]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
* stack.c (return_command): Work around uninitialized variable
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
8ab8155f 3 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
b99bd4ef
NC
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
ec2655a6 15 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
b99bd4ef 27
42a68e18 28#include "as.h"
5287ad62 29#include <limits.h>
037e8744 30#include <stdarg.h>
c19d1205 31#define NO_RELOC 0
3882b010 32#include "safe-ctype.h"
b99bd4ef
NC
33#include "subsegs.h"
34#include "obstack.h"
3da1d841 35#include "libiberty.h"
f263249b
RE
36#include "opcode/arm.h"
37
b99bd4ef
NC
38#ifdef OBJ_ELF
39#include "elf/arm.h"
a394c00f 40#include "dw2gencfi.h"
b99bd4ef
NC
41#endif
42
f0927246
NC
43#include "dwarf2dbg.h"
44
7ed4c4c5
NC
45#ifdef OBJ_ELF
46/* Must be at least the size of the largest unwind opcode (currently two). */
47#define ARM_OPCODE_CHUNK_SIZE 8
48
49/* This structure holds the unwinding state. */
50
51static struct
52{
c19d1205
ZW
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
7ed4c4c5 57 /* The segment containing the function. */
c19d1205
ZW
58 segT saved_seg;
59 subsegT saved_subseg;
7ed4c4c5
NC
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
c19d1205
ZW
62 int opcode_count;
63 int opcode_alloc;
7ed4c4c5 64 /* The number of bytes pushed to the stack. */
c19d1205 65 offsetT frame_size;
7ed4c4c5
NC
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
c19d1205 69 offsetT pending_offset;
7ed4c4c5 70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
7ed4c4c5 74 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 75 unsigned fp_used:1;
7ed4c4c5 76 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 77 unsigned sp_restored:1;
7ed4c4c5
NC
78} unwind;
79
8b1ad454
NC
80#endif /* OBJ_ELF */
81
4962c51a
MS
82/* Results from operand parsing worker functions. */
83
84typedef enum
85{
86 PARSE_OPERAND_SUCCESS,
87 PARSE_OPERAND_FAIL,
88 PARSE_OPERAND_FAIL_NO_BACKTRACK
89} parse_operand_result;
90
33a392fb
PB
91enum arm_float_abi
92{
93 ARM_FLOAT_ABI_HARD,
94 ARM_FLOAT_ABI_SOFTFP,
95 ARM_FLOAT_ABI_SOFT
96};
97
c19d1205 98/* Types of processor to assemble for. */
b99bd4ef 99#ifndef CPU_DEFAULT
8a59fff3 100/* The code that was here used to select a default CPU depending on compiler
fa94de6b 101 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
102 changing gas' default behaviour depending upon the build host.
103
104 If you have a target that requires a default CPU option then the you
105 should define CPU_DEFAULT here. */
b99bd4ef
NC
106#endif
107
108#ifndef FPU_DEFAULT
c820d418
MM
109# ifdef TE_LINUX
110# define FPU_DEFAULT FPU_ARCH_FPA
111# elif defined (TE_NetBSD)
112# ifdef OBJ_ELF
113# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
114# else
115 /* Legacy a.out format. */
116# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
117# endif
4e7fd91e
PB
118# elif defined (TE_VXWORKS)
119# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
120# else
121 /* For backwards compatibility, default to FPA. */
122# define FPU_DEFAULT FPU_ARCH_FPA
123# endif
124#endif /* ifndef FPU_DEFAULT */
b99bd4ef 125
c19d1205 126#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 127
e74cfd16
PB
128static arm_feature_set cpu_variant;
129static arm_feature_set arm_arch_used;
130static arm_feature_set thumb_arch_used;
b99bd4ef 131
b99bd4ef 132/* Flags stored in private area of BFD structure. */
c19d1205
ZW
133static int uses_apcs_26 = FALSE;
134static int atpcs = FALSE;
b34976b6
AM
135static int support_interwork = FALSE;
136static int uses_apcs_float = FALSE;
c19d1205 137static int pic_code = FALSE;
845b51d6 138static int fix_v4bx = FALSE;
278df34e
NS
139/* Warn on using deprecated features. */
140static int warn_on_deprecated = TRUE;
141
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);
e74cfd16 243
33a392fb 244static int mfloat_abi_opt = -1;
e74cfd16
PB
245/* Record user cpu selection for object attributes. */
246static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
247/* Must be long enough to hold any of the names in arm_cpus. */
248static char selected_cpu_name[16];
8d67f500
NC
249
250/* Return if no cpu was selected on command-line. */
251static bfd_boolean
252no_cpu_selected (void)
253{
254 return selected_cpu.core == arm_arch_none.core
255 && selected_cpu.coproc == arm_arch_none.coproc;
256}
257
7cc69913 258#ifdef OBJ_ELF
deeaaff8
DJ
259# ifdef EABI_DEFAULT
260static int meabi_flags = EABI_DEFAULT;
261# else
d507cf36 262static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 263# endif
e1da3f5b 264
ee3c0378
AS
265static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
266
e1da3f5b 267bfd_boolean
5f4273c7 268arm_is_eabi (void)
e1da3f5b
PB
269{
270 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
271}
7cc69913 272#endif
b99bd4ef 273
b99bd4ef 274#ifdef OBJ_ELF
c19d1205 275/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
276symbolS * GOT_symbol;
277#endif
278
b99bd4ef
NC
279/* 0: assemble for ARM,
280 1: assemble for Thumb,
281 2: assemble for Thumb even though target CPU does not support thumb
282 instructions. */
283static int thumb_mode = 0;
8dc2430f
NC
284/* A value distinct from the possible values for thumb_mode that we
285 can use to record whether thumb_mode has been copied into the
286 tc_frag_data field of a frag. */
287#define MODE_RECORDED (1 << 4)
b99bd4ef 288
e07e6e58
NC
289/* Specifies the intrinsic IT insn behavior mode. */
290enum implicit_it_mode
291{
292 IMPLICIT_IT_MODE_NEVER = 0x00,
293 IMPLICIT_IT_MODE_ARM = 0x01,
294 IMPLICIT_IT_MODE_THUMB = 0x02,
295 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
296};
297static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
298
c19d1205
ZW
299/* If unified_syntax is true, we are processing the new unified
300 ARM/Thumb syntax. Important differences from the old ARM mode:
301
302 - Immediate operands do not require a # prefix.
303 - Conditional affixes always appear at the end of the
304 instruction. (For backward compatibility, those instructions
305 that formerly had them in the middle, continue to accept them
306 there.)
307 - The IT instruction may appear, and if it does is validated
308 against subsequent conditional affixes. It does not generate
309 machine code.
310
311 Important differences from the old Thumb mode:
312
313 - Immediate operands do not require a # prefix.
314 - Most of the V6T2 instructions are only available in unified mode.
315 - The .N and .W suffixes are recognized and honored (it is an error
316 if they cannot be honored).
317 - All instructions set the flags if and only if they have an 's' affix.
318 - Conditional affixes may be used. They are validated against
319 preceding IT instructions. Unlike ARM mode, you cannot use a
320 conditional affix except in the scope of an IT instruction. */
321
322static bfd_boolean unified_syntax = FALSE;
b99bd4ef 323
bacebabc
RM
324/* An immediate operand can start with #, and ld*, st*, pld operands
325 can contain [ and ]. We need to tell APP not to elide whitespace
326 before a [, which can appear as the first operand for pld. */
327const char arm_symbol_chars[] = "#[]";
328
5287ad62
JB
329enum neon_el_type
330{
dcbf9037 331 NT_invtype,
5287ad62
JB
332 NT_untyped,
333 NT_integer,
334 NT_float,
335 NT_poly,
336 NT_signed,
dcbf9037 337 NT_unsigned
5287ad62
JB
338};
339
340struct neon_type_el
341{
342 enum neon_el_type type;
343 unsigned size;
344};
345
346#define NEON_MAX_TYPE_ELS 4
347
348struct neon_type
349{
350 struct neon_type_el el[NEON_MAX_TYPE_ELS];
351 unsigned elems;
352};
353
e07e6e58
NC
354enum it_instruction_type
355{
356 OUTSIDE_IT_INSN,
357 INSIDE_IT_INSN,
358 INSIDE_IT_LAST_INSN,
359 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
360 if inside, should be the last one. */
361 NEUTRAL_IT_INSN, /* This could be either inside or outside,
362 i.e. BKPT and NOP. */
363 IT_INSN /* The IT insn has been parsed. */
364};
365
ad6cec43
MGD
366/* The maximum number of operands we need. */
367#define ARM_IT_MAX_OPERANDS 6
368
b99bd4ef
NC
369struct arm_it
370{
c19d1205 371 const char * error;
b99bd4ef 372 unsigned long instruction;
c19d1205
ZW
373 int size;
374 int size_req;
375 int cond;
037e8744
JB
376 /* "uncond_value" is set to the value in place of the conditional field in
377 unconditional versions of the instruction, or -1 if nothing is
378 appropriate. */
379 int uncond_value;
5287ad62 380 struct neon_type vectype;
88714cb8
DG
381 /* This does not indicate an actual NEON instruction, only that
382 the mnemonic accepts neon-style type suffixes. */
383 int is_neon;
0110f2b8
PB
384 /* Set to the opcode if the instruction needs relaxation.
385 Zero if the instruction is not relaxed. */
386 unsigned long relax;
b99bd4ef
NC
387 struct
388 {
389 bfd_reloc_code_real_type type;
c19d1205
ZW
390 expressionS exp;
391 int pc_rel;
b99bd4ef 392 } reloc;
b99bd4ef 393
e07e6e58
NC
394 enum it_instruction_type it_insn_type;
395
c19d1205
ZW
396 struct
397 {
398 unsigned reg;
ca3f61f7 399 signed int imm;
dcbf9037 400 struct neon_type_el vectype;
ca3f61f7
NC
401 unsigned present : 1; /* Operand present. */
402 unsigned isreg : 1; /* Operand was a register. */
403 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
404 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
405 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 406 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
407 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
408 instructions. This allows us to disambiguate ARM <-> vector insns. */
409 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 410 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 411 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 412 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
413 unsigned hasreloc : 1; /* Operand has relocation suffix. */
414 unsigned writeback : 1; /* Operand has trailing ! */
415 unsigned preind : 1; /* Preindexed address. */
416 unsigned postind : 1; /* Postindexed address. */
417 unsigned negative : 1; /* Index register was negated. */
418 unsigned shifted : 1; /* Shift applied to operation. */
419 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 420 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
421};
422
c19d1205 423static struct arm_it inst;
b99bd4ef
NC
424
425#define NUM_FLOAT_VALS 8
426
05d2d07e 427const char * fp_const[] =
b99bd4ef
NC
428{
429 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
430};
431
c19d1205 432/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
433#define MAX_LITTLENUMS 6
434
435LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
436
437#define FAIL (-1)
438#define SUCCESS (0)
439
440#define SUFF_S 1
441#define SUFF_D 2
442#define SUFF_E 3
443#define SUFF_P 4
444
c19d1205
ZW
445#define CP_T_X 0x00008000
446#define CP_T_Y 0x00400000
b99bd4ef 447
c19d1205
ZW
448#define CONDS_BIT 0x00100000
449#define LOAD_BIT 0x00100000
b99bd4ef
NC
450
451#define DOUBLE_LOAD_FLAG 0x00000001
452
453struct asm_cond
454{
d3ce72d0 455 const char * template_name;
c921be7d 456 unsigned long value;
b99bd4ef
NC
457};
458
c19d1205 459#define COND_ALWAYS 0xE
b99bd4ef 460
b99bd4ef
NC
461struct asm_psr
462{
d3ce72d0 463 const char * template_name;
c921be7d 464 unsigned long field;
b99bd4ef
NC
465};
466
62b3e311
PB
467struct asm_barrier_opt
468{
e797f7e0
MGD
469 const char * template_name;
470 unsigned long value;
471 const arm_feature_set arch;
62b3e311
PB
472};
473
2d2255b5 474/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
475#define SPSR_BIT (1 << 22)
476
c19d1205
ZW
477/* The individual PSR flag bits. */
478#define PSR_c (1 << 16)
479#define PSR_x (1 << 17)
480#define PSR_s (1 << 18)
481#define PSR_f (1 << 19)
b99bd4ef 482
c19d1205 483struct reloc_entry
bfae80f2 484{
c921be7d
NC
485 char * name;
486 bfd_reloc_code_real_type reloc;
bfae80f2
RE
487};
488
5287ad62 489enum vfp_reg_pos
bfae80f2 490{
5287ad62
JB
491 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
492 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
493};
494
495enum vfp_ldstm_type
496{
497 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
498};
499
dcbf9037
JB
500/* Bits for DEFINED field in neon_typed_alias. */
501#define NTA_HASTYPE 1
502#define NTA_HASINDEX 2
503
504struct neon_typed_alias
505{
c921be7d
NC
506 unsigned char defined;
507 unsigned char index;
508 struct neon_type_el eltype;
dcbf9037
JB
509};
510
c19d1205
ZW
511/* ARM register categories. This includes coprocessor numbers and various
512 architecture extensions' registers. */
513enum arm_reg_type
bfae80f2 514{
c19d1205
ZW
515 REG_TYPE_RN,
516 REG_TYPE_CP,
517 REG_TYPE_CN,
518 REG_TYPE_FN,
519 REG_TYPE_VFS,
520 REG_TYPE_VFD,
5287ad62 521 REG_TYPE_NQ,
037e8744 522 REG_TYPE_VFSD,
5287ad62 523 REG_TYPE_NDQ,
037e8744 524 REG_TYPE_NSDQ,
c19d1205
ZW
525 REG_TYPE_VFC,
526 REG_TYPE_MVF,
527 REG_TYPE_MVD,
528 REG_TYPE_MVFX,
529 REG_TYPE_MVDX,
530 REG_TYPE_MVAX,
531 REG_TYPE_DSPSC,
532 REG_TYPE_MMXWR,
533 REG_TYPE_MMXWC,
534 REG_TYPE_MMXWCG,
535 REG_TYPE_XSCALE,
90ec0d68 536 REG_TYPE_RNB
bfae80f2
RE
537};
538
dcbf9037
JB
539/* Structure for a hash table entry for a register.
540 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
541 information which states whether a vector type or index is specified (for a
542 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
543struct reg_entry
544{
c921be7d 545 const char * name;
90ec0d68 546 unsigned int number;
c921be7d
NC
547 unsigned char type;
548 unsigned char builtin;
549 struct neon_typed_alias * neon;
6c43fab6
RE
550};
551
c19d1205 552/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 553const char * const reg_expected_msgs[] =
c19d1205
ZW
554{
555 N_("ARM register expected"),
556 N_("bad or missing co-processor number"),
557 N_("co-processor register expected"),
558 N_("FPA register expected"),
559 N_("VFP single precision register expected"),
5287ad62
JB
560 N_("VFP/Neon double precision register expected"),
561 N_("Neon quad precision register expected"),
037e8744 562 N_("VFP single or double precision register expected"),
5287ad62 563 N_("Neon double or quad precision register expected"),
037e8744 564 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
565 N_("VFP system register expected"),
566 N_("Maverick MVF register expected"),
567 N_("Maverick MVD register expected"),
568 N_("Maverick MVFX register expected"),
569 N_("Maverick MVDX register expected"),
570 N_("Maverick MVAX register expected"),
571 N_("Maverick DSPSC register expected"),
572 N_("iWMMXt data register expected"),
573 N_("iWMMXt control register expected"),
574 N_("iWMMXt scalar register expected"),
575 N_("XScale accumulator register expected"),
6c43fab6
RE
576};
577
c19d1205 578/* Some well known registers that we refer to directly elsewhere. */
bd340a04 579#define REG_R12 12
c19d1205
ZW
580#define REG_SP 13
581#define REG_LR 14
582#define REG_PC 15
404ff6b5 583
b99bd4ef
NC
584/* ARM instructions take 4bytes in the object file, Thumb instructions
585 take 2: */
c19d1205 586#define INSN_SIZE 4
b99bd4ef
NC
587
588struct asm_opcode
589{
590 /* Basic string to match. */
d3ce72d0 591 const char * template_name;
c19d1205
ZW
592
593 /* Parameters to instruction. */
5be8be5d 594 unsigned int operands[8];
c19d1205
ZW
595
596 /* Conditional tag - see opcode_lookup. */
597 unsigned int tag : 4;
b99bd4ef
NC
598
599 /* Basic instruction code. */
c19d1205 600 unsigned int avalue : 28;
b99bd4ef 601
c19d1205
ZW
602 /* Thumb-format instruction code. */
603 unsigned int tvalue;
b99bd4ef 604
90e4755a 605 /* Which architecture variant provides this instruction. */
c921be7d
NC
606 const arm_feature_set * avariant;
607 const arm_feature_set * tvariant;
c19d1205
ZW
608
609 /* Function to call to encode instruction in ARM format. */
610 void (* aencode) (void);
b99bd4ef 611
c19d1205
ZW
612 /* Function to call to encode instruction in Thumb format. */
613 void (* tencode) (void);
b99bd4ef
NC
614};
615
a737bd4d
NC
616/* Defines for various bits that we will want to toggle. */
617#define INST_IMMEDIATE 0x02000000
618#define OFFSET_REG 0x02000000
c19d1205 619#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
620#define SHIFT_BY_REG 0x00000010
621#define PRE_INDEX 0x01000000
622#define INDEX_UP 0x00800000
623#define WRITE_BACK 0x00200000
624#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 625#define CPSI_MMOD 0x00020000
90e4755a 626
a737bd4d
NC
627#define LITERAL_MASK 0xf000f000
628#define OPCODE_MASK 0xfe1fffff
629#define V4_STR_BIT 0x00000020
90e4755a 630
efd81785
PB
631#define T2_SUBS_PC_LR 0xf3de8f00
632
a737bd4d 633#define DATA_OP_SHIFT 21
90e4755a 634
ef8d22e6
PB
635#define T2_OPCODE_MASK 0xfe1fffff
636#define T2_DATA_OP_SHIFT 21
637
6530b175
NC
638#define A_COND_MASK 0xf0000000
639#define A_PUSH_POP_OP_MASK 0x0fff0000
640
641/* Opcodes for pushing/poping registers to/from the stack. */
642#define A1_OPCODE_PUSH 0x092d0000
643#define A2_OPCODE_PUSH 0x052d0004
644#define A2_OPCODE_POP 0x049d0004
645
a737bd4d
NC
646/* Codes to distinguish the arithmetic instructions. */
647#define OPCODE_AND 0
648#define OPCODE_EOR 1
649#define OPCODE_SUB 2
650#define OPCODE_RSB 3
651#define OPCODE_ADD 4
652#define OPCODE_ADC 5
653#define OPCODE_SBC 6
654#define OPCODE_RSC 7
655#define OPCODE_TST 8
656#define OPCODE_TEQ 9
657#define OPCODE_CMP 10
658#define OPCODE_CMN 11
659#define OPCODE_ORR 12
660#define OPCODE_MOV 13
661#define OPCODE_BIC 14
662#define OPCODE_MVN 15
90e4755a 663
ef8d22e6
PB
664#define T2_OPCODE_AND 0
665#define T2_OPCODE_BIC 1
666#define T2_OPCODE_ORR 2
667#define T2_OPCODE_ORN 3
668#define T2_OPCODE_EOR 4
669#define T2_OPCODE_ADD 8
670#define T2_OPCODE_ADC 10
671#define T2_OPCODE_SBC 11
672#define T2_OPCODE_SUB 13
673#define T2_OPCODE_RSB 14
674
a737bd4d
NC
675#define T_OPCODE_MUL 0x4340
676#define T_OPCODE_TST 0x4200
677#define T_OPCODE_CMN 0x42c0
678#define T_OPCODE_NEG 0x4240
679#define T_OPCODE_MVN 0x43c0
90e4755a 680
a737bd4d
NC
681#define T_OPCODE_ADD_R3 0x1800
682#define T_OPCODE_SUB_R3 0x1a00
683#define T_OPCODE_ADD_HI 0x4400
684#define T_OPCODE_ADD_ST 0xb000
685#define T_OPCODE_SUB_ST 0xb080
686#define T_OPCODE_ADD_SP 0xa800
687#define T_OPCODE_ADD_PC 0xa000
688#define T_OPCODE_ADD_I8 0x3000
689#define T_OPCODE_SUB_I8 0x3800
690#define T_OPCODE_ADD_I3 0x1c00
691#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 692
a737bd4d
NC
693#define T_OPCODE_ASR_R 0x4100
694#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
695#define T_OPCODE_LSR_R 0x40c0
696#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
697#define T_OPCODE_ASR_I 0x1000
698#define T_OPCODE_LSL_I 0x0000
699#define T_OPCODE_LSR_I 0x0800
b99bd4ef 700
a737bd4d
NC
701#define T_OPCODE_MOV_I8 0x2000
702#define T_OPCODE_CMP_I8 0x2800
703#define T_OPCODE_CMP_LR 0x4280
704#define T_OPCODE_MOV_HR 0x4600
705#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 706
a737bd4d
NC
707#define T_OPCODE_LDR_PC 0x4800
708#define T_OPCODE_LDR_SP 0x9800
709#define T_OPCODE_STR_SP 0x9000
710#define T_OPCODE_LDR_IW 0x6800
711#define T_OPCODE_STR_IW 0x6000
712#define T_OPCODE_LDR_IH 0x8800
713#define T_OPCODE_STR_IH 0x8000
714#define T_OPCODE_LDR_IB 0x7800
715#define T_OPCODE_STR_IB 0x7000
716#define T_OPCODE_LDR_RW 0x5800
717#define T_OPCODE_STR_RW 0x5000
718#define T_OPCODE_LDR_RH 0x5a00
719#define T_OPCODE_STR_RH 0x5200
720#define T_OPCODE_LDR_RB 0x5c00
721#define T_OPCODE_STR_RB 0x5400
c9b604bd 722
a737bd4d
NC
723#define T_OPCODE_PUSH 0xb400
724#define T_OPCODE_POP 0xbc00
b99bd4ef 725
2fc8bdac 726#define T_OPCODE_BRANCH 0xe000
b99bd4ef 727
a737bd4d 728#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 729#define THUMB_PP_PC_LR 0x0100
c19d1205 730#define THUMB_LOAD_BIT 0x0800
53365c0d 731#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
732
733#define BAD_ARGS _("bad arguments to instruction")
fdfde340 734#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
735#define BAD_PC _("r15 not allowed here")
736#define BAD_COND _("instruction cannot be conditional")
737#define BAD_OVERLAP _("registers may not be the same")
738#define BAD_HIREG _("lo register required")
739#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 740#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
741#define BAD_BRANCH _("branch must be last instruction in IT block")
742#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 743#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
744#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
745#define BAD_IT_COND _("incorrect condition in IT block")
746#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 747#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
748#define BAD_PC_ADDRESSING \
749 _("cannot use register index with PC-relative addressing")
750#define BAD_PC_WRITEBACK \
751 _("cannot use writeback with PC-relative addressing")
08f10d51 752#define BAD_RANGE _("branch out of range")
c19d1205 753
c921be7d
NC
754static struct hash_control * arm_ops_hsh;
755static struct hash_control * arm_cond_hsh;
756static struct hash_control * arm_shift_hsh;
757static struct hash_control * arm_psr_hsh;
758static struct hash_control * arm_v7m_psr_hsh;
759static struct hash_control * arm_reg_hsh;
760static struct hash_control * arm_reloc_hsh;
761static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 762
b99bd4ef
NC
763/* Stuff needed to resolve the label ambiguity
764 As:
765 ...
766 label: <insn>
767 may differ from:
768 ...
769 label:
5f4273c7 770 <insn> */
b99bd4ef
NC
771
772symbolS * last_label_seen;
b34976b6 773static int label_is_thumb_function_name = FALSE;
e07e6e58 774
3d0c9500
NC
775/* Literal pool structure. Held on a per-section
776 and per-sub-section basis. */
a737bd4d 777
c19d1205 778#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 779typedef struct literal_pool
b99bd4ef 780{
c921be7d
NC
781 expressionS literals [MAX_LITERAL_POOL_SIZE];
782 unsigned int next_free_entry;
783 unsigned int id;
784 symbolS * symbol;
785 segT section;
786 subsegT sub_section;
a8040cf2
NC
787#ifdef OBJ_ELF
788 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
789#endif
c921be7d 790 struct literal_pool * next;
3d0c9500 791} literal_pool;
b99bd4ef 792
3d0c9500
NC
793/* Pointer to a linked list of literal pools. */
794literal_pool * list_of_pools = NULL;
e27ec89e 795
e07e6e58
NC
796#ifdef OBJ_ELF
797# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
798#else
799static struct current_it now_it;
800#endif
801
802static inline int
803now_it_compatible (int cond)
804{
805 return (cond & ~1) == (now_it.cc & ~1);
806}
807
808static inline int
809conditional_insn (void)
810{
811 return inst.cond != COND_ALWAYS;
812}
813
814static int in_it_block (void);
815
816static int handle_it_state (void);
817
818static void force_automatic_it_block_close (void);
819
c921be7d
NC
820static void it_fsm_post_encode (void);
821
e07e6e58
NC
822#define set_it_insn_type(type) \
823 do \
824 { \
825 inst.it_insn_type = type; \
826 if (handle_it_state () == FAIL) \
827 return; \
828 } \
829 while (0)
830
c921be7d
NC
831#define set_it_insn_type_nonvoid(type, failret) \
832 do \
833 { \
834 inst.it_insn_type = type; \
835 if (handle_it_state () == FAIL) \
836 return failret; \
837 } \
838 while(0)
839
e07e6e58
NC
840#define set_it_insn_type_last() \
841 do \
842 { \
843 if (inst.cond == COND_ALWAYS) \
844 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
845 else \
846 set_it_insn_type (INSIDE_IT_LAST_INSN); \
847 } \
848 while (0)
849
c19d1205 850/* Pure syntax. */
b99bd4ef 851
c19d1205
ZW
852/* This array holds the chars that always start a comment. If the
853 pre-processor is disabled, these aren't very useful. */
854const char comment_chars[] = "@";
3d0c9500 855
c19d1205
ZW
856/* This array holds the chars that only start a comment at the beginning of
857 a line. If the line seems to have the form '# 123 filename'
858 .line and .file directives will appear in the pre-processed output. */
859/* Note that input_file.c hand checks for '#' at the beginning of the
860 first line of the input file. This is because the compiler outputs
861 #NO_APP at the beginning of its output. */
862/* Also note that comments like this one will always work. */
863const char line_comment_chars[] = "#";
3d0c9500 864
c19d1205 865const char line_separator_chars[] = ";";
b99bd4ef 866
c19d1205
ZW
867/* Chars that can be used to separate mant
868 from exp in floating point numbers. */
869const char EXP_CHARS[] = "eE";
3d0c9500 870
c19d1205
ZW
871/* Chars that mean this number is a floating point constant. */
872/* As in 0f12.456 */
873/* or 0d1.2345e12 */
b99bd4ef 874
c19d1205 875const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 876
c19d1205
ZW
877/* Prefix characters that indicate the start of an immediate
878 value. */
879#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 880
c19d1205
ZW
881/* Separator character handling. */
882
883#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
884
885static inline int
886skip_past_char (char ** str, char c)
887{
8ab8155f
NC
888 /* PR gas/14987: Allow for whitespace before the expected character. */
889 skip_whitespace (*str);
427d0db6 890
c19d1205
ZW
891 if (**str == c)
892 {
893 (*str)++;
894 return SUCCESS;
3d0c9500 895 }
c19d1205
ZW
896 else
897 return FAIL;
898}
c921be7d 899
c19d1205 900#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 901
c19d1205
ZW
902/* Arithmetic expressions (possibly involving symbols). */
903
904/* Return TRUE if anything in the expression is a bignum. */
905
906static int
907walk_no_bignums (symbolS * sp)
908{
909 if (symbol_get_value_expression (sp)->X_op == O_big)
910 return 1;
911
912 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 913 {
c19d1205
ZW
914 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
915 || (symbol_get_value_expression (sp)->X_op_symbol
916 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
917 }
918
c19d1205 919 return 0;
3d0c9500
NC
920}
921
c19d1205
ZW
922static int in_my_get_expression = 0;
923
924/* Third argument to my_get_expression. */
925#define GE_NO_PREFIX 0
926#define GE_IMM_PREFIX 1
927#define GE_OPT_PREFIX 2
5287ad62
JB
928/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
929 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
930#define GE_OPT_PREFIX_BIG 3
a737bd4d 931
b99bd4ef 932static int
c19d1205 933my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 934{
c19d1205
ZW
935 char * save_in;
936 segT seg;
b99bd4ef 937
c19d1205
ZW
938 /* In unified syntax, all prefixes are optional. */
939 if (unified_syntax)
5287ad62
JB
940 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
941 : GE_OPT_PREFIX;
b99bd4ef 942
c19d1205 943 switch (prefix_mode)
b99bd4ef 944 {
c19d1205
ZW
945 case GE_NO_PREFIX: break;
946 case GE_IMM_PREFIX:
947 if (!is_immediate_prefix (**str))
948 {
949 inst.error = _("immediate expression requires a # prefix");
950 return FAIL;
951 }
952 (*str)++;
953 break;
954 case GE_OPT_PREFIX:
5287ad62 955 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
956 if (is_immediate_prefix (**str))
957 (*str)++;
958 break;
959 default: abort ();
960 }
b99bd4ef 961
c19d1205 962 memset (ep, 0, sizeof (expressionS));
b99bd4ef 963
c19d1205
ZW
964 save_in = input_line_pointer;
965 input_line_pointer = *str;
966 in_my_get_expression = 1;
967 seg = expression (ep);
968 in_my_get_expression = 0;
969
f86adc07 970 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 971 {
f86adc07 972 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
973 *str = input_line_pointer;
974 input_line_pointer = save_in;
975 if (inst.error == NULL)
f86adc07
NS
976 inst.error = (ep->X_op == O_absent
977 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
978 return 1;
979 }
b99bd4ef 980
c19d1205
ZW
981#ifdef OBJ_AOUT
982 if (seg != absolute_section
983 && seg != text_section
984 && seg != data_section
985 && seg != bss_section
986 && seg != undefined_section)
987 {
988 inst.error = _("bad segment");
989 *str = input_line_pointer;
990 input_line_pointer = save_in;
991 return 1;
b99bd4ef 992 }
87975d2a
AM
993#else
994 (void) seg;
c19d1205 995#endif
b99bd4ef 996
c19d1205
ZW
997 /* Get rid of any bignums now, so that we don't generate an error for which
998 we can't establish a line number later on. Big numbers are never valid
999 in instructions, which is where this routine is always called. */
5287ad62
JB
1000 if (prefix_mode != GE_OPT_PREFIX_BIG
1001 && (ep->X_op == O_big
1002 || (ep->X_add_symbol
1003 && (walk_no_bignums (ep->X_add_symbol)
1004 || (ep->X_op_symbol
1005 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1006 {
1007 inst.error = _("invalid constant");
1008 *str = input_line_pointer;
1009 input_line_pointer = save_in;
1010 return 1;
1011 }
b99bd4ef 1012
c19d1205
ZW
1013 *str = input_line_pointer;
1014 input_line_pointer = save_in;
1015 return 0;
b99bd4ef
NC
1016}
1017
c19d1205
ZW
1018/* Turn a string in input_line_pointer into a floating point constant
1019 of type TYPE, and store the appropriate bytes in *LITP. The number
1020 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1021 returned, or NULL on OK.
b99bd4ef 1022
c19d1205
ZW
1023 Note that fp constants aren't represent in the normal way on the ARM.
1024 In big endian mode, things are as expected. However, in little endian
1025 mode fp constants are big-endian word-wise, and little-endian byte-wise
1026 within the words. For example, (double) 1.1 in big endian mode is
1027 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1028 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1029
c19d1205 1030 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1031
c19d1205
ZW
1032char *
1033md_atof (int type, char * litP, int * sizeP)
1034{
1035 int prec;
1036 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1037 char *t;
1038 int i;
b99bd4ef 1039
c19d1205
ZW
1040 switch (type)
1041 {
1042 case 'f':
1043 case 'F':
1044 case 's':
1045 case 'S':
1046 prec = 2;
1047 break;
b99bd4ef 1048
c19d1205
ZW
1049 case 'd':
1050 case 'D':
1051 case 'r':
1052 case 'R':
1053 prec = 4;
1054 break;
b99bd4ef 1055
c19d1205
ZW
1056 case 'x':
1057 case 'X':
499ac353 1058 prec = 5;
c19d1205 1059 break;
b99bd4ef 1060
c19d1205
ZW
1061 case 'p':
1062 case 'P':
499ac353 1063 prec = 5;
c19d1205 1064 break;
a737bd4d 1065
c19d1205
ZW
1066 default:
1067 *sizeP = 0;
499ac353 1068 return _("Unrecognized or unsupported floating point constant");
c19d1205 1069 }
b99bd4ef 1070
c19d1205
ZW
1071 t = atof_ieee (input_line_pointer, type, words);
1072 if (t)
1073 input_line_pointer = t;
499ac353 1074 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1075
c19d1205
ZW
1076 if (target_big_endian)
1077 {
1078 for (i = 0; i < prec; i++)
1079 {
499ac353
NC
1080 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1081 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1082 }
1083 }
1084 else
1085 {
e74cfd16 1086 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1087 for (i = prec - 1; i >= 0; i--)
1088 {
499ac353
NC
1089 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1090 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1091 }
1092 else
1093 /* For a 4 byte float the order of elements in `words' is 1 0.
1094 For an 8 byte float the order is 1 0 3 2. */
1095 for (i = 0; i < prec; i += 2)
1096 {
499ac353
NC
1097 md_number_to_chars (litP, (valueT) words[i + 1],
1098 sizeof (LITTLENUM_TYPE));
1099 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1100 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1101 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1102 }
1103 }
b99bd4ef 1104
499ac353 1105 return NULL;
c19d1205 1106}
b99bd4ef 1107
c19d1205
ZW
1108/* We handle all bad expressions here, so that we can report the faulty
1109 instruction in the error message. */
1110void
91d6fa6a 1111md_operand (expressionS * exp)
c19d1205
ZW
1112{
1113 if (in_my_get_expression)
91d6fa6a 1114 exp->X_op = O_illegal;
b99bd4ef
NC
1115}
1116
c19d1205 1117/* Immediate values. */
b99bd4ef 1118
c19d1205
ZW
1119/* Generic immediate-value read function for use in directives.
1120 Accepts anything that 'expression' can fold to a constant.
1121 *val receives the number. */
1122#ifdef OBJ_ELF
1123static int
1124immediate_for_directive (int *val)
b99bd4ef 1125{
c19d1205
ZW
1126 expressionS exp;
1127 exp.X_op = O_illegal;
b99bd4ef 1128
c19d1205
ZW
1129 if (is_immediate_prefix (*input_line_pointer))
1130 {
1131 input_line_pointer++;
1132 expression (&exp);
1133 }
b99bd4ef 1134
c19d1205
ZW
1135 if (exp.X_op != O_constant)
1136 {
1137 as_bad (_("expected #constant"));
1138 ignore_rest_of_line ();
1139 return FAIL;
1140 }
1141 *val = exp.X_add_number;
1142 return SUCCESS;
b99bd4ef 1143}
c19d1205 1144#endif
b99bd4ef 1145
c19d1205 1146/* Register parsing. */
b99bd4ef 1147
c19d1205
ZW
1148/* Generic register parser. CCP points to what should be the
1149 beginning of a register name. If it is indeed a valid register
1150 name, advance CCP over it and return the reg_entry structure;
1151 otherwise return NULL. Does not issue diagnostics. */
1152
1153static struct reg_entry *
1154arm_reg_parse_multi (char **ccp)
b99bd4ef 1155{
c19d1205
ZW
1156 char *start = *ccp;
1157 char *p;
1158 struct reg_entry *reg;
b99bd4ef 1159
c19d1205
ZW
1160#ifdef REGISTER_PREFIX
1161 if (*start != REGISTER_PREFIX)
01cfc07f 1162 return NULL;
c19d1205
ZW
1163 start++;
1164#endif
1165#ifdef OPTIONAL_REGISTER_PREFIX
1166 if (*start == OPTIONAL_REGISTER_PREFIX)
1167 start++;
1168#endif
b99bd4ef 1169
c19d1205
ZW
1170 p = start;
1171 if (!ISALPHA (*p) || !is_name_beginner (*p))
1172 return NULL;
b99bd4ef 1173
c19d1205
ZW
1174 do
1175 p++;
1176 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1177
1178 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1179
1180 if (!reg)
1181 return NULL;
1182
1183 *ccp = p;
1184 return reg;
b99bd4ef
NC
1185}
1186
1187static int
dcbf9037
JB
1188arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1189 enum arm_reg_type type)
b99bd4ef 1190{
c19d1205
ZW
1191 /* Alternative syntaxes are accepted for a few register classes. */
1192 switch (type)
1193 {
1194 case REG_TYPE_MVF:
1195 case REG_TYPE_MVD:
1196 case REG_TYPE_MVFX:
1197 case REG_TYPE_MVDX:
1198 /* Generic coprocessor register names are allowed for these. */
79134647 1199 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1200 return reg->number;
1201 break;
69b97547 1202
c19d1205
ZW
1203 case REG_TYPE_CP:
1204 /* For backward compatibility, a bare number is valid here. */
1205 {
1206 unsigned long processor = strtoul (start, ccp, 10);
1207 if (*ccp != start && processor <= 15)
1208 return processor;
1209 }
6057a28f 1210
c19d1205
ZW
1211 case REG_TYPE_MMXWC:
1212 /* WC includes WCG. ??? I'm not sure this is true for all
1213 instructions that take WC registers. */
79134647 1214 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1215 return reg->number;
6057a28f 1216 break;
c19d1205 1217
6057a28f 1218 default:
c19d1205 1219 break;
6057a28f
NC
1220 }
1221
dcbf9037
JB
1222 return FAIL;
1223}
1224
1225/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1226 return value is the register number or FAIL. */
1227
1228static int
1229arm_reg_parse (char **ccp, enum arm_reg_type type)
1230{
1231 char *start = *ccp;
1232 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1233 int ret;
1234
1235 /* Do not allow a scalar (reg+index) to parse as a register. */
1236 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1237 return FAIL;
1238
1239 if (reg && reg->type == type)
1240 return reg->number;
1241
1242 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1243 return ret;
1244
c19d1205
ZW
1245 *ccp = start;
1246 return FAIL;
1247}
69b97547 1248
dcbf9037
JB
1249/* Parse a Neon type specifier. *STR should point at the leading '.'
1250 character. Does no verification at this stage that the type fits the opcode
1251 properly. E.g.,
1252
1253 .i32.i32.s16
1254 .s32.f32
1255 .u16
1256
1257 Can all be legally parsed by this function.
1258
1259 Fills in neon_type struct pointer with parsed information, and updates STR
1260 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1261 type, FAIL if not. */
1262
1263static int
1264parse_neon_type (struct neon_type *type, char **str)
1265{
1266 char *ptr = *str;
1267
1268 if (type)
1269 type->elems = 0;
1270
1271 while (type->elems < NEON_MAX_TYPE_ELS)
1272 {
1273 enum neon_el_type thistype = NT_untyped;
1274 unsigned thissize = -1u;
1275
1276 if (*ptr != '.')
1277 break;
1278
1279 ptr++;
1280
1281 /* Just a size without an explicit type. */
1282 if (ISDIGIT (*ptr))
1283 goto parsesize;
1284
1285 switch (TOLOWER (*ptr))
1286 {
1287 case 'i': thistype = NT_integer; break;
1288 case 'f': thistype = NT_float; break;
1289 case 'p': thistype = NT_poly; break;
1290 case 's': thistype = NT_signed; break;
1291 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1292 case 'd':
1293 thistype = NT_float;
1294 thissize = 64;
1295 ptr++;
1296 goto done;
dcbf9037
JB
1297 default:
1298 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1299 return FAIL;
1300 }
1301
1302 ptr++;
1303
1304 /* .f is an abbreviation for .f32. */
1305 if (thistype == NT_float && !ISDIGIT (*ptr))
1306 thissize = 32;
1307 else
1308 {
1309 parsesize:
1310 thissize = strtoul (ptr, &ptr, 10);
1311
1312 if (thissize != 8 && thissize != 16 && thissize != 32
1313 && thissize != 64)
1314 {
1315 as_bad (_("bad size %d in type specifier"), thissize);
1316 return FAIL;
1317 }
1318 }
1319
037e8744 1320 done:
dcbf9037
JB
1321 if (type)
1322 {
1323 type->el[type->elems].type = thistype;
1324 type->el[type->elems].size = thissize;
1325 type->elems++;
1326 }
1327 }
1328
1329 /* Empty/missing type is not a successful parse. */
1330 if (type->elems == 0)
1331 return FAIL;
1332
1333 *str = ptr;
1334
1335 return SUCCESS;
1336}
1337
1338/* Errors may be set multiple times during parsing or bit encoding
1339 (particularly in the Neon bits), but usually the earliest error which is set
1340 will be the most meaningful. Avoid overwriting it with later (cascading)
1341 errors by calling this function. */
1342
1343static void
1344first_error (const char *err)
1345{
1346 if (!inst.error)
1347 inst.error = err;
1348}
1349
1350/* Parse a single type, e.g. ".s32", leading period included. */
1351static int
1352parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1353{
1354 char *str = *ccp;
1355 struct neon_type optype;
1356
1357 if (*str == '.')
1358 {
1359 if (parse_neon_type (&optype, &str) == SUCCESS)
1360 {
1361 if (optype.elems == 1)
1362 *vectype = optype.el[0];
1363 else
1364 {
1365 first_error (_("only one type should be specified for operand"));
1366 return FAIL;
1367 }
1368 }
1369 else
1370 {
1371 first_error (_("vector type expected"));
1372 return FAIL;
1373 }
1374 }
1375 else
1376 return FAIL;
5f4273c7 1377
dcbf9037 1378 *ccp = str;
5f4273c7 1379
dcbf9037
JB
1380 return SUCCESS;
1381}
1382
1383/* Special meanings for indices (which have a range of 0-7), which will fit into
1384 a 4-bit integer. */
1385
1386#define NEON_ALL_LANES 15
1387#define NEON_INTERLEAVE_LANES 14
1388
1389/* Parse either a register or a scalar, with an optional type. Return the
1390 register number, and optionally fill in the actual type of the register
1391 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1392 type/index information in *TYPEINFO. */
1393
1394static int
1395parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1396 enum arm_reg_type *rtype,
1397 struct neon_typed_alias *typeinfo)
1398{
1399 char *str = *ccp;
1400 struct reg_entry *reg = arm_reg_parse_multi (&str);
1401 struct neon_typed_alias atype;
1402 struct neon_type_el parsetype;
1403
1404 atype.defined = 0;
1405 atype.index = -1;
1406 atype.eltype.type = NT_invtype;
1407 atype.eltype.size = -1;
1408
1409 /* Try alternate syntax for some types of register. Note these are mutually
1410 exclusive with the Neon syntax extensions. */
1411 if (reg == NULL)
1412 {
1413 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1414 if (altreg != FAIL)
1415 *ccp = str;
1416 if (typeinfo)
1417 *typeinfo = atype;
1418 return altreg;
1419 }
1420
037e8744
JB
1421 /* Undo polymorphism when a set of register types may be accepted. */
1422 if ((type == REG_TYPE_NDQ
1423 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1424 || (type == REG_TYPE_VFSD
1425 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1426 || (type == REG_TYPE_NSDQ
1427 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1428 || reg->type == REG_TYPE_NQ))
1429 || (type == REG_TYPE_MMXWC
1430 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1431 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1432
1433 if (type != reg->type)
1434 return FAIL;
1435
1436 if (reg->neon)
1437 atype = *reg->neon;
5f4273c7 1438
dcbf9037
JB
1439 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1440 {
1441 if ((atype.defined & NTA_HASTYPE) != 0)
1442 {
1443 first_error (_("can't redefine type for operand"));
1444 return FAIL;
1445 }
1446 atype.defined |= NTA_HASTYPE;
1447 atype.eltype = parsetype;
1448 }
5f4273c7 1449
dcbf9037
JB
1450 if (skip_past_char (&str, '[') == SUCCESS)
1451 {
1452 if (type != REG_TYPE_VFD)
1453 {
1454 first_error (_("only D registers may be indexed"));
1455 return FAIL;
1456 }
5f4273c7 1457
dcbf9037
JB
1458 if ((atype.defined & NTA_HASINDEX) != 0)
1459 {
1460 first_error (_("can't change index for operand"));
1461 return FAIL;
1462 }
1463
1464 atype.defined |= NTA_HASINDEX;
1465
1466 if (skip_past_char (&str, ']') == SUCCESS)
1467 atype.index = NEON_ALL_LANES;
1468 else
1469 {
1470 expressionS exp;
1471
1472 my_get_expression (&exp, &str, GE_NO_PREFIX);
1473
1474 if (exp.X_op != O_constant)
1475 {
1476 first_error (_("constant expression required"));
1477 return FAIL;
1478 }
1479
1480 if (skip_past_char (&str, ']') == FAIL)
1481 return FAIL;
1482
1483 atype.index = exp.X_add_number;
1484 }
1485 }
5f4273c7 1486
dcbf9037
JB
1487 if (typeinfo)
1488 *typeinfo = atype;
5f4273c7 1489
dcbf9037
JB
1490 if (rtype)
1491 *rtype = type;
5f4273c7 1492
dcbf9037 1493 *ccp = str;
5f4273c7 1494
dcbf9037
JB
1495 return reg->number;
1496}
1497
1498/* Like arm_reg_parse, but allow allow the following extra features:
1499 - If RTYPE is non-zero, return the (possibly restricted) type of the
1500 register (e.g. Neon double or quad reg when either has been requested).
1501 - If this is a Neon vector type with additional type information, fill
1502 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1503 This function will fault on encountering a scalar. */
dcbf9037
JB
1504
1505static int
1506arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1507 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1508{
1509 struct neon_typed_alias atype;
1510 char *str = *ccp;
1511 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1512
1513 if (reg == FAIL)
1514 return FAIL;
1515
0855e32b
NS
1516 /* Do not allow regname(... to parse as a register. */
1517 if (*str == '(')
1518 return FAIL;
1519
dcbf9037
JB
1520 /* Do not allow a scalar (reg+index) to parse as a register. */
1521 if ((atype.defined & NTA_HASINDEX) != 0)
1522 {
1523 first_error (_("register operand expected, but got scalar"));
1524 return FAIL;
1525 }
1526
1527 if (vectype)
1528 *vectype = atype.eltype;
1529
1530 *ccp = str;
1531
1532 return reg;
1533}
1534
1535#define NEON_SCALAR_REG(X) ((X) >> 4)
1536#define NEON_SCALAR_INDEX(X) ((X) & 15)
1537
5287ad62
JB
1538/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1539 have enough information to be able to do a good job bounds-checking. So, we
1540 just do easy checks here, and do further checks later. */
1541
1542static int
dcbf9037 1543parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1544{
dcbf9037 1545 int reg;
5287ad62 1546 char *str = *ccp;
dcbf9037 1547 struct neon_typed_alias atype;
5f4273c7 1548
dcbf9037 1549 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1550
dcbf9037 1551 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1552 return FAIL;
5f4273c7 1553
dcbf9037 1554 if (atype.index == NEON_ALL_LANES)
5287ad62 1555 {
dcbf9037 1556 first_error (_("scalar must have an index"));
5287ad62
JB
1557 return FAIL;
1558 }
dcbf9037 1559 else if (atype.index >= 64 / elsize)
5287ad62 1560 {
dcbf9037 1561 first_error (_("scalar index out of range"));
5287ad62
JB
1562 return FAIL;
1563 }
5f4273c7 1564
dcbf9037
JB
1565 if (type)
1566 *type = atype.eltype;
5f4273c7 1567
5287ad62 1568 *ccp = str;
5f4273c7 1569
dcbf9037 1570 return reg * 16 + atype.index;
5287ad62
JB
1571}
1572
c19d1205 1573/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1574
c19d1205
ZW
1575static long
1576parse_reg_list (char ** strp)
1577{
1578 char * str = * strp;
1579 long range = 0;
1580 int another_range;
a737bd4d 1581
c19d1205
ZW
1582 /* We come back here if we get ranges concatenated by '+' or '|'. */
1583 do
6057a28f 1584 {
c19d1205 1585 another_range = 0;
a737bd4d 1586
c19d1205
ZW
1587 if (*str == '{')
1588 {
1589 int in_range = 0;
1590 int cur_reg = -1;
a737bd4d 1591
c19d1205
ZW
1592 str++;
1593 do
1594 {
1595 int reg;
6057a28f 1596
dcbf9037 1597 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1598 {
dcbf9037 1599 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1600 return FAIL;
1601 }
a737bd4d 1602
c19d1205
ZW
1603 if (in_range)
1604 {
1605 int i;
a737bd4d 1606
c19d1205
ZW
1607 if (reg <= cur_reg)
1608 {
dcbf9037 1609 first_error (_("bad range in register list"));
c19d1205
ZW
1610 return FAIL;
1611 }
40a18ebd 1612
c19d1205
ZW
1613 for (i = cur_reg + 1; i < reg; i++)
1614 {
1615 if (range & (1 << i))
1616 as_tsktsk
1617 (_("Warning: duplicated register (r%d) in register list"),
1618 i);
1619 else
1620 range |= 1 << i;
1621 }
1622 in_range = 0;
1623 }
a737bd4d 1624
c19d1205
ZW
1625 if (range & (1 << reg))
1626 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1627 reg);
1628 else if (reg <= cur_reg)
1629 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1630
c19d1205
ZW
1631 range |= 1 << reg;
1632 cur_reg = reg;
1633 }
1634 while (skip_past_comma (&str) != FAIL
1635 || (in_range = 1, *str++ == '-'));
1636 str--;
a737bd4d 1637
c19d1205
ZW
1638 if (*str++ != '}')
1639 {
dcbf9037 1640 first_error (_("missing `}'"));
c19d1205
ZW
1641 return FAIL;
1642 }
1643 }
1644 else
1645 {
91d6fa6a 1646 expressionS exp;
40a18ebd 1647
91d6fa6a 1648 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1649 return FAIL;
40a18ebd 1650
91d6fa6a 1651 if (exp.X_op == O_constant)
c19d1205 1652 {
91d6fa6a
NC
1653 if (exp.X_add_number
1654 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1655 {
1656 inst.error = _("invalid register mask");
1657 return FAIL;
1658 }
a737bd4d 1659
91d6fa6a 1660 if ((range & exp.X_add_number) != 0)
c19d1205 1661 {
91d6fa6a 1662 int regno = range & exp.X_add_number;
a737bd4d 1663
c19d1205
ZW
1664 regno &= -regno;
1665 regno = (1 << regno) - 1;
1666 as_tsktsk
1667 (_("Warning: duplicated register (r%d) in register list"),
1668 regno);
1669 }
a737bd4d 1670
91d6fa6a 1671 range |= exp.X_add_number;
c19d1205
ZW
1672 }
1673 else
1674 {
1675 if (inst.reloc.type != 0)
1676 {
1677 inst.error = _("expression too complex");
1678 return FAIL;
1679 }
a737bd4d 1680
91d6fa6a 1681 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1682 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1683 inst.reloc.pc_rel = 0;
1684 }
1685 }
a737bd4d 1686
c19d1205
ZW
1687 if (*str == '|' || *str == '+')
1688 {
1689 str++;
1690 another_range = 1;
1691 }
a737bd4d 1692 }
c19d1205 1693 while (another_range);
a737bd4d 1694
c19d1205
ZW
1695 *strp = str;
1696 return range;
a737bd4d
NC
1697}
1698
5287ad62
JB
1699/* Types of registers in a list. */
1700
1701enum reg_list_els
1702{
1703 REGLIST_VFP_S,
1704 REGLIST_VFP_D,
1705 REGLIST_NEON_D
1706};
1707
c19d1205
ZW
1708/* Parse a VFP register list. If the string is invalid return FAIL.
1709 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1710 register. Parses registers of type ETYPE.
1711 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1712 - Q registers can be used to specify pairs of D registers
1713 - { } can be omitted from around a singleton register list
1714 FIXME: This is not implemented, as it would require backtracking in
1715 some cases, e.g.:
1716 vtbl.8 d3,d4,d5
1717 This could be done (the meaning isn't really ambiguous), but doesn't
1718 fit in well with the current parsing framework.
dcbf9037
JB
1719 - 32 D registers may be used (also true for VFPv3).
1720 FIXME: Types are ignored in these register lists, which is probably a
1721 bug. */
6057a28f 1722
c19d1205 1723static int
037e8744 1724parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1725{
037e8744 1726 char *str = *ccp;
c19d1205
ZW
1727 int base_reg;
1728 int new_base;
21d799b5 1729 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1730 int max_regs = 0;
c19d1205
ZW
1731 int count = 0;
1732 int warned = 0;
1733 unsigned long mask = 0;
a737bd4d 1734 int i;
6057a28f 1735
037e8744 1736 if (*str != '{')
5287ad62
JB
1737 {
1738 inst.error = _("expecting {");
1739 return FAIL;
1740 }
6057a28f 1741
037e8744 1742 str++;
6057a28f 1743
5287ad62 1744 switch (etype)
c19d1205 1745 {
5287ad62 1746 case REGLIST_VFP_S:
c19d1205
ZW
1747 regtype = REG_TYPE_VFS;
1748 max_regs = 32;
5287ad62 1749 break;
5f4273c7 1750
5287ad62
JB
1751 case REGLIST_VFP_D:
1752 regtype = REG_TYPE_VFD;
b7fc2769 1753 break;
5f4273c7 1754
b7fc2769
JB
1755 case REGLIST_NEON_D:
1756 regtype = REG_TYPE_NDQ;
1757 break;
1758 }
1759
1760 if (etype != REGLIST_VFP_S)
1761 {
b1cc4aeb
PB
1762 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1763 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1764 {
1765 max_regs = 32;
1766 if (thumb_mode)
1767 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1768 fpu_vfp_ext_d32);
5287ad62
JB
1769 else
1770 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1771 fpu_vfp_ext_d32);
5287ad62
JB
1772 }
1773 else
1774 max_regs = 16;
c19d1205 1775 }
6057a28f 1776
c19d1205 1777 base_reg = max_regs;
a737bd4d 1778
c19d1205
ZW
1779 do
1780 {
5287ad62 1781 int setmask = 1, addregs = 1;
dcbf9037 1782
037e8744 1783 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1784
c19d1205 1785 if (new_base == FAIL)
a737bd4d 1786 {
dcbf9037 1787 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1788 return FAIL;
1789 }
5f4273c7 1790
b7fc2769
JB
1791 if (new_base >= max_regs)
1792 {
1793 first_error (_("register out of range in list"));
1794 return FAIL;
1795 }
5f4273c7 1796
5287ad62
JB
1797 /* Note: a value of 2 * n is returned for the register Q<n>. */
1798 if (regtype == REG_TYPE_NQ)
1799 {
1800 setmask = 3;
1801 addregs = 2;
1802 }
1803
c19d1205
ZW
1804 if (new_base < base_reg)
1805 base_reg = new_base;
a737bd4d 1806
5287ad62 1807 if (mask & (setmask << new_base))
c19d1205 1808 {
dcbf9037 1809 first_error (_("invalid register list"));
c19d1205 1810 return FAIL;
a737bd4d 1811 }
a737bd4d 1812
c19d1205
ZW
1813 if ((mask >> new_base) != 0 && ! warned)
1814 {
1815 as_tsktsk (_("register list not in ascending order"));
1816 warned = 1;
1817 }
0bbf2aa4 1818
5287ad62
JB
1819 mask |= setmask << new_base;
1820 count += addregs;
0bbf2aa4 1821
037e8744 1822 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1823 {
1824 int high_range;
0bbf2aa4 1825
037e8744 1826 str++;
0bbf2aa4 1827
037e8744 1828 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1829 == FAIL)
c19d1205
ZW
1830 {
1831 inst.error = gettext (reg_expected_msgs[regtype]);
1832 return FAIL;
1833 }
0bbf2aa4 1834
b7fc2769
JB
1835 if (high_range >= max_regs)
1836 {
1837 first_error (_("register out of range in list"));
1838 return FAIL;
1839 }
1840
5287ad62
JB
1841 if (regtype == REG_TYPE_NQ)
1842 high_range = high_range + 1;
1843
c19d1205
ZW
1844 if (high_range <= new_base)
1845 {
1846 inst.error = _("register range not in ascending order");
1847 return FAIL;
1848 }
0bbf2aa4 1849
5287ad62 1850 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1851 {
5287ad62 1852 if (mask & (setmask << new_base))
0bbf2aa4 1853 {
c19d1205
ZW
1854 inst.error = _("invalid register list");
1855 return FAIL;
0bbf2aa4 1856 }
c19d1205 1857
5287ad62
JB
1858 mask |= setmask << new_base;
1859 count += addregs;
0bbf2aa4 1860 }
0bbf2aa4 1861 }
0bbf2aa4 1862 }
037e8744 1863 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1864
037e8744 1865 str++;
0bbf2aa4 1866
c19d1205
ZW
1867 /* Sanity check -- should have raised a parse error above. */
1868 if (count == 0 || count > max_regs)
1869 abort ();
1870
1871 *pbase = base_reg;
1872
1873 /* Final test -- the registers must be consecutive. */
1874 mask >>= base_reg;
1875 for (i = 0; i < count; i++)
1876 {
1877 if ((mask & (1u << i)) == 0)
1878 {
1879 inst.error = _("non-contiguous register range");
1880 return FAIL;
1881 }
1882 }
1883
037e8744
JB
1884 *ccp = str;
1885
c19d1205 1886 return count;
b99bd4ef
NC
1887}
1888
dcbf9037
JB
1889/* True if two alias types are the same. */
1890
c921be7d 1891static bfd_boolean
dcbf9037
JB
1892neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1893{
1894 if (!a && !b)
c921be7d 1895 return TRUE;
5f4273c7 1896
dcbf9037 1897 if (!a || !b)
c921be7d 1898 return FALSE;
dcbf9037
JB
1899
1900 if (a->defined != b->defined)
c921be7d 1901 return FALSE;
5f4273c7 1902
dcbf9037
JB
1903 if ((a->defined & NTA_HASTYPE) != 0
1904 && (a->eltype.type != b->eltype.type
1905 || a->eltype.size != b->eltype.size))
c921be7d 1906 return FALSE;
dcbf9037
JB
1907
1908 if ((a->defined & NTA_HASINDEX) != 0
1909 && (a->index != b->index))
c921be7d 1910 return FALSE;
5f4273c7 1911
c921be7d 1912 return TRUE;
dcbf9037
JB
1913}
1914
5287ad62
JB
1915/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1916 The base register is put in *PBASE.
dcbf9037 1917 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1918 the return value.
1919 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1920 Bits [6:5] encode the list length (minus one).
1921 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1922
5287ad62 1923#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1924#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1925#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1926
1927static int
dcbf9037
JB
1928parse_neon_el_struct_list (char **str, unsigned *pbase,
1929 struct neon_type_el *eltype)
5287ad62
JB
1930{
1931 char *ptr = *str;
1932 int base_reg = -1;
1933 int reg_incr = -1;
1934 int count = 0;
1935 int lane = -1;
1936 int leading_brace = 0;
1937 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1938 const char *const incr_error = _("register stride must be 1 or 2");
1939 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1940 struct neon_typed_alias firsttype;
5f4273c7 1941
5287ad62
JB
1942 if (skip_past_char (&ptr, '{') == SUCCESS)
1943 leading_brace = 1;
5f4273c7 1944
5287ad62
JB
1945 do
1946 {
dcbf9037
JB
1947 struct neon_typed_alias atype;
1948 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1949
5287ad62
JB
1950 if (getreg == FAIL)
1951 {
dcbf9037 1952 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1953 return FAIL;
1954 }
5f4273c7 1955
5287ad62
JB
1956 if (base_reg == -1)
1957 {
1958 base_reg = getreg;
1959 if (rtype == REG_TYPE_NQ)
1960 {
1961 reg_incr = 1;
5287ad62 1962 }
dcbf9037 1963 firsttype = atype;
5287ad62
JB
1964 }
1965 else if (reg_incr == -1)
1966 {
1967 reg_incr = getreg - base_reg;
1968 if (reg_incr < 1 || reg_incr > 2)
1969 {
dcbf9037 1970 first_error (_(incr_error));
5287ad62
JB
1971 return FAIL;
1972 }
1973 }
1974 else if (getreg != base_reg + reg_incr * count)
1975 {
dcbf9037
JB
1976 first_error (_(incr_error));
1977 return FAIL;
1978 }
1979
c921be7d 1980 if (! neon_alias_types_same (&atype, &firsttype))
dcbf9037
JB
1981 {
1982 first_error (_(type_error));
5287ad62
JB
1983 return FAIL;
1984 }
5f4273c7 1985
5287ad62
JB
1986 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1987 modes. */
1988 if (ptr[0] == '-')
1989 {
dcbf9037 1990 struct neon_typed_alias htype;
5287ad62
JB
1991 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1992 if (lane == -1)
1993 lane = NEON_INTERLEAVE_LANES;
1994 else if (lane != NEON_INTERLEAVE_LANES)
1995 {
dcbf9037 1996 first_error (_(type_error));
5287ad62
JB
1997 return FAIL;
1998 }
1999 if (reg_incr == -1)
2000 reg_incr = 1;
2001 else if (reg_incr != 1)
2002 {
dcbf9037 2003 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
2004 return FAIL;
2005 }
2006 ptr++;
dcbf9037 2007 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
2008 if (hireg == FAIL)
2009 {
dcbf9037
JB
2010 first_error (_(reg_expected_msgs[rtype]));
2011 return FAIL;
2012 }
c921be7d 2013 if (! neon_alias_types_same (&htype, &firsttype))
dcbf9037
JB
2014 {
2015 first_error (_(type_error));
5287ad62
JB
2016 return FAIL;
2017 }
2018 count += hireg + dregs - getreg;
2019 continue;
2020 }
5f4273c7 2021
5287ad62
JB
2022 /* If we're using Q registers, we can't use [] or [n] syntax. */
2023 if (rtype == REG_TYPE_NQ)
2024 {
2025 count += 2;
2026 continue;
2027 }
5f4273c7 2028
dcbf9037 2029 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 2030 {
dcbf9037
JB
2031 if (lane == -1)
2032 lane = atype.index;
2033 else if (lane != atype.index)
5287ad62 2034 {
dcbf9037
JB
2035 first_error (_(type_error));
2036 return FAIL;
5287ad62
JB
2037 }
2038 }
2039 else if (lane == -1)
2040 lane = NEON_INTERLEAVE_LANES;
2041 else if (lane != NEON_INTERLEAVE_LANES)
2042 {
dcbf9037 2043 first_error (_(type_error));
5287ad62
JB
2044 return FAIL;
2045 }
2046 count++;
2047 }
2048 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2049
5287ad62
JB
2050 /* No lane set by [x]. We must be interleaving structures. */
2051 if (lane == -1)
2052 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2053
5287ad62
JB
2054 /* Sanity check. */
2055 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2056 || (count > 1 && reg_incr == -1))
2057 {
dcbf9037 2058 first_error (_("error parsing element/structure list"));
5287ad62
JB
2059 return FAIL;
2060 }
2061
2062 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2063 {
dcbf9037 2064 first_error (_("expected }"));
5287ad62
JB
2065 return FAIL;
2066 }
5f4273c7 2067
5287ad62
JB
2068 if (reg_incr == -1)
2069 reg_incr = 1;
2070
dcbf9037
JB
2071 if (eltype)
2072 *eltype = firsttype.eltype;
2073
5287ad62
JB
2074 *pbase = base_reg;
2075 *str = ptr;
5f4273c7 2076
5287ad62
JB
2077 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2078}
2079
c19d1205
ZW
2080/* Parse an explicit relocation suffix on an expression. This is
2081 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2082 arm_reloc_hsh contains no entries, so this function can only
2083 succeed if there is no () after the word. Returns -1 on error,
2084 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2085
c19d1205
ZW
2086static int
2087parse_reloc (char **str)
b99bd4ef 2088{
c19d1205
ZW
2089 struct reloc_entry *r;
2090 char *p, *q;
b99bd4ef 2091
c19d1205
ZW
2092 if (**str != '(')
2093 return BFD_RELOC_UNUSED;
b99bd4ef 2094
c19d1205
ZW
2095 p = *str + 1;
2096 q = p;
2097
2098 while (*q && *q != ')' && *q != ',')
2099 q++;
2100 if (*q != ')')
2101 return -1;
2102
21d799b5
NC
2103 if ((r = (struct reloc_entry *)
2104 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2105 return -1;
2106
2107 *str = q + 1;
2108 return r->reloc;
b99bd4ef
NC
2109}
2110
c19d1205
ZW
2111/* Directives: register aliases. */
2112
dcbf9037 2113static struct reg_entry *
90ec0d68 2114insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2115{
d3ce72d0 2116 struct reg_entry *new_reg;
c19d1205 2117 const char *name;
b99bd4ef 2118
d3ce72d0 2119 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2120 {
d3ce72d0 2121 if (new_reg->builtin)
c19d1205 2122 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2123
c19d1205
ZW
2124 /* Only warn about a redefinition if it's not defined as the
2125 same register. */
d3ce72d0 2126 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2127 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2128
d929913e 2129 return NULL;
c19d1205 2130 }
b99bd4ef 2131
c19d1205 2132 name = xstrdup (str);
d3ce72d0 2133 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2134
d3ce72d0
NC
2135 new_reg->name = name;
2136 new_reg->number = number;
2137 new_reg->type = type;
2138 new_reg->builtin = FALSE;
2139 new_reg->neon = NULL;
b99bd4ef 2140
d3ce72d0 2141 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2142 abort ();
5f4273c7 2143
d3ce72d0 2144 return new_reg;
dcbf9037
JB
2145}
2146
2147static void
2148insert_neon_reg_alias (char *str, int number, int type,
2149 struct neon_typed_alias *atype)
2150{
2151 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2152
dcbf9037
JB
2153 if (!reg)
2154 {
2155 first_error (_("attempt to redefine typed alias"));
2156 return;
2157 }
5f4273c7 2158
dcbf9037
JB
2159 if (atype)
2160 {
21d799b5
NC
2161 reg->neon = (struct neon_typed_alias *)
2162 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2163 *reg->neon = *atype;
2164 }
c19d1205 2165}
b99bd4ef 2166
c19d1205 2167/* Look for the .req directive. This is of the form:
b99bd4ef 2168
c19d1205 2169 new_register_name .req existing_register_name
b99bd4ef 2170
c19d1205 2171 If we find one, or if it looks sufficiently like one that we want to
d929913e 2172 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2173
d929913e 2174static bfd_boolean
c19d1205
ZW
2175create_register_alias (char * newname, char *p)
2176{
2177 struct reg_entry *old;
2178 char *oldname, *nbuf;
2179 size_t nlen;
b99bd4ef 2180
c19d1205
ZW
2181 /* The input scrubber ensures that whitespace after the mnemonic is
2182 collapsed to single spaces. */
2183 oldname = p;
2184 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2185 return FALSE;
b99bd4ef 2186
c19d1205
ZW
2187 oldname += 6;
2188 if (*oldname == '\0')
d929913e 2189 return FALSE;
b99bd4ef 2190
21d799b5 2191 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2192 if (!old)
b99bd4ef 2193 {
c19d1205 2194 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2195 return TRUE;
b99bd4ef
NC
2196 }
2197
c19d1205
ZW
2198 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2199 the desired alias name, and p points to its end. If not, then
2200 the desired alias name is in the global original_case_string. */
2201#ifdef TC_CASE_SENSITIVE
2202 nlen = p - newname;
2203#else
2204 newname = original_case_string;
2205 nlen = strlen (newname);
2206#endif
b99bd4ef 2207
21d799b5 2208 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2209 memcpy (nbuf, newname, nlen);
2210 nbuf[nlen] = '\0';
b99bd4ef 2211
c19d1205
ZW
2212 /* Create aliases under the new name as stated; an all-lowercase
2213 version of the new name; and an all-uppercase version of the new
2214 name. */
d929913e
NC
2215 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2216 {
2217 for (p = nbuf; *p; p++)
2218 *p = TOUPPER (*p);
c19d1205 2219
d929913e
NC
2220 if (strncmp (nbuf, newname, nlen))
2221 {
2222 /* If this attempt to create an additional alias fails, do not bother
2223 trying to create the all-lower case alias. We will fail and issue
2224 a second, duplicate error message. This situation arises when the
2225 programmer does something like:
2226 foo .req r0
2227 Foo .req r1
2228 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2229 the artificial FOO alias because it has already been created by the
d929913e
NC
2230 first .req. */
2231 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2232 return TRUE;
2233 }
c19d1205 2234
d929913e
NC
2235 for (p = nbuf; *p; p++)
2236 *p = TOLOWER (*p);
c19d1205 2237
d929913e
NC
2238 if (strncmp (nbuf, newname, nlen))
2239 insert_reg_alias (nbuf, old->number, old->type);
2240 }
c19d1205 2241
d929913e 2242 return TRUE;
b99bd4ef
NC
2243}
2244
dcbf9037
JB
2245/* Create a Neon typed/indexed register alias using directives, e.g.:
2246 X .dn d5.s32[1]
2247 Y .qn 6.s16
2248 Z .dn d7
2249 T .dn Z[0]
2250 These typed registers can be used instead of the types specified after the
2251 Neon mnemonic, so long as all operands given have types. Types can also be
2252 specified directly, e.g.:
5f4273c7 2253 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2254
c921be7d 2255static bfd_boolean
dcbf9037
JB
2256create_neon_reg_alias (char *newname, char *p)
2257{
2258 enum arm_reg_type basetype;
2259 struct reg_entry *basereg;
2260 struct reg_entry mybasereg;
2261 struct neon_type ntype;
2262 struct neon_typed_alias typeinfo;
12d6b0b7 2263 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2264 int namelen;
5f4273c7 2265
dcbf9037
JB
2266 typeinfo.defined = 0;
2267 typeinfo.eltype.type = NT_invtype;
2268 typeinfo.eltype.size = -1;
2269 typeinfo.index = -1;
5f4273c7 2270
dcbf9037 2271 nameend = p;
5f4273c7 2272
dcbf9037
JB
2273 if (strncmp (p, " .dn ", 5) == 0)
2274 basetype = REG_TYPE_VFD;
2275 else if (strncmp (p, " .qn ", 5) == 0)
2276 basetype = REG_TYPE_NQ;
2277 else
c921be7d 2278 return FALSE;
5f4273c7 2279
dcbf9037 2280 p += 5;
5f4273c7 2281
dcbf9037 2282 if (*p == '\0')
c921be7d 2283 return FALSE;
5f4273c7 2284
dcbf9037
JB
2285 basereg = arm_reg_parse_multi (&p);
2286
2287 if (basereg && basereg->type != basetype)
2288 {
2289 as_bad (_("bad type for register"));
c921be7d 2290 return FALSE;
dcbf9037
JB
2291 }
2292
2293 if (basereg == NULL)
2294 {
2295 expressionS exp;
2296 /* Try parsing as an integer. */
2297 my_get_expression (&exp, &p, GE_NO_PREFIX);
2298 if (exp.X_op != O_constant)
2299 {
2300 as_bad (_("expression must be constant"));
c921be7d 2301 return FALSE;
dcbf9037
JB
2302 }
2303 basereg = &mybasereg;
2304 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2305 : exp.X_add_number;
2306 basereg->neon = 0;
2307 }
2308
2309 if (basereg->neon)
2310 typeinfo = *basereg->neon;
2311
2312 if (parse_neon_type (&ntype, &p) == SUCCESS)
2313 {
2314 /* We got a type. */
2315 if (typeinfo.defined & NTA_HASTYPE)
2316 {
2317 as_bad (_("can't redefine the type of a register alias"));
c921be7d 2318 return FALSE;
dcbf9037 2319 }
5f4273c7 2320
dcbf9037
JB
2321 typeinfo.defined |= NTA_HASTYPE;
2322 if (ntype.elems != 1)
2323 {
2324 as_bad (_("you must specify a single type only"));
c921be7d 2325 return FALSE;
dcbf9037
JB
2326 }
2327 typeinfo.eltype = ntype.el[0];
2328 }
5f4273c7 2329
dcbf9037
JB
2330 if (skip_past_char (&p, '[') == SUCCESS)
2331 {
2332 expressionS exp;
2333 /* We got a scalar index. */
5f4273c7 2334
dcbf9037
JB
2335 if (typeinfo.defined & NTA_HASINDEX)
2336 {
2337 as_bad (_("can't redefine the index of a scalar alias"));
c921be7d 2338 return FALSE;
dcbf9037 2339 }
5f4273c7 2340
dcbf9037 2341 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2342
dcbf9037
JB
2343 if (exp.X_op != O_constant)
2344 {
2345 as_bad (_("scalar index must be constant"));
c921be7d 2346 return FALSE;
dcbf9037 2347 }
5f4273c7 2348
dcbf9037
JB
2349 typeinfo.defined |= NTA_HASINDEX;
2350 typeinfo.index = exp.X_add_number;
5f4273c7 2351
dcbf9037
JB
2352 if (skip_past_char (&p, ']') == FAIL)
2353 {
2354 as_bad (_("expecting ]"));
c921be7d 2355 return FALSE;
dcbf9037
JB
2356 }
2357 }
2358
15735687
NS
2359 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2360 the desired alias name, and p points to its end. If not, then
2361 the desired alias name is in the global original_case_string. */
2362#ifdef TC_CASE_SENSITIVE
dcbf9037 2363 namelen = nameend - newname;
15735687
NS
2364#else
2365 newname = original_case_string;
2366 namelen = strlen (newname);
2367#endif
2368
21d799b5 2369 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2370 strncpy (namebuf, newname, namelen);
2371 namebuf[namelen] = '\0';
5f4273c7 2372
dcbf9037
JB
2373 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2374 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2375
dcbf9037
JB
2376 /* Insert name in all uppercase. */
2377 for (p = namebuf; *p; p++)
2378 *p = TOUPPER (*p);
5f4273c7 2379
dcbf9037
JB
2380 if (strncmp (namebuf, newname, namelen))
2381 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2382 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2383
dcbf9037
JB
2384 /* Insert name in all lowercase. */
2385 for (p = namebuf; *p; p++)
2386 *p = TOLOWER (*p);
5f4273c7 2387
dcbf9037
JB
2388 if (strncmp (namebuf, newname, namelen))
2389 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2390 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2391
c921be7d 2392 return TRUE;
dcbf9037
JB
2393}
2394
c19d1205
ZW
2395/* Should never be called, as .req goes between the alias and the
2396 register name, not at the beginning of the line. */
c921be7d 2397
b99bd4ef 2398static void
c19d1205 2399s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2400{
c19d1205
ZW
2401 as_bad (_("invalid syntax for .req directive"));
2402}
b99bd4ef 2403
dcbf9037
JB
2404static void
2405s_dn (int a ATTRIBUTE_UNUSED)
2406{
2407 as_bad (_("invalid syntax for .dn directive"));
2408}
2409
2410static void
2411s_qn (int a ATTRIBUTE_UNUSED)
2412{
2413 as_bad (_("invalid syntax for .qn directive"));
2414}
2415
c19d1205
ZW
2416/* The .unreq directive deletes an alias which was previously defined
2417 by .req. For example:
b99bd4ef 2418
c19d1205
ZW
2419 my_alias .req r11
2420 .unreq my_alias */
b99bd4ef
NC
2421
2422static void
c19d1205 2423s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2424{
c19d1205
ZW
2425 char * name;
2426 char saved_char;
b99bd4ef 2427
c19d1205
ZW
2428 name = input_line_pointer;
2429
2430 while (*input_line_pointer != 0
2431 && *input_line_pointer != ' '
2432 && *input_line_pointer != '\n')
2433 ++input_line_pointer;
2434
2435 saved_char = *input_line_pointer;
2436 *input_line_pointer = 0;
2437
2438 if (!*name)
2439 as_bad (_("invalid syntax for .unreq directive"));
2440 else
2441 {
21d799b5
NC
2442 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2443 name);
c19d1205
ZW
2444
2445 if (!reg)
2446 as_bad (_("unknown register alias '%s'"), name);
2447 else if (reg->builtin)
a1727c1a 2448 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2449 name);
2450 else
2451 {
d929913e
NC
2452 char * p;
2453 char * nbuf;
2454
db0bc284 2455 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2456 free ((char *) reg->name);
dcbf9037
JB
2457 if (reg->neon)
2458 free (reg->neon);
c19d1205 2459 free (reg);
d929913e
NC
2460
2461 /* Also locate the all upper case and all lower case versions.
2462 Do not complain if we cannot find one or the other as it
2463 was probably deleted above. */
5f4273c7 2464
d929913e
NC
2465 nbuf = strdup (name);
2466 for (p = nbuf; *p; p++)
2467 *p = TOUPPER (*p);
21d799b5 2468 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2469 if (reg)
2470 {
db0bc284 2471 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2472 free ((char *) reg->name);
2473 if (reg->neon)
2474 free (reg->neon);
2475 free (reg);
2476 }
2477
2478 for (p = nbuf; *p; p++)
2479 *p = TOLOWER (*p);
21d799b5 2480 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2481 if (reg)
2482 {
db0bc284 2483 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2484 free ((char *) reg->name);
2485 if (reg->neon)
2486 free (reg->neon);
2487 free (reg);
2488 }
2489
2490 free (nbuf);
c19d1205
ZW
2491 }
2492 }
b99bd4ef 2493
c19d1205 2494 *input_line_pointer = saved_char;
b99bd4ef
NC
2495 demand_empty_rest_of_line ();
2496}
2497
c19d1205
ZW
2498/* Directives: Instruction set selection. */
2499
2500#ifdef OBJ_ELF
2501/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2502 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2503 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2504 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2505
cd000bff
DJ
2506/* Create a new mapping symbol for the transition to STATE. */
2507
2508static void
2509make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2510{
a737bd4d 2511 symbolS * symbolP;
c19d1205
ZW
2512 const char * symname;
2513 int type;
b99bd4ef 2514
c19d1205 2515 switch (state)
b99bd4ef 2516 {
c19d1205
ZW
2517 case MAP_DATA:
2518 symname = "$d";
2519 type = BSF_NO_FLAGS;
2520 break;
2521 case MAP_ARM:
2522 symname = "$a";
2523 type = BSF_NO_FLAGS;
2524 break;
2525 case MAP_THUMB:
2526 symname = "$t";
2527 type = BSF_NO_FLAGS;
2528 break;
c19d1205
ZW
2529 default:
2530 abort ();
2531 }
2532
cd000bff 2533 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2534 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2535
2536 switch (state)
2537 {
2538 case MAP_ARM:
2539 THUMB_SET_FUNC (symbolP, 0);
2540 ARM_SET_THUMB (symbolP, 0);
2541 ARM_SET_INTERWORK (symbolP, support_interwork);
2542 break;
2543
2544 case MAP_THUMB:
2545 THUMB_SET_FUNC (symbolP, 1);
2546 ARM_SET_THUMB (symbolP, 1);
2547 ARM_SET_INTERWORK (symbolP, support_interwork);
2548 break;
2549
2550 case MAP_DATA:
2551 default:
cd000bff
DJ
2552 break;
2553 }
2554
2555 /* Save the mapping symbols for future reference. Also check that
2556 we do not place two mapping symbols at the same offset within a
2557 frag. We'll handle overlap between frags in
2de7820f
JZ
2558 check_mapping_symbols.
2559
2560 If .fill or other data filling directive generates zero sized data,
2561 the mapping symbol for the following code will have the same value
2562 as the one generated for the data filling directive. In this case,
2563 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2564 if (value == 0)
2565 {
2de7820f
JZ
2566 if (frag->tc_frag_data.first_map != NULL)
2567 {
2568 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2569 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2570 }
cd000bff
DJ
2571 frag->tc_frag_data.first_map = symbolP;
2572 }
2573 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2574 {
2575 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2576 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2577 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2578 }
cd000bff
DJ
2579 frag->tc_frag_data.last_map = symbolP;
2580}
2581
2582/* We must sometimes convert a region marked as code to data during
2583 code alignment, if an odd number of bytes have to be padded. The
2584 code mapping symbol is pushed to an aligned address. */
2585
2586static void
2587insert_data_mapping_symbol (enum mstate state,
2588 valueT value, fragS *frag, offsetT bytes)
2589{
2590 /* If there was already a mapping symbol, remove it. */
2591 if (frag->tc_frag_data.last_map != NULL
2592 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2593 {
2594 symbolS *symp = frag->tc_frag_data.last_map;
2595
2596 if (value == 0)
2597 {
2598 know (frag->tc_frag_data.first_map == symp);
2599 frag->tc_frag_data.first_map = NULL;
2600 }
2601 frag->tc_frag_data.last_map = NULL;
2602 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2603 }
cd000bff
DJ
2604
2605 make_mapping_symbol (MAP_DATA, value, frag);
2606 make_mapping_symbol (state, value + bytes, frag);
2607}
2608
2609static void mapping_state_2 (enum mstate state, int max_chars);
2610
2611/* Set the mapping state to STATE. Only call this when about to
2612 emit some STATE bytes to the file. */
2613
2614void
2615mapping_state (enum mstate state)
2616{
940b5ce0
DJ
2617 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2618
cd000bff
DJ
2619#define TRANSITION(from, to) (mapstate == (from) && state == (to))
2620
2621 if (mapstate == state)
2622 /* The mapping symbol has already been emitted.
2623 There is nothing else to do. */
2624 return;
49c62a33
NC
2625
2626 if (state == MAP_ARM || state == MAP_THUMB)
2627 /* PR gas/12931
2628 All ARM instructions require 4-byte alignment.
2629 (Almost) all Thumb instructions require 2-byte alignment.
2630
2631 When emitting instructions into any section, mark the section
2632 appropriately.
2633
2634 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2635 but themselves require 2-byte alignment; this applies to some
2636 PC- relative forms. However, these cases will invovle implicit
2637 literal pool generation or an explicit .align >=2, both of
2638 which will cause the section to me marked with sufficient
2639 alignment. Thus, we don't handle those cases here. */
2640 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2641
2642 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
cd000bff
DJ
2643 /* This case will be evaluated later in the next else. */
2644 return;
2645 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2646 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2647 {
2648 /* Only add the symbol if the offset is > 0:
2649 if we're at the first frag, check it's size > 0;
2650 if we're not at the first frag, then for sure
2651 the offset is > 0. */
2652 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2653 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2654
2655 if (add_symbol)
2656 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2657 }
2658
2659 mapping_state_2 (state, 0);
2660#undef TRANSITION
2661}
2662
2663/* Same as mapping_state, but MAX_CHARS bytes have already been
2664 allocated. Put the mapping symbol that far back. */
2665
2666static void
2667mapping_state_2 (enum mstate state, int max_chars)
2668{
940b5ce0
DJ
2669 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2670
2671 if (!SEG_NORMAL (now_seg))
2672 return;
2673
cd000bff
DJ
2674 if (mapstate == state)
2675 /* The mapping symbol has already been emitted.
2676 There is nothing else to do. */
2677 return;
2678
cd000bff
DJ
2679 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2680 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205
ZW
2681}
2682#else
d3106081
NS
2683#define mapping_state(x) ((void)0)
2684#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2685#endif
2686
2687/* Find the real, Thumb encoded start of a Thumb function. */
2688
4343666d 2689#ifdef OBJ_COFF
c19d1205
ZW
2690static symbolS *
2691find_real_start (symbolS * symbolP)
2692{
2693 char * real_start;
2694 const char * name = S_GET_NAME (symbolP);
2695 symbolS * new_target;
2696
2697 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2698#define STUB_NAME ".real_start_of"
2699
2700 if (name == NULL)
2701 abort ();
2702
37f6032b
ZW
2703 /* The compiler may generate BL instructions to local labels because
2704 it needs to perform a branch to a far away location. These labels
2705 do not have a corresponding ".real_start_of" label. We check
2706 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2707 the ".real_start_of" convention for nonlocal branches. */
2708 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2709 return symbolP;
2710
37f6032b 2711 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2712 new_target = symbol_find (real_start);
2713
2714 if (new_target == NULL)
2715 {
bd3ba5d1 2716 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2717 new_target = symbolP;
2718 }
2719
c19d1205
ZW
2720 return new_target;
2721}
4343666d 2722#endif
c19d1205
ZW
2723
2724static void
2725opcode_select (int width)
2726{
2727 switch (width)
2728 {
2729 case 16:
2730 if (! thumb_mode)
2731 {
e74cfd16 2732 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2733 as_bad (_("selected processor does not support THUMB opcodes"));
2734
2735 thumb_mode = 1;
2736 /* No need to force the alignment, since we will have been
2737 coming from ARM mode, which is word-aligned. */
2738 record_alignment (now_seg, 1);
2739 }
c19d1205
ZW
2740 break;
2741
2742 case 32:
2743 if (thumb_mode)
2744 {
e74cfd16 2745 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2746 as_bad (_("selected processor does not support ARM opcodes"));
2747
2748 thumb_mode = 0;
2749
2750 if (!need_pass_2)
2751 frag_align (2, 0, 0);
2752
2753 record_alignment (now_seg, 1);
2754 }
c19d1205
ZW
2755 break;
2756
2757 default:
2758 as_bad (_("invalid instruction size selected (%d)"), width);
2759 }
2760}
2761
2762static void
2763s_arm (int ignore ATTRIBUTE_UNUSED)
2764{
2765 opcode_select (32);
2766 demand_empty_rest_of_line ();
2767}
2768
2769static void
2770s_thumb (int ignore ATTRIBUTE_UNUSED)
2771{
2772 opcode_select (16);
2773 demand_empty_rest_of_line ();
2774}
2775
2776static void
2777s_code (int unused ATTRIBUTE_UNUSED)
2778{
2779 int temp;
2780
2781 temp = get_absolute_expression ();
2782 switch (temp)
2783 {
2784 case 16:
2785 case 32:
2786 opcode_select (temp);
2787 break;
2788
2789 default:
2790 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2791 }
2792}
2793
2794static void
2795s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2796{
2797 /* If we are not already in thumb mode go into it, EVEN if
2798 the target processor does not support thumb instructions.
2799 This is used by gcc/config/arm/lib1funcs.asm for example
2800 to compile interworking support functions even if the
2801 target processor should not support interworking. */
2802 if (! thumb_mode)
2803 {
2804 thumb_mode = 2;
2805 record_alignment (now_seg, 1);
2806 }
2807
2808 demand_empty_rest_of_line ();
2809}
2810
2811static void
2812s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2813{
2814 s_thumb (0);
2815
2816 /* The following label is the name/address of the start of a Thumb function.
2817 We need to know this for the interworking support. */
2818 label_is_thumb_function_name = TRUE;
2819}
2820
2821/* Perform a .set directive, but also mark the alias as
2822 being a thumb function. */
2823
2824static void
2825s_thumb_set (int equiv)
2826{
2827 /* XXX the following is a duplicate of the code for s_set() in read.c
2828 We cannot just call that code as we need to get at the symbol that
2829 is created. */
2830 char * name;
2831 char delim;
2832 char * end_name;
2833 symbolS * symbolP;
2834
2835 /* Especial apologies for the random logic:
2836 This just grew, and could be parsed much more simply!
2837 Dean - in haste. */
2838 name = input_line_pointer;
2839 delim = get_symbol_end ();
2840 end_name = input_line_pointer;
2841 *end_name = delim;
2842
2843 if (*input_line_pointer != ',')
2844 {
2845 *end_name = 0;
2846 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2847 *end_name = delim;
2848 ignore_rest_of_line ();
2849 return;
2850 }
2851
2852 input_line_pointer++;
2853 *end_name = 0;
2854
2855 if (name[0] == '.' && name[1] == '\0')
2856 {
2857 /* XXX - this should not happen to .thumb_set. */
2858 abort ();
2859 }
2860
2861 if ((symbolP = symbol_find (name)) == NULL
2862 && (symbolP = md_undefined_symbol (name)) == NULL)
2863 {
2864#ifndef NO_LISTING
2865 /* When doing symbol listings, play games with dummy fragments living
2866 outside the normal fragment chain to record the file and line info
c19d1205 2867 for this symbol. */
b99bd4ef
NC
2868 if (listing & LISTING_SYMBOLS)
2869 {
2870 extern struct list_info_struct * listing_tail;
21d799b5 2871 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2872
2873 memset (dummy_frag, 0, sizeof (fragS));
2874 dummy_frag->fr_type = rs_fill;
2875 dummy_frag->line = listing_tail;
2876 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2877 dummy_frag->fr_symbol = symbolP;
2878 }
2879 else
2880#endif
2881 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2882
2883#ifdef OBJ_COFF
2884 /* "set" symbols are local unless otherwise specified. */
2885 SF_SET_LOCAL (symbolP);
2886#endif /* OBJ_COFF */
2887 } /* Make a new symbol. */
2888
2889 symbol_table_insert (symbolP);
2890
2891 * end_name = delim;
2892
2893 if (equiv
2894 && S_IS_DEFINED (symbolP)
2895 && S_GET_SEGMENT (symbolP) != reg_section)
2896 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2897
2898 pseudo_set (symbolP);
2899
2900 demand_empty_rest_of_line ();
2901
c19d1205 2902 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2903
2904 THUMB_SET_FUNC (symbolP, 1);
2905 ARM_SET_THUMB (symbolP, 1);
2906#if defined OBJ_ELF || defined OBJ_COFF
2907 ARM_SET_INTERWORK (symbolP, support_interwork);
2908#endif
2909}
2910
c19d1205 2911/* Directives: Mode selection. */
b99bd4ef 2912
c19d1205
ZW
2913/* .syntax [unified|divided] - choose the new unified syntax
2914 (same for Arm and Thumb encoding, modulo slight differences in what
2915 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2916static void
c19d1205 2917s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2918{
c19d1205
ZW
2919 char *name, delim;
2920
2921 name = input_line_pointer;
2922 delim = get_symbol_end ();
2923
2924 if (!strcasecmp (name, "unified"))
2925 unified_syntax = TRUE;
2926 else if (!strcasecmp (name, "divided"))
2927 unified_syntax = FALSE;
2928 else
2929 {
2930 as_bad (_("unrecognized syntax mode \"%s\""), name);
2931 return;
2932 }
2933 *input_line_pointer = delim;
b99bd4ef
NC
2934 demand_empty_rest_of_line ();
2935}
2936
c19d1205
ZW
2937/* Directives: sectioning and alignment. */
2938
2939/* Same as s_align_ptwo but align 0 => align 2. */
2940
b99bd4ef 2941static void
c19d1205 2942s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2943{
a737bd4d 2944 int temp;
dce323d1 2945 bfd_boolean fill_p;
c19d1205
ZW
2946 long temp_fill;
2947 long max_alignment = 15;
b99bd4ef
NC
2948
2949 temp = get_absolute_expression ();
c19d1205
ZW
2950 if (temp > max_alignment)
2951 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2952 else if (temp < 0)
b99bd4ef 2953 {
c19d1205
ZW
2954 as_bad (_("alignment negative. 0 assumed."));
2955 temp = 0;
2956 }
b99bd4ef 2957
c19d1205
ZW
2958 if (*input_line_pointer == ',')
2959 {
2960 input_line_pointer++;
2961 temp_fill = get_absolute_expression ();
dce323d1 2962 fill_p = TRUE;
b99bd4ef 2963 }
c19d1205 2964 else
dce323d1
PB
2965 {
2966 fill_p = FALSE;
2967 temp_fill = 0;
2968 }
b99bd4ef 2969
c19d1205
ZW
2970 if (!temp)
2971 temp = 2;
b99bd4ef 2972
c19d1205
ZW
2973 /* Only make a frag if we HAVE to. */
2974 if (temp && !need_pass_2)
dce323d1
PB
2975 {
2976 if (!fill_p && subseg_text_p (now_seg))
2977 frag_align_code (temp, 0);
2978 else
2979 frag_align (temp, (int) temp_fill, 0);
2980 }
c19d1205
ZW
2981 demand_empty_rest_of_line ();
2982
2983 record_alignment (now_seg, temp);
b99bd4ef
NC
2984}
2985
c19d1205
ZW
2986static void
2987s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2988{
c19d1205
ZW
2989 /* We don't support putting frags in the BSS segment, we fake it by
2990 marking in_bss, then looking at s_skip for clues. */
2991 subseg_set (bss_section, 0);
2992 demand_empty_rest_of_line ();
cd000bff
DJ
2993
2994#ifdef md_elf_section_change_hook
2995 md_elf_section_change_hook ();
2996#endif
c19d1205 2997}
b99bd4ef 2998
c19d1205
ZW
2999static void
3000s_even (int ignore ATTRIBUTE_UNUSED)
3001{
3002 /* Never make frag if expect extra pass. */
3003 if (!need_pass_2)
3004 frag_align (1, 0, 0);
b99bd4ef 3005
c19d1205 3006 record_alignment (now_seg, 1);
b99bd4ef 3007
c19d1205 3008 demand_empty_rest_of_line ();
b99bd4ef
NC
3009}
3010
c19d1205 3011/* Directives: Literal pools. */
a737bd4d 3012
c19d1205
ZW
3013static literal_pool *
3014find_literal_pool (void)
a737bd4d 3015{
c19d1205 3016 literal_pool * pool;
a737bd4d 3017
c19d1205 3018 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3019 {
c19d1205
ZW
3020 if (pool->section == now_seg
3021 && pool->sub_section == now_subseg)
3022 break;
a737bd4d
NC
3023 }
3024
c19d1205 3025 return pool;
a737bd4d
NC
3026}
3027
c19d1205
ZW
3028static literal_pool *
3029find_or_make_literal_pool (void)
a737bd4d 3030{
c19d1205
ZW
3031 /* Next literal pool ID number. */
3032 static unsigned int latest_pool_num = 1;
3033 literal_pool * pool;
a737bd4d 3034
c19d1205 3035 pool = find_literal_pool ();
a737bd4d 3036
c19d1205 3037 if (pool == NULL)
a737bd4d 3038 {
c19d1205 3039 /* Create a new pool. */
21d799b5 3040 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
3041 if (! pool)
3042 return NULL;
a737bd4d 3043
c19d1205
ZW
3044 pool->next_free_entry = 0;
3045 pool->section = now_seg;
3046 pool->sub_section = now_subseg;
3047 pool->next = list_of_pools;
3048 pool->symbol = NULL;
3049
3050 /* Add it to the list. */
3051 list_of_pools = pool;
a737bd4d 3052 }
a737bd4d 3053
c19d1205
ZW
3054 /* New pools, and emptied pools, will have a NULL symbol. */
3055 if (pool->symbol == NULL)
a737bd4d 3056 {
c19d1205
ZW
3057 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3058 (valueT) 0, &zero_address_frag);
3059 pool->id = latest_pool_num ++;
a737bd4d
NC
3060 }
3061
c19d1205
ZW
3062 /* Done. */
3063 return pool;
a737bd4d
NC
3064}
3065
c19d1205 3066/* Add the literal in the global 'inst'
5f4273c7 3067 structure to the relevant literal pool. */
b99bd4ef
NC
3068
3069static int
c19d1205 3070add_to_lit_pool (void)
b99bd4ef 3071{
c19d1205
ZW
3072 literal_pool * pool;
3073 unsigned int entry;
b99bd4ef 3074
c19d1205
ZW
3075 pool = find_or_make_literal_pool ();
3076
3077 /* Check if this literal value is already in the pool. */
3078 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3079 {
c19d1205
ZW
3080 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3081 && (inst.reloc.exp.X_op == O_constant)
3082 && (pool->literals[entry].X_add_number
3083 == inst.reloc.exp.X_add_number)
3084 && (pool->literals[entry].X_unsigned
3085 == inst.reloc.exp.X_unsigned))
3086 break;
3087
3088 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3089 && (inst.reloc.exp.X_op == O_symbol)
3090 && (pool->literals[entry].X_add_number
3091 == inst.reloc.exp.X_add_number)
3092 && (pool->literals[entry].X_add_symbol
3093 == inst.reloc.exp.X_add_symbol)
3094 && (pool->literals[entry].X_op_symbol
3095 == inst.reloc.exp.X_op_symbol))
3096 break;
b99bd4ef
NC
3097 }
3098
c19d1205
ZW
3099 /* Do we need to create a new entry? */
3100 if (entry == pool->next_free_entry)
3101 {
3102 if (entry >= MAX_LITERAL_POOL_SIZE)
3103 {
3104 inst.error = _("literal pool overflow");
3105 return FAIL;
3106 }
3107
3108 pool->literals[entry] = inst.reloc.exp;
a8040cf2
NC
3109#ifdef OBJ_ELF
3110 /* PR ld/12974: Record the location of the first source line to reference
3111 this entry in the literal pool. If it turns out during linking that the
3112 symbol does not exist we will be able to give an accurate line number for
3113 the (first use of the) missing reference. */
3114 if (debug_type == DEBUG_DWARF2)
3115 dwarf2_where (pool->locs + entry);
3116#endif
c19d1205
ZW
3117 pool->next_free_entry += 1;
3118 }
b99bd4ef 3119
c19d1205
ZW
3120 inst.reloc.exp.X_op = O_symbol;
3121 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3122 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3123
c19d1205 3124 return SUCCESS;
b99bd4ef
NC
3125}
3126
c19d1205
ZW
3127/* Can't use symbol_new here, so have to create a symbol and then at
3128 a later date assign it a value. Thats what these functions do. */
e16bb312 3129
c19d1205
ZW
3130static void
3131symbol_locate (symbolS * symbolP,
3132 const char * name, /* It is copied, the caller can modify. */
3133 segT segment, /* Segment identifier (SEG_<something>). */
3134 valueT valu, /* Symbol value. */
3135 fragS * frag) /* Associated fragment. */
3136{
3137 unsigned int name_length;
3138 char * preserved_copy_of_name;
e16bb312 3139
c19d1205
ZW
3140 name_length = strlen (name) + 1; /* +1 for \0. */
3141 obstack_grow (&notes, name, name_length);
21d799b5 3142 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3143
c19d1205
ZW
3144#ifdef tc_canonicalize_symbol_name
3145 preserved_copy_of_name =
3146 tc_canonicalize_symbol_name (preserved_copy_of_name);
3147#endif
b99bd4ef 3148
c19d1205 3149 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3150
c19d1205
ZW
3151 S_SET_SEGMENT (symbolP, segment);
3152 S_SET_VALUE (symbolP, valu);
3153 symbol_clear_list_pointers (symbolP);
b99bd4ef 3154
c19d1205 3155 symbol_set_frag (symbolP, frag);
b99bd4ef 3156
c19d1205
ZW
3157 /* Link to end of symbol chain. */
3158 {
3159 extern int symbol_table_frozen;
b99bd4ef 3160
c19d1205
ZW
3161 if (symbol_table_frozen)
3162 abort ();
3163 }
b99bd4ef 3164
c19d1205 3165 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3166
c19d1205 3167 obj_symbol_new_hook (symbolP);
b99bd4ef 3168
c19d1205
ZW
3169#ifdef tc_symbol_new_hook
3170 tc_symbol_new_hook (symbolP);
3171#endif
3172
3173#ifdef DEBUG_SYMS
3174 verify_symbol_chain (symbol_rootP, symbol_lastP);
3175#endif /* DEBUG_SYMS */
b99bd4ef
NC
3176}
3177
b99bd4ef 3178
c19d1205
ZW
3179static void
3180s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3181{
c19d1205
ZW
3182 unsigned int entry;
3183 literal_pool * pool;
3184 char sym_name[20];
b99bd4ef 3185
c19d1205
ZW
3186 pool = find_literal_pool ();
3187 if (pool == NULL
3188 || pool->symbol == NULL
3189 || pool->next_free_entry == 0)
3190 return;
b99bd4ef 3191
c19d1205 3192 mapping_state (MAP_DATA);
b99bd4ef 3193
c19d1205
ZW
3194 /* Align pool as you have word accesses.
3195 Only make a frag if we have to. */
3196 if (!need_pass_2)
3197 frag_align (2, 0, 0);
b99bd4ef 3198
c19d1205 3199 record_alignment (now_seg, 2);
b99bd4ef 3200
c19d1205 3201 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3202
c19d1205
ZW
3203 symbol_locate (pool->symbol, sym_name, now_seg,
3204 (valueT) frag_now_fix (), frag_now);
3205 symbol_table_insert (pool->symbol);
b99bd4ef 3206
c19d1205 3207 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3208
c19d1205
ZW
3209#if defined OBJ_COFF || defined OBJ_ELF
3210 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3211#endif
6c43fab6 3212
c19d1205 3213 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3214 {
3215#ifdef OBJ_ELF
3216 if (debug_type == DEBUG_DWARF2)
3217 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3218#endif
3219 /* First output the expression in the instruction to the pool. */
3220 emit_expr (&(pool->literals[entry]), 4); /* .word */
3221 }
b99bd4ef 3222
c19d1205
ZW
3223 /* Mark the pool as empty. */
3224 pool->next_free_entry = 0;
3225 pool->symbol = NULL;
b99bd4ef
NC
3226}
3227
c19d1205
ZW
3228#ifdef OBJ_ELF
3229/* Forward declarations for functions below, in the MD interface
3230 section. */
3231static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3232static valueT create_unwind_entry (int);
3233static void start_unwind_section (const segT, int);
3234static void add_unwind_opcode (valueT, int);
3235static void flush_pending_unwind (void);
b99bd4ef 3236
c19d1205 3237/* Directives: Data. */
b99bd4ef 3238
c19d1205
ZW
3239static void
3240s_arm_elf_cons (int nbytes)
3241{
3242 expressionS exp;
b99bd4ef 3243
c19d1205
ZW
3244#ifdef md_flush_pending_output
3245 md_flush_pending_output ();
3246#endif
b99bd4ef 3247
c19d1205 3248 if (is_it_end_of_statement ())
b99bd4ef 3249 {
c19d1205
ZW
3250 demand_empty_rest_of_line ();
3251 return;
b99bd4ef
NC
3252 }
3253
c19d1205
ZW
3254#ifdef md_cons_align
3255 md_cons_align (nbytes);
3256#endif
b99bd4ef 3257
c19d1205
ZW
3258 mapping_state (MAP_DATA);
3259 do
b99bd4ef 3260 {
c19d1205
ZW
3261 int reloc;
3262 char *base = input_line_pointer;
b99bd4ef 3263
c19d1205 3264 expression (& exp);
b99bd4ef 3265
c19d1205
ZW
3266 if (exp.X_op != O_symbol)
3267 emit_expr (&exp, (unsigned int) nbytes);
3268 else
3269 {
3270 char *before_reloc = input_line_pointer;
3271 reloc = parse_reloc (&input_line_pointer);
3272 if (reloc == -1)
3273 {
3274 as_bad (_("unrecognized relocation suffix"));
3275 ignore_rest_of_line ();
3276 return;
3277 }
3278 else if (reloc == BFD_RELOC_UNUSED)
3279 emit_expr (&exp, (unsigned int) nbytes);
3280 else
3281 {
21d799b5
NC
3282 reloc_howto_type *howto = (reloc_howto_type *)
3283 bfd_reloc_type_lookup (stdoutput,
3284 (bfd_reloc_code_real_type) reloc);
c19d1205 3285 int size = bfd_get_reloc_size (howto);
b99bd4ef 3286
2fc8bdac
ZW
3287 if (reloc == BFD_RELOC_ARM_PLT32)
3288 {
3289 as_bad (_("(plt) is only valid on branch targets"));
3290 reloc = BFD_RELOC_UNUSED;
3291 size = 0;
3292 }
3293
c19d1205 3294 if (size > nbytes)
2fc8bdac 3295 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3296 howto->name, nbytes);
3297 else
3298 {
3299 /* We've parsed an expression stopping at O_symbol.
3300 But there may be more expression left now that we
3301 have parsed the relocation marker. Parse it again.
3302 XXX Surely there is a cleaner way to do this. */
3303 char *p = input_line_pointer;
3304 int offset;
21d799b5 3305 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3306 memcpy (save_buf, base, input_line_pointer - base);
3307 memmove (base + (input_line_pointer - before_reloc),
3308 base, before_reloc - base);
3309
3310 input_line_pointer = base + (input_line_pointer-before_reloc);
3311 expression (&exp);
3312 memcpy (base, save_buf, p - base);
3313
3314 offset = nbytes - size;
3315 p = frag_more ((int) nbytes);
3316 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3317 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3318 }
3319 }
3320 }
b99bd4ef 3321 }
c19d1205 3322 while (*input_line_pointer++ == ',');
b99bd4ef 3323
c19d1205
ZW
3324 /* Put terminator back into stream. */
3325 input_line_pointer --;
3326 demand_empty_rest_of_line ();
b99bd4ef
NC
3327}
3328
c921be7d
NC
3329/* Emit an expression containing a 32-bit thumb instruction.
3330 Implementation based on put_thumb32_insn. */
3331
3332static void
3333emit_thumb32_expr (expressionS * exp)
3334{
3335 expressionS exp_high = *exp;
3336
3337 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3338 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3339 exp->X_add_number &= 0xffff;
3340 emit_expr (exp, (unsigned int) THUMB_SIZE);
3341}
3342
3343/* Guess the instruction size based on the opcode. */
3344
3345static int
3346thumb_insn_size (int opcode)
3347{
3348 if ((unsigned int) opcode < 0xe800u)
3349 return 2;
3350 else if ((unsigned int) opcode >= 0xe8000000u)
3351 return 4;
3352 else
3353 return 0;
3354}
3355
3356static bfd_boolean
3357emit_insn (expressionS *exp, int nbytes)
3358{
3359 int size = 0;
3360
3361 if (exp->X_op == O_constant)
3362 {
3363 size = nbytes;
3364
3365 if (size == 0)
3366 size = thumb_insn_size (exp->X_add_number);
3367
3368 if (size != 0)
3369 {
3370 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3371 {
3372 as_bad (_(".inst.n operand too big. "\
3373 "Use .inst.w instead"));
3374 size = 0;
3375 }
3376 else
3377 {
3378 if (now_it.state == AUTOMATIC_IT_BLOCK)
3379 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3380 else
3381 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3382
3383 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3384 emit_thumb32_expr (exp);
3385 else
3386 emit_expr (exp, (unsigned int) size);
3387
3388 it_fsm_post_encode ();
3389 }
3390 }
3391 else
3392 as_bad (_("cannot determine Thumb instruction size. " \
3393 "Use .inst.n/.inst.w instead"));
3394 }
3395 else
3396 as_bad (_("constant expression required"));
3397
3398 return (size != 0);
3399}
3400
3401/* Like s_arm_elf_cons but do not use md_cons_align and
3402 set the mapping state to MAP_ARM/MAP_THUMB. */
3403
3404static void
3405s_arm_elf_inst (int nbytes)
3406{
3407 if (is_it_end_of_statement ())
3408 {
3409 demand_empty_rest_of_line ();
3410 return;
3411 }
3412
3413 /* Calling mapping_state () here will not change ARM/THUMB,
3414 but will ensure not to be in DATA state. */
3415
3416 if (thumb_mode)
3417 mapping_state (MAP_THUMB);
3418 else
3419 {
3420 if (nbytes != 0)
3421 {
3422 as_bad (_("width suffixes are invalid in ARM mode"));
3423 ignore_rest_of_line ();
3424 return;
3425 }
3426
3427 nbytes = 4;
3428
3429 mapping_state (MAP_ARM);
3430 }
3431
3432 do
3433 {
3434 expressionS exp;
3435
3436 expression (& exp);
3437
3438 if (! emit_insn (& exp, nbytes))
3439 {
3440 ignore_rest_of_line ();
3441 return;
3442 }
3443 }
3444 while (*input_line_pointer++ == ',');
3445
3446 /* Put terminator back into stream. */
3447 input_line_pointer --;
3448 demand_empty_rest_of_line ();
3449}
b99bd4ef 3450
c19d1205 3451/* Parse a .rel31 directive. */
b99bd4ef 3452
c19d1205
ZW
3453static void
3454s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3455{
3456 expressionS exp;
3457 char *p;
3458 valueT highbit;
b99bd4ef 3459
c19d1205
ZW
3460 highbit = 0;
3461 if (*input_line_pointer == '1')
3462 highbit = 0x80000000;
3463 else if (*input_line_pointer != '0')
3464 as_bad (_("expected 0 or 1"));
b99bd4ef 3465
c19d1205
ZW
3466 input_line_pointer++;
3467 if (*input_line_pointer != ',')
3468 as_bad (_("missing comma"));
3469 input_line_pointer++;
b99bd4ef 3470
c19d1205
ZW
3471#ifdef md_flush_pending_output
3472 md_flush_pending_output ();
3473#endif
b99bd4ef 3474
c19d1205
ZW
3475#ifdef md_cons_align
3476 md_cons_align (4);
3477#endif
b99bd4ef 3478
c19d1205 3479 mapping_state (MAP_DATA);
b99bd4ef 3480
c19d1205 3481 expression (&exp);
b99bd4ef 3482
c19d1205
ZW
3483 p = frag_more (4);
3484 md_number_to_chars (p, highbit, 4);
3485 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3486 BFD_RELOC_ARM_PREL31);
b99bd4ef 3487
c19d1205 3488 demand_empty_rest_of_line ();
b99bd4ef
NC
3489}
3490
c19d1205 3491/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3492
c19d1205 3493/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3494
c19d1205
ZW
3495static void
3496s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3497{
3498 demand_empty_rest_of_line ();
921e5f0a
PB
3499 if (unwind.proc_start)
3500 {
c921be7d 3501 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3502 return;
3503 }
3504
c19d1205
ZW
3505 /* Mark the start of the function. */
3506 unwind.proc_start = expr_build_dot ();
b99bd4ef 3507
c19d1205
ZW
3508 /* Reset the rest of the unwind info. */
3509 unwind.opcode_count = 0;
3510 unwind.table_entry = NULL;
3511 unwind.personality_routine = NULL;
3512 unwind.personality_index = -1;
3513 unwind.frame_size = 0;
3514 unwind.fp_offset = 0;
fdfde340 3515 unwind.fp_reg = REG_SP;
c19d1205
ZW
3516 unwind.fp_used = 0;
3517 unwind.sp_restored = 0;
3518}
b99bd4ef 3519
b99bd4ef 3520
c19d1205
ZW
3521/* Parse a handlerdata directive. Creates the exception handling table entry
3522 for the function. */
b99bd4ef 3523
c19d1205
ZW
3524static void
3525s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3526{
3527 demand_empty_rest_of_line ();
921e5f0a 3528 if (!unwind.proc_start)
c921be7d 3529 as_bad (MISSING_FNSTART);
921e5f0a 3530
c19d1205 3531 if (unwind.table_entry)
6decc662 3532 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3533
c19d1205
ZW
3534 create_unwind_entry (1);
3535}
a737bd4d 3536
c19d1205 3537/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3538
c19d1205
ZW
3539static void
3540s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3541{
3542 long where;
3543 char *ptr;
3544 valueT val;
940b5ce0 3545 unsigned int marked_pr_dependency;
f02232aa 3546
c19d1205 3547 demand_empty_rest_of_line ();
f02232aa 3548
921e5f0a
PB
3549 if (!unwind.proc_start)
3550 {
c921be7d 3551 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3552 return;
3553 }
3554
c19d1205
ZW
3555 /* Add eh table entry. */
3556 if (unwind.table_entry == NULL)
3557 val = create_unwind_entry (0);
3558 else
3559 val = 0;
f02232aa 3560
c19d1205
ZW
3561 /* Add index table entry. This is two words. */
3562 start_unwind_section (unwind.saved_seg, 1);
3563 frag_align (2, 0, 0);
3564 record_alignment (now_seg, 2);
b99bd4ef 3565
c19d1205 3566 ptr = frag_more (8);
5011093d 3567 memset (ptr, 0, 8);
c19d1205 3568 where = frag_now_fix () - 8;
f02232aa 3569
c19d1205
ZW
3570 /* Self relative offset of the function start. */
3571 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3572 BFD_RELOC_ARM_PREL31);
f02232aa 3573
c19d1205
ZW
3574 /* Indicate dependency on EHABI-defined personality routines to the
3575 linker, if it hasn't been done already. */
940b5ce0
DJ
3576 marked_pr_dependency
3577 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3578 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3579 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3580 {
5f4273c7
NC
3581 static const char *const name[] =
3582 {
3583 "__aeabi_unwind_cpp_pr0",
3584 "__aeabi_unwind_cpp_pr1",
3585 "__aeabi_unwind_cpp_pr2"
3586 };
c19d1205
ZW
3587 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3588 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3589 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3590 |= 1 << unwind.personality_index;
c19d1205 3591 }
f02232aa 3592
c19d1205
ZW
3593 if (val)
3594 /* Inline exception table entry. */
3595 md_number_to_chars (ptr + 4, val, 4);
3596 else
3597 /* Self relative offset of the table entry. */
3598 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3599 BFD_RELOC_ARM_PREL31);
f02232aa 3600
c19d1205
ZW
3601 /* Restore the original section. */
3602 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3603
3604 unwind.proc_start = NULL;
c19d1205 3605}
f02232aa 3606
f02232aa 3607
c19d1205 3608/* Parse an unwind_cantunwind directive. */
b99bd4ef 3609
c19d1205
ZW
3610static void
3611s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3612{
3613 demand_empty_rest_of_line ();
921e5f0a 3614 if (!unwind.proc_start)
c921be7d 3615 as_bad (MISSING_FNSTART);
921e5f0a 3616
c19d1205
ZW
3617 if (unwind.personality_routine || unwind.personality_index != -1)
3618 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3619
c19d1205
ZW
3620 unwind.personality_index = -2;
3621}
b99bd4ef 3622
b99bd4ef 3623
c19d1205 3624/* Parse a personalityindex directive. */
b99bd4ef 3625
c19d1205
ZW
3626static void
3627s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3628{
3629 expressionS exp;
b99bd4ef 3630
921e5f0a 3631 if (!unwind.proc_start)
c921be7d 3632 as_bad (MISSING_FNSTART);
921e5f0a 3633
c19d1205
ZW
3634 if (unwind.personality_routine || unwind.personality_index != -1)
3635 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3636
c19d1205 3637 expression (&exp);
b99bd4ef 3638
c19d1205
ZW
3639 if (exp.X_op != O_constant
3640 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3641 {
c19d1205
ZW
3642 as_bad (_("bad personality routine number"));
3643 ignore_rest_of_line ();
3644 return;
b99bd4ef
NC
3645 }
3646
c19d1205 3647 unwind.personality_index = exp.X_add_number;
b99bd4ef 3648
c19d1205
ZW
3649 demand_empty_rest_of_line ();
3650}
e16bb312 3651
e16bb312 3652
c19d1205 3653/* Parse a personality directive. */
e16bb312 3654
c19d1205
ZW
3655static void
3656s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3657{
3658 char *name, *p, c;
a737bd4d 3659
921e5f0a 3660 if (!unwind.proc_start)
c921be7d 3661 as_bad (MISSING_FNSTART);
921e5f0a 3662
c19d1205
ZW
3663 if (unwind.personality_routine || unwind.personality_index != -1)
3664 as_bad (_("duplicate .personality directive"));
a737bd4d 3665
c19d1205
ZW
3666 name = input_line_pointer;
3667 c = get_symbol_end ();
3668 p = input_line_pointer;
3669 unwind.personality_routine = symbol_find_or_make (name);
3670 *p = c;
3671 demand_empty_rest_of_line ();
3672}
e16bb312 3673
e16bb312 3674
c19d1205 3675/* Parse a directive saving core registers. */
e16bb312 3676
c19d1205
ZW
3677static void
3678s_arm_unwind_save_core (void)
e16bb312 3679{
c19d1205
ZW
3680 valueT op;
3681 long range;
3682 int n;
e16bb312 3683
c19d1205
ZW
3684 range = parse_reg_list (&input_line_pointer);
3685 if (range == FAIL)
e16bb312 3686 {
c19d1205
ZW
3687 as_bad (_("expected register list"));
3688 ignore_rest_of_line ();
3689 return;
3690 }
e16bb312 3691
c19d1205 3692 demand_empty_rest_of_line ();
e16bb312 3693
c19d1205
ZW
3694 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3695 into .unwind_save {..., sp...}. We aren't bothered about the value of
3696 ip because it is clobbered by calls. */
3697 if (unwind.sp_restored && unwind.fp_reg == 12
3698 && (range & 0x3000) == 0x1000)
3699 {
3700 unwind.opcode_count--;
3701 unwind.sp_restored = 0;
3702 range = (range | 0x2000) & ~0x1000;
3703 unwind.pending_offset = 0;
3704 }
e16bb312 3705
01ae4198
DJ
3706 /* Pop r4-r15. */
3707 if (range & 0xfff0)
c19d1205 3708 {
01ae4198
DJ
3709 /* See if we can use the short opcodes. These pop a block of up to 8
3710 registers starting with r4, plus maybe r14. */
3711 for (n = 0; n < 8; n++)
3712 {
3713 /* Break at the first non-saved register. */
3714 if ((range & (1 << (n + 4))) == 0)
3715 break;
3716 }
3717 /* See if there are any other bits set. */
3718 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3719 {
3720 /* Use the long form. */
3721 op = 0x8000 | ((range >> 4) & 0xfff);
3722 add_unwind_opcode (op, 2);
3723 }
0dd132b6 3724 else
01ae4198
DJ
3725 {
3726 /* Use the short form. */
3727 if (range & 0x4000)
3728 op = 0xa8; /* Pop r14. */
3729 else
3730 op = 0xa0; /* Do not pop r14. */
3731 op |= (n - 1);
3732 add_unwind_opcode (op, 1);
3733 }
c19d1205 3734 }
0dd132b6 3735
c19d1205
ZW
3736 /* Pop r0-r3. */
3737 if (range & 0xf)
3738 {
3739 op = 0xb100 | (range & 0xf);
3740 add_unwind_opcode (op, 2);
0dd132b6
NC
3741 }
3742
c19d1205
ZW
3743 /* Record the number of bytes pushed. */
3744 for (n = 0; n < 16; n++)
3745 {
3746 if (range & (1 << n))
3747 unwind.frame_size += 4;
3748 }
0dd132b6
NC
3749}
3750
c19d1205
ZW
3751
3752/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3753
3754static void
c19d1205 3755s_arm_unwind_save_fpa (int reg)
b99bd4ef 3756{
c19d1205
ZW
3757 expressionS exp;
3758 int num_regs;
3759 valueT op;
b99bd4ef 3760
c19d1205
ZW
3761 /* Get Number of registers to transfer. */
3762 if (skip_past_comma (&input_line_pointer) != FAIL)
3763 expression (&exp);
3764 else
3765 exp.X_op = O_illegal;
b99bd4ef 3766
c19d1205 3767 if (exp.X_op != O_constant)
b99bd4ef 3768 {
c19d1205
ZW
3769 as_bad (_("expected , <constant>"));
3770 ignore_rest_of_line ();
b99bd4ef
NC
3771 return;
3772 }
3773
c19d1205
ZW
3774 num_regs = exp.X_add_number;
3775
3776 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3777 {
c19d1205
ZW
3778 as_bad (_("number of registers must be in the range [1:4]"));
3779 ignore_rest_of_line ();
b99bd4ef
NC
3780 return;
3781 }
3782
c19d1205 3783 demand_empty_rest_of_line ();
b99bd4ef 3784
c19d1205
ZW
3785 if (reg == 4)
3786 {
3787 /* Short form. */
3788 op = 0xb4 | (num_regs - 1);
3789 add_unwind_opcode (op, 1);
3790 }
b99bd4ef
NC
3791 else
3792 {
c19d1205
ZW
3793 /* Long form. */
3794 op = 0xc800 | (reg << 4) | (num_regs - 1);
3795 add_unwind_opcode (op, 2);
b99bd4ef 3796 }
c19d1205 3797 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3798}
3799
c19d1205 3800
fa073d69
MS
3801/* Parse a directive saving VFP registers for ARMv6 and above. */
3802
3803static void
3804s_arm_unwind_save_vfp_armv6 (void)
3805{
3806 int count;
3807 unsigned int start;
3808 valueT op;
3809 int num_vfpv3_regs = 0;
3810 int num_regs_below_16;
3811
3812 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3813 if (count == FAIL)
3814 {
3815 as_bad (_("expected register list"));
3816 ignore_rest_of_line ();
3817 return;
3818 }
3819
3820 demand_empty_rest_of_line ();
3821
3822 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3823 than FSTMX/FLDMX-style ones). */
3824
3825 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3826 if (start >= 16)
3827 num_vfpv3_regs = count;
3828 else if (start + count > 16)
3829 num_vfpv3_regs = start + count - 16;
3830
3831 if (num_vfpv3_regs > 0)
3832 {
3833 int start_offset = start > 16 ? start - 16 : 0;
3834 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3835 add_unwind_opcode (op, 2);
3836 }
3837
3838 /* Generate opcode for registers numbered in the range 0 .. 15. */
3839 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3840 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3841 if (num_regs_below_16 > 0)
3842 {
3843 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3844 add_unwind_opcode (op, 2);
3845 }
3846
3847 unwind.frame_size += count * 8;
3848}
3849
3850
3851/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3852
3853static void
c19d1205 3854s_arm_unwind_save_vfp (void)
b99bd4ef 3855{
c19d1205 3856 int count;
ca3f61f7 3857 unsigned int reg;
c19d1205 3858 valueT op;
b99bd4ef 3859
5287ad62 3860 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3861 if (count == FAIL)
b99bd4ef 3862 {
c19d1205
ZW
3863 as_bad (_("expected register list"));
3864 ignore_rest_of_line ();
b99bd4ef
NC
3865 return;
3866 }
3867
c19d1205 3868 demand_empty_rest_of_line ();
b99bd4ef 3869
c19d1205 3870 if (reg == 8)
b99bd4ef 3871 {
c19d1205
ZW
3872 /* Short form. */
3873 op = 0xb8 | (count - 1);
3874 add_unwind_opcode (op, 1);
b99bd4ef 3875 }
c19d1205 3876 else
b99bd4ef 3877 {
c19d1205
ZW
3878 /* Long form. */
3879 op = 0xb300 | (reg << 4) | (count - 1);
3880 add_unwind_opcode (op, 2);
b99bd4ef 3881 }
c19d1205
ZW
3882 unwind.frame_size += count * 8 + 4;
3883}
b99bd4ef 3884
b99bd4ef 3885
c19d1205
ZW
3886/* Parse a directive saving iWMMXt data registers. */
3887
3888static void
3889s_arm_unwind_save_mmxwr (void)
3890{
3891 int reg;
3892 int hi_reg;
3893 int i;
3894 unsigned mask = 0;
3895 valueT op;
b99bd4ef 3896
c19d1205
ZW
3897 if (*input_line_pointer == '{')
3898 input_line_pointer++;
b99bd4ef 3899
c19d1205 3900 do
b99bd4ef 3901 {
dcbf9037 3902 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3903
c19d1205 3904 if (reg == FAIL)
b99bd4ef 3905 {
9b7132d3 3906 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3907 goto error;
b99bd4ef
NC
3908 }
3909
c19d1205
ZW
3910 if (mask >> reg)
3911 as_tsktsk (_("register list not in ascending order"));
3912 mask |= 1 << reg;
b99bd4ef 3913
c19d1205
ZW
3914 if (*input_line_pointer == '-')
3915 {
3916 input_line_pointer++;
dcbf9037 3917 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3918 if (hi_reg == FAIL)
3919 {
9b7132d3 3920 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3921 goto error;
3922 }
3923 else if (reg >= hi_reg)
3924 {
3925 as_bad (_("bad register range"));
3926 goto error;
3927 }
3928 for (; reg < hi_reg; reg++)
3929 mask |= 1 << reg;
3930 }
3931 }
3932 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3933
c19d1205
ZW
3934 if (*input_line_pointer == '}')
3935 input_line_pointer++;
b99bd4ef 3936
c19d1205 3937 demand_empty_rest_of_line ();
b99bd4ef 3938
708587a4 3939 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3940 the list. */
3941 flush_pending_unwind ();
b99bd4ef 3942
c19d1205 3943 for (i = 0; i < 16; i++)
b99bd4ef 3944 {
c19d1205
ZW
3945 if (mask & (1 << i))
3946 unwind.frame_size += 8;
b99bd4ef
NC
3947 }
3948
c19d1205
ZW
3949 /* Attempt to combine with a previous opcode. We do this because gcc
3950 likes to output separate unwind directives for a single block of
3951 registers. */
3952 if (unwind.opcode_count > 0)
b99bd4ef 3953 {
c19d1205
ZW
3954 i = unwind.opcodes[unwind.opcode_count - 1];
3955 if ((i & 0xf8) == 0xc0)
3956 {
3957 i &= 7;
3958 /* Only merge if the blocks are contiguous. */
3959 if (i < 6)
3960 {
3961 if ((mask & 0xfe00) == (1 << 9))
3962 {
3963 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3964 unwind.opcode_count--;
3965 }
3966 }
3967 else if (i == 6 && unwind.opcode_count >= 2)
3968 {
3969 i = unwind.opcodes[unwind.opcode_count - 2];
3970 reg = i >> 4;
3971 i &= 0xf;
b99bd4ef 3972
c19d1205
ZW
3973 op = 0xffff << (reg - 1);
3974 if (reg > 0
87a1fd79 3975 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3976 {
3977 op = (1 << (reg + i + 1)) - 1;
3978 op &= ~((1 << reg) - 1);
3979 mask |= op;
3980 unwind.opcode_count -= 2;
3981 }
3982 }
3983 }
b99bd4ef
NC
3984 }
3985
c19d1205
ZW
3986 hi_reg = 15;
3987 /* We want to generate opcodes in the order the registers have been
3988 saved, ie. descending order. */
3989 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3990 {
c19d1205
ZW
3991 /* Save registers in blocks. */
3992 if (reg < 0
3993 || !(mask & (1 << reg)))
3994 {
3995 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3996 preceding block. */
c19d1205
ZW
3997 if (reg != hi_reg)
3998 {
3999 if (reg == 9)
4000 {
4001 /* Short form. */
4002 op = 0xc0 | (hi_reg - 10);
4003 add_unwind_opcode (op, 1);
4004 }
4005 else
4006 {
4007 /* Long form. */
4008 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4009 add_unwind_opcode (op, 2);
4010 }
4011 }
4012 hi_reg = reg - 1;
4013 }
b99bd4ef
NC
4014 }
4015
c19d1205
ZW
4016 return;
4017error:
4018 ignore_rest_of_line ();
b99bd4ef
NC
4019}
4020
4021static void
c19d1205 4022s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4023{
c19d1205
ZW
4024 int reg;
4025 int hi_reg;
4026 unsigned mask = 0;
4027 valueT op;
b99bd4ef 4028
c19d1205
ZW
4029 if (*input_line_pointer == '{')
4030 input_line_pointer++;
b99bd4ef 4031
c19d1205 4032 do
b99bd4ef 4033 {
dcbf9037 4034 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4035
c19d1205
ZW
4036 if (reg == FAIL)
4037 {
9b7132d3 4038 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4039 goto error;
4040 }
b99bd4ef 4041
c19d1205
ZW
4042 reg -= 8;
4043 if (mask >> reg)
4044 as_tsktsk (_("register list not in ascending order"));
4045 mask |= 1 << reg;
b99bd4ef 4046
c19d1205
ZW
4047 if (*input_line_pointer == '-')
4048 {
4049 input_line_pointer++;
dcbf9037 4050 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4051 if (hi_reg == FAIL)
4052 {
9b7132d3 4053 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4054 goto error;
4055 }
4056 else if (reg >= hi_reg)
4057 {
4058 as_bad (_("bad register range"));
4059 goto error;
4060 }
4061 for (; reg < hi_reg; reg++)
4062 mask |= 1 << reg;
4063 }
b99bd4ef 4064 }
c19d1205 4065 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4066
c19d1205
ZW
4067 if (*input_line_pointer == '}')
4068 input_line_pointer++;
b99bd4ef 4069
c19d1205
ZW
4070 demand_empty_rest_of_line ();
4071
708587a4 4072 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4073 the list. */
4074 flush_pending_unwind ();
b99bd4ef 4075
c19d1205 4076 for (reg = 0; reg < 16; reg++)
b99bd4ef 4077 {
c19d1205
ZW
4078 if (mask & (1 << reg))
4079 unwind.frame_size += 4;
b99bd4ef 4080 }
c19d1205
ZW
4081 op = 0xc700 | mask;
4082 add_unwind_opcode (op, 2);
4083 return;
4084error:
4085 ignore_rest_of_line ();
b99bd4ef
NC
4086}
4087
c19d1205 4088
fa073d69
MS
4089/* Parse an unwind_save directive.
4090 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4091
b99bd4ef 4092static void
fa073d69 4093s_arm_unwind_save (int arch_v6)
b99bd4ef 4094{
c19d1205
ZW
4095 char *peek;
4096 struct reg_entry *reg;
4097 bfd_boolean had_brace = FALSE;
b99bd4ef 4098
921e5f0a 4099 if (!unwind.proc_start)
c921be7d 4100 as_bad (MISSING_FNSTART);
921e5f0a 4101
c19d1205
ZW
4102 /* Figure out what sort of save we have. */
4103 peek = input_line_pointer;
b99bd4ef 4104
c19d1205 4105 if (*peek == '{')
b99bd4ef 4106 {
c19d1205
ZW
4107 had_brace = TRUE;
4108 peek++;
b99bd4ef
NC
4109 }
4110
c19d1205 4111 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4112
c19d1205 4113 if (!reg)
b99bd4ef 4114 {
c19d1205
ZW
4115 as_bad (_("register expected"));
4116 ignore_rest_of_line ();
b99bd4ef
NC
4117 return;
4118 }
4119
c19d1205 4120 switch (reg->type)
b99bd4ef 4121 {
c19d1205
ZW
4122 case REG_TYPE_FN:
4123 if (had_brace)
4124 {
4125 as_bad (_("FPA .unwind_save does not take a register list"));
4126 ignore_rest_of_line ();
4127 return;
4128 }
93ac2687 4129 input_line_pointer = peek;
c19d1205 4130 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4131 return;
c19d1205
ZW
4132
4133 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
4134 case REG_TYPE_VFD:
4135 if (arch_v6)
4136 s_arm_unwind_save_vfp_armv6 ();
4137 else
4138 s_arm_unwind_save_vfp ();
4139 return;
c19d1205
ZW
4140 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4141 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4142
4143 default:
4144 as_bad (_(".unwind_save does not support this kind of register"));
4145 ignore_rest_of_line ();
b99bd4ef 4146 }
c19d1205 4147}
b99bd4ef 4148
b99bd4ef 4149
c19d1205
ZW
4150/* Parse an unwind_movsp directive. */
4151
4152static void
4153s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4154{
4155 int reg;
4156 valueT op;
4fa3602b 4157 int offset;
c19d1205 4158
921e5f0a 4159 if (!unwind.proc_start)
c921be7d 4160 as_bad (MISSING_FNSTART);
921e5f0a 4161
dcbf9037 4162 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4163 if (reg == FAIL)
b99bd4ef 4164 {
9b7132d3 4165 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4166 ignore_rest_of_line ();
b99bd4ef
NC
4167 return;
4168 }
4fa3602b
PB
4169
4170 /* Optional constant. */
4171 if (skip_past_comma (&input_line_pointer) != FAIL)
4172 {
4173 if (immediate_for_directive (&offset) == FAIL)
4174 return;
4175 }
4176 else
4177 offset = 0;
4178
c19d1205 4179 demand_empty_rest_of_line ();
b99bd4ef 4180
c19d1205 4181 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4182 {
c19d1205 4183 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4184 return;
4185 }
4186
c19d1205
ZW
4187 if (unwind.fp_reg != REG_SP)
4188 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4189
c19d1205
ZW
4190 /* Generate opcode to restore the value. */
4191 op = 0x90 | reg;
4192 add_unwind_opcode (op, 1);
4193
4194 /* Record the information for later. */
4195 unwind.fp_reg = reg;
4fa3602b 4196 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4197 unwind.sp_restored = 1;
b05fe5cf
ZW
4198}
4199
c19d1205
ZW
4200/* Parse an unwind_pad directive. */
4201
b05fe5cf 4202static void
c19d1205 4203s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4204{
c19d1205 4205 int offset;
b05fe5cf 4206
921e5f0a 4207 if (!unwind.proc_start)
c921be7d 4208 as_bad (MISSING_FNSTART);
921e5f0a 4209
c19d1205
ZW
4210 if (immediate_for_directive (&offset) == FAIL)
4211 return;
b99bd4ef 4212
c19d1205
ZW
4213 if (offset & 3)
4214 {
4215 as_bad (_("stack increment must be multiple of 4"));
4216 ignore_rest_of_line ();
4217 return;
4218 }
b99bd4ef 4219
c19d1205
ZW
4220 /* Don't generate any opcodes, just record the details for later. */
4221 unwind.frame_size += offset;
4222 unwind.pending_offset += offset;
4223
4224 demand_empty_rest_of_line ();
4225}
4226
4227/* Parse an unwind_setfp directive. */
4228
4229static void
4230s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4231{
c19d1205
ZW
4232 int sp_reg;
4233 int fp_reg;
4234 int offset;
4235
921e5f0a 4236 if (!unwind.proc_start)
c921be7d 4237 as_bad (MISSING_FNSTART);
921e5f0a 4238
dcbf9037 4239 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4240 if (skip_past_comma (&input_line_pointer) == FAIL)
4241 sp_reg = FAIL;
4242 else
dcbf9037 4243 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4244
c19d1205
ZW
4245 if (fp_reg == FAIL || sp_reg == FAIL)
4246 {
4247 as_bad (_("expected <reg>, <reg>"));
4248 ignore_rest_of_line ();
4249 return;
4250 }
b99bd4ef 4251
c19d1205
ZW
4252 /* Optional constant. */
4253 if (skip_past_comma (&input_line_pointer) != FAIL)
4254 {
4255 if (immediate_for_directive (&offset) == FAIL)
4256 return;
4257 }
4258 else
4259 offset = 0;
a737bd4d 4260
c19d1205 4261 demand_empty_rest_of_line ();
a737bd4d 4262
fdfde340 4263 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4264 {
c19d1205
ZW
4265 as_bad (_("register must be either sp or set by a previous"
4266 "unwind_movsp directive"));
4267 return;
a737bd4d
NC
4268 }
4269
c19d1205
ZW
4270 /* Don't generate any opcodes, just record the information for later. */
4271 unwind.fp_reg = fp_reg;
4272 unwind.fp_used = 1;
fdfde340 4273 if (sp_reg == REG_SP)
c19d1205
ZW
4274 unwind.fp_offset = unwind.frame_size - offset;
4275 else
4276 unwind.fp_offset -= offset;
a737bd4d
NC
4277}
4278
c19d1205
ZW
4279/* Parse an unwind_raw directive. */
4280
4281static void
4282s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4283{
c19d1205 4284 expressionS exp;
708587a4 4285 /* This is an arbitrary limit. */
c19d1205
ZW
4286 unsigned char op[16];
4287 int count;
a737bd4d 4288
921e5f0a 4289 if (!unwind.proc_start)
c921be7d 4290 as_bad (MISSING_FNSTART);
921e5f0a 4291
c19d1205
ZW
4292 expression (&exp);
4293 if (exp.X_op == O_constant
4294 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4295 {
c19d1205
ZW
4296 unwind.frame_size += exp.X_add_number;
4297 expression (&exp);
4298 }
4299 else
4300 exp.X_op = O_illegal;
a737bd4d 4301
c19d1205
ZW
4302 if (exp.X_op != O_constant)
4303 {
4304 as_bad (_("expected <offset>, <opcode>"));
4305 ignore_rest_of_line ();
4306 return;
4307 }
a737bd4d 4308
c19d1205 4309 count = 0;
a737bd4d 4310
c19d1205
ZW
4311 /* Parse the opcode. */
4312 for (;;)
4313 {
4314 if (count >= 16)
4315 {
4316 as_bad (_("unwind opcode too long"));
4317 ignore_rest_of_line ();
a737bd4d 4318 }
c19d1205 4319 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4320 {
c19d1205
ZW
4321 as_bad (_("invalid unwind opcode"));
4322 ignore_rest_of_line ();
4323 return;
a737bd4d 4324 }
c19d1205 4325 op[count++] = exp.X_add_number;
a737bd4d 4326
c19d1205
ZW
4327 /* Parse the next byte. */
4328 if (skip_past_comma (&input_line_pointer) == FAIL)
4329 break;
a737bd4d 4330
c19d1205
ZW
4331 expression (&exp);
4332 }
b99bd4ef 4333
c19d1205
ZW
4334 /* Add the opcode bytes in reverse order. */
4335 while (count--)
4336 add_unwind_opcode (op[count], 1);
b99bd4ef 4337
c19d1205 4338 demand_empty_rest_of_line ();
b99bd4ef 4339}
ee065d83
PB
4340
4341
4342/* Parse a .eabi_attribute directive. */
4343
4344static void
4345s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4346{
0420f52b 4347 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4348
4349 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4350 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4351}
4352
0855e32b
NS
4353/* Emit a tls fix for the symbol. */
4354
4355static void
4356s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4357{
4358 char *p;
4359 expressionS exp;
4360#ifdef md_flush_pending_output
4361 md_flush_pending_output ();
4362#endif
4363
4364#ifdef md_cons_align
4365 md_cons_align (4);
4366#endif
4367
4368 /* Since we're just labelling the code, there's no need to define a
4369 mapping symbol. */
4370 expression (&exp);
4371 p = obstack_next_free (&frchain_now->frch_obstack);
4372 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4373 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4374 : BFD_RELOC_ARM_TLS_DESCSEQ);
4375}
cdf9ccec 4376#endif /* OBJ_ELF */
0855e32b 4377
ee065d83 4378static void s_arm_arch (int);
7a1d4c38 4379static void s_arm_object_arch (int);
ee065d83
PB
4380static void s_arm_cpu (int);
4381static void s_arm_fpu (int);
69133863 4382static void s_arm_arch_extension (int);
b99bd4ef 4383
f0927246
NC
4384#ifdef TE_PE
4385
4386static void
5f4273c7 4387pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4388{
4389 expressionS exp;
4390
4391 do
4392 {
4393 expression (&exp);
4394 if (exp.X_op == O_symbol)
4395 exp.X_op = O_secrel;
4396
4397 emit_expr (&exp, 4);
4398 }
4399 while (*input_line_pointer++ == ',');
4400
4401 input_line_pointer--;
4402 demand_empty_rest_of_line ();
4403}
4404#endif /* TE_PE */
4405
c19d1205
ZW
4406/* This table describes all the machine specific pseudo-ops the assembler
4407 has to support. The fields are:
4408 pseudo-op name without dot
4409 function to call to execute this pseudo-op
4410 Integer arg to pass to the function. */
b99bd4ef 4411
c19d1205 4412const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4413{
c19d1205
ZW
4414 /* Never called because '.req' does not start a line. */
4415 { "req", s_req, 0 },
dcbf9037
JB
4416 /* Following two are likewise never called. */
4417 { "dn", s_dn, 0 },
4418 { "qn", s_qn, 0 },
c19d1205
ZW
4419 { "unreq", s_unreq, 0 },
4420 { "bss", s_bss, 0 },
4421 { "align", s_align, 0 },
4422 { "arm", s_arm, 0 },
4423 { "thumb", s_thumb, 0 },
4424 { "code", s_code, 0 },
4425 { "force_thumb", s_force_thumb, 0 },
4426 { "thumb_func", s_thumb_func, 0 },
4427 { "thumb_set", s_thumb_set, 0 },
4428 { "even", s_even, 0 },
4429 { "ltorg", s_ltorg, 0 },
4430 { "pool", s_ltorg, 0 },
4431 { "syntax", s_syntax, 0 },
8463be01
PB
4432 { "cpu", s_arm_cpu, 0 },
4433 { "arch", s_arm_arch, 0 },
7a1d4c38 4434 { "object_arch", s_arm_object_arch, 0 },
8463be01 4435 { "fpu", s_arm_fpu, 0 },
69133863 4436 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4437#ifdef OBJ_ELF
c921be7d
NC
4438 { "word", s_arm_elf_cons, 4 },
4439 { "long", s_arm_elf_cons, 4 },
4440 { "inst.n", s_arm_elf_inst, 2 },
4441 { "inst.w", s_arm_elf_inst, 4 },
4442 { "inst", s_arm_elf_inst, 0 },
4443 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4444 { "fnstart", s_arm_unwind_fnstart, 0 },
4445 { "fnend", s_arm_unwind_fnend, 0 },
4446 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4447 { "personality", s_arm_unwind_personality, 0 },
4448 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4449 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4450 { "save", s_arm_unwind_save, 0 },
fa073d69 4451 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4452 { "movsp", s_arm_unwind_movsp, 0 },
4453 { "pad", s_arm_unwind_pad, 0 },
4454 { "setfp", s_arm_unwind_setfp, 0 },
4455 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4456 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4457 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4458#else
4459 { "word", cons, 4},
f0927246
NC
4460
4461 /* These are used for dwarf. */
4462 {"2byte", cons, 2},
4463 {"4byte", cons, 4},
4464 {"8byte", cons, 8},
4465 /* These are used for dwarf2. */
4466 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4467 { "loc", dwarf2_directive_loc, 0 },
4468 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4469#endif
4470 { "extend", float_cons, 'x' },
4471 { "ldouble", float_cons, 'x' },
4472 { "packed", float_cons, 'p' },
f0927246
NC
4473#ifdef TE_PE
4474 {"secrel32", pe_directive_secrel, 0},
4475#endif
c19d1205
ZW
4476 { 0, 0, 0 }
4477};
4478\f
4479/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4480
c19d1205
ZW
4481/* Generic immediate-value read function for use in insn parsing.
4482 STR points to the beginning of the immediate (the leading #);
4483 VAL receives the value; if the value is outside [MIN, MAX]
4484 issue an error. PREFIX_OPT is true if the immediate prefix is
4485 optional. */
b99bd4ef 4486
c19d1205
ZW
4487static int
4488parse_immediate (char **str, int *val, int min, int max,
4489 bfd_boolean prefix_opt)
4490{
4491 expressionS exp;
4492 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4493 if (exp.X_op != O_constant)
b99bd4ef 4494 {
c19d1205
ZW
4495 inst.error = _("constant expression required");
4496 return FAIL;
4497 }
b99bd4ef 4498
c19d1205
ZW
4499 if (exp.X_add_number < min || exp.X_add_number > max)
4500 {
4501 inst.error = _("immediate value out of range");
4502 return FAIL;
4503 }
b99bd4ef 4504
c19d1205
ZW
4505 *val = exp.X_add_number;
4506 return SUCCESS;
4507}
b99bd4ef 4508
5287ad62 4509/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4510 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4511 instructions. Puts the result directly in inst.operands[i]. */
4512
4513static int
4514parse_big_immediate (char **str, int i)
4515{
4516 expressionS exp;
4517 char *ptr = *str;
4518
4519 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4520
4521 if (exp.X_op == O_constant)
036dc3f7
PB
4522 {
4523 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4524 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4525 O_constant. We have to be careful not to break compilation for
4526 32-bit X_add_number, though. */
58ad575f 4527 if ((exp.X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7
PB
4528 {
4529 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4530 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4531 inst.operands[i].regisimm = 1;
4532 }
4533 }
5287ad62 4534 else if (exp.X_op == O_big
95b75c01 4535 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
5287ad62
JB
4536 {
4537 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4538
5287ad62
JB
4539 /* Bignums have their least significant bits in
4540 generic_bignum[0]. Make sure we put 32 bits in imm and
4541 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4542 gas_assert (parts != 0);
95b75c01
NC
4543
4544 /* Make sure that the number is not too big.
4545 PR 11972: Bignums can now be sign-extended to the
4546 size of a .octa so check that the out of range bits
4547 are all zero or all one. */
4548 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4549 {
4550 LITTLENUM_TYPE m = -1;
4551
4552 if (generic_bignum[parts * 2] != 0
4553 && generic_bignum[parts * 2] != m)
4554 return FAIL;
4555
4556 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4557 if (generic_bignum[j] != generic_bignum[j-1])
4558 return FAIL;
4559 }
4560
5287ad62
JB
4561 inst.operands[i].imm = 0;
4562 for (j = 0; j < parts; j++, idx++)
4563 inst.operands[i].imm |= generic_bignum[idx]
4564 << (LITTLENUM_NUMBER_OF_BITS * j);
4565 inst.operands[i].reg = 0;
4566 for (j = 0; j < parts; j++, idx++)
4567 inst.operands[i].reg |= generic_bignum[idx]
4568 << (LITTLENUM_NUMBER_OF_BITS * j);
4569 inst.operands[i].regisimm = 1;
4570 }
4571 else
4572 return FAIL;
5f4273c7 4573
5287ad62
JB
4574 *str = ptr;
4575
4576 return SUCCESS;
4577}
4578
c19d1205
ZW
4579/* Returns the pseudo-register number of an FPA immediate constant,
4580 or FAIL if there isn't a valid constant here. */
b99bd4ef 4581
c19d1205
ZW
4582static int
4583parse_fpa_immediate (char ** str)
4584{
4585 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4586 char * save_in;
4587 expressionS exp;
4588 int i;
4589 int j;
b99bd4ef 4590
c19d1205
ZW
4591 /* First try and match exact strings, this is to guarantee
4592 that some formats will work even for cross assembly. */
b99bd4ef 4593
c19d1205
ZW
4594 for (i = 0; fp_const[i]; i++)
4595 {
4596 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4597 {
c19d1205 4598 char *start = *str;
b99bd4ef 4599
c19d1205
ZW
4600 *str += strlen (fp_const[i]);
4601 if (is_end_of_line[(unsigned char) **str])
4602 return i + 8;
4603 *str = start;
4604 }
4605 }
b99bd4ef 4606
c19d1205
ZW
4607 /* Just because we didn't get a match doesn't mean that the constant
4608 isn't valid, just that it is in a format that we don't
4609 automatically recognize. Try parsing it with the standard
4610 expression routines. */
b99bd4ef 4611
c19d1205 4612 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4613
c19d1205
ZW
4614 /* Look for a raw floating point number. */
4615 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4616 && is_end_of_line[(unsigned char) *save_in])
4617 {
4618 for (i = 0; i < NUM_FLOAT_VALS; i++)
4619 {
4620 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4621 {
c19d1205
ZW
4622 if (words[j] != fp_values[i][j])
4623 break;
b99bd4ef
NC
4624 }
4625
c19d1205 4626 if (j == MAX_LITTLENUMS)
b99bd4ef 4627 {
c19d1205
ZW
4628 *str = save_in;
4629 return i + 8;
b99bd4ef
NC
4630 }
4631 }
4632 }
b99bd4ef 4633
c19d1205
ZW
4634 /* Try and parse a more complex expression, this will probably fail
4635 unless the code uses a floating point prefix (eg "0f"). */
4636 save_in = input_line_pointer;
4637 input_line_pointer = *str;
4638 if (expression (&exp) == absolute_section
4639 && exp.X_op == O_big
4640 && exp.X_add_number < 0)
4641 {
4642 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4643 Ditto for 15. */
4644 if (gen_to_words (words, 5, (long) 15) == 0)
4645 {
4646 for (i = 0; i < NUM_FLOAT_VALS; i++)
4647 {
4648 for (j = 0; j < MAX_LITTLENUMS; j++)
4649 {
4650 if (words[j] != fp_values[i][j])
4651 break;
4652 }
b99bd4ef 4653
c19d1205
ZW
4654 if (j == MAX_LITTLENUMS)
4655 {
4656 *str = input_line_pointer;
4657 input_line_pointer = save_in;
4658 return i + 8;
4659 }
4660 }
4661 }
b99bd4ef
NC
4662 }
4663
c19d1205
ZW
4664 *str = input_line_pointer;
4665 input_line_pointer = save_in;
4666 inst.error = _("invalid FPA immediate expression");
4667 return FAIL;
b99bd4ef
NC
4668}
4669
136da414
JB
4670/* Returns 1 if a number has "quarter-precision" float format
4671 0baBbbbbbc defgh000 00000000 00000000. */
4672
4673static int
4674is_quarter_float (unsigned imm)
4675{
4676 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4677 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4678}
4679
4680/* Parse an 8-bit "quarter-precision" floating point number of the form:
4681 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4682 The zero and minus-zero cases need special handling, since they can't be
4683 encoded in the "quarter-precision" float format, but can nonetheless be
4684 loaded as integer constants. */
136da414
JB
4685
4686static unsigned
4687parse_qfloat_immediate (char **ccp, int *immed)
4688{
4689 char *str = *ccp;
c96612cc 4690 char *fpnum;
136da414 4691 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4692 int found_fpchar = 0;
5f4273c7 4693
136da414 4694 skip_past_char (&str, '#');
5f4273c7 4695
c96612cc
JB
4696 /* We must not accidentally parse an integer as a floating-point number. Make
4697 sure that the value we parse is not an integer by checking for special
4698 characters '.' or 'e'.
4699 FIXME: This is a horrible hack, but doing better is tricky because type
4700 information isn't in a very usable state at parse time. */
4701 fpnum = str;
4702 skip_whitespace (fpnum);
4703
4704 if (strncmp (fpnum, "0x", 2) == 0)
4705 return FAIL;
4706 else
4707 {
4708 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4709 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4710 {
4711 found_fpchar = 1;
4712 break;
4713 }
4714
4715 if (!found_fpchar)
4716 return FAIL;
4717 }
5f4273c7 4718
136da414
JB
4719 if ((str = atof_ieee (str, 's', words)) != NULL)
4720 {
4721 unsigned fpword = 0;
4722 int i;
5f4273c7 4723
136da414
JB
4724 /* Our FP word must be 32 bits (single-precision FP). */
4725 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4726 {
4727 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4728 fpword |= words[i];
4729 }
5f4273c7 4730
c96612cc 4731 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4732 *immed = fpword;
4733 else
4734 return FAIL;
4735
4736 *ccp = str;
5f4273c7 4737
136da414
JB
4738 return SUCCESS;
4739 }
5f4273c7 4740
136da414
JB
4741 return FAIL;
4742}
4743
c19d1205
ZW
4744/* Shift operands. */
4745enum shift_kind
b99bd4ef 4746{
c19d1205
ZW
4747 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4748};
b99bd4ef 4749
c19d1205
ZW
4750struct asm_shift_name
4751{
4752 const char *name;
4753 enum shift_kind kind;
4754};
b99bd4ef 4755
c19d1205
ZW
4756/* Third argument to parse_shift. */
4757enum parse_shift_mode
4758{
4759 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4760 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4761 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4762 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4763 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4764};
b99bd4ef 4765
c19d1205
ZW
4766/* Parse a <shift> specifier on an ARM data processing instruction.
4767 This has three forms:
b99bd4ef 4768
c19d1205
ZW
4769 (LSL|LSR|ASL|ASR|ROR) Rs
4770 (LSL|LSR|ASL|ASR|ROR) #imm
4771 RRX
b99bd4ef 4772
c19d1205
ZW
4773 Note that ASL is assimilated to LSL in the instruction encoding, and
4774 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4775
c19d1205
ZW
4776static int
4777parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4778{
c19d1205
ZW
4779 const struct asm_shift_name *shift_name;
4780 enum shift_kind shift;
4781 char *s = *str;
4782 char *p = s;
4783 int reg;
b99bd4ef 4784
c19d1205
ZW
4785 for (p = *str; ISALPHA (*p); p++)
4786 ;
b99bd4ef 4787
c19d1205 4788 if (p == *str)
b99bd4ef 4789 {
c19d1205
ZW
4790 inst.error = _("shift expression expected");
4791 return FAIL;
b99bd4ef
NC
4792 }
4793
21d799b5
NC
4794 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4795 p - *str);
c19d1205
ZW
4796
4797 if (shift_name == NULL)
b99bd4ef 4798 {
c19d1205
ZW
4799 inst.error = _("shift expression expected");
4800 return FAIL;
b99bd4ef
NC
4801 }
4802
c19d1205 4803 shift = shift_name->kind;
b99bd4ef 4804
c19d1205
ZW
4805 switch (mode)
4806 {
4807 case NO_SHIFT_RESTRICT:
4808 case SHIFT_IMMEDIATE: break;
b99bd4ef 4809
c19d1205
ZW
4810 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4811 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4812 {
4813 inst.error = _("'LSL' or 'ASR' required");
4814 return FAIL;
4815 }
4816 break;
b99bd4ef 4817
c19d1205
ZW
4818 case SHIFT_LSL_IMMEDIATE:
4819 if (shift != SHIFT_LSL)
4820 {
4821 inst.error = _("'LSL' required");
4822 return FAIL;
4823 }
4824 break;
b99bd4ef 4825
c19d1205
ZW
4826 case SHIFT_ASR_IMMEDIATE:
4827 if (shift != SHIFT_ASR)
4828 {
4829 inst.error = _("'ASR' required");
4830 return FAIL;
4831 }
4832 break;
b99bd4ef 4833
c19d1205
ZW
4834 default: abort ();
4835 }
b99bd4ef 4836
c19d1205
ZW
4837 if (shift != SHIFT_RRX)
4838 {
4839 /* Whitespace can appear here if the next thing is a bare digit. */
4840 skip_whitespace (p);
b99bd4ef 4841
c19d1205 4842 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4843 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4844 {
4845 inst.operands[i].imm = reg;
4846 inst.operands[i].immisreg = 1;
4847 }
4848 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4849 return FAIL;
4850 }
4851 inst.operands[i].shift_kind = shift;
4852 inst.operands[i].shifted = 1;
4853 *str = p;
4854 return SUCCESS;
b99bd4ef
NC
4855}
4856
c19d1205 4857/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4858
c19d1205
ZW
4859 #<immediate>
4860 #<immediate>, <rotate>
4861 <Rm>
4862 <Rm>, <shift>
b99bd4ef 4863
c19d1205
ZW
4864 where <shift> is defined by parse_shift above, and <rotate> is a
4865 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4866 is deferred to md_apply_fix. */
b99bd4ef 4867
c19d1205
ZW
4868static int
4869parse_shifter_operand (char **str, int i)
4870{
4871 int value;
91d6fa6a 4872 expressionS exp;
b99bd4ef 4873
dcbf9037 4874 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4875 {
4876 inst.operands[i].reg = value;
4877 inst.operands[i].isreg = 1;
b99bd4ef 4878
c19d1205
ZW
4879 /* parse_shift will override this if appropriate */
4880 inst.reloc.exp.X_op = O_constant;
4881 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4882
c19d1205
ZW
4883 if (skip_past_comma (str) == FAIL)
4884 return SUCCESS;
b99bd4ef 4885
c19d1205
ZW
4886 /* Shift operation on register. */
4887 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4888 }
4889
c19d1205
ZW
4890 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4891 return FAIL;
b99bd4ef 4892
c19d1205 4893 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4894 {
c19d1205 4895 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 4896 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 4897 return FAIL;
b99bd4ef 4898
91d6fa6a 4899 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
4900 {
4901 inst.error = _("constant expression expected");
4902 return FAIL;
4903 }
b99bd4ef 4904
91d6fa6a 4905 value = exp.X_add_number;
c19d1205
ZW
4906 if (value < 0 || value > 30 || value % 2 != 0)
4907 {
4908 inst.error = _("invalid rotation");
4909 return FAIL;
4910 }
4911 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4912 {
4913 inst.error = _("invalid constant");
4914 return FAIL;
4915 }
09d92015 4916
a415b1cd
JB
4917 /* Encode as specified. */
4918 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
4919 return SUCCESS;
09d92015
MM
4920 }
4921
c19d1205
ZW
4922 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4923 inst.reloc.pc_rel = 0;
4924 return SUCCESS;
09d92015
MM
4925}
4926
4962c51a
MS
4927/* Group relocation information. Each entry in the table contains the
4928 textual name of the relocation as may appear in assembler source
4929 and must end with a colon.
4930 Along with this textual name are the relocation codes to be used if
4931 the corresponding instruction is an ALU instruction (ADD or SUB only),
4932 an LDR, an LDRS, or an LDC. */
4933
4934struct group_reloc_table_entry
4935{
4936 const char *name;
4937 int alu_code;
4938 int ldr_code;
4939 int ldrs_code;
4940 int ldc_code;
4941};
4942
4943typedef enum
4944{
4945 /* Varieties of non-ALU group relocation. */
4946
4947 GROUP_LDR,
4948 GROUP_LDRS,
4949 GROUP_LDC
4950} group_reloc_type;
4951
4952static struct group_reloc_table_entry group_reloc_table[] =
4953 { /* Program counter relative: */
4954 { "pc_g0_nc",
4955 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4956 0, /* LDR */
4957 0, /* LDRS */
4958 0 }, /* LDC */
4959 { "pc_g0",
4960 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4961 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4962 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4963 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4964 { "pc_g1_nc",
4965 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4966 0, /* LDR */
4967 0, /* LDRS */
4968 0 }, /* LDC */
4969 { "pc_g1",
4970 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4971 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4972 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4973 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4974 { "pc_g2",
4975 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4976 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4977 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4978 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4979 /* Section base relative */
4980 { "sb_g0_nc",
4981 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4982 0, /* LDR */
4983 0, /* LDRS */
4984 0 }, /* LDC */
4985 { "sb_g0",
4986 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4987 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4988 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4989 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4990 { "sb_g1_nc",
4991 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4992 0, /* LDR */
4993 0, /* LDRS */
4994 0 }, /* LDC */
4995 { "sb_g1",
4996 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4997 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4998 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4999 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5000 { "sb_g2",
5001 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5002 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5003 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5004 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
5005
5006/* Given the address of a pointer pointing to the textual name of a group
5007 relocation as may appear in assembler source, attempt to find its details
5008 in group_reloc_table. The pointer will be updated to the character after
5009 the trailing colon. On failure, FAIL will be returned; SUCCESS
5010 otherwise. On success, *entry will be updated to point at the relevant
5011 group_reloc_table entry. */
5012
5013static int
5014find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5015{
5016 unsigned int i;
5017 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5018 {
5019 int length = strlen (group_reloc_table[i].name);
5020
5f4273c7
NC
5021 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5022 && (*str)[length] == ':')
4962c51a
MS
5023 {
5024 *out = &group_reloc_table[i];
5025 *str += (length + 1);
5026 return SUCCESS;
5027 }
5028 }
5029
5030 return FAIL;
5031}
5032
5033/* Parse a <shifter_operand> for an ARM data processing instruction
5034 (as for parse_shifter_operand) where group relocations are allowed:
5035
5036 #<immediate>
5037 #<immediate>, <rotate>
5038 #:<group_reloc>:<expression>
5039 <Rm>
5040 <Rm>, <shift>
5041
5042 where <group_reloc> is one of the strings defined in group_reloc_table.
5043 The hashes are optional.
5044
5045 Everything else is as for parse_shifter_operand. */
5046
5047static parse_operand_result
5048parse_shifter_operand_group_reloc (char **str, int i)
5049{
5050 /* Determine if we have the sequence of characters #: or just :
5051 coming next. If we do, then we check for a group relocation.
5052 If we don't, punt the whole lot to parse_shifter_operand. */
5053
5054 if (((*str)[0] == '#' && (*str)[1] == ':')
5055 || (*str)[0] == ':')
5056 {
5057 struct group_reloc_table_entry *entry;
5058
5059 if ((*str)[0] == '#')
5060 (*str) += 2;
5061 else
5062 (*str)++;
5063
5064 /* Try to parse a group relocation. Anything else is an error. */
5065 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5066 {
5067 inst.error = _("unknown group relocation");
5068 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5069 }
5070
5071 /* We now have the group relocation table entry corresponding to
5072 the name in the assembler source. Next, we parse the expression. */
5073 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
5074 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5075
5076 /* Record the relocation type (always the ALU variant here). */
21d799b5 5077 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5078 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5079
5080 return PARSE_OPERAND_SUCCESS;
5081 }
5082 else
5083 return parse_shifter_operand (str, i) == SUCCESS
5084 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5085
5086 /* Never reached. */
5087}
5088
8e560766
MGD
5089/* Parse a Neon alignment expression. Information is written to
5090 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5091
8e560766
MGD
5092 align .imm = align << 8, .immisalign=1, .preind=0 */
5093static parse_operand_result
5094parse_neon_alignment (char **str, int i)
5095{
5096 char *p = *str;
5097 expressionS exp;
5098
5099 my_get_expression (&exp, &p, GE_NO_PREFIX);
5100
5101 if (exp.X_op != O_constant)
5102 {
5103 inst.error = _("alignment must be constant");
5104 return PARSE_OPERAND_FAIL;
5105 }
5106
5107 inst.operands[i].imm = exp.X_add_number << 8;
5108 inst.operands[i].immisalign = 1;
5109 /* Alignments are not pre-indexes. */
5110 inst.operands[i].preind = 0;
5111
5112 *str = p;
5113 return PARSE_OPERAND_SUCCESS;
5114}
5115
c19d1205
ZW
5116/* Parse all forms of an ARM address expression. Information is written
5117 to inst.operands[i] and/or inst.reloc.
09d92015 5118
c19d1205 5119 Preindexed addressing (.preind=1):
09d92015 5120
c19d1205
ZW
5121 [Rn, #offset] .reg=Rn .reloc.exp=offset
5122 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5123 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5124 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5125
c19d1205 5126 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5127
c19d1205 5128 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5129
c19d1205
ZW
5130 [Rn], #offset .reg=Rn .reloc.exp=offset
5131 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5132 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5133 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5134
c19d1205 5135 Unindexed addressing (.preind=0, .postind=0):
09d92015 5136
c19d1205 5137 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5138
c19d1205 5139 Other:
09d92015 5140
c19d1205
ZW
5141 [Rn]{!} shorthand for [Rn,#0]{!}
5142 =immediate .isreg=0 .reloc.exp=immediate
5143 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5144
c19d1205
ZW
5145 It is the caller's responsibility to check for addressing modes not
5146 supported by the instruction, and to set inst.reloc.type. */
5147
4962c51a
MS
5148static parse_operand_result
5149parse_address_main (char **str, int i, int group_relocations,
5150 group_reloc_type group_type)
09d92015 5151{
c19d1205
ZW
5152 char *p = *str;
5153 int reg;
09d92015 5154
c19d1205 5155 if (skip_past_char (&p, '[') == FAIL)
09d92015 5156 {
c19d1205
ZW
5157 if (skip_past_char (&p, '=') == FAIL)
5158 {
974da60d 5159 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5160 inst.reloc.pc_rel = 1;
5161 inst.operands[i].reg = REG_PC;
5162 inst.operands[i].isreg = 1;
5163 inst.operands[i].preind = 1;
5164 }
974da60d 5165 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
09d92015 5166
c19d1205 5167 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 5168 return PARSE_OPERAND_FAIL;
09d92015 5169
c19d1205 5170 *str = p;
4962c51a 5171 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5172 }
5173
8ab8155f
NC
5174 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5175 skip_whitespace (p);
5176
dcbf9037 5177 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5178 {
c19d1205 5179 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5180 return PARSE_OPERAND_FAIL;
09d92015 5181 }
c19d1205
ZW
5182 inst.operands[i].reg = reg;
5183 inst.operands[i].isreg = 1;
09d92015 5184
c19d1205 5185 if (skip_past_comma (&p) == SUCCESS)
09d92015 5186 {
c19d1205 5187 inst.operands[i].preind = 1;
09d92015 5188
c19d1205
ZW
5189 if (*p == '+') p++;
5190 else if (*p == '-') p++, inst.operands[i].negative = 1;
5191
dcbf9037 5192 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5193 {
c19d1205
ZW
5194 inst.operands[i].imm = reg;
5195 inst.operands[i].immisreg = 1;
5196
5197 if (skip_past_comma (&p) == SUCCESS)
5198 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5199 return PARSE_OPERAND_FAIL;
c19d1205 5200 }
5287ad62 5201 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5202 {
5203 /* FIXME: '@' should be used here, but it's filtered out by generic
5204 code before we get to see it here. This may be subject to
5205 change. */
5206 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5207
8e560766
MGD
5208 if (result != PARSE_OPERAND_SUCCESS)
5209 return result;
5210 }
c19d1205
ZW
5211 else
5212 {
5213 if (inst.operands[i].negative)
5214 {
5215 inst.operands[i].negative = 0;
5216 p--;
5217 }
4962c51a 5218
5f4273c7
NC
5219 if (group_relocations
5220 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5221 {
5222 struct group_reloc_table_entry *entry;
5223
5224 /* Skip over the #: or : sequence. */
5225 if (*p == '#')
5226 p += 2;
5227 else
5228 p++;
5229
5230 /* Try to parse a group relocation. Anything else is an
5231 error. */
5232 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5233 {
5234 inst.error = _("unknown group relocation");
5235 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5236 }
5237
5238 /* We now have the group relocation table entry corresponding to
5239 the name in the assembler source. Next, we parse the
5240 expression. */
5241 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5242 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5243
5244 /* Record the relocation type. */
5245 switch (group_type)
5246 {
5247 case GROUP_LDR:
21d799b5 5248 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
4962c51a
MS
5249 break;
5250
5251 case GROUP_LDRS:
21d799b5 5252 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
4962c51a
MS
5253 break;
5254
5255 case GROUP_LDC:
21d799b5 5256 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
4962c51a
MS
5257 break;
5258
5259 default:
9c2799c2 5260 gas_assert (0);
4962c51a
MS
5261 }
5262
5263 if (inst.reloc.type == 0)
5264 {
5265 inst.error = _("this group relocation is not allowed on this instruction");
5266 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5267 }
5268 }
5269 else
26d97720
NS
5270 {
5271 char *q = p;
5272 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5273 return PARSE_OPERAND_FAIL;
5274 /* If the offset is 0, find out if it's a +0 or -0. */
5275 if (inst.reloc.exp.X_op == O_constant
5276 && inst.reloc.exp.X_add_number == 0)
5277 {
5278 skip_whitespace (q);
5279 if (*q == '#')
5280 {
5281 q++;
5282 skip_whitespace (q);
5283 }
5284 if (*q == '-')
5285 inst.operands[i].negative = 1;
5286 }
5287 }
09d92015
MM
5288 }
5289 }
8e560766
MGD
5290 else if (skip_past_char (&p, ':') == SUCCESS)
5291 {
5292 /* FIXME: '@' should be used here, but it's filtered out by generic code
5293 before we get to see it here. This may be subject to change. */
5294 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5295
8e560766
MGD
5296 if (result != PARSE_OPERAND_SUCCESS)
5297 return result;
5298 }
09d92015 5299
c19d1205 5300 if (skip_past_char (&p, ']') == FAIL)
09d92015 5301 {
c19d1205 5302 inst.error = _("']' expected");
4962c51a 5303 return PARSE_OPERAND_FAIL;
09d92015
MM
5304 }
5305
c19d1205
ZW
5306 if (skip_past_char (&p, '!') == SUCCESS)
5307 inst.operands[i].writeback = 1;
09d92015 5308
c19d1205 5309 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5310 {
c19d1205
ZW
5311 if (skip_past_char (&p, '{') == SUCCESS)
5312 {
5313 /* [Rn], {expr} - unindexed, with option */
5314 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5315 0, 255, TRUE) == FAIL)
4962c51a 5316 return PARSE_OPERAND_FAIL;
09d92015 5317
c19d1205
ZW
5318 if (skip_past_char (&p, '}') == FAIL)
5319 {
5320 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5321 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5322 }
5323 if (inst.operands[i].preind)
5324 {
5325 inst.error = _("cannot combine index with option");
4962c51a 5326 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5327 }
5328 *str = p;
4962c51a 5329 return PARSE_OPERAND_SUCCESS;
09d92015 5330 }
c19d1205
ZW
5331 else
5332 {
5333 inst.operands[i].postind = 1;
5334 inst.operands[i].writeback = 1;
09d92015 5335
c19d1205
ZW
5336 if (inst.operands[i].preind)
5337 {
5338 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5339 return PARSE_OPERAND_FAIL;
c19d1205 5340 }
09d92015 5341
c19d1205
ZW
5342 if (*p == '+') p++;
5343 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5344
dcbf9037 5345 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5346 {
5287ad62
JB
5347 /* We might be using the immediate for alignment already. If we
5348 are, OR the register number into the low-order bits. */
5349 if (inst.operands[i].immisalign)
5350 inst.operands[i].imm |= reg;
5351 else
5352 inst.operands[i].imm = reg;
c19d1205 5353 inst.operands[i].immisreg = 1;
a737bd4d 5354
c19d1205
ZW
5355 if (skip_past_comma (&p) == SUCCESS)
5356 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5357 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5358 }
5359 else
5360 {
26d97720 5361 char *q = p;
c19d1205
ZW
5362 if (inst.operands[i].negative)
5363 {
5364 inst.operands[i].negative = 0;
5365 p--;
5366 }
5367 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5368 return PARSE_OPERAND_FAIL;
26d97720
NS
5369 /* If the offset is 0, find out if it's a +0 or -0. */
5370 if (inst.reloc.exp.X_op == O_constant
5371 && inst.reloc.exp.X_add_number == 0)
5372 {
5373 skip_whitespace (q);
5374 if (*q == '#')
5375 {
5376 q++;
5377 skip_whitespace (q);
5378 }
5379 if (*q == '-')
5380 inst.operands[i].negative = 1;
5381 }
c19d1205
ZW
5382 }
5383 }
a737bd4d
NC
5384 }
5385
c19d1205
ZW
5386 /* If at this point neither .preind nor .postind is set, we have a
5387 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5388 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5389 {
5390 inst.operands[i].preind = 1;
5391 inst.reloc.exp.X_op = O_constant;
5392 inst.reloc.exp.X_add_number = 0;
5393 }
5394 *str = p;
4962c51a
MS
5395 return PARSE_OPERAND_SUCCESS;
5396}
5397
5398static int
5399parse_address (char **str, int i)
5400{
21d799b5 5401 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
4962c51a
MS
5402 ? SUCCESS : FAIL;
5403}
5404
5405static parse_operand_result
5406parse_address_group_reloc (char **str, int i, group_reloc_type type)
5407{
5408 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5409}
5410
b6895b4f
PB
5411/* Parse an operand for a MOVW or MOVT instruction. */
5412static int
5413parse_half (char **str)
5414{
5415 char * p;
5f4273c7 5416
b6895b4f
PB
5417 p = *str;
5418 skip_past_char (&p, '#');
5f4273c7 5419 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5420 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5421 else if (strncasecmp (p, ":upper16:", 9) == 0)
5422 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5423
5424 if (inst.reloc.type != BFD_RELOC_UNUSED)
5425 {
5426 p += 9;
5f4273c7 5427 skip_whitespace (p);
b6895b4f
PB
5428 }
5429
5430 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5431 return FAIL;
5432
5433 if (inst.reloc.type == BFD_RELOC_UNUSED)
5434 {
5435 if (inst.reloc.exp.X_op != O_constant)
5436 {
5437 inst.error = _("constant expression expected");
5438 return FAIL;
5439 }
5440 if (inst.reloc.exp.X_add_number < 0
5441 || inst.reloc.exp.X_add_number > 0xffff)
5442 {
5443 inst.error = _("immediate value out of range");
5444 return FAIL;
5445 }
5446 }
5447 *str = p;
5448 return SUCCESS;
5449}
5450
c19d1205 5451/* Miscellaneous. */
a737bd4d 5452
c19d1205
ZW
5453/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5454 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5455static int
d2cd1205 5456parse_psr (char **str, bfd_boolean lhs)
09d92015 5457{
c19d1205
ZW
5458 char *p;
5459 unsigned long psr_field;
62b3e311
PB
5460 const struct asm_psr *psr;
5461 char *start;
d2cd1205 5462 bfd_boolean is_apsr = FALSE;
ac7f631b 5463 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5464
a4482bb6
NC
5465 /* PR gas/12698: If the user has specified -march=all then m_profile will
5466 be TRUE, but we want to ignore it in this case as we are building for any
5467 CPU type, including non-m variants. */
5468 if (selected_cpu.core == arm_arch_any.core)
5469 m_profile = FALSE;
5470
c19d1205
ZW
5471 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5472 feature for ease of use and backwards compatibility. */
5473 p = *str;
62b3e311 5474 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5475 {
5476 if (m_profile)
5477 goto unsupported_psr;
fa94de6b 5478
d2cd1205
JB
5479 psr_field = SPSR_BIT;
5480 }
5481 else if (strncasecmp (p, "CPSR", 4) == 0)
5482 {
5483 if (m_profile)
5484 goto unsupported_psr;
5485
5486 psr_field = 0;
5487 }
5488 else if (strncasecmp (p, "APSR", 4) == 0)
5489 {
5490 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5491 and ARMv7-R architecture CPUs. */
5492 is_apsr = TRUE;
5493 psr_field = 0;
5494 }
5495 else if (m_profile)
62b3e311
PB
5496 {
5497 start = p;
5498 do
5499 p++;
5500 while (ISALNUM (*p) || *p == '_');
5501
d2cd1205
JB
5502 if (strncasecmp (start, "iapsr", 5) == 0
5503 || strncasecmp (start, "eapsr", 5) == 0
5504 || strncasecmp (start, "xpsr", 4) == 0
5505 || strncasecmp (start, "psr", 3) == 0)
5506 p = start + strcspn (start, "rR") + 1;
5507
21d799b5
NC
5508 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5509 p - start);
d2cd1205 5510
62b3e311
PB
5511 if (!psr)
5512 return FAIL;
09d92015 5513
d2cd1205
JB
5514 /* If APSR is being written, a bitfield may be specified. Note that
5515 APSR itself is handled above. */
5516 if (psr->field <= 3)
5517 {
5518 psr_field = psr->field;
5519 is_apsr = TRUE;
5520 goto check_suffix;
5521 }
5522
62b3e311 5523 *str = p;
d2cd1205
JB
5524 /* M-profile MSR instructions have the mask field set to "10", except
5525 *PSR variants which modify APSR, which may use a different mask (and
5526 have been handled already). Do that by setting the PSR_f field
5527 here. */
5528 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5529 }
d2cd1205
JB
5530 else
5531 goto unsupported_psr;
09d92015 5532
62b3e311 5533 p += 4;
d2cd1205 5534check_suffix:
c19d1205
ZW
5535 if (*p == '_')
5536 {
5537 /* A suffix follows. */
c19d1205
ZW
5538 p++;
5539 start = p;
a737bd4d 5540
c19d1205
ZW
5541 do
5542 p++;
5543 while (ISALNUM (*p) || *p == '_');
a737bd4d 5544
d2cd1205
JB
5545 if (is_apsr)
5546 {
5547 /* APSR uses a notation for bits, rather than fields. */
5548 unsigned int nzcvq_bits = 0;
5549 unsigned int g_bit = 0;
5550 char *bit;
fa94de6b 5551
d2cd1205
JB
5552 for (bit = start; bit != p; bit++)
5553 {
5554 switch (TOLOWER (*bit))
5555 {
5556 case 'n':
5557 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5558 break;
5559
5560 case 'z':
5561 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5562 break;
5563
5564 case 'c':
5565 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5566 break;
5567
5568 case 'v':
5569 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5570 break;
fa94de6b 5571
d2cd1205
JB
5572 case 'q':
5573 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5574 break;
fa94de6b 5575
d2cd1205
JB
5576 case 'g':
5577 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5578 break;
fa94de6b 5579
d2cd1205
JB
5580 default:
5581 inst.error = _("unexpected bit specified after APSR");
5582 return FAIL;
5583 }
5584 }
fa94de6b 5585
d2cd1205
JB
5586 if (nzcvq_bits == 0x1f)
5587 psr_field |= PSR_f;
fa94de6b 5588
d2cd1205
JB
5589 if (g_bit == 0x1)
5590 {
5591 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
5592 {
5593 inst.error = _("selected processor does not "
5594 "support DSP extension");
5595 return FAIL;
5596 }
5597
5598 psr_field |= PSR_s;
5599 }
fa94de6b 5600
d2cd1205
JB
5601 if ((nzcvq_bits & 0x20) != 0
5602 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5603 || (g_bit & 0x2) != 0)
5604 {
5605 inst.error = _("bad bitmask specified after APSR");
5606 return FAIL;
5607 }
5608 }
5609 else
5610 {
5611 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5612 p - start);
5613 if (!psr)
5614 goto error;
a737bd4d 5615
d2cd1205
JB
5616 psr_field |= psr->field;
5617 }
a737bd4d 5618 }
c19d1205 5619 else
a737bd4d 5620 {
c19d1205
ZW
5621 if (ISALNUM (*p))
5622 goto error; /* Garbage after "[CS]PSR". */
5623
d2cd1205
JB
5624 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
5625 is deprecated, but allow it anyway. */
5626 if (is_apsr && lhs)
5627 {
5628 psr_field |= PSR_f;
5629 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5630 "deprecated"));
5631 }
5632 else if (!m_profile)
5633 /* These bits are never right for M-profile devices: don't set them
5634 (only code paths which read/write APSR reach here). */
5635 psr_field |= (PSR_c | PSR_f);
a737bd4d 5636 }
c19d1205
ZW
5637 *str = p;
5638 return psr_field;
a737bd4d 5639
d2cd1205
JB
5640 unsupported_psr:
5641 inst.error = _("selected processor does not support requested special "
5642 "purpose register");
5643 return FAIL;
5644
c19d1205
ZW
5645 error:
5646 inst.error = _("flag for {c}psr instruction expected");
5647 return FAIL;
a737bd4d
NC
5648}
5649
c19d1205
ZW
5650/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5651 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5652
c19d1205
ZW
5653static int
5654parse_cps_flags (char **str)
a737bd4d 5655{
c19d1205
ZW
5656 int val = 0;
5657 int saw_a_flag = 0;
5658 char *s = *str;
a737bd4d 5659
c19d1205
ZW
5660 for (;;)
5661 switch (*s++)
5662 {
5663 case '\0': case ',':
5664 goto done;
a737bd4d 5665
c19d1205
ZW
5666 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5667 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5668 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5669
c19d1205
ZW
5670 default:
5671 inst.error = _("unrecognized CPS flag");
5672 return FAIL;
5673 }
a737bd4d 5674
c19d1205
ZW
5675 done:
5676 if (saw_a_flag == 0)
a737bd4d 5677 {
c19d1205
ZW
5678 inst.error = _("missing CPS flags");
5679 return FAIL;
a737bd4d 5680 }
a737bd4d 5681
c19d1205
ZW
5682 *str = s - 1;
5683 return val;
a737bd4d
NC
5684}
5685
c19d1205
ZW
5686/* Parse an endian specifier ("BE" or "LE", case insensitive);
5687 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5688
5689static int
c19d1205 5690parse_endian_specifier (char **str)
a737bd4d 5691{
c19d1205
ZW
5692 int little_endian;
5693 char *s = *str;
a737bd4d 5694
c19d1205
ZW
5695 if (strncasecmp (s, "BE", 2))
5696 little_endian = 0;
5697 else if (strncasecmp (s, "LE", 2))
5698 little_endian = 1;
5699 else
a737bd4d 5700 {
c19d1205 5701 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5702 return FAIL;
5703 }
5704
c19d1205 5705 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5706 {
c19d1205 5707 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5708 return FAIL;
5709 }
5710
c19d1205
ZW
5711 *str = s + 2;
5712 return little_endian;
5713}
a737bd4d 5714
c19d1205
ZW
5715/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5716 value suitable for poking into the rotate field of an sxt or sxta
5717 instruction, or FAIL on error. */
5718
5719static int
5720parse_ror (char **str)
5721{
5722 int rot;
5723 char *s = *str;
5724
5725 if (strncasecmp (s, "ROR", 3) == 0)
5726 s += 3;
5727 else
a737bd4d 5728 {
c19d1205 5729 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5730 return FAIL;
5731 }
c19d1205
ZW
5732
5733 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5734 return FAIL;
5735
5736 switch (rot)
a737bd4d 5737 {
c19d1205
ZW
5738 case 0: *str = s; return 0x0;
5739 case 8: *str = s; return 0x1;
5740 case 16: *str = s; return 0x2;
5741 case 24: *str = s; return 0x3;
5742
5743 default:
5744 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5745 return FAIL;
5746 }
c19d1205 5747}
a737bd4d 5748
c19d1205
ZW
5749/* Parse a conditional code (from conds[] below). The value returned is in the
5750 range 0 .. 14, or FAIL. */
5751static int
5752parse_cond (char **str)
5753{
c462b453 5754 char *q;
c19d1205 5755 const struct asm_cond *c;
c462b453
PB
5756 int n;
5757 /* Condition codes are always 2 characters, so matching up to
5758 3 characters is sufficient. */
5759 char cond[3];
a737bd4d 5760
c462b453
PB
5761 q = *str;
5762 n = 0;
5763 while (ISALPHA (*q) && n < 3)
5764 {
e07e6e58 5765 cond[n] = TOLOWER (*q);
c462b453
PB
5766 q++;
5767 n++;
5768 }
a737bd4d 5769
21d799b5 5770 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5771 if (!c)
a737bd4d 5772 {
c19d1205 5773 inst.error = _("condition required");
a737bd4d
NC
5774 return FAIL;
5775 }
5776
c19d1205
ZW
5777 *str = q;
5778 return c->value;
5779}
5780
e797f7e0
MGD
5781/* If the given feature available in the selected CPU, mark it as used.
5782 Returns TRUE iff feature is available. */
5783static bfd_boolean
5784mark_feature_used (const arm_feature_set *feature)
5785{
5786 /* Ensure the option is valid on the current architecture. */
5787 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
5788 return FALSE;
5789
5790 /* Add the appropriate architecture feature for the barrier option used.
5791 */
5792 if (thumb_mode)
5793 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
5794 else
5795 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
5796
5797 return TRUE;
5798}
5799
62b3e311
PB
5800/* Parse an option for a barrier instruction. Returns the encoding for the
5801 option, or FAIL. */
5802static int
5803parse_barrier (char **str)
5804{
5805 char *p, *q;
5806 const struct asm_barrier_opt *o;
5807
5808 p = q = *str;
5809 while (ISALPHA (*q))
5810 q++;
5811
21d799b5
NC
5812 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5813 q - p);
62b3e311
PB
5814 if (!o)
5815 return FAIL;
5816
e797f7e0
MGD
5817 if (!mark_feature_used (&o->arch))
5818 return FAIL;
5819
62b3e311
PB
5820 *str = q;
5821 return o->value;
5822}
5823
92e90b6e
PB
5824/* Parse the operands of a table branch instruction. Similar to a memory
5825 operand. */
5826static int
5827parse_tb (char **str)
5828{
5829 char * p = *str;
5830 int reg;
5831
5832 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5833 {
5834 inst.error = _("'[' expected");
5835 return FAIL;
5836 }
92e90b6e 5837
dcbf9037 5838 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5839 {
5840 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5841 return FAIL;
5842 }
5843 inst.operands[0].reg = reg;
5844
5845 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5846 {
5847 inst.error = _("',' expected");
5848 return FAIL;
5849 }
5f4273c7 5850
dcbf9037 5851 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5852 {
5853 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5854 return FAIL;
5855 }
5856 inst.operands[0].imm = reg;
5857
5858 if (skip_past_comma (&p) == SUCCESS)
5859 {
5860 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5861 return FAIL;
5862 if (inst.reloc.exp.X_add_number != 1)
5863 {
5864 inst.error = _("invalid shift");
5865 return FAIL;
5866 }
5867 inst.operands[0].shifted = 1;
5868 }
5869
5870 if (skip_past_char (&p, ']') == FAIL)
5871 {
5872 inst.error = _("']' expected");
5873 return FAIL;
5874 }
5875 *str = p;
5876 return SUCCESS;
5877}
5878
5287ad62
JB
5879/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5880 information on the types the operands can take and how they are encoded.
037e8744
JB
5881 Up to four operands may be read; this function handles setting the
5882 ".present" field for each read operand itself.
5287ad62
JB
5883 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5884 else returns FAIL. */
5885
5886static int
5887parse_neon_mov (char **str, int *which_operand)
5888{
5889 int i = *which_operand, val;
5890 enum arm_reg_type rtype;
5891 char *ptr = *str;
dcbf9037 5892 struct neon_type_el optype;
5f4273c7 5893
dcbf9037 5894 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5895 {
5896 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5897 inst.operands[i].reg = val;
5898 inst.operands[i].isscalar = 1;
dcbf9037 5899 inst.operands[i].vectype = optype;
5287ad62
JB
5900 inst.operands[i++].present = 1;
5901
5902 if (skip_past_comma (&ptr) == FAIL)
5903 goto wanted_comma;
5f4273c7 5904
dcbf9037 5905 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5906 goto wanted_arm;
5f4273c7 5907
5287ad62
JB
5908 inst.operands[i].reg = val;
5909 inst.operands[i].isreg = 1;
5910 inst.operands[i].present = 1;
5911 }
037e8744 5912 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5913 != FAIL)
5287ad62
JB
5914 {
5915 /* Cases 0, 1, 2, 3, 5 (D only). */
5916 if (skip_past_comma (&ptr) == FAIL)
5917 goto wanted_comma;
5f4273c7 5918
5287ad62
JB
5919 inst.operands[i].reg = val;
5920 inst.operands[i].isreg = 1;
5921 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5922 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5923 inst.operands[i].isvec = 1;
dcbf9037 5924 inst.operands[i].vectype = optype;
5287ad62
JB
5925 inst.operands[i++].present = 1;
5926
dcbf9037 5927 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5928 {
037e8744
JB
5929 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5930 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5931 inst.operands[i].reg = val;
5932 inst.operands[i].isreg = 1;
037e8744 5933 inst.operands[i].present = 1;
5287ad62
JB
5934
5935 if (rtype == REG_TYPE_NQ)
5936 {
dcbf9037 5937 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5938 return FAIL;
5939 }
037e8744
JB
5940 else if (rtype != REG_TYPE_VFS)
5941 {
5942 i++;
5943 if (skip_past_comma (&ptr) == FAIL)
5944 goto wanted_comma;
5945 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5946 goto wanted_arm;
5947 inst.operands[i].reg = val;
5948 inst.operands[i].isreg = 1;
5949 inst.operands[i].present = 1;
5950 }
5287ad62 5951 }
037e8744
JB
5952 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5953 &optype)) != FAIL)
5287ad62
JB
5954 {
5955 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5956 Case 1: VMOV<c><q> <Dd>, <Dm>
5957 Case 8: VMOV.F32 <Sd>, <Sm>
5958 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5959
5960 inst.operands[i].reg = val;
5961 inst.operands[i].isreg = 1;
5962 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5963 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5964 inst.operands[i].isvec = 1;
dcbf9037 5965 inst.operands[i].vectype = optype;
5287ad62 5966 inst.operands[i].present = 1;
5f4273c7 5967
037e8744
JB
5968 if (skip_past_comma (&ptr) == SUCCESS)
5969 {
5970 /* Case 15. */
5971 i++;
5972
5973 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5974 goto wanted_arm;
5975
5976 inst.operands[i].reg = val;
5977 inst.operands[i].isreg = 1;
5978 inst.operands[i++].present = 1;
5f4273c7 5979
037e8744
JB
5980 if (skip_past_comma (&ptr) == FAIL)
5981 goto wanted_comma;
5f4273c7 5982
037e8744
JB
5983 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5984 goto wanted_arm;
5f4273c7 5985
037e8744
JB
5986 inst.operands[i].reg = val;
5987 inst.operands[i].isreg = 1;
1b11b49f 5988 inst.operands[i].present = 1;
037e8744 5989 }
5287ad62 5990 }
4641781c
PB
5991 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5992 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5993 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5994 Case 10: VMOV.F32 <Sd>, #<imm>
5995 Case 11: VMOV.F64 <Dd>, #<imm> */
5996 inst.operands[i].immisfloat = 1;
5997 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5998 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5999 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6000 ;
5287ad62
JB
6001 else
6002 {
dcbf9037 6003 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
6004 return FAIL;
6005 }
6006 }
dcbf9037 6007 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6008 {
6009 /* Cases 6, 7. */
6010 inst.operands[i].reg = val;
6011 inst.operands[i].isreg = 1;
6012 inst.operands[i++].present = 1;
5f4273c7 6013
5287ad62
JB
6014 if (skip_past_comma (&ptr) == FAIL)
6015 goto wanted_comma;
5f4273c7 6016
dcbf9037 6017 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6018 {
6019 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6020 inst.operands[i].reg = val;
6021 inst.operands[i].isscalar = 1;
6022 inst.operands[i].present = 1;
dcbf9037 6023 inst.operands[i].vectype = optype;
5287ad62 6024 }
dcbf9037 6025 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6026 {
6027 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6028 inst.operands[i].reg = val;
6029 inst.operands[i].isreg = 1;
6030 inst.operands[i++].present = 1;
5f4273c7 6031
5287ad62
JB
6032 if (skip_past_comma (&ptr) == FAIL)
6033 goto wanted_comma;
5f4273c7 6034
037e8744 6035 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 6036 == FAIL)
5287ad62 6037 {
037e8744 6038 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
6039 return FAIL;
6040 }
6041
6042 inst.operands[i].reg = val;
6043 inst.operands[i].isreg = 1;
037e8744
JB
6044 inst.operands[i].isvec = 1;
6045 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 6046 inst.operands[i].vectype = optype;
5287ad62 6047 inst.operands[i].present = 1;
5f4273c7 6048
037e8744
JB
6049 if (rtype == REG_TYPE_VFS)
6050 {
6051 /* Case 14. */
6052 i++;
6053 if (skip_past_comma (&ptr) == FAIL)
6054 goto wanted_comma;
6055 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6056 &optype)) == FAIL)
6057 {
6058 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6059 return FAIL;
6060 }
6061 inst.operands[i].reg = val;
6062 inst.operands[i].isreg = 1;
6063 inst.operands[i].isvec = 1;
6064 inst.operands[i].issingle = 1;
6065 inst.operands[i].vectype = optype;
6066 inst.operands[i].present = 1;
6067 }
6068 }
6069 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
6070 != FAIL)
6071 {
6072 /* Case 13. */
6073 inst.operands[i].reg = val;
6074 inst.operands[i].isreg = 1;
6075 inst.operands[i].isvec = 1;
6076 inst.operands[i].issingle = 1;
6077 inst.operands[i].vectype = optype;
1b11b49f 6078 inst.operands[i].present = 1;
5287ad62
JB
6079 }
6080 }
6081 else
6082 {
dcbf9037 6083 first_error (_("parse error"));
5287ad62
JB
6084 return FAIL;
6085 }
6086
6087 /* Successfully parsed the operands. Update args. */
6088 *which_operand = i;
6089 *str = ptr;
6090 return SUCCESS;
6091
5f4273c7 6092 wanted_comma:
dcbf9037 6093 first_error (_("expected comma"));
5287ad62 6094 return FAIL;
5f4273c7
NC
6095
6096 wanted_arm:
dcbf9037 6097 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6098 return FAIL;
5287ad62
JB
6099}
6100
5be8be5d
DG
6101/* Use this macro when the operand constraints are different
6102 for ARM and THUMB (e.g. ldrd). */
6103#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6104 ((arm_operand) | ((thumb_operand) << 16))
6105
c19d1205
ZW
6106/* Matcher codes for parse_operands. */
6107enum operand_parse_code
6108{
6109 OP_stop, /* end of line */
6110
6111 OP_RR, /* ARM register */
6112 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6113 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6114 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6115 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6116 optional trailing ! */
c19d1205
ZW
6117 OP_RRw, /* ARM register, not r15, optional trailing ! */
6118 OP_RCP, /* Coprocessor number */
6119 OP_RCN, /* Coprocessor register */
6120 OP_RF, /* FPA register */
6121 OP_RVS, /* VFP single precision register */
5287ad62
JB
6122 OP_RVD, /* VFP double precision register (0..15) */
6123 OP_RND, /* Neon double precision register (0..31) */
6124 OP_RNQ, /* Neon quad precision register */
037e8744 6125 OP_RVSD, /* VFP single or double precision register */
5287ad62 6126 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6127 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6128 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6129 OP_RVC, /* VFP control register */
6130 OP_RMF, /* Maverick F register */
6131 OP_RMD, /* Maverick D register */
6132 OP_RMFX, /* Maverick FX register */
6133 OP_RMDX, /* Maverick DX register */
6134 OP_RMAX, /* Maverick AX register */
6135 OP_RMDS, /* Maverick DSPSC register */
6136 OP_RIWR, /* iWMMXt wR register */
6137 OP_RIWC, /* iWMMXt wC register */
6138 OP_RIWG, /* iWMMXt wCG register */
6139 OP_RXA, /* XScale accumulator register */
6140
6141 OP_REGLST, /* ARM register list */
6142 OP_VRSLST, /* VFP single-precision register list */
6143 OP_VRDLST, /* VFP double-precision register list */
037e8744 6144 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6145 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6146 OP_NSTRLST, /* Neon element/structure list */
6147
5287ad62 6148 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6149 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 6150 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6151 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6152 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6153 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6154 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6155 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6156 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6157 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6158
6159 OP_I0, /* immediate zero */
c19d1205
ZW
6160 OP_I7, /* immediate value 0 .. 7 */
6161 OP_I15, /* 0 .. 15 */
6162 OP_I16, /* 1 .. 16 */
5287ad62 6163 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6164 OP_I31, /* 0 .. 31 */
6165 OP_I31w, /* 0 .. 31, optional trailing ! */
6166 OP_I32, /* 1 .. 32 */
5287ad62
JB
6167 OP_I32z, /* 0 .. 32 */
6168 OP_I63, /* 0 .. 63 */
c19d1205 6169 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6170 OP_I64, /* 1 .. 64 */
6171 OP_I64z, /* 0 .. 64 */
c19d1205 6172 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6173
6174 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6175 OP_I7b, /* 0 .. 7 */
6176 OP_I15b, /* 0 .. 15 */
6177 OP_I31b, /* 0 .. 31 */
6178
6179 OP_SH, /* shifter operand */
4962c51a 6180 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6181 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6182 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6183 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6184 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6185 OP_EXP, /* arbitrary expression */
6186 OP_EXPi, /* same, with optional immediate prefix */
6187 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6188 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6189
6190 OP_CPSF, /* CPS flags */
6191 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6192 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6193 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6194 OP_COND, /* conditional code */
92e90b6e 6195 OP_TB, /* Table branch. */
c19d1205 6196
037e8744
JB
6197 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6198
c19d1205
ZW
6199 OP_RRnpc_I0, /* ARM register or literal 0 */
6200 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6201 OP_RR_EXi, /* ARM register or expression with imm prefix */
6202 OP_RF_IF, /* FPA register or immediate */
6203 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6204 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6205
6206 /* Optional operands. */
6207 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6208 OP_oI31b, /* 0 .. 31 */
5287ad62 6209 OP_oI32b, /* 1 .. 32 */
5f1af56b 6210 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6211 OP_oIffffb, /* 0 .. 65535 */
6212 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6213
6214 OP_oRR, /* ARM register */
6215 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6216 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6217 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6218 OP_oRND, /* Optional Neon double precision register */
6219 OP_oRNQ, /* Optional Neon quad precision register */
6220 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6221 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6222 OP_oSHll, /* LSL immediate */
6223 OP_oSHar, /* ASR immediate */
6224 OP_oSHllar, /* LSL or ASR immediate */
6225 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6226 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6227
5be8be5d
DG
6228 /* Some pre-defined mixed (ARM/THUMB) operands. */
6229 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6230 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6231 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6232
c19d1205
ZW
6233 OP_FIRST_OPTIONAL = OP_oI7b
6234};
a737bd4d 6235
c19d1205
ZW
6236/* Generic instruction operand parser. This does no encoding and no
6237 semantic validation; it merely squirrels values away in the inst
6238 structure. Returns SUCCESS or FAIL depending on whether the
6239 specified grammar matched. */
6240static int
5be8be5d 6241parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6242{
5be8be5d 6243 unsigned const int *upat = pattern;
c19d1205
ZW
6244 char *backtrack_pos = 0;
6245 const char *backtrack_error = 0;
99aad254 6246 int i, val = 0, backtrack_index = 0;
5287ad62 6247 enum arm_reg_type rtype;
4962c51a 6248 parse_operand_result result;
5be8be5d 6249 unsigned int op_parse_code;
c19d1205 6250
e07e6e58
NC
6251#define po_char_or_fail(chr) \
6252 do \
6253 { \
6254 if (skip_past_char (&str, chr) == FAIL) \
6255 goto bad_args; \
6256 } \
6257 while (0)
c19d1205 6258
e07e6e58
NC
6259#define po_reg_or_fail(regtype) \
6260 do \
dcbf9037 6261 { \
e07e6e58
NC
6262 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6263 & inst.operands[i].vectype); \
6264 if (val == FAIL) \
6265 { \
6266 first_error (_(reg_expected_msgs[regtype])); \
6267 goto failure; \
6268 } \
6269 inst.operands[i].reg = val; \
6270 inst.operands[i].isreg = 1; \
6271 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6272 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6273 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6274 || rtype == REG_TYPE_VFD \
6275 || rtype == REG_TYPE_NQ); \
dcbf9037 6276 } \
e07e6e58
NC
6277 while (0)
6278
6279#define po_reg_or_goto(regtype, label) \
6280 do \
6281 { \
6282 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6283 & inst.operands[i].vectype); \
6284 if (val == FAIL) \
6285 goto label; \
dcbf9037 6286 \
e07e6e58
NC
6287 inst.operands[i].reg = val; \
6288 inst.operands[i].isreg = 1; \
6289 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6290 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6291 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6292 || rtype == REG_TYPE_VFD \
6293 || rtype == REG_TYPE_NQ); \
6294 } \
6295 while (0)
6296
6297#define po_imm_or_fail(min, max, popt) \
6298 do \
6299 { \
6300 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6301 goto failure; \
6302 inst.operands[i].imm = val; \
6303 } \
6304 while (0)
6305
6306#define po_scalar_or_goto(elsz, label) \
6307 do \
6308 { \
6309 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6310 if (val == FAIL) \
6311 goto label; \
6312 inst.operands[i].reg = val; \
6313 inst.operands[i].isscalar = 1; \
6314 } \
6315 while (0)
6316
6317#define po_misc_or_fail(expr) \
6318 do \
6319 { \
6320 if (expr) \
6321 goto failure; \
6322 } \
6323 while (0)
6324
6325#define po_misc_or_fail_no_backtrack(expr) \
6326 do \
6327 { \
6328 result = expr; \
6329 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6330 backtrack_pos = 0; \
6331 if (result != PARSE_OPERAND_SUCCESS) \
6332 goto failure; \
6333 } \
6334 while (0)
4962c51a 6335
52e7f43d
RE
6336#define po_barrier_or_imm(str) \
6337 do \
6338 { \
6339 val = parse_barrier (&str); \
6340 if (val == FAIL) \
6341 { \
6342 if (ISALPHA (*str)) \
6343 goto failure; \
6344 else \
6345 goto immediate; \
6346 } \
6347 else \
6348 { \
6349 if ((inst.instruction & 0xf0) == 0x60 \
6350 && val != 0xf) \
6351 { \
6352 /* ISB can only take SY as an option. */ \
6353 inst.error = _("invalid barrier type"); \
6354 goto failure; \
6355 } \
6356 } \
6357 } \
6358 while (0)
6359
c19d1205
ZW
6360 skip_whitespace (str);
6361
6362 for (i = 0; upat[i] != OP_stop; i++)
6363 {
5be8be5d
DG
6364 op_parse_code = upat[i];
6365 if (op_parse_code >= 1<<16)
6366 op_parse_code = thumb ? (op_parse_code >> 16)
6367 : (op_parse_code & ((1<<16)-1));
6368
6369 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6370 {
6371 /* Remember where we are in case we need to backtrack. */
9c2799c2 6372 gas_assert (!backtrack_pos);
c19d1205
ZW
6373 backtrack_pos = str;
6374 backtrack_error = inst.error;
6375 backtrack_index = i;
6376 }
6377
b6702015 6378 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6379 po_char_or_fail (',');
6380
5be8be5d 6381 switch (op_parse_code)
c19d1205
ZW
6382 {
6383 /* Registers */
6384 case OP_oRRnpc:
5be8be5d 6385 case OP_oRRnpcsp:
c19d1205 6386 case OP_RRnpc:
5be8be5d 6387 case OP_RRnpcsp:
c19d1205
ZW
6388 case OP_oRR:
6389 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6390 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6391 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6392 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6393 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6394 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
6395 case OP_oRND:
6396 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6397 case OP_RVC:
6398 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6399 break;
6400 /* Also accept generic coprocessor regs for unknown registers. */
6401 coproc_reg:
6402 po_reg_or_fail (REG_TYPE_CN);
6403 break;
c19d1205
ZW
6404 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6405 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6406 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6407 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6408 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6409 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6410 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6411 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6412 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6413 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
6414 case OP_oRNQ:
6415 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6416 case OP_oRNDQ:
6417 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
6418 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6419 case OP_oRNSDQ:
6420 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
6421
6422 /* Neon scalar. Using an element size of 8 means that some invalid
6423 scalars are accepted here, so deal with those in later code. */
6424 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6425
5287ad62
JB
6426 case OP_RNDQ_I0:
6427 {
6428 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6429 break;
6430 try_imm0:
6431 po_imm_or_fail (0, 0, TRUE);
6432 }
6433 break;
6434
037e8744
JB
6435 case OP_RVSD_I0:
6436 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6437 break;
6438
5287ad62
JB
6439 case OP_RR_RNSC:
6440 {
6441 po_scalar_or_goto (8, try_rr);
6442 break;
6443 try_rr:
6444 po_reg_or_fail (REG_TYPE_RN);
6445 }
6446 break;
6447
037e8744
JB
6448 case OP_RNSDQ_RNSC:
6449 {
6450 po_scalar_or_goto (8, try_nsdq);
6451 break;
6452 try_nsdq:
6453 po_reg_or_fail (REG_TYPE_NSDQ);
6454 }
6455 break;
6456
5287ad62
JB
6457 case OP_RNDQ_RNSC:
6458 {
6459 po_scalar_or_goto (8, try_ndq);
6460 break;
6461 try_ndq:
6462 po_reg_or_fail (REG_TYPE_NDQ);
6463 }
6464 break;
6465
6466 case OP_RND_RNSC:
6467 {
6468 po_scalar_or_goto (8, try_vfd);
6469 break;
6470 try_vfd:
6471 po_reg_or_fail (REG_TYPE_VFD);
6472 }
6473 break;
6474
6475 case OP_VMOV:
6476 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6477 not careful then bad things might happen. */
6478 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6479 break;
6480
4316f0d2 6481 case OP_RNDQ_Ibig:
5287ad62 6482 {
4316f0d2 6483 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
5287ad62 6484 break;
4316f0d2 6485 try_immbig:
5287ad62
JB
6486 /* There's a possibility of getting a 64-bit immediate here, so
6487 we need special handling. */
6488 if (parse_big_immediate (&str, i) == FAIL)
6489 {
6490 inst.error = _("immediate value is out of range");
6491 goto failure;
6492 }
6493 }
6494 break;
6495
6496 case OP_RNDQ_I63b:
6497 {
6498 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6499 break;
6500 try_shimm:
6501 po_imm_or_fail (0, 63, TRUE);
6502 }
6503 break;
c19d1205
ZW
6504
6505 case OP_RRnpcb:
6506 po_char_or_fail ('[');
6507 po_reg_or_fail (REG_TYPE_RN);
6508 po_char_or_fail (']');
6509 break;
a737bd4d 6510
55881a11 6511 case OP_RRnpctw:
c19d1205 6512 case OP_RRw:
b6702015 6513 case OP_oRRw:
c19d1205
ZW
6514 po_reg_or_fail (REG_TYPE_RN);
6515 if (skip_past_char (&str, '!') == SUCCESS)
6516 inst.operands[i].writeback = 1;
6517 break;
6518
6519 /* Immediates */
6520 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6521 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6522 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 6523 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6524 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6525 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 6526 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6527 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
6528 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6529 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6530 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6531 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6532
6533 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6534 case OP_oI7b:
6535 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6536 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6537 case OP_oI31b:
6538 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 6539 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5f1af56b 6540 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6541 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6542
6543 /* Immediate variants */
6544 case OP_oI255c:
6545 po_char_or_fail ('{');
6546 po_imm_or_fail (0, 255, TRUE);
6547 po_char_or_fail ('}');
6548 break;
6549
6550 case OP_I31w:
6551 /* The expression parser chokes on a trailing !, so we have
6552 to find it first and zap it. */
6553 {
6554 char *s = str;
6555 while (*s && *s != ',')
6556 s++;
6557 if (s[-1] == '!')
6558 {
6559 s[-1] = '\0';
6560 inst.operands[i].writeback = 1;
6561 }
6562 po_imm_or_fail (0, 31, TRUE);
6563 if (str == s - 1)
6564 str = s;
6565 }
6566 break;
6567
6568 /* Expressions */
6569 case OP_EXPi: EXPi:
6570 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6571 GE_OPT_PREFIX));
6572 break;
6573
6574 case OP_EXP:
6575 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6576 GE_NO_PREFIX));
6577 break;
6578
6579 case OP_EXPr: EXPr:
6580 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6581 GE_NO_PREFIX));
6582 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6583 {
c19d1205
ZW
6584 val = parse_reloc (&str);
6585 if (val == -1)
6586 {
6587 inst.error = _("unrecognized relocation suffix");
6588 goto failure;
6589 }
6590 else if (val != BFD_RELOC_UNUSED)
6591 {
6592 inst.operands[i].imm = val;
6593 inst.operands[i].hasreloc = 1;
6594 }
a737bd4d 6595 }
c19d1205 6596 break;
a737bd4d 6597
b6895b4f
PB
6598 /* Operand for MOVW or MOVT. */
6599 case OP_HALF:
6600 po_misc_or_fail (parse_half (&str));
6601 break;
6602
e07e6e58 6603 /* Register or expression. */
c19d1205
ZW
6604 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6605 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6606
e07e6e58 6607 /* Register or immediate. */
c19d1205
ZW
6608 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6609 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6610
c19d1205
ZW
6611 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6612 IF:
6613 if (!is_immediate_prefix (*str))
6614 goto bad_args;
6615 str++;
6616 val = parse_fpa_immediate (&str);
6617 if (val == FAIL)
6618 goto failure;
6619 /* FPA immediates are encoded as registers 8-15.
6620 parse_fpa_immediate has already applied the offset. */
6621 inst.operands[i].reg = val;
6622 inst.operands[i].isreg = 1;
6623 break;
09d92015 6624
2d447fca
JM
6625 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6626 I32z: po_imm_or_fail (0, 32, FALSE); break;
6627
e07e6e58 6628 /* Two kinds of register. */
c19d1205
ZW
6629 case OP_RIWR_RIWC:
6630 {
6631 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6632 if (!rege
6633 || (rege->type != REG_TYPE_MMXWR
6634 && rege->type != REG_TYPE_MMXWC
6635 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6636 {
6637 inst.error = _("iWMMXt data or control register expected");
6638 goto failure;
6639 }
6640 inst.operands[i].reg = rege->number;
6641 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6642 }
6643 break;
09d92015 6644
41adaa5c
JM
6645 case OP_RIWC_RIWG:
6646 {
6647 struct reg_entry *rege = arm_reg_parse_multi (&str);
6648 if (!rege
6649 || (rege->type != REG_TYPE_MMXWC
6650 && rege->type != REG_TYPE_MMXWCG))
6651 {
6652 inst.error = _("iWMMXt control register expected");
6653 goto failure;
6654 }
6655 inst.operands[i].reg = rege->number;
6656 inst.operands[i].isreg = 1;
6657 }
6658 break;
6659
c19d1205
ZW
6660 /* Misc */
6661 case OP_CPSF: val = parse_cps_flags (&str); break;
6662 case OP_ENDI: val = parse_endian_specifier (&str); break;
6663 case OP_oROR: val = parse_ror (&str); break;
c19d1205 6664 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6665 case OP_oBARRIER_I15:
6666 po_barrier_or_imm (str); break;
6667 immediate:
6668 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6669 goto failure;
6670 break;
c19d1205 6671
fa94de6b 6672 case OP_wPSR:
d2cd1205 6673 case OP_rPSR:
90ec0d68
MGD
6674 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6675 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6676 {
6677 inst.error = _("Banked registers are not available with this "
6678 "architecture.");
6679 goto failure;
6680 }
6681 break;
d2cd1205
JB
6682 try_psr:
6683 val = parse_psr (&str, op_parse_code == OP_wPSR);
6684 break;
037e8744
JB
6685
6686 case OP_APSR_RR:
6687 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6688 break;
6689 try_apsr:
6690 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6691 instruction). */
6692 if (strncasecmp (str, "APSR_", 5) == 0)
6693 {
6694 unsigned found = 0;
6695 str += 5;
6696 while (found < 15)
6697 switch (*str++)
6698 {
6699 case 'c': found = (found & 1) ? 16 : found | 1; break;
6700 case 'n': found = (found & 2) ? 16 : found | 2; break;
6701 case 'z': found = (found & 4) ? 16 : found | 4; break;
6702 case 'v': found = (found & 8) ? 16 : found | 8; break;
6703 default: found = 16;
6704 }
6705 if (found != 15)
6706 goto failure;
6707 inst.operands[i].isvec = 1;
f7c21dc7
NC
6708 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6709 inst.operands[i].reg = REG_PC;
037e8744
JB
6710 }
6711 else
6712 goto failure;
6713 break;
6714
92e90b6e
PB
6715 case OP_TB:
6716 po_misc_or_fail (parse_tb (&str));
6717 break;
6718
e07e6e58 6719 /* Register lists. */
c19d1205
ZW
6720 case OP_REGLST:
6721 val = parse_reg_list (&str);
6722 if (*str == '^')
6723 {
6724 inst.operands[1].writeback = 1;
6725 str++;
6726 }
6727 break;
09d92015 6728
c19d1205 6729 case OP_VRSLST:
5287ad62 6730 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6731 break;
09d92015 6732
c19d1205 6733 case OP_VRDLST:
5287ad62 6734 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6735 break;
a737bd4d 6736
037e8744
JB
6737 case OP_VRSDLST:
6738 /* Allow Q registers too. */
6739 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6740 REGLIST_NEON_D);
6741 if (val == FAIL)
6742 {
6743 inst.error = NULL;
6744 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6745 REGLIST_VFP_S);
6746 inst.operands[i].issingle = 1;
6747 }
6748 break;
6749
5287ad62
JB
6750 case OP_NRDLST:
6751 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6752 REGLIST_NEON_D);
6753 break;
6754
6755 case OP_NSTRLST:
dcbf9037
JB
6756 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6757 &inst.operands[i].vectype);
5287ad62
JB
6758 break;
6759
c19d1205
ZW
6760 /* Addressing modes */
6761 case OP_ADDR:
6762 po_misc_or_fail (parse_address (&str, i));
6763 break;
09d92015 6764
4962c51a
MS
6765 case OP_ADDRGLDR:
6766 po_misc_or_fail_no_backtrack (
6767 parse_address_group_reloc (&str, i, GROUP_LDR));
6768 break;
6769
6770 case OP_ADDRGLDRS:
6771 po_misc_or_fail_no_backtrack (
6772 parse_address_group_reloc (&str, i, GROUP_LDRS));
6773 break;
6774
6775 case OP_ADDRGLDC:
6776 po_misc_or_fail_no_backtrack (
6777 parse_address_group_reloc (&str, i, GROUP_LDC));
6778 break;
6779
c19d1205
ZW
6780 case OP_SH:
6781 po_misc_or_fail (parse_shifter_operand (&str, i));
6782 break;
09d92015 6783
4962c51a
MS
6784 case OP_SHG:
6785 po_misc_or_fail_no_backtrack (
6786 parse_shifter_operand_group_reloc (&str, i));
6787 break;
6788
c19d1205
ZW
6789 case OP_oSHll:
6790 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6791 break;
09d92015 6792
c19d1205
ZW
6793 case OP_oSHar:
6794 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6795 break;
09d92015 6796
c19d1205
ZW
6797 case OP_oSHllar:
6798 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6799 break;
09d92015 6800
c19d1205 6801 default:
5be8be5d 6802 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 6803 }
09d92015 6804
c19d1205
ZW
6805 /* Various value-based sanity checks and shared operations. We
6806 do not signal immediate failures for the register constraints;
6807 this allows a syntax error to take precedence. */
5be8be5d 6808 switch (op_parse_code)
c19d1205
ZW
6809 {
6810 case OP_oRRnpc:
6811 case OP_RRnpc:
6812 case OP_RRnpcb:
6813 case OP_RRw:
b6702015 6814 case OP_oRRw:
c19d1205
ZW
6815 case OP_RRnpc_I0:
6816 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6817 inst.error = BAD_PC;
6818 break;
09d92015 6819
5be8be5d
DG
6820 case OP_oRRnpcsp:
6821 case OP_RRnpcsp:
6822 if (inst.operands[i].isreg)
6823 {
6824 if (inst.operands[i].reg == REG_PC)
6825 inst.error = BAD_PC;
6826 else if (inst.operands[i].reg == REG_SP)
6827 inst.error = BAD_SP;
6828 }
6829 break;
6830
55881a11 6831 case OP_RRnpctw:
fa94de6b
RM
6832 if (inst.operands[i].isreg
6833 && inst.operands[i].reg == REG_PC
55881a11
MGD
6834 && (inst.operands[i].writeback || thumb))
6835 inst.error = BAD_PC;
6836 break;
6837
c19d1205
ZW
6838 case OP_CPSF:
6839 case OP_ENDI:
6840 case OP_oROR:
d2cd1205
JB
6841 case OP_wPSR:
6842 case OP_rPSR:
c19d1205 6843 case OP_COND:
52e7f43d 6844 case OP_oBARRIER_I15:
c19d1205
ZW
6845 case OP_REGLST:
6846 case OP_VRSLST:
6847 case OP_VRDLST:
037e8744 6848 case OP_VRSDLST:
5287ad62
JB
6849 case OP_NRDLST:
6850 case OP_NSTRLST:
c19d1205
ZW
6851 if (val == FAIL)
6852 goto failure;
6853 inst.operands[i].imm = val;
6854 break;
a737bd4d 6855
c19d1205
ZW
6856 default:
6857 break;
6858 }
09d92015 6859
c19d1205
ZW
6860 /* If we get here, this operand was successfully parsed. */
6861 inst.operands[i].present = 1;
6862 continue;
09d92015 6863
c19d1205 6864 bad_args:
09d92015 6865 inst.error = BAD_ARGS;
c19d1205
ZW
6866
6867 failure:
6868 if (!backtrack_pos)
d252fdde
PB
6869 {
6870 /* The parse routine should already have set inst.error, but set a
5f4273c7 6871 default here just in case. */
d252fdde
PB
6872 if (!inst.error)
6873 inst.error = _("syntax error");
6874 return FAIL;
6875 }
c19d1205
ZW
6876
6877 /* Do not backtrack over a trailing optional argument that
6878 absorbed some text. We will only fail again, with the
6879 'garbage following instruction' error message, which is
6880 probably less helpful than the current one. */
6881 if (backtrack_index == i && backtrack_pos != str
6882 && upat[i+1] == OP_stop)
d252fdde
PB
6883 {
6884 if (!inst.error)
6885 inst.error = _("syntax error");
6886 return FAIL;
6887 }
c19d1205
ZW
6888
6889 /* Try again, skipping the optional argument at backtrack_pos. */
6890 str = backtrack_pos;
6891 inst.error = backtrack_error;
6892 inst.operands[backtrack_index].present = 0;
6893 i = backtrack_index;
6894 backtrack_pos = 0;
09d92015 6895 }
09d92015 6896
c19d1205
ZW
6897 /* Check that we have parsed all the arguments. */
6898 if (*str != '\0' && !inst.error)
6899 inst.error = _("garbage following instruction");
09d92015 6900
c19d1205 6901 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6902}
6903
c19d1205
ZW
6904#undef po_char_or_fail
6905#undef po_reg_or_fail
6906#undef po_reg_or_goto
6907#undef po_imm_or_fail
5287ad62 6908#undef po_scalar_or_fail
52e7f43d 6909#undef po_barrier_or_imm
e07e6e58 6910
c19d1205 6911/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6912#define constraint(expr, err) \
6913 do \
c19d1205 6914 { \
e07e6e58
NC
6915 if (expr) \
6916 { \
6917 inst.error = err; \
6918 return; \
6919 } \
c19d1205 6920 } \
e07e6e58 6921 while (0)
c19d1205 6922
fdfde340
JM
6923/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6924 instructions are unpredictable if these registers are used. This
6925 is the BadReg predicate in ARM's Thumb-2 documentation. */
6926#define reject_bad_reg(reg) \
6927 do \
6928 if (reg == REG_SP || reg == REG_PC) \
6929 { \
6930 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6931 return; \
6932 } \
6933 while (0)
6934
94206790
MM
6935/* If REG is R13 (the stack pointer), warn that its use is
6936 deprecated. */
6937#define warn_deprecated_sp(reg) \
6938 do \
6939 if (warn_on_deprecated && reg == REG_SP) \
6940 as_warn (_("use of r13 is deprecated")); \
6941 while (0)
6942
c19d1205
ZW
6943/* Functions for operand encoding. ARM, then Thumb. */
6944
6945#define rotate_left(v, n) (v << n | v >> (32 - n))
6946
6947/* If VAL can be encoded in the immediate field of an ARM instruction,
6948 return the encoded form. Otherwise, return FAIL. */
6949
6950static unsigned int
6951encode_arm_immediate (unsigned int val)
09d92015 6952{
c19d1205
ZW
6953 unsigned int a, i;
6954
6955 for (i = 0; i < 32; i += 2)
6956 if ((a = rotate_left (val, i)) <= 0xff)
6957 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6958
6959 return FAIL;
09d92015
MM
6960}
6961
c19d1205
ZW
6962/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6963 return the encoded form. Otherwise, return FAIL. */
6964static unsigned int
6965encode_thumb32_immediate (unsigned int val)
09d92015 6966{
c19d1205 6967 unsigned int a, i;
09d92015 6968
9c3c69f2 6969 if (val <= 0xff)
c19d1205 6970 return val;
a737bd4d 6971
9c3c69f2 6972 for (i = 1; i <= 24; i++)
09d92015 6973 {
9c3c69f2
PB
6974 a = val >> i;
6975 if ((val & ~(0xff << i)) == 0)
6976 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6977 }
a737bd4d 6978
c19d1205
ZW
6979 a = val & 0xff;
6980 if (val == ((a << 16) | a))
6981 return 0x100 | a;
6982 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6983 return 0x300 | a;
09d92015 6984
c19d1205
ZW
6985 a = val & 0xff00;
6986 if (val == ((a << 16) | a))
6987 return 0x200 | (a >> 8);
a737bd4d 6988
c19d1205 6989 return FAIL;
09d92015 6990}
5287ad62 6991/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6992
6993static void
5287ad62
JB
6994encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6995{
6996 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6997 && reg > 15)
6998 {
b1cc4aeb 6999 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
7000 {
7001 if (thumb_mode)
7002 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 7003 fpu_vfp_ext_d32);
5287ad62
JB
7004 else
7005 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 7006 fpu_vfp_ext_d32);
5287ad62
JB
7007 }
7008 else
7009 {
dcbf9037 7010 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
7011 return;
7012 }
7013 }
7014
c19d1205 7015 switch (pos)
09d92015 7016 {
c19d1205
ZW
7017 case VFP_REG_Sd:
7018 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7019 break;
7020
7021 case VFP_REG_Sn:
7022 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7023 break;
7024
7025 case VFP_REG_Sm:
7026 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7027 break;
7028
5287ad62
JB
7029 case VFP_REG_Dd:
7030 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7031 break;
5f4273c7 7032
5287ad62
JB
7033 case VFP_REG_Dn:
7034 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7035 break;
5f4273c7 7036
5287ad62
JB
7037 case VFP_REG_Dm:
7038 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7039 break;
7040
c19d1205
ZW
7041 default:
7042 abort ();
09d92015 7043 }
09d92015
MM
7044}
7045
c19d1205 7046/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7047 if any, is handled by md_apply_fix. */
09d92015 7048static void
c19d1205 7049encode_arm_shift (int i)
09d92015 7050{
c19d1205
ZW
7051 if (inst.operands[i].shift_kind == SHIFT_RRX)
7052 inst.instruction |= SHIFT_ROR << 5;
7053 else
09d92015 7054 {
c19d1205
ZW
7055 inst.instruction |= inst.operands[i].shift_kind << 5;
7056 if (inst.operands[i].immisreg)
7057 {
7058 inst.instruction |= SHIFT_BY_REG;
7059 inst.instruction |= inst.operands[i].imm << 8;
7060 }
7061 else
7062 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7063 }
c19d1205 7064}
09d92015 7065
c19d1205
ZW
7066static void
7067encode_arm_shifter_operand (int i)
7068{
7069 if (inst.operands[i].isreg)
09d92015 7070 {
c19d1205
ZW
7071 inst.instruction |= inst.operands[i].reg;
7072 encode_arm_shift (i);
09d92015 7073 }
c19d1205 7074 else
a415b1cd
JB
7075 {
7076 inst.instruction |= INST_IMMEDIATE;
7077 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7078 inst.instruction |= inst.operands[i].imm;
7079 }
09d92015
MM
7080}
7081
c19d1205 7082/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7083static void
c19d1205 7084encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7085{
2b2f5df9
NC
7086 /* PR 14260:
7087 Generate an error if the operand is not a register. */
7088 constraint (!inst.operands[i].isreg,
7089 _("Instruction does not support =N addresses"));
7090
c19d1205 7091 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7092
c19d1205 7093 if (inst.operands[i].preind)
09d92015 7094 {
c19d1205
ZW
7095 if (is_t)
7096 {
7097 inst.error = _("instruction does not accept preindexed addressing");
7098 return;
7099 }
7100 inst.instruction |= PRE_INDEX;
7101 if (inst.operands[i].writeback)
7102 inst.instruction |= WRITE_BACK;
09d92015 7103
c19d1205
ZW
7104 }
7105 else if (inst.operands[i].postind)
7106 {
9c2799c2 7107 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7108 if (is_t)
7109 inst.instruction |= WRITE_BACK;
7110 }
7111 else /* unindexed - only for coprocessor */
09d92015 7112 {
c19d1205 7113 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7114 return;
7115 }
7116
c19d1205
ZW
7117 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7118 && (((inst.instruction & 0x000f0000) >> 16)
7119 == ((inst.instruction & 0x0000f000) >> 12)))
7120 as_warn ((inst.instruction & LOAD_BIT)
7121 ? _("destination register same as write-back base")
7122 : _("source register same as write-back base"));
09d92015
MM
7123}
7124
c19d1205
ZW
7125/* inst.operands[i] was set up by parse_address. Encode it into an
7126 ARM-format mode 2 load or store instruction. If is_t is true,
7127 reject forms that cannot be used with a T instruction (i.e. not
7128 post-indexed). */
a737bd4d 7129static void
c19d1205 7130encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7131{
5be8be5d
DG
7132 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7133
c19d1205 7134 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7135
c19d1205 7136 if (inst.operands[i].immisreg)
09d92015 7137 {
5be8be5d
DG
7138 constraint ((inst.operands[i].imm == REG_PC
7139 || (is_pc && inst.operands[i].writeback)),
7140 BAD_PC_ADDRESSING);
c19d1205
ZW
7141 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7142 inst.instruction |= inst.operands[i].imm;
7143 if (!inst.operands[i].negative)
7144 inst.instruction |= INDEX_UP;
7145 if (inst.operands[i].shifted)
7146 {
7147 if (inst.operands[i].shift_kind == SHIFT_RRX)
7148 inst.instruction |= SHIFT_ROR << 5;
7149 else
7150 {
7151 inst.instruction |= inst.operands[i].shift_kind << 5;
7152 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7153 }
7154 }
09d92015 7155 }
c19d1205 7156 else /* immediate offset in inst.reloc */
09d92015 7157 {
5be8be5d
DG
7158 if (is_pc && !inst.reloc.pc_rel)
7159 {
7160 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7161
7162 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7163 cannot use PC in addressing.
7164 PC cannot be used in writeback addressing, either. */
7165 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7166 BAD_PC_ADDRESSING);
23a10334 7167
dc5ec521 7168 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7169 if (warn_on_deprecated
7170 && !is_load
7171 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7172 as_warn (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7173 }
7174
c19d1205 7175 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7176 {
7177 /* Prefer + for zero encoded value. */
7178 if (!inst.operands[i].negative)
7179 inst.instruction |= INDEX_UP;
7180 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7181 }
09d92015 7182 }
09d92015
MM
7183}
7184
c19d1205
ZW
7185/* inst.operands[i] was set up by parse_address. Encode it into an
7186 ARM-format mode 3 load or store instruction. Reject forms that
7187 cannot be used with such instructions. If is_t is true, reject
7188 forms that cannot be used with a T instruction (i.e. not
7189 post-indexed). */
7190static void
7191encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7192{
c19d1205 7193 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7194 {
c19d1205
ZW
7195 inst.error = _("instruction does not accept scaled register index");
7196 return;
09d92015 7197 }
a737bd4d 7198
c19d1205 7199 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7200
c19d1205
ZW
7201 if (inst.operands[i].immisreg)
7202 {
5be8be5d
DG
7203 constraint ((inst.operands[i].imm == REG_PC
7204 || inst.operands[i].reg == REG_PC),
7205 BAD_PC_ADDRESSING);
c19d1205
ZW
7206 inst.instruction |= inst.operands[i].imm;
7207 if (!inst.operands[i].negative)
7208 inst.instruction |= INDEX_UP;
7209 }
7210 else /* immediate offset in inst.reloc */
7211 {
5be8be5d
DG
7212 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7213 && inst.operands[i].writeback),
7214 BAD_PC_WRITEBACK);
c19d1205
ZW
7215 inst.instruction |= HWOFFSET_IMM;
7216 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7217 {
7218 /* Prefer + for zero encoded value. */
7219 if (!inst.operands[i].negative)
7220 inst.instruction |= INDEX_UP;
7221
7222 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7223 }
c19d1205 7224 }
a737bd4d
NC
7225}
7226
c19d1205
ZW
7227/* inst.operands[i] was set up by parse_address. Encode it into an
7228 ARM-format instruction. Reject all forms which cannot be encoded
7229 into a coprocessor load/store instruction. If wb_ok is false,
7230 reject use of writeback; if unind_ok is false, reject use of
7231 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
7232 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
7233 (in which case it is preserved). */
09d92015 7234
c19d1205
ZW
7235static int
7236encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 7237{
c19d1205 7238 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7239
9c2799c2 7240 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 7241
c19d1205 7242 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 7243 {
9c2799c2 7244 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
7245 if (!unind_ok)
7246 {
7247 inst.error = _("instruction does not support unindexed addressing");
7248 return FAIL;
7249 }
7250 inst.instruction |= inst.operands[i].imm;
7251 inst.instruction |= INDEX_UP;
7252 return SUCCESS;
09d92015 7253 }
a737bd4d 7254
c19d1205
ZW
7255 if (inst.operands[i].preind)
7256 inst.instruction |= PRE_INDEX;
a737bd4d 7257
c19d1205 7258 if (inst.operands[i].writeback)
09d92015 7259 {
c19d1205
ZW
7260 if (inst.operands[i].reg == REG_PC)
7261 {
7262 inst.error = _("pc may not be used with write-back");
7263 return FAIL;
7264 }
7265 if (!wb_ok)
7266 {
7267 inst.error = _("instruction does not support writeback");
7268 return FAIL;
7269 }
7270 inst.instruction |= WRITE_BACK;
09d92015 7271 }
a737bd4d 7272
c19d1205 7273 if (reloc_override)
21d799b5 7274 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a
MS
7275 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
7276 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
7277 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
7278 {
7279 if (thumb_mode)
7280 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
7281 else
7282 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
7283 }
7284
26d97720
NS
7285 /* Prefer + for zero encoded value. */
7286 if (!inst.operands[i].negative)
7287 inst.instruction |= INDEX_UP;
7288
c19d1205
ZW
7289 return SUCCESS;
7290}
a737bd4d 7291
c19d1205
ZW
7292/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7293 Determine whether it can be performed with a move instruction; if
7294 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7295 return TRUE; if it can't, convert inst.instruction to a literal-pool
7296 load and return FALSE. If this is not a valid thing to do in the
7297 current context, set inst.error and return TRUE.
a737bd4d 7298
c19d1205
ZW
7299 inst.operands[i] describes the destination register. */
7300
c921be7d 7301static bfd_boolean
c19d1205
ZW
7302move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
7303{
53365c0d
PB
7304 unsigned long tbit;
7305
7306 if (thumb_p)
7307 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7308 else
7309 tbit = LOAD_BIT;
7310
7311 if ((inst.instruction & tbit) == 0)
09d92015 7312 {
c19d1205 7313 inst.error = _("invalid pseudo operation");
c921be7d 7314 return TRUE;
09d92015 7315 }
c19d1205 7316 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
7317 {
7318 inst.error = _("constant expression expected");
c921be7d 7319 return TRUE;
09d92015 7320 }
c19d1205 7321 if (inst.reloc.exp.X_op == O_constant)
09d92015 7322 {
c19d1205
ZW
7323 if (thumb_p)
7324 {
53365c0d 7325 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
7326 {
7327 /* This can be done with a mov(1) instruction. */
7328 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7329 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 7330 return TRUE;
c19d1205
ZW
7331 }
7332 }
7333 else
7334 {
7335 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7336 if (value != FAIL)
7337 {
7338 /* This can be done with a mov instruction. */
7339 inst.instruction &= LITERAL_MASK;
7340 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7341 inst.instruction |= value & 0xfff;
c921be7d 7342 return TRUE;
c19d1205 7343 }
09d92015 7344
c19d1205
ZW
7345 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7346 if (value != FAIL)
7347 {
7348 /* This can be done with a mvn instruction. */
7349 inst.instruction &= LITERAL_MASK;
7350 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7351 inst.instruction |= value & 0xfff;
c921be7d 7352 return TRUE;
c19d1205
ZW
7353 }
7354 }
09d92015
MM
7355 }
7356
c19d1205
ZW
7357 if (add_to_lit_pool () == FAIL)
7358 {
7359 inst.error = _("literal pool insertion failed");
c921be7d 7360 return TRUE;
c19d1205
ZW
7361 }
7362 inst.operands[1].reg = REG_PC;
7363 inst.operands[1].isreg = 1;
7364 inst.operands[1].preind = 1;
7365 inst.reloc.pc_rel = 1;
7366 inst.reloc.type = (thumb_p
7367 ? BFD_RELOC_ARM_THUMB_OFFSET
7368 : (mode_3
7369 ? BFD_RELOC_ARM_HWLITERAL
7370 : BFD_RELOC_ARM_LITERAL));
c921be7d 7371 return FALSE;
09d92015
MM
7372}
7373
5f4273c7 7374/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
7375 First some generics; their names are taken from the conventional
7376 bit positions for register arguments in ARM format instructions. */
09d92015 7377
a737bd4d 7378static void
c19d1205 7379do_noargs (void)
09d92015 7380{
c19d1205 7381}
a737bd4d 7382
c19d1205
ZW
7383static void
7384do_rd (void)
7385{
7386 inst.instruction |= inst.operands[0].reg << 12;
7387}
a737bd4d 7388
c19d1205
ZW
7389static void
7390do_rd_rm (void)
7391{
7392 inst.instruction |= inst.operands[0].reg << 12;
7393 inst.instruction |= inst.operands[1].reg;
7394}
09d92015 7395
9eb6c0f1
MGD
7396static void
7397do_rm_rn (void)
7398{
7399 inst.instruction |= inst.operands[0].reg;
7400 inst.instruction |= inst.operands[1].reg << 16;
7401}
7402
c19d1205
ZW
7403static void
7404do_rd_rn (void)
7405{
7406 inst.instruction |= inst.operands[0].reg << 12;
7407 inst.instruction |= inst.operands[1].reg << 16;
7408}
a737bd4d 7409
c19d1205
ZW
7410static void
7411do_rn_rd (void)
7412{
7413 inst.instruction |= inst.operands[0].reg << 16;
7414 inst.instruction |= inst.operands[1].reg << 12;
7415}
09d92015 7416
59d09be6
MGD
7417static bfd_boolean
7418check_obsolete (const arm_feature_set *feature, const char *msg)
7419{
7420 if (ARM_CPU_IS_ANY (cpu_variant))
7421 {
7422 as_warn ("%s", msg);
7423 return TRUE;
7424 }
7425 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
7426 {
7427 as_bad ("%s", msg);
7428 return TRUE;
7429 }
7430
7431 return FALSE;
7432}
7433
c19d1205
ZW
7434static void
7435do_rd_rm_rn (void)
7436{
9a64e435 7437 unsigned Rn = inst.operands[2].reg;
708587a4 7438 /* Enforce restrictions on SWP instruction. */
9a64e435 7439 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
7440 {
7441 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7442 _("Rn must not overlap other operands"));
7443
59d09be6
MGD
7444 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
7445 */
7446 if (!check_obsolete (&arm_ext_v8,
7447 _("swp{b} use is obsoleted for ARMv8 and later"))
7448 && warn_on_deprecated
7449 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
7450 as_warn (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 7451 }
59d09be6 7452
c19d1205
ZW
7453 inst.instruction |= inst.operands[0].reg << 12;
7454 inst.instruction |= inst.operands[1].reg;
9a64e435 7455 inst.instruction |= Rn << 16;
c19d1205 7456}
09d92015 7457
c19d1205
ZW
7458static void
7459do_rd_rn_rm (void)
7460{
7461 inst.instruction |= inst.operands[0].reg << 12;
7462 inst.instruction |= inst.operands[1].reg << 16;
7463 inst.instruction |= inst.operands[2].reg;
7464}
a737bd4d 7465
c19d1205
ZW
7466static void
7467do_rm_rd_rn (void)
7468{
5be8be5d
DG
7469 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7470 constraint (((inst.reloc.exp.X_op != O_constant
7471 && inst.reloc.exp.X_op != O_illegal)
7472 || inst.reloc.exp.X_add_number != 0),
7473 BAD_ADDR_MODE);
c19d1205
ZW
7474 inst.instruction |= inst.operands[0].reg;
7475 inst.instruction |= inst.operands[1].reg << 12;
7476 inst.instruction |= inst.operands[2].reg << 16;
7477}
09d92015 7478
c19d1205
ZW
7479static void
7480do_imm0 (void)
7481{
7482 inst.instruction |= inst.operands[0].imm;
7483}
09d92015 7484
c19d1205
ZW
7485static void
7486do_rd_cpaddr (void)
7487{
7488 inst.instruction |= inst.operands[0].reg << 12;
7489 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 7490}
a737bd4d 7491
c19d1205
ZW
7492/* ARM instructions, in alphabetical order by function name (except
7493 that wrapper functions appear immediately after the function they
7494 wrap). */
09d92015 7495
c19d1205
ZW
7496/* This is a pseudo-op of the form "adr rd, label" to be converted
7497 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
7498
7499static void
c19d1205 7500do_adr (void)
09d92015 7501{
c19d1205 7502 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7503
c19d1205
ZW
7504 /* Frag hacking will turn this into a sub instruction if the offset turns
7505 out to be negative. */
7506 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 7507 inst.reloc.pc_rel = 1;
2fc8bdac 7508 inst.reloc.exp.X_add_number -= 8;
c19d1205 7509}
b99bd4ef 7510
c19d1205
ZW
7511/* This is a pseudo-op of the form "adrl rd, label" to be converted
7512 into a relative address of the form:
7513 add rd, pc, #low(label-.-8)"
7514 add rd, rd, #high(label-.-8)" */
b99bd4ef 7515
c19d1205
ZW
7516static void
7517do_adrl (void)
7518{
7519 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7520
c19d1205
ZW
7521 /* Frag hacking will turn this into a sub instruction if the offset turns
7522 out to be negative. */
7523 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
7524 inst.reloc.pc_rel = 1;
7525 inst.size = INSN_SIZE * 2;
2fc8bdac 7526 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
7527}
7528
b99bd4ef 7529static void
c19d1205 7530do_arit (void)
b99bd4ef 7531{
c19d1205
ZW
7532 if (!inst.operands[1].present)
7533 inst.operands[1].reg = inst.operands[0].reg;
7534 inst.instruction |= inst.operands[0].reg << 12;
7535 inst.instruction |= inst.operands[1].reg << 16;
7536 encode_arm_shifter_operand (2);
7537}
b99bd4ef 7538
62b3e311
PB
7539static void
7540do_barrier (void)
7541{
7542 if (inst.operands[0].present)
7543 {
7544 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
7545 && inst.operands[0].imm > 0xf
7546 && inst.operands[0].imm < 0x0,
bd3ba5d1 7547 _("bad barrier type"));
62b3e311
PB
7548 inst.instruction |= inst.operands[0].imm;
7549 }
7550 else
7551 inst.instruction |= 0xf;
7552}
7553
c19d1205
ZW
7554static void
7555do_bfc (void)
7556{
7557 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7558 constraint (msb > 32, _("bit-field extends past end of register"));
7559 /* The instruction encoding stores the LSB and MSB,
7560 not the LSB and width. */
7561 inst.instruction |= inst.operands[0].reg << 12;
7562 inst.instruction |= inst.operands[1].imm << 7;
7563 inst.instruction |= (msb - 1) << 16;
7564}
b99bd4ef 7565
c19d1205
ZW
7566static void
7567do_bfi (void)
7568{
7569 unsigned int msb;
b99bd4ef 7570
c19d1205
ZW
7571 /* #0 in second position is alternative syntax for bfc, which is
7572 the same instruction but with REG_PC in the Rm field. */
7573 if (!inst.operands[1].isreg)
7574 inst.operands[1].reg = REG_PC;
b99bd4ef 7575
c19d1205
ZW
7576 msb = inst.operands[2].imm + inst.operands[3].imm;
7577 constraint (msb > 32, _("bit-field extends past end of register"));
7578 /* The instruction encoding stores the LSB and MSB,
7579 not the LSB and width. */
7580 inst.instruction |= inst.operands[0].reg << 12;
7581 inst.instruction |= inst.operands[1].reg;
7582 inst.instruction |= inst.operands[2].imm << 7;
7583 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7584}
7585
b99bd4ef 7586static void
c19d1205 7587do_bfx (void)
b99bd4ef 7588{
c19d1205
ZW
7589 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7590 _("bit-field extends past end of register"));
7591 inst.instruction |= inst.operands[0].reg << 12;
7592 inst.instruction |= inst.operands[1].reg;
7593 inst.instruction |= inst.operands[2].imm << 7;
7594 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7595}
09d92015 7596
c19d1205
ZW
7597/* ARM V5 breakpoint instruction (argument parse)
7598 BKPT <16 bit unsigned immediate>
7599 Instruction is not conditional.
7600 The bit pattern given in insns[] has the COND_ALWAYS condition,
7601 and it is an error if the caller tried to override that. */
b99bd4ef 7602
c19d1205
ZW
7603static void
7604do_bkpt (void)
7605{
7606 /* Top 12 of 16 bits to bits 19:8. */
7607 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7608
c19d1205
ZW
7609 /* Bottom 4 of 16 bits to bits 3:0. */
7610 inst.instruction |= inst.operands[0].imm & 0xf;
7611}
09d92015 7612
c19d1205
ZW
7613static void
7614encode_branch (int default_reloc)
7615{
7616 if (inst.operands[0].hasreloc)
7617 {
0855e32b
NS
7618 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
7619 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
7620 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
7621 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
7622 ? BFD_RELOC_ARM_PLT32
7623 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 7624 }
b99bd4ef 7625 else
9ae92b05 7626 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 7627 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7628}
7629
b99bd4ef 7630static void
c19d1205 7631do_branch (void)
b99bd4ef 7632{
39b41c9c
PB
7633#ifdef OBJ_ELF
7634 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7635 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7636 else
7637#endif
7638 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7639}
7640
7641static void
7642do_bl (void)
7643{
7644#ifdef OBJ_ELF
7645 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7646 {
7647 if (inst.cond == COND_ALWAYS)
7648 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7649 else
7650 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7651 }
7652 else
7653#endif
7654 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7655}
b99bd4ef 7656
c19d1205
ZW
7657/* ARM V5 branch-link-exchange instruction (argument parse)
7658 BLX <target_addr> ie BLX(1)
7659 BLX{<condition>} <Rm> ie BLX(2)
7660 Unfortunately, there are two different opcodes for this mnemonic.
7661 So, the insns[].value is not used, and the code here zaps values
7662 into inst.instruction.
7663 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7664
c19d1205
ZW
7665static void
7666do_blx (void)
7667{
7668 if (inst.operands[0].isreg)
b99bd4ef 7669 {
c19d1205
ZW
7670 /* Arg is a register; the opcode provided by insns[] is correct.
7671 It is not illegal to do "blx pc", just useless. */
7672 if (inst.operands[0].reg == REG_PC)
7673 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7674
c19d1205
ZW
7675 inst.instruction |= inst.operands[0].reg;
7676 }
7677 else
b99bd4ef 7678 {
c19d1205 7679 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7680 conditionally, and the opcode must be adjusted.
7681 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7682 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7683 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7684 inst.instruction = 0xfa000000;
267bf995 7685 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7686 }
c19d1205
ZW
7687}
7688
7689static void
7690do_bx (void)
7691{
845b51d6
PB
7692 bfd_boolean want_reloc;
7693
c19d1205
ZW
7694 if (inst.operands[0].reg == REG_PC)
7695 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7696
c19d1205 7697 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7698 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7699 it is for ARMv4t or earlier. */
7700 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7701 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7702 want_reloc = TRUE;
7703
5ad34203 7704#ifdef OBJ_ELF
845b51d6 7705 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7706#endif
584206db 7707 want_reloc = FALSE;
845b51d6
PB
7708
7709 if (want_reloc)
7710 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7711}
7712
c19d1205
ZW
7713
7714/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7715
7716static void
c19d1205 7717do_bxj (void)
a737bd4d 7718{
c19d1205
ZW
7719 if (inst.operands[0].reg == REG_PC)
7720 as_tsktsk (_("use of r15 in bxj is not really useful"));
7721
7722 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7723}
7724
c19d1205
ZW
7725/* Co-processor data operation:
7726 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7727 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7728static void
7729do_cdp (void)
7730{
7731 inst.instruction |= inst.operands[0].reg << 8;
7732 inst.instruction |= inst.operands[1].imm << 20;
7733 inst.instruction |= inst.operands[2].reg << 12;
7734 inst.instruction |= inst.operands[3].reg << 16;
7735 inst.instruction |= inst.operands[4].reg;
7736 inst.instruction |= inst.operands[5].imm << 5;
7737}
a737bd4d
NC
7738
7739static void
c19d1205 7740do_cmp (void)
a737bd4d 7741{
c19d1205
ZW
7742 inst.instruction |= inst.operands[0].reg << 16;
7743 encode_arm_shifter_operand (1);
a737bd4d
NC
7744}
7745
c19d1205
ZW
7746/* Transfer between coprocessor and ARM registers.
7747 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7748 MRC2
7749 MCR{cond}
7750 MCR2
7751
7752 No special properties. */
09d92015 7753
dcbd0d71
MGD
7754struct deprecated_coproc_regs_s
7755{
7756 unsigned cp;
7757 int opc1;
7758 unsigned crn;
7759 unsigned crm;
7760 int opc2;
7761 arm_feature_set deprecated;
7762 arm_feature_set obsoleted;
7763 const char *dep_msg;
7764 const char *obs_msg;
7765};
7766
7767#define DEPR_ACCESS_V8 \
7768 N_("This coprocessor register access is deprecated in ARMv8")
7769
7770/* Table of all deprecated coprocessor registers. */
7771static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
7772{
7773 {15, 0, 7, 10, 5, /* CP15DMB. */
7774 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7775 DEPR_ACCESS_V8, NULL},
7776 {15, 0, 7, 10, 4, /* CP15DSB. */
7777 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7778 DEPR_ACCESS_V8, NULL},
7779 {15, 0, 7, 5, 4, /* CP15ISB. */
7780 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7781 DEPR_ACCESS_V8, NULL},
7782 {14, 6, 1, 0, 0, /* TEEHBR. */
7783 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7784 DEPR_ACCESS_V8, NULL},
7785 {14, 6, 0, 0, 0, /* TEECR. */
7786 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7787 DEPR_ACCESS_V8, NULL},
7788};
7789
7790#undef DEPR_ACCESS_V8
7791
7792static const size_t deprecated_coproc_reg_count =
7793 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
7794
09d92015 7795static void
c19d1205 7796do_co_reg (void)
09d92015 7797{
fdfde340 7798 unsigned Rd;
dcbd0d71 7799 size_t i;
fdfde340
JM
7800
7801 Rd = inst.operands[2].reg;
7802 if (thumb_mode)
7803 {
7804 if (inst.instruction == 0xee000010
7805 || inst.instruction == 0xfe000010)
7806 /* MCR, MCR2 */
7807 reject_bad_reg (Rd);
7808 else
7809 /* MRC, MRC2 */
7810 constraint (Rd == REG_SP, BAD_SP);
7811 }
7812 else
7813 {
7814 /* MCR */
7815 if (inst.instruction == 0xe000010)
7816 constraint (Rd == REG_PC, BAD_PC);
7817 }
7818
dcbd0d71
MGD
7819 for (i = 0; i < deprecated_coproc_reg_count; ++i)
7820 {
7821 const struct deprecated_coproc_regs_s *r =
7822 deprecated_coproc_regs + i;
7823
7824 if (inst.operands[0].reg == r->cp
7825 && inst.operands[1].imm == r->opc1
7826 && inst.operands[3].reg == r->crn
7827 && inst.operands[4].reg == r->crm
7828 && inst.operands[5].imm == r->opc2)
7829 {
7830 if (!check_obsolete (&r->obsoleted, r->obs_msg)
7831 && warn_on_deprecated
7832 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
7833 as_warn ("%s", r->dep_msg);
7834 }
7835 }
fdfde340 7836
c19d1205
ZW
7837 inst.instruction |= inst.operands[0].reg << 8;
7838 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7839 inst.instruction |= Rd << 12;
c19d1205
ZW
7840 inst.instruction |= inst.operands[3].reg << 16;
7841 inst.instruction |= inst.operands[4].reg;
7842 inst.instruction |= inst.operands[5].imm << 5;
7843}
09d92015 7844
c19d1205
ZW
7845/* Transfer between coprocessor register and pair of ARM registers.
7846 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7847 MCRR2
7848 MRRC{cond}
7849 MRRC2
b99bd4ef 7850
c19d1205 7851 Two XScale instructions are special cases of these:
09d92015 7852
c19d1205
ZW
7853 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7854 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7855
5f4273c7 7856 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7857
c19d1205
ZW
7858static void
7859do_co_reg2c (void)
7860{
fdfde340
JM
7861 unsigned Rd, Rn;
7862
7863 Rd = inst.operands[2].reg;
7864 Rn = inst.operands[3].reg;
7865
7866 if (thumb_mode)
7867 {
7868 reject_bad_reg (Rd);
7869 reject_bad_reg (Rn);
7870 }
7871 else
7872 {
7873 constraint (Rd == REG_PC, BAD_PC);
7874 constraint (Rn == REG_PC, BAD_PC);
7875 }
7876
c19d1205
ZW
7877 inst.instruction |= inst.operands[0].reg << 8;
7878 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7879 inst.instruction |= Rd << 12;
7880 inst.instruction |= Rn << 16;
c19d1205 7881 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7882}
7883
c19d1205
ZW
7884static void
7885do_cpsi (void)
7886{
7887 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7888 if (inst.operands[1].present)
7889 {
7890 inst.instruction |= CPSI_MMOD;
7891 inst.instruction |= inst.operands[1].imm;
7892 }
c19d1205 7893}
b99bd4ef 7894
62b3e311
PB
7895static void
7896do_dbg (void)
7897{
7898 inst.instruction |= inst.operands[0].imm;
7899}
7900
eea54501
MGD
7901static void
7902do_div (void)
7903{
7904 unsigned Rd, Rn, Rm;
7905
7906 Rd = inst.operands[0].reg;
7907 Rn = (inst.operands[1].present
7908 ? inst.operands[1].reg : Rd);
7909 Rm = inst.operands[2].reg;
7910
7911 constraint ((Rd == REG_PC), BAD_PC);
7912 constraint ((Rn == REG_PC), BAD_PC);
7913 constraint ((Rm == REG_PC), BAD_PC);
7914
7915 inst.instruction |= Rd << 16;
7916 inst.instruction |= Rn << 0;
7917 inst.instruction |= Rm << 8;
7918}
7919
b99bd4ef 7920static void
c19d1205 7921do_it (void)
b99bd4ef 7922{
c19d1205 7923 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7924 process it to do the validation as if in
7925 thumb mode, just in case the code gets
7926 assembled for thumb using the unified syntax. */
7927
c19d1205 7928 inst.size = 0;
e07e6e58
NC
7929 if (unified_syntax)
7930 {
7931 set_it_insn_type (IT_INSN);
7932 now_it.mask = (inst.instruction & 0xf) | 0x10;
7933 now_it.cc = inst.operands[0].imm;
7934 }
09d92015 7935}
b99bd4ef 7936
6530b175
NC
7937/* If there is only one register in the register list,
7938 then return its register number. Otherwise return -1. */
7939static int
7940only_one_reg_in_list (int range)
7941{
7942 int i = ffs (range) - 1;
7943 return (i > 15 || range != (1 << i)) ? -1 : i;
7944}
7945
09d92015 7946static void
6530b175 7947encode_ldmstm(int from_push_pop_mnem)
ea6ef066 7948{
c19d1205
ZW
7949 int base_reg = inst.operands[0].reg;
7950 int range = inst.operands[1].imm;
6530b175 7951 int one_reg;
ea6ef066 7952
c19d1205
ZW
7953 inst.instruction |= base_reg << 16;
7954 inst.instruction |= range;
ea6ef066 7955
c19d1205
ZW
7956 if (inst.operands[1].writeback)
7957 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7958
c19d1205 7959 if (inst.operands[0].writeback)
ea6ef066 7960 {
c19d1205
ZW
7961 inst.instruction |= WRITE_BACK;
7962 /* Check for unpredictable uses of writeback. */
7963 if (inst.instruction & LOAD_BIT)
09d92015 7964 {
c19d1205
ZW
7965 /* Not allowed in LDM type 2. */
7966 if ((inst.instruction & LDM_TYPE_2_OR_3)
7967 && ((range & (1 << REG_PC)) == 0))
7968 as_warn (_("writeback of base register is UNPREDICTABLE"));
7969 /* Only allowed if base reg not in list for other types. */
7970 else if (range & (1 << base_reg))
7971 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7972 }
7973 else /* STM. */
7974 {
7975 /* Not allowed for type 2. */
7976 if (inst.instruction & LDM_TYPE_2_OR_3)
7977 as_warn (_("writeback of base register is UNPREDICTABLE"));
7978 /* Only allowed if base reg not in list, or first in list. */
7979 else if ((range & (1 << base_reg))
7980 && (range & ((1 << base_reg) - 1)))
7981 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7982 }
ea6ef066 7983 }
6530b175
NC
7984
7985 /* If PUSH/POP has only one register, then use the A2 encoding. */
7986 one_reg = only_one_reg_in_list (range);
7987 if (from_push_pop_mnem && one_reg >= 0)
7988 {
7989 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
7990
7991 inst.instruction &= A_COND_MASK;
7992 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
7993 inst.instruction |= one_reg << 12;
7994 }
7995}
7996
7997static void
7998do_ldmstm (void)
7999{
8000 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8001}
8002
c19d1205
ZW
8003/* ARMv5TE load-consecutive (argument parse)
8004 Mode is like LDRH.
8005
8006 LDRccD R, mode
8007 STRccD R, mode. */
8008
a737bd4d 8009static void
c19d1205 8010do_ldrd (void)
a737bd4d 8011{
c19d1205 8012 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8013 _("first transfer register must be even"));
c19d1205
ZW
8014 constraint (inst.operands[1].present
8015 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8016 _("can only transfer two consecutive registers"));
c19d1205
ZW
8017 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8018 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8019
c19d1205
ZW
8020 if (!inst.operands[1].present)
8021 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8022
c56791bb
RE
8023 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8024 register and the first register written; we have to diagnose
8025 overlap between the base and the second register written here. */
ea6ef066 8026
c56791bb
RE
8027 if (inst.operands[2].reg == inst.operands[1].reg
8028 && (inst.operands[2].writeback || inst.operands[2].postind))
8029 as_warn (_("base register written back, and overlaps "
8030 "second transfer register"));
b05fe5cf 8031
c56791bb
RE
8032 if (!(inst.instruction & V4_STR_BIT))
8033 {
c19d1205 8034 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8035 destination (even if not write-back). */
8036 if (inst.operands[2].immisreg
8037 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8038 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8039 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8040 }
c19d1205
ZW
8041 inst.instruction |= inst.operands[0].reg << 12;
8042 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8043}
8044
8045static void
c19d1205 8046do_ldrex (void)
b05fe5cf 8047{
c19d1205
ZW
8048 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8049 || inst.operands[1].postind || inst.operands[1].writeback
8050 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8051 || inst.operands[1].negative
8052 /* This can arise if the programmer has written
8053 strex rN, rM, foo
8054 or if they have mistakenly used a register name as the last
8055 operand, eg:
8056 strex rN, rM, rX
8057 It is very difficult to distinguish between these two cases
8058 because "rX" might actually be a label. ie the register
8059 name has been occluded by a symbol of the same name. So we
8060 just generate a general 'bad addressing mode' type error
8061 message and leave it up to the programmer to discover the
8062 true cause and fix their mistake. */
8063 || (inst.operands[1].reg == REG_PC),
8064 BAD_ADDR_MODE);
b05fe5cf 8065
c19d1205
ZW
8066 constraint (inst.reloc.exp.X_op != O_constant
8067 || inst.reloc.exp.X_add_number != 0,
8068 _("offset must be zero in ARM encoding"));
b05fe5cf 8069
5be8be5d
DG
8070 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8071
c19d1205
ZW
8072 inst.instruction |= inst.operands[0].reg << 12;
8073 inst.instruction |= inst.operands[1].reg << 16;
8074 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8075}
8076
8077static void
c19d1205 8078do_ldrexd (void)
b05fe5cf 8079{
c19d1205
ZW
8080 constraint (inst.operands[0].reg % 2 != 0,
8081 _("even register required"));
8082 constraint (inst.operands[1].present
8083 && inst.operands[1].reg != inst.operands[0].reg + 1,
8084 _("can only load two consecutive registers"));
8085 /* If op 1 were present and equal to PC, this function wouldn't
8086 have been called in the first place. */
8087 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8088
c19d1205
ZW
8089 inst.instruction |= inst.operands[0].reg << 12;
8090 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8091}
8092
1be5fd2e
NC
8093/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8094 which is not a multiple of four is UNPREDICTABLE. */
8095static void
8096check_ldr_r15_aligned (void)
8097{
8098 constraint (!(inst.operands[1].immisreg)
8099 && (inst.operands[0].reg == REG_PC
8100 && inst.operands[1].reg == REG_PC
8101 && (inst.reloc.exp.X_add_number & 0x3)),
8102 _("ldr to register 15 must be 4-byte alligned"));
8103}
8104
b05fe5cf 8105static void
c19d1205 8106do_ldst (void)
b05fe5cf 8107{
c19d1205
ZW
8108 inst.instruction |= inst.operands[0].reg << 12;
8109 if (!inst.operands[1].isreg)
8110 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 8111 return;
c19d1205 8112 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8113 check_ldr_r15_aligned ();
b05fe5cf
ZW
8114}
8115
8116static void
c19d1205 8117do_ldstt (void)
b05fe5cf 8118{
c19d1205
ZW
8119 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8120 reject [Rn,...]. */
8121 if (inst.operands[1].preind)
b05fe5cf 8122 {
bd3ba5d1
NC
8123 constraint (inst.reloc.exp.X_op != O_constant
8124 || inst.reloc.exp.X_add_number != 0,
c19d1205 8125 _("this instruction requires a post-indexed address"));
b05fe5cf 8126
c19d1205
ZW
8127 inst.operands[1].preind = 0;
8128 inst.operands[1].postind = 1;
8129 inst.operands[1].writeback = 1;
b05fe5cf 8130 }
c19d1205
ZW
8131 inst.instruction |= inst.operands[0].reg << 12;
8132 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8133}
b05fe5cf 8134
c19d1205 8135/* Halfword and signed-byte load/store operations. */
b05fe5cf 8136
c19d1205
ZW
8137static void
8138do_ldstv4 (void)
8139{
ff4a8d2b 8140 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8141 inst.instruction |= inst.operands[0].reg << 12;
8142 if (!inst.operands[1].isreg)
8143 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 8144 return;
c19d1205 8145 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
8146}
8147
8148static void
c19d1205 8149do_ldsttv4 (void)
b05fe5cf 8150{
c19d1205
ZW
8151 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8152 reject [Rn,...]. */
8153 if (inst.operands[1].preind)
b05fe5cf 8154 {
bd3ba5d1
NC
8155 constraint (inst.reloc.exp.X_op != O_constant
8156 || inst.reloc.exp.X_add_number != 0,
c19d1205 8157 _("this instruction requires a post-indexed address"));
b05fe5cf 8158
c19d1205
ZW
8159 inst.operands[1].preind = 0;
8160 inst.operands[1].postind = 1;
8161 inst.operands[1].writeback = 1;
b05fe5cf 8162 }
c19d1205
ZW
8163 inst.instruction |= inst.operands[0].reg << 12;
8164 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8165}
b05fe5cf 8166
c19d1205
ZW
8167/* Co-processor register load/store.
8168 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8169static void
8170do_lstc (void)
8171{
8172 inst.instruction |= inst.operands[0].reg << 8;
8173 inst.instruction |= inst.operands[1].reg << 12;
8174 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
8175}
8176
b05fe5cf 8177static void
c19d1205 8178do_mlas (void)
b05fe5cf 8179{
8fb9d7b9 8180 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 8181 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 8182 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 8183 && !(inst.instruction & 0x00400000))
8fb9d7b9 8184 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 8185
c19d1205
ZW
8186 inst.instruction |= inst.operands[0].reg << 16;
8187 inst.instruction |= inst.operands[1].reg;
8188 inst.instruction |= inst.operands[2].reg << 8;
8189 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 8190}
b05fe5cf 8191
c19d1205
ZW
8192static void
8193do_mov (void)
8194{
8195 inst.instruction |= inst.operands[0].reg << 12;
8196 encode_arm_shifter_operand (1);
8197}
b05fe5cf 8198
c19d1205
ZW
8199/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8200static void
8201do_mov16 (void)
8202{
b6895b4f
PB
8203 bfd_vma imm;
8204 bfd_boolean top;
8205
8206 top = (inst.instruction & 0x00400000) != 0;
8207 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8208 _(":lower16: not allowed this instruction"));
8209 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8210 _(":upper16: not allowed instruction"));
c19d1205 8211 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
8212 if (inst.reloc.type == BFD_RELOC_UNUSED)
8213 {
8214 imm = inst.reloc.exp.X_add_number;
8215 /* The value is in two pieces: 0:11, 16:19. */
8216 inst.instruction |= (imm & 0x00000fff);
8217 inst.instruction |= (imm & 0x0000f000) << 4;
8218 }
b05fe5cf 8219}
b99bd4ef 8220
037e8744
JB
8221static void do_vfp_nsyn_opcode (const char *);
8222
8223static int
8224do_vfp_nsyn_mrs (void)
8225{
8226 if (inst.operands[0].isvec)
8227 {
8228 if (inst.operands[1].reg != 1)
8229 first_error (_("operand 1 must be FPSCR"));
8230 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8231 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8232 do_vfp_nsyn_opcode ("fmstat");
8233 }
8234 else if (inst.operands[1].isvec)
8235 do_vfp_nsyn_opcode ("fmrx");
8236 else
8237 return FAIL;
5f4273c7 8238
037e8744
JB
8239 return SUCCESS;
8240}
8241
8242static int
8243do_vfp_nsyn_msr (void)
8244{
8245 if (inst.operands[0].isvec)
8246 do_vfp_nsyn_opcode ("fmxr");
8247 else
8248 return FAIL;
8249
8250 return SUCCESS;
8251}
8252
f7c21dc7
NC
8253static void
8254do_vmrs (void)
8255{
8256 unsigned Rt = inst.operands[0].reg;
fa94de6b 8257
f7c21dc7
NC
8258 if (thumb_mode && inst.operands[0].reg == REG_SP)
8259 {
8260 inst.error = BAD_SP;
8261 return;
8262 }
8263
8264 /* APSR_ sets isvec. All other refs to PC are illegal. */
8265 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
8266 {
8267 inst.error = BAD_PC;
8268 return;
8269 }
8270
7465e07a
NC
8271 switch (inst.operands[1].reg)
8272 {
8273 case 0: /* FPSID */
8274 case 1: /* FPSCR */
8275 case 6: /* MVFR1 */
8276 case 7: /* MVFR0 */
8277 case 8: /* FPEXC */
8278 inst.instruction |= (inst.operands[1].reg << 16);
8279 break;
8280 default:
8281 first_error (_("operand 1 must be a VFP extension System Register"));
8282 }
f7c21dc7
NC
8283
8284 inst.instruction |= (Rt << 12);
8285}
8286
8287static void
8288do_vmsr (void)
8289{
8290 unsigned Rt = inst.operands[1].reg;
fa94de6b 8291
f7c21dc7
NC
8292 if (thumb_mode)
8293 reject_bad_reg (Rt);
8294 else if (Rt == REG_PC)
8295 {
8296 inst.error = BAD_PC;
8297 return;
8298 }
8299
7465e07a
NC
8300 switch (inst.operands[0].reg)
8301 {
8302 case 0: /* FPSID */
8303 case 1: /* FPSCR */
8304 case 8: /* FPEXC */
8305 inst.instruction |= (inst.operands[0].reg << 16);
8306 break;
8307 default:
8308 first_error (_("operand 0 must be FPSID or FPSCR pr FPEXC"));
8309 }
f7c21dc7
NC
8310
8311 inst.instruction |= (Rt << 12);
8312}
8313
b99bd4ef 8314static void
c19d1205 8315do_mrs (void)
b99bd4ef 8316{
90ec0d68
MGD
8317 unsigned br;
8318
037e8744
JB
8319 if (do_vfp_nsyn_mrs () == SUCCESS)
8320 return;
8321
ff4a8d2b 8322 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 8323 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
8324
8325 if (inst.operands[1].isreg)
8326 {
8327 br = inst.operands[1].reg;
8328 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
8329 as_bad (_("bad register for mrs"));
8330 }
8331 else
8332 {
8333 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
8334 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
8335 != (PSR_c|PSR_f),
d2cd1205 8336 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
8337 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
8338 }
8339
8340 inst.instruction |= br;
c19d1205 8341}
b99bd4ef 8342
c19d1205
ZW
8343/* Two possible forms:
8344 "{C|S}PSR_<field>, Rm",
8345 "{C|S}PSR_f, #expression". */
b99bd4ef 8346
c19d1205
ZW
8347static void
8348do_msr (void)
8349{
037e8744
JB
8350 if (do_vfp_nsyn_msr () == SUCCESS)
8351 return;
8352
c19d1205
ZW
8353 inst.instruction |= inst.operands[0].imm;
8354 if (inst.operands[1].isreg)
8355 inst.instruction |= inst.operands[1].reg;
8356 else
b99bd4ef 8357 {
c19d1205
ZW
8358 inst.instruction |= INST_IMMEDIATE;
8359 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8360 inst.reloc.pc_rel = 0;
b99bd4ef 8361 }
b99bd4ef
NC
8362}
8363
c19d1205
ZW
8364static void
8365do_mul (void)
a737bd4d 8366{
ff4a8d2b
NC
8367 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
8368
c19d1205
ZW
8369 if (!inst.operands[2].present)
8370 inst.operands[2].reg = inst.operands[0].reg;
8371 inst.instruction |= inst.operands[0].reg << 16;
8372 inst.instruction |= inst.operands[1].reg;
8373 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 8374
8fb9d7b9
MS
8375 if (inst.operands[0].reg == inst.operands[1].reg
8376 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8377 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
8378}
8379
c19d1205
ZW
8380/* Long Multiply Parser
8381 UMULL RdLo, RdHi, Rm, Rs
8382 SMULL RdLo, RdHi, Rm, Rs
8383 UMLAL RdLo, RdHi, Rm, Rs
8384 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
8385
8386static void
c19d1205 8387do_mull (void)
b99bd4ef 8388{
c19d1205
ZW
8389 inst.instruction |= inst.operands[0].reg << 12;
8390 inst.instruction |= inst.operands[1].reg << 16;
8391 inst.instruction |= inst.operands[2].reg;
8392 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 8393
682b27ad
PB
8394 /* rdhi and rdlo must be different. */
8395 if (inst.operands[0].reg == inst.operands[1].reg)
8396 as_tsktsk (_("rdhi and rdlo must be different"));
8397
8398 /* rdhi, rdlo and rm must all be different before armv6. */
8399 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 8400 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 8401 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
8402 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
8403}
b99bd4ef 8404
c19d1205
ZW
8405static void
8406do_nop (void)
8407{
e7495e45
NS
8408 if (inst.operands[0].present
8409 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
8410 {
8411 /* Architectural NOP hints are CPSR sets with no bits selected. */
8412 inst.instruction &= 0xf0000000;
e7495e45
NS
8413 inst.instruction |= 0x0320f000;
8414 if (inst.operands[0].present)
8415 inst.instruction |= inst.operands[0].imm;
c19d1205 8416 }
b99bd4ef
NC
8417}
8418
c19d1205
ZW
8419/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
8420 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
8421 Condition defaults to COND_ALWAYS.
8422 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
8423
8424static void
c19d1205 8425do_pkhbt (void)
b99bd4ef 8426{
c19d1205
ZW
8427 inst.instruction |= inst.operands[0].reg << 12;
8428 inst.instruction |= inst.operands[1].reg << 16;
8429 inst.instruction |= inst.operands[2].reg;
8430 if (inst.operands[3].present)
8431 encode_arm_shift (3);
8432}
b99bd4ef 8433
c19d1205 8434/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 8435
c19d1205
ZW
8436static void
8437do_pkhtb (void)
8438{
8439 if (!inst.operands[3].present)
b99bd4ef 8440 {
c19d1205
ZW
8441 /* If the shift specifier is omitted, turn the instruction
8442 into pkhbt rd, rm, rn. */
8443 inst.instruction &= 0xfff00010;
8444 inst.instruction |= inst.operands[0].reg << 12;
8445 inst.instruction |= inst.operands[1].reg;
8446 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8447 }
8448 else
8449 {
c19d1205
ZW
8450 inst.instruction |= inst.operands[0].reg << 12;
8451 inst.instruction |= inst.operands[1].reg << 16;
8452 inst.instruction |= inst.operands[2].reg;
8453 encode_arm_shift (3);
b99bd4ef
NC
8454 }
8455}
8456
c19d1205 8457/* ARMv5TE: Preload-Cache
60e5ef9f 8458 MP Extensions: Preload for write
c19d1205 8459
60e5ef9f 8460 PLD(W) <addr_mode>
c19d1205
ZW
8461
8462 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
8463
8464static void
c19d1205 8465do_pld (void)
b99bd4ef 8466{
c19d1205
ZW
8467 constraint (!inst.operands[0].isreg,
8468 _("'[' expected after PLD mnemonic"));
8469 constraint (inst.operands[0].postind,
8470 _("post-indexed expression used in preload instruction"));
8471 constraint (inst.operands[0].writeback,
8472 _("writeback used in preload instruction"));
8473 constraint (!inst.operands[0].preind,
8474 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
8475 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8476}
b99bd4ef 8477
62b3e311
PB
8478/* ARMv7: PLI <addr_mode> */
8479static void
8480do_pli (void)
8481{
8482 constraint (!inst.operands[0].isreg,
8483 _("'[' expected after PLI mnemonic"));
8484 constraint (inst.operands[0].postind,
8485 _("post-indexed expression used in preload instruction"));
8486 constraint (inst.operands[0].writeback,
8487 _("writeback used in preload instruction"));
8488 constraint (!inst.operands[0].preind,
8489 _("unindexed addressing used in preload instruction"));
8490 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8491 inst.instruction &= ~PRE_INDEX;
8492}
8493
c19d1205
ZW
8494static void
8495do_push_pop (void)
8496{
8497 inst.operands[1] = inst.operands[0];
8498 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8499 inst.operands[0].isreg = 1;
8500 inst.operands[0].writeback = 1;
8501 inst.operands[0].reg = REG_SP;
6530b175 8502 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 8503}
b99bd4ef 8504
c19d1205
ZW
8505/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8506 word at the specified address and the following word
8507 respectively.
8508 Unconditionally executed.
8509 Error if Rn is R15. */
b99bd4ef 8510
c19d1205
ZW
8511static void
8512do_rfe (void)
8513{
8514 inst.instruction |= inst.operands[0].reg << 16;
8515 if (inst.operands[0].writeback)
8516 inst.instruction |= WRITE_BACK;
8517}
b99bd4ef 8518
c19d1205 8519/* ARM V6 ssat (argument parse). */
b99bd4ef 8520
c19d1205
ZW
8521static void
8522do_ssat (void)
8523{
8524 inst.instruction |= inst.operands[0].reg << 12;
8525 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8526 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8527
c19d1205
ZW
8528 if (inst.operands[3].present)
8529 encode_arm_shift (3);
b99bd4ef
NC
8530}
8531
c19d1205 8532/* ARM V6 usat (argument parse). */
b99bd4ef
NC
8533
8534static void
c19d1205 8535do_usat (void)
b99bd4ef 8536{
c19d1205
ZW
8537 inst.instruction |= inst.operands[0].reg << 12;
8538 inst.instruction |= inst.operands[1].imm << 16;
8539 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8540
c19d1205
ZW
8541 if (inst.operands[3].present)
8542 encode_arm_shift (3);
b99bd4ef
NC
8543}
8544
c19d1205 8545/* ARM V6 ssat16 (argument parse). */
09d92015
MM
8546
8547static void
c19d1205 8548do_ssat16 (void)
09d92015 8549{
c19d1205
ZW
8550 inst.instruction |= inst.operands[0].reg << 12;
8551 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8552 inst.instruction |= inst.operands[2].reg;
09d92015
MM
8553}
8554
c19d1205
ZW
8555static void
8556do_usat16 (void)
a737bd4d 8557{
c19d1205
ZW
8558 inst.instruction |= inst.operands[0].reg << 12;
8559 inst.instruction |= inst.operands[1].imm << 16;
8560 inst.instruction |= inst.operands[2].reg;
8561}
a737bd4d 8562
c19d1205
ZW
8563/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8564 preserving the other bits.
a737bd4d 8565
c19d1205
ZW
8566 setend <endian_specifier>, where <endian_specifier> is either
8567 BE or LE. */
a737bd4d 8568
c19d1205
ZW
8569static void
8570do_setend (void)
8571{
12e37cbc
MGD
8572 if (warn_on_deprecated
8573 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
8574 as_warn (_("setend use is deprecated for ARMv8"));
8575
c19d1205
ZW
8576 if (inst.operands[0].imm)
8577 inst.instruction |= 0x200;
a737bd4d
NC
8578}
8579
8580static void
c19d1205 8581do_shift (void)
a737bd4d 8582{
c19d1205
ZW
8583 unsigned int Rm = (inst.operands[1].present
8584 ? inst.operands[1].reg
8585 : inst.operands[0].reg);
a737bd4d 8586
c19d1205
ZW
8587 inst.instruction |= inst.operands[0].reg << 12;
8588 inst.instruction |= Rm;
8589 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 8590 {
c19d1205
ZW
8591 inst.instruction |= inst.operands[2].reg << 8;
8592 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
8593 /* PR 12854: Error on extraneous shifts. */
8594 constraint (inst.operands[2].shifted,
8595 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
8596 }
8597 else
c19d1205 8598 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
8599}
8600
09d92015 8601static void
3eb17e6b 8602do_smc (void)
09d92015 8603{
3eb17e6b 8604 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 8605 inst.reloc.pc_rel = 0;
09d92015
MM
8606}
8607
90ec0d68
MGD
8608static void
8609do_hvc (void)
8610{
8611 inst.reloc.type = BFD_RELOC_ARM_HVC;
8612 inst.reloc.pc_rel = 0;
8613}
8614
09d92015 8615static void
c19d1205 8616do_swi (void)
09d92015 8617{
c19d1205
ZW
8618 inst.reloc.type = BFD_RELOC_ARM_SWI;
8619 inst.reloc.pc_rel = 0;
09d92015
MM
8620}
8621
c19d1205
ZW
8622/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8623 SMLAxy{cond} Rd,Rm,Rs,Rn
8624 SMLAWy{cond} Rd,Rm,Rs,Rn
8625 Error if any register is R15. */
e16bb312 8626
c19d1205
ZW
8627static void
8628do_smla (void)
e16bb312 8629{
c19d1205
ZW
8630 inst.instruction |= inst.operands[0].reg << 16;
8631 inst.instruction |= inst.operands[1].reg;
8632 inst.instruction |= inst.operands[2].reg << 8;
8633 inst.instruction |= inst.operands[3].reg << 12;
8634}
a737bd4d 8635
c19d1205
ZW
8636/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8637 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8638 Error if any register is R15.
8639 Warning if Rdlo == Rdhi. */
a737bd4d 8640
c19d1205
ZW
8641static void
8642do_smlal (void)
8643{
8644 inst.instruction |= inst.operands[0].reg << 12;
8645 inst.instruction |= inst.operands[1].reg << 16;
8646 inst.instruction |= inst.operands[2].reg;
8647 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 8648
c19d1205
ZW
8649 if (inst.operands[0].reg == inst.operands[1].reg)
8650 as_tsktsk (_("rdhi and rdlo must be different"));
8651}
a737bd4d 8652
c19d1205
ZW
8653/* ARM V5E (El Segundo) signed-multiply (argument parse)
8654 SMULxy{cond} Rd,Rm,Rs
8655 Error if any register is R15. */
a737bd4d 8656
c19d1205
ZW
8657static void
8658do_smul (void)
8659{
8660 inst.instruction |= inst.operands[0].reg << 16;
8661 inst.instruction |= inst.operands[1].reg;
8662 inst.instruction |= inst.operands[2].reg << 8;
8663}
a737bd4d 8664
b6702015
PB
8665/* ARM V6 srs (argument parse). The variable fields in the encoding are
8666 the same for both ARM and Thumb-2. */
a737bd4d 8667
c19d1205
ZW
8668static void
8669do_srs (void)
8670{
b6702015
PB
8671 int reg;
8672
8673 if (inst.operands[0].present)
8674 {
8675 reg = inst.operands[0].reg;
fdfde340 8676 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
8677 }
8678 else
fdfde340 8679 reg = REG_SP;
b6702015
PB
8680
8681 inst.instruction |= reg << 16;
8682 inst.instruction |= inst.operands[1].imm;
8683 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
8684 inst.instruction |= WRITE_BACK;
8685}
a737bd4d 8686
c19d1205 8687/* ARM V6 strex (argument parse). */
a737bd4d 8688
c19d1205
ZW
8689static void
8690do_strex (void)
8691{
8692 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8693 || inst.operands[2].postind || inst.operands[2].writeback
8694 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
8695 || inst.operands[2].negative
8696 /* See comment in do_ldrex(). */
8697 || (inst.operands[2].reg == REG_PC),
8698 BAD_ADDR_MODE);
a737bd4d 8699
c19d1205
ZW
8700 constraint (inst.operands[0].reg == inst.operands[1].reg
8701 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 8702
c19d1205
ZW
8703 constraint (inst.reloc.exp.X_op != O_constant
8704 || inst.reloc.exp.X_add_number != 0,
8705 _("offset must be zero in ARM encoding"));
a737bd4d 8706
c19d1205
ZW
8707 inst.instruction |= inst.operands[0].reg << 12;
8708 inst.instruction |= inst.operands[1].reg;
8709 inst.instruction |= inst.operands[2].reg << 16;
8710 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8711}
8712
877807f8
NC
8713static void
8714do_t_strexbh (void)
8715{
8716 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8717 || inst.operands[2].postind || inst.operands[2].writeback
8718 || inst.operands[2].immisreg || inst.operands[2].shifted
8719 || inst.operands[2].negative,
8720 BAD_ADDR_MODE);
8721
8722 constraint (inst.operands[0].reg == inst.operands[1].reg
8723 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8724
8725 do_rm_rd_rn ();
8726}
8727
e16bb312 8728static void
c19d1205 8729do_strexd (void)
e16bb312 8730{
c19d1205
ZW
8731 constraint (inst.operands[1].reg % 2 != 0,
8732 _("even register required"));
8733 constraint (inst.operands[2].present
8734 && inst.operands[2].reg != inst.operands[1].reg + 1,
8735 _("can only store two consecutive registers"));
8736 /* If op 2 were present and equal to PC, this function wouldn't
8737 have been called in the first place. */
8738 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8739
c19d1205
ZW
8740 constraint (inst.operands[0].reg == inst.operands[1].reg
8741 || inst.operands[0].reg == inst.operands[1].reg + 1
8742 || inst.operands[0].reg == inst.operands[3].reg,
8743 BAD_OVERLAP);
e16bb312 8744
c19d1205
ZW
8745 inst.instruction |= inst.operands[0].reg << 12;
8746 inst.instruction |= inst.operands[1].reg;
8747 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8748}
8749
9eb6c0f1
MGD
8750/* ARM V8 STRL. */
8751static void
4b8c8c02 8752do_stlex (void)
9eb6c0f1
MGD
8753{
8754 constraint (inst.operands[0].reg == inst.operands[1].reg
8755 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8756
8757 do_rd_rm_rn ();
8758}
8759
8760static void
4b8c8c02 8761do_t_stlex (void)
9eb6c0f1
MGD
8762{
8763 constraint (inst.operands[0].reg == inst.operands[1].reg
8764 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8765
8766 do_rm_rd_rn ();
8767}
8768
c19d1205
ZW
8769/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8770 extends it to 32-bits, and adds the result to a value in another
8771 register. You can specify a rotation by 0, 8, 16, or 24 bits
8772 before extracting the 16-bit value.
8773 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8774 Condition defaults to COND_ALWAYS.
8775 Error if any register uses R15. */
8776
e16bb312 8777static void
c19d1205 8778do_sxtah (void)
e16bb312 8779{
c19d1205
ZW
8780 inst.instruction |= inst.operands[0].reg << 12;
8781 inst.instruction |= inst.operands[1].reg << 16;
8782 inst.instruction |= inst.operands[2].reg;
8783 inst.instruction |= inst.operands[3].imm << 10;
8784}
e16bb312 8785
c19d1205 8786/* ARM V6 SXTH.
e16bb312 8787
c19d1205
ZW
8788 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8789 Condition defaults to COND_ALWAYS.
8790 Error if any register uses R15. */
e16bb312
NC
8791
8792static void
c19d1205 8793do_sxth (void)
e16bb312 8794{
c19d1205
ZW
8795 inst.instruction |= inst.operands[0].reg << 12;
8796 inst.instruction |= inst.operands[1].reg;
8797 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8798}
c19d1205
ZW
8799\f
8800/* VFP instructions. In a logical order: SP variant first, monad
8801 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8802
8803static void
c19d1205 8804do_vfp_sp_monadic (void)
e16bb312 8805{
5287ad62
JB
8806 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8807 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8808}
8809
8810static void
c19d1205 8811do_vfp_sp_dyadic (void)
e16bb312 8812{
5287ad62
JB
8813 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8814 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8815 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8816}
8817
8818static void
c19d1205 8819do_vfp_sp_compare_z (void)
e16bb312 8820{
5287ad62 8821 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8822}
8823
8824static void
c19d1205 8825do_vfp_dp_sp_cvt (void)
e16bb312 8826{
5287ad62
JB
8827 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8828 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8829}
8830
8831static void
c19d1205 8832do_vfp_sp_dp_cvt (void)
e16bb312 8833{
5287ad62
JB
8834 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8835 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8836}
8837
8838static void
c19d1205 8839do_vfp_reg_from_sp (void)
e16bb312 8840{
c19d1205 8841 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8842 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8843}
8844
8845static void
c19d1205 8846do_vfp_reg2_from_sp2 (void)
e16bb312 8847{
c19d1205
ZW
8848 constraint (inst.operands[2].imm != 2,
8849 _("only two consecutive VFP SP registers allowed here"));
8850 inst.instruction |= inst.operands[0].reg << 12;
8851 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8852 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8853}
8854
8855static void
c19d1205 8856do_vfp_sp_from_reg (void)
e16bb312 8857{
5287ad62 8858 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8859 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8860}
8861
8862static void
c19d1205 8863do_vfp_sp2_from_reg2 (void)
e16bb312 8864{
c19d1205
ZW
8865 constraint (inst.operands[0].imm != 2,
8866 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8867 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8868 inst.instruction |= inst.operands[1].reg << 12;
8869 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8870}
8871
8872static void
c19d1205 8873do_vfp_sp_ldst (void)
e16bb312 8874{
5287ad62 8875 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 8876 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8877}
8878
8879static void
c19d1205 8880do_vfp_dp_ldst (void)
e16bb312 8881{
5287ad62 8882 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 8883 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8884}
8885
c19d1205 8886
e16bb312 8887static void
c19d1205 8888vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8889{
c19d1205
ZW
8890 if (inst.operands[0].writeback)
8891 inst.instruction |= WRITE_BACK;
8892 else
8893 constraint (ldstm_type != VFP_LDSTMIA,
8894 _("this addressing mode requires base-register writeback"));
8895 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8896 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 8897 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
8898}
8899
8900static void
c19d1205 8901vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8902{
c19d1205 8903 int count;
e16bb312 8904
c19d1205
ZW
8905 if (inst.operands[0].writeback)
8906 inst.instruction |= WRITE_BACK;
8907 else
8908 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8909 _("this addressing mode requires base-register writeback"));
e16bb312 8910
c19d1205 8911 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8912 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 8913
c19d1205
ZW
8914 count = inst.operands[1].imm << 1;
8915 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8916 count += 1;
e16bb312 8917
c19d1205 8918 inst.instruction |= count;
e16bb312
NC
8919}
8920
8921static void
c19d1205 8922do_vfp_sp_ldstmia (void)
e16bb312 8923{
c19d1205 8924 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8925}
8926
8927static void
c19d1205 8928do_vfp_sp_ldstmdb (void)
e16bb312 8929{
c19d1205 8930 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8931}
8932
8933static void
c19d1205 8934do_vfp_dp_ldstmia (void)
e16bb312 8935{
c19d1205 8936 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8937}
8938
8939static void
c19d1205 8940do_vfp_dp_ldstmdb (void)
e16bb312 8941{
c19d1205 8942 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8943}
8944
8945static void
c19d1205 8946do_vfp_xp_ldstmia (void)
e16bb312 8947{
c19d1205
ZW
8948 vfp_dp_ldstm (VFP_LDSTMIAX);
8949}
e16bb312 8950
c19d1205
ZW
8951static void
8952do_vfp_xp_ldstmdb (void)
8953{
8954 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 8955}
5287ad62
JB
8956
8957static void
8958do_vfp_dp_rd_rm (void)
8959{
8960 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8961 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8962}
8963
8964static void
8965do_vfp_dp_rn_rd (void)
8966{
8967 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8968 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8969}
8970
8971static void
8972do_vfp_dp_rd_rn (void)
8973{
8974 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8975 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8976}
8977
8978static void
8979do_vfp_dp_rd_rn_rm (void)
8980{
8981 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8982 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8983 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8984}
8985
8986static void
8987do_vfp_dp_rd (void)
8988{
8989 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8990}
8991
8992static void
8993do_vfp_dp_rm_rd_rn (void)
8994{
8995 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8996 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8997 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8998}
8999
9000/* VFPv3 instructions. */
9001static void
9002do_vfp_sp_const (void)
9003{
9004 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9005 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9006 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9007}
9008
9009static void
9010do_vfp_dp_const (void)
9011{
9012 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9013 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9014 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9015}
9016
9017static void
9018vfp_conv (int srcsize)
9019{
5f1af56b
MGD
9020 int immbits = srcsize - inst.operands[1].imm;
9021
fa94de6b
RM
9022 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9023 {
5f1af56b
MGD
9024 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
9025 i.e. immbits must be in range 0 - 16. */
9026 inst.error = _("immediate value out of range, expected range [0, 16]");
9027 return;
9028 }
fa94de6b 9029 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9030 {
9031 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
9032 i.e. immbits must be in range 0 - 31. */
9033 inst.error = _("immediate value out of range, expected range [1, 32]");
9034 return;
9035 }
9036
5287ad62
JB
9037 inst.instruction |= (immbits & 1) << 5;
9038 inst.instruction |= (immbits >> 1);
9039}
9040
9041static void
9042do_vfp_sp_conv_16 (void)
9043{
9044 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9045 vfp_conv (16);
9046}
9047
9048static void
9049do_vfp_dp_conv_16 (void)
9050{
9051 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9052 vfp_conv (16);
9053}
9054
9055static void
9056do_vfp_sp_conv_32 (void)
9057{
9058 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9059 vfp_conv (32);
9060}
9061
9062static void
9063do_vfp_dp_conv_32 (void)
9064{
9065 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9066 vfp_conv (32);
9067}
c19d1205
ZW
9068\f
9069/* FPA instructions. Also in a logical order. */
e16bb312 9070
c19d1205
ZW
9071static void
9072do_fpa_cmp (void)
9073{
9074 inst.instruction |= inst.operands[0].reg << 16;
9075 inst.instruction |= inst.operands[1].reg;
9076}
b99bd4ef
NC
9077
9078static void
c19d1205 9079do_fpa_ldmstm (void)
b99bd4ef 9080{
c19d1205
ZW
9081 inst.instruction |= inst.operands[0].reg << 12;
9082 switch (inst.operands[1].imm)
9083 {
9084 case 1: inst.instruction |= CP_T_X; break;
9085 case 2: inst.instruction |= CP_T_Y; break;
9086 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9087 case 4: break;
9088 default: abort ();
9089 }
b99bd4ef 9090
c19d1205
ZW
9091 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9092 {
9093 /* The instruction specified "ea" or "fd", so we can only accept
9094 [Rn]{!}. The instruction does not really support stacking or
9095 unstacking, so we have to emulate these by setting appropriate
9096 bits and offsets. */
9097 constraint (inst.reloc.exp.X_op != O_constant
9098 || inst.reloc.exp.X_add_number != 0,
9099 _("this instruction does not support indexing"));
b99bd4ef 9100
c19d1205
ZW
9101 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9102 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9103
c19d1205
ZW
9104 if (!(inst.instruction & INDEX_UP))
9105 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9106
c19d1205
ZW
9107 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9108 {
9109 inst.operands[2].preind = 0;
9110 inst.operands[2].postind = 1;
9111 }
9112 }
b99bd4ef 9113
c19d1205 9114 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9115}
c19d1205
ZW
9116\f
9117/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9118
c19d1205
ZW
9119static void
9120do_iwmmxt_tandorc (void)
9121{
9122 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9123}
b99bd4ef 9124
c19d1205
ZW
9125static void
9126do_iwmmxt_textrc (void)
9127{
9128 inst.instruction |= inst.operands[0].reg << 12;
9129 inst.instruction |= inst.operands[1].imm;
9130}
b99bd4ef
NC
9131
9132static void
c19d1205 9133do_iwmmxt_textrm (void)
b99bd4ef 9134{
c19d1205
ZW
9135 inst.instruction |= inst.operands[0].reg << 12;
9136 inst.instruction |= inst.operands[1].reg << 16;
9137 inst.instruction |= inst.operands[2].imm;
9138}
b99bd4ef 9139
c19d1205
ZW
9140static void
9141do_iwmmxt_tinsr (void)
9142{
9143 inst.instruction |= inst.operands[0].reg << 16;
9144 inst.instruction |= inst.operands[1].reg << 12;
9145 inst.instruction |= inst.operands[2].imm;
9146}
b99bd4ef 9147
c19d1205
ZW
9148static void
9149do_iwmmxt_tmia (void)
9150{
9151 inst.instruction |= inst.operands[0].reg << 5;
9152 inst.instruction |= inst.operands[1].reg;
9153 inst.instruction |= inst.operands[2].reg << 12;
9154}
b99bd4ef 9155
c19d1205
ZW
9156static void
9157do_iwmmxt_waligni (void)
9158{
9159 inst.instruction |= inst.operands[0].reg << 12;
9160 inst.instruction |= inst.operands[1].reg << 16;
9161 inst.instruction |= inst.operands[2].reg;
9162 inst.instruction |= inst.operands[3].imm << 20;
9163}
b99bd4ef 9164
2d447fca
JM
9165static void
9166do_iwmmxt_wmerge (void)
9167{
9168 inst.instruction |= inst.operands[0].reg << 12;
9169 inst.instruction |= inst.operands[1].reg << 16;
9170 inst.instruction |= inst.operands[2].reg;
9171 inst.instruction |= inst.operands[3].imm << 21;
9172}
9173
c19d1205
ZW
9174static void
9175do_iwmmxt_wmov (void)
9176{
9177 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9178 inst.instruction |= inst.operands[0].reg << 12;
9179 inst.instruction |= inst.operands[1].reg << 16;
9180 inst.instruction |= inst.operands[1].reg;
9181}
b99bd4ef 9182
c19d1205
ZW
9183static void
9184do_iwmmxt_wldstbh (void)
9185{
8f06b2d8 9186 int reloc;
c19d1205 9187 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
9188 if (thumb_mode)
9189 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9190 else
9191 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9192 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
9193}
9194
c19d1205
ZW
9195static void
9196do_iwmmxt_wldstw (void)
9197{
9198 /* RIWR_RIWC clears .isreg for a control register. */
9199 if (!inst.operands[0].isreg)
9200 {
9201 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9202 inst.instruction |= 0xf0000000;
9203 }
b99bd4ef 9204
c19d1205
ZW
9205 inst.instruction |= inst.operands[0].reg << 12;
9206 encode_arm_cp_address (1, TRUE, TRUE, 0);
9207}
b99bd4ef
NC
9208
9209static void
c19d1205 9210do_iwmmxt_wldstd (void)
b99bd4ef 9211{
c19d1205 9212 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
9213 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9214 && inst.operands[1].immisreg)
9215 {
9216 inst.instruction &= ~0x1a000ff;
9217 inst.instruction |= (0xf << 28);
9218 if (inst.operands[1].preind)
9219 inst.instruction |= PRE_INDEX;
9220 if (!inst.operands[1].negative)
9221 inst.instruction |= INDEX_UP;
9222 if (inst.operands[1].writeback)
9223 inst.instruction |= WRITE_BACK;
9224 inst.instruction |= inst.operands[1].reg << 16;
9225 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9226 inst.instruction |= inst.operands[1].imm;
9227 }
9228 else
9229 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 9230}
b99bd4ef 9231
c19d1205
ZW
9232static void
9233do_iwmmxt_wshufh (void)
9234{
9235 inst.instruction |= inst.operands[0].reg << 12;
9236 inst.instruction |= inst.operands[1].reg << 16;
9237 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
9238 inst.instruction |= (inst.operands[2].imm & 0x0f);
9239}
b99bd4ef 9240
c19d1205
ZW
9241static void
9242do_iwmmxt_wzero (void)
9243{
9244 /* WZERO reg is an alias for WANDN reg, reg, reg. */
9245 inst.instruction |= inst.operands[0].reg;
9246 inst.instruction |= inst.operands[0].reg << 12;
9247 inst.instruction |= inst.operands[0].reg << 16;
9248}
2d447fca
JM
9249
9250static void
9251do_iwmmxt_wrwrwr_or_imm5 (void)
9252{
9253 if (inst.operands[2].isreg)
9254 do_rd_rn_rm ();
9255 else {
9256 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
9257 _("immediate operand requires iWMMXt2"));
9258 do_rd_rn ();
9259 if (inst.operands[2].imm == 0)
9260 {
9261 switch ((inst.instruction >> 20) & 0xf)
9262 {
9263 case 4:
9264 case 5:
9265 case 6:
5f4273c7 9266 case 7:
2d447fca
JM
9267 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
9268 inst.operands[2].imm = 16;
9269 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
9270 break;
9271 case 8:
9272 case 9:
9273 case 10:
9274 case 11:
9275 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
9276 inst.operands[2].imm = 32;
9277 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
9278 break;
9279 case 12:
9280 case 13:
9281 case 14:
9282 case 15:
9283 {
9284 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
9285 unsigned long wrn;
9286 wrn = (inst.instruction >> 16) & 0xf;
9287 inst.instruction &= 0xff0fff0f;
9288 inst.instruction |= wrn;
9289 /* Bail out here; the instruction is now assembled. */
9290 return;
9291 }
9292 }
9293 }
9294 /* Map 32 -> 0, etc. */
9295 inst.operands[2].imm &= 0x1f;
9296 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
9297 }
9298}
c19d1205
ZW
9299\f
9300/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
9301 operations first, then control, shift, and load/store. */
b99bd4ef 9302
c19d1205 9303/* Insns like "foo X,Y,Z". */
b99bd4ef 9304
c19d1205
ZW
9305static void
9306do_mav_triple (void)
9307{
9308 inst.instruction |= inst.operands[0].reg << 16;
9309 inst.instruction |= inst.operands[1].reg;
9310 inst.instruction |= inst.operands[2].reg << 12;
9311}
b99bd4ef 9312
c19d1205
ZW
9313/* Insns like "foo W,X,Y,Z".
9314 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 9315
c19d1205
ZW
9316static void
9317do_mav_quad (void)
9318{
9319 inst.instruction |= inst.operands[0].reg << 5;
9320 inst.instruction |= inst.operands[1].reg << 12;
9321 inst.instruction |= inst.operands[2].reg << 16;
9322 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
9323}
9324
c19d1205
ZW
9325/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
9326static void
9327do_mav_dspsc (void)
a737bd4d 9328{
c19d1205
ZW
9329 inst.instruction |= inst.operands[1].reg << 12;
9330}
a737bd4d 9331
c19d1205
ZW
9332/* Maverick shift immediate instructions.
9333 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
9334 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 9335
c19d1205
ZW
9336static void
9337do_mav_shift (void)
9338{
9339 int imm = inst.operands[2].imm;
a737bd4d 9340
c19d1205
ZW
9341 inst.instruction |= inst.operands[0].reg << 12;
9342 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 9343
c19d1205
ZW
9344 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
9345 Bits 5-7 of the insn should have bits 4-6 of the immediate.
9346 Bit 4 should be 0. */
9347 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 9348
c19d1205
ZW
9349 inst.instruction |= imm;
9350}
9351\f
9352/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 9353
c19d1205
ZW
9354/* Xscale multiply-accumulate (argument parse)
9355 MIAcc acc0,Rm,Rs
9356 MIAPHcc acc0,Rm,Rs
9357 MIAxycc acc0,Rm,Rs. */
a737bd4d 9358
c19d1205
ZW
9359static void
9360do_xsc_mia (void)
9361{
9362 inst.instruction |= inst.operands[1].reg;
9363 inst.instruction |= inst.operands[2].reg << 12;
9364}
a737bd4d 9365
c19d1205 9366/* Xscale move-accumulator-register (argument parse)
a737bd4d 9367
c19d1205 9368 MARcc acc0,RdLo,RdHi. */
b99bd4ef 9369
c19d1205
ZW
9370static void
9371do_xsc_mar (void)
9372{
9373 inst.instruction |= inst.operands[1].reg << 12;
9374 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9375}
9376
c19d1205 9377/* Xscale move-register-accumulator (argument parse)
b99bd4ef 9378
c19d1205 9379 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
9380
9381static void
c19d1205 9382do_xsc_mra (void)
b99bd4ef 9383{
c19d1205
ZW
9384 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
9385 inst.instruction |= inst.operands[0].reg << 12;
9386 inst.instruction |= inst.operands[1].reg << 16;
9387}
9388\f
9389/* Encoding functions relevant only to Thumb. */
b99bd4ef 9390
c19d1205
ZW
9391/* inst.operands[i] is a shifted-register operand; encode
9392 it into inst.instruction in the format used by Thumb32. */
9393
9394static void
9395encode_thumb32_shifted_operand (int i)
9396{
9397 unsigned int value = inst.reloc.exp.X_add_number;
9398 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 9399
9c3c69f2
PB
9400 constraint (inst.operands[i].immisreg,
9401 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
9402 inst.instruction |= inst.operands[i].reg;
9403 if (shift == SHIFT_RRX)
9404 inst.instruction |= SHIFT_ROR << 4;
9405 else
b99bd4ef 9406 {
c19d1205
ZW
9407 constraint (inst.reloc.exp.X_op != O_constant,
9408 _("expression too complex"));
9409
9410 constraint (value > 32
9411 || (value == 32 && (shift == SHIFT_LSL
9412 || shift == SHIFT_ROR)),
9413 _("shift expression is too large"));
9414
9415 if (value == 0)
9416 shift = SHIFT_LSL;
9417 else if (value == 32)
9418 value = 0;
9419
9420 inst.instruction |= shift << 4;
9421 inst.instruction |= (value & 0x1c) << 10;
9422 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 9423 }
c19d1205 9424}
b99bd4ef 9425
b99bd4ef 9426
c19d1205
ZW
9427/* inst.operands[i] was set up by parse_address. Encode it into a
9428 Thumb32 format load or store instruction. Reject forms that cannot
9429 be used with such instructions. If is_t is true, reject forms that
9430 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
9431 that cannot be used with a D instruction. If it is a store insn,
9432 reject PC in Rn. */
b99bd4ef 9433
c19d1205
ZW
9434static void
9435encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
9436{
5be8be5d 9437 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
9438
9439 constraint (!inst.operands[i].isreg,
53365c0d 9440 _("Instruction does not support =N addresses"));
b99bd4ef 9441
c19d1205
ZW
9442 inst.instruction |= inst.operands[i].reg << 16;
9443 if (inst.operands[i].immisreg)
b99bd4ef 9444 {
5be8be5d 9445 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
9446 constraint (is_t || is_d, _("cannot use register index with this instruction"));
9447 constraint (inst.operands[i].negative,
9448 _("Thumb does not support negative register indexing"));
9449 constraint (inst.operands[i].postind,
9450 _("Thumb does not support register post-indexing"));
9451 constraint (inst.operands[i].writeback,
9452 _("Thumb does not support register indexing with writeback"));
9453 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
9454 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 9455
f40d1643 9456 inst.instruction |= inst.operands[i].imm;
c19d1205 9457 if (inst.operands[i].shifted)
b99bd4ef 9458 {
c19d1205
ZW
9459 constraint (inst.reloc.exp.X_op != O_constant,
9460 _("expression too complex"));
9c3c69f2
PB
9461 constraint (inst.reloc.exp.X_add_number < 0
9462 || inst.reloc.exp.X_add_number > 3,
c19d1205 9463 _("shift out of range"));
9c3c69f2 9464 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
9465 }
9466 inst.reloc.type = BFD_RELOC_UNUSED;
9467 }
9468 else if (inst.operands[i].preind)
9469 {
5be8be5d 9470 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 9471 constraint (is_t && inst.operands[i].writeback,
c19d1205 9472 _("cannot use writeback with this instruction"));
5be8be5d
DG
9473 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
9474 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
c19d1205
ZW
9475
9476 if (is_d)
9477 {
9478 inst.instruction |= 0x01000000;
9479 if (inst.operands[i].writeback)
9480 inst.instruction |= 0x00200000;
b99bd4ef 9481 }
c19d1205 9482 else
b99bd4ef 9483 {
c19d1205
ZW
9484 inst.instruction |= 0x00000c00;
9485 if (inst.operands[i].writeback)
9486 inst.instruction |= 0x00000100;
b99bd4ef 9487 }
c19d1205 9488 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 9489 }
c19d1205 9490 else if (inst.operands[i].postind)
b99bd4ef 9491 {
9c2799c2 9492 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
9493 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
9494 constraint (is_t, _("cannot use post-indexing with this instruction"));
9495
9496 if (is_d)
9497 inst.instruction |= 0x00200000;
9498 else
9499 inst.instruction |= 0x00000900;
9500 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9501 }
9502 else /* unindexed - only for coprocessor */
9503 inst.error = _("instruction does not accept unindexed addressing");
9504}
9505
9506/* Table of Thumb instructions which exist in both 16- and 32-bit
9507 encodings (the latter only in post-V6T2 cores). The index is the
9508 value used in the insns table below. When there is more than one
9509 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
9510 holds variant (1).
9511 Also contains several pseudo-instructions used during relaxation. */
c19d1205 9512#define T16_32_TAB \
21d799b5
NC
9513 X(_adc, 4140, eb400000), \
9514 X(_adcs, 4140, eb500000), \
9515 X(_add, 1c00, eb000000), \
9516 X(_adds, 1c00, eb100000), \
9517 X(_addi, 0000, f1000000), \
9518 X(_addis, 0000, f1100000), \
9519 X(_add_pc,000f, f20f0000), \
9520 X(_add_sp,000d, f10d0000), \
9521 X(_adr, 000f, f20f0000), \
9522 X(_and, 4000, ea000000), \
9523 X(_ands, 4000, ea100000), \
9524 X(_asr, 1000, fa40f000), \
9525 X(_asrs, 1000, fa50f000), \
9526 X(_b, e000, f000b000), \
9527 X(_bcond, d000, f0008000), \
9528 X(_bic, 4380, ea200000), \
9529 X(_bics, 4380, ea300000), \
9530 X(_cmn, 42c0, eb100f00), \
9531 X(_cmp, 2800, ebb00f00), \
9532 X(_cpsie, b660, f3af8400), \
9533 X(_cpsid, b670, f3af8600), \
9534 X(_cpy, 4600, ea4f0000), \
9535 X(_dec_sp,80dd, f1ad0d00), \
9536 X(_eor, 4040, ea800000), \
9537 X(_eors, 4040, ea900000), \
9538 X(_inc_sp,00dd, f10d0d00), \
9539 X(_ldmia, c800, e8900000), \
9540 X(_ldr, 6800, f8500000), \
9541 X(_ldrb, 7800, f8100000), \
9542 X(_ldrh, 8800, f8300000), \
9543 X(_ldrsb, 5600, f9100000), \
9544 X(_ldrsh, 5e00, f9300000), \
9545 X(_ldr_pc,4800, f85f0000), \
9546 X(_ldr_pc2,4800, f85f0000), \
9547 X(_ldr_sp,9800, f85d0000), \
9548 X(_lsl, 0000, fa00f000), \
9549 X(_lsls, 0000, fa10f000), \
9550 X(_lsr, 0800, fa20f000), \
9551 X(_lsrs, 0800, fa30f000), \
9552 X(_mov, 2000, ea4f0000), \
9553 X(_movs, 2000, ea5f0000), \
9554 X(_mul, 4340, fb00f000), \
9555 X(_muls, 4340, ffffffff), /* no 32b muls */ \
9556 X(_mvn, 43c0, ea6f0000), \
9557 X(_mvns, 43c0, ea7f0000), \
9558 X(_neg, 4240, f1c00000), /* rsb #0 */ \
9559 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
9560 X(_orr, 4300, ea400000), \
9561 X(_orrs, 4300, ea500000), \
9562 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9563 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9564 X(_rev, ba00, fa90f080), \
9565 X(_rev16, ba40, fa90f090), \
9566 X(_revsh, bac0, fa90f0b0), \
9567 X(_ror, 41c0, fa60f000), \
9568 X(_rors, 41c0, fa70f000), \
9569 X(_sbc, 4180, eb600000), \
9570 X(_sbcs, 4180, eb700000), \
9571 X(_stmia, c000, e8800000), \
9572 X(_str, 6000, f8400000), \
9573 X(_strb, 7000, f8000000), \
9574 X(_strh, 8000, f8200000), \
9575 X(_str_sp,9000, f84d0000), \
9576 X(_sub, 1e00, eba00000), \
9577 X(_subs, 1e00, ebb00000), \
9578 X(_subi, 8000, f1a00000), \
9579 X(_subis, 8000, f1b00000), \
9580 X(_sxtb, b240, fa4ff080), \
9581 X(_sxth, b200, fa0ff080), \
9582 X(_tst, 4200, ea100f00), \
9583 X(_uxtb, b2c0, fa5ff080), \
9584 X(_uxth, b280, fa1ff080), \
9585 X(_nop, bf00, f3af8000), \
9586 X(_yield, bf10, f3af8001), \
9587 X(_wfe, bf20, f3af8002), \
9588 X(_wfi, bf30, f3af8003), \
53c4b28b
MGD
9589 X(_sev, bf40, f3af8004), \
9590 X(_sevl, bf50, f3af8005)
c19d1205
ZW
9591
9592/* To catch errors in encoding functions, the codes are all offset by
9593 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9594 as 16-bit instructions. */
21d799b5 9595#define X(a,b,c) T_MNEM##a
c19d1205
ZW
9596enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9597#undef X
9598
9599#define X(a,b,c) 0x##b
9600static const unsigned short thumb_op16[] = { T16_32_TAB };
9601#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9602#undef X
9603
9604#define X(a,b,c) 0x##c
9605static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
9606#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9607#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
9608#undef X
9609#undef T16_32_TAB
9610
9611/* Thumb instruction encoders, in alphabetical order. */
9612
92e90b6e 9613/* ADDW or SUBW. */
c921be7d 9614
92e90b6e
PB
9615static void
9616do_t_add_sub_w (void)
9617{
9618 int Rd, Rn;
9619
9620 Rd = inst.operands[0].reg;
9621 Rn = inst.operands[1].reg;
9622
539d4391
NC
9623 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9624 is the SP-{plus,minus}-immediate form of the instruction. */
9625 if (Rn == REG_SP)
9626 constraint (Rd == REG_PC, BAD_PC);
9627 else
9628 reject_bad_reg (Rd);
fdfde340 9629
92e90b6e
PB
9630 inst.instruction |= (Rn << 16) | (Rd << 8);
9631 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9632}
9633
c19d1205
ZW
9634/* Parse an add or subtract instruction. We get here with inst.instruction
9635 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9636
9637static void
9638do_t_add_sub (void)
9639{
9640 int Rd, Rs, Rn;
9641
9642 Rd = inst.operands[0].reg;
9643 Rs = (inst.operands[1].present
9644 ? inst.operands[1].reg /* Rd, Rs, foo */
9645 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9646
e07e6e58
NC
9647 if (Rd == REG_PC)
9648 set_it_insn_type_last ();
9649
c19d1205
ZW
9650 if (unified_syntax)
9651 {
0110f2b8
PB
9652 bfd_boolean flags;
9653 bfd_boolean narrow;
9654 int opcode;
9655
9656 flags = (inst.instruction == T_MNEM_adds
9657 || inst.instruction == T_MNEM_subs);
9658 if (flags)
e07e6e58 9659 narrow = !in_it_block ();
0110f2b8 9660 else
e07e6e58 9661 narrow = in_it_block ();
c19d1205 9662 if (!inst.operands[2].isreg)
b99bd4ef 9663 {
16805f35
PB
9664 int add;
9665
fdfde340
JM
9666 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9667
16805f35
PB
9668 add = (inst.instruction == T_MNEM_add
9669 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
9670 opcode = 0;
9671 if (inst.size_req != 4)
9672 {
0110f2b8
PB
9673 /* Attempt to use a narrow opcode, with relaxation if
9674 appropriate. */
9675 if (Rd == REG_SP && Rs == REG_SP && !flags)
9676 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9677 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9678 opcode = T_MNEM_add_sp;
9679 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9680 opcode = T_MNEM_add_pc;
9681 else if (Rd <= 7 && Rs <= 7 && narrow)
9682 {
9683 if (flags)
9684 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9685 else
9686 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9687 }
9688 if (opcode)
9689 {
9690 inst.instruction = THUMB_OP16(opcode);
9691 inst.instruction |= (Rd << 4) | Rs;
9692 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9693 if (inst.size_req != 2)
9694 inst.relax = opcode;
9695 }
9696 else
9697 constraint (inst.size_req == 2, BAD_HIREG);
9698 }
9699 if (inst.size_req == 4
9700 || (inst.size_req != 2 && !opcode))
9701 {
efd81785
PB
9702 if (Rd == REG_PC)
9703 {
fdfde340 9704 constraint (add, BAD_PC);
efd81785
PB
9705 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9706 _("only SUBS PC, LR, #const allowed"));
9707 constraint (inst.reloc.exp.X_op != O_constant,
9708 _("expression too complex"));
9709 constraint (inst.reloc.exp.X_add_number < 0
9710 || inst.reloc.exp.X_add_number > 0xff,
9711 _("immediate value out of range"));
9712 inst.instruction = T2_SUBS_PC_LR
9713 | inst.reloc.exp.X_add_number;
9714 inst.reloc.type = BFD_RELOC_UNUSED;
9715 return;
9716 }
9717 else if (Rs == REG_PC)
16805f35
PB
9718 {
9719 /* Always use addw/subw. */
9720 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9721 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9722 }
9723 else
9724 {
9725 inst.instruction = THUMB_OP32 (inst.instruction);
9726 inst.instruction = (inst.instruction & 0xe1ffffff)
9727 | 0x10000000;
9728 if (flags)
9729 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9730 else
9731 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9732 }
dc4503c6
PB
9733 inst.instruction |= Rd << 8;
9734 inst.instruction |= Rs << 16;
0110f2b8 9735 }
b99bd4ef 9736 }
c19d1205
ZW
9737 else
9738 {
5f4cb198
NC
9739 unsigned int value = inst.reloc.exp.X_add_number;
9740 unsigned int shift = inst.operands[2].shift_kind;
9741
c19d1205
ZW
9742 Rn = inst.operands[2].reg;
9743 /* See if we can do this with a 16-bit instruction. */
9744 if (!inst.operands[2].shifted && inst.size_req != 4)
9745 {
e27ec89e
PB
9746 if (Rd > 7 || Rs > 7 || Rn > 7)
9747 narrow = FALSE;
9748
9749 if (narrow)
c19d1205 9750 {
e27ec89e
PB
9751 inst.instruction = ((inst.instruction == T_MNEM_adds
9752 || inst.instruction == T_MNEM_add)
c19d1205
ZW
9753 ? T_OPCODE_ADD_R3
9754 : T_OPCODE_SUB_R3);
9755 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9756 return;
9757 }
b99bd4ef 9758
7e806470 9759 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 9760 {
7e806470
PB
9761 /* Thumb-1 cores (except v6-M) require at least one high
9762 register in a narrow non flag setting add. */
9763 if (Rd > 7 || Rn > 7
9764 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9765 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9766 {
7e806470
PB
9767 if (Rd == Rn)
9768 {
9769 Rn = Rs;
9770 Rs = Rd;
9771 }
c19d1205
ZW
9772 inst.instruction = T_OPCODE_ADD_HI;
9773 inst.instruction |= (Rd & 8) << 4;
9774 inst.instruction |= (Rd & 7);
9775 inst.instruction |= Rn << 3;
9776 return;
9777 }
c19d1205
ZW
9778 }
9779 }
c921be7d 9780
fdfde340
JM
9781 constraint (Rd == REG_PC, BAD_PC);
9782 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9783 constraint (Rs == REG_PC, BAD_PC);
9784 reject_bad_reg (Rn);
9785
c19d1205
ZW
9786 /* If we get here, it can't be done in 16 bits. */
9787 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9788 _("shift must be constant"));
9789 inst.instruction = THUMB_OP32 (inst.instruction);
9790 inst.instruction |= Rd << 8;
9791 inst.instruction |= Rs << 16;
5f4cb198
NC
9792 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
9793 _("shift value over 3 not allowed in thumb mode"));
9794 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
9795 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
9796 encode_thumb32_shifted_operand (2);
9797 }
9798 }
9799 else
9800 {
9801 constraint (inst.instruction == T_MNEM_adds
9802 || inst.instruction == T_MNEM_subs,
9803 BAD_THUMB32);
b99bd4ef 9804
c19d1205 9805 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9806 {
c19d1205
ZW
9807 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9808 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9809 BAD_HIREG);
9810
9811 inst.instruction = (inst.instruction == T_MNEM_add
9812 ? 0x0000 : 0x8000);
9813 inst.instruction |= (Rd << 4) | Rs;
9814 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9815 return;
9816 }
9817
c19d1205
ZW
9818 Rn = inst.operands[2].reg;
9819 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9820
c19d1205
ZW
9821 /* We now have Rd, Rs, and Rn set to registers. */
9822 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9823 {
c19d1205
ZW
9824 /* Can't do this for SUB. */
9825 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9826 inst.instruction = T_OPCODE_ADD_HI;
9827 inst.instruction |= (Rd & 8) << 4;
9828 inst.instruction |= (Rd & 7);
9829 if (Rs == Rd)
9830 inst.instruction |= Rn << 3;
9831 else if (Rn == Rd)
9832 inst.instruction |= Rs << 3;
9833 else
9834 constraint (1, _("dest must overlap one source register"));
9835 }
9836 else
9837 {
9838 inst.instruction = (inst.instruction == T_MNEM_add
9839 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9840 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9841 }
b99bd4ef 9842 }
b99bd4ef
NC
9843}
9844
c19d1205
ZW
9845static void
9846do_t_adr (void)
9847{
fdfde340
JM
9848 unsigned Rd;
9849
9850 Rd = inst.operands[0].reg;
9851 reject_bad_reg (Rd);
9852
9853 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9854 {
9855 /* Defer to section relaxation. */
9856 inst.relax = inst.instruction;
9857 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9858 inst.instruction |= Rd << 4;
0110f2b8
PB
9859 }
9860 else if (unified_syntax && inst.size_req != 2)
e9f89963 9861 {
0110f2b8 9862 /* Generate a 32-bit opcode. */
e9f89963 9863 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9864 inst.instruction |= Rd << 8;
e9f89963
PB
9865 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9866 inst.reloc.pc_rel = 1;
9867 }
9868 else
9869 {
0110f2b8 9870 /* Generate a 16-bit opcode. */
e9f89963
PB
9871 inst.instruction = THUMB_OP16 (inst.instruction);
9872 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9873 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9874 inst.reloc.pc_rel = 1;
b99bd4ef 9875
fdfde340 9876 inst.instruction |= Rd << 4;
e9f89963 9877 }
c19d1205 9878}
b99bd4ef 9879
c19d1205
ZW
9880/* Arithmetic instructions for which there is just one 16-bit
9881 instruction encoding, and it allows only two low registers.
9882 For maximal compatibility with ARM syntax, we allow three register
9883 operands even when Thumb-32 instructions are not available, as long
9884 as the first two are identical. For instance, both "sbc r0,r1" and
9885 "sbc r0,r0,r1" are allowed. */
b99bd4ef 9886static void
c19d1205 9887do_t_arit3 (void)
b99bd4ef 9888{
c19d1205 9889 int Rd, Rs, Rn;
b99bd4ef 9890
c19d1205
ZW
9891 Rd = inst.operands[0].reg;
9892 Rs = (inst.operands[1].present
9893 ? inst.operands[1].reg /* Rd, Rs, foo */
9894 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9895 Rn = inst.operands[2].reg;
b99bd4ef 9896
fdfde340
JM
9897 reject_bad_reg (Rd);
9898 reject_bad_reg (Rs);
9899 if (inst.operands[2].isreg)
9900 reject_bad_reg (Rn);
9901
c19d1205 9902 if (unified_syntax)
b99bd4ef 9903 {
c19d1205
ZW
9904 if (!inst.operands[2].isreg)
9905 {
9906 /* For an immediate, we always generate a 32-bit opcode;
9907 section relaxation will shrink it later if possible. */
9908 inst.instruction = THUMB_OP32 (inst.instruction);
9909 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9910 inst.instruction |= Rd << 8;
9911 inst.instruction |= Rs << 16;
9912 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9913 }
9914 else
9915 {
e27ec89e
PB
9916 bfd_boolean narrow;
9917
c19d1205 9918 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9919 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9920 narrow = !in_it_block ();
e27ec89e 9921 else
e07e6e58 9922 narrow = in_it_block ();
e27ec89e
PB
9923
9924 if (Rd > 7 || Rn > 7 || Rs > 7)
9925 narrow = FALSE;
9926 if (inst.operands[2].shifted)
9927 narrow = FALSE;
9928 if (inst.size_req == 4)
9929 narrow = FALSE;
9930
9931 if (narrow
c19d1205
ZW
9932 && Rd == Rs)
9933 {
9934 inst.instruction = THUMB_OP16 (inst.instruction);
9935 inst.instruction |= Rd;
9936 inst.instruction |= Rn << 3;
9937 return;
9938 }
b99bd4ef 9939
c19d1205
ZW
9940 /* If we get here, it can't be done in 16 bits. */
9941 constraint (inst.operands[2].shifted
9942 && inst.operands[2].immisreg,
9943 _("shift must be constant"));
9944 inst.instruction = THUMB_OP32 (inst.instruction);
9945 inst.instruction |= Rd << 8;
9946 inst.instruction |= Rs << 16;
9947 encode_thumb32_shifted_operand (2);
9948 }
a737bd4d 9949 }
c19d1205 9950 else
b99bd4ef 9951 {
c19d1205
ZW
9952 /* On its face this is a lie - the instruction does set the
9953 flags. However, the only supported mnemonic in this mode
9954 says it doesn't. */
9955 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9956
c19d1205
ZW
9957 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9958 _("unshifted register required"));
9959 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9960 constraint (Rd != Rs,
9961 _("dest and source1 must be the same register"));
a737bd4d 9962
c19d1205
ZW
9963 inst.instruction = THUMB_OP16 (inst.instruction);
9964 inst.instruction |= Rd;
9965 inst.instruction |= Rn << 3;
b99bd4ef 9966 }
a737bd4d 9967}
b99bd4ef 9968
c19d1205
ZW
9969/* Similarly, but for instructions where the arithmetic operation is
9970 commutative, so we can allow either of them to be different from
9971 the destination operand in a 16-bit instruction. For instance, all
9972 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9973 accepted. */
9974static void
9975do_t_arit3c (void)
a737bd4d 9976{
c19d1205 9977 int Rd, Rs, Rn;
b99bd4ef 9978
c19d1205
ZW
9979 Rd = inst.operands[0].reg;
9980 Rs = (inst.operands[1].present
9981 ? inst.operands[1].reg /* Rd, Rs, foo */
9982 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9983 Rn = inst.operands[2].reg;
c921be7d 9984
fdfde340
JM
9985 reject_bad_reg (Rd);
9986 reject_bad_reg (Rs);
9987 if (inst.operands[2].isreg)
9988 reject_bad_reg (Rn);
a737bd4d 9989
c19d1205 9990 if (unified_syntax)
a737bd4d 9991 {
c19d1205 9992 if (!inst.operands[2].isreg)
b99bd4ef 9993 {
c19d1205
ZW
9994 /* For an immediate, we always generate a 32-bit opcode;
9995 section relaxation will shrink it later if possible. */
9996 inst.instruction = THUMB_OP32 (inst.instruction);
9997 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9998 inst.instruction |= Rd << 8;
9999 inst.instruction |= Rs << 16;
10000 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10001 }
c19d1205 10002 else
a737bd4d 10003 {
e27ec89e
PB
10004 bfd_boolean narrow;
10005
c19d1205 10006 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10007 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10008 narrow = !in_it_block ();
e27ec89e 10009 else
e07e6e58 10010 narrow = in_it_block ();
e27ec89e
PB
10011
10012 if (Rd > 7 || Rn > 7 || Rs > 7)
10013 narrow = FALSE;
10014 if (inst.operands[2].shifted)
10015 narrow = FALSE;
10016 if (inst.size_req == 4)
10017 narrow = FALSE;
10018
10019 if (narrow)
a737bd4d 10020 {
c19d1205 10021 if (Rd == Rs)
a737bd4d 10022 {
c19d1205
ZW
10023 inst.instruction = THUMB_OP16 (inst.instruction);
10024 inst.instruction |= Rd;
10025 inst.instruction |= Rn << 3;
10026 return;
a737bd4d 10027 }
c19d1205 10028 if (Rd == Rn)
a737bd4d 10029 {
c19d1205
ZW
10030 inst.instruction = THUMB_OP16 (inst.instruction);
10031 inst.instruction |= Rd;
10032 inst.instruction |= Rs << 3;
10033 return;
a737bd4d
NC
10034 }
10035 }
c19d1205
ZW
10036
10037 /* If we get here, it can't be done in 16 bits. */
10038 constraint (inst.operands[2].shifted
10039 && inst.operands[2].immisreg,
10040 _("shift must be constant"));
10041 inst.instruction = THUMB_OP32 (inst.instruction);
10042 inst.instruction |= Rd << 8;
10043 inst.instruction |= Rs << 16;
10044 encode_thumb32_shifted_operand (2);
a737bd4d 10045 }
b99bd4ef 10046 }
c19d1205
ZW
10047 else
10048 {
10049 /* On its face this is a lie - the instruction does set the
10050 flags. However, the only supported mnemonic in this mode
10051 says it doesn't. */
10052 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10053
c19d1205
ZW
10054 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10055 _("unshifted register required"));
10056 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10057
10058 inst.instruction = THUMB_OP16 (inst.instruction);
10059 inst.instruction |= Rd;
10060
10061 if (Rd == Rs)
10062 inst.instruction |= Rn << 3;
10063 else if (Rd == Rn)
10064 inst.instruction |= Rs << 3;
10065 else
10066 constraint (1, _("dest must overlap one source register"));
10067 }
a737bd4d
NC
10068}
10069
62b3e311
PB
10070static void
10071do_t_barrier (void)
10072{
10073 if (inst.operands[0].present)
10074 {
10075 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
10076 && inst.operands[0].imm > 0xf
10077 && inst.operands[0].imm < 0x0,
bd3ba5d1 10078 _("bad barrier type"));
62b3e311
PB
10079 inst.instruction |= inst.operands[0].imm;
10080 }
10081 else
10082 inst.instruction |= 0xf;
10083}
10084
c19d1205
ZW
10085static void
10086do_t_bfc (void)
a737bd4d 10087{
fdfde340 10088 unsigned Rd;
c19d1205
ZW
10089 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10090 constraint (msb > 32, _("bit-field extends past end of register"));
10091 /* The instruction encoding stores the LSB and MSB,
10092 not the LSB and width. */
fdfde340
JM
10093 Rd = inst.operands[0].reg;
10094 reject_bad_reg (Rd);
10095 inst.instruction |= Rd << 8;
c19d1205
ZW
10096 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10097 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10098 inst.instruction |= msb - 1;
b99bd4ef
NC
10099}
10100
c19d1205
ZW
10101static void
10102do_t_bfi (void)
b99bd4ef 10103{
fdfde340 10104 int Rd, Rn;
c19d1205 10105 unsigned int msb;
b99bd4ef 10106
fdfde340
JM
10107 Rd = inst.operands[0].reg;
10108 reject_bad_reg (Rd);
10109
c19d1205
ZW
10110 /* #0 in second position is alternative syntax for bfc, which is
10111 the same instruction but with REG_PC in the Rm field. */
10112 if (!inst.operands[1].isreg)
fdfde340
JM
10113 Rn = REG_PC;
10114 else
10115 {
10116 Rn = inst.operands[1].reg;
10117 reject_bad_reg (Rn);
10118 }
b99bd4ef 10119
c19d1205
ZW
10120 msb = inst.operands[2].imm + inst.operands[3].imm;
10121 constraint (msb > 32, _("bit-field extends past end of register"));
10122 /* The instruction encoding stores the LSB and MSB,
10123 not the LSB and width. */
fdfde340
JM
10124 inst.instruction |= Rd << 8;
10125 inst.instruction |= Rn << 16;
c19d1205
ZW
10126 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10127 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10128 inst.instruction |= msb - 1;
b99bd4ef
NC
10129}
10130
c19d1205
ZW
10131static void
10132do_t_bfx (void)
b99bd4ef 10133{
fdfde340
JM
10134 unsigned Rd, Rn;
10135
10136 Rd = inst.operands[0].reg;
10137 Rn = inst.operands[1].reg;
10138
10139 reject_bad_reg (Rd);
10140 reject_bad_reg (Rn);
10141
c19d1205
ZW
10142 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10143 _("bit-field extends past end of register"));
fdfde340
JM
10144 inst.instruction |= Rd << 8;
10145 inst.instruction |= Rn << 16;
c19d1205
ZW
10146 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10147 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10148 inst.instruction |= inst.operands[3].imm - 1;
10149}
b99bd4ef 10150
c19d1205
ZW
10151/* ARM V5 Thumb BLX (argument parse)
10152 BLX <target_addr> which is BLX(1)
10153 BLX <Rm> which is BLX(2)
10154 Unfortunately, there are two different opcodes for this mnemonic.
10155 So, the insns[].value is not used, and the code here zaps values
10156 into inst.instruction.
b99bd4ef 10157
c19d1205
ZW
10158 ??? How to take advantage of the additional two bits of displacement
10159 available in Thumb32 mode? Need new relocation? */
b99bd4ef 10160
c19d1205
ZW
10161static void
10162do_t_blx (void)
10163{
e07e6e58
NC
10164 set_it_insn_type_last ();
10165
c19d1205 10166 if (inst.operands[0].isreg)
fdfde340
JM
10167 {
10168 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10169 /* We have a register, so this is BLX(2). */
10170 inst.instruction |= inst.operands[0].reg << 3;
10171 }
b99bd4ef
NC
10172 else
10173 {
c19d1205 10174 /* No register. This must be BLX(1). */
2fc8bdac 10175 inst.instruction = 0xf000e800;
0855e32b 10176 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
10177 }
10178}
10179
c19d1205
ZW
10180static void
10181do_t_branch (void)
b99bd4ef 10182{
0110f2b8 10183 int opcode;
dfa9f0d5 10184 int cond;
9ae92b05 10185 int reloc;
dfa9f0d5 10186
e07e6e58
NC
10187 cond = inst.cond;
10188 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10189
10190 if (in_it_block ())
dfa9f0d5
PB
10191 {
10192 /* Conditional branches inside IT blocks are encoded as unconditional
10193 branches. */
10194 cond = COND_ALWAYS;
dfa9f0d5
PB
10195 }
10196 else
10197 cond = inst.cond;
10198
10199 if (cond != COND_ALWAYS)
0110f2b8
PB
10200 opcode = T_MNEM_bcond;
10201 else
10202 opcode = inst.instruction;
10203
12d6b0b7
RS
10204 if (unified_syntax
10205 && (inst.size_req == 4
10960bfb
PB
10206 || (inst.size_req != 2
10207 && (inst.operands[0].hasreloc
10208 || inst.reloc.exp.X_op == O_constant))))
c19d1205 10209 {
0110f2b8 10210 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 10211 if (cond == COND_ALWAYS)
9ae92b05 10212 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
10213 else
10214 {
9c2799c2 10215 gas_assert (cond != 0xF);
dfa9f0d5 10216 inst.instruction |= cond << 22;
9ae92b05 10217 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
10218 }
10219 }
b99bd4ef
NC
10220 else
10221 {
0110f2b8 10222 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 10223 if (cond == COND_ALWAYS)
9ae92b05 10224 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 10225 else
b99bd4ef 10226 {
dfa9f0d5 10227 inst.instruction |= cond << 8;
9ae92b05 10228 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 10229 }
0110f2b8
PB
10230 /* Allow section relaxation. */
10231 if (unified_syntax && inst.size_req != 2)
10232 inst.relax = opcode;
b99bd4ef 10233 }
9ae92b05 10234 inst.reloc.type = reloc;
c19d1205 10235 inst.reloc.pc_rel = 1;
b99bd4ef
NC
10236}
10237
8884b720 10238/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 10239 between the two is the maximum immediate allowed - which is passed in
8884b720 10240 RANGE. */
b99bd4ef 10241static void
8884b720 10242do_t_bkpt_hlt1 (int range)
b99bd4ef 10243{
dfa9f0d5
PB
10244 constraint (inst.cond != COND_ALWAYS,
10245 _("instruction is always unconditional"));
c19d1205 10246 if (inst.operands[0].present)
b99bd4ef 10247 {
8884b720 10248 constraint (inst.operands[0].imm > range,
c19d1205
ZW
10249 _("immediate value out of range"));
10250 inst.instruction |= inst.operands[0].imm;
b99bd4ef 10251 }
8884b720
MGD
10252
10253 set_it_insn_type (NEUTRAL_IT_INSN);
10254}
10255
10256static void
10257do_t_hlt (void)
10258{
10259 do_t_bkpt_hlt1 (63);
10260}
10261
10262static void
10263do_t_bkpt (void)
10264{
10265 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
10266}
10267
10268static void
c19d1205 10269do_t_branch23 (void)
b99bd4ef 10270{
e07e6e58 10271 set_it_insn_type_last ();
0855e32b 10272 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 10273
0855e32b
NS
10274 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
10275 this file. We used to simply ignore the PLT reloc type here --
10276 the branch encoding is now needed to deal with TLSCALL relocs.
10277 So if we see a PLT reloc now, put it back to how it used to be to
10278 keep the preexisting behaviour. */
10279 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
10280 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 10281
4343666d 10282#if defined(OBJ_COFF)
c19d1205
ZW
10283 /* If the destination of the branch is a defined symbol which does not have
10284 the THUMB_FUNC attribute, then we must be calling a function which has
10285 the (interfacearm) attribute. We look for the Thumb entry point to that
10286 function and change the branch to refer to that function instead. */
10287 if ( inst.reloc.exp.X_op == O_symbol
10288 && inst.reloc.exp.X_add_symbol != NULL
10289 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10290 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10291 inst.reloc.exp.X_add_symbol =
10292 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 10293#endif
90e4755a
RE
10294}
10295
10296static void
c19d1205 10297do_t_bx (void)
90e4755a 10298{
e07e6e58 10299 set_it_insn_type_last ();
c19d1205
ZW
10300 inst.instruction |= inst.operands[0].reg << 3;
10301 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
10302 should cause the alignment to be checked once it is known. This is
10303 because BX PC only works if the instruction is word aligned. */
10304}
90e4755a 10305
c19d1205
ZW
10306static void
10307do_t_bxj (void)
10308{
fdfde340 10309 int Rm;
90e4755a 10310
e07e6e58 10311 set_it_insn_type_last ();
fdfde340
JM
10312 Rm = inst.operands[0].reg;
10313 reject_bad_reg (Rm);
10314 inst.instruction |= Rm << 16;
90e4755a
RE
10315}
10316
10317static void
c19d1205 10318do_t_clz (void)
90e4755a 10319{
fdfde340
JM
10320 unsigned Rd;
10321 unsigned Rm;
10322
10323 Rd = inst.operands[0].reg;
10324 Rm = inst.operands[1].reg;
10325
10326 reject_bad_reg (Rd);
10327 reject_bad_reg (Rm);
10328
10329 inst.instruction |= Rd << 8;
10330 inst.instruction |= Rm << 16;
10331 inst.instruction |= Rm;
c19d1205 10332}
90e4755a 10333
dfa9f0d5
PB
10334static void
10335do_t_cps (void)
10336{
e07e6e58 10337 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
10338 inst.instruction |= inst.operands[0].imm;
10339}
10340
c19d1205
ZW
10341static void
10342do_t_cpsi (void)
10343{
e07e6e58 10344 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 10345 if (unified_syntax
62b3e311
PB
10346 && (inst.operands[1].present || inst.size_req == 4)
10347 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 10348 {
c19d1205
ZW
10349 unsigned int imod = (inst.instruction & 0x0030) >> 4;
10350 inst.instruction = 0xf3af8000;
10351 inst.instruction |= imod << 9;
10352 inst.instruction |= inst.operands[0].imm << 5;
10353 if (inst.operands[1].present)
10354 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 10355 }
c19d1205 10356 else
90e4755a 10357 {
62b3e311
PB
10358 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
10359 && (inst.operands[0].imm & 4),
10360 _("selected processor does not support 'A' form "
10361 "of this instruction"));
10362 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
10363 _("Thumb does not support the 2-argument "
10364 "form of this instruction"));
10365 inst.instruction |= inst.operands[0].imm;
90e4755a 10366 }
90e4755a
RE
10367}
10368
c19d1205
ZW
10369/* THUMB CPY instruction (argument parse). */
10370
90e4755a 10371static void
c19d1205 10372do_t_cpy (void)
90e4755a 10373{
c19d1205 10374 if (inst.size_req == 4)
90e4755a 10375 {
c19d1205
ZW
10376 inst.instruction = THUMB_OP32 (T_MNEM_mov);
10377 inst.instruction |= inst.operands[0].reg << 8;
10378 inst.instruction |= inst.operands[1].reg;
90e4755a 10379 }
c19d1205 10380 else
90e4755a 10381 {
c19d1205
ZW
10382 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
10383 inst.instruction |= (inst.operands[0].reg & 0x7);
10384 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 10385 }
90e4755a
RE
10386}
10387
90e4755a 10388static void
25fe350b 10389do_t_cbz (void)
90e4755a 10390{
e07e6e58 10391 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
10392 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10393 inst.instruction |= inst.operands[0].reg;
10394 inst.reloc.pc_rel = 1;
10395 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
10396}
90e4755a 10397
62b3e311
PB
10398static void
10399do_t_dbg (void)
10400{
10401 inst.instruction |= inst.operands[0].imm;
10402}
10403
10404static void
10405do_t_div (void)
10406{
fdfde340
JM
10407 unsigned Rd, Rn, Rm;
10408
10409 Rd = inst.operands[0].reg;
10410 Rn = (inst.operands[1].present
10411 ? inst.operands[1].reg : Rd);
10412 Rm = inst.operands[2].reg;
10413
10414 reject_bad_reg (Rd);
10415 reject_bad_reg (Rn);
10416 reject_bad_reg (Rm);
10417
10418 inst.instruction |= Rd << 8;
10419 inst.instruction |= Rn << 16;
10420 inst.instruction |= Rm;
62b3e311
PB
10421}
10422
c19d1205
ZW
10423static void
10424do_t_hint (void)
10425{
10426 if (unified_syntax && inst.size_req == 4)
10427 inst.instruction = THUMB_OP32 (inst.instruction);
10428 else
10429 inst.instruction = THUMB_OP16 (inst.instruction);
10430}
90e4755a 10431
c19d1205
ZW
10432static void
10433do_t_it (void)
10434{
10435 unsigned int cond = inst.operands[0].imm;
e27ec89e 10436
e07e6e58
NC
10437 set_it_insn_type (IT_INSN);
10438 now_it.mask = (inst.instruction & 0xf) | 0x10;
10439 now_it.cc = cond;
5a01bb1d 10440 now_it.warn_deprecated = FALSE;
e27ec89e
PB
10441
10442 /* If the condition is a negative condition, invert the mask. */
c19d1205 10443 if ((cond & 0x1) == 0x0)
90e4755a 10444 {
c19d1205 10445 unsigned int mask = inst.instruction & 0x000f;
90e4755a 10446
c19d1205 10447 if ((mask & 0x7) == 0)
5a01bb1d
MGD
10448 {
10449 /* No conversion needed. */
10450 now_it.block_length = 1;
10451 }
c19d1205 10452 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
10453 {
10454 mask ^= 0x8;
10455 now_it.block_length = 2;
10456 }
e27ec89e 10457 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
10458 {
10459 mask ^= 0xC;
10460 now_it.block_length = 3;
10461 }
c19d1205 10462 else
5a01bb1d
MGD
10463 {
10464 mask ^= 0xE;
10465 now_it.block_length = 4;
10466 }
90e4755a 10467
e27ec89e
PB
10468 inst.instruction &= 0xfff0;
10469 inst.instruction |= mask;
c19d1205 10470 }
90e4755a 10471
c19d1205
ZW
10472 inst.instruction |= cond << 4;
10473}
90e4755a 10474
3c707909
PB
10475/* Helper function used for both push/pop and ldm/stm. */
10476static void
10477encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
10478{
10479 bfd_boolean load;
10480
10481 load = (inst.instruction & (1 << 20)) != 0;
10482
10483 if (mask & (1 << 13))
10484 inst.error = _("SP not allowed in register list");
1e5b0379
NC
10485
10486 if ((mask & (1 << base)) != 0
10487 && writeback)
10488 inst.error = _("having the base register in the register list when "
10489 "using write back is UNPREDICTABLE");
10490
3c707909
PB
10491 if (load)
10492 {
e07e6e58
NC
10493 if (mask & (1 << 15))
10494 {
10495 if (mask & (1 << 14))
10496 inst.error = _("LR and PC should not both be in register list");
10497 else
10498 set_it_insn_type_last ();
10499 }
3c707909
PB
10500 }
10501 else
10502 {
10503 if (mask & (1 << 15))
10504 inst.error = _("PC not allowed in register list");
3c707909
PB
10505 }
10506
10507 if ((mask & (mask - 1)) == 0)
10508 {
10509 /* Single register transfers implemented as str/ldr. */
10510 if (writeback)
10511 {
10512 if (inst.instruction & (1 << 23))
10513 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
10514 else
10515 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
10516 }
10517 else
10518 {
10519 if (inst.instruction & (1 << 23))
10520 inst.instruction = 0x00800000; /* ia -> [base] */
10521 else
10522 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
10523 }
10524
10525 inst.instruction |= 0xf8400000;
10526 if (load)
10527 inst.instruction |= 0x00100000;
10528
5f4273c7 10529 mask = ffs (mask) - 1;
3c707909
PB
10530 mask <<= 12;
10531 }
10532 else if (writeback)
10533 inst.instruction |= WRITE_BACK;
10534
10535 inst.instruction |= mask;
10536 inst.instruction |= base << 16;
10537}
10538
c19d1205
ZW
10539static void
10540do_t_ldmstm (void)
10541{
10542 /* This really doesn't seem worth it. */
10543 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10544 _("expression too complex"));
10545 constraint (inst.operands[1].writeback,
10546 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 10547
c19d1205
ZW
10548 if (unified_syntax)
10549 {
3c707909
PB
10550 bfd_boolean narrow;
10551 unsigned mask;
10552
10553 narrow = FALSE;
c19d1205
ZW
10554 /* See if we can use a 16-bit instruction. */
10555 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
10556 && inst.size_req != 4
3c707909 10557 && !(inst.operands[1].imm & ~0xff))
90e4755a 10558 {
3c707909 10559 mask = 1 << inst.operands[0].reg;
90e4755a 10560
eab4f823 10561 if (inst.operands[0].reg <= 7)
90e4755a 10562 {
3c707909 10563 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
10564 ? inst.operands[0].writeback
10565 : (inst.operands[0].writeback
10566 == !(inst.operands[1].imm & mask)))
10567 {
10568 if (inst.instruction == T_MNEM_stmia
10569 && (inst.operands[1].imm & mask)
10570 && (inst.operands[1].imm & (mask - 1)))
10571 as_warn (_("value stored for r%d is UNKNOWN"),
10572 inst.operands[0].reg);
3c707909 10573
eab4f823
MGD
10574 inst.instruction = THUMB_OP16 (inst.instruction);
10575 inst.instruction |= inst.operands[0].reg << 8;
10576 inst.instruction |= inst.operands[1].imm;
10577 narrow = TRUE;
10578 }
10579 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10580 {
10581 /* This means 1 register in reg list one of 3 situations:
10582 1. Instruction is stmia, but without writeback.
10583 2. lmdia without writeback, but with Rn not in
10584 reglist.
10585 3. ldmia with writeback, but with Rn in reglist.
10586 Case 3 is UNPREDICTABLE behaviour, so we handle
10587 case 1 and 2 which can be converted into a 16-bit
10588 str or ldr. The SP cases are handled below. */
10589 unsigned long opcode;
10590 /* First, record an error for Case 3. */
10591 if (inst.operands[1].imm & mask
10592 && inst.operands[0].writeback)
fa94de6b 10593 inst.error =
eab4f823
MGD
10594 _("having the base register in the register list when "
10595 "using write back is UNPREDICTABLE");
fa94de6b
RM
10596
10597 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
10598 : T_MNEM_ldr);
10599 inst.instruction = THUMB_OP16 (opcode);
10600 inst.instruction |= inst.operands[0].reg << 3;
10601 inst.instruction |= (ffs (inst.operands[1].imm)-1);
10602 narrow = TRUE;
10603 }
90e4755a 10604 }
eab4f823 10605 else if (inst.operands[0] .reg == REG_SP)
90e4755a 10606 {
eab4f823
MGD
10607 if (inst.operands[0].writeback)
10608 {
fa94de6b 10609 inst.instruction =
eab4f823
MGD
10610 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10611 ? T_MNEM_push : T_MNEM_pop);
10612 inst.instruction |= inst.operands[1].imm;
10613 narrow = TRUE;
10614 }
10615 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10616 {
fa94de6b 10617 inst.instruction =
eab4f823
MGD
10618 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10619 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10620 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10621 narrow = TRUE;
10622 }
90e4755a 10623 }
3c707909
PB
10624 }
10625
10626 if (!narrow)
10627 {
c19d1205
ZW
10628 if (inst.instruction < 0xffff)
10629 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 10630
5f4273c7
NC
10631 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10632 inst.operands[0].writeback);
90e4755a
RE
10633 }
10634 }
c19d1205 10635 else
90e4755a 10636 {
c19d1205
ZW
10637 constraint (inst.operands[0].reg > 7
10638 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
10639 constraint (inst.instruction != T_MNEM_ldmia
10640 && inst.instruction != T_MNEM_stmia,
10641 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 10642 if (inst.instruction == T_MNEM_stmia)
f03698e6 10643 {
c19d1205
ZW
10644 if (!inst.operands[0].writeback)
10645 as_warn (_("this instruction will write back the base register"));
10646 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10647 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 10648 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 10649 inst.operands[0].reg);
f03698e6 10650 }
c19d1205 10651 else
90e4755a 10652 {
c19d1205
ZW
10653 if (!inst.operands[0].writeback
10654 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10655 as_warn (_("this instruction will write back the base register"));
10656 else if (inst.operands[0].writeback
10657 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10658 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
10659 }
10660
c19d1205
ZW
10661 inst.instruction = THUMB_OP16 (inst.instruction);
10662 inst.instruction |= inst.operands[0].reg << 8;
10663 inst.instruction |= inst.operands[1].imm;
10664 }
10665}
e28cd48c 10666
c19d1205
ZW
10667static void
10668do_t_ldrex (void)
10669{
10670 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10671 || inst.operands[1].postind || inst.operands[1].writeback
10672 || inst.operands[1].immisreg || inst.operands[1].shifted
10673 || inst.operands[1].negative,
01cfc07f 10674 BAD_ADDR_MODE);
e28cd48c 10675
5be8be5d
DG
10676 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10677
c19d1205
ZW
10678 inst.instruction |= inst.operands[0].reg << 12;
10679 inst.instruction |= inst.operands[1].reg << 16;
10680 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10681}
e28cd48c 10682
c19d1205
ZW
10683static void
10684do_t_ldrexd (void)
10685{
10686 if (!inst.operands[1].present)
1cac9012 10687 {
c19d1205
ZW
10688 constraint (inst.operands[0].reg == REG_LR,
10689 _("r14 not allowed as first register "
10690 "when second register is omitted"));
10691 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 10692 }
c19d1205
ZW
10693 constraint (inst.operands[0].reg == inst.operands[1].reg,
10694 BAD_OVERLAP);
b99bd4ef 10695
c19d1205
ZW
10696 inst.instruction |= inst.operands[0].reg << 12;
10697 inst.instruction |= inst.operands[1].reg << 8;
10698 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10699}
10700
10701static void
c19d1205 10702do_t_ldst (void)
b99bd4ef 10703{
0110f2b8
PB
10704 unsigned long opcode;
10705 int Rn;
10706
e07e6e58
NC
10707 if (inst.operands[0].isreg
10708 && !inst.operands[0].preind
10709 && inst.operands[0].reg == REG_PC)
10710 set_it_insn_type_last ();
10711
0110f2b8 10712 opcode = inst.instruction;
c19d1205 10713 if (unified_syntax)
b99bd4ef 10714 {
53365c0d
PB
10715 if (!inst.operands[1].isreg)
10716 {
10717 if (opcode <= 0xffff)
10718 inst.instruction = THUMB_OP32 (opcode);
10719 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10720 return;
10721 }
0110f2b8
PB
10722 if (inst.operands[1].isreg
10723 && !inst.operands[1].writeback
c19d1205
ZW
10724 && !inst.operands[1].shifted && !inst.operands[1].postind
10725 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
10726 && opcode <= 0xffff
10727 && inst.size_req != 4)
c19d1205 10728 {
0110f2b8
PB
10729 /* Insn may have a 16-bit form. */
10730 Rn = inst.operands[1].reg;
10731 if (inst.operands[1].immisreg)
10732 {
10733 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 10734 /* [Rn, Rik] */
0110f2b8
PB
10735 if (Rn <= 7 && inst.operands[1].imm <= 7)
10736 goto op16;
5be8be5d
DG
10737 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10738 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
10739 }
10740 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10741 && opcode != T_MNEM_ldrsb)
10742 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10743 || (Rn == REG_SP && opcode == T_MNEM_str))
10744 {
10745 /* [Rn, #const] */
10746 if (Rn > 7)
10747 {
10748 if (Rn == REG_PC)
10749 {
10750 if (inst.reloc.pc_rel)
10751 opcode = T_MNEM_ldr_pc2;
10752 else
10753 opcode = T_MNEM_ldr_pc;
10754 }
10755 else
10756 {
10757 if (opcode == T_MNEM_ldr)
10758 opcode = T_MNEM_ldr_sp;
10759 else
10760 opcode = T_MNEM_str_sp;
10761 }
10762 inst.instruction = inst.operands[0].reg << 8;
10763 }
10764 else
10765 {
10766 inst.instruction = inst.operands[0].reg;
10767 inst.instruction |= inst.operands[1].reg << 3;
10768 }
10769 inst.instruction |= THUMB_OP16 (opcode);
10770 if (inst.size_req == 2)
10771 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10772 else
10773 inst.relax = opcode;
10774 return;
10775 }
c19d1205 10776 }
0110f2b8 10777 /* Definitely a 32-bit variant. */
5be8be5d 10778
8d67f500
NC
10779 /* Warning for Erratum 752419. */
10780 if (opcode == T_MNEM_ldr
10781 && inst.operands[0].reg == REG_SP
10782 && inst.operands[1].writeback == 1
10783 && !inst.operands[1].immisreg)
10784 {
10785 if (no_cpu_selected ()
10786 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
10787 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
10788 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
10789 as_warn (_("This instruction may be unpredictable "
10790 "if executed on M-profile cores "
10791 "with interrupts enabled."));
10792 }
10793
5be8be5d 10794 /* Do some validations regarding addressing modes. */
1be5fd2e 10795 if (inst.operands[1].immisreg)
5be8be5d
DG
10796 reject_bad_reg (inst.operands[1].imm);
10797
1be5fd2e
NC
10798 constraint (inst.operands[1].writeback == 1
10799 && inst.operands[0].reg == inst.operands[1].reg,
10800 BAD_OVERLAP);
10801
0110f2b8 10802 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
10803 inst.instruction |= inst.operands[0].reg << 12;
10804 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 10805 check_ldr_r15_aligned ();
b99bd4ef
NC
10806 return;
10807 }
10808
c19d1205
ZW
10809 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10810
10811 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 10812 {
c19d1205
ZW
10813 /* Only [Rn,Rm] is acceptable. */
10814 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10815 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10816 || inst.operands[1].postind || inst.operands[1].shifted
10817 || inst.operands[1].negative,
10818 _("Thumb does not support this addressing mode"));
10819 inst.instruction = THUMB_OP16 (inst.instruction);
10820 goto op16;
b99bd4ef 10821 }
5f4273c7 10822
c19d1205
ZW
10823 inst.instruction = THUMB_OP16 (inst.instruction);
10824 if (!inst.operands[1].isreg)
10825 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10826 return;
b99bd4ef 10827
c19d1205
ZW
10828 constraint (!inst.operands[1].preind
10829 || inst.operands[1].shifted
10830 || inst.operands[1].writeback,
10831 _("Thumb does not support this addressing mode"));
10832 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 10833 {
c19d1205
ZW
10834 constraint (inst.instruction & 0x0600,
10835 _("byte or halfword not valid for base register"));
10836 constraint (inst.operands[1].reg == REG_PC
10837 && !(inst.instruction & THUMB_LOAD_BIT),
10838 _("r15 based store not allowed"));
10839 constraint (inst.operands[1].immisreg,
10840 _("invalid base register for register offset"));
b99bd4ef 10841
c19d1205
ZW
10842 if (inst.operands[1].reg == REG_PC)
10843 inst.instruction = T_OPCODE_LDR_PC;
10844 else if (inst.instruction & THUMB_LOAD_BIT)
10845 inst.instruction = T_OPCODE_LDR_SP;
10846 else
10847 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 10848
c19d1205
ZW
10849 inst.instruction |= inst.operands[0].reg << 8;
10850 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10851 return;
10852 }
90e4755a 10853
c19d1205
ZW
10854 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10855 if (!inst.operands[1].immisreg)
10856 {
10857 /* Immediate offset. */
10858 inst.instruction |= inst.operands[0].reg;
10859 inst.instruction |= inst.operands[1].reg << 3;
10860 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10861 return;
10862 }
90e4755a 10863
c19d1205
ZW
10864 /* Register offset. */
10865 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10866 constraint (inst.operands[1].negative,
10867 _("Thumb does not support this addressing mode"));
90e4755a 10868
c19d1205
ZW
10869 op16:
10870 switch (inst.instruction)
10871 {
10872 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10873 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10874 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10875 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10876 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10877 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10878 case 0x5600 /* ldrsb */:
10879 case 0x5e00 /* ldrsh */: break;
10880 default: abort ();
10881 }
90e4755a 10882
c19d1205
ZW
10883 inst.instruction |= inst.operands[0].reg;
10884 inst.instruction |= inst.operands[1].reg << 3;
10885 inst.instruction |= inst.operands[1].imm << 6;
10886}
90e4755a 10887
c19d1205
ZW
10888static void
10889do_t_ldstd (void)
10890{
10891 if (!inst.operands[1].present)
b99bd4ef 10892 {
c19d1205
ZW
10893 inst.operands[1].reg = inst.operands[0].reg + 1;
10894 constraint (inst.operands[0].reg == REG_LR,
10895 _("r14 not allowed here"));
bd340a04
MGD
10896 constraint (inst.operands[0].reg == REG_R12,
10897 _("r12 not allowed here"));
b99bd4ef 10898 }
bd340a04
MGD
10899
10900 if (inst.operands[2].writeback
10901 && (inst.operands[0].reg == inst.operands[2].reg
10902 || inst.operands[1].reg == inst.operands[2].reg))
10903 as_warn (_("base register written back, and overlaps "
10904 "one of transfer registers"));
10905
c19d1205
ZW
10906 inst.instruction |= inst.operands[0].reg << 12;
10907 inst.instruction |= inst.operands[1].reg << 8;
10908 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
10909}
10910
c19d1205
ZW
10911static void
10912do_t_ldstt (void)
10913{
10914 inst.instruction |= inst.operands[0].reg << 12;
10915 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10916}
a737bd4d 10917
b99bd4ef 10918static void
c19d1205 10919do_t_mla (void)
b99bd4ef 10920{
fdfde340 10921 unsigned Rd, Rn, Rm, Ra;
c921be7d 10922
fdfde340
JM
10923 Rd = inst.operands[0].reg;
10924 Rn = inst.operands[1].reg;
10925 Rm = inst.operands[2].reg;
10926 Ra = inst.operands[3].reg;
10927
10928 reject_bad_reg (Rd);
10929 reject_bad_reg (Rn);
10930 reject_bad_reg (Rm);
10931 reject_bad_reg (Ra);
10932
10933 inst.instruction |= Rd << 8;
10934 inst.instruction |= Rn << 16;
10935 inst.instruction |= Rm;
10936 inst.instruction |= Ra << 12;
c19d1205 10937}
b99bd4ef 10938
c19d1205
ZW
10939static void
10940do_t_mlal (void)
10941{
fdfde340
JM
10942 unsigned RdLo, RdHi, Rn, Rm;
10943
10944 RdLo = inst.operands[0].reg;
10945 RdHi = inst.operands[1].reg;
10946 Rn = inst.operands[2].reg;
10947 Rm = inst.operands[3].reg;
10948
10949 reject_bad_reg (RdLo);
10950 reject_bad_reg (RdHi);
10951 reject_bad_reg (Rn);
10952 reject_bad_reg (Rm);
10953
10954 inst.instruction |= RdLo << 12;
10955 inst.instruction |= RdHi << 8;
10956 inst.instruction |= Rn << 16;
10957 inst.instruction |= Rm;
c19d1205 10958}
b99bd4ef 10959
c19d1205
ZW
10960static void
10961do_t_mov_cmp (void)
10962{
fdfde340
JM
10963 unsigned Rn, Rm;
10964
10965 Rn = inst.operands[0].reg;
10966 Rm = inst.operands[1].reg;
10967
e07e6e58
NC
10968 if (Rn == REG_PC)
10969 set_it_insn_type_last ();
10970
c19d1205 10971 if (unified_syntax)
b99bd4ef 10972 {
c19d1205
ZW
10973 int r0off = (inst.instruction == T_MNEM_mov
10974 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 10975 unsigned long opcode;
3d388997
PB
10976 bfd_boolean narrow;
10977 bfd_boolean low_regs;
10978
fdfde340 10979 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 10980 opcode = inst.instruction;
e07e6e58 10981 if (in_it_block ())
0110f2b8 10982 narrow = opcode != T_MNEM_movs;
3d388997 10983 else
0110f2b8 10984 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
10985 if (inst.size_req == 4
10986 || inst.operands[1].shifted)
10987 narrow = FALSE;
10988
efd81785
PB
10989 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10990 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10991 && !inst.operands[1].shifted
fdfde340
JM
10992 && Rn == REG_PC
10993 && Rm == REG_LR)
efd81785
PB
10994 {
10995 inst.instruction = T2_SUBS_PC_LR;
10996 return;
10997 }
10998
fdfde340
JM
10999 if (opcode == T_MNEM_cmp)
11000 {
11001 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11002 if (narrow)
11003 {
11004 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11005 but valid. */
11006 warn_deprecated_sp (Rm);
11007 /* R15 was documented as a valid choice for Rm in ARMv6,
11008 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11009 tools reject R15, so we do too. */
11010 constraint (Rm == REG_PC, BAD_PC);
11011 }
11012 else
11013 reject_bad_reg (Rm);
fdfde340
JM
11014 }
11015 else if (opcode == T_MNEM_mov
11016 || opcode == T_MNEM_movs)
11017 {
11018 if (inst.operands[1].isreg)
11019 {
11020 if (opcode == T_MNEM_movs)
11021 {
11022 reject_bad_reg (Rn);
11023 reject_bad_reg (Rm);
11024 }
76fa04a4
MGD
11025 else if (narrow)
11026 {
11027 /* This is mov.n. */
11028 if ((Rn == REG_SP || Rn == REG_PC)
11029 && (Rm == REG_SP || Rm == REG_PC))
11030 {
11031 as_warn (_("Use of r%u as a source register is "
11032 "deprecated when r%u is the destination "
11033 "register."), Rm, Rn);
11034 }
11035 }
11036 else
11037 {
11038 /* This is mov.w. */
11039 constraint (Rn == REG_PC, BAD_PC);
11040 constraint (Rm == REG_PC, BAD_PC);
11041 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11042 }
fdfde340
JM
11043 }
11044 else
11045 reject_bad_reg (Rn);
11046 }
11047
c19d1205
ZW
11048 if (!inst.operands[1].isreg)
11049 {
0110f2b8 11050 /* Immediate operand. */
e07e6e58 11051 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11052 narrow = 0;
11053 if (low_regs && narrow)
11054 {
11055 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11056 inst.instruction |= Rn << 8;
0110f2b8
PB
11057 if (inst.size_req == 2)
11058 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11059 else
11060 inst.relax = opcode;
11061 }
11062 else
11063 {
11064 inst.instruction = THUMB_OP32 (inst.instruction);
11065 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11066 inst.instruction |= Rn << r0off;
0110f2b8
PB
11067 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11068 }
c19d1205 11069 }
728ca7c9
PB
11070 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11071 && (inst.instruction == T_MNEM_mov
11072 || inst.instruction == T_MNEM_movs))
11073 {
11074 /* Register shifts are encoded as separate shift instructions. */
11075 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11076
e07e6e58 11077 if (in_it_block ())
728ca7c9
PB
11078 narrow = !flags;
11079 else
11080 narrow = flags;
11081
11082 if (inst.size_req == 4)
11083 narrow = FALSE;
11084
11085 if (!low_regs || inst.operands[1].imm > 7)
11086 narrow = FALSE;
11087
fdfde340 11088 if (Rn != Rm)
728ca7c9
PB
11089 narrow = FALSE;
11090
11091 switch (inst.operands[1].shift_kind)
11092 {
11093 case SHIFT_LSL:
11094 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11095 break;
11096 case SHIFT_ASR:
11097 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11098 break;
11099 case SHIFT_LSR:
11100 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11101 break;
11102 case SHIFT_ROR:
11103 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11104 break;
11105 default:
5f4273c7 11106 abort ();
728ca7c9
PB
11107 }
11108
11109 inst.instruction = opcode;
11110 if (narrow)
11111 {
fdfde340 11112 inst.instruction |= Rn;
728ca7c9
PB
11113 inst.instruction |= inst.operands[1].imm << 3;
11114 }
11115 else
11116 {
11117 if (flags)
11118 inst.instruction |= CONDS_BIT;
11119
fdfde340
JM
11120 inst.instruction |= Rn << 8;
11121 inst.instruction |= Rm << 16;
728ca7c9
PB
11122 inst.instruction |= inst.operands[1].imm;
11123 }
11124 }
3d388997 11125 else if (!narrow)
c19d1205 11126 {
728ca7c9
PB
11127 /* Some mov with immediate shift have narrow variants.
11128 Register shifts are handled above. */
11129 if (low_regs && inst.operands[1].shifted
11130 && (inst.instruction == T_MNEM_mov
11131 || inst.instruction == T_MNEM_movs))
11132 {
e07e6e58 11133 if (in_it_block ())
728ca7c9
PB
11134 narrow = (inst.instruction == T_MNEM_mov);
11135 else
11136 narrow = (inst.instruction == T_MNEM_movs);
11137 }
11138
11139 if (narrow)
11140 {
11141 switch (inst.operands[1].shift_kind)
11142 {
11143 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11144 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11145 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11146 default: narrow = FALSE; break;
11147 }
11148 }
11149
11150 if (narrow)
11151 {
fdfde340
JM
11152 inst.instruction |= Rn;
11153 inst.instruction |= Rm << 3;
728ca7c9
PB
11154 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11155 }
11156 else
11157 {
11158 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11159 inst.instruction |= Rn << r0off;
728ca7c9
PB
11160 encode_thumb32_shifted_operand (1);
11161 }
c19d1205
ZW
11162 }
11163 else
11164 switch (inst.instruction)
11165 {
11166 case T_MNEM_mov:
837b3435 11167 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
11168 results. Don't allow this. */
11169 if (low_regs)
11170 {
11171 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11172 "MOV Rd, Rs with two low registers is not "
11173 "permitted on this architecture");
fa94de6b 11174 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
11175 arm_ext_v6);
11176 }
11177
c19d1205 11178 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
11179 inst.instruction |= (Rn & 0x8) << 4;
11180 inst.instruction |= (Rn & 0x7);
11181 inst.instruction |= Rm << 3;
c19d1205 11182 break;
b99bd4ef 11183
c19d1205
ZW
11184 case T_MNEM_movs:
11185 /* We know we have low registers at this point.
941a8a52
MGD
11186 Generate LSLS Rd, Rs, #0. */
11187 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
11188 inst.instruction |= Rn;
11189 inst.instruction |= Rm << 3;
c19d1205
ZW
11190 break;
11191
11192 case T_MNEM_cmp:
3d388997 11193 if (low_regs)
c19d1205
ZW
11194 {
11195 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
11196 inst.instruction |= Rn;
11197 inst.instruction |= Rm << 3;
c19d1205
ZW
11198 }
11199 else
11200 {
11201 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
11202 inst.instruction |= (Rn & 0x8) << 4;
11203 inst.instruction |= (Rn & 0x7);
11204 inst.instruction |= Rm << 3;
c19d1205
ZW
11205 }
11206 break;
11207 }
b99bd4ef
NC
11208 return;
11209 }
11210
c19d1205 11211 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
11212
11213 /* PR 10443: Do not silently ignore shifted operands. */
11214 constraint (inst.operands[1].shifted,
11215 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
11216
c19d1205 11217 if (inst.operands[1].isreg)
b99bd4ef 11218 {
fdfde340 11219 if (Rn < 8 && Rm < 8)
b99bd4ef 11220 {
c19d1205
ZW
11221 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11222 since a MOV instruction produces unpredictable results. */
11223 if (inst.instruction == T_OPCODE_MOV_I8)
11224 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 11225 else
c19d1205 11226 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 11227
fdfde340
JM
11228 inst.instruction |= Rn;
11229 inst.instruction |= Rm << 3;
b99bd4ef
NC
11230 }
11231 else
11232 {
c19d1205
ZW
11233 if (inst.instruction == T_OPCODE_MOV_I8)
11234 inst.instruction = T_OPCODE_MOV_HR;
11235 else
11236 inst.instruction = T_OPCODE_CMP_HR;
11237 do_t_cpy ();
b99bd4ef
NC
11238 }
11239 }
c19d1205 11240 else
b99bd4ef 11241 {
fdfde340 11242 constraint (Rn > 7,
c19d1205 11243 _("only lo regs allowed with immediate"));
fdfde340 11244 inst.instruction |= Rn << 8;
c19d1205
ZW
11245 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11246 }
11247}
b99bd4ef 11248
c19d1205
ZW
11249static void
11250do_t_mov16 (void)
11251{
fdfde340 11252 unsigned Rd;
b6895b4f
PB
11253 bfd_vma imm;
11254 bfd_boolean top;
11255
11256 top = (inst.instruction & 0x00800000) != 0;
11257 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
11258 {
11259 constraint (top, _(":lower16: not allowed this instruction"));
11260 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
11261 }
11262 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
11263 {
11264 constraint (!top, _(":upper16: not allowed this instruction"));
11265 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
11266 }
11267
fdfde340
JM
11268 Rd = inst.operands[0].reg;
11269 reject_bad_reg (Rd);
11270
11271 inst.instruction |= Rd << 8;
b6895b4f
PB
11272 if (inst.reloc.type == BFD_RELOC_UNUSED)
11273 {
11274 imm = inst.reloc.exp.X_add_number;
11275 inst.instruction |= (imm & 0xf000) << 4;
11276 inst.instruction |= (imm & 0x0800) << 15;
11277 inst.instruction |= (imm & 0x0700) << 4;
11278 inst.instruction |= (imm & 0x00ff);
11279 }
c19d1205 11280}
b99bd4ef 11281
c19d1205
ZW
11282static void
11283do_t_mvn_tst (void)
11284{
fdfde340 11285 unsigned Rn, Rm;
c921be7d 11286
fdfde340
JM
11287 Rn = inst.operands[0].reg;
11288 Rm = inst.operands[1].reg;
11289
11290 if (inst.instruction == T_MNEM_cmp
11291 || inst.instruction == T_MNEM_cmn)
11292 constraint (Rn == REG_PC, BAD_PC);
11293 else
11294 reject_bad_reg (Rn);
11295 reject_bad_reg (Rm);
11296
c19d1205
ZW
11297 if (unified_syntax)
11298 {
11299 int r0off = (inst.instruction == T_MNEM_mvn
11300 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
11301 bfd_boolean narrow;
11302
11303 if (inst.size_req == 4
11304 || inst.instruction > 0xffff
11305 || inst.operands[1].shifted
fdfde340 11306 || Rn > 7 || Rm > 7)
3d388997
PB
11307 narrow = FALSE;
11308 else if (inst.instruction == T_MNEM_cmn)
11309 narrow = TRUE;
11310 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11311 narrow = !in_it_block ();
3d388997 11312 else
e07e6e58 11313 narrow = in_it_block ();
3d388997 11314
c19d1205 11315 if (!inst.operands[1].isreg)
b99bd4ef 11316 {
c19d1205
ZW
11317 /* For an immediate, we always generate a 32-bit opcode;
11318 section relaxation will shrink it later if possible. */
11319 if (inst.instruction < 0xffff)
11320 inst.instruction = THUMB_OP32 (inst.instruction);
11321 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11322 inst.instruction |= Rn << r0off;
c19d1205 11323 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11324 }
c19d1205 11325 else
b99bd4ef 11326 {
c19d1205 11327 /* See if we can do this with a 16-bit instruction. */
3d388997 11328 if (narrow)
b99bd4ef 11329 {
c19d1205 11330 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11331 inst.instruction |= Rn;
11332 inst.instruction |= Rm << 3;
b99bd4ef 11333 }
c19d1205 11334 else
b99bd4ef 11335 {
c19d1205
ZW
11336 constraint (inst.operands[1].shifted
11337 && inst.operands[1].immisreg,
11338 _("shift must be constant"));
11339 if (inst.instruction < 0xffff)
11340 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11341 inst.instruction |= Rn << r0off;
c19d1205 11342 encode_thumb32_shifted_operand (1);
b99bd4ef 11343 }
b99bd4ef
NC
11344 }
11345 }
11346 else
11347 {
c19d1205
ZW
11348 constraint (inst.instruction > 0xffff
11349 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
11350 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
11351 _("unshifted register required"));
fdfde340 11352 constraint (Rn > 7 || Rm > 7,
c19d1205 11353 BAD_HIREG);
b99bd4ef 11354
c19d1205 11355 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11356 inst.instruction |= Rn;
11357 inst.instruction |= Rm << 3;
b99bd4ef 11358 }
b99bd4ef
NC
11359}
11360
b05fe5cf 11361static void
c19d1205 11362do_t_mrs (void)
b05fe5cf 11363{
fdfde340 11364 unsigned Rd;
037e8744
JB
11365
11366 if (do_vfp_nsyn_mrs () == SUCCESS)
11367 return;
11368
90ec0d68
MGD
11369 Rd = inst.operands[0].reg;
11370 reject_bad_reg (Rd);
11371 inst.instruction |= Rd << 8;
11372
11373 if (inst.operands[1].isreg)
62b3e311 11374 {
90ec0d68
MGD
11375 unsigned br = inst.operands[1].reg;
11376 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
11377 as_bad (_("bad register for mrs"));
11378
11379 inst.instruction |= br & (0xf << 16);
11380 inst.instruction |= (br & 0x300) >> 4;
11381 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
11382 }
11383 else
11384 {
90ec0d68 11385 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 11386
d2cd1205 11387 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
11388 {
11389 /* PR gas/12698: The constraint is only applied for m_profile.
11390 If the user has specified -march=all, we want to ignore it as
11391 we are building for any CPU type, including non-m variants. */
11392 bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core;
11393 constraint ((flags != 0) && m_profile, _("selected processor does "
11394 "not support requested special purpose register"));
11395 }
90ec0d68 11396 else
d2cd1205
JB
11397 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
11398 devices). */
11399 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
11400 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 11401
90ec0d68
MGD
11402 inst.instruction |= (flags & SPSR_BIT) >> 2;
11403 inst.instruction |= inst.operands[1].imm & 0xff;
11404 inst.instruction |= 0xf0000;
11405 }
c19d1205 11406}
b05fe5cf 11407
c19d1205
ZW
11408static void
11409do_t_msr (void)
11410{
62b3e311 11411 int flags;
fdfde340 11412 unsigned Rn;
62b3e311 11413
037e8744
JB
11414 if (do_vfp_nsyn_msr () == SUCCESS)
11415 return;
11416
c19d1205
ZW
11417 constraint (!inst.operands[1].isreg,
11418 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
11419
11420 if (inst.operands[0].isreg)
11421 flags = (int)(inst.operands[0].reg);
11422 else
11423 flags = inst.operands[0].imm;
11424
d2cd1205 11425 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 11426 {
d2cd1205
JB
11427 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11428
1a43faaf
NC
11429 /* PR gas/12698: The constraint is only applied for m_profile.
11430 If the user has specified -march=all, we want to ignore it as
11431 we are building for any CPU type, including non-m variants. */
11432 bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core;
11433 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11434 && (bits & ~(PSR_s | PSR_f)) != 0)
11435 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11436 && bits != PSR_f)) && m_profile,
11437 _("selected processor does not support requested special "
11438 "purpose register"));
62b3e311
PB
11439 }
11440 else
d2cd1205
JB
11441 constraint ((flags & 0xff) != 0, _("selected processor does not support "
11442 "requested special purpose register"));
c921be7d 11443
fdfde340
JM
11444 Rn = inst.operands[1].reg;
11445 reject_bad_reg (Rn);
11446
62b3e311 11447 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
11448 inst.instruction |= (flags & 0xf0000) >> 8;
11449 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 11450 inst.instruction |= (flags & 0xff);
fdfde340 11451 inst.instruction |= Rn << 16;
c19d1205 11452}
b05fe5cf 11453
c19d1205
ZW
11454static void
11455do_t_mul (void)
11456{
17828f45 11457 bfd_boolean narrow;
fdfde340 11458 unsigned Rd, Rn, Rm;
17828f45 11459
c19d1205
ZW
11460 if (!inst.operands[2].present)
11461 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 11462
fdfde340
JM
11463 Rd = inst.operands[0].reg;
11464 Rn = inst.operands[1].reg;
11465 Rm = inst.operands[2].reg;
11466
17828f45 11467 if (unified_syntax)
b05fe5cf 11468 {
17828f45 11469 if (inst.size_req == 4
fdfde340
JM
11470 || (Rd != Rn
11471 && Rd != Rm)
11472 || Rn > 7
11473 || Rm > 7)
17828f45
JM
11474 narrow = FALSE;
11475 else if (inst.instruction == T_MNEM_muls)
e07e6e58 11476 narrow = !in_it_block ();
17828f45 11477 else
e07e6e58 11478 narrow = in_it_block ();
b05fe5cf 11479 }
c19d1205 11480 else
b05fe5cf 11481 {
17828f45 11482 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 11483 constraint (Rn > 7 || Rm > 7,
c19d1205 11484 BAD_HIREG);
17828f45
JM
11485 narrow = TRUE;
11486 }
b05fe5cf 11487
17828f45
JM
11488 if (narrow)
11489 {
11490 /* 16-bit MULS/Conditional MUL. */
c19d1205 11491 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11492 inst.instruction |= Rd;
b05fe5cf 11493
fdfde340
JM
11494 if (Rd == Rn)
11495 inst.instruction |= Rm << 3;
11496 else if (Rd == Rm)
11497 inst.instruction |= Rn << 3;
c19d1205
ZW
11498 else
11499 constraint (1, _("dest must overlap one source register"));
11500 }
17828f45
JM
11501 else
11502 {
e07e6e58
NC
11503 constraint (inst.instruction != T_MNEM_mul,
11504 _("Thumb-2 MUL must not set flags"));
17828f45
JM
11505 /* 32-bit MUL. */
11506 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11507 inst.instruction |= Rd << 8;
11508 inst.instruction |= Rn << 16;
11509 inst.instruction |= Rm << 0;
11510
11511 reject_bad_reg (Rd);
11512 reject_bad_reg (Rn);
11513 reject_bad_reg (Rm);
17828f45 11514 }
c19d1205 11515}
b05fe5cf 11516
c19d1205
ZW
11517static void
11518do_t_mull (void)
11519{
fdfde340 11520 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 11521
fdfde340
JM
11522 RdLo = inst.operands[0].reg;
11523 RdHi = inst.operands[1].reg;
11524 Rn = inst.operands[2].reg;
11525 Rm = inst.operands[3].reg;
11526
11527 reject_bad_reg (RdLo);
11528 reject_bad_reg (RdHi);
11529 reject_bad_reg (Rn);
11530 reject_bad_reg (Rm);
11531
11532 inst.instruction |= RdLo << 12;
11533 inst.instruction |= RdHi << 8;
11534 inst.instruction |= Rn << 16;
11535 inst.instruction |= Rm;
11536
11537 if (RdLo == RdHi)
c19d1205
ZW
11538 as_tsktsk (_("rdhi and rdlo must be different"));
11539}
b05fe5cf 11540
c19d1205
ZW
11541static void
11542do_t_nop (void)
11543{
e07e6e58
NC
11544 set_it_insn_type (NEUTRAL_IT_INSN);
11545
c19d1205
ZW
11546 if (unified_syntax)
11547 {
11548 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 11549 {
c19d1205
ZW
11550 inst.instruction = THUMB_OP32 (inst.instruction);
11551 inst.instruction |= inst.operands[0].imm;
11552 }
11553 else
11554 {
bc2d1808
NC
11555 /* PR9722: Check for Thumb2 availability before
11556 generating a thumb2 nop instruction. */
afa62d5e 11557 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
11558 {
11559 inst.instruction = THUMB_OP16 (inst.instruction);
11560 inst.instruction |= inst.operands[0].imm << 4;
11561 }
11562 else
11563 inst.instruction = 0x46c0;
c19d1205
ZW
11564 }
11565 }
11566 else
11567 {
11568 constraint (inst.operands[0].present,
11569 _("Thumb does not support NOP with hints"));
11570 inst.instruction = 0x46c0;
11571 }
11572}
b05fe5cf 11573
c19d1205
ZW
11574static void
11575do_t_neg (void)
11576{
11577 if (unified_syntax)
11578 {
3d388997
PB
11579 bfd_boolean narrow;
11580
11581 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11582 narrow = !in_it_block ();
3d388997 11583 else
e07e6e58 11584 narrow = in_it_block ();
3d388997
PB
11585 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11586 narrow = FALSE;
11587 if (inst.size_req == 4)
11588 narrow = FALSE;
11589
11590 if (!narrow)
c19d1205
ZW
11591 {
11592 inst.instruction = THUMB_OP32 (inst.instruction);
11593 inst.instruction |= inst.operands[0].reg << 8;
11594 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
11595 }
11596 else
11597 {
c19d1205
ZW
11598 inst.instruction = THUMB_OP16 (inst.instruction);
11599 inst.instruction |= inst.operands[0].reg;
11600 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
11601 }
11602 }
11603 else
11604 {
c19d1205
ZW
11605 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
11606 BAD_HIREG);
11607 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11608
11609 inst.instruction = THUMB_OP16 (inst.instruction);
11610 inst.instruction |= inst.operands[0].reg;
11611 inst.instruction |= inst.operands[1].reg << 3;
11612 }
11613}
11614
1c444d06
JM
11615static void
11616do_t_orn (void)
11617{
11618 unsigned Rd, Rn;
11619
11620 Rd = inst.operands[0].reg;
11621 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
11622
fdfde340
JM
11623 reject_bad_reg (Rd);
11624 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
11625 reject_bad_reg (Rn);
11626
1c444d06
JM
11627 inst.instruction |= Rd << 8;
11628 inst.instruction |= Rn << 16;
11629
11630 if (!inst.operands[2].isreg)
11631 {
11632 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11633 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11634 }
11635 else
11636 {
11637 unsigned Rm;
11638
11639 Rm = inst.operands[2].reg;
fdfde340 11640 reject_bad_reg (Rm);
1c444d06
JM
11641
11642 constraint (inst.operands[2].shifted
11643 && inst.operands[2].immisreg,
11644 _("shift must be constant"));
11645 encode_thumb32_shifted_operand (2);
11646 }
11647}
11648
c19d1205
ZW
11649static void
11650do_t_pkhbt (void)
11651{
fdfde340
JM
11652 unsigned Rd, Rn, Rm;
11653
11654 Rd = inst.operands[0].reg;
11655 Rn = inst.operands[1].reg;
11656 Rm = inst.operands[2].reg;
11657
11658 reject_bad_reg (Rd);
11659 reject_bad_reg (Rn);
11660 reject_bad_reg (Rm);
11661
11662 inst.instruction |= Rd << 8;
11663 inst.instruction |= Rn << 16;
11664 inst.instruction |= Rm;
c19d1205
ZW
11665 if (inst.operands[3].present)
11666 {
11667 unsigned int val = inst.reloc.exp.X_add_number;
11668 constraint (inst.reloc.exp.X_op != O_constant,
11669 _("expression too complex"));
11670 inst.instruction |= (val & 0x1c) << 10;
11671 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 11672 }
c19d1205 11673}
b05fe5cf 11674
c19d1205
ZW
11675static void
11676do_t_pkhtb (void)
11677{
11678 if (!inst.operands[3].present)
1ef52f49
NC
11679 {
11680 unsigned Rtmp;
11681
11682 inst.instruction &= ~0x00000020;
11683
11684 /* PR 10168. Swap the Rm and Rn registers. */
11685 Rtmp = inst.operands[1].reg;
11686 inst.operands[1].reg = inst.operands[2].reg;
11687 inst.operands[2].reg = Rtmp;
11688 }
c19d1205 11689 do_t_pkhbt ();
b05fe5cf
ZW
11690}
11691
c19d1205
ZW
11692static void
11693do_t_pld (void)
11694{
fdfde340
JM
11695 if (inst.operands[0].immisreg)
11696 reject_bad_reg (inst.operands[0].imm);
11697
c19d1205
ZW
11698 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11699}
b05fe5cf 11700
c19d1205
ZW
11701static void
11702do_t_push_pop (void)
b99bd4ef 11703{
e9f89963 11704 unsigned mask;
5f4273c7 11705
c19d1205
ZW
11706 constraint (inst.operands[0].writeback,
11707 _("push/pop do not support {reglist}^"));
11708 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11709 _("expression too complex"));
b99bd4ef 11710
e9f89963
PB
11711 mask = inst.operands[0].imm;
11712 if ((mask & ~0xff) == 0)
3c707909 11713 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 11714 else if ((inst.instruction == T_MNEM_push
e9f89963 11715 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 11716 || (inst.instruction == T_MNEM_pop
e9f89963 11717 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 11718 {
c19d1205
ZW
11719 inst.instruction = THUMB_OP16 (inst.instruction);
11720 inst.instruction |= THUMB_PP_PC_LR;
3c707909 11721 inst.instruction |= mask & 0xff;
c19d1205
ZW
11722 }
11723 else if (unified_syntax)
11724 {
3c707909 11725 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 11726 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
11727 }
11728 else
11729 {
11730 inst.error = _("invalid register list to push/pop instruction");
11731 return;
11732 }
c19d1205 11733}
b99bd4ef 11734
c19d1205
ZW
11735static void
11736do_t_rbit (void)
11737{
fdfde340
JM
11738 unsigned Rd, Rm;
11739
11740 Rd = inst.operands[0].reg;
11741 Rm = inst.operands[1].reg;
11742
11743 reject_bad_reg (Rd);
11744 reject_bad_reg (Rm);
11745
11746 inst.instruction |= Rd << 8;
11747 inst.instruction |= Rm << 16;
11748 inst.instruction |= Rm;
c19d1205 11749}
b99bd4ef 11750
c19d1205
ZW
11751static void
11752do_t_rev (void)
11753{
fdfde340
JM
11754 unsigned Rd, Rm;
11755
11756 Rd = inst.operands[0].reg;
11757 Rm = inst.operands[1].reg;
11758
11759 reject_bad_reg (Rd);
11760 reject_bad_reg (Rm);
11761
11762 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
11763 && inst.size_req != 4)
11764 {
11765 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11766 inst.instruction |= Rd;
11767 inst.instruction |= Rm << 3;
c19d1205
ZW
11768 }
11769 else if (unified_syntax)
11770 {
11771 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11772 inst.instruction |= Rd << 8;
11773 inst.instruction |= Rm << 16;
11774 inst.instruction |= Rm;
c19d1205
ZW
11775 }
11776 else
11777 inst.error = BAD_HIREG;
11778}
b99bd4ef 11779
1c444d06
JM
11780static void
11781do_t_rrx (void)
11782{
11783 unsigned Rd, Rm;
11784
11785 Rd = inst.operands[0].reg;
11786 Rm = inst.operands[1].reg;
11787
fdfde340
JM
11788 reject_bad_reg (Rd);
11789 reject_bad_reg (Rm);
c921be7d 11790
1c444d06
JM
11791 inst.instruction |= Rd << 8;
11792 inst.instruction |= Rm;
11793}
11794
c19d1205
ZW
11795static void
11796do_t_rsb (void)
11797{
fdfde340 11798 unsigned Rd, Rs;
b99bd4ef 11799
c19d1205
ZW
11800 Rd = inst.operands[0].reg;
11801 Rs = (inst.operands[1].present
11802 ? inst.operands[1].reg /* Rd, Rs, foo */
11803 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 11804
fdfde340
JM
11805 reject_bad_reg (Rd);
11806 reject_bad_reg (Rs);
11807 if (inst.operands[2].isreg)
11808 reject_bad_reg (inst.operands[2].reg);
11809
c19d1205
ZW
11810 inst.instruction |= Rd << 8;
11811 inst.instruction |= Rs << 16;
11812 if (!inst.operands[2].isreg)
11813 {
026d3abb
PB
11814 bfd_boolean narrow;
11815
11816 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 11817 narrow = !in_it_block ();
026d3abb 11818 else
e07e6e58 11819 narrow = in_it_block ();
026d3abb
PB
11820
11821 if (Rd > 7 || Rs > 7)
11822 narrow = FALSE;
11823
11824 if (inst.size_req == 4 || !unified_syntax)
11825 narrow = FALSE;
11826
11827 if (inst.reloc.exp.X_op != O_constant
11828 || inst.reloc.exp.X_add_number != 0)
11829 narrow = FALSE;
11830
11831 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11832 relaxation, but it doesn't seem worth the hassle. */
11833 if (narrow)
11834 {
11835 inst.reloc.type = BFD_RELOC_UNUSED;
11836 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11837 inst.instruction |= Rs << 3;
11838 inst.instruction |= Rd;
11839 }
11840 else
11841 {
11842 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11843 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11844 }
c19d1205
ZW
11845 }
11846 else
11847 encode_thumb32_shifted_operand (2);
11848}
b99bd4ef 11849
c19d1205
ZW
11850static void
11851do_t_setend (void)
11852{
12e37cbc
MGD
11853 if (warn_on_deprecated
11854 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11855 as_warn (_("setend use is deprecated for ARMv8"));
11856
e07e6e58 11857 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11858 if (inst.operands[0].imm)
11859 inst.instruction |= 0x8;
11860}
b99bd4ef 11861
c19d1205
ZW
11862static void
11863do_t_shift (void)
11864{
11865 if (!inst.operands[1].present)
11866 inst.operands[1].reg = inst.operands[0].reg;
11867
11868 if (unified_syntax)
11869 {
3d388997
PB
11870 bfd_boolean narrow;
11871 int shift_kind;
11872
11873 switch (inst.instruction)
11874 {
11875 case T_MNEM_asr:
11876 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11877 case T_MNEM_lsl:
11878 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11879 case T_MNEM_lsr:
11880 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11881 case T_MNEM_ror:
11882 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11883 default: abort ();
11884 }
11885
11886 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11887 narrow = !in_it_block ();
3d388997 11888 else
e07e6e58 11889 narrow = in_it_block ();
3d388997
PB
11890 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11891 narrow = FALSE;
11892 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11893 narrow = FALSE;
11894 if (inst.operands[2].isreg
11895 && (inst.operands[1].reg != inst.operands[0].reg
11896 || inst.operands[2].reg > 7))
11897 narrow = FALSE;
11898 if (inst.size_req == 4)
11899 narrow = FALSE;
11900
fdfde340
JM
11901 reject_bad_reg (inst.operands[0].reg);
11902 reject_bad_reg (inst.operands[1].reg);
c921be7d 11903
3d388997 11904 if (!narrow)
c19d1205
ZW
11905 {
11906 if (inst.operands[2].isreg)
b99bd4ef 11907 {
fdfde340 11908 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
11909 inst.instruction = THUMB_OP32 (inst.instruction);
11910 inst.instruction |= inst.operands[0].reg << 8;
11911 inst.instruction |= inst.operands[1].reg << 16;
11912 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
11913
11914 /* PR 12854: Error on extraneous shifts. */
11915 constraint (inst.operands[2].shifted,
11916 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
11917 }
11918 else
11919 {
11920 inst.operands[1].shifted = 1;
3d388997 11921 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
11922 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11923 ? T_MNEM_movs : T_MNEM_mov);
11924 inst.instruction |= inst.operands[0].reg << 8;
11925 encode_thumb32_shifted_operand (1);
11926 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11927 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
11928 }
11929 }
11930 else
11931 {
c19d1205 11932 if (inst.operands[2].isreg)
b99bd4ef 11933 {
3d388997 11934 switch (shift_kind)
b99bd4ef 11935 {
3d388997
PB
11936 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11937 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11938 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11939 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 11940 default: abort ();
b99bd4ef 11941 }
5f4273c7 11942
c19d1205
ZW
11943 inst.instruction |= inst.operands[0].reg;
11944 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
11945
11946 /* PR 12854: Error on extraneous shifts. */
11947 constraint (inst.operands[2].shifted,
11948 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
11949 }
11950 else
11951 {
3d388997 11952 switch (shift_kind)
b99bd4ef 11953 {
3d388997
PB
11954 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11955 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11956 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 11957 default: abort ();
b99bd4ef 11958 }
c19d1205
ZW
11959 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11960 inst.instruction |= inst.operands[0].reg;
11961 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11962 }
11963 }
c19d1205
ZW
11964 }
11965 else
11966 {
11967 constraint (inst.operands[0].reg > 7
11968 || inst.operands[1].reg > 7, BAD_HIREG);
11969 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 11970
c19d1205
ZW
11971 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11972 {
11973 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11974 constraint (inst.operands[0].reg != inst.operands[1].reg,
11975 _("source1 and dest must be same register"));
b99bd4ef 11976
c19d1205
ZW
11977 switch (inst.instruction)
11978 {
11979 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11980 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11981 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11982 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11983 default: abort ();
11984 }
5f4273c7 11985
c19d1205
ZW
11986 inst.instruction |= inst.operands[0].reg;
11987 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
11988
11989 /* PR 12854: Error on extraneous shifts. */
11990 constraint (inst.operands[2].shifted,
11991 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
11992 }
11993 else
b99bd4ef 11994 {
c19d1205
ZW
11995 switch (inst.instruction)
11996 {
11997 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11998 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11999 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12000 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12001 default: abort ();
12002 }
12003 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12004 inst.instruction |= inst.operands[0].reg;
12005 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12006 }
12007 }
b99bd4ef
NC
12008}
12009
12010static void
c19d1205 12011do_t_simd (void)
b99bd4ef 12012{
fdfde340
JM
12013 unsigned Rd, Rn, Rm;
12014
12015 Rd = inst.operands[0].reg;
12016 Rn = inst.operands[1].reg;
12017 Rm = inst.operands[2].reg;
12018
12019 reject_bad_reg (Rd);
12020 reject_bad_reg (Rn);
12021 reject_bad_reg (Rm);
12022
12023 inst.instruction |= Rd << 8;
12024 inst.instruction |= Rn << 16;
12025 inst.instruction |= Rm;
c19d1205 12026}
b99bd4ef 12027
03ee1b7f
NC
12028static void
12029do_t_simd2 (void)
12030{
12031 unsigned Rd, Rn, Rm;
12032
12033 Rd = inst.operands[0].reg;
12034 Rm = inst.operands[1].reg;
12035 Rn = inst.operands[2].reg;
12036
12037 reject_bad_reg (Rd);
12038 reject_bad_reg (Rn);
12039 reject_bad_reg (Rm);
12040
12041 inst.instruction |= Rd << 8;
12042 inst.instruction |= Rn << 16;
12043 inst.instruction |= Rm;
12044}
12045
c19d1205 12046static void
3eb17e6b 12047do_t_smc (void)
c19d1205
ZW
12048{
12049 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12050 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12051 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12052 constraint (inst.reloc.exp.X_op != O_constant,
12053 _("expression too complex"));
12054 inst.reloc.type = BFD_RELOC_UNUSED;
12055 inst.instruction |= (value & 0xf000) >> 12;
12056 inst.instruction |= (value & 0x0ff0);
12057 inst.instruction |= (value & 0x000f) << 16;
12058}
b99bd4ef 12059
90ec0d68
MGD
12060static void
12061do_t_hvc (void)
12062{
12063 unsigned int value = inst.reloc.exp.X_add_number;
12064
12065 inst.reloc.type = BFD_RELOC_UNUSED;
12066 inst.instruction |= (value & 0x0fff);
12067 inst.instruction |= (value & 0xf000) << 4;
12068}
12069
c19d1205 12070static void
3a21c15a 12071do_t_ssat_usat (int bias)
c19d1205 12072{
fdfde340
JM
12073 unsigned Rd, Rn;
12074
12075 Rd = inst.operands[0].reg;
12076 Rn = inst.operands[2].reg;
12077
12078 reject_bad_reg (Rd);
12079 reject_bad_reg (Rn);
12080
12081 inst.instruction |= Rd << 8;
3a21c15a 12082 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12083 inst.instruction |= Rn << 16;
b99bd4ef 12084
c19d1205 12085 if (inst.operands[3].present)
b99bd4ef 12086 {
3a21c15a
NC
12087 offsetT shift_amount = inst.reloc.exp.X_add_number;
12088
12089 inst.reloc.type = BFD_RELOC_UNUSED;
12090
c19d1205
ZW
12091 constraint (inst.reloc.exp.X_op != O_constant,
12092 _("expression too complex"));
b99bd4ef 12093
3a21c15a 12094 if (shift_amount != 0)
6189168b 12095 {
3a21c15a
NC
12096 constraint (shift_amount > 31,
12097 _("shift expression is too large"));
12098
c19d1205 12099 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12100 inst.instruction |= 0x00200000; /* sh bit. */
12101
12102 inst.instruction |= (shift_amount & 0x1c) << 10;
12103 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
12104 }
12105 }
b99bd4ef 12106}
c921be7d 12107
3a21c15a
NC
12108static void
12109do_t_ssat (void)
12110{
12111 do_t_ssat_usat (1);
12112}
b99bd4ef 12113
0dd132b6 12114static void
c19d1205 12115do_t_ssat16 (void)
0dd132b6 12116{
fdfde340
JM
12117 unsigned Rd, Rn;
12118
12119 Rd = inst.operands[0].reg;
12120 Rn = inst.operands[2].reg;
12121
12122 reject_bad_reg (Rd);
12123 reject_bad_reg (Rn);
12124
12125 inst.instruction |= Rd << 8;
c19d1205 12126 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 12127 inst.instruction |= Rn << 16;
c19d1205 12128}
0dd132b6 12129
c19d1205
ZW
12130static void
12131do_t_strex (void)
12132{
12133 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12134 || inst.operands[2].postind || inst.operands[2].writeback
12135 || inst.operands[2].immisreg || inst.operands[2].shifted
12136 || inst.operands[2].negative,
01cfc07f 12137 BAD_ADDR_MODE);
0dd132b6 12138
5be8be5d
DG
12139 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12140
c19d1205
ZW
12141 inst.instruction |= inst.operands[0].reg << 8;
12142 inst.instruction |= inst.operands[1].reg << 12;
12143 inst.instruction |= inst.operands[2].reg << 16;
12144 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
12145}
12146
b99bd4ef 12147static void
c19d1205 12148do_t_strexd (void)
b99bd4ef 12149{
c19d1205
ZW
12150 if (!inst.operands[2].present)
12151 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 12152
c19d1205
ZW
12153 constraint (inst.operands[0].reg == inst.operands[1].reg
12154 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 12155 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 12156 BAD_OVERLAP);
b99bd4ef 12157
c19d1205
ZW
12158 inst.instruction |= inst.operands[0].reg;
12159 inst.instruction |= inst.operands[1].reg << 12;
12160 inst.instruction |= inst.operands[2].reg << 8;
12161 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
12162}
12163
12164static void
c19d1205 12165do_t_sxtah (void)
b99bd4ef 12166{
fdfde340
JM
12167 unsigned Rd, Rn, Rm;
12168
12169 Rd = inst.operands[0].reg;
12170 Rn = inst.operands[1].reg;
12171 Rm = inst.operands[2].reg;
12172
12173 reject_bad_reg (Rd);
12174 reject_bad_reg (Rn);
12175 reject_bad_reg (Rm);
12176
12177 inst.instruction |= Rd << 8;
12178 inst.instruction |= Rn << 16;
12179 inst.instruction |= Rm;
c19d1205
ZW
12180 inst.instruction |= inst.operands[3].imm << 4;
12181}
b99bd4ef 12182
c19d1205
ZW
12183static void
12184do_t_sxth (void)
12185{
fdfde340
JM
12186 unsigned Rd, Rm;
12187
12188 Rd = inst.operands[0].reg;
12189 Rm = inst.operands[1].reg;
12190
12191 reject_bad_reg (Rd);
12192 reject_bad_reg (Rm);
c921be7d
NC
12193
12194 if (inst.instruction <= 0xffff
12195 && inst.size_req != 4
fdfde340 12196 && Rd <= 7 && Rm <= 7
c19d1205 12197 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 12198 {
c19d1205 12199 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12200 inst.instruction |= Rd;
12201 inst.instruction |= Rm << 3;
b99bd4ef 12202 }
c19d1205 12203 else if (unified_syntax)
b99bd4ef 12204 {
c19d1205
ZW
12205 if (inst.instruction <= 0xffff)
12206 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12207 inst.instruction |= Rd << 8;
12208 inst.instruction |= Rm;
c19d1205 12209 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 12210 }
c19d1205 12211 else
b99bd4ef 12212 {
c19d1205
ZW
12213 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
12214 _("Thumb encoding does not support rotation"));
12215 constraint (1, BAD_HIREG);
b99bd4ef 12216 }
c19d1205 12217}
b99bd4ef 12218
c19d1205
ZW
12219static void
12220do_t_swi (void)
12221{
b2a5fbdc
MGD
12222 /* We have to do the following check manually as ARM_EXT_OS only applies
12223 to ARM_EXT_V6M. */
12224 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
12225 {
ac7f631b
NC
12226 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
12227 /* This only applies to the v6m howver, not later architectures. */
12228 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
12229 as_bad (_("SVC is not permitted on this architecture"));
12230 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
12231 }
12232
c19d1205
ZW
12233 inst.reloc.type = BFD_RELOC_ARM_SWI;
12234}
b99bd4ef 12235
92e90b6e
PB
12236static void
12237do_t_tb (void)
12238{
fdfde340 12239 unsigned Rn, Rm;
92e90b6e
PB
12240 int half;
12241
12242 half = (inst.instruction & 0x10) != 0;
e07e6e58 12243 set_it_insn_type_last ();
dfa9f0d5
PB
12244 constraint (inst.operands[0].immisreg,
12245 _("instruction requires register index"));
fdfde340
JM
12246
12247 Rn = inst.operands[0].reg;
12248 Rm = inst.operands[0].imm;
c921be7d 12249
fdfde340
JM
12250 constraint (Rn == REG_SP, BAD_SP);
12251 reject_bad_reg (Rm);
12252
92e90b6e
PB
12253 constraint (!half && inst.operands[0].shifted,
12254 _("instruction does not allow shifted index"));
fdfde340 12255 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
12256}
12257
c19d1205
ZW
12258static void
12259do_t_usat (void)
12260{
3a21c15a 12261 do_t_ssat_usat (0);
b99bd4ef
NC
12262}
12263
12264static void
c19d1205 12265do_t_usat16 (void)
b99bd4ef 12266{
fdfde340
JM
12267 unsigned Rd, Rn;
12268
12269 Rd = inst.operands[0].reg;
12270 Rn = inst.operands[2].reg;
12271
12272 reject_bad_reg (Rd);
12273 reject_bad_reg (Rn);
12274
12275 inst.instruction |= Rd << 8;
c19d1205 12276 inst.instruction |= inst.operands[1].imm;
fdfde340 12277 inst.instruction |= Rn << 16;
b99bd4ef 12278}
c19d1205 12279
5287ad62 12280/* Neon instruction encoder helpers. */
5f4273c7 12281
5287ad62 12282/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 12283
5287ad62
JB
12284/* An "invalid" code for the following tables. */
12285#define N_INV -1u
12286
12287struct neon_tab_entry
b99bd4ef 12288{
5287ad62
JB
12289 unsigned integer;
12290 unsigned float_or_poly;
12291 unsigned scalar_or_imm;
12292};
5f4273c7 12293
5287ad62
JB
12294/* Map overloaded Neon opcodes to their respective encodings. */
12295#define NEON_ENC_TAB \
12296 X(vabd, 0x0000700, 0x1200d00, N_INV), \
12297 X(vmax, 0x0000600, 0x0000f00, N_INV), \
12298 X(vmin, 0x0000610, 0x0200f00, N_INV), \
12299 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
12300 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
12301 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
12302 X(vadd, 0x0000800, 0x0000d00, N_INV), \
12303 X(vsub, 0x1000800, 0x0200d00, N_INV), \
12304 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
12305 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
12306 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
12307 /* Register variants of the following two instructions are encoded as
e07e6e58 12308 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
12309 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
12310 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
12311 X(vfma, N_INV, 0x0000c10, N_INV), \
12312 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
12313 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
12314 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
12315 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
12316 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
12317 X(vmlal, 0x0800800, N_INV, 0x0800240), \
12318 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
12319 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
12320 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
12321 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
12322 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
12323 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
12324 X(vshl, 0x0000400, N_INV, 0x0800510), \
12325 X(vqshl, 0x0000410, N_INV, 0x0800710), \
12326 X(vand, 0x0000110, N_INV, 0x0800030), \
12327 X(vbic, 0x0100110, N_INV, 0x0800030), \
12328 X(veor, 0x1000110, N_INV, N_INV), \
12329 X(vorn, 0x0300110, N_INV, 0x0800010), \
12330 X(vorr, 0x0200110, N_INV, 0x0800010), \
12331 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
12332 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
12333 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
12334 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
12335 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
12336 X(vst1, 0x0000000, 0x0800000, N_INV), \
12337 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
12338 X(vst2, 0x0000100, 0x0800100, N_INV), \
12339 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
12340 X(vst3, 0x0000200, 0x0800200, N_INV), \
12341 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
12342 X(vst4, 0x0000300, 0x0800300, N_INV), \
12343 X(vmovn, 0x1b20200, N_INV, N_INV), \
12344 X(vtrn, 0x1b20080, N_INV, N_INV), \
12345 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
12346 X(vqmovun, 0x1b20240, N_INV, N_INV), \
12347 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
12348 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
12349 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
12350 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
12351 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
12352 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
12353 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
12354 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
12355 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
12356 X(vseleq, 0xe000a00, N_INV, N_INV), \
12357 X(vselvs, 0xe100a00, N_INV, N_INV), \
12358 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
12359 X(vselgt, 0xe300a00, N_INV, N_INV), \
12360 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 12361 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
12362 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
12363 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 12364 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 12365 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
12366 X(sha3op, 0x2000c00, N_INV, N_INV), \
12367 X(sha1h, 0x3b902c0, N_INV, N_INV), \
12368 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
12369
12370enum neon_opc
12371{
12372#define X(OPC,I,F,S) N_MNEM_##OPC
12373NEON_ENC_TAB
12374#undef X
12375};
b99bd4ef 12376
5287ad62
JB
12377static const struct neon_tab_entry neon_enc_tab[] =
12378{
12379#define X(OPC,I,F,S) { (I), (F), (S) }
12380NEON_ENC_TAB
12381#undef X
12382};
b99bd4ef 12383
88714cb8
DG
12384/* Do not use these macros; instead, use NEON_ENCODE defined below. */
12385#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12386#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12387#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12388#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12389#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12390#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12391#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12392#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12393#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12394#define NEON_ENC_SINGLE_(X) \
037e8744 12395 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 12396#define NEON_ENC_DOUBLE_(X) \
037e8744 12397 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
12398#define NEON_ENC_FPV8_(X) \
12399 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 12400
88714cb8
DG
12401#define NEON_ENCODE(type, inst) \
12402 do \
12403 { \
12404 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
12405 inst.is_neon = 1; \
12406 } \
12407 while (0)
12408
12409#define check_neon_suffixes \
12410 do \
12411 { \
12412 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
12413 { \
12414 as_bad (_("invalid neon suffix for non neon instruction")); \
12415 return; \
12416 } \
12417 } \
12418 while (0)
12419
037e8744
JB
12420/* Define shapes for instruction operands. The following mnemonic characters
12421 are used in this table:
5287ad62 12422
037e8744 12423 F - VFP S<n> register
5287ad62
JB
12424 D - Neon D<n> register
12425 Q - Neon Q<n> register
12426 I - Immediate
12427 S - Scalar
12428 R - ARM register
12429 L - D<n> register list
5f4273c7 12430
037e8744
JB
12431 This table is used to generate various data:
12432 - enumerations of the form NS_DDR to be used as arguments to
12433 neon_select_shape.
12434 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 12435 - a table used to drive neon_select_shape. */
b99bd4ef 12436
037e8744
JB
12437#define NEON_SHAPE_DEF \
12438 X(3, (D, D, D), DOUBLE), \
12439 X(3, (Q, Q, Q), QUAD), \
12440 X(3, (D, D, I), DOUBLE), \
12441 X(3, (Q, Q, I), QUAD), \
12442 X(3, (D, D, S), DOUBLE), \
12443 X(3, (Q, Q, S), QUAD), \
12444 X(2, (D, D), DOUBLE), \
12445 X(2, (Q, Q), QUAD), \
12446 X(2, (D, S), DOUBLE), \
12447 X(2, (Q, S), QUAD), \
12448 X(2, (D, R), DOUBLE), \
12449 X(2, (Q, R), QUAD), \
12450 X(2, (D, I), DOUBLE), \
12451 X(2, (Q, I), QUAD), \
12452 X(3, (D, L, D), DOUBLE), \
12453 X(2, (D, Q), MIXED), \
12454 X(2, (Q, D), MIXED), \
12455 X(3, (D, Q, I), MIXED), \
12456 X(3, (Q, D, I), MIXED), \
12457 X(3, (Q, D, D), MIXED), \
12458 X(3, (D, Q, Q), MIXED), \
12459 X(3, (Q, Q, D), MIXED), \
12460 X(3, (Q, D, S), MIXED), \
12461 X(3, (D, Q, S), MIXED), \
12462 X(4, (D, D, D, I), DOUBLE), \
12463 X(4, (Q, Q, Q, I), QUAD), \
12464 X(2, (F, F), SINGLE), \
12465 X(3, (F, F, F), SINGLE), \
12466 X(2, (F, I), SINGLE), \
12467 X(2, (F, D), MIXED), \
12468 X(2, (D, F), MIXED), \
12469 X(3, (F, F, I), MIXED), \
12470 X(4, (R, R, F, F), SINGLE), \
12471 X(4, (F, F, R, R), SINGLE), \
12472 X(3, (D, R, R), DOUBLE), \
12473 X(3, (R, R, D), DOUBLE), \
12474 X(2, (S, R), SINGLE), \
12475 X(2, (R, S), SINGLE), \
12476 X(2, (F, R), SINGLE), \
12477 X(2, (R, F), SINGLE)
12478
12479#define S2(A,B) NS_##A##B
12480#define S3(A,B,C) NS_##A##B##C
12481#define S4(A,B,C,D) NS_##A##B##C##D
12482
12483#define X(N, L, C) S##N L
12484
5287ad62
JB
12485enum neon_shape
12486{
037e8744
JB
12487 NEON_SHAPE_DEF,
12488 NS_NULL
5287ad62 12489};
b99bd4ef 12490
037e8744
JB
12491#undef X
12492#undef S2
12493#undef S3
12494#undef S4
12495
12496enum neon_shape_class
12497{
12498 SC_SINGLE,
12499 SC_DOUBLE,
12500 SC_QUAD,
12501 SC_MIXED
12502};
12503
12504#define X(N, L, C) SC_##C
12505
12506static enum neon_shape_class neon_shape_class[] =
12507{
12508 NEON_SHAPE_DEF
12509};
12510
12511#undef X
12512
12513enum neon_shape_el
12514{
12515 SE_F,
12516 SE_D,
12517 SE_Q,
12518 SE_I,
12519 SE_S,
12520 SE_R,
12521 SE_L
12522};
12523
12524/* Register widths of above. */
12525static unsigned neon_shape_el_size[] =
12526{
12527 32,
12528 64,
12529 128,
12530 0,
12531 32,
12532 32,
12533 0
12534};
12535
12536struct neon_shape_info
12537{
12538 unsigned els;
12539 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
12540};
12541
12542#define S2(A,B) { SE_##A, SE_##B }
12543#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
12544#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
12545
12546#define X(N, L, C) { N, S##N L }
12547
12548static struct neon_shape_info neon_shape_tab[] =
12549{
12550 NEON_SHAPE_DEF
12551};
12552
12553#undef X
12554#undef S2
12555#undef S3
12556#undef S4
12557
5287ad62
JB
12558/* Bit masks used in type checking given instructions.
12559 'N_EQK' means the type must be the same as (or based on in some way) the key
12560 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
12561 set, various other bits can be set as well in order to modify the meaning of
12562 the type constraint. */
12563
12564enum neon_type_mask
12565{
8e79c3df
CM
12566 N_S8 = 0x0000001,
12567 N_S16 = 0x0000002,
12568 N_S32 = 0x0000004,
12569 N_S64 = 0x0000008,
12570 N_U8 = 0x0000010,
12571 N_U16 = 0x0000020,
12572 N_U32 = 0x0000040,
12573 N_U64 = 0x0000080,
12574 N_I8 = 0x0000100,
12575 N_I16 = 0x0000200,
12576 N_I32 = 0x0000400,
12577 N_I64 = 0x0000800,
12578 N_8 = 0x0001000,
12579 N_16 = 0x0002000,
12580 N_32 = 0x0004000,
12581 N_64 = 0x0008000,
12582 N_P8 = 0x0010000,
12583 N_P16 = 0x0020000,
12584 N_F16 = 0x0040000,
12585 N_F32 = 0x0080000,
12586 N_F64 = 0x0100000,
4f51b4bd 12587 N_P64 = 0x0200000,
c921be7d
NC
12588 N_KEY = 0x1000000, /* Key element (main type specifier). */
12589 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 12590 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 12591 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
12592 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
12593 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
12594 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
12595 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
12596 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
12597 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
12598 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 12599 N_UTYP = 0,
4f51b4bd 12600 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
12601};
12602
dcbf9037
JB
12603#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
12604
5287ad62
JB
12605#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
12606#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
12607#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
12608#define N_SUF_32 (N_SU_32 | N_F32)
12609#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
12610#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
12611
12612/* Pass this as the first type argument to neon_check_type to ignore types
12613 altogether. */
12614#define N_IGNORE_TYPE (N_KEY | N_EQK)
12615
037e8744
JB
12616/* Select a "shape" for the current instruction (describing register types or
12617 sizes) from a list of alternatives. Return NS_NULL if the current instruction
12618 doesn't fit. For non-polymorphic shapes, checking is usually done as a
12619 function of operand parsing, so this function doesn't need to be called.
12620 Shapes should be listed in order of decreasing length. */
5287ad62
JB
12621
12622static enum neon_shape
037e8744 12623neon_select_shape (enum neon_shape shape, ...)
5287ad62 12624{
037e8744
JB
12625 va_list ap;
12626 enum neon_shape first_shape = shape;
5287ad62
JB
12627
12628 /* Fix missing optional operands. FIXME: we don't know at this point how
12629 many arguments we should have, so this makes the assumption that we have
12630 > 1. This is true of all current Neon opcodes, I think, but may not be
12631 true in the future. */
12632 if (!inst.operands[1].present)
12633 inst.operands[1] = inst.operands[0];
12634
037e8744 12635 va_start (ap, shape);
5f4273c7 12636
21d799b5 12637 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
12638 {
12639 unsigned j;
12640 int matches = 1;
12641
12642 for (j = 0; j < neon_shape_tab[shape].els; j++)
12643 {
12644 if (!inst.operands[j].present)
12645 {
12646 matches = 0;
12647 break;
12648 }
12649
12650 switch (neon_shape_tab[shape].el[j])
12651 {
12652 case SE_F:
12653 if (!(inst.operands[j].isreg
12654 && inst.operands[j].isvec
12655 && inst.operands[j].issingle
12656 && !inst.operands[j].isquad))
12657 matches = 0;
12658 break;
12659
12660 case SE_D:
12661 if (!(inst.operands[j].isreg
12662 && inst.operands[j].isvec
12663 && !inst.operands[j].isquad
12664 && !inst.operands[j].issingle))
12665 matches = 0;
12666 break;
12667
12668 case SE_R:
12669 if (!(inst.operands[j].isreg
12670 && !inst.operands[j].isvec))
12671 matches = 0;
12672 break;
12673
12674 case SE_Q:
12675 if (!(inst.operands[j].isreg
12676 && inst.operands[j].isvec
12677 && inst.operands[j].isquad
12678 && !inst.operands[j].issingle))
12679 matches = 0;
12680 break;
12681
12682 case SE_I:
12683 if (!(!inst.operands[j].isreg
12684 && !inst.operands[j].isscalar))
12685 matches = 0;
12686 break;
12687
12688 case SE_S:
12689 if (!(!inst.operands[j].isreg
12690 && inst.operands[j].isscalar))
12691 matches = 0;
12692 break;
12693
12694 case SE_L:
12695 break;
12696 }
3fde54a2
JZ
12697 if (!matches)
12698 break;
037e8744 12699 }
ad6cec43
MGD
12700 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
12701 /* We've matched all the entries in the shape table, and we don't
12702 have any left over operands which have not been matched. */
5287ad62 12703 break;
037e8744 12704 }
5f4273c7 12705
037e8744 12706 va_end (ap);
5287ad62 12707
037e8744
JB
12708 if (shape == NS_NULL && first_shape != NS_NULL)
12709 first_error (_("invalid instruction shape"));
5287ad62 12710
037e8744
JB
12711 return shape;
12712}
5287ad62 12713
037e8744
JB
12714/* True if SHAPE is predominantly a quadword operation (most of the time, this
12715 means the Q bit should be set). */
12716
12717static int
12718neon_quad (enum neon_shape shape)
12719{
12720 return neon_shape_class[shape] == SC_QUAD;
5287ad62 12721}
037e8744 12722
5287ad62
JB
12723static void
12724neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
12725 unsigned *g_size)
12726{
12727 /* Allow modification to be made to types which are constrained to be
12728 based on the key element, based on bits set alongside N_EQK. */
12729 if ((typebits & N_EQK) != 0)
12730 {
12731 if ((typebits & N_HLF) != 0)
12732 *g_size /= 2;
12733 else if ((typebits & N_DBL) != 0)
12734 *g_size *= 2;
12735 if ((typebits & N_SGN) != 0)
12736 *g_type = NT_signed;
12737 else if ((typebits & N_UNS) != 0)
12738 *g_type = NT_unsigned;
12739 else if ((typebits & N_INT) != 0)
12740 *g_type = NT_integer;
12741 else if ((typebits & N_FLT) != 0)
12742 *g_type = NT_float;
dcbf9037
JB
12743 else if ((typebits & N_SIZ) != 0)
12744 *g_type = NT_untyped;
5287ad62
JB
12745 }
12746}
5f4273c7 12747
5287ad62
JB
12748/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12749 operand type, i.e. the single type specified in a Neon instruction when it
12750 is the only one given. */
12751
12752static struct neon_type_el
12753neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12754{
12755 struct neon_type_el dest = *key;
5f4273c7 12756
9c2799c2 12757 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 12758
5287ad62
JB
12759 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12760
12761 return dest;
12762}
12763
12764/* Convert Neon type and size into compact bitmask representation. */
12765
12766static enum neon_type_mask
12767type_chk_of_el_type (enum neon_el_type type, unsigned size)
12768{
12769 switch (type)
12770 {
12771 case NT_untyped:
12772 switch (size)
12773 {
12774 case 8: return N_8;
12775 case 16: return N_16;
12776 case 32: return N_32;
12777 case 64: return N_64;
12778 default: ;
12779 }
12780 break;
12781
12782 case NT_integer:
12783 switch (size)
12784 {
12785 case 8: return N_I8;
12786 case 16: return N_I16;
12787 case 32: return N_I32;
12788 case 64: return N_I64;
12789 default: ;
12790 }
12791 break;
12792
12793 case NT_float:
037e8744
JB
12794 switch (size)
12795 {
8e79c3df 12796 case 16: return N_F16;
037e8744
JB
12797 case 32: return N_F32;
12798 case 64: return N_F64;
12799 default: ;
12800 }
5287ad62
JB
12801 break;
12802
12803 case NT_poly:
12804 switch (size)
12805 {
12806 case 8: return N_P8;
12807 case 16: return N_P16;
4f51b4bd 12808 case 64: return N_P64;
5287ad62
JB
12809 default: ;
12810 }
12811 break;
12812
12813 case NT_signed:
12814 switch (size)
12815 {
12816 case 8: return N_S8;
12817 case 16: return N_S16;
12818 case 32: return N_S32;
12819 case 64: return N_S64;
12820 default: ;
12821 }
12822 break;
12823
12824 case NT_unsigned:
12825 switch (size)
12826 {
12827 case 8: return N_U8;
12828 case 16: return N_U16;
12829 case 32: return N_U32;
12830 case 64: return N_U64;
12831 default: ;
12832 }
12833 break;
12834
12835 default: ;
12836 }
5f4273c7 12837
5287ad62
JB
12838 return N_UTYP;
12839}
12840
12841/* Convert compact Neon bitmask type representation to a type and size. Only
12842 handles the case where a single bit is set in the mask. */
12843
dcbf9037 12844static int
5287ad62
JB
12845el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12846 enum neon_type_mask mask)
12847{
dcbf9037
JB
12848 if ((mask & N_EQK) != 0)
12849 return FAIL;
12850
5287ad62
JB
12851 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12852 *size = 8;
c70a8987 12853 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 12854 *size = 16;
dcbf9037 12855 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 12856 *size = 32;
4f51b4bd 12857 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 12858 *size = 64;
dcbf9037
JB
12859 else
12860 return FAIL;
12861
5287ad62
JB
12862 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12863 *type = NT_signed;
dcbf9037 12864 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 12865 *type = NT_unsigned;
dcbf9037 12866 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 12867 *type = NT_integer;
dcbf9037 12868 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 12869 *type = NT_untyped;
4f51b4bd 12870 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 12871 *type = NT_poly;
c70a8987 12872 else if ((mask & (N_F16 | N_F32 | N_F64)) != 0)
5287ad62 12873 *type = NT_float;
dcbf9037
JB
12874 else
12875 return FAIL;
5f4273c7 12876
dcbf9037 12877 return SUCCESS;
5287ad62
JB
12878}
12879
12880/* Modify a bitmask of allowed types. This is only needed for type
12881 relaxation. */
12882
12883static unsigned
12884modify_types_allowed (unsigned allowed, unsigned mods)
12885{
12886 unsigned size;
12887 enum neon_el_type type;
12888 unsigned destmask;
12889 int i;
5f4273c7 12890
5287ad62 12891 destmask = 0;
5f4273c7 12892
5287ad62
JB
12893 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12894 {
21d799b5
NC
12895 if (el_type_of_type_chk (&type, &size,
12896 (enum neon_type_mask) (allowed & i)) == SUCCESS)
dcbf9037
JB
12897 {
12898 neon_modify_type_size (mods, &type, &size);
12899 destmask |= type_chk_of_el_type (type, size);
12900 }
5287ad62 12901 }
5f4273c7 12902
5287ad62
JB
12903 return destmask;
12904}
12905
12906/* Check type and return type classification.
12907 The manual states (paraphrase): If one datatype is given, it indicates the
12908 type given in:
12909 - the second operand, if there is one
12910 - the operand, if there is no second operand
12911 - the result, if there are no operands.
12912 This isn't quite good enough though, so we use a concept of a "key" datatype
12913 which is set on a per-instruction basis, which is the one which matters when
12914 only one data type is written.
12915 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 12916 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
12917
12918static struct neon_type_el
12919neon_check_type (unsigned els, enum neon_shape ns, ...)
12920{
12921 va_list ap;
12922 unsigned i, pass, key_el = 0;
12923 unsigned types[NEON_MAX_TYPE_ELS];
12924 enum neon_el_type k_type = NT_invtype;
12925 unsigned k_size = -1u;
12926 struct neon_type_el badtype = {NT_invtype, -1};
12927 unsigned key_allowed = 0;
12928
12929 /* Optional registers in Neon instructions are always (not) in operand 1.
12930 Fill in the missing operand here, if it was omitted. */
12931 if (els > 1 && !inst.operands[1].present)
12932 inst.operands[1] = inst.operands[0];
12933
12934 /* Suck up all the varargs. */
12935 va_start (ap, ns);
12936 for (i = 0; i < els; i++)
12937 {
12938 unsigned thisarg = va_arg (ap, unsigned);
12939 if (thisarg == N_IGNORE_TYPE)
12940 {
12941 va_end (ap);
12942 return badtype;
12943 }
12944 types[i] = thisarg;
12945 if ((thisarg & N_KEY) != 0)
12946 key_el = i;
12947 }
12948 va_end (ap);
12949
dcbf9037
JB
12950 if (inst.vectype.elems > 0)
12951 for (i = 0; i < els; i++)
12952 if (inst.operands[i].vectype.type != NT_invtype)
12953 {
12954 first_error (_("types specified in both the mnemonic and operands"));
12955 return badtype;
12956 }
12957
5287ad62
JB
12958 /* Duplicate inst.vectype elements here as necessary.
12959 FIXME: No idea if this is exactly the same as the ARM assembler,
12960 particularly when an insn takes one register and one non-register
12961 operand. */
12962 if (inst.vectype.elems == 1 && els > 1)
12963 {
12964 unsigned j;
12965 inst.vectype.elems = els;
12966 inst.vectype.el[key_el] = inst.vectype.el[0];
12967 for (j = 0; j < els; j++)
dcbf9037
JB
12968 if (j != key_el)
12969 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12970 types[j]);
12971 }
12972 else if (inst.vectype.elems == 0 && els > 0)
12973 {
12974 unsigned j;
12975 /* No types were given after the mnemonic, so look for types specified
12976 after each operand. We allow some flexibility here; as long as the
12977 "key" operand has a type, we can infer the others. */
12978 for (j = 0; j < els; j++)
12979 if (inst.operands[j].vectype.type != NT_invtype)
12980 inst.vectype.el[j] = inst.operands[j].vectype;
12981
12982 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 12983 {
dcbf9037
JB
12984 for (j = 0; j < els; j++)
12985 if (inst.operands[j].vectype.type == NT_invtype)
12986 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12987 types[j]);
12988 }
12989 else
12990 {
12991 first_error (_("operand types can't be inferred"));
12992 return badtype;
5287ad62
JB
12993 }
12994 }
12995 else if (inst.vectype.elems != els)
12996 {
dcbf9037 12997 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
12998 return badtype;
12999 }
13000
13001 for (pass = 0; pass < 2; pass++)
13002 {
13003 for (i = 0; i < els; i++)
13004 {
13005 unsigned thisarg = types[i];
13006 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13007 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13008 enum neon_el_type g_type = inst.vectype.el[i].type;
13009 unsigned g_size = inst.vectype.el[i].size;
13010
13011 /* Decay more-specific signed & unsigned types to sign-insensitive
13012 integer types if sign-specific variants are unavailable. */
13013 if ((g_type == NT_signed || g_type == NT_unsigned)
13014 && (types_allowed & N_SU_ALL) == 0)
13015 g_type = NT_integer;
13016
13017 /* If only untyped args are allowed, decay any more specific types to
13018 them. Some instructions only care about signs for some element
13019 sizes, so handle that properly. */
91ff7894
MGD
13020 if (((types_allowed & N_UNT) == 0)
13021 && ((g_size == 8 && (types_allowed & N_8) != 0)
13022 || (g_size == 16 && (types_allowed & N_16) != 0)
13023 || (g_size == 32 && (types_allowed & N_32) != 0)
13024 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
13025 g_type = NT_untyped;
13026
13027 if (pass == 0)
13028 {
13029 if ((thisarg & N_KEY) != 0)
13030 {
13031 k_type = g_type;
13032 k_size = g_size;
13033 key_allowed = thisarg & ~N_KEY;
13034 }
13035 }
13036 else
13037 {
037e8744
JB
13038 if ((thisarg & N_VFP) != 0)
13039 {
99b253c5
NC
13040 enum neon_shape_el regshape;
13041 unsigned regwidth, match;
13042
13043 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13044 if (ns == NS_NULL)
13045 {
13046 first_error (_("invalid instruction shape"));
13047 return badtype;
13048 }
13049 regshape = neon_shape_tab[ns].el[i];
13050 regwidth = neon_shape_el_size[regshape];
037e8744
JB
13051
13052 /* In VFP mode, operands must match register widths. If we
13053 have a key operand, use its width, else use the width of
13054 the current operand. */
13055 if (k_size != -1u)
13056 match = k_size;
13057 else
13058 match = g_size;
13059
13060 if (regwidth != match)
13061 {
13062 first_error (_("operand size must match register width"));
13063 return badtype;
13064 }
13065 }
5f4273c7 13066
5287ad62
JB
13067 if ((thisarg & N_EQK) == 0)
13068 {
13069 unsigned given_type = type_chk_of_el_type (g_type, g_size);
13070
13071 if ((given_type & types_allowed) == 0)
13072 {
dcbf9037 13073 first_error (_("bad type in Neon instruction"));
5287ad62
JB
13074 return badtype;
13075 }
13076 }
13077 else
13078 {
13079 enum neon_el_type mod_k_type = k_type;
13080 unsigned mod_k_size = k_size;
13081 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
13082 if (g_type != mod_k_type || g_size != mod_k_size)
13083 {
dcbf9037 13084 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
13085 return badtype;
13086 }
13087 }
13088 }
13089 }
13090 }
13091
13092 return inst.vectype.el[key_el];
13093}
13094
037e8744 13095/* Neon-style VFP instruction forwarding. */
5287ad62 13096
037e8744
JB
13097/* Thumb VFP instructions have 0xE in the condition field. */
13098
13099static void
13100do_vfp_cond_or_thumb (void)
5287ad62 13101{
88714cb8
DG
13102 inst.is_neon = 1;
13103
5287ad62 13104 if (thumb_mode)
037e8744 13105 inst.instruction |= 0xe0000000;
5287ad62 13106 else
037e8744 13107 inst.instruction |= inst.cond << 28;
5287ad62
JB
13108}
13109
037e8744
JB
13110/* Look up and encode a simple mnemonic, for use as a helper function for the
13111 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
13112 etc. It is assumed that operand parsing has already been done, and that the
13113 operands are in the form expected by the given opcode (this isn't necessarily
13114 the same as the form in which they were parsed, hence some massaging must
13115 take place before this function is called).
13116 Checks current arch version against that in the looked-up opcode. */
5287ad62 13117
037e8744
JB
13118static void
13119do_vfp_nsyn_opcode (const char *opname)
5287ad62 13120{
037e8744 13121 const struct asm_opcode *opcode;
5f4273c7 13122
21d799b5 13123 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 13124
037e8744
JB
13125 if (!opcode)
13126 abort ();
5287ad62 13127
037e8744
JB
13128 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
13129 thumb_mode ? *opcode->tvariant : *opcode->avariant),
13130 _(BAD_FPU));
5287ad62 13131
88714cb8
DG
13132 inst.is_neon = 1;
13133
037e8744
JB
13134 if (thumb_mode)
13135 {
13136 inst.instruction = opcode->tvalue;
13137 opcode->tencode ();
13138 }
13139 else
13140 {
13141 inst.instruction = (inst.cond << 28) | opcode->avalue;
13142 opcode->aencode ();
13143 }
13144}
5287ad62
JB
13145
13146static void
037e8744 13147do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 13148{
037e8744
JB
13149 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
13150
13151 if (rs == NS_FFF)
13152 {
13153 if (is_add)
13154 do_vfp_nsyn_opcode ("fadds");
13155 else
13156 do_vfp_nsyn_opcode ("fsubs");
13157 }
13158 else
13159 {
13160 if (is_add)
13161 do_vfp_nsyn_opcode ("faddd");
13162 else
13163 do_vfp_nsyn_opcode ("fsubd");
13164 }
13165}
13166
13167/* Check operand types to see if this is a VFP instruction, and if so call
13168 PFN (). */
13169
13170static int
13171try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
13172{
13173 enum neon_shape rs;
13174 struct neon_type_el et;
13175
13176 switch (args)
13177 {
13178 case 2:
13179 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13180 et = neon_check_type (2, rs,
13181 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13182 break;
5f4273c7 13183
037e8744
JB
13184 case 3:
13185 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13186 et = neon_check_type (3, rs,
13187 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13188 break;
13189
13190 default:
13191 abort ();
13192 }
13193
13194 if (et.type != NT_invtype)
13195 {
13196 pfn (rs);
13197 return SUCCESS;
13198 }
037e8744 13199
99b253c5 13200 inst.error = NULL;
037e8744
JB
13201 return FAIL;
13202}
13203
13204static void
13205do_vfp_nsyn_mla_mls (enum neon_shape rs)
13206{
13207 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 13208
037e8744
JB
13209 if (rs == NS_FFF)
13210 {
13211 if (is_mla)
13212 do_vfp_nsyn_opcode ("fmacs");
13213 else
1ee69515 13214 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
13215 }
13216 else
13217 {
13218 if (is_mla)
13219 do_vfp_nsyn_opcode ("fmacd");
13220 else
1ee69515 13221 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
13222 }
13223}
13224
62f3b8c8
PB
13225static void
13226do_vfp_nsyn_fma_fms (enum neon_shape rs)
13227{
13228 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
13229
13230 if (rs == NS_FFF)
13231 {
13232 if (is_fma)
13233 do_vfp_nsyn_opcode ("ffmas");
13234 else
13235 do_vfp_nsyn_opcode ("ffnmas");
13236 }
13237 else
13238 {
13239 if (is_fma)
13240 do_vfp_nsyn_opcode ("ffmad");
13241 else
13242 do_vfp_nsyn_opcode ("ffnmad");
13243 }
13244}
13245
037e8744
JB
13246static void
13247do_vfp_nsyn_mul (enum neon_shape rs)
13248{
13249 if (rs == NS_FFF)
13250 do_vfp_nsyn_opcode ("fmuls");
13251 else
13252 do_vfp_nsyn_opcode ("fmuld");
13253}
13254
13255static void
13256do_vfp_nsyn_abs_neg (enum neon_shape rs)
13257{
13258 int is_neg = (inst.instruction & 0x80) != 0;
13259 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
13260
13261 if (rs == NS_FF)
13262 {
13263 if (is_neg)
13264 do_vfp_nsyn_opcode ("fnegs");
13265 else
13266 do_vfp_nsyn_opcode ("fabss");
13267 }
13268 else
13269 {
13270 if (is_neg)
13271 do_vfp_nsyn_opcode ("fnegd");
13272 else
13273 do_vfp_nsyn_opcode ("fabsd");
13274 }
13275}
13276
13277/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
13278 insns belong to Neon, and are handled elsewhere. */
13279
13280static void
13281do_vfp_nsyn_ldm_stm (int is_dbmode)
13282{
13283 int is_ldm = (inst.instruction & (1 << 20)) != 0;
13284 if (is_ldm)
13285 {
13286 if (is_dbmode)
13287 do_vfp_nsyn_opcode ("fldmdbs");
13288 else
13289 do_vfp_nsyn_opcode ("fldmias");
13290 }
13291 else
13292 {
13293 if (is_dbmode)
13294 do_vfp_nsyn_opcode ("fstmdbs");
13295 else
13296 do_vfp_nsyn_opcode ("fstmias");
13297 }
13298}
13299
037e8744
JB
13300static void
13301do_vfp_nsyn_sqrt (void)
13302{
13303 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13304 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13305
037e8744
JB
13306 if (rs == NS_FF)
13307 do_vfp_nsyn_opcode ("fsqrts");
13308 else
13309 do_vfp_nsyn_opcode ("fsqrtd");
13310}
13311
13312static void
13313do_vfp_nsyn_div (void)
13314{
13315 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13316 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13317 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13318
037e8744
JB
13319 if (rs == NS_FFF)
13320 do_vfp_nsyn_opcode ("fdivs");
13321 else
13322 do_vfp_nsyn_opcode ("fdivd");
13323}
13324
13325static void
13326do_vfp_nsyn_nmul (void)
13327{
13328 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13329 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13330 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13331
037e8744
JB
13332 if (rs == NS_FFF)
13333 {
88714cb8 13334 NEON_ENCODE (SINGLE, inst);
037e8744
JB
13335 do_vfp_sp_dyadic ();
13336 }
13337 else
13338 {
88714cb8 13339 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
13340 do_vfp_dp_rd_rn_rm ();
13341 }
13342 do_vfp_cond_or_thumb ();
13343}
13344
13345static void
13346do_vfp_nsyn_cmp (void)
13347{
13348 if (inst.operands[1].isreg)
13349 {
13350 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13351 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13352
037e8744
JB
13353 if (rs == NS_FF)
13354 {
88714cb8 13355 NEON_ENCODE (SINGLE, inst);
037e8744
JB
13356 do_vfp_sp_monadic ();
13357 }
13358 else
13359 {
88714cb8 13360 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
13361 do_vfp_dp_rd_rm ();
13362 }
13363 }
13364 else
13365 {
13366 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
13367 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
13368
13369 switch (inst.instruction & 0x0fffffff)
13370 {
13371 case N_MNEM_vcmp:
13372 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
13373 break;
13374 case N_MNEM_vcmpe:
13375 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
13376 break;
13377 default:
13378 abort ();
13379 }
5f4273c7 13380
037e8744
JB
13381 if (rs == NS_FI)
13382 {
88714cb8 13383 NEON_ENCODE (SINGLE, inst);
037e8744
JB
13384 do_vfp_sp_compare_z ();
13385 }
13386 else
13387 {
88714cb8 13388 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
13389 do_vfp_dp_rd ();
13390 }
13391 }
13392 do_vfp_cond_or_thumb ();
13393}
13394
13395static void
13396nsyn_insert_sp (void)
13397{
13398 inst.operands[1] = inst.operands[0];
13399 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 13400 inst.operands[0].reg = REG_SP;
037e8744
JB
13401 inst.operands[0].isreg = 1;
13402 inst.operands[0].writeback = 1;
13403 inst.operands[0].present = 1;
13404}
13405
13406static void
13407do_vfp_nsyn_push (void)
13408{
13409 nsyn_insert_sp ();
13410 if (inst.operands[1].issingle)
13411 do_vfp_nsyn_opcode ("fstmdbs");
13412 else
13413 do_vfp_nsyn_opcode ("fstmdbd");
13414}
13415
13416static void
13417do_vfp_nsyn_pop (void)
13418{
13419 nsyn_insert_sp ();
13420 if (inst.operands[1].issingle)
22b5b651 13421 do_vfp_nsyn_opcode ("fldmias");
037e8744 13422 else
22b5b651 13423 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
13424}
13425
13426/* Fix up Neon data-processing instructions, ORing in the correct bits for
13427 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
13428
88714cb8
DG
13429static void
13430neon_dp_fixup (struct arm_it* insn)
037e8744 13431{
88714cb8
DG
13432 unsigned int i = insn->instruction;
13433 insn->is_neon = 1;
13434
037e8744
JB
13435 if (thumb_mode)
13436 {
13437 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
13438 if (i & (1 << 24))
13439 i |= 1 << 28;
5f4273c7 13440
037e8744 13441 i &= ~(1 << 24);
5f4273c7 13442
037e8744
JB
13443 i |= 0xef000000;
13444 }
13445 else
13446 i |= 0xf2000000;
5f4273c7 13447
88714cb8 13448 insn->instruction = i;
037e8744
JB
13449}
13450
13451/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
13452 (0, 1, 2, 3). */
13453
13454static unsigned
13455neon_logbits (unsigned x)
13456{
13457 return ffs (x) - 4;
13458}
13459
13460#define LOW4(R) ((R) & 0xf)
13461#define HI1(R) (((R) >> 4) & 1)
13462
13463/* Encode insns with bit pattern:
13464
13465 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13466 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 13467
037e8744
JB
13468 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
13469 different meaning for some instruction. */
13470
13471static void
13472neon_three_same (int isquad, int ubit, int size)
13473{
13474 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13475 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13476 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13477 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13478 inst.instruction |= LOW4 (inst.operands[2].reg);
13479 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13480 inst.instruction |= (isquad != 0) << 6;
13481 inst.instruction |= (ubit != 0) << 24;
13482 if (size != -1)
13483 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 13484
88714cb8 13485 neon_dp_fixup (&inst);
037e8744
JB
13486}
13487
13488/* Encode instructions of the form:
13489
13490 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
13491 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
13492
13493 Don't write size if SIZE == -1. */
13494
13495static void
13496neon_two_same (int qbit, int ubit, int size)
13497{
13498 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13499 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13500 inst.instruction |= LOW4 (inst.operands[1].reg);
13501 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13502 inst.instruction |= (qbit != 0) << 6;
13503 inst.instruction |= (ubit != 0) << 24;
13504
13505 if (size != -1)
13506 inst.instruction |= neon_logbits (size) << 18;
13507
88714cb8 13508 neon_dp_fixup (&inst);
5287ad62
JB
13509}
13510
13511/* Neon instruction encoders, in approximate order of appearance. */
13512
13513static void
13514do_neon_dyadic_i_su (void)
13515{
037e8744 13516 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13517 struct neon_type_el et = neon_check_type (3, rs,
13518 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 13519 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13520}
13521
13522static void
13523do_neon_dyadic_i64_su (void)
13524{
037e8744 13525 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13526 struct neon_type_el et = neon_check_type (3, rs,
13527 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 13528 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13529}
13530
13531static void
13532neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
13533 unsigned immbits)
13534{
13535 unsigned size = et.size >> 3;
13536 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13537 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13538 inst.instruction |= LOW4 (inst.operands[1].reg);
13539 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13540 inst.instruction |= (isquad != 0) << 6;
13541 inst.instruction |= immbits << 16;
13542 inst.instruction |= (size >> 3) << 7;
13543 inst.instruction |= (size & 0x7) << 19;
13544 if (write_ubit)
13545 inst.instruction |= (uval != 0) << 24;
13546
88714cb8 13547 neon_dp_fixup (&inst);
5287ad62
JB
13548}
13549
13550static void
13551do_neon_shl_imm (void)
13552{
13553 if (!inst.operands[2].isreg)
13554 {
037e8744 13555 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 13556 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
88714cb8 13557 NEON_ENCODE (IMMED, inst);
037e8744 13558 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
13559 }
13560 else
13561 {
037e8744 13562 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13563 struct neon_type_el et = neon_check_type (3, rs,
13564 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13565 unsigned int tmp;
13566
13567 /* VSHL/VQSHL 3-register variants have syntax such as:
13568 vshl.xx Dd, Dm, Dn
13569 whereas other 3-register operations encoded by neon_three_same have
13570 syntax like:
13571 vadd.xx Dd, Dn, Dm
13572 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
13573 here. */
13574 tmp = inst.operands[2].reg;
13575 inst.operands[2].reg = inst.operands[1].reg;
13576 inst.operands[1].reg = tmp;
88714cb8 13577 NEON_ENCODE (INTEGER, inst);
037e8744 13578 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13579 }
13580}
13581
13582static void
13583do_neon_qshl_imm (void)
13584{
13585 if (!inst.operands[2].isreg)
13586 {
037e8744 13587 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 13588 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 13589
88714cb8 13590 NEON_ENCODE (IMMED, inst);
037e8744 13591 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13592 inst.operands[2].imm);
13593 }
13594 else
13595 {
037e8744 13596 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13597 struct neon_type_el et = neon_check_type (3, rs,
13598 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13599 unsigned int tmp;
13600
13601 /* See note in do_neon_shl_imm. */
13602 tmp = inst.operands[2].reg;
13603 inst.operands[2].reg = inst.operands[1].reg;
13604 inst.operands[1].reg = tmp;
88714cb8 13605 NEON_ENCODE (INTEGER, inst);
037e8744 13606 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13607 }
13608}
13609
627907b7
JB
13610static void
13611do_neon_rshl (void)
13612{
13613 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13614 struct neon_type_el et = neon_check_type (3, rs,
13615 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13616 unsigned int tmp;
13617
13618 tmp = inst.operands[2].reg;
13619 inst.operands[2].reg = inst.operands[1].reg;
13620 inst.operands[1].reg = tmp;
13621 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13622}
13623
5287ad62
JB
13624static int
13625neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
13626{
036dc3f7
PB
13627 /* Handle .I8 pseudo-instructions. */
13628 if (size == 8)
5287ad62 13629 {
5287ad62
JB
13630 /* Unfortunately, this will make everything apart from zero out-of-range.
13631 FIXME is this the intended semantics? There doesn't seem much point in
13632 accepting .I8 if so. */
13633 immediate |= immediate << 8;
13634 size = 16;
036dc3f7
PB
13635 }
13636
13637 if (size >= 32)
13638 {
13639 if (immediate == (immediate & 0x000000ff))
13640 {
13641 *immbits = immediate;
13642 return 0x1;
13643 }
13644 else if (immediate == (immediate & 0x0000ff00))
13645 {
13646 *immbits = immediate >> 8;
13647 return 0x3;
13648 }
13649 else if (immediate == (immediate & 0x00ff0000))
13650 {
13651 *immbits = immediate >> 16;
13652 return 0x5;
13653 }
13654 else if (immediate == (immediate & 0xff000000))
13655 {
13656 *immbits = immediate >> 24;
13657 return 0x7;
13658 }
13659 if ((immediate & 0xffff) != (immediate >> 16))
13660 goto bad_immediate;
13661 immediate &= 0xffff;
5287ad62
JB
13662 }
13663
13664 if (immediate == (immediate & 0x000000ff))
13665 {
13666 *immbits = immediate;
036dc3f7 13667 return 0x9;
5287ad62
JB
13668 }
13669 else if (immediate == (immediate & 0x0000ff00))
13670 {
13671 *immbits = immediate >> 8;
036dc3f7 13672 return 0xb;
5287ad62
JB
13673 }
13674
13675 bad_immediate:
dcbf9037 13676 first_error (_("immediate value out of range"));
5287ad62
JB
13677 return FAIL;
13678}
13679
13680/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
13681 A, B, C, D. */
13682
13683static int
13684neon_bits_same_in_bytes (unsigned imm)
13685{
13686 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
13687 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
13688 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
13689 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
13690}
13691
13692/* For immediate of above form, return 0bABCD. */
13693
13694static unsigned
13695neon_squash_bits (unsigned imm)
13696{
13697 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
13698 | ((imm & 0x01000000) >> 21);
13699}
13700
136da414 13701/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
13702
13703static unsigned
13704neon_qfloat_bits (unsigned imm)
13705{
136da414 13706 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
13707}
13708
13709/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
13710 the instruction. *OP is passed as the initial value of the op field, and
13711 may be set to a different value depending on the constant (i.e.
13712 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 13713 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 13714 try smaller element sizes. */
5287ad62
JB
13715
13716static int
c96612cc
JB
13717neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
13718 unsigned *immbits, int *op, int size,
13719 enum neon_el_type type)
5287ad62 13720{
c96612cc
JB
13721 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13722 float. */
13723 if (type == NT_float && !float_p)
13724 return FAIL;
13725
136da414
JB
13726 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13727 {
13728 if (size != 32 || *op == 1)
13729 return FAIL;
13730 *immbits = neon_qfloat_bits (immlo);
13731 return 0xf;
13732 }
036dc3f7
PB
13733
13734 if (size == 64)
5287ad62 13735 {
036dc3f7
PB
13736 if (neon_bits_same_in_bytes (immhi)
13737 && neon_bits_same_in_bytes (immlo))
13738 {
13739 if (*op == 1)
13740 return FAIL;
13741 *immbits = (neon_squash_bits (immhi) << 4)
13742 | neon_squash_bits (immlo);
13743 *op = 1;
13744 return 0xe;
13745 }
13746
13747 if (immhi != immlo)
13748 return FAIL;
5287ad62 13749 }
036dc3f7
PB
13750
13751 if (size >= 32)
5287ad62 13752 {
036dc3f7
PB
13753 if (immlo == (immlo & 0x000000ff))
13754 {
13755 *immbits = immlo;
13756 return 0x0;
13757 }
13758 else if (immlo == (immlo & 0x0000ff00))
13759 {
13760 *immbits = immlo >> 8;
13761 return 0x2;
13762 }
13763 else if (immlo == (immlo & 0x00ff0000))
13764 {
13765 *immbits = immlo >> 16;
13766 return 0x4;
13767 }
13768 else if (immlo == (immlo & 0xff000000))
13769 {
13770 *immbits = immlo >> 24;
13771 return 0x6;
13772 }
13773 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13774 {
13775 *immbits = (immlo >> 8) & 0xff;
13776 return 0xc;
13777 }
13778 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13779 {
13780 *immbits = (immlo >> 16) & 0xff;
13781 return 0xd;
13782 }
13783
13784 if ((immlo & 0xffff) != (immlo >> 16))
13785 return FAIL;
13786 immlo &= 0xffff;
5287ad62 13787 }
036dc3f7
PB
13788
13789 if (size >= 16)
5287ad62 13790 {
036dc3f7
PB
13791 if (immlo == (immlo & 0x000000ff))
13792 {
13793 *immbits = immlo;
13794 return 0x8;
13795 }
13796 else if (immlo == (immlo & 0x0000ff00))
13797 {
13798 *immbits = immlo >> 8;
13799 return 0xa;
13800 }
13801
13802 if ((immlo & 0xff) != (immlo >> 8))
13803 return FAIL;
13804 immlo &= 0xff;
5287ad62 13805 }
036dc3f7
PB
13806
13807 if (immlo == (immlo & 0x000000ff))
5287ad62 13808 {
036dc3f7
PB
13809 /* Don't allow MVN with 8-bit immediate. */
13810 if (*op == 1)
13811 return FAIL;
13812 *immbits = immlo;
13813 return 0xe;
5287ad62 13814 }
5287ad62
JB
13815
13816 return FAIL;
13817}
13818
13819/* Write immediate bits [7:0] to the following locations:
13820
13821 |28/24|23 19|18 16|15 4|3 0|
13822 | 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|
13823
13824 This function is used by VMOV/VMVN/VORR/VBIC. */
13825
13826static void
13827neon_write_immbits (unsigned immbits)
13828{
13829 inst.instruction |= immbits & 0xf;
13830 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13831 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13832}
13833
13834/* Invert low-order SIZE bits of XHI:XLO. */
13835
13836static void
13837neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13838{
13839 unsigned immlo = xlo ? *xlo : 0;
13840 unsigned immhi = xhi ? *xhi : 0;
13841
13842 switch (size)
13843 {
13844 case 8:
13845 immlo = (~immlo) & 0xff;
13846 break;
13847
13848 case 16:
13849 immlo = (~immlo) & 0xffff;
13850 break;
13851
13852 case 64:
13853 immhi = (~immhi) & 0xffffffff;
13854 /* fall through. */
13855
13856 case 32:
13857 immlo = (~immlo) & 0xffffffff;
13858 break;
13859
13860 default:
13861 abort ();
13862 }
13863
13864 if (xlo)
13865 *xlo = immlo;
13866
13867 if (xhi)
13868 *xhi = immhi;
13869}
13870
13871static void
13872do_neon_logic (void)
13873{
13874 if (inst.operands[2].present && inst.operands[2].isreg)
13875 {
037e8744 13876 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13877 neon_check_type (3, rs, N_IGNORE_TYPE);
13878 /* U bit and size field were set as part of the bitmask. */
88714cb8 13879 NEON_ENCODE (INTEGER, inst);
037e8744 13880 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13881 }
13882 else
13883 {
4316f0d2
DG
13884 const int three_ops_form = (inst.operands[2].present
13885 && !inst.operands[2].isreg);
13886 const int immoperand = (three_ops_form ? 2 : 1);
13887 enum neon_shape rs = (three_ops_form
13888 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13889 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744
JB
13890 struct neon_type_el et = neon_check_type (2, rs,
13891 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 13892 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
13893 unsigned immbits;
13894 int cmode;
5f4273c7 13895
5287ad62
JB
13896 if (et.type == NT_invtype)
13897 return;
5f4273c7 13898
4316f0d2
DG
13899 if (three_ops_form)
13900 constraint (inst.operands[0].reg != inst.operands[1].reg,
13901 _("first and second operands shall be the same register"));
13902
88714cb8 13903 NEON_ENCODE (IMMED, inst);
5287ad62 13904
4316f0d2 13905 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
13906 if (et.size == 64)
13907 {
13908 /* .i64 is a pseudo-op, so the immediate must be a repeating
13909 pattern. */
4316f0d2
DG
13910 if (immbits != (inst.operands[immoperand].regisimm ?
13911 inst.operands[immoperand].reg : 0))
036dc3f7
PB
13912 {
13913 /* Set immbits to an invalid constant. */
13914 immbits = 0xdeadbeef;
13915 }
13916 }
13917
5287ad62
JB
13918 switch (opcode)
13919 {
13920 case N_MNEM_vbic:
036dc3f7 13921 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13922 break;
5f4273c7 13923
5287ad62 13924 case N_MNEM_vorr:
036dc3f7 13925 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13926 break;
5f4273c7 13927
5287ad62
JB
13928 case N_MNEM_vand:
13929 /* Pseudo-instruction for VBIC. */
5287ad62
JB
13930 neon_invert_size (&immbits, 0, et.size);
13931 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13932 break;
5f4273c7 13933
5287ad62
JB
13934 case N_MNEM_vorn:
13935 /* Pseudo-instruction for VORR. */
5287ad62
JB
13936 neon_invert_size (&immbits, 0, et.size);
13937 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13938 break;
5f4273c7 13939
5287ad62
JB
13940 default:
13941 abort ();
13942 }
13943
13944 if (cmode == FAIL)
13945 return;
13946
037e8744 13947 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13948 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13949 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13950 inst.instruction |= cmode << 8;
13951 neon_write_immbits (immbits);
5f4273c7 13952
88714cb8 13953 neon_dp_fixup (&inst);
5287ad62
JB
13954 }
13955}
13956
13957static void
13958do_neon_bitfield (void)
13959{
037e8744 13960 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 13961 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 13962 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13963}
13964
13965static void
dcbf9037
JB
13966neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13967 unsigned destbits)
5287ad62 13968{
037e8744 13969 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
13970 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13971 types | N_KEY);
5287ad62
JB
13972 if (et.type == NT_float)
13973 {
88714cb8 13974 NEON_ENCODE (FLOAT, inst);
037e8744 13975 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13976 }
13977 else
13978 {
88714cb8 13979 NEON_ENCODE (INTEGER, inst);
037e8744 13980 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
13981 }
13982}
13983
13984static void
13985do_neon_dyadic_if_su (void)
13986{
dcbf9037 13987 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13988}
13989
13990static void
13991do_neon_dyadic_if_su_d (void)
13992{
13993 /* This version only allow D registers, but that constraint is enforced during
13994 operand parsing so we don't need to do anything extra here. */
dcbf9037 13995 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13996}
13997
5287ad62
JB
13998static void
13999do_neon_dyadic_if_i_d (void)
14000{
428e3f1f
PB
14001 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14002 affected if we specify unsigned args. */
14003 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14004}
14005
037e8744
JB
14006enum vfp_or_neon_is_neon_bits
14007{
14008 NEON_CHECK_CC = 1,
73924fbc
MGD
14009 NEON_CHECK_ARCH = 2,
14010 NEON_CHECK_ARCH8 = 4
037e8744
JB
14011};
14012
14013/* Call this function if an instruction which may have belonged to the VFP or
14014 Neon instruction sets, but turned out to be a Neon instruction (due to the
14015 operand types involved, etc.). We have to check and/or fix-up a couple of
14016 things:
14017
14018 - Make sure the user hasn't attempted to make a Neon instruction
14019 conditional.
14020 - Alter the value in the condition code field if necessary.
14021 - Make sure that the arch supports Neon instructions.
14022
14023 Which of these operations take place depends on bits from enum
14024 vfp_or_neon_is_neon_bits.
14025
14026 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14027 current instruction's condition is COND_ALWAYS, the condition field is
14028 changed to inst.uncond_value. This is necessary because instructions shared
14029 between VFP and Neon may be conditional for the VFP variants only, and the
14030 unconditional Neon version must have, e.g., 0xF in the condition field. */
14031
14032static int
14033vfp_or_neon_is_neon (unsigned check)
14034{
14035 /* Conditions are always legal in Thumb mode (IT blocks). */
14036 if (!thumb_mode && (check & NEON_CHECK_CC))
14037 {
14038 if (inst.cond != COND_ALWAYS)
14039 {
14040 first_error (_(BAD_COND));
14041 return FAIL;
14042 }
14043 if (inst.uncond_value != -1)
14044 inst.instruction |= inst.uncond_value << 28;
14045 }
5f4273c7 14046
037e8744 14047 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14048 && !mark_feature_used (&fpu_neon_ext_v1))
14049 {
14050 first_error (_(BAD_FPU));
14051 return FAIL;
14052 }
14053
14054 if ((check & NEON_CHECK_ARCH8)
14055 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14056 {
14057 first_error (_(BAD_FPU));
14058 return FAIL;
14059 }
5f4273c7 14060
037e8744
JB
14061 return SUCCESS;
14062}
14063
5287ad62
JB
14064static void
14065do_neon_addsub_if_i (void)
14066{
037e8744
JB
14067 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14068 return;
14069
14070 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14071 return;
14072
5287ad62
JB
14073 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14074 affected if we specify unsigned args. */
dcbf9037 14075 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14076}
14077
14078/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14079 result to be:
14080 V<op> A,B (A is operand 0, B is operand 2)
14081 to mean:
14082 V<op> A,B,A
14083 not:
14084 V<op> A,B,B
14085 so handle that case specially. */
14086
14087static void
14088neon_exchange_operands (void)
14089{
14090 void *scratch = alloca (sizeof (inst.operands[0]));
14091 if (inst.operands[1].present)
14092 {
14093 /* Swap operands[1] and operands[2]. */
14094 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14095 inst.operands[1] = inst.operands[2];
14096 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
14097 }
14098 else
14099 {
14100 inst.operands[1] = inst.operands[2];
14101 inst.operands[2] = inst.operands[0];
14102 }
14103}
14104
14105static void
14106neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14107{
14108 if (inst.operands[2].isreg)
14109 {
14110 if (invert)
14111 neon_exchange_operands ();
dcbf9037 14112 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14113 }
14114 else
14115 {
037e8744 14116 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
14117 struct neon_type_el et = neon_check_type (2, rs,
14118 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 14119
88714cb8 14120 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14121 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14122 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14123 inst.instruction |= LOW4 (inst.operands[1].reg);
14124 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14125 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14126 inst.instruction |= (et.type == NT_float) << 10;
14127 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14128
88714cb8 14129 neon_dp_fixup (&inst);
5287ad62
JB
14130 }
14131}
14132
14133static void
14134do_neon_cmp (void)
14135{
14136 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
14137}
14138
14139static void
14140do_neon_cmp_inv (void)
14141{
14142 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
14143}
14144
14145static void
14146do_neon_ceq (void)
14147{
14148 neon_compare (N_IF_32, N_IF_32, FALSE);
14149}
14150
14151/* For multiply instructions, we have the possibility of 16-bit or 32-bit
14152 scalars, which are encoded in 5 bits, M : Rm.
14153 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14154 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14155 index in M. */
14156
14157static unsigned
14158neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14159{
dcbf9037
JB
14160 unsigned regno = NEON_SCALAR_REG (scalar);
14161 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
14162
14163 switch (elsize)
14164 {
14165 case 16:
14166 if (regno > 7 || elno > 3)
14167 goto bad_scalar;
14168 return regno | (elno << 3);
5f4273c7 14169
5287ad62
JB
14170 case 32:
14171 if (regno > 15 || elno > 1)
14172 goto bad_scalar;
14173 return regno | (elno << 4);
14174
14175 default:
14176 bad_scalar:
dcbf9037 14177 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
14178 }
14179
14180 return 0;
14181}
14182
14183/* Encode multiply / multiply-accumulate scalar instructions. */
14184
14185static void
14186neon_mul_mac (struct neon_type_el et, int ubit)
14187{
dcbf9037
JB
14188 unsigned scalar;
14189
14190 /* Give a more helpful error message if we have an invalid type. */
14191 if (et.type == NT_invtype)
14192 return;
5f4273c7 14193
dcbf9037 14194 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
14195 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14196 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14197 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14198 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14199 inst.instruction |= LOW4 (scalar);
14200 inst.instruction |= HI1 (scalar) << 5;
14201 inst.instruction |= (et.type == NT_float) << 8;
14202 inst.instruction |= neon_logbits (et.size) << 20;
14203 inst.instruction |= (ubit != 0) << 24;
14204
88714cb8 14205 neon_dp_fixup (&inst);
5287ad62
JB
14206}
14207
14208static void
14209do_neon_mac_maybe_scalar (void)
14210{
037e8744
JB
14211 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14212 return;
14213
14214 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14215 return;
14216
5287ad62
JB
14217 if (inst.operands[2].isscalar)
14218 {
037e8744 14219 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
14220 struct neon_type_el et = neon_check_type (3, rs,
14221 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 14222 NEON_ENCODE (SCALAR, inst);
037e8744 14223 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14224 }
14225 else
428e3f1f
PB
14226 {
14227 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14228 affected if we specify unsigned args. */
14229 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14230 }
5287ad62
JB
14231}
14232
62f3b8c8
PB
14233static void
14234do_neon_fmac (void)
14235{
14236 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
14237 return;
14238
14239 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14240 return;
14241
14242 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14243}
14244
5287ad62
JB
14245static void
14246do_neon_tst (void)
14247{
037e8744 14248 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14249 struct neon_type_el et = neon_check_type (3, rs,
14250 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 14251 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14252}
14253
14254/* VMUL with 3 registers allows the P8 type. The scalar version supports the
14255 same types as the MAC equivalents. The polynomial type for this instruction
14256 is encoded the same as the integer type. */
14257
14258static void
14259do_neon_mul (void)
14260{
037e8744
JB
14261 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14262 return;
14263
14264 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14265 return;
14266
5287ad62
JB
14267 if (inst.operands[2].isscalar)
14268 do_neon_mac_maybe_scalar ();
14269 else
dcbf9037 14270 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
14271}
14272
14273static void
14274do_neon_qdmulh (void)
14275{
14276 if (inst.operands[2].isscalar)
14277 {
037e8744 14278 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
14279 struct neon_type_el et = neon_check_type (3, rs,
14280 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14281 NEON_ENCODE (SCALAR, inst);
037e8744 14282 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14283 }
14284 else
14285 {
037e8744 14286 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14287 struct neon_type_el et = neon_check_type (3, rs,
14288 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14289 NEON_ENCODE (INTEGER, inst);
5287ad62 14290 /* The U bit (rounding) comes from bit mask. */
037e8744 14291 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14292 }
14293}
14294
14295static void
14296do_neon_fcmp_absolute (void)
14297{
037e8744 14298 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14299 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14300 /* Size field comes from bit mask. */
037e8744 14301 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
14302}
14303
14304static void
14305do_neon_fcmp_absolute_inv (void)
14306{
14307 neon_exchange_operands ();
14308 do_neon_fcmp_absolute ();
14309}
14310
14311static void
14312do_neon_step (void)
14313{
037e8744 14314 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14315 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 14316 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14317}
14318
14319static void
14320do_neon_abs_neg (void)
14321{
037e8744
JB
14322 enum neon_shape rs;
14323 struct neon_type_el et;
5f4273c7 14324
037e8744
JB
14325 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
14326 return;
14327
14328 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14329 return;
14330
14331 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14332 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 14333
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);
14337 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14338 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14339 inst.instruction |= (et.type == NT_float) << 10;
14340 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14341
88714cb8 14342 neon_dp_fixup (&inst);
5287ad62
JB
14343}
14344
14345static void
14346do_neon_sli (void)
14347{
037e8744 14348 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14349 struct neon_type_el et = neon_check_type (2, rs,
14350 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14351 int imm = inst.operands[2].imm;
14352 constraint (imm < 0 || (unsigned)imm >= et.size,
14353 _("immediate out of range for insert"));
037e8744 14354 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14355}
14356
14357static void
14358do_neon_sri (void)
14359{
037e8744 14360 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14361 struct neon_type_el et = neon_check_type (2, rs,
14362 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14363 int imm = inst.operands[2].imm;
14364 constraint (imm < 1 || (unsigned)imm > et.size,
14365 _("immediate out of range for insert"));
037e8744 14366 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
14367}
14368
14369static void
14370do_neon_qshlu_imm (void)
14371{
037e8744 14372 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14373 struct neon_type_el et = neon_check_type (2, rs,
14374 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14375 int imm = inst.operands[2].imm;
14376 constraint (imm < 0 || (unsigned)imm >= et.size,
14377 _("immediate out of range for shift"));
14378 /* Only encodes the 'U present' variant of the instruction.
14379 In this case, signed types have OP (bit 8) set to 0.
14380 Unsigned types have OP set to 1. */
14381 inst.instruction |= (et.type == NT_unsigned) << 8;
14382 /* The rest of the bits are the same as other immediate shifts. */
037e8744 14383 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14384}
14385
14386static void
14387do_neon_qmovn (void)
14388{
14389 struct neon_type_el et = neon_check_type (2, NS_DQ,
14390 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14391 /* Saturating move where operands can be signed or unsigned, and the
14392 destination has the same signedness. */
88714cb8 14393 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14394 if (et.type == NT_unsigned)
14395 inst.instruction |= 0xc0;
14396 else
14397 inst.instruction |= 0x80;
14398 neon_two_same (0, 1, et.size / 2);
14399}
14400
14401static void
14402do_neon_qmovun (void)
14403{
14404 struct neon_type_el et = neon_check_type (2, NS_DQ,
14405 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14406 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 14407 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14408 neon_two_same (0, 1, et.size / 2);
14409}
14410
14411static void
14412do_neon_rshift_sat_narrow (void)
14413{
14414 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14415 or unsigned. If operands are unsigned, results must also be unsigned. */
14416 struct neon_type_el et = neon_check_type (2, NS_DQI,
14417 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14418 int imm = inst.operands[2].imm;
14419 /* This gets the bounds check, size encoding and immediate bits calculation
14420 right. */
14421 et.size /= 2;
5f4273c7 14422
5287ad62
JB
14423 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14424 VQMOVN.I<size> <Dd>, <Qm>. */
14425 if (imm == 0)
14426 {
14427 inst.operands[2].present = 0;
14428 inst.instruction = N_MNEM_vqmovn;
14429 do_neon_qmovn ();
14430 return;
14431 }
5f4273c7 14432
5287ad62
JB
14433 constraint (imm < 1 || (unsigned)imm > et.size,
14434 _("immediate out of range"));
14435 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14436}
14437
14438static void
14439do_neon_rshift_sat_narrow_u (void)
14440{
14441 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14442 or unsigned. If operands are unsigned, results must also be unsigned. */
14443 struct neon_type_el et = neon_check_type (2, NS_DQI,
14444 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14445 int imm = inst.operands[2].imm;
14446 /* This gets the bounds check, size encoding and immediate bits calculation
14447 right. */
14448 et.size /= 2;
14449
14450 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14451 VQMOVUN.I<size> <Dd>, <Qm>. */
14452 if (imm == 0)
14453 {
14454 inst.operands[2].present = 0;
14455 inst.instruction = N_MNEM_vqmovun;
14456 do_neon_qmovun ();
14457 return;
14458 }
14459
14460 constraint (imm < 1 || (unsigned)imm > et.size,
14461 _("immediate out of range"));
14462 /* FIXME: The manual is kind of unclear about what value U should have in
14463 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
14464 must be 1. */
14465 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
14466}
14467
14468static void
14469do_neon_movn (void)
14470{
14471 struct neon_type_el et = neon_check_type (2, NS_DQ,
14472 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 14473 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14474 neon_two_same (0, 1, et.size / 2);
14475}
14476
14477static void
14478do_neon_rshift_narrow (void)
14479{
14480 struct neon_type_el et = neon_check_type (2, NS_DQI,
14481 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14482 int imm = inst.operands[2].imm;
14483 /* This gets the bounds check, size encoding and immediate bits calculation
14484 right. */
14485 et.size /= 2;
5f4273c7 14486
5287ad62
JB
14487 /* If immediate is zero then we are a pseudo-instruction for
14488 VMOVN.I<size> <Dd>, <Qm> */
14489 if (imm == 0)
14490 {
14491 inst.operands[2].present = 0;
14492 inst.instruction = N_MNEM_vmovn;
14493 do_neon_movn ();
14494 return;
14495 }
5f4273c7 14496
5287ad62
JB
14497 constraint (imm < 1 || (unsigned)imm > et.size,
14498 _("immediate out of range for narrowing operation"));
14499 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
14500}
14501
14502static void
14503do_neon_shll (void)
14504{
14505 /* FIXME: Type checking when lengthening. */
14506 struct neon_type_el et = neon_check_type (2, NS_QDI,
14507 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
14508 unsigned imm = inst.operands[2].imm;
14509
14510 if (imm == et.size)
14511 {
14512 /* Maximum shift variant. */
88714cb8 14513 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14514 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14515 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14516 inst.instruction |= LOW4 (inst.operands[1].reg);
14517 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14518 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14519
88714cb8 14520 neon_dp_fixup (&inst);
5287ad62
JB
14521 }
14522 else
14523 {
14524 /* A more-specific type check for non-max versions. */
14525 et = neon_check_type (2, NS_QDI,
14526 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 14527 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14528 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
14529 }
14530}
14531
037e8744 14532/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
14533 the current instruction is. */
14534
6b9a8b67
MGD
14535#define CVT_FLAVOUR_VAR \
14536 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
14537 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
14538 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
14539 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
14540 /* Half-precision conversions. */ \
14541 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
14542 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
14543 /* VFP instructions. */ \
14544 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
14545 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
14546 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
14547 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
14548 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
14549 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
14550 /* VFP instructions with bitshift. */ \
14551 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
14552 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
14553 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
14554 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
14555 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
14556 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
14557 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
14558 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
14559
14560#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
14561 neon_cvt_flavour_##C,
14562
14563/* The different types of conversions we can do. */
14564enum neon_cvt_flavour
14565{
14566 CVT_FLAVOUR_VAR
14567 neon_cvt_flavour_invalid,
14568 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
14569};
14570
14571#undef CVT_VAR
14572
14573static enum neon_cvt_flavour
14574get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 14575{
6b9a8b67
MGD
14576#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
14577 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
14578 if (et.type != NT_invtype) \
14579 { \
14580 inst.error = NULL; \
14581 return (neon_cvt_flavour_##C); \
5287ad62 14582 }
6b9a8b67 14583
5287ad62 14584 struct neon_type_el et;
037e8744
JB
14585 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
14586 || rs == NS_FF) ? N_VFP : 0;
14587 /* The instruction versions which take an immediate take one register
14588 argument, which is extended to the width of the full register. Thus the
14589 "source" and "destination" registers must have the same width. Hack that
14590 here by making the size equal to the key (wider, in this case) operand. */
14591 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 14592
6b9a8b67
MGD
14593 CVT_FLAVOUR_VAR;
14594
14595 return neon_cvt_flavour_invalid;
5287ad62
JB
14596#undef CVT_VAR
14597}
14598
7e8e6784
MGD
14599enum neon_cvt_mode
14600{
14601 neon_cvt_mode_a,
14602 neon_cvt_mode_n,
14603 neon_cvt_mode_p,
14604 neon_cvt_mode_m,
14605 neon_cvt_mode_z,
30bdf752
MGD
14606 neon_cvt_mode_x,
14607 neon_cvt_mode_r
7e8e6784
MGD
14608};
14609
037e8744
JB
14610/* Neon-syntax VFP conversions. */
14611
5287ad62 14612static void
6b9a8b67 14613do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 14614{
037e8744 14615 const char *opname = 0;
5f4273c7 14616
037e8744 14617 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 14618 {
037e8744
JB
14619 /* Conversions with immediate bitshift. */
14620 const char *enc[] =
14621 {
6b9a8b67
MGD
14622#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
14623 CVT_FLAVOUR_VAR
14624 NULL
14625#undef CVT_VAR
037e8744
JB
14626 };
14627
6b9a8b67 14628 if (flavour < (int) ARRAY_SIZE (enc))
037e8744
JB
14629 {
14630 opname = enc[flavour];
14631 constraint (inst.operands[0].reg != inst.operands[1].reg,
14632 _("operands 0 and 1 must be the same register"));
14633 inst.operands[1] = inst.operands[2];
14634 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
14635 }
5287ad62
JB
14636 }
14637 else
14638 {
037e8744
JB
14639 /* Conversions without bitshift. */
14640 const char *enc[] =
14641 {
6b9a8b67
MGD
14642#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
14643 CVT_FLAVOUR_VAR
14644 NULL
14645#undef CVT_VAR
037e8744
JB
14646 };
14647
6b9a8b67 14648 if (flavour < (int) ARRAY_SIZE (enc))
037e8744
JB
14649 opname = enc[flavour];
14650 }
14651
14652 if (opname)
14653 do_vfp_nsyn_opcode (opname);
14654}
14655
14656static void
14657do_vfp_nsyn_cvtz (void)
14658{
14659 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
6b9a8b67 14660 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
14661 const char *enc[] =
14662 {
6b9a8b67
MGD
14663#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
14664 CVT_FLAVOUR_VAR
14665 NULL
14666#undef CVT_VAR
037e8744
JB
14667 };
14668
6b9a8b67 14669 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
14670 do_vfp_nsyn_opcode (enc[flavour]);
14671}
f31fef98 14672
037e8744 14673static void
bacebabc 14674do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
14675 enum neon_cvt_mode mode)
14676{
14677 int sz, op;
14678 int rm;
14679
14680 set_it_insn_type (OUTSIDE_IT_INSN);
14681
14682 switch (flavour)
14683 {
14684 case neon_cvt_flavour_s32_f64:
14685 sz = 1;
14686 op = 0;
14687 break;
14688 case neon_cvt_flavour_s32_f32:
14689 sz = 0;
14690 op = 1;
14691 break;
14692 case neon_cvt_flavour_u32_f64:
14693 sz = 1;
14694 op = 0;
14695 break;
14696 case neon_cvt_flavour_u32_f32:
14697 sz = 0;
14698 op = 0;
14699 break;
14700 default:
14701 first_error (_("invalid instruction shape"));
14702 return;
14703 }
14704
14705 switch (mode)
14706 {
14707 case neon_cvt_mode_a: rm = 0; break;
14708 case neon_cvt_mode_n: rm = 1; break;
14709 case neon_cvt_mode_p: rm = 2; break;
14710 case neon_cvt_mode_m: rm = 3; break;
14711 default: first_error (_("invalid rounding mode")); return;
14712 }
14713
14714 NEON_ENCODE (FPV8, inst);
14715 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14716 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
14717 inst.instruction |= sz << 8;
14718 inst.instruction |= op << 7;
14719 inst.instruction |= rm << 16;
14720 inst.instruction |= 0xf0000000;
14721 inst.is_neon = TRUE;
14722}
14723
14724static void
14725do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
14726{
14727 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 14728 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
6b9a8b67 14729 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 14730
e3e535bc 14731 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 14732 if (mode == neon_cvt_mode_z
e3e535bc 14733 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
bacebabc
RM
14734 && (flavour == neon_cvt_flavour_s32_f32
14735 || flavour == neon_cvt_flavour_u32_f32
14736 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 14737 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
14738 && (rs == NS_FD || rs == NS_FF))
14739 {
14740 do_vfp_nsyn_cvtz ();
14741 return;
14742 }
14743
037e8744 14744 /* VFP rather than Neon conversions. */
6b9a8b67 14745 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 14746 {
7e8e6784
MGD
14747 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
14748 do_vfp_nsyn_cvt (rs, flavour);
14749 else
14750 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
14751
037e8744
JB
14752 return;
14753 }
14754
14755 switch (rs)
14756 {
14757 case NS_DDI:
14758 case NS_QQI:
14759 {
35997600
NC
14760 unsigned immbits;
14761 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
14762
037e8744
JB
14763 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14764 return;
14765
14766 /* Fixed-point conversion with #0 immediate is encoded as an
14767 integer conversion. */
14768 if (inst.operands[2].present && inst.operands[2].imm == 0)
14769 goto int_encode;
35997600 14770 immbits = 32 - inst.operands[2].imm;
88714cb8 14771 NEON_ENCODE (IMMED, inst);
6b9a8b67 14772 if (flavour != neon_cvt_flavour_invalid)
037e8744
JB
14773 inst.instruction |= enctab[flavour];
14774 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14775 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14776 inst.instruction |= LOW4 (inst.operands[1].reg);
14777 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14778 inst.instruction |= neon_quad (rs) << 6;
14779 inst.instruction |= 1 << 21;
14780 inst.instruction |= immbits << 16;
14781
88714cb8 14782 neon_dp_fixup (&inst);
037e8744
JB
14783 }
14784 break;
14785
14786 case NS_DD:
14787 case NS_QQ:
7e8e6784
MGD
14788 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
14789 {
14790 NEON_ENCODE (FLOAT, inst);
14791 set_it_insn_type (OUTSIDE_IT_INSN);
14792
14793 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
14794 return;
14795
14796 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14797 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14798 inst.instruction |= LOW4 (inst.operands[1].reg);
14799 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14800 inst.instruction |= neon_quad (rs) << 6;
14801 inst.instruction |= (flavour == neon_cvt_flavour_u32_f32) << 7;
14802 inst.instruction |= mode << 8;
14803 if (thumb_mode)
14804 inst.instruction |= 0xfc000000;
14805 else
14806 inst.instruction |= 0xf0000000;
14807 }
14808 else
14809 {
037e8744 14810 int_encode:
7e8e6784
MGD
14811 {
14812 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
037e8744 14813
7e8e6784 14814 NEON_ENCODE (INTEGER, inst);
037e8744 14815
7e8e6784
MGD
14816 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14817 return;
037e8744 14818
7e8e6784
MGD
14819 if (flavour != neon_cvt_flavour_invalid)
14820 inst.instruction |= enctab[flavour];
037e8744 14821
7e8e6784
MGD
14822 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14823 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14824 inst.instruction |= LOW4 (inst.operands[1].reg);
14825 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14826 inst.instruction |= neon_quad (rs) << 6;
14827 inst.instruction |= 2 << 18;
037e8744 14828
7e8e6784
MGD
14829 neon_dp_fixup (&inst);
14830 }
14831 }
14832 break;
037e8744 14833
8e79c3df
CM
14834 /* Half-precision conversions for Advanced SIMD -- neon. */
14835 case NS_QD:
14836 case NS_DQ:
14837
14838 if ((rs == NS_DQ)
14839 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14840 {
14841 as_bad (_("operand size must match register width"));
14842 break;
14843 }
14844
14845 if ((rs == NS_QD)
14846 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14847 {
14848 as_bad (_("operand size must match register width"));
14849 break;
14850 }
14851
14852 if (rs == NS_DQ)
14853 inst.instruction = 0x3b60600;
14854 else
14855 inst.instruction = 0x3b60700;
14856
14857 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14858 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14859 inst.instruction |= LOW4 (inst.operands[1].reg);
14860 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 14861 neon_dp_fixup (&inst);
8e79c3df
CM
14862 break;
14863
037e8744
JB
14864 default:
14865 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
14866 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
14867 do_vfp_nsyn_cvt (rs, flavour);
14868 else
14869 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 14870 }
5287ad62
JB
14871}
14872
e3e535bc
NC
14873static void
14874do_neon_cvtr (void)
14875{
7e8e6784 14876 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
14877}
14878
14879static void
14880do_neon_cvt (void)
14881{
7e8e6784
MGD
14882 do_neon_cvt_1 (neon_cvt_mode_z);
14883}
14884
14885static void
14886do_neon_cvta (void)
14887{
14888 do_neon_cvt_1 (neon_cvt_mode_a);
14889}
14890
14891static void
14892do_neon_cvtn (void)
14893{
14894 do_neon_cvt_1 (neon_cvt_mode_n);
14895}
14896
14897static void
14898do_neon_cvtp (void)
14899{
14900 do_neon_cvt_1 (neon_cvt_mode_p);
14901}
14902
14903static void
14904do_neon_cvtm (void)
14905{
14906 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
14907}
14908
8e79c3df 14909static void
c70a8987 14910do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 14911{
c70a8987
MGD
14912 if (is_double)
14913 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 14914
c70a8987
MGD
14915 encode_arm_vfp_reg (inst.operands[0].reg,
14916 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
14917 encode_arm_vfp_reg (inst.operands[1].reg,
14918 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
14919 inst.instruction |= to ? 0x10000 : 0;
14920 inst.instruction |= t ? 0x80 : 0;
14921 inst.instruction |= is_double ? 0x100 : 0;
14922 do_vfp_cond_or_thumb ();
14923}
8e79c3df 14924
c70a8987
MGD
14925static void
14926do_neon_cvttb_1 (bfd_boolean t)
14927{
14928 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_DF, NS_NULL);
8e79c3df 14929
c70a8987
MGD
14930 if (rs == NS_NULL)
14931 return;
14932 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
14933 {
14934 inst.error = NULL;
14935 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
14936 }
14937 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
14938 {
14939 inst.error = NULL;
14940 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
14941 }
14942 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
14943 {
14944 inst.error = NULL;
14945 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
14946 }
14947 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
14948 {
14949 inst.error = NULL;
14950 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
14951 }
14952 else
14953 return;
14954}
14955
14956static void
14957do_neon_cvtb (void)
14958{
14959 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
14960}
14961
14962
14963static void
14964do_neon_cvtt (void)
14965{
c70a8987 14966 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
14967}
14968
5287ad62
JB
14969static void
14970neon_move_immediate (void)
14971{
037e8744
JB
14972 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14973 struct neon_type_el et = neon_check_type (2, rs,
14974 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 14975 unsigned immlo, immhi = 0, immbits;
c96612cc 14976 int op, cmode, float_p;
5287ad62 14977
037e8744
JB
14978 constraint (et.type == NT_invtype,
14979 _("operand size must be specified for immediate VMOV"));
14980
5287ad62
JB
14981 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14982 op = (inst.instruction & (1 << 5)) != 0;
14983
14984 immlo = inst.operands[1].imm;
14985 if (inst.operands[1].regisimm)
14986 immhi = inst.operands[1].reg;
14987
14988 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14989 _("immediate has bits set outside the operand size"));
14990
c96612cc
JB
14991 float_p = inst.operands[1].immisfloat;
14992
14993 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 14994 et.size, et.type)) == FAIL)
5287ad62
JB
14995 {
14996 /* Invert relevant bits only. */
14997 neon_invert_size (&immlo, &immhi, et.size);
14998 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14999 with one or the other; those cases are caught by
15000 neon_cmode_for_move_imm. */
15001 op = !op;
c96612cc
JB
15002 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15003 &op, et.size, et.type)) == FAIL)
5287ad62 15004 {
dcbf9037 15005 first_error (_("immediate out of range"));
5287ad62
JB
15006 return;
15007 }
15008 }
15009
15010 inst.instruction &= ~(1 << 5);
15011 inst.instruction |= op << 5;
15012
15013 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15014 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 15015 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15016 inst.instruction |= cmode << 8;
15017
15018 neon_write_immbits (immbits);
15019}
15020
15021static void
15022do_neon_mvn (void)
15023{
15024 if (inst.operands[1].isreg)
15025 {
037e8744 15026 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 15027
88714cb8 15028 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15029 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15030 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15031 inst.instruction |= LOW4 (inst.operands[1].reg);
15032 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15033 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15034 }
15035 else
15036 {
88714cb8 15037 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15038 neon_move_immediate ();
15039 }
15040
88714cb8 15041 neon_dp_fixup (&inst);
5287ad62
JB
15042}
15043
15044/* Encode instructions of form:
15045
15046 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 15047 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
15048
15049static void
15050neon_mixed_length (struct neon_type_el et, unsigned size)
15051{
15052 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15053 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15054 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15055 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15056 inst.instruction |= LOW4 (inst.operands[2].reg);
15057 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15058 inst.instruction |= (et.type == NT_unsigned) << 24;
15059 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 15060
88714cb8 15061 neon_dp_fixup (&inst);
5287ad62
JB
15062}
15063
15064static void
15065do_neon_dyadic_long (void)
15066{
15067 /* FIXME: Type checking for lengthening op. */
15068 struct neon_type_el et = neon_check_type (3, NS_QDD,
15069 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
15070 neon_mixed_length (et, et.size);
15071}
15072
15073static void
15074do_neon_abal (void)
15075{
15076 struct neon_type_el et = neon_check_type (3, NS_QDD,
15077 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
15078 neon_mixed_length (et, et.size);
15079}
15080
15081static void
15082neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
15083{
15084 if (inst.operands[2].isscalar)
15085 {
dcbf9037
JB
15086 struct neon_type_el et = neon_check_type (3, NS_QDS,
15087 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 15088 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15089 neon_mul_mac (et, et.type == NT_unsigned);
15090 }
15091 else
15092 {
15093 struct neon_type_el et = neon_check_type (3, NS_QDD,
15094 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 15095 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15096 neon_mixed_length (et, et.size);
15097 }
15098}
15099
15100static void
15101do_neon_mac_maybe_scalar_long (void)
15102{
15103 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
15104}
15105
15106static void
15107do_neon_dyadic_wide (void)
15108{
15109 struct neon_type_el et = neon_check_type (3, NS_QQD,
15110 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
15111 neon_mixed_length (et, et.size);
15112}
15113
15114static void
15115do_neon_dyadic_narrow (void)
15116{
15117 struct neon_type_el et = neon_check_type (3, NS_QDD,
15118 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
15119 /* Operand sign is unimportant, and the U bit is part of the opcode,
15120 so force the operand type to integer. */
15121 et.type = NT_integer;
5287ad62
JB
15122 neon_mixed_length (et, et.size / 2);
15123}
15124
15125static void
15126do_neon_mul_sat_scalar_long (void)
15127{
15128 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
15129}
15130
15131static void
15132do_neon_vmull (void)
15133{
15134 if (inst.operands[2].isscalar)
15135 do_neon_mac_maybe_scalar_long ();
15136 else
15137 {
15138 struct neon_type_el et = neon_check_type (3, NS_QDD,
4f51b4bd
MGD
15139 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
15140
5287ad62 15141 if (et.type == NT_poly)
88714cb8 15142 NEON_ENCODE (POLY, inst);
5287ad62 15143 else
88714cb8 15144 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
15145
15146 /* For polynomial encoding the U bit must be zero, and the size must
15147 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
15148 obviously, as 0b10). */
15149 if (et.size == 64)
15150 {
15151 /* Check we're on the correct architecture. */
15152 if (!mark_feature_used (&fpu_crypto_ext_armv8))
15153 inst.error =
15154 _("Instruction form not available on this architecture.");
15155
15156 et.size = 32;
15157 }
15158
5287ad62
JB
15159 neon_mixed_length (et, et.size);
15160 }
15161}
15162
15163static void
15164do_neon_ext (void)
15165{
037e8744 15166 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
15167 struct neon_type_el et = neon_check_type (3, rs,
15168 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15169 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
15170
15171 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
15172 _("shift out of range"));
5287ad62
JB
15173 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15174 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15175 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15176 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15177 inst.instruction |= LOW4 (inst.operands[2].reg);
15178 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 15179 inst.instruction |= neon_quad (rs) << 6;
5287ad62 15180 inst.instruction |= imm << 8;
5f4273c7 15181
88714cb8 15182 neon_dp_fixup (&inst);
5287ad62
JB
15183}
15184
15185static void
15186do_neon_rev (void)
15187{
037e8744 15188 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15189 struct neon_type_el et = neon_check_type (2, rs,
15190 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15191 unsigned op = (inst.instruction >> 7) & 3;
15192 /* N (width of reversed regions) is encoded as part of the bitmask. We
15193 extract it here to check the elements to be reversed are smaller.
15194 Otherwise we'd get a reserved instruction. */
15195 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 15196 gas_assert (elsize != 0);
5287ad62
JB
15197 constraint (et.size >= elsize,
15198 _("elements must be smaller than reversal region"));
037e8744 15199 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15200}
15201
15202static void
15203do_neon_dup (void)
15204{
15205 if (inst.operands[1].isscalar)
15206 {
037e8744 15207 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
15208 struct neon_type_el et = neon_check_type (2, rs,
15209 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 15210 unsigned sizebits = et.size >> 3;
dcbf9037 15211 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 15212 int logsize = neon_logbits (et.size);
dcbf9037 15213 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
15214
15215 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
15216 return;
15217
88714cb8 15218 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15219 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15220 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15221 inst.instruction |= LOW4 (dm);
15222 inst.instruction |= HI1 (dm) << 5;
037e8744 15223 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15224 inst.instruction |= x << 17;
15225 inst.instruction |= sizebits << 16;
5f4273c7 15226
88714cb8 15227 neon_dp_fixup (&inst);
5287ad62
JB
15228 }
15229 else
15230 {
037e8744
JB
15231 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
15232 struct neon_type_el et = neon_check_type (2, rs,
15233 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 15234 /* Duplicate ARM register to lanes of vector. */
88714cb8 15235 NEON_ENCODE (ARMREG, inst);
5287ad62
JB
15236 switch (et.size)
15237 {
15238 case 8: inst.instruction |= 0x400000; break;
15239 case 16: inst.instruction |= 0x000020; break;
15240 case 32: inst.instruction |= 0x000000; break;
15241 default: break;
15242 }
15243 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15244 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
15245 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 15246 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
15247 /* The encoding for this instruction is identical for the ARM and Thumb
15248 variants, except for the condition field. */
037e8744 15249 do_vfp_cond_or_thumb ();
5287ad62
JB
15250 }
15251}
15252
15253/* VMOV has particularly many variations. It can be one of:
15254 0. VMOV<c><q> <Qd>, <Qm>
15255 1. VMOV<c><q> <Dd>, <Dm>
15256 (Register operations, which are VORR with Rm = Rn.)
15257 2. VMOV<c><q>.<dt> <Qd>, #<imm>
15258 3. VMOV<c><q>.<dt> <Dd>, #<imm>
15259 (Immediate loads.)
15260 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
15261 (ARM register to scalar.)
15262 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
15263 (Two ARM registers to vector.)
15264 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
15265 (Scalar to ARM register.)
15266 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
15267 (Vector to two ARM registers.)
037e8744
JB
15268 8. VMOV.F32 <Sd>, <Sm>
15269 9. VMOV.F64 <Dd>, <Dm>
15270 (VFP register moves.)
15271 10. VMOV.F32 <Sd>, #imm
15272 11. VMOV.F64 <Dd>, #imm
15273 (VFP float immediate load.)
15274 12. VMOV <Rd>, <Sm>
15275 (VFP single to ARM reg.)
15276 13. VMOV <Sd>, <Rm>
15277 (ARM reg to VFP single.)
15278 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
15279 (Two ARM regs to two VFP singles.)
15280 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
15281 (Two VFP singles to two ARM regs.)
5f4273c7 15282
037e8744
JB
15283 These cases can be disambiguated using neon_select_shape, except cases 1/9
15284 and 3/11 which depend on the operand type too.
5f4273c7 15285
5287ad62 15286 All the encoded bits are hardcoded by this function.
5f4273c7 15287
b7fc2769
JB
15288 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
15289 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 15290
5287ad62 15291 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 15292 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
15293
15294static void
15295do_neon_mov (void)
15296{
037e8744
JB
15297 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
15298 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
15299 NS_NULL);
15300 struct neon_type_el et;
15301 const char *ldconst = 0;
5287ad62 15302
037e8744 15303 switch (rs)
5287ad62 15304 {
037e8744
JB
15305 case NS_DD: /* case 1/9. */
15306 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15307 /* It is not an error here if no type is given. */
15308 inst.error = NULL;
15309 if (et.type == NT_float && et.size == 64)
5287ad62 15310 {
037e8744
JB
15311 do_vfp_nsyn_opcode ("fcpyd");
15312 break;
5287ad62 15313 }
037e8744 15314 /* fall through. */
5287ad62 15315
037e8744
JB
15316 case NS_QQ: /* case 0/1. */
15317 {
15318 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15319 return;
15320 /* The architecture manual I have doesn't explicitly state which
15321 value the U bit should have for register->register moves, but
15322 the equivalent VORR instruction has U = 0, so do that. */
15323 inst.instruction = 0x0200110;
15324 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15325 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15326 inst.instruction |= LOW4 (inst.operands[1].reg);
15327 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15328 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15329 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15330 inst.instruction |= neon_quad (rs) << 6;
15331
88714cb8 15332 neon_dp_fixup (&inst);
037e8744
JB
15333 }
15334 break;
5f4273c7 15335
037e8744
JB
15336 case NS_DI: /* case 3/11. */
15337 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15338 inst.error = NULL;
15339 if (et.type == NT_float && et.size == 64)
5287ad62 15340 {
037e8744
JB
15341 /* case 11 (fconstd). */
15342 ldconst = "fconstd";
15343 goto encode_fconstd;
5287ad62 15344 }
037e8744
JB
15345 /* fall through. */
15346
15347 case NS_QI: /* case 2/3. */
15348 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15349 return;
15350 inst.instruction = 0x0800010;
15351 neon_move_immediate ();
88714cb8 15352 neon_dp_fixup (&inst);
5287ad62 15353 break;
5f4273c7 15354
037e8744
JB
15355 case NS_SR: /* case 4. */
15356 {
15357 unsigned bcdebits = 0;
91d6fa6a 15358 int logsize;
037e8744
JB
15359 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
15360 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
15361
91d6fa6a
NC
15362 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
15363 logsize = neon_logbits (et.size);
15364
037e8744
JB
15365 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15366 _(BAD_FPU));
15367 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15368 && et.size != 32, _(BAD_FPU));
15369 constraint (et.type == NT_invtype, _("bad type for scalar"));
15370 constraint (x >= 64 / et.size, _("scalar index out of range"));
15371
15372 switch (et.size)
15373 {
15374 case 8: bcdebits = 0x8; break;
15375 case 16: bcdebits = 0x1; break;
15376 case 32: bcdebits = 0x0; break;
15377 default: ;
15378 }
15379
15380 bcdebits |= x << logsize;
15381
15382 inst.instruction = 0xe000b10;
15383 do_vfp_cond_or_thumb ();
15384 inst.instruction |= LOW4 (dn) << 16;
15385 inst.instruction |= HI1 (dn) << 7;
15386 inst.instruction |= inst.operands[1].reg << 12;
15387 inst.instruction |= (bcdebits & 3) << 5;
15388 inst.instruction |= (bcdebits >> 2) << 21;
15389 }
15390 break;
5f4273c7 15391
037e8744 15392 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 15393 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 15394 _(BAD_FPU));
b7fc2769 15395
037e8744
JB
15396 inst.instruction = 0xc400b10;
15397 do_vfp_cond_or_thumb ();
15398 inst.instruction |= LOW4 (inst.operands[0].reg);
15399 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
15400 inst.instruction |= inst.operands[1].reg << 12;
15401 inst.instruction |= inst.operands[2].reg << 16;
15402 break;
5f4273c7 15403
037e8744
JB
15404 case NS_RS: /* case 6. */
15405 {
91d6fa6a 15406 unsigned logsize;
037e8744
JB
15407 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
15408 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
15409 unsigned abcdebits = 0;
15410
91d6fa6a
NC
15411 et = neon_check_type (2, NS_NULL,
15412 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
15413 logsize = neon_logbits (et.size);
15414
037e8744
JB
15415 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15416 _(BAD_FPU));
15417 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15418 && et.size != 32, _(BAD_FPU));
15419 constraint (et.type == NT_invtype, _("bad type for scalar"));
15420 constraint (x >= 64 / et.size, _("scalar index out of range"));
15421
15422 switch (et.size)
15423 {
15424 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
15425 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
15426 case 32: abcdebits = 0x00; break;
15427 default: ;
15428 }
15429
15430 abcdebits |= x << logsize;
15431 inst.instruction = 0xe100b10;
15432 do_vfp_cond_or_thumb ();
15433 inst.instruction |= LOW4 (dn) << 16;
15434 inst.instruction |= HI1 (dn) << 7;
15435 inst.instruction |= inst.operands[0].reg << 12;
15436 inst.instruction |= (abcdebits & 3) << 5;
15437 inst.instruction |= (abcdebits >> 2) << 21;
15438 }
15439 break;
5f4273c7 15440
037e8744
JB
15441 case NS_RRD: /* case 7 (fmrrd). */
15442 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
15443 _(BAD_FPU));
15444
15445 inst.instruction = 0xc500b10;
15446 do_vfp_cond_or_thumb ();
15447 inst.instruction |= inst.operands[0].reg << 12;
15448 inst.instruction |= inst.operands[1].reg << 16;
15449 inst.instruction |= LOW4 (inst.operands[2].reg);
15450 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15451 break;
5f4273c7 15452
037e8744
JB
15453 case NS_FF: /* case 8 (fcpys). */
15454 do_vfp_nsyn_opcode ("fcpys");
15455 break;
5f4273c7 15456
037e8744
JB
15457 case NS_FI: /* case 10 (fconsts). */
15458 ldconst = "fconsts";
15459 encode_fconstd:
15460 if (is_quarter_float (inst.operands[1].imm))
5287ad62 15461 {
037e8744
JB
15462 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
15463 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
15464 }
15465 else
037e8744
JB
15466 first_error (_("immediate out of range"));
15467 break;
5f4273c7 15468
037e8744
JB
15469 case NS_RF: /* case 12 (fmrs). */
15470 do_vfp_nsyn_opcode ("fmrs");
15471 break;
5f4273c7 15472
037e8744
JB
15473 case NS_FR: /* case 13 (fmsr). */
15474 do_vfp_nsyn_opcode ("fmsr");
15475 break;
5f4273c7 15476
037e8744
JB
15477 /* The encoders for the fmrrs and fmsrr instructions expect three operands
15478 (one of which is a list), but we have parsed four. Do some fiddling to
15479 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
15480 expect. */
15481 case NS_RRFF: /* case 14 (fmrrs). */
15482 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
15483 _("VFP registers must be adjacent"));
15484 inst.operands[2].imm = 2;
15485 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15486 do_vfp_nsyn_opcode ("fmrrs");
15487 break;
5f4273c7 15488
037e8744
JB
15489 case NS_FFRR: /* case 15 (fmsrr). */
15490 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
15491 _("VFP registers must be adjacent"));
15492 inst.operands[1] = inst.operands[2];
15493 inst.operands[2] = inst.operands[3];
15494 inst.operands[0].imm = 2;
15495 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15496 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 15497 break;
5f4273c7 15498
5287ad62
JB
15499 default:
15500 abort ();
15501 }
15502}
15503
15504static void
15505do_neon_rshift_round_imm (void)
15506{
037e8744 15507 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15508 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
15509 int imm = inst.operands[2].imm;
15510
15511 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
15512 if (imm == 0)
15513 {
15514 inst.operands[2].present = 0;
15515 do_neon_mov ();
15516 return;
15517 }
15518
15519 constraint (imm < 1 || (unsigned)imm > et.size,
15520 _("immediate out of range for shift"));
037e8744 15521 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
15522 et.size - imm);
15523}
15524
15525static void
15526do_neon_movl (void)
15527{
15528 struct neon_type_el et = neon_check_type (2, NS_QD,
15529 N_EQK | N_DBL, N_SU_32 | N_KEY);
15530 unsigned sizebits = et.size >> 3;
15531 inst.instruction |= sizebits << 19;
15532 neon_two_same (0, et.type == NT_unsigned, -1);
15533}
15534
15535static void
15536do_neon_trn (void)
15537{
037e8744 15538 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15539 struct neon_type_el et = neon_check_type (2, rs,
15540 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 15541 NEON_ENCODE (INTEGER, inst);
037e8744 15542 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15543}
15544
15545static void
15546do_neon_zip_uzp (void)
15547{
037e8744 15548 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15549 struct neon_type_el et = neon_check_type (2, rs,
15550 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15551 if (rs == NS_DD && et.size == 32)
15552 {
15553 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
15554 inst.instruction = N_MNEM_vtrn;
15555 do_neon_trn ();
15556 return;
15557 }
037e8744 15558 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15559}
15560
15561static void
15562do_neon_sat_abs_neg (void)
15563{
037e8744 15564 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15565 struct neon_type_el et = neon_check_type (2, rs,
15566 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 15567 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15568}
15569
15570static void
15571do_neon_pair_long (void)
15572{
037e8744 15573 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15574 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
15575 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
15576 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 15577 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15578}
15579
15580static void
15581do_neon_recip_est (void)
15582{
037e8744 15583 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15584 struct neon_type_el et = neon_check_type (2, rs,
15585 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
15586 inst.instruction |= (et.type == NT_float) << 8;
037e8744 15587 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15588}
15589
15590static void
15591do_neon_cls (void)
15592{
037e8744 15593 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15594 struct neon_type_el et = neon_check_type (2, rs,
15595 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 15596 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15597}
15598
15599static void
15600do_neon_clz (void)
15601{
037e8744 15602 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15603 struct neon_type_el et = neon_check_type (2, rs,
15604 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 15605 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15606}
15607
15608static void
15609do_neon_cnt (void)
15610{
037e8744 15611 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15612 struct neon_type_el et = neon_check_type (2, rs,
15613 N_EQK | N_INT, N_8 | N_KEY);
037e8744 15614 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15615}
15616
15617static void
15618do_neon_swp (void)
15619{
037e8744
JB
15620 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15621 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
15622}
15623
15624static void
15625do_neon_tbl_tbx (void)
15626{
15627 unsigned listlenbits;
dcbf9037 15628 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 15629
5287ad62
JB
15630 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
15631 {
dcbf9037 15632 first_error (_("bad list length for table lookup"));
5287ad62
JB
15633 return;
15634 }
5f4273c7 15635
5287ad62
JB
15636 listlenbits = inst.operands[1].imm - 1;
15637 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15638 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15639 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15640 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15641 inst.instruction |= LOW4 (inst.operands[2].reg);
15642 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15643 inst.instruction |= listlenbits << 8;
5f4273c7 15644
88714cb8 15645 neon_dp_fixup (&inst);
5287ad62
JB
15646}
15647
15648static void
15649do_neon_ldm_stm (void)
15650{
15651 /* P, U and L bits are part of bitmask. */
15652 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
15653 unsigned offsetbits = inst.operands[1].imm * 2;
15654
037e8744
JB
15655 if (inst.operands[1].issingle)
15656 {
15657 do_vfp_nsyn_ldm_stm (is_dbmode);
15658 return;
15659 }
15660
5287ad62
JB
15661 constraint (is_dbmode && !inst.operands[0].writeback,
15662 _("writeback (!) must be used for VLDMDB and VSTMDB"));
15663
15664 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15665 _("register list must contain at least 1 and at most 16 "
15666 "registers"));
15667
15668 inst.instruction |= inst.operands[0].reg << 16;
15669 inst.instruction |= inst.operands[0].writeback << 21;
15670 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15671 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
15672
15673 inst.instruction |= offsetbits;
5f4273c7 15674
037e8744 15675 do_vfp_cond_or_thumb ();
5287ad62
JB
15676}
15677
15678static void
15679do_neon_ldr_str (void)
15680{
5287ad62 15681 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 15682
6844b2c2
MGD
15683 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
15684 And is UNPREDICTABLE in thumb mode. */
fa94de6b 15685 if (!is_ldr
6844b2c2
MGD
15686 && inst.operands[1].reg == REG_PC
15687 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
15688 {
15689 if (!thumb_mode && warn_on_deprecated)
15690 as_warn (_("Use of PC here is deprecated"));
15691 else
15692 inst.error = _("Use of PC here is UNPREDICTABLE");
15693 }
15694
037e8744
JB
15695 if (inst.operands[0].issingle)
15696 {
cd2f129f
JB
15697 if (is_ldr)
15698 do_vfp_nsyn_opcode ("flds");
15699 else
15700 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
15701 }
15702 else
5287ad62 15703 {
cd2f129f
JB
15704 if (is_ldr)
15705 do_vfp_nsyn_opcode ("fldd");
5287ad62 15706 else
cd2f129f 15707 do_vfp_nsyn_opcode ("fstd");
5287ad62 15708 }
5287ad62
JB
15709}
15710
15711/* "interleave" version also handles non-interleaving register VLD1/VST1
15712 instructions. */
15713
15714static void
15715do_neon_ld_st_interleave (void)
15716{
037e8744 15717 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
15718 N_8 | N_16 | N_32 | N_64);
15719 unsigned alignbits = 0;
15720 unsigned idx;
15721 /* The bits in this table go:
15722 0: register stride of one (0) or two (1)
15723 1,2: register list length, minus one (1, 2, 3, 4).
15724 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
15725 We use -1 for invalid entries. */
15726 const int typetable[] =
15727 {
15728 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
15729 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
15730 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
15731 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
15732 };
15733 int typebits;
15734
dcbf9037
JB
15735 if (et.type == NT_invtype)
15736 return;
15737
5287ad62
JB
15738 if (inst.operands[1].immisalign)
15739 switch (inst.operands[1].imm >> 8)
15740 {
15741 case 64: alignbits = 1; break;
15742 case 128:
e23c0ad8
JZ
15743 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
15744 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
15745 goto bad_alignment;
15746 alignbits = 2;
15747 break;
15748 case 256:
e23c0ad8 15749 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
15750 goto bad_alignment;
15751 alignbits = 3;
15752 break;
15753 default:
15754 bad_alignment:
dcbf9037 15755 first_error (_("bad alignment"));
5287ad62
JB
15756 return;
15757 }
15758
15759 inst.instruction |= alignbits << 4;
15760 inst.instruction |= neon_logbits (et.size) << 6;
15761
15762 /* Bits [4:6] of the immediate in a list specifier encode register stride
15763 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
15764 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
15765 up the right value for "type" in a table based on this value and the given
15766 list style, then stick it back. */
15767 idx = ((inst.operands[0].imm >> 4) & 7)
15768 | (((inst.instruction >> 8) & 3) << 3);
15769
15770 typebits = typetable[idx];
5f4273c7 15771
5287ad62
JB
15772 constraint (typebits == -1, _("bad list type for instruction"));
15773
15774 inst.instruction &= ~0xf00;
15775 inst.instruction |= typebits << 8;
15776}
15777
15778/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
15779 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
15780 otherwise. The variable arguments are a list of pairs of legal (size, align)
15781 values, terminated with -1. */
15782
15783static int
15784neon_alignment_bit (int size, int align, int *do_align, ...)
15785{
15786 va_list ap;
15787 int result = FAIL, thissize, thisalign;
5f4273c7 15788
5287ad62
JB
15789 if (!inst.operands[1].immisalign)
15790 {
15791 *do_align = 0;
15792 return SUCCESS;
15793 }
5f4273c7 15794
5287ad62
JB
15795 va_start (ap, do_align);
15796
15797 do
15798 {
15799 thissize = va_arg (ap, int);
15800 if (thissize == -1)
15801 break;
15802 thisalign = va_arg (ap, int);
15803
15804 if (size == thissize && align == thisalign)
15805 result = SUCCESS;
15806 }
15807 while (result != SUCCESS);
15808
15809 va_end (ap);
15810
15811 if (result == SUCCESS)
15812 *do_align = 1;
15813 else
dcbf9037 15814 first_error (_("unsupported alignment for instruction"));
5f4273c7 15815
5287ad62
JB
15816 return result;
15817}
15818
15819static void
15820do_neon_ld_st_lane (void)
15821{
037e8744 15822 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15823 int align_good, do_align = 0;
15824 int logsize = neon_logbits (et.size);
15825 int align = inst.operands[1].imm >> 8;
15826 int n = (inst.instruction >> 8) & 3;
15827 int max_el = 64 / et.size;
5f4273c7 15828
dcbf9037
JB
15829 if (et.type == NT_invtype)
15830 return;
5f4273c7 15831
5287ad62
JB
15832 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
15833 _("bad list length"));
15834 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
15835 _("scalar index out of range"));
15836 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
15837 && et.size == 8,
15838 _("stride of 2 unavailable when element size is 8"));
5f4273c7 15839
5287ad62
JB
15840 switch (n)
15841 {
15842 case 0: /* VLD1 / VST1. */
15843 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
15844 32, 32, -1);
15845 if (align_good == FAIL)
15846 return;
15847 if (do_align)
15848 {
15849 unsigned alignbits = 0;
15850 switch (et.size)
15851 {
15852 case 16: alignbits = 0x1; break;
15853 case 32: alignbits = 0x3; break;
15854 default: ;
15855 }
15856 inst.instruction |= alignbits << 4;
15857 }
15858 break;
15859
15860 case 1: /* VLD2 / VST2. */
15861 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
15862 32, 64, -1);
15863 if (align_good == FAIL)
15864 return;
15865 if (do_align)
15866 inst.instruction |= 1 << 4;
15867 break;
15868
15869 case 2: /* VLD3 / VST3. */
15870 constraint (inst.operands[1].immisalign,
15871 _("can't use alignment with this instruction"));
15872 break;
15873
15874 case 3: /* VLD4 / VST4. */
15875 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15876 16, 64, 32, 64, 32, 128, -1);
15877 if (align_good == FAIL)
15878 return;
15879 if (do_align)
15880 {
15881 unsigned alignbits = 0;
15882 switch (et.size)
15883 {
15884 case 8: alignbits = 0x1; break;
15885 case 16: alignbits = 0x1; break;
15886 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
15887 default: ;
15888 }
15889 inst.instruction |= alignbits << 4;
15890 }
15891 break;
15892
15893 default: ;
15894 }
15895
15896 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
15897 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15898 inst.instruction |= 1 << (4 + logsize);
5f4273c7 15899
5287ad62
JB
15900 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
15901 inst.instruction |= logsize << 10;
15902}
15903
15904/* Encode single n-element structure to all lanes VLD<n> instructions. */
15905
15906static void
15907do_neon_ld_dup (void)
15908{
037e8744 15909 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15910 int align_good, do_align = 0;
15911
dcbf9037
JB
15912 if (et.type == NT_invtype)
15913 return;
15914
5287ad62
JB
15915 switch ((inst.instruction >> 8) & 3)
15916 {
15917 case 0: /* VLD1. */
9c2799c2 15918 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
15919 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15920 &do_align, 16, 16, 32, 32, -1);
15921 if (align_good == FAIL)
15922 return;
15923 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15924 {
15925 case 1: break;
15926 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 15927 default: first_error (_("bad list length")); return;
5287ad62
JB
15928 }
15929 inst.instruction |= neon_logbits (et.size) << 6;
15930 break;
15931
15932 case 1: /* VLD2. */
15933 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15934 &do_align, 8, 16, 16, 32, 32, 64, -1);
15935 if (align_good == FAIL)
15936 return;
15937 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15938 _("bad list length"));
15939 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15940 inst.instruction |= 1 << 5;
15941 inst.instruction |= neon_logbits (et.size) << 6;
15942 break;
15943
15944 case 2: /* VLD3. */
15945 constraint (inst.operands[1].immisalign,
15946 _("can't use alignment with this instruction"));
15947 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15948 _("bad list length"));
15949 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15950 inst.instruction |= 1 << 5;
15951 inst.instruction |= neon_logbits (et.size) << 6;
15952 break;
15953
15954 case 3: /* VLD4. */
15955 {
15956 int align = inst.operands[1].imm >> 8;
15957 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15958 16, 64, 32, 64, 32, 128, -1);
15959 if (align_good == FAIL)
15960 return;
15961 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15962 _("bad list length"));
15963 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15964 inst.instruction |= 1 << 5;
15965 if (et.size == 32 && align == 128)
15966 inst.instruction |= 0x3 << 6;
15967 else
15968 inst.instruction |= neon_logbits (et.size) << 6;
15969 }
15970 break;
15971
15972 default: ;
15973 }
15974
15975 inst.instruction |= do_align << 4;
15976}
15977
15978/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15979 apart from bits [11:4]. */
15980
15981static void
15982do_neon_ldx_stx (void)
15983{
b1a769ed
DG
15984 if (inst.operands[1].isreg)
15985 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15986
5287ad62
JB
15987 switch (NEON_LANE (inst.operands[0].imm))
15988 {
15989 case NEON_INTERLEAVE_LANES:
88714cb8 15990 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
15991 do_neon_ld_st_interleave ();
15992 break;
5f4273c7 15993
5287ad62 15994 case NEON_ALL_LANES:
88714cb8 15995 NEON_ENCODE (DUP, inst);
5287ad62
JB
15996 do_neon_ld_dup ();
15997 break;
5f4273c7 15998
5287ad62 15999 default:
88714cb8 16000 NEON_ENCODE (LANE, inst);
5287ad62
JB
16001 do_neon_ld_st_lane ();
16002 }
16003
16004 /* L bit comes from bit mask. */
16005 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16006 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16007 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 16008
5287ad62
JB
16009 if (inst.operands[1].postind)
16010 {
16011 int postreg = inst.operands[1].imm & 0xf;
16012 constraint (!inst.operands[1].immisreg,
16013 _("post-index must be a register"));
16014 constraint (postreg == 0xd || postreg == 0xf,
16015 _("bad register for post-index"));
16016 inst.instruction |= postreg;
16017 }
16018 else if (inst.operands[1].writeback)
16019 {
16020 inst.instruction |= 0xd;
16021 }
16022 else
5f4273c7
NC
16023 inst.instruction |= 0xf;
16024
5287ad62
JB
16025 if (thumb_mode)
16026 inst.instruction |= 0xf9000000;
16027 else
16028 inst.instruction |= 0xf4000000;
16029}
33399f07
MGD
16030
16031/* FP v8. */
16032static void
16033do_vfp_nsyn_fpv8 (enum neon_shape rs)
16034{
16035 NEON_ENCODE (FPV8, inst);
16036
16037 if (rs == NS_FFF)
16038 do_vfp_sp_dyadic ();
16039 else
16040 do_vfp_dp_rd_rn_rm ();
16041
16042 if (rs == NS_DDD)
16043 inst.instruction |= 0x100;
16044
16045 inst.instruction |= 0xf0000000;
16046}
16047
16048static void
16049do_vsel (void)
16050{
16051 set_it_insn_type (OUTSIDE_IT_INSN);
16052
16053 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
16054 first_error (_("invalid instruction shape"));
16055}
16056
73924fbc
MGD
16057static void
16058do_vmaxnm (void)
16059{
16060 set_it_insn_type (OUTSIDE_IT_INSN);
16061
16062 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
16063 return;
16064
16065 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16066 return;
16067
16068 neon_dyadic_misc (NT_untyped, N_F32, 0);
16069}
16070
30bdf752
MGD
16071static void
16072do_vrint_1 (enum neon_cvt_mode mode)
16073{
16074 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_QQ, NS_NULL);
16075 struct neon_type_el et;
16076
16077 if (rs == NS_NULL)
16078 return;
16079
16080 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
16081 if (et.type != NT_invtype)
16082 {
16083 /* VFP encodings. */
16084 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
16085 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
16086 set_it_insn_type (OUTSIDE_IT_INSN);
16087
16088 NEON_ENCODE (FPV8, inst);
16089 if (rs == NS_FF)
16090 do_vfp_sp_monadic ();
16091 else
16092 do_vfp_dp_rd_rm ();
16093
16094 switch (mode)
16095 {
16096 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
16097 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
16098 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
16099 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
16100 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
16101 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
16102 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
16103 default: abort ();
16104 }
16105
16106 inst.instruction |= (rs == NS_DD) << 8;
16107 do_vfp_cond_or_thumb ();
16108 }
16109 else
16110 {
16111 /* Neon encodings (or something broken...). */
16112 inst.error = NULL;
16113 et = neon_check_type (2, rs, N_EQK, N_F32 | N_KEY);
16114
16115 if (et.type == NT_invtype)
16116 return;
16117
16118 set_it_insn_type (OUTSIDE_IT_INSN);
16119 NEON_ENCODE (FLOAT, inst);
16120
16121 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16122 return;
16123
16124 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16125 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16126 inst.instruction |= LOW4 (inst.operands[1].reg);
16127 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16128 inst.instruction |= neon_quad (rs) << 6;
16129 switch (mode)
16130 {
16131 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
16132 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
16133 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
16134 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
16135 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
16136 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
16137 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
16138 default: abort ();
16139 }
16140
16141 if (thumb_mode)
16142 inst.instruction |= 0xfc000000;
16143 else
16144 inst.instruction |= 0xf0000000;
16145 }
16146}
16147
16148static void
16149do_vrintx (void)
16150{
16151 do_vrint_1 (neon_cvt_mode_x);
16152}
16153
16154static void
16155do_vrintz (void)
16156{
16157 do_vrint_1 (neon_cvt_mode_z);
16158}
16159
16160static void
16161do_vrintr (void)
16162{
16163 do_vrint_1 (neon_cvt_mode_r);
16164}
16165
16166static void
16167do_vrinta (void)
16168{
16169 do_vrint_1 (neon_cvt_mode_a);
16170}
16171
16172static void
16173do_vrintn (void)
16174{
16175 do_vrint_1 (neon_cvt_mode_n);
16176}
16177
16178static void
16179do_vrintp (void)
16180{
16181 do_vrint_1 (neon_cvt_mode_p);
16182}
16183
16184static void
16185do_vrintm (void)
16186{
16187 do_vrint_1 (neon_cvt_mode_m);
16188}
16189
91ff7894
MGD
16190/* Crypto v1 instructions. */
16191static void
16192do_crypto_2op_1 (unsigned elttype, int op)
16193{
16194 set_it_insn_type (OUTSIDE_IT_INSN);
16195
16196 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
16197 == NT_invtype)
16198 return;
16199
16200 inst.error = NULL;
16201
16202 NEON_ENCODE (INTEGER, inst);
16203 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16204 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16205 inst.instruction |= LOW4 (inst.operands[1].reg);
16206 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16207 if (op != -1)
16208 inst.instruction |= op << 6;
16209
16210 if (thumb_mode)
16211 inst.instruction |= 0xfc000000;
16212 else
16213 inst.instruction |= 0xf0000000;
16214}
16215
48adcd8e
MGD
16216static void
16217do_crypto_3op_1 (int u, int op)
16218{
16219 set_it_insn_type (OUTSIDE_IT_INSN);
16220
16221 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
16222 N_32 | N_UNT | N_KEY).type == NT_invtype)
16223 return;
16224
16225 inst.error = NULL;
16226
16227 NEON_ENCODE (INTEGER, inst);
16228 neon_three_same (1, u, 8 << op);
16229}
16230
91ff7894
MGD
16231static void
16232do_aese (void)
16233{
16234 do_crypto_2op_1 (N_8, 0);
16235}
16236
16237static void
16238do_aesd (void)
16239{
16240 do_crypto_2op_1 (N_8, 1);
16241}
16242
16243static void
16244do_aesmc (void)
16245{
16246 do_crypto_2op_1 (N_8, 2);
16247}
16248
16249static void
16250do_aesimc (void)
16251{
16252 do_crypto_2op_1 (N_8, 3);
16253}
16254
48adcd8e
MGD
16255static void
16256do_sha1c (void)
16257{
16258 do_crypto_3op_1 (0, 0);
16259}
16260
16261static void
16262do_sha1p (void)
16263{
16264 do_crypto_3op_1 (0, 1);
16265}
16266
16267static void
16268do_sha1m (void)
16269{
16270 do_crypto_3op_1 (0, 2);
16271}
16272
16273static void
16274do_sha1su0 (void)
16275{
16276 do_crypto_3op_1 (0, 3);
16277}
91ff7894 16278
48adcd8e
MGD
16279static void
16280do_sha256h (void)
16281{
16282 do_crypto_3op_1 (1, 0);
16283}
16284
16285static void
16286do_sha256h2 (void)
16287{
16288 do_crypto_3op_1 (1, 1);
16289}
16290
16291static void
16292do_sha256su1 (void)
16293{
16294 do_crypto_3op_1 (1, 2);
16295}
3c9017d2
MGD
16296
16297static void
16298do_sha1h (void)
16299{
16300 do_crypto_2op_1 (N_32, -1);
16301}
16302
16303static void
16304do_sha1su1 (void)
16305{
16306 do_crypto_2op_1 (N_32, 0);
16307}
16308
16309static void
16310do_sha256su0 (void)
16311{
16312 do_crypto_2op_1 (N_32, 1);
16313}
5287ad62
JB
16314\f
16315/* Overall per-instruction processing. */
16316
16317/* We need to be able to fix up arbitrary expressions in some statements.
16318 This is so that we can handle symbols that are an arbitrary distance from
16319 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
16320 which returns part of an address in a form which will be valid for
16321 a data instruction. We do this by pushing the expression into a symbol
16322 in the expr_section, and creating a fix for that. */
16323
16324static void
16325fix_new_arm (fragS * frag,
16326 int where,
16327 short int size,
16328 expressionS * exp,
16329 int pc_rel,
16330 int reloc)
16331{
16332 fixS * new_fix;
16333
16334 switch (exp->X_op)
16335 {
16336 case O_constant:
6e7ce2cd
PB
16337 if (pc_rel)
16338 {
16339 /* Create an absolute valued symbol, so we have something to
16340 refer to in the object file. Unfortunately for us, gas's
16341 generic expression parsing will already have folded out
16342 any use of .set foo/.type foo %function that may have
16343 been used to set type information of the target location,
16344 that's being specified symbolically. We have to presume
16345 the user knows what they are doing. */
16346 char name[16 + 8];
16347 symbolS *symbol;
16348
16349 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
16350
16351 symbol = symbol_find_or_make (name);
16352 S_SET_SEGMENT (symbol, absolute_section);
16353 symbol_set_frag (symbol, &zero_address_frag);
16354 S_SET_VALUE (symbol, exp->X_add_number);
16355 exp->X_op = O_symbol;
16356 exp->X_add_symbol = symbol;
16357 exp->X_add_number = 0;
16358 }
16359 /* FALLTHROUGH */
5287ad62
JB
16360 case O_symbol:
16361 case O_add:
16362 case O_subtract:
21d799b5
NC
16363 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
16364 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
16365 break;
16366
16367 default:
21d799b5
NC
16368 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
16369 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
16370 break;
16371 }
16372
16373 /* Mark whether the fix is to a THUMB instruction, or an ARM
16374 instruction. */
16375 new_fix->tc_fix_data = thumb_mode;
16376}
16377
16378/* Create a frg for an instruction requiring relaxation. */
16379static void
16380output_relax_insn (void)
16381{
16382 char * to;
16383 symbolS *sym;
0110f2b8
PB
16384 int offset;
16385
6e1cb1a6
PB
16386 /* The size of the instruction is unknown, so tie the debug info to the
16387 start of the instruction. */
16388 dwarf2_emit_insn (0);
6e1cb1a6 16389
0110f2b8
PB
16390 switch (inst.reloc.exp.X_op)
16391 {
16392 case O_symbol:
16393 sym = inst.reloc.exp.X_add_symbol;
16394 offset = inst.reloc.exp.X_add_number;
16395 break;
16396 case O_constant:
16397 sym = NULL;
16398 offset = inst.reloc.exp.X_add_number;
16399 break;
16400 default:
16401 sym = make_expr_symbol (&inst.reloc.exp);
16402 offset = 0;
16403 break;
16404 }
16405 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
16406 inst.relax, sym, offset, NULL/*offset, opcode*/);
16407 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
16408}
16409
16410/* Write a 32-bit thumb instruction to buf. */
16411static void
16412put_thumb32_insn (char * buf, unsigned long insn)
16413{
16414 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
16415 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
16416}
16417
b99bd4ef 16418static void
c19d1205 16419output_inst (const char * str)
b99bd4ef 16420{
c19d1205 16421 char * to = NULL;
b99bd4ef 16422
c19d1205 16423 if (inst.error)
b99bd4ef 16424 {
c19d1205 16425 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
16426 return;
16427 }
5f4273c7
NC
16428 if (inst.relax)
16429 {
16430 output_relax_insn ();
0110f2b8 16431 return;
5f4273c7 16432 }
c19d1205
ZW
16433 if (inst.size == 0)
16434 return;
b99bd4ef 16435
c19d1205 16436 to = frag_more (inst.size);
8dc2430f
NC
16437 /* PR 9814: Record the thumb mode into the current frag so that we know
16438 what type of NOP padding to use, if necessary. We override any previous
16439 setting so that if the mode has changed then the NOPS that we use will
16440 match the encoding of the last instruction in the frag. */
cd000bff 16441 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
16442
16443 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 16444 {
9c2799c2 16445 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 16446 put_thumb32_insn (to, inst.instruction);
b99bd4ef 16447 }
c19d1205 16448 else if (inst.size > INSN_SIZE)
b99bd4ef 16449 {
9c2799c2 16450 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
16451 md_number_to_chars (to, inst.instruction, INSN_SIZE);
16452 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 16453 }
c19d1205
ZW
16454 else
16455 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 16456
c19d1205
ZW
16457 if (inst.reloc.type != BFD_RELOC_UNUSED)
16458 fix_new_arm (frag_now, to - frag_now->fr_literal,
16459 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
16460 inst.reloc.type);
b99bd4ef 16461
c19d1205 16462 dwarf2_emit_insn (inst.size);
c19d1205 16463}
b99bd4ef 16464
e07e6e58
NC
16465static char *
16466output_it_inst (int cond, int mask, char * to)
16467{
16468 unsigned long instruction = 0xbf00;
16469
16470 mask &= 0xf;
16471 instruction |= mask;
16472 instruction |= cond << 4;
16473
16474 if (to == NULL)
16475 {
16476 to = frag_more (2);
16477#ifdef OBJ_ELF
16478 dwarf2_emit_insn (2);
16479#endif
16480 }
16481
16482 md_number_to_chars (to, instruction, 2);
16483
16484 return to;
16485}
16486
c19d1205
ZW
16487/* Tag values used in struct asm_opcode's tag field. */
16488enum opcode_tag
16489{
16490 OT_unconditional, /* Instruction cannot be conditionalized.
16491 The ARM condition field is still 0xE. */
16492 OT_unconditionalF, /* Instruction cannot be conditionalized
16493 and carries 0xF in its ARM condition field. */
16494 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
16495 OT_csuffixF, /* Some forms of the instruction take a conditional
16496 suffix, others place 0xF where the condition field
16497 would be. */
c19d1205
ZW
16498 OT_cinfix3, /* Instruction takes a conditional infix,
16499 beginning at character index 3. (In
16500 unified mode, it becomes a suffix.) */
088fa78e
KH
16501 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
16502 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
16503 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
16504 character index 3, even in unified mode. Used for
16505 legacy instructions where suffix and infix forms
16506 may be ambiguous. */
c19d1205 16507 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 16508 suffix or an infix at character index 3. */
c19d1205
ZW
16509 OT_odd_infix_unc, /* This is the unconditional variant of an
16510 instruction that takes a conditional infix
16511 at an unusual position. In unified mode,
16512 this variant will accept a suffix. */
16513 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
16514 are the conditional variants of instructions that
16515 take conditional infixes in unusual positions.
16516 The infix appears at character index
16517 (tag - OT_odd_infix_0). These are not accepted
16518 in unified mode. */
16519};
b99bd4ef 16520
c19d1205
ZW
16521/* Subroutine of md_assemble, responsible for looking up the primary
16522 opcode from the mnemonic the user wrote. STR points to the
16523 beginning of the mnemonic.
16524
16525 This is not simply a hash table lookup, because of conditional
16526 variants. Most instructions have conditional variants, which are
16527 expressed with a _conditional affix_ to the mnemonic. If we were
16528 to encode each conditional variant as a literal string in the opcode
16529 table, it would have approximately 20,000 entries.
16530
16531 Most mnemonics take this affix as a suffix, and in unified syntax,
16532 'most' is upgraded to 'all'. However, in the divided syntax, some
16533 instructions take the affix as an infix, notably the s-variants of
16534 the arithmetic instructions. Of those instructions, all but six
16535 have the infix appear after the third character of the mnemonic.
16536
16537 Accordingly, the algorithm for looking up primary opcodes given
16538 an identifier is:
16539
16540 1. Look up the identifier in the opcode table.
16541 If we find a match, go to step U.
16542
16543 2. Look up the last two characters of the identifier in the
16544 conditions table. If we find a match, look up the first N-2
16545 characters of the identifier in the opcode table. If we
16546 find a match, go to step CE.
16547
16548 3. Look up the fourth and fifth characters of the identifier in
16549 the conditions table. If we find a match, extract those
16550 characters from the identifier, and look up the remaining
16551 characters in the opcode table. If we find a match, go
16552 to step CM.
16553
16554 4. Fail.
16555
16556 U. Examine the tag field of the opcode structure, in case this is
16557 one of the six instructions with its conditional infix in an
16558 unusual place. If it is, the tag tells us where to find the
16559 infix; look it up in the conditions table and set inst.cond
16560 accordingly. Otherwise, this is an unconditional instruction.
16561 Again set inst.cond accordingly. Return the opcode structure.
16562
16563 CE. Examine the tag field to make sure this is an instruction that
16564 should receive a conditional suffix. If it is not, fail.
16565 Otherwise, set inst.cond from the suffix we already looked up,
16566 and return the opcode structure.
16567
16568 CM. Examine the tag field to make sure this is an instruction that
16569 should receive a conditional infix after the third character.
16570 If it is not, fail. Otherwise, undo the edits to the current
16571 line of input and proceed as for case CE. */
16572
16573static const struct asm_opcode *
16574opcode_lookup (char **str)
16575{
16576 char *end, *base;
16577 char *affix;
16578 const struct asm_opcode *opcode;
16579 const struct asm_cond *cond;
e3cb604e 16580 char save[2];
c19d1205
ZW
16581
16582 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 16583 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 16584 for (base = end = *str; *end != '\0'; end++)
721a8186 16585 if (*end == ' ' || *end == '.')
c19d1205 16586 break;
b99bd4ef 16587
c19d1205 16588 if (end == base)
c921be7d 16589 return NULL;
b99bd4ef 16590
5287ad62 16591 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 16592 if (end[0] == '.')
b99bd4ef 16593 {
5287ad62 16594 int offset = 2;
5f4273c7 16595
267d2029
JB
16596 /* The .w and .n suffixes are only valid if the unified syntax is in
16597 use. */
16598 if (unified_syntax && end[1] == 'w')
c19d1205 16599 inst.size_req = 4;
267d2029 16600 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
16601 inst.size_req = 2;
16602 else
5287ad62
JB
16603 offset = 0;
16604
16605 inst.vectype.elems = 0;
16606
16607 *str = end + offset;
b99bd4ef 16608
5f4273c7 16609 if (end[offset] == '.')
5287ad62 16610 {
267d2029
JB
16611 /* See if we have a Neon type suffix (possible in either unified or
16612 non-unified ARM syntax mode). */
dcbf9037 16613 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 16614 return NULL;
5287ad62
JB
16615 }
16616 else if (end[offset] != '\0' && end[offset] != ' ')
c921be7d 16617 return NULL;
b99bd4ef 16618 }
c19d1205
ZW
16619 else
16620 *str = end;
b99bd4ef 16621
c19d1205 16622 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5
NC
16623 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16624 end - base);
c19d1205 16625 if (opcode)
b99bd4ef 16626 {
c19d1205
ZW
16627 /* step U */
16628 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 16629 {
c19d1205
ZW
16630 inst.cond = COND_ALWAYS;
16631 return opcode;
b99bd4ef 16632 }
b99bd4ef 16633
278df34e 16634 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
16635 as_warn (_("conditional infixes are deprecated in unified syntax"));
16636 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 16637 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 16638 gas_assert (cond);
b99bd4ef 16639
c19d1205
ZW
16640 inst.cond = cond->value;
16641 return opcode;
16642 }
b99bd4ef 16643
c19d1205
ZW
16644 /* Cannot have a conditional suffix on a mnemonic of less than two
16645 characters. */
16646 if (end - base < 3)
c921be7d 16647 return NULL;
b99bd4ef 16648
c19d1205
ZW
16649 /* Look for suffixed mnemonic. */
16650 affix = end - 2;
21d799b5
NC
16651 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
16652 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16653 affix - base);
c19d1205
ZW
16654 if (opcode && cond)
16655 {
16656 /* step CE */
16657 switch (opcode->tag)
16658 {
e3cb604e
PB
16659 case OT_cinfix3_legacy:
16660 /* Ignore conditional suffixes matched on infix only mnemonics. */
16661 break;
16662
c19d1205 16663 case OT_cinfix3:
088fa78e 16664 case OT_cinfix3_deprecated:
c19d1205
ZW
16665 case OT_odd_infix_unc:
16666 if (!unified_syntax)
e3cb604e 16667 return 0;
c19d1205
ZW
16668 /* else fall through */
16669
16670 case OT_csuffix:
037e8744 16671 case OT_csuffixF:
c19d1205
ZW
16672 case OT_csuf_or_in3:
16673 inst.cond = cond->value;
16674 return opcode;
16675
16676 case OT_unconditional:
16677 case OT_unconditionalF:
dfa9f0d5 16678 if (thumb_mode)
c921be7d 16679 inst.cond = cond->value;
dfa9f0d5
PB
16680 else
16681 {
c921be7d 16682 /* Delayed diagnostic. */
dfa9f0d5
PB
16683 inst.error = BAD_COND;
16684 inst.cond = COND_ALWAYS;
16685 }
c19d1205 16686 return opcode;
b99bd4ef 16687
c19d1205 16688 default:
c921be7d 16689 return NULL;
c19d1205
ZW
16690 }
16691 }
b99bd4ef 16692
c19d1205
ZW
16693 /* Cannot have a usual-position infix on a mnemonic of less than
16694 six characters (five would be a suffix). */
16695 if (end - base < 6)
c921be7d 16696 return NULL;
b99bd4ef 16697
c19d1205
ZW
16698 /* Look for infixed mnemonic in the usual position. */
16699 affix = base + 3;
21d799b5 16700 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 16701 if (!cond)
c921be7d 16702 return NULL;
e3cb604e
PB
16703
16704 memcpy (save, affix, 2);
16705 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5
NC
16706 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16707 (end - base) - 2);
e3cb604e
PB
16708 memmove (affix + 2, affix, (end - affix) - 2);
16709 memcpy (affix, save, 2);
16710
088fa78e
KH
16711 if (opcode
16712 && (opcode->tag == OT_cinfix3
16713 || opcode->tag == OT_cinfix3_deprecated
16714 || opcode->tag == OT_csuf_or_in3
16715 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 16716 {
c921be7d 16717 /* Step CM. */
278df34e 16718 if (warn_on_deprecated && unified_syntax
088fa78e
KH
16719 && (opcode->tag == OT_cinfix3
16720 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
16721 as_warn (_("conditional infixes are deprecated in unified syntax"));
16722
16723 inst.cond = cond->value;
16724 return opcode;
b99bd4ef
NC
16725 }
16726
c921be7d 16727 return NULL;
b99bd4ef
NC
16728}
16729
e07e6e58
NC
16730/* This function generates an initial IT instruction, leaving its block
16731 virtually open for the new instructions. Eventually,
16732 the mask will be updated by now_it_add_mask () each time
16733 a new instruction needs to be included in the IT block.
16734 Finally, the block is closed with close_automatic_it_block ().
16735 The block closure can be requested either from md_assemble (),
16736 a tencode (), or due to a label hook. */
16737
16738static void
16739new_automatic_it_block (int cond)
16740{
16741 now_it.state = AUTOMATIC_IT_BLOCK;
16742 now_it.mask = 0x18;
16743 now_it.cc = cond;
16744 now_it.block_length = 1;
cd000bff 16745 mapping_state (MAP_THUMB);
e07e6e58 16746 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
16747 now_it.warn_deprecated = FALSE;
16748 now_it.insn_cond = TRUE;
e07e6e58
NC
16749}
16750
16751/* Close an automatic IT block.
16752 See comments in new_automatic_it_block (). */
16753
16754static void
16755close_automatic_it_block (void)
16756{
16757 now_it.mask = 0x10;
16758 now_it.block_length = 0;
16759}
16760
16761/* Update the mask of the current automatically-generated IT
16762 instruction. See comments in new_automatic_it_block (). */
16763
16764static void
16765now_it_add_mask (int cond)
16766{
16767#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
16768#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
16769 | ((bitvalue) << (nbit)))
e07e6e58 16770 const int resulting_bit = (cond & 1);
c921be7d 16771
e07e6e58
NC
16772 now_it.mask &= 0xf;
16773 now_it.mask = SET_BIT_VALUE (now_it.mask,
16774 resulting_bit,
16775 (5 - now_it.block_length));
16776 now_it.mask = SET_BIT_VALUE (now_it.mask,
16777 1,
16778 ((5 - now_it.block_length) - 1) );
16779 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
16780
16781#undef CLEAR_BIT
16782#undef SET_BIT_VALUE
e07e6e58
NC
16783}
16784
16785/* The IT blocks handling machinery is accessed through the these functions:
16786 it_fsm_pre_encode () from md_assemble ()
16787 set_it_insn_type () optional, from the tencode functions
16788 set_it_insn_type_last () ditto
16789 in_it_block () ditto
16790 it_fsm_post_encode () from md_assemble ()
16791 force_automatic_it_block_close () from label habdling functions
16792
16793 Rationale:
16794 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
16795 initializing the IT insn type with a generic initial value depending
16796 on the inst.condition.
16797 2) During the tencode function, two things may happen:
16798 a) The tencode function overrides the IT insn type by
16799 calling either set_it_insn_type (type) or set_it_insn_type_last ().
16800 b) The tencode function queries the IT block state by
16801 calling in_it_block () (i.e. to determine narrow/not narrow mode).
16802
16803 Both set_it_insn_type and in_it_block run the internal FSM state
16804 handling function (handle_it_state), because: a) setting the IT insn
16805 type may incur in an invalid state (exiting the function),
16806 and b) querying the state requires the FSM to be updated.
16807 Specifically we want to avoid creating an IT block for conditional
16808 branches, so it_fsm_pre_encode is actually a guess and we can't
16809 determine whether an IT block is required until the tencode () routine
16810 has decided what type of instruction this actually it.
16811 Because of this, if set_it_insn_type and in_it_block have to be used,
16812 set_it_insn_type has to be called first.
16813
16814 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
16815 determines the insn IT type depending on the inst.cond code.
16816 When a tencode () routine encodes an instruction that can be
16817 either outside an IT block, or, in the case of being inside, has to be
16818 the last one, set_it_insn_type_last () will determine the proper
16819 IT instruction type based on the inst.cond code. Otherwise,
16820 set_it_insn_type can be called for overriding that logic or
16821 for covering other cases.
16822
16823 Calling handle_it_state () may not transition the IT block state to
16824 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
16825 still queried. Instead, if the FSM determines that the state should
16826 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
16827 after the tencode () function: that's what it_fsm_post_encode () does.
16828
16829 Since in_it_block () calls the state handling function to get an
16830 updated state, an error may occur (due to invalid insns combination).
16831 In that case, inst.error is set.
16832 Therefore, inst.error has to be checked after the execution of
16833 the tencode () routine.
16834
16835 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
16836 any pending state change (if any) that didn't take place in
16837 handle_it_state () as explained above. */
16838
16839static void
16840it_fsm_pre_encode (void)
16841{
16842 if (inst.cond != COND_ALWAYS)
16843 inst.it_insn_type = INSIDE_IT_INSN;
16844 else
16845 inst.it_insn_type = OUTSIDE_IT_INSN;
16846
16847 now_it.state_handled = 0;
16848}
16849
16850/* IT state FSM handling function. */
16851
16852static int
16853handle_it_state (void)
16854{
16855 now_it.state_handled = 1;
5a01bb1d 16856 now_it.insn_cond = FALSE;
e07e6e58
NC
16857
16858 switch (now_it.state)
16859 {
16860 case OUTSIDE_IT_BLOCK:
16861 switch (inst.it_insn_type)
16862 {
16863 case OUTSIDE_IT_INSN:
16864 break;
16865
16866 case INSIDE_IT_INSN:
16867 case INSIDE_IT_LAST_INSN:
16868 if (thumb_mode == 0)
16869 {
c921be7d 16870 if (unified_syntax
e07e6e58
NC
16871 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
16872 as_tsktsk (_("Warning: conditional outside an IT block"\
16873 " for Thumb."));
16874 }
16875 else
16876 {
16877 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
16878 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
16879 {
16880 /* Automatically generate the IT instruction. */
16881 new_automatic_it_block (inst.cond);
16882 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
16883 close_automatic_it_block ();
16884 }
16885 else
16886 {
16887 inst.error = BAD_OUT_IT;
16888 return FAIL;
16889 }
16890 }
16891 break;
16892
16893 case IF_INSIDE_IT_LAST_INSN:
16894 case NEUTRAL_IT_INSN:
16895 break;
16896
16897 case IT_INSN:
16898 now_it.state = MANUAL_IT_BLOCK;
16899 now_it.block_length = 0;
16900 break;
16901 }
16902 break;
16903
16904 case AUTOMATIC_IT_BLOCK:
16905 /* Three things may happen now:
16906 a) We should increment current it block size;
16907 b) We should close current it block (closing insn or 4 insns);
16908 c) We should close current it block and start a new one (due
16909 to incompatible conditions or
16910 4 insns-length block reached). */
16911
16912 switch (inst.it_insn_type)
16913 {
16914 case OUTSIDE_IT_INSN:
16915 /* The closure of the block shall happen immediatelly,
16916 so any in_it_block () call reports the block as closed. */
16917 force_automatic_it_block_close ();
16918 break;
16919
16920 case INSIDE_IT_INSN:
16921 case INSIDE_IT_LAST_INSN:
16922 case IF_INSIDE_IT_LAST_INSN:
16923 now_it.block_length++;
16924
16925 if (now_it.block_length > 4
16926 || !now_it_compatible (inst.cond))
16927 {
16928 force_automatic_it_block_close ();
16929 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
16930 new_automatic_it_block (inst.cond);
16931 }
16932 else
16933 {
5a01bb1d 16934 now_it.insn_cond = TRUE;
e07e6e58
NC
16935 now_it_add_mask (inst.cond);
16936 }
16937
16938 if (now_it.state == AUTOMATIC_IT_BLOCK
16939 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
16940 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
16941 close_automatic_it_block ();
16942 break;
16943
16944 case NEUTRAL_IT_INSN:
16945 now_it.block_length++;
5a01bb1d 16946 now_it.insn_cond = TRUE;
e07e6e58
NC
16947
16948 if (now_it.block_length > 4)
16949 force_automatic_it_block_close ();
16950 else
16951 now_it_add_mask (now_it.cc & 1);
16952 break;
16953
16954 case IT_INSN:
16955 close_automatic_it_block ();
16956 now_it.state = MANUAL_IT_BLOCK;
16957 break;
16958 }
16959 break;
16960
16961 case MANUAL_IT_BLOCK:
16962 {
16963 /* Check conditional suffixes. */
16964 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
16965 int is_last;
16966 now_it.mask <<= 1;
16967 now_it.mask &= 0x1f;
16968 is_last = (now_it.mask == 0x10);
5a01bb1d 16969 now_it.insn_cond = TRUE;
e07e6e58
NC
16970
16971 switch (inst.it_insn_type)
16972 {
16973 case OUTSIDE_IT_INSN:
16974 inst.error = BAD_NOT_IT;
16975 return FAIL;
16976
16977 case INSIDE_IT_INSN:
16978 if (cond != inst.cond)
16979 {
16980 inst.error = BAD_IT_COND;
16981 return FAIL;
16982 }
16983 break;
16984
16985 case INSIDE_IT_LAST_INSN:
16986 case IF_INSIDE_IT_LAST_INSN:
16987 if (cond != inst.cond)
16988 {
16989 inst.error = BAD_IT_COND;
16990 return FAIL;
16991 }
16992 if (!is_last)
16993 {
16994 inst.error = BAD_BRANCH;
16995 return FAIL;
16996 }
16997 break;
16998
16999 case NEUTRAL_IT_INSN:
17000 /* The BKPT instruction is unconditional even in an IT block. */
17001 break;
17002
17003 case IT_INSN:
17004 inst.error = BAD_IT_IT;
17005 return FAIL;
17006 }
17007 }
17008 break;
17009 }
17010
17011 return SUCCESS;
17012}
17013
5a01bb1d
MGD
17014struct depr_insn_mask
17015{
17016 unsigned long pattern;
17017 unsigned long mask;
17018 const char* description;
17019};
17020
17021/* List of 16-bit instruction patterns deprecated in an IT block in
17022 ARMv8. */
17023static const struct depr_insn_mask depr_it_insns[] = {
17024 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
17025 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
17026 { 0xa000, 0xb800, N_("ADR") },
17027 { 0x4800, 0xf800, N_("Literal loads") },
17028 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
17029 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
17030 { 0, 0, NULL }
17031};
17032
e07e6e58
NC
17033static void
17034it_fsm_post_encode (void)
17035{
17036 int is_last;
17037
17038 if (!now_it.state_handled)
17039 handle_it_state ();
17040
5a01bb1d
MGD
17041 if (now_it.insn_cond
17042 && !now_it.warn_deprecated
17043 && warn_on_deprecated
17044 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
17045 {
17046 if (inst.instruction >= 0x10000)
17047 {
17048 as_warn (_("it blocks containing wide Thumb instructions are "
17049 "deprecated in ARMv8"));
17050 now_it.warn_deprecated = TRUE;
17051 }
17052 else
17053 {
17054 const struct depr_insn_mask *p = depr_it_insns;
17055
17056 while (p->mask != 0)
17057 {
17058 if ((inst.instruction & p->mask) == p->pattern)
17059 {
17060 as_warn (_("it blocks containing 16-bit Thumb intsructions "
17061 "of the following class are deprecated in ARMv8: "
17062 "%s"), p->description);
17063 now_it.warn_deprecated = TRUE;
17064 break;
17065 }
17066
17067 ++p;
17068 }
17069 }
17070
17071 if (now_it.block_length > 1)
17072 {
17073 as_warn (_("it blocks of more than one conditional instruction are "
17074 "deprecated in ARMv8"));
17075 now_it.warn_deprecated = TRUE;
17076 }
17077 }
17078
e07e6e58
NC
17079 is_last = (now_it.mask == 0x10);
17080 if (is_last)
17081 {
17082 now_it.state = OUTSIDE_IT_BLOCK;
17083 now_it.mask = 0;
17084 }
17085}
17086
17087static void
17088force_automatic_it_block_close (void)
17089{
17090 if (now_it.state == AUTOMATIC_IT_BLOCK)
17091 {
17092 close_automatic_it_block ();
17093 now_it.state = OUTSIDE_IT_BLOCK;
17094 now_it.mask = 0;
17095 }
17096}
17097
17098static int
17099in_it_block (void)
17100{
17101 if (!now_it.state_handled)
17102 handle_it_state ();
17103
17104 return now_it.state != OUTSIDE_IT_BLOCK;
17105}
17106
c19d1205
ZW
17107void
17108md_assemble (char *str)
b99bd4ef 17109{
c19d1205
ZW
17110 char *p = str;
17111 const struct asm_opcode * opcode;
b99bd4ef 17112
c19d1205
ZW
17113 /* Align the previous label if needed. */
17114 if (last_label_seen != NULL)
b99bd4ef 17115 {
c19d1205
ZW
17116 symbol_set_frag (last_label_seen, frag_now);
17117 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
17118 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
17119 }
17120
c19d1205
ZW
17121 memset (&inst, '\0', sizeof (inst));
17122 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 17123
c19d1205
ZW
17124 opcode = opcode_lookup (&p);
17125 if (!opcode)
b99bd4ef 17126 {
c19d1205 17127 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 17128 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d
NC
17129 if (! create_register_alias (str, p)
17130 && ! create_neon_reg_alias (str, p))
c19d1205 17131 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 17132
b99bd4ef
NC
17133 return;
17134 }
17135
278df34e 17136 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
17137 as_warn (_("s suffix on comparison instruction is deprecated"));
17138
037e8744
JB
17139 /* The value which unconditional instructions should have in place of the
17140 condition field. */
17141 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
17142
c19d1205 17143 if (thumb_mode)
b99bd4ef 17144 {
e74cfd16 17145 arm_feature_set variant;
8f06b2d8
PB
17146
17147 variant = cpu_variant;
17148 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
17149 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
17150 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 17151 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
17152 if (!opcode->tvariant
17153 || (thumb_mode == 1
17154 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 17155 {
bf3eeda7 17156 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
b99bd4ef
NC
17157 return;
17158 }
c19d1205
ZW
17159 if (inst.cond != COND_ALWAYS && !unified_syntax
17160 && opcode->tencode != do_t_branch)
b99bd4ef 17161 {
c19d1205 17162 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
17163 return;
17164 }
17165
752d5da4 17166 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 17167 {
7e806470 17168 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
17169 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
17170 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
17171 {
17172 /* Two things are addressed here.
17173 1) Implicit require narrow instructions on Thumb-1.
17174 This avoids relaxation accidentally introducing Thumb-2
17175 instructions.
17176 2) Reject wide instructions in non Thumb-2 cores. */
17177 if (inst.size_req == 0)
17178 inst.size_req = 2;
17179 else if (inst.size_req == 4)
17180 {
bf3eeda7 17181 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
752d5da4
NC
17182 return;
17183 }
17184 }
076d447c
PB
17185 }
17186
c19d1205
ZW
17187 inst.instruction = opcode->tvalue;
17188
5be8be5d 17189 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
e07e6e58
NC
17190 {
17191 /* Prepare the it_insn_type for those encodings that don't set
17192 it. */
17193 it_fsm_pre_encode ();
c19d1205 17194
e07e6e58
NC
17195 opcode->tencode ();
17196
17197 it_fsm_post_encode ();
17198 }
e27ec89e 17199
0110f2b8 17200 if (!(inst.error || inst.relax))
b99bd4ef 17201 {
9c2799c2 17202 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
17203 inst.size = (inst.instruction > 0xffff ? 4 : 2);
17204 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 17205 {
c19d1205 17206 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
17207 return;
17208 }
17209 }
076d447c
PB
17210
17211 /* Something has gone badly wrong if we try to relax a fixed size
17212 instruction. */
9c2799c2 17213 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 17214
e74cfd16
PB
17215 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17216 *opcode->tvariant);
ee065d83 17217 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 17218 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 17219 anything other than bl/blx and v6-M instructions.
ee065d83 17220 This is overly pessimistic for relaxable instructions. */
7e806470
PB
17221 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
17222 || inst.relax)
e07e6e58
NC
17223 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
17224 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
17225 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17226 arm_ext_v6t2);
cd000bff 17227
88714cb8
DG
17228 check_neon_suffixes;
17229
cd000bff 17230 if (!inst.error)
c877a2f2
NC
17231 {
17232 mapping_state (MAP_THUMB);
17233 }
c19d1205 17234 }
3e9e4fcf 17235 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 17236 {
845b51d6
PB
17237 bfd_boolean is_bx;
17238
17239 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
17240 is_bx = (opcode->aencode == do_bx);
17241
c19d1205 17242 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
17243 if (!(is_bx && fix_v4bx)
17244 && !(opcode->avariant &&
17245 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 17246 {
bf3eeda7 17247 as_bad (_("selected processor does not support ARM mode `%s'"), str);
c19d1205 17248 return;
b99bd4ef 17249 }
c19d1205 17250 if (inst.size_req)
b99bd4ef 17251 {
c19d1205
ZW
17252 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
17253 return;
b99bd4ef
NC
17254 }
17255
c19d1205
ZW
17256 inst.instruction = opcode->avalue;
17257 if (opcode->tag == OT_unconditionalF)
17258 inst.instruction |= 0xF << 28;
17259 else
17260 inst.instruction |= inst.cond << 28;
17261 inst.size = INSN_SIZE;
5be8be5d 17262 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
e07e6e58
NC
17263 {
17264 it_fsm_pre_encode ();
17265 opcode->aencode ();
17266 it_fsm_post_encode ();
17267 }
ee065d83
PB
17268 /* Arm mode bx is marked as both v4T and v5 because it's still required
17269 on a hypothetical non-thumb v5 core. */
845b51d6 17270 if (is_bx)
e74cfd16 17271 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 17272 else
e74cfd16
PB
17273 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
17274 *opcode->avariant);
88714cb8
DG
17275
17276 check_neon_suffixes;
17277
cd000bff 17278 if (!inst.error)
c877a2f2
NC
17279 {
17280 mapping_state (MAP_ARM);
17281 }
b99bd4ef 17282 }
3e9e4fcf
JB
17283 else
17284 {
17285 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
17286 "-- `%s'"), str);
17287 return;
17288 }
c19d1205
ZW
17289 output_inst (str);
17290}
b99bd4ef 17291
e07e6e58
NC
17292static void
17293check_it_blocks_finished (void)
17294{
17295#ifdef OBJ_ELF
17296 asection *sect;
17297
17298 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
17299 if (seg_info (sect)->tc_segment_info_data.current_it.state
17300 == MANUAL_IT_BLOCK)
17301 {
17302 as_warn (_("section '%s' finished with an open IT block."),
17303 sect->name);
17304 }
17305#else
17306 if (now_it.state == MANUAL_IT_BLOCK)
17307 as_warn (_("file finished with an open IT block."));
17308#endif
17309}
17310
c19d1205
ZW
17311/* Various frobbings of labels and their addresses. */
17312
17313void
17314arm_start_line_hook (void)
17315{
17316 last_label_seen = NULL;
b99bd4ef
NC
17317}
17318
c19d1205
ZW
17319void
17320arm_frob_label (symbolS * sym)
b99bd4ef 17321{
c19d1205 17322 last_label_seen = sym;
b99bd4ef 17323
c19d1205 17324 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 17325
c19d1205
ZW
17326#if defined OBJ_COFF || defined OBJ_ELF
17327 ARM_SET_INTERWORK (sym, support_interwork);
17328#endif
b99bd4ef 17329
e07e6e58
NC
17330 force_automatic_it_block_close ();
17331
5f4273c7 17332 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
17333 as Thumb functions. This is because these labels, whilst
17334 they exist inside Thumb code, are not the entry points for
17335 possible ARM->Thumb calls. Also, these labels can be used
17336 as part of a computed goto or switch statement. eg gcc
17337 can generate code that looks like this:
b99bd4ef 17338
c19d1205
ZW
17339 ldr r2, [pc, .Laaa]
17340 lsl r3, r3, #2
17341 ldr r2, [r3, r2]
17342 mov pc, r2
b99bd4ef 17343
c19d1205
ZW
17344 .Lbbb: .word .Lxxx
17345 .Lccc: .word .Lyyy
17346 ..etc...
17347 .Laaa: .word Lbbb
b99bd4ef 17348
c19d1205
ZW
17349 The first instruction loads the address of the jump table.
17350 The second instruction converts a table index into a byte offset.
17351 The third instruction gets the jump address out of the table.
17352 The fourth instruction performs the jump.
b99bd4ef 17353
c19d1205
ZW
17354 If the address stored at .Laaa is that of a symbol which has the
17355 Thumb_Func bit set, then the linker will arrange for this address
17356 to have the bottom bit set, which in turn would mean that the
17357 address computation performed by the third instruction would end
17358 up with the bottom bit set. Since the ARM is capable of unaligned
17359 word loads, the instruction would then load the incorrect address
17360 out of the jump table, and chaos would ensue. */
17361 if (label_is_thumb_function_name
17362 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
17363 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 17364 {
c19d1205
ZW
17365 /* When the address of a Thumb function is taken the bottom
17366 bit of that address should be set. This will allow
17367 interworking between Arm and Thumb functions to work
17368 correctly. */
b99bd4ef 17369
c19d1205 17370 THUMB_SET_FUNC (sym, 1);
b99bd4ef 17371
c19d1205 17372 label_is_thumb_function_name = FALSE;
b99bd4ef 17373 }
07a53e5c 17374
07a53e5c 17375 dwarf2_emit_label (sym);
b99bd4ef
NC
17376}
17377
c921be7d 17378bfd_boolean
c19d1205 17379arm_data_in_code (void)
b99bd4ef 17380{
c19d1205 17381 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 17382 {
c19d1205
ZW
17383 *input_line_pointer = '/';
17384 input_line_pointer += 5;
17385 *input_line_pointer = 0;
c921be7d 17386 return TRUE;
b99bd4ef
NC
17387 }
17388
c921be7d 17389 return FALSE;
b99bd4ef
NC
17390}
17391
c19d1205
ZW
17392char *
17393arm_canonicalize_symbol_name (char * name)
b99bd4ef 17394{
c19d1205 17395 int len;
b99bd4ef 17396
c19d1205
ZW
17397 if (thumb_mode && (len = strlen (name)) > 5
17398 && streq (name + len - 5, "/data"))
17399 *(name + len - 5) = 0;
b99bd4ef 17400
c19d1205 17401 return name;
b99bd4ef 17402}
c19d1205
ZW
17403\f
17404/* Table of all register names defined by default. The user can
17405 define additional names with .req. Note that all register names
17406 should appear in both upper and lowercase variants. Some registers
17407 also have mixed-case names. */
b99bd4ef 17408
dcbf9037 17409#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 17410#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 17411#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
17412#define REGSET(p,t) \
17413 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
17414 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
17415 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
17416 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
17417#define REGSETH(p,t) \
17418 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
17419 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
17420 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
17421 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
17422#define REGSET2(p,t) \
17423 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
17424 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
17425 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
17426 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
17427#define SPLRBANK(base,bank,t) \
17428 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
17429 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
17430 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
17431 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
17432 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
17433 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 17434
c19d1205 17435static const struct reg_entry reg_names[] =
7ed4c4c5 17436{
c19d1205
ZW
17437 /* ARM integer registers. */
17438 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 17439
c19d1205
ZW
17440 /* ATPCS synonyms. */
17441 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
17442 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
17443 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 17444
c19d1205
ZW
17445 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
17446 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
17447 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 17448
c19d1205
ZW
17449 /* Well-known aliases. */
17450 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
17451 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
17452
17453 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
17454 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
17455
17456 /* Coprocessor numbers. */
17457 REGSET(p, CP), REGSET(P, CP),
17458
17459 /* Coprocessor register numbers. The "cr" variants are for backward
17460 compatibility. */
17461 REGSET(c, CN), REGSET(C, CN),
17462 REGSET(cr, CN), REGSET(CR, CN),
17463
90ec0d68
MGD
17464 /* ARM banked registers. */
17465 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
17466 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
17467 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
17468 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
17469 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
17470 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
17471 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
17472
17473 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
17474 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
17475 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
17476 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
17477 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
17478 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB),
17479 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
17480 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
17481
17482 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
17483 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
17484 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
17485 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
17486 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
17487 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
17488 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 17489 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
17490 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
17491
c19d1205
ZW
17492 /* FPA registers. */
17493 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
17494 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
17495
17496 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
17497 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
17498
17499 /* VFP SP registers. */
5287ad62
JB
17500 REGSET(s,VFS), REGSET(S,VFS),
17501 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
17502
17503 /* VFP DP Registers. */
5287ad62
JB
17504 REGSET(d,VFD), REGSET(D,VFD),
17505 /* Extra Neon DP registers. */
17506 REGSETH(d,VFD), REGSETH(D,VFD),
17507
17508 /* Neon QP registers. */
17509 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
17510
17511 /* VFP control registers. */
17512 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
17513 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
17514 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
17515 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
17516 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
17517 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
17518
17519 /* Maverick DSP coprocessor registers. */
17520 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
17521 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
17522
17523 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
17524 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
17525 REGDEF(dspsc,0,DSPSC),
17526
17527 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
17528 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
17529 REGDEF(DSPSC,0,DSPSC),
17530
17531 /* iWMMXt data registers - p0, c0-15. */
17532 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
17533
17534 /* iWMMXt control registers - p1, c0-3. */
17535 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
17536 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
17537 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
17538 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
17539
17540 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
17541 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
17542 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
17543 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
17544 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
17545
17546 /* XScale accumulator registers. */
17547 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
17548};
17549#undef REGDEF
17550#undef REGNUM
17551#undef REGSET
7ed4c4c5 17552
c19d1205
ZW
17553/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
17554 within psr_required_here. */
17555static const struct asm_psr psrs[] =
17556{
17557 /* Backward compatibility notation. Note that "all" is no longer
17558 truly all possible PSR bits. */
17559 {"all", PSR_c | PSR_f},
17560 {"flg", PSR_f},
17561 {"ctl", PSR_c},
17562
17563 /* Individual flags. */
17564 {"f", PSR_f},
17565 {"c", PSR_c},
17566 {"x", PSR_x},
17567 {"s", PSR_s},
59b42a0d 17568
c19d1205
ZW
17569 /* Combinations of flags. */
17570 {"fs", PSR_f | PSR_s},
17571 {"fx", PSR_f | PSR_x},
17572 {"fc", PSR_f | PSR_c},
17573 {"sf", PSR_s | PSR_f},
17574 {"sx", PSR_s | PSR_x},
17575 {"sc", PSR_s | PSR_c},
17576 {"xf", PSR_x | PSR_f},
17577 {"xs", PSR_x | PSR_s},
17578 {"xc", PSR_x | PSR_c},
17579 {"cf", PSR_c | PSR_f},
17580 {"cs", PSR_c | PSR_s},
17581 {"cx", PSR_c | PSR_x},
17582 {"fsx", PSR_f | PSR_s | PSR_x},
17583 {"fsc", PSR_f | PSR_s | PSR_c},
17584 {"fxs", PSR_f | PSR_x | PSR_s},
17585 {"fxc", PSR_f | PSR_x | PSR_c},
17586 {"fcs", PSR_f | PSR_c | PSR_s},
17587 {"fcx", PSR_f | PSR_c | PSR_x},
17588 {"sfx", PSR_s | PSR_f | PSR_x},
17589 {"sfc", PSR_s | PSR_f | PSR_c},
17590 {"sxf", PSR_s | PSR_x | PSR_f},
17591 {"sxc", PSR_s | PSR_x | PSR_c},
17592 {"scf", PSR_s | PSR_c | PSR_f},
17593 {"scx", PSR_s | PSR_c | PSR_x},
17594 {"xfs", PSR_x | PSR_f | PSR_s},
17595 {"xfc", PSR_x | PSR_f | PSR_c},
17596 {"xsf", PSR_x | PSR_s | PSR_f},
17597 {"xsc", PSR_x | PSR_s | PSR_c},
17598 {"xcf", PSR_x | PSR_c | PSR_f},
17599 {"xcs", PSR_x | PSR_c | PSR_s},
17600 {"cfs", PSR_c | PSR_f | PSR_s},
17601 {"cfx", PSR_c | PSR_f | PSR_x},
17602 {"csf", PSR_c | PSR_s | PSR_f},
17603 {"csx", PSR_c | PSR_s | PSR_x},
17604 {"cxf", PSR_c | PSR_x | PSR_f},
17605 {"cxs", PSR_c | PSR_x | PSR_s},
17606 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
17607 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
17608 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
17609 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
17610 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
17611 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
17612 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
17613 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
17614 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
17615 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
17616 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
17617 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
17618 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
17619 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
17620 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
17621 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
17622 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
17623 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
17624 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
17625 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
17626 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
17627 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
17628 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
17629 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
17630};
17631
62b3e311
PB
17632/* Table of V7M psr names. */
17633static const struct asm_psr v7m_psrs[] =
17634{
2b744c99
PB
17635 {"apsr", 0 }, {"APSR", 0 },
17636 {"iapsr", 1 }, {"IAPSR", 1 },
17637 {"eapsr", 2 }, {"EAPSR", 2 },
17638 {"psr", 3 }, {"PSR", 3 },
17639 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
17640 {"ipsr", 5 }, {"IPSR", 5 },
17641 {"epsr", 6 }, {"EPSR", 6 },
17642 {"iepsr", 7 }, {"IEPSR", 7 },
17643 {"msp", 8 }, {"MSP", 8 },
17644 {"psp", 9 }, {"PSP", 9 },
17645 {"primask", 16}, {"PRIMASK", 16},
17646 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
17647 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
17648 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99
PB
17649 {"faultmask", 19}, {"FAULTMASK", 19},
17650 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
17651};
17652
c19d1205
ZW
17653/* Table of all shift-in-operand names. */
17654static const struct asm_shift_name shift_names [] =
b99bd4ef 17655{
c19d1205
ZW
17656 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
17657 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
17658 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
17659 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
17660 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
17661 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
17662};
b99bd4ef 17663
c19d1205
ZW
17664/* Table of all explicit relocation names. */
17665#ifdef OBJ_ELF
17666static struct reloc_entry reloc_names[] =
17667{
17668 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
17669 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
17670 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
17671 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
17672 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
17673 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
17674 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
17675 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
17676 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
17677 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 17678 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
17679 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
17680 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
17681 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
17682 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
17683 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
17684 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
17685 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
17686};
17687#endif
b99bd4ef 17688
c19d1205
ZW
17689/* Table of all conditional affixes. 0xF is not defined as a condition code. */
17690static const struct asm_cond conds[] =
17691{
17692 {"eq", 0x0},
17693 {"ne", 0x1},
17694 {"cs", 0x2}, {"hs", 0x2},
17695 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
17696 {"mi", 0x4},
17697 {"pl", 0x5},
17698 {"vs", 0x6},
17699 {"vc", 0x7},
17700 {"hi", 0x8},
17701 {"ls", 0x9},
17702 {"ge", 0xa},
17703 {"lt", 0xb},
17704 {"gt", 0xc},
17705 {"le", 0xd},
17706 {"al", 0xe}
17707};
bfae80f2 17708
e797f7e0
MGD
17709#define UL_BARRIER(L,U,CODE,FEAT) \
17710 { L, CODE, ARM_FEATURE (FEAT, 0) }, \
17711 { U, CODE, ARM_FEATURE (FEAT, 0) }
17712
62b3e311
PB
17713static struct asm_barrier_opt barrier_opt_names[] =
17714{
e797f7e0
MGD
17715 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
17716 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
17717 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
17718 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
17719 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
17720 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
17721 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
17722 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
17723 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
17724 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
17725 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
17726 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
17727 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
17728 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
17729 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
17730 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
17731};
17732
e797f7e0
MGD
17733#undef UL_BARRIER
17734
c19d1205
ZW
17735/* Table of ARM-format instructions. */
17736
17737/* Macros for gluing together operand strings. N.B. In all cases
17738 other than OPS0, the trailing OP_stop comes from default
17739 zero-initialization of the unspecified elements of the array. */
17740#define OPS0() { OP_stop, }
17741#define OPS1(a) { OP_##a, }
17742#define OPS2(a,b) { OP_##a,OP_##b, }
17743#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
17744#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
17745#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
17746#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
17747
5be8be5d
DG
17748/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
17749 This is useful when mixing operands for ARM and THUMB, i.e. using the
17750 MIX_ARM_THUMB_OPERANDS macro.
17751 In order to use these macros, prefix the number of operands with _
17752 e.g. _3. */
17753#define OPS_1(a) { a, }
17754#define OPS_2(a,b) { a,b, }
17755#define OPS_3(a,b,c) { a,b,c, }
17756#define OPS_4(a,b,c,d) { a,b,c,d, }
17757#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
17758#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
17759
c19d1205
ZW
17760/* These macros abstract out the exact format of the mnemonic table and
17761 save some repeated characters. */
17762
17763/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
17764#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 17765 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 17766 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
17767
17768/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
17769 a T_MNEM_xyz enumerator. */
17770#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 17771 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 17772#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 17773 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
17774
17775/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
17776 infix after the third character. */
17777#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 17778 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 17779 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 17780#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 17781 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 17782 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 17783#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 17784 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 17785#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 17786 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 17787#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 17788 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 17789#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 17790 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 17791
c19d1205 17792/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
17793 field is still 0xE. Many of the Thumb variants can be executed
17794 conditionally, so this is checked separately. */
c19d1205 17795#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 17796 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 17797 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
17798
17799/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
17800 condition code field. */
17801#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 17802 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 17803 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
17804
17805/* ARM-only variants of all the above. */
6a86118a 17806#define CE(mnem, op, nops, ops, ae) \
21d799b5 17807 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
17808
17809#define C3(mnem, op, nops, ops, ae) \
17810 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17811
e3cb604e
PB
17812/* Legacy mnemonics that always have conditional infix after the third
17813 character. */
17814#define CL(mnem, op, nops, ops, ae) \
21d799b5 17815 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
17816 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17817
8f06b2d8
PB
17818/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
17819#define cCE(mnem, op, nops, ops, ae) \
21d799b5 17820 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 17821
e3cb604e
PB
17822/* Legacy coprocessor instructions where conditional infix and conditional
17823 suffix are ambiguous. For consistency this includes all FPA instructions,
17824 not just the potentially ambiguous ones. */
17825#define cCL(mnem, op, nops, ops, ae) \
21d799b5 17826 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
17827 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17828
17829/* Coprocessor, takes either a suffix or a position-3 infix
17830 (for an FPA corner case). */
17831#define C3E(mnem, op, nops, ops, ae) \
21d799b5 17832 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 17833 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 17834
6a86118a 17835#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
17836 { m1 #m2 m3, OPS##nops ops, \
17837 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
17838 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17839
17840#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
17841 xCM_ (m1, , m2, op, nops, ops, ae), \
17842 xCM_ (m1, eq, m2, op, nops, ops, ae), \
17843 xCM_ (m1, ne, m2, op, nops, ops, ae), \
17844 xCM_ (m1, cs, m2, op, nops, ops, ae), \
17845 xCM_ (m1, hs, m2, op, nops, ops, ae), \
17846 xCM_ (m1, cc, m2, op, nops, ops, ae), \
17847 xCM_ (m1, ul, m2, op, nops, ops, ae), \
17848 xCM_ (m1, lo, m2, op, nops, ops, ae), \
17849 xCM_ (m1, mi, m2, op, nops, ops, ae), \
17850 xCM_ (m1, pl, m2, op, nops, ops, ae), \
17851 xCM_ (m1, vs, m2, op, nops, ops, ae), \
17852 xCM_ (m1, vc, m2, op, nops, ops, ae), \
17853 xCM_ (m1, hi, m2, op, nops, ops, ae), \
17854 xCM_ (m1, ls, m2, op, nops, ops, ae), \
17855 xCM_ (m1, ge, m2, op, nops, ops, ae), \
17856 xCM_ (m1, lt, m2, op, nops, ops, ae), \
17857 xCM_ (m1, gt, m2, op, nops, ops, ae), \
17858 xCM_ (m1, le, m2, op, nops, ops, ae), \
17859 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
17860
17861#define UE(mnem, op, nops, ops, ae) \
17862 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17863
17864#define UF(mnem, op, nops, ops, ae) \
17865 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17866
5287ad62
JB
17867/* Neon data-processing. ARM versions are unconditional with cond=0xf.
17868 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
17869 use the same encoding function for each. */
17870#define NUF(mnem, op, nops, ops, enc) \
17871 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
17872 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17873
17874/* Neon data processing, version which indirects through neon_enc_tab for
17875 the various overloaded versions of opcodes. */
17876#define nUF(mnem, op, nops, ops, enc) \
21d799b5 17877 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
17878 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17879
17880/* Neon insn with conditional suffix for the ARM version, non-overloaded
17881 version. */
037e8744
JB
17882#define NCE_tag(mnem, op, nops, ops, enc, tag) \
17883 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
17884 THUMB_VARIANT, do_##enc, do_##enc }
17885
037e8744 17886#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 17887 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
17888
17889#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 17890 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 17891
5287ad62 17892/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 17893#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 17894 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
17895 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17896
037e8744 17897#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 17898 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
17899
17900#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 17901 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 17902
c19d1205
ZW
17903#define do_0 0
17904
c19d1205 17905static const struct asm_opcode insns[] =
bfae80f2 17906{
e74cfd16
PB
17907#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
17908#define THUMB_VARIANT &arm_ext_v4t
21d799b5
NC
17909 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
17910 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
17911 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
17912 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
17913 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
17914 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
17915 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
17916 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
17917 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
17918 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
17919 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
17920 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
17921 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
17922 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
17923 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
17924 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
17925
17926 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
17927 for setting PSR flag bits. They are obsolete in V6 and do not
17928 have Thumb equivalents. */
21d799b5
NC
17929 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17930 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17931 CL("tstp", 110f000, 2, (RR, SH), cmp),
17932 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17933 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17934 CL("cmpp", 150f000, 2, (RR, SH), cmp),
17935 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17936 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17937 CL("cmnp", 170f000, 2, (RR, SH), cmp),
17938
17939 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
17940 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
17941 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
17942 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
17943
17944 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
17945 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17946 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
17947 OP_RRnpc),
17948 OP_ADDRGLDR),ldst, t_ldst),
17949 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
17950
17951 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17952 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17953 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17954 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17955 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17956 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17957
17958 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
17959 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
17960 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
17961 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 17962
c19d1205 17963 /* Pseudo ops. */
21d799b5 17964 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 17965 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 17966 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
17967
17968 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
17969 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
17970 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
17971 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
17972 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
17973 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
17974 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
17975 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
17976 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
17977 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
17978 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
17979 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
17980 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 17981
16a4cf17 17982 /* These may simplify to neg. */
21d799b5
NC
17983 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
17984 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 17985
c921be7d
NC
17986#undef THUMB_VARIANT
17987#define THUMB_VARIANT & arm_ext_v6
17988
21d799b5 17989 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
17990
17991 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
17992#undef THUMB_VARIANT
17993#define THUMB_VARIANT & arm_ext_v6t2
17994
21d799b5
NC
17995 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17996 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17997 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 17998
5be8be5d
DG
17999 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18000 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18001 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
18002 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 18003
21d799b5
NC
18004 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18005 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 18006
21d799b5
NC
18007 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18008 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
18009
18010 /* V1 instructions with no Thumb analogue at all. */
21d799b5 18011 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
18012 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
18013
18014 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
18015 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
18016 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
18017 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
18018 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
18019 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
18020 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
18021 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
18022
c921be7d
NC
18023#undef ARM_VARIANT
18024#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
18025#undef THUMB_VARIANT
18026#define THUMB_VARIANT & arm_ext_v4t
18027
21d799b5
NC
18028 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
18029 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 18030
c921be7d
NC
18031#undef THUMB_VARIANT
18032#define THUMB_VARIANT & arm_ext_v6t2
18033
21d799b5 18034 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
18035 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
18036
18037 /* Generic coprocessor instructions. */
21d799b5
NC
18038 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18039 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18040 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18041 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18042 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18043 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 18044 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 18045
c921be7d
NC
18046#undef ARM_VARIANT
18047#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
18048
21d799b5 18049 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
18050 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
18051
c921be7d
NC
18052#undef ARM_VARIANT
18053#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
18054#undef THUMB_VARIANT
18055#define THUMB_VARIANT & arm_ext_msr
18056
d2cd1205
JB
18057 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
18058 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 18059
c921be7d
NC
18060#undef ARM_VARIANT
18061#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
18062#undef THUMB_VARIANT
18063#define THUMB_VARIANT & arm_ext_v6t2
18064
21d799b5
NC
18065 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18066 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18067 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18068 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18069 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18070 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18071 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18072 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 18073
c921be7d
NC
18074#undef ARM_VARIANT
18075#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
18076#undef THUMB_VARIANT
18077#define THUMB_VARIANT & arm_ext_v4t
18078
5be8be5d
DG
18079 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18080 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18081 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18082 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
18083 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18084 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 18085
c921be7d
NC
18086#undef ARM_VARIANT
18087#define ARM_VARIANT & arm_ext_v4t_5
18088
c19d1205
ZW
18089 /* ARM Architecture 4T. */
18090 /* Note: bx (and blx) are required on V5, even if the processor does
18091 not support Thumb. */
21d799b5 18092 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 18093
c921be7d
NC
18094#undef ARM_VARIANT
18095#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
18096#undef THUMB_VARIANT
18097#define THUMB_VARIANT & arm_ext_v5t
18098
c19d1205
ZW
18099 /* Note: blx has 2 variants; the .value coded here is for
18100 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
18101 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
18102 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 18103
c921be7d
NC
18104#undef THUMB_VARIANT
18105#define THUMB_VARIANT & arm_ext_v6t2
18106
21d799b5
NC
18107 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
18108 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18109 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18110 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18111 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18112 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18113 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18114 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 18115
c921be7d
NC
18116#undef ARM_VARIANT
18117#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
9e3c6df6
PB
18118#undef THUMB_VARIANT
18119#define THUMB_VARIANT &arm_ext_v5exp
c921be7d 18120
21d799b5
NC
18121 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18122 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18123 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18124 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 18125
21d799b5
NC
18126 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18127 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 18128
21d799b5
NC
18129 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18130 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18131 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18132 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 18133
21d799b5
NC
18134 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18135 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18136 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18137 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 18138
21d799b5
NC
18139 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18140 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 18141
03ee1b7f
NC
18142 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18143 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18144 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18145 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 18146
c921be7d
NC
18147#undef ARM_VARIANT
18148#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
9e3c6df6
PB
18149#undef THUMB_VARIANT
18150#define THUMB_VARIANT &arm_ext_v6t2
c921be7d 18151
21d799b5 18152 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
18153 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
18154 ldrd, t_ldstd),
18155 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
18156 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 18157
21d799b5
NC
18158 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18159 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 18160
c921be7d
NC
18161#undef ARM_VARIANT
18162#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
18163
21d799b5 18164 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 18165
c921be7d
NC
18166#undef ARM_VARIANT
18167#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
18168#undef THUMB_VARIANT
18169#define THUMB_VARIANT & arm_ext_v6
18170
21d799b5
NC
18171 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
18172 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
18173 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18174 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18175 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18176 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18177 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18178 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18179 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18180 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 18181
c921be7d
NC
18182#undef THUMB_VARIANT
18183#define THUMB_VARIANT & arm_ext_v6t2
18184
5be8be5d
DG
18185 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
18186 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
18187 strex, t_strex),
21d799b5
NC
18188 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18189 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 18190
21d799b5
NC
18191 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
18192 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 18193
9e3c6df6 18194/* ARM V6 not included in V7M. */
c921be7d
NC
18195#undef THUMB_VARIANT
18196#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 18197 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 18198 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
18199 UF(rfeib, 9900a00, 1, (RRw), rfe),
18200 UF(rfeda, 8100a00, 1, (RRw), rfe),
18201 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18202 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
18203 UF(rfefa, 8100a00, 1, (RRw), rfe),
18204 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18205 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 18206 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
18207 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18208 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 18209 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 18210 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 18211 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 18212 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 18213 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 18214 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 18215
9e3c6df6
PB
18216/* ARM V6 not included in V7M (eg. integer SIMD). */
18217#undef THUMB_VARIANT
18218#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
18219 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
18220 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
18221 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
18222 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18223 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18224 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18225 /* Old name for QASX. */
21d799b5
NC
18226 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18227 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18228 /* Old name for QSAX. */
21d799b5
NC
18229 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18230 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18231 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18232 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18233 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18234 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18235 /* Old name for SASX. */
21d799b5
NC
18236 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18237 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18238 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18239 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18240 /* Old name for SHASX. */
21d799b5
NC
18241 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18242 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18243 /* Old name for SHSAX. */
21d799b5
NC
18244 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18245 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18246 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18247 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18248 /* Old name for SSAX. */
21d799b5
NC
18249 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18250 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18251 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18252 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18253 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18254 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18255 /* Old name for UASX. */
21d799b5
NC
18256 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18257 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18258 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18259 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18260 /* Old name for UHASX. */
21d799b5
NC
18261 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18262 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18263 /* Old name for UHSAX. */
21d799b5
NC
18264 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18265 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18266 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18267 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18268 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18269 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18270 /* Old name for UQASX. */
21d799b5
NC
18271 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18272 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18273 /* Old name for UQSAX. */
21d799b5
NC
18274 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18275 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18276 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18277 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18278 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18279 /* Old name for USAX. */
21d799b5
NC
18280 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18281 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18282 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18283 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18284 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18285 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18286 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18287 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18288 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18289 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18290 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18291 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18292 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18293 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18294 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18295 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18296 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18297 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18298 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18299 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18300 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18301 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18302 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18303 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18304 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18305 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18306 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18307 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18308 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
18309 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
18310 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
18311 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18312 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18313 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 18314
c921be7d
NC
18315#undef ARM_VARIANT
18316#define ARM_VARIANT & arm_ext_v6k
18317#undef THUMB_VARIANT
18318#define THUMB_VARIANT & arm_ext_v6k
18319
21d799b5
NC
18320 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
18321 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
18322 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
18323 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 18324
c921be7d
NC
18325#undef THUMB_VARIANT
18326#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
18327 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
18328 ldrexd, t_ldrexd),
18329 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
18330 RRnpcb), strexd, t_strexd),
ebdca51a 18331
c921be7d
NC
18332#undef THUMB_VARIANT
18333#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
18334 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
18335 rd_rn, rd_rn),
18336 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
18337 rd_rn, rd_rn),
18338 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 18339 strex, t_strexbh),
5be8be5d 18340 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 18341 strex, t_strexbh),
21d799b5 18342 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 18343
c921be7d 18344#undef ARM_VARIANT
f4c65163
MGD
18345#define ARM_VARIANT & arm_ext_sec
18346#undef THUMB_VARIANT
18347#define THUMB_VARIANT & arm_ext_sec
c921be7d 18348
21d799b5 18349 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 18350
90ec0d68
MGD
18351#undef ARM_VARIANT
18352#define ARM_VARIANT & arm_ext_virt
18353#undef THUMB_VARIANT
18354#define THUMB_VARIANT & arm_ext_virt
18355
18356 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
18357 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
18358
c921be7d
NC
18359#undef ARM_VARIANT
18360#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
18361#undef THUMB_VARIANT
18362#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 18363
21d799b5
NC
18364 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
18365 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
18366 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
18367 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 18368
21d799b5
NC
18369 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
18370 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
18371 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
18372 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 18373
5be8be5d
DG
18374 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18375 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18376 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18377 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 18378
bf3eeda7
NS
18379 /* Thumb-only instructions. */
18380#undef ARM_VARIANT
18381#define ARM_VARIANT NULL
18382 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
18383 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
18384
18385 /* ARM does not really have an IT instruction, so always allow it.
18386 The opcode is copied from Thumb in order to allow warnings in
18387 -mimplicit-it=[never | arm] modes. */
18388#undef ARM_VARIANT
18389#define ARM_VARIANT & arm_ext_v1
18390
21d799b5
NC
18391 TUE("it", bf08, bf08, 1, (COND), it, t_it),
18392 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
18393 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
18394 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
18395 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
18396 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
18397 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
18398 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
18399 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
18400 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
18401 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
18402 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
18403 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
18404 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
18405 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 18406 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
18407 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
18408 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 18409
92e90b6e 18410 /* Thumb2 only instructions. */
c921be7d
NC
18411#undef ARM_VARIANT
18412#define ARM_VARIANT NULL
92e90b6e 18413
21d799b5
NC
18414 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
18415 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
18416 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
18417 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
18418 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
18419 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 18420
eea54501
MGD
18421 /* Hardware division instructions. */
18422#undef ARM_VARIANT
18423#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
18424#undef THUMB_VARIANT
18425#define THUMB_VARIANT & arm_ext_div
18426
eea54501
MGD
18427 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
18428 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 18429
7e806470 18430 /* ARM V6M/V7 instructions. */
c921be7d
NC
18431#undef ARM_VARIANT
18432#define ARM_VARIANT & arm_ext_barrier
18433#undef THUMB_VARIANT
18434#define THUMB_VARIANT & arm_ext_barrier
18435
52e7f43d
RE
18436 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
18437 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
18438 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
7e806470 18439
62b3e311 18440 /* ARM V7 instructions. */
c921be7d
NC
18441#undef ARM_VARIANT
18442#define ARM_VARIANT & arm_ext_v7
18443#undef THUMB_VARIANT
18444#define THUMB_VARIANT & arm_ext_v7
18445
21d799b5
NC
18446 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
18447 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 18448
60e5ef9f
MGD
18449#undef ARM_VARIANT
18450#define ARM_VARIANT & arm_ext_mp
18451#undef THUMB_VARIANT
18452#define THUMB_VARIANT & arm_ext_mp
18453
18454 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
18455
53c4b28b
MGD
18456 /* AArchv8 instructions. */
18457#undef ARM_VARIANT
18458#define ARM_VARIANT & arm_ext_v8
18459#undef THUMB_VARIANT
18460#define THUMB_VARIANT & arm_ext_v8
18461
18462 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
8884b720 18463 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
4b8c8c02
RE
18464 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18465 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
9eb6c0f1 18466 ldrexd, t_ldrexd),
4b8c8c02
RE
18467 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
18468 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18469 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
18470 stlex, t_stlex),
18471 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
9eb6c0f1 18472 strexd, t_strexd),
4b8c8c02
RE
18473 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
18474 stlex, t_stlex),
18475 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
18476 stlex, t_stlex),
18477 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18478 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18479 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18480 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
18481 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
18482 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
53c4b28b 18483
8884b720 18484 /* ARMv8 T32 only. */
b79f7053
MGD
18485#undef ARM_VARIANT
18486#define ARM_VARIANT NULL
18487 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
18488 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
18489 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
18490
33399f07
MGD
18491 /* FP for ARMv8. */
18492#undef ARM_VARIANT
18493#define ARM_VARIANT & fpu_vfp_ext_armv8
18494#undef THUMB_VARIANT
18495#define THUMB_VARIANT & fpu_vfp_ext_armv8
18496
18497 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
18498 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
18499 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
18500 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
18501 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
18502 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
18503 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
18504 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
18505 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
18506 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
18507 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
18508 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
18509 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
18510 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
18511 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
18512 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
18513 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 18514
91ff7894
MGD
18515 /* Crypto v1 extensions. */
18516#undef ARM_VARIANT
18517#define ARM_VARIANT & fpu_crypto_ext_armv8
18518#undef THUMB_VARIANT
18519#define THUMB_VARIANT & fpu_crypto_ext_armv8
18520
18521 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
18522 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
18523 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
18524 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
18525 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
18526 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
18527 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
18528 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
18529 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
18530 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
18531 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
18532 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
18533 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
18534 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 18535
c921be7d
NC
18536#undef ARM_VARIANT
18537#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
18538#undef THUMB_VARIANT
18539#define THUMB_VARIANT NULL
c921be7d 18540
21d799b5
NC
18541 cCE("wfs", e200110, 1, (RR), rd),
18542 cCE("rfs", e300110, 1, (RR), rd),
18543 cCE("wfc", e400110, 1, (RR), rd),
18544 cCE("rfc", e500110, 1, (RR), rd),
18545
18546 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
18547 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
18548 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
18549 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
18550
18551 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
18552 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
18553 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
18554 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
18555
18556 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
18557 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
18558 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
18559 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
18560 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
18561 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
18562 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
18563 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
18564 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
18565 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
18566 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
18567 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
18568
18569 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
18570 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
18571 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
18572 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
18573 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
18574 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
18575 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
18576 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
18577 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
18578 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
18579 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
18580 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
18581
18582 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
18583 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
18584 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
18585 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
18586 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
18587 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
18588 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
18589 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
18590 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
18591 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
18592 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
18593 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
18594
18595 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
18596 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
18597 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
18598 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
18599 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
18600 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
18601 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
18602 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
18603 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
18604 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
18605 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
18606 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
18607
18608 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
18609 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
18610 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
18611 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
18612 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
18613 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
18614 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
18615 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
18616 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
18617 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
18618 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
18619 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
18620
18621 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
18622 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
18623 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
18624 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
18625 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
18626 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
18627 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
18628 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
18629 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
18630 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
18631 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
18632 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
18633
18634 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
18635 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
18636 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
18637 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
18638 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
18639 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
18640 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
18641 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
18642 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
18643 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
18644 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
18645 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
18646
18647 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
18648 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
18649 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
18650 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
18651 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
18652 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
18653 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
18654 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
18655 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
18656 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
18657 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
18658 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
18659
18660 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
18661 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
18662 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
18663 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
18664 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
18665 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
18666 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
18667 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
18668 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
18669 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
18670 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
18671 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
18672
18673 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
18674 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
18675 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
18676 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
18677 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
18678 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
18679 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
18680 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
18681 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
18682 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
18683 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
18684 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
18685
18686 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
18687 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
18688 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
18689 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
18690 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
18691 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
18692 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
18693 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
18694 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
18695 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
18696 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
18697 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
18698
18699 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
18700 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
18701 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
18702 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
18703 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
18704 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
18705 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
18706 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
18707 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
18708 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
18709 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
18710 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
18711
18712 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
18713 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
18714 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
18715 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
18716 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
18717 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
18718 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
18719 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
18720 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
18721 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
18722 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
18723 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
18724
18725 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
18726 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
18727 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
18728 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
18729 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
18730 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
18731 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
18732 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
18733 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
18734 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
18735 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
18736 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
18737
18738 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
18739 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
18740 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
18741 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
18742 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
18743 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
18744 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
18745 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
18746 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
18747 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
18748 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
18749 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
18750
18751 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
18752 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
18753 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
18754 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
18755 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
18756 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
18757 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
18758 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
18759 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
18760 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
18761 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
18762 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
18763
18764 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
18765 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
18766 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
18767 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
18768 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
18769 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18770 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18771 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18772 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
18773 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
18774 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
18775 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
18776
18777 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
18778 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
18779 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
18780 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
18781 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
18782 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18783 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18784 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18785 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
18786 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
18787 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
18788 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
18789
18790 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
18791 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
18792 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
18793 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
18794 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
18795 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18796 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18797 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18798 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
18799 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
18800 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
18801 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
18802
18803 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
18804 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
18805 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
18806 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
18807 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
18808 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18809 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18810 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18811 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
18812 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
18813 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
18814 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
18815
18816 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
18817 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
18818 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
18819 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
18820 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
18821 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18822 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18823 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18824 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
18825 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
18826 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
18827 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
18828
18829 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
18830 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
18831 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
18832 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
18833 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
18834 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18835 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18836 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18837 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
18838 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
18839 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
18840 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
18841
18842 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
18843 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
18844 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
18845 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
18846 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
18847 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18848 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18849 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18850 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
18851 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
18852 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
18853 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
18854
18855 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
18856 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
18857 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
18858 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
18859 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
18860 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18861 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18862 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18863 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
18864 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
18865 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
18866 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
18867
18868 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
18869 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
18870 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
18871 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
18872 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
18873 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18874 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18875 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18876 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
18877 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
18878 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
18879 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
18880
18881 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
18882 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
18883 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
18884 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
18885 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
18886 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18887 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18888 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18889 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
18890 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
18891 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
18892 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
18893
18894 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18895 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18896 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18897 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18898 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18899 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18900 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18901 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18902 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18903 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18904 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18905 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18906
18907 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18908 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18909 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18910 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18911 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18912 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18913 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18914 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18915 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18916 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18917 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18918 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18919
18920 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18921 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18922 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18923 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18924 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18925 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18926 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18927 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18928 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18929 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18930 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18931 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18932
18933 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
18934 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
18935 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
18936 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
18937
18938 cCL("flts", e000110, 2, (RF, RR), rn_rd),
18939 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
18940 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
18941 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
18942 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
18943 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
18944 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
18945 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
18946 cCL("flte", e080110, 2, (RF, RR), rn_rd),
18947 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
18948 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
18949 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 18950
c19d1205
ZW
18951 /* The implementation of the FIX instruction is broken on some
18952 assemblers, in that it accepts a precision specifier as well as a
18953 rounding specifier, despite the fact that this is meaningless.
18954 To be more compatible, we accept it as well, though of course it
18955 does not set any bits. */
21d799b5
NC
18956 cCE("fix", e100110, 2, (RR, RF), rd_rm),
18957 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
18958 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
18959 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
18960 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
18961 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
18962 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
18963 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
18964 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
18965 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
18966 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
18967 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
18968 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 18969
c19d1205 18970 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
18971#undef ARM_VARIANT
18972#define ARM_VARIANT & fpu_fpa_ext_v2
18973
21d799b5
NC
18974 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18975 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18976 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18977 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18978 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18979 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 18980
c921be7d
NC
18981#undef ARM_VARIANT
18982#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
18983
c19d1205 18984 /* Moves and type conversions. */
21d799b5
NC
18985 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
18986 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
18987 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
18988 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
18989 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
18990 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
18991 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
18992 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
18993 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
18994 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18995 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
18996 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18997 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
18998 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
18999
19000 /* Memory operations. */
21d799b5
NC
19001 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
19002 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
19003 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19004 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19005 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19006 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19007 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19008 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19009 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19010 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19011 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19012 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19013 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19014 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19015 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19016 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19017 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19018 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 19019
c19d1205 19020 /* Monadic operations. */
21d799b5
NC
19021 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
19022 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
19023 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
19024
19025 /* Dyadic operations. */
21d799b5
NC
19026 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19027 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19028 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19029 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19030 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19031 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19032 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19033 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19034 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 19035
c19d1205 19036 /* Comparisons. */
21d799b5
NC
19037 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
19038 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
19039 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
19040 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 19041
62f3b8c8
PB
19042 /* Double precision load/store are still present on single precision
19043 implementations. */
19044 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
19045 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
19046 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19047 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19048 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19049 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19050 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19051 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19052 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19053 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 19054
c921be7d
NC
19055#undef ARM_VARIANT
19056#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
19057
c19d1205 19058 /* Moves and type conversions. */
21d799b5
NC
19059 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19060 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19061 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19062 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
19063 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
19064 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
19065 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
19066 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19067 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
19068 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19069 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19070 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19071 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 19072
c19d1205 19073 /* Monadic operations. */
21d799b5
NC
19074 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19075 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19076 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
19077
19078 /* Dyadic operations. */
21d799b5
NC
19079 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19080 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19081 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19082 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19083 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19084 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19085 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19086 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19087 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 19088
c19d1205 19089 /* Comparisons. */
21d799b5
NC
19090 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19091 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
19092 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19093 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 19094
c921be7d
NC
19095#undef ARM_VARIANT
19096#define ARM_VARIANT & fpu_vfp_ext_v2
19097
21d799b5
NC
19098 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
19099 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
19100 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
19101 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 19102
037e8744
JB
19103/* Instructions which may belong to either the Neon or VFP instruction sets.
19104 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
19105#undef ARM_VARIANT
19106#define ARM_VARIANT & fpu_vfp_ext_v1xd
19107#undef THUMB_VARIANT
19108#define THUMB_VARIANT & fpu_vfp_ext_v1xd
19109
037e8744
JB
19110 /* These mnemonics are unique to VFP. */
19111 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
19112 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
19113 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19114 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19115 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19116 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
19117 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
19118 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
19119 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
19120 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
19121
19122 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
19123 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
19124 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
19125 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 19126
21d799b5
NC
19127 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
19128 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
19129
19130 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19131 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19132
55881a11
MGD
19133 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19134 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19135 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19136 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19137 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19138 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
19139 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
19140 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 19141
5f1af56b 19142 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 19143 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
19144 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
19145 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 19146
037e8744
JB
19147
19148 /* NOTE: All VMOV encoding is special-cased! */
19149 NCE(vmov, 0, 1, (VMOV), neon_mov),
19150 NCE(vmovq, 0, 1, (VMOV), neon_mov),
19151
c921be7d
NC
19152#undef THUMB_VARIANT
19153#define THUMB_VARIANT & fpu_neon_ext_v1
19154#undef ARM_VARIANT
19155#define ARM_VARIANT & fpu_neon_ext_v1
19156
5287ad62
JB
19157 /* Data processing with three registers of the same length. */
19158 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
19159 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
19160 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
19161 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19162 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19163 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19164 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19165 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19166 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19167 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
19168 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19169 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
19170 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19171 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
19172 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19173 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
19174 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19175 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
19176 /* If not immediate, fall back to neon_dyadic_i64_su.
19177 shl_imm should accept I8 I16 I32 I64,
19178 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
19179 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
19180 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
19181 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
19182 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 19183 /* Logic ops, types optional & ignored. */
4316f0d2
DG
19184 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19185 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19186 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19187 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19188 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19189 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19190 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19191 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19192 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
19193 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
19194 /* Bitfield ops, untyped. */
19195 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19196 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19197 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19198 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19199 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19200 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19201 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
19202 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19203 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19204 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19205 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19206 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19207 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
19208 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
19209 back to neon_dyadic_if_su. */
21d799b5
NC
19210 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19211 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19212 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19213 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19214 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19215 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
19216 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19217 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 19218 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
19219 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
19220 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 19221 /* As above, D registers only. */
21d799b5
NC
19222 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
19223 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 19224 /* Int and float variants, signedness unimportant. */
21d799b5
NC
19225 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19226 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19227 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 19228 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
19229 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
19230 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
19231 /* vtst takes sizes 8, 16, 32. */
19232 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
19233 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
19234 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 19235 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 19236 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
19237 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19238 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19239 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19240 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
19241 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19242 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
19243 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19244 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
19245 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19246 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
19247 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19248 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
19249 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19250 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19251 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19252 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19253
19254 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 19255 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
19256 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
19257
19258 /* Data processing with two registers and a shift amount. */
19259 /* Right shifts, and variants with rounding.
19260 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
19261 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19262 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19263 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19264 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19265 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19266 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19267 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19268 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19269 /* Shift and insert. Sizes accepted 8 16 32 64. */
19270 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
19271 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
19272 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
19273 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
19274 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
19275 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
19276 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
19277 /* Right shift immediate, saturating & narrowing, with rounding variants.
19278 Types accepted S16 S32 S64 U16 U32 U64. */
19279 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19280 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19281 /* As above, unsigned. Types accepted S16 S32 S64. */
19282 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19283 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19284 /* Right shift narrowing. Types accepted I16 I32 I64. */
19285 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19286 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19287 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 19288 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 19289 /* CVT with optional immediate for fixed-point variant. */
21d799b5 19290 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 19291
4316f0d2
DG
19292 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
19293 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
19294
19295 /* Data processing, three registers of different lengths. */
19296 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
19297 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
19298 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
19299 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
19300 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
19301 /* If not scalar, fall back to neon_dyadic_long.
19302 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
19303 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
19304 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
19305 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
19306 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
19307 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
19308 /* Dyadic, narrowing insns. Types I16 I32 I64. */
19309 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19310 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19311 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19312 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19313 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
19314 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
19315 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
19316 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
19317 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
19318 S16 S32 U16 U32. */
21d799b5 19319 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
19320
19321 /* Extract. Size 8. */
3b8d421e
PB
19322 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
19323 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
19324
19325 /* Two registers, miscellaneous. */
19326 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
19327 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
19328 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
19329 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
19330 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
19331 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
19332 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
19333 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
19334 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
19335 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
19336 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
19337 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
19338 /* VMOVN. Types I16 I32 I64. */
21d799b5 19339 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 19340 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 19341 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 19342 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 19343 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
19344 /* VZIP / VUZP. Sizes 8 16 32. */
19345 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
19346 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
19347 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
19348 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
19349 /* VQABS / VQNEG. Types S8 S16 S32. */
19350 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
19351 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
19352 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
19353 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
19354 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
19355 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
19356 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
19357 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
19358 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
19359 /* Reciprocal estimates. Types U32 F32. */
19360 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
19361 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
19362 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
19363 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
19364 /* VCLS. Types S8 S16 S32. */
19365 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
19366 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
19367 /* VCLZ. Types I8 I16 I32. */
19368 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
19369 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
19370 /* VCNT. Size 8. */
19371 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
19372 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
19373 /* Two address, untyped. */
19374 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
19375 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
19376 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
19377 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
19378 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
19379
19380 /* Table lookup. Size 8. */
19381 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
19382 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
19383
c921be7d
NC
19384#undef THUMB_VARIANT
19385#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
19386#undef ARM_VARIANT
19387#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
19388
5287ad62 19389 /* Neon element/structure load/store. */
21d799b5
NC
19390 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
19391 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
19392 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
19393 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
19394 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
19395 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
19396 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
19397 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 19398
c921be7d 19399#undef THUMB_VARIANT
62f3b8c8
PB
19400#define THUMB_VARIANT &fpu_vfp_ext_v3xd
19401#undef ARM_VARIANT
19402#define ARM_VARIANT &fpu_vfp_ext_v3xd
19403 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
19404 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19405 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19406 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19407 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19408 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19409 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19410 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19411 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19412
19413#undef THUMB_VARIANT
c921be7d
NC
19414#define THUMB_VARIANT & fpu_vfp_ext_v3
19415#undef ARM_VARIANT
19416#define ARM_VARIANT & fpu_vfp_ext_v3
19417
21d799b5 19418 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 19419 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 19420 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 19421 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 19422 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 19423 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 19424 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 19425 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 19426 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 19427
62f3b8c8
PB
19428#undef ARM_VARIANT
19429#define ARM_VARIANT &fpu_vfp_ext_fma
19430#undef THUMB_VARIANT
19431#define THUMB_VARIANT &fpu_vfp_ext_fma
19432 /* Mnemonics shared by Neon and VFP. These are included in the
19433 VFP FMA variant; NEON and VFP FMA always includes the NEON
19434 FMA instructions. */
19435 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
19436 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
19437 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
19438 the v form should always be used. */
19439 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19440 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19441 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19442 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19443 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19444 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19445
5287ad62 19446#undef THUMB_VARIANT
c921be7d
NC
19447#undef ARM_VARIANT
19448#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
19449
21d799b5
NC
19450 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19451 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19452 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19453 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19454 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19455 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19456 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
19457 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 19458
c921be7d
NC
19459#undef ARM_VARIANT
19460#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
19461
21d799b5
NC
19462 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
19463 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
19464 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
19465 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
19466 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
19467 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
19468 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
19469 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
19470 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
19471 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
19472 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
19473 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
19474 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
19475 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
19476 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
19477 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
19478 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
19479 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
19480 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
19481 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
19482 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19483 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19484 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19485 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19486 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19487 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19488 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
19489 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
19490 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
19491 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
19492 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
19493 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
19494 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
19495 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
19496 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
19497 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
19498 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
19499 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19500 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19501 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19502 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19503 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19504 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19505 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19506 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19507 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19508 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
19509 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19510 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19511 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19512 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19513 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19514 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19515 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19516 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19517 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19518 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19519 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19520 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19521 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19522 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19523 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19524 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19525 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19526 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19527 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19528 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19529 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19530 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
19531 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
19532 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19533 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19534 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19535 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19536 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19537 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19538 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19539 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19540 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19541 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19542 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19543 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19544 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19545 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19546 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19547 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19548 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19549 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19550 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
19551 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19552 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19553 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19554 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19555 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19556 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19557 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19558 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19559 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19560 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19561 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19562 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19563 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19564 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19565 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19566 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19567 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19568 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19569 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19570 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19571 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19572 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
19573 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19574 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19575 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19576 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19577 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19578 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19579 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19580 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19581 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19582 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19583 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19584 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19585 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19586 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19587 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19588 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19589 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19590 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19591 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19592 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19593 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
19594 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
19595 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19596 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19597 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19598 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19599 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19600 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19601 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19602 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19603 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19604 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
19605 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
19606 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
19607 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
19608 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
19609 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
19610 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19611 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19612 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19613 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
19614 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
19615 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
19616 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
19617 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
19618 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
19619 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19620 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19621 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19622 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19623 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 19624
c921be7d
NC
19625#undef ARM_VARIANT
19626#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
19627
21d799b5
NC
19628 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
19629 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
19630 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
19631 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
19632 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
19633 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
19634 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19635 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19636 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19637 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19638 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19639 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19640 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19641 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19642 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19643 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19644 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19645 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19646 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19647 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19648 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
19649 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19650 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19651 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19652 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19653 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19654 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19655 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19656 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19657 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19658 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19659 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19660 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19661 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19662 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19663 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19664 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19665 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19666 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19667 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19668 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19669 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19670 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19671 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19672 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19673 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19674 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19675 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19676 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19677 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19678 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19679 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19680 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19681 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19682 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19683 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19684 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 19685
c921be7d
NC
19686#undef ARM_VARIANT
19687#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
19688
21d799b5
NC
19689 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
19690 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
19691 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
19692 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
19693 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
19694 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
19695 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
19696 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
19697 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
19698 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
19699 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
19700 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
19701 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
19702 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
19703 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
19704 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
19705 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
19706 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
19707 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
19708 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
19709 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
19710 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
19711 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
19712 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
19713 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
19714 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
19715 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
19716 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
19717 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
19718 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
19719 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
19720 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
19721 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
19722 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
19723 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
19724 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
19725 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
19726 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
19727 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
19728 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
19729 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
19730 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
19731 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
19732 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
19733 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
19734 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
19735 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
19736 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
19737 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
19738 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
19739 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
19740 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
19741 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
19742 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
19743 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
19744 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
19745 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
19746 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
19747 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
19748 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
19749 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
19750 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
19751 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
19752 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
19753 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19754 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19755 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19756 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19757 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19758 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19759 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19760 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19761 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
19762 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
19763 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
19764 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
19765};
19766#undef ARM_VARIANT
19767#undef THUMB_VARIANT
19768#undef TCE
c19d1205
ZW
19769#undef TUE
19770#undef TUF
19771#undef TCC
8f06b2d8 19772#undef cCE
e3cb604e
PB
19773#undef cCL
19774#undef C3E
c19d1205
ZW
19775#undef CE
19776#undef CM
19777#undef UE
19778#undef UF
19779#undef UT
5287ad62
JB
19780#undef NUF
19781#undef nUF
19782#undef NCE
19783#undef nCE
c19d1205
ZW
19784#undef OPS0
19785#undef OPS1
19786#undef OPS2
19787#undef OPS3
19788#undef OPS4
19789#undef OPS5
19790#undef OPS6
19791#undef do_0
19792\f
19793/* MD interface: bits in the object file. */
bfae80f2 19794
c19d1205
ZW
19795/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
19796 for use in the a.out file, and stores them in the array pointed to by buf.
19797 This knows about the endian-ness of the target machine and does
19798 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
19799 2 (short) and 4 (long) Floating numbers are put out as a series of
19800 LITTLENUMS (shorts, here at least). */
b99bd4ef 19801
c19d1205
ZW
19802void
19803md_number_to_chars (char * buf, valueT val, int n)
19804{
19805 if (target_big_endian)
19806 number_to_chars_bigendian (buf, val, n);
19807 else
19808 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
19809}
19810
c19d1205
ZW
19811static valueT
19812md_chars_to_number (char * buf, int n)
bfae80f2 19813{
c19d1205
ZW
19814 valueT result = 0;
19815 unsigned char * where = (unsigned char *) buf;
bfae80f2 19816
c19d1205 19817 if (target_big_endian)
b99bd4ef 19818 {
c19d1205
ZW
19819 while (n--)
19820 {
19821 result <<= 8;
19822 result |= (*where++ & 255);
19823 }
b99bd4ef 19824 }
c19d1205 19825 else
b99bd4ef 19826 {
c19d1205
ZW
19827 while (n--)
19828 {
19829 result <<= 8;
19830 result |= (where[n] & 255);
19831 }
bfae80f2 19832 }
b99bd4ef 19833
c19d1205 19834 return result;
bfae80f2 19835}
b99bd4ef 19836
c19d1205 19837/* MD interface: Sections. */
b99bd4ef 19838
fa94de6b
RM
19839/* Calculate the maximum variable size (i.e., excluding fr_fix)
19840 that an rs_machine_dependent frag may reach. */
19841
19842unsigned int
19843arm_frag_max_var (fragS *fragp)
19844{
19845 /* We only use rs_machine_dependent for variable-size Thumb instructions,
19846 which are either THUMB_SIZE (2) or INSN_SIZE (4).
19847
19848 Note that we generate relaxable instructions even for cases that don't
19849 really need it, like an immediate that's a trivial constant. So we're
19850 overestimating the instruction size for some of those cases. Rather
19851 than putting more intelligence here, it would probably be better to
19852 avoid generating a relaxation frag in the first place when it can be
19853 determined up front that a short instruction will suffice. */
19854
19855 gas_assert (fragp->fr_type == rs_machine_dependent);
19856 return INSN_SIZE;
19857}
19858
0110f2b8
PB
19859/* Estimate the size of a frag before relaxing. Assume everything fits in
19860 2 bytes. */
19861
c19d1205 19862int
0110f2b8 19863md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
19864 segT segtype ATTRIBUTE_UNUSED)
19865{
0110f2b8
PB
19866 fragp->fr_var = 2;
19867 return 2;
19868}
19869
19870/* Convert a machine dependent frag. */
19871
19872void
19873md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
19874{
19875 unsigned long insn;
19876 unsigned long old_op;
19877 char *buf;
19878 expressionS exp;
19879 fixS *fixp;
19880 int reloc_type;
19881 int pc_rel;
19882 int opcode;
19883
19884 buf = fragp->fr_literal + fragp->fr_fix;
19885
19886 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
19887 if (fragp->fr_symbol)
19888 {
0110f2b8
PB
19889 exp.X_op = O_symbol;
19890 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
19891 }
19892 else
19893 {
0110f2b8 19894 exp.X_op = O_constant;
5f4273c7 19895 }
0110f2b8
PB
19896 exp.X_add_number = fragp->fr_offset;
19897 opcode = fragp->fr_subtype;
19898 switch (opcode)
19899 {
19900 case T_MNEM_ldr_pc:
19901 case T_MNEM_ldr_pc2:
19902 case T_MNEM_ldr_sp:
19903 case T_MNEM_str_sp:
19904 case T_MNEM_ldr:
19905 case T_MNEM_ldrb:
19906 case T_MNEM_ldrh:
19907 case T_MNEM_str:
19908 case T_MNEM_strb:
19909 case T_MNEM_strh:
19910 if (fragp->fr_var == 4)
19911 {
5f4273c7 19912 insn = THUMB_OP32 (opcode);
0110f2b8
PB
19913 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
19914 {
19915 insn |= (old_op & 0x700) << 4;
19916 }
19917 else
19918 {
19919 insn |= (old_op & 7) << 12;
19920 insn |= (old_op & 0x38) << 13;
19921 }
19922 insn |= 0x00000c00;
19923 put_thumb32_insn (buf, insn);
19924 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
19925 }
19926 else
19927 {
19928 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
19929 }
19930 pc_rel = (opcode == T_MNEM_ldr_pc2);
19931 break;
19932 case T_MNEM_adr:
19933 if (fragp->fr_var == 4)
19934 {
19935 insn = THUMB_OP32 (opcode);
19936 insn |= (old_op & 0xf0) << 4;
19937 put_thumb32_insn (buf, insn);
19938 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
19939 }
19940 else
19941 {
19942 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19943 exp.X_add_number -= 4;
19944 }
19945 pc_rel = 1;
19946 break;
19947 case T_MNEM_mov:
19948 case T_MNEM_movs:
19949 case T_MNEM_cmp:
19950 case T_MNEM_cmn:
19951 if (fragp->fr_var == 4)
19952 {
19953 int r0off = (opcode == T_MNEM_mov
19954 || opcode == T_MNEM_movs) ? 0 : 8;
19955 insn = THUMB_OP32 (opcode);
19956 insn = (insn & 0xe1ffffff) | 0x10000000;
19957 insn |= (old_op & 0x700) << r0off;
19958 put_thumb32_insn (buf, insn);
19959 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
19960 }
19961 else
19962 {
19963 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
19964 }
19965 pc_rel = 0;
19966 break;
19967 case T_MNEM_b:
19968 if (fragp->fr_var == 4)
19969 {
19970 insn = THUMB_OP32(opcode);
19971 put_thumb32_insn (buf, insn);
19972 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
19973 }
19974 else
19975 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
19976 pc_rel = 1;
19977 break;
19978 case T_MNEM_bcond:
19979 if (fragp->fr_var == 4)
19980 {
19981 insn = THUMB_OP32(opcode);
19982 insn |= (old_op & 0xf00) << 14;
19983 put_thumb32_insn (buf, insn);
19984 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
19985 }
19986 else
19987 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
19988 pc_rel = 1;
19989 break;
19990 case T_MNEM_add_sp:
19991 case T_MNEM_add_pc:
19992 case T_MNEM_inc_sp:
19993 case T_MNEM_dec_sp:
19994 if (fragp->fr_var == 4)
19995 {
19996 /* ??? Choose between add and addw. */
19997 insn = THUMB_OP32 (opcode);
19998 insn |= (old_op & 0xf0) << 4;
19999 put_thumb32_insn (buf, insn);
16805f35
PB
20000 if (opcode == T_MNEM_add_pc)
20001 reloc_type = BFD_RELOC_ARM_T32_IMM12;
20002 else
20003 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
20004 }
20005 else
20006 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20007 pc_rel = 0;
20008 break;
20009
20010 case T_MNEM_addi:
20011 case T_MNEM_addis:
20012 case T_MNEM_subi:
20013 case T_MNEM_subis:
20014 if (fragp->fr_var == 4)
20015 {
20016 insn = THUMB_OP32 (opcode);
20017 insn |= (old_op & 0xf0) << 4;
20018 insn |= (old_op & 0xf) << 16;
20019 put_thumb32_insn (buf, insn);
16805f35
PB
20020 if (insn & (1 << 20))
20021 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
20022 else
20023 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
20024 }
20025 else
20026 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20027 pc_rel = 0;
20028 break;
20029 default:
5f4273c7 20030 abort ();
0110f2b8
PB
20031 }
20032 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 20033 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
20034 fixp->fx_file = fragp->fr_file;
20035 fixp->fx_line = fragp->fr_line;
20036 fragp->fr_fix += fragp->fr_var;
20037}
20038
20039/* Return the size of a relaxable immediate operand instruction.
20040 SHIFT and SIZE specify the form of the allowable immediate. */
20041static int
20042relax_immediate (fragS *fragp, int size, int shift)
20043{
20044 offsetT offset;
20045 offsetT mask;
20046 offsetT low;
20047
20048 /* ??? Should be able to do better than this. */
20049 if (fragp->fr_symbol)
20050 return 4;
20051
20052 low = (1 << shift) - 1;
20053 mask = (1 << (shift + size)) - (1 << shift);
20054 offset = fragp->fr_offset;
20055 /* Force misaligned offsets to 32-bit variant. */
20056 if (offset & low)
5e77afaa 20057 return 4;
0110f2b8
PB
20058 if (offset & ~mask)
20059 return 4;
20060 return 2;
20061}
20062
5e77afaa
PB
20063/* Get the address of a symbol during relaxation. */
20064static addressT
5f4273c7 20065relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
20066{
20067 fragS *sym_frag;
20068 addressT addr;
20069 symbolS *sym;
20070
20071 sym = fragp->fr_symbol;
20072 sym_frag = symbol_get_frag (sym);
20073 know (S_GET_SEGMENT (sym) != absolute_section
20074 || sym_frag == &zero_address_frag);
20075 addr = S_GET_VALUE (sym) + fragp->fr_offset;
20076
20077 /* If frag has yet to be reached on this pass, assume it will
20078 move by STRETCH just as we did. If this is not so, it will
20079 be because some frag between grows, and that will force
20080 another pass. */
20081
20082 if (stretch != 0
20083 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
20084 {
20085 fragS *f;
20086
20087 /* Adjust stretch for any alignment frag. Note that if have
20088 been expanding the earlier code, the symbol may be
20089 defined in what appears to be an earlier frag. FIXME:
20090 This doesn't handle the fr_subtype field, which specifies
20091 a maximum number of bytes to skip when doing an
20092 alignment. */
20093 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
20094 {
20095 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
20096 {
20097 if (stretch < 0)
20098 stretch = - ((- stretch)
20099 & ~ ((1 << (int) f->fr_offset) - 1));
20100 else
20101 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
20102 if (stretch == 0)
20103 break;
20104 }
20105 }
20106 if (f != NULL)
20107 addr += stretch;
20108 }
5e77afaa
PB
20109
20110 return addr;
20111}
20112
0110f2b8
PB
20113/* Return the size of a relaxable adr pseudo-instruction or PC-relative
20114 load. */
20115static int
5e77afaa 20116relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
20117{
20118 addressT addr;
20119 offsetT val;
20120
20121 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
20122 if (fragp->fr_symbol == NULL
20123 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
20124 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20125 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
20126 return 4;
20127
5f4273c7 20128 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
20129 addr = fragp->fr_address + fragp->fr_fix;
20130 addr = (addr + 4) & ~3;
5e77afaa 20131 /* Force misaligned targets to 32-bit variant. */
0110f2b8 20132 if (val & 3)
5e77afaa 20133 return 4;
0110f2b8
PB
20134 val -= addr;
20135 if (val < 0 || val > 1020)
20136 return 4;
20137 return 2;
20138}
20139
20140/* Return the size of a relaxable add/sub immediate instruction. */
20141static int
20142relax_addsub (fragS *fragp, asection *sec)
20143{
20144 char *buf;
20145 int op;
20146
20147 buf = fragp->fr_literal + fragp->fr_fix;
20148 op = bfd_get_16(sec->owner, buf);
20149 if ((op & 0xf) == ((op >> 4) & 0xf))
20150 return relax_immediate (fragp, 8, 0);
20151 else
20152 return relax_immediate (fragp, 3, 0);
20153}
20154
20155
20156/* Return the size of a relaxable branch instruction. BITS is the
20157 size of the offset field in the narrow instruction. */
20158
20159static int
5e77afaa 20160relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
20161{
20162 addressT addr;
20163 offsetT val;
20164 offsetT limit;
20165
20166 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 20167 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
20168 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20169 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
20170 return 4;
20171
267bf995
RR
20172#ifdef OBJ_ELF
20173 if (S_IS_DEFINED (fragp->fr_symbol)
20174 && ARM_IS_FUNC (fragp->fr_symbol))
20175 return 4;
0d9b4b55
NC
20176
20177 /* PR 12532. Global symbols with default visibility might
20178 be preempted, so do not relax relocations to them. */
20179 if ((ELF_ST_VISIBILITY (S_GET_OTHER (fragp->fr_symbol)) == STV_DEFAULT)
20180 && (! S_IS_LOCAL (fragp->fr_symbol)))
20181 return 4;
267bf995
RR
20182#endif
20183
5f4273c7 20184 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
20185 addr = fragp->fr_address + fragp->fr_fix + 4;
20186 val -= addr;
20187
20188 /* Offset is a signed value *2 */
20189 limit = 1 << bits;
20190 if (val >= limit || val < -limit)
20191 return 4;
20192 return 2;
20193}
20194
20195
20196/* Relax a machine dependent frag. This returns the amount by which
20197 the current size of the frag should change. */
20198
20199int
5e77afaa 20200arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
20201{
20202 int oldsize;
20203 int newsize;
20204
20205 oldsize = fragp->fr_var;
20206 switch (fragp->fr_subtype)
20207 {
20208 case T_MNEM_ldr_pc2:
5f4273c7 20209 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
20210 break;
20211 case T_MNEM_ldr_pc:
20212 case T_MNEM_ldr_sp:
20213 case T_MNEM_str_sp:
5f4273c7 20214 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
20215 break;
20216 case T_MNEM_ldr:
20217 case T_MNEM_str:
5f4273c7 20218 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
20219 break;
20220 case T_MNEM_ldrh:
20221 case T_MNEM_strh:
5f4273c7 20222 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
20223 break;
20224 case T_MNEM_ldrb:
20225 case T_MNEM_strb:
5f4273c7 20226 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
20227 break;
20228 case T_MNEM_adr:
5f4273c7 20229 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
20230 break;
20231 case T_MNEM_mov:
20232 case T_MNEM_movs:
20233 case T_MNEM_cmp:
20234 case T_MNEM_cmn:
5f4273c7 20235 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
20236 break;
20237 case T_MNEM_b:
5f4273c7 20238 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
20239 break;
20240 case T_MNEM_bcond:
5f4273c7 20241 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
20242 break;
20243 case T_MNEM_add_sp:
20244 case T_MNEM_add_pc:
20245 newsize = relax_immediate (fragp, 8, 2);
20246 break;
20247 case T_MNEM_inc_sp:
20248 case T_MNEM_dec_sp:
20249 newsize = relax_immediate (fragp, 7, 2);
20250 break;
20251 case T_MNEM_addi:
20252 case T_MNEM_addis:
20253 case T_MNEM_subi:
20254 case T_MNEM_subis:
20255 newsize = relax_addsub (fragp, sec);
20256 break;
20257 default:
5f4273c7 20258 abort ();
0110f2b8 20259 }
5e77afaa
PB
20260
20261 fragp->fr_var = newsize;
20262 /* Freeze wide instructions that are at or before the same location as
20263 in the previous pass. This avoids infinite loops.
5f4273c7
NC
20264 Don't freeze them unconditionally because targets may be artificially
20265 misaligned by the expansion of preceding frags. */
5e77afaa 20266 if (stretch <= 0 && newsize > 2)
0110f2b8 20267 {
0110f2b8 20268 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 20269 frag_wane (fragp);
0110f2b8 20270 }
5e77afaa 20271
0110f2b8 20272 return newsize - oldsize;
c19d1205 20273}
b99bd4ef 20274
c19d1205 20275/* Round up a section size to the appropriate boundary. */
b99bd4ef 20276
c19d1205
ZW
20277valueT
20278md_section_align (segT segment ATTRIBUTE_UNUSED,
20279 valueT size)
20280{
f0927246
NC
20281#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
20282 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
20283 {
20284 /* For a.out, force the section size to be aligned. If we don't do
20285 this, BFD will align it for us, but it will not write out the
20286 final bytes of the section. This may be a bug in BFD, but it is
20287 easier to fix it here since that is how the other a.out targets
20288 work. */
20289 int align;
20290
20291 align = bfd_get_section_alignment (stdoutput, segment);
20292 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
20293 }
c19d1205 20294#endif
f0927246
NC
20295
20296 return size;
bfae80f2 20297}
b99bd4ef 20298
c19d1205
ZW
20299/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
20300 of an rs_align_code fragment. */
20301
20302void
20303arm_handle_align (fragS * fragP)
bfae80f2 20304{
e7495e45
NS
20305 static char const arm_noop[2][2][4] =
20306 {
20307 { /* ARMv1 */
20308 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
20309 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
20310 },
20311 { /* ARMv6k */
20312 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
20313 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
20314 },
20315 };
20316 static char const thumb_noop[2][2][2] =
20317 {
20318 { /* Thumb-1 */
20319 {0xc0, 0x46}, /* LE */
20320 {0x46, 0xc0}, /* BE */
20321 },
20322 { /* Thumb-2 */
20323 {0x00, 0xbf}, /* LE */
20324 {0xbf, 0x00} /* BE */
20325 }
20326 };
20327 static char const wide_thumb_noop[2][4] =
20328 { /* Wide Thumb-2 */
20329 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
20330 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
20331 };
c921be7d 20332
e7495e45 20333 unsigned bytes, fix, noop_size;
c19d1205
ZW
20334 char * p;
20335 const char * noop;
e7495e45 20336 const char *narrow_noop = NULL;
cd000bff
DJ
20337#ifdef OBJ_ELF
20338 enum mstate state;
20339#endif
bfae80f2 20340
c19d1205 20341 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
20342 return;
20343
c19d1205
ZW
20344 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
20345 p = fragP->fr_literal + fragP->fr_fix;
20346 fix = 0;
bfae80f2 20347
c19d1205
ZW
20348 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
20349 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 20350
cd000bff 20351 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 20352
cd000bff 20353 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 20354 {
e7495e45
NS
20355 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
20356 {
20357 narrow_noop = thumb_noop[1][target_big_endian];
20358 noop = wide_thumb_noop[target_big_endian];
20359 }
c19d1205 20360 else
e7495e45
NS
20361 noop = thumb_noop[0][target_big_endian];
20362 noop_size = 2;
cd000bff
DJ
20363#ifdef OBJ_ELF
20364 state = MAP_THUMB;
20365#endif
7ed4c4c5
NC
20366 }
20367 else
20368 {
e7495e45
NS
20369 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
20370 [target_big_endian];
20371 noop_size = 4;
cd000bff
DJ
20372#ifdef OBJ_ELF
20373 state = MAP_ARM;
20374#endif
7ed4c4c5 20375 }
c921be7d 20376
e7495e45 20377 fragP->fr_var = noop_size;
c921be7d 20378
c19d1205 20379 if (bytes & (noop_size - 1))
7ed4c4c5 20380 {
c19d1205 20381 fix = bytes & (noop_size - 1);
cd000bff
DJ
20382#ifdef OBJ_ELF
20383 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
20384#endif
c19d1205
ZW
20385 memset (p, 0, fix);
20386 p += fix;
20387 bytes -= fix;
a737bd4d 20388 }
a737bd4d 20389
e7495e45
NS
20390 if (narrow_noop)
20391 {
20392 if (bytes & noop_size)
20393 {
20394 /* Insert a narrow noop. */
20395 memcpy (p, narrow_noop, noop_size);
20396 p += noop_size;
20397 bytes -= noop_size;
20398 fix += noop_size;
20399 }
20400
20401 /* Use wide noops for the remainder */
20402 noop_size = 4;
20403 }
20404
c19d1205 20405 while (bytes >= noop_size)
a737bd4d 20406 {
c19d1205
ZW
20407 memcpy (p, noop, noop_size);
20408 p += noop_size;
20409 bytes -= noop_size;
20410 fix += noop_size;
a737bd4d
NC
20411 }
20412
c19d1205 20413 fragP->fr_fix += fix;
a737bd4d
NC
20414}
20415
c19d1205
ZW
20416/* Called from md_do_align. Used to create an alignment
20417 frag in a code section. */
20418
20419void
20420arm_frag_align_code (int n, int max)
bfae80f2 20421{
c19d1205 20422 char * p;
7ed4c4c5 20423
c19d1205 20424 /* We assume that there will never be a requirement
6ec8e702 20425 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 20426 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
20427 {
20428 char err_msg[128];
20429
fa94de6b 20430 sprintf (err_msg,
6ec8e702
NC
20431 _("alignments greater than %d bytes not supported in .text sections."),
20432 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 20433 as_fatal ("%s", err_msg);
6ec8e702 20434 }
bfae80f2 20435
c19d1205
ZW
20436 p = frag_var (rs_align_code,
20437 MAX_MEM_FOR_RS_ALIGN_CODE,
20438 1,
20439 (relax_substateT) max,
20440 (symbolS *) NULL,
20441 (offsetT) n,
20442 (char *) NULL);
20443 *p = 0;
20444}
bfae80f2 20445
8dc2430f
NC
20446/* Perform target specific initialisation of a frag.
20447 Note - despite the name this initialisation is not done when the frag
20448 is created, but only when its type is assigned. A frag can be created
20449 and used a long time before its type is set, so beware of assuming that
20450 this initialisationis performed first. */
bfae80f2 20451
cd000bff
DJ
20452#ifndef OBJ_ELF
20453void
20454arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
20455{
20456 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 20457 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
20458}
20459
20460#else /* OBJ_ELF is defined. */
c19d1205 20461void
cd000bff 20462arm_init_frag (fragS * fragP, int max_chars)
c19d1205 20463{
8dc2430f
NC
20464 /* If the current ARM vs THUMB mode has not already
20465 been recorded into this frag then do so now. */
cd000bff
DJ
20466 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
20467 {
20468 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
20469
20470 /* Record a mapping symbol for alignment frags. We will delete this
20471 later if the alignment ends up empty. */
20472 switch (fragP->fr_type)
20473 {
20474 case rs_align:
20475 case rs_align_test:
20476 case rs_fill:
20477 mapping_state_2 (MAP_DATA, max_chars);
20478 break;
20479 case rs_align_code:
20480 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
20481 break;
20482 default:
20483 break;
20484 }
20485 }
bfae80f2
RE
20486}
20487
c19d1205
ZW
20488/* When we change sections we need to issue a new mapping symbol. */
20489
20490void
20491arm_elf_change_section (void)
bfae80f2 20492{
c19d1205
ZW
20493 /* Link an unlinked unwind index table section to the .text section. */
20494 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
20495 && elf_linked_to_section (now_seg) == NULL)
20496 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
20497}
20498
c19d1205
ZW
20499int
20500arm_elf_section_type (const char * str, size_t len)
e45d0630 20501{
c19d1205
ZW
20502 if (len == 5 && strncmp (str, "exidx", 5) == 0)
20503 return SHT_ARM_EXIDX;
e45d0630 20504
c19d1205
ZW
20505 return -1;
20506}
20507\f
20508/* Code to deal with unwinding tables. */
e45d0630 20509
c19d1205 20510static void add_unwind_adjustsp (offsetT);
e45d0630 20511
5f4273c7 20512/* Generate any deferred unwind frame offset. */
e45d0630 20513
bfae80f2 20514static void
c19d1205 20515flush_pending_unwind (void)
bfae80f2 20516{
c19d1205 20517 offsetT offset;
bfae80f2 20518
c19d1205
ZW
20519 offset = unwind.pending_offset;
20520 unwind.pending_offset = 0;
20521 if (offset != 0)
20522 add_unwind_adjustsp (offset);
bfae80f2
RE
20523}
20524
c19d1205
ZW
20525/* Add an opcode to this list for this function. Two-byte opcodes should
20526 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
20527 order. */
20528
bfae80f2 20529static void
c19d1205 20530add_unwind_opcode (valueT op, int length)
bfae80f2 20531{
c19d1205
ZW
20532 /* Add any deferred stack adjustment. */
20533 if (unwind.pending_offset)
20534 flush_pending_unwind ();
bfae80f2 20535
c19d1205 20536 unwind.sp_restored = 0;
bfae80f2 20537
c19d1205 20538 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 20539 {
c19d1205
ZW
20540 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
20541 if (unwind.opcodes)
21d799b5
NC
20542 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
20543 unwind.opcode_alloc);
c19d1205 20544 else
21d799b5 20545 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 20546 }
c19d1205 20547 while (length > 0)
bfae80f2 20548 {
c19d1205
ZW
20549 length--;
20550 unwind.opcodes[unwind.opcode_count] = op & 0xff;
20551 op >>= 8;
20552 unwind.opcode_count++;
bfae80f2 20553 }
bfae80f2
RE
20554}
20555
c19d1205
ZW
20556/* Add unwind opcodes to adjust the stack pointer. */
20557
bfae80f2 20558static void
c19d1205 20559add_unwind_adjustsp (offsetT offset)
bfae80f2 20560{
c19d1205 20561 valueT op;
bfae80f2 20562
c19d1205 20563 if (offset > 0x200)
bfae80f2 20564 {
c19d1205
ZW
20565 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
20566 char bytes[5];
20567 int n;
20568 valueT o;
bfae80f2 20569
c19d1205
ZW
20570 /* Long form: 0xb2, uleb128. */
20571 /* This might not fit in a word so add the individual bytes,
20572 remembering the list is built in reverse order. */
20573 o = (valueT) ((offset - 0x204) >> 2);
20574 if (o == 0)
20575 add_unwind_opcode (0, 1);
bfae80f2 20576
c19d1205
ZW
20577 /* Calculate the uleb128 encoding of the offset. */
20578 n = 0;
20579 while (o)
20580 {
20581 bytes[n] = o & 0x7f;
20582 o >>= 7;
20583 if (o)
20584 bytes[n] |= 0x80;
20585 n++;
20586 }
20587 /* Add the insn. */
20588 for (; n; n--)
20589 add_unwind_opcode (bytes[n - 1], 1);
20590 add_unwind_opcode (0xb2, 1);
20591 }
20592 else if (offset > 0x100)
bfae80f2 20593 {
c19d1205
ZW
20594 /* Two short opcodes. */
20595 add_unwind_opcode (0x3f, 1);
20596 op = (offset - 0x104) >> 2;
20597 add_unwind_opcode (op, 1);
bfae80f2 20598 }
c19d1205
ZW
20599 else if (offset > 0)
20600 {
20601 /* Short opcode. */
20602 op = (offset - 4) >> 2;
20603 add_unwind_opcode (op, 1);
20604 }
20605 else if (offset < 0)
bfae80f2 20606 {
c19d1205
ZW
20607 offset = -offset;
20608 while (offset > 0x100)
bfae80f2 20609 {
c19d1205
ZW
20610 add_unwind_opcode (0x7f, 1);
20611 offset -= 0x100;
bfae80f2 20612 }
c19d1205
ZW
20613 op = ((offset - 4) >> 2) | 0x40;
20614 add_unwind_opcode (op, 1);
bfae80f2 20615 }
bfae80f2
RE
20616}
20617
c19d1205
ZW
20618/* Finish the list of unwind opcodes for this function. */
20619static void
20620finish_unwind_opcodes (void)
bfae80f2 20621{
c19d1205 20622 valueT op;
bfae80f2 20623
c19d1205 20624 if (unwind.fp_used)
bfae80f2 20625 {
708587a4 20626 /* Adjust sp as necessary. */
c19d1205
ZW
20627 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
20628 flush_pending_unwind ();
bfae80f2 20629
c19d1205
ZW
20630 /* After restoring sp from the frame pointer. */
20631 op = 0x90 | unwind.fp_reg;
20632 add_unwind_opcode (op, 1);
20633 }
20634 else
20635 flush_pending_unwind ();
bfae80f2
RE
20636}
20637
bfae80f2 20638
c19d1205
ZW
20639/* Start an exception table entry. If idx is nonzero this is an index table
20640 entry. */
bfae80f2
RE
20641
20642static void
c19d1205 20643start_unwind_section (const segT text_seg, int idx)
bfae80f2 20644{
c19d1205
ZW
20645 const char * text_name;
20646 const char * prefix;
20647 const char * prefix_once;
20648 const char * group_name;
20649 size_t prefix_len;
20650 size_t text_len;
20651 char * sec_name;
20652 size_t sec_name_len;
20653 int type;
20654 int flags;
20655 int linkonce;
bfae80f2 20656
c19d1205 20657 if (idx)
bfae80f2 20658 {
c19d1205
ZW
20659 prefix = ELF_STRING_ARM_unwind;
20660 prefix_once = ELF_STRING_ARM_unwind_once;
20661 type = SHT_ARM_EXIDX;
bfae80f2 20662 }
c19d1205 20663 else
bfae80f2 20664 {
c19d1205
ZW
20665 prefix = ELF_STRING_ARM_unwind_info;
20666 prefix_once = ELF_STRING_ARM_unwind_info_once;
20667 type = SHT_PROGBITS;
bfae80f2
RE
20668 }
20669
c19d1205
ZW
20670 text_name = segment_name (text_seg);
20671 if (streq (text_name, ".text"))
20672 text_name = "";
20673
20674 if (strncmp (text_name, ".gnu.linkonce.t.",
20675 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 20676 {
c19d1205
ZW
20677 prefix = prefix_once;
20678 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
20679 }
20680
c19d1205
ZW
20681 prefix_len = strlen (prefix);
20682 text_len = strlen (text_name);
20683 sec_name_len = prefix_len + text_len;
21d799b5 20684 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
20685 memcpy (sec_name, prefix, prefix_len);
20686 memcpy (sec_name + prefix_len, text_name, text_len);
20687 sec_name[prefix_len + text_len] = '\0';
bfae80f2 20688
c19d1205
ZW
20689 flags = SHF_ALLOC;
20690 linkonce = 0;
20691 group_name = 0;
bfae80f2 20692
c19d1205
ZW
20693 /* Handle COMDAT group. */
20694 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 20695 {
c19d1205
ZW
20696 group_name = elf_group_name (text_seg);
20697 if (group_name == NULL)
20698 {
bd3ba5d1 20699 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
20700 segment_name (text_seg));
20701 ignore_rest_of_line ();
20702 return;
20703 }
20704 flags |= SHF_GROUP;
20705 linkonce = 1;
bfae80f2
RE
20706 }
20707
c19d1205 20708 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 20709
5f4273c7 20710 /* Set the section link for index tables. */
c19d1205
ZW
20711 if (idx)
20712 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
20713}
20714
bfae80f2 20715
c19d1205
ZW
20716/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
20717 personality routine data. Returns zero, or the index table value for
20718 and inline entry. */
20719
20720static valueT
20721create_unwind_entry (int have_data)
bfae80f2 20722{
c19d1205
ZW
20723 int size;
20724 addressT where;
20725 char *ptr;
20726 /* The current word of data. */
20727 valueT data;
20728 /* The number of bytes left in this word. */
20729 int n;
bfae80f2 20730
c19d1205 20731 finish_unwind_opcodes ();
bfae80f2 20732
c19d1205
ZW
20733 /* Remember the current text section. */
20734 unwind.saved_seg = now_seg;
20735 unwind.saved_subseg = now_subseg;
bfae80f2 20736
c19d1205 20737 start_unwind_section (now_seg, 0);
bfae80f2 20738
c19d1205 20739 if (unwind.personality_routine == NULL)
bfae80f2 20740 {
c19d1205
ZW
20741 if (unwind.personality_index == -2)
20742 {
20743 if (have_data)
5f4273c7 20744 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
20745 return 1; /* EXIDX_CANTUNWIND. */
20746 }
bfae80f2 20747
c19d1205
ZW
20748 /* Use a default personality routine if none is specified. */
20749 if (unwind.personality_index == -1)
20750 {
20751 if (unwind.opcode_count > 3)
20752 unwind.personality_index = 1;
20753 else
20754 unwind.personality_index = 0;
20755 }
bfae80f2 20756
c19d1205
ZW
20757 /* Space for the personality routine entry. */
20758 if (unwind.personality_index == 0)
20759 {
20760 if (unwind.opcode_count > 3)
20761 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 20762
c19d1205
ZW
20763 if (!have_data)
20764 {
20765 /* All the data is inline in the index table. */
20766 data = 0x80;
20767 n = 3;
20768 while (unwind.opcode_count > 0)
20769 {
20770 unwind.opcode_count--;
20771 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
20772 n--;
20773 }
bfae80f2 20774
c19d1205
ZW
20775 /* Pad with "finish" opcodes. */
20776 while (n--)
20777 data = (data << 8) | 0xb0;
bfae80f2 20778
c19d1205
ZW
20779 return data;
20780 }
20781 size = 0;
20782 }
20783 else
20784 /* We get two opcodes "free" in the first word. */
20785 size = unwind.opcode_count - 2;
20786 }
20787 else
5011093d
NC
20788 {
20789 gas_assert (unwind.personality_index == -1);
20790
20791 /* An extra byte is required for the opcode count. */
20792 size = unwind.opcode_count + 1;
20793 }
bfae80f2 20794
c19d1205
ZW
20795 size = (size + 3) >> 2;
20796 if (size > 0xff)
20797 as_bad (_("too many unwind opcodes"));
bfae80f2 20798
c19d1205
ZW
20799 frag_align (2, 0, 0);
20800 record_alignment (now_seg, 2);
20801 unwind.table_entry = expr_build_dot ();
20802
20803 /* Allocate the table entry. */
20804 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
20805 /* PR 13449: Zero the table entries in case some of them are not used. */
20806 memset (ptr, 0, (size << 2) + 4);
c19d1205 20807 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 20808
c19d1205 20809 switch (unwind.personality_index)
bfae80f2 20810 {
c19d1205
ZW
20811 case -1:
20812 /* ??? Should this be a PLT generating relocation? */
20813 /* Custom personality routine. */
20814 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
20815 BFD_RELOC_ARM_PREL31);
bfae80f2 20816
c19d1205
ZW
20817 where += 4;
20818 ptr += 4;
bfae80f2 20819
c19d1205 20820 /* Set the first byte to the number of additional words. */
5011093d 20821 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
20822 n = 3;
20823 break;
bfae80f2 20824
c19d1205
ZW
20825 /* ABI defined personality routines. */
20826 case 0:
20827 /* Three opcodes bytes are packed into the first word. */
20828 data = 0x80;
20829 n = 3;
20830 break;
bfae80f2 20831
c19d1205
ZW
20832 case 1:
20833 case 2:
20834 /* The size and first two opcode bytes go in the first word. */
20835 data = ((0x80 + unwind.personality_index) << 8) | size;
20836 n = 2;
20837 break;
bfae80f2 20838
c19d1205
ZW
20839 default:
20840 /* Should never happen. */
20841 abort ();
20842 }
bfae80f2 20843
c19d1205
ZW
20844 /* Pack the opcodes into words (MSB first), reversing the list at the same
20845 time. */
20846 while (unwind.opcode_count > 0)
20847 {
20848 if (n == 0)
20849 {
20850 md_number_to_chars (ptr, data, 4);
20851 ptr += 4;
20852 n = 4;
20853 data = 0;
20854 }
20855 unwind.opcode_count--;
20856 n--;
20857 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
20858 }
20859
20860 /* Finish off the last word. */
20861 if (n < 4)
20862 {
20863 /* Pad with "finish" opcodes. */
20864 while (n--)
20865 data = (data << 8) | 0xb0;
20866
20867 md_number_to_chars (ptr, data, 4);
20868 }
20869
20870 if (!have_data)
20871 {
20872 /* Add an empty descriptor if there is no user-specified data. */
20873 ptr = frag_more (4);
20874 md_number_to_chars (ptr, 0, 4);
20875 }
20876
20877 return 0;
bfae80f2
RE
20878}
20879
f0927246
NC
20880
20881/* Initialize the DWARF-2 unwind information for this procedure. */
20882
20883void
20884tc_arm_frame_initial_instructions (void)
20885{
20886 cfi_add_CFA_def_cfa (REG_SP, 0);
20887}
20888#endif /* OBJ_ELF */
20889
c19d1205
ZW
20890/* Convert REGNAME to a DWARF-2 register number. */
20891
20892int
1df69f4f 20893tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 20894{
1df69f4f 20895 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
20896
20897 if (reg == FAIL)
20898 return -1;
20899
20900 return reg;
bfae80f2
RE
20901}
20902
f0927246 20903#ifdef TE_PE
c19d1205 20904void
f0927246 20905tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 20906{
91d6fa6a 20907 expressionS exp;
bfae80f2 20908
91d6fa6a
NC
20909 exp.X_op = O_secrel;
20910 exp.X_add_symbol = symbol;
20911 exp.X_add_number = 0;
20912 emit_expr (&exp, size);
f0927246
NC
20913}
20914#endif
bfae80f2 20915
c19d1205 20916/* MD interface: Symbol and relocation handling. */
bfae80f2 20917
2fc8bdac
ZW
20918/* Return the address within the segment that a PC-relative fixup is
20919 relative to. For ARM, PC-relative fixups applied to instructions
20920 are generally relative to the location of the fixup plus 8 bytes.
20921 Thumb branches are offset by 4, and Thumb loads relative to PC
20922 require special handling. */
bfae80f2 20923
c19d1205 20924long
2fc8bdac 20925md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 20926{
2fc8bdac
ZW
20927 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
20928
20929 /* If this is pc-relative and we are going to emit a relocation
20930 then we just want to put out any pipeline compensation that the linker
53baae48
NC
20931 will need. Otherwise we want to use the calculated base.
20932 For WinCE we skip the bias for externals as well, since this
20933 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 20934 if (fixP->fx_pcrel
2fc8bdac 20935 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
20936 || (arm_force_relocation (fixP)
20937#ifdef TE_WINCE
20938 && !S_IS_EXTERNAL (fixP->fx_addsy)
20939#endif
20940 )))
2fc8bdac 20941 base = 0;
bfae80f2 20942
267bf995 20943
c19d1205 20944 switch (fixP->fx_r_type)
bfae80f2 20945 {
2fc8bdac
ZW
20946 /* PC relative addressing on the Thumb is slightly odd as the
20947 bottom two bits of the PC are forced to zero for the
20948 calculation. This happens *after* application of the
20949 pipeline offset. However, Thumb adrl already adjusts for
20950 this, so we need not do it again. */
c19d1205 20951 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 20952 return base & ~3;
c19d1205
ZW
20953
20954 case BFD_RELOC_ARM_THUMB_OFFSET:
20955 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 20956 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 20957 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 20958 return (base + 4) & ~3;
c19d1205 20959
2fc8bdac
ZW
20960 /* Thumb branches are simply offset by +4. */
20961 case BFD_RELOC_THUMB_PCREL_BRANCH7:
20962 case BFD_RELOC_THUMB_PCREL_BRANCH9:
20963 case BFD_RELOC_THUMB_PCREL_BRANCH12:
20964 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 20965 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 20966 return base + 4;
bfae80f2 20967
267bf995 20968 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
20969 if (fixP->fx_addsy
20970 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20971 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20972 && ARM_IS_FUNC (fixP->fx_addsy)
20973 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20974 base = fixP->fx_where + fixP->fx_frag->fr_address;
20975 return base + 4;
20976
00adf2d4
JB
20977 /* BLX is like branches above, but forces the low two bits of PC to
20978 zero. */
486499d0
CL
20979 case BFD_RELOC_THUMB_PCREL_BLX:
20980 if (fixP->fx_addsy
20981 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20982 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20983 && THUMB_IS_FUNC (fixP->fx_addsy)
20984 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20985 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
20986 return (base + 4) & ~3;
20987
2fc8bdac
ZW
20988 /* ARM mode branches are offset by +8. However, the Windows CE
20989 loader expects the relocation not to take this into account. */
267bf995 20990 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
20991 if (fixP->fx_addsy
20992 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20993 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20994 && ARM_IS_FUNC (fixP->fx_addsy)
20995 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20996 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 20997 return base + 8;
267bf995 20998
486499d0
CL
20999 case BFD_RELOC_ARM_PCREL_CALL:
21000 if (fixP->fx_addsy
21001 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21002 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21003 && THUMB_IS_FUNC (fixP->fx_addsy)
21004 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21005 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 21006 return base + 8;
267bf995 21007
2fc8bdac 21008 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 21009 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 21010 case BFD_RELOC_ARM_PLT32:
c19d1205 21011#ifdef TE_WINCE
5f4273c7 21012 /* When handling fixups immediately, because we have already
53baae48
NC
21013 discovered the value of a symbol, or the address of the frag involved
21014 we must account for the offset by +8, as the OS loader will never see the reloc.
21015 see fixup_segment() in write.c
21016 The S_IS_EXTERNAL test handles the case of global symbols.
21017 Those need the calculated base, not just the pipe compensation the linker will need. */
21018 if (fixP->fx_pcrel
21019 && fixP->fx_addsy != NULL
21020 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21021 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
21022 return base + 8;
2fc8bdac 21023 return base;
c19d1205 21024#else
2fc8bdac 21025 return base + 8;
c19d1205 21026#endif
2fc8bdac 21027
267bf995 21028
2fc8bdac
ZW
21029 /* ARM mode loads relative to PC are also offset by +8. Unlike
21030 branches, the Windows CE loader *does* expect the relocation
21031 to take this into account. */
21032 case BFD_RELOC_ARM_OFFSET_IMM:
21033 case BFD_RELOC_ARM_OFFSET_IMM8:
21034 case BFD_RELOC_ARM_HWLITERAL:
21035 case BFD_RELOC_ARM_LITERAL:
21036 case BFD_RELOC_ARM_CP_OFF_IMM:
21037 return base + 8;
21038
21039
21040 /* Other PC-relative relocations are un-offset. */
21041 default:
21042 return base;
21043 }
bfae80f2
RE
21044}
21045
c19d1205
ZW
21046/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
21047 Otherwise we have no need to default values of symbols. */
21048
21049symbolS *
21050md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 21051{
c19d1205
ZW
21052#ifdef OBJ_ELF
21053 if (name[0] == '_' && name[1] == 'G'
21054 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
21055 {
21056 if (!GOT_symbol)
21057 {
21058 if (symbol_find (name))
bd3ba5d1 21059 as_bad (_("GOT already in the symbol table"));
bfae80f2 21060
c19d1205
ZW
21061 GOT_symbol = symbol_new (name, undefined_section,
21062 (valueT) 0, & zero_address_frag);
21063 }
bfae80f2 21064
c19d1205 21065 return GOT_symbol;
bfae80f2 21066 }
c19d1205 21067#endif
bfae80f2 21068
c921be7d 21069 return NULL;
bfae80f2
RE
21070}
21071
55cf6793 21072/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
21073 computed as two separate immediate values, added together. We
21074 already know that this value cannot be computed by just one ARM
21075 instruction. */
21076
21077static unsigned int
21078validate_immediate_twopart (unsigned int val,
21079 unsigned int * highpart)
bfae80f2 21080{
c19d1205
ZW
21081 unsigned int a;
21082 unsigned int i;
bfae80f2 21083
c19d1205
ZW
21084 for (i = 0; i < 32; i += 2)
21085 if (((a = rotate_left (val, i)) & 0xff) != 0)
21086 {
21087 if (a & 0xff00)
21088 {
21089 if (a & ~ 0xffff)
21090 continue;
21091 * highpart = (a >> 8) | ((i + 24) << 7);
21092 }
21093 else if (a & 0xff0000)
21094 {
21095 if (a & 0xff000000)
21096 continue;
21097 * highpart = (a >> 16) | ((i + 16) << 7);
21098 }
21099 else
21100 {
9c2799c2 21101 gas_assert (a & 0xff000000);
c19d1205
ZW
21102 * highpart = (a >> 24) | ((i + 8) << 7);
21103 }
bfae80f2 21104
c19d1205
ZW
21105 return (a & 0xff) | (i << 7);
21106 }
bfae80f2 21107
c19d1205 21108 return FAIL;
bfae80f2
RE
21109}
21110
c19d1205
ZW
21111static int
21112validate_offset_imm (unsigned int val, int hwse)
21113{
21114 if ((hwse && val > 255) || val > 4095)
21115 return FAIL;
21116 return val;
21117}
bfae80f2 21118
55cf6793 21119/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
21120 negative immediate constant by altering the instruction. A bit of
21121 a hack really.
21122 MOV <-> MVN
21123 AND <-> BIC
21124 ADC <-> SBC
21125 by inverting the second operand, and
21126 ADD <-> SUB
21127 CMP <-> CMN
21128 by negating the second operand. */
bfae80f2 21129
c19d1205
ZW
21130static int
21131negate_data_op (unsigned long * instruction,
21132 unsigned long value)
bfae80f2 21133{
c19d1205
ZW
21134 int op, new_inst;
21135 unsigned long negated, inverted;
bfae80f2 21136
c19d1205
ZW
21137 negated = encode_arm_immediate (-value);
21138 inverted = encode_arm_immediate (~value);
bfae80f2 21139
c19d1205
ZW
21140 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
21141 switch (op)
bfae80f2 21142 {
c19d1205
ZW
21143 /* First negates. */
21144 case OPCODE_SUB: /* ADD <-> SUB */
21145 new_inst = OPCODE_ADD;
21146 value = negated;
21147 break;
bfae80f2 21148
c19d1205
ZW
21149 case OPCODE_ADD:
21150 new_inst = OPCODE_SUB;
21151 value = negated;
21152 break;
bfae80f2 21153
c19d1205
ZW
21154 case OPCODE_CMP: /* CMP <-> CMN */
21155 new_inst = OPCODE_CMN;
21156 value = negated;
21157 break;
bfae80f2 21158
c19d1205
ZW
21159 case OPCODE_CMN:
21160 new_inst = OPCODE_CMP;
21161 value = negated;
21162 break;
bfae80f2 21163
c19d1205
ZW
21164 /* Now Inverted ops. */
21165 case OPCODE_MOV: /* MOV <-> MVN */
21166 new_inst = OPCODE_MVN;
21167 value = inverted;
21168 break;
bfae80f2 21169
c19d1205
ZW
21170 case OPCODE_MVN:
21171 new_inst = OPCODE_MOV;
21172 value = inverted;
21173 break;
bfae80f2 21174
c19d1205
ZW
21175 case OPCODE_AND: /* AND <-> BIC */
21176 new_inst = OPCODE_BIC;
21177 value = inverted;
21178 break;
bfae80f2 21179
c19d1205
ZW
21180 case OPCODE_BIC:
21181 new_inst = OPCODE_AND;
21182 value = inverted;
21183 break;
bfae80f2 21184
c19d1205
ZW
21185 case OPCODE_ADC: /* ADC <-> SBC */
21186 new_inst = OPCODE_SBC;
21187 value = inverted;
21188 break;
bfae80f2 21189
c19d1205
ZW
21190 case OPCODE_SBC:
21191 new_inst = OPCODE_ADC;
21192 value = inverted;
21193 break;
bfae80f2 21194
c19d1205
ZW
21195 /* We cannot do anything. */
21196 default:
21197 return FAIL;
b99bd4ef
NC
21198 }
21199
c19d1205
ZW
21200 if (value == (unsigned) FAIL)
21201 return FAIL;
21202
21203 *instruction &= OPCODE_MASK;
21204 *instruction |= new_inst << DATA_OP_SHIFT;
21205 return value;
b99bd4ef
NC
21206}
21207
ef8d22e6
PB
21208/* Like negate_data_op, but for Thumb-2. */
21209
21210static unsigned int
16dd5e42 21211thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
21212{
21213 int op, new_inst;
21214 int rd;
16dd5e42 21215 unsigned int negated, inverted;
ef8d22e6
PB
21216
21217 negated = encode_thumb32_immediate (-value);
21218 inverted = encode_thumb32_immediate (~value);
21219
21220 rd = (*instruction >> 8) & 0xf;
21221 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
21222 switch (op)
21223 {
21224 /* ADD <-> SUB. Includes CMP <-> CMN. */
21225 case T2_OPCODE_SUB:
21226 new_inst = T2_OPCODE_ADD;
21227 value = negated;
21228 break;
21229
21230 case T2_OPCODE_ADD:
21231 new_inst = T2_OPCODE_SUB;
21232 value = negated;
21233 break;
21234
21235 /* ORR <-> ORN. Includes MOV <-> MVN. */
21236 case T2_OPCODE_ORR:
21237 new_inst = T2_OPCODE_ORN;
21238 value = inverted;
21239 break;
21240
21241 case T2_OPCODE_ORN:
21242 new_inst = T2_OPCODE_ORR;
21243 value = inverted;
21244 break;
21245
21246 /* AND <-> BIC. TST has no inverted equivalent. */
21247 case T2_OPCODE_AND:
21248 new_inst = T2_OPCODE_BIC;
21249 if (rd == 15)
21250 value = FAIL;
21251 else
21252 value = inverted;
21253 break;
21254
21255 case T2_OPCODE_BIC:
21256 new_inst = T2_OPCODE_AND;
21257 value = inverted;
21258 break;
21259
21260 /* ADC <-> SBC */
21261 case T2_OPCODE_ADC:
21262 new_inst = T2_OPCODE_SBC;
21263 value = inverted;
21264 break;
21265
21266 case T2_OPCODE_SBC:
21267 new_inst = T2_OPCODE_ADC;
21268 value = inverted;
21269 break;
21270
21271 /* We cannot do anything. */
21272 default:
21273 return FAIL;
21274 }
21275
16dd5e42 21276 if (value == (unsigned int)FAIL)
ef8d22e6
PB
21277 return FAIL;
21278
21279 *instruction &= T2_OPCODE_MASK;
21280 *instruction |= new_inst << T2_DATA_OP_SHIFT;
21281 return value;
21282}
21283
8f06b2d8
PB
21284/* Read a 32-bit thumb instruction from buf. */
21285static unsigned long
21286get_thumb32_insn (char * buf)
21287{
21288 unsigned long insn;
21289 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
21290 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21291
21292 return insn;
21293}
21294
a8bc6c78
PB
21295
21296/* We usually want to set the low bit on the address of thumb function
21297 symbols. In particular .word foo - . should have the low bit set.
21298 Generic code tries to fold the difference of two symbols to
21299 a constant. Prevent this and force a relocation when the first symbols
21300 is a thumb function. */
c921be7d
NC
21301
21302bfd_boolean
a8bc6c78
PB
21303arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
21304{
21305 if (op == O_subtract
21306 && l->X_op == O_symbol
21307 && r->X_op == O_symbol
21308 && THUMB_IS_FUNC (l->X_add_symbol))
21309 {
21310 l->X_op = O_subtract;
21311 l->X_op_symbol = r->X_add_symbol;
21312 l->X_add_number -= r->X_add_number;
c921be7d 21313 return TRUE;
a8bc6c78 21314 }
c921be7d 21315
a8bc6c78 21316 /* Process as normal. */
c921be7d 21317 return FALSE;
a8bc6c78
PB
21318}
21319
4a42ebbc
RR
21320/* Encode Thumb2 unconditional branches and calls. The encoding
21321 for the 2 are identical for the immediate values. */
21322
21323static void
21324encode_thumb2_b_bl_offset (char * buf, offsetT value)
21325{
21326#define T2I1I2MASK ((1 << 13) | (1 << 11))
21327 offsetT newval;
21328 offsetT newval2;
21329 addressT S, I1, I2, lo, hi;
21330
21331 S = (value >> 24) & 0x01;
21332 I1 = (value >> 23) & 0x01;
21333 I2 = (value >> 22) & 0x01;
21334 hi = (value >> 12) & 0x3ff;
fa94de6b 21335 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
21336 newval = md_chars_to_number (buf, THUMB_SIZE);
21337 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21338 newval |= (S << 10) | hi;
21339 newval2 &= ~T2I1I2MASK;
21340 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
21341 md_number_to_chars (buf, newval, THUMB_SIZE);
21342 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
21343}
21344
c19d1205 21345void
55cf6793 21346md_apply_fix (fixS * fixP,
c19d1205
ZW
21347 valueT * valP,
21348 segT seg)
21349{
21350 offsetT value = * valP;
21351 offsetT newval;
21352 unsigned int newimm;
21353 unsigned long temp;
21354 int sign;
21355 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 21356
9c2799c2 21357 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 21358
c19d1205 21359 /* Note whether this will delete the relocation. */
4962c51a 21360
c19d1205
ZW
21361 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
21362 fixP->fx_done = 1;
b99bd4ef 21363
adbaf948 21364 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 21365 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
21366 for emit_reloc. */
21367 value &= 0xffffffff;
21368 value ^= 0x80000000;
5f4273c7 21369 value -= 0x80000000;
adbaf948
ZW
21370
21371 *valP = value;
c19d1205 21372 fixP->fx_addnumber = value;
b99bd4ef 21373
adbaf948
ZW
21374 /* Same treatment for fixP->fx_offset. */
21375 fixP->fx_offset &= 0xffffffff;
21376 fixP->fx_offset ^= 0x80000000;
21377 fixP->fx_offset -= 0x80000000;
21378
c19d1205 21379 switch (fixP->fx_r_type)
b99bd4ef 21380 {
c19d1205
ZW
21381 case BFD_RELOC_NONE:
21382 /* This will need to go in the object file. */
21383 fixP->fx_done = 0;
21384 break;
b99bd4ef 21385
c19d1205
ZW
21386 case BFD_RELOC_ARM_IMMEDIATE:
21387 /* We claim that this fixup has been processed here,
21388 even if in fact we generate an error because we do
21389 not have a reloc for it, so tc_gen_reloc will reject it. */
21390 fixP->fx_done = 1;
b99bd4ef 21391
77db8e2e 21392 if (fixP->fx_addsy)
b99bd4ef 21393 {
77db8e2e 21394 const char *msg = 0;
b99bd4ef 21395
77db8e2e
NC
21396 if (! S_IS_DEFINED (fixP->fx_addsy))
21397 msg = _("undefined symbol %s used as an immediate value");
21398 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
21399 msg = _("symbol %s is in a different section");
21400 else if (S_IS_WEAK (fixP->fx_addsy))
21401 msg = _("symbol %s is weak and may be overridden later");
21402
21403 if (msg)
21404 {
21405 as_bad_where (fixP->fx_file, fixP->fx_line,
21406 msg, S_GET_NAME (fixP->fx_addsy));
21407 break;
21408 }
42e5fcbf
AS
21409 }
21410
c19d1205
ZW
21411 temp = md_chars_to_number (buf, INSN_SIZE);
21412
5e73442d
SL
21413 /* If the offset is negative, we should use encoding A2 for ADR. */
21414 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
21415 newimm = negate_data_op (&temp, value);
21416 else
21417 {
21418 newimm = encode_arm_immediate (value);
21419
21420 /* If the instruction will fail, see if we can fix things up by
21421 changing the opcode. */
21422 if (newimm == (unsigned int) FAIL)
21423 newimm = negate_data_op (&temp, value);
21424 }
21425
21426 if (newimm == (unsigned int) FAIL)
b99bd4ef 21427 {
c19d1205
ZW
21428 as_bad_where (fixP->fx_file, fixP->fx_line,
21429 _("invalid constant (%lx) after fixup"),
21430 (unsigned long) value);
21431 break;
b99bd4ef 21432 }
b99bd4ef 21433
c19d1205
ZW
21434 newimm |= (temp & 0xfffff000);
21435 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
21436 break;
b99bd4ef 21437
c19d1205
ZW
21438 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21439 {
21440 unsigned int highpart = 0;
21441 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 21442
77db8e2e 21443 if (fixP->fx_addsy)
42e5fcbf 21444 {
77db8e2e 21445 const char *msg = 0;
42e5fcbf 21446
77db8e2e
NC
21447 if (! S_IS_DEFINED (fixP->fx_addsy))
21448 msg = _("undefined symbol %s used as an immediate value");
21449 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
21450 msg = _("symbol %s is in a different section");
21451 else if (S_IS_WEAK (fixP->fx_addsy))
21452 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 21453
77db8e2e
NC
21454 if (msg)
21455 {
21456 as_bad_where (fixP->fx_file, fixP->fx_line,
21457 msg, S_GET_NAME (fixP->fx_addsy));
21458 break;
21459 }
21460 }
fa94de6b 21461
c19d1205
ZW
21462 newimm = encode_arm_immediate (value);
21463 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 21464
c19d1205
ZW
21465 /* If the instruction will fail, see if we can fix things up by
21466 changing the opcode. */
21467 if (newimm == (unsigned int) FAIL
21468 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
21469 {
21470 /* No ? OK - try using two ADD instructions to generate
21471 the value. */
21472 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 21473
c19d1205
ZW
21474 /* Yes - then make sure that the second instruction is
21475 also an add. */
21476 if (newimm != (unsigned int) FAIL)
21477 newinsn = temp;
21478 /* Still No ? Try using a negated value. */
21479 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
21480 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
21481 /* Otherwise - give up. */
21482 else
21483 {
21484 as_bad_where (fixP->fx_file, fixP->fx_line,
21485 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
21486 (long) value);
21487 break;
21488 }
b99bd4ef 21489
c19d1205
ZW
21490 /* Replace the first operand in the 2nd instruction (which
21491 is the PC) with the destination register. We have
21492 already added in the PC in the first instruction and we
21493 do not want to do it again. */
21494 newinsn &= ~ 0xf0000;
21495 newinsn |= ((newinsn & 0x0f000) << 4);
21496 }
b99bd4ef 21497
c19d1205
ZW
21498 newimm |= (temp & 0xfffff000);
21499 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 21500
c19d1205
ZW
21501 highpart |= (newinsn & 0xfffff000);
21502 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
21503 }
21504 break;
b99bd4ef 21505
c19d1205 21506 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
21507 if (!fixP->fx_done && seg->use_rela_p)
21508 value = 0;
21509
c19d1205 21510 case BFD_RELOC_ARM_LITERAL:
26d97720 21511 sign = value > 0;
b99bd4ef 21512
c19d1205
ZW
21513 if (value < 0)
21514 value = - value;
b99bd4ef 21515
c19d1205 21516 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 21517 {
c19d1205
ZW
21518 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
21519 as_bad_where (fixP->fx_file, fixP->fx_line,
21520 _("invalid literal constant: pool needs to be closer"));
21521 else
21522 as_bad_where (fixP->fx_file, fixP->fx_line,
21523 _("bad immediate value for offset (%ld)"),
21524 (long) value);
21525 break;
f03698e6
RE
21526 }
21527
c19d1205 21528 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
21529 if (value == 0)
21530 newval &= 0xfffff000;
21531 else
21532 {
21533 newval &= 0xff7ff000;
21534 newval |= value | (sign ? INDEX_UP : 0);
21535 }
c19d1205
ZW
21536 md_number_to_chars (buf, newval, INSN_SIZE);
21537 break;
b99bd4ef 21538
c19d1205
ZW
21539 case BFD_RELOC_ARM_OFFSET_IMM8:
21540 case BFD_RELOC_ARM_HWLITERAL:
26d97720 21541 sign = value > 0;
b99bd4ef 21542
c19d1205
ZW
21543 if (value < 0)
21544 value = - value;
b99bd4ef 21545
c19d1205 21546 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 21547 {
c19d1205
ZW
21548 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
21549 as_bad_where (fixP->fx_file, fixP->fx_line,
21550 _("invalid literal constant: pool needs to be closer"));
21551 else
427d0db6
RM
21552 as_bad_where (fixP->fx_file, fixP->fx_line,
21553 _("bad immediate value for 8-bit offset (%ld)"),
21554 (long) value);
c19d1205 21555 break;
b99bd4ef
NC
21556 }
21557
c19d1205 21558 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
21559 if (value == 0)
21560 newval &= 0xfffff0f0;
21561 else
21562 {
21563 newval &= 0xff7ff0f0;
21564 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
21565 }
c19d1205
ZW
21566 md_number_to_chars (buf, newval, INSN_SIZE);
21567 break;
b99bd4ef 21568
c19d1205
ZW
21569 case BFD_RELOC_ARM_T32_OFFSET_U8:
21570 if (value < 0 || value > 1020 || value % 4 != 0)
21571 as_bad_where (fixP->fx_file, fixP->fx_line,
21572 _("bad immediate value for offset (%ld)"), (long) value);
21573 value /= 4;
b99bd4ef 21574
c19d1205 21575 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
21576 newval |= value;
21577 md_number_to_chars (buf+2, newval, THUMB_SIZE);
21578 break;
b99bd4ef 21579
c19d1205
ZW
21580 case BFD_RELOC_ARM_T32_OFFSET_IMM:
21581 /* This is a complicated relocation used for all varieties of Thumb32
21582 load/store instruction with immediate offset:
21583
21584 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
21585 *4, optional writeback(W)
21586 (doubleword load/store)
21587
21588 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
21589 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
21590 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
21591 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
21592 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
21593
21594 Uppercase letters indicate bits that are already encoded at
21595 this point. Lowercase letters are our problem. For the
21596 second block of instructions, the secondary opcode nybble
21597 (bits 8..11) is present, and bit 23 is zero, even if this is
21598 a PC-relative operation. */
21599 newval = md_chars_to_number (buf, THUMB_SIZE);
21600 newval <<= 16;
21601 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 21602
c19d1205 21603 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 21604 {
c19d1205
ZW
21605 /* Doubleword load/store: 8-bit offset, scaled by 4. */
21606 if (value >= 0)
21607 newval |= (1 << 23);
21608 else
21609 value = -value;
21610 if (value % 4 != 0)
21611 {
21612 as_bad_where (fixP->fx_file, fixP->fx_line,
21613 _("offset not a multiple of 4"));
21614 break;
21615 }
21616 value /= 4;
216d22bc 21617 if (value > 0xff)
c19d1205
ZW
21618 {
21619 as_bad_where (fixP->fx_file, fixP->fx_line,
21620 _("offset out of range"));
21621 break;
21622 }
21623 newval &= ~0xff;
b99bd4ef 21624 }
c19d1205 21625 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 21626 {
c19d1205
ZW
21627 /* PC-relative, 12-bit offset. */
21628 if (value >= 0)
21629 newval |= (1 << 23);
21630 else
21631 value = -value;
216d22bc 21632 if (value > 0xfff)
c19d1205
ZW
21633 {
21634 as_bad_where (fixP->fx_file, fixP->fx_line,
21635 _("offset out of range"));
21636 break;
21637 }
21638 newval &= ~0xfff;
b99bd4ef 21639 }
c19d1205 21640 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 21641 {
c19d1205
ZW
21642 /* Writeback: 8-bit, +/- offset. */
21643 if (value >= 0)
21644 newval |= (1 << 9);
21645 else
21646 value = -value;
216d22bc 21647 if (value > 0xff)
c19d1205
ZW
21648 {
21649 as_bad_where (fixP->fx_file, fixP->fx_line,
21650 _("offset out of range"));
21651 break;
21652 }
21653 newval &= ~0xff;
b99bd4ef 21654 }
c19d1205 21655 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 21656 {
c19d1205 21657 /* T-instruction: positive 8-bit offset. */
216d22bc 21658 if (value < 0 || value > 0xff)
b99bd4ef 21659 {
c19d1205
ZW
21660 as_bad_where (fixP->fx_file, fixP->fx_line,
21661 _("offset out of range"));
21662 break;
b99bd4ef 21663 }
c19d1205
ZW
21664 newval &= ~0xff;
21665 newval |= value;
b99bd4ef
NC
21666 }
21667 else
b99bd4ef 21668 {
c19d1205
ZW
21669 /* Positive 12-bit or negative 8-bit offset. */
21670 int limit;
21671 if (value >= 0)
b99bd4ef 21672 {
c19d1205
ZW
21673 newval |= (1 << 23);
21674 limit = 0xfff;
21675 }
21676 else
21677 {
21678 value = -value;
21679 limit = 0xff;
21680 }
21681 if (value > limit)
21682 {
21683 as_bad_where (fixP->fx_file, fixP->fx_line,
21684 _("offset out of range"));
21685 break;
b99bd4ef 21686 }
c19d1205 21687 newval &= ~limit;
b99bd4ef 21688 }
b99bd4ef 21689
c19d1205
ZW
21690 newval |= value;
21691 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
21692 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
21693 break;
404ff6b5 21694
c19d1205
ZW
21695 case BFD_RELOC_ARM_SHIFT_IMM:
21696 newval = md_chars_to_number (buf, INSN_SIZE);
21697 if (((unsigned long) value) > 32
21698 || (value == 32
21699 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
21700 {
21701 as_bad_where (fixP->fx_file, fixP->fx_line,
21702 _("shift expression is too large"));
21703 break;
21704 }
404ff6b5 21705
c19d1205
ZW
21706 if (value == 0)
21707 /* Shifts of zero must be done as lsl. */
21708 newval &= ~0x60;
21709 else if (value == 32)
21710 value = 0;
21711 newval &= 0xfffff07f;
21712 newval |= (value & 0x1f) << 7;
21713 md_number_to_chars (buf, newval, INSN_SIZE);
21714 break;
404ff6b5 21715
c19d1205 21716 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 21717 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 21718 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 21719 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
21720 /* We claim that this fixup has been processed here,
21721 even if in fact we generate an error because we do
21722 not have a reloc for it, so tc_gen_reloc will reject it. */
21723 fixP->fx_done = 1;
404ff6b5 21724
c19d1205
ZW
21725 if (fixP->fx_addsy
21726 && ! S_IS_DEFINED (fixP->fx_addsy))
21727 {
21728 as_bad_where (fixP->fx_file, fixP->fx_line,
21729 _("undefined symbol %s used as an immediate value"),
21730 S_GET_NAME (fixP->fx_addsy));
21731 break;
21732 }
404ff6b5 21733
c19d1205
ZW
21734 newval = md_chars_to_number (buf, THUMB_SIZE);
21735 newval <<= 16;
21736 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 21737
16805f35
PB
21738 newimm = FAIL;
21739 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21740 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
21741 {
21742 newimm = encode_thumb32_immediate (value);
21743 if (newimm == (unsigned int) FAIL)
21744 newimm = thumb32_negate_data_op (&newval, value);
21745 }
16805f35
PB
21746 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
21747 && newimm == (unsigned int) FAIL)
92e90b6e 21748 {
16805f35
PB
21749 /* Turn add/sum into addw/subw. */
21750 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
21751 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
21752 /* No flat 12-bit imm encoding for addsw/subsw. */
21753 if ((newval & 0x00100000) == 0)
e9f89963 21754 {
40f246e3
NC
21755 /* 12 bit immediate for addw/subw. */
21756 if (value < 0)
21757 {
21758 value = -value;
21759 newval ^= 0x00a00000;
21760 }
21761 if (value > 0xfff)
21762 newimm = (unsigned int) FAIL;
21763 else
21764 newimm = value;
e9f89963 21765 }
92e90b6e 21766 }
cc8a6dd0 21767
c19d1205 21768 if (newimm == (unsigned int)FAIL)
3631a3c8 21769 {
c19d1205
ZW
21770 as_bad_where (fixP->fx_file, fixP->fx_line,
21771 _("invalid constant (%lx) after fixup"),
21772 (unsigned long) value);
21773 break;
3631a3c8
NC
21774 }
21775
c19d1205
ZW
21776 newval |= (newimm & 0x800) << 15;
21777 newval |= (newimm & 0x700) << 4;
21778 newval |= (newimm & 0x0ff);
cc8a6dd0 21779
c19d1205
ZW
21780 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
21781 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
21782 break;
a737bd4d 21783
3eb17e6b 21784 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
21785 if (((unsigned long) value) > 0xffff)
21786 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 21787 _("invalid smc expression"));
2fc8bdac 21788 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
21789 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
21790 md_number_to_chars (buf, newval, INSN_SIZE);
21791 break;
a737bd4d 21792
90ec0d68
MGD
21793 case BFD_RELOC_ARM_HVC:
21794 if (((unsigned long) value) > 0xffff)
21795 as_bad_where (fixP->fx_file, fixP->fx_line,
21796 _("invalid hvc expression"));
21797 newval = md_chars_to_number (buf, INSN_SIZE);
21798 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
21799 md_number_to_chars (buf, newval, INSN_SIZE);
21800 break;
21801
c19d1205 21802 case BFD_RELOC_ARM_SWI:
adbaf948 21803 if (fixP->tc_fix_data != 0)
c19d1205
ZW
21804 {
21805 if (((unsigned long) value) > 0xff)
21806 as_bad_where (fixP->fx_file, fixP->fx_line,
21807 _("invalid swi expression"));
2fc8bdac 21808 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
21809 newval |= value;
21810 md_number_to_chars (buf, newval, THUMB_SIZE);
21811 }
21812 else
21813 {
21814 if (((unsigned long) value) > 0x00ffffff)
21815 as_bad_where (fixP->fx_file, fixP->fx_line,
21816 _("invalid swi expression"));
2fc8bdac 21817 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
21818 newval |= value;
21819 md_number_to_chars (buf, newval, INSN_SIZE);
21820 }
21821 break;
a737bd4d 21822
c19d1205
ZW
21823 case BFD_RELOC_ARM_MULTI:
21824 if (((unsigned long) value) > 0xffff)
21825 as_bad_where (fixP->fx_file, fixP->fx_line,
21826 _("invalid expression in load/store multiple"));
21827 newval = value | md_chars_to_number (buf, INSN_SIZE);
21828 md_number_to_chars (buf, newval, INSN_SIZE);
21829 break;
a737bd4d 21830
c19d1205 21831#ifdef OBJ_ELF
39b41c9c 21832 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
21833
21834 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21835 && fixP->fx_addsy
34e77a92 21836 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21837 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21838 && THUMB_IS_FUNC (fixP->fx_addsy))
21839 /* Flip the bl to blx. This is a simple flip
21840 bit here because we generate PCREL_CALL for
21841 unconditional bls. */
21842 {
21843 newval = md_chars_to_number (buf, INSN_SIZE);
21844 newval = newval | 0x10000000;
21845 md_number_to_chars (buf, newval, INSN_SIZE);
21846 temp = 1;
21847 fixP->fx_done = 1;
21848 }
39b41c9c
PB
21849 else
21850 temp = 3;
21851 goto arm_branch_common;
21852
21853 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
21854 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21855 && fixP->fx_addsy
34e77a92 21856 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21857 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21858 && THUMB_IS_FUNC (fixP->fx_addsy))
21859 {
21860 /* This would map to a bl<cond>, b<cond>,
21861 b<always> to a Thumb function. We
21862 need to force a relocation for this particular
21863 case. */
21864 newval = md_chars_to_number (buf, INSN_SIZE);
21865 fixP->fx_done = 0;
21866 }
21867
2fc8bdac 21868 case BFD_RELOC_ARM_PLT32:
c19d1205 21869#endif
39b41c9c
PB
21870 case BFD_RELOC_ARM_PCREL_BRANCH:
21871 temp = 3;
21872 goto arm_branch_common;
a737bd4d 21873
39b41c9c 21874 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 21875
39b41c9c 21876 temp = 1;
267bf995
RR
21877 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21878 && fixP->fx_addsy
34e77a92 21879 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21880 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21881 && ARM_IS_FUNC (fixP->fx_addsy))
21882 {
21883 /* Flip the blx to a bl and warn. */
21884 const char *name = S_GET_NAME (fixP->fx_addsy);
21885 newval = 0xeb000000;
21886 as_warn_where (fixP->fx_file, fixP->fx_line,
21887 _("blx to '%s' an ARM ISA state function changed to bl"),
21888 name);
21889 md_number_to_chars (buf, newval, INSN_SIZE);
21890 temp = 3;
21891 fixP->fx_done = 1;
21892 }
21893
21894#ifdef OBJ_ELF
21895 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21896 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
21897#endif
21898
39b41c9c 21899 arm_branch_common:
c19d1205 21900 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
21901 instruction, in a 24 bit, signed field. Bits 26 through 32 either
21902 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
21903 also be be clear. */
21904 if (value & temp)
c19d1205 21905 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
21906 _("misaligned branch destination"));
21907 if ((value & (offsetT)0xfe000000) != (offsetT)0
21908 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 21909 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 21910
2fc8bdac 21911 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 21912 {
2fc8bdac
ZW
21913 newval = md_chars_to_number (buf, INSN_SIZE);
21914 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
21915 /* Set the H bit on BLX instructions. */
21916 if (temp == 1)
21917 {
21918 if (value & 2)
21919 newval |= 0x01000000;
21920 else
21921 newval &= ~0x01000000;
21922 }
2fc8bdac 21923 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 21924 }
c19d1205 21925 break;
a737bd4d 21926
25fe350b
MS
21927 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
21928 /* CBZ can only branch forward. */
a737bd4d 21929
738755b0
MS
21930 /* Attempts to use CBZ to branch to the next instruction
21931 (which, strictly speaking, are prohibited) will be turned into
21932 no-ops.
21933
21934 FIXME: It may be better to remove the instruction completely and
21935 perform relaxation. */
21936 if (value == -2)
2fc8bdac
ZW
21937 {
21938 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 21939 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
21940 md_number_to_chars (buf, newval, THUMB_SIZE);
21941 }
738755b0
MS
21942 else
21943 {
21944 if (value & ~0x7e)
08f10d51 21945 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0
MS
21946
21947 if (fixP->fx_done || !seg->use_rela_p)
21948 {
21949 newval = md_chars_to_number (buf, THUMB_SIZE);
21950 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
21951 md_number_to_chars (buf, newval, THUMB_SIZE);
21952 }
21953 }
c19d1205 21954 break;
a737bd4d 21955
c19d1205 21956 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 21957 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 21958 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 21959
2fc8bdac
ZW
21960 if (fixP->fx_done || !seg->use_rela_p)
21961 {
21962 newval = md_chars_to_number (buf, THUMB_SIZE);
21963 newval |= (value & 0x1ff) >> 1;
21964 md_number_to_chars (buf, newval, THUMB_SIZE);
21965 }
c19d1205 21966 break;
a737bd4d 21967
c19d1205 21968 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 21969 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 21970 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 21971
2fc8bdac
ZW
21972 if (fixP->fx_done || !seg->use_rela_p)
21973 {
21974 newval = md_chars_to_number (buf, THUMB_SIZE);
21975 newval |= (value & 0xfff) >> 1;
21976 md_number_to_chars (buf, newval, THUMB_SIZE);
21977 }
c19d1205 21978 break;
a737bd4d 21979
c19d1205 21980 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
21981 if (fixP->fx_addsy
21982 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21983 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21984 && ARM_IS_FUNC (fixP->fx_addsy)
21985 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21986 {
21987 /* Force a relocation for a branch 20 bits wide. */
21988 fixP->fx_done = 0;
21989 }
08f10d51 21990 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
21991 as_bad_where (fixP->fx_file, fixP->fx_line,
21992 _("conditional branch out of range"));
404ff6b5 21993
2fc8bdac
ZW
21994 if (fixP->fx_done || !seg->use_rela_p)
21995 {
21996 offsetT newval2;
21997 addressT S, J1, J2, lo, hi;
404ff6b5 21998
2fc8bdac
ZW
21999 S = (value & 0x00100000) >> 20;
22000 J2 = (value & 0x00080000) >> 19;
22001 J1 = (value & 0x00040000) >> 18;
22002 hi = (value & 0x0003f000) >> 12;
22003 lo = (value & 0x00000ffe) >> 1;
6c43fab6 22004
2fc8bdac
ZW
22005 newval = md_chars_to_number (buf, THUMB_SIZE);
22006 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22007 newval |= (S << 10) | hi;
22008 newval2 |= (J1 << 13) | (J2 << 11) | lo;
22009 md_number_to_chars (buf, newval, THUMB_SIZE);
22010 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22011 }
c19d1205 22012 break;
6c43fab6 22013
c19d1205 22014 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
22015 /* If there is a blx from a thumb state function to
22016 another thumb function flip this to a bl and warn
22017 about it. */
22018
22019 if (fixP->fx_addsy
34e77a92 22020 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22021 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22022 && THUMB_IS_FUNC (fixP->fx_addsy))
22023 {
22024 const char *name = S_GET_NAME (fixP->fx_addsy);
22025 as_warn_where (fixP->fx_file, fixP->fx_line,
22026 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
22027 name);
22028 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22029 newval = newval | 0x1000;
22030 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22031 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22032 fixP->fx_done = 1;
22033 }
22034
22035
22036 goto thumb_bl_common;
22037
c19d1205 22038 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
22039 /* A bl from Thumb state ISA to an internal ARM state function
22040 is converted to a blx. */
22041 if (fixP->fx_addsy
22042 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22043 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22044 && ARM_IS_FUNC (fixP->fx_addsy)
22045 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22046 {
22047 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22048 newval = newval & ~0x1000;
22049 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22050 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
22051 fixP->fx_done = 1;
22052 }
22053
22054 thumb_bl_common:
22055
2fc8bdac
ZW
22056 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22057 /* For a BLX instruction, make sure that the relocation is rounded up
22058 to a word boundary. This follows the semantics of the instruction
22059 which specifies that bit 1 of the target address will come from bit
22060 1 of the base address. */
d406f3e4
JB
22061 value = (value + 3) & ~ 3;
22062
22063#ifdef OBJ_ELF
22064 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
22065 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22066 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22067#endif
404ff6b5 22068
2b2f5df9
NC
22069 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
22070 {
22071 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
22072 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22073 else if ((value & ~0x1ffffff)
22074 && ((value & ~0x1ffffff) != ~0x1ffffff))
22075 as_bad_where (fixP->fx_file, fixP->fx_line,
22076 _("Thumb2 branch out of range"));
22077 }
4a42ebbc
RR
22078
22079 if (fixP->fx_done || !seg->use_rela_p)
22080 encode_thumb2_b_bl_offset (buf, value);
22081
c19d1205 22082 break;
404ff6b5 22083
c19d1205 22084 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
22085 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
22086 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 22087
2fc8bdac 22088 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 22089 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 22090
2fc8bdac 22091 break;
a737bd4d 22092
2fc8bdac
ZW
22093 case BFD_RELOC_8:
22094 if (fixP->fx_done || !seg->use_rela_p)
22095 md_number_to_chars (buf, value, 1);
c19d1205 22096 break;
a737bd4d 22097
c19d1205 22098 case BFD_RELOC_16:
2fc8bdac 22099 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 22100 md_number_to_chars (buf, value, 2);
c19d1205 22101 break;
a737bd4d 22102
c19d1205 22103#ifdef OBJ_ELF
0855e32b
NS
22104 case BFD_RELOC_ARM_TLS_CALL:
22105 case BFD_RELOC_ARM_THM_TLS_CALL:
22106 case BFD_RELOC_ARM_TLS_DESCSEQ:
22107 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
22108 S_SET_THREAD_LOCAL (fixP->fx_addsy);
22109 break;
22110
22111 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
22112 case BFD_RELOC_ARM_TLS_GD32:
22113 case BFD_RELOC_ARM_TLS_LE32:
22114 case BFD_RELOC_ARM_TLS_IE32:
22115 case BFD_RELOC_ARM_TLS_LDM32:
22116 case BFD_RELOC_ARM_TLS_LDO32:
22117 S_SET_THREAD_LOCAL (fixP->fx_addsy);
22118 /* fall through */
6c43fab6 22119
c19d1205
ZW
22120 case BFD_RELOC_ARM_GOT32:
22121 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
22122 if (fixP->fx_done || !seg->use_rela_p)
22123 md_number_to_chars (buf, 0, 4);
c19d1205 22124 break;
b43420e6
NC
22125
22126 case BFD_RELOC_ARM_GOT_PREL:
22127 if (fixP->fx_done || !seg->use_rela_p)
22128 md_number_to_chars (buf, value, 4);
22129 break;
22130
9a6f4e97
NS
22131 case BFD_RELOC_ARM_TARGET2:
22132 /* TARGET2 is not partial-inplace, so we need to write the
22133 addend here for REL targets, because it won't be written out
22134 during reloc processing later. */
22135 if (fixP->fx_done || !seg->use_rela_p)
22136 md_number_to_chars (buf, fixP->fx_offset, 4);
22137 break;
c19d1205 22138#endif
6c43fab6 22139
c19d1205
ZW
22140 case BFD_RELOC_RVA:
22141 case BFD_RELOC_32:
22142 case BFD_RELOC_ARM_TARGET1:
22143 case BFD_RELOC_ARM_ROSEGREL32:
22144 case BFD_RELOC_ARM_SBREL32:
22145 case BFD_RELOC_32_PCREL:
f0927246
NC
22146#ifdef TE_PE
22147 case BFD_RELOC_32_SECREL:
22148#endif
2fc8bdac 22149 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
22150#ifdef TE_WINCE
22151 /* For WinCE we only do this for pcrel fixups. */
22152 if (fixP->fx_done || fixP->fx_pcrel)
22153#endif
22154 md_number_to_chars (buf, value, 4);
c19d1205 22155 break;
6c43fab6 22156
c19d1205
ZW
22157#ifdef OBJ_ELF
22158 case BFD_RELOC_ARM_PREL31:
2fc8bdac 22159 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
22160 {
22161 newval = md_chars_to_number (buf, 4) & 0x80000000;
22162 if ((value ^ (value >> 1)) & 0x40000000)
22163 {
22164 as_bad_where (fixP->fx_file, fixP->fx_line,
22165 _("rel31 relocation overflow"));
22166 }
22167 newval |= value & 0x7fffffff;
22168 md_number_to_chars (buf, newval, 4);
22169 }
22170 break;
c19d1205 22171#endif
a737bd4d 22172
c19d1205 22173 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 22174 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
22175 if (value < -1023 || value > 1023 || (value & 3))
22176 as_bad_where (fixP->fx_file, fixP->fx_line,
22177 _("co-processor offset out of range"));
22178 cp_off_common:
26d97720 22179 sign = value > 0;
c19d1205
ZW
22180 if (value < 0)
22181 value = -value;
8f06b2d8
PB
22182 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22183 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22184 newval = md_chars_to_number (buf, INSN_SIZE);
22185 else
22186 newval = get_thumb32_insn (buf);
26d97720
NS
22187 if (value == 0)
22188 newval &= 0xffffff00;
22189 else
22190 {
22191 newval &= 0xff7fff00;
22192 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
22193 }
8f06b2d8
PB
22194 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22195 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22196 md_number_to_chars (buf, newval, INSN_SIZE);
22197 else
22198 put_thumb32_insn (buf, newval);
c19d1205 22199 break;
a737bd4d 22200
c19d1205 22201 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 22202 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
22203 if (value < -255 || value > 255)
22204 as_bad_where (fixP->fx_file, fixP->fx_line,
22205 _("co-processor offset out of range"));
df7849c5 22206 value *= 4;
c19d1205 22207 goto cp_off_common;
6c43fab6 22208
c19d1205
ZW
22209 case BFD_RELOC_ARM_THUMB_OFFSET:
22210 newval = md_chars_to_number (buf, THUMB_SIZE);
22211 /* Exactly what ranges, and where the offset is inserted depends
22212 on the type of instruction, we can establish this from the
22213 top 4 bits. */
22214 switch (newval >> 12)
22215 {
22216 case 4: /* PC load. */
22217 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
22218 forced to zero for these loads; md_pcrel_from has already
22219 compensated for this. */
22220 if (value & 3)
22221 as_bad_where (fixP->fx_file, fixP->fx_line,
22222 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
22223 (((unsigned long) fixP->fx_frag->fr_address
22224 + (unsigned long) fixP->fx_where) & ~3)
22225 + (unsigned long) value);
a737bd4d 22226
c19d1205
ZW
22227 if (value & ~0x3fc)
22228 as_bad_where (fixP->fx_file, fixP->fx_line,
22229 _("invalid offset, value too big (0x%08lX)"),
22230 (long) value);
a737bd4d 22231
c19d1205
ZW
22232 newval |= value >> 2;
22233 break;
a737bd4d 22234
c19d1205
ZW
22235 case 9: /* SP load/store. */
22236 if (value & ~0x3fc)
22237 as_bad_where (fixP->fx_file, fixP->fx_line,
22238 _("invalid offset, value too big (0x%08lX)"),
22239 (long) value);
22240 newval |= value >> 2;
22241 break;
6c43fab6 22242
c19d1205
ZW
22243 case 6: /* Word load/store. */
22244 if (value & ~0x7c)
22245 as_bad_where (fixP->fx_file, fixP->fx_line,
22246 _("invalid offset, value too big (0x%08lX)"),
22247 (long) value);
22248 newval |= value << 4; /* 6 - 2. */
22249 break;
a737bd4d 22250
c19d1205
ZW
22251 case 7: /* Byte load/store. */
22252 if (value & ~0x1f)
22253 as_bad_where (fixP->fx_file, fixP->fx_line,
22254 _("invalid offset, value too big (0x%08lX)"),
22255 (long) value);
22256 newval |= value << 6;
22257 break;
a737bd4d 22258
c19d1205
ZW
22259 case 8: /* Halfword load/store. */
22260 if (value & ~0x3e)
22261 as_bad_where (fixP->fx_file, fixP->fx_line,
22262 _("invalid offset, value too big (0x%08lX)"),
22263 (long) value);
22264 newval |= value << 5; /* 6 - 1. */
22265 break;
a737bd4d 22266
c19d1205
ZW
22267 default:
22268 as_bad_where (fixP->fx_file, fixP->fx_line,
22269 "Unable to process relocation for thumb opcode: %lx",
22270 (unsigned long) newval);
22271 break;
22272 }
22273 md_number_to_chars (buf, newval, THUMB_SIZE);
22274 break;
a737bd4d 22275
c19d1205
ZW
22276 case BFD_RELOC_ARM_THUMB_ADD:
22277 /* This is a complicated relocation, since we use it for all of
22278 the following immediate relocations:
a737bd4d 22279
c19d1205
ZW
22280 3bit ADD/SUB
22281 8bit ADD/SUB
22282 9bit ADD/SUB SP word-aligned
22283 10bit ADD PC/SP word-aligned
a737bd4d 22284
c19d1205
ZW
22285 The type of instruction being processed is encoded in the
22286 instruction field:
a737bd4d 22287
c19d1205
ZW
22288 0x8000 SUB
22289 0x00F0 Rd
22290 0x000F Rs
22291 */
22292 newval = md_chars_to_number (buf, THUMB_SIZE);
22293 {
22294 int rd = (newval >> 4) & 0xf;
22295 int rs = newval & 0xf;
22296 int subtract = !!(newval & 0x8000);
a737bd4d 22297
c19d1205
ZW
22298 /* Check for HI regs, only very restricted cases allowed:
22299 Adjusting SP, and using PC or SP to get an address. */
22300 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
22301 || (rs > 7 && rs != REG_SP && rs != REG_PC))
22302 as_bad_where (fixP->fx_file, fixP->fx_line,
22303 _("invalid Hi register with immediate"));
a737bd4d 22304
c19d1205
ZW
22305 /* If value is negative, choose the opposite instruction. */
22306 if (value < 0)
22307 {
22308 value = -value;
22309 subtract = !subtract;
22310 if (value < 0)
22311 as_bad_where (fixP->fx_file, fixP->fx_line,
22312 _("immediate value out of range"));
22313 }
a737bd4d 22314
c19d1205
ZW
22315 if (rd == REG_SP)
22316 {
22317 if (value & ~0x1fc)
22318 as_bad_where (fixP->fx_file, fixP->fx_line,
22319 _("invalid immediate for stack address calculation"));
22320 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
22321 newval |= value >> 2;
22322 }
22323 else if (rs == REG_PC || rs == REG_SP)
22324 {
22325 if (subtract || value & ~0x3fc)
22326 as_bad_where (fixP->fx_file, fixP->fx_line,
22327 _("invalid immediate for address calculation (value = 0x%08lX)"),
22328 (unsigned long) value);
22329 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
22330 newval |= rd << 8;
22331 newval |= value >> 2;
22332 }
22333 else if (rs == rd)
22334 {
22335 if (value & ~0xff)
22336 as_bad_where (fixP->fx_file, fixP->fx_line,
22337 _("immediate value out of range"));
22338 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
22339 newval |= (rd << 8) | value;
22340 }
22341 else
22342 {
22343 if (value & ~0x7)
22344 as_bad_where (fixP->fx_file, fixP->fx_line,
22345 _("immediate value out of range"));
22346 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
22347 newval |= rd | (rs << 3) | (value << 6);
22348 }
22349 }
22350 md_number_to_chars (buf, newval, THUMB_SIZE);
22351 break;
a737bd4d 22352
c19d1205
ZW
22353 case BFD_RELOC_ARM_THUMB_IMM:
22354 newval = md_chars_to_number (buf, THUMB_SIZE);
22355 if (value < 0 || value > 255)
22356 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 22357 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
22358 (long) value);
22359 newval |= value;
22360 md_number_to_chars (buf, newval, THUMB_SIZE);
22361 break;
a737bd4d 22362
c19d1205
ZW
22363 case BFD_RELOC_ARM_THUMB_SHIFT:
22364 /* 5bit shift value (0..32). LSL cannot take 32. */
22365 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
22366 temp = newval & 0xf800;
22367 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
22368 as_bad_where (fixP->fx_file, fixP->fx_line,
22369 _("invalid shift value: %ld"), (long) value);
22370 /* Shifts of zero must be encoded as LSL. */
22371 if (value == 0)
22372 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
22373 /* Shifts of 32 are encoded as zero. */
22374 else if (value == 32)
22375 value = 0;
22376 newval |= value << 6;
22377 md_number_to_chars (buf, newval, THUMB_SIZE);
22378 break;
a737bd4d 22379
c19d1205
ZW
22380 case BFD_RELOC_VTABLE_INHERIT:
22381 case BFD_RELOC_VTABLE_ENTRY:
22382 fixP->fx_done = 0;
22383 return;
6c43fab6 22384
b6895b4f
PB
22385 case BFD_RELOC_ARM_MOVW:
22386 case BFD_RELOC_ARM_MOVT:
22387 case BFD_RELOC_ARM_THUMB_MOVW:
22388 case BFD_RELOC_ARM_THUMB_MOVT:
22389 if (fixP->fx_done || !seg->use_rela_p)
22390 {
22391 /* REL format relocations are limited to a 16-bit addend. */
22392 if (!fixP->fx_done)
22393 {
39623e12 22394 if (value < -0x8000 || value > 0x7fff)
b6895b4f 22395 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 22396 _("offset out of range"));
b6895b4f
PB
22397 }
22398 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
22399 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
22400 {
22401 value >>= 16;
22402 }
22403
22404 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
22405 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
22406 {
22407 newval = get_thumb32_insn (buf);
22408 newval &= 0xfbf08f00;
22409 newval |= (value & 0xf000) << 4;
22410 newval |= (value & 0x0800) << 15;
22411 newval |= (value & 0x0700) << 4;
22412 newval |= (value & 0x00ff);
22413 put_thumb32_insn (buf, newval);
22414 }
22415 else
22416 {
22417 newval = md_chars_to_number (buf, 4);
22418 newval &= 0xfff0f000;
22419 newval |= value & 0x0fff;
22420 newval |= (value & 0xf000) << 4;
22421 md_number_to_chars (buf, newval, 4);
22422 }
22423 }
22424 return;
22425
4962c51a
MS
22426 case BFD_RELOC_ARM_ALU_PC_G0_NC:
22427 case BFD_RELOC_ARM_ALU_PC_G0:
22428 case BFD_RELOC_ARM_ALU_PC_G1_NC:
22429 case BFD_RELOC_ARM_ALU_PC_G1:
22430 case BFD_RELOC_ARM_ALU_PC_G2:
22431 case BFD_RELOC_ARM_ALU_SB_G0_NC:
22432 case BFD_RELOC_ARM_ALU_SB_G0:
22433 case BFD_RELOC_ARM_ALU_SB_G1_NC:
22434 case BFD_RELOC_ARM_ALU_SB_G1:
22435 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 22436 gas_assert (!fixP->fx_done);
4962c51a
MS
22437 if (!seg->use_rela_p)
22438 {
22439 bfd_vma insn;
22440 bfd_vma encoded_addend;
22441 bfd_vma addend_abs = abs (value);
22442
22443 /* Check that the absolute value of the addend can be
22444 expressed as an 8-bit constant plus a rotation. */
22445 encoded_addend = encode_arm_immediate (addend_abs);
22446 if (encoded_addend == (unsigned int) FAIL)
22447 as_bad_where (fixP->fx_file, fixP->fx_line,
22448 _("the offset 0x%08lX is not representable"),
495bde8e 22449 (unsigned long) addend_abs);
4962c51a
MS
22450
22451 /* Extract the instruction. */
22452 insn = md_chars_to_number (buf, INSN_SIZE);
22453
22454 /* If the addend is positive, use an ADD instruction.
22455 Otherwise use a SUB. Take care not to destroy the S bit. */
22456 insn &= 0xff1fffff;
22457 if (value < 0)
22458 insn |= 1 << 22;
22459 else
22460 insn |= 1 << 23;
22461
22462 /* Place the encoded addend into the first 12 bits of the
22463 instruction. */
22464 insn &= 0xfffff000;
22465 insn |= encoded_addend;
5f4273c7
NC
22466
22467 /* Update the instruction. */
4962c51a
MS
22468 md_number_to_chars (buf, insn, INSN_SIZE);
22469 }
22470 break;
22471
22472 case BFD_RELOC_ARM_LDR_PC_G0:
22473 case BFD_RELOC_ARM_LDR_PC_G1:
22474 case BFD_RELOC_ARM_LDR_PC_G2:
22475 case BFD_RELOC_ARM_LDR_SB_G0:
22476 case BFD_RELOC_ARM_LDR_SB_G1:
22477 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 22478 gas_assert (!fixP->fx_done);
4962c51a
MS
22479 if (!seg->use_rela_p)
22480 {
22481 bfd_vma insn;
22482 bfd_vma addend_abs = abs (value);
22483
22484 /* Check that the absolute value of the addend can be
22485 encoded in 12 bits. */
22486 if (addend_abs >= 0x1000)
22487 as_bad_where (fixP->fx_file, fixP->fx_line,
22488 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 22489 (unsigned long) addend_abs);
4962c51a
MS
22490
22491 /* Extract the instruction. */
22492 insn = md_chars_to_number (buf, INSN_SIZE);
22493
22494 /* If the addend is negative, clear bit 23 of the instruction.
22495 Otherwise set it. */
22496 if (value < 0)
22497 insn &= ~(1 << 23);
22498 else
22499 insn |= 1 << 23;
22500
22501 /* Place the absolute value of the addend into the first 12 bits
22502 of the instruction. */
22503 insn &= 0xfffff000;
22504 insn |= addend_abs;
5f4273c7
NC
22505
22506 /* Update the instruction. */
4962c51a
MS
22507 md_number_to_chars (buf, insn, INSN_SIZE);
22508 }
22509 break;
22510
22511 case BFD_RELOC_ARM_LDRS_PC_G0:
22512 case BFD_RELOC_ARM_LDRS_PC_G1:
22513 case BFD_RELOC_ARM_LDRS_PC_G2:
22514 case BFD_RELOC_ARM_LDRS_SB_G0:
22515 case BFD_RELOC_ARM_LDRS_SB_G1:
22516 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 22517 gas_assert (!fixP->fx_done);
4962c51a
MS
22518 if (!seg->use_rela_p)
22519 {
22520 bfd_vma insn;
22521 bfd_vma addend_abs = abs (value);
22522
22523 /* Check that the absolute value of the addend can be
22524 encoded in 8 bits. */
22525 if (addend_abs >= 0x100)
22526 as_bad_where (fixP->fx_file, fixP->fx_line,
22527 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 22528 (unsigned long) addend_abs);
4962c51a
MS
22529
22530 /* Extract the instruction. */
22531 insn = md_chars_to_number (buf, INSN_SIZE);
22532
22533 /* If the addend is negative, clear bit 23 of the instruction.
22534 Otherwise set it. */
22535 if (value < 0)
22536 insn &= ~(1 << 23);
22537 else
22538 insn |= 1 << 23;
22539
22540 /* Place the first four bits of the absolute value of the addend
22541 into the first 4 bits of the instruction, and the remaining
22542 four into bits 8 .. 11. */
22543 insn &= 0xfffff0f0;
22544 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
22545
22546 /* Update the instruction. */
4962c51a
MS
22547 md_number_to_chars (buf, insn, INSN_SIZE);
22548 }
22549 break;
22550
22551 case BFD_RELOC_ARM_LDC_PC_G0:
22552 case BFD_RELOC_ARM_LDC_PC_G1:
22553 case BFD_RELOC_ARM_LDC_PC_G2:
22554 case BFD_RELOC_ARM_LDC_SB_G0:
22555 case BFD_RELOC_ARM_LDC_SB_G1:
22556 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 22557 gas_assert (!fixP->fx_done);
4962c51a
MS
22558 if (!seg->use_rela_p)
22559 {
22560 bfd_vma insn;
22561 bfd_vma addend_abs = abs (value);
22562
22563 /* Check that the absolute value of the addend is a multiple of
22564 four and, when divided by four, fits in 8 bits. */
22565 if (addend_abs & 0x3)
22566 as_bad_where (fixP->fx_file, fixP->fx_line,
22567 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 22568 (unsigned long) addend_abs);
4962c51a
MS
22569
22570 if ((addend_abs >> 2) > 0xff)
22571 as_bad_where (fixP->fx_file, fixP->fx_line,
22572 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 22573 (unsigned long) addend_abs);
4962c51a
MS
22574
22575 /* Extract the instruction. */
22576 insn = md_chars_to_number (buf, INSN_SIZE);
22577
22578 /* If the addend is negative, clear bit 23 of the instruction.
22579 Otherwise set it. */
22580 if (value < 0)
22581 insn &= ~(1 << 23);
22582 else
22583 insn |= 1 << 23;
22584
22585 /* Place the addend (divided by four) into the first eight
22586 bits of the instruction. */
22587 insn &= 0xfffffff0;
22588 insn |= addend_abs >> 2;
5f4273c7
NC
22589
22590 /* Update the instruction. */
4962c51a
MS
22591 md_number_to_chars (buf, insn, INSN_SIZE);
22592 }
22593 break;
22594
845b51d6
PB
22595 case BFD_RELOC_ARM_V4BX:
22596 /* This will need to go in the object file. */
22597 fixP->fx_done = 0;
22598 break;
22599
c19d1205
ZW
22600 case BFD_RELOC_UNUSED:
22601 default:
22602 as_bad_where (fixP->fx_file, fixP->fx_line,
22603 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
22604 }
6c43fab6
RE
22605}
22606
c19d1205
ZW
22607/* Translate internal representation of relocation info to BFD target
22608 format. */
a737bd4d 22609
c19d1205 22610arelent *
00a97672 22611tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 22612{
c19d1205
ZW
22613 arelent * reloc;
22614 bfd_reloc_code_real_type code;
a737bd4d 22615
21d799b5 22616 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 22617
21d799b5 22618 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
22619 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
22620 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 22621
2fc8bdac 22622 if (fixp->fx_pcrel)
00a97672
RS
22623 {
22624 if (section->use_rela_p)
22625 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
22626 else
22627 fixp->fx_offset = reloc->address;
22628 }
c19d1205 22629 reloc->addend = fixp->fx_offset;
a737bd4d 22630
c19d1205 22631 switch (fixp->fx_r_type)
a737bd4d 22632 {
c19d1205
ZW
22633 case BFD_RELOC_8:
22634 if (fixp->fx_pcrel)
22635 {
22636 code = BFD_RELOC_8_PCREL;
22637 break;
22638 }
a737bd4d 22639
c19d1205
ZW
22640 case BFD_RELOC_16:
22641 if (fixp->fx_pcrel)
22642 {
22643 code = BFD_RELOC_16_PCREL;
22644 break;
22645 }
6c43fab6 22646
c19d1205
ZW
22647 case BFD_RELOC_32:
22648 if (fixp->fx_pcrel)
22649 {
22650 code = BFD_RELOC_32_PCREL;
22651 break;
22652 }
a737bd4d 22653
b6895b4f
PB
22654 case BFD_RELOC_ARM_MOVW:
22655 if (fixp->fx_pcrel)
22656 {
22657 code = BFD_RELOC_ARM_MOVW_PCREL;
22658 break;
22659 }
22660
22661 case BFD_RELOC_ARM_MOVT:
22662 if (fixp->fx_pcrel)
22663 {
22664 code = BFD_RELOC_ARM_MOVT_PCREL;
22665 break;
22666 }
22667
22668 case BFD_RELOC_ARM_THUMB_MOVW:
22669 if (fixp->fx_pcrel)
22670 {
22671 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
22672 break;
22673 }
22674
22675 case BFD_RELOC_ARM_THUMB_MOVT:
22676 if (fixp->fx_pcrel)
22677 {
22678 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
22679 break;
22680 }
22681
c19d1205
ZW
22682 case BFD_RELOC_NONE:
22683 case BFD_RELOC_ARM_PCREL_BRANCH:
22684 case BFD_RELOC_ARM_PCREL_BLX:
22685 case BFD_RELOC_RVA:
22686 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22687 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22688 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22689 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22690 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22691 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
22692 case BFD_RELOC_VTABLE_ENTRY:
22693 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
22694#ifdef TE_PE
22695 case BFD_RELOC_32_SECREL:
22696#endif
c19d1205
ZW
22697 code = fixp->fx_r_type;
22698 break;
a737bd4d 22699
00adf2d4
JB
22700 case BFD_RELOC_THUMB_PCREL_BLX:
22701#ifdef OBJ_ELF
22702 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
22703 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
22704 else
22705#endif
22706 code = BFD_RELOC_THUMB_PCREL_BLX;
22707 break;
22708
c19d1205
ZW
22709 case BFD_RELOC_ARM_LITERAL:
22710 case BFD_RELOC_ARM_HWLITERAL:
22711 /* If this is called then the a literal has
22712 been referenced across a section boundary. */
22713 as_bad_where (fixp->fx_file, fixp->fx_line,
22714 _("literal referenced across section boundary"));
22715 return NULL;
a737bd4d 22716
c19d1205 22717#ifdef OBJ_ELF
0855e32b
NS
22718 case BFD_RELOC_ARM_TLS_CALL:
22719 case BFD_RELOC_ARM_THM_TLS_CALL:
22720 case BFD_RELOC_ARM_TLS_DESCSEQ:
22721 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
22722 case BFD_RELOC_ARM_GOT32:
22723 case BFD_RELOC_ARM_GOTOFF:
b43420e6 22724 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
22725 case BFD_RELOC_ARM_PLT32:
22726 case BFD_RELOC_ARM_TARGET1:
22727 case BFD_RELOC_ARM_ROSEGREL32:
22728 case BFD_RELOC_ARM_SBREL32:
22729 case BFD_RELOC_ARM_PREL31:
22730 case BFD_RELOC_ARM_TARGET2:
22731 case BFD_RELOC_ARM_TLS_LE32:
22732 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
22733 case BFD_RELOC_ARM_PCREL_CALL:
22734 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
22735 case BFD_RELOC_ARM_ALU_PC_G0_NC:
22736 case BFD_RELOC_ARM_ALU_PC_G0:
22737 case BFD_RELOC_ARM_ALU_PC_G1_NC:
22738 case BFD_RELOC_ARM_ALU_PC_G1:
22739 case BFD_RELOC_ARM_ALU_PC_G2:
22740 case BFD_RELOC_ARM_LDR_PC_G0:
22741 case BFD_RELOC_ARM_LDR_PC_G1:
22742 case BFD_RELOC_ARM_LDR_PC_G2:
22743 case BFD_RELOC_ARM_LDRS_PC_G0:
22744 case BFD_RELOC_ARM_LDRS_PC_G1:
22745 case BFD_RELOC_ARM_LDRS_PC_G2:
22746 case BFD_RELOC_ARM_LDC_PC_G0:
22747 case BFD_RELOC_ARM_LDC_PC_G1:
22748 case BFD_RELOC_ARM_LDC_PC_G2:
22749 case BFD_RELOC_ARM_ALU_SB_G0_NC:
22750 case BFD_RELOC_ARM_ALU_SB_G0:
22751 case BFD_RELOC_ARM_ALU_SB_G1_NC:
22752 case BFD_RELOC_ARM_ALU_SB_G1:
22753 case BFD_RELOC_ARM_ALU_SB_G2:
22754 case BFD_RELOC_ARM_LDR_SB_G0:
22755 case BFD_RELOC_ARM_LDR_SB_G1:
22756 case BFD_RELOC_ARM_LDR_SB_G2:
22757 case BFD_RELOC_ARM_LDRS_SB_G0:
22758 case BFD_RELOC_ARM_LDRS_SB_G1:
22759 case BFD_RELOC_ARM_LDRS_SB_G2:
22760 case BFD_RELOC_ARM_LDC_SB_G0:
22761 case BFD_RELOC_ARM_LDC_SB_G1:
22762 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 22763 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
22764 code = fixp->fx_r_type;
22765 break;
a737bd4d 22766
0855e32b 22767 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
22768 case BFD_RELOC_ARM_TLS_GD32:
22769 case BFD_RELOC_ARM_TLS_IE32:
22770 case BFD_RELOC_ARM_TLS_LDM32:
22771 /* BFD will include the symbol's address in the addend.
22772 But we don't want that, so subtract it out again here. */
22773 if (!S_IS_COMMON (fixp->fx_addsy))
22774 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
22775 code = fixp->fx_r_type;
22776 break;
22777#endif
a737bd4d 22778
c19d1205
ZW
22779 case BFD_RELOC_ARM_IMMEDIATE:
22780 as_bad_where (fixp->fx_file, fixp->fx_line,
22781 _("internal relocation (type: IMMEDIATE) not fixed up"));
22782 return NULL;
a737bd4d 22783
c19d1205
ZW
22784 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22785 as_bad_where (fixp->fx_file, fixp->fx_line,
22786 _("ADRL used for a symbol not defined in the same file"));
22787 return NULL;
a737bd4d 22788
c19d1205 22789 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
22790 if (section->use_rela_p)
22791 {
22792 code = fixp->fx_r_type;
22793 break;
22794 }
22795
c19d1205
ZW
22796 if (fixp->fx_addsy != NULL
22797 && !S_IS_DEFINED (fixp->fx_addsy)
22798 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 22799 {
c19d1205
ZW
22800 as_bad_where (fixp->fx_file, fixp->fx_line,
22801 _("undefined local label `%s'"),
22802 S_GET_NAME (fixp->fx_addsy));
22803 return NULL;
a737bd4d
NC
22804 }
22805
c19d1205
ZW
22806 as_bad_where (fixp->fx_file, fixp->fx_line,
22807 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
22808 return NULL;
a737bd4d 22809
c19d1205
ZW
22810 default:
22811 {
22812 char * type;
6c43fab6 22813
c19d1205
ZW
22814 switch (fixp->fx_r_type)
22815 {
22816 case BFD_RELOC_NONE: type = "NONE"; break;
22817 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
22818 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 22819 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
22820 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
22821 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
22822 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 22823 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 22824 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
22825 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
22826 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
22827 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
22828 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
22829 default: type = _("<unknown>"); break;
22830 }
22831 as_bad_where (fixp->fx_file, fixp->fx_line,
22832 _("cannot represent %s relocation in this object file format"),
22833 type);
22834 return NULL;
22835 }
a737bd4d 22836 }
6c43fab6 22837
c19d1205
ZW
22838#ifdef OBJ_ELF
22839 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
22840 && GOT_symbol
22841 && fixp->fx_addsy == GOT_symbol)
22842 {
22843 code = BFD_RELOC_ARM_GOTPC;
22844 reloc->addend = fixp->fx_offset = reloc->address;
22845 }
22846#endif
6c43fab6 22847
c19d1205 22848 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 22849
c19d1205
ZW
22850 if (reloc->howto == NULL)
22851 {
22852 as_bad_where (fixp->fx_file, fixp->fx_line,
22853 _("cannot represent %s relocation in this object file format"),
22854 bfd_get_reloc_code_name (code));
22855 return NULL;
22856 }
6c43fab6 22857
c19d1205
ZW
22858 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
22859 vtable entry to be used in the relocation's section offset. */
22860 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
22861 reloc->address = fixp->fx_offset;
6c43fab6 22862
c19d1205 22863 return reloc;
6c43fab6
RE
22864}
22865
c19d1205 22866/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 22867
c19d1205
ZW
22868void
22869cons_fix_new_arm (fragS * frag,
22870 int where,
22871 int size,
22872 expressionS * exp)
6c43fab6 22873{
c19d1205
ZW
22874 bfd_reloc_code_real_type type;
22875 int pcrel = 0;
6c43fab6 22876
c19d1205
ZW
22877 /* Pick a reloc.
22878 FIXME: @@ Should look at CPU word size. */
22879 switch (size)
22880 {
22881 case 1:
22882 type = BFD_RELOC_8;
22883 break;
22884 case 2:
22885 type = BFD_RELOC_16;
22886 break;
22887 case 4:
22888 default:
22889 type = BFD_RELOC_32;
22890 break;
22891 case 8:
22892 type = BFD_RELOC_64;
22893 break;
22894 }
6c43fab6 22895
f0927246
NC
22896#ifdef TE_PE
22897 if (exp->X_op == O_secrel)
22898 {
22899 exp->X_op = O_symbol;
22900 type = BFD_RELOC_32_SECREL;
22901 }
22902#endif
22903
c19d1205
ZW
22904 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
22905}
6c43fab6 22906
4343666d 22907#if defined (OBJ_COFF)
c19d1205
ZW
22908void
22909arm_validate_fix (fixS * fixP)
6c43fab6 22910{
c19d1205
ZW
22911 /* If the destination of the branch is a defined symbol which does not have
22912 the THUMB_FUNC attribute, then we must be calling a function which has
22913 the (interfacearm) attribute. We look for the Thumb entry point to that
22914 function and change the branch to refer to that function instead. */
22915 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
22916 && fixP->fx_addsy != NULL
22917 && S_IS_DEFINED (fixP->fx_addsy)
22918 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 22919 {
c19d1205 22920 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 22921 }
c19d1205
ZW
22922}
22923#endif
6c43fab6 22924
267bf995 22925
c19d1205
ZW
22926int
22927arm_force_relocation (struct fix * fixp)
22928{
22929#if defined (OBJ_COFF) && defined (TE_PE)
22930 if (fixp->fx_r_type == BFD_RELOC_RVA)
22931 return 1;
22932#endif
6c43fab6 22933
267bf995
RR
22934 /* In case we have a call or a branch to a function in ARM ISA mode from
22935 a thumb function or vice-versa force the relocation. These relocations
22936 are cleared off for some cores that might have blx and simple transformations
22937 are possible. */
22938
22939#ifdef OBJ_ELF
22940 switch (fixp->fx_r_type)
22941 {
22942 case BFD_RELOC_ARM_PCREL_JUMP:
22943 case BFD_RELOC_ARM_PCREL_CALL:
22944 case BFD_RELOC_THUMB_PCREL_BLX:
22945 if (THUMB_IS_FUNC (fixp->fx_addsy))
22946 return 1;
22947 break;
22948
22949 case BFD_RELOC_ARM_PCREL_BLX:
22950 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22951 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22952 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22953 if (ARM_IS_FUNC (fixp->fx_addsy))
22954 return 1;
22955 break;
22956
22957 default:
22958 break;
22959 }
22960#endif
22961
b5884301
PB
22962 /* Resolve these relocations even if the symbol is extern or weak.
22963 Technically this is probably wrong due to symbol preemption.
22964 In practice these relocations do not have enough range to be useful
22965 at dynamic link time, and some code (e.g. in the Linux kernel)
22966 expects these references to be resolved. */
c19d1205
ZW
22967 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
22968 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 22969 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 22970 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
22971 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22972 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
22973 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 22974 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
22975 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22976 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
22977 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
22978 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
22979 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
22980 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 22981 return 0;
a737bd4d 22982
4962c51a
MS
22983 /* Always leave these relocations for the linker. */
22984 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22985 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22986 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
22987 return 1;
22988
f0291e4c
PB
22989 /* Always generate relocations against function symbols. */
22990 if (fixp->fx_r_type == BFD_RELOC_32
22991 && fixp->fx_addsy
22992 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
22993 return 1;
22994
c19d1205 22995 return generic_force_reloc (fixp);
404ff6b5
AH
22996}
22997
0ffdc86c 22998#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
22999/* Relocations against function names must be left unadjusted,
23000 so that the linker can use this information to generate interworking
23001 stubs. The MIPS version of this function
c19d1205
ZW
23002 also prevents relocations that are mips-16 specific, but I do not
23003 know why it does this.
404ff6b5 23004
c19d1205
ZW
23005 FIXME:
23006 There is one other problem that ought to be addressed here, but
23007 which currently is not: Taking the address of a label (rather
23008 than a function) and then later jumping to that address. Such
23009 addresses also ought to have their bottom bit set (assuming that
23010 they reside in Thumb code), but at the moment they will not. */
404ff6b5 23011
c19d1205
ZW
23012bfd_boolean
23013arm_fix_adjustable (fixS * fixP)
404ff6b5 23014{
c19d1205
ZW
23015 if (fixP->fx_addsy == NULL)
23016 return 1;
404ff6b5 23017
e28387c3
PB
23018 /* Preserve relocations against symbols with function type. */
23019 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 23020 return FALSE;
e28387c3 23021
c19d1205
ZW
23022 if (THUMB_IS_FUNC (fixP->fx_addsy)
23023 && fixP->fx_subsy == NULL)
c921be7d 23024 return FALSE;
a737bd4d 23025
c19d1205
ZW
23026 /* We need the symbol name for the VTABLE entries. */
23027 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
23028 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 23029 return FALSE;
404ff6b5 23030
c19d1205
ZW
23031 /* Don't allow symbols to be discarded on GOT related relocs. */
23032 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
23033 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
23034 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
23035 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
23036 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
23037 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
23038 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
23039 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
23040 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
23041 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
23042 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
23043 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
23044 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 23045 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 23046 return FALSE;
a737bd4d 23047
4962c51a
MS
23048 /* Similarly for group relocations. */
23049 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
23050 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
23051 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 23052 return FALSE;
4962c51a 23053
79947c54
CD
23054 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
23055 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
23056 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23057 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
23058 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
23059 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23060 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
23061 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
23062 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 23063 return FALSE;
79947c54 23064
c921be7d 23065 return TRUE;
a737bd4d 23066}
0ffdc86c
NC
23067#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
23068
23069#ifdef OBJ_ELF
404ff6b5 23070
c19d1205
ZW
23071const char *
23072elf32_arm_target_format (void)
404ff6b5 23073{
c19d1205
ZW
23074#ifdef TE_SYMBIAN
23075 return (target_big_endian
23076 ? "elf32-bigarm-symbian"
23077 : "elf32-littlearm-symbian");
23078#elif defined (TE_VXWORKS)
23079 return (target_big_endian
23080 ? "elf32-bigarm-vxworks"
23081 : "elf32-littlearm-vxworks");
b38cadfb
NC
23082#elif defined (TE_NACL)
23083 return (target_big_endian
23084 ? "elf32-bigarm-nacl"
23085 : "elf32-littlearm-nacl");
c19d1205
ZW
23086#else
23087 if (target_big_endian)
23088 return "elf32-bigarm";
23089 else
23090 return "elf32-littlearm";
23091#endif
404ff6b5
AH
23092}
23093
c19d1205
ZW
23094void
23095armelf_frob_symbol (symbolS * symp,
23096 int * puntp)
404ff6b5 23097{
c19d1205
ZW
23098 elf_frob_symbol (symp, puntp);
23099}
23100#endif
404ff6b5 23101
c19d1205 23102/* MD interface: Finalization. */
a737bd4d 23103
c19d1205
ZW
23104void
23105arm_cleanup (void)
23106{
23107 literal_pool * pool;
a737bd4d 23108
e07e6e58
NC
23109 /* Ensure that all the IT blocks are properly closed. */
23110 check_it_blocks_finished ();
23111
c19d1205
ZW
23112 for (pool = list_of_pools; pool; pool = pool->next)
23113 {
5f4273c7 23114 /* Put it at the end of the relevant section. */
c19d1205
ZW
23115 subseg_set (pool->section, pool->sub_section);
23116#ifdef OBJ_ELF
23117 arm_elf_change_section ();
23118#endif
23119 s_ltorg (0);
23120 }
404ff6b5
AH
23121}
23122
cd000bff
DJ
23123#ifdef OBJ_ELF
23124/* Remove any excess mapping symbols generated for alignment frags in
23125 SEC. We may have created a mapping symbol before a zero byte
23126 alignment; remove it if there's a mapping symbol after the
23127 alignment. */
23128static void
23129check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
23130 void *dummy ATTRIBUTE_UNUSED)
23131{
23132 segment_info_type *seginfo = seg_info (sec);
23133 fragS *fragp;
23134
23135 if (seginfo == NULL || seginfo->frchainP == NULL)
23136 return;
23137
23138 for (fragp = seginfo->frchainP->frch_root;
23139 fragp != NULL;
23140 fragp = fragp->fr_next)
23141 {
23142 symbolS *sym = fragp->tc_frag_data.last_map;
23143 fragS *next = fragp->fr_next;
23144
23145 /* Variable-sized frags have been converted to fixed size by
23146 this point. But if this was variable-sized to start with,
23147 there will be a fixed-size frag after it. So don't handle
23148 next == NULL. */
23149 if (sym == NULL || next == NULL)
23150 continue;
23151
23152 if (S_GET_VALUE (sym) < next->fr_address)
23153 /* Not at the end of this frag. */
23154 continue;
23155 know (S_GET_VALUE (sym) == next->fr_address);
23156
23157 do
23158 {
23159 if (next->tc_frag_data.first_map != NULL)
23160 {
23161 /* Next frag starts with a mapping symbol. Discard this
23162 one. */
23163 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23164 break;
23165 }
23166
23167 if (next->fr_next == NULL)
23168 {
23169 /* This mapping symbol is at the end of the section. Discard
23170 it. */
23171 know (next->fr_fix == 0 && next->fr_var == 0);
23172 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23173 break;
23174 }
23175
23176 /* As long as we have empty frags without any mapping symbols,
23177 keep looking. */
23178 /* If the next frag is non-empty and does not start with a
23179 mapping symbol, then this mapping symbol is required. */
23180 if (next->fr_address != next->fr_next->fr_address)
23181 break;
23182
23183 next = next->fr_next;
23184 }
23185 while (next != NULL);
23186 }
23187}
23188#endif
23189
c19d1205
ZW
23190/* Adjust the symbol table. This marks Thumb symbols as distinct from
23191 ARM ones. */
404ff6b5 23192
c19d1205
ZW
23193void
23194arm_adjust_symtab (void)
404ff6b5 23195{
c19d1205
ZW
23196#ifdef OBJ_COFF
23197 symbolS * sym;
404ff6b5 23198
c19d1205
ZW
23199 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
23200 {
23201 if (ARM_IS_THUMB (sym))
23202 {
23203 if (THUMB_IS_FUNC (sym))
23204 {
23205 /* Mark the symbol as a Thumb function. */
23206 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
23207 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
23208 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 23209
c19d1205
ZW
23210 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
23211 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
23212 else
23213 as_bad (_("%s: unexpected function type: %d"),
23214 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
23215 }
23216 else switch (S_GET_STORAGE_CLASS (sym))
23217 {
23218 case C_EXT:
23219 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
23220 break;
23221 case C_STAT:
23222 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
23223 break;
23224 case C_LABEL:
23225 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
23226 break;
23227 default:
23228 /* Do nothing. */
23229 break;
23230 }
23231 }
a737bd4d 23232
c19d1205
ZW
23233 if (ARM_IS_INTERWORK (sym))
23234 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 23235 }
c19d1205
ZW
23236#endif
23237#ifdef OBJ_ELF
23238 symbolS * sym;
23239 char bind;
404ff6b5 23240
c19d1205 23241 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 23242 {
c19d1205
ZW
23243 if (ARM_IS_THUMB (sym))
23244 {
23245 elf_symbol_type * elf_sym;
404ff6b5 23246
c19d1205
ZW
23247 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
23248 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 23249
b0796911
PB
23250 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
23251 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
23252 {
23253 /* If it's a .thumb_func, declare it as so,
23254 otherwise tag label as .code 16. */
23255 if (THUMB_IS_FUNC (sym))
35fc36a8
RS
23256 elf_sym->internal_elf_sym.st_target_internal
23257 = ST_BRANCH_TO_THUMB;
3ba67470 23258 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
23259 elf_sym->internal_elf_sym.st_info =
23260 ELF_ST_INFO (bind, STT_ARM_16BIT);
23261 }
23262 }
23263 }
cd000bff
DJ
23264
23265 /* Remove any overlapping mapping symbols generated by alignment frags. */
23266 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
23267 /* Now do generic ELF adjustments. */
23268 elf_adjust_symtab ();
c19d1205 23269#endif
404ff6b5
AH
23270}
23271
c19d1205 23272/* MD interface: Initialization. */
404ff6b5 23273
a737bd4d 23274static void
c19d1205 23275set_constant_flonums (void)
a737bd4d 23276{
c19d1205 23277 int i;
404ff6b5 23278
c19d1205
ZW
23279 for (i = 0; i < NUM_FLOAT_VALS; i++)
23280 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
23281 abort ();
a737bd4d 23282}
404ff6b5 23283
3e9e4fcf
JB
23284/* Auto-select Thumb mode if it's the only available instruction set for the
23285 given architecture. */
23286
23287static void
23288autoselect_thumb_from_cpu_variant (void)
23289{
23290 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
23291 opcode_select (16);
23292}
23293
c19d1205
ZW
23294void
23295md_begin (void)
a737bd4d 23296{
c19d1205
ZW
23297 unsigned mach;
23298 unsigned int i;
404ff6b5 23299
c19d1205
ZW
23300 if ( (arm_ops_hsh = hash_new ()) == NULL
23301 || (arm_cond_hsh = hash_new ()) == NULL
23302 || (arm_shift_hsh = hash_new ()) == NULL
23303 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 23304 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 23305 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
23306 || (arm_reloc_hsh = hash_new ()) == NULL
23307 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
23308 as_fatal (_("virtual memory exhausted"));
23309
23310 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 23311 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 23312 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 23313 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 23314 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 23315 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 23316 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 23317 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 23318 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0
NC
23319 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
23320 (void *) (v7m_psrs + i));
c19d1205 23321 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 23322 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
23323 for (i = 0;
23324 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
23325 i++)
d3ce72d0 23326 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 23327 (void *) (barrier_opt_names + i));
c19d1205 23328#ifdef OBJ_ELF
3da1d841
NC
23329 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
23330 {
23331 struct reloc_entry * entry = reloc_names + i;
23332
23333 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
23334 /* This makes encode_branch() use the EABI versions of this relocation. */
23335 entry->reloc = BFD_RELOC_UNUSED;
23336
23337 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
23338 }
c19d1205
ZW
23339#endif
23340
23341 set_constant_flonums ();
404ff6b5 23342
c19d1205
ZW
23343 /* Set the cpu variant based on the command-line options. We prefer
23344 -mcpu= over -march= if both are set (as for GCC); and we prefer
23345 -mfpu= over any other way of setting the floating point unit.
23346 Use of legacy options with new options are faulted. */
e74cfd16 23347 if (legacy_cpu)
404ff6b5 23348 {
e74cfd16 23349 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
23350 as_bad (_("use of old and new-style options to set CPU type"));
23351
23352 mcpu_cpu_opt = legacy_cpu;
404ff6b5 23353 }
e74cfd16 23354 else if (!mcpu_cpu_opt)
c19d1205 23355 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 23356
e74cfd16 23357 if (legacy_fpu)
c19d1205 23358 {
e74cfd16 23359 if (mfpu_opt)
c19d1205 23360 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
23361
23362 mfpu_opt = legacy_fpu;
23363 }
e74cfd16 23364 else if (!mfpu_opt)
03b1477f 23365 {
45eb4c1b
NS
23366#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
23367 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
23368 /* Some environments specify a default FPU. If they don't, infer it
23369 from the processor. */
e74cfd16 23370 if (mcpu_fpu_opt)
03b1477f
RE
23371 mfpu_opt = mcpu_fpu_opt;
23372 else
23373 mfpu_opt = march_fpu_opt;
39c2da32 23374#else
e74cfd16 23375 mfpu_opt = &fpu_default;
39c2da32 23376#endif
03b1477f
RE
23377 }
23378
e74cfd16 23379 if (!mfpu_opt)
03b1477f 23380 {
493cb6ef 23381 if (mcpu_cpu_opt != NULL)
e74cfd16 23382 mfpu_opt = &fpu_default;
493cb6ef 23383 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 23384 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 23385 else
e74cfd16 23386 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
23387 }
23388
ee065d83 23389#ifdef CPU_DEFAULT
e74cfd16 23390 if (!mcpu_cpu_opt)
ee065d83 23391 {
e74cfd16
PB
23392 mcpu_cpu_opt = &cpu_default;
23393 selected_cpu = cpu_default;
ee065d83 23394 }
e74cfd16
PB
23395#else
23396 if (mcpu_cpu_opt)
23397 selected_cpu = *mcpu_cpu_opt;
ee065d83 23398 else
e74cfd16 23399 mcpu_cpu_opt = &arm_arch_any;
ee065d83 23400#endif
03b1477f 23401
e74cfd16 23402 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 23403
3e9e4fcf
JB
23404 autoselect_thumb_from_cpu_variant ();
23405
e74cfd16 23406 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 23407
f17c130b 23408#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 23409 {
7cc69913
NC
23410 unsigned int flags = 0;
23411
23412#if defined OBJ_ELF
23413 flags = meabi_flags;
d507cf36
PB
23414
23415 switch (meabi_flags)
33a392fb 23416 {
d507cf36 23417 case EF_ARM_EABI_UNKNOWN:
7cc69913 23418#endif
d507cf36
PB
23419 /* Set the flags in the private structure. */
23420 if (uses_apcs_26) flags |= F_APCS26;
23421 if (support_interwork) flags |= F_INTERWORK;
23422 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 23423 if (pic_code) flags |= F_PIC;
e74cfd16 23424 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
23425 flags |= F_SOFT_FLOAT;
23426
d507cf36
PB
23427 switch (mfloat_abi_opt)
23428 {
23429 case ARM_FLOAT_ABI_SOFT:
23430 case ARM_FLOAT_ABI_SOFTFP:
23431 flags |= F_SOFT_FLOAT;
23432 break;
33a392fb 23433
d507cf36
PB
23434 case ARM_FLOAT_ABI_HARD:
23435 if (flags & F_SOFT_FLOAT)
23436 as_bad (_("hard-float conflicts with specified fpu"));
23437 break;
23438 }
03b1477f 23439
e74cfd16
PB
23440 /* Using pure-endian doubles (even if soft-float). */
23441 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 23442 flags |= F_VFP_FLOAT;
f17c130b 23443
fde78edd 23444#if defined OBJ_ELF
e74cfd16 23445 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 23446 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
23447 break;
23448
8cb51566 23449 case EF_ARM_EABI_VER4:
3a4a14e9 23450 case EF_ARM_EABI_VER5:
c19d1205 23451 /* No additional flags to set. */
d507cf36
PB
23452 break;
23453
23454 default:
23455 abort ();
23456 }
7cc69913 23457#endif
b99bd4ef
NC
23458 bfd_set_private_flags (stdoutput, flags);
23459
23460 /* We have run out flags in the COFF header to encode the
23461 status of ATPCS support, so instead we create a dummy,
c19d1205 23462 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
23463 if (atpcs)
23464 {
23465 asection * sec;
23466
23467 sec = bfd_make_section (stdoutput, ".arm.atpcs");
23468
23469 if (sec != NULL)
23470 {
23471 bfd_set_section_flags
23472 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
23473 bfd_set_section_size (stdoutput, sec, 0);
23474 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
23475 }
23476 }
7cc69913 23477 }
f17c130b 23478#endif
b99bd4ef
NC
23479
23480 /* Record the CPU type as well. */
2d447fca
JM
23481 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
23482 mach = bfd_mach_arm_iWMMXt2;
23483 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 23484 mach = bfd_mach_arm_iWMMXt;
e74cfd16 23485 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 23486 mach = bfd_mach_arm_XScale;
e74cfd16 23487 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 23488 mach = bfd_mach_arm_ep9312;
e74cfd16 23489 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 23490 mach = bfd_mach_arm_5TE;
e74cfd16 23491 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 23492 {
e74cfd16 23493 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
23494 mach = bfd_mach_arm_5T;
23495 else
23496 mach = bfd_mach_arm_5;
23497 }
e74cfd16 23498 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 23499 {
e74cfd16 23500 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
23501 mach = bfd_mach_arm_4T;
23502 else
23503 mach = bfd_mach_arm_4;
23504 }
e74cfd16 23505 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 23506 mach = bfd_mach_arm_3M;
e74cfd16
PB
23507 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
23508 mach = bfd_mach_arm_3;
23509 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
23510 mach = bfd_mach_arm_2a;
23511 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
23512 mach = bfd_mach_arm_2;
23513 else
23514 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
23515
23516 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
23517}
23518
c19d1205 23519/* Command line processing. */
b99bd4ef 23520
c19d1205
ZW
23521/* md_parse_option
23522 Invocation line includes a switch not recognized by the base assembler.
23523 See if it's a processor-specific option.
b99bd4ef 23524
c19d1205
ZW
23525 This routine is somewhat complicated by the need for backwards
23526 compatibility (since older releases of gcc can't be changed).
23527 The new options try to make the interface as compatible as
23528 possible with GCC.
b99bd4ef 23529
c19d1205 23530 New options (supported) are:
b99bd4ef 23531
c19d1205
ZW
23532 -mcpu=<cpu name> Assemble for selected processor
23533 -march=<architecture name> Assemble for selected architecture
23534 -mfpu=<fpu architecture> Assemble for selected FPU.
23535 -EB/-mbig-endian Big-endian
23536 -EL/-mlittle-endian Little-endian
23537 -k Generate PIC code
23538 -mthumb Start in Thumb mode
23539 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 23540
278df34e 23541 -m[no-]warn-deprecated Warn about deprecated features
267bf995 23542
c19d1205 23543 For now we will also provide support for:
b99bd4ef 23544
c19d1205
ZW
23545 -mapcs-32 32-bit Program counter
23546 -mapcs-26 26-bit Program counter
23547 -macps-float Floats passed in FP registers
23548 -mapcs-reentrant Reentrant code
23549 -matpcs
23550 (sometime these will probably be replaced with -mapcs=<list of options>
23551 and -matpcs=<list of options>)
b99bd4ef 23552
c19d1205
ZW
23553 The remaining options are only supported for back-wards compatibility.
23554 Cpu variants, the arm part is optional:
23555 -m[arm]1 Currently not supported.
23556 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
23557 -m[arm]3 Arm 3 processor
23558 -m[arm]6[xx], Arm 6 processors
23559 -m[arm]7[xx][t][[d]m] Arm 7 processors
23560 -m[arm]8[10] Arm 8 processors
23561 -m[arm]9[20][tdmi] Arm 9 processors
23562 -mstrongarm[110[0]] StrongARM processors
23563 -mxscale XScale processors
23564 -m[arm]v[2345[t[e]]] Arm architectures
23565 -mall All (except the ARM1)
23566 FP variants:
23567 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
23568 -mfpe-old (No float load/store multiples)
23569 -mvfpxd VFP Single precision
23570 -mvfp All VFP
23571 -mno-fpu Disable all floating point instructions
b99bd4ef 23572
c19d1205
ZW
23573 The following CPU names are recognized:
23574 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
23575 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
23576 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
23577 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
23578 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
23579 arm10t arm10e, arm1020t, arm1020e, arm10200e,
23580 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 23581
c19d1205 23582 */
b99bd4ef 23583
c19d1205 23584const char * md_shortopts = "m:k";
b99bd4ef 23585
c19d1205
ZW
23586#ifdef ARM_BI_ENDIAN
23587#define OPTION_EB (OPTION_MD_BASE + 0)
23588#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 23589#else
c19d1205
ZW
23590#if TARGET_BYTES_BIG_ENDIAN
23591#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 23592#else
c19d1205
ZW
23593#define OPTION_EL (OPTION_MD_BASE + 1)
23594#endif
b99bd4ef 23595#endif
845b51d6 23596#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 23597
c19d1205 23598struct option md_longopts[] =
b99bd4ef 23599{
c19d1205
ZW
23600#ifdef OPTION_EB
23601 {"EB", no_argument, NULL, OPTION_EB},
23602#endif
23603#ifdef OPTION_EL
23604 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 23605#endif
845b51d6 23606 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
23607 {NULL, no_argument, NULL, 0}
23608};
b99bd4ef 23609
c19d1205 23610size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 23611
c19d1205 23612struct arm_option_table
b99bd4ef 23613{
c19d1205
ZW
23614 char *option; /* Option name to match. */
23615 char *help; /* Help information. */
23616 int *var; /* Variable to change. */
23617 int value; /* What to change it to. */
23618 char *deprecated; /* If non-null, print this message. */
23619};
b99bd4ef 23620
c19d1205
ZW
23621struct arm_option_table arm_opts[] =
23622{
23623 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
23624 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
23625 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
23626 &support_interwork, 1, NULL},
23627 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
23628 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
23629 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
23630 1, NULL},
23631 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
23632 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
23633 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
23634 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
23635 NULL},
b99bd4ef 23636
c19d1205
ZW
23637 /* These are recognized by the assembler, but have no affect on code. */
23638 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
23639 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
23640
23641 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
23642 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
23643 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
23644 {NULL, NULL, NULL, 0, NULL}
23645};
23646
23647struct arm_legacy_option_table
23648{
23649 char *option; /* Option name to match. */
23650 const arm_feature_set **var; /* Variable to change. */
23651 const arm_feature_set value; /* What to change it to. */
23652 char *deprecated; /* If non-null, print this message. */
23653};
b99bd4ef 23654
e74cfd16
PB
23655const struct arm_legacy_option_table arm_legacy_opts[] =
23656{
c19d1205
ZW
23657 /* DON'T add any new processors to this list -- we want the whole list
23658 to go away... Add them to the processors table instead. */
e74cfd16
PB
23659 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
23660 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
23661 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
23662 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
23663 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
23664 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
23665 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
23666 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
23667 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
23668 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
23669 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
23670 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
23671 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
23672 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
23673 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
23674 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
23675 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
23676 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
23677 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
23678 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
23679 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
23680 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
23681 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
23682 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
23683 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
23684 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
23685 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
23686 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
23687 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
23688 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
23689 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
23690 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
23691 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
23692 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
23693 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
23694 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
23695 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
23696 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
23697 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
23698 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
23699 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
23700 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
23701 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
23702 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
23703 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
23704 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
23705 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23706 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23707 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23708 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23709 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
23710 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
23711 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
23712 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
23713 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
23714 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
23715 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
23716 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
23717 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
23718 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
23719 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
23720 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
23721 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
23722 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
23723 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
23724 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
23725 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
23726 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
23727 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
23728 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 23729 N_("use -mcpu=strongarm110")},
e74cfd16 23730 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 23731 N_("use -mcpu=strongarm1100")},
e74cfd16 23732 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 23733 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
23734 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
23735 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
23736 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 23737
c19d1205 23738 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
23739 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
23740 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
23741 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
23742 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
23743 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
23744 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
23745 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
23746 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
23747 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
23748 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
23749 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
23750 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
23751 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
23752 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
23753 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
23754 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
23755 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
23756 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 23757
c19d1205 23758 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
23759 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
23760 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
23761 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
23762 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 23763 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 23764
e74cfd16 23765 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 23766};
7ed4c4c5 23767
c19d1205 23768struct arm_cpu_option_table
7ed4c4c5 23769{
c19d1205 23770 char *name;
f3bad469 23771 size_t name_len;
e74cfd16 23772 const arm_feature_set value;
c19d1205
ZW
23773 /* For some CPUs we assume an FPU unless the user explicitly sets
23774 -mfpu=... */
e74cfd16 23775 const arm_feature_set default_fpu;
ee065d83
PB
23776 /* The canonical name of the CPU, or NULL to use NAME converted to upper
23777 case. */
23778 const char *canonical_name;
c19d1205 23779};
7ed4c4c5 23780
c19d1205
ZW
23781/* This list should, at a minimum, contain all the cpu names
23782 recognized by GCC. */
f3bad469 23783#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 23784static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 23785{
f3bad469
MGD
23786 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
23787 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
23788 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
23789 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
23790 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
23791 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23792 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23793 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23794 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23795 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23796 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23797 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23798 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23799 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23800 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23801 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23802 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23803 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23804 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23805 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23806 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23807 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23808 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23809 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23810 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23811 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23812 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23813 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23814 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23815 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23816 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23817 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23818 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23819 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23820 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23821 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23822 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23823 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23824 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23825 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
23826 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23827 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23828 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23829 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23830 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23831 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
23832 /* For V5 or later processors we default to using VFP; but the user
23833 should really set the FPU type explicitly. */
f3bad469
MGD
23834 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23835 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23836 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
23837 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
23838 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
23839 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23840 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
23841 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23842 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23843 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
23844 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23845 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23846 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23847 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23848 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23849 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
23850 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23851 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23852 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23853 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
23854 "ARM1026EJ-S"),
23855 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
23856 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23857 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23858 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23859 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23860 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23861 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
23862 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
23863 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
23864 "ARM1136JF-S"),
23865 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
23866 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
23867 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
23868 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
23869 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
23870 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL),
23871 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL),
23872 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
23873 FPU_NONE, "Cortex-A5"),
23874 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
23875 FPU_ARCH_NEON_VFP_V4,
23876 "Cortex-A7"),
23877 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
23878 ARM_FEATURE (0, FPU_VFP_V3
5287ad62 23879 | FPU_NEON_EXT_V1),
f3bad469
MGD
23880 "Cortex-A8"),
23881 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
23882 ARM_FEATURE (0, FPU_VFP_V3
15290f0a 23883 | FPU_NEON_EXT_V1),
f3bad469
MGD
23884 "Cortex-A9"),
23885 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
23886 FPU_ARCH_NEON_VFP_V4,
23887 "Cortex-A15"),
23888 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
23889 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
23890 "Cortex-R4F"),
23891 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
23892 FPU_NONE, "Cortex-R5"),
23893 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
23894 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
23895 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
23896 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 23897 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
c19d1205 23898 /* ??? XSCALE is really an architecture. */
f3bad469 23899 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 23900 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
23901 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
23902 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
23903 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 23904 /* Maverick */
f3bad469
MGD
23905 ARM_CPU_OPT ("ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
23906 FPU_ARCH_MAVERICK,
23907 "ARM920T"),
23908 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 23909};
f3bad469 23910#undef ARM_CPU_OPT
7ed4c4c5 23911
c19d1205 23912struct arm_arch_option_table
7ed4c4c5 23913{
c19d1205 23914 char *name;
f3bad469 23915 size_t name_len;
e74cfd16
PB
23916 const arm_feature_set value;
23917 const arm_feature_set default_fpu;
c19d1205 23918};
7ed4c4c5 23919
c19d1205
ZW
23920/* This list should, at a minimum, contain all the architecture names
23921 recognized by GCC. */
f3bad469 23922#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 23923static const struct arm_arch_option_table arm_archs[] =
c19d1205 23924{
f3bad469
MGD
23925 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
23926 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
23927 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
23928 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
23929 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
23930 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
23931 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
23932 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
23933 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
23934 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
23935 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
23936 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
23937 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
23938 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
23939 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
23940 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
23941 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
23942 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
23943 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
23944 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
23945 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
23946 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP),
23947 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
23948 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
23949 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
23950 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP),
23951 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
23952 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
23953 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
23954 /* The official spelling of the ARMv7 profile variants is the dashed form.
23955 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469
MGD
23956 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
23957 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
23958 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
23959 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
23960 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
23961 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
23962 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
bca38921 23963 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
f3bad469
MGD
23964 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
23965 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
23966 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
23967 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 23968};
f3bad469 23969#undef ARM_ARCH_OPT
7ed4c4c5 23970
69133863
MGD
23971/* ISA extensions in the co-processor and main instruction set space. */
23972struct arm_option_extension_value_table
c19d1205
ZW
23973{
23974 char *name;
f3bad469 23975 size_t name_len;
e74cfd16 23976 const arm_feature_set value;
69133863 23977 const arm_feature_set allowed_archs;
c19d1205 23978};
7ed4c4c5 23979
69133863
MGD
23980/* The following table must be in alphabetical order with a NULL last entry.
23981 */
f3bad469 23982#define ARM_EXT_OPT(N, V, AA) { N, sizeof (N) - 1, V, AA }
69133863 23983static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 23984{
bca38921
MGD
23985 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
23986 ARM_FEATURE (ARM_EXT_V8, 0)),
23987 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8,
23988 ARM_FEATURE (ARM_EXT_V8, 0)),
f3bad469
MGD
23989 ARM_EXT_OPT ("idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0),
23990 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
23991 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY),
23992 ARM_EXT_OPT ("iwmmxt2",
23993 ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY),
23994 ARM_EXT_OPT ("maverick",
23995 ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY),
23996 ARM_EXT_OPT ("mp", ARM_FEATURE (ARM_EXT_MP, 0),
23997 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
bca38921
MGD
23998 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
23999 ARM_FEATURE (ARM_EXT_V8, 0)),
f3bad469
MGD
24000 ARM_EXT_OPT ("os", ARM_FEATURE (ARM_EXT_OS, 0),
24001 ARM_FEATURE (ARM_EXT_V6M, 0)),
24002 ARM_EXT_OPT ("sec", ARM_FEATURE (ARM_EXT_SEC, 0),
24003 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)),
24004 ARM_EXT_OPT ("virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV
24005 | ARM_EXT_DIV, 0),
24006 ARM_FEATURE (ARM_EXT_V7A, 0)),
24007 ARM_EXT_OPT ("xscale",ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY),
24008 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
69133863 24009};
f3bad469 24010#undef ARM_EXT_OPT
69133863
MGD
24011
24012/* ISA floating-point and Advanced SIMD extensions. */
24013struct arm_option_fpu_value_table
24014{
24015 char *name;
24016 const arm_feature_set value;
c19d1205 24017};
7ed4c4c5 24018
c19d1205
ZW
24019/* This list should, at a minimum, contain all the fpu names
24020 recognized by GCC. */
69133863 24021static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
24022{
24023 {"softfpa", FPU_NONE},
24024 {"fpe", FPU_ARCH_FPE},
24025 {"fpe2", FPU_ARCH_FPE},
24026 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
24027 {"fpa", FPU_ARCH_FPA},
24028 {"fpa10", FPU_ARCH_FPA},
24029 {"fpa11", FPU_ARCH_FPA},
24030 {"arm7500fe", FPU_ARCH_FPA},
24031 {"softvfp", FPU_ARCH_VFP},
24032 {"softvfp+vfp", FPU_ARCH_VFP_V2},
24033 {"vfp", FPU_ARCH_VFP_V2},
24034 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 24035 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
24036 {"vfp10", FPU_ARCH_VFP_V2},
24037 {"vfp10-r0", FPU_ARCH_VFP_V1},
24038 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
24039 {"vfpv2", FPU_ARCH_VFP_V2},
24040 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 24041 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 24042 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
24043 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
24044 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
24045 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
24046 {"arm1020t", FPU_ARCH_VFP_V1},
24047 {"arm1020e", FPU_ARCH_VFP_V2},
24048 {"arm1136jfs", FPU_ARCH_VFP_V2},
24049 {"arm1136jf-s", FPU_ARCH_VFP_V2},
24050 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 24051 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 24052 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
24053 {"vfpv4", FPU_ARCH_VFP_V4},
24054 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 24055 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 24056 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
24057 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
24058 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
24059 {"crypto-neon-fp-armv8",
24060 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
e74cfd16
PB
24061 {NULL, ARM_ARCH_NONE}
24062};
24063
24064struct arm_option_value_table
24065{
24066 char *name;
24067 long value;
c19d1205 24068};
7ed4c4c5 24069
e74cfd16 24070static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
24071{
24072 {"hard", ARM_FLOAT_ABI_HARD},
24073 {"softfp", ARM_FLOAT_ABI_SOFTFP},
24074 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 24075 {NULL, 0}
c19d1205 24076};
7ed4c4c5 24077
c19d1205 24078#ifdef OBJ_ELF
3a4a14e9 24079/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 24080static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
24081{
24082 {"gnu", EF_ARM_EABI_UNKNOWN},
24083 {"4", EF_ARM_EABI_VER4},
3a4a14e9 24084 {"5", EF_ARM_EABI_VER5},
e74cfd16 24085 {NULL, 0}
c19d1205
ZW
24086};
24087#endif
7ed4c4c5 24088
c19d1205
ZW
24089struct arm_long_option_table
24090{
24091 char * option; /* Substring to match. */
24092 char * help; /* Help information. */
24093 int (* func) (char * subopt); /* Function to decode sub-option. */
24094 char * deprecated; /* If non-null, print this message. */
24095};
7ed4c4c5 24096
c921be7d 24097static bfd_boolean
f3bad469 24098arm_parse_extension (char *str, const arm_feature_set **opt_p)
7ed4c4c5 24099{
21d799b5
NC
24100 arm_feature_set *ext_set = (arm_feature_set *)
24101 xmalloc (sizeof (arm_feature_set));
e74cfd16 24102
69133863 24103 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
24104 extensions being added before being removed. We achieve this by having
24105 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 24106 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 24107 or removing it (0) and only allowing it to change in the order
69133863
MGD
24108 -1 -> 1 -> 0. */
24109 const struct arm_option_extension_value_table * opt = NULL;
24110 int adding_value = -1;
24111
e74cfd16
PB
24112 /* Copy the feature set, so that we can modify it. */
24113 *ext_set = **opt_p;
24114 *opt_p = ext_set;
24115
c19d1205 24116 while (str != NULL && *str != 0)
7ed4c4c5 24117 {
f3bad469
MGD
24118 char *ext;
24119 size_t len;
7ed4c4c5 24120
c19d1205
ZW
24121 if (*str != '+')
24122 {
24123 as_bad (_("invalid architectural extension"));
c921be7d 24124 return FALSE;
c19d1205 24125 }
7ed4c4c5 24126
c19d1205
ZW
24127 str++;
24128 ext = strchr (str, '+');
7ed4c4c5 24129
c19d1205 24130 if (ext != NULL)
f3bad469 24131 len = ext - str;
c19d1205 24132 else
f3bad469 24133 len = strlen (str);
7ed4c4c5 24134
f3bad469 24135 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
24136 {
24137 if (adding_value != 0)
24138 {
24139 adding_value = 0;
24140 opt = arm_extensions;
24141 }
24142
f3bad469 24143 len -= 2;
69133863
MGD
24144 str += 2;
24145 }
f3bad469 24146 else if (len > 0)
69133863
MGD
24147 {
24148 if (adding_value == -1)
24149 {
24150 adding_value = 1;
24151 opt = arm_extensions;
24152 }
24153 else if (adding_value != 1)
24154 {
24155 as_bad (_("must specify extensions to add before specifying "
24156 "those to remove"));
24157 return FALSE;
24158 }
24159 }
24160
f3bad469 24161 if (len == 0)
c19d1205
ZW
24162 {
24163 as_bad (_("missing architectural extension"));
c921be7d 24164 return FALSE;
c19d1205 24165 }
7ed4c4c5 24166
69133863
MGD
24167 gas_assert (adding_value != -1);
24168 gas_assert (opt != NULL);
24169
24170 /* Scan over the options table trying to find an exact match. */
24171 for (; opt->name != NULL; opt++)
f3bad469 24172 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 24173 {
69133863
MGD
24174 /* Check we can apply the extension to this architecture. */
24175 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
24176 {
24177 as_bad (_("extension does not apply to the base architecture"));
24178 return FALSE;
24179 }
24180
24181 /* Add or remove the extension. */
24182 if (adding_value)
24183 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
24184 else
24185 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
24186
c19d1205
ZW
24187 break;
24188 }
7ed4c4c5 24189
c19d1205
ZW
24190 if (opt->name == NULL)
24191 {
69133863
MGD
24192 /* Did we fail to find an extension because it wasn't specified in
24193 alphabetical order, or because it does not exist? */
24194
24195 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 24196 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
24197 break;
24198
24199 if (opt->name == NULL)
24200 as_bad (_("unknown architectural extension `%s'"), str);
24201 else
24202 as_bad (_("architectural extensions must be specified in "
24203 "alphabetical order"));
24204
c921be7d 24205 return FALSE;
c19d1205 24206 }
69133863
MGD
24207 else
24208 {
24209 /* We should skip the extension we've just matched the next time
24210 round. */
24211 opt++;
24212 }
7ed4c4c5 24213
c19d1205
ZW
24214 str = ext;
24215 };
7ed4c4c5 24216
c921be7d 24217 return TRUE;
c19d1205 24218}
7ed4c4c5 24219
c921be7d 24220static bfd_boolean
f3bad469 24221arm_parse_cpu (char *str)
7ed4c4c5 24222{
f3bad469
MGD
24223 const struct arm_cpu_option_table *opt;
24224 char *ext = strchr (str, '+');
24225 size_t len;
7ed4c4c5 24226
c19d1205 24227 if (ext != NULL)
f3bad469 24228 len = ext - str;
7ed4c4c5 24229 else
f3bad469 24230 len = strlen (str);
7ed4c4c5 24231
f3bad469 24232 if (len == 0)
7ed4c4c5 24233 {
c19d1205 24234 as_bad (_("missing cpu name `%s'"), str);
c921be7d 24235 return FALSE;
7ed4c4c5
NC
24236 }
24237
c19d1205 24238 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 24239 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 24240 {
e74cfd16
PB
24241 mcpu_cpu_opt = &opt->value;
24242 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 24243 if (opt->canonical_name)
5f4273c7 24244 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
24245 else
24246 {
f3bad469 24247 size_t i;
c921be7d 24248
f3bad469 24249 for (i = 0; i < len; i++)
ee065d83
PB
24250 selected_cpu_name[i] = TOUPPER (opt->name[i]);
24251 selected_cpu_name[i] = 0;
24252 }
7ed4c4c5 24253
c19d1205
ZW
24254 if (ext != NULL)
24255 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 24256
c921be7d 24257 return TRUE;
c19d1205 24258 }
7ed4c4c5 24259
c19d1205 24260 as_bad (_("unknown cpu `%s'"), str);
c921be7d 24261 return FALSE;
7ed4c4c5
NC
24262}
24263
c921be7d 24264static bfd_boolean
f3bad469 24265arm_parse_arch (char *str)
7ed4c4c5 24266{
e74cfd16 24267 const struct arm_arch_option_table *opt;
c19d1205 24268 char *ext = strchr (str, '+');
f3bad469 24269 size_t len;
7ed4c4c5 24270
c19d1205 24271 if (ext != NULL)
f3bad469 24272 len = ext - str;
7ed4c4c5 24273 else
f3bad469 24274 len = strlen (str);
7ed4c4c5 24275
f3bad469 24276 if (len == 0)
7ed4c4c5 24277 {
c19d1205 24278 as_bad (_("missing architecture name `%s'"), str);
c921be7d 24279 return FALSE;
7ed4c4c5
NC
24280 }
24281
c19d1205 24282 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 24283 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 24284 {
e74cfd16
PB
24285 march_cpu_opt = &opt->value;
24286 march_fpu_opt = &opt->default_fpu;
5f4273c7 24287 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 24288
c19d1205
ZW
24289 if (ext != NULL)
24290 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 24291
c921be7d 24292 return TRUE;
c19d1205
ZW
24293 }
24294
24295 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 24296 return FALSE;
7ed4c4c5 24297}
eb043451 24298
c921be7d 24299static bfd_boolean
c19d1205
ZW
24300arm_parse_fpu (char * str)
24301{
69133863 24302 const struct arm_option_fpu_value_table * opt;
b99bd4ef 24303
c19d1205
ZW
24304 for (opt = arm_fpus; opt->name != NULL; opt++)
24305 if (streq (opt->name, str))
24306 {
e74cfd16 24307 mfpu_opt = &opt->value;
c921be7d 24308 return TRUE;
c19d1205 24309 }
b99bd4ef 24310
c19d1205 24311 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 24312 return FALSE;
c19d1205
ZW
24313}
24314
c921be7d 24315static bfd_boolean
c19d1205 24316arm_parse_float_abi (char * str)
b99bd4ef 24317{
e74cfd16 24318 const struct arm_option_value_table * opt;
b99bd4ef 24319
c19d1205
ZW
24320 for (opt = arm_float_abis; opt->name != NULL; opt++)
24321 if (streq (opt->name, str))
24322 {
24323 mfloat_abi_opt = opt->value;
c921be7d 24324 return TRUE;
c19d1205 24325 }
cc8a6dd0 24326
c19d1205 24327 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 24328 return FALSE;
c19d1205 24329}
b99bd4ef 24330
c19d1205 24331#ifdef OBJ_ELF
c921be7d 24332static bfd_boolean
c19d1205
ZW
24333arm_parse_eabi (char * str)
24334{
e74cfd16 24335 const struct arm_option_value_table *opt;
cc8a6dd0 24336
c19d1205
ZW
24337 for (opt = arm_eabis; opt->name != NULL; opt++)
24338 if (streq (opt->name, str))
24339 {
24340 meabi_flags = opt->value;
c921be7d 24341 return TRUE;
c19d1205
ZW
24342 }
24343 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 24344 return FALSE;
c19d1205
ZW
24345}
24346#endif
cc8a6dd0 24347
c921be7d 24348static bfd_boolean
e07e6e58
NC
24349arm_parse_it_mode (char * str)
24350{
c921be7d 24351 bfd_boolean ret = TRUE;
e07e6e58
NC
24352
24353 if (streq ("arm", str))
24354 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
24355 else if (streq ("thumb", str))
24356 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
24357 else if (streq ("always", str))
24358 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
24359 else if (streq ("never", str))
24360 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
24361 else
24362 {
24363 as_bad (_("unknown implicit IT mode `%s', should be "\
24364 "arm, thumb, always, or never."), str);
c921be7d 24365 ret = FALSE;
e07e6e58
NC
24366 }
24367
24368 return ret;
24369}
24370
c19d1205
ZW
24371struct arm_long_option_table arm_long_opts[] =
24372{
24373 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
24374 arm_parse_cpu, NULL},
24375 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
24376 arm_parse_arch, NULL},
24377 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
24378 arm_parse_fpu, NULL},
24379 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
24380 arm_parse_float_abi, NULL},
24381#ifdef OBJ_ELF
7fac0536 24382 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
24383 arm_parse_eabi, NULL},
24384#endif
e07e6e58
NC
24385 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
24386 arm_parse_it_mode, NULL},
c19d1205
ZW
24387 {NULL, NULL, 0, NULL}
24388};
cc8a6dd0 24389
c19d1205
ZW
24390int
24391md_parse_option (int c, char * arg)
24392{
24393 struct arm_option_table *opt;
e74cfd16 24394 const struct arm_legacy_option_table *fopt;
c19d1205 24395 struct arm_long_option_table *lopt;
b99bd4ef 24396
c19d1205 24397 switch (c)
b99bd4ef 24398 {
c19d1205
ZW
24399#ifdef OPTION_EB
24400 case OPTION_EB:
24401 target_big_endian = 1;
24402 break;
24403#endif
cc8a6dd0 24404
c19d1205
ZW
24405#ifdef OPTION_EL
24406 case OPTION_EL:
24407 target_big_endian = 0;
24408 break;
24409#endif
b99bd4ef 24410
845b51d6
PB
24411 case OPTION_FIX_V4BX:
24412 fix_v4bx = TRUE;
24413 break;
24414
c19d1205
ZW
24415 case 'a':
24416 /* Listing option. Just ignore these, we don't support additional
24417 ones. */
24418 return 0;
b99bd4ef 24419
c19d1205
ZW
24420 default:
24421 for (opt = arm_opts; opt->option != NULL; opt++)
24422 {
24423 if (c == opt->option[0]
24424 && ((arg == NULL && opt->option[1] == 0)
24425 || streq (arg, opt->option + 1)))
24426 {
c19d1205 24427 /* If the option is deprecated, tell the user. */
278df34e 24428 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
24429 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
24430 arg ? arg : "", _(opt->deprecated));
b99bd4ef 24431
c19d1205
ZW
24432 if (opt->var != NULL)
24433 *opt->var = opt->value;
cc8a6dd0 24434
c19d1205
ZW
24435 return 1;
24436 }
24437 }
b99bd4ef 24438
e74cfd16
PB
24439 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
24440 {
24441 if (c == fopt->option[0]
24442 && ((arg == NULL && fopt->option[1] == 0)
24443 || streq (arg, fopt->option + 1)))
24444 {
e74cfd16 24445 /* If the option is deprecated, tell the user. */
278df34e 24446 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
24447 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
24448 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
24449
24450 if (fopt->var != NULL)
24451 *fopt->var = &fopt->value;
24452
24453 return 1;
24454 }
24455 }
24456
c19d1205
ZW
24457 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
24458 {
24459 /* These options are expected to have an argument. */
24460 if (c == lopt->option[0]
24461 && arg != NULL
24462 && strncmp (arg, lopt->option + 1,
24463 strlen (lopt->option + 1)) == 0)
24464 {
c19d1205 24465 /* If the option is deprecated, tell the user. */
278df34e 24466 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
24467 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
24468 _(lopt->deprecated));
b99bd4ef 24469
c19d1205
ZW
24470 /* Call the sup-option parser. */
24471 return lopt->func (arg + strlen (lopt->option) - 1);
24472 }
24473 }
a737bd4d 24474
c19d1205
ZW
24475 return 0;
24476 }
a394c00f 24477
c19d1205
ZW
24478 return 1;
24479}
a394c00f 24480
c19d1205
ZW
24481void
24482md_show_usage (FILE * fp)
a394c00f 24483{
c19d1205
ZW
24484 struct arm_option_table *opt;
24485 struct arm_long_option_table *lopt;
a394c00f 24486
c19d1205 24487 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 24488
c19d1205
ZW
24489 for (opt = arm_opts; opt->option != NULL; opt++)
24490 if (opt->help != NULL)
24491 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 24492
c19d1205
ZW
24493 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
24494 if (lopt->help != NULL)
24495 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 24496
c19d1205
ZW
24497#ifdef OPTION_EB
24498 fprintf (fp, _("\
24499 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
24500#endif
24501
c19d1205
ZW
24502#ifdef OPTION_EL
24503 fprintf (fp, _("\
24504 -EL assemble code for a little-endian cpu\n"));
a737bd4d 24505#endif
845b51d6
PB
24506
24507 fprintf (fp, _("\
24508 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 24509}
ee065d83
PB
24510
24511
24512#ifdef OBJ_ELF
62b3e311
PB
24513typedef struct
24514{
24515 int val;
24516 arm_feature_set flags;
24517} cpu_arch_ver_table;
24518
24519/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
24520 least features first. */
24521static const cpu_arch_ver_table cpu_arch_ver[] =
24522{
24523 {1, ARM_ARCH_V4},
24524 {2, ARM_ARCH_V4T},
24525 {3, ARM_ARCH_V5},
ee3c0378 24526 {3, ARM_ARCH_V5T},
62b3e311
PB
24527 {4, ARM_ARCH_V5TE},
24528 {5, ARM_ARCH_V5TEJ},
24529 {6, ARM_ARCH_V6},
7e806470 24530 {9, ARM_ARCH_V6K},
f4c65163 24531 {7, ARM_ARCH_V6Z},
91e22acd 24532 {11, ARM_ARCH_V6M},
b2a5fbdc 24533 {12, ARM_ARCH_V6SM},
7e806470 24534 {8, ARM_ARCH_V6T2},
bca38921 24535 {10, ARM_ARCH_V7A_IDIV_MP_SEC_VIRT},
62b3e311
PB
24536 {10, ARM_ARCH_V7R},
24537 {10, ARM_ARCH_V7M},
bca38921 24538 {14, ARM_ARCH_V8A},
62b3e311
PB
24539 {0, ARM_ARCH_NONE}
24540};
24541
ee3c0378
AS
24542/* Set an attribute if it has not already been set by the user. */
24543static void
24544aeabi_set_attribute_int (int tag, int value)
24545{
24546 if (tag < 1
24547 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
24548 || !attributes_set_explicitly[tag])
24549 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
24550}
24551
24552static void
24553aeabi_set_attribute_string (int tag, const char *value)
24554{
24555 if (tag < 1
24556 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
24557 || !attributes_set_explicitly[tag])
24558 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
24559}
24560
ee065d83
PB
24561/* Set the public EABI object attributes. */
24562static void
24563aeabi_set_public_attributes (void)
24564{
24565 int arch;
69239280 24566 char profile;
90ec0d68 24567 int virt_sec = 0;
bca38921 24568 int fp16_optional = 0;
e74cfd16 24569 arm_feature_set flags;
62b3e311
PB
24570 arm_feature_set tmp;
24571 const cpu_arch_ver_table *p;
ee065d83
PB
24572
24573 /* Choose the architecture based on the capabilities of the requested cpu
24574 (if any) and/or the instructions actually used. */
e74cfd16
PB
24575 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
24576 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
24577 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
24578
24579 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
24580 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
24581
24582 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
24583 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
24584
24585 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
24586 if (object_arch)
24587 {
24588 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
24589 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
24590 }
24591
251665fc
MGD
24592 /* We need to make sure that the attributes do not identify us as v6S-M
24593 when the only v6S-M feature in use is the Operating System Extensions. */
24594 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
24595 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
24596 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
24597
62b3e311
PB
24598 tmp = flags;
24599 arch = 0;
24600 for (p = cpu_arch_ver; p->val; p++)
24601 {
24602 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
24603 {
24604 arch = p->val;
24605 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
24606 }
24607 }
ee065d83 24608
9e3c6df6
PB
24609 /* The table lookup above finds the last architecture to contribute
24610 a new feature. Unfortunately, Tag13 is a subset of the union of
24611 v6T2 and v7-M, so it is never seen as contributing a new feature.
24612 We can not search for the last entry which is entirely used,
24613 because if no CPU is specified we build up only those flags
24614 actually used. Perhaps we should separate out the specified
24615 and implicit cases. Avoid taking this path for -march=all by
24616 checking for contradictory v7-A / v7-M features. */
24617 if (arch == 10
24618 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
24619 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
24620 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
24621 arch = 13;
24622
ee065d83
PB
24623 /* Tag_CPU_name. */
24624 if (selected_cpu_name[0])
24625 {
91d6fa6a 24626 char *q;
ee065d83 24627
91d6fa6a
NC
24628 q = selected_cpu_name;
24629 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
24630 {
24631 int i;
5f4273c7 24632
91d6fa6a
NC
24633 q += 4;
24634 for (i = 0; q[i]; i++)
24635 q[i] = TOUPPER (q[i]);
ee065d83 24636 }
91d6fa6a 24637 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 24638 }
62f3b8c8 24639
ee065d83 24640 /* Tag_CPU_arch. */
ee3c0378 24641 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 24642
62b3e311
PB
24643 /* Tag_CPU_arch_profile. */
24644 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
69239280 24645 profile = 'A';
62b3e311 24646 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 24647 profile = 'R';
7e806470 24648 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
24649 profile = 'M';
24650 else
24651 profile = '\0';
24652
24653 if (profile != '\0')
24654 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 24655
ee065d83 24656 /* Tag_ARM_ISA_use. */
ee3c0378
AS
24657 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
24658 || arch == 0)
24659 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 24660
ee065d83 24661 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
24662 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
24663 || arch == 0)
24664 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
24665 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 24666
ee065d83 24667 /* Tag_VFP_arch. */
bca38921
MGD
24668 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8))
24669 aeabi_set_attribute_int (Tag_VFP_arch, 7);
24670 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
24671 aeabi_set_attribute_int (Tag_VFP_arch,
24672 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
24673 ? 5 : 6);
24674 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
24675 {
24676 fp16_optional = 1;
24677 aeabi_set_attribute_int (Tag_VFP_arch, 3);
24678 }
ada65aa3 24679 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
24680 {
24681 aeabi_set_attribute_int (Tag_VFP_arch, 4);
24682 fp16_optional = 1;
24683 }
ee3c0378
AS
24684 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
24685 aeabi_set_attribute_int (Tag_VFP_arch, 2);
24686 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
24687 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
24688 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 24689
4547cb56
NC
24690 /* Tag_ABI_HardFP_use. */
24691 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
24692 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
24693 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
24694
ee065d83 24695 /* Tag_WMMX_arch. */
ee3c0378
AS
24696 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
24697 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
24698 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
24699 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 24700
ee3c0378 24701 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
bca38921
MGD
24702 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
24703 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
24704 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
24705 {
24706 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
24707 {
24708 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
24709 }
24710 else
24711 {
24712 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
24713 fp16_optional = 1;
24714 }
24715 }
fa94de6b 24716
ee3c0378 24717 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 24718 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 24719 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 24720
69239280
MGD
24721 /* Tag_DIV_use.
24722
24723 We set Tag_DIV_use to two when integer divide instructions have been used
24724 in ARM state, or when Thumb integer divide instructions have been used,
24725 but we have no architecture profile set, nor have we any ARM instructions.
24726
bca38921
MGD
24727 For ARMv8 we set the tag to 0 as integer divide is implied by the base
24728 architecture.
24729
69239280 24730 For new architectures we will have to check these tests. */
bca38921
MGD
24731 gas_assert (arch <= TAG_CPU_ARCH_V8);
24732 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8))
24733 aeabi_set_attribute_int (Tag_DIV_use, 0);
24734 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
24735 || (profile == '\0'
24736 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
24737 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 24738 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
24739
24740 /* Tag_MP_extension_use. */
24741 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
24742 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
24743
24744 /* Tag Virtualization_use. */
24745 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
24746 virt_sec |= 1;
24747 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
24748 virt_sec |= 2;
24749 if (virt_sec != 0)
24750 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
24751}
24752
104d59d1 24753/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
24754void
24755arm_md_end (void)
24756{
ee065d83
PB
24757 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
24758 return;
24759
24760 aeabi_set_public_attributes ();
ee065d83 24761}
8463be01 24762#endif /* OBJ_ELF */
ee065d83
PB
24763
24764
24765/* Parse a .cpu directive. */
24766
24767static void
24768s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
24769{
e74cfd16 24770 const struct arm_cpu_option_table *opt;
ee065d83
PB
24771 char *name;
24772 char saved_char;
24773
24774 name = input_line_pointer;
5f4273c7 24775 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
24776 input_line_pointer++;
24777 saved_char = *input_line_pointer;
24778 *input_line_pointer = 0;
24779
24780 /* Skip the first "all" entry. */
24781 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
24782 if (streq (opt->name, name))
24783 {
e74cfd16
PB
24784 mcpu_cpu_opt = &opt->value;
24785 selected_cpu = opt->value;
ee065d83 24786 if (opt->canonical_name)
5f4273c7 24787 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
24788 else
24789 {
24790 int i;
24791 for (i = 0; opt->name[i]; i++)
24792 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 24793
ee065d83
PB
24794 selected_cpu_name[i] = 0;
24795 }
e74cfd16 24796 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
24797 *input_line_pointer = saved_char;
24798 demand_empty_rest_of_line ();
24799 return;
24800 }
24801 as_bad (_("unknown cpu `%s'"), name);
24802 *input_line_pointer = saved_char;
24803 ignore_rest_of_line ();
24804}
24805
24806
24807/* Parse a .arch directive. */
24808
24809static void
24810s_arm_arch (int ignored ATTRIBUTE_UNUSED)
24811{
e74cfd16 24812 const struct arm_arch_option_table *opt;
ee065d83
PB
24813 char saved_char;
24814 char *name;
24815
24816 name = input_line_pointer;
5f4273c7 24817 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
24818 input_line_pointer++;
24819 saved_char = *input_line_pointer;
24820 *input_line_pointer = 0;
24821
24822 /* Skip the first "all" entry. */
24823 for (opt = arm_archs + 1; opt->name != NULL; opt++)
24824 if (streq (opt->name, name))
24825 {
e74cfd16
PB
24826 mcpu_cpu_opt = &opt->value;
24827 selected_cpu = opt->value;
5f4273c7 24828 strcpy (selected_cpu_name, opt->name);
e74cfd16 24829 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
24830 *input_line_pointer = saved_char;
24831 demand_empty_rest_of_line ();
24832 return;
24833 }
24834
24835 as_bad (_("unknown architecture `%s'\n"), name);
24836 *input_line_pointer = saved_char;
24837 ignore_rest_of_line ();
24838}
24839
24840
7a1d4c38
PB
24841/* Parse a .object_arch directive. */
24842
24843static void
24844s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
24845{
24846 const struct arm_arch_option_table *opt;
24847 char saved_char;
24848 char *name;
24849
24850 name = input_line_pointer;
5f4273c7 24851 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
24852 input_line_pointer++;
24853 saved_char = *input_line_pointer;
24854 *input_line_pointer = 0;
24855
24856 /* Skip the first "all" entry. */
24857 for (opt = arm_archs + 1; opt->name != NULL; opt++)
24858 if (streq (opt->name, name))
24859 {
24860 object_arch = &opt->value;
24861 *input_line_pointer = saved_char;
24862 demand_empty_rest_of_line ();
24863 return;
24864 }
24865
24866 as_bad (_("unknown architecture `%s'\n"), name);
24867 *input_line_pointer = saved_char;
24868 ignore_rest_of_line ();
24869}
24870
69133863
MGD
24871/* Parse a .arch_extension directive. */
24872
24873static void
24874s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
24875{
24876 const struct arm_option_extension_value_table *opt;
24877 char saved_char;
24878 char *name;
24879 int adding_value = 1;
24880
24881 name = input_line_pointer;
24882 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24883 input_line_pointer++;
24884 saved_char = *input_line_pointer;
24885 *input_line_pointer = 0;
24886
24887 if (strlen (name) >= 2
24888 && strncmp (name, "no", 2) == 0)
24889 {
24890 adding_value = 0;
24891 name += 2;
24892 }
24893
24894 for (opt = arm_extensions; opt->name != NULL; opt++)
24895 if (streq (opt->name, name))
24896 {
24897 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
24898 {
24899 as_bad (_("architectural extension `%s' is not allowed for the "
24900 "current base architecture"), name);
24901 break;
24902 }
24903
24904 if (adding_value)
24905 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
24906 else
24907 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
24908
24909 mcpu_cpu_opt = &selected_cpu;
24910 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24911 *input_line_pointer = saved_char;
24912 demand_empty_rest_of_line ();
24913 return;
24914 }
24915
24916 if (opt->name == NULL)
24917 as_bad (_("unknown architecture `%s'\n"), name);
24918
24919 *input_line_pointer = saved_char;
24920 ignore_rest_of_line ();
24921}
24922
ee065d83
PB
24923/* Parse a .fpu directive. */
24924
24925static void
24926s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
24927{
69133863 24928 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
24929 char saved_char;
24930 char *name;
24931
24932 name = input_line_pointer;
5f4273c7 24933 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
24934 input_line_pointer++;
24935 saved_char = *input_line_pointer;
24936 *input_line_pointer = 0;
5f4273c7 24937
ee065d83
PB
24938 for (opt = arm_fpus; opt->name != NULL; opt++)
24939 if (streq (opt->name, name))
24940 {
e74cfd16
PB
24941 mfpu_opt = &opt->value;
24942 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
24943 *input_line_pointer = saved_char;
24944 demand_empty_rest_of_line ();
24945 return;
24946 }
24947
24948 as_bad (_("unknown floating point format `%s'\n"), name);
24949 *input_line_pointer = saved_char;
24950 ignore_rest_of_line ();
24951}
ee065d83 24952
794ba86a 24953/* Copy symbol information. */
f31fef98 24954
794ba86a
DJ
24955void
24956arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
24957{
24958 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
24959}
e04befd0 24960
f31fef98 24961#ifdef OBJ_ELF
e04befd0
AS
24962/* Given a symbolic attribute NAME, return the proper integer value.
24963 Returns -1 if the attribute is not known. */
f31fef98 24964
e04befd0
AS
24965int
24966arm_convert_symbolic_attribute (const char *name)
24967{
f31fef98
NC
24968 static const struct
24969 {
24970 const char * name;
24971 const int tag;
24972 }
24973 attribute_table[] =
24974 {
24975 /* When you modify this table you should
24976 also modify the list in doc/c-arm.texi. */
e04befd0 24977#define T(tag) {#tag, tag}
f31fef98
NC
24978 T (Tag_CPU_raw_name),
24979 T (Tag_CPU_name),
24980 T (Tag_CPU_arch),
24981 T (Tag_CPU_arch_profile),
24982 T (Tag_ARM_ISA_use),
24983 T (Tag_THUMB_ISA_use),
75375b3e 24984 T (Tag_FP_arch),
f31fef98
NC
24985 T (Tag_VFP_arch),
24986 T (Tag_WMMX_arch),
24987 T (Tag_Advanced_SIMD_arch),
24988 T (Tag_PCS_config),
24989 T (Tag_ABI_PCS_R9_use),
24990 T (Tag_ABI_PCS_RW_data),
24991 T (Tag_ABI_PCS_RO_data),
24992 T (Tag_ABI_PCS_GOT_use),
24993 T (Tag_ABI_PCS_wchar_t),
24994 T (Tag_ABI_FP_rounding),
24995 T (Tag_ABI_FP_denormal),
24996 T (Tag_ABI_FP_exceptions),
24997 T (Tag_ABI_FP_user_exceptions),
24998 T (Tag_ABI_FP_number_model),
75375b3e 24999 T (Tag_ABI_align_needed),
f31fef98 25000 T (Tag_ABI_align8_needed),
75375b3e 25001 T (Tag_ABI_align_preserved),
f31fef98
NC
25002 T (Tag_ABI_align8_preserved),
25003 T (Tag_ABI_enum_size),
25004 T (Tag_ABI_HardFP_use),
25005 T (Tag_ABI_VFP_args),
25006 T (Tag_ABI_WMMX_args),
25007 T (Tag_ABI_optimization_goals),
25008 T (Tag_ABI_FP_optimization_goals),
25009 T (Tag_compatibility),
25010 T (Tag_CPU_unaligned_access),
75375b3e 25011 T (Tag_FP_HP_extension),
f31fef98
NC
25012 T (Tag_VFP_HP_extension),
25013 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
25014 T (Tag_MPextension_use),
25015 T (Tag_DIV_use),
f31fef98
NC
25016 T (Tag_nodefaults),
25017 T (Tag_also_compatible_with),
25018 T (Tag_conformance),
25019 T (Tag_T2EE_use),
25020 T (Tag_Virtualization_use),
cd21e546 25021 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 25022#undef T
f31fef98 25023 };
e04befd0
AS
25024 unsigned int i;
25025
25026 if (name == NULL)
25027 return -1;
25028
f31fef98 25029 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 25030 if (streq (name, attribute_table[i].name))
e04befd0
AS
25031 return attribute_table[i].tag;
25032
25033 return -1;
25034}
267bf995
RR
25035
25036
25037/* Apply sym value for relocations only in the case that
25038 they are for local symbols and you have the respective
25039 architectural feature for blx and simple switches. */
25040int
25041arm_apply_sym_value (struct fix * fixP)
25042{
25043 if (fixP->fx_addsy
25044 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
34e77a92 25045 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
25046 {
25047 switch (fixP->fx_r_type)
25048 {
25049 case BFD_RELOC_ARM_PCREL_BLX:
25050 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25051 if (ARM_IS_FUNC (fixP->fx_addsy))
25052 return 1;
25053 break;
25054
25055 case BFD_RELOC_ARM_PCREL_CALL:
25056 case BFD_RELOC_THUMB_PCREL_BLX:
25057 if (THUMB_IS_FUNC (fixP->fx_addsy))
25058 return 1;
25059 break;
25060
25061 default:
25062 break;
25063 }
25064
25065 }
25066 return 0;
25067}
f31fef98 25068#endif /* OBJ_ELF */