]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
bfd/
[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,
b43420e6 3 2004, 2005, 2006, 2007, 2008, 2009, 2010
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"
b99bd4ef 35
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
MGD
100/* The code that was here used to select a default CPU depending on compiler
101 pre-defines which were only present when doing native builds, thus
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);
7e806470 198static const arm_feature_set arm_ext_m =
b2a5fbdc 199 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, 0);
60e5ef9f 200static const arm_feature_set arm_ext_mp = ARM_FEATURE (ARM_EXT_MP, 0);
f4c65163 201static const arm_feature_set arm_ext_sec = ARM_FEATURE (ARM_EXT_SEC, 0);
b2a5fbdc 202static const arm_feature_set arm_ext_os = ARM_FEATURE (ARM_EXT_OS, 0);
eea54501 203static const arm_feature_set arm_ext_adiv = ARM_FEATURE (ARM_EXT_ADIV, 0);
90ec0d68 204static const arm_feature_set arm_ext_virt = ARM_FEATURE (ARM_EXT_VIRT, 0);
e74cfd16
PB
205
206static const arm_feature_set arm_arch_any = ARM_ANY;
207static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
208static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
209static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
251665fc 210static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
e74cfd16 211
2d447fca
JM
212static const arm_feature_set arm_cext_iwmmxt2 =
213 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
214static const arm_feature_set arm_cext_iwmmxt =
215 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
216static const arm_feature_set arm_cext_xscale =
217 ARM_FEATURE (0, ARM_CEXT_XSCALE);
218static const arm_feature_set arm_cext_maverick =
219 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
220static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
221static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
222static const arm_feature_set fpu_vfp_ext_v1xd =
223 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
224static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
225static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
62f3b8c8 226static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
5287ad62 227static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
228static const arm_feature_set fpu_vfp_ext_d32 =
229 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
230static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
231static const arm_feature_set fpu_vfp_v3_or_neon_ext =
232 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
62f3b8c8
PB
233static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
234static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
235static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
e74cfd16 236
33a392fb 237static int mfloat_abi_opt = -1;
e74cfd16
PB
238/* Record user cpu selection for object attributes. */
239static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
240/* Must be long enough to hold any of the names in arm_cpus. */
241static char selected_cpu_name[16];
7cc69913 242#ifdef OBJ_ELF
deeaaff8
DJ
243# ifdef EABI_DEFAULT
244static int meabi_flags = EABI_DEFAULT;
245# else
d507cf36 246static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 247# endif
e1da3f5b 248
ee3c0378
AS
249static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
250
e1da3f5b 251bfd_boolean
5f4273c7 252arm_is_eabi (void)
e1da3f5b
PB
253{
254 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
255}
7cc69913 256#endif
b99bd4ef 257
b99bd4ef 258#ifdef OBJ_ELF
c19d1205 259/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
260symbolS * GOT_symbol;
261#endif
262
b99bd4ef
NC
263/* 0: assemble for ARM,
264 1: assemble for Thumb,
265 2: assemble for Thumb even though target CPU does not support thumb
266 instructions. */
267static int thumb_mode = 0;
8dc2430f
NC
268/* A value distinct from the possible values for thumb_mode that we
269 can use to record whether thumb_mode has been copied into the
270 tc_frag_data field of a frag. */
271#define MODE_RECORDED (1 << 4)
b99bd4ef 272
e07e6e58
NC
273/* Specifies the intrinsic IT insn behavior mode. */
274enum implicit_it_mode
275{
276 IMPLICIT_IT_MODE_NEVER = 0x00,
277 IMPLICIT_IT_MODE_ARM = 0x01,
278 IMPLICIT_IT_MODE_THUMB = 0x02,
279 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
280};
281static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
282
c19d1205
ZW
283/* If unified_syntax is true, we are processing the new unified
284 ARM/Thumb syntax. Important differences from the old ARM mode:
285
286 - Immediate operands do not require a # prefix.
287 - Conditional affixes always appear at the end of the
288 instruction. (For backward compatibility, those instructions
289 that formerly had them in the middle, continue to accept them
290 there.)
291 - The IT instruction may appear, and if it does is validated
292 against subsequent conditional affixes. It does not generate
293 machine code.
294
295 Important differences from the old Thumb mode:
296
297 - Immediate operands do not require a # prefix.
298 - Most of the V6T2 instructions are only available in unified mode.
299 - The .N and .W suffixes are recognized and honored (it is an error
300 if they cannot be honored).
301 - All instructions set the flags if and only if they have an 's' affix.
302 - Conditional affixes may be used. They are validated against
303 preceding IT instructions. Unlike ARM mode, you cannot use a
304 conditional affix except in the scope of an IT instruction. */
305
306static bfd_boolean unified_syntax = FALSE;
b99bd4ef 307
5287ad62
JB
308enum neon_el_type
309{
dcbf9037 310 NT_invtype,
5287ad62
JB
311 NT_untyped,
312 NT_integer,
313 NT_float,
314 NT_poly,
315 NT_signed,
dcbf9037 316 NT_unsigned
5287ad62
JB
317};
318
319struct neon_type_el
320{
321 enum neon_el_type type;
322 unsigned size;
323};
324
325#define NEON_MAX_TYPE_ELS 4
326
327struct neon_type
328{
329 struct neon_type_el el[NEON_MAX_TYPE_ELS];
330 unsigned elems;
331};
332
e07e6e58
NC
333enum it_instruction_type
334{
335 OUTSIDE_IT_INSN,
336 INSIDE_IT_INSN,
337 INSIDE_IT_LAST_INSN,
338 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
339 if inside, should be the last one. */
340 NEUTRAL_IT_INSN, /* This could be either inside or outside,
341 i.e. BKPT and NOP. */
342 IT_INSN /* The IT insn has been parsed. */
343};
344
b99bd4ef
NC
345struct arm_it
346{
c19d1205 347 const char * error;
b99bd4ef 348 unsigned long instruction;
c19d1205
ZW
349 int size;
350 int size_req;
351 int cond;
037e8744
JB
352 /* "uncond_value" is set to the value in place of the conditional field in
353 unconditional versions of the instruction, or -1 if nothing is
354 appropriate. */
355 int uncond_value;
5287ad62 356 struct neon_type vectype;
88714cb8
DG
357 /* This does not indicate an actual NEON instruction, only that
358 the mnemonic accepts neon-style type suffixes. */
359 int is_neon;
0110f2b8
PB
360 /* Set to the opcode if the instruction needs relaxation.
361 Zero if the instruction is not relaxed. */
362 unsigned long relax;
b99bd4ef
NC
363 struct
364 {
365 bfd_reloc_code_real_type type;
c19d1205
ZW
366 expressionS exp;
367 int pc_rel;
b99bd4ef 368 } reloc;
b99bd4ef 369
e07e6e58
NC
370 enum it_instruction_type it_insn_type;
371
c19d1205
ZW
372 struct
373 {
374 unsigned reg;
ca3f61f7 375 signed int imm;
dcbf9037 376 struct neon_type_el vectype;
ca3f61f7
NC
377 unsigned present : 1; /* Operand present. */
378 unsigned isreg : 1; /* Operand was a register. */
379 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
380 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
381 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 382 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
383 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
384 instructions. This allows us to disambiguate ARM <-> vector insns. */
385 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 386 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 387 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 388 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
389 unsigned hasreloc : 1; /* Operand has relocation suffix. */
390 unsigned writeback : 1; /* Operand has trailing ! */
391 unsigned preind : 1; /* Preindexed address. */
392 unsigned postind : 1; /* Postindexed address. */
393 unsigned negative : 1; /* Index register was negated. */
394 unsigned shifted : 1; /* Shift applied to operation. */
395 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 396 } operands[6];
b99bd4ef
NC
397};
398
c19d1205 399static struct arm_it inst;
b99bd4ef
NC
400
401#define NUM_FLOAT_VALS 8
402
05d2d07e 403const char * fp_const[] =
b99bd4ef
NC
404{
405 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
406};
407
c19d1205 408/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
409#define MAX_LITTLENUMS 6
410
411LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
412
413#define FAIL (-1)
414#define SUCCESS (0)
415
416#define SUFF_S 1
417#define SUFF_D 2
418#define SUFF_E 3
419#define SUFF_P 4
420
c19d1205
ZW
421#define CP_T_X 0x00008000
422#define CP_T_Y 0x00400000
b99bd4ef 423
c19d1205
ZW
424#define CONDS_BIT 0x00100000
425#define LOAD_BIT 0x00100000
b99bd4ef
NC
426
427#define DOUBLE_LOAD_FLAG 0x00000001
428
429struct asm_cond
430{
d3ce72d0 431 const char * template_name;
c921be7d 432 unsigned long value;
b99bd4ef
NC
433};
434
c19d1205 435#define COND_ALWAYS 0xE
b99bd4ef 436
b99bd4ef
NC
437struct asm_psr
438{
d3ce72d0 439 const char * template_name;
c921be7d 440 unsigned long field;
b99bd4ef
NC
441};
442
62b3e311
PB
443struct asm_barrier_opt
444{
d3ce72d0 445 const char * template_name;
c921be7d 446 unsigned long value;
62b3e311
PB
447};
448
2d2255b5 449/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
450#define SPSR_BIT (1 << 22)
451
c19d1205
ZW
452/* The individual PSR flag bits. */
453#define PSR_c (1 << 16)
454#define PSR_x (1 << 17)
455#define PSR_s (1 << 18)
456#define PSR_f (1 << 19)
b99bd4ef 457
c19d1205 458struct reloc_entry
bfae80f2 459{
c921be7d
NC
460 char * name;
461 bfd_reloc_code_real_type reloc;
bfae80f2
RE
462};
463
5287ad62 464enum vfp_reg_pos
bfae80f2 465{
5287ad62
JB
466 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
467 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
468};
469
470enum vfp_ldstm_type
471{
472 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
473};
474
dcbf9037
JB
475/* Bits for DEFINED field in neon_typed_alias. */
476#define NTA_HASTYPE 1
477#define NTA_HASINDEX 2
478
479struct neon_typed_alias
480{
c921be7d
NC
481 unsigned char defined;
482 unsigned char index;
483 struct neon_type_el eltype;
dcbf9037
JB
484};
485
c19d1205
ZW
486/* ARM register categories. This includes coprocessor numbers and various
487 architecture extensions' registers. */
488enum arm_reg_type
bfae80f2 489{
c19d1205
ZW
490 REG_TYPE_RN,
491 REG_TYPE_CP,
492 REG_TYPE_CN,
493 REG_TYPE_FN,
494 REG_TYPE_VFS,
495 REG_TYPE_VFD,
5287ad62 496 REG_TYPE_NQ,
037e8744 497 REG_TYPE_VFSD,
5287ad62 498 REG_TYPE_NDQ,
037e8744 499 REG_TYPE_NSDQ,
c19d1205
ZW
500 REG_TYPE_VFC,
501 REG_TYPE_MVF,
502 REG_TYPE_MVD,
503 REG_TYPE_MVFX,
504 REG_TYPE_MVDX,
505 REG_TYPE_MVAX,
506 REG_TYPE_DSPSC,
507 REG_TYPE_MMXWR,
508 REG_TYPE_MMXWC,
509 REG_TYPE_MMXWCG,
510 REG_TYPE_XSCALE,
90ec0d68 511 REG_TYPE_RNB
bfae80f2
RE
512};
513
dcbf9037
JB
514/* Structure for a hash table entry for a register.
515 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
516 information which states whether a vector type or index is specified (for a
517 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
518struct reg_entry
519{
c921be7d 520 const char * name;
90ec0d68 521 unsigned int number;
c921be7d
NC
522 unsigned char type;
523 unsigned char builtin;
524 struct neon_typed_alias * neon;
6c43fab6
RE
525};
526
c19d1205 527/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 528const char * const reg_expected_msgs[] =
c19d1205
ZW
529{
530 N_("ARM register expected"),
531 N_("bad or missing co-processor number"),
532 N_("co-processor register expected"),
533 N_("FPA register expected"),
534 N_("VFP single precision register expected"),
5287ad62
JB
535 N_("VFP/Neon double precision register expected"),
536 N_("Neon quad precision register expected"),
037e8744 537 N_("VFP single or double precision register expected"),
5287ad62 538 N_("Neon double or quad precision register expected"),
037e8744 539 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
540 N_("VFP system register expected"),
541 N_("Maverick MVF register expected"),
542 N_("Maverick MVD register expected"),
543 N_("Maverick MVFX register expected"),
544 N_("Maverick MVDX register expected"),
545 N_("Maverick MVAX register expected"),
546 N_("Maverick DSPSC register expected"),
547 N_("iWMMXt data register expected"),
548 N_("iWMMXt control register expected"),
549 N_("iWMMXt scalar register expected"),
550 N_("XScale accumulator register expected"),
6c43fab6
RE
551};
552
c19d1205
ZW
553/* Some well known registers that we refer to directly elsewhere. */
554#define REG_SP 13
555#define REG_LR 14
556#define REG_PC 15
404ff6b5 557
b99bd4ef
NC
558/* ARM instructions take 4bytes in the object file, Thumb instructions
559 take 2: */
c19d1205 560#define INSN_SIZE 4
b99bd4ef
NC
561
562struct asm_opcode
563{
564 /* Basic string to match. */
d3ce72d0 565 const char * template_name;
c19d1205
ZW
566
567 /* Parameters to instruction. */
5be8be5d 568 unsigned int operands[8];
c19d1205
ZW
569
570 /* Conditional tag - see opcode_lookup. */
571 unsigned int tag : 4;
b99bd4ef
NC
572
573 /* Basic instruction code. */
c19d1205 574 unsigned int avalue : 28;
b99bd4ef 575
c19d1205
ZW
576 /* Thumb-format instruction code. */
577 unsigned int tvalue;
b99bd4ef 578
90e4755a 579 /* Which architecture variant provides this instruction. */
c921be7d
NC
580 const arm_feature_set * avariant;
581 const arm_feature_set * tvariant;
c19d1205
ZW
582
583 /* Function to call to encode instruction in ARM format. */
584 void (* aencode) (void);
b99bd4ef 585
c19d1205
ZW
586 /* Function to call to encode instruction in Thumb format. */
587 void (* tencode) (void);
b99bd4ef
NC
588};
589
a737bd4d
NC
590/* Defines for various bits that we will want to toggle. */
591#define INST_IMMEDIATE 0x02000000
592#define OFFSET_REG 0x02000000
c19d1205 593#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
594#define SHIFT_BY_REG 0x00000010
595#define PRE_INDEX 0x01000000
596#define INDEX_UP 0x00800000
597#define WRITE_BACK 0x00200000
598#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 599#define CPSI_MMOD 0x00020000
90e4755a 600
a737bd4d
NC
601#define LITERAL_MASK 0xf000f000
602#define OPCODE_MASK 0xfe1fffff
603#define V4_STR_BIT 0x00000020
90e4755a 604
efd81785
PB
605#define T2_SUBS_PC_LR 0xf3de8f00
606
a737bd4d 607#define DATA_OP_SHIFT 21
90e4755a 608
ef8d22e6
PB
609#define T2_OPCODE_MASK 0xfe1fffff
610#define T2_DATA_OP_SHIFT 21
611
a737bd4d
NC
612/* Codes to distinguish the arithmetic instructions. */
613#define OPCODE_AND 0
614#define OPCODE_EOR 1
615#define OPCODE_SUB 2
616#define OPCODE_RSB 3
617#define OPCODE_ADD 4
618#define OPCODE_ADC 5
619#define OPCODE_SBC 6
620#define OPCODE_RSC 7
621#define OPCODE_TST 8
622#define OPCODE_TEQ 9
623#define OPCODE_CMP 10
624#define OPCODE_CMN 11
625#define OPCODE_ORR 12
626#define OPCODE_MOV 13
627#define OPCODE_BIC 14
628#define OPCODE_MVN 15
90e4755a 629
ef8d22e6
PB
630#define T2_OPCODE_AND 0
631#define T2_OPCODE_BIC 1
632#define T2_OPCODE_ORR 2
633#define T2_OPCODE_ORN 3
634#define T2_OPCODE_EOR 4
635#define T2_OPCODE_ADD 8
636#define T2_OPCODE_ADC 10
637#define T2_OPCODE_SBC 11
638#define T2_OPCODE_SUB 13
639#define T2_OPCODE_RSB 14
640
a737bd4d
NC
641#define T_OPCODE_MUL 0x4340
642#define T_OPCODE_TST 0x4200
643#define T_OPCODE_CMN 0x42c0
644#define T_OPCODE_NEG 0x4240
645#define T_OPCODE_MVN 0x43c0
90e4755a 646
a737bd4d
NC
647#define T_OPCODE_ADD_R3 0x1800
648#define T_OPCODE_SUB_R3 0x1a00
649#define T_OPCODE_ADD_HI 0x4400
650#define T_OPCODE_ADD_ST 0xb000
651#define T_OPCODE_SUB_ST 0xb080
652#define T_OPCODE_ADD_SP 0xa800
653#define T_OPCODE_ADD_PC 0xa000
654#define T_OPCODE_ADD_I8 0x3000
655#define T_OPCODE_SUB_I8 0x3800
656#define T_OPCODE_ADD_I3 0x1c00
657#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 658
a737bd4d
NC
659#define T_OPCODE_ASR_R 0x4100
660#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
661#define T_OPCODE_LSR_R 0x40c0
662#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
663#define T_OPCODE_ASR_I 0x1000
664#define T_OPCODE_LSL_I 0x0000
665#define T_OPCODE_LSR_I 0x0800
b99bd4ef 666
a737bd4d
NC
667#define T_OPCODE_MOV_I8 0x2000
668#define T_OPCODE_CMP_I8 0x2800
669#define T_OPCODE_CMP_LR 0x4280
670#define T_OPCODE_MOV_HR 0x4600
671#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 672
a737bd4d
NC
673#define T_OPCODE_LDR_PC 0x4800
674#define T_OPCODE_LDR_SP 0x9800
675#define T_OPCODE_STR_SP 0x9000
676#define T_OPCODE_LDR_IW 0x6800
677#define T_OPCODE_STR_IW 0x6000
678#define T_OPCODE_LDR_IH 0x8800
679#define T_OPCODE_STR_IH 0x8000
680#define T_OPCODE_LDR_IB 0x7800
681#define T_OPCODE_STR_IB 0x7000
682#define T_OPCODE_LDR_RW 0x5800
683#define T_OPCODE_STR_RW 0x5000
684#define T_OPCODE_LDR_RH 0x5a00
685#define T_OPCODE_STR_RH 0x5200
686#define T_OPCODE_LDR_RB 0x5c00
687#define T_OPCODE_STR_RB 0x5400
c9b604bd 688
a737bd4d
NC
689#define T_OPCODE_PUSH 0xb400
690#define T_OPCODE_POP 0xbc00
b99bd4ef 691
2fc8bdac 692#define T_OPCODE_BRANCH 0xe000
b99bd4ef 693
a737bd4d 694#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 695#define THUMB_PP_PC_LR 0x0100
c19d1205 696#define THUMB_LOAD_BIT 0x0800
53365c0d 697#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
698
699#define BAD_ARGS _("bad arguments to instruction")
fdfde340 700#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
701#define BAD_PC _("r15 not allowed here")
702#define BAD_COND _("instruction cannot be conditional")
703#define BAD_OVERLAP _("registers may not be the same")
704#define BAD_HIREG _("lo register required")
705#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 706#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
707#define BAD_BRANCH _("branch must be last instruction in IT block")
708#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 709#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
710#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
711#define BAD_IT_COND _("incorrect condition in IT block")
712#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 713#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
714#define BAD_PC_ADDRESSING \
715 _("cannot use register index with PC-relative addressing")
716#define BAD_PC_WRITEBACK \
717 _("cannot use writeback with PC-relative addressing")
c19d1205 718
c921be7d
NC
719static struct hash_control * arm_ops_hsh;
720static struct hash_control * arm_cond_hsh;
721static struct hash_control * arm_shift_hsh;
722static struct hash_control * arm_psr_hsh;
723static struct hash_control * arm_v7m_psr_hsh;
724static struct hash_control * arm_reg_hsh;
725static struct hash_control * arm_reloc_hsh;
726static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 727
b99bd4ef
NC
728/* Stuff needed to resolve the label ambiguity
729 As:
730 ...
731 label: <insn>
732 may differ from:
733 ...
734 label:
5f4273c7 735 <insn> */
b99bd4ef
NC
736
737symbolS * last_label_seen;
b34976b6 738static int label_is_thumb_function_name = FALSE;
e07e6e58 739
3d0c9500
NC
740/* Literal pool structure. Held on a per-section
741 and per-sub-section basis. */
a737bd4d 742
c19d1205 743#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 744typedef struct literal_pool
b99bd4ef 745{
c921be7d
NC
746 expressionS literals [MAX_LITERAL_POOL_SIZE];
747 unsigned int next_free_entry;
748 unsigned int id;
749 symbolS * symbol;
750 segT section;
751 subsegT sub_section;
752 struct literal_pool * next;
3d0c9500 753} literal_pool;
b99bd4ef 754
3d0c9500
NC
755/* Pointer to a linked list of literal pools. */
756literal_pool * list_of_pools = NULL;
e27ec89e 757
e07e6e58
NC
758#ifdef OBJ_ELF
759# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
760#else
761static struct current_it now_it;
762#endif
763
764static inline int
765now_it_compatible (int cond)
766{
767 return (cond & ~1) == (now_it.cc & ~1);
768}
769
770static inline int
771conditional_insn (void)
772{
773 return inst.cond != COND_ALWAYS;
774}
775
776static int in_it_block (void);
777
778static int handle_it_state (void);
779
780static void force_automatic_it_block_close (void);
781
c921be7d
NC
782static void it_fsm_post_encode (void);
783
e07e6e58
NC
784#define set_it_insn_type(type) \
785 do \
786 { \
787 inst.it_insn_type = type; \
788 if (handle_it_state () == FAIL) \
789 return; \
790 } \
791 while (0)
792
c921be7d
NC
793#define set_it_insn_type_nonvoid(type, failret) \
794 do \
795 { \
796 inst.it_insn_type = type; \
797 if (handle_it_state () == FAIL) \
798 return failret; \
799 } \
800 while(0)
801
e07e6e58
NC
802#define set_it_insn_type_last() \
803 do \
804 { \
805 if (inst.cond == COND_ALWAYS) \
806 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
807 else \
808 set_it_insn_type (INSIDE_IT_LAST_INSN); \
809 } \
810 while (0)
811
c19d1205 812/* Pure syntax. */
b99bd4ef 813
c19d1205
ZW
814/* This array holds the chars that always start a comment. If the
815 pre-processor is disabled, these aren't very useful. */
816const char comment_chars[] = "@";
3d0c9500 817
c19d1205
ZW
818/* This array holds the chars that only start a comment at the beginning of
819 a line. If the line seems to have the form '# 123 filename'
820 .line and .file directives will appear in the pre-processed output. */
821/* Note that input_file.c hand checks for '#' at the beginning of the
822 first line of the input file. This is because the compiler outputs
823 #NO_APP at the beginning of its output. */
824/* Also note that comments like this one will always work. */
825const char line_comment_chars[] = "#";
3d0c9500 826
c19d1205 827const char line_separator_chars[] = ";";
b99bd4ef 828
c19d1205
ZW
829/* Chars that can be used to separate mant
830 from exp in floating point numbers. */
831const char EXP_CHARS[] = "eE";
3d0c9500 832
c19d1205
ZW
833/* Chars that mean this number is a floating point constant. */
834/* As in 0f12.456 */
835/* or 0d1.2345e12 */
b99bd4ef 836
c19d1205 837const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 838
c19d1205
ZW
839/* Prefix characters that indicate the start of an immediate
840 value. */
841#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 842
c19d1205
ZW
843/* Separator character handling. */
844
845#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
846
847static inline int
848skip_past_char (char ** str, char c)
849{
850 if (**str == c)
851 {
852 (*str)++;
853 return SUCCESS;
3d0c9500 854 }
c19d1205
ZW
855 else
856 return FAIL;
857}
c921be7d 858
c19d1205 859#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 860
c19d1205
ZW
861/* Arithmetic expressions (possibly involving symbols). */
862
863/* Return TRUE if anything in the expression is a bignum. */
864
865static int
866walk_no_bignums (symbolS * sp)
867{
868 if (symbol_get_value_expression (sp)->X_op == O_big)
869 return 1;
870
871 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 872 {
c19d1205
ZW
873 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
874 || (symbol_get_value_expression (sp)->X_op_symbol
875 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
876 }
877
c19d1205 878 return 0;
3d0c9500
NC
879}
880
c19d1205
ZW
881static int in_my_get_expression = 0;
882
883/* Third argument to my_get_expression. */
884#define GE_NO_PREFIX 0
885#define GE_IMM_PREFIX 1
886#define GE_OPT_PREFIX 2
5287ad62
JB
887/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
888 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
889#define GE_OPT_PREFIX_BIG 3
a737bd4d 890
b99bd4ef 891static int
c19d1205 892my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 893{
c19d1205
ZW
894 char * save_in;
895 segT seg;
b99bd4ef 896
c19d1205
ZW
897 /* In unified syntax, all prefixes are optional. */
898 if (unified_syntax)
5287ad62
JB
899 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
900 : GE_OPT_PREFIX;
b99bd4ef 901
c19d1205 902 switch (prefix_mode)
b99bd4ef 903 {
c19d1205
ZW
904 case GE_NO_PREFIX: break;
905 case GE_IMM_PREFIX:
906 if (!is_immediate_prefix (**str))
907 {
908 inst.error = _("immediate expression requires a # prefix");
909 return FAIL;
910 }
911 (*str)++;
912 break;
913 case GE_OPT_PREFIX:
5287ad62 914 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
915 if (is_immediate_prefix (**str))
916 (*str)++;
917 break;
918 default: abort ();
919 }
b99bd4ef 920
c19d1205 921 memset (ep, 0, sizeof (expressionS));
b99bd4ef 922
c19d1205
ZW
923 save_in = input_line_pointer;
924 input_line_pointer = *str;
925 in_my_get_expression = 1;
926 seg = expression (ep);
927 in_my_get_expression = 0;
928
f86adc07 929 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 930 {
f86adc07 931 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
932 *str = input_line_pointer;
933 input_line_pointer = save_in;
934 if (inst.error == NULL)
f86adc07
NS
935 inst.error = (ep->X_op == O_absent
936 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
937 return 1;
938 }
b99bd4ef 939
c19d1205
ZW
940#ifdef OBJ_AOUT
941 if (seg != absolute_section
942 && seg != text_section
943 && seg != data_section
944 && seg != bss_section
945 && seg != undefined_section)
946 {
947 inst.error = _("bad segment");
948 *str = input_line_pointer;
949 input_line_pointer = save_in;
950 return 1;
b99bd4ef 951 }
87975d2a
AM
952#else
953 (void) seg;
c19d1205 954#endif
b99bd4ef 955
c19d1205
ZW
956 /* Get rid of any bignums now, so that we don't generate an error for which
957 we can't establish a line number later on. Big numbers are never valid
958 in instructions, which is where this routine is always called. */
5287ad62
JB
959 if (prefix_mode != GE_OPT_PREFIX_BIG
960 && (ep->X_op == O_big
961 || (ep->X_add_symbol
962 && (walk_no_bignums (ep->X_add_symbol)
963 || (ep->X_op_symbol
964 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
965 {
966 inst.error = _("invalid constant");
967 *str = input_line_pointer;
968 input_line_pointer = save_in;
969 return 1;
970 }
b99bd4ef 971
c19d1205
ZW
972 *str = input_line_pointer;
973 input_line_pointer = save_in;
974 return 0;
b99bd4ef
NC
975}
976
c19d1205
ZW
977/* Turn a string in input_line_pointer into a floating point constant
978 of type TYPE, and store the appropriate bytes in *LITP. The number
979 of LITTLENUMS emitted is stored in *SIZEP. An error message is
980 returned, or NULL on OK.
b99bd4ef 981
c19d1205
ZW
982 Note that fp constants aren't represent in the normal way on the ARM.
983 In big endian mode, things are as expected. However, in little endian
984 mode fp constants are big-endian word-wise, and little-endian byte-wise
985 within the words. For example, (double) 1.1 in big endian mode is
986 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
987 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 988
c19d1205 989 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 990
c19d1205
ZW
991char *
992md_atof (int type, char * litP, int * sizeP)
993{
994 int prec;
995 LITTLENUM_TYPE words[MAX_LITTLENUMS];
996 char *t;
997 int i;
b99bd4ef 998
c19d1205
ZW
999 switch (type)
1000 {
1001 case 'f':
1002 case 'F':
1003 case 's':
1004 case 'S':
1005 prec = 2;
1006 break;
b99bd4ef 1007
c19d1205
ZW
1008 case 'd':
1009 case 'D':
1010 case 'r':
1011 case 'R':
1012 prec = 4;
1013 break;
b99bd4ef 1014
c19d1205
ZW
1015 case 'x':
1016 case 'X':
499ac353 1017 prec = 5;
c19d1205 1018 break;
b99bd4ef 1019
c19d1205
ZW
1020 case 'p':
1021 case 'P':
499ac353 1022 prec = 5;
c19d1205 1023 break;
a737bd4d 1024
c19d1205
ZW
1025 default:
1026 *sizeP = 0;
499ac353 1027 return _("Unrecognized or unsupported floating point constant");
c19d1205 1028 }
b99bd4ef 1029
c19d1205
ZW
1030 t = atof_ieee (input_line_pointer, type, words);
1031 if (t)
1032 input_line_pointer = t;
499ac353 1033 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1034
c19d1205
ZW
1035 if (target_big_endian)
1036 {
1037 for (i = 0; i < prec; i++)
1038 {
499ac353
NC
1039 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1040 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1041 }
1042 }
1043 else
1044 {
e74cfd16 1045 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1046 for (i = prec - 1; i >= 0; i--)
1047 {
499ac353
NC
1048 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1049 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1050 }
1051 else
1052 /* For a 4 byte float the order of elements in `words' is 1 0.
1053 For an 8 byte float the order is 1 0 3 2. */
1054 for (i = 0; i < prec; i += 2)
1055 {
499ac353
NC
1056 md_number_to_chars (litP, (valueT) words[i + 1],
1057 sizeof (LITTLENUM_TYPE));
1058 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1059 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1060 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1061 }
1062 }
b99bd4ef 1063
499ac353 1064 return NULL;
c19d1205 1065}
b99bd4ef 1066
c19d1205
ZW
1067/* We handle all bad expressions here, so that we can report the faulty
1068 instruction in the error message. */
1069void
91d6fa6a 1070md_operand (expressionS * exp)
c19d1205
ZW
1071{
1072 if (in_my_get_expression)
91d6fa6a 1073 exp->X_op = O_illegal;
b99bd4ef
NC
1074}
1075
c19d1205 1076/* Immediate values. */
b99bd4ef 1077
c19d1205
ZW
1078/* Generic immediate-value read function for use in directives.
1079 Accepts anything that 'expression' can fold to a constant.
1080 *val receives the number. */
1081#ifdef OBJ_ELF
1082static int
1083immediate_for_directive (int *val)
b99bd4ef 1084{
c19d1205
ZW
1085 expressionS exp;
1086 exp.X_op = O_illegal;
b99bd4ef 1087
c19d1205
ZW
1088 if (is_immediate_prefix (*input_line_pointer))
1089 {
1090 input_line_pointer++;
1091 expression (&exp);
1092 }
b99bd4ef 1093
c19d1205
ZW
1094 if (exp.X_op != O_constant)
1095 {
1096 as_bad (_("expected #constant"));
1097 ignore_rest_of_line ();
1098 return FAIL;
1099 }
1100 *val = exp.X_add_number;
1101 return SUCCESS;
b99bd4ef 1102}
c19d1205 1103#endif
b99bd4ef 1104
c19d1205 1105/* Register parsing. */
b99bd4ef 1106
c19d1205
ZW
1107/* Generic register parser. CCP points to what should be the
1108 beginning of a register name. If it is indeed a valid register
1109 name, advance CCP over it and return the reg_entry structure;
1110 otherwise return NULL. Does not issue diagnostics. */
1111
1112static struct reg_entry *
1113arm_reg_parse_multi (char **ccp)
b99bd4ef 1114{
c19d1205
ZW
1115 char *start = *ccp;
1116 char *p;
1117 struct reg_entry *reg;
b99bd4ef 1118
c19d1205
ZW
1119#ifdef REGISTER_PREFIX
1120 if (*start != REGISTER_PREFIX)
01cfc07f 1121 return NULL;
c19d1205
ZW
1122 start++;
1123#endif
1124#ifdef OPTIONAL_REGISTER_PREFIX
1125 if (*start == OPTIONAL_REGISTER_PREFIX)
1126 start++;
1127#endif
b99bd4ef 1128
c19d1205
ZW
1129 p = start;
1130 if (!ISALPHA (*p) || !is_name_beginner (*p))
1131 return NULL;
b99bd4ef 1132
c19d1205
ZW
1133 do
1134 p++;
1135 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1136
1137 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1138
1139 if (!reg)
1140 return NULL;
1141
1142 *ccp = p;
1143 return reg;
b99bd4ef
NC
1144}
1145
1146static int
dcbf9037
JB
1147arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1148 enum arm_reg_type type)
b99bd4ef 1149{
c19d1205
ZW
1150 /* Alternative syntaxes are accepted for a few register classes. */
1151 switch (type)
1152 {
1153 case REG_TYPE_MVF:
1154 case REG_TYPE_MVD:
1155 case REG_TYPE_MVFX:
1156 case REG_TYPE_MVDX:
1157 /* Generic coprocessor register names are allowed for these. */
79134647 1158 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1159 return reg->number;
1160 break;
69b97547 1161
c19d1205
ZW
1162 case REG_TYPE_CP:
1163 /* For backward compatibility, a bare number is valid here. */
1164 {
1165 unsigned long processor = strtoul (start, ccp, 10);
1166 if (*ccp != start && processor <= 15)
1167 return processor;
1168 }
6057a28f 1169
c19d1205
ZW
1170 case REG_TYPE_MMXWC:
1171 /* WC includes WCG. ??? I'm not sure this is true for all
1172 instructions that take WC registers. */
79134647 1173 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1174 return reg->number;
6057a28f 1175 break;
c19d1205 1176
6057a28f 1177 default:
c19d1205 1178 break;
6057a28f
NC
1179 }
1180
dcbf9037
JB
1181 return FAIL;
1182}
1183
1184/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1185 return value is the register number or FAIL. */
1186
1187static int
1188arm_reg_parse (char **ccp, enum arm_reg_type type)
1189{
1190 char *start = *ccp;
1191 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1192 int ret;
1193
1194 /* Do not allow a scalar (reg+index) to parse as a register. */
1195 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1196 return FAIL;
1197
1198 if (reg && reg->type == type)
1199 return reg->number;
1200
1201 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1202 return ret;
1203
c19d1205
ZW
1204 *ccp = start;
1205 return FAIL;
1206}
69b97547 1207
dcbf9037
JB
1208/* Parse a Neon type specifier. *STR should point at the leading '.'
1209 character. Does no verification at this stage that the type fits the opcode
1210 properly. E.g.,
1211
1212 .i32.i32.s16
1213 .s32.f32
1214 .u16
1215
1216 Can all be legally parsed by this function.
1217
1218 Fills in neon_type struct pointer with parsed information, and updates STR
1219 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1220 type, FAIL if not. */
1221
1222static int
1223parse_neon_type (struct neon_type *type, char **str)
1224{
1225 char *ptr = *str;
1226
1227 if (type)
1228 type->elems = 0;
1229
1230 while (type->elems < NEON_MAX_TYPE_ELS)
1231 {
1232 enum neon_el_type thistype = NT_untyped;
1233 unsigned thissize = -1u;
1234
1235 if (*ptr != '.')
1236 break;
1237
1238 ptr++;
1239
1240 /* Just a size without an explicit type. */
1241 if (ISDIGIT (*ptr))
1242 goto parsesize;
1243
1244 switch (TOLOWER (*ptr))
1245 {
1246 case 'i': thistype = NT_integer; break;
1247 case 'f': thistype = NT_float; break;
1248 case 'p': thistype = NT_poly; break;
1249 case 's': thistype = NT_signed; break;
1250 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1251 case 'd':
1252 thistype = NT_float;
1253 thissize = 64;
1254 ptr++;
1255 goto done;
dcbf9037
JB
1256 default:
1257 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1258 return FAIL;
1259 }
1260
1261 ptr++;
1262
1263 /* .f is an abbreviation for .f32. */
1264 if (thistype == NT_float && !ISDIGIT (*ptr))
1265 thissize = 32;
1266 else
1267 {
1268 parsesize:
1269 thissize = strtoul (ptr, &ptr, 10);
1270
1271 if (thissize != 8 && thissize != 16 && thissize != 32
1272 && thissize != 64)
1273 {
1274 as_bad (_("bad size %d in type specifier"), thissize);
1275 return FAIL;
1276 }
1277 }
1278
037e8744 1279 done:
dcbf9037
JB
1280 if (type)
1281 {
1282 type->el[type->elems].type = thistype;
1283 type->el[type->elems].size = thissize;
1284 type->elems++;
1285 }
1286 }
1287
1288 /* Empty/missing type is not a successful parse. */
1289 if (type->elems == 0)
1290 return FAIL;
1291
1292 *str = ptr;
1293
1294 return SUCCESS;
1295}
1296
1297/* Errors may be set multiple times during parsing or bit encoding
1298 (particularly in the Neon bits), but usually the earliest error which is set
1299 will be the most meaningful. Avoid overwriting it with later (cascading)
1300 errors by calling this function. */
1301
1302static void
1303first_error (const char *err)
1304{
1305 if (!inst.error)
1306 inst.error = err;
1307}
1308
1309/* Parse a single type, e.g. ".s32", leading period included. */
1310static int
1311parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1312{
1313 char *str = *ccp;
1314 struct neon_type optype;
1315
1316 if (*str == '.')
1317 {
1318 if (parse_neon_type (&optype, &str) == SUCCESS)
1319 {
1320 if (optype.elems == 1)
1321 *vectype = optype.el[0];
1322 else
1323 {
1324 first_error (_("only one type should be specified for operand"));
1325 return FAIL;
1326 }
1327 }
1328 else
1329 {
1330 first_error (_("vector type expected"));
1331 return FAIL;
1332 }
1333 }
1334 else
1335 return FAIL;
5f4273c7 1336
dcbf9037 1337 *ccp = str;
5f4273c7 1338
dcbf9037
JB
1339 return SUCCESS;
1340}
1341
1342/* Special meanings for indices (which have a range of 0-7), which will fit into
1343 a 4-bit integer. */
1344
1345#define NEON_ALL_LANES 15
1346#define NEON_INTERLEAVE_LANES 14
1347
1348/* Parse either a register or a scalar, with an optional type. Return the
1349 register number, and optionally fill in the actual type of the register
1350 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1351 type/index information in *TYPEINFO. */
1352
1353static int
1354parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1355 enum arm_reg_type *rtype,
1356 struct neon_typed_alias *typeinfo)
1357{
1358 char *str = *ccp;
1359 struct reg_entry *reg = arm_reg_parse_multi (&str);
1360 struct neon_typed_alias atype;
1361 struct neon_type_el parsetype;
1362
1363 atype.defined = 0;
1364 atype.index = -1;
1365 atype.eltype.type = NT_invtype;
1366 atype.eltype.size = -1;
1367
1368 /* Try alternate syntax for some types of register. Note these are mutually
1369 exclusive with the Neon syntax extensions. */
1370 if (reg == NULL)
1371 {
1372 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1373 if (altreg != FAIL)
1374 *ccp = str;
1375 if (typeinfo)
1376 *typeinfo = atype;
1377 return altreg;
1378 }
1379
037e8744
JB
1380 /* Undo polymorphism when a set of register types may be accepted. */
1381 if ((type == REG_TYPE_NDQ
1382 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1383 || (type == REG_TYPE_VFSD
1384 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1385 || (type == REG_TYPE_NSDQ
1386 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1387 || reg->type == REG_TYPE_NQ))
1388 || (type == REG_TYPE_MMXWC
1389 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1390 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1391
1392 if (type != reg->type)
1393 return FAIL;
1394
1395 if (reg->neon)
1396 atype = *reg->neon;
5f4273c7 1397
dcbf9037
JB
1398 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1399 {
1400 if ((atype.defined & NTA_HASTYPE) != 0)
1401 {
1402 first_error (_("can't redefine type for operand"));
1403 return FAIL;
1404 }
1405 atype.defined |= NTA_HASTYPE;
1406 atype.eltype = parsetype;
1407 }
5f4273c7 1408
dcbf9037
JB
1409 if (skip_past_char (&str, '[') == SUCCESS)
1410 {
1411 if (type != REG_TYPE_VFD)
1412 {
1413 first_error (_("only D registers may be indexed"));
1414 return FAIL;
1415 }
5f4273c7 1416
dcbf9037
JB
1417 if ((atype.defined & NTA_HASINDEX) != 0)
1418 {
1419 first_error (_("can't change index for operand"));
1420 return FAIL;
1421 }
1422
1423 atype.defined |= NTA_HASINDEX;
1424
1425 if (skip_past_char (&str, ']') == SUCCESS)
1426 atype.index = NEON_ALL_LANES;
1427 else
1428 {
1429 expressionS exp;
1430
1431 my_get_expression (&exp, &str, GE_NO_PREFIX);
1432
1433 if (exp.X_op != O_constant)
1434 {
1435 first_error (_("constant expression required"));
1436 return FAIL;
1437 }
1438
1439 if (skip_past_char (&str, ']') == FAIL)
1440 return FAIL;
1441
1442 atype.index = exp.X_add_number;
1443 }
1444 }
5f4273c7 1445
dcbf9037
JB
1446 if (typeinfo)
1447 *typeinfo = atype;
5f4273c7 1448
dcbf9037
JB
1449 if (rtype)
1450 *rtype = type;
5f4273c7 1451
dcbf9037 1452 *ccp = str;
5f4273c7 1453
dcbf9037
JB
1454 return reg->number;
1455}
1456
1457/* Like arm_reg_parse, but allow allow the following extra features:
1458 - If RTYPE is non-zero, return the (possibly restricted) type of the
1459 register (e.g. Neon double or quad reg when either has been requested).
1460 - If this is a Neon vector type with additional type information, fill
1461 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1462 This function will fault on encountering a scalar. */
dcbf9037
JB
1463
1464static int
1465arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1466 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1467{
1468 struct neon_typed_alias atype;
1469 char *str = *ccp;
1470 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1471
1472 if (reg == FAIL)
1473 return FAIL;
1474
0855e32b
NS
1475 /* Do not allow regname(... to parse as a register. */
1476 if (*str == '(')
1477 return FAIL;
1478
dcbf9037
JB
1479 /* Do not allow a scalar (reg+index) to parse as a register. */
1480 if ((atype.defined & NTA_HASINDEX) != 0)
1481 {
1482 first_error (_("register operand expected, but got scalar"));
1483 return FAIL;
1484 }
1485
1486 if (vectype)
1487 *vectype = atype.eltype;
1488
1489 *ccp = str;
1490
1491 return reg;
1492}
1493
1494#define NEON_SCALAR_REG(X) ((X) >> 4)
1495#define NEON_SCALAR_INDEX(X) ((X) & 15)
1496
5287ad62
JB
1497/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1498 have enough information to be able to do a good job bounds-checking. So, we
1499 just do easy checks here, and do further checks later. */
1500
1501static int
dcbf9037 1502parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1503{
dcbf9037 1504 int reg;
5287ad62 1505 char *str = *ccp;
dcbf9037 1506 struct neon_typed_alias atype;
5f4273c7 1507
dcbf9037 1508 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1509
dcbf9037 1510 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1511 return FAIL;
5f4273c7 1512
dcbf9037 1513 if (atype.index == NEON_ALL_LANES)
5287ad62 1514 {
dcbf9037 1515 first_error (_("scalar must have an index"));
5287ad62
JB
1516 return FAIL;
1517 }
dcbf9037 1518 else if (atype.index >= 64 / elsize)
5287ad62 1519 {
dcbf9037 1520 first_error (_("scalar index out of range"));
5287ad62
JB
1521 return FAIL;
1522 }
5f4273c7 1523
dcbf9037
JB
1524 if (type)
1525 *type = atype.eltype;
5f4273c7 1526
5287ad62 1527 *ccp = str;
5f4273c7 1528
dcbf9037 1529 return reg * 16 + atype.index;
5287ad62
JB
1530}
1531
c19d1205 1532/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1533
c19d1205
ZW
1534static long
1535parse_reg_list (char ** strp)
1536{
1537 char * str = * strp;
1538 long range = 0;
1539 int another_range;
a737bd4d 1540
c19d1205
ZW
1541 /* We come back here if we get ranges concatenated by '+' or '|'. */
1542 do
6057a28f 1543 {
c19d1205 1544 another_range = 0;
a737bd4d 1545
c19d1205
ZW
1546 if (*str == '{')
1547 {
1548 int in_range = 0;
1549 int cur_reg = -1;
a737bd4d 1550
c19d1205
ZW
1551 str++;
1552 do
1553 {
1554 int reg;
6057a28f 1555
dcbf9037 1556 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1557 {
dcbf9037 1558 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1559 return FAIL;
1560 }
a737bd4d 1561
c19d1205
ZW
1562 if (in_range)
1563 {
1564 int i;
a737bd4d 1565
c19d1205
ZW
1566 if (reg <= cur_reg)
1567 {
dcbf9037 1568 first_error (_("bad range in register list"));
c19d1205
ZW
1569 return FAIL;
1570 }
40a18ebd 1571
c19d1205
ZW
1572 for (i = cur_reg + 1; i < reg; i++)
1573 {
1574 if (range & (1 << i))
1575 as_tsktsk
1576 (_("Warning: duplicated register (r%d) in register list"),
1577 i);
1578 else
1579 range |= 1 << i;
1580 }
1581 in_range = 0;
1582 }
a737bd4d 1583
c19d1205
ZW
1584 if (range & (1 << reg))
1585 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1586 reg);
1587 else if (reg <= cur_reg)
1588 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1589
c19d1205
ZW
1590 range |= 1 << reg;
1591 cur_reg = reg;
1592 }
1593 while (skip_past_comma (&str) != FAIL
1594 || (in_range = 1, *str++ == '-'));
1595 str--;
a737bd4d 1596
c19d1205
ZW
1597 if (*str++ != '}')
1598 {
dcbf9037 1599 first_error (_("missing `}'"));
c19d1205
ZW
1600 return FAIL;
1601 }
1602 }
1603 else
1604 {
91d6fa6a 1605 expressionS exp;
40a18ebd 1606
91d6fa6a 1607 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1608 return FAIL;
40a18ebd 1609
91d6fa6a 1610 if (exp.X_op == O_constant)
c19d1205 1611 {
91d6fa6a
NC
1612 if (exp.X_add_number
1613 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1614 {
1615 inst.error = _("invalid register mask");
1616 return FAIL;
1617 }
a737bd4d 1618
91d6fa6a 1619 if ((range & exp.X_add_number) != 0)
c19d1205 1620 {
91d6fa6a 1621 int regno = range & exp.X_add_number;
a737bd4d 1622
c19d1205
ZW
1623 regno &= -regno;
1624 regno = (1 << regno) - 1;
1625 as_tsktsk
1626 (_("Warning: duplicated register (r%d) in register list"),
1627 regno);
1628 }
a737bd4d 1629
91d6fa6a 1630 range |= exp.X_add_number;
c19d1205
ZW
1631 }
1632 else
1633 {
1634 if (inst.reloc.type != 0)
1635 {
1636 inst.error = _("expression too complex");
1637 return FAIL;
1638 }
a737bd4d 1639
91d6fa6a 1640 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1641 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1642 inst.reloc.pc_rel = 0;
1643 }
1644 }
a737bd4d 1645
c19d1205
ZW
1646 if (*str == '|' || *str == '+')
1647 {
1648 str++;
1649 another_range = 1;
1650 }
a737bd4d 1651 }
c19d1205 1652 while (another_range);
a737bd4d 1653
c19d1205
ZW
1654 *strp = str;
1655 return range;
a737bd4d
NC
1656}
1657
5287ad62
JB
1658/* Types of registers in a list. */
1659
1660enum reg_list_els
1661{
1662 REGLIST_VFP_S,
1663 REGLIST_VFP_D,
1664 REGLIST_NEON_D
1665};
1666
c19d1205
ZW
1667/* Parse a VFP register list. If the string is invalid return FAIL.
1668 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1669 register. Parses registers of type ETYPE.
1670 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1671 - Q registers can be used to specify pairs of D registers
1672 - { } can be omitted from around a singleton register list
1673 FIXME: This is not implemented, as it would require backtracking in
1674 some cases, e.g.:
1675 vtbl.8 d3,d4,d5
1676 This could be done (the meaning isn't really ambiguous), but doesn't
1677 fit in well with the current parsing framework.
dcbf9037
JB
1678 - 32 D registers may be used (also true for VFPv3).
1679 FIXME: Types are ignored in these register lists, which is probably a
1680 bug. */
6057a28f 1681
c19d1205 1682static int
037e8744 1683parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1684{
037e8744 1685 char *str = *ccp;
c19d1205
ZW
1686 int base_reg;
1687 int new_base;
21d799b5 1688 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1689 int max_regs = 0;
c19d1205
ZW
1690 int count = 0;
1691 int warned = 0;
1692 unsigned long mask = 0;
a737bd4d 1693 int i;
6057a28f 1694
037e8744 1695 if (*str != '{')
5287ad62
JB
1696 {
1697 inst.error = _("expecting {");
1698 return FAIL;
1699 }
6057a28f 1700
037e8744 1701 str++;
6057a28f 1702
5287ad62 1703 switch (etype)
c19d1205 1704 {
5287ad62 1705 case REGLIST_VFP_S:
c19d1205
ZW
1706 regtype = REG_TYPE_VFS;
1707 max_regs = 32;
5287ad62 1708 break;
5f4273c7 1709
5287ad62
JB
1710 case REGLIST_VFP_D:
1711 regtype = REG_TYPE_VFD;
b7fc2769 1712 break;
5f4273c7 1713
b7fc2769
JB
1714 case REGLIST_NEON_D:
1715 regtype = REG_TYPE_NDQ;
1716 break;
1717 }
1718
1719 if (etype != REGLIST_VFP_S)
1720 {
b1cc4aeb
PB
1721 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1722 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1723 {
1724 max_regs = 32;
1725 if (thumb_mode)
1726 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1727 fpu_vfp_ext_d32);
5287ad62
JB
1728 else
1729 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1730 fpu_vfp_ext_d32);
5287ad62
JB
1731 }
1732 else
1733 max_regs = 16;
c19d1205 1734 }
6057a28f 1735
c19d1205 1736 base_reg = max_regs;
a737bd4d 1737
c19d1205
ZW
1738 do
1739 {
5287ad62 1740 int setmask = 1, addregs = 1;
dcbf9037 1741
037e8744 1742 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1743
c19d1205 1744 if (new_base == FAIL)
a737bd4d 1745 {
dcbf9037 1746 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1747 return FAIL;
1748 }
5f4273c7 1749
b7fc2769
JB
1750 if (new_base >= max_regs)
1751 {
1752 first_error (_("register out of range in list"));
1753 return FAIL;
1754 }
5f4273c7 1755
5287ad62
JB
1756 /* Note: a value of 2 * n is returned for the register Q<n>. */
1757 if (regtype == REG_TYPE_NQ)
1758 {
1759 setmask = 3;
1760 addregs = 2;
1761 }
1762
c19d1205
ZW
1763 if (new_base < base_reg)
1764 base_reg = new_base;
a737bd4d 1765
5287ad62 1766 if (mask & (setmask << new_base))
c19d1205 1767 {
dcbf9037 1768 first_error (_("invalid register list"));
c19d1205 1769 return FAIL;
a737bd4d 1770 }
a737bd4d 1771
c19d1205
ZW
1772 if ((mask >> new_base) != 0 && ! warned)
1773 {
1774 as_tsktsk (_("register list not in ascending order"));
1775 warned = 1;
1776 }
0bbf2aa4 1777
5287ad62
JB
1778 mask |= setmask << new_base;
1779 count += addregs;
0bbf2aa4 1780
037e8744 1781 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1782 {
1783 int high_range;
0bbf2aa4 1784
037e8744 1785 str++;
0bbf2aa4 1786
037e8744 1787 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1788 == FAIL)
c19d1205
ZW
1789 {
1790 inst.error = gettext (reg_expected_msgs[regtype]);
1791 return FAIL;
1792 }
0bbf2aa4 1793
b7fc2769
JB
1794 if (high_range >= max_regs)
1795 {
1796 first_error (_("register out of range in list"));
1797 return FAIL;
1798 }
1799
5287ad62
JB
1800 if (regtype == REG_TYPE_NQ)
1801 high_range = high_range + 1;
1802
c19d1205
ZW
1803 if (high_range <= new_base)
1804 {
1805 inst.error = _("register range not in ascending order");
1806 return FAIL;
1807 }
0bbf2aa4 1808
5287ad62 1809 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1810 {
5287ad62 1811 if (mask & (setmask << new_base))
0bbf2aa4 1812 {
c19d1205
ZW
1813 inst.error = _("invalid register list");
1814 return FAIL;
0bbf2aa4 1815 }
c19d1205 1816
5287ad62
JB
1817 mask |= setmask << new_base;
1818 count += addregs;
0bbf2aa4 1819 }
0bbf2aa4 1820 }
0bbf2aa4 1821 }
037e8744 1822 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1823
037e8744 1824 str++;
0bbf2aa4 1825
c19d1205
ZW
1826 /* Sanity check -- should have raised a parse error above. */
1827 if (count == 0 || count > max_regs)
1828 abort ();
1829
1830 *pbase = base_reg;
1831
1832 /* Final test -- the registers must be consecutive. */
1833 mask >>= base_reg;
1834 for (i = 0; i < count; i++)
1835 {
1836 if ((mask & (1u << i)) == 0)
1837 {
1838 inst.error = _("non-contiguous register range");
1839 return FAIL;
1840 }
1841 }
1842
037e8744
JB
1843 *ccp = str;
1844
c19d1205 1845 return count;
b99bd4ef
NC
1846}
1847
dcbf9037
JB
1848/* True if two alias types are the same. */
1849
c921be7d 1850static bfd_boolean
dcbf9037
JB
1851neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1852{
1853 if (!a && !b)
c921be7d 1854 return TRUE;
5f4273c7 1855
dcbf9037 1856 if (!a || !b)
c921be7d 1857 return FALSE;
dcbf9037
JB
1858
1859 if (a->defined != b->defined)
c921be7d 1860 return FALSE;
5f4273c7 1861
dcbf9037
JB
1862 if ((a->defined & NTA_HASTYPE) != 0
1863 && (a->eltype.type != b->eltype.type
1864 || a->eltype.size != b->eltype.size))
c921be7d 1865 return FALSE;
dcbf9037
JB
1866
1867 if ((a->defined & NTA_HASINDEX) != 0
1868 && (a->index != b->index))
c921be7d 1869 return FALSE;
5f4273c7 1870
c921be7d 1871 return TRUE;
dcbf9037
JB
1872}
1873
5287ad62
JB
1874/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1875 The base register is put in *PBASE.
dcbf9037 1876 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1877 the return value.
1878 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1879 Bits [6:5] encode the list length (minus one).
1880 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1881
5287ad62 1882#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1883#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1884#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1885
1886static int
dcbf9037
JB
1887parse_neon_el_struct_list (char **str, unsigned *pbase,
1888 struct neon_type_el *eltype)
5287ad62
JB
1889{
1890 char *ptr = *str;
1891 int base_reg = -1;
1892 int reg_incr = -1;
1893 int count = 0;
1894 int lane = -1;
1895 int leading_brace = 0;
1896 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1897 const char *const incr_error = _("register stride must be 1 or 2");
1898 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1899 struct neon_typed_alias firsttype;
5f4273c7 1900
5287ad62
JB
1901 if (skip_past_char (&ptr, '{') == SUCCESS)
1902 leading_brace = 1;
5f4273c7 1903
5287ad62
JB
1904 do
1905 {
dcbf9037
JB
1906 struct neon_typed_alias atype;
1907 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1908
5287ad62
JB
1909 if (getreg == FAIL)
1910 {
dcbf9037 1911 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1912 return FAIL;
1913 }
5f4273c7 1914
5287ad62
JB
1915 if (base_reg == -1)
1916 {
1917 base_reg = getreg;
1918 if (rtype == REG_TYPE_NQ)
1919 {
1920 reg_incr = 1;
5287ad62 1921 }
dcbf9037 1922 firsttype = atype;
5287ad62
JB
1923 }
1924 else if (reg_incr == -1)
1925 {
1926 reg_incr = getreg - base_reg;
1927 if (reg_incr < 1 || reg_incr > 2)
1928 {
dcbf9037 1929 first_error (_(incr_error));
5287ad62
JB
1930 return FAIL;
1931 }
1932 }
1933 else if (getreg != base_reg + reg_incr * count)
1934 {
dcbf9037
JB
1935 first_error (_(incr_error));
1936 return FAIL;
1937 }
1938
c921be7d 1939 if (! neon_alias_types_same (&atype, &firsttype))
dcbf9037
JB
1940 {
1941 first_error (_(type_error));
5287ad62
JB
1942 return FAIL;
1943 }
5f4273c7 1944
5287ad62
JB
1945 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1946 modes. */
1947 if (ptr[0] == '-')
1948 {
dcbf9037 1949 struct neon_typed_alias htype;
5287ad62
JB
1950 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1951 if (lane == -1)
1952 lane = NEON_INTERLEAVE_LANES;
1953 else if (lane != NEON_INTERLEAVE_LANES)
1954 {
dcbf9037 1955 first_error (_(type_error));
5287ad62
JB
1956 return FAIL;
1957 }
1958 if (reg_incr == -1)
1959 reg_incr = 1;
1960 else if (reg_incr != 1)
1961 {
dcbf9037 1962 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1963 return FAIL;
1964 }
1965 ptr++;
dcbf9037 1966 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1967 if (hireg == FAIL)
1968 {
dcbf9037
JB
1969 first_error (_(reg_expected_msgs[rtype]));
1970 return FAIL;
1971 }
c921be7d 1972 if (! neon_alias_types_same (&htype, &firsttype))
dcbf9037
JB
1973 {
1974 first_error (_(type_error));
5287ad62
JB
1975 return FAIL;
1976 }
1977 count += hireg + dregs - getreg;
1978 continue;
1979 }
5f4273c7 1980
5287ad62
JB
1981 /* If we're using Q registers, we can't use [] or [n] syntax. */
1982 if (rtype == REG_TYPE_NQ)
1983 {
1984 count += 2;
1985 continue;
1986 }
5f4273c7 1987
dcbf9037 1988 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1989 {
dcbf9037
JB
1990 if (lane == -1)
1991 lane = atype.index;
1992 else if (lane != atype.index)
5287ad62 1993 {
dcbf9037
JB
1994 first_error (_(type_error));
1995 return FAIL;
5287ad62
JB
1996 }
1997 }
1998 else if (lane == -1)
1999 lane = NEON_INTERLEAVE_LANES;
2000 else if (lane != NEON_INTERLEAVE_LANES)
2001 {
dcbf9037 2002 first_error (_(type_error));
5287ad62
JB
2003 return FAIL;
2004 }
2005 count++;
2006 }
2007 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2008
5287ad62
JB
2009 /* No lane set by [x]. We must be interleaving structures. */
2010 if (lane == -1)
2011 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2012
5287ad62
JB
2013 /* Sanity check. */
2014 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2015 || (count > 1 && reg_incr == -1))
2016 {
dcbf9037 2017 first_error (_("error parsing element/structure list"));
5287ad62
JB
2018 return FAIL;
2019 }
2020
2021 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2022 {
dcbf9037 2023 first_error (_("expected }"));
5287ad62
JB
2024 return FAIL;
2025 }
5f4273c7 2026
5287ad62
JB
2027 if (reg_incr == -1)
2028 reg_incr = 1;
2029
dcbf9037
JB
2030 if (eltype)
2031 *eltype = firsttype.eltype;
2032
5287ad62
JB
2033 *pbase = base_reg;
2034 *str = ptr;
5f4273c7 2035
5287ad62
JB
2036 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2037}
2038
c19d1205
ZW
2039/* Parse an explicit relocation suffix on an expression. This is
2040 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2041 arm_reloc_hsh contains no entries, so this function can only
2042 succeed if there is no () after the word. Returns -1 on error,
2043 BFD_RELOC_UNUSED if there wasn't any suffix. */
2044static int
2045parse_reloc (char **str)
b99bd4ef 2046{
c19d1205
ZW
2047 struct reloc_entry *r;
2048 char *p, *q;
b99bd4ef 2049
c19d1205
ZW
2050 if (**str != '(')
2051 return BFD_RELOC_UNUSED;
b99bd4ef 2052
c19d1205
ZW
2053 p = *str + 1;
2054 q = p;
2055
2056 while (*q && *q != ')' && *q != ',')
2057 q++;
2058 if (*q != ')')
2059 return -1;
2060
21d799b5
NC
2061 if ((r = (struct reloc_entry *)
2062 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2063 return -1;
2064
2065 *str = q + 1;
2066 return r->reloc;
b99bd4ef
NC
2067}
2068
c19d1205
ZW
2069/* Directives: register aliases. */
2070
dcbf9037 2071static struct reg_entry *
90ec0d68 2072insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2073{
d3ce72d0 2074 struct reg_entry *new_reg;
c19d1205 2075 const char *name;
b99bd4ef 2076
d3ce72d0 2077 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2078 {
d3ce72d0 2079 if (new_reg->builtin)
c19d1205 2080 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2081
c19d1205
ZW
2082 /* Only warn about a redefinition if it's not defined as the
2083 same register. */
d3ce72d0 2084 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2085 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2086
d929913e 2087 return NULL;
c19d1205 2088 }
b99bd4ef 2089
c19d1205 2090 name = xstrdup (str);
d3ce72d0 2091 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2092
d3ce72d0
NC
2093 new_reg->name = name;
2094 new_reg->number = number;
2095 new_reg->type = type;
2096 new_reg->builtin = FALSE;
2097 new_reg->neon = NULL;
b99bd4ef 2098
d3ce72d0 2099 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2100 abort ();
5f4273c7 2101
d3ce72d0 2102 return new_reg;
dcbf9037
JB
2103}
2104
2105static void
2106insert_neon_reg_alias (char *str, int number, int type,
2107 struct neon_typed_alias *atype)
2108{
2109 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2110
dcbf9037
JB
2111 if (!reg)
2112 {
2113 first_error (_("attempt to redefine typed alias"));
2114 return;
2115 }
5f4273c7 2116
dcbf9037
JB
2117 if (atype)
2118 {
21d799b5
NC
2119 reg->neon = (struct neon_typed_alias *)
2120 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2121 *reg->neon = *atype;
2122 }
c19d1205 2123}
b99bd4ef 2124
c19d1205 2125/* Look for the .req directive. This is of the form:
b99bd4ef 2126
c19d1205 2127 new_register_name .req existing_register_name
b99bd4ef 2128
c19d1205 2129 If we find one, or if it looks sufficiently like one that we want to
d929913e 2130 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2131
d929913e 2132static bfd_boolean
c19d1205
ZW
2133create_register_alias (char * newname, char *p)
2134{
2135 struct reg_entry *old;
2136 char *oldname, *nbuf;
2137 size_t nlen;
b99bd4ef 2138
c19d1205
ZW
2139 /* The input scrubber ensures that whitespace after the mnemonic is
2140 collapsed to single spaces. */
2141 oldname = p;
2142 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2143 return FALSE;
b99bd4ef 2144
c19d1205
ZW
2145 oldname += 6;
2146 if (*oldname == '\0')
d929913e 2147 return FALSE;
b99bd4ef 2148
21d799b5 2149 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2150 if (!old)
b99bd4ef 2151 {
c19d1205 2152 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2153 return TRUE;
b99bd4ef
NC
2154 }
2155
c19d1205
ZW
2156 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2157 the desired alias name, and p points to its end. If not, then
2158 the desired alias name is in the global original_case_string. */
2159#ifdef TC_CASE_SENSITIVE
2160 nlen = p - newname;
2161#else
2162 newname = original_case_string;
2163 nlen = strlen (newname);
2164#endif
b99bd4ef 2165
21d799b5 2166 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2167 memcpy (nbuf, newname, nlen);
2168 nbuf[nlen] = '\0';
b99bd4ef 2169
c19d1205
ZW
2170 /* Create aliases under the new name as stated; an all-lowercase
2171 version of the new name; and an all-uppercase version of the new
2172 name. */
d929913e
NC
2173 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2174 {
2175 for (p = nbuf; *p; p++)
2176 *p = TOUPPER (*p);
c19d1205 2177
d929913e
NC
2178 if (strncmp (nbuf, newname, nlen))
2179 {
2180 /* If this attempt to create an additional alias fails, do not bother
2181 trying to create the all-lower case alias. We will fail and issue
2182 a second, duplicate error message. This situation arises when the
2183 programmer does something like:
2184 foo .req r0
2185 Foo .req r1
2186 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2187 the artificial FOO alias because it has already been created by the
d929913e
NC
2188 first .req. */
2189 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2190 return TRUE;
2191 }
c19d1205 2192
d929913e
NC
2193 for (p = nbuf; *p; p++)
2194 *p = TOLOWER (*p);
c19d1205 2195
d929913e
NC
2196 if (strncmp (nbuf, newname, nlen))
2197 insert_reg_alias (nbuf, old->number, old->type);
2198 }
c19d1205 2199
d929913e 2200 return TRUE;
b99bd4ef
NC
2201}
2202
dcbf9037
JB
2203/* Create a Neon typed/indexed register alias using directives, e.g.:
2204 X .dn d5.s32[1]
2205 Y .qn 6.s16
2206 Z .dn d7
2207 T .dn Z[0]
2208 These typed registers can be used instead of the types specified after the
2209 Neon mnemonic, so long as all operands given have types. Types can also be
2210 specified directly, e.g.:
5f4273c7 2211 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2212
c921be7d 2213static bfd_boolean
dcbf9037
JB
2214create_neon_reg_alias (char *newname, char *p)
2215{
2216 enum arm_reg_type basetype;
2217 struct reg_entry *basereg;
2218 struct reg_entry mybasereg;
2219 struct neon_type ntype;
2220 struct neon_typed_alias typeinfo;
12d6b0b7 2221 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2222 int namelen;
5f4273c7 2223
dcbf9037
JB
2224 typeinfo.defined = 0;
2225 typeinfo.eltype.type = NT_invtype;
2226 typeinfo.eltype.size = -1;
2227 typeinfo.index = -1;
5f4273c7 2228
dcbf9037 2229 nameend = p;
5f4273c7 2230
dcbf9037
JB
2231 if (strncmp (p, " .dn ", 5) == 0)
2232 basetype = REG_TYPE_VFD;
2233 else if (strncmp (p, " .qn ", 5) == 0)
2234 basetype = REG_TYPE_NQ;
2235 else
c921be7d 2236 return FALSE;
5f4273c7 2237
dcbf9037 2238 p += 5;
5f4273c7 2239
dcbf9037 2240 if (*p == '\0')
c921be7d 2241 return FALSE;
5f4273c7 2242
dcbf9037
JB
2243 basereg = arm_reg_parse_multi (&p);
2244
2245 if (basereg && basereg->type != basetype)
2246 {
2247 as_bad (_("bad type for register"));
c921be7d 2248 return FALSE;
dcbf9037
JB
2249 }
2250
2251 if (basereg == NULL)
2252 {
2253 expressionS exp;
2254 /* Try parsing as an integer. */
2255 my_get_expression (&exp, &p, GE_NO_PREFIX);
2256 if (exp.X_op != O_constant)
2257 {
2258 as_bad (_("expression must be constant"));
c921be7d 2259 return FALSE;
dcbf9037
JB
2260 }
2261 basereg = &mybasereg;
2262 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2263 : exp.X_add_number;
2264 basereg->neon = 0;
2265 }
2266
2267 if (basereg->neon)
2268 typeinfo = *basereg->neon;
2269
2270 if (parse_neon_type (&ntype, &p) == SUCCESS)
2271 {
2272 /* We got a type. */
2273 if (typeinfo.defined & NTA_HASTYPE)
2274 {
2275 as_bad (_("can't redefine the type of a register alias"));
c921be7d 2276 return FALSE;
dcbf9037 2277 }
5f4273c7 2278
dcbf9037
JB
2279 typeinfo.defined |= NTA_HASTYPE;
2280 if (ntype.elems != 1)
2281 {
2282 as_bad (_("you must specify a single type only"));
c921be7d 2283 return FALSE;
dcbf9037
JB
2284 }
2285 typeinfo.eltype = ntype.el[0];
2286 }
5f4273c7 2287
dcbf9037
JB
2288 if (skip_past_char (&p, '[') == SUCCESS)
2289 {
2290 expressionS exp;
2291 /* We got a scalar index. */
5f4273c7 2292
dcbf9037
JB
2293 if (typeinfo.defined & NTA_HASINDEX)
2294 {
2295 as_bad (_("can't redefine the index of a scalar alias"));
c921be7d 2296 return FALSE;
dcbf9037 2297 }
5f4273c7 2298
dcbf9037 2299 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2300
dcbf9037
JB
2301 if (exp.X_op != O_constant)
2302 {
2303 as_bad (_("scalar index must be constant"));
c921be7d 2304 return FALSE;
dcbf9037 2305 }
5f4273c7 2306
dcbf9037
JB
2307 typeinfo.defined |= NTA_HASINDEX;
2308 typeinfo.index = exp.X_add_number;
5f4273c7 2309
dcbf9037
JB
2310 if (skip_past_char (&p, ']') == FAIL)
2311 {
2312 as_bad (_("expecting ]"));
c921be7d 2313 return FALSE;
dcbf9037
JB
2314 }
2315 }
2316
15735687
NS
2317 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2318 the desired alias name, and p points to its end. If not, then
2319 the desired alias name is in the global original_case_string. */
2320#ifdef TC_CASE_SENSITIVE
dcbf9037 2321 namelen = nameend - newname;
15735687
NS
2322#else
2323 newname = original_case_string;
2324 namelen = strlen (newname);
2325#endif
2326
21d799b5 2327 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2328 strncpy (namebuf, newname, namelen);
2329 namebuf[namelen] = '\0';
5f4273c7 2330
dcbf9037
JB
2331 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2332 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2333
dcbf9037
JB
2334 /* Insert name in all uppercase. */
2335 for (p = namebuf; *p; p++)
2336 *p = TOUPPER (*p);
5f4273c7 2337
dcbf9037
JB
2338 if (strncmp (namebuf, newname, namelen))
2339 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2340 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2341
dcbf9037
JB
2342 /* Insert name in all lowercase. */
2343 for (p = namebuf; *p; p++)
2344 *p = TOLOWER (*p);
5f4273c7 2345
dcbf9037
JB
2346 if (strncmp (namebuf, newname, namelen))
2347 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2348 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2349
c921be7d 2350 return TRUE;
dcbf9037
JB
2351}
2352
c19d1205
ZW
2353/* Should never be called, as .req goes between the alias and the
2354 register name, not at the beginning of the line. */
c921be7d 2355
b99bd4ef 2356static void
c19d1205 2357s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2358{
c19d1205
ZW
2359 as_bad (_("invalid syntax for .req directive"));
2360}
b99bd4ef 2361
dcbf9037
JB
2362static void
2363s_dn (int a ATTRIBUTE_UNUSED)
2364{
2365 as_bad (_("invalid syntax for .dn directive"));
2366}
2367
2368static void
2369s_qn (int a ATTRIBUTE_UNUSED)
2370{
2371 as_bad (_("invalid syntax for .qn directive"));
2372}
2373
c19d1205
ZW
2374/* The .unreq directive deletes an alias which was previously defined
2375 by .req. For example:
b99bd4ef 2376
c19d1205
ZW
2377 my_alias .req r11
2378 .unreq my_alias */
b99bd4ef
NC
2379
2380static void
c19d1205 2381s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2382{
c19d1205
ZW
2383 char * name;
2384 char saved_char;
b99bd4ef 2385
c19d1205
ZW
2386 name = input_line_pointer;
2387
2388 while (*input_line_pointer != 0
2389 && *input_line_pointer != ' '
2390 && *input_line_pointer != '\n')
2391 ++input_line_pointer;
2392
2393 saved_char = *input_line_pointer;
2394 *input_line_pointer = 0;
2395
2396 if (!*name)
2397 as_bad (_("invalid syntax for .unreq directive"));
2398 else
2399 {
21d799b5
NC
2400 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2401 name);
c19d1205
ZW
2402
2403 if (!reg)
2404 as_bad (_("unknown register alias '%s'"), name);
2405 else if (reg->builtin)
2406 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2407 name);
2408 else
2409 {
d929913e
NC
2410 char * p;
2411 char * nbuf;
2412
db0bc284 2413 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2414 free ((char *) reg->name);
dcbf9037
JB
2415 if (reg->neon)
2416 free (reg->neon);
c19d1205 2417 free (reg);
d929913e
NC
2418
2419 /* Also locate the all upper case and all lower case versions.
2420 Do not complain if we cannot find one or the other as it
2421 was probably deleted above. */
5f4273c7 2422
d929913e
NC
2423 nbuf = strdup (name);
2424 for (p = nbuf; *p; p++)
2425 *p = TOUPPER (*p);
21d799b5 2426 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2427 if (reg)
2428 {
db0bc284 2429 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2430 free ((char *) reg->name);
2431 if (reg->neon)
2432 free (reg->neon);
2433 free (reg);
2434 }
2435
2436 for (p = nbuf; *p; p++)
2437 *p = TOLOWER (*p);
21d799b5 2438 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2439 if (reg)
2440 {
db0bc284 2441 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2442 free ((char *) reg->name);
2443 if (reg->neon)
2444 free (reg->neon);
2445 free (reg);
2446 }
2447
2448 free (nbuf);
c19d1205
ZW
2449 }
2450 }
b99bd4ef 2451
c19d1205 2452 *input_line_pointer = saved_char;
b99bd4ef
NC
2453 demand_empty_rest_of_line ();
2454}
2455
c19d1205
ZW
2456/* Directives: Instruction set selection. */
2457
2458#ifdef OBJ_ELF
2459/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2460 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2461 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2462 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2463
cd000bff
DJ
2464/* Create a new mapping symbol for the transition to STATE. */
2465
2466static void
2467make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2468{
a737bd4d 2469 symbolS * symbolP;
c19d1205
ZW
2470 const char * symname;
2471 int type;
b99bd4ef 2472
c19d1205 2473 switch (state)
b99bd4ef 2474 {
c19d1205
ZW
2475 case MAP_DATA:
2476 symname = "$d";
2477 type = BSF_NO_FLAGS;
2478 break;
2479 case MAP_ARM:
2480 symname = "$a";
2481 type = BSF_NO_FLAGS;
2482 break;
2483 case MAP_THUMB:
2484 symname = "$t";
2485 type = BSF_NO_FLAGS;
2486 break;
c19d1205
ZW
2487 default:
2488 abort ();
2489 }
2490
cd000bff 2491 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2492 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2493
2494 switch (state)
2495 {
2496 case MAP_ARM:
2497 THUMB_SET_FUNC (symbolP, 0);
2498 ARM_SET_THUMB (symbolP, 0);
2499 ARM_SET_INTERWORK (symbolP, support_interwork);
2500 break;
2501
2502 case MAP_THUMB:
2503 THUMB_SET_FUNC (symbolP, 1);
2504 ARM_SET_THUMB (symbolP, 1);
2505 ARM_SET_INTERWORK (symbolP, support_interwork);
2506 break;
2507
2508 case MAP_DATA:
2509 default:
cd000bff
DJ
2510 break;
2511 }
2512
2513 /* Save the mapping symbols for future reference. Also check that
2514 we do not place two mapping symbols at the same offset within a
2515 frag. We'll handle overlap between frags in
2de7820f
JZ
2516 check_mapping_symbols.
2517
2518 If .fill or other data filling directive generates zero sized data,
2519 the mapping symbol for the following code will have the same value
2520 as the one generated for the data filling directive. In this case,
2521 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2522 if (value == 0)
2523 {
2de7820f
JZ
2524 if (frag->tc_frag_data.first_map != NULL)
2525 {
2526 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2527 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2528 }
cd000bff
DJ
2529 frag->tc_frag_data.first_map = symbolP;
2530 }
2531 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2532 {
2533 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2534 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2535 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2536 }
cd000bff
DJ
2537 frag->tc_frag_data.last_map = symbolP;
2538}
2539
2540/* We must sometimes convert a region marked as code to data during
2541 code alignment, if an odd number of bytes have to be padded. The
2542 code mapping symbol is pushed to an aligned address. */
2543
2544static void
2545insert_data_mapping_symbol (enum mstate state,
2546 valueT value, fragS *frag, offsetT bytes)
2547{
2548 /* If there was already a mapping symbol, remove it. */
2549 if (frag->tc_frag_data.last_map != NULL
2550 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2551 {
2552 symbolS *symp = frag->tc_frag_data.last_map;
2553
2554 if (value == 0)
2555 {
2556 know (frag->tc_frag_data.first_map == symp);
2557 frag->tc_frag_data.first_map = NULL;
2558 }
2559 frag->tc_frag_data.last_map = NULL;
2560 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2561 }
cd000bff
DJ
2562
2563 make_mapping_symbol (MAP_DATA, value, frag);
2564 make_mapping_symbol (state, value + bytes, frag);
2565}
2566
2567static void mapping_state_2 (enum mstate state, int max_chars);
2568
2569/* Set the mapping state to STATE. Only call this when about to
2570 emit some STATE bytes to the file. */
2571
2572void
2573mapping_state (enum mstate state)
2574{
940b5ce0
DJ
2575 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2576
cd000bff
DJ
2577#define TRANSITION(from, to) (mapstate == (from) && state == (to))
2578
2579 if (mapstate == state)
2580 /* The mapping symbol has already been emitted.
2581 There is nothing else to do. */
2582 return;
2583 else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2584 /* This case will be evaluated later in the next else. */
2585 return;
2586 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2587 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2588 {
2589 /* Only add the symbol if the offset is > 0:
2590 if we're at the first frag, check it's size > 0;
2591 if we're not at the first frag, then for sure
2592 the offset is > 0. */
2593 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2594 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2595
2596 if (add_symbol)
2597 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2598 }
2599
2600 mapping_state_2 (state, 0);
2601#undef TRANSITION
2602}
2603
2604/* Same as mapping_state, but MAX_CHARS bytes have already been
2605 allocated. Put the mapping symbol that far back. */
2606
2607static void
2608mapping_state_2 (enum mstate state, int max_chars)
2609{
940b5ce0
DJ
2610 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2611
2612 if (!SEG_NORMAL (now_seg))
2613 return;
2614
cd000bff
DJ
2615 if (mapstate == state)
2616 /* The mapping symbol has already been emitted.
2617 There is nothing else to do. */
2618 return;
2619
cd000bff
DJ
2620 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2621 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205
ZW
2622}
2623#else
d3106081
NS
2624#define mapping_state(x) ((void)0)
2625#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2626#endif
2627
2628/* Find the real, Thumb encoded start of a Thumb function. */
2629
4343666d 2630#ifdef OBJ_COFF
c19d1205
ZW
2631static symbolS *
2632find_real_start (symbolS * symbolP)
2633{
2634 char * real_start;
2635 const char * name = S_GET_NAME (symbolP);
2636 symbolS * new_target;
2637
2638 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2639#define STUB_NAME ".real_start_of"
2640
2641 if (name == NULL)
2642 abort ();
2643
37f6032b
ZW
2644 /* The compiler may generate BL instructions to local labels because
2645 it needs to perform a branch to a far away location. These labels
2646 do not have a corresponding ".real_start_of" label. We check
2647 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2648 the ".real_start_of" convention for nonlocal branches. */
2649 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2650 return symbolP;
2651
37f6032b 2652 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2653 new_target = symbol_find (real_start);
2654
2655 if (new_target == NULL)
2656 {
bd3ba5d1 2657 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2658 new_target = symbolP;
2659 }
2660
c19d1205
ZW
2661 return new_target;
2662}
4343666d 2663#endif
c19d1205
ZW
2664
2665static void
2666opcode_select (int width)
2667{
2668 switch (width)
2669 {
2670 case 16:
2671 if (! thumb_mode)
2672 {
e74cfd16 2673 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2674 as_bad (_("selected processor does not support THUMB opcodes"));
2675
2676 thumb_mode = 1;
2677 /* No need to force the alignment, since we will have been
2678 coming from ARM mode, which is word-aligned. */
2679 record_alignment (now_seg, 1);
2680 }
c19d1205
ZW
2681 break;
2682
2683 case 32:
2684 if (thumb_mode)
2685 {
e74cfd16 2686 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2687 as_bad (_("selected processor does not support ARM opcodes"));
2688
2689 thumb_mode = 0;
2690
2691 if (!need_pass_2)
2692 frag_align (2, 0, 0);
2693
2694 record_alignment (now_seg, 1);
2695 }
c19d1205
ZW
2696 break;
2697
2698 default:
2699 as_bad (_("invalid instruction size selected (%d)"), width);
2700 }
2701}
2702
2703static void
2704s_arm (int ignore ATTRIBUTE_UNUSED)
2705{
2706 opcode_select (32);
2707 demand_empty_rest_of_line ();
2708}
2709
2710static void
2711s_thumb (int ignore ATTRIBUTE_UNUSED)
2712{
2713 opcode_select (16);
2714 demand_empty_rest_of_line ();
2715}
2716
2717static void
2718s_code (int unused ATTRIBUTE_UNUSED)
2719{
2720 int temp;
2721
2722 temp = get_absolute_expression ();
2723 switch (temp)
2724 {
2725 case 16:
2726 case 32:
2727 opcode_select (temp);
2728 break;
2729
2730 default:
2731 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2732 }
2733}
2734
2735static void
2736s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2737{
2738 /* If we are not already in thumb mode go into it, EVEN if
2739 the target processor does not support thumb instructions.
2740 This is used by gcc/config/arm/lib1funcs.asm for example
2741 to compile interworking support functions even if the
2742 target processor should not support interworking. */
2743 if (! thumb_mode)
2744 {
2745 thumb_mode = 2;
2746 record_alignment (now_seg, 1);
2747 }
2748
2749 demand_empty_rest_of_line ();
2750}
2751
2752static void
2753s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2754{
2755 s_thumb (0);
2756
2757 /* The following label is the name/address of the start of a Thumb function.
2758 We need to know this for the interworking support. */
2759 label_is_thumb_function_name = TRUE;
2760}
2761
2762/* Perform a .set directive, but also mark the alias as
2763 being a thumb function. */
2764
2765static void
2766s_thumb_set (int equiv)
2767{
2768 /* XXX the following is a duplicate of the code for s_set() in read.c
2769 We cannot just call that code as we need to get at the symbol that
2770 is created. */
2771 char * name;
2772 char delim;
2773 char * end_name;
2774 symbolS * symbolP;
2775
2776 /* Especial apologies for the random logic:
2777 This just grew, and could be parsed much more simply!
2778 Dean - in haste. */
2779 name = input_line_pointer;
2780 delim = get_symbol_end ();
2781 end_name = input_line_pointer;
2782 *end_name = delim;
2783
2784 if (*input_line_pointer != ',')
2785 {
2786 *end_name = 0;
2787 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2788 *end_name = delim;
2789 ignore_rest_of_line ();
2790 return;
2791 }
2792
2793 input_line_pointer++;
2794 *end_name = 0;
2795
2796 if (name[0] == '.' && name[1] == '\0')
2797 {
2798 /* XXX - this should not happen to .thumb_set. */
2799 abort ();
2800 }
2801
2802 if ((symbolP = symbol_find (name)) == NULL
2803 && (symbolP = md_undefined_symbol (name)) == NULL)
2804 {
2805#ifndef NO_LISTING
2806 /* When doing symbol listings, play games with dummy fragments living
2807 outside the normal fragment chain to record the file and line info
c19d1205 2808 for this symbol. */
b99bd4ef
NC
2809 if (listing & LISTING_SYMBOLS)
2810 {
2811 extern struct list_info_struct * listing_tail;
21d799b5 2812 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2813
2814 memset (dummy_frag, 0, sizeof (fragS));
2815 dummy_frag->fr_type = rs_fill;
2816 dummy_frag->line = listing_tail;
2817 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2818 dummy_frag->fr_symbol = symbolP;
2819 }
2820 else
2821#endif
2822 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2823
2824#ifdef OBJ_COFF
2825 /* "set" symbols are local unless otherwise specified. */
2826 SF_SET_LOCAL (symbolP);
2827#endif /* OBJ_COFF */
2828 } /* Make a new symbol. */
2829
2830 symbol_table_insert (symbolP);
2831
2832 * end_name = delim;
2833
2834 if (equiv
2835 && S_IS_DEFINED (symbolP)
2836 && S_GET_SEGMENT (symbolP) != reg_section)
2837 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2838
2839 pseudo_set (symbolP);
2840
2841 demand_empty_rest_of_line ();
2842
c19d1205 2843 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2844
2845 THUMB_SET_FUNC (symbolP, 1);
2846 ARM_SET_THUMB (symbolP, 1);
2847#if defined OBJ_ELF || defined OBJ_COFF
2848 ARM_SET_INTERWORK (symbolP, support_interwork);
2849#endif
2850}
2851
c19d1205 2852/* Directives: Mode selection. */
b99bd4ef 2853
c19d1205
ZW
2854/* .syntax [unified|divided] - choose the new unified syntax
2855 (same for Arm and Thumb encoding, modulo slight differences in what
2856 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2857static void
c19d1205 2858s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2859{
c19d1205
ZW
2860 char *name, delim;
2861
2862 name = input_line_pointer;
2863 delim = get_symbol_end ();
2864
2865 if (!strcasecmp (name, "unified"))
2866 unified_syntax = TRUE;
2867 else if (!strcasecmp (name, "divided"))
2868 unified_syntax = FALSE;
2869 else
2870 {
2871 as_bad (_("unrecognized syntax mode \"%s\""), name);
2872 return;
2873 }
2874 *input_line_pointer = delim;
b99bd4ef
NC
2875 demand_empty_rest_of_line ();
2876}
2877
c19d1205
ZW
2878/* Directives: sectioning and alignment. */
2879
2880/* Same as s_align_ptwo but align 0 => align 2. */
2881
b99bd4ef 2882static void
c19d1205 2883s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2884{
a737bd4d 2885 int temp;
dce323d1 2886 bfd_boolean fill_p;
c19d1205
ZW
2887 long temp_fill;
2888 long max_alignment = 15;
b99bd4ef
NC
2889
2890 temp = get_absolute_expression ();
c19d1205
ZW
2891 if (temp > max_alignment)
2892 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2893 else if (temp < 0)
b99bd4ef 2894 {
c19d1205
ZW
2895 as_bad (_("alignment negative. 0 assumed."));
2896 temp = 0;
2897 }
b99bd4ef 2898
c19d1205
ZW
2899 if (*input_line_pointer == ',')
2900 {
2901 input_line_pointer++;
2902 temp_fill = get_absolute_expression ();
dce323d1 2903 fill_p = TRUE;
b99bd4ef 2904 }
c19d1205 2905 else
dce323d1
PB
2906 {
2907 fill_p = FALSE;
2908 temp_fill = 0;
2909 }
b99bd4ef 2910
c19d1205
ZW
2911 if (!temp)
2912 temp = 2;
b99bd4ef 2913
c19d1205
ZW
2914 /* Only make a frag if we HAVE to. */
2915 if (temp && !need_pass_2)
dce323d1
PB
2916 {
2917 if (!fill_p && subseg_text_p (now_seg))
2918 frag_align_code (temp, 0);
2919 else
2920 frag_align (temp, (int) temp_fill, 0);
2921 }
c19d1205
ZW
2922 demand_empty_rest_of_line ();
2923
2924 record_alignment (now_seg, temp);
b99bd4ef
NC
2925}
2926
c19d1205
ZW
2927static void
2928s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2929{
c19d1205
ZW
2930 /* We don't support putting frags in the BSS segment, we fake it by
2931 marking in_bss, then looking at s_skip for clues. */
2932 subseg_set (bss_section, 0);
2933 demand_empty_rest_of_line ();
cd000bff
DJ
2934
2935#ifdef md_elf_section_change_hook
2936 md_elf_section_change_hook ();
2937#endif
c19d1205 2938}
b99bd4ef 2939
c19d1205
ZW
2940static void
2941s_even (int ignore ATTRIBUTE_UNUSED)
2942{
2943 /* Never make frag if expect extra pass. */
2944 if (!need_pass_2)
2945 frag_align (1, 0, 0);
b99bd4ef 2946
c19d1205 2947 record_alignment (now_seg, 1);
b99bd4ef 2948
c19d1205 2949 demand_empty_rest_of_line ();
b99bd4ef
NC
2950}
2951
c19d1205 2952/* Directives: Literal pools. */
a737bd4d 2953
c19d1205
ZW
2954static literal_pool *
2955find_literal_pool (void)
a737bd4d 2956{
c19d1205 2957 literal_pool * pool;
a737bd4d 2958
c19d1205 2959 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2960 {
c19d1205
ZW
2961 if (pool->section == now_seg
2962 && pool->sub_section == now_subseg)
2963 break;
a737bd4d
NC
2964 }
2965
c19d1205 2966 return pool;
a737bd4d
NC
2967}
2968
c19d1205
ZW
2969static literal_pool *
2970find_or_make_literal_pool (void)
a737bd4d 2971{
c19d1205
ZW
2972 /* Next literal pool ID number. */
2973 static unsigned int latest_pool_num = 1;
2974 literal_pool * pool;
a737bd4d 2975
c19d1205 2976 pool = find_literal_pool ();
a737bd4d 2977
c19d1205 2978 if (pool == NULL)
a737bd4d 2979 {
c19d1205 2980 /* Create a new pool. */
21d799b5 2981 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
2982 if (! pool)
2983 return NULL;
a737bd4d 2984
c19d1205
ZW
2985 pool->next_free_entry = 0;
2986 pool->section = now_seg;
2987 pool->sub_section = now_subseg;
2988 pool->next = list_of_pools;
2989 pool->symbol = NULL;
2990
2991 /* Add it to the list. */
2992 list_of_pools = pool;
a737bd4d 2993 }
a737bd4d 2994
c19d1205
ZW
2995 /* New pools, and emptied pools, will have a NULL symbol. */
2996 if (pool->symbol == NULL)
a737bd4d 2997 {
c19d1205
ZW
2998 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2999 (valueT) 0, &zero_address_frag);
3000 pool->id = latest_pool_num ++;
a737bd4d
NC
3001 }
3002
c19d1205
ZW
3003 /* Done. */
3004 return pool;
a737bd4d
NC
3005}
3006
c19d1205 3007/* Add the literal in the global 'inst'
5f4273c7 3008 structure to the relevant literal pool. */
b99bd4ef
NC
3009
3010static int
c19d1205 3011add_to_lit_pool (void)
b99bd4ef 3012{
c19d1205
ZW
3013 literal_pool * pool;
3014 unsigned int entry;
b99bd4ef 3015
c19d1205
ZW
3016 pool = find_or_make_literal_pool ();
3017
3018 /* Check if this literal value is already in the pool. */
3019 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3020 {
c19d1205
ZW
3021 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3022 && (inst.reloc.exp.X_op == O_constant)
3023 && (pool->literals[entry].X_add_number
3024 == inst.reloc.exp.X_add_number)
3025 && (pool->literals[entry].X_unsigned
3026 == inst.reloc.exp.X_unsigned))
3027 break;
3028
3029 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3030 && (inst.reloc.exp.X_op == O_symbol)
3031 && (pool->literals[entry].X_add_number
3032 == inst.reloc.exp.X_add_number)
3033 && (pool->literals[entry].X_add_symbol
3034 == inst.reloc.exp.X_add_symbol)
3035 && (pool->literals[entry].X_op_symbol
3036 == inst.reloc.exp.X_op_symbol))
3037 break;
b99bd4ef
NC
3038 }
3039
c19d1205
ZW
3040 /* Do we need to create a new entry? */
3041 if (entry == pool->next_free_entry)
3042 {
3043 if (entry >= MAX_LITERAL_POOL_SIZE)
3044 {
3045 inst.error = _("literal pool overflow");
3046 return FAIL;
3047 }
3048
3049 pool->literals[entry] = inst.reloc.exp;
3050 pool->next_free_entry += 1;
3051 }
b99bd4ef 3052
c19d1205
ZW
3053 inst.reloc.exp.X_op = O_symbol;
3054 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3055 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3056
c19d1205 3057 return SUCCESS;
b99bd4ef
NC
3058}
3059
c19d1205
ZW
3060/* Can't use symbol_new here, so have to create a symbol and then at
3061 a later date assign it a value. Thats what these functions do. */
e16bb312 3062
c19d1205
ZW
3063static void
3064symbol_locate (symbolS * symbolP,
3065 const char * name, /* It is copied, the caller can modify. */
3066 segT segment, /* Segment identifier (SEG_<something>). */
3067 valueT valu, /* Symbol value. */
3068 fragS * frag) /* Associated fragment. */
3069{
3070 unsigned int name_length;
3071 char * preserved_copy_of_name;
e16bb312 3072
c19d1205
ZW
3073 name_length = strlen (name) + 1; /* +1 for \0. */
3074 obstack_grow (&notes, name, name_length);
21d799b5 3075 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3076
c19d1205
ZW
3077#ifdef tc_canonicalize_symbol_name
3078 preserved_copy_of_name =
3079 tc_canonicalize_symbol_name (preserved_copy_of_name);
3080#endif
b99bd4ef 3081
c19d1205 3082 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3083
c19d1205
ZW
3084 S_SET_SEGMENT (symbolP, segment);
3085 S_SET_VALUE (symbolP, valu);
3086 symbol_clear_list_pointers (symbolP);
b99bd4ef 3087
c19d1205 3088 symbol_set_frag (symbolP, frag);
b99bd4ef 3089
c19d1205
ZW
3090 /* Link to end of symbol chain. */
3091 {
3092 extern int symbol_table_frozen;
b99bd4ef 3093
c19d1205
ZW
3094 if (symbol_table_frozen)
3095 abort ();
3096 }
b99bd4ef 3097
c19d1205 3098 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3099
c19d1205 3100 obj_symbol_new_hook (symbolP);
b99bd4ef 3101
c19d1205
ZW
3102#ifdef tc_symbol_new_hook
3103 tc_symbol_new_hook (symbolP);
3104#endif
3105
3106#ifdef DEBUG_SYMS
3107 verify_symbol_chain (symbol_rootP, symbol_lastP);
3108#endif /* DEBUG_SYMS */
b99bd4ef
NC
3109}
3110
b99bd4ef 3111
c19d1205
ZW
3112static void
3113s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3114{
c19d1205
ZW
3115 unsigned int entry;
3116 literal_pool * pool;
3117 char sym_name[20];
b99bd4ef 3118
c19d1205
ZW
3119 pool = find_literal_pool ();
3120 if (pool == NULL
3121 || pool->symbol == NULL
3122 || pool->next_free_entry == 0)
3123 return;
b99bd4ef 3124
c19d1205 3125 mapping_state (MAP_DATA);
b99bd4ef 3126
c19d1205
ZW
3127 /* Align pool as you have word accesses.
3128 Only make a frag if we have to. */
3129 if (!need_pass_2)
3130 frag_align (2, 0, 0);
b99bd4ef 3131
c19d1205 3132 record_alignment (now_seg, 2);
b99bd4ef 3133
c19d1205 3134 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3135
c19d1205
ZW
3136 symbol_locate (pool->symbol, sym_name, now_seg,
3137 (valueT) frag_now_fix (), frag_now);
3138 symbol_table_insert (pool->symbol);
b99bd4ef 3139
c19d1205 3140 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3141
c19d1205
ZW
3142#if defined OBJ_COFF || defined OBJ_ELF
3143 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3144#endif
6c43fab6 3145
c19d1205
ZW
3146 for (entry = 0; entry < pool->next_free_entry; entry ++)
3147 /* First output the expression in the instruction to the pool. */
3148 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 3149
c19d1205
ZW
3150 /* Mark the pool as empty. */
3151 pool->next_free_entry = 0;
3152 pool->symbol = NULL;
b99bd4ef
NC
3153}
3154
c19d1205
ZW
3155#ifdef OBJ_ELF
3156/* Forward declarations for functions below, in the MD interface
3157 section. */
3158static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3159static valueT create_unwind_entry (int);
3160static void start_unwind_section (const segT, int);
3161static void add_unwind_opcode (valueT, int);
3162static void flush_pending_unwind (void);
b99bd4ef 3163
c19d1205 3164/* Directives: Data. */
b99bd4ef 3165
c19d1205
ZW
3166static void
3167s_arm_elf_cons (int nbytes)
3168{
3169 expressionS exp;
b99bd4ef 3170
c19d1205
ZW
3171#ifdef md_flush_pending_output
3172 md_flush_pending_output ();
3173#endif
b99bd4ef 3174
c19d1205 3175 if (is_it_end_of_statement ())
b99bd4ef 3176 {
c19d1205
ZW
3177 demand_empty_rest_of_line ();
3178 return;
b99bd4ef
NC
3179 }
3180
c19d1205
ZW
3181#ifdef md_cons_align
3182 md_cons_align (nbytes);
3183#endif
b99bd4ef 3184
c19d1205
ZW
3185 mapping_state (MAP_DATA);
3186 do
b99bd4ef 3187 {
c19d1205
ZW
3188 int reloc;
3189 char *base = input_line_pointer;
b99bd4ef 3190
c19d1205 3191 expression (& exp);
b99bd4ef 3192
c19d1205
ZW
3193 if (exp.X_op != O_symbol)
3194 emit_expr (&exp, (unsigned int) nbytes);
3195 else
3196 {
3197 char *before_reloc = input_line_pointer;
3198 reloc = parse_reloc (&input_line_pointer);
3199 if (reloc == -1)
3200 {
3201 as_bad (_("unrecognized relocation suffix"));
3202 ignore_rest_of_line ();
3203 return;
3204 }
3205 else if (reloc == BFD_RELOC_UNUSED)
3206 emit_expr (&exp, (unsigned int) nbytes);
3207 else
3208 {
21d799b5
NC
3209 reloc_howto_type *howto = (reloc_howto_type *)
3210 bfd_reloc_type_lookup (stdoutput,
3211 (bfd_reloc_code_real_type) reloc);
c19d1205 3212 int size = bfd_get_reloc_size (howto);
b99bd4ef 3213
2fc8bdac
ZW
3214 if (reloc == BFD_RELOC_ARM_PLT32)
3215 {
3216 as_bad (_("(plt) is only valid on branch targets"));
3217 reloc = BFD_RELOC_UNUSED;
3218 size = 0;
3219 }
3220
c19d1205 3221 if (size > nbytes)
2fc8bdac 3222 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3223 howto->name, nbytes);
3224 else
3225 {
3226 /* We've parsed an expression stopping at O_symbol.
3227 But there may be more expression left now that we
3228 have parsed the relocation marker. Parse it again.
3229 XXX Surely there is a cleaner way to do this. */
3230 char *p = input_line_pointer;
3231 int offset;
21d799b5 3232 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3233 memcpy (save_buf, base, input_line_pointer - base);
3234 memmove (base + (input_line_pointer - before_reloc),
3235 base, before_reloc - base);
3236
3237 input_line_pointer = base + (input_line_pointer-before_reloc);
3238 expression (&exp);
3239 memcpy (base, save_buf, p - base);
3240
3241 offset = nbytes - size;
3242 p = frag_more ((int) nbytes);
3243 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3244 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3245 }
3246 }
3247 }
b99bd4ef 3248 }
c19d1205 3249 while (*input_line_pointer++ == ',');
b99bd4ef 3250
c19d1205
ZW
3251 /* Put terminator back into stream. */
3252 input_line_pointer --;
3253 demand_empty_rest_of_line ();
b99bd4ef
NC
3254}
3255
c921be7d
NC
3256/* Emit an expression containing a 32-bit thumb instruction.
3257 Implementation based on put_thumb32_insn. */
3258
3259static void
3260emit_thumb32_expr (expressionS * exp)
3261{
3262 expressionS exp_high = *exp;
3263
3264 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3265 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3266 exp->X_add_number &= 0xffff;
3267 emit_expr (exp, (unsigned int) THUMB_SIZE);
3268}
3269
3270/* Guess the instruction size based on the opcode. */
3271
3272static int
3273thumb_insn_size (int opcode)
3274{
3275 if ((unsigned int) opcode < 0xe800u)
3276 return 2;
3277 else if ((unsigned int) opcode >= 0xe8000000u)
3278 return 4;
3279 else
3280 return 0;
3281}
3282
3283static bfd_boolean
3284emit_insn (expressionS *exp, int nbytes)
3285{
3286 int size = 0;
3287
3288 if (exp->X_op == O_constant)
3289 {
3290 size = nbytes;
3291
3292 if (size == 0)
3293 size = thumb_insn_size (exp->X_add_number);
3294
3295 if (size != 0)
3296 {
3297 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3298 {
3299 as_bad (_(".inst.n operand too big. "\
3300 "Use .inst.w instead"));
3301 size = 0;
3302 }
3303 else
3304 {
3305 if (now_it.state == AUTOMATIC_IT_BLOCK)
3306 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3307 else
3308 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3309
3310 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3311 emit_thumb32_expr (exp);
3312 else
3313 emit_expr (exp, (unsigned int) size);
3314
3315 it_fsm_post_encode ();
3316 }
3317 }
3318 else
3319 as_bad (_("cannot determine Thumb instruction size. " \
3320 "Use .inst.n/.inst.w instead"));
3321 }
3322 else
3323 as_bad (_("constant expression required"));
3324
3325 return (size != 0);
3326}
3327
3328/* Like s_arm_elf_cons but do not use md_cons_align and
3329 set the mapping state to MAP_ARM/MAP_THUMB. */
3330
3331static void
3332s_arm_elf_inst (int nbytes)
3333{
3334 if (is_it_end_of_statement ())
3335 {
3336 demand_empty_rest_of_line ();
3337 return;
3338 }
3339
3340 /* Calling mapping_state () here will not change ARM/THUMB,
3341 but will ensure not to be in DATA state. */
3342
3343 if (thumb_mode)
3344 mapping_state (MAP_THUMB);
3345 else
3346 {
3347 if (nbytes != 0)
3348 {
3349 as_bad (_("width suffixes are invalid in ARM mode"));
3350 ignore_rest_of_line ();
3351 return;
3352 }
3353
3354 nbytes = 4;
3355
3356 mapping_state (MAP_ARM);
3357 }
3358
3359 do
3360 {
3361 expressionS exp;
3362
3363 expression (& exp);
3364
3365 if (! emit_insn (& exp, nbytes))
3366 {
3367 ignore_rest_of_line ();
3368 return;
3369 }
3370 }
3371 while (*input_line_pointer++ == ',');
3372
3373 /* Put terminator back into stream. */
3374 input_line_pointer --;
3375 demand_empty_rest_of_line ();
3376}
b99bd4ef 3377
c19d1205 3378/* Parse a .rel31 directive. */
b99bd4ef 3379
c19d1205
ZW
3380static void
3381s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3382{
3383 expressionS exp;
3384 char *p;
3385 valueT highbit;
b99bd4ef 3386
c19d1205
ZW
3387 highbit = 0;
3388 if (*input_line_pointer == '1')
3389 highbit = 0x80000000;
3390 else if (*input_line_pointer != '0')
3391 as_bad (_("expected 0 or 1"));
b99bd4ef 3392
c19d1205
ZW
3393 input_line_pointer++;
3394 if (*input_line_pointer != ',')
3395 as_bad (_("missing comma"));
3396 input_line_pointer++;
b99bd4ef 3397
c19d1205
ZW
3398#ifdef md_flush_pending_output
3399 md_flush_pending_output ();
3400#endif
b99bd4ef 3401
c19d1205
ZW
3402#ifdef md_cons_align
3403 md_cons_align (4);
3404#endif
b99bd4ef 3405
c19d1205 3406 mapping_state (MAP_DATA);
b99bd4ef 3407
c19d1205 3408 expression (&exp);
b99bd4ef 3409
c19d1205
ZW
3410 p = frag_more (4);
3411 md_number_to_chars (p, highbit, 4);
3412 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3413 BFD_RELOC_ARM_PREL31);
b99bd4ef 3414
c19d1205 3415 demand_empty_rest_of_line ();
b99bd4ef
NC
3416}
3417
c19d1205 3418/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3419
c19d1205 3420/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3421
c19d1205
ZW
3422static void
3423s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3424{
3425 demand_empty_rest_of_line ();
921e5f0a
PB
3426 if (unwind.proc_start)
3427 {
c921be7d 3428 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3429 return;
3430 }
3431
c19d1205
ZW
3432 /* Mark the start of the function. */
3433 unwind.proc_start = expr_build_dot ();
b99bd4ef 3434
c19d1205
ZW
3435 /* Reset the rest of the unwind info. */
3436 unwind.opcode_count = 0;
3437 unwind.table_entry = NULL;
3438 unwind.personality_routine = NULL;
3439 unwind.personality_index = -1;
3440 unwind.frame_size = 0;
3441 unwind.fp_offset = 0;
fdfde340 3442 unwind.fp_reg = REG_SP;
c19d1205
ZW
3443 unwind.fp_used = 0;
3444 unwind.sp_restored = 0;
3445}
b99bd4ef 3446
b99bd4ef 3447
c19d1205
ZW
3448/* Parse a handlerdata directive. Creates the exception handling table entry
3449 for the function. */
b99bd4ef 3450
c19d1205
ZW
3451static void
3452s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3453{
3454 demand_empty_rest_of_line ();
921e5f0a 3455 if (!unwind.proc_start)
c921be7d 3456 as_bad (MISSING_FNSTART);
921e5f0a 3457
c19d1205 3458 if (unwind.table_entry)
6decc662 3459 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3460
c19d1205
ZW
3461 create_unwind_entry (1);
3462}
a737bd4d 3463
c19d1205 3464/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3465
c19d1205
ZW
3466static void
3467s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3468{
3469 long where;
3470 char *ptr;
3471 valueT val;
940b5ce0 3472 unsigned int marked_pr_dependency;
f02232aa 3473
c19d1205 3474 demand_empty_rest_of_line ();
f02232aa 3475
921e5f0a
PB
3476 if (!unwind.proc_start)
3477 {
c921be7d 3478 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3479 return;
3480 }
3481
c19d1205
ZW
3482 /* Add eh table entry. */
3483 if (unwind.table_entry == NULL)
3484 val = create_unwind_entry (0);
3485 else
3486 val = 0;
f02232aa 3487
c19d1205
ZW
3488 /* Add index table entry. This is two words. */
3489 start_unwind_section (unwind.saved_seg, 1);
3490 frag_align (2, 0, 0);
3491 record_alignment (now_seg, 2);
b99bd4ef 3492
c19d1205
ZW
3493 ptr = frag_more (8);
3494 where = frag_now_fix () - 8;
f02232aa 3495
c19d1205
ZW
3496 /* Self relative offset of the function start. */
3497 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3498 BFD_RELOC_ARM_PREL31);
f02232aa 3499
c19d1205
ZW
3500 /* Indicate dependency on EHABI-defined personality routines to the
3501 linker, if it hasn't been done already. */
940b5ce0
DJ
3502 marked_pr_dependency
3503 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3504 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3505 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3506 {
5f4273c7
NC
3507 static const char *const name[] =
3508 {
3509 "__aeabi_unwind_cpp_pr0",
3510 "__aeabi_unwind_cpp_pr1",
3511 "__aeabi_unwind_cpp_pr2"
3512 };
c19d1205
ZW
3513 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3514 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3515 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3516 |= 1 << unwind.personality_index;
c19d1205 3517 }
f02232aa 3518
c19d1205
ZW
3519 if (val)
3520 /* Inline exception table entry. */
3521 md_number_to_chars (ptr + 4, val, 4);
3522 else
3523 /* Self relative offset of the table entry. */
3524 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3525 BFD_RELOC_ARM_PREL31);
f02232aa 3526
c19d1205
ZW
3527 /* Restore the original section. */
3528 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3529
3530 unwind.proc_start = NULL;
c19d1205 3531}
f02232aa 3532
f02232aa 3533
c19d1205 3534/* Parse an unwind_cantunwind directive. */
b99bd4ef 3535
c19d1205
ZW
3536static void
3537s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3538{
3539 demand_empty_rest_of_line ();
921e5f0a 3540 if (!unwind.proc_start)
c921be7d 3541 as_bad (MISSING_FNSTART);
921e5f0a 3542
c19d1205
ZW
3543 if (unwind.personality_routine || unwind.personality_index != -1)
3544 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3545
c19d1205
ZW
3546 unwind.personality_index = -2;
3547}
b99bd4ef 3548
b99bd4ef 3549
c19d1205 3550/* Parse a personalityindex directive. */
b99bd4ef 3551
c19d1205
ZW
3552static void
3553s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3554{
3555 expressionS exp;
b99bd4ef 3556
921e5f0a 3557 if (!unwind.proc_start)
c921be7d 3558 as_bad (MISSING_FNSTART);
921e5f0a 3559
c19d1205
ZW
3560 if (unwind.personality_routine || unwind.personality_index != -1)
3561 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3562
c19d1205 3563 expression (&exp);
b99bd4ef 3564
c19d1205
ZW
3565 if (exp.X_op != O_constant
3566 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3567 {
c19d1205
ZW
3568 as_bad (_("bad personality routine number"));
3569 ignore_rest_of_line ();
3570 return;
b99bd4ef
NC
3571 }
3572
c19d1205 3573 unwind.personality_index = exp.X_add_number;
b99bd4ef 3574
c19d1205
ZW
3575 demand_empty_rest_of_line ();
3576}
e16bb312 3577
e16bb312 3578
c19d1205 3579/* Parse a personality directive. */
e16bb312 3580
c19d1205
ZW
3581static void
3582s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3583{
3584 char *name, *p, c;
a737bd4d 3585
921e5f0a 3586 if (!unwind.proc_start)
c921be7d 3587 as_bad (MISSING_FNSTART);
921e5f0a 3588
c19d1205
ZW
3589 if (unwind.personality_routine || unwind.personality_index != -1)
3590 as_bad (_("duplicate .personality directive"));
a737bd4d 3591
c19d1205
ZW
3592 name = input_line_pointer;
3593 c = get_symbol_end ();
3594 p = input_line_pointer;
3595 unwind.personality_routine = symbol_find_or_make (name);
3596 *p = c;
3597 demand_empty_rest_of_line ();
3598}
e16bb312 3599
e16bb312 3600
c19d1205 3601/* Parse a directive saving core registers. */
e16bb312 3602
c19d1205
ZW
3603static void
3604s_arm_unwind_save_core (void)
e16bb312 3605{
c19d1205
ZW
3606 valueT op;
3607 long range;
3608 int n;
e16bb312 3609
c19d1205
ZW
3610 range = parse_reg_list (&input_line_pointer);
3611 if (range == FAIL)
e16bb312 3612 {
c19d1205
ZW
3613 as_bad (_("expected register list"));
3614 ignore_rest_of_line ();
3615 return;
3616 }
e16bb312 3617
c19d1205 3618 demand_empty_rest_of_line ();
e16bb312 3619
c19d1205
ZW
3620 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3621 into .unwind_save {..., sp...}. We aren't bothered about the value of
3622 ip because it is clobbered by calls. */
3623 if (unwind.sp_restored && unwind.fp_reg == 12
3624 && (range & 0x3000) == 0x1000)
3625 {
3626 unwind.opcode_count--;
3627 unwind.sp_restored = 0;
3628 range = (range | 0x2000) & ~0x1000;
3629 unwind.pending_offset = 0;
3630 }
e16bb312 3631
01ae4198
DJ
3632 /* Pop r4-r15. */
3633 if (range & 0xfff0)
c19d1205 3634 {
01ae4198
DJ
3635 /* See if we can use the short opcodes. These pop a block of up to 8
3636 registers starting with r4, plus maybe r14. */
3637 for (n = 0; n < 8; n++)
3638 {
3639 /* Break at the first non-saved register. */
3640 if ((range & (1 << (n + 4))) == 0)
3641 break;
3642 }
3643 /* See if there are any other bits set. */
3644 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3645 {
3646 /* Use the long form. */
3647 op = 0x8000 | ((range >> 4) & 0xfff);
3648 add_unwind_opcode (op, 2);
3649 }
0dd132b6 3650 else
01ae4198
DJ
3651 {
3652 /* Use the short form. */
3653 if (range & 0x4000)
3654 op = 0xa8; /* Pop r14. */
3655 else
3656 op = 0xa0; /* Do not pop r14. */
3657 op |= (n - 1);
3658 add_unwind_opcode (op, 1);
3659 }
c19d1205 3660 }
0dd132b6 3661
c19d1205
ZW
3662 /* Pop r0-r3. */
3663 if (range & 0xf)
3664 {
3665 op = 0xb100 | (range & 0xf);
3666 add_unwind_opcode (op, 2);
0dd132b6
NC
3667 }
3668
c19d1205
ZW
3669 /* Record the number of bytes pushed. */
3670 for (n = 0; n < 16; n++)
3671 {
3672 if (range & (1 << n))
3673 unwind.frame_size += 4;
3674 }
0dd132b6
NC
3675}
3676
c19d1205
ZW
3677
3678/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3679
3680static void
c19d1205 3681s_arm_unwind_save_fpa (int reg)
b99bd4ef 3682{
c19d1205
ZW
3683 expressionS exp;
3684 int num_regs;
3685 valueT op;
b99bd4ef 3686
c19d1205
ZW
3687 /* Get Number of registers to transfer. */
3688 if (skip_past_comma (&input_line_pointer) != FAIL)
3689 expression (&exp);
3690 else
3691 exp.X_op = O_illegal;
b99bd4ef 3692
c19d1205 3693 if (exp.X_op != O_constant)
b99bd4ef 3694 {
c19d1205
ZW
3695 as_bad (_("expected , <constant>"));
3696 ignore_rest_of_line ();
b99bd4ef
NC
3697 return;
3698 }
3699
c19d1205
ZW
3700 num_regs = exp.X_add_number;
3701
3702 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3703 {
c19d1205
ZW
3704 as_bad (_("number of registers must be in the range [1:4]"));
3705 ignore_rest_of_line ();
b99bd4ef
NC
3706 return;
3707 }
3708
c19d1205 3709 demand_empty_rest_of_line ();
b99bd4ef 3710
c19d1205
ZW
3711 if (reg == 4)
3712 {
3713 /* Short form. */
3714 op = 0xb4 | (num_regs - 1);
3715 add_unwind_opcode (op, 1);
3716 }
b99bd4ef
NC
3717 else
3718 {
c19d1205
ZW
3719 /* Long form. */
3720 op = 0xc800 | (reg << 4) | (num_regs - 1);
3721 add_unwind_opcode (op, 2);
b99bd4ef 3722 }
c19d1205 3723 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3724}
3725
c19d1205 3726
fa073d69
MS
3727/* Parse a directive saving VFP registers for ARMv6 and above. */
3728
3729static void
3730s_arm_unwind_save_vfp_armv6 (void)
3731{
3732 int count;
3733 unsigned int start;
3734 valueT op;
3735 int num_vfpv3_regs = 0;
3736 int num_regs_below_16;
3737
3738 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3739 if (count == FAIL)
3740 {
3741 as_bad (_("expected register list"));
3742 ignore_rest_of_line ();
3743 return;
3744 }
3745
3746 demand_empty_rest_of_line ();
3747
3748 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3749 than FSTMX/FLDMX-style ones). */
3750
3751 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3752 if (start >= 16)
3753 num_vfpv3_regs = count;
3754 else if (start + count > 16)
3755 num_vfpv3_regs = start + count - 16;
3756
3757 if (num_vfpv3_regs > 0)
3758 {
3759 int start_offset = start > 16 ? start - 16 : 0;
3760 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3761 add_unwind_opcode (op, 2);
3762 }
3763
3764 /* Generate opcode for registers numbered in the range 0 .. 15. */
3765 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3766 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3767 if (num_regs_below_16 > 0)
3768 {
3769 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3770 add_unwind_opcode (op, 2);
3771 }
3772
3773 unwind.frame_size += count * 8;
3774}
3775
3776
3777/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3778
3779static void
c19d1205 3780s_arm_unwind_save_vfp (void)
b99bd4ef 3781{
c19d1205 3782 int count;
ca3f61f7 3783 unsigned int reg;
c19d1205 3784 valueT op;
b99bd4ef 3785
5287ad62 3786 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3787 if (count == FAIL)
b99bd4ef 3788 {
c19d1205
ZW
3789 as_bad (_("expected register list"));
3790 ignore_rest_of_line ();
b99bd4ef
NC
3791 return;
3792 }
3793
c19d1205 3794 demand_empty_rest_of_line ();
b99bd4ef 3795
c19d1205 3796 if (reg == 8)
b99bd4ef 3797 {
c19d1205
ZW
3798 /* Short form. */
3799 op = 0xb8 | (count - 1);
3800 add_unwind_opcode (op, 1);
b99bd4ef 3801 }
c19d1205 3802 else
b99bd4ef 3803 {
c19d1205
ZW
3804 /* Long form. */
3805 op = 0xb300 | (reg << 4) | (count - 1);
3806 add_unwind_opcode (op, 2);
b99bd4ef 3807 }
c19d1205
ZW
3808 unwind.frame_size += count * 8 + 4;
3809}
b99bd4ef 3810
b99bd4ef 3811
c19d1205
ZW
3812/* Parse a directive saving iWMMXt data registers. */
3813
3814static void
3815s_arm_unwind_save_mmxwr (void)
3816{
3817 int reg;
3818 int hi_reg;
3819 int i;
3820 unsigned mask = 0;
3821 valueT op;
b99bd4ef 3822
c19d1205
ZW
3823 if (*input_line_pointer == '{')
3824 input_line_pointer++;
b99bd4ef 3825
c19d1205 3826 do
b99bd4ef 3827 {
dcbf9037 3828 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3829
c19d1205 3830 if (reg == FAIL)
b99bd4ef 3831 {
9b7132d3 3832 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3833 goto error;
b99bd4ef
NC
3834 }
3835
c19d1205
ZW
3836 if (mask >> reg)
3837 as_tsktsk (_("register list not in ascending order"));
3838 mask |= 1 << reg;
b99bd4ef 3839
c19d1205
ZW
3840 if (*input_line_pointer == '-')
3841 {
3842 input_line_pointer++;
dcbf9037 3843 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3844 if (hi_reg == FAIL)
3845 {
9b7132d3 3846 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3847 goto error;
3848 }
3849 else if (reg >= hi_reg)
3850 {
3851 as_bad (_("bad register range"));
3852 goto error;
3853 }
3854 for (; reg < hi_reg; reg++)
3855 mask |= 1 << reg;
3856 }
3857 }
3858 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3859
c19d1205
ZW
3860 if (*input_line_pointer == '}')
3861 input_line_pointer++;
b99bd4ef 3862
c19d1205 3863 demand_empty_rest_of_line ();
b99bd4ef 3864
708587a4 3865 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3866 the list. */
3867 flush_pending_unwind ();
b99bd4ef 3868
c19d1205 3869 for (i = 0; i < 16; i++)
b99bd4ef 3870 {
c19d1205
ZW
3871 if (mask & (1 << i))
3872 unwind.frame_size += 8;
b99bd4ef
NC
3873 }
3874
c19d1205
ZW
3875 /* Attempt to combine with a previous opcode. We do this because gcc
3876 likes to output separate unwind directives for a single block of
3877 registers. */
3878 if (unwind.opcode_count > 0)
b99bd4ef 3879 {
c19d1205
ZW
3880 i = unwind.opcodes[unwind.opcode_count - 1];
3881 if ((i & 0xf8) == 0xc0)
3882 {
3883 i &= 7;
3884 /* Only merge if the blocks are contiguous. */
3885 if (i < 6)
3886 {
3887 if ((mask & 0xfe00) == (1 << 9))
3888 {
3889 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3890 unwind.opcode_count--;
3891 }
3892 }
3893 else if (i == 6 && unwind.opcode_count >= 2)
3894 {
3895 i = unwind.opcodes[unwind.opcode_count - 2];
3896 reg = i >> 4;
3897 i &= 0xf;
b99bd4ef 3898
c19d1205
ZW
3899 op = 0xffff << (reg - 1);
3900 if (reg > 0
87a1fd79 3901 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3902 {
3903 op = (1 << (reg + i + 1)) - 1;
3904 op &= ~((1 << reg) - 1);
3905 mask |= op;
3906 unwind.opcode_count -= 2;
3907 }
3908 }
3909 }
b99bd4ef
NC
3910 }
3911
c19d1205
ZW
3912 hi_reg = 15;
3913 /* We want to generate opcodes in the order the registers have been
3914 saved, ie. descending order. */
3915 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3916 {
c19d1205
ZW
3917 /* Save registers in blocks. */
3918 if (reg < 0
3919 || !(mask & (1 << reg)))
3920 {
3921 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3922 preceding block. */
c19d1205
ZW
3923 if (reg != hi_reg)
3924 {
3925 if (reg == 9)
3926 {
3927 /* Short form. */
3928 op = 0xc0 | (hi_reg - 10);
3929 add_unwind_opcode (op, 1);
3930 }
3931 else
3932 {
3933 /* Long form. */
3934 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3935 add_unwind_opcode (op, 2);
3936 }
3937 }
3938 hi_reg = reg - 1;
3939 }
b99bd4ef
NC
3940 }
3941
c19d1205
ZW
3942 return;
3943error:
3944 ignore_rest_of_line ();
b99bd4ef
NC
3945}
3946
3947static void
c19d1205 3948s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3949{
c19d1205
ZW
3950 int reg;
3951 int hi_reg;
3952 unsigned mask = 0;
3953 valueT op;
b99bd4ef 3954
c19d1205
ZW
3955 if (*input_line_pointer == '{')
3956 input_line_pointer++;
b99bd4ef 3957
c19d1205 3958 do
b99bd4ef 3959 {
dcbf9037 3960 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3961
c19d1205
ZW
3962 if (reg == FAIL)
3963 {
9b7132d3 3964 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3965 goto error;
3966 }
b99bd4ef 3967
c19d1205
ZW
3968 reg -= 8;
3969 if (mask >> reg)
3970 as_tsktsk (_("register list not in ascending order"));
3971 mask |= 1 << reg;
b99bd4ef 3972
c19d1205
ZW
3973 if (*input_line_pointer == '-')
3974 {
3975 input_line_pointer++;
dcbf9037 3976 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3977 if (hi_reg == FAIL)
3978 {
9b7132d3 3979 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3980 goto error;
3981 }
3982 else if (reg >= hi_reg)
3983 {
3984 as_bad (_("bad register range"));
3985 goto error;
3986 }
3987 for (; reg < hi_reg; reg++)
3988 mask |= 1 << reg;
3989 }
b99bd4ef 3990 }
c19d1205 3991 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3992
c19d1205
ZW
3993 if (*input_line_pointer == '}')
3994 input_line_pointer++;
b99bd4ef 3995
c19d1205
ZW
3996 demand_empty_rest_of_line ();
3997
708587a4 3998 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3999 the list. */
4000 flush_pending_unwind ();
b99bd4ef 4001
c19d1205 4002 for (reg = 0; reg < 16; reg++)
b99bd4ef 4003 {
c19d1205
ZW
4004 if (mask & (1 << reg))
4005 unwind.frame_size += 4;
b99bd4ef 4006 }
c19d1205
ZW
4007 op = 0xc700 | mask;
4008 add_unwind_opcode (op, 2);
4009 return;
4010error:
4011 ignore_rest_of_line ();
b99bd4ef
NC
4012}
4013
c19d1205 4014
fa073d69
MS
4015/* Parse an unwind_save directive.
4016 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4017
b99bd4ef 4018static void
fa073d69 4019s_arm_unwind_save (int arch_v6)
b99bd4ef 4020{
c19d1205
ZW
4021 char *peek;
4022 struct reg_entry *reg;
4023 bfd_boolean had_brace = FALSE;
b99bd4ef 4024
921e5f0a 4025 if (!unwind.proc_start)
c921be7d 4026 as_bad (MISSING_FNSTART);
921e5f0a 4027
c19d1205
ZW
4028 /* Figure out what sort of save we have. */
4029 peek = input_line_pointer;
b99bd4ef 4030
c19d1205 4031 if (*peek == '{')
b99bd4ef 4032 {
c19d1205
ZW
4033 had_brace = TRUE;
4034 peek++;
b99bd4ef
NC
4035 }
4036
c19d1205 4037 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4038
c19d1205 4039 if (!reg)
b99bd4ef 4040 {
c19d1205
ZW
4041 as_bad (_("register expected"));
4042 ignore_rest_of_line ();
b99bd4ef
NC
4043 return;
4044 }
4045
c19d1205 4046 switch (reg->type)
b99bd4ef 4047 {
c19d1205
ZW
4048 case REG_TYPE_FN:
4049 if (had_brace)
4050 {
4051 as_bad (_("FPA .unwind_save does not take a register list"));
4052 ignore_rest_of_line ();
4053 return;
4054 }
93ac2687 4055 input_line_pointer = peek;
c19d1205 4056 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4057 return;
c19d1205
ZW
4058
4059 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
4060 case REG_TYPE_VFD:
4061 if (arch_v6)
4062 s_arm_unwind_save_vfp_armv6 ();
4063 else
4064 s_arm_unwind_save_vfp ();
4065 return;
c19d1205
ZW
4066 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4067 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4068
4069 default:
4070 as_bad (_(".unwind_save does not support this kind of register"));
4071 ignore_rest_of_line ();
b99bd4ef 4072 }
c19d1205 4073}
b99bd4ef 4074
b99bd4ef 4075
c19d1205
ZW
4076/* Parse an unwind_movsp directive. */
4077
4078static void
4079s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4080{
4081 int reg;
4082 valueT op;
4fa3602b 4083 int offset;
c19d1205 4084
921e5f0a 4085 if (!unwind.proc_start)
c921be7d 4086 as_bad (MISSING_FNSTART);
921e5f0a 4087
dcbf9037 4088 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4089 if (reg == FAIL)
b99bd4ef 4090 {
9b7132d3 4091 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4092 ignore_rest_of_line ();
b99bd4ef
NC
4093 return;
4094 }
4fa3602b
PB
4095
4096 /* Optional constant. */
4097 if (skip_past_comma (&input_line_pointer) != FAIL)
4098 {
4099 if (immediate_for_directive (&offset) == FAIL)
4100 return;
4101 }
4102 else
4103 offset = 0;
4104
c19d1205 4105 demand_empty_rest_of_line ();
b99bd4ef 4106
c19d1205 4107 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4108 {
c19d1205 4109 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4110 return;
4111 }
4112
c19d1205
ZW
4113 if (unwind.fp_reg != REG_SP)
4114 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4115
c19d1205
ZW
4116 /* Generate opcode to restore the value. */
4117 op = 0x90 | reg;
4118 add_unwind_opcode (op, 1);
4119
4120 /* Record the information for later. */
4121 unwind.fp_reg = reg;
4fa3602b 4122 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4123 unwind.sp_restored = 1;
b05fe5cf
ZW
4124}
4125
c19d1205
ZW
4126/* Parse an unwind_pad directive. */
4127
b05fe5cf 4128static void
c19d1205 4129s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4130{
c19d1205 4131 int offset;
b05fe5cf 4132
921e5f0a 4133 if (!unwind.proc_start)
c921be7d 4134 as_bad (MISSING_FNSTART);
921e5f0a 4135
c19d1205
ZW
4136 if (immediate_for_directive (&offset) == FAIL)
4137 return;
b99bd4ef 4138
c19d1205
ZW
4139 if (offset & 3)
4140 {
4141 as_bad (_("stack increment must be multiple of 4"));
4142 ignore_rest_of_line ();
4143 return;
4144 }
b99bd4ef 4145
c19d1205
ZW
4146 /* Don't generate any opcodes, just record the details for later. */
4147 unwind.frame_size += offset;
4148 unwind.pending_offset += offset;
4149
4150 demand_empty_rest_of_line ();
4151}
4152
4153/* Parse an unwind_setfp directive. */
4154
4155static void
4156s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4157{
c19d1205
ZW
4158 int sp_reg;
4159 int fp_reg;
4160 int offset;
4161
921e5f0a 4162 if (!unwind.proc_start)
c921be7d 4163 as_bad (MISSING_FNSTART);
921e5f0a 4164
dcbf9037 4165 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4166 if (skip_past_comma (&input_line_pointer) == FAIL)
4167 sp_reg = FAIL;
4168 else
dcbf9037 4169 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4170
c19d1205
ZW
4171 if (fp_reg == FAIL || sp_reg == FAIL)
4172 {
4173 as_bad (_("expected <reg>, <reg>"));
4174 ignore_rest_of_line ();
4175 return;
4176 }
b99bd4ef 4177
c19d1205
ZW
4178 /* Optional constant. */
4179 if (skip_past_comma (&input_line_pointer) != FAIL)
4180 {
4181 if (immediate_for_directive (&offset) == FAIL)
4182 return;
4183 }
4184 else
4185 offset = 0;
a737bd4d 4186
c19d1205 4187 demand_empty_rest_of_line ();
a737bd4d 4188
fdfde340 4189 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4190 {
c19d1205
ZW
4191 as_bad (_("register must be either sp or set by a previous"
4192 "unwind_movsp directive"));
4193 return;
a737bd4d
NC
4194 }
4195
c19d1205
ZW
4196 /* Don't generate any opcodes, just record the information for later. */
4197 unwind.fp_reg = fp_reg;
4198 unwind.fp_used = 1;
fdfde340 4199 if (sp_reg == REG_SP)
c19d1205
ZW
4200 unwind.fp_offset = unwind.frame_size - offset;
4201 else
4202 unwind.fp_offset -= offset;
a737bd4d
NC
4203}
4204
c19d1205
ZW
4205/* Parse an unwind_raw directive. */
4206
4207static void
4208s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4209{
c19d1205 4210 expressionS exp;
708587a4 4211 /* This is an arbitrary limit. */
c19d1205
ZW
4212 unsigned char op[16];
4213 int count;
a737bd4d 4214
921e5f0a 4215 if (!unwind.proc_start)
c921be7d 4216 as_bad (MISSING_FNSTART);
921e5f0a 4217
c19d1205
ZW
4218 expression (&exp);
4219 if (exp.X_op == O_constant
4220 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4221 {
c19d1205
ZW
4222 unwind.frame_size += exp.X_add_number;
4223 expression (&exp);
4224 }
4225 else
4226 exp.X_op = O_illegal;
a737bd4d 4227
c19d1205
ZW
4228 if (exp.X_op != O_constant)
4229 {
4230 as_bad (_("expected <offset>, <opcode>"));
4231 ignore_rest_of_line ();
4232 return;
4233 }
a737bd4d 4234
c19d1205 4235 count = 0;
a737bd4d 4236
c19d1205
ZW
4237 /* Parse the opcode. */
4238 for (;;)
4239 {
4240 if (count >= 16)
4241 {
4242 as_bad (_("unwind opcode too long"));
4243 ignore_rest_of_line ();
a737bd4d 4244 }
c19d1205 4245 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4246 {
c19d1205
ZW
4247 as_bad (_("invalid unwind opcode"));
4248 ignore_rest_of_line ();
4249 return;
a737bd4d 4250 }
c19d1205 4251 op[count++] = exp.X_add_number;
a737bd4d 4252
c19d1205
ZW
4253 /* Parse the next byte. */
4254 if (skip_past_comma (&input_line_pointer) == FAIL)
4255 break;
a737bd4d 4256
c19d1205
ZW
4257 expression (&exp);
4258 }
b99bd4ef 4259
c19d1205
ZW
4260 /* Add the opcode bytes in reverse order. */
4261 while (count--)
4262 add_unwind_opcode (op[count], 1);
b99bd4ef 4263
c19d1205 4264 demand_empty_rest_of_line ();
b99bd4ef 4265}
ee065d83
PB
4266
4267
4268/* Parse a .eabi_attribute directive. */
4269
4270static void
4271s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4272{
ee3c0378
AS
4273 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4274
4275 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4276 attributes_set_explicitly[tag] = 1;
ee065d83 4277}
8463be01 4278#endif /* OBJ_ELF */
ee065d83 4279
0855e32b
NS
4280/* Emit a tls fix for the symbol. */
4281
4282static void
4283s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4284{
4285 char *p;
4286 expressionS exp;
4287#ifdef md_flush_pending_output
4288 md_flush_pending_output ();
4289#endif
4290
4291#ifdef md_cons_align
4292 md_cons_align (4);
4293#endif
4294
4295 /* Since we're just labelling the code, there's no need to define a
4296 mapping symbol. */
4297 expression (&exp);
4298 p = obstack_next_free (&frchain_now->frch_obstack);
4299 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4300 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4301 : BFD_RELOC_ARM_TLS_DESCSEQ);
4302}
4303
ee065d83 4304static void s_arm_arch (int);
7a1d4c38 4305static void s_arm_object_arch (int);
ee065d83
PB
4306static void s_arm_cpu (int);
4307static void s_arm_fpu (int);
69133863 4308static void s_arm_arch_extension (int);
b99bd4ef 4309
f0927246
NC
4310#ifdef TE_PE
4311
4312static void
5f4273c7 4313pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4314{
4315 expressionS exp;
4316
4317 do
4318 {
4319 expression (&exp);
4320 if (exp.X_op == O_symbol)
4321 exp.X_op = O_secrel;
4322
4323 emit_expr (&exp, 4);
4324 }
4325 while (*input_line_pointer++ == ',');
4326
4327 input_line_pointer--;
4328 demand_empty_rest_of_line ();
4329}
4330#endif /* TE_PE */
4331
c19d1205
ZW
4332/* This table describes all the machine specific pseudo-ops the assembler
4333 has to support. The fields are:
4334 pseudo-op name without dot
4335 function to call to execute this pseudo-op
4336 Integer arg to pass to the function. */
b99bd4ef 4337
c19d1205 4338const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4339{
c19d1205
ZW
4340 /* Never called because '.req' does not start a line. */
4341 { "req", s_req, 0 },
dcbf9037
JB
4342 /* Following two are likewise never called. */
4343 { "dn", s_dn, 0 },
4344 { "qn", s_qn, 0 },
c19d1205
ZW
4345 { "unreq", s_unreq, 0 },
4346 { "bss", s_bss, 0 },
4347 { "align", s_align, 0 },
4348 { "arm", s_arm, 0 },
4349 { "thumb", s_thumb, 0 },
4350 { "code", s_code, 0 },
4351 { "force_thumb", s_force_thumb, 0 },
4352 { "thumb_func", s_thumb_func, 0 },
4353 { "thumb_set", s_thumb_set, 0 },
4354 { "even", s_even, 0 },
4355 { "ltorg", s_ltorg, 0 },
4356 { "pool", s_ltorg, 0 },
4357 { "syntax", s_syntax, 0 },
8463be01
PB
4358 { "cpu", s_arm_cpu, 0 },
4359 { "arch", s_arm_arch, 0 },
7a1d4c38 4360 { "object_arch", s_arm_object_arch, 0 },
8463be01 4361 { "fpu", s_arm_fpu, 0 },
69133863 4362 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4363#ifdef OBJ_ELF
c921be7d
NC
4364 { "word", s_arm_elf_cons, 4 },
4365 { "long", s_arm_elf_cons, 4 },
4366 { "inst.n", s_arm_elf_inst, 2 },
4367 { "inst.w", s_arm_elf_inst, 4 },
4368 { "inst", s_arm_elf_inst, 0 },
4369 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4370 { "fnstart", s_arm_unwind_fnstart, 0 },
4371 { "fnend", s_arm_unwind_fnend, 0 },
4372 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4373 { "personality", s_arm_unwind_personality, 0 },
4374 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4375 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4376 { "save", s_arm_unwind_save, 0 },
fa073d69 4377 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4378 { "movsp", s_arm_unwind_movsp, 0 },
4379 { "pad", s_arm_unwind_pad, 0 },
4380 { "setfp", s_arm_unwind_setfp, 0 },
4381 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4382 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4383 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4384#else
4385 { "word", cons, 4},
f0927246
NC
4386
4387 /* These are used for dwarf. */
4388 {"2byte", cons, 2},
4389 {"4byte", cons, 4},
4390 {"8byte", cons, 8},
4391 /* These are used for dwarf2. */
4392 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4393 { "loc", dwarf2_directive_loc, 0 },
4394 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4395#endif
4396 { "extend", float_cons, 'x' },
4397 { "ldouble", float_cons, 'x' },
4398 { "packed", float_cons, 'p' },
f0927246
NC
4399#ifdef TE_PE
4400 {"secrel32", pe_directive_secrel, 0},
4401#endif
c19d1205
ZW
4402 { 0, 0, 0 }
4403};
4404\f
4405/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4406
c19d1205
ZW
4407/* Generic immediate-value read function for use in insn parsing.
4408 STR points to the beginning of the immediate (the leading #);
4409 VAL receives the value; if the value is outside [MIN, MAX]
4410 issue an error. PREFIX_OPT is true if the immediate prefix is
4411 optional. */
b99bd4ef 4412
c19d1205
ZW
4413static int
4414parse_immediate (char **str, int *val, int min, int max,
4415 bfd_boolean prefix_opt)
4416{
4417 expressionS exp;
4418 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4419 if (exp.X_op != O_constant)
b99bd4ef 4420 {
c19d1205
ZW
4421 inst.error = _("constant expression required");
4422 return FAIL;
4423 }
b99bd4ef 4424
c19d1205
ZW
4425 if (exp.X_add_number < min || exp.X_add_number > max)
4426 {
4427 inst.error = _("immediate value out of range");
4428 return FAIL;
4429 }
b99bd4ef 4430
c19d1205
ZW
4431 *val = exp.X_add_number;
4432 return SUCCESS;
4433}
b99bd4ef 4434
5287ad62 4435/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4436 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4437 instructions. Puts the result directly in inst.operands[i]. */
4438
4439static int
4440parse_big_immediate (char **str, int i)
4441{
4442 expressionS exp;
4443 char *ptr = *str;
4444
4445 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4446
4447 if (exp.X_op == O_constant)
036dc3f7
PB
4448 {
4449 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4450 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4451 O_constant. We have to be careful not to break compilation for
4452 32-bit X_add_number, though. */
4453 if ((exp.X_add_number & ~0xffffffffl) != 0)
4454 {
4455 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4456 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4457 inst.operands[i].regisimm = 1;
4458 }
4459 }
5287ad62 4460 else if (exp.X_op == O_big
95b75c01 4461 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
5287ad62
JB
4462 {
4463 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4464
5287ad62
JB
4465 /* Bignums have their least significant bits in
4466 generic_bignum[0]. Make sure we put 32 bits in imm and
4467 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4468 gas_assert (parts != 0);
95b75c01
NC
4469
4470 /* Make sure that the number is not too big.
4471 PR 11972: Bignums can now be sign-extended to the
4472 size of a .octa so check that the out of range bits
4473 are all zero or all one. */
4474 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4475 {
4476 LITTLENUM_TYPE m = -1;
4477
4478 if (generic_bignum[parts * 2] != 0
4479 && generic_bignum[parts * 2] != m)
4480 return FAIL;
4481
4482 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4483 if (generic_bignum[j] != generic_bignum[j-1])
4484 return FAIL;
4485 }
4486
5287ad62
JB
4487 inst.operands[i].imm = 0;
4488 for (j = 0; j < parts; j++, idx++)
4489 inst.operands[i].imm |= generic_bignum[idx]
4490 << (LITTLENUM_NUMBER_OF_BITS * j);
4491 inst.operands[i].reg = 0;
4492 for (j = 0; j < parts; j++, idx++)
4493 inst.operands[i].reg |= generic_bignum[idx]
4494 << (LITTLENUM_NUMBER_OF_BITS * j);
4495 inst.operands[i].regisimm = 1;
4496 }
4497 else
4498 return FAIL;
5f4273c7 4499
5287ad62
JB
4500 *str = ptr;
4501
4502 return SUCCESS;
4503}
4504
c19d1205
ZW
4505/* Returns the pseudo-register number of an FPA immediate constant,
4506 or FAIL if there isn't a valid constant here. */
b99bd4ef 4507
c19d1205
ZW
4508static int
4509parse_fpa_immediate (char ** str)
4510{
4511 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4512 char * save_in;
4513 expressionS exp;
4514 int i;
4515 int j;
b99bd4ef 4516
c19d1205
ZW
4517 /* First try and match exact strings, this is to guarantee
4518 that some formats will work even for cross assembly. */
b99bd4ef 4519
c19d1205
ZW
4520 for (i = 0; fp_const[i]; i++)
4521 {
4522 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4523 {
c19d1205 4524 char *start = *str;
b99bd4ef 4525
c19d1205
ZW
4526 *str += strlen (fp_const[i]);
4527 if (is_end_of_line[(unsigned char) **str])
4528 return i + 8;
4529 *str = start;
4530 }
4531 }
b99bd4ef 4532
c19d1205
ZW
4533 /* Just because we didn't get a match doesn't mean that the constant
4534 isn't valid, just that it is in a format that we don't
4535 automatically recognize. Try parsing it with the standard
4536 expression routines. */
b99bd4ef 4537
c19d1205 4538 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4539
c19d1205
ZW
4540 /* Look for a raw floating point number. */
4541 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4542 && is_end_of_line[(unsigned char) *save_in])
4543 {
4544 for (i = 0; i < NUM_FLOAT_VALS; i++)
4545 {
4546 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4547 {
c19d1205
ZW
4548 if (words[j] != fp_values[i][j])
4549 break;
b99bd4ef
NC
4550 }
4551
c19d1205 4552 if (j == MAX_LITTLENUMS)
b99bd4ef 4553 {
c19d1205
ZW
4554 *str = save_in;
4555 return i + 8;
b99bd4ef
NC
4556 }
4557 }
4558 }
b99bd4ef 4559
c19d1205
ZW
4560 /* Try and parse a more complex expression, this will probably fail
4561 unless the code uses a floating point prefix (eg "0f"). */
4562 save_in = input_line_pointer;
4563 input_line_pointer = *str;
4564 if (expression (&exp) == absolute_section
4565 && exp.X_op == O_big
4566 && exp.X_add_number < 0)
4567 {
4568 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4569 Ditto for 15. */
4570 if (gen_to_words (words, 5, (long) 15) == 0)
4571 {
4572 for (i = 0; i < NUM_FLOAT_VALS; i++)
4573 {
4574 for (j = 0; j < MAX_LITTLENUMS; j++)
4575 {
4576 if (words[j] != fp_values[i][j])
4577 break;
4578 }
b99bd4ef 4579
c19d1205
ZW
4580 if (j == MAX_LITTLENUMS)
4581 {
4582 *str = input_line_pointer;
4583 input_line_pointer = save_in;
4584 return i + 8;
4585 }
4586 }
4587 }
b99bd4ef
NC
4588 }
4589
c19d1205
ZW
4590 *str = input_line_pointer;
4591 input_line_pointer = save_in;
4592 inst.error = _("invalid FPA immediate expression");
4593 return FAIL;
b99bd4ef
NC
4594}
4595
136da414
JB
4596/* Returns 1 if a number has "quarter-precision" float format
4597 0baBbbbbbc defgh000 00000000 00000000. */
4598
4599static int
4600is_quarter_float (unsigned imm)
4601{
4602 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4603 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4604}
4605
4606/* Parse an 8-bit "quarter-precision" floating point number of the form:
4607 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4608 The zero and minus-zero cases need special handling, since they can't be
4609 encoded in the "quarter-precision" float format, but can nonetheless be
4610 loaded as integer constants. */
136da414
JB
4611
4612static unsigned
4613parse_qfloat_immediate (char **ccp, int *immed)
4614{
4615 char *str = *ccp;
c96612cc 4616 char *fpnum;
136da414 4617 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4618 int found_fpchar = 0;
5f4273c7 4619
136da414 4620 skip_past_char (&str, '#');
5f4273c7 4621
c96612cc
JB
4622 /* We must not accidentally parse an integer as a floating-point number. Make
4623 sure that the value we parse is not an integer by checking for special
4624 characters '.' or 'e'.
4625 FIXME: This is a horrible hack, but doing better is tricky because type
4626 information isn't in a very usable state at parse time. */
4627 fpnum = str;
4628 skip_whitespace (fpnum);
4629
4630 if (strncmp (fpnum, "0x", 2) == 0)
4631 return FAIL;
4632 else
4633 {
4634 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4635 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4636 {
4637 found_fpchar = 1;
4638 break;
4639 }
4640
4641 if (!found_fpchar)
4642 return FAIL;
4643 }
5f4273c7 4644
136da414
JB
4645 if ((str = atof_ieee (str, 's', words)) != NULL)
4646 {
4647 unsigned fpword = 0;
4648 int i;
5f4273c7 4649
136da414
JB
4650 /* Our FP word must be 32 bits (single-precision FP). */
4651 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4652 {
4653 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4654 fpword |= words[i];
4655 }
5f4273c7 4656
c96612cc 4657 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4658 *immed = fpword;
4659 else
4660 return FAIL;
4661
4662 *ccp = str;
5f4273c7 4663
136da414
JB
4664 return SUCCESS;
4665 }
5f4273c7 4666
136da414
JB
4667 return FAIL;
4668}
4669
c19d1205
ZW
4670/* Shift operands. */
4671enum shift_kind
b99bd4ef 4672{
c19d1205
ZW
4673 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4674};
b99bd4ef 4675
c19d1205
ZW
4676struct asm_shift_name
4677{
4678 const char *name;
4679 enum shift_kind kind;
4680};
b99bd4ef 4681
c19d1205
ZW
4682/* Third argument to parse_shift. */
4683enum parse_shift_mode
4684{
4685 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4686 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4687 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4688 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4689 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4690};
b99bd4ef 4691
c19d1205
ZW
4692/* Parse a <shift> specifier on an ARM data processing instruction.
4693 This has three forms:
b99bd4ef 4694
c19d1205
ZW
4695 (LSL|LSR|ASL|ASR|ROR) Rs
4696 (LSL|LSR|ASL|ASR|ROR) #imm
4697 RRX
b99bd4ef 4698
c19d1205
ZW
4699 Note that ASL is assimilated to LSL in the instruction encoding, and
4700 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4701
c19d1205
ZW
4702static int
4703parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4704{
c19d1205
ZW
4705 const struct asm_shift_name *shift_name;
4706 enum shift_kind shift;
4707 char *s = *str;
4708 char *p = s;
4709 int reg;
b99bd4ef 4710
c19d1205
ZW
4711 for (p = *str; ISALPHA (*p); p++)
4712 ;
b99bd4ef 4713
c19d1205 4714 if (p == *str)
b99bd4ef 4715 {
c19d1205
ZW
4716 inst.error = _("shift expression expected");
4717 return FAIL;
b99bd4ef
NC
4718 }
4719
21d799b5
NC
4720 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4721 p - *str);
c19d1205
ZW
4722
4723 if (shift_name == NULL)
b99bd4ef 4724 {
c19d1205
ZW
4725 inst.error = _("shift expression expected");
4726 return FAIL;
b99bd4ef
NC
4727 }
4728
c19d1205 4729 shift = shift_name->kind;
b99bd4ef 4730
c19d1205
ZW
4731 switch (mode)
4732 {
4733 case NO_SHIFT_RESTRICT:
4734 case SHIFT_IMMEDIATE: break;
b99bd4ef 4735
c19d1205
ZW
4736 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4737 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4738 {
4739 inst.error = _("'LSL' or 'ASR' required");
4740 return FAIL;
4741 }
4742 break;
b99bd4ef 4743
c19d1205
ZW
4744 case SHIFT_LSL_IMMEDIATE:
4745 if (shift != SHIFT_LSL)
4746 {
4747 inst.error = _("'LSL' required");
4748 return FAIL;
4749 }
4750 break;
b99bd4ef 4751
c19d1205
ZW
4752 case SHIFT_ASR_IMMEDIATE:
4753 if (shift != SHIFT_ASR)
4754 {
4755 inst.error = _("'ASR' required");
4756 return FAIL;
4757 }
4758 break;
b99bd4ef 4759
c19d1205
ZW
4760 default: abort ();
4761 }
b99bd4ef 4762
c19d1205
ZW
4763 if (shift != SHIFT_RRX)
4764 {
4765 /* Whitespace can appear here if the next thing is a bare digit. */
4766 skip_whitespace (p);
b99bd4ef 4767
c19d1205 4768 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4769 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4770 {
4771 inst.operands[i].imm = reg;
4772 inst.operands[i].immisreg = 1;
4773 }
4774 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4775 return FAIL;
4776 }
4777 inst.operands[i].shift_kind = shift;
4778 inst.operands[i].shifted = 1;
4779 *str = p;
4780 return SUCCESS;
b99bd4ef
NC
4781}
4782
c19d1205 4783/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4784
c19d1205
ZW
4785 #<immediate>
4786 #<immediate>, <rotate>
4787 <Rm>
4788 <Rm>, <shift>
b99bd4ef 4789
c19d1205
ZW
4790 where <shift> is defined by parse_shift above, and <rotate> is a
4791 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4792 is deferred to md_apply_fix. */
b99bd4ef 4793
c19d1205
ZW
4794static int
4795parse_shifter_operand (char **str, int i)
4796{
4797 int value;
91d6fa6a 4798 expressionS exp;
b99bd4ef 4799
dcbf9037 4800 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4801 {
4802 inst.operands[i].reg = value;
4803 inst.operands[i].isreg = 1;
b99bd4ef 4804
c19d1205
ZW
4805 /* parse_shift will override this if appropriate */
4806 inst.reloc.exp.X_op = O_constant;
4807 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4808
c19d1205
ZW
4809 if (skip_past_comma (str) == FAIL)
4810 return SUCCESS;
b99bd4ef 4811
c19d1205
ZW
4812 /* Shift operation on register. */
4813 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4814 }
4815
c19d1205
ZW
4816 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4817 return FAIL;
b99bd4ef 4818
c19d1205 4819 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4820 {
c19d1205 4821 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 4822 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 4823 return FAIL;
b99bd4ef 4824
91d6fa6a 4825 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
4826 {
4827 inst.error = _("constant expression expected");
4828 return FAIL;
4829 }
b99bd4ef 4830
91d6fa6a 4831 value = exp.X_add_number;
c19d1205
ZW
4832 if (value < 0 || value > 30 || value % 2 != 0)
4833 {
4834 inst.error = _("invalid rotation");
4835 return FAIL;
4836 }
4837 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4838 {
4839 inst.error = _("invalid constant");
4840 return FAIL;
4841 }
09d92015 4842
55cf6793 4843 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4844 inst.reloc.exp.X_add_number
4845 = (((inst.reloc.exp.X_add_number << (32 - value))
4846 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4847 }
4848
c19d1205
ZW
4849 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4850 inst.reloc.pc_rel = 0;
4851 return SUCCESS;
09d92015
MM
4852}
4853
4962c51a
MS
4854/* Group relocation information. Each entry in the table contains the
4855 textual name of the relocation as may appear in assembler source
4856 and must end with a colon.
4857 Along with this textual name are the relocation codes to be used if
4858 the corresponding instruction is an ALU instruction (ADD or SUB only),
4859 an LDR, an LDRS, or an LDC. */
4860
4861struct group_reloc_table_entry
4862{
4863 const char *name;
4864 int alu_code;
4865 int ldr_code;
4866 int ldrs_code;
4867 int ldc_code;
4868};
4869
4870typedef enum
4871{
4872 /* Varieties of non-ALU group relocation. */
4873
4874 GROUP_LDR,
4875 GROUP_LDRS,
4876 GROUP_LDC
4877} group_reloc_type;
4878
4879static struct group_reloc_table_entry group_reloc_table[] =
4880 { /* Program counter relative: */
4881 { "pc_g0_nc",
4882 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4883 0, /* LDR */
4884 0, /* LDRS */
4885 0 }, /* LDC */
4886 { "pc_g0",
4887 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4888 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4889 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4890 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4891 { "pc_g1_nc",
4892 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4893 0, /* LDR */
4894 0, /* LDRS */
4895 0 }, /* LDC */
4896 { "pc_g1",
4897 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4898 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4899 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4900 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4901 { "pc_g2",
4902 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4903 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4904 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4905 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4906 /* Section base relative */
4907 { "sb_g0_nc",
4908 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4909 0, /* LDR */
4910 0, /* LDRS */
4911 0 }, /* LDC */
4912 { "sb_g0",
4913 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4914 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4915 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4916 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4917 { "sb_g1_nc",
4918 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4919 0, /* LDR */
4920 0, /* LDRS */
4921 0 }, /* LDC */
4922 { "sb_g1",
4923 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4924 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4925 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4926 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4927 { "sb_g2",
4928 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4929 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4930 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4931 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4932
4933/* Given the address of a pointer pointing to the textual name of a group
4934 relocation as may appear in assembler source, attempt to find its details
4935 in group_reloc_table. The pointer will be updated to the character after
4936 the trailing colon. On failure, FAIL will be returned; SUCCESS
4937 otherwise. On success, *entry will be updated to point at the relevant
4938 group_reloc_table entry. */
4939
4940static int
4941find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4942{
4943 unsigned int i;
4944 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4945 {
4946 int length = strlen (group_reloc_table[i].name);
4947
5f4273c7
NC
4948 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4949 && (*str)[length] == ':')
4962c51a
MS
4950 {
4951 *out = &group_reloc_table[i];
4952 *str += (length + 1);
4953 return SUCCESS;
4954 }
4955 }
4956
4957 return FAIL;
4958}
4959
4960/* Parse a <shifter_operand> for an ARM data processing instruction
4961 (as for parse_shifter_operand) where group relocations are allowed:
4962
4963 #<immediate>
4964 #<immediate>, <rotate>
4965 #:<group_reloc>:<expression>
4966 <Rm>
4967 <Rm>, <shift>
4968
4969 where <group_reloc> is one of the strings defined in group_reloc_table.
4970 The hashes are optional.
4971
4972 Everything else is as for parse_shifter_operand. */
4973
4974static parse_operand_result
4975parse_shifter_operand_group_reloc (char **str, int i)
4976{
4977 /* Determine if we have the sequence of characters #: or just :
4978 coming next. If we do, then we check for a group relocation.
4979 If we don't, punt the whole lot to parse_shifter_operand. */
4980
4981 if (((*str)[0] == '#' && (*str)[1] == ':')
4982 || (*str)[0] == ':')
4983 {
4984 struct group_reloc_table_entry *entry;
4985
4986 if ((*str)[0] == '#')
4987 (*str) += 2;
4988 else
4989 (*str)++;
4990
4991 /* Try to parse a group relocation. Anything else is an error. */
4992 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4993 {
4994 inst.error = _("unknown group relocation");
4995 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4996 }
4997
4998 /* We now have the group relocation table entry corresponding to
4999 the name in the assembler source. Next, we parse the expression. */
5000 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
5001 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5002
5003 /* Record the relocation type (always the ALU variant here). */
21d799b5 5004 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5005 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5006
5007 return PARSE_OPERAND_SUCCESS;
5008 }
5009 else
5010 return parse_shifter_operand (str, i) == SUCCESS
5011 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5012
5013 /* Never reached. */
5014}
5015
8e560766
MGD
5016/* Parse a Neon alignment expression. Information is written to
5017 inst.operands[i]. We assume the initial ':' has been skipped.
5018
5019 align .imm = align << 8, .immisalign=1, .preind=0 */
5020static parse_operand_result
5021parse_neon_alignment (char **str, int i)
5022{
5023 char *p = *str;
5024 expressionS exp;
5025
5026 my_get_expression (&exp, &p, GE_NO_PREFIX);
5027
5028 if (exp.X_op != O_constant)
5029 {
5030 inst.error = _("alignment must be constant");
5031 return PARSE_OPERAND_FAIL;
5032 }
5033
5034 inst.operands[i].imm = exp.X_add_number << 8;
5035 inst.operands[i].immisalign = 1;
5036 /* Alignments are not pre-indexes. */
5037 inst.operands[i].preind = 0;
5038
5039 *str = p;
5040 return PARSE_OPERAND_SUCCESS;
5041}
5042
c19d1205
ZW
5043/* Parse all forms of an ARM address expression. Information is written
5044 to inst.operands[i] and/or inst.reloc.
09d92015 5045
c19d1205 5046 Preindexed addressing (.preind=1):
09d92015 5047
c19d1205
ZW
5048 [Rn, #offset] .reg=Rn .reloc.exp=offset
5049 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5050 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5051 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5052
c19d1205 5053 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5054
c19d1205 5055 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5056
c19d1205
ZW
5057 [Rn], #offset .reg=Rn .reloc.exp=offset
5058 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5059 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5060 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5061
c19d1205 5062 Unindexed addressing (.preind=0, .postind=0):
09d92015 5063
c19d1205 5064 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5065
c19d1205 5066 Other:
09d92015 5067
c19d1205
ZW
5068 [Rn]{!} shorthand for [Rn,#0]{!}
5069 =immediate .isreg=0 .reloc.exp=immediate
5070 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5071
c19d1205
ZW
5072 It is the caller's responsibility to check for addressing modes not
5073 supported by the instruction, and to set inst.reloc.type. */
5074
4962c51a
MS
5075static parse_operand_result
5076parse_address_main (char **str, int i, int group_relocations,
5077 group_reloc_type group_type)
09d92015 5078{
c19d1205
ZW
5079 char *p = *str;
5080 int reg;
09d92015 5081
c19d1205 5082 if (skip_past_char (&p, '[') == FAIL)
09d92015 5083 {
c19d1205
ZW
5084 if (skip_past_char (&p, '=') == FAIL)
5085 {
974da60d 5086 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5087 inst.reloc.pc_rel = 1;
5088 inst.operands[i].reg = REG_PC;
5089 inst.operands[i].isreg = 1;
5090 inst.operands[i].preind = 1;
5091 }
974da60d 5092 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
09d92015 5093
c19d1205 5094 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 5095 return PARSE_OPERAND_FAIL;
09d92015 5096
c19d1205 5097 *str = p;
4962c51a 5098 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5099 }
5100
dcbf9037 5101 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5102 {
c19d1205 5103 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5104 return PARSE_OPERAND_FAIL;
09d92015 5105 }
c19d1205
ZW
5106 inst.operands[i].reg = reg;
5107 inst.operands[i].isreg = 1;
09d92015 5108
c19d1205 5109 if (skip_past_comma (&p) == SUCCESS)
09d92015 5110 {
c19d1205 5111 inst.operands[i].preind = 1;
09d92015 5112
c19d1205
ZW
5113 if (*p == '+') p++;
5114 else if (*p == '-') p++, inst.operands[i].negative = 1;
5115
dcbf9037 5116 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5117 {
c19d1205
ZW
5118 inst.operands[i].imm = reg;
5119 inst.operands[i].immisreg = 1;
5120
5121 if (skip_past_comma (&p) == SUCCESS)
5122 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5123 return PARSE_OPERAND_FAIL;
c19d1205 5124 }
5287ad62 5125 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5126 {
5127 /* FIXME: '@' should be used here, but it's filtered out by generic
5128 code before we get to see it here. This may be subject to
5129 change. */
5130 parse_operand_result result = parse_neon_alignment (&p, i);
5131
5132 if (result != PARSE_OPERAND_SUCCESS)
5133 return result;
5134 }
c19d1205
ZW
5135 else
5136 {
5137 if (inst.operands[i].negative)
5138 {
5139 inst.operands[i].negative = 0;
5140 p--;
5141 }
4962c51a 5142
5f4273c7
NC
5143 if (group_relocations
5144 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5145 {
5146 struct group_reloc_table_entry *entry;
5147
5148 /* Skip over the #: or : sequence. */
5149 if (*p == '#')
5150 p += 2;
5151 else
5152 p++;
5153
5154 /* Try to parse a group relocation. Anything else is an
5155 error. */
5156 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5157 {
5158 inst.error = _("unknown group relocation");
5159 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5160 }
5161
5162 /* We now have the group relocation table entry corresponding to
5163 the name in the assembler source. Next, we parse the
5164 expression. */
5165 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5166 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5167
5168 /* Record the relocation type. */
5169 switch (group_type)
5170 {
5171 case GROUP_LDR:
21d799b5 5172 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
4962c51a
MS
5173 break;
5174
5175 case GROUP_LDRS:
21d799b5 5176 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
4962c51a
MS
5177 break;
5178
5179 case GROUP_LDC:
21d799b5 5180 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
4962c51a
MS
5181 break;
5182
5183 default:
9c2799c2 5184 gas_assert (0);
4962c51a
MS
5185 }
5186
5187 if (inst.reloc.type == 0)
5188 {
5189 inst.error = _("this group relocation is not allowed on this instruction");
5190 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5191 }
5192 }
5193 else
5194 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5195 return PARSE_OPERAND_FAIL;
09d92015
MM
5196 }
5197 }
8e560766
MGD
5198 else if (skip_past_char (&p, ':') == SUCCESS)
5199 {
5200 /* FIXME: '@' should be used here, but it's filtered out by generic code
5201 before we get to see it here. This may be subject to change. */
5202 parse_operand_result result = parse_neon_alignment (&p, i);
5203
5204 if (result != PARSE_OPERAND_SUCCESS)
5205 return result;
5206 }
09d92015 5207
c19d1205 5208 if (skip_past_char (&p, ']') == FAIL)
09d92015 5209 {
c19d1205 5210 inst.error = _("']' expected");
4962c51a 5211 return PARSE_OPERAND_FAIL;
09d92015
MM
5212 }
5213
c19d1205
ZW
5214 if (skip_past_char (&p, '!') == SUCCESS)
5215 inst.operands[i].writeback = 1;
09d92015 5216
c19d1205 5217 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5218 {
c19d1205
ZW
5219 if (skip_past_char (&p, '{') == SUCCESS)
5220 {
5221 /* [Rn], {expr} - unindexed, with option */
5222 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5223 0, 255, TRUE) == FAIL)
4962c51a 5224 return PARSE_OPERAND_FAIL;
09d92015 5225
c19d1205
ZW
5226 if (skip_past_char (&p, '}') == FAIL)
5227 {
5228 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5229 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5230 }
5231 if (inst.operands[i].preind)
5232 {
5233 inst.error = _("cannot combine index with option");
4962c51a 5234 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5235 }
5236 *str = p;
4962c51a 5237 return PARSE_OPERAND_SUCCESS;
09d92015 5238 }
c19d1205
ZW
5239 else
5240 {
5241 inst.operands[i].postind = 1;
5242 inst.operands[i].writeback = 1;
09d92015 5243
c19d1205
ZW
5244 if (inst.operands[i].preind)
5245 {
5246 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5247 return PARSE_OPERAND_FAIL;
c19d1205 5248 }
09d92015 5249
c19d1205
ZW
5250 if (*p == '+') p++;
5251 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5252
dcbf9037 5253 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5254 {
5287ad62
JB
5255 /* We might be using the immediate for alignment already. If we
5256 are, OR the register number into the low-order bits. */
5257 if (inst.operands[i].immisalign)
5258 inst.operands[i].imm |= reg;
5259 else
5260 inst.operands[i].imm = reg;
c19d1205 5261 inst.operands[i].immisreg = 1;
a737bd4d 5262
c19d1205
ZW
5263 if (skip_past_comma (&p) == SUCCESS)
5264 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5265 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5266 }
5267 else
5268 {
5269 if (inst.operands[i].negative)
5270 {
5271 inst.operands[i].negative = 0;
5272 p--;
5273 }
5274 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5275 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5276 }
5277 }
a737bd4d
NC
5278 }
5279
c19d1205
ZW
5280 /* If at this point neither .preind nor .postind is set, we have a
5281 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5282 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5283 {
5284 inst.operands[i].preind = 1;
5285 inst.reloc.exp.X_op = O_constant;
5286 inst.reloc.exp.X_add_number = 0;
5287 }
5288 *str = p;
4962c51a
MS
5289 return PARSE_OPERAND_SUCCESS;
5290}
5291
5292static int
5293parse_address (char **str, int i)
5294{
21d799b5 5295 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
4962c51a
MS
5296 ? SUCCESS : FAIL;
5297}
5298
5299static parse_operand_result
5300parse_address_group_reloc (char **str, int i, group_reloc_type type)
5301{
5302 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5303}
5304
b6895b4f
PB
5305/* Parse an operand for a MOVW or MOVT instruction. */
5306static int
5307parse_half (char **str)
5308{
5309 char * p;
5f4273c7 5310
b6895b4f
PB
5311 p = *str;
5312 skip_past_char (&p, '#');
5f4273c7 5313 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5314 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5315 else if (strncasecmp (p, ":upper16:", 9) == 0)
5316 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5317
5318 if (inst.reloc.type != BFD_RELOC_UNUSED)
5319 {
5320 p += 9;
5f4273c7 5321 skip_whitespace (p);
b6895b4f
PB
5322 }
5323
5324 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5325 return FAIL;
5326
5327 if (inst.reloc.type == BFD_RELOC_UNUSED)
5328 {
5329 if (inst.reloc.exp.X_op != O_constant)
5330 {
5331 inst.error = _("constant expression expected");
5332 return FAIL;
5333 }
5334 if (inst.reloc.exp.X_add_number < 0
5335 || inst.reloc.exp.X_add_number > 0xffff)
5336 {
5337 inst.error = _("immediate value out of range");
5338 return FAIL;
5339 }
5340 }
5341 *str = p;
5342 return SUCCESS;
5343}
5344
c19d1205 5345/* Miscellaneous. */
a737bd4d 5346
c19d1205
ZW
5347/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5348 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5349static int
5350parse_psr (char **str)
09d92015 5351{
c19d1205
ZW
5352 char *p;
5353 unsigned long psr_field;
62b3e311
PB
5354 const struct asm_psr *psr;
5355 char *start;
09d92015 5356
c19d1205
ZW
5357 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5358 feature for ease of use and backwards compatibility. */
5359 p = *str;
62b3e311 5360 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 5361 psr_field = SPSR_BIT;
59b42a0d
MGD
5362 else if (strncasecmp (p, "CPSR", 4) == 0
5363 || (strncasecmp (p, "APSR", 4) == 0
5364 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)))
c19d1205
ZW
5365 psr_field = 0;
5366 else
62b3e311
PB
5367 {
5368 start = p;
5369 do
5370 p++;
5371 while (ISALNUM (*p) || *p == '_');
5372
21d799b5
NC
5373 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5374 p - start);
62b3e311
PB
5375 if (!psr)
5376 return FAIL;
09d92015 5377
62b3e311
PB
5378 *str = p;
5379 return psr->field;
5380 }
09d92015 5381
62b3e311 5382 p += 4;
c19d1205
ZW
5383 if (*p == '_')
5384 {
5385 /* A suffix follows. */
c19d1205
ZW
5386 p++;
5387 start = p;
a737bd4d 5388
c19d1205
ZW
5389 do
5390 p++;
5391 while (ISALNUM (*p) || *p == '_');
a737bd4d 5392
21d799b5
NC
5393 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5394 p - start);
c19d1205
ZW
5395 if (!psr)
5396 goto error;
a737bd4d 5397
c19d1205 5398 psr_field |= psr->field;
a737bd4d 5399 }
c19d1205 5400 else
a737bd4d 5401 {
c19d1205
ZW
5402 if (ISALNUM (*p))
5403 goto error; /* Garbage after "[CS]PSR". */
5404
5405 psr_field |= (PSR_c | PSR_f);
a737bd4d 5406 }
c19d1205
ZW
5407 *str = p;
5408 return psr_field;
a737bd4d 5409
c19d1205
ZW
5410 error:
5411 inst.error = _("flag for {c}psr instruction expected");
5412 return FAIL;
a737bd4d
NC
5413}
5414
c19d1205
ZW
5415/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5416 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5417
c19d1205
ZW
5418static int
5419parse_cps_flags (char **str)
a737bd4d 5420{
c19d1205
ZW
5421 int val = 0;
5422 int saw_a_flag = 0;
5423 char *s = *str;
a737bd4d 5424
c19d1205
ZW
5425 for (;;)
5426 switch (*s++)
5427 {
5428 case '\0': case ',':
5429 goto done;
a737bd4d 5430
c19d1205
ZW
5431 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5432 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5433 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5434
c19d1205
ZW
5435 default:
5436 inst.error = _("unrecognized CPS flag");
5437 return FAIL;
5438 }
a737bd4d 5439
c19d1205
ZW
5440 done:
5441 if (saw_a_flag == 0)
a737bd4d 5442 {
c19d1205
ZW
5443 inst.error = _("missing CPS flags");
5444 return FAIL;
a737bd4d 5445 }
a737bd4d 5446
c19d1205
ZW
5447 *str = s - 1;
5448 return val;
a737bd4d
NC
5449}
5450
c19d1205
ZW
5451/* Parse an endian specifier ("BE" or "LE", case insensitive);
5452 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5453
5454static int
c19d1205 5455parse_endian_specifier (char **str)
a737bd4d 5456{
c19d1205
ZW
5457 int little_endian;
5458 char *s = *str;
a737bd4d 5459
c19d1205
ZW
5460 if (strncasecmp (s, "BE", 2))
5461 little_endian = 0;
5462 else if (strncasecmp (s, "LE", 2))
5463 little_endian = 1;
5464 else
a737bd4d 5465 {
c19d1205 5466 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5467 return FAIL;
5468 }
5469
c19d1205 5470 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5471 {
c19d1205 5472 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5473 return FAIL;
5474 }
5475
c19d1205
ZW
5476 *str = s + 2;
5477 return little_endian;
5478}
a737bd4d 5479
c19d1205
ZW
5480/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5481 value suitable for poking into the rotate field of an sxt or sxta
5482 instruction, or FAIL on error. */
5483
5484static int
5485parse_ror (char **str)
5486{
5487 int rot;
5488 char *s = *str;
5489
5490 if (strncasecmp (s, "ROR", 3) == 0)
5491 s += 3;
5492 else
a737bd4d 5493 {
c19d1205 5494 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5495 return FAIL;
5496 }
c19d1205
ZW
5497
5498 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5499 return FAIL;
5500
5501 switch (rot)
a737bd4d 5502 {
c19d1205
ZW
5503 case 0: *str = s; return 0x0;
5504 case 8: *str = s; return 0x1;
5505 case 16: *str = s; return 0x2;
5506 case 24: *str = s; return 0x3;
5507
5508 default:
5509 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5510 return FAIL;
5511 }
c19d1205 5512}
a737bd4d 5513
c19d1205
ZW
5514/* Parse a conditional code (from conds[] below). The value returned is in the
5515 range 0 .. 14, or FAIL. */
5516static int
5517parse_cond (char **str)
5518{
c462b453 5519 char *q;
c19d1205 5520 const struct asm_cond *c;
c462b453
PB
5521 int n;
5522 /* Condition codes are always 2 characters, so matching up to
5523 3 characters is sufficient. */
5524 char cond[3];
a737bd4d 5525
c462b453
PB
5526 q = *str;
5527 n = 0;
5528 while (ISALPHA (*q) && n < 3)
5529 {
e07e6e58 5530 cond[n] = TOLOWER (*q);
c462b453
PB
5531 q++;
5532 n++;
5533 }
a737bd4d 5534
21d799b5 5535 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5536 if (!c)
a737bd4d 5537 {
c19d1205 5538 inst.error = _("condition required");
a737bd4d
NC
5539 return FAIL;
5540 }
5541
c19d1205
ZW
5542 *str = q;
5543 return c->value;
5544}
5545
62b3e311
PB
5546/* Parse an option for a barrier instruction. Returns the encoding for the
5547 option, or FAIL. */
5548static int
5549parse_barrier (char **str)
5550{
5551 char *p, *q;
5552 const struct asm_barrier_opt *o;
5553
5554 p = q = *str;
5555 while (ISALPHA (*q))
5556 q++;
5557
21d799b5
NC
5558 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5559 q - p);
62b3e311
PB
5560 if (!o)
5561 return FAIL;
5562
5563 *str = q;
5564 return o->value;
5565}
5566
92e90b6e
PB
5567/* Parse the operands of a table branch instruction. Similar to a memory
5568 operand. */
5569static int
5570parse_tb (char **str)
5571{
5572 char * p = *str;
5573 int reg;
5574
5575 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5576 {
5577 inst.error = _("'[' expected");
5578 return FAIL;
5579 }
92e90b6e 5580
dcbf9037 5581 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5582 {
5583 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5584 return FAIL;
5585 }
5586 inst.operands[0].reg = reg;
5587
5588 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5589 {
5590 inst.error = _("',' expected");
5591 return FAIL;
5592 }
5f4273c7 5593
dcbf9037 5594 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5595 {
5596 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5597 return FAIL;
5598 }
5599 inst.operands[0].imm = reg;
5600
5601 if (skip_past_comma (&p) == SUCCESS)
5602 {
5603 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5604 return FAIL;
5605 if (inst.reloc.exp.X_add_number != 1)
5606 {
5607 inst.error = _("invalid shift");
5608 return FAIL;
5609 }
5610 inst.operands[0].shifted = 1;
5611 }
5612
5613 if (skip_past_char (&p, ']') == FAIL)
5614 {
5615 inst.error = _("']' expected");
5616 return FAIL;
5617 }
5618 *str = p;
5619 return SUCCESS;
5620}
5621
5287ad62
JB
5622/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5623 information on the types the operands can take and how they are encoded.
037e8744
JB
5624 Up to four operands may be read; this function handles setting the
5625 ".present" field for each read operand itself.
5287ad62
JB
5626 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5627 else returns FAIL. */
5628
5629static int
5630parse_neon_mov (char **str, int *which_operand)
5631{
5632 int i = *which_operand, val;
5633 enum arm_reg_type rtype;
5634 char *ptr = *str;
dcbf9037 5635 struct neon_type_el optype;
5f4273c7 5636
dcbf9037 5637 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5638 {
5639 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5640 inst.operands[i].reg = val;
5641 inst.operands[i].isscalar = 1;
dcbf9037 5642 inst.operands[i].vectype = optype;
5287ad62
JB
5643 inst.operands[i++].present = 1;
5644
5645 if (skip_past_comma (&ptr) == FAIL)
5646 goto wanted_comma;
5f4273c7 5647
dcbf9037 5648 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5649 goto wanted_arm;
5f4273c7 5650
5287ad62
JB
5651 inst.operands[i].reg = val;
5652 inst.operands[i].isreg = 1;
5653 inst.operands[i].present = 1;
5654 }
037e8744 5655 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5656 != FAIL)
5287ad62
JB
5657 {
5658 /* Cases 0, 1, 2, 3, 5 (D only). */
5659 if (skip_past_comma (&ptr) == FAIL)
5660 goto wanted_comma;
5f4273c7 5661
5287ad62
JB
5662 inst.operands[i].reg = val;
5663 inst.operands[i].isreg = 1;
5664 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5665 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5666 inst.operands[i].isvec = 1;
dcbf9037 5667 inst.operands[i].vectype = optype;
5287ad62
JB
5668 inst.operands[i++].present = 1;
5669
dcbf9037 5670 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5671 {
037e8744
JB
5672 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5673 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5674 inst.operands[i].reg = val;
5675 inst.operands[i].isreg = 1;
037e8744 5676 inst.operands[i].present = 1;
5287ad62
JB
5677
5678 if (rtype == REG_TYPE_NQ)
5679 {
dcbf9037 5680 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5681 return FAIL;
5682 }
037e8744
JB
5683 else if (rtype != REG_TYPE_VFS)
5684 {
5685 i++;
5686 if (skip_past_comma (&ptr) == FAIL)
5687 goto wanted_comma;
5688 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5689 goto wanted_arm;
5690 inst.operands[i].reg = val;
5691 inst.operands[i].isreg = 1;
5692 inst.operands[i].present = 1;
5693 }
5287ad62 5694 }
037e8744
JB
5695 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5696 &optype)) != FAIL)
5287ad62
JB
5697 {
5698 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5699 Case 1: VMOV<c><q> <Dd>, <Dm>
5700 Case 8: VMOV.F32 <Sd>, <Sm>
5701 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5702
5703 inst.operands[i].reg = val;
5704 inst.operands[i].isreg = 1;
5705 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5706 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5707 inst.operands[i].isvec = 1;
dcbf9037 5708 inst.operands[i].vectype = optype;
5287ad62 5709 inst.operands[i].present = 1;
5f4273c7 5710
037e8744
JB
5711 if (skip_past_comma (&ptr) == SUCCESS)
5712 {
5713 /* Case 15. */
5714 i++;
5715
5716 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5717 goto wanted_arm;
5718
5719 inst.operands[i].reg = val;
5720 inst.operands[i].isreg = 1;
5721 inst.operands[i++].present = 1;
5f4273c7 5722
037e8744
JB
5723 if (skip_past_comma (&ptr) == FAIL)
5724 goto wanted_comma;
5f4273c7 5725
037e8744
JB
5726 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5727 goto wanted_arm;
5f4273c7 5728
037e8744
JB
5729 inst.operands[i].reg = val;
5730 inst.operands[i].isreg = 1;
5731 inst.operands[i++].present = 1;
5732 }
5287ad62 5733 }
4641781c
PB
5734 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5735 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5736 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5737 Case 10: VMOV.F32 <Sd>, #<imm>
5738 Case 11: VMOV.F64 <Dd>, #<imm> */
5739 inst.operands[i].immisfloat = 1;
5740 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5741 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5742 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5743 ;
5287ad62
JB
5744 else
5745 {
dcbf9037 5746 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5747 return FAIL;
5748 }
5749 }
dcbf9037 5750 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5751 {
5752 /* Cases 6, 7. */
5753 inst.operands[i].reg = val;
5754 inst.operands[i].isreg = 1;
5755 inst.operands[i++].present = 1;
5f4273c7 5756
5287ad62
JB
5757 if (skip_past_comma (&ptr) == FAIL)
5758 goto wanted_comma;
5f4273c7 5759
dcbf9037 5760 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5761 {
5762 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5763 inst.operands[i].reg = val;
5764 inst.operands[i].isscalar = 1;
5765 inst.operands[i].present = 1;
dcbf9037 5766 inst.operands[i].vectype = optype;
5287ad62 5767 }
dcbf9037 5768 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5769 {
5770 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5771 inst.operands[i].reg = val;
5772 inst.operands[i].isreg = 1;
5773 inst.operands[i++].present = 1;
5f4273c7 5774
5287ad62
JB
5775 if (skip_past_comma (&ptr) == FAIL)
5776 goto wanted_comma;
5f4273c7 5777
037e8744 5778 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5779 == FAIL)
5287ad62 5780 {
037e8744 5781 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5782 return FAIL;
5783 }
5784
5785 inst.operands[i].reg = val;
5786 inst.operands[i].isreg = 1;
037e8744
JB
5787 inst.operands[i].isvec = 1;
5788 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5789 inst.operands[i].vectype = optype;
5287ad62 5790 inst.operands[i].present = 1;
5f4273c7 5791
037e8744
JB
5792 if (rtype == REG_TYPE_VFS)
5793 {
5794 /* Case 14. */
5795 i++;
5796 if (skip_past_comma (&ptr) == FAIL)
5797 goto wanted_comma;
5798 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5799 &optype)) == FAIL)
5800 {
5801 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5802 return FAIL;
5803 }
5804 inst.operands[i].reg = val;
5805 inst.operands[i].isreg = 1;
5806 inst.operands[i].isvec = 1;
5807 inst.operands[i].issingle = 1;
5808 inst.operands[i].vectype = optype;
5809 inst.operands[i].present = 1;
5810 }
5811 }
5812 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5813 != FAIL)
5814 {
5815 /* Case 13. */
5816 inst.operands[i].reg = val;
5817 inst.operands[i].isreg = 1;
5818 inst.operands[i].isvec = 1;
5819 inst.operands[i].issingle = 1;
5820 inst.operands[i].vectype = optype;
5821 inst.operands[i++].present = 1;
5287ad62
JB
5822 }
5823 }
5824 else
5825 {
dcbf9037 5826 first_error (_("parse error"));
5287ad62
JB
5827 return FAIL;
5828 }
5829
5830 /* Successfully parsed the operands. Update args. */
5831 *which_operand = i;
5832 *str = ptr;
5833 return SUCCESS;
5834
5f4273c7 5835 wanted_comma:
dcbf9037 5836 first_error (_("expected comma"));
5287ad62 5837 return FAIL;
5f4273c7
NC
5838
5839 wanted_arm:
dcbf9037 5840 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5841 return FAIL;
5287ad62
JB
5842}
5843
5be8be5d
DG
5844/* Use this macro when the operand constraints are different
5845 for ARM and THUMB (e.g. ldrd). */
5846#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
5847 ((arm_operand) | ((thumb_operand) << 16))
5848
c19d1205
ZW
5849/* Matcher codes for parse_operands. */
5850enum operand_parse_code
5851{
5852 OP_stop, /* end of line */
5853
5854 OP_RR, /* ARM register */
5855 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 5856 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 5857 OP_RRnpcb, /* ARM register, not r15, in square brackets */
55881a11
MGD
5858 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
5859 optional trailing ! */
c19d1205
ZW
5860 OP_RRw, /* ARM register, not r15, optional trailing ! */
5861 OP_RCP, /* Coprocessor number */
5862 OP_RCN, /* Coprocessor register */
5863 OP_RF, /* FPA register */
5864 OP_RVS, /* VFP single precision register */
5287ad62
JB
5865 OP_RVD, /* VFP double precision register (0..15) */
5866 OP_RND, /* Neon double precision register (0..31) */
5867 OP_RNQ, /* Neon quad precision register */
037e8744 5868 OP_RVSD, /* VFP single or double precision register */
5287ad62 5869 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5870 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5871 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5872 OP_RVC, /* VFP control register */
5873 OP_RMF, /* Maverick F register */
5874 OP_RMD, /* Maverick D register */
5875 OP_RMFX, /* Maverick FX register */
5876 OP_RMDX, /* Maverick DX register */
5877 OP_RMAX, /* Maverick AX register */
5878 OP_RMDS, /* Maverick DSPSC register */
5879 OP_RIWR, /* iWMMXt wR register */
5880 OP_RIWC, /* iWMMXt wC register */
5881 OP_RIWG, /* iWMMXt wCG register */
5882 OP_RXA, /* XScale accumulator register */
5883
5884 OP_REGLST, /* ARM register list */
5885 OP_VRSLST, /* VFP single-precision register list */
5886 OP_VRDLST, /* VFP double-precision register list */
037e8744 5887 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5888 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5889 OP_NSTRLST, /* Neon element/structure list */
5890
5287ad62 5891 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5892 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5893 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5894 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5895 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5896 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5897 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 5898 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 5899 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5900 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5901
5902 OP_I0, /* immediate zero */
c19d1205
ZW
5903 OP_I7, /* immediate value 0 .. 7 */
5904 OP_I15, /* 0 .. 15 */
5905 OP_I16, /* 1 .. 16 */
5287ad62 5906 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5907 OP_I31, /* 0 .. 31 */
5908 OP_I31w, /* 0 .. 31, optional trailing ! */
5909 OP_I32, /* 1 .. 32 */
5287ad62
JB
5910 OP_I32z, /* 0 .. 32 */
5911 OP_I63, /* 0 .. 63 */
c19d1205 5912 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5913 OP_I64, /* 1 .. 64 */
5914 OP_I64z, /* 0 .. 64 */
c19d1205 5915 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5916
5917 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5918 OP_I7b, /* 0 .. 7 */
5919 OP_I15b, /* 0 .. 15 */
5920 OP_I31b, /* 0 .. 31 */
5921
5922 OP_SH, /* shifter operand */
4962c51a 5923 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5924 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5925 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5926 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5927 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5928 OP_EXP, /* arbitrary expression */
5929 OP_EXPi, /* same, with optional immediate prefix */
5930 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5931 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5932
5933 OP_CPSF, /* CPS flags */
5934 OP_ENDI, /* Endianness specifier */
5935 OP_PSR, /* CPSR/SPSR mask for msr */
5936 OP_COND, /* conditional code */
92e90b6e 5937 OP_TB, /* Table branch. */
c19d1205 5938
037e8744
JB
5939 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5940 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5941
c19d1205
ZW
5942 OP_RRnpc_I0, /* ARM register or literal 0 */
5943 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5944 OP_RR_EXi, /* ARM register or expression with imm prefix */
5945 OP_RF_IF, /* FPA register or immediate */
5946 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5947 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5948
5949 /* Optional operands. */
5950 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5951 OP_oI31b, /* 0 .. 31 */
5287ad62 5952 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5953 OP_oIffffb, /* 0 .. 65535 */
5954 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5955
5956 OP_oRR, /* ARM register */
5957 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 5958 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 5959 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5960 OP_oRND, /* Optional Neon double precision register */
5961 OP_oRNQ, /* Optional Neon quad precision register */
5962 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5963 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5964 OP_oSHll, /* LSL immediate */
5965 OP_oSHar, /* ASR immediate */
5966 OP_oSHllar, /* LSL or ASR immediate */
5967 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 5968 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 5969
5be8be5d
DG
5970 /* Some pre-defined mixed (ARM/THUMB) operands. */
5971 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
5972 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
5973 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
5974
c19d1205
ZW
5975 OP_FIRST_OPTIONAL = OP_oI7b
5976};
a737bd4d 5977
c19d1205
ZW
5978/* Generic instruction operand parser. This does no encoding and no
5979 semantic validation; it merely squirrels values away in the inst
5980 structure. Returns SUCCESS or FAIL depending on whether the
5981 specified grammar matched. */
5982static int
5be8be5d 5983parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 5984{
5be8be5d 5985 unsigned const int *upat = pattern;
c19d1205
ZW
5986 char *backtrack_pos = 0;
5987 const char *backtrack_error = 0;
5988 int i, val, backtrack_index = 0;
5287ad62 5989 enum arm_reg_type rtype;
4962c51a 5990 parse_operand_result result;
5be8be5d 5991 unsigned int op_parse_code;
c19d1205 5992
e07e6e58
NC
5993#define po_char_or_fail(chr) \
5994 do \
5995 { \
5996 if (skip_past_char (&str, chr) == FAIL) \
5997 goto bad_args; \
5998 } \
5999 while (0)
c19d1205 6000
e07e6e58
NC
6001#define po_reg_or_fail(regtype) \
6002 do \
dcbf9037 6003 { \
e07e6e58
NC
6004 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6005 & inst.operands[i].vectype); \
6006 if (val == FAIL) \
6007 { \
6008 first_error (_(reg_expected_msgs[regtype])); \
6009 goto failure; \
6010 } \
6011 inst.operands[i].reg = val; \
6012 inst.operands[i].isreg = 1; \
6013 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6014 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6015 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6016 || rtype == REG_TYPE_VFD \
6017 || rtype == REG_TYPE_NQ); \
dcbf9037 6018 } \
e07e6e58
NC
6019 while (0)
6020
6021#define po_reg_or_goto(regtype, label) \
6022 do \
6023 { \
6024 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6025 & inst.operands[i].vectype); \
6026 if (val == FAIL) \
6027 goto label; \
dcbf9037 6028 \
e07e6e58
NC
6029 inst.operands[i].reg = val; \
6030 inst.operands[i].isreg = 1; \
6031 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6032 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6033 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6034 || rtype == REG_TYPE_VFD \
6035 || rtype == REG_TYPE_NQ); \
6036 } \
6037 while (0)
6038
6039#define po_imm_or_fail(min, max, popt) \
6040 do \
6041 { \
6042 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6043 goto failure; \
6044 inst.operands[i].imm = val; \
6045 } \
6046 while (0)
6047
6048#define po_scalar_or_goto(elsz, label) \
6049 do \
6050 { \
6051 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6052 if (val == FAIL) \
6053 goto label; \
6054 inst.operands[i].reg = val; \
6055 inst.operands[i].isscalar = 1; \
6056 } \
6057 while (0)
6058
6059#define po_misc_or_fail(expr) \
6060 do \
6061 { \
6062 if (expr) \
6063 goto failure; \
6064 } \
6065 while (0)
6066
6067#define po_misc_or_fail_no_backtrack(expr) \
6068 do \
6069 { \
6070 result = expr; \
6071 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6072 backtrack_pos = 0; \
6073 if (result != PARSE_OPERAND_SUCCESS) \
6074 goto failure; \
6075 } \
6076 while (0)
4962c51a 6077
52e7f43d
RE
6078#define po_barrier_or_imm(str) \
6079 do \
6080 { \
6081 val = parse_barrier (&str); \
6082 if (val == FAIL) \
6083 { \
6084 if (ISALPHA (*str)) \
6085 goto failure; \
6086 else \
6087 goto immediate; \
6088 } \
6089 else \
6090 { \
6091 if ((inst.instruction & 0xf0) == 0x60 \
6092 && val != 0xf) \
6093 { \
6094 /* ISB can only take SY as an option. */ \
6095 inst.error = _("invalid barrier type"); \
6096 goto failure; \
6097 } \
6098 } \
6099 } \
6100 while (0)
6101
c19d1205
ZW
6102 skip_whitespace (str);
6103
6104 for (i = 0; upat[i] != OP_stop; i++)
6105 {
5be8be5d
DG
6106 op_parse_code = upat[i];
6107 if (op_parse_code >= 1<<16)
6108 op_parse_code = thumb ? (op_parse_code >> 16)
6109 : (op_parse_code & ((1<<16)-1));
6110
6111 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6112 {
6113 /* Remember where we are in case we need to backtrack. */
9c2799c2 6114 gas_assert (!backtrack_pos);
c19d1205
ZW
6115 backtrack_pos = str;
6116 backtrack_error = inst.error;
6117 backtrack_index = i;
6118 }
6119
b6702015 6120 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6121 po_char_or_fail (',');
6122
5be8be5d 6123 switch (op_parse_code)
c19d1205
ZW
6124 {
6125 /* Registers */
6126 case OP_oRRnpc:
5be8be5d 6127 case OP_oRRnpcsp:
c19d1205 6128 case OP_RRnpc:
5be8be5d 6129 case OP_RRnpcsp:
c19d1205
ZW
6130 case OP_oRR:
6131 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6132 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6133 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6134 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6135 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6136 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
6137 case OP_oRND:
6138 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6139 case OP_RVC:
6140 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6141 break;
6142 /* Also accept generic coprocessor regs for unknown registers. */
6143 coproc_reg:
6144 po_reg_or_fail (REG_TYPE_CN);
6145 break;
c19d1205
ZW
6146 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6147 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6148 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6149 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6150 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6151 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6152 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6153 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6154 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6155 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
6156 case OP_oRNQ:
6157 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6158 case OP_oRNDQ:
6159 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
6160 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6161 case OP_oRNSDQ:
6162 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
6163
6164 /* Neon scalar. Using an element size of 8 means that some invalid
6165 scalars are accepted here, so deal with those in later code. */
6166 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6167
5287ad62
JB
6168 case OP_RNDQ_I0:
6169 {
6170 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6171 break;
6172 try_imm0:
6173 po_imm_or_fail (0, 0, TRUE);
6174 }
6175 break;
6176
037e8744
JB
6177 case OP_RVSD_I0:
6178 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6179 break;
6180
5287ad62
JB
6181 case OP_RR_RNSC:
6182 {
6183 po_scalar_or_goto (8, try_rr);
6184 break;
6185 try_rr:
6186 po_reg_or_fail (REG_TYPE_RN);
6187 }
6188 break;
6189
037e8744
JB
6190 case OP_RNSDQ_RNSC:
6191 {
6192 po_scalar_or_goto (8, try_nsdq);
6193 break;
6194 try_nsdq:
6195 po_reg_or_fail (REG_TYPE_NSDQ);
6196 }
6197 break;
6198
5287ad62
JB
6199 case OP_RNDQ_RNSC:
6200 {
6201 po_scalar_or_goto (8, try_ndq);
6202 break;
6203 try_ndq:
6204 po_reg_or_fail (REG_TYPE_NDQ);
6205 }
6206 break;
6207
6208 case OP_RND_RNSC:
6209 {
6210 po_scalar_or_goto (8, try_vfd);
6211 break;
6212 try_vfd:
6213 po_reg_or_fail (REG_TYPE_VFD);
6214 }
6215 break;
6216
6217 case OP_VMOV:
6218 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6219 not careful then bad things might happen. */
6220 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6221 break;
6222
4316f0d2 6223 case OP_RNDQ_Ibig:
5287ad62 6224 {
4316f0d2 6225 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
5287ad62 6226 break;
4316f0d2 6227 try_immbig:
5287ad62
JB
6228 /* There's a possibility of getting a 64-bit immediate here, so
6229 we need special handling. */
6230 if (parse_big_immediate (&str, i) == FAIL)
6231 {
6232 inst.error = _("immediate value is out of range");
6233 goto failure;
6234 }
6235 }
6236 break;
6237
6238 case OP_RNDQ_I63b:
6239 {
6240 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6241 break;
6242 try_shimm:
6243 po_imm_or_fail (0, 63, TRUE);
6244 }
6245 break;
c19d1205
ZW
6246
6247 case OP_RRnpcb:
6248 po_char_or_fail ('[');
6249 po_reg_or_fail (REG_TYPE_RN);
6250 po_char_or_fail (']');
6251 break;
a737bd4d 6252
55881a11 6253 case OP_RRnpctw:
c19d1205 6254 case OP_RRw:
b6702015 6255 case OP_oRRw:
c19d1205
ZW
6256 po_reg_or_fail (REG_TYPE_RN);
6257 if (skip_past_char (&str, '!') == SUCCESS)
6258 inst.operands[i].writeback = 1;
6259 break;
6260
6261 /* Immediates */
6262 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6263 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6264 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 6265 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6266 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6267 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 6268 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6269 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
6270 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6271 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6272 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6273 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6274
6275 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6276 case OP_oI7b:
6277 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6278 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6279 case OP_oI31b:
6280 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 6281 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
6282 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6283
6284 /* Immediate variants */
6285 case OP_oI255c:
6286 po_char_or_fail ('{');
6287 po_imm_or_fail (0, 255, TRUE);
6288 po_char_or_fail ('}');
6289 break;
6290
6291 case OP_I31w:
6292 /* The expression parser chokes on a trailing !, so we have
6293 to find it first and zap it. */
6294 {
6295 char *s = str;
6296 while (*s && *s != ',')
6297 s++;
6298 if (s[-1] == '!')
6299 {
6300 s[-1] = '\0';
6301 inst.operands[i].writeback = 1;
6302 }
6303 po_imm_or_fail (0, 31, TRUE);
6304 if (str == s - 1)
6305 str = s;
6306 }
6307 break;
6308
6309 /* Expressions */
6310 case OP_EXPi: EXPi:
6311 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6312 GE_OPT_PREFIX));
6313 break;
6314
6315 case OP_EXP:
6316 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6317 GE_NO_PREFIX));
6318 break;
6319
6320 case OP_EXPr: EXPr:
6321 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6322 GE_NO_PREFIX));
6323 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6324 {
c19d1205
ZW
6325 val = parse_reloc (&str);
6326 if (val == -1)
6327 {
6328 inst.error = _("unrecognized relocation suffix");
6329 goto failure;
6330 }
6331 else if (val != BFD_RELOC_UNUSED)
6332 {
6333 inst.operands[i].imm = val;
6334 inst.operands[i].hasreloc = 1;
6335 }
a737bd4d 6336 }
c19d1205 6337 break;
a737bd4d 6338
b6895b4f
PB
6339 /* Operand for MOVW or MOVT. */
6340 case OP_HALF:
6341 po_misc_or_fail (parse_half (&str));
6342 break;
6343
e07e6e58 6344 /* Register or expression. */
c19d1205
ZW
6345 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6346 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6347
e07e6e58 6348 /* Register or immediate. */
c19d1205
ZW
6349 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6350 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6351
c19d1205
ZW
6352 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6353 IF:
6354 if (!is_immediate_prefix (*str))
6355 goto bad_args;
6356 str++;
6357 val = parse_fpa_immediate (&str);
6358 if (val == FAIL)
6359 goto failure;
6360 /* FPA immediates are encoded as registers 8-15.
6361 parse_fpa_immediate has already applied the offset. */
6362 inst.operands[i].reg = val;
6363 inst.operands[i].isreg = 1;
6364 break;
09d92015 6365
2d447fca
JM
6366 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6367 I32z: po_imm_or_fail (0, 32, FALSE); break;
6368
e07e6e58 6369 /* Two kinds of register. */
c19d1205
ZW
6370 case OP_RIWR_RIWC:
6371 {
6372 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6373 if (!rege
6374 || (rege->type != REG_TYPE_MMXWR
6375 && rege->type != REG_TYPE_MMXWC
6376 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6377 {
6378 inst.error = _("iWMMXt data or control register expected");
6379 goto failure;
6380 }
6381 inst.operands[i].reg = rege->number;
6382 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6383 }
6384 break;
09d92015 6385
41adaa5c
JM
6386 case OP_RIWC_RIWG:
6387 {
6388 struct reg_entry *rege = arm_reg_parse_multi (&str);
6389 if (!rege
6390 || (rege->type != REG_TYPE_MMXWC
6391 && rege->type != REG_TYPE_MMXWCG))
6392 {
6393 inst.error = _("iWMMXt control register expected");
6394 goto failure;
6395 }
6396 inst.operands[i].reg = rege->number;
6397 inst.operands[i].isreg = 1;
6398 }
6399 break;
6400
c19d1205
ZW
6401 /* Misc */
6402 case OP_CPSF: val = parse_cps_flags (&str); break;
6403 case OP_ENDI: val = parse_endian_specifier (&str); break;
6404 case OP_oROR: val = parse_ror (&str); break;
6405 case OP_PSR: val = parse_psr (&str); break;
6406 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6407 case OP_oBARRIER_I15:
6408 po_barrier_or_imm (str); break;
6409 immediate:
6410 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6411 goto failure;
6412 break;
c19d1205 6413
037e8744 6414 case OP_RVC_PSR:
90ec0d68 6415 po_reg_or_goto (REG_TYPE_VFC, try_banked_reg);
037e8744
JB
6416 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6417 break;
90ec0d68
MGD
6418 try_banked_reg:
6419 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6420 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6421 {
6422 inst.error = _("Banked registers are not available with this "
6423 "architecture.");
6424 goto failure;
6425 }
6426 break;
037e8744
JB
6427 try_psr:
6428 val = parse_psr (&str);
6429 break;
6430
6431 case OP_APSR_RR:
6432 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6433 break;
6434 try_apsr:
6435 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6436 instruction). */
6437 if (strncasecmp (str, "APSR_", 5) == 0)
6438 {
6439 unsigned found = 0;
6440 str += 5;
6441 while (found < 15)
6442 switch (*str++)
6443 {
6444 case 'c': found = (found & 1) ? 16 : found | 1; break;
6445 case 'n': found = (found & 2) ? 16 : found | 2; break;
6446 case 'z': found = (found & 4) ? 16 : found | 4; break;
6447 case 'v': found = (found & 8) ? 16 : found | 8; break;
6448 default: found = 16;
6449 }
6450 if (found != 15)
6451 goto failure;
6452 inst.operands[i].isvec = 1;
f7c21dc7
NC
6453 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6454 inst.operands[i].reg = REG_PC;
037e8744
JB
6455 }
6456 else
6457 goto failure;
6458 break;
6459
92e90b6e
PB
6460 case OP_TB:
6461 po_misc_or_fail (parse_tb (&str));
6462 break;
6463
e07e6e58 6464 /* Register lists. */
c19d1205
ZW
6465 case OP_REGLST:
6466 val = parse_reg_list (&str);
6467 if (*str == '^')
6468 {
6469 inst.operands[1].writeback = 1;
6470 str++;
6471 }
6472 break;
09d92015 6473
c19d1205 6474 case OP_VRSLST:
5287ad62 6475 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6476 break;
09d92015 6477
c19d1205 6478 case OP_VRDLST:
5287ad62 6479 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6480 break;
a737bd4d 6481
037e8744
JB
6482 case OP_VRSDLST:
6483 /* Allow Q registers too. */
6484 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6485 REGLIST_NEON_D);
6486 if (val == FAIL)
6487 {
6488 inst.error = NULL;
6489 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6490 REGLIST_VFP_S);
6491 inst.operands[i].issingle = 1;
6492 }
6493 break;
6494
5287ad62
JB
6495 case OP_NRDLST:
6496 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6497 REGLIST_NEON_D);
6498 break;
6499
6500 case OP_NSTRLST:
dcbf9037
JB
6501 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6502 &inst.operands[i].vectype);
5287ad62
JB
6503 break;
6504
c19d1205
ZW
6505 /* Addressing modes */
6506 case OP_ADDR:
6507 po_misc_or_fail (parse_address (&str, i));
6508 break;
09d92015 6509
4962c51a
MS
6510 case OP_ADDRGLDR:
6511 po_misc_or_fail_no_backtrack (
6512 parse_address_group_reloc (&str, i, GROUP_LDR));
6513 break;
6514
6515 case OP_ADDRGLDRS:
6516 po_misc_or_fail_no_backtrack (
6517 parse_address_group_reloc (&str, i, GROUP_LDRS));
6518 break;
6519
6520 case OP_ADDRGLDC:
6521 po_misc_or_fail_no_backtrack (
6522 parse_address_group_reloc (&str, i, GROUP_LDC));
6523 break;
6524
c19d1205
ZW
6525 case OP_SH:
6526 po_misc_or_fail (parse_shifter_operand (&str, i));
6527 break;
09d92015 6528
4962c51a
MS
6529 case OP_SHG:
6530 po_misc_or_fail_no_backtrack (
6531 parse_shifter_operand_group_reloc (&str, i));
6532 break;
6533
c19d1205
ZW
6534 case OP_oSHll:
6535 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6536 break;
09d92015 6537
c19d1205
ZW
6538 case OP_oSHar:
6539 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6540 break;
09d92015 6541
c19d1205
ZW
6542 case OP_oSHllar:
6543 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6544 break;
09d92015 6545
c19d1205 6546 default:
5be8be5d 6547 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 6548 }
09d92015 6549
c19d1205
ZW
6550 /* Various value-based sanity checks and shared operations. We
6551 do not signal immediate failures for the register constraints;
6552 this allows a syntax error to take precedence. */
5be8be5d 6553 switch (op_parse_code)
c19d1205
ZW
6554 {
6555 case OP_oRRnpc:
6556 case OP_RRnpc:
6557 case OP_RRnpcb:
6558 case OP_RRw:
b6702015 6559 case OP_oRRw:
c19d1205
ZW
6560 case OP_RRnpc_I0:
6561 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6562 inst.error = BAD_PC;
6563 break;
09d92015 6564
5be8be5d
DG
6565 case OP_oRRnpcsp:
6566 case OP_RRnpcsp:
6567 if (inst.operands[i].isreg)
6568 {
6569 if (inst.operands[i].reg == REG_PC)
6570 inst.error = BAD_PC;
6571 else if (inst.operands[i].reg == REG_SP)
6572 inst.error = BAD_SP;
6573 }
6574 break;
6575
55881a11
MGD
6576 case OP_RRnpctw:
6577 if (inst.operands[i].isreg
6578 && inst.operands[i].reg == REG_PC
6579 && (inst.operands[i].writeback || thumb))
6580 inst.error = BAD_PC;
6581 break;
6582
c19d1205
ZW
6583 case OP_CPSF:
6584 case OP_ENDI:
6585 case OP_oROR:
6586 case OP_PSR:
037e8744 6587 case OP_RVC_PSR:
c19d1205 6588 case OP_COND:
52e7f43d 6589 case OP_oBARRIER_I15:
c19d1205
ZW
6590 case OP_REGLST:
6591 case OP_VRSLST:
6592 case OP_VRDLST:
037e8744 6593 case OP_VRSDLST:
5287ad62
JB
6594 case OP_NRDLST:
6595 case OP_NSTRLST:
c19d1205
ZW
6596 if (val == FAIL)
6597 goto failure;
6598 inst.operands[i].imm = val;
6599 break;
a737bd4d 6600
c19d1205
ZW
6601 default:
6602 break;
6603 }
09d92015 6604
c19d1205
ZW
6605 /* If we get here, this operand was successfully parsed. */
6606 inst.operands[i].present = 1;
6607 continue;
09d92015 6608
c19d1205 6609 bad_args:
09d92015 6610 inst.error = BAD_ARGS;
c19d1205
ZW
6611
6612 failure:
6613 if (!backtrack_pos)
d252fdde
PB
6614 {
6615 /* The parse routine should already have set inst.error, but set a
5f4273c7 6616 default here just in case. */
d252fdde
PB
6617 if (!inst.error)
6618 inst.error = _("syntax error");
6619 return FAIL;
6620 }
c19d1205
ZW
6621
6622 /* Do not backtrack over a trailing optional argument that
6623 absorbed some text. We will only fail again, with the
6624 'garbage following instruction' error message, which is
6625 probably less helpful than the current one. */
6626 if (backtrack_index == i && backtrack_pos != str
6627 && upat[i+1] == OP_stop)
d252fdde
PB
6628 {
6629 if (!inst.error)
6630 inst.error = _("syntax error");
6631 return FAIL;
6632 }
c19d1205
ZW
6633
6634 /* Try again, skipping the optional argument at backtrack_pos. */
6635 str = backtrack_pos;
6636 inst.error = backtrack_error;
6637 inst.operands[backtrack_index].present = 0;
6638 i = backtrack_index;
6639 backtrack_pos = 0;
09d92015 6640 }
09d92015 6641
c19d1205
ZW
6642 /* Check that we have parsed all the arguments. */
6643 if (*str != '\0' && !inst.error)
6644 inst.error = _("garbage following instruction");
09d92015 6645
c19d1205 6646 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6647}
6648
c19d1205
ZW
6649#undef po_char_or_fail
6650#undef po_reg_or_fail
6651#undef po_reg_or_goto
6652#undef po_imm_or_fail
5287ad62 6653#undef po_scalar_or_fail
52e7f43d 6654#undef po_barrier_or_imm
e07e6e58 6655
c19d1205 6656/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6657#define constraint(expr, err) \
6658 do \
c19d1205 6659 { \
e07e6e58
NC
6660 if (expr) \
6661 { \
6662 inst.error = err; \
6663 return; \
6664 } \
c19d1205 6665 } \
e07e6e58 6666 while (0)
c19d1205 6667
fdfde340
JM
6668/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6669 instructions are unpredictable if these registers are used. This
6670 is the BadReg predicate in ARM's Thumb-2 documentation. */
6671#define reject_bad_reg(reg) \
6672 do \
6673 if (reg == REG_SP || reg == REG_PC) \
6674 { \
6675 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6676 return; \
6677 } \
6678 while (0)
6679
94206790
MM
6680/* If REG is R13 (the stack pointer), warn that its use is
6681 deprecated. */
6682#define warn_deprecated_sp(reg) \
6683 do \
6684 if (warn_on_deprecated && reg == REG_SP) \
6685 as_warn (_("use of r13 is deprecated")); \
6686 while (0)
6687
c19d1205
ZW
6688/* Functions for operand encoding. ARM, then Thumb. */
6689
6690#define rotate_left(v, n) (v << n | v >> (32 - n))
6691
6692/* If VAL can be encoded in the immediate field of an ARM instruction,
6693 return the encoded form. Otherwise, return FAIL. */
6694
6695static unsigned int
6696encode_arm_immediate (unsigned int val)
09d92015 6697{
c19d1205
ZW
6698 unsigned int a, i;
6699
6700 for (i = 0; i < 32; i += 2)
6701 if ((a = rotate_left (val, i)) <= 0xff)
6702 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6703
6704 return FAIL;
09d92015
MM
6705}
6706
c19d1205
ZW
6707/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6708 return the encoded form. Otherwise, return FAIL. */
6709static unsigned int
6710encode_thumb32_immediate (unsigned int val)
09d92015 6711{
c19d1205 6712 unsigned int a, i;
09d92015 6713
9c3c69f2 6714 if (val <= 0xff)
c19d1205 6715 return val;
a737bd4d 6716
9c3c69f2 6717 for (i = 1; i <= 24; i++)
09d92015 6718 {
9c3c69f2
PB
6719 a = val >> i;
6720 if ((val & ~(0xff << i)) == 0)
6721 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6722 }
a737bd4d 6723
c19d1205
ZW
6724 a = val & 0xff;
6725 if (val == ((a << 16) | a))
6726 return 0x100 | a;
6727 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6728 return 0x300 | a;
09d92015 6729
c19d1205
ZW
6730 a = val & 0xff00;
6731 if (val == ((a << 16) | a))
6732 return 0x200 | (a >> 8);
a737bd4d 6733
c19d1205 6734 return FAIL;
09d92015 6735}
5287ad62 6736/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6737
6738static void
5287ad62
JB
6739encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6740{
6741 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6742 && reg > 15)
6743 {
b1cc4aeb 6744 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6745 {
6746 if (thumb_mode)
6747 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6748 fpu_vfp_ext_d32);
5287ad62
JB
6749 else
6750 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6751 fpu_vfp_ext_d32);
5287ad62
JB
6752 }
6753 else
6754 {
dcbf9037 6755 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6756 return;
6757 }
6758 }
6759
c19d1205 6760 switch (pos)
09d92015 6761 {
c19d1205
ZW
6762 case VFP_REG_Sd:
6763 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6764 break;
6765
6766 case VFP_REG_Sn:
6767 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6768 break;
6769
6770 case VFP_REG_Sm:
6771 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6772 break;
6773
5287ad62
JB
6774 case VFP_REG_Dd:
6775 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6776 break;
5f4273c7 6777
5287ad62
JB
6778 case VFP_REG_Dn:
6779 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6780 break;
5f4273c7 6781
5287ad62
JB
6782 case VFP_REG_Dm:
6783 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6784 break;
6785
c19d1205
ZW
6786 default:
6787 abort ();
09d92015 6788 }
09d92015
MM
6789}
6790
c19d1205 6791/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6792 if any, is handled by md_apply_fix. */
09d92015 6793static void
c19d1205 6794encode_arm_shift (int i)
09d92015 6795{
c19d1205
ZW
6796 if (inst.operands[i].shift_kind == SHIFT_RRX)
6797 inst.instruction |= SHIFT_ROR << 5;
6798 else
09d92015 6799 {
c19d1205
ZW
6800 inst.instruction |= inst.operands[i].shift_kind << 5;
6801 if (inst.operands[i].immisreg)
6802 {
6803 inst.instruction |= SHIFT_BY_REG;
6804 inst.instruction |= inst.operands[i].imm << 8;
6805 }
6806 else
6807 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6808 }
c19d1205 6809}
09d92015 6810
c19d1205
ZW
6811static void
6812encode_arm_shifter_operand (int i)
6813{
6814 if (inst.operands[i].isreg)
09d92015 6815 {
c19d1205
ZW
6816 inst.instruction |= inst.operands[i].reg;
6817 encode_arm_shift (i);
09d92015 6818 }
c19d1205
ZW
6819 else
6820 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6821}
6822
c19d1205 6823/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6824static void
c19d1205 6825encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6826{
9c2799c2 6827 gas_assert (inst.operands[i].isreg);
c19d1205 6828 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6829
c19d1205 6830 if (inst.operands[i].preind)
09d92015 6831 {
c19d1205
ZW
6832 if (is_t)
6833 {
6834 inst.error = _("instruction does not accept preindexed addressing");
6835 return;
6836 }
6837 inst.instruction |= PRE_INDEX;
6838 if (inst.operands[i].writeback)
6839 inst.instruction |= WRITE_BACK;
09d92015 6840
c19d1205
ZW
6841 }
6842 else if (inst.operands[i].postind)
6843 {
9c2799c2 6844 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
6845 if (is_t)
6846 inst.instruction |= WRITE_BACK;
6847 }
6848 else /* unindexed - only for coprocessor */
09d92015 6849 {
c19d1205 6850 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6851 return;
6852 }
6853
c19d1205
ZW
6854 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6855 && (((inst.instruction & 0x000f0000) >> 16)
6856 == ((inst.instruction & 0x0000f000) >> 12)))
6857 as_warn ((inst.instruction & LOAD_BIT)
6858 ? _("destination register same as write-back base")
6859 : _("source register same as write-back base"));
09d92015
MM
6860}
6861
c19d1205
ZW
6862/* inst.operands[i] was set up by parse_address. Encode it into an
6863 ARM-format mode 2 load or store instruction. If is_t is true,
6864 reject forms that cannot be used with a T instruction (i.e. not
6865 post-indexed). */
a737bd4d 6866static void
c19d1205 6867encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6868{
5be8be5d
DG
6869 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
6870
c19d1205 6871 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6872
c19d1205 6873 if (inst.operands[i].immisreg)
09d92015 6874 {
5be8be5d
DG
6875 constraint ((inst.operands[i].imm == REG_PC
6876 || (is_pc && inst.operands[i].writeback)),
6877 BAD_PC_ADDRESSING);
c19d1205
ZW
6878 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6879 inst.instruction |= inst.operands[i].imm;
6880 if (!inst.operands[i].negative)
6881 inst.instruction |= INDEX_UP;
6882 if (inst.operands[i].shifted)
6883 {
6884 if (inst.operands[i].shift_kind == SHIFT_RRX)
6885 inst.instruction |= SHIFT_ROR << 5;
6886 else
6887 {
6888 inst.instruction |= inst.operands[i].shift_kind << 5;
6889 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6890 }
6891 }
09d92015 6892 }
c19d1205 6893 else /* immediate offset in inst.reloc */
09d92015 6894 {
5be8be5d
DG
6895 if (is_pc && !inst.reloc.pc_rel)
6896 {
6897 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
6898
6899 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
6900 cannot use PC in addressing.
6901 PC cannot be used in writeback addressing, either. */
6902 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 6903 BAD_PC_ADDRESSING);
23a10334 6904
dc5ec521 6905 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
6906 if (warn_on_deprecated
6907 && !is_load
6908 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
6909 as_warn (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
6910 }
6911
c19d1205
ZW
6912 if (inst.reloc.type == BFD_RELOC_UNUSED)
6913 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6914 }
09d92015
MM
6915}
6916
c19d1205
ZW
6917/* inst.operands[i] was set up by parse_address. Encode it into an
6918 ARM-format mode 3 load or store instruction. Reject forms that
6919 cannot be used with such instructions. If is_t is true, reject
6920 forms that cannot be used with a T instruction (i.e. not
6921 post-indexed). */
6922static void
6923encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6924{
c19d1205 6925 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6926 {
c19d1205
ZW
6927 inst.error = _("instruction does not accept scaled register index");
6928 return;
09d92015 6929 }
a737bd4d 6930
c19d1205 6931 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6932
c19d1205
ZW
6933 if (inst.operands[i].immisreg)
6934 {
5be8be5d
DG
6935 constraint ((inst.operands[i].imm == REG_PC
6936 || inst.operands[i].reg == REG_PC),
6937 BAD_PC_ADDRESSING);
c19d1205
ZW
6938 inst.instruction |= inst.operands[i].imm;
6939 if (!inst.operands[i].negative)
6940 inst.instruction |= INDEX_UP;
6941 }
6942 else /* immediate offset in inst.reloc */
6943 {
5be8be5d
DG
6944 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
6945 && inst.operands[i].writeback),
6946 BAD_PC_WRITEBACK);
c19d1205
ZW
6947 inst.instruction |= HWOFFSET_IMM;
6948 if (inst.reloc.type == BFD_RELOC_UNUSED)
6949 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6950 }
a737bd4d
NC
6951}
6952
c19d1205
ZW
6953/* inst.operands[i] was set up by parse_address. Encode it into an
6954 ARM-format instruction. Reject all forms which cannot be encoded
6955 into a coprocessor load/store instruction. If wb_ok is false,
6956 reject use of writeback; if unind_ok is false, reject use of
6957 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6958 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6959 (in which case it is preserved). */
09d92015 6960
c19d1205
ZW
6961static int
6962encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6963{
c19d1205 6964 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6965
9c2799c2 6966 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6967
c19d1205 6968 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6969 {
9c2799c2 6970 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
6971 if (!unind_ok)
6972 {
6973 inst.error = _("instruction does not support unindexed addressing");
6974 return FAIL;
6975 }
6976 inst.instruction |= inst.operands[i].imm;
6977 inst.instruction |= INDEX_UP;
6978 return SUCCESS;
09d92015 6979 }
a737bd4d 6980
c19d1205
ZW
6981 if (inst.operands[i].preind)
6982 inst.instruction |= PRE_INDEX;
a737bd4d 6983
c19d1205 6984 if (inst.operands[i].writeback)
09d92015 6985 {
c19d1205
ZW
6986 if (inst.operands[i].reg == REG_PC)
6987 {
6988 inst.error = _("pc may not be used with write-back");
6989 return FAIL;
6990 }
6991 if (!wb_ok)
6992 {
6993 inst.error = _("instruction does not support writeback");
6994 return FAIL;
6995 }
6996 inst.instruction |= WRITE_BACK;
09d92015 6997 }
a737bd4d 6998
c19d1205 6999 if (reloc_override)
21d799b5 7000 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a
MS
7001 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
7002 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
7003 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
7004 {
7005 if (thumb_mode)
7006 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
7007 else
7008 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
7009 }
7010
c19d1205
ZW
7011 return SUCCESS;
7012}
a737bd4d 7013
c19d1205
ZW
7014/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7015 Determine whether it can be performed with a move instruction; if
7016 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7017 return TRUE; if it can't, convert inst.instruction to a literal-pool
7018 load and return FALSE. If this is not a valid thing to do in the
7019 current context, set inst.error and return TRUE.
a737bd4d 7020
c19d1205
ZW
7021 inst.operands[i] describes the destination register. */
7022
c921be7d 7023static bfd_boolean
c19d1205
ZW
7024move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
7025{
53365c0d
PB
7026 unsigned long tbit;
7027
7028 if (thumb_p)
7029 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7030 else
7031 tbit = LOAD_BIT;
7032
7033 if ((inst.instruction & tbit) == 0)
09d92015 7034 {
c19d1205 7035 inst.error = _("invalid pseudo operation");
c921be7d 7036 return TRUE;
09d92015 7037 }
c19d1205 7038 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
7039 {
7040 inst.error = _("constant expression expected");
c921be7d 7041 return TRUE;
09d92015 7042 }
c19d1205 7043 if (inst.reloc.exp.X_op == O_constant)
09d92015 7044 {
c19d1205
ZW
7045 if (thumb_p)
7046 {
53365c0d 7047 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
7048 {
7049 /* This can be done with a mov(1) instruction. */
7050 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7051 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 7052 return TRUE;
c19d1205
ZW
7053 }
7054 }
7055 else
7056 {
7057 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7058 if (value != FAIL)
7059 {
7060 /* This can be done with a mov instruction. */
7061 inst.instruction &= LITERAL_MASK;
7062 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7063 inst.instruction |= value & 0xfff;
c921be7d 7064 return TRUE;
c19d1205 7065 }
09d92015 7066
c19d1205
ZW
7067 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7068 if (value != FAIL)
7069 {
7070 /* This can be done with a mvn instruction. */
7071 inst.instruction &= LITERAL_MASK;
7072 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7073 inst.instruction |= value & 0xfff;
c921be7d 7074 return TRUE;
c19d1205
ZW
7075 }
7076 }
09d92015
MM
7077 }
7078
c19d1205
ZW
7079 if (add_to_lit_pool () == FAIL)
7080 {
7081 inst.error = _("literal pool insertion failed");
c921be7d 7082 return TRUE;
c19d1205
ZW
7083 }
7084 inst.operands[1].reg = REG_PC;
7085 inst.operands[1].isreg = 1;
7086 inst.operands[1].preind = 1;
7087 inst.reloc.pc_rel = 1;
7088 inst.reloc.type = (thumb_p
7089 ? BFD_RELOC_ARM_THUMB_OFFSET
7090 : (mode_3
7091 ? BFD_RELOC_ARM_HWLITERAL
7092 : BFD_RELOC_ARM_LITERAL));
c921be7d 7093 return FALSE;
09d92015
MM
7094}
7095
5f4273c7 7096/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
7097 First some generics; their names are taken from the conventional
7098 bit positions for register arguments in ARM format instructions. */
09d92015 7099
a737bd4d 7100static void
c19d1205 7101do_noargs (void)
09d92015 7102{
c19d1205 7103}
a737bd4d 7104
c19d1205
ZW
7105static void
7106do_rd (void)
7107{
7108 inst.instruction |= inst.operands[0].reg << 12;
7109}
a737bd4d 7110
c19d1205
ZW
7111static void
7112do_rd_rm (void)
7113{
7114 inst.instruction |= inst.operands[0].reg << 12;
7115 inst.instruction |= inst.operands[1].reg;
7116}
09d92015 7117
c19d1205
ZW
7118static void
7119do_rd_rn (void)
7120{
7121 inst.instruction |= inst.operands[0].reg << 12;
7122 inst.instruction |= inst.operands[1].reg << 16;
7123}
a737bd4d 7124
c19d1205
ZW
7125static void
7126do_rn_rd (void)
7127{
7128 inst.instruction |= inst.operands[0].reg << 16;
7129 inst.instruction |= inst.operands[1].reg << 12;
7130}
09d92015 7131
c19d1205
ZW
7132static void
7133do_rd_rm_rn (void)
7134{
9a64e435 7135 unsigned Rn = inst.operands[2].reg;
708587a4 7136 /* Enforce restrictions on SWP instruction. */
9a64e435 7137 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
7138 {
7139 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7140 _("Rn must not overlap other operands"));
7141
7142 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
7143 if (warn_on_deprecated
7144 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7145 as_warn (_("swp{b} use is deprecated for this architecture"));
7146
7147 }
c19d1205
ZW
7148 inst.instruction |= inst.operands[0].reg << 12;
7149 inst.instruction |= inst.operands[1].reg;
9a64e435 7150 inst.instruction |= Rn << 16;
c19d1205 7151}
09d92015 7152
c19d1205
ZW
7153static void
7154do_rd_rn_rm (void)
7155{
7156 inst.instruction |= inst.operands[0].reg << 12;
7157 inst.instruction |= inst.operands[1].reg << 16;
7158 inst.instruction |= inst.operands[2].reg;
7159}
a737bd4d 7160
c19d1205
ZW
7161static void
7162do_rm_rd_rn (void)
7163{
5be8be5d
DG
7164 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7165 constraint (((inst.reloc.exp.X_op != O_constant
7166 && inst.reloc.exp.X_op != O_illegal)
7167 || inst.reloc.exp.X_add_number != 0),
7168 BAD_ADDR_MODE);
c19d1205
ZW
7169 inst.instruction |= inst.operands[0].reg;
7170 inst.instruction |= inst.operands[1].reg << 12;
7171 inst.instruction |= inst.operands[2].reg << 16;
7172}
09d92015 7173
c19d1205
ZW
7174static void
7175do_imm0 (void)
7176{
7177 inst.instruction |= inst.operands[0].imm;
7178}
09d92015 7179
c19d1205
ZW
7180static void
7181do_rd_cpaddr (void)
7182{
7183 inst.instruction |= inst.operands[0].reg << 12;
7184 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 7185}
a737bd4d 7186
c19d1205
ZW
7187/* ARM instructions, in alphabetical order by function name (except
7188 that wrapper functions appear immediately after the function they
7189 wrap). */
09d92015 7190
c19d1205
ZW
7191/* This is a pseudo-op of the form "adr rd, label" to be converted
7192 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
7193
7194static void
c19d1205 7195do_adr (void)
09d92015 7196{
c19d1205 7197 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7198
c19d1205
ZW
7199 /* Frag hacking will turn this into a sub instruction if the offset turns
7200 out to be negative. */
7201 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 7202 inst.reloc.pc_rel = 1;
2fc8bdac 7203 inst.reloc.exp.X_add_number -= 8;
c19d1205 7204}
b99bd4ef 7205
c19d1205
ZW
7206/* This is a pseudo-op of the form "adrl rd, label" to be converted
7207 into a relative address of the form:
7208 add rd, pc, #low(label-.-8)"
7209 add rd, rd, #high(label-.-8)" */
b99bd4ef 7210
c19d1205
ZW
7211static void
7212do_adrl (void)
7213{
7214 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7215
c19d1205
ZW
7216 /* Frag hacking will turn this into a sub instruction if the offset turns
7217 out to be negative. */
7218 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
7219 inst.reloc.pc_rel = 1;
7220 inst.size = INSN_SIZE * 2;
2fc8bdac 7221 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
7222}
7223
b99bd4ef 7224static void
c19d1205 7225do_arit (void)
b99bd4ef 7226{
c19d1205
ZW
7227 if (!inst.operands[1].present)
7228 inst.operands[1].reg = inst.operands[0].reg;
7229 inst.instruction |= inst.operands[0].reg << 12;
7230 inst.instruction |= inst.operands[1].reg << 16;
7231 encode_arm_shifter_operand (2);
7232}
b99bd4ef 7233
62b3e311
PB
7234static void
7235do_barrier (void)
7236{
7237 if (inst.operands[0].present)
7238 {
7239 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
7240 && inst.operands[0].imm > 0xf
7241 && inst.operands[0].imm < 0x0,
bd3ba5d1 7242 _("bad barrier type"));
62b3e311
PB
7243 inst.instruction |= inst.operands[0].imm;
7244 }
7245 else
7246 inst.instruction |= 0xf;
7247}
7248
c19d1205
ZW
7249static void
7250do_bfc (void)
7251{
7252 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7253 constraint (msb > 32, _("bit-field extends past end of register"));
7254 /* The instruction encoding stores the LSB and MSB,
7255 not the LSB and width. */
7256 inst.instruction |= inst.operands[0].reg << 12;
7257 inst.instruction |= inst.operands[1].imm << 7;
7258 inst.instruction |= (msb - 1) << 16;
7259}
b99bd4ef 7260
c19d1205
ZW
7261static void
7262do_bfi (void)
7263{
7264 unsigned int msb;
b99bd4ef 7265
c19d1205
ZW
7266 /* #0 in second position is alternative syntax for bfc, which is
7267 the same instruction but with REG_PC in the Rm field. */
7268 if (!inst.operands[1].isreg)
7269 inst.operands[1].reg = REG_PC;
b99bd4ef 7270
c19d1205
ZW
7271 msb = inst.operands[2].imm + inst.operands[3].imm;
7272 constraint (msb > 32, _("bit-field extends past end of register"));
7273 /* The instruction encoding stores the LSB and MSB,
7274 not the LSB and width. */
7275 inst.instruction |= inst.operands[0].reg << 12;
7276 inst.instruction |= inst.operands[1].reg;
7277 inst.instruction |= inst.operands[2].imm << 7;
7278 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7279}
7280
b99bd4ef 7281static void
c19d1205 7282do_bfx (void)
b99bd4ef 7283{
c19d1205
ZW
7284 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7285 _("bit-field extends past end of register"));
7286 inst.instruction |= inst.operands[0].reg << 12;
7287 inst.instruction |= inst.operands[1].reg;
7288 inst.instruction |= inst.operands[2].imm << 7;
7289 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7290}
09d92015 7291
c19d1205
ZW
7292/* ARM V5 breakpoint instruction (argument parse)
7293 BKPT <16 bit unsigned immediate>
7294 Instruction is not conditional.
7295 The bit pattern given in insns[] has the COND_ALWAYS condition,
7296 and it is an error if the caller tried to override that. */
b99bd4ef 7297
c19d1205
ZW
7298static void
7299do_bkpt (void)
7300{
7301 /* Top 12 of 16 bits to bits 19:8. */
7302 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7303
c19d1205
ZW
7304 /* Bottom 4 of 16 bits to bits 3:0. */
7305 inst.instruction |= inst.operands[0].imm & 0xf;
7306}
09d92015 7307
c19d1205
ZW
7308static void
7309encode_branch (int default_reloc)
7310{
7311 if (inst.operands[0].hasreloc)
7312 {
0855e32b
NS
7313 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
7314 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
7315 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
7316 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
7317 ? BFD_RELOC_ARM_PLT32
7318 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 7319 }
b99bd4ef 7320 else
9ae92b05 7321 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 7322 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7323}
7324
b99bd4ef 7325static void
c19d1205 7326do_branch (void)
b99bd4ef 7327{
39b41c9c
PB
7328#ifdef OBJ_ELF
7329 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7330 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7331 else
7332#endif
7333 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7334}
7335
7336static void
7337do_bl (void)
7338{
7339#ifdef OBJ_ELF
7340 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7341 {
7342 if (inst.cond == COND_ALWAYS)
7343 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7344 else
7345 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7346 }
7347 else
7348#endif
7349 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7350}
b99bd4ef 7351
c19d1205
ZW
7352/* ARM V5 branch-link-exchange instruction (argument parse)
7353 BLX <target_addr> ie BLX(1)
7354 BLX{<condition>} <Rm> ie BLX(2)
7355 Unfortunately, there are two different opcodes for this mnemonic.
7356 So, the insns[].value is not used, and the code here zaps values
7357 into inst.instruction.
7358 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7359
c19d1205
ZW
7360static void
7361do_blx (void)
7362{
7363 if (inst.operands[0].isreg)
b99bd4ef 7364 {
c19d1205
ZW
7365 /* Arg is a register; the opcode provided by insns[] is correct.
7366 It is not illegal to do "blx pc", just useless. */
7367 if (inst.operands[0].reg == REG_PC)
7368 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7369
c19d1205
ZW
7370 inst.instruction |= inst.operands[0].reg;
7371 }
7372 else
b99bd4ef 7373 {
c19d1205 7374 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7375 conditionally, and the opcode must be adjusted.
7376 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7377 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7378 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7379 inst.instruction = 0xfa000000;
267bf995 7380 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7381 }
c19d1205
ZW
7382}
7383
7384static void
7385do_bx (void)
7386{
845b51d6
PB
7387 bfd_boolean want_reloc;
7388
c19d1205
ZW
7389 if (inst.operands[0].reg == REG_PC)
7390 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7391
c19d1205 7392 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7393 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7394 it is for ARMv4t or earlier. */
7395 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7396 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7397 want_reloc = TRUE;
7398
5ad34203 7399#ifdef OBJ_ELF
845b51d6 7400 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7401#endif
584206db 7402 want_reloc = FALSE;
845b51d6
PB
7403
7404 if (want_reloc)
7405 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7406}
7407
c19d1205
ZW
7408
7409/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7410
7411static void
c19d1205 7412do_bxj (void)
a737bd4d 7413{
c19d1205
ZW
7414 if (inst.operands[0].reg == REG_PC)
7415 as_tsktsk (_("use of r15 in bxj is not really useful"));
7416
7417 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7418}
7419
c19d1205
ZW
7420/* Co-processor data operation:
7421 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7422 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7423static void
7424do_cdp (void)
7425{
7426 inst.instruction |= inst.operands[0].reg << 8;
7427 inst.instruction |= inst.operands[1].imm << 20;
7428 inst.instruction |= inst.operands[2].reg << 12;
7429 inst.instruction |= inst.operands[3].reg << 16;
7430 inst.instruction |= inst.operands[4].reg;
7431 inst.instruction |= inst.operands[5].imm << 5;
7432}
a737bd4d
NC
7433
7434static void
c19d1205 7435do_cmp (void)
a737bd4d 7436{
c19d1205
ZW
7437 inst.instruction |= inst.operands[0].reg << 16;
7438 encode_arm_shifter_operand (1);
a737bd4d
NC
7439}
7440
c19d1205
ZW
7441/* Transfer between coprocessor and ARM registers.
7442 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7443 MRC2
7444 MCR{cond}
7445 MCR2
7446
7447 No special properties. */
09d92015
MM
7448
7449static void
c19d1205 7450do_co_reg (void)
09d92015 7451{
fdfde340
JM
7452 unsigned Rd;
7453
7454 Rd = inst.operands[2].reg;
7455 if (thumb_mode)
7456 {
7457 if (inst.instruction == 0xee000010
7458 || inst.instruction == 0xfe000010)
7459 /* MCR, MCR2 */
7460 reject_bad_reg (Rd);
7461 else
7462 /* MRC, MRC2 */
7463 constraint (Rd == REG_SP, BAD_SP);
7464 }
7465 else
7466 {
7467 /* MCR */
7468 if (inst.instruction == 0xe000010)
7469 constraint (Rd == REG_PC, BAD_PC);
7470 }
7471
7472
c19d1205
ZW
7473 inst.instruction |= inst.operands[0].reg << 8;
7474 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7475 inst.instruction |= Rd << 12;
c19d1205
ZW
7476 inst.instruction |= inst.operands[3].reg << 16;
7477 inst.instruction |= inst.operands[4].reg;
7478 inst.instruction |= inst.operands[5].imm << 5;
7479}
09d92015 7480
c19d1205
ZW
7481/* Transfer between coprocessor register and pair of ARM registers.
7482 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7483 MCRR2
7484 MRRC{cond}
7485 MRRC2
b99bd4ef 7486
c19d1205 7487 Two XScale instructions are special cases of these:
09d92015 7488
c19d1205
ZW
7489 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7490 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7491
5f4273c7 7492 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7493
c19d1205
ZW
7494static void
7495do_co_reg2c (void)
7496{
fdfde340
JM
7497 unsigned Rd, Rn;
7498
7499 Rd = inst.operands[2].reg;
7500 Rn = inst.operands[3].reg;
7501
7502 if (thumb_mode)
7503 {
7504 reject_bad_reg (Rd);
7505 reject_bad_reg (Rn);
7506 }
7507 else
7508 {
7509 constraint (Rd == REG_PC, BAD_PC);
7510 constraint (Rn == REG_PC, BAD_PC);
7511 }
7512
c19d1205
ZW
7513 inst.instruction |= inst.operands[0].reg << 8;
7514 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7515 inst.instruction |= Rd << 12;
7516 inst.instruction |= Rn << 16;
c19d1205 7517 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7518}
7519
c19d1205
ZW
7520static void
7521do_cpsi (void)
7522{
7523 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7524 if (inst.operands[1].present)
7525 {
7526 inst.instruction |= CPSI_MMOD;
7527 inst.instruction |= inst.operands[1].imm;
7528 }
c19d1205 7529}
b99bd4ef 7530
62b3e311
PB
7531static void
7532do_dbg (void)
7533{
7534 inst.instruction |= inst.operands[0].imm;
7535}
7536
eea54501
MGD
7537static void
7538do_div (void)
7539{
7540 unsigned Rd, Rn, Rm;
7541
7542 Rd = inst.operands[0].reg;
7543 Rn = (inst.operands[1].present
7544 ? inst.operands[1].reg : Rd);
7545 Rm = inst.operands[2].reg;
7546
7547 constraint ((Rd == REG_PC), BAD_PC);
7548 constraint ((Rn == REG_PC), BAD_PC);
7549 constraint ((Rm == REG_PC), BAD_PC);
7550
7551 inst.instruction |= Rd << 16;
7552 inst.instruction |= Rn << 0;
7553 inst.instruction |= Rm << 8;
7554}
7555
b99bd4ef 7556static void
c19d1205 7557do_it (void)
b99bd4ef 7558{
c19d1205 7559 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7560 process it to do the validation as if in
7561 thumb mode, just in case the code gets
7562 assembled for thumb using the unified syntax. */
7563
c19d1205 7564 inst.size = 0;
e07e6e58
NC
7565 if (unified_syntax)
7566 {
7567 set_it_insn_type (IT_INSN);
7568 now_it.mask = (inst.instruction & 0xf) | 0x10;
7569 now_it.cc = inst.operands[0].imm;
7570 }
09d92015 7571}
b99bd4ef 7572
09d92015 7573static void
c19d1205 7574do_ldmstm (void)
ea6ef066 7575{
c19d1205
ZW
7576 int base_reg = inst.operands[0].reg;
7577 int range = inst.operands[1].imm;
ea6ef066 7578
c19d1205
ZW
7579 inst.instruction |= base_reg << 16;
7580 inst.instruction |= range;
ea6ef066 7581
c19d1205
ZW
7582 if (inst.operands[1].writeback)
7583 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7584
c19d1205 7585 if (inst.operands[0].writeback)
ea6ef066 7586 {
c19d1205
ZW
7587 inst.instruction |= WRITE_BACK;
7588 /* Check for unpredictable uses of writeback. */
7589 if (inst.instruction & LOAD_BIT)
09d92015 7590 {
c19d1205
ZW
7591 /* Not allowed in LDM type 2. */
7592 if ((inst.instruction & LDM_TYPE_2_OR_3)
7593 && ((range & (1 << REG_PC)) == 0))
7594 as_warn (_("writeback of base register is UNPREDICTABLE"));
7595 /* Only allowed if base reg not in list for other types. */
7596 else if (range & (1 << base_reg))
7597 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7598 }
7599 else /* STM. */
7600 {
7601 /* Not allowed for type 2. */
7602 if (inst.instruction & LDM_TYPE_2_OR_3)
7603 as_warn (_("writeback of base register is UNPREDICTABLE"));
7604 /* Only allowed if base reg not in list, or first in list. */
7605 else if ((range & (1 << base_reg))
7606 && (range & ((1 << base_reg) - 1)))
7607 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7608 }
ea6ef066 7609 }
a737bd4d
NC
7610}
7611
c19d1205
ZW
7612/* ARMv5TE load-consecutive (argument parse)
7613 Mode is like LDRH.
7614
7615 LDRccD R, mode
7616 STRccD R, mode. */
7617
a737bd4d 7618static void
c19d1205 7619do_ldrd (void)
a737bd4d 7620{
c19d1205
ZW
7621 constraint (inst.operands[0].reg % 2 != 0,
7622 _("first destination register must be even"));
7623 constraint (inst.operands[1].present
7624 && inst.operands[1].reg != inst.operands[0].reg + 1,
7625 _("can only load two consecutive registers"));
7626 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7627 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7628
c19d1205
ZW
7629 if (!inst.operands[1].present)
7630 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7631
c19d1205 7632 if (inst.instruction & LOAD_BIT)
a737bd4d 7633 {
c19d1205
ZW
7634 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7635 register and the first register written; we have to diagnose
7636 overlap between the base and the second register written here. */
ea6ef066 7637
c19d1205
ZW
7638 if (inst.operands[2].reg == inst.operands[1].reg
7639 && (inst.operands[2].writeback || inst.operands[2].postind))
7640 as_warn (_("base register written back, and overlaps "
7641 "second destination register"));
b05fe5cf 7642
c19d1205
ZW
7643 /* For an index-register load, the index register must not overlap the
7644 destination (even if not write-back). */
7645 else if (inst.operands[2].immisreg
ca3f61f7
NC
7646 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7647 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 7648 as_warn (_("index register overlaps destination register"));
b05fe5cf 7649 }
c19d1205
ZW
7650
7651 inst.instruction |= inst.operands[0].reg << 12;
7652 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7653}
7654
7655static void
c19d1205 7656do_ldrex (void)
b05fe5cf 7657{
c19d1205
ZW
7658 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7659 || inst.operands[1].postind || inst.operands[1].writeback
7660 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7661 || inst.operands[1].negative
7662 /* This can arise if the programmer has written
7663 strex rN, rM, foo
7664 or if they have mistakenly used a register name as the last
7665 operand, eg:
7666 strex rN, rM, rX
7667 It is very difficult to distinguish between these two cases
7668 because "rX" might actually be a label. ie the register
7669 name has been occluded by a symbol of the same name. So we
7670 just generate a general 'bad addressing mode' type error
7671 message and leave it up to the programmer to discover the
7672 true cause and fix their mistake. */
7673 || (inst.operands[1].reg == REG_PC),
7674 BAD_ADDR_MODE);
b05fe5cf 7675
c19d1205
ZW
7676 constraint (inst.reloc.exp.X_op != O_constant
7677 || inst.reloc.exp.X_add_number != 0,
7678 _("offset must be zero in ARM encoding"));
b05fe5cf 7679
5be8be5d
DG
7680 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7681
c19d1205
ZW
7682 inst.instruction |= inst.operands[0].reg << 12;
7683 inst.instruction |= inst.operands[1].reg << 16;
7684 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7685}
7686
7687static void
c19d1205 7688do_ldrexd (void)
b05fe5cf 7689{
c19d1205
ZW
7690 constraint (inst.operands[0].reg % 2 != 0,
7691 _("even register required"));
7692 constraint (inst.operands[1].present
7693 && inst.operands[1].reg != inst.operands[0].reg + 1,
7694 _("can only load two consecutive registers"));
7695 /* If op 1 were present and equal to PC, this function wouldn't
7696 have been called in the first place. */
7697 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7698
c19d1205
ZW
7699 inst.instruction |= inst.operands[0].reg << 12;
7700 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7701}
7702
7703static void
c19d1205 7704do_ldst (void)
b05fe5cf 7705{
c19d1205
ZW
7706 inst.instruction |= inst.operands[0].reg << 12;
7707 if (!inst.operands[1].isreg)
7708 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7709 return;
c19d1205 7710 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7711}
7712
7713static void
c19d1205 7714do_ldstt (void)
b05fe5cf 7715{
c19d1205
ZW
7716 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7717 reject [Rn,...]. */
7718 if (inst.operands[1].preind)
b05fe5cf 7719 {
bd3ba5d1
NC
7720 constraint (inst.reloc.exp.X_op != O_constant
7721 || inst.reloc.exp.X_add_number != 0,
c19d1205 7722 _("this instruction requires a post-indexed address"));
b05fe5cf 7723
c19d1205
ZW
7724 inst.operands[1].preind = 0;
7725 inst.operands[1].postind = 1;
7726 inst.operands[1].writeback = 1;
b05fe5cf 7727 }
c19d1205
ZW
7728 inst.instruction |= inst.operands[0].reg << 12;
7729 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7730}
b05fe5cf 7731
c19d1205 7732/* Halfword and signed-byte load/store operations. */
b05fe5cf 7733
c19d1205
ZW
7734static void
7735do_ldstv4 (void)
7736{
ff4a8d2b 7737 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7738 inst.instruction |= inst.operands[0].reg << 12;
7739 if (!inst.operands[1].isreg)
7740 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7741 return;
c19d1205 7742 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7743}
7744
7745static void
c19d1205 7746do_ldsttv4 (void)
b05fe5cf 7747{
c19d1205
ZW
7748 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7749 reject [Rn,...]. */
7750 if (inst.operands[1].preind)
b05fe5cf 7751 {
bd3ba5d1
NC
7752 constraint (inst.reloc.exp.X_op != O_constant
7753 || inst.reloc.exp.X_add_number != 0,
c19d1205 7754 _("this instruction requires a post-indexed address"));
b05fe5cf 7755
c19d1205
ZW
7756 inst.operands[1].preind = 0;
7757 inst.operands[1].postind = 1;
7758 inst.operands[1].writeback = 1;
b05fe5cf 7759 }
c19d1205
ZW
7760 inst.instruction |= inst.operands[0].reg << 12;
7761 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7762}
b05fe5cf 7763
c19d1205
ZW
7764/* Co-processor register load/store.
7765 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7766static void
7767do_lstc (void)
7768{
7769 inst.instruction |= inst.operands[0].reg << 8;
7770 inst.instruction |= inst.operands[1].reg << 12;
7771 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7772}
7773
b05fe5cf 7774static void
c19d1205 7775do_mlas (void)
b05fe5cf 7776{
8fb9d7b9 7777 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7778 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7779 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7780 && !(inst.instruction & 0x00400000))
8fb9d7b9 7781 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7782
c19d1205
ZW
7783 inst.instruction |= inst.operands[0].reg << 16;
7784 inst.instruction |= inst.operands[1].reg;
7785 inst.instruction |= inst.operands[2].reg << 8;
7786 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7787}
b05fe5cf 7788
c19d1205
ZW
7789static void
7790do_mov (void)
7791{
7792 inst.instruction |= inst.operands[0].reg << 12;
7793 encode_arm_shifter_operand (1);
7794}
b05fe5cf 7795
c19d1205
ZW
7796/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7797static void
7798do_mov16 (void)
7799{
b6895b4f
PB
7800 bfd_vma imm;
7801 bfd_boolean top;
7802
7803 top = (inst.instruction & 0x00400000) != 0;
7804 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7805 _(":lower16: not allowed this instruction"));
7806 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7807 _(":upper16: not allowed instruction"));
c19d1205 7808 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7809 if (inst.reloc.type == BFD_RELOC_UNUSED)
7810 {
7811 imm = inst.reloc.exp.X_add_number;
7812 /* The value is in two pieces: 0:11, 16:19. */
7813 inst.instruction |= (imm & 0x00000fff);
7814 inst.instruction |= (imm & 0x0000f000) << 4;
7815 }
b05fe5cf 7816}
b99bd4ef 7817
037e8744
JB
7818static void do_vfp_nsyn_opcode (const char *);
7819
7820static int
7821do_vfp_nsyn_mrs (void)
7822{
7823 if (inst.operands[0].isvec)
7824 {
7825 if (inst.operands[1].reg != 1)
7826 first_error (_("operand 1 must be FPSCR"));
7827 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7828 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7829 do_vfp_nsyn_opcode ("fmstat");
7830 }
7831 else if (inst.operands[1].isvec)
7832 do_vfp_nsyn_opcode ("fmrx");
7833 else
7834 return FAIL;
5f4273c7 7835
037e8744
JB
7836 return SUCCESS;
7837}
7838
7839static int
7840do_vfp_nsyn_msr (void)
7841{
7842 if (inst.operands[0].isvec)
7843 do_vfp_nsyn_opcode ("fmxr");
7844 else
7845 return FAIL;
7846
7847 return SUCCESS;
7848}
7849
f7c21dc7
NC
7850static void
7851do_vmrs (void)
7852{
7853 unsigned Rt = inst.operands[0].reg;
7854
7855 if (thumb_mode && inst.operands[0].reg == REG_SP)
7856 {
7857 inst.error = BAD_SP;
7858 return;
7859 }
7860
7861 /* APSR_ sets isvec. All other refs to PC are illegal. */
7862 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
7863 {
7864 inst.error = BAD_PC;
7865 return;
7866 }
7867
7868 if (inst.operands[1].reg != 1)
7869 first_error (_("operand 1 must be FPSCR"));
7870
7871 inst.instruction |= (Rt << 12);
7872}
7873
7874static void
7875do_vmsr (void)
7876{
7877 unsigned Rt = inst.operands[1].reg;
7878
7879 if (thumb_mode)
7880 reject_bad_reg (Rt);
7881 else if (Rt == REG_PC)
7882 {
7883 inst.error = BAD_PC;
7884 return;
7885 }
7886
7887 if (inst.operands[0].reg != 1)
7888 first_error (_("operand 0 must be FPSCR"));
7889
7890 inst.instruction |= (Rt << 12);
7891}
7892
b99bd4ef 7893static void
c19d1205 7894do_mrs (void)
b99bd4ef 7895{
90ec0d68
MGD
7896 unsigned br;
7897
037e8744
JB
7898 if (do_vfp_nsyn_mrs () == SUCCESS)
7899 return;
7900
ff4a8d2b 7901 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 7902 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
7903
7904 if (inst.operands[1].isreg)
7905 {
7906 br = inst.operands[1].reg;
7907 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
7908 as_bad (_("bad register for mrs"));
7909 }
7910 else
7911 {
7912 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7913 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7914 != (PSR_c|PSR_f),
7915 _("'CPSR' or 'SPSR' expected"));
7916 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
7917 }
7918
7919 inst.instruction |= br;
c19d1205 7920}
b99bd4ef 7921
c19d1205
ZW
7922/* Two possible forms:
7923 "{C|S}PSR_<field>, Rm",
7924 "{C|S}PSR_f, #expression". */
b99bd4ef 7925
c19d1205
ZW
7926static void
7927do_msr (void)
7928{
037e8744
JB
7929 if (do_vfp_nsyn_msr () == SUCCESS)
7930 return;
7931
c19d1205
ZW
7932 inst.instruction |= inst.operands[0].imm;
7933 if (inst.operands[1].isreg)
7934 inst.instruction |= inst.operands[1].reg;
7935 else
b99bd4ef 7936 {
c19d1205
ZW
7937 inst.instruction |= INST_IMMEDIATE;
7938 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7939 inst.reloc.pc_rel = 0;
b99bd4ef 7940 }
b99bd4ef
NC
7941}
7942
c19d1205
ZW
7943static void
7944do_mul (void)
a737bd4d 7945{
ff4a8d2b
NC
7946 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
7947
c19d1205
ZW
7948 if (!inst.operands[2].present)
7949 inst.operands[2].reg = inst.operands[0].reg;
7950 inst.instruction |= inst.operands[0].reg << 16;
7951 inst.instruction |= inst.operands[1].reg;
7952 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7953
8fb9d7b9
MS
7954 if (inst.operands[0].reg == inst.operands[1].reg
7955 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7956 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7957}
7958
c19d1205
ZW
7959/* Long Multiply Parser
7960 UMULL RdLo, RdHi, Rm, Rs
7961 SMULL RdLo, RdHi, Rm, Rs
7962 UMLAL RdLo, RdHi, Rm, Rs
7963 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7964
7965static void
c19d1205 7966do_mull (void)
b99bd4ef 7967{
c19d1205
ZW
7968 inst.instruction |= inst.operands[0].reg << 12;
7969 inst.instruction |= inst.operands[1].reg << 16;
7970 inst.instruction |= inst.operands[2].reg;
7971 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7972
682b27ad
PB
7973 /* rdhi and rdlo must be different. */
7974 if (inst.operands[0].reg == inst.operands[1].reg)
7975 as_tsktsk (_("rdhi and rdlo must be different"));
7976
7977 /* rdhi, rdlo and rm must all be different before armv6. */
7978 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7979 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7980 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7981 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7982}
b99bd4ef 7983
c19d1205
ZW
7984static void
7985do_nop (void)
7986{
e7495e45
NS
7987 if (inst.operands[0].present
7988 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
7989 {
7990 /* Architectural NOP hints are CPSR sets with no bits selected. */
7991 inst.instruction &= 0xf0000000;
e7495e45
NS
7992 inst.instruction |= 0x0320f000;
7993 if (inst.operands[0].present)
7994 inst.instruction |= inst.operands[0].imm;
c19d1205 7995 }
b99bd4ef
NC
7996}
7997
c19d1205
ZW
7998/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7999 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
8000 Condition defaults to COND_ALWAYS.
8001 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
8002
8003static void
c19d1205 8004do_pkhbt (void)
b99bd4ef 8005{
c19d1205
ZW
8006 inst.instruction |= inst.operands[0].reg << 12;
8007 inst.instruction |= inst.operands[1].reg << 16;
8008 inst.instruction |= inst.operands[2].reg;
8009 if (inst.operands[3].present)
8010 encode_arm_shift (3);
8011}
b99bd4ef 8012
c19d1205 8013/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 8014
c19d1205
ZW
8015static void
8016do_pkhtb (void)
8017{
8018 if (!inst.operands[3].present)
b99bd4ef 8019 {
c19d1205
ZW
8020 /* If the shift specifier is omitted, turn the instruction
8021 into pkhbt rd, rm, rn. */
8022 inst.instruction &= 0xfff00010;
8023 inst.instruction |= inst.operands[0].reg << 12;
8024 inst.instruction |= inst.operands[1].reg;
8025 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8026 }
8027 else
8028 {
c19d1205
ZW
8029 inst.instruction |= inst.operands[0].reg << 12;
8030 inst.instruction |= inst.operands[1].reg << 16;
8031 inst.instruction |= inst.operands[2].reg;
8032 encode_arm_shift (3);
b99bd4ef
NC
8033 }
8034}
8035
c19d1205 8036/* ARMv5TE: Preload-Cache
60e5ef9f 8037 MP Extensions: Preload for write
c19d1205 8038
60e5ef9f 8039 PLD(W) <addr_mode>
c19d1205
ZW
8040
8041 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
8042
8043static void
c19d1205 8044do_pld (void)
b99bd4ef 8045{
c19d1205
ZW
8046 constraint (!inst.operands[0].isreg,
8047 _("'[' expected after PLD mnemonic"));
8048 constraint (inst.operands[0].postind,
8049 _("post-indexed expression used in preload instruction"));
8050 constraint (inst.operands[0].writeback,
8051 _("writeback used in preload instruction"));
8052 constraint (!inst.operands[0].preind,
8053 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
8054 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8055}
b99bd4ef 8056
62b3e311
PB
8057/* ARMv7: PLI <addr_mode> */
8058static void
8059do_pli (void)
8060{
8061 constraint (!inst.operands[0].isreg,
8062 _("'[' expected after PLI mnemonic"));
8063 constraint (inst.operands[0].postind,
8064 _("post-indexed expression used in preload instruction"));
8065 constraint (inst.operands[0].writeback,
8066 _("writeback used in preload instruction"));
8067 constraint (!inst.operands[0].preind,
8068 _("unindexed addressing used in preload instruction"));
8069 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8070 inst.instruction &= ~PRE_INDEX;
8071}
8072
c19d1205
ZW
8073static void
8074do_push_pop (void)
8075{
8076 inst.operands[1] = inst.operands[0];
8077 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8078 inst.operands[0].isreg = 1;
8079 inst.operands[0].writeback = 1;
8080 inst.operands[0].reg = REG_SP;
8081 do_ldmstm ();
8082}
b99bd4ef 8083
c19d1205
ZW
8084/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8085 word at the specified address and the following word
8086 respectively.
8087 Unconditionally executed.
8088 Error if Rn is R15. */
b99bd4ef 8089
c19d1205
ZW
8090static void
8091do_rfe (void)
8092{
8093 inst.instruction |= inst.operands[0].reg << 16;
8094 if (inst.operands[0].writeback)
8095 inst.instruction |= WRITE_BACK;
8096}
b99bd4ef 8097
c19d1205 8098/* ARM V6 ssat (argument parse). */
b99bd4ef 8099
c19d1205
ZW
8100static void
8101do_ssat (void)
8102{
8103 inst.instruction |= inst.operands[0].reg << 12;
8104 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8105 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8106
c19d1205
ZW
8107 if (inst.operands[3].present)
8108 encode_arm_shift (3);
b99bd4ef
NC
8109}
8110
c19d1205 8111/* ARM V6 usat (argument parse). */
b99bd4ef
NC
8112
8113static void
c19d1205 8114do_usat (void)
b99bd4ef 8115{
c19d1205
ZW
8116 inst.instruction |= inst.operands[0].reg << 12;
8117 inst.instruction |= inst.operands[1].imm << 16;
8118 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8119
c19d1205
ZW
8120 if (inst.operands[3].present)
8121 encode_arm_shift (3);
b99bd4ef
NC
8122}
8123
c19d1205 8124/* ARM V6 ssat16 (argument parse). */
09d92015
MM
8125
8126static void
c19d1205 8127do_ssat16 (void)
09d92015 8128{
c19d1205
ZW
8129 inst.instruction |= inst.operands[0].reg << 12;
8130 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8131 inst.instruction |= inst.operands[2].reg;
09d92015
MM
8132}
8133
c19d1205
ZW
8134static void
8135do_usat16 (void)
a737bd4d 8136{
c19d1205
ZW
8137 inst.instruction |= inst.operands[0].reg << 12;
8138 inst.instruction |= inst.operands[1].imm << 16;
8139 inst.instruction |= inst.operands[2].reg;
8140}
a737bd4d 8141
c19d1205
ZW
8142/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8143 preserving the other bits.
a737bd4d 8144
c19d1205
ZW
8145 setend <endian_specifier>, where <endian_specifier> is either
8146 BE or LE. */
a737bd4d 8147
c19d1205
ZW
8148static void
8149do_setend (void)
8150{
8151 if (inst.operands[0].imm)
8152 inst.instruction |= 0x200;
a737bd4d
NC
8153}
8154
8155static void
c19d1205 8156do_shift (void)
a737bd4d 8157{
c19d1205
ZW
8158 unsigned int Rm = (inst.operands[1].present
8159 ? inst.operands[1].reg
8160 : inst.operands[0].reg);
a737bd4d 8161
c19d1205
ZW
8162 inst.instruction |= inst.operands[0].reg << 12;
8163 inst.instruction |= Rm;
8164 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 8165 {
c19d1205
ZW
8166 inst.instruction |= inst.operands[2].reg << 8;
8167 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
8168 }
8169 else
c19d1205 8170 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
8171}
8172
09d92015 8173static void
3eb17e6b 8174do_smc (void)
09d92015 8175{
3eb17e6b 8176 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 8177 inst.reloc.pc_rel = 0;
09d92015
MM
8178}
8179
90ec0d68
MGD
8180static void
8181do_hvc (void)
8182{
8183 inst.reloc.type = BFD_RELOC_ARM_HVC;
8184 inst.reloc.pc_rel = 0;
8185}
8186
09d92015 8187static void
c19d1205 8188do_swi (void)
09d92015 8189{
c19d1205
ZW
8190 inst.reloc.type = BFD_RELOC_ARM_SWI;
8191 inst.reloc.pc_rel = 0;
09d92015
MM
8192}
8193
c19d1205
ZW
8194/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8195 SMLAxy{cond} Rd,Rm,Rs,Rn
8196 SMLAWy{cond} Rd,Rm,Rs,Rn
8197 Error if any register is R15. */
e16bb312 8198
c19d1205
ZW
8199static void
8200do_smla (void)
e16bb312 8201{
c19d1205
ZW
8202 inst.instruction |= inst.operands[0].reg << 16;
8203 inst.instruction |= inst.operands[1].reg;
8204 inst.instruction |= inst.operands[2].reg << 8;
8205 inst.instruction |= inst.operands[3].reg << 12;
8206}
a737bd4d 8207
c19d1205
ZW
8208/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8209 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8210 Error if any register is R15.
8211 Warning if Rdlo == Rdhi. */
a737bd4d 8212
c19d1205
ZW
8213static void
8214do_smlal (void)
8215{
8216 inst.instruction |= inst.operands[0].reg << 12;
8217 inst.instruction |= inst.operands[1].reg << 16;
8218 inst.instruction |= inst.operands[2].reg;
8219 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 8220
c19d1205
ZW
8221 if (inst.operands[0].reg == inst.operands[1].reg)
8222 as_tsktsk (_("rdhi and rdlo must be different"));
8223}
a737bd4d 8224
c19d1205
ZW
8225/* ARM V5E (El Segundo) signed-multiply (argument parse)
8226 SMULxy{cond} Rd,Rm,Rs
8227 Error if any register is R15. */
a737bd4d 8228
c19d1205
ZW
8229static void
8230do_smul (void)
8231{
8232 inst.instruction |= inst.operands[0].reg << 16;
8233 inst.instruction |= inst.operands[1].reg;
8234 inst.instruction |= inst.operands[2].reg << 8;
8235}
a737bd4d 8236
b6702015
PB
8237/* ARM V6 srs (argument parse). The variable fields in the encoding are
8238 the same for both ARM and Thumb-2. */
a737bd4d 8239
c19d1205
ZW
8240static void
8241do_srs (void)
8242{
b6702015
PB
8243 int reg;
8244
8245 if (inst.operands[0].present)
8246 {
8247 reg = inst.operands[0].reg;
fdfde340 8248 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
8249 }
8250 else
fdfde340 8251 reg = REG_SP;
b6702015
PB
8252
8253 inst.instruction |= reg << 16;
8254 inst.instruction |= inst.operands[1].imm;
8255 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
8256 inst.instruction |= WRITE_BACK;
8257}
a737bd4d 8258
c19d1205 8259/* ARM V6 strex (argument parse). */
a737bd4d 8260
c19d1205
ZW
8261static void
8262do_strex (void)
8263{
8264 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8265 || inst.operands[2].postind || inst.operands[2].writeback
8266 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
8267 || inst.operands[2].negative
8268 /* See comment in do_ldrex(). */
8269 || (inst.operands[2].reg == REG_PC),
8270 BAD_ADDR_MODE);
a737bd4d 8271
c19d1205
ZW
8272 constraint (inst.operands[0].reg == inst.operands[1].reg
8273 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 8274
c19d1205
ZW
8275 constraint (inst.reloc.exp.X_op != O_constant
8276 || inst.reloc.exp.X_add_number != 0,
8277 _("offset must be zero in ARM encoding"));
a737bd4d 8278
c19d1205
ZW
8279 inst.instruction |= inst.operands[0].reg << 12;
8280 inst.instruction |= inst.operands[1].reg;
8281 inst.instruction |= inst.operands[2].reg << 16;
8282 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8283}
8284
8285static void
c19d1205 8286do_strexd (void)
e16bb312 8287{
c19d1205
ZW
8288 constraint (inst.operands[1].reg % 2 != 0,
8289 _("even register required"));
8290 constraint (inst.operands[2].present
8291 && inst.operands[2].reg != inst.operands[1].reg + 1,
8292 _("can only store two consecutive registers"));
8293 /* If op 2 were present and equal to PC, this function wouldn't
8294 have been called in the first place. */
8295 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8296
c19d1205
ZW
8297 constraint (inst.operands[0].reg == inst.operands[1].reg
8298 || inst.operands[0].reg == inst.operands[1].reg + 1
8299 || inst.operands[0].reg == inst.operands[3].reg,
8300 BAD_OVERLAP);
e16bb312 8301
c19d1205
ZW
8302 inst.instruction |= inst.operands[0].reg << 12;
8303 inst.instruction |= inst.operands[1].reg;
8304 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8305}
8306
c19d1205
ZW
8307/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8308 extends it to 32-bits, and adds the result to a value in another
8309 register. You can specify a rotation by 0, 8, 16, or 24 bits
8310 before extracting the 16-bit value.
8311 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8312 Condition defaults to COND_ALWAYS.
8313 Error if any register uses R15. */
8314
e16bb312 8315static void
c19d1205 8316do_sxtah (void)
e16bb312 8317{
c19d1205
ZW
8318 inst.instruction |= inst.operands[0].reg << 12;
8319 inst.instruction |= inst.operands[1].reg << 16;
8320 inst.instruction |= inst.operands[2].reg;
8321 inst.instruction |= inst.operands[3].imm << 10;
8322}
e16bb312 8323
c19d1205 8324/* ARM V6 SXTH.
e16bb312 8325
c19d1205
ZW
8326 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8327 Condition defaults to COND_ALWAYS.
8328 Error if any register uses R15. */
e16bb312
NC
8329
8330static void
c19d1205 8331do_sxth (void)
e16bb312 8332{
c19d1205
ZW
8333 inst.instruction |= inst.operands[0].reg << 12;
8334 inst.instruction |= inst.operands[1].reg;
8335 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8336}
c19d1205
ZW
8337\f
8338/* VFP instructions. In a logical order: SP variant first, monad
8339 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8340
8341static void
c19d1205 8342do_vfp_sp_monadic (void)
e16bb312 8343{
5287ad62
JB
8344 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8345 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8346}
8347
8348static void
c19d1205 8349do_vfp_sp_dyadic (void)
e16bb312 8350{
5287ad62
JB
8351 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8352 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8353 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8354}
8355
8356static void
c19d1205 8357do_vfp_sp_compare_z (void)
e16bb312 8358{
5287ad62 8359 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8360}
8361
8362static void
c19d1205 8363do_vfp_dp_sp_cvt (void)
e16bb312 8364{
5287ad62
JB
8365 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8366 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8367}
8368
8369static void
c19d1205 8370do_vfp_sp_dp_cvt (void)
e16bb312 8371{
5287ad62
JB
8372 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8373 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8374}
8375
8376static void
c19d1205 8377do_vfp_reg_from_sp (void)
e16bb312 8378{
c19d1205 8379 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8380 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8381}
8382
8383static void
c19d1205 8384do_vfp_reg2_from_sp2 (void)
e16bb312 8385{
c19d1205
ZW
8386 constraint (inst.operands[2].imm != 2,
8387 _("only two consecutive VFP SP registers allowed here"));
8388 inst.instruction |= inst.operands[0].reg << 12;
8389 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8390 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8391}
8392
8393static void
c19d1205 8394do_vfp_sp_from_reg (void)
e16bb312 8395{
5287ad62 8396 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8397 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8398}
8399
8400static void
c19d1205 8401do_vfp_sp2_from_reg2 (void)
e16bb312 8402{
c19d1205
ZW
8403 constraint (inst.operands[0].imm != 2,
8404 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8405 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8406 inst.instruction |= inst.operands[1].reg << 12;
8407 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8408}
8409
8410static void
c19d1205 8411do_vfp_sp_ldst (void)
e16bb312 8412{
5287ad62 8413 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 8414 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8415}
8416
8417static void
c19d1205 8418do_vfp_dp_ldst (void)
e16bb312 8419{
5287ad62 8420 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 8421 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8422}
8423
c19d1205 8424
e16bb312 8425static void
c19d1205 8426vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8427{
c19d1205
ZW
8428 if (inst.operands[0].writeback)
8429 inst.instruction |= WRITE_BACK;
8430 else
8431 constraint (ldstm_type != VFP_LDSTMIA,
8432 _("this addressing mode requires base-register writeback"));
8433 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8434 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 8435 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
8436}
8437
8438static void
c19d1205 8439vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8440{
c19d1205 8441 int count;
e16bb312 8442
c19d1205
ZW
8443 if (inst.operands[0].writeback)
8444 inst.instruction |= WRITE_BACK;
8445 else
8446 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8447 _("this addressing mode requires base-register writeback"));
e16bb312 8448
c19d1205 8449 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8450 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 8451
c19d1205
ZW
8452 count = inst.operands[1].imm << 1;
8453 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8454 count += 1;
e16bb312 8455
c19d1205 8456 inst.instruction |= count;
e16bb312
NC
8457}
8458
8459static void
c19d1205 8460do_vfp_sp_ldstmia (void)
e16bb312 8461{
c19d1205 8462 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8463}
8464
8465static void
c19d1205 8466do_vfp_sp_ldstmdb (void)
e16bb312 8467{
c19d1205 8468 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8469}
8470
8471static void
c19d1205 8472do_vfp_dp_ldstmia (void)
e16bb312 8473{
c19d1205 8474 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8475}
8476
8477static void
c19d1205 8478do_vfp_dp_ldstmdb (void)
e16bb312 8479{
c19d1205 8480 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8481}
8482
8483static void
c19d1205 8484do_vfp_xp_ldstmia (void)
e16bb312 8485{
c19d1205
ZW
8486 vfp_dp_ldstm (VFP_LDSTMIAX);
8487}
e16bb312 8488
c19d1205
ZW
8489static void
8490do_vfp_xp_ldstmdb (void)
8491{
8492 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 8493}
5287ad62
JB
8494
8495static void
8496do_vfp_dp_rd_rm (void)
8497{
8498 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8499 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8500}
8501
8502static void
8503do_vfp_dp_rn_rd (void)
8504{
8505 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8506 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8507}
8508
8509static void
8510do_vfp_dp_rd_rn (void)
8511{
8512 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8513 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8514}
8515
8516static void
8517do_vfp_dp_rd_rn_rm (void)
8518{
8519 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8520 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8521 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8522}
8523
8524static void
8525do_vfp_dp_rd (void)
8526{
8527 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8528}
8529
8530static void
8531do_vfp_dp_rm_rd_rn (void)
8532{
8533 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8534 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8535 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8536}
8537
8538/* VFPv3 instructions. */
8539static void
8540do_vfp_sp_const (void)
8541{
8542 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8543 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8544 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8545}
8546
8547static void
8548do_vfp_dp_const (void)
8549{
8550 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8551 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8552 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8553}
8554
8555static void
8556vfp_conv (int srcsize)
8557{
8558 unsigned immbits = srcsize - inst.operands[1].imm;
8559 inst.instruction |= (immbits & 1) << 5;
8560 inst.instruction |= (immbits >> 1);
8561}
8562
8563static void
8564do_vfp_sp_conv_16 (void)
8565{
8566 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8567 vfp_conv (16);
8568}
8569
8570static void
8571do_vfp_dp_conv_16 (void)
8572{
8573 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8574 vfp_conv (16);
8575}
8576
8577static void
8578do_vfp_sp_conv_32 (void)
8579{
8580 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8581 vfp_conv (32);
8582}
8583
8584static void
8585do_vfp_dp_conv_32 (void)
8586{
8587 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8588 vfp_conv (32);
8589}
c19d1205
ZW
8590\f
8591/* FPA instructions. Also in a logical order. */
e16bb312 8592
c19d1205
ZW
8593static void
8594do_fpa_cmp (void)
8595{
8596 inst.instruction |= inst.operands[0].reg << 16;
8597 inst.instruction |= inst.operands[1].reg;
8598}
b99bd4ef
NC
8599
8600static void
c19d1205 8601do_fpa_ldmstm (void)
b99bd4ef 8602{
c19d1205
ZW
8603 inst.instruction |= inst.operands[0].reg << 12;
8604 switch (inst.operands[1].imm)
8605 {
8606 case 1: inst.instruction |= CP_T_X; break;
8607 case 2: inst.instruction |= CP_T_Y; break;
8608 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8609 case 4: break;
8610 default: abort ();
8611 }
b99bd4ef 8612
c19d1205
ZW
8613 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8614 {
8615 /* The instruction specified "ea" or "fd", so we can only accept
8616 [Rn]{!}. The instruction does not really support stacking or
8617 unstacking, so we have to emulate these by setting appropriate
8618 bits and offsets. */
8619 constraint (inst.reloc.exp.X_op != O_constant
8620 || inst.reloc.exp.X_add_number != 0,
8621 _("this instruction does not support indexing"));
b99bd4ef 8622
c19d1205
ZW
8623 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8624 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8625
c19d1205
ZW
8626 if (!(inst.instruction & INDEX_UP))
8627 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8628
c19d1205
ZW
8629 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8630 {
8631 inst.operands[2].preind = 0;
8632 inst.operands[2].postind = 1;
8633 }
8634 }
b99bd4ef 8635
c19d1205 8636 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8637}
c19d1205
ZW
8638\f
8639/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8640
c19d1205
ZW
8641static void
8642do_iwmmxt_tandorc (void)
8643{
8644 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8645}
b99bd4ef 8646
c19d1205
ZW
8647static void
8648do_iwmmxt_textrc (void)
8649{
8650 inst.instruction |= inst.operands[0].reg << 12;
8651 inst.instruction |= inst.operands[1].imm;
8652}
b99bd4ef
NC
8653
8654static void
c19d1205 8655do_iwmmxt_textrm (void)
b99bd4ef 8656{
c19d1205
ZW
8657 inst.instruction |= inst.operands[0].reg << 12;
8658 inst.instruction |= inst.operands[1].reg << 16;
8659 inst.instruction |= inst.operands[2].imm;
8660}
b99bd4ef 8661
c19d1205
ZW
8662static void
8663do_iwmmxt_tinsr (void)
8664{
8665 inst.instruction |= inst.operands[0].reg << 16;
8666 inst.instruction |= inst.operands[1].reg << 12;
8667 inst.instruction |= inst.operands[2].imm;
8668}
b99bd4ef 8669
c19d1205
ZW
8670static void
8671do_iwmmxt_tmia (void)
8672{
8673 inst.instruction |= inst.operands[0].reg << 5;
8674 inst.instruction |= inst.operands[1].reg;
8675 inst.instruction |= inst.operands[2].reg << 12;
8676}
b99bd4ef 8677
c19d1205
ZW
8678static void
8679do_iwmmxt_waligni (void)
8680{
8681 inst.instruction |= inst.operands[0].reg << 12;
8682 inst.instruction |= inst.operands[1].reg << 16;
8683 inst.instruction |= inst.operands[2].reg;
8684 inst.instruction |= inst.operands[3].imm << 20;
8685}
b99bd4ef 8686
2d447fca
JM
8687static void
8688do_iwmmxt_wmerge (void)
8689{
8690 inst.instruction |= inst.operands[0].reg << 12;
8691 inst.instruction |= inst.operands[1].reg << 16;
8692 inst.instruction |= inst.operands[2].reg;
8693 inst.instruction |= inst.operands[3].imm << 21;
8694}
8695
c19d1205
ZW
8696static void
8697do_iwmmxt_wmov (void)
8698{
8699 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8700 inst.instruction |= inst.operands[0].reg << 12;
8701 inst.instruction |= inst.operands[1].reg << 16;
8702 inst.instruction |= inst.operands[1].reg;
8703}
b99bd4ef 8704
c19d1205
ZW
8705static void
8706do_iwmmxt_wldstbh (void)
8707{
8f06b2d8 8708 int reloc;
c19d1205 8709 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8710 if (thumb_mode)
8711 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8712 else
8713 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8714 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8715}
8716
c19d1205
ZW
8717static void
8718do_iwmmxt_wldstw (void)
8719{
8720 /* RIWR_RIWC clears .isreg for a control register. */
8721 if (!inst.operands[0].isreg)
8722 {
8723 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8724 inst.instruction |= 0xf0000000;
8725 }
b99bd4ef 8726
c19d1205
ZW
8727 inst.instruction |= inst.operands[0].reg << 12;
8728 encode_arm_cp_address (1, TRUE, TRUE, 0);
8729}
b99bd4ef
NC
8730
8731static void
c19d1205 8732do_iwmmxt_wldstd (void)
b99bd4ef 8733{
c19d1205 8734 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8735 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8736 && inst.operands[1].immisreg)
8737 {
8738 inst.instruction &= ~0x1a000ff;
8739 inst.instruction |= (0xf << 28);
8740 if (inst.operands[1].preind)
8741 inst.instruction |= PRE_INDEX;
8742 if (!inst.operands[1].negative)
8743 inst.instruction |= INDEX_UP;
8744 if (inst.operands[1].writeback)
8745 inst.instruction |= WRITE_BACK;
8746 inst.instruction |= inst.operands[1].reg << 16;
8747 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8748 inst.instruction |= inst.operands[1].imm;
8749 }
8750 else
8751 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8752}
b99bd4ef 8753
c19d1205
ZW
8754static void
8755do_iwmmxt_wshufh (void)
8756{
8757 inst.instruction |= inst.operands[0].reg << 12;
8758 inst.instruction |= inst.operands[1].reg << 16;
8759 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8760 inst.instruction |= (inst.operands[2].imm & 0x0f);
8761}
b99bd4ef 8762
c19d1205
ZW
8763static void
8764do_iwmmxt_wzero (void)
8765{
8766 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8767 inst.instruction |= inst.operands[0].reg;
8768 inst.instruction |= inst.operands[0].reg << 12;
8769 inst.instruction |= inst.operands[0].reg << 16;
8770}
2d447fca
JM
8771
8772static void
8773do_iwmmxt_wrwrwr_or_imm5 (void)
8774{
8775 if (inst.operands[2].isreg)
8776 do_rd_rn_rm ();
8777 else {
8778 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8779 _("immediate operand requires iWMMXt2"));
8780 do_rd_rn ();
8781 if (inst.operands[2].imm == 0)
8782 {
8783 switch ((inst.instruction >> 20) & 0xf)
8784 {
8785 case 4:
8786 case 5:
8787 case 6:
5f4273c7 8788 case 7:
2d447fca
JM
8789 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8790 inst.operands[2].imm = 16;
8791 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8792 break;
8793 case 8:
8794 case 9:
8795 case 10:
8796 case 11:
8797 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8798 inst.operands[2].imm = 32;
8799 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8800 break;
8801 case 12:
8802 case 13:
8803 case 14:
8804 case 15:
8805 {
8806 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8807 unsigned long wrn;
8808 wrn = (inst.instruction >> 16) & 0xf;
8809 inst.instruction &= 0xff0fff0f;
8810 inst.instruction |= wrn;
8811 /* Bail out here; the instruction is now assembled. */
8812 return;
8813 }
8814 }
8815 }
8816 /* Map 32 -> 0, etc. */
8817 inst.operands[2].imm &= 0x1f;
8818 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8819 }
8820}
c19d1205
ZW
8821\f
8822/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8823 operations first, then control, shift, and load/store. */
b99bd4ef 8824
c19d1205 8825/* Insns like "foo X,Y,Z". */
b99bd4ef 8826
c19d1205
ZW
8827static void
8828do_mav_triple (void)
8829{
8830 inst.instruction |= inst.operands[0].reg << 16;
8831 inst.instruction |= inst.operands[1].reg;
8832 inst.instruction |= inst.operands[2].reg << 12;
8833}
b99bd4ef 8834
c19d1205
ZW
8835/* Insns like "foo W,X,Y,Z".
8836 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8837
c19d1205
ZW
8838static void
8839do_mav_quad (void)
8840{
8841 inst.instruction |= inst.operands[0].reg << 5;
8842 inst.instruction |= inst.operands[1].reg << 12;
8843 inst.instruction |= inst.operands[2].reg << 16;
8844 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8845}
8846
c19d1205
ZW
8847/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8848static void
8849do_mav_dspsc (void)
a737bd4d 8850{
c19d1205
ZW
8851 inst.instruction |= inst.operands[1].reg << 12;
8852}
a737bd4d 8853
c19d1205
ZW
8854/* Maverick shift immediate instructions.
8855 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8856 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8857
c19d1205
ZW
8858static void
8859do_mav_shift (void)
8860{
8861 int imm = inst.operands[2].imm;
a737bd4d 8862
c19d1205
ZW
8863 inst.instruction |= inst.operands[0].reg << 12;
8864 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8865
c19d1205
ZW
8866 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8867 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8868 Bit 4 should be 0. */
8869 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8870
c19d1205
ZW
8871 inst.instruction |= imm;
8872}
8873\f
8874/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8875
c19d1205
ZW
8876/* Xscale multiply-accumulate (argument parse)
8877 MIAcc acc0,Rm,Rs
8878 MIAPHcc acc0,Rm,Rs
8879 MIAxycc acc0,Rm,Rs. */
a737bd4d 8880
c19d1205
ZW
8881static void
8882do_xsc_mia (void)
8883{
8884 inst.instruction |= inst.operands[1].reg;
8885 inst.instruction |= inst.operands[2].reg << 12;
8886}
a737bd4d 8887
c19d1205 8888/* Xscale move-accumulator-register (argument parse)
a737bd4d 8889
c19d1205 8890 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8891
c19d1205
ZW
8892static void
8893do_xsc_mar (void)
8894{
8895 inst.instruction |= inst.operands[1].reg << 12;
8896 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8897}
8898
c19d1205 8899/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8900
c19d1205 8901 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8902
8903static void
c19d1205 8904do_xsc_mra (void)
b99bd4ef 8905{
c19d1205
ZW
8906 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8907 inst.instruction |= inst.operands[0].reg << 12;
8908 inst.instruction |= inst.operands[1].reg << 16;
8909}
8910\f
8911/* Encoding functions relevant only to Thumb. */
b99bd4ef 8912
c19d1205
ZW
8913/* inst.operands[i] is a shifted-register operand; encode
8914 it into inst.instruction in the format used by Thumb32. */
8915
8916static void
8917encode_thumb32_shifted_operand (int i)
8918{
8919 unsigned int value = inst.reloc.exp.X_add_number;
8920 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8921
9c3c69f2
PB
8922 constraint (inst.operands[i].immisreg,
8923 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8924 inst.instruction |= inst.operands[i].reg;
8925 if (shift == SHIFT_RRX)
8926 inst.instruction |= SHIFT_ROR << 4;
8927 else
b99bd4ef 8928 {
c19d1205
ZW
8929 constraint (inst.reloc.exp.X_op != O_constant,
8930 _("expression too complex"));
8931
8932 constraint (value > 32
8933 || (value == 32 && (shift == SHIFT_LSL
8934 || shift == SHIFT_ROR)),
8935 _("shift expression is too large"));
8936
8937 if (value == 0)
8938 shift = SHIFT_LSL;
8939 else if (value == 32)
8940 value = 0;
8941
8942 inst.instruction |= shift << 4;
8943 inst.instruction |= (value & 0x1c) << 10;
8944 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8945 }
c19d1205 8946}
b99bd4ef 8947
b99bd4ef 8948
c19d1205
ZW
8949/* inst.operands[i] was set up by parse_address. Encode it into a
8950 Thumb32 format load or store instruction. Reject forms that cannot
8951 be used with such instructions. If is_t is true, reject forms that
8952 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
8953 that cannot be used with a D instruction. If it is a store insn,
8954 reject PC in Rn. */
b99bd4ef 8955
c19d1205
ZW
8956static void
8957encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8958{
5be8be5d 8959 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
8960
8961 constraint (!inst.operands[i].isreg,
53365c0d 8962 _("Instruction does not support =N addresses"));
b99bd4ef 8963
c19d1205
ZW
8964 inst.instruction |= inst.operands[i].reg << 16;
8965 if (inst.operands[i].immisreg)
b99bd4ef 8966 {
5be8be5d 8967 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
8968 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8969 constraint (inst.operands[i].negative,
8970 _("Thumb does not support negative register indexing"));
8971 constraint (inst.operands[i].postind,
8972 _("Thumb does not support register post-indexing"));
8973 constraint (inst.operands[i].writeback,
8974 _("Thumb does not support register indexing with writeback"));
8975 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8976 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8977
f40d1643 8978 inst.instruction |= inst.operands[i].imm;
c19d1205 8979 if (inst.operands[i].shifted)
b99bd4ef 8980 {
c19d1205
ZW
8981 constraint (inst.reloc.exp.X_op != O_constant,
8982 _("expression too complex"));
9c3c69f2
PB
8983 constraint (inst.reloc.exp.X_add_number < 0
8984 || inst.reloc.exp.X_add_number > 3,
c19d1205 8985 _("shift out of range"));
9c3c69f2 8986 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8987 }
8988 inst.reloc.type = BFD_RELOC_UNUSED;
8989 }
8990 else if (inst.operands[i].preind)
8991 {
5be8be5d 8992 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 8993 constraint (is_t && inst.operands[i].writeback,
c19d1205 8994 _("cannot use writeback with this instruction"));
5be8be5d
DG
8995 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
8996 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
c19d1205
ZW
8997
8998 if (is_d)
8999 {
9000 inst.instruction |= 0x01000000;
9001 if (inst.operands[i].writeback)
9002 inst.instruction |= 0x00200000;
b99bd4ef 9003 }
c19d1205 9004 else
b99bd4ef 9005 {
c19d1205
ZW
9006 inst.instruction |= 0x00000c00;
9007 if (inst.operands[i].writeback)
9008 inst.instruction |= 0x00000100;
b99bd4ef 9009 }
c19d1205 9010 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 9011 }
c19d1205 9012 else if (inst.operands[i].postind)
b99bd4ef 9013 {
9c2799c2 9014 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
9015 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
9016 constraint (is_t, _("cannot use post-indexing with this instruction"));
9017
9018 if (is_d)
9019 inst.instruction |= 0x00200000;
9020 else
9021 inst.instruction |= 0x00000900;
9022 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9023 }
9024 else /* unindexed - only for coprocessor */
9025 inst.error = _("instruction does not accept unindexed addressing");
9026}
9027
9028/* Table of Thumb instructions which exist in both 16- and 32-bit
9029 encodings (the latter only in post-V6T2 cores). The index is the
9030 value used in the insns table below. When there is more than one
9031 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
9032 holds variant (1).
9033 Also contains several pseudo-instructions used during relaxation. */
c19d1205 9034#define T16_32_TAB \
21d799b5
NC
9035 X(_adc, 4140, eb400000), \
9036 X(_adcs, 4140, eb500000), \
9037 X(_add, 1c00, eb000000), \
9038 X(_adds, 1c00, eb100000), \
9039 X(_addi, 0000, f1000000), \
9040 X(_addis, 0000, f1100000), \
9041 X(_add_pc,000f, f20f0000), \
9042 X(_add_sp,000d, f10d0000), \
9043 X(_adr, 000f, f20f0000), \
9044 X(_and, 4000, ea000000), \
9045 X(_ands, 4000, ea100000), \
9046 X(_asr, 1000, fa40f000), \
9047 X(_asrs, 1000, fa50f000), \
9048 X(_b, e000, f000b000), \
9049 X(_bcond, d000, f0008000), \
9050 X(_bic, 4380, ea200000), \
9051 X(_bics, 4380, ea300000), \
9052 X(_cmn, 42c0, eb100f00), \
9053 X(_cmp, 2800, ebb00f00), \
9054 X(_cpsie, b660, f3af8400), \
9055 X(_cpsid, b670, f3af8600), \
9056 X(_cpy, 4600, ea4f0000), \
9057 X(_dec_sp,80dd, f1ad0d00), \
9058 X(_eor, 4040, ea800000), \
9059 X(_eors, 4040, ea900000), \
9060 X(_inc_sp,00dd, f10d0d00), \
9061 X(_ldmia, c800, e8900000), \
9062 X(_ldr, 6800, f8500000), \
9063 X(_ldrb, 7800, f8100000), \
9064 X(_ldrh, 8800, f8300000), \
9065 X(_ldrsb, 5600, f9100000), \
9066 X(_ldrsh, 5e00, f9300000), \
9067 X(_ldr_pc,4800, f85f0000), \
9068 X(_ldr_pc2,4800, f85f0000), \
9069 X(_ldr_sp,9800, f85d0000), \
9070 X(_lsl, 0000, fa00f000), \
9071 X(_lsls, 0000, fa10f000), \
9072 X(_lsr, 0800, fa20f000), \
9073 X(_lsrs, 0800, fa30f000), \
9074 X(_mov, 2000, ea4f0000), \
9075 X(_movs, 2000, ea5f0000), \
9076 X(_mul, 4340, fb00f000), \
9077 X(_muls, 4340, ffffffff), /* no 32b muls */ \
9078 X(_mvn, 43c0, ea6f0000), \
9079 X(_mvns, 43c0, ea7f0000), \
9080 X(_neg, 4240, f1c00000), /* rsb #0 */ \
9081 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
9082 X(_orr, 4300, ea400000), \
9083 X(_orrs, 4300, ea500000), \
9084 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9085 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9086 X(_rev, ba00, fa90f080), \
9087 X(_rev16, ba40, fa90f090), \
9088 X(_revsh, bac0, fa90f0b0), \
9089 X(_ror, 41c0, fa60f000), \
9090 X(_rors, 41c0, fa70f000), \
9091 X(_sbc, 4180, eb600000), \
9092 X(_sbcs, 4180, eb700000), \
9093 X(_stmia, c000, e8800000), \
9094 X(_str, 6000, f8400000), \
9095 X(_strb, 7000, f8000000), \
9096 X(_strh, 8000, f8200000), \
9097 X(_str_sp,9000, f84d0000), \
9098 X(_sub, 1e00, eba00000), \
9099 X(_subs, 1e00, ebb00000), \
9100 X(_subi, 8000, f1a00000), \
9101 X(_subis, 8000, f1b00000), \
9102 X(_sxtb, b240, fa4ff080), \
9103 X(_sxth, b200, fa0ff080), \
9104 X(_tst, 4200, ea100f00), \
9105 X(_uxtb, b2c0, fa5ff080), \
9106 X(_uxth, b280, fa1ff080), \
9107 X(_nop, bf00, f3af8000), \
9108 X(_yield, bf10, f3af8001), \
9109 X(_wfe, bf20, f3af8002), \
9110 X(_wfi, bf30, f3af8003), \
9111 X(_sev, bf40, f3af8004),
c19d1205
ZW
9112
9113/* To catch errors in encoding functions, the codes are all offset by
9114 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9115 as 16-bit instructions. */
21d799b5 9116#define X(a,b,c) T_MNEM##a
c19d1205
ZW
9117enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9118#undef X
9119
9120#define X(a,b,c) 0x##b
9121static const unsigned short thumb_op16[] = { T16_32_TAB };
9122#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9123#undef X
9124
9125#define X(a,b,c) 0x##c
9126static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
9127#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9128#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
9129#undef X
9130#undef T16_32_TAB
9131
9132/* Thumb instruction encoders, in alphabetical order. */
9133
92e90b6e 9134/* ADDW or SUBW. */
c921be7d 9135
92e90b6e
PB
9136static void
9137do_t_add_sub_w (void)
9138{
9139 int Rd, Rn;
9140
9141 Rd = inst.operands[0].reg;
9142 Rn = inst.operands[1].reg;
9143
539d4391
NC
9144 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9145 is the SP-{plus,minus}-immediate form of the instruction. */
9146 if (Rn == REG_SP)
9147 constraint (Rd == REG_PC, BAD_PC);
9148 else
9149 reject_bad_reg (Rd);
fdfde340 9150
92e90b6e
PB
9151 inst.instruction |= (Rn << 16) | (Rd << 8);
9152 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9153}
9154
c19d1205
ZW
9155/* Parse an add or subtract instruction. We get here with inst.instruction
9156 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9157
9158static void
9159do_t_add_sub (void)
9160{
9161 int Rd, Rs, Rn;
9162
9163 Rd = inst.operands[0].reg;
9164 Rs = (inst.operands[1].present
9165 ? inst.operands[1].reg /* Rd, Rs, foo */
9166 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9167
e07e6e58
NC
9168 if (Rd == REG_PC)
9169 set_it_insn_type_last ();
9170
c19d1205
ZW
9171 if (unified_syntax)
9172 {
0110f2b8
PB
9173 bfd_boolean flags;
9174 bfd_boolean narrow;
9175 int opcode;
9176
9177 flags = (inst.instruction == T_MNEM_adds
9178 || inst.instruction == T_MNEM_subs);
9179 if (flags)
e07e6e58 9180 narrow = !in_it_block ();
0110f2b8 9181 else
e07e6e58 9182 narrow = in_it_block ();
c19d1205 9183 if (!inst.operands[2].isreg)
b99bd4ef 9184 {
16805f35
PB
9185 int add;
9186
fdfde340
JM
9187 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9188
16805f35
PB
9189 add = (inst.instruction == T_MNEM_add
9190 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
9191 opcode = 0;
9192 if (inst.size_req != 4)
9193 {
0110f2b8
PB
9194 /* Attempt to use a narrow opcode, with relaxation if
9195 appropriate. */
9196 if (Rd == REG_SP && Rs == REG_SP && !flags)
9197 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9198 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9199 opcode = T_MNEM_add_sp;
9200 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9201 opcode = T_MNEM_add_pc;
9202 else if (Rd <= 7 && Rs <= 7 && narrow)
9203 {
9204 if (flags)
9205 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9206 else
9207 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9208 }
9209 if (opcode)
9210 {
9211 inst.instruction = THUMB_OP16(opcode);
9212 inst.instruction |= (Rd << 4) | Rs;
9213 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9214 if (inst.size_req != 2)
9215 inst.relax = opcode;
9216 }
9217 else
9218 constraint (inst.size_req == 2, BAD_HIREG);
9219 }
9220 if (inst.size_req == 4
9221 || (inst.size_req != 2 && !opcode))
9222 {
efd81785
PB
9223 if (Rd == REG_PC)
9224 {
fdfde340 9225 constraint (add, BAD_PC);
efd81785
PB
9226 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9227 _("only SUBS PC, LR, #const allowed"));
9228 constraint (inst.reloc.exp.X_op != O_constant,
9229 _("expression too complex"));
9230 constraint (inst.reloc.exp.X_add_number < 0
9231 || inst.reloc.exp.X_add_number > 0xff,
9232 _("immediate value out of range"));
9233 inst.instruction = T2_SUBS_PC_LR
9234 | inst.reloc.exp.X_add_number;
9235 inst.reloc.type = BFD_RELOC_UNUSED;
9236 return;
9237 }
9238 else if (Rs == REG_PC)
16805f35
PB
9239 {
9240 /* Always use addw/subw. */
9241 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9242 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9243 }
9244 else
9245 {
9246 inst.instruction = THUMB_OP32 (inst.instruction);
9247 inst.instruction = (inst.instruction & 0xe1ffffff)
9248 | 0x10000000;
9249 if (flags)
9250 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9251 else
9252 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9253 }
dc4503c6
PB
9254 inst.instruction |= Rd << 8;
9255 inst.instruction |= Rs << 16;
0110f2b8 9256 }
b99bd4ef 9257 }
c19d1205
ZW
9258 else
9259 {
9260 Rn = inst.operands[2].reg;
9261 /* See if we can do this with a 16-bit instruction. */
9262 if (!inst.operands[2].shifted && inst.size_req != 4)
9263 {
e27ec89e
PB
9264 if (Rd > 7 || Rs > 7 || Rn > 7)
9265 narrow = FALSE;
9266
9267 if (narrow)
c19d1205 9268 {
e27ec89e
PB
9269 inst.instruction = ((inst.instruction == T_MNEM_adds
9270 || inst.instruction == T_MNEM_add)
c19d1205
ZW
9271 ? T_OPCODE_ADD_R3
9272 : T_OPCODE_SUB_R3);
9273 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9274 return;
9275 }
b99bd4ef 9276
7e806470 9277 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 9278 {
7e806470
PB
9279 /* Thumb-1 cores (except v6-M) require at least one high
9280 register in a narrow non flag setting add. */
9281 if (Rd > 7 || Rn > 7
9282 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9283 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9284 {
7e806470
PB
9285 if (Rd == Rn)
9286 {
9287 Rn = Rs;
9288 Rs = Rd;
9289 }
c19d1205
ZW
9290 inst.instruction = T_OPCODE_ADD_HI;
9291 inst.instruction |= (Rd & 8) << 4;
9292 inst.instruction |= (Rd & 7);
9293 inst.instruction |= Rn << 3;
9294 return;
9295 }
c19d1205
ZW
9296 }
9297 }
c921be7d 9298
fdfde340
JM
9299 constraint (Rd == REG_PC, BAD_PC);
9300 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9301 constraint (Rs == REG_PC, BAD_PC);
9302 reject_bad_reg (Rn);
9303
c19d1205
ZW
9304 /* If we get here, it can't be done in 16 bits. */
9305 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9306 _("shift must be constant"));
9307 inst.instruction = THUMB_OP32 (inst.instruction);
9308 inst.instruction |= Rd << 8;
9309 inst.instruction |= Rs << 16;
9310 encode_thumb32_shifted_operand (2);
9311 }
9312 }
9313 else
9314 {
9315 constraint (inst.instruction == T_MNEM_adds
9316 || inst.instruction == T_MNEM_subs,
9317 BAD_THUMB32);
b99bd4ef 9318
c19d1205 9319 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9320 {
c19d1205
ZW
9321 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9322 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9323 BAD_HIREG);
9324
9325 inst.instruction = (inst.instruction == T_MNEM_add
9326 ? 0x0000 : 0x8000);
9327 inst.instruction |= (Rd << 4) | Rs;
9328 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9329 return;
9330 }
9331
c19d1205
ZW
9332 Rn = inst.operands[2].reg;
9333 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9334
c19d1205
ZW
9335 /* We now have Rd, Rs, and Rn set to registers. */
9336 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9337 {
c19d1205
ZW
9338 /* Can't do this for SUB. */
9339 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9340 inst.instruction = T_OPCODE_ADD_HI;
9341 inst.instruction |= (Rd & 8) << 4;
9342 inst.instruction |= (Rd & 7);
9343 if (Rs == Rd)
9344 inst.instruction |= Rn << 3;
9345 else if (Rn == Rd)
9346 inst.instruction |= Rs << 3;
9347 else
9348 constraint (1, _("dest must overlap one source register"));
9349 }
9350 else
9351 {
9352 inst.instruction = (inst.instruction == T_MNEM_add
9353 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9354 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9355 }
b99bd4ef 9356 }
b99bd4ef
NC
9357}
9358
c19d1205
ZW
9359static void
9360do_t_adr (void)
9361{
fdfde340
JM
9362 unsigned Rd;
9363
9364 Rd = inst.operands[0].reg;
9365 reject_bad_reg (Rd);
9366
9367 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9368 {
9369 /* Defer to section relaxation. */
9370 inst.relax = inst.instruction;
9371 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9372 inst.instruction |= Rd << 4;
0110f2b8
PB
9373 }
9374 else if (unified_syntax && inst.size_req != 2)
e9f89963 9375 {
0110f2b8 9376 /* Generate a 32-bit opcode. */
e9f89963 9377 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9378 inst.instruction |= Rd << 8;
e9f89963
PB
9379 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9380 inst.reloc.pc_rel = 1;
9381 }
9382 else
9383 {
0110f2b8 9384 /* Generate a 16-bit opcode. */
e9f89963
PB
9385 inst.instruction = THUMB_OP16 (inst.instruction);
9386 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9387 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9388 inst.reloc.pc_rel = 1;
b99bd4ef 9389
fdfde340 9390 inst.instruction |= Rd << 4;
e9f89963 9391 }
c19d1205 9392}
b99bd4ef 9393
c19d1205
ZW
9394/* Arithmetic instructions for which there is just one 16-bit
9395 instruction encoding, and it allows only two low registers.
9396 For maximal compatibility with ARM syntax, we allow three register
9397 operands even when Thumb-32 instructions are not available, as long
9398 as the first two are identical. For instance, both "sbc r0,r1" and
9399 "sbc r0,r0,r1" are allowed. */
b99bd4ef 9400static void
c19d1205 9401do_t_arit3 (void)
b99bd4ef 9402{
c19d1205 9403 int Rd, Rs, Rn;
b99bd4ef 9404
c19d1205
ZW
9405 Rd = inst.operands[0].reg;
9406 Rs = (inst.operands[1].present
9407 ? inst.operands[1].reg /* Rd, Rs, foo */
9408 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9409 Rn = inst.operands[2].reg;
b99bd4ef 9410
fdfde340
JM
9411 reject_bad_reg (Rd);
9412 reject_bad_reg (Rs);
9413 if (inst.operands[2].isreg)
9414 reject_bad_reg (Rn);
9415
c19d1205 9416 if (unified_syntax)
b99bd4ef 9417 {
c19d1205
ZW
9418 if (!inst.operands[2].isreg)
9419 {
9420 /* For an immediate, we always generate a 32-bit opcode;
9421 section relaxation will shrink it later if possible. */
9422 inst.instruction = THUMB_OP32 (inst.instruction);
9423 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9424 inst.instruction |= Rd << 8;
9425 inst.instruction |= Rs << 16;
9426 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9427 }
9428 else
9429 {
e27ec89e
PB
9430 bfd_boolean narrow;
9431
c19d1205 9432 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9433 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9434 narrow = !in_it_block ();
e27ec89e 9435 else
e07e6e58 9436 narrow = in_it_block ();
e27ec89e
PB
9437
9438 if (Rd > 7 || Rn > 7 || Rs > 7)
9439 narrow = FALSE;
9440 if (inst.operands[2].shifted)
9441 narrow = FALSE;
9442 if (inst.size_req == 4)
9443 narrow = FALSE;
9444
9445 if (narrow
c19d1205
ZW
9446 && Rd == Rs)
9447 {
9448 inst.instruction = THUMB_OP16 (inst.instruction);
9449 inst.instruction |= Rd;
9450 inst.instruction |= Rn << 3;
9451 return;
9452 }
b99bd4ef 9453
c19d1205
ZW
9454 /* If we get here, it can't be done in 16 bits. */
9455 constraint (inst.operands[2].shifted
9456 && inst.operands[2].immisreg,
9457 _("shift must be constant"));
9458 inst.instruction = THUMB_OP32 (inst.instruction);
9459 inst.instruction |= Rd << 8;
9460 inst.instruction |= Rs << 16;
9461 encode_thumb32_shifted_operand (2);
9462 }
a737bd4d 9463 }
c19d1205 9464 else
b99bd4ef 9465 {
c19d1205
ZW
9466 /* On its face this is a lie - the instruction does set the
9467 flags. However, the only supported mnemonic in this mode
9468 says it doesn't. */
9469 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9470
c19d1205
ZW
9471 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9472 _("unshifted register required"));
9473 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9474 constraint (Rd != Rs,
9475 _("dest and source1 must be the same register"));
a737bd4d 9476
c19d1205
ZW
9477 inst.instruction = THUMB_OP16 (inst.instruction);
9478 inst.instruction |= Rd;
9479 inst.instruction |= Rn << 3;
b99bd4ef 9480 }
a737bd4d 9481}
b99bd4ef 9482
c19d1205
ZW
9483/* Similarly, but for instructions where the arithmetic operation is
9484 commutative, so we can allow either of them to be different from
9485 the destination operand in a 16-bit instruction. For instance, all
9486 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9487 accepted. */
9488static void
9489do_t_arit3c (void)
a737bd4d 9490{
c19d1205 9491 int Rd, Rs, Rn;
b99bd4ef 9492
c19d1205
ZW
9493 Rd = inst.operands[0].reg;
9494 Rs = (inst.operands[1].present
9495 ? inst.operands[1].reg /* Rd, Rs, foo */
9496 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9497 Rn = inst.operands[2].reg;
c921be7d 9498
fdfde340
JM
9499 reject_bad_reg (Rd);
9500 reject_bad_reg (Rs);
9501 if (inst.operands[2].isreg)
9502 reject_bad_reg (Rn);
a737bd4d 9503
c19d1205 9504 if (unified_syntax)
a737bd4d 9505 {
c19d1205 9506 if (!inst.operands[2].isreg)
b99bd4ef 9507 {
c19d1205
ZW
9508 /* For an immediate, we always generate a 32-bit opcode;
9509 section relaxation will shrink it later if possible. */
9510 inst.instruction = THUMB_OP32 (inst.instruction);
9511 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9512 inst.instruction |= Rd << 8;
9513 inst.instruction |= Rs << 16;
9514 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9515 }
c19d1205 9516 else
a737bd4d 9517 {
e27ec89e
PB
9518 bfd_boolean narrow;
9519
c19d1205 9520 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9521 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9522 narrow = !in_it_block ();
e27ec89e 9523 else
e07e6e58 9524 narrow = in_it_block ();
e27ec89e
PB
9525
9526 if (Rd > 7 || Rn > 7 || Rs > 7)
9527 narrow = FALSE;
9528 if (inst.operands[2].shifted)
9529 narrow = FALSE;
9530 if (inst.size_req == 4)
9531 narrow = FALSE;
9532
9533 if (narrow)
a737bd4d 9534 {
c19d1205 9535 if (Rd == Rs)
a737bd4d 9536 {
c19d1205
ZW
9537 inst.instruction = THUMB_OP16 (inst.instruction);
9538 inst.instruction |= Rd;
9539 inst.instruction |= Rn << 3;
9540 return;
a737bd4d 9541 }
c19d1205 9542 if (Rd == Rn)
a737bd4d 9543 {
c19d1205
ZW
9544 inst.instruction = THUMB_OP16 (inst.instruction);
9545 inst.instruction |= Rd;
9546 inst.instruction |= Rs << 3;
9547 return;
a737bd4d
NC
9548 }
9549 }
c19d1205
ZW
9550
9551 /* If we get here, it can't be done in 16 bits. */
9552 constraint (inst.operands[2].shifted
9553 && inst.operands[2].immisreg,
9554 _("shift must be constant"));
9555 inst.instruction = THUMB_OP32 (inst.instruction);
9556 inst.instruction |= Rd << 8;
9557 inst.instruction |= Rs << 16;
9558 encode_thumb32_shifted_operand (2);
a737bd4d 9559 }
b99bd4ef 9560 }
c19d1205
ZW
9561 else
9562 {
9563 /* On its face this is a lie - the instruction does set the
9564 flags. However, the only supported mnemonic in this mode
9565 says it doesn't. */
9566 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9567
c19d1205
ZW
9568 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9569 _("unshifted register required"));
9570 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9571
9572 inst.instruction = THUMB_OP16 (inst.instruction);
9573 inst.instruction |= Rd;
9574
9575 if (Rd == Rs)
9576 inst.instruction |= Rn << 3;
9577 else if (Rd == Rn)
9578 inst.instruction |= Rs << 3;
9579 else
9580 constraint (1, _("dest must overlap one source register"));
9581 }
a737bd4d
NC
9582}
9583
62b3e311
PB
9584static void
9585do_t_barrier (void)
9586{
9587 if (inst.operands[0].present)
9588 {
9589 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
9590 && inst.operands[0].imm > 0xf
9591 && inst.operands[0].imm < 0x0,
bd3ba5d1 9592 _("bad barrier type"));
62b3e311
PB
9593 inst.instruction |= inst.operands[0].imm;
9594 }
9595 else
9596 inst.instruction |= 0xf;
9597}
9598
c19d1205
ZW
9599static void
9600do_t_bfc (void)
a737bd4d 9601{
fdfde340 9602 unsigned Rd;
c19d1205
ZW
9603 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9604 constraint (msb > 32, _("bit-field extends past end of register"));
9605 /* The instruction encoding stores the LSB and MSB,
9606 not the LSB and width. */
fdfde340
JM
9607 Rd = inst.operands[0].reg;
9608 reject_bad_reg (Rd);
9609 inst.instruction |= Rd << 8;
c19d1205
ZW
9610 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9611 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9612 inst.instruction |= msb - 1;
b99bd4ef
NC
9613}
9614
c19d1205
ZW
9615static void
9616do_t_bfi (void)
b99bd4ef 9617{
fdfde340 9618 int Rd, Rn;
c19d1205 9619 unsigned int msb;
b99bd4ef 9620
fdfde340
JM
9621 Rd = inst.operands[0].reg;
9622 reject_bad_reg (Rd);
9623
c19d1205
ZW
9624 /* #0 in second position is alternative syntax for bfc, which is
9625 the same instruction but with REG_PC in the Rm field. */
9626 if (!inst.operands[1].isreg)
fdfde340
JM
9627 Rn = REG_PC;
9628 else
9629 {
9630 Rn = inst.operands[1].reg;
9631 reject_bad_reg (Rn);
9632 }
b99bd4ef 9633
c19d1205
ZW
9634 msb = inst.operands[2].imm + inst.operands[3].imm;
9635 constraint (msb > 32, _("bit-field extends past end of register"));
9636 /* The instruction encoding stores the LSB and MSB,
9637 not the LSB and width. */
fdfde340
JM
9638 inst.instruction |= Rd << 8;
9639 inst.instruction |= Rn << 16;
c19d1205
ZW
9640 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9641 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9642 inst.instruction |= msb - 1;
b99bd4ef
NC
9643}
9644
c19d1205
ZW
9645static void
9646do_t_bfx (void)
b99bd4ef 9647{
fdfde340
JM
9648 unsigned Rd, Rn;
9649
9650 Rd = inst.operands[0].reg;
9651 Rn = inst.operands[1].reg;
9652
9653 reject_bad_reg (Rd);
9654 reject_bad_reg (Rn);
9655
c19d1205
ZW
9656 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9657 _("bit-field extends past end of register"));
fdfde340
JM
9658 inst.instruction |= Rd << 8;
9659 inst.instruction |= Rn << 16;
c19d1205
ZW
9660 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9661 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9662 inst.instruction |= inst.operands[3].imm - 1;
9663}
b99bd4ef 9664
c19d1205
ZW
9665/* ARM V5 Thumb BLX (argument parse)
9666 BLX <target_addr> which is BLX(1)
9667 BLX <Rm> which is BLX(2)
9668 Unfortunately, there are two different opcodes for this mnemonic.
9669 So, the insns[].value is not used, and the code here zaps values
9670 into inst.instruction.
b99bd4ef 9671
c19d1205
ZW
9672 ??? How to take advantage of the additional two bits of displacement
9673 available in Thumb32 mode? Need new relocation? */
b99bd4ef 9674
c19d1205
ZW
9675static void
9676do_t_blx (void)
9677{
e07e6e58
NC
9678 set_it_insn_type_last ();
9679
c19d1205 9680 if (inst.operands[0].isreg)
fdfde340
JM
9681 {
9682 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9683 /* We have a register, so this is BLX(2). */
9684 inst.instruction |= inst.operands[0].reg << 3;
9685 }
b99bd4ef
NC
9686 else
9687 {
c19d1205 9688 /* No register. This must be BLX(1). */
2fc8bdac 9689 inst.instruction = 0xf000e800;
0855e32b 9690 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
9691 }
9692}
9693
c19d1205
ZW
9694static void
9695do_t_branch (void)
b99bd4ef 9696{
0110f2b8 9697 int opcode;
dfa9f0d5 9698 int cond;
9ae92b05 9699 int reloc;
dfa9f0d5 9700
e07e6e58
NC
9701 cond = inst.cond;
9702 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9703
9704 if (in_it_block ())
dfa9f0d5
PB
9705 {
9706 /* Conditional branches inside IT blocks are encoded as unconditional
9707 branches. */
9708 cond = COND_ALWAYS;
dfa9f0d5
PB
9709 }
9710 else
9711 cond = inst.cond;
9712
9713 if (cond != COND_ALWAYS)
0110f2b8
PB
9714 opcode = T_MNEM_bcond;
9715 else
9716 opcode = inst.instruction;
9717
12d6b0b7
RS
9718 if (unified_syntax
9719 && (inst.size_req == 4
9720 || (inst.size_req != 2 && inst.operands[0].hasreloc)))
c19d1205 9721 {
0110f2b8 9722 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9723 if (cond == COND_ALWAYS)
9ae92b05 9724 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9725 else
9726 {
9c2799c2 9727 gas_assert (cond != 0xF);
dfa9f0d5 9728 inst.instruction |= cond << 22;
9ae92b05 9729 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
9730 }
9731 }
b99bd4ef
NC
9732 else
9733 {
0110f2b8 9734 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9735 if (cond == COND_ALWAYS)
9ae92b05 9736 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 9737 else
b99bd4ef 9738 {
dfa9f0d5 9739 inst.instruction |= cond << 8;
9ae92b05 9740 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9741 }
0110f2b8
PB
9742 /* Allow section relaxation. */
9743 if (unified_syntax && inst.size_req != 2)
9744 inst.relax = opcode;
b99bd4ef 9745 }
9ae92b05 9746 inst.reloc.type = reloc;
c19d1205 9747 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9748}
9749
9750static void
c19d1205 9751do_t_bkpt (void)
b99bd4ef 9752{
dfa9f0d5
PB
9753 constraint (inst.cond != COND_ALWAYS,
9754 _("instruction is always unconditional"));
c19d1205 9755 if (inst.operands[0].present)
b99bd4ef 9756 {
c19d1205
ZW
9757 constraint (inst.operands[0].imm > 255,
9758 _("immediate value out of range"));
9759 inst.instruction |= inst.operands[0].imm;
e07e6e58 9760 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 9761 }
b99bd4ef
NC
9762}
9763
9764static void
c19d1205 9765do_t_branch23 (void)
b99bd4ef 9766{
e07e6e58 9767 set_it_insn_type_last ();
0855e32b
NS
9768 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
9769
9770 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
9771 this file. We used to simply ignore the PLT reloc type here --
9772 the branch encoding is now needed to deal with TLSCALL relocs.
9773 So if we see a PLT reloc now, put it back to how it used to be to
9774 keep the preexisting behaviour. */
9775 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
9776 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 9777
4343666d 9778#if defined(OBJ_COFF)
c19d1205
ZW
9779 /* If the destination of the branch is a defined symbol which does not have
9780 the THUMB_FUNC attribute, then we must be calling a function which has
9781 the (interfacearm) attribute. We look for the Thumb entry point to that
9782 function and change the branch to refer to that function instead. */
9783 if ( inst.reloc.exp.X_op == O_symbol
9784 && inst.reloc.exp.X_add_symbol != NULL
9785 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9786 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9787 inst.reloc.exp.X_add_symbol =
9788 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 9789#endif
90e4755a
RE
9790}
9791
9792static void
c19d1205 9793do_t_bx (void)
90e4755a 9794{
e07e6e58 9795 set_it_insn_type_last ();
c19d1205
ZW
9796 inst.instruction |= inst.operands[0].reg << 3;
9797 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9798 should cause the alignment to be checked once it is known. This is
9799 because BX PC only works if the instruction is word aligned. */
9800}
90e4755a 9801
c19d1205
ZW
9802static void
9803do_t_bxj (void)
9804{
fdfde340 9805 int Rm;
90e4755a 9806
e07e6e58 9807 set_it_insn_type_last ();
fdfde340
JM
9808 Rm = inst.operands[0].reg;
9809 reject_bad_reg (Rm);
9810 inst.instruction |= Rm << 16;
90e4755a
RE
9811}
9812
9813static void
c19d1205 9814do_t_clz (void)
90e4755a 9815{
fdfde340
JM
9816 unsigned Rd;
9817 unsigned Rm;
9818
9819 Rd = inst.operands[0].reg;
9820 Rm = inst.operands[1].reg;
9821
9822 reject_bad_reg (Rd);
9823 reject_bad_reg (Rm);
9824
9825 inst.instruction |= Rd << 8;
9826 inst.instruction |= Rm << 16;
9827 inst.instruction |= Rm;
c19d1205 9828}
90e4755a 9829
dfa9f0d5
PB
9830static void
9831do_t_cps (void)
9832{
e07e6e58 9833 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
9834 inst.instruction |= inst.operands[0].imm;
9835}
9836
c19d1205
ZW
9837static void
9838do_t_cpsi (void)
9839{
e07e6e58 9840 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 9841 if (unified_syntax
62b3e311
PB
9842 && (inst.operands[1].present || inst.size_req == 4)
9843 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9844 {
c19d1205
ZW
9845 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9846 inst.instruction = 0xf3af8000;
9847 inst.instruction |= imod << 9;
9848 inst.instruction |= inst.operands[0].imm << 5;
9849 if (inst.operands[1].present)
9850 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9851 }
c19d1205 9852 else
90e4755a 9853 {
62b3e311
PB
9854 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9855 && (inst.operands[0].imm & 4),
9856 _("selected processor does not support 'A' form "
9857 "of this instruction"));
9858 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9859 _("Thumb does not support the 2-argument "
9860 "form of this instruction"));
9861 inst.instruction |= inst.operands[0].imm;
90e4755a 9862 }
90e4755a
RE
9863}
9864
c19d1205
ZW
9865/* THUMB CPY instruction (argument parse). */
9866
90e4755a 9867static void
c19d1205 9868do_t_cpy (void)
90e4755a 9869{
c19d1205 9870 if (inst.size_req == 4)
90e4755a 9871 {
c19d1205
ZW
9872 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9873 inst.instruction |= inst.operands[0].reg << 8;
9874 inst.instruction |= inst.operands[1].reg;
90e4755a 9875 }
c19d1205 9876 else
90e4755a 9877 {
c19d1205
ZW
9878 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9879 inst.instruction |= (inst.operands[0].reg & 0x7);
9880 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9881 }
90e4755a
RE
9882}
9883
90e4755a 9884static void
25fe350b 9885do_t_cbz (void)
90e4755a 9886{
e07e6e58 9887 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
9888 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9889 inst.instruction |= inst.operands[0].reg;
9890 inst.reloc.pc_rel = 1;
9891 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9892}
90e4755a 9893
62b3e311
PB
9894static void
9895do_t_dbg (void)
9896{
9897 inst.instruction |= inst.operands[0].imm;
9898}
9899
9900static void
9901do_t_div (void)
9902{
fdfde340
JM
9903 unsigned Rd, Rn, Rm;
9904
9905 Rd = inst.operands[0].reg;
9906 Rn = (inst.operands[1].present
9907 ? inst.operands[1].reg : Rd);
9908 Rm = inst.operands[2].reg;
9909
9910 reject_bad_reg (Rd);
9911 reject_bad_reg (Rn);
9912 reject_bad_reg (Rm);
9913
9914 inst.instruction |= Rd << 8;
9915 inst.instruction |= Rn << 16;
9916 inst.instruction |= Rm;
62b3e311
PB
9917}
9918
c19d1205
ZW
9919static void
9920do_t_hint (void)
9921{
9922 if (unified_syntax && inst.size_req == 4)
9923 inst.instruction = THUMB_OP32 (inst.instruction);
9924 else
9925 inst.instruction = THUMB_OP16 (inst.instruction);
9926}
90e4755a 9927
c19d1205
ZW
9928static void
9929do_t_it (void)
9930{
9931 unsigned int cond = inst.operands[0].imm;
e27ec89e 9932
e07e6e58
NC
9933 set_it_insn_type (IT_INSN);
9934 now_it.mask = (inst.instruction & 0xf) | 0x10;
9935 now_it.cc = cond;
e27ec89e
PB
9936
9937 /* If the condition is a negative condition, invert the mask. */
c19d1205 9938 if ((cond & 0x1) == 0x0)
90e4755a 9939 {
c19d1205 9940 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9941
c19d1205
ZW
9942 if ((mask & 0x7) == 0)
9943 /* no conversion needed */;
9944 else if ((mask & 0x3) == 0)
e27ec89e
PB
9945 mask ^= 0x8;
9946 else if ((mask & 0x1) == 0)
9947 mask ^= 0xC;
c19d1205 9948 else
e27ec89e 9949 mask ^= 0xE;
90e4755a 9950
e27ec89e
PB
9951 inst.instruction &= 0xfff0;
9952 inst.instruction |= mask;
c19d1205 9953 }
90e4755a 9954
c19d1205
ZW
9955 inst.instruction |= cond << 4;
9956}
90e4755a 9957
3c707909
PB
9958/* Helper function used for both push/pop and ldm/stm. */
9959static void
9960encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9961{
9962 bfd_boolean load;
9963
9964 load = (inst.instruction & (1 << 20)) != 0;
9965
9966 if (mask & (1 << 13))
9967 inst.error = _("SP not allowed in register list");
1e5b0379
NC
9968
9969 if ((mask & (1 << base)) != 0
9970 && writeback)
9971 inst.error = _("having the base register in the register list when "
9972 "using write back is UNPREDICTABLE");
9973
3c707909
PB
9974 if (load)
9975 {
e07e6e58
NC
9976 if (mask & (1 << 15))
9977 {
9978 if (mask & (1 << 14))
9979 inst.error = _("LR and PC should not both be in register list");
9980 else
9981 set_it_insn_type_last ();
9982 }
3c707909
PB
9983 }
9984 else
9985 {
9986 if (mask & (1 << 15))
9987 inst.error = _("PC not allowed in register list");
3c707909
PB
9988 }
9989
9990 if ((mask & (mask - 1)) == 0)
9991 {
9992 /* Single register transfers implemented as str/ldr. */
9993 if (writeback)
9994 {
9995 if (inst.instruction & (1 << 23))
9996 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9997 else
9998 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9999 }
10000 else
10001 {
10002 if (inst.instruction & (1 << 23))
10003 inst.instruction = 0x00800000; /* ia -> [base] */
10004 else
10005 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
10006 }
10007
10008 inst.instruction |= 0xf8400000;
10009 if (load)
10010 inst.instruction |= 0x00100000;
10011
5f4273c7 10012 mask = ffs (mask) - 1;
3c707909
PB
10013 mask <<= 12;
10014 }
10015 else if (writeback)
10016 inst.instruction |= WRITE_BACK;
10017
10018 inst.instruction |= mask;
10019 inst.instruction |= base << 16;
10020}
10021
c19d1205
ZW
10022static void
10023do_t_ldmstm (void)
10024{
10025 /* This really doesn't seem worth it. */
10026 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10027 _("expression too complex"));
10028 constraint (inst.operands[1].writeback,
10029 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 10030
c19d1205
ZW
10031 if (unified_syntax)
10032 {
3c707909
PB
10033 bfd_boolean narrow;
10034 unsigned mask;
10035
10036 narrow = FALSE;
c19d1205
ZW
10037 /* See if we can use a 16-bit instruction. */
10038 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
10039 && inst.size_req != 4
3c707909 10040 && !(inst.operands[1].imm & ~0xff))
90e4755a 10041 {
3c707909 10042 mask = 1 << inst.operands[0].reg;
90e4755a 10043
eab4f823 10044 if (inst.operands[0].reg <= 7)
90e4755a 10045 {
3c707909 10046 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
10047 ? inst.operands[0].writeback
10048 : (inst.operands[0].writeback
10049 == !(inst.operands[1].imm & mask)))
10050 {
10051 if (inst.instruction == T_MNEM_stmia
10052 && (inst.operands[1].imm & mask)
10053 && (inst.operands[1].imm & (mask - 1)))
10054 as_warn (_("value stored for r%d is UNKNOWN"),
10055 inst.operands[0].reg);
3c707909 10056
eab4f823
MGD
10057 inst.instruction = THUMB_OP16 (inst.instruction);
10058 inst.instruction |= inst.operands[0].reg << 8;
10059 inst.instruction |= inst.operands[1].imm;
10060 narrow = TRUE;
10061 }
10062 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10063 {
10064 /* This means 1 register in reg list one of 3 situations:
10065 1. Instruction is stmia, but without writeback.
10066 2. lmdia without writeback, but with Rn not in
10067 reglist.
10068 3. ldmia with writeback, but with Rn in reglist.
10069 Case 3 is UNPREDICTABLE behaviour, so we handle
10070 case 1 and 2 which can be converted into a 16-bit
10071 str or ldr. The SP cases are handled below. */
10072 unsigned long opcode;
10073 /* First, record an error for Case 3. */
10074 if (inst.operands[1].imm & mask
10075 && inst.operands[0].writeback)
10076 inst.error =
10077 _("having the base register in the register list when "
10078 "using write back is UNPREDICTABLE");
10079
10080 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
10081 : T_MNEM_ldr);
10082 inst.instruction = THUMB_OP16 (opcode);
10083 inst.instruction |= inst.operands[0].reg << 3;
10084 inst.instruction |= (ffs (inst.operands[1].imm)-1);
10085 narrow = TRUE;
10086 }
90e4755a 10087 }
eab4f823 10088 else if (inst.operands[0] .reg == REG_SP)
90e4755a 10089 {
eab4f823
MGD
10090 if (inst.operands[0].writeback)
10091 {
10092 inst.instruction =
10093 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10094 ? T_MNEM_push : T_MNEM_pop);
10095 inst.instruction |= inst.operands[1].imm;
10096 narrow = TRUE;
10097 }
10098 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10099 {
10100 inst.instruction =
10101 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10102 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10103 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10104 narrow = TRUE;
10105 }
90e4755a 10106 }
3c707909
PB
10107 }
10108
10109 if (!narrow)
10110 {
c19d1205
ZW
10111 if (inst.instruction < 0xffff)
10112 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 10113
5f4273c7
NC
10114 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10115 inst.operands[0].writeback);
90e4755a
RE
10116 }
10117 }
c19d1205 10118 else
90e4755a 10119 {
c19d1205
ZW
10120 constraint (inst.operands[0].reg > 7
10121 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
10122 constraint (inst.instruction != T_MNEM_ldmia
10123 && inst.instruction != T_MNEM_stmia,
10124 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 10125 if (inst.instruction == T_MNEM_stmia)
f03698e6 10126 {
c19d1205
ZW
10127 if (!inst.operands[0].writeback)
10128 as_warn (_("this instruction will write back the base register"));
10129 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10130 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 10131 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 10132 inst.operands[0].reg);
f03698e6 10133 }
c19d1205 10134 else
90e4755a 10135 {
c19d1205
ZW
10136 if (!inst.operands[0].writeback
10137 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10138 as_warn (_("this instruction will write back the base register"));
10139 else if (inst.operands[0].writeback
10140 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10141 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
10142 }
10143
c19d1205
ZW
10144 inst.instruction = THUMB_OP16 (inst.instruction);
10145 inst.instruction |= inst.operands[0].reg << 8;
10146 inst.instruction |= inst.operands[1].imm;
10147 }
10148}
e28cd48c 10149
c19d1205
ZW
10150static void
10151do_t_ldrex (void)
10152{
10153 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10154 || inst.operands[1].postind || inst.operands[1].writeback
10155 || inst.operands[1].immisreg || inst.operands[1].shifted
10156 || inst.operands[1].negative,
01cfc07f 10157 BAD_ADDR_MODE);
e28cd48c 10158
5be8be5d
DG
10159 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10160
c19d1205
ZW
10161 inst.instruction |= inst.operands[0].reg << 12;
10162 inst.instruction |= inst.operands[1].reg << 16;
10163 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10164}
e28cd48c 10165
c19d1205
ZW
10166static void
10167do_t_ldrexd (void)
10168{
10169 if (!inst.operands[1].present)
1cac9012 10170 {
c19d1205
ZW
10171 constraint (inst.operands[0].reg == REG_LR,
10172 _("r14 not allowed as first register "
10173 "when second register is omitted"));
10174 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 10175 }
c19d1205
ZW
10176 constraint (inst.operands[0].reg == inst.operands[1].reg,
10177 BAD_OVERLAP);
b99bd4ef 10178
c19d1205
ZW
10179 inst.instruction |= inst.operands[0].reg << 12;
10180 inst.instruction |= inst.operands[1].reg << 8;
10181 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10182}
10183
10184static void
c19d1205 10185do_t_ldst (void)
b99bd4ef 10186{
0110f2b8
PB
10187 unsigned long opcode;
10188 int Rn;
10189
e07e6e58
NC
10190 if (inst.operands[0].isreg
10191 && !inst.operands[0].preind
10192 && inst.operands[0].reg == REG_PC)
10193 set_it_insn_type_last ();
10194
0110f2b8 10195 opcode = inst.instruction;
c19d1205 10196 if (unified_syntax)
b99bd4ef 10197 {
53365c0d
PB
10198 if (!inst.operands[1].isreg)
10199 {
10200 if (opcode <= 0xffff)
10201 inst.instruction = THUMB_OP32 (opcode);
10202 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10203 return;
10204 }
0110f2b8
PB
10205 if (inst.operands[1].isreg
10206 && !inst.operands[1].writeback
c19d1205
ZW
10207 && !inst.operands[1].shifted && !inst.operands[1].postind
10208 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
10209 && opcode <= 0xffff
10210 && inst.size_req != 4)
c19d1205 10211 {
0110f2b8
PB
10212 /* Insn may have a 16-bit form. */
10213 Rn = inst.operands[1].reg;
10214 if (inst.operands[1].immisreg)
10215 {
10216 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 10217 /* [Rn, Rik] */
0110f2b8
PB
10218 if (Rn <= 7 && inst.operands[1].imm <= 7)
10219 goto op16;
5be8be5d
DG
10220 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10221 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
10222 }
10223 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10224 && opcode != T_MNEM_ldrsb)
10225 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10226 || (Rn == REG_SP && opcode == T_MNEM_str))
10227 {
10228 /* [Rn, #const] */
10229 if (Rn > 7)
10230 {
10231 if (Rn == REG_PC)
10232 {
10233 if (inst.reloc.pc_rel)
10234 opcode = T_MNEM_ldr_pc2;
10235 else
10236 opcode = T_MNEM_ldr_pc;
10237 }
10238 else
10239 {
10240 if (opcode == T_MNEM_ldr)
10241 opcode = T_MNEM_ldr_sp;
10242 else
10243 opcode = T_MNEM_str_sp;
10244 }
10245 inst.instruction = inst.operands[0].reg << 8;
10246 }
10247 else
10248 {
10249 inst.instruction = inst.operands[0].reg;
10250 inst.instruction |= inst.operands[1].reg << 3;
10251 }
10252 inst.instruction |= THUMB_OP16 (opcode);
10253 if (inst.size_req == 2)
10254 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10255 else
10256 inst.relax = opcode;
10257 return;
10258 }
c19d1205 10259 }
0110f2b8 10260 /* Definitely a 32-bit variant. */
5be8be5d
DG
10261
10262 /* Do some validations regarding addressing modes. */
10263 if (inst.operands[1].immisreg && opcode != T_MNEM_ldr
10264 && opcode != T_MNEM_str)
10265 reject_bad_reg (inst.operands[1].imm);
10266
0110f2b8 10267 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
10268 inst.instruction |= inst.operands[0].reg << 12;
10269 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
10270 return;
10271 }
10272
c19d1205
ZW
10273 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10274
10275 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 10276 {
c19d1205
ZW
10277 /* Only [Rn,Rm] is acceptable. */
10278 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10279 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10280 || inst.operands[1].postind || inst.operands[1].shifted
10281 || inst.operands[1].negative,
10282 _("Thumb does not support this addressing mode"));
10283 inst.instruction = THUMB_OP16 (inst.instruction);
10284 goto op16;
b99bd4ef 10285 }
5f4273c7 10286
c19d1205
ZW
10287 inst.instruction = THUMB_OP16 (inst.instruction);
10288 if (!inst.operands[1].isreg)
10289 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10290 return;
b99bd4ef 10291
c19d1205
ZW
10292 constraint (!inst.operands[1].preind
10293 || inst.operands[1].shifted
10294 || inst.operands[1].writeback,
10295 _("Thumb does not support this addressing mode"));
10296 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 10297 {
c19d1205
ZW
10298 constraint (inst.instruction & 0x0600,
10299 _("byte or halfword not valid for base register"));
10300 constraint (inst.operands[1].reg == REG_PC
10301 && !(inst.instruction & THUMB_LOAD_BIT),
10302 _("r15 based store not allowed"));
10303 constraint (inst.operands[1].immisreg,
10304 _("invalid base register for register offset"));
b99bd4ef 10305
c19d1205
ZW
10306 if (inst.operands[1].reg == REG_PC)
10307 inst.instruction = T_OPCODE_LDR_PC;
10308 else if (inst.instruction & THUMB_LOAD_BIT)
10309 inst.instruction = T_OPCODE_LDR_SP;
10310 else
10311 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 10312
c19d1205
ZW
10313 inst.instruction |= inst.operands[0].reg << 8;
10314 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10315 return;
10316 }
90e4755a 10317
c19d1205
ZW
10318 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10319 if (!inst.operands[1].immisreg)
10320 {
10321 /* Immediate offset. */
10322 inst.instruction |= inst.operands[0].reg;
10323 inst.instruction |= inst.operands[1].reg << 3;
10324 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10325 return;
10326 }
90e4755a 10327
c19d1205
ZW
10328 /* Register offset. */
10329 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10330 constraint (inst.operands[1].negative,
10331 _("Thumb does not support this addressing mode"));
90e4755a 10332
c19d1205
ZW
10333 op16:
10334 switch (inst.instruction)
10335 {
10336 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10337 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10338 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10339 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10340 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10341 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10342 case 0x5600 /* ldrsb */:
10343 case 0x5e00 /* ldrsh */: break;
10344 default: abort ();
10345 }
90e4755a 10346
c19d1205
ZW
10347 inst.instruction |= inst.operands[0].reg;
10348 inst.instruction |= inst.operands[1].reg << 3;
10349 inst.instruction |= inst.operands[1].imm << 6;
10350}
90e4755a 10351
c19d1205
ZW
10352static void
10353do_t_ldstd (void)
10354{
10355 if (!inst.operands[1].present)
b99bd4ef 10356 {
c19d1205
ZW
10357 inst.operands[1].reg = inst.operands[0].reg + 1;
10358 constraint (inst.operands[0].reg == REG_LR,
10359 _("r14 not allowed here"));
b99bd4ef 10360 }
c19d1205
ZW
10361 inst.instruction |= inst.operands[0].reg << 12;
10362 inst.instruction |= inst.operands[1].reg << 8;
10363 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
10364}
10365
c19d1205
ZW
10366static void
10367do_t_ldstt (void)
10368{
10369 inst.instruction |= inst.operands[0].reg << 12;
10370 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10371}
a737bd4d 10372
b99bd4ef 10373static void
c19d1205 10374do_t_mla (void)
b99bd4ef 10375{
fdfde340 10376 unsigned Rd, Rn, Rm, Ra;
c921be7d 10377
fdfde340
JM
10378 Rd = inst.operands[0].reg;
10379 Rn = inst.operands[1].reg;
10380 Rm = inst.operands[2].reg;
10381 Ra = inst.operands[3].reg;
10382
10383 reject_bad_reg (Rd);
10384 reject_bad_reg (Rn);
10385 reject_bad_reg (Rm);
10386 reject_bad_reg (Ra);
10387
10388 inst.instruction |= Rd << 8;
10389 inst.instruction |= Rn << 16;
10390 inst.instruction |= Rm;
10391 inst.instruction |= Ra << 12;
c19d1205 10392}
b99bd4ef 10393
c19d1205
ZW
10394static void
10395do_t_mlal (void)
10396{
fdfde340
JM
10397 unsigned RdLo, RdHi, Rn, Rm;
10398
10399 RdLo = inst.operands[0].reg;
10400 RdHi = inst.operands[1].reg;
10401 Rn = inst.operands[2].reg;
10402 Rm = inst.operands[3].reg;
10403
10404 reject_bad_reg (RdLo);
10405 reject_bad_reg (RdHi);
10406 reject_bad_reg (Rn);
10407 reject_bad_reg (Rm);
10408
10409 inst.instruction |= RdLo << 12;
10410 inst.instruction |= RdHi << 8;
10411 inst.instruction |= Rn << 16;
10412 inst.instruction |= Rm;
c19d1205 10413}
b99bd4ef 10414
c19d1205
ZW
10415static void
10416do_t_mov_cmp (void)
10417{
fdfde340
JM
10418 unsigned Rn, Rm;
10419
10420 Rn = inst.operands[0].reg;
10421 Rm = inst.operands[1].reg;
10422
e07e6e58
NC
10423 if (Rn == REG_PC)
10424 set_it_insn_type_last ();
10425
c19d1205 10426 if (unified_syntax)
b99bd4ef 10427 {
c19d1205
ZW
10428 int r0off = (inst.instruction == T_MNEM_mov
10429 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 10430 unsigned long opcode;
3d388997
PB
10431 bfd_boolean narrow;
10432 bfd_boolean low_regs;
10433
fdfde340 10434 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 10435 opcode = inst.instruction;
e07e6e58 10436 if (in_it_block ())
0110f2b8 10437 narrow = opcode != T_MNEM_movs;
3d388997 10438 else
0110f2b8 10439 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
10440 if (inst.size_req == 4
10441 || inst.operands[1].shifted)
10442 narrow = FALSE;
10443
efd81785
PB
10444 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10445 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10446 && !inst.operands[1].shifted
fdfde340
JM
10447 && Rn == REG_PC
10448 && Rm == REG_LR)
efd81785
PB
10449 {
10450 inst.instruction = T2_SUBS_PC_LR;
10451 return;
10452 }
10453
fdfde340
JM
10454 if (opcode == T_MNEM_cmp)
10455 {
10456 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
10457 if (narrow)
10458 {
10459 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10460 but valid. */
10461 warn_deprecated_sp (Rm);
10462 /* R15 was documented as a valid choice for Rm in ARMv6,
10463 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10464 tools reject R15, so we do too. */
10465 constraint (Rm == REG_PC, BAD_PC);
10466 }
10467 else
10468 reject_bad_reg (Rm);
fdfde340
JM
10469 }
10470 else if (opcode == T_MNEM_mov
10471 || opcode == T_MNEM_movs)
10472 {
10473 if (inst.operands[1].isreg)
10474 {
10475 if (opcode == T_MNEM_movs)
10476 {
10477 reject_bad_reg (Rn);
10478 reject_bad_reg (Rm);
10479 }
76fa04a4
MGD
10480 else if (narrow)
10481 {
10482 /* This is mov.n. */
10483 if ((Rn == REG_SP || Rn == REG_PC)
10484 && (Rm == REG_SP || Rm == REG_PC))
10485 {
10486 as_warn (_("Use of r%u as a source register is "
10487 "deprecated when r%u is the destination "
10488 "register."), Rm, Rn);
10489 }
10490 }
10491 else
10492 {
10493 /* This is mov.w. */
10494 constraint (Rn == REG_PC, BAD_PC);
10495 constraint (Rm == REG_PC, BAD_PC);
10496 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
10497 }
fdfde340
JM
10498 }
10499 else
10500 reject_bad_reg (Rn);
10501 }
10502
c19d1205
ZW
10503 if (!inst.operands[1].isreg)
10504 {
0110f2b8 10505 /* Immediate operand. */
e07e6e58 10506 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
10507 narrow = 0;
10508 if (low_regs && narrow)
10509 {
10510 inst.instruction = THUMB_OP16 (opcode);
fdfde340 10511 inst.instruction |= Rn << 8;
0110f2b8
PB
10512 if (inst.size_req == 2)
10513 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10514 else
10515 inst.relax = opcode;
10516 }
10517 else
10518 {
10519 inst.instruction = THUMB_OP32 (inst.instruction);
10520 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10521 inst.instruction |= Rn << r0off;
0110f2b8
PB
10522 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10523 }
c19d1205 10524 }
728ca7c9
PB
10525 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10526 && (inst.instruction == T_MNEM_mov
10527 || inst.instruction == T_MNEM_movs))
10528 {
10529 /* Register shifts are encoded as separate shift instructions. */
10530 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10531
e07e6e58 10532 if (in_it_block ())
728ca7c9
PB
10533 narrow = !flags;
10534 else
10535 narrow = flags;
10536
10537 if (inst.size_req == 4)
10538 narrow = FALSE;
10539
10540 if (!low_regs || inst.operands[1].imm > 7)
10541 narrow = FALSE;
10542
fdfde340 10543 if (Rn != Rm)
728ca7c9
PB
10544 narrow = FALSE;
10545
10546 switch (inst.operands[1].shift_kind)
10547 {
10548 case SHIFT_LSL:
10549 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10550 break;
10551 case SHIFT_ASR:
10552 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10553 break;
10554 case SHIFT_LSR:
10555 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10556 break;
10557 case SHIFT_ROR:
10558 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10559 break;
10560 default:
5f4273c7 10561 abort ();
728ca7c9
PB
10562 }
10563
10564 inst.instruction = opcode;
10565 if (narrow)
10566 {
fdfde340 10567 inst.instruction |= Rn;
728ca7c9
PB
10568 inst.instruction |= inst.operands[1].imm << 3;
10569 }
10570 else
10571 {
10572 if (flags)
10573 inst.instruction |= CONDS_BIT;
10574
fdfde340
JM
10575 inst.instruction |= Rn << 8;
10576 inst.instruction |= Rm << 16;
728ca7c9
PB
10577 inst.instruction |= inst.operands[1].imm;
10578 }
10579 }
3d388997 10580 else if (!narrow)
c19d1205 10581 {
728ca7c9
PB
10582 /* Some mov with immediate shift have narrow variants.
10583 Register shifts are handled above. */
10584 if (low_regs && inst.operands[1].shifted
10585 && (inst.instruction == T_MNEM_mov
10586 || inst.instruction == T_MNEM_movs))
10587 {
e07e6e58 10588 if (in_it_block ())
728ca7c9
PB
10589 narrow = (inst.instruction == T_MNEM_mov);
10590 else
10591 narrow = (inst.instruction == T_MNEM_movs);
10592 }
10593
10594 if (narrow)
10595 {
10596 switch (inst.operands[1].shift_kind)
10597 {
10598 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10599 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10600 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10601 default: narrow = FALSE; break;
10602 }
10603 }
10604
10605 if (narrow)
10606 {
fdfde340
JM
10607 inst.instruction |= Rn;
10608 inst.instruction |= Rm << 3;
728ca7c9
PB
10609 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10610 }
10611 else
10612 {
10613 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10614 inst.instruction |= Rn << r0off;
728ca7c9
PB
10615 encode_thumb32_shifted_operand (1);
10616 }
c19d1205
ZW
10617 }
10618 else
10619 switch (inst.instruction)
10620 {
10621 case T_MNEM_mov:
10622 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
10623 inst.instruction |= (Rn & 0x8) << 4;
10624 inst.instruction |= (Rn & 0x7);
10625 inst.instruction |= Rm << 3;
c19d1205 10626 break;
b99bd4ef 10627
c19d1205
ZW
10628 case T_MNEM_movs:
10629 /* We know we have low registers at this point.
941a8a52
MGD
10630 Generate LSLS Rd, Rs, #0. */
10631 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
10632 inst.instruction |= Rn;
10633 inst.instruction |= Rm << 3;
c19d1205
ZW
10634 break;
10635
10636 case T_MNEM_cmp:
3d388997 10637 if (low_regs)
c19d1205
ZW
10638 {
10639 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
10640 inst.instruction |= Rn;
10641 inst.instruction |= Rm << 3;
c19d1205
ZW
10642 }
10643 else
10644 {
10645 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
10646 inst.instruction |= (Rn & 0x8) << 4;
10647 inst.instruction |= (Rn & 0x7);
10648 inst.instruction |= Rm << 3;
c19d1205
ZW
10649 }
10650 break;
10651 }
b99bd4ef
NC
10652 return;
10653 }
10654
c19d1205 10655 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
10656
10657 /* PR 10443: Do not silently ignore shifted operands. */
10658 constraint (inst.operands[1].shifted,
10659 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10660
c19d1205 10661 if (inst.operands[1].isreg)
b99bd4ef 10662 {
fdfde340 10663 if (Rn < 8 && Rm < 8)
b99bd4ef 10664 {
c19d1205
ZW
10665 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10666 since a MOV instruction produces unpredictable results. */
10667 if (inst.instruction == T_OPCODE_MOV_I8)
10668 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 10669 else
c19d1205 10670 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 10671
fdfde340
JM
10672 inst.instruction |= Rn;
10673 inst.instruction |= Rm << 3;
b99bd4ef
NC
10674 }
10675 else
10676 {
c19d1205
ZW
10677 if (inst.instruction == T_OPCODE_MOV_I8)
10678 inst.instruction = T_OPCODE_MOV_HR;
10679 else
10680 inst.instruction = T_OPCODE_CMP_HR;
10681 do_t_cpy ();
b99bd4ef
NC
10682 }
10683 }
c19d1205 10684 else
b99bd4ef 10685 {
fdfde340 10686 constraint (Rn > 7,
c19d1205 10687 _("only lo regs allowed with immediate"));
fdfde340 10688 inst.instruction |= Rn << 8;
c19d1205
ZW
10689 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10690 }
10691}
b99bd4ef 10692
c19d1205
ZW
10693static void
10694do_t_mov16 (void)
10695{
fdfde340 10696 unsigned Rd;
b6895b4f
PB
10697 bfd_vma imm;
10698 bfd_boolean top;
10699
10700 top = (inst.instruction & 0x00800000) != 0;
10701 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10702 {
10703 constraint (top, _(":lower16: not allowed this instruction"));
10704 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10705 }
10706 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10707 {
10708 constraint (!top, _(":upper16: not allowed this instruction"));
10709 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10710 }
10711
fdfde340
JM
10712 Rd = inst.operands[0].reg;
10713 reject_bad_reg (Rd);
10714
10715 inst.instruction |= Rd << 8;
b6895b4f
PB
10716 if (inst.reloc.type == BFD_RELOC_UNUSED)
10717 {
10718 imm = inst.reloc.exp.X_add_number;
10719 inst.instruction |= (imm & 0xf000) << 4;
10720 inst.instruction |= (imm & 0x0800) << 15;
10721 inst.instruction |= (imm & 0x0700) << 4;
10722 inst.instruction |= (imm & 0x00ff);
10723 }
c19d1205 10724}
b99bd4ef 10725
c19d1205
ZW
10726static void
10727do_t_mvn_tst (void)
10728{
fdfde340 10729 unsigned Rn, Rm;
c921be7d 10730
fdfde340
JM
10731 Rn = inst.operands[0].reg;
10732 Rm = inst.operands[1].reg;
10733
10734 if (inst.instruction == T_MNEM_cmp
10735 || inst.instruction == T_MNEM_cmn)
10736 constraint (Rn == REG_PC, BAD_PC);
10737 else
10738 reject_bad_reg (Rn);
10739 reject_bad_reg (Rm);
10740
c19d1205
ZW
10741 if (unified_syntax)
10742 {
10743 int r0off = (inst.instruction == T_MNEM_mvn
10744 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
10745 bfd_boolean narrow;
10746
10747 if (inst.size_req == 4
10748 || inst.instruction > 0xffff
10749 || inst.operands[1].shifted
fdfde340 10750 || Rn > 7 || Rm > 7)
3d388997
PB
10751 narrow = FALSE;
10752 else if (inst.instruction == T_MNEM_cmn)
10753 narrow = TRUE;
10754 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10755 narrow = !in_it_block ();
3d388997 10756 else
e07e6e58 10757 narrow = in_it_block ();
3d388997 10758
c19d1205 10759 if (!inst.operands[1].isreg)
b99bd4ef 10760 {
c19d1205
ZW
10761 /* For an immediate, we always generate a 32-bit opcode;
10762 section relaxation will shrink it later if possible. */
10763 if (inst.instruction < 0xffff)
10764 inst.instruction = THUMB_OP32 (inst.instruction);
10765 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10766 inst.instruction |= Rn << r0off;
c19d1205 10767 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10768 }
c19d1205 10769 else
b99bd4ef 10770 {
c19d1205 10771 /* See if we can do this with a 16-bit instruction. */
3d388997 10772 if (narrow)
b99bd4ef 10773 {
c19d1205 10774 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10775 inst.instruction |= Rn;
10776 inst.instruction |= Rm << 3;
b99bd4ef 10777 }
c19d1205 10778 else
b99bd4ef 10779 {
c19d1205
ZW
10780 constraint (inst.operands[1].shifted
10781 && inst.operands[1].immisreg,
10782 _("shift must be constant"));
10783 if (inst.instruction < 0xffff)
10784 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10785 inst.instruction |= Rn << r0off;
c19d1205 10786 encode_thumb32_shifted_operand (1);
b99bd4ef 10787 }
b99bd4ef
NC
10788 }
10789 }
10790 else
10791 {
c19d1205
ZW
10792 constraint (inst.instruction > 0xffff
10793 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10794 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10795 _("unshifted register required"));
fdfde340 10796 constraint (Rn > 7 || Rm > 7,
c19d1205 10797 BAD_HIREG);
b99bd4ef 10798
c19d1205 10799 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10800 inst.instruction |= Rn;
10801 inst.instruction |= Rm << 3;
b99bd4ef 10802 }
b99bd4ef
NC
10803}
10804
b05fe5cf 10805static void
c19d1205 10806do_t_mrs (void)
b05fe5cf 10807{
fdfde340 10808 unsigned Rd;
037e8744
JB
10809
10810 if (do_vfp_nsyn_mrs () == SUCCESS)
10811 return;
10812
90ec0d68
MGD
10813 Rd = inst.operands[0].reg;
10814 reject_bad_reg (Rd);
10815 inst.instruction |= Rd << 8;
10816
10817 if (inst.operands[1].isreg)
62b3e311 10818 {
90ec0d68
MGD
10819 unsigned br = inst.operands[1].reg;
10820 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
10821 as_bad (_("bad register for mrs"));
10822
10823 inst.instruction |= br & (0xf << 16);
10824 inst.instruction |= (br & 0x300) >> 4;
10825 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
10826 }
10827 else
10828 {
90ec0d68 10829 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 10830
90ec0d68
MGD
10831 if (flags == 0)
10832 {
10833 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10834 _("selected processor does not support "
10835 "requested special purpose register"));
10836 }
10837 else
10838 {
10839 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10840 _("selected processor does not support "
10841 "requested special purpose register"));
10842 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10843 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10844 _("'CPSR' or 'SPSR' expected"));
10845 }
fdfde340 10846
90ec0d68
MGD
10847 inst.instruction |= (flags & SPSR_BIT) >> 2;
10848 inst.instruction |= inst.operands[1].imm & 0xff;
10849 inst.instruction |= 0xf0000;
10850 }
c19d1205 10851}
b05fe5cf 10852
c19d1205
ZW
10853static void
10854do_t_msr (void)
10855{
62b3e311 10856 int flags;
fdfde340 10857 unsigned Rn;
62b3e311 10858
037e8744
JB
10859 if (do_vfp_nsyn_msr () == SUCCESS)
10860 return;
10861
c19d1205
ZW
10862 constraint (!inst.operands[1].isreg,
10863 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
10864
10865 if (inst.operands[0].isreg)
10866 flags = (int)(inst.operands[0].reg);
10867 else
10868 flags = inst.operands[0].imm;
10869
62b3e311
PB
10870 if (flags & ~0xff)
10871 {
10872 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10873 _("selected processor does not support "
10874 "requested special purpose register"));
10875 }
10876 else
10877 {
7e806470 10878 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10879 _("selected processor does not support "
10880 "requested special purpose register"));
10881 flags |= PSR_f;
10882 }
c921be7d 10883
fdfde340
JM
10884 Rn = inst.operands[1].reg;
10885 reject_bad_reg (Rn);
10886
62b3e311 10887 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
10888 inst.instruction |= (flags & 0xf0000) >> 8;
10889 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 10890 inst.instruction |= (flags & 0xff);
fdfde340 10891 inst.instruction |= Rn << 16;
c19d1205 10892}
b05fe5cf 10893
c19d1205
ZW
10894static void
10895do_t_mul (void)
10896{
17828f45 10897 bfd_boolean narrow;
fdfde340 10898 unsigned Rd, Rn, Rm;
17828f45 10899
c19d1205
ZW
10900 if (!inst.operands[2].present)
10901 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 10902
fdfde340
JM
10903 Rd = inst.operands[0].reg;
10904 Rn = inst.operands[1].reg;
10905 Rm = inst.operands[2].reg;
10906
17828f45 10907 if (unified_syntax)
b05fe5cf 10908 {
17828f45 10909 if (inst.size_req == 4
fdfde340
JM
10910 || (Rd != Rn
10911 && Rd != Rm)
10912 || Rn > 7
10913 || Rm > 7)
17828f45
JM
10914 narrow = FALSE;
10915 else if (inst.instruction == T_MNEM_muls)
e07e6e58 10916 narrow = !in_it_block ();
17828f45 10917 else
e07e6e58 10918 narrow = in_it_block ();
b05fe5cf 10919 }
c19d1205 10920 else
b05fe5cf 10921 {
17828f45 10922 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 10923 constraint (Rn > 7 || Rm > 7,
c19d1205 10924 BAD_HIREG);
17828f45
JM
10925 narrow = TRUE;
10926 }
b05fe5cf 10927
17828f45
JM
10928 if (narrow)
10929 {
10930 /* 16-bit MULS/Conditional MUL. */
c19d1205 10931 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10932 inst.instruction |= Rd;
b05fe5cf 10933
fdfde340
JM
10934 if (Rd == Rn)
10935 inst.instruction |= Rm << 3;
10936 else if (Rd == Rm)
10937 inst.instruction |= Rn << 3;
c19d1205
ZW
10938 else
10939 constraint (1, _("dest must overlap one source register"));
10940 }
17828f45
JM
10941 else
10942 {
e07e6e58
NC
10943 constraint (inst.instruction != T_MNEM_mul,
10944 _("Thumb-2 MUL must not set flags"));
17828f45
JM
10945 /* 32-bit MUL. */
10946 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10947 inst.instruction |= Rd << 8;
10948 inst.instruction |= Rn << 16;
10949 inst.instruction |= Rm << 0;
10950
10951 reject_bad_reg (Rd);
10952 reject_bad_reg (Rn);
10953 reject_bad_reg (Rm);
17828f45 10954 }
c19d1205 10955}
b05fe5cf 10956
c19d1205
ZW
10957static void
10958do_t_mull (void)
10959{
fdfde340 10960 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 10961
fdfde340
JM
10962 RdLo = inst.operands[0].reg;
10963 RdHi = inst.operands[1].reg;
10964 Rn = inst.operands[2].reg;
10965 Rm = inst.operands[3].reg;
10966
10967 reject_bad_reg (RdLo);
10968 reject_bad_reg (RdHi);
10969 reject_bad_reg (Rn);
10970 reject_bad_reg (Rm);
10971
10972 inst.instruction |= RdLo << 12;
10973 inst.instruction |= RdHi << 8;
10974 inst.instruction |= Rn << 16;
10975 inst.instruction |= Rm;
10976
10977 if (RdLo == RdHi)
c19d1205
ZW
10978 as_tsktsk (_("rdhi and rdlo must be different"));
10979}
b05fe5cf 10980
c19d1205
ZW
10981static void
10982do_t_nop (void)
10983{
e07e6e58
NC
10984 set_it_insn_type (NEUTRAL_IT_INSN);
10985
c19d1205
ZW
10986 if (unified_syntax)
10987 {
10988 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 10989 {
c19d1205
ZW
10990 inst.instruction = THUMB_OP32 (inst.instruction);
10991 inst.instruction |= inst.operands[0].imm;
10992 }
10993 else
10994 {
bc2d1808
NC
10995 /* PR9722: Check for Thumb2 availability before
10996 generating a thumb2 nop instruction. */
afa62d5e 10997 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
10998 {
10999 inst.instruction = THUMB_OP16 (inst.instruction);
11000 inst.instruction |= inst.operands[0].imm << 4;
11001 }
11002 else
11003 inst.instruction = 0x46c0;
c19d1205
ZW
11004 }
11005 }
11006 else
11007 {
11008 constraint (inst.operands[0].present,
11009 _("Thumb does not support NOP with hints"));
11010 inst.instruction = 0x46c0;
11011 }
11012}
b05fe5cf 11013
c19d1205
ZW
11014static void
11015do_t_neg (void)
11016{
11017 if (unified_syntax)
11018 {
3d388997
PB
11019 bfd_boolean narrow;
11020
11021 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11022 narrow = !in_it_block ();
3d388997 11023 else
e07e6e58 11024 narrow = in_it_block ();
3d388997
PB
11025 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11026 narrow = FALSE;
11027 if (inst.size_req == 4)
11028 narrow = FALSE;
11029
11030 if (!narrow)
c19d1205
ZW
11031 {
11032 inst.instruction = THUMB_OP32 (inst.instruction);
11033 inst.instruction |= inst.operands[0].reg << 8;
11034 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
11035 }
11036 else
11037 {
c19d1205
ZW
11038 inst.instruction = THUMB_OP16 (inst.instruction);
11039 inst.instruction |= inst.operands[0].reg;
11040 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
11041 }
11042 }
11043 else
11044 {
c19d1205
ZW
11045 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
11046 BAD_HIREG);
11047 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11048
11049 inst.instruction = THUMB_OP16 (inst.instruction);
11050 inst.instruction |= inst.operands[0].reg;
11051 inst.instruction |= inst.operands[1].reg << 3;
11052 }
11053}
11054
1c444d06
JM
11055static void
11056do_t_orn (void)
11057{
11058 unsigned Rd, Rn;
11059
11060 Rd = inst.operands[0].reg;
11061 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
11062
fdfde340
JM
11063 reject_bad_reg (Rd);
11064 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
11065 reject_bad_reg (Rn);
11066
1c444d06
JM
11067 inst.instruction |= Rd << 8;
11068 inst.instruction |= Rn << 16;
11069
11070 if (!inst.operands[2].isreg)
11071 {
11072 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11073 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11074 }
11075 else
11076 {
11077 unsigned Rm;
11078
11079 Rm = inst.operands[2].reg;
fdfde340 11080 reject_bad_reg (Rm);
1c444d06
JM
11081
11082 constraint (inst.operands[2].shifted
11083 && inst.operands[2].immisreg,
11084 _("shift must be constant"));
11085 encode_thumb32_shifted_operand (2);
11086 }
11087}
11088
c19d1205
ZW
11089static void
11090do_t_pkhbt (void)
11091{
fdfde340
JM
11092 unsigned Rd, Rn, Rm;
11093
11094 Rd = inst.operands[0].reg;
11095 Rn = inst.operands[1].reg;
11096 Rm = inst.operands[2].reg;
11097
11098 reject_bad_reg (Rd);
11099 reject_bad_reg (Rn);
11100 reject_bad_reg (Rm);
11101
11102 inst.instruction |= Rd << 8;
11103 inst.instruction |= Rn << 16;
11104 inst.instruction |= Rm;
c19d1205
ZW
11105 if (inst.operands[3].present)
11106 {
11107 unsigned int val = inst.reloc.exp.X_add_number;
11108 constraint (inst.reloc.exp.X_op != O_constant,
11109 _("expression too complex"));
11110 inst.instruction |= (val & 0x1c) << 10;
11111 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 11112 }
c19d1205 11113}
b05fe5cf 11114
c19d1205
ZW
11115static void
11116do_t_pkhtb (void)
11117{
11118 if (!inst.operands[3].present)
1ef52f49
NC
11119 {
11120 unsigned Rtmp;
11121
11122 inst.instruction &= ~0x00000020;
11123
11124 /* PR 10168. Swap the Rm and Rn registers. */
11125 Rtmp = inst.operands[1].reg;
11126 inst.operands[1].reg = inst.operands[2].reg;
11127 inst.operands[2].reg = Rtmp;
11128 }
c19d1205 11129 do_t_pkhbt ();
b05fe5cf
ZW
11130}
11131
c19d1205
ZW
11132static void
11133do_t_pld (void)
11134{
fdfde340
JM
11135 if (inst.operands[0].immisreg)
11136 reject_bad_reg (inst.operands[0].imm);
11137
c19d1205
ZW
11138 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11139}
b05fe5cf 11140
c19d1205
ZW
11141static void
11142do_t_push_pop (void)
b99bd4ef 11143{
e9f89963 11144 unsigned mask;
5f4273c7 11145
c19d1205
ZW
11146 constraint (inst.operands[0].writeback,
11147 _("push/pop do not support {reglist}^"));
11148 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11149 _("expression too complex"));
b99bd4ef 11150
e9f89963
PB
11151 mask = inst.operands[0].imm;
11152 if ((mask & ~0xff) == 0)
3c707909 11153 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 11154 else if ((inst.instruction == T_MNEM_push
e9f89963 11155 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 11156 || (inst.instruction == T_MNEM_pop
e9f89963 11157 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 11158 {
c19d1205
ZW
11159 inst.instruction = THUMB_OP16 (inst.instruction);
11160 inst.instruction |= THUMB_PP_PC_LR;
3c707909 11161 inst.instruction |= mask & 0xff;
c19d1205
ZW
11162 }
11163 else if (unified_syntax)
11164 {
3c707909 11165 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 11166 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
11167 }
11168 else
11169 {
11170 inst.error = _("invalid register list to push/pop instruction");
11171 return;
11172 }
c19d1205 11173}
b99bd4ef 11174
c19d1205
ZW
11175static void
11176do_t_rbit (void)
11177{
fdfde340
JM
11178 unsigned Rd, Rm;
11179
11180 Rd = inst.operands[0].reg;
11181 Rm = inst.operands[1].reg;
11182
11183 reject_bad_reg (Rd);
11184 reject_bad_reg (Rm);
11185
11186 inst.instruction |= Rd << 8;
11187 inst.instruction |= Rm << 16;
11188 inst.instruction |= Rm;
c19d1205 11189}
b99bd4ef 11190
c19d1205
ZW
11191static void
11192do_t_rev (void)
11193{
fdfde340
JM
11194 unsigned Rd, Rm;
11195
11196 Rd = inst.operands[0].reg;
11197 Rm = inst.operands[1].reg;
11198
11199 reject_bad_reg (Rd);
11200 reject_bad_reg (Rm);
11201
11202 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
11203 && inst.size_req != 4)
11204 {
11205 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11206 inst.instruction |= Rd;
11207 inst.instruction |= Rm << 3;
c19d1205
ZW
11208 }
11209 else if (unified_syntax)
11210 {
11211 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11212 inst.instruction |= Rd << 8;
11213 inst.instruction |= Rm << 16;
11214 inst.instruction |= Rm;
c19d1205
ZW
11215 }
11216 else
11217 inst.error = BAD_HIREG;
11218}
b99bd4ef 11219
1c444d06
JM
11220static void
11221do_t_rrx (void)
11222{
11223 unsigned Rd, Rm;
11224
11225 Rd = inst.operands[0].reg;
11226 Rm = inst.operands[1].reg;
11227
fdfde340
JM
11228 reject_bad_reg (Rd);
11229 reject_bad_reg (Rm);
c921be7d 11230
1c444d06
JM
11231 inst.instruction |= Rd << 8;
11232 inst.instruction |= Rm;
11233}
11234
c19d1205
ZW
11235static void
11236do_t_rsb (void)
11237{
fdfde340 11238 unsigned Rd, Rs;
b99bd4ef 11239
c19d1205
ZW
11240 Rd = inst.operands[0].reg;
11241 Rs = (inst.operands[1].present
11242 ? inst.operands[1].reg /* Rd, Rs, foo */
11243 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 11244
fdfde340
JM
11245 reject_bad_reg (Rd);
11246 reject_bad_reg (Rs);
11247 if (inst.operands[2].isreg)
11248 reject_bad_reg (inst.operands[2].reg);
11249
c19d1205
ZW
11250 inst.instruction |= Rd << 8;
11251 inst.instruction |= Rs << 16;
11252 if (!inst.operands[2].isreg)
11253 {
026d3abb
PB
11254 bfd_boolean narrow;
11255
11256 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 11257 narrow = !in_it_block ();
026d3abb 11258 else
e07e6e58 11259 narrow = in_it_block ();
026d3abb
PB
11260
11261 if (Rd > 7 || Rs > 7)
11262 narrow = FALSE;
11263
11264 if (inst.size_req == 4 || !unified_syntax)
11265 narrow = FALSE;
11266
11267 if (inst.reloc.exp.X_op != O_constant
11268 || inst.reloc.exp.X_add_number != 0)
11269 narrow = FALSE;
11270
11271 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11272 relaxation, but it doesn't seem worth the hassle. */
11273 if (narrow)
11274 {
11275 inst.reloc.type = BFD_RELOC_UNUSED;
11276 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11277 inst.instruction |= Rs << 3;
11278 inst.instruction |= Rd;
11279 }
11280 else
11281 {
11282 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11283 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11284 }
c19d1205
ZW
11285 }
11286 else
11287 encode_thumb32_shifted_operand (2);
11288}
b99bd4ef 11289
c19d1205
ZW
11290static void
11291do_t_setend (void)
11292{
e07e6e58 11293 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11294 if (inst.operands[0].imm)
11295 inst.instruction |= 0x8;
11296}
b99bd4ef 11297
c19d1205
ZW
11298static void
11299do_t_shift (void)
11300{
11301 if (!inst.operands[1].present)
11302 inst.operands[1].reg = inst.operands[0].reg;
11303
11304 if (unified_syntax)
11305 {
3d388997
PB
11306 bfd_boolean narrow;
11307 int shift_kind;
11308
11309 switch (inst.instruction)
11310 {
11311 case T_MNEM_asr:
11312 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11313 case T_MNEM_lsl:
11314 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11315 case T_MNEM_lsr:
11316 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11317 case T_MNEM_ror:
11318 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11319 default: abort ();
11320 }
11321
11322 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11323 narrow = !in_it_block ();
3d388997 11324 else
e07e6e58 11325 narrow = in_it_block ();
3d388997
PB
11326 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11327 narrow = FALSE;
11328 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11329 narrow = FALSE;
11330 if (inst.operands[2].isreg
11331 && (inst.operands[1].reg != inst.operands[0].reg
11332 || inst.operands[2].reg > 7))
11333 narrow = FALSE;
11334 if (inst.size_req == 4)
11335 narrow = FALSE;
11336
fdfde340
JM
11337 reject_bad_reg (inst.operands[0].reg);
11338 reject_bad_reg (inst.operands[1].reg);
c921be7d 11339
3d388997 11340 if (!narrow)
c19d1205
ZW
11341 {
11342 if (inst.operands[2].isreg)
b99bd4ef 11343 {
fdfde340 11344 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
11345 inst.instruction = THUMB_OP32 (inst.instruction);
11346 inst.instruction |= inst.operands[0].reg << 8;
11347 inst.instruction |= inst.operands[1].reg << 16;
11348 inst.instruction |= inst.operands[2].reg;
11349 }
11350 else
11351 {
11352 inst.operands[1].shifted = 1;
3d388997 11353 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
11354 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11355 ? T_MNEM_movs : T_MNEM_mov);
11356 inst.instruction |= inst.operands[0].reg << 8;
11357 encode_thumb32_shifted_operand (1);
11358 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11359 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
11360 }
11361 }
11362 else
11363 {
c19d1205 11364 if (inst.operands[2].isreg)
b99bd4ef 11365 {
3d388997 11366 switch (shift_kind)
b99bd4ef 11367 {
3d388997
PB
11368 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11369 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11370 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11371 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 11372 default: abort ();
b99bd4ef 11373 }
5f4273c7 11374
c19d1205
ZW
11375 inst.instruction |= inst.operands[0].reg;
11376 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
11377 }
11378 else
11379 {
3d388997 11380 switch (shift_kind)
b99bd4ef 11381 {
3d388997
PB
11382 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11383 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11384 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 11385 default: abort ();
b99bd4ef 11386 }
c19d1205
ZW
11387 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11388 inst.instruction |= inst.operands[0].reg;
11389 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11390 }
11391 }
c19d1205
ZW
11392 }
11393 else
11394 {
11395 constraint (inst.operands[0].reg > 7
11396 || inst.operands[1].reg > 7, BAD_HIREG);
11397 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 11398
c19d1205
ZW
11399 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11400 {
11401 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11402 constraint (inst.operands[0].reg != inst.operands[1].reg,
11403 _("source1 and dest must be same register"));
b99bd4ef 11404
c19d1205
ZW
11405 switch (inst.instruction)
11406 {
11407 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11408 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11409 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11410 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11411 default: abort ();
11412 }
5f4273c7 11413
c19d1205
ZW
11414 inst.instruction |= inst.operands[0].reg;
11415 inst.instruction |= inst.operands[2].reg << 3;
11416 }
11417 else
b99bd4ef 11418 {
c19d1205
ZW
11419 switch (inst.instruction)
11420 {
11421 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11422 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11423 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11424 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11425 default: abort ();
11426 }
11427 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11428 inst.instruction |= inst.operands[0].reg;
11429 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11430 }
11431 }
b99bd4ef
NC
11432}
11433
11434static void
c19d1205 11435do_t_simd (void)
b99bd4ef 11436{
fdfde340
JM
11437 unsigned Rd, Rn, Rm;
11438
11439 Rd = inst.operands[0].reg;
11440 Rn = inst.operands[1].reg;
11441 Rm = inst.operands[2].reg;
11442
11443 reject_bad_reg (Rd);
11444 reject_bad_reg (Rn);
11445 reject_bad_reg (Rm);
11446
11447 inst.instruction |= Rd << 8;
11448 inst.instruction |= Rn << 16;
11449 inst.instruction |= Rm;
c19d1205 11450}
b99bd4ef 11451
03ee1b7f
NC
11452static void
11453do_t_simd2 (void)
11454{
11455 unsigned Rd, Rn, Rm;
11456
11457 Rd = inst.operands[0].reg;
11458 Rm = inst.operands[1].reg;
11459 Rn = inst.operands[2].reg;
11460
11461 reject_bad_reg (Rd);
11462 reject_bad_reg (Rn);
11463 reject_bad_reg (Rm);
11464
11465 inst.instruction |= Rd << 8;
11466 inst.instruction |= Rn << 16;
11467 inst.instruction |= Rm;
11468}
11469
c19d1205 11470static void
3eb17e6b 11471do_t_smc (void)
c19d1205
ZW
11472{
11473 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
11474 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
11475 _("SMC is not permitted on this architecture"));
c19d1205
ZW
11476 constraint (inst.reloc.exp.X_op != O_constant,
11477 _("expression too complex"));
11478 inst.reloc.type = BFD_RELOC_UNUSED;
11479 inst.instruction |= (value & 0xf000) >> 12;
11480 inst.instruction |= (value & 0x0ff0);
11481 inst.instruction |= (value & 0x000f) << 16;
11482}
b99bd4ef 11483
90ec0d68
MGD
11484static void
11485do_t_hvc (void)
11486{
11487 unsigned int value = inst.reloc.exp.X_add_number;
11488
11489 inst.reloc.type = BFD_RELOC_UNUSED;
11490 inst.instruction |= (value & 0x0fff);
11491 inst.instruction |= (value & 0xf000) << 4;
11492}
11493
c19d1205 11494static void
3a21c15a 11495do_t_ssat_usat (int bias)
c19d1205 11496{
fdfde340
JM
11497 unsigned Rd, Rn;
11498
11499 Rd = inst.operands[0].reg;
11500 Rn = inst.operands[2].reg;
11501
11502 reject_bad_reg (Rd);
11503 reject_bad_reg (Rn);
11504
11505 inst.instruction |= Rd << 8;
3a21c15a 11506 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 11507 inst.instruction |= Rn << 16;
b99bd4ef 11508
c19d1205 11509 if (inst.operands[3].present)
b99bd4ef 11510 {
3a21c15a
NC
11511 offsetT shift_amount = inst.reloc.exp.X_add_number;
11512
11513 inst.reloc.type = BFD_RELOC_UNUSED;
11514
c19d1205
ZW
11515 constraint (inst.reloc.exp.X_op != O_constant,
11516 _("expression too complex"));
b99bd4ef 11517
3a21c15a 11518 if (shift_amount != 0)
6189168b 11519 {
3a21c15a
NC
11520 constraint (shift_amount > 31,
11521 _("shift expression is too large"));
11522
c19d1205 11523 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
11524 inst.instruction |= 0x00200000; /* sh bit. */
11525
11526 inst.instruction |= (shift_amount & 0x1c) << 10;
11527 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
11528 }
11529 }
b99bd4ef 11530}
c921be7d 11531
3a21c15a
NC
11532static void
11533do_t_ssat (void)
11534{
11535 do_t_ssat_usat (1);
11536}
b99bd4ef 11537
0dd132b6 11538static void
c19d1205 11539do_t_ssat16 (void)
0dd132b6 11540{
fdfde340
JM
11541 unsigned Rd, Rn;
11542
11543 Rd = inst.operands[0].reg;
11544 Rn = inst.operands[2].reg;
11545
11546 reject_bad_reg (Rd);
11547 reject_bad_reg (Rn);
11548
11549 inst.instruction |= Rd << 8;
c19d1205 11550 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 11551 inst.instruction |= Rn << 16;
c19d1205 11552}
0dd132b6 11553
c19d1205
ZW
11554static void
11555do_t_strex (void)
11556{
11557 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11558 || inst.operands[2].postind || inst.operands[2].writeback
11559 || inst.operands[2].immisreg || inst.operands[2].shifted
11560 || inst.operands[2].negative,
01cfc07f 11561 BAD_ADDR_MODE);
0dd132b6 11562
5be8be5d
DG
11563 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11564
c19d1205
ZW
11565 inst.instruction |= inst.operands[0].reg << 8;
11566 inst.instruction |= inst.operands[1].reg << 12;
11567 inst.instruction |= inst.operands[2].reg << 16;
11568 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
11569}
11570
b99bd4ef 11571static void
c19d1205 11572do_t_strexd (void)
b99bd4ef 11573{
c19d1205
ZW
11574 if (!inst.operands[2].present)
11575 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 11576
c19d1205
ZW
11577 constraint (inst.operands[0].reg == inst.operands[1].reg
11578 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 11579 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 11580 BAD_OVERLAP);
b99bd4ef 11581
c19d1205
ZW
11582 inst.instruction |= inst.operands[0].reg;
11583 inst.instruction |= inst.operands[1].reg << 12;
11584 inst.instruction |= inst.operands[2].reg << 8;
11585 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
11586}
11587
11588static void
c19d1205 11589do_t_sxtah (void)
b99bd4ef 11590{
fdfde340
JM
11591 unsigned Rd, Rn, Rm;
11592
11593 Rd = inst.operands[0].reg;
11594 Rn = inst.operands[1].reg;
11595 Rm = inst.operands[2].reg;
11596
11597 reject_bad_reg (Rd);
11598 reject_bad_reg (Rn);
11599 reject_bad_reg (Rm);
11600
11601 inst.instruction |= Rd << 8;
11602 inst.instruction |= Rn << 16;
11603 inst.instruction |= Rm;
c19d1205
ZW
11604 inst.instruction |= inst.operands[3].imm << 4;
11605}
b99bd4ef 11606
c19d1205
ZW
11607static void
11608do_t_sxth (void)
11609{
fdfde340
JM
11610 unsigned Rd, Rm;
11611
11612 Rd = inst.operands[0].reg;
11613 Rm = inst.operands[1].reg;
11614
11615 reject_bad_reg (Rd);
11616 reject_bad_reg (Rm);
c921be7d
NC
11617
11618 if (inst.instruction <= 0xffff
11619 && inst.size_req != 4
fdfde340 11620 && Rd <= 7 && Rm <= 7
c19d1205 11621 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 11622 {
c19d1205 11623 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11624 inst.instruction |= Rd;
11625 inst.instruction |= Rm << 3;
b99bd4ef 11626 }
c19d1205 11627 else if (unified_syntax)
b99bd4ef 11628 {
c19d1205
ZW
11629 if (inst.instruction <= 0xffff)
11630 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11631 inst.instruction |= Rd << 8;
11632 inst.instruction |= Rm;
c19d1205 11633 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 11634 }
c19d1205 11635 else
b99bd4ef 11636 {
c19d1205
ZW
11637 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11638 _("Thumb encoding does not support rotation"));
11639 constraint (1, BAD_HIREG);
b99bd4ef 11640 }
c19d1205 11641}
b99bd4ef 11642
c19d1205
ZW
11643static void
11644do_t_swi (void)
11645{
b2a5fbdc
MGD
11646 /* We have to do the following check manually as ARM_EXT_OS only applies
11647 to ARM_EXT_V6M. */
11648 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
11649 {
11650 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os))
11651 as_bad (_("SVC is not permitted on this architecture"));
11652 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
11653 }
11654
c19d1205
ZW
11655 inst.reloc.type = BFD_RELOC_ARM_SWI;
11656}
b99bd4ef 11657
92e90b6e
PB
11658static void
11659do_t_tb (void)
11660{
fdfde340 11661 unsigned Rn, Rm;
92e90b6e
PB
11662 int half;
11663
11664 half = (inst.instruction & 0x10) != 0;
e07e6e58 11665 set_it_insn_type_last ();
dfa9f0d5
PB
11666 constraint (inst.operands[0].immisreg,
11667 _("instruction requires register index"));
fdfde340
JM
11668
11669 Rn = inst.operands[0].reg;
11670 Rm = inst.operands[0].imm;
c921be7d 11671
fdfde340
JM
11672 constraint (Rn == REG_SP, BAD_SP);
11673 reject_bad_reg (Rm);
11674
92e90b6e
PB
11675 constraint (!half && inst.operands[0].shifted,
11676 _("instruction does not allow shifted index"));
fdfde340 11677 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
11678}
11679
c19d1205
ZW
11680static void
11681do_t_usat (void)
11682{
3a21c15a 11683 do_t_ssat_usat (0);
b99bd4ef
NC
11684}
11685
11686static void
c19d1205 11687do_t_usat16 (void)
b99bd4ef 11688{
fdfde340
JM
11689 unsigned Rd, Rn;
11690
11691 Rd = inst.operands[0].reg;
11692 Rn = inst.operands[2].reg;
11693
11694 reject_bad_reg (Rd);
11695 reject_bad_reg (Rn);
11696
11697 inst.instruction |= Rd << 8;
c19d1205 11698 inst.instruction |= inst.operands[1].imm;
fdfde340 11699 inst.instruction |= Rn << 16;
b99bd4ef 11700}
c19d1205 11701
5287ad62 11702/* Neon instruction encoder helpers. */
5f4273c7 11703
5287ad62 11704/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 11705
5287ad62
JB
11706/* An "invalid" code for the following tables. */
11707#define N_INV -1u
11708
11709struct neon_tab_entry
b99bd4ef 11710{
5287ad62
JB
11711 unsigned integer;
11712 unsigned float_or_poly;
11713 unsigned scalar_or_imm;
11714};
5f4273c7 11715
5287ad62
JB
11716/* Map overloaded Neon opcodes to their respective encodings. */
11717#define NEON_ENC_TAB \
11718 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11719 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11720 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11721 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11722 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11723 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11724 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11725 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11726 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11727 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11728 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11729 /* Register variants of the following two instructions are encoded as
e07e6e58 11730 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
11731 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11732 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
11733 X(vfma, N_INV, 0x0000c10, N_INV), \
11734 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
11735 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11736 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11737 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11738 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11739 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11740 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11741 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11742 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11743 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11744 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11745 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11746 X(vshl, 0x0000400, N_INV, 0x0800510), \
11747 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11748 X(vand, 0x0000110, N_INV, 0x0800030), \
11749 X(vbic, 0x0100110, N_INV, 0x0800030), \
11750 X(veor, 0x1000110, N_INV, N_INV), \
11751 X(vorn, 0x0300110, N_INV, 0x0800010), \
11752 X(vorr, 0x0200110, N_INV, 0x0800010), \
11753 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11754 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11755 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11756 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11757 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11758 X(vst1, 0x0000000, 0x0800000, N_INV), \
11759 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11760 X(vst2, 0x0000100, 0x0800100, N_INV), \
11761 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11762 X(vst3, 0x0000200, 0x0800200, N_INV), \
11763 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11764 X(vst4, 0x0000300, 0x0800300, N_INV), \
11765 X(vmovn, 0x1b20200, N_INV, N_INV), \
11766 X(vtrn, 0x1b20080, N_INV, N_INV), \
11767 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
11768 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11769 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
11770 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11771 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
11772 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11773 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
11774 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11775 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11776 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11777 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
11778
11779enum neon_opc
11780{
11781#define X(OPC,I,F,S) N_MNEM_##OPC
11782NEON_ENC_TAB
11783#undef X
11784};
b99bd4ef 11785
5287ad62
JB
11786static const struct neon_tab_entry neon_enc_tab[] =
11787{
11788#define X(OPC,I,F,S) { (I), (F), (S) }
11789NEON_ENC_TAB
11790#undef X
11791};
b99bd4ef 11792
88714cb8
DG
11793/* Do not use these macros; instead, use NEON_ENCODE defined below. */
11794#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11795#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11796#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11797#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11798#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11799#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11800#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11801#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11802#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11803#define NEON_ENC_SINGLE_(X) \
037e8744 11804 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 11805#define NEON_ENC_DOUBLE_(X) \
037e8744 11806 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 11807
88714cb8
DG
11808#define NEON_ENCODE(type, inst) \
11809 do \
11810 { \
11811 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
11812 inst.is_neon = 1; \
11813 } \
11814 while (0)
11815
11816#define check_neon_suffixes \
11817 do \
11818 { \
11819 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
11820 { \
11821 as_bad (_("invalid neon suffix for non neon instruction")); \
11822 return; \
11823 } \
11824 } \
11825 while (0)
11826
037e8744
JB
11827/* Define shapes for instruction operands. The following mnemonic characters
11828 are used in this table:
5287ad62 11829
037e8744 11830 F - VFP S<n> register
5287ad62
JB
11831 D - Neon D<n> register
11832 Q - Neon Q<n> register
11833 I - Immediate
11834 S - Scalar
11835 R - ARM register
11836 L - D<n> register list
5f4273c7 11837
037e8744
JB
11838 This table is used to generate various data:
11839 - enumerations of the form NS_DDR to be used as arguments to
11840 neon_select_shape.
11841 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 11842 - a table used to drive neon_select_shape. */
b99bd4ef 11843
037e8744
JB
11844#define NEON_SHAPE_DEF \
11845 X(3, (D, D, D), DOUBLE), \
11846 X(3, (Q, Q, Q), QUAD), \
11847 X(3, (D, D, I), DOUBLE), \
11848 X(3, (Q, Q, I), QUAD), \
11849 X(3, (D, D, S), DOUBLE), \
11850 X(3, (Q, Q, S), QUAD), \
11851 X(2, (D, D), DOUBLE), \
11852 X(2, (Q, Q), QUAD), \
11853 X(2, (D, S), DOUBLE), \
11854 X(2, (Q, S), QUAD), \
11855 X(2, (D, R), DOUBLE), \
11856 X(2, (Q, R), QUAD), \
11857 X(2, (D, I), DOUBLE), \
11858 X(2, (Q, I), QUAD), \
11859 X(3, (D, L, D), DOUBLE), \
11860 X(2, (D, Q), MIXED), \
11861 X(2, (Q, D), MIXED), \
11862 X(3, (D, Q, I), MIXED), \
11863 X(3, (Q, D, I), MIXED), \
11864 X(3, (Q, D, D), MIXED), \
11865 X(3, (D, Q, Q), MIXED), \
11866 X(3, (Q, Q, D), MIXED), \
11867 X(3, (Q, D, S), MIXED), \
11868 X(3, (D, Q, S), MIXED), \
11869 X(4, (D, D, D, I), DOUBLE), \
11870 X(4, (Q, Q, Q, I), QUAD), \
11871 X(2, (F, F), SINGLE), \
11872 X(3, (F, F, F), SINGLE), \
11873 X(2, (F, I), SINGLE), \
11874 X(2, (F, D), MIXED), \
11875 X(2, (D, F), MIXED), \
11876 X(3, (F, F, I), MIXED), \
11877 X(4, (R, R, F, F), SINGLE), \
11878 X(4, (F, F, R, R), SINGLE), \
11879 X(3, (D, R, R), DOUBLE), \
11880 X(3, (R, R, D), DOUBLE), \
11881 X(2, (S, R), SINGLE), \
11882 X(2, (R, S), SINGLE), \
11883 X(2, (F, R), SINGLE), \
11884 X(2, (R, F), SINGLE)
11885
11886#define S2(A,B) NS_##A##B
11887#define S3(A,B,C) NS_##A##B##C
11888#define S4(A,B,C,D) NS_##A##B##C##D
11889
11890#define X(N, L, C) S##N L
11891
5287ad62
JB
11892enum neon_shape
11893{
037e8744
JB
11894 NEON_SHAPE_DEF,
11895 NS_NULL
5287ad62 11896};
b99bd4ef 11897
037e8744
JB
11898#undef X
11899#undef S2
11900#undef S3
11901#undef S4
11902
11903enum neon_shape_class
11904{
11905 SC_SINGLE,
11906 SC_DOUBLE,
11907 SC_QUAD,
11908 SC_MIXED
11909};
11910
11911#define X(N, L, C) SC_##C
11912
11913static enum neon_shape_class neon_shape_class[] =
11914{
11915 NEON_SHAPE_DEF
11916};
11917
11918#undef X
11919
11920enum neon_shape_el
11921{
11922 SE_F,
11923 SE_D,
11924 SE_Q,
11925 SE_I,
11926 SE_S,
11927 SE_R,
11928 SE_L
11929};
11930
11931/* Register widths of above. */
11932static unsigned neon_shape_el_size[] =
11933{
11934 32,
11935 64,
11936 128,
11937 0,
11938 32,
11939 32,
11940 0
11941};
11942
11943struct neon_shape_info
11944{
11945 unsigned els;
11946 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11947};
11948
11949#define S2(A,B) { SE_##A, SE_##B }
11950#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11951#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11952
11953#define X(N, L, C) { N, S##N L }
11954
11955static struct neon_shape_info neon_shape_tab[] =
11956{
11957 NEON_SHAPE_DEF
11958};
11959
11960#undef X
11961#undef S2
11962#undef S3
11963#undef S4
11964
5287ad62
JB
11965/* Bit masks used in type checking given instructions.
11966 'N_EQK' means the type must be the same as (or based on in some way) the key
11967 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11968 set, various other bits can be set as well in order to modify the meaning of
11969 the type constraint. */
11970
11971enum neon_type_mask
11972{
8e79c3df
CM
11973 N_S8 = 0x0000001,
11974 N_S16 = 0x0000002,
11975 N_S32 = 0x0000004,
11976 N_S64 = 0x0000008,
11977 N_U8 = 0x0000010,
11978 N_U16 = 0x0000020,
11979 N_U32 = 0x0000040,
11980 N_U64 = 0x0000080,
11981 N_I8 = 0x0000100,
11982 N_I16 = 0x0000200,
11983 N_I32 = 0x0000400,
11984 N_I64 = 0x0000800,
11985 N_8 = 0x0001000,
11986 N_16 = 0x0002000,
11987 N_32 = 0x0004000,
11988 N_64 = 0x0008000,
11989 N_P8 = 0x0010000,
11990 N_P16 = 0x0020000,
11991 N_F16 = 0x0040000,
11992 N_F32 = 0x0080000,
11993 N_F64 = 0x0100000,
c921be7d
NC
11994 N_KEY = 0x1000000, /* Key element (main type specifier). */
11995 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 11996 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
c921be7d
NC
11997 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
11998 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
11999 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
12000 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
12001 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
12002 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
12003 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 12004 N_UTYP = 0,
037e8744 12005 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
12006};
12007
dcbf9037
JB
12008#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
12009
5287ad62
JB
12010#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
12011#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
12012#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
12013#define N_SUF_32 (N_SU_32 | N_F32)
12014#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
12015#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
12016
12017/* Pass this as the first type argument to neon_check_type to ignore types
12018 altogether. */
12019#define N_IGNORE_TYPE (N_KEY | N_EQK)
12020
037e8744
JB
12021/* Select a "shape" for the current instruction (describing register types or
12022 sizes) from a list of alternatives. Return NS_NULL if the current instruction
12023 doesn't fit. For non-polymorphic shapes, checking is usually done as a
12024 function of operand parsing, so this function doesn't need to be called.
12025 Shapes should be listed in order of decreasing length. */
5287ad62
JB
12026
12027static enum neon_shape
037e8744 12028neon_select_shape (enum neon_shape shape, ...)
5287ad62 12029{
037e8744
JB
12030 va_list ap;
12031 enum neon_shape first_shape = shape;
5287ad62
JB
12032
12033 /* Fix missing optional operands. FIXME: we don't know at this point how
12034 many arguments we should have, so this makes the assumption that we have
12035 > 1. This is true of all current Neon opcodes, I think, but may not be
12036 true in the future. */
12037 if (!inst.operands[1].present)
12038 inst.operands[1] = inst.operands[0];
12039
037e8744 12040 va_start (ap, shape);
5f4273c7 12041
21d799b5 12042 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
12043 {
12044 unsigned j;
12045 int matches = 1;
12046
12047 for (j = 0; j < neon_shape_tab[shape].els; j++)
12048 {
12049 if (!inst.operands[j].present)
12050 {
12051 matches = 0;
12052 break;
12053 }
12054
12055 switch (neon_shape_tab[shape].el[j])
12056 {
12057 case SE_F:
12058 if (!(inst.operands[j].isreg
12059 && inst.operands[j].isvec
12060 && inst.operands[j].issingle
12061 && !inst.operands[j].isquad))
12062 matches = 0;
12063 break;
12064
12065 case SE_D:
12066 if (!(inst.operands[j].isreg
12067 && inst.operands[j].isvec
12068 && !inst.operands[j].isquad
12069 && !inst.operands[j].issingle))
12070 matches = 0;
12071 break;
12072
12073 case SE_R:
12074 if (!(inst.operands[j].isreg
12075 && !inst.operands[j].isvec))
12076 matches = 0;
12077 break;
12078
12079 case SE_Q:
12080 if (!(inst.operands[j].isreg
12081 && inst.operands[j].isvec
12082 && inst.operands[j].isquad
12083 && !inst.operands[j].issingle))
12084 matches = 0;
12085 break;
12086
12087 case SE_I:
12088 if (!(!inst.operands[j].isreg
12089 && !inst.operands[j].isscalar))
12090 matches = 0;
12091 break;
12092
12093 case SE_S:
12094 if (!(!inst.operands[j].isreg
12095 && inst.operands[j].isscalar))
12096 matches = 0;
12097 break;
12098
12099 case SE_L:
12100 break;
12101 }
3fde54a2
JZ
12102 if (!matches)
12103 break;
037e8744
JB
12104 }
12105 if (matches)
5287ad62 12106 break;
037e8744 12107 }
5f4273c7 12108
037e8744 12109 va_end (ap);
5287ad62 12110
037e8744
JB
12111 if (shape == NS_NULL && first_shape != NS_NULL)
12112 first_error (_("invalid instruction shape"));
5287ad62 12113
037e8744
JB
12114 return shape;
12115}
5287ad62 12116
037e8744
JB
12117/* True if SHAPE is predominantly a quadword operation (most of the time, this
12118 means the Q bit should be set). */
12119
12120static int
12121neon_quad (enum neon_shape shape)
12122{
12123 return neon_shape_class[shape] == SC_QUAD;
5287ad62 12124}
037e8744 12125
5287ad62
JB
12126static void
12127neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
12128 unsigned *g_size)
12129{
12130 /* Allow modification to be made to types which are constrained to be
12131 based on the key element, based on bits set alongside N_EQK. */
12132 if ((typebits & N_EQK) != 0)
12133 {
12134 if ((typebits & N_HLF) != 0)
12135 *g_size /= 2;
12136 else if ((typebits & N_DBL) != 0)
12137 *g_size *= 2;
12138 if ((typebits & N_SGN) != 0)
12139 *g_type = NT_signed;
12140 else if ((typebits & N_UNS) != 0)
12141 *g_type = NT_unsigned;
12142 else if ((typebits & N_INT) != 0)
12143 *g_type = NT_integer;
12144 else if ((typebits & N_FLT) != 0)
12145 *g_type = NT_float;
dcbf9037
JB
12146 else if ((typebits & N_SIZ) != 0)
12147 *g_type = NT_untyped;
5287ad62
JB
12148 }
12149}
5f4273c7 12150
5287ad62
JB
12151/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12152 operand type, i.e. the single type specified in a Neon instruction when it
12153 is the only one given. */
12154
12155static struct neon_type_el
12156neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12157{
12158 struct neon_type_el dest = *key;
5f4273c7 12159
9c2799c2 12160 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 12161
5287ad62
JB
12162 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12163
12164 return dest;
12165}
12166
12167/* Convert Neon type and size into compact bitmask representation. */
12168
12169static enum neon_type_mask
12170type_chk_of_el_type (enum neon_el_type type, unsigned size)
12171{
12172 switch (type)
12173 {
12174 case NT_untyped:
12175 switch (size)
12176 {
12177 case 8: return N_8;
12178 case 16: return N_16;
12179 case 32: return N_32;
12180 case 64: return N_64;
12181 default: ;
12182 }
12183 break;
12184
12185 case NT_integer:
12186 switch (size)
12187 {
12188 case 8: return N_I8;
12189 case 16: return N_I16;
12190 case 32: return N_I32;
12191 case 64: return N_I64;
12192 default: ;
12193 }
12194 break;
12195
12196 case NT_float:
037e8744
JB
12197 switch (size)
12198 {
8e79c3df 12199 case 16: return N_F16;
037e8744
JB
12200 case 32: return N_F32;
12201 case 64: return N_F64;
12202 default: ;
12203 }
5287ad62
JB
12204 break;
12205
12206 case NT_poly:
12207 switch (size)
12208 {
12209 case 8: return N_P8;
12210 case 16: return N_P16;
12211 default: ;
12212 }
12213 break;
12214
12215 case NT_signed:
12216 switch (size)
12217 {
12218 case 8: return N_S8;
12219 case 16: return N_S16;
12220 case 32: return N_S32;
12221 case 64: return N_S64;
12222 default: ;
12223 }
12224 break;
12225
12226 case NT_unsigned:
12227 switch (size)
12228 {
12229 case 8: return N_U8;
12230 case 16: return N_U16;
12231 case 32: return N_U32;
12232 case 64: return N_U64;
12233 default: ;
12234 }
12235 break;
12236
12237 default: ;
12238 }
5f4273c7 12239
5287ad62
JB
12240 return N_UTYP;
12241}
12242
12243/* Convert compact Neon bitmask type representation to a type and size. Only
12244 handles the case where a single bit is set in the mask. */
12245
dcbf9037 12246static int
5287ad62
JB
12247el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12248 enum neon_type_mask mask)
12249{
dcbf9037
JB
12250 if ((mask & N_EQK) != 0)
12251 return FAIL;
12252
5287ad62
JB
12253 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12254 *size = 8;
dcbf9037 12255 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 12256 *size = 16;
dcbf9037 12257 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 12258 *size = 32;
037e8744 12259 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 12260 *size = 64;
dcbf9037
JB
12261 else
12262 return FAIL;
12263
5287ad62
JB
12264 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12265 *type = NT_signed;
dcbf9037 12266 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 12267 *type = NT_unsigned;
dcbf9037 12268 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 12269 *type = NT_integer;
dcbf9037 12270 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 12271 *type = NT_untyped;
dcbf9037 12272 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 12273 *type = NT_poly;
037e8744 12274 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 12275 *type = NT_float;
dcbf9037
JB
12276 else
12277 return FAIL;
5f4273c7 12278
dcbf9037 12279 return SUCCESS;
5287ad62
JB
12280}
12281
12282/* Modify a bitmask of allowed types. This is only needed for type
12283 relaxation. */
12284
12285static unsigned
12286modify_types_allowed (unsigned allowed, unsigned mods)
12287{
12288 unsigned size;
12289 enum neon_el_type type;
12290 unsigned destmask;
12291 int i;
5f4273c7 12292
5287ad62 12293 destmask = 0;
5f4273c7 12294
5287ad62
JB
12295 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12296 {
21d799b5
NC
12297 if (el_type_of_type_chk (&type, &size,
12298 (enum neon_type_mask) (allowed & i)) == SUCCESS)
dcbf9037
JB
12299 {
12300 neon_modify_type_size (mods, &type, &size);
12301 destmask |= type_chk_of_el_type (type, size);
12302 }
5287ad62 12303 }
5f4273c7 12304
5287ad62
JB
12305 return destmask;
12306}
12307
12308/* Check type and return type classification.
12309 The manual states (paraphrase): If one datatype is given, it indicates the
12310 type given in:
12311 - the second operand, if there is one
12312 - the operand, if there is no second operand
12313 - the result, if there are no operands.
12314 This isn't quite good enough though, so we use a concept of a "key" datatype
12315 which is set on a per-instruction basis, which is the one which matters when
12316 only one data type is written.
12317 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 12318 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
12319
12320static struct neon_type_el
12321neon_check_type (unsigned els, enum neon_shape ns, ...)
12322{
12323 va_list ap;
12324 unsigned i, pass, key_el = 0;
12325 unsigned types[NEON_MAX_TYPE_ELS];
12326 enum neon_el_type k_type = NT_invtype;
12327 unsigned k_size = -1u;
12328 struct neon_type_el badtype = {NT_invtype, -1};
12329 unsigned key_allowed = 0;
12330
12331 /* Optional registers in Neon instructions are always (not) in operand 1.
12332 Fill in the missing operand here, if it was omitted. */
12333 if (els > 1 && !inst.operands[1].present)
12334 inst.operands[1] = inst.operands[0];
12335
12336 /* Suck up all the varargs. */
12337 va_start (ap, ns);
12338 for (i = 0; i < els; i++)
12339 {
12340 unsigned thisarg = va_arg (ap, unsigned);
12341 if (thisarg == N_IGNORE_TYPE)
12342 {
12343 va_end (ap);
12344 return badtype;
12345 }
12346 types[i] = thisarg;
12347 if ((thisarg & N_KEY) != 0)
12348 key_el = i;
12349 }
12350 va_end (ap);
12351
dcbf9037
JB
12352 if (inst.vectype.elems > 0)
12353 for (i = 0; i < els; i++)
12354 if (inst.operands[i].vectype.type != NT_invtype)
12355 {
12356 first_error (_("types specified in both the mnemonic and operands"));
12357 return badtype;
12358 }
12359
5287ad62
JB
12360 /* Duplicate inst.vectype elements here as necessary.
12361 FIXME: No idea if this is exactly the same as the ARM assembler,
12362 particularly when an insn takes one register and one non-register
12363 operand. */
12364 if (inst.vectype.elems == 1 && els > 1)
12365 {
12366 unsigned j;
12367 inst.vectype.elems = els;
12368 inst.vectype.el[key_el] = inst.vectype.el[0];
12369 for (j = 0; j < els; j++)
dcbf9037
JB
12370 if (j != key_el)
12371 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12372 types[j]);
12373 }
12374 else if (inst.vectype.elems == 0 && els > 0)
12375 {
12376 unsigned j;
12377 /* No types were given after the mnemonic, so look for types specified
12378 after each operand. We allow some flexibility here; as long as the
12379 "key" operand has a type, we can infer the others. */
12380 for (j = 0; j < els; j++)
12381 if (inst.operands[j].vectype.type != NT_invtype)
12382 inst.vectype.el[j] = inst.operands[j].vectype;
12383
12384 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 12385 {
dcbf9037
JB
12386 for (j = 0; j < els; j++)
12387 if (inst.operands[j].vectype.type == NT_invtype)
12388 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12389 types[j]);
12390 }
12391 else
12392 {
12393 first_error (_("operand types can't be inferred"));
12394 return badtype;
5287ad62
JB
12395 }
12396 }
12397 else if (inst.vectype.elems != els)
12398 {
dcbf9037 12399 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
12400 return badtype;
12401 }
12402
12403 for (pass = 0; pass < 2; pass++)
12404 {
12405 for (i = 0; i < els; i++)
12406 {
12407 unsigned thisarg = types[i];
12408 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12409 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12410 enum neon_el_type g_type = inst.vectype.el[i].type;
12411 unsigned g_size = inst.vectype.el[i].size;
12412
12413 /* Decay more-specific signed & unsigned types to sign-insensitive
12414 integer types if sign-specific variants are unavailable. */
12415 if ((g_type == NT_signed || g_type == NT_unsigned)
12416 && (types_allowed & N_SU_ALL) == 0)
12417 g_type = NT_integer;
12418
12419 /* If only untyped args are allowed, decay any more specific types to
12420 them. Some instructions only care about signs for some element
12421 sizes, so handle that properly. */
12422 if ((g_size == 8 && (types_allowed & N_8) != 0)
12423 || (g_size == 16 && (types_allowed & N_16) != 0)
12424 || (g_size == 32 && (types_allowed & N_32) != 0)
12425 || (g_size == 64 && (types_allowed & N_64) != 0))
12426 g_type = NT_untyped;
12427
12428 if (pass == 0)
12429 {
12430 if ((thisarg & N_KEY) != 0)
12431 {
12432 k_type = g_type;
12433 k_size = g_size;
12434 key_allowed = thisarg & ~N_KEY;
12435 }
12436 }
12437 else
12438 {
037e8744
JB
12439 if ((thisarg & N_VFP) != 0)
12440 {
99b253c5
NC
12441 enum neon_shape_el regshape;
12442 unsigned regwidth, match;
12443
12444 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12445 if (ns == NS_NULL)
12446 {
12447 first_error (_("invalid instruction shape"));
12448 return badtype;
12449 }
12450 regshape = neon_shape_tab[ns].el[i];
12451 regwidth = neon_shape_el_size[regshape];
037e8744
JB
12452
12453 /* In VFP mode, operands must match register widths. If we
12454 have a key operand, use its width, else use the width of
12455 the current operand. */
12456 if (k_size != -1u)
12457 match = k_size;
12458 else
12459 match = g_size;
12460
12461 if (regwidth != match)
12462 {
12463 first_error (_("operand size must match register width"));
12464 return badtype;
12465 }
12466 }
5f4273c7 12467
5287ad62
JB
12468 if ((thisarg & N_EQK) == 0)
12469 {
12470 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12471
12472 if ((given_type & types_allowed) == 0)
12473 {
dcbf9037 12474 first_error (_("bad type in Neon instruction"));
5287ad62
JB
12475 return badtype;
12476 }
12477 }
12478 else
12479 {
12480 enum neon_el_type mod_k_type = k_type;
12481 unsigned mod_k_size = k_size;
12482 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12483 if (g_type != mod_k_type || g_size != mod_k_size)
12484 {
dcbf9037 12485 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
12486 return badtype;
12487 }
12488 }
12489 }
12490 }
12491 }
12492
12493 return inst.vectype.el[key_el];
12494}
12495
037e8744 12496/* Neon-style VFP instruction forwarding. */
5287ad62 12497
037e8744
JB
12498/* Thumb VFP instructions have 0xE in the condition field. */
12499
12500static void
12501do_vfp_cond_or_thumb (void)
5287ad62 12502{
88714cb8
DG
12503 inst.is_neon = 1;
12504
5287ad62 12505 if (thumb_mode)
037e8744 12506 inst.instruction |= 0xe0000000;
5287ad62 12507 else
037e8744 12508 inst.instruction |= inst.cond << 28;
5287ad62
JB
12509}
12510
037e8744
JB
12511/* Look up and encode a simple mnemonic, for use as a helper function for the
12512 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12513 etc. It is assumed that operand parsing has already been done, and that the
12514 operands are in the form expected by the given opcode (this isn't necessarily
12515 the same as the form in which they were parsed, hence some massaging must
12516 take place before this function is called).
12517 Checks current arch version against that in the looked-up opcode. */
5287ad62 12518
037e8744
JB
12519static void
12520do_vfp_nsyn_opcode (const char *opname)
5287ad62 12521{
037e8744 12522 const struct asm_opcode *opcode;
5f4273c7 12523
21d799b5 12524 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 12525
037e8744
JB
12526 if (!opcode)
12527 abort ();
5287ad62 12528
037e8744
JB
12529 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12530 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12531 _(BAD_FPU));
5287ad62 12532
88714cb8
DG
12533 inst.is_neon = 1;
12534
037e8744
JB
12535 if (thumb_mode)
12536 {
12537 inst.instruction = opcode->tvalue;
12538 opcode->tencode ();
12539 }
12540 else
12541 {
12542 inst.instruction = (inst.cond << 28) | opcode->avalue;
12543 opcode->aencode ();
12544 }
12545}
5287ad62
JB
12546
12547static void
037e8744 12548do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 12549{
037e8744
JB
12550 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12551
12552 if (rs == NS_FFF)
12553 {
12554 if (is_add)
12555 do_vfp_nsyn_opcode ("fadds");
12556 else
12557 do_vfp_nsyn_opcode ("fsubs");
12558 }
12559 else
12560 {
12561 if (is_add)
12562 do_vfp_nsyn_opcode ("faddd");
12563 else
12564 do_vfp_nsyn_opcode ("fsubd");
12565 }
12566}
12567
12568/* Check operand types to see if this is a VFP instruction, and if so call
12569 PFN (). */
12570
12571static int
12572try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12573{
12574 enum neon_shape rs;
12575 struct neon_type_el et;
12576
12577 switch (args)
12578 {
12579 case 2:
12580 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12581 et = neon_check_type (2, rs,
12582 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12583 break;
5f4273c7 12584
037e8744
JB
12585 case 3:
12586 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12587 et = neon_check_type (3, rs,
12588 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12589 break;
12590
12591 default:
12592 abort ();
12593 }
12594
12595 if (et.type != NT_invtype)
12596 {
12597 pfn (rs);
12598 return SUCCESS;
12599 }
037e8744 12600
99b253c5 12601 inst.error = NULL;
037e8744
JB
12602 return FAIL;
12603}
12604
12605static void
12606do_vfp_nsyn_mla_mls (enum neon_shape rs)
12607{
12608 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 12609
037e8744
JB
12610 if (rs == NS_FFF)
12611 {
12612 if (is_mla)
12613 do_vfp_nsyn_opcode ("fmacs");
12614 else
1ee69515 12615 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
12616 }
12617 else
12618 {
12619 if (is_mla)
12620 do_vfp_nsyn_opcode ("fmacd");
12621 else
1ee69515 12622 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
12623 }
12624}
12625
62f3b8c8
PB
12626static void
12627do_vfp_nsyn_fma_fms (enum neon_shape rs)
12628{
12629 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12630
12631 if (rs == NS_FFF)
12632 {
12633 if (is_fma)
12634 do_vfp_nsyn_opcode ("ffmas");
12635 else
12636 do_vfp_nsyn_opcode ("ffnmas");
12637 }
12638 else
12639 {
12640 if (is_fma)
12641 do_vfp_nsyn_opcode ("ffmad");
12642 else
12643 do_vfp_nsyn_opcode ("ffnmad");
12644 }
12645}
12646
037e8744
JB
12647static void
12648do_vfp_nsyn_mul (enum neon_shape rs)
12649{
12650 if (rs == NS_FFF)
12651 do_vfp_nsyn_opcode ("fmuls");
12652 else
12653 do_vfp_nsyn_opcode ("fmuld");
12654}
12655
12656static void
12657do_vfp_nsyn_abs_neg (enum neon_shape rs)
12658{
12659 int is_neg = (inst.instruction & 0x80) != 0;
12660 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12661
12662 if (rs == NS_FF)
12663 {
12664 if (is_neg)
12665 do_vfp_nsyn_opcode ("fnegs");
12666 else
12667 do_vfp_nsyn_opcode ("fabss");
12668 }
12669 else
12670 {
12671 if (is_neg)
12672 do_vfp_nsyn_opcode ("fnegd");
12673 else
12674 do_vfp_nsyn_opcode ("fabsd");
12675 }
12676}
12677
12678/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12679 insns belong to Neon, and are handled elsewhere. */
12680
12681static void
12682do_vfp_nsyn_ldm_stm (int is_dbmode)
12683{
12684 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12685 if (is_ldm)
12686 {
12687 if (is_dbmode)
12688 do_vfp_nsyn_opcode ("fldmdbs");
12689 else
12690 do_vfp_nsyn_opcode ("fldmias");
12691 }
12692 else
12693 {
12694 if (is_dbmode)
12695 do_vfp_nsyn_opcode ("fstmdbs");
12696 else
12697 do_vfp_nsyn_opcode ("fstmias");
12698 }
12699}
12700
037e8744
JB
12701static void
12702do_vfp_nsyn_sqrt (void)
12703{
12704 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12705 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12706
037e8744
JB
12707 if (rs == NS_FF)
12708 do_vfp_nsyn_opcode ("fsqrts");
12709 else
12710 do_vfp_nsyn_opcode ("fsqrtd");
12711}
12712
12713static void
12714do_vfp_nsyn_div (void)
12715{
12716 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12717 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12718 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12719
037e8744
JB
12720 if (rs == NS_FFF)
12721 do_vfp_nsyn_opcode ("fdivs");
12722 else
12723 do_vfp_nsyn_opcode ("fdivd");
12724}
12725
12726static void
12727do_vfp_nsyn_nmul (void)
12728{
12729 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12730 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12731 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12732
037e8744
JB
12733 if (rs == NS_FFF)
12734 {
88714cb8 12735 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12736 do_vfp_sp_dyadic ();
12737 }
12738 else
12739 {
88714cb8 12740 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12741 do_vfp_dp_rd_rn_rm ();
12742 }
12743 do_vfp_cond_or_thumb ();
12744}
12745
12746static void
12747do_vfp_nsyn_cmp (void)
12748{
12749 if (inst.operands[1].isreg)
12750 {
12751 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12752 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12753
037e8744
JB
12754 if (rs == NS_FF)
12755 {
88714cb8 12756 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12757 do_vfp_sp_monadic ();
12758 }
12759 else
12760 {
88714cb8 12761 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12762 do_vfp_dp_rd_rm ();
12763 }
12764 }
12765 else
12766 {
12767 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12768 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12769
12770 switch (inst.instruction & 0x0fffffff)
12771 {
12772 case N_MNEM_vcmp:
12773 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12774 break;
12775 case N_MNEM_vcmpe:
12776 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12777 break;
12778 default:
12779 abort ();
12780 }
5f4273c7 12781
037e8744
JB
12782 if (rs == NS_FI)
12783 {
88714cb8 12784 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12785 do_vfp_sp_compare_z ();
12786 }
12787 else
12788 {
88714cb8 12789 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12790 do_vfp_dp_rd ();
12791 }
12792 }
12793 do_vfp_cond_or_thumb ();
12794}
12795
12796static void
12797nsyn_insert_sp (void)
12798{
12799 inst.operands[1] = inst.operands[0];
12800 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 12801 inst.operands[0].reg = REG_SP;
037e8744
JB
12802 inst.operands[0].isreg = 1;
12803 inst.operands[0].writeback = 1;
12804 inst.operands[0].present = 1;
12805}
12806
12807static void
12808do_vfp_nsyn_push (void)
12809{
12810 nsyn_insert_sp ();
12811 if (inst.operands[1].issingle)
12812 do_vfp_nsyn_opcode ("fstmdbs");
12813 else
12814 do_vfp_nsyn_opcode ("fstmdbd");
12815}
12816
12817static void
12818do_vfp_nsyn_pop (void)
12819{
12820 nsyn_insert_sp ();
12821 if (inst.operands[1].issingle)
22b5b651 12822 do_vfp_nsyn_opcode ("fldmias");
037e8744 12823 else
22b5b651 12824 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
12825}
12826
12827/* Fix up Neon data-processing instructions, ORing in the correct bits for
12828 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12829
88714cb8
DG
12830static void
12831neon_dp_fixup (struct arm_it* insn)
037e8744 12832{
88714cb8
DG
12833 unsigned int i = insn->instruction;
12834 insn->is_neon = 1;
12835
037e8744
JB
12836 if (thumb_mode)
12837 {
12838 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12839 if (i & (1 << 24))
12840 i |= 1 << 28;
5f4273c7 12841
037e8744 12842 i &= ~(1 << 24);
5f4273c7 12843
037e8744
JB
12844 i |= 0xef000000;
12845 }
12846 else
12847 i |= 0xf2000000;
5f4273c7 12848
88714cb8 12849 insn->instruction = i;
037e8744
JB
12850}
12851
12852/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12853 (0, 1, 2, 3). */
12854
12855static unsigned
12856neon_logbits (unsigned x)
12857{
12858 return ffs (x) - 4;
12859}
12860
12861#define LOW4(R) ((R) & 0xf)
12862#define HI1(R) (((R) >> 4) & 1)
12863
12864/* Encode insns with bit pattern:
12865
12866 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12867 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 12868
037e8744
JB
12869 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12870 different meaning for some instruction. */
12871
12872static void
12873neon_three_same (int isquad, int ubit, int size)
12874{
12875 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12876 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12877 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12878 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12879 inst.instruction |= LOW4 (inst.operands[2].reg);
12880 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12881 inst.instruction |= (isquad != 0) << 6;
12882 inst.instruction |= (ubit != 0) << 24;
12883 if (size != -1)
12884 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12885
88714cb8 12886 neon_dp_fixup (&inst);
037e8744
JB
12887}
12888
12889/* Encode instructions of the form:
12890
12891 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12892 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
12893
12894 Don't write size if SIZE == -1. */
12895
12896static void
12897neon_two_same (int qbit, int ubit, int size)
12898{
12899 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12900 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12901 inst.instruction |= LOW4 (inst.operands[1].reg);
12902 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12903 inst.instruction |= (qbit != 0) << 6;
12904 inst.instruction |= (ubit != 0) << 24;
12905
12906 if (size != -1)
12907 inst.instruction |= neon_logbits (size) << 18;
12908
88714cb8 12909 neon_dp_fixup (&inst);
5287ad62
JB
12910}
12911
12912/* Neon instruction encoders, in approximate order of appearance. */
12913
12914static void
12915do_neon_dyadic_i_su (void)
12916{
037e8744 12917 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12918 struct neon_type_el et = neon_check_type (3, rs,
12919 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 12920 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12921}
12922
12923static void
12924do_neon_dyadic_i64_su (void)
12925{
037e8744 12926 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12927 struct neon_type_el et = neon_check_type (3, rs,
12928 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 12929 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12930}
12931
12932static void
12933neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12934 unsigned immbits)
12935{
12936 unsigned size = et.size >> 3;
12937 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12938 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12939 inst.instruction |= LOW4 (inst.operands[1].reg);
12940 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12941 inst.instruction |= (isquad != 0) << 6;
12942 inst.instruction |= immbits << 16;
12943 inst.instruction |= (size >> 3) << 7;
12944 inst.instruction |= (size & 0x7) << 19;
12945 if (write_ubit)
12946 inst.instruction |= (uval != 0) << 24;
12947
88714cb8 12948 neon_dp_fixup (&inst);
5287ad62
JB
12949}
12950
12951static void
12952do_neon_shl_imm (void)
12953{
12954 if (!inst.operands[2].isreg)
12955 {
037e8744 12956 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12957 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
88714cb8 12958 NEON_ENCODE (IMMED, inst);
037e8744 12959 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
12960 }
12961 else
12962 {
037e8744 12963 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12964 struct neon_type_el et = neon_check_type (3, rs,
12965 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12966 unsigned int tmp;
12967
12968 /* VSHL/VQSHL 3-register variants have syntax such as:
12969 vshl.xx Dd, Dm, Dn
12970 whereas other 3-register operations encoded by neon_three_same have
12971 syntax like:
12972 vadd.xx Dd, Dn, Dm
12973 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12974 here. */
12975 tmp = inst.operands[2].reg;
12976 inst.operands[2].reg = inst.operands[1].reg;
12977 inst.operands[1].reg = tmp;
88714cb8 12978 NEON_ENCODE (INTEGER, inst);
037e8744 12979 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12980 }
12981}
12982
12983static void
12984do_neon_qshl_imm (void)
12985{
12986 if (!inst.operands[2].isreg)
12987 {
037e8744 12988 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12989 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 12990
88714cb8 12991 NEON_ENCODE (IMMED, inst);
037e8744 12992 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
12993 inst.operands[2].imm);
12994 }
12995 else
12996 {
037e8744 12997 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12998 struct neon_type_el et = neon_check_type (3, rs,
12999 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13000 unsigned int tmp;
13001
13002 /* See note in do_neon_shl_imm. */
13003 tmp = inst.operands[2].reg;
13004 inst.operands[2].reg = inst.operands[1].reg;
13005 inst.operands[1].reg = tmp;
88714cb8 13006 NEON_ENCODE (INTEGER, inst);
037e8744 13007 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13008 }
13009}
13010
627907b7
JB
13011static void
13012do_neon_rshl (void)
13013{
13014 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13015 struct neon_type_el et = neon_check_type (3, rs,
13016 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13017 unsigned int tmp;
13018
13019 tmp = inst.operands[2].reg;
13020 inst.operands[2].reg = inst.operands[1].reg;
13021 inst.operands[1].reg = tmp;
13022 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13023}
13024
5287ad62
JB
13025static int
13026neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
13027{
036dc3f7
PB
13028 /* Handle .I8 pseudo-instructions. */
13029 if (size == 8)
5287ad62 13030 {
5287ad62
JB
13031 /* Unfortunately, this will make everything apart from zero out-of-range.
13032 FIXME is this the intended semantics? There doesn't seem much point in
13033 accepting .I8 if so. */
13034 immediate |= immediate << 8;
13035 size = 16;
036dc3f7
PB
13036 }
13037
13038 if (size >= 32)
13039 {
13040 if (immediate == (immediate & 0x000000ff))
13041 {
13042 *immbits = immediate;
13043 return 0x1;
13044 }
13045 else if (immediate == (immediate & 0x0000ff00))
13046 {
13047 *immbits = immediate >> 8;
13048 return 0x3;
13049 }
13050 else if (immediate == (immediate & 0x00ff0000))
13051 {
13052 *immbits = immediate >> 16;
13053 return 0x5;
13054 }
13055 else if (immediate == (immediate & 0xff000000))
13056 {
13057 *immbits = immediate >> 24;
13058 return 0x7;
13059 }
13060 if ((immediate & 0xffff) != (immediate >> 16))
13061 goto bad_immediate;
13062 immediate &= 0xffff;
5287ad62
JB
13063 }
13064
13065 if (immediate == (immediate & 0x000000ff))
13066 {
13067 *immbits = immediate;
036dc3f7 13068 return 0x9;
5287ad62
JB
13069 }
13070 else if (immediate == (immediate & 0x0000ff00))
13071 {
13072 *immbits = immediate >> 8;
036dc3f7 13073 return 0xb;
5287ad62
JB
13074 }
13075
13076 bad_immediate:
dcbf9037 13077 first_error (_("immediate value out of range"));
5287ad62
JB
13078 return FAIL;
13079}
13080
13081/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
13082 A, B, C, D. */
13083
13084static int
13085neon_bits_same_in_bytes (unsigned imm)
13086{
13087 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
13088 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
13089 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
13090 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
13091}
13092
13093/* For immediate of above form, return 0bABCD. */
13094
13095static unsigned
13096neon_squash_bits (unsigned imm)
13097{
13098 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
13099 | ((imm & 0x01000000) >> 21);
13100}
13101
136da414 13102/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
13103
13104static unsigned
13105neon_qfloat_bits (unsigned imm)
13106{
136da414 13107 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
13108}
13109
13110/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
13111 the instruction. *OP is passed as the initial value of the op field, and
13112 may be set to a different value depending on the constant (i.e.
13113 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 13114 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 13115 try smaller element sizes. */
5287ad62
JB
13116
13117static int
c96612cc
JB
13118neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
13119 unsigned *immbits, int *op, int size,
13120 enum neon_el_type type)
5287ad62 13121{
c96612cc
JB
13122 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13123 float. */
13124 if (type == NT_float && !float_p)
13125 return FAIL;
13126
136da414
JB
13127 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13128 {
13129 if (size != 32 || *op == 1)
13130 return FAIL;
13131 *immbits = neon_qfloat_bits (immlo);
13132 return 0xf;
13133 }
036dc3f7
PB
13134
13135 if (size == 64)
5287ad62 13136 {
036dc3f7
PB
13137 if (neon_bits_same_in_bytes (immhi)
13138 && neon_bits_same_in_bytes (immlo))
13139 {
13140 if (*op == 1)
13141 return FAIL;
13142 *immbits = (neon_squash_bits (immhi) << 4)
13143 | neon_squash_bits (immlo);
13144 *op = 1;
13145 return 0xe;
13146 }
13147
13148 if (immhi != immlo)
13149 return FAIL;
5287ad62 13150 }
036dc3f7
PB
13151
13152 if (size >= 32)
5287ad62 13153 {
036dc3f7
PB
13154 if (immlo == (immlo & 0x000000ff))
13155 {
13156 *immbits = immlo;
13157 return 0x0;
13158 }
13159 else if (immlo == (immlo & 0x0000ff00))
13160 {
13161 *immbits = immlo >> 8;
13162 return 0x2;
13163 }
13164 else if (immlo == (immlo & 0x00ff0000))
13165 {
13166 *immbits = immlo >> 16;
13167 return 0x4;
13168 }
13169 else if (immlo == (immlo & 0xff000000))
13170 {
13171 *immbits = immlo >> 24;
13172 return 0x6;
13173 }
13174 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13175 {
13176 *immbits = (immlo >> 8) & 0xff;
13177 return 0xc;
13178 }
13179 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13180 {
13181 *immbits = (immlo >> 16) & 0xff;
13182 return 0xd;
13183 }
13184
13185 if ((immlo & 0xffff) != (immlo >> 16))
13186 return FAIL;
13187 immlo &= 0xffff;
5287ad62 13188 }
036dc3f7
PB
13189
13190 if (size >= 16)
5287ad62 13191 {
036dc3f7
PB
13192 if (immlo == (immlo & 0x000000ff))
13193 {
13194 *immbits = immlo;
13195 return 0x8;
13196 }
13197 else if (immlo == (immlo & 0x0000ff00))
13198 {
13199 *immbits = immlo >> 8;
13200 return 0xa;
13201 }
13202
13203 if ((immlo & 0xff) != (immlo >> 8))
13204 return FAIL;
13205 immlo &= 0xff;
5287ad62 13206 }
036dc3f7
PB
13207
13208 if (immlo == (immlo & 0x000000ff))
5287ad62 13209 {
036dc3f7
PB
13210 /* Don't allow MVN with 8-bit immediate. */
13211 if (*op == 1)
13212 return FAIL;
13213 *immbits = immlo;
13214 return 0xe;
5287ad62 13215 }
5287ad62
JB
13216
13217 return FAIL;
13218}
13219
13220/* Write immediate bits [7:0] to the following locations:
13221
13222 |28/24|23 19|18 16|15 4|3 0|
13223 | 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|
13224
13225 This function is used by VMOV/VMVN/VORR/VBIC. */
13226
13227static void
13228neon_write_immbits (unsigned immbits)
13229{
13230 inst.instruction |= immbits & 0xf;
13231 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13232 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13233}
13234
13235/* Invert low-order SIZE bits of XHI:XLO. */
13236
13237static void
13238neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13239{
13240 unsigned immlo = xlo ? *xlo : 0;
13241 unsigned immhi = xhi ? *xhi : 0;
13242
13243 switch (size)
13244 {
13245 case 8:
13246 immlo = (~immlo) & 0xff;
13247 break;
13248
13249 case 16:
13250 immlo = (~immlo) & 0xffff;
13251 break;
13252
13253 case 64:
13254 immhi = (~immhi) & 0xffffffff;
13255 /* fall through. */
13256
13257 case 32:
13258 immlo = (~immlo) & 0xffffffff;
13259 break;
13260
13261 default:
13262 abort ();
13263 }
13264
13265 if (xlo)
13266 *xlo = immlo;
13267
13268 if (xhi)
13269 *xhi = immhi;
13270}
13271
13272static void
13273do_neon_logic (void)
13274{
13275 if (inst.operands[2].present && inst.operands[2].isreg)
13276 {
037e8744 13277 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13278 neon_check_type (3, rs, N_IGNORE_TYPE);
13279 /* U bit and size field were set as part of the bitmask. */
88714cb8 13280 NEON_ENCODE (INTEGER, inst);
037e8744 13281 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13282 }
13283 else
13284 {
4316f0d2
DG
13285 const int three_ops_form = (inst.operands[2].present
13286 && !inst.operands[2].isreg);
13287 const int immoperand = (three_ops_form ? 2 : 1);
13288 enum neon_shape rs = (three_ops_form
13289 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13290 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744
JB
13291 struct neon_type_el et = neon_check_type (2, rs,
13292 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 13293 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
13294 unsigned immbits;
13295 int cmode;
5f4273c7 13296
5287ad62
JB
13297 if (et.type == NT_invtype)
13298 return;
5f4273c7 13299
4316f0d2
DG
13300 if (three_ops_form)
13301 constraint (inst.operands[0].reg != inst.operands[1].reg,
13302 _("first and second operands shall be the same register"));
13303
88714cb8 13304 NEON_ENCODE (IMMED, inst);
5287ad62 13305
4316f0d2 13306 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
13307 if (et.size == 64)
13308 {
13309 /* .i64 is a pseudo-op, so the immediate must be a repeating
13310 pattern. */
4316f0d2
DG
13311 if (immbits != (inst.operands[immoperand].regisimm ?
13312 inst.operands[immoperand].reg : 0))
036dc3f7
PB
13313 {
13314 /* Set immbits to an invalid constant. */
13315 immbits = 0xdeadbeef;
13316 }
13317 }
13318
5287ad62
JB
13319 switch (opcode)
13320 {
13321 case N_MNEM_vbic:
036dc3f7 13322 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13323 break;
5f4273c7 13324
5287ad62 13325 case N_MNEM_vorr:
036dc3f7 13326 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13327 break;
5f4273c7 13328
5287ad62
JB
13329 case N_MNEM_vand:
13330 /* Pseudo-instruction for VBIC. */
5287ad62
JB
13331 neon_invert_size (&immbits, 0, et.size);
13332 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13333 break;
5f4273c7 13334
5287ad62
JB
13335 case N_MNEM_vorn:
13336 /* Pseudo-instruction for VORR. */
5287ad62
JB
13337 neon_invert_size (&immbits, 0, et.size);
13338 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13339 break;
5f4273c7 13340
5287ad62
JB
13341 default:
13342 abort ();
13343 }
13344
13345 if (cmode == FAIL)
13346 return;
13347
037e8744 13348 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13349 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13350 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13351 inst.instruction |= cmode << 8;
13352 neon_write_immbits (immbits);
5f4273c7 13353
88714cb8 13354 neon_dp_fixup (&inst);
5287ad62
JB
13355 }
13356}
13357
13358static void
13359do_neon_bitfield (void)
13360{
037e8744 13361 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 13362 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 13363 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13364}
13365
13366static void
dcbf9037
JB
13367neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13368 unsigned destbits)
5287ad62 13369{
037e8744 13370 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
13371 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13372 types | N_KEY);
5287ad62
JB
13373 if (et.type == NT_float)
13374 {
88714cb8 13375 NEON_ENCODE (FLOAT, inst);
037e8744 13376 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13377 }
13378 else
13379 {
88714cb8 13380 NEON_ENCODE (INTEGER, inst);
037e8744 13381 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
13382 }
13383}
13384
13385static void
13386do_neon_dyadic_if_su (void)
13387{
dcbf9037 13388 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13389}
13390
13391static void
13392do_neon_dyadic_if_su_d (void)
13393{
13394 /* This version only allow D registers, but that constraint is enforced during
13395 operand parsing so we don't need to do anything extra here. */
dcbf9037 13396 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13397}
13398
5287ad62
JB
13399static void
13400do_neon_dyadic_if_i_d (void)
13401{
428e3f1f
PB
13402 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13403 affected if we specify unsigned args. */
13404 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
13405}
13406
037e8744
JB
13407enum vfp_or_neon_is_neon_bits
13408{
13409 NEON_CHECK_CC = 1,
13410 NEON_CHECK_ARCH = 2
13411};
13412
13413/* Call this function if an instruction which may have belonged to the VFP or
13414 Neon instruction sets, but turned out to be a Neon instruction (due to the
13415 operand types involved, etc.). We have to check and/or fix-up a couple of
13416 things:
13417
13418 - Make sure the user hasn't attempted to make a Neon instruction
13419 conditional.
13420 - Alter the value in the condition code field if necessary.
13421 - Make sure that the arch supports Neon instructions.
13422
13423 Which of these operations take place depends on bits from enum
13424 vfp_or_neon_is_neon_bits.
13425
13426 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13427 current instruction's condition is COND_ALWAYS, the condition field is
13428 changed to inst.uncond_value. This is necessary because instructions shared
13429 between VFP and Neon may be conditional for the VFP variants only, and the
13430 unconditional Neon version must have, e.g., 0xF in the condition field. */
13431
13432static int
13433vfp_or_neon_is_neon (unsigned check)
13434{
13435 /* Conditions are always legal in Thumb mode (IT blocks). */
13436 if (!thumb_mode && (check & NEON_CHECK_CC))
13437 {
13438 if (inst.cond != COND_ALWAYS)
13439 {
13440 first_error (_(BAD_COND));
13441 return FAIL;
13442 }
13443 if (inst.uncond_value != -1)
13444 inst.instruction |= inst.uncond_value << 28;
13445 }
5f4273c7 13446
037e8744
JB
13447 if ((check & NEON_CHECK_ARCH)
13448 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13449 {
13450 first_error (_(BAD_FPU));
13451 return FAIL;
13452 }
5f4273c7 13453
037e8744
JB
13454 return SUCCESS;
13455}
13456
5287ad62
JB
13457static void
13458do_neon_addsub_if_i (void)
13459{
037e8744
JB
13460 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13461 return;
13462
13463 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13464 return;
13465
5287ad62
JB
13466 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13467 affected if we specify unsigned args. */
dcbf9037 13468 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
13469}
13470
13471/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13472 result to be:
13473 V<op> A,B (A is operand 0, B is operand 2)
13474 to mean:
13475 V<op> A,B,A
13476 not:
13477 V<op> A,B,B
13478 so handle that case specially. */
13479
13480static void
13481neon_exchange_operands (void)
13482{
13483 void *scratch = alloca (sizeof (inst.operands[0]));
13484 if (inst.operands[1].present)
13485 {
13486 /* Swap operands[1] and operands[2]. */
13487 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13488 inst.operands[1] = inst.operands[2];
13489 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13490 }
13491 else
13492 {
13493 inst.operands[1] = inst.operands[2];
13494 inst.operands[2] = inst.operands[0];
13495 }
13496}
13497
13498static void
13499neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13500{
13501 if (inst.operands[2].isreg)
13502 {
13503 if (invert)
13504 neon_exchange_operands ();
dcbf9037 13505 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
13506 }
13507 else
13508 {
037e8744 13509 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
13510 struct neon_type_el et = neon_check_type (2, rs,
13511 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 13512
88714cb8 13513 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13514 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13515 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13516 inst.instruction |= LOW4 (inst.operands[1].reg);
13517 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13518 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13519 inst.instruction |= (et.type == NT_float) << 10;
13520 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13521
88714cb8 13522 neon_dp_fixup (&inst);
5287ad62
JB
13523 }
13524}
13525
13526static void
13527do_neon_cmp (void)
13528{
13529 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13530}
13531
13532static void
13533do_neon_cmp_inv (void)
13534{
13535 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13536}
13537
13538static void
13539do_neon_ceq (void)
13540{
13541 neon_compare (N_IF_32, N_IF_32, FALSE);
13542}
13543
13544/* For multiply instructions, we have the possibility of 16-bit or 32-bit
13545 scalars, which are encoded in 5 bits, M : Rm.
13546 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13547 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13548 index in M. */
13549
13550static unsigned
13551neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13552{
dcbf9037
JB
13553 unsigned regno = NEON_SCALAR_REG (scalar);
13554 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
13555
13556 switch (elsize)
13557 {
13558 case 16:
13559 if (regno > 7 || elno > 3)
13560 goto bad_scalar;
13561 return regno | (elno << 3);
5f4273c7 13562
5287ad62
JB
13563 case 32:
13564 if (regno > 15 || elno > 1)
13565 goto bad_scalar;
13566 return regno | (elno << 4);
13567
13568 default:
13569 bad_scalar:
dcbf9037 13570 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
13571 }
13572
13573 return 0;
13574}
13575
13576/* Encode multiply / multiply-accumulate scalar instructions. */
13577
13578static void
13579neon_mul_mac (struct neon_type_el et, int ubit)
13580{
dcbf9037
JB
13581 unsigned scalar;
13582
13583 /* Give a more helpful error message if we have an invalid type. */
13584 if (et.type == NT_invtype)
13585 return;
5f4273c7 13586
dcbf9037 13587 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
13588 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13589 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13590 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13591 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13592 inst.instruction |= LOW4 (scalar);
13593 inst.instruction |= HI1 (scalar) << 5;
13594 inst.instruction |= (et.type == NT_float) << 8;
13595 inst.instruction |= neon_logbits (et.size) << 20;
13596 inst.instruction |= (ubit != 0) << 24;
13597
88714cb8 13598 neon_dp_fixup (&inst);
5287ad62
JB
13599}
13600
13601static void
13602do_neon_mac_maybe_scalar (void)
13603{
037e8744
JB
13604 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13605 return;
13606
13607 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13608 return;
13609
5287ad62
JB
13610 if (inst.operands[2].isscalar)
13611 {
037e8744 13612 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13613 struct neon_type_el et = neon_check_type (3, rs,
13614 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 13615 NEON_ENCODE (SCALAR, inst);
037e8744 13616 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13617 }
13618 else
428e3f1f
PB
13619 {
13620 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13621 affected if we specify unsigned args. */
13622 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13623 }
5287ad62
JB
13624}
13625
62f3b8c8
PB
13626static void
13627do_neon_fmac (void)
13628{
13629 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13630 return;
13631
13632 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13633 return;
13634
13635 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13636}
13637
5287ad62
JB
13638static void
13639do_neon_tst (void)
13640{
037e8744 13641 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13642 struct neon_type_el et = neon_check_type (3, rs,
13643 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 13644 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13645}
13646
13647/* VMUL with 3 registers allows the P8 type. The scalar version supports the
13648 same types as the MAC equivalents. The polynomial type for this instruction
13649 is encoded the same as the integer type. */
13650
13651static void
13652do_neon_mul (void)
13653{
037e8744
JB
13654 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13655 return;
13656
13657 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13658 return;
13659
5287ad62
JB
13660 if (inst.operands[2].isscalar)
13661 do_neon_mac_maybe_scalar ();
13662 else
dcbf9037 13663 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
13664}
13665
13666static void
13667do_neon_qdmulh (void)
13668{
13669 if (inst.operands[2].isscalar)
13670 {
037e8744 13671 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13672 struct neon_type_el et = neon_check_type (3, rs,
13673 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13674 NEON_ENCODE (SCALAR, inst);
037e8744 13675 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13676 }
13677 else
13678 {
037e8744 13679 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13680 struct neon_type_el et = neon_check_type (3, rs,
13681 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13682 NEON_ENCODE (INTEGER, inst);
5287ad62 13683 /* The U bit (rounding) comes from bit mask. */
037e8744 13684 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13685 }
13686}
13687
13688static void
13689do_neon_fcmp_absolute (void)
13690{
037e8744 13691 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13692 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13693 /* Size field comes from bit mask. */
037e8744 13694 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
13695}
13696
13697static void
13698do_neon_fcmp_absolute_inv (void)
13699{
13700 neon_exchange_operands ();
13701 do_neon_fcmp_absolute ();
13702}
13703
13704static void
13705do_neon_step (void)
13706{
037e8744 13707 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 13708 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 13709 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13710}
13711
13712static void
13713do_neon_abs_neg (void)
13714{
037e8744
JB
13715 enum neon_shape rs;
13716 struct neon_type_el et;
5f4273c7 13717
037e8744
JB
13718 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13719 return;
13720
13721 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13722 return;
13723
13724 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13725 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 13726
5287ad62
JB
13727 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13728 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13729 inst.instruction |= LOW4 (inst.operands[1].reg);
13730 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13731 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13732 inst.instruction |= (et.type == NT_float) << 10;
13733 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13734
88714cb8 13735 neon_dp_fixup (&inst);
5287ad62
JB
13736}
13737
13738static void
13739do_neon_sli (void)
13740{
037e8744 13741 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13742 struct neon_type_el et = neon_check_type (2, rs,
13743 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13744 int imm = inst.operands[2].imm;
13745 constraint (imm < 0 || (unsigned)imm >= et.size,
13746 _("immediate out of range for insert"));
037e8744 13747 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13748}
13749
13750static void
13751do_neon_sri (void)
13752{
037e8744 13753 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13754 struct neon_type_el et = neon_check_type (2, rs,
13755 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13756 int imm = inst.operands[2].imm;
13757 constraint (imm < 1 || (unsigned)imm > et.size,
13758 _("immediate out of range for insert"));
037e8744 13759 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
13760}
13761
13762static void
13763do_neon_qshlu_imm (void)
13764{
037e8744 13765 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13766 struct neon_type_el et = neon_check_type (2, rs,
13767 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13768 int imm = inst.operands[2].imm;
13769 constraint (imm < 0 || (unsigned)imm >= et.size,
13770 _("immediate out of range for shift"));
13771 /* Only encodes the 'U present' variant of the instruction.
13772 In this case, signed types have OP (bit 8) set to 0.
13773 Unsigned types have OP set to 1. */
13774 inst.instruction |= (et.type == NT_unsigned) << 8;
13775 /* The rest of the bits are the same as other immediate shifts. */
037e8744 13776 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13777}
13778
13779static void
13780do_neon_qmovn (void)
13781{
13782 struct neon_type_el et = neon_check_type (2, NS_DQ,
13783 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13784 /* Saturating move where operands can be signed or unsigned, and the
13785 destination has the same signedness. */
88714cb8 13786 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13787 if (et.type == NT_unsigned)
13788 inst.instruction |= 0xc0;
13789 else
13790 inst.instruction |= 0x80;
13791 neon_two_same (0, 1, et.size / 2);
13792}
13793
13794static void
13795do_neon_qmovun (void)
13796{
13797 struct neon_type_el et = neon_check_type (2, NS_DQ,
13798 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13799 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 13800 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13801 neon_two_same (0, 1, et.size / 2);
13802}
13803
13804static void
13805do_neon_rshift_sat_narrow (void)
13806{
13807 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13808 or unsigned. If operands are unsigned, results must also be unsigned. */
13809 struct neon_type_el et = neon_check_type (2, NS_DQI,
13810 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13811 int imm = inst.operands[2].imm;
13812 /* This gets the bounds check, size encoding and immediate bits calculation
13813 right. */
13814 et.size /= 2;
5f4273c7 13815
5287ad62
JB
13816 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13817 VQMOVN.I<size> <Dd>, <Qm>. */
13818 if (imm == 0)
13819 {
13820 inst.operands[2].present = 0;
13821 inst.instruction = N_MNEM_vqmovn;
13822 do_neon_qmovn ();
13823 return;
13824 }
5f4273c7 13825
5287ad62
JB
13826 constraint (imm < 1 || (unsigned)imm > et.size,
13827 _("immediate out of range"));
13828 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13829}
13830
13831static void
13832do_neon_rshift_sat_narrow_u (void)
13833{
13834 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13835 or unsigned. If operands are unsigned, results must also be unsigned. */
13836 struct neon_type_el et = neon_check_type (2, NS_DQI,
13837 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13838 int imm = inst.operands[2].imm;
13839 /* This gets the bounds check, size encoding and immediate bits calculation
13840 right. */
13841 et.size /= 2;
13842
13843 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13844 VQMOVUN.I<size> <Dd>, <Qm>. */
13845 if (imm == 0)
13846 {
13847 inst.operands[2].present = 0;
13848 inst.instruction = N_MNEM_vqmovun;
13849 do_neon_qmovun ();
13850 return;
13851 }
13852
13853 constraint (imm < 1 || (unsigned)imm > et.size,
13854 _("immediate out of range"));
13855 /* FIXME: The manual is kind of unclear about what value U should have in
13856 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13857 must be 1. */
13858 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13859}
13860
13861static void
13862do_neon_movn (void)
13863{
13864 struct neon_type_el et = neon_check_type (2, NS_DQ,
13865 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 13866 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13867 neon_two_same (0, 1, et.size / 2);
13868}
13869
13870static void
13871do_neon_rshift_narrow (void)
13872{
13873 struct neon_type_el et = neon_check_type (2, NS_DQI,
13874 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13875 int imm = inst.operands[2].imm;
13876 /* This gets the bounds check, size encoding and immediate bits calculation
13877 right. */
13878 et.size /= 2;
5f4273c7 13879
5287ad62
JB
13880 /* If immediate is zero then we are a pseudo-instruction for
13881 VMOVN.I<size> <Dd>, <Qm> */
13882 if (imm == 0)
13883 {
13884 inst.operands[2].present = 0;
13885 inst.instruction = N_MNEM_vmovn;
13886 do_neon_movn ();
13887 return;
13888 }
5f4273c7 13889
5287ad62
JB
13890 constraint (imm < 1 || (unsigned)imm > et.size,
13891 _("immediate out of range for narrowing operation"));
13892 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13893}
13894
13895static void
13896do_neon_shll (void)
13897{
13898 /* FIXME: Type checking when lengthening. */
13899 struct neon_type_el et = neon_check_type (2, NS_QDI,
13900 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13901 unsigned imm = inst.operands[2].imm;
13902
13903 if (imm == et.size)
13904 {
13905 /* Maximum shift variant. */
88714cb8 13906 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13907 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13908 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13909 inst.instruction |= LOW4 (inst.operands[1].reg);
13910 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13911 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13912
88714cb8 13913 neon_dp_fixup (&inst);
5287ad62
JB
13914 }
13915 else
13916 {
13917 /* A more-specific type check for non-max versions. */
13918 et = neon_check_type (2, NS_QDI,
13919 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 13920 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13921 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13922 }
13923}
13924
037e8744 13925/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
13926 the current instruction is. */
13927
13928static int
13929neon_cvt_flavour (enum neon_shape rs)
13930{
037e8744
JB
13931#define CVT_VAR(C,X,Y) \
13932 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13933 if (et.type != NT_invtype) \
13934 { \
13935 inst.error = NULL; \
13936 return (C); \
5287ad62
JB
13937 }
13938 struct neon_type_el et;
037e8744
JB
13939 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13940 || rs == NS_FF) ? N_VFP : 0;
13941 /* The instruction versions which take an immediate take one register
13942 argument, which is extended to the width of the full register. Thus the
13943 "source" and "destination" registers must have the same width. Hack that
13944 here by making the size equal to the key (wider, in this case) operand. */
13945 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 13946
5287ad62
JB
13947 CVT_VAR (0, N_S32, N_F32);
13948 CVT_VAR (1, N_U32, N_F32);
13949 CVT_VAR (2, N_F32, N_S32);
13950 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
13951 /* Half-precision conversions. */
13952 CVT_VAR (4, N_F32, N_F16);
13953 CVT_VAR (5, N_F16, N_F32);
5f4273c7 13954
037e8744 13955 whole_reg = N_VFP;
5f4273c7 13956
037e8744 13957 /* VFP instructions. */
8e79c3df
CM
13958 CVT_VAR (6, N_F32, N_F64);
13959 CVT_VAR (7, N_F64, N_F32);
13960 CVT_VAR (8, N_S32, N_F64 | key);
13961 CVT_VAR (9, N_U32, N_F64 | key);
13962 CVT_VAR (10, N_F64 | key, N_S32);
13963 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 13964 /* VFP instructions with bitshift. */
8e79c3df
CM
13965 CVT_VAR (12, N_F32 | key, N_S16);
13966 CVT_VAR (13, N_F32 | key, N_U16);
13967 CVT_VAR (14, N_F64 | key, N_S16);
13968 CVT_VAR (15, N_F64 | key, N_U16);
13969 CVT_VAR (16, N_S16, N_F32 | key);
13970 CVT_VAR (17, N_U16, N_F32 | key);
13971 CVT_VAR (18, N_S16, N_F64 | key);
13972 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 13973
5287ad62
JB
13974 return -1;
13975#undef CVT_VAR
13976}
13977
037e8744
JB
13978/* Neon-syntax VFP conversions. */
13979
5287ad62 13980static void
037e8744 13981do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 13982{
037e8744 13983 const char *opname = 0;
5f4273c7 13984
037e8744 13985 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 13986 {
037e8744
JB
13987 /* Conversions with immediate bitshift. */
13988 const char *enc[] =
13989 {
13990 "ftosls",
13991 "ftouls",
13992 "fsltos",
13993 "fultos",
13994 NULL,
13995 NULL,
8e79c3df
CM
13996 NULL,
13997 NULL,
037e8744
JB
13998 "ftosld",
13999 "ftould",
14000 "fsltod",
14001 "fultod",
14002 "fshtos",
14003 "fuhtos",
14004 "fshtod",
14005 "fuhtod",
14006 "ftoshs",
14007 "ftouhs",
14008 "ftoshd",
14009 "ftouhd"
14010 };
14011
14012 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14013 {
14014 opname = enc[flavour];
14015 constraint (inst.operands[0].reg != inst.operands[1].reg,
14016 _("operands 0 and 1 must be the same register"));
14017 inst.operands[1] = inst.operands[2];
14018 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
14019 }
5287ad62
JB
14020 }
14021 else
14022 {
037e8744
JB
14023 /* Conversions without bitshift. */
14024 const char *enc[] =
14025 {
14026 "ftosis",
14027 "ftouis",
14028 "fsitos",
14029 "fuitos",
8e79c3df
CM
14030 "NULL",
14031 "NULL",
037e8744
JB
14032 "fcvtsd",
14033 "fcvtds",
14034 "ftosid",
14035 "ftouid",
14036 "fsitod",
14037 "fuitod"
14038 };
14039
14040 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14041 opname = enc[flavour];
14042 }
14043
14044 if (opname)
14045 do_vfp_nsyn_opcode (opname);
14046}
14047
14048static void
14049do_vfp_nsyn_cvtz (void)
14050{
14051 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
14052 int flavour = neon_cvt_flavour (rs);
14053 const char *enc[] =
14054 {
14055 "ftosizs",
14056 "ftouizs",
14057 NULL,
14058 NULL,
14059 NULL,
14060 NULL,
8e79c3df
CM
14061 NULL,
14062 NULL,
037e8744
JB
14063 "ftosizd",
14064 "ftouizd"
14065 };
14066
14067 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
14068 do_vfp_nsyn_opcode (enc[flavour]);
14069}
f31fef98 14070
037e8744 14071static void
e3e535bc 14072do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
037e8744
JB
14073{
14074 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 14075 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
14076 int flavour = neon_cvt_flavour (rs);
14077
e3e535bc
NC
14078 /* PR11109: Handle round-to-zero for VCVT conversions. */
14079 if (round_to_zero
14080 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
14081 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
14082 && (rs == NS_FD || rs == NS_FF))
14083 {
14084 do_vfp_nsyn_cvtz ();
14085 return;
14086 }
14087
037e8744 14088 /* VFP rather than Neon conversions. */
8e79c3df 14089 if (flavour >= 6)
037e8744
JB
14090 {
14091 do_vfp_nsyn_cvt (rs, flavour);
14092 return;
14093 }
14094
14095 switch (rs)
14096 {
14097 case NS_DDI:
14098 case NS_QQI:
14099 {
35997600
NC
14100 unsigned immbits;
14101 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
14102
037e8744
JB
14103 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14104 return;
14105
14106 /* Fixed-point conversion with #0 immediate is encoded as an
14107 integer conversion. */
14108 if (inst.operands[2].present && inst.operands[2].imm == 0)
14109 goto int_encode;
35997600 14110 immbits = 32 - inst.operands[2].imm;
88714cb8 14111 NEON_ENCODE (IMMED, inst);
037e8744
JB
14112 if (flavour != -1)
14113 inst.instruction |= enctab[flavour];
14114 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14115 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14116 inst.instruction |= LOW4 (inst.operands[1].reg);
14117 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14118 inst.instruction |= neon_quad (rs) << 6;
14119 inst.instruction |= 1 << 21;
14120 inst.instruction |= immbits << 16;
14121
88714cb8 14122 neon_dp_fixup (&inst);
037e8744
JB
14123 }
14124 break;
14125
14126 case NS_DD:
14127 case NS_QQ:
14128 int_encode:
14129 {
14130 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
14131
88714cb8 14132 NEON_ENCODE (INTEGER, inst);
037e8744
JB
14133
14134 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14135 return;
14136
14137 if (flavour != -1)
14138 inst.instruction |= enctab[flavour];
14139
14140 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14141 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14142 inst.instruction |= LOW4 (inst.operands[1].reg);
14143 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14144 inst.instruction |= neon_quad (rs) << 6;
14145 inst.instruction |= 2 << 18;
14146
88714cb8 14147 neon_dp_fixup (&inst);
037e8744
JB
14148 }
14149 break;
14150
8e79c3df
CM
14151 /* Half-precision conversions for Advanced SIMD -- neon. */
14152 case NS_QD:
14153 case NS_DQ:
14154
14155 if ((rs == NS_DQ)
14156 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14157 {
14158 as_bad (_("operand size must match register width"));
14159 break;
14160 }
14161
14162 if ((rs == NS_QD)
14163 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14164 {
14165 as_bad (_("operand size must match register width"));
14166 break;
14167 }
14168
14169 if (rs == NS_DQ)
14170 inst.instruction = 0x3b60600;
14171 else
14172 inst.instruction = 0x3b60700;
14173
14174 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14175 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14176 inst.instruction |= LOW4 (inst.operands[1].reg);
14177 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 14178 neon_dp_fixup (&inst);
8e79c3df
CM
14179 break;
14180
037e8744
JB
14181 default:
14182 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
14183 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 14184 }
5287ad62
JB
14185}
14186
e3e535bc
NC
14187static void
14188do_neon_cvtr (void)
14189{
14190 do_neon_cvt_1 (FALSE);
14191}
14192
14193static void
14194do_neon_cvt (void)
14195{
14196 do_neon_cvt_1 (TRUE);
14197}
14198
8e79c3df
CM
14199static void
14200do_neon_cvtb (void)
14201{
14202 inst.instruction = 0xeb20a40;
14203
14204 /* The sizes are attached to the mnemonic. */
14205 if (inst.vectype.el[0].type != NT_invtype
14206 && inst.vectype.el[0].size == 16)
14207 inst.instruction |= 0x00010000;
14208
14209 /* Programmer's syntax: the sizes are attached to the operands. */
14210 else if (inst.operands[0].vectype.type != NT_invtype
14211 && inst.operands[0].vectype.size == 16)
14212 inst.instruction |= 0x00010000;
14213
14214 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14215 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
14216 do_vfp_cond_or_thumb ();
14217}
14218
14219
14220static void
14221do_neon_cvtt (void)
14222{
14223 do_neon_cvtb ();
14224 inst.instruction |= 0x80;
14225}
14226
5287ad62
JB
14227static void
14228neon_move_immediate (void)
14229{
037e8744
JB
14230 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14231 struct neon_type_el et = neon_check_type (2, rs,
14232 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 14233 unsigned immlo, immhi = 0, immbits;
c96612cc 14234 int op, cmode, float_p;
5287ad62 14235
037e8744
JB
14236 constraint (et.type == NT_invtype,
14237 _("operand size must be specified for immediate VMOV"));
14238
5287ad62
JB
14239 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14240 op = (inst.instruction & (1 << 5)) != 0;
14241
14242 immlo = inst.operands[1].imm;
14243 if (inst.operands[1].regisimm)
14244 immhi = inst.operands[1].reg;
14245
14246 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14247 _("immediate has bits set outside the operand size"));
14248
c96612cc
JB
14249 float_p = inst.operands[1].immisfloat;
14250
14251 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 14252 et.size, et.type)) == FAIL)
5287ad62
JB
14253 {
14254 /* Invert relevant bits only. */
14255 neon_invert_size (&immlo, &immhi, et.size);
14256 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14257 with one or the other; those cases are caught by
14258 neon_cmode_for_move_imm. */
14259 op = !op;
c96612cc
JB
14260 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
14261 &op, et.size, et.type)) == FAIL)
5287ad62 14262 {
dcbf9037 14263 first_error (_("immediate out of range"));
5287ad62
JB
14264 return;
14265 }
14266 }
14267
14268 inst.instruction &= ~(1 << 5);
14269 inst.instruction |= op << 5;
14270
14271 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14272 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 14273 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14274 inst.instruction |= cmode << 8;
14275
14276 neon_write_immbits (immbits);
14277}
14278
14279static void
14280do_neon_mvn (void)
14281{
14282 if (inst.operands[1].isreg)
14283 {
037e8744 14284 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 14285
88714cb8 14286 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14287 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14288 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14289 inst.instruction |= LOW4 (inst.operands[1].reg);
14290 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14291 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14292 }
14293 else
14294 {
88714cb8 14295 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14296 neon_move_immediate ();
14297 }
14298
88714cb8 14299 neon_dp_fixup (&inst);
5287ad62
JB
14300}
14301
14302/* Encode instructions of form:
14303
14304 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 14305 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
14306
14307static void
14308neon_mixed_length (struct neon_type_el et, unsigned size)
14309{
14310 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14311 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14312 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14313 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14314 inst.instruction |= LOW4 (inst.operands[2].reg);
14315 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14316 inst.instruction |= (et.type == NT_unsigned) << 24;
14317 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14318
88714cb8 14319 neon_dp_fixup (&inst);
5287ad62
JB
14320}
14321
14322static void
14323do_neon_dyadic_long (void)
14324{
14325 /* FIXME: Type checking for lengthening op. */
14326 struct neon_type_el et = neon_check_type (3, NS_QDD,
14327 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14328 neon_mixed_length (et, et.size);
14329}
14330
14331static void
14332do_neon_abal (void)
14333{
14334 struct neon_type_el et = neon_check_type (3, NS_QDD,
14335 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14336 neon_mixed_length (et, et.size);
14337}
14338
14339static void
14340neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14341{
14342 if (inst.operands[2].isscalar)
14343 {
dcbf9037
JB
14344 struct neon_type_el et = neon_check_type (3, NS_QDS,
14345 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 14346 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14347 neon_mul_mac (et, et.type == NT_unsigned);
14348 }
14349 else
14350 {
14351 struct neon_type_el et = neon_check_type (3, NS_QDD,
14352 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 14353 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14354 neon_mixed_length (et, et.size);
14355 }
14356}
14357
14358static void
14359do_neon_mac_maybe_scalar_long (void)
14360{
14361 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14362}
14363
14364static void
14365do_neon_dyadic_wide (void)
14366{
14367 struct neon_type_el et = neon_check_type (3, NS_QQD,
14368 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14369 neon_mixed_length (et, et.size);
14370}
14371
14372static void
14373do_neon_dyadic_narrow (void)
14374{
14375 struct neon_type_el et = neon_check_type (3, NS_QDD,
14376 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
14377 /* Operand sign is unimportant, and the U bit is part of the opcode,
14378 so force the operand type to integer. */
14379 et.type = NT_integer;
5287ad62
JB
14380 neon_mixed_length (et, et.size / 2);
14381}
14382
14383static void
14384do_neon_mul_sat_scalar_long (void)
14385{
14386 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14387}
14388
14389static void
14390do_neon_vmull (void)
14391{
14392 if (inst.operands[2].isscalar)
14393 do_neon_mac_maybe_scalar_long ();
14394 else
14395 {
14396 struct neon_type_el et = neon_check_type (3, NS_QDD,
14397 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14398 if (et.type == NT_poly)
88714cb8 14399 NEON_ENCODE (POLY, inst);
5287ad62 14400 else
88714cb8 14401 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14402 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14403 zero. Should be OK as-is. */
14404 neon_mixed_length (et, et.size);
14405 }
14406}
14407
14408static void
14409do_neon_ext (void)
14410{
037e8744 14411 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
14412 struct neon_type_el et = neon_check_type (3, rs,
14413 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14414 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
14415
14416 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14417 _("shift out of range"));
5287ad62
JB
14418 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14419 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14420 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14421 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14422 inst.instruction |= LOW4 (inst.operands[2].reg);
14423 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 14424 inst.instruction |= neon_quad (rs) << 6;
5287ad62 14425 inst.instruction |= imm << 8;
5f4273c7 14426
88714cb8 14427 neon_dp_fixup (&inst);
5287ad62
JB
14428}
14429
14430static void
14431do_neon_rev (void)
14432{
037e8744 14433 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14434 struct neon_type_el et = neon_check_type (2, rs,
14435 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14436 unsigned op = (inst.instruction >> 7) & 3;
14437 /* N (width of reversed regions) is encoded as part of the bitmask. We
14438 extract it here to check the elements to be reversed are smaller.
14439 Otherwise we'd get a reserved instruction. */
14440 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 14441 gas_assert (elsize != 0);
5287ad62
JB
14442 constraint (et.size >= elsize,
14443 _("elements must be smaller than reversal region"));
037e8744 14444 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14445}
14446
14447static void
14448do_neon_dup (void)
14449{
14450 if (inst.operands[1].isscalar)
14451 {
037e8744 14452 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
14453 struct neon_type_el et = neon_check_type (2, rs,
14454 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 14455 unsigned sizebits = et.size >> 3;
dcbf9037 14456 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 14457 int logsize = neon_logbits (et.size);
dcbf9037 14458 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
14459
14460 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14461 return;
14462
88714cb8 14463 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14464 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14465 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14466 inst.instruction |= LOW4 (dm);
14467 inst.instruction |= HI1 (dm) << 5;
037e8744 14468 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14469 inst.instruction |= x << 17;
14470 inst.instruction |= sizebits << 16;
5f4273c7 14471
88714cb8 14472 neon_dp_fixup (&inst);
5287ad62
JB
14473 }
14474 else
14475 {
037e8744
JB
14476 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14477 struct neon_type_el et = neon_check_type (2, rs,
14478 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 14479 /* Duplicate ARM register to lanes of vector. */
88714cb8 14480 NEON_ENCODE (ARMREG, inst);
5287ad62
JB
14481 switch (et.size)
14482 {
14483 case 8: inst.instruction |= 0x400000; break;
14484 case 16: inst.instruction |= 0x000020; break;
14485 case 32: inst.instruction |= 0x000000; break;
14486 default: break;
14487 }
14488 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14489 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14490 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 14491 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
14492 /* The encoding for this instruction is identical for the ARM and Thumb
14493 variants, except for the condition field. */
037e8744 14494 do_vfp_cond_or_thumb ();
5287ad62
JB
14495 }
14496}
14497
14498/* VMOV has particularly many variations. It can be one of:
14499 0. VMOV<c><q> <Qd>, <Qm>
14500 1. VMOV<c><q> <Dd>, <Dm>
14501 (Register operations, which are VORR with Rm = Rn.)
14502 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14503 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14504 (Immediate loads.)
14505 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14506 (ARM register to scalar.)
14507 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14508 (Two ARM registers to vector.)
14509 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14510 (Scalar to ARM register.)
14511 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14512 (Vector to two ARM registers.)
037e8744
JB
14513 8. VMOV.F32 <Sd>, <Sm>
14514 9. VMOV.F64 <Dd>, <Dm>
14515 (VFP register moves.)
14516 10. VMOV.F32 <Sd>, #imm
14517 11. VMOV.F64 <Dd>, #imm
14518 (VFP float immediate load.)
14519 12. VMOV <Rd>, <Sm>
14520 (VFP single to ARM reg.)
14521 13. VMOV <Sd>, <Rm>
14522 (ARM reg to VFP single.)
14523 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14524 (Two ARM regs to two VFP singles.)
14525 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14526 (Two VFP singles to two ARM regs.)
5f4273c7 14527
037e8744
JB
14528 These cases can be disambiguated using neon_select_shape, except cases 1/9
14529 and 3/11 which depend on the operand type too.
5f4273c7 14530
5287ad62 14531 All the encoded bits are hardcoded by this function.
5f4273c7 14532
b7fc2769
JB
14533 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14534 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 14535
5287ad62 14536 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 14537 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
14538
14539static void
14540do_neon_mov (void)
14541{
037e8744
JB
14542 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14543 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14544 NS_NULL);
14545 struct neon_type_el et;
14546 const char *ldconst = 0;
5287ad62 14547
037e8744 14548 switch (rs)
5287ad62 14549 {
037e8744
JB
14550 case NS_DD: /* case 1/9. */
14551 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14552 /* It is not an error here if no type is given. */
14553 inst.error = NULL;
14554 if (et.type == NT_float && et.size == 64)
5287ad62 14555 {
037e8744
JB
14556 do_vfp_nsyn_opcode ("fcpyd");
14557 break;
5287ad62 14558 }
037e8744 14559 /* fall through. */
5287ad62 14560
037e8744
JB
14561 case NS_QQ: /* case 0/1. */
14562 {
14563 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14564 return;
14565 /* The architecture manual I have doesn't explicitly state which
14566 value the U bit should have for register->register moves, but
14567 the equivalent VORR instruction has U = 0, so do that. */
14568 inst.instruction = 0x0200110;
14569 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14570 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14571 inst.instruction |= LOW4 (inst.operands[1].reg);
14572 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14573 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14574 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14575 inst.instruction |= neon_quad (rs) << 6;
14576
88714cb8 14577 neon_dp_fixup (&inst);
037e8744
JB
14578 }
14579 break;
5f4273c7 14580
037e8744
JB
14581 case NS_DI: /* case 3/11. */
14582 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14583 inst.error = NULL;
14584 if (et.type == NT_float && et.size == 64)
5287ad62 14585 {
037e8744
JB
14586 /* case 11 (fconstd). */
14587 ldconst = "fconstd";
14588 goto encode_fconstd;
5287ad62 14589 }
037e8744
JB
14590 /* fall through. */
14591
14592 case NS_QI: /* case 2/3. */
14593 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14594 return;
14595 inst.instruction = 0x0800010;
14596 neon_move_immediate ();
88714cb8 14597 neon_dp_fixup (&inst);
5287ad62 14598 break;
5f4273c7 14599
037e8744
JB
14600 case NS_SR: /* case 4. */
14601 {
14602 unsigned bcdebits = 0;
91d6fa6a 14603 int logsize;
037e8744
JB
14604 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14605 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14606
91d6fa6a
NC
14607 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14608 logsize = neon_logbits (et.size);
14609
037e8744
JB
14610 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14611 _(BAD_FPU));
14612 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14613 && et.size != 32, _(BAD_FPU));
14614 constraint (et.type == NT_invtype, _("bad type for scalar"));
14615 constraint (x >= 64 / et.size, _("scalar index out of range"));
14616
14617 switch (et.size)
14618 {
14619 case 8: bcdebits = 0x8; break;
14620 case 16: bcdebits = 0x1; break;
14621 case 32: bcdebits = 0x0; break;
14622 default: ;
14623 }
14624
14625 bcdebits |= x << logsize;
14626
14627 inst.instruction = 0xe000b10;
14628 do_vfp_cond_or_thumb ();
14629 inst.instruction |= LOW4 (dn) << 16;
14630 inst.instruction |= HI1 (dn) << 7;
14631 inst.instruction |= inst.operands[1].reg << 12;
14632 inst.instruction |= (bcdebits & 3) << 5;
14633 inst.instruction |= (bcdebits >> 2) << 21;
14634 }
14635 break;
5f4273c7 14636
037e8744 14637 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 14638 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 14639 _(BAD_FPU));
b7fc2769 14640
037e8744
JB
14641 inst.instruction = 0xc400b10;
14642 do_vfp_cond_or_thumb ();
14643 inst.instruction |= LOW4 (inst.operands[0].reg);
14644 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14645 inst.instruction |= inst.operands[1].reg << 12;
14646 inst.instruction |= inst.operands[2].reg << 16;
14647 break;
5f4273c7 14648
037e8744
JB
14649 case NS_RS: /* case 6. */
14650 {
91d6fa6a 14651 unsigned logsize;
037e8744
JB
14652 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14653 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14654 unsigned abcdebits = 0;
14655
91d6fa6a
NC
14656 et = neon_check_type (2, NS_NULL,
14657 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14658 logsize = neon_logbits (et.size);
14659
037e8744
JB
14660 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14661 _(BAD_FPU));
14662 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14663 && et.size != 32, _(BAD_FPU));
14664 constraint (et.type == NT_invtype, _("bad type for scalar"));
14665 constraint (x >= 64 / et.size, _("scalar index out of range"));
14666
14667 switch (et.size)
14668 {
14669 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14670 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14671 case 32: abcdebits = 0x00; break;
14672 default: ;
14673 }
14674
14675 abcdebits |= x << logsize;
14676 inst.instruction = 0xe100b10;
14677 do_vfp_cond_or_thumb ();
14678 inst.instruction |= LOW4 (dn) << 16;
14679 inst.instruction |= HI1 (dn) << 7;
14680 inst.instruction |= inst.operands[0].reg << 12;
14681 inst.instruction |= (abcdebits & 3) << 5;
14682 inst.instruction |= (abcdebits >> 2) << 21;
14683 }
14684 break;
5f4273c7 14685
037e8744
JB
14686 case NS_RRD: /* case 7 (fmrrd). */
14687 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14688 _(BAD_FPU));
14689
14690 inst.instruction = 0xc500b10;
14691 do_vfp_cond_or_thumb ();
14692 inst.instruction |= inst.operands[0].reg << 12;
14693 inst.instruction |= inst.operands[1].reg << 16;
14694 inst.instruction |= LOW4 (inst.operands[2].reg);
14695 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14696 break;
5f4273c7 14697
037e8744
JB
14698 case NS_FF: /* case 8 (fcpys). */
14699 do_vfp_nsyn_opcode ("fcpys");
14700 break;
5f4273c7 14701
037e8744
JB
14702 case NS_FI: /* case 10 (fconsts). */
14703 ldconst = "fconsts";
14704 encode_fconstd:
14705 if (is_quarter_float (inst.operands[1].imm))
5287ad62 14706 {
037e8744
JB
14707 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14708 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
14709 }
14710 else
037e8744
JB
14711 first_error (_("immediate out of range"));
14712 break;
5f4273c7 14713
037e8744
JB
14714 case NS_RF: /* case 12 (fmrs). */
14715 do_vfp_nsyn_opcode ("fmrs");
14716 break;
5f4273c7 14717
037e8744
JB
14718 case NS_FR: /* case 13 (fmsr). */
14719 do_vfp_nsyn_opcode ("fmsr");
14720 break;
5f4273c7 14721
037e8744
JB
14722 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14723 (one of which is a list), but we have parsed four. Do some fiddling to
14724 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14725 expect. */
14726 case NS_RRFF: /* case 14 (fmrrs). */
14727 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14728 _("VFP registers must be adjacent"));
14729 inst.operands[2].imm = 2;
14730 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14731 do_vfp_nsyn_opcode ("fmrrs");
14732 break;
5f4273c7 14733
037e8744
JB
14734 case NS_FFRR: /* case 15 (fmsrr). */
14735 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14736 _("VFP registers must be adjacent"));
14737 inst.operands[1] = inst.operands[2];
14738 inst.operands[2] = inst.operands[3];
14739 inst.operands[0].imm = 2;
14740 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14741 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 14742 break;
5f4273c7 14743
5287ad62
JB
14744 default:
14745 abort ();
14746 }
14747}
14748
14749static void
14750do_neon_rshift_round_imm (void)
14751{
037e8744 14752 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14753 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14754 int imm = inst.operands[2].imm;
14755
14756 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14757 if (imm == 0)
14758 {
14759 inst.operands[2].present = 0;
14760 do_neon_mov ();
14761 return;
14762 }
14763
14764 constraint (imm < 1 || (unsigned)imm > et.size,
14765 _("immediate out of range for shift"));
037e8744 14766 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
14767 et.size - imm);
14768}
14769
14770static void
14771do_neon_movl (void)
14772{
14773 struct neon_type_el et = neon_check_type (2, NS_QD,
14774 N_EQK | N_DBL, N_SU_32 | N_KEY);
14775 unsigned sizebits = et.size >> 3;
14776 inst.instruction |= sizebits << 19;
14777 neon_two_same (0, et.type == NT_unsigned, -1);
14778}
14779
14780static void
14781do_neon_trn (void)
14782{
037e8744 14783 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14784 struct neon_type_el et = neon_check_type (2, rs,
14785 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 14786 NEON_ENCODE (INTEGER, inst);
037e8744 14787 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14788}
14789
14790static void
14791do_neon_zip_uzp (void)
14792{
037e8744 14793 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14794 struct neon_type_el et = neon_check_type (2, rs,
14795 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14796 if (rs == NS_DD && et.size == 32)
14797 {
14798 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14799 inst.instruction = N_MNEM_vtrn;
14800 do_neon_trn ();
14801 return;
14802 }
037e8744 14803 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14804}
14805
14806static void
14807do_neon_sat_abs_neg (void)
14808{
037e8744 14809 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14810 struct neon_type_el et = neon_check_type (2, rs,
14811 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14812 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14813}
14814
14815static void
14816do_neon_pair_long (void)
14817{
037e8744 14818 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14819 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14820 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14821 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 14822 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14823}
14824
14825static void
14826do_neon_recip_est (void)
14827{
037e8744 14828 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14829 struct neon_type_el et = neon_check_type (2, rs,
14830 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
14831 inst.instruction |= (et.type == NT_float) << 8;
037e8744 14832 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14833}
14834
14835static void
14836do_neon_cls (void)
14837{
037e8744 14838 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14839 struct neon_type_el et = neon_check_type (2, rs,
14840 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14841 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14842}
14843
14844static void
14845do_neon_clz (void)
14846{
037e8744 14847 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14848 struct neon_type_el et = neon_check_type (2, rs,
14849 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 14850 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14851}
14852
14853static void
14854do_neon_cnt (void)
14855{
037e8744 14856 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14857 struct neon_type_el et = neon_check_type (2, rs,
14858 N_EQK | N_INT, N_8 | N_KEY);
037e8744 14859 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14860}
14861
14862static void
14863do_neon_swp (void)
14864{
037e8744
JB
14865 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14866 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
14867}
14868
14869static void
14870do_neon_tbl_tbx (void)
14871{
14872 unsigned listlenbits;
dcbf9037 14873 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 14874
5287ad62
JB
14875 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14876 {
dcbf9037 14877 first_error (_("bad list length for table lookup"));
5287ad62
JB
14878 return;
14879 }
5f4273c7 14880
5287ad62
JB
14881 listlenbits = inst.operands[1].imm - 1;
14882 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14883 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14884 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14885 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14886 inst.instruction |= LOW4 (inst.operands[2].reg);
14887 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14888 inst.instruction |= listlenbits << 8;
5f4273c7 14889
88714cb8 14890 neon_dp_fixup (&inst);
5287ad62
JB
14891}
14892
14893static void
14894do_neon_ldm_stm (void)
14895{
14896 /* P, U and L bits are part of bitmask. */
14897 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14898 unsigned offsetbits = inst.operands[1].imm * 2;
14899
037e8744
JB
14900 if (inst.operands[1].issingle)
14901 {
14902 do_vfp_nsyn_ldm_stm (is_dbmode);
14903 return;
14904 }
14905
5287ad62
JB
14906 constraint (is_dbmode && !inst.operands[0].writeback,
14907 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14908
14909 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14910 _("register list must contain at least 1 and at most 16 "
14911 "registers"));
14912
14913 inst.instruction |= inst.operands[0].reg << 16;
14914 inst.instruction |= inst.operands[0].writeback << 21;
14915 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14916 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14917
14918 inst.instruction |= offsetbits;
5f4273c7 14919
037e8744 14920 do_vfp_cond_or_thumb ();
5287ad62
JB
14921}
14922
14923static void
14924do_neon_ldr_str (void)
14925{
5287ad62 14926 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 14927
6844b2c2
MGD
14928 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
14929 And is UNPREDICTABLE in thumb mode. */
14930 if (!is_ldr
14931 && inst.operands[1].reg == REG_PC
14932 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
14933 {
14934 if (!thumb_mode && warn_on_deprecated)
14935 as_warn (_("Use of PC here is deprecated"));
14936 else
14937 inst.error = _("Use of PC here is UNPREDICTABLE");
14938 }
14939
037e8744
JB
14940 if (inst.operands[0].issingle)
14941 {
cd2f129f
JB
14942 if (is_ldr)
14943 do_vfp_nsyn_opcode ("flds");
14944 else
14945 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
14946 }
14947 else
5287ad62 14948 {
cd2f129f
JB
14949 if (is_ldr)
14950 do_vfp_nsyn_opcode ("fldd");
5287ad62 14951 else
cd2f129f 14952 do_vfp_nsyn_opcode ("fstd");
5287ad62 14953 }
5287ad62
JB
14954}
14955
14956/* "interleave" version also handles non-interleaving register VLD1/VST1
14957 instructions. */
14958
14959static void
14960do_neon_ld_st_interleave (void)
14961{
037e8744 14962 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
14963 N_8 | N_16 | N_32 | N_64);
14964 unsigned alignbits = 0;
14965 unsigned idx;
14966 /* The bits in this table go:
14967 0: register stride of one (0) or two (1)
14968 1,2: register list length, minus one (1, 2, 3, 4).
14969 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14970 We use -1 for invalid entries. */
14971 const int typetable[] =
14972 {
14973 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14974 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14975 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14976 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14977 };
14978 int typebits;
14979
dcbf9037
JB
14980 if (et.type == NT_invtype)
14981 return;
14982
5287ad62
JB
14983 if (inst.operands[1].immisalign)
14984 switch (inst.operands[1].imm >> 8)
14985 {
14986 case 64: alignbits = 1; break;
14987 case 128:
e23c0ad8
JZ
14988 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
14989 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
14990 goto bad_alignment;
14991 alignbits = 2;
14992 break;
14993 case 256:
e23c0ad8 14994 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
14995 goto bad_alignment;
14996 alignbits = 3;
14997 break;
14998 default:
14999 bad_alignment:
dcbf9037 15000 first_error (_("bad alignment"));
5287ad62
JB
15001 return;
15002 }
15003
15004 inst.instruction |= alignbits << 4;
15005 inst.instruction |= neon_logbits (et.size) << 6;
15006
15007 /* Bits [4:6] of the immediate in a list specifier encode register stride
15008 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
15009 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
15010 up the right value for "type" in a table based on this value and the given
15011 list style, then stick it back. */
15012 idx = ((inst.operands[0].imm >> 4) & 7)
15013 | (((inst.instruction >> 8) & 3) << 3);
15014
15015 typebits = typetable[idx];
5f4273c7 15016
5287ad62
JB
15017 constraint (typebits == -1, _("bad list type for instruction"));
15018
15019 inst.instruction &= ~0xf00;
15020 inst.instruction |= typebits << 8;
15021}
15022
15023/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
15024 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
15025 otherwise. The variable arguments are a list of pairs of legal (size, align)
15026 values, terminated with -1. */
15027
15028static int
15029neon_alignment_bit (int size, int align, int *do_align, ...)
15030{
15031 va_list ap;
15032 int result = FAIL, thissize, thisalign;
5f4273c7 15033
5287ad62
JB
15034 if (!inst.operands[1].immisalign)
15035 {
15036 *do_align = 0;
15037 return SUCCESS;
15038 }
5f4273c7 15039
5287ad62
JB
15040 va_start (ap, do_align);
15041
15042 do
15043 {
15044 thissize = va_arg (ap, int);
15045 if (thissize == -1)
15046 break;
15047 thisalign = va_arg (ap, int);
15048
15049 if (size == thissize && align == thisalign)
15050 result = SUCCESS;
15051 }
15052 while (result != SUCCESS);
15053
15054 va_end (ap);
15055
15056 if (result == SUCCESS)
15057 *do_align = 1;
15058 else
dcbf9037 15059 first_error (_("unsupported alignment for instruction"));
5f4273c7 15060
5287ad62
JB
15061 return result;
15062}
15063
15064static void
15065do_neon_ld_st_lane (void)
15066{
037e8744 15067 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15068 int align_good, do_align = 0;
15069 int logsize = neon_logbits (et.size);
15070 int align = inst.operands[1].imm >> 8;
15071 int n = (inst.instruction >> 8) & 3;
15072 int max_el = 64 / et.size;
5f4273c7 15073
dcbf9037
JB
15074 if (et.type == NT_invtype)
15075 return;
5f4273c7 15076
5287ad62
JB
15077 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
15078 _("bad list length"));
15079 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
15080 _("scalar index out of range"));
15081 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
15082 && et.size == 8,
15083 _("stride of 2 unavailable when element size is 8"));
5f4273c7 15084
5287ad62
JB
15085 switch (n)
15086 {
15087 case 0: /* VLD1 / VST1. */
15088 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
15089 32, 32, -1);
15090 if (align_good == FAIL)
15091 return;
15092 if (do_align)
15093 {
15094 unsigned alignbits = 0;
15095 switch (et.size)
15096 {
15097 case 16: alignbits = 0x1; break;
15098 case 32: alignbits = 0x3; break;
15099 default: ;
15100 }
15101 inst.instruction |= alignbits << 4;
15102 }
15103 break;
15104
15105 case 1: /* VLD2 / VST2. */
15106 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
15107 32, 64, -1);
15108 if (align_good == FAIL)
15109 return;
15110 if (do_align)
15111 inst.instruction |= 1 << 4;
15112 break;
15113
15114 case 2: /* VLD3 / VST3. */
15115 constraint (inst.operands[1].immisalign,
15116 _("can't use alignment with this instruction"));
15117 break;
15118
15119 case 3: /* VLD4 / VST4. */
15120 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15121 16, 64, 32, 64, 32, 128, -1);
15122 if (align_good == FAIL)
15123 return;
15124 if (do_align)
15125 {
15126 unsigned alignbits = 0;
15127 switch (et.size)
15128 {
15129 case 8: alignbits = 0x1; break;
15130 case 16: alignbits = 0x1; break;
15131 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
15132 default: ;
15133 }
15134 inst.instruction |= alignbits << 4;
15135 }
15136 break;
15137
15138 default: ;
15139 }
15140
15141 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
15142 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15143 inst.instruction |= 1 << (4 + logsize);
5f4273c7 15144
5287ad62
JB
15145 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
15146 inst.instruction |= logsize << 10;
15147}
15148
15149/* Encode single n-element structure to all lanes VLD<n> instructions. */
15150
15151static void
15152do_neon_ld_dup (void)
15153{
037e8744 15154 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15155 int align_good, do_align = 0;
15156
dcbf9037
JB
15157 if (et.type == NT_invtype)
15158 return;
15159
5287ad62
JB
15160 switch ((inst.instruction >> 8) & 3)
15161 {
15162 case 0: /* VLD1. */
9c2799c2 15163 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
15164 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15165 &do_align, 16, 16, 32, 32, -1);
15166 if (align_good == FAIL)
15167 return;
15168 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15169 {
15170 case 1: break;
15171 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 15172 default: first_error (_("bad list length")); return;
5287ad62
JB
15173 }
15174 inst.instruction |= neon_logbits (et.size) << 6;
15175 break;
15176
15177 case 1: /* VLD2. */
15178 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15179 &do_align, 8, 16, 16, 32, 32, 64, -1);
15180 if (align_good == FAIL)
15181 return;
15182 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15183 _("bad list length"));
15184 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15185 inst.instruction |= 1 << 5;
15186 inst.instruction |= neon_logbits (et.size) << 6;
15187 break;
15188
15189 case 2: /* VLD3. */
15190 constraint (inst.operands[1].immisalign,
15191 _("can't use alignment with this instruction"));
15192 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15193 _("bad list length"));
15194 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15195 inst.instruction |= 1 << 5;
15196 inst.instruction |= neon_logbits (et.size) << 6;
15197 break;
15198
15199 case 3: /* VLD4. */
15200 {
15201 int align = inst.operands[1].imm >> 8;
15202 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15203 16, 64, 32, 64, 32, 128, -1);
15204 if (align_good == FAIL)
15205 return;
15206 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15207 _("bad list length"));
15208 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15209 inst.instruction |= 1 << 5;
15210 if (et.size == 32 && align == 128)
15211 inst.instruction |= 0x3 << 6;
15212 else
15213 inst.instruction |= neon_logbits (et.size) << 6;
15214 }
15215 break;
15216
15217 default: ;
15218 }
15219
15220 inst.instruction |= do_align << 4;
15221}
15222
15223/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15224 apart from bits [11:4]. */
15225
15226static void
15227do_neon_ldx_stx (void)
15228{
b1a769ed
DG
15229 if (inst.operands[1].isreg)
15230 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15231
5287ad62
JB
15232 switch (NEON_LANE (inst.operands[0].imm))
15233 {
15234 case NEON_INTERLEAVE_LANES:
88714cb8 15235 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
15236 do_neon_ld_st_interleave ();
15237 break;
5f4273c7 15238
5287ad62 15239 case NEON_ALL_LANES:
88714cb8 15240 NEON_ENCODE (DUP, inst);
5287ad62
JB
15241 do_neon_ld_dup ();
15242 break;
5f4273c7 15243
5287ad62 15244 default:
88714cb8 15245 NEON_ENCODE (LANE, inst);
5287ad62
JB
15246 do_neon_ld_st_lane ();
15247 }
15248
15249 /* L bit comes from bit mask. */
15250 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15251 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15252 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 15253
5287ad62
JB
15254 if (inst.operands[1].postind)
15255 {
15256 int postreg = inst.operands[1].imm & 0xf;
15257 constraint (!inst.operands[1].immisreg,
15258 _("post-index must be a register"));
15259 constraint (postreg == 0xd || postreg == 0xf,
15260 _("bad register for post-index"));
15261 inst.instruction |= postreg;
15262 }
15263 else if (inst.operands[1].writeback)
15264 {
15265 inst.instruction |= 0xd;
15266 }
15267 else
5f4273c7
NC
15268 inst.instruction |= 0xf;
15269
5287ad62
JB
15270 if (thumb_mode)
15271 inst.instruction |= 0xf9000000;
15272 else
15273 inst.instruction |= 0xf4000000;
15274}
5287ad62
JB
15275\f
15276/* Overall per-instruction processing. */
15277
15278/* We need to be able to fix up arbitrary expressions in some statements.
15279 This is so that we can handle symbols that are an arbitrary distance from
15280 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
15281 which returns part of an address in a form which will be valid for
15282 a data instruction. We do this by pushing the expression into a symbol
15283 in the expr_section, and creating a fix for that. */
15284
15285static void
15286fix_new_arm (fragS * frag,
15287 int where,
15288 short int size,
15289 expressionS * exp,
15290 int pc_rel,
15291 int reloc)
15292{
15293 fixS * new_fix;
15294
15295 switch (exp->X_op)
15296 {
15297 case O_constant:
15298 case O_symbol:
15299 case O_add:
15300 case O_subtract:
21d799b5
NC
15301 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
15302 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15303 break;
15304
15305 default:
21d799b5
NC
15306 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
15307 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15308 break;
15309 }
15310
15311 /* Mark whether the fix is to a THUMB instruction, or an ARM
15312 instruction. */
15313 new_fix->tc_fix_data = thumb_mode;
15314}
15315
15316/* Create a frg for an instruction requiring relaxation. */
15317static void
15318output_relax_insn (void)
15319{
15320 char * to;
15321 symbolS *sym;
0110f2b8
PB
15322 int offset;
15323
6e1cb1a6
PB
15324 /* The size of the instruction is unknown, so tie the debug info to the
15325 start of the instruction. */
15326 dwarf2_emit_insn (0);
6e1cb1a6 15327
0110f2b8
PB
15328 switch (inst.reloc.exp.X_op)
15329 {
15330 case O_symbol:
15331 sym = inst.reloc.exp.X_add_symbol;
15332 offset = inst.reloc.exp.X_add_number;
15333 break;
15334 case O_constant:
15335 sym = NULL;
15336 offset = inst.reloc.exp.X_add_number;
15337 break;
15338 default:
15339 sym = make_expr_symbol (&inst.reloc.exp);
15340 offset = 0;
15341 break;
15342 }
15343 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15344 inst.relax, sym, offset, NULL/*offset, opcode*/);
15345 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
15346}
15347
15348/* Write a 32-bit thumb instruction to buf. */
15349static void
15350put_thumb32_insn (char * buf, unsigned long insn)
15351{
15352 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15353 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15354}
15355
b99bd4ef 15356static void
c19d1205 15357output_inst (const char * str)
b99bd4ef 15358{
c19d1205 15359 char * to = NULL;
b99bd4ef 15360
c19d1205 15361 if (inst.error)
b99bd4ef 15362 {
c19d1205 15363 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
15364 return;
15365 }
5f4273c7
NC
15366 if (inst.relax)
15367 {
15368 output_relax_insn ();
0110f2b8 15369 return;
5f4273c7 15370 }
c19d1205
ZW
15371 if (inst.size == 0)
15372 return;
b99bd4ef 15373
c19d1205 15374 to = frag_more (inst.size);
8dc2430f
NC
15375 /* PR 9814: Record the thumb mode into the current frag so that we know
15376 what type of NOP padding to use, if necessary. We override any previous
15377 setting so that if the mode has changed then the NOPS that we use will
15378 match the encoding of the last instruction in the frag. */
cd000bff 15379 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
15380
15381 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 15382 {
9c2799c2 15383 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 15384 put_thumb32_insn (to, inst.instruction);
b99bd4ef 15385 }
c19d1205 15386 else if (inst.size > INSN_SIZE)
b99bd4ef 15387 {
9c2799c2 15388 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
15389 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15390 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 15391 }
c19d1205
ZW
15392 else
15393 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 15394
c19d1205
ZW
15395 if (inst.reloc.type != BFD_RELOC_UNUSED)
15396 fix_new_arm (frag_now, to - frag_now->fr_literal,
15397 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15398 inst.reloc.type);
b99bd4ef 15399
c19d1205 15400 dwarf2_emit_insn (inst.size);
c19d1205 15401}
b99bd4ef 15402
e07e6e58
NC
15403static char *
15404output_it_inst (int cond, int mask, char * to)
15405{
15406 unsigned long instruction = 0xbf00;
15407
15408 mask &= 0xf;
15409 instruction |= mask;
15410 instruction |= cond << 4;
15411
15412 if (to == NULL)
15413 {
15414 to = frag_more (2);
15415#ifdef OBJ_ELF
15416 dwarf2_emit_insn (2);
15417#endif
15418 }
15419
15420 md_number_to_chars (to, instruction, 2);
15421
15422 return to;
15423}
15424
c19d1205
ZW
15425/* Tag values used in struct asm_opcode's tag field. */
15426enum opcode_tag
15427{
15428 OT_unconditional, /* Instruction cannot be conditionalized.
15429 The ARM condition field is still 0xE. */
15430 OT_unconditionalF, /* Instruction cannot be conditionalized
15431 and carries 0xF in its ARM condition field. */
15432 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
15433 OT_csuffixF, /* Some forms of the instruction take a conditional
15434 suffix, others place 0xF where the condition field
15435 would be. */
c19d1205
ZW
15436 OT_cinfix3, /* Instruction takes a conditional infix,
15437 beginning at character index 3. (In
15438 unified mode, it becomes a suffix.) */
088fa78e
KH
15439 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15440 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
15441 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15442 character index 3, even in unified mode. Used for
15443 legacy instructions where suffix and infix forms
15444 may be ambiguous. */
c19d1205 15445 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 15446 suffix or an infix at character index 3. */
c19d1205
ZW
15447 OT_odd_infix_unc, /* This is the unconditional variant of an
15448 instruction that takes a conditional infix
15449 at an unusual position. In unified mode,
15450 this variant will accept a suffix. */
15451 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15452 are the conditional variants of instructions that
15453 take conditional infixes in unusual positions.
15454 The infix appears at character index
15455 (tag - OT_odd_infix_0). These are not accepted
15456 in unified mode. */
15457};
b99bd4ef 15458
c19d1205
ZW
15459/* Subroutine of md_assemble, responsible for looking up the primary
15460 opcode from the mnemonic the user wrote. STR points to the
15461 beginning of the mnemonic.
15462
15463 This is not simply a hash table lookup, because of conditional
15464 variants. Most instructions have conditional variants, which are
15465 expressed with a _conditional affix_ to the mnemonic. If we were
15466 to encode each conditional variant as a literal string in the opcode
15467 table, it would have approximately 20,000 entries.
15468
15469 Most mnemonics take this affix as a suffix, and in unified syntax,
15470 'most' is upgraded to 'all'. However, in the divided syntax, some
15471 instructions take the affix as an infix, notably the s-variants of
15472 the arithmetic instructions. Of those instructions, all but six
15473 have the infix appear after the third character of the mnemonic.
15474
15475 Accordingly, the algorithm for looking up primary opcodes given
15476 an identifier is:
15477
15478 1. Look up the identifier in the opcode table.
15479 If we find a match, go to step U.
15480
15481 2. Look up the last two characters of the identifier in the
15482 conditions table. If we find a match, look up the first N-2
15483 characters of the identifier in the opcode table. If we
15484 find a match, go to step CE.
15485
15486 3. Look up the fourth and fifth characters of the identifier in
15487 the conditions table. If we find a match, extract those
15488 characters from the identifier, and look up the remaining
15489 characters in the opcode table. If we find a match, go
15490 to step CM.
15491
15492 4. Fail.
15493
15494 U. Examine the tag field of the opcode structure, in case this is
15495 one of the six instructions with its conditional infix in an
15496 unusual place. If it is, the tag tells us where to find the
15497 infix; look it up in the conditions table and set inst.cond
15498 accordingly. Otherwise, this is an unconditional instruction.
15499 Again set inst.cond accordingly. Return the opcode structure.
15500
15501 CE. Examine the tag field to make sure this is an instruction that
15502 should receive a conditional suffix. If it is not, fail.
15503 Otherwise, set inst.cond from the suffix we already looked up,
15504 and return the opcode structure.
15505
15506 CM. Examine the tag field to make sure this is an instruction that
15507 should receive a conditional infix after the third character.
15508 If it is not, fail. Otherwise, undo the edits to the current
15509 line of input and proceed as for case CE. */
15510
15511static const struct asm_opcode *
15512opcode_lookup (char **str)
15513{
15514 char *end, *base;
15515 char *affix;
15516 const struct asm_opcode *opcode;
15517 const struct asm_cond *cond;
e3cb604e 15518 char save[2];
c19d1205
ZW
15519
15520 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 15521 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 15522 for (base = end = *str; *end != '\0'; end++)
721a8186 15523 if (*end == ' ' || *end == '.')
c19d1205 15524 break;
b99bd4ef 15525
c19d1205 15526 if (end == base)
c921be7d 15527 return NULL;
b99bd4ef 15528
5287ad62 15529 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 15530 if (end[0] == '.')
b99bd4ef 15531 {
5287ad62 15532 int offset = 2;
5f4273c7 15533
267d2029
JB
15534 /* The .w and .n suffixes are only valid if the unified syntax is in
15535 use. */
15536 if (unified_syntax && end[1] == 'w')
c19d1205 15537 inst.size_req = 4;
267d2029 15538 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
15539 inst.size_req = 2;
15540 else
5287ad62
JB
15541 offset = 0;
15542
15543 inst.vectype.elems = 0;
15544
15545 *str = end + offset;
b99bd4ef 15546
5f4273c7 15547 if (end[offset] == '.')
5287ad62 15548 {
267d2029
JB
15549 /* See if we have a Neon type suffix (possible in either unified or
15550 non-unified ARM syntax mode). */
dcbf9037 15551 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 15552 return NULL;
5287ad62
JB
15553 }
15554 else if (end[offset] != '\0' && end[offset] != ' ')
c921be7d 15555 return NULL;
b99bd4ef 15556 }
c19d1205
ZW
15557 else
15558 *str = end;
b99bd4ef 15559
c19d1205 15560 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5
NC
15561 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15562 end - base);
c19d1205 15563 if (opcode)
b99bd4ef 15564 {
c19d1205
ZW
15565 /* step U */
15566 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 15567 {
c19d1205
ZW
15568 inst.cond = COND_ALWAYS;
15569 return opcode;
b99bd4ef 15570 }
b99bd4ef 15571
278df34e 15572 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
15573 as_warn (_("conditional infixes are deprecated in unified syntax"));
15574 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 15575 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 15576 gas_assert (cond);
b99bd4ef 15577
c19d1205
ZW
15578 inst.cond = cond->value;
15579 return opcode;
15580 }
b99bd4ef 15581
c19d1205
ZW
15582 /* Cannot have a conditional suffix on a mnemonic of less than two
15583 characters. */
15584 if (end - base < 3)
c921be7d 15585 return NULL;
b99bd4ef 15586
c19d1205
ZW
15587 /* Look for suffixed mnemonic. */
15588 affix = end - 2;
21d799b5
NC
15589 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15590 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15591 affix - base);
c19d1205
ZW
15592 if (opcode && cond)
15593 {
15594 /* step CE */
15595 switch (opcode->tag)
15596 {
e3cb604e
PB
15597 case OT_cinfix3_legacy:
15598 /* Ignore conditional suffixes matched on infix only mnemonics. */
15599 break;
15600
c19d1205 15601 case OT_cinfix3:
088fa78e 15602 case OT_cinfix3_deprecated:
c19d1205
ZW
15603 case OT_odd_infix_unc:
15604 if (!unified_syntax)
e3cb604e 15605 return 0;
c19d1205
ZW
15606 /* else fall through */
15607
15608 case OT_csuffix:
037e8744 15609 case OT_csuffixF:
c19d1205
ZW
15610 case OT_csuf_or_in3:
15611 inst.cond = cond->value;
15612 return opcode;
15613
15614 case OT_unconditional:
15615 case OT_unconditionalF:
dfa9f0d5 15616 if (thumb_mode)
c921be7d 15617 inst.cond = cond->value;
dfa9f0d5
PB
15618 else
15619 {
c921be7d 15620 /* Delayed diagnostic. */
dfa9f0d5
PB
15621 inst.error = BAD_COND;
15622 inst.cond = COND_ALWAYS;
15623 }
c19d1205 15624 return opcode;
b99bd4ef 15625
c19d1205 15626 default:
c921be7d 15627 return NULL;
c19d1205
ZW
15628 }
15629 }
b99bd4ef 15630
c19d1205
ZW
15631 /* Cannot have a usual-position infix on a mnemonic of less than
15632 six characters (five would be a suffix). */
15633 if (end - base < 6)
c921be7d 15634 return NULL;
b99bd4ef 15635
c19d1205
ZW
15636 /* Look for infixed mnemonic in the usual position. */
15637 affix = base + 3;
21d799b5 15638 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 15639 if (!cond)
c921be7d 15640 return NULL;
e3cb604e
PB
15641
15642 memcpy (save, affix, 2);
15643 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5
NC
15644 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15645 (end - base) - 2);
e3cb604e
PB
15646 memmove (affix + 2, affix, (end - affix) - 2);
15647 memcpy (affix, save, 2);
15648
088fa78e
KH
15649 if (opcode
15650 && (opcode->tag == OT_cinfix3
15651 || opcode->tag == OT_cinfix3_deprecated
15652 || opcode->tag == OT_csuf_or_in3
15653 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 15654 {
c921be7d 15655 /* Step CM. */
278df34e 15656 if (warn_on_deprecated && unified_syntax
088fa78e
KH
15657 && (opcode->tag == OT_cinfix3
15658 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
15659 as_warn (_("conditional infixes are deprecated in unified syntax"));
15660
15661 inst.cond = cond->value;
15662 return opcode;
b99bd4ef
NC
15663 }
15664
c921be7d 15665 return NULL;
b99bd4ef
NC
15666}
15667
e07e6e58
NC
15668/* This function generates an initial IT instruction, leaving its block
15669 virtually open for the new instructions. Eventually,
15670 the mask will be updated by now_it_add_mask () each time
15671 a new instruction needs to be included in the IT block.
15672 Finally, the block is closed with close_automatic_it_block ().
15673 The block closure can be requested either from md_assemble (),
15674 a tencode (), or due to a label hook. */
15675
15676static void
15677new_automatic_it_block (int cond)
15678{
15679 now_it.state = AUTOMATIC_IT_BLOCK;
15680 now_it.mask = 0x18;
15681 now_it.cc = cond;
15682 now_it.block_length = 1;
cd000bff 15683 mapping_state (MAP_THUMB);
e07e6e58
NC
15684 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15685}
15686
15687/* Close an automatic IT block.
15688 See comments in new_automatic_it_block (). */
15689
15690static void
15691close_automatic_it_block (void)
15692{
15693 now_it.mask = 0x10;
15694 now_it.block_length = 0;
15695}
15696
15697/* Update the mask of the current automatically-generated IT
15698 instruction. See comments in new_automatic_it_block (). */
15699
15700static void
15701now_it_add_mask (int cond)
15702{
15703#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15704#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15705 | ((bitvalue) << (nbit)))
e07e6e58 15706 const int resulting_bit = (cond & 1);
c921be7d 15707
e07e6e58
NC
15708 now_it.mask &= 0xf;
15709 now_it.mask = SET_BIT_VALUE (now_it.mask,
15710 resulting_bit,
15711 (5 - now_it.block_length));
15712 now_it.mask = SET_BIT_VALUE (now_it.mask,
15713 1,
15714 ((5 - now_it.block_length) - 1) );
15715 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15716
15717#undef CLEAR_BIT
15718#undef SET_BIT_VALUE
e07e6e58
NC
15719}
15720
15721/* The IT blocks handling machinery is accessed through the these functions:
15722 it_fsm_pre_encode () from md_assemble ()
15723 set_it_insn_type () optional, from the tencode functions
15724 set_it_insn_type_last () ditto
15725 in_it_block () ditto
15726 it_fsm_post_encode () from md_assemble ()
15727 force_automatic_it_block_close () from label habdling functions
15728
15729 Rationale:
15730 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15731 initializing the IT insn type with a generic initial value depending
15732 on the inst.condition.
15733 2) During the tencode function, two things may happen:
15734 a) The tencode function overrides the IT insn type by
15735 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15736 b) The tencode function queries the IT block state by
15737 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15738
15739 Both set_it_insn_type and in_it_block run the internal FSM state
15740 handling function (handle_it_state), because: a) setting the IT insn
15741 type may incur in an invalid state (exiting the function),
15742 and b) querying the state requires the FSM to be updated.
15743 Specifically we want to avoid creating an IT block for conditional
15744 branches, so it_fsm_pre_encode is actually a guess and we can't
15745 determine whether an IT block is required until the tencode () routine
15746 has decided what type of instruction this actually it.
15747 Because of this, if set_it_insn_type and in_it_block have to be used,
15748 set_it_insn_type has to be called first.
15749
15750 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15751 determines the insn IT type depending on the inst.cond code.
15752 When a tencode () routine encodes an instruction that can be
15753 either outside an IT block, or, in the case of being inside, has to be
15754 the last one, set_it_insn_type_last () will determine the proper
15755 IT instruction type based on the inst.cond code. Otherwise,
15756 set_it_insn_type can be called for overriding that logic or
15757 for covering other cases.
15758
15759 Calling handle_it_state () may not transition the IT block state to
15760 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15761 still queried. Instead, if the FSM determines that the state should
15762 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15763 after the tencode () function: that's what it_fsm_post_encode () does.
15764
15765 Since in_it_block () calls the state handling function to get an
15766 updated state, an error may occur (due to invalid insns combination).
15767 In that case, inst.error is set.
15768 Therefore, inst.error has to be checked after the execution of
15769 the tencode () routine.
15770
15771 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15772 any pending state change (if any) that didn't take place in
15773 handle_it_state () as explained above. */
15774
15775static void
15776it_fsm_pre_encode (void)
15777{
15778 if (inst.cond != COND_ALWAYS)
15779 inst.it_insn_type = INSIDE_IT_INSN;
15780 else
15781 inst.it_insn_type = OUTSIDE_IT_INSN;
15782
15783 now_it.state_handled = 0;
15784}
15785
15786/* IT state FSM handling function. */
15787
15788static int
15789handle_it_state (void)
15790{
15791 now_it.state_handled = 1;
15792
15793 switch (now_it.state)
15794 {
15795 case OUTSIDE_IT_BLOCK:
15796 switch (inst.it_insn_type)
15797 {
15798 case OUTSIDE_IT_INSN:
15799 break;
15800
15801 case INSIDE_IT_INSN:
15802 case INSIDE_IT_LAST_INSN:
15803 if (thumb_mode == 0)
15804 {
c921be7d 15805 if (unified_syntax
e07e6e58
NC
15806 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15807 as_tsktsk (_("Warning: conditional outside an IT block"\
15808 " for Thumb."));
15809 }
15810 else
15811 {
15812 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15813 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15814 {
15815 /* Automatically generate the IT instruction. */
15816 new_automatic_it_block (inst.cond);
15817 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15818 close_automatic_it_block ();
15819 }
15820 else
15821 {
15822 inst.error = BAD_OUT_IT;
15823 return FAIL;
15824 }
15825 }
15826 break;
15827
15828 case IF_INSIDE_IT_LAST_INSN:
15829 case NEUTRAL_IT_INSN:
15830 break;
15831
15832 case IT_INSN:
15833 now_it.state = MANUAL_IT_BLOCK;
15834 now_it.block_length = 0;
15835 break;
15836 }
15837 break;
15838
15839 case AUTOMATIC_IT_BLOCK:
15840 /* Three things may happen now:
15841 a) We should increment current it block size;
15842 b) We should close current it block (closing insn or 4 insns);
15843 c) We should close current it block and start a new one (due
15844 to incompatible conditions or
15845 4 insns-length block reached). */
15846
15847 switch (inst.it_insn_type)
15848 {
15849 case OUTSIDE_IT_INSN:
15850 /* The closure of the block shall happen immediatelly,
15851 so any in_it_block () call reports the block as closed. */
15852 force_automatic_it_block_close ();
15853 break;
15854
15855 case INSIDE_IT_INSN:
15856 case INSIDE_IT_LAST_INSN:
15857 case IF_INSIDE_IT_LAST_INSN:
15858 now_it.block_length++;
15859
15860 if (now_it.block_length > 4
15861 || !now_it_compatible (inst.cond))
15862 {
15863 force_automatic_it_block_close ();
15864 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15865 new_automatic_it_block (inst.cond);
15866 }
15867 else
15868 {
15869 now_it_add_mask (inst.cond);
15870 }
15871
15872 if (now_it.state == AUTOMATIC_IT_BLOCK
15873 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15874 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15875 close_automatic_it_block ();
15876 break;
15877
15878 case NEUTRAL_IT_INSN:
15879 now_it.block_length++;
15880
15881 if (now_it.block_length > 4)
15882 force_automatic_it_block_close ();
15883 else
15884 now_it_add_mask (now_it.cc & 1);
15885 break;
15886
15887 case IT_INSN:
15888 close_automatic_it_block ();
15889 now_it.state = MANUAL_IT_BLOCK;
15890 break;
15891 }
15892 break;
15893
15894 case MANUAL_IT_BLOCK:
15895 {
15896 /* Check conditional suffixes. */
15897 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15898 int is_last;
15899 now_it.mask <<= 1;
15900 now_it.mask &= 0x1f;
15901 is_last = (now_it.mask == 0x10);
15902
15903 switch (inst.it_insn_type)
15904 {
15905 case OUTSIDE_IT_INSN:
15906 inst.error = BAD_NOT_IT;
15907 return FAIL;
15908
15909 case INSIDE_IT_INSN:
15910 if (cond != inst.cond)
15911 {
15912 inst.error = BAD_IT_COND;
15913 return FAIL;
15914 }
15915 break;
15916
15917 case INSIDE_IT_LAST_INSN:
15918 case IF_INSIDE_IT_LAST_INSN:
15919 if (cond != inst.cond)
15920 {
15921 inst.error = BAD_IT_COND;
15922 return FAIL;
15923 }
15924 if (!is_last)
15925 {
15926 inst.error = BAD_BRANCH;
15927 return FAIL;
15928 }
15929 break;
15930
15931 case NEUTRAL_IT_INSN:
15932 /* The BKPT instruction is unconditional even in an IT block. */
15933 break;
15934
15935 case IT_INSN:
15936 inst.error = BAD_IT_IT;
15937 return FAIL;
15938 }
15939 }
15940 break;
15941 }
15942
15943 return SUCCESS;
15944}
15945
15946static void
15947it_fsm_post_encode (void)
15948{
15949 int is_last;
15950
15951 if (!now_it.state_handled)
15952 handle_it_state ();
15953
15954 is_last = (now_it.mask == 0x10);
15955 if (is_last)
15956 {
15957 now_it.state = OUTSIDE_IT_BLOCK;
15958 now_it.mask = 0;
15959 }
15960}
15961
15962static void
15963force_automatic_it_block_close (void)
15964{
15965 if (now_it.state == AUTOMATIC_IT_BLOCK)
15966 {
15967 close_automatic_it_block ();
15968 now_it.state = OUTSIDE_IT_BLOCK;
15969 now_it.mask = 0;
15970 }
15971}
15972
15973static int
15974in_it_block (void)
15975{
15976 if (!now_it.state_handled)
15977 handle_it_state ();
15978
15979 return now_it.state != OUTSIDE_IT_BLOCK;
15980}
15981
c19d1205
ZW
15982void
15983md_assemble (char *str)
b99bd4ef 15984{
c19d1205
ZW
15985 char *p = str;
15986 const struct asm_opcode * opcode;
b99bd4ef 15987
c19d1205
ZW
15988 /* Align the previous label if needed. */
15989 if (last_label_seen != NULL)
b99bd4ef 15990 {
c19d1205
ZW
15991 symbol_set_frag (last_label_seen, frag_now);
15992 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15993 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
15994 }
15995
c19d1205
ZW
15996 memset (&inst, '\0', sizeof (inst));
15997 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 15998
c19d1205
ZW
15999 opcode = opcode_lookup (&p);
16000 if (!opcode)
b99bd4ef 16001 {
c19d1205 16002 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 16003 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d
NC
16004 if (! create_register_alias (str, p)
16005 && ! create_neon_reg_alias (str, p))
c19d1205 16006 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 16007
b99bd4ef
NC
16008 return;
16009 }
16010
278df34e 16011 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
16012 as_warn (_("s suffix on comparison instruction is deprecated"));
16013
037e8744
JB
16014 /* The value which unconditional instructions should have in place of the
16015 condition field. */
16016 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
16017
c19d1205 16018 if (thumb_mode)
b99bd4ef 16019 {
e74cfd16 16020 arm_feature_set variant;
8f06b2d8
PB
16021
16022 variant = cpu_variant;
16023 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
16024 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
16025 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 16026 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
16027 if (!opcode->tvariant
16028 || (thumb_mode == 1
16029 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 16030 {
bf3eeda7 16031 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
b99bd4ef
NC
16032 return;
16033 }
c19d1205
ZW
16034 if (inst.cond != COND_ALWAYS && !unified_syntax
16035 && opcode->tencode != do_t_branch)
b99bd4ef 16036 {
c19d1205 16037 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
16038 return;
16039 }
16040
752d5da4 16041 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 16042 {
7e806470 16043 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
16044 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
16045 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
16046 {
16047 /* Two things are addressed here.
16048 1) Implicit require narrow instructions on Thumb-1.
16049 This avoids relaxation accidentally introducing Thumb-2
16050 instructions.
16051 2) Reject wide instructions in non Thumb-2 cores. */
16052 if (inst.size_req == 0)
16053 inst.size_req = 2;
16054 else if (inst.size_req == 4)
16055 {
bf3eeda7 16056 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
752d5da4
NC
16057 return;
16058 }
16059 }
076d447c
PB
16060 }
16061
c19d1205
ZW
16062 inst.instruction = opcode->tvalue;
16063
5be8be5d 16064 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
e07e6e58
NC
16065 {
16066 /* Prepare the it_insn_type for those encodings that don't set
16067 it. */
16068 it_fsm_pre_encode ();
c19d1205 16069
e07e6e58
NC
16070 opcode->tencode ();
16071
16072 it_fsm_post_encode ();
16073 }
e27ec89e 16074
0110f2b8 16075 if (!(inst.error || inst.relax))
b99bd4ef 16076 {
9c2799c2 16077 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
16078 inst.size = (inst.instruction > 0xffff ? 4 : 2);
16079 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 16080 {
c19d1205 16081 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
16082 return;
16083 }
16084 }
076d447c
PB
16085
16086 /* Something has gone badly wrong if we try to relax a fixed size
16087 instruction. */
9c2799c2 16088 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 16089
e74cfd16
PB
16090 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16091 *opcode->tvariant);
ee065d83 16092 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 16093 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 16094 anything other than bl/blx and v6-M instructions.
ee065d83 16095 This is overly pessimistic for relaxable instructions. */
7e806470
PB
16096 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
16097 || inst.relax)
e07e6e58
NC
16098 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
16099 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
16100 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16101 arm_ext_v6t2);
cd000bff 16102
88714cb8
DG
16103 check_neon_suffixes;
16104
cd000bff 16105 if (!inst.error)
c877a2f2
NC
16106 {
16107 mapping_state (MAP_THUMB);
16108 }
c19d1205 16109 }
3e9e4fcf 16110 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 16111 {
845b51d6
PB
16112 bfd_boolean is_bx;
16113
16114 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
16115 is_bx = (opcode->aencode == do_bx);
16116
c19d1205 16117 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
16118 if (!(is_bx && fix_v4bx)
16119 && !(opcode->avariant &&
16120 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 16121 {
bf3eeda7 16122 as_bad (_("selected processor does not support ARM mode `%s'"), str);
c19d1205 16123 return;
b99bd4ef 16124 }
c19d1205 16125 if (inst.size_req)
b99bd4ef 16126 {
c19d1205
ZW
16127 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
16128 return;
b99bd4ef
NC
16129 }
16130
c19d1205
ZW
16131 inst.instruction = opcode->avalue;
16132 if (opcode->tag == OT_unconditionalF)
16133 inst.instruction |= 0xF << 28;
16134 else
16135 inst.instruction |= inst.cond << 28;
16136 inst.size = INSN_SIZE;
5be8be5d 16137 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
e07e6e58
NC
16138 {
16139 it_fsm_pre_encode ();
16140 opcode->aencode ();
16141 it_fsm_post_encode ();
16142 }
ee065d83
PB
16143 /* Arm mode bx is marked as both v4T and v5 because it's still required
16144 on a hypothetical non-thumb v5 core. */
845b51d6 16145 if (is_bx)
e74cfd16 16146 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 16147 else
e74cfd16
PB
16148 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
16149 *opcode->avariant);
88714cb8
DG
16150
16151 check_neon_suffixes;
16152
cd000bff 16153 if (!inst.error)
c877a2f2
NC
16154 {
16155 mapping_state (MAP_ARM);
16156 }
b99bd4ef 16157 }
3e9e4fcf
JB
16158 else
16159 {
16160 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
16161 "-- `%s'"), str);
16162 return;
16163 }
c19d1205
ZW
16164 output_inst (str);
16165}
b99bd4ef 16166
e07e6e58
NC
16167static void
16168check_it_blocks_finished (void)
16169{
16170#ifdef OBJ_ELF
16171 asection *sect;
16172
16173 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
16174 if (seg_info (sect)->tc_segment_info_data.current_it.state
16175 == MANUAL_IT_BLOCK)
16176 {
16177 as_warn (_("section '%s' finished with an open IT block."),
16178 sect->name);
16179 }
16180#else
16181 if (now_it.state == MANUAL_IT_BLOCK)
16182 as_warn (_("file finished with an open IT block."));
16183#endif
16184}
16185
c19d1205
ZW
16186/* Various frobbings of labels and their addresses. */
16187
16188void
16189arm_start_line_hook (void)
16190{
16191 last_label_seen = NULL;
b99bd4ef
NC
16192}
16193
c19d1205
ZW
16194void
16195arm_frob_label (symbolS * sym)
b99bd4ef 16196{
c19d1205 16197 last_label_seen = sym;
b99bd4ef 16198
c19d1205 16199 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 16200
c19d1205
ZW
16201#if defined OBJ_COFF || defined OBJ_ELF
16202 ARM_SET_INTERWORK (sym, support_interwork);
16203#endif
b99bd4ef 16204
e07e6e58
NC
16205 force_automatic_it_block_close ();
16206
5f4273c7 16207 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
16208 as Thumb functions. This is because these labels, whilst
16209 they exist inside Thumb code, are not the entry points for
16210 possible ARM->Thumb calls. Also, these labels can be used
16211 as part of a computed goto or switch statement. eg gcc
16212 can generate code that looks like this:
b99bd4ef 16213
c19d1205
ZW
16214 ldr r2, [pc, .Laaa]
16215 lsl r3, r3, #2
16216 ldr r2, [r3, r2]
16217 mov pc, r2
b99bd4ef 16218
c19d1205
ZW
16219 .Lbbb: .word .Lxxx
16220 .Lccc: .word .Lyyy
16221 ..etc...
16222 .Laaa: .word Lbbb
b99bd4ef 16223
c19d1205
ZW
16224 The first instruction loads the address of the jump table.
16225 The second instruction converts a table index into a byte offset.
16226 The third instruction gets the jump address out of the table.
16227 The fourth instruction performs the jump.
b99bd4ef 16228
c19d1205
ZW
16229 If the address stored at .Laaa is that of a symbol which has the
16230 Thumb_Func bit set, then the linker will arrange for this address
16231 to have the bottom bit set, which in turn would mean that the
16232 address computation performed by the third instruction would end
16233 up with the bottom bit set. Since the ARM is capable of unaligned
16234 word loads, the instruction would then load the incorrect address
16235 out of the jump table, and chaos would ensue. */
16236 if (label_is_thumb_function_name
16237 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
16238 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 16239 {
c19d1205
ZW
16240 /* When the address of a Thumb function is taken the bottom
16241 bit of that address should be set. This will allow
16242 interworking between Arm and Thumb functions to work
16243 correctly. */
b99bd4ef 16244
c19d1205 16245 THUMB_SET_FUNC (sym, 1);
b99bd4ef 16246
c19d1205 16247 label_is_thumb_function_name = FALSE;
b99bd4ef 16248 }
07a53e5c 16249
07a53e5c 16250 dwarf2_emit_label (sym);
b99bd4ef
NC
16251}
16252
c921be7d 16253bfd_boolean
c19d1205 16254arm_data_in_code (void)
b99bd4ef 16255{
c19d1205 16256 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 16257 {
c19d1205
ZW
16258 *input_line_pointer = '/';
16259 input_line_pointer += 5;
16260 *input_line_pointer = 0;
c921be7d 16261 return TRUE;
b99bd4ef
NC
16262 }
16263
c921be7d 16264 return FALSE;
b99bd4ef
NC
16265}
16266
c19d1205
ZW
16267char *
16268arm_canonicalize_symbol_name (char * name)
b99bd4ef 16269{
c19d1205 16270 int len;
b99bd4ef 16271
c19d1205
ZW
16272 if (thumb_mode && (len = strlen (name)) > 5
16273 && streq (name + len - 5, "/data"))
16274 *(name + len - 5) = 0;
b99bd4ef 16275
c19d1205 16276 return name;
b99bd4ef 16277}
c19d1205
ZW
16278\f
16279/* Table of all register names defined by default. The user can
16280 define additional names with .req. Note that all register names
16281 should appear in both upper and lowercase variants. Some registers
16282 also have mixed-case names. */
b99bd4ef 16283
dcbf9037 16284#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 16285#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 16286#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
16287#define REGSET(p,t) \
16288 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
16289 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
16290 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
16291 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
16292#define REGSETH(p,t) \
16293 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
16294 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
16295 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
16296 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
16297#define REGSET2(p,t) \
16298 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
16299 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
16300 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
16301 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
16302#define SPLRBANK(base,bank,t) \
16303 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
16304 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
16305 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
16306 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
16307 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
16308 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 16309
c19d1205 16310static const struct reg_entry reg_names[] =
7ed4c4c5 16311{
c19d1205
ZW
16312 /* ARM integer registers. */
16313 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 16314
c19d1205
ZW
16315 /* ATPCS synonyms. */
16316 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
16317 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16318 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 16319
c19d1205
ZW
16320 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16321 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16322 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 16323
c19d1205
ZW
16324 /* Well-known aliases. */
16325 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16326 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16327
16328 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16329 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16330
16331 /* Coprocessor numbers. */
16332 REGSET(p, CP), REGSET(P, CP),
16333
16334 /* Coprocessor register numbers. The "cr" variants are for backward
16335 compatibility. */
16336 REGSET(c, CN), REGSET(C, CN),
16337 REGSET(cr, CN), REGSET(CR, CN),
16338
90ec0d68
MGD
16339 /* ARM banked registers. */
16340 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
16341 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
16342 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
16343 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
16344 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
16345 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
16346 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
16347
16348 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
16349 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
16350 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
16351 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
16352 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
16353 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB),
16354 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
16355 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
16356
16357 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
16358 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
16359 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
16360 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
16361 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
16362 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
16363 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
16364 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
16365 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
16366
c19d1205
ZW
16367 /* FPA registers. */
16368 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16369 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16370
16371 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16372 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16373
16374 /* VFP SP registers. */
5287ad62
JB
16375 REGSET(s,VFS), REGSET(S,VFS),
16376 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
16377
16378 /* VFP DP Registers. */
5287ad62
JB
16379 REGSET(d,VFD), REGSET(D,VFD),
16380 /* Extra Neon DP registers. */
16381 REGSETH(d,VFD), REGSETH(D,VFD),
16382
16383 /* Neon QP registers. */
16384 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
16385
16386 /* VFP control registers. */
16387 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16388 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
16389 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16390 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16391 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16392 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
16393
16394 /* Maverick DSP coprocessor registers. */
16395 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16396 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16397
16398 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16399 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16400 REGDEF(dspsc,0,DSPSC),
16401
16402 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16403 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16404 REGDEF(DSPSC,0,DSPSC),
16405
16406 /* iWMMXt data registers - p0, c0-15. */
16407 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16408
16409 /* iWMMXt control registers - p1, c0-3. */
16410 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16411 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16412 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16413 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16414
16415 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16416 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16417 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16418 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16419 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16420
16421 /* XScale accumulator registers. */
16422 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16423};
16424#undef REGDEF
16425#undef REGNUM
16426#undef REGSET
7ed4c4c5 16427
c19d1205
ZW
16428/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16429 within psr_required_here. */
16430static const struct asm_psr psrs[] =
16431{
16432 /* Backward compatibility notation. Note that "all" is no longer
16433 truly all possible PSR bits. */
16434 {"all", PSR_c | PSR_f},
16435 {"flg", PSR_f},
16436 {"ctl", PSR_c},
16437
16438 /* Individual flags. */
16439 {"f", PSR_f},
16440 {"c", PSR_c},
16441 {"x", PSR_x},
16442 {"s", PSR_s},
59b42a0d
MGD
16443 {"g", PSR_s},
16444
c19d1205
ZW
16445 /* Combinations of flags. */
16446 {"fs", PSR_f | PSR_s},
16447 {"fx", PSR_f | PSR_x},
16448 {"fc", PSR_f | PSR_c},
16449 {"sf", PSR_s | PSR_f},
16450 {"sx", PSR_s | PSR_x},
16451 {"sc", PSR_s | PSR_c},
16452 {"xf", PSR_x | PSR_f},
16453 {"xs", PSR_x | PSR_s},
16454 {"xc", PSR_x | PSR_c},
16455 {"cf", PSR_c | PSR_f},
16456 {"cs", PSR_c | PSR_s},
16457 {"cx", PSR_c | PSR_x},
16458 {"fsx", PSR_f | PSR_s | PSR_x},
16459 {"fsc", PSR_f | PSR_s | PSR_c},
16460 {"fxs", PSR_f | PSR_x | PSR_s},
16461 {"fxc", PSR_f | PSR_x | PSR_c},
16462 {"fcs", PSR_f | PSR_c | PSR_s},
16463 {"fcx", PSR_f | PSR_c | PSR_x},
16464 {"sfx", PSR_s | PSR_f | PSR_x},
16465 {"sfc", PSR_s | PSR_f | PSR_c},
16466 {"sxf", PSR_s | PSR_x | PSR_f},
16467 {"sxc", PSR_s | PSR_x | PSR_c},
16468 {"scf", PSR_s | PSR_c | PSR_f},
16469 {"scx", PSR_s | PSR_c | PSR_x},
16470 {"xfs", PSR_x | PSR_f | PSR_s},
16471 {"xfc", PSR_x | PSR_f | PSR_c},
16472 {"xsf", PSR_x | PSR_s | PSR_f},
16473 {"xsc", PSR_x | PSR_s | PSR_c},
16474 {"xcf", PSR_x | PSR_c | PSR_f},
16475 {"xcs", PSR_x | PSR_c | PSR_s},
16476 {"cfs", PSR_c | PSR_f | PSR_s},
16477 {"cfx", PSR_c | PSR_f | PSR_x},
16478 {"csf", PSR_c | PSR_s | PSR_f},
16479 {"csx", PSR_c | PSR_s | PSR_x},
16480 {"cxf", PSR_c | PSR_x | PSR_f},
16481 {"cxs", PSR_c | PSR_x | PSR_s},
16482 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16483 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16484 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16485 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16486 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16487 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16488 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16489 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16490 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16491 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16492 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16493 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16494 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16495 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16496 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16497 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16498 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16499 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16500 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16501 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16502 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16503 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16504 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16505 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
59b42a0d
MGD
16506
16507 /* APSR flags */
16508 {"nzcvq", PSR_f},
16509 {"nzcvqg", PSR_s | PSR_f}
c19d1205
ZW
16510};
16511
62b3e311
PB
16512/* Table of V7M psr names. */
16513static const struct asm_psr v7m_psrs[] =
16514{
2b744c99
PB
16515 {"apsr", 0 }, {"APSR", 0 },
16516 {"iapsr", 1 }, {"IAPSR", 1 },
16517 {"eapsr", 2 }, {"EAPSR", 2 },
16518 {"psr", 3 }, {"PSR", 3 },
16519 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16520 {"ipsr", 5 }, {"IPSR", 5 },
16521 {"epsr", 6 }, {"EPSR", 6 },
16522 {"iepsr", 7 }, {"IEPSR", 7 },
16523 {"msp", 8 }, {"MSP", 8 },
16524 {"psp", 9 }, {"PSP", 9 },
16525 {"primask", 16}, {"PRIMASK", 16},
16526 {"basepri", 17}, {"BASEPRI", 17},
16527 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16528 {"faultmask", 19}, {"FAULTMASK", 19},
16529 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
16530};
16531
c19d1205
ZW
16532/* Table of all shift-in-operand names. */
16533static const struct asm_shift_name shift_names [] =
b99bd4ef 16534{
c19d1205
ZW
16535 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16536 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16537 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16538 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16539 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16540 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16541};
b99bd4ef 16542
c19d1205
ZW
16543/* Table of all explicit relocation names. */
16544#ifdef OBJ_ELF
16545static struct reloc_entry reloc_names[] =
16546{
16547 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16548 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16549 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16550 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16551 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16552 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16553 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16554 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16555 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16556 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 16557 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
16558 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
16559 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
16560 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
16561 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
16562 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
16563 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
16564 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
16565};
16566#endif
b99bd4ef 16567
c19d1205
ZW
16568/* Table of all conditional affixes. 0xF is not defined as a condition code. */
16569static const struct asm_cond conds[] =
16570{
16571 {"eq", 0x0},
16572 {"ne", 0x1},
16573 {"cs", 0x2}, {"hs", 0x2},
16574 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16575 {"mi", 0x4},
16576 {"pl", 0x5},
16577 {"vs", 0x6},
16578 {"vc", 0x7},
16579 {"hi", 0x8},
16580 {"ls", 0x9},
16581 {"ge", 0xa},
16582 {"lt", 0xb},
16583 {"gt", 0xc},
16584 {"le", 0xd},
16585 {"al", 0xe}
16586};
bfae80f2 16587
62b3e311
PB
16588static struct asm_barrier_opt barrier_opt_names[] =
16589{
52e7f43d
RE
16590 { "sy", 0xf }, { "SY", 0xf },
16591 { "un", 0x7 }, { "UN", 0x7 },
16592 { "st", 0xe }, { "ST", 0xe },
16593 { "unst", 0x6 }, { "UNST", 0x6 },
16594 { "ish", 0xb }, { "ISH", 0xb },
16595 { "sh", 0xb }, { "SH", 0xb },
16596 { "ishst", 0xa }, { "ISHST", 0xa },
16597 { "shst", 0xa }, { "SHST", 0xa },
16598 { "nsh", 0x7 }, { "NSH", 0x7 },
16599 { "nshst", 0x6 }, { "NSHST", 0x6 },
16600 { "osh", 0x3 }, { "OSH", 0x3 },
16601 { "oshst", 0x2 }, { "OSHST", 0x2 }
62b3e311
PB
16602};
16603
c19d1205
ZW
16604/* Table of ARM-format instructions. */
16605
16606/* Macros for gluing together operand strings. N.B. In all cases
16607 other than OPS0, the trailing OP_stop comes from default
16608 zero-initialization of the unspecified elements of the array. */
16609#define OPS0() { OP_stop, }
16610#define OPS1(a) { OP_##a, }
16611#define OPS2(a,b) { OP_##a,OP_##b, }
16612#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16613#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16614#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16615#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16616
5be8be5d
DG
16617/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16618 This is useful when mixing operands for ARM and THUMB, i.e. using the
16619 MIX_ARM_THUMB_OPERANDS macro.
16620 In order to use these macros, prefix the number of operands with _
16621 e.g. _3. */
16622#define OPS_1(a) { a, }
16623#define OPS_2(a,b) { a,b, }
16624#define OPS_3(a,b,c) { a,b,c, }
16625#define OPS_4(a,b,c,d) { a,b,c,d, }
16626#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16627#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16628
c19d1205
ZW
16629/* These macros abstract out the exact format of the mnemonic table and
16630 save some repeated characters. */
16631
16632/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16633#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16634 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 16635 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16636
16637/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16638 a T_MNEM_xyz enumerator. */
16639#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16640 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16641#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16642 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16643
16644/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16645 infix after the third character. */
16646#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 16647 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 16648 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 16649#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 16650 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 16651 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 16652#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16653 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 16654#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16655 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16656#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16657 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 16658#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16659 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16660
16661/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16662 appear in the condition table. */
16663#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
21d799b5 16664 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
1887dd22 16665 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16666
16667#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
16668 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16669 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16670 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16671 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16672 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16673 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16674 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16675 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16676 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16677 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16678 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16679 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16680 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16681 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16682 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16683 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16684 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16685 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16686 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
16687
16688#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
16689 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16690#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
21d799b5 16691 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16692
16693/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
16694 field is still 0xE. Many of the Thumb variants can be executed
16695 conditionally, so this is checked separately. */
c19d1205 16696#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16697 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16698 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16699
16700/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16701 condition code field. */
16702#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 16703 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16704 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16705
16706/* ARM-only variants of all the above. */
6a86118a 16707#define CE(mnem, op, nops, ops, ae) \
21d799b5 16708 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
16709
16710#define C3(mnem, op, nops, ops, ae) \
16711 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16712
e3cb604e
PB
16713/* Legacy mnemonics that always have conditional infix after the third
16714 character. */
16715#define CL(mnem, op, nops, ops, ae) \
21d799b5 16716 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16717 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16718
8f06b2d8
PB
16719/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16720#define cCE(mnem, op, nops, ops, ae) \
21d799b5 16721 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16722
e3cb604e
PB
16723/* Legacy coprocessor instructions where conditional infix and conditional
16724 suffix are ambiguous. For consistency this includes all FPA instructions,
16725 not just the potentially ambiguous ones. */
16726#define cCL(mnem, op, nops, ops, ae) \
21d799b5 16727 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16728 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16729
16730/* Coprocessor, takes either a suffix or a position-3 infix
16731 (for an FPA corner case). */
16732#define C3E(mnem, op, nops, ops, ae) \
21d799b5 16733 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 16734 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16735
6a86118a 16736#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
16737 { m1 #m2 m3, OPS##nops ops, \
16738 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
16739 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16740
16741#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
16742 xCM_ (m1, , m2, op, nops, ops, ae), \
16743 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16744 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16745 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16746 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16747 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16748 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16749 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16750 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16751 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16752 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16753 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16754 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16755 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16756 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16757 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16758 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16759 xCM_ (m1, le, m2, op, nops, ops, ae), \
16760 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
16761
16762#define UE(mnem, op, nops, ops, ae) \
16763 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16764
16765#define UF(mnem, op, nops, ops, ae) \
16766 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16767
5287ad62
JB
16768/* Neon data-processing. ARM versions are unconditional with cond=0xf.
16769 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16770 use the same encoding function for each. */
16771#define NUF(mnem, op, nops, ops, enc) \
16772 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16773 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16774
16775/* Neon data processing, version which indirects through neon_enc_tab for
16776 the various overloaded versions of opcodes. */
16777#define nUF(mnem, op, nops, ops, enc) \
21d799b5 16778 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16779 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16780
16781/* Neon insn with conditional suffix for the ARM version, non-overloaded
16782 version. */
037e8744
JB
16783#define NCE_tag(mnem, op, nops, ops, enc, tag) \
16784 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
16785 THUMB_VARIANT, do_##enc, do_##enc }
16786
037e8744 16787#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 16788 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16789
16790#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 16791 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16792
5287ad62 16793/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 16794#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 16795 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16796 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16797
037e8744 16798#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 16799 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16800
16801#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 16802 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16803
c19d1205
ZW
16804#define do_0 0
16805
c19d1205 16806static const struct asm_opcode insns[] =
bfae80f2 16807{
e74cfd16
PB
16808#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
16809#define THUMB_VARIANT &arm_ext_v4t
21d799b5
NC
16810 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
16811 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
16812 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
16813 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
16814 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
16815 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
16816 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
16817 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
16818 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
16819 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
16820 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
16821 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
16822 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
16823 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
16824 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
16825 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
16826
16827 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
16828 for setting PSR flag bits. They are obsolete in V6 and do not
16829 have Thumb equivalents. */
21d799b5
NC
16830 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16831 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16832 CL("tstp", 110f000, 2, (RR, SH), cmp),
16833 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16834 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16835 CL("cmpp", 150f000, 2, (RR, SH), cmp),
16836 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16837 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16838 CL("cmnp", 170f000, 2, (RR, SH), cmp),
16839
16840 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
16841 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
16842 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
16843 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
16844
16845 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
16846 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16847 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
16848 OP_RRnpc),
16849 OP_ADDRGLDR),ldst, t_ldst),
16850 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
16851
16852 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16853 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16854 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16855 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16856 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16857 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16858
16859 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
16860 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
16861 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
16862 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 16863
c19d1205 16864 /* Pseudo ops. */
21d799b5 16865 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 16866 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 16867 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
16868
16869 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
16870 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
16871 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
16872 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
16873 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
16874 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
16875 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
16876 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
16877 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
16878 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
16879 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
16880 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
16881 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 16882
16a4cf17 16883 /* These may simplify to neg. */
21d799b5
NC
16884 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
16885 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 16886
c921be7d
NC
16887#undef THUMB_VARIANT
16888#define THUMB_VARIANT & arm_ext_v6
16889
21d799b5 16890 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
16891
16892 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
16893#undef THUMB_VARIANT
16894#define THUMB_VARIANT & arm_ext_v6t2
16895
21d799b5
NC
16896 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16897 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16898 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 16899
5be8be5d
DG
16900 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16901 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16902 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
16903 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 16904
21d799b5
NC
16905 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16906 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 16907
21d799b5
NC
16908 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16909 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
16910
16911 /* V1 instructions with no Thumb analogue at all. */
21d799b5 16912 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
16913 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16914
16915 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16916 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16917 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16918 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16919 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16920 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16921 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16922 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16923
c921be7d
NC
16924#undef ARM_VARIANT
16925#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
16926#undef THUMB_VARIANT
16927#define THUMB_VARIANT & arm_ext_v4t
16928
21d799b5
NC
16929 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16930 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 16931
c921be7d
NC
16932#undef THUMB_VARIANT
16933#define THUMB_VARIANT & arm_ext_v6t2
16934
21d799b5 16935 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
16936 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16937
16938 /* Generic coprocessor instructions. */
21d799b5
NC
16939 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16940 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16941 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16942 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16943 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16944 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 16945 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16946
c921be7d
NC
16947#undef ARM_VARIANT
16948#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
16949
21d799b5 16950 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
16951 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16952
c921be7d
NC
16953#undef ARM_VARIANT
16954#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
16955#undef THUMB_VARIANT
16956#define THUMB_VARIANT & arm_ext_msr
16957
90ec0d68 16958 TCE("mrs", 1000000, f3e08000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
21d799b5 16959 TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205 16960
c921be7d
NC
16961#undef ARM_VARIANT
16962#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
16963#undef THUMB_VARIANT
16964#define THUMB_VARIANT & arm_ext_v6t2
16965
21d799b5
NC
16966 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16967 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16968 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16969 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16970 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16971 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16972 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16973 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 16974
c921be7d
NC
16975#undef ARM_VARIANT
16976#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
16977#undef THUMB_VARIANT
16978#define THUMB_VARIANT & arm_ext_v4t
16979
5be8be5d
DG
16980 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16981 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16982 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16983 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16984 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16985 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 16986
c921be7d
NC
16987#undef ARM_VARIANT
16988#define ARM_VARIANT & arm_ext_v4t_5
16989
c19d1205
ZW
16990 /* ARM Architecture 4T. */
16991 /* Note: bx (and blx) are required on V5, even if the processor does
16992 not support Thumb. */
21d799b5 16993 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 16994
c921be7d
NC
16995#undef ARM_VARIANT
16996#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
16997#undef THUMB_VARIANT
16998#define THUMB_VARIANT & arm_ext_v5t
16999
c19d1205
ZW
17000 /* Note: blx has 2 variants; the .value coded here is for
17001 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
17002 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
17003 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 17004
c921be7d
NC
17005#undef THUMB_VARIANT
17006#define THUMB_VARIANT & arm_ext_v6t2
17007
21d799b5
NC
17008 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
17009 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17010 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17011 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17012 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17013 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17014 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17015 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 17016
c921be7d
NC
17017#undef ARM_VARIANT
17018#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
9e3c6df6
PB
17019#undef THUMB_VARIANT
17020#define THUMB_VARIANT &arm_ext_v5exp
c921be7d 17021
21d799b5
NC
17022 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17023 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17024 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17025 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 17026
21d799b5
NC
17027 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17028 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 17029
21d799b5
NC
17030 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17031 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17032 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17033 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 17034
21d799b5
NC
17035 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17036 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17037 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17038 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 17039
21d799b5
NC
17040 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17041 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 17042
03ee1b7f
NC
17043 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17044 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17045 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17046 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 17047
c921be7d
NC
17048#undef ARM_VARIANT
17049#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
9e3c6df6
PB
17050#undef THUMB_VARIANT
17051#define THUMB_VARIANT &arm_ext_v6t2
c921be7d 17052
21d799b5 17053 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
17054 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
17055 ldrd, t_ldstd),
17056 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
17057 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 17058
21d799b5
NC
17059 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17060 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 17061
c921be7d
NC
17062#undef ARM_VARIANT
17063#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
17064
21d799b5 17065 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 17066
c921be7d
NC
17067#undef ARM_VARIANT
17068#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
17069#undef THUMB_VARIANT
17070#define THUMB_VARIANT & arm_ext_v6
17071
21d799b5
NC
17072 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
17073 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
17074 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17075 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17076 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17077 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17078 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17079 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17080 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17081 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 17082
c921be7d
NC
17083#undef THUMB_VARIANT
17084#define THUMB_VARIANT & arm_ext_v6t2
17085
5be8be5d
DG
17086 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
17087 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17088 strex, t_strex),
21d799b5
NC
17089 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17090 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 17091
21d799b5
NC
17092 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
17093 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 17094
9e3c6df6 17095/* ARM V6 not included in V7M. */
c921be7d
NC
17096#undef THUMB_VARIANT
17097#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6
PB
17098 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17099 UF(rfeib, 9900a00, 1, (RRw), rfe),
17100 UF(rfeda, 8100a00, 1, (RRw), rfe),
17101 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17102 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17103 UF(rfefa, 9900a00, 1, (RRw), rfe),
17104 UF(rfeea, 8100a00, 1, (RRw), rfe),
17105 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17106 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
17107 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
17108 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
17109 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 17110
9e3c6df6
PB
17111/* ARM V6 not included in V7M (eg. integer SIMD). */
17112#undef THUMB_VARIANT
17113#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
17114 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
17115 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
17116 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
17117 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17118 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17119 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17120 /* Old name for QASX. */
21d799b5
NC
17121 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17122 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17123 /* Old name for QSAX. */
21d799b5
NC
17124 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17125 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17126 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17127 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17128 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17129 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17130 /* Old name for SASX. */
21d799b5
NC
17131 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17132 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17133 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17134 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17135 /* Old name for SHASX. */
21d799b5
NC
17136 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17137 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17138 /* Old name for SHSAX. */
21d799b5
NC
17139 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17140 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17141 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17142 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17143 /* Old name for SSAX. */
21d799b5
NC
17144 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17145 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17146 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17147 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17148 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17149 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17150 /* Old name for UASX. */
21d799b5
NC
17151 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17152 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17153 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17154 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17155 /* Old name for UHASX. */
21d799b5
NC
17156 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17157 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17158 /* Old name for UHSAX. */
21d799b5
NC
17159 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17160 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17161 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17162 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17163 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17164 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17165 /* Old name for UQASX. */
21d799b5
NC
17166 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17167 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17168 /* Old name for UQSAX. */
21d799b5
NC
17169 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17170 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17171 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17172 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17173 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17174 /* Old name for USAX. */
21d799b5
NC
17175 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17176 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
17177 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17178 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17179 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17180 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17181 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17182 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17183 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17184 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17185 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17186 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17187 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17188 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17189 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17190 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17191 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17192 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17193 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17194 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17195 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17196 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17197 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17198 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17199 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17200 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17201 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17202 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17203 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
17204 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
17205 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
17206 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17207 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17208 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 17209
c921be7d
NC
17210#undef ARM_VARIANT
17211#define ARM_VARIANT & arm_ext_v6k
17212#undef THUMB_VARIANT
17213#define THUMB_VARIANT & arm_ext_v6k
17214
21d799b5
NC
17215 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
17216 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
17217 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
17218 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 17219
c921be7d
NC
17220#undef THUMB_VARIANT
17221#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
17222 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
17223 ldrexd, t_ldrexd),
17224 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
17225 RRnpcb), strexd, t_strexd),
ebdca51a 17226
c921be7d
NC
17227#undef THUMB_VARIANT
17228#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
17229 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
17230 rd_rn, rd_rn),
17231 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
17232 rd_rn, rd_rn),
17233 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17234 strex, rm_rd_rn),
17235 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17236 strex, rm_rd_rn),
21d799b5 17237 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 17238
c921be7d 17239#undef ARM_VARIANT
f4c65163
MGD
17240#define ARM_VARIANT & arm_ext_sec
17241#undef THUMB_VARIANT
17242#define THUMB_VARIANT & arm_ext_sec
c921be7d 17243
21d799b5 17244 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 17245
90ec0d68
MGD
17246#undef ARM_VARIANT
17247#define ARM_VARIANT & arm_ext_virt
17248#undef THUMB_VARIANT
17249#define THUMB_VARIANT & arm_ext_virt
17250
17251 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
17252 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
17253
c921be7d
NC
17254#undef ARM_VARIANT
17255#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
17256#undef THUMB_VARIANT
17257#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 17258
21d799b5
NC
17259 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
17260 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
17261 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17262 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 17263
21d799b5
NC
17264 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17265 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
17266 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
17267 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 17268
5be8be5d
DG
17269 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17270 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17271 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17272 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 17273
bf3eeda7
NS
17274 /* Thumb-only instructions. */
17275#undef ARM_VARIANT
17276#define ARM_VARIANT NULL
17277 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
17278 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
17279
17280 /* ARM does not really have an IT instruction, so always allow it.
17281 The opcode is copied from Thumb in order to allow warnings in
17282 -mimplicit-it=[never | arm] modes. */
17283#undef ARM_VARIANT
17284#define ARM_VARIANT & arm_ext_v1
17285
21d799b5
NC
17286 TUE("it", bf08, bf08, 1, (COND), it, t_it),
17287 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
17288 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
17289 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
17290 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
17291 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
17292 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
17293 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
17294 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
17295 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
17296 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
17297 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
17298 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
17299 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
17300 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 17301 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
17302 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
17303 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 17304
92e90b6e 17305 /* Thumb2 only instructions. */
c921be7d
NC
17306#undef ARM_VARIANT
17307#define ARM_VARIANT NULL
92e90b6e 17308
21d799b5
NC
17309 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17310 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17311 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
17312 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
17313 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
17314 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 17315
eea54501
MGD
17316 /* Hardware division instructions. */
17317#undef ARM_VARIANT
17318#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
17319#undef THUMB_VARIANT
17320#define THUMB_VARIANT & arm_ext_div
17321
eea54501
MGD
17322 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
17323 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 17324
7e806470 17325 /* ARM V6M/V7 instructions. */
c921be7d
NC
17326#undef ARM_VARIANT
17327#define ARM_VARIANT & arm_ext_barrier
17328#undef THUMB_VARIANT
17329#define THUMB_VARIANT & arm_ext_barrier
17330
52e7f43d
RE
17331 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
17332 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
17333 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
7e806470 17334
62b3e311 17335 /* ARM V7 instructions. */
c921be7d
NC
17336#undef ARM_VARIANT
17337#define ARM_VARIANT & arm_ext_v7
17338#undef THUMB_VARIANT
17339#define THUMB_VARIANT & arm_ext_v7
17340
21d799b5
NC
17341 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
17342 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 17343
60e5ef9f
MGD
17344#undef ARM_VARIANT
17345#define ARM_VARIANT & arm_ext_mp
17346#undef THUMB_VARIANT
17347#define THUMB_VARIANT & arm_ext_mp
17348
17349 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
17350
c921be7d
NC
17351#undef ARM_VARIANT
17352#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
17353
21d799b5
NC
17354 cCE("wfs", e200110, 1, (RR), rd),
17355 cCE("rfs", e300110, 1, (RR), rd),
17356 cCE("wfc", e400110, 1, (RR), rd),
17357 cCE("rfc", e500110, 1, (RR), rd),
17358
17359 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
17360 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
17361 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
17362 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
17363
17364 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
17365 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
17366 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
17367 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
17368
17369 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
17370 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
17371 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
17372 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
17373 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
17374 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
17375 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
17376 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
17377 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
17378 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
17379 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
17380 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
17381
17382 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
17383 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
17384 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
17385 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
17386 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17387 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17388 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17389 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17390 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17391 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17392 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17393 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17394
17395 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17396 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17397 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17398 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17399 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17400 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17401 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17402 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17403 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17404 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17405 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17406 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17407
17408 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17409 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17410 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17411 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17412 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17413 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17414 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17415 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17416 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17417 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17418 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17419 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17420
17421 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17422 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17423 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17424 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17425 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17426 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17427 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17428 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17429 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17430 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17431 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17432 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17433
17434 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17435 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17436 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17437 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17438 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17439 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17440 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17441 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17442 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17443 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17444 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17445 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17446
17447 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17448 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17449 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17450 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17451 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17452 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17453 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17454 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17455 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17456 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17457 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17458 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17459
17460 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17461 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17462 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17463 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17464 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17465 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17466 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17467 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17468 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17469 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17470 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17471 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17472
17473 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17474 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17475 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17476 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17477 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17478 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17479 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17480 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17481 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17482 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17483 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17484 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17485
17486 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17487 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17488 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17489 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17490 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17491 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17492 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17493 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17494 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17495 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17496 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17497 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17498
17499 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17500 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17501 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17502 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17503 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17504 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17505 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17506 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17507 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17508 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17509 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17510 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17511
17512 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17513 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17514 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17515 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17516 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17517 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17518 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17519 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17520 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17521 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17522 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17523 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17524
17525 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17526 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17527 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17528 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17529 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17530 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17531 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17532 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17533 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17534 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17535 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17536 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17537
17538 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17539 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17540 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17541 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17542 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17543 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17544 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17545 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17546 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17547 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17548 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17549 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17550
17551 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17552 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17553 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17554 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17555 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17556 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17557 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17558 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17559 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17560 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17561 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17562 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17563
17564 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17565 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17566 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17567 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17568 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17569 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17570 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17571 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17572 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17573 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17574 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17575 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17576
17577 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17578 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17579 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17580 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17581 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17582 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17583 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17584 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17585 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17586 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17587 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17588 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17589
17590 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17591 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17592 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17593 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17594 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17595 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17596 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17597 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17598 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17599 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17600 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17601 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17602
17603 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17604 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17605 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17606 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17607 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17608 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17609 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17610 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17611 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17612 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17613 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17614 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17615
17616 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17617 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17618 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17619 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17620 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17621 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17622 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17623 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17624 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17625 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17626 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17627 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17628
17629 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17630 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17631 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17632 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17633 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17634 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17635 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17636 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17637 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17638 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17639 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17640 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17641
17642 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17643 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17644 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17645 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17646 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17647 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17648 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17649 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17650 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17651 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17652 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17653 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17654
17655 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17656 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17657 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17658 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17659 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17660 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17661 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17662 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17663 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17664 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17665 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17666 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17667
17668 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17669 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17670 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17671 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17672 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17673 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17674 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17675 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17676 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17677 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17678 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17679 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17680
17681 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17682 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17683 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17684 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17685 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17686 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17687 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17688 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17689 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17690 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17691 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17692 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17693
17694 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17695 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17696 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17697 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17698 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17699 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17700 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17701 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17702 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17703 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17704 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17705 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17706
17707 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17708 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17709 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17710 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17711 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17712 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17713 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17714 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17715 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17716 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17717 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17718 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17719
17720 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17721 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17722 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17723 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17724 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17725 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17726 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17727 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17728 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17729 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17730 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17731 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17732
17733 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17734 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17735 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17736 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17737 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17738 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17739 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17740 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17741 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17742 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17743 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17744 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17745
17746 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17747 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17748 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17749 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17750
17751 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17752 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17753 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17754 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17755 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17756 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17757 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17758 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17759 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17760 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17761 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17762 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 17763
c19d1205
ZW
17764 /* The implementation of the FIX instruction is broken on some
17765 assemblers, in that it accepts a precision specifier as well as a
17766 rounding specifier, despite the fact that this is meaningless.
17767 To be more compatible, we accept it as well, though of course it
17768 does not set any bits. */
21d799b5
NC
17769 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17770 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17771 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17772 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17773 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17774 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17775 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17776 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17777 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17778 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17779 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17780 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17781 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 17782
c19d1205 17783 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
17784#undef ARM_VARIANT
17785#define ARM_VARIANT & fpu_fpa_ext_v2
17786
21d799b5
NC
17787 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17788 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17789 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17790 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17791 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17792 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 17793
c921be7d
NC
17794#undef ARM_VARIANT
17795#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
17796
c19d1205 17797 /* Moves and type conversions. */
21d799b5
NC
17798 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
17799 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
17800 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
17801 cCE("fmstat", ef1fa10, 0, (), noargs),
f7c21dc7
NC
17802 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
17803 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
21d799b5
NC
17804 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
17805 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
17806 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
17807 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17808 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
17809 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17810 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
17811 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
17812
17813 /* Memory operations. */
21d799b5
NC
17814 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17815 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
17816 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17817 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17818 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17819 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17820 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17821 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17822 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17823 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17824 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17825 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17826 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17827 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17828 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17829 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17830 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17831 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 17832
c19d1205 17833 /* Monadic operations. */
21d799b5
NC
17834 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
17835 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
17836 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
17837
17838 /* Dyadic operations. */
21d799b5
NC
17839 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17840 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17841 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17842 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17843 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17844 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17845 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17846 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17847 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 17848
c19d1205 17849 /* Comparisons. */
21d799b5
NC
17850 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
17851 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
17852 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
17853 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 17854
62f3b8c8
PB
17855 /* Double precision load/store are still present on single precision
17856 implementations. */
17857 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17858 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
17859 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17860 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17861 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17862 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17863 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17864 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17865 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17866 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 17867
c921be7d
NC
17868#undef ARM_VARIANT
17869#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
17870
c19d1205 17871 /* Moves and type conversions. */
21d799b5
NC
17872 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17873 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17874 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17875 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
17876 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
17877 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
17878 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
17879 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17880 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
17881 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17882 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17883 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17884 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 17885
c19d1205 17886 /* Monadic operations. */
21d799b5
NC
17887 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17888 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17889 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
17890
17891 /* Dyadic operations. */
21d799b5
NC
17892 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17893 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17894 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17895 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17896 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17897 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17898 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17899 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17900 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 17901
c19d1205 17902 /* Comparisons. */
21d799b5
NC
17903 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17904 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
17905 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17906 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 17907
c921be7d
NC
17908#undef ARM_VARIANT
17909#define ARM_VARIANT & fpu_vfp_ext_v2
17910
21d799b5
NC
17911 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
17912 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
17913 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
17914 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 17915
037e8744
JB
17916/* Instructions which may belong to either the Neon or VFP instruction sets.
17917 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
17918#undef ARM_VARIANT
17919#define ARM_VARIANT & fpu_vfp_ext_v1xd
17920#undef THUMB_VARIANT
17921#define THUMB_VARIANT & fpu_vfp_ext_v1xd
17922
037e8744
JB
17923 /* These mnemonics are unique to VFP. */
17924 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
17925 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
17926 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17927 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17928 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17929 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17930 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
17931 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
17932 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
17933 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
17934
17935 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
17936 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
17937 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17938 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 17939
21d799b5
NC
17940 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17941 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
17942
17943 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17944 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17945
55881a11
MGD
17946 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17947 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17948 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17949 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17950 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17951 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
17952 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17953 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 17954
e3e535bc
NC
17955 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
17956 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
21d799b5
NC
17957 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
17958 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 17959
037e8744
JB
17960
17961 /* NOTE: All VMOV encoding is special-cased! */
17962 NCE(vmov, 0, 1, (VMOV), neon_mov),
17963 NCE(vmovq, 0, 1, (VMOV), neon_mov),
17964
c921be7d
NC
17965#undef THUMB_VARIANT
17966#define THUMB_VARIANT & fpu_neon_ext_v1
17967#undef ARM_VARIANT
17968#define ARM_VARIANT & fpu_neon_ext_v1
17969
5287ad62
JB
17970 /* Data processing with three registers of the same length. */
17971 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
17972 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
17973 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
17974 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17975 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17976 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17977 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17978 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17979 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17980 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17981 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17982 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17983 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17984 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
17985 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17986 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17987 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17988 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
17989 /* If not immediate, fall back to neon_dyadic_i64_su.
17990 shl_imm should accept I8 I16 I32 I64,
17991 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
17992 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17993 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17994 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17995 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 17996 /* Logic ops, types optional & ignored. */
4316f0d2
DG
17997 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17998 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17999 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18000 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18001 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18002 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18003 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18004 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18005 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
18006 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
18007 /* Bitfield ops, untyped. */
18008 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18009 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18010 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18011 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18012 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18013 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18014 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
18015 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18016 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18017 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18018 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18019 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18020 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
18021 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
18022 back to neon_dyadic_if_su. */
21d799b5
NC
18023 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18024 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18025 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18026 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18027 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18028 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
18029 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18030 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 18031 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
18032 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
18033 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 18034 /* As above, D registers only. */
21d799b5
NC
18035 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
18036 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 18037 /* Int and float variants, signedness unimportant. */
21d799b5
NC
18038 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18039 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18040 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 18041 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
18042 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
18043 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
18044 /* vtst takes sizes 8, 16, 32. */
18045 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
18046 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
18047 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 18048 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 18049 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
18050 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18051 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
18052 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18053 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
18054 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18055 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
18056 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18057 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
18058 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18059 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
18060 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18061 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
18062 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18063 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18064 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18065 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18066
18067 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 18068 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
18069 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
18070
18071 /* Data processing with two registers and a shift amount. */
18072 /* Right shifts, and variants with rounding.
18073 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
18074 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18075 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18076 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18077 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18078 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18079 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18080 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18081 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18082 /* Shift and insert. Sizes accepted 8 16 32 64. */
18083 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
18084 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
18085 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
18086 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
18087 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
18088 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
18089 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
18090 /* Right shift immediate, saturating & narrowing, with rounding variants.
18091 Types accepted S16 S32 S64 U16 U32 U64. */
18092 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18093 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18094 /* As above, unsigned. Types accepted S16 S32 S64. */
18095 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18096 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18097 /* Right shift narrowing. Types accepted I16 I32 I64. */
18098 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18099 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18100 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 18101 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 18102 /* CVT with optional immediate for fixed-point variant. */
21d799b5 18103 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 18104
4316f0d2
DG
18105 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
18106 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
18107
18108 /* Data processing, three registers of different lengths. */
18109 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
18110 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
18111 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
18112 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
18113 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
18114 /* If not scalar, fall back to neon_dyadic_long.
18115 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
18116 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
18117 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
18118 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
18119 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18120 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18121 /* Dyadic, narrowing insns. Types I16 I32 I64. */
18122 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18123 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18124 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18125 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18126 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
18127 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18128 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18129 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
18130 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
18131 S16 S32 U16 U32. */
21d799b5 18132 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
18133
18134 /* Extract. Size 8. */
3b8d421e
PB
18135 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
18136 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
18137
18138 /* Two registers, miscellaneous. */
18139 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
18140 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
18141 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
18142 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
18143 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
18144 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
18145 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
18146 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
18147 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
18148 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
18149 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
18150 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
18151 /* VMOVN. Types I16 I32 I64. */
21d799b5 18152 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 18153 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 18154 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 18155 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 18156 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
18157 /* VZIP / VUZP. Sizes 8 16 32. */
18158 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
18159 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
18160 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
18161 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
18162 /* VQABS / VQNEG. Types S8 S16 S32. */
18163 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18164 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
18165 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18166 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
18167 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
18168 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
18169 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
18170 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
18171 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
18172 /* Reciprocal estimates. Types U32 F32. */
18173 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
18174 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
18175 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
18176 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
18177 /* VCLS. Types S8 S16 S32. */
18178 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
18179 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
18180 /* VCLZ. Types I8 I16 I32. */
18181 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
18182 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
18183 /* VCNT. Size 8. */
18184 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
18185 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
18186 /* Two address, untyped. */
18187 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
18188 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
18189 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
18190 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
18191 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
18192
18193 /* Table lookup. Size 8. */
18194 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18195 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18196
c921be7d
NC
18197#undef THUMB_VARIANT
18198#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
18199#undef ARM_VARIANT
18200#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
18201
5287ad62 18202 /* Neon element/structure load/store. */
21d799b5
NC
18203 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18204 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18205 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18206 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18207 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18208 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18209 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18210 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 18211
c921be7d 18212#undef THUMB_VARIANT
62f3b8c8
PB
18213#define THUMB_VARIANT &fpu_vfp_ext_v3xd
18214#undef ARM_VARIANT
18215#define ARM_VARIANT &fpu_vfp_ext_v3xd
18216 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
18217 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18218 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18219 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18220 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18221 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18222 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18223 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18224 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18225
18226#undef THUMB_VARIANT
c921be7d
NC
18227#define THUMB_VARIANT & fpu_vfp_ext_v3
18228#undef ARM_VARIANT
18229#define ARM_VARIANT & fpu_vfp_ext_v3
18230
21d799b5 18231 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 18232 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18233 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18234 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18235 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18236 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18237 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18238 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18239 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 18240
62f3b8c8
PB
18241#undef ARM_VARIANT
18242#define ARM_VARIANT &fpu_vfp_ext_fma
18243#undef THUMB_VARIANT
18244#define THUMB_VARIANT &fpu_vfp_ext_fma
18245 /* Mnemonics shared by Neon and VFP. These are included in the
18246 VFP FMA variant; NEON and VFP FMA always includes the NEON
18247 FMA instructions. */
18248 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18249 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18250 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
18251 the v form should always be used. */
18252 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18253 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18254 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18255 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18256 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18257 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18258
5287ad62 18259#undef THUMB_VARIANT
c921be7d
NC
18260#undef ARM_VARIANT
18261#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
18262
21d799b5
NC
18263 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18264 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18265 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18266 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18267 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18268 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18269 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
18270 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 18271
c921be7d
NC
18272#undef ARM_VARIANT
18273#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
18274
21d799b5
NC
18275 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
18276 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
18277 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
18278 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
18279 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
18280 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
18281 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
18282 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
18283 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
18284 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18285 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18286 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18287 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18288 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18289 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18290 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18291 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18292 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18293 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
18294 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
18295 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18296 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18297 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18298 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18299 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18300 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18301 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
18302 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
18303 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
18304 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
18305 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
18306 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
18307 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
18308 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
18309 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
18310 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
18311 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
18312 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18313 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18314 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18315 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18316 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18317 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18318 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18319 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18320 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18321 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
18322 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18323 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18324 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18325 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18326 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18327 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18328 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18329 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18330 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18331 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18332 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18333 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18334 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18335 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18336 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18337 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18338 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18339 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18340 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18341 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18342 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18343 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18344 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18345 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18346 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18347 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18348 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18349 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18350 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18351 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18352 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18353 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18354 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18355 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18356 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18357 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18358 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18359 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18360 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18361 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18362 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18363 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
18364 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18365 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18366 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18367 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18368 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18369 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18370 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18371 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18372 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18373 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18374 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18375 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18376 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18377 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18378 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18379 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18380 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18381 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18382 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18383 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18384 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18385 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
18386 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18387 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18388 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18389 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18390 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18391 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18392 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18393 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18394 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18395 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18396 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18397 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18398 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18399 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18400 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18401 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18402 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18403 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18404 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18405 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18406 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18407 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18408 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18409 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18410 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18411 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18412 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18413 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18414 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18415 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18416 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18417 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18418 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18419 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18420 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18421 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18422 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18423 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18424 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18425 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18426 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18427 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18428 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18429 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18430 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18431 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18432 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18433 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18434 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18435 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18436 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 18437
c921be7d
NC
18438#undef ARM_VARIANT
18439#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18440
21d799b5
NC
18441 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18442 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18443 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18444 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18445 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18446 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18447 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18448 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18449 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18450 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18451 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18452 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18453 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18454 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18455 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18456 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18457 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18458 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18459 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18460 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18461 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18462 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18463 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18464 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18465 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18466 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18467 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18468 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18469 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18470 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18471 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18472 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18473 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18474 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18475 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18476 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18477 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18478 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18479 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18480 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18481 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18482 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18483 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18484 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18485 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18486 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18487 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18488 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18489 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18490 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18491 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18492 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18493 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18494 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18495 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18496 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18497 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 18498
c921be7d
NC
18499#undef ARM_VARIANT
18500#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18501
21d799b5
NC
18502 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18503 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18504 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18505 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18506 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18507 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18508 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18509 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18510 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18511 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18512 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18513 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18514 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18515 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18516 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18517 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18518 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18519 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18520 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18521 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18522 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18523 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18524 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18525 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18526 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18527 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18528 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18529 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18530 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18531 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18532 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18533 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18534 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18535 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18536 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18537 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18538 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18539 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18540 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18541 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18542 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18543 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18544 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18545 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18546 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18547 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18548 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18549 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18550 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18551 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18552 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18553 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18554 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18555 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18556 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18557 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18558 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18559 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18560 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18561 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18562 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18563 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18564 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18565 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18566 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18567 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18568 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18569 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18570 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18571 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18572 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18573 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18574 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18575 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18576 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18577 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
18578};
18579#undef ARM_VARIANT
18580#undef THUMB_VARIANT
18581#undef TCE
18582#undef TCM
18583#undef TUE
18584#undef TUF
18585#undef TCC
8f06b2d8 18586#undef cCE
e3cb604e
PB
18587#undef cCL
18588#undef C3E
c19d1205
ZW
18589#undef CE
18590#undef CM
18591#undef UE
18592#undef UF
18593#undef UT
5287ad62
JB
18594#undef NUF
18595#undef nUF
18596#undef NCE
18597#undef nCE
c19d1205
ZW
18598#undef OPS0
18599#undef OPS1
18600#undef OPS2
18601#undef OPS3
18602#undef OPS4
18603#undef OPS5
18604#undef OPS6
18605#undef do_0
18606\f
18607/* MD interface: bits in the object file. */
bfae80f2 18608
c19d1205
ZW
18609/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18610 for use in the a.out file, and stores them in the array pointed to by buf.
18611 This knows about the endian-ness of the target machine and does
18612 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18613 2 (short) and 4 (long) Floating numbers are put out as a series of
18614 LITTLENUMS (shorts, here at least). */
b99bd4ef 18615
c19d1205
ZW
18616void
18617md_number_to_chars (char * buf, valueT val, int n)
18618{
18619 if (target_big_endian)
18620 number_to_chars_bigendian (buf, val, n);
18621 else
18622 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
18623}
18624
c19d1205
ZW
18625static valueT
18626md_chars_to_number (char * buf, int n)
bfae80f2 18627{
c19d1205
ZW
18628 valueT result = 0;
18629 unsigned char * where = (unsigned char *) buf;
bfae80f2 18630
c19d1205 18631 if (target_big_endian)
b99bd4ef 18632 {
c19d1205
ZW
18633 while (n--)
18634 {
18635 result <<= 8;
18636 result |= (*where++ & 255);
18637 }
b99bd4ef 18638 }
c19d1205 18639 else
b99bd4ef 18640 {
c19d1205
ZW
18641 while (n--)
18642 {
18643 result <<= 8;
18644 result |= (where[n] & 255);
18645 }
bfae80f2 18646 }
b99bd4ef 18647
c19d1205 18648 return result;
bfae80f2 18649}
b99bd4ef 18650
c19d1205 18651/* MD interface: Sections. */
b99bd4ef 18652
0110f2b8
PB
18653/* Estimate the size of a frag before relaxing. Assume everything fits in
18654 2 bytes. */
18655
c19d1205 18656int
0110f2b8 18657md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
18658 segT segtype ATTRIBUTE_UNUSED)
18659{
0110f2b8
PB
18660 fragp->fr_var = 2;
18661 return 2;
18662}
18663
18664/* Convert a machine dependent frag. */
18665
18666void
18667md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18668{
18669 unsigned long insn;
18670 unsigned long old_op;
18671 char *buf;
18672 expressionS exp;
18673 fixS *fixp;
18674 int reloc_type;
18675 int pc_rel;
18676 int opcode;
18677
18678 buf = fragp->fr_literal + fragp->fr_fix;
18679
18680 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
18681 if (fragp->fr_symbol)
18682 {
0110f2b8
PB
18683 exp.X_op = O_symbol;
18684 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
18685 }
18686 else
18687 {
0110f2b8 18688 exp.X_op = O_constant;
5f4273c7 18689 }
0110f2b8
PB
18690 exp.X_add_number = fragp->fr_offset;
18691 opcode = fragp->fr_subtype;
18692 switch (opcode)
18693 {
18694 case T_MNEM_ldr_pc:
18695 case T_MNEM_ldr_pc2:
18696 case T_MNEM_ldr_sp:
18697 case T_MNEM_str_sp:
18698 case T_MNEM_ldr:
18699 case T_MNEM_ldrb:
18700 case T_MNEM_ldrh:
18701 case T_MNEM_str:
18702 case T_MNEM_strb:
18703 case T_MNEM_strh:
18704 if (fragp->fr_var == 4)
18705 {
5f4273c7 18706 insn = THUMB_OP32 (opcode);
0110f2b8
PB
18707 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18708 {
18709 insn |= (old_op & 0x700) << 4;
18710 }
18711 else
18712 {
18713 insn |= (old_op & 7) << 12;
18714 insn |= (old_op & 0x38) << 13;
18715 }
18716 insn |= 0x00000c00;
18717 put_thumb32_insn (buf, insn);
18718 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18719 }
18720 else
18721 {
18722 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18723 }
18724 pc_rel = (opcode == T_MNEM_ldr_pc2);
18725 break;
18726 case T_MNEM_adr:
18727 if (fragp->fr_var == 4)
18728 {
18729 insn = THUMB_OP32 (opcode);
18730 insn |= (old_op & 0xf0) << 4;
18731 put_thumb32_insn (buf, insn);
18732 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18733 }
18734 else
18735 {
18736 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18737 exp.X_add_number -= 4;
18738 }
18739 pc_rel = 1;
18740 break;
18741 case T_MNEM_mov:
18742 case T_MNEM_movs:
18743 case T_MNEM_cmp:
18744 case T_MNEM_cmn:
18745 if (fragp->fr_var == 4)
18746 {
18747 int r0off = (opcode == T_MNEM_mov
18748 || opcode == T_MNEM_movs) ? 0 : 8;
18749 insn = THUMB_OP32 (opcode);
18750 insn = (insn & 0xe1ffffff) | 0x10000000;
18751 insn |= (old_op & 0x700) << r0off;
18752 put_thumb32_insn (buf, insn);
18753 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18754 }
18755 else
18756 {
18757 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18758 }
18759 pc_rel = 0;
18760 break;
18761 case T_MNEM_b:
18762 if (fragp->fr_var == 4)
18763 {
18764 insn = THUMB_OP32(opcode);
18765 put_thumb32_insn (buf, insn);
18766 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18767 }
18768 else
18769 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18770 pc_rel = 1;
18771 break;
18772 case T_MNEM_bcond:
18773 if (fragp->fr_var == 4)
18774 {
18775 insn = THUMB_OP32(opcode);
18776 insn |= (old_op & 0xf00) << 14;
18777 put_thumb32_insn (buf, insn);
18778 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18779 }
18780 else
18781 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18782 pc_rel = 1;
18783 break;
18784 case T_MNEM_add_sp:
18785 case T_MNEM_add_pc:
18786 case T_MNEM_inc_sp:
18787 case T_MNEM_dec_sp:
18788 if (fragp->fr_var == 4)
18789 {
18790 /* ??? Choose between add and addw. */
18791 insn = THUMB_OP32 (opcode);
18792 insn |= (old_op & 0xf0) << 4;
18793 put_thumb32_insn (buf, insn);
16805f35
PB
18794 if (opcode == T_MNEM_add_pc)
18795 reloc_type = BFD_RELOC_ARM_T32_IMM12;
18796 else
18797 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
18798 }
18799 else
18800 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18801 pc_rel = 0;
18802 break;
18803
18804 case T_MNEM_addi:
18805 case T_MNEM_addis:
18806 case T_MNEM_subi:
18807 case T_MNEM_subis:
18808 if (fragp->fr_var == 4)
18809 {
18810 insn = THUMB_OP32 (opcode);
18811 insn |= (old_op & 0xf0) << 4;
18812 insn |= (old_op & 0xf) << 16;
18813 put_thumb32_insn (buf, insn);
16805f35
PB
18814 if (insn & (1 << 20))
18815 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18816 else
18817 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
18818 }
18819 else
18820 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18821 pc_rel = 0;
18822 break;
18823 default:
5f4273c7 18824 abort ();
0110f2b8
PB
18825 }
18826 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 18827 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
18828 fixp->fx_file = fragp->fr_file;
18829 fixp->fx_line = fragp->fr_line;
18830 fragp->fr_fix += fragp->fr_var;
18831}
18832
18833/* Return the size of a relaxable immediate operand instruction.
18834 SHIFT and SIZE specify the form of the allowable immediate. */
18835static int
18836relax_immediate (fragS *fragp, int size, int shift)
18837{
18838 offsetT offset;
18839 offsetT mask;
18840 offsetT low;
18841
18842 /* ??? Should be able to do better than this. */
18843 if (fragp->fr_symbol)
18844 return 4;
18845
18846 low = (1 << shift) - 1;
18847 mask = (1 << (shift + size)) - (1 << shift);
18848 offset = fragp->fr_offset;
18849 /* Force misaligned offsets to 32-bit variant. */
18850 if (offset & low)
5e77afaa 18851 return 4;
0110f2b8
PB
18852 if (offset & ~mask)
18853 return 4;
18854 return 2;
18855}
18856
5e77afaa
PB
18857/* Get the address of a symbol during relaxation. */
18858static addressT
5f4273c7 18859relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
18860{
18861 fragS *sym_frag;
18862 addressT addr;
18863 symbolS *sym;
18864
18865 sym = fragp->fr_symbol;
18866 sym_frag = symbol_get_frag (sym);
18867 know (S_GET_SEGMENT (sym) != absolute_section
18868 || sym_frag == &zero_address_frag);
18869 addr = S_GET_VALUE (sym) + fragp->fr_offset;
18870
18871 /* If frag has yet to be reached on this pass, assume it will
18872 move by STRETCH just as we did. If this is not so, it will
18873 be because some frag between grows, and that will force
18874 another pass. */
18875
18876 if (stretch != 0
18877 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
18878 {
18879 fragS *f;
18880
18881 /* Adjust stretch for any alignment frag. Note that if have
18882 been expanding the earlier code, the symbol may be
18883 defined in what appears to be an earlier frag. FIXME:
18884 This doesn't handle the fr_subtype field, which specifies
18885 a maximum number of bytes to skip when doing an
18886 alignment. */
18887 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
18888 {
18889 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
18890 {
18891 if (stretch < 0)
18892 stretch = - ((- stretch)
18893 & ~ ((1 << (int) f->fr_offset) - 1));
18894 else
18895 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
18896 if (stretch == 0)
18897 break;
18898 }
18899 }
18900 if (f != NULL)
18901 addr += stretch;
18902 }
5e77afaa
PB
18903
18904 return addr;
18905}
18906
0110f2b8
PB
18907/* Return the size of a relaxable adr pseudo-instruction or PC-relative
18908 load. */
18909static int
5e77afaa 18910relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
18911{
18912 addressT addr;
18913 offsetT val;
18914
18915 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
18916 if (fragp->fr_symbol == NULL
18917 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
18918 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18919 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
18920 return 4;
18921
5f4273c7 18922 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18923 addr = fragp->fr_address + fragp->fr_fix;
18924 addr = (addr + 4) & ~3;
5e77afaa 18925 /* Force misaligned targets to 32-bit variant. */
0110f2b8 18926 if (val & 3)
5e77afaa 18927 return 4;
0110f2b8
PB
18928 val -= addr;
18929 if (val < 0 || val > 1020)
18930 return 4;
18931 return 2;
18932}
18933
18934/* Return the size of a relaxable add/sub immediate instruction. */
18935static int
18936relax_addsub (fragS *fragp, asection *sec)
18937{
18938 char *buf;
18939 int op;
18940
18941 buf = fragp->fr_literal + fragp->fr_fix;
18942 op = bfd_get_16(sec->owner, buf);
18943 if ((op & 0xf) == ((op >> 4) & 0xf))
18944 return relax_immediate (fragp, 8, 0);
18945 else
18946 return relax_immediate (fragp, 3, 0);
18947}
18948
18949
18950/* Return the size of a relaxable branch instruction. BITS is the
18951 size of the offset field in the narrow instruction. */
18952
18953static int
5e77afaa 18954relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
18955{
18956 addressT addr;
18957 offsetT val;
18958 offsetT limit;
18959
18960 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 18961 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
18962 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18963 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
18964 return 4;
18965
267bf995
RR
18966#ifdef OBJ_ELF
18967 if (S_IS_DEFINED (fragp->fr_symbol)
18968 && ARM_IS_FUNC (fragp->fr_symbol))
18969 return 4;
18970#endif
18971
5f4273c7 18972 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18973 addr = fragp->fr_address + fragp->fr_fix + 4;
18974 val -= addr;
18975
18976 /* Offset is a signed value *2 */
18977 limit = 1 << bits;
18978 if (val >= limit || val < -limit)
18979 return 4;
18980 return 2;
18981}
18982
18983
18984/* Relax a machine dependent frag. This returns the amount by which
18985 the current size of the frag should change. */
18986
18987int
5e77afaa 18988arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
18989{
18990 int oldsize;
18991 int newsize;
18992
18993 oldsize = fragp->fr_var;
18994 switch (fragp->fr_subtype)
18995 {
18996 case T_MNEM_ldr_pc2:
5f4273c7 18997 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18998 break;
18999 case T_MNEM_ldr_pc:
19000 case T_MNEM_ldr_sp:
19001 case T_MNEM_str_sp:
5f4273c7 19002 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
19003 break;
19004 case T_MNEM_ldr:
19005 case T_MNEM_str:
5f4273c7 19006 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
19007 break;
19008 case T_MNEM_ldrh:
19009 case T_MNEM_strh:
5f4273c7 19010 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
19011 break;
19012 case T_MNEM_ldrb:
19013 case T_MNEM_strb:
5f4273c7 19014 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
19015 break;
19016 case T_MNEM_adr:
5f4273c7 19017 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
19018 break;
19019 case T_MNEM_mov:
19020 case T_MNEM_movs:
19021 case T_MNEM_cmp:
19022 case T_MNEM_cmn:
5f4273c7 19023 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
19024 break;
19025 case T_MNEM_b:
5f4273c7 19026 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
19027 break;
19028 case T_MNEM_bcond:
5f4273c7 19029 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
19030 break;
19031 case T_MNEM_add_sp:
19032 case T_MNEM_add_pc:
19033 newsize = relax_immediate (fragp, 8, 2);
19034 break;
19035 case T_MNEM_inc_sp:
19036 case T_MNEM_dec_sp:
19037 newsize = relax_immediate (fragp, 7, 2);
19038 break;
19039 case T_MNEM_addi:
19040 case T_MNEM_addis:
19041 case T_MNEM_subi:
19042 case T_MNEM_subis:
19043 newsize = relax_addsub (fragp, sec);
19044 break;
19045 default:
5f4273c7 19046 abort ();
0110f2b8 19047 }
5e77afaa
PB
19048
19049 fragp->fr_var = newsize;
19050 /* Freeze wide instructions that are at or before the same location as
19051 in the previous pass. This avoids infinite loops.
5f4273c7
NC
19052 Don't freeze them unconditionally because targets may be artificially
19053 misaligned by the expansion of preceding frags. */
5e77afaa 19054 if (stretch <= 0 && newsize > 2)
0110f2b8 19055 {
0110f2b8 19056 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 19057 frag_wane (fragp);
0110f2b8 19058 }
5e77afaa 19059
0110f2b8 19060 return newsize - oldsize;
c19d1205 19061}
b99bd4ef 19062
c19d1205 19063/* Round up a section size to the appropriate boundary. */
b99bd4ef 19064
c19d1205
ZW
19065valueT
19066md_section_align (segT segment ATTRIBUTE_UNUSED,
19067 valueT size)
19068{
f0927246
NC
19069#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
19070 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
19071 {
19072 /* For a.out, force the section size to be aligned. If we don't do
19073 this, BFD will align it for us, but it will not write out the
19074 final bytes of the section. This may be a bug in BFD, but it is
19075 easier to fix it here since that is how the other a.out targets
19076 work. */
19077 int align;
19078
19079 align = bfd_get_section_alignment (stdoutput, segment);
19080 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
19081 }
c19d1205 19082#endif
f0927246
NC
19083
19084 return size;
bfae80f2 19085}
b99bd4ef 19086
c19d1205
ZW
19087/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
19088 of an rs_align_code fragment. */
19089
19090void
19091arm_handle_align (fragS * fragP)
bfae80f2 19092{
e7495e45
NS
19093 static char const arm_noop[2][2][4] =
19094 {
19095 { /* ARMv1 */
19096 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
19097 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
19098 },
19099 { /* ARMv6k */
19100 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
19101 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
19102 },
19103 };
19104 static char const thumb_noop[2][2][2] =
19105 {
19106 { /* Thumb-1 */
19107 {0xc0, 0x46}, /* LE */
19108 {0x46, 0xc0}, /* BE */
19109 },
19110 { /* Thumb-2 */
19111 {0x00, 0xbf}, /* LE */
19112 {0xbf, 0x00} /* BE */
19113 }
19114 };
19115 static char const wide_thumb_noop[2][4] =
19116 { /* Wide Thumb-2 */
19117 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
19118 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
19119 };
c921be7d 19120
e7495e45 19121 unsigned bytes, fix, noop_size;
c19d1205
ZW
19122 char * p;
19123 const char * noop;
e7495e45 19124 const char *narrow_noop = NULL;
cd000bff
DJ
19125#ifdef OBJ_ELF
19126 enum mstate state;
19127#endif
bfae80f2 19128
c19d1205 19129 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
19130 return;
19131
c19d1205
ZW
19132 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
19133 p = fragP->fr_literal + fragP->fr_fix;
19134 fix = 0;
bfae80f2 19135
c19d1205
ZW
19136 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
19137 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 19138
cd000bff 19139 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 19140
cd000bff 19141 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 19142 {
e7495e45
NS
19143 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
19144 {
19145 narrow_noop = thumb_noop[1][target_big_endian];
19146 noop = wide_thumb_noop[target_big_endian];
19147 }
c19d1205 19148 else
e7495e45
NS
19149 noop = thumb_noop[0][target_big_endian];
19150 noop_size = 2;
cd000bff
DJ
19151#ifdef OBJ_ELF
19152 state = MAP_THUMB;
19153#endif
7ed4c4c5
NC
19154 }
19155 else
19156 {
e7495e45
NS
19157 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
19158 [target_big_endian];
19159 noop_size = 4;
cd000bff
DJ
19160#ifdef OBJ_ELF
19161 state = MAP_ARM;
19162#endif
7ed4c4c5 19163 }
c921be7d 19164
e7495e45 19165 fragP->fr_var = noop_size;
c921be7d 19166
c19d1205 19167 if (bytes & (noop_size - 1))
7ed4c4c5 19168 {
c19d1205 19169 fix = bytes & (noop_size - 1);
cd000bff
DJ
19170#ifdef OBJ_ELF
19171 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
19172#endif
c19d1205
ZW
19173 memset (p, 0, fix);
19174 p += fix;
19175 bytes -= fix;
a737bd4d 19176 }
a737bd4d 19177
e7495e45
NS
19178 if (narrow_noop)
19179 {
19180 if (bytes & noop_size)
19181 {
19182 /* Insert a narrow noop. */
19183 memcpy (p, narrow_noop, noop_size);
19184 p += noop_size;
19185 bytes -= noop_size;
19186 fix += noop_size;
19187 }
19188
19189 /* Use wide noops for the remainder */
19190 noop_size = 4;
19191 }
19192
c19d1205 19193 while (bytes >= noop_size)
a737bd4d 19194 {
c19d1205
ZW
19195 memcpy (p, noop, noop_size);
19196 p += noop_size;
19197 bytes -= noop_size;
19198 fix += noop_size;
a737bd4d
NC
19199 }
19200
c19d1205 19201 fragP->fr_fix += fix;
a737bd4d
NC
19202}
19203
c19d1205
ZW
19204/* Called from md_do_align. Used to create an alignment
19205 frag in a code section. */
19206
19207void
19208arm_frag_align_code (int n, int max)
bfae80f2 19209{
c19d1205 19210 char * p;
7ed4c4c5 19211
c19d1205 19212 /* We assume that there will never be a requirement
6ec8e702 19213 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 19214 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
19215 {
19216 char err_msg[128];
19217
19218 sprintf (err_msg,
19219 _("alignments greater than %d bytes not supported in .text sections."),
19220 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 19221 as_fatal ("%s", err_msg);
6ec8e702 19222 }
bfae80f2 19223
c19d1205
ZW
19224 p = frag_var (rs_align_code,
19225 MAX_MEM_FOR_RS_ALIGN_CODE,
19226 1,
19227 (relax_substateT) max,
19228 (symbolS *) NULL,
19229 (offsetT) n,
19230 (char *) NULL);
19231 *p = 0;
19232}
bfae80f2 19233
8dc2430f
NC
19234/* Perform target specific initialisation of a frag.
19235 Note - despite the name this initialisation is not done when the frag
19236 is created, but only when its type is assigned. A frag can be created
19237 and used a long time before its type is set, so beware of assuming that
19238 this initialisationis performed first. */
bfae80f2 19239
cd000bff
DJ
19240#ifndef OBJ_ELF
19241void
19242arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
19243{
19244 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 19245 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
19246}
19247
19248#else /* OBJ_ELF is defined. */
c19d1205 19249void
cd000bff 19250arm_init_frag (fragS * fragP, int max_chars)
c19d1205 19251{
8dc2430f
NC
19252 /* If the current ARM vs THUMB mode has not already
19253 been recorded into this frag then do so now. */
cd000bff
DJ
19254 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
19255 {
19256 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19257
19258 /* Record a mapping symbol for alignment frags. We will delete this
19259 later if the alignment ends up empty. */
19260 switch (fragP->fr_type)
19261 {
19262 case rs_align:
19263 case rs_align_test:
19264 case rs_fill:
19265 mapping_state_2 (MAP_DATA, max_chars);
19266 break;
19267 case rs_align_code:
19268 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
19269 break;
19270 default:
19271 break;
19272 }
19273 }
bfae80f2
RE
19274}
19275
c19d1205
ZW
19276/* When we change sections we need to issue a new mapping symbol. */
19277
19278void
19279arm_elf_change_section (void)
bfae80f2 19280{
c19d1205
ZW
19281 /* Link an unlinked unwind index table section to the .text section. */
19282 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
19283 && elf_linked_to_section (now_seg) == NULL)
19284 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
19285}
19286
c19d1205
ZW
19287int
19288arm_elf_section_type (const char * str, size_t len)
e45d0630 19289{
c19d1205
ZW
19290 if (len == 5 && strncmp (str, "exidx", 5) == 0)
19291 return SHT_ARM_EXIDX;
e45d0630 19292
c19d1205
ZW
19293 return -1;
19294}
19295\f
19296/* Code to deal with unwinding tables. */
e45d0630 19297
c19d1205 19298static void add_unwind_adjustsp (offsetT);
e45d0630 19299
5f4273c7 19300/* Generate any deferred unwind frame offset. */
e45d0630 19301
bfae80f2 19302static void
c19d1205 19303flush_pending_unwind (void)
bfae80f2 19304{
c19d1205 19305 offsetT offset;
bfae80f2 19306
c19d1205
ZW
19307 offset = unwind.pending_offset;
19308 unwind.pending_offset = 0;
19309 if (offset != 0)
19310 add_unwind_adjustsp (offset);
bfae80f2
RE
19311}
19312
c19d1205
ZW
19313/* Add an opcode to this list for this function. Two-byte opcodes should
19314 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
19315 order. */
19316
bfae80f2 19317static void
c19d1205 19318add_unwind_opcode (valueT op, int length)
bfae80f2 19319{
c19d1205
ZW
19320 /* Add any deferred stack adjustment. */
19321 if (unwind.pending_offset)
19322 flush_pending_unwind ();
bfae80f2 19323
c19d1205 19324 unwind.sp_restored = 0;
bfae80f2 19325
c19d1205 19326 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 19327 {
c19d1205
ZW
19328 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
19329 if (unwind.opcodes)
21d799b5
NC
19330 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
19331 unwind.opcode_alloc);
c19d1205 19332 else
21d799b5 19333 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 19334 }
c19d1205 19335 while (length > 0)
bfae80f2 19336 {
c19d1205
ZW
19337 length--;
19338 unwind.opcodes[unwind.opcode_count] = op & 0xff;
19339 op >>= 8;
19340 unwind.opcode_count++;
bfae80f2 19341 }
bfae80f2
RE
19342}
19343
c19d1205
ZW
19344/* Add unwind opcodes to adjust the stack pointer. */
19345
bfae80f2 19346static void
c19d1205 19347add_unwind_adjustsp (offsetT offset)
bfae80f2 19348{
c19d1205 19349 valueT op;
bfae80f2 19350
c19d1205 19351 if (offset > 0x200)
bfae80f2 19352 {
c19d1205
ZW
19353 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
19354 char bytes[5];
19355 int n;
19356 valueT o;
bfae80f2 19357
c19d1205
ZW
19358 /* Long form: 0xb2, uleb128. */
19359 /* This might not fit in a word so add the individual bytes,
19360 remembering the list is built in reverse order. */
19361 o = (valueT) ((offset - 0x204) >> 2);
19362 if (o == 0)
19363 add_unwind_opcode (0, 1);
bfae80f2 19364
c19d1205
ZW
19365 /* Calculate the uleb128 encoding of the offset. */
19366 n = 0;
19367 while (o)
19368 {
19369 bytes[n] = o & 0x7f;
19370 o >>= 7;
19371 if (o)
19372 bytes[n] |= 0x80;
19373 n++;
19374 }
19375 /* Add the insn. */
19376 for (; n; n--)
19377 add_unwind_opcode (bytes[n - 1], 1);
19378 add_unwind_opcode (0xb2, 1);
19379 }
19380 else if (offset > 0x100)
bfae80f2 19381 {
c19d1205
ZW
19382 /* Two short opcodes. */
19383 add_unwind_opcode (0x3f, 1);
19384 op = (offset - 0x104) >> 2;
19385 add_unwind_opcode (op, 1);
bfae80f2 19386 }
c19d1205
ZW
19387 else if (offset > 0)
19388 {
19389 /* Short opcode. */
19390 op = (offset - 4) >> 2;
19391 add_unwind_opcode (op, 1);
19392 }
19393 else if (offset < 0)
bfae80f2 19394 {
c19d1205
ZW
19395 offset = -offset;
19396 while (offset > 0x100)
bfae80f2 19397 {
c19d1205
ZW
19398 add_unwind_opcode (0x7f, 1);
19399 offset -= 0x100;
bfae80f2 19400 }
c19d1205
ZW
19401 op = ((offset - 4) >> 2) | 0x40;
19402 add_unwind_opcode (op, 1);
bfae80f2 19403 }
bfae80f2
RE
19404}
19405
c19d1205
ZW
19406/* Finish the list of unwind opcodes for this function. */
19407static void
19408finish_unwind_opcodes (void)
bfae80f2 19409{
c19d1205 19410 valueT op;
bfae80f2 19411
c19d1205 19412 if (unwind.fp_used)
bfae80f2 19413 {
708587a4 19414 /* Adjust sp as necessary. */
c19d1205
ZW
19415 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19416 flush_pending_unwind ();
bfae80f2 19417
c19d1205
ZW
19418 /* After restoring sp from the frame pointer. */
19419 op = 0x90 | unwind.fp_reg;
19420 add_unwind_opcode (op, 1);
19421 }
19422 else
19423 flush_pending_unwind ();
bfae80f2
RE
19424}
19425
bfae80f2 19426
c19d1205
ZW
19427/* Start an exception table entry. If idx is nonzero this is an index table
19428 entry. */
bfae80f2
RE
19429
19430static void
c19d1205 19431start_unwind_section (const segT text_seg, int idx)
bfae80f2 19432{
c19d1205
ZW
19433 const char * text_name;
19434 const char * prefix;
19435 const char * prefix_once;
19436 const char * group_name;
19437 size_t prefix_len;
19438 size_t text_len;
19439 char * sec_name;
19440 size_t sec_name_len;
19441 int type;
19442 int flags;
19443 int linkonce;
bfae80f2 19444
c19d1205 19445 if (idx)
bfae80f2 19446 {
c19d1205
ZW
19447 prefix = ELF_STRING_ARM_unwind;
19448 prefix_once = ELF_STRING_ARM_unwind_once;
19449 type = SHT_ARM_EXIDX;
bfae80f2 19450 }
c19d1205 19451 else
bfae80f2 19452 {
c19d1205
ZW
19453 prefix = ELF_STRING_ARM_unwind_info;
19454 prefix_once = ELF_STRING_ARM_unwind_info_once;
19455 type = SHT_PROGBITS;
bfae80f2
RE
19456 }
19457
c19d1205
ZW
19458 text_name = segment_name (text_seg);
19459 if (streq (text_name, ".text"))
19460 text_name = "";
19461
19462 if (strncmp (text_name, ".gnu.linkonce.t.",
19463 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 19464 {
c19d1205
ZW
19465 prefix = prefix_once;
19466 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
19467 }
19468
c19d1205
ZW
19469 prefix_len = strlen (prefix);
19470 text_len = strlen (text_name);
19471 sec_name_len = prefix_len + text_len;
21d799b5 19472 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
19473 memcpy (sec_name, prefix, prefix_len);
19474 memcpy (sec_name + prefix_len, text_name, text_len);
19475 sec_name[prefix_len + text_len] = '\0';
bfae80f2 19476
c19d1205
ZW
19477 flags = SHF_ALLOC;
19478 linkonce = 0;
19479 group_name = 0;
bfae80f2 19480
c19d1205
ZW
19481 /* Handle COMDAT group. */
19482 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 19483 {
c19d1205
ZW
19484 group_name = elf_group_name (text_seg);
19485 if (group_name == NULL)
19486 {
bd3ba5d1 19487 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
19488 segment_name (text_seg));
19489 ignore_rest_of_line ();
19490 return;
19491 }
19492 flags |= SHF_GROUP;
19493 linkonce = 1;
bfae80f2
RE
19494 }
19495
c19d1205 19496 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 19497
5f4273c7 19498 /* Set the section link for index tables. */
c19d1205
ZW
19499 if (idx)
19500 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
19501}
19502
bfae80f2 19503
c19d1205
ZW
19504/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19505 personality routine data. Returns zero, or the index table value for
19506 and inline entry. */
19507
19508static valueT
19509create_unwind_entry (int have_data)
bfae80f2 19510{
c19d1205
ZW
19511 int size;
19512 addressT where;
19513 char *ptr;
19514 /* The current word of data. */
19515 valueT data;
19516 /* The number of bytes left in this word. */
19517 int n;
bfae80f2 19518
c19d1205 19519 finish_unwind_opcodes ();
bfae80f2 19520
c19d1205
ZW
19521 /* Remember the current text section. */
19522 unwind.saved_seg = now_seg;
19523 unwind.saved_subseg = now_subseg;
bfae80f2 19524
c19d1205 19525 start_unwind_section (now_seg, 0);
bfae80f2 19526
c19d1205 19527 if (unwind.personality_routine == NULL)
bfae80f2 19528 {
c19d1205
ZW
19529 if (unwind.personality_index == -2)
19530 {
19531 if (have_data)
5f4273c7 19532 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
19533 return 1; /* EXIDX_CANTUNWIND. */
19534 }
bfae80f2 19535
c19d1205
ZW
19536 /* Use a default personality routine if none is specified. */
19537 if (unwind.personality_index == -1)
19538 {
19539 if (unwind.opcode_count > 3)
19540 unwind.personality_index = 1;
19541 else
19542 unwind.personality_index = 0;
19543 }
bfae80f2 19544
c19d1205
ZW
19545 /* Space for the personality routine entry. */
19546 if (unwind.personality_index == 0)
19547 {
19548 if (unwind.opcode_count > 3)
19549 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 19550
c19d1205
ZW
19551 if (!have_data)
19552 {
19553 /* All the data is inline in the index table. */
19554 data = 0x80;
19555 n = 3;
19556 while (unwind.opcode_count > 0)
19557 {
19558 unwind.opcode_count--;
19559 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19560 n--;
19561 }
bfae80f2 19562
c19d1205
ZW
19563 /* Pad with "finish" opcodes. */
19564 while (n--)
19565 data = (data << 8) | 0xb0;
bfae80f2 19566
c19d1205
ZW
19567 return data;
19568 }
19569 size = 0;
19570 }
19571 else
19572 /* We get two opcodes "free" in the first word. */
19573 size = unwind.opcode_count - 2;
19574 }
19575 else
19576 /* An extra byte is required for the opcode count. */
19577 size = unwind.opcode_count + 1;
bfae80f2 19578
c19d1205
ZW
19579 size = (size + 3) >> 2;
19580 if (size > 0xff)
19581 as_bad (_("too many unwind opcodes"));
bfae80f2 19582
c19d1205
ZW
19583 frag_align (2, 0, 0);
19584 record_alignment (now_seg, 2);
19585 unwind.table_entry = expr_build_dot ();
19586
19587 /* Allocate the table entry. */
19588 ptr = frag_more ((size << 2) + 4);
19589 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 19590
c19d1205 19591 switch (unwind.personality_index)
bfae80f2 19592 {
c19d1205
ZW
19593 case -1:
19594 /* ??? Should this be a PLT generating relocation? */
19595 /* Custom personality routine. */
19596 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19597 BFD_RELOC_ARM_PREL31);
bfae80f2 19598
c19d1205
ZW
19599 where += 4;
19600 ptr += 4;
bfae80f2 19601
c19d1205
ZW
19602 /* Set the first byte to the number of additional words. */
19603 data = size - 1;
19604 n = 3;
19605 break;
bfae80f2 19606
c19d1205
ZW
19607 /* ABI defined personality routines. */
19608 case 0:
19609 /* Three opcodes bytes are packed into the first word. */
19610 data = 0x80;
19611 n = 3;
19612 break;
bfae80f2 19613
c19d1205
ZW
19614 case 1:
19615 case 2:
19616 /* The size and first two opcode bytes go in the first word. */
19617 data = ((0x80 + unwind.personality_index) << 8) | size;
19618 n = 2;
19619 break;
bfae80f2 19620
c19d1205
ZW
19621 default:
19622 /* Should never happen. */
19623 abort ();
19624 }
bfae80f2 19625
c19d1205
ZW
19626 /* Pack the opcodes into words (MSB first), reversing the list at the same
19627 time. */
19628 while (unwind.opcode_count > 0)
19629 {
19630 if (n == 0)
19631 {
19632 md_number_to_chars (ptr, data, 4);
19633 ptr += 4;
19634 n = 4;
19635 data = 0;
19636 }
19637 unwind.opcode_count--;
19638 n--;
19639 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19640 }
19641
19642 /* Finish off the last word. */
19643 if (n < 4)
19644 {
19645 /* Pad with "finish" opcodes. */
19646 while (n--)
19647 data = (data << 8) | 0xb0;
19648
19649 md_number_to_chars (ptr, data, 4);
19650 }
19651
19652 if (!have_data)
19653 {
19654 /* Add an empty descriptor if there is no user-specified data. */
19655 ptr = frag_more (4);
19656 md_number_to_chars (ptr, 0, 4);
19657 }
19658
19659 return 0;
bfae80f2
RE
19660}
19661
f0927246
NC
19662
19663/* Initialize the DWARF-2 unwind information for this procedure. */
19664
19665void
19666tc_arm_frame_initial_instructions (void)
19667{
19668 cfi_add_CFA_def_cfa (REG_SP, 0);
19669}
19670#endif /* OBJ_ELF */
19671
c19d1205
ZW
19672/* Convert REGNAME to a DWARF-2 register number. */
19673
19674int
1df69f4f 19675tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 19676{
1df69f4f 19677 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
19678
19679 if (reg == FAIL)
19680 return -1;
19681
19682 return reg;
bfae80f2
RE
19683}
19684
f0927246 19685#ifdef TE_PE
c19d1205 19686void
f0927246 19687tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 19688{
91d6fa6a 19689 expressionS exp;
bfae80f2 19690
91d6fa6a
NC
19691 exp.X_op = O_secrel;
19692 exp.X_add_symbol = symbol;
19693 exp.X_add_number = 0;
19694 emit_expr (&exp, size);
f0927246
NC
19695}
19696#endif
bfae80f2 19697
c19d1205 19698/* MD interface: Symbol and relocation handling. */
bfae80f2 19699
2fc8bdac
ZW
19700/* Return the address within the segment that a PC-relative fixup is
19701 relative to. For ARM, PC-relative fixups applied to instructions
19702 are generally relative to the location of the fixup plus 8 bytes.
19703 Thumb branches are offset by 4, and Thumb loads relative to PC
19704 require special handling. */
bfae80f2 19705
c19d1205 19706long
2fc8bdac 19707md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 19708{
2fc8bdac
ZW
19709 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19710
19711 /* If this is pc-relative and we are going to emit a relocation
19712 then we just want to put out any pipeline compensation that the linker
53baae48
NC
19713 will need. Otherwise we want to use the calculated base.
19714 For WinCE we skip the bias for externals as well, since this
19715 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 19716 if (fixP->fx_pcrel
2fc8bdac 19717 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
19718 || (arm_force_relocation (fixP)
19719#ifdef TE_WINCE
19720 && !S_IS_EXTERNAL (fixP->fx_addsy)
19721#endif
19722 )))
2fc8bdac 19723 base = 0;
bfae80f2 19724
267bf995 19725
c19d1205 19726 switch (fixP->fx_r_type)
bfae80f2 19727 {
2fc8bdac
ZW
19728 /* PC relative addressing on the Thumb is slightly odd as the
19729 bottom two bits of the PC are forced to zero for the
19730 calculation. This happens *after* application of the
19731 pipeline offset. However, Thumb adrl already adjusts for
19732 this, so we need not do it again. */
c19d1205 19733 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 19734 return base & ~3;
c19d1205
ZW
19735
19736 case BFD_RELOC_ARM_THUMB_OFFSET:
19737 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 19738 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 19739 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 19740 return (base + 4) & ~3;
c19d1205 19741
2fc8bdac
ZW
19742 /* Thumb branches are simply offset by +4. */
19743 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19744 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19745 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19746 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 19747 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 19748 return base + 4;
bfae80f2 19749
267bf995 19750 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
19751 if (fixP->fx_addsy
19752 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19753 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19754 && ARM_IS_FUNC (fixP->fx_addsy)
19755 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19756 base = fixP->fx_where + fixP->fx_frag->fr_address;
19757 return base + 4;
19758
00adf2d4
JB
19759 /* BLX is like branches above, but forces the low two bits of PC to
19760 zero. */
486499d0
CL
19761 case BFD_RELOC_THUMB_PCREL_BLX:
19762 if (fixP->fx_addsy
19763 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19764 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19765 && THUMB_IS_FUNC (fixP->fx_addsy)
19766 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19767 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
19768 return (base + 4) & ~3;
19769
2fc8bdac
ZW
19770 /* ARM mode branches are offset by +8. However, the Windows CE
19771 loader expects the relocation not to take this into account. */
267bf995 19772 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
19773 if (fixP->fx_addsy
19774 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19775 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19776 && ARM_IS_FUNC (fixP->fx_addsy)
19777 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19778 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19779 return base + 8;
267bf995 19780
486499d0
CL
19781 case BFD_RELOC_ARM_PCREL_CALL:
19782 if (fixP->fx_addsy
19783 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19784 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19785 && THUMB_IS_FUNC (fixP->fx_addsy)
19786 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19787 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19788 return base + 8;
267bf995 19789
2fc8bdac 19790 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 19791 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 19792 case BFD_RELOC_ARM_PLT32:
c19d1205 19793#ifdef TE_WINCE
5f4273c7 19794 /* When handling fixups immediately, because we have already
53baae48
NC
19795 discovered the value of a symbol, or the address of the frag involved
19796 we must account for the offset by +8, as the OS loader will never see the reloc.
19797 see fixup_segment() in write.c
19798 The S_IS_EXTERNAL test handles the case of global symbols.
19799 Those need the calculated base, not just the pipe compensation the linker will need. */
19800 if (fixP->fx_pcrel
19801 && fixP->fx_addsy != NULL
19802 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19803 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
19804 return base + 8;
2fc8bdac 19805 return base;
c19d1205 19806#else
2fc8bdac 19807 return base + 8;
c19d1205 19808#endif
2fc8bdac 19809
267bf995 19810
2fc8bdac
ZW
19811 /* ARM mode loads relative to PC are also offset by +8. Unlike
19812 branches, the Windows CE loader *does* expect the relocation
19813 to take this into account. */
19814 case BFD_RELOC_ARM_OFFSET_IMM:
19815 case BFD_RELOC_ARM_OFFSET_IMM8:
19816 case BFD_RELOC_ARM_HWLITERAL:
19817 case BFD_RELOC_ARM_LITERAL:
19818 case BFD_RELOC_ARM_CP_OFF_IMM:
19819 return base + 8;
19820
19821
19822 /* Other PC-relative relocations are un-offset. */
19823 default:
19824 return base;
19825 }
bfae80f2
RE
19826}
19827
c19d1205
ZW
19828/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
19829 Otherwise we have no need to default values of symbols. */
19830
19831symbolS *
19832md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 19833{
c19d1205
ZW
19834#ifdef OBJ_ELF
19835 if (name[0] == '_' && name[1] == 'G'
19836 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
19837 {
19838 if (!GOT_symbol)
19839 {
19840 if (symbol_find (name))
bd3ba5d1 19841 as_bad (_("GOT already in the symbol table"));
bfae80f2 19842
c19d1205
ZW
19843 GOT_symbol = symbol_new (name, undefined_section,
19844 (valueT) 0, & zero_address_frag);
19845 }
bfae80f2 19846
c19d1205 19847 return GOT_symbol;
bfae80f2 19848 }
c19d1205 19849#endif
bfae80f2 19850
c921be7d 19851 return NULL;
bfae80f2
RE
19852}
19853
55cf6793 19854/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
19855 computed as two separate immediate values, added together. We
19856 already know that this value cannot be computed by just one ARM
19857 instruction. */
19858
19859static unsigned int
19860validate_immediate_twopart (unsigned int val,
19861 unsigned int * highpart)
bfae80f2 19862{
c19d1205
ZW
19863 unsigned int a;
19864 unsigned int i;
bfae80f2 19865
c19d1205
ZW
19866 for (i = 0; i < 32; i += 2)
19867 if (((a = rotate_left (val, i)) & 0xff) != 0)
19868 {
19869 if (a & 0xff00)
19870 {
19871 if (a & ~ 0xffff)
19872 continue;
19873 * highpart = (a >> 8) | ((i + 24) << 7);
19874 }
19875 else if (a & 0xff0000)
19876 {
19877 if (a & 0xff000000)
19878 continue;
19879 * highpart = (a >> 16) | ((i + 16) << 7);
19880 }
19881 else
19882 {
9c2799c2 19883 gas_assert (a & 0xff000000);
c19d1205
ZW
19884 * highpart = (a >> 24) | ((i + 8) << 7);
19885 }
bfae80f2 19886
c19d1205
ZW
19887 return (a & 0xff) | (i << 7);
19888 }
bfae80f2 19889
c19d1205 19890 return FAIL;
bfae80f2
RE
19891}
19892
c19d1205
ZW
19893static int
19894validate_offset_imm (unsigned int val, int hwse)
19895{
19896 if ((hwse && val > 255) || val > 4095)
19897 return FAIL;
19898 return val;
19899}
bfae80f2 19900
55cf6793 19901/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
19902 negative immediate constant by altering the instruction. A bit of
19903 a hack really.
19904 MOV <-> MVN
19905 AND <-> BIC
19906 ADC <-> SBC
19907 by inverting the second operand, and
19908 ADD <-> SUB
19909 CMP <-> CMN
19910 by negating the second operand. */
bfae80f2 19911
c19d1205
ZW
19912static int
19913negate_data_op (unsigned long * instruction,
19914 unsigned long value)
bfae80f2 19915{
c19d1205
ZW
19916 int op, new_inst;
19917 unsigned long negated, inverted;
bfae80f2 19918
c19d1205
ZW
19919 negated = encode_arm_immediate (-value);
19920 inverted = encode_arm_immediate (~value);
bfae80f2 19921
c19d1205
ZW
19922 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
19923 switch (op)
bfae80f2 19924 {
c19d1205
ZW
19925 /* First negates. */
19926 case OPCODE_SUB: /* ADD <-> SUB */
19927 new_inst = OPCODE_ADD;
19928 value = negated;
19929 break;
bfae80f2 19930
c19d1205
ZW
19931 case OPCODE_ADD:
19932 new_inst = OPCODE_SUB;
19933 value = negated;
19934 break;
bfae80f2 19935
c19d1205
ZW
19936 case OPCODE_CMP: /* CMP <-> CMN */
19937 new_inst = OPCODE_CMN;
19938 value = negated;
19939 break;
bfae80f2 19940
c19d1205
ZW
19941 case OPCODE_CMN:
19942 new_inst = OPCODE_CMP;
19943 value = negated;
19944 break;
bfae80f2 19945
c19d1205
ZW
19946 /* Now Inverted ops. */
19947 case OPCODE_MOV: /* MOV <-> MVN */
19948 new_inst = OPCODE_MVN;
19949 value = inverted;
19950 break;
bfae80f2 19951
c19d1205
ZW
19952 case OPCODE_MVN:
19953 new_inst = OPCODE_MOV;
19954 value = inverted;
19955 break;
bfae80f2 19956
c19d1205
ZW
19957 case OPCODE_AND: /* AND <-> BIC */
19958 new_inst = OPCODE_BIC;
19959 value = inverted;
19960 break;
bfae80f2 19961
c19d1205
ZW
19962 case OPCODE_BIC:
19963 new_inst = OPCODE_AND;
19964 value = inverted;
19965 break;
bfae80f2 19966
c19d1205
ZW
19967 case OPCODE_ADC: /* ADC <-> SBC */
19968 new_inst = OPCODE_SBC;
19969 value = inverted;
19970 break;
bfae80f2 19971
c19d1205
ZW
19972 case OPCODE_SBC:
19973 new_inst = OPCODE_ADC;
19974 value = inverted;
19975 break;
bfae80f2 19976
c19d1205
ZW
19977 /* We cannot do anything. */
19978 default:
19979 return FAIL;
b99bd4ef
NC
19980 }
19981
c19d1205
ZW
19982 if (value == (unsigned) FAIL)
19983 return FAIL;
19984
19985 *instruction &= OPCODE_MASK;
19986 *instruction |= new_inst << DATA_OP_SHIFT;
19987 return value;
b99bd4ef
NC
19988}
19989
ef8d22e6
PB
19990/* Like negate_data_op, but for Thumb-2. */
19991
19992static unsigned int
16dd5e42 19993thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
19994{
19995 int op, new_inst;
19996 int rd;
16dd5e42 19997 unsigned int negated, inverted;
ef8d22e6
PB
19998
19999 negated = encode_thumb32_immediate (-value);
20000 inverted = encode_thumb32_immediate (~value);
20001
20002 rd = (*instruction >> 8) & 0xf;
20003 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
20004 switch (op)
20005 {
20006 /* ADD <-> SUB. Includes CMP <-> CMN. */
20007 case T2_OPCODE_SUB:
20008 new_inst = T2_OPCODE_ADD;
20009 value = negated;
20010 break;
20011
20012 case T2_OPCODE_ADD:
20013 new_inst = T2_OPCODE_SUB;
20014 value = negated;
20015 break;
20016
20017 /* ORR <-> ORN. Includes MOV <-> MVN. */
20018 case T2_OPCODE_ORR:
20019 new_inst = T2_OPCODE_ORN;
20020 value = inverted;
20021 break;
20022
20023 case T2_OPCODE_ORN:
20024 new_inst = T2_OPCODE_ORR;
20025 value = inverted;
20026 break;
20027
20028 /* AND <-> BIC. TST has no inverted equivalent. */
20029 case T2_OPCODE_AND:
20030 new_inst = T2_OPCODE_BIC;
20031 if (rd == 15)
20032 value = FAIL;
20033 else
20034 value = inverted;
20035 break;
20036
20037 case T2_OPCODE_BIC:
20038 new_inst = T2_OPCODE_AND;
20039 value = inverted;
20040 break;
20041
20042 /* ADC <-> SBC */
20043 case T2_OPCODE_ADC:
20044 new_inst = T2_OPCODE_SBC;
20045 value = inverted;
20046 break;
20047
20048 case T2_OPCODE_SBC:
20049 new_inst = T2_OPCODE_ADC;
20050 value = inverted;
20051 break;
20052
20053 /* We cannot do anything. */
20054 default:
20055 return FAIL;
20056 }
20057
16dd5e42 20058 if (value == (unsigned int)FAIL)
ef8d22e6
PB
20059 return FAIL;
20060
20061 *instruction &= T2_OPCODE_MASK;
20062 *instruction |= new_inst << T2_DATA_OP_SHIFT;
20063 return value;
20064}
20065
8f06b2d8
PB
20066/* Read a 32-bit thumb instruction from buf. */
20067static unsigned long
20068get_thumb32_insn (char * buf)
20069{
20070 unsigned long insn;
20071 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
20072 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20073
20074 return insn;
20075}
20076
a8bc6c78
PB
20077
20078/* We usually want to set the low bit on the address of thumb function
20079 symbols. In particular .word foo - . should have the low bit set.
20080 Generic code tries to fold the difference of two symbols to
20081 a constant. Prevent this and force a relocation when the first symbols
20082 is a thumb function. */
c921be7d
NC
20083
20084bfd_boolean
a8bc6c78
PB
20085arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
20086{
20087 if (op == O_subtract
20088 && l->X_op == O_symbol
20089 && r->X_op == O_symbol
20090 && THUMB_IS_FUNC (l->X_add_symbol))
20091 {
20092 l->X_op = O_subtract;
20093 l->X_op_symbol = r->X_add_symbol;
20094 l->X_add_number -= r->X_add_number;
c921be7d 20095 return TRUE;
a8bc6c78 20096 }
c921be7d 20097
a8bc6c78 20098 /* Process as normal. */
c921be7d 20099 return FALSE;
a8bc6c78
PB
20100}
20101
4a42ebbc
RR
20102/* Encode Thumb2 unconditional branches and calls. The encoding
20103 for the 2 are identical for the immediate values. */
20104
20105static void
20106encode_thumb2_b_bl_offset (char * buf, offsetT value)
20107{
20108#define T2I1I2MASK ((1 << 13) | (1 << 11))
20109 offsetT newval;
20110 offsetT newval2;
20111 addressT S, I1, I2, lo, hi;
20112
20113 S = (value >> 24) & 0x01;
20114 I1 = (value >> 23) & 0x01;
20115 I2 = (value >> 22) & 0x01;
20116 hi = (value >> 12) & 0x3ff;
20117 lo = (value >> 1) & 0x7ff;
20118 newval = md_chars_to_number (buf, THUMB_SIZE);
20119 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20120 newval |= (S << 10) | hi;
20121 newval2 &= ~T2I1I2MASK;
20122 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
20123 md_number_to_chars (buf, newval, THUMB_SIZE);
20124 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20125}
20126
c19d1205 20127void
55cf6793 20128md_apply_fix (fixS * fixP,
c19d1205
ZW
20129 valueT * valP,
20130 segT seg)
20131{
20132 offsetT value = * valP;
20133 offsetT newval;
20134 unsigned int newimm;
20135 unsigned long temp;
20136 int sign;
20137 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 20138
9c2799c2 20139 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 20140
c19d1205 20141 /* Note whether this will delete the relocation. */
4962c51a 20142
c19d1205
ZW
20143 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
20144 fixP->fx_done = 1;
b99bd4ef 20145
adbaf948 20146 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 20147 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
20148 for emit_reloc. */
20149 value &= 0xffffffff;
20150 value ^= 0x80000000;
5f4273c7 20151 value -= 0x80000000;
adbaf948
ZW
20152
20153 *valP = value;
c19d1205 20154 fixP->fx_addnumber = value;
b99bd4ef 20155
adbaf948
ZW
20156 /* Same treatment for fixP->fx_offset. */
20157 fixP->fx_offset &= 0xffffffff;
20158 fixP->fx_offset ^= 0x80000000;
20159 fixP->fx_offset -= 0x80000000;
20160
c19d1205 20161 switch (fixP->fx_r_type)
b99bd4ef 20162 {
c19d1205
ZW
20163 case BFD_RELOC_NONE:
20164 /* This will need to go in the object file. */
20165 fixP->fx_done = 0;
20166 break;
b99bd4ef 20167
c19d1205
ZW
20168 case BFD_RELOC_ARM_IMMEDIATE:
20169 /* We claim that this fixup has been processed here,
20170 even if in fact we generate an error because we do
20171 not have a reloc for it, so tc_gen_reloc will reject it. */
20172 fixP->fx_done = 1;
b99bd4ef 20173
77db8e2e 20174 if (fixP->fx_addsy)
b99bd4ef 20175 {
77db8e2e 20176 const char *msg = 0;
b99bd4ef 20177
77db8e2e
NC
20178 if (! S_IS_DEFINED (fixP->fx_addsy))
20179 msg = _("undefined symbol %s used as an immediate value");
20180 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20181 msg = _("symbol %s is in a different section");
20182 else if (S_IS_WEAK (fixP->fx_addsy))
20183 msg = _("symbol %s is weak and may be overridden later");
20184
20185 if (msg)
20186 {
20187 as_bad_where (fixP->fx_file, fixP->fx_line,
20188 msg, S_GET_NAME (fixP->fx_addsy));
20189 break;
20190 }
42e5fcbf
AS
20191 }
20192
c19d1205
ZW
20193 newimm = encode_arm_immediate (value);
20194 temp = md_chars_to_number (buf, INSN_SIZE);
20195
20196 /* If the instruction will fail, see if we can fix things up by
20197 changing the opcode. */
20198 if (newimm == (unsigned int) FAIL
20199 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 20200 {
c19d1205
ZW
20201 as_bad_where (fixP->fx_file, fixP->fx_line,
20202 _("invalid constant (%lx) after fixup"),
20203 (unsigned long) value);
20204 break;
b99bd4ef 20205 }
b99bd4ef 20206
c19d1205
ZW
20207 newimm |= (temp & 0xfffff000);
20208 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20209 break;
b99bd4ef 20210
c19d1205
ZW
20211 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20212 {
20213 unsigned int highpart = 0;
20214 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 20215
77db8e2e 20216 if (fixP->fx_addsy)
42e5fcbf 20217 {
77db8e2e 20218 const char *msg = 0;
42e5fcbf 20219
77db8e2e
NC
20220 if (! S_IS_DEFINED (fixP->fx_addsy))
20221 msg = _("undefined symbol %s used as an immediate value");
20222 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20223 msg = _("symbol %s is in a different section");
20224 else if (S_IS_WEAK (fixP->fx_addsy))
20225 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 20226
77db8e2e
NC
20227 if (msg)
20228 {
20229 as_bad_where (fixP->fx_file, fixP->fx_line,
20230 msg, S_GET_NAME (fixP->fx_addsy));
20231 break;
20232 }
20233 }
20234
c19d1205
ZW
20235 newimm = encode_arm_immediate (value);
20236 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 20237
c19d1205
ZW
20238 /* If the instruction will fail, see if we can fix things up by
20239 changing the opcode. */
20240 if (newimm == (unsigned int) FAIL
20241 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
20242 {
20243 /* No ? OK - try using two ADD instructions to generate
20244 the value. */
20245 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 20246
c19d1205
ZW
20247 /* Yes - then make sure that the second instruction is
20248 also an add. */
20249 if (newimm != (unsigned int) FAIL)
20250 newinsn = temp;
20251 /* Still No ? Try using a negated value. */
20252 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
20253 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
20254 /* Otherwise - give up. */
20255 else
20256 {
20257 as_bad_where (fixP->fx_file, fixP->fx_line,
20258 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
20259 (long) value);
20260 break;
20261 }
b99bd4ef 20262
c19d1205
ZW
20263 /* Replace the first operand in the 2nd instruction (which
20264 is the PC) with the destination register. We have
20265 already added in the PC in the first instruction and we
20266 do not want to do it again. */
20267 newinsn &= ~ 0xf0000;
20268 newinsn |= ((newinsn & 0x0f000) << 4);
20269 }
b99bd4ef 20270
c19d1205
ZW
20271 newimm |= (temp & 0xfffff000);
20272 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 20273
c19d1205
ZW
20274 highpart |= (newinsn & 0xfffff000);
20275 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
20276 }
20277 break;
b99bd4ef 20278
c19d1205 20279 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
20280 if (!fixP->fx_done && seg->use_rela_p)
20281 value = 0;
20282
c19d1205
ZW
20283 case BFD_RELOC_ARM_LITERAL:
20284 sign = value >= 0;
b99bd4ef 20285
c19d1205
ZW
20286 if (value < 0)
20287 value = - value;
b99bd4ef 20288
c19d1205 20289 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 20290 {
c19d1205
ZW
20291 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
20292 as_bad_where (fixP->fx_file, fixP->fx_line,
20293 _("invalid literal constant: pool needs to be closer"));
20294 else
20295 as_bad_where (fixP->fx_file, fixP->fx_line,
20296 _("bad immediate value for offset (%ld)"),
20297 (long) value);
20298 break;
f03698e6
RE
20299 }
20300
c19d1205
ZW
20301 newval = md_chars_to_number (buf, INSN_SIZE);
20302 newval &= 0xff7ff000;
20303 newval |= value | (sign ? INDEX_UP : 0);
20304 md_number_to_chars (buf, newval, INSN_SIZE);
20305 break;
b99bd4ef 20306
c19d1205
ZW
20307 case BFD_RELOC_ARM_OFFSET_IMM8:
20308 case BFD_RELOC_ARM_HWLITERAL:
20309 sign = value >= 0;
b99bd4ef 20310
c19d1205
ZW
20311 if (value < 0)
20312 value = - value;
b99bd4ef 20313
c19d1205 20314 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 20315 {
c19d1205
ZW
20316 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
20317 as_bad_where (fixP->fx_file, fixP->fx_line,
20318 _("invalid literal constant: pool needs to be closer"));
20319 else
f9d4405b 20320 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
20321 (long) value);
20322 break;
b99bd4ef
NC
20323 }
20324
c19d1205
ZW
20325 newval = md_chars_to_number (buf, INSN_SIZE);
20326 newval &= 0xff7ff0f0;
20327 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
20328 md_number_to_chars (buf, newval, INSN_SIZE);
20329 break;
b99bd4ef 20330
c19d1205
ZW
20331 case BFD_RELOC_ARM_T32_OFFSET_U8:
20332 if (value < 0 || value > 1020 || value % 4 != 0)
20333 as_bad_where (fixP->fx_file, fixP->fx_line,
20334 _("bad immediate value for offset (%ld)"), (long) value);
20335 value /= 4;
b99bd4ef 20336
c19d1205 20337 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
20338 newval |= value;
20339 md_number_to_chars (buf+2, newval, THUMB_SIZE);
20340 break;
b99bd4ef 20341
c19d1205
ZW
20342 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20343 /* This is a complicated relocation used for all varieties of Thumb32
20344 load/store instruction with immediate offset:
20345
20346 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
20347 *4, optional writeback(W)
20348 (doubleword load/store)
20349
20350 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
20351 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
20352 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
20353 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
20354 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
20355
20356 Uppercase letters indicate bits that are already encoded at
20357 this point. Lowercase letters are our problem. For the
20358 second block of instructions, the secondary opcode nybble
20359 (bits 8..11) is present, and bit 23 is zero, even if this is
20360 a PC-relative operation. */
20361 newval = md_chars_to_number (buf, THUMB_SIZE);
20362 newval <<= 16;
20363 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 20364
c19d1205 20365 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 20366 {
c19d1205
ZW
20367 /* Doubleword load/store: 8-bit offset, scaled by 4. */
20368 if (value >= 0)
20369 newval |= (1 << 23);
20370 else
20371 value = -value;
20372 if (value % 4 != 0)
20373 {
20374 as_bad_where (fixP->fx_file, fixP->fx_line,
20375 _("offset not a multiple of 4"));
20376 break;
20377 }
20378 value /= 4;
216d22bc 20379 if (value > 0xff)
c19d1205
ZW
20380 {
20381 as_bad_where (fixP->fx_file, fixP->fx_line,
20382 _("offset out of range"));
20383 break;
20384 }
20385 newval &= ~0xff;
b99bd4ef 20386 }
c19d1205 20387 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 20388 {
c19d1205
ZW
20389 /* PC-relative, 12-bit offset. */
20390 if (value >= 0)
20391 newval |= (1 << 23);
20392 else
20393 value = -value;
216d22bc 20394 if (value > 0xfff)
c19d1205
ZW
20395 {
20396 as_bad_where (fixP->fx_file, fixP->fx_line,
20397 _("offset out of range"));
20398 break;
20399 }
20400 newval &= ~0xfff;
b99bd4ef 20401 }
c19d1205 20402 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 20403 {
c19d1205
ZW
20404 /* Writeback: 8-bit, +/- offset. */
20405 if (value >= 0)
20406 newval |= (1 << 9);
20407 else
20408 value = -value;
216d22bc 20409 if (value > 0xff)
c19d1205
ZW
20410 {
20411 as_bad_where (fixP->fx_file, fixP->fx_line,
20412 _("offset out of range"));
20413 break;
20414 }
20415 newval &= ~0xff;
b99bd4ef 20416 }
c19d1205 20417 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 20418 {
c19d1205 20419 /* T-instruction: positive 8-bit offset. */
216d22bc 20420 if (value < 0 || value > 0xff)
b99bd4ef 20421 {
c19d1205
ZW
20422 as_bad_where (fixP->fx_file, fixP->fx_line,
20423 _("offset out of range"));
20424 break;
b99bd4ef 20425 }
c19d1205
ZW
20426 newval &= ~0xff;
20427 newval |= value;
b99bd4ef
NC
20428 }
20429 else
b99bd4ef 20430 {
c19d1205
ZW
20431 /* Positive 12-bit or negative 8-bit offset. */
20432 int limit;
20433 if (value >= 0)
b99bd4ef 20434 {
c19d1205
ZW
20435 newval |= (1 << 23);
20436 limit = 0xfff;
20437 }
20438 else
20439 {
20440 value = -value;
20441 limit = 0xff;
20442 }
20443 if (value > limit)
20444 {
20445 as_bad_where (fixP->fx_file, fixP->fx_line,
20446 _("offset out of range"));
20447 break;
b99bd4ef 20448 }
c19d1205 20449 newval &= ~limit;
b99bd4ef 20450 }
b99bd4ef 20451
c19d1205
ZW
20452 newval |= value;
20453 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20454 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20455 break;
404ff6b5 20456
c19d1205
ZW
20457 case BFD_RELOC_ARM_SHIFT_IMM:
20458 newval = md_chars_to_number (buf, INSN_SIZE);
20459 if (((unsigned long) value) > 32
20460 || (value == 32
20461 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20462 {
20463 as_bad_where (fixP->fx_file, fixP->fx_line,
20464 _("shift expression is too large"));
20465 break;
20466 }
404ff6b5 20467
c19d1205
ZW
20468 if (value == 0)
20469 /* Shifts of zero must be done as lsl. */
20470 newval &= ~0x60;
20471 else if (value == 32)
20472 value = 0;
20473 newval &= 0xfffff07f;
20474 newval |= (value & 0x1f) << 7;
20475 md_number_to_chars (buf, newval, INSN_SIZE);
20476 break;
404ff6b5 20477
c19d1205 20478 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 20479 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 20480 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 20481 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
20482 /* We claim that this fixup has been processed here,
20483 even if in fact we generate an error because we do
20484 not have a reloc for it, so tc_gen_reloc will reject it. */
20485 fixP->fx_done = 1;
404ff6b5 20486
c19d1205
ZW
20487 if (fixP->fx_addsy
20488 && ! S_IS_DEFINED (fixP->fx_addsy))
20489 {
20490 as_bad_where (fixP->fx_file, fixP->fx_line,
20491 _("undefined symbol %s used as an immediate value"),
20492 S_GET_NAME (fixP->fx_addsy));
20493 break;
20494 }
404ff6b5 20495
c19d1205
ZW
20496 newval = md_chars_to_number (buf, THUMB_SIZE);
20497 newval <<= 16;
20498 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 20499
16805f35
PB
20500 newimm = FAIL;
20501 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20502 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
20503 {
20504 newimm = encode_thumb32_immediate (value);
20505 if (newimm == (unsigned int) FAIL)
20506 newimm = thumb32_negate_data_op (&newval, value);
20507 }
16805f35
PB
20508 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20509 && newimm == (unsigned int) FAIL)
92e90b6e 20510 {
16805f35
PB
20511 /* Turn add/sum into addw/subw. */
20512 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20513 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
20514 /* No flat 12-bit imm encoding for addsw/subsw. */
20515 if ((newval & 0x00100000) == 0)
e9f89963 20516 {
40f246e3
NC
20517 /* 12 bit immediate for addw/subw. */
20518 if (value < 0)
20519 {
20520 value = -value;
20521 newval ^= 0x00a00000;
20522 }
20523 if (value > 0xfff)
20524 newimm = (unsigned int) FAIL;
20525 else
20526 newimm = value;
e9f89963 20527 }
92e90b6e 20528 }
cc8a6dd0 20529
c19d1205 20530 if (newimm == (unsigned int)FAIL)
3631a3c8 20531 {
c19d1205
ZW
20532 as_bad_where (fixP->fx_file, fixP->fx_line,
20533 _("invalid constant (%lx) after fixup"),
20534 (unsigned long) value);
20535 break;
3631a3c8
NC
20536 }
20537
c19d1205
ZW
20538 newval |= (newimm & 0x800) << 15;
20539 newval |= (newimm & 0x700) << 4;
20540 newval |= (newimm & 0x0ff);
cc8a6dd0 20541
c19d1205
ZW
20542 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20543 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20544 break;
a737bd4d 20545
3eb17e6b 20546 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
20547 if (((unsigned long) value) > 0xffff)
20548 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 20549 _("invalid smc expression"));
2fc8bdac 20550 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20551 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20552 md_number_to_chars (buf, newval, INSN_SIZE);
20553 break;
a737bd4d 20554
90ec0d68
MGD
20555 case BFD_RELOC_ARM_HVC:
20556 if (((unsigned long) value) > 0xffff)
20557 as_bad_where (fixP->fx_file, fixP->fx_line,
20558 _("invalid hvc expression"));
20559 newval = md_chars_to_number (buf, INSN_SIZE);
20560 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20561 md_number_to_chars (buf, newval, INSN_SIZE);
20562 break;
20563
c19d1205 20564 case BFD_RELOC_ARM_SWI:
adbaf948 20565 if (fixP->tc_fix_data != 0)
c19d1205
ZW
20566 {
20567 if (((unsigned long) value) > 0xff)
20568 as_bad_where (fixP->fx_file, fixP->fx_line,
20569 _("invalid swi expression"));
2fc8bdac 20570 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
20571 newval |= value;
20572 md_number_to_chars (buf, newval, THUMB_SIZE);
20573 }
20574 else
20575 {
20576 if (((unsigned long) value) > 0x00ffffff)
20577 as_bad_where (fixP->fx_file, fixP->fx_line,
20578 _("invalid swi expression"));
2fc8bdac 20579 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20580 newval |= value;
20581 md_number_to_chars (buf, newval, INSN_SIZE);
20582 }
20583 break;
a737bd4d 20584
c19d1205
ZW
20585 case BFD_RELOC_ARM_MULTI:
20586 if (((unsigned long) value) > 0xffff)
20587 as_bad_where (fixP->fx_file, fixP->fx_line,
20588 _("invalid expression in load/store multiple"));
20589 newval = value | md_chars_to_number (buf, INSN_SIZE);
20590 md_number_to_chars (buf, newval, INSN_SIZE);
20591 break;
a737bd4d 20592
c19d1205 20593#ifdef OBJ_ELF
39b41c9c 20594 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
20595
20596 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20597 && fixP->fx_addsy
20598 && !S_IS_EXTERNAL (fixP->fx_addsy)
20599 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20600 && THUMB_IS_FUNC (fixP->fx_addsy))
20601 /* Flip the bl to blx. This is a simple flip
20602 bit here because we generate PCREL_CALL for
20603 unconditional bls. */
20604 {
20605 newval = md_chars_to_number (buf, INSN_SIZE);
20606 newval = newval | 0x10000000;
20607 md_number_to_chars (buf, newval, INSN_SIZE);
20608 temp = 1;
20609 fixP->fx_done = 1;
20610 }
39b41c9c
PB
20611 else
20612 temp = 3;
20613 goto arm_branch_common;
20614
20615 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
20616 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20617 && fixP->fx_addsy
20618 && !S_IS_EXTERNAL (fixP->fx_addsy)
20619 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20620 && THUMB_IS_FUNC (fixP->fx_addsy))
20621 {
20622 /* This would map to a bl<cond>, b<cond>,
20623 b<always> to a Thumb function. We
20624 need to force a relocation for this particular
20625 case. */
20626 newval = md_chars_to_number (buf, INSN_SIZE);
20627 fixP->fx_done = 0;
20628 }
20629
2fc8bdac 20630 case BFD_RELOC_ARM_PLT32:
c19d1205 20631#endif
39b41c9c
PB
20632 case BFD_RELOC_ARM_PCREL_BRANCH:
20633 temp = 3;
20634 goto arm_branch_common;
a737bd4d 20635
39b41c9c 20636 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 20637
39b41c9c 20638 temp = 1;
267bf995
RR
20639 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20640 && fixP->fx_addsy
20641 && !S_IS_EXTERNAL (fixP->fx_addsy)
20642 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20643 && ARM_IS_FUNC (fixP->fx_addsy))
20644 {
20645 /* Flip the blx to a bl and warn. */
20646 const char *name = S_GET_NAME (fixP->fx_addsy);
20647 newval = 0xeb000000;
20648 as_warn_where (fixP->fx_file, fixP->fx_line,
20649 _("blx to '%s' an ARM ISA state function changed to bl"),
20650 name);
20651 md_number_to_chars (buf, newval, INSN_SIZE);
20652 temp = 3;
20653 fixP->fx_done = 1;
20654 }
20655
20656#ifdef OBJ_ELF
20657 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20658 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20659#endif
20660
39b41c9c 20661 arm_branch_common:
c19d1205 20662 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
20663 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20664 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20665 also be be clear. */
20666 if (value & temp)
c19d1205 20667 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
20668 _("misaligned branch destination"));
20669 if ((value & (offsetT)0xfe000000) != (offsetT)0
20670 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20671 as_bad_where (fixP->fx_file, fixP->fx_line,
20672 _("branch out of range"));
a737bd4d 20673
2fc8bdac 20674 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20675 {
2fc8bdac
ZW
20676 newval = md_chars_to_number (buf, INSN_SIZE);
20677 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
20678 /* Set the H bit on BLX instructions. */
20679 if (temp == 1)
20680 {
20681 if (value & 2)
20682 newval |= 0x01000000;
20683 else
20684 newval &= ~0x01000000;
20685 }
2fc8bdac 20686 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 20687 }
c19d1205 20688 break;
a737bd4d 20689
25fe350b
MS
20690 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20691 /* CBZ can only branch forward. */
a737bd4d 20692
738755b0
MS
20693 /* Attempts to use CBZ to branch to the next instruction
20694 (which, strictly speaking, are prohibited) will be turned into
20695 no-ops.
20696
20697 FIXME: It may be better to remove the instruction completely and
20698 perform relaxation. */
20699 if (value == -2)
2fc8bdac
ZW
20700 {
20701 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 20702 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
20703 md_number_to_chars (buf, newval, THUMB_SIZE);
20704 }
738755b0
MS
20705 else
20706 {
20707 if (value & ~0x7e)
20708 as_bad_where (fixP->fx_file, fixP->fx_line,
20709 _("branch out of range"));
20710
20711 if (fixP->fx_done || !seg->use_rela_p)
20712 {
20713 newval = md_chars_to_number (buf, THUMB_SIZE);
20714 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20715 md_number_to_chars (buf, newval, THUMB_SIZE);
20716 }
20717 }
c19d1205 20718 break;
a737bd4d 20719
c19d1205 20720 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
20721 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20722 as_bad_where (fixP->fx_file, fixP->fx_line,
20723 _("branch out of range"));
a737bd4d 20724
2fc8bdac
ZW
20725 if (fixP->fx_done || !seg->use_rela_p)
20726 {
20727 newval = md_chars_to_number (buf, THUMB_SIZE);
20728 newval |= (value & 0x1ff) >> 1;
20729 md_number_to_chars (buf, newval, THUMB_SIZE);
20730 }
c19d1205 20731 break;
a737bd4d 20732
c19d1205 20733 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
20734 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20735 as_bad_where (fixP->fx_file, fixP->fx_line,
20736 _("branch out of range"));
a737bd4d 20737
2fc8bdac
ZW
20738 if (fixP->fx_done || !seg->use_rela_p)
20739 {
20740 newval = md_chars_to_number (buf, THUMB_SIZE);
20741 newval |= (value & 0xfff) >> 1;
20742 md_number_to_chars (buf, newval, THUMB_SIZE);
20743 }
c19d1205 20744 break;
a737bd4d 20745
c19d1205 20746 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
20747 if (fixP->fx_addsy
20748 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20749 && !S_IS_EXTERNAL (fixP->fx_addsy)
20750 && S_IS_DEFINED (fixP->fx_addsy)
20751 && ARM_IS_FUNC (fixP->fx_addsy)
20752 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20753 {
20754 /* Force a relocation for a branch 20 bits wide. */
20755 fixP->fx_done = 0;
20756 }
2fc8bdac
ZW
20757 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20758 as_bad_where (fixP->fx_file, fixP->fx_line,
20759 _("conditional branch out of range"));
404ff6b5 20760
2fc8bdac
ZW
20761 if (fixP->fx_done || !seg->use_rela_p)
20762 {
20763 offsetT newval2;
20764 addressT S, J1, J2, lo, hi;
404ff6b5 20765
2fc8bdac
ZW
20766 S = (value & 0x00100000) >> 20;
20767 J2 = (value & 0x00080000) >> 19;
20768 J1 = (value & 0x00040000) >> 18;
20769 hi = (value & 0x0003f000) >> 12;
20770 lo = (value & 0x00000ffe) >> 1;
6c43fab6 20771
2fc8bdac
ZW
20772 newval = md_chars_to_number (buf, THUMB_SIZE);
20773 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20774 newval |= (S << 10) | hi;
20775 newval2 |= (J1 << 13) | (J2 << 11) | lo;
20776 md_number_to_chars (buf, newval, THUMB_SIZE);
20777 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20778 }
c19d1205 20779 break;
6c43fab6 20780
c19d1205 20781 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
20782
20783 /* If there is a blx from a thumb state function to
20784 another thumb function flip this to a bl and warn
20785 about it. */
20786
20787 if (fixP->fx_addsy
20788 && S_IS_DEFINED (fixP->fx_addsy)
20789 && !S_IS_EXTERNAL (fixP->fx_addsy)
20790 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20791 && THUMB_IS_FUNC (fixP->fx_addsy))
20792 {
20793 const char *name = S_GET_NAME (fixP->fx_addsy);
20794 as_warn_where (fixP->fx_file, fixP->fx_line,
20795 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
20796 name);
20797 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20798 newval = newval | 0x1000;
20799 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20800 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20801 fixP->fx_done = 1;
20802 }
20803
20804
20805 goto thumb_bl_common;
20806
c19d1205 20807 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
20808
20809 /* A bl from Thumb state ISA to an internal ARM state function
20810 is converted to a blx. */
20811 if (fixP->fx_addsy
20812 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20813 && !S_IS_EXTERNAL (fixP->fx_addsy)
20814 && S_IS_DEFINED (fixP->fx_addsy)
20815 && ARM_IS_FUNC (fixP->fx_addsy)
20816 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20817 {
20818 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20819 newval = newval & ~0x1000;
20820 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20821 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
20822 fixP->fx_done = 1;
20823 }
20824
20825 thumb_bl_common:
20826
20827#ifdef OBJ_ELF
20828 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
20829 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20830 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20831#endif
20832
2fc8bdac
ZW
20833 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20834 /* For a BLX instruction, make sure that the relocation is rounded up
20835 to a word boundary. This follows the semantics of the instruction
20836 which specifies that bit 1 of the target address will come from bit
20837 1 of the base address. */
20838 value = (value + 1) & ~ 1;
404ff6b5 20839
2fc8bdac 20840
4a42ebbc
RR
20841 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
20842 {
20843 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
20844 {
20845 as_bad_where (fixP->fx_file, fixP->fx_line,
20846 _("branch out of range"));
20847 }
20848 else if ((value & ~0x1ffffff)
20849 && ((value & ~0x1ffffff) != ~0x1ffffff))
20850 {
20851 as_bad_where (fixP->fx_file, fixP->fx_line,
20852 _("Thumb2 branch out of range"));
20853 }
c19d1205 20854 }
4a42ebbc
RR
20855
20856 if (fixP->fx_done || !seg->use_rela_p)
20857 encode_thumb2_b_bl_offset (buf, value);
20858
c19d1205 20859 break;
404ff6b5 20860
c19d1205 20861 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
20862 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
20863 as_bad_where (fixP->fx_file, fixP->fx_line,
20864 _("branch out of range"));
6c43fab6 20865
2fc8bdac 20866 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 20867 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 20868
2fc8bdac 20869 break;
a737bd4d 20870
2fc8bdac
ZW
20871 case BFD_RELOC_8:
20872 if (fixP->fx_done || !seg->use_rela_p)
20873 md_number_to_chars (buf, value, 1);
c19d1205 20874 break;
a737bd4d 20875
c19d1205 20876 case BFD_RELOC_16:
2fc8bdac 20877 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20878 md_number_to_chars (buf, value, 2);
c19d1205 20879 break;
a737bd4d 20880
c19d1205 20881#ifdef OBJ_ELF
0855e32b
NS
20882 case BFD_RELOC_ARM_TLS_CALL:
20883 case BFD_RELOC_ARM_THM_TLS_CALL:
20884 case BFD_RELOC_ARM_TLS_DESCSEQ:
20885 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
20886 S_SET_THREAD_LOCAL (fixP->fx_addsy);
20887 break;
20888
20889 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
20890 case BFD_RELOC_ARM_TLS_GD32:
20891 case BFD_RELOC_ARM_TLS_LE32:
20892 case BFD_RELOC_ARM_TLS_IE32:
20893 case BFD_RELOC_ARM_TLS_LDM32:
20894 case BFD_RELOC_ARM_TLS_LDO32:
20895 S_SET_THREAD_LOCAL (fixP->fx_addsy);
20896 /* fall through */
6c43fab6 20897
c19d1205
ZW
20898 case BFD_RELOC_ARM_GOT32:
20899 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
20900 if (fixP->fx_done || !seg->use_rela_p)
20901 md_number_to_chars (buf, 0, 4);
c19d1205 20902 break;
b43420e6
NC
20903
20904 case BFD_RELOC_ARM_GOT_PREL:
20905 if (fixP->fx_done || !seg->use_rela_p)
20906 md_number_to_chars (buf, value, 4);
20907 break;
20908
9a6f4e97
NS
20909 case BFD_RELOC_ARM_TARGET2:
20910 /* TARGET2 is not partial-inplace, so we need to write the
20911 addend here for REL targets, because it won't be written out
20912 during reloc processing later. */
20913 if (fixP->fx_done || !seg->use_rela_p)
20914 md_number_to_chars (buf, fixP->fx_offset, 4);
20915 break;
c19d1205 20916#endif
6c43fab6 20917
c19d1205
ZW
20918 case BFD_RELOC_RVA:
20919 case BFD_RELOC_32:
20920 case BFD_RELOC_ARM_TARGET1:
20921 case BFD_RELOC_ARM_ROSEGREL32:
20922 case BFD_RELOC_ARM_SBREL32:
20923 case BFD_RELOC_32_PCREL:
f0927246
NC
20924#ifdef TE_PE
20925 case BFD_RELOC_32_SECREL:
20926#endif
2fc8bdac 20927 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
20928#ifdef TE_WINCE
20929 /* For WinCE we only do this for pcrel fixups. */
20930 if (fixP->fx_done || fixP->fx_pcrel)
20931#endif
20932 md_number_to_chars (buf, value, 4);
c19d1205 20933 break;
6c43fab6 20934
c19d1205
ZW
20935#ifdef OBJ_ELF
20936 case BFD_RELOC_ARM_PREL31:
2fc8bdac 20937 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
20938 {
20939 newval = md_chars_to_number (buf, 4) & 0x80000000;
20940 if ((value ^ (value >> 1)) & 0x40000000)
20941 {
20942 as_bad_where (fixP->fx_file, fixP->fx_line,
20943 _("rel31 relocation overflow"));
20944 }
20945 newval |= value & 0x7fffffff;
20946 md_number_to_chars (buf, newval, 4);
20947 }
20948 break;
c19d1205 20949#endif
a737bd4d 20950
c19d1205 20951 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 20952 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
20953 if (value < -1023 || value > 1023 || (value & 3))
20954 as_bad_where (fixP->fx_file, fixP->fx_line,
20955 _("co-processor offset out of range"));
20956 cp_off_common:
20957 sign = value >= 0;
20958 if (value < 0)
20959 value = -value;
8f06b2d8
PB
20960 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20961 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20962 newval = md_chars_to_number (buf, INSN_SIZE);
20963 else
20964 newval = get_thumb32_insn (buf);
20965 newval &= 0xff7fff00;
c19d1205 20966 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
20967 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20968 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20969 md_number_to_chars (buf, newval, INSN_SIZE);
20970 else
20971 put_thumb32_insn (buf, newval);
c19d1205 20972 break;
a737bd4d 20973
c19d1205 20974 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 20975 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
20976 if (value < -255 || value > 255)
20977 as_bad_where (fixP->fx_file, fixP->fx_line,
20978 _("co-processor offset out of range"));
df7849c5 20979 value *= 4;
c19d1205 20980 goto cp_off_common;
6c43fab6 20981
c19d1205
ZW
20982 case BFD_RELOC_ARM_THUMB_OFFSET:
20983 newval = md_chars_to_number (buf, THUMB_SIZE);
20984 /* Exactly what ranges, and where the offset is inserted depends
20985 on the type of instruction, we can establish this from the
20986 top 4 bits. */
20987 switch (newval >> 12)
20988 {
20989 case 4: /* PC load. */
20990 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
20991 forced to zero for these loads; md_pcrel_from has already
20992 compensated for this. */
20993 if (value & 3)
20994 as_bad_where (fixP->fx_file, fixP->fx_line,
20995 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
20996 (((unsigned long) fixP->fx_frag->fr_address
20997 + (unsigned long) fixP->fx_where) & ~3)
20998 + (unsigned long) value);
a737bd4d 20999
c19d1205
ZW
21000 if (value & ~0x3fc)
21001 as_bad_where (fixP->fx_file, fixP->fx_line,
21002 _("invalid offset, value too big (0x%08lX)"),
21003 (long) value);
a737bd4d 21004
c19d1205
ZW
21005 newval |= value >> 2;
21006 break;
a737bd4d 21007
c19d1205
ZW
21008 case 9: /* SP load/store. */
21009 if (value & ~0x3fc)
21010 as_bad_where (fixP->fx_file, fixP->fx_line,
21011 _("invalid offset, value too big (0x%08lX)"),
21012 (long) value);
21013 newval |= value >> 2;
21014 break;
6c43fab6 21015
c19d1205
ZW
21016 case 6: /* Word load/store. */
21017 if (value & ~0x7c)
21018 as_bad_where (fixP->fx_file, fixP->fx_line,
21019 _("invalid offset, value too big (0x%08lX)"),
21020 (long) value);
21021 newval |= value << 4; /* 6 - 2. */
21022 break;
a737bd4d 21023
c19d1205
ZW
21024 case 7: /* Byte load/store. */
21025 if (value & ~0x1f)
21026 as_bad_where (fixP->fx_file, fixP->fx_line,
21027 _("invalid offset, value too big (0x%08lX)"),
21028 (long) value);
21029 newval |= value << 6;
21030 break;
a737bd4d 21031
c19d1205
ZW
21032 case 8: /* Halfword load/store. */
21033 if (value & ~0x3e)
21034 as_bad_where (fixP->fx_file, fixP->fx_line,
21035 _("invalid offset, value too big (0x%08lX)"),
21036 (long) value);
21037 newval |= value << 5; /* 6 - 1. */
21038 break;
a737bd4d 21039
c19d1205
ZW
21040 default:
21041 as_bad_where (fixP->fx_file, fixP->fx_line,
21042 "Unable to process relocation for thumb opcode: %lx",
21043 (unsigned long) newval);
21044 break;
21045 }
21046 md_number_to_chars (buf, newval, THUMB_SIZE);
21047 break;
a737bd4d 21048
c19d1205
ZW
21049 case BFD_RELOC_ARM_THUMB_ADD:
21050 /* This is a complicated relocation, since we use it for all of
21051 the following immediate relocations:
a737bd4d 21052
c19d1205
ZW
21053 3bit ADD/SUB
21054 8bit ADD/SUB
21055 9bit ADD/SUB SP word-aligned
21056 10bit ADD PC/SP word-aligned
a737bd4d 21057
c19d1205
ZW
21058 The type of instruction being processed is encoded in the
21059 instruction field:
a737bd4d 21060
c19d1205
ZW
21061 0x8000 SUB
21062 0x00F0 Rd
21063 0x000F Rs
21064 */
21065 newval = md_chars_to_number (buf, THUMB_SIZE);
21066 {
21067 int rd = (newval >> 4) & 0xf;
21068 int rs = newval & 0xf;
21069 int subtract = !!(newval & 0x8000);
a737bd4d 21070
c19d1205
ZW
21071 /* Check for HI regs, only very restricted cases allowed:
21072 Adjusting SP, and using PC or SP to get an address. */
21073 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
21074 || (rs > 7 && rs != REG_SP && rs != REG_PC))
21075 as_bad_where (fixP->fx_file, fixP->fx_line,
21076 _("invalid Hi register with immediate"));
a737bd4d 21077
c19d1205
ZW
21078 /* If value is negative, choose the opposite instruction. */
21079 if (value < 0)
21080 {
21081 value = -value;
21082 subtract = !subtract;
21083 if (value < 0)
21084 as_bad_where (fixP->fx_file, fixP->fx_line,
21085 _("immediate value out of range"));
21086 }
a737bd4d 21087
c19d1205
ZW
21088 if (rd == REG_SP)
21089 {
21090 if (value & ~0x1fc)
21091 as_bad_where (fixP->fx_file, fixP->fx_line,
21092 _("invalid immediate for stack address calculation"));
21093 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
21094 newval |= value >> 2;
21095 }
21096 else if (rs == REG_PC || rs == REG_SP)
21097 {
21098 if (subtract || value & ~0x3fc)
21099 as_bad_where (fixP->fx_file, fixP->fx_line,
21100 _("invalid immediate for address calculation (value = 0x%08lX)"),
21101 (unsigned long) value);
21102 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
21103 newval |= rd << 8;
21104 newval |= value >> 2;
21105 }
21106 else if (rs == rd)
21107 {
21108 if (value & ~0xff)
21109 as_bad_where (fixP->fx_file, fixP->fx_line,
21110 _("immediate value out of range"));
21111 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
21112 newval |= (rd << 8) | value;
21113 }
21114 else
21115 {
21116 if (value & ~0x7)
21117 as_bad_where (fixP->fx_file, fixP->fx_line,
21118 _("immediate value out of range"));
21119 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
21120 newval |= rd | (rs << 3) | (value << 6);
21121 }
21122 }
21123 md_number_to_chars (buf, newval, THUMB_SIZE);
21124 break;
a737bd4d 21125
c19d1205
ZW
21126 case BFD_RELOC_ARM_THUMB_IMM:
21127 newval = md_chars_to_number (buf, THUMB_SIZE);
21128 if (value < 0 || value > 255)
21129 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 21130 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
21131 (long) value);
21132 newval |= value;
21133 md_number_to_chars (buf, newval, THUMB_SIZE);
21134 break;
a737bd4d 21135
c19d1205
ZW
21136 case BFD_RELOC_ARM_THUMB_SHIFT:
21137 /* 5bit shift value (0..32). LSL cannot take 32. */
21138 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
21139 temp = newval & 0xf800;
21140 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
21141 as_bad_where (fixP->fx_file, fixP->fx_line,
21142 _("invalid shift value: %ld"), (long) value);
21143 /* Shifts of zero must be encoded as LSL. */
21144 if (value == 0)
21145 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
21146 /* Shifts of 32 are encoded as zero. */
21147 else if (value == 32)
21148 value = 0;
21149 newval |= value << 6;
21150 md_number_to_chars (buf, newval, THUMB_SIZE);
21151 break;
a737bd4d 21152
c19d1205
ZW
21153 case BFD_RELOC_VTABLE_INHERIT:
21154 case BFD_RELOC_VTABLE_ENTRY:
21155 fixP->fx_done = 0;
21156 return;
6c43fab6 21157
b6895b4f
PB
21158 case BFD_RELOC_ARM_MOVW:
21159 case BFD_RELOC_ARM_MOVT:
21160 case BFD_RELOC_ARM_THUMB_MOVW:
21161 case BFD_RELOC_ARM_THUMB_MOVT:
21162 if (fixP->fx_done || !seg->use_rela_p)
21163 {
21164 /* REL format relocations are limited to a 16-bit addend. */
21165 if (!fixP->fx_done)
21166 {
39623e12 21167 if (value < -0x8000 || value > 0x7fff)
b6895b4f 21168 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 21169 _("offset out of range"));
b6895b4f
PB
21170 }
21171 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21172 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21173 {
21174 value >>= 16;
21175 }
21176
21177 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21178 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21179 {
21180 newval = get_thumb32_insn (buf);
21181 newval &= 0xfbf08f00;
21182 newval |= (value & 0xf000) << 4;
21183 newval |= (value & 0x0800) << 15;
21184 newval |= (value & 0x0700) << 4;
21185 newval |= (value & 0x00ff);
21186 put_thumb32_insn (buf, newval);
21187 }
21188 else
21189 {
21190 newval = md_chars_to_number (buf, 4);
21191 newval &= 0xfff0f000;
21192 newval |= value & 0x0fff;
21193 newval |= (value & 0xf000) << 4;
21194 md_number_to_chars (buf, newval, 4);
21195 }
21196 }
21197 return;
21198
4962c51a
MS
21199 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21200 case BFD_RELOC_ARM_ALU_PC_G0:
21201 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21202 case BFD_RELOC_ARM_ALU_PC_G1:
21203 case BFD_RELOC_ARM_ALU_PC_G2:
21204 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21205 case BFD_RELOC_ARM_ALU_SB_G0:
21206 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21207 case BFD_RELOC_ARM_ALU_SB_G1:
21208 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 21209 gas_assert (!fixP->fx_done);
4962c51a
MS
21210 if (!seg->use_rela_p)
21211 {
21212 bfd_vma insn;
21213 bfd_vma encoded_addend;
21214 bfd_vma addend_abs = abs (value);
21215
21216 /* Check that the absolute value of the addend can be
21217 expressed as an 8-bit constant plus a rotation. */
21218 encoded_addend = encode_arm_immediate (addend_abs);
21219 if (encoded_addend == (unsigned int) FAIL)
21220 as_bad_where (fixP->fx_file, fixP->fx_line,
21221 _("the offset 0x%08lX is not representable"),
495bde8e 21222 (unsigned long) addend_abs);
4962c51a
MS
21223
21224 /* Extract the instruction. */
21225 insn = md_chars_to_number (buf, INSN_SIZE);
21226
21227 /* If the addend is positive, use an ADD instruction.
21228 Otherwise use a SUB. Take care not to destroy the S bit. */
21229 insn &= 0xff1fffff;
21230 if (value < 0)
21231 insn |= 1 << 22;
21232 else
21233 insn |= 1 << 23;
21234
21235 /* Place the encoded addend into the first 12 bits of the
21236 instruction. */
21237 insn &= 0xfffff000;
21238 insn |= encoded_addend;
5f4273c7
NC
21239
21240 /* Update the instruction. */
4962c51a
MS
21241 md_number_to_chars (buf, insn, INSN_SIZE);
21242 }
21243 break;
21244
21245 case BFD_RELOC_ARM_LDR_PC_G0:
21246 case BFD_RELOC_ARM_LDR_PC_G1:
21247 case BFD_RELOC_ARM_LDR_PC_G2:
21248 case BFD_RELOC_ARM_LDR_SB_G0:
21249 case BFD_RELOC_ARM_LDR_SB_G1:
21250 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 21251 gas_assert (!fixP->fx_done);
4962c51a
MS
21252 if (!seg->use_rela_p)
21253 {
21254 bfd_vma insn;
21255 bfd_vma addend_abs = abs (value);
21256
21257 /* Check that the absolute value of the addend can be
21258 encoded in 12 bits. */
21259 if (addend_abs >= 0x1000)
21260 as_bad_where (fixP->fx_file, fixP->fx_line,
21261 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 21262 (unsigned long) addend_abs);
4962c51a
MS
21263
21264 /* Extract the instruction. */
21265 insn = md_chars_to_number (buf, INSN_SIZE);
21266
21267 /* If the addend is negative, clear bit 23 of the instruction.
21268 Otherwise set it. */
21269 if (value < 0)
21270 insn &= ~(1 << 23);
21271 else
21272 insn |= 1 << 23;
21273
21274 /* Place the absolute value of the addend into the first 12 bits
21275 of the instruction. */
21276 insn &= 0xfffff000;
21277 insn |= addend_abs;
5f4273c7
NC
21278
21279 /* Update the instruction. */
4962c51a
MS
21280 md_number_to_chars (buf, insn, INSN_SIZE);
21281 }
21282 break;
21283
21284 case BFD_RELOC_ARM_LDRS_PC_G0:
21285 case BFD_RELOC_ARM_LDRS_PC_G1:
21286 case BFD_RELOC_ARM_LDRS_PC_G2:
21287 case BFD_RELOC_ARM_LDRS_SB_G0:
21288 case BFD_RELOC_ARM_LDRS_SB_G1:
21289 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 21290 gas_assert (!fixP->fx_done);
4962c51a
MS
21291 if (!seg->use_rela_p)
21292 {
21293 bfd_vma insn;
21294 bfd_vma addend_abs = abs (value);
21295
21296 /* Check that the absolute value of the addend can be
21297 encoded in 8 bits. */
21298 if (addend_abs >= 0x100)
21299 as_bad_where (fixP->fx_file, fixP->fx_line,
21300 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 21301 (unsigned long) addend_abs);
4962c51a
MS
21302
21303 /* Extract the instruction. */
21304 insn = md_chars_to_number (buf, INSN_SIZE);
21305
21306 /* If the addend is negative, clear bit 23 of the instruction.
21307 Otherwise set it. */
21308 if (value < 0)
21309 insn &= ~(1 << 23);
21310 else
21311 insn |= 1 << 23;
21312
21313 /* Place the first four bits of the absolute value of the addend
21314 into the first 4 bits of the instruction, and the remaining
21315 four into bits 8 .. 11. */
21316 insn &= 0xfffff0f0;
21317 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
21318
21319 /* Update the instruction. */
4962c51a
MS
21320 md_number_to_chars (buf, insn, INSN_SIZE);
21321 }
21322 break;
21323
21324 case BFD_RELOC_ARM_LDC_PC_G0:
21325 case BFD_RELOC_ARM_LDC_PC_G1:
21326 case BFD_RELOC_ARM_LDC_PC_G2:
21327 case BFD_RELOC_ARM_LDC_SB_G0:
21328 case BFD_RELOC_ARM_LDC_SB_G1:
21329 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 21330 gas_assert (!fixP->fx_done);
4962c51a
MS
21331 if (!seg->use_rela_p)
21332 {
21333 bfd_vma insn;
21334 bfd_vma addend_abs = abs (value);
21335
21336 /* Check that the absolute value of the addend is a multiple of
21337 four and, when divided by four, fits in 8 bits. */
21338 if (addend_abs & 0x3)
21339 as_bad_where (fixP->fx_file, fixP->fx_line,
21340 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 21341 (unsigned long) addend_abs);
4962c51a
MS
21342
21343 if ((addend_abs >> 2) > 0xff)
21344 as_bad_where (fixP->fx_file, fixP->fx_line,
21345 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 21346 (unsigned long) addend_abs);
4962c51a
MS
21347
21348 /* Extract the instruction. */
21349 insn = md_chars_to_number (buf, INSN_SIZE);
21350
21351 /* If the addend is negative, clear bit 23 of the instruction.
21352 Otherwise set it. */
21353 if (value < 0)
21354 insn &= ~(1 << 23);
21355 else
21356 insn |= 1 << 23;
21357
21358 /* Place the addend (divided by four) into the first eight
21359 bits of the instruction. */
21360 insn &= 0xfffffff0;
21361 insn |= addend_abs >> 2;
5f4273c7
NC
21362
21363 /* Update the instruction. */
4962c51a
MS
21364 md_number_to_chars (buf, insn, INSN_SIZE);
21365 }
21366 break;
21367
845b51d6
PB
21368 case BFD_RELOC_ARM_V4BX:
21369 /* This will need to go in the object file. */
21370 fixP->fx_done = 0;
21371 break;
21372
c19d1205
ZW
21373 case BFD_RELOC_UNUSED:
21374 default:
21375 as_bad_where (fixP->fx_file, fixP->fx_line,
21376 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
21377 }
6c43fab6
RE
21378}
21379
c19d1205
ZW
21380/* Translate internal representation of relocation info to BFD target
21381 format. */
a737bd4d 21382
c19d1205 21383arelent *
00a97672 21384tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 21385{
c19d1205
ZW
21386 arelent * reloc;
21387 bfd_reloc_code_real_type code;
a737bd4d 21388
21d799b5 21389 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 21390
21d799b5 21391 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
21392 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
21393 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 21394
2fc8bdac 21395 if (fixp->fx_pcrel)
00a97672
RS
21396 {
21397 if (section->use_rela_p)
21398 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
21399 else
21400 fixp->fx_offset = reloc->address;
21401 }
c19d1205 21402 reloc->addend = fixp->fx_offset;
a737bd4d 21403
c19d1205 21404 switch (fixp->fx_r_type)
a737bd4d 21405 {
c19d1205
ZW
21406 case BFD_RELOC_8:
21407 if (fixp->fx_pcrel)
21408 {
21409 code = BFD_RELOC_8_PCREL;
21410 break;
21411 }
a737bd4d 21412
c19d1205
ZW
21413 case BFD_RELOC_16:
21414 if (fixp->fx_pcrel)
21415 {
21416 code = BFD_RELOC_16_PCREL;
21417 break;
21418 }
6c43fab6 21419
c19d1205
ZW
21420 case BFD_RELOC_32:
21421 if (fixp->fx_pcrel)
21422 {
21423 code = BFD_RELOC_32_PCREL;
21424 break;
21425 }
a737bd4d 21426
b6895b4f
PB
21427 case BFD_RELOC_ARM_MOVW:
21428 if (fixp->fx_pcrel)
21429 {
21430 code = BFD_RELOC_ARM_MOVW_PCREL;
21431 break;
21432 }
21433
21434 case BFD_RELOC_ARM_MOVT:
21435 if (fixp->fx_pcrel)
21436 {
21437 code = BFD_RELOC_ARM_MOVT_PCREL;
21438 break;
21439 }
21440
21441 case BFD_RELOC_ARM_THUMB_MOVW:
21442 if (fixp->fx_pcrel)
21443 {
21444 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21445 break;
21446 }
21447
21448 case BFD_RELOC_ARM_THUMB_MOVT:
21449 if (fixp->fx_pcrel)
21450 {
21451 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21452 break;
21453 }
21454
c19d1205
ZW
21455 case BFD_RELOC_NONE:
21456 case BFD_RELOC_ARM_PCREL_BRANCH:
21457 case BFD_RELOC_ARM_PCREL_BLX:
21458 case BFD_RELOC_RVA:
21459 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21460 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21461 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21462 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21463 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21464 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
21465 case BFD_RELOC_VTABLE_ENTRY:
21466 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
21467#ifdef TE_PE
21468 case BFD_RELOC_32_SECREL:
21469#endif
c19d1205
ZW
21470 code = fixp->fx_r_type;
21471 break;
a737bd4d 21472
00adf2d4
JB
21473 case BFD_RELOC_THUMB_PCREL_BLX:
21474#ifdef OBJ_ELF
21475 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21476 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21477 else
21478#endif
21479 code = BFD_RELOC_THUMB_PCREL_BLX;
21480 break;
21481
c19d1205
ZW
21482 case BFD_RELOC_ARM_LITERAL:
21483 case BFD_RELOC_ARM_HWLITERAL:
21484 /* If this is called then the a literal has
21485 been referenced across a section boundary. */
21486 as_bad_where (fixp->fx_file, fixp->fx_line,
21487 _("literal referenced across section boundary"));
21488 return NULL;
a737bd4d 21489
c19d1205 21490#ifdef OBJ_ELF
0855e32b
NS
21491 case BFD_RELOC_ARM_TLS_CALL:
21492 case BFD_RELOC_ARM_THM_TLS_CALL:
21493 case BFD_RELOC_ARM_TLS_DESCSEQ:
21494 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
21495 case BFD_RELOC_ARM_GOT32:
21496 case BFD_RELOC_ARM_GOTOFF:
b43420e6 21497 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
21498 case BFD_RELOC_ARM_PLT32:
21499 case BFD_RELOC_ARM_TARGET1:
21500 case BFD_RELOC_ARM_ROSEGREL32:
21501 case BFD_RELOC_ARM_SBREL32:
21502 case BFD_RELOC_ARM_PREL31:
21503 case BFD_RELOC_ARM_TARGET2:
21504 case BFD_RELOC_ARM_TLS_LE32:
21505 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
21506 case BFD_RELOC_ARM_PCREL_CALL:
21507 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
21508 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21509 case BFD_RELOC_ARM_ALU_PC_G0:
21510 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21511 case BFD_RELOC_ARM_ALU_PC_G1:
21512 case BFD_RELOC_ARM_ALU_PC_G2:
21513 case BFD_RELOC_ARM_LDR_PC_G0:
21514 case BFD_RELOC_ARM_LDR_PC_G1:
21515 case BFD_RELOC_ARM_LDR_PC_G2:
21516 case BFD_RELOC_ARM_LDRS_PC_G0:
21517 case BFD_RELOC_ARM_LDRS_PC_G1:
21518 case BFD_RELOC_ARM_LDRS_PC_G2:
21519 case BFD_RELOC_ARM_LDC_PC_G0:
21520 case BFD_RELOC_ARM_LDC_PC_G1:
21521 case BFD_RELOC_ARM_LDC_PC_G2:
21522 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21523 case BFD_RELOC_ARM_ALU_SB_G0:
21524 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21525 case BFD_RELOC_ARM_ALU_SB_G1:
21526 case BFD_RELOC_ARM_ALU_SB_G2:
21527 case BFD_RELOC_ARM_LDR_SB_G0:
21528 case BFD_RELOC_ARM_LDR_SB_G1:
21529 case BFD_RELOC_ARM_LDR_SB_G2:
21530 case BFD_RELOC_ARM_LDRS_SB_G0:
21531 case BFD_RELOC_ARM_LDRS_SB_G1:
21532 case BFD_RELOC_ARM_LDRS_SB_G2:
21533 case BFD_RELOC_ARM_LDC_SB_G0:
21534 case BFD_RELOC_ARM_LDC_SB_G1:
21535 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 21536 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
21537 code = fixp->fx_r_type;
21538 break;
a737bd4d 21539
0855e32b 21540 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
21541 case BFD_RELOC_ARM_TLS_GD32:
21542 case BFD_RELOC_ARM_TLS_IE32:
21543 case BFD_RELOC_ARM_TLS_LDM32:
21544 /* BFD will include the symbol's address in the addend.
21545 But we don't want that, so subtract it out again here. */
21546 if (!S_IS_COMMON (fixp->fx_addsy))
21547 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21548 code = fixp->fx_r_type;
21549 break;
21550#endif
a737bd4d 21551
c19d1205
ZW
21552 case BFD_RELOC_ARM_IMMEDIATE:
21553 as_bad_where (fixp->fx_file, fixp->fx_line,
21554 _("internal relocation (type: IMMEDIATE) not fixed up"));
21555 return NULL;
a737bd4d 21556
c19d1205
ZW
21557 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21558 as_bad_where (fixp->fx_file, fixp->fx_line,
21559 _("ADRL used for a symbol not defined in the same file"));
21560 return NULL;
a737bd4d 21561
c19d1205 21562 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
21563 if (section->use_rela_p)
21564 {
21565 code = fixp->fx_r_type;
21566 break;
21567 }
21568
c19d1205
ZW
21569 if (fixp->fx_addsy != NULL
21570 && !S_IS_DEFINED (fixp->fx_addsy)
21571 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 21572 {
c19d1205
ZW
21573 as_bad_where (fixp->fx_file, fixp->fx_line,
21574 _("undefined local label `%s'"),
21575 S_GET_NAME (fixp->fx_addsy));
21576 return NULL;
a737bd4d
NC
21577 }
21578
c19d1205
ZW
21579 as_bad_where (fixp->fx_file, fixp->fx_line,
21580 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21581 return NULL;
a737bd4d 21582
c19d1205
ZW
21583 default:
21584 {
21585 char * type;
6c43fab6 21586
c19d1205
ZW
21587 switch (fixp->fx_r_type)
21588 {
21589 case BFD_RELOC_NONE: type = "NONE"; break;
21590 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21591 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 21592 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
21593 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21594 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21595 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 21596 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 21597 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
21598 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21599 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21600 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21601 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21602 default: type = _("<unknown>"); break;
21603 }
21604 as_bad_where (fixp->fx_file, fixp->fx_line,
21605 _("cannot represent %s relocation in this object file format"),
21606 type);
21607 return NULL;
21608 }
a737bd4d 21609 }
6c43fab6 21610
c19d1205
ZW
21611#ifdef OBJ_ELF
21612 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21613 && GOT_symbol
21614 && fixp->fx_addsy == GOT_symbol)
21615 {
21616 code = BFD_RELOC_ARM_GOTPC;
21617 reloc->addend = fixp->fx_offset = reloc->address;
21618 }
21619#endif
6c43fab6 21620
c19d1205 21621 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 21622
c19d1205
ZW
21623 if (reloc->howto == NULL)
21624 {
21625 as_bad_where (fixp->fx_file, fixp->fx_line,
21626 _("cannot represent %s relocation in this object file format"),
21627 bfd_get_reloc_code_name (code));
21628 return NULL;
21629 }
6c43fab6 21630
c19d1205
ZW
21631 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21632 vtable entry to be used in the relocation's section offset. */
21633 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21634 reloc->address = fixp->fx_offset;
6c43fab6 21635
c19d1205 21636 return reloc;
6c43fab6
RE
21637}
21638
c19d1205 21639/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 21640
c19d1205
ZW
21641void
21642cons_fix_new_arm (fragS * frag,
21643 int where,
21644 int size,
21645 expressionS * exp)
6c43fab6 21646{
c19d1205
ZW
21647 bfd_reloc_code_real_type type;
21648 int pcrel = 0;
6c43fab6 21649
c19d1205
ZW
21650 /* Pick a reloc.
21651 FIXME: @@ Should look at CPU word size. */
21652 switch (size)
21653 {
21654 case 1:
21655 type = BFD_RELOC_8;
21656 break;
21657 case 2:
21658 type = BFD_RELOC_16;
21659 break;
21660 case 4:
21661 default:
21662 type = BFD_RELOC_32;
21663 break;
21664 case 8:
21665 type = BFD_RELOC_64;
21666 break;
21667 }
6c43fab6 21668
f0927246
NC
21669#ifdef TE_PE
21670 if (exp->X_op == O_secrel)
21671 {
21672 exp->X_op = O_symbol;
21673 type = BFD_RELOC_32_SECREL;
21674 }
21675#endif
21676
c19d1205
ZW
21677 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21678}
6c43fab6 21679
4343666d 21680#if defined (OBJ_COFF)
c19d1205
ZW
21681void
21682arm_validate_fix (fixS * fixP)
6c43fab6 21683{
c19d1205
ZW
21684 /* If the destination of the branch is a defined symbol which does not have
21685 the THUMB_FUNC attribute, then we must be calling a function which has
21686 the (interfacearm) attribute. We look for the Thumb entry point to that
21687 function and change the branch to refer to that function instead. */
21688 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21689 && fixP->fx_addsy != NULL
21690 && S_IS_DEFINED (fixP->fx_addsy)
21691 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 21692 {
c19d1205 21693 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 21694 }
c19d1205
ZW
21695}
21696#endif
6c43fab6 21697
267bf995 21698
c19d1205
ZW
21699int
21700arm_force_relocation (struct fix * fixp)
21701{
21702#if defined (OBJ_COFF) && defined (TE_PE)
21703 if (fixp->fx_r_type == BFD_RELOC_RVA)
21704 return 1;
21705#endif
6c43fab6 21706
267bf995
RR
21707 /* In case we have a call or a branch to a function in ARM ISA mode from
21708 a thumb function or vice-versa force the relocation. These relocations
21709 are cleared off for some cores that might have blx and simple transformations
21710 are possible. */
21711
21712#ifdef OBJ_ELF
21713 switch (fixp->fx_r_type)
21714 {
21715 case BFD_RELOC_ARM_PCREL_JUMP:
21716 case BFD_RELOC_ARM_PCREL_CALL:
21717 case BFD_RELOC_THUMB_PCREL_BLX:
21718 if (THUMB_IS_FUNC (fixp->fx_addsy))
21719 return 1;
21720 break;
21721
21722 case BFD_RELOC_ARM_PCREL_BLX:
21723 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21724 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21725 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21726 if (ARM_IS_FUNC (fixp->fx_addsy))
21727 return 1;
21728 break;
21729
21730 default:
21731 break;
21732 }
21733#endif
21734
c19d1205
ZW
21735 /* Resolve these relocations even if the symbol is extern or weak. */
21736 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21737 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 21738 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 21739 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
21740 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21741 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
21742 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 21743 return 0;
a737bd4d 21744
4962c51a
MS
21745 /* Always leave these relocations for the linker. */
21746 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21747 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21748 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21749 return 1;
21750
f0291e4c
PB
21751 /* Always generate relocations against function symbols. */
21752 if (fixp->fx_r_type == BFD_RELOC_32
21753 && fixp->fx_addsy
21754 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21755 return 1;
21756
c19d1205 21757 return generic_force_reloc (fixp);
404ff6b5
AH
21758}
21759
0ffdc86c 21760#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
21761/* Relocations against function names must be left unadjusted,
21762 so that the linker can use this information to generate interworking
21763 stubs. The MIPS version of this function
c19d1205
ZW
21764 also prevents relocations that are mips-16 specific, but I do not
21765 know why it does this.
404ff6b5 21766
c19d1205
ZW
21767 FIXME:
21768 There is one other problem that ought to be addressed here, but
21769 which currently is not: Taking the address of a label (rather
21770 than a function) and then later jumping to that address. Such
21771 addresses also ought to have their bottom bit set (assuming that
21772 they reside in Thumb code), but at the moment they will not. */
404ff6b5 21773
c19d1205
ZW
21774bfd_boolean
21775arm_fix_adjustable (fixS * fixP)
404ff6b5 21776{
c19d1205
ZW
21777 if (fixP->fx_addsy == NULL)
21778 return 1;
404ff6b5 21779
e28387c3
PB
21780 /* Preserve relocations against symbols with function type. */
21781 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 21782 return FALSE;
e28387c3 21783
c19d1205
ZW
21784 if (THUMB_IS_FUNC (fixP->fx_addsy)
21785 && fixP->fx_subsy == NULL)
c921be7d 21786 return FALSE;
a737bd4d 21787
c19d1205
ZW
21788 /* We need the symbol name for the VTABLE entries. */
21789 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
21790 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 21791 return FALSE;
404ff6b5 21792
c19d1205
ZW
21793 /* Don't allow symbols to be discarded on GOT related relocs. */
21794 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
21795 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
21796 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
21797 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
21798 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
21799 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
21800 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
21801 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
21802 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
21803 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
21804 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
21805 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
21806 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 21807 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 21808 return FALSE;
a737bd4d 21809
4962c51a
MS
21810 /* Similarly for group relocations. */
21811 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21812 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21813 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 21814 return FALSE;
4962c51a 21815
79947c54
CD
21816 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
21817 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
21818 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21819 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
21820 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
21821 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21822 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
21823 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
21824 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 21825 return FALSE;
79947c54 21826
c921be7d 21827 return TRUE;
a737bd4d 21828}
0ffdc86c
NC
21829#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
21830
21831#ifdef OBJ_ELF
404ff6b5 21832
c19d1205
ZW
21833const char *
21834elf32_arm_target_format (void)
404ff6b5 21835{
c19d1205
ZW
21836#ifdef TE_SYMBIAN
21837 return (target_big_endian
21838 ? "elf32-bigarm-symbian"
21839 : "elf32-littlearm-symbian");
21840#elif defined (TE_VXWORKS)
21841 return (target_big_endian
21842 ? "elf32-bigarm-vxworks"
21843 : "elf32-littlearm-vxworks");
21844#else
21845 if (target_big_endian)
21846 return "elf32-bigarm";
21847 else
21848 return "elf32-littlearm";
21849#endif
404ff6b5
AH
21850}
21851
c19d1205
ZW
21852void
21853armelf_frob_symbol (symbolS * symp,
21854 int * puntp)
404ff6b5 21855{
c19d1205
ZW
21856 elf_frob_symbol (symp, puntp);
21857}
21858#endif
404ff6b5 21859
c19d1205 21860/* MD interface: Finalization. */
a737bd4d 21861
c19d1205
ZW
21862void
21863arm_cleanup (void)
21864{
21865 literal_pool * pool;
a737bd4d 21866
e07e6e58
NC
21867 /* Ensure that all the IT blocks are properly closed. */
21868 check_it_blocks_finished ();
21869
c19d1205
ZW
21870 for (pool = list_of_pools; pool; pool = pool->next)
21871 {
5f4273c7 21872 /* Put it at the end of the relevant section. */
c19d1205
ZW
21873 subseg_set (pool->section, pool->sub_section);
21874#ifdef OBJ_ELF
21875 arm_elf_change_section ();
21876#endif
21877 s_ltorg (0);
21878 }
404ff6b5
AH
21879}
21880
cd000bff
DJ
21881#ifdef OBJ_ELF
21882/* Remove any excess mapping symbols generated for alignment frags in
21883 SEC. We may have created a mapping symbol before a zero byte
21884 alignment; remove it if there's a mapping symbol after the
21885 alignment. */
21886static void
21887check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
21888 void *dummy ATTRIBUTE_UNUSED)
21889{
21890 segment_info_type *seginfo = seg_info (sec);
21891 fragS *fragp;
21892
21893 if (seginfo == NULL || seginfo->frchainP == NULL)
21894 return;
21895
21896 for (fragp = seginfo->frchainP->frch_root;
21897 fragp != NULL;
21898 fragp = fragp->fr_next)
21899 {
21900 symbolS *sym = fragp->tc_frag_data.last_map;
21901 fragS *next = fragp->fr_next;
21902
21903 /* Variable-sized frags have been converted to fixed size by
21904 this point. But if this was variable-sized to start with,
21905 there will be a fixed-size frag after it. So don't handle
21906 next == NULL. */
21907 if (sym == NULL || next == NULL)
21908 continue;
21909
21910 if (S_GET_VALUE (sym) < next->fr_address)
21911 /* Not at the end of this frag. */
21912 continue;
21913 know (S_GET_VALUE (sym) == next->fr_address);
21914
21915 do
21916 {
21917 if (next->tc_frag_data.first_map != NULL)
21918 {
21919 /* Next frag starts with a mapping symbol. Discard this
21920 one. */
21921 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21922 break;
21923 }
21924
21925 if (next->fr_next == NULL)
21926 {
21927 /* This mapping symbol is at the end of the section. Discard
21928 it. */
21929 know (next->fr_fix == 0 && next->fr_var == 0);
21930 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21931 break;
21932 }
21933
21934 /* As long as we have empty frags without any mapping symbols,
21935 keep looking. */
21936 /* If the next frag is non-empty and does not start with a
21937 mapping symbol, then this mapping symbol is required. */
21938 if (next->fr_address != next->fr_next->fr_address)
21939 break;
21940
21941 next = next->fr_next;
21942 }
21943 while (next != NULL);
21944 }
21945}
21946#endif
21947
c19d1205
ZW
21948/* Adjust the symbol table. This marks Thumb symbols as distinct from
21949 ARM ones. */
404ff6b5 21950
c19d1205
ZW
21951void
21952arm_adjust_symtab (void)
404ff6b5 21953{
c19d1205
ZW
21954#ifdef OBJ_COFF
21955 symbolS * sym;
404ff6b5 21956
c19d1205
ZW
21957 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21958 {
21959 if (ARM_IS_THUMB (sym))
21960 {
21961 if (THUMB_IS_FUNC (sym))
21962 {
21963 /* Mark the symbol as a Thumb function. */
21964 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
21965 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
21966 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 21967
c19d1205
ZW
21968 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
21969 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
21970 else
21971 as_bad (_("%s: unexpected function type: %d"),
21972 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
21973 }
21974 else switch (S_GET_STORAGE_CLASS (sym))
21975 {
21976 case C_EXT:
21977 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
21978 break;
21979 case C_STAT:
21980 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
21981 break;
21982 case C_LABEL:
21983 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
21984 break;
21985 default:
21986 /* Do nothing. */
21987 break;
21988 }
21989 }
a737bd4d 21990
c19d1205
ZW
21991 if (ARM_IS_INTERWORK (sym))
21992 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 21993 }
c19d1205
ZW
21994#endif
21995#ifdef OBJ_ELF
21996 symbolS * sym;
21997 char bind;
404ff6b5 21998
c19d1205 21999 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 22000 {
c19d1205
ZW
22001 if (ARM_IS_THUMB (sym))
22002 {
22003 elf_symbol_type * elf_sym;
404ff6b5 22004
c19d1205
ZW
22005 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
22006 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 22007
b0796911
PB
22008 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
22009 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
22010 {
22011 /* If it's a .thumb_func, declare it as so,
22012 otherwise tag label as .code 16. */
22013 if (THUMB_IS_FUNC (sym))
22014 elf_sym->internal_elf_sym.st_info =
22015 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 22016 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
22017 elf_sym->internal_elf_sym.st_info =
22018 ELF_ST_INFO (bind, STT_ARM_16BIT);
22019 }
22020 }
22021 }
cd000bff
DJ
22022
22023 /* Remove any overlapping mapping symbols generated by alignment frags. */
22024 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
22025 /* Now do generic ELF adjustments. */
22026 elf_adjust_symtab ();
c19d1205 22027#endif
404ff6b5
AH
22028}
22029
c19d1205 22030/* MD interface: Initialization. */
404ff6b5 22031
a737bd4d 22032static void
c19d1205 22033set_constant_flonums (void)
a737bd4d 22034{
c19d1205 22035 int i;
404ff6b5 22036
c19d1205
ZW
22037 for (i = 0; i < NUM_FLOAT_VALS; i++)
22038 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
22039 abort ();
a737bd4d 22040}
404ff6b5 22041
3e9e4fcf
JB
22042/* Auto-select Thumb mode if it's the only available instruction set for the
22043 given architecture. */
22044
22045static void
22046autoselect_thumb_from_cpu_variant (void)
22047{
22048 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
22049 opcode_select (16);
22050}
22051
c19d1205
ZW
22052void
22053md_begin (void)
a737bd4d 22054{
c19d1205
ZW
22055 unsigned mach;
22056 unsigned int i;
404ff6b5 22057
c19d1205
ZW
22058 if ( (arm_ops_hsh = hash_new ()) == NULL
22059 || (arm_cond_hsh = hash_new ()) == NULL
22060 || (arm_shift_hsh = hash_new ()) == NULL
22061 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 22062 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 22063 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
22064 || (arm_reloc_hsh = hash_new ()) == NULL
22065 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
22066 as_fatal (_("virtual memory exhausted"));
22067
22068 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 22069 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 22070 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 22071 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 22072 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 22073 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 22074 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 22075 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 22076 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0
NC
22077 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
22078 (void *) (v7m_psrs + i));
c19d1205 22079 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 22080 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
22081 for (i = 0;
22082 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
22083 i++)
d3ce72d0 22084 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 22085 (void *) (barrier_opt_names + i));
c19d1205
ZW
22086#ifdef OBJ_ELF
22087 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 22088 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
22089#endif
22090
22091 set_constant_flonums ();
404ff6b5 22092
c19d1205
ZW
22093 /* Set the cpu variant based on the command-line options. We prefer
22094 -mcpu= over -march= if both are set (as for GCC); and we prefer
22095 -mfpu= over any other way of setting the floating point unit.
22096 Use of legacy options with new options are faulted. */
e74cfd16 22097 if (legacy_cpu)
404ff6b5 22098 {
e74cfd16 22099 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
22100 as_bad (_("use of old and new-style options to set CPU type"));
22101
22102 mcpu_cpu_opt = legacy_cpu;
404ff6b5 22103 }
e74cfd16 22104 else if (!mcpu_cpu_opt)
c19d1205 22105 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 22106
e74cfd16 22107 if (legacy_fpu)
c19d1205 22108 {
e74cfd16 22109 if (mfpu_opt)
c19d1205 22110 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
22111
22112 mfpu_opt = legacy_fpu;
22113 }
e74cfd16 22114 else if (!mfpu_opt)
03b1477f 22115 {
45eb4c1b
NS
22116#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
22117 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
22118 /* Some environments specify a default FPU. If they don't, infer it
22119 from the processor. */
e74cfd16 22120 if (mcpu_fpu_opt)
03b1477f
RE
22121 mfpu_opt = mcpu_fpu_opt;
22122 else
22123 mfpu_opt = march_fpu_opt;
39c2da32 22124#else
e74cfd16 22125 mfpu_opt = &fpu_default;
39c2da32 22126#endif
03b1477f
RE
22127 }
22128
e74cfd16 22129 if (!mfpu_opt)
03b1477f 22130 {
493cb6ef 22131 if (mcpu_cpu_opt != NULL)
e74cfd16 22132 mfpu_opt = &fpu_default;
493cb6ef 22133 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 22134 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 22135 else
e74cfd16 22136 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
22137 }
22138
ee065d83 22139#ifdef CPU_DEFAULT
e74cfd16 22140 if (!mcpu_cpu_opt)
ee065d83 22141 {
e74cfd16
PB
22142 mcpu_cpu_opt = &cpu_default;
22143 selected_cpu = cpu_default;
ee065d83 22144 }
e74cfd16
PB
22145#else
22146 if (mcpu_cpu_opt)
22147 selected_cpu = *mcpu_cpu_opt;
ee065d83 22148 else
e74cfd16 22149 mcpu_cpu_opt = &arm_arch_any;
ee065d83 22150#endif
03b1477f 22151
e74cfd16 22152 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 22153
3e9e4fcf
JB
22154 autoselect_thumb_from_cpu_variant ();
22155
e74cfd16 22156 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 22157
f17c130b 22158#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 22159 {
7cc69913
NC
22160 unsigned int flags = 0;
22161
22162#if defined OBJ_ELF
22163 flags = meabi_flags;
d507cf36
PB
22164
22165 switch (meabi_flags)
33a392fb 22166 {
d507cf36 22167 case EF_ARM_EABI_UNKNOWN:
7cc69913 22168#endif
d507cf36
PB
22169 /* Set the flags in the private structure. */
22170 if (uses_apcs_26) flags |= F_APCS26;
22171 if (support_interwork) flags |= F_INTERWORK;
22172 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 22173 if (pic_code) flags |= F_PIC;
e74cfd16 22174 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
22175 flags |= F_SOFT_FLOAT;
22176
d507cf36
PB
22177 switch (mfloat_abi_opt)
22178 {
22179 case ARM_FLOAT_ABI_SOFT:
22180 case ARM_FLOAT_ABI_SOFTFP:
22181 flags |= F_SOFT_FLOAT;
22182 break;
33a392fb 22183
d507cf36
PB
22184 case ARM_FLOAT_ABI_HARD:
22185 if (flags & F_SOFT_FLOAT)
22186 as_bad (_("hard-float conflicts with specified fpu"));
22187 break;
22188 }
03b1477f 22189
e74cfd16
PB
22190 /* Using pure-endian doubles (even if soft-float). */
22191 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 22192 flags |= F_VFP_FLOAT;
f17c130b 22193
fde78edd 22194#if defined OBJ_ELF
e74cfd16 22195 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 22196 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
22197 break;
22198
8cb51566 22199 case EF_ARM_EABI_VER4:
3a4a14e9 22200 case EF_ARM_EABI_VER5:
c19d1205 22201 /* No additional flags to set. */
d507cf36
PB
22202 break;
22203
22204 default:
22205 abort ();
22206 }
7cc69913 22207#endif
b99bd4ef
NC
22208 bfd_set_private_flags (stdoutput, flags);
22209
22210 /* We have run out flags in the COFF header to encode the
22211 status of ATPCS support, so instead we create a dummy,
c19d1205 22212 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
22213 if (atpcs)
22214 {
22215 asection * sec;
22216
22217 sec = bfd_make_section (stdoutput, ".arm.atpcs");
22218
22219 if (sec != NULL)
22220 {
22221 bfd_set_section_flags
22222 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
22223 bfd_set_section_size (stdoutput, sec, 0);
22224 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
22225 }
22226 }
7cc69913 22227 }
f17c130b 22228#endif
b99bd4ef
NC
22229
22230 /* Record the CPU type as well. */
2d447fca
JM
22231 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
22232 mach = bfd_mach_arm_iWMMXt2;
22233 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 22234 mach = bfd_mach_arm_iWMMXt;
e74cfd16 22235 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 22236 mach = bfd_mach_arm_XScale;
e74cfd16 22237 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 22238 mach = bfd_mach_arm_ep9312;
e74cfd16 22239 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 22240 mach = bfd_mach_arm_5TE;
e74cfd16 22241 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 22242 {
e74cfd16 22243 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22244 mach = bfd_mach_arm_5T;
22245 else
22246 mach = bfd_mach_arm_5;
22247 }
e74cfd16 22248 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 22249 {
e74cfd16 22250 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22251 mach = bfd_mach_arm_4T;
22252 else
22253 mach = bfd_mach_arm_4;
22254 }
e74cfd16 22255 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 22256 mach = bfd_mach_arm_3M;
e74cfd16
PB
22257 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
22258 mach = bfd_mach_arm_3;
22259 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
22260 mach = bfd_mach_arm_2a;
22261 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
22262 mach = bfd_mach_arm_2;
22263 else
22264 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
22265
22266 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
22267}
22268
c19d1205 22269/* Command line processing. */
b99bd4ef 22270
c19d1205
ZW
22271/* md_parse_option
22272 Invocation line includes a switch not recognized by the base assembler.
22273 See if it's a processor-specific option.
b99bd4ef 22274
c19d1205
ZW
22275 This routine is somewhat complicated by the need for backwards
22276 compatibility (since older releases of gcc can't be changed).
22277 The new options try to make the interface as compatible as
22278 possible with GCC.
b99bd4ef 22279
c19d1205 22280 New options (supported) are:
b99bd4ef 22281
c19d1205
ZW
22282 -mcpu=<cpu name> Assemble for selected processor
22283 -march=<architecture name> Assemble for selected architecture
22284 -mfpu=<fpu architecture> Assemble for selected FPU.
22285 -EB/-mbig-endian Big-endian
22286 -EL/-mlittle-endian Little-endian
22287 -k Generate PIC code
22288 -mthumb Start in Thumb mode
22289 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 22290
278df34e 22291 -m[no-]warn-deprecated Warn about deprecated features
267bf995 22292
c19d1205 22293 For now we will also provide support for:
b99bd4ef 22294
c19d1205
ZW
22295 -mapcs-32 32-bit Program counter
22296 -mapcs-26 26-bit Program counter
22297 -macps-float Floats passed in FP registers
22298 -mapcs-reentrant Reentrant code
22299 -matpcs
22300 (sometime these will probably be replaced with -mapcs=<list of options>
22301 and -matpcs=<list of options>)
b99bd4ef 22302
c19d1205
ZW
22303 The remaining options are only supported for back-wards compatibility.
22304 Cpu variants, the arm part is optional:
22305 -m[arm]1 Currently not supported.
22306 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
22307 -m[arm]3 Arm 3 processor
22308 -m[arm]6[xx], Arm 6 processors
22309 -m[arm]7[xx][t][[d]m] Arm 7 processors
22310 -m[arm]8[10] Arm 8 processors
22311 -m[arm]9[20][tdmi] Arm 9 processors
22312 -mstrongarm[110[0]] StrongARM processors
22313 -mxscale XScale processors
22314 -m[arm]v[2345[t[e]]] Arm architectures
22315 -mall All (except the ARM1)
22316 FP variants:
22317 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
22318 -mfpe-old (No float load/store multiples)
22319 -mvfpxd VFP Single precision
22320 -mvfp All VFP
22321 -mno-fpu Disable all floating point instructions
b99bd4ef 22322
c19d1205
ZW
22323 The following CPU names are recognized:
22324 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
22325 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
22326 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
22327 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
22328 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
22329 arm10t arm10e, arm1020t, arm1020e, arm10200e,
22330 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 22331
c19d1205 22332 */
b99bd4ef 22333
c19d1205 22334const char * md_shortopts = "m:k";
b99bd4ef 22335
c19d1205
ZW
22336#ifdef ARM_BI_ENDIAN
22337#define OPTION_EB (OPTION_MD_BASE + 0)
22338#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 22339#else
c19d1205
ZW
22340#if TARGET_BYTES_BIG_ENDIAN
22341#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 22342#else
c19d1205
ZW
22343#define OPTION_EL (OPTION_MD_BASE + 1)
22344#endif
b99bd4ef 22345#endif
845b51d6 22346#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 22347
c19d1205 22348struct option md_longopts[] =
b99bd4ef 22349{
c19d1205
ZW
22350#ifdef OPTION_EB
22351 {"EB", no_argument, NULL, OPTION_EB},
22352#endif
22353#ifdef OPTION_EL
22354 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 22355#endif
845b51d6 22356 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
22357 {NULL, no_argument, NULL, 0}
22358};
b99bd4ef 22359
c19d1205 22360size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 22361
c19d1205 22362struct arm_option_table
b99bd4ef 22363{
c19d1205
ZW
22364 char *option; /* Option name to match. */
22365 char *help; /* Help information. */
22366 int *var; /* Variable to change. */
22367 int value; /* What to change it to. */
22368 char *deprecated; /* If non-null, print this message. */
22369};
b99bd4ef 22370
c19d1205
ZW
22371struct arm_option_table arm_opts[] =
22372{
22373 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
22374 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
22375 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
22376 &support_interwork, 1, NULL},
22377 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
22378 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
22379 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
22380 1, NULL},
22381 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
22382 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
22383 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
22384 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
22385 NULL},
b99bd4ef 22386
c19d1205
ZW
22387 /* These are recognized by the assembler, but have no affect on code. */
22388 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
22389 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
22390
22391 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
22392 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
22393 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
22394 {NULL, NULL, NULL, 0, NULL}
22395};
22396
22397struct arm_legacy_option_table
22398{
22399 char *option; /* Option name to match. */
22400 const arm_feature_set **var; /* Variable to change. */
22401 const arm_feature_set value; /* What to change it to. */
22402 char *deprecated; /* If non-null, print this message. */
22403};
b99bd4ef 22404
e74cfd16
PB
22405const struct arm_legacy_option_table arm_legacy_opts[] =
22406{
c19d1205
ZW
22407 /* DON'T add any new processors to this list -- we want the whole list
22408 to go away... Add them to the processors table instead. */
e74cfd16
PB
22409 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22410 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22411 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22412 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22413 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22414 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22415 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22416 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22417 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22418 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22419 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22420 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22421 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22422 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22423 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22424 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22425 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22426 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22427 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22428 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22429 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22430 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22431 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22432 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22433 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22434 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22435 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22436 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22437 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22438 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22439 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22440 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22441 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22442 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22443 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22444 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22445 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22446 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22447 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22448 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22449 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22450 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22451 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22452 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22453 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22454 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22455 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22456 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22457 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22458 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22459 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22460 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22461 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22462 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22463 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22464 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22465 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22466 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22467 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22468 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22469 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22470 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22471 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22472 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22473 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22474 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22475 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22476 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22477 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22478 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22479 N_("use -mcpu=strongarm110")},
e74cfd16 22480 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22481 N_("use -mcpu=strongarm1100")},
e74cfd16 22482 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22483 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
22484 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22485 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22486 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 22487
c19d1205 22488 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
22489 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22490 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22491 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22492 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22493 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22494 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22495 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22496 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22497 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22498 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22499 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22500 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22501 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22502 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22503 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22504 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22505 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22506 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 22507
c19d1205 22508 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
22509 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22510 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22511 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22512 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 22513 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 22514
e74cfd16 22515 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 22516};
7ed4c4c5 22517
c19d1205 22518struct arm_cpu_option_table
7ed4c4c5 22519{
c19d1205 22520 char *name;
e74cfd16 22521 const arm_feature_set value;
c19d1205
ZW
22522 /* For some CPUs we assume an FPU unless the user explicitly sets
22523 -mfpu=... */
e74cfd16 22524 const arm_feature_set default_fpu;
ee065d83
PB
22525 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22526 case. */
22527 const char *canonical_name;
c19d1205 22528};
7ed4c4c5 22529
c19d1205
ZW
22530/* This list should, at a minimum, contain all the cpu names
22531 recognized by GCC. */
e74cfd16 22532static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 22533{
ee065d83
PB
22534 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
22535 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
22536 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
22537 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22538 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22539 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22540 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22541 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22542 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22543 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22544 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22545 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22546 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22547 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22548 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22549 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22550 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22551 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22552 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22553 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22554 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22555 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22556 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22557 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22558 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22559 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22560 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22561 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22562 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22563 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22564 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22565 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22566 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22567 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22568 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22569 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22570 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22571 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22572 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22573 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
22574 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22575 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22576 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22577 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
22578 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22579 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
22580 /* For V5 or later processors we default to using VFP; but the user
22581 should really set the FPU type explicitly. */
ee065d83
PB
22582 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22583 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22584 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22585 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22586 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22587 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22588 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22589 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22590 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22591 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22592 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22593 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22594 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22595 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22596 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22597 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22598 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22599 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22600 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22601 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22602 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
7fac0536
NC
22603 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
22604 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
22605 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22606 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22607 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22608 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
4ff9b924
MGD
22609 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"},
22610 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"},
ee065d83
PB
22611 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22612 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22613 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22614 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
f4c65163
MGD
22615 {"cortex-a5", ARM_ARCH_V7A_MP_SEC,
22616 FPU_NONE, "Cortex-A5"},
22617 {"cortex-a8", ARM_ARCH_V7A_SEC,
22618 ARM_FEATURE (0, FPU_VFP_V3
5287ad62 22619 | FPU_NEON_EXT_V1),
4ff9b924 22620 "Cortex-A8"},
f4c65163
MGD
22621 {"cortex-a9", ARM_ARCH_V7A_MP_SEC,
22622 ARM_FEATURE (0, FPU_VFP_V3
15290f0a 22623 | FPU_NEON_EXT_V1),
4ff9b924 22624 "Cortex-A9"},
90ec0d68 22625 {"cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
eea54501 22626 FPU_ARCH_NEON_VFP_V4,
dbb1f804 22627 "Cortex-A15"},
4ff9b924
MGD
22628 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"},
22629 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
22630 "Cortex-R4F"},
22631 {"cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"},
22632 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"},
b2a5fbdc
MGD
22633 {"cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"},
22634 {"cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"},
c19d1205 22635 /* ??? XSCALE is really an architecture. */
ee065d83 22636 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22637 /* ??? iwmmxt is not a processor. */
ee065d83 22638 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 22639 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 22640 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22641 /* Maverick */
e07e6e58 22642 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
e74cfd16 22643 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 22644};
7ed4c4c5 22645
c19d1205 22646struct arm_arch_option_table
7ed4c4c5 22647{
c19d1205 22648 char *name;
e74cfd16
PB
22649 const arm_feature_set value;
22650 const arm_feature_set default_fpu;
c19d1205 22651};
7ed4c4c5 22652
c19d1205
ZW
22653/* This list should, at a minimum, contain all the architecture names
22654 recognized by GCC. */
e74cfd16 22655static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
22656{
22657 {"all", ARM_ANY, FPU_ARCH_FPA},
22658 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22659 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22660 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22661 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22662 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22663 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22664 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22665 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22666 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22667 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22668 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22669 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22670 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22671 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22672 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22673 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22674 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22675 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22676 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22677 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22678 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22679 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22680 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22681 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22682 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 22683 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
b2a5fbdc 22684 {"armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP},
62b3e311 22685 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
22686 /* The official spelling of the ARMv7 profile variants is the dashed form.
22687 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
22688 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22689 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22690 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
22691 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22692 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22693 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
9e3c6df6 22694 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
c19d1205
ZW
22695 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22696 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 22697 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 22698 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 22699};
7ed4c4c5 22700
69133863
MGD
22701/* ISA extensions in the co-processor and main instruction set space. */
22702struct arm_option_extension_value_table
c19d1205
ZW
22703{
22704 char *name;
e74cfd16 22705 const arm_feature_set value;
69133863 22706 const arm_feature_set allowed_archs;
c19d1205 22707};
7ed4c4c5 22708
69133863
MGD
22709/* The following table must be in alphabetical order with a NULL last entry.
22710 */
22711static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 22712{
eea54501
MGD
22713 {"idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0),
22714 ARM_FEATURE (ARM_EXT_V7A, 0)},
69133863
MGD
22715 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY},
22716 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY},
22717 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY},
60e5ef9f
MGD
22718 {"mp", ARM_FEATURE (ARM_EXT_MP, 0),
22719 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)},
b2a5fbdc
MGD
22720 {"os", ARM_FEATURE (ARM_EXT_OS, 0),
22721 ARM_FEATURE (ARM_EXT_V6M, 0)},
f4c65163
MGD
22722 {"sec", ARM_FEATURE (ARM_EXT_SEC, 0),
22723 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)},
90ec0d68
MGD
22724 {"virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV | ARM_EXT_DIV, 0),
22725 ARM_FEATURE (ARM_EXT_V7A, 0)},
69133863 22726 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY},
60e5ef9f 22727 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
69133863
MGD
22728};
22729
22730/* ISA floating-point and Advanced SIMD extensions. */
22731struct arm_option_fpu_value_table
22732{
22733 char *name;
22734 const arm_feature_set value;
c19d1205 22735};
7ed4c4c5 22736
c19d1205
ZW
22737/* This list should, at a minimum, contain all the fpu names
22738 recognized by GCC. */
69133863 22739static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
22740{
22741 {"softfpa", FPU_NONE},
22742 {"fpe", FPU_ARCH_FPE},
22743 {"fpe2", FPU_ARCH_FPE},
22744 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22745 {"fpa", FPU_ARCH_FPA},
22746 {"fpa10", FPU_ARCH_FPA},
22747 {"fpa11", FPU_ARCH_FPA},
22748 {"arm7500fe", FPU_ARCH_FPA},
22749 {"softvfp", FPU_ARCH_VFP},
22750 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22751 {"vfp", FPU_ARCH_VFP_V2},
22752 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 22753 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
22754 {"vfp10", FPU_ARCH_VFP_V2},
22755 {"vfp10-r0", FPU_ARCH_VFP_V1},
22756 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
22757 {"vfpv2", FPU_ARCH_VFP_V2},
22758 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 22759 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 22760 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
22761 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
22762 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
22763 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
22764 {"arm1020t", FPU_ARCH_VFP_V1},
22765 {"arm1020e", FPU_ARCH_VFP_V2},
22766 {"arm1136jfs", FPU_ARCH_VFP_V2},
22767 {"arm1136jf-s", FPU_ARCH_VFP_V2},
22768 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 22769 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 22770 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
22771 {"vfpv4", FPU_ARCH_VFP_V4},
22772 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 22773 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 22774 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
e74cfd16
PB
22775 {NULL, ARM_ARCH_NONE}
22776};
22777
22778struct arm_option_value_table
22779{
22780 char *name;
22781 long value;
c19d1205 22782};
7ed4c4c5 22783
e74cfd16 22784static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
22785{
22786 {"hard", ARM_FLOAT_ABI_HARD},
22787 {"softfp", ARM_FLOAT_ABI_SOFTFP},
22788 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 22789 {NULL, 0}
c19d1205 22790};
7ed4c4c5 22791
c19d1205 22792#ifdef OBJ_ELF
3a4a14e9 22793/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 22794static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
22795{
22796 {"gnu", EF_ARM_EABI_UNKNOWN},
22797 {"4", EF_ARM_EABI_VER4},
3a4a14e9 22798 {"5", EF_ARM_EABI_VER5},
e74cfd16 22799 {NULL, 0}
c19d1205
ZW
22800};
22801#endif
7ed4c4c5 22802
c19d1205
ZW
22803struct arm_long_option_table
22804{
22805 char * option; /* Substring to match. */
22806 char * help; /* Help information. */
22807 int (* func) (char * subopt); /* Function to decode sub-option. */
22808 char * deprecated; /* If non-null, print this message. */
22809};
7ed4c4c5 22810
c921be7d 22811static bfd_boolean
e74cfd16 22812arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 22813{
21d799b5
NC
22814 arm_feature_set *ext_set = (arm_feature_set *)
22815 xmalloc (sizeof (arm_feature_set));
e74cfd16 22816
69133863
MGD
22817 /* We insist on extensions being specified in alphabetical order, and with
22818 extensions being added before being removed. We achieve this by having
22819 the global ARM_EXTENSIONS table in alphabetical order, and using the
22820 ADDING_VALUE variable to indicate whether we are adding an extension (1)
22821 or removing it (0) and only allowing it to change in the order
22822 -1 -> 1 -> 0. */
22823 const struct arm_option_extension_value_table * opt = NULL;
22824 int adding_value = -1;
22825
e74cfd16
PB
22826 /* Copy the feature set, so that we can modify it. */
22827 *ext_set = **opt_p;
22828 *opt_p = ext_set;
22829
c19d1205 22830 while (str != NULL && *str != 0)
7ed4c4c5 22831 {
c19d1205 22832 char * ext;
69133863 22833 size_t optlen;
7ed4c4c5 22834
c19d1205
ZW
22835 if (*str != '+')
22836 {
22837 as_bad (_("invalid architectural extension"));
c921be7d 22838 return FALSE;
c19d1205 22839 }
7ed4c4c5 22840
c19d1205
ZW
22841 str++;
22842 ext = strchr (str, '+');
7ed4c4c5 22843
c19d1205
ZW
22844 if (ext != NULL)
22845 optlen = ext - str;
22846 else
22847 optlen = strlen (str);
7ed4c4c5 22848
69133863
MGD
22849 if (optlen >= 2
22850 && strncmp (str, "no", 2) == 0)
22851 {
22852 if (adding_value != 0)
22853 {
22854 adding_value = 0;
22855 opt = arm_extensions;
22856 }
22857
22858 optlen -= 2;
22859 str += 2;
22860 }
22861 else if (optlen > 0)
22862 {
22863 if (adding_value == -1)
22864 {
22865 adding_value = 1;
22866 opt = arm_extensions;
22867 }
22868 else if (adding_value != 1)
22869 {
22870 as_bad (_("must specify extensions to add before specifying "
22871 "those to remove"));
22872 return FALSE;
22873 }
22874 }
22875
c19d1205
ZW
22876 if (optlen == 0)
22877 {
22878 as_bad (_("missing architectural extension"));
c921be7d 22879 return FALSE;
c19d1205 22880 }
7ed4c4c5 22881
69133863
MGD
22882 gas_assert (adding_value != -1);
22883 gas_assert (opt != NULL);
22884
22885 /* Scan over the options table trying to find an exact match. */
22886 for (; opt->name != NULL; opt++)
22887 if (strncmp (opt->name, str, optlen) == 0
22888 && strlen (opt->name) == optlen)
c19d1205 22889 {
69133863
MGD
22890 /* Check we can apply the extension to this architecture. */
22891 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
22892 {
22893 as_bad (_("extension does not apply to the base architecture"));
22894 return FALSE;
22895 }
22896
22897 /* Add or remove the extension. */
22898 if (adding_value)
22899 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
22900 else
22901 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
22902
c19d1205
ZW
22903 break;
22904 }
7ed4c4c5 22905
c19d1205
ZW
22906 if (opt->name == NULL)
22907 {
69133863
MGD
22908 /* Did we fail to find an extension because it wasn't specified in
22909 alphabetical order, or because it does not exist? */
22910
22911 for (opt = arm_extensions; opt->name != NULL; opt++)
22912 if (strncmp (opt->name, str, optlen) == 0)
22913 break;
22914
22915 if (opt->name == NULL)
22916 as_bad (_("unknown architectural extension `%s'"), str);
22917 else
22918 as_bad (_("architectural extensions must be specified in "
22919 "alphabetical order"));
22920
c921be7d 22921 return FALSE;
c19d1205 22922 }
69133863
MGD
22923 else
22924 {
22925 /* We should skip the extension we've just matched the next time
22926 round. */
22927 opt++;
22928 }
7ed4c4c5 22929
c19d1205
ZW
22930 str = ext;
22931 };
7ed4c4c5 22932
c921be7d 22933 return TRUE;
c19d1205 22934}
7ed4c4c5 22935
c921be7d 22936static bfd_boolean
c19d1205 22937arm_parse_cpu (char * str)
7ed4c4c5 22938{
e74cfd16 22939 const struct arm_cpu_option_table * opt;
c19d1205
ZW
22940 char * ext = strchr (str, '+');
22941 int optlen;
7ed4c4c5 22942
c19d1205
ZW
22943 if (ext != NULL)
22944 optlen = ext - str;
7ed4c4c5 22945 else
c19d1205 22946 optlen = strlen (str);
7ed4c4c5 22947
c19d1205 22948 if (optlen == 0)
7ed4c4c5 22949 {
c19d1205 22950 as_bad (_("missing cpu name `%s'"), str);
c921be7d 22951 return FALSE;
7ed4c4c5
NC
22952 }
22953
c19d1205
ZW
22954 for (opt = arm_cpus; opt->name != NULL; opt++)
22955 if (strncmp (opt->name, str, optlen) == 0)
22956 {
e74cfd16
PB
22957 mcpu_cpu_opt = &opt->value;
22958 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 22959 if (opt->canonical_name)
5f4273c7 22960 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22961 else
22962 {
22963 int i;
c921be7d 22964
ee065d83
PB
22965 for (i = 0; i < optlen; i++)
22966 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22967 selected_cpu_name[i] = 0;
22968 }
7ed4c4c5 22969
c19d1205
ZW
22970 if (ext != NULL)
22971 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 22972
c921be7d 22973 return TRUE;
c19d1205 22974 }
7ed4c4c5 22975
c19d1205 22976 as_bad (_("unknown cpu `%s'"), str);
c921be7d 22977 return FALSE;
7ed4c4c5
NC
22978}
22979
c921be7d 22980static bfd_boolean
c19d1205 22981arm_parse_arch (char * str)
7ed4c4c5 22982{
e74cfd16 22983 const struct arm_arch_option_table *opt;
c19d1205
ZW
22984 char *ext = strchr (str, '+');
22985 int optlen;
7ed4c4c5 22986
c19d1205
ZW
22987 if (ext != NULL)
22988 optlen = ext - str;
7ed4c4c5 22989 else
c19d1205 22990 optlen = strlen (str);
7ed4c4c5 22991
c19d1205 22992 if (optlen == 0)
7ed4c4c5 22993 {
c19d1205 22994 as_bad (_("missing architecture name `%s'"), str);
c921be7d 22995 return FALSE;
7ed4c4c5
NC
22996 }
22997
c19d1205 22998 for (opt = arm_archs; opt->name != NULL; opt++)
69133863 22999 if (strncmp (opt->name, str, optlen) == 0)
c19d1205 23000 {
e74cfd16
PB
23001 march_cpu_opt = &opt->value;
23002 march_fpu_opt = &opt->default_fpu;
5f4273c7 23003 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 23004
c19d1205
ZW
23005 if (ext != NULL)
23006 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 23007
c921be7d 23008 return TRUE;
c19d1205
ZW
23009 }
23010
23011 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 23012 return FALSE;
7ed4c4c5 23013}
eb043451 23014
c921be7d 23015static bfd_boolean
c19d1205
ZW
23016arm_parse_fpu (char * str)
23017{
69133863 23018 const struct arm_option_fpu_value_table * opt;
b99bd4ef 23019
c19d1205
ZW
23020 for (opt = arm_fpus; opt->name != NULL; opt++)
23021 if (streq (opt->name, str))
23022 {
e74cfd16 23023 mfpu_opt = &opt->value;
c921be7d 23024 return TRUE;
c19d1205 23025 }
b99bd4ef 23026
c19d1205 23027 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 23028 return FALSE;
c19d1205
ZW
23029}
23030
c921be7d 23031static bfd_boolean
c19d1205 23032arm_parse_float_abi (char * str)
b99bd4ef 23033{
e74cfd16 23034 const struct arm_option_value_table * opt;
b99bd4ef 23035
c19d1205
ZW
23036 for (opt = arm_float_abis; opt->name != NULL; opt++)
23037 if (streq (opt->name, str))
23038 {
23039 mfloat_abi_opt = opt->value;
c921be7d 23040 return TRUE;
c19d1205 23041 }
cc8a6dd0 23042
c19d1205 23043 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 23044 return FALSE;
c19d1205 23045}
b99bd4ef 23046
c19d1205 23047#ifdef OBJ_ELF
c921be7d 23048static bfd_boolean
c19d1205
ZW
23049arm_parse_eabi (char * str)
23050{
e74cfd16 23051 const struct arm_option_value_table *opt;
cc8a6dd0 23052
c19d1205
ZW
23053 for (opt = arm_eabis; opt->name != NULL; opt++)
23054 if (streq (opt->name, str))
23055 {
23056 meabi_flags = opt->value;
c921be7d 23057 return TRUE;
c19d1205
ZW
23058 }
23059 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 23060 return FALSE;
c19d1205
ZW
23061}
23062#endif
cc8a6dd0 23063
c921be7d 23064static bfd_boolean
e07e6e58
NC
23065arm_parse_it_mode (char * str)
23066{
c921be7d 23067 bfd_boolean ret = TRUE;
e07e6e58
NC
23068
23069 if (streq ("arm", str))
23070 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
23071 else if (streq ("thumb", str))
23072 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
23073 else if (streq ("always", str))
23074 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
23075 else if (streq ("never", str))
23076 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
23077 else
23078 {
23079 as_bad (_("unknown implicit IT mode `%s', should be "\
23080 "arm, thumb, always, or never."), str);
c921be7d 23081 ret = FALSE;
e07e6e58
NC
23082 }
23083
23084 return ret;
23085}
23086
c19d1205
ZW
23087struct arm_long_option_table arm_long_opts[] =
23088{
23089 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
23090 arm_parse_cpu, NULL},
23091 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
23092 arm_parse_arch, NULL},
23093 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
23094 arm_parse_fpu, NULL},
23095 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
23096 arm_parse_float_abi, NULL},
23097#ifdef OBJ_ELF
7fac0536 23098 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
23099 arm_parse_eabi, NULL},
23100#endif
e07e6e58
NC
23101 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
23102 arm_parse_it_mode, NULL},
c19d1205
ZW
23103 {NULL, NULL, 0, NULL}
23104};
cc8a6dd0 23105
c19d1205
ZW
23106int
23107md_parse_option (int c, char * arg)
23108{
23109 struct arm_option_table *opt;
e74cfd16 23110 const struct arm_legacy_option_table *fopt;
c19d1205 23111 struct arm_long_option_table *lopt;
b99bd4ef 23112
c19d1205 23113 switch (c)
b99bd4ef 23114 {
c19d1205
ZW
23115#ifdef OPTION_EB
23116 case OPTION_EB:
23117 target_big_endian = 1;
23118 break;
23119#endif
cc8a6dd0 23120
c19d1205
ZW
23121#ifdef OPTION_EL
23122 case OPTION_EL:
23123 target_big_endian = 0;
23124 break;
23125#endif
b99bd4ef 23126
845b51d6
PB
23127 case OPTION_FIX_V4BX:
23128 fix_v4bx = TRUE;
23129 break;
23130
c19d1205
ZW
23131 case 'a':
23132 /* Listing option. Just ignore these, we don't support additional
23133 ones. */
23134 return 0;
b99bd4ef 23135
c19d1205
ZW
23136 default:
23137 for (opt = arm_opts; opt->option != NULL; opt++)
23138 {
23139 if (c == opt->option[0]
23140 && ((arg == NULL && opt->option[1] == 0)
23141 || streq (arg, opt->option + 1)))
23142 {
c19d1205 23143 /* If the option is deprecated, tell the user. */
278df34e 23144 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
23145 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23146 arg ? arg : "", _(opt->deprecated));
b99bd4ef 23147
c19d1205
ZW
23148 if (opt->var != NULL)
23149 *opt->var = opt->value;
cc8a6dd0 23150
c19d1205
ZW
23151 return 1;
23152 }
23153 }
b99bd4ef 23154
e74cfd16
PB
23155 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
23156 {
23157 if (c == fopt->option[0]
23158 && ((arg == NULL && fopt->option[1] == 0)
23159 || streq (arg, fopt->option + 1)))
23160 {
e74cfd16 23161 /* If the option is deprecated, tell the user. */
278df34e 23162 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
23163 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23164 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
23165
23166 if (fopt->var != NULL)
23167 *fopt->var = &fopt->value;
23168
23169 return 1;
23170 }
23171 }
23172
c19d1205
ZW
23173 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23174 {
23175 /* These options are expected to have an argument. */
23176 if (c == lopt->option[0]
23177 && arg != NULL
23178 && strncmp (arg, lopt->option + 1,
23179 strlen (lopt->option + 1)) == 0)
23180 {
c19d1205 23181 /* If the option is deprecated, tell the user. */
278df34e 23182 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
23183 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
23184 _(lopt->deprecated));
b99bd4ef 23185
c19d1205
ZW
23186 /* Call the sup-option parser. */
23187 return lopt->func (arg + strlen (lopt->option) - 1);
23188 }
23189 }
a737bd4d 23190
c19d1205
ZW
23191 return 0;
23192 }
a394c00f 23193
c19d1205
ZW
23194 return 1;
23195}
a394c00f 23196
c19d1205
ZW
23197void
23198md_show_usage (FILE * fp)
a394c00f 23199{
c19d1205
ZW
23200 struct arm_option_table *opt;
23201 struct arm_long_option_table *lopt;
a394c00f 23202
c19d1205 23203 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 23204
c19d1205
ZW
23205 for (opt = arm_opts; opt->option != NULL; opt++)
23206 if (opt->help != NULL)
23207 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 23208
c19d1205
ZW
23209 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23210 if (lopt->help != NULL)
23211 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 23212
c19d1205
ZW
23213#ifdef OPTION_EB
23214 fprintf (fp, _("\
23215 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
23216#endif
23217
c19d1205
ZW
23218#ifdef OPTION_EL
23219 fprintf (fp, _("\
23220 -EL assemble code for a little-endian cpu\n"));
a737bd4d 23221#endif
845b51d6
PB
23222
23223 fprintf (fp, _("\
23224 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 23225}
ee065d83
PB
23226
23227
23228#ifdef OBJ_ELF
62b3e311
PB
23229typedef struct
23230{
23231 int val;
23232 arm_feature_set flags;
23233} cpu_arch_ver_table;
23234
23235/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
23236 least features first. */
23237static const cpu_arch_ver_table cpu_arch_ver[] =
23238{
23239 {1, ARM_ARCH_V4},
23240 {2, ARM_ARCH_V4T},
23241 {3, ARM_ARCH_V5},
ee3c0378 23242 {3, ARM_ARCH_V5T},
62b3e311
PB
23243 {4, ARM_ARCH_V5TE},
23244 {5, ARM_ARCH_V5TEJ},
23245 {6, ARM_ARCH_V6},
7e806470 23246 {9, ARM_ARCH_V6K},
f4c65163 23247 {7, ARM_ARCH_V6Z},
91e22acd 23248 {11, ARM_ARCH_V6M},
b2a5fbdc 23249 {12, ARM_ARCH_V6SM},
7e806470 23250 {8, ARM_ARCH_V6T2},
62b3e311
PB
23251 {10, ARM_ARCH_V7A},
23252 {10, ARM_ARCH_V7R},
23253 {10, ARM_ARCH_V7M},
23254 {0, ARM_ARCH_NONE}
23255};
23256
ee3c0378
AS
23257/* Set an attribute if it has not already been set by the user. */
23258static void
23259aeabi_set_attribute_int (int tag, int value)
23260{
23261 if (tag < 1
23262 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23263 || !attributes_set_explicitly[tag])
23264 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
23265}
23266
23267static void
23268aeabi_set_attribute_string (int tag, const char *value)
23269{
23270 if (tag < 1
23271 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23272 || !attributes_set_explicitly[tag])
23273 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
23274}
23275
ee065d83
PB
23276/* Set the public EABI object attributes. */
23277static void
23278aeabi_set_public_attributes (void)
23279{
23280 int arch;
90ec0d68 23281 int virt_sec = 0;
e74cfd16 23282 arm_feature_set flags;
62b3e311
PB
23283 arm_feature_set tmp;
23284 const cpu_arch_ver_table *p;
ee065d83
PB
23285
23286 /* Choose the architecture based on the capabilities of the requested cpu
23287 (if any) and/or the instructions actually used. */
e74cfd16
PB
23288 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
23289 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
23290 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
23291 /*Allow the user to override the reported architecture. */
23292 if (object_arch)
23293 {
23294 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
23295 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
23296 }
23297
251665fc
MGD
23298 /* We need to make sure that the attributes do not identify us as v6S-M
23299 when the only v6S-M feature in use is the Operating System Extensions. */
23300 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
23301 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
23302 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
23303
62b3e311
PB
23304 tmp = flags;
23305 arch = 0;
23306 for (p = cpu_arch_ver; p->val; p++)
23307 {
23308 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
23309 {
23310 arch = p->val;
23311 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
23312 }
23313 }
ee065d83 23314
9e3c6df6
PB
23315 /* The table lookup above finds the last architecture to contribute
23316 a new feature. Unfortunately, Tag13 is a subset of the union of
23317 v6T2 and v7-M, so it is never seen as contributing a new feature.
23318 We can not search for the last entry which is entirely used,
23319 because if no CPU is specified we build up only those flags
23320 actually used. Perhaps we should separate out the specified
23321 and implicit cases. Avoid taking this path for -march=all by
23322 checking for contradictory v7-A / v7-M features. */
23323 if (arch == 10
23324 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
23325 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
23326 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
23327 arch = 13;
23328
ee065d83
PB
23329 /* Tag_CPU_name. */
23330 if (selected_cpu_name[0])
23331 {
91d6fa6a 23332 char *q;
ee065d83 23333
91d6fa6a
NC
23334 q = selected_cpu_name;
23335 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
23336 {
23337 int i;
5f4273c7 23338
91d6fa6a
NC
23339 q += 4;
23340 for (i = 0; q[i]; i++)
23341 q[i] = TOUPPER (q[i]);
ee065d83 23342 }
91d6fa6a 23343 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 23344 }
62f3b8c8 23345
ee065d83 23346 /* Tag_CPU_arch. */
ee3c0378 23347 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 23348
62b3e311
PB
23349 /* Tag_CPU_arch_profile. */
23350 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 23351 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 23352 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 23353 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 23354 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 23355 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
62f3b8c8 23356
ee065d83 23357 /* Tag_ARM_ISA_use. */
ee3c0378
AS
23358 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
23359 || arch == 0)
23360 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 23361
ee065d83 23362 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
23363 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
23364 || arch == 0)
23365 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
23366 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 23367
ee065d83 23368 /* Tag_VFP_arch. */
62f3b8c8
PB
23369 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
23370 aeabi_set_attribute_int (Tag_VFP_arch,
23371 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
23372 ? 5 : 6);
23373 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
ee3c0378 23374 aeabi_set_attribute_int (Tag_VFP_arch, 3);
ada65aa3 23375 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
ee3c0378
AS
23376 aeabi_set_attribute_int (Tag_VFP_arch, 4);
23377 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
23378 aeabi_set_attribute_int (Tag_VFP_arch, 2);
23379 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
23380 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
23381 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 23382
4547cb56
NC
23383 /* Tag_ABI_HardFP_use. */
23384 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
23385 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
23386 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
23387
ee065d83 23388 /* Tag_WMMX_arch. */
ee3c0378
AS
23389 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
23390 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
23391 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
23392 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 23393
ee3c0378 23394 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 23395 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
62f3b8c8
PB
23396 aeabi_set_attribute_int
23397 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
23398 ? 2 : 1));
23399
ee3c0378 23400 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
62f3b8c8 23401 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
ee3c0378 23402 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56
NC
23403
23404 /* Tag_DIV_use. */
eea54501
MGD
23405 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv))
23406 aeabi_set_attribute_int (Tag_DIV_use, 2);
23407 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_div))
4547cb56 23408 aeabi_set_attribute_int (Tag_DIV_use, 0);
4547cb56
NC
23409 else
23410 aeabi_set_attribute_int (Tag_DIV_use, 1);
60e5ef9f
MGD
23411
23412 /* Tag_MP_extension_use. */
23413 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
23414 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
23415
23416 /* Tag Virtualization_use. */
23417 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
23418 virt_sec |= 1;
23419 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
23420 virt_sec |= 2;
23421 if (virt_sec != 0)
23422 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
23423}
23424
104d59d1 23425/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
23426void
23427arm_md_end (void)
23428{
ee065d83
PB
23429 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
23430 return;
23431
23432 aeabi_set_public_attributes ();
ee065d83 23433}
8463be01 23434#endif /* OBJ_ELF */
ee065d83
PB
23435
23436
23437/* Parse a .cpu directive. */
23438
23439static void
23440s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
23441{
e74cfd16 23442 const struct arm_cpu_option_table *opt;
ee065d83
PB
23443 char *name;
23444 char saved_char;
23445
23446 name = input_line_pointer;
5f4273c7 23447 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23448 input_line_pointer++;
23449 saved_char = *input_line_pointer;
23450 *input_line_pointer = 0;
23451
23452 /* Skip the first "all" entry. */
23453 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
23454 if (streq (opt->name, name))
23455 {
e74cfd16
PB
23456 mcpu_cpu_opt = &opt->value;
23457 selected_cpu = opt->value;
ee065d83 23458 if (opt->canonical_name)
5f4273c7 23459 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
23460 else
23461 {
23462 int i;
23463 for (i = 0; opt->name[i]; i++)
23464 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23465 selected_cpu_name[i] = 0;
23466 }
e74cfd16 23467 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23468 *input_line_pointer = saved_char;
23469 demand_empty_rest_of_line ();
23470 return;
23471 }
23472 as_bad (_("unknown cpu `%s'"), name);
23473 *input_line_pointer = saved_char;
23474 ignore_rest_of_line ();
23475}
23476
23477
23478/* Parse a .arch directive. */
23479
23480static void
23481s_arm_arch (int ignored ATTRIBUTE_UNUSED)
23482{
e74cfd16 23483 const struct arm_arch_option_table *opt;
ee065d83
PB
23484 char saved_char;
23485 char *name;
23486
23487 name = input_line_pointer;
5f4273c7 23488 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23489 input_line_pointer++;
23490 saved_char = *input_line_pointer;
23491 *input_line_pointer = 0;
23492
23493 /* Skip the first "all" entry. */
23494 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23495 if (streq (opt->name, name))
23496 {
e74cfd16
PB
23497 mcpu_cpu_opt = &opt->value;
23498 selected_cpu = opt->value;
5f4273c7 23499 strcpy (selected_cpu_name, opt->name);
e74cfd16 23500 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23501 *input_line_pointer = saved_char;
23502 demand_empty_rest_of_line ();
23503 return;
23504 }
23505
23506 as_bad (_("unknown architecture `%s'\n"), name);
23507 *input_line_pointer = saved_char;
23508 ignore_rest_of_line ();
23509}
23510
23511
7a1d4c38
PB
23512/* Parse a .object_arch directive. */
23513
23514static void
23515s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
23516{
23517 const struct arm_arch_option_table *opt;
23518 char saved_char;
23519 char *name;
23520
23521 name = input_line_pointer;
5f4273c7 23522 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
23523 input_line_pointer++;
23524 saved_char = *input_line_pointer;
23525 *input_line_pointer = 0;
23526
23527 /* Skip the first "all" entry. */
23528 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23529 if (streq (opt->name, name))
23530 {
23531 object_arch = &opt->value;
23532 *input_line_pointer = saved_char;
23533 demand_empty_rest_of_line ();
23534 return;
23535 }
23536
23537 as_bad (_("unknown architecture `%s'\n"), name);
23538 *input_line_pointer = saved_char;
23539 ignore_rest_of_line ();
23540}
23541
69133863
MGD
23542/* Parse a .arch_extension directive. */
23543
23544static void
23545s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
23546{
23547 const struct arm_option_extension_value_table *opt;
23548 char saved_char;
23549 char *name;
23550 int adding_value = 1;
23551
23552 name = input_line_pointer;
23553 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23554 input_line_pointer++;
23555 saved_char = *input_line_pointer;
23556 *input_line_pointer = 0;
23557
23558 if (strlen (name) >= 2
23559 && strncmp (name, "no", 2) == 0)
23560 {
23561 adding_value = 0;
23562 name += 2;
23563 }
23564
23565 for (opt = arm_extensions; opt->name != NULL; opt++)
23566 if (streq (opt->name, name))
23567 {
23568 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
23569 {
23570 as_bad (_("architectural extension `%s' is not allowed for the "
23571 "current base architecture"), name);
23572 break;
23573 }
23574
23575 if (adding_value)
23576 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
23577 else
23578 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
23579
23580 mcpu_cpu_opt = &selected_cpu;
23581 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23582 *input_line_pointer = saved_char;
23583 demand_empty_rest_of_line ();
23584 return;
23585 }
23586
23587 if (opt->name == NULL)
23588 as_bad (_("unknown architecture `%s'\n"), name);
23589
23590 *input_line_pointer = saved_char;
23591 ignore_rest_of_line ();
23592}
23593
ee065d83
PB
23594/* Parse a .fpu directive. */
23595
23596static void
23597s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
23598{
69133863 23599 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
23600 char saved_char;
23601 char *name;
23602
23603 name = input_line_pointer;
5f4273c7 23604 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23605 input_line_pointer++;
23606 saved_char = *input_line_pointer;
23607 *input_line_pointer = 0;
5f4273c7 23608
ee065d83
PB
23609 for (opt = arm_fpus; opt->name != NULL; opt++)
23610 if (streq (opt->name, name))
23611 {
e74cfd16
PB
23612 mfpu_opt = &opt->value;
23613 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23614 *input_line_pointer = saved_char;
23615 demand_empty_rest_of_line ();
23616 return;
23617 }
23618
23619 as_bad (_("unknown floating point format `%s'\n"), name);
23620 *input_line_pointer = saved_char;
23621 ignore_rest_of_line ();
23622}
ee065d83 23623
794ba86a 23624/* Copy symbol information. */
f31fef98 23625
794ba86a
DJ
23626void
23627arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
23628{
23629 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
23630}
e04befd0 23631
f31fef98 23632#ifdef OBJ_ELF
e04befd0
AS
23633/* Given a symbolic attribute NAME, return the proper integer value.
23634 Returns -1 if the attribute is not known. */
f31fef98 23635
e04befd0
AS
23636int
23637arm_convert_symbolic_attribute (const char *name)
23638{
f31fef98
NC
23639 static const struct
23640 {
23641 const char * name;
23642 const int tag;
23643 }
23644 attribute_table[] =
23645 {
23646 /* When you modify this table you should
23647 also modify the list in doc/c-arm.texi. */
e04befd0 23648#define T(tag) {#tag, tag}
f31fef98
NC
23649 T (Tag_CPU_raw_name),
23650 T (Tag_CPU_name),
23651 T (Tag_CPU_arch),
23652 T (Tag_CPU_arch_profile),
23653 T (Tag_ARM_ISA_use),
23654 T (Tag_THUMB_ISA_use),
75375b3e 23655 T (Tag_FP_arch),
f31fef98
NC
23656 T (Tag_VFP_arch),
23657 T (Tag_WMMX_arch),
23658 T (Tag_Advanced_SIMD_arch),
23659 T (Tag_PCS_config),
23660 T (Tag_ABI_PCS_R9_use),
23661 T (Tag_ABI_PCS_RW_data),
23662 T (Tag_ABI_PCS_RO_data),
23663 T (Tag_ABI_PCS_GOT_use),
23664 T (Tag_ABI_PCS_wchar_t),
23665 T (Tag_ABI_FP_rounding),
23666 T (Tag_ABI_FP_denormal),
23667 T (Tag_ABI_FP_exceptions),
23668 T (Tag_ABI_FP_user_exceptions),
23669 T (Tag_ABI_FP_number_model),
75375b3e 23670 T (Tag_ABI_align_needed),
f31fef98 23671 T (Tag_ABI_align8_needed),
75375b3e 23672 T (Tag_ABI_align_preserved),
f31fef98
NC
23673 T (Tag_ABI_align8_preserved),
23674 T (Tag_ABI_enum_size),
23675 T (Tag_ABI_HardFP_use),
23676 T (Tag_ABI_VFP_args),
23677 T (Tag_ABI_WMMX_args),
23678 T (Tag_ABI_optimization_goals),
23679 T (Tag_ABI_FP_optimization_goals),
23680 T (Tag_compatibility),
23681 T (Tag_CPU_unaligned_access),
75375b3e 23682 T (Tag_FP_HP_extension),
f31fef98
NC
23683 T (Tag_VFP_HP_extension),
23684 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
23685 T (Tag_MPextension_use),
23686 T (Tag_DIV_use),
f31fef98
NC
23687 T (Tag_nodefaults),
23688 T (Tag_also_compatible_with),
23689 T (Tag_conformance),
23690 T (Tag_T2EE_use),
23691 T (Tag_Virtualization_use),
cd21e546 23692 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 23693#undef T
f31fef98 23694 };
e04befd0
AS
23695 unsigned int i;
23696
23697 if (name == NULL)
23698 return -1;
23699
f31fef98 23700 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 23701 if (streq (name, attribute_table[i].name))
e04befd0
AS
23702 return attribute_table[i].tag;
23703
23704 return -1;
23705}
267bf995
RR
23706
23707
23708/* Apply sym value for relocations only in the case that
23709 they are for local symbols and you have the respective
23710 architectural feature for blx and simple switches. */
23711int
23712arm_apply_sym_value (struct fix * fixP)
23713{
23714 if (fixP->fx_addsy
23715 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23716 && !S_IS_EXTERNAL (fixP->fx_addsy))
23717 {
23718 switch (fixP->fx_r_type)
23719 {
23720 case BFD_RELOC_ARM_PCREL_BLX:
23721 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23722 if (ARM_IS_FUNC (fixP->fx_addsy))
23723 return 1;
23724 break;
23725
23726 case BFD_RELOC_ARM_PCREL_CALL:
23727 case BFD_RELOC_THUMB_PCREL_BLX:
23728 if (THUMB_IS_FUNC (fixP->fx_addsy))
23729 return 1;
23730 break;
23731
23732 default:
23733 break;
23734 }
23735
23736 }
23737 return 0;
23738}
f31fef98 23739#endif /* OBJ_ELF */