]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
mach-o: read and dump: prebound_dylib, prebind_cksum, twolevel_hints.
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
4b95cf5c 2 Copyright (C) 1994-2014 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
171static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
172static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
173static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
174static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
175static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
176static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
177static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
178static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
179static const arm_feature_set arm_ext_v4t_5 =
180 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
181static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
182static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
183static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
184static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
185static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
186static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
e74cfd16 187static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
b2a5fbdc 188static const arm_feature_set arm_ext_v6m = ARM_FEATURE (ARM_EXT_V6M, 0);
62b3e311 189static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
9e3c6df6 190static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
7e806470
PB
191static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
192static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
193static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
194static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
195static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
196static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
9e3c6df6 197static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
bca38921 198static const arm_feature_set arm_ext_v8 = ARM_FEATURE (ARM_EXT_V8, 0);
7e806470 199static const arm_feature_set arm_ext_m =
b2a5fbdc 200 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, 0);
60e5ef9f 201static const arm_feature_set arm_ext_mp = ARM_FEATURE (ARM_EXT_MP, 0);
f4c65163 202static const arm_feature_set arm_ext_sec = ARM_FEATURE (ARM_EXT_SEC, 0);
b2a5fbdc 203static const arm_feature_set arm_ext_os = ARM_FEATURE (ARM_EXT_OS, 0);
eea54501 204static const arm_feature_set arm_ext_adiv = ARM_FEATURE (ARM_EXT_ADIV, 0);
90ec0d68 205static const arm_feature_set arm_ext_virt = ARM_FEATURE (ARM_EXT_VIRT, 0);
e74cfd16
PB
206
207static const arm_feature_set arm_arch_any = ARM_ANY;
208static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
209static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
210static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
251665fc 211static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
e74cfd16 212
2d447fca
JM
213static const arm_feature_set arm_cext_iwmmxt2 =
214 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
215static const arm_feature_set arm_cext_iwmmxt =
216 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
217static const arm_feature_set arm_cext_xscale =
218 ARM_FEATURE (0, ARM_CEXT_XSCALE);
219static const arm_feature_set arm_cext_maverick =
220 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
221static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
222static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
223static const arm_feature_set fpu_vfp_ext_v1xd =
224 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
225static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
226static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
62f3b8c8 227static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
5287ad62 228static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
229static const arm_feature_set fpu_vfp_ext_d32 =
230 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
231static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
232static const arm_feature_set fpu_vfp_v3_or_neon_ext =
233 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
62f3b8c8
PB
234static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
235static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
236static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
bca38921
MGD
237static const arm_feature_set fpu_vfp_ext_armv8 =
238 ARM_FEATURE (0, FPU_VFP_EXT_ARMV8);
239static const arm_feature_set fpu_neon_ext_armv8 =
240 ARM_FEATURE (0, FPU_NEON_EXT_ARMV8);
241static const arm_feature_set fpu_crypto_ext_armv8 =
242 ARM_FEATURE (0, FPU_CRYPTO_EXT_ARMV8);
dd5181d5
KT
243static const arm_feature_set crc_ext_armv8 =
244 ARM_FEATURE (0, CRC_EXT_ARMV8);
e74cfd16 245
33a392fb 246static int mfloat_abi_opt = -1;
e74cfd16
PB
247/* Record user cpu selection for object attributes. */
248static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
249/* Must be long enough to hold any of the names in arm_cpus. */
250static char selected_cpu_name[16];
8d67f500
NC
251
252/* Return if no cpu was selected on command-line. */
253static bfd_boolean
254no_cpu_selected (void)
255{
256 return selected_cpu.core == arm_arch_none.core
257 && selected_cpu.coproc == arm_arch_none.coproc;
258}
259
7cc69913 260#ifdef OBJ_ELF
deeaaff8
DJ
261# ifdef EABI_DEFAULT
262static int meabi_flags = EABI_DEFAULT;
263# else
d507cf36 264static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 265# endif
e1da3f5b 266
ee3c0378
AS
267static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
268
e1da3f5b 269bfd_boolean
5f4273c7 270arm_is_eabi (void)
e1da3f5b
PB
271{
272 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
273}
7cc69913 274#endif
b99bd4ef 275
b99bd4ef 276#ifdef OBJ_ELF
c19d1205 277/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
278symbolS * GOT_symbol;
279#endif
280
b99bd4ef
NC
281/* 0: assemble for ARM,
282 1: assemble for Thumb,
283 2: assemble for Thumb even though target CPU does not support thumb
284 instructions. */
285static int thumb_mode = 0;
8dc2430f
NC
286/* A value distinct from the possible values for thumb_mode that we
287 can use to record whether thumb_mode has been copied into the
288 tc_frag_data field of a frag. */
289#define MODE_RECORDED (1 << 4)
b99bd4ef 290
e07e6e58
NC
291/* Specifies the intrinsic IT insn behavior mode. */
292enum implicit_it_mode
293{
294 IMPLICIT_IT_MODE_NEVER = 0x00,
295 IMPLICIT_IT_MODE_ARM = 0x01,
296 IMPLICIT_IT_MODE_THUMB = 0x02,
297 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
298};
299static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
300
c19d1205
ZW
301/* If unified_syntax is true, we are processing the new unified
302 ARM/Thumb syntax. Important differences from the old ARM mode:
303
304 - Immediate operands do not require a # prefix.
305 - Conditional affixes always appear at the end of the
306 instruction. (For backward compatibility, those instructions
307 that formerly had them in the middle, continue to accept them
308 there.)
309 - The IT instruction may appear, and if it does is validated
310 against subsequent conditional affixes. It does not generate
311 machine code.
312
313 Important differences from the old Thumb mode:
314
315 - Immediate operands do not require a # prefix.
316 - Most of the V6T2 instructions are only available in unified mode.
317 - The .N and .W suffixes are recognized and honored (it is an error
318 if they cannot be honored).
319 - All instructions set the flags if and only if they have an 's' affix.
320 - Conditional affixes may be used. They are validated against
321 preceding IT instructions. Unlike ARM mode, you cannot use a
322 conditional affix except in the scope of an IT instruction. */
323
324static bfd_boolean unified_syntax = FALSE;
b99bd4ef 325
bacebabc
RM
326/* An immediate operand can start with #, and ld*, st*, pld operands
327 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
328 before a [, which can appear as the first operand for pld.
329 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
330const char arm_symbol_chars[] = "#[]{}";
bacebabc 331
5287ad62
JB
332enum neon_el_type
333{
dcbf9037 334 NT_invtype,
5287ad62
JB
335 NT_untyped,
336 NT_integer,
337 NT_float,
338 NT_poly,
339 NT_signed,
dcbf9037 340 NT_unsigned
5287ad62
JB
341};
342
343struct neon_type_el
344{
345 enum neon_el_type type;
346 unsigned size;
347};
348
349#define NEON_MAX_TYPE_ELS 4
350
351struct neon_type
352{
353 struct neon_type_el el[NEON_MAX_TYPE_ELS];
354 unsigned elems;
355};
356
e07e6e58
NC
357enum it_instruction_type
358{
359 OUTSIDE_IT_INSN,
360 INSIDE_IT_INSN,
361 INSIDE_IT_LAST_INSN,
362 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 363 if inside, should be the last one. */
e07e6e58 364 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 365 i.e. BKPT and NOP. */
e07e6e58
NC
366 IT_INSN /* The IT insn has been parsed. */
367};
368
ad6cec43
MGD
369/* The maximum number of operands we need. */
370#define ARM_IT_MAX_OPERANDS 6
371
b99bd4ef
NC
372struct arm_it
373{
c19d1205 374 const char * error;
b99bd4ef 375 unsigned long instruction;
c19d1205
ZW
376 int size;
377 int size_req;
378 int cond;
037e8744
JB
379 /* "uncond_value" is set to the value in place of the conditional field in
380 unconditional versions of the instruction, or -1 if nothing is
381 appropriate. */
382 int uncond_value;
5287ad62 383 struct neon_type vectype;
88714cb8
DG
384 /* This does not indicate an actual NEON instruction, only that
385 the mnemonic accepts neon-style type suffixes. */
386 int is_neon;
0110f2b8
PB
387 /* Set to the opcode if the instruction needs relaxation.
388 Zero if the instruction is not relaxed. */
389 unsigned long relax;
b99bd4ef
NC
390 struct
391 {
392 bfd_reloc_code_real_type type;
c19d1205
ZW
393 expressionS exp;
394 int pc_rel;
b99bd4ef 395 } reloc;
b99bd4ef 396
e07e6e58
NC
397 enum it_instruction_type it_insn_type;
398
c19d1205
ZW
399 struct
400 {
401 unsigned reg;
ca3f61f7 402 signed int imm;
dcbf9037 403 struct neon_type_el vectype;
ca3f61f7
NC
404 unsigned present : 1; /* Operand present. */
405 unsigned isreg : 1; /* Operand was a register. */
406 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
407 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
408 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 409 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
410 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
411 instructions. This allows us to disambiguate ARM <-> vector insns. */
412 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 413 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 414 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 415 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
416 unsigned hasreloc : 1; /* Operand has relocation suffix. */
417 unsigned writeback : 1; /* Operand has trailing ! */
418 unsigned preind : 1; /* Preindexed address. */
419 unsigned postind : 1; /* Postindexed address. */
420 unsigned negative : 1; /* Index register was negated. */
421 unsigned shifted : 1; /* Shift applied to operation. */
422 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 423 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
424};
425
c19d1205 426static struct arm_it inst;
b99bd4ef
NC
427
428#define NUM_FLOAT_VALS 8
429
05d2d07e 430const char * fp_const[] =
b99bd4ef
NC
431{
432 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
433};
434
c19d1205 435/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
436#define MAX_LITTLENUMS 6
437
438LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
439
440#define FAIL (-1)
441#define SUCCESS (0)
442
443#define SUFF_S 1
444#define SUFF_D 2
445#define SUFF_E 3
446#define SUFF_P 4
447
c19d1205
ZW
448#define CP_T_X 0x00008000
449#define CP_T_Y 0x00400000
b99bd4ef 450
c19d1205
ZW
451#define CONDS_BIT 0x00100000
452#define LOAD_BIT 0x00100000
b99bd4ef
NC
453
454#define DOUBLE_LOAD_FLAG 0x00000001
455
456struct asm_cond
457{
d3ce72d0 458 const char * template_name;
c921be7d 459 unsigned long value;
b99bd4ef
NC
460};
461
c19d1205 462#define COND_ALWAYS 0xE
b99bd4ef 463
b99bd4ef
NC
464struct asm_psr
465{
d3ce72d0 466 const char * template_name;
c921be7d 467 unsigned long field;
b99bd4ef
NC
468};
469
62b3e311
PB
470struct asm_barrier_opt
471{
e797f7e0
MGD
472 const char * template_name;
473 unsigned long value;
474 const arm_feature_set arch;
62b3e311
PB
475};
476
2d2255b5 477/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
478#define SPSR_BIT (1 << 22)
479
c19d1205
ZW
480/* The individual PSR flag bits. */
481#define PSR_c (1 << 16)
482#define PSR_x (1 << 17)
483#define PSR_s (1 << 18)
484#define PSR_f (1 << 19)
b99bd4ef 485
c19d1205 486struct reloc_entry
bfae80f2 487{
c921be7d
NC
488 char * name;
489 bfd_reloc_code_real_type reloc;
bfae80f2
RE
490};
491
5287ad62 492enum vfp_reg_pos
bfae80f2 493{
5287ad62
JB
494 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
495 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
496};
497
498enum vfp_ldstm_type
499{
500 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
501};
502
dcbf9037
JB
503/* Bits for DEFINED field in neon_typed_alias. */
504#define NTA_HASTYPE 1
505#define NTA_HASINDEX 2
506
507struct neon_typed_alias
508{
c921be7d
NC
509 unsigned char defined;
510 unsigned char index;
511 struct neon_type_el eltype;
dcbf9037
JB
512};
513
c19d1205
ZW
514/* ARM register categories. This includes coprocessor numbers and various
515 architecture extensions' registers. */
516enum arm_reg_type
bfae80f2 517{
c19d1205
ZW
518 REG_TYPE_RN,
519 REG_TYPE_CP,
520 REG_TYPE_CN,
521 REG_TYPE_FN,
522 REG_TYPE_VFS,
523 REG_TYPE_VFD,
5287ad62 524 REG_TYPE_NQ,
037e8744 525 REG_TYPE_VFSD,
5287ad62 526 REG_TYPE_NDQ,
037e8744 527 REG_TYPE_NSDQ,
c19d1205
ZW
528 REG_TYPE_VFC,
529 REG_TYPE_MVF,
530 REG_TYPE_MVD,
531 REG_TYPE_MVFX,
532 REG_TYPE_MVDX,
533 REG_TYPE_MVAX,
534 REG_TYPE_DSPSC,
535 REG_TYPE_MMXWR,
536 REG_TYPE_MMXWC,
537 REG_TYPE_MMXWCG,
538 REG_TYPE_XSCALE,
90ec0d68 539 REG_TYPE_RNB
bfae80f2
RE
540};
541
dcbf9037
JB
542/* Structure for a hash table entry for a register.
543 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
544 information which states whether a vector type or index is specified (for a
545 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
546struct reg_entry
547{
c921be7d 548 const char * name;
90ec0d68 549 unsigned int number;
c921be7d
NC
550 unsigned char type;
551 unsigned char builtin;
552 struct neon_typed_alias * neon;
6c43fab6
RE
553};
554
c19d1205 555/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 556const char * const reg_expected_msgs[] =
c19d1205
ZW
557{
558 N_("ARM register expected"),
559 N_("bad or missing co-processor number"),
560 N_("co-processor register expected"),
561 N_("FPA register expected"),
562 N_("VFP single precision register expected"),
5287ad62
JB
563 N_("VFP/Neon double precision register expected"),
564 N_("Neon quad precision register expected"),
037e8744 565 N_("VFP single or double precision register expected"),
5287ad62 566 N_("Neon double or quad precision register expected"),
037e8744 567 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
568 N_("VFP system register expected"),
569 N_("Maverick MVF register expected"),
570 N_("Maverick MVD register expected"),
571 N_("Maverick MVFX register expected"),
572 N_("Maverick MVDX register expected"),
573 N_("Maverick MVAX register expected"),
574 N_("Maverick DSPSC register expected"),
575 N_("iWMMXt data register expected"),
576 N_("iWMMXt control register expected"),
577 N_("iWMMXt scalar register expected"),
578 N_("XScale accumulator register expected"),
6c43fab6
RE
579};
580
c19d1205 581/* Some well known registers that we refer to directly elsewhere. */
bd340a04 582#define REG_R12 12
c19d1205
ZW
583#define REG_SP 13
584#define REG_LR 14
585#define REG_PC 15
404ff6b5 586
b99bd4ef
NC
587/* ARM instructions take 4bytes in the object file, Thumb instructions
588 take 2: */
c19d1205 589#define INSN_SIZE 4
b99bd4ef
NC
590
591struct asm_opcode
592{
593 /* Basic string to match. */
d3ce72d0 594 const char * template_name;
c19d1205
ZW
595
596 /* Parameters to instruction. */
5be8be5d 597 unsigned int operands[8];
c19d1205
ZW
598
599 /* Conditional tag - see opcode_lookup. */
600 unsigned int tag : 4;
b99bd4ef
NC
601
602 /* Basic instruction code. */
c19d1205 603 unsigned int avalue : 28;
b99bd4ef 604
c19d1205
ZW
605 /* Thumb-format instruction code. */
606 unsigned int tvalue;
b99bd4ef 607
90e4755a 608 /* Which architecture variant provides this instruction. */
c921be7d
NC
609 const arm_feature_set * avariant;
610 const arm_feature_set * tvariant;
c19d1205
ZW
611
612 /* Function to call to encode instruction in ARM format. */
613 void (* aencode) (void);
b99bd4ef 614
c19d1205
ZW
615 /* Function to call to encode instruction in Thumb format. */
616 void (* tencode) (void);
b99bd4ef
NC
617};
618
a737bd4d
NC
619/* Defines for various bits that we will want to toggle. */
620#define INST_IMMEDIATE 0x02000000
621#define OFFSET_REG 0x02000000
c19d1205 622#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
623#define SHIFT_BY_REG 0x00000010
624#define PRE_INDEX 0x01000000
625#define INDEX_UP 0x00800000
626#define WRITE_BACK 0x00200000
627#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 628#define CPSI_MMOD 0x00020000
90e4755a 629
a737bd4d
NC
630#define LITERAL_MASK 0xf000f000
631#define OPCODE_MASK 0xfe1fffff
632#define V4_STR_BIT 0x00000020
90e4755a 633
efd81785
PB
634#define T2_SUBS_PC_LR 0xf3de8f00
635
a737bd4d 636#define DATA_OP_SHIFT 21
90e4755a 637
ef8d22e6
PB
638#define T2_OPCODE_MASK 0xfe1fffff
639#define T2_DATA_OP_SHIFT 21
640
6530b175
NC
641#define A_COND_MASK 0xf0000000
642#define A_PUSH_POP_OP_MASK 0x0fff0000
643
644/* Opcodes for pushing/poping registers to/from the stack. */
645#define A1_OPCODE_PUSH 0x092d0000
646#define A2_OPCODE_PUSH 0x052d0004
647#define A2_OPCODE_POP 0x049d0004
648
a737bd4d
NC
649/* Codes to distinguish the arithmetic instructions. */
650#define OPCODE_AND 0
651#define OPCODE_EOR 1
652#define OPCODE_SUB 2
653#define OPCODE_RSB 3
654#define OPCODE_ADD 4
655#define OPCODE_ADC 5
656#define OPCODE_SBC 6
657#define OPCODE_RSC 7
658#define OPCODE_TST 8
659#define OPCODE_TEQ 9
660#define OPCODE_CMP 10
661#define OPCODE_CMN 11
662#define OPCODE_ORR 12
663#define OPCODE_MOV 13
664#define OPCODE_BIC 14
665#define OPCODE_MVN 15
90e4755a 666
ef8d22e6
PB
667#define T2_OPCODE_AND 0
668#define T2_OPCODE_BIC 1
669#define T2_OPCODE_ORR 2
670#define T2_OPCODE_ORN 3
671#define T2_OPCODE_EOR 4
672#define T2_OPCODE_ADD 8
673#define T2_OPCODE_ADC 10
674#define T2_OPCODE_SBC 11
675#define T2_OPCODE_SUB 13
676#define T2_OPCODE_RSB 14
677
a737bd4d
NC
678#define T_OPCODE_MUL 0x4340
679#define T_OPCODE_TST 0x4200
680#define T_OPCODE_CMN 0x42c0
681#define T_OPCODE_NEG 0x4240
682#define T_OPCODE_MVN 0x43c0
90e4755a 683
a737bd4d
NC
684#define T_OPCODE_ADD_R3 0x1800
685#define T_OPCODE_SUB_R3 0x1a00
686#define T_OPCODE_ADD_HI 0x4400
687#define T_OPCODE_ADD_ST 0xb000
688#define T_OPCODE_SUB_ST 0xb080
689#define T_OPCODE_ADD_SP 0xa800
690#define T_OPCODE_ADD_PC 0xa000
691#define T_OPCODE_ADD_I8 0x3000
692#define T_OPCODE_SUB_I8 0x3800
693#define T_OPCODE_ADD_I3 0x1c00
694#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 695
a737bd4d
NC
696#define T_OPCODE_ASR_R 0x4100
697#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
698#define T_OPCODE_LSR_R 0x40c0
699#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
700#define T_OPCODE_ASR_I 0x1000
701#define T_OPCODE_LSL_I 0x0000
702#define T_OPCODE_LSR_I 0x0800
b99bd4ef 703
a737bd4d
NC
704#define T_OPCODE_MOV_I8 0x2000
705#define T_OPCODE_CMP_I8 0x2800
706#define T_OPCODE_CMP_LR 0x4280
707#define T_OPCODE_MOV_HR 0x4600
708#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 709
a737bd4d
NC
710#define T_OPCODE_LDR_PC 0x4800
711#define T_OPCODE_LDR_SP 0x9800
712#define T_OPCODE_STR_SP 0x9000
713#define T_OPCODE_LDR_IW 0x6800
714#define T_OPCODE_STR_IW 0x6000
715#define T_OPCODE_LDR_IH 0x8800
716#define T_OPCODE_STR_IH 0x8000
717#define T_OPCODE_LDR_IB 0x7800
718#define T_OPCODE_STR_IB 0x7000
719#define T_OPCODE_LDR_RW 0x5800
720#define T_OPCODE_STR_RW 0x5000
721#define T_OPCODE_LDR_RH 0x5a00
722#define T_OPCODE_STR_RH 0x5200
723#define T_OPCODE_LDR_RB 0x5c00
724#define T_OPCODE_STR_RB 0x5400
c9b604bd 725
a737bd4d
NC
726#define T_OPCODE_PUSH 0xb400
727#define T_OPCODE_POP 0xbc00
b99bd4ef 728
2fc8bdac 729#define T_OPCODE_BRANCH 0xe000
b99bd4ef 730
a737bd4d 731#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 732#define THUMB_PP_PC_LR 0x0100
c19d1205 733#define THUMB_LOAD_BIT 0x0800
53365c0d 734#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
735
736#define BAD_ARGS _("bad arguments to instruction")
fdfde340 737#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
738#define BAD_PC _("r15 not allowed here")
739#define BAD_COND _("instruction cannot be conditional")
740#define BAD_OVERLAP _("registers may not be the same")
741#define BAD_HIREG _("lo register required")
742#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 743#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
744#define BAD_BRANCH _("branch must be last instruction in IT block")
745#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 746#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
747#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
748#define BAD_IT_COND _("incorrect condition in IT block")
749#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 750#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
751#define BAD_PC_ADDRESSING \
752 _("cannot use register index with PC-relative addressing")
753#define BAD_PC_WRITEBACK \
754 _("cannot use writeback with PC-relative addressing")
08f10d51 755#define BAD_RANGE _("branch out of range")
dd5181d5 756#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
c19d1205 757
c921be7d
NC
758static struct hash_control * arm_ops_hsh;
759static struct hash_control * arm_cond_hsh;
760static struct hash_control * arm_shift_hsh;
761static struct hash_control * arm_psr_hsh;
762static struct hash_control * arm_v7m_psr_hsh;
763static struct hash_control * arm_reg_hsh;
764static struct hash_control * arm_reloc_hsh;
765static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 766
b99bd4ef
NC
767/* Stuff needed to resolve the label ambiguity
768 As:
769 ...
770 label: <insn>
771 may differ from:
772 ...
773 label:
5f4273c7 774 <insn> */
b99bd4ef
NC
775
776symbolS * last_label_seen;
b34976b6 777static int label_is_thumb_function_name = FALSE;
e07e6e58 778
3d0c9500
NC
779/* Literal pool structure. Held on a per-section
780 and per-sub-section basis. */
a737bd4d 781
c19d1205 782#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 783typedef struct literal_pool
b99bd4ef 784{
c921be7d
NC
785 expressionS literals [MAX_LITERAL_POOL_SIZE];
786 unsigned int next_free_entry;
787 unsigned int id;
788 symbolS * symbol;
789 segT section;
790 subsegT sub_section;
a8040cf2
NC
791#ifdef OBJ_ELF
792 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
793#endif
c921be7d 794 struct literal_pool * next;
3d0c9500 795} literal_pool;
b99bd4ef 796
3d0c9500
NC
797/* Pointer to a linked list of literal pools. */
798literal_pool * list_of_pools = NULL;
e27ec89e 799
2e6976a8
DG
800typedef enum asmfunc_states
801{
802 OUTSIDE_ASMFUNC,
803 WAITING_ASMFUNC_NAME,
804 WAITING_ENDASMFUNC
805} asmfunc_states;
806
807static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
808
e07e6e58
NC
809#ifdef OBJ_ELF
810# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
811#else
812static struct current_it now_it;
813#endif
814
815static inline int
816now_it_compatible (int cond)
817{
818 return (cond & ~1) == (now_it.cc & ~1);
819}
820
821static inline int
822conditional_insn (void)
823{
824 return inst.cond != COND_ALWAYS;
825}
826
827static int in_it_block (void);
828
829static int handle_it_state (void);
830
831static void force_automatic_it_block_close (void);
832
c921be7d
NC
833static void it_fsm_post_encode (void);
834
e07e6e58
NC
835#define set_it_insn_type(type) \
836 do \
837 { \
838 inst.it_insn_type = type; \
839 if (handle_it_state () == FAIL) \
477330fc 840 return; \
e07e6e58
NC
841 } \
842 while (0)
843
c921be7d
NC
844#define set_it_insn_type_nonvoid(type, failret) \
845 do \
846 { \
847 inst.it_insn_type = type; \
848 if (handle_it_state () == FAIL) \
477330fc 849 return failret; \
c921be7d
NC
850 } \
851 while(0)
852
e07e6e58
NC
853#define set_it_insn_type_last() \
854 do \
855 { \
856 if (inst.cond == COND_ALWAYS) \
477330fc 857 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 858 else \
477330fc 859 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
860 } \
861 while (0)
862
c19d1205 863/* Pure syntax. */
b99bd4ef 864
c19d1205
ZW
865/* This array holds the chars that always start a comment. If the
866 pre-processor is disabled, these aren't very useful. */
2e6976a8 867char arm_comment_chars[] = "@";
3d0c9500 868
c19d1205
ZW
869/* This array holds the chars that only start a comment at the beginning of
870 a line. If the line seems to have the form '# 123 filename'
871 .line and .file directives will appear in the pre-processed output. */
872/* Note that input_file.c hand checks for '#' at the beginning of the
873 first line of the input file. This is because the compiler outputs
874 #NO_APP at the beginning of its output. */
875/* Also note that comments like this one will always work. */
876const char line_comment_chars[] = "#";
3d0c9500 877
2e6976a8 878char arm_line_separator_chars[] = ";";
b99bd4ef 879
c19d1205
ZW
880/* Chars that can be used to separate mant
881 from exp in floating point numbers. */
882const char EXP_CHARS[] = "eE";
3d0c9500 883
c19d1205
ZW
884/* Chars that mean this number is a floating point constant. */
885/* As in 0f12.456 */
886/* or 0d1.2345e12 */
b99bd4ef 887
c19d1205 888const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 889
c19d1205
ZW
890/* Prefix characters that indicate the start of an immediate
891 value. */
892#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 893
c19d1205
ZW
894/* Separator character handling. */
895
896#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
897
898static inline int
899skip_past_char (char ** str, char c)
900{
8ab8155f
NC
901 /* PR gas/14987: Allow for whitespace before the expected character. */
902 skip_whitespace (*str);
427d0db6 903
c19d1205
ZW
904 if (**str == c)
905 {
906 (*str)++;
907 return SUCCESS;
3d0c9500 908 }
c19d1205
ZW
909 else
910 return FAIL;
911}
c921be7d 912
c19d1205 913#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 914
c19d1205
ZW
915/* Arithmetic expressions (possibly involving symbols). */
916
917/* Return TRUE if anything in the expression is a bignum. */
918
919static int
920walk_no_bignums (symbolS * sp)
921{
922 if (symbol_get_value_expression (sp)->X_op == O_big)
923 return 1;
924
925 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 926 {
c19d1205
ZW
927 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
928 || (symbol_get_value_expression (sp)->X_op_symbol
929 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
930 }
931
c19d1205 932 return 0;
3d0c9500
NC
933}
934
c19d1205
ZW
935static int in_my_get_expression = 0;
936
937/* Third argument to my_get_expression. */
938#define GE_NO_PREFIX 0
939#define GE_IMM_PREFIX 1
940#define GE_OPT_PREFIX 2
5287ad62
JB
941/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
942 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
943#define GE_OPT_PREFIX_BIG 3
a737bd4d 944
b99bd4ef 945static int
c19d1205 946my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 947{
c19d1205
ZW
948 char * save_in;
949 segT seg;
b99bd4ef 950
c19d1205
ZW
951 /* In unified syntax, all prefixes are optional. */
952 if (unified_syntax)
5287ad62 953 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 954 : GE_OPT_PREFIX;
b99bd4ef 955
c19d1205 956 switch (prefix_mode)
b99bd4ef 957 {
c19d1205
ZW
958 case GE_NO_PREFIX: break;
959 case GE_IMM_PREFIX:
960 if (!is_immediate_prefix (**str))
961 {
962 inst.error = _("immediate expression requires a # prefix");
963 return FAIL;
964 }
965 (*str)++;
966 break;
967 case GE_OPT_PREFIX:
5287ad62 968 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
969 if (is_immediate_prefix (**str))
970 (*str)++;
971 break;
972 default: abort ();
973 }
b99bd4ef 974
c19d1205 975 memset (ep, 0, sizeof (expressionS));
b99bd4ef 976
c19d1205
ZW
977 save_in = input_line_pointer;
978 input_line_pointer = *str;
979 in_my_get_expression = 1;
980 seg = expression (ep);
981 in_my_get_expression = 0;
982
f86adc07 983 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 984 {
f86adc07 985 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
986 *str = input_line_pointer;
987 input_line_pointer = save_in;
988 if (inst.error == NULL)
f86adc07
NS
989 inst.error = (ep->X_op == O_absent
990 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
991 return 1;
992 }
b99bd4ef 993
c19d1205
ZW
994#ifdef OBJ_AOUT
995 if (seg != absolute_section
996 && seg != text_section
997 && seg != data_section
998 && seg != bss_section
999 && seg != undefined_section)
1000 {
1001 inst.error = _("bad segment");
1002 *str = input_line_pointer;
1003 input_line_pointer = save_in;
1004 return 1;
b99bd4ef 1005 }
87975d2a
AM
1006#else
1007 (void) seg;
c19d1205 1008#endif
b99bd4ef 1009
c19d1205
ZW
1010 /* Get rid of any bignums now, so that we don't generate an error for which
1011 we can't establish a line number later on. Big numbers are never valid
1012 in instructions, which is where this routine is always called. */
5287ad62
JB
1013 if (prefix_mode != GE_OPT_PREFIX_BIG
1014 && (ep->X_op == O_big
477330fc 1015 || (ep->X_add_symbol
5287ad62 1016 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1017 || (ep->X_op_symbol
5287ad62 1018 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1019 {
1020 inst.error = _("invalid constant");
1021 *str = input_line_pointer;
1022 input_line_pointer = save_in;
1023 return 1;
1024 }
b99bd4ef 1025
c19d1205
ZW
1026 *str = input_line_pointer;
1027 input_line_pointer = save_in;
1028 return 0;
b99bd4ef
NC
1029}
1030
c19d1205
ZW
1031/* Turn a string in input_line_pointer into a floating point constant
1032 of type TYPE, and store the appropriate bytes in *LITP. The number
1033 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1034 returned, or NULL on OK.
b99bd4ef 1035
c19d1205
ZW
1036 Note that fp constants aren't represent in the normal way on the ARM.
1037 In big endian mode, things are as expected. However, in little endian
1038 mode fp constants are big-endian word-wise, and little-endian byte-wise
1039 within the words. For example, (double) 1.1 in big endian mode is
1040 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1041 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1042
c19d1205 1043 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1044
c19d1205
ZW
1045char *
1046md_atof (int type, char * litP, int * sizeP)
1047{
1048 int prec;
1049 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1050 char *t;
1051 int i;
b99bd4ef 1052
c19d1205
ZW
1053 switch (type)
1054 {
1055 case 'f':
1056 case 'F':
1057 case 's':
1058 case 'S':
1059 prec = 2;
1060 break;
b99bd4ef 1061
c19d1205
ZW
1062 case 'd':
1063 case 'D':
1064 case 'r':
1065 case 'R':
1066 prec = 4;
1067 break;
b99bd4ef 1068
c19d1205
ZW
1069 case 'x':
1070 case 'X':
499ac353 1071 prec = 5;
c19d1205 1072 break;
b99bd4ef 1073
c19d1205
ZW
1074 case 'p':
1075 case 'P':
499ac353 1076 prec = 5;
c19d1205 1077 break;
a737bd4d 1078
c19d1205
ZW
1079 default:
1080 *sizeP = 0;
499ac353 1081 return _("Unrecognized or unsupported floating point constant");
c19d1205 1082 }
b99bd4ef 1083
c19d1205
ZW
1084 t = atof_ieee (input_line_pointer, type, words);
1085 if (t)
1086 input_line_pointer = t;
499ac353 1087 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1088
c19d1205
ZW
1089 if (target_big_endian)
1090 {
1091 for (i = 0; i < prec; i++)
1092 {
499ac353
NC
1093 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1094 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1095 }
1096 }
1097 else
1098 {
e74cfd16 1099 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1100 for (i = prec - 1; i >= 0; i--)
1101 {
499ac353
NC
1102 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1103 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1104 }
1105 else
1106 /* For a 4 byte float the order of elements in `words' is 1 0.
1107 For an 8 byte float the order is 1 0 3 2. */
1108 for (i = 0; i < prec; i += 2)
1109 {
499ac353
NC
1110 md_number_to_chars (litP, (valueT) words[i + 1],
1111 sizeof (LITTLENUM_TYPE));
1112 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1113 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1114 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1115 }
1116 }
b99bd4ef 1117
499ac353 1118 return NULL;
c19d1205 1119}
b99bd4ef 1120
c19d1205
ZW
1121/* We handle all bad expressions here, so that we can report the faulty
1122 instruction in the error message. */
1123void
91d6fa6a 1124md_operand (expressionS * exp)
c19d1205
ZW
1125{
1126 if (in_my_get_expression)
91d6fa6a 1127 exp->X_op = O_illegal;
b99bd4ef
NC
1128}
1129
c19d1205 1130/* Immediate values. */
b99bd4ef 1131
c19d1205
ZW
1132/* Generic immediate-value read function for use in directives.
1133 Accepts anything that 'expression' can fold to a constant.
1134 *val receives the number. */
1135#ifdef OBJ_ELF
1136static int
1137immediate_for_directive (int *val)
b99bd4ef 1138{
c19d1205
ZW
1139 expressionS exp;
1140 exp.X_op = O_illegal;
b99bd4ef 1141
c19d1205
ZW
1142 if (is_immediate_prefix (*input_line_pointer))
1143 {
1144 input_line_pointer++;
1145 expression (&exp);
1146 }
b99bd4ef 1147
c19d1205
ZW
1148 if (exp.X_op != O_constant)
1149 {
1150 as_bad (_("expected #constant"));
1151 ignore_rest_of_line ();
1152 return FAIL;
1153 }
1154 *val = exp.X_add_number;
1155 return SUCCESS;
b99bd4ef 1156}
c19d1205 1157#endif
b99bd4ef 1158
c19d1205 1159/* Register parsing. */
b99bd4ef 1160
c19d1205
ZW
1161/* Generic register parser. CCP points to what should be the
1162 beginning of a register name. If it is indeed a valid register
1163 name, advance CCP over it and return the reg_entry structure;
1164 otherwise return NULL. Does not issue diagnostics. */
1165
1166static struct reg_entry *
1167arm_reg_parse_multi (char **ccp)
b99bd4ef 1168{
c19d1205
ZW
1169 char *start = *ccp;
1170 char *p;
1171 struct reg_entry *reg;
b99bd4ef 1172
477330fc
RM
1173 skip_whitespace (start);
1174
c19d1205
ZW
1175#ifdef REGISTER_PREFIX
1176 if (*start != REGISTER_PREFIX)
01cfc07f 1177 return NULL;
c19d1205
ZW
1178 start++;
1179#endif
1180#ifdef OPTIONAL_REGISTER_PREFIX
1181 if (*start == OPTIONAL_REGISTER_PREFIX)
1182 start++;
1183#endif
b99bd4ef 1184
c19d1205
ZW
1185 p = start;
1186 if (!ISALPHA (*p) || !is_name_beginner (*p))
1187 return NULL;
b99bd4ef 1188
c19d1205
ZW
1189 do
1190 p++;
1191 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1192
1193 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1194
1195 if (!reg)
1196 return NULL;
1197
1198 *ccp = p;
1199 return reg;
b99bd4ef
NC
1200}
1201
1202static int
dcbf9037 1203arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1204 enum arm_reg_type type)
b99bd4ef 1205{
c19d1205
ZW
1206 /* Alternative syntaxes are accepted for a few register classes. */
1207 switch (type)
1208 {
1209 case REG_TYPE_MVF:
1210 case REG_TYPE_MVD:
1211 case REG_TYPE_MVFX:
1212 case REG_TYPE_MVDX:
1213 /* Generic coprocessor register names are allowed for these. */
79134647 1214 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1215 return reg->number;
1216 break;
69b97547 1217
c19d1205
ZW
1218 case REG_TYPE_CP:
1219 /* For backward compatibility, a bare number is valid here. */
1220 {
1221 unsigned long processor = strtoul (start, ccp, 10);
1222 if (*ccp != start && processor <= 15)
1223 return processor;
1224 }
6057a28f 1225
c19d1205
ZW
1226 case REG_TYPE_MMXWC:
1227 /* WC includes WCG. ??? I'm not sure this is true for all
1228 instructions that take WC registers. */
79134647 1229 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1230 return reg->number;
6057a28f 1231 break;
c19d1205 1232
6057a28f 1233 default:
c19d1205 1234 break;
6057a28f
NC
1235 }
1236
dcbf9037
JB
1237 return FAIL;
1238}
1239
1240/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1241 return value is the register number or FAIL. */
1242
1243static int
1244arm_reg_parse (char **ccp, enum arm_reg_type type)
1245{
1246 char *start = *ccp;
1247 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1248 int ret;
1249
1250 /* Do not allow a scalar (reg+index) to parse as a register. */
1251 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1252 return FAIL;
1253
1254 if (reg && reg->type == type)
1255 return reg->number;
1256
1257 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1258 return ret;
1259
c19d1205
ZW
1260 *ccp = start;
1261 return FAIL;
1262}
69b97547 1263
dcbf9037
JB
1264/* Parse a Neon type specifier. *STR should point at the leading '.'
1265 character. Does no verification at this stage that the type fits the opcode
1266 properly. E.g.,
1267
1268 .i32.i32.s16
1269 .s32.f32
1270 .u16
1271
1272 Can all be legally parsed by this function.
1273
1274 Fills in neon_type struct pointer with parsed information, and updates STR
1275 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1276 type, FAIL if not. */
1277
1278static int
1279parse_neon_type (struct neon_type *type, char **str)
1280{
1281 char *ptr = *str;
1282
1283 if (type)
1284 type->elems = 0;
1285
1286 while (type->elems < NEON_MAX_TYPE_ELS)
1287 {
1288 enum neon_el_type thistype = NT_untyped;
1289 unsigned thissize = -1u;
1290
1291 if (*ptr != '.')
1292 break;
1293
1294 ptr++;
1295
1296 /* Just a size without an explicit type. */
1297 if (ISDIGIT (*ptr))
1298 goto parsesize;
1299
1300 switch (TOLOWER (*ptr))
1301 {
1302 case 'i': thistype = NT_integer; break;
1303 case 'f': thistype = NT_float; break;
1304 case 'p': thistype = NT_poly; break;
1305 case 's': thistype = NT_signed; break;
1306 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1307 case 'd':
1308 thistype = NT_float;
1309 thissize = 64;
1310 ptr++;
1311 goto done;
dcbf9037
JB
1312 default:
1313 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1314 return FAIL;
1315 }
1316
1317 ptr++;
1318
1319 /* .f is an abbreviation for .f32. */
1320 if (thistype == NT_float && !ISDIGIT (*ptr))
1321 thissize = 32;
1322 else
1323 {
1324 parsesize:
1325 thissize = strtoul (ptr, &ptr, 10);
1326
1327 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1328 && thissize != 64)
1329 {
1330 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1331 return FAIL;
1332 }
1333 }
1334
037e8744 1335 done:
dcbf9037 1336 if (type)
477330fc
RM
1337 {
1338 type->el[type->elems].type = thistype;
dcbf9037
JB
1339 type->el[type->elems].size = thissize;
1340 type->elems++;
1341 }
1342 }
1343
1344 /* Empty/missing type is not a successful parse. */
1345 if (type->elems == 0)
1346 return FAIL;
1347
1348 *str = ptr;
1349
1350 return SUCCESS;
1351}
1352
1353/* Errors may be set multiple times during parsing or bit encoding
1354 (particularly in the Neon bits), but usually the earliest error which is set
1355 will be the most meaningful. Avoid overwriting it with later (cascading)
1356 errors by calling this function. */
1357
1358static void
1359first_error (const char *err)
1360{
1361 if (!inst.error)
1362 inst.error = err;
1363}
1364
1365/* Parse a single type, e.g. ".s32", leading period included. */
1366static int
1367parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1368{
1369 char *str = *ccp;
1370 struct neon_type optype;
1371
1372 if (*str == '.')
1373 {
1374 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1375 {
1376 if (optype.elems == 1)
1377 *vectype = optype.el[0];
1378 else
1379 {
1380 first_error (_("only one type should be specified for operand"));
1381 return FAIL;
1382 }
1383 }
dcbf9037 1384 else
477330fc
RM
1385 {
1386 first_error (_("vector type expected"));
1387 return FAIL;
1388 }
dcbf9037
JB
1389 }
1390 else
1391 return FAIL;
5f4273c7 1392
dcbf9037 1393 *ccp = str;
5f4273c7 1394
dcbf9037
JB
1395 return SUCCESS;
1396}
1397
1398/* Special meanings for indices (which have a range of 0-7), which will fit into
1399 a 4-bit integer. */
1400
1401#define NEON_ALL_LANES 15
1402#define NEON_INTERLEAVE_LANES 14
1403
1404/* Parse either a register or a scalar, with an optional type. Return the
1405 register number, and optionally fill in the actual type of the register
1406 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1407 type/index information in *TYPEINFO. */
1408
1409static int
1410parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1411 enum arm_reg_type *rtype,
1412 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1413{
1414 char *str = *ccp;
1415 struct reg_entry *reg = arm_reg_parse_multi (&str);
1416 struct neon_typed_alias atype;
1417 struct neon_type_el parsetype;
1418
1419 atype.defined = 0;
1420 atype.index = -1;
1421 atype.eltype.type = NT_invtype;
1422 atype.eltype.size = -1;
1423
1424 /* Try alternate syntax for some types of register. Note these are mutually
1425 exclusive with the Neon syntax extensions. */
1426 if (reg == NULL)
1427 {
1428 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1429 if (altreg != FAIL)
477330fc 1430 *ccp = str;
dcbf9037 1431 if (typeinfo)
477330fc 1432 *typeinfo = atype;
dcbf9037
JB
1433 return altreg;
1434 }
1435
037e8744
JB
1436 /* Undo polymorphism when a set of register types may be accepted. */
1437 if ((type == REG_TYPE_NDQ
1438 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1439 || (type == REG_TYPE_VFSD
477330fc 1440 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1441 || (type == REG_TYPE_NSDQ
477330fc
RM
1442 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1443 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1444 || (type == REG_TYPE_MMXWC
1445 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1446 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1447
1448 if (type != reg->type)
1449 return FAIL;
1450
1451 if (reg->neon)
1452 atype = *reg->neon;
5f4273c7 1453
dcbf9037
JB
1454 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1455 {
1456 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1457 {
1458 first_error (_("can't redefine type for operand"));
1459 return FAIL;
1460 }
dcbf9037
JB
1461 atype.defined |= NTA_HASTYPE;
1462 atype.eltype = parsetype;
1463 }
5f4273c7 1464
dcbf9037
JB
1465 if (skip_past_char (&str, '[') == SUCCESS)
1466 {
1467 if (type != REG_TYPE_VFD)
477330fc
RM
1468 {
1469 first_error (_("only D registers may be indexed"));
1470 return FAIL;
1471 }
5f4273c7 1472
dcbf9037 1473 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1474 {
1475 first_error (_("can't change index for operand"));
1476 return FAIL;
1477 }
dcbf9037
JB
1478
1479 atype.defined |= NTA_HASINDEX;
1480
1481 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1482 atype.index = NEON_ALL_LANES;
dcbf9037 1483 else
477330fc
RM
1484 {
1485 expressionS exp;
dcbf9037 1486
477330fc 1487 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1488
477330fc
RM
1489 if (exp.X_op != O_constant)
1490 {
1491 first_error (_("constant expression required"));
1492 return FAIL;
1493 }
dcbf9037 1494
477330fc
RM
1495 if (skip_past_char (&str, ']') == FAIL)
1496 return FAIL;
dcbf9037 1497
477330fc
RM
1498 atype.index = exp.X_add_number;
1499 }
dcbf9037 1500 }
5f4273c7 1501
dcbf9037
JB
1502 if (typeinfo)
1503 *typeinfo = atype;
5f4273c7 1504
dcbf9037
JB
1505 if (rtype)
1506 *rtype = type;
5f4273c7 1507
dcbf9037 1508 *ccp = str;
5f4273c7 1509
dcbf9037
JB
1510 return reg->number;
1511}
1512
1513/* Like arm_reg_parse, but allow allow the following extra features:
1514 - If RTYPE is non-zero, return the (possibly restricted) type of the
1515 register (e.g. Neon double or quad reg when either has been requested).
1516 - If this is a Neon vector type with additional type information, fill
1517 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1518 This function will fault on encountering a scalar. */
dcbf9037
JB
1519
1520static int
1521arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1522 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1523{
1524 struct neon_typed_alias atype;
1525 char *str = *ccp;
1526 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1527
1528 if (reg == FAIL)
1529 return FAIL;
1530
0855e32b
NS
1531 /* Do not allow regname(... to parse as a register. */
1532 if (*str == '(')
1533 return FAIL;
1534
dcbf9037
JB
1535 /* Do not allow a scalar (reg+index) to parse as a register. */
1536 if ((atype.defined & NTA_HASINDEX) != 0)
1537 {
1538 first_error (_("register operand expected, but got scalar"));
1539 return FAIL;
1540 }
1541
1542 if (vectype)
1543 *vectype = atype.eltype;
1544
1545 *ccp = str;
1546
1547 return reg;
1548}
1549
1550#define NEON_SCALAR_REG(X) ((X) >> 4)
1551#define NEON_SCALAR_INDEX(X) ((X) & 15)
1552
5287ad62
JB
1553/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1554 have enough information to be able to do a good job bounds-checking. So, we
1555 just do easy checks here, and do further checks later. */
1556
1557static int
dcbf9037 1558parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1559{
dcbf9037 1560 int reg;
5287ad62 1561 char *str = *ccp;
dcbf9037 1562 struct neon_typed_alias atype;
5f4273c7 1563
dcbf9037 1564 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1565
dcbf9037 1566 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1567 return FAIL;
5f4273c7 1568
dcbf9037 1569 if (atype.index == NEON_ALL_LANES)
5287ad62 1570 {
dcbf9037 1571 first_error (_("scalar must have an index"));
5287ad62
JB
1572 return FAIL;
1573 }
dcbf9037 1574 else if (atype.index >= 64 / elsize)
5287ad62 1575 {
dcbf9037 1576 first_error (_("scalar index out of range"));
5287ad62
JB
1577 return FAIL;
1578 }
5f4273c7 1579
dcbf9037
JB
1580 if (type)
1581 *type = atype.eltype;
5f4273c7 1582
5287ad62 1583 *ccp = str;
5f4273c7 1584
dcbf9037 1585 return reg * 16 + atype.index;
5287ad62
JB
1586}
1587
c19d1205 1588/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1589
c19d1205
ZW
1590static long
1591parse_reg_list (char ** strp)
1592{
1593 char * str = * strp;
1594 long range = 0;
1595 int another_range;
a737bd4d 1596
c19d1205
ZW
1597 /* We come back here if we get ranges concatenated by '+' or '|'. */
1598 do
6057a28f 1599 {
477330fc
RM
1600 skip_whitespace (str);
1601
c19d1205 1602 another_range = 0;
a737bd4d 1603
c19d1205
ZW
1604 if (*str == '{')
1605 {
1606 int in_range = 0;
1607 int cur_reg = -1;
a737bd4d 1608
c19d1205
ZW
1609 str++;
1610 do
1611 {
1612 int reg;
6057a28f 1613
dcbf9037 1614 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1615 {
dcbf9037 1616 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1617 return FAIL;
1618 }
a737bd4d 1619
c19d1205
ZW
1620 if (in_range)
1621 {
1622 int i;
a737bd4d 1623
c19d1205
ZW
1624 if (reg <= cur_reg)
1625 {
dcbf9037 1626 first_error (_("bad range in register list"));
c19d1205
ZW
1627 return FAIL;
1628 }
40a18ebd 1629
c19d1205
ZW
1630 for (i = cur_reg + 1; i < reg; i++)
1631 {
1632 if (range & (1 << i))
1633 as_tsktsk
1634 (_("Warning: duplicated register (r%d) in register list"),
1635 i);
1636 else
1637 range |= 1 << i;
1638 }
1639 in_range = 0;
1640 }
a737bd4d 1641
c19d1205
ZW
1642 if (range & (1 << reg))
1643 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1644 reg);
1645 else if (reg <= cur_reg)
1646 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1647
c19d1205
ZW
1648 range |= 1 << reg;
1649 cur_reg = reg;
1650 }
1651 while (skip_past_comma (&str) != FAIL
1652 || (in_range = 1, *str++ == '-'));
1653 str--;
a737bd4d 1654
d996d970 1655 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1656 {
dcbf9037 1657 first_error (_("missing `}'"));
c19d1205
ZW
1658 return FAIL;
1659 }
1660 }
1661 else
1662 {
91d6fa6a 1663 expressionS exp;
40a18ebd 1664
91d6fa6a 1665 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1666 return FAIL;
40a18ebd 1667
91d6fa6a 1668 if (exp.X_op == O_constant)
c19d1205 1669 {
91d6fa6a
NC
1670 if (exp.X_add_number
1671 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1672 {
1673 inst.error = _("invalid register mask");
1674 return FAIL;
1675 }
a737bd4d 1676
91d6fa6a 1677 if ((range & exp.X_add_number) != 0)
c19d1205 1678 {
91d6fa6a 1679 int regno = range & exp.X_add_number;
a737bd4d 1680
c19d1205
ZW
1681 regno &= -regno;
1682 regno = (1 << regno) - 1;
1683 as_tsktsk
1684 (_("Warning: duplicated register (r%d) in register list"),
1685 regno);
1686 }
a737bd4d 1687
91d6fa6a 1688 range |= exp.X_add_number;
c19d1205
ZW
1689 }
1690 else
1691 {
1692 if (inst.reloc.type != 0)
1693 {
1694 inst.error = _("expression too complex");
1695 return FAIL;
1696 }
a737bd4d 1697
91d6fa6a 1698 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1699 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1700 inst.reloc.pc_rel = 0;
1701 }
1702 }
a737bd4d 1703
c19d1205
ZW
1704 if (*str == '|' || *str == '+')
1705 {
1706 str++;
1707 another_range = 1;
1708 }
a737bd4d 1709 }
c19d1205 1710 while (another_range);
a737bd4d 1711
c19d1205
ZW
1712 *strp = str;
1713 return range;
a737bd4d
NC
1714}
1715
5287ad62
JB
1716/* Types of registers in a list. */
1717
1718enum reg_list_els
1719{
1720 REGLIST_VFP_S,
1721 REGLIST_VFP_D,
1722 REGLIST_NEON_D
1723};
1724
c19d1205
ZW
1725/* Parse a VFP register list. If the string is invalid return FAIL.
1726 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1727 register. Parses registers of type ETYPE.
1728 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1729 - Q registers can be used to specify pairs of D registers
1730 - { } can be omitted from around a singleton register list
477330fc
RM
1731 FIXME: This is not implemented, as it would require backtracking in
1732 some cases, e.g.:
1733 vtbl.8 d3,d4,d5
1734 This could be done (the meaning isn't really ambiguous), but doesn't
1735 fit in well with the current parsing framework.
dcbf9037
JB
1736 - 32 D registers may be used (also true for VFPv3).
1737 FIXME: Types are ignored in these register lists, which is probably a
1738 bug. */
6057a28f 1739
c19d1205 1740static int
037e8744 1741parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1742{
037e8744 1743 char *str = *ccp;
c19d1205
ZW
1744 int base_reg;
1745 int new_base;
21d799b5 1746 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1747 int max_regs = 0;
c19d1205
ZW
1748 int count = 0;
1749 int warned = 0;
1750 unsigned long mask = 0;
a737bd4d 1751 int i;
6057a28f 1752
477330fc 1753 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1754 {
1755 inst.error = _("expecting {");
1756 return FAIL;
1757 }
6057a28f 1758
5287ad62 1759 switch (etype)
c19d1205 1760 {
5287ad62 1761 case REGLIST_VFP_S:
c19d1205
ZW
1762 regtype = REG_TYPE_VFS;
1763 max_regs = 32;
5287ad62 1764 break;
5f4273c7 1765
5287ad62
JB
1766 case REGLIST_VFP_D:
1767 regtype = REG_TYPE_VFD;
b7fc2769 1768 break;
5f4273c7 1769
b7fc2769
JB
1770 case REGLIST_NEON_D:
1771 regtype = REG_TYPE_NDQ;
1772 break;
1773 }
1774
1775 if (etype != REGLIST_VFP_S)
1776 {
b1cc4aeb
PB
1777 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1778 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1779 {
1780 max_regs = 32;
1781 if (thumb_mode)
1782 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1783 fpu_vfp_ext_d32);
1784 else
1785 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1786 fpu_vfp_ext_d32);
1787 }
5287ad62 1788 else
477330fc 1789 max_regs = 16;
c19d1205 1790 }
6057a28f 1791
c19d1205 1792 base_reg = max_regs;
a737bd4d 1793
c19d1205
ZW
1794 do
1795 {
5287ad62 1796 int setmask = 1, addregs = 1;
dcbf9037 1797
037e8744 1798 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1799
c19d1205 1800 if (new_base == FAIL)
a737bd4d 1801 {
dcbf9037 1802 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1803 return FAIL;
1804 }
5f4273c7 1805
b7fc2769 1806 if (new_base >= max_regs)
477330fc
RM
1807 {
1808 first_error (_("register out of range in list"));
1809 return FAIL;
1810 }
5f4273c7 1811
5287ad62
JB
1812 /* Note: a value of 2 * n is returned for the register Q<n>. */
1813 if (regtype == REG_TYPE_NQ)
477330fc
RM
1814 {
1815 setmask = 3;
1816 addregs = 2;
1817 }
5287ad62 1818
c19d1205
ZW
1819 if (new_base < base_reg)
1820 base_reg = new_base;
a737bd4d 1821
5287ad62 1822 if (mask & (setmask << new_base))
c19d1205 1823 {
dcbf9037 1824 first_error (_("invalid register list"));
c19d1205 1825 return FAIL;
a737bd4d 1826 }
a737bd4d 1827
c19d1205
ZW
1828 if ((mask >> new_base) != 0 && ! warned)
1829 {
1830 as_tsktsk (_("register list not in ascending order"));
1831 warned = 1;
1832 }
0bbf2aa4 1833
5287ad62
JB
1834 mask |= setmask << new_base;
1835 count += addregs;
0bbf2aa4 1836
037e8744 1837 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1838 {
1839 int high_range;
0bbf2aa4 1840
037e8744 1841 str++;
0bbf2aa4 1842
037e8744 1843 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1844 == FAIL)
c19d1205
ZW
1845 {
1846 inst.error = gettext (reg_expected_msgs[regtype]);
1847 return FAIL;
1848 }
0bbf2aa4 1849
477330fc
RM
1850 if (high_range >= max_regs)
1851 {
1852 first_error (_("register out of range in list"));
1853 return FAIL;
1854 }
b7fc2769 1855
477330fc
RM
1856 if (regtype == REG_TYPE_NQ)
1857 high_range = high_range + 1;
5287ad62 1858
c19d1205
ZW
1859 if (high_range <= new_base)
1860 {
1861 inst.error = _("register range not in ascending order");
1862 return FAIL;
1863 }
0bbf2aa4 1864
5287ad62 1865 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1866 {
5287ad62 1867 if (mask & (setmask << new_base))
0bbf2aa4 1868 {
c19d1205
ZW
1869 inst.error = _("invalid register list");
1870 return FAIL;
0bbf2aa4 1871 }
c19d1205 1872
5287ad62
JB
1873 mask |= setmask << new_base;
1874 count += addregs;
0bbf2aa4 1875 }
0bbf2aa4 1876 }
0bbf2aa4 1877 }
037e8744 1878 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1879
037e8744 1880 str++;
0bbf2aa4 1881
c19d1205
ZW
1882 /* Sanity check -- should have raised a parse error above. */
1883 if (count == 0 || count > max_regs)
1884 abort ();
1885
1886 *pbase = base_reg;
1887
1888 /* Final test -- the registers must be consecutive. */
1889 mask >>= base_reg;
1890 for (i = 0; i < count; i++)
1891 {
1892 if ((mask & (1u << i)) == 0)
1893 {
1894 inst.error = _("non-contiguous register range");
1895 return FAIL;
1896 }
1897 }
1898
037e8744
JB
1899 *ccp = str;
1900
c19d1205 1901 return count;
b99bd4ef
NC
1902}
1903
dcbf9037
JB
1904/* True if two alias types are the same. */
1905
c921be7d 1906static bfd_boolean
dcbf9037
JB
1907neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1908{
1909 if (!a && !b)
c921be7d 1910 return TRUE;
5f4273c7 1911
dcbf9037 1912 if (!a || !b)
c921be7d 1913 return FALSE;
dcbf9037
JB
1914
1915 if (a->defined != b->defined)
c921be7d 1916 return FALSE;
5f4273c7 1917
dcbf9037
JB
1918 if ((a->defined & NTA_HASTYPE) != 0
1919 && (a->eltype.type != b->eltype.type
477330fc 1920 || a->eltype.size != b->eltype.size))
c921be7d 1921 return FALSE;
dcbf9037
JB
1922
1923 if ((a->defined & NTA_HASINDEX) != 0
1924 && (a->index != b->index))
c921be7d 1925 return FALSE;
5f4273c7 1926
c921be7d 1927 return TRUE;
dcbf9037
JB
1928}
1929
5287ad62
JB
1930/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1931 The base register is put in *PBASE.
dcbf9037 1932 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1933 the return value.
1934 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1935 Bits [6:5] encode the list length (minus one).
1936 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1937
5287ad62 1938#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1939#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1940#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1941
1942static int
dcbf9037 1943parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 1944 struct neon_type_el *eltype)
5287ad62
JB
1945{
1946 char *ptr = *str;
1947 int base_reg = -1;
1948 int reg_incr = -1;
1949 int count = 0;
1950 int lane = -1;
1951 int leading_brace = 0;
1952 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1953 const char *const incr_error = _("register stride must be 1 or 2");
1954 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1955 struct neon_typed_alias firsttype;
5f4273c7 1956
5287ad62
JB
1957 if (skip_past_char (&ptr, '{') == SUCCESS)
1958 leading_brace = 1;
5f4273c7 1959
5287ad62
JB
1960 do
1961 {
dcbf9037
JB
1962 struct neon_typed_alias atype;
1963 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1964
5287ad62 1965 if (getreg == FAIL)
477330fc
RM
1966 {
1967 first_error (_(reg_expected_msgs[rtype]));
1968 return FAIL;
1969 }
5f4273c7 1970
5287ad62 1971 if (base_reg == -1)
477330fc
RM
1972 {
1973 base_reg = getreg;
1974 if (rtype == REG_TYPE_NQ)
1975 {
1976 reg_incr = 1;
1977 }
1978 firsttype = atype;
1979 }
5287ad62 1980 else if (reg_incr == -1)
477330fc
RM
1981 {
1982 reg_incr = getreg - base_reg;
1983 if (reg_incr < 1 || reg_incr > 2)
1984 {
1985 first_error (_(incr_error));
1986 return FAIL;
1987 }
1988 }
5287ad62 1989 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
1990 {
1991 first_error (_(incr_error));
1992 return FAIL;
1993 }
dcbf9037 1994
c921be7d 1995 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
1996 {
1997 first_error (_(type_error));
1998 return FAIL;
1999 }
5f4273c7 2000
5287ad62 2001 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2002 modes. */
5287ad62 2003 if (ptr[0] == '-')
477330fc
RM
2004 {
2005 struct neon_typed_alias htype;
2006 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2007 if (lane == -1)
2008 lane = NEON_INTERLEAVE_LANES;
2009 else if (lane != NEON_INTERLEAVE_LANES)
2010 {
2011 first_error (_(type_error));
2012 return FAIL;
2013 }
2014 if (reg_incr == -1)
2015 reg_incr = 1;
2016 else if (reg_incr != 1)
2017 {
2018 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2019 return FAIL;
2020 }
2021 ptr++;
2022 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2023 if (hireg == FAIL)
2024 {
2025 first_error (_(reg_expected_msgs[rtype]));
2026 return FAIL;
2027 }
2028 if (! neon_alias_types_same (&htype, &firsttype))
2029 {
2030 first_error (_(type_error));
2031 return FAIL;
2032 }
2033 count += hireg + dregs - getreg;
2034 continue;
2035 }
5f4273c7 2036
5287ad62
JB
2037 /* If we're using Q registers, we can't use [] or [n] syntax. */
2038 if (rtype == REG_TYPE_NQ)
477330fc
RM
2039 {
2040 count += 2;
2041 continue;
2042 }
5f4273c7 2043
dcbf9037 2044 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2045 {
2046 if (lane == -1)
2047 lane = atype.index;
2048 else if (lane != atype.index)
2049 {
2050 first_error (_(type_error));
2051 return FAIL;
2052 }
2053 }
5287ad62 2054 else if (lane == -1)
477330fc 2055 lane = NEON_INTERLEAVE_LANES;
5287ad62 2056 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2057 {
2058 first_error (_(type_error));
2059 return FAIL;
2060 }
5287ad62
JB
2061 count++;
2062 }
2063 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2064
5287ad62
JB
2065 /* No lane set by [x]. We must be interleaving structures. */
2066 if (lane == -1)
2067 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2068
5287ad62
JB
2069 /* Sanity check. */
2070 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2071 || (count > 1 && reg_incr == -1))
2072 {
dcbf9037 2073 first_error (_("error parsing element/structure list"));
5287ad62
JB
2074 return FAIL;
2075 }
2076
2077 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2078 {
dcbf9037 2079 first_error (_("expected }"));
5287ad62
JB
2080 return FAIL;
2081 }
5f4273c7 2082
5287ad62
JB
2083 if (reg_incr == -1)
2084 reg_incr = 1;
2085
dcbf9037
JB
2086 if (eltype)
2087 *eltype = firsttype.eltype;
2088
5287ad62
JB
2089 *pbase = base_reg;
2090 *str = ptr;
5f4273c7 2091
5287ad62
JB
2092 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2093}
2094
c19d1205
ZW
2095/* Parse an explicit relocation suffix on an expression. This is
2096 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2097 arm_reloc_hsh contains no entries, so this function can only
2098 succeed if there is no () after the word. Returns -1 on error,
2099 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2100
c19d1205
ZW
2101static int
2102parse_reloc (char **str)
b99bd4ef 2103{
c19d1205
ZW
2104 struct reloc_entry *r;
2105 char *p, *q;
b99bd4ef 2106
c19d1205
ZW
2107 if (**str != '(')
2108 return BFD_RELOC_UNUSED;
b99bd4ef 2109
c19d1205
ZW
2110 p = *str + 1;
2111 q = p;
2112
2113 while (*q && *q != ')' && *q != ',')
2114 q++;
2115 if (*q != ')')
2116 return -1;
2117
21d799b5
NC
2118 if ((r = (struct reloc_entry *)
2119 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2120 return -1;
2121
2122 *str = q + 1;
2123 return r->reloc;
b99bd4ef
NC
2124}
2125
c19d1205
ZW
2126/* Directives: register aliases. */
2127
dcbf9037 2128static struct reg_entry *
90ec0d68 2129insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2130{
d3ce72d0 2131 struct reg_entry *new_reg;
c19d1205 2132 const char *name;
b99bd4ef 2133
d3ce72d0 2134 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2135 {
d3ce72d0 2136 if (new_reg->builtin)
c19d1205 2137 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2138
c19d1205
ZW
2139 /* Only warn about a redefinition if it's not defined as the
2140 same register. */
d3ce72d0 2141 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2142 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2143
d929913e 2144 return NULL;
c19d1205 2145 }
b99bd4ef 2146
c19d1205 2147 name = xstrdup (str);
d3ce72d0 2148 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2149
d3ce72d0
NC
2150 new_reg->name = name;
2151 new_reg->number = number;
2152 new_reg->type = type;
2153 new_reg->builtin = FALSE;
2154 new_reg->neon = NULL;
b99bd4ef 2155
d3ce72d0 2156 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2157 abort ();
5f4273c7 2158
d3ce72d0 2159 return new_reg;
dcbf9037
JB
2160}
2161
2162static void
2163insert_neon_reg_alias (char *str, int number, int type,
477330fc 2164 struct neon_typed_alias *atype)
dcbf9037
JB
2165{
2166 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2167
dcbf9037
JB
2168 if (!reg)
2169 {
2170 first_error (_("attempt to redefine typed alias"));
2171 return;
2172 }
5f4273c7 2173
dcbf9037
JB
2174 if (atype)
2175 {
21d799b5 2176 reg->neon = (struct neon_typed_alias *)
477330fc 2177 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2178 *reg->neon = *atype;
2179 }
c19d1205 2180}
b99bd4ef 2181
c19d1205 2182/* Look for the .req directive. This is of the form:
b99bd4ef 2183
c19d1205 2184 new_register_name .req existing_register_name
b99bd4ef 2185
c19d1205 2186 If we find one, or if it looks sufficiently like one that we want to
d929913e 2187 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2188
d929913e 2189static bfd_boolean
c19d1205
ZW
2190create_register_alias (char * newname, char *p)
2191{
2192 struct reg_entry *old;
2193 char *oldname, *nbuf;
2194 size_t nlen;
b99bd4ef 2195
c19d1205
ZW
2196 /* The input scrubber ensures that whitespace after the mnemonic is
2197 collapsed to single spaces. */
2198 oldname = p;
2199 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2200 return FALSE;
b99bd4ef 2201
c19d1205
ZW
2202 oldname += 6;
2203 if (*oldname == '\0')
d929913e 2204 return FALSE;
b99bd4ef 2205
21d799b5 2206 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2207 if (!old)
b99bd4ef 2208 {
c19d1205 2209 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2210 return TRUE;
b99bd4ef
NC
2211 }
2212
c19d1205
ZW
2213 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2214 the desired alias name, and p points to its end. If not, then
2215 the desired alias name is in the global original_case_string. */
2216#ifdef TC_CASE_SENSITIVE
2217 nlen = p - newname;
2218#else
2219 newname = original_case_string;
2220 nlen = strlen (newname);
2221#endif
b99bd4ef 2222
21d799b5 2223 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2224 memcpy (nbuf, newname, nlen);
2225 nbuf[nlen] = '\0';
b99bd4ef 2226
c19d1205
ZW
2227 /* Create aliases under the new name as stated; an all-lowercase
2228 version of the new name; and an all-uppercase version of the new
2229 name. */
d929913e
NC
2230 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2231 {
2232 for (p = nbuf; *p; p++)
2233 *p = TOUPPER (*p);
c19d1205 2234
d929913e
NC
2235 if (strncmp (nbuf, newname, nlen))
2236 {
2237 /* If this attempt to create an additional alias fails, do not bother
2238 trying to create the all-lower case alias. We will fail and issue
2239 a second, duplicate error message. This situation arises when the
2240 programmer does something like:
2241 foo .req r0
2242 Foo .req r1
2243 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2244 the artificial FOO alias because it has already been created by the
d929913e
NC
2245 first .req. */
2246 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2247 return TRUE;
2248 }
c19d1205 2249
d929913e
NC
2250 for (p = nbuf; *p; p++)
2251 *p = TOLOWER (*p);
c19d1205 2252
d929913e
NC
2253 if (strncmp (nbuf, newname, nlen))
2254 insert_reg_alias (nbuf, old->number, old->type);
2255 }
c19d1205 2256
d929913e 2257 return TRUE;
b99bd4ef
NC
2258}
2259
dcbf9037
JB
2260/* Create a Neon typed/indexed register alias using directives, e.g.:
2261 X .dn d5.s32[1]
2262 Y .qn 6.s16
2263 Z .dn d7
2264 T .dn Z[0]
2265 These typed registers can be used instead of the types specified after the
2266 Neon mnemonic, so long as all operands given have types. Types can also be
2267 specified directly, e.g.:
5f4273c7 2268 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2269
c921be7d 2270static bfd_boolean
dcbf9037
JB
2271create_neon_reg_alias (char *newname, char *p)
2272{
2273 enum arm_reg_type basetype;
2274 struct reg_entry *basereg;
2275 struct reg_entry mybasereg;
2276 struct neon_type ntype;
2277 struct neon_typed_alias typeinfo;
12d6b0b7 2278 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2279 int namelen;
5f4273c7 2280
dcbf9037
JB
2281 typeinfo.defined = 0;
2282 typeinfo.eltype.type = NT_invtype;
2283 typeinfo.eltype.size = -1;
2284 typeinfo.index = -1;
5f4273c7 2285
dcbf9037 2286 nameend = p;
5f4273c7 2287
dcbf9037
JB
2288 if (strncmp (p, " .dn ", 5) == 0)
2289 basetype = REG_TYPE_VFD;
2290 else if (strncmp (p, " .qn ", 5) == 0)
2291 basetype = REG_TYPE_NQ;
2292 else
c921be7d 2293 return FALSE;
5f4273c7 2294
dcbf9037 2295 p += 5;
5f4273c7 2296
dcbf9037 2297 if (*p == '\0')
c921be7d 2298 return FALSE;
5f4273c7 2299
dcbf9037
JB
2300 basereg = arm_reg_parse_multi (&p);
2301
2302 if (basereg && basereg->type != basetype)
2303 {
2304 as_bad (_("bad type for register"));
c921be7d 2305 return FALSE;
dcbf9037
JB
2306 }
2307
2308 if (basereg == NULL)
2309 {
2310 expressionS exp;
2311 /* Try parsing as an integer. */
2312 my_get_expression (&exp, &p, GE_NO_PREFIX);
2313 if (exp.X_op != O_constant)
477330fc
RM
2314 {
2315 as_bad (_("expression must be constant"));
2316 return FALSE;
2317 }
dcbf9037
JB
2318 basereg = &mybasereg;
2319 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2320 : exp.X_add_number;
dcbf9037
JB
2321 basereg->neon = 0;
2322 }
2323
2324 if (basereg->neon)
2325 typeinfo = *basereg->neon;
2326
2327 if (parse_neon_type (&ntype, &p) == SUCCESS)
2328 {
2329 /* We got a type. */
2330 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2331 {
2332 as_bad (_("can't redefine the type of a register alias"));
2333 return FALSE;
2334 }
5f4273c7 2335
dcbf9037
JB
2336 typeinfo.defined |= NTA_HASTYPE;
2337 if (ntype.elems != 1)
477330fc
RM
2338 {
2339 as_bad (_("you must specify a single type only"));
2340 return FALSE;
2341 }
dcbf9037
JB
2342 typeinfo.eltype = ntype.el[0];
2343 }
5f4273c7 2344
dcbf9037
JB
2345 if (skip_past_char (&p, '[') == SUCCESS)
2346 {
2347 expressionS exp;
2348 /* We got a scalar index. */
5f4273c7 2349
dcbf9037 2350 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2351 {
2352 as_bad (_("can't redefine the index of a scalar alias"));
2353 return FALSE;
2354 }
5f4273c7 2355
dcbf9037 2356 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2357
dcbf9037 2358 if (exp.X_op != O_constant)
477330fc
RM
2359 {
2360 as_bad (_("scalar index must be constant"));
2361 return FALSE;
2362 }
5f4273c7 2363
dcbf9037
JB
2364 typeinfo.defined |= NTA_HASINDEX;
2365 typeinfo.index = exp.X_add_number;
5f4273c7 2366
dcbf9037 2367 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2368 {
2369 as_bad (_("expecting ]"));
2370 return FALSE;
2371 }
dcbf9037
JB
2372 }
2373
15735687
NS
2374 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2375 the desired alias name, and p points to its end. If not, then
2376 the desired alias name is in the global original_case_string. */
2377#ifdef TC_CASE_SENSITIVE
dcbf9037 2378 namelen = nameend - newname;
15735687
NS
2379#else
2380 newname = original_case_string;
2381 namelen = strlen (newname);
2382#endif
2383
21d799b5 2384 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2385 strncpy (namebuf, newname, namelen);
2386 namebuf[namelen] = '\0';
5f4273c7 2387
dcbf9037 2388 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2389 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2390
dcbf9037
JB
2391 /* Insert name in all uppercase. */
2392 for (p = namebuf; *p; p++)
2393 *p = TOUPPER (*p);
5f4273c7 2394
dcbf9037
JB
2395 if (strncmp (namebuf, newname, namelen))
2396 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2397 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2398
dcbf9037
JB
2399 /* Insert name in all lowercase. */
2400 for (p = namebuf; *p; p++)
2401 *p = TOLOWER (*p);
5f4273c7 2402
dcbf9037
JB
2403 if (strncmp (namebuf, newname, namelen))
2404 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2405 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2406
c921be7d 2407 return TRUE;
dcbf9037
JB
2408}
2409
c19d1205
ZW
2410/* Should never be called, as .req goes between the alias and the
2411 register name, not at the beginning of the line. */
c921be7d 2412
b99bd4ef 2413static void
c19d1205 2414s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2415{
c19d1205
ZW
2416 as_bad (_("invalid syntax for .req directive"));
2417}
b99bd4ef 2418
dcbf9037
JB
2419static void
2420s_dn (int a ATTRIBUTE_UNUSED)
2421{
2422 as_bad (_("invalid syntax for .dn directive"));
2423}
2424
2425static void
2426s_qn (int a ATTRIBUTE_UNUSED)
2427{
2428 as_bad (_("invalid syntax for .qn directive"));
2429}
2430
c19d1205
ZW
2431/* The .unreq directive deletes an alias which was previously defined
2432 by .req. For example:
b99bd4ef 2433
c19d1205
ZW
2434 my_alias .req r11
2435 .unreq my_alias */
b99bd4ef
NC
2436
2437static void
c19d1205 2438s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2439{
c19d1205
ZW
2440 char * name;
2441 char saved_char;
b99bd4ef 2442
c19d1205
ZW
2443 name = input_line_pointer;
2444
2445 while (*input_line_pointer != 0
2446 && *input_line_pointer != ' '
2447 && *input_line_pointer != '\n')
2448 ++input_line_pointer;
2449
2450 saved_char = *input_line_pointer;
2451 *input_line_pointer = 0;
2452
2453 if (!*name)
2454 as_bad (_("invalid syntax for .unreq directive"));
2455 else
2456 {
21d799b5 2457 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2458 name);
c19d1205
ZW
2459
2460 if (!reg)
2461 as_bad (_("unknown register alias '%s'"), name);
2462 else if (reg->builtin)
a1727c1a 2463 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2464 name);
2465 else
2466 {
d929913e
NC
2467 char * p;
2468 char * nbuf;
2469
db0bc284 2470 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2471 free ((char *) reg->name);
477330fc
RM
2472 if (reg->neon)
2473 free (reg->neon);
c19d1205 2474 free (reg);
d929913e
NC
2475
2476 /* Also locate the all upper case and all lower case versions.
2477 Do not complain if we cannot find one or the other as it
2478 was probably deleted above. */
5f4273c7 2479
d929913e
NC
2480 nbuf = strdup (name);
2481 for (p = nbuf; *p; p++)
2482 *p = TOUPPER (*p);
21d799b5 2483 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2484 if (reg)
2485 {
db0bc284 2486 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2487 free ((char *) reg->name);
2488 if (reg->neon)
2489 free (reg->neon);
2490 free (reg);
2491 }
2492
2493 for (p = nbuf; *p; p++)
2494 *p = TOLOWER (*p);
21d799b5 2495 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2496 if (reg)
2497 {
db0bc284 2498 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2499 free ((char *) reg->name);
2500 if (reg->neon)
2501 free (reg->neon);
2502 free (reg);
2503 }
2504
2505 free (nbuf);
c19d1205
ZW
2506 }
2507 }
b99bd4ef 2508
c19d1205 2509 *input_line_pointer = saved_char;
b99bd4ef
NC
2510 demand_empty_rest_of_line ();
2511}
2512
c19d1205
ZW
2513/* Directives: Instruction set selection. */
2514
2515#ifdef OBJ_ELF
2516/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2517 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2518 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2519 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2520
cd000bff
DJ
2521/* Create a new mapping symbol for the transition to STATE. */
2522
2523static void
2524make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2525{
a737bd4d 2526 symbolS * symbolP;
c19d1205
ZW
2527 const char * symname;
2528 int type;
b99bd4ef 2529
c19d1205 2530 switch (state)
b99bd4ef 2531 {
c19d1205
ZW
2532 case MAP_DATA:
2533 symname = "$d";
2534 type = BSF_NO_FLAGS;
2535 break;
2536 case MAP_ARM:
2537 symname = "$a";
2538 type = BSF_NO_FLAGS;
2539 break;
2540 case MAP_THUMB:
2541 symname = "$t";
2542 type = BSF_NO_FLAGS;
2543 break;
c19d1205
ZW
2544 default:
2545 abort ();
2546 }
2547
cd000bff 2548 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2549 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2550
2551 switch (state)
2552 {
2553 case MAP_ARM:
2554 THUMB_SET_FUNC (symbolP, 0);
2555 ARM_SET_THUMB (symbolP, 0);
2556 ARM_SET_INTERWORK (symbolP, support_interwork);
2557 break;
2558
2559 case MAP_THUMB:
2560 THUMB_SET_FUNC (symbolP, 1);
2561 ARM_SET_THUMB (symbolP, 1);
2562 ARM_SET_INTERWORK (symbolP, support_interwork);
2563 break;
2564
2565 case MAP_DATA:
2566 default:
cd000bff
DJ
2567 break;
2568 }
2569
2570 /* Save the mapping symbols for future reference. Also check that
2571 we do not place two mapping symbols at the same offset within a
2572 frag. We'll handle overlap between frags in
2de7820f
JZ
2573 check_mapping_symbols.
2574
2575 If .fill or other data filling directive generates zero sized data,
2576 the mapping symbol for the following code will have the same value
2577 as the one generated for the data filling directive. In this case,
2578 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2579 if (value == 0)
2580 {
2de7820f
JZ
2581 if (frag->tc_frag_data.first_map != NULL)
2582 {
2583 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2584 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2585 }
cd000bff
DJ
2586 frag->tc_frag_data.first_map = symbolP;
2587 }
2588 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2589 {
2590 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2591 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2592 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2593 }
cd000bff
DJ
2594 frag->tc_frag_data.last_map = symbolP;
2595}
2596
2597/* We must sometimes convert a region marked as code to data during
2598 code alignment, if an odd number of bytes have to be padded. The
2599 code mapping symbol is pushed to an aligned address. */
2600
2601static void
2602insert_data_mapping_symbol (enum mstate state,
2603 valueT value, fragS *frag, offsetT bytes)
2604{
2605 /* If there was already a mapping symbol, remove it. */
2606 if (frag->tc_frag_data.last_map != NULL
2607 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2608 {
2609 symbolS *symp = frag->tc_frag_data.last_map;
2610
2611 if (value == 0)
2612 {
2613 know (frag->tc_frag_data.first_map == symp);
2614 frag->tc_frag_data.first_map = NULL;
2615 }
2616 frag->tc_frag_data.last_map = NULL;
2617 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2618 }
cd000bff
DJ
2619
2620 make_mapping_symbol (MAP_DATA, value, frag);
2621 make_mapping_symbol (state, value + bytes, frag);
2622}
2623
2624static void mapping_state_2 (enum mstate state, int max_chars);
2625
2626/* Set the mapping state to STATE. Only call this when about to
2627 emit some STATE bytes to the file. */
2628
2629void
2630mapping_state (enum mstate state)
2631{
940b5ce0
DJ
2632 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2633
cd000bff
DJ
2634#define TRANSITION(from, to) (mapstate == (from) && state == (to))
2635
2636 if (mapstate == state)
2637 /* The mapping symbol has already been emitted.
2638 There is nothing else to do. */
2639 return;
49c62a33
NC
2640
2641 if (state == MAP_ARM || state == MAP_THUMB)
2642 /* PR gas/12931
2643 All ARM instructions require 4-byte alignment.
2644 (Almost) all Thumb instructions require 2-byte alignment.
2645
2646 When emitting instructions into any section, mark the section
2647 appropriately.
2648
2649 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2650 but themselves require 2-byte alignment; this applies to some
2651 PC- relative forms. However, these cases will invovle implicit
2652 literal pool generation or an explicit .align >=2, both of
2653 which will cause the section to me marked with sufficient
2654 alignment. Thus, we don't handle those cases here. */
2655 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2656
2657 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
cd000bff
DJ
2658 /* This case will be evaluated later in the next else. */
2659 return;
2660 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
477330fc 2661 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
cd000bff
DJ
2662 {
2663 /* Only add the symbol if the offset is > 0:
477330fc
RM
2664 if we're at the first frag, check it's size > 0;
2665 if we're not at the first frag, then for sure
2666 the offset is > 0. */
cd000bff
DJ
2667 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2668 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2669
2670 if (add_symbol)
477330fc 2671 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
cd000bff
DJ
2672 }
2673
2674 mapping_state_2 (state, 0);
2675#undef TRANSITION
2676}
2677
2678/* Same as mapping_state, but MAX_CHARS bytes have already been
2679 allocated. Put the mapping symbol that far back. */
2680
2681static void
2682mapping_state_2 (enum mstate state, int max_chars)
2683{
940b5ce0
DJ
2684 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2685
2686 if (!SEG_NORMAL (now_seg))
2687 return;
2688
cd000bff
DJ
2689 if (mapstate == state)
2690 /* The mapping symbol has already been emitted.
2691 There is nothing else to do. */
2692 return;
2693
cd000bff
DJ
2694 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2695 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205
ZW
2696}
2697#else
d3106081
NS
2698#define mapping_state(x) ((void)0)
2699#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2700#endif
2701
2702/* Find the real, Thumb encoded start of a Thumb function. */
2703
4343666d 2704#ifdef OBJ_COFF
c19d1205
ZW
2705static symbolS *
2706find_real_start (symbolS * symbolP)
2707{
2708 char * real_start;
2709 const char * name = S_GET_NAME (symbolP);
2710 symbolS * new_target;
2711
2712 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2713#define STUB_NAME ".real_start_of"
2714
2715 if (name == NULL)
2716 abort ();
2717
37f6032b
ZW
2718 /* The compiler may generate BL instructions to local labels because
2719 it needs to perform a branch to a far away location. These labels
2720 do not have a corresponding ".real_start_of" label. We check
2721 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2722 the ".real_start_of" convention for nonlocal branches. */
2723 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2724 return symbolP;
2725
37f6032b 2726 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2727 new_target = symbol_find (real_start);
2728
2729 if (new_target == NULL)
2730 {
bd3ba5d1 2731 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2732 new_target = symbolP;
2733 }
2734
c19d1205
ZW
2735 return new_target;
2736}
4343666d 2737#endif
c19d1205
ZW
2738
2739static void
2740opcode_select (int width)
2741{
2742 switch (width)
2743 {
2744 case 16:
2745 if (! thumb_mode)
2746 {
e74cfd16 2747 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2748 as_bad (_("selected processor does not support THUMB opcodes"));
2749
2750 thumb_mode = 1;
2751 /* No need to force the alignment, since we will have been
2752 coming from ARM mode, which is word-aligned. */
2753 record_alignment (now_seg, 1);
2754 }
c19d1205
ZW
2755 break;
2756
2757 case 32:
2758 if (thumb_mode)
2759 {
e74cfd16 2760 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2761 as_bad (_("selected processor does not support ARM opcodes"));
2762
2763 thumb_mode = 0;
2764
2765 if (!need_pass_2)
2766 frag_align (2, 0, 0);
2767
2768 record_alignment (now_seg, 1);
2769 }
c19d1205
ZW
2770 break;
2771
2772 default:
2773 as_bad (_("invalid instruction size selected (%d)"), width);
2774 }
2775}
2776
2777static void
2778s_arm (int ignore ATTRIBUTE_UNUSED)
2779{
2780 opcode_select (32);
2781 demand_empty_rest_of_line ();
2782}
2783
2784static void
2785s_thumb (int ignore ATTRIBUTE_UNUSED)
2786{
2787 opcode_select (16);
2788 demand_empty_rest_of_line ();
2789}
2790
2791static void
2792s_code (int unused ATTRIBUTE_UNUSED)
2793{
2794 int temp;
2795
2796 temp = get_absolute_expression ();
2797 switch (temp)
2798 {
2799 case 16:
2800 case 32:
2801 opcode_select (temp);
2802 break;
2803
2804 default:
2805 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2806 }
2807}
2808
2809static void
2810s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2811{
2812 /* If we are not already in thumb mode go into it, EVEN if
2813 the target processor does not support thumb instructions.
2814 This is used by gcc/config/arm/lib1funcs.asm for example
2815 to compile interworking support functions even if the
2816 target processor should not support interworking. */
2817 if (! thumb_mode)
2818 {
2819 thumb_mode = 2;
2820 record_alignment (now_seg, 1);
2821 }
2822
2823 demand_empty_rest_of_line ();
2824}
2825
2826static void
2827s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2828{
2829 s_thumb (0);
2830
2831 /* The following label is the name/address of the start of a Thumb function.
2832 We need to know this for the interworking support. */
2833 label_is_thumb_function_name = TRUE;
2834}
2835
2836/* Perform a .set directive, but also mark the alias as
2837 being a thumb function. */
2838
2839static void
2840s_thumb_set (int equiv)
2841{
2842 /* XXX the following is a duplicate of the code for s_set() in read.c
2843 We cannot just call that code as we need to get at the symbol that
2844 is created. */
2845 char * name;
2846 char delim;
2847 char * end_name;
2848 symbolS * symbolP;
2849
2850 /* Especial apologies for the random logic:
2851 This just grew, and could be parsed much more simply!
2852 Dean - in haste. */
2853 name = input_line_pointer;
2854 delim = get_symbol_end ();
2855 end_name = input_line_pointer;
2856 *end_name = delim;
2857
2858 if (*input_line_pointer != ',')
2859 {
2860 *end_name = 0;
2861 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2862 *end_name = delim;
2863 ignore_rest_of_line ();
2864 return;
2865 }
2866
2867 input_line_pointer++;
2868 *end_name = 0;
2869
2870 if (name[0] == '.' && name[1] == '\0')
2871 {
2872 /* XXX - this should not happen to .thumb_set. */
2873 abort ();
2874 }
2875
2876 if ((symbolP = symbol_find (name)) == NULL
2877 && (symbolP = md_undefined_symbol (name)) == NULL)
2878 {
2879#ifndef NO_LISTING
2880 /* When doing symbol listings, play games with dummy fragments living
2881 outside the normal fragment chain to record the file and line info
c19d1205 2882 for this symbol. */
b99bd4ef
NC
2883 if (listing & LISTING_SYMBOLS)
2884 {
2885 extern struct list_info_struct * listing_tail;
21d799b5 2886 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2887
2888 memset (dummy_frag, 0, sizeof (fragS));
2889 dummy_frag->fr_type = rs_fill;
2890 dummy_frag->line = listing_tail;
2891 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2892 dummy_frag->fr_symbol = symbolP;
2893 }
2894 else
2895#endif
2896 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2897
2898#ifdef OBJ_COFF
2899 /* "set" symbols are local unless otherwise specified. */
2900 SF_SET_LOCAL (symbolP);
2901#endif /* OBJ_COFF */
2902 } /* Make a new symbol. */
2903
2904 symbol_table_insert (symbolP);
2905
2906 * end_name = delim;
2907
2908 if (equiv
2909 && S_IS_DEFINED (symbolP)
2910 && S_GET_SEGMENT (symbolP) != reg_section)
2911 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2912
2913 pseudo_set (symbolP);
2914
2915 demand_empty_rest_of_line ();
2916
c19d1205 2917 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2918
2919 THUMB_SET_FUNC (symbolP, 1);
2920 ARM_SET_THUMB (symbolP, 1);
2921#if defined OBJ_ELF || defined OBJ_COFF
2922 ARM_SET_INTERWORK (symbolP, support_interwork);
2923#endif
2924}
2925
c19d1205 2926/* Directives: Mode selection. */
b99bd4ef 2927
c19d1205
ZW
2928/* .syntax [unified|divided] - choose the new unified syntax
2929 (same for Arm and Thumb encoding, modulo slight differences in what
2930 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2931static void
c19d1205 2932s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2933{
c19d1205
ZW
2934 char *name, delim;
2935
2936 name = input_line_pointer;
2937 delim = get_symbol_end ();
2938
2939 if (!strcasecmp (name, "unified"))
2940 unified_syntax = TRUE;
2941 else if (!strcasecmp (name, "divided"))
2942 unified_syntax = FALSE;
2943 else
2944 {
2945 as_bad (_("unrecognized syntax mode \"%s\""), name);
2946 return;
2947 }
2948 *input_line_pointer = delim;
b99bd4ef
NC
2949 demand_empty_rest_of_line ();
2950}
2951
c19d1205
ZW
2952/* Directives: sectioning and alignment. */
2953
2954/* Same as s_align_ptwo but align 0 => align 2. */
2955
b99bd4ef 2956static void
c19d1205 2957s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2958{
a737bd4d 2959 int temp;
dce323d1 2960 bfd_boolean fill_p;
c19d1205
ZW
2961 long temp_fill;
2962 long max_alignment = 15;
b99bd4ef
NC
2963
2964 temp = get_absolute_expression ();
c19d1205
ZW
2965 if (temp > max_alignment)
2966 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2967 else if (temp < 0)
b99bd4ef 2968 {
c19d1205
ZW
2969 as_bad (_("alignment negative. 0 assumed."));
2970 temp = 0;
2971 }
b99bd4ef 2972
c19d1205
ZW
2973 if (*input_line_pointer == ',')
2974 {
2975 input_line_pointer++;
2976 temp_fill = get_absolute_expression ();
dce323d1 2977 fill_p = TRUE;
b99bd4ef 2978 }
c19d1205 2979 else
dce323d1
PB
2980 {
2981 fill_p = FALSE;
2982 temp_fill = 0;
2983 }
b99bd4ef 2984
c19d1205
ZW
2985 if (!temp)
2986 temp = 2;
b99bd4ef 2987
c19d1205
ZW
2988 /* Only make a frag if we HAVE to. */
2989 if (temp && !need_pass_2)
dce323d1
PB
2990 {
2991 if (!fill_p && subseg_text_p (now_seg))
2992 frag_align_code (temp, 0);
2993 else
2994 frag_align (temp, (int) temp_fill, 0);
2995 }
c19d1205
ZW
2996 demand_empty_rest_of_line ();
2997
2998 record_alignment (now_seg, temp);
b99bd4ef
NC
2999}
3000
c19d1205
ZW
3001static void
3002s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3003{
c19d1205
ZW
3004 /* We don't support putting frags in the BSS segment, we fake it by
3005 marking in_bss, then looking at s_skip for clues. */
3006 subseg_set (bss_section, 0);
3007 demand_empty_rest_of_line ();
cd000bff
DJ
3008
3009#ifdef md_elf_section_change_hook
3010 md_elf_section_change_hook ();
3011#endif
c19d1205 3012}
b99bd4ef 3013
c19d1205
ZW
3014static void
3015s_even (int ignore ATTRIBUTE_UNUSED)
3016{
3017 /* Never make frag if expect extra pass. */
3018 if (!need_pass_2)
3019 frag_align (1, 0, 0);
b99bd4ef 3020
c19d1205 3021 record_alignment (now_seg, 1);
b99bd4ef 3022
c19d1205 3023 demand_empty_rest_of_line ();
b99bd4ef
NC
3024}
3025
2e6976a8
DG
3026/* Directives: CodeComposer Studio. */
3027
3028/* .ref (for CodeComposer Studio syntax only). */
3029static void
3030s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3031{
3032 if (codecomposer_syntax)
3033 ignore_rest_of_line ();
3034 else
3035 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3036}
3037
3038/* If name is not NULL, then it is used for marking the beginning of a
3039 function, wherease if it is NULL then it means the function end. */
3040static void
3041asmfunc_debug (const char * name)
3042{
3043 static const char * last_name = NULL;
3044
3045 if (name != NULL)
3046 {
3047 gas_assert (last_name == NULL);
3048 last_name = name;
3049
3050 if (debug_type == DEBUG_STABS)
3051 stabs_generate_asm_func (name, name);
3052 }
3053 else
3054 {
3055 gas_assert (last_name != NULL);
3056
3057 if (debug_type == DEBUG_STABS)
3058 stabs_generate_asm_endfunc (last_name, last_name);
3059
3060 last_name = NULL;
3061 }
3062}
3063
3064static void
3065s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3066{
3067 if (codecomposer_syntax)
3068 {
3069 switch (asmfunc_state)
3070 {
3071 case OUTSIDE_ASMFUNC:
3072 asmfunc_state = WAITING_ASMFUNC_NAME;
3073 break;
3074
3075 case WAITING_ASMFUNC_NAME:
3076 as_bad (_(".asmfunc repeated."));
3077 break;
3078
3079 case WAITING_ENDASMFUNC:
3080 as_bad (_(".asmfunc without function."));
3081 break;
3082 }
3083 demand_empty_rest_of_line ();
3084 }
3085 else
3086 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3087}
3088
3089static void
3090s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3091{
3092 if (codecomposer_syntax)
3093 {
3094 switch (asmfunc_state)
3095 {
3096 case OUTSIDE_ASMFUNC:
3097 as_bad (_(".endasmfunc without a .asmfunc."));
3098 break;
3099
3100 case WAITING_ASMFUNC_NAME:
3101 as_bad (_(".endasmfunc without function."));
3102 break;
3103
3104 case WAITING_ENDASMFUNC:
3105 asmfunc_state = OUTSIDE_ASMFUNC;
3106 asmfunc_debug (NULL);
3107 break;
3108 }
3109 demand_empty_rest_of_line ();
3110 }
3111 else
3112 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3113}
3114
3115static void
3116s_ccs_def (int name)
3117{
3118 if (codecomposer_syntax)
3119 s_globl (name);
3120 else
3121 as_bad (_(".def pseudo-op only available with -mccs flag."));
3122}
3123
c19d1205 3124/* Directives: Literal pools. */
a737bd4d 3125
c19d1205
ZW
3126static literal_pool *
3127find_literal_pool (void)
a737bd4d 3128{
c19d1205 3129 literal_pool * pool;
a737bd4d 3130
c19d1205 3131 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3132 {
c19d1205
ZW
3133 if (pool->section == now_seg
3134 && pool->sub_section == now_subseg)
3135 break;
a737bd4d
NC
3136 }
3137
c19d1205 3138 return pool;
a737bd4d
NC
3139}
3140
c19d1205
ZW
3141static literal_pool *
3142find_or_make_literal_pool (void)
a737bd4d 3143{
c19d1205
ZW
3144 /* Next literal pool ID number. */
3145 static unsigned int latest_pool_num = 1;
3146 literal_pool * pool;
a737bd4d 3147
c19d1205 3148 pool = find_literal_pool ();
a737bd4d 3149
c19d1205 3150 if (pool == NULL)
a737bd4d 3151 {
c19d1205 3152 /* Create a new pool. */
21d799b5 3153 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
3154 if (! pool)
3155 return NULL;
a737bd4d 3156
c19d1205
ZW
3157 pool->next_free_entry = 0;
3158 pool->section = now_seg;
3159 pool->sub_section = now_subseg;
3160 pool->next = list_of_pools;
3161 pool->symbol = NULL;
3162
3163 /* Add it to the list. */
3164 list_of_pools = pool;
a737bd4d 3165 }
a737bd4d 3166
c19d1205
ZW
3167 /* New pools, and emptied pools, will have a NULL symbol. */
3168 if (pool->symbol == NULL)
a737bd4d 3169 {
c19d1205
ZW
3170 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3171 (valueT) 0, &zero_address_frag);
3172 pool->id = latest_pool_num ++;
a737bd4d
NC
3173 }
3174
c19d1205
ZW
3175 /* Done. */
3176 return pool;
a737bd4d
NC
3177}
3178
c19d1205 3179/* Add the literal in the global 'inst'
5f4273c7 3180 structure to the relevant literal pool. */
b99bd4ef
NC
3181
3182static int
c19d1205 3183add_to_lit_pool (void)
b99bd4ef 3184{
c19d1205
ZW
3185 literal_pool * pool;
3186 unsigned int entry;
b99bd4ef 3187
c19d1205
ZW
3188 pool = find_or_make_literal_pool ();
3189
3190 /* Check if this literal value is already in the pool. */
3191 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3192 {
c19d1205
ZW
3193 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3194 && (inst.reloc.exp.X_op == O_constant)
3195 && (pool->literals[entry].X_add_number
3196 == inst.reloc.exp.X_add_number)
3197 && (pool->literals[entry].X_unsigned
3198 == inst.reloc.exp.X_unsigned))
3199 break;
3200
3201 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3202 && (inst.reloc.exp.X_op == O_symbol)
3203 && (pool->literals[entry].X_add_number
3204 == inst.reloc.exp.X_add_number)
3205 && (pool->literals[entry].X_add_symbol
3206 == inst.reloc.exp.X_add_symbol)
3207 && (pool->literals[entry].X_op_symbol
3208 == inst.reloc.exp.X_op_symbol))
3209 break;
b99bd4ef
NC
3210 }
3211
c19d1205
ZW
3212 /* Do we need to create a new entry? */
3213 if (entry == pool->next_free_entry)
3214 {
3215 if (entry >= MAX_LITERAL_POOL_SIZE)
3216 {
3217 inst.error = _("literal pool overflow");
3218 return FAIL;
3219 }
3220
3221 pool->literals[entry] = inst.reloc.exp;
a8040cf2
NC
3222#ifdef OBJ_ELF
3223 /* PR ld/12974: Record the location of the first source line to reference
3224 this entry in the literal pool. If it turns out during linking that the
3225 symbol does not exist we will be able to give an accurate line number for
3226 the (first use of the) missing reference. */
3227 if (debug_type == DEBUG_DWARF2)
3228 dwarf2_where (pool->locs + entry);
3229#endif
c19d1205
ZW
3230 pool->next_free_entry += 1;
3231 }
b99bd4ef 3232
c19d1205
ZW
3233 inst.reloc.exp.X_op = O_symbol;
3234 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3235 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3236
c19d1205 3237 return SUCCESS;
b99bd4ef
NC
3238}
3239
2e6976a8
DG
3240bfd_boolean
3241tc_start_label_without_colon (char unused1 ATTRIBUTE_UNUSED, const char * rest)
3242{
3243 bfd_boolean ret = TRUE;
3244
3245 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3246 {
3247 const char *label = rest;
3248
3249 while (!is_end_of_line[(int) label[-1]])
3250 --label;
3251
3252 if (*label == '.')
3253 {
3254 as_bad (_("Invalid label '%s'"), label);
3255 ret = FALSE;
3256 }
3257
3258 asmfunc_debug (label);
3259
3260 asmfunc_state = WAITING_ENDASMFUNC;
3261 }
3262
3263 return ret;
3264}
3265
c19d1205
ZW
3266/* Can't use symbol_new here, so have to create a symbol and then at
3267 a later date assign it a value. Thats what these functions do. */
e16bb312 3268
c19d1205
ZW
3269static void
3270symbol_locate (symbolS * symbolP,
3271 const char * name, /* It is copied, the caller can modify. */
3272 segT segment, /* Segment identifier (SEG_<something>). */
3273 valueT valu, /* Symbol value. */
3274 fragS * frag) /* Associated fragment. */
3275{
3276 unsigned int name_length;
3277 char * preserved_copy_of_name;
e16bb312 3278
c19d1205
ZW
3279 name_length = strlen (name) + 1; /* +1 for \0. */
3280 obstack_grow (&notes, name, name_length);
21d799b5 3281 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3282
c19d1205
ZW
3283#ifdef tc_canonicalize_symbol_name
3284 preserved_copy_of_name =
3285 tc_canonicalize_symbol_name (preserved_copy_of_name);
3286#endif
b99bd4ef 3287
c19d1205 3288 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3289
c19d1205
ZW
3290 S_SET_SEGMENT (symbolP, segment);
3291 S_SET_VALUE (symbolP, valu);
3292 symbol_clear_list_pointers (symbolP);
b99bd4ef 3293
c19d1205 3294 symbol_set_frag (symbolP, frag);
b99bd4ef 3295
c19d1205
ZW
3296 /* Link to end of symbol chain. */
3297 {
3298 extern int symbol_table_frozen;
b99bd4ef 3299
c19d1205
ZW
3300 if (symbol_table_frozen)
3301 abort ();
3302 }
b99bd4ef 3303
c19d1205 3304 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3305
c19d1205 3306 obj_symbol_new_hook (symbolP);
b99bd4ef 3307
c19d1205
ZW
3308#ifdef tc_symbol_new_hook
3309 tc_symbol_new_hook (symbolP);
3310#endif
3311
3312#ifdef DEBUG_SYMS
3313 verify_symbol_chain (symbol_rootP, symbol_lastP);
3314#endif /* DEBUG_SYMS */
b99bd4ef
NC
3315}
3316
b99bd4ef 3317
c19d1205
ZW
3318static void
3319s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3320{
c19d1205
ZW
3321 unsigned int entry;
3322 literal_pool * pool;
3323 char sym_name[20];
b99bd4ef 3324
c19d1205
ZW
3325 pool = find_literal_pool ();
3326 if (pool == NULL
3327 || pool->symbol == NULL
3328 || pool->next_free_entry == 0)
3329 return;
b99bd4ef 3330
c19d1205 3331 mapping_state (MAP_DATA);
b99bd4ef 3332
c19d1205
ZW
3333 /* Align pool as you have word accesses.
3334 Only make a frag if we have to. */
3335 if (!need_pass_2)
3336 frag_align (2, 0, 0);
b99bd4ef 3337
c19d1205 3338 record_alignment (now_seg, 2);
b99bd4ef 3339
c19d1205 3340 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3341
c19d1205
ZW
3342 symbol_locate (pool->symbol, sym_name, now_seg,
3343 (valueT) frag_now_fix (), frag_now);
3344 symbol_table_insert (pool->symbol);
b99bd4ef 3345
c19d1205 3346 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3347
c19d1205
ZW
3348#if defined OBJ_COFF || defined OBJ_ELF
3349 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3350#endif
6c43fab6 3351
c19d1205 3352 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3353 {
3354#ifdef OBJ_ELF
3355 if (debug_type == DEBUG_DWARF2)
3356 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3357#endif
3358 /* First output the expression in the instruction to the pool. */
3359 emit_expr (&(pool->literals[entry]), 4); /* .word */
3360 }
b99bd4ef 3361
c19d1205
ZW
3362 /* Mark the pool as empty. */
3363 pool->next_free_entry = 0;
3364 pool->symbol = NULL;
b99bd4ef
NC
3365}
3366
c19d1205
ZW
3367#ifdef OBJ_ELF
3368/* Forward declarations for functions below, in the MD interface
3369 section. */
3370static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3371static valueT create_unwind_entry (int);
3372static void start_unwind_section (const segT, int);
3373static void add_unwind_opcode (valueT, int);
3374static void flush_pending_unwind (void);
b99bd4ef 3375
c19d1205 3376/* Directives: Data. */
b99bd4ef 3377
c19d1205
ZW
3378static void
3379s_arm_elf_cons (int nbytes)
3380{
3381 expressionS exp;
b99bd4ef 3382
c19d1205
ZW
3383#ifdef md_flush_pending_output
3384 md_flush_pending_output ();
3385#endif
b99bd4ef 3386
c19d1205 3387 if (is_it_end_of_statement ())
b99bd4ef 3388 {
c19d1205
ZW
3389 demand_empty_rest_of_line ();
3390 return;
b99bd4ef
NC
3391 }
3392
c19d1205
ZW
3393#ifdef md_cons_align
3394 md_cons_align (nbytes);
3395#endif
b99bd4ef 3396
c19d1205
ZW
3397 mapping_state (MAP_DATA);
3398 do
b99bd4ef 3399 {
c19d1205
ZW
3400 int reloc;
3401 char *base = input_line_pointer;
b99bd4ef 3402
c19d1205 3403 expression (& exp);
b99bd4ef 3404
c19d1205
ZW
3405 if (exp.X_op != O_symbol)
3406 emit_expr (&exp, (unsigned int) nbytes);
3407 else
3408 {
3409 char *before_reloc = input_line_pointer;
3410 reloc = parse_reloc (&input_line_pointer);
3411 if (reloc == -1)
3412 {
3413 as_bad (_("unrecognized relocation suffix"));
3414 ignore_rest_of_line ();
3415 return;
3416 }
3417 else if (reloc == BFD_RELOC_UNUSED)
3418 emit_expr (&exp, (unsigned int) nbytes);
3419 else
3420 {
21d799b5 3421 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3422 bfd_reloc_type_lookup (stdoutput,
3423 (bfd_reloc_code_real_type) reloc);
c19d1205 3424 int size = bfd_get_reloc_size (howto);
b99bd4ef 3425
2fc8bdac
ZW
3426 if (reloc == BFD_RELOC_ARM_PLT32)
3427 {
3428 as_bad (_("(plt) is only valid on branch targets"));
3429 reloc = BFD_RELOC_UNUSED;
3430 size = 0;
3431 }
3432
c19d1205 3433 if (size > nbytes)
2fc8bdac 3434 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3435 howto->name, nbytes);
3436 else
3437 {
3438 /* We've parsed an expression stopping at O_symbol.
3439 But there may be more expression left now that we
3440 have parsed the relocation marker. Parse it again.
3441 XXX Surely there is a cleaner way to do this. */
3442 char *p = input_line_pointer;
3443 int offset;
21d799b5 3444 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3445 memcpy (save_buf, base, input_line_pointer - base);
3446 memmove (base + (input_line_pointer - before_reloc),
3447 base, before_reloc - base);
3448
3449 input_line_pointer = base + (input_line_pointer-before_reloc);
3450 expression (&exp);
3451 memcpy (base, save_buf, p - base);
3452
3453 offset = nbytes - size;
3454 p = frag_more ((int) nbytes);
3455 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3456 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3457 }
3458 }
3459 }
b99bd4ef 3460 }
c19d1205 3461 while (*input_line_pointer++ == ',');
b99bd4ef 3462
c19d1205
ZW
3463 /* Put terminator back into stream. */
3464 input_line_pointer --;
3465 demand_empty_rest_of_line ();
b99bd4ef
NC
3466}
3467
c921be7d
NC
3468/* Emit an expression containing a 32-bit thumb instruction.
3469 Implementation based on put_thumb32_insn. */
3470
3471static void
3472emit_thumb32_expr (expressionS * exp)
3473{
3474 expressionS exp_high = *exp;
3475
3476 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3477 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3478 exp->X_add_number &= 0xffff;
3479 emit_expr (exp, (unsigned int) THUMB_SIZE);
3480}
3481
3482/* Guess the instruction size based on the opcode. */
3483
3484static int
3485thumb_insn_size (int opcode)
3486{
3487 if ((unsigned int) opcode < 0xe800u)
3488 return 2;
3489 else if ((unsigned int) opcode >= 0xe8000000u)
3490 return 4;
3491 else
3492 return 0;
3493}
3494
3495static bfd_boolean
3496emit_insn (expressionS *exp, int nbytes)
3497{
3498 int size = 0;
3499
3500 if (exp->X_op == O_constant)
3501 {
3502 size = nbytes;
3503
3504 if (size == 0)
3505 size = thumb_insn_size (exp->X_add_number);
3506
3507 if (size != 0)
3508 {
3509 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3510 {
3511 as_bad (_(".inst.n operand too big. "\
3512 "Use .inst.w instead"));
3513 size = 0;
3514 }
3515 else
3516 {
3517 if (now_it.state == AUTOMATIC_IT_BLOCK)
3518 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3519 else
3520 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3521
3522 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3523 emit_thumb32_expr (exp);
3524 else
3525 emit_expr (exp, (unsigned int) size);
3526
3527 it_fsm_post_encode ();
3528 }
3529 }
3530 else
3531 as_bad (_("cannot determine Thumb instruction size. " \
3532 "Use .inst.n/.inst.w instead"));
3533 }
3534 else
3535 as_bad (_("constant expression required"));
3536
3537 return (size != 0);
3538}
3539
3540/* Like s_arm_elf_cons but do not use md_cons_align and
3541 set the mapping state to MAP_ARM/MAP_THUMB. */
3542
3543static void
3544s_arm_elf_inst (int nbytes)
3545{
3546 if (is_it_end_of_statement ())
3547 {
3548 demand_empty_rest_of_line ();
3549 return;
3550 }
3551
3552 /* Calling mapping_state () here will not change ARM/THUMB,
3553 but will ensure not to be in DATA state. */
3554
3555 if (thumb_mode)
3556 mapping_state (MAP_THUMB);
3557 else
3558 {
3559 if (nbytes != 0)
3560 {
3561 as_bad (_("width suffixes are invalid in ARM mode"));
3562 ignore_rest_of_line ();
3563 return;
3564 }
3565
3566 nbytes = 4;
3567
3568 mapping_state (MAP_ARM);
3569 }
3570
3571 do
3572 {
3573 expressionS exp;
3574
3575 expression (& exp);
3576
3577 if (! emit_insn (& exp, nbytes))
3578 {
3579 ignore_rest_of_line ();
3580 return;
3581 }
3582 }
3583 while (*input_line_pointer++ == ',');
3584
3585 /* Put terminator back into stream. */
3586 input_line_pointer --;
3587 demand_empty_rest_of_line ();
3588}
b99bd4ef 3589
c19d1205 3590/* Parse a .rel31 directive. */
b99bd4ef 3591
c19d1205
ZW
3592static void
3593s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3594{
3595 expressionS exp;
3596 char *p;
3597 valueT highbit;
b99bd4ef 3598
c19d1205
ZW
3599 highbit = 0;
3600 if (*input_line_pointer == '1')
3601 highbit = 0x80000000;
3602 else if (*input_line_pointer != '0')
3603 as_bad (_("expected 0 or 1"));
b99bd4ef 3604
c19d1205
ZW
3605 input_line_pointer++;
3606 if (*input_line_pointer != ',')
3607 as_bad (_("missing comma"));
3608 input_line_pointer++;
b99bd4ef 3609
c19d1205
ZW
3610#ifdef md_flush_pending_output
3611 md_flush_pending_output ();
3612#endif
b99bd4ef 3613
c19d1205
ZW
3614#ifdef md_cons_align
3615 md_cons_align (4);
3616#endif
b99bd4ef 3617
c19d1205 3618 mapping_state (MAP_DATA);
b99bd4ef 3619
c19d1205 3620 expression (&exp);
b99bd4ef 3621
c19d1205
ZW
3622 p = frag_more (4);
3623 md_number_to_chars (p, highbit, 4);
3624 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3625 BFD_RELOC_ARM_PREL31);
b99bd4ef 3626
c19d1205 3627 demand_empty_rest_of_line ();
b99bd4ef
NC
3628}
3629
c19d1205 3630/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3631
c19d1205 3632/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3633
c19d1205
ZW
3634static void
3635s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3636{
3637 demand_empty_rest_of_line ();
921e5f0a
PB
3638 if (unwind.proc_start)
3639 {
c921be7d 3640 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3641 return;
3642 }
3643
c19d1205
ZW
3644 /* Mark the start of the function. */
3645 unwind.proc_start = expr_build_dot ();
b99bd4ef 3646
c19d1205
ZW
3647 /* Reset the rest of the unwind info. */
3648 unwind.opcode_count = 0;
3649 unwind.table_entry = NULL;
3650 unwind.personality_routine = NULL;
3651 unwind.personality_index = -1;
3652 unwind.frame_size = 0;
3653 unwind.fp_offset = 0;
fdfde340 3654 unwind.fp_reg = REG_SP;
c19d1205
ZW
3655 unwind.fp_used = 0;
3656 unwind.sp_restored = 0;
3657}
b99bd4ef 3658
b99bd4ef 3659
c19d1205
ZW
3660/* Parse a handlerdata directive. Creates the exception handling table entry
3661 for the function. */
b99bd4ef 3662
c19d1205
ZW
3663static void
3664s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3665{
3666 demand_empty_rest_of_line ();
921e5f0a 3667 if (!unwind.proc_start)
c921be7d 3668 as_bad (MISSING_FNSTART);
921e5f0a 3669
c19d1205 3670 if (unwind.table_entry)
6decc662 3671 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3672
c19d1205
ZW
3673 create_unwind_entry (1);
3674}
a737bd4d 3675
c19d1205 3676/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3677
c19d1205
ZW
3678static void
3679s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3680{
3681 long where;
3682 char *ptr;
3683 valueT val;
940b5ce0 3684 unsigned int marked_pr_dependency;
f02232aa 3685
c19d1205 3686 demand_empty_rest_of_line ();
f02232aa 3687
921e5f0a
PB
3688 if (!unwind.proc_start)
3689 {
c921be7d 3690 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3691 return;
3692 }
3693
c19d1205
ZW
3694 /* Add eh table entry. */
3695 if (unwind.table_entry == NULL)
3696 val = create_unwind_entry (0);
3697 else
3698 val = 0;
f02232aa 3699
c19d1205
ZW
3700 /* Add index table entry. This is two words. */
3701 start_unwind_section (unwind.saved_seg, 1);
3702 frag_align (2, 0, 0);
3703 record_alignment (now_seg, 2);
b99bd4ef 3704
c19d1205 3705 ptr = frag_more (8);
5011093d 3706 memset (ptr, 0, 8);
c19d1205 3707 where = frag_now_fix () - 8;
f02232aa 3708
c19d1205
ZW
3709 /* Self relative offset of the function start. */
3710 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3711 BFD_RELOC_ARM_PREL31);
f02232aa 3712
c19d1205
ZW
3713 /* Indicate dependency on EHABI-defined personality routines to the
3714 linker, if it hasn't been done already. */
940b5ce0
DJ
3715 marked_pr_dependency
3716 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3717 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3718 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3719 {
5f4273c7
NC
3720 static const char *const name[] =
3721 {
3722 "__aeabi_unwind_cpp_pr0",
3723 "__aeabi_unwind_cpp_pr1",
3724 "__aeabi_unwind_cpp_pr2"
3725 };
c19d1205
ZW
3726 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3727 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3728 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3729 |= 1 << unwind.personality_index;
c19d1205 3730 }
f02232aa 3731
c19d1205
ZW
3732 if (val)
3733 /* Inline exception table entry. */
3734 md_number_to_chars (ptr + 4, val, 4);
3735 else
3736 /* Self relative offset of the table entry. */
3737 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3738 BFD_RELOC_ARM_PREL31);
f02232aa 3739
c19d1205
ZW
3740 /* Restore the original section. */
3741 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3742
3743 unwind.proc_start = NULL;
c19d1205 3744}
f02232aa 3745
f02232aa 3746
c19d1205 3747/* Parse an unwind_cantunwind directive. */
b99bd4ef 3748
c19d1205
ZW
3749static void
3750s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3751{
3752 demand_empty_rest_of_line ();
921e5f0a 3753 if (!unwind.proc_start)
c921be7d 3754 as_bad (MISSING_FNSTART);
921e5f0a 3755
c19d1205
ZW
3756 if (unwind.personality_routine || unwind.personality_index != -1)
3757 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3758
c19d1205
ZW
3759 unwind.personality_index = -2;
3760}
b99bd4ef 3761
b99bd4ef 3762
c19d1205 3763/* Parse a personalityindex directive. */
b99bd4ef 3764
c19d1205
ZW
3765static void
3766s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3767{
3768 expressionS exp;
b99bd4ef 3769
921e5f0a 3770 if (!unwind.proc_start)
c921be7d 3771 as_bad (MISSING_FNSTART);
921e5f0a 3772
c19d1205
ZW
3773 if (unwind.personality_routine || unwind.personality_index != -1)
3774 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3775
c19d1205 3776 expression (&exp);
b99bd4ef 3777
c19d1205
ZW
3778 if (exp.X_op != O_constant
3779 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3780 {
c19d1205
ZW
3781 as_bad (_("bad personality routine number"));
3782 ignore_rest_of_line ();
3783 return;
b99bd4ef
NC
3784 }
3785
c19d1205 3786 unwind.personality_index = exp.X_add_number;
b99bd4ef 3787
c19d1205
ZW
3788 demand_empty_rest_of_line ();
3789}
e16bb312 3790
e16bb312 3791
c19d1205 3792/* Parse a personality directive. */
e16bb312 3793
c19d1205
ZW
3794static void
3795s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3796{
3797 char *name, *p, c;
a737bd4d 3798
921e5f0a 3799 if (!unwind.proc_start)
c921be7d 3800 as_bad (MISSING_FNSTART);
921e5f0a 3801
c19d1205
ZW
3802 if (unwind.personality_routine || unwind.personality_index != -1)
3803 as_bad (_("duplicate .personality directive"));
a737bd4d 3804
c19d1205
ZW
3805 name = input_line_pointer;
3806 c = get_symbol_end ();
3807 p = input_line_pointer;
3808 unwind.personality_routine = symbol_find_or_make (name);
3809 *p = c;
3810 demand_empty_rest_of_line ();
3811}
e16bb312 3812
e16bb312 3813
c19d1205 3814/* Parse a directive saving core registers. */
e16bb312 3815
c19d1205
ZW
3816static void
3817s_arm_unwind_save_core (void)
e16bb312 3818{
c19d1205
ZW
3819 valueT op;
3820 long range;
3821 int n;
e16bb312 3822
c19d1205
ZW
3823 range = parse_reg_list (&input_line_pointer);
3824 if (range == FAIL)
e16bb312 3825 {
c19d1205
ZW
3826 as_bad (_("expected register list"));
3827 ignore_rest_of_line ();
3828 return;
3829 }
e16bb312 3830
c19d1205 3831 demand_empty_rest_of_line ();
e16bb312 3832
c19d1205
ZW
3833 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3834 into .unwind_save {..., sp...}. We aren't bothered about the value of
3835 ip because it is clobbered by calls. */
3836 if (unwind.sp_restored && unwind.fp_reg == 12
3837 && (range & 0x3000) == 0x1000)
3838 {
3839 unwind.opcode_count--;
3840 unwind.sp_restored = 0;
3841 range = (range | 0x2000) & ~0x1000;
3842 unwind.pending_offset = 0;
3843 }
e16bb312 3844
01ae4198
DJ
3845 /* Pop r4-r15. */
3846 if (range & 0xfff0)
c19d1205 3847 {
01ae4198
DJ
3848 /* See if we can use the short opcodes. These pop a block of up to 8
3849 registers starting with r4, plus maybe r14. */
3850 for (n = 0; n < 8; n++)
3851 {
3852 /* Break at the first non-saved register. */
3853 if ((range & (1 << (n + 4))) == 0)
3854 break;
3855 }
3856 /* See if there are any other bits set. */
3857 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3858 {
3859 /* Use the long form. */
3860 op = 0x8000 | ((range >> 4) & 0xfff);
3861 add_unwind_opcode (op, 2);
3862 }
0dd132b6 3863 else
01ae4198
DJ
3864 {
3865 /* Use the short form. */
3866 if (range & 0x4000)
3867 op = 0xa8; /* Pop r14. */
3868 else
3869 op = 0xa0; /* Do not pop r14. */
3870 op |= (n - 1);
3871 add_unwind_opcode (op, 1);
3872 }
c19d1205 3873 }
0dd132b6 3874
c19d1205
ZW
3875 /* Pop r0-r3. */
3876 if (range & 0xf)
3877 {
3878 op = 0xb100 | (range & 0xf);
3879 add_unwind_opcode (op, 2);
0dd132b6
NC
3880 }
3881
c19d1205
ZW
3882 /* Record the number of bytes pushed. */
3883 for (n = 0; n < 16; n++)
3884 {
3885 if (range & (1 << n))
3886 unwind.frame_size += 4;
3887 }
0dd132b6
NC
3888}
3889
c19d1205
ZW
3890
3891/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3892
3893static void
c19d1205 3894s_arm_unwind_save_fpa (int reg)
b99bd4ef 3895{
c19d1205
ZW
3896 expressionS exp;
3897 int num_regs;
3898 valueT op;
b99bd4ef 3899
c19d1205
ZW
3900 /* Get Number of registers to transfer. */
3901 if (skip_past_comma (&input_line_pointer) != FAIL)
3902 expression (&exp);
3903 else
3904 exp.X_op = O_illegal;
b99bd4ef 3905
c19d1205 3906 if (exp.X_op != O_constant)
b99bd4ef 3907 {
c19d1205
ZW
3908 as_bad (_("expected , <constant>"));
3909 ignore_rest_of_line ();
b99bd4ef
NC
3910 return;
3911 }
3912
c19d1205
ZW
3913 num_regs = exp.X_add_number;
3914
3915 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3916 {
c19d1205
ZW
3917 as_bad (_("number of registers must be in the range [1:4]"));
3918 ignore_rest_of_line ();
b99bd4ef
NC
3919 return;
3920 }
3921
c19d1205 3922 demand_empty_rest_of_line ();
b99bd4ef 3923
c19d1205
ZW
3924 if (reg == 4)
3925 {
3926 /* Short form. */
3927 op = 0xb4 | (num_regs - 1);
3928 add_unwind_opcode (op, 1);
3929 }
b99bd4ef
NC
3930 else
3931 {
c19d1205
ZW
3932 /* Long form. */
3933 op = 0xc800 | (reg << 4) | (num_regs - 1);
3934 add_unwind_opcode (op, 2);
b99bd4ef 3935 }
c19d1205 3936 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3937}
3938
c19d1205 3939
fa073d69
MS
3940/* Parse a directive saving VFP registers for ARMv6 and above. */
3941
3942static void
3943s_arm_unwind_save_vfp_armv6 (void)
3944{
3945 int count;
3946 unsigned int start;
3947 valueT op;
3948 int num_vfpv3_regs = 0;
3949 int num_regs_below_16;
3950
3951 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3952 if (count == FAIL)
3953 {
3954 as_bad (_("expected register list"));
3955 ignore_rest_of_line ();
3956 return;
3957 }
3958
3959 demand_empty_rest_of_line ();
3960
3961 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3962 than FSTMX/FLDMX-style ones). */
3963
3964 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3965 if (start >= 16)
3966 num_vfpv3_regs = count;
3967 else if (start + count > 16)
3968 num_vfpv3_regs = start + count - 16;
3969
3970 if (num_vfpv3_regs > 0)
3971 {
3972 int start_offset = start > 16 ? start - 16 : 0;
3973 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3974 add_unwind_opcode (op, 2);
3975 }
3976
3977 /* Generate opcode for registers numbered in the range 0 .. 15. */
3978 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3979 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3980 if (num_regs_below_16 > 0)
3981 {
3982 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3983 add_unwind_opcode (op, 2);
3984 }
3985
3986 unwind.frame_size += count * 8;
3987}
3988
3989
3990/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3991
3992static void
c19d1205 3993s_arm_unwind_save_vfp (void)
b99bd4ef 3994{
c19d1205 3995 int count;
ca3f61f7 3996 unsigned int reg;
c19d1205 3997 valueT op;
b99bd4ef 3998
5287ad62 3999 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4000 if (count == FAIL)
b99bd4ef 4001 {
c19d1205
ZW
4002 as_bad (_("expected register list"));
4003 ignore_rest_of_line ();
b99bd4ef
NC
4004 return;
4005 }
4006
c19d1205 4007 demand_empty_rest_of_line ();
b99bd4ef 4008
c19d1205 4009 if (reg == 8)
b99bd4ef 4010 {
c19d1205
ZW
4011 /* Short form. */
4012 op = 0xb8 | (count - 1);
4013 add_unwind_opcode (op, 1);
b99bd4ef 4014 }
c19d1205 4015 else
b99bd4ef 4016 {
c19d1205
ZW
4017 /* Long form. */
4018 op = 0xb300 | (reg << 4) | (count - 1);
4019 add_unwind_opcode (op, 2);
b99bd4ef 4020 }
c19d1205
ZW
4021 unwind.frame_size += count * 8 + 4;
4022}
b99bd4ef 4023
b99bd4ef 4024
c19d1205
ZW
4025/* Parse a directive saving iWMMXt data registers. */
4026
4027static void
4028s_arm_unwind_save_mmxwr (void)
4029{
4030 int reg;
4031 int hi_reg;
4032 int i;
4033 unsigned mask = 0;
4034 valueT op;
b99bd4ef 4035
c19d1205
ZW
4036 if (*input_line_pointer == '{')
4037 input_line_pointer++;
b99bd4ef 4038
c19d1205 4039 do
b99bd4ef 4040 {
dcbf9037 4041 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4042
c19d1205 4043 if (reg == FAIL)
b99bd4ef 4044 {
9b7132d3 4045 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4046 goto error;
b99bd4ef
NC
4047 }
4048
c19d1205
ZW
4049 if (mask >> reg)
4050 as_tsktsk (_("register list not in ascending order"));
4051 mask |= 1 << reg;
b99bd4ef 4052
c19d1205
ZW
4053 if (*input_line_pointer == '-')
4054 {
4055 input_line_pointer++;
dcbf9037 4056 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4057 if (hi_reg == FAIL)
4058 {
9b7132d3 4059 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4060 goto error;
4061 }
4062 else if (reg >= hi_reg)
4063 {
4064 as_bad (_("bad register range"));
4065 goto error;
4066 }
4067 for (; reg < hi_reg; reg++)
4068 mask |= 1 << reg;
4069 }
4070 }
4071 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4072
d996d970 4073 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4074
c19d1205 4075 demand_empty_rest_of_line ();
b99bd4ef 4076
708587a4 4077 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4078 the list. */
4079 flush_pending_unwind ();
b99bd4ef 4080
c19d1205 4081 for (i = 0; i < 16; i++)
b99bd4ef 4082 {
c19d1205
ZW
4083 if (mask & (1 << i))
4084 unwind.frame_size += 8;
b99bd4ef
NC
4085 }
4086
c19d1205
ZW
4087 /* Attempt to combine with a previous opcode. We do this because gcc
4088 likes to output separate unwind directives for a single block of
4089 registers. */
4090 if (unwind.opcode_count > 0)
b99bd4ef 4091 {
c19d1205
ZW
4092 i = unwind.opcodes[unwind.opcode_count - 1];
4093 if ((i & 0xf8) == 0xc0)
4094 {
4095 i &= 7;
4096 /* Only merge if the blocks are contiguous. */
4097 if (i < 6)
4098 {
4099 if ((mask & 0xfe00) == (1 << 9))
4100 {
4101 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4102 unwind.opcode_count--;
4103 }
4104 }
4105 else if (i == 6 && unwind.opcode_count >= 2)
4106 {
4107 i = unwind.opcodes[unwind.opcode_count - 2];
4108 reg = i >> 4;
4109 i &= 0xf;
b99bd4ef 4110
c19d1205
ZW
4111 op = 0xffff << (reg - 1);
4112 if (reg > 0
87a1fd79 4113 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4114 {
4115 op = (1 << (reg + i + 1)) - 1;
4116 op &= ~((1 << reg) - 1);
4117 mask |= op;
4118 unwind.opcode_count -= 2;
4119 }
4120 }
4121 }
b99bd4ef
NC
4122 }
4123
c19d1205
ZW
4124 hi_reg = 15;
4125 /* We want to generate opcodes in the order the registers have been
4126 saved, ie. descending order. */
4127 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4128 {
c19d1205
ZW
4129 /* Save registers in blocks. */
4130 if (reg < 0
4131 || !(mask & (1 << reg)))
4132 {
4133 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4134 preceding block. */
c19d1205
ZW
4135 if (reg != hi_reg)
4136 {
4137 if (reg == 9)
4138 {
4139 /* Short form. */
4140 op = 0xc0 | (hi_reg - 10);
4141 add_unwind_opcode (op, 1);
4142 }
4143 else
4144 {
4145 /* Long form. */
4146 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4147 add_unwind_opcode (op, 2);
4148 }
4149 }
4150 hi_reg = reg - 1;
4151 }
b99bd4ef
NC
4152 }
4153
c19d1205
ZW
4154 return;
4155error:
4156 ignore_rest_of_line ();
b99bd4ef
NC
4157}
4158
4159static void
c19d1205 4160s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4161{
c19d1205
ZW
4162 int reg;
4163 int hi_reg;
4164 unsigned mask = 0;
4165 valueT op;
b99bd4ef 4166
c19d1205
ZW
4167 if (*input_line_pointer == '{')
4168 input_line_pointer++;
b99bd4ef 4169
477330fc
RM
4170 skip_whitespace (input_line_pointer);
4171
c19d1205 4172 do
b99bd4ef 4173 {
dcbf9037 4174 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4175
c19d1205
ZW
4176 if (reg == FAIL)
4177 {
9b7132d3 4178 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4179 goto error;
4180 }
b99bd4ef 4181
c19d1205
ZW
4182 reg -= 8;
4183 if (mask >> reg)
4184 as_tsktsk (_("register list not in ascending order"));
4185 mask |= 1 << reg;
b99bd4ef 4186
c19d1205
ZW
4187 if (*input_line_pointer == '-')
4188 {
4189 input_line_pointer++;
dcbf9037 4190 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4191 if (hi_reg == FAIL)
4192 {
9b7132d3 4193 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4194 goto error;
4195 }
4196 else if (reg >= hi_reg)
4197 {
4198 as_bad (_("bad register range"));
4199 goto error;
4200 }
4201 for (; reg < hi_reg; reg++)
4202 mask |= 1 << reg;
4203 }
b99bd4ef 4204 }
c19d1205 4205 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4206
d996d970 4207 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4208
c19d1205
ZW
4209 demand_empty_rest_of_line ();
4210
708587a4 4211 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4212 the list. */
4213 flush_pending_unwind ();
b99bd4ef 4214
c19d1205 4215 for (reg = 0; reg < 16; reg++)
b99bd4ef 4216 {
c19d1205
ZW
4217 if (mask & (1 << reg))
4218 unwind.frame_size += 4;
b99bd4ef 4219 }
c19d1205
ZW
4220 op = 0xc700 | mask;
4221 add_unwind_opcode (op, 2);
4222 return;
4223error:
4224 ignore_rest_of_line ();
b99bd4ef
NC
4225}
4226
c19d1205 4227
fa073d69
MS
4228/* Parse an unwind_save directive.
4229 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4230
b99bd4ef 4231static void
fa073d69 4232s_arm_unwind_save (int arch_v6)
b99bd4ef 4233{
c19d1205
ZW
4234 char *peek;
4235 struct reg_entry *reg;
4236 bfd_boolean had_brace = FALSE;
b99bd4ef 4237
921e5f0a 4238 if (!unwind.proc_start)
c921be7d 4239 as_bad (MISSING_FNSTART);
921e5f0a 4240
c19d1205
ZW
4241 /* Figure out what sort of save we have. */
4242 peek = input_line_pointer;
b99bd4ef 4243
c19d1205 4244 if (*peek == '{')
b99bd4ef 4245 {
c19d1205
ZW
4246 had_brace = TRUE;
4247 peek++;
b99bd4ef
NC
4248 }
4249
c19d1205 4250 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4251
c19d1205 4252 if (!reg)
b99bd4ef 4253 {
c19d1205
ZW
4254 as_bad (_("register expected"));
4255 ignore_rest_of_line ();
b99bd4ef
NC
4256 return;
4257 }
4258
c19d1205 4259 switch (reg->type)
b99bd4ef 4260 {
c19d1205
ZW
4261 case REG_TYPE_FN:
4262 if (had_brace)
4263 {
4264 as_bad (_("FPA .unwind_save does not take a register list"));
4265 ignore_rest_of_line ();
4266 return;
4267 }
93ac2687 4268 input_line_pointer = peek;
c19d1205 4269 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4270 return;
c19d1205 4271
1f5afe1c
NC
4272 case REG_TYPE_RN:
4273 s_arm_unwind_save_core ();
4274 return;
4275
fa073d69
MS
4276 case REG_TYPE_VFD:
4277 if (arch_v6)
477330fc 4278 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4279 else
477330fc 4280 s_arm_unwind_save_vfp ();
fa073d69 4281 return;
1f5afe1c
NC
4282
4283 case REG_TYPE_MMXWR:
4284 s_arm_unwind_save_mmxwr ();
4285 return;
4286
4287 case REG_TYPE_MMXWCG:
4288 s_arm_unwind_save_mmxwcg ();
4289 return;
c19d1205
ZW
4290
4291 default:
4292 as_bad (_(".unwind_save does not support this kind of register"));
4293 ignore_rest_of_line ();
b99bd4ef 4294 }
c19d1205 4295}
b99bd4ef 4296
b99bd4ef 4297
c19d1205
ZW
4298/* Parse an unwind_movsp directive. */
4299
4300static void
4301s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4302{
4303 int reg;
4304 valueT op;
4fa3602b 4305 int offset;
c19d1205 4306
921e5f0a 4307 if (!unwind.proc_start)
c921be7d 4308 as_bad (MISSING_FNSTART);
921e5f0a 4309
dcbf9037 4310 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4311 if (reg == FAIL)
b99bd4ef 4312 {
9b7132d3 4313 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4314 ignore_rest_of_line ();
b99bd4ef
NC
4315 return;
4316 }
4fa3602b
PB
4317
4318 /* Optional constant. */
4319 if (skip_past_comma (&input_line_pointer) != FAIL)
4320 {
4321 if (immediate_for_directive (&offset) == FAIL)
4322 return;
4323 }
4324 else
4325 offset = 0;
4326
c19d1205 4327 demand_empty_rest_of_line ();
b99bd4ef 4328
c19d1205 4329 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4330 {
c19d1205 4331 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4332 return;
4333 }
4334
c19d1205
ZW
4335 if (unwind.fp_reg != REG_SP)
4336 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4337
c19d1205
ZW
4338 /* Generate opcode to restore the value. */
4339 op = 0x90 | reg;
4340 add_unwind_opcode (op, 1);
4341
4342 /* Record the information for later. */
4343 unwind.fp_reg = reg;
4fa3602b 4344 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4345 unwind.sp_restored = 1;
b05fe5cf
ZW
4346}
4347
c19d1205
ZW
4348/* Parse an unwind_pad directive. */
4349
b05fe5cf 4350static void
c19d1205 4351s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4352{
c19d1205 4353 int offset;
b05fe5cf 4354
921e5f0a 4355 if (!unwind.proc_start)
c921be7d 4356 as_bad (MISSING_FNSTART);
921e5f0a 4357
c19d1205
ZW
4358 if (immediate_for_directive (&offset) == FAIL)
4359 return;
b99bd4ef 4360
c19d1205
ZW
4361 if (offset & 3)
4362 {
4363 as_bad (_("stack increment must be multiple of 4"));
4364 ignore_rest_of_line ();
4365 return;
4366 }
b99bd4ef 4367
c19d1205
ZW
4368 /* Don't generate any opcodes, just record the details for later. */
4369 unwind.frame_size += offset;
4370 unwind.pending_offset += offset;
4371
4372 demand_empty_rest_of_line ();
4373}
4374
4375/* Parse an unwind_setfp directive. */
4376
4377static void
4378s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4379{
c19d1205
ZW
4380 int sp_reg;
4381 int fp_reg;
4382 int offset;
4383
921e5f0a 4384 if (!unwind.proc_start)
c921be7d 4385 as_bad (MISSING_FNSTART);
921e5f0a 4386
dcbf9037 4387 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4388 if (skip_past_comma (&input_line_pointer) == FAIL)
4389 sp_reg = FAIL;
4390 else
dcbf9037 4391 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4392
c19d1205
ZW
4393 if (fp_reg == FAIL || sp_reg == FAIL)
4394 {
4395 as_bad (_("expected <reg>, <reg>"));
4396 ignore_rest_of_line ();
4397 return;
4398 }
b99bd4ef 4399
c19d1205
ZW
4400 /* Optional constant. */
4401 if (skip_past_comma (&input_line_pointer) != FAIL)
4402 {
4403 if (immediate_for_directive (&offset) == FAIL)
4404 return;
4405 }
4406 else
4407 offset = 0;
a737bd4d 4408
c19d1205 4409 demand_empty_rest_of_line ();
a737bd4d 4410
fdfde340 4411 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4412 {
c19d1205
ZW
4413 as_bad (_("register must be either sp or set by a previous"
4414 "unwind_movsp directive"));
4415 return;
a737bd4d
NC
4416 }
4417
c19d1205
ZW
4418 /* Don't generate any opcodes, just record the information for later. */
4419 unwind.fp_reg = fp_reg;
4420 unwind.fp_used = 1;
fdfde340 4421 if (sp_reg == REG_SP)
c19d1205
ZW
4422 unwind.fp_offset = unwind.frame_size - offset;
4423 else
4424 unwind.fp_offset -= offset;
a737bd4d
NC
4425}
4426
c19d1205
ZW
4427/* Parse an unwind_raw directive. */
4428
4429static void
4430s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4431{
c19d1205 4432 expressionS exp;
708587a4 4433 /* This is an arbitrary limit. */
c19d1205
ZW
4434 unsigned char op[16];
4435 int count;
a737bd4d 4436
921e5f0a 4437 if (!unwind.proc_start)
c921be7d 4438 as_bad (MISSING_FNSTART);
921e5f0a 4439
c19d1205
ZW
4440 expression (&exp);
4441 if (exp.X_op == O_constant
4442 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4443 {
c19d1205
ZW
4444 unwind.frame_size += exp.X_add_number;
4445 expression (&exp);
4446 }
4447 else
4448 exp.X_op = O_illegal;
a737bd4d 4449
c19d1205
ZW
4450 if (exp.X_op != O_constant)
4451 {
4452 as_bad (_("expected <offset>, <opcode>"));
4453 ignore_rest_of_line ();
4454 return;
4455 }
a737bd4d 4456
c19d1205 4457 count = 0;
a737bd4d 4458
c19d1205
ZW
4459 /* Parse the opcode. */
4460 for (;;)
4461 {
4462 if (count >= 16)
4463 {
4464 as_bad (_("unwind opcode too long"));
4465 ignore_rest_of_line ();
a737bd4d 4466 }
c19d1205 4467 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4468 {
c19d1205
ZW
4469 as_bad (_("invalid unwind opcode"));
4470 ignore_rest_of_line ();
4471 return;
a737bd4d 4472 }
c19d1205 4473 op[count++] = exp.X_add_number;
a737bd4d 4474
c19d1205
ZW
4475 /* Parse the next byte. */
4476 if (skip_past_comma (&input_line_pointer) == FAIL)
4477 break;
a737bd4d 4478
c19d1205
ZW
4479 expression (&exp);
4480 }
b99bd4ef 4481
c19d1205
ZW
4482 /* Add the opcode bytes in reverse order. */
4483 while (count--)
4484 add_unwind_opcode (op[count], 1);
b99bd4ef 4485
c19d1205 4486 demand_empty_rest_of_line ();
b99bd4ef 4487}
ee065d83
PB
4488
4489
4490/* Parse a .eabi_attribute directive. */
4491
4492static void
4493s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4494{
0420f52b 4495 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4496
4497 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4498 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4499}
4500
0855e32b
NS
4501/* Emit a tls fix for the symbol. */
4502
4503static void
4504s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4505{
4506 char *p;
4507 expressionS exp;
4508#ifdef md_flush_pending_output
4509 md_flush_pending_output ();
4510#endif
4511
4512#ifdef md_cons_align
4513 md_cons_align (4);
4514#endif
4515
4516 /* Since we're just labelling the code, there's no need to define a
4517 mapping symbol. */
4518 expression (&exp);
4519 p = obstack_next_free (&frchain_now->frch_obstack);
4520 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4521 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4522 : BFD_RELOC_ARM_TLS_DESCSEQ);
4523}
cdf9ccec 4524#endif /* OBJ_ELF */
0855e32b 4525
ee065d83 4526static void s_arm_arch (int);
7a1d4c38 4527static void s_arm_object_arch (int);
ee065d83
PB
4528static void s_arm_cpu (int);
4529static void s_arm_fpu (int);
69133863 4530static void s_arm_arch_extension (int);
b99bd4ef 4531
f0927246
NC
4532#ifdef TE_PE
4533
4534static void
5f4273c7 4535pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4536{
4537 expressionS exp;
4538
4539 do
4540 {
4541 expression (&exp);
4542 if (exp.X_op == O_symbol)
4543 exp.X_op = O_secrel;
4544
4545 emit_expr (&exp, 4);
4546 }
4547 while (*input_line_pointer++ == ',');
4548
4549 input_line_pointer--;
4550 demand_empty_rest_of_line ();
4551}
4552#endif /* TE_PE */
4553
c19d1205
ZW
4554/* This table describes all the machine specific pseudo-ops the assembler
4555 has to support. The fields are:
4556 pseudo-op name without dot
4557 function to call to execute this pseudo-op
4558 Integer arg to pass to the function. */
b99bd4ef 4559
c19d1205 4560const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4561{
c19d1205
ZW
4562 /* Never called because '.req' does not start a line. */
4563 { "req", s_req, 0 },
dcbf9037
JB
4564 /* Following two are likewise never called. */
4565 { "dn", s_dn, 0 },
4566 { "qn", s_qn, 0 },
c19d1205
ZW
4567 { "unreq", s_unreq, 0 },
4568 { "bss", s_bss, 0 },
4569 { "align", s_align, 0 },
4570 { "arm", s_arm, 0 },
4571 { "thumb", s_thumb, 0 },
4572 { "code", s_code, 0 },
4573 { "force_thumb", s_force_thumb, 0 },
4574 { "thumb_func", s_thumb_func, 0 },
4575 { "thumb_set", s_thumb_set, 0 },
4576 { "even", s_even, 0 },
4577 { "ltorg", s_ltorg, 0 },
4578 { "pool", s_ltorg, 0 },
4579 { "syntax", s_syntax, 0 },
8463be01
PB
4580 { "cpu", s_arm_cpu, 0 },
4581 { "arch", s_arm_arch, 0 },
7a1d4c38 4582 { "object_arch", s_arm_object_arch, 0 },
8463be01 4583 { "fpu", s_arm_fpu, 0 },
69133863 4584 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4585#ifdef OBJ_ELF
c921be7d
NC
4586 { "word", s_arm_elf_cons, 4 },
4587 { "long", s_arm_elf_cons, 4 },
4588 { "inst.n", s_arm_elf_inst, 2 },
4589 { "inst.w", s_arm_elf_inst, 4 },
4590 { "inst", s_arm_elf_inst, 0 },
4591 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4592 { "fnstart", s_arm_unwind_fnstart, 0 },
4593 { "fnend", s_arm_unwind_fnend, 0 },
4594 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4595 { "personality", s_arm_unwind_personality, 0 },
4596 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4597 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4598 { "save", s_arm_unwind_save, 0 },
fa073d69 4599 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4600 { "movsp", s_arm_unwind_movsp, 0 },
4601 { "pad", s_arm_unwind_pad, 0 },
4602 { "setfp", s_arm_unwind_setfp, 0 },
4603 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4604 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4605 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4606#else
4607 { "word", cons, 4},
f0927246
NC
4608
4609 /* These are used for dwarf. */
4610 {"2byte", cons, 2},
4611 {"4byte", cons, 4},
4612 {"8byte", cons, 8},
4613 /* These are used for dwarf2. */
4614 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4615 { "loc", dwarf2_directive_loc, 0 },
4616 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4617#endif
4618 { "extend", float_cons, 'x' },
4619 { "ldouble", float_cons, 'x' },
4620 { "packed", float_cons, 'p' },
f0927246
NC
4621#ifdef TE_PE
4622 {"secrel32", pe_directive_secrel, 0},
4623#endif
2e6976a8
DG
4624
4625 /* These are for compatibility with CodeComposer Studio. */
4626 {"ref", s_ccs_ref, 0},
4627 {"def", s_ccs_def, 0},
4628 {"asmfunc", s_ccs_asmfunc, 0},
4629 {"endasmfunc", s_ccs_endasmfunc, 0},
4630
c19d1205
ZW
4631 { 0, 0, 0 }
4632};
4633\f
4634/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4635
c19d1205
ZW
4636/* Generic immediate-value read function for use in insn parsing.
4637 STR points to the beginning of the immediate (the leading #);
4638 VAL receives the value; if the value is outside [MIN, MAX]
4639 issue an error. PREFIX_OPT is true if the immediate prefix is
4640 optional. */
b99bd4ef 4641
c19d1205
ZW
4642static int
4643parse_immediate (char **str, int *val, int min, int max,
4644 bfd_boolean prefix_opt)
4645{
4646 expressionS exp;
4647 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4648 if (exp.X_op != O_constant)
b99bd4ef 4649 {
c19d1205
ZW
4650 inst.error = _("constant expression required");
4651 return FAIL;
4652 }
b99bd4ef 4653
c19d1205
ZW
4654 if (exp.X_add_number < min || exp.X_add_number > max)
4655 {
4656 inst.error = _("immediate value out of range");
4657 return FAIL;
4658 }
b99bd4ef 4659
c19d1205
ZW
4660 *val = exp.X_add_number;
4661 return SUCCESS;
4662}
b99bd4ef 4663
5287ad62 4664/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4665 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4666 instructions. Puts the result directly in inst.operands[i]. */
4667
4668static int
4669parse_big_immediate (char **str, int i)
4670{
4671 expressionS exp;
4672 char *ptr = *str;
4673
4674 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4675
4676 if (exp.X_op == O_constant)
036dc3f7
PB
4677 {
4678 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4679 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4680 O_constant. We have to be careful not to break compilation for
4681 32-bit X_add_number, though. */
58ad575f 4682 if ((exp.X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4683 {
477330fc 4684 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
036dc3f7
PB
4685 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4686 inst.operands[i].regisimm = 1;
4687 }
4688 }
5287ad62 4689 else if (exp.X_op == O_big
95b75c01 4690 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
5287ad62
JB
4691 {
4692 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4693
5287ad62 4694 /* Bignums have their least significant bits in
477330fc
RM
4695 generic_bignum[0]. Make sure we put 32 bits in imm and
4696 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4697 gas_assert (parts != 0);
95b75c01
NC
4698
4699 /* Make sure that the number is not too big.
4700 PR 11972: Bignums can now be sign-extended to the
4701 size of a .octa so check that the out of range bits
4702 are all zero or all one. */
4703 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4704 {
4705 LITTLENUM_TYPE m = -1;
4706
4707 if (generic_bignum[parts * 2] != 0
4708 && generic_bignum[parts * 2] != m)
4709 return FAIL;
4710
4711 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4712 if (generic_bignum[j] != generic_bignum[j-1])
4713 return FAIL;
4714 }
4715
5287ad62
JB
4716 inst.operands[i].imm = 0;
4717 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4718 inst.operands[i].imm |= generic_bignum[idx]
4719 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4720 inst.operands[i].reg = 0;
4721 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4722 inst.operands[i].reg |= generic_bignum[idx]
4723 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4724 inst.operands[i].regisimm = 1;
4725 }
4726 else
4727 return FAIL;
5f4273c7 4728
5287ad62
JB
4729 *str = ptr;
4730
4731 return SUCCESS;
4732}
4733
c19d1205
ZW
4734/* Returns the pseudo-register number of an FPA immediate constant,
4735 or FAIL if there isn't a valid constant here. */
b99bd4ef 4736
c19d1205
ZW
4737static int
4738parse_fpa_immediate (char ** str)
4739{
4740 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4741 char * save_in;
4742 expressionS exp;
4743 int i;
4744 int j;
b99bd4ef 4745
c19d1205
ZW
4746 /* First try and match exact strings, this is to guarantee
4747 that some formats will work even for cross assembly. */
b99bd4ef 4748
c19d1205
ZW
4749 for (i = 0; fp_const[i]; i++)
4750 {
4751 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4752 {
c19d1205 4753 char *start = *str;
b99bd4ef 4754
c19d1205
ZW
4755 *str += strlen (fp_const[i]);
4756 if (is_end_of_line[(unsigned char) **str])
4757 return i + 8;
4758 *str = start;
4759 }
4760 }
b99bd4ef 4761
c19d1205
ZW
4762 /* Just because we didn't get a match doesn't mean that the constant
4763 isn't valid, just that it is in a format that we don't
4764 automatically recognize. Try parsing it with the standard
4765 expression routines. */
b99bd4ef 4766
c19d1205 4767 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4768
c19d1205
ZW
4769 /* Look for a raw floating point number. */
4770 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4771 && is_end_of_line[(unsigned char) *save_in])
4772 {
4773 for (i = 0; i < NUM_FLOAT_VALS; i++)
4774 {
4775 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4776 {
c19d1205
ZW
4777 if (words[j] != fp_values[i][j])
4778 break;
b99bd4ef
NC
4779 }
4780
c19d1205 4781 if (j == MAX_LITTLENUMS)
b99bd4ef 4782 {
c19d1205
ZW
4783 *str = save_in;
4784 return i + 8;
b99bd4ef
NC
4785 }
4786 }
4787 }
b99bd4ef 4788
c19d1205
ZW
4789 /* Try and parse a more complex expression, this will probably fail
4790 unless the code uses a floating point prefix (eg "0f"). */
4791 save_in = input_line_pointer;
4792 input_line_pointer = *str;
4793 if (expression (&exp) == absolute_section
4794 && exp.X_op == O_big
4795 && exp.X_add_number < 0)
4796 {
4797 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4798 Ditto for 15. */
4799 if (gen_to_words (words, 5, (long) 15) == 0)
4800 {
4801 for (i = 0; i < NUM_FLOAT_VALS; i++)
4802 {
4803 for (j = 0; j < MAX_LITTLENUMS; j++)
4804 {
4805 if (words[j] != fp_values[i][j])
4806 break;
4807 }
b99bd4ef 4808
c19d1205
ZW
4809 if (j == MAX_LITTLENUMS)
4810 {
4811 *str = input_line_pointer;
4812 input_line_pointer = save_in;
4813 return i + 8;
4814 }
4815 }
4816 }
b99bd4ef
NC
4817 }
4818
c19d1205
ZW
4819 *str = input_line_pointer;
4820 input_line_pointer = save_in;
4821 inst.error = _("invalid FPA immediate expression");
4822 return FAIL;
b99bd4ef
NC
4823}
4824
136da414
JB
4825/* Returns 1 if a number has "quarter-precision" float format
4826 0baBbbbbbc defgh000 00000000 00000000. */
4827
4828static int
4829is_quarter_float (unsigned imm)
4830{
4831 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4832 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4833}
4834
4835/* Parse an 8-bit "quarter-precision" floating point number of the form:
4836 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4837 The zero and minus-zero cases need special handling, since they can't be
4838 encoded in the "quarter-precision" float format, but can nonetheless be
4839 loaded as integer constants. */
136da414
JB
4840
4841static unsigned
4842parse_qfloat_immediate (char **ccp, int *immed)
4843{
4844 char *str = *ccp;
c96612cc 4845 char *fpnum;
136da414 4846 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4847 int found_fpchar = 0;
5f4273c7 4848
136da414 4849 skip_past_char (&str, '#');
5f4273c7 4850
c96612cc
JB
4851 /* We must not accidentally parse an integer as a floating-point number. Make
4852 sure that the value we parse is not an integer by checking for special
4853 characters '.' or 'e'.
4854 FIXME: This is a horrible hack, but doing better is tricky because type
4855 information isn't in a very usable state at parse time. */
4856 fpnum = str;
4857 skip_whitespace (fpnum);
4858
4859 if (strncmp (fpnum, "0x", 2) == 0)
4860 return FAIL;
4861 else
4862 {
4863 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
4864 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4865 {
4866 found_fpchar = 1;
4867 break;
4868 }
c96612cc
JB
4869
4870 if (!found_fpchar)
477330fc 4871 return FAIL;
c96612cc 4872 }
5f4273c7 4873
136da414
JB
4874 if ((str = atof_ieee (str, 's', words)) != NULL)
4875 {
4876 unsigned fpword = 0;
4877 int i;
5f4273c7 4878
136da414
JB
4879 /* Our FP word must be 32 bits (single-precision FP). */
4880 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
4881 {
4882 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4883 fpword |= words[i];
4884 }
5f4273c7 4885
c96612cc 4886 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 4887 *immed = fpword;
136da414 4888 else
477330fc 4889 return FAIL;
136da414
JB
4890
4891 *ccp = str;
5f4273c7 4892
136da414
JB
4893 return SUCCESS;
4894 }
5f4273c7 4895
136da414
JB
4896 return FAIL;
4897}
4898
c19d1205
ZW
4899/* Shift operands. */
4900enum shift_kind
b99bd4ef 4901{
c19d1205
ZW
4902 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4903};
b99bd4ef 4904
c19d1205
ZW
4905struct asm_shift_name
4906{
4907 const char *name;
4908 enum shift_kind kind;
4909};
b99bd4ef 4910
c19d1205
ZW
4911/* Third argument to parse_shift. */
4912enum parse_shift_mode
4913{
4914 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4915 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4916 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4917 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4918 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4919};
b99bd4ef 4920
c19d1205
ZW
4921/* Parse a <shift> specifier on an ARM data processing instruction.
4922 This has three forms:
b99bd4ef 4923
c19d1205
ZW
4924 (LSL|LSR|ASL|ASR|ROR) Rs
4925 (LSL|LSR|ASL|ASR|ROR) #imm
4926 RRX
b99bd4ef 4927
c19d1205
ZW
4928 Note that ASL is assimilated to LSL in the instruction encoding, and
4929 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4930
c19d1205
ZW
4931static int
4932parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4933{
c19d1205
ZW
4934 const struct asm_shift_name *shift_name;
4935 enum shift_kind shift;
4936 char *s = *str;
4937 char *p = s;
4938 int reg;
b99bd4ef 4939
c19d1205
ZW
4940 for (p = *str; ISALPHA (*p); p++)
4941 ;
b99bd4ef 4942
c19d1205 4943 if (p == *str)
b99bd4ef 4944 {
c19d1205
ZW
4945 inst.error = _("shift expression expected");
4946 return FAIL;
b99bd4ef
NC
4947 }
4948
21d799b5 4949 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 4950 p - *str);
c19d1205
ZW
4951
4952 if (shift_name == NULL)
b99bd4ef 4953 {
c19d1205
ZW
4954 inst.error = _("shift expression expected");
4955 return FAIL;
b99bd4ef
NC
4956 }
4957
c19d1205 4958 shift = shift_name->kind;
b99bd4ef 4959
c19d1205
ZW
4960 switch (mode)
4961 {
4962 case NO_SHIFT_RESTRICT:
4963 case SHIFT_IMMEDIATE: break;
b99bd4ef 4964
c19d1205
ZW
4965 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4966 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4967 {
4968 inst.error = _("'LSL' or 'ASR' required");
4969 return FAIL;
4970 }
4971 break;
b99bd4ef 4972
c19d1205
ZW
4973 case SHIFT_LSL_IMMEDIATE:
4974 if (shift != SHIFT_LSL)
4975 {
4976 inst.error = _("'LSL' required");
4977 return FAIL;
4978 }
4979 break;
b99bd4ef 4980
c19d1205
ZW
4981 case SHIFT_ASR_IMMEDIATE:
4982 if (shift != SHIFT_ASR)
4983 {
4984 inst.error = _("'ASR' required");
4985 return FAIL;
4986 }
4987 break;
b99bd4ef 4988
c19d1205
ZW
4989 default: abort ();
4990 }
b99bd4ef 4991
c19d1205
ZW
4992 if (shift != SHIFT_RRX)
4993 {
4994 /* Whitespace can appear here if the next thing is a bare digit. */
4995 skip_whitespace (p);
b99bd4ef 4996
c19d1205 4997 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4998 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4999 {
5000 inst.operands[i].imm = reg;
5001 inst.operands[i].immisreg = 1;
5002 }
5003 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5004 return FAIL;
5005 }
5006 inst.operands[i].shift_kind = shift;
5007 inst.operands[i].shifted = 1;
5008 *str = p;
5009 return SUCCESS;
b99bd4ef
NC
5010}
5011
c19d1205 5012/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5013
c19d1205
ZW
5014 #<immediate>
5015 #<immediate>, <rotate>
5016 <Rm>
5017 <Rm>, <shift>
b99bd4ef 5018
c19d1205
ZW
5019 where <shift> is defined by parse_shift above, and <rotate> is a
5020 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5021 is deferred to md_apply_fix. */
b99bd4ef 5022
c19d1205
ZW
5023static int
5024parse_shifter_operand (char **str, int i)
5025{
5026 int value;
91d6fa6a 5027 expressionS exp;
b99bd4ef 5028
dcbf9037 5029 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5030 {
5031 inst.operands[i].reg = value;
5032 inst.operands[i].isreg = 1;
b99bd4ef 5033
c19d1205
ZW
5034 /* parse_shift will override this if appropriate */
5035 inst.reloc.exp.X_op = O_constant;
5036 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5037
c19d1205
ZW
5038 if (skip_past_comma (str) == FAIL)
5039 return SUCCESS;
b99bd4ef 5040
c19d1205
ZW
5041 /* Shift operation on register. */
5042 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5043 }
5044
c19d1205
ZW
5045 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5046 return FAIL;
b99bd4ef 5047
c19d1205 5048 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5049 {
c19d1205 5050 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5051 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5052 return FAIL;
b99bd4ef 5053
91d6fa6a 5054 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5055 {
5056 inst.error = _("constant expression expected");
5057 return FAIL;
5058 }
b99bd4ef 5059
91d6fa6a 5060 value = exp.X_add_number;
c19d1205
ZW
5061 if (value < 0 || value > 30 || value % 2 != 0)
5062 {
5063 inst.error = _("invalid rotation");
5064 return FAIL;
5065 }
5066 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5067 {
5068 inst.error = _("invalid constant");
5069 return FAIL;
5070 }
09d92015 5071
a415b1cd
JB
5072 /* Encode as specified. */
5073 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5074 return SUCCESS;
09d92015
MM
5075 }
5076
c19d1205
ZW
5077 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5078 inst.reloc.pc_rel = 0;
5079 return SUCCESS;
09d92015
MM
5080}
5081
4962c51a
MS
5082/* Group relocation information. Each entry in the table contains the
5083 textual name of the relocation as may appear in assembler source
5084 and must end with a colon.
5085 Along with this textual name are the relocation codes to be used if
5086 the corresponding instruction is an ALU instruction (ADD or SUB only),
5087 an LDR, an LDRS, or an LDC. */
5088
5089struct group_reloc_table_entry
5090{
5091 const char *name;
5092 int alu_code;
5093 int ldr_code;
5094 int ldrs_code;
5095 int ldc_code;
5096};
5097
5098typedef enum
5099{
5100 /* Varieties of non-ALU group relocation. */
5101
5102 GROUP_LDR,
5103 GROUP_LDRS,
5104 GROUP_LDC
5105} group_reloc_type;
5106
5107static struct group_reloc_table_entry group_reloc_table[] =
5108 { /* Program counter relative: */
5109 { "pc_g0_nc",
5110 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5111 0, /* LDR */
5112 0, /* LDRS */
5113 0 }, /* LDC */
5114 { "pc_g0",
5115 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5116 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5117 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5118 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5119 { "pc_g1_nc",
5120 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5121 0, /* LDR */
5122 0, /* LDRS */
5123 0 }, /* LDC */
5124 { "pc_g1",
5125 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5126 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5127 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5128 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5129 { "pc_g2",
5130 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5131 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5132 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5133 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5134 /* Section base relative */
5135 { "sb_g0_nc",
5136 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5137 0, /* LDR */
5138 0, /* LDRS */
5139 0 }, /* LDC */
5140 { "sb_g0",
5141 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5142 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5143 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5144 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5145 { "sb_g1_nc",
5146 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5147 0, /* LDR */
5148 0, /* LDRS */
5149 0 }, /* LDC */
5150 { "sb_g1",
5151 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5152 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5153 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5154 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5155 { "sb_g2",
5156 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5157 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5158 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5159 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
5160
5161/* Given the address of a pointer pointing to the textual name of a group
5162 relocation as may appear in assembler source, attempt to find its details
5163 in group_reloc_table. The pointer will be updated to the character after
5164 the trailing colon. On failure, FAIL will be returned; SUCCESS
5165 otherwise. On success, *entry will be updated to point at the relevant
5166 group_reloc_table entry. */
5167
5168static int
5169find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5170{
5171 unsigned int i;
5172 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5173 {
5174 int length = strlen (group_reloc_table[i].name);
5175
5f4273c7
NC
5176 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5177 && (*str)[length] == ':')
477330fc
RM
5178 {
5179 *out = &group_reloc_table[i];
5180 *str += (length + 1);
5181 return SUCCESS;
5182 }
4962c51a
MS
5183 }
5184
5185 return FAIL;
5186}
5187
5188/* Parse a <shifter_operand> for an ARM data processing instruction
5189 (as for parse_shifter_operand) where group relocations are allowed:
5190
5191 #<immediate>
5192 #<immediate>, <rotate>
5193 #:<group_reloc>:<expression>
5194 <Rm>
5195 <Rm>, <shift>
5196
5197 where <group_reloc> is one of the strings defined in group_reloc_table.
5198 The hashes are optional.
5199
5200 Everything else is as for parse_shifter_operand. */
5201
5202static parse_operand_result
5203parse_shifter_operand_group_reloc (char **str, int i)
5204{
5205 /* Determine if we have the sequence of characters #: or just :
5206 coming next. If we do, then we check for a group relocation.
5207 If we don't, punt the whole lot to parse_shifter_operand. */
5208
5209 if (((*str)[0] == '#' && (*str)[1] == ':')
5210 || (*str)[0] == ':')
5211 {
5212 struct group_reloc_table_entry *entry;
5213
5214 if ((*str)[0] == '#')
477330fc 5215 (*str) += 2;
4962c51a 5216 else
477330fc 5217 (*str)++;
4962c51a
MS
5218
5219 /* Try to parse a group relocation. Anything else is an error. */
5220 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5221 {
5222 inst.error = _("unknown group relocation");
5223 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5224 }
4962c51a
MS
5225
5226 /* We now have the group relocation table entry corresponding to
477330fc 5227 the name in the assembler source. Next, we parse the expression. */
4962c51a 5228 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5229 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5230
5231 /* Record the relocation type (always the ALU variant here). */
21d799b5 5232 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5233 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5234
5235 return PARSE_OPERAND_SUCCESS;
5236 }
5237 else
5238 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5239 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5240
5241 /* Never reached. */
5242}
5243
8e560766
MGD
5244/* Parse a Neon alignment expression. Information is written to
5245 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5246
8e560766
MGD
5247 align .imm = align << 8, .immisalign=1, .preind=0 */
5248static parse_operand_result
5249parse_neon_alignment (char **str, int i)
5250{
5251 char *p = *str;
5252 expressionS exp;
5253
5254 my_get_expression (&exp, &p, GE_NO_PREFIX);
5255
5256 if (exp.X_op != O_constant)
5257 {
5258 inst.error = _("alignment must be constant");
5259 return PARSE_OPERAND_FAIL;
5260 }
5261
5262 inst.operands[i].imm = exp.X_add_number << 8;
5263 inst.operands[i].immisalign = 1;
5264 /* Alignments are not pre-indexes. */
5265 inst.operands[i].preind = 0;
5266
5267 *str = p;
5268 return PARSE_OPERAND_SUCCESS;
5269}
5270
c19d1205
ZW
5271/* Parse all forms of an ARM address expression. Information is written
5272 to inst.operands[i] and/or inst.reloc.
09d92015 5273
c19d1205 5274 Preindexed addressing (.preind=1):
09d92015 5275
c19d1205
ZW
5276 [Rn, #offset] .reg=Rn .reloc.exp=offset
5277 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5278 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5279 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5280
c19d1205 5281 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5282
c19d1205 5283 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5284
c19d1205
ZW
5285 [Rn], #offset .reg=Rn .reloc.exp=offset
5286 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5287 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5288 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5289
c19d1205 5290 Unindexed addressing (.preind=0, .postind=0):
09d92015 5291
c19d1205 5292 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5293
c19d1205 5294 Other:
09d92015 5295
c19d1205
ZW
5296 [Rn]{!} shorthand for [Rn,#0]{!}
5297 =immediate .isreg=0 .reloc.exp=immediate
5298 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5299
c19d1205
ZW
5300 It is the caller's responsibility to check for addressing modes not
5301 supported by the instruction, and to set inst.reloc.type. */
5302
4962c51a
MS
5303static parse_operand_result
5304parse_address_main (char **str, int i, int group_relocations,
477330fc 5305 group_reloc_type group_type)
09d92015 5306{
c19d1205
ZW
5307 char *p = *str;
5308 int reg;
09d92015 5309
c19d1205 5310 if (skip_past_char (&p, '[') == FAIL)
09d92015 5311 {
c19d1205
ZW
5312 if (skip_past_char (&p, '=') == FAIL)
5313 {
974da60d 5314 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5315 inst.reloc.pc_rel = 1;
5316 inst.operands[i].reg = REG_PC;
5317 inst.operands[i].isreg = 1;
5318 inst.operands[i].preind = 1;
5319 }
974da60d 5320 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
09d92015 5321
c19d1205 5322 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 5323 return PARSE_OPERAND_FAIL;
09d92015 5324
c19d1205 5325 *str = p;
4962c51a 5326 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5327 }
5328
8ab8155f
NC
5329 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5330 skip_whitespace (p);
5331
dcbf9037 5332 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5333 {
c19d1205 5334 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5335 return PARSE_OPERAND_FAIL;
09d92015 5336 }
c19d1205
ZW
5337 inst.operands[i].reg = reg;
5338 inst.operands[i].isreg = 1;
09d92015 5339
c19d1205 5340 if (skip_past_comma (&p) == SUCCESS)
09d92015 5341 {
c19d1205 5342 inst.operands[i].preind = 1;
09d92015 5343
c19d1205
ZW
5344 if (*p == '+') p++;
5345 else if (*p == '-') p++, inst.operands[i].negative = 1;
5346
dcbf9037 5347 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5348 {
c19d1205
ZW
5349 inst.operands[i].imm = reg;
5350 inst.operands[i].immisreg = 1;
5351
5352 if (skip_past_comma (&p) == SUCCESS)
5353 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5354 return PARSE_OPERAND_FAIL;
c19d1205 5355 }
5287ad62 5356 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5357 {
5358 /* FIXME: '@' should be used here, but it's filtered out by generic
5359 code before we get to see it here. This may be subject to
5360 change. */
5361 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5362
8e560766
MGD
5363 if (result != PARSE_OPERAND_SUCCESS)
5364 return result;
5365 }
c19d1205
ZW
5366 else
5367 {
5368 if (inst.operands[i].negative)
5369 {
5370 inst.operands[i].negative = 0;
5371 p--;
5372 }
4962c51a 5373
5f4273c7
NC
5374 if (group_relocations
5375 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5376 {
5377 struct group_reloc_table_entry *entry;
5378
477330fc
RM
5379 /* Skip over the #: or : sequence. */
5380 if (*p == '#')
5381 p += 2;
5382 else
5383 p++;
4962c51a
MS
5384
5385 /* Try to parse a group relocation. Anything else is an
477330fc 5386 error. */
4962c51a
MS
5387 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5388 {
5389 inst.error = _("unknown group relocation");
5390 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5391 }
5392
5393 /* We now have the group relocation table entry corresponding to
5394 the name in the assembler source. Next, we parse the
477330fc 5395 expression. */
4962c51a
MS
5396 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5397 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5398
5399 /* Record the relocation type. */
477330fc
RM
5400 switch (group_type)
5401 {
5402 case GROUP_LDR:
5403 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5404 break;
4962c51a 5405
477330fc
RM
5406 case GROUP_LDRS:
5407 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5408 break;
4962c51a 5409
477330fc
RM
5410 case GROUP_LDC:
5411 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5412 break;
4962c51a 5413
477330fc
RM
5414 default:
5415 gas_assert (0);
5416 }
4962c51a 5417
477330fc 5418 if (inst.reloc.type == 0)
4962c51a
MS
5419 {
5420 inst.error = _("this group relocation is not allowed on this instruction");
5421 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5422 }
477330fc
RM
5423 }
5424 else
26d97720
NS
5425 {
5426 char *q = p;
5427 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5428 return PARSE_OPERAND_FAIL;
5429 /* If the offset is 0, find out if it's a +0 or -0. */
5430 if (inst.reloc.exp.X_op == O_constant
5431 && inst.reloc.exp.X_add_number == 0)
5432 {
5433 skip_whitespace (q);
5434 if (*q == '#')
5435 {
5436 q++;
5437 skip_whitespace (q);
5438 }
5439 if (*q == '-')
5440 inst.operands[i].negative = 1;
5441 }
5442 }
09d92015
MM
5443 }
5444 }
8e560766
MGD
5445 else if (skip_past_char (&p, ':') == SUCCESS)
5446 {
5447 /* FIXME: '@' should be used here, but it's filtered out by generic code
5448 before we get to see it here. This may be subject to change. */
5449 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5450
8e560766
MGD
5451 if (result != PARSE_OPERAND_SUCCESS)
5452 return result;
5453 }
09d92015 5454
c19d1205 5455 if (skip_past_char (&p, ']') == FAIL)
09d92015 5456 {
c19d1205 5457 inst.error = _("']' expected");
4962c51a 5458 return PARSE_OPERAND_FAIL;
09d92015
MM
5459 }
5460
c19d1205
ZW
5461 if (skip_past_char (&p, '!') == SUCCESS)
5462 inst.operands[i].writeback = 1;
09d92015 5463
c19d1205 5464 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5465 {
c19d1205
ZW
5466 if (skip_past_char (&p, '{') == SUCCESS)
5467 {
5468 /* [Rn], {expr} - unindexed, with option */
5469 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5470 0, 255, TRUE) == FAIL)
4962c51a 5471 return PARSE_OPERAND_FAIL;
09d92015 5472
c19d1205
ZW
5473 if (skip_past_char (&p, '}') == FAIL)
5474 {
5475 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5476 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5477 }
5478 if (inst.operands[i].preind)
5479 {
5480 inst.error = _("cannot combine index with option");
4962c51a 5481 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5482 }
5483 *str = p;
4962c51a 5484 return PARSE_OPERAND_SUCCESS;
09d92015 5485 }
c19d1205
ZW
5486 else
5487 {
5488 inst.operands[i].postind = 1;
5489 inst.operands[i].writeback = 1;
09d92015 5490
c19d1205
ZW
5491 if (inst.operands[i].preind)
5492 {
5493 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5494 return PARSE_OPERAND_FAIL;
c19d1205 5495 }
09d92015 5496
c19d1205
ZW
5497 if (*p == '+') p++;
5498 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5499
dcbf9037 5500 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5501 {
477330fc
RM
5502 /* We might be using the immediate for alignment already. If we
5503 are, OR the register number into the low-order bits. */
5504 if (inst.operands[i].immisalign)
5505 inst.operands[i].imm |= reg;
5506 else
5507 inst.operands[i].imm = reg;
c19d1205 5508 inst.operands[i].immisreg = 1;
a737bd4d 5509
c19d1205
ZW
5510 if (skip_past_comma (&p) == SUCCESS)
5511 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5512 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5513 }
5514 else
5515 {
26d97720 5516 char *q = p;
c19d1205
ZW
5517 if (inst.operands[i].negative)
5518 {
5519 inst.operands[i].negative = 0;
5520 p--;
5521 }
5522 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5523 return PARSE_OPERAND_FAIL;
26d97720
NS
5524 /* If the offset is 0, find out if it's a +0 or -0. */
5525 if (inst.reloc.exp.X_op == O_constant
5526 && inst.reloc.exp.X_add_number == 0)
5527 {
5528 skip_whitespace (q);
5529 if (*q == '#')
5530 {
5531 q++;
5532 skip_whitespace (q);
5533 }
5534 if (*q == '-')
5535 inst.operands[i].negative = 1;
5536 }
c19d1205
ZW
5537 }
5538 }
a737bd4d
NC
5539 }
5540
c19d1205
ZW
5541 /* If at this point neither .preind nor .postind is set, we have a
5542 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5543 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5544 {
5545 inst.operands[i].preind = 1;
5546 inst.reloc.exp.X_op = O_constant;
5547 inst.reloc.exp.X_add_number = 0;
5548 }
5549 *str = p;
4962c51a
MS
5550 return PARSE_OPERAND_SUCCESS;
5551}
5552
5553static int
5554parse_address (char **str, int i)
5555{
21d799b5 5556 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5557 ? SUCCESS : FAIL;
4962c51a
MS
5558}
5559
5560static parse_operand_result
5561parse_address_group_reloc (char **str, int i, group_reloc_type type)
5562{
5563 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5564}
5565
b6895b4f
PB
5566/* Parse an operand for a MOVW or MOVT instruction. */
5567static int
5568parse_half (char **str)
5569{
5570 char * p;
5f4273c7 5571
b6895b4f
PB
5572 p = *str;
5573 skip_past_char (&p, '#');
5f4273c7 5574 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5575 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5576 else if (strncasecmp (p, ":upper16:", 9) == 0)
5577 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5578
5579 if (inst.reloc.type != BFD_RELOC_UNUSED)
5580 {
5581 p += 9;
5f4273c7 5582 skip_whitespace (p);
b6895b4f
PB
5583 }
5584
5585 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5586 return FAIL;
5587
5588 if (inst.reloc.type == BFD_RELOC_UNUSED)
5589 {
5590 if (inst.reloc.exp.X_op != O_constant)
5591 {
5592 inst.error = _("constant expression expected");
5593 return FAIL;
5594 }
5595 if (inst.reloc.exp.X_add_number < 0
5596 || inst.reloc.exp.X_add_number > 0xffff)
5597 {
5598 inst.error = _("immediate value out of range");
5599 return FAIL;
5600 }
5601 }
5602 *str = p;
5603 return SUCCESS;
5604}
5605
c19d1205 5606/* Miscellaneous. */
a737bd4d 5607
c19d1205
ZW
5608/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5609 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5610static int
d2cd1205 5611parse_psr (char **str, bfd_boolean lhs)
09d92015 5612{
c19d1205
ZW
5613 char *p;
5614 unsigned long psr_field;
62b3e311
PB
5615 const struct asm_psr *psr;
5616 char *start;
d2cd1205 5617 bfd_boolean is_apsr = FALSE;
ac7f631b 5618 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5619
a4482bb6
NC
5620 /* PR gas/12698: If the user has specified -march=all then m_profile will
5621 be TRUE, but we want to ignore it in this case as we are building for any
5622 CPU type, including non-m variants. */
5623 if (selected_cpu.core == arm_arch_any.core)
5624 m_profile = FALSE;
5625
c19d1205
ZW
5626 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5627 feature for ease of use and backwards compatibility. */
5628 p = *str;
62b3e311 5629 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5630 {
5631 if (m_profile)
5632 goto unsupported_psr;
fa94de6b 5633
d2cd1205
JB
5634 psr_field = SPSR_BIT;
5635 }
5636 else if (strncasecmp (p, "CPSR", 4) == 0)
5637 {
5638 if (m_profile)
5639 goto unsupported_psr;
5640
5641 psr_field = 0;
5642 }
5643 else if (strncasecmp (p, "APSR", 4) == 0)
5644 {
5645 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5646 and ARMv7-R architecture CPUs. */
5647 is_apsr = TRUE;
5648 psr_field = 0;
5649 }
5650 else if (m_profile)
62b3e311
PB
5651 {
5652 start = p;
5653 do
5654 p++;
5655 while (ISALNUM (*p) || *p == '_');
5656
d2cd1205
JB
5657 if (strncasecmp (start, "iapsr", 5) == 0
5658 || strncasecmp (start, "eapsr", 5) == 0
5659 || strncasecmp (start, "xpsr", 4) == 0
5660 || strncasecmp (start, "psr", 3) == 0)
5661 p = start + strcspn (start, "rR") + 1;
5662
21d799b5 5663 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5664 p - start);
d2cd1205 5665
62b3e311
PB
5666 if (!psr)
5667 return FAIL;
09d92015 5668
d2cd1205
JB
5669 /* If APSR is being written, a bitfield may be specified. Note that
5670 APSR itself is handled above. */
5671 if (psr->field <= 3)
5672 {
5673 psr_field = psr->field;
5674 is_apsr = TRUE;
5675 goto check_suffix;
5676 }
5677
62b3e311 5678 *str = p;
d2cd1205
JB
5679 /* M-profile MSR instructions have the mask field set to "10", except
5680 *PSR variants which modify APSR, which may use a different mask (and
5681 have been handled already). Do that by setting the PSR_f field
5682 here. */
5683 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5684 }
d2cd1205
JB
5685 else
5686 goto unsupported_psr;
09d92015 5687
62b3e311 5688 p += 4;
d2cd1205 5689check_suffix:
c19d1205
ZW
5690 if (*p == '_')
5691 {
5692 /* A suffix follows. */
c19d1205
ZW
5693 p++;
5694 start = p;
a737bd4d 5695
c19d1205
ZW
5696 do
5697 p++;
5698 while (ISALNUM (*p) || *p == '_');
a737bd4d 5699
d2cd1205
JB
5700 if (is_apsr)
5701 {
5702 /* APSR uses a notation for bits, rather than fields. */
5703 unsigned int nzcvq_bits = 0;
5704 unsigned int g_bit = 0;
5705 char *bit;
fa94de6b 5706
d2cd1205
JB
5707 for (bit = start; bit != p; bit++)
5708 {
5709 switch (TOLOWER (*bit))
477330fc 5710 {
d2cd1205
JB
5711 case 'n':
5712 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5713 break;
5714
5715 case 'z':
5716 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5717 break;
5718
5719 case 'c':
5720 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5721 break;
5722
5723 case 'v':
5724 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5725 break;
fa94de6b 5726
d2cd1205
JB
5727 case 'q':
5728 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5729 break;
fa94de6b 5730
d2cd1205
JB
5731 case 'g':
5732 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5733 break;
fa94de6b 5734
d2cd1205
JB
5735 default:
5736 inst.error = _("unexpected bit specified after APSR");
5737 return FAIL;
5738 }
5739 }
fa94de6b 5740
d2cd1205
JB
5741 if (nzcvq_bits == 0x1f)
5742 psr_field |= PSR_f;
fa94de6b 5743
d2cd1205
JB
5744 if (g_bit == 0x1)
5745 {
5746 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5747 {
d2cd1205
JB
5748 inst.error = _("selected processor does not "
5749 "support DSP extension");
5750 return FAIL;
5751 }
5752
5753 psr_field |= PSR_s;
5754 }
fa94de6b 5755
d2cd1205
JB
5756 if ((nzcvq_bits & 0x20) != 0
5757 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5758 || (g_bit & 0x2) != 0)
5759 {
5760 inst.error = _("bad bitmask specified after APSR");
5761 return FAIL;
5762 }
5763 }
5764 else
477330fc 5765 {
d2cd1205 5766 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5767 p - start);
d2cd1205 5768 if (!psr)
477330fc 5769 goto error;
a737bd4d 5770
d2cd1205
JB
5771 psr_field |= psr->field;
5772 }
a737bd4d 5773 }
c19d1205 5774 else
a737bd4d 5775 {
c19d1205
ZW
5776 if (ISALNUM (*p))
5777 goto error; /* Garbage after "[CS]PSR". */
5778
d2cd1205 5779 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5780 is deprecated, but allow it anyway. */
d2cd1205
JB
5781 if (is_apsr && lhs)
5782 {
5783 psr_field |= PSR_f;
5784 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5785 "deprecated"));
5786 }
5787 else if (!m_profile)
5788 /* These bits are never right for M-profile devices: don't set them
5789 (only code paths which read/write APSR reach here). */
5790 psr_field |= (PSR_c | PSR_f);
a737bd4d 5791 }
c19d1205
ZW
5792 *str = p;
5793 return psr_field;
a737bd4d 5794
d2cd1205
JB
5795 unsupported_psr:
5796 inst.error = _("selected processor does not support requested special "
5797 "purpose register");
5798 return FAIL;
5799
c19d1205
ZW
5800 error:
5801 inst.error = _("flag for {c}psr instruction expected");
5802 return FAIL;
a737bd4d
NC
5803}
5804
c19d1205
ZW
5805/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5806 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5807
c19d1205
ZW
5808static int
5809parse_cps_flags (char **str)
a737bd4d 5810{
c19d1205
ZW
5811 int val = 0;
5812 int saw_a_flag = 0;
5813 char *s = *str;
a737bd4d 5814
c19d1205
ZW
5815 for (;;)
5816 switch (*s++)
5817 {
5818 case '\0': case ',':
5819 goto done;
a737bd4d 5820
c19d1205
ZW
5821 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5822 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5823 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5824
c19d1205
ZW
5825 default:
5826 inst.error = _("unrecognized CPS flag");
5827 return FAIL;
5828 }
a737bd4d 5829
c19d1205
ZW
5830 done:
5831 if (saw_a_flag == 0)
a737bd4d 5832 {
c19d1205
ZW
5833 inst.error = _("missing CPS flags");
5834 return FAIL;
a737bd4d 5835 }
a737bd4d 5836
c19d1205
ZW
5837 *str = s - 1;
5838 return val;
a737bd4d
NC
5839}
5840
c19d1205
ZW
5841/* Parse an endian specifier ("BE" or "LE", case insensitive);
5842 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5843
5844static int
c19d1205 5845parse_endian_specifier (char **str)
a737bd4d 5846{
c19d1205
ZW
5847 int little_endian;
5848 char *s = *str;
a737bd4d 5849
c19d1205
ZW
5850 if (strncasecmp (s, "BE", 2))
5851 little_endian = 0;
5852 else if (strncasecmp (s, "LE", 2))
5853 little_endian = 1;
5854 else
a737bd4d 5855 {
c19d1205 5856 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5857 return FAIL;
5858 }
5859
c19d1205 5860 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5861 {
c19d1205 5862 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5863 return FAIL;
5864 }
5865
c19d1205
ZW
5866 *str = s + 2;
5867 return little_endian;
5868}
a737bd4d 5869
c19d1205
ZW
5870/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5871 value suitable for poking into the rotate field of an sxt or sxta
5872 instruction, or FAIL on error. */
5873
5874static int
5875parse_ror (char **str)
5876{
5877 int rot;
5878 char *s = *str;
5879
5880 if (strncasecmp (s, "ROR", 3) == 0)
5881 s += 3;
5882 else
a737bd4d 5883 {
c19d1205 5884 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5885 return FAIL;
5886 }
c19d1205
ZW
5887
5888 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5889 return FAIL;
5890
5891 switch (rot)
a737bd4d 5892 {
c19d1205
ZW
5893 case 0: *str = s; return 0x0;
5894 case 8: *str = s; return 0x1;
5895 case 16: *str = s; return 0x2;
5896 case 24: *str = s; return 0x3;
5897
5898 default:
5899 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5900 return FAIL;
5901 }
c19d1205 5902}
a737bd4d 5903
c19d1205
ZW
5904/* Parse a conditional code (from conds[] below). The value returned is in the
5905 range 0 .. 14, or FAIL. */
5906static int
5907parse_cond (char **str)
5908{
c462b453 5909 char *q;
c19d1205 5910 const struct asm_cond *c;
c462b453
PB
5911 int n;
5912 /* Condition codes are always 2 characters, so matching up to
5913 3 characters is sufficient. */
5914 char cond[3];
a737bd4d 5915
c462b453
PB
5916 q = *str;
5917 n = 0;
5918 while (ISALPHA (*q) && n < 3)
5919 {
e07e6e58 5920 cond[n] = TOLOWER (*q);
c462b453
PB
5921 q++;
5922 n++;
5923 }
a737bd4d 5924
21d799b5 5925 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5926 if (!c)
a737bd4d 5927 {
c19d1205 5928 inst.error = _("condition required");
a737bd4d
NC
5929 return FAIL;
5930 }
5931
c19d1205
ZW
5932 *str = q;
5933 return c->value;
5934}
5935
e797f7e0
MGD
5936/* If the given feature available in the selected CPU, mark it as used.
5937 Returns TRUE iff feature is available. */
5938static bfd_boolean
5939mark_feature_used (const arm_feature_set *feature)
5940{
5941 /* Ensure the option is valid on the current architecture. */
5942 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
5943 return FALSE;
5944
5945 /* Add the appropriate architecture feature for the barrier option used.
5946 */
5947 if (thumb_mode)
5948 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
5949 else
5950 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
5951
5952 return TRUE;
5953}
5954
62b3e311
PB
5955/* Parse an option for a barrier instruction. Returns the encoding for the
5956 option, or FAIL. */
5957static int
5958parse_barrier (char **str)
5959{
5960 char *p, *q;
5961 const struct asm_barrier_opt *o;
5962
5963 p = q = *str;
5964 while (ISALPHA (*q))
5965 q++;
5966
21d799b5 5967 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 5968 q - p);
62b3e311
PB
5969 if (!o)
5970 return FAIL;
5971
e797f7e0
MGD
5972 if (!mark_feature_used (&o->arch))
5973 return FAIL;
5974
62b3e311
PB
5975 *str = q;
5976 return o->value;
5977}
5978
92e90b6e
PB
5979/* Parse the operands of a table branch instruction. Similar to a memory
5980 operand. */
5981static int
5982parse_tb (char **str)
5983{
5984 char * p = *str;
5985 int reg;
5986
5987 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5988 {
5989 inst.error = _("'[' expected");
5990 return FAIL;
5991 }
92e90b6e 5992
dcbf9037 5993 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5994 {
5995 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5996 return FAIL;
5997 }
5998 inst.operands[0].reg = reg;
5999
6000 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6001 {
6002 inst.error = _("',' expected");
6003 return FAIL;
6004 }
5f4273c7 6005
dcbf9037 6006 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6007 {
6008 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6009 return FAIL;
6010 }
6011 inst.operands[0].imm = reg;
6012
6013 if (skip_past_comma (&p) == SUCCESS)
6014 {
6015 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6016 return FAIL;
6017 if (inst.reloc.exp.X_add_number != 1)
6018 {
6019 inst.error = _("invalid shift");
6020 return FAIL;
6021 }
6022 inst.operands[0].shifted = 1;
6023 }
6024
6025 if (skip_past_char (&p, ']') == FAIL)
6026 {
6027 inst.error = _("']' expected");
6028 return FAIL;
6029 }
6030 *str = p;
6031 return SUCCESS;
6032}
6033
5287ad62
JB
6034/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6035 information on the types the operands can take and how they are encoded.
037e8744
JB
6036 Up to four operands may be read; this function handles setting the
6037 ".present" field for each read operand itself.
5287ad62
JB
6038 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6039 else returns FAIL. */
6040
6041static int
6042parse_neon_mov (char **str, int *which_operand)
6043{
6044 int i = *which_operand, val;
6045 enum arm_reg_type rtype;
6046 char *ptr = *str;
dcbf9037 6047 struct neon_type_el optype;
5f4273c7 6048
dcbf9037 6049 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6050 {
6051 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6052 inst.operands[i].reg = val;
6053 inst.operands[i].isscalar = 1;
dcbf9037 6054 inst.operands[i].vectype = optype;
5287ad62
JB
6055 inst.operands[i++].present = 1;
6056
6057 if (skip_past_comma (&ptr) == FAIL)
477330fc 6058 goto wanted_comma;
5f4273c7 6059
dcbf9037 6060 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6061 goto wanted_arm;
5f4273c7 6062
5287ad62
JB
6063 inst.operands[i].reg = val;
6064 inst.operands[i].isreg = 1;
6065 inst.operands[i].present = 1;
6066 }
037e8744 6067 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6068 != FAIL)
5287ad62
JB
6069 {
6070 /* Cases 0, 1, 2, 3, 5 (D only). */
6071 if (skip_past_comma (&ptr) == FAIL)
477330fc 6072 goto wanted_comma;
5f4273c7 6073
5287ad62
JB
6074 inst.operands[i].reg = val;
6075 inst.operands[i].isreg = 1;
6076 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6077 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6078 inst.operands[i].isvec = 1;
dcbf9037 6079 inst.operands[i].vectype = optype;
5287ad62
JB
6080 inst.operands[i++].present = 1;
6081
dcbf9037 6082 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6083 {
6084 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6085 Case 13: VMOV <Sd>, <Rm> */
6086 inst.operands[i].reg = val;
6087 inst.operands[i].isreg = 1;
6088 inst.operands[i].present = 1;
6089
6090 if (rtype == REG_TYPE_NQ)
6091 {
6092 first_error (_("can't use Neon quad register here"));
6093 return FAIL;
6094 }
6095 else if (rtype != REG_TYPE_VFS)
6096 {
6097 i++;
6098 if (skip_past_comma (&ptr) == FAIL)
6099 goto wanted_comma;
6100 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6101 goto wanted_arm;
6102 inst.operands[i].reg = val;
6103 inst.operands[i].isreg = 1;
6104 inst.operands[i].present = 1;
6105 }
6106 }
037e8744 6107 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6108 &optype)) != FAIL)
6109 {
6110 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6111 Case 1: VMOV<c><q> <Dd>, <Dm>
6112 Case 8: VMOV.F32 <Sd>, <Sm>
6113 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6114
6115 inst.operands[i].reg = val;
6116 inst.operands[i].isreg = 1;
6117 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6118 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6119 inst.operands[i].isvec = 1;
6120 inst.operands[i].vectype = optype;
6121 inst.operands[i].present = 1;
6122
6123 if (skip_past_comma (&ptr) == SUCCESS)
6124 {
6125 /* Case 15. */
6126 i++;
6127
6128 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6129 goto wanted_arm;
6130
6131 inst.operands[i].reg = val;
6132 inst.operands[i].isreg = 1;
6133 inst.operands[i++].present = 1;
6134
6135 if (skip_past_comma (&ptr) == FAIL)
6136 goto wanted_comma;
6137
6138 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6139 goto wanted_arm;
6140
6141 inst.operands[i].reg = val;
6142 inst.operands[i].isreg = 1;
6143 inst.operands[i].present = 1;
6144 }
6145 }
4641781c 6146 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6147 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6148 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6149 Case 10: VMOV.F32 <Sd>, #<imm>
6150 Case 11: VMOV.F64 <Dd>, #<imm> */
6151 inst.operands[i].immisfloat = 1;
4641781c 6152 else if (parse_big_immediate (&ptr, i) == SUCCESS)
477330fc
RM
6153 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6154 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6155 ;
5287ad62 6156 else
477330fc
RM
6157 {
6158 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6159 return FAIL;
6160 }
5287ad62 6161 }
dcbf9037 6162 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6163 {
6164 /* Cases 6, 7. */
6165 inst.operands[i].reg = val;
6166 inst.operands[i].isreg = 1;
6167 inst.operands[i++].present = 1;
5f4273c7 6168
5287ad62 6169 if (skip_past_comma (&ptr) == FAIL)
477330fc 6170 goto wanted_comma;
5f4273c7 6171
dcbf9037 6172 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6173 {
6174 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6175 inst.operands[i].reg = val;
6176 inst.operands[i].isscalar = 1;
6177 inst.operands[i].present = 1;
6178 inst.operands[i].vectype = optype;
6179 }
dcbf9037 6180 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6181 {
6182 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6183 inst.operands[i].reg = val;
6184 inst.operands[i].isreg = 1;
6185 inst.operands[i++].present = 1;
6186
6187 if (skip_past_comma (&ptr) == FAIL)
6188 goto wanted_comma;
6189
6190 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6191 == FAIL)
6192 {
6193 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6194 return FAIL;
6195 }
6196
6197 inst.operands[i].reg = val;
6198 inst.operands[i].isreg = 1;
6199 inst.operands[i].isvec = 1;
6200 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6201 inst.operands[i].vectype = optype;
6202 inst.operands[i].present = 1;
6203
6204 if (rtype == REG_TYPE_VFS)
6205 {
6206 /* Case 14. */
6207 i++;
6208 if (skip_past_comma (&ptr) == FAIL)
6209 goto wanted_comma;
6210 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6211 &optype)) == FAIL)
6212 {
6213 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6214 return FAIL;
6215 }
6216 inst.operands[i].reg = val;
6217 inst.operands[i].isreg = 1;
6218 inst.operands[i].isvec = 1;
6219 inst.operands[i].issingle = 1;
6220 inst.operands[i].vectype = optype;
6221 inst.operands[i].present = 1;
6222 }
6223 }
037e8744 6224 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6225 != FAIL)
6226 {
6227 /* Case 13. */
6228 inst.operands[i].reg = val;
6229 inst.operands[i].isreg = 1;
6230 inst.operands[i].isvec = 1;
6231 inst.operands[i].issingle = 1;
6232 inst.operands[i].vectype = optype;
6233 inst.operands[i].present = 1;
6234 }
5287ad62
JB
6235 }
6236 else
6237 {
dcbf9037 6238 first_error (_("parse error"));
5287ad62
JB
6239 return FAIL;
6240 }
6241
6242 /* Successfully parsed the operands. Update args. */
6243 *which_operand = i;
6244 *str = ptr;
6245 return SUCCESS;
6246
5f4273c7 6247 wanted_comma:
dcbf9037 6248 first_error (_("expected comma"));
5287ad62 6249 return FAIL;
5f4273c7
NC
6250
6251 wanted_arm:
dcbf9037 6252 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6253 return FAIL;
5287ad62
JB
6254}
6255
5be8be5d
DG
6256/* Use this macro when the operand constraints are different
6257 for ARM and THUMB (e.g. ldrd). */
6258#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6259 ((arm_operand) | ((thumb_operand) << 16))
6260
c19d1205
ZW
6261/* Matcher codes for parse_operands. */
6262enum operand_parse_code
6263{
6264 OP_stop, /* end of line */
6265
6266 OP_RR, /* ARM register */
6267 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6268 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6269 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6270 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6271 optional trailing ! */
c19d1205
ZW
6272 OP_RRw, /* ARM register, not r15, optional trailing ! */
6273 OP_RCP, /* Coprocessor number */
6274 OP_RCN, /* Coprocessor register */
6275 OP_RF, /* FPA register */
6276 OP_RVS, /* VFP single precision register */
5287ad62
JB
6277 OP_RVD, /* VFP double precision register (0..15) */
6278 OP_RND, /* Neon double precision register (0..31) */
6279 OP_RNQ, /* Neon quad precision register */
037e8744 6280 OP_RVSD, /* VFP single or double precision register */
5287ad62 6281 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6282 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6283 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6284 OP_RVC, /* VFP control register */
6285 OP_RMF, /* Maverick F register */
6286 OP_RMD, /* Maverick D register */
6287 OP_RMFX, /* Maverick FX register */
6288 OP_RMDX, /* Maverick DX register */
6289 OP_RMAX, /* Maverick AX register */
6290 OP_RMDS, /* Maverick DSPSC register */
6291 OP_RIWR, /* iWMMXt wR register */
6292 OP_RIWC, /* iWMMXt wC register */
6293 OP_RIWG, /* iWMMXt wCG register */
6294 OP_RXA, /* XScale accumulator register */
6295
6296 OP_REGLST, /* ARM register list */
6297 OP_VRSLST, /* VFP single-precision register list */
6298 OP_VRDLST, /* VFP double-precision register list */
037e8744 6299 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6300 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6301 OP_NSTRLST, /* Neon element/structure list */
6302
5287ad62 6303 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6304 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 6305 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6306 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6307 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6308 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6309 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6310 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6311 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6312 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6313
6314 OP_I0, /* immediate zero */
c19d1205
ZW
6315 OP_I7, /* immediate value 0 .. 7 */
6316 OP_I15, /* 0 .. 15 */
6317 OP_I16, /* 1 .. 16 */
5287ad62 6318 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6319 OP_I31, /* 0 .. 31 */
6320 OP_I31w, /* 0 .. 31, optional trailing ! */
6321 OP_I32, /* 1 .. 32 */
5287ad62
JB
6322 OP_I32z, /* 0 .. 32 */
6323 OP_I63, /* 0 .. 63 */
c19d1205 6324 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6325 OP_I64, /* 1 .. 64 */
6326 OP_I64z, /* 0 .. 64 */
c19d1205 6327 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6328
6329 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6330 OP_I7b, /* 0 .. 7 */
6331 OP_I15b, /* 0 .. 15 */
6332 OP_I31b, /* 0 .. 31 */
6333
6334 OP_SH, /* shifter operand */
4962c51a 6335 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6336 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6337 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6338 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6339 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6340 OP_EXP, /* arbitrary expression */
6341 OP_EXPi, /* same, with optional immediate prefix */
6342 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6343 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6344
6345 OP_CPSF, /* CPS flags */
6346 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6347 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6348 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6349 OP_COND, /* conditional code */
92e90b6e 6350 OP_TB, /* Table branch. */
c19d1205 6351
037e8744
JB
6352 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6353
c19d1205
ZW
6354 OP_RRnpc_I0, /* ARM register or literal 0 */
6355 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6356 OP_RR_EXi, /* ARM register or expression with imm prefix */
6357 OP_RF_IF, /* FPA register or immediate */
6358 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6359 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6360
6361 /* Optional operands. */
6362 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6363 OP_oI31b, /* 0 .. 31 */
5287ad62 6364 OP_oI32b, /* 1 .. 32 */
5f1af56b 6365 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6366 OP_oIffffb, /* 0 .. 65535 */
6367 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6368
6369 OP_oRR, /* ARM register */
6370 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6371 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6372 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6373 OP_oRND, /* Optional Neon double precision register */
6374 OP_oRNQ, /* Optional Neon quad precision register */
6375 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6376 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6377 OP_oSHll, /* LSL immediate */
6378 OP_oSHar, /* ASR immediate */
6379 OP_oSHllar, /* LSL or ASR immediate */
6380 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6381 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6382
5be8be5d
DG
6383 /* Some pre-defined mixed (ARM/THUMB) operands. */
6384 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6385 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6386 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6387
c19d1205
ZW
6388 OP_FIRST_OPTIONAL = OP_oI7b
6389};
a737bd4d 6390
c19d1205
ZW
6391/* Generic instruction operand parser. This does no encoding and no
6392 semantic validation; it merely squirrels values away in the inst
6393 structure. Returns SUCCESS or FAIL depending on whether the
6394 specified grammar matched. */
6395static int
5be8be5d 6396parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6397{
5be8be5d 6398 unsigned const int *upat = pattern;
c19d1205
ZW
6399 char *backtrack_pos = 0;
6400 const char *backtrack_error = 0;
99aad254 6401 int i, val = 0, backtrack_index = 0;
5287ad62 6402 enum arm_reg_type rtype;
4962c51a 6403 parse_operand_result result;
5be8be5d 6404 unsigned int op_parse_code;
c19d1205 6405
e07e6e58
NC
6406#define po_char_or_fail(chr) \
6407 do \
6408 { \
6409 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6410 goto bad_args; \
e07e6e58
NC
6411 } \
6412 while (0)
c19d1205 6413
e07e6e58
NC
6414#define po_reg_or_fail(regtype) \
6415 do \
dcbf9037 6416 { \
e07e6e58 6417 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6418 & inst.operands[i].vectype); \
e07e6e58 6419 if (val == FAIL) \
477330fc
RM
6420 { \
6421 first_error (_(reg_expected_msgs[regtype])); \
6422 goto failure; \
6423 } \
e07e6e58
NC
6424 inst.operands[i].reg = val; \
6425 inst.operands[i].isreg = 1; \
6426 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6427 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6428 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6429 || rtype == REG_TYPE_VFD \
6430 || rtype == REG_TYPE_NQ); \
dcbf9037 6431 } \
e07e6e58
NC
6432 while (0)
6433
6434#define po_reg_or_goto(regtype, label) \
6435 do \
6436 { \
6437 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6438 & inst.operands[i].vectype); \
6439 if (val == FAIL) \
6440 goto label; \
dcbf9037 6441 \
e07e6e58
NC
6442 inst.operands[i].reg = val; \
6443 inst.operands[i].isreg = 1; \
6444 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6445 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6446 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6447 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6448 || rtype == REG_TYPE_NQ); \
6449 } \
6450 while (0)
6451
6452#define po_imm_or_fail(min, max, popt) \
6453 do \
6454 { \
6455 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6456 goto failure; \
6457 inst.operands[i].imm = val; \
6458 } \
6459 while (0)
6460
6461#define po_scalar_or_goto(elsz, label) \
6462 do \
6463 { \
6464 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6465 if (val == FAIL) \
6466 goto label; \
6467 inst.operands[i].reg = val; \
6468 inst.operands[i].isscalar = 1; \
6469 } \
6470 while (0)
6471
6472#define po_misc_or_fail(expr) \
6473 do \
6474 { \
6475 if (expr) \
6476 goto failure; \
6477 } \
6478 while (0)
6479
6480#define po_misc_or_fail_no_backtrack(expr) \
6481 do \
6482 { \
6483 result = expr; \
6484 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6485 backtrack_pos = 0; \
6486 if (result != PARSE_OPERAND_SUCCESS) \
6487 goto failure; \
6488 } \
6489 while (0)
4962c51a 6490
52e7f43d
RE
6491#define po_barrier_or_imm(str) \
6492 do \
6493 { \
6494 val = parse_barrier (&str); \
ccb84d65
JB
6495 if (val == FAIL && ! ISALPHA (*str)) \
6496 goto immediate; \
6497 if (val == FAIL \
6498 /* ISB can only take SY as an option. */ \
6499 || ((inst.instruction & 0xf0) == 0x60 \
6500 && val != 0xf)) \
52e7f43d 6501 { \
ccb84d65
JB
6502 inst.error = _("invalid barrier type"); \
6503 backtrack_pos = 0; \
6504 goto failure; \
52e7f43d
RE
6505 } \
6506 } \
6507 while (0)
6508
c19d1205
ZW
6509 skip_whitespace (str);
6510
6511 for (i = 0; upat[i] != OP_stop; i++)
6512 {
5be8be5d
DG
6513 op_parse_code = upat[i];
6514 if (op_parse_code >= 1<<16)
6515 op_parse_code = thumb ? (op_parse_code >> 16)
6516 : (op_parse_code & ((1<<16)-1));
6517
6518 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6519 {
6520 /* Remember where we are in case we need to backtrack. */
9c2799c2 6521 gas_assert (!backtrack_pos);
c19d1205
ZW
6522 backtrack_pos = str;
6523 backtrack_error = inst.error;
6524 backtrack_index = i;
6525 }
6526
b6702015 6527 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6528 po_char_or_fail (',');
6529
5be8be5d 6530 switch (op_parse_code)
c19d1205
ZW
6531 {
6532 /* Registers */
6533 case OP_oRRnpc:
5be8be5d 6534 case OP_oRRnpcsp:
c19d1205 6535 case OP_RRnpc:
5be8be5d 6536 case OP_RRnpcsp:
c19d1205
ZW
6537 case OP_oRR:
6538 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6539 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6540 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6541 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6542 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6543 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6544 case OP_oRND:
5287ad62 6545 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6546 case OP_RVC:
6547 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6548 break;
6549 /* Also accept generic coprocessor regs for unknown registers. */
6550 coproc_reg:
6551 po_reg_or_fail (REG_TYPE_CN);
6552 break;
c19d1205
ZW
6553 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6554 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6555 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6556 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6557 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6558 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6559 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6560 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6561 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6562 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6563 case OP_oRNQ:
5287ad62 6564 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6565 case OP_oRNDQ:
5287ad62 6566 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6567 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6568 case OP_oRNSDQ:
6569 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6570
6571 /* Neon scalar. Using an element size of 8 means that some invalid
6572 scalars are accepted here, so deal with those in later code. */
6573 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6574
6575 case OP_RNDQ_I0:
6576 {
6577 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6578 break;
6579 try_imm0:
6580 po_imm_or_fail (0, 0, TRUE);
6581 }
6582 break;
6583
6584 case OP_RVSD_I0:
6585 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6586 break;
6587
6588 case OP_RR_RNSC:
6589 {
6590 po_scalar_or_goto (8, try_rr);
6591 break;
6592 try_rr:
6593 po_reg_or_fail (REG_TYPE_RN);
6594 }
6595 break;
6596
6597 case OP_RNSDQ_RNSC:
6598 {
6599 po_scalar_or_goto (8, try_nsdq);
6600 break;
6601 try_nsdq:
6602 po_reg_or_fail (REG_TYPE_NSDQ);
6603 }
6604 break;
6605
6606 case OP_RNDQ_RNSC:
6607 {
6608 po_scalar_or_goto (8, try_ndq);
6609 break;
6610 try_ndq:
6611 po_reg_or_fail (REG_TYPE_NDQ);
6612 }
6613 break;
6614
6615 case OP_RND_RNSC:
6616 {
6617 po_scalar_or_goto (8, try_vfd);
6618 break;
6619 try_vfd:
6620 po_reg_or_fail (REG_TYPE_VFD);
6621 }
6622 break;
6623
6624 case OP_VMOV:
6625 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6626 not careful then bad things might happen. */
6627 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6628 break;
6629
6630 case OP_RNDQ_Ibig:
6631 {
6632 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6633 break;
6634 try_immbig:
6635 /* There's a possibility of getting a 64-bit immediate here, so
6636 we need special handling. */
6637 if (parse_big_immediate (&str, i) == FAIL)
6638 {
6639 inst.error = _("immediate value is out of range");
6640 goto failure;
6641 }
6642 }
6643 break;
6644
6645 case OP_RNDQ_I63b:
6646 {
6647 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6648 break;
6649 try_shimm:
6650 po_imm_or_fail (0, 63, TRUE);
6651 }
6652 break;
c19d1205
ZW
6653
6654 case OP_RRnpcb:
6655 po_char_or_fail ('[');
6656 po_reg_or_fail (REG_TYPE_RN);
6657 po_char_or_fail (']');
6658 break;
a737bd4d 6659
55881a11 6660 case OP_RRnpctw:
c19d1205 6661 case OP_RRw:
b6702015 6662 case OP_oRRw:
c19d1205
ZW
6663 po_reg_or_fail (REG_TYPE_RN);
6664 if (skip_past_char (&str, '!') == SUCCESS)
6665 inst.operands[i].writeback = 1;
6666 break;
6667
6668 /* Immediates */
6669 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6670 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6671 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6672 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6673 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6674 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6675 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6676 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6677 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6678 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6679 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6680 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6681
6682 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6683 case OP_oI7b:
6684 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6685 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6686 case OP_oI31b:
6687 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6688 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6689 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6690 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6691
6692 /* Immediate variants */
6693 case OP_oI255c:
6694 po_char_or_fail ('{');
6695 po_imm_or_fail (0, 255, TRUE);
6696 po_char_or_fail ('}');
6697 break;
6698
6699 case OP_I31w:
6700 /* The expression parser chokes on a trailing !, so we have
6701 to find it first and zap it. */
6702 {
6703 char *s = str;
6704 while (*s && *s != ',')
6705 s++;
6706 if (s[-1] == '!')
6707 {
6708 s[-1] = '\0';
6709 inst.operands[i].writeback = 1;
6710 }
6711 po_imm_or_fail (0, 31, TRUE);
6712 if (str == s - 1)
6713 str = s;
6714 }
6715 break;
6716
6717 /* Expressions */
6718 case OP_EXPi: EXPi:
6719 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6720 GE_OPT_PREFIX));
6721 break;
6722
6723 case OP_EXP:
6724 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6725 GE_NO_PREFIX));
6726 break;
6727
6728 case OP_EXPr: EXPr:
6729 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6730 GE_NO_PREFIX));
6731 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6732 {
c19d1205
ZW
6733 val = parse_reloc (&str);
6734 if (val == -1)
6735 {
6736 inst.error = _("unrecognized relocation suffix");
6737 goto failure;
6738 }
6739 else if (val != BFD_RELOC_UNUSED)
6740 {
6741 inst.operands[i].imm = val;
6742 inst.operands[i].hasreloc = 1;
6743 }
a737bd4d 6744 }
c19d1205 6745 break;
a737bd4d 6746
b6895b4f
PB
6747 /* Operand for MOVW or MOVT. */
6748 case OP_HALF:
6749 po_misc_or_fail (parse_half (&str));
6750 break;
6751
e07e6e58 6752 /* Register or expression. */
c19d1205
ZW
6753 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6754 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6755
e07e6e58 6756 /* Register or immediate. */
c19d1205
ZW
6757 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6758 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6759
c19d1205
ZW
6760 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6761 IF:
6762 if (!is_immediate_prefix (*str))
6763 goto bad_args;
6764 str++;
6765 val = parse_fpa_immediate (&str);
6766 if (val == FAIL)
6767 goto failure;
6768 /* FPA immediates are encoded as registers 8-15.
6769 parse_fpa_immediate has already applied the offset. */
6770 inst.operands[i].reg = val;
6771 inst.operands[i].isreg = 1;
6772 break;
09d92015 6773
2d447fca
JM
6774 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6775 I32z: po_imm_or_fail (0, 32, FALSE); break;
6776
e07e6e58 6777 /* Two kinds of register. */
c19d1205
ZW
6778 case OP_RIWR_RIWC:
6779 {
6780 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6781 if (!rege
6782 || (rege->type != REG_TYPE_MMXWR
6783 && rege->type != REG_TYPE_MMXWC
6784 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6785 {
6786 inst.error = _("iWMMXt data or control register expected");
6787 goto failure;
6788 }
6789 inst.operands[i].reg = rege->number;
6790 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6791 }
6792 break;
09d92015 6793
41adaa5c
JM
6794 case OP_RIWC_RIWG:
6795 {
6796 struct reg_entry *rege = arm_reg_parse_multi (&str);
6797 if (!rege
6798 || (rege->type != REG_TYPE_MMXWC
6799 && rege->type != REG_TYPE_MMXWCG))
6800 {
6801 inst.error = _("iWMMXt control register expected");
6802 goto failure;
6803 }
6804 inst.operands[i].reg = rege->number;
6805 inst.operands[i].isreg = 1;
6806 }
6807 break;
6808
c19d1205
ZW
6809 /* Misc */
6810 case OP_CPSF: val = parse_cps_flags (&str); break;
6811 case OP_ENDI: val = parse_endian_specifier (&str); break;
6812 case OP_oROR: val = parse_ror (&str); break;
c19d1205 6813 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6814 case OP_oBARRIER_I15:
6815 po_barrier_or_imm (str); break;
6816 immediate:
6817 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 6818 goto failure;
52e7f43d 6819 break;
c19d1205 6820
fa94de6b 6821 case OP_wPSR:
d2cd1205 6822 case OP_rPSR:
90ec0d68
MGD
6823 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6824 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6825 {
6826 inst.error = _("Banked registers are not available with this "
6827 "architecture.");
6828 goto failure;
6829 }
6830 break;
d2cd1205
JB
6831 try_psr:
6832 val = parse_psr (&str, op_parse_code == OP_wPSR);
6833 break;
037e8744 6834
477330fc
RM
6835 case OP_APSR_RR:
6836 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6837 break;
6838 try_apsr:
6839 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6840 instruction). */
6841 if (strncasecmp (str, "APSR_", 5) == 0)
6842 {
6843 unsigned found = 0;
6844 str += 5;
6845 while (found < 15)
6846 switch (*str++)
6847 {
6848 case 'c': found = (found & 1) ? 16 : found | 1; break;
6849 case 'n': found = (found & 2) ? 16 : found | 2; break;
6850 case 'z': found = (found & 4) ? 16 : found | 4; break;
6851 case 'v': found = (found & 8) ? 16 : found | 8; break;
6852 default: found = 16;
6853 }
6854 if (found != 15)
6855 goto failure;
6856 inst.operands[i].isvec = 1;
f7c21dc7
NC
6857 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6858 inst.operands[i].reg = REG_PC;
477330fc
RM
6859 }
6860 else
6861 goto failure;
6862 break;
037e8744 6863
92e90b6e
PB
6864 case OP_TB:
6865 po_misc_or_fail (parse_tb (&str));
6866 break;
6867
e07e6e58 6868 /* Register lists. */
c19d1205
ZW
6869 case OP_REGLST:
6870 val = parse_reg_list (&str);
6871 if (*str == '^')
6872 {
6873 inst.operands[1].writeback = 1;
6874 str++;
6875 }
6876 break;
09d92015 6877
c19d1205 6878 case OP_VRSLST:
5287ad62 6879 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6880 break;
09d92015 6881
c19d1205 6882 case OP_VRDLST:
5287ad62 6883 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6884 break;
a737bd4d 6885
477330fc
RM
6886 case OP_VRSDLST:
6887 /* Allow Q registers too. */
6888 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6889 REGLIST_NEON_D);
6890 if (val == FAIL)
6891 {
6892 inst.error = NULL;
6893 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6894 REGLIST_VFP_S);
6895 inst.operands[i].issingle = 1;
6896 }
6897 break;
6898
6899 case OP_NRDLST:
6900 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6901 REGLIST_NEON_D);
6902 break;
5287ad62
JB
6903
6904 case OP_NSTRLST:
477330fc
RM
6905 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6906 &inst.operands[i].vectype);
6907 break;
5287ad62 6908
c19d1205
ZW
6909 /* Addressing modes */
6910 case OP_ADDR:
6911 po_misc_or_fail (parse_address (&str, i));
6912 break;
09d92015 6913
4962c51a
MS
6914 case OP_ADDRGLDR:
6915 po_misc_or_fail_no_backtrack (
477330fc 6916 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
6917 break;
6918
6919 case OP_ADDRGLDRS:
6920 po_misc_or_fail_no_backtrack (
477330fc 6921 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
6922 break;
6923
6924 case OP_ADDRGLDC:
6925 po_misc_or_fail_no_backtrack (
477330fc 6926 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
6927 break;
6928
c19d1205
ZW
6929 case OP_SH:
6930 po_misc_or_fail (parse_shifter_operand (&str, i));
6931 break;
09d92015 6932
4962c51a
MS
6933 case OP_SHG:
6934 po_misc_or_fail_no_backtrack (
477330fc 6935 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
6936 break;
6937
c19d1205
ZW
6938 case OP_oSHll:
6939 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6940 break;
09d92015 6941
c19d1205
ZW
6942 case OP_oSHar:
6943 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6944 break;
09d92015 6945
c19d1205
ZW
6946 case OP_oSHllar:
6947 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6948 break;
09d92015 6949
c19d1205 6950 default:
5be8be5d 6951 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 6952 }
09d92015 6953
c19d1205
ZW
6954 /* Various value-based sanity checks and shared operations. We
6955 do not signal immediate failures for the register constraints;
6956 this allows a syntax error to take precedence. */
5be8be5d 6957 switch (op_parse_code)
c19d1205
ZW
6958 {
6959 case OP_oRRnpc:
6960 case OP_RRnpc:
6961 case OP_RRnpcb:
6962 case OP_RRw:
b6702015 6963 case OP_oRRw:
c19d1205
ZW
6964 case OP_RRnpc_I0:
6965 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6966 inst.error = BAD_PC;
6967 break;
09d92015 6968
5be8be5d
DG
6969 case OP_oRRnpcsp:
6970 case OP_RRnpcsp:
6971 if (inst.operands[i].isreg)
6972 {
6973 if (inst.operands[i].reg == REG_PC)
6974 inst.error = BAD_PC;
6975 else if (inst.operands[i].reg == REG_SP)
6976 inst.error = BAD_SP;
6977 }
6978 break;
6979
55881a11 6980 case OP_RRnpctw:
fa94de6b
RM
6981 if (inst.operands[i].isreg
6982 && inst.operands[i].reg == REG_PC
55881a11
MGD
6983 && (inst.operands[i].writeback || thumb))
6984 inst.error = BAD_PC;
6985 break;
6986
c19d1205
ZW
6987 case OP_CPSF:
6988 case OP_ENDI:
6989 case OP_oROR:
d2cd1205
JB
6990 case OP_wPSR:
6991 case OP_rPSR:
c19d1205 6992 case OP_COND:
52e7f43d 6993 case OP_oBARRIER_I15:
c19d1205
ZW
6994 case OP_REGLST:
6995 case OP_VRSLST:
6996 case OP_VRDLST:
477330fc
RM
6997 case OP_VRSDLST:
6998 case OP_NRDLST:
6999 case OP_NSTRLST:
c19d1205
ZW
7000 if (val == FAIL)
7001 goto failure;
7002 inst.operands[i].imm = val;
7003 break;
a737bd4d 7004
c19d1205
ZW
7005 default:
7006 break;
7007 }
09d92015 7008
c19d1205
ZW
7009 /* If we get here, this operand was successfully parsed. */
7010 inst.operands[i].present = 1;
7011 continue;
09d92015 7012
c19d1205 7013 bad_args:
09d92015 7014 inst.error = BAD_ARGS;
c19d1205
ZW
7015
7016 failure:
7017 if (!backtrack_pos)
d252fdde
PB
7018 {
7019 /* The parse routine should already have set inst.error, but set a
5f4273c7 7020 default here just in case. */
d252fdde
PB
7021 if (!inst.error)
7022 inst.error = _("syntax error");
7023 return FAIL;
7024 }
c19d1205
ZW
7025
7026 /* Do not backtrack over a trailing optional argument that
7027 absorbed some text. We will only fail again, with the
7028 'garbage following instruction' error message, which is
7029 probably less helpful than the current one. */
7030 if (backtrack_index == i && backtrack_pos != str
7031 && upat[i+1] == OP_stop)
d252fdde
PB
7032 {
7033 if (!inst.error)
7034 inst.error = _("syntax error");
7035 return FAIL;
7036 }
c19d1205
ZW
7037
7038 /* Try again, skipping the optional argument at backtrack_pos. */
7039 str = backtrack_pos;
7040 inst.error = backtrack_error;
7041 inst.operands[backtrack_index].present = 0;
7042 i = backtrack_index;
7043 backtrack_pos = 0;
09d92015 7044 }
09d92015 7045
c19d1205
ZW
7046 /* Check that we have parsed all the arguments. */
7047 if (*str != '\0' && !inst.error)
7048 inst.error = _("garbage following instruction");
09d92015 7049
c19d1205 7050 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7051}
7052
c19d1205
ZW
7053#undef po_char_or_fail
7054#undef po_reg_or_fail
7055#undef po_reg_or_goto
7056#undef po_imm_or_fail
5287ad62 7057#undef po_scalar_or_fail
52e7f43d 7058#undef po_barrier_or_imm
e07e6e58 7059
c19d1205 7060/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7061#define constraint(expr, err) \
7062 do \
c19d1205 7063 { \
e07e6e58
NC
7064 if (expr) \
7065 { \
7066 inst.error = err; \
7067 return; \
7068 } \
c19d1205 7069 } \
e07e6e58 7070 while (0)
c19d1205 7071
fdfde340
JM
7072/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7073 instructions are unpredictable if these registers are used. This
7074 is the BadReg predicate in ARM's Thumb-2 documentation. */
7075#define reject_bad_reg(reg) \
7076 do \
7077 if (reg == REG_SP || reg == REG_PC) \
7078 { \
7079 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
7080 return; \
7081 } \
7082 while (0)
7083
94206790
MM
7084/* If REG is R13 (the stack pointer), warn that its use is
7085 deprecated. */
7086#define warn_deprecated_sp(reg) \
7087 do \
7088 if (warn_on_deprecated && reg == REG_SP) \
7089 as_warn (_("use of r13 is deprecated")); \
7090 while (0)
7091
c19d1205
ZW
7092/* Functions for operand encoding. ARM, then Thumb. */
7093
7094#define rotate_left(v, n) (v << n | v >> (32 - n))
7095
7096/* If VAL can be encoded in the immediate field of an ARM instruction,
7097 return the encoded form. Otherwise, return FAIL. */
7098
7099static unsigned int
7100encode_arm_immediate (unsigned int val)
09d92015 7101{
c19d1205
ZW
7102 unsigned int a, i;
7103
7104 for (i = 0; i < 32; i += 2)
7105 if ((a = rotate_left (val, i)) <= 0xff)
7106 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7107
7108 return FAIL;
09d92015
MM
7109}
7110
c19d1205
ZW
7111/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7112 return the encoded form. Otherwise, return FAIL. */
7113static unsigned int
7114encode_thumb32_immediate (unsigned int val)
09d92015 7115{
c19d1205 7116 unsigned int a, i;
09d92015 7117
9c3c69f2 7118 if (val <= 0xff)
c19d1205 7119 return val;
a737bd4d 7120
9c3c69f2 7121 for (i = 1; i <= 24; i++)
09d92015 7122 {
9c3c69f2
PB
7123 a = val >> i;
7124 if ((val & ~(0xff << i)) == 0)
7125 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7126 }
a737bd4d 7127
c19d1205
ZW
7128 a = val & 0xff;
7129 if (val == ((a << 16) | a))
7130 return 0x100 | a;
7131 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7132 return 0x300 | a;
09d92015 7133
c19d1205
ZW
7134 a = val & 0xff00;
7135 if (val == ((a << 16) | a))
7136 return 0x200 | (a >> 8);
a737bd4d 7137
c19d1205 7138 return FAIL;
09d92015 7139}
5287ad62 7140/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7141
7142static void
5287ad62
JB
7143encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7144{
7145 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7146 && reg > 15)
7147 {
b1cc4aeb 7148 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7149 {
7150 if (thumb_mode)
7151 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7152 fpu_vfp_ext_d32);
7153 else
7154 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7155 fpu_vfp_ext_d32);
7156 }
5287ad62 7157 else
477330fc
RM
7158 {
7159 first_error (_("D register out of range for selected VFP version"));
7160 return;
7161 }
5287ad62
JB
7162 }
7163
c19d1205 7164 switch (pos)
09d92015 7165 {
c19d1205
ZW
7166 case VFP_REG_Sd:
7167 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7168 break;
7169
7170 case VFP_REG_Sn:
7171 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7172 break;
7173
7174 case VFP_REG_Sm:
7175 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7176 break;
7177
5287ad62
JB
7178 case VFP_REG_Dd:
7179 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7180 break;
5f4273c7 7181
5287ad62
JB
7182 case VFP_REG_Dn:
7183 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7184 break;
5f4273c7 7185
5287ad62
JB
7186 case VFP_REG_Dm:
7187 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7188 break;
7189
c19d1205
ZW
7190 default:
7191 abort ();
09d92015 7192 }
09d92015
MM
7193}
7194
c19d1205 7195/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7196 if any, is handled by md_apply_fix. */
09d92015 7197static void
c19d1205 7198encode_arm_shift (int i)
09d92015 7199{
c19d1205
ZW
7200 if (inst.operands[i].shift_kind == SHIFT_RRX)
7201 inst.instruction |= SHIFT_ROR << 5;
7202 else
09d92015 7203 {
c19d1205
ZW
7204 inst.instruction |= inst.operands[i].shift_kind << 5;
7205 if (inst.operands[i].immisreg)
7206 {
7207 inst.instruction |= SHIFT_BY_REG;
7208 inst.instruction |= inst.operands[i].imm << 8;
7209 }
7210 else
7211 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7212 }
c19d1205 7213}
09d92015 7214
c19d1205
ZW
7215static void
7216encode_arm_shifter_operand (int i)
7217{
7218 if (inst.operands[i].isreg)
09d92015 7219 {
c19d1205
ZW
7220 inst.instruction |= inst.operands[i].reg;
7221 encode_arm_shift (i);
09d92015 7222 }
c19d1205 7223 else
a415b1cd
JB
7224 {
7225 inst.instruction |= INST_IMMEDIATE;
7226 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7227 inst.instruction |= inst.operands[i].imm;
7228 }
09d92015
MM
7229}
7230
c19d1205 7231/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7232static void
c19d1205 7233encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7234{
2b2f5df9
NC
7235 /* PR 14260:
7236 Generate an error if the operand is not a register. */
7237 constraint (!inst.operands[i].isreg,
7238 _("Instruction does not support =N addresses"));
7239
c19d1205 7240 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7241
c19d1205 7242 if (inst.operands[i].preind)
09d92015 7243 {
c19d1205
ZW
7244 if (is_t)
7245 {
7246 inst.error = _("instruction does not accept preindexed addressing");
7247 return;
7248 }
7249 inst.instruction |= PRE_INDEX;
7250 if (inst.operands[i].writeback)
7251 inst.instruction |= WRITE_BACK;
09d92015 7252
c19d1205
ZW
7253 }
7254 else if (inst.operands[i].postind)
7255 {
9c2799c2 7256 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7257 if (is_t)
7258 inst.instruction |= WRITE_BACK;
7259 }
7260 else /* unindexed - only for coprocessor */
09d92015 7261 {
c19d1205 7262 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7263 return;
7264 }
7265
c19d1205
ZW
7266 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7267 && (((inst.instruction & 0x000f0000) >> 16)
7268 == ((inst.instruction & 0x0000f000) >> 12)))
7269 as_warn ((inst.instruction & LOAD_BIT)
7270 ? _("destination register same as write-back base")
7271 : _("source register same as write-back base"));
09d92015
MM
7272}
7273
c19d1205
ZW
7274/* inst.operands[i] was set up by parse_address. Encode it into an
7275 ARM-format mode 2 load or store instruction. If is_t is true,
7276 reject forms that cannot be used with a T instruction (i.e. not
7277 post-indexed). */
a737bd4d 7278static void
c19d1205 7279encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7280{
5be8be5d
DG
7281 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7282
c19d1205 7283 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7284
c19d1205 7285 if (inst.operands[i].immisreg)
09d92015 7286 {
5be8be5d
DG
7287 constraint ((inst.operands[i].imm == REG_PC
7288 || (is_pc && inst.operands[i].writeback)),
7289 BAD_PC_ADDRESSING);
c19d1205
ZW
7290 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7291 inst.instruction |= inst.operands[i].imm;
7292 if (!inst.operands[i].negative)
7293 inst.instruction |= INDEX_UP;
7294 if (inst.operands[i].shifted)
7295 {
7296 if (inst.operands[i].shift_kind == SHIFT_RRX)
7297 inst.instruction |= SHIFT_ROR << 5;
7298 else
7299 {
7300 inst.instruction |= inst.operands[i].shift_kind << 5;
7301 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7302 }
7303 }
09d92015 7304 }
c19d1205 7305 else /* immediate offset in inst.reloc */
09d92015 7306 {
5be8be5d
DG
7307 if (is_pc && !inst.reloc.pc_rel)
7308 {
7309 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7310
7311 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7312 cannot use PC in addressing.
7313 PC cannot be used in writeback addressing, either. */
7314 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7315 BAD_PC_ADDRESSING);
23a10334 7316
dc5ec521 7317 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7318 if (warn_on_deprecated
7319 && !is_load
7320 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7321 as_warn (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7322 }
7323
c19d1205 7324 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7325 {
7326 /* Prefer + for zero encoded value. */
7327 if (!inst.operands[i].negative)
7328 inst.instruction |= INDEX_UP;
7329 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7330 }
09d92015 7331 }
09d92015
MM
7332}
7333
c19d1205
ZW
7334/* inst.operands[i] was set up by parse_address. Encode it into an
7335 ARM-format mode 3 load or store instruction. Reject forms that
7336 cannot be used with such instructions. If is_t is true, reject
7337 forms that cannot be used with a T instruction (i.e. not
7338 post-indexed). */
7339static void
7340encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7341{
c19d1205 7342 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7343 {
c19d1205
ZW
7344 inst.error = _("instruction does not accept scaled register index");
7345 return;
09d92015 7346 }
a737bd4d 7347
c19d1205 7348 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7349
c19d1205
ZW
7350 if (inst.operands[i].immisreg)
7351 {
5be8be5d 7352 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7353 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7354 BAD_PC_ADDRESSING);
eb9f3f00
JB
7355 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7356 BAD_PC_WRITEBACK);
c19d1205
ZW
7357 inst.instruction |= inst.operands[i].imm;
7358 if (!inst.operands[i].negative)
7359 inst.instruction |= INDEX_UP;
7360 }
7361 else /* immediate offset in inst.reloc */
7362 {
5be8be5d
DG
7363 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7364 && inst.operands[i].writeback),
7365 BAD_PC_WRITEBACK);
c19d1205
ZW
7366 inst.instruction |= HWOFFSET_IMM;
7367 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7368 {
7369 /* Prefer + for zero encoded value. */
7370 if (!inst.operands[i].negative)
7371 inst.instruction |= INDEX_UP;
7372
7373 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7374 }
c19d1205 7375 }
a737bd4d
NC
7376}
7377
c19d1205
ZW
7378/* inst.operands[i] was set up by parse_address. Encode it into an
7379 ARM-format instruction. Reject all forms which cannot be encoded
7380 into a coprocessor load/store instruction. If wb_ok is false,
7381 reject use of writeback; if unind_ok is false, reject use of
7382 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
7383 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
7384 (in which case it is preserved). */
09d92015 7385
c19d1205
ZW
7386static int
7387encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 7388{
c19d1205 7389 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7390
9c2799c2 7391 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 7392
c19d1205 7393 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 7394 {
9c2799c2 7395 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
7396 if (!unind_ok)
7397 {
7398 inst.error = _("instruction does not support unindexed addressing");
7399 return FAIL;
7400 }
7401 inst.instruction |= inst.operands[i].imm;
7402 inst.instruction |= INDEX_UP;
7403 return SUCCESS;
09d92015 7404 }
a737bd4d 7405
c19d1205
ZW
7406 if (inst.operands[i].preind)
7407 inst.instruction |= PRE_INDEX;
a737bd4d 7408
c19d1205 7409 if (inst.operands[i].writeback)
09d92015 7410 {
c19d1205
ZW
7411 if (inst.operands[i].reg == REG_PC)
7412 {
7413 inst.error = _("pc may not be used with write-back");
7414 return FAIL;
7415 }
7416 if (!wb_ok)
7417 {
7418 inst.error = _("instruction does not support writeback");
7419 return FAIL;
7420 }
7421 inst.instruction |= WRITE_BACK;
09d92015 7422 }
a737bd4d 7423
c19d1205 7424 if (reloc_override)
21d799b5 7425 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a 7426 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
477330fc
RM
7427 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
7428 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
4962c51a
MS
7429 {
7430 if (thumb_mode)
477330fc 7431 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
4962c51a 7432 else
477330fc 7433 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
4962c51a
MS
7434 }
7435
26d97720
NS
7436 /* Prefer + for zero encoded value. */
7437 if (!inst.operands[i].negative)
7438 inst.instruction |= INDEX_UP;
7439
c19d1205
ZW
7440 return SUCCESS;
7441}
a737bd4d 7442
c19d1205
ZW
7443/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7444 Determine whether it can be performed with a move instruction; if
7445 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7446 return TRUE; if it can't, convert inst.instruction to a literal-pool
7447 load and return FALSE. If this is not a valid thing to do in the
7448 current context, set inst.error and return TRUE.
a737bd4d 7449
c19d1205
ZW
7450 inst.operands[i] describes the destination register. */
7451
c921be7d 7452static bfd_boolean
c19d1205
ZW
7453move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
7454{
53365c0d
PB
7455 unsigned long tbit;
7456
7457 if (thumb_p)
7458 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7459 else
7460 tbit = LOAD_BIT;
7461
7462 if ((inst.instruction & tbit) == 0)
09d92015 7463 {
c19d1205 7464 inst.error = _("invalid pseudo operation");
c921be7d 7465 return TRUE;
09d92015 7466 }
c19d1205 7467 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
7468 {
7469 inst.error = _("constant expression expected");
c921be7d 7470 return TRUE;
09d92015 7471 }
c19d1205 7472 if (inst.reloc.exp.X_op == O_constant)
09d92015 7473 {
c19d1205
ZW
7474 if (thumb_p)
7475 {
53365c0d 7476 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
7477 {
7478 /* This can be done with a mov(1) instruction. */
7479 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7480 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 7481 return TRUE;
c19d1205
ZW
7482 }
7483 }
7484 else
7485 {
7486 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7487 if (value != FAIL)
7488 {
7489 /* This can be done with a mov instruction. */
7490 inst.instruction &= LITERAL_MASK;
7491 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7492 inst.instruction |= value & 0xfff;
c921be7d 7493 return TRUE;
c19d1205 7494 }
09d92015 7495
c19d1205
ZW
7496 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7497 if (value != FAIL)
7498 {
7499 /* This can be done with a mvn instruction. */
7500 inst.instruction &= LITERAL_MASK;
7501 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7502 inst.instruction |= value & 0xfff;
c921be7d 7503 return TRUE;
c19d1205
ZW
7504 }
7505 }
09d92015
MM
7506 }
7507
c19d1205
ZW
7508 if (add_to_lit_pool () == FAIL)
7509 {
7510 inst.error = _("literal pool insertion failed");
c921be7d 7511 return TRUE;
c19d1205
ZW
7512 }
7513 inst.operands[1].reg = REG_PC;
7514 inst.operands[1].isreg = 1;
7515 inst.operands[1].preind = 1;
7516 inst.reloc.pc_rel = 1;
7517 inst.reloc.type = (thumb_p
7518 ? BFD_RELOC_ARM_THUMB_OFFSET
7519 : (mode_3
7520 ? BFD_RELOC_ARM_HWLITERAL
7521 : BFD_RELOC_ARM_LITERAL));
c921be7d 7522 return FALSE;
09d92015
MM
7523}
7524
5f4273c7 7525/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
7526 First some generics; their names are taken from the conventional
7527 bit positions for register arguments in ARM format instructions. */
09d92015 7528
a737bd4d 7529static void
c19d1205 7530do_noargs (void)
09d92015 7531{
c19d1205 7532}
a737bd4d 7533
c19d1205
ZW
7534static void
7535do_rd (void)
7536{
7537 inst.instruction |= inst.operands[0].reg << 12;
7538}
a737bd4d 7539
c19d1205
ZW
7540static void
7541do_rd_rm (void)
7542{
7543 inst.instruction |= inst.operands[0].reg << 12;
7544 inst.instruction |= inst.operands[1].reg;
7545}
09d92015 7546
9eb6c0f1
MGD
7547static void
7548do_rm_rn (void)
7549{
7550 inst.instruction |= inst.operands[0].reg;
7551 inst.instruction |= inst.operands[1].reg << 16;
7552}
7553
c19d1205
ZW
7554static void
7555do_rd_rn (void)
7556{
7557 inst.instruction |= inst.operands[0].reg << 12;
7558 inst.instruction |= inst.operands[1].reg << 16;
7559}
a737bd4d 7560
c19d1205
ZW
7561static void
7562do_rn_rd (void)
7563{
7564 inst.instruction |= inst.operands[0].reg << 16;
7565 inst.instruction |= inst.operands[1].reg << 12;
7566}
09d92015 7567
59d09be6
MGD
7568static bfd_boolean
7569check_obsolete (const arm_feature_set *feature, const char *msg)
7570{
7571 if (ARM_CPU_IS_ANY (cpu_variant))
7572 {
7573 as_warn ("%s", msg);
7574 return TRUE;
7575 }
7576 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
7577 {
7578 as_bad ("%s", msg);
7579 return TRUE;
7580 }
7581
7582 return FALSE;
7583}
7584
c19d1205
ZW
7585static void
7586do_rd_rm_rn (void)
7587{
9a64e435 7588 unsigned Rn = inst.operands[2].reg;
708587a4 7589 /* Enforce restrictions on SWP instruction. */
9a64e435 7590 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
7591 {
7592 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7593 _("Rn must not overlap other operands"));
7594
59d09be6
MGD
7595 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
7596 */
7597 if (!check_obsolete (&arm_ext_v8,
7598 _("swp{b} use is obsoleted for ARMv8 and later"))
7599 && warn_on_deprecated
7600 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
7601 as_warn (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 7602 }
59d09be6 7603
c19d1205
ZW
7604 inst.instruction |= inst.operands[0].reg << 12;
7605 inst.instruction |= inst.operands[1].reg;
9a64e435 7606 inst.instruction |= Rn << 16;
c19d1205 7607}
09d92015 7608
c19d1205
ZW
7609static void
7610do_rd_rn_rm (void)
7611{
7612 inst.instruction |= inst.operands[0].reg << 12;
7613 inst.instruction |= inst.operands[1].reg << 16;
7614 inst.instruction |= inst.operands[2].reg;
7615}
a737bd4d 7616
c19d1205
ZW
7617static void
7618do_rm_rd_rn (void)
7619{
5be8be5d
DG
7620 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7621 constraint (((inst.reloc.exp.X_op != O_constant
7622 && inst.reloc.exp.X_op != O_illegal)
7623 || inst.reloc.exp.X_add_number != 0),
7624 BAD_ADDR_MODE);
c19d1205
ZW
7625 inst.instruction |= inst.operands[0].reg;
7626 inst.instruction |= inst.operands[1].reg << 12;
7627 inst.instruction |= inst.operands[2].reg << 16;
7628}
09d92015 7629
c19d1205
ZW
7630static void
7631do_imm0 (void)
7632{
7633 inst.instruction |= inst.operands[0].imm;
7634}
09d92015 7635
c19d1205
ZW
7636static void
7637do_rd_cpaddr (void)
7638{
7639 inst.instruction |= inst.operands[0].reg << 12;
7640 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 7641}
a737bd4d 7642
c19d1205
ZW
7643/* ARM instructions, in alphabetical order by function name (except
7644 that wrapper functions appear immediately after the function they
7645 wrap). */
09d92015 7646
c19d1205
ZW
7647/* This is a pseudo-op of the form "adr rd, label" to be converted
7648 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
7649
7650static void
c19d1205 7651do_adr (void)
09d92015 7652{
c19d1205 7653 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7654
c19d1205
ZW
7655 /* Frag hacking will turn this into a sub instruction if the offset turns
7656 out to be negative. */
7657 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 7658 inst.reloc.pc_rel = 1;
2fc8bdac 7659 inst.reloc.exp.X_add_number -= 8;
c19d1205 7660}
b99bd4ef 7661
c19d1205
ZW
7662/* This is a pseudo-op of the form "adrl rd, label" to be converted
7663 into a relative address of the form:
7664 add rd, pc, #low(label-.-8)"
7665 add rd, rd, #high(label-.-8)" */
b99bd4ef 7666
c19d1205
ZW
7667static void
7668do_adrl (void)
7669{
7670 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7671
c19d1205
ZW
7672 /* Frag hacking will turn this into a sub instruction if the offset turns
7673 out to be negative. */
7674 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
7675 inst.reloc.pc_rel = 1;
7676 inst.size = INSN_SIZE * 2;
2fc8bdac 7677 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
7678}
7679
b99bd4ef 7680static void
c19d1205 7681do_arit (void)
b99bd4ef 7682{
c19d1205
ZW
7683 if (!inst.operands[1].present)
7684 inst.operands[1].reg = inst.operands[0].reg;
7685 inst.instruction |= inst.operands[0].reg << 12;
7686 inst.instruction |= inst.operands[1].reg << 16;
7687 encode_arm_shifter_operand (2);
7688}
b99bd4ef 7689
62b3e311
PB
7690static void
7691do_barrier (void)
7692{
7693 if (inst.operands[0].present)
ccb84d65 7694 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
7695 else
7696 inst.instruction |= 0xf;
7697}
7698
c19d1205
ZW
7699static void
7700do_bfc (void)
7701{
7702 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7703 constraint (msb > 32, _("bit-field extends past end of register"));
7704 /* The instruction encoding stores the LSB and MSB,
7705 not the LSB and width. */
7706 inst.instruction |= inst.operands[0].reg << 12;
7707 inst.instruction |= inst.operands[1].imm << 7;
7708 inst.instruction |= (msb - 1) << 16;
7709}
b99bd4ef 7710
c19d1205
ZW
7711static void
7712do_bfi (void)
7713{
7714 unsigned int msb;
b99bd4ef 7715
c19d1205
ZW
7716 /* #0 in second position is alternative syntax for bfc, which is
7717 the same instruction but with REG_PC in the Rm field. */
7718 if (!inst.operands[1].isreg)
7719 inst.operands[1].reg = REG_PC;
b99bd4ef 7720
c19d1205
ZW
7721 msb = inst.operands[2].imm + inst.operands[3].imm;
7722 constraint (msb > 32, _("bit-field extends past end of register"));
7723 /* The instruction encoding stores the LSB and MSB,
7724 not the LSB and width. */
7725 inst.instruction |= inst.operands[0].reg << 12;
7726 inst.instruction |= inst.operands[1].reg;
7727 inst.instruction |= inst.operands[2].imm << 7;
7728 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7729}
7730
b99bd4ef 7731static void
c19d1205 7732do_bfx (void)
b99bd4ef 7733{
c19d1205
ZW
7734 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7735 _("bit-field extends past end of register"));
7736 inst.instruction |= inst.operands[0].reg << 12;
7737 inst.instruction |= inst.operands[1].reg;
7738 inst.instruction |= inst.operands[2].imm << 7;
7739 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7740}
09d92015 7741
c19d1205
ZW
7742/* ARM V5 breakpoint instruction (argument parse)
7743 BKPT <16 bit unsigned immediate>
7744 Instruction is not conditional.
7745 The bit pattern given in insns[] has the COND_ALWAYS condition,
7746 and it is an error if the caller tried to override that. */
b99bd4ef 7747
c19d1205
ZW
7748static void
7749do_bkpt (void)
7750{
7751 /* Top 12 of 16 bits to bits 19:8. */
7752 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7753
c19d1205
ZW
7754 /* Bottom 4 of 16 bits to bits 3:0. */
7755 inst.instruction |= inst.operands[0].imm & 0xf;
7756}
09d92015 7757
c19d1205
ZW
7758static void
7759encode_branch (int default_reloc)
7760{
7761 if (inst.operands[0].hasreloc)
7762 {
0855e32b
NS
7763 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
7764 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
7765 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
7766 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
7767 ? BFD_RELOC_ARM_PLT32
7768 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 7769 }
b99bd4ef 7770 else
9ae92b05 7771 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 7772 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7773}
7774
b99bd4ef 7775static void
c19d1205 7776do_branch (void)
b99bd4ef 7777{
39b41c9c
PB
7778#ifdef OBJ_ELF
7779 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7780 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7781 else
7782#endif
7783 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7784}
7785
7786static void
7787do_bl (void)
7788{
7789#ifdef OBJ_ELF
7790 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7791 {
7792 if (inst.cond == COND_ALWAYS)
7793 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7794 else
7795 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7796 }
7797 else
7798#endif
7799 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7800}
b99bd4ef 7801
c19d1205
ZW
7802/* ARM V5 branch-link-exchange instruction (argument parse)
7803 BLX <target_addr> ie BLX(1)
7804 BLX{<condition>} <Rm> ie BLX(2)
7805 Unfortunately, there are two different opcodes for this mnemonic.
7806 So, the insns[].value is not used, and the code here zaps values
7807 into inst.instruction.
7808 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7809
c19d1205
ZW
7810static void
7811do_blx (void)
7812{
7813 if (inst.operands[0].isreg)
b99bd4ef 7814 {
c19d1205
ZW
7815 /* Arg is a register; the opcode provided by insns[] is correct.
7816 It is not illegal to do "blx pc", just useless. */
7817 if (inst.operands[0].reg == REG_PC)
7818 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7819
c19d1205
ZW
7820 inst.instruction |= inst.operands[0].reg;
7821 }
7822 else
b99bd4ef 7823 {
c19d1205 7824 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7825 conditionally, and the opcode must be adjusted.
7826 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7827 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7828 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7829 inst.instruction = 0xfa000000;
267bf995 7830 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7831 }
c19d1205
ZW
7832}
7833
7834static void
7835do_bx (void)
7836{
845b51d6
PB
7837 bfd_boolean want_reloc;
7838
c19d1205
ZW
7839 if (inst.operands[0].reg == REG_PC)
7840 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7841
c19d1205 7842 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7843 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7844 it is for ARMv4t or earlier. */
7845 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7846 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7847 want_reloc = TRUE;
7848
5ad34203 7849#ifdef OBJ_ELF
845b51d6 7850 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7851#endif
584206db 7852 want_reloc = FALSE;
845b51d6
PB
7853
7854 if (want_reloc)
7855 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7856}
7857
c19d1205
ZW
7858
7859/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7860
7861static void
c19d1205 7862do_bxj (void)
a737bd4d 7863{
c19d1205
ZW
7864 if (inst.operands[0].reg == REG_PC)
7865 as_tsktsk (_("use of r15 in bxj is not really useful"));
7866
7867 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7868}
7869
c19d1205
ZW
7870/* Co-processor data operation:
7871 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7872 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7873static void
7874do_cdp (void)
7875{
7876 inst.instruction |= inst.operands[0].reg << 8;
7877 inst.instruction |= inst.operands[1].imm << 20;
7878 inst.instruction |= inst.operands[2].reg << 12;
7879 inst.instruction |= inst.operands[3].reg << 16;
7880 inst.instruction |= inst.operands[4].reg;
7881 inst.instruction |= inst.operands[5].imm << 5;
7882}
a737bd4d
NC
7883
7884static void
c19d1205 7885do_cmp (void)
a737bd4d 7886{
c19d1205
ZW
7887 inst.instruction |= inst.operands[0].reg << 16;
7888 encode_arm_shifter_operand (1);
a737bd4d
NC
7889}
7890
c19d1205
ZW
7891/* Transfer between coprocessor and ARM registers.
7892 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7893 MRC2
7894 MCR{cond}
7895 MCR2
7896
7897 No special properties. */
09d92015 7898
dcbd0d71
MGD
7899struct deprecated_coproc_regs_s
7900{
7901 unsigned cp;
7902 int opc1;
7903 unsigned crn;
7904 unsigned crm;
7905 int opc2;
7906 arm_feature_set deprecated;
7907 arm_feature_set obsoleted;
7908 const char *dep_msg;
7909 const char *obs_msg;
7910};
7911
7912#define DEPR_ACCESS_V8 \
7913 N_("This coprocessor register access is deprecated in ARMv8")
7914
7915/* Table of all deprecated coprocessor registers. */
7916static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
7917{
7918 {15, 0, 7, 10, 5, /* CP15DMB. */
7919 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7920 DEPR_ACCESS_V8, NULL},
7921 {15, 0, 7, 10, 4, /* CP15DSB. */
7922 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7923 DEPR_ACCESS_V8, NULL},
7924 {15, 0, 7, 5, 4, /* CP15ISB. */
7925 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7926 DEPR_ACCESS_V8, NULL},
7927 {14, 6, 1, 0, 0, /* TEEHBR. */
7928 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7929 DEPR_ACCESS_V8, NULL},
7930 {14, 6, 0, 0, 0, /* TEECR. */
7931 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7932 DEPR_ACCESS_V8, NULL},
7933};
7934
7935#undef DEPR_ACCESS_V8
7936
7937static const size_t deprecated_coproc_reg_count =
7938 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
7939
09d92015 7940static void
c19d1205 7941do_co_reg (void)
09d92015 7942{
fdfde340 7943 unsigned Rd;
dcbd0d71 7944 size_t i;
fdfde340
JM
7945
7946 Rd = inst.operands[2].reg;
7947 if (thumb_mode)
7948 {
7949 if (inst.instruction == 0xee000010
7950 || inst.instruction == 0xfe000010)
7951 /* MCR, MCR2 */
7952 reject_bad_reg (Rd);
7953 else
7954 /* MRC, MRC2 */
7955 constraint (Rd == REG_SP, BAD_SP);
7956 }
7957 else
7958 {
7959 /* MCR */
7960 if (inst.instruction == 0xe000010)
7961 constraint (Rd == REG_PC, BAD_PC);
7962 }
7963
dcbd0d71
MGD
7964 for (i = 0; i < deprecated_coproc_reg_count; ++i)
7965 {
7966 const struct deprecated_coproc_regs_s *r =
7967 deprecated_coproc_regs + i;
7968
7969 if (inst.operands[0].reg == r->cp
7970 && inst.operands[1].imm == r->opc1
7971 && inst.operands[3].reg == r->crn
7972 && inst.operands[4].reg == r->crm
7973 && inst.operands[5].imm == r->opc2)
7974 {
b10bf8c5 7975 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 7976 && warn_on_deprecated
dcbd0d71
MGD
7977 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
7978 as_warn ("%s", r->dep_msg);
7979 }
7980 }
fdfde340 7981
c19d1205
ZW
7982 inst.instruction |= inst.operands[0].reg << 8;
7983 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7984 inst.instruction |= Rd << 12;
c19d1205
ZW
7985 inst.instruction |= inst.operands[3].reg << 16;
7986 inst.instruction |= inst.operands[4].reg;
7987 inst.instruction |= inst.operands[5].imm << 5;
7988}
09d92015 7989
c19d1205
ZW
7990/* Transfer between coprocessor register and pair of ARM registers.
7991 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7992 MCRR2
7993 MRRC{cond}
7994 MRRC2
b99bd4ef 7995
c19d1205 7996 Two XScale instructions are special cases of these:
09d92015 7997
c19d1205
ZW
7998 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7999 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8000
5f4273c7 8001 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8002
c19d1205
ZW
8003static void
8004do_co_reg2c (void)
8005{
fdfde340
JM
8006 unsigned Rd, Rn;
8007
8008 Rd = inst.operands[2].reg;
8009 Rn = inst.operands[3].reg;
8010
8011 if (thumb_mode)
8012 {
8013 reject_bad_reg (Rd);
8014 reject_bad_reg (Rn);
8015 }
8016 else
8017 {
8018 constraint (Rd == REG_PC, BAD_PC);
8019 constraint (Rn == REG_PC, BAD_PC);
8020 }
8021
c19d1205
ZW
8022 inst.instruction |= inst.operands[0].reg << 8;
8023 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8024 inst.instruction |= Rd << 12;
8025 inst.instruction |= Rn << 16;
c19d1205 8026 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8027}
8028
c19d1205
ZW
8029static void
8030do_cpsi (void)
8031{
8032 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8033 if (inst.operands[1].present)
8034 {
8035 inst.instruction |= CPSI_MMOD;
8036 inst.instruction |= inst.operands[1].imm;
8037 }
c19d1205 8038}
b99bd4ef 8039
62b3e311
PB
8040static void
8041do_dbg (void)
8042{
8043 inst.instruction |= inst.operands[0].imm;
8044}
8045
eea54501
MGD
8046static void
8047do_div (void)
8048{
8049 unsigned Rd, Rn, Rm;
8050
8051 Rd = inst.operands[0].reg;
8052 Rn = (inst.operands[1].present
8053 ? inst.operands[1].reg : Rd);
8054 Rm = inst.operands[2].reg;
8055
8056 constraint ((Rd == REG_PC), BAD_PC);
8057 constraint ((Rn == REG_PC), BAD_PC);
8058 constraint ((Rm == REG_PC), BAD_PC);
8059
8060 inst.instruction |= Rd << 16;
8061 inst.instruction |= Rn << 0;
8062 inst.instruction |= Rm << 8;
8063}
8064
b99bd4ef 8065static void
c19d1205 8066do_it (void)
b99bd4ef 8067{
c19d1205 8068 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8069 process it to do the validation as if in
8070 thumb mode, just in case the code gets
8071 assembled for thumb using the unified syntax. */
8072
c19d1205 8073 inst.size = 0;
e07e6e58
NC
8074 if (unified_syntax)
8075 {
8076 set_it_insn_type (IT_INSN);
8077 now_it.mask = (inst.instruction & 0xf) | 0x10;
8078 now_it.cc = inst.operands[0].imm;
8079 }
09d92015 8080}
b99bd4ef 8081
6530b175
NC
8082/* If there is only one register in the register list,
8083 then return its register number. Otherwise return -1. */
8084static int
8085only_one_reg_in_list (int range)
8086{
8087 int i = ffs (range) - 1;
8088 return (i > 15 || range != (1 << i)) ? -1 : i;
8089}
8090
09d92015 8091static void
6530b175 8092encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8093{
c19d1205
ZW
8094 int base_reg = inst.operands[0].reg;
8095 int range = inst.operands[1].imm;
6530b175 8096 int one_reg;
ea6ef066 8097
c19d1205
ZW
8098 inst.instruction |= base_reg << 16;
8099 inst.instruction |= range;
ea6ef066 8100
c19d1205
ZW
8101 if (inst.operands[1].writeback)
8102 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8103
c19d1205 8104 if (inst.operands[0].writeback)
ea6ef066 8105 {
c19d1205
ZW
8106 inst.instruction |= WRITE_BACK;
8107 /* Check for unpredictable uses of writeback. */
8108 if (inst.instruction & LOAD_BIT)
09d92015 8109 {
c19d1205
ZW
8110 /* Not allowed in LDM type 2. */
8111 if ((inst.instruction & LDM_TYPE_2_OR_3)
8112 && ((range & (1 << REG_PC)) == 0))
8113 as_warn (_("writeback of base register is UNPREDICTABLE"));
8114 /* Only allowed if base reg not in list for other types. */
8115 else if (range & (1 << base_reg))
8116 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8117 }
8118 else /* STM. */
8119 {
8120 /* Not allowed for type 2. */
8121 if (inst.instruction & LDM_TYPE_2_OR_3)
8122 as_warn (_("writeback of base register is UNPREDICTABLE"));
8123 /* Only allowed if base reg not in list, or first in list. */
8124 else if ((range & (1 << base_reg))
8125 && (range & ((1 << base_reg) - 1)))
8126 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8127 }
ea6ef066 8128 }
6530b175
NC
8129
8130 /* If PUSH/POP has only one register, then use the A2 encoding. */
8131 one_reg = only_one_reg_in_list (range);
8132 if (from_push_pop_mnem && one_reg >= 0)
8133 {
8134 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8135
8136 inst.instruction &= A_COND_MASK;
8137 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8138 inst.instruction |= one_reg << 12;
8139 }
8140}
8141
8142static void
8143do_ldmstm (void)
8144{
8145 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8146}
8147
c19d1205
ZW
8148/* ARMv5TE load-consecutive (argument parse)
8149 Mode is like LDRH.
8150
8151 LDRccD R, mode
8152 STRccD R, mode. */
8153
a737bd4d 8154static void
c19d1205 8155do_ldrd (void)
a737bd4d 8156{
c19d1205 8157 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8158 _("first transfer register must be even"));
c19d1205
ZW
8159 constraint (inst.operands[1].present
8160 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8161 _("can only transfer two consecutive registers"));
c19d1205
ZW
8162 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8163 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8164
c19d1205
ZW
8165 if (!inst.operands[1].present)
8166 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8167
c56791bb
RE
8168 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8169 register and the first register written; we have to diagnose
8170 overlap between the base and the second register written here. */
ea6ef066 8171
c56791bb
RE
8172 if (inst.operands[2].reg == inst.operands[1].reg
8173 && (inst.operands[2].writeback || inst.operands[2].postind))
8174 as_warn (_("base register written back, and overlaps "
8175 "second transfer register"));
b05fe5cf 8176
c56791bb
RE
8177 if (!(inst.instruction & V4_STR_BIT))
8178 {
c19d1205 8179 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8180 destination (even if not write-back). */
8181 if (inst.operands[2].immisreg
8182 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8183 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8184 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8185 }
c19d1205
ZW
8186 inst.instruction |= inst.operands[0].reg << 12;
8187 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8188}
8189
8190static void
c19d1205 8191do_ldrex (void)
b05fe5cf 8192{
c19d1205
ZW
8193 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8194 || inst.operands[1].postind || inst.operands[1].writeback
8195 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8196 || inst.operands[1].negative
8197 /* This can arise if the programmer has written
8198 strex rN, rM, foo
8199 or if they have mistakenly used a register name as the last
8200 operand, eg:
8201 strex rN, rM, rX
8202 It is very difficult to distinguish between these two cases
8203 because "rX" might actually be a label. ie the register
8204 name has been occluded by a symbol of the same name. So we
8205 just generate a general 'bad addressing mode' type error
8206 message and leave it up to the programmer to discover the
8207 true cause and fix their mistake. */
8208 || (inst.operands[1].reg == REG_PC),
8209 BAD_ADDR_MODE);
b05fe5cf 8210
c19d1205
ZW
8211 constraint (inst.reloc.exp.X_op != O_constant
8212 || inst.reloc.exp.X_add_number != 0,
8213 _("offset must be zero in ARM encoding"));
b05fe5cf 8214
5be8be5d
DG
8215 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8216
c19d1205
ZW
8217 inst.instruction |= inst.operands[0].reg << 12;
8218 inst.instruction |= inst.operands[1].reg << 16;
8219 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8220}
8221
8222static void
c19d1205 8223do_ldrexd (void)
b05fe5cf 8224{
c19d1205
ZW
8225 constraint (inst.operands[0].reg % 2 != 0,
8226 _("even register required"));
8227 constraint (inst.operands[1].present
8228 && inst.operands[1].reg != inst.operands[0].reg + 1,
8229 _("can only load two consecutive registers"));
8230 /* If op 1 were present and equal to PC, this function wouldn't
8231 have been called in the first place. */
8232 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8233
c19d1205
ZW
8234 inst.instruction |= inst.operands[0].reg << 12;
8235 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8236}
8237
1be5fd2e
NC
8238/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8239 which is not a multiple of four is UNPREDICTABLE. */
8240static void
8241check_ldr_r15_aligned (void)
8242{
8243 constraint (!(inst.operands[1].immisreg)
8244 && (inst.operands[0].reg == REG_PC
8245 && inst.operands[1].reg == REG_PC
8246 && (inst.reloc.exp.X_add_number & 0x3)),
8247 _("ldr to register 15 must be 4-byte alligned"));
8248}
8249
b05fe5cf 8250static void
c19d1205 8251do_ldst (void)
b05fe5cf 8252{
c19d1205
ZW
8253 inst.instruction |= inst.operands[0].reg << 12;
8254 if (!inst.operands[1].isreg)
8255 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 8256 return;
c19d1205 8257 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8258 check_ldr_r15_aligned ();
b05fe5cf
ZW
8259}
8260
8261static void
c19d1205 8262do_ldstt (void)
b05fe5cf 8263{
c19d1205
ZW
8264 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8265 reject [Rn,...]. */
8266 if (inst.operands[1].preind)
b05fe5cf 8267 {
bd3ba5d1
NC
8268 constraint (inst.reloc.exp.X_op != O_constant
8269 || inst.reloc.exp.X_add_number != 0,
c19d1205 8270 _("this instruction requires a post-indexed address"));
b05fe5cf 8271
c19d1205
ZW
8272 inst.operands[1].preind = 0;
8273 inst.operands[1].postind = 1;
8274 inst.operands[1].writeback = 1;
b05fe5cf 8275 }
c19d1205
ZW
8276 inst.instruction |= inst.operands[0].reg << 12;
8277 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8278}
b05fe5cf 8279
c19d1205 8280/* Halfword and signed-byte load/store operations. */
b05fe5cf 8281
c19d1205
ZW
8282static void
8283do_ldstv4 (void)
8284{
ff4a8d2b 8285 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8286 inst.instruction |= inst.operands[0].reg << 12;
8287 if (!inst.operands[1].isreg)
8288 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 8289 return;
c19d1205 8290 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
8291}
8292
8293static void
c19d1205 8294do_ldsttv4 (void)
b05fe5cf 8295{
c19d1205
ZW
8296 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8297 reject [Rn,...]. */
8298 if (inst.operands[1].preind)
b05fe5cf 8299 {
bd3ba5d1
NC
8300 constraint (inst.reloc.exp.X_op != O_constant
8301 || inst.reloc.exp.X_add_number != 0,
c19d1205 8302 _("this instruction requires a post-indexed address"));
b05fe5cf 8303
c19d1205
ZW
8304 inst.operands[1].preind = 0;
8305 inst.operands[1].postind = 1;
8306 inst.operands[1].writeback = 1;
b05fe5cf 8307 }
c19d1205
ZW
8308 inst.instruction |= inst.operands[0].reg << 12;
8309 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8310}
b05fe5cf 8311
c19d1205
ZW
8312/* Co-processor register load/store.
8313 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8314static void
8315do_lstc (void)
8316{
8317 inst.instruction |= inst.operands[0].reg << 8;
8318 inst.instruction |= inst.operands[1].reg << 12;
8319 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
8320}
8321
b05fe5cf 8322static void
c19d1205 8323do_mlas (void)
b05fe5cf 8324{
8fb9d7b9 8325 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 8326 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 8327 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 8328 && !(inst.instruction & 0x00400000))
8fb9d7b9 8329 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 8330
c19d1205
ZW
8331 inst.instruction |= inst.operands[0].reg << 16;
8332 inst.instruction |= inst.operands[1].reg;
8333 inst.instruction |= inst.operands[2].reg << 8;
8334 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 8335}
b05fe5cf 8336
c19d1205
ZW
8337static void
8338do_mov (void)
8339{
8340 inst.instruction |= inst.operands[0].reg << 12;
8341 encode_arm_shifter_operand (1);
8342}
b05fe5cf 8343
c19d1205
ZW
8344/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8345static void
8346do_mov16 (void)
8347{
b6895b4f
PB
8348 bfd_vma imm;
8349 bfd_boolean top;
8350
8351 top = (inst.instruction & 0x00400000) != 0;
8352 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8353 _(":lower16: not allowed this instruction"));
8354 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8355 _(":upper16: not allowed instruction"));
c19d1205 8356 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
8357 if (inst.reloc.type == BFD_RELOC_UNUSED)
8358 {
8359 imm = inst.reloc.exp.X_add_number;
8360 /* The value is in two pieces: 0:11, 16:19. */
8361 inst.instruction |= (imm & 0x00000fff);
8362 inst.instruction |= (imm & 0x0000f000) << 4;
8363 }
b05fe5cf 8364}
b99bd4ef 8365
037e8744
JB
8366static void do_vfp_nsyn_opcode (const char *);
8367
8368static int
8369do_vfp_nsyn_mrs (void)
8370{
8371 if (inst.operands[0].isvec)
8372 {
8373 if (inst.operands[1].reg != 1)
477330fc 8374 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
8375 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8376 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8377 do_vfp_nsyn_opcode ("fmstat");
8378 }
8379 else if (inst.operands[1].isvec)
8380 do_vfp_nsyn_opcode ("fmrx");
8381 else
8382 return FAIL;
5f4273c7 8383
037e8744
JB
8384 return SUCCESS;
8385}
8386
8387static int
8388do_vfp_nsyn_msr (void)
8389{
8390 if (inst.operands[0].isvec)
8391 do_vfp_nsyn_opcode ("fmxr");
8392 else
8393 return FAIL;
8394
8395 return SUCCESS;
8396}
8397
f7c21dc7
NC
8398static void
8399do_vmrs (void)
8400{
8401 unsigned Rt = inst.operands[0].reg;
fa94de6b 8402
16d02dc9 8403 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
8404 {
8405 inst.error = BAD_SP;
8406 return;
8407 }
8408
8409 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 8410 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
8411 {
8412 inst.error = BAD_PC;
8413 return;
8414 }
8415
16d02dc9
JB
8416 /* If we get through parsing the register name, we just insert the number
8417 generated into the instruction without further validation. */
8418 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
8419 inst.instruction |= (Rt << 12);
8420}
8421
8422static void
8423do_vmsr (void)
8424{
8425 unsigned Rt = inst.operands[1].reg;
fa94de6b 8426
f7c21dc7
NC
8427 if (thumb_mode)
8428 reject_bad_reg (Rt);
8429 else if (Rt == REG_PC)
8430 {
8431 inst.error = BAD_PC;
8432 return;
8433 }
8434
16d02dc9
JB
8435 /* If we get through parsing the register name, we just insert the number
8436 generated into the instruction without further validation. */
8437 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
8438 inst.instruction |= (Rt << 12);
8439}
8440
b99bd4ef 8441static void
c19d1205 8442do_mrs (void)
b99bd4ef 8443{
90ec0d68
MGD
8444 unsigned br;
8445
037e8744
JB
8446 if (do_vfp_nsyn_mrs () == SUCCESS)
8447 return;
8448
ff4a8d2b 8449 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 8450 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
8451
8452 if (inst.operands[1].isreg)
8453 {
8454 br = inst.operands[1].reg;
8455 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
8456 as_bad (_("bad register for mrs"));
8457 }
8458 else
8459 {
8460 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
8461 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
8462 != (PSR_c|PSR_f),
d2cd1205 8463 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
8464 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
8465 }
8466
8467 inst.instruction |= br;
c19d1205 8468}
b99bd4ef 8469
c19d1205
ZW
8470/* Two possible forms:
8471 "{C|S}PSR_<field>, Rm",
8472 "{C|S}PSR_f, #expression". */
b99bd4ef 8473
c19d1205
ZW
8474static void
8475do_msr (void)
8476{
037e8744
JB
8477 if (do_vfp_nsyn_msr () == SUCCESS)
8478 return;
8479
c19d1205
ZW
8480 inst.instruction |= inst.operands[0].imm;
8481 if (inst.operands[1].isreg)
8482 inst.instruction |= inst.operands[1].reg;
8483 else
b99bd4ef 8484 {
c19d1205
ZW
8485 inst.instruction |= INST_IMMEDIATE;
8486 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8487 inst.reloc.pc_rel = 0;
b99bd4ef 8488 }
b99bd4ef
NC
8489}
8490
c19d1205
ZW
8491static void
8492do_mul (void)
a737bd4d 8493{
ff4a8d2b
NC
8494 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
8495
c19d1205
ZW
8496 if (!inst.operands[2].present)
8497 inst.operands[2].reg = inst.operands[0].reg;
8498 inst.instruction |= inst.operands[0].reg << 16;
8499 inst.instruction |= inst.operands[1].reg;
8500 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 8501
8fb9d7b9
MS
8502 if (inst.operands[0].reg == inst.operands[1].reg
8503 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8504 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
8505}
8506
c19d1205
ZW
8507/* Long Multiply Parser
8508 UMULL RdLo, RdHi, Rm, Rs
8509 SMULL RdLo, RdHi, Rm, Rs
8510 UMLAL RdLo, RdHi, Rm, Rs
8511 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
8512
8513static void
c19d1205 8514do_mull (void)
b99bd4ef 8515{
c19d1205
ZW
8516 inst.instruction |= inst.operands[0].reg << 12;
8517 inst.instruction |= inst.operands[1].reg << 16;
8518 inst.instruction |= inst.operands[2].reg;
8519 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 8520
682b27ad
PB
8521 /* rdhi and rdlo must be different. */
8522 if (inst.operands[0].reg == inst.operands[1].reg)
8523 as_tsktsk (_("rdhi and rdlo must be different"));
8524
8525 /* rdhi, rdlo and rm must all be different before armv6. */
8526 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 8527 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 8528 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
8529 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
8530}
b99bd4ef 8531
c19d1205
ZW
8532static void
8533do_nop (void)
8534{
e7495e45
NS
8535 if (inst.operands[0].present
8536 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
8537 {
8538 /* Architectural NOP hints are CPSR sets with no bits selected. */
8539 inst.instruction &= 0xf0000000;
e7495e45
NS
8540 inst.instruction |= 0x0320f000;
8541 if (inst.operands[0].present)
8542 inst.instruction |= inst.operands[0].imm;
c19d1205 8543 }
b99bd4ef
NC
8544}
8545
c19d1205
ZW
8546/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
8547 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
8548 Condition defaults to COND_ALWAYS.
8549 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
8550
8551static void
c19d1205 8552do_pkhbt (void)
b99bd4ef 8553{
c19d1205
ZW
8554 inst.instruction |= inst.operands[0].reg << 12;
8555 inst.instruction |= inst.operands[1].reg << 16;
8556 inst.instruction |= inst.operands[2].reg;
8557 if (inst.operands[3].present)
8558 encode_arm_shift (3);
8559}
b99bd4ef 8560
c19d1205 8561/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 8562
c19d1205
ZW
8563static void
8564do_pkhtb (void)
8565{
8566 if (!inst.operands[3].present)
b99bd4ef 8567 {
c19d1205
ZW
8568 /* If the shift specifier is omitted, turn the instruction
8569 into pkhbt rd, rm, rn. */
8570 inst.instruction &= 0xfff00010;
8571 inst.instruction |= inst.operands[0].reg << 12;
8572 inst.instruction |= inst.operands[1].reg;
8573 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8574 }
8575 else
8576 {
c19d1205
ZW
8577 inst.instruction |= inst.operands[0].reg << 12;
8578 inst.instruction |= inst.operands[1].reg << 16;
8579 inst.instruction |= inst.operands[2].reg;
8580 encode_arm_shift (3);
b99bd4ef
NC
8581 }
8582}
8583
c19d1205 8584/* ARMv5TE: Preload-Cache
60e5ef9f 8585 MP Extensions: Preload for write
c19d1205 8586
60e5ef9f 8587 PLD(W) <addr_mode>
c19d1205
ZW
8588
8589 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
8590
8591static void
c19d1205 8592do_pld (void)
b99bd4ef 8593{
c19d1205
ZW
8594 constraint (!inst.operands[0].isreg,
8595 _("'[' expected after PLD mnemonic"));
8596 constraint (inst.operands[0].postind,
8597 _("post-indexed expression used in preload instruction"));
8598 constraint (inst.operands[0].writeback,
8599 _("writeback used in preload instruction"));
8600 constraint (!inst.operands[0].preind,
8601 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
8602 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8603}
b99bd4ef 8604
62b3e311
PB
8605/* ARMv7: PLI <addr_mode> */
8606static void
8607do_pli (void)
8608{
8609 constraint (!inst.operands[0].isreg,
8610 _("'[' expected after PLI mnemonic"));
8611 constraint (inst.operands[0].postind,
8612 _("post-indexed expression used in preload instruction"));
8613 constraint (inst.operands[0].writeback,
8614 _("writeback used in preload instruction"));
8615 constraint (!inst.operands[0].preind,
8616 _("unindexed addressing used in preload instruction"));
8617 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8618 inst.instruction &= ~PRE_INDEX;
8619}
8620
c19d1205
ZW
8621static void
8622do_push_pop (void)
8623{
8624 inst.operands[1] = inst.operands[0];
8625 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8626 inst.operands[0].isreg = 1;
8627 inst.operands[0].writeback = 1;
8628 inst.operands[0].reg = REG_SP;
6530b175 8629 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 8630}
b99bd4ef 8631
c19d1205
ZW
8632/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8633 word at the specified address and the following word
8634 respectively.
8635 Unconditionally executed.
8636 Error if Rn is R15. */
b99bd4ef 8637
c19d1205
ZW
8638static void
8639do_rfe (void)
8640{
8641 inst.instruction |= inst.operands[0].reg << 16;
8642 if (inst.operands[0].writeback)
8643 inst.instruction |= WRITE_BACK;
8644}
b99bd4ef 8645
c19d1205 8646/* ARM V6 ssat (argument parse). */
b99bd4ef 8647
c19d1205
ZW
8648static void
8649do_ssat (void)
8650{
8651 inst.instruction |= inst.operands[0].reg << 12;
8652 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8653 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8654
c19d1205
ZW
8655 if (inst.operands[3].present)
8656 encode_arm_shift (3);
b99bd4ef
NC
8657}
8658
c19d1205 8659/* ARM V6 usat (argument parse). */
b99bd4ef
NC
8660
8661static void
c19d1205 8662do_usat (void)
b99bd4ef 8663{
c19d1205
ZW
8664 inst.instruction |= inst.operands[0].reg << 12;
8665 inst.instruction |= inst.operands[1].imm << 16;
8666 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8667
c19d1205
ZW
8668 if (inst.operands[3].present)
8669 encode_arm_shift (3);
b99bd4ef
NC
8670}
8671
c19d1205 8672/* ARM V6 ssat16 (argument parse). */
09d92015
MM
8673
8674static void
c19d1205 8675do_ssat16 (void)
09d92015 8676{
c19d1205
ZW
8677 inst.instruction |= inst.operands[0].reg << 12;
8678 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8679 inst.instruction |= inst.operands[2].reg;
09d92015
MM
8680}
8681
c19d1205
ZW
8682static void
8683do_usat16 (void)
a737bd4d 8684{
c19d1205
ZW
8685 inst.instruction |= inst.operands[0].reg << 12;
8686 inst.instruction |= inst.operands[1].imm << 16;
8687 inst.instruction |= inst.operands[2].reg;
8688}
a737bd4d 8689
c19d1205
ZW
8690/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8691 preserving the other bits.
a737bd4d 8692
c19d1205
ZW
8693 setend <endian_specifier>, where <endian_specifier> is either
8694 BE or LE. */
a737bd4d 8695
c19d1205
ZW
8696static void
8697do_setend (void)
8698{
12e37cbc
MGD
8699 if (warn_on_deprecated
8700 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
8701 as_warn (_("setend use is deprecated for ARMv8"));
8702
c19d1205
ZW
8703 if (inst.operands[0].imm)
8704 inst.instruction |= 0x200;
a737bd4d
NC
8705}
8706
8707static void
c19d1205 8708do_shift (void)
a737bd4d 8709{
c19d1205
ZW
8710 unsigned int Rm = (inst.operands[1].present
8711 ? inst.operands[1].reg
8712 : inst.operands[0].reg);
a737bd4d 8713
c19d1205
ZW
8714 inst.instruction |= inst.operands[0].reg << 12;
8715 inst.instruction |= Rm;
8716 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 8717 {
c19d1205
ZW
8718 inst.instruction |= inst.operands[2].reg << 8;
8719 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
8720 /* PR 12854: Error on extraneous shifts. */
8721 constraint (inst.operands[2].shifted,
8722 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
8723 }
8724 else
c19d1205 8725 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
8726}
8727
09d92015 8728static void
3eb17e6b 8729do_smc (void)
09d92015 8730{
3eb17e6b 8731 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 8732 inst.reloc.pc_rel = 0;
09d92015
MM
8733}
8734
90ec0d68
MGD
8735static void
8736do_hvc (void)
8737{
8738 inst.reloc.type = BFD_RELOC_ARM_HVC;
8739 inst.reloc.pc_rel = 0;
8740}
8741
09d92015 8742static void
c19d1205 8743do_swi (void)
09d92015 8744{
c19d1205
ZW
8745 inst.reloc.type = BFD_RELOC_ARM_SWI;
8746 inst.reloc.pc_rel = 0;
09d92015
MM
8747}
8748
c19d1205
ZW
8749/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8750 SMLAxy{cond} Rd,Rm,Rs,Rn
8751 SMLAWy{cond} Rd,Rm,Rs,Rn
8752 Error if any register is R15. */
e16bb312 8753
c19d1205
ZW
8754static void
8755do_smla (void)
e16bb312 8756{
c19d1205
ZW
8757 inst.instruction |= inst.operands[0].reg << 16;
8758 inst.instruction |= inst.operands[1].reg;
8759 inst.instruction |= inst.operands[2].reg << 8;
8760 inst.instruction |= inst.operands[3].reg << 12;
8761}
a737bd4d 8762
c19d1205
ZW
8763/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8764 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8765 Error if any register is R15.
8766 Warning if Rdlo == Rdhi. */
a737bd4d 8767
c19d1205
ZW
8768static void
8769do_smlal (void)
8770{
8771 inst.instruction |= inst.operands[0].reg << 12;
8772 inst.instruction |= inst.operands[1].reg << 16;
8773 inst.instruction |= inst.operands[2].reg;
8774 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 8775
c19d1205
ZW
8776 if (inst.operands[0].reg == inst.operands[1].reg)
8777 as_tsktsk (_("rdhi and rdlo must be different"));
8778}
a737bd4d 8779
c19d1205
ZW
8780/* ARM V5E (El Segundo) signed-multiply (argument parse)
8781 SMULxy{cond} Rd,Rm,Rs
8782 Error if any register is R15. */
a737bd4d 8783
c19d1205
ZW
8784static void
8785do_smul (void)
8786{
8787 inst.instruction |= inst.operands[0].reg << 16;
8788 inst.instruction |= inst.operands[1].reg;
8789 inst.instruction |= inst.operands[2].reg << 8;
8790}
a737bd4d 8791
b6702015
PB
8792/* ARM V6 srs (argument parse). The variable fields in the encoding are
8793 the same for both ARM and Thumb-2. */
a737bd4d 8794
c19d1205
ZW
8795static void
8796do_srs (void)
8797{
b6702015
PB
8798 int reg;
8799
8800 if (inst.operands[0].present)
8801 {
8802 reg = inst.operands[0].reg;
fdfde340 8803 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
8804 }
8805 else
fdfde340 8806 reg = REG_SP;
b6702015
PB
8807
8808 inst.instruction |= reg << 16;
8809 inst.instruction |= inst.operands[1].imm;
8810 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
8811 inst.instruction |= WRITE_BACK;
8812}
a737bd4d 8813
c19d1205 8814/* ARM V6 strex (argument parse). */
a737bd4d 8815
c19d1205
ZW
8816static void
8817do_strex (void)
8818{
8819 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8820 || inst.operands[2].postind || inst.operands[2].writeback
8821 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
8822 || inst.operands[2].negative
8823 /* See comment in do_ldrex(). */
8824 || (inst.operands[2].reg == REG_PC),
8825 BAD_ADDR_MODE);
a737bd4d 8826
c19d1205
ZW
8827 constraint (inst.operands[0].reg == inst.operands[1].reg
8828 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 8829
c19d1205
ZW
8830 constraint (inst.reloc.exp.X_op != O_constant
8831 || inst.reloc.exp.X_add_number != 0,
8832 _("offset must be zero in ARM encoding"));
a737bd4d 8833
c19d1205
ZW
8834 inst.instruction |= inst.operands[0].reg << 12;
8835 inst.instruction |= inst.operands[1].reg;
8836 inst.instruction |= inst.operands[2].reg << 16;
8837 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8838}
8839
877807f8
NC
8840static void
8841do_t_strexbh (void)
8842{
8843 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8844 || inst.operands[2].postind || inst.operands[2].writeback
8845 || inst.operands[2].immisreg || inst.operands[2].shifted
8846 || inst.operands[2].negative,
8847 BAD_ADDR_MODE);
8848
8849 constraint (inst.operands[0].reg == inst.operands[1].reg
8850 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8851
8852 do_rm_rd_rn ();
8853}
8854
e16bb312 8855static void
c19d1205 8856do_strexd (void)
e16bb312 8857{
c19d1205
ZW
8858 constraint (inst.operands[1].reg % 2 != 0,
8859 _("even register required"));
8860 constraint (inst.operands[2].present
8861 && inst.operands[2].reg != inst.operands[1].reg + 1,
8862 _("can only store two consecutive registers"));
8863 /* If op 2 were present and equal to PC, this function wouldn't
8864 have been called in the first place. */
8865 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8866
c19d1205
ZW
8867 constraint (inst.operands[0].reg == inst.operands[1].reg
8868 || inst.operands[0].reg == inst.operands[1].reg + 1
8869 || inst.operands[0].reg == inst.operands[3].reg,
8870 BAD_OVERLAP);
e16bb312 8871
c19d1205
ZW
8872 inst.instruction |= inst.operands[0].reg << 12;
8873 inst.instruction |= inst.operands[1].reg;
8874 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8875}
8876
9eb6c0f1
MGD
8877/* ARM V8 STRL. */
8878static void
4b8c8c02 8879do_stlex (void)
9eb6c0f1
MGD
8880{
8881 constraint (inst.operands[0].reg == inst.operands[1].reg
8882 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8883
8884 do_rd_rm_rn ();
8885}
8886
8887static void
4b8c8c02 8888do_t_stlex (void)
9eb6c0f1
MGD
8889{
8890 constraint (inst.operands[0].reg == inst.operands[1].reg
8891 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8892
8893 do_rm_rd_rn ();
8894}
8895
c19d1205
ZW
8896/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8897 extends it to 32-bits, and adds the result to a value in another
8898 register. You can specify a rotation by 0, 8, 16, or 24 bits
8899 before extracting the 16-bit value.
8900 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8901 Condition defaults to COND_ALWAYS.
8902 Error if any register uses R15. */
8903
e16bb312 8904static void
c19d1205 8905do_sxtah (void)
e16bb312 8906{
c19d1205
ZW
8907 inst.instruction |= inst.operands[0].reg << 12;
8908 inst.instruction |= inst.operands[1].reg << 16;
8909 inst.instruction |= inst.operands[2].reg;
8910 inst.instruction |= inst.operands[3].imm << 10;
8911}
e16bb312 8912
c19d1205 8913/* ARM V6 SXTH.
e16bb312 8914
c19d1205
ZW
8915 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8916 Condition defaults to COND_ALWAYS.
8917 Error if any register uses R15. */
e16bb312
NC
8918
8919static void
c19d1205 8920do_sxth (void)
e16bb312 8921{
c19d1205
ZW
8922 inst.instruction |= inst.operands[0].reg << 12;
8923 inst.instruction |= inst.operands[1].reg;
8924 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8925}
c19d1205
ZW
8926\f
8927/* VFP instructions. In a logical order: SP variant first, monad
8928 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8929
8930static void
c19d1205 8931do_vfp_sp_monadic (void)
e16bb312 8932{
5287ad62
JB
8933 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8934 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8935}
8936
8937static void
c19d1205 8938do_vfp_sp_dyadic (void)
e16bb312 8939{
5287ad62
JB
8940 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8941 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8942 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8943}
8944
8945static void
c19d1205 8946do_vfp_sp_compare_z (void)
e16bb312 8947{
5287ad62 8948 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8949}
8950
8951static void
c19d1205 8952do_vfp_dp_sp_cvt (void)
e16bb312 8953{
5287ad62
JB
8954 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8955 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8956}
8957
8958static void
c19d1205 8959do_vfp_sp_dp_cvt (void)
e16bb312 8960{
5287ad62
JB
8961 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8962 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8963}
8964
8965static void
c19d1205 8966do_vfp_reg_from_sp (void)
e16bb312 8967{
c19d1205 8968 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8969 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8970}
8971
8972static void
c19d1205 8973do_vfp_reg2_from_sp2 (void)
e16bb312 8974{
c19d1205
ZW
8975 constraint (inst.operands[2].imm != 2,
8976 _("only two consecutive VFP SP registers allowed here"));
8977 inst.instruction |= inst.operands[0].reg << 12;
8978 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8979 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8980}
8981
8982static void
c19d1205 8983do_vfp_sp_from_reg (void)
e16bb312 8984{
5287ad62 8985 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8986 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8987}
8988
8989static void
c19d1205 8990do_vfp_sp2_from_reg2 (void)
e16bb312 8991{
c19d1205
ZW
8992 constraint (inst.operands[0].imm != 2,
8993 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8994 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8995 inst.instruction |= inst.operands[1].reg << 12;
8996 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8997}
8998
8999static void
c19d1205 9000do_vfp_sp_ldst (void)
e16bb312 9001{
5287ad62 9002 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9003 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9004}
9005
9006static void
c19d1205 9007do_vfp_dp_ldst (void)
e16bb312 9008{
5287ad62 9009 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9010 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9011}
9012
c19d1205 9013
e16bb312 9014static void
c19d1205 9015vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9016{
c19d1205
ZW
9017 if (inst.operands[0].writeback)
9018 inst.instruction |= WRITE_BACK;
9019 else
9020 constraint (ldstm_type != VFP_LDSTMIA,
9021 _("this addressing mode requires base-register writeback"));
9022 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9023 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9024 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9025}
9026
9027static void
c19d1205 9028vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9029{
c19d1205 9030 int count;
e16bb312 9031
c19d1205
ZW
9032 if (inst.operands[0].writeback)
9033 inst.instruction |= WRITE_BACK;
9034 else
9035 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9036 _("this addressing mode requires base-register writeback"));
e16bb312 9037
c19d1205 9038 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9039 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9040
c19d1205
ZW
9041 count = inst.operands[1].imm << 1;
9042 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9043 count += 1;
e16bb312 9044
c19d1205 9045 inst.instruction |= count;
e16bb312
NC
9046}
9047
9048static void
c19d1205 9049do_vfp_sp_ldstmia (void)
e16bb312 9050{
c19d1205 9051 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9052}
9053
9054static void
c19d1205 9055do_vfp_sp_ldstmdb (void)
e16bb312 9056{
c19d1205 9057 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9058}
9059
9060static void
c19d1205 9061do_vfp_dp_ldstmia (void)
e16bb312 9062{
c19d1205 9063 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9064}
9065
9066static void
c19d1205 9067do_vfp_dp_ldstmdb (void)
e16bb312 9068{
c19d1205 9069 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9070}
9071
9072static void
c19d1205 9073do_vfp_xp_ldstmia (void)
e16bb312 9074{
c19d1205
ZW
9075 vfp_dp_ldstm (VFP_LDSTMIAX);
9076}
e16bb312 9077
c19d1205
ZW
9078static void
9079do_vfp_xp_ldstmdb (void)
9080{
9081 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9082}
5287ad62
JB
9083
9084static void
9085do_vfp_dp_rd_rm (void)
9086{
9087 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9088 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9089}
9090
9091static void
9092do_vfp_dp_rn_rd (void)
9093{
9094 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9095 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9096}
9097
9098static void
9099do_vfp_dp_rd_rn (void)
9100{
9101 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9102 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9103}
9104
9105static void
9106do_vfp_dp_rd_rn_rm (void)
9107{
9108 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9109 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9110 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9111}
9112
9113static void
9114do_vfp_dp_rd (void)
9115{
9116 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9117}
9118
9119static void
9120do_vfp_dp_rm_rd_rn (void)
9121{
9122 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9123 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9124 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9125}
9126
9127/* VFPv3 instructions. */
9128static void
9129do_vfp_sp_const (void)
9130{
9131 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9132 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9133 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9134}
9135
9136static void
9137do_vfp_dp_const (void)
9138{
9139 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9140 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9141 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9142}
9143
9144static void
9145vfp_conv (int srcsize)
9146{
5f1af56b
MGD
9147 int immbits = srcsize - inst.operands[1].imm;
9148
fa94de6b
RM
9149 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9150 {
5f1af56b 9151 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9152 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9153 inst.error = _("immediate value out of range, expected range [0, 16]");
9154 return;
9155 }
fa94de6b 9156 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9157 {
9158 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9159 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9160 inst.error = _("immediate value out of range, expected range [1, 32]");
9161 return;
9162 }
9163
5287ad62
JB
9164 inst.instruction |= (immbits & 1) << 5;
9165 inst.instruction |= (immbits >> 1);
9166}
9167
9168static void
9169do_vfp_sp_conv_16 (void)
9170{
9171 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9172 vfp_conv (16);
9173}
9174
9175static void
9176do_vfp_dp_conv_16 (void)
9177{
9178 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9179 vfp_conv (16);
9180}
9181
9182static void
9183do_vfp_sp_conv_32 (void)
9184{
9185 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9186 vfp_conv (32);
9187}
9188
9189static void
9190do_vfp_dp_conv_32 (void)
9191{
9192 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9193 vfp_conv (32);
9194}
c19d1205
ZW
9195\f
9196/* FPA instructions. Also in a logical order. */
e16bb312 9197
c19d1205
ZW
9198static void
9199do_fpa_cmp (void)
9200{
9201 inst.instruction |= inst.operands[0].reg << 16;
9202 inst.instruction |= inst.operands[1].reg;
9203}
b99bd4ef
NC
9204
9205static void
c19d1205 9206do_fpa_ldmstm (void)
b99bd4ef 9207{
c19d1205
ZW
9208 inst.instruction |= inst.operands[0].reg << 12;
9209 switch (inst.operands[1].imm)
9210 {
9211 case 1: inst.instruction |= CP_T_X; break;
9212 case 2: inst.instruction |= CP_T_Y; break;
9213 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9214 case 4: break;
9215 default: abort ();
9216 }
b99bd4ef 9217
c19d1205
ZW
9218 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9219 {
9220 /* The instruction specified "ea" or "fd", so we can only accept
9221 [Rn]{!}. The instruction does not really support stacking or
9222 unstacking, so we have to emulate these by setting appropriate
9223 bits and offsets. */
9224 constraint (inst.reloc.exp.X_op != O_constant
9225 || inst.reloc.exp.X_add_number != 0,
9226 _("this instruction does not support indexing"));
b99bd4ef 9227
c19d1205
ZW
9228 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9229 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9230
c19d1205
ZW
9231 if (!(inst.instruction & INDEX_UP))
9232 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9233
c19d1205
ZW
9234 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9235 {
9236 inst.operands[2].preind = 0;
9237 inst.operands[2].postind = 1;
9238 }
9239 }
b99bd4ef 9240
c19d1205 9241 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9242}
c19d1205
ZW
9243\f
9244/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9245
c19d1205
ZW
9246static void
9247do_iwmmxt_tandorc (void)
9248{
9249 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9250}
b99bd4ef 9251
c19d1205
ZW
9252static void
9253do_iwmmxt_textrc (void)
9254{
9255 inst.instruction |= inst.operands[0].reg << 12;
9256 inst.instruction |= inst.operands[1].imm;
9257}
b99bd4ef
NC
9258
9259static void
c19d1205 9260do_iwmmxt_textrm (void)
b99bd4ef 9261{
c19d1205
ZW
9262 inst.instruction |= inst.operands[0].reg << 12;
9263 inst.instruction |= inst.operands[1].reg << 16;
9264 inst.instruction |= inst.operands[2].imm;
9265}
b99bd4ef 9266
c19d1205
ZW
9267static void
9268do_iwmmxt_tinsr (void)
9269{
9270 inst.instruction |= inst.operands[0].reg << 16;
9271 inst.instruction |= inst.operands[1].reg << 12;
9272 inst.instruction |= inst.operands[2].imm;
9273}
b99bd4ef 9274
c19d1205
ZW
9275static void
9276do_iwmmxt_tmia (void)
9277{
9278 inst.instruction |= inst.operands[0].reg << 5;
9279 inst.instruction |= inst.operands[1].reg;
9280 inst.instruction |= inst.operands[2].reg << 12;
9281}
b99bd4ef 9282
c19d1205
ZW
9283static void
9284do_iwmmxt_waligni (void)
9285{
9286 inst.instruction |= inst.operands[0].reg << 12;
9287 inst.instruction |= inst.operands[1].reg << 16;
9288 inst.instruction |= inst.operands[2].reg;
9289 inst.instruction |= inst.operands[3].imm << 20;
9290}
b99bd4ef 9291
2d447fca
JM
9292static void
9293do_iwmmxt_wmerge (void)
9294{
9295 inst.instruction |= inst.operands[0].reg << 12;
9296 inst.instruction |= inst.operands[1].reg << 16;
9297 inst.instruction |= inst.operands[2].reg;
9298 inst.instruction |= inst.operands[3].imm << 21;
9299}
9300
c19d1205
ZW
9301static void
9302do_iwmmxt_wmov (void)
9303{
9304 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9305 inst.instruction |= inst.operands[0].reg << 12;
9306 inst.instruction |= inst.operands[1].reg << 16;
9307 inst.instruction |= inst.operands[1].reg;
9308}
b99bd4ef 9309
c19d1205
ZW
9310static void
9311do_iwmmxt_wldstbh (void)
9312{
8f06b2d8 9313 int reloc;
c19d1205 9314 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
9315 if (thumb_mode)
9316 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9317 else
9318 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9319 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
9320}
9321
c19d1205
ZW
9322static void
9323do_iwmmxt_wldstw (void)
9324{
9325 /* RIWR_RIWC clears .isreg for a control register. */
9326 if (!inst.operands[0].isreg)
9327 {
9328 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9329 inst.instruction |= 0xf0000000;
9330 }
b99bd4ef 9331
c19d1205
ZW
9332 inst.instruction |= inst.operands[0].reg << 12;
9333 encode_arm_cp_address (1, TRUE, TRUE, 0);
9334}
b99bd4ef
NC
9335
9336static void
c19d1205 9337do_iwmmxt_wldstd (void)
b99bd4ef 9338{
c19d1205 9339 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
9340 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9341 && inst.operands[1].immisreg)
9342 {
9343 inst.instruction &= ~0x1a000ff;
9344 inst.instruction |= (0xf << 28);
9345 if (inst.operands[1].preind)
9346 inst.instruction |= PRE_INDEX;
9347 if (!inst.operands[1].negative)
9348 inst.instruction |= INDEX_UP;
9349 if (inst.operands[1].writeback)
9350 inst.instruction |= WRITE_BACK;
9351 inst.instruction |= inst.operands[1].reg << 16;
9352 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9353 inst.instruction |= inst.operands[1].imm;
9354 }
9355 else
9356 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 9357}
b99bd4ef 9358
c19d1205
ZW
9359static void
9360do_iwmmxt_wshufh (void)
9361{
9362 inst.instruction |= inst.operands[0].reg << 12;
9363 inst.instruction |= inst.operands[1].reg << 16;
9364 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
9365 inst.instruction |= (inst.operands[2].imm & 0x0f);
9366}
b99bd4ef 9367
c19d1205
ZW
9368static void
9369do_iwmmxt_wzero (void)
9370{
9371 /* WZERO reg is an alias for WANDN reg, reg, reg. */
9372 inst.instruction |= inst.operands[0].reg;
9373 inst.instruction |= inst.operands[0].reg << 12;
9374 inst.instruction |= inst.operands[0].reg << 16;
9375}
2d447fca
JM
9376
9377static void
9378do_iwmmxt_wrwrwr_or_imm5 (void)
9379{
9380 if (inst.operands[2].isreg)
9381 do_rd_rn_rm ();
9382 else {
9383 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
9384 _("immediate operand requires iWMMXt2"));
9385 do_rd_rn ();
9386 if (inst.operands[2].imm == 0)
9387 {
9388 switch ((inst.instruction >> 20) & 0xf)
9389 {
9390 case 4:
9391 case 5:
9392 case 6:
5f4273c7 9393 case 7:
2d447fca
JM
9394 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
9395 inst.operands[2].imm = 16;
9396 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
9397 break;
9398 case 8:
9399 case 9:
9400 case 10:
9401 case 11:
9402 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
9403 inst.operands[2].imm = 32;
9404 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
9405 break;
9406 case 12:
9407 case 13:
9408 case 14:
9409 case 15:
9410 {
9411 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
9412 unsigned long wrn;
9413 wrn = (inst.instruction >> 16) & 0xf;
9414 inst.instruction &= 0xff0fff0f;
9415 inst.instruction |= wrn;
9416 /* Bail out here; the instruction is now assembled. */
9417 return;
9418 }
9419 }
9420 }
9421 /* Map 32 -> 0, etc. */
9422 inst.operands[2].imm &= 0x1f;
9423 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
9424 }
9425}
c19d1205
ZW
9426\f
9427/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
9428 operations first, then control, shift, and load/store. */
b99bd4ef 9429
c19d1205 9430/* Insns like "foo X,Y,Z". */
b99bd4ef 9431
c19d1205
ZW
9432static void
9433do_mav_triple (void)
9434{
9435 inst.instruction |= inst.operands[0].reg << 16;
9436 inst.instruction |= inst.operands[1].reg;
9437 inst.instruction |= inst.operands[2].reg << 12;
9438}
b99bd4ef 9439
c19d1205
ZW
9440/* Insns like "foo W,X,Y,Z".
9441 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 9442
c19d1205
ZW
9443static void
9444do_mav_quad (void)
9445{
9446 inst.instruction |= inst.operands[0].reg << 5;
9447 inst.instruction |= inst.operands[1].reg << 12;
9448 inst.instruction |= inst.operands[2].reg << 16;
9449 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
9450}
9451
c19d1205
ZW
9452/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
9453static void
9454do_mav_dspsc (void)
a737bd4d 9455{
c19d1205
ZW
9456 inst.instruction |= inst.operands[1].reg << 12;
9457}
a737bd4d 9458
c19d1205
ZW
9459/* Maverick shift immediate instructions.
9460 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
9461 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 9462
c19d1205
ZW
9463static void
9464do_mav_shift (void)
9465{
9466 int imm = inst.operands[2].imm;
a737bd4d 9467
c19d1205
ZW
9468 inst.instruction |= inst.operands[0].reg << 12;
9469 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 9470
c19d1205
ZW
9471 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
9472 Bits 5-7 of the insn should have bits 4-6 of the immediate.
9473 Bit 4 should be 0. */
9474 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 9475
c19d1205
ZW
9476 inst.instruction |= imm;
9477}
9478\f
9479/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 9480
c19d1205
ZW
9481/* Xscale multiply-accumulate (argument parse)
9482 MIAcc acc0,Rm,Rs
9483 MIAPHcc acc0,Rm,Rs
9484 MIAxycc acc0,Rm,Rs. */
a737bd4d 9485
c19d1205
ZW
9486static void
9487do_xsc_mia (void)
9488{
9489 inst.instruction |= inst.operands[1].reg;
9490 inst.instruction |= inst.operands[2].reg << 12;
9491}
a737bd4d 9492
c19d1205 9493/* Xscale move-accumulator-register (argument parse)
a737bd4d 9494
c19d1205 9495 MARcc acc0,RdLo,RdHi. */
b99bd4ef 9496
c19d1205
ZW
9497static void
9498do_xsc_mar (void)
9499{
9500 inst.instruction |= inst.operands[1].reg << 12;
9501 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9502}
9503
c19d1205 9504/* Xscale move-register-accumulator (argument parse)
b99bd4ef 9505
c19d1205 9506 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
9507
9508static void
c19d1205 9509do_xsc_mra (void)
b99bd4ef 9510{
c19d1205
ZW
9511 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
9512 inst.instruction |= inst.operands[0].reg << 12;
9513 inst.instruction |= inst.operands[1].reg << 16;
9514}
9515\f
9516/* Encoding functions relevant only to Thumb. */
b99bd4ef 9517
c19d1205
ZW
9518/* inst.operands[i] is a shifted-register operand; encode
9519 it into inst.instruction in the format used by Thumb32. */
9520
9521static void
9522encode_thumb32_shifted_operand (int i)
9523{
9524 unsigned int value = inst.reloc.exp.X_add_number;
9525 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 9526
9c3c69f2
PB
9527 constraint (inst.operands[i].immisreg,
9528 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
9529 inst.instruction |= inst.operands[i].reg;
9530 if (shift == SHIFT_RRX)
9531 inst.instruction |= SHIFT_ROR << 4;
9532 else
b99bd4ef 9533 {
c19d1205
ZW
9534 constraint (inst.reloc.exp.X_op != O_constant,
9535 _("expression too complex"));
9536
9537 constraint (value > 32
9538 || (value == 32 && (shift == SHIFT_LSL
9539 || shift == SHIFT_ROR)),
9540 _("shift expression is too large"));
9541
9542 if (value == 0)
9543 shift = SHIFT_LSL;
9544 else if (value == 32)
9545 value = 0;
9546
9547 inst.instruction |= shift << 4;
9548 inst.instruction |= (value & 0x1c) << 10;
9549 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 9550 }
c19d1205 9551}
b99bd4ef 9552
b99bd4ef 9553
c19d1205
ZW
9554/* inst.operands[i] was set up by parse_address. Encode it into a
9555 Thumb32 format load or store instruction. Reject forms that cannot
9556 be used with such instructions. If is_t is true, reject forms that
9557 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
9558 that cannot be used with a D instruction. If it is a store insn,
9559 reject PC in Rn. */
b99bd4ef 9560
c19d1205
ZW
9561static void
9562encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
9563{
5be8be5d 9564 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
9565
9566 constraint (!inst.operands[i].isreg,
53365c0d 9567 _("Instruction does not support =N addresses"));
b99bd4ef 9568
c19d1205
ZW
9569 inst.instruction |= inst.operands[i].reg << 16;
9570 if (inst.operands[i].immisreg)
b99bd4ef 9571 {
5be8be5d 9572 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
9573 constraint (is_t || is_d, _("cannot use register index with this instruction"));
9574 constraint (inst.operands[i].negative,
9575 _("Thumb does not support negative register indexing"));
9576 constraint (inst.operands[i].postind,
9577 _("Thumb does not support register post-indexing"));
9578 constraint (inst.operands[i].writeback,
9579 _("Thumb does not support register indexing with writeback"));
9580 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
9581 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 9582
f40d1643 9583 inst.instruction |= inst.operands[i].imm;
c19d1205 9584 if (inst.operands[i].shifted)
b99bd4ef 9585 {
c19d1205
ZW
9586 constraint (inst.reloc.exp.X_op != O_constant,
9587 _("expression too complex"));
9c3c69f2
PB
9588 constraint (inst.reloc.exp.X_add_number < 0
9589 || inst.reloc.exp.X_add_number > 3,
c19d1205 9590 _("shift out of range"));
9c3c69f2 9591 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
9592 }
9593 inst.reloc.type = BFD_RELOC_UNUSED;
9594 }
9595 else if (inst.operands[i].preind)
9596 {
5be8be5d 9597 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 9598 constraint (is_t && inst.operands[i].writeback,
c19d1205 9599 _("cannot use writeback with this instruction"));
4755303e
WN
9600 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
9601 BAD_PC_ADDRESSING);
c19d1205
ZW
9602
9603 if (is_d)
9604 {
9605 inst.instruction |= 0x01000000;
9606 if (inst.operands[i].writeback)
9607 inst.instruction |= 0x00200000;
b99bd4ef 9608 }
c19d1205 9609 else
b99bd4ef 9610 {
c19d1205
ZW
9611 inst.instruction |= 0x00000c00;
9612 if (inst.operands[i].writeback)
9613 inst.instruction |= 0x00000100;
b99bd4ef 9614 }
c19d1205 9615 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 9616 }
c19d1205 9617 else if (inst.operands[i].postind)
b99bd4ef 9618 {
9c2799c2 9619 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
9620 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
9621 constraint (is_t, _("cannot use post-indexing with this instruction"));
9622
9623 if (is_d)
9624 inst.instruction |= 0x00200000;
9625 else
9626 inst.instruction |= 0x00000900;
9627 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9628 }
9629 else /* unindexed - only for coprocessor */
9630 inst.error = _("instruction does not accept unindexed addressing");
9631}
9632
9633/* Table of Thumb instructions which exist in both 16- and 32-bit
9634 encodings (the latter only in post-V6T2 cores). The index is the
9635 value used in the insns table below. When there is more than one
9636 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
9637 holds variant (1).
9638 Also contains several pseudo-instructions used during relaxation. */
c19d1205 9639#define T16_32_TAB \
21d799b5
NC
9640 X(_adc, 4140, eb400000), \
9641 X(_adcs, 4140, eb500000), \
9642 X(_add, 1c00, eb000000), \
9643 X(_adds, 1c00, eb100000), \
9644 X(_addi, 0000, f1000000), \
9645 X(_addis, 0000, f1100000), \
9646 X(_add_pc,000f, f20f0000), \
9647 X(_add_sp,000d, f10d0000), \
9648 X(_adr, 000f, f20f0000), \
9649 X(_and, 4000, ea000000), \
9650 X(_ands, 4000, ea100000), \
9651 X(_asr, 1000, fa40f000), \
9652 X(_asrs, 1000, fa50f000), \
9653 X(_b, e000, f000b000), \
9654 X(_bcond, d000, f0008000), \
9655 X(_bic, 4380, ea200000), \
9656 X(_bics, 4380, ea300000), \
9657 X(_cmn, 42c0, eb100f00), \
9658 X(_cmp, 2800, ebb00f00), \
9659 X(_cpsie, b660, f3af8400), \
9660 X(_cpsid, b670, f3af8600), \
9661 X(_cpy, 4600, ea4f0000), \
9662 X(_dec_sp,80dd, f1ad0d00), \
9663 X(_eor, 4040, ea800000), \
9664 X(_eors, 4040, ea900000), \
9665 X(_inc_sp,00dd, f10d0d00), \
9666 X(_ldmia, c800, e8900000), \
9667 X(_ldr, 6800, f8500000), \
9668 X(_ldrb, 7800, f8100000), \
9669 X(_ldrh, 8800, f8300000), \
9670 X(_ldrsb, 5600, f9100000), \
9671 X(_ldrsh, 5e00, f9300000), \
9672 X(_ldr_pc,4800, f85f0000), \
9673 X(_ldr_pc2,4800, f85f0000), \
9674 X(_ldr_sp,9800, f85d0000), \
9675 X(_lsl, 0000, fa00f000), \
9676 X(_lsls, 0000, fa10f000), \
9677 X(_lsr, 0800, fa20f000), \
9678 X(_lsrs, 0800, fa30f000), \
9679 X(_mov, 2000, ea4f0000), \
9680 X(_movs, 2000, ea5f0000), \
9681 X(_mul, 4340, fb00f000), \
9682 X(_muls, 4340, ffffffff), /* no 32b muls */ \
9683 X(_mvn, 43c0, ea6f0000), \
9684 X(_mvns, 43c0, ea7f0000), \
9685 X(_neg, 4240, f1c00000), /* rsb #0 */ \
9686 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
9687 X(_orr, 4300, ea400000), \
9688 X(_orrs, 4300, ea500000), \
9689 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9690 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9691 X(_rev, ba00, fa90f080), \
9692 X(_rev16, ba40, fa90f090), \
9693 X(_revsh, bac0, fa90f0b0), \
9694 X(_ror, 41c0, fa60f000), \
9695 X(_rors, 41c0, fa70f000), \
9696 X(_sbc, 4180, eb600000), \
9697 X(_sbcs, 4180, eb700000), \
9698 X(_stmia, c000, e8800000), \
9699 X(_str, 6000, f8400000), \
9700 X(_strb, 7000, f8000000), \
9701 X(_strh, 8000, f8200000), \
9702 X(_str_sp,9000, f84d0000), \
9703 X(_sub, 1e00, eba00000), \
9704 X(_subs, 1e00, ebb00000), \
9705 X(_subi, 8000, f1a00000), \
9706 X(_subis, 8000, f1b00000), \
9707 X(_sxtb, b240, fa4ff080), \
9708 X(_sxth, b200, fa0ff080), \
9709 X(_tst, 4200, ea100f00), \
9710 X(_uxtb, b2c0, fa5ff080), \
9711 X(_uxth, b280, fa1ff080), \
9712 X(_nop, bf00, f3af8000), \
9713 X(_yield, bf10, f3af8001), \
9714 X(_wfe, bf20, f3af8002), \
9715 X(_wfi, bf30, f3af8003), \
53c4b28b 9716 X(_sev, bf40, f3af8004), \
74db7efb
NC
9717 X(_sevl, bf50, f3af8005), \
9718 X(_udf, de00, f7f0a000)
c19d1205
ZW
9719
9720/* To catch errors in encoding functions, the codes are all offset by
9721 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9722 as 16-bit instructions. */
21d799b5 9723#define X(a,b,c) T_MNEM##a
c19d1205
ZW
9724enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9725#undef X
9726
9727#define X(a,b,c) 0x##b
9728static const unsigned short thumb_op16[] = { T16_32_TAB };
9729#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9730#undef X
9731
9732#define X(a,b,c) 0x##c
9733static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
9734#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9735#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
9736#undef X
9737#undef T16_32_TAB
9738
9739/* Thumb instruction encoders, in alphabetical order. */
9740
92e90b6e 9741/* ADDW or SUBW. */
c921be7d 9742
92e90b6e
PB
9743static void
9744do_t_add_sub_w (void)
9745{
9746 int Rd, Rn;
9747
9748 Rd = inst.operands[0].reg;
9749 Rn = inst.operands[1].reg;
9750
539d4391
NC
9751 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9752 is the SP-{plus,minus}-immediate form of the instruction. */
9753 if (Rn == REG_SP)
9754 constraint (Rd == REG_PC, BAD_PC);
9755 else
9756 reject_bad_reg (Rd);
fdfde340 9757
92e90b6e
PB
9758 inst.instruction |= (Rn << 16) | (Rd << 8);
9759 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9760}
9761
c19d1205
ZW
9762/* Parse an add or subtract instruction. We get here with inst.instruction
9763 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9764
9765static void
9766do_t_add_sub (void)
9767{
9768 int Rd, Rs, Rn;
9769
9770 Rd = inst.operands[0].reg;
9771 Rs = (inst.operands[1].present
9772 ? inst.operands[1].reg /* Rd, Rs, foo */
9773 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9774
e07e6e58
NC
9775 if (Rd == REG_PC)
9776 set_it_insn_type_last ();
9777
c19d1205
ZW
9778 if (unified_syntax)
9779 {
0110f2b8
PB
9780 bfd_boolean flags;
9781 bfd_boolean narrow;
9782 int opcode;
9783
9784 flags = (inst.instruction == T_MNEM_adds
9785 || inst.instruction == T_MNEM_subs);
9786 if (flags)
e07e6e58 9787 narrow = !in_it_block ();
0110f2b8 9788 else
e07e6e58 9789 narrow = in_it_block ();
c19d1205 9790 if (!inst.operands[2].isreg)
b99bd4ef 9791 {
16805f35
PB
9792 int add;
9793
fdfde340
JM
9794 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9795
16805f35
PB
9796 add = (inst.instruction == T_MNEM_add
9797 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
9798 opcode = 0;
9799 if (inst.size_req != 4)
9800 {
0110f2b8 9801 /* Attempt to use a narrow opcode, with relaxation if
477330fc 9802 appropriate. */
0110f2b8
PB
9803 if (Rd == REG_SP && Rs == REG_SP && !flags)
9804 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9805 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9806 opcode = T_MNEM_add_sp;
9807 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9808 opcode = T_MNEM_add_pc;
9809 else if (Rd <= 7 && Rs <= 7 && narrow)
9810 {
9811 if (flags)
9812 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9813 else
9814 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9815 }
9816 if (opcode)
9817 {
9818 inst.instruction = THUMB_OP16(opcode);
9819 inst.instruction |= (Rd << 4) | Rs;
9820 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9821 if (inst.size_req != 2)
9822 inst.relax = opcode;
9823 }
9824 else
9825 constraint (inst.size_req == 2, BAD_HIREG);
9826 }
9827 if (inst.size_req == 4
9828 || (inst.size_req != 2 && !opcode))
9829 {
efd81785
PB
9830 if (Rd == REG_PC)
9831 {
fdfde340 9832 constraint (add, BAD_PC);
efd81785
PB
9833 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9834 _("only SUBS PC, LR, #const allowed"));
9835 constraint (inst.reloc.exp.X_op != O_constant,
9836 _("expression too complex"));
9837 constraint (inst.reloc.exp.X_add_number < 0
9838 || inst.reloc.exp.X_add_number > 0xff,
9839 _("immediate value out of range"));
9840 inst.instruction = T2_SUBS_PC_LR
9841 | inst.reloc.exp.X_add_number;
9842 inst.reloc.type = BFD_RELOC_UNUSED;
9843 return;
9844 }
9845 else if (Rs == REG_PC)
16805f35
PB
9846 {
9847 /* Always use addw/subw. */
9848 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9849 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9850 }
9851 else
9852 {
9853 inst.instruction = THUMB_OP32 (inst.instruction);
9854 inst.instruction = (inst.instruction & 0xe1ffffff)
9855 | 0x10000000;
9856 if (flags)
9857 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9858 else
9859 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9860 }
dc4503c6
PB
9861 inst.instruction |= Rd << 8;
9862 inst.instruction |= Rs << 16;
0110f2b8 9863 }
b99bd4ef 9864 }
c19d1205
ZW
9865 else
9866 {
5f4cb198
NC
9867 unsigned int value = inst.reloc.exp.X_add_number;
9868 unsigned int shift = inst.operands[2].shift_kind;
9869
c19d1205
ZW
9870 Rn = inst.operands[2].reg;
9871 /* See if we can do this with a 16-bit instruction. */
9872 if (!inst.operands[2].shifted && inst.size_req != 4)
9873 {
e27ec89e
PB
9874 if (Rd > 7 || Rs > 7 || Rn > 7)
9875 narrow = FALSE;
9876
9877 if (narrow)
c19d1205 9878 {
e27ec89e
PB
9879 inst.instruction = ((inst.instruction == T_MNEM_adds
9880 || inst.instruction == T_MNEM_add)
c19d1205
ZW
9881 ? T_OPCODE_ADD_R3
9882 : T_OPCODE_SUB_R3);
9883 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9884 return;
9885 }
b99bd4ef 9886
7e806470 9887 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 9888 {
7e806470
PB
9889 /* Thumb-1 cores (except v6-M) require at least one high
9890 register in a narrow non flag setting add. */
9891 if (Rd > 7 || Rn > 7
9892 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9893 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9894 {
7e806470
PB
9895 if (Rd == Rn)
9896 {
9897 Rn = Rs;
9898 Rs = Rd;
9899 }
c19d1205
ZW
9900 inst.instruction = T_OPCODE_ADD_HI;
9901 inst.instruction |= (Rd & 8) << 4;
9902 inst.instruction |= (Rd & 7);
9903 inst.instruction |= Rn << 3;
9904 return;
9905 }
c19d1205
ZW
9906 }
9907 }
c921be7d 9908
fdfde340
JM
9909 constraint (Rd == REG_PC, BAD_PC);
9910 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9911 constraint (Rs == REG_PC, BAD_PC);
9912 reject_bad_reg (Rn);
9913
c19d1205
ZW
9914 /* If we get here, it can't be done in 16 bits. */
9915 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9916 _("shift must be constant"));
9917 inst.instruction = THUMB_OP32 (inst.instruction);
9918 inst.instruction |= Rd << 8;
9919 inst.instruction |= Rs << 16;
5f4cb198
NC
9920 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
9921 _("shift value over 3 not allowed in thumb mode"));
9922 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
9923 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
9924 encode_thumb32_shifted_operand (2);
9925 }
9926 }
9927 else
9928 {
9929 constraint (inst.instruction == T_MNEM_adds
9930 || inst.instruction == T_MNEM_subs,
9931 BAD_THUMB32);
b99bd4ef 9932
c19d1205 9933 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9934 {
c19d1205
ZW
9935 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9936 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9937 BAD_HIREG);
9938
9939 inst.instruction = (inst.instruction == T_MNEM_add
9940 ? 0x0000 : 0x8000);
9941 inst.instruction |= (Rd << 4) | Rs;
9942 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9943 return;
9944 }
9945
c19d1205
ZW
9946 Rn = inst.operands[2].reg;
9947 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9948
c19d1205
ZW
9949 /* We now have Rd, Rs, and Rn set to registers. */
9950 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9951 {
c19d1205
ZW
9952 /* Can't do this for SUB. */
9953 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9954 inst.instruction = T_OPCODE_ADD_HI;
9955 inst.instruction |= (Rd & 8) << 4;
9956 inst.instruction |= (Rd & 7);
9957 if (Rs == Rd)
9958 inst.instruction |= Rn << 3;
9959 else if (Rn == Rd)
9960 inst.instruction |= Rs << 3;
9961 else
9962 constraint (1, _("dest must overlap one source register"));
9963 }
9964 else
9965 {
9966 inst.instruction = (inst.instruction == T_MNEM_add
9967 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9968 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9969 }
b99bd4ef 9970 }
b99bd4ef
NC
9971}
9972
c19d1205
ZW
9973static void
9974do_t_adr (void)
9975{
fdfde340
JM
9976 unsigned Rd;
9977
9978 Rd = inst.operands[0].reg;
9979 reject_bad_reg (Rd);
9980
9981 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9982 {
9983 /* Defer to section relaxation. */
9984 inst.relax = inst.instruction;
9985 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9986 inst.instruction |= Rd << 4;
0110f2b8
PB
9987 }
9988 else if (unified_syntax && inst.size_req != 2)
e9f89963 9989 {
0110f2b8 9990 /* Generate a 32-bit opcode. */
e9f89963 9991 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9992 inst.instruction |= Rd << 8;
e9f89963
PB
9993 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9994 inst.reloc.pc_rel = 1;
9995 }
9996 else
9997 {
0110f2b8 9998 /* Generate a 16-bit opcode. */
e9f89963
PB
9999 inst.instruction = THUMB_OP16 (inst.instruction);
10000 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10001 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10002 inst.reloc.pc_rel = 1;
b99bd4ef 10003
fdfde340 10004 inst.instruction |= Rd << 4;
e9f89963 10005 }
c19d1205 10006}
b99bd4ef 10007
c19d1205
ZW
10008/* Arithmetic instructions for which there is just one 16-bit
10009 instruction encoding, and it allows only two low registers.
10010 For maximal compatibility with ARM syntax, we allow three register
10011 operands even when Thumb-32 instructions are not available, as long
10012 as the first two are identical. For instance, both "sbc r0,r1" and
10013 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10014static void
c19d1205 10015do_t_arit3 (void)
b99bd4ef 10016{
c19d1205 10017 int Rd, Rs, Rn;
b99bd4ef 10018
c19d1205
ZW
10019 Rd = inst.operands[0].reg;
10020 Rs = (inst.operands[1].present
10021 ? inst.operands[1].reg /* Rd, Rs, foo */
10022 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10023 Rn = inst.operands[2].reg;
b99bd4ef 10024
fdfde340
JM
10025 reject_bad_reg (Rd);
10026 reject_bad_reg (Rs);
10027 if (inst.operands[2].isreg)
10028 reject_bad_reg (Rn);
10029
c19d1205 10030 if (unified_syntax)
b99bd4ef 10031 {
c19d1205
ZW
10032 if (!inst.operands[2].isreg)
10033 {
10034 /* For an immediate, we always generate a 32-bit opcode;
10035 section relaxation will shrink it later if possible. */
10036 inst.instruction = THUMB_OP32 (inst.instruction);
10037 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10038 inst.instruction |= Rd << 8;
10039 inst.instruction |= Rs << 16;
10040 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10041 }
10042 else
10043 {
e27ec89e
PB
10044 bfd_boolean narrow;
10045
c19d1205 10046 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10047 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10048 narrow = !in_it_block ();
e27ec89e 10049 else
e07e6e58 10050 narrow = in_it_block ();
e27ec89e
PB
10051
10052 if (Rd > 7 || Rn > 7 || Rs > 7)
10053 narrow = FALSE;
10054 if (inst.operands[2].shifted)
10055 narrow = FALSE;
10056 if (inst.size_req == 4)
10057 narrow = FALSE;
10058
10059 if (narrow
c19d1205
ZW
10060 && Rd == Rs)
10061 {
10062 inst.instruction = THUMB_OP16 (inst.instruction);
10063 inst.instruction |= Rd;
10064 inst.instruction |= Rn << 3;
10065 return;
10066 }
b99bd4ef 10067
c19d1205
ZW
10068 /* If we get here, it can't be done in 16 bits. */
10069 constraint (inst.operands[2].shifted
10070 && inst.operands[2].immisreg,
10071 _("shift must be constant"));
10072 inst.instruction = THUMB_OP32 (inst.instruction);
10073 inst.instruction |= Rd << 8;
10074 inst.instruction |= Rs << 16;
10075 encode_thumb32_shifted_operand (2);
10076 }
a737bd4d 10077 }
c19d1205 10078 else
b99bd4ef 10079 {
c19d1205
ZW
10080 /* On its face this is a lie - the instruction does set the
10081 flags. However, the only supported mnemonic in this mode
10082 says it doesn't. */
10083 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10084
c19d1205
ZW
10085 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10086 _("unshifted register required"));
10087 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10088 constraint (Rd != Rs,
10089 _("dest and source1 must be the same register"));
a737bd4d 10090
c19d1205
ZW
10091 inst.instruction = THUMB_OP16 (inst.instruction);
10092 inst.instruction |= Rd;
10093 inst.instruction |= Rn << 3;
b99bd4ef 10094 }
a737bd4d 10095}
b99bd4ef 10096
c19d1205
ZW
10097/* Similarly, but for instructions where the arithmetic operation is
10098 commutative, so we can allow either of them to be different from
10099 the destination operand in a 16-bit instruction. For instance, all
10100 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10101 accepted. */
10102static void
10103do_t_arit3c (void)
a737bd4d 10104{
c19d1205 10105 int Rd, Rs, Rn;
b99bd4ef 10106
c19d1205
ZW
10107 Rd = inst.operands[0].reg;
10108 Rs = (inst.operands[1].present
10109 ? inst.operands[1].reg /* Rd, Rs, foo */
10110 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10111 Rn = inst.operands[2].reg;
c921be7d 10112
fdfde340
JM
10113 reject_bad_reg (Rd);
10114 reject_bad_reg (Rs);
10115 if (inst.operands[2].isreg)
10116 reject_bad_reg (Rn);
a737bd4d 10117
c19d1205 10118 if (unified_syntax)
a737bd4d 10119 {
c19d1205 10120 if (!inst.operands[2].isreg)
b99bd4ef 10121 {
c19d1205
ZW
10122 /* For an immediate, we always generate a 32-bit opcode;
10123 section relaxation will shrink it later if possible. */
10124 inst.instruction = THUMB_OP32 (inst.instruction);
10125 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10126 inst.instruction |= Rd << 8;
10127 inst.instruction |= Rs << 16;
10128 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10129 }
c19d1205 10130 else
a737bd4d 10131 {
e27ec89e
PB
10132 bfd_boolean narrow;
10133
c19d1205 10134 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10135 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10136 narrow = !in_it_block ();
e27ec89e 10137 else
e07e6e58 10138 narrow = in_it_block ();
e27ec89e
PB
10139
10140 if (Rd > 7 || Rn > 7 || Rs > 7)
10141 narrow = FALSE;
10142 if (inst.operands[2].shifted)
10143 narrow = FALSE;
10144 if (inst.size_req == 4)
10145 narrow = FALSE;
10146
10147 if (narrow)
a737bd4d 10148 {
c19d1205 10149 if (Rd == Rs)
a737bd4d 10150 {
c19d1205
ZW
10151 inst.instruction = THUMB_OP16 (inst.instruction);
10152 inst.instruction |= Rd;
10153 inst.instruction |= Rn << 3;
10154 return;
a737bd4d 10155 }
c19d1205 10156 if (Rd == Rn)
a737bd4d 10157 {
c19d1205
ZW
10158 inst.instruction = THUMB_OP16 (inst.instruction);
10159 inst.instruction |= Rd;
10160 inst.instruction |= Rs << 3;
10161 return;
a737bd4d
NC
10162 }
10163 }
c19d1205
ZW
10164
10165 /* If we get here, it can't be done in 16 bits. */
10166 constraint (inst.operands[2].shifted
10167 && inst.operands[2].immisreg,
10168 _("shift must be constant"));
10169 inst.instruction = THUMB_OP32 (inst.instruction);
10170 inst.instruction |= Rd << 8;
10171 inst.instruction |= Rs << 16;
10172 encode_thumb32_shifted_operand (2);
a737bd4d 10173 }
b99bd4ef 10174 }
c19d1205
ZW
10175 else
10176 {
10177 /* On its face this is a lie - the instruction does set the
10178 flags. However, the only supported mnemonic in this mode
10179 says it doesn't. */
10180 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10181
c19d1205
ZW
10182 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10183 _("unshifted register required"));
10184 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10185
10186 inst.instruction = THUMB_OP16 (inst.instruction);
10187 inst.instruction |= Rd;
10188
10189 if (Rd == Rs)
10190 inst.instruction |= Rn << 3;
10191 else if (Rd == Rn)
10192 inst.instruction |= Rs << 3;
10193 else
10194 constraint (1, _("dest must overlap one source register"));
10195 }
a737bd4d
NC
10196}
10197
c19d1205
ZW
10198static void
10199do_t_bfc (void)
a737bd4d 10200{
fdfde340 10201 unsigned Rd;
c19d1205
ZW
10202 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10203 constraint (msb > 32, _("bit-field extends past end of register"));
10204 /* The instruction encoding stores the LSB and MSB,
10205 not the LSB and width. */
fdfde340
JM
10206 Rd = inst.operands[0].reg;
10207 reject_bad_reg (Rd);
10208 inst.instruction |= Rd << 8;
c19d1205
ZW
10209 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10210 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10211 inst.instruction |= msb - 1;
b99bd4ef
NC
10212}
10213
c19d1205
ZW
10214static void
10215do_t_bfi (void)
b99bd4ef 10216{
fdfde340 10217 int Rd, Rn;
c19d1205 10218 unsigned int msb;
b99bd4ef 10219
fdfde340
JM
10220 Rd = inst.operands[0].reg;
10221 reject_bad_reg (Rd);
10222
c19d1205
ZW
10223 /* #0 in second position is alternative syntax for bfc, which is
10224 the same instruction but with REG_PC in the Rm field. */
10225 if (!inst.operands[1].isreg)
fdfde340
JM
10226 Rn = REG_PC;
10227 else
10228 {
10229 Rn = inst.operands[1].reg;
10230 reject_bad_reg (Rn);
10231 }
b99bd4ef 10232
c19d1205
ZW
10233 msb = inst.operands[2].imm + inst.operands[3].imm;
10234 constraint (msb > 32, _("bit-field extends past end of register"));
10235 /* The instruction encoding stores the LSB and MSB,
10236 not the LSB and width. */
fdfde340
JM
10237 inst.instruction |= Rd << 8;
10238 inst.instruction |= Rn << 16;
c19d1205
ZW
10239 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10240 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10241 inst.instruction |= msb - 1;
b99bd4ef
NC
10242}
10243
c19d1205
ZW
10244static void
10245do_t_bfx (void)
b99bd4ef 10246{
fdfde340
JM
10247 unsigned Rd, Rn;
10248
10249 Rd = inst.operands[0].reg;
10250 Rn = inst.operands[1].reg;
10251
10252 reject_bad_reg (Rd);
10253 reject_bad_reg (Rn);
10254
c19d1205
ZW
10255 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10256 _("bit-field extends past end of register"));
fdfde340
JM
10257 inst.instruction |= Rd << 8;
10258 inst.instruction |= Rn << 16;
c19d1205
ZW
10259 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10260 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10261 inst.instruction |= inst.operands[3].imm - 1;
10262}
b99bd4ef 10263
c19d1205
ZW
10264/* ARM V5 Thumb BLX (argument parse)
10265 BLX <target_addr> which is BLX(1)
10266 BLX <Rm> which is BLX(2)
10267 Unfortunately, there are two different opcodes for this mnemonic.
10268 So, the insns[].value is not used, and the code here zaps values
10269 into inst.instruction.
b99bd4ef 10270
c19d1205
ZW
10271 ??? How to take advantage of the additional two bits of displacement
10272 available in Thumb32 mode? Need new relocation? */
b99bd4ef 10273
c19d1205
ZW
10274static void
10275do_t_blx (void)
10276{
e07e6e58
NC
10277 set_it_insn_type_last ();
10278
c19d1205 10279 if (inst.operands[0].isreg)
fdfde340
JM
10280 {
10281 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10282 /* We have a register, so this is BLX(2). */
10283 inst.instruction |= inst.operands[0].reg << 3;
10284 }
b99bd4ef
NC
10285 else
10286 {
c19d1205 10287 /* No register. This must be BLX(1). */
2fc8bdac 10288 inst.instruction = 0xf000e800;
0855e32b 10289 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
10290 }
10291}
10292
c19d1205
ZW
10293static void
10294do_t_branch (void)
b99bd4ef 10295{
0110f2b8 10296 int opcode;
dfa9f0d5 10297 int cond;
9ae92b05 10298 int reloc;
dfa9f0d5 10299
e07e6e58
NC
10300 cond = inst.cond;
10301 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10302
10303 if (in_it_block ())
dfa9f0d5
PB
10304 {
10305 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 10306 branches. */
dfa9f0d5 10307 cond = COND_ALWAYS;
dfa9f0d5
PB
10308 }
10309 else
10310 cond = inst.cond;
10311
10312 if (cond != COND_ALWAYS)
0110f2b8
PB
10313 opcode = T_MNEM_bcond;
10314 else
10315 opcode = inst.instruction;
10316
12d6b0b7
RS
10317 if (unified_syntax
10318 && (inst.size_req == 4
10960bfb
PB
10319 || (inst.size_req != 2
10320 && (inst.operands[0].hasreloc
10321 || inst.reloc.exp.X_op == O_constant))))
c19d1205 10322 {
0110f2b8 10323 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 10324 if (cond == COND_ALWAYS)
9ae92b05 10325 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
10326 else
10327 {
9c2799c2 10328 gas_assert (cond != 0xF);
dfa9f0d5 10329 inst.instruction |= cond << 22;
9ae92b05 10330 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
10331 }
10332 }
b99bd4ef
NC
10333 else
10334 {
0110f2b8 10335 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 10336 if (cond == COND_ALWAYS)
9ae92b05 10337 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 10338 else
b99bd4ef 10339 {
dfa9f0d5 10340 inst.instruction |= cond << 8;
9ae92b05 10341 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 10342 }
0110f2b8
PB
10343 /* Allow section relaxation. */
10344 if (unified_syntax && inst.size_req != 2)
10345 inst.relax = opcode;
b99bd4ef 10346 }
9ae92b05 10347 inst.reloc.type = reloc;
c19d1205 10348 inst.reloc.pc_rel = 1;
b99bd4ef
NC
10349}
10350
8884b720 10351/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 10352 between the two is the maximum immediate allowed - which is passed in
8884b720 10353 RANGE. */
b99bd4ef 10354static void
8884b720 10355do_t_bkpt_hlt1 (int range)
b99bd4ef 10356{
dfa9f0d5
PB
10357 constraint (inst.cond != COND_ALWAYS,
10358 _("instruction is always unconditional"));
c19d1205 10359 if (inst.operands[0].present)
b99bd4ef 10360 {
8884b720 10361 constraint (inst.operands[0].imm > range,
c19d1205
ZW
10362 _("immediate value out of range"));
10363 inst.instruction |= inst.operands[0].imm;
b99bd4ef 10364 }
8884b720
MGD
10365
10366 set_it_insn_type (NEUTRAL_IT_INSN);
10367}
10368
10369static void
10370do_t_hlt (void)
10371{
10372 do_t_bkpt_hlt1 (63);
10373}
10374
10375static void
10376do_t_bkpt (void)
10377{
10378 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
10379}
10380
10381static void
c19d1205 10382do_t_branch23 (void)
b99bd4ef 10383{
e07e6e58 10384 set_it_insn_type_last ();
0855e32b 10385 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 10386
0855e32b
NS
10387 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
10388 this file. We used to simply ignore the PLT reloc type here --
10389 the branch encoding is now needed to deal with TLSCALL relocs.
10390 So if we see a PLT reloc now, put it back to how it used to be to
10391 keep the preexisting behaviour. */
10392 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
10393 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 10394
4343666d 10395#if defined(OBJ_COFF)
c19d1205
ZW
10396 /* If the destination of the branch is a defined symbol which does not have
10397 the THUMB_FUNC attribute, then we must be calling a function which has
10398 the (interfacearm) attribute. We look for the Thumb entry point to that
10399 function and change the branch to refer to that function instead. */
10400 if ( inst.reloc.exp.X_op == O_symbol
10401 && inst.reloc.exp.X_add_symbol != NULL
10402 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10403 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10404 inst.reloc.exp.X_add_symbol =
10405 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 10406#endif
90e4755a
RE
10407}
10408
10409static void
c19d1205 10410do_t_bx (void)
90e4755a 10411{
e07e6e58 10412 set_it_insn_type_last ();
c19d1205
ZW
10413 inst.instruction |= inst.operands[0].reg << 3;
10414 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
10415 should cause the alignment to be checked once it is known. This is
10416 because BX PC only works if the instruction is word aligned. */
10417}
90e4755a 10418
c19d1205
ZW
10419static void
10420do_t_bxj (void)
10421{
fdfde340 10422 int Rm;
90e4755a 10423
e07e6e58 10424 set_it_insn_type_last ();
fdfde340
JM
10425 Rm = inst.operands[0].reg;
10426 reject_bad_reg (Rm);
10427 inst.instruction |= Rm << 16;
90e4755a
RE
10428}
10429
10430static void
c19d1205 10431do_t_clz (void)
90e4755a 10432{
fdfde340
JM
10433 unsigned Rd;
10434 unsigned Rm;
10435
10436 Rd = inst.operands[0].reg;
10437 Rm = inst.operands[1].reg;
10438
10439 reject_bad_reg (Rd);
10440 reject_bad_reg (Rm);
10441
10442 inst.instruction |= Rd << 8;
10443 inst.instruction |= Rm << 16;
10444 inst.instruction |= Rm;
c19d1205 10445}
90e4755a 10446
dfa9f0d5
PB
10447static void
10448do_t_cps (void)
10449{
e07e6e58 10450 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
10451 inst.instruction |= inst.operands[0].imm;
10452}
10453
c19d1205
ZW
10454static void
10455do_t_cpsi (void)
10456{
e07e6e58 10457 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 10458 if (unified_syntax
62b3e311
PB
10459 && (inst.operands[1].present || inst.size_req == 4)
10460 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 10461 {
c19d1205
ZW
10462 unsigned int imod = (inst.instruction & 0x0030) >> 4;
10463 inst.instruction = 0xf3af8000;
10464 inst.instruction |= imod << 9;
10465 inst.instruction |= inst.operands[0].imm << 5;
10466 if (inst.operands[1].present)
10467 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 10468 }
c19d1205 10469 else
90e4755a 10470 {
62b3e311
PB
10471 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
10472 && (inst.operands[0].imm & 4),
10473 _("selected processor does not support 'A' form "
10474 "of this instruction"));
10475 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
10476 _("Thumb does not support the 2-argument "
10477 "form of this instruction"));
10478 inst.instruction |= inst.operands[0].imm;
90e4755a 10479 }
90e4755a
RE
10480}
10481
c19d1205
ZW
10482/* THUMB CPY instruction (argument parse). */
10483
90e4755a 10484static void
c19d1205 10485do_t_cpy (void)
90e4755a 10486{
c19d1205 10487 if (inst.size_req == 4)
90e4755a 10488 {
c19d1205
ZW
10489 inst.instruction = THUMB_OP32 (T_MNEM_mov);
10490 inst.instruction |= inst.operands[0].reg << 8;
10491 inst.instruction |= inst.operands[1].reg;
90e4755a 10492 }
c19d1205 10493 else
90e4755a 10494 {
c19d1205
ZW
10495 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
10496 inst.instruction |= (inst.operands[0].reg & 0x7);
10497 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 10498 }
90e4755a
RE
10499}
10500
90e4755a 10501static void
25fe350b 10502do_t_cbz (void)
90e4755a 10503{
e07e6e58 10504 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
10505 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10506 inst.instruction |= inst.operands[0].reg;
10507 inst.reloc.pc_rel = 1;
10508 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
10509}
90e4755a 10510
62b3e311
PB
10511static void
10512do_t_dbg (void)
10513{
10514 inst.instruction |= inst.operands[0].imm;
10515}
10516
10517static void
10518do_t_div (void)
10519{
fdfde340
JM
10520 unsigned Rd, Rn, Rm;
10521
10522 Rd = inst.operands[0].reg;
10523 Rn = (inst.operands[1].present
10524 ? inst.operands[1].reg : Rd);
10525 Rm = inst.operands[2].reg;
10526
10527 reject_bad_reg (Rd);
10528 reject_bad_reg (Rn);
10529 reject_bad_reg (Rm);
10530
10531 inst.instruction |= Rd << 8;
10532 inst.instruction |= Rn << 16;
10533 inst.instruction |= Rm;
62b3e311
PB
10534}
10535
c19d1205
ZW
10536static void
10537do_t_hint (void)
10538{
10539 if (unified_syntax && inst.size_req == 4)
10540 inst.instruction = THUMB_OP32 (inst.instruction);
10541 else
10542 inst.instruction = THUMB_OP16 (inst.instruction);
10543}
90e4755a 10544
c19d1205
ZW
10545static void
10546do_t_it (void)
10547{
10548 unsigned int cond = inst.operands[0].imm;
e27ec89e 10549
e07e6e58
NC
10550 set_it_insn_type (IT_INSN);
10551 now_it.mask = (inst.instruction & 0xf) | 0x10;
10552 now_it.cc = cond;
5a01bb1d 10553 now_it.warn_deprecated = FALSE;
e27ec89e
PB
10554
10555 /* If the condition is a negative condition, invert the mask. */
c19d1205 10556 if ((cond & 0x1) == 0x0)
90e4755a 10557 {
c19d1205 10558 unsigned int mask = inst.instruction & 0x000f;
90e4755a 10559
c19d1205 10560 if ((mask & 0x7) == 0)
5a01bb1d
MGD
10561 {
10562 /* No conversion needed. */
10563 now_it.block_length = 1;
10564 }
c19d1205 10565 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
10566 {
10567 mask ^= 0x8;
10568 now_it.block_length = 2;
10569 }
e27ec89e 10570 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
10571 {
10572 mask ^= 0xC;
10573 now_it.block_length = 3;
10574 }
c19d1205 10575 else
5a01bb1d
MGD
10576 {
10577 mask ^= 0xE;
10578 now_it.block_length = 4;
10579 }
90e4755a 10580
e27ec89e
PB
10581 inst.instruction &= 0xfff0;
10582 inst.instruction |= mask;
c19d1205 10583 }
90e4755a 10584
c19d1205
ZW
10585 inst.instruction |= cond << 4;
10586}
90e4755a 10587
3c707909
PB
10588/* Helper function used for both push/pop and ldm/stm. */
10589static void
10590encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
10591{
10592 bfd_boolean load;
10593
10594 load = (inst.instruction & (1 << 20)) != 0;
10595
10596 if (mask & (1 << 13))
10597 inst.error = _("SP not allowed in register list");
1e5b0379
NC
10598
10599 if ((mask & (1 << base)) != 0
10600 && writeback)
10601 inst.error = _("having the base register in the register list when "
10602 "using write back is UNPREDICTABLE");
10603
3c707909
PB
10604 if (load)
10605 {
e07e6e58 10606 if (mask & (1 << 15))
477330fc
RM
10607 {
10608 if (mask & (1 << 14))
10609 inst.error = _("LR and PC should not both be in register list");
10610 else
10611 set_it_insn_type_last ();
10612 }
3c707909
PB
10613 }
10614 else
10615 {
10616 if (mask & (1 << 15))
10617 inst.error = _("PC not allowed in register list");
3c707909
PB
10618 }
10619
10620 if ((mask & (mask - 1)) == 0)
10621 {
10622 /* Single register transfers implemented as str/ldr. */
10623 if (writeback)
10624 {
10625 if (inst.instruction & (1 << 23))
10626 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
10627 else
10628 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
10629 }
10630 else
10631 {
10632 if (inst.instruction & (1 << 23))
10633 inst.instruction = 0x00800000; /* ia -> [base] */
10634 else
10635 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
10636 }
10637
10638 inst.instruction |= 0xf8400000;
10639 if (load)
10640 inst.instruction |= 0x00100000;
10641
5f4273c7 10642 mask = ffs (mask) - 1;
3c707909
PB
10643 mask <<= 12;
10644 }
10645 else if (writeback)
10646 inst.instruction |= WRITE_BACK;
10647
10648 inst.instruction |= mask;
10649 inst.instruction |= base << 16;
10650}
10651
c19d1205
ZW
10652static void
10653do_t_ldmstm (void)
10654{
10655 /* This really doesn't seem worth it. */
10656 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10657 _("expression too complex"));
10658 constraint (inst.operands[1].writeback,
10659 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 10660
c19d1205
ZW
10661 if (unified_syntax)
10662 {
3c707909
PB
10663 bfd_boolean narrow;
10664 unsigned mask;
10665
10666 narrow = FALSE;
c19d1205
ZW
10667 /* See if we can use a 16-bit instruction. */
10668 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
10669 && inst.size_req != 4
3c707909 10670 && !(inst.operands[1].imm & ~0xff))
90e4755a 10671 {
3c707909 10672 mask = 1 << inst.operands[0].reg;
90e4755a 10673
eab4f823 10674 if (inst.operands[0].reg <= 7)
90e4755a 10675 {
3c707909 10676 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
10677 ? inst.operands[0].writeback
10678 : (inst.operands[0].writeback
10679 == !(inst.operands[1].imm & mask)))
477330fc 10680 {
eab4f823
MGD
10681 if (inst.instruction == T_MNEM_stmia
10682 && (inst.operands[1].imm & mask)
10683 && (inst.operands[1].imm & (mask - 1)))
10684 as_warn (_("value stored for r%d is UNKNOWN"),
10685 inst.operands[0].reg);
3c707909 10686
eab4f823
MGD
10687 inst.instruction = THUMB_OP16 (inst.instruction);
10688 inst.instruction |= inst.operands[0].reg << 8;
10689 inst.instruction |= inst.operands[1].imm;
10690 narrow = TRUE;
10691 }
10692 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10693 {
10694 /* This means 1 register in reg list one of 3 situations:
10695 1. Instruction is stmia, but without writeback.
10696 2. lmdia without writeback, but with Rn not in
477330fc 10697 reglist.
eab4f823
MGD
10698 3. ldmia with writeback, but with Rn in reglist.
10699 Case 3 is UNPREDICTABLE behaviour, so we handle
10700 case 1 and 2 which can be converted into a 16-bit
10701 str or ldr. The SP cases are handled below. */
10702 unsigned long opcode;
10703 /* First, record an error for Case 3. */
10704 if (inst.operands[1].imm & mask
10705 && inst.operands[0].writeback)
fa94de6b 10706 inst.error =
eab4f823
MGD
10707 _("having the base register in the register list when "
10708 "using write back is UNPREDICTABLE");
fa94de6b
RM
10709
10710 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
10711 : T_MNEM_ldr);
10712 inst.instruction = THUMB_OP16 (opcode);
10713 inst.instruction |= inst.operands[0].reg << 3;
10714 inst.instruction |= (ffs (inst.operands[1].imm)-1);
10715 narrow = TRUE;
10716 }
90e4755a 10717 }
eab4f823 10718 else if (inst.operands[0] .reg == REG_SP)
90e4755a 10719 {
eab4f823
MGD
10720 if (inst.operands[0].writeback)
10721 {
fa94de6b 10722 inst.instruction =
eab4f823 10723 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 10724 ? T_MNEM_push : T_MNEM_pop);
eab4f823 10725 inst.instruction |= inst.operands[1].imm;
477330fc 10726 narrow = TRUE;
eab4f823
MGD
10727 }
10728 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10729 {
fa94de6b 10730 inst.instruction =
eab4f823 10731 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 10732 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 10733 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 10734 narrow = TRUE;
eab4f823 10735 }
90e4755a 10736 }
3c707909
PB
10737 }
10738
10739 if (!narrow)
10740 {
c19d1205
ZW
10741 if (inst.instruction < 0xffff)
10742 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 10743
5f4273c7
NC
10744 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10745 inst.operands[0].writeback);
90e4755a
RE
10746 }
10747 }
c19d1205 10748 else
90e4755a 10749 {
c19d1205
ZW
10750 constraint (inst.operands[0].reg > 7
10751 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
10752 constraint (inst.instruction != T_MNEM_ldmia
10753 && inst.instruction != T_MNEM_stmia,
10754 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 10755 if (inst.instruction == T_MNEM_stmia)
f03698e6 10756 {
c19d1205
ZW
10757 if (!inst.operands[0].writeback)
10758 as_warn (_("this instruction will write back the base register"));
10759 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10760 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 10761 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 10762 inst.operands[0].reg);
f03698e6 10763 }
c19d1205 10764 else
90e4755a 10765 {
c19d1205
ZW
10766 if (!inst.operands[0].writeback
10767 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10768 as_warn (_("this instruction will write back the base register"));
10769 else if (inst.operands[0].writeback
10770 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10771 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
10772 }
10773
c19d1205
ZW
10774 inst.instruction = THUMB_OP16 (inst.instruction);
10775 inst.instruction |= inst.operands[0].reg << 8;
10776 inst.instruction |= inst.operands[1].imm;
10777 }
10778}
e28cd48c 10779
c19d1205
ZW
10780static void
10781do_t_ldrex (void)
10782{
10783 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10784 || inst.operands[1].postind || inst.operands[1].writeback
10785 || inst.operands[1].immisreg || inst.operands[1].shifted
10786 || inst.operands[1].negative,
01cfc07f 10787 BAD_ADDR_MODE);
e28cd48c 10788
5be8be5d
DG
10789 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10790
c19d1205
ZW
10791 inst.instruction |= inst.operands[0].reg << 12;
10792 inst.instruction |= inst.operands[1].reg << 16;
10793 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10794}
e28cd48c 10795
c19d1205
ZW
10796static void
10797do_t_ldrexd (void)
10798{
10799 if (!inst.operands[1].present)
1cac9012 10800 {
c19d1205
ZW
10801 constraint (inst.operands[0].reg == REG_LR,
10802 _("r14 not allowed as first register "
10803 "when second register is omitted"));
10804 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 10805 }
c19d1205
ZW
10806 constraint (inst.operands[0].reg == inst.operands[1].reg,
10807 BAD_OVERLAP);
b99bd4ef 10808
c19d1205
ZW
10809 inst.instruction |= inst.operands[0].reg << 12;
10810 inst.instruction |= inst.operands[1].reg << 8;
10811 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10812}
10813
10814static void
c19d1205 10815do_t_ldst (void)
b99bd4ef 10816{
0110f2b8
PB
10817 unsigned long opcode;
10818 int Rn;
10819
e07e6e58
NC
10820 if (inst.operands[0].isreg
10821 && !inst.operands[0].preind
10822 && inst.operands[0].reg == REG_PC)
10823 set_it_insn_type_last ();
10824
0110f2b8 10825 opcode = inst.instruction;
c19d1205 10826 if (unified_syntax)
b99bd4ef 10827 {
53365c0d
PB
10828 if (!inst.operands[1].isreg)
10829 {
10830 if (opcode <= 0xffff)
10831 inst.instruction = THUMB_OP32 (opcode);
10832 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10833 return;
10834 }
0110f2b8
PB
10835 if (inst.operands[1].isreg
10836 && !inst.operands[1].writeback
c19d1205
ZW
10837 && !inst.operands[1].shifted && !inst.operands[1].postind
10838 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
10839 && opcode <= 0xffff
10840 && inst.size_req != 4)
c19d1205 10841 {
0110f2b8
PB
10842 /* Insn may have a 16-bit form. */
10843 Rn = inst.operands[1].reg;
10844 if (inst.operands[1].immisreg)
10845 {
10846 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 10847 /* [Rn, Rik] */
0110f2b8
PB
10848 if (Rn <= 7 && inst.operands[1].imm <= 7)
10849 goto op16;
5be8be5d
DG
10850 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10851 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
10852 }
10853 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10854 && opcode != T_MNEM_ldrsb)
10855 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10856 || (Rn == REG_SP && opcode == T_MNEM_str))
10857 {
10858 /* [Rn, #const] */
10859 if (Rn > 7)
10860 {
10861 if (Rn == REG_PC)
10862 {
10863 if (inst.reloc.pc_rel)
10864 opcode = T_MNEM_ldr_pc2;
10865 else
10866 opcode = T_MNEM_ldr_pc;
10867 }
10868 else
10869 {
10870 if (opcode == T_MNEM_ldr)
10871 opcode = T_MNEM_ldr_sp;
10872 else
10873 opcode = T_MNEM_str_sp;
10874 }
10875 inst.instruction = inst.operands[0].reg << 8;
10876 }
10877 else
10878 {
10879 inst.instruction = inst.operands[0].reg;
10880 inst.instruction |= inst.operands[1].reg << 3;
10881 }
10882 inst.instruction |= THUMB_OP16 (opcode);
10883 if (inst.size_req == 2)
10884 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10885 else
10886 inst.relax = opcode;
10887 return;
10888 }
c19d1205 10889 }
0110f2b8 10890 /* Definitely a 32-bit variant. */
5be8be5d 10891
8d67f500
NC
10892 /* Warning for Erratum 752419. */
10893 if (opcode == T_MNEM_ldr
10894 && inst.operands[0].reg == REG_SP
10895 && inst.operands[1].writeback == 1
10896 && !inst.operands[1].immisreg)
10897 {
10898 if (no_cpu_selected ()
10899 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
10900 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
10901 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
10902 as_warn (_("This instruction may be unpredictable "
10903 "if executed on M-profile cores "
10904 "with interrupts enabled."));
10905 }
10906
5be8be5d 10907 /* Do some validations regarding addressing modes. */
1be5fd2e 10908 if (inst.operands[1].immisreg)
5be8be5d
DG
10909 reject_bad_reg (inst.operands[1].imm);
10910
1be5fd2e
NC
10911 constraint (inst.operands[1].writeback == 1
10912 && inst.operands[0].reg == inst.operands[1].reg,
10913 BAD_OVERLAP);
10914
0110f2b8 10915 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
10916 inst.instruction |= inst.operands[0].reg << 12;
10917 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 10918 check_ldr_r15_aligned ();
b99bd4ef
NC
10919 return;
10920 }
10921
c19d1205
ZW
10922 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10923
10924 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 10925 {
c19d1205
ZW
10926 /* Only [Rn,Rm] is acceptable. */
10927 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10928 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10929 || inst.operands[1].postind || inst.operands[1].shifted
10930 || inst.operands[1].negative,
10931 _("Thumb does not support this addressing mode"));
10932 inst.instruction = THUMB_OP16 (inst.instruction);
10933 goto op16;
b99bd4ef 10934 }
5f4273c7 10935
c19d1205
ZW
10936 inst.instruction = THUMB_OP16 (inst.instruction);
10937 if (!inst.operands[1].isreg)
10938 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10939 return;
b99bd4ef 10940
c19d1205
ZW
10941 constraint (!inst.operands[1].preind
10942 || inst.operands[1].shifted
10943 || inst.operands[1].writeback,
10944 _("Thumb does not support this addressing mode"));
10945 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 10946 {
c19d1205
ZW
10947 constraint (inst.instruction & 0x0600,
10948 _("byte or halfword not valid for base register"));
10949 constraint (inst.operands[1].reg == REG_PC
10950 && !(inst.instruction & THUMB_LOAD_BIT),
10951 _("r15 based store not allowed"));
10952 constraint (inst.operands[1].immisreg,
10953 _("invalid base register for register offset"));
b99bd4ef 10954
c19d1205
ZW
10955 if (inst.operands[1].reg == REG_PC)
10956 inst.instruction = T_OPCODE_LDR_PC;
10957 else if (inst.instruction & THUMB_LOAD_BIT)
10958 inst.instruction = T_OPCODE_LDR_SP;
10959 else
10960 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 10961
c19d1205
ZW
10962 inst.instruction |= inst.operands[0].reg << 8;
10963 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10964 return;
10965 }
90e4755a 10966
c19d1205
ZW
10967 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10968 if (!inst.operands[1].immisreg)
10969 {
10970 /* Immediate offset. */
10971 inst.instruction |= inst.operands[0].reg;
10972 inst.instruction |= inst.operands[1].reg << 3;
10973 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10974 return;
10975 }
90e4755a 10976
c19d1205
ZW
10977 /* Register offset. */
10978 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10979 constraint (inst.operands[1].negative,
10980 _("Thumb does not support this addressing mode"));
90e4755a 10981
c19d1205
ZW
10982 op16:
10983 switch (inst.instruction)
10984 {
10985 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10986 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10987 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10988 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10989 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10990 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10991 case 0x5600 /* ldrsb */:
10992 case 0x5e00 /* ldrsh */: break;
10993 default: abort ();
10994 }
90e4755a 10995
c19d1205
ZW
10996 inst.instruction |= inst.operands[0].reg;
10997 inst.instruction |= inst.operands[1].reg << 3;
10998 inst.instruction |= inst.operands[1].imm << 6;
10999}
90e4755a 11000
c19d1205
ZW
11001static void
11002do_t_ldstd (void)
11003{
11004 if (!inst.operands[1].present)
b99bd4ef 11005 {
c19d1205
ZW
11006 inst.operands[1].reg = inst.operands[0].reg + 1;
11007 constraint (inst.operands[0].reg == REG_LR,
11008 _("r14 not allowed here"));
bd340a04 11009 constraint (inst.operands[0].reg == REG_R12,
477330fc 11010 _("r12 not allowed here"));
b99bd4ef 11011 }
bd340a04
MGD
11012
11013 if (inst.operands[2].writeback
11014 && (inst.operands[0].reg == inst.operands[2].reg
11015 || inst.operands[1].reg == inst.operands[2].reg))
11016 as_warn (_("base register written back, and overlaps "
477330fc 11017 "one of transfer registers"));
bd340a04 11018
c19d1205
ZW
11019 inst.instruction |= inst.operands[0].reg << 12;
11020 inst.instruction |= inst.operands[1].reg << 8;
11021 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11022}
11023
c19d1205
ZW
11024static void
11025do_t_ldstt (void)
11026{
11027 inst.instruction |= inst.operands[0].reg << 12;
11028 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11029}
a737bd4d 11030
b99bd4ef 11031static void
c19d1205 11032do_t_mla (void)
b99bd4ef 11033{
fdfde340 11034 unsigned Rd, Rn, Rm, Ra;
c921be7d 11035
fdfde340
JM
11036 Rd = inst.operands[0].reg;
11037 Rn = inst.operands[1].reg;
11038 Rm = inst.operands[2].reg;
11039 Ra = inst.operands[3].reg;
11040
11041 reject_bad_reg (Rd);
11042 reject_bad_reg (Rn);
11043 reject_bad_reg (Rm);
11044 reject_bad_reg (Ra);
11045
11046 inst.instruction |= Rd << 8;
11047 inst.instruction |= Rn << 16;
11048 inst.instruction |= Rm;
11049 inst.instruction |= Ra << 12;
c19d1205 11050}
b99bd4ef 11051
c19d1205
ZW
11052static void
11053do_t_mlal (void)
11054{
fdfde340
JM
11055 unsigned RdLo, RdHi, Rn, Rm;
11056
11057 RdLo = inst.operands[0].reg;
11058 RdHi = inst.operands[1].reg;
11059 Rn = inst.operands[2].reg;
11060 Rm = inst.operands[3].reg;
11061
11062 reject_bad_reg (RdLo);
11063 reject_bad_reg (RdHi);
11064 reject_bad_reg (Rn);
11065 reject_bad_reg (Rm);
11066
11067 inst.instruction |= RdLo << 12;
11068 inst.instruction |= RdHi << 8;
11069 inst.instruction |= Rn << 16;
11070 inst.instruction |= Rm;
c19d1205 11071}
b99bd4ef 11072
c19d1205
ZW
11073static void
11074do_t_mov_cmp (void)
11075{
fdfde340
JM
11076 unsigned Rn, Rm;
11077
11078 Rn = inst.operands[0].reg;
11079 Rm = inst.operands[1].reg;
11080
e07e6e58
NC
11081 if (Rn == REG_PC)
11082 set_it_insn_type_last ();
11083
c19d1205 11084 if (unified_syntax)
b99bd4ef 11085 {
c19d1205
ZW
11086 int r0off = (inst.instruction == T_MNEM_mov
11087 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11088 unsigned long opcode;
3d388997
PB
11089 bfd_boolean narrow;
11090 bfd_boolean low_regs;
11091
fdfde340 11092 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11093 opcode = inst.instruction;
e07e6e58 11094 if (in_it_block ())
0110f2b8 11095 narrow = opcode != T_MNEM_movs;
3d388997 11096 else
0110f2b8 11097 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11098 if (inst.size_req == 4
11099 || inst.operands[1].shifted)
11100 narrow = FALSE;
11101
efd81785
PB
11102 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11103 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11104 && !inst.operands[1].shifted
fdfde340
JM
11105 && Rn == REG_PC
11106 && Rm == REG_LR)
efd81785
PB
11107 {
11108 inst.instruction = T2_SUBS_PC_LR;
11109 return;
11110 }
11111
fdfde340
JM
11112 if (opcode == T_MNEM_cmp)
11113 {
11114 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11115 if (narrow)
11116 {
11117 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11118 but valid. */
11119 warn_deprecated_sp (Rm);
11120 /* R15 was documented as a valid choice for Rm in ARMv6,
11121 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11122 tools reject R15, so we do too. */
11123 constraint (Rm == REG_PC, BAD_PC);
11124 }
11125 else
11126 reject_bad_reg (Rm);
fdfde340
JM
11127 }
11128 else if (opcode == T_MNEM_mov
11129 || opcode == T_MNEM_movs)
11130 {
11131 if (inst.operands[1].isreg)
11132 {
11133 if (opcode == T_MNEM_movs)
11134 {
11135 reject_bad_reg (Rn);
11136 reject_bad_reg (Rm);
11137 }
76fa04a4
MGD
11138 else if (narrow)
11139 {
11140 /* This is mov.n. */
11141 if ((Rn == REG_SP || Rn == REG_PC)
11142 && (Rm == REG_SP || Rm == REG_PC))
11143 {
11144 as_warn (_("Use of r%u as a source register is "
11145 "deprecated when r%u is the destination "
11146 "register."), Rm, Rn);
11147 }
11148 }
11149 else
11150 {
11151 /* This is mov.w. */
11152 constraint (Rn == REG_PC, BAD_PC);
11153 constraint (Rm == REG_PC, BAD_PC);
11154 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11155 }
fdfde340
JM
11156 }
11157 else
11158 reject_bad_reg (Rn);
11159 }
11160
c19d1205
ZW
11161 if (!inst.operands[1].isreg)
11162 {
0110f2b8 11163 /* Immediate operand. */
e07e6e58 11164 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11165 narrow = 0;
11166 if (low_regs && narrow)
11167 {
11168 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11169 inst.instruction |= Rn << 8;
0110f2b8
PB
11170 if (inst.size_req == 2)
11171 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11172 else
11173 inst.relax = opcode;
11174 }
11175 else
11176 {
11177 inst.instruction = THUMB_OP32 (inst.instruction);
11178 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11179 inst.instruction |= Rn << r0off;
0110f2b8
PB
11180 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11181 }
c19d1205 11182 }
728ca7c9
PB
11183 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11184 && (inst.instruction == T_MNEM_mov
11185 || inst.instruction == T_MNEM_movs))
11186 {
11187 /* Register shifts are encoded as separate shift instructions. */
11188 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11189
e07e6e58 11190 if (in_it_block ())
728ca7c9
PB
11191 narrow = !flags;
11192 else
11193 narrow = flags;
11194
11195 if (inst.size_req == 4)
11196 narrow = FALSE;
11197
11198 if (!low_regs || inst.operands[1].imm > 7)
11199 narrow = FALSE;
11200
fdfde340 11201 if (Rn != Rm)
728ca7c9
PB
11202 narrow = FALSE;
11203
11204 switch (inst.operands[1].shift_kind)
11205 {
11206 case SHIFT_LSL:
11207 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11208 break;
11209 case SHIFT_ASR:
11210 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11211 break;
11212 case SHIFT_LSR:
11213 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11214 break;
11215 case SHIFT_ROR:
11216 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11217 break;
11218 default:
5f4273c7 11219 abort ();
728ca7c9
PB
11220 }
11221
11222 inst.instruction = opcode;
11223 if (narrow)
11224 {
fdfde340 11225 inst.instruction |= Rn;
728ca7c9
PB
11226 inst.instruction |= inst.operands[1].imm << 3;
11227 }
11228 else
11229 {
11230 if (flags)
11231 inst.instruction |= CONDS_BIT;
11232
fdfde340
JM
11233 inst.instruction |= Rn << 8;
11234 inst.instruction |= Rm << 16;
728ca7c9
PB
11235 inst.instruction |= inst.operands[1].imm;
11236 }
11237 }
3d388997 11238 else if (!narrow)
c19d1205 11239 {
728ca7c9
PB
11240 /* Some mov with immediate shift have narrow variants.
11241 Register shifts are handled above. */
11242 if (low_regs && inst.operands[1].shifted
11243 && (inst.instruction == T_MNEM_mov
11244 || inst.instruction == T_MNEM_movs))
11245 {
e07e6e58 11246 if (in_it_block ())
728ca7c9
PB
11247 narrow = (inst.instruction == T_MNEM_mov);
11248 else
11249 narrow = (inst.instruction == T_MNEM_movs);
11250 }
11251
11252 if (narrow)
11253 {
11254 switch (inst.operands[1].shift_kind)
11255 {
11256 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11257 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11258 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11259 default: narrow = FALSE; break;
11260 }
11261 }
11262
11263 if (narrow)
11264 {
fdfde340
JM
11265 inst.instruction |= Rn;
11266 inst.instruction |= Rm << 3;
728ca7c9
PB
11267 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11268 }
11269 else
11270 {
11271 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11272 inst.instruction |= Rn << r0off;
728ca7c9
PB
11273 encode_thumb32_shifted_operand (1);
11274 }
c19d1205
ZW
11275 }
11276 else
11277 switch (inst.instruction)
11278 {
11279 case T_MNEM_mov:
837b3435 11280 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
11281 results. Don't allow this. */
11282 if (low_regs)
11283 {
11284 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11285 "MOV Rd, Rs with two low registers is not "
11286 "permitted on this architecture");
fa94de6b 11287 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
11288 arm_ext_v6);
11289 }
11290
c19d1205 11291 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
11292 inst.instruction |= (Rn & 0x8) << 4;
11293 inst.instruction |= (Rn & 0x7);
11294 inst.instruction |= Rm << 3;
c19d1205 11295 break;
b99bd4ef 11296
c19d1205
ZW
11297 case T_MNEM_movs:
11298 /* We know we have low registers at this point.
941a8a52
MGD
11299 Generate LSLS Rd, Rs, #0. */
11300 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
11301 inst.instruction |= Rn;
11302 inst.instruction |= Rm << 3;
c19d1205
ZW
11303 break;
11304
11305 case T_MNEM_cmp:
3d388997 11306 if (low_regs)
c19d1205
ZW
11307 {
11308 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
11309 inst.instruction |= Rn;
11310 inst.instruction |= Rm << 3;
c19d1205
ZW
11311 }
11312 else
11313 {
11314 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
11315 inst.instruction |= (Rn & 0x8) << 4;
11316 inst.instruction |= (Rn & 0x7);
11317 inst.instruction |= Rm << 3;
c19d1205
ZW
11318 }
11319 break;
11320 }
b99bd4ef
NC
11321 return;
11322 }
11323
c19d1205 11324 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
11325
11326 /* PR 10443: Do not silently ignore shifted operands. */
11327 constraint (inst.operands[1].shifted,
11328 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
11329
c19d1205 11330 if (inst.operands[1].isreg)
b99bd4ef 11331 {
fdfde340 11332 if (Rn < 8 && Rm < 8)
b99bd4ef 11333 {
c19d1205
ZW
11334 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11335 since a MOV instruction produces unpredictable results. */
11336 if (inst.instruction == T_OPCODE_MOV_I8)
11337 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 11338 else
c19d1205 11339 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 11340
fdfde340
JM
11341 inst.instruction |= Rn;
11342 inst.instruction |= Rm << 3;
b99bd4ef
NC
11343 }
11344 else
11345 {
c19d1205
ZW
11346 if (inst.instruction == T_OPCODE_MOV_I8)
11347 inst.instruction = T_OPCODE_MOV_HR;
11348 else
11349 inst.instruction = T_OPCODE_CMP_HR;
11350 do_t_cpy ();
b99bd4ef
NC
11351 }
11352 }
c19d1205 11353 else
b99bd4ef 11354 {
fdfde340 11355 constraint (Rn > 7,
c19d1205 11356 _("only lo regs allowed with immediate"));
fdfde340 11357 inst.instruction |= Rn << 8;
c19d1205
ZW
11358 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11359 }
11360}
b99bd4ef 11361
c19d1205
ZW
11362static void
11363do_t_mov16 (void)
11364{
fdfde340 11365 unsigned Rd;
b6895b4f
PB
11366 bfd_vma imm;
11367 bfd_boolean top;
11368
11369 top = (inst.instruction & 0x00800000) != 0;
11370 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
11371 {
11372 constraint (top, _(":lower16: not allowed this instruction"));
11373 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
11374 }
11375 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
11376 {
11377 constraint (!top, _(":upper16: not allowed this instruction"));
11378 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
11379 }
11380
fdfde340
JM
11381 Rd = inst.operands[0].reg;
11382 reject_bad_reg (Rd);
11383
11384 inst.instruction |= Rd << 8;
b6895b4f
PB
11385 if (inst.reloc.type == BFD_RELOC_UNUSED)
11386 {
11387 imm = inst.reloc.exp.X_add_number;
11388 inst.instruction |= (imm & 0xf000) << 4;
11389 inst.instruction |= (imm & 0x0800) << 15;
11390 inst.instruction |= (imm & 0x0700) << 4;
11391 inst.instruction |= (imm & 0x00ff);
11392 }
c19d1205 11393}
b99bd4ef 11394
c19d1205
ZW
11395static void
11396do_t_mvn_tst (void)
11397{
fdfde340 11398 unsigned Rn, Rm;
c921be7d 11399
fdfde340
JM
11400 Rn = inst.operands[0].reg;
11401 Rm = inst.operands[1].reg;
11402
11403 if (inst.instruction == T_MNEM_cmp
11404 || inst.instruction == T_MNEM_cmn)
11405 constraint (Rn == REG_PC, BAD_PC);
11406 else
11407 reject_bad_reg (Rn);
11408 reject_bad_reg (Rm);
11409
c19d1205
ZW
11410 if (unified_syntax)
11411 {
11412 int r0off = (inst.instruction == T_MNEM_mvn
11413 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
11414 bfd_boolean narrow;
11415
11416 if (inst.size_req == 4
11417 || inst.instruction > 0xffff
11418 || inst.operands[1].shifted
fdfde340 11419 || Rn > 7 || Rm > 7)
3d388997 11420 narrow = FALSE;
fe8b4cc3
KT
11421 else if (inst.instruction == T_MNEM_cmn
11422 || inst.instruction == T_MNEM_tst)
3d388997
PB
11423 narrow = TRUE;
11424 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11425 narrow = !in_it_block ();
3d388997 11426 else
e07e6e58 11427 narrow = in_it_block ();
3d388997 11428
c19d1205 11429 if (!inst.operands[1].isreg)
b99bd4ef 11430 {
c19d1205
ZW
11431 /* For an immediate, we always generate a 32-bit opcode;
11432 section relaxation will shrink it later if possible. */
11433 if (inst.instruction < 0xffff)
11434 inst.instruction = THUMB_OP32 (inst.instruction);
11435 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11436 inst.instruction |= Rn << r0off;
c19d1205 11437 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11438 }
c19d1205 11439 else
b99bd4ef 11440 {
c19d1205 11441 /* See if we can do this with a 16-bit instruction. */
3d388997 11442 if (narrow)
b99bd4ef 11443 {
c19d1205 11444 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11445 inst.instruction |= Rn;
11446 inst.instruction |= Rm << 3;
b99bd4ef 11447 }
c19d1205 11448 else
b99bd4ef 11449 {
c19d1205
ZW
11450 constraint (inst.operands[1].shifted
11451 && inst.operands[1].immisreg,
11452 _("shift must be constant"));
11453 if (inst.instruction < 0xffff)
11454 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11455 inst.instruction |= Rn << r0off;
c19d1205 11456 encode_thumb32_shifted_operand (1);
b99bd4ef 11457 }
b99bd4ef
NC
11458 }
11459 }
11460 else
11461 {
c19d1205
ZW
11462 constraint (inst.instruction > 0xffff
11463 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
11464 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
11465 _("unshifted register required"));
fdfde340 11466 constraint (Rn > 7 || Rm > 7,
c19d1205 11467 BAD_HIREG);
b99bd4ef 11468
c19d1205 11469 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11470 inst.instruction |= Rn;
11471 inst.instruction |= Rm << 3;
b99bd4ef 11472 }
b99bd4ef
NC
11473}
11474
b05fe5cf 11475static void
c19d1205 11476do_t_mrs (void)
b05fe5cf 11477{
fdfde340 11478 unsigned Rd;
037e8744
JB
11479
11480 if (do_vfp_nsyn_mrs () == SUCCESS)
11481 return;
11482
90ec0d68
MGD
11483 Rd = inst.operands[0].reg;
11484 reject_bad_reg (Rd);
11485 inst.instruction |= Rd << 8;
11486
11487 if (inst.operands[1].isreg)
62b3e311 11488 {
90ec0d68
MGD
11489 unsigned br = inst.operands[1].reg;
11490 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
11491 as_bad (_("bad register for mrs"));
11492
11493 inst.instruction |= br & (0xf << 16);
11494 inst.instruction |= (br & 0x300) >> 4;
11495 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
11496 }
11497 else
11498 {
90ec0d68 11499 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 11500
d2cd1205 11501 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
11502 {
11503 /* PR gas/12698: The constraint is only applied for m_profile.
11504 If the user has specified -march=all, we want to ignore it as
11505 we are building for any CPU type, including non-m variants. */
11506 bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core;
11507 constraint ((flags != 0) && m_profile, _("selected processor does "
11508 "not support requested special purpose register"));
11509 }
90ec0d68 11510 else
d2cd1205
JB
11511 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
11512 devices). */
11513 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
11514 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 11515
90ec0d68
MGD
11516 inst.instruction |= (flags & SPSR_BIT) >> 2;
11517 inst.instruction |= inst.operands[1].imm & 0xff;
11518 inst.instruction |= 0xf0000;
11519 }
c19d1205 11520}
b05fe5cf 11521
c19d1205
ZW
11522static void
11523do_t_msr (void)
11524{
62b3e311 11525 int flags;
fdfde340 11526 unsigned Rn;
62b3e311 11527
037e8744
JB
11528 if (do_vfp_nsyn_msr () == SUCCESS)
11529 return;
11530
c19d1205
ZW
11531 constraint (!inst.operands[1].isreg,
11532 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
11533
11534 if (inst.operands[0].isreg)
11535 flags = (int)(inst.operands[0].reg);
11536 else
11537 flags = inst.operands[0].imm;
11538
d2cd1205 11539 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 11540 {
d2cd1205
JB
11541 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11542
1a43faaf 11543 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
11544 If the user has specified -march=all, we want to ignore it as
11545 we are building for any CPU type, including non-m variants. */
1a43faaf
NC
11546 bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core;
11547 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
11548 && (bits & ~(PSR_s | PSR_f)) != 0)
11549 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11550 && bits != PSR_f)) && m_profile,
11551 _("selected processor does not support requested special "
11552 "purpose register"));
62b3e311
PB
11553 }
11554 else
d2cd1205
JB
11555 constraint ((flags & 0xff) != 0, _("selected processor does not support "
11556 "requested special purpose register"));
c921be7d 11557
fdfde340
JM
11558 Rn = inst.operands[1].reg;
11559 reject_bad_reg (Rn);
11560
62b3e311 11561 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
11562 inst.instruction |= (flags & 0xf0000) >> 8;
11563 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 11564 inst.instruction |= (flags & 0xff);
fdfde340 11565 inst.instruction |= Rn << 16;
c19d1205 11566}
b05fe5cf 11567
c19d1205
ZW
11568static void
11569do_t_mul (void)
11570{
17828f45 11571 bfd_boolean narrow;
fdfde340 11572 unsigned Rd, Rn, Rm;
17828f45 11573
c19d1205
ZW
11574 if (!inst.operands[2].present)
11575 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 11576
fdfde340
JM
11577 Rd = inst.operands[0].reg;
11578 Rn = inst.operands[1].reg;
11579 Rm = inst.operands[2].reg;
11580
17828f45 11581 if (unified_syntax)
b05fe5cf 11582 {
17828f45 11583 if (inst.size_req == 4
fdfde340
JM
11584 || (Rd != Rn
11585 && Rd != Rm)
11586 || Rn > 7
11587 || Rm > 7)
17828f45
JM
11588 narrow = FALSE;
11589 else if (inst.instruction == T_MNEM_muls)
e07e6e58 11590 narrow = !in_it_block ();
17828f45 11591 else
e07e6e58 11592 narrow = in_it_block ();
b05fe5cf 11593 }
c19d1205 11594 else
b05fe5cf 11595 {
17828f45 11596 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 11597 constraint (Rn > 7 || Rm > 7,
c19d1205 11598 BAD_HIREG);
17828f45
JM
11599 narrow = TRUE;
11600 }
b05fe5cf 11601
17828f45
JM
11602 if (narrow)
11603 {
11604 /* 16-bit MULS/Conditional MUL. */
c19d1205 11605 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11606 inst.instruction |= Rd;
b05fe5cf 11607
fdfde340
JM
11608 if (Rd == Rn)
11609 inst.instruction |= Rm << 3;
11610 else if (Rd == Rm)
11611 inst.instruction |= Rn << 3;
c19d1205
ZW
11612 else
11613 constraint (1, _("dest must overlap one source register"));
11614 }
17828f45
JM
11615 else
11616 {
e07e6e58
NC
11617 constraint (inst.instruction != T_MNEM_mul,
11618 _("Thumb-2 MUL must not set flags"));
17828f45
JM
11619 /* 32-bit MUL. */
11620 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11621 inst.instruction |= Rd << 8;
11622 inst.instruction |= Rn << 16;
11623 inst.instruction |= Rm << 0;
11624
11625 reject_bad_reg (Rd);
11626 reject_bad_reg (Rn);
11627 reject_bad_reg (Rm);
17828f45 11628 }
c19d1205 11629}
b05fe5cf 11630
c19d1205
ZW
11631static void
11632do_t_mull (void)
11633{
fdfde340 11634 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 11635
fdfde340
JM
11636 RdLo = inst.operands[0].reg;
11637 RdHi = inst.operands[1].reg;
11638 Rn = inst.operands[2].reg;
11639 Rm = inst.operands[3].reg;
11640
11641 reject_bad_reg (RdLo);
11642 reject_bad_reg (RdHi);
11643 reject_bad_reg (Rn);
11644 reject_bad_reg (Rm);
11645
11646 inst.instruction |= RdLo << 12;
11647 inst.instruction |= RdHi << 8;
11648 inst.instruction |= Rn << 16;
11649 inst.instruction |= Rm;
11650
11651 if (RdLo == RdHi)
c19d1205
ZW
11652 as_tsktsk (_("rdhi and rdlo must be different"));
11653}
b05fe5cf 11654
c19d1205
ZW
11655static void
11656do_t_nop (void)
11657{
e07e6e58
NC
11658 set_it_insn_type (NEUTRAL_IT_INSN);
11659
c19d1205
ZW
11660 if (unified_syntax)
11661 {
11662 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 11663 {
c19d1205
ZW
11664 inst.instruction = THUMB_OP32 (inst.instruction);
11665 inst.instruction |= inst.operands[0].imm;
11666 }
11667 else
11668 {
bc2d1808
NC
11669 /* PR9722: Check for Thumb2 availability before
11670 generating a thumb2 nop instruction. */
afa62d5e 11671 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
11672 {
11673 inst.instruction = THUMB_OP16 (inst.instruction);
11674 inst.instruction |= inst.operands[0].imm << 4;
11675 }
11676 else
11677 inst.instruction = 0x46c0;
c19d1205
ZW
11678 }
11679 }
11680 else
11681 {
11682 constraint (inst.operands[0].present,
11683 _("Thumb does not support NOP with hints"));
11684 inst.instruction = 0x46c0;
11685 }
11686}
b05fe5cf 11687
c19d1205
ZW
11688static void
11689do_t_neg (void)
11690{
11691 if (unified_syntax)
11692 {
3d388997
PB
11693 bfd_boolean narrow;
11694
11695 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11696 narrow = !in_it_block ();
3d388997 11697 else
e07e6e58 11698 narrow = in_it_block ();
3d388997
PB
11699 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11700 narrow = FALSE;
11701 if (inst.size_req == 4)
11702 narrow = FALSE;
11703
11704 if (!narrow)
c19d1205
ZW
11705 {
11706 inst.instruction = THUMB_OP32 (inst.instruction);
11707 inst.instruction |= inst.operands[0].reg << 8;
11708 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
11709 }
11710 else
11711 {
c19d1205
ZW
11712 inst.instruction = THUMB_OP16 (inst.instruction);
11713 inst.instruction |= inst.operands[0].reg;
11714 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
11715 }
11716 }
11717 else
11718 {
c19d1205
ZW
11719 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
11720 BAD_HIREG);
11721 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11722
11723 inst.instruction = THUMB_OP16 (inst.instruction);
11724 inst.instruction |= inst.operands[0].reg;
11725 inst.instruction |= inst.operands[1].reg << 3;
11726 }
11727}
11728
1c444d06
JM
11729static void
11730do_t_orn (void)
11731{
11732 unsigned Rd, Rn;
11733
11734 Rd = inst.operands[0].reg;
11735 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
11736
fdfde340
JM
11737 reject_bad_reg (Rd);
11738 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
11739 reject_bad_reg (Rn);
11740
1c444d06
JM
11741 inst.instruction |= Rd << 8;
11742 inst.instruction |= Rn << 16;
11743
11744 if (!inst.operands[2].isreg)
11745 {
11746 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11747 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11748 }
11749 else
11750 {
11751 unsigned Rm;
11752
11753 Rm = inst.operands[2].reg;
fdfde340 11754 reject_bad_reg (Rm);
1c444d06
JM
11755
11756 constraint (inst.operands[2].shifted
11757 && inst.operands[2].immisreg,
11758 _("shift must be constant"));
11759 encode_thumb32_shifted_operand (2);
11760 }
11761}
11762
c19d1205
ZW
11763static void
11764do_t_pkhbt (void)
11765{
fdfde340
JM
11766 unsigned Rd, Rn, Rm;
11767
11768 Rd = inst.operands[0].reg;
11769 Rn = inst.operands[1].reg;
11770 Rm = inst.operands[2].reg;
11771
11772 reject_bad_reg (Rd);
11773 reject_bad_reg (Rn);
11774 reject_bad_reg (Rm);
11775
11776 inst.instruction |= Rd << 8;
11777 inst.instruction |= Rn << 16;
11778 inst.instruction |= Rm;
c19d1205
ZW
11779 if (inst.operands[3].present)
11780 {
11781 unsigned int val = inst.reloc.exp.X_add_number;
11782 constraint (inst.reloc.exp.X_op != O_constant,
11783 _("expression too complex"));
11784 inst.instruction |= (val & 0x1c) << 10;
11785 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 11786 }
c19d1205 11787}
b05fe5cf 11788
c19d1205
ZW
11789static void
11790do_t_pkhtb (void)
11791{
11792 if (!inst.operands[3].present)
1ef52f49
NC
11793 {
11794 unsigned Rtmp;
11795
11796 inst.instruction &= ~0x00000020;
11797
11798 /* PR 10168. Swap the Rm and Rn registers. */
11799 Rtmp = inst.operands[1].reg;
11800 inst.operands[1].reg = inst.operands[2].reg;
11801 inst.operands[2].reg = Rtmp;
11802 }
c19d1205 11803 do_t_pkhbt ();
b05fe5cf
ZW
11804}
11805
c19d1205
ZW
11806static void
11807do_t_pld (void)
11808{
fdfde340
JM
11809 if (inst.operands[0].immisreg)
11810 reject_bad_reg (inst.operands[0].imm);
11811
c19d1205
ZW
11812 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11813}
b05fe5cf 11814
c19d1205
ZW
11815static void
11816do_t_push_pop (void)
b99bd4ef 11817{
e9f89963 11818 unsigned mask;
5f4273c7 11819
c19d1205
ZW
11820 constraint (inst.operands[0].writeback,
11821 _("push/pop do not support {reglist}^"));
11822 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11823 _("expression too complex"));
b99bd4ef 11824
e9f89963 11825 mask = inst.operands[0].imm;
d3bfe16e 11826 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 11827 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e
JB
11828 else if (inst.size_req != 4
11829 && (mask & ~0xff) == (1 << (inst.instruction == T_MNEM_push
11830 ? REG_LR : REG_PC)))
b99bd4ef 11831 {
c19d1205
ZW
11832 inst.instruction = THUMB_OP16 (inst.instruction);
11833 inst.instruction |= THUMB_PP_PC_LR;
3c707909 11834 inst.instruction |= mask & 0xff;
c19d1205
ZW
11835 }
11836 else if (unified_syntax)
11837 {
3c707909 11838 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 11839 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
11840 }
11841 else
11842 {
11843 inst.error = _("invalid register list to push/pop instruction");
11844 return;
11845 }
c19d1205 11846}
b99bd4ef 11847
c19d1205
ZW
11848static void
11849do_t_rbit (void)
11850{
fdfde340
JM
11851 unsigned Rd, Rm;
11852
11853 Rd = inst.operands[0].reg;
11854 Rm = inst.operands[1].reg;
11855
11856 reject_bad_reg (Rd);
11857 reject_bad_reg (Rm);
11858
11859 inst.instruction |= Rd << 8;
11860 inst.instruction |= Rm << 16;
11861 inst.instruction |= Rm;
c19d1205 11862}
b99bd4ef 11863
c19d1205
ZW
11864static void
11865do_t_rev (void)
11866{
fdfde340
JM
11867 unsigned Rd, Rm;
11868
11869 Rd = inst.operands[0].reg;
11870 Rm = inst.operands[1].reg;
11871
11872 reject_bad_reg (Rd);
11873 reject_bad_reg (Rm);
11874
11875 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
11876 && inst.size_req != 4)
11877 {
11878 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11879 inst.instruction |= Rd;
11880 inst.instruction |= Rm << 3;
c19d1205
ZW
11881 }
11882 else if (unified_syntax)
11883 {
11884 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11885 inst.instruction |= Rd << 8;
11886 inst.instruction |= Rm << 16;
11887 inst.instruction |= Rm;
c19d1205
ZW
11888 }
11889 else
11890 inst.error = BAD_HIREG;
11891}
b99bd4ef 11892
1c444d06
JM
11893static void
11894do_t_rrx (void)
11895{
11896 unsigned Rd, Rm;
11897
11898 Rd = inst.operands[0].reg;
11899 Rm = inst.operands[1].reg;
11900
fdfde340
JM
11901 reject_bad_reg (Rd);
11902 reject_bad_reg (Rm);
c921be7d 11903
1c444d06
JM
11904 inst.instruction |= Rd << 8;
11905 inst.instruction |= Rm;
11906}
11907
c19d1205
ZW
11908static void
11909do_t_rsb (void)
11910{
fdfde340 11911 unsigned Rd, Rs;
b99bd4ef 11912
c19d1205
ZW
11913 Rd = inst.operands[0].reg;
11914 Rs = (inst.operands[1].present
11915 ? inst.operands[1].reg /* Rd, Rs, foo */
11916 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 11917
fdfde340
JM
11918 reject_bad_reg (Rd);
11919 reject_bad_reg (Rs);
11920 if (inst.operands[2].isreg)
11921 reject_bad_reg (inst.operands[2].reg);
11922
c19d1205
ZW
11923 inst.instruction |= Rd << 8;
11924 inst.instruction |= Rs << 16;
11925 if (!inst.operands[2].isreg)
11926 {
026d3abb
PB
11927 bfd_boolean narrow;
11928
11929 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 11930 narrow = !in_it_block ();
026d3abb 11931 else
e07e6e58 11932 narrow = in_it_block ();
026d3abb
PB
11933
11934 if (Rd > 7 || Rs > 7)
11935 narrow = FALSE;
11936
11937 if (inst.size_req == 4 || !unified_syntax)
11938 narrow = FALSE;
11939
11940 if (inst.reloc.exp.X_op != O_constant
11941 || inst.reloc.exp.X_add_number != 0)
11942 narrow = FALSE;
11943
11944 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 11945 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
11946 if (narrow)
11947 {
11948 inst.reloc.type = BFD_RELOC_UNUSED;
11949 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11950 inst.instruction |= Rs << 3;
11951 inst.instruction |= Rd;
11952 }
11953 else
11954 {
11955 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11956 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11957 }
c19d1205
ZW
11958 }
11959 else
11960 encode_thumb32_shifted_operand (2);
11961}
b99bd4ef 11962
c19d1205
ZW
11963static void
11964do_t_setend (void)
11965{
12e37cbc
MGD
11966 if (warn_on_deprecated
11967 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11968 as_warn (_("setend use is deprecated for ARMv8"));
11969
e07e6e58 11970 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11971 if (inst.operands[0].imm)
11972 inst.instruction |= 0x8;
11973}
b99bd4ef 11974
c19d1205
ZW
11975static void
11976do_t_shift (void)
11977{
11978 if (!inst.operands[1].present)
11979 inst.operands[1].reg = inst.operands[0].reg;
11980
11981 if (unified_syntax)
11982 {
3d388997
PB
11983 bfd_boolean narrow;
11984 int shift_kind;
11985
11986 switch (inst.instruction)
11987 {
11988 case T_MNEM_asr:
11989 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11990 case T_MNEM_lsl:
11991 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11992 case T_MNEM_lsr:
11993 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11994 case T_MNEM_ror:
11995 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11996 default: abort ();
11997 }
11998
11999 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12000 narrow = !in_it_block ();
3d388997 12001 else
e07e6e58 12002 narrow = in_it_block ();
3d388997
PB
12003 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12004 narrow = FALSE;
12005 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12006 narrow = FALSE;
12007 if (inst.operands[2].isreg
12008 && (inst.operands[1].reg != inst.operands[0].reg
12009 || inst.operands[2].reg > 7))
12010 narrow = FALSE;
12011 if (inst.size_req == 4)
12012 narrow = FALSE;
12013
fdfde340
JM
12014 reject_bad_reg (inst.operands[0].reg);
12015 reject_bad_reg (inst.operands[1].reg);
c921be7d 12016
3d388997 12017 if (!narrow)
c19d1205
ZW
12018 {
12019 if (inst.operands[2].isreg)
b99bd4ef 12020 {
fdfde340 12021 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12022 inst.instruction = THUMB_OP32 (inst.instruction);
12023 inst.instruction |= inst.operands[0].reg << 8;
12024 inst.instruction |= inst.operands[1].reg << 16;
12025 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12026
12027 /* PR 12854: Error on extraneous shifts. */
12028 constraint (inst.operands[2].shifted,
12029 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12030 }
12031 else
12032 {
12033 inst.operands[1].shifted = 1;
3d388997 12034 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12035 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12036 ? T_MNEM_movs : T_MNEM_mov);
12037 inst.instruction |= inst.operands[0].reg << 8;
12038 encode_thumb32_shifted_operand (1);
12039 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12040 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12041 }
12042 }
12043 else
12044 {
c19d1205 12045 if (inst.operands[2].isreg)
b99bd4ef 12046 {
3d388997 12047 switch (shift_kind)
b99bd4ef 12048 {
3d388997
PB
12049 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12050 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12051 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12052 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12053 default: abort ();
b99bd4ef 12054 }
5f4273c7 12055
c19d1205
ZW
12056 inst.instruction |= inst.operands[0].reg;
12057 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12058
12059 /* PR 12854: Error on extraneous shifts. */
12060 constraint (inst.operands[2].shifted,
12061 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12062 }
12063 else
12064 {
3d388997 12065 switch (shift_kind)
b99bd4ef 12066 {
3d388997
PB
12067 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12068 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12069 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12070 default: abort ();
b99bd4ef 12071 }
c19d1205
ZW
12072 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12073 inst.instruction |= inst.operands[0].reg;
12074 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12075 }
12076 }
c19d1205
ZW
12077 }
12078 else
12079 {
12080 constraint (inst.operands[0].reg > 7
12081 || inst.operands[1].reg > 7, BAD_HIREG);
12082 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12083
c19d1205
ZW
12084 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12085 {
12086 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12087 constraint (inst.operands[0].reg != inst.operands[1].reg,
12088 _("source1 and dest must be same register"));
b99bd4ef 12089
c19d1205
ZW
12090 switch (inst.instruction)
12091 {
12092 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12093 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12094 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12095 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12096 default: abort ();
12097 }
5f4273c7 12098
c19d1205
ZW
12099 inst.instruction |= inst.operands[0].reg;
12100 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12101
12102 /* PR 12854: Error on extraneous shifts. */
12103 constraint (inst.operands[2].shifted,
12104 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12105 }
12106 else
b99bd4ef 12107 {
c19d1205
ZW
12108 switch (inst.instruction)
12109 {
12110 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12111 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12112 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12113 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12114 default: abort ();
12115 }
12116 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12117 inst.instruction |= inst.operands[0].reg;
12118 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12119 }
12120 }
b99bd4ef
NC
12121}
12122
12123static void
c19d1205 12124do_t_simd (void)
b99bd4ef 12125{
fdfde340
JM
12126 unsigned Rd, Rn, Rm;
12127
12128 Rd = inst.operands[0].reg;
12129 Rn = inst.operands[1].reg;
12130 Rm = inst.operands[2].reg;
12131
12132 reject_bad_reg (Rd);
12133 reject_bad_reg (Rn);
12134 reject_bad_reg (Rm);
12135
12136 inst.instruction |= Rd << 8;
12137 inst.instruction |= Rn << 16;
12138 inst.instruction |= Rm;
c19d1205 12139}
b99bd4ef 12140
03ee1b7f
NC
12141static void
12142do_t_simd2 (void)
12143{
12144 unsigned Rd, Rn, Rm;
12145
12146 Rd = inst.operands[0].reg;
12147 Rm = inst.operands[1].reg;
12148 Rn = inst.operands[2].reg;
12149
12150 reject_bad_reg (Rd);
12151 reject_bad_reg (Rn);
12152 reject_bad_reg (Rm);
12153
12154 inst.instruction |= Rd << 8;
12155 inst.instruction |= Rn << 16;
12156 inst.instruction |= Rm;
12157}
12158
c19d1205 12159static void
3eb17e6b 12160do_t_smc (void)
c19d1205
ZW
12161{
12162 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12163 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12164 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12165 constraint (inst.reloc.exp.X_op != O_constant,
12166 _("expression too complex"));
12167 inst.reloc.type = BFD_RELOC_UNUSED;
12168 inst.instruction |= (value & 0xf000) >> 12;
12169 inst.instruction |= (value & 0x0ff0);
12170 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12171 /* PR gas/15623: SMC instructions must be last in an IT block. */
12172 set_it_insn_type_last ();
c19d1205 12173}
b99bd4ef 12174
90ec0d68
MGD
12175static void
12176do_t_hvc (void)
12177{
12178 unsigned int value = inst.reloc.exp.X_add_number;
12179
12180 inst.reloc.type = BFD_RELOC_UNUSED;
12181 inst.instruction |= (value & 0x0fff);
12182 inst.instruction |= (value & 0xf000) << 4;
12183}
12184
c19d1205 12185static void
3a21c15a 12186do_t_ssat_usat (int bias)
c19d1205 12187{
fdfde340
JM
12188 unsigned Rd, Rn;
12189
12190 Rd = inst.operands[0].reg;
12191 Rn = inst.operands[2].reg;
12192
12193 reject_bad_reg (Rd);
12194 reject_bad_reg (Rn);
12195
12196 inst.instruction |= Rd << 8;
3a21c15a 12197 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12198 inst.instruction |= Rn << 16;
b99bd4ef 12199
c19d1205 12200 if (inst.operands[3].present)
b99bd4ef 12201 {
3a21c15a
NC
12202 offsetT shift_amount = inst.reloc.exp.X_add_number;
12203
12204 inst.reloc.type = BFD_RELOC_UNUSED;
12205
c19d1205
ZW
12206 constraint (inst.reloc.exp.X_op != O_constant,
12207 _("expression too complex"));
b99bd4ef 12208
3a21c15a 12209 if (shift_amount != 0)
6189168b 12210 {
3a21c15a
NC
12211 constraint (shift_amount > 31,
12212 _("shift expression is too large"));
12213
c19d1205 12214 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12215 inst.instruction |= 0x00200000; /* sh bit. */
12216
12217 inst.instruction |= (shift_amount & 0x1c) << 10;
12218 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
12219 }
12220 }
b99bd4ef 12221}
c921be7d 12222
3a21c15a
NC
12223static void
12224do_t_ssat (void)
12225{
12226 do_t_ssat_usat (1);
12227}
b99bd4ef 12228
0dd132b6 12229static void
c19d1205 12230do_t_ssat16 (void)
0dd132b6 12231{
fdfde340
JM
12232 unsigned Rd, Rn;
12233
12234 Rd = inst.operands[0].reg;
12235 Rn = inst.operands[2].reg;
12236
12237 reject_bad_reg (Rd);
12238 reject_bad_reg (Rn);
12239
12240 inst.instruction |= Rd << 8;
c19d1205 12241 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 12242 inst.instruction |= Rn << 16;
c19d1205 12243}
0dd132b6 12244
c19d1205
ZW
12245static void
12246do_t_strex (void)
12247{
12248 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12249 || inst.operands[2].postind || inst.operands[2].writeback
12250 || inst.operands[2].immisreg || inst.operands[2].shifted
12251 || inst.operands[2].negative,
01cfc07f 12252 BAD_ADDR_MODE);
0dd132b6 12253
5be8be5d
DG
12254 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12255
c19d1205
ZW
12256 inst.instruction |= inst.operands[0].reg << 8;
12257 inst.instruction |= inst.operands[1].reg << 12;
12258 inst.instruction |= inst.operands[2].reg << 16;
12259 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
12260}
12261
b99bd4ef 12262static void
c19d1205 12263do_t_strexd (void)
b99bd4ef 12264{
c19d1205
ZW
12265 if (!inst.operands[2].present)
12266 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 12267
c19d1205
ZW
12268 constraint (inst.operands[0].reg == inst.operands[1].reg
12269 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 12270 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 12271 BAD_OVERLAP);
b99bd4ef 12272
c19d1205
ZW
12273 inst.instruction |= inst.operands[0].reg;
12274 inst.instruction |= inst.operands[1].reg << 12;
12275 inst.instruction |= inst.operands[2].reg << 8;
12276 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
12277}
12278
12279static void
c19d1205 12280do_t_sxtah (void)
b99bd4ef 12281{
fdfde340
JM
12282 unsigned Rd, Rn, Rm;
12283
12284 Rd = inst.operands[0].reg;
12285 Rn = inst.operands[1].reg;
12286 Rm = inst.operands[2].reg;
12287
12288 reject_bad_reg (Rd);
12289 reject_bad_reg (Rn);
12290 reject_bad_reg (Rm);
12291
12292 inst.instruction |= Rd << 8;
12293 inst.instruction |= Rn << 16;
12294 inst.instruction |= Rm;
c19d1205
ZW
12295 inst.instruction |= inst.operands[3].imm << 4;
12296}
b99bd4ef 12297
c19d1205
ZW
12298static void
12299do_t_sxth (void)
12300{
fdfde340
JM
12301 unsigned Rd, Rm;
12302
12303 Rd = inst.operands[0].reg;
12304 Rm = inst.operands[1].reg;
12305
12306 reject_bad_reg (Rd);
12307 reject_bad_reg (Rm);
c921be7d
NC
12308
12309 if (inst.instruction <= 0xffff
12310 && inst.size_req != 4
fdfde340 12311 && Rd <= 7 && Rm <= 7
c19d1205 12312 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 12313 {
c19d1205 12314 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12315 inst.instruction |= Rd;
12316 inst.instruction |= Rm << 3;
b99bd4ef 12317 }
c19d1205 12318 else if (unified_syntax)
b99bd4ef 12319 {
c19d1205
ZW
12320 if (inst.instruction <= 0xffff)
12321 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12322 inst.instruction |= Rd << 8;
12323 inst.instruction |= Rm;
c19d1205 12324 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 12325 }
c19d1205 12326 else
b99bd4ef 12327 {
c19d1205
ZW
12328 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
12329 _("Thumb encoding does not support rotation"));
12330 constraint (1, BAD_HIREG);
b99bd4ef 12331 }
c19d1205 12332}
b99bd4ef 12333
c19d1205
ZW
12334static void
12335do_t_swi (void)
12336{
b2a5fbdc
MGD
12337 /* We have to do the following check manually as ARM_EXT_OS only applies
12338 to ARM_EXT_V6M. */
12339 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
12340 {
ac7f631b
NC
12341 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
12342 /* This only applies to the v6m howver, not later architectures. */
12343 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
12344 as_bad (_("SVC is not permitted on this architecture"));
12345 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
12346 }
12347
c19d1205
ZW
12348 inst.reloc.type = BFD_RELOC_ARM_SWI;
12349}
b99bd4ef 12350
92e90b6e
PB
12351static void
12352do_t_tb (void)
12353{
fdfde340 12354 unsigned Rn, Rm;
92e90b6e
PB
12355 int half;
12356
12357 half = (inst.instruction & 0x10) != 0;
e07e6e58 12358 set_it_insn_type_last ();
dfa9f0d5
PB
12359 constraint (inst.operands[0].immisreg,
12360 _("instruction requires register index"));
fdfde340
JM
12361
12362 Rn = inst.operands[0].reg;
12363 Rm = inst.operands[0].imm;
c921be7d 12364
fdfde340
JM
12365 constraint (Rn == REG_SP, BAD_SP);
12366 reject_bad_reg (Rm);
12367
92e90b6e
PB
12368 constraint (!half && inst.operands[0].shifted,
12369 _("instruction does not allow shifted index"));
fdfde340 12370 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
12371}
12372
74db7efb
NC
12373static void
12374do_t_udf (void)
12375{
12376 if (!inst.operands[0].present)
12377 inst.operands[0].imm = 0;
12378
12379 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
12380 {
12381 constraint (inst.size_req == 2,
12382 _("immediate value out of range"));
12383 inst.instruction = THUMB_OP32 (inst.instruction);
12384 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
12385 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
12386 }
12387 else
12388 {
12389 inst.instruction = THUMB_OP16 (inst.instruction);
12390 inst.instruction |= inst.operands[0].imm;
12391 }
12392
12393 set_it_insn_type (NEUTRAL_IT_INSN);
12394}
12395
12396
c19d1205
ZW
12397static void
12398do_t_usat (void)
12399{
3a21c15a 12400 do_t_ssat_usat (0);
b99bd4ef
NC
12401}
12402
12403static void
c19d1205 12404do_t_usat16 (void)
b99bd4ef 12405{
fdfde340
JM
12406 unsigned Rd, Rn;
12407
12408 Rd = inst.operands[0].reg;
12409 Rn = inst.operands[2].reg;
12410
12411 reject_bad_reg (Rd);
12412 reject_bad_reg (Rn);
12413
12414 inst.instruction |= Rd << 8;
c19d1205 12415 inst.instruction |= inst.operands[1].imm;
fdfde340 12416 inst.instruction |= Rn << 16;
b99bd4ef 12417}
c19d1205 12418
5287ad62 12419/* Neon instruction encoder helpers. */
5f4273c7 12420
5287ad62 12421/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 12422
5287ad62
JB
12423/* An "invalid" code for the following tables. */
12424#define N_INV -1u
12425
12426struct neon_tab_entry
b99bd4ef 12427{
5287ad62
JB
12428 unsigned integer;
12429 unsigned float_or_poly;
12430 unsigned scalar_or_imm;
12431};
5f4273c7 12432
5287ad62
JB
12433/* Map overloaded Neon opcodes to their respective encodings. */
12434#define NEON_ENC_TAB \
12435 X(vabd, 0x0000700, 0x1200d00, N_INV), \
12436 X(vmax, 0x0000600, 0x0000f00, N_INV), \
12437 X(vmin, 0x0000610, 0x0200f00, N_INV), \
12438 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
12439 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
12440 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
12441 X(vadd, 0x0000800, 0x0000d00, N_INV), \
12442 X(vsub, 0x1000800, 0x0200d00, N_INV), \
12443 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
12444 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
12445 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
12446 /* Register variants of the following two instructions are encoded as
e07e6e58 12447 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
12448 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
12449 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
12450 X(vfma, N_INV, 0x0000c10, N_INV), \
12451 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
12452 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
12453 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
12454 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
12455 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
12456 X(vmlal, 0x0800800, N_INV, 0x0800240), \
12457 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
12458 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
12459 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
12460 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
12461 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
12462 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
12463 X(vshl, 0x0000400, N_INV, 0x0800510), \
12464 X(vqshl, 0x0000410, N_INV, 0x0800710), \
12465 X(vand, 0x0000110, N_INV, 0x0800030), \
12466 X(vbic, 0x0100110, N_INV, 0x0800030), \
12467 X(veor, 0x1000110, N_INV, N_INV), \
12468 X(vorn, 0x0300110, N_INV, 0x0800010), \
12469 X(vorr, 0x0200110, N_INV, 0x0800010), \
12470 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
12471 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
12472 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
12473 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
12474 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
12475 X(vst1, 0x0000000, 0x0800000, N_INV), \
12476 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
12477 X(vst2, 0x0000100, 0x0800100, N_INV), \
12478 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
12479 X(vst3, 0x0000200, 0x0800200, N_INV), \
12480 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
12481 X(vst4, 0x0000300, 0x0800300, N_INV), \
12482 X(vmovn, 0x1b20200, N_INV, N_INV), \
12483 X(vtrn, 0x1b20080, N_INV, N_INV), \
12484 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
12485 X(vqmovun, 0x1b20240, N_INV, N_INV), \
12486 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
12487 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
12488 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
12489 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
12490 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
12491 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
12492 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
12493 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
12494 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
12495 X(vseleq, 0xe000a00, N_INV, N_INV), \
12496 X(vselvs, 0xe100a00, N_INV, N_INV), \
12497 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
12498 X(vselgt, 0xe300a00, N_INV, N_INV), \
12499 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 12500 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
12501 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
12502 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 12503 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 12504 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
12505 X(sha3op, 0x2000c00, N_INV, N_INV), \
12506 X(sha1h, 0x3b902c0, N_INV, N_INV), \
12507 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
12508
12509enum neon_opc
12510{
12511#define X(OPC,I,F,S) N_MNEM_##OPC
12512NEON_ENC_TAB
12513#undef X
12514};
b99bd4ef 12515
5287ad62
JB
12516static const struct neon_tab_entry neon_enc_tab[] =
12517{
12518#define X(OPC,I,F,S) { (I), (F), (S) }
12519NEON_ENC_TAB
12520#undef X
12521};
b99bd4ef 12522
88714cb8
DG
12523/* Do not use these macros; instead, use NEON_ENCODE defined below. */
12524#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12525#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12526#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12527#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12528#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12529#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12530#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12531#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12532#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12533#define NEON_ENC_SINGLE_(X) \
037e8744 12534 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 12535#define NEON_ENC_DOUBLE_(X) \
037e8744 12536 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
12537#define NEON_ENC_FPV8_(X) \
12538 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 12539
88714cb8
DG
12540#define NEON_ENCODE(type, inst) \
12541 do \
12542 { \
12543 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
12544 inst.is_neon = 1; \
12545 } \
12546 while (0)
12547
12548#define check_neon_suffixes \
12549 do \
12550 { \
12551 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
12552 { \
12553 as_bad (_("invalid neon suffix for non neon instruction")); \
12554 return; \
12555 } \
12556 } \
12557 while (0)
12558
037e8744
JB
12559/* Define shapes for instruction operands. The following mnemonic characters
12560 are used in this table:
5287ad62 12561
037e8744 12562 F - VFP S<n> register
5287ad62
JB
12563 D - Neon D<n> register
12564 Q - Neon Q<n> register
12565 I - Immediate
12566 S - Scalar
12567 R - ARM register
12568 L - D<n> register list
5f4273c7 12569
037e8744
JB
12570 This table is used to generate various data:
12571 - enumerations of the form NS_DDR to be used as arguments to
12572 neon_select_shape.
12573 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 12574 - a table used to drive neon_select_shape. */
b99bd4ef 12575
037e8744
JB
12576#define NEON_SHAPE_DEF \
12577 X(3, (D, D, D), DOUBLE), \
12578 X(3, (Q, Q, Q), QUAD), \
12579 X(3, (D, D, I), DOUBLE), \
12580 X(3, (Q, Q, I), QUAD), \
12581 X(3, (D, D, S), DOUBLE), \
12582 X(3, (Q, Q, S), QUAD), \
12583 X(2, (D, D), DOUBLE), \
12584 X(2, (Q, Q), QUAD), \
12585 X(2, (D, S), DOUBLE), \
12586 X(2, (Q, S), QUAD), \
12587 X(2, (D, R), DOUBLE), \
12588 X(2, (Q, R), QUAD), \
12589 X(2, (D, I), DOUBLE), \
12590 X(2, (Q, I), QUAD), \
12591 X(3, (D, L, D), DOUBLE), \
12592 X(2, (D, Q), MIXED), \
12593 X(2, (Q, D), MIXED), \
12594 X(3, (D, Q, I), MIXED), \
12595 X(3, (Q, D, I), MIXED), \
12596 X(3, (Q, D, D), MIXED), \
12597 X(3, (D, Q, Q), MIXED), \
12598 X(3, (Q, Q, D), MIXED), \
12599 X(3, (Q, D, S), MIXED), \
12600 X(3, (D, Q, S), MIXED), \
12601 X(4, (D, D, D, I), DOUBLE), \
12602 X(4, (Q, Q, Q, I), QUAD), \
12603 X(2, (F, F), SINGLE), \
12604 X(3, (F, F, F), SINGLE), \
12605 X(2, (F, I), SINGLE), \
12606 X(2, (F, D), MIXED), \
12607 X(2, (D, F), MIXED), \
12608 X(3, (F, F, I), MIXED), \
12609 X(4, (R, R, F, F), SINGLE), \
12610 X(4, (F, F, R, R), SINGLE), \
12611 X(3, (D, R, R), DOUBLE), \
12612 X(3, (R, R, D), DOUBLE), \
12613 X(2, (S, R), SINGLE), \
12614 X(2, (R, S), SINGLE), \
12615 X(2, (F, R), SINGLE), \
12616 X(2, (R, F), SINGLE)
12617
12618#define S2(A,B) NS_##A##B
12619#define S3(A,B,C) NS_##A##B##C
12620#define S4(A,B,C,D) NS_##A##B##C##D
12621
12622#define X(N, L, C) S##N L
12623
5287ad62
JB
12624enum neon_shape
12625{
037e8744
JB
12626 NEON_SHAPE_DEF,
12627 NS_NULL
5287ad62 12628};
b99bd4ef 12629
037e8744
JB
12630#undef X
12631#undef S2
12632#undef S3
12633#undef S4
12634
12635enum neon_shape_class
12636{
12637 SC_SINGLE,
12638 SC_DOUBLE,
12639 SC_QUAD,
12640 SC_MIXED
12641};
12642
12643#define X(N, L, C) SC_##C
12644
12645static enum neon_shape_class neon_shape_class[] =
12646{
12647 NEON_SHAPE_DEF
12648};
12649
12650#undef X
12651
12652enum neon_shape_el
12653{
12654 SE_F,
12655 SE_D,
12656 SE_Q,
12657 SE_I,
12658 SE_S,
12659 SE_R,
12660 SE_L
12661};
12662
12663/* Register widths of above. */
12664static unsigned neon_shape_el_size[] =
12665{
12666 32,
12667 64,
12668 128,
12669 0,
12670 32,
12671 32,
12672 0
12673};
12674
12675struct neon_shape_info
12676{
12677 unsigned els;
12678 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
12679};
12680
12681#define S2(A,B) { SE_##A, SE_##B }
12682#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
12683#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
12684
12685#define X(N, L, C) { N, S##N L }
12686
12687static struct neon_shape_info neon_shape_tab[] =
12688{
12689 NEON_SHAPE_DEF
12690};
12691
12692#undef X
12693#undef S2
12694#undef S3
12695#undef S4
12696
5287ad62
JB
12697/* Bit masks used in type checking given instructions.
12698 'N_EQK' means the type must be the same as (or based on in some way) the key
12699 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
12700 set, various other bits can be set as well in order to modify the meaning of
12701 the type constraint. */
12702
12703enum neon_type_mask
12704{
8e79c3df
CM
12705 N_S8 = 0x0000001,
12706 N_S16 = 0x0000002,
12707 N_S32 = 0x0000004,
12708 N_S64 = 0x0000008,
12709 N_U8 = 0x0000010,
12710 N_U16 = 0x0000020,
12711 N_U32 = 0x0000040,
12712 N_U64 = 0x0000080,
12713 N_I8 = 0x0000100,
12714 N_I16 = 0x0000200,
12715 N_I32 = 0x0000400,
12716 N_I64 = 0x0000800,
12717 N_8 = 0x0001000,
12718 N_16 = 0x0002000,
12719 N_32 = 0x0004000,
12720 N_64 = 0x0008000,
12721 N_P8 = 0x0010000,
12722 N_P16 = 0x0020000,
12723 N_F16 = 0x0040000,
12724 N_F32 = 0x0080000,
12725 N_F64 = 0x0100000,
4f51b4bd 12726 N_P64 = 0x0200000,
c921be7d
NC
12727 N_KEY = 0x1000000, /* Key element (main type specifier). */
12728 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 12729 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 12730 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
12731 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
12732 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
12733 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
12734 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
12735 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
12736 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
12737 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 12738 N_UTYP = 0,
4f51b4bd 12739 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
12740};
12741
dcbf9037
JB
12742#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
12743
5287ad62
JB
12744#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
12745#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
12746#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
12747#define N_SUF_32 (N_SU_32 | N_F32)
12748#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
12749#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
12750
12751/* Pass this as the first type argument to neon_check_type to ignore types
12752 altogether. */
12753#define N_IGNORE_TYPE (N_KEY | N_EQK)
12754
037e8744
JB
12755/* Select a "shape" for the current instruction (describing register types or
12756 sizes) from a list of alternatives. Return NS_NULL if the current instruction
12757 doesn't fit. For non-polymorphic shapes, checking is usually done as a
12758 function of operand parsing, so this function doesn't need to be called.
12759 Shapes should be listed in order of decreasing length. */
5287ad62
JB
12760
12761static enum neon_shape
037e8744 12762neon_select_shape (enum neon_shape shape, ...)
5287ad62 12763{
037e8744
JB
12764 va_list ap;
12765 enum neon_shape first_shape = shape;
5287ad62
JB
12766
12767 /* Fix missing optional operands. FIXME: we don't know at this point how
12768 many arguments we should have, so this makes the assumption that we have
12769 > 1. This is true of all current Neon opcodes, I think, but may not be
12770 true in the future. */
12771 if (!inst.operands[1].present)
12772 inst.operands[1] = inst.operands[0];
12773
037e8744 12774 va_start (ap, shape);
5f4273c7 12775
21d799b5 12776 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
12777 {
12778 unsigned j;
12779 int matches = 1;
12780
12781 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
12782 {
12783 if (!inst.operands[j].present)
12784 {
12785 matches = 0;
12786 break;
12787 }
12788
12789 switch (neon_shape_tab[shape].el[j])
12790 {
12791 case SE_F:
12792 if (!(inst.operands[j].isreg
12793 && inst.operands[j].isvec
12794 && inst.operands[j].issingle
12795 && !inst.operands[j].isquad))
12796 matches = 0;
12797 break;
12798
12799 case SE_D:
12800 if (!(inst.operands[j].isreg
12801 && inst.operands[j].isvec
12802 && !inst.operands[j].isquad
12803 && !inst.operands[j].issingle))
12804 matches = 0;
12805 break;
12806
12807 case SE_R:
12808 if (!(inst.operands[j].isreg
12809 && !inst.operands[j].isvec))
12810 matches = 0;
12811 break;
12812
12813 case SE_Q:
12814 if (!(inst.operands[j].isreg
12815 && inst.operands[j].isvec
12816 && inst.operands[j].isquad
12817 && !inst.operands[j].issingle))
12818 matches = 0;
12819 break;
12820
12821 case SE_I:
12822 if (!(!inst.operands[j].isreg
12823 && !inst.operands[j].isscalar))
12824 matches = 0;
12825 break;
12826
12827 case SE_S:
12828 if (!(!inst.operands[j].isreg
12829 && inst.operands[j].isscalar))
12830 matches = 0;
12831 break;
12832
12833 case SE_L:
12834 break;
12835 }
3fde54a2
JZ
12836 if (!matches)
12837 break;
477330fc 12838 }
ad6cec43
MGD
12839 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
12840 /* We've matched all the entries in the shape table, and we don't
12841 have any left over operands which have not been matched. */
477330fc 12842 break;
037e8744 12843 }
5f4273c7 12844
037e8744 12845 va_end (ap);
5287ad62 12846
037e8744
JB
12847 if (shape == NS_NULL && first_shape != NS_NULL)
12848 first_error (_("invalid instruction shape"));
5287ad62 12849
037e8744
JB
12850 return shape;
12851}
5287ad62 12852
037e8744
JB
12853/* True if SHAPE is predominantly a quadword operation (most of the time, this
12854 means the Q bit should be set). */
12855
12856static int
12857neon_quad (enum neon_shape shape)
12858{
12859 return neon_shape_class[shape] == SC_QUAD;
5287ad62 12860}
037e8744 12861
5287ad62
JB
12862static void
12863neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 12864 unsigned *g_size)
5287ad62
JB
12865{
12866 /* Allow modification to be made to types which are constrained to be
12867 based on the key element, based on bits set alongside N_EQK. */
12868 if ((typebits & N_EQK) != 0)
12869 {
12870 if ((typebits & N_HLF) != 0)
12871 *g_size /= 2;
12872 else if ((typebits & N_DBL) != 0)
12873 *g_size *= 2;
12874 if ((typebits & N_SGN) != 0)
12875 *g_type = NT_signed;
12876 else if ((typebits & N_UNS) != 0)
477330fc 12877 *g_type = NT_unsigned;
5287ad62 12878 else if ((typebits & N_INT) != 0)
477330fc 12879 *g_type = NT_integer;
5287ad62 12880 else if ((typebits & N_FLT) != 0)
477330fc 12881 *g_type = NT_float;
dcbf9037 12882 else if ((typebits & N_SIZ) != 0)
477330fc 12883 *g_type = NT_untyped;
5287ad62
JB
12884 }
12885}
5f4273c7 12886
5287ad62
JB
12887/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12888 operand type, i.e. the single type specified in a Neon instruction when it
12889 is the only one given. */
12890
12891static struct neon_type_el
12892neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12893{
12894 struct neon_type_el dest = *key;
5f4273c7 12895
9c2799c2 12896 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 12897
5287ad62
JB
12898 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12899
12900 return dest;
12901}
12902
12903/* Convert Neon type and size into compact bitmask representation. */
12904
12905static enum neon_type_mask
12906type_chk_of_el_type (enum neon_el_type type, unsigned size)
12907{
12908 switch (type)
12909 {
12910 case NT_untyped:
12911 switch (size)
477330fc
RM
12912 {
12913 case 8: return N_8;
12914 case 16: return N_16;
12915 case 32: return N_32;
12916 case 64: return N_64;
12917 default: ;
12918 }
5287ad62
JB
12919 break;
12920
12921 case NT_integer:
12922 switch (size)
477330fc
RM
12923 {
12924 case 8: return N_I8;
12925 case 16: return N_I16;
12926 case 32: return N_I32;
12927 case 64: return N_I64;
12928 default: ;
12929 }
5287ad62
JB
12930 break;
12931
12932 case NT_float:
037e8744 12933 switch (size)
477330fc 12934 {
8e79c3df 12935 case 16: return N_F16;
477330fc
RM
12936 case 32: return N_F32;
12937 case 64: return N_F64;
12938 default: ;
12939 }
5287ad62
JB
12940 break;
12941
12942 case NT_poly:
12943 switch (size)
477330fc
RM
12944 {
12945 case 8: return N_P8;
12946 case 16: return N_P16;
4f51b4bd 12947 case 64: return N_P64;
477330fc
RM
12948 default: ;
12949 }
5287ad62
JB
12950 break;
12951
12952 case NT_signed:
12953 switch (size)
477330fc
RM
12954 {
12955 case 8: return N_S8;
12956 case 16: return N_S16;
12957 case 32: return N_S32;
12958 case 64: return N_S64;
12959 default: ;
12960 }
5287ad62
JB
12961 break;
12962
12963 case NT_unsigned:
12964 switch (size)
477330fc
RM
12965 {
12966 case 8: return N_U8;
12967 case 16: return N_U16;
12968 case 32: return N_U32;
12969 case 64: return N_U64;
12970 default: ;
12971 }
5287ad62
JB
12972 break;
12973
12974 default: ;
12975 }
5f4273c7 12976
5287ad62
JB
12977 return N_UTYP;
12978}
12979
12980/* Convert compact Neon bitmask type representation to a type and size. Only
12981 handles the case where a single bit is set in the mask. */
12982
dcbf9037 12983static int
5287ad62 12984el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 12985 enum neon_type_mask mask)
5287ad62 12986{
dcbf9037
JB
12987 if ((mask & N_EQK) != 0)
12988 return FAIL;
12989
5287ad62
JB
12990 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12991 *size = 8;
c70a8987 12992 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 12993 *size = 16;
dcbf9037 12994 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 12995 *size = 32;
4f51b4bd 12996 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 12997 *size = 64;
dcbf9037
JB
12998 else
12999 return FAIL;
13000
5287ad62
JB
13001 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13002 *type = NT_signed;
dcbf9037 13003 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13004 *type = NT_unsigned;
dcbf9037 13005 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13006 *type = NT_integer;
dcbf9037 13007 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13008 *type = NT_untyped;
4f51b4bd 13009 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13010 *type = NT_poly;
c70a8987 13011 else if ((mask & (N_F16 | N_F32 | N_F64)) != 0)
5287ad62 13012 *type = NT_float;
dcbf9037
JB
13013 else
13014 return FAIL;
5f4273c7 13015
dcbf9037 13016 return SUCCESS;
5287ad62
JB
13017}
13018
13019/* Modify a bitmask of allowed types. This is only needed for type
13020 relaxation. */
13021
13022static unsigned
13023modify_types_allowed (unsigned allowed, unsigned mods)
13024{
13025 unsigned size;
13026 enum neon_el_type type;
13027 unsigned destmask;
13028 int i;
5f4273c7 13029
5287ad62 13030 destmask = 0;
5f4273c7 13031
5287ad62
JB
13032 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13033 {
21d799b5 13034 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13035 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13036 {
13037 neon_modify_type_size (mods, &type, &size);
13038 destmask |= type_chk_of_el_type (type, size);
13039 }
5287ad62 13040 }
5f4273c7 13041
5287ad62
JB
13042 return destmask;
13043}
13044
13045/* Check type and return type classification.
13046 The manual states (paraphrase): If one datatype is given, it indicates the
13047 type given in:
13048 - the second operand, if there is one
13049 - the operand, if there is no second operand
13050 - the result, if there are no operands.
13051 This isn't quite good enough though, so we use a concept of a "key" datatype
13052 which is set on a per-instruction basis, which is the one which matters when
13053 only one data type is written.
13054 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13055 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13056
13057static struct neon_type_el
13058neon_check_type (unsigned els, enum neon_shape ns, ...)
13059{
13060 va_list ap;
13061 unsigned i, pass, key_el = 0;
13062 unsigned types[NEON_MAX_TYPE_ELS];
13063 enum neon_el_type k_type = NT_invtype;
13064 unsigned k_size = -1u;
13065 struct neon_type_el badtype = {NT_invtype, -1};
13066 unsigned key_allowed = 0;
13067
13068 /* Optional registers in Neon instructions are always (not) in operand 1.
13069 Fill in the missing operand here, if it was omitted. */
13070 if (els > 1 && !inst.operands[1].present)
13071 inst.operands[1] = inst.operands[0];
13072
13073 /* Suck up all the varargs. */
13074 va_start (ap, ns);
13075 for (i = 0; i < els; i++)
13076 {
13077 unsigned thisarg = va_arg (ap, unsigned);
13078 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13079 {
13080 va_end (ap);
13081 return badtype;
13082 }
5287ad62
JB
13083 types[i] = thisarg;
13084 if ((thisarg & N_KEY) != 0)
477330fc 13085 key_el = i;
5287ad62
JB
13086 }
13087 va_end (ap);
13088
dcbf9037
JB
13089 if (inst.vectype.elems > 0)
13090 for (i = 0; i < els; i++)
13091 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13092 {
13093 first_error (_("types specified in both the mnemonic and operands"));
13094 return badtype;
13095 }
dcbf9037 13096
5287ad62
JB
13097 /* Duplicate inst.vectype elements here as necessary.
13098 FIXME: No idea if this is exactly the same as the ARM assembler,
13099 particularly when an insn takes one register and one non-register
13100 operand. */
13101 if (inst.vectype.elems == 1 && els > 1)
13102 {
13103 unsigned j;
13104 inst.vectype.elems = els;
13105 inst.vectype.el[key_el] = inst.vectype.el[0];
13106 for (j = 0; j < els; j++)
477330fc
RM
13107 if (j != key_el)
13108 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13109 types[j]);
dcbf9037
JB
13110 }
13111 else if (inst.vectype.elems == 0 && els > 0)
13112 {
13113 unsigned j;
13114 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13115 after each operand. We allow some flexibility here; as long as the
13116 "key" operand has a type, we can infer the others. */
dcbf9037 13117 for (j = 0; j < els; j++)
477330fc
RM
13118 if (inst.operands[j].vectype.type != NT_invtype)
13119 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13120
13121 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13122 {
13123 for (j = 0; j < els; j++)
13124 if (inst.operands[j].vectype.type == NT_invtype)
13125 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13126 types[j]);
13127 }
dcbf9037 13128 else
477330fc
RM
13129 {
13130 first_error (_("operand types can't be inferred"));
13131 return badtype;
13132 }
5287ad62
JB
13133 }
13134 else if (inst.vectype.elems != els)
13135 {
dcbf9037 13136 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13137 return badtype;
13138 }
13139
13140 for (pass = 0; pass < 2; pass++)
13141 {
13142 for (i = 0; i < els; i++)
477330fc
RM
13143 {
13144 unsigned thisarg = types[i];
13145 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13146 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13147 enum neon_el_type g_type = inst.vectype.el[i].type;
13148 unsigned g_size = inst.vectype.el[i].size;
13149
13150 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 13151 integer types if sign-specific variants are unavailable. */
477330fc 13152 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
13153 && (types_allowed & N_SU_ALL) == 0)
13154 g_type = NT_integer;
13155
477330fc 13156 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
13157 them. Some instructions only care about signs for some element
13158 sizes, so handle that properly. */
477330fc 13159 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
13160 && ((g_size == 8 && (types_allowed & N_8) != 0)
13161 || (g_size == 16 && (types_allowed & N_16) != 0)
13162 || (g_size == 32 && (types_allowed & N_32) != 0)
13163 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
13164 g_type = NT_untyped;
13165
477330fc
RM
13166 if (pass == 0)
13167 {
13168 if ((thisarg & N_KEY) != 0)
13169 {
13170 k_type = g_type;
13171 k_size = g_size;
13172 key_allowed = thisarg & ~N_KEY;
13173 }
13174 }
13175 else
13176 {
13177 if ((thisarg & N_VFP) != 0)
13178 {
13179 enum neon_shape_el regshape;
13180 unsigned regwidth, match;
99b253c5
NC
13181
13182 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13183 if (ns == NS_NULL)
13184 {
13185 first_error (_("invalid instruction shape"));
13186 return badtype;
13187 }
477330fc
RM
13188 regshape = neon_shape_tab[ns].el[i];
13189 regwidth = neon_shape_el_size[regshape];
13190
13191 /* In VFP mode, operands must match register widths. If we
13192 have a key operand, use its width, else use the width of
13193 the current operand. */
13194 if (k_size != -1u)
13195 match = k_size;
13196 else
13197 match = g_size;
13198
13199 if (regwidth != match)
13200 {
13201 first_error (_("operand size must match register width"));
13202 return badtype;
13203 }
13204 }
13205
13206 if ((thisarg & N_EQK) == 0)
13207 {
13208 unsigned given_type = type_chk_of_el_type (g_type, g_size);
13209
13210 if ((given_type & types_allowed) == 0)
13211 {
13212 first_error (_("bad type in Neon instruction"));
13213 return badtype;
13214 }
13215 }
13216 else
13217 {
13218 enum neon_el_type mod_k_type = k_type;
13219 unsigned mod_k_size = k_size;
13220 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
13221 if (g_type != mod_k_type || g_size != mod_k_size)
13222 {
13223 first_error (_("inconsistent types in Neon instruction"));
13224 return badtype;
13225 }
13226 }
13227 }
13228 }
5287ad62
JB
13229 }
13230
13231 return inst.vectype.el[key_el];
13232}
13233
037e8744 13234/* Neon-style VFP instruction forwarding. */
5287ad62 13235
037e8744
JB
13236/* Thumb VFP instructions have 0xE in the condition field. */
13237
13238static void
13239do_vfp_cond_or_thumb (void)
5287ad62 13240{
88714cb8
DG
13241 inst.is_neon = 1;
13242
5287ad62 13243 if (thumb_mode)
037e8744 13244 inst.instruction |= 0xe0000000;
5287ad62 13245 else
037e8744 13246 inst.instruction |= inst.cond << 28;
5287ad62
JB
13247}
13248
037e8744
JB
13249/* Look up and encode a simple mnemonic, for use as a helper function for the
13250 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
13251 etc. It is assumed that operand parsing has already been done, and that the
13252 operands are in the form expected by the given opcode (this isn't necessarily
13253 the same as the form in which they were parsed, hence some massaging must
13254 take place before this function is called).
13255 Checks current arch version against that in the looked-up opcode. */
5287ad62 13256
037e8744
JB
13257static void
13258do_vfp_nsyn_opcode (const char *opname)
5287ad62 13259{
037e8744 13260 const struct asm_opcode *opcode;
5f4273c7 13261
21d799b5 13262 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 13263
037e8744
JB
13264 if (!opcode)
13265 abort ();
5287ad62 13266
037e8744 13267 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
13268 thumb_mode ? *opcode->tvariant : *opcode->avariant),
13269 _(BAD_FPU));
5287ad62 13270
88714cb8
DG
13271 inst.is_neon = 1;
13272
037e8744
JB
13273 if (thumb_mode)
13274 {
13275 inst.instruction = opcode->tvalue;
13276 opcode->tencode ();
13277 }
13278 else
13279 {
13280 inst.instruction = (inst.cond << 28) | opcode->avalue;
13281 opcode->aencode ();
13282 }
13283}
5287ad62
JB
13284
13285static void
037e8744 13286do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 13287{
037e8744
JB
13288 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
13289
13290 if (rs == NS_FFF)
13291 {
13292 if (is_add)
477330fc 13293 do_vfp_nsyn_opcode ("fadds");
037e8744 13294 else
477330fc 13295 do_vfp_nsyn_opcode ("fsubs");
037e8744
JB
13296 }
13297 else
13298 {
13299 if (is_add)
477330fc 13300 do_vfp_nsyn_opcode ("faddd");
037e8744 13301 else
477330fc 13302 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
13303 }
13304}
13305
13306/* Check operand types to see if this is a VFP instruction, and if so call
13307 PFN (). */
13308
13309static int
13310try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
13311{
13312 enum neon_shape rs;
13313 struct neon_type_el et;
13314
13315 switch (args)
13316 {
13317 case 2:
13318 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13319 et = neon_check_type (2, rs,
477330fc 13320 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
037e8744 13321 break;
5f4273c7 13322
037e8744
JB
13323 case 3:
13324 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13325 et = neon_check_type (3, rs,
477330fc 13326 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
037e8744
JB
13327 break;
13328
13329 default:
13330 abort ();
13331 }
13332
13333 if (et.type != NT_invtype)
13334 {
13335 pfn (rs);
13336 return SUCCESS;
13337 }
037e8744 13338
99b253c5 13339 inst.error = NULL;
037e8744
JB
13340 return FAIL;
13341}
13342
13343static void
13344do_vfp_nsyn_mla_mls (enum neon_shape rs)
13345{
13346 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 13347
037e8744
JB
13348 if (rs == NS_FFF)
13349 {
13350 if (is_mla)
477330fc 13351 do_vfp_nsyn_opcode ("fmacs");
037e8744 13352 else
477330fc 13353 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
13354 }
13355 else
13356 {
13357 if (is_mla)
477330fc 13358 do_vfp_nsyn_opcode ("fmacd");
037e8744 13359 else
477330fc 13360 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
13361 }
13362}
13363
62f3b8c8
PB
13364static void
13365do_vfp_nsyn_fma_fms (enum neon_shape rs)
13366{
13367 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
13368
13369 if (rs == NS_FFF)
13370 {
13371 if (is_fma)
477330fc 13372 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 13373 else
477330fc 13374 do_vfp_nsyn_opcode ("ffnmas");
62f3b8c8
PB
13375 }
13376 else
13377 {
13378 if (is_fma)
477330fc 13379 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 13380 else
477330fc 13381 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
13382 }
13383}
13384
037e8744
JB
13385static void
13386do_vfp_nsyn_mul (enum neon_shape rs)
13387{
13388 if (rs == NS_FFF)
13389 do_vfp_nsyn_opcode ("fmuls");
13390 else
13391 do_vfp_nsyn_opcode ("fmuld");
13392}
13393
13394static void
13395do_vfp_nsyn_abs_neg (enum neon_shape rs)
13396{
13397 int is_neg = (inst.instruction & 0x80) != 0;
13398 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
13399
13400 if (rs == NS_FF)
13401 {
13402 if (is_neg)
477330fc 13403 do_vfp_nsyn_opcode ("fnegs");
037e8744 13404 else
477330fc 13405 do_vfp_nsyn_opcode ("fabss");
037e8744
JB
13406 }
13407 else
13408 {
13409 if (is_neg)
477330fc 13410 do_vfp_nsyn_opcode ("fnegd");
037e8744 13411 else
477330fc 13412 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
13413 }
13414}
13415
13416/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
13417 insns belong to Neon, and are handled elsewhere. */
13418
13419static void
13420do_vfp_nsyn_ldm_stm (int is_dbmode)
13421{
13422 int is_ldm = (inst.instruction & (1 << 20)) != 0;
13423 if (is_ldm)
13424 {
13425 if (is_dbmode)
477330fc 13426 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 13427 else
477330fc 13428 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
13429 }
13430 else
13431 {
13432 if (is_dbmode)
477330fc 13433 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 13434 else
477330fc 13435 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
13436 }
13437}
13438
037e8744
JB
13439static void
13440do_vfp_nsyn_sqrt (void)
13441{
13442 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13443 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13444
037e8744
JB
13445 if (rs == NS_FF)
13446 do_vfp_nsyn_opcode ("fsqrts");
13447 else
13448 do_vfp_nsyn_opcode ("fsqrtd");
13449}
13450
13451static void
13452do_vfp_nsyn_div (void)
13453{
13454 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13455 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13456 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13457
037e8744
JB
13458 if (rs == NS_FFF)
13459 do_vfp_nsyn_opcode ("fdivs");
13460 else
13461 do_vfp_nsyn_opcode ("fdivd");
13462}
13463
13464static void
13465do_vfp_nsyn_nmul (void)
13466{
13467 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13468 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13469 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13470
037e8744
JB
13471 if (rs == NS_FFF)
13472 {
88714cb8 13473 NEON_ENCODE (SINGLE, inst);
037e8744
JB
13474 do_vfp_sp_dyadic ();
13475 }
13476 else
13477 {
88714cb8 13478 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
13479 do_vfp_dp_rd_rn_rm ();
13480 }
13481 do_vfp_cond_or_thumb ();
13482}
13483
13484static void
13485do_vfp_nsyn_cmp (void)
13486{
13487 if (inst.operands[1].isreg)
13488 {
13489 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13490 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13491
037e8744 13492 if (rs == NS_FF)
477330fc
RM
13493 {
13494 NEON_ENCODE (SINGLE, inst);
13495 do_vfp_sp_monadic ();
13496 }
037e8744 13497 else
477330fc
RM
13498 {
13499 NEON_ENCODE (DOUBLE, inst);
13500 do_vfp_dp_rd_rm ();
13501 }
037e8744
JB
13502 }
13503 else
13504 {
13505 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
13506 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
13507
13508 switch (inst.instruction & 0x0fffffff)
477330fc
RM
13509 {
13510 case N_MNEM_vcmp:
13511 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
13512 break;
13513 case N_MNEM_vcmpe:
13514 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
13515 break;
13516 default:
13517 abort ();
13518 }
5f4273c7 13519
037e8744 13520 if (rs == NS_FI)
477330fc
RM
13521 {
13522 NEON_ENCODE (SINGLE, inst);
13523 do_vfp_sp_compare_z ();
13524 }
037e8744 13525 else
477330fc
RM
13526 {
13527 NEON_ENCODE (DOUBLE, inst);
13528 do_vfp_dp_rd ();
13529 }
037e8744
JB
13530 }
13531 do_vfp_cond_or_thumb ();
13532}
13533
13534static void
13535nsyn_insert_sp (void)
13536{
13537 inst.operands[1] = inst.operands[0];
13538 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 13539 inst.operands[0].reg = REG_SP;
037e8744
JB
13540 inst.operands[0].isreg = 1;
13541 inst.operands[0].writeback = 1;
13542 inst.operands[0].present = 1;
13543}
13544
13545static void
13546do_vfp_nsyn_push (void)
13547{
13548 nsyn_insert_sp ();
13549 if (inst.operands[1].issingle)
13550 do_vfp_nsyn_opcode ("fstmdbs");
13551 else
13552 do_vfp_nsyn_opcode ("fstmdbd");
13553}
13554
13555static void
13556do_vfp_nsyn_pop (void)
13557{
13558 nsyn_insert_sp ();
13559 if (inst.operands[1].issingle)
22b5b651 13560 do_vfp_nsyn_opcode ("fldmias");
037e8744 13561 else
22b5b651 13562 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
13563}
13564
13565/* Fix up Neon data-processing instructions, ORing in the correct bits for
13566 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
13567
88714cb8
DG
13568static void
13569neon_dp_fixup (struct arm_it* insn)
037e8744 13570{
88714cb8
DG
13571 unsigned int i = insn->instruction;
13572 insn->is_neon = 1;
13573
037e8744
JB
13574 if (thumb_mode)
13575 {
13576 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
13577 if (i & (1 << 24))
477330fc 13578 i |= 1 << 28;
5f4273c7 13579
037e8744 13580 i &= ~(1 << 24);
5f4273c7 13581
037e8744
JB
13582 i |= 0xef000000;
13583 }
13584 else
13585 i |= 0xf2000000;
5f4273c7 13586
88714cb8 13587 insn->instruction = i;
037e8744
JB
13588}
13589
13590/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
13591 (0, 1, 2, 3). */
13592
13593static unsigned
13594neon_logbits (unsigned x)
13595{
13596 return ffs (x) - 4;
13597}
13598
13599#define LOW4(R) ((R) & 0xf)
13600#define HI1(R) (((R) >> 4) & 1)
13601
13602/* Encode insns with bit pattern:
13603
13604 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13605 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 13606
037e8744
JB
13607 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
13608 different meaning for some instruction. */
13609
13610static void
13611neon_three_same (int isquad, int ubit, int size)
13612{
13613 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13614 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13615 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13616 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13617 inst.instruction |= LOW4 (inst.operands[2].reg);
13618 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13619 inst.instruction |= (isquad != 0) << 6;
13620 inst.instruction |= (ubit != 0) << 24;
13621 if (size != -1)
13622 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 13623
88714cb8 13624 neon_dp_fixup (&inst);
037e8744
JB
13625}
13626
13627/* Encode instructions of the form:
13628
13629 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
13630 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
13631
13632 Don't write size if SIZE == -1. */
13633
13634static void
13635neon_two_same (int qbit, int ubit, int size)
13636{
13637 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13638 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13639 inst.instruction |= LOW4 (inst.operands[1].reg);
13640 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13641 inst.instruction |= (qbit != 0) << 6;
13642 inst.instruction |= (ubit != 0) << 24;
13643
13644 if (size != -1)
13645 inst.instruction |= neon_logbits (size) << 18;
13646
88714cb8 13647 neon_dp_fixup (&inst);
5287ad62
JB
13648}
13649
13650/* Neon instruction encoders, in approximate order of appearance. */
13651
13652static void
13653do_neon_dyadic_i_su (void)
13654{
037e8744 13655 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13656 struct neon_type_el et = neon_check_type (3, rs,
13657 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 13658 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13659}
13660
13661static void
13662do_neon_dyadic_i64_su (void)
13663{
037e8744 13664 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13665 struct neon_type_el et = neon_check_type (3, rs,
13666 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 13667 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13668}
13669
13670static void
13671neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 13672 unsigned immbits)
5287ad62
JB
13673{
13674 unsigned size = et.size >> 3;
13675 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13676 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13677 inst.instruction |= LOW4 (inst.operands[1].reg);
13678 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13679 inst.instruction |= (isquad != 0) << 6;
13680 inst.instruction |= immbits << 16;
13681 inst.instruction |= (size >> 3) << 7;
13682 inst.instruction |= (size & 0x7) << 19;
13683 if (write_ubit)
13684 inst.instruction |= (uval != 0) << 24;
13685
88714cb8 13686 neon_dp_fixup (&inst);
5287ad62
JB
13687}
13688
13689static void
13690do_neon_shl_imm (void)
13691{
13692 if (!inst.operands[2].isreg)
13693 {
037e8744 13694 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 13695 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
88714cb8 13696 NEON_ENCODE (IMMED, inst);
037e8744 13697 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
13698 }
13699 else
13700 {
037e8744 13701 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 13702 struct neon_type_el et = neon_check_type (3, rs,
477330fc 13703 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13704 unsigned int tmp;
13705
13706 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
13707 vshl.xx Dd, Dm, Dn
13708 whereas other 3-register operations encoded by neon_three_same have
13709 syntax like:
13710 vadd.xx Dd, Dn, Dm
13711 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
13712 here. */
627907b7
JB
13713 tmp = inst.operands[2].reg;
13714 inst.operands[2].reg = inst.operands[1].reg;
13715 inst.operands[1].reg = tmp;
88714cb8 13716 NEON_ENCODE (INTEGER, inst);
037e8744 13717 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13718 }
13719}
13720
13721static void
13722do_neon_qshl_imm (void)
13723{
13724 if (!inst.operands[2].isreg)
13725 {
037e8744 13726 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 13727 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 13728
88714cb8 13729 NEON_ENCODE (IMMED, inst);
037e8744 13730 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 13731 inst.operands[2].imm);
5287ad62
JB
13732 }
13733 else
13734 {
037e8744 13735 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 13736 struct neon_type_el et = neon_check_type (3, rs,
477330fc 13737 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13738 unsigned int tmp;
13739
13740 /* See note in do_neon_shl_imm. */
13741 tmp = inst.operands[2].reg;
13742 inst.operands[2].reg = inst.operands[1].reg;
13743 inst.operands[1].reg = tmp;
88714cb8 13744 NEON_ENCODE (INTEGER, inst);
037e8744 13745 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13746 }
13747}
13748
627907b7
JB
13749static void
13750do_neon_rshl (void)
13751{
13752 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13753 struct neon_type_el et = neon_check_type (3, rs,
13754 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13755 unsigned int tmp;
13756
13757 tmp = inst.operands[2].reg;
13758 inst.operands[2].reg = inst.operands[1].reg;
13759 inst.operands[1].reg = tmp;
13760 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13761}
13762
5287ad62
JB
13763static int
13764neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
13765{
036dc3f7
PB
13766 /* Handle .I8 pseudo-instructions. */
13767 if (size == 8)
5287ad62 13768 {
5287ad62 13769 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
13770 FIXME is this the intended semantics? There doesn't seem much point in
13771 accepting .I8 if so. */
5287ad62
JB
13772 immediate |= immediate << 8;
13773 size = 16;
036dc3f7
PB
13774 }
13775
13776 if (size >= 32)
13777 {
13778 if (immediate == (immediate & 0x000000ff))
13779 {
13780 *immbits = immediate;
13781 return 0x1;
13782 }
13783 else if (immediate == (immediate & 0x0000ff00))
13784 {
13785 *immbits = immediate >> 8;
13786 return 0x3;
13787 }
13788 else if (immediate == (immediate & 0x00ff0000))
13789 {
13790 *immbits = immediate >> 16;
13791 return 0x5;
13792 }
13793 else if (immediate == (immediate & 0xff000000))
13794 {
13795 *immbits = immediate >> 24;
13796 return 0x7;
13797 }
13798 if ((immediate & 0xffff) != (immediate >> 16))
13799 goto bad_immediate;
13800 immediate &= 0xffff;
5287ad62
JB
13801 }
13802
13803 if (immediate == (immediate & 0x000000ff))
13804 {
13805 *immbits = immediate;
036dc3f7 13806 return 0x9;
5287ad62
JB
13807 }
13808 else if (immediate == (immediate & 0x0000ff00))
13809 {
13810 *immbits = immediate >> 8;
036dc3f7 13811 return 0xb;
5287ad62
JB
13812 }
13813
13814 bad_immediate:
dcbf9037 13815 first_error (_("immediate value out of range"));
5287ad62
JB
13816 return FAIL;
13817}
13818
13819/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
13820 A, B, C, D. */
13821
13822static int
13823neon_bits_same_in_bytes (unsigned imm)
13824{
13825 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
477330fc
RM
13826 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
13827 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
13828 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
5287ad62
JB
13829}
13830
13831/* For immediate of above form, return 0bABCD. */
13832
13833static unsigned
13834neon_squash_bits (unsigned imm)
13835{
13836 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
477330fc 13837 | ((imm & 0x01000000) >> 21);
5287ad62
JB
13838}
13839
136da414 13840/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
13841
13842static unsigned
13843neon_qfloat_bits (unsigned imm)
13844{
136da414 13845 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
13846}
13847
13848/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
13849 the instruction. *OP is passed as the initial value of the op field, and
13850 may be set to a different value depending on the constant (i.e.
13851 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 13852 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 13853 try smaller element sizes. */
5287ad62
JB
13854
13855static int
c96612cc
JB
13856neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
13857 unsigned *immbits, int *op, int size,
13858 enum neon_el_type type)
5287ad62 13859{
c96612cc
JB
13860 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13861 float. */
13862 if (type == NT_float && !float_p)
13863 return FAIL;
13864
136da414
JB
13865 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13866 {
13867 if (size != 32 || *op == 1)
477330fc 13868 return FAIL;
136da414
JB
13869 *immbits = neon_qfloat_bits (immlo);
13870 return 0xf;
13871 }
036dc3f7
PB
13872
13873 if (size == 64)
5287ad62 13874 {
036dc3f7
PB
13875 if (neon_bits_same_in_bytes (immhi)
13876 && neon_bits_same_in_bytes (immlo))
13877 {
13878 if (*op == 1)
13879 return FAIL;
13880 *immbits = (neon_squash_bits (immhi) << 4)
13881 | neon_squash_bits (immlo);
13882 *op = 1;
13883 return 0xe;
13884 }
13885
13886 if (immhi != immlo)
13887 return FAIL;
5287ad62 13888 }
036dc3f7
PB
13889
13890 if (size >= 32)
5287ad62 13891 {
036dc3f7
PB
13892 if (immlo == (immlo & 0x000000ff))
13893 {
13894 *immbits = immlo;
13895 return 0x0;
13896 }
13897 else if (immlo == (immlo & 0x0000ff00))
13898 {
13899 *immbits = immlo >> 8;
13900 return 0x2;
13901 }
13902 else if (immlo == (immlo & 0x00ff0000))
13903 {
13904 *immbits = immlo >> 16;
13905 return 0x4;
13906 }
13907 else if (immlo == (immlo & 0xff000000))
13908 {
13909 *immbits = immlo >> 24;
13910 return 0x6;
13911 }
13912 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13913 {
13914 *immbits = (immlo >> 8) & 0xff;
13915 return 0xc;
13916 }
13917 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13918 {
13919 *immbits = (immlo >> 16) & 0xff;
13920 return 0xd;
13921 }
13922
13923 if ((immlo & 0xffff) != (immlo >> 16))
13924 return FAIL;
13925 immlo &= 0xffff;
5287ad62 13926 }
036dc3f7
PB
13927
13928 if (size >= 16)
5287ad62 13929 {
036dc3f7
PB
13930 if (immlo == (immlo & 0x000000ff))
13931 {
13932 *immbits = immlo;
13933 return 0x8;
13934 }
13935 else if (immlo == (immlo & 0x0000ff00))
13936 {
13937 *immbits = immlo >> 8;
13938 return 0xa;
13939 }
13940
13941 if ((immlo & 0xff) != (immlo >> 8))
13942 return FAIL;
13943 immlo &= 0xff;
5287ad62 13944 }
036dc3f7
PB
13945
13946 if (immlo == (immlo & 0x000000ff))
5287ad62 13947 {
036dc3f7
PB
13948 /* Don't allow MVN with 8-bit immediate. */
13949 if (*op == 1)
13950 return FAIL;
13951 *immbits = immlo;
13952 return 0xe;
5287ad62 13953 }
5287ad62
JB
13954
13955 return FAIL;
13956}
13957
13958/* Write immediate bits [7:0] to the following locations:
13959
13960 |28/24|23 19|18 16|15 4|3 0|
13961 | 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|
13962
13963 This function is used by VMOV/VMVN/VORR/VBIC. */
13964
13965static void
13966neon_write_immbits (unsigned immbits)
13967{
13968 inst.instruction |= immbits & 0xf;
13969 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13970 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13971}
13972
13973/* Invert low-order SIZE bits of XHI:XLO. */
13974
13975static void
13976neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13977{
13978 unsigned immlo = xlo ? *xlo : 0;
13979 unsigned immhi = xhi ? *xhi : 0;
13980
13981 switch (size)
13982 {
13983 case 8:
13984 immlo = (~immlo) & 0xff;
13985 break;
13986
13987 case 16:
13988 immlo = (~immlo) & 0xffff;
13989 break;
13990
13991 case 64:
13992 immhi = (~immhi) & 0xffffffff;
13993 /* fall through. */
13994
13995 case 32:
13996 immlo = (~immlo) & 0xffffffff;
13997 break;
13998
13999 default:
14000 abort ();
14001 }
14002
14003 if (xlo)
14004 *xlo = immlo;
14005
14006 if (xhi)
14007 *xhi = immhi;
14008}
14009
14010static void
14011do_neon_logic (void)
14012{
14013 if (inst.operands[2].present && inst.operands[2].isreg)
14014 {
037e8744 14015 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14016 neon_check_type (3, rs, N_IGNORE_TYPE);
14017 /* U bit and size field were set as part of the bitmask. */
88714cb8 14018 NEON_ENCODE (INTEGER, inst);
037e8744 14019 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14020 }
14021 else
14022 {
4316f0d2
DG
14023 const int three_ops_form = (inst.operands[2].present
14024 && !inst.operands[2].isreg);
14025 const int immoperand = (three_ops_form ? 2 : 1);
14026 enum neon_shape rs = (three_ops_form
14027 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14028 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14029 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14030 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14031 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14032 unsigned immbits;
14033 int cmode;
5f4273c7 14034
5287ad62 14035 if (et.type == NT_invtype)
477330fc 14036 return;
5f4273c7 14037
4316f0d2
DG
14038 if (three_ops_form)
14039 constraint (inst.operands[0].reg != inst.operands[1].reg,
14040 _("first and second operands shall be the same register"));
14041
88714cb8 14042 NEON_ENCODE (IMMED, inst);
5287ad62 14043
4316f0d2 14044 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14045 if (et.size == 64)
14046 {
14047 /* .i64 is a pseudo-op, so the immediate must be a repeating
14048 pattern. */
4316f0d2
DG
14049 if (immbits != (inst.operands[immoperand].regisimm ?
14050 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14051 {
14052 /* Set immbits to an invalid constant. */
14053 immbits = 0xdeadbeef;
14054 }
14055 }
14056
5287ad62 14057 switch (opcode)
477330fc
RM
14058 {
14059 case N_MNEM_vbic:
14060 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14061 break;
14062
14063 case N_MNEM_vorr:
14064 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14065 break;
14066
14067 case N_MNEM_vand:
14068 /* Pseudo-instruction for VBIC. */
14069 neon_invert_size (&immbits, 0, et.size);
14070 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14071 break;
14072
14073 case N_MNEM_vorn:
14074 /* Pseudo-instruction for VORR. */
14075 neon_invert_size (&immbits, 0, et.size);
14076 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14077 break;
14078
14079 default:
14080 abort ();
14081 }
5287ad62
JB
14082
14083 if (cmode == FAIL)
477330fc 14084 return;
5287ad62 14085
037e8744 14086 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14087 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14088 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14089 inst.instruction |= cmode << 8;
14090 neon_write_immbits (immbits);
5f4273c7 14091
88714cb8 14092 neon_dp_fixup (&inst);
5287ad62
JB
14093 }
14094}
14095
14096static void
14097do_neon_bitfield (void)
14098{
037e8744 14099 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14100 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14101 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14102}
14103
14104static void
dcbf9037 14105neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14106 unsigned destbits)
5287ad62 14107{
037e8744 14108 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14109 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14110 types | N_KEY);
5287ad62
JB
14111 if (et.type == NT_float)
14112 {
88714cb8 14113 NEON_ENCODE (FLOAT, inst);
037e8744 14114 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14115 }
14116 else
14117 {
88714cb8 14118 NEON_ENCODE (INTEGER, inst);
037e8744 14119 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14120 }
14121}
14122
14123static void
14124do_neon_dyadic_if_su (void)
14125{
dcbf9037 14126 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14127}
14128
14129static void
14130do_neon_dyadic_if_su_d (void)
14131{
14132 /* This version only allow D registers, but that constraint is enforced during
14133 operand parsing so we don't need to do anything extra here. */
dcbf9037 14134 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14135}
14136
5287ad62
JB
14137static void
14138do_neon_dyadic_if_i_d (void)
14139{
428e3f1f
PB
14140 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14141 affected if we specify unsigned args. */
14142 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14143}
14144
037e8744
JB
14145enum vfp_or_neon_is_neon_bits
14146{
14147 NEON_CHECK_CC = 1,
73924fbc
MGD
14148 NEON_CHECK_ARCH = 2,
14149 NEON_CHECK_ARCH8 = 4
037e8744
JB
14150};
14151
14152/* Call this function if an instruction which may have belonged to the VFP or
14153 Neon instruction sets, but turned out to be a Neon instruction (due to the
14154 operand types involved, etc.). We have to check and/or fix-up a couple of
14155 things:
14156
14157 - Make sure the user hasn't attempted to make a Neon instruction
14158 conditional.
14159 - Alter the value in the condition code field if necessary.
14160 - Make sure that the arch supports Neon instructions.
14161
14162 Which of these operations take place depends on bits from enum
14163 vfp_or_neon_is_neon_bits.
14164
14165 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14166 current instruction's condition is COND_ALWAYS, the condition field is
14167 changed to inst.uncond_value. This is necessary because instructions shared
14168 between VFP and Neon may be conditional for the VFP variants only, and the
14169 unconditional Neon version must have, e.g., 0xF in the condition field. */
14170
14171static int
14172vfp_or_neon_is_neon (unsigned check)
14173{
14174 /* Conditions are always legal in Thumb mode (IT blocks). */
14175 if (!thumb_mode && (check & NEON_CHECK_CC))
14176 {
14177 if (inst.cond != COND_ALWAYS)
477330fc
RM
14178 {
14179 first_error (_(BAD_COND));
14180 return FAIL;
14181 }
037e8744 14182 if (inst.uncond_value != -1)
477330fc 14183 inst.instruction |= inst.uncond_value << 28;
037e8744 14184 }
5f4273c7 14185
037e8744 14186 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14187 && !mark_feature_used (&fpu_neon_ext_v1))
14188 {
14189 first_error (_(BAD_FPU));
14190 return FAIL;
14191 }
14192
14193 if ((check & NEON_CHECK_ARCH8)
14194 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14195 {
14196 first_error (_(BAD_FPU));
14197 return FAIL;
14198 }
5f4273c7 14199
037e8744
JB
14200 return SUCCESS;
14201}
14202
5287ad62
JB
14203static void
14204do_neon_addsub_if_i (void)
14205{
037e8744
JB
14206 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14207 return;
14208
14209 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14210 return;
14211
5287ad62
JB
14212 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14213 affected if we specify unsigned args. */
dcbf9037 14214 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14215}
14216
14217/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14218 result to be:
14219 V<op> A,B (A is operand 0, B is operand 2)
14220 to mean:
14221 V<op> A,B,A
14222 not:
14223 V<op> A,B,B
14224 so handle that case specially. */
14225
14226static void
14227neon_exchange_operands (void)
14228{
14229 void *scratch = alloca (sizeof (inst.operands[0]));
14230 if (inst.operands[1].present)
14231 {
14232 /* Swap operands[1] and operands[2]. */
14233 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14234 inst.operands[1] = inst.operands[2];
14235 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
14236 }
14237 else
14238 {
14239 inst.operands[1] = inst.operands[2];
14240 inst.operands[2] = inst.operands[0];
14241 }
14242}
14243
14244static void
14245neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14246{
14247 if (inst.operands[2].isreg)
14248 {
14249 if (invert)
477330fc 14250 neon_exchange_operands ();
dcbf9037 14251 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14252 }
14253 else
14254 {
037e8744 14255 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 14256 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14257 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 14258
88714cb8 14259 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14260 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14261 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14262 inst.instruction |= LOW4 (inst.operands[1].reg);
14263 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14264 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14265 inst.instruction |= (et.type == NT_float) << 10;
14266 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14267
88714cb8 14268 neon_dp_fixup (&inst);
5287ad62
JB
14269 }
14270}
14271
14272static void
14273do_neon_cmp (void)
14274{
14275 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
14276}
14277
14278static void
14279do_neon_cmp_inv (void)
14280{
14281 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
14282}
14283
14284static void
14285do_neon_ceq (void)
14286{
14287 neon_compare (N_IF_32, N_IF_32, FALSE);
14288}
14289
14290/* For multiply instructions, we have the possibility of 16-bit or 32-bit
14291 scalars, which are encoded in 5 bits, M : Rm.
14292 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14293 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14294 index in M. */
14295
14296static unsigned
14297neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14298{
dcbf9037
JB
14299 unsigned regno = NEON_SCALAR_REG (scalar);
14300 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
14301
14302 switch (elsize)
14303 {
14304 case 16:
14305 if (regno > 7 || elno > 3)
477330fc 14306 goto bad_scalar;
5287ad62 14307 return regno | (elno << 3);
5f4273c7 14308
5287ad62
JB
14309 case 32:
14310 if (regno > 15 || elno > 1)
477330fc 14311 goto bad_scalar;
5287ad62
JB
14312 return regno | (elno << 4);
14313
14314 default:
14315 bad_scalar:
dcbf9037 14316 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
14317 }
14318
14319 return 0;
14320}
14321
14322/* Encode multiply / multiply-accumulate scalar instructions. */
14323
14324static void
14325neon_mul_mac (struct neon_type_el et, int ubit)
14326{
dcbf9037
JB
14327 unsigned scalar;
14328
14329 /* Give a more helpful error message if we have an invalid type. */
14330 if (et.type == NT_invtype)
14331 return;
5f4273c7 14332
dcbf9037 14333 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
14334 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14335 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14336 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14337 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14338 inst.instruction |= LOW4 (scalar);
14339 inst.instruction |= HI1 (scalar) << 5;
14340 inst.instruction |= (et.type == NT_float) << 8;
14341 inst.instruction |= neon_logbits (et.size) << 20;
14342 inst.instruction |= (ubit != 0) << 24;
14343
88714cb8 14344 neon_dp_fixup (&inst);
5287ad62
JB
14345}
14346
14347static void
14348do_neon_mac_maybe_scalar (void)
14349{
037e8744
JB
14350 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14351 return;
14352
14353 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14354 return;
14355
5287ad62
JB
14356 if (inst.operands[2].isscalar)
14357 {
037e8744 14358 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 14359 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14360 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 14361 NEON_ENCODE (SCALAR, inst);
037e8744 14362 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14363 }
14364 else
428e3f1f
PB
14365 {
14366 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14367 affected if we specify unsigned args. */
14368 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14369 }
5287ad62
JB
14370}
14371
62f3b8c8
PB
14372static void
14373do_neon_fmac (void)
14374{
14375 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
14376 return;
14377
14378 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14379 return;
14380
14381 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14382}
14383
5287ad62
JB
14384static void
14385do_neon_tst (void)
14386{
037e8744 14387 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14388 struct neon_type_el et = neon_check_type (3, rs,
14389 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 14390 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14391}
14392
14393/* VMUL with 3 registers allows the P8 type. The scalar version supports the
14394 same types as the MAC equivalents. The polynomial type for this instruction
14395 is encoded the same as the integer type. */
14396
14397static void
14398do_neon_mul (void)
14399{
037e8744
JB
14400 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14401 return;
14402
14403 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14404 return;
14405
5287ad62
JB
14406 if (inst.operands[2].isscalar)
14407 do_neon_mac_maybe_scalar ();
14408 else
dcbf9037 14409 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
14410}
14411
14412static void
14413do_neon_qdmulh (void)
14414{
14415 if (inst.operands[2].isscalar)
14416 {
037e8744 14417 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 14418 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14419 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14420 NEON_ENCODE (SCALAR, inst);
037e8744 14421 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14422 }
14423 else
14424 {
037e8744 14425 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14426 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14427 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14428 NEON_ENCODE (INTEGER, inst);
5287ad62 14429 /* The U bit (rounding) comes from bit mask. */
037e8744 14430 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14431 }
14432}
14433
14434static void
14435do_neon_fcmp_absolute (void)
14436{
037e8744 14437 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14438 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14439 /* Size field comes from bit mask. */
037e8744 14440 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
14441}
14442
14443static void
14444do_neon_fcmp_absolute_inv (void)
14445{
14446 neon_exchange_operands ();
14447 do_neon_fcmp_absolute ();
14448}
14449
14450static void
14451do_neon_step (void)
14452{
037e8744 14453 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14454 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 14455 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14456}
14457
14458static void
14459do_neon_abs_neg (void)
14460{
037e8744
JB
14461 enum neon_shape rs;
14462 struct neon_type_el et;
5f4273c7 14463
037e8744
JB
14464 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
14465 return;
14466
14467 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14468 return;
14469
14470 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14471 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 14472
5287ad62
JB
14473 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14474 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14475 inst.instruction |= LOW4 (inst.operands[1].reg);
14476 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14477 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14478 inst.instruction |= (et.type == NT_float) << 10;
14479 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14480
88714cb8 14481 neon_dp_fixup (&inst);
5287ad62
JB
14482}
14483
14484static void
14485do_neon_sli (void)
14486{
037e8744 14487 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14488 struct neon_type_el et = neon_check_type (2, rs,
14489 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14490 int imm = inst.operands[2].imm;
14491 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 14492 _("immediate out of range for insert"));
037e8744 14493 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14494}
14495
14496static void
14497do_neon_sri (void)
14498{
037e8744 14499 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14500 struct neon_type_el et = neon_check_type (2, rs,
14501 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14502 int imm = inst.operands[2].imm;
14503 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14504 _("immediate out of range for insert"));
037e8744 14505 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
14506}
14507
14508static void
14509do_neon_qshlu_imm (void)
14510{
037e8744 14511 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14512 struct neon_type_el et = neon_check_type (2, rs,
14513 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14514 int imm = inst.operands[2].imm;
14515 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 14516 _("immediate out of range for shift"));
5287ad62
JB
14517 /* Only encodes the 'U present' variant of the instruction.
14518 In this case, signed types have OP (bit 8) set to 0.
14519 Unsigned types have OP set to 1. */
14520 inst.instruction |= (et.type == NT_unsigned) << 8;
14521 /* The rest of the bits are the same as other immediate shifts. */
037e8744 14522 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14523}
14524
14525static void
14526do_neon_qmovn (void)
14527{
14528 struct neon_type_el et = neon_check_type (2, NS_DQ,
14529 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14530 /* Saturating move where operands can be signed or unsigned, and the
14531 destination has the same signedness. */
88714cb8 14532 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14533 if (et.type == NT_unsigned)
14534 inst.instruction |= 0xc0;
14535 else
14536 inst.instruction |= 0x80;
14537 neon_two_same (0, 1, et.size / 2);
14538}
14539
14540static void
14541do_neon_qmovun (void)
14542{
14543 struct neon_type_el et = neon_check_type (2, NS_DQ,
14544 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14545 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 14546 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14547 neon_two_same (0, 1, et.size / 2);
14548}
14549
14550static void
14551do_neon_rshift_sat_narrow (void)
14552{
14553 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14554 or unsigned. If operands are unsigned, results must also be unsigned. */
14555 struct neon_type_el et = neon_check_type (2, NS_DQI,
14556 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14557 int imm = inst.operands[2].imm;
14558 /* This gets the bounds check, size encoding and immediate bits calculation
14559 right. */
14560 et.size /= 2;
5f4273c7 14561
5287ad62
JB
14562 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14563 VQMOVN.I<size> <Dd>, <Qm>. */
14564 if (imm == 0)
14565 {
14566 inst.operands[2].present = 0;
14567 inst.instruction = N_MNEM_vqmovn;
14568 do_neon_qmovn ();
14569 return;
14570 }
5f4273c7 14571
5287ad62 14572 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14573 _("immediate out of range"));
5287ad62
JB
14574 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14575}
14576
14577static void
14578do_neon_rshift_sat_narrow_u (void)
14579{
14580 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14581 or unsigned. If operands are unsigned, results must also be unsigned. */
14582 struct neon_type_el et = neon_check_type (2, NS_DQI,
14583 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14584 int imm = inst.operands[2].imm;
14585 /* This gets the bounds check, size encoding and immediate bits calculation
14586 right. */
14587 et.size /= 2;
14588
14589 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14590 VQMOVUN.I<size> <Dd>, <Qm>. */
14591 if (imm == 0)
14592 {
14593 inst.operands[2].present = 0;
14594 inst.instruction = N_MNEM_vqmovun;
14595 do_neon_qmovun ();
14596 return;
14597 }
14598
14599 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14600 _("immediate out of range"));
5287ad62
JB
14601 /* FIXME: The manual is kind of unclear about what value U should have in
14602 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
14603 must be 1. */
14604 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
14605}
14606
14607static void
14608do_neon_movn (void)
14609{
14610 struct neon_type_el et = neon_check_type (2, NS_DQ,
14611 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 14612 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14613 neon_two_same (0, 1, et.size / 2);
14614}
14615
14616static void
14617do_neon_rshift_narrow (void)
14618{
14619 struct neon_type_el et = neon_check_type (2, NS_DQI,
14620 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14621 int imm = inst.operands[2].imm;
14622 /* This gets the bounds check, size encoding and immediate bits calculation
14623 right. */
14624 et.size /= 2;
5f4273c7 14625
5287ad62
JB
14626 /* If immediate is zero then we are a pseudo-instruction for
14627 VMOVN.I<size> <Dd>, <Qm> */
14628 if (imm == 0)
14629 {
14630 inst.operands[2].present = 0;
14631 inst.instruction = N_MNEM_vmovn;
14632 do_neon_movn ();
14633 return;
14634 }
5f4273c7 14635
5287ad62 14636 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14637 _("immediate out of range for narrowing operation"));
5287ad62
JB
14638 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
14639}
14640
14641static void
14642do_neon_shll (void)
14643{
14644 /* FIXME: Type checking when lengthening. */
14645 struct neon_type_el et = neon_check_type (2, NS_QDI,
14646 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
14647 unsigned imm = inst.operands[2].imm;
14648
14649 if (imm == et.size)
14650 {
14651 /* Maximum shift variant. */
88714cb8 14652 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14653 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14654 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14655 inst.instruction |= LOW4 (inst.operands[1].reg);
14656 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14657 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14658
88714cb8 14659 neon_dp_fixup (&inst);
5287ad62
JB
14660 }
14661 else
14662 {
14663 /* A more-specific type check for non-max versions. */
14664 et = neon_check_type (2, NS_QDI,
477330fc 14665 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 14666 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14667 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
14668 }
14669}
14670
037e8744 14671/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
14672 the current instruction is. */
14673
6b9a8b67
MGD
14674#define CVT_FLAVOUR_VAR \
14675 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
14676 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
14677 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
14678 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
14679 /* Half-precision conversions. */ \
14680 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
14681 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
14682 /* VFP instructions. */ \
14683 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
14684 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
14685 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
14686 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
14687 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
14688 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
14689 /* VFP instructions with bitshift. */ \
14690 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
14691 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
14692 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
14693 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
14694 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
14695 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
14696 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
14697 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
14698
14699#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
14700 neon_cvt_flavour_##C,
14701
14702/* The different types of conversions we can do. */
14703enum neon_cvt_flavour
14704{
14705 CVT_FLAVOUR_VAR
14706 neon_cvt_flavour_invalid,
14707 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
14708};
14709
14710#undef CVT_VAR
14711
14712static enum neon_cvt_flavour
14713get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 14714{
6b9a8b67
MGD
14715#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
14716 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
14717 if (et.type != NT_invtype) \
14718 { \
14719 inst.error = NULL; \
14720 return (neon_cvt_flavour_##C); \
5287ad62 14721 }
6b9a8b67 14722
5287ad62 14723 struct neon_type_el et;
037e8744 14724 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 14725 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
14726 /* The instruction versions which take an immediate take one register
14727 argument, which is extended to the width of the full register. Thus the
14728 "source" and "destination" registers must have the same width. Hack that
14729 here by making the size equal to the key (wider, in this case) operand. */
14730 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 14731
6b9a8b67
MGD
14732 CVT_FLAVOUR_VAR;
14733
14734 return neon_cvt_flavour_invalid;
5287ad62
JB
14735#undef CVT_VAR
14736}
14737
7e8e6784
MGD
14738enum neon_cvt_mode
14739{
14740 neon_cvt_mode_a,
14741 neon_cvt_mode_n,
14742 neon_cvt_mode_p,
14743 neon_cvt_mode_m,
14744 neon_cvt_mode_z,
30bdf752
MGD
14745 neon_cvt_mode_x,
14746 neon_cvt_mode_r
7e8e6784
MGD
14747};
14748
037e8744
JB
14749/* Neon-syntax VFP conversions. */
14750
5287ad62 14751static void
6b9a8b67 14752do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 14753{
037e8744 14754 const char *opname = 0;
5f4273c7 14755
037e8744 14756 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 14757 {
037e8744
JB
14758 /* Conversions with immediate bitshift. */
14759 const char *enc[] =
477330fc 14760 {
6b9a8b67
MGD
14761#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
14762 CVT_FLAVOUR_VAR
14763 NULL
14764#undef CVT_VAR
477330fc 14765 };
037e8744 14766
6b9a8b67 14767 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
14768 {
14769 opname = enc[flavour];
14770 constraint (inst.operands[0].reg != inst.operands[1].reg,
14771 _("operands 0 and 1 must be the same register"));
14772 inst.operands[1] = inst.operands[2];
14773 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
14774 }
5287ad62
JB
14775 }
14776 else
14777 {
037e8744
JB
14778 /* Conversions without bitshift. */
14779 const char *enc[] =
477330fc 14780 {
6b9a8b67
MGD
14781#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
14782 CVT_FLAVOUR_VAR
14783 NULL
14784#undef CVT_VAR
477330fc 14785 };
037e8744 14786
6b9a8b67 14787 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 14788 opname = enc[flavour];
037e8744
JB
14789 }
14790
14791 if (opname)
14792 do_vfp_nsyn_opcode (opname);
14793}
14794
14795static void
14796do_vfp_nsyn_cvtz (void)
14797{
14798 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
6b9a8b67 14799 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
14800 const char *enc[] =
14801 {
6b9a8b67
MGD
14802#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
14803 CVT_FLAVOUR_VAR
14804 NULL
14805#undef CVT_VAR
037e8744
JB
14806 };
14807
6b9a8b67 14808 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
14809 do_vfp_nsyn_opcode (enc[flavour]);
14810}
f31fef98 14811
037e8744 14812static void
bacebabc 14813do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
14814 enum neon_cvt_mode mode)
14815{
14816 int sz, op;
14817 int rm;
14818
14819 set_it_insn_type (OUTSIDE_IT_INSN);
14820
14821 switch (flavour)
14822 {
14823 case neon_cvt_flavour_s32_f64:
14824 sz = 1;
827f64ff 14825 op = 1;
7e8e6784
MGD
14826 break;
14827 case neon_cvt_flavour_s32_f32:
14828 sz = 0;
14829 op = 1;
14830 break;
14831 case neon_cvt_flavour_u32_f64:
14832 sz = 1;
14833 op = 0;
14834 break;
14835 case neon_cvt_flavour_u32_f32:
14836 sz = 0;
14837 op = 0;
14838 break;
14839 default:
14840 first_error (_("invalid instruction shape"));
14841 return;
14842 }
14843
14844 switch (mode)
14845 {
14846 case neon_cvt_mode_a: rm = 0; break;
14847 case neon_cvt_mode_n: rm = 1; break;
14848 case neon_cvt_mode_p: rm = 2; break;
14849 case neon_cvt_mode_m: rm = 3; break;
14850 default: first_error (_("invalid rounding mode")); return;
14851 }
14852
14853 NEON_ENCODE (FPV8, inst);
14854 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14855 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
14856 inst.instruction |= sz << 8;
14857 inst.instruction |= op << 7;
14858 inst.instruction |= rm << 16;
14859 inst.instruction |= 0xf0000000;
14860 inst.is_neon = TRUE;
14861}
14862
14863static void
14864do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
14865{
14866 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 14867 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
6b9a8b67 14868 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 14869
e3e535bc 14870 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 14871 if (mode == neon_cvt_mode_z
e3e535bc 14872 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
bacebabc
RM
14873 && (flavour == neon_cvt_flavour_s32_f32
14874 || flavour == neon_cvt_flavour_u32_f32
14875 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 14876 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
14877 && (rs == NS_FD || rs == NS_FF))
14878 {
14879 do_vfp_nsyn_cvtz ();
14880 return;
14881 }
14882
037e8744 14883 /* VFP rather than Neon conversions. */
6b9a8b67 14884 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 14885 {
7e8e6784
MGD
14886 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
14887 do_vfp_nsyn_cvt (rs, flavour);
14888 else
14889 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
14890
037e8744
JB
14891 return;
14892 }
14893
14894 switch (rs)
14895 {
14896 case NS_DDI:
14897 case NS_QQI:
14898 {
477330fc
RM
14899 unsigned immbits;
14900 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
35997600 14901
477330fc
RM
14902 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14903 return;
037e8744 14904
477330fc
RM
14905 /* Fixed-point conversion with #0 immediate is encoded as an
14906 integer conversion. */
14907 if (inst.operands[2].present && inst.operands[2].imm == 0)
14908 goto int_encode;
35997600 14909 immbits = 32 - inst.operands[2].imm;
477330fc
RM
14910 NEON_ENCODE (IMMED, inst);
14911 if (flavour != neon_cvt_flavour_invalid)
14912 inst.instruction |= enctab[flavour];
14913 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14914 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14915 inst.instruction |= LOW4 (inst.operands[1].reg);
14916 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14917 inst.instruction |= neon_quad (rs) << 6;
14918 inst.instruction |= 1 << 21;
14919 inst.instruction |= immbits << 16;
14920
14921 neon_dp_fixup (&inst);
037e8744
JB
14922 }
14923 break;
14924
14925 case NS_DD:
14926 case NS_QQ:
7e8e6784
MGD
14927 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
14928 {
14929 NEON_ENCODE (FLOAT, inst);
14930 set_it_insn_type (OUTSIDE_IT_INSN);
14931
14932 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
14933 return;
14934
14935 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14936 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14937 inst.instruction |= LOW4 (inst.operands[1].reg);
14938 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14939 inst.instruction |= neon_quad (rs) << 6;
14940 inst.instruction |= (flavour == neon_cvt_flavour_u32_f32) << 7;
14941 inst.instruction |= mode << 8;
14942 if (thumb_mode)
14943 inst.instruction |= 0xfc000000;
14944 else
14945 inst.instruction |= 0xf0000000;
14946 }
14947 else
14948 {
037e8744 14949 int_encode:
7e8e6784
MGD
14950 {
14951 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
037e8744 14952
7e8e6784 14953 NEON_ENCODE (INTEGER, inst);
037e8744 14954
7e8e6784
MGD
14955 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14956 return;
037e8744 14957
7e8e6784
MGD
14958 if (flavour != neon_cvt_flavour_invalid)
14959 inst.instruction |= enctab[flavour];
037e8744 14960
7e8e6784
MGD
14961 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14962 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14963 inst.instruction |= LOW4 (inst.operands[1].reg);
14964 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14965 inst.instruction |= neon_quad (rs) << 6;
14966 inst.instruction |= 2 << 18;
037e8744 14967
7e8e6784
MGD
14968 neon_dp_fixup (&inst);
14969 }
14970 }
14971 break;
037e8744 14972
8e79c3df
CM
14973 /* Half-precision conversions for Advanced SIMD -- neon. */
14974 case NS_QD:
14975 case NS_DQ:
14976
14977 if ((rs == NS_DQ)
14978 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14979 {
14980 as_bad (_("operand size must match register width"));
14981 break;
14982 }
14983
14984 if ((rs == NS_QD)
14985 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14986 {
14987 as_bad (_("operand size must match register width"));
14988 break;
14989 }
14990
14991 if (rs == NS_DQ)
477330fc 14992 inst.instruction = 0x3b60600;
8e79c3df
CM
14993 else
14994 inst.instruction = 0x3b60700;
14995
14996 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14997 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14998 inst.instruction |= LOW4 (inst.operands[1].reg);
14999 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15000 neon_dp_fixup (&inst);
8e79c3df
CM
15001 break;
15002
037e8744
JB
15003 default:
15004 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15005 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15006 do_vfp_nsyn_cvt (rs, flavour);
15007 else
15008 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15009 }
5287ad62
JB
15010}
15011
e3e535bc
NC
15012static void
15013do_neon_cvtr (void)
15014{
7e8e6784 15015 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15016}
15017
15018static void
15019do_neon_cvt (void)
15020{
7e8e6784
MGD
15021 do_neon_cvt_1 (neon_cvt_mode_z);
15022}
15023
15024static void
15025do_neon_cvta (void)
15026{
15027 do_neon_cvt_1 (neon_cvt_mode_a);
15028}
15029
15030static void
15031do_neon_cvtn (void)
15032{
15033 do_neon_cvt_1 (neon_cvt_mode_n);
15034}
15035
15036static void
15037do_neon_cvtp (void)
15038{
15039 do_neon_cvt_1 (neon_cvt_mode_p);
15040}
15041
15042static void
15043do_neon_cvtm (void)
15044{
15045 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15046}
15047
8e79c3df 15048static void
c70a8987 15049do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15050{
c70a8987
MGD
15051 if (is_double)
15052 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15053
c70a8987
MGD
15054 encode_arm_vfp_reg (inst.operands[0].reg,
15055 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15056 encode_arm_vfp_reg (inst.operands[1].reg,
15057 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15058 inst.instruction |= to ? 0x10000 : 0;
15059 inst.instruction |= t ? 0x80 : 0;
15060 inst.instruction |= is_double ? 0x100 : 0;
15061 do_vfp_cond_or_thumb ();
15062}
8e79c3df 15063
c70a8987
MGD
15064static void
15065do_neon_cvttb_1 (bfd_boolean t)
15066{
15067 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_DF, NS_NULL);
8e79c3df 15068
c70a8987
MGD
15069 if (rs == NS_NULL)
15070 return;
15071 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15072 {
15073 inst.error = NULL;
15074 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15075 }
15076 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15077 {
15078 inst.error = NULL;
15079 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15080 }
15081 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15082 {
15083 inst.error = NULL;
15084 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15085 }
15086 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15087 {
15088 inst.error = NULL;
15089 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15090 }
15091 else
15092 return;
15093}
15094
15095static void
15096do_neon_cvtb (void)
15097{
15098 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15099}
15100
15101
15102static void
15103do_neon_cvtt (void)
15104{
c70a8987 15105 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15106}
15107
5287ad62
JB
15108static void
15109neon_move_immediate (void)
15110{
037e8744
JB
15111 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15112 struct neon_type_el et = neon_check_type (2, rs,
15113 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15114 unsigned immlo, immhi = 0, immbits;
c96612cc 15115 int op, cmode, float_p;
5287ad62 15116
037e8744 15117 constraint (et.type == NT_invtype,
477330fc 15118 _("operand size must be specified for immediate VMOV"));
037e8744 15119
5287ad62
JB
15120 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15121 op = (inst.instruction & (1 << 5)) != 0;
15122
15123 immlo = inst.operands[1].imm;
15124 if (inst.operands[1].regisimm)
15125 immhi = inst.operands[1].reg;
15126
15127 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 15128 _("immediate has bits set outside the operand size"));
5287ad62 15129
c96612cc
JB
15130 float_p = inst.operands[1].immisfloat;
15131
15132 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 15133 et.size, et.type)) == FAIL)
5287ad62
JB
15134 {
15135 /* Invert relevant bits only. */
15136 neon_invert_size (&immlo, &immhi, et.size);
15137 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
15138 with one or the other; those cases are caught by
15139 neon_cmode_for_move_imm. */
5287ad62 15140 op = !op;
c96612cc
JB
15141 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15142 &op, et.size, et.type)) == FAIL)
477330fc
RM
15143 {
15144 first_error (_("immediate out of range"));
15145 return;
15146 }
5287ad62
JB
15147 }
15148
15149 inst.instruction &= ~(1 << 5);
15150 inst.instruction |= op << 5;
15151
15152 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15153 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 15154 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15155 inst.instruction |= cmode << 8;
15156
15157 neon_write_immbits (immbits);
15158}
15159
15160static void
15161do_neon_mvn (void)
15162{
15163 if (inst.operands[1].isreg)
15164 {
037e8744 15165 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 15166
88714cb8 15167 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15168 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15169 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15170 inst.instruction |= LOW4 (inst.operands[1].reg);
15171 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15172 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15173 }
15174 else
15175 {
88714cb8 15176 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15177 neon_move_immediate ();
15178 }
15179
88714cb8 15180 neon_dp_fixup (&inst);
5287ad62
JB
15181}
15182
15183/* Encode instructions of form:
15184
15185 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 15186 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
15187
15188static void
15189neon_mixed_length (struct neon_type_el et, unsigned size)
15190{
15191 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15192 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15193 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15194 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15195 inst.instruction |= LOW4 (inst.operands[2].reg);
15196 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15197 inst.instruction |= (et.type == NT_unsigned) << 24;
15198 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 15199
88714cb8 15200 neon_dp_fixup (&inst);
5287ad62
JB
15201}
15202
15203static void
15204do_neon_dyadic_long (void)
15205{
15206 /* FIXME: Type checking for lengthening op. */
15207 struct neon_type_el et = neon_check_type (3, NS_QDD,
15208 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
15209 neon_mixed_length (et, et.size);
15210}
15211
15212static void
15213do_neon_abal (void)
15214{
15215 struct neon_type_el et = neon_check_type (3, NS_QDD,
15216 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
15217 neon_mixed_length (et, et.size);
15218}
15219
15220static void
15221neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
15222{
15223 if (inst.operands[2].isscalar)
15224 {
dcbf9037 15225 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 15226 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 15227 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15228 neon_mul_mac (et, et.type == NT_unsigned);
15229 }
15230 else
15231 {
15232 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 15233 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 15234 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15235 neon_mixed_length (et, et.size);
15236 }
15237}
15238
15239static void
15240do_neon_mac_maybe_scalar_long (void)
15241{
15242 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
15243}
15244
15245static void
15246do_neon_dyadic_wide (void)
15247{
15248 struct neon_type_el et = neon_check_type (3, NS_QQD,
15249 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
15250 neon_mixed_length (et, et.size);
15251}
15252
15253static void
15254do_neon_dyadic_narrow (void)
15255{
15256 struct neon_type_el et = neon_check_type (3, NS_QDD,
15257 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
15258 /* Operand sign is unimportant, and the U bit is part of the opcode,
15259 so force the operand type to integer. */
15260 et.type = NT_integer;
5287ad62
JB
15261 neon_mixed_length (et, et.size / 2);
15262}
15263
15264static void
15265do_neon_mul_sat_scalar_long (void)
15266{
15267 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
15268}
15269
15270static void
15271do_neon_vmull (void)
15272{
15273 if (inst.operands[2].isscalar)
15274 do_neon_mac_maybe_scalar_long ();
15275 else
15276 {
15277 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 15278 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 15279
5287ad62 15280 if (et.type == NT_poly)
477330fc 15281 NEON_ENCODE (POLY, inst);
5287ad62 15282 else
477330fc 15283 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
15284
15285 /* For polynomial encoding the U bit must be zero, and the size must
15286 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
15287 obviously, as 0b10). */
15288 if (et.size == 64)
15289 {
15290 /* Check we're on the correct architecture. */
15291 if (!mark_feature_used (&fpu_crypto_ext_armv8))
15292 inst.error =
15293 _("Instruction form not available on this architecture.");
15294
15295 et.size = 32;
15296 }
15297
5287ad62
JB
15298 neon_mixed_length (et, et.size);
15299 }
15300}
15301
15302static void
15303do_neon_ext (void)
15304{
037e8744 15305 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
15306 struct neon_type_el et = neon_check_type (3, rs,
15307 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15308 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
15309
15310 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
15311 _("shift out of range"));
5287ad62
JB
15312 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15313 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15314 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15315 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15316 inst.instruction |= LOW4 (inst.operands[2].reg);
15317 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 15318 inst.instruction |= neon_quad (rs) << 6;
5287ad62 15319 inst.instruction |= imm << 8;
5f4273c7 15320
88714cb8 15321 neon_dp_fixup (&inst);
5287ad62
JB
15322}
15323
15324static void
15325do_neon_rev (void)
15326{
037e8744 15327 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15328 struct neon_type_el et = neon_check_type (2, rs,
15329 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15330 unsigned op = (inst.instruction >> 7) & 3;
15331 /* N (width of reversed regions) is encoded as part of the bitmask. We
15332 extract it here to check the elements to be reversed are smaller.
15333 Otherwise we'd get a reserved instruction. */
15334 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 15335 gas_assert (elsize != 0);
5287ad62 15336 constraint (et.size >= elsize,
477330fc 15337 _("elements must be smaller than reversal region"));
037e8744 15338 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15339}
15340
15341static void
15342do_neon_dup (void)
15343{
15344 if (inst.operands[1].isscalar)
15345 {
037e8744 15346 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 15347 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15348 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 15349 unsigned sizebits = et.size >> 3;
dcbf9037 15350 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 15351 int logsize = neon_logbits (et.size);
dcbf9037 15352 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
15353
15354 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 15355 return;
037e8744 15356
88714cb8 15357 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15358 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15359 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15360 inst.instruction |= LOW4 (dm);
15361 inst.instruction |= HI1 (dm) << 5;
037e8744 15362 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15363 inst.instruction |= x << 17;
15364 inst.instruction |= sizebits << 16;
5f4273c7 15365
88714cb8 15366 neon_dp_fixup (&inst);
5287ad62
JB
15367 }
15368 else
15369 {
037e8744
JB
15370 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
15371 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15372 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 15373 /* Duplicate ARM register to lanes of vector. */
88714cb8 15374 NEON_ENCODE (ARMREG, inst);
5287ad62 15375 switch (et.size)
477330fc
RM
15376 {
15377 case 8: inst.instruction |= 0x400000; break;
15378 case 16: inst.instruction |= 0x000020; break;
15379 case 32: inst.instruction |= 0x000000; break;
15380 default: break;
15381 }
5287ad62
JB
15382 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15383 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
15384 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 15385 inst.instruction |= neon_quad (rs) << 21;
5287ad62 15386 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 15387 variants, except for the condition field. */
037e8744 15388 do_vfp_cond_or_thumb ();
5287ad62
JB
15389 }
15390}
15391
15392/* VMOV has particularly many variations. It can be one of:
15393 0. VMOV<c><q> <Qd>, <Qm>
15394 1. VMOV<c><q> <Dd>, <Dm>
15395 (Register operations, which are VORR with Rm = Rn.)
15396 2. VMOV<c><q>.<dt> <Qd>, #<imm>
15397 3. VMOV<c><q>.<dt> <Dd>, #<imm>
15398 (Immediate loads.)
15399 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
15400 (ARM register to scalar.)
15401 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
15402 (Two ARM registers to vector.)
15403 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
15404 (Scalar to ARM register.)
15405 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
15406 (Vector to two ARM registers.)
037e8744
JB
15407 8. VMOV.F32 <Sd>, <Sm>
15408 9. VMOV.F64 <Dd>, <Dm>
15409 (VFP register moves.)
15410 10. VMOV.F32 <Sd>, #imm
15411 11. VMOV.F64 <Dd>, #imm
15412 (VFP float immediate load.)
15413 12. VMOV <Rd>, <Sm>
15414 (VFP single to ARM reg.)
15415 13. VMOV <Sd>, <Rm>
15416 (ARM reg to VFP single.)
15417 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
15418 (Two ARM regs to two VFP singles.)
15419 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
15420 (Two VFP singles to two ARM regs.)
5f4273c7 15421
037e8744
JB
15422 These cases can be disambiguated using neon_select_shape, except cases 1/9
15423 and 3/11 which depend on the operand type too.
5f4273c7 15424
5287ad62 15425 All the encoded bits are hardcoded by this function.
5f4273c7 15426
b7fc2769
JB
15427 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
15428 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 15429
5287ad62 15430 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 15431 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
15432
15433static void
15434do_neon_mov (void)
15435{
037e8744
JB
15436 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
15437 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
15438 NS_NULL);
15439 struct neon_type_el et;
15440 const char *ldconst = 0;
5287ad62 15441
037e8744 15442 switch (rs)
5287ad62 15443 {
037e8744
JB
15444 case NS_DD: /* case 1/9. */
15445 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15446 /* It is not an error here if no type is given. */
15447 inst.error = NULL;
15448 if (et.type == NT_float && et.size == 64)
477330fc
RM
15449 {
15450 do_vfp_nsyn_opcode ("fcpyd");
15451 break;
15452 }
037e8744 15453 /* fall through. */
5287ad62 15454
037e8744
JB
15455 case NS_QQ: /* case 0/1. */
15456 {
477330fc
RM
15457 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15458 return;
15459 /* The architecture manual I have doesn't explicitly state which
15460 value the U bit should have for register->register moves, but
15461 the equivalent VORR instruction has U = 0, so do that. */
15462 inst.instruction = 0x0200110;
15463 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15464 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15465 inst.instruction |= LOW4 (inst.operands[1].reg);
15466 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15467 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15468 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15469 inst.instruction |= neon_quad (rs) << 6;
15470
15471 neon_dp_fixup (&inst);
037e8744
JB
15472 }
15473 break;
5f4273c7 15474
037e8744
JB
15475 case NS_DI: /* case 3/11. */
15476 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15477 inst.error = NULL;
15478 if (et.type == NT_float && et.size == 64)
477330fc
RM
15479 {
15480 /* case 11 (fconstd). */
15481 ldconst = "fconstd";
15482 goto encode_fconstd;
15483 }
037e8744
JB
15484 /* fall through. */
15485
15486 case NS_QI: /* case 2/3. */
15487 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 15488 return;
037e8744
JB
15489 inst.instruction = 0x0800010;
15490 neon_move_immediate ();
88714cb8 15491 neon_dp_fixup (&inst);
5287ad62 15492 break;
5f4273c7 15493
037e8744
JB
15494 case NS_SR: /* case 4. */
15495 {
477330fc
RM
15496 unsigned bcdebits = 0;
15497 int logsize;
15498 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
15499 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 15500
05ac0ffb
JB
15501 /* .<size> is optional here, defaulting to .32. */
15502 if (inst.vectype.elems == 0
15503 && inst.operands[0].vectype.type == NT_invtype
15504 && inst.operands[1].vectype.type == NT_invtype)
15505 {
15506 inst.vectype.el[0].type = NT_untyped;
15507 inst.vectype.el[0].size = 32;
15508 inst.vectype.elems = 1;
15509 }
15510
477330fc
RM
15511 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
15512 logsize = neon_logbits (et.size);
15513
15514 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15515 _(BAD_FPU));
15516 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15517 && et.size != 32, _(BAD_FPU));
15518 constraint (et.type == NT_invtype, _("bad type for scalar"));
15519 constraint (x >= 64 / et.size, _("scalar index out of range"));
15520
15521 switch (et.size)
15522 {
15523 case 8: bcdebits = 0x8; break;
15524 case 16: bcdebits = 0x1; break;
15525 case 32: bcdebits = 0x0; break;
15526 default: ;
15527 }
15528
15529 bcdebits |= x << logsize;
15530
15531 inst.instruction = 0xe000b10;
15532 do_vfp_cond_or_thumb ();
15533 inst.instruction |= LOW4 (dn) << 16;
15534 inst.instruction |= HI1 (dn) << 7;
15535 inst.instruction |= inst.operands[1].reg << 12;
15536 inst.instruction |= (bcdebits & 3) << 5;
15537 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
15538 }
15539 break;
5f4273c7 15540
037e8744 15541 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 15542 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 15543 _(BAD_FPU));
b7fc2769 15544
037e8744
JB
15545 inst.instruction = 0xc400b10;
15546 do_vfp_cond_or_thumb ();
15547 inst.instruction |= LOW4 (inst.operands[0].reg);
15548 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
15549 inst.instruction |= inst.operands[1].reg << 12;
15550 inst.instruction |= inst.operands[2].reg << 16;
15551 break;
5f4273c7 15552
037e8744
JB
15553 case NS_RS: /* case 6. */
15554 {
477330fc
RM
15555 unsigned logsize;
15556 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
15557 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
15558 unsigned abcdebits = 0;
037e8744 15559
05ac0ffb
JB
15560 /* .<dt> is optional here, defaulting to .32. */
15561 if (inst.vectype.elems == 0
15562 && inst.operands[0].vectype.type == NT_invtype
15563 && inst.operands[1].vectype.type == NT_invtype)
15564 {
15565 inst.vectype.el[0].type = NT_untyped;
15566 inst.vectype.el[0].size = 32;
15567 inst.vectype.elems = 1;
15568 }
15569
91d6fa6a
NC
15570 et = neon_check_type (2, NS_NULL,
15571 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
15572 logsize = neon_logbits (et.size);
15573
15574 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15575 _(BAD_FPU));
15576 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15577 && et.size != 32, _(BAD_FPU));
15578 constraint (et.type == NT_invtype, _("bad type for scalar"));
15579 constraint (x >= 64 / et.size, _("scalar index out of range"));
15580
15581 switch (et.size)
15582 {
15583 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
15584 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
15585 case 32: abcdebits = 0x00; break;
15586 default: ;
15587 }
15588
15589 abcdebits |= x << logsize;
15590 inst.instruction = 0xe100b10;
15591 do_vfp_cond_or_thumb ();
15592 inst.instruction |= LOW4 (dn) << 16;
15593 inst.instruction |= HI1 (dn) << 7;
15594 inst.instruction |= inst.operands[0].reg << 12;
15595 inst.instruction |= (abcdebits & 3) << 5;
15596 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
15597 }
15598 break;
5f4273c7 15599
037e8744
JB
15600 case NS_RRD: /* case 7 (fmrrd). */
15601 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 15602 _(BAD_FPU));
037e8744
JB
15603
15604 inst.instruction = 0xc500b10;
15605 do_vfp_cond_or_thumb ();
15606 inst.instruction |= inst.operands[0].reg << 12;
15607 inst.instruction |= inst.operands[1].reg << 16;
15608 inst.instruction |= LOW4 (inst.operands[2].reg);
15609 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15610 break;
5f4273c7 15611
037e8744
JB
15612 case NS_FF: /* case 8 (fcpys). */
15613 do_vfp_nsyn_opcode ("fcpys");
15614 break;
5f4273c7 15615
037e8744
JB
15616 case NS_FI: /* case 10 (fconsts). */
15617 ldconst = "fconsts";
15618 encode_fconstd:
15619 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
15620 {
15621 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
15622 do_vfp_nsyn_opcode (ldconst);
15623 }
5287ad62 15624 else
477330fc 15625 first_error (_("immediate out of range"));
037e8744 15626 break;
5f4273c7 15627
037e8744
JB
15628 case NS_RF: /* case 12 (fmrs). */
15629 do_vfp_nsyn_opcode ("fmrs");
15630 break;
5f4273c7 15631
037e8744
JB
15632 case NS_FR: /* case 13 (fmsr). */
15633 do_vfp_nsyn_opcode ("fmsr");
15634 break;
5f4273c7 15635
037e8744
JB
15636 /* The encoders for the fmrrs and fmsrr instructions expect three operands
15637 (one of which is a list), but we have parsed four. Do some fiddling to
15638 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
15639 expect. */
15640 case NS_RRFF: /* case 14 (fmrrs). */
15641 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 15642 _("VFP registers must be adjacent"));
037e8744
JB
15643 inst.operands[2].imm = 2;
15644 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15645 do_vfp_nsyn_opcode ("fmrrs");
15646 break;
5f4273c7 15647
037e8744
JB
15648 case NS_FFRR: /* case 15 (fmsrr). */
15649 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 15650 _("VFP registers must be adjacent"));
037e8744
JB
15651 inst.operands[1] = inst.operands[2];
15652 inst.operands[2] = inst.operands[3];
15653 inst.operands[0].imm = 2;
15654 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15655 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 15656 break;
5f4273c7 15657
4c261dff
NC
15658 case NS_NULL:
15659 /* neon_select_shape has determined that the instruction
15660 shape is wrong and has already set the error message. */
15661 break;
15662
5287ad62
JB
15663 default:
15664 abort ();
15665 }
15666}
15667
15668static void
15669do_neon_rshift_round_imm (void)
15670{
037e8744 15671 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15672 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
15673 int imm = inst.operands[2].imm;
15674
15675 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
15676 if (imm == 0)
15677 {
15678 inst.operands[2].present = 0;
15679 do_neon_mov ();
15680 return;
15681 }
15682
15683 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15684 _("immediate out of range for shift"));
037e8744 15685 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 15686 et.size - imm);
5287ad62
JB
15687}
15688
15689static void
15690do_neon_movl (void)
15691{
15692 struct neon_type_el et = neon_check_type (2, NS_QD,
15693 N_EQK | N_DBL, N_SU_32 | N_KEY);
15694 unsigned sizebits = et.size >> 3;
15695 inst.instruction |= sizebits << 19;
15696 neon_two_same (0, et.type == NT_unsigned, -1);
15697}
15698
15699static void
15700do_neon_trn (void)
15701{
037e8744 15702 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15703 struct neon_type_el et = neon_check_type (2, rs,
15704 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 15705 NEON_ENCODE (INTEGER, inst);
037e8744 15706 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15707}
15708
15709static void
15710do_neon_zip_uzp (void)
15711{
037e8744 15712 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15713 struct neon_type_el et = neon_check_type (2, rs,
15714 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15715 if (rs == NS_DD && et.size == 32)
15716 {
15717 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
15718 inst.instruction = N_MNEM_vtrn;
15719 do_neon_trn ();
15720 return;
15721 }
037e8744 15722 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15723}
15724
15725static void
15726do_neon_sat_abs_neg (void)
15727{
037e8744 15728 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15729 struct neon_type_el et = neon_check_type (2, rs,
15730 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 15731 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15732}
15733
15734static void
15735do_neon_pair_long (void)
15736{
037e8744 15737 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15738 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
15739 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
15740 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 15741 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15742}
15743
15744static void
15745do_neon_recip_est (void)
15746{
037e8744 15747 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15748 struct neon_type_el et = neon_check_type (2, rs,
15749 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
15750 inst.instruction |= (et.type == NT_float) << 8;
037e8744 15751 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15752}
15753
15754static void
15755do_neon_cls (void)
15756{
037e8744 15757 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15758 struct neon_type_el et = neon_check_type (2, rs,
15759 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 15760 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15761}
15762
15763static void
15764do_neon_clz (void)
15765{
037e8744 15766 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15767 struct neon_type_el et = neon_check_type (2, rs,
15768 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 15769 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15770}
15771
15772static void
15773do_neon_cnt (void)
15774{
037e8744 15775 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15776 struct neon_type_el et = neon_check_type (2, rs,
15777 N_EQK | N_INT, N_8 | N_KEY);
037e8744 15778 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15779}
15780
15781static void
15782do_neon_swp (void)
15783{
037e8744
JB
15784 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15785 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
15786}
15787
15788static void
15789do_neon_tbl_tbx (void)
15790{
15791 unsigned listlenbits;
dcbf9037 15792 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 15793
5287ad62
JB
15794 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
15795 {
dcbf9037 15796 first_error (_("bad list length for table lookup"));
5287ad62
JB
15797 return;
15798 }
5f4273c7 15799
5287ad62
JB
15800 listlenbits = inst.operands[1].imm - 1;
15801 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15802 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15803 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15804 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15805 inst.instruction |= LOW4 (inst.operands[2].reg);
15806 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15807 inst.instruction |= listlenbits << 8;
5f4273c7 15808
88714cb8 15809 neon_dp_fixup (&inst);
5287ad62
JB
15810}
15811
15812static void
15813do_neon_ldm_stm (void)
15814{
15815 /* P, U and L bits are part of bitmask. */
15816 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
15817 unsigned offsetbits = inst.operands[1].imm * 2;
15818
037e8744
JB
15819 if (inst.operands[1].issingle)
15820 {
15821 do_vfp_nsyn_ldm_stm (is_dbmode);
15822 return;
15823 }
15824
5287ad62 15825 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 15826 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
15827
15828 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
15829 _("register list must contain at least 1 and at most 16 "
15830 "registers"));
5287ad62
JB
15831
15832 inst.instruction |= inst.operands[0].reg << 16;
15833 inst.instruction |= inst.operands[0].writeback << 21;
15834 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15835 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
15836
15837 inst.instruction |= offsetbits;
5f4273c7 15838
037e8744 15839 do_vfp_cond_or_thumb ();
5287ad62
JB
15840}
15841
15842static void
15843do_neon_ldr_str (void)
15844{
5287ad62 15845 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 15846
6844b2c2
MGD
15847 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
15848 And is UNPREDICTABLE in thumb mode. */
fa94de6b 15849 if (!is_ldr
6844b2c2 15850 && inst.operands[1].reg == REG_PC
ba86b375 15851 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 15852 {
94dcf8bf 15853 if (thumb_mode)
6844b2c2 15854 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf
JB
15855 else if (warn_on_deprecated)
15856 as_warn (_("Use of PC here is deprecated"));
6844b2c2
MGD
15857 }
15858
037e8744
JB
15859 if (inst.operands[0].issingle)
15860 {
cd2f129f 15861 if (is_ldr)
477330fc 15862 do_vfp_nsyn_opcode ("flds");
cd2f129f 15863 else
477330fc 15864 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
15865 }
15866 else
5287ad62 15867 {
cd2f129f 15868 if (is_ldr)
477330fc 15869 do_vfp_nsyn_opcode ("fldd");
5287ad62 15870 else
477330fc 15871 do_vfp_nsyn_opcode ("fstd");
5287ad62 15872 }
5287ad62
JB
15873}
15874
15875/* "interleave" version also handles non-interleaving register VLD1/VST1
15876 instructions. */
15877
15878static void
15879do_neon_ld_st_interleave (void)
15880{
037e8744 15881 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 15882 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
15883 unsigned alignbits = 0;
15884 unsigned idx;
15885 /* The bits in this table go:
15886 0: register stride of one (0) or two (1)
15887 1,2: register list length, minus one (1, 2, 3, 4).
15888 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
15889 We use -1 for invalid entries. */
15890 const int typetable[] =
15891 {
15892 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
15893 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
15894 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
15895 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
15896 };
15897 int typebits;
15898
dcbf9037
JB
15899 if (et.type == NT_invtype)
15900 return;
15901
5287ad62
JB
15902 if (inst.operands[1].immisalign)
15903 switch (inst.operands[1].imm >> 8)
15904 {
15905 case 64: alignbits = 1; break;
15906 case 128:
477330fc 15907 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 15908 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
15909 goto bad_alignment;
15910 alignbits = 2;
15911 break;
5287ad62 15912 case 256:
477330fc
RM
15913 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
15914 goto bad_alignment;
15915 alignbits = 3;
15916 break;
5287ad62
JB
15917 default:
15918 bad_alignment:
477330fc
RM
15919 first_error (_("bad alignment"));
15920 return;
5287ad62
JB
15921 }
15922
15923 inst.instruction |= alignbits << 4;
15924 inst.instruction |= neon_logbits (et.size) << 6;
15925
15926 /* Bits [4:6] of the immediate in a list specifier encode register stride
15927 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
15928 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
15929 up the right value for "type" in a table based on this value and the given
15930 list style, then stick it back. */
15931 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 15932 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
15933
15934 typebits = typetable[idx];
5f4273c7 15935
5287ad62 15936 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
15937 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
15938 _("bad element type for instruction"));
5287ad62
JB
15939
15940 inst.instruction &= ~0xf00;
15941 inst.instruction |= typebits << 8;
15942}
15943
15944/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
15945 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
15946 otherwise. The variable arguments are a list of pairs of legal (size, align)
15947 values, terminated with -1. */
15948
15949static int
15950neon_alignment_bit (int size, int align, int *do_align, ...)
15951{
15952 va_list ap;
15953 int result = FAIL, thissize, thisalign;
5f4273c7 15954
5287ad62
JB
15955 if (!inst.operands[1].immisalign)
15956 {
15957 *do_align = 0;
15958 return SUCCESS;
15959 }
5f4273c7 15960
5287ad62
JB
15961 va_start (ap, do_align);
15962
15963 do
15964 {
15965 thissize = va_arg (ap, int);
15966 if (thissize == -1)
477330fc 15967 break;
5287ad62
JB
15968 thisalign = va_arg (ap, int);
15969
15970 if (size == thissize && align == thisalign)
477330fc 15971 result = SUCCESS;
5287ad62
JB
15972 }
15973 while (result != SUCCESS);
15974
15975 va_end (ap);
15976
15977 if (result == SUCCESS)
15978 *do_align = 1;
15979 else
dcbf9037 15980 first_error (_("unsupported alignment for instruction"));
5f4273c7 15981
5287ad62
JB
15982 return result;
15983}
15984
15985static void
15986do_neon_ld_st_lane (void)
15987{
037e8744 15988 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15989 int align_good, do_align = 0;
15990 int logsize = neon_logbits (et.size);
15991 int align = inst.operands[1].imm >> 8;
15992 int n = (inst.instruction >> 8) & 3;
15993 int max_el = 64 / et.size;
5f4273c7 15994
dcbf9037
JB
15995 if (et.type == NT_invtype)
15996 return;
5f4273c7 15997
5287ad62 15998 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 15999 _("bad list length"));
5287ad62 16000 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16001 _("scalar index out of range"));
5287ad62 16002 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16003 && et.size == 8,
16004 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16005
5287ad62
JB
16006 switch (n)
16007 {
16008 case 0: /* VLD1 / VST1. */
16009 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
477330fc 16010 32, 32, -1);
5287ad62 16011 if (align_good == FAIL)
477330fc 16012 return;
5287ad62 16013 if (do_align)
477330fc
RM
16014 {
16015 unsigned alignbits = 0;
16016 switch (et.size)
16017 {
16018 case 16: alignbits = 0x1; break;
16019 case 32: alignbits = 0x3; break;
16020 default: ;
16021 }
16022 inst.instruction |= alignbits << 4;
16023 }
5287ad62
JB
16024 break;
16025
16026 case 1: /* VLD2 / VST2. */
16027 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
477330fc 16028 32, 64, -1);
5287ad62 16029 if (align_good == FAIL)
477330fc 16030 return;
5287ad62 16031 if (do_align)
477330fc 16032 inst.instruction |= 1 << 4;
5287ad62
JB
16033 break;
16034
16035 case 2: /* VLD3 / VST3. */
16036 constraint (inst.operands[1].immisalign,
477330fc 16037 _("can't use alignment with this instruction"));
5287ad62
JB
16038 break;
16039
16040 case 3: /* VLD4 / VST4. */
16041 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
477330fc 16042 16, 64, 32, 64, 32, 128, -1);
5287ad62 16043 if (align_good == FAIL)
477330fc 16044 return;
5287ad62 16045 if (do_align)
477330fc
RM
16046 {
16047 unsigned alignbits = 0;
16048 switch (et.size)
16049 {
16050 case 8: alignbits = 0x1; break;
16051 case 16: alignbits = 0x1; break;
16052 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16053 default: ;
16054 }
16055 inst.instruction |= alignbits << 4;
16056 }
5287ad62
JB
16057 break;
16058
16059 default: ;
16060 }
16061
16062 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16063 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16064 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16065
5287ad62
JB
16066 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16067 inst.instruction |= logsize << 10;
16068}
16069
16070/* Encode single n-element structure to all lanes VLD<n> instructions. */
16071
16072static void
16073do_neon_ld_dup (void)
16074{
037e8744 16075 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
16076 int align_good, do_align = 0;
16077
dcbf9037
JB
16078 if (et.type == NT_invtype)
16079 return;
16080
5287ad62
JB
16081 switch ((inst.instruction >> 8) & 3)
16082 {
16083 case 0: /* VLD1. */
9c2799c2 16084 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16085 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
477330fc 16086 &do_align, 16, 16, 32, 32, -1);
5287ad62 16087 if (align_good == FAIL)
477330fc 16088 return;
5287ad62 16089 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
16090 {
16091 case 1: break;
16092 case 2: inst.instruction |= 1 << 5; break;
16093 default: first_error (_("bad list length")); return;
16094 }
5287ad62
JB
16095 inst.instruction |= neon_logbits (et.size) << 6;
16096 break;
16097
16098 case 1: /* VLD2. */
16099 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
477330fc 16100 &do_align, 8, 16, 16, 32, 32, 64, -1);
5287ad62 16101 if (align_good == FAIL)
477330fc 16102 return;
5287ad62 16103 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 16104 _("bad list length"));
5287ad62 16105 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16106 inst.instruction |= 1 << 5;
5287ad62
JB
16107 inst.instruction |= neon_logbits (et.size) << 6;
16108 break;
16109
16110 case 2: /* VLD3. */
16111 constraint (inst.operands[1].immisalign,
477330fc 16112 _("can't use alignment with this instruction"));
5287ad62 16113 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 16114 _("bad list length"));
5287ad62 16115 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16116 inst.instruction |= 1 << 5;
5287ad62
JB
16117 inst.instruction |= neon_logbits (et.size) << 6;
16118 break;
16119
16120 case 3: /* VLD4. */
16121 {
477330fc
RM
16122 int align = inst.operands[1].imm >> 8;
16123 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
16124 16, 64, 32, 64, 32, 128, -1);
16125 if (align_good == FAIL)
16126 return;
16127 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
16128 _("bad list length"));
16129 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16130 inst.instruction |= 1 << 5;
16131 if (et.size == 32 && align == 128)
16132 inst.instruction |= 0x3 << 6;
16133 else
16134 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
16135 }
16136 break;
16137
16138 default: ;
16139 }
16140
16141 inst.instruction |= do_align << 4;
16142}
16143
16144/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
16145 apart from bits [11:4]. */
16146
16147static void
16148do_neon_ldx_stx (void)
16149{
b1a769ed
DG
16150 if (inst.operands[1].isreg)
16151 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16152
5287ad62
JB
16153 switch (NEON_LANE (inst.operands[0].imm))
16154 {
16155 case NEON_INTERLEAVE_LANES:
88714cb8 16156 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
16157 do_neon_ld_st_interleave ();
16158 break;
5f4273c7 16159
5287ad62 16160 case NEON_ALL_LANES:
88714cb8 16161 NEON_ENCODE (DUP, inst);
2d51fb74
JB
16162 if (inst.instruction == N_INV)
16163 {
16164 first_error ("only loads support such operands");
16165 break;
16166 }
5287ad62
JB
16167 do_neon_ld_dup ();
16168 break;
5f4273c7 16169
5287ad62 16170 default:
88714cb8 16171 NEON_ENCODE (LANE, inst);
5287ad62
JB
16172 do_neon_ld_st_lane ();
16173 }
16174
16175 /* L bit comes from bit mask. */
16176 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16177 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16178 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 16179
5287ad62
JB
16180 if (inst.operands[1].postind)
16181 {
16182 int postreg = inst.operands[1].imm & 0xf;
16183 constraint (!inst.operands[1].immisreg,
477330fc 16184 _("post-index must be a register"));
5287ad62 16185 constraint (postreg == 0xd || postreg == 0xf,
477330fc 16186 _("bad register for post-index"));
5287ad62
JB
16187 inst.instruction |= postreg;
16188 }
4f2374c7 16189 else
5287ad62 16190 {
4f2374c7
WN
16191 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
16192 constraint (inst.reloc.exp.X_op != O_constant
16193 || inst.reloc.exp.X_add_number != 0,
16194 BAD_ADDR_MODE);
16195
16196 if (inst.operands[1].writeback)
16197 {
16198 inst.instruction |= 0xd;
16199 }
16200 else
16201 inst.instruction |= 0xf;
5287ad62 16202 }
5f4273c7 16203
5287ad62
JB
16204 if (thumb_mode)
16205 inst.instruction |= 0xf9000000;
16206 else
16207 inst.instruction |= 0xf4000000;
16208}
33399f07
MGD
16209
16210/* FP v8. */
16211static void
16212do_vfp_nsyn_fpv8 (enum neon_shape rs)
16213{
16214 NEON_ENCODE (FPV8, inst);
16215
16216 if (rs == NS_FFF)
16217 do_vfp_sp_dyadic ();
16218 else
16219 do_vfp_dp_rd_rn_rm ();
16220
16221 if (rs == NS_DDD)
16222 inst.instruction |= 0x100;
16223
16224 inst.instruction |= 0xf0000000;
16225}
16226
16227static void
16228do_vsel (void)
16229{
16230 set_it_insn_type (OUTSIDE_IT_INSN);
16231
16232 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
16233 first_error (_("invalid instruction shape"));
16234}
16235
73924fbc
MGD
16236static void
16237do_vmaxnm (void)
16238{
16239 set_it_insn_type (OUTSIDE_IT_INSN);
16240
16241 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
16242 return;
16243
16244 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16245 return;
16246
16247 neon_dyadic_misc (NT_untyped, N_F32, 0);
16248}
16249
30bdf752
MGD
16250static void
16251do_vrint_1 (enum neon_cvt_mode mode)
16252{
16253 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_QQ, NS_NULL);
16254 struct neon_type_el et;
16255
16256 if (rs == NS_NULL)
16257 return;
16258
16259 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
16260 if (et.type != NT_invtype)
16261 {
16262 /* VFP encodings. */
16263 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
16264 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
16265 set_it_insn_type (OUTSIDE_IT_INSN);
16266
16267 NEON_ENCODE (FPV8, inst);
16268 if (rs == NS_FF)
16269 do_vfp_sp_monadic ();
16270 else
16271 do_vfp_dp_rd_rm ();
16272
16273 switch (mode)
16274 {
16275 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
16276 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
16277 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
16278 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
16279 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
16280 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
16281 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
16282 default: abort ();
16283 }
16284
16285 inst.instruction |= (rs == NS_DD) << 8;
16286 do_vfp_cond_or_thumb ();
16287 }
16288 else
16289 {
16290 /* Neon encodings (or something broken...). */
16291 inst.error = NULL;
16292 et = neon_check_type (2, rs, N_EQK, N_F32 | N_KEY);
16293
16294 if (et.type == NT_invtype)
16295 return;
16296
16297 set_it_insn_type (OUTSIDE_IT_INSN);
16298 NEON_ENCODE (FLOAT, inst);
16299
16300 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16301 return;
16302
16303 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16304 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16305 inst.instruction |= LOW4 (inst.operands[1].reg);
16306 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16307 inst.instruction |= neon_quad (rs) << 6;
16308 switch (mode)
16309 {
16310 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
16311 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
16312 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
16313 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
16314 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
16315 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
16316 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
16317 default: abort ();
16318 }
16319
16320 if (thumb_mode)
16321 inst.instruction |= 0xfc000000;
16322 else
16323 inst.instruction |= 0xf0000000;
16324 }
16325}
16326
16327static void
16328do_vrintx (void)
16329{
16330 do_vrint_1 (neon_cvt_mode_x);
16331}
16332
16333static void
16334do_vrintz (void)
16335{
16336 do_vrint_1 (neon_cvt_mode_z);
16337}
16338
16339static void
16340do_vrintr (void)
16341{
16342 do_vrint_1 (neon_cvt_mode_r);
16343}
16344
16345static void
16346do_vrinta (void)
16347{
16348 do_vrint_1 (neon_cvt_mode_a);
16349}
16350
16351static void
16352do_vrintn (void)
16353{
16354 do_vrint_1 (neon_cvt_mode_n);
16355}
16356
16357static void
16358do_vrintp (void)
16359{
16360 do_vrint_1 (neon_cvt_mode_p);
16361}
16362
16363static void
16364do_vrintm (void)
16365{
16366 do_vrint_1 (neon_cvt_mode_m);
16367}
16368
91ff7894
MGD
16369/* Crypto v1 instructions. */
16370static void
16371do_crypto_2op_1 (unsigned elttype, int op)
16372{
16373 set_it_insn_type (OUTSIDE_IT_INSN);
16374
16375 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
16376 == NT_invtype)
16377 return;
16378
16379 inst.error = NULL;
16380
16381 NEON_ENCODE (INTEGER, inst);
16382 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16383 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16384 inst.instruction |= LOW4 (inst.operands[1].reg);
16385 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16386 if (op != -1)
16387 inst.instruction |= op << 6;
16388
16389 if (thumb_mode)
16390 inst.instruction |= 0xfc000000;
16391 else
16392 inst.instruction |= 0xf0000000;
16393}
16394
48adcd8e
MGD
16395static void
16396do_crypto_3op_1 (int u, int op)
16397{
16398 set_it_insn_type (OUTSIDE_IT_INSN);
16399
16400 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
16401 N_32 | N_UNT | N_KEY).type == NT_invtype)
16402 return;
16403
16404 inst.error = NULL;
16405
16406 NEON_ENCODE (INTEGER, inst);
16407 neon_three_same (1, u, 8 << op);
16408}
16409
91ff7894
MGD
16410static void
16411do_aese (void)
16412{
16413 do_crypto_2op_1 (N_8, 0);
16414}
16415
16416static void
16417do_aesd (void)
16418{
16419 do_crypto_2op_1 (N_8, 1);
16420}
16421
16422static void
16423do_aesmc (void)
16424{
16425 do_crypto_2op_1 (N_8, 2);
16426}
16427
16428static void
16429do_aesimc (void)
16430{
16431 do_crypto_2op_1 (N_8, 3);
16432}
16433
48adcd8e
MGD
16434static void
16435do_sha1c (void)
16436{
16437 do_crypto_3op_1 (0, 0);
16438}
16439
16440static void
16441do_sha1p (void)
16442{
16443 do_crypto_3op_1 (0, 1);
16444}
16445
16446static void
16447do_sha1m (void)
16448{
16449 do_crypto_3op_1 (0, 2);
16450}
16451
16452static void
16453do_sha1su0 (void)
16454{
16455 do_crypto_3op_1 (0, 3);
16456}
91ff7894 16457
48adcd8e
MGD
16458static void
16459do_sha256h (void)
16460{
16461 do_crypto_3op_1 (1, 0);
16462}
16463
16464static void
16465do_sha256h2 (void)
16466{
16467 do_crypto_3op_1 (1, 1);
16468}
16469
16470static void
16471do_sha256su1 (void)
16472{
16473 do_crypto_3op_1 (1, 2);
16474}
3c9017d2
MGD
16475
16476static void
16477do_sha1h (void)
16478{
16479 do_crypto_2op_1 (N_32, -1);
16480}
16481
16482static void
16483do_sha1su1 (void)
16484{
16485 do_crypto_2op_1 (N_32, 0);
16486}
16487
16488static void
16489do_sha256su0 (void)
16490{
16491 do_crypto_2op_1 (N_32, 1);
16492}
dd5181d5
KT
16493
16494static void
16495do_crc32_1 (unsigned int poly, unsigned int sz)
16496{
16497 unsigned int Rd = inst.operands[0].reg;
16498 unsigned int Rn = inst.operands[1].reg;
16499 unsigned int Rm = inst.operands[2].reg;
16500
16501 set_it_insn_type (OUTSIDE_IT_INSN);
16502 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
16503 inst.instruction |= LOW4 (Rn) << 16;
16504 inst.instruction |= LOW4 (Rm);
16505 inst.instruction |= sz << (thumb_mode ? 4 : 21);
16506 inst.instruction |= poly << (thumb_mode ? 20 : 9);
16507
16508 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
16509 as_warn (UNPRED_REG ("r15"));
16510 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
16511 as_warn (UNPRED_REG ("r13"));
16512}
16513
16514static void
16515do_crc32b (void)
16516{
16517 do_crc32_1 (0, 0);
16518}
16519
16520static void
16521do_crc32h (void)
16522{
16523 do_crc32_1 (0, 1);
16524}
16525
16526static void
16527do_crc32w (void)
16528{
16529 do_crc32_1 (0, 2);
16530}
16531
16532static void
16533do_crc32cb (void)
16534{
16535 do_crc32_1 (1, 0);
16536}
16537
16538static void
16539do_crc32ch (void)
16540{
16541 do_crc32_1 (1, 1);
16542}
16543
16544static void
16545do_crc32cw (void)
16546{
16547 do_crc32_1 (1, 2);
16548}
16549
5287ad62
JB
16550\f
16551/* Overall per-instruction processing. */
16552
16553/* We need to be able to fix up arbitrary expressions in some statements.
16554 This is so that we can handle symbols that are an arbitrary distance from
16555 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
16556 which returns part of an address in a form which will be valid for
16557 a data instruction. We do this by pushing the expression into a symbol
16558 in the expr_section, and creating a fix for that. */
16559
16560static void
16561fix_new_arm (fragS * frag,
16562 int where,
16563 short int size,
16564 expressionS * exp,
16565 int pc_rel,
16566 int reloc)
16567{
16568 fixS * new_fix;
16569
16570 switch (exp->X_op)
16571 {
16572 case O_constant:
6e7ce2cd
PB
16573 if (pc_rel)
16574 {
16575 /* Create an absolute valued symbol, so we have something to
477330fc
RM
16576 refer to in the object file. Unfortunately for us, gas's
16577 generic expression parsing will already have folded out
16578 any use of .set foo/.type foo %function that may have
16579 been used to set type information of the target location,
16580 that's being specified symbolically. We have to presume
16581 the user knows what they are doing. */
6e7ce2cd
PB
16582 char name[16 + 8];
16583 symbolS *symbol;
16584
16585 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
16586
16587 symbol = symbol_find_or_make (name);
16588 S_SET_SEGMENT (symbol, absolute_section);
16589 symbol_set_frag (symbol, &zero_address_frag);
16590 S_SET_VALUE (symbol, exp->X_add_number);
16591 exp->X_op = O_symbol;
16592 exp->X_add_symbol = symbol;
16593 exp->X_add_number = 0;
16594 }
16595 /* FALLTHROUGH */
5287ad62
JB
16596 case O_symbol:
16597 case O_add:
16598 case O_subtract:
21d799b5 16599 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 16600 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
16601 break;
16602
16603 default:
21d799b5 16604 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 16605 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
16606 break;
16607 }
16608
16609 /* Mark whether the fix is to a THUMB instruction, or an ARM
16610 instruction. */
16611 new_fix->tc_fix_data = thumb_mode;
16612}
16613
16614/* Create a frg for an instruction requiring relaxation. */
16615static void
16616output_relax_insn (void)
16617{
16618 char * to;
16619 symbolS *sym;
0110f2b8
PB
16620 int offset;
16621
6e1cb1a6
PB
16622 /* The size of the instruction is unknown, so tie the debug info to the
16623 start of the instruction. */
16624 dwarf2_emit_insn (0);
6e1cb1a6 16625
0110f2b8
PB
16626 switch (inst.reloc.exp.X_op)
16627 {
16628 case O_symbol:
16629 sym = inst.reloc.exp.X_add_symbol;
16630 offset = inst.reloc.exp.X_add_number;
16631 break;
16632 case O_constant:
16633 sym = NULL;
16634 offset = inst.reloc.exp.X_add_number;
16635 break;
16636 default:
16637 sym = make_expr_symbol (&inst.reloc.exp);
16638 offset = 0;
16639 break;
16640 }
16641 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
16642 inst.relax, sym, offset, NULL/*offset, opcode*/);
16643 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
16644}
16645
16646/* Write a 32-bit thumb instruction to buf. */
16647static void
16648put_thumb32_insn (char * buf, unsigned long insn)
16649{
16650 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
16651 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
16652}
16653
b99bd4ef 16654static void
c19d1205 16655output_inst (const char * str)
b99bd4ef 16656{
c19d1205 16657 char * to = NULL;
b99bd4ef 16658
c19d1205 16659 if (inst.error)
b99bd4ef 16660 {
c19d1205 16661 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
16662 return;
16663 }
5f4273c7
NC
16664 if (inst.relax)
16665 {
16666 output_relax_insn ();
0110f2b8 16667 return;
5f4273c7 16668 }
c19d1205
ZW
16669 if (inst.size == 0)
16670 return;
b99bd4ef 16671
c19d1205 16672 to = frag_more (inst.size);
8dc2430f
NC
16673 /* PR 9814: Record the thumb mode into the current frag so that we know
16674 what type of NOP padding to use, if necessary. We override any previous
16675 setting so that if the mode has changed then the NOPS that we use will
16676 match the encoding of the last instruction in the frag. */
cd000bff 16677 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
16678
16679 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 16680 {
9c2799c2 16681 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 16682 put_thumb32_insn (to, inst.instruction);
b99bd4ef 16683 }
c19d1205 16684 else if (inst.size > INSN_SIZE)
b99bd4ef 16685 {
9c2799c2 16686 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
16687 md_number_to_chars (to, inst.instruction, INSN_SIZE);
16688 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 16689 }
c19d1205
ZW
16690 else
16691 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 16692
c19d1205
ZW
16693 if (inst.reloc.type != BFD_RELOC_UNUSED)
16694 fix_new_arm (frag_now, to - frag_now->fr_literal,
16695 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
16696 inst.reloc.type);
b99bd4ef 16697
c19d1205 16698 dwarf2_emit_insn (inst.size);
c19d1205 16699}
b99bd4ef 16700
e07e6e58
NC
16701static char *
16702output_it_inst (int cond, int mask, char * to)
16703{
16704 unsigned long instruction = 0xbf00;
16705
16706 mask &= 0xf;
16707 instruction |= mask;
16708 instruction |= cond << 4;
16709
16710 if (to == NULL)
16711 {
16712 to = frag_more (2);
16713#ifdef OBJ_ELF
16714 dwarf2_emit_insn (2);
16715#endif
16716 }
16717
16718 md_number_to_chars (to, instruction, 2);
16719
16720 return to;
16721}
16722
c19d1205
ZW
16723/* Tag values used in struct asm_opcode's tag field. */
16724enum opcode_tag
16725{
16726 OT_unconditional, /* Instruction cannot be conditionalized.
16727 The ARM condition field is still 0xE. */
16728 OT_unconditionalF, /* Instruction cannot be conditionalized
16729 and carries 0xF in its ARM condition field. */
16730 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 16731 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
16732 suffix, others place 0xF where the condition field
16733 would be. */
c19d1205
ZW
16734 OT_cinfix3, /* Instruction takes a conditional infix,
16735 beginning at character index 3. (In
16736 unified mode, it becomes a suffix.) */
088fa78e
KH
16737 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
16738 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
16739 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
16740 character index 3, even in unified mode. Used for
16741 legacy instructions where suffix and infix forms
16742 may be ambiguous. */
c19d1205 16743 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 16744 suffix or an infix at character index 3. */
c19d1205
ZW
16745 OT_odd_infix_unc, /* This is the unconditional variant of an
16746 instruction that takes a conditional infix
16747 at an unusual position. In unified mode,
16748 this variant will accept a suffix. */
16749 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
16750 are the conditional variants of instructions that
16751 take conditional infixes in unusual positions.
16752 The infix appears at character index
16753 (tag - OT_odd_infix_0). These are not accepted
16754 in unified mode. */
16755};
b99bd4ef 16756
c19d1205
ZW
16757/* Subroutine of md_assemble, responsible for looking up the primary
16758 opcode from the mnemonic the user wrote. STR points to the
16759 beginning of the mnemonic.
16760
16761 This is not simply a hash table lookup, because of conditional
16762 variants. Most instructions have conditional variants, which are
16763 expressed with a _conditional affix_ to the mnemonic. If we were
16764 to encode each conditional variant as a literal string in the opcode
16765 table, it would have approximately 20,000 entries.
16766
16767 Most mnemonics take this affix as a suffix, and in unified syntax,
16768 'most' is upgraded to 'all'. However, in the divided syntax, some
16769 instructions take the affix as an infix, notably the s-variants of
16770 the arithmetic instructions. Of those instructions, all but six
16771 have the infix appear after the third character of the mnemonic.
16772
16773 Accordingly, the algorithm for looking up primary opcodes given
16774 an identifier is:
16775
16776 1. Look up the identifier in the opcode table.
16777 If we find a match, go to step U.
16778
16779 2. Look up the last two characters of the identifier in the
16780 conditions table. If we find a match, look up the first N-2
16781 characters of the identifier in the opcode table. If we
16782 find a match, go to step CE.
16783
16784 3. Look up the fourth and fifth characters of the identifier in
16785 the conditions table. If we find a match, extract those
16786 characters from the identifier, and look up the remaining
16787 characters in the opcode table. If we find a match, go
16788 to step CM.
16789
16790 4. Fail.
16791
16792 U. Examine the tag field of the opcode structure, in case this is
16793 one of the six instructions with its conditional infix in an
16794 unusual place. If it is, the tag tells us where to find the
16795 infix; look it up in the conditions table and set inst.cond
16796 accordingly. Otherwise, this is an unconditional instruction.
16797 Again set inst.cond accordingly. Return the opcode structure.
16798
16799 CE. Examine the tag field to make sure this is an instruction that
16800 should receive a conditional suffix. If it is not, fail.
16801 Otherwise, set inst.cond from the suffix we already looked up,
16802 and return the opcode structure.
16803
16804 CM. Examine the tag field to make sure this is an instruction that
16805 should receive a conditional infix after the third character.
16806 If it is not, fail. Otherwise, undo the edits to the current
16807 line of input and proceed as for case CE. */
16808
16809static const struct asm_opcode *
16810opcode_lookup (char **str)
16811{
16812 char *end, *base;
16813 char *affix;
16814 const struct asm_opcode *opcode;
16815 const struct asm_cond *cond;
e3cb604e 16816 char save[2];
c19d1205
ZW
16817
16818 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 16819 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 16820 for (base = end = *str; *end != '\0'; end++)
721a8186 16821 if (*end == ' ' || *end == '.')
c19d1205 16822 break;
b99bd4ef 16823
c19d1205 16824 if (end == base)
c921be7d 16825 return NULL;
b99bd4ef 16826
5287ad62 16827 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 16828 if (end[0] == '.')
b99bd4ef 16829 {
5287ad62 16830 int offset = 2;
5f4273c7 16831
267d2029 16832 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 16833 use. */
267d2029 16834 if (unified_syntax && end[1] == 'w')
c19d1205 16835 inst.size_req = 4;
267d2029 16836 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
16837 inst.size_req = 2;
16838 else
477330fc 16839 offset = 0;
5287ad62
JB
16840
16841 inst.vectype.elems = 0;
16842
16843 *str = end + offset;
b99bd4ef 16844
5f4273c7 16845 if (end[offset] == '.')
5287ad62 16846 {
267d2029 16847 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
16848 non-unified ARM syntax mode). */
16849 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 16850 return NULL;
477330fc 16851 }
5287ad62 16852 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 16853 return NULL;
b99bd4ef 16854 }
c19d1205
ZW
16855 else
16856 *str = end;
b99bd4ef 16857
c19d1205 16858 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 16859 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 16860 end - base);
c19d1205 16861 if (opcode)
b99bd4ef 16862 {
c19d1205
ZW
16863 /* step U */
16864 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 16865 {
c19d1205
ZW
16866 inst.cond = COND_ALWAYS;
16867 return opcode;
b99bd4ef 16868 }
b99bd4ef 16869
278df34e 16870 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
16871 as_warn (_("conditional infixes are deprecated in unified syntax"));
16872 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 16873 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 16874 gas_assert (cond);
b99bd4ef 16875
c19d1205
ZW
16876 inst.cond = cond->value;
16877 return opcode;
16878 }
b99bd4ef 16879
c19d1205
ZW
16880 /* Cannot have a conditional suffix on a mnemonic of less than two
16881 characters. */
16882 if (end - base < 3)
c921be7d 16883 return NULL;
b99bd4ef 16884
c19d1205
ZW
16885 /* Look for suffixed mnemonic. */
16886 affix = end - 2;
21d799b5
NC
16887 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
16888 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 16889 affix - base);
c19d1205
ZW
16890 if (opcode && cond)
16891 {
16892 /* step CE */
16893 switch (opcode->tag)
16894 {
e3cb604e
PB
16895 case OT_cinfix3_legacy:
16896 /* Ignore conditional suffixes matched on infix only mnemonics. */
16897 break;
16898
c19d1205 16899 case OT_cinfix3:
088fa78e 16900 case OT_cinfix3_deprecated:
c19d1205
ZW
16901 case OT_odd_infix_unc:
16902 if (!unified_syntax)
e3cb604e 16903 return 0;
c19d1205
ZW
16904 /* else fall through */
16905
16906 case OT_csuffix:
477330fc 16907 case OT_csuffixF:
c19d1205
ZW
16908 case OT_csuf_or_in3:
16909 inst.cond = cond->value;
16910 return opcode;
16911
16912 case OT_unconditional:
16913 case OT_unconditionalF:
dfa9f0d5 16914 if (thumb_mode)
c921be7d 16915 inst.cond = cond->value;
dfa9f0d5
PB
16916 else
16917 {
c921be7d 16918 /* Delayed diagnostic. */
dfa9f0d5
PB
16919 inst.error = BAD_COND;
16920 inst.cond = COND_ALWAYS;
16921 }
c19d1205 16922 return opcode;
b99bd4ef 16923
c19d1205 16924 default:
c921be7d 16925 return NULL;
c19d1205
ZW
16926 }
16927 }
b99bd4ef 16928
c19d1205
ZW
16929 /* Cannot have a usual-position infix on a mnemonic of less than
16930 six characters (five would be a suffix). */
16931 if (end - base < 6)
c921be7d 16932 return NULL;
b99bd4ef 16933
c19d1205
ZW
16934 /* Look for infixed mnemonic in the usual position. */
16935 affix = base + 3;
21d799b5 16936 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 16937 if (!cond)
c921be7d 16938 return NULL;
e3cb604e
PB
16939
16940 memcpy (save, affix, 2);
16941 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 16942 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 16943 (end - base) - 2);
e3cb604e
PB
16944 memmove (affix + 2, affix, (end - affix) - 2);
16945 memcpy (affix, save, 2);
16946
088fa78e
KH
16947 if (opcode
16948 && (opcode->tag == OT_cinfix3
16949 || opcode->tag == OT_cinfix3_deprecated
16950 || opcode->tag == OT_csuf_or_in3
16951 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 16952 {
c921be7d 16953 /* Step CM. */
278df34e 16954 if (warn_on_deprecated && unified_syntax
088fa78e
KH
16955 && (opcode->tag == OT_cinfix3
16956 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
16957 as_warn (_("conditional infixes are deprecated in unified syntax"));
16958
16959 inst.cond = cond->value;
16960 return opcode;
b99bd4ef
NC
16961 }
16962
c921be7d 16963 return NULL;
b99bd4ef
NC
16964}
16965
e07e6e58
NC
16966/* This function generates an initial IT instruction, leaving its block
16967 virtually open for the new instructions. Eventually,
16968 the mask will be updated by now_it_add_mask () each time
16969 a new instruction needs to be included in the IT block.
16970 Finally, the block is closed with close_automatic_it_block ().
16971 The block closure can be requested either from md_assemble (),
16972 a tencode (), or due to a label hook. */
16973
16974static void
16975new_automatic_it_block (int cond)
16976{
16977 now_it.state = AUTOMATIC_IT_BLOCK;
16978 now_it.mask = 0x18;
16979 now_it.cc = cond;
16980 now_it.block_length = 1;
cd000bff 16981 mapping_state (MAP_THUMB);
e07e6e58 16982 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
16983 now_it.warn_deprecated = FALSE;
16984 now_it.insn_cond = TRUE;
e07e6e58
NC
16985}
16986
16987/* Close an automatic IT block.
16988 See comments in new_automatic_it_block (). */
16989
16990static void
16991close_automatic_it_block (void)
16992{
16993 now_it.mask = 0x10;
16994 now_it.block_length = 0;
16995}
16996
16997/* Update the mask of the current automatically-generated IT
16998 instruction. See comments in new_automatic_it_block (). */
16999
17000static void
17001now_it_add_mask (int cond)
17002{
17003#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
17004#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 17005 | ((bitvalue) << (nbit)))
e07e6e58 17006 const int resulting_bit = (cond & 1);
c921be7d 17007
e07e6e58
NC
17008 now_it.mask &= 0xf;
17009 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17010 resulting_bit,
17011 (5 - now_it.block_length));
e07e6e58 17012 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17013 1,
17014 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
17015 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
17016
17017#undef CLEAR_BIT
17018#undef SET_BIT_VALUE
e07e6e58
NC
17019}
17020
17021/* The IT blocks handling machinery is accessed through the these functions:
17022 it_fsm_pre_encode () from md_assemble ()
17023 set_it_insn_type () optional, from the tencode functions
17024 set_it_insn_type_last () ditto
17025 in_it_block () ditto
17026 it_fsm_post_encode () from md_assemble ()
17027 force_automatic_it_block_close () from label habdling functions
17028
17029 Rationale:
17030 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
17031 initializing the IT insn type with a generic initial value depending
17032 on the inst.condition.
e07e6e58 17033 2) During the tencode function, two things may happen:
477330fc
RM
17034 a) The tencode function overrides the IT insn type by
17035 calling either set_it_insn_type (type) or set_it_insn_type_last ().
17036 b) The tencode function queries the IT block state by
17037 calling in_it_block () (i.e. to determine narrow/not narrow mode).
17038
17039 Both set_it_insn_type and in_it_block run the internal FSM state
17040 handling function (handle_it_state), because: a) setting the IT insn
17041 type may incur in an invalid state (exiting the function),
17042 and b) querying the state requires the FSM to be updated.
17043 Specifically we want to avoid creating an IT block for conditional
17044 branches, so it_fsm_pre_encode is actually a guess and we can't
17045 determine whether an IT block is required until the tencode () routine
17046 has decided what type of instruction this actually it.
17047 Because of this, if set_it_insn_type and in_it_block have to be used,
17048 set_it_insn_type has to be called first.
17049
17050 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
17051 determines the insn IT type depending on the inst.cond code.
17052 When a tencode () routine encodes an instruction that can be
17053 either outside an IT block, or, in the case of being inside, has to be
17054 the last one, set_it_insn_type_last () will determine the proper
17055 IT instruction type based on the inst.cond code. Otherwise,
17056 set_it_insn_type can be called for overriding that logic or
17057 for covering other cases.
17058
17059 Calling handle_it_state () may not transition the IT block state to
17060 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
17061 still queried. Instead, if the FSM determines that the state should
17062 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
17063 after the tencode () function: that's what it_fsm_post_encode () does.
17064
17065 Since in_it_block () calls the state handling function to get an
17066 updated state, an error may occur (due to invalid insns combination).
17067 In that case, inst.error is set.
17068 Therefore, inst.error has to be checked after the execution of
17069 the tencode () routine.
e07e6e58
NC
17070
17071 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
17072 any pending state change (if any) that didn't take place in
17073 handle_it_state () as explained above. */
e07e6e58
NC
17074
17075static void
17076it_fsm_pre_encode (void)
17077{
17078 if (inst.cond != COND_ALWAYS)
17079 inst.it_insn_type = INSIDE_IT_INSN;
17080 else
17081 inst.it_insn_type = OUTSIDE_IT_INSN;
17082
17083 now_it.state_handled = 0;
17084}
17085
17086/* IT state FSM handling function. */
17087
17088static int
17089handle_it_state (void)
17090{
17091 now_it.state_handled = 1;
5a01bb1d 17092 now_it.insn_cond = FALSE;
e07e6e58
NC
17093
17094 switch (now_it.state)
17095 {
17096 case OUTSIDE_IT_BLOCK:
17097 switch (inst.it_insn_type)
17098 {
17099 case OUTSIDE_IT_INSN:
17100 break;
17101
17102 case INSIDE_IT_INSN:
17103 case INSIDE_IT_LAST_INSN:
17104 if (thumb_mode == 0)
17105 {
c921be7d 17106 if (unified_syntax
e07e6e58
NC
17107 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
17108 as_tsktsk (_("Warning: conditional outside an IT block"\
17109 " for Thumb."));
17110 }
17111 else
17112 {
17113 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
17114 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
17115 {
17116 /* Automatically generate the IT instruction. */
17117 new_automatic_it_block (inst.cond);
17118 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
17119 close_automatic_it_block ();
17120 }
17121 else
17122 {
17123 inst.error = BAD_OUT_IT;
17124 return FAIL;
17125 }
17126 }
17127 break;
17128
17129 case IF_INSIDE_IT_LAST_INSN:
17130 case NEUTRAL_IT_INSN:
17131 break;
17132
17133 case IT_INSN:
17134 now_it.state = MANUAL_IT_BLOCK;
17135 now_it.block_length = 0;
17136 break;
17137 }
17138 break;
17139
17140 case AUTOMATIC_IT_BLOCK:
17141 /* Three things may happen now:
17142 a) We should increment current it block size;
17143 b) We should close current it block (closing insn or 4 insns);
17144 c) We should close current it block and start a new one (due
17145 to incompatible conditions or
17146 4 insns-length block reached). */
17147
17148 switch (inst.it_insn_type)
17149 {
17150 case OUTSIDE_IT_INSN:
17151 /* The closure of the block shall happen immediatelly,
17152 so any in_it_block () call reports the block as closed. */
17153 force_automatic_it_block_close ();
17154 break;
17155
17156 case INSIDE_IT_INSN:
17157 case INSIDE_IT_LAST_INSN:
17158 case IF_INSIDE_IT_LAST_INSN:
17159 now_it.block_length++;
17160
17161 if (now_it.block_length > 4
17162 || !now_it_compatible (inst.cond))
17163 {
17164 force_automatic_it_block_close ();
17165 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
17166 new_automatic_it_block (inst.cond);
17167 }
17168 else
17169 {
5a01bb1d 17170 now_it.insn_cond = TRUE;
e07e6e58
NC
17171 now_it_add_mask (inst.cond);
17172 }
17173
17174 if (now_it.state == AUTOMATIC_IT_BLOCK
17175 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
17176 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
17177 close_automatic_it_block ();
17178 break;
17179
17180 case NEUTRAL_IT_INSN:
17181 now_it.block_length++;
5a01bb1d 17182 now_it.insn_cond = TRUE;
e07e6e58
NC
17183
17184 if (now_it.block_length > 4)
17185 force_automatic_it_block_close ();
17186 else
17187 now_it_add_mask (now_it.cc & 1);
17188 break;
17189
17190 case IT_INSN:
17191 close_automatic_it_block ();
17192 now_it.state = MANUAL_IT_BLOCK;
17193 break;
17194 }
17195 break;
17196
17197 case MANUAL_IT_BLOCK:
17198 {
17199 /* Check conditional suffixes. */
17200 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
17201 int is_last;
17202 now_it.mask <<= 1;
17203 now_it.mask &= 0x1f;
17204 is_last = (now_it.mask == 0x10);
5a01bb1d 17205 now_it.insn_cond = TRUE;
e07e6e58
NC
17206
17207 switch (inst.it_insn_type)
17208 {
17209 case OUTSIDE_IT_INSN:
17210 inst.error = BAD_NOT_IT;
17211 return FAIL;
17212
17213 case INSIDE_IT_INSN:
17214 if (cond != inst.cond)
17215 {
17216 inst.error = BAD_IT_COND;
17217 return FAIL;
17218 }
17219 break;
17220
17221 case INSIDE_IT_LAST_INSN:
17222 case IF_INSIDE_IT_LAST_INSN:
17223 if (cond != inst.cond)
17224 {
17225 inst.error = BAD_IT_COND;
17226 return FAIL;
17227 }
17228 if (!is_last)
17229 {
17230 inst.error = BAD_BRANCH;
17231 return FAIL;
17232 }
17233 break;
17234
17235 case NEUTRAL_IT_INSN:
17236 /* The BKPT instruction is unconditional even in an IT block. */
17237 break;
17238
17239 case IT_INSN:
17240 inst.error = BAD_IT_IT;
17241 return FAIL;
17242 }
17243 }
17244 break;
17245 }
17246
17247 return SUCCESS;
17248}
17249
5a01bb1d
MGD
17250struct depr_insn_mask
17251{
17252 unsigned long pattern;
17253 unsigned long mask;
17254 const char* description;
17255};
17256
17257/* List of 16-bit instruction patterns deprecated in an IT block in
17258 ARMv8. */
17259static const struct depr_insn_mask depr_it_insns[] = {
17260 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
17261 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
17262 { 0xa000, 0xb800, N_("ADR") },
17263 { 0x4800, 0xf800, N_("Literal loads") },
17264 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
17265 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
17266 { 0, 0, NULL }
17267};
17268
e07e6e58
NC
17269static void
17270it_fsm_post_encode (void)
17271{
17272 int is_last;
17273
17274 if (!now_it.state_handled)
17275 handle_it_state ();
17276
5a01bb1d
MGD
17277 if (now_it.insn_cond
17278 && !now_it.warn_deprecated
17279 && warn_on_deprecated
17280 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
17281 {
17282 if (inst.instruction >= 0x10000)
17283 {
0a8897c7 17284 as_warn (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
17285 "deprecated in ARMv8"));
17286 now_it.warn_deprecated = TRUE;
17287 }
17288 else
17289 {
17290 const struct depr_insn_mask *p = depr_it_insns;
17291
17292 while (p->mask != 0)
17293 {
17294 if ((inst.instruction & p->mask) == p->pattern)
17295 {
0a8897c7 17296 as_warn (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
17297 "of the following class are deprecated in ARMv8: "
17298 "%s"), p->description);
17299 now_it.warn_deprecated = TRUE;
17300 break;
17301 }
17302
17303 ++p;
17304 }
17305 }
17306
17307 if (now_it.block_length > 1)
17308 {
0a8897c7
KT
17309 as_warn (_("IT blocks containing more than one conditional "
17310 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
17311 now_it.warn_deprecated = TRUE;
17312 }
17313 }
17314
e07e6e58
NC
17315 is_last = (now_it.mask == 0x10);
17316 if (is_last)
17317 {
17318 now_it.state = OUTSIDE_IT_BLOCK;
17319 now_it.mask = 0;
17320 }
17321}
17322
17323static void
17324force_automatic_it_block_close (void)
17325{
17326 if (now_it.state == AUTOMATIC_IT_BLOCK)
17327 {
17328 close_automatic_it_block ();
17329 now_it.state = OUTSIDE_IT_BLOCK;
17330 now_it.mask = 0;
17331 }
17332}
17333
17334static int
17335in_it_block (void)
17336{
17337 if (!now_it.state_handled)
17338 handle_it_state ();
17339
17340 return now_it.state != OUTSIDE_IT_BLOCK;
17341}
17342
c19d1205
ZW
17343void
17344md_assemble (char *str)
b99bd4ef 17345{
c19d1205
ZW
17346 char *p = str;
17347 const struct asm_opcode * opcode;
b99bd4ef 17348
c19d1205
ZW
17349 /* Align the previous label if needed. */
17350 if (last_label_seen != NULL)
b99bd4ef 17351 {
c19d1205
ZW
17352 symbol_set_frag (last_label_seen, frag_now);
17353 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
17354 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
17355 }
17356
c19d1205
ZW
17357 memset (&inst, '\0', sizeof (inst));
17358 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 17359
c19d1205
ZW
17360 opcode = opcode_lookup (&p);
17361 if (!opcode)
b99bd4ef 17362 {
c19d1205 17363 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 17364 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 17365 if (! create_register_alias (str, p)
477330fc 17366 && ! create_neon_reg_alias (str, p))
c19d1205 17367 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 17368
b99bd4ef
NC
17369 return;
17370 }
17371
278df34e 17372 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
17373 as_warn (_("s suffix on comparison instruction is deprecated"));
17374
037e8744
JB
17375 /* The value which unconditional instructions should have in place of the
17376 condition field. */
17377 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
17378
c19d1205 17379 if (thumb_mode)
b99bd4ef 17380 {
e74cfd16 17381 arm_feature_set variant;
8f06b2d8
PB
17382
17383 variant = cpu_variant;
17384 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
17385 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
17386 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 17387 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
17388 if (!opcode->tvariant
17389 || (thumb_mode == 1
17390 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 17391 {
bf3eeda7 17392 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
b99bd4ef
NC
17393 return;
17394 }
c19d1205
ZW
17395 if (inst.cond != COND_ALWAYS && !unified_syntax
17396 && opcode->tencode != do_t_branch)
b99bd4ef 17397 {
c19d1205 17398 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
17399 return;
17400 }
17401
752d5da4 17402 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 17403 {
7e806470 17404 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
17405 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
17406 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
17407 {
17408 /* Two things are addressed here.
17409 1) Implicit require narrow instructions on Thumb-1.
17410 This avoids relaxation accidentally introducing Thumb-2
17411 instructions.
17412 2) Reject wide instructions in non Thumb-2 cores. */
17413 if (inst.size_req == 0)
17414 inst.size_req = 2;
17415 else if (inst.size_req == 4)
17416 {
bf3eeda7 17417 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
752d5da4
NC
17418 return;
17419 }
17420 }
076d447c
PB
17421 }
17422
c19d1205
ZW
17423 inst.instruction = opcode->tvalue;
17424
5be8be5d 17425 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
17426 {
17427 /* Prepare the it_insn_type for those encodings that don't set
17428 it. */
17429 it_fsm_pre_encode ();
c19d1205 17430
477330fc 17431 opcode->tencode ();
e07e6e58 17432
477330fc
RM
17433 it_fsm_post_encode ();
17434 }
e27ec89e 17435
0110f2b8 17436 if (!(inst.error || inst.relax))
b99bd4ef 17437 {
9c2799c2 17438 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
17439 inst.size = (inst.instruction > 0xffff ? 4 : 2);
17440 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 17441 {
c19d1205 17442 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
17443 return;
17444 }
17445 }
076d447c
PB
17446
17447 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 17448 instruction. */
9c2799c2 17449 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 17450
e74cfd16
PB
17451 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17452 *opcode->tvariant);
ee065d83 17453 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 17454 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 17455 anything other than bl/blx and v6-M instructions.
ee065d83 17456 This is overly pessimistic for relaxable instructions. */
7e806470
PB
17457 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
17458 || inst.relax)
e07e6e58
NC
17459 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
17460 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
17461 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17462 arm_ext_v6t2);
cd000bff 17463
88714cb8
DG
17464 check_neon_suffixes;
17465
cd000bff 17466 if (!inst.error)
c877a2f2
NC
17467 {
17468 mapping_state (MAP_THUMB);
17469 }
c19d1205 17470 }
3e9e4fcf 17471 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 17472 {
845b51d6
PB
17473 bfd_boolean is_bx;
17474
17475 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
17476 is_bx = (opcode->aencode == do_bx);
17477
c19d1205 17478 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
17479 if (!(is_bx && fix_v4bx)
17480 && !(opcode->avariant &&
17481 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 17482 {
bf3eeda7 17483 as_bad (_("selected processor does not support ARM mode `%s'"), str);
c19d1205 17484 return;
b99bd4ef 17485 }
c19d1205 17486 if (inst.size_req)
b99bd4ef 17487 {
c19d1205
ZW
17488 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
17489 return;
b99bd4ef
NC
17490 }
17491
c19d1205
ZW
17492 inst.instruction = opcode->avalue;
17493 if (opcode->tag == OT_unconditionalF)
17494 inst.instruction |= 0xF << 28;
17495 else
17496 inst.instruction |= inst.cond << 28;
17497 inst.size = INSN_SIZE;
5be8be5d 17498 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
17499 {
17500 it_fsm_pre_encode ();
17501 opcode->aencode ();
17502 it_fsm_post_encode ();
17503 }
ee065d83 17504 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 17505 on a hypothetical non-thumb v5 core. */
845b51d6 17506 if (is_bx)
e74cfd16 17507 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 17508 else
e74cfd16
PB
17509 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
17510 *opcode->avariant);
88714cb8
DG
17511
17512 check_neon_suffixes;
17513
cd000bff 17514 if (!inst.error)
c877a2f2
NC
17515 {
17516 mapping_state (MAP_ARM);
17517 }
b99bd4ef 17518 }
3e9e4fcf
JB
17519 else
17520 {
17521 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
17522 "-- `%s'"), str);
17523 return;
17524 }
c19d1205
ZW
17525 output_inst (str);
17526}
b99bd4ef 17527
e07e6e58
NC
17528static void
17529check_it_blocks_finished (void)
17530{
17531#ifdef OBJ_ELF
17532 asection *sect;
17533
17534 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
17535 if (seg_info (sect)->tc_segment_info_data.current_it.state
17536 == MANUAL_IT_BLOCK)
17537 {
17538 as_warn (_("section '%s' finished with an open IT block."),
17539 sect->name);
17540 }
17541#else
17542 if (now_it.state == MANUAL_IT_BLOCK)
17543 as_warn (_("file finished with an open IT block."));
17544#endif
17545}
17546
c19d1205
ZW
17547/* Various frobbings of labels and their addresses. */
17548
17549void
17550arm_start_line_hook (void)
17551{
17552 last_label_seen = NULL;
b99bd4ef
NC
17553}
17554
c19d1205
ZW
17555void
17556arm_frob_label (symbolS * sym)
b99bd4ef 17557{
c19d1205 17558 last_label_seen = sym;
b99bd4ef 17559
c19d1205 17560 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 17561
c19d1205
ZW
17562#if defined OBJ_COFF || defined OBJ_ELF
17563 ARM_SET_INTERWORK (sym, support_interwork);
17564#endif
b99bd4ef 17565
e07e6e58
NC
17566 force_automatic_it_block_close ();
17567
5f4273c7 17568 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
17569 as Thumb functions. This is because these labels, whilst
17570 they exist inside Thumb code, are not the entry points for
17571 possible ARM->Thumb calls. Also, these labels can be used
17572 as part of a computed goto or switch statement. eg gcc
17573 can generate code that looks like this:
b99bd4ef 17574
c19d1205
ZW
17575 ldr r2, [pc, .Laaa]
17576 lsl r3, r3, #2
17577 ldr r2, [r3, r2]
17578 mov pc, r2
b99bd4ef 17579
c19d1205
ZW
17580 .Lbbb: .word .Lxxx
17581 .Lccc: .word .Lyyy
17582 ..etc...
17583 .Laaa: .word Lbbb
b99bd4ef 17584
c19d1205
ZW
17585 The first instruction loads the address of the jump table.
17586 The second instruction converts a table index into a byte offset.
17587 The third instruction gets the jump address out of the table.
17588 The fourth instruction performs the jump.
b99bd4ef 17589
c19d1205
ZW
17590 If the address stored at .Laaa is that of a symbol which has the
17591 Thumb_Func bit set, then the linker will arrange for this address
17592 to have the bottom bit set, which in turn would mean that the
17593 address computation performed by the third instruction would end
17594 up with the bottom bit set. Since the ARM is capable of unaligned
17595 word loads, the instruction would then load the incorrect address
17596 out of the jump table, and chaos would ensue. */
17597 if (label_is_thumb_function_name
17598 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
17599 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 17600 {
c19d1205
ZW
17601 /* When the address of a Thumb function is taken the bottom
17602 bit of that address should be set. This will allow
17603 interworking between Arm and Thumb functions to work
17604 correctly. */
b99bd4ef 17605
c19d1205 17606 THUMB_SET_FUNC (sym, 1);
b99bd4ef 17607
c19d1205 17608 label_is_thumb_function_name = FALSE;
b99bd4ef 17609 }
07a53e5c 17610
07a53e5c 17611 dwarf2_emit_label (sym);
b99bd4ef
NC
17612}
17613
c921be7d 17614bfd_boolean
c19d1205 17615arm_data_in_code (void)
b99bd4ef 17616{
c19d1205 17617 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 17618 {
c19d1205
ZW
17619 *input_line_pointer = '/';
17620 input_line_pointer += 5;
17621 *input_line_pointer = 0;
c921be7d 17622 return TRUE;
b99bd4ef
NC
17623 }
17624
c921be7d 17625 return FALSE;
b99bd4ef
NC
17626}
17627
c19d1205
ZW
17628char *
17629arm_canonicalize_symbol_name (char * name)
b99bd4ef 17630{
c19d1205 17631 int len;
b99bd4ef 17632
c19d1205
ZW
17633 if (thumb_mode && (len = strlen (name)) > 5
17634 && streq (name + len - 5, "/data"))
17635 *(name + len - 5) = 0;
b99bd4ef 17636
c19d1205 17637 return name;
b99bd4ef 17638}
c19d1205
ZW
17639\f
17640/* Table of all register names defined by default. The user can
17641 define additional names with .req. Note that all register names
17642 should appear in both upper and lowercase variants. Some registers
17643 also have mixed-case names. */
b99bd4ef 17644
dcbf9037 17645#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 17646#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 17647#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
17648#define REGSET(p,t) \
17649 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
17650 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
17651 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
17652 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
17653#define REGSETH(p,t) \
17654 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
17655 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
17656 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
17657 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
17658#define REGSET2(p,t) \
17659 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
17660 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
17661 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
17662 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
17663#define SPLRBANK(base,bank,t) \
17664 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
17665 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
17666 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
17667 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
17668 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
17669 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 17670
c19d1205 17671static const struct reg_entry reg_names[] =
7ed4c4c5 17672{
c19d1205
ZW
17673 /* ARM integer registers. */
17674 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 17675
c19d1205
ZW
17676 /* ATPCS synonyms. */
17677 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
17678 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
17679 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 17680
c19d1205
ZW
17681 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
17682 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
17683 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 17684
c19d1205
ZW
17685 /* Well-known aliases. */
17686 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
17687 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
17688
17689 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
17690 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
17691
17692 /* Coprocessor numbers. */
17693 REGSET(p, CP), REGSET(P, CP),
17694
17695 /* Coprocessor register numbers. The "cr" variants are for backward
17696 compatibility. */
17697 REGSET(c, CN), REGSET(C, CN),
17698 REGSET(cr, CN), REGSET(CR, CN),
17699
90ec0d68
MGD
17700 /* ARM banked registers. */
17701 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
17702 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
17703 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
17704 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
17705 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
17706 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
17707 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
17708
17709 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
17710 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
17711 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
17712 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
17713 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 17714 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
17715 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
17716 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
17717
17718 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
17719 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
17720 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
17721 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
17722 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
17723 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
17724 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 17725 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
17726 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
17727
c19d1205
ZW
17728 /* FPA registers. */
17729 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
17730 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
17731
17732 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
17733 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
17734
17735 /* VFP SP registers. */
5287ad62
JB
17736 REGSET(s,VFS), REGSET(S,VFS),
17737 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
17738
17739 /* VFP DP Registers. */
5287ad62
JB
17740 REGSET(d,VFD), REGSET(D,VFD),
17741 /* Extra Neon DP registers. */
17742 REGSETH(d,VFD), REGSETH(D,VFD),
17743
17744 /* Neon QP registers. */
17745 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
17746
17747 /* VFP control registers. */
17748 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
17749 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
17750 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
17751 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
17752 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
17753 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
17754
17755 /* Maverick DSP coprocessor registers. */
17756 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
17757 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
17758
17759 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
17760 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
17761 REGDEF(dspsc,0,DSPSC),
17762
17763 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
17764 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
17765 REGDEF(DSPSC,0,DSPSC),
17766
17767 /* iWMMXt data registers - p0, c0-15. */
17768 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
17769
17770 /* iWMMXt control registers - p1, c0-3. */
17771 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
17772 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
17773 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
17774 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
17775
17776 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
17777 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
17778 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
17779 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
17780 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
17781
17782 /* XScale accumulator registers. */
17783 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
17784};
17785#undef REGDEF
17786#undef REGNUM
17787#undef REGSET
7ed4c4c5 17788
c19d1205
ZW
17789/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
17790 within psr_required_here. */
17791static const struct asm_psr psrs[] =
17792{
17793 /* Backward compatibility notation. Note that "all" is no longer
17794 truly all possible PSR bits. */
17795 {"all", PSR_c | PSR_f},
17796 {"flg", PSR_f},
17797 {"ctl", PSR_c},
17798
17799 /* Individual flags. */
17800 {"f", PSR_f},
17801 {"c", PSR_c},
17802 {"x", PSR_x},
17803 {"s", PSR_s},
59b42a0d 17804
c19d1205
ZW
17805 /* Combinations of flags. */
17806 {"fs", PSR_f | PSR_s},
17807 {"fx", PSR_f | PSR_x},
17808 {"fc", PSR_f | PSR_c},
17809 {"sf", PSR_s | PSR_f},
17810 {"sx", PSR_s | PSR_x},
17811 {"sc", PSR_s | PSR_c},
17812 {"xf", PSR_x | PSR_f},
17813 {"xs", PSR_x | PSR_s},
17814 {"xc", PSR_x | PSR_c},
17815 {"cf", PSR_c | PSR_f},
17816 {"cs", PSR_c | PSR_s},
17817 {"cx", PSR_c | PSR_x},
17818 {"fsx", PSR_f | PSR_s | PSR_x},
17819 {"fsc", PSR_f | PSR_s | PSR_c},
17820 {"fxs", PSR_f | PSR_x | PSR_s},
17821 {"fxc", PSR_f | PSR_x | PSR_c},
17822 {"fcs", PSR_f | PSR_c | PSR_s},
17823 {"fcx", PSR_f | PSR_c | PSR_x},
17824 {"sfx", PSR_s | PSR_f | PSR_x},
17825 {"sfc", PSR_s | PSR_f | PSR_c},
17826 {"sxf", PSR_s | PSR_x | PSR_f},
17827 {"sxc", PSR_s | PSR_x | PSR_c},
17828 {"scf", PSR_s | PSR_c | PSR_f},
17829 {"scx", PSR_s | PSR_c | PSR_x},
17830 {"xfs", PSR_x | PSR_f | PSR_s},
17831 {"xfc", PSR_x | PSR_f | PSR_c},
17832 {"xsf", PSR_x | PSR_s | PSR_f},
17833 {"xsc", PSR_x | PSR_s | PSR_c},
17834 {"xcf", PSR_x | PSR_c | PSR_f},
17835 {"xcs", PSR_x | PSR_c | PSR_s},
17836 {"cfs", PSR_c | PSR_f | PSR_s},
17837 {"cfx", PSR_c | PSR_f | PSR_x},
17838 {"csf", PSR_c | PSR_s | PSR_f},
17839 {"csx", PSR_c | PSR_s | PSR_x},
17840 {"cxf", PSR_c | PSR_x | PSR_f},
17841 {"cxs", PSR_c | PSR_x | PSR_s},
17842 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
17843 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
17844 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
17845 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
17846 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
17847 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
17848 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
17849 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
17850 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
17851 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
17852 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
17853 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
17854 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
17855 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
17856 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
17857 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
17858 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
17859 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
17860 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
17861 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
17862 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
17863 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
17864 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
17865 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
17866};
17867
62b3e311
PB
17868/* Table of V7M psr names. */
17869static const struct asm_psr v7m_psrs[] =
17870{
2b744c99
PB
17871 {"apsr", 0 }, {"APSR", 0 },
17872 {"iapsr", 1 }, {"IAPSR", 1 },
17873 {"eapsr", 2 }, {"EAPSR", 2 },
17874 {"psr", 3 }, {"PSR", 3 },
17875 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
17876 {"ipsr", 5 }, {"IPSR", 5 },
17877 {"epsr", 6 }, {"EPSR", 6 },
17878 {"iepsr", 7 }, {"IEPSR", 7 },
17879 {"msp", 8 }, {"MSP", 8 },
17880 {"psp", 9 }, {"PSP", 9 },
17881 {"primask", 16}, {"PRIMASK", 16},
17882 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
17883 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
17884 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99
PB
17885 {"faultmask", 19}, {"FAULTMASK", 19},
17886 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
17887};
17888
c19d1205
ZW
17889/* Table of all shift-in-operand names. */
17890static const struct asm_shift_name shift_names [] =
b99bd4ef 17891{
c19d1205
ZW
17892 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
17893 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
17894 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
17895 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
17896 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
17897 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
17898};
b99bd4ef 17899
c19d1205
ZW
17900/* Table of all explicit relocation names. */
17901#ifdef OBJ_ELF
17902static struct reloc_entry reloc_names[] =
17903{
17904 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
17905 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
17906 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
17907 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
17908 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
17909 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
17910 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
17911 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
17912 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
17913 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 17914 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
17915 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
17916 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 17917 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 17918 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 17919 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 17920 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 17921 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
17922};
17923#endif
b99bd4ef 17924
c19d1205
ZW
17925/* Table of all conditional affixes. 0xF is not defined as a condition code. */
17926static const struct asm_cond conds[] =
17927{
17928 {"eq", 0x0},
17929 {"ne", 0x1},
17930 {"cs", 0x2}, {"hs", 0x2},
17931 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
17932 {"mi", 0x4},
17933 {"pl", 0x5},
17934 {"vs", 0x6},
17935 {"vc", 0x7},
17936 {"hi", 0x8},
17937 {"ls", 0x9},
17938 {"ge", 0xa},
17939 {"lt", 0xb},
17940 {"gt", 0xc},
17941 {"le", 0xd},
17942 {"al", 0xe}
17943};
bfae80f2 17944
e797f7e0
MGD
17945#define UL_BARRIER(L,U,CODE,FEAT) \
17946 { L, CODE, ARM_FEATURE (FEAT, 0) }, \
17947 { U, CODE, ARM_FEATURE (FEAT, 0) }
17948
62b3e311
PB
17949static struct asm_barrier_opt barrier_opt_names[] =
17950{
e797f7e0
MGD
17951 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
17952 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
17953 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
17954 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
17955 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
17956 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
17957 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
17958 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
17959 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
17960 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
17961 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
17962 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
17963 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
17964 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
17965 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
17966 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
17967};
17968
e797f7e0
MGD
17969#undef UL_BARRIER
17970
c19d1205
ZW
17971/* Table of ARM-format instructions. */
17972
17973/* Macros for gluing together operand strings. N.B. In all cases
17974 other than OPS0, the trailing OP_stop comes from default
17975 zero-initialization of the unspecified elements of the array. */
17976#define OPS0() { OP_stop, }
17977#define OPS1(a) { OP_##a, }
17978#define OPS2(a,b) { OP_##a,OP_##b, }
17979#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
17980#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
17981#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
17982#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
17983
5be8be5d
DG
17984/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
17985 This is useful when mixing operands for ARM and THUMB, i.e. using the
17986 MIX_ARM_THUMB_OPERANDS macro.
17987 In order to use these macros, prefix the number of operands with _
17988 e.g. _3. */
17989#define OPS_1(a) { a, }
17990#define OPS_2(a,b) { a,b, }
17991#define OPS_3(a,b,c) { a,b,c, }
17992#define OPS_4(a,b,c,d) { a,b,c,d, }
17993#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
17994#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
17995
c19d1205
ZW
17996/* These macros abstract out the exact format of the mnemonic table and
17997 save some repeated characters. */
17998
17999/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
18000#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18001 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 18002 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18003
18004/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
18005 a T_MNEM_xyz enumerator. */
18006#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18007 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18008#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18009 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
18010
18011/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
18012 infix after the third character. */
18013#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 18014 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 18015 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 18016#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 18017 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 18018 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18019#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18020 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 18021#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18022 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18023#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18024 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 18025#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18026 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 18027
c19d1205 18028/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
18029 field is still 0xE. Many of the Thumb variants can be executed
18030 conditionally, so this is checked separately. */
c19d1205 18031#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18032 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18033 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18034
dd5181d5
KT
18035/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
18036 Used by mnemonics that have very minimal differences in the encoding for
18037 ARM and Thumb variants and can be handled in a common function. */
18038#define TUEc(mnem, op, top, nops, ops, en) \
18039 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
18040 THUMB_VARIANT, do_##en, do_##en }
18041
c19d1205
ZW
18042/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
18043 condition code field. */
18044#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 18045 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18046 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18047
18048/* ARM-only variants of all the above. */
6a86118a 18049#define CE(mnem, op, nops, ops, ae) \
21d799b5 18050 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
18051
18052#define C3(mnem, op, nops, ops, ae) \
18053 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18054
e3cb604e
PB
18055/* Legacy mnemonics that always have conditional infix after the third
18056 character. */
18057#define CL(mnem, op, nops, ops, ae) \
21d799b5 18058 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18059 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18060
8f06b2d8
PB
18061/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
18062#define cCE(mnem, op, nops, ops, ae) \
21d799b5 18063 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18064
e3cb604e
PB
18065/* Legacy coprocessor instructions where conditional infix and conditional
18066 suffix are ambiguous. For consistency this includes all FPA instructions,
18067 not just the potentially ambiguous ones. */
18068#define cCL(mnem, op, nops, ops, ae) \
21d799b5 18069 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18070 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
18071
18072/* Coprocessor, takes either a suffix or a position-3 infix
18073 (for an FPA corner case). */
18074#define C3E(mnem, op, nops, ops, ae) \
21d799b5 18075 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 18076 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18077
6a86118a 18078#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
18079 { m1 #m2 m3, OPS##nops ops, \
18080 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
18081 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18082
18083#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
18084 xCM_ (m1, , m2, op, nops, ops, ae), \
18085 xCM_ (m1, eq, m2, op, nops, ops, ae), \
18086 xCM_ (m1, ne, m2, op, nops, ops, ae), \
18087 xCM_ (m1, cs, m2, op, nops, ops, ae), \
18088 xCM_ (m1, hs, m2, op, nops, ops, ae), \
18089 xCM_ (m1, cc, m2, op, nops, ops, ae), \
18090 xCM_ (m1, ul, m2, op, nops, ops, ae), \
18091 xCM_ (m1, lo, m2, op, nops, ops, ae), \
18092 xCM_ (m1, mi, m2, op, nops, ops, ae), \
18093 xCM_ (m1, pl, m2, op, nops, ops, ae), \
18094 xCM_ (m1, vs, m2, op, nops, ops, ae), \
18095 xCM_ (m1, vc, m2, op, nops, ops, ae), \
18096 xCM_ (m1, hi, m2, op, nops, ops, ae), \
18097 xCM_ (m1, ls, m2, op, nops, ops, ae), \
18098 xCM_ (m1, ge, m2, op, nops, ops, ae), \
18099 xCM_ (m1, lt, m2, op, nops, ops, ae), \
18100 xCM_ (m1, gt, m2, op, nops, ops, ae), \
18101 xCM_ (m1, le, m2, op, nops, ops, ae), \
18102 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
18103
18104#define UE(mnem, op, nops, ops, ae) \
18105 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18106
18107#define UF(mnem, op, nops, ops, ae) \
18108 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18109
5287ad62
JB
18110/* Neon data-processing. ARM versions are unconditional with cond=0xf.
18111 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
18112 use the same encoding function for each. */
18113#define NUF(mnem, op, nops, ops, enc) \
18114 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
18115 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18116
18117/* Neon data processing, version which indirects through neon_enc_tab for
18118 the various overloaded versions of opcodes. */
18119#define nUF(mnem, op, nops, ops, enc) \
21d799b5 18120 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
18121 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18122
18123/* Neon insn with conditional suffix for the ARM version, non-overloaded
18124 version. */
037e8744
JB
18125#define NCE_tag(mnem, op, nops, ops, enc, tag) \
18126 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
18127 THUMB_VARIANT, do_##enc, do_##enc }
18128
037e8744 18129#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 18130 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
18131
18132#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 18133 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 18134
5287ad62 18135/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 18136#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 18137 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
18138 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18139
037e8744 18140#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 18141 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
18142
18143#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 18144 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 18145
c19d1205
ZW
18146#define do_0 0
18147
c19d1205 18148static const struct asm_opcode insns[] =
bfae80f2 18149{
74db7efb
NC
18150#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
18151#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
18152 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
18153 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
18154 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
18155 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
18156 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
18157 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
18158 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
18159 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
18160 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
18161 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
18162 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
18163 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
18164 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
18165 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
18166 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
18167 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
18168
18169 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
18170 for setting PSR flag bits. They are obsolete in V6 and do not
18171 have Thumb equivalents. */
21d799b5
NC
18172 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18173 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18174 CL("tstp", 110f000, 2, (RR, SH), cmp),
18175 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18176 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18177 CL("cmpp", 150f000, 2, (RR, SH), cmp),
18178 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18179 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18180 CL("cmnp", 170f000, 2, (RR, SH), cmp),
18181
18182 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
18183 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
18184 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
18185 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
18186
18187 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
18188 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
18189 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
18190 OP_RRnpc),
18191 OP_ADDRGLDR),ldst, t_ldst),
18192 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
18193
18194 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18195 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18196 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18197 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18198 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18199 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18200
18201 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
18202 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
18203 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
18204 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 18205
c19d1205 18206 /* Pseudo ops. */
21d799b5 18207 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 18208 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 18209 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 18210 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
18211
18212 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
18213 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
18214 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
18215 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
18216 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
18217 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
18218 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
18219 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
18220 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
18221 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
18222 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
18223 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
18224 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 18225
16a4cf17 18226 /* These may simplify to neg. */
21d799b5
NC
18227 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
18228 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 18229
c921be7d
NC
18230#undef THUMB_VARIANT
18231#define THUMB_VARIANT & arm_ext_v6
18232
21d799b5 18233 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
18234
18235 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
18236#undef THUMB_VARIANT
18237#define THUMB_VARIANT & arm_ext_v6t2
18238
21d799b5
NC
18239 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
18240 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
18241 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 18242
5be8be5d
DG
18243 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18244 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18245 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
18246 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 18247
21d799b5
NC
18248 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18249 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 18250
21d799b5
NC
18251 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18252 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
18253
18254 /* V1 instructions with no Thumb analogue at all. */
21d799b5 18255 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
18256 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
18257
18258 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
18259 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
18260 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
18261 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
18262 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
18263 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
18264 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
18265 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
18266
c921be7d
NC
18267#undef ARM_VARIANT
18268#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
18269#undef THUMB_VARIANT
18270#define THUMB_VARIANT & arm_ext_v4t
18271
21d799b5
NC
18272 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
18273 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 18274
c921be7d
NC
18275#undef THUMB_VARIANT
18276#define THUMB_VARIANT & arm_ext_v6t2
18277
21d799b5 18278 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
18279 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
18280
18281 /* Generic coprocessor instructions. */
21d799b5
NC
18282 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18283 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18284 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18285 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18286 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18287 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 18288 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 18289
c921be7d
NC
18290#undef ARM_VARIANT
18291#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
18292
21d799b5 18293 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
18294 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
18295
c921be7d
NC
18296#undef ARM_VARIANT
18297#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
18298#undef THUMB_VARIANT
18299#define THUMB_VARIANT & arm_ext_msr
18300
d2cd1205
JB
18301 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
18302 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 18303
c921be7d
NC
18304#undef ARM_VARIANT
18305#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
18306#undef THUMB_VARIANT
18307#define THUMB_VARIANT & arm_ext_v6t2
18308
21d799b5
NC
18309 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18310 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18311 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18312 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18313 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18314 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18315 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18316 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 18317
c921be7d
NC
18318#undef ARM_VARIANT
18319#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
18320#undef THUMB_VARIANT
18321#define THUMB_VARIANT & arm_ext_v4t
18322
5be8be5d
DG
18323 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18324 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18325 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18326 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
18327 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18328 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 18329
c921be7d
NC
18330#undef ARM_VARIANT
18331#define ARM_VARIANT & arm_ext_v4t_5
18332
c19d1205
ZW
18333 /* ARM Architecture 4T. */
18334 /* Note: bx (and blx) are required on V5, even if the processor does
18335 not support Thumb. */
21d799b5 18336 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 18337
c921be7d
NC
18338#undef ARM_VARIANT
18339#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
18340#undef THUMB_VARIANT
18341#define THUMB_VARIANT & arm_ext_v5t
18342
c19d1205
ZW
18343 /* Note: blx has 2 variants; the .value coded here is for
18344 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
18345 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
18346 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 18347
c921be7d
NC
18348#undef THUMB_VARIANT
18349#define THUMB_VARIANT & arm_ext_v6t2
18350
21d799b5
NC
18351 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
18352 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18353 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18354 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18355 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18356 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18357 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18358 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 18359
c921be7d 18360#undef ARM_VARIANT
74db7efb
NC
18361#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
18362#undef THUMB_VARIANT
18363#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 18364
21d799b5
NC
18365 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18366 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18367 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18368 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 18369
21d799b5
NC
18370 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18371 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 18372
21d799b5
NC
18373 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18374 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18375 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18376 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 18377
21d799b5
NC
18378 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18379 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18380 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18381 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 18382
21d799b5
NC
18383 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18384 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 18385
03ee1b7f
NC
18386 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18387 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18388 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18389 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 18390
c921be7d 18391#undef ARM_VARIANT
74db7efb
NC
18392#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
18393#undef THUMB_VARIANT
18394#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 18395
21d799b5 18396 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
18397 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
18398 ldrd, t_ldstd),
18399 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
18400 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 18401
21d799b5
NC
18402 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18403 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 18404
c921be7d
NC
18405#undef ARM_VARIANT
18406#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
18407
21d799b5 18408 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 18409
c921be7d
NC
18410#undef ARM_VARIANT
18411#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
18412#undef THUMB_VARIANT
18413#define THUMB_VARIANT & arm_ext_v6
18414
21d799b5
NC
18415 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
18416 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
18417 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18418 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18419 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18420 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18421 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18422 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18423 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18424 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 18425
c921be7d
NC
18426#undef THUMB_VARIANT
18427#define THUMB_VARIANT & arm_ext_v6t2
18428
5be8be5d
DG
18429 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
18430 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
18431 strex, t_strex),
21d799b5
NC
18432 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18433 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 18434
21d799b5
NC
18435 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
18436 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 18437
9e3c6df6 18438/* ARM V6 not included in V7M. */
c921be7d
NC
18439#undef THUMB_VARIANT
18440#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 18441 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 18442 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
18443 UF(rfeib, 9900a00, 1, (RRw), rfe),
18444 UF(rfeda, 8100a00, 1, (RRw), rfe),
18445 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18446 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
18447 UF(rfefa, 8100a00, 1, (RRw), rfe),
18448 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18449 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 18450 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
18451 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18452 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 18453 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 18454 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 18455 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 18456 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 18457 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 18458 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 18459
9e3c6df6
PB
18460/* ARM V6 not included in V7M (eg. integer SIMD). */
18461#undef THUMB_VARIANT
18462#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
18463 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
18464 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
18465 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
18466 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18467 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18468 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18469 /* Old name for QASX. */
74db7efb 18470 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 18471 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18472 /* Old name for QSAX. */
74db7efb 18473 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18474 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18475 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18476 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18477 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18478 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18479 /* Old name for SASX. */
74db7efb 18480 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18481 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18482 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18483 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18484 /* Old name for SHASX. */
21d799b5 18485 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18486 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18487 /* Old name for SHSAX. */
21d799b5
NC
18488 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18489 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18490 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18491 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18492 /* Old name for SSAX. */
74db7efb 18493 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18494 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18495 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18496 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18497 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18498 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18499 /* Old name for UASX. */
74db7efb 18500 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18501 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18502 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18503 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18504 /* Old name for UHASX. */
21d799b5
NC
18505 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18506 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18507 /* Old name for UHSAX. */
21d799b5
NC
18508 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18509 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18510 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18511 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18512 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18513 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18514 /* Old name for UQASX. */
21d799b5
NC
18515 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18516 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18517 /* Old name for UQSAX. */
21d799b5
NC
18518 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18519 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18520 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18521 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18522 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18523 /* Old name for USAX. */
74db7efb 18524 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 18525 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18526 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18527 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18528 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18529 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18530 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18531 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18532 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18533 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18534 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18535 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18536 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18537 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18538 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18539 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18540 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18541 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18542 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18543 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18544 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18545 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18546 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18547 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18548 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18549 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18550 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18551 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18552 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
18553 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
18554 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
18555 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18556 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18557 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 18558
c921be7d
NC
18559#undef ARM_VARIANT
18560#define ARM_VARIANT & arm_ext_v6k
18561#undef THUMB_VARIANT
18562#define THUMB_VARIANT & arm_ext_v6k
18563
21d799b5
NC
18564 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
18565 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
18566 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
18567 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 18568
c921be7d
NC
18569#undef THUMB_VARIANT
18570#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
18571 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
18572 ldrexd, t_ldrexd),
18573 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
18574 RRnpcb), strexd, t_strexd),
ebdca51a 18575
c921be7d
NC
18576#undef THUMB_VARIANT
18577#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
18578 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
18579 rd_rn, rd_rn),
18580 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
18581 rd_rn, rd_rn),
18582 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 18583 strex, t_strexbh),
5be8be5d 18584 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 18585 strex, t_strexbh),
21d799b5 18586 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 18587
c921be7d 18588#undef ARM_VARIANT
f4c65163 18589#define ARM_VARIANT & arm_ext_sec
74db7efb 18590#undef THUMB_VARIANT
f4c65163 18591#define THUMB_VARIANT & arm_ext_sec
c921be7d 18592
21d799b5 18593 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 18594
90ec0d68
MGD
18595#undef ARM_VARIANT
18596#define ARM_VARIANT & arm_ext_virt
18597#undef THUMB_VARIANT
18598#define THUMB_VARIANT & arm_ext_virt
18599
18600 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
18601 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
18602
c921be7d 18603#undef ARM_VARIANT
74db7efb 18604#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
18605#undef THUMB_VARIANT
18606#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 18607
21d799b5
NC
18608 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
18609 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
18610 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
18611 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 18612
21d799b5
NC
18613 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
18614 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
18615 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
18616 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 18617
5be8be5d
DG
18618 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18619 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18620 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18621 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 18622
bf3eeda7 18623 /* Thumb-only instructions. */
74db7efb 18624#undef ARM_VARIANT
bf3eeda7
NS
18625#define ARM_VARIANT NULL
18626 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
18627 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
18628
18629 /* ARM does not really have an IT instruction, so always allow it.
18630 The opcode is copied from Thumb in order to allow warnings in
18631 -mimplicit-it=[never | arm] modes. */
18632#undef ARM_VARIANT
18633#define ARM_VARIANT & arm_ext_v1
18634
21d799b5
NC
18635 TUE("it", bf08, bf08, 1, (COND), it, t_it),
18636 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
18637 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
18638 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
18639 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
18640 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
18641 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
18642 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
18643 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
18644 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
18645 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
18646 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
18647 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
18648 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
18649 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 18650 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
18651 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
18652 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 18653
92e90b6e 18654 /* Thumb2 only instructions. */
c921be7d
NC
18655#undef ARM_VARIANT
18656#define ARM_VARIANT NULL
92e90b6e 18657
21d799b5
NC
18658 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
18659 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
18660 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
18661 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
18662 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
18663 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 18664
eea54501
MGD
18665 /* Hardware division instructions. */
18666#undef ARM_VARIANT
18667#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
18668#undef THUMB_VARIANT
18669#define THUMB_VARIANT & arm_ext_div
18670
eea54501
MGD
18671 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
18672 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 18673
7e806470 18674 /* ARM V6M/V7 instructions. */
c921be7d
NC
18675#undef ARM_VARIANT
18676#define ARM_VARIANT & arm_ext_barrier
18677#undef THUMB_VARIANT
18678#define THUMB_VARIANT & arm_ext_barrier
18679
ccb84d65
JB
18680 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
18681 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
18682 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 18683
62b3e311 18684 /* ARM V7 instructions. */
c921be7d
NC
18685#undef ARM_VARIANT
18686#define ARM_VARIANT & arm_ext_v7
18687#undef THUMB_VARIANT
18688#define THUMB_VARIANT & arm_ext_v7
18689
21d799b5
NC
18690 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
18691 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 18692
74db7efb 18693#undef ARM_VARIANT
60e5ef9f 18694#define ARM_VARIANT & arm_ext_mp
74db7efb 18695#undef THUMB_VARIANT
60e5ef9f
MGD
18696#define THUMB_VARIANT & arm_ext_mp
18697
18698 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
18699
53c4b28b
MGD
18700 /* AArchv8 instructions. */
18701#undef ARM_VARIANT
18702#define ARM_VARIANT & arm_ext_v8
18703#undef THUMB_VARIANT
18704#define THUMB_VARIANT & arm_ext_v8
18705
18706 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
8884b720 18707 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
4b8c8c02
RE
18708 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18709 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
9eb6c0f1 18710 ldrexd, t_ldrexd),
4b8c8c02
RE
18711 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
18712 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18713 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
18714 stlex, t_stlex),
18715 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
9eb6c0f1 18716 strexd, t_strexd),
4b8c8c02
RE
18717 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
18718 stlex, t_stlex),
18719 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
18720 stlex, t_stlex),
18721 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18722 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18723 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18724 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
18725 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
18726 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
53c4b28b 18727
8884b720 18728 /* ARMv8 T32 only. */
74db7efb 18729#undef ARM_VARIANT
b79f7053
MGD
18730#define ARM_VARIANT NULL
18731 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
18732 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
18733 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
18734
33399f07
MGD
18735 /* FP for ARMv8. */
18736#undef ARM_VARIANT
74db7efb 18737#define ARM_VARIANT & fpu_vfp_ext_armv8
33399f07
MGD
18738#undef THUMB_VARIANT
18739#define THUMB_VARIANT & fpu_vfp_ext_armv8
18740
18741 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
18742 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
18743 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
18744 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
18745 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
18746 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
18747 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
18748 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
18749 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
18750 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
18751 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
18752 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
18753 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
18754 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
18755 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
18756 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
18757 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 18758
91ff7894
MGD
18759 /* Crypto v1 extensions. */
18760#undef ARM_VARIANT
18761#define ARM_VARIANT & fpu_crypto_ext_armv8
18762#undef THUMB_VARIANT
18763#define THUMB_VARIANT & fpu_crypto_ext_armv8
18764
18765 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
18766 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
18767 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
18768 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
18769 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
18770 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
18771 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
18772 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
18773 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
18774 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
18775 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
18776 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
18777 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
18778 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 18779
dd5181d5 18780#undef ARM_VARIANT
74db7efb 18781#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
18782#undef THUMB_VARIANT
18783#define THUMB_VARIANT & crc_ext_armv8
18784 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
18785 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
18786 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
18787 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
18788 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
18789 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
18790
c921be7d
NC
18791#undef ARM_VARIANT
18792#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
18793#undef THUMB_VARIANT
18794#define THUMB_VARIANT NULL
c921be7d 18795
21d799b5
NC
18796 cCE("wfs", e200110, 1, (RR), rd),
18797 cCE("rfs", e300110, 1, (RR), rd),
18798 cCE("wfc", e400110, 1, (RR), rd),
18799 cCE("rfc", e500110, 1, (RR), rd),
18800
18801 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
18802 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
18803 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
18804 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
18805
18806 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
18807 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
18808 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
18809 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
18810
18811 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
18812 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
18813 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
18814 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
18815 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
18816 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
18817 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
18818 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
18819 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
18820 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
18821 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
18822 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
18823
18824 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
18825 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
18826 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
18827 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
18828 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
18829 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
18830 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
18831 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
18832 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
18833 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
18834 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
18835 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
18836
18837 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
18838 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
18839 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
18840 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
18841 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
18842 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
18843 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
18844 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
18845 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
18846 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
18847 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
18848 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
18849
18850 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
18851 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
18852 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
18853 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
18854 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
18855 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
18856 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
18857 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
18858 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
18859 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
18860 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
18861 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
18862
18863 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
18864 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
18865 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
18866 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
18867 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
18868 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
18869 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
18870 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
18871 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
18872 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
18873 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
18874 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
18875
18876 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
18877 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
18878 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
18879 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
18880 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
18881 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
18882 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
18883 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
18884 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
18885 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
18886 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
18887 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
18888
18889 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
18890 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
18891 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
18892 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
18893 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
18894 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
18895 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
18896 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
18897 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
18898 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
18899 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
18900 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
18901
18902 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
18903 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
18904 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
18905 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
18906 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
18907 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
18908 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
18909 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
18910 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
18911 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
18912 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
18913 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
18914
18915 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
18916 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
18917 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
18918 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
18919 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
18920 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
18921 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
18922 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
18923 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
18924 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
18925 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
18926 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
18927
18928 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
18929 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
18930 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
18931 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
18932 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
18933 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
18934 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
18935 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
18936 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
18937 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
18938 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
18939 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
18940
18941 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
18942 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
18943 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
18944 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
18945 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
18946 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
18947 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
18948 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
18949 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
18950 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
18951 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
18952 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
18953
18954 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
18955 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
18956 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
18957 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
18958 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
18959 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
18960 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
18961 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
18962 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
18963 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
18964 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
18965 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
18966
18967 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
18968 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
18969 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
18970 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
18971 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
18972 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
18973 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
18974 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
18975 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
18976 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
18977 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
18978 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
18979
18980 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
18981 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
18982 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
18983 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
18984 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
18985 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
18986 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
18987 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
18988 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
18989 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
18990 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
18991 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
18992
18993 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
18994 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
18995 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
18996 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
18997 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
18998 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
18999 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
19000 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
19001 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
19002 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
19003 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
19004 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
19005
19006 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
19007 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
19008 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
19009 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
19010 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
19011 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
19012 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
19013 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
19014 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
19015 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
19016 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
19017 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
19018
19019 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
19020 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
19021 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
19022 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
19023 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
19024 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19025 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19026 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19027 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
19028 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
19029 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
19030 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
19031
19032 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
19033 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
19034 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
19035 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
19036 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
19037 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19038 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19039 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19040 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
19041 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
19042 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
19043 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
19044
19045 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
19046 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
19047 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
19048 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
19049 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
19050 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19051 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19052 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19053 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
19054 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
19055 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
19056 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
19057
19058 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
19059 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
19060 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
19061 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
19062 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
19063 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19064 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19065 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19066 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
19067 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
19068 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
19069 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
19070
19071 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
19072 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
19073 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
19074 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
19075 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
19076 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19077 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19078 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19079 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
19080 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
19081 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
19082 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
19083
19084 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
19085 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
19086 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
19087 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
19088 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
19089 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19090 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19091 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19092 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
19093 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
19094 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
19095 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
19096
19097 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
19098 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
19099 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
19100 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
19101 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
19102 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19103 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19104 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19105 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
19106 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
19107 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
19108 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
19109
19110 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
19111 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
19112 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
19113 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
19114 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
19115 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19116 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19117 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19118 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
19119 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
19120 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
19121 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
19122
19123 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
19124 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
19125 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
19126 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
19127 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
19128 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19129 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19130 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19131 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
19132 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
19133 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
19134 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
19135
19136 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
19137 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
19138 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
19139 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
19140 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
19141 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19142 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19143 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19144 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
19145 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
19146 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
19147 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
19148
19149 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19150 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19151 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19152 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19153 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19154 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19155 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19156 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19157 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19158 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19159 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19160 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19161
19162 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19163 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19164 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19165 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19166 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19167 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19168 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19169 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19170 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19171 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19172 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19173 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19174
19175 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19176 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19177 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19178 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19179 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19180 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19181 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19182 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19183 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19184 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19185 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19186 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19187
19188 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
19189 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
19190 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
19191 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
19192
19193 cCL("flts", e000110, 2, (RF, RR), rn_rd),
19194 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
19195 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
19196 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
19197 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
19198 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
19199 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
19200 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
19201 cCL("flte", e080110, 2, (RF, RR), rn_rd),
19202 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
19203 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
19204 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 19205
c19d1205
ZW
19206 /* The implementation of the FIX instruction is broken on some
19207 assemblers, in that it accepts a precision specifier as well as a
19208 rounding specifier, despite the fact that this is meaningless.
19209 To be more compatible, we accept it as well, though of course it
19210 does not set any bits. */
21d799b5
NC
19211 cCE("fix", e100110, 2, (RR, RF), rd_rm),
19212 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
19213 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
19214 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
19215 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
19216 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
19217 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
19218 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
19219 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
19220 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
19221 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
19222 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
19223 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 19224
c19d1205 19225 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
19226#undef ARM_VARIANT
19227#define ARM_VARIANT & fpu_fpa_ext_v2
19228
21d799b5
NC
19229 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19230 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19231 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19232 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19233 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19234 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 19235
c921be7d
NC
19236#undef ARM_VARIANT
19237#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
19238
c19d1205 19239 /* Moves and type conversions. */
21d799b5
NC
19240 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
19241 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
19242 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
19243 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
19244 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
19245 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
19246 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
19247 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
19248 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
19249 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
19250 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
19251 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
19252 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
19253 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
19254
19255 /* Memory operations. */
21d799b5
NC
19256 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
19257 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
19258 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19259 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19260 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19261 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19262 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19263 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19264 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19265 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19266 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19267 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19268 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19269 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19270 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19271 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19272 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19273 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 19274
c19d1205 19275 /* Monadic operations. */
21d799b5
NC
19276 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
19277 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
19278 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
19279
19280 /* Dyadic operations. */
21d799b5
NC
19281 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19282 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19283 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19284 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19285 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19286 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19287 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19288 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19289 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 19290
c19d1205 19291 /* Comparisons. */
21d799b5
NC
19292 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
19293 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
19294 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
19295 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 19296
62f3b8c8
PB
19297 /* Double precision load/store are still present on single precision
19298 implementations. */
19299 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
19300 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
19301 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19302 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19303 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19304 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19305 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19306 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19307 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19308 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 19309
c921be7d
NC
19310#undef ARM_VARIANT
19311#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
19312
c19d1205 19313 /* Moves and type conversions. */
21d799b5
NC
19314 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19315 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19316 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19317 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
19318 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
19319 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
19320 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
19321 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19322 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
19323 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19324 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19325 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19326 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 19327
c19d1205 19328 /* Monadic operations. */
21d799b5
NC
19329 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19330 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19331 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
19332
19333 /* Dyadic operations. */
21d799b5
NC
19334 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19335 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19336 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19337 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19338 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19339 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19340 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19341 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19342 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 19343
c19d1205 19344 /* Comparisons. */
21d799b5
NC
19345 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19346 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
19347 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19348 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 19349
c921be7d
NC
19350#undef ARM_VARIANT
19351#define ARM_VARIANT & fpu_vfp_ext_v2
19352
21d799b5
NC
19353 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
19354 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
19355 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
19356 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 19357
037e8744
JB
19358/* Instructions which may belong to either the Neon or VFP instruction sets.
19359 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
19360#undef ARM_VARIANT
19361#define ARM_VARIANT & fpu_vfp_ext_v1xd
19362#undef THUMB_VARIANT
19363#define THUMB_VARIANT & fpu_vfp_ext_v1xd
19364
037e8744
JB
19365 /* These mnemonics are unique to VFP. */
19366 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
19367 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
19368 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19369 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19370 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19371 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
19372 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
19373 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
19374 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
19375 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
19376
19377 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
19378 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
19379 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
19380 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 19381
21d799b5
NC
19382 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
19383 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
19384
19385 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19386 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19387
55881a11
MGD
19388 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19389 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19390 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19391 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19392 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19393 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
19394 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
19395 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 19396
5f1af56b 19397 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 19398 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
19399 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
19400 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 19401
037e8744
JB
19402
19403 /* NOTE: All VMOV encoding is special-cased! */
19404 NCE(vmov, 0, 1, (VMOV), neon_mov),
19405 NCE(vmovq, 0, 1, (VMOV), neon_mov),
19406
c921be7d
NC
19407#undef THUMB_VARIANT
19408#define THUMB_VARIANT & fpu_neon_ext_v1
19409#undef ARM_VARIANT
19410#define ARM_VARIANT & fpu_neon_ext_v1
19411
5287ad62
JB
19412 /* Data processing with three registers of the same length. */
19413 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
19414 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
19415 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
19416 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19417 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19418 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19419 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19420 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19421 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19422 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
19423 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19424 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
19425 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19426 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
19427 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19428 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
19429 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19430 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
19431 /* If not immediate, fall back to neon_dyadic_i64_su.
19432 shl_imm should accept I8 I16 I32 I64,
19433 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
19434 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
19435 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
19436 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
19437 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 19438 /* Logic ops, types optional & ignored. */
4316f0d2
DG
19439 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19440 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19441 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19442 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19443 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19444 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19445 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19446 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19447 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
19448 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
19449 /* Bitfield ops, untyped. */
19450 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19451 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19452 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19453 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19454 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19455 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19456 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
19457 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19458 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19459 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19460 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19461 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19462 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
19463 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
19464 back to neon_dyadic_if_su. */
21d799b5
NC
19465 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19466 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19467 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19468 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19469 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19470 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
19471 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19472 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 19473 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
19474 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
19475 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 19476 /* As above, D registers only. */
21d799b5
NC
19477 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
19478 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 19479 /* Int and float variants, signedness unimportant. */
21d799b5
NC
19480 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19481 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19482 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 19483 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
19484 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
19485 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
19486 /* vtst takes sizes 8, 16, 32. */
19487 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
19488 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
19489 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 19490 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 19491 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
19492 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19493 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19494 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19495 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
19496 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19497 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
19498 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19499 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
19500 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19501 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
19502 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19503 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
19504 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19505 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19506 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19507 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19508
19509 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 19510 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
19511 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
19512
19513 /* Data processing with two registers and a shift amount. */
19514 /* Right shifts, and variants with rounding.
19515 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
19516 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19517 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19518 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19519 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19520 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19521 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19522 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19523 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19524 /* Shift and insert. Sizes accepted 8 16 32 64. */
19525 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
19526 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
19527 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
19528 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
19529 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
19530 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
19531 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
19532 /* Right shift immediate, saturating & narrowing, with rounding variants.
19533 Types accepted S16 S32 S64 U16 U32 U64. */
19534 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19535 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19536 /* As above, unsigned. Types accepted S16 S32 S64. */
19537 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19538 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19539 /* Right shift narrowing. Types accepted I16 I32 I64. */
19540 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19541 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19542 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 19543 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 19544 /* CVT with optional immediate for fixed-point variant. */
21d799b5 19545 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 19546
4316f0d2
DG
19547 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
19548 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
19549
19550 /* Data processing, three registers of different lengths. */
19551 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
19552 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
19553 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
19554 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
19555 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
19556 /* If not scalar, fall back to neon_dyadic_long.
19557 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
19558 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
19559 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
19560 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
19561 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
19562 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
19563 /* Dyadic, narrowing insns. Types I16 I32 I64. */
19564 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19565 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19566 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19567 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19568 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
19569 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
19570 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
19571 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
19572 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
19573 S16 S32 U16 U32. */
21d799b5 19574 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
19575
19576 /* Extract. Size 8. */
3b8d421e
PB
19577 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
19578 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
19579
19580 /* Two registers, miscellaneous. */
19581 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
19582 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
19583 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
19584 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
19585 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
19586 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
19587 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
19588 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
19589 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
19590 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
19591 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
19592 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
19593 /* VMOVN. Types I16 I32 I64. */
21d799b5 19594 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 19595 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 19596 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 19597 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 19598 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
19599 /* VZIP / VUZP. Sizes 8 16 32. */
19600 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
19601 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
19602 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
19603 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
19604 /* VQABS / VQNEG. Types S8 S16 S32. */
19605 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
19606 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
19607 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
19608 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
19609 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
19610 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
19611 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
19612 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
19613 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
19614 /* Reciprocal estimates. Types U32 F32. */
19615 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
19616 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
19617 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
19618 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
19619 /* VCLS. Types S8 S16 S32. */
19620 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
19621 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
19622 /* VCLZ. Types I8 I16 I32. */
19623 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
19624 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
19625 /* VCNT. Size 8. */
19626 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
19627 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
19628 /* Two address, untyped. */
19629 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
19630 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
19631 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
19632 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
19633 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
19634
19635 /* Table lookup. Size 8. */
19636 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
19637 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
19638
c921be7d
NC
19639#undef THUMB_VARIANT
19640#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
19641#undef ARM_VARIANT
19642#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
19643
5287ad62 19644 /* Neon element/structure load/store. */
21d799b5
NC
19645 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
19646 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
19647 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
19648 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
19649 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
19650 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
19651 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
19652 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 19653
c921be7d 19654#undef THUMB_VARIANT
74db7efb
NC
19655#define THUMB_VARIANT & fpu_vfp_ext_v3xd
19656#undef ARM_VARIANT
19657#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
19658 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
19659 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19660 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19661 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19662 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19663 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19664 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19665 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19666 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19667
74db7efb 19668#undef THUMB_VARIANT
c921be7d
NC
19669#define THUMB_VARIANT & fpu_vfp_ext_v3
19670#undef ARM_VARIANT
19671#define ARM_VARIANT & fpu_vfp_ext_v3
19672
21d799b5 19673 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 19674 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 19675 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 19676 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 19677 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 19678 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 19679 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 19680 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 19681 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 19682
74db7efb
NC
19683#undef ARM_VARIANT
19684#define ARM_VARIANT & fpu_vfp_ext_fma
19685#undef THUMB_VARIANT
19686#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
19687 /* Mnemonics shared by Neon and VFP. These are included in the
19688 VFP FMA variant; NEON and VFP FMA always includes the NEON
19689 FMA instructions. */
19690 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
19691 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
19692 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
19693 the v form should always be used. */
19694 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19695 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19696 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19697 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19698 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19699 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19700
5287ad62 19701#undef THUMB_VARIANT
c921be7d
NC
19702#undef ARM_VARIANT
19703#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
19704
21d799b5
NC
19705 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19706 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19707 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19708 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19709 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19710 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19711 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
19712 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 19713
c921be7d
NC
19714#undef ARM_VARIANT
19715#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
19716
21d799b5
NC
19717 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
19718 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
19719 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
19720 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
19721 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
19722 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
19723 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
19724 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
19725 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
19726 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
19727 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
19728 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
19729 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
19730 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
19731 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
19732 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
19733 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
19734 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
19735 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
19736 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
19737 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19738 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19739 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19740 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19741 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19742 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
19743 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
19744 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
19745 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
19746 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
19747 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
19748 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
19749 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
19750 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
19751 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
19752 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
19753 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
19754 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19755 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19756 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19757 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19758 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19759 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19760 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19761 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19762 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19763 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
19764 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19765 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19766 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19767 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
19768 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19769 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19770 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19771 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19772 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19773 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19774 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19775 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19776 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
19777 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19778 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19779 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19780 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19781 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19782 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
19783 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19784 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19785 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
19786 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
19787 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19788 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19789 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19790 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19791 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19792 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19793 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19794 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19795 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19796 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19797 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19798 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19799 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19800 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19801 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19802 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19803 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19804 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19805 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
19806 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19807 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19808 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19809 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19810 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
19811 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19812 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19813 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19814 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19815 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19816 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
19817 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19818 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19819 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19820 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19821 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19822 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19823 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19824 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19825 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19826 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19827 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
19828 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19829 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19830 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19831 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19832 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19833 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19834 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19835 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19836 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19837 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19838 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19839 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19840 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19841 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19842 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19843 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19844 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19845 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19846 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19847 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19848 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
19849 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
19850 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19851 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19852 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19853 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19854 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19855 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19856 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19857 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19858 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19859 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
19860 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
19861 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
19862 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
19863 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
19864 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
19865 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19866 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19867 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19868 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
19869 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
19870 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
19871 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
19872 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
19873 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
19874 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19875 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19876 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19877 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19878 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 19879
c921be7d
NC
19880#undef ARM_VARIANT
19881#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
19882
21d799b5
NC
19883 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
19884 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
19885 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
19886 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
19887 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
19888 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
19889 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19890 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19891 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19892 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19893 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19894 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19895 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19896 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19897 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19898 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19899 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19900 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19901 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19902 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19903 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
19904 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19905 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19906 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19907 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19908 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19909 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19910 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19911 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19912 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19913 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19914 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19915 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19916 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19917 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19918 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19919 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19920 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19921 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19922 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19923 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19924 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19925 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19926 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19927 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19928 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19929 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19930 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19931 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19932 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19933 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19934 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19935 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19936 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19937 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19938 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19939 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 19940
c921be7d
NC
19941#undef ARM_VARIANT
19942#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
19943
21d799b5
NC
19944 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
19945 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
19946 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
19947 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
19948 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
19949 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
19950 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
19951 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
19952 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
19953 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
19954 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
19955 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
19956 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
19957 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
19958 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
19959 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
19960 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
19961 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
19962 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
19963 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
19964 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
19965 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
19966 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
19967 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
19968 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
19969 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
19970 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
19971 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
19972 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
19973 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
19974 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
19975 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
19976 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
19977 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
19978 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
19979 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
19980 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
19981 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
19982 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
19983 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
19984 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
19985 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
19986 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
19987 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
19988 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
19989 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
19990 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
19991 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
19992 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
19993 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
19994 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
19995 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
19996 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
19997 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
19998 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
19999 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
20000 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
20001 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
20002 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
20003 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
20004 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
20005 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
20006 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
20007 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
20008 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20009 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20010 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20011 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20012 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20013 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20014 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20015 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
20016 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
20017 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
20018 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
20019 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
20020};
20021#undef ARM_VARIANT
20022#undef THUMB_VARIANT
20023#undef TCE
c19d1205
ZW
20024#undef TUE
20025#undef TUF
20026#undef TCC
8f06b2d8 20027#undef cCE
e3cb604e
PB
20028#undef cCL
20029#undef C3E
c19d1205
ZW
20030#undef CE
20031#undef CM
20032#undef UE
20033#undef UF
20034#undef UT
5287ad62
JB
20035#undef NUF
20036#undef nUF
20037#undef NCE
20038#undef nCE
c19d1205
ZW
20039#undef OPS0
20040#undef OPS1
20041#undef OPS2
20042#undef OPS3
20043#undef OPS4
20044#undef OPS5
20045#undef OPS6
20046#undef do_0
20047\f
20048/* MD interface: bits in the object file. */
bfae80f2 20049
c19d1205
ZW
20050/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
20051 for use in the a.out file, and stores them in the array pointed to by buf.
20052 This knows about the endian-ness of the target machine and does
20053 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
20054 2 (short) and 4 (long) Floating numbers are put out as a series of
20055 LITTLENUMS (shorts, here at least). */
b99bd4ef 20056
c19d1205
ZW
20057void
20058md_number_to_chars (char * buf, valueT val, int n)
20059{
20060 if (target_big_endian)
20061 number_to_chars_bigendian (buf, val, n);
20062 else
20063 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
20064}
20065
c19d1205
ZW
20066static valueT
20067md_chars_to_number (char * buf, int n)
bfae80f2 20068{
c19d1205
ZW
20069 valueT result = 0;
20070 unsigned char * where = (unsigned char *) buf;
bfae80f2 20071
c19d1205 20072 if (target_big_endian)
b99bd4ef 20073 {
c19d1205
ZW
20074 while (n--)
20075 {
20076 result <<= 8;
20077 result |= (*where++ & 255);
20078 }
b99bd4ef 20079 }
c19d1205 20080 else
b99bd4ef 20081 {
c19d1205
ZW
20082 while (n--)
20083 {
20084 result <<= 8;
20085 result |= (where[n] & 255);
20086 }
bfae80f2 20087 }
b99bd4ef 20088
c19d1205 20089 return result;
bfae80f2 20090}
b99bd4ef 20091
c19d1205 20092/* MD interface: Sections. */
b99bd4ef 20093
fa94de6b
RM
20094/* Calculate the maximum variable size (i.e., excluding fr_fix)
20095 that an rs_machine_dependent frag may reach. */
20096
20097unsigned int
20098arm_frag_max_var (fragS *fragp)
20099{
20100 /* We only use rs_machine_dependent for variable-size Thumb instructions,
20101 which are either THUMB_SIZE (2) or INSN_SIZE (4).
20102
20103 Note that we generate relaxable instructions even for cases that don't
20104 really need it, like an immediate that's a trivial constant. So we're
20105 overestimating the instruction size for some of those cases. Rather
20106 than putting more intelligence here, it would probably be better to
20107 avoid generating a relaxation frag in the first place when it can be
20108 determined up front that a short instruction will suffice. */
20109
20110 gas_assert (fragp->fr_type == rs_machine_dependent);
20111 return INSN_SIZE;
20112}
20113
0110f2b8
PB
20114/* Estimate the size of a frag before relaxing. Assume everything fits in
20115 2 bytes. */
20116
c19d1205 20117int
0110f2b8 20118md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
20119 segT segtype ATTRIBUTE_UNUSED)
20120{
0110f2b8
PB
20121 fragp->fr_var = 2;
20122 return 2;
20123}
20124
20125/* Convert a machine dependent frag. */
20126
20127void
20128md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
20129{
20130 unsigned long insn;
20131 unsigned long old_op;
20132 char *buf;
20133 expressionS exp;
20134 fixS *fixp;
20135 int reloc_type;
20136 int pc_rel;
20137 int opcode;
20138
20139 buf = fragp->fr_literal + fragp->fr_fix;
20140
20141 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
20142 if (fragp->fr_symbol)
20143 {
0110f2b8
PB
20144 exp.X_op = O_symbol;
20145 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
20146 }
20147 else
20148 {
0110f2b8 20149 exp.X_op = O_constant;
5f4273c7 20150 }
0110f2b8
PB
20151 exp.X_add_number = fragp->fr_offset;
20152 opcode = fragp->fr_subtype;
20153 switch (opcode)
20154 {
20155 case T_MNEM_ldr_pc:
20156 case T_MNEM_ldr_pc2:
20157 case T_MNEM_ldr_sp:
20158 case T_MNEM_str_sp:
20159 case T_MNEM_ldr:
20160 case T_MNEM_ldrb:
20161 case T_MNEM_ldrh:
20162 case T_MNEM_str:
20163 case T_MNEM_strb:
20164 case T_MNEM_strh:
20165 if (fragp->fr_var == 4)
20166 {
5f4273c7 20167 insn = THUMB_OP32 (opcode);
0110f2b8
PB
20168 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
20169 {
20170 insn |= (old_op & 0x700) << 4;
20171 }
20172 else
20173 {
20174 insn |= (old_op & 7) << 12;
20175 insn |= (old_op & 0x38) << 13;
20176 }
20177 insn |= 0x00000c00;
20178 put_thumb32_insn (buf, insn);
20179 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
20180 }
20181 else
20182 {
20183 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
20184 }
20185 pc_rel = (opcode == T_MNEM_ldr_pc2);
20186 break;
20187 case T_MNEM_adr:
20188 if (fragp->fr_var == 4)
20189 {
20190 insn = THUMB_OP32 (opcode);
20191 insn |= (old_op & 0xf0) << 4;
20192 put_thumb32_insn (buf, insn);
20193 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
20194 }
20195 else
20196 {
20197 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20198 exp.X_add_number -= 4;
20199 }
20200 pc_rel = 1;
20201 break;
20202 case T_MNEM_mov:
20203 case T_MNEM_movs:
20204 case T_MNEM_cmp:
20205 case T_MNEM_cmn:
20206 if (fragp->fr_var == 4)
20207 {
20208 int r0off = (opcode == T_MNEM_mov
20209 || opcode == T_MNEM_movs) ? 0 : 8;
20210 insn = THUMB_OP32 (opcode);
20211 insn = (insn & 0xe1ffffff) | 0x10000000;
20212 insn |= (old_op & 0x700) << r0off;
20213 put_thumb32_insn (buf, insn);
20214 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
20215 }
20216 else
20217 {
20218 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
20219 }
20220 pc_rel = 0;
20221 break;
20222 case T_MNEM_b:
20223 if (fragp->fr_var == 4)
20224 {
20225 insn = THUMB_OP32(opcode);
20226 put_thumb32_insn (buf, insn);
20227 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
20228 }
20229 else
20230 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
20231 pc_rel = 1;
20232 break;
20233 case T_MNEM_bcond:
20234 if (fragp->fr_var == 4)
20235 {
20236 insn = THUMB_OP32(opcode);
20237 insn |= (old_op & 0xf00) << 14;
20238 put_thumb32_insn (buf, insn);
20239 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
20240 }
20241 else
20242 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
20243 pc_rel = 1;
20244 break;
20245 case T_MNEM_add_sp:
20246 case T_MNEM_add_pc:
20247 case T_MNEM_inc_sp:
20248 case T_MNEM_dec_sp:
20249 if (fragp->fr_var == 4)
20250 {
20251 /* ??? Choose between add and addw. */
20252 insn = THUMB_OP32 (opcode);
20253 insn |= (old_op & 0xf0) << 4;
20254 put_thumb32_insn (buf, insn);
16805f35
PB
20255 if (opcode == T_MNEM_add_pc)
20256 reloc_type = BFD_RELOC_ARM_T32_IMM12;
20257 else
20258 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
20259 }
20260 else
20261 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20262 pc_rel = 0;
20263 break;
20264
20265 case T_MNEM_addi:
20266 case T_MNEM_addis:
20267 case T_MNEM_subi:
20268 case T_MNEM_subis:
20269 if (fragp->fr_var == 4)
20270 {
20271 insn = THUMB_OP32 (opcode);
20272 insn |= (old_op & 0xf0) << 4;
20273 insn |= (old_op & 0xf) << 16;
20274 put_thumb32_insn (buf, insn);
16805f35
PB
20275 if (insn & (1 << 20))
20276 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
20277 else
20278 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
20279 }
20280 else
20281 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20282 pc_rel = 0;
20283 break;
20284 default:
5f4273c7 20285 abort ();
0110f2b8
PB
20286 }
20287 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 20288 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
20289 fixp->fx_file = fragp->fr_file;
20290 fixp->fx_line = fragp->fr_line;
20291 fragp->fr_fix += fragp->fr_var;
20292}
20293
20294/* Return the size of a relaxable immediate operand instruction.
20295 SHIFT and SIZE specify the form of the allowable immediate. */
20296static int
20297relax_immediate (fragS *fragp, int size, int shift)
20298{
20299 offsetT offset;
20300 offsetT mask;
20301 offsetT low;
20302
20303 /* ??? Should be able to do better than this. */
20304 if (fragp->fr_symbol)
20305 return 4;
20306
20307 low = (1 << shift) - 1;
20308 mask = (1 << (shift + size)) - (1 << shift);
20309 offset = fragp->fr_offset;
20310 /* Force misaligned offsets to 32-bit variant. */
20311 if (offset & low)
5e77afaa 20312 return 4;
0110f2b8
PB
20313 if (offset & ~mask)
20314 return 4;
20315 return 2;
20316}
20317
5e77afaa
PB
20318/* Get the address of a symbol during relaxation. */
20319static addressT
5f4273c7 20320relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
20321{
20322 fragS *sym_frag;
20323 addressT addr;
20324 symbolS *sym;
20325
20326 sym = fragp->fr_symbol;
20327 sym_frag = symbol_get_frag (sym);
20328 know (S_GET_SEGMENT (sym) != absolute_section
20329 || sym_frag == &zero_address_frag);
20330 addr = S_GET_VALUE (sym) + fragp->fr_offset;
20331
20332 /* If frag has yet to be reached on this pass, assume it will
20333 move by STRETCH just as we did. If this is not so, it will
20334 be because some frag between grows, and that will force
20335 another pass. */
20336
20337 if (stretch != 0
20338 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
20339 {
20340 fragS *f;
20341
20342 /* Adjust stretch for any alignment frag. Note that if have
20343 been expanding the earlier code, the symbol may be
20344 defined in what appears to be an earlier frag. FIXME:
20345 This doesn't handle the fr_subtype field, which specifies
20346 a maximum number of bytes to skip when doing an
20347 alignment. */
20348 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
20349 {
20350 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
20351 {
20352 if (stretch < 0)
20353 stretch = - ((- stretch)
20354 & ~ ((1 << (int) f->fr_offset) - 1));
20355 else
20356 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
20357 if (stretch == 0)
20358 break;
20359 }
20360 }
20361 if (f != NULL)
20362 addr += stretch;
20363 }
5e77afaa
PB
20364
20365 return addr;
20366}
20367
0110f2b8
PB
20368/* Return the size of a relaxable adr pseudo-instruction or PC-relative
20369 load. */
20370static int
5e77afaa 20371relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
20372{
20373 addressT addr;
20374 offsetT val;
20375
20376 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
20377 if (fragp->fr_symbol == NULL
20378 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
20379 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20380 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
20381 return 4;
20382
5f4273c7 20383 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
20384 addr = fragp->fr_address + fragp->fr_fix;
20385 addr = (addr + 4) & ~3;
5e77afaa 20386 /* Force misaligned targets to 32-bit variant. */
0110f2b8 20387 if (val & 3)
5e77afaa 20388 return 4;
0110f2b8
PB
20389 val -= addr;
20390 if (val < 0 || val > 1020)
20391 return 4;
20392 return 2;
20393}
20394
20395/* Return the size of a relaxable add/sub immediate instruction. */
20396static int
20397relax_addsub (fragS *fragp, asection *sec)
20398{
20399 char *buf;
20400 int op;
20401
20402 buf = fragp->fr_literal + fragp->fr_fix;
20403 op = bfd_get_16(sec->owner, buf);
20404 if ((op & 0xf) == ((op >> 4) & 0xf))
20405 return relax_immediate (fragp, 8, 0);
20406 else
20407 return relax_immediate (fragp, 3, 0);
20408}
20409
e83a675f
RE
20410/* Return TRUE iff the definition of symbol S could be pre-empted
20411 (overridden) at link or load time. */
20412static bfd_boolean
20413symbol_preemptible (symbolS *s)
20414{
20415 /* Weak symbols can always be pre-empted. */
20416 if (S_IS_WEAK (s))
20417 return TRUE;
20418
20419 /* Non-global symbols cannot be pre-empted. */
20420 if (! S_IS_EXTERNAL (s))
20421 return FALSE;
20422
20423#ifdef OBJ_ELF
20424 /* In ELF, a global symbol can be marked protected, or private. In that
20425 case it can't be pre-empted (other definitions in the same link unit
20426 would violate the ODR). */
20427 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
20428 return FALSE;
20429#endif
20430
20431 /* Other global symbols might be pre-empted. */
20432 return TRUE;
20433}
0110f2b8
PB
20434
20435/* Return the size of a relaxable branch instruction. BITS is the
20436 size of the offset field in the narrow instruction. */
20437
20438static int
5e77afaa 20439relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
20440{
20441 addressT addr;
20442 offsetT val;
20443 offsetT limit;
20444
20445 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 20446 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
20447 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20448 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
20449 return 4;
20450
267bf995 20451#ifdef OBJ_ELF
e83a675f 20452 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
20453 if (S_IS_DEFINED (fragp->fr_symbol)
20454 && ARM_IS_FUNC (fragp->fr_symbol))
20455 return 4;
e83a675f 20456#endif
0d9b4b55 20457
e83a675f 20458 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 20459 return 4;
267bf995 20460
5f4273c7 20461 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
20462 addr = fragp->fr_address + fragp->fr_fix + 4;
20463 val -= addr;
20464
20465 /* Offset is a signed value *2 */
20466 limit = 1 << bits;
20467 if (val >= limit || val < -limit)
20468 return 4;
20469 return 2;
20470}
20471
20472
20473/* Relax a machine dependent frag. This returns the amount by which
20474 the current size of the frag should change. */
20475
20476int
5e77afaa 20477arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
20478{
20479 int oldsize;
20480 int newsize;
20481
20482 oldsize = fragp->fr_var;
20483 switch (fragp->fr_subtype)
20484 {
20485 case T_MNEM_ldr_pc2:
5f4273c7 20486 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
20487 break;
20488 case T_MNEM_ldr_pc:
20489 case T_MNEM_ldr_sp:
20490 case T_MNEM_str_sp:
5f4273c7 20491 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
20492 break;
20493 case T_MNEM_ldr:
20494 case T_MNEM_str:
5f4273c7 20495 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
20496 break;
20497 case T_MNEM_ldrh:
20498 case T_MNEM_strh:
5f4273c7 20499 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
20500 break;
20501 case T_MNEM_ldrb:
20502 case T_MNEM_strb:
5f4273c7 20503 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
20504 break;
20505 case T_MNEM_adr:
5f4273c7 20506 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
20507 break;
20508 case T_MNEM_mov:
20509 case T_MNEM_movs:
20510 case T_MNEM_cmp:
20511 case T_MNEM_cmn:
5f4273c7 20512 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
20513 break;
20514 case T_MNEM_b:
5f4273c7 20515 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
20516 break;
20517 case T_MNEM_bcond:
5f4273c7 20518 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
20519 break;
20520 case T_MNEM_add_sp:
20521 case T_MNEM_add_pc:
20522 newsize = relax_immediate (fragp, 8, 2);
20523 break;
20524 case T_MNEM_inc_sp:
20525 case T_MNEM_dec_sp:
20526 newsize = relax_immediate (fragp, 7, 2);
20527 break;
20528 case T_MNEM_addi:
20529 case T_MNEM_addis:
20530 case T_MNEM_subi:
20531 case T_MNEM_subis:
20532 newsize = relax_addsub (fragp, sec);
20533 break;
20534 default:
5f4273c7 20535 abort ();
0110f2b8 20536 }
5e77afaa
PB
20537
20538 fragp->fr_var = newsize;
20539 /* Freeze wide instructions that are at or before the same location as
20540 in the previous pass. This avoids infinite loops.
5f4273c7
NC
20541 Don't freeze them unconditionally because targets may be artificially
20542 misaligned by the expansion of preceding frags. */
5e77afaa 20543 if (stretch <= 0 && newsize > 2)
0110f2b8 20544 {
0110f2b8 20545 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 20546 frag_wane (fragp);
0110f2b8 20547 }
5e77afaa 20548
0110f2b8 20549 return newsize - oldsize;
c19d1205 20550}
b99bd4ef 20551
c19d1205 20552/* Round up a section size to the appropriate boundary. */
b99bd4ef 20553
c19d1205
ZW
20554valueT
20555md_section_align (segT segment ATTRIBUTE_UNUSED,
20556 valueT size)
20557{
f0927246
NC
20558#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
20559 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
20560 {
20561 /* For a.out, force the section size to be aligned. If we don't do
20562 this, BFD will align it for us, but it will not write out the
20563 final bytes of the section. This may be a bug in BFD, but it is
20564 easier to fix it here since that is how the other a.out targets
20565 work. */
20566 int align;
20567
20568 align = bfd_get_section_alignment (stdoutput, segment);
20569 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
20570 }
c19d1205 20571#endif
f0927246
NC
20572
20573 return size;
bfae80f2 20574}
b99bd4ef 20575
c19d1205
ZW
20576/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
20577 of an rs_align_code fragment. */
20578
20579void
20580arm_handle_align (fragS * fragP)
bfae80f2 20581{
e7495e45
NS
20582 static char const arm_noop[2][2][4] =
20583 {
20584 { /* ARMv1 */
20585 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
20586 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
20587 },
20588 { /* ARMv6k */
20589 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
20590 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
20591 },
20592 };
20593 static char const thumb_noop[2][2][2] =
20594 {
20595 { /* Thumb-1 */
20596 {0xc0, 0x46}, /* LE */
20597 {0x46, 0xc0}, /* BE */
20598 },
20599 { /* Thumb-2 */
20600 {0x00, 0xbf}, /* LE */
20601 {0xbf, 0x00} /* BE */
20602 }
20603 };
20604 static char const wide_thumb_noop[2][4] =
20605 { /* Wide Thumb-2 */
20606 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
20607 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
20608 };
c921be7d 20609
e7495e45 20610 unsigned bytes, fix, noop_size;
c19d1205
ZW
20611 char * p;
20612 const char * noop;
e7495e45 20613 const char *narrow_noop = NULL;
cd000bff
DJ
20614#ifdef OBJ_ELF
20615 enum mstate state;
20616#endif
bfae80f2 20617
c19d1205 20618 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
20619 return;
20620
c19d1205
ZW
20621 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
20622 p = fragP->fr_literal + fragP->fr_fix;
20623 fix = 0;
bfae80f2 20624
c19d1205
ZW
20625 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
20626 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 20627
cd000bff 20628 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 20629
cd000bff 20630 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 20631 {
e7495e45
NS
20632 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
20633 {
20634 narrow_noop = thumb_noop[1][target_big_endian];
20635 noop = wide_thumb_noop[target_big_endian];
20636 }
c19d1205 20637 else
e7495e45
NS
20638 noop = thumb_noop[0][target_big_endian];
20639 noop_size = 2;
cd000bff
DJ
20640#ifdef OBJ_ELF
20641 state = MAP_THUMB;
20642#endif
7ed4c4c5
NC
20643 }
20644 else
20645 {
e7495e45
NS
20646 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
20647 [target_big_endian];
20648 noop_size = 4;
cd000bff
DJ
20649#ifdef OBJ_ELF
20650 state = MAP_ARM;
20651#endif
7ed4c4c5 20652 }
c921be7d 20653
e7495e45 20654 fragP->fr_var = noop_size;
c921be7d 20655
c19d1205 20656 if (bytes & (noop_size - 1))
7ed4c4c5 20657 {
c19d1205 20658 fix = bytes & (noop_size - 1);
cd000bff
DJ
20659#ifdef OBJ_ELF
20660 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
20661#endif
c19d1205
ZW
20662 memset (p, 0, fix);
20663 p += fix;
20664 bytes -= fix;
a737bd4d 20665 }
a737bd4d 20666
e7495e45
NS
20667 if (narrow_noop)
20668 {
20669 if (bytes & noop_size)
20670 {
20671 /* Insert a narrow noop. */
20672 memcpy (p, narrow_noop, noop_size);
20673 p += noop_size;
20674 bytes -= noop_size;
20675 fix += noop_size;
20676 }
20677
20678 /* Use wide noops for the remainder */
20679 noop_size = 4;
20680 }
20681
c19d1205 20682 while (bytes >= noop_size)
a737bd4d 20683 {
c19d1205
ZW
20684 memcpy (p, noop, noop_size);
20685 p += noop_size;
20686 bytes -= noop_size;
20687 fix += noop_size;
a737bd4d
NC
20688 }
20689
c19d1205 20690 fragP->fr_fix += fix;
a737bd4d
NC
20691}
20692
c19d1205
ZW
20693/* Called from md_do_align. Used to create an alignment
20694 frag in a code section. */
20695
20696void
20697arm_frag_align_code (int n, int max)
bfae80f2 20698{
c19d1205 20699 char * p;
7ed4c4c5 20700
c19d1205 20701 /* We assume that there will never be a requirement
6ec8e702 20702 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 20703 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
20704 {
20705 char err_msg[128];
20706
fa94de6b 20707 sprintf (err_msg,
477330fc
RM
20708 _("alignments greater than %d bytes not supported in .text sections."),
20709 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 20710 as_fatal ("%s", err_msg);
6ec8e702 20711 }
bfae80f2 20712
c19d1205
ZW
20713 p = frag_var (rs_align_code,
20714 MAX_MEM_FOR_RS_ALIGN_CODE,
20715 1,
20716 (relax_substateT) max,
20717 (symbolS *) NULL,
20718 (offsetT) n,
20719 (char *) NULL);
20720 *p = 0;
20721}
bfae80f2 20722
8dc2430f
NC
20723/* Perform target specific initialisation of a frag.
20724 Note - despite the name this initialisation is not done when the frag
20725 is created, but only when its type is assigned. A frag can be created
20726 and used a long time before its type is set, so beware of assuming that
20727 this initialisationis performed first. */
bfae80f2 20728
cd000bff
DJ
20729#ifndef OBJ_ELF
20730void
20731arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
20732{
20733 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 20734 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
20735}
20736
20737#else /* OBJ_ELF is defined. */
c19d1205 20738void
cd000bff 20739arm_init_frag (fragS * fragP, int max_chars)
c19d1205 20740{
8dc2430f
NC
20741 /* If the current ARM vs THUMB mode has not already
20742 been recorded into this frag then do so now. */
cd000bff
DJ
20743 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
20744 {
20745 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
20746
20747 /* Record a mapping symbol for alignment frags. We will delete this
20748 later if the alignment ends up empty. */
20749 switch (fragP->fr_type)
20750 {
20751 case rs_align:
20752 case rs_align_test:
20753 case rs_fill:
20754 mapping_state_2 (MAP_DATA, max_chars);
20755 break;
20756 case rs_align_code:
20757 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
20758 break;
20759 default:
20760 break;
20761 }
20762 }
bfae80f2
RE
20763}
20764
c19d1205
ZW
20765/* When we change sections we need to issue a new mapping symbol. */
20766
20767void
20768arm_elf_change_section (void)
bfae80f2 20769{
c19d1205
ZW
20770 /* Link an unlinked unwind index table section to the .text section. */
20771 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
20772 && elf_linked_to_section (now_seg) == NULL)
20773 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
20774}
20775
c19d1205
ZW
20776int
20777arm_elf_section_type (const char * str, size_t len)
e45d0630 20778{
c19d1205
ZW
20779 if (len == 5 && strncmp (str, "exidx", 5) == 0)
20780 return SHT_ARM_EXIDX;
e45d0630 20781
c19d1205
ZW
20782 return -1;
20783}
20784\f
20785/* Code to deal with unwinding tables. */
e45d0630 20786
c19d1205 20787static void add_unwind_adjustsp (offsetT);
e45d0630 20788
5f4273c7 20789/* Generate any deferred unwind frame offset. */
e45d0630 20790
bfae80f2 20791static void
c19d1205 20792flush_pending_unwind (void)
bfae80f2 20793{
c19d1205 20794 offsetT offset;
bfae80f2 20795
c19d1205
ZW
20796 offset = unwind.pending_offset;
20797 unwind.pending_offset = 0;
20798 if (offset != 0)
20799 add_unwind_adjustsp (offset);
bfae80f2
RE
20800}
20801
c19d1205
ZW
20802/* Add an opcode to this list for this function. Two-byte opcodes should
20803 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
20804 order. */
20805
bfae80f2 20806static void
c19d1205 20807add_unwind_opcode (valueT op, int length)
bfae80f2 20808{
c19d1205
ZW
20809 /* Add any deferred stack adjustment. */
20810 if (unwind.pending_offset)
20811 flush_pending_unwind ();
bfae80f2 20812
c19d1205 20813 unwind.sp_restored = 0;
bfae80f2 20814
c19d1205 20815 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 20816 {
c19d1205
ZW
20817 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
20818 if (unwind.opcodes)
21d799b5 20819 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
477330fc 20820 unwind.opcode_alloc);
c19d1205 20821 else
21d799b5 20822 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 20823 }
c19d1205 20824 while (length > 0)
bfae80f2 20825 {
c19d1205
ZW
20826 length--;
20827 unwind.opcodes[unwind.opcode_count] = op & 0xff;
20828 op >>= 8;
20829 unwind.opcode_count++;
bfae80f2 20830 }
bfae80f2
RE
20831}
20832
c19d1205
ZW
20833/* Add unwind opcodes to adjust the stack pointer. */
20834
bfae80f2 20835static void
c19d1205 20836add_unwind_adjustsp (offsetT offset)
bfae80f2 20837{
c19d1205 20838 valueT op;
bfae80f2 20839
c19d1205 20840 if (offset > 0x200)
bfae80f2 20841 {
c19d1205
ZW
20842 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
20843 char bytes[5];
20844 int n;
20845 valueT o;
bfae80f2 20846
c19d1205
ZW
20847 /* Long form: 0xb2, uleb128. */
20848 /* This might not fit in a word so add the individual bytes,
20849 remembering the list is built in reverse order. */
20850 o = (valueT) ((offset - 0x204) >> 2);
20851 if (o == 0)
20852 add_unwind_opcode (0, 1);
bfae80f2 20853
c19d1205
ZW
20854 /* Calculate the uleb128 encoding of the offset. */
20855 n = 0;
20856 while (o)
20857 {
20858 bytes[n] = o & 0x7f;
20859 o >>= 7;
20860 if (o)
20861 bytes[n] |= 0x80;
20862 n++;
20863 }
20864 /* Add the insn. */
20865 for (; n; n--)
20866 add_unwind_opcode (bytes[n - 1], 1);
20867 add_unwind_opcode (0xb2, 1);
20868 }
20869 else if (offset > 0x100)
bfae80f2 20870 {
c19d1205
ZW
20871 /* Two short opcodes. */
20872 add_unwind_opcode (0x3f, 1);
20873 op = (offset - 0x104) >> 2;
20874 add_unwind_opcode (op, 1);
bfae80f2 20875 }
c19d1205
ZW
20876 else if (offset > 0)
20877 {
20878 /* Short opcode. */
20879 op = (offset - 4) >> 2;
20880 add_unwind_opcode (op, 1);
20881 }
20882 else if (offset < 0)
bfae80f2 20883 {
c19d1205
ZW
20884 offset = -offset;
20885 while (offset > 0x100)
bfae80f2 20886 {
c19d1205
ZW
20887 add_unwind_opcode (0x7f, 1);
20888 offset -= 0x100;
bfae80f2 20889 }
c19d1205
ZW
20890 op = ((offset - 4) >> 2) | 0x40;
20891 add_unwind_opcode (op, 1);
bfae80f2 20892 }
bfae80f2
RE
20893}
20894
c19d1205
ZW
20895/* Finish the list of unwind opcodes for this function. */
20896static void
20897finish_unwind_opcodes (void)
bfae80f2 20898{
c19d1205 20899 valueT op;
bfae80f2 20900
c19d1205 20901 if (unwind.fp_used)
bfae80f2 20902 {
708587a4 20903 /* Adjust sp as necessary. */
c19d1205
ZW
20904 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
20905 flush_pending_unwind ();
bfae80f2 20906
c19d1205
ZW
20907 /* After restoring sp from the frame pointer. */
20908 op = 0x90 | unwind.fp_reg;
20909 add_unwind_opcode (op, 1);
20910 }
20911 else
20912 flush_pending_unwind ();
bfae80f2
RE
20913}
20914
bfae80f2 20915
c19d1205
ZW
20916/* Start an exception table entry. If idx is nonzero this is an index table
20917 entry. */
bfae80f2
RE
20918
20919static void
c19d1205 20920start_unwind_section (const segT text_seg, int idx)
bfae80f2 20921{
c19d1205
ZW
20922 const char * text_name;
20923 const char * prefix;
20924 const char * prefix_once;
20925 const char * group_name;
20926 size_t prefix_len;
20927 size_t text_len;
20928 char * sec_name;
20929 size_t sec_name_len;
20930 int type;
20931 int flags;
20932 int linkonce;
bfae80f2 20933
c19d1205 20934 if (idx)
bfae80f2 20935 {
c19d1205
ZW
20936 prefix = ELF_STRING_ARM_unwind;
20937 prefix_once = ELF_STRING_ARM_unwind_once;
20938 type = SHT_ARM_EXIDX;
bfae80f2 20939 }
c19d1205 20940 else
bfae80f2 20941 {
c19d1205
ZW
20942 prefix = ELF_STRING_ARM_unwind_info;
20943 prefix_once = ELF_STRING_ARM_unwind_info_once;
20944 type = SHT_PROGBITS;
bfae80f2
RE
20945 }
20946
c19d1205
ZW
20947 text_name = segment_name (text_seg);
20948 if (streq (text_name, ".text"))
20949 text_name = "";
20950
20951 if (strncmp (text_name, ".gnu.linkonce.t.",
20952 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 20953 {
c19d1205
ZW
20954 prefix = prefix_once;
20955 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
20956 }
20957
c19d1205
ZW
20958 prefix_len = strlen (prefix);
20959 text_len = strlen (text_name);
20960 sec_name_len = prefix_len + text_len;
21d799b5 20961 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
20962 memcpy (sec_name, prefix, prefix_len);
20963 memcpy (sec_name + prefix_len, text_name, text_len);
20964 sec_name[prefix_len + text_len] = '\0';
bfae80f2 20965
c19d1205
ZW
20966 flags = SHF_ALLOC;
20967 linkonce = 0;
20968 group_name = 0;
bfae80f2 20969
c19d1205
ZW
20970 /* Handle COMDAT group. */
20971 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 20972 {
c19d1205
ZW
20973 group_name = elf_group_name (text_seg);
20974 if (group_name == NULL)
20975 {
bd3ba5d1 20976 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
20977 segment_name (text_seg));
20978 ignore_rest_of_line ();
20979 return;
20980 }
20981 flags |= SHF_GROUP;
20982 linkonce = 1;
bfae80f2
RE
20983 }
20984
c19d1205 20985 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 20986
5f4273c7 20987 /* Set the section link for index tables. */
c19d1205
ZW
20988 if (idx)
20989 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
20990}
20991
bfae80f2 20992
c19d1205
ZW
20993/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
20994 personality routine data. Returns zero, or the index table value for
20995 and inline entry. */
20996
20997static valueT
20998create_unwind_entry (int have_data)
bfae80f2 20999{
c19d1205
ZW
21000 int size;
21001 addressT where;
21002 char *ptr;
21003 /* The current word of data. */
21004 valueT data;
21005 /* The number of bytes left in this word. */
21006 int n;
bfae80f2 21007
c19d1205 21008 finish_unwind_opcodes ();
bfae80f2 21009
c19d1205
ZW
21010 /* Remember the current text section. */
21011 unwind.saved_seg = now_seg;
21012 unwind.saved_subseg = now_subseg;
bfae80f2 21013
c19d1205 21014 start_unwind_section (now_seg, 0);
bfae80f2 21015
c19d1205 21016 if (unwind.personality_routine == NULL)
bfae80f2 21017 {
c19d1205
ZW
21018 if (unwind.personality_index == -2)
21019 {
21020 if (have_data)
5f4273c7 21021 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
21022 return 1; /* EXIDX_CANTUNWIND. */
21023 }
bfae80f2 21024
c19d1205
ZW
21025 /* Use a default personality routine if none is specified. */
21026 if (unwind.personality_index == -1)
21027 {
21028 if (unwind.opcode_count > 3)
21029 unwind.personality_index = 1;
21030 else
21031 unwind.personality_index = 0;
21032 }
bfae80f2 21033
c19d1205
ZW
21034 /* Space for the personality routine entry. */
21035 if (unwind.personality_index == 0)
21036 {
21037 if (unwind.opcode_count > 3)
21038 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 21039
c19d1205
ZW
21040 if (!have_data)
21041 {
21042 /* All the data is inline in the index table. */
21043 data = 0x80;
21044 n = 3;
21045 while (unwind.opcode_count > 0)
21046 {
21047 unwind.opcode_count--;
21048 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21049 n--;
21050 }
bfae80f2 21051
c19d1205
ZW
21052 /* Pad with "finish" opcodes. */
21053 while (n--)
21054 data = (data << 8) | 0xb0;
bfae80f2 21055
c19d1205
ZW
21056 return data;
21057 }
21058 size = 0;
21059 }
21060 else
21061 /* We get two opcodes "free" in the first word. */
21062 size = unwind.opcode_count - 2;
21063 }
21064 else
5011093d
NC
21065 {
21066 gas_assert (unwind.personality_index == -1);
21067
21068 /* An extra byte is required for the opcode count. */
21069 size = unwind.opcode_count + 1;
21070 }
bfae80f2 21071
c19d1205
ZW
21072 size = (size + 3) >> 2;
21073 if (size > 0xff)
21074 as_bad (_("too many unwind opcodes"));
bfae80f2 21075
c19d1205
ZW
21076 frag_align (2, 0, 0);
21077 record_alignment (now_seg, 2);
21078 unwind.table_entry = expr_build_dot ();
21079
21080 /* Allocate the table entry. */
21081 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
21082 /* PR 13449: Zero the table entries in case some of them are not used. */
21083 memset (ptr, 0, (size << 2) + 4);
c19d1205 21084 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 21085
c19d1205 21086 switch (unwind.personality_index)
bfae80f2 21087 {
c19d1205
ZW
21088 case -1:
21089 /* ??? Should this be a PLT generating relocation? */
21090 /* Custom personality routine. */
21091 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
21092 BFD_RELOC_ARM_PREL31);
bfae80f2 21093
c19d1205
ZW
21094 where += 4;
21095 ptr += 4;
bfae80f2 21096
c19d1205 21097 /* Set the first byte to the number of additional words. */
5011093d 21098 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
21099 n = 3;
21100 break;
bfae80f2 21101
c19d1205
ZW
21102 /* ABI defined personality routines. */
21103 case 0:
21104 /* Three opcodes bytes are packed into the first word. */
21105 data = 0x80;
21106 n = 3;
21107 break;
bfae80f2 21108
c19d1205
ZW
21109 case 1:
21110 case 2:
21111 /* The size and first two opcode bytes go in the first word. */
21112 data = ((0x80 + unwind.personality_index) << 8) | size;
21113 n = 2;
21114 break;
bfae80f2 21115
c19d1205
ZW
21116 default:
21117 /* Should never happen. */
21118 abort ();
21119 }
bfae80f2 21120
c19d1205
ZW
21121 /* Pack the opcodes into words (MSB first), reversing the list at the same
21122 time. */
21123 while (unwind.opcode_count > 0)
21124 {
21125 if (n == 0)
21126 {
21127 md_number_to_chars (ptr, data, 4);
21128 ptr += 4;
21129 n = 4;
21130 data = 0;
21131 }
21132 unwind.opcode_count--;
21133 n--;
21134 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21135 }
21136
21137 /* Finish off the last word. */
21138 if (n < 4)
21139 {
21140 /* Pad with "finish" opcodes. */
21141 while (n--)
21142 data = (data << 8) | 0xb0;
21143
21144 md_number_to_chars (ptr, data, 4);
21145 }
21146
21147 if (!have_data)
21148 {
21149 /* Add an empty descriptor if there is no user-specified data. */
21150 ptr = frag_more (4);
21151 md_number_to_chars (ptr, 0, 4);
21152 }
21153
21154 return 0;
bfae80f2
RE
21155}
21156
f0927246
NC
21157
21158/* Initialize the DWARF-2 unwind information for this procedure. */
21159
21160void
21161tc_arm_frame_initial_instructions (void)
21162{
21163 cfi_add_CFA_def_cfa (REG_SP, 0);
21164}
21165#endif /* OBJ_ELF */
21166
c19d1205
ZW
21167/* Convert REGNAME to a DWARF-2 register number. */
21168
21169int
1df69f4f 21170tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 21171{
1df69f4f 21172 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
21173 if (reg != FAIL)
21174 return reg;
c19d1205 21175
1f5afe1c
NC
21176 /* PR 16694: Allow VFP registers as well. */
21177 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
21178 if (reg != FAIL)
21179 return 64 + reg;
c19d1205 21180
1f5afe1c
NC
21181 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
21182 if (reg != FAIL)
21183 return reg + 256;
21184
21185 return -1;
bfae80f2
RE
21186}
21187
f0927246 21188#ifdef TE_PE
c19d1205 21189void
f0927246 21190tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 21191{
91d6fa6a 21192 expressionS exp;
bfae80f2 21193
91d6fa6a
NC
21194 exp.X_op = O_secrel;
21195 exp.X_add_symbol = symbol;
21196 exp.X_add_number = 0;
21197 emit_expr (&exp, size);
f0927246
NC
21198}
21199#endif
bfae80f2 21200
c19d1205 21201/* MD interface: Symbol and relocation handling. */
bfae80f2 21202
2fc8bdac
ZW
21203/* Return the address within the segment that a PC-relative fixup is
21204 relative to. For ARM, PC-relative fixups applied to instructions
21205 are generally relative to the location of the fixup plus 8 bytes.
21206 Thumb branches are offset by 4, and Thumb loads relative to PC
21207 require special handling. */
bfae80f2 21208
c19d1205 21209long
2fc8bdac 21210md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 21211{
2fc8bdac
ZW
21212 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
21213
21214 /* If this is pc-relative and we are going to emit a relocation
21215 then we just want to put out any pipeline compensation that the linker
53baae48
NC
21216 will need. Otherwise we want to use the calculated base.
21217 For WinCE we skip the bias for externals as well, since this
21218 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 21219 if (fixP->fx_pcrel
2fc8bdac 21220 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
21221 || (arm_force_relocation (fixP)
21222#ifdef TE_WINCE
21223 && !S_IS_EXTERNAL (fixP->fx_addsy)
21224#endif
21225 )))
2fc8bdac 21226 base = 0;
bfae80f2 21227
267bf995 21228
c19d1205 21229 switch (fixP->fx_r_type)
bfae80f2 21230 {
2fc8bdac
ZW
21231 /* PC relative addressing on the Thumb is slightly odd as the
21232 bottom two bits of the PC are forced to zero for the
21233 calculation. This happens *after* application of the
21234 pipeline offset. However, Thumb adrl already adjusts for
21235 this, so we need not do it again. */
c19d1205 21236 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 21237 return base & ~3;
c19d1205
ZW
21238
21239 case BFD_RELOC_ARM_THUMB_OFFSET:
21240 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 21241 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 21242 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 21243 return (base + 4) & ~3;
c19d1205 21244
2fc8bdac
ZW
21245 /* Thumb branches are simply offset by +4. */
21246 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21247 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21248 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21249 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 21250 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 21251 return base + 4;
bfae80f2 21252
267bf995 21253 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
21254 if (fixP->fx_addsy
21255 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21256 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 21257 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
21258 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21259 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
21260 return base + 4;
21261
00adf2d4
JB
21262 /* BLX is like branches above, but forces the low two bits of PC to
21263 zero. */
486499d0
CL
21264 case BFD_RELOC_THUMB_PCREL_BLX:
21265 if (fixP->fx_addsy
21266 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21267 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21268 && THUMB_IS_FUNC (fixP->fx_addsy)
21269 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21270 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
21271 return (base + 4) & ~3;
21272
2fc8bdac
ZW
21273 /* ARM mode branches are offset by +8. However, the Windows CE
21274 loader expects the relocation not to take this into account. */
267bf995 21275 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
21276 if (fixP->fx_addsy
21277 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21278 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21279 && ARM_IS_FUNC (fixP->fx_addsy)
21280 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21281 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 21282 return base + 8;
267bf995 21283
486499d0
CL
21284 case BFD_RELOC_ARM_PCREL_CALL:
21285 if (fixP->fx_addsy
21286 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21287 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21288 && THUMB_IS_FUNC (fixP->fx_addsy)
21289 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21290 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 21291 return base + 8;
267bf995 21292
2fc8bdac 21293 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 21294 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 21295 case BFD_RELOC_ARM_PLT32:
c19d1205 21296#ifdef TE_WINCE
5f4273c7 21297 /* When handling fixups immediately, because we have already
477330fc 21298 discovered the value of a symbol, or the address of the frag involved
53baae48 21299 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
21300 see fixup_segment() in write.c
21301 The S_IS_EXTERNAL test handles the case of global symbols.
21302 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
21303 if (fixP->fx_pcrel
21304 && fixP->fx_addsy != NULL
21305 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21306 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
21307 return base + 8;
2fc8bdac 21308 return base;
c19d1205 21309#else
2fc8bdac 21310 return base + 8;
c19d1205 21311#endif
2fc8bdac 21312
267bf995 21313
2fc8bdac
ZW
21314 /* ARM mode loads relative to PC are also offset by +8. Unlike
21315 branches, the Windows CE loader *does* expect the relocation
21316 to take this into account. */
21317 case BFD_RELOC_ARM_OFFSET_IMM:
21318 case BFD_RELOC_ARM_OFFSET_IMM8:
21319 case BFD_RELOC_ARM_HWLITERAL:
21320 case BFD_RELOC_ARM_LITERAL:
21321 case BFD_RELOC_ARM_CP_OFF_IMM:
21322 return base + 8;
21323
21324
21325 /* Other PC-relative relocations are un-offset. */
21326 default:
21327 return base;
21328 }
bfae80f2
RE
21329}
21330
c19d1205
ZW
21331/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
21332 Otherwise we have no need to default values of symbols. */
21333
21334symbolS *
21335md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 21336{
c19d1205
ZW
21337#ifdef OBJ_ELF
21338 if (name[0] == '_' && name[1] == 'G'
21339 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
21340 {
21341 if (!GOT_symbol)
21342 {
21343 if (symbol_find (name))
bd3ba5d1 21344 as_bad (_("GOT already in the symbol table"));
bfae80f2 21345
c19d1205
ZW
21346 GOT_symbol = symbol_new (name, undefined_section,
21347 (valueT) 0, & zero_address_frag);
21348 }
bfae80f2 21349
c19d1205 21350 return GOT_symbol;
bfae80f2 21351 }
c19d1205 21352#endif
bfae80f2 21353
c921be7d 21354 return NULL;
bfae80f2
RE
21355}
21356
55cf6793 21357/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
21358 computed as two separate immediate values, added together. We
21359 already know that this value cannot be computed by just one ARM
21360 instruction. */
21361
21362static unsigned int
21363validate_immediate_twopart (unsigned int val,
21364 unsigned int * highpart)
bfae80f2 21365{
c19d1205
ZW
21366 unsigned int a;
21367 unsigned int i;
bfae80f2 21368
c19d1205
ZW
21369 for (i = 0; i < 32; i += 2)
21370 if (((a = rotate_left (val, i)) & 0xff) != 0)
21371 {
21372 if (a & 0xff00)
21373 {
21374 if (a & ~ 0xffff)
21375 continue;
21376 * highpart = (a >> 8) | ((i + 24) << 7);
21377 }
21378 else if (a & 0xff0000)
21379 {
21380 if (a & 0xff000000)
21381 continue;
21382 * highpart = (a >> 16) | ((i + 16) << 7);
21383 }
21384 else
21385 {
9c2799c2 21386 gas_assert (a & 0xff000000);
c19d1205
ZW
21387 * highpart = (a >> 24) | ((i + 8) << 7);
21388 }
bfae80f2 21389
c19d1205
ZW
21390 return (a & 0xff) | (i << 7);
21391 }
bfae80f2 21392
c19d1205 21393 return FAIL;
bfae80f2
RE
21394}
21395
c19d1205
ZW
21396static int
21397validate_offset_imm (unsigned int val, int hwse)
21398{
21399 if ((hwse && val > 255) || val > 4095)
21400 return FAIL;
21401 return val;
21402}
bfae80f2 21403
55cf6793 21404/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
21405 negative immediate constant by altering the instruction. A bit of
21406 a hack really.
21407 MOV <-> MVN
21408 AND <-> BIC
21409 ADC <-> SBC
21410 by inverting the second operand, and
21411 ADD <-> SUB
21412 CMP <-> CMN
21413 by negating the second operand. */
bfae80f2 21414
c19d1205
ZW
21415static int
21416negate_data_op (unsigned long * instruction,
21417 unsigned long value)
bfae80f2 21418{
c19d1205
ZW
21419 int op, new_inst;
21420 unsigned long negated, inverted;
bfae80f2 21421
c19d1205
ZW
21422 negated = encode_arm_immediate (-value);
21423 inverted = encode_arm_immediate (~value);
bfae80f2 21424
c19d1205
ZW
21425 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
21426 switch (op)
bfae80f2 21427 {
c19d1205
ZW
21428 /* First negates. */
21429 case OPCODE_SUB: /* ADD <-> SUB */
21430 new_inst = OPCODE_ADD;
21431 value = negated;
21432 break;
bfae80f2 21433
c19d1205
ZW
21434 case OPCODE_ADD:
21435 new_inst = OPCODE_SUB;
21436 value = negated;
21437 break;
bfae80f2 21438
c19d1205
ZW
21439 case OPCODE_CMP: /* CMP <-> CMN */
21440 new_inst = OPCODE_CMN;
21441 value = negated;
21442 break;
bfae80f2 21443
c19d1205
ZW
21444 case OPCODE_CMN:
21445 new_inst = OPCODE_CMP;
21446 value = negated;
21447 break;
bfae80f2 21448
c19d1205
ZW
21449 /* Now Inverted ops. */
21450 case OPCODE_MOV: /* MOV <-> MVN */
21451 new_inst = OPCODE_MVN;
21452 value = inverted;
21453 break;
bfae80f2 21454
c19d1205
ZW
21455 case OPCODE_MVN:
21456 new_inst = OPCODE_MOV;
21457 value = inverted;
21458 break;
bfae80f2 21459
c19d1205
ZW
21460 case OPCODE_AND: /* AND <-> BIC */
21461 new_inst = OPCODE_BIC;
21462 value = inverted;
21463 break;
bfae80f2 21464
c19d1205
ZW
21465 case OPCODE_BIC:
21466 new_inst = OPCODE_AND;
21467 value = inverted;
21468 break;
bfae80f2 21469
c19d1205
ZW
21470 case OPCODE_ADC: /* ADC <-> SBC */
21471 new_inst = OPCODE_SBC;
21472 value = inverted;
21473 break;
bfae80f2 21474
c19d1205
ZW
21475 case OPCODE_SBC:
21476 new_inst = OPCODE_ADC;
21477 value = inverted;
21478 break;
bfae80f2 21479
c19d1205
ZW
21480 /* We cannot do anything. */
21481 default:
21482 return FAIL;
b99bd4ef
NC
21483 }
21484
c19d1205
ZW
21485 if (value == (unsigned) FAIL)
21486 return FAIL;
21487
21488 *instruction &= OPCODE_MASK;
21489 *instruction |= new_inst << DATA_OP_SHIFT;
21490 return value;
b99bd4ef
NC
21491}
21492
ef8d22e6
PB
21493/* Like negate_data_op, but for Thumb-2. */
21494
21495static unsigned int
16dd5e42 21496thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
21497{
21498 int op, new_inst;
21499 int rd;
16dd5e42 21500 unsigned int negated, inverted;
ef8d22e6
PB
21501
21502 negated = encode_thumb32_immediate (-value);
21503 inverted = encode_thumb32_immediate (~value);
21504
21505 rd = (*instruction >> 8) & 0xf;
21506 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
21507 switch (op)
21508 {
21509 /* ADD <-> SUB. Includes CMP <-> CMN. */
21510 case T2_OPCODE_SUB:
21511 new_inst = T2_OPCODE_ADD;
21512 value = negated;
21513 break;
21514
21515 case T2_OPCODE_ADD:
21516 new_inst = T2_OPCODE_SUB;
21517 value = negated;
21518 break;
21519
21520 /* ORR <-> ORN. Includes MOV <-> MVN. */
21521 case T2_OPCODE_ORR:
21522 new_inst = T2_OPCODE_ORN;
21523 value = inverted;
21524 break;
21525
21526 case T2_OPCODE_ORN:
21527 new_inst = T2_OPCODE_ORR;
21528 value = inverted;
21529 break;
21530
21531 /* AND <-> BIC. TST has no inverted equivalent. */
21532 case T2_OPCODE_AND:
21533 new_inst = T2_OPCODE_BIC;
21534 if (rd == 15)
21535 value = FAIL;
21536 else
21537 value = inverted;
21538 break;
21539
21540 case T2_OPCODE_BIC:
21541 new_inst = T2_OPCODE_AND;
21542 value = inverted;
21543 break;
21544
21545 /* ADC <-> SBC */
21546 case T2_OPCODE_ADC:
21547 new_inst = T2_OPCODE_SBC;
21548 value = inverted;
21549 break;
21550
21551 case T2_OPCODE_SBC:
21552 new_inst = T2_OPCODE_ADC;
21553 value = inverted;
21554 break;
21555
21556 /* We cannot do anything. */
21557 default:
21558 return FAIL;
21559 }
21560
16dd5e42 21561 if (value == (unsigned int)FAIL)
ef8d22e6
PB
21562 return FAIL;
21563
21564 *instruction &= T2_OPCODE_MASK;
21565 *instruction |= new_inst << T2_DATA_OP_SHIFT;
21566 return value;
21567}
21568
8f06b2d8
PB
21569/* Read a 32-bit thumb instruction from buf. */
21570static unsigned long
21571get_thumb32_insn (char * buf)
21572{
21573 unsigned long insn;
21574 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
21575 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21576
21577 return insn;
21578}
21579
a8bc6c78
PB
21580
21581/* We usually want to set the low bit on the address of thumb function
21582 symbols. In particular .word foo - . should have the low bit set.
21583 Generic code tries to fold the difference of two symbols to
21584 a constant. Prevent this and force a relocation when the first symbols
21585 is a thumb function. */
c921be7d
NC
21586
21587bfd_boolean
a8bc6c78
PB
21588arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
21589{
21590 if (op == O_subtract
21591 && l->X_op == O_symbol
21592 && r->X_op == O_symbol
21593 && THUMB_IS_FUNC (l->X_add_symbol))
21594 {
21595 l->X_op = O_subtract;
21596 l->X_op_symbol = r->X_add_symbol;
21597 l->X_add_number -= r->X_add_number;
c921be7d 21598 return TRUE;
a8bc6c78 21599 }
c921be7d 21600
a8bc6c78 21601 /* Process as normal. */
c921be7d 21602 return FALSE;
a8bc6c78
PB
21603}
21604
4a42ebbc
RR
21605/* Encode Thumb2 unconditional branches and calls. The encoding
21606 for the 2 are identical for the immediate values. */
21607
21608static void
21609encode_thumb2_b_bl_offset (char * buf, offsetT value)
21610{
21611#define T2I1I2MASK ((1 << 13) | (1 << 11))
21612 offsetT newval;
21613 offsetT newval2;
21614 addressT S, I1, I2, lo, hi;
21615
21616 S = (value >> 24) & 0x01;
21617 I1 = (value >> 23) & 0x01;
21618 I2 = (value >> 22) & 0x01;
21619 hi = (value >> 12) & 0x3ff;
fa94de6b 21620 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
21621 newval = md_chars_to_number (buf, THUMB_SIZE);
21622 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21623 newval |= (S << 10) | hi;
21624 newval2 &= ~T2I1I2MASK;
21625 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
21626 md_number_to_chars (buf, newval, THUMB_SIZE);
21627 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
21628}
21629
c19d1205 21630void
55cf6793 21631md_apply_fix (fixS * fixP,
c19d1205
ZW
21632 valueT * valP,
21633 segT seg)
21634{
21635 offsetT value = * valP;
21636 offsetT newval;
21637 unsigned int newimm;
21638 unsigned long temp;
21639 int sign;
21640 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 21641
9c2799c2 21642 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 21643
c19d1205 21644 /* Note whether this will delete the relocation. */
4962c51a 21645
c19d1205
ZW
21646 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
21647 fixP->fx_done = 1;
b99bd4ef 21648
adbaf948 21649 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 21650 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
21651 for emit_reloc. */
21652 value &= 0xffffffff;
21653 value ^= 0x80000000;
5f4273c7 21654 value -= 0x80000000;
adbaf948
ZW
21655
21656 *valP = value;
c19d1205 21657 fixP->fx_addnumber = value;
b99bd4ef 21658
adbaf948
ZW
21659 /* Same treatment for fixP->fx_offset. */
21660 fixP->fx_offset &= 0xffffffff;
21661 fixP->fx_offset ^= 0x80000000;
21662 fixP->fx_offset -= 0x80000000;
21663
c19d1205 21664 switch (fixP->fx_r_type)
b99bd4ef 21665 {
c19d1205
ZW
21666 case BFD_RELOC_NONE:
21667 /* This will need to go in the object file. */
21668 fixP->fx_done = 0;
21669 break;
b99bd4ef 21670
c19d1205
ZW
21671 case BFD_RELOC_ARM_IMMEDIATE:
21672 /* We claim that this fixup has been processed here,
21673 even if in fact we generate an error because we do
21674 not have a reloc for it, so tc_gen_reloc will reject it. */
21675 fixP->fx_done = 1;
b99bd4ef 21676
77db8e2e 21677 if (fixP->fx_addsy)
b99bd4ef 21678 {
77db8e2e 21679 const char *msg = 0;
b99bd4ef 21680
77db8e2e
NC
21681 if (! S_IS_DEFINED (fixP->fx_addsy))
21682 msg = _("undefined symbol %s used as an immediate value");
21683 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
21684 msg = _("symbol %s is in a different section");
21685 else if (S_IS_WEAK (fixP->fx_addsy))
21686 msg = _("symbol %s is weak and may be overridden later");
21687
21688 if (msg)
21689 {
21690 as_bad_where (fixP->fx_file, fixP->fx_line,
21691 msg, S_GET_NAME (fixP->fx_addsy));
21692 break;
21693 }
42e5fcbf
AS
21694 }
21695
c19d1205
ZW
21696 temp = md_chars_to_number (buf, INSN_SIZE);
21697
5e73442d
SL
21698 /* If the offset is negative, we should use encoding A2 for ADR. */
21699 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
21700 newimm = negate_data_op (&temp, value);
21701 else
21702 {
21703 newimm = encode_arm_immediate (value);
21704
21705 /* If the instruction will fail, see if we can fix things up by
21706 changing the opcode. */
21707 if (newimm == (unsigned int) FAIL)
21708 newimm = negate_data_op (&temp, value);
21709 }
21710
21711 if (newimm == (unsigned int) FAIL)
b99bd4ef 21712 {
c19d1205
ZW
21713 as_bad_where (fixP->fx_file, fixP->fx_line,
21714 _("invalid constant (%lx) after fixup"),
21715 (unsigned long) value);
21716 break;
b99bd4ef 21717 }
b99bd4ef 21718
c19d1205
ZW
21719 newimm |= (temp & 0xfffff000);
21720 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
21721 break;
b99bd4ef 21722
c19d1205
ZW
21723 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21724 {
21725 unsigned int highpart = 0;
21726 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 21727
77db8e2e 21728 if (fixP->fx_addsy)
42e5fcbf 21729 {
77db8e2e 21730 const char *msg = 0;
42e5fcbf 21731
77db8e2e
NC
21732 if (! S_IS_DEFINED (fixP->fx_addsy))
21733 msg = _("undefined symbol %s used as an immediate value");
21734 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
21735 msg = _("symbol %s is in a different section");
21736 else if (S_IS_WEAK (fixP->fx_addsy))
21737 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 21738
77db8e2e
NC
21739 if (msg)
21740 {
21741 as_bad_where (fixP->fx_file, fixP->fx_line,
21742 msg, S_GET_NAME (fixP->fx_addsy));
21743 break;
21744 }
21745 }
fa94de6b 21746
c19d1205
ZW
21747 newimm = encode_arm_immediate (value);
21748 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 21749
c19d1205
ZW
21750 /* If the instruction will fail, see if we can fix things up by
21751 changing the opcode. */
21752 if (newimm == (unsigned int) FAIL
21753 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
21754 {
21755 /* No ? OK - try using two ADD instructions to generate
21756 the value. */
21757 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 21758
c19d1205
ZW
21759 /* Yes - then make sure that the second instruction is
21760 also an add. */
21761 if (newimm != (unsigned int) FAIL)
21762 newinsn = temp;
21763 /* Still No ? Try using a negated value. */
21764 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
21765 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
21766 /* Otherwise - give up. */
21767 else
21768 {
21769 as_bad_where (fixP->fx_file, fixP->fx_line,
21770 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
21771 (long) value);
21772 break;
21773 }
b99bd4ef 21774
c19d1205
ZW
21775 /* Replace the first operand in the 2nd instruction (which
21776 is the PC) with the destination register. We have
21777 already added in the PC in the first instruction and we
21778 do not want to do it again. */
21779 newinsn &= ~ 0xf0000;
21780 newinsn |= ((newinsn & 0x0f000) << 4);
21781 }
b99bd4ef 21782
c19d1205
ZW
21783 newimm |= (temp & 0xfffff000);
21784 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 21785
c19d1205
ZW
21786 highpart |= (newinsn & 0xfffff000);
21787 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
21788 }
21789 break;
b99bd4ef 21790
c19d1205 21791 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
21792 if (!fixP->fx_done && seg->use_rela_p)
21793 value = 0;
21794
c19d1205 21795 case BFD_RELOC_ARM_LITERAL:
26d97720 21796 sign = value > 0;
b99bd4ef 21797
c19d1205
ZW
21798 if (value < 0)
21799 value = - value;
b99bd4ef 21800
c19d1205 21801 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 21802 {
c19d1205
ZW
21803 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
21804 as_bad_where (fixP->fx_file, fixP->fx_line,
21805 _("invalid literal constant: pool needs to be closer"));
21806 else
21807 as_bad_where (fixP->fx_file, fixP->fx_line,
21808 _("bad immediate value for offset (%ld)"),
21809 (long) value);
21810 break;
f03698e6
RE
21811 }
21812
c19d1205 21813 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
21814 if (value == 0)
21815 newval &= 0xfffff000;
21816 else
21817 {
21818 newval &= 0xff7ff000;
21819 newval |= value | (sign ? INDEX_UP : 0);
21820 }
c19d1205
ZW
21821 md_number_to_chars (buf, newval, INSN_SIZE);
21822 break;
b99bd4ef 21823
c19d1205
ZW
21824 case BFD_RELOC_ARM_OFFSET_IMM8:
21825 case BFD_RELOC_ARM_HWLITERAL:
26d97720 21826 sign = value > 0;
b99bd4ef 21827
c19d1205
ZW
21828 if (value < 0)
21829 value = - value;
b99bd4ef 21830
c19d1205 21831 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 21832 {
c19d1205
ZW
21833 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
21834 as_bad_where (fixP->fx_file, fixP->fx_line,
21835 _("invalid literal constant: pool needs to be closer"));
21836 else
427d0db6
RM
21837 as_bad_where (fixP->fx_file, fixP->fx_line,
21838 _("bad immediate value for 8-bit offset (%ld)"),
21839 (long) value);
c19d1205 21840 break;
b99bd4ef
NC
21841 }
21842
c19d1205 21843 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
21844 if (value == 0)
21845 newval &= 0xfffff0f0;
21846 else
21847 {
21848 newval &= 0xff7ff0f0;
21849 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
21850 }
c19d1205
ZW
21851 md_number_to_chars (buf, newval, INSN_SIZE);
21852 break;
b99bd4ef 21853
c19d1205
ZW
21854 case BFD_RELOC_ARM_T32_OFFSET_U8:
21855 if (value < 0 || value > 1020 || value % 4 != 0)
21856 as_bad_where (fixP->fx_file, fixP->fx_line,
21857 _("bad immediate value for offset (%ld)"), (long) value);
21858 value /= 4;
b99bd4ef 21859
c19d1205 21860 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
21861 newval |= value;
21862 md_number_to_chars (buf+2, newval, THUMB_SIZE);
21863 break;
b99bd4ef 21864
c19d1205
ZW
21865 case BFD_RELOC_ARM_T32_OFFSET_IMM:
21866 /* This is a complicated relocation used for all varieties of Thumb32
21867 load/store instruction with immediate offset:
21868
21869 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 21870 *4, optional writeback(W)
c19d1205
ZW
21871 (doubleword load/store)
21872
21873 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
21874 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
21875 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
21876 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
21877 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
21878
21879 Uppercase letters indicate bits that are already encoded at
21880 this point. Lowercase letters are our problem. For the
21881 second block of instructions, the secondary opcode nybble
21882 (bits 8..11) is present, and bit 23 is zero, even if this is
21883 a PC-relative operation. */
21884 newval = md_chars_to_number (buf, THUMB_SIZE);
21885 newval <<= 16;
21886 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 21887
c19d1205 21888 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 21889 {
c19d1205
ZW
21890 /* Doubleword load/store: 8-bit offset, scaled by 4. */
21891 if (value >= 0)
21892 newval |= (1 << 23);
21893 else
21894 value = -value;
21895 if (value % 4 != 0)
21896 {
21897 as_bad_where (fixP->fx_file, fixP->fx_line,
21898 _("offset not a multiple of 4"));
21899 break;
21900 }
21901 value /= 4;
216d22bc 21902 if (value > 0xff)
c19d1205
ZW
21903 {
21904 as_bad_where (fixP->fx_file, fixP->fx_line,
21905 _("offset out of range"));
21906 break;
21907 }
21908 newval &= ~0xff;
b99bd4ef 21909 }
c19d1205 21910 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 21911 {
c19d1205
ZW
21912 /* PC-relative, 12-bit offset. */
21913 if (value >= 0)
21914 newval |= (1 << 23);
21915 else
21916 value = -value;
216d22bc 21917 if (value > 0xfff)
c19d1205
ZW
21918 {
21919 as_bad_where (fixP->fx_file, fixP->fx_line,
21920 _("offset out of range"));
21921 break;
21922 }
21923 newval &= ~0xfff;
b99bd4ef 21924 }
c19d1205 21925 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 21926 {
c19d1205
ZW
21927 /* Writeback: 8-bit, +/- offset. */
21928 if (value >= 0)
21929 newval |= (1 << 9);
21930 else
21931 value = -value;
216d22bc 21932 if (value > 0xff)
c19d1205
ZW
21933 {
21934 as_bad_where (fixP->fx_file, fixP->fx_line,
21935 _("offset out of range"));
21936 break;
21937 }
21938 newval &= ~0xff;
b99bd4ef 21939 }
c19d1205 21940 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 21941 {
c19d1205 21942 /* T-instruction: positive 8-bit offset. */
216d22bc 21943 if (value < 0 || value > 0xff)
b99bd4ef 21944 {
c19d1205
ZW
21945 as_bad_where (fixP->fx_file, fixP->fx_line,
21946 _("offset out of range"));
21947 break;
b99bd4ef 21948 }
c19d1205
ZW
21949 newval &= ~0xff;
21950 newval |= value;
b99bd4ef
NC
21951 }
21952 else
b99bd4ef 21953 {
c19d1205
ZW
21954 /* Positive 12-bit or negative 8-bit offset. */
21955 int limit;
21956 if (value >= 0)
b99bd4ef 21957 {
c19d1205
ZW
21958 newval |= (1 << 23);
21959 limit = 0xfff;
21960 }
21961 else
21962 {
21963 value = -value;
21964 limit = 0xff;
21965 }
21966 if (value > limit)
21967 {
21968 as_bad_where (fixP->fx_file, fixP->fx_line,
21969 _("offset out of range"));
21970 break;
b99bd4ef 21971 }
c19d1205 21972 newval &= ~limit;
b99bd4ef 21973 }
b99bd4ef 21974
c19d1205
ZW
21975 newval |= value;
21976 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
21977 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
21978 break;
404ff6b5 21979
c19d1205
ZW
21980 case BFD_RELOC_ARM_SHIFT_IMM:
21981 newval = md_chars_to_number (buf, INSN_SIZE);
21982 if (((unsigned long) value) > 32
21983 || (value == 32
21984 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
21985 {
21986 as_bad_where (fixP->fx_file, fixP->fx_line,
21987 _("shift expression is too large"));
21988 break;
21989 }
404ff6b5 21990
c19d1205
ZW
21991 if (value == 0)
21992 /* Shifts of zero must be done as lsl. */
21993 newval &= ~0x60;
21994 else if (value == 32)
21995 value = 0;
21996 newval &= 0xfffff07f;
21997 newval |= (value & 0x1f) << 7;
21998 md_number_to_chars (buf, newval, INSN_SIZE);
21999 break;
404ff6b5 22000
c19d1205 22001 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 22002 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 22003 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 22004 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
22005 /* We claim that this fixup has been processed here,
22006 even if in fact we generate an error because we do
22007 not have a reloc for it, so tc_gen_reloc will reject it. */
22008 fixP->fx_done = 1;
404ff6b5 22009
c19d1205
ZW
22010 if (fixP->fx_addsy
22011 && ! S_IS_DEFINED (fixP->fx_addsy))
22012 {
22013 as_bad_where (fixP->fx_file, fixP->fx_line,
22014 _("undefined symbol %s used as an immediate value"),
22015 S_GET_NAME (fixP->fx_addsy));
22016 break;
22017 }
404ff6b5 22018
c19d1205
ZW
22019 newval = md_chars_to_number (buf, THUMB_SIZE);
22020 newval <<= 16;
22021 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 22022
16805f35
PB
22023 newimm = FAIL;
22024 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22025 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
22026 {
22027 newimm = encode_thumb32_immediate (value);
22028 if (newimm == (unsigned int) FAIL)
22029 newimm = thumb32_negate_data_op (&newval, value);
22030 }
16805f35
PB
22031 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
22032 && newimm == (unsigned int) FAIL)
92e90b6e 22033 {
16805f35
PB
22034 /* Turn add/sum into addw/subw. */
22035 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
22036 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
22037 /* No flat 12-bit imm encoding for addsw/subsw. */
22038 if ((newval & 0x00100000) == 0)
e9f89963 22039 {
40f246e3
NC
22040 /* 12 bit immediate for addw/subw. */
22041 if (value < 0)
22042 {
22043 value = -value;
22044 newval ^= 0x00a00000;
22045 }
22046 if (value > 0xfff)
22047 newimm = (unsigned int) FAIL;
22048 else
22049 newimm = value;
e9f89963 22050 }
92e90b6e 22051 }
cc8a6dd0 22052
c19d1205 22053 if (newimm == (unsigned int)FAIL)
3631a3c8 22054 {
c19d1205
ZW
22055 as_bad_where (fixP->fx_file, fixP->fx_line,
22056 _("invalid constant (%lx) after fixup"),
22057 (unsigned long) value);
22058 break;
3631a3c8
NC
22059 }
22060
c19d1205
ZW
22061 newval |= (newimm & 0x800) << 15;
22062 newval |= (newimm & 0x700) << 4;
22063 newval |= (newimm & 0x0ff);
cc8a6dd0 22064
c19d1205
ZW
22065 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
22066 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
22067 break;
a737bd4d 22068
3eb17e6b 22069 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
22070 if (((unsigned long) value) > 0xffff)
22071 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 22072 _("invalid smc expression"));
2fc8bdac 22073 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
22074 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22075 md_number_to_chars (buf, newval, INSN_SIZE);
22076 break;
a737bd4d 22077
90ec0d68
MGD
22078 case BFD_RELOC_ARM_HVC:
22079 if (((unsigned long) value) > 0xffff)
22080 as_bad_where (fixP->fx_file, fixP->fx_line,
22081 _("invalid hvc expression"));
22082 newval = md_chars_to_number (buf, INSN_SIZE);
22083 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22084 md_number_to_chars (buf, newval, INSN_SIZE);
22085 break;
22086
c19d1205 22087 case BFD_RELOC_ARM_SWI:
adbaf948 22088 if (fixP->tc_fix_data != 0)
c19d1205
ZW
22089 {
22090 if (((unsigned long) value) > 0xff)
22091 as_bad_where (fixP->fx_file, fixP->fx_line,
22092 _("invalid swi expression"));
2fc8bdac 22093 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
22094 newval |= value;
22095 md_number_to_chars (buf, newval, THUMB_SIZE);
22096 }
22097 else
22098 {
22099 if (((unsigned long) value) > 0x00ffffff)
22100 as_bad_where (fixP->fx_file, fixP->fx_line,
22101 _("invalid swi expression"));
2fc8bdac 22102 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
22103 newval |= value;
22104 md_number_to_chars (buf, newval, INSN_SIZE);
22105 }
22106 break;
a737bd4d 22107
c19d1205
ZW
22108 case BFD_RELOC_ARM_MULTI:
22109 if (((unsigned long) value) > 0xffff)
22110 as_bad_where (fixP->fx_file, fixP->fx_line,
22111 _("invalid expression in load/store multiple"));
22112 newval = value | md_chars_to_number (buf, INSN_SIZE);
22113 md_number_to_chars (buf, newval, INSN_SIZE);
22114 break;
a737bd4d 22115
c19d1205 22116#ifdef OBJ_ELF
39b41c9c 22117 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
22118
22119 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22120 && fixP->fx_addsy
34e77a92 22121 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22122 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22123 && THUMB_IS_FUNC (fixP->fx_addsy))
22124 /* Flip the bl to blx. This is a simple flip
22125 bit here because we generate PCREL_CALL for
22126 unconditional bls. */
22127 {
22128 newval = md_chars_to_number (buf, INSN_SIZE);
22129 newval = newval | 0x10000000;
22130 md_number_to_chars (buf, newval, INSN_SIZE);
22131 temp = 1;
22132 fixP->fx_done = 1;
22133 }
39b41c9c
PB
22134 else
22135 temp = 3;
22136 goto arm_branch_common;
22137
22138 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
22139 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22140 && fixP->fx_addsy
34e77a92 22141 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22142 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22143 && THUMB_IS_FUNC (fixP->fx_addsy))
22144 {
22145 /* This would map to a bl<cond>, b<cond>,
22146 b<always> to a Thumb function. We
22147 need to force a relocation for this particular
22148 case. */
22149 newval = md_chars_to_number (buf, INSN_SIZE);
22150 fixP->fx_done = 0;
22151 }
22152
2fc8bdac 22153 case BFD_RELOC_ARM_PLT32:
c19d1205 22154#endif
39b41c9c
PB
22155 case BFD_RELOC_ARM_PCREL_BRANCH:
22156 temp = 3;
22157 goto arm_branch_common;
a737bd4d 22158
39b41c9c 22159 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 22160
39b41c9c 22161 temp = 1;
267bf995
RR
22162 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22163 && fixP->fx_addsy
34e77a92 22164 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22165 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22166 && ARM_IS_FUNC (fixP->fx_addsy))
22167 {
22168 /* Flip the blx to a bl and warn. */
22169 const char *name = S_GET_NAME (fixP->fx_addsy);
22170 newval = 0xeb000000;
22171 as_warn_where (fixP->fx_file, fixP->fx_line,
22172 _("blx to '%s' an ARM ISA state function changed to bl"),
22173 name);
22174 md_number_to_chars (buf, newval, INSN_SIZE);
22175 temp = 3;
22176 fixP->fx_done = 1;
22177 }
22178
22179#ifdef OBJ_ELF
22180 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 22181 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
22182#endif
22183
39b41c9c 22184 arm_branch_common:
c19d1205 22185 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
22186 instruction, in a 24 bit, signed field. Bits 26 through 32 either
22187 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
22188 also be be clear. */
22189 if (value & temp)
c19d1205 22190 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
22191 _("misaligned branch destination"));
22192 if ((value & (offsetT)0xfe000000) != (offsetT)0
22193 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 22194 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22195
2fc8bdac 22196 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 22197 {
2fc8bdac
ZW
22198 newval = md_chars_to_number (buf, INSN_SIZE);
22199 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
22200 /* Set the H bit on BLX instructions. */
22201 if (temp == 1)
22202 {
22203 if (value & 2)
22204 newval |= 0x01000000;
22205 else
22206 newval &= ~0x01000000;
22207 }
2fc8bdac 22208 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 22209 }
c19d1205 22210 break;
a737bd4d 22211
25fe350b
MS
22212 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
22213 /* CBZ can only branch forward. */
a737bd4d 22214
738755b0 22215 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
22216 (which, strictly speaking, are prohibited) will be turned into
22217 no-ops.
738755b0
MS
22218
22219 FIXME: It may be better to remove the instruction completely and
22220 perform relaxation. */
22221 if (value == -2)
2fc8bdac
ZW
22222 {
22223 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 22224 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
22225 md_number_to_chars (buf, newval, THUMB_SIZE);
22226 }
738755b0
MS
22227 else
22228 {
22229 if (value & ~0x7e)
08f10d51 22230 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 22231
477330fc 22232 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
22233 {
22234 newval = md_chars_to_number (buf, THUMB_SIZE);
22235 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
22236 md_number_to_chars (buf, newval, THUMB_SIZE);
22237 }
22238 }
c19d1205 22239 break;
a737bd4d 22240
c19d1205 22241 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 22242 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 22243 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22244
2fc8bdac
ZW
22245 if (fixP->fx_done || !seg->use_rela_p)
22246 {
22247 newval = md_chars_to_number (buf, THUMB_SIZE);
22248 newval |= (value & 0x1ff) >> 1;
22249 md_number_to_chars (buf, newval, THUMB_SIZE);
22250 }
c19d1205 22251 break;
a737bd4d 22252
c19d1205 22253 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 22254 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 22255 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22256
2fc8bdac
ZW
22257 if (fixP->fx_done || !seg->use_rela_p)
22258 {
22259 newval = md_chars_to_number (buf, THUMB_SIZE);
22260 newval |= (value & 0xfff) >> 1;
22261 md_number_to_chars (buf, newval, THUMB_SIZE);
22262 }
c19d1205 22263 break;
a737bd4d 22264
c19d1205 22265 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
22266 if (fixP->fx_addsy
22267 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22268 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22269 && ARM_IS_FUNC (fixP->fx_addsy)
22270 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22271 {
22272 /* Force a relocation for a branch 20 bits wide. */
22273 fixP->fx_done = 0;
22274 }
08f10d51 22275 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
22276 as_bad_where (fixP->fx_file, fixP->fx_line,
22277 _("conditional branch out of range"));
404ff6b5 22278
2fc8bdac
ZW
22279 if (fixP->fx_done || !seg->use_rela_p)
22280 {
22281 offsetT newval2;
22282 addressT S, J1, J2, lo, hi;
404ff6b5 22283
2fc8bdac
ZW
22284 S = (value & 0x00100000) >> 20;
22285 J2 = (value & 0x00080000) >> 19;
22286 J1 = (value & 0x00040000) >> 18;
22287 hi = (value & 0x0003f000) >> 12;
22288 lo = (value & 0x00000ffe) >> 1;
6c43fab6 22289
2fc8bdac
ZW
22290 newval = md_chars_to_number (buf, THUMB_SIZE);
22291 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22292 newval |= (S << 10) | hi;
22293 newval2 |= (J1 << 13) | (J2 << 11) | lo;
22294 md_number_to_chars (buf, newval, THUMB_SIZE);
22295 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22296 }
c19d1205 22297 break;
6c43fab6 22298
c19d1205 22299 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
22300 /* If there is a blx from a thumb state function to
22301 another thumb function flip this to a bl and warn
22302 about it. */
22303
22304 if (fixP->fx_addsy
34e77a92 22305 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22306 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22307 && THUMB_IS_FUNC (fixP->fx_addsy))
22308 {
22309 const char *name = S_GET_NAME (fixP->fx_addsy);
22310 as_warn_where (fixP->fx_file, fixP->fx_line,
22311 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
22312 name);
22313 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22314 newval = newval | 0x1000;
22315 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22316 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22317 fixP->fx_done = 1;
22318 }
22319
22320
22321 goto thumb_bl_common;
22322
c19d1205 22323 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
22324 /* A bl from Thumb state ISA to an internal ARM state function
22325 is converted to a blx. */
22326 if (fixP->fx_addsy
22327 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22328 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22329 && ARM_IS_FUNC (fixP->fx_addsy)
22330 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22331 {
22332 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22333 newval = newval & ~0x1000;
22334 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22335 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
22336 fixP->fx_done = 1;
22337 }
22338
22339 thumb_bl_common:
22340
2fc8bdac
ZW
22341 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22342 /* For a BLX instruction, make sure that the relocation is rounded up
22343 to a word boundary. This follows the semantics of the instruction
22344 which specifies that bit 1 of the target address will come from bit
22345 1 of the base address. */
d406f3e4
JB
22346 value = (value + 3) & ~ 3;
22347
22348#ifdef OBJ_ELF
22349 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
22350 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22351 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22352#endif
404ff6b5 22353
2b2f5df9
NC
22354 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
22355 {
22356 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
22357 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22358 else if ((value & ~0x1ffffff)
22359 && ((value & ~0x1ffffff) != ~0x1ffffff))
22360 as_bad_where (fixP->fx_file, fixP->fx_line,
22361 _("Thumb2 branch out of range"));
22362 }
4a42ebbc
RR
22363
22364 if (fixP->fx_done || !seg->use_rela_p)
22365 encode_thumb2_b_bl_offset (buf, value);
22366
c19d1205 22367 break;
404ff6b5 22368
c19d1205 22369 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
22370 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
22371 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 22372
2fc8bdac 22373 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 22374 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 22375
2fc8bdac 22376 break;
a737bd4d 22377
2fc8bdac
ZW
22378 case BFD_RELOC_8:
22379 if (fixP->fx_done || !seg->use_rela_p)
22380 md_number_to_chars (buf, value, 1);
c19d1205 22381 break;
a737bd4d 22382
c19d1205 22383 case BFD_RELOC_16:
2fc8bdac 22384 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 22385 md_number_to_chars (buf, value, 2);
c19d1205 22386 break;
a737bd4d 22387
c19d1205 22388#ifdef OBJ_ELF
0855e32b
NS
22389 case BFD_RELOC_ARM_TLS_CALL:
22390 case BFD_RELOC_ARM_THM_TLS_CALL:
22391 case BFD_RELOC_ARM_TLS_DESCSEQ:
22392 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
22393 S_SET_THREAD_LOCAL (fixP->fx_addsy);
22394 break;
22395
22396 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
22397 case BFD_RELOC_ARM_TLS_GD32:
22398 case BFD_RELOC_ARM_TLS_LE32:
22399 case BFD_RELOC_ARM_TLS_IE32:
22400 case BFD_RELOC_ARM_TLS_LDM32:
22401 case BFD_RELOC_ARM_TLS_LDO32:
22402 S_SET_THREAD_LOCAL (fixP->fx_addsy);
22403 /* fall through */
6c43fab6 22404
c19d1205
ZW
22405 case BFD_RELOC_ARM_GOT32:
22406 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
22407 if (fixP->fx_done || !seg->use_rela_p)
22408 md_number_to_chars (buf, 0, 4);
c19d1205 22409 break;
b43420e6
NC
22410
22411 case BFD_RELOC_ARM_GOT_PREL:
22412 if (fixP->fx_done || !seg->use_rela_p)
477330fc 22413 md_number_to_chars (buf, value, 4);
b43420e6
NC
22414 break;
22415
9a6f4e97
NS
22416 case BFD_RELOC_ARM_TARGET2:
22417 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
22418 addend here for REL targets, because it won't be written out
22419 during reloc processing later. */
9a6f4e97
NS
22420 if (fixP->fx_done || !seg->use_rela_p)
22421 md_number_to_chars (buf, fixP->fx_offset, 4);
22422 break;
c19d1205 22423#endif
6c43fab6 22424
c19d1205
ZW
22425 case BFD_RELOC_RVA:
22426 case BFD_RELOC_32:
22427 case BFD_RELOC_ARM_TARGET1:
22428 case BFD_RELOC_ARM_ROSEGREL32:
22429 case BFD_RELOC_ARM_SBREL32:
22430 case BFD_RELOC_32_PCREL:
f0927246
NC
22431#ifdef TE_PE
22432 case BFD_RELOC_32_SECREL:
22433#endif
2fc8bdac 22434 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
22435#ifdef TE_WINCE
22436 /* For WinCE we only do this for pcrel fixups. */
22437 if (fixP->fx_done || fixP->fx_pcrel)
22438#endif
22439 md_number_to_chars (buf, value, 4);
c19d1205 22440 break;
6c43fab6 22441
c19d1205
ZW
22442#ifdef OBJ_ELF
22443 case BFD_RELOC_ARM_PREL31:
2fc8bdac 22444 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
22445 {
22446 newval = md_chars_to_number (buf, 4) & 0x80000000;
22447 if ((value ^ (value >> 1)) & 0x40000000)
22448 {
22449 as_bad_where (fixP->fx_file, fixP->fx_line,
22450 _("rel31 relocation overflow"));
22451 }
22452 newval |= value & 0x7fffffff;
22453 md_number_to_chars (buf, newval, 4);
22454 }
22455 break;
c19d1205 22456#endif
a737bd4d 22457
c19d1205 22458 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 22459 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
22460 if (value < -1023 || value > 1023 || (value & 3))
22461 as_bad_where (fixP->fx_file, fixP->fx_line,
22462 _("co-processor offset out of range"));
22463 cp_off_common:
26d97720 22464 sign = value > 0;
c19d1205
ZW
22465 if (value < 0)
22466 value = -value;
8f06b2d8
PB
22467 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22468 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22469 newval = md_chars_to_number (buf, INSN_SIZE);
22470 else
22471 newval = get_thumb32_insn (buf);
26d97720
NS
22472 if (value == 0)
22473 newval &= 0xffffff00;
22474 else
22475 {
22476 newval &= 0xff7fff00;
22477 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
22478 }
8f06b2d8
PB
22479 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22480 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22481 md_number_to_chars (buf, newval, INSN_SIZE);
22482 else
22483 put_thumb32_insn (buf, newval);
c19d1205 22484 break;
a737bd4d 22485
c19d1205 22486 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 22487 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
22488 if (value < -255 || value > 255)
22489 as_bad_where (fixP->fx_file, fixP->fx_line,
22490 _("co-processor offset out of range"));
df7849c5 22491 value *= 4;
c19d1205 22492 goto cp_off_common;
6c43fab6 22493
c19d1205
ZW
22494 case BFD_RELOC_ARM_THUMB_OFFSET:
22495 newval = md_chars_to_number (buf, THUMB_SIZE);
22496 /* Exactly what ranges, and where the offset is inserted depends
22497 on the type of instruction, we can establish this from the
22498 top 4 bits. */
22499 switch (newval >> 12)
22500 {
22501 case 4: /* PC load. */
22502 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
22503 forced to zero for these loads; md_pcrel_from has already
22504 compensated for this. */
22505 if (value & 3)
22506 as_bad_where (fixP->fx_file, fixP->fx_line,
22507 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
22508 (((unsigned long) fixP->fx_frag->fr_address
22509 + (unsigned long) fixP->fx_where) & ~3)
22510 + (unsigned long) value);
a737bd4d 22511
c19d1205
ZW
22512 if (value & ~0x3fc)
22513 as_bad_where (fixP->fx_file, fixP->fx_line,
22514 _("invalid offset, value too big (0x%08lX)"),
22515 (long) value);
a737bd4d 22516
c19d1205
ZW
22517 newval |= value >> 2;
22518 break;
a737bd4d 22519
c19d1205
ZW
22520 case 9: /* SP load/store. */
22521 if (value & ~0x3fc)
22522 as_bad_where (fixP->fx_file, fixP->fx_line,
22523 _("invalid offset, value too big (0x%08lX)"),
22524 (long) value);
22525 newval |= value >> 2;
22526 break;
6c43fab6 22527
c19d1205
ZW
22528 case 6: /* Word load/store. */
22529 if (value & ~0x7c)
22530 as_bad_where (fixP->fx_file, fixP->fx_line,
22531 _("invalid offset, value too big (0x%08lX)"),
22532 (long) value);
22533 newval |= value << 4; /* 6 - 2. */
22534 break;
a737bd4d 22535
c19d1205
ZW
22536 case 7: /* Byte load/store. */
22537 if (value & ~0x1f)
22538 as_bad_where (fixP->fx_file, fixP->fx_line,
22539 _("invalid offset, value too big (0x%08lX)"),
22540 (long) value);
22541 newval |= value << 6;
22542 break;
a737bd4d 22543
c19d1205
ZW
22544 case 8: /* Halfword load/store. */
22545 if (value & ~0x3e)
22546 as_bad_where (fixP->fx_file, fixP->fx_line,
22547 _("invalid offset, value too big (0x%08lX)"),
22548 (long) value);
22549 newval |= value << 5; /* 6 - 1. */
22550 break;
a737bd4d 22551
c19d1205
ZW
22552 default:
22553 as_bad_where (fixP->fx_file, fixP->fx_line,
22554 "Unable to process relocation for thumb opcode: %lx",
22555 (unsigned long) newval);
22556 break;
22557 }
22558 md_number_to_chars (buf, newval, THUMB_SIZE);
22559 break;
a737bd4d 22560
c19d1205
ZW
22561 case BFD_RELOC_ARM_THUMB_ADD:
22562 /* This is a complicated relocation, since we use it for all of
22563 the following immediate relocations:
a737bd4d 22564
c19d1205
ZW
22565 3bit ADD/SUB
22566 8bit ADD/SUB
22567 9bit ADD/SUB SP word-aligned
22568 10bit ADD PC/SP word-aligned
a737bd4d 22569
c19d1205
ZW
22570 The type of instruction being processed is encoded in the
22571 instruction field:
a737bd4d 22572
c19d1205
ZW
22573 0x8000 SUB
22574 0x00F0 Rd
22575 0x000F Rs
22576 */
22577 newval = md_chars_to_number (buf, THUMB_SIZE);
22578 {
22579 int rd = (newval >> 4) & 0xf;
22580 int rs = newval & 0xf;
22581 int subtract = !!(newval & 0x8000);
a737bd4d 22582
c19d1205
ZW
22583 /* Check for HI regs, only very restricted cases allowed:
22584 Adjusting SP, and using PC or SP to get an address. */
22585 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
22586 || (rs > 7 && rs != REG_SP && rs != REG_PC))
22587 as_bad_where (fixP->fx_file, fixP->fx_line,
22588 _("invalid Hi register with immediate"));
a737bd4d 22589
c19d1205
ZW
22590 /* If value is negative, choose the opposite instruction. */
22591 if (value < 0)
22592 {
22593 value = -value;
22594 subtract = !subtract;
22595 if (value < 0)
22596 as_bad_where (fixP->fx_file, fixP->fx_line,
22597 _("immediate value out of range"));
22598 }
a737bd4d 22599
c19d1205
ZW
22600 if (rd == REG_SP)
22601 {
22602 if (value & ~0x1fc)
22603 as_bad_where (fixP->fx_file, fixP->fx_line,
22604 _("invalid immediate for stack address calculation"));
22605 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
22606 newval |= value >> 2;
22607 }
22608 else if (rs == REG_PC || rs == REG_SP)
22609 {
22610 if (subtract || value & ~0x3fc)
22611 as_bad_where (fixP->fx_file, fixP->fx_line,
22612 _("invalid immediate for address calculation (value = 0x%08lX)"),
22613 (unsigned long) value);
22614 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
22615 newval |= rd << 8;
22616 newval |= value >> 2;
22617 }
22618 else if (rs == rd)
22619 {
22620 if (value & ~0xff)
22621 as_bad_where (fixP->fx_file, fixP->fx_line,
22622 _("immediate value out of range"));
22623 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
22624 newval |= (rd << 8) | value;
22625 }
22626 else
22627 {
22628 if (value & ~0x7)
22629 as_bad_where (fixP->fx_file, fixP->fx_line,
22630 _("immediate value out of range"));
22631 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
22632 newval |= rd | (rs << 3) | (value << 6);
22633 }
22634 }
22635 md_number_to_chars (buf, newval, THUMB_SIZE);
22636 break;
a737bd4d 22637
c19d1205
ZW
22638 case BFD_RELOC_ARM_THUMB_IMM:
22639 newval = md_chars_to_number (buf, THUMB_SIZE);
22640 if (value < 0 || value > 255)
22641 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 22642 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
22643 (long) value);
22644 newval |= value;
22645 md_number_to_chars (buf, newval, THUMB_SIZE);
22646 break;
a737bd4d 22647
c19d1205
ZW
22648 case BFD_RELOC_ARM_THUMB_SHIFT:
22649 /* 5bit shift value (0..32). LSL cannot take 32. */
22650 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
22651 temp = newval & 0xf800;
22652 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
22653 as_bad_where (fixP->fx_file, fixP->fx_line,
22654 _("invalid shift value: %ld"), (long) value);
22655 /* Shifts of zero must be encoded as LSL. */
22656 if (value == 0)
22657 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
22658 /* Shifts of 32 are encoded as zero. */
22659 else if (value == 32)
22660 value = 0;
22661 newval |= value << 6;
22662 md_number_to_chars (buf, newval, THUMB_SIZE);
22663 break;
a737bd4d 22664
c19d1205
ZW
22665 case BFD_RELOC_VTABLE_INHERIT:
22666 case BFD_RELOC_VTABLE_ENTRY:
22667 fixP->fx_done = 0;
22668 return;
6c43fab6 22669
b6895b4f
PB
22670 case BFD_RELOC_ARM_MOVW:
22671 case BFD_RELOC_ARM_MOVT:
22672 case BFD_RELOC_ARM_THUMB_MOVW:
22673 case BFD_RELOC_ARM_THUMB_MOVT:
22674 if (fixP->fx_done || !seg->use_rela_p)
22675 {
22676 /* REL format relocations are limited to a 16-bit addend. */
22677 if (!fixP->fx_done)
22678 {
39623e12 22679 if (value < -0x8000 || value > 0x7fff)
b6895b4f 22680 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 22681 _("offset out of range"));
b6895b4f
PB
22682 }
22683 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
22684 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
22685 {
22686 value >>= 16;
22687 }
22688
22689 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
22690 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
22691 {
22692 newval = get_thumb32_insn (buf);
22693 newval &= 0xfbf08f00;
22694 newval |= (value & 0xf000) << 4;
22695 newval |= (value & 0x0800) << 15;
22696 newval |= (value & 0x0700) << 4;
22697 newval |= (value & 0x00ff);
22698 put_thumb32_insn (buf, newval);
22699 }
22700 else
22701 {
22702 newval = md_chars_to_number (buf, 4);
22703 newval &= 0xfff0f000;
22704 newval |= value & 0x0fff;
22705 newval |= (value & 0xf000) << 4;
22706 md_number_to_chars (buf, newval, 4);
22707 }
22708 }
22709 return;
22710
4962c51a
MS
22711 case BFD_RELOC_ARM_ALU_PC_G0_NC:
22712 case BFD_RELOC_ARM_ALU_PC_G0:
22713 case BFD_RELOC_ARM_ALU_PC_G1_NC:
22714 case BFD_RELOC_ARM_ALU_PC_G1:
22715 case BFD_RELOC_ARM_ALU_PC_G2:
22716 case BFD_RELOC_ARM_ALU_SB_G0_NC:
22717 case BFD_RELOC_ARM_ALU_SB_G0:
22718 case BFD_RELOC_ARM_ALU_SB_G1_NC:
22719 case BFD_RELOC_ARM_ALU_SB_G1:
22720 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 22721 gas_assert (!fixP->fx_done);
4962c51a
MS
22722 if (!seg->use_rela_p)
22723 {
477330fc
RM
22724 bfd_vma insn;
22725 bfd_vma encoded_addend;
22726 bfd_vma addend_abs = abs (value);
22727
22728 /* Check that the absolute value of the addend can be
22729 expressed as an 8-bit constant plus a rotation. */
22730 encoded_addend = encode_arm_immediate (addend_abs);
22731 if (encoded_addend == (unsigned int) FAIL)
4962c51a 22732 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
22733 _("the offset 0x%08lX is not representable"),
22734 (unsigned long) addend_abs);
22735
22736 /* Extract the instruction. */
22737 insn = md_chars_to_number (buf, INSN_SIZE);
22738
22739 /* If the addend is positive, use an ADD instruction.
22740 Otherwise use a SUB. Take care not to destroy the S bit. */
22741 insn &= 0xff1fffff;
22742 if (value < 0)
22743 insn |= 1 << 22;
22744 else
22745 insn |= 1 << 23;
22746
22747 /* Place the encoded addend into the first 12 bits of the
22748 instruction. */
22749 insn &= 0xfffff000;
22750 insn |= encoded_addend;
22751
22752 /* Update the instruction. */
22753 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
22754 }
22755 break;
22756
22757 case BFD_RELOC_ARM_LDR_PC_G0:
22758 case BFD_RELOC_ARM_LDR_PC_G1:
22759 case BFD_RELOC_ARM_LDR_PC_G2:
22760 case BFD_RELOC_ARM_LDR_SB_G0:
22761 case BFD_RELOC_ARM_LDR_SB_G1:
22762 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 22763 gas_assert (!fixP->fx_done);
4962c51a 22764 if (!seg->use_rela_p)
477330fc
RM
22765 {
22766 bfd_vma insn;
22767 bfd_vma addend_abs = abs (value);
4962c51a 22768
477330fc
RM
22769 /* Check that the absolute value of the addend can be
22770 encoded in 12 bits. */
22771 if (addend_abs >= 0x1000)
4962c51a 22772 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
22773 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
22774 (unsigned long) addend_abs);
22775
22776 /* Extract the instruction. */
22777 insn = md_chars_to_number (buf, INSN_SIZE);
22778
22779 /* If the addend is negative, clear bit 23 of the instruction.
22780 Otherwise set it. */
22781 if (value < 0)
22782 insn &= ~(1 << 23);
22783 else
22784 insn |= 1 << 23;
22785
22786 /* Place the absolute value of the addend into the first 12 bits
22787 of the instruction. */
22788 insn &= 0xfffff000;
22789 insn |= addend_abs;
22790
22791 /* Update the instruction. */
22792 md_number_to_chars (buf, insn, INSN_SIZE);
22793 }
4962c51a
MS
22794 break;
22795
22796 case BFD_RELOC_ARM_LDRS_PC_G0:
22797 case BFD_RELOC_ARM_LDRS_PC_G1:
22798 case BFD_RELOC_ARM_LDRS_PC_G2:
22799 case BFD_RELOC_ARM_LDRS_SB_G0:
22800 case BFD_RELOC_ARM_LDRS_SB_G1:
22801 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 22802 gas_assert (!fixP->fx_done);
4962c51a 22803 if (!seg->use_rela_p)
477330fc
RM
22804 {
22805 bfd_vma insn;
22806 bfd_vma addend_abs = abs (value);
4962c51a 22807
477330fc
RM
22808 /* Check that the absolute value of the addend can be
22809 encoded in 8 bits. */
22810 if (addend_abs >= 0x100)
4962c51a 22811 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
22812 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
22813 (unsigned long) addend_abs);
22814
22815 /* Extract the instruction. */
22816 insn = md_chars_to_number (buf, INSN_SIZE);
22817
22818 /* If the addend is negative, clear bit 23 of the instruction.
22819 Otherwise set it. */
22820 if (value < 0)
22821 insn &= ~(1 << 23);
22822 else
22823 insn |= 1 << 23;
22824
22825 /* Place the first four bits of the absolute value of the addend
22826 into the first 4 bits of the instruction, and the remaining
22827 four into bits 8 .. 11. */
22828 insn &= 0xfffff0f0;
22829 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
22830
22831 /* Update the instruction. */
22832 md_number_to_chars (buf, insn, INSN_SIZE);
22833 }
4962c51a
MS
22834 break;
22835
22836 case BFD_RELOC_ARM_LDC_PC_G0:
22837 case BFD_RELOC_ARM_LDC_PC_G1:
22838 case BFD_RELOC_ARM_LDC_PC_G2:
22839 case BFD_RELOC_ARM_LDC_SB_G0:
22840 case BFD_RELOC_ARM_LDC_SB_G1:
22841 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 22842 gas_assert (!fixP->fx_done);
4962c51a 22843 if (!seg->use_rela_p)
477330fc
RM
22844 {
22845 bfd_vma insn;
22846 bfd_vma addend_abs = abs (value);
4962c51a 22847
477330fc
RM
22848 /* Check that the absolute value of the addend is a multiple of
22849 four and, when divided by four, fits in 8 bits. */
22850 if (addend_abs & 0x3)
4962c51a 22851 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
22852 _("bad offset 0x%08lX (must be word-aligned)"),
22853 (unsigned long) addend_abs);
4962c51a 22854
477330fc 22855 if ((addend_abs >> 2) > 0xff)
4962c51a 22856 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
22857 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
22858 (unsigned long) addend_abs);
22859
22860 /* Extract the instruction. */
22861 insn = md_chars_to_number (buf, INSN_SIZE);
22862
22863 /* If the addend is negative, clear bit 23 of the instruction.
22864 Otherwise set it. */
22865 if (value < 0)
22866 insn &= ~(1 << 23);
22867 else
22868 insn |= 1 << 23;
22869
22870 /* Place the addend (divided by four) into the first eight
22871 bits of the instruction. */
22872 insn &= 0xfffffff0;
22873 insn |= addend_abs >> 2;
22874
22875 /* Update the instruction. */
22876 md_number_to_chars (buf, insn, INSN_SIZE);
22877 }
4962c51a
MS
22878 break;
22879
845b51d6
PB
22880 case BFD_RELOC_ARM_V4BX:
22881 /* This will need to go in the object file. */
22882 fixP->fx_done = 0;
22883 break;
22884
c19d1205
ZW
22885 case BFD_RELOC_UNUSED:
22886 default:
22887 as_bad_where (fixP->fx_file, fixP->fx_line,
22888 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
22889 }
6c43fab6
RE
22890}
22891
c19d1205
ZW
22892/* Translate internal representation of relocation info to BFD target
22893 format. */
a737bd4d 22894
c19d1205 22895arelent *
00a97672 22896tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 22897{
c19d1205
ZW
22898 arelent * reloc;
22899 bfd_reloc_code_real_type code;
a737bd4d 22900
21d799b5 22901 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 22902
21d799b5 22903 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
22904 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
22905 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 22906
2fc8bdac 22907 if (fixp->fx_pcrel)
00a97672
RS
22908 {
22909 if (section->use_rela_p)
22910 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
22911 else
22912 fixp->fx_offset = reloc->address;
22913 }
c19d1205 22914 reloc->addend = fixp->fx_offset;
a737bd4d 22915
c19d1205 22916 switch (fixp->fx_r_type)
a737bd4d 22917 {
c19d1205
ZW
22918 case BFD_RELOC_8:
22919 if (fixp->fx_pcrel)
22920 {
22921 code = BFD_RELOC_8_PCREL;
22922 break;
22923 }
a737bd4d 22924
c19d1205
ZW
22925 case BFD_RELOC_16:
22926 if (fixp->fx_pcrel)
22927 {
22928 code = BFD_RELOC_16_PCREL;
22929 break;
22930 }
6c43fab6 22931
c19d1205
ZW
22932 case BFD_RELOC_32:
22933 if (fixp->fx_pcrel)
22934 {
22935 code = BFD_RELOC_32_PCREL;
22936 break;
22937 }
a737bd4d 22938
b6895b4f
PB
22939 case BFD_RELOC_ARM_MOVW:
22940 if (fixp->fx_pcrel)
22941 {
22942 code = BFD_RELOC_ARM_MOVW_PCREL;
22943 break;
22944 }
22945
22946 case BFD_RELOC_ARM_MOVT:
22947 if (fixp->fx_pcrel)
22948 {
22949 code = BFD_RELOC_ARM_MOVT_PCREL;
22950 break;
22951 }
22952
22953 case BFD_RELOC_ARM_THUMB_MOVW:
22954 if (fixp->fx_pcrel)
22955 {
22956 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
22957 break;
22958 }
22959
22960 case BFD_RELOC_ARM_THUMB_MOVT:
22961 if (fixp->fx_pcrel)
22962 {
22963 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
22964 break;
22965 }
22966
c19d1205
ZW
22967 case BFD_RELOC_NONE:
22968 case BFD_RELOC_ARM_PCREL_BRANCH:
22969 case BFD_RELOC_ARM_PCREL_BLX:
22970 case BFD_RELOC_RVA:
22971 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22972 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22973 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22974 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22975 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22976 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
22977 case BFD_RELOC_VTABLE_ENTRY:
22978 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
22979#ifdef TE_PE
22980 case BFD_RELOC_32_SECREL:
22981#endif
c19d1205
ZW
22982 code = fixp->fx_r_type;
22983 break;
a737bd4d 22984
00adf2d4
JB
22985 case BFD_RELOC_THUMB_PCREL_BLX:
22986#ifdef OBJ_ELF
22987 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
22988 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
22989 else
22990#endif
22991 code = BFD_RELOC_THUMB_PCREL_BLX;
22992 break;
22993
c19d1205
ZW
22994 case BFD_RELOC_ARM_LITERAL:
22995 case BFD_RELOC_ARM_HWLITERAL:
22996 /* If this is called then the a literal has
22997 been referenced across a section boundary. */
22998 as_bad_where (fixp->fx_file, fixp->fx_line,
22999 _("literal referenced across section boundary"));
23000 return NULL;
a737bd4d 23001
c19d1205 23002#ifdef OBJ_ELF
0855e32b
NS
23003 case BFD_RELOC_ARM_TLS_CALL:
23004 case BFD_RELOC_ARM_THM_TLS_CALL:
23005 case BFD_RELOC_ARM_TLS_DESCSEQ:
23006 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
23007 case BFD_RELOC_ARM_GOT32:
23008 case BFD_RELOC_ARM_GOTOFF:
b43420e6 23009 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
23010 case BFD_RELOC_ARM_PLT32:
23011 case BFD_RELOC_ARM_TARGET1:
23012 case BFD_RELOC_ARM_ROSEGREL32:
23013 case BFD_RELOC_ARM_SBREL32:
23014 case BFD_RELOC_ARM_PREL31:
23015 case BFD_RELOC_ARM_TARGET2:
23016 case BFD_RELOC_ARM_TLS_LE32:
23017 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
23018 case BFD_RELOC_ARM_PCREL_CALL:
23019 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
23020 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23021 case BFD_RELOC_ARM_ALU_PC_G0:
23022 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23023 case BFD_RELOC_ARM_ALU_PC_G1:
23024 case BFD_RELOC_ARM_ALU_PC_G2:
23025 case BFD_RELOC_ARM_LDR_PC_G0:
23026 case BFD_RELOC_ARM_LDR_PC_G1:
23027 case BFD_RELOC_ARM_LDR_PC_G2:
23028 case BFD_RELOC_ARM_LDRS_PC_G0:
23029 case BFD_RELOC_ARM_LDRS_PC_G1:
23030 case BFD_RELOC_ARM_LDRS_PC_G2:
23031 case BFD_RELOC_ARM_LDC_PC_G0:
23032 case BFD_RELOC_ARM_LDC_PC_G1:
23033 case BFD_RELOC_ARM_LDC_PC_G2:
23034 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23035 case BFD_RELOC_ARM_ALU_SB_G0:
23036 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23037 case BFD_RELOC_ARM_ALU_SB_G1:
23038 case BFD_RELOC_ARM_ALU_SB_G2:
23039 case BFD_RELOC_ARM_LDR_SB_G0:
23040 case BFD_RELOC_ARM_LDR_SB_G1:
23041 case BFD_RELOC_ARM_LDR_SB_G2:
23042 case BFD_RELOC_ARM_LDRS_SB_G0:
23043 case BFD_RELOC_ARM_LDRS_SB_G1:
23044 case BFD_RELOC_ARM_LDRS_SB_G2:
23045 case BFD_RELOC_ARM_LDC_SB_G0:
23046 case BFD_RELOC_ARM_LDC_SB_G1:
23047 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 23048 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
23049 code = fixp->fx_r_type;
23050 break;
a737bd4d 23051
0855e32b 23052 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23053 case BFD_RELOC_ARM_TLS_GD32:
23054 case BFD_RELOC_ARM_TLS_IE32:
23055 case BFD_RELOC_ARM_TLS_LDM32:
23056 /* BFD will include the symbol's address in the addend.
23057 But we don't want that, so subtract it out again here. */
23058 if (!S_IS_COMMON (fixp->fx_addsy))
23059 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
23060 code = fixp->fx_r_type;
23061 break;
23062#endif
a737bd4d 23063
c19d1205
ZW
23064 case BFD_RELOC_ARM_IMMEDIATE:
23065 as_bad_where (fixp->fx_file, fixp->fx_line,
23066 _("internal relocation (type: IMMEDIATE) not fixed up"));
23067 return NULL;
a737bd4d 23068
c19d1205
ZW
23069 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23070 as_bad_where (fixp->fx_file, fixp->fx_line,
23071 _("ADRL used for a symbol not defined in the same file"));
23072 return NULL;
a737bd4d 23073
c19d1205 23074 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23075 if (section->use_rela_p)
23076 {
23077 code = fixp->fx_r_type;
23078 break;
23079 }
23080
c19d1205
ZW
23081 if (fixp->fx_addsy != NULL
23082 && !S_IS_DEFINED (fixp->fx_addsy)
23083 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 23084 {
c19d1205
ZW
23085 as_bad_where (fixp->fx_file, fixp->fx_line,
23086 _("undefined local label `%s'"),
23087 S_GET_NAME (fixp->fx_addsy));
23088 return NULL;
a737bd4d
NC
23089 }
23090
c19d1205
ZW
23091 as_bad_where (fixp->fx_file, fixp->fx_line,
23092 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
23093 return NULL;
a737bd4d 23094
c19d1205
ZW
23095 default:
23096 {
23097 char * type;
6c43fab6 23098
c19d1205
ZW
23099 switch (fixp->fx_r_type)
23100 {
23101 case BFD_RELOC_NONE: type = "NONE"; break;
23102 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
23103 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 23104 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
23105 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
23106 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
23107 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 23108 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 23109 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
23110 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
23111 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
23112 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
23113 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
23114 default: type = _("<unknown>"); break;
23115 }
23116 as_bad_where (fixp->fx_file, fixp->fx_line,
23117 _("cannot represent %s relocation in this object file format"),
23118 type);
23119 return NULL;
23120 }
a737bd4d 23121 }
6c43fab6 23122
c19d1205
ZW
23123#ifdef OBJ_ELF
23124 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
23125 && GOT_symbol
23126 && fixp->fx_addsy == GOT_symbol)
23127 {
23128 code = BFD_RELOC_ARM_GOTPC;
23129 reloc->addend = fixp->fx_offset = reloc->address;
23130 }
23131#endif
6c43fab6 23132
c19d1205 23133 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 23134
c19d1205
ZW
23135 if (reloc->howto == NULL)
23136 {
23137 as_bad_where (fixp->fx_file, fixp->fx_line,
23138 _("cannot represent %s relocation in this object file format"),
23139 bfd_get_reloc_code_name (code));
23140 return NULL;
23141 }
6c43fab6 23142
c19d1205
ZW
23143 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
23144 vtable entry to be used in the relocation's section offset. */
23145 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
23146 reloc->address = fixp->fx_offset;
6c43fab6 23147
c19d1205 23148 return reloc;
6c43fab6
RE
23149}
23150
c19d1205 23151/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 23152
c19d1205
ZW
23153void
23154cons_fix_new_arm (fragS * frag,
23155 int where,
23156 int size,
23157 expressionS * exp)
6c43fab6 23158{
c19d1205
ZW
23159 bfd_reloc_code_real_type type;
23160 int pcrel = 0;
6c43fab6 23161
c19d1205
ZW
23162 /* Pick a reloc.
23163 FIXME: @@ Should look at CPU word size. */
23164 switch (size)
23165 {
23166 case 1:
23167 type = BFD_RELOC_8;
23168 break;
23169 case 2:
23170 type = BFD_RELOC_16;
23171 break;
23172 case 4:
23173 default:
23174 type = BFD_RELOC_32;
23175 break;
23176 case 8:
23177 type = BFD_RELOC_64;
23178 break;
23179 }
6c43fab6 23180
f0927246
NC
23181#ifdef TE_PE
23182 if (exp->X_op == O_secrel)
23183 {
23184 exp->X_op = O_symbol;
23185 type = BFD_RELOC_32_SECREL;
23186 }
23187#endif
23188
c19d1205
ZW
23189 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
23190}
6c43fab6 23191
4343666d 23192#if defined (OBJ_COFF)
c19d1205
ZW
23193void
23194arm_validate_fix (fixS * fixP)
6c43fab6 23195{
c19d1205
ZW
23196 /* If the destination of the branch is a defined symbol which does not have
23197 the THUMB_FUNC attribute, then we must be calling a function which has
23198 the (interfacearm) attribute. We look for the Thumb entry point to that
23199 function and change the branch to refer to that function instead. */
23200 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
23201 && fixP->fx_addsy != NULL
23202 && S_IS_DEFINED (fixP->fx_addsy)
23203 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 23204 {
c19d1205 23205 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 23206 }
c19d1205
ZW
23207}
23208#endif
6c43fab6 23209
267bf995 23210
c19d1205
ZW
23211int
23212arm_force_relocation (struct fix * fixp)
23213{
23214#if defined (OBJ_COFF) && defined (TE_PE)
23215 if (fixp->fx_r_type == BFD_RELOC_RVA)
23216 return 1;
23217#endif
6c43fab6 23218
267bf995
RR
23219 /* In case we have a call or a branch to a function in ARM ISA mode from
23220 a thumb function or vice-versa force the relocation. These relocations
23221 are cleared off for some cores that might have blx and simple transformations
23222 are possible. */
23223
23224#ifdef OBJ_ELF
23225 switch (fixp->fx_r_type)
23226 {
23227 case BFD_RELOC_ARM_PCREL_JUMP:
23228 case BFD_RELOC_ARM_PCREL_CALL:
23229 case BFD_RELOC_THUMB_PCREL_BLX:
23230 if (THUMB_IS_FUNC (fixp->fx_addsy))
23231 return 1;
23232 break;
23233
23234 case BFD_RELOC_ARM_PCREL_BLX:
23235 case BFD_RELOC_THUMB_PCREL_BRANCH25:
23236 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23237 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23238 if (ARM_IS_FUNC (fixp->fx_addsy))
23239 return 1;
23240 break;
23241
23242 default:
23243 break;
23244 }
23245#endif
23246
b5884301
PB
23247 /* Resolve these relocations even if the symbol is extern or weak.
23248 Technically this is probably wrong due to symbol preemption.
23249 In practice these relocations do not have enough range to be useful
23250 at dynamic link time, and some code (e.g. in the Linux kernel)
23251 expects these references to be resolved. */
c19d1205
ZW
23252 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
23253 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 23254 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 23255 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
23256 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23257 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
23258 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 23259 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
23260 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23261 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
23262 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
23263 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
23264 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
23265 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 23266 return 0;
a737bd4d 23267
4962c51a
MS
23268 /* Always leave these relocations for the linker. */
23269 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
23270 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
23271 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
23272 return 1;
23273
f0291e4c
PB
23274 /* Always generate relocations against function symbols. */
23275 if (fixp->fx_r_type == BFD_RELOC_32
23276 && fixp->fx_addsy
23277 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
23278 return 1;
23279
c19d1205 23280 return generic_force_reloc (fixp);
404ff6b5
AH
23281}
23282
0ffdc86c 23283#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
23284/* Relocations against function names must be left unadjusted,
23285 so that the linker can use this information to generate interworking
23286 stubs. The MIPS version of this function
c19d1205
ZW
23287 also prevents relocations that are mips-16 specific, but I do not
23288 know why it does this.
404ff6b5 23289
c19d1205
ZW
23290 FIXME:
23291 There is one other problem that ought to be addressed here, but
23292 which currently is not: Taking the address of a label (rather
23293 than a function) and then later jumping to that address. Such
23294 addresses also ought to have their bottom bit set (assuming that
23295 they reside in Thumb code), but at the moment they will not. */
404ff6b5 23296
c19d1205
ZW
23297bfd_boolean
23298arm_fix_adjustable (fixS * fixP)
404ff6b5 23299{
c19d1205
ZW
23300 if (fixP->fx_addsy == NULL)
23301 return 1;
404ff6b5 23302
e28387c3
PB
23303 /* Preserve relocations against symbols with function type. */
23304 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 23305 return FALSE;
e28387c3 23306
c19d1205
ZW
23307 if (THUMB_IS_FUNC (fixP->fx_addsy)
23308 && fixP->fx_subsy == NULL)
c921be7d 23309 return FALSE;
a737bd4d 23310
c19d1205
ZW
23311 /* We need the symbol name for the VTABLE entries. */
23312 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
23313 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 23314 return FALSE;
404ff6b5 23315
c19d1205
ZW
23316 /* Don't allow symbols to be discarded on GOT related relocs. */
23317 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
23318 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
23319 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
23320 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
23321 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
23322 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
23323 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
23324 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
23325 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
23326 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
23327 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
23328 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
23329 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 23330 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 23331 return FALSE;
a737bd4d 23332
4962c51a
MS
23333 /* Similarly for group relocations. */
23334 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
23335 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
23336 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 23337 return FALSE;
4962c51a 23338
79947c54
CD
23339 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
23340 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
23341 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23342 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
23343 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
23344 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23345 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
23346 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
23347 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 23348 return FALSE;
79947c54 23349
c921be7d 23350 return TRUE;
a737bd4d 23351}
0ffdc86c
NC
23352#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
23353
23354#ifdef OBJ_ELF
404ff6b5 23355
c19d1205
ZW
23356const char *
23357elf32_arm_target_format (void)
404ff6b5 23358{
c19d1205
ZW
23359#ifdef TE_SYMBIAN
23360 return (target_big_endian
23361 ? "elf32-bigarm-symbian"
23362 : "elf32-littlearm-symbian");
23363#elif defined (TE_VXWORKS)
23364 return (target_big_endian
23365 ? "elf32-bigarm-vxworks"
23366 : "elf32-littlearm-vxworks");
b38cadfb
NC
23367#elif defined (TE_NACL)
23368 return (target_big_endian
23369 ? "elf32-bigarm-nacl"
23370 : "elf32-littlearm-nacl");
c19d1205
ZW
23371#else
23372 if (target_big_endian)
23373 return "elf32-bigarm";
23374 else
23375 return "elf32-littlearm";
23376#endif
404ff6b5
AH
23377}
23378
c19d1205
ZW
23379void
23380armelf_frob_symbol (symbolS * symp,
23381 int * puntp)
404ff6b5 23382{
c19d1205
ZW
23383 elf_frob_symbol (symp, puntp);
23384}
23385#endif
404ff6b5 23386
c19d1205 23387/* MD interface: Finalization. */
a737bd4d 23388
c19d1205
ZW
23389void
23390arm_cleanup (void)
23391{
23392 literal_pool * pool;
a737bd4d 23393
e07e6e58
NC
23394 /* Ensure that all the IT blocks are properly closed. */
23395 check_it_blocks_finished ();
23396
c19d1205
ZW
23397 for (pool = list_of_pools; pool; pool = pool->next)
23398 {
5f4273c7 23399 /* Put it at the end of the relevant section. */
c19d1205
ZW
23400 subseg_set (pool->section, pool->sub_section);
23401#ifdef OBJ_ELF
23402 arm_elf_change_section ();
23403#endif
23404 s_ltorg (0);
23405 }
404ff6b5
AH
23406}
23407
cd000bff
DJ
23408#ifdef OBJ_ELF
23409/* Remove any excess mapping symbols generated for alignment frags in
23410 SEC. We may have created a mapping symbol before a zero byte
23411 alignment; remove it if there's a mapping symbol after the
23412 alignment. */
23413static void
23414check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
23415 void *dummy ATTRIBUTE_UNUSED)
23416{
23417 segment_info_type *seginfo = seg_info (sec);
23418 fragS *fragp;
23419
23420 if (seginfo == NULL || seginfo->frchainP == NULL)
23421 return;
23422
23423 for (fragp = seginfo->frchainP->frch_root;
23424 fragp != NULL;
23425 fragp = fragp->fr_next)
23426 {
23427 symbolS *sym = fragp->tc_frag_data.last_map;
23428 fragS *next = fragp->fr_next;
23429
23430 /* Variable-sized frags have been converted to fixed size by
23431 this point. But if this was variable-sized to start with,
23432 there will be a fixed-size frag after it. So don't handle
23433 next == NULL. */
23434 if (sym == NULL || next == NULL)
23435 continue;
23436
23437 if (S_GET_VALUE (sym) < next->fr_address)
23438 /* Not at the end of this frag. */
23439 continue;
23440 know (S_GET_VALUE (sym) == next->fr_address);
23441
23442 do
23443 {
23444 if (next->tc_frag_data.first_map != NULL)
23445 {
23446 /* Next frag starts with a mapping symbol. Discard this
23447 one. */
23448 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23449 break;
23450 }
23451
23452 if (next->fr_next == NULL)
23453 {
23454 /* This mapping symbol is at the end of the section. Discard
23455 it. */
23456 know (next->fr_fix == 0 && next->fr_var == 0);
23457 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23458 break;
23459 }
23460
23461 /* As long as we have empty frags without any mapping symbols,
23462 keep looking. */
23463 /* If the next frag is non-empty and does not start with a
23464 mapping symbol, then this mapping symbol is required. */
23465 if (next->fr_address != next->fr_next->fr_address)
23466 break;
23467
23468 next = next->fr_next;
23469 }
23470 while (next != NULL);
23471 }
23472}
23473#endif
23474
c19d1205
ZW
23475/* Adjust the symbol table. This marks Thumb symbols as distinct from
23476 ARM ones. */
404ff6b5 23477
c19d1205
ZW
23478void
23479arm_adjust_symtab (void)
404ff6b5 23480{
c19d1205
ZW
23481#ifdef OBJ_COFF
23482 symbolS * sym;
404ff6b5 23483
c19d1205
ZW
23484 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
23485 {
23486 if (ARM_IS_THUMB (sym))
23487 {
23488 if (THUMB_IS_FUNC (sym))
23489 {
23490 /* Mark the symbol as a Thumb function. */
23491 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
23492 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
23493 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 23494
c19d1205
ZW
23495 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
23496 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
23497 else
23498 as_bad (_("%s: unexpected function type: %d"),
23499 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
23500 }
23501 else switch (S_GET_STORAGE_CLASS (sym))
23502 {
23503 case C_EXT:
23504 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
23505 break;
23506 case C_STAT:
23507 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
23508 break;
23509 case C_LABEL:
23510 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
23511 break;
23512 default:
23513 /* Do nothing. */
23514 break;
23515 }
23516 }
a737bd4d 23517
c19d1205
ZW
23518 if (ARM_IS_INTERWORK (sym))
23519 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 23520 }
c19d1205
ZW
23521#endif
23522#ifdef OBJ_ELF
23523 symbolS * sym;
23524 char bind;
404ff6b5 23525
c19d1205 23526 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 23527 {
c19d1205
ZW
23528 if (ARM_IS_THUMB (sym))
23529 {
23530 elf_symbol_type * elf_sym;
404ff6b5 23531
c19d1205
ZW
23532 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
23533 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 23534
b0796911
PB
23535 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
23536 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
23537 {
23538 /* If it's a .thumb_func, declare it as so,
23539 otherwise tag label as .code 16. */
23540 if (THUMB_IS_FUNC (sym))
35fc36a8
RS
23541 elf_sym->internal_elf_sym.st_target_internal
23542 = ST_BRANCH_TO_THUMB;
3ba67470 23543 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
23544 elf_sym->internal_elf_sym.st_info =
23545 ELF_ST_INFO (bind, STT_ARM_16BIT);
23546 }
23547 }
23548 }
cd000bff
DJ
23549
23550 /* Remove any overlapping mapping symbols generated by alignment frags. */
23551 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
23552 /* Now do generic ELF adjustments. */
23553 elf_adjust_symtab ();
c19d1205 23554#endif
404ff6b5
AH
23555}
23556
c19d1205 23557/* MD interface: Initialization. */
404ff6b5 23558
a737bd4d 23559static void
c19d1205 23560set_constant_flonums (void)
a737bd4d 23561{
c19d1205 23562 int i;
404ff6b5 23563
c19d1205
ZW
23564 for (i = 0; i < NUM_FLOAT_VALS; i++)
23565 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
23566 abort ();
a737bd4d 23567}
404ff6b5 23568
3e9e4fcf
JB
23569/* Auto-select Thumb mode if it's the only available instruction set for the
23570 given architecture. */
23571
23572static void
23573autoselect_thumb_from_cpu_variant (void)
23574{
23575 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
23576 opcode_select (16);
23577}
23578
c19d1205
ZW
23579void
23580md_begin (void)
a737bd4d 23581{
c19d1205
ZW
23582 unsigned mach;
23583 unsigned int i;
404ff6b5 23584
c19d1205
ZW
23585 if ( (arm_ops_hsh = hash_new ()) == NULL
23586 || (arm_cond_hsh = hash_new ()) == NULL
23587 || (arm_shift_hsh = hash_new ()) == NULL
23588 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 23589 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 23590 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
23591 || (arm_reloc_hsh = hash_new ()) == NULL
23592 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
23593 as_fatal (_("virtual memory exhausted"));
23594
23595 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 23596 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 23597 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 23598 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 23599 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 23600 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 23601 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 23602 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 23603 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 23604 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 23605 (void *) (v7m_psrs + i));
c19d1205 23606 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 23607 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
23608 for (i = 0;
23609 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
23610 i++)
d3ce72d0 23611 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 23612 (void *) (barrier_opt_names + i));
c19d1205 23613#ifdef OBJ_ELF
3da1d841
NC
23614 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
23615 {
23616 struct reloc_entry * entry = reloc_names + i;
23617
23618 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
23619 /* This makes encode_branch() use the EABI versions of this relocation. */
23620 entry->reloc = BFD_RELOC_UNUSED;
23621
23622 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
23623 }
c19d1205
ZW
23624#endif
23625
23626 set_constant_flonums ();
404ff6b5 23627
c19d1205
ZW
23628 /* Set the cpu variant based on the command-line options. We prefer
23629 -mcpu= over -march= if both are set (as for GCC); and we prefer
23630 -mfpu= over any other way of setting the floating point unit.
23631 Use of legacy options with new options are faulted. */
e74cfd16 23632 if (legacy_cpu)
404ff6b5 23633 {
e74cfd16 23634 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
23635 as_bad (_("use of old and new-style options to set CPU type"));
23636
23637 mcpu_cpu_opt = legacy_cpu;
404ff6b5 23638 }
e74cfd16 23639 else if (!mcpu_cpu_opt)
c19d1205 23640 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 23641
e74cfd16 23642 if (legacy_fpu)
c19d1205 23643 {
e74cfd16 23644 if (mfpu_opt)
c19d1205 23645 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
23646
23647 mfpu_opt = legacy_fpu;
23648 }
e74cfd16 23649 else if (!mfpu_opt)
03b1477f 23650 {
45eb4c1b
NS
23651#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
23652 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
23653 /* Some environments specify a default FPU. If they don't, infer it
23654 from the processor. */
e74cfd16 23655 if (mcpu_fpu_opt)
03b1477f
RE
23656 mfpu_opt = mcpu_fpu_opt;
23657 else
23658 mfpu_opt = march_fpu_opt;
39c2da32 23659#else
e74cfd16 23660 mfpu_opt = &fpu_default;
39c2da32 23661#endif
03b1477f
RE
23662 }
23663
e74cfd16 23664 if (!mfpu_opt)
03b1477f 23665 {
493cb6ef 23666 if (mcpu_cpu_opt != NULL)
e74cfd16 23667 mfpu_opt = &fpu_default;
493cb6ef 23668 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 23669 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 23670 else
e74cfd16 23671 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
23672 }
23673
ee065d83 23674#ifdef CPU_DEFAULT
e74cfd16 23675 if (!mcpu_cpu_opt)
ee065d83 23676 {
e74cfd16
PB
23677 mcpu_cpu_opt = &cpu_default;
23678 selected_cpu = cpu_default;
ee065d83 23679 }
e74cfd16
PB
23680#else
23681 if (mcpu_cpu_opt)
23682 selected_cpu = *mcpu_cpu_opt;
ee065d83 23683 else
e74cfd16 23684 mcpu_cpu_opt = &arm_arch_any;
ee065d83 23685#endif
03b1477f 23686
e74cfd16 23687 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 23688
3e9e4fcf
JB
23689 autoselect_thumb_from_cpu_variant ();
23690
e74cfd16 23691 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 23692
f17c130b 23693#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 23694 {
7cc69913
NC
23695 unsigned int flags = 0;
23696
23697#if defined OBJ_ELF
23698 flags = meabi_flags;
d507cf36
PB
23699
23700 switch (meabi_flags)
33a392fb 23701 {
d507cf36 23702 case EF_ARM_EABI_UNKNOWN:
7cc69913 23703#endif
d507cf36
PB
23704 /* Set the flags in the private structure. */
23705 if (uses_apcs_26) flags |= F_APCS26;
23706 if (support_interwork) flags |= F_INTERWORK;
23707 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 23708 if (pic_code) flags |= F_PIC;
e74cfd16 23709 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
23710 flags |= F_SOFT_FLOAT;
23711
d507cf36
PB
23712 switch (mfloat_abi_opt)
23713 {
23714 case ARM_FLOAT_ABI_SOFT:
23715 case ARM_FLOAT_ABI_SOFTFP:
23716 flags |= F_SOFT_FLOAT;
23717 break;
33a392fb 23718
d507cf36
PB
23719 case ARM_FLOAT_ABI_HARD:
23720 if (flags & F_SOFT_FLOAT)
23721 as_bad (_("hard-float conflicts with specified fpu"));
23722 break;
23723 }
03b1477f 23724
e74cfd16
PB
23725 /* Using pure-endian doubles (even if soft-float). */
23726 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 23727 flags |= F_VFP_FLOAT;
f17c130b 23728
fde78edd 23729#if defined OBJ_ELF
e74cfd16 23730 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 23731 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
23732 break;
23733
8cb51566 23734 case EF_ARM_EABI_VER4:
3a4a14e9 23735 case EF_ARM_EABI_VER5:
c19d1205 23736 /* No additional flags to set. */
d507cf36
PB
23737 break;
23738
23739 default:
23740 abort ();
23741 }
7cc69913 23742#endif
b99bd4ef
NC
23743 bfd_set_private_flags (stdoutput, flags);
23744
23745 /* We have run out flags in the COFF header to encode the
23746 status of ATPCS support, so instead we create a dummy,
c19d1205 23747 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
23748 if (atpcs)
23749 {
23750 asection * sec;
23751
23752 sec = bfd_make_section (stdoutput, ".arm.atpcs");
23753
23754 if (sec != NULL)
23755 {
23756 bfd_set_section_flags
23757 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
23758 bfd_set_section_size (stdoutput, sec, 0);
23759 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
23760 }
23761 }
7cc69913 23762 }
f17c130b 23763#endif
b99bd4ef
NC
23764
23765 /* Record the CPU type as well. */
2d447fca
JM
23766 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
23767 mach = bfd_mach_arm_iWMMXt2;
23768 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 23769 mach = bfd_mach_arm_iWMMXt;
e74cfd16 23770 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 23771 mach = bfd_mach_arm_XScale;
e74cfd16 23772 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 23773 mach = bfd_mach_arm_ep9312;
e74cfd16 23774 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 23775 mach = bfd_mach_arm_5TE;
e74cfd16 23776 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 23777 {
e74cfd16 23778 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
23779 mach = bfd_mach_arm_5T;
23780 else
23781 mach = bfd_mach_arm_5;
23782 }
e74cfd16 23783 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 23784 {
e74cfd16 23785 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
23786 mach = bfd_mach_arm_4T;
23787 else
23788 mach = bfd_mach_arm_4;
23789 }
e74cfd16 23790 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 23791 mach = bfd_mach_arm_3M;
e74cfd16
PB
23792 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
23793 mach = bfd_mach_arm_3;
23794 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
23795 mach = bfd_mach_arm_2a;
23796 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
23797 mach = bfd_mach_arm_2;
23798 else
23799 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
23800
23801 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
23802}
23803
c19d1205 23804/* Command line processing. */
b99bd4ef 23805
c19d1205
ZW
23806/* md_parse_option
23807 Invocation line includes a switch not recognized by the base assembler.
23808 See if it's a processor-specific option.
b99bd4ef 23809
c19d1205
ZW
23810 This routine is somewhat complicated by the need for backwards
23811 compatibility (since older releases of gcc can't be changed).
23812 The new options try to make the interface as compatible as
23813 possible with GCC.
b99bd4ef 23814
c19d1205 23815 New options (supported) are:
b99bd4ef 23816
c19d1205
ZW
23817 -mcpu=<cpu name> Assemble for selected processor
23818 -march=<architecture name> Assemble for selected architecture
23819 -mfpu=<fpu architecture> Assemble for selected FPU.
23820 -EB/-mbig-endian Big-endian
23821 -EL/-mlittle-endian Little-endian
23822 -k Generate PIC code
23823 -mthumb Start in Thumb mode
23824 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 23825
278df34e 23826 -m[no-]warn-deprecated Warn about deprecated features
267bf995 23827
c19d1205 23828 For now we will also provide support for:
b99bd4ef 23829
c19d1205
ZW
23830 -mapcs-32 32-bit Program counter
23831 -mapcs-26 26-bit Program counter
23832 -macps-float Floats passed in FP registers
23833 -mapcs-reentrant Reentrant code
23834 -matpcs
23835 (sometime these will probably be replaced with -mapcs=<list of options>
23836 and -matpcs=<list of options>)
b99bd4ef 23837
c19d1205
ZW
23838 The remaining options are only supported for back-wards compatibility.
23839 Cpu variants, the arm part is optional:
23840 -m[arm]1 Currently not supported.
23841 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
23842 -m[arm]3 Arm 3 processor
23843 -m[arm]6[xx], Arm 6 processors
23844 -m[arm]7[xx][t][[d]m] Arm 7 processors
23845 -m[arm]8[10] Arm 8 processors
23846 -m[arm]9[20][tdmi] Arm 9 processors
23847 -mstrongarm[110[0]] StrongARM processors
23848 -mxscale XScale processors
23849 -m[arm]v[2345[t[e]]] Arm architectures
23850 -mall All (except the ARM1)
23851 FP variants:
23852 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
23853 -mfpe-old (No float load/store multiples)
23854 -mvfpxd VFP Single precision
23855 -mvfp All VFP
23856 -mno-fpu Disable all floating point instructions
b99bd4ef 23857
c19d1205
ZW
23858 The following CPU names are recognized:
23859 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
23860 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
23861 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
23862 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
23863 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
23864 arm10t arm10e, arm1020t, arm1020e, arm10200e,
23865 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 23866
c19d1205 23867 */
b99bd4ef 23868
c19d1205 23869const char * md_shortopts = "m:k";
b99bd4ef 23870
c19d1205
ZW
23871#ifdef ARM_BI_ENDIAN
23872#define OPTION_EB (OPTION_MD_BASE + 0)
23873#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 23874#else
c19d1205
ZW
23875#if TARGET_BYTES_BIG_ENDIAN
23876#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 23877#else
c19d1205
ZW
23878#define OPTION_EL (OPTION_MD_BASE + 1)
23879#endif
b99bd4ef 23880#endif
845b51d6 23881#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 23882
c19d1205 23883struct option md_longopts[] =
b99bd4ef 23884{
c19d1205
ZW
23885#ifdef OPTION_EB
23886 {"EB", no_argument, NULL, OPTION_EB},
23887#endif
23888#ifdef OPTION_EL
23889 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 23890#endif
845b51d6 23891 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
23892 {NULL, no_argument, NULL, 0}
23893};
b99bd4ef 23894
c19d1205 23895size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 23896
c19d1205 23897struct arm_option_table
b99bd4ef 23898{
c19d1205
ZW
23899 char *option; /* Option name to match. */
23900 char *help; /* Help information. */
23901 int *var; /* Variable to change. */
23902 int value; /* What to change it to. */
23903 char *deprecated; /* If non-null, print this message. */
23904};
b99bd4ef 23905
c19d1205
ZW
23906struct arm_option_table arm_opts[] =
23907{
23908 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
23909 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
23910 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
23911 &support_interwork, 1, NULL},
23912 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
23913 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
23914 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
23915 1, NULL},
23916 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
23917 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
23918 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
23919 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
23920 NULL},
b99bd4ef 23921
c19d1205
ZW
23922 /* These are recognized by the assembler, but have no affect on code. */
23923 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
23924 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
23925
23926 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
23927 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
23928 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
23929 {NULL, NULL, NULL, 0, NULL}
23930};
23931
23932struct arm_legacy_option_table
23933{
23934 char *option; /* Option name to match. */
23935 const arm_feature_set **var; /* Variable to change. */
23936 const arm_feature_set value; /* What to change it to. */
23937 char *deprecated; /* If non-null, print this message. */
23938};
b99bd4ef 23939
e74cfd16
PB
23940const struct arm_legacy_option_table arm_legacy_opts[] =
23941{
c19d1205
ZW
23942 /* DON'T add any new processors to this list -- we want the whole list
23943 to go away... Add them to the processors table instead. */
e74cfd16
PB
23944 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
23945 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
23946 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
23947 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
23948 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
23949 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
23950 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
23951 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
23952 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
23953 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
23954 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
23955 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
23956 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
23957 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
23958 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
23959 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
23960 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
23961 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
23962 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
23963 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
23964 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
23965 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
23966 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
23967 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
23968 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
23969 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
23970 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
23971 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
23972 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
23973 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
23974 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
23975 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
23976 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
23977 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
23978 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
23979 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
23980 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
23981 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
23982 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
23983 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
23984 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
23985 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
23986 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
23987 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
23988 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
23989 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
23990 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23991 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23992 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23993 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23994 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
23995 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
23996 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
23997 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
23998 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
23999 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
24000 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
24001 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
24002 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
24003 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
24004 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
24005 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
24006 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
24007 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
24008 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
24009 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
24010 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
24011 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
24012 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
24013 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24014 N_("use -mcpu=strongarm110")},
e74cfd16 24015 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24016 N_("use -mcpu=strongarm1100")},
e74cfd16 24017 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24018 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
24019 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
24020 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
24021 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 24022
c19d1205 24023 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
24024 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
24025 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
24026 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
24027 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
24028 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
24029 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
24030 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
24031 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
24032 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
24033 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
24034 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
24035 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
24036 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
24037 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
24038 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
24039 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
24040 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
24041 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 24042
c19d1205 24043 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
24044 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
24045 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
24046 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
24047 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 24048 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 24049
e74cfd16 24050 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 24051};
7ed4c4c5 24052
c19d1205 24053struct arm_cpu_option_table
7ed4c4c5 24054{
c19d1205 24055 char *name;
f3bad469 24056 size_t name_len;
e74cfd16 24057 const arm_feature_set value;
c19d1205
ZW
24058 /* For some CPUs we assume an FPU unless the user explicitly sets
24059 -mfpu=... */
e74cfd16 24060 const arm_feature_set default_fpu;
ee065d83
PB
24061 /* The canonical name of the CPU, or NULL to use NAME converted to upper
24062 case. */
24063 const char *canonical_name;
c19d1205 24064};
7ed4c4c5 24065
c19d1205
ZW
24066/* This list should, at a minimum, contain all the cpu names
24067 recognized by GCC. */
f3bad469 24068#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 24069static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 24070{
f3bad469
MGD
24071 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
24072 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
24073 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
24074 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
24075 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
24076 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24077 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24078 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24079 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24080 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24081 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24082 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24083 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24084 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24085 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24086 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24087 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24088 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24089 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24090 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24091 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24092 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24093 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24094 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24095 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24096 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24097 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24098 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24099 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24100 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24101 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24102 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24103 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24104 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24105 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24106 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24107 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24108 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24109 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24110 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
24111 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24112 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24113 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24114 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24115 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24116 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
24117 /* For V5 or later processors we default to using VFP; but the user
24118 should really set the FPU type explicitly. */
f3bad469
MGD
24119 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24120 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24121 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
24122 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
24123 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
24124 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24125 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
24126 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24127 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24128 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
24129 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24130 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24131 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24132 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24133 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24134 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
24135 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24136 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24137 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24138 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
24139 "ARM1026EJ-S"),
24140 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
24141 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24142 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24143 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24144 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24145 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24146 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
24147 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
24148 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
24149 "ARM1136JF-S"),
24150 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
24151 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
24152 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
24153 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
24154 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
24155 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL),
24156 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL),
24157 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
24158 FPU_NONE, "Cortex-A5"),
c9fb6e58 24159 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469
MGD
24160 "Cortex-A7"),
24161 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
24162 ARM_FEATURE (0, FPU_VFP_V3
477330fc 24163 | FPU_NEON_EXT_V1),
f3bad469
MGD
24164 "Cortex-A8"),
24165 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
24166 ARM_FEATURE (0, FPU_VFP_V3
477330fc 24167 | FPU_NEON_EXT_V1),
f3bad469 24168 "Cortex-A9"),
c9fb6e58 24169 ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
63a4bc21 24170 "Cortex-A12"),
c9fb6e58 24171 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469 24172 "Cortex-A15"),
92eb40d9 24173 ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 24174 "Cortex-A53"),
92eb40d9 24175 ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 24176 "Cortex-A57"),
f3bad469
MGD
24177 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
24178 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
24179 "Cortex-R4F"),
24180 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
24181 FPU_NONE, "Cortex-R5"),
70a8bc5b 24182 ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV,
24183 FPU_ARCH_VFP_V3D16,
24184 "Cortex-R7"),
f3bad469
MGD
24185 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
24186 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
24187 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
24188 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 24189 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
c19d1205 24190 /* ??? XSCALE is really an architecture. */
f3bad469 24191 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 24192 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
24193 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
24194 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
24195 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 24196 /* Maverick */
f3bad469 24197 ARM_CPU_OPT ("ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
da4339ed
NC
24198 FPU_ARCH_MAVERICK, "ARM920T"),
24199 /* Marvell processors. */
4a81b02a 24200 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE (ARM_AEXT_V7A | ARM_EXT_MP | ARM_EXT_SEC, 0),
477330fc 24201 FPU_ARCH_VFP_V3D16, NULL),
da4339ed 24202
f3bad469 24203 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 24204};
f3bad469 24205#undef ARM_CPU_OPT
7ed4c4c5 24206
c19d1205 24207struct arm_arch_option_table
7ed4c4c5 24208{
c19d1205 24209 char *name;
f3bad469 24210 size_t name_len;
e74cfd16
PB
24211 const arm_feature_set value;
24212 const arm_feature_set default_fpu;
c19d1205 24213};
7ed4c4c5 24214
c19d1205
ZW
24215/* This list should, at a minimum, contain all the architecture names
24216 recognized by GCC. */
f3bad469 24217#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 24218static const struct arm_arch_option_table arm_archs[] =
c19d1205 24219{
f3bad469
MGD
24220 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
24221 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
24222 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
24223 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
24224 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
24225 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
24226 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
24227 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
24228 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
24229 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
24230 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
24231 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
24232 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
24233 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
24234 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
24235 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
24236 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
24237 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
24238 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
24239 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
24240 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
24241 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP),
24242 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
24243 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
24244 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
24245 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP),
24246 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
24247 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
24248 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
24249 /* The official spelling of the ARMv7 profile variants is the dashed form.
24250 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 24251 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 24252 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
24253 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
24254 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
24255 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
24256 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
24257 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
24258 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
bca38921 24259 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
f3bad469
MGD
24260 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
24261 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
24262 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
24263 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 24264};
f3bad469 24265#undef ARM_ARCH_OPT
7ed4c4c5 24266
69133863
MGD
24267/* ISA extensions in the co-processor and main instruction set space. */
24268struct arm_option_extension_value_table
c19d1205
ZW
24269{
24270 char *name;
f3bad469 24271 size_t name_len;
e74cfd16 24272 const arm_feature_set value;
69133863 24273 const arm_feature_set allowed_archs;
c19d1205 24274};
7ed4c4c5 24275
69133863
MGD
24276/* The following table must be in alphabetical order with a NULL last entry.
24277 */
f3bad469 24278#define ARM_EXT_OPT(N, V, AA) { N, sizeof (N) - 1, V, AA }
69133863 24279static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 24280{
dd5181d5 24281 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE (ARM_EXT_V8, 0)),
bca38921
MGD
24282 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24283 ARM_FEATURE (ARM_EXT_V8, 0)),
24284 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8,
24285 ARM_FEATURE (ARM_EXT_V8, 0)),
f3bad469
MGD
24286 ARM_EXT_OPT ("idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0),
24287 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
24288 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY),
24289 ARM_EXT_OPT ("iwmmxt2",
24290 ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY),
24291 ARM_EXT_OPT ("maverick",
477330fc 24292 ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY),
f3bad469
MGD
24293 ARM_EXT_OPT ("mp", ARM_FEATURE (ARM_EXT_MP, 0),
24294 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
bca38921
MGD
24295 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
24296 ARM_FEATURE (ARM_EXT_V8, 0)),
f3bad469
MGD
24297 ARM_EXT_OPT ("os", ARM_FEATURE (ARM_EXT_OS, 0),
24298 ARM_FEATURE (ARM_EXT_V6M, 0)),
24299 ARM_EXT_OPT ("sec", ARM_FEATURE (ARM_EXT_SEC, 0),
24300 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)),
24301 ARM_EXT_OPT ("virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV
24302 | ARM_EXT_DIV, 0),
24303 ARM_FEATURE (ARM_EXT_V7A, 0)),
24304 ARM_EXT_OPT ("xscale",ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY),
24305 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
69133863 24306};
f3bad469 24307#undef ARM_EXT_OPT
69133863
MGD
24308
24309/* ISA floating-point and Advanced SIMD extensions. */
24310struct arm_option_fpu_value_table
24311{
24312 char *name;
24313 const arm_feature_set value;
c19d1205 24314};
7ed4c4c5 24315
c19d1205
ZW
24316/* This list should, at a minimum, contain all the fpu names
24317 recognized by GCC. */
69133863 24318static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
24319{
24320 {"softfpa", FPU_NONE},
24321 {"fpe", FPU_ARCH_FPE},
24322 {"fpe2", FPU_ARCH_FPE},
24323 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
24324 {"fpa", FPU_ARCH_FPA},
24325 {"fpa10", FPU_ARCH_FPA},
24326 {"fpa11", FPU_ARCH_FPA},
24327 {"arm7500fe", FPU_ARCH_FPA},
24328 {"softvfp", FPU_ARCH_VFP},
24329 {"softvfp+vfp", FPU_ARCH_VFP_V2},
24330 {"vfp", FPU_ARCH_VFP_V2},
24331 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 24332 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
24333 {"vfp10", FPU_ARCH_VFP_V2},
24334 {"vfp10-r0", FPU_ARCH_VFP_V1},
24335 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
24336 {"vfpv2", FPU_ARCH_VFP_V2},
24337 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 24338 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 24339 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
24340 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
24341 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
24342 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
24343 {"arm1020t", FPU_ARCH_VFP_V1},
24344 {"arm1020e", FPU_ARCH_VFP_V2},
24345 {"arm1136jfs", FPU_ARCH_VFP_V2},
24346 {"arm1136jf-s", FPU_ARCH_VFP_V2},
24347 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 24348 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 24349 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
24350 {"vfpv4", FPU_ARCH_VFP_V4},
24351 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 24352 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 24353 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
24354 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
24355 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
24356 {"crypto-neon-fp-armv8",
24357 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
e74cfd16
PB
24358 {NULL, ARM_ARCH_NONE}
24359};
24360
24361struct arm_option_value_table
24362{
24363 char *name;
24364 long value;
c19d1205 24365};
7ed4c4c5 24366
e74cfd16 24367static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
24368{
24369 {"hard", ARM_FLOAT_ABI_HARD},
24370 {"softfp", ARM_FLOAT_ABI_SOFTFP},
24371 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 24372 {NULL, 0}
c19d1205 24373};
7ed4c4c5 24374
c19d1205 24375#ifdef OBJ_ELF
3a4a14e9 24376/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 24377static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
24378{
24379 {"gnu", EF_ARM_EABI_UNKNOWN},
24380 {"4", EF_ARM_EABI_VER4},
3a4a14e9 24381 {"5", EF_ARM_EABI_VER5},
e74cfd16 24382 {NULL, 0}
c19d1205
ZW
24383};
24384#endif
7ed4c4c5 24385
c19d1205
ZW
24386struct arm_long_option_table
24387{
24388 char * option; /* Substring to match. */
24389 char * help; /* Help information. */
24390 int (* func) (char * subopt); /* Function to decode sub-option. */
24391 char * deprecated; /* If non-null, print this message. */
24392};
7ed4c4c5 24393
c921be7d 24394static bfd_boolean
f3bad469 24395arm_parse_extension (char *str, const arm_feature_set **opt_p)
7ed4c4c5 24396{
21d799b5
NC
24397 arm_feature_set *ext_set = (arm_feature_set *)
24398 xmalloc (sizeof (arm_feature_set));
e74cfd16 24399
69133863 24400 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
24401 extensions being added before being removed. We achieve this by having
24402 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 24403 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 24404 or removing it (0) and only allowing it to change in the order
69133863
MGD
24405 -1 -> 1 -> 0. */
24406 const struct arm_option_extension_value_table * opt = NULL;
24407 int adding_value = -1;
24408
e74cfd16
PB
24409 /* Copy the feature set, so that we can modify it. */
24410 *ext_set = **opt_p;
24411 *opt_p = ext_set;
24412
c19d1205 24413 while (str != NULL && *str != 0)
7ed4c4c5 24414 {
f3bad469
MGD
24415 char *ext;
24416 size_t len;
7ed4c4c5 24417
c19d1205
ZW
24418 if (*str != '+')
24419 {
24420 as_bad (_("invalid architectural extension"));
c921be7d 24421 return FALSE;
c19d1205 24422 }
7ed4c4c5 24423
c19d1205
ZW
24424 str++;
24425 ext = strchr (str, '+');
7ed4c4c5 24426
c19d1205 24427 if (ext != NULL)
f3bad469 24428 len = ext - str;
c19d1205 24429 else
f3bad469 24430 len = strlen (str);
7ed4c4c5 24431
f3bad469 24432 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
24433 {
24434 if (adding_value != 0)
24435 {
24436 adding_value = 0;
24437 opt = arm_extensions;
24438 }
24439
f3bad469 24440 len -= 2;
69133863
MGD
24441 str += 2;
24442 }
f3bad469 24443 else if (len > 0)
69133863
MGD
24444 {
24445 if (adding_value == -1)
24446 {
24447 adding_value = 1;
24448 opt = arm_extensions;
24449 }
24450 else if (adding_value != 1)
24451 {
24452 as_bad (_("must specify extensions to add before specifying "
24453 "those to remove"));
24454 return FALSE;
24455 }
24456 }
24457
f3bad469 24458 if (len == 0)
c19d1205
ZW
24459 {
24460 as_bad (_("missing architectural extension"));
c921be7d 24461 return FALSE;
c19d1205 24462 }
7ed4c4c5 24463
69133863
MGD
24464 gas_assert (adding_value != -1);
24465 gas_assert (opt != NULL);
24466
24467 /* Scan over the options table trying to find an exact match. */
24468 for (; opt->name != NULL; opt++)
f3bad469 24469 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 24470 {
69133863
MGD
24471 /* Check we can apply the extension to this architecture. */
24472 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
24473 {
24474 as_bad (_("extension does not apply to the base architecture"));
24475 return FALSE;
24476 }
24477
24478 /* Add or remove the extension. */
24479 if (adding_value)
24480 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
24481 else
24482 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
24483
c19d1205
ZW
24484 break;
24485 }
7ed4c4c5 24486
c19d1205
ZW
24487 if (opt->name == NULL)
24488 {
69133863
MGD
24489 /* Did we fail to find an extension because it wasn't specified in
24490 alphabetical order, or because it does not exist? */
24491
24492 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 24493 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
24494 break;
24495
24496 if (opt->name == NULL)
24497 as_bad (_("unknown architectural extension `%s'"), str);
24498 else
24499 as_bad (_("architectural extensions must be specified in "
24500 "alphabetical order"));
24501
c921be7d 24502 return FALSE;
c19d1205 24503 }
69133863
MGD
24504 else
24505 {
24506 /* We should skip the extension we've just matched the next time
24507 round. */
24508 opt++;
24509 }
7ed4c4c5 24510
c19d1205
ZW
24511 str = ext;
24512 };
7ed4c4c5 24513
c921be7d 24514 return TRUE;
c19d1205 24515}
7ed4c4c5 24516
c921be7d 24517static bfd_boolean
f3bad469 24518arm_parse_cpu (char *str)
7ed4c4c5 24519{
f3bad469
MGD
24520 const struct arm_cpu_option_table *opt;
24521 char *ext = strchr (str, '+');
24522 size_t len;
7ed4c4c5 24523
c19d1205 24524 if (ext != NULL)
f3bad469 24525 len = ext - str;
7ed4c4c5 24526 else
f3bad469 24527 len = strlen (str);
7ed4c4c5 24528
f3bad469 24529 if (len == 0)
7ed4c4c5 24530 {
c19d1205 24531 as_bad (_("missing cpu name `%s'"), str);
c921be7d 24532 return FALSE;
7ed4c4c5
NC
24533 }
24534
c19d1205 24535 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 24536 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 24537 {
e74cfd16
PB
24538 mcpu_cpu_opt = &opt->value;
24539 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 24540 if (opt->canonical_name)
5f4273c7 24541 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
24542 else
24543 {
f3bad469 24544 size_t i;
c921be7d 24545
f3bad469 24546 for (i = 0; i < len; i++)
ee065d83
PB
24547 selected_cpu_name[i] = TOUPPER (opt->name[i]);
24548 selected_cpu_name[i] = 0;
24549 }
7ed4c4c5 24550
c19d1205
ZW
24551 if (ext != NULL)
24552 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 24553
c921be7d 24554 return TRUE;
c19d1205 24555 }
7ed4c4c5 24556
c19d1205 24557 as_bad (_("unknown cpu `%s'"), str);
c921be7d 24558 return FALSE;
7ed4c4c5
NC
24559}
24560
c921be7d 24561static bfd_boolean
f3bad469 24562arm_parse_arch (char *str)
7ed4c4c5 24563{
e74cfd16 24564 const struct arm_arch_option_table *opt;
c19d1205 24565 char *ext = strchr (str, '+');
f3bad469 24566 size_t len;
7ed4c4c5 24567
c19d1205 24568 if (ext != NULL)
f3bad469 24569 len = ext - str;
7ed4c4c5 24570 else
f3bad469 24571 len = strlen (str);
7ed4c4c5 24572
f3bad469 24573 if (len == 0)
7ed4c4c5 24574 {
c19d1205 24575 as_bad (_("missing architecture name `%s'"), str);
c921be7d 24576 return FALSE;
7ed4c4c5
NC
24577 }
24578
c19d1205 24579 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 24580 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 24581 {
e74cfd16
PB
24582 march_cpu_opt = &opt->value;
24583 march_fpu_opt = &opt->default_fpu;
5f4273c7 24584 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 24585
c19d1205
ZW
24586 if (ext != NULL)
24587 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 24588
c921be7d 24589 return TRUE;
c19d1205
ZW
24590 }
24591
24592 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 24593 return FALSE;
7ed4c4c5 24594}
eb043451 24595
c921be7d 24596static bfd_boolean
c19d1205
ZW
24597arm_parse_fpu (char * str)
24598{
69133863 24599 const struct arm_option_fpu_value_table * opt;
b99bd4ef 24600
c19d1205
ZW
24601 for (opt = arm_fpus; opt->name != NULL; opt++)
24602 if (streq (opt->name, str))
24603 {
e74cfd16 24604 mfpu_opt = &opt->value;
c921be7d 24605 return TRUE;
c19d1205 24606 }
b99bd4ef 24607
c19d1205 24608 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 24609 return FALSE;
c19d1205
ZW
24610}
24611
c921be7d 24612static bfd_boolean
c19d1205 24613arm_parse_float_abi (char * str)
b99bd4ef 24614{
e74cfd16 24615 const struct arm_option_value_table * opt;
b99bd4ef 24616
c19d1205
ZW
24617 for (opt = arm_float_abis; opt->name != NULL; opt++)
24618 if (streq (opt->name, str))
24619 {
24620 mfloat_abi_opt = opt->value;
c921be7d 24621 return TRUE;
c19d1205 24622 }
cc8a6dd0 24623
c19d1205 24624 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 24625 return FALSE;
c19d1205 24626}
b99bd4ef 24627
c19d1205 24628#ifdef OBJ_ELF
c921be7d 24629static bfd_boolean
c19d1205
ZW
24630arm_parse_eabi (char * str)
24631{
e74cfd16 24632 const struct arm_option_value_table *opt;
cc8a6dd0 24633
c19d1205
ZW
24634 for (opt = arm_eabis; opt->name != NULL; opt++)
24635 if (streq (opt->name, str))
24636 {
24637 meabi_flags = opt->value;
c921be7d 24638 return TRUE;
c19d1205
ZW
24639 }
24640 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 24641 return FALSE;
c19d1205
ZW
24642}
24643#endif
cc8a6dd0 24644
c921be7d 24645static bfd_boolean
e07e6e58
NC
24646arm_parse_it_mode (char * str)
24647{
c921be7d 24648 bfd_boolean ret = TRUE;
e07e6e58
NC
24649
24650 if (streq ("arm", str))
24651 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
24652 else if (streq ("thumb", str))
24653 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
24654 else if (streq ("always", str))
24655 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
24656 else if (streq ("never", str))
24657 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
24658 else
24659 {
24660 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 24661 "arm, thumb, always, or never."), str);
c921be7d 24662 ret = FALSE;
e07e6e58
NC
24663 }
24664
24665 return ret;
24666}
24667
2e6976a8
DG
24668static bfd_boolean
24669arm_ccs_mode (char * unused ATTRIBUTE_UNUSED)
24670{
24671 codecomposer_syntax = TRUE;
24672 arm_comment_chars[0] = ';';
24673 arm_line_separator_chars[0] = 0;
24674 return TRUE;
24675}
24676
c19d1205
ZW
24677struct arm_long_option_table arm_long_opts[] =
24678{
24679 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
24680 arm_parse_cpu, NULL},
24681 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
24682 arm_parse_arch, NULL},
24683 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
24684 arm_parse_fpu, NULL},
24685 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
24686 arm_parse_float_abi, NULL},
24687#ifdef OBJ_ELF
7fac0536 24688 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
24689 arm_parse_eabi, NULL},
24690#endif
e07e6e58
NC
24691 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
24692 arm_parse_it_mode, NULL},
2e6976a8
DG
24693 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
24694 arm_ccs_mode, NULL},
c19d1205
ZW
24695 {NULL, NULL, 0, NULL}
24696};
cc8a6dd0 24697
c19d1205
ZW
24698int
24699md_parse_option (int c, char * arg)
24700{
24701 struct arm_option_table *opt;
e74cfd16 24702 const struct arm_legacy_option_table *fopt;
c19d1205 24703 struct arm_long_option_table *lopt;
b99bd4ef 24704
c19d1205 24705 switch (c)
b99bd4ef 24706 {
c19d1205
ZW
24707#ifdef OPTION_EB
24708 case OPTION_EB:
24709 target_big_endian = 1;
24710 break;
24711#endif
cc8a6dd0 24712
c19d1205
ZW
24713#ifdef OPTION_EL
24714 case OPTION_EL:
24715 target_big_endian = 0;
24716 break;
24717#endif
b99bd4ef 24718
845b51d6
PB
24719 case OPTION_FIX_V4BX:
24720 fix_v4bx = TRUE;
24721 break;
24722
c19d1205
ZW
24723 case 'a':
24724 /* Listing option. Just ignore these, we don't support additional
24725 ones. */
24726 return 0;
b99bd4ef 24727
c19d1205
ZW
24728 default:
24729 for (opt = arm_opts; opt->option != NULL; opt++)
24730 {
24731 if (c == opt->option[0]
24732 && ((arg == NULL && opt->option[1] == 0)
24733 || streq (arg, opt->option + 1)))
24734 {
c19d1205 24735 /* If the option is deprecated, tell the user. */
278df34e 24736 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
24737 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
24738 arg ? arg : "", _(opt->deprecated));
b99bd4ef 24739
c19d1205
ZW
24740 if (opt->var != NULL)
24741 *opt->var = opt->value;
cc8a6dd0 24742
c19d1205
ZW
24743 return 1;
24744 }
24745 }
b99bd4ef 24746
e74cfd16
PB
24747 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
24748 {
24749 if (c == fopt->option[0]
24750 && ((arg == NULL && fopt->option[1] == 0)
24751 || streq (arg, fopt->option + 1)))
24752 {
e74cfd16 24753 /* If the option is deprecated, tell the user. */
278df34e 24754 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
24755 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
24756 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
24757
24758 if (fopt->var != NULL)
24759 *fopt->var = &fopt->value;
24760
24761 return 1;
24762 }
24763 }
24764
c19d1205
ZW
24765 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
24766 {
24767 /* These options are expected to have an argument. */
24768 if (c == lopt->option[0]
24769 && arg != NULL
24770 && strncmp (arg, lopt->option + 1,
24771 strlen (lopt->option + 1)) == 0)
24772 {
c19d1205 24773 /* If the option is deprecated, tell the user. */
278df34e 24774 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
24775 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
24776 _(lopt->deprecated));
b99bd4ef 24777
c19d1205
ZW
24778 /* Call the sup-option parser. */
24779 return lopt->func (arg + strlen (lopt->option) - 1);
24780 }
24781 }
a737bd4d 24782
c19d1205
ZW
24783 return 0;
24784 }
a394c00f 24785
c19d1205
ZW
24786 return 1;
24787}
a394c00f 24788
c19d1205
ZW
24789void
24790md_show_usage (FILE * fp)
a394c00f 24791{
c19d1205
ZW
24792 struct arm_option_table *opt;
24793 struct arm_long_option_table *lopt;
a394c00f 24794
c19d1205 24795 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 24796
c19d1205
ZW
24797 for (opt = arm_opts; opt->option != NULL; opt++)
24798 if (opt->help != NULL)
24799 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 24800
c19d1205
ZW
24801 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
24802 if (lopt->help != NULL)
24803 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 24804
c19d1205
ZW
24805#ifdef OPTION_EB
24806 fprintf (fp, _("\
24807 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
24808#endif
24809
c19d1205
ZW
24810#ifdef OPTION_EL
24811 fprintf (fp, _("\
24812 -EL assemble code for a little-endian cpu\n"));
a737bd4d 24813#endif
845b51d6
PB
24814
24815 fprintf (fp, _("\
24816 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 24817}
ee065d83
PB
24818
24819
24820#ifdef OBJ_ELF
62b3e311
PB
24821typedef struct
24822{
24823 int val;
24824 arm_feature_set flags;
24825} cpu_arch_ver_table;
24826
24827/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
24828 least features first. */
24829static const cpu_arch_ver_table cpu_arch_ver[] =
24830{
24831 {1, ARM_ARCH_V4},
24832 {2, ARM_ARCH_V4T},
24833 {3, ARM_ARCH_V5},
ee3c0378 24834 {3, ARM_ARCH_V5T},
62b3e311
PB
24835 {4, ARM_ARCH_V5TE},
24836 {5, ARM_ARCH_V5TEJ},
24837 {6, ARM_ARCH_V6},
7e806470 24838 {9, ARM_ARCH_V6K},
f4c65163 24839 {7, ARM_ARCH_V6Z},
91e22acd 24840 {11, ARM_ARCH_V6M},
b2a5fbdc 24841 {12, ARM_ARCH_V6SM},
7e806470 24842 {8, ARM_ARCH_V6T2},
c9fb6e58 24843 {10, ARM_ARCH_V7VE},
62b3e311
PB
24844 {10, ARM_ARCH_V7R},
24845 {10, ARM_ARCH_V7M},
bca38921 24846 {14, ARM_ARCH_V8A},
62b3e311
PB
24847 {0, ARM_ARCH_NONE}
24848};
24849
ee3c0378
AS
24850/* Set an attribute if it has not already been set by the user. */
24851static void
24852aeabi_set_attribute_int (int tag, int value)
24853{
24854 if (tag < 1
24855 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
24856 || !attributes_set_explicitly[tag])
24857 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
24858}
24859
24860static void
24861aeabi_set_attribute_string (int tag, const char *value)
24862{
24863 if (tag < 1
24864 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
24865 || !attributes_set_explicitly[tag])
24866 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
24867}
24868
ee065d83
PB
24869/* Set the public EABI object attributes. */
24870static void
24871aeabi_set_public_attributes (void)
24872{
24873 int arch;
69239280 24874 char profile;
90ec0d68 24875 int virt_sec = 0;
bca38921 24876 int fp16_optional = 0;
e74cfd16 24877 arm_feature_set flags;
62b3e311
PB
24878 arm_feature_set tmp;
24879 const cpu_arch_ver_table *p;
ee065d83
PB
24880
24881 /* Choose the architecture based on the capabilities of the requested cpu
24882 (if any) and/or the instructions actually used. */
e74cfd16
PB
24883 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
24884 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
24885 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
24886
24887 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
24888 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
24889
24890 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
24891 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
24892
24893 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
24894 if (object_arch)
24895 {
24896 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
24897 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
24898 }
24899
251665fc
MGD
24900 /* We need to make sure that the attributes do not identify us as v6S-M
24901 when the only v6S-M feature in use is the Operating System Extensions. */
24902 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
24903 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
477330fc 24904 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
251665fc 24905
62b3e311
PB
24906 tmp = flags;
24907 arch = 0;
24908 for (p = cpu_arch_ver; p->val; p++)
24909 {
24910 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
24911 {
24912 arch = p->val;
24913 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
24914 }
24915 }
ee065d83 24916
9e3c6df6
PB
24917 /* The table lookup above finds the last architecture to contribute
24918 a new feature. Unfortunately, Tag13 is a subset of the union of
24919 v6T2 and v7-M, so it is never seen as contributing a new feature.
24920 We can not search for the last entry which is entirely used,
24921 because if no CPU is specified we build up only those flags
24922 actually used. Perhaps we should separate out the specified
24923 and implicit cases. Avoid taking this path for -march=all by
24924 checking for contradictory v7-A / v7-M features. */
24925 if (arch == 10
24926 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
24927 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
24928 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
24929 arch = 13;
24930
ee065d83
PB
24931 /* Tag_CPU_name. */
24932 if (selected_cpu_name[0])
24933 {
91d6fa6a 24934 char *q;
ee065d83 24935
91d6fa6a
NC
24936 q = selected_cpu_name;
24937 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
24938 {
24939 int i;
5f4273c7 24940
91d6fa6a
NC
24941 q += 4;
24942 for (i = 0; q[i]; i++)
24943 q[i] = TOUPPER (q[i]);
ee065d83 24944 }
91d6fa6a 24945 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 24946 }
62f3b8c8 24947
ee065d83 24948 /* Tag_CPU_arch. */
ee3c0378 24949 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 24950
62b3e311
PB
24951 /* Tag_CPU_arch_profile. */
24952 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
69239280 24953 profile = 'A';
62b3e311 24954 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 24955 profile = 'R';
7e806470 24956 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
24957 profile = 'M';
24958 else
24959 profile = '\0';
24960
24961 if (profile != '\0')
24962 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 24963
ee065d83 24964 /* Tag_ARM_ISA_use. */
ee3c0378
AS
24965 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
24966 || arch == 0)
24967 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 24968
ee065d83 24969 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
24970 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
24971 || arch == 0)
24972 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
24973 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 24974
ee065d83 24975 /* Tag_VFP_arch. */
bca38921
MGD
24976 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8))
24977 aeabi_set_attribute_int (Tag_VFP_arch, 7);
24978 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
24979 aeabi_set_attribute_int (Tag_VFP_arch,
24980 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
24981 ? 5 : 6);
24982 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
24983 {
24984 fp16_optional = 1;
24985 aeabi_set_attribute_int (Tag_VFP_arch, 3);
24986 }
ada65aa3 24987 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
24988 {
24989 aeabi_set_attribute_int (Tag_VFP_arch, 4);
24990 fp16_optional = 1;
24991 }
ee3c0378
AS
24992 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
24993 aeabi_set_attribute_int (Tag_VFP_arch, 2);
24994 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 24995 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 24996 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 24997
4547cb56
NC
24998 /* Tag_ABI_HardFP_use. */
24999 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
25000 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
25001 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
25002
ee065d83 25003 /* Tag_WMMX_arch. */
ee3c0378
AS
25004 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
25005 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
25006 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
25007 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 25008
ee3c0378 25009 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
bca38921
MGD
25010 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
25011 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
25012 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
25013 {
25014 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
25015 {
25016 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
25017 }
25018 else
25019 {
25020 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
25021 fp16_optional = 1;
25022 }
25023 }
fa94de6b 25024
ee3c0378 25025 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 25026 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 25027 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 25028
69239280
MGD
25029 /* Tag_DIV_use.
25030
25031 We set Tag_DIV_use to two when integer divide instructions have been used
25032 in ARM state, or when Thumb integer divide instructions have been used,
25033 but we have no architecture profile set, nor have we any ARM instructions.
25034
bca38921
MGD
25035 For ARMv8 we set the tag to 0 as integer divide is implied by the base
25036 architecture.
25037
69239280 25038 For new architectures we will have to check these tests. */
bca38921
MGD
25039 gas_assert (arch <= TAG_CPU_ARCH_V8);
25040 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8))
25041 aeabi_set_attribute_int (Tag_DIV_use, 0);
25042 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
25043 || (profile == '\0'
25044 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
25045 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 25046 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
25047
25048 /* Tag_MP_extension_use. */
25049 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
25050 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
25051
25052 /* Tag Virtualization_use. */
25053 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
25054 virt_sec |= 1;
25055 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
25056 virt_sec |= 2;
25057 if (virt_sec != 0)
25058 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
25059}
25060
104d59d1 25061/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
25062void
25063arm_md_end (void)
25064{
ee065d83
PB
25065 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
25066 return;
25067
25068 aeabi_set_public_attributes ();
ee065d83 25069}
8463be01 25070#endif /* OBJ_ELF */
ee065d83
PB
25071
25072
25073/* Parse a .cpu directive. */
25074
25075static void
25076s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
25077{
e74cfd16 25078 const struct arm_cpu_option_table *opt;
ee065d83
PB
25079 char *name;
25080 char saved_char;
25081
25082 name = input_line_pointer;
5f4273c7 25083 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
25084 input_line_pointer++;
25085 saved_char = *input_line_pointer;
25086 *input_line_pointer = 0;
25087
25088 /* Skip the first "all" entry. */
25089 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
25090 if (streq (opt->name, name))
25091 {
e74cfd16
PB
25092 mcpu_cpu_opt = &opt->value;
25093 selected_cpu = opt->value;
ee065d83 25094 if (opt->canonical_name)
5f4273c7 25095 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
25096 else
25097 {
25098 int i;
25099 for (i = 0; opt->name[i]; i++)
25100 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 25101
ee065d83
PB
25102 selected_cpu_name[i] = 0;
25103 }
e74cfd16 25104 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
25105 *input_line_pointer = saved_char;
25106 demand_empty_rest_of_line ();
25107 return;
25108 }
25109 as_bad (_("unknown cpu `%s'"), name);
25110 *input_line_pointer = saved_char;
25111 ignore_rest_of_line ();
25112}
25113
25114
25115/* Parse a .arch directive. */
25116
25117static void
25118s_arm_arch (int ignored ATTRIBUTE_UNUSED)
25119{
e74cfd16 25120 const struct arm_arch_option_table *opt;
ee065d83
PB
25121 char saved_char;
25122 char *name;
25123
25124 name = input_line_pointer;
5f4273c7 25125 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
25126 input_line_pointer++;
25127 saved_char = *input_line_pointer;
25128 *input_line_pointer = 0;
25129
25130 /* Skip the first "all" entry. */
25131 for (opt = arm_archs + 1; opt->name != NULL; opt++)
25132 if (streq (opt->name, name))
25133 {
e74cfd16
PB
25134 mcpu_cpu_opt = &opt->value;
25135 selected_cpu = opt->value;
5f4273c7 25136 strcpy (selected_cpu_name, opt->name);
e74cfd16 25137 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
25138 *input_line_pointer = saved_char;
25139 demand_empty_rest_of_line ();
25140 return;
25141 }
25142
25143 as_bad (_("unknown architecture `%s'\n"), name);
25144 *input_line_pointer = saved_char;
25145 ignore_rest_of_line ();
25146}
25147
25148
7a1d4c38
PB
25149/* Parse a .object_arch directive. */
25150
25151static void
25152s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
25153{
25154 const struct arm_arch_option_table *opt;
25155 char saved_char;
25156 char *name;
25157
25158 name = input_line_pointer;
5f4273c7 25159 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
25160 input_line_pointer++;
25161 saved_char = *input_line_pointer;
25162 *input_line_pointer = 0;
25163
25164 /* Skip the first "all" entry. */
25165 for (opt = arm_archs + 1; opt->name != NULL; opt++)
25166 if (streq (opt->name, name))
25167 {
25168 object_arch = &opt->value;
25169 *input_line_pointer = saved_char;
25170 demand_empty_rest_of_line ();
25171 return;
25172 }
25173
25174 as_bad (_("unknown architecture `%s'\n"), name);
25175 *input_line_pointer = saved_char;
25176 ignore_rest_of_line ();
25177}
25178
69133863
MGD
25179/* Parse a .arch_extension directive. */
25180
25181static void
25182s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
25183{
25184 const struct arm_option_extension_value_table *opt;
25185 char saved_char;
25186 char *name;
25187 int adding_value = 1;
25188
25189 name = input_line_pointer;
25190 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
25191 input_line_pointer++;
25192 saved_char = *input_line_pointer;
25193 *input_line_pointer = 0;
25194
25195 if (strlen (name) >= 2
25196 && strncmp (name, "no", 2) == 0)
25197 {
25198 adding_value = 0;
25199 name += 2;
25200 }
25201
25202 for (opt = arm_extensions; opt->name != NULL; opt++)
25203 if (streq (opt->name, name))
25204 {
25205 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
25206 {
25207 as_bad (_("architectural extension `%s' is not allowed for the "
25208 "current base architecture"), name);
25209 break;
25210 }
25211
25212 if (adding_value)
25213 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
25214 else
25215 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
25216
25217 mcpu_cpu_opt = &selected_cpu;
25218 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
25219 *input_line_pointer = saved_char;
25220 demand_empty_rest_of_line ();
25221 return;
25222 }
25223
25224 if (opt->name == NULL)
e673710a 25225 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
25226
25227 *input_line_pointer = saved_char;
25228 ignore_rest_of_line ();
25229}
25230
ee065d83
PB
25231/* Parse a .fpu directive. */
25232
25233static void
25234s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
25235{
69133863 25236 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
25237 char saved_char;
25238 char *name;
25239
25240 name = input_line_pointer;
5f4273c7 25241 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
25242 input_line_pointer++;
25243 saved_char = *input_line_pointer;
25244 *input_line_pointer = 0;
5f4273c7 25245
ee065d83
PB
25246 for (opt = arm_fpus; opt->name != NULL; opt++)
25247 if (streq (opt->name, name))
25248 {
e74cfd16
PB
25249 mfpu_opt = &opt->value;
25250 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
25251 *input_line_pointer = saved_char;
25252 demand_empty_rest_of_line ();
25253 return;
25254 }
25255
25256 as_bad (_("unknown floating point format `%s'\n"), name);
25257 *input_line_pointer = saved_char;
25258 ignore_rest_of_line ();
25259}
ee065d83 25260
794ba86a 25261/* Copy symbol information. */
f31fef98 25262
794ba86a
DJ
25263void
25264arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
25265{
25266 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
25267}
e04befd0 25268
f31fef98 25269#ifdef OBJ_ELF
e04befd0
AS
25270/* Given a symbolic attribute NAME, return the proper integer value.
25271 Returns -1 if the attribute is not known. */
f31fef98 25272
e04befd0
AS
25273int
25274arm_convert_symbolic_attribute (const char *name)
25275{
f31fef98
NC
25276 static const struct
25277 {
25278 const char * name;
25279 const int tag;
25280 }
25281 attribute_table[] =
25282 {
25283 /* When you modify this table you should
25284 also modify the list in doc/c-arm.texi. */
e04befd0 25285#define T(tag) {#tag, tag}
f31fef98
NC
25286 T (Tag_CPU_raw_name),
25287 T (Tag_CPU_name),
25288 T (Tag_CPU_arch),
25289 T (Tag_CPU_arch_profile),
25290 T (Tag_ARM_ISA_use),
25291 T (Tag_THUMB_ISA_use),
75375b3e 25292 T (Tag_FP_arch),
f31fef98
NC
25293 T (Tag_VFP_arch),
25294 T (Tag_WMMX_arch),
25295 T (Tag_Advanced_SIMD_arch),
25296 T (Tag_PCS_config),
25297 T (Tag_ABI_PCS_R9_use),
25298 T (Tag_ABI_PCS_RW_data),
25299 T (Tag_ABI_PCS_RO_data),
25300 T (Tag_ABI_PCS_GOT_use),
25301 T (Tag_ABI_PCS_wchar_t),
25302 T (Tag_ABI_FP_rounding),
25303 T (Tag_ABI_FP_denormal),
25304 T (Tag_ABI_FP_exceptions),
25305 T (Tag_ABI_FP_user_exceptions),
25306 T (Tag_ABI_FP_number_model),
75375b3e 25307 T (Tag_ABI_align_needed),
f31fef98 25308 T (Tag_ABI_align8_needed),
75375b3e 25309 T (Tag_ABI_align_preserved),
f31fef98
NC
25310 T (Tag_ABI_align8_preserved),
25311 T (Tag_ABI_enum_size),
25312 T (Tag_ABI_HardFP_use),
25313 T (Tag_ABI_VFP_args),
25314 T (Tag_ABI_WMMX_args),
25315 T (Tag_ABI_optimization_goals),
25316 T (Tag_ABI_FP_optimization_goals),
25317 T (Tag_compatibility),
25318 T (Tag_CPU_unaligned_access),
75375b3e 25319 T (Tag_FP_HP_extension),
f31fef98
NC
25320 T (Tag_VFP_HP_extension),
25321 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
25322 T (Tag_MPextension_use),
25323 T (Tag_DIV_use),
f31fef98
NC
25324 T (Tag_nodefaults),
25325 T (Tag_also_compatible_with),
25326 T (Tag_conformance),
25327 T (Tag_T2EE_use),
25328 T (Tag_Virtualization_use),
cd21e546 25329 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 25330#undef T
f31fef98 25331 };
e04befd0
AS
25332 unsigned int i;
25333
25334 if (name == NULL)
25335 return -1;
25336
f31fef98 25337 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 25338 if (streq (name, attribute_table[i].name))
e04befd0
AS
25339 return attribute_table[i].tag;
25340
25341 return -1;
25342}
267bf995
RR
25343
25344
25345/* Apply sym value for relocations only in the case that
25346 they are for local symbols and you have the respective
25347 architectural feature for blx and simple switches. */
25348int
25349arm_apply_sym_value (struct fix * fixP)
25350{
25351 if (fixP->fx_addsy
25352 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
34e77a92 25353 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
25354 {
25355 switch (fixP->fx_r_type)
25356 {
25357 case BFD_RELOC_ARM_PCREL_BLX:
25358 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25359 if (ARM_IS_FUNC (fixP->fx_addsy))
25360 return 1;
25361 break;
25362
25363 case BFD_RELOC_ARM_PCREL_CALL:
25364 case BFD_RELOC_THUMB_PCREL_BLX:
25365 if (THUMB_IS_FUNC (fixP->fx_addsy))
25366 return 1;
25367 break;
25368
25369 default:
25370 break;
25371 }
25372
25373 }
25374 return 0;
25375}
f31fef98 25376#endif /* OBJ_ELF */