* gas/config/tc-arm.c (arm_cpus): Correct canonical names for Cortex CPUs.
[deliverable/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);
187static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
188static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 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
PB
198static const arm_feature_set arm_ext_m =
199 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
e74cfd16
PB
200
201static const arm_feature_set arm_arch_any = ARM_ANY;
202static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
203static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
204static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
205
2d447fca
JM
206static const arm_feature_set arm_cext_iwmmxt2 =
207 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
208static const arm_feature_set arm_cext_iwmmxt =
209 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
210static const arm_feature_set arm_cext_xscale =
211 ARM_FEATURE (0, ARM_CEXT_XSCALE);
212static const arm_feature_set arm_cext_maverick =
213 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
214static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
215static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
216static const arm_feature_set fpu_vfp_ext_v1xd =
217 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
218static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
219static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
62f3b8c8 220static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
5287ad62 221static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
222static const arm_feature_set fpu_vfp_ext_d32 =
223 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
224static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
225static const arm_feature_set fpu_vfp_v3_or_neon_ext =
226 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
62f3b8c8
PB
227static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
228static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
229static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
e74cfd16 230
33a392fb 231static int mfloat_abi_opt = -1;
e74cfd16
PB
232/* Record user cpu selection for object attributes. */
233static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
234/* Must be long enough to hold any of the names in arm_cpus. */
235static char selected_cpu_name[16];
7cc69913 236#ifdef OBJ_ELF
deeaaff8
DJ
237# ifdef EABI_DEFAULT
238static int meabi_flags = EABI_DEFAULT;
239# else
d507cf36 240static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 241# endif
e1da3f5b 242
ee3c0378
AS
243static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
244
e1da3f5b 245bfd_boolean
5f4273c7 246arm_is_eabi (void)
e1da3f5b
PB
247{
248 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
249}
7cc69913 250#endif
b99bd4ef 251
b99bd4ef 252#ifdef OBJ_ELF
c19d1205 253/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
254symbolS * GOT_symbol;
255#endif
256
b99bd4ef
NC
257/* 0: assemble for ARM,
258 1: assemble for Thumb,
259 2: assemble for Thumb even though target CPU does not support thumb
260 instructions. */
261static int thumb_mode = 0;
8dc2430f
NC
262/* A value distinct from the possible values for thumb_mode that we
263 can use to record whether thumb_mode has been copied into the
264 tc_frag_data field of a frag. */
265#define MODE_RECORDED (1 << 4)
b99bd4ef 266
e07e6e58
NC
267/* Specifies the intrinsic IT insn behavior mode. */
268enum implicit_it_mode
269{
270 IMPLICIT_IT_MODE_NEVER = 0x00,
271 IMPLICIT_IT_MODE_ARM = 0x01,
272 IMPLICIT_IT_MODE_THUMB = 0x02,
273 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
274};
275static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
276
c19d1205
ZW
277/* If unified_syntax is true, we are processing the new unified
278 ARM/Thumb syntax. Important differences from the old ARM mode:
279
280 - Immediate operands do not require a # prefix.
281 - Conditional affixes always appear at the end of the
282 instruction. (For backward compatibility, those instructions
283 that formerly had them in the middle, continue to accept them
284 there.)
285 - The IT instruction may appear, and if it does is validated
286 against subsequent conditional affixes. It does not generate
287 machine code.
288
289 Important differences from the old Thumb mode:
290
291 - Immediate operands do not require a # prefix.
292 - Most of the V6T2 instructions are only available in unified mode.
293 - The .N and .W suffixes are recognized and honored (it is an error
294 if they cannot be honored).
295 - All instructions set the flags if and only if they have an 's' affix.
296 - Conditional affixes may be used. They are validated against
297 preceding IT instructions. Unlike ARM mode, you cannot use a
298 conditional affix except in the scope of an IT instruction. */
299
300static bfd_boolean unified_syntax = FALSE;
b99bd4ef 301
5287ad62
JB
302enum neon_el_type
303{
dcbf9037 304 NT_invtype,
5287ad62
JB
305 NT_untyped,
306 NT_integer,
307 NT_float,
308 NT_poly,
309 NT_signed,
dcbf9037 310 NT_unsigned
5287ad62
JB
311};
312
313struct neon_type_el
314{
315 enum neon_el_type type;
316 unsigned size;
317};
318
319#define NEON_MAX_TYPE_ELS 4
320
321struct neon_type
322{
323 struct neon_type_el el[NEON_MAX_TYPE_ELS];
324 unsigned elems;
325};
326
e07e6e58
NC
327enum it_instruction_type
328{
329 OUTSIDE_IT_INSN,
330 INSIDE_IT_INSN,
331 INSIDE_IT_LAST_INSN,
332 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
333 if inside, should be the last one. */
334 NEUTRAL_IT_INSN, /* This could be either inside or outside,
335 i.e. BKPT and NOP. */
336 IT_INSN /* The IT insn has been parsed. */
337};
338
b99bd4ef
NC
339struct arm_it
340{
c19d1205 341 const char * error;
b99bd4ef 342 unsigned long instruction;
c19d1205
ZW
343 int size;
344 int size_req;
345 int cond;
037e8744
JB
346 /* "uncond_value" is set to the value in place of the conditional field in
347 unconditional versions of the instruction, or -1 if nothing is
348 appropriate. */
349 int uncond_value;
5287ad62 350 struct neon_type vectype;
88714cb8
DG
351 /* This does not indicate an actual NEON instruction, only that
352 the mnemonic accepts neon-style type suffixes. */
353 int is_neon;
0110f2b8
PB
354 /* Set to the opcode if the instruction needs relaxation.
355 Zero if the instruction is not relaxed. */
356 unsigned long relax;
b99bd4ef
NC
357 struct
358 {
359 bfd_reloc_code_real_type type;
c19d1205
ZW
360 expressionS exp;
361 int pc_rel;
b99bd4ef 362 } reloc;
b99bd4ef 363
e07e6e58
NC
364 enum it_instruction_type it_insn_type;
365
c19d1205
ZW
366 struct
367 {
368 unsigned reg;
ca3f61f7 369 signed int imm;
dcbf9037 370 struct neon_type_el vectype;
ca3f61f7
NC
371 unsigned present : 1; /* Operand present. */
372 unsigned isreg : 1; /* Operand was a register. */
373 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
374 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
375 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 376 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
377 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
378 instructions. This allows us to disambiguate ARM <-> vector insns. */
379 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 380 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 381 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 382 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
383 unsigned hasreloc : 1; /* Operand has relocation suffix. */
384 unsigned writeback : 1; /* Operand has trailing ! */
385 unsigned preind : 1; /* Preindexed address. */
386 unsigned postind : 1; /* Postindexed address. */
387 unsigned negative : 1; /* Index register was negated. */
388 unsigned shifted : 1; /* Shift applied to operation. */
389 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 390 } operands[6];
b99bd4ef
NC
391};
392
c19d1205 393static struct arm_it inst;
b99bd4ef
NC
394
395#define NUM_FLOAT_VALS 8
396
05d2d07e 397const char * fp_const[] =
b99bd4ef
NC
398{
399 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
400};
401
c19d1205 402/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
403#define MAX_LITTLENUMS 6
404
405LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
406
407#define FAIL (-1)
408#define SUCCESS (0)
409
410#define SUFF_S 1
411#define SUFF_D 2
412#define SUFF_E 3
413#define SUFF_P 4
414
c19d1205
ZW
415#define CP_T_X 0x00008000
416#define CP_T_Y 0x00400000
b99bd4ef 417
c19d1205
ZW
418#define CONDS_BIT 0x00100000
419#define LOAD_BIT 0x00100000
b99bd4ef
NC
420
421#define DOUBLE_LOAD_FLAG 0x00000001
422
423struct asm_cond
424{
d3ce72d0 425 const char * template_name;
c921be7d 426 unsigned long value;
b99bd4ef
NC
427};
428
c19d1205 429#define COND_ALWAYS 0xE
b99bd4ef 430
b99bd4ef
NC
431struct asm_psr
432{
d3ce72d0 433 const char * template_name;
c921be7d 434 unsigned long field;
b99bd4ef
NC
435};
436
62b3e311
PB
437struct asm_barrier_opt
438{
d3ce72d0 439 const char * template_name;
c921be7d 440 unsigned long value;
62b3e311
PB
441};
442
2d2255b5 443/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
444#define SPSR_BIT (1 << 22)
445
c19d1205
ZW
446/* The individual PSR flag bits. */
447#define PSR_c (1 << 16)
448#define PSR_x (1 << 17)
449#define PSR_s (1 << 18)
450#define PSR_f (1 << 19)
b99bd4ef 451
c19d1205 452struct reloc_entry
bfae80f2 453{
c921be7d
NC
454 char * name;
455 bfd_reloc_code_real_type reloc;
bfae80f2
RE
456};
457
5287ad62 458enum vfp_reg_pos
bfae80f2 459{
5287ad62
JB
460 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
461 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
462};
463
464enum vfp_ldstm_type
465{
466 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
467};
468
dcbf9037
JB
469/* Bits for DEFINED field in neon_typed_alias. */
470#define NTA_HASTYPE 1
471#define NTA_HASINDEX 2
472
473struct neon_typed_alias
474{
c921be7d
NC
475 unsigned char defined;
476 unsigned char index;
477 struct neon_type_el eltype;
dcbf9037
JB
478};
479
c19d1205
ZW
480/* ARM register categories. This includes coprocessor numbers and various
481 architecture extensions' registers. */
482enum arm_reg_type
bfae80f2 483{
c19d1205
ZW
484 REG_TYPE_RN,
485 REG_TYPE_CP,
486 REG_TYPE_CN,
487 REG_TYPE_FN,
488 REG_TYPE_VFS,
489 REG_TYPE_VFD,
5287ad62 490 REG_TYPE_NQ,
037e8744 491 REG_TYPE_VFSD,
5287ad62 492 REG_TYPE_NDQ,
037e8744 493 REG_TYPE_NSDQ,
c19d1205
ZW
494 REG_TYPE_VFC,
495 REG_TYPE_MVF,
496 REG_TYPE_MVD,
497 REG_TYPE_MVFX,
498 REG_TYPE_MVDX,
499 REG_TYPE_MVAX,
500 REG_TYPE_DSPSC,
501 REG_TYPE_MMXWR,
502 REG_TYPE_MMXWC,
503 REG_TYPE_MMXWCG,
504 REG_TYPE_XSCALE,
bfae80f2
RE
505};
506
dcbf9037
JB
507/* Structure for a hash table entry for a register.
508 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
509 information which states whether a vector type or index is specified (for a
510 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
511struct reg_entry
512{
c921be7d
NC
513 const char * name;
514 unsigned char number;
515 unsigned char type;
516 unsigned char builtin;
517 struct neon_typed_alias * neon;
6c43fab6
RE
518};
519
c19d1205 520/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 521const char * const reg_expected_msgs[] =
c19d1205
ZW
522{
523 N_("ARM register expected"),
524 N_("bad or missing co-processor number"),
525 N_("co-processor register expected"),
526 N_("FPA register expected"),
527 N_("VFP single precision register expected"),
5287ad62
JB
528 N_("VFP/Neon double precision register expected"),
529 N_("Neon quad precision register expected"),
037e8744 530 N_("VFP single or double precision register expected"),
5287ad62 531 N_("Neon double or quad precision register expected"),
037e8744 532 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
533 N_("VFP system register expected"),
534 N_("Maverick MVF register expected"),
535 N_("Maverick MVD register expected"),
536 N_("Maverick MVFX register expected"),
537 N_("Maverick MVDX register expected"),
538 N_("Maverick MVAX register expected"),
539 N_("Maverick DSPSC register expected"),
540 N_("iWMMXt data register expected"),
541 N_("iWMMXt control register expected"),
542 N_("iWMMXt scalar register expected"),
543 N_("XScale accumulator register expected"),
6c43fab6
RE
544};
545
c19d1205
ZW
546/* Some well known registers that we refer to directly elsewhere. */
547#define REG_SP 13
548#define REG_LR 14
549#define REG_PC 15
404ff6b5 550
b99bd4ef
NC
551/* ARM instructions take 4bytes in the object file, Thumb instructions
552 take 2: */
c19d1205 553#define INSN_SIZE 4
b99bd4ef
NC
554
555struct asm_opcode
556{
557 /* Basic string to match. */
d3ce72d0 558 const char * template_name;
c19d1205
ZW
559
560 /* Parameters to instruction. */
5be8be5d 561 unsigned int operands[8];
c19d1205
ZW
562
563 /* Conditional tag - see opcode_lookup. */
564 unsigned int tag : 4;
b99bd4ef
NC
565
566 /* Basic instruction code. */
c19d1205 567 unsigned int avalue : 28;
b99bd4ef 568
c19d1205
ZW
569 /* Thumb-format instruction code. */
570 unsigned int tvalue;
b99bd4ef 571
90e4755a 572 /* Which architecture variant provides this instruction. */
c921be7d
NC
573 const arm_feature_set * avariant;
574 const arm_feature_set * tvariant;
c19d1205
ZW
575
576 /* Function to call to encode instruction in ARM format. */
577 void (* aencode) (void);
b99bd4ef 578
c19d1205
ZW
579 /* Function to call to encode instruction in Thumb format. */
580 void (* tencode) (void);
b99bd4ef
NC
581};
582
a737bd4d
NC
583/* Defines for various bits that we will want to toggle. */
584#define INST_IMMEDIATE 0x02000000
585#define OFFSET_REG 0x02000000
c19d1205 586#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
587#define SHIFT_BY_REG 0x00000010
588#define PRE_INDEX 0x01000000
589#define INDEX_UP 0x00800000
590#define WRITE_BACK 0x00200000
591#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 592#define CPSI_MMOD 0x00020000
90e4755a 593
a737bd4d
NC
594#define LITERAL_MASK 0xf000f000
595#define OPCODE_MASK 0xfe1fffff
596#define V4_STR_BIT 0x00000020
90e4755a 597
efd81785
PB
598#define T2_SUBS_PC_LR 0xf3de8f00
599
a737bd4d 600#define DATA_OP_SHIFT 21
90e4755a 601
ef8d22e6
PB
602#define T2_OPCODE_MASK 0xfe1fffff
603#define T2_DATA_OP_SHIFT 21
604
a737bd4d
NC
605/* Codes to distinguish the arithmetic instructions. */
606#define OPCODE_AND 0
607#define OPCODE_EOR 1
608#define OPCODE_SUB 2
609#define OPCODE_RSB 3
610#define OPCODE_ADD 4
611#define OPCODE_ADC 5
612#define OPCODE_SBC 6
613#define OPCODE_RSC 7
614#define OPCODE_TST 8
615#define OPCODE_TEQ 9
616#define OPCODE_CMP 10
617#define OPCODE_CMN 11
618#define OPCODE_ORR 12
619#define OPCODE_MOV 13
620#define OPCODE_BIC 14
621#define OPCODE_MVN 15
90e4755a 622
ef8d22e6
PB
623#define T2_OPCODE_AND 0
624#define T2_OPCODE_BIC 1
625#define T2_OPCODE_ORR 2
626#define T2_OPCODE_ORN 3
627#define T2_OPCODE_EOR 4
628#define T2_OPCODE_ADD 8
629#define T2_OPCODE_ADC 10
630#define T2_OPCODE_SBC 11
631#define T2_OPCODE_SUB 13
632#define T2_OPCODE_RSB 14
633
a737bd4d
NC
634#define T_OPCODE_MUL 0x4340
635#define T_OPCODE_TST 0x4200
636#define T_OPCODE_CMN 0x42c0
637#define T_OPCODE_NEG 0x4240
638#define T_OPCODE_MVN 0x43c0
90e4755a 639
a737bd4d
NC
640#define T_OPCODE_ADD_R3 0x1800
641#define T_OPCODE_SUB_R3 0x1a00
642#define T_OPCODE_ADD_HI 0x4400
643#define T_OPCODE_ADD_ST 0xb000
644#define T_OPCODE_SUB_ST 0xb080
645#define T_OPCODE_ADD_SP 0xa800
646#define T_OPCODE_ADD_PC 0xa000
647#define T_OPCODE_ADD_I8 0x3000
648#define T_OPCODE_SUB_I8 0x3800
649#define T_OPCODE_ADD_I3 0x1c00
650#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 651
a737bd4d
NC
652#define T_OPCODE_ASR_R 0x4100
653#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
654#define T_OPCODE_LSR_R 0x40c0
655#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
656#define T_OPCODE_ASR_I 0x1000
657#define T_OPCODE_LSL_I 0x0000
658#define T_OPCODE_LSR_I 0x0800
b99bd4ef 659
a737bd4d
NC
660#define T_OPCODE_MOV_I8 0x2000
661#define T_OPCODE_CMP_I8 0x2800
662#define T_OPCODE_CMP_LR 0x4280
663#define T_OPCODE_MOV_HR 0x4600
664#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 665
a737bd4d
NC
666#define T_OPCODE_LDR_PC 0x4800
667#define T_OPCODE_LDR_SP 0x9800
668#define T_OPCODE_STR_SP 0x9000
669#define T_OPCODE_LDR_IW 0x6800
670#define T_OPCODE_STR_IW 0x6000
671#define T_OPCODE_LDR_IH 0x8800
672#define T_OPCODE_STR_IH 0x8000
673#define T_OPCODE_LDR_IB 0x7800
674#define T_OPCODE_STR_IB 0x7000
675#define T_OPCODE_LDR_RW 0x5800
676#define T_OPCODE_STR_RW 0x5000
677#define T_OPCODE_LDR_RH 0x5a00
678#define T_OPCODE_STR_RH 0x5200
679#define T_OPCODE_LDR_RB 0x5c00
680#define T_OPCODE_STR_RB 0x5400
c9b604bd 681
a737bd4d
NC
682#define T_OPCODE_PUSH 0xb400
683#define T_OPCODE_POP 0xbc00
b99bd4ef 684
2fc8bdac 685#define T_OPCODE_BRANCH 0xe000
b99bd4ef 686
a737bd4d 687#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 688#define THUMB_PP_PC_LR 0x0100
c19d1205 689#define THUMB_LOAD_BIT 0x0800
53365c0d 690#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
691
692#define BAD_ARGS _("bad arguments to instruction")
fdfde340 693#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
694#define BAD_PC _("r15 not allowed here")
695#define BAD_COND _("instruction cannot be conditional")
696#define BAD_OVERLAP _("registers may not be the same")
697#define BAD_HIREG _("lo register required")
698#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 699#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
700#define BAD_BRANCH _("branch must be last instruction in IT block")
701#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 702#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
703#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
704#define BAD_IT_COND _("incorrect condition in IT block")
705#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 706#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
707#define BAD_PC_ADDRESSING \
708 _("cannot use register index with PC-relative addressing")
709#define BAD_PC_WRITEBACK \
710 _("cannot use writeback with PC-relative addressing")
c19d1205 711
c921be7d
NC
712static struct hash_control * arm_ops_hsh;
713static struct hash_control * arm_cond_hsh;
714static struct hash_control * arm_shift_hsh;
715static struct hash_control * arm_psr_hsh;
716static struct hash_control * arm_v7m_psr_hsh;
717static struct hash_control * arm_reg_hsh;
718static struct hash_control * arm_reloc_hsh;
719static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 720
b99bd4ef
NC
721/* Stuff needed to resolve the label ambiguity
722 As:
723 ...
724 label: <insn>
725 may differ from:
726 ...
727 label:
5f4273c7 728 <insn> */
b99bd4ef
NC
729
730symbolS * last_label_seen;
b34976b6 731static int label_is_thumb_function_name = FALSE;
e07e6e58 732
3d0c9500
NC
733/* Literal pool structure. Held on a per-section
734 and per-sub-section basis. */
a737bd4d 735
c19d1205 736#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 737typedef struct literal_pool
b99bd4ef 738{
c921be7d
NC
739 expressionS literals [MAX_LITERAL_POOL_SIZE];
740 unsigned int next_free_entry;
741 unsigned int id;
742 symbolS * symbol;
743 segT section;
744 subsegT sub_section;
745 struct literal_pool * next;
3d0c9500 746} literal_pool;
b99bd4ef 747
3d0c9500
NC
748/* Pointer to a linked list of literal pools. */
749literal_pool * list_of_pools = NULL;
e27ec89e 750
e07e6e58
NC
751#ifdef OBJ_ELF
752# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
753#else
754static struct current_it now_it;
755#endif
756
757static inline int
758now_it_compatible (int cond)
759{
760 return (cond & ~1) == (now_it.cc & ~1);
761}
762
763static inline int
764conditional_insn (void)
765{
766 return inst.cond != COND_ALWAYS;
767}
768
769static int in_it_block (void);
770
771static int handle_it_state (void);
772
773static void force_automatic_it_block_close (void);
774
c921be7d
NC
775static void it_fsm_post_encode (void);
776
e07e6e58
NC
777#define set_it_insn_type(type) \
778 do \
779 { \
780 inst.it_insn_type = type; \
781 if (handle_it_state () == FAIL) \
782 return; \
783 } \
784 while (0)
785
c921be7d
NC
786#define set_it_insn_type_nonvoid(type, failret) \
787 do \
788 { \
789 inst.it_insn_type = type; \
790 if (handle_it_state () == FAIL) \
791 return failret; \
792 } \
793 while(0)
794
e07e6e58
NC
795#define set_it_insn_type_last() \
796 do \
797 { \
798 if (inst.cond == COND_ALWAYS) \
799 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
800 else \
801 set_it_insn_type (INSIDE_IT_LAST_INSN); \
802 } \
803 while (0)
804
c19d1205 805/* Pure syntax. */
b99bd4ef 806
c19d1205
ZW
807/* This array holds the chars that always start a comment. If the
808 pre-processor is disabled, these aren't very useful. */
809const char comment_chars[] = "@";
3d0c9500 810
c19d1205
ZW
811/* This array holds the chars that only start a comment at the beginning of
812 a line. If the line seems to have the form '# 123 filename'
813 .line and .file directives will appear in the pre-processed output. */
814/* Note that input_file.c hand checks for '#' at the beginning of the
815 first line of the input file. This is because the compiler outputs
816 #NO_APP at the beginning of its output. */
817/* Also note that comments like this one will always work. */
818const char line_comment_chars[] = "#";
3d0c9500 819
c19d1205 820const char line_separator_chars[] = ";";
b99bd4ef 821
c19d1205
ZW
822/* Chars that can be used to separate mant
823 from exp in floating point numbers. */
824const char EXP_CHARS[] = "eE";
3d0c9500 825
c19d1205
ZW
826/* Chars that mean this number is a floating point constant. */
827/* As in 0f12.456 */
828/* or 0d1.2345e12 */
b99bd4ef 829
c19d1205 830const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 831
c19d1205
ZW
832/* Prefix characters that indicate the start of an immediate
833 value. */
834#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 835
c19d1205
ZW
836/* Separator character handling. */
837
838#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
839
840static inline int
841skip_past_char (char ** str, char c)
842{
843 if (**str == c)
844 {
845 (*str)++;
846 return SUCCESS;
3d0c9500 847 }
c19d1205
ZW
848 else
849 return FAIL;
850}
c921be7d 851
c19d1205 852#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 853
c19d1205
ZW
854/* Arithmetic expressions (possibly involving symbols). */
855
856/* Return TRUE if anything in the expression is a bignum. */
857
858static int
859walk_no_bignums (symbolS * sp)
860{
861 if (symbol_get_value_expression (sp)->X_op == O_big)
862 return 1;
863
864 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 865 {
c19d1205
ZW
866 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
867 || (symbol_get_value_expression (sp)->X_op_symbol
868 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
869 }
870
c19d1205 871 return 0;
3d0c9500
NC
872}
873
c19d1205
ZW
874static int in_my_get_expression = 0;
875
876/* Third argument to my_get_expression. */
877#define GE_NO_PREFIX 0
878#define GE_IMM_PREFIX 1
879#define GE_OPT_PREFIX 2
5287ad62
JB
880/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
881 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
882#define GE_OPT_PREFIX_BIG 3
a737bd4d 883
b99bd4ef 884static int
c19d1205 885my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 886{
c19d1205
ZW
887 char * save_in;
888 segT seg;
b99bd4ef 889
c19d1205
ZW
890 /* In unified syntax, all prefixes are optional. */
891 if (unified_syntax)
5287ad62
JB
892 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
893 : GE_OPT_PREFIX;
b99bd4ef 894
c19d1205 895 switch (prefix_mode)
b99bd4ef 896 {
c19d1205
ZW
897 case GE_NO_PREFIX: break;
898 case GE_IMM_PREFIX:
899 if (!is_immediate_prefix (**str))
900 {
901 inst.error = _("immediate expression requires a # prefix");
902 return FAIL;
903 }
904 (*str)++;
905 break;
906 case GE_OPT_PREFIX:
5287ad62 907 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
908 if (is_immediate_prefix (**str))
909 (*str)++;
910 break;
911 default: abort ();
912 }
b99bd4ef 913
c19d1205 914 memset (ep, 0, sizeof (expressionS));
b99bd4ef 915
c19d1205
ZW
916 save_in = input_line_pointer;
917 input_line_pointer = *str;
918 in_my_get_expression = 1;
919 seg = expression (ep);
920 in_my_get_expression = 0;
921
f86adc07 922 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 923 {
f86adc07 924 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
925 *str = input_line_pointer;
926 input_line_pointer = save_in;
927 if (inst.error == NULL)
f86adc07
NS
928 inst.error = (ep->X_op == O_absent
929 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
930 return 1;
931 }
b99bd4ef 932
c19d1205
ZW
933#ifdef OBJ_AOUT
934 if (seg != absolute_section
935 && seg != text_section
936 && seg != data_section
937 && seg != bss_section
938 && seg != undefined_section)
939 {
940 inst.error = _("bad segment");
941 *str = input_line_pointer;
942 input_line_pointer = save_in;
943 return 1;
b99bd4ef 944 }
87975d2a
AM
945#else
946 (void) seg;
c19d1205 947#endif
b99bd4ef 948
c19d1205
ZW
949 /* Get rid of any bignums now, so that we don't generate an error for which
950 we can't establish a line number later on. Big numbers are never valid
951 in instructions, which is where this routine is always called. */
5287ad62
JB
952 if (prefix_mode != GE_OPT_PREFIX_BIG
953 && (ep->X_op == O_big
954 || (ep->X_add_symbol
955 && (walk_no_bignums (ep->X_add_symbol)
956 || (ep->X_op_symbol
957 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
958 {
959 inst.error = _("invalid constant");
960 *str = input_line_pointer;
961 input_line_pointer = save_in;
962 return 1;
963 }
b99bd4ef 964
c19d1205
ZW
965 *str = input_line_pointer;
966 input_line_pointer = save_in;
967 return 0;
b99bd4ef
NC
968}
969
c19d1205
ZW
970/* Turn a string in input_line_pointer into a floating point constant
971 of type TYPE, and store the appropriate bytes in *LITP. The number
972 of LITTLENUMS emitted is stored in *SIZEP. An error message is
973 returned, or NULL on OK.
b99bd4ef 974
c19d1205
ZW
975 Note that fp constants aren't represent in the normal way on the ARM.
976 In big endian mode, things are as expected. However, in little endian
977 mode fp constants are big-endian word-wise, and little-endian byte-wise
978 within the words. For example, (double) 1.1 in big endian mode is
979 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
980 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 981
c19d1205 982 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 983
c19d1205
ZW
984char *
985md_atof (int type, char * litP, int * sizeP)
986{
987 int prec;
988 LITTLENUM_TYPE words[MAX_LITTLENUMS];
989 char *t;
990 int i;
b99bd4ef 991
c19d1205
ZW
992 switch (type)
993 {
994 case 'f':
995 case 'F':
996 case 's':
997 case 'S':
998 prec = 2;
999 break;
b99bd4ef 1000
c19d1205
ZW
1001 case 'd':
1002 case 'D':
1003 case 'r':
1004 case 'R':
1005 prec = 4;
1006 break;
b99bd4ef 1007
c19d1205
ZW
1008 case 'x':
1009 case 'X':
499ac353 1010 prec = 5;
c19d1205 1011 break;
b99bd4ef 1012
c19d1205
ZW
1013 case 'p':
1014 case 'P':
499ac353 1015 prec = 5;
c19d1205 1016 break;
a737bd4d 1017
c19d1205
ZW
1018 default:
1019 *sizeP = 0;
499ac353 1020 return _("Unrecognized or unsupported floating point constant");
c19d1205 1021 }
b99bd4ef 1022
c19d1205
ZW
1023 t = atof_ieee (input_line_pointer, type, words);
1024 if (t)
1025 input_line_pointer = t;
499ac353 1026 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1027
c19d1205
ZW
1028 if (target_big_endian)
1029 {
1030 for (i = 0; i < prec; i++)
1031 {
499ac353
NC
1032 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1033 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1034 }
1035 }
1036 else
1037 {
e74cfd16 1038 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1039 for (i = prec - 1; i >= 0; i--)
1040 {
499ac353
NC
1041 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1042 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1043 }
1044 else
1045 /* For a 4 byte float the order of elements in `words' is 1 0.
1046 For an 8 byte float the order is 1 0 3 2. */
1047 for (i = 0; i < prec; i += 2)
1048 {
499ac353
NC
1049 md_number_to_chars (litP, (valueT) words[i + 1],
1050 sizeof (LITTLENUM_TYPE));
1051 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1052 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1053 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1054 }
1055 }
b99bd4ef 1056
499ac353 1057 return NULL;
c19d1205 1058}
b99bd4ef 1059
c19d1205
ZW
1060/* We handle all bad expressions here, so that we can report the faulty
1061 instruction in the error message. */
1062void
91d6fa6a 1063md_operand (expressionS * exp)
c19d1205
ZW
1064{
1065 if (in_my_get_expression)
91d6fa6a 1066 exp->X_op = O_illegal;
b99bd4ef
NC
1067}
1068
c19d1205 1069/* Immediate values. */
b99bd4ef 1070
c19d1205
ZW
1071/* Generic immediate-value read function for use in directives.
1072 Accepts anything that 'expression' can fold to a constant.
1073 *val receives the number. */
1074#ifdef OBJ_ELF
1075static int
1076immediate_for_directive (int *val)
b99bd4ef 1077{
c19d1205
ZW
1078 expressionS exp;
1079 exp.X_op = O_illegal;
b99bd4ef 1080
c19d1205
ZW
1081 if (is_immediate_prefix (*input_line_pointer))
1082 {
1083 input_line_pointer++;
1084 expression (&exp);
1085 }
b99bd4ef 1086
c19d1205
ZW
1087 if (exp.X_op != O_constant)
1088 {
1089 as_bad (_("expected #constant"));
1090 ignore_rest_of_line ();
1091 return FAIL;
1092 }
1093 *val = exp.X_add_number;
1094 return SUCCESS;
b99bd4ef 1095}
c19d1205 1096#endif
b99bd4ef 1097
c19d1205 1098/* Register parsing. */
b99bd4ef 1099
c19d1205
ZW
1100/* Generic register parser. CCP points to what should be the
1101 beginning of a register name. If it is indeed a valid register
1102 name, advance CCP over it and return the reg_entry structure;
1103 otherwise return NULL. Does not issue diagnostics. */
1104
1105static struct reg_entry *
1106arm_reg_parse_multi (char **ccp)
b99bd4ef 1107{
c19d1205
ZW
1108 char *start = *ccp;
1109 char *p;
1110 struct reg_entry *reg;
b99bd4ef 1111
c19d1205
ZW
1112#ifdef REGISTER_PREFIX
1113 if (*start != REGISTER_PREFIX)
01cfc07f 1114 return NULL;
c19d1205
ZW
1115 start++;
1116#endif
1117#ifdef OPTIONAL_REGISTER_PREFIX
1118 if (*start == OPTIONAL_REGISTER_PREFIX)
1119 start++;
1120#endif
b99bd4ef 1121
c19d1205
ZW
1122 p = start;
1123 if (!ISALPHA (*p) || !is_name_beginner (*p))
1124 return NULL;
b99bd4ef 1125
c19d1205
ZW
1126 do
1127 p++;
1128 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1129
1130 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1131
1132 if (!reg)
1133 return NULL;
1134
1135 *ccp = p;
1136 return reg;
b99bd4ef
NC
1137}
1138
1139static int
dcbf9037
JB
1140arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1141 enum arm_reg_type type)
b99bd4ef 1142{
c19d1205
ZW
1143 /* Alternative syntaxes are accepted for a few register classes. */
1144 switch (type)
1145 {
1146 case REG_TYPE_MVF:
1147 case REG_TYPE_MVD:
1148 case REG_TYPE_MVFX:
1149 case REG_TYPE_MVDX:
1150 /* Generic coprocessor register names are allowed for these. */
79134647 1151 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1152 return reg->number;
1153 break;
69b97547 1154
c19d1205
ZW
1155 case REG_TYPE_CP:
1156 /* For backward compatibility, a bare number is valid here. */
1157 {
1158 unsigned long processor = strtoul (start, ccp, 10);
1159 if (*ccp != start && processor <= 15)
1160 return processor;
1161 }
6057a28f 1162
c19d1205
ZW
1163 case REG_TYPE_MMXWC:
1164 /* WC includes WCG. ??? I'm not sure this is true for all
1165 instructions that take WC registers. */
79134647 1166 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1167 return reg->number;
6057a28f 1168 break;
c19d1205 1169
6057a28f 1170 default:
c19d1205 1171 break;
6057a28f
NC
1172 }
1173
dcbf9037
JB
1174 return FAIL;
1175}
1176
1177/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1178 return value is the register number or FAIL. */
1179
1180static int
1181arm_reg_parse (char **ccp, enum arm_reg_type type)
1182{
1183 char *start = *ccp;
1184 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1185 int ret;
1186
1187 /* Do not allow a scalar (reg+index) to parse as a register. */
1188 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1189 return FAIL;
1190
1191 if (reg && reg->type == type)
1192 return reg->number;
1193
1194 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1195 return ret;
1196
c19d1205
ZW
1197 *ccp = start;
1198 return FAIL;
1199}
69b97547 1200
dcbf9037
JB
1201/* Parse a Neon type specifier. *STR should point at the leading '.'
1202 character. Does no verification at this stage that the type fits the opcode
1203 properly. E.g.,
1204
1205 .i32.i32.s16
1206 .s32.f32
1207 .u16
1208
1209 Can all be legally parsed by this function.
1210
1211 Fills in neon_type struct pointer with parsed information, and updates STR
1212 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1213 type, FAIL if not. */
1214
1215static int
1216parse_neon_type (struct neon_type *type, char **str)
1217{
1218 char *ptr = *str;
1219
1220 if (type)
1221 type->elems = 0;
1222
1223 while (type->elems < NEON_MAX_TYPE_ELS)
1224 {
1225 enum neon_el_type thistype = NT_untyped;
1226 unsigned thissize = -1u;
1227
1228 if (*ptr != '.')
1229 break;
1230
1231 ptr++;
1232
1233 /* Just a size without an explicit type. */
1234 if (ISDIGIT (*ptr))
1235 goto parsesize;
1236
1237 switch (TOLOWER (*ptr))
1238 {
1239 case 'i': thistype = NT_integer; break;
1240 case 'f': thistype = NT_float; break;
1241 case 'p': thistype = NT_poly; break;
1242 case 's': thistype = NT_signed; break;
1243 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1244 case 'd':
1245 thistype = NT_float;
1246 thissize = 64;
1247 ptr++;
1248 goto done;
dcbf9037
JB
1249 default:
1250 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1251 return FAIL;
1252 }
1253
1254 ptr++;
1255
1256 /* .f is an abbreviation for .f32. */
1257 if (thistype == NT_float && !ISDIGIT (*ptr))
1258 thissize = 32;
1259 else
1260 {
1261 parsesize:
1262 thissize = strtoul (ptr, &ptr, 10);
1263
1264 if (thissize != 8 && thissize != 16 && thissize != 32
1265 && thissize != 64)
1266 {
1267 as_bad (_("bad size %d in type specifier"), thissize);
1268 return FAIL;
1269 }
1270 }
1271
037e8744 1272 done:
dcbf9037
JB
1273 if (type)
1274 {
1275 type->el[type->elems].type = thistype;
1276 type->el[type->elems].size = thissize;
1277 type->elems++;
1278 }
1279 }
1280
1281 /* Empty/missing type is not a successful parse. */
1282 if (type->elems == 0)
1283 return FAIL;
1284
1285 *str = ptr;
1286
1287 return SUCCESS;
1288}
1289
1290/* Errors may be set multiple times during parsing or bit encoding
1291 (particularly in the Neon bits), but usually the earliest error which is set
1292 will be the most meaningful. Avoid overwriting it with later (cascading)
1293 errors by calling this function. */
1294
1295static void
1296first_error (const char *err)
1297{
1298 if (!inst.error)
1299 inst.error = err;
1300}
1301
1302/* Parse a single type, e.g. ".s32", leading period included. */
1303static int
1304parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1305{
1306 char *str = *ccp;
1307 struct neon_type optype;
1308
1309 if (*str == '.')
1310 {
1311 if (parse_neon_type (&optype, &str) == SUCCESS)
1312 {
1313 if (optype.elems == 1)
1314 *vectype = optype.el[0];
1315 else
1316 {
1317 first_error (_("only one type should be specified for operand"));
1318 return FAIL;
1319 }
1320 }
1321 else
1322 {
1323 first_error (_("vector type expected"));
1324 return FAIL;
1325 }
1326 }
1327 else
1328 return FAIL;
5f4273c7 1329
dcbf9037 1330 *ccp = str;
5f4273c7 1331
dcbf9037
JB
1332 return SUCCESS;
1333}
1334
1335/* Special meanings for indices (which have a range of 0-7), which will fit into
1336 a 4-bit integer. */
1337
1338#define NEON_ALL_LANES 15
1339#define NEON_INTERLEAVE_LANES 14
1340
1341/* Parse either a register or a scalar, with an optional type. Return the
1342 register number, and optionally fill in the actual type of the register
1343 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1344 type/index information in *TYPEINFO. */
1345
1346static int
1347parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1348 enum arm_reg_type *rtype,
1349 struct neon_typed_alias *typeinfo)
1350{
1351 char *str = *ccp;
1352 struct reg_entry *reg = arm_reg_parse_multi (&str);
1353 struct neon_typed_alias atype;
1354 struct neon_type_el parsetype;
1355
1356 atype.defined = 0;
1357 atype.index = -1;
1358 atype.eltype.type = NT_invtype;
1359 atype.eltype.size = -1;
1360
1361 /* Try alternate syntax for some types of register. Note these are mutually
1362 exclusive with the Neon syntax extensions. */
1363 if (reg == NULL)
1364 {
1365 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1366 if (altreg != FAIL)
1367 *ccp = str;
1368 if (typeinfo)
1369 *typeinfo = atype;
1370 return altreg;
1371 }
1372
037e8744
JB
1373 /* Undo polymorphism when a set of register types may be accepted. */
1374 if ((type == REG_TYPE_NDQ
1375 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1376 || (type == REG_TYPE_VFSD
1377 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1378 || (type == REG_TYPE_NSDQ
1379 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1380 || reg->type == REG_TYPE_NQ))
1381 || (type == REG_TYPE_MMXWC
1382 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1383 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1384
1385 if (type != reg->type)
1386 return FAIL;
1387
1388 if (reg->neon)
1389 atype = *reg->neon;
5f4273c7 1390
dcbf9037
JB
1391 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1392 {
1393 if ((atype.defined & NTA_HASTYPE) != 0)
1394 {
1395 first_error (_("can't redefine type for operand"));
1396 return FAIL;
1397 }
1398 atype.defined |= NTA_HASTYPE;
1399 atype.eltype = parsetype;
1400 }
5f4273c7 1401
dcbf9037
JB
1402 if (skip_past_char (&str, '[') == SUCCESS)
1403 {
1404 if (type != REG_TYPE_VFD)
1405 {
1406 first_error (_("only D registers may be indexed"));
1407 return FAIL;
1408 }
5f4273c7 1409
dcbf9037
JB
1410 if ((atype.defined & NTA_HASINDEX) != 0)
1411 {
1412 first_error (_("can't change index for operand"));
1413 return FAIL;
1414 }
1415
1416 atype.defined |= NTA_HASINDEX;
1417
1418 if (skip_past_char (&str, ']') == SUCCESS)
1419 atype.index = NEON_ALL_LANES;
1420 else
1421 {
1422 expressionS exp;
1423
1424 my_get_expression (&exp, &str, GE_NO_PREFIX);
1425
1426 if (exp.X_op != O_constant)
1427 {
1428 first_error (_("constant expression required"));
1429 return FAIL;
1430 }
1431
1432 if (skip_past_char (&str, ']') == FAIL)
1433 return FAIL;
1434
1435 atype.index = exp.X_add_number;
1436 }
1437 }
5f4273c7 1438
dcbf9037
JB
1439 if (typeinfo)
1440 *typeinfo = atype;
5f4273c7 1441
dcbf9037
JB
1442 if (rtype)
1443 *rtype = type;
5f4273c7 1444
dcbf9037 1445 *ccp = str;
5f4273c7 1446
dcbf9037
JB
1447 return reg->number;
1448}
1449
1450/* Like arm_reg_parse, but allow allow the following extra features:
1451 - If RTYPE is non-zero, return the (possibly restricted) type of the
1452 register (e.g. Neon double or quad reg when either has been requested).
1453 - If this is a Neon vector type with additional type information, fill
1454 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1455 This function will fault on encountering a scalar. */
dcbf9037
JB
1456
1457static int
1458arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1459 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1460{
1461 struct neon_typed_alias atype;
1462 char *str = *ccp;
1463 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1464
1465 if (reg == FAIL)
1466 return FAIL;
1467
1468 /* Do not allow a scalar (reg+index) to parse as a register. */
1469 if ((atype.defined & NTA_HASINDEX) != 0)
1470 {
1471 first_error (_("register operand expected, but got scalar"));
1472 return FAIL;
1473 }
1474
1475 if (vectype)
1476 *vectype = atype.eltype;
1477
1478 *ccp = str;
1479
1480 return reg;
1481}
1482
1483#define NEON_SCALAR_REG(X) ((X) >> 4)
1484#define NEON_SCALAR_INDEX(X) ((X) & 15)
1485
5287ad62
JB
1486/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1487 have enough information to be able to do a good job bounds-checking. So, we
1488 just do easy checks here, and do further checks later. */
1489
1490static int
dcbf9037 1491parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1492{
dcbf9037 1493 int reg;
5287ad62 1494 char *str = *ccp;
dcbf9037 1495 struct neon_typed_alias atype;
5f4273c7 1496
dcbf9037 1497 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1498
dcbf9037 1499 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1500 return FAIL;
5f4273c7 1501
dcbf9037 1502 if (atype.index == NEON_ALL_LANES)
5287ad62 1503 {
dcbf9037 1504 first_error (_("scalar must have an index"));
5287ad62
JB
1505 return FAIL;
1506 }
dcbf9037 1507 else if (atype.index >= 64 / elsize)
5287ad62 1508 {
dcbf9037 1509 first_error (_("scalar index out of range"));
5287ad62
JB
1510 return FAIL;
1511 }
5f4273c7 1512
dcbf9037
JB
1513 if (type)
1514 *type = atype.eltype;
5f4273c7 1515
5287ad62 1516 *ccp = str;
5f4273c7 1517
dcbf9037 1518 return reg * 16 + atype.index;
5287ad62
JB
1519}
1520
c19d1205 1521/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1522
c19d1205
ZW
1523static long
1524parse_reg_list (char ** strp)
1525{
1526 char * str = * strp;
1527 long range = 0;
1528 int another_range;
a737bd4d 1529
c19d1205
ZW
1530 /* We come back here if we get ranges concatenated by '+' or '|'. */
1531 do
6057a28f 1532 {
c19d1205 1533 another_range = 0;
a737bd4d 1534
c19d1205
ZW
1535 if (*str == '{')
1536 {
1537 int in_range = 0;
1538 int cur_reg = -1;
a737bd4d 1539
c19d1205
ZW
1540 str++;
1541 do
1542 {
1543 int reg;
6057a28f 1544
dcbf9037 1545 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1546 {
dcbf9037 1547 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1548 return FAIL;
1549 }
a737bd4d 1550
c19d1205
ZW
1551 if (in_range)
1552 {
1553 int i;
a737bd4d 1554
c19d1205
ZW
1555 if (reg <= cur_reg)
1556 {
dcbf9037 1557 first_error (_("bad range in register list"));
c19d1205
ZW
1558 return FAIL;
1559 }
40a18ebd 1560
c19d1205
ZW
1561 for (i = cur_reg + 1; i < reg; i++)
1562 {
1563 if (range & (1 << i))
1564 as_tsktsk
1565 (_("Warning: duplicated register (r%d) in register list"),
1566 i);
1567 else
1568 range |= 1 << i;
1569 }
1570 in_range = 0;
1571 }
a737bd4d 1572
c19d1205
ZW
1573 if (range & (1 << reg))
1574 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1575 reg);
1576 else if (reg <= cur_reg)
1577 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1578
c19d1205
ZW
1579 range |= 1 << reg;
1580 cur_reg = reg;
1581 }
1582 while (skip_past_comma (&str) != FAIL
1583 || (in_range = 1, *str++ == '-'));
1584 str--;
a737bd4d 1585
c19d1205
ZW
1586 if (*str++ != '}')
1587 {
dcbf9037 1588 first_error (_("missing `}'"));
c19d1205
ZW
1589 return FAIL;
1590 }
1591 }
1592 else
1593 {
91d6fa6a 1594 expressionS exp;
40a18ebd 1595
91d6fa6a 1596 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1597 return FAIL;
40a18ebd 1598
91d6fa6a 1599 if (exp.X_op == O_constant)
c19d1205 1600 {
91d6fa6a
NC
1601 if (exp.X_add_number
1602 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1603 {
1604 inst.error = _("invalid register mask");
1605 return FAIL;
1606 }
a737bd4d 1607
91d6fa6a 1608 if ((range & exp.X_add_number) != 0)
c19d1205 1609 {
91d6fa6a 1610 int regno = range & exp.X_add_number;
a737bd4d 1611
c19d1205
ZW
1612 regno &= -regno;
1613 regno = (1 << regno) - 1;
1614 as_tsktsk
1615 (_("Warning: duplicated register (r%d) in register list"),
1616 regno);
1617 }
a737bd4d 1618
91d6fa6a 1619 range |= exp.X_add_number;
c19d1205
ZW
1620 }
1621 else
1622 {
1623 if (inst.reloc.type != 0)
1624 {
1625 inst.error = _("expression too complex");
1626 return FAIL;
1627 }
a737bd4d 1628
91d6fa6a 1629 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1630 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1631 inst.reloc.pc_rel = 0;
1632 }
1633 }
a737bd4d 1634
c19d1205
ZW
1635 if (*str == '|' || *str == '+')
1636 {
1637 str++;
1638 another_range = 1;
1639 }
a737bd4d 1640 }
c19d1205 1641 while (another_range);
a737bd4d 1642
c19d1205
ZW
1643 *strp = str;
1644 return range;
a737bd4d
NC
1645}
1646
5287ad62
JB
1647/* Types of registers in a list. */
1648
1649enum reg_list_els
1650{
1651 REGLIST_VFP_S,
1652 REGLIST_VFP_D,
1653 REGLIST_NEON_D
1654};
1655
c19d1205
ZW
1656/* Parse a VFP register list. If the string is invalid return FAIL.
1657 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1658 register. Parses registers of type ETYPE.
1659 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1660 - Q registers can be used to specify pairs of D registers
1661 - { } can be omitted from around a singleton register list
1662 FIXME: This is not implemented, as it would require backtracking in
1663 some cases, e.g.:
1664 vtbl.8 d3,d4,d5
1665 This could be done (the meaning isn't really ambiguous), but doesn't
1666 fit in well with the current parsing framework.
dcbf9037
JB
1667 - 32 D registers may be used (also true for VFPv3).
1668 FIXME: Types are ignored in these register lists, which is probably a
1669 bug. */
6057a28f 1670
c19d1205 1671static int
037e8744 1672parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1673{
037e8744 1674 char *str = *ccp;
c19d1205
ZW
1675 int base_reg;
1676 int new_base;
21d799b5 1677 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1678 int max_regs = 0;
c19d1205
ZW
1679 int count = 0;
1680 int warned = 0;
1681 unsigned long mask = 0;
a737bd4d 1682 int i;
6057a28f 1683
037e8744 1684 if (*str != '{')
5287ad62
JB
1685 {
1686 inst.error = _("expecting {");
1687 return FAIL;
1688 }
6057a28f 1689
037e8744 1690 str++;
6057a28f 1691
5287ad62 1692 switch (etype)
c19d1205 1693 {
5287ad62 1694 case REGLIST_VFP_S:
c19d1205
ZW
1695 regtype = REG_TYPE_VFS;
1696 max_regs = 32;
5287ad62 1697 break;
5f4273c7 1698
5287ad62
JB
1699 case REGLIST_VFP_D:
1700 regtype = REG_TYPE_VFD;
b7fc2769 1701 break;
5f4273c7 1702
b7fc2769
JB
1703 case REGLIST_NEON_D:
1704 regtype = REG_TYPE_NDQ;
1705 break;
1706 }
1707
1708 if (etype != REGLIST_VFP_S)
1709 {
b1cc4aeb
PB
1710 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1711 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1712 {
1713 max_regs = 32;
1714 if (thumb_mode)
1715 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1716 fpu_vfp_ext_d32);
5287ad62
JB
1717 else
1718 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1719 fpu_vfp_ext_d32);
5287ad62
JB
1720 }
1721 else
1722 max_regs = 16;
c19d1205 1723 }
6057a28f 1724
c19d1205 1725 base_reg = max_regs;
a737bd4d 1726
c19d1205
ZW
1727 do
1728 {
5287ad62 1729 int setmask = 1, addregs = 1;
dcbf9037 1730
037e8744 1731 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1732
c19d1205 1733 if (new_base == FAIL)
a737bd4d 1734 {
dcbf9037 1735 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1736 return FAIL;
1737 }
5f4273c7 1738
b7fc2769
JB
1739 if (new_base >= max_regs)
1740 {
1741 first_error (_("register out of range in list"));
1742 return FAIL;
1743 }
5f4273c7 1744
5287ad62
JB
1745 /* Note: a value of 2 * n is returned for the register Q<n>. */
1746 if (regtype == REG_TYPE_NQ)
1747 {
1748 setmask = 3;
1749 addregs = 2;
1750 }
1751
c19d1205
ZW
1752 if (new_base < base_reg)
1753 base_reg = new_base;
a737bd4d 1754
5287ad62 1755 if (mask & (setmask << new_base))
c19d1205 1756 {
dcbf9037 1757 first_error (_("invalid register list"));
c19d1205 1758 return FAIL;
a737bd4d 1759 }
a737bd4d 1760
c19d1205
ZW
1761 if ((mask >> new_base) != 0 && ! warned)
1762 {
1763 as_tsktsk (_("register list not in ascending order"));
1764 warned = 1;
1765 }
0bbf2aa4 1766
5287ad62
JB
1767 mask |= setmask << new_base;
1768 count += addregs;
0bbf2aa4 1769
037e8744 1770 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1771 {
1772 int high_range;
0bbf2aa4 1773
037e8744 1774 str++;
0bbf2aa4 1775
037e8744 1776 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1777 == FAIL)
c19d1205
ZW
1778 {
1779 inst.error = gettext (reg_expected_msgs[regtype]);
1780 return FAIL;
1781 }
0bbf2aa4 1782
b7fc2769
JB
1783 if (high_range >= max_regs)
1784 {
1785 first_error (_("register out of range in list"));
1786 return FAIL;
1787 }
1788
5287ad62
JB
1789 if (regtype == REG_TYPE_NQ)
1790 high_range = high_range + 1;
1791
c19d1205
ZW
1792 if (high_range <= new_base)
1793 {
1794 inst.error = _("register range not in ascending order");
1795 return FAIL;
1796 }
0bbf2aa4 1797
5287ad62 1798 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1799 {
5287ad62 1800 if (mask & (setmask << new_base))
0bbf2aa4 1801 {
c19d1205
ZW
1802 inst.error = _("invalid register list");
1803 return FAIL;
0bbf2aa4 1804 }
c19d1205 1805
5287ad62
JB
1806 mask |= setmask << new_base;
1807 count += addregs;
0bbf2aa4 1808 }
0bbf2aa4 1809 }
0bbf2aa4 1810 }
037e8744 1811 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1812
037e8744 1813 str++;
0bbf2aa4 1814
c19d1205
ZW
1815 /* Sanity check -- should have raised a parse error above. */
1816 if (count == 0 || count > max_regs)
1817 abort ();
1818
1819 *pbase = base_reg;
1820
1821 /* Final test -- the registers must be consecutive. */
1822 mask >>= base_reg;
1823 for (i = 0; i < count; i++)
1824 {
1825 if ((mask & (1u << i)) == 0)
1826 {
1827 inst.error = _("non-contiguous register range");
1828 return FAIL;
1829 }
1830 }
1831
037e8744
JB
1832 *ccp = str;
1833
c19d1205 1834 return count;
b99bd4ef
NC
1835}
1836
dcbf9037
JB
1837/* True if two alias types are the same. */
1838
c921be7d 1839static bfd_boolean
dcbf9037
JB
1840neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1841{
1842 if (!a && !b)
c921be7d 1843 return TRUE;
5f4273c7 1844
dcbf9037 1845 if (!a || !b)
c921be7d 1846 return FALSE;
dcbf9037
JB
1847
1848 if (a->defined != b->defined)
c921be7d 1849 return FALSE;
5f4273c7 1850
dcbf9037
JB
1851 if ((a->defined & NTA_HASTYPE) != 0
1852 && (a->eltype.type != b->eltype.type
1853 || a->eltype.size != b->eltype.size))
c921be7d 1854 return FALSE;
dcbf9037
JB
1855
1856 if ((a->defined & NTA_HASINDEX) != 0
1857 && (a->index != b->index))
c921be7d 1858 return FALSE;
5f4273c7 1859
c921be7d 1860 return TRUE;
dcbf9037
JB
1861}
1862
5287ad62
JB
1863/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1864 The base register is put in *PBASE.
dcbf9037 1865 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1866 the return value.
1867 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1868 Bits [6:5] encode the list length (minus one).
1869 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1870
5287ad62 1871#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1872#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1873#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1874
1875static int
dcbf9037
JB
1876parse_neon_el_struct_list (char **str, unsigned *pbase,
1877 struct neon_type_el *eltype)
5287ad62
JB
1878{
1879 char *ptr = *str;
1880 int base_reg = -1;
1881 int reg_incr = -1;
1882 int count = 0;
1883 int lane = -1;
1884 int leading_brace = 0;
1885 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1886 const char *const incr_error = _("register stride must be 1 or 2");
1887 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1888 struct neon_typed_alias firsttype;
5f4273c7 1889
5287ad62
JB
1890 if (skip_past_char (&ptr, '{') == SUCCESS)
1891 leading_brace = 1;
5f4273c7 1892
5287ad62
JB
1893 do
1894 {
dcbf9037
JB
1895 struct neon_typed_alias atype;
1896 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1897
5287ad62
JB
1898 if (getreg == FAIL)
1899 {
dcbf9037 1900 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1901 return FAIL;
1902 }
5f4273c7 1903
5287ad62
JB
1904 if (base_reg == -1)
1905 {
1906 base_reg = getreg;
1907 if (rtype == REG_TYPE_NQ)
1908 {
1909 reg_incr = 1;
5287ad62 1910 }
dcbf9037 1911 firsttype = atype;
5287ad62
JB
1912 }
1913 else if (reg_incr == -1)
1914 {
1915 reg_incr = getreg - base_reg;
1916 if (reg_incr < 1 || reg_incr > 2)
1917 {
dcbf9037 1918 first_error (_(incr_error));
5287ad62
JB
1919 return FAIL;
1920 }
1921 }
1922 else if (getreg != base_reg + reg_incr * count)
1923 {
dcbf9037
JB
1924 first_error (_(incr_error));
1925 return FAIL;
1926 }
1927
c921be7d 1928 if (! neon_alias_types_same (&atype, &firsttype))
dcbf9037
JB
1929 {
1930 first_error (_(type_error));
5287ad62
JB
1931 return FAIL;
1932 }
5f4273c7 1933
5287ad62
JB
1934 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1935 modes. */
1936 if (ptr[0] == '-')
1937 {
dcbf9037 1938 struct neon_typed_alias htype;
5287ad62
JB
1939 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1940 if (lane == -1)
1941 lane = NEON_INTERLEAVE_LANES;
1942 else if (lane != NEON_INTERLEAVE_LANES)
1943 {
dcbf9037 1944 first_error (_(type_error));
5287ad62
JB
1945 return FAIL;
1946 }
1947 if (reg_incr == -1)
1948 reg_incr = 1;
1949 else if (reg_incr != 1)
1950 {
dcbf9037 1951 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1952 return FAIL;
1953 }
1954 ptr++;
dcbf9037 1955 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1956 if (hireg == FAIL)
1957 {
dcbf9037
JB
1958 first_error (_(reg_expected_msgs[rtype]));
1959 return FAIL;
1960 }
c921be7d 1961 if (! neon_alias_types_same (&htype, &firsttype))
dcbf9037
JB
1962 {
1963 first_error (_(type_error));
5287ad62
JB
1964 return FAIL;
1965 }
1966 count += hireg + dregs - getreg;
1967 continue;
1968 }
5f4273c7 1969
5287ad62
JB
1970 /* If we're using Q registers, we can't use [] or [n] syntax. */
1971 if (rtype == REG_TYPE_NQ)
1972 {
1973 count += 2;
1974 continue;
1975 }
5f4273c7 1976
dcbf9037 1977 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1978 {
dcbf9037
JB
1979 if (lane == -1)
1980 lane = atype.index;
1981 else if (lane != atype.index)
5287ad62 1982 {
dcbf9037
JB
1983 first_error (_(type_error));
1984 return FAIL;
5287ad62
JB
1985 }
1986 }
1987 else if (lane == -1)
1988 lane = NEON_INTERLEAVE_LANES;
1989 else if (lane != NEON_INTERLEAVE_LANES)
1990 {
dcbf9037 1991 first_error (_(type_error));
5287ad62
JB
1992 return FAIL;
1993 }
1994 count++;
1995 }
1996 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 1997
5287ad62
JB
1998 /* No lane set by [x]. We must be interleaving structures. */
1999 if (lane == -1)
2000 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2001
5287ad62
JB
2002 /* Sanity check. */
2003 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2004 || (count > 1 && reg_incr == -1))
2005 {
dcbf9037 2006 first_error (_("error parsing element/structure list"));
5287ad62
JB
2007 return FAIL;
2008 }
2009
2010 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2011 {
dcbf9037 2012 first_error (_("expected }"));
5287ad62
JB
2013 return FAIL;
2014 }
5f4273c7 2015
5287ad62
JB
2016 if (reg_incr == -1)
2017 reg_incr = 1;
2018
dcbf9037
JB
2019 if (eltype)
2020 *eltype = firsttype.eltype;
2021
5287ad62
JB
2022 *pbase = base_reg;
2023 *str = ptr;
5f4273c7 2024
5287ad62
JB
2025 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2026}
2027
c19d1205
ZW
2028/* Parse an explicit relocation suffix on an expression. This is
2029 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2030 arm_reloc_hsh contains no entries, so this function can only
2031 succeed if there is no () after the word. Returns -1 on error,
2032 BFD_RELOC_UNUSED if there wasn't any suffix. */
2033static int
2034parse_reloc (char **str)
b99bd4ef 2035{
c19d1205
ZW
2036 struct reloc_entry *r;
2037 char *p, *q;
b99bd4ef 2038
c19d1205
ZW
2039 if (**str != '(')
2040 return BFD_RELOC_UNUSED;
b99bd4ef 2041
c19d1205
ZW
2042 p = *str + 1;
2043 q = p;
2044
2045 while (*q && *q != ')' && *q != ',')
2046 q++;
2047 if (*q != ')')
2048 return -1;
2049
21d799b5
NC
2050 if ((r = (struct reloc_entry *)
2051 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2052 return -1;
2053
2054 *str = q + 1;
2055 return r->reloc;
b99bd4ef
NC
2056}
2057
c19d1205
ZW
2058/* Directives: register aliases. */
2059
dcbf9037 2060static struct reg_entry *
c19d1205 2061insert_reg_alias (char *str, int number, int type)
b99bd4ef 2062{
d3ce72d0 2063 struct reg_entry *new_reg;
c19d1205 2064 const char *name;
b99bd4ef 2065
d3ce72d0 2066 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2067 {
d3ce72d0 2068 if (new_reg->builtin)
c19d1205 2069 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2070
c19d1205
ZW
2071 /* Only warn about a redefinition if it's not defined as the
2072 same register. */
d3ce72d0 2073 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2074 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2075
d929913e 2076 return NULL;
c19d1205 2077 }
b99bd4ef 2078
c19d1205 2079 name = xstrdup (str);
d3ce72d0 2080 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2081
d3ce72d0
NC
2082 new_reg->name = name;
2083 new_reg->number = number;
2084 new_reg->type = type;
2085 new_reg->builtin = FALSE;
2086 new_reg->neon = NULL;
b99bd4ef 2087
d3ce72d0 2088 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2089 abort ();
5f4273c7 2090
d3ce72d0 2091 return new_reg;
dcbf9037
JB
2092}
2093
2094static void
2095insert_neon_reg_alias (char *str, int number, int type,
2096 struct neon_typed_alias *atype)
2097{
2098 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2099
dcbf9037
JB
2100 if (!reg)
2101 {
2102 first_error (_("attempt to redefine typed alias"));
2103 return;
2104 }
5f4273c7 2105
dcbf9037
JB
2106 if (atype)
2107 {
21d799b5
NC
2108 reg->neon = (struct neon_typed_alias *)
2109 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2110 *reg->neon = *atype;
2111 }
c19d1205 2112}
b99bd4ef 2113
c19d1205 2114/* Look for the .req directive. This is of the form:
b99bd4ef 2115
c19d1205 2116 new_register_name .req existing_register_name
b99bd4ef 2117
c19d1205 2118 If we find one, or if it looks sufficiently like one that we want to
d929913e 2119 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2120
d929913e 2121static bfd_boolean
c19d1205
ZW
2122create_register_alias (char * newname, char *p)
2123{
2124 struct reg_entry *old;
2125 char *oldname, *nbuf;
2126 size_t nlen;
b99bd4ef 2127
c19d1205
ZW
2128 /* The input scrubber ensures that whitespace after the mnemonic is
2129 collapsed to single spaces. */
2130 oldname = p;
2131 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2132 return FALSE;
b99bd4ef 2133
c19d1205
ZW
2134 oldname += 6;
2135 if (*oldname == '\0')
d929913e 2136 return FALSE;
b99bd4ef 2137
21d799b5 2138 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2139 if (!old)
b99bd4ef 2140 {
c19d1205 2141 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2142 return TRUE;
b99bd4ef
NC
2143 }
2144
c19d1205
ZW
2145 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2146 the desired alias name, and p points to its end. If not, then
2147 the desired alias name is in the global original_case_string. */
2148#ifdef TC_CASE_SENSITIVE
2149 nlen = p - newname;
2150#else
2151 newname = original_case_string;
2152 nlen = strlen (newname);
2153#endif
b99bd4ef 2154
21d799b5 2155 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2156 memcpy (nbuf, newname, nlen);
2157 nbuf[nlen] = '\0';
b99bd4ef 2158
c19d1205
ZW
2159 /* Create aliases under the new name as stated; an all-lowercase
2160 version of the new name; and an all-uppercase version of the new
2161 name. */
d929913e
NC
2162 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2163 {
2164 for (p = nbuf; *p; p++)
2165 *p = TOUPPER (*p);
c19d1205 2166
d929913e
NC
2167 if (strncmp (nbuf, newname, nlen))
2168 {
2169 /* If this attempt to create an additional alias fails, do not bother
2170 trying to create the all-lower case alias. We will fail and issue
2171 a second, duplicate error message. This situation arises when the
2172 programmer does something like:
2173 foo .req r0
2174 Foo .req r1
2175 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2176 the artificial FOO alias because it has already been created by the
d929913e
NC
2177 first .req. */
2178 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2179 return TRUE;
2180 }
c19d1205 2181
d929913e
NC
2182 for (p = nbuf; *p; p++)
2183 *p = TOLOWER (*p);
c19d1205 2184
d929913e
NC
2185 if (strncmp (nbuf, newname, nlen))
2186 insert_reg_alias (nbuf, old->number, old->type);
2187 }
c19d1205 2188
d929913e 2189 return TRUE;
b99bd4ef
NC
2190}
2191
dcbf9037
JB
2192/* Create a Neon typed/indexed register alias using directives, e.g.:
2193 X .dn d5.s32[1]
2194 Y .qn 6.s16
2195 Z .dn d7
2196 T .dn Z[0]
2197 These typed registers can be used instead of the types specified after the
2198 Neon mnemonic, so long as all operands given have types. Types can also be
2199 specified directly, e.g.:
5f4273c7 2200 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2201
c921be7d 2202static bfd_boolean
dcbf9037
JB
2203create_neon_reg_alias (char *newname, char *p)
2204{
2205 enum arm_reg_type basetype;
2206 struct reg_entry *basereg;
2207 struct reg_entry mybasereg;
2208 struct neon_type ntype;
2209 struct neon_typed_alias typeinfo;
2210 char *namebuf, *nameend;
2211 int namelen;
5f4273c7 2212
dcbf9037
JB
2213 typeinfo.defined = 0;
2214 typeinfo.eltype.type = NT_invtype;
2215 typeinfo.eltype.size = -1;
2216 typeinfo.index = -1;
5f4273c7 2217
dcbf9037 2218 nameend = p;
5f4273c7 2219
dcbf9037
JB
2220 if (strncmp (p, " .dn ", 5) == 0)
2221 basetype = REG_TYPE_VFD;
2222 else if (strncmp (p, " .qn ", 5) == 0)
2223 basetype = REG_TYPE_NQ;
2224 else
c921be7d 2225 return FALSE;
5f4273c7 2226
dcbf9037 2227 p += 5;
5f4273c7 2228
dcbf9037 2229 if (*p == '\0')
c921be7d 2230 return FALSE;
5f4273c7 2231
dcbf9037
JB
2232 basereg = arm_reg_parse_multi (&p);
2233
2234 if (basereg && basereg->type != basetype)
2235 {
2236 as_bad (_("bad type for register"));
c921be7d 2237 return FALSE;
dcbf9037
JB
2238 }
2239
2240 if (basereg == NULL)
2241 {
2242 expressionS exp;
2243 /* Try parsing as an integer. */
2244 my_get_expression (&exp, &p, GE_NO_PREFIX);
2245 if (exp.X_op != O_constant)
2246 {
2247 as_bad (_("expression must be constant"));
c921be7d 2248 return FALSE;
dcbf9037
JB
2249 }
2250 basereg = &mybasereg;
2251 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2252 : exp.X_add_number;
2253 basereg->neon = 0;
2254 }
2255
2256 if (basereg->neon)
2257 typeinfo = *basereg->neon;
2258
2259 if (parse_neon_type (&ntype, &p) == SUCCESS)
2260 {
2261 /* We got a type. */
2262 if (typeinfo.defined & NTA_HASTYPE)
2263 {
2264 as_bad (_("can't redefine the type of a register alias"));
c921be7d 2265 return FALSE;
dcbf9037 2266 }
5f4273c7 2267
dcbf9037
JB
2268 typeinfo.defined |= NTA_HASTYPE;
2269 if (ntype.elems != 1)
2270 {
2271 as_bad (_("you must specify a single type only"));
c921be7d 2272 return FALSE;
dcbf9037
JB
2273 }
2274 typeinfo.eltype = ntype.el[0];
2275 }
5f4273c7 2276
dcbf9037
JB
2277 if (skip_past_char (&p, '[') == SUCCESS)
2278 {
2279 expressionS exp;
2280 /* We got a scalar index. */
5f4273c7 2281
dcbf9037
JB
2282 if (typeinfo.defined & NTA_HASINDEX)
2283 {
2284 as_bad (_("can't redefine the index of a scalar alias"));
c921be7d 2285 return FALSE;
dcbf9037 2286 }
5f4273c7 2287
dcbf9037 2288 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2289
dcbf9037
JB
2290 if (exp.X_op != O_constant)
2291 {
2292 as_bad (_("scalar index must be constant"));
c921be7d 2293 return FALSE;
dcbf9037 2294 }
5f4273c7 2295
dcbf9037
JB
2296 typeinfo.defined |= NTA_HASINDEX;
2297 typeinfo.index = exp.X_add_number;
5f4273c7 2298
dcbf9037
JB
2299 if (skip_past_char (&p, ']') == FAIL)
2300 {
2301 as_bad (_("expecting ]"));
c921be7d 2302 return FALSE;
dcbf9037
JB
2303 }
2304 }
2305
15735687
NS
2306 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2307 the desired alias name, and p points to its end. If not, then
2308 the desired alias name is in the global original_case_string. */
2309#ifdef TC_CASE_SENSITIVE
dcbf9037 2310 namelen = nameend - newname;
15735687
NS
2311#else
2312 newname = original_case_string;
2313 namelen = strlen (newname);
2314#endif
2315
21d799b5 2316 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2317 strncpy (namebuf, newname, namelen);
2318 namebuf[namelen] = '\0';
5f4273c7 2319
dcbf9037
JB
2320 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2321 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2322
dcbf9037
JB
2323 /* Insert name in all uppercase. */
2324 for (p = namebuf; *p; p++)
2325 *p = TOUPPER (*p);
5f4273c7 2326
dcbf9037
JB
2327 if (strncmp (namebuf, newname, namelen))
2328 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2329 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2330
dcbf9037
JB
2331 /* Insert name in all lowercase. */
2332 for (p = namebuf; *p; p++)
2333 *p = TOLOWER (*p);
5f4273c7 2334
dcbf9037
JB
2335 if (strncmp (namebuf, newname, namelen))
2336 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2337 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2338
c921be7d 2339 return TRUE;
dcbf9037
JB
2340}
2341
c19d1205
ZW
2342/* Should never be called, as .req goes between the alias and the
2343 register name, not at the beginning of the line. */
c921be7d 2344
b99bd4ef 2345static void
c19d1205 2346s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2347{
c19d1205
ZW
2348 as_bad (_("invalid syntax for .req directive"));
2349}
b99bd4ef 2350
dcbf9037
JB
2351static void
2352s_dn (int a ATTRIBUTE_UNUSED)
2353{
2354 as_bad (_("invalid syntax for .dn directive"));
2355}
2356
2357static void
2358s_qn (int a ATTRIBUTE_UNUSED)
2359{
2360 as_bad (_("invalid syntax for .qn directive"));
2361}
2362
c19d1205
ZW
2363/* The .unreq directive deletes an alias which was previously defined
2364 by .req. For example:
b99bd4ef 2365
c19d1205
ZW
2366 my_alias .req r11
2367 .unreq my_alias */
b99bd4ef
NC
2368
2369static void
c19d1205 2370s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2371{
c19d1205
ZW
2372 char * name;
2373 char saved_char;
b99bd4ef 2374
c19d1205
ZW
2375 name = input_line_pointer;
2376
2377 while (*input_line_pointer != 0
2378 && *input_line_pointer != ' '
2379 && *input_line_pointer != '\n')
2380 ++input_line_pointer;
2381
2382 saved_char = *input_line_pointer;
2383 *input_line_pointer = 0;
2384
2385 if (!*name)
2386 as_bad (_("invalid syntax for .unreq directive"));
2387 else
2388 {
21d799b5
NC
2389 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2390 name);
c19d1205
ZW
2391
2392 if (!reg)
2393 as_bad (_("unknown register alias '%s'"), name);
2394 else if (reg->builtin)
2395 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2396 name);
2397 else
2398 {
d929913e
NC
2399 char * p;
2400 char * nbuf;
2401
db0bc284 2402 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2403 free ((char *) reg->name);
dcbf9037
JB
2404 if (reg->neon)
2405 free (reg->neon);
c19d1205 2406 free (reg);
d929913e
NC
2407
2408 /* Also locate the all upper case and all lower case versions.
2409 Do not complain if we cannot find one or the other as it
2410 was probably deleted above. */
5f4273c7 2411
d929913e
NC
2412 nbuf = strdup (name);
2413 for (p = nbuf; *p; p++)
2414 *p = TOUPPER (*p);
21d799b5 2415 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2416 if (reg)
2417 {
db0bc284 2418 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2419 free ((char *) reg->name);
2420 if (reg->neon)
2421 free (reg->neon);
2422 free (reg);
2423 }
2424
2425 for (p = nbuf; *p; p++)
2426 *p = TOLOWER (*p);
21d799b5 2427 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2428 if (reg)
2429 {
db0bc284 2430 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2431 free ((char *) reg->name);
2432 if (reg->neon)
2433 free (reg->neon);
2434 free (reg);
2435 }
2436
2437 free (nbuf);
c19d1205
ZW
2438 }
2439 }
b99bd4ef 2440
c19d1205 2441 *input_line_pointer = saved_char;
b99bd4ef
NC
2442 demand_empty_rest_of_line ();
2443}
2444
c19d1205
ZW
2445/* Directives: Instruction set selection. */
2446
2447#ifdef OBJ_ELF
2448/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2449 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2450 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2451 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2452
cd000bff
DJ
2453/* Create a new mapping symbol for the transition to STATE. */
2454
2455static void
2456make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2457{
a737bd4d 2458 symbolS * symbolP;
c19d1205
ZW
2459 const char * symname;
2460 int type;
b99bd4ef 2461
c19d1205 2462 switch (state)
b99bd4ef 2463 {
c19d1205
ZW
2464 case MAP_DATA:
2465 symname = "$d";
2466 type = BSF_NO_FLAGS;
2467 break;
2468 case MAP_ARM:
2469 symname = "$a";
2470 type = BSF_NO_FLAGS;
2471 break;
2472 case MAP_THUMB:
2473 symname = "$t";
2474 type = BSF_NO_FLAGS;
2475 break;
c19d1205
ZW
2476 default:
2477 abort ();
2478 }
2479
cd000bff 2480 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2481 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2482
2483 switch (state)
2484 {
2485 case MAP_ARM:
2486 THUMB_SET_FUNC (symbolP, 0);
2487 ARM_SET_THUMB (symbolP, 0);
2488 ARM_SET_INTERWORK (symbolP, support_interwork);
2489 break;
2490
2491 case MAP_THUMB:
2492 THUMB_SET_FUNC (symbolP, 1);
2493 ARM_SET_THUMB (symbolP, 1);
2494 ARM_SET_INTERWORK (symbolP, support_interwork);
2495 break;
2496
2497 case MAP_DATA:
2498 default:
cd000bff
DJ
2499 break;
2500 }
2501
2502 /* Save the mapping symbols for future reference. Also check that
2503 we do not place two mapping symbols at the same offset within a
2504 frag. We'll handle overlap between frags in
2de7820f
JZ
2505 check_mapping_symbols.
2506
2507 If .fill or other data filling directive generates zero sized data,
2508 the mapping symbol for the following code will have the same value
2509 as the one generated for the data filling directive. In this case,
2510 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2511 if (value == 0)
2512 {
2de7820f
JZ
2513 if (frag->tc_frag_data.first_map != NULL)
2514 {
2515 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2516 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2517 }
cd000bff
DJ
2518 frag->tc_frag_data.first_map = symbolP;
2519 }
2520 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2521 {
2522 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2523 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2524 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2525 }
cd000bff
DJ
2526 frag->tc_frag_data.last_map = symbolP;
2527}
2528
2529/* We must sometimes convert a region marked as code to data during
2530 code alignment, if an odd number of bytes have to be padded. The
2531 code mapping symbol is pushed to an aligned address. */
2532
2533static void
2534insert_data_mapping_symbol (enum mstate state,
2535 valueT value, fragS *frag, offsetT bytes)
2536{
2537 /* If there was already a mapping symbol, remove it. */
2538 if (frag->tc_frag_data.last_map != NULL
2539 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2540 {
2541 symbolS *symp = frag->tc_frag_data.last_map;
2542
2543 if (value == 0)
2544 {
2545 know (frag->tc_frag_data.first_map == symp);
2546 frag->tc_frag_data.first_map = NULL;
2547 }
2548 frag->tc_frag_data.last_map = NULL;
2549 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2550 }
cd000bff
DJ
2551
2552 make_mapping_symbol (MAP_DATA, value, frag);
2553 make_mapping_symbol (state, value + bytes, frag);
2554}
2555
2556static void mapping_state_2 (enum mstate state, int max_chars);
2557
2558/* Set the mapping state to STATE. Only call this when about to
2559 emit some STATE bytes to the file. */
2560
2561void
2562mapping_state (enum mstate state)
2563{
940b5ce0
DJ
2564 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2565
cd000bff
DJ
2566#define TRANSITION(from, to) (mapstate == (from) && state == (to))
2567
2568 if (mapstate == state)
2569 /* The mapping symbol has already been emitted.
2570 There is nothing else to do. */
2571 return;
2572 else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2573 /* This case will be evaluated later in the next else. */
2574 return;
2575 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2576 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2577 {
2578 /* Only add the symbol if the offset is > 0:
2579 if we're at the first frag, check it's size > 0;
2580 if we're not at the first frag, then for sure
2581 the offset is > 0. */
2582 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2583 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2584
2585 if (add_symbol)
2586 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2587 }
2588
2589 mapping_state_2 (state, 0);
2590#undef TRANSITION
2591}
2592
2593/* Same as mapping_state, but MAX_CHARS bytes have already been
2594 allocated. Put the mapping symbol that far back. */
2595
2596static void
2597mapping_state_2 (enum mstate state, int max_chars)
2598{
940b5ce0
DJ
2599 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2600
2601 if (!SEG_NORMAL (now_seg))
2602 return;
2603
cd000bff
DJ
2604 if (mapstate == state)
2605 /* The mapping symbol has already been emitted.
2606 There is nothing else to do. */
2607 return;
2608
cd000bff
DJ
2609 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2610 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205
ZW
2611}
2612#else
d3106081
NS
2613#define mapping_state(x) ((void)0)
2614#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2615#endif
2616
2617/* Find the real, Thumb encoded start of a Thumb function. */
2618
4343666d 2619#ifdef OBJ_COFF
c19d1205
ZW
2620static symbolS *
2621find_real_start (symbolS * symbolP)
2622{
2623 char * real_start;
2624 const char * name = S_GET_NAME (symbolP);
2625 symbolS * new_target;
2626
2627 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2628#define STUB_NAME ".real_start_of"
2629
2630 if (name == NULL)
2631 abort ();
2632
37f6032b
ZW
2633 /* The compiler may generate BL instructions to local labels because
2634 it needs to perform a branch to a far away location. These labels
2635 do not have a corresponding ".real_start_of" label. We check
2636 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2637 the ".real_start_of" convention for nonlocal branches. */
2638 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2639 return symbolP;
2640
37f6032b 2641 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2642 new_target = symbol_find (real_start);
2643
2644 if (new_target == NULL)
2645 {
bd3ba5d1 2646 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2647 new_target = symbolP;
2648 }
2649
c19d1205
ZW
2650 return new_target;
2651}
4343666d 2652#endif
c19d1205
ZW
2653
2654static void
2655opcode_select (int width)
2656{
2657 switch (width)
2658 {
2659 case 16:
2660 if (! thumb_mode)
2661 {
e74cfd16 2662 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2663 as_bad (_("selected processor does not support THUMB opcodes"));
2664
2665 thumb_mode = 1;
2666 /* No need to force the alignment, since we will have been
2667 coming from ARM mode, which is word-aligned. */
2668 record_alignment (now_seg, 1);
2669 }
c19d1205
ZW
2670 break;
2671
2672 case 32:
2673 if (thumb_mode)
2674 {
e74cfd16 2675 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2676 as_bad (_("selected processor does not support ARM opcodes"));
2677
2678 thumb_mode = 0;
2679
2680 if (!need_pass_2)
2681 frag_align (2, 0, 0);
2682
2683 record_alignment (now_seg, 1);
2684 }
c19d1205
ZW
2685 break;
2686
2687 default:
2688 as_bad (_("invalid instruction size selected (%d)"), width);
2689 }
2690}
2691
2692static void
2693s_arm (int ignore ATTRIBUTE_UNUSED)
2694{
2695 opcode_select (32);
2696 demand_empty_rest_of_line ();
2697}
2698
2699static void
2700s_thumb (int ignore ATTRIBUTE_UNUSED)
2701{
2702 opcode_select (16);
2703 demand_empty_rest_of_line ();
2704}
2705
2706static void
2707s_code (int unused ATTRIBUTE_UNUSED)
2708{
2709 int temp;
2710
2711 temp = get_absolute_expression ();
2712 switch (temp)
2713 {
2714 case 16:
2715 case 32:
2716 opcode_select (temp);
2717 break;
2718
2719 default:
2720 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2721 }
2722}
2723
2724static void
2725s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2726{
2727 /* If we are not already in thumb mode go into it, EVEN if
2728 the target processor does not support thumb instructions.
2729 This is used by gcc/config/arm/lib1funcs.asm for example
2730 to compile interworking support functions even if the
2731 target processor should not support interworking. */
2732 if (! thumb_mode)
2733 {
2734 thumb_mode = 2;
2735 record_alignment (now_seg, 1);
2736 }
2737
2738 demand_empty_rest_of_line ();
2739}
2740
2741static void
2742s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2743{
2744 s_thumb (0);
2745
2746 /* The following label is the name/address of the start of a Thumb function.
2747 We need to know this for the interworking support. */
2748 label_is_thumb_function_name = TRUE;
2749}
2750
2751/* Perform a .set directive, but also mark the alias as
2752 being a thumb function. */
2753
2754static void
2755s_thumb_set (int equiv)
2756{
2757 /* XXX the following is a duplicate of the code for s_set() in read.c
2758 We cannot just call that code as we need to get at the symbol that
2759 is created. */
2760 char * name;
2761 char delim;
2762 char * end_name;
2763 symbolS * symbolP;
2764
2765 /* Especial apologies for the random logic:
2766 This just grew, and could be parsed much more simply!
2767 Dean - in haste. */
2768 name = input_line_pointer;
2769 delim = get_symbol_end ();
2770 end_name = input_line_pointer;
2771 *end_name = delim;
2772
2773 if (*input_line_pointer != ',')
2774 {
2775 *end_name = 0;
2776 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2777 *end_name = delim;
2778 ignore_rest_of_line ();
2779 return;
2780 }
2781
2782 input_line_pointer++;
2783 *end_name = 0;
2784
2785 if (name[0] == '.' && name[1] == '\0')
2786 {
2787 /* XXX - this should not happen to .thumb_set. */
2788 abort ();
2789 }
2790
2791 if ((symbolP = symbol_find (name)) == NULL
2792 && (symbolP = md_undefined_symbol (name)) == NULL)
2793 {
2794#ifndef NO_LISTING
2795 /* When doing symbol listings, play games with dummy fragments living
2796 outside the normal fragment chain to record the file and line info
c19d1205 2797 for this symbol. */
b99bd4ef
NC
2798 if (listing & LISTING_SYMBOLS)
2799 {
2800 extern struct list_info_struct * listing_tail;
21d799b5 2801 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2802
2803 memset (dummy_frag, 0, sizeof (fragS));
2804 dummy_frag->fr_type = rs_fill;
2805 dummy_frag->line = listing_tail;
2806 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2807 dummy_frag->fr_symbol = symbolP;
2808 }
2809 else
2810#endif
2811 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2812
2813#ifdef OBJ_COFF
2814 /* "set" symbols are local unless otherwise specified. */
2815 SF_SET_LOCAL (symbolP);
2816#endif /* OBJ_COFF */
2817 } /* Make a new symbol. */
2818
2819 symbol_table_insert (symbolP);
2820
2821 * end_name = delim;
2822
2823 if (equiv
2824 && S_IS_DEFINED (symbolP)
2825 && S_GET_SEGMENT (symbolP) != reg_section)
2826 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2827
2828 pseudo_set (symbolP);
2829
2830 demand_empty_rest_of_line ();
2831
c19d1205 2832 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2833
2834 THUMB_SET_FUNC (symbolP, 1);
2835 ARM_SET_THUMB (symbolP, 1);
2836#if defined OBJ_ELF || defined OBJ_COFF
2837 ARM_SET_INTERWORK (symbolP, support_interwork);
2838#endif
2839}
2840
c19d1205 2841/* Directives: Mode selection. */
b99bd4ef 2842
c19d1205
ZW
2843/* .syntax [unified|divided] - choose the new unified syntax
2844 (same for Arm and Thumb encoding, modulo slight differences in what
2845 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2846static void
c19d1205 2847s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2848{
c19d1205
ZW
2849 char *name, delim;
2850
2851 name = input_line_pointer;
2852 delim = get_symbol_end ();
2853
2854 if (!strcasecmp (name, "unified"))
2855 unified_syntax = TRUE;
2856 else if (!strcasecmp (name, "divided"))
2857 unified_syntax = FALSE;
2858 else
2859 {
2860 as_bad (_("unrecognized syntax mode \"%s\""), name);
2861 return;
2862 }
2863 *input_line_pointer = delim;
b99bd4ef
NC
2864 demand_empty_rest_of_line ();
2865}
2866
c19d1205
ZW
2867/* Directives: sectioning and alignment. */
2868
2869/* Same as s_align_ptwo but align 0 => align 2. */
2870
b99bd4ef 2871static void
c19d1205 2872s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2873{
a737bd4d 2874 int temp;
dce323d1 2875 bfd_boolean fill_p;
c19d1205
ZW
2876 long temp_fill;
2877 long max_alignment = 15;
b99bd4ef
NC
2878
2879 temp = get_absolute_expression ();
c19d1205
ZW
2880 if (temp > max_alignment)
2881 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2882 else if (temp < 0)
b99bd4ef 2883 {
c19d1205
ZW
2884 as_bad (_("alignment negative. 0 assumed."));
2885 temp = 0;
2886 }
b99bd4ef 2887
c19d1205
ZW
2888 if (*input_line_pointer == ',')
2889 {
2890 input_line_pointer++;
2891 temp_fill = get_absolute_expression ();
dce323d1 2892 fill_p = TRUE;
b99bd4ef 2893 }
c19d1205 2894 else
dce323d1
PB
2895 {
2896 fill_p = FALSE;
2897 temp_fill = 0;
2898 }
b99bd4ef 2899
c19d1205
ZW
2900 if (!temp)
2901 temp = 2;
b99bd4ef 2902
c19d1205
ZW
2903 /* Only make a frag if we HAVE to. */
2904 if (temp && !need_pass_2)
dce323d1
PB
2905 {
2906 if (!fill_p && subseg_text_p (now_seg))
2907 frag_align_code (temp, 0);
2908 else
2909 frag_align (temp, (int) temp_fill, 0);
2910 }
c19d1205
ZW
2911 demand_empty_rest_of_line ();
2912
2913 record_alignment (now_seg, temp);
b99bd4ef
NC
2914}
2915
c19d1205
ZW
2916static void
2917s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2918{
c19d1205
ZW
2919 /* We don't support putting frags in the BSS segment, we fake it by
2920 marking in_bss, then looking at s_skip for clues. */
2921 subseg_set (bss_section, 0);
2922 demand_empty_rest_of_line ();
cd000bff
DJ
2923
2924#ifdef md_elf_section_change_hook
2925 md_elf_section_change_hook ();
2926#endif
c19d1205 2927}
b99bd4ef 2928
c19d1205
ZW
2929static void
2930s_even (int ignore ATTRIBUTE_UNUSED)
2931{
2932 /* Never make frag if expect extra pass. */
2933 if (!need_pass_2)
2934 frag_align (1, 0, 0);
b99bd4ef 2935
c19d1205 2936 record_alignment (now_seg, 1);
b99bd4ef 2937
c19d1205 2938 demand_empty_rest_of_line ();
b99bd4ef
NC
2939}
2940
c19d1205 2941/* Directives: Literal pools. */
a737bd4d 2942
c19d1205
ZW
2943static literal_pool *
2944find_literal_pool (void)
a737bd4d 2945{
c19d1205 2946 literal_pool * pool;
a737bd4d 2947
c19d1205 2948 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2949 {
c19d1205
ZW
2950 if (pool->section == now_seg
2951 && pool->sub_section == now_subseg)
2952 break;
a737bd4d
NC
2953 }
2954
c19d1205 2955 return pool;
a737bd4d
NC
2956}
2957
c19d1205
ZW
2958static literal_pool *
2959find_or_make_literal_pool (void)
a737bd4d 2960{
c19d1205
ZW
2961 /* Next literal pool ID number. */
2962 static unsigned int latest_pool_num = 1;
2963 literal_pool * pool;
a737bd4d 2964
c19d1205 2965 pool = find_literal_pool ();
a737bd4d 2966
c19d1205 2967 if (pool == NULL)
a737bd4d 2968 {
c19d1205 2969 /* Create a new pool. */
21d799b5 2970 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
2971 if (! pool)
2972 return NULL;
a737bd4d 2973
c19d1205
ZW
2974 pool->next_free_entry = 0;
2975 pool->section = now_seg;
2976 pool->sub_section = now_subseg;
2977 pool->next = list_of_pools;
2978 pool->symbol = NULL;
2979
2980 /* Add it to the list. */
2981 list_of_pools = pool;
a737bd4d 2982 }
a737bd4d 2983
c19d1205
ZW
2984 /* New pools, and emptied pools, will have a NULL symbol. */
2985 if (pool->symbol == NULL)
a737bd4d 2986 {
c19d1205
ZW
2987 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2988 (valueT) 0, &zero_address_frag);
2989 pool->id = latest_pool_num ++;
a737bd4d
NC
2990 }
2991
c19d1205
ZW
2992 /* Done. */
2993 return pool;
a737bd4d
NC
2994}
2995
c19d1205 2996/* Add the literal in the global 'inst'
5f4273c7 2997 structure to the relevant literal pool. */
b99bd4ef
NC
2998
2999static int
c19d1205 3000add_to_lit_pool (void)
b99bd4ef 3001{
c19d1205
ZW
3002 literal_pool * pool;
3003 unsigned int entry;
b99bd4ef 3004
c19d1205
ZW
3005 pool = find_or_make_literal_pool ();
3006
3007 /* Check if this literal value is already in the pool. */
3008 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3009 {
c19d1205
ZW
3010 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3011 && (inst.reloc.exp.X_op == O_constant)
3012 && (pool->literals[entry].X_add_number
3013 == inst.reloc.exp.X_add_number)
3014 && (pool->literals[entry].X_unsigned
3015 == inst.reloc.exp.X_unsigned))
3016 break;
3017
3018 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3019 && (inst.reloc.exp.X_op == O_symbol)
3020 && (pool->literals[entry].X_add_number
3021 == inst.reloc.exp.X_add_number)
3022 && (pool->literals[entry].X_add_symbol
3023 == inst.reloc.exp.X_add_symbol)
3024 && (pool->literals[entry].X_op_symbol
3025 == inst.reloc.exp.X_op_symbol))
3026 break;
b99bd4ef
NC
3027 }
3028
c19d1205
ZW
3029 /* Do we need to create a new entry? */
3030 if (entry == pool->next_free_entry)
3031 {
3032 if (entry >= MAX_LITERAL_POOL_SIZE)
3033 {
3034 inst.error = _("literal pool overflow");
3035 return FAIL;
3036 }
3037
3038 pool->literals[entry] = inst.reloc.exp;
3039 pool->next_free_entry += 1;
3040 }
b99bd4ef 3041
c19d1205
ZW
3042 inst.reloc.exp.X_op = O_symbol;
3043 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3044 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3045
c19d1205 3046 return SUCCESS;
b99bd4ef
NC
3047}
3048
c19d1205
ZW
3049/* Can't use symbol_new here, so have to create a symbol and then at
3050 a later date assign it a value. Thats what these functions do. */
e16bb312 3051
c19d1205
ZW
3052static void
3053symbol_locate (symbolS * symbolP,
3054 const char * name, /* It is copied, the caller can modify. */
3055 segT segment, /* Segment identifier (SEG_<something>). */
3056 valueT valu, /* Symbol value. */
3057 fragS * frag) /* Associated fragment. */
3058{
3059 unsigned int name_length;
3060 char * preserved_copy_of_name;
e16bb312 3061
c19d1205
ZW
3062 name_length = strlen (name) + 1; /* +1 for \0. */
3063 obstack_grow (&notes, name, name_length);
21d799b5 3064 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3065
c19d1205
ZW
3066#ifdef tc_canonicalize_symbol_name
3067 preserved_copy_of_name =
3068 tc_canonicalize_symbol_name (preserved_copy_of_name);
3069#endif
b99bd4ef 3070
c19d1205 3071 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3072
c19d1205
ZW
3073 S_SET_SEGMENT (symbolP, segment);
3074 S_SET_VALUE (symbolP, valu);
3075 symbol_clear_list_pointers (symbolP);
b99bd4ef 3076
c19d1205 3077 symbol_set_frag (symbolP, frag);
b99bd4ef 3078
c19d1205
ZW
3079 /* Link to end of symbol chain. */
3080 {
3081 extern int symbol_table_frozen;
b99bd4ef 3082
c19d1205
ZW
3083 if (symbol_table_frozen)
3084 abort ();
3085 }
b99bd4ef 3086
c19d1205 3087 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3088
c19d1205 3089 obj_symbol_new_hook (symbolP);
b99bd4ef 3090
c19d1205
ZW
3091#ifdef tc_symbol_new_hook
3092 tc_symbol_new_hook (symbolP);
3093#endif
3094
3095#ifdef DEBUG_SYMS
3096 verify_symbol_chain (symbol_rootP, symbol_lastP);
3097#endif /* DEBUG_SYMS */
b99bd4ef
NC
3098}
3099
b99bd4ef 3100
c19d1205
ZW
3101static void
3102s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3103{
c19d1205
ZW
3104 unsigned int entry;
3105 literal_pool * pool;
3106 char sym_name[20];
b99bd4ef 3107
c19d1205
ZW
3108 pool = find_literal_pool ();
3109 if (pool == NULL
3110 || pool->symbol == NULL
3111 || pool->next_free_entry == 0)
3112 return;
b99bd4ef 3113
c19d1205 3114 mapping_state (MAP_DATA);
b99bd4ef 3115
c19d1205
ZW
3116 /* Align pool as you have word accesses.
3117 Only make a frag if we have to. */
3118 if (!need_pass_2)
3119 frag_align (2, 0, 0);
b99bd4ef 3120
c19d1205 3121 record_alignment (now_seg, 2);
b99bd4ef 3122
c19d1205 3123 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3124
c19d1205
ZW
3125 symbol_locate (pool->symbol, sym_name, now_seg,
3126 (valueT) frag_now_fix (), frag_now);
3127 symbol_table_insert (pool->symbol);
b99bd4ef 3128
c19d1205 3129 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3130
c19d1205
ZW
3131#if defined OBJ_COFF || defined OBJ_ELF
3132 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3133#endif
6c43fab6 3134
c19d1205
ZW
3135 for (entry = 0; entry < pool->next_free_entry; entry ++)
3136 /* First output the expression in the instruction to the pool. */
3137 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 3138
c19d1205
ZW
3139 /* Mark the pool as empty. */
3140 pool->next_free_entry = 0;
3141 pool->symbol = NULL;
b99bd4ef
NC
3142}
3143
c19d1205
ZW
3144#ifdef OBJ_ELF
3145/* Forward declarations for functions below, in the MD interface
3146 section. */
3147static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3148static valueT create_unwind_entry (int);
3149static void start_unwind_section (const segT, int);
3150static void add_unwind_opcode (valueT, int);
3151static void flush_pending_unwind (void);
b99bd4ef 3152
c19d1205 3153/* Directives: Data. */
b99bd4ef 3154
c19d1205
ZW
3155static void
3156s_arm_elf_cons (int nbytes)
3157{
3158 expressionS exp;
b99bd4ef 3159
c19d1205
ZW
3160#ifdef md_flush_pending_output
3161 md_flush_pending_output ();
3162#endif
b99bd4ef 3163
c19d1205 3164 if (is_it_end_of_statement ())
b99bd4ef 3165 {
c19d1205
ZW
3166 demand_empty_rest_of_line ();
3167 return;
b99bd4ef
NC
3168 }
3169
c19d1205
ZW
3170#ifdef md_cons_align
3171 md_cons_align (nbytes);
3172#endif
b99bd4ef 3173
c19d1205
ZW
3174 mapping_state (MAP_DATA);
3175 do
b99bd4ef 3176 {
c19d1205
ZW
3177 int reloc;
3178 char *base = input_line_pointer;
b99bd4ef 3179
c19d1205 3180 expression (& exp);
b99bd4ef 3181
c19d1205
ZW
3182 if (exp.X_op != O_symbol)
3183 emit_expr (&exp, (unsigned int) nbytes);
3184 else
3185 {
3186 char *before_reloc = input_line_pointer;
3187 reloc = parse_reloc (&input_line_pointer);
3188 if (reloc == -1)
3189 {
3190 as_bad (_("unrecognized relocation suffix"));
3191 ignore_rest_of_line ();
3192 return;
3193 }
3194 else if (reloc == BFD_RELOC_UNUSED)
3195 emit_expr (&exp, (unsigned int) nbytes);
3196 else
3197 {
21d799b5
NC
3198 reloc_howto_type *howto = (reloc_howto_type *)
3199 bfd_reloc_type_lookup (stdoutput,
3200 (bfd_reloc_code_real_type) reloc);
c19d1205 3201 int size = bfd_get_reloc_size (howto);
b99bd4ef 3202
2fc8bdac
ZW
3203 if (reloc == BFD_RELOC_ARM_PLT32)
3204 {
3205 as_bad (_("(plt) is only valid on branch targets"));
3206 reloc = BFD_RELOC_UNUSED;
3207 size = 0;
3208 }
3209
c19d1205 3210 if (size > nbytes)
2fc8bdac 3211 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3212 howto->name, nbytes);
3213 else
3214 {
3215 /* We've parsed an expression stopping at O_symbol.
3216 But there may be more expression left now that we
3217 have parsed the relocation marker. Parse it again.
3218 XXX Surely there is a cleaner way to do this. */
3219 char *p = input_line_pointer;
3220 int offset;
21d799b5 3221 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3222 memcpy (save_buf, base, input_line_pointer - base);
3223 memmove (base + (input_line_pointer - before_reloc),
3224 base, before_reloc - base);
3225
3226 input_line_pointer = base + (input_line_pointer-before_reloc);
3227 expression (&exp);
3228 memcpy (base, save_buf, p - base);
3229
3230 offset = nbytes - size;
3231 p = frag_more ((int) nbytes);
3232 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3233 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3234 }
3235 }
3236 }
b99bd4ef 3237 }
c19d1205 3238 while (*input_line_pointer++ == ',');
b99bd4ef 3239
c19d1205
ZW
3240 /* Put terminator back into stream. */
3241 input_line_pointer --;
3242 demand_empty_rest_of_line ();
b99bd4ef
NC
3243}
3244
c921be7d
NC
3245/* Emit an expression containing a 32-bit thumb instruction.
3246 Implementation based on put_thumb32_insn. */
3247
3248static void
3249emit_thumb32_expr (expressionS * exp)
3250{
3251 expressionS exp_high = *exp;
3252
3253 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3254 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3255 exp->X_add_number &= 0xffff;
3256 emit_expr (exp, (unsigned int) THUMB_SIZE);
3257}
3258
3259/* Guess the instruction size based on the opcode. */
3260
3261static int
3262thumb_insn_size (int opcode)
3263{
3264 if ((unsigned int) opcode < 0xe800u)
3265 return 2;
3266 else if ((unsigned int) opcode >= 0xe8000000u)
3267 return 4;
3268 else
3269 return 0;
3270}
3271
3272static bfd_boolean
3273emit_insn (expressionS *exp, int nbytes)
3274{
3275 int size = 0;
3276
3277 if (exp->X_op == O_constant)
3278 {
3279 size = nbytes;
3280
3281 if (size == 0)
3282 size = thumb_insn_size (exp->X_add_number);
3283
3284 if (size != 0)
3285 {
3286 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3287 {
3288 as_bad (_(".inst.n operand too big. "\
3289 "Use .inst.w instead"));
3290 size = 0;
3291 }
3292 else
3293 {
3294 if (now_it.state == AUTOMATIC_IT_BLOCK)
3295 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3296 else
3297 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3298
3299 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3300 emit_thumb32_expr (exp);
3301 else
3302 emit_expr (exp, (unsigned int) size);
3303
3304 it_fsm_post_encode ();
3305 }
3306 }
3307 else
3308 as_bad (_("cannot determine Thumb instruction size. " \
3309 "Use .inst.n/.inst.w instead"));
3310 }
3311 else
3312 as_bad (_("constant expression required"));
3313
3314 return (size != 0);
3315}
3316
3317/* Like s_arm_elf_cons but do not use md_cons_align and
3318 set the mapping state to MAP_ARM/MAP_THUMB. */
3319
3320static void
3321s_arm_elf_inst (int nbytes)
3322{
3323 if (is_it_end_of_statement ())
3324 {
3325 demand_empty_rest_of_line ();
3326 return;
3327 }
3328
3329 /* Calling mapping_state () here will not change ARM/THUMB,
3330 but will ensure not to be in DATA state. */
3331
3332 if (thumb_mode)
3333 mapping_state (MAP_THUMB);
3334 else
3335 {
3336 if (nbytes != 0)
3337 {
3338 as_bad (_("width suffixes are invalid in ARM mode"));
3339 ignore_rest_of_line ();
3340 return;
3341 }
3342
3343 nbytes = 4;
3344
3345 mapping_state (MAP_ARM);
3346 }
3347
3348 do
3349 {
3350 expressionS exp;
3351
3352 expression (& exp);
3353
3354 if (! emit_insn (& exp, nbytes))
3355 {
3356 ignore_rest_of_line ();
3357 return;
3358 }
3359 }
3360 while (*input_line_pointer++ == ',');
3361
3362 /* Put terminator back into stream. */
3363 input_line_pointer --;
3364 demand_empty_rest_of_line ();
3365}
b99bd4ef 3366
c19d1205 3367/* Parse a .rel31 directive. */
b99bd4ef 3368
c19d1205
ZW
3369static void
3370s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3371{
3372 expressionS exp;
3373 char *p;
3374 valueT highbit;
b99bd4ef 3375
c19d1205
ZW
3376 highbit = 0;
3377 if (*input_line_pointer == '1')
3378 highbit = 0x80000000;
3379 else if (*input_line_pointer != '0')
3380 as_bad (_("expected 0 or 1"));
b99bd4ef 3381
c19d1205
ZW
3382 input_line_pointer++;
3383 if (*input_line_pointer != ',')
3384 as_bad (_("missing comma"));
3385 input_line_pointer++;
b99bd4ef 3386
c19d1205
ZW
3387#ifdef md_flush_pending_output
3388 md_flush_pending_output ();
3389#endif
b99bd4ef 3390
c19d1205
ZW
3391#ifdef md_cons_align
3392 md_cons_align (4);
3393#endif
b99bd4ef 3394
c19d1205 3395 mapping_state (MAP_DATA);
b99bd4ef 3396
c19d1205 3397 expression (&exp);
b99bd4ef 3398
c19d1205
ZW
3399 p = frag_more (4);
3400 md_number_to_chars (p, highbit, 4);
3401 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3402 BFD_RELOC_ARM_PREL31);
b99bd4ef 3403
c19d1205 3404 demand_empty_rest_of_line ();
b99bd4ef
NC
3405}
3406
c19d1205 3407/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3408
c19d1205 3409/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3410
c19d1205
ZW
3411static void
3412s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3413{
3414 demand_empty_rest_of_line ();
921e5f0a
PB
3415 if (unwind.proc_start)
3416 {
c921be7d 3417 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3418 return;
3419 }
3420
c19d1205
ZW
3421 /* Mark the start of the function. */
3422 unwind.proc_start = expr_build_dot ();
b99bd4ef 3423
c19d1205
ZW
3424 /* Reset the rest of the unwind info. */
3425 unwind.opcode_count = 0;
3426 unwind.table_entry = NULL;
3427 unwind.personality_routine = NULL;
3428 unwind.personality_index = -1;
3429 unwind.frame_size = 0;
3430 unwind.fp_offset = 0;
fdfde340 3431 unwind.fp_reg = REG_SP;
c19d1205
ZW
3432 unwind.fp_used = 0;
3433 unwind.sp_restored = 0;
3434}
b99bd4ef 3435
b99bd4ef 3436
c19d1205
ZW
3437/* Parse a handlerdata directive. Creates the exception handling table entry
3438 for the function. */
b99bd4ef 3439
c19d1205
ZW
3440static void
3441s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3442{
3443 demand_empty_rest_of_line ();
921e5f0a 3444 if (!unwind.proc_start)
c921be7d 3445 as_bad (MISSING_FNSTART);
921e5f0a 3446
c19d1205 3447 if (unwind.table_entry)
6decc662 3448 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3449
c19d1205
ZW
3450 create_unwind_entry (1);
3451}
a737bd4d 3452
c19d1205 3453/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3454
c19d1205
ZW
3455static void
3456s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3457{
3458 long where;
3459 char *ptr;
3460 valueT val;
940b5ce0 3461 unsigned int marked_pr_dependency;
f02232aa 3462
c19d1205 3463 demand_empty_rest_of_line ();
f02232aa 3464
921e5f0a
PB
3465 if (!unwind.proc_start)
3466 {
c921be7d 3467 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3468 return;
3469 }
3470
c19d1205
ZW
3471 /* Add eh table entry. */
3472 if (unwind.table_entry == NULL)
3473 val = create_unwind_entry (0);
3474 else
3475 val = 0;
f02232aa 3476
c19d1205
ZW
3477 /* Add index table entry. This is two words. */
3478 start_unwind_section (unwind.saved_seg, 1);
3479 frag_align (2, 0, 0);
3480 record_alignment (now_seg, 2);
b99bd4ef 3481
c19d1205
ZW
3482 ptr = frag_more (8);
3483 where = frag_now_fix () - 8;
f02232aa 3484
c19d1205
ZW
3485 /* Self relative offset of the function start. */
3486 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3487 BFD_RELOC_ARM_PREL31);
f02232aa 3488
c19d1205
ZW
3489 /* Indicate dependency on EHABI-defined personality routines to the
3490 linker, if it hasn't been done already. */
940b5ce0
DJ
3491 marked_pr_dependency
3492 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3493 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3494 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3495 {
5f4273c7
NC
3496 static const char *const name[] =
3497 {
3498 "__aeabi_unwind_cpp_pr0",
3499 "__aeabi_unwind_cpp_pr1",
3500 "__aeabi_unwind_cpp_pr2"
3501 };
c19d1205
ZW
3502 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3503 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3504 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3505 |= 1 << unwind.personality_index;
c19d1205 3506 }
f02232aa 3507
c19d1205
ZW
3508 if (val)
3509 /* Inline exception table entry. */
3510 md_number_to_chars (ptr + 4, val, 4);
3511 else
3512 /* Self relative offset of the table entry. */
3513 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3514 BFD_RELOC_ARM_PREL31);
f02232aa 3515
c19d1205
ZW
3516 /* Restore the original section. */
3517 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3518
3519 unwind.proc_start = NULL;
c19d1205 3520}
f02232aa 3521
f02232aa 3522
c19d1205 3523/* Parse an unwind_cantunwind directive. */
b99bd4ef 3524
c19d1205
ZW
3525static void
3526s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3527{
3528 demand_empty_rest_of_line ();
921e5f0a 3529 if (!unwind.proc_start)
c921be7d 3530 as_bad (MISSING_FNSTART);
921e5f0a 3531
c19d1205
ZW
3532 if (unwind.personality_routine || unwind.personality_index != -1)
3533 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3534
c19d1205
ZW
3535 unwind.personality_index = -2;
3536}
b99bd4ef 3537
b99bd4ef 3538
c19d1205 3539/* Parse a personalityindex directive. */
b99bd4ef 3540
c19d1205
ZW
3541static void
3542s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3543{
3544 expressionS exp;
b99bd4ef 3545
921e5f0a 3546 if (!unwind.proc_start)
c921be7d 3547 as_bad (MISSING_FNSTART);
921e5f0a 3548
c19d1205
ZW
3549 if (unwind.personality_routine || unwind.personality_index != -1)
3550 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3551
c19d1205 3552 expression (&exp);
b99bd4ef 3553
c19d1205
ZW
3554 if (exp.X_op != O_constant
3555 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3556 {
c19d1205
ZW
3557 as_bad (_("bad personality routine number"));
3558 ignore_rest_of_line ();
3559 return;
b99bd4ef
NC
3560 }
3561
c19d1205 3562 unwind.personality_index = exp.X_add_number;
b99bd4ef 3563
c19d1205
ZW
3564 demand_empty_rest_of_line ();
3565}
e16bb312 3566
e16bb312 3567
c19d1205 3568/* Parse a personality directive. */
e16bb312 3569
c19d1205
ZW
3570static void
3571s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3572{
3573 char *name, *p, c;
a737bd4d 3574
921e5f0a 3575 if (!unwind.proc_start)
c921be7d 3576 as_bad (MISSING_FNSTART);
921e5f0a 3577
c19d1205
ZW
3578 if (unwind.personality_routine || unwind.personality_index != -1)
3579 as_bad (_("duplicate .personality directive"));
a737bd4d 3580
c19d1205
ZW
3581 name = input_line_pointer;
3582 c = get_symbol_end ();
3583 p = input_line_pointer;
3584 unwind.personality_routine = symbol_find_or_make (name);
3585 *p = c;
3586 demand_empty_rest_of_line ();
3587}
e16bb312 3588
e16bb312 3589
c19d1205 3590/* Parse a directive saving core registers. */
e16bb312 3591
c19d1205
ZW
3592static void
3593s_arm_unwind_save_core (void)
e16bb312 3594{
c19d1205
ZW
3595 valueT op;
3596 long range;
3597 int n;
e16bb312 3598
c19d1205
ZW
3599 range = parse_reg_list (&input_line_pointer);
3600 if (range == FAIL)
e16bb312 3601 {
c19d1205
ZW
3602 as_bad (_("expected register list"));
3603 ignore_rest_of_line ();
3604 return;
3605 }
e16bb312 3606
c19d1205 3607 demand_empty_rest_of_line ();
e16bb312 3608
c19d1205
ZW
3609 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3610 into .unwind_save {..., sp...}. We aren't bothered about the value of
3611 ip because it is clobbered by calls. */
3612 if (unwind.sp_restored && unwind.fp_reg == 12
3613 && (range & 0x3000) == 0x1000)
3614 {
3615 unwind.opcode_count--;
3616 unwind.sp_restored = 0;
3617 range = (range | 0x2000) & ~0x1000;
3618 unwind.pending_offset = 0;
3619 }
e16bb312 3620
01ae4198
DJ
3621 /* Pop r4-r15. */
3622 if (range & 0xfff0)
c19d1205 3623 {
01ae4198
DJ
3624 /* See if we can use the short opcodes. These pop a block of up to 8
3625 registers starting with r4, plus maybe r14. */
3626 for (n = 0; n < 8; n++)
3627 {
3628 /* Break at the first non-saved register. */
3629 if ((range & (1 << (n + 4))) == 0)
3630 break;
3631 }
3632 /* See if there are any other bits set. */
3633 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3634 {
3635 /* Use the long form. */
3636 op = 0x8000 | ((range >> 4) & 0xfff);
3637 add_unwind_opcode (op, 2);
3638 }
0dd132b6 3639 else
01ae4198
DJ
3640 {
3641 /* Use the short form. */
3642 if (range & 0x4000)
3643 op = 0xa8; /* Pop r14. */
3644 else
3645 op = 0xa0; /* Do not pop r14. */
3646 op |= (n - 1);
3647 add_unwind_opcode (op, 1);
3648 }
c19d1205 3649 }
0dd132b6 3650
c19d1205
ZW
3651 /* Pop r0-r3. */
3652 if (range & 0xf)
3653 {
3654 op = 0xb100 | (range & 0xf);
3655 add_unwind_opcode (op, 2);
0dd132b6
NC
3656 }
3657
c19d1205
ZW
3658 /* Record the number of bytes pushed. */
3659 for (n = 0; n < 16; n++)
3660 {
3661 if (range & (1 << n))
3662 unwind.frame_size += 4;
3663 }
0dd132b6
NC
3664}
3665
c19d1205
ZW
3666
3667/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3668
3669static void
c19d1205 3670s_arm_unwind_save_fpa (int reg)
b99bd4ef 3671{
c19d1205
ZW
3672 expressionS exp;
3673 int num_regs;
3674 valueT op;
b99bd4ef 3675
c19d1205
ZW
3676 /* Get Number of registers to transfer. */
3677 if (skip_past_comma (&input_line_pointer) != FAIL)
3678 expression (&exp);
3679 else
3680 exp.X_op = O_illegal;
b99bd4ef 3681
c19d1205 3682 if (exp.X_op != O_constant)
b99bd4ef 3683 {
c19d1205
ZW
3684 as_bad (_("expected , <constant>"));
3685 ignore_rest_of_line ();
b99bd4ef
NC
3686 return;
3687 }
3688
c19d1205
ZW
3689 num_regs = exp.X_add_number;
3690
3691 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3692 {
c19d1205
ZW
3693 as_bad (_("number of registers must be in the range [1:4]"));
3694 ignore_rest_of_line ();
b99bd4ef
NC
3695 return;
3696 }
3697
c19d1205 3698 demand_empty_rest_of_line ();
b99bd4ef 3699
c19d1205
ZW
3700 if (reg == 4)
3701 {
3702 /* Short form. */
3703 op = 0xb4 | (num_regs - 1);
3704 add_unwind_opcode (op, 1);
3705 }
b99bd4ef
NC
3706 else
3707 {
c19d1205
ZW
3708 /* Long form. */
3709 op = 0xc800 | (reg << 4) | (num_regs - 1);
3710 add_unwind_opcode (op, 2);
b99bd4ef 3711 }
c19d1205 3712 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3713}
3714
c19d1205 3715
fa073d69
MS
3716/* Parse a directive saving VFP registers for ARMv6 and above. */
3717
3718static void
3719s_arm_unwind_save_vfp_armv6 (void)
3720{
3721 int count;
3722 unsigned int start;
3723 valueT op;
3724 int num_vfpv3_regs = 0;
3725 int num_regs_below_16;
3726
3727 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3728 if (count == FAIL)
3729 {
3730 as_bad (_("expected register list"));
3731 ignore_rest_of_line ();
3732 return;
3733 }
3734
3735 demand_empty_rest_of_line ();
3736
3737 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3738 than FSTMX/FLDMX-style ones). */
3739
3740 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3741 if (start >= 16)
3742 num_vfpv3_regs = count;
3743 else if (start + count > 16)
3744 num_vfpv3_regs = start + count - 16;
3745
3746 if (num_vfpv3_regs > 0)
3747 {
3748 int start_offset = start > 16 ? start - 16 : 0;
3749 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3750 add_unwind_opcode (op, 2);
3751 }
3752
3753 /* Generate opcode for registers numbered in the range 0 .. 15. */
3754 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3755 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3756 if (num_regs_below_16 > 0)
3757 {
3758 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3759 add_unwind_opcode (op, 2);
3760 }
3761
3762 unwind.frame_size += count * 8;
3763}
3764
3765
3766/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3767
3768static void
c19d1205 3769s_arm_unwind_save_vfp (void)
b99bd4ef 3770{
c19d1205 3771 int count;
ca3f61f7 3772 unsigned int reg;
c19d1205 3773 valueT op;
b99bd4ef 3774
5287ad62 3775 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3776 if (count == FAIL)
b99bd4ef 3777 {
c19d1205
ZW
3778 as_bad (_("expected register list"));
3779 ignore_rest_of_line ();
b99bd4ef
NC
3780 return;
3781 }
3782
c19d1205 3783 demand_empty_rest_of_line ();
b99bd4ef 3784
c19d1205 3785 if (reg == 8)
b99bd4ef 3786 {
c19d1205
ZW
3787 /* Short form. */
3788 op = 0xb8 | (count - 1);
3789 add_unwind_opcode (op, 1);
b99bd4ef 3790 }
c19d1205 3791 else
b99bd4ef 3792 {
c19d1205
ZW
3793 /* Long form. */
3794 op = 0xb300 | (reg << 4) | (count - 1);
3795 add_unwind_opcode (op, 2);
b99bd4ef 3796 }
c19d1205
ZW
3797 unwind.frame_size += count * 8 + 4;
3798}
b99bd4ef 3799
b99bd4ef 3800
c19d1205
ZW
3801/* Parse a directive saving iWMMXt data registers. */
3802
3803static void
3804s_arm_unwind_save_mmxwr (void)
3805{
3806 int reg;
3807 int hi_reg;
3808 int i;
3809 unsigned mask = 0;
3810 valueT op;
b99bd4ef 3811
c19d1205
ZW
3812 if (*input_line_pointer == '{')
3813 input_line_pointer++;
b99bd4ef 3814
c19d1205 3815 do
b99bd4ef 3816 {
dcbf9037 3817 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3818
c19d1205 3819 if (reg == FAIL)
b99bd4ef 3820 {
9b7132d3 3821 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3822 goto error;
b99bd4ef
NC
3823 }
3824
c19d1205
ZW
3825 if (mask >> reg)
3826 as_tsktsk (_("register list not in ascending order"));
3827 mask |= 1 << reg;
b99bd4ef 3828
c19d1205
ZW
3829 if (*input_line_pointer == '-')
3830 {
3831 input_line_pointer++;
dcbf9037 3832 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3833 if (hi_reg == FAIL)
3834 {
9b7132d3 3835 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3836 goto error;
3837 }
3838 else if (reg >= hi_reg)
3839 {
3840 as_bad (_("bad register range"));
3841 goto error;
3842 }
3843 for (; reg < hi_reg; reg++)
3844 mask |= 1 << reg;
3845 }
3846 }
3847 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3848
c19d1205
ZW
3849 if (*input_line_pointer == '}')
3850 input_line_pointer++;
b99bd4ef 3851
c19d1205 3852 demand_empty_rest_of_line ();
b99bd4ef 3853
708587a4 3854 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3855 the list. */
3856 flush_pending_unwind ();
b99bd4ef 3857
c19d1205 3858 for (i = 0; i < 16; i++)
b99bd4ef 3859 {
c19d1205
ZW
3860 if (mask & (1 << i))
3861 unwind.frame_size += 8;
b99bd4ef
NC
3862 }
3863
c19d1205
ZW
3864 /* Attempt to combine with a previous opcode. We do this because gcc
3865 likes to output separate unwind directives for a single block of
3866 registers. */
3867 if (unwind.opcode_count > 0)
b99bd4ef 3868 {
c19d1205
ZW
3869 i = unwind.opcodes[unwind.opcode_count - 1];
3870 if ((i & 0xf8) == 0xc0)
3871 {
3872 i &= 7;
3873 /* Only merge if the blocks are contiguous. */
3874 if (i < 6)
3875 {
3876 if ((mask & 0xfe00) == (1 << 9))
3877 {
3878 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3879 unwind.opcode_count--;
3880 }
3881 }
3882 else if (i == 6 && unwind.opcode_count >= 2)
3883 {
3884 i = unwind.opcodes[unwind.opcode_count - 2];
3885 reg = i >> 4;
3886 i &= 0xf;
b99bd4ef 3887
c19d1205
ZW
3888 op = 0xffff << (reg - 1);
3889 if (reg > 0
87a1fd79 3890 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3891 {
3892 op = (1 << (reg + i + 1)) - 1;
3893 op &= ~((1 << reg) - 1);
3894 mask |= op;
3895 unwind.opcode_count -= 2;
3896 }
3897 }
3898 }
b99bd4ef
NC
3899 }
3900
c19d1205
ZW
3901 hi_reg = 15;
3902 /* We want to generate opcodes in the order the registers have been
3903 saved, ie. descending order. */
3904 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3905 {
c19d1205
ZW
3906 /* Save registers in blocks. */
3907 if (reg < 0
3908 || !(mask & (1 << reg)))
3909 {
3910 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3911 preceding block. */
c19d1205
ZW
3912 if (reg != hi_reg)
3913 {
3914 if (reg == 9)
3915 {
3916 /* Short form. */
3917 op = 0xc0 | (hi_reg - 10);
3918 add_unwind_opcode (op, 1);
3919 }
3920 else
3921 {
3922 /* Long form. */
3923 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3924 add_unwind_opcode (op, 2);
3925 }
3926 }
3927 hi_reg = reg - 1;
3928 }
b99bd4ef
NC
3929 }
3930
c19d1205
ZW
3931 return;
3932error:
3933 ignore_rest_of_line ();
b99bd4ef
NC
3934}
3935
3936static void
c19d1205 3937s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3938{
c19d1205
ZW
3939 int reg;
3940 int hi_reg;
3941 unsigned mask = 0;
3942 valueT op;
b99bd4ef 3943
c19d1205
ZW
3944 if (*input_line_pointer == '{')
3945 input_line_pointer++;
b99bd4ef 3946
c19d1205 3947 do
b99bd4ef 3948 {
dcbf9037 3949 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3950
c19d1205
ZW
3951 if (reg == FAIL)
3952 {
9b7132d3 3953 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3954 goto error;
3955 }
b99bd4ef 3956
c19d1205
ZW
3957 reg -= 8;
3958 if (mask >> reg)
3959 as_tsktsk (_("register list not in ascending order"));
3960 mask |= 1 << reg;
b99bd4ef 3961
c19d1205
ZW
3962 if (*input_line_pointer == '-')
3963 {
3964 input_line_pointer++;
dcbf9037 3965 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3966 if (hi_reg == FAIL)
3967 {
9b7132d3 3968 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3969 goto error;
3970 }
3971 else if (reg >= hi_reg)
3972 {
3973 as_bad (_("bad register range"));
3974 goto error;
3975 }
3976 for (; reg < hi_reg; reg++)
3977 mask |= 1 << reg;
3978 }
b99bd4ef 3979 }
c19d1205 3980 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3981
c19d1205
ZW
3982 if (*input_line_pointer == '}')
3983 input_line_pointer++;
b99bd4ef 3984
c19d1205
ZW
3985 demand_empty_rest_of_line ();
3986
708587a4 3987 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3988 the list. */
3989 flush_pending_unwind ();
b99bd4ef 3990
c19d1205 3991 for (reg = 0; reg < 16; reg++)
b99bd4ef 3992 {
c19d1205
ZW
3993 if (mask & (1 << reg))
3994 unwind.frame_size += 4;
b99bd4ef 3995 }
c19d1205
ZW
3996 op = 0xc700 | mask;
3997 add_unwind_opcode (op, 2);
3998 return;
3999error:
4000 ignore_rest_of_line ();
b99bd4ef
NC
4001}
4002
c19d1205 4003
fa073d69
MS
4004/* Parse an unwind_save directive.
4005 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4006
b99bd4ef 4007static void
fa073d69 4008s_arm_unwind_save (int arch_v6)
b99bd4ef 4009{
c19d1205
ZW
4010 char *peek;
4011 struct reg_entry *reg;
4012 bfd_boolean had_brace = FALSE;
b99bd4ef 4013
921e5f0a 4014 if (!unwind.proc_start)
c921be7d 4015 as_bad (MISSING_FNSTART);
921e5f0a 4016
c19d1205
ZW
4017 /* Figure out what sort of save we have. */
4018 peek = input_line_pointer;
b99bd4ef 4019
c19d1205 4020 if (*peek == '{')
b99bd4ef 4021 {
c19d1205
ZW
4022 had_brace = TRUE;
4023 peek++;
b99bd4ef
NC
4024 }
4025
c19d1205 4026 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4027
c19d1205 4028 if (!reg)
b99bd4ef 4029 {
c19d1205
ZW
4030 as_bad (_("register expected"));
4031 ignore_rest_of_line ();
b99bd4ef
NC
4032 return;
4033 }
4034
c19d1205 4035 switch (reg->type)
b99bd4ef 4036 {
c19d1205
ZW
4037 case REG_TYPE_FN:
4038 if (had_brace)
4039 {
4040 as_bad (_("FPA .unwind_save does not take a register list"));
4041 ignore_rest_of_line ();
4042 return;
4043 }
93ac2687 4044 input_line_pointer = peek;
c19d1205 4045 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4046 return;
c19d1205
ZW
4047
4048 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
4049 case REG_TYPE_VFD:
4050 if (arch_v6)
4051 s_arm_unwind_save_vfp_armv6 ();
4052 else
4053 s_arm_unwind_save_vfp ();
4054 return;
c19d1205
ZW
4055 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4056 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4057
4058 default:
4059 as_bad (_(".unwind_save does not support this kind of register"));
4060 ignore_rest_of_line ();
b99bd4ef 4061 }
c19d1205 4062}
b99bd4ef 4063
b99bd4ef 4064
c19d1205
ZW
4065/* Parse an unwind_movsp directive. */
4066
4067static void
4068s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4069{
4070 int reg;
4071 valueT op;
4fa3602b 4072 int offset;
c19d1205 4073
921e5f0a 4074 if (!unwind.proc_start)
c921be7d 4075 as_bad (MISSING_FNSTART);
921e5f0a 4076
dcbf9037 4077 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4078 if (reg == FAIL)
b99bd4ef 4079 {
9b7132d3 4080 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4081 ignore_rest_of_line ();
b99bd4ef
NC
4082 return;
4083 }
4fa3602b
PB
4084
4085 /* Optional constant. */
4086 if (skip_past_comma (&input_line_pointer) != FAIL)
4087 {
4088 if (immediate_for_directive (&offset) == FAIL)
4089 return;
4090 }
4091 else
4092 offset = 0;
4093
c19d1205 4094 demand_empty_rest_of_line ();
b99bd4ef 4095
c19d1205 4096 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4097 {
c19d1205 4098 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4099 return;
4100 }
4101
c19d1205
ZW
4102 if (unwind.fp_reg != REG_SP)
4103 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4104
c19d1205
ZW
4105 /* Generate opcode to restore the value. */
4106 op = 0x90 | reg;
4107 add_unwind_opcode (op, 1);
4108
4109 /* Record the information for later. */
4110 unwind.fp_reg = reg;
4fa3602b 4111 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4112 unwind.sp_restored = 1;
b05fe5cf
ZW
4113}
4114
c19d1205
ZW
4115/* Parse an unwind_pad directive. */
4116
b05fe5cf 4117static void
c19d1205 4118s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4119{
c19d1205 4120 int offset;
b05fe5cf 4121
921e5f0a 4122 if (!unwind.proc_start)
c921be7d 4123 as_bad (MISSING_FNSTART);
921e5f0a 4124
c19d1205
ZW
4125 if (immediate_for_directive (&offset) == FAIL)
4126 return;
b99bd4ef 4127
c19d1205
ZW
4128 if (offset & 3)
4129 {
4130 as_bad (_("stack increment must be multiple of 4"));
4131 ignore_rest_of_line ();
4132 return;
4133 }
b99bd4ef 4134
c19d1205
ZW
4135 /* Don't generate any opcodes, just record the details for later. */
4136 unwind.frame_size += offset;
4137 unwind.pending_offset += offset;
4138
4139 demand_empty_rest_of_line ();
4140}
4141
4142/* Parse an unwind_setfp directive. */
4143
4144static void
4145s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4146{
c19d1205
ZW
4147 int sp_reg;
4148 int fp_reg;
4149 int offset;
4150
921e5f0a 4151 if (!unwind.proc_start)
c921be7d 4152 as_bad (MISSING_FNSTART);
921e5f0a 4153
dcbf9037 4154 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4155 if (skip_past_comma (&input_line_pointer) == FAIL)
4156 sp_reg = FAIL;
4157 else
dcbf9037 4158 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4159
c19d1205
ZW
4160 if (fp_reg == FAIL || sp_reg == FAIL)
4161 {
4162 as_bad (_("expected <reg>, <reg>"));
4163 ignore_rest_of_line ();
4164 return;
4165 }
b99bd4ef 4166
c19d1205
ZW
4167 /* Optional constant. */
4168 if (skip_past_comma (&input_line_pointer) != FAIL)
4169 {
4170 if (immediate_for_directive (&offset) == FAIL)
4171 return;
4172 }
4173 else
4174 offset = 0;
a737bd4d 4175
c19d1205 4176 demand_empty_rest_of_line ();
a737bd4d 4177
fdfde340 4178 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4179 {
c19d1205
ZW
4180 as_bad (_("register must be either sp or set by a previous"
4181 "unwind_movsp directive"));
4182 return;
a737bd4d
NC
4183 }
4184
c19d1205
ZW
4185 /* Don't generate any opcodes, just record the information for later. */
4186 unwind.fp_reg = fp_reg;
4187 unwind.fp_used = 1;
fdfde340 4188 if (sp_reg == REG_SP)
c19d1205
ZW
4189 unwind.fp_offset = unwind.frame_size - offset;
4190 else
4191 unwind.fp_offset -= offset;
a737bd4d
NC
4192}
4193
c19d1205
ZW
4194/* Parse an unwind_raw directive. */
4195
4196static void
4197s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4198{
c19d1205 4199 expressionS exp;
708587a4 4200 /* This is an arbitrary limit. */
c19d1205
ZW
4201 unsigned char op[16];
4202 int count;
a737bd4d 4203
921e5f0a 4204 if (!unwind.proc_start)
c921be7d 4205 as_bad (MISSING_FNSTART);
921e5f0a 4206
c19d1205
ZW
4207 expression (&exp);
4208 if (exp.X_op == O_constant
4209 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4210 {
c19d1205
ZW
4211 unwind.frame_size += exp.X_add_number;
4212 expression (&exp);
4213 }
4214 else
4215 exp.X_op = O_illegal;
a737bd4d 4216
c19d1205
ZW
4217 if (exp.X_op != O_constant)
4218 {
4219 as_bad (_("expected <offset>, <opcode>"));
4220 ignore_rest_of_line ();
4221 return;
4222 }
a737bd4d 4223
c19d1205 4224 count = 0;
a737bd4d 4225
c19d1205
ZW
4226 /* Parse the opcode. */
4227 for (;;)
4228 {
4229 if (count >= 16)
4230 {
4231 as_bad (_("unwind opcode too long"));
4232 ignore_rest_of_line ();
a737bd4d 4233 }
c19d1205 4234 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4235 {
c19d1205
ZW
4236 as_bad (_("invalid unwind opcode"));
4237 ignore_rest_of_line ();
4238 return;
a737bd4d 4239 }
c19d1205 4240 op[count++] = exp.X_add_number;
a737bd4d 4241
c19d1205
ZW
4242 /* Parse the next byte. */
4243 if (skip_past_comma (&input_line_pointer) == FAIL)
4244 break;
a737bd4d 4245
c19d1205
ZW
4246 expression (&exp);
4247 }
b99bd4ef 4248
c19d1205
ZW
4249 /* Add the opcode bytes in reverse order. */
4250 while (count--)
4251 add_unwind_opcode (op[count], 1);
b99bd4ef 4252
c19d1205 4253 demand_empty_rest_of_line ();
b99bd4ef 4254}
ee065d83
PB
4255
4256
4257/* Parse a .eabi_attribute directive. */
4258
4259static void
4260s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4261{
ee3c0378
AS
4262 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4263
4264 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4265 attributes_set_explicitly[tag] = 1;
ee065d83 4266}
8463be01 4267#endif /* OBJ_ELF */
ee065d83
PB
4268
4269static void s_arm_arch (int);
7a1d4c38 4270static void s_arm_object_arch (int);
ee065d83
PB
4271static void s_arm_cpu (int);
4272static void s_arm_fpu (int);
b99bd4ef 4273
f0927246
NC
4274#ifdef TE_PE
4275
4276static void
5f4273c7 4277pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4278{
4279 expressionS exp;
4280
4281 do
4282 {
4283 expression (&exp);
4284 if (exp.X_op == O_symbol)
4285 exp.X_op = O_secrel;
4286
4287 emit_expr (&exp, 4);
4288 }
4289 while (*input_line_pointer++ == ',');
4290
4291 input_line_pointer--;
4292 demand_empty_rest_of_line ();
4293}
4294#endif /* TE_PE */
4295
c19d1205
ZW
4296/* This table describes all the machine specific pseudo-ops the assembler
4297 has to support. The fields are:
4298 pseudo-op name without dot
4299 function to call to execute this pseudo-op
4300 Integer arg to pass to the function. */
b99bd4ef 4301
c19d1205 4302const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4303{
c19d1205
ZW
4304 /* Never called because '.req' does not start a line. */
4305 { "req", s_req, 0 },
dcbf9037
JB
4306 /* Following two are likewise never called. */
4307 { "dn", s_dn, 0 },
4308 { "qn", s_qn, 0 },
c19d1205
ZW
4309 { "unreq", s_unreq, 0 },
4310 { "bss", s_bss, 0 },
4311 { "align", s_align, 0 },
4312 { "arm", s_arm, 0 },
4313 { "thumb", s_thumb, 0 },
4314 { "code", s_code, 0 },
4315 { "force_thumb", s_force_thumb, 0 },
4316 { "thumb_func", s_thumb_func, 0 },
4317 { "thumb_set", s_thumb_set, 0 },
4318 { "even", s_even, 0 },
4319 { "ltorg", s_ltorg, 0 },
4320 { "pool", s_ltorg, 0 },
4321 { "syntax", s_syntax, 0 },
8463be01
PB
4322 { "cpu", s_arm_cpu, 0 },
4323 { "arch", s_arm_arch, 0 },
7a1d4c38 4324 { "object_arch", s_arm_object_arch, 0 },
8463be01 4325 { "fpu", s_arm_fpu, 0 },
c19d1205 4326#ifdef OBJ_ELF
c921be7d
NC
4327 { "word", s_arm_elf_cons, 4 },
4328 { "long", s_arm_elf_cons, 4 },
4329 { "inst.n", s_arm_elf_inst, 2 },
4330 { "inst.w", s_arm_elf_inst, 4 },
4331 { "inst", s_arm_elf_inst, 0 },
4332 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4333 { "fnstart", s_arm_unwind_fnstart, 0 },
4334 { "fnend", s_arm_unwind_fnend, 0 },
4335 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4336 { "personality", s_arm_unwind_personality, 0 },
4337 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4338 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4339 { "save", s_arm_unwind_save, 0 },
fa073d69 4340 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4341 { "movsp", s_arm_unwind_movsp, 0 },
4342 { "pad", s_arm_unwind_pad, 0 },
4343 { "setfp", s_arm_unwind_setfp, 0 },
4344 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4345 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
4346#else
4347 { "word", cons, 4},
f0927246
NC
4348
4349 /* These are used for dwarf. */
4350 {"2byte", cons, 2},
4351 {"4byte", cons, 4},
4352 {"8byte", cons, 8},
4353 /* These are used for dwarf2. */
4354 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4355 { "loc", dwarf2_directive_loc, 0 },
4356 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4357#endif
4358 { "extend", float_cons, 'x' },
4359 { "ldouble", float_cons, 'x' },
4360 { "packed", float_cons, 'p' },
f0927246
NC
4361#ifdef TE_PE
4362 {"secrel32", pe_directive_secrel, 0},
4363#endif
c19d1205
ZW
4364 { 0, 0, 0 }
4365};
4366\f
4367/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4368
c19d1205
ZW
4369/* Generic immediate-value read function for use in insn parsing.
4370 STR points to the beginning of the immediate (the leading #);
4371 VAL receives the value; if the value is outside [MIN, MAX]
4372 issue an error. PREFIX_OPT is true if the immediate prefix is
4373 optional. */
b99bd4ef 4374
c19d1205
ZW
4375static int
4376parse_immediate (char **str, int *val, int min, int max,
4377 bfd_boolean prefix_opt)
4378{
4379 expressionS exp;
4380 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4381 if (exp.X_op != O_constant)
b99bd4ef 4382 {
c19d1205
ZW
4383 inst.error = _("constant expression required");
4384 return FAIL;
4385 }
b99bd4ef 4386
c19d1205
ZW
4387 if (exp.X_add_number < min || exp.X_add_number > max)
4388 {
4389 inst.error = _("immediate value out of range");
4390 return FAIL;
4391 }
b99bd4ef 4392
c19d1205
ZW
4393 *val = exp.X_add_number;
4394 return SUCCESS;
4395}
b99bd4ef 4396
5287ad62 4397/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4398 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4399 instructions. Puts the result directly in inst.operands[i]. */
4400
4401static int
4402parse_big_immediate (char **str, int i)
4403{
4404 expressionS exp;
4405 char *ptr = *str;
4406
4407 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4408
4409 if (exp.X_op == O_constant)
036dc3f7
PB
4410 {
4411 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4412 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4413 O_constant. We have to be careful not to break compilation for
4414 32-bit X_add_number, though. */
4415 if ((exp.X_add_number & ~0xffffffffl) != 0)
4416 {
4417 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4418 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4419 inst.operands[i].regisimm = 1;
4420 }
4421 }
5287ad62 4422 else if (exp.X_op == O_big
95b75c01 4423 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
5287ad62
JB
4424 {
4425 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4426
5287ad62
JB
4427 /* Bignums have their least significant bits in
4428 generic_bignum[0]. Make sure we put 32 bits in imm and
4429 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4430 gas_assert (parts != 0);
95b75c01
NC
4431
4432 /* Make sure that the number is not too big.
4433 PR 11972: Bignums can now be sign-extended to the
4434 size of a .octa so check that the out of range bits
4435 are all zero or all one. */
4436 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4437 {
4438 LITTLENUM_TYPE m = -1;
4439
4440 if (generic_bignum[parts * 2] != 0
4441 && generic_bignum[parts * 2] != m)
4442 return FAIL;
4443
4444 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4445 if (generic_bignum[j] != generic_bignum[j-1])
4446 return FAIL;
4447 }
4448
5287ad62
JB
4449 inst.operands[i].imm = 0;
4450 for (j = 0; j < parts; j++, idx++)
4451 inst.operands[i].imm |= generic_bignum[idx]
4452 << (LITTLENUM_NUMBER_OF_BITS * j);
4453 inst.operands[i].reg = 0;
4454 for (j = 0; j < parts; j++, idx++)
4455 inst.operands[i].reg |= generic_bignum[idx]
4456 << (LITTLENUM_NUMBER_OF_BITS * j);
4457 inst.operands[i].regisimm = 1;
4458 }
4459 else
4460 return FAIL;
5f4273c7 4461
5287ad62
JB
4462 *str = ptr;
4463
4464 return SUCCESS;
4465}
4466
c19d1205
ZW
4467/* Returns the pseudo-register number of an FPA immediate constant,
4468 or FAIL if there isn't a valid constant here. */
b99bd4ef 4469
c19d1205
ZW
4470static int
4471parse_fpa_immediate (char ** str)
4472{
4473 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4474 char * save_in;
4475 expressionS exp;
4476 int i;
4477 int j;
b99bd4ef 4478
c19d1205
ZW
4479 /* First try and match exact strings, this is to guarantee
4480 that some formats will work even for cross assembly. */
b99bd4ef 4481
c19d1205
ZW
4482 for (i = 0; fp_const[i]; i++)
4483 {
4484 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4485 {
c19d1205 4486 char *start = *str;
b99bd4ef 4487
c19d1205
ZW
4488 *str += strlen (fp_const[i]);
4489 if (is_end_of_line[(unsigned char) **str])
4490 return i + 8;
4491 *str = start;
4492 }
4493 }
b99bd4ef 4494
c19d1205
ZW
4495 /* Just because we didn't get a match doesn't mean that the constant
4496 isn't valid, just that it is in a format that we don't
4497 automatically recognize. Try parsing it with the standard
4498 expression routines. */
b99bd4ef 4499
c19d1205 4500 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4501
c19d1205
ZW
4502 /* Look for a raw floating point number. */
4503 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4504 && is_end_of_line[(unsigned char) *save_in])
4505 {
4506 for (i = 0; i < NUM_FLOAT_VALS; i++)
4507 {
4508 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4509 {
c19d1205
ZW
4510 if (words[j] != fp_values[i][j])
4511 break;
b99bd4ef
NC
4512 }
4513
c19d1205 4514 if (j == MAX_LITTLENUMS)
b99bd4ef 4515 {
c19d1205
ZW
4516 *str = save_in;
4517 return i + 8;
b99bd4ef
NC
4518 }
4519 }
4520 }
b99bd4ef 4521
c19d1205
ZW
4522 /* Try and parse a more complex expression, this will probably fail
4523 unless the code uses a floating point prefix (eg "0f"). */
4524 save_in = input_line_pointer;
4525 input_line_pointer = *str;
4526 if (expression (&exp) == absolute_section
4527 && exp.X_op == O_big
4528 && exp.X_add_number < 0)
4529 {
4530 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4531 Ditto for 15. */
4532 if (gen_to_words (words, 5, (long) 15) == 0)
4533 {
4534 for (i = 0; i < NUM_FLOAT_VALS; i++)
4535 {
4536 for (j = 0; j < MAX_LITTLENUMS; j++)
4537 {
4538 if (words[j] != fp_values[i][j])
4539 break;
4540 }
b99bd4ef 4541
c19d1205
ZW
4542 if (j == MAX_LITTLENUMS)
4543 {
4544 *str = input_line_pointer;
4545 input_line_pointer = save_in;
4546 return i + 8;
4547 }
4548 }
4549 }
b99bd4ef
NC
4550 }
4551
c19d1205
ZW
4552 *str = input_line_pointer;
4553 input_line_pointer = save_in;
4554 inst.error = _("invalid FPA immediate expression");
4555 return FAIL;
b99bd4ef
NC
4556}
4557
136da414
JB
4558/* Returns 1 if a number has "quarter-precision" float format
4559 0baBbbbbbc defgh000 00000000 00000000. */
4560
4561static int
4562is_quarter_float (unsigned imm)
4563{
4564 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4565 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4566}
4567
4568/* Parse an 8-bit "quarter-precision" floating point number of the form:
4569 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4570 The zero and minus-zero cases need special handling, since they can't be
4571 encoded in the "quarter-precision" float format, but can nonetheless be
4572 loaded as integer constants. */
136da414
JB
4573
4574static unsigned
4575parse_qfloat_immediate (char **ccp, int *immed)
4576{
4577 char *str = *ccp;
c96612cc 4578 char *fpnum;
136da414 4579 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4580 int found_fpchar = 0;
5f4273c7 4581
136da414 4582 skip_past_char (&str, '#');
5f4273c7 4583
c96612cc
JB
4584 /* We must not accidentally parse an integer as a floating-point number. Make
4585 sure that the value we parse is not an integer by checking for special
4586 characters '.' or 'e'.
4587 FIXME: This is a horrible hack, but doing better is tricky because type
4588 information isn't in a very usable state at parse time. */
4589 fpnum = str;
4590 skip_whitespace (fpnum);
4591
4592 if (strncmp (fpnum, "0x", 2) == 0)
4593 return FAIL;
4594 else
4595 {
4596 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4597 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4598 {
4599 found_fpchar = 1;
4600 break;
4601 }
4602
4603 if (!found_fpchar)
4604 return FAIL;
4605 }
5f4273c7 4606
136da414
JB
4607 if ((str = atof_ieee (str, 's', words)) != NULL)
4608 {
4609 unsigned fpword = 0;
4610 int i;
5f4273c7 4611
136da414
JB
4612 /* Our FP word must be 32 bits (single-precision FP). */
4613 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4614 {
4615 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4616 fpword |= words[i];
4617 }
5f4273c7 4618
c96612cc 4619 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4620 *immed = fpword;
4621 else
4622 return FAIL;
4623
4624 *ccp = str;
5f4273c7 4625
136da414
JB
4626 return SUCCESS;
4627 }
5f4273c7 4628
136da414
JB
4629 return FAIL;
4630}
4631
c19d1205
ZW
4632/* Shift operands. */
4633enum shift_kind
b99bd4ef 4634{
c19d1205
ZW
4635 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4636};
b99bd4ef 4637
c19d1205
ZW
4638struct asm_shift_name
4639{
4640 const char *name;
4641 enum shift_kind kind;
4642};
b99bd4ef 4643
c19d1205
ZW
4644/* Third argument to parse_shift. */
4645enum parse_shift_mode
4646{
4647 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4648 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4649 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4650 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4651 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4652};
b99bd4ef 4653
c19d1205
ZW
4654/* Parse a <shift> specifier on an ARM data processing instruction.
4655 This has three forms:
b99bd4ef 4656
c19d1205
ZW
4657 (LSL|LSR|ASL|ASR|ROR) Rs
4658 (LSL|LSR|ASL|ASR|ROR) #imm
4659 RRX
b99bd4ef 4660
c19d1205
ZW
4661 Note that ASL is assimilated to LSL in the instruction encoding, and
4662 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4663
c19d1205
ZW
4664static int
4665parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4666{
c19d1205
ZW
4667 const struct asm_shift_name *shift_name;
4668 enum shift_kind shift;
4669 char *s = *str;
4670 char *p = s;
4671 int reg;
b99bd4ef 4672
c19d1205
ZW
4673 for (p = *str; ISALPHA (*p); p++)
4674 ;
b99bd4ef 4675
c19d1205 4676 if (p == *str)
b99bd4ef 4677 {
c19d1205
ZW
4678 inst.error = _("shift expression expected");
4679 return FAIL;
b99bd4ef
NC
4680 }
4681
21d799b5
NC
4682 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4683 p - *str);
c19d1205
ZW
4684
4685 if (shift_name == NULL)
b99bd4ef 4686 {
c19d1205
ZW
4687 inst.error = _("shift expression expected");
4688 return FAIL;
b99bd4ef
NC
4689 }
4690
c19d1205 4691 shift = shift_name->kind;
b99bd4ef 4692
c19d1205
ZW
4693 switch (mode)
4694 {
4695 case NO_SHIFT_RESTRICT:
4696 case SHIFT_IMMEDIATE: break;
b99bd4ef 4697
c19d1205
ZW
4698 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4699 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4700 {
4701 inst.error = _("'LSL' or 'ASR' required");
4702 return FAIL;
4703 }
4704 break;
b99bd4ef 4705
c19d1205
ZW
4706 case SHIFT_LSL_IMMEDIATE:
4707 if (shift != SHIFT_LSL)
4708 {
4709 inst.error = _("'LSL' required");
4710 return FAIL;
4711 }
4712 break;
b99bd4ef 4713
c19d1205
ZW
4714 case SHIFT_ASR_IMMEDIATE:
4715 if (shift != SHIFT_ASR)
4716 {
4717 inst.error = _("'ASR' required");
4718 return FAIL;
4719 }
4720 break;
b99bd4ef 4721
c19d1205
ZW
4722 default: abort ();
4723 }
b99bd4ef 4724
c19d1205
ZW
4725 if (shift != SHIFT_RRX)
4726 {
4727 /* Whitespace can appear here if the next thing is a bare digit. */
4728 skip_whitespace (p);
b99bd4ef 4729
c19d1205 4730 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4731 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4732 {
4733 inst.operands[i].imm = reg;
4734 inst.operands[i].immisreg = 1;
4735 }
4736 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4737 return FAIL;
4738 }
4739 inst.operands[i].shift_kind = shift;
4740 inst.operands[i].shifted = 1;
4741 *str = p;
4742 return SUCCESS;
b99bd4ef
NC
4743}
4744
c19d1205 4745/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4746
c19d1205
ZW
4747 #<immediate>
4748 #<immediate>, <rotate>
4749 <Rm>
4750 <Rm>, <shift>
b99bd4ef 4751
c19d1205
ZW
4752 where <shift> is defined by parse_shift above, and <rotate> is a
4753 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4754 is deferred to md_apply_fix. */
b99bd4ef 4755
c19d1205
ZW
4756static int
4757parse_shifter_operand (char **str, int i)
4758{
4759 int value;
91d6fa6a 4760 expressionS exp;
b99bd4ef 4761
dcbf9037 4762 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4763 {
4764 inst.operands[i].reg = value;
4765 inst.operands[i].isreg = 1;
b99bd4ef 4766
c19d1205
ZW
4767 /* parse_shift will override this if appropriate */
4768 inst.reloc.exp.X_op = O_constant;
4769 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4770
c19d1205
ZW
4771 if (skip_past_comma (str) == FAIL)
4772 return SUCCESS;
b99bd4ef 4773
c19d1205
ZW
4774 /* Shift operation on register. */
4775 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4776 }
4777
c19d1205
ZW
4778 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4779 return FAIL;
b99bd4ef 4780
c19d1205 4781 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4782 {
c19d1205 4783 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 4784 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 4785 return FAIL;
b99bd4ef 4786
91d6fa6a 4787 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
4788 {
4789 inst.error = _("constant expression expected");
4790 return FAIL;
4791 }
b99bd4ef 4792
91d6fa6a 4793 value = exp.X_add_number;
c19d1205
ZW
4794 if (value < 0 || value > 30 || value % 2 != 0)
4795 {
4796 inst.error = _("invalid rotation");
4797 return FAIL;
4798 }
4799 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4800 {
4801 inst.error = _("invalid constant");
4802 return FAIL;
4803 }
09d92015 4804
55cf6793 4805 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4806 inst.reloc.exp.X_add_number
4807 = (((inst.reloc.exp.X_add_number << (32 - value))
4808 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4809 }
4810
c19d1205
ZW
4811 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4812 inst.reloc.pc_rel = 0;
4813 return SUCCESS;
09d92015
MM
4814}
4815
4962c51a
MS
4816/* Group relocation information. Each entry in the table contains the
4817 textual name of the relocation as may appear in assembler source
4818 and must end with a colon.
4819 Along with this textual name are the relocation codes to be used if
4820 the corresponding instruction is an ALU instruction (ADD or SUB only),
4821 an LDR, an LDRS, or an LDC. */
4822
4823struct group_reloc_table_entry
4824{
4825 const char *name;
4826 int alu_code;
4827 int ldr_code;
4828 int ldrs_code;
4829 int ldc_code;
4830};
4831
4832typedef enum
4833{
4834 /* Varieties of non-ALU group relocation. */
4835
4836 GROUP_LDR,
4837 GROUP_LDRS,
4838 GROUP_LDC
4839} group_reloc_type;
4840
4841static struct group_reloc_table_entry group_reloc_table[] =
4842 { /* Program counter relative: */
4843 { "pc_g0_nc",
4844 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4845 0, /* LDR */
4846 0, /* LDRS */
4847 0 }, /* LDC */
4848 { "pc_g0",
4849 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4850 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4851 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4852 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4853 { "pc_g1_nc",
4854 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4855 0, /* LDR */
4856 0, /* LDRS */
4857 0 }, /* LDC */
4858 { "pc_g1",
4859 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4860 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4861 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4862 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4863 { "pc_g2",
4864 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4865 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4866 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4867 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4868 /* Section base relative */
4869 { "sb_g0_nc",
4870 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4871 0, /* LDR */
4872 0, /* LDRS */
4873 0 }, /* LDC */
4874 { "sb_g0",
4875 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4876 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4877 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4878 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4879 { "sb_g1_nc",
4880 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4881 0, /* LDR */
4882 0, /* LDRS */
4883 0 }, /* LDC */
4884 { "sb_g1",
4885 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4886 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4887 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4888 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4889 { "sb_g2",
4890 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4891 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4892 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4893 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4894
4895/* Given the address of a pointer pointing to the textual name of a group
4896 relocation as may appear in assembler source, attempt to find its details
4897 in group_reloc_table. The pointer will be updated to the character after
4898 the trailing colon. On failure, FAIL will be returned; SUCCESS
4899 otherwise. On success, *entry will be updated to point at the relevant
4900 group_reloc_table entry. */
4901
4902static int
4903find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4904{
4905 unsigned int i;
4906 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4907 {
4908 int length = strlen (group_reloc_table[i].name);
4909
5f4273c7
NC
4910 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4911 && (*str)[length] == ':')
4962c51a
MS
4912 {
4913 *out = &group_reloc_table[i];
4914 *str += (length + 1);
4915 return SUCCESS;
4916 }
4917 }
4918
4919 return FAIL;
4920}
4921
4922/* Parse a <shifter_operand> for an ARM data processing instruction
4923 (as for parse_shifter_operand) where group relocations are allowed:
4924
4925 #<immediate>
4926 #<immediate>, <rotate>
4927 #:<group_reloc>:<expression>
4928 <Rm>
4929 <Rm>, <shift>
4930
4931 where <group_reloc> is one of the strings defined in group_reloc_table.
4932 The hashes are optional.
4933
4934 Everything else is as for parse_shifter_operand. */
4935
4936static parse_operand_result
4937parse_shifter_operand_group_reloc (char **str, int i)
4938{
4939 /* Determine if we have the sequence of characters #: or just :
4940 coming next. If we do, then we check for a group relocation.
4941 If we don't, punt the whole lot to parse_shifter_operand. */
4942
4943 if (((*str)[0] == '#' && (*str)[1] == ':')
4944 || (*str)[0] == ':')
4945 {
4946 struct group_reloc_table_entry *entry;
4947
4948 if ((*str)[0] == '#')
4949 (*str) += 2;
4950 else
4951 (*str)++;
4952
4953 /* Try to parse a group relocation. Anything else is an error. */
4954 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4955 {
4956 inst.error = _("unknown group relocation");
4957 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4958 }
4959
4960 /* We now have the group relocation table entry corresponding to
4961 the name in the assembler source. Next, we parse the expression. */
4962 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4963 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4964
4965 /* Record the relocation type (always the ALU variant here). */
21d799b5 4966 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 4967 gas_assert (inst.reloc.type != 0);
4962c51a
MS
4968
4969 return PARSE_OPERAND_SUCCESS;
4970 }
4971 else
4972 return parse_shifter_operand (str, i) == SUCCESS
4973 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4974
4975 /* Never reached. */
4976}
4977
8e560766
MGD
4978/* Parse a Neon alignment expression. Information is written to
4979 inst.operands[i]. We assume the initial ':' has been skipped.
4980
4981 align .imm = align << 8, .immisalign=1, .preind=0 */
4982static parse_operand_result
4983parse_neon_alignment (char **str, int i)
4984{
4985 char *p = *str;
4986 expressionS exp;
4987
4988 my_get_expression (&exp, &p, GE_NO_PREFIX);
4989
4990 if (exp.X_op != O_constant)
4991 {
4992 inst.error = _("alignment must be constant");
4993 return PARSE_OPERAND_FAIL;
4994 }
4995
4996 inst.operands[i].imm = exp.X_add_number << 8;
4997 inst.operands[i].immisalign = 1;
4998 /* Alignments are not pre-indexes. */
4999 inst.operands[i].preind = 0;
5000
5001 *str = p;
5002 return PARSE_OPERAND_SUCCESS;
5003}
5004
c19d1205
ZW
5005/* Parse all forms of an ARM address expression. Information is written
5006 to inst.operands[i] and/or inst.reloc.
09d92015 5007
c19d1205 5008 Preindexed addressing (.preind=1):
09d92015 5009
c19d1205
ZW
5010 [Rn, #offset] .reg=Rn .reloc.exp=offset
5011 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5012 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5013 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5014
c19d1205 5015 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5016
c19d1205 5017 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5018
c19d1205
ZW
5019 [Rn], #offset .reg=Rn .reloc.exp=offset
5020 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5021 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5022 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5023
c19d1205 5024 Unindexed addressing (.preind=0, .postind=0):
09d92015 5025
c19d1205 5026 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5027
c19d1205 5028 Other:
09d92015 5029
c19d1205
ZW
5030 [Rn]{!} shorthand for [Rn,#0]{!}
5031 =immediate .isreg=0 .reloc.exp=immediate
5032 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5033
c19d1205
ZW
5034 It is the caller's responsibility to check for addressing modes not
5035 supported by the instruction, and to set inst.reloc.type. */
5036
4962c51a
MS
5037static parse_operand_result
5038parse_address_main (char **str, int i, int group_relocations,
5039 group_reloc_type group_type)
09d92015 5040{
c19d1205
ZW
5041 char *p = *str;
5042 int reg;
09d92015 5043
c19d1205 5044 if (skip_past_char (&p, '[') == FAIL)
09d92015 5045 {
c19d1205
ZW
5046 if (skip_past_char (&p, '=') == FAIL)
5047 {
974da60d 5048 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5049 inst.reloc.pc_rel = 1;
5050 inst.operands[i].reg = REG_PC;
5051 inst.operands[i].isreg = 1;
5052 inst.operands[i].preind = 1;
5053 }
974da60d 5054 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
09d92015 5055
c19d1205 5056 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 5057 return PARSE_OPERAND_FAIL;
09d92015 5058
c19d1205 5059 *str = p;
4962c51a 5060 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5061 }
5062
dcbf9037 5063 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5064 {
c19d1205 5065 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5066 return PARSE_OPERAND_FAIL;
09d92015 5067 }
c19d1205
ZW
5068 inst.operands[i].reg = reg;
5069 inst.operands[i].isreg = 1;
09d92015 5070
c19d1205 5071 if (skip_past_comma (&p) == SUCCESS)
09d92015 5072 {
c19d1205 5073 inst.operands[i].preind = 1;
09d92015 5074
c19d1205
ZW
5075 if (*p == '+') p++;
5076 else if (*p == '-') p++, inst.operands[i].negative = 1;
5077
dcbf9037 5078 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5079 {
c19d1205
ZW
5080 inst.operands[i].imm = reg;
5081 inst.operands[i].immisreg = 1;
5082
5083 if (skip_past_comma (&p) == SUCCESS)
5084 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5085 return PARSE_OPERAND_FAIL;
c19d1205 5086 }
5287ad62 5087 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5088 {
5089 /* FIXME: '@' should be used here, but it's filtered out by generic
5090 code before we get to see it here. This may be subject to
5091 change. */
5092 parse_operand_result result = parse_neon_alignment (&p, i);
5093
5094 if (result != PARSE_OPERAND_SUCCESS)
5095 return result;
5096 }
c19d1205
ZW
5097 else
5098 {
5099 if (inst.operands[i].negative)
5100 {
5101 inst.operands[i].negative = 0;
5102 p--;
5103 }
4962c51a 5104
5f4273c7
NC
5105 if (group_relocations
5106 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5107 {
5108 struct group_reloc_table_entry *entry;
5109
5110 /* Skip over the #: or : sequence. */
5111 if (*p == '#')
5112 p += 2;
5113 else
5114 p++;
5115
5116 /* Try to parse a group relocation. Anything else is an
5117 error. */
5118 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5119 {
5120 inst.error = _("unknown group relocation");
5121 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5122 }
5123
5124 /* We now have the group relocation table entry corresponding to
5125 the name in the assembler source. Next, we parse the
5126 expression. */
5127 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5128 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5129
5130 /* Record the relocation type. */
5131 switch (group_type)
5132 {
5133 case GROUP_LDR:
21d799b5 5134 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
4962c51a
MS
5135 break;
5136
5137 case GROUP_LDRS:
21d799b5 5138 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
4962c51a
MS
5139 break;
5140
5141 case GROUP_LDC:
21d799b5 5142 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
4962c51a
MS
5143 break;
5144
5145 default:
9c2799c2 5146 gas_assert (0);
4962c51a
MS
5147 }
5148
5149 if (inst.reloc.type == 0)
5150 {
5151 inst.error = _("this group relocation is not allowed on this instruction");
5152 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5153 }
5154 }
5155 else
5156 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5157 return PARSE_OPERAND_FAIL;
09d92015
MM
5158 }
5159 }
8e560766
MGD
5160 else if (skip_past_char (&p, ':') == SUCCESS)
5161 {
5162 /* FIXME: '@' should be used here, but it's filtered out by generic code
5163 before we get to see it here. This may be subject to change. */
5164 parse_operand_result result = parse_neon_alignment (&p, i);
5165
5166 if (result != PARSE_OPERAND_SUCCESS)
5167 return result;
5168 }
09d92015 5169
c19d1205 5170 if (skip_past_char (&p, ']') == FAIL)
09d92015 5171 {
c19d1205 5172 inst.error = _("']' expected");
4962c51a 5173 return PARSE_OPERAND_FAIL;
09d92015
MM
5174 }
5175
c19d1205
ZW
5176 if (skip_past_char (&p, '!') == SUCCESS)
5177 inst.operands[i].writeback = 1;
09d92015 5178
c19d1205 5179 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5180 {
c19d1205
ZW
5181 if (skip_past_char (&p, '{') == SUCCESS)
5182 {
5183 /* [Rn], {expr} - unindexed, with option */
5184 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5185 0, 255, TRUE) == FAIL)
4962c51a 5186 return PARSE_OPERAND_FAIL;
09d92015 5187
c19d1205
ZW
5188 if (skip_past_char (&p, '}') == FAIL)
5189 {
5190 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5191 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5192 }
5193 if (inst.operands[i].preind)
5194 {
5195 inst.error = _("cannot combine index with option");
4962c51a 5196 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5197 }
5198 *str = p;
4962c51a 5199 return PARSE_OPERAND_SUCCESS;
09d92015 5200 }
c19d1205
ZW
5201 else
5202 {
5203 inst.operands[i].postind = 1;
5204 inst.operands[i].writeback = 1;
09d92015 5205
c19d1205
ZW
5206 if (inst.operands[i].preind)
5207 {
5208 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5209 return PARSE_OPERAND_FAIL;
c19d1205 5210 }
09d92015 5211
c19d1205
ZW
5212 if (*p == '+') p++;
5213 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5214
dcbf9037 5215 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5216 {
5287ad62
JB
5217 /* We might be using the immediate for alignment already. If we
5218 are, OR the register number into the low-order bits. */
5219 if (inst.operands[i].immisalign)
5220 inst.operands[i].imm |= reg;
5221 else
5222 inst.operands[i].imm = reg;
c19d1205 5223 inst.operands[i].immisreg = 1;
a737bd4d 5224
c19d1205
ZW
5225 if (skip_past_comma (&p) == SUCCESS)
5226 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5227 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5228 }
5229 else
5230 {
5231 if (inst.operands[i].negative)
5232 {
5233 inst.operands[i].negative = 0;
5234 p--;
5235 }
5236 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5237 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5238 }
5239 }
a737bd4d
NC
5240 }
5241
c19d1205
ZW
5242 /* If at this point neither .preind nor .postind is set, we have a
5243 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5244 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5245 {
5246 inst.operands[i].preind = 1;
5247 inst.reloc.exp.X_op = O_constant;
5248 inst.reloc.exp.X_add_number = 0;
5249 }
5250 *str = p;
4962c51a
MS
5251 return PARSE_OPERAND_SUCCESS;
5252}
5253
5254static int
5255parse_address (char **str, int i)
5256{
21d799b5 5257 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
4962c51a
MS
5258 ? SUCCESS : FAIL;
5259}
5260
5261static parse_operand_result
5262parse_address_group_reloc (char **str, int i, group_reloc_type type)
5263{
5264 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5265}
5266
b6895b4f
PB
5267/* Parse an operand for a MOVW or MOVT instruction. */
5268static int
5269parse_half (char **str)
5270{
5271 char * p;
5f4273c7 5272
b6895b4f
PB
5273 p = *str;
5274 skip_past_char (&p, '#');
5f4273c7 5275 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5276 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5277 else if (strncasecmp (p, ":upper16:", 9) == 0)
5278 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5279
5280 if (inst.reloc.type != BFD_RELOC_UNUSED)
5281 {
5282 p += 9;
5f4273c7 5283 skip_whitespace (p);
b6895b4f
PB
5284 }
5285
5286 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5287 return FAIL;
5288
5289 if (inst.reloc.type == BFD_RELOC_UNUSED)
5290 {
5291 if (inst.reloc.exp.X_op != O_constant)
5292 {
5293 inst.error = _("constant expression expected");
5294 return FAIL;
5295 }
5296 if (inst.reloc.exp.X_add_number < 0
5297 || inst.reloc.exp.X_add_number > 0xffff)
5298 {
5299 inst.error = _("immediate value out of range");
5300 return FAIL;
5301 }
5302 }
5303 *str = p;
5304 return SUCCESS;
5305}
5306
c19d1205 5307/* Miscellaneous. */
a737bd4d 5308
c19d1205
ZW
5309/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5310 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5311static int
5312parse_psr (char **str)
09d92015 5313{
c19d1205
ZW
5314 char *p;
5315 unsigned long psr_field;
62b3e311
PB
5316 const struct asm_psr *psr;
5317 char *start;
09d92015 5318
c19d1205
ZW
5319 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5320 feature for ease of use and backwards compatibility. */
5321 p = *str;
62b3e311 5322 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 5323 psr_field = SPSR_BIT;
59b42a0d
MGD
5324 else if (strncasecmp (p, "CPSR", 4) == 0
5325 || (strncasecmp (p, "APSR", 4) == 0
5326 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)))
c19d1205
ZW
5327 psr_field = 0;
5328 else
62b3e311
PB
5329 {
5330 start = p;
5331 do
5332 p++;
5333 while (ISALNUM (*p) || *p == '_');
5334
21d799b5
NC
5335 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5336 p - start);
62b3e311
PB
5337 if (!psr)
5338 return FAIL;
09d92015 5339
62b3e311
PB
5340 *str = p;
5341 return psr->field;
5342 }
09d92015 5343
62b3e311 5344 p += 4;
c19d1205
ZW
5345 if (*p == '_')
5346 {
5347 /* A suffix follows. */
c19d1205
ZW
5348 p++;
5349 start = p;
a737bd4d 5350
c19d1205
ZW
5351 do
5352 p++;
5353 while (ISALNUM (*p) || *p == '_');
a737bd4d 5354
21d799b5
NC
5355 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5356 p - start);
c19d1205
ZW
5357 if (!psr)
5358 goto error;
a737bd4d 5359
c19d1205 5360 psr_field |= psr->field;
a737bd4d 5361 }
c19d1205 5362 else
a737bd4d 5363 {
c19d1205
ZW
5364 if (ISALNUM (*p))
5365 goto error; /* Garbage after "[CS]PSR". */
5366
5367 psr_field |= (PSR_c | PSR_f);
a737bd4d 5368 }
c19d1205
ZW
5369 *str = p;
5370 return psr_field;
a737bd4d 5371
c19d1205
ZW
5372 error:
5373 inst.error = _("flag for {c}psr instruction expected");
5374 return FAIL;
a737bd4d
NC
5375}
5376
c19d1205
ZW
5377/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5378 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5379
c19d1205
ZW
5380static int
5381parse_cps_flags (char **str)
a737bd4d 5382{
c19d1205
ZW
5383 int val = 0;
5384 int saw_a_flag = 0;
5385 char *s = *str;
a737bd4d 5386
c19d1205
ZW
5387 for (;;)
5388 switch (*s++)
5389 {
5390 case '\0': case ',':
5391 goto done;
a737bd4d 5392
c19d1205
ZW
5393 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5394 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5395 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5396
c19d1205
ZW
5397 default:
5398 inst.error = _("unrecognized CPS flag");
5399 return FAIL;
5400 }
a737bd4d 5401
c19d1205
ZW
5402 done:
5403 if (saw_a_flag == 0)
a737bd4d 5404 {
c19d1205
ZW
5405 inst.error = _("missing CPS flags");
5406 return FAIL;
a737bd4d 5407 }
a737bd4d 5408
c19d1205
ZW
5409 *str = s - 1;
5410 return val;
a737bd4d
NC
5411}
5412
c19d1205
ZW
5413/* Parse an endian specifier ("BE" or "LE", case insensitive);
5414 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5415
5416static int
c19d1205 5417parse_endian_specifier (char **str)
a737bd4d 5418{
c19d1205
ZW
5419 int little_endian;
5420 char *s = *str;
a737bd4d 5421
c19d1205
ZW
5422 if (strncasecmp (s, "BE", 2))
5423 little_endian = 0;
5424 else if (strncasecmp (s, "LE", 2))
5425 little_endian = 1;
5426 else
a737bd4d 5427 {
c19d1205 5428 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5429 return FAIL;
5430 }
5431
c19d1205 5432 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5433 {
c19d1205 5434 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5435 return FAIL;
5436 }
5437
c19d1205
ZW
5438 *str = s + 2;
5439 return little_endian;
5440}
a737bd4d 5441
c19d1205
ZW
5442/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5443 value suitable for poking into the rotate field of an sxt or sxta
5444 instruction, or FAIL on error. */
5445
5446static int
5447parse_ror (char **str)
5448{
5449 int rot;
5450 char *s = *str;
5451
5452 if (strncasecmp (s, "ROR", 3) == 0)
5453 s += 3;
5454 else
a737bd4d 5455 {
c19d1205 5456 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5457 return FAIL;
5458 }
c19d1205
ZW
5459
5460 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5461 return FAIL;
5462
5463 switch (rot)
a737bd4d 5464 {
c19d1205
ZW
5465 case 0: *str = s; return 0x0;
5466 case 8: *str = s; return 0x1;
5467 case 16: *str = s; return 0x2;
5468 case 24: *str = s; return 0x3;
5469
5470 default:
5471 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5472 return FAIL;
5473 }
c19d1205 5474}
a737bd4d 5475
c19d1205
ZW
5476/* Parse a conditional code (from conds[] below). The value returned is in the
5477 range 0 .. 14, or FAIL. */
5478static int
5479parse_cond (char **str)
5480{
c462b453 5481 char *q;
c19d1205 5482 const struct asm_cond *c;
c462b453
PB
5483 int n;
5484 /* Condition codes are always 2 characters, so matching up to
5485 3 characters is sufficient. */
5486 char cond[3];
a737bd4d 5487
c462b453
PB
5488 q = *str;
5489 n = 0;
5490 while (ISALPHA (*q) && n < 3)
5491 {
e07e6e58 5492 cond[n] = TOLOWER (*q);
c462b453
PB
5493 q++;
5494 n++;
5495 }
a737bd4d 5496
21d799b5 5497 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5498 if (!c)
a737bd4d 5499 {
c19d1205 5500 inst.error = _("condition required");
a737bd4d
NC
5501 return FAIL;
5502 }
5503
c19d1205
ZW
5504 *str = q;
5505 return c->value;
5506}
5507
62b3e311
PB
5508/* Parse an option for a barrier instruction. Returns the encoding for the
5509 option, or FAIL. */
5510static int
5511parse_barrier (char **str)
5512{
5513 char *p, *q;
5514 const struct asm_barrier_opt *o;
5515
5516 p = q = *str;
5517 while (ISALPHA (*q))
5518 q++;
5519
21d799b5
NC
5520 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5521 q - p);
62b3e311
PB
5522 if (!o)
5523 return FAIL;
5524
5525 *str = q;
5526 return o->value;
5527}
5528
92e90b6e
PB
5529/* Parse the operands of a table branch instruction. Similar to a memory
5530 operand. */
5531static int
5532parse_tb (char **str)
5533{
5534 char * p = *str;
5535 int reg;
5536
5537 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5538 {
5539 inst.error = _("'[' expected");
5540 return FAIL;
5541 }
92e90b6e 5542
dcbf9037 5543 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5544 {
5545 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5546 return FAIL;
5547 }
5548 inst.operands[0].reg = reg;
5549
5550 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5551 {
5552 inst.error = _("',' expected");
5553 return FAIL;
5554 }
5f4273c7 5555
dcbf9037 5556 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5557 {
5558 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5559 return FAIL;
5560 }
5561 inst.operands[0].imm = reg;
5562
5563 if (skip_past_comma (&p) == SUCCESS)
5564 {
5565 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5566 return FAIL;
5567 if (inst.reloc.exp.X_add_number != 1)
5568 {
5569 inst.error = _("invalid shift");
5570 return FAIL;
5571 }
5572 inst.operands[0].shifted = 1;
5573 }
5574
5575 if (skip_past_char (&p, ']') == FAIL)
5576 {
5577 inst.error = _("']' expected");
5578 return FAIL;
5579 }
5580 *str = p;
5581 return SUCCESS;
5582}
5583
5287ad62
JB
5584/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5585 information on the types the operands can take and how they are encoded.
037e8744
JB
5586 Up to four operands may be read; this function handles setting the
5587 ".present" field for each read operand itself.
5287ad62
JB
5588 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5589 else returns FAIL. */
5590
5591static int
5592parse_neon_mov (char **str, int *which_operand)
5593{
5594 int i = *which_operand, val;
5595 enum arm_reg_type rtype;
5596 char *ptr = *str;
dcbf9037 5597 struct neon_type_el optype;
5f4273c7 5598
dcbf9037 5599 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5600 {
5601 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5602 inst.operands[i].reg = val;
5603 inst.operands[i].isscalar = 1;
dcbf9037 5604 inst.operands[i].vectype = optype;
5287ad62
JB
5605 inst.operands[i++].present = 1;
5606
5607 if (skip_past_comma (&ptr) == FAIL)
5608 goto wanted_comma;
5f4273c7 5609
dcbf9037 5610 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5611 goto wanted_arm;
5f4273c7 5612
5287ad62
JB
5613 inst.operands[i].reg = val;
5614 inst.operands[i].isreg = 1;
5615 inst.operands[i].present = 1;
5616 }
037e8744 5617 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5618 != FAIL)
5287ad62
JB
5619 {
5620 /* Cases 0, 1, 2, 3, 5 (D only). */
5621 if (skip_past_comma (&ptr) == FAIL)
5622 goto wanted_comma;
5f4273c7 5623
5287ad62
JB
5624 inst.operands[i].reg = val;
5625 inst.operands[i].isreg = 1;
5626 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5627 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5628 inst.operands[i].isvec = 1;
dcbf9037 5629 inst.operands[i].vectype = optype;
5287ad62
JB
5630 inst.operands[i++].present = 1;
5631
dcbf9037 5632 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5633 {
037e8744
JB
5634 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5635 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5636 inst.operands[i].reg = val;
5637 inst.operands[i].isreg = 1;
037e8744 5638 inst.operands[i].present = 1;
5287ad62
JB
5639
5640 if (rtype == REG_TYPE_NQ)
5641 {
dcbf9037 5642 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5643 return FAIL;
5644 }
037e8744
JB
5645 else if (rtype != REG_TYPE_VFS)
5646 {
5647 i++;
5648 if (skip_past_comma (&ptr) == FAIL)
5649 goto wanted_comma;
5650 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5651 goto wanted_arm;
5652 inst.operands[i].reg = val;
5653 inst.operands[i].isreg = 1;
5654 inst.operands[i].present = 1;
5655 }
5287ad62 5656 }
037e8744
JB
5657 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5658 &optype)) != FAIL)
5287ad62
JB
5659 {
5660 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5661 Case 1: VMOV<c><q> <Dd>, <Dm>
5662 Case 8: VMOV.F32 <Sd>, <Sm>
5663 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5664
5665 inst.operands[i].reg = val;
5666 inst.operands[i].isreg = 1;
5667 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5668 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5669 inst.operands[i].isvec = 1;
dcbf9037 5670 inst.operands[i].vectype = optype;
5287ad62 5671 inst.operands[i].present = 1;
5f4273c7 5672
037e8744
JB
5673 if (skip_past_comma (&ptr) == SUCCESS)
5674 {
5675 /* Case 15. */
5676 i++;
5677
5678 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5679 goto wanted_arm;
5680
5681 inst.operands[i].reg = val;
5682 inst.operands[i].isreg = 1;
5683 inst.operands[i++].present = 1;
5f4273c7 5684
037e8744
JB
5685 if (skip_past_comma (&ptr) == FAIL)
5686 goto wanted_comma;
5f4273c7 5687
037e8744
JB
5688 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5689 goto wanted_arm;
5f4273c7 5690
037e8744
JB
5691 inst.operands[i].reg = val;
5692 inst.operands[i].isreg = 1;
5693 inst.operands[i++].present = 1;
5694 }
5287ad62 5695 }
4641781c
PB
5696 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5697 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5698 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5699 Case 10: VMOV.F32 <Sd>, #<imm>
5700 Case 11: VMOV.F64 <Dd>, #<imm> */
5701 inst.operands[i].immisfloat = 1;
5702 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5703 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5704 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5705 ;
5287ad62
JB
5706 else
5707 {
dcbf9037 5708 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5709 return FAIL;
5710 }
5711 }
dcbf9037 5712 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5713 {
5714 /* Cases 6, 7. */
5715 inst.operands[i].reg = val;
5716 inst.operands[i].isreg = 1;
5717 inst.operands[i++].present = 1;
5f4273c7 5718
5287ad62
JB
5719 if (skip_past_comma (&ptr) == FAIL)
5720 goto wanted_comma;
5f4273c7 5721
dcbf9037 5722 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5723 {
5724 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5725 inst.operands[i].reg = val;
5726 inst.operands[i].isscalar = 1;
5727 inst.operands[i].present = 1;
dcbf9037 5728 inst.operands[i].vectype = optype;
5287ad62 5729 }
dcbf9037 5730 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5731 {
5732 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5733 inst.operands[i].reg = val;
5734 inst.operands[i].isreg = 1;
5735 inst.operands[i++].present = 1;
5f4273c7 5736
5287ad62
JB
5737 if (skip_past_comma (&ptr) == FAIL)
5738 goto wanted_comma;
5f4273c7 5739
037e8744 5740 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5741 == FAIL)
5287ad62 5742 {
037e8744 5743 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5744 return FAIL;
5745 }
5746
5747 inst.operands[i].reg = val;
5748 inst.operands[i].isreg = 1;
037e8744
JB
5749 inst.operands[i].isvec = 1;
5750 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5751 inst.operands[i].vectype = optype;
5287ad62 5752 inst.operands[i].present = 1;
5f4273c7 5753
037e8744
JB
5754 if (rtype == REG_TYPE_VFS)
5755 {
5756 /* Case 14. */
5757 i++;
5758 if (skip_past_comma (&ptr) == FAIL)
5759 goto wanted_comma;
5760 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5761 &optype)) == FAIL)
5762 {
5763 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5764 return FAIL;
5765 }
5766 inst.operands[i].reg = val;
5767 inst.operands[i].isreg = 1;
5768 inst.operands[i].isvec = 1;
5769 inst.operands[i].issingle = 1;
5770 inst.operands[i].vectype = optype;
5771 inst.operands[i].present = 1;
5772 }
5773 }
5774 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5775 != FAIL)
5776 {
5777 /* Case 13. */
5778 inst.operands[i].reg = val;
5779 inst.operands[i].isreg = 1;
5780 inst.operands[i].isvec = 1;
5781 inst.operands[i].issingle = 1;
5782 inst.operands[i].vectype = optype;
5783 inst.operands[i++].present = 1;
5287ad62
JB
5784 }
5785 }
5786 else
5787 {
dcbf9037 5788 first_error (_("parse error"));
5287ad62
JB
5789 return FAIL;
5790 }
5791
5792 /* Successfully parsed the operands. Update args. */
5793 *which_operand = i;
5794 *str = ptr;
5795 return SUCCESS;
5796
5f4273c7 5797 wanted_comma:
dcbf9037 5798 first_error (_("expected comma"));
5287ad62 5799 return FAIL;
5f4273c7
NC
5800
5801 wanted_arm:
dcbf9037 5802 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5803 return FAIL;
5287ad62
JB
5804}
5805
5be8be5d
DG
5806/* Use this macro when the operand constraints are different
5807 for ARM and THUMB (e.g. ldrd). */
5808#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
5809 ((arm_operand) | ((thumb_operand) << 16))
5810
c19d1205
ZW
5811/* Matcher codes for parse_operands. */
5812enum operand_parse_code
5813{
5814 OP_stop, /* end of line */
5815
5816 OP_RR, /* ARM register */
5817 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 5818 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 5819 OP_RRnpcb, /* ARM register, not r15, in square brackets */
55881a11
MGD
5820 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
5821 optional trailing ! */
c19d1205
ZW
5822 OP_RRw, /* ARM register, not r15, optional trailing ! */
5823 OP_RCP, /* Coprocessor number */
5824 OP_RCN, /* Coprocessor register */
5825 OP_RF, /* FPA register */
5826 OP_RVS, /* VFP single precision register */
5287ad62
JB
5827 OP_RVD, /* VFP double precision register (0..15) */
5828 OP_RND, /* Neon double precision register (0..31) */
5829 OP_RNQ, /* Neon quad precision register */
037e8744 5830 OP_RVSD, /* VFP single or double precision register */
5287ad62 5831 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5832 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5833 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5834 OP_RVC, /* VFP control register */
5835 OP_RMF, /* Maverick F register */
5836 OP_RMD, /* Maverick D register */
5837 OP_RMFX, /* Maverick FX register */
5838 OP_RMDX, /* Maverick DX register */
5839 OP_RMAX, /* Maverick AX register */
5840 OP_RMDS, /* Maverick DSPSC register */
5841 OP_RIWR, /* iWMMXt wR register */
5842 OP_RIWC, /* iWMMXt wC register */
5843 OP_RIWG, /* iWMMXt wCG register */
5844 OP_RXA, /* XScale accumulator register */
5845
5846 OP_REGLST, /* ARM register list */
5847 OP_VRSLST, /* VFP single-precision register list */
5848 OP_VRDLST, /* VFP double-precision register list */
037e8744 5849 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5850 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5851 OP_NSTRLST, /* Neon element/structure list */
5852
5287ad62 5853 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5854 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5855 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5856 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5857 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5858 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5859 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 5860 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 5861 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5862 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5863
5864 OP_I0, /* immediate zero */
c19d1205
ZW
5865 OP_I7, /* immediate value 0 .. 7 */
5866 OP_I15, /* 0 .. 15 */
5867 OP_I16, /* 1 .. 16 */
5287ad62 5868 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5869 OP_I31, /* 0 .. 31 */
5870 OP_I31w, /* 0 .. 31, optional trailing ! */
5871 OP_I32, /* 1 .. 32 */
5287ad62
JB
5872 OP_I32z, /* 0 .. 32 */
5873 OP_I63, /* 0 .. 63 */
c19d1205 5874 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5875 OP_I64, /* 1 .. 64 */
5876 OP_I64z, /* 0 .. 64 */
c19d1205 5877 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5878
5879 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5880 OP_I7b, /* 0 .. 7 */
5881 OP_I15b, /* 0 .. 15 */
5882 OP_I31b, /* 0 .. 31 */
5883
5884 OP_SH, /* shifter operand */
4962c51a 5885 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5886 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5887 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5888 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5889 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5890 OP_EXP, /* arbitrary expression */
5891 OP_EXPi, /* same, with optional immediate prefix */
5892 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5893 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5894
5895 OP_CPSF, /* CPS flags */
5896 OP_ENDI, /* Endianness specifier */
5897 OP_PSR, /* CPSR/SPSR mask for msr */
5898 OP_COND, /* conditional code */
92e90b6e 5899 OP_TB, /* Table branch. */
c19d1205 5900
037e8744
JB
5901 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5902 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5903
c19d1205
ZW
5904 OP_RRnpc_I0, /* ARM register or literal 0 */
5905 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5906 OP_RR_EXi, /* ARM register or expression with imm prefix */
5907 OP_RF_IF, /* FPA register or immediate */
5908 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5909 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5910
5911 /* Optional operands. */
5912 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5913 OP_oI31b, /* 0 .. 31 */
5287ad62 5914 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5915 OP_oIffffb, /* 0 .. 65535 */
5916 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5917
5918 OP_oRR, /* ARM register */
5919 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 5920 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 5921 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5922 OP_oRND, /* Optional Neon double precision register */
5923 OP_oRNQ, /* Optional Neon quad precision register */
5924 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5925 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5926 OP_oSHll, /* LSL immediate */
5927 OP_oSHar, /* ASR immediate */
5928 OP_oSHllar, /* LSL or ASR immediate */
5929 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 5930 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 5931
5be8be5d
DG
5932 /* Some pre-defined mixed (ARM/THUMB) operands. */
5933 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
5934 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
5935 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
5936
c19d1205
ZW
5937 OP_FIRST_OPTIONAL = OP_oI7b
5938};
a737bd4d 5939
c19d1205
ZW
5940/* Generic instruction operand parser. This does no encoding and no
5941 semantic validation; it merely squirrels values away in the inst
5942 structure. Returns SUCCESS or FAIL depending on whether the
5943 specified grammar matched. */
5944static int
5be8be5d 5945parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 5946{
5be8be5d 5947 unsigned const int *upat = pattern;
c19d1205
ZW
5948 char *backtrack_pos = 0;
5949 const char *backtrack_error = 0;
5950 int i, val, backtrack_index = 0;
5287ad62 5951 enum arm_reg_type rtype;
4962c51a 5952 parse_operand_result result;
5be8be5d 5953 unsigned int op_parse_code;
c19d1205 5954
e07e6e58
NC
5955#define po_char_or_fail(chr) \
5956 do \
5957 { \
5958 if (skip_past_char (&str, chr) == FAIL) \
5959 goto bad_args; \
5960 } \
5961 while (0)
c19d1205 5962
e07e6e58
NC
5963#define po_reg_or_fail(regtype) \
5964 do \
dcbf9037 5965 { \
e07e6e58
NC
5966 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5967 & inst.operands[i].vectype); \
5968 if (val == FAIL) \
5969 { \
5970 first_error (_(reg_expected_msgs[regtype])); \
5971 goto failure; \
5972 } \
5973 inst.operands[i].reg = val; \
5974 inst.operands[i].isreg = 1; \
5975 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5976 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5977 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5978 || rtype == REG_TYPE_VFD \
5979 || rtype == REG_TYPE_NQ); \
dcbf9037 5980 } \
e07e6e58
NC
5981 while (0)
5982
5983#define po_reg_or_goto(regtype, label) \
5984 do \
5985 { \
5986 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5987 & inst.operands[i].vectype); \
5988 if (val == FAIL) \
5989 goto label; \
dcbf9037 5990 \
e07e6e58
NC
5991 inst.operands[i].reg = val; \
5992 inst.operands[i].isreg = 1; \
5993 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5994 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5995 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5996 || rtype == REG_TYPE_VFD \
5997 || rtype == REG_TYPE_NQ); \
5998 } \
5999 while (0)
6000
6001#define po_imm_or_fail(min, max, popt) \
6002 do \
6003 { \
6004 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6005 goto failure; \
6006 inst.operands[i].imm = val; \
6007 } \
6008 while (0)
6009
6010#define po_scalar_or_goto(elsz, label) \
6011 do \
6012 { \
6013 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6014 if (val == FAIL) \
6015 goto label; \
6016 inst.operands[i].reg = val; \
6017 inst.operands[i].isscalar = 1; \
6018 } \
6019 while (0)
6020
6021#define po_misc_or_fail(expr) \
6022 do \
6023 { \
6024 if (expr) \
6025 goto failure; \
6026 } \
6027 while (0)
6028
6029#define po_misc_or_fail_no_backtrack(expr) \
6030 do \
6031 { \
6032 result = expr; \
6033 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6034 backtrack_pos = 0; \
6035 if (result != PARSE_OPERAND_SUCCESS) \
6036 goto failure; \
6037 } \
6038 while (0)
4962c51a 6039
52e7f43d
RE
6040#define po_barrier_or_imm(str) \
6041 do \
6042 { \
6043 val = parse_barrier (&str); \
6044 if (val == FAIL) \
6045 { \
6046 if (ISALPHA (*str)) \
6047 goto failure; \
6048 else \
6049 goto immediate; \
6050 } \
6051 else \
6052 { \
6053 if ((inst.instruction & 0xf0) == 0x60 \
6054 && val != 0xf) \
6055 { \
6056 /* ISB can only take SY as an option. */ \
6057 inst.error = _("invalid barrier type"); \
6058 goto failure; \
6059 } \
6060 } \
6061 } \
6062 while (0)
6063
c19d1205
ZW
6064 skip_whitespace (str);
6065
6066 for (i = 0; upat[i] != OP_stop; i++)
6067 {
5be8be5d
DG
6068 op_parse_code = upat[i];
6069 if (op_parse_code >= 1<<16)
6070 op_parse_code = thumb ? (op_parse_code >> 16)
6071 : (op_parse_code & ((1<<16)-1));
6072
6073 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6074 {
6075 /* Remember where we are in case we need to backtrack. */
9c2799c2 6076 gas_assert (!backtrack_pos);
c19d1205
ZW
6077 backtrack_pos = str;
6078 backtrack_error = inst.error;
6079 backtrack_index = i;
6080 }
6081
b6702015 6082 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6083 po_char_or_fail (',');
6084
5be8be5d 6085 switch (op_parse_code)
c19d1205
ZW
6086 {
6087 /* Registers */
6088 case OP_oRRnpc:
5be8be5d 6089 case OP_oRRnpcsp:
c19d1205 6090 case OP_RRnpc:
5be8be5d 6091 case OP_RRnpcsp:
c19d1205
ZW
6092 case OP_oRR:
6093 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6094 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6095 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6096 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6097 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6098 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
6099 case OP_oRND:
6100 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6101 case OP_RVC:
6102 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6103 break;
6104 /* Also accept generic coprocessor regs for unknown registers. */
6105 coproc_reg:
6106 po_reg_or_fail (REG_TYPE_CN);
6107 break;
c19d1205
ZW
6108 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6109 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6110 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6111 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6112 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6113 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6114 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6115 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6116 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6117 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
6118 case OP_oRNQ:
6119 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6120 case OP_oRNDQ:
6121 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
6122 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6123 case OP_oRNSDQ:
6124 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
6125
6126 /* Neon scalar. Using an element size of 8 means that some invalid
6127 scalars are accepted here, so deal with those in later code. */
6128 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6129
5287ad62
JB
6130 case OP_RNDQ_I0:
6131 {
6132 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6133 break;
6134 try_imm0:
6135 po_imm_or_fail (0, 0, TRUE);
6136 }
6137 break;
6138
037e8744
JB
6139 case OP_RVSD_I0:
6140 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6141 break;
6142
5287ad62
JB
6143 case OP_RR_RNSC:
6144 {
6145 po_scalar_or_goto (8, try_rr);
6146 break;
6147 try_rr:
6148 po_reg_or_fail (REG_TYPE_RN);
6149 }
6150 break;
6151
037e8744
JB
6152 case OP_RNSDQ_RNSC:
6153 {
6154 po_scalar_or_goto (8, try_nsdq);
6155 break;
6156 try_nsdq:
6157 po_reg_or_fail (REG_TYPE_NSDQ);
6158 }
6159 break;
6160
5287ad62
JB
6161 case OP_RNDQ_RNSC:
6162 {
6163 po_scalar_or_goto (8, try_ndq);
6164 break;
6165 try_ndq:
6166 po_reg_or_fail (REG_TYPE_NDQ);
6167 }
6168 break;
6169
6170 case OP_RND_RNSC:
6171 {
6172 po_scalar_or_goto (8, try_vfd);
6173 break;
6174 try_vfd:
6175 po_reg_or_fail (REG_TYPE_VFD);
6176 }
6177 break;
6178
6179 case OP_VMOV:
6180 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6181 not careful then bad things might happen. */
6182 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6183 break;
6184
4316f0d2 6185 case OP_RNDQ_Ibig:
5287ad62 6186 {
4316f0d2 6187 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
5287ad62 6188 break;
4316f0d2 6189 try_immbig:
5287ad62
JB
6190 /* There's a possibility of getting a 64-bit immediate here, so
6191 we need special handling. */
6192 if (parse_big_immediate (&str, i) == FAIL)
6193 {
6194 inst.error = _("immediate value is out of range");
6195 goto failure;
6196 }
6197 }
6198 break;
6199
6200 case OP_RNDQ_I63b:
6201 {
6202 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6203 break;
6204 try_shimm:
6205 po_imm_or_fail (0, 63, TRUE);
6206 }
6207 break;
c19d1205
ZW
6208
6209 case OP_RRnpcb:
6210 po_char_or_fail ('[');
6211 po_reg_or_fail (REG_TYPE_RN);
6212 po_char_or_fail (']');
6213 break;
a737bd4d 6214
55881a11 6215 case OP_RRnpctw:
c19d1205 6216 case OP_RRw:
b6702015 6217 case OP_oRRw:
c19d1205
ZW
6218 po_reg_or_fail (REG_TYPE_RN);
6219 if (skip_past_char (&str, '!') == SUCCESS)
6220 inst.operands[i].writeback = 1;
6221 break;
6222
6223 /* Immediates */
6224 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6225 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6226 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 6227 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6228 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6229 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 6230 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6231 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
6232 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6233 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6234 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6235 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6236
6237 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6238 case OP_oI7b:
6239 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6240 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6241 case OP_oI31b:
6242 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 6243 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
6244 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6245
6246 /* Immediate variants */
6247 case OP_oI255c:
6248 po_char_or_fail ('{');
6249 po_imm_or_fail (0, 255, TRUE);
6250 po_char_or_fail ('}');
6251 break;
6252
6253 case OP_I31w:
6254 /* The expression parser chokes on a trailing !, so we have
6255 to find it first and zap it. */
6256 {
6257 char *s = str;
6258 while (*s && *s != ',')
6259 s++;
6260 if (s[-1] == '!')
6261 {
6262 s[-1] = '\0';
6263 inst.operands[i].writeback = 1;
6264 }
6265 po_imm_or_fail (0, 31, TRUE);
6266 if (str == s - 1)
6267 str = s;
6268 }
6269 break;
6270
6271 /* Expressions */
6272 case OP_EXPi: EXPi:
6273 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6274 GE_OPT_PREFIX));
6275 break;
6276
6277 case OP_EXP:
6278 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6279 GE_NO_PREFIX));
6280 break;
6281
6282 case OP_EXPr: EXPr:
6283 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6284 GE_NO_PREFIX));
6285 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6286 {
c19d1205
ZW
6287 val = parse_reloc (&str);
6288 if (val == -1)
6289 {
6290 inst.error = _("unrecognized relocation suffix");
6291 goto failure;
6292 }
6293 else if (val != BFD_RELOC_UNUSED)
6294 {
6295 inst.operands[i].imm = val;
6296 inst.operands[i].hasreloc = 1;
6297 }
a737bd4d 6298 }
c19d1205 6299 break;
a737bd4d 6300
b6895b4f
PB
6301 /* Operand for MOVW or MOVT. */
6302 case OP_HALF:
6303 po_misc_or_fail (parse_half (&str));
6304 break;
6305
e07e6e58 6306 /* Register or expression. */
c19d1205
ZW
6307 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6308 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6309
e07e6e58 6310 /* Register or immediate. */
c19d1205
ZW
6311 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6312 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6313
c19d1205
ZW
6314 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6315 IF:
6316 if (!is_immediate_prefix (*str))
6317 goto bad_args;
6318 str++;
6319 val = parse_fpa_immediate (&str);
6320 if (val == FAIL)
6321 goto failure;
6322 /* FPA immediates are encoded as registers 8-15.
6323 parse_fpa_immediate has already applied the offset. */
6324 inst.operands[i].reg = val;
6325 inst.operands[i].isreg = 1;
6326 break;
09d92015 6327
2d447fca
JM
6328 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6329 I32z: po_imm_or_fail (0, 32, FALSE); break;
6330
e07e6e58 6331 /* Two kinds of register. */
c19d1205
ZW
6332 case OP_RIWR_RIWC:
6333 {
6334 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6335 if (!rege
6336 || (rege->type != REG_TYPE_MMXWR
6337 && rege->type != REG_TYPE_MMXWC
6338 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6339 {
6340 inst.error = _("iWMMXt data or control register expected");
6341 goto failure;
6342 }
6343 inst.operands[i].reg = rege->number;
6344 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6345 }
6346 break;
09d92015 6347
41adaa5c
JM
6348 case OP_RIWC_RIWG:
6349 {
6350 struct reg_entry *rege = arm_reg_parse_multi (&str);
6351 if (!rege
6352 || (rege->type != REG_TYPE_MMXWC
6353 && rege->type != REG_TYPE_MMXWCG))
6354 {
6355 inst.error = _("iWMMXt control register expected");
6356 goto failure;
6357 }
6358 inst.operands[i].reg = rege->number;
6359 inst.operands[i].isreg = 1;
6360 }
6361 break;
6362
c19d1205
ZW
6363 /* Misc */
6364 case OP_CPSF: val = parse_cps_flags (&str); break;
6365 case OP_ENDI: val = parse_endian_specifier (&str); break;
6366 case OP_oROR: val = parse_ror (&str); break;
6367 case OP_PSR: val = parse_psr (&str); break;
6368 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6369 case OP_oBARRIER_I15:
6370 po_barrier_or_imm (str); break;
6371 immediate:
6372 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6373 goto failure;
6374 break;
c19d1205 6375
037e8744
JB
6376 case OP_RVC_PSR:
6377 po_reg_or_goto (REG_TYPE_VFC, try_psr);
6378 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6379 break;
6380 try_psr:
6381 val = parse_psr (&str);
6382 break;
6383
6384 case OP_APSR_RR:
6385 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6386 break;
6387 try_apsr:
6388 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6389 instruction). */
6390 if (strncasecmp (str, "APSR_", 5) == 0)
6391 {
6392 unsigned found = 0;
6393 str += 5;
6394 while (found < 15)
6395 switch (*str++)
6396 {
6397 case 'c': found = (found & 1) ? 16 : found | 1; break;
6398 case 'n': found = (found & 2) ? 16 : found | 2; break;
6399 case 'z': found = (found & 4) ? 16 : found | 4; break;
6400 case 'v': found = (found & 8) ? 16 : found | 8; break;
6401 default: found = 16;
6402 }
6403 if (found != 15)
6404 goto failure;
6405 inst.operands[i].isvec = 1;
f7c21dc7
NC
6406 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6407 inst.operands[i].reg = REG_PC;
037e8744
JB
6408 }
6409 else
6410 goto failure;
6411 break;
6412
92e90b6e
PB
6413 case OP_TB:
6414 po_misc_or_fail (parse_tb (&str));
6415 break;
6416
e07e6e58 6417 /* Register lists. */
c19d1205
ZW
6418 case OP_REGLST:
6419 val = parse_reg_list (&str);
6420 if (*str == '^')
6421 {
6422 inst.operands[1].writeback = 1;
6423 str++;
6424 }
6425 break;
09d92015 6426
c19d1205 6427 case OP_VRSLST:
5287ad62 6428 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6429 break;
09d92015 6430
c19d1205 6431 case OP_VRDLST:
5287ad62 6432 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6433 break;
a737bd4d 6434
037e8744
JB
6435 case OP_VRSDLST:
6436 /* Allow Q registers too. */
6437 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6438 REGLIST_NEON_D);
6439 if (val == FAIL)
6440 {
6441 inst.error = NULL;
6442 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6443 REGLIST_VFP_S);
6444 inst.operands[i].issingle = 1;
6445 }
6446 break;
6447
5287ad62
JB
6448 case OP_NRDLST:
6449 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6450 REGLIST_NEON_D);
6451 break;
6452
6453 case OP_NSTRLST:
dcbf9037
JB
6454 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6455 &inst.operands[i].vectype);
5287ad62
JB
6456 break;
6457
c19d1205
ZW
6458 /* Addressing modes */
6459 case OP_ADDR:
6460 po_misc_or_fail (parse_address (&str, i));
6461 break;
09d92015 6462
4962c51a
MS
6463 case OP_ADDRGLDR:
6464 po_misc_or_fail_no_backtrack (
6465 parse_address_group_reloc (&str, i, GROUP_LDR));
6466 break;
6467
6468 case OP_ADDRGLDRS:
6469 po_misc_or_fail_no_backtrack (
6470 parse_address_group_reloc (&str, i, GROUP_LDRS));
6471 break;
6472
6473 case OP_ADDRGLDC:
6474 po_misc_or_fail_no_backtrack (
6475 parse_address_group_reloc (&str, i, GROUP_LDC));
6476 break;
6477
c19d1205
ZW
6478 case OP_SH:
6479 po_misc_or_fail (parse_shifter_operand (&str, i));
6480 break;
09d92015 6481
4962c51a
MS
6482 case OP_SHG:
6483 po_misc_or_fail_no_backtrack (
6484 parse_shifter_operand_group_reloc (&str, i));
6485 break;
6486
c19d1205
ZW
6487 case OP_oSHll:
6488 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6489 break;
09d92015 6490
c19d1205
ZW
6491 case OP_oSHar:
6492 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6493 break;
09d92015 6494
c19d1205
ZW
6495 case OP_oSHllar:
6496 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6497 break;
09d92015 6498
c19d1205 6499 default:
5be8be5d 6500 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 6501 }
09d92015 6502
c19d1205
ZW
6503 /* Various value-based sanity checks and shared operations. We
6504 do not signal immediate failures for the register constraints;
6505 this allows a syntax error to take precedence. */
5be8be5d 6506 switch (op_parse_code)
c19d1205
ZW
6507 {
6508 case OP_oRRnpc:
6509 case OP_RRnpc:
6510 case OP_RRnpcb:
6511 case OP_RRw:
b6702015 6512 case OP_oRRw:
c19d1205
ZW
6513 case OP_RRnpc_I0:
6514 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6515 inst.error = BAD_PC;
6516 break;
09d92015 6517
5be8be5d
DG
6518 case OP_oRRnpcsp:
6519 case OP_RRnpcsp:
6520 if (inst.operands[i].isreg)
6521 {
6522 if (inst.operands[i].reg == REG_PC)
6523 inst.error = BAD_PC;
6524 else if (inst.operands[i].reg == REG_SP)
6525 inst.error = BAD_SP;
6526 }
6527 break;
6528
55881a11
MGD
6529 case OP_RRnpctw:
6530 if (inst.operands[i].isreg
6531 && inst.operands[i].reg == REG_PC
6532 && (inst.operands[i].writeback || thumb))
6533 inst.error = BAD_PC;
6534 break;
6535
c19d1205
ZW
6536 case OP_CPSF:
6537 case OP_ENDI:
6538 case OP_oROR:
6539 case OP_PSR:
037e8744 6540 case OP_RVC_PSR:
c19d1205 6541 case OP_COND:
52e7f43d 6542 case OP_oBARRIER_I15:
c19d1205
ZW
6543 case OP_REGLST:
6544 case OP_VRSLST:
6545 case OP_VRDLST:
037e8744 6546 case OP_VRSDLST:
5287ad62
JB
6547 case OP_NRDLST:
6548 case OP_NSTRLST:
c19d1205
ZW
6549 if (val == FAIL)
6550 goto failure;
6551 inst.operands[i].imm = val;
6552 break;
a737bd4d 6553
c19d1205
ZW
6554 default:
6555 break;
6556 }
09d92015 6557
c19d1205
ZW
6558 /* If we get here, this operand was successfully parsed. */
6559 inst.operands[i].present = 1;
6560 continue;
09d92015 6561
c19d1205 6562 bad_args:
09d92015 6563 inst.error = BAD_ARGS;
c19d1205
ZW
6564
6565 failure:
6566 if (!backtrack_pos)
d252fdde
PB
6567 {
6568 /* The parse routine should already have set inst.error, but set a
5f4273c7 6569 default here just in case. */
d252fdde
PB
6570 if (!inst.error)
6571 inst.error = _("syntax error");
6572 return FAIL;
6573 }
c19d1205
ZW
6574
6575 /* Do not backtrack over a trailing optional argument that
6576 absorbed some text. We will only fail again, with the
6577 'garbage following instruction' error message, which is
6578 probably less helpful than the current one. */
6579 if (backtrack_index == i && backtrack_pos != str
6580 && upat[i+1] == OP_stop)
d252fdde
PB
6581 {
6582 if (!inst.error)
6583 inst.error = _("syntax error");
6584 return FAIL;
6585 }
c19d1205
ZW
6586
6587 /* Try again, skipping the optional argument at backtrack_pos. */
6588 str = backtrack_pos;
6589 inst.error = backtrack_error;
6590 inst.operands[backtrack_index].present = 0;
6591 i = backtrack_index;
6592 backtrack_pos = 0;
09d92015 6593 }
09d92015 6594
c19d1205
ZW
6595 /* Check that we have parsed all the arguments. */
6596 if (*str != '\0' && !inst.error)
6597 inst.error = _("garbage following instruction");
09d92015 6598
c19d1205 6599 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6600}
6601
c19d1205
ZW
6602#undef po_char_or_fail
6603#undef po_reg_or_fail
6604#undef po_reg_or_goto
6605#undef po_imm_or_fail
5287ad62 6606#undef po_scalar_or_fail
52e7f43d 6607#undef po_barrier_or_imm
e07e6e58 6608
c19d1205 6609/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6610#define constraint(expr, err) \
6611 do \
c19d1205 6612 { \
e07e6e58
NC
6613 if (expr) \
6614 { \
6615 inst.error = err; \
6616 return; \
6617 } \
c19d1205 6618 } \
e07e6e58 6619 while (0)
c19d1205 6620
fdfde340
JM
6621/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6622 instructions are unpredictable if these registers are used. This
6623 is the BadReg predicate in ARM's Thumb-2 documentation. */
6624#define reject_bad_reg(reg) \
6625 do \
6626 if (reg == REG_SP || reg == REG_PC) \
6627 { \
6628 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6629 return; \
6630 } \
6631 while (0)
6632
94206790
MM
6633/* If REG is R13 (the stack pointer), warn that its use is
6634 deprecated. */
6635#define warn_deprecated_sp(reg) \
6636 do \
6637 if (warn_on_deprecated && reg == REG_SP) \
6638 as_warn (_("use of r13 is deprecated")); \
6639 while (0)
6640
c19d1205
ZW
6641/* Functions for operand encoding. ARM, then Thumb. */
6642
6643#define rotate_left(v, n) (v << n | v >> (32 - n))
6644
6645/* If VAL can be encoded in the immediate field of an ARM instruction,
6646 return the encoded form. Otherwise, return FAIL. */
6647
6648static unsigned int
6649encode_arm_immediate (unsigned int val)
09d92015 6650{
c19d1205
ZW
6651 unsigned int a, i;
6652
6653 for (i = 0; i < 32; i += 2)
6654 if ((a = rotate_left (val, i)) <= 0xff)
6655 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6656
6657 return FAIL;
09d92015
MM
6658}
6659
c19d1205
ZW
6660/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6661 return the encoded form. Otherwise, return FAIL. */
6662static unsigned int
6663encode_thumb32_immediate (unsigned int val)
09d92015 6664{
c19d1205 6665 unsigned int a, i;
09d92015 6666
9c3c69f2 6667 if (val <= 0xff)
c19d1205 6668 return val;
a737bd4d 6669
9c3c69f2 6670 for (i = 1; i <= 24; i++)
09d92015 6671 {
9c3c69f2
PB
6672 a = val >> i;
6673 if ((val & ~(0xff << i)) == 0)
6674 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6675 }
a737bd4d 6676
c19d1205
ZW
6677 a = val & 0xff;
6678 if (val == ((a << 16) | a))
6679 return 0x100 | a;
6680 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6681 return 0x300 | a;
09d92015 6682
c19d1205
ZW
6683 a = val & 0xff00;
6684 if (val == ((a << 16) | a))
6685 return 0x200 | (a >> 8);
a737bd4d 6686
c19d1205 6687 return FAIL;
09d92015 6688}
5287ad62 6689/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6690
6691static void
5287ad62
JB
6692encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6693{
6694 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6695 && reg > 15)
6696 {
b1cc4aeb 6697 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6698 {
6699 if (thumb_mode)
6700 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6701 fpu_vfp_ext_d32);
5287ad62
JB
6702 else
6703 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6704 fpu_vfp_ext_d32);
5287ad62
JB
6705 }
6706 else
6707 {
dcbf9037 6708 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6709 return;
6710 }
6711 }
6712
c19d1205 6713 switch (pos)
09d92015 6714 {
c19d1205
ZW
6715 case VFP_REG_Sd:
6716 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6717 break;
6718
6719 case VFP_REG_Sn:
6720 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6721 break;
6722
6723 case VFP_REG_Sm:
6724 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6725 break;
6726
5287ad62
JB
6727 case VFP_REG_Dd:
6728 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6729 break;
5f4273c7 6730
5287ad62
JB
6731 case VFP_REG_Dn:
6732 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6733 break;
5f4273c7 6734
5287ad62
JB
6735 case VFP_REG_Dm:
6736 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6737 break;
6738
c19d1205
ZW
6739 default:
6740 abort ();
09d92015 6741 }
09d92015
MM
6742}
6743
c19d1205 6744/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6745 if any, is handled by md_apply_fix. */
09d92015 6746static void
c19d1205 6747encode_arm_shift (int i)
09d92015 6748{
c19d1205
ZW
6749 if (inst.operands[i].shift_kind == SHIFT_RRX)
6750 inst.instruction |= SHIFT_ROR << 5;
6751 else
09d92015 6752 {
c19d1205
ZW
6753 inst.instruction |= inst.operands[i].shift_kind << 5;
6754 if (inst.operands[i].immisreg)
6755 {
6756 inst.instruction |= SHIFT_BY_REG;
6757 inst.instruction |= inst.operands[i].imm << 8;
6758 }
6759 else
6760 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6761 }
c19d1205 6762}
09d92015 6763
c19d1205
ZW
6764static void
6765encode_arm_shifter_operand (int i)
6766{
6767 if (inst.operands[i].isreg)
09d92015 6768 {
c19d1205
ZW
6769 inst.instruction |= inst.operands[i].reg;
6770 encode_arm_shift (i);
09d92015 6771 }
c19d1205
ZW
6772 else
6773 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6774}
6775
c19d1205 6776/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6777static void
c19d1205 6778encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6779{
9c2799c2 6780 gas_assert (inst.operands[i].isreg);
c19d1205 6781 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6782
c19d1205 6783 if (inst.operands[i].preind)
09d92015 6784 {
c19d1205
ZW
6785 if (is_t)
6786 {
6787 inst.error = _("instruction does not accept preindexed addressing");
6788 return;
6789 }
6790 inst.instruction |= PRE_INDEX;
6791 if (inst.operands[i].writeback)
6792 inst.instruction |= WRITE_BACK;
09d92015 6793
c19d1205
ZW
6794 }
6795 else if (inst.operands[i].postind)
6796 {
9c2799c2 6797 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
6798 if (is_t)
6799 inst.instruction |= WRITE_BACK;
6800 }
6801 else /* unindexed - only for coprocessor */
09d92015 6802 {
c19d1205 6803 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6804 return;
6805 }
6806
c19d1205
ZW
6807 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6808 && (((inst.instruction & 0x000f0000) >> 16)
6809 == ((inst.instruction & 0x0000f000) >> 12)))
6810 as_warn ((inst.instruction & LOAD_BIT)
6811 ? _("destination register same as write-back base")
6812 : _("source register same as write-back base"));
09d92015
MM
6813}
6814
c19d1205
ZW
6815/* inst.operands[i] was set up by parse_address. Encode it into an
6816 ARM-format mode 2 load or store instruction. If is_t is true,
6817 reject forms that cannot be used with a T instruction (i.e. not
6818 post-indexed). */
a737bd4d 6819static void
c19d1205 6820encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6821{
5be8be5d
DG
6822 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
6823
c19d1205 6824 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6825
c19d1205 6826 if (inst.operands[i].immisreg)
09d92015 6827 {
5be8be5d
DG
6828 constraint ((inst.operands[i].imm == REG_PC
6829 || (is_pc && inst.operands[i].writeback)),
6830 BAD_PC_ADDRESSING);
c19d1205
ZW
6831 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6832 inst.instruction |= inst.operands[i].imm;
6833 if (!inst.operands[i].negative)
6834 inst.instruction |= INDEX_UP;
6835 if (inst.operands[i].shifted)
6836 {
6837 if (inst.operands[i].shift_kind == SHIFT_RRX)
6838 inst.instruction |= SHIFT_ROR << 5;
6839 else
6840 {
6841 inst.instruction |= inst.operands[i].shift_kind << 5;
6842 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6843 }
6844 }
09d92015 6845 }
c19d1205 6846 else /* immediate offset in inst.reloc */
09d92015 6847 {
5be8be5d
DG
6848 if (is_pc && !inst.reloc.pc_rel)
6849 {
6850 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
6851
6852 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
6853 cannot use PC in addressing.
6854 PC cannot be used in writeback addressing, either. */
6855 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 6856 BAD_PC_ADDRESSING);
23a10334 6857
dc5ec521 6858 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
6859 if (warn_on_deprecated
6860 && !is_load
6861 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
6862 as_warn (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
6863 }
6864
c19d1205
ZW
6865 if (inst.reloc.type == BFD_RELOC_UNUSED)
6866 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6867 }
09d92015
MM
6868}
6869
c19d1205
ZW
6870/* inst.operands[i] was set up by parse_address. Encode it into an
6871 ARM-format mode 3 load or store instruction. Reject forms that
6872 cannot be used with such instructions. If is_t is true, reject
6873 forms that cannot be used with a T instruction (i.e. not
6874 post-indexed). */
6875static void
6876encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6877{
c19d1205 6878 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6879 {
c19d1205
ZW
6880 inst.error = _("instruction does not accept scaled register index");
6881 return;
09d92015 6882 }
a737bd4d 6883
c19d1205 6884 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6885
c19d1205
ZW
6886 if (inst.operands[i].immisreg)
6887 {
5be8be5d
DG
6888 constraint ((inst.operands[i].imm == REG_PC
6889 || inst.operands[i].reg == REG_PC),
6890 BAD_PC_ADDRESSING);
c19d1205
ZW
6891 inst.instruction |= inst.operands[i].imm;
6892 if (!inst.operands[i].negative)
6893 inst.instruction |= INDEX_UP;
6894 }
6895 else /* immediate offset in inst.reloc */
6896 {
5be8be5d
DG
6897 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
6898 && inst.operands[i].writeback),
6899 BAD_PC_WRITEBACK);
c19d1205
ZW
6900 inst.instruction |= HWOFFSET_IMM;
6901 if (inst.reloc.type == BFD_RELOC_UNUSED)
6902 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6903 }
a737bd4d
NC
6904}
6905
c19d1205
ZW
6906/* inst.operands[i] was set up by parse_address. Encode it into an
6907 ARM-format instruction. Reject all forms which cannot be encoded
6908 into a coprocessor load/store instruction. If wb_ok is false,
6909 reject use of writeback; if unind_ok is false, reject use of
6910 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6911 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6912 (in which case it is preserved). */
09d92015 6913
c19d1205
ZW
6914static int
6915encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6916{
c19d1205 6917 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6918
9c2799c2 6919 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6920
c19d1205 6921 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6922 {
9c2799c2 6923 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
6924 if (!unind_ok)
6925 {
6926 inst.error = _("instruction does not support unindexed addressing");
6927 return FAIL;
6928 }
6929 inst.instruction |= inst.operands[i].imm;
6930 inst.instruction |= INDEX_UP;
6931 return SUCCESS;
09d92015 6932 }
a737bd4d 6933
c19d1205
ZW
6934 if (inst.operands[i].preind)
6935 inst.instruction |= PRE_INDEX;
a737bd4d 6936
c19d1205 6937 if (inst.operands[i].writeback)
09d92015 6938 {
c19d1205
ZW
6939 if (inst.operands[i].reg == REG_PC)
6940 {
6941 inst.error = _("pc may not be used with write-back");
6942 return FAIL;
6943 }
6944 if (!wb_ok)
6945 {
6946 inst.error = _("instruction does not support writeback");
6947 return FAIL;
6948 }
6949 inst.instruction |= WRITE_BACK;
09d92015 6950 }
a737bd4d 6951
c19d1205 6952 if (reloc_override)
21d799b5 6953 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a
MS
6954 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6955 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6956 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6957 {
6958 if (thumb_mode)
6959 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6960 else
6961 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6962 }
6963
c19d1205
ZW
6964 return SUCCESS;
6965}
a737bd4d 6966
c19d1205
ZW
6967/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6968 Determine whether it can be performed with a move instruction; if
6969 it can, convert inst.instruction to that move instruction and
c921be7d
NC
6970 return TRUE; if it can't, convert inst.instruction to a literal-pool
6971 load and return FALSE. If this is not a valid thing to do in the
6972 current context, set inst.error and return TRUE.
a737bd4d 6973
c19d1205
ZW
6974 inst.operands[i] describes the destination register. */
6975
c921be7d 6976static bfd_boolean
c19d1205
ZW
6977move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6978{
53365c0d
PB
6979 unsigned long tbit;
6980
6981 if (thumb_p)
6982 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6983 else
6984 tbit = LOAD_BIT;
6985
6986 if ((inst.instruction & tbit) == 0)
09d92015 6987 {
c19d1205 6988 inst.error = _("invalid pseudo operation");
c921be7d 6989 return TRUE;
09d92015 6990 }
c19d1205 6991 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6992 {
6993 inst.error = _("constant expression expected");
c921be7d 6994 return TRUE;
09d92015 6995 }
c19d1205 6996 if (inst.reloc.exp.X_op == O_constant)
09d92015 6997 {
c19d1205
ZW
6998 if (thumb_p)
6999 {
53365c0d 7000 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
7001 {
7002 /* This can be done with a mov(1) instruction. */
7003 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7004 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 7005 return TRUE;
c19d1205
ZW
7006 }
7007 }
7008 else
7009 {
7010 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7011 if (value != FAIL)
7012 {
7013 /* This can be done with a mov instruction. */
7014 inst.instruction &= LITERAL_MASK;
7015 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7016 inst.instruction |= value & 0xfff;
c921be7d 7017 return TRUE;
c19d1205 7018 }
09d92015 7019
c19d1205
ZW
7020 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7021 if (value != FAIL)
7022 {
7023 /* This can be done with a mvn instruction. */
7024 inst.instruction &= LITERAL_MASK;
7025 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7026 inst.instruction |= value & 0xfff;
c921be7d 7027 return TRUE;
c19d1205
ZW
7028 }
7029 }
09d92015
MM
7030 }
7031
c19d1205
ZW
7032 if (add_to_lit_pool () == FAIL)
7033 {
7034 inst.error = _("literal pool insertion failed");
c921be7d 7035 return TRUE;
c19d1205
ZW
7036 }
7037 inst.operands[1].reg = REG_PC;
7038 inst.operands[1].isreg = 1;
7039 inst.operands[1].preind = 1;
7040 inst.reloc.pc_rel = 1;
7041 inst.reloc.type = (thumb_p
7042 ? BFD_RELOC_ARM_THUMB_OFFSET
7043 : (mode_3
7044 ? BFD_RELOC_ARM_HWLITERAL
7045 : BFD_RELOC_ARM_LITERAL));
c921be7d 7046 return FALSE;
09d92015
MM
7047}
7048
5f4273c7 7049/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
7050 First some generics; their names are taken from the conventional
7051 bit positions for register arguments in ARM format instructions. */
09d92015 7052
a737bd4d 7053static void
c19d1205 7054do_noargs (void)
09d92015 7055{
c19d1205 7056}
a737bd4d 7057
c19d1205
ZW
7058static void
7059do_rd (void)
7060{
7061 inst.instruction |= inst.operands[0].reg << 12;
7062}
a737bd4d 7063
c19d1205
ZW
7064static void
7065do_rd_rm (void)
7066{
7067 inst.instruction |= inst.operands[0].reg << 12;
7068 inst.instruction |= inst.operands[1].reg;
7069}
09d92015 7070
c19d1205
ZW
7071static void
7072do_rd_rn (void)
7073{
7074 inst.instruction |= inst.operands[0].reg << 12;
7075 inst.instruction |= inst.operands[1].reg << 16;
7076}
a737bd4d 7077
c19d1205
ZW
7078static void
7079do_rn_rd (void)
7080{
7081 inst.instruction |= inst.operands[0].reg << 16;
7082 inst.instruction |= inst.operands[1].reg << 12;
7083}
09d92015 7084
c19d1205
ZW
7085static void
7086do_rd_rm_rn (void)
7087{
9a64e435 7088 unsigned Rn = inst.operands[2].reg;
708587a4 7089 /* Enforce restrictions on SWP instruction. */
9a64e435 7090 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
7091 {
7092 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7093 _("Rn must not overlap other operands"));
7094
7095 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
7096 if (warn_on_deprecated
7097 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7098 as_warn (_("swp{b} use is deprecated for this architecture"));
7099
7100 }
c19d1205
ZW
7101 inst.instruction |= inst.operands[0].reg << 12;
7102 inst.instruction |= inst.operands[1].reg;
9a64e435 7103 inst.instruction |= Rn << 16;
c19d1205 7104}
09d92015 7105
c19d1205
ZW
7106static void
7107do_rd_rn_rm (void)
7108{
7109 inst.instruction |= inst.operands[0].reg << 12;
7110 inst.instruction |= inst.operands[1].reg << 16;
7111 inst.instruction |= inst.operands[2].reg;
7112}
a737bd4d 7113
c19d1205
ZW
7114static void
7115do_rm_rd_rn (void)
7116{
5be8be5d
DG
7117 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7118 constraint (((inst.reloc.exp.X_op != O_constant
7119 && inst.reloc.exp.X_op != O_illegal)
7120 || inst.reloc.exp.X_add_number != 0),
7121 BAD_ADDR_MODE);
c19d1205
ZW
7122 inst.instruction |= inst.operands[0].reg;
7123 inst.instruction |= inst.operands[1].reg << 12;
7124 inst.instruction |= inst.operands[2].reg << 16;
7125}
09d92015 7126
c19d1205
ZW
7127static void
7128do_imm0 (void)
7129{
7130 inst.instruction |= inst.operands[0].imm;
7131}
09d92015 7132
c19d1205
ZW
7133static void
7134do_rd_cpaddr (void)
7135{
7136 inst.instruction |= inst.operands[0].reg << 12;
7137 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 7138}
a737bd4d 7139
c19d1205
ZW
7140/* ARM instructions, in alphabetical order by function name (except
7141 that wrapper functions appear immediately after the function they
7142 wrap). */
09d92015 7143
c19d1205
ZW
7144/* This is a pseudo-op of the form "adr rd, label" to be converted
7145 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
7146
7147static void
c19d1205 7148do_adr (void)
09d92015 7149{
c19d1205 7150 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7151
c19d1205
ZW
7152 /* Frag hacking will turn this into a sub instruction if the offset turns
7153 out to be negative. */
7154 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 7155 inst.reloc.pc_rel = 1;
2fc8bdac 7156 inst.reloc.exp.X_add_number -= 8;
c19d1205 7157}
b99bd4ef 7158
c19d1205
ZW
7159/* This is a pseudo-op of the form "adrl rd, label" to be converted
7160 into a relative address of the form:
7161 add rd, pc, #low(label-.-8)"
7162 add rd, rd, #high(label-.-8)" */
b99bd4ef 7163
c19d1205
ZW
7164static void
7165do_adrl (void)
7166{
7167 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7168
c19d1205
ZW
7169 /* Frag hacking will turn this into a sub instruction if the offset turns
7170 out to be negative. */
7171 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
7172 inst.reloc.pc_rel = 1;
7173 inst.size = INSN_SIZE * 2;
2fc8bdac 7174 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
7175}
7176
b99bd4ef 7177static void
c19d1205 7178do_arit (void)
b99bd4ef 7179{
c19d1205
ZW
7180 if (!inst.operands[1].present)
7181 inst.operands[1].reg = inst.operands[0].reg;
7182 inst.instruction |= inst.operands[0].reg << 12;
7183 inst.instruction |= inst.operands[1].reg << 16;
7184 encode_arm_shifter_operand (2);
7185}
b99bd4ef 7186
62b3e311
PB
7187static void
7188do_barrier (void)
7189{
7190 if (inst.operands[0].present)
7191 {
7192 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
7193 && inst.operands[0].imm > 0xf
7194 && inst.operands[0].imm < 0x0,
bd3ba5d1 7195 _("bad barrier type"));
62b3e311
PB
7196 inst.instruction |= inst.operands[0].imm;
7197 }
7198 else
7199 inst.instruction |= 0xf;
7200}
7201
c19d1205
ZW
7202static void
7203do_bfc (void)
7204{
7205 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7206 constraint (msb > 32, _("bit-field extends past end of register"));
7207 /* The instruction encoding stores the LSB and MSB,
7208 not the LSB and width. */
7209 inst.instruction |= inst.operands[0].reg << 12;
7210 inst.instruction |= inst.operands[1].imm << 7;
7211 inst.instruction |= (msb - 1) << 16;
7212}
b99bd4ef 7213
c19d1205
ZW
7214static void
7215do_bfi (void)
7216{
7217 unsigned int msb;
b99bd4ef 7218
c19d1205
ZW
7219 /* #0 in second position is alternative syntax for bfc, which is
7220 the same instruction but with REG_PC in the Rm field. */
7221 if (!inst.operands[1].isreg)
7222 inst.operands[1].reg = REG_PC;
b99bd4ef 7223
c19d1205
ZW
7224 msb = inst.operands[2].imm + inst.operands[3].imm;
7225 constraint (msb > 32, _("bit-field extends past end of register"));
7226 /* The instruction encoding stores the LSB and MSB,
7227 not the LSB and width. */
7228 inst.instruction |= inst.operands[0].reg << 12;
7229 inst.instruction |= inst.operands[1].reg;
7230 inst.instruction |= inst.operands[2].imm << 7;
7231 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7232}
7233
b99bd4ef 7234static void
c19d1205 7235do_bfx (void)
b99bd4ef 7236{
c19d1205
ZW
7237 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7238 _("bit-field extends past end of register"));
7239 inst.instruction |= inst.operands[0].reg << 12;
7240 inst.instruction |= inst.operands[1].reg;
7241 inst.instruction |= inst.operands[2].imm << 7;
7242 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7243}
09d92015 7244
c19d1205
ZW
7245/* ARM V5 breakpoint instruction (argument parse)
7246 BKPT <16 bit unsigned immediate>
7247 Instruction is not conditional.
7248 The bit pattern given in insns[] has the COND_ALWAYS condition,
7249 and it is an error if the caller tried to override that. */
b99bd4ef 7250
c19d1205
ZW
7251static void
7252do_bkpt (void)
7253{
7254 /* Top 12 of 16 bits to bits 19:8. */
7255 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7256
c19d1205
ZW
7257 /* Bottom 4 of 16 bits to bits 3:0. */
7258 inst.instruction |= inst.operands[0].imm & 0xf;
7259}
09d92015 7260
c19d1205
ZW
7261static void
7262encode_branch (int default_reloc)
7263{
7264 if (inst.operands[0].hasreloc)
7265 {
7266 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
7267 _("the only suffix valid here is '(plt)'"));
267bf995 7268 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 7269 }
b99bd4ef 7270 else
c19d1205 7271 {
21d799b5 7272 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
c19d1205 7273 }
2fc8bdac 7274 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7275}
7276
b99bd4ef 7277static void
c19d1205 7278do_branch (void)
b99bd4ef 7279{
39b41c9c
PB
7280#ifdef OBJ_ELF
7281 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7282 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7283 else
7284#endif
7285 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7286}
7287
7288static void
7289do_bl (void)
7290{
7291#ifdef OBJ_ELF
7292 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7293 {
7294 if (inst.cond == COND_ALWAYS)
7295 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7296 else
7297 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7298 }
7299 else
7300#endif
7301 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7302}
b99bd4ef 7303
c19d1205
ZW
7304/* ARM V5 branch-link-exchange instruction (argument parse)
7305 BLX <target_addr> ie BLX(1)
7306 BLX{<condition>} <Rm> ie BLX(2)
7307 Unfortunately, there are two different opcodes for this mnemonic.
7308 So, the insns[].value is not used, and the code here zaps values
7309 into inst.instruction.
7310 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7311
c19d1205
ZW
7312static void
7313do_blx (void)
7314{
7315 if (inst.operands[0].isreg)
b99bd4ef 7316 {
c19d1205
ZW
7317 /* Arg is a register; the opcode provided by insns[] is correct.
7318 It is not illegal to do "blx pc", just useless. */
7319 if (inst.operands[0].reg == REG_PC)
7320 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7321
c19d1205
ZW
7322 inst.instruction |= inst.operands[0].reg;
7323 }
7324 else
b99bd4ef 7325 {
c19d1205 7326 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7327 conditionally, and the opcode must be adjusted.
7328 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7329 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7330 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7331 inst.instruction = 0xfa000000;
267bf995 7332 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7333 }
c19d1205
ZW
7334}
7335
7336static void
7337do_bx (void)
7338{
845b51d6
PB
7339 bfd_boolean want_reloc;
7340
c19d1205
ZW
7341 if (inst.operands[0].reg == REG_PC)
7342 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7343
c19d1205 7344 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7345 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7346 it is for ARMv4t or earlier. */
7347 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7348 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7349 want_reloc = TRUE;
7350
5ad34203 7351#ifdef OBJ_ELF
845b51d6 7352 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7353#endif
584206db 7354 want_reloc = FALSE;
845b51d6
PB
7355
7356 if (want_reloc)
7357 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7358}
7359
c19d1205
ZW
7360
7361/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7362
7363static void
c19d1205 7364do_bxj (void)
a737bd4d 7365{
c19d1205
ZW
7366 if (inst.operands[0].reg == REG_PC)
7367 as_tsktsk (_("use of r15 in bxj is not really useful"));
7368
7369 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7370}
7371
c19d1205
ZW
7372/* Co-processor data operation:
7373 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7374 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7375static void
7376do_cdp (void)
7377{
7378 inst.instruction |= inst.operands[0].reg << 8;
7379 inst.instruction |= inst.operands[1].imm << 20;
7380 inst.instruction |= inst.operands[2].reg << 12;
7381 inst.instruction |= inst.operands[3].reg << 16;
7382 inst.instruction |= inst.operands[4].reg;
7383 inst.instruction |= inst.operands[5].imm << 5;
7384}
a737bd4d
NC
7385
7386static void
c19d1205 7387do_cmp (void)
a737bd4d 7388{
c19d1205
ZW
7389 inst.instruction |= inst.operands[0].reg << 16;
7390 encode_arm_shifter_operand (1);
a737bd4d
NC
7391}
7392
c19d1205
ZW
7393/* Transfer between coprocessor and ARM registers.
7394 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7395 MRC2
7396 MCR{cond}
7397 MCR2
7398
7399 No special properties. */
09d92015
MM
7400
7401static void
c19d1205 7402do_co_reg (void)
09d92015 7403{
fdfde340
JM
7404 unsigned Rd;
7405
7406 Rd = inst.operands[2].reg;
7407 if (thumb_mode)
7408 {
7409 if (inst.instruction == 0xee000010
7410 || inst.instruction == 0xfe000010)
7411 /* MCR, MCR2 */
7412 reject_bad_reg (Rd);
7413 else
7414 /* MRC, MRC2 */
7415 constraint (Rd == REG_SP, BAD_SP);
7416 }
7417 else
7418 {
7419 /* MCR */
7420 if (inst.instruction == 0xe000010)
7421 constraint (Rd == REG_PC, BAD_PC);
7422 }
7423
7424
c19d1205
ZW
7425 inst.instruction |= inst.operands[0].reg << 8;
7426 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7427 inst.instruction |= Rd << 12;
c19d1205
ZW
7428 inst.instruction |= inst.operands[3].reg << 16;
7429 inst.instruction |= inst.operands[4].reg;
7430 inst.instruction |= inst.operands[5].imm << 5;
7431}
09d92015 7432
c19d1205
ZW
7433/* Transfer between coprocessor register and pair of ARM registers.
7434 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7435 MCRR2
7436 MRRC{cond}
7437 MRRC2
b99bd4ef 7438
c19d1205 7439 Two XScale instructions are special cases of these:
09d92015 7440
c19d1205
ZW
7441 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7442 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7443
5f4273c7 7444 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7445
c19d1205
ZW
7446static void
7447do_co_reg2c (void)
7448{
fdfde340
JM
7449 unsigned Rd, Rn;
7450
7451 Rd = inst.operands[2].reg;
7452 Rn = inst.operands[3].reg;
7453
7454 if (thumb_mode)
7455 {
7456 reject_bad_reg (Rd);
7457 reject_bad_reg (Rn);
7458 }
7459 else
7460 {
7461 constraint (Rd == REG_PC, BAD_PC);
7462 constraint (Rn == REG_PC, BAD_PC);
7463 }
7464
c19d1205
ZW
7465 inst.instruction |= inst.operands[0].reg << 8;
7466 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7467 inst.instruction |= Rd << 12;
7468 inst.instruction |= Rn << 16;
c19d1205 7469 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7470}
7471
c19d1205
ZW
7472static void
7473do_cpsi (void)
7474{
7475 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7476 if (inst.operands[1].present)
7477 {
7478 inst.instruction |= CPSI_MMOD;
7479 inst.instruction |= inst.operands[1].imm;
7480 }
c19d1205 7481}
b99bd4ef 7482
62b3e311
PB
7483static void
7484do_dbg (void)
7485{
7486 inst.instruction |= inst.operands[0].imm;
7487}
7488
b99bd4ef 7489static void
c19d1205 7490do_it (void)
b99bd4ef 7491{
c19d1205 7492 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7493 process it to do the validation as if in
7494 thumb mode, just in case the code gets
7495 assembled for thumb using the unified syntax. */
7496
c19d1205 7497 inst.size = 0;
e07e6e58
NC
7498 if (unified_syntax)
7499 {
7500 set_it_insn_type (IT_INSN);
7501 now_it.mask = (inst.instruction & 0xf) | 0x10;
7502 now_it.cc = inst.operands[0].imm;
7503 }
09d92015 7504}
b99bd4ef 7505
09d92015 7506static void
c19d1205 7507do_ldmstm (void)
ea6ef066 7508{
c19d1205
ZW
7509 int base_reg = inst.operands[0].reg;
7510 int range = inst.operands[1].imm;
ea6ef066 7511
c19d1205
ZW
7512 inst.instruction |= base_reg << 16;
7513 inst.instruction |= range;
ea6ef066 7514
c19d1205
ZW
7515 if (inst.operands[1].writeback)
7516 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7517
c19d1205 7518 if (inst.operands[0].writeback)
ea6ef066 7519 {
c19d1205
ZW
7520 inst.instruction |= WRITE_BACK;
7521 /* Check for unpredictable uses of writeback. */
7522 if (inst.instruction & LOAD_BIT)
09d92015 7523 {
c19d1205
ZW
7524 /* Not allowed in LDM type 2. */
7525 if ((inst.instruction & LDM_TYPE_2_OR_3)
7526 && ((range & (1 << REG_PC)) == 0))
7527 as_warn (_("writeback of base register is UNPREDICTABLE"));
7528 /* Only allowed if base reg not in list for other types. */
7529 else if (range & (1 << base_reg))
7530 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7531 }
7532 else /* STM. */
7533 {
7534 /* Not allowed for type 2. */
7535 if (inst.instruction & LDM_TYPE_2_OR_3)
7536 as_warn (_("writeback of base register is UNPREDICTABLE"));
7537 /* Only allowed if base reg not in list, or first in list. */
7538 else if ((range & (1 << base_reg))
7539 && (range & ((1 << base_reg) - 1)))
7540 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7541 }
ea6ef066 7542 }
a737bd4d
NC
7543}
7544
c19d1205
ZW
7545/* ARMv5TE load-consecutive (argument parse)
7546 Mode is like LDRH.
7547
7548 LDRccD R, mode
7549 STRccD R, mode. */
7550
a737bd4d 7551static void
c19d1205 7552do_ldrd (void)
a737bd4d 7553{
c19d1205
ZW
7554 constraint (inst.operands[0].reg % 2 != 0,
7555 _("first destination register must be even"));
7556 constraint (inst.operands[1].present
7557 && inst.operands[1].reg != inst.operands[0].reg + 1,
7558 _("can only load two consecutive registers"));
7559 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7560 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7561
c19d1205
ZW
7562 if (!inst.operands[1].present)
7563 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7564
c19d1205 7565 if (inst.instruction & LOAD_BIT)
a737bd4d 7566 {
c19d1205
ZW
7567 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7568 register and the first register written; we have to diagnose
7569 overlap between the base and the second register written here. */
ea6ef066 7570
c19d1205
ZW
7571 if (inst.operands[2].reg == inst.operands[1].reg
7572 && (inst.operands[2].writeback || inst.operands[2].postind))
7573 as_warn (_("base register written back, and overlaps "
7574 "second destination register"));
b05fe5cf 7575
c19d1205
ZW
7576 /* For an index-register load, the index register must not overlap the
7577 destination (even if not write-back). */
7578 else if (inst.operands[2].immisreg
ca3f61f7
NC
7579 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7580 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 7581 as_warn (_("index register overlaps destination register"));
b05fe5cf 7582 }
c19d1205
ZW
7583
7584 inst.instruction |= inst.operands[0].reg << 12;
7585 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7586}
7587
7588static void
c19d1205 7589do_ldrex (void)
b05fe5cf 7590{
c19d1205
ZW
7591 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7592 || inst.operands[1].postind || inst.operands[1].writeback
7593 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7594 || inst.operands[1].negative
7595 /* This can arise if the programmer has written
7596 strex rN, rM, foo
7597 or if they have mistakenly used a register name as the last
7598 operand, eg:
7599 strex rN, rM, rX
7600 It is very difficult to distinguish between these two cases
7601 because "rX" might actually be a label. ie the register
7602 name has been occluded by a symbol of the same name. So we
7603 just generate a general 'bad addressing mode' type error
7604 message and leave it up to the programmer to discover the
7605 true cause and fix their mistake. */
7606 || (inst.operands[1].reg == REG_PC),
7607 BAD_ADDR_MODE);
b05fe5cf 7608
c19d1205
ZW
7609 constraint (inst.reloc.exp.X_op != O_constant
7610 || inst.reloc.exp.X_add_number != 0,
7611 _("offset must be zero in ARM encoding"));
b05fe5cf 7612
5be8be5d
DG
7613 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7614
c19d1205
ZW
7615 inst.instruction |= inst.operands[0].reg << 12;
7616 inst.instruction |= inst.operands[1].reg << 16;
7617 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7618}
7619
7620static void
c19d1205 7621do_ldrexd (void)
b05fe5cf 7622{
c19d1205
ZW
7623 constraint (inst.operands[0].reg % 2 != 0,
7624 _("even register required"));
7625 constraint (inst.operands[1].present
7626 && inst.operands[1].reg != inst.operands[0].reg + 1,
7627 _("can only load two consecutive registers"));
7628 /* If op 1 were present and equal to PC, this function wouldn't
7629 have been called in the first place. */
7630 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7631
c19d1205
ZW
7632 inst.instruction |= inst.operands[0].reg << 12;
7633 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7634}
7635
7636static void
c19d1205 7637do_ldst (void)
b05fe5cf 7638{
c19d1205
ZW
7639 inst.instruction |= inst.operands[0].reg << 12;
7640 if (!inst.operands[1].isreg)
7641 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7642 return;
c19d1205 7643 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7644}
7645
7646static void
c19d1205 7647do_ldstt (void)
b05fe5cf 7648{
c19d1205
ZW
7649 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7650 reject [Rn,...]. */
7651 if (inst.operands[1].preind)
b05fe5cf 7652 {
bd3ba5d1
NC
7653 constraint (inst.reloc.exp.X_op != O_constant
7654 || inst.reloc.exp.X_add_number != 0,
c19d1205 7655 _("this instruction requires a post-indexed address"));
b05fe5cf 7656
c19d1205
ZW
7657 inst.operands[1].preind = 0;
7658 inst.operands[1].postind = 1;
7659 inst.operands[1].writeback = 1;
b05fe5cf 7660 }
c19d1205
ZW
7661 inst.instruction |= inst.operands[0].reg << 12;
7662 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7663}
b05fe5cf 7664
c19d1205 7665/* Halfword and signed-byte load/store operations. */
b05fe5cf 7666
c19d1205
ZW
7667static void
7668do_ldstv4 (void)
7669{
ff4a8d2b 7670 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7671 inst.instruction |= inst.operands[0].reg << 12;
7672 if (!inst.operands[1].isreg)
7673 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7674 return;
c19d1205 7675 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7676}
7677
7678static void
c19d1205 7679do_ldsttv4 (void)
b05fe5cf 7680{
c19d1205
ZW
7681 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7682 reject [Rn,...]. */
7683 if (inst.operands[1].preind)
b05fe5cf 7684 {
bd3ba5d1
NC
7685 constraint (inst.reloc.exp.X_op != O_constant
7686 || inst.reloc.exp.X_add_number != 0,
c19d1205 7687 _("this instruction requires a post-indexed address"));
b05fe5cf 7688
c19d1205
ZW
7689 inst.operands[1].preind = 0;
7690 inst.operands[1].postind = 1;
7691 inst.operands[1].writeback = 1;
b05fe5cf 7692 }
c19d1205
ZW
7693 inst.instruction |= inst.operands[0].reg << 12;
7694 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7695}
b05fe5cf 7696
c19d1205
ZW
7697/* Co-processor register load/store.
7698 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7699static void
7700do_lstc (void)
7701{
7702 inst.instruction |= inst.operands[0].reg << 8;
7703 inst.instruction |= inst.operands[1].reg << 12;
7704 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7705}
7706
b05fe5cf 7707static void
c19d1205 7708do_mlas (void)
b05fe5cf 7709{
8fb9d7b9 7710 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7711 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7712 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7713 && !(inst.instruction & 0x00400000))
8fb9d7b9 7714 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7715
c19d1205
ZW
7716 inst.instruction |= inst.operands[0].reg << 16;
7717 inst.instruction |= inst.operands[1].reg;
7718 inst.instruction |= inst.operands[2].reg << 8;
7719 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7720}
b05fe5cf 7721
c19d1205
ZW
7722static void
7723do_mov (void)
7724{
7725 inst.instruction |= inst.operands[0].reg << 12;
7726 encode_arm_shifter_operand (1);
7727}
b05fe5cf 7728
c19d1205
ZW
7729/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7730static void
7731do_mov16 (void)
7732{
b6895b4f
PB
7733 bfd_vma imm;
7734 bfd_boolean top;
7735
7736 top = (inst.instruction & 0x00400000) != 0;
7737 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7738 _(":lower16: not allowed this instruction"));
7739 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7740 _(":upper16: not allowed instruction"));
c19d1205 7741 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7742 if (inst.reloc.type == BFD_RELOC_UNUSED)
7743 {
7744 imm = inst.reloc.exp.X_add_number;
7745 /* The value is in two pieces: 0:11, 16:19. */
7746 inst.instruction |= (imm & 0x00000fff);
7747 inst.instruction |= (imm & 0x0000f000) << 4;
7748 }
b05fe5cf 7749}
b99bd4ef 7750
037e8744
JB
7751static void do_vfp_nsyn_opcode (const char *);
7752
7753static int
7754do_vfp_nsyn_mrs (void)
7755{
7756 if (inst.operands[0].isvec)
7757 {
7758 if (inst.operands[1].reg != 1)
7759 first_error (_("operand 1 must be FPSCR"));
7760 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7761 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7762 do_vfp_nsyn_opcode ("fmstat");
7763 }
7764 else if (inst.operands[1].isvec)
7765 do_vfp_nsyn_opcode ("fmrx");
7766 else
7767 return FAIL;
5f4273c7 7768
037e8744
JB
7769 return SUCCESS;
7770}
7771
7772static int
7773do_vfp_nsyn_msr (void)
7774{
7775 if (inst.operands[0].isvec)
7776 do_vfp_nsyn_opcode ("fmxr");
7777 else
7778 return FAIL;
7779
7780 return SUCCESS;
7781}
7782
f7c21dc7
NC
7783static void
7784do_vmrs (void)
7785{
7786 unsigned Rt = inst.operands[0].reg;
7787
7788 if (thumb_mode && inst.operands[0].reg == REG_SP)
7789 {
7790 inst.error = BAD_SP;
7791 return;
7792 }
7793
7794 /* APSR_ sets isvec. All other refs to PC are illegal. */
7795 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
7796 {
7797 inst.error = BAD_PC;
7798 return;
7799 }
7800
7801 if (inst.operands[1].reg != 1)
7802 first_error (_("operand 1 must be FPSCR"));
7803
7804 inst.instruction |= (Rt << 12);
7805}
7806
7807static void
7808do_vmsr (void)
7809{
7810 unsigned Rt = inst.operands[1].reg;
7811
7812 if (thumb_mode)
7813 reject_bad_reg (Rt);
7814 else if (Rt == REG_PC)
7815 {
7816 inst.error = BAD_PC;
7817 return;
7818 }
7819
7820 if (inst.operands[0].reg != 1)
7821 first_error (_("operand 0 must be FPSCR"));
7822
7823 inst.instruction |= (Rt << 12);
7824}
7825
b99bd4ef 7826static void
c19d1205 7827do_mrs (void)
b99bd4ef 7828{
037e8744
JB
7829 if (do_vfp_nsyn_mrs () == SUCCESS)
7830 return;
7831
c19d1205
ZW
7832 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7833 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7834 != (PSR_c|PSR_f),
7835 _("'CPSR' or 'SPSR' expected"));
ff4a8d2b 7836 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7837 inst.instruction |= inst.operands[0].reg << 12;
7838 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7839}
b99bd4ef 7840
c19d1205
ZW
7841/* Two possible forms:
7842 "{C|S}PSR_<field>, Rm",
7843 "{C|S}PSR_f, #expression". */
b99bd4ef 7844
c19d1205
ZW
7845static void
7846do_msr (void)
7847{
037e8744
JB
7848 if (do_vfp_nsyn_msr () == SUCCESS)
7849 return;
7850
c19d1205
ZW
7851 inst.instruction |= inst.operands[0].imm;
7852 if (inst.operands[1].isreg)
7853 inst.instruction |= inst.operands[1].reg;
7854 else
b99bd4ef 7855 {
c19d1205
ZW
7856 inst.instruction |= INST_IMMEDIATE;
7857 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7858 inst.reloc.pc_rel = 0;
b99bd4ef 7859 }
b99bd4ef
NC
7860}
7861
c19d1205
ZW
7862static void
7863do_mul (void)
a737bd4d 7864{
ff4a8d2b
NC
7865 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
7866
c19d1205
ZW
7867 if (!inst.operands[2].present)
7868 inst.operands[2].reg = inst.operands[0].reg;
7869 inst.instruction |= inst.operands[0].reg << 16;
7870 inst.instruction |= inst.operands[1].reg;
7871 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7872
8fb9d7b9
MS
7873 if (inst.operands[0].reg == inst.operands[1].reg
7874 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7875 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7876}
7877
c19d1205
ZW
7878/* Long Multiply Parser
7879 UMULL RdLo, RdHi, Rm, Rs
7880 SMULL RdLo, RdHi, Rm, Rs
7881 UMLAL RdLo, RdHi, Rm, Rs
7882 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7883
7884static void
c19d1205 7885do_mull (void)
b99bd4ef 7886{
c19d1205
ZW
7887 inst.instruction |= inst.operands[0].reg << 12;
7888 inst.instruction |= inst.operands[1].reg << 16;
7889 inst.instruction |= inst.operands[2].reg;
7890 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7891
682b27ad
PB
7892 /* rdhi and rdlo must be different. */
7893 if (inst.operands[0].reg == inst.operands[1].reg)
7894 as_tsktsk (_("rdhi and rdlo must be different"));
7895
7896 /* rdhi, rdlo and rm must all be different before armv6. */
7897 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7898 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7899 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7900 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7901}
b99bd4ef 7902
c19d1205
ZW
7903static void
7904do_nop (void)
7905{
e7495e45
NS
7906 if (inst.operands[0].present
7907 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
7908 {
7909 /* Architectural NOP hints are CPSR sets with no bits selected. */
7910 inst.instruction &= 0xf0000000;
e7495e45
NS
7911 inst.instruction |= 0x0320f000;
7912 if (inst.operands[0].present)
7913 inst.instruction |= inst.operands[0].imm;
c19d1205 7914 }
b99bd4ef
NC
7915}
7916
c19d1205
ZW
7917/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7918 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7919 Condition defaults to COND_ALWAYS.
7920 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7921
7922static void
c19d1205 7923do_pkhbt (void)
b99bd4ef 7924{
c19d1205
ZW
7925 inst.instruction |= inst.operands[0].reg << 12;
7926 inst.instruction |= inst.operands[1].reg << 16;
7927 inst.instruction |= inst.operands[2].reg;
7928 if (inst.operands[3].present)
7929 encode_arm_shift (3);
7930}
b99bd4ef 7931
c19d1205 7932/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7933
c19d1205
ZW
7934static void
7935do_pkhtb (void)
7936{
7937 if (!inst.operands[3].present)
b99bd4ef 7938 {
c19d1205
ZW
7939 /* If the shift specifier is omitted, turn the instruction
7940 into pkhbt rd, rm, rn. */
7941 inst.instruction &= 0xfff00010;
7942 inst.instruction |= inst.operands[0].reg << 12;
7943 inst.instruction |= inst.operands[1].reg;
7944 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7945 }
7946 else
7947 {
c19d1205
ZW
7948 inst.instruction |= inst.operands[0].reg << 12;
7949 inst.instruction |= inst.operands[1].reg << 16;
7950 inst.instruction |= inst.operands[2].reg;
7951 encode_arm_shift (3);
b99bd4ef
NC
7952 }
7953}
7954
c19d1205
ZW
7955/* ARMv5TE: Preload-Cache
7956
7957 PLD <addr_mode>
7958
7959 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7960
7961static void
c19d1205 7962do_pld (void)
b99bd4ef 7963{
c19d1205
ZW
7964 constraint (!inst.operands[0].isreg,
7965 _("'[' expected after PLD mnemonic"));
7966 constraint (inst.operands[0].postind,
7967 _("post-indexed expression used in preload instruction"));
7968 constraint (inst.operands[0].writeback,
7969 _("writeback used in preload instruction"));
7970 constraint (!inst.operands[0].preind,
7971 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7972 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7973}
b99bd4ef 7974
62b3e311
PB
7975/* ARMv7: PLI <addr_mode> */
7976static void
7977do_pli (void)
7978{
7979 constraint (!inst.operands[0].isreg,
7980 _("'[' expected after PLI mnemonic"));
7981 constraint (inst.operands[0].postind,
7982 _("post-indexed expression used in preload instruction"));
7983 constraint (inst.operands[0].writeback,
7984 _("writeback used in preload instruction"));
7985 constraint (!inst.operands[0].preind,
7986 _("unindexed addressing used in preload instruction"));
7987 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7988 inst.instruction &= ~PRE_INDEX;
7989}
7990
c19d1205
ZW
7991static void
7992do_push_pop (void)
7993{
7994 inst.operands[1] = inst.operands[0];
7995 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7996 inst.operands[0].isreg = 1;
7997 inst.operands[0].writeback = 1;
7998 inst.operands[0].reg = REG_SP;
7999 do_ldmstm ();
8000}
b99bd4ef 8001
c19d1205
ZW
8002/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8003 word at the specified address and the following word
8004 respectively.
8005 Unconditionally executed.
8006 Error if Rn is R15. */
b99bd4ef 8007
c19d1205
ZW
8008static void
8009do_rfe (void)
8010{
8011 inst.instruction |= inst.operands[0].reg << 16;
8012 if (inst.operands[0].writeback)
8013 inst.instruction |= WRITE_BACK;
8014}
b99bd4ef 8015
c19d1205 8016/* ARM V6 ssat (argument parse). */
b99bd4ef 8017
c19d1205
ZW
8018static void
8019do_ssat (void)
8020{
8021 inst.instruction |= inst.operands[0].reg << 12;
8022 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8023 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8024
c19d1205
ZW
8025 if (inst.operands[3].present)
8026 encode_arm_shift (3);
b99bd4ef
NC
8027}
8028
c19d1205 8029/* ARM V6 usat (argument parse). */
b99bd4ef
NC
8030
8031static void
c19d1205 8032do_usat (void)
b99bd4ef 8033{
c19d1205
ZW
8034 inst.instruction |= inst.operands[0].reg << 12;
8035 inst.instruction |= inst.operands[1].imm << 16;
8036 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8037
c19d1205
ZW
8038 if (inst.operands[3].present)
8039 encode_arm_shift (3);
b99bd4ef
NC
8040}
8041
c19d1205 8042/* ARM V6 ssat16 (argument parse). */
09d92015
MM
8043
8044static void
c19d1205 8045do_ssat16 (void)
09d92015 8046{
c19d1205
ZW
8047 inst.instruction |= inst.operands[0].reg << 12;
8048 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8049 inst.instruction |= inst.operands[2].reg;
09d92015
MM
8050}
8051
c19d1205
ZW
8052static void
8053do_usat16 (void)
a737bd4d 8054{
c19d1205
ZW
8055 inst.instruction |= inst.operands[0].reg << 12;
8056 inst.instruction |= inst.operands[1].imm << 16;
8057 inst.instruction |= inst.operands[2].reg;
8058}
a737bd4d 8059
c19d1205
ZW
8060/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8061 preserving the other bits.
a737bd4d 8062
c19d1205
ZW
8063 setend <endian_specifier>, where <endian_specifier> is either
8064 BE or LE. */
a737bd4d 8065
c19d1205
ZW
8066static void
8067do_setend (void)
8068{
8069 if (inst.operands[0].imm)
8070 inst.instruction |= 0x200;
a737bd4d
NC
8071}
8072
8073static void
c19d1205 8074do_shift (void)
a737bd4d 8075{
c19d1205
ZW
8076 unsigned int Rm = (inst.operands[1].present
8077 ? inst.operands[1].reg
8078 : inst.operands[0].reg);
a737bd4d 8079
c19d1205
ZW
8080 inst.instruction |= inst.operands[0].reg << 12;
8081 inst.instruction |= Rm;
8082 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 8083 {
c19d1205
ZW
8084 inst.instruction |= inst.operands[2].reg << 8;
8085 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
8086 }
8087 else
c19d1205 8088 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
8089}
8090
09d92015 8091static void
3eb17e6b 8092do_smc (void)
09d92015 8093{
3eb17e6b 8094 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 8095 inst.reloc.pc_rel = 0;
09d92015
MM
8096}
8097
09d92015 8098static void
c19d1205 8099do_swi (void)
09d92015 8100{
c19d1205
ZW
8101 inst.reloc.type = BFD_RELOC_ARM_SWI;
8102 inst.reloc.pc_rel = 0;
09d92015
MM
8103}
8104
c19d1205
ZW
8105/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8106 SMLAxy{cond} Rd,Rm,Rs,Rn
8107 SMLAWy{cond} Rd,Rm,Rs,Rn
8108 Error if any register is R15. */
e16bb312 8109
c19d1205
ZW
8110static void
8111do_smla (void)
e16bb312 8112{
c19d1205
ZW
8113 inst.instruction |= inst.operands[0].reg << 16;
8114 inst.instruction |= inst.operands[1].reg;
8115 inst.instruction |= inst.operands[2].reg << 8;
8116 inst.instruction |= inst.operands[3].reg << 12;
8117}
a737bd4d 8118
c19d1205
ZW
8119/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8120 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8121 Error if any register is R15.
8122 Warning if Rdlo == Rdhi. */
a737bd4d 8123
c19d1205
ZW
8124static void
8125do_smlal (void)
8126{
8127 inst.instruction |= inst.operands[0].reg << 12;
8128 inst.instruction |= inst.operands[1].reg << 16;
8129 inst.instruction |= inst.operands[2].reg;
8130 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 8131
c19d1205
ZW
8132 if (inst.operands[0].reg == inst.operands[1].reg)
8133 as_tsktsk (_("rdhi and rdlo must be different"));
8134}
a737bd4d 8135
c19d1205
ZW
8136/* ARM V5E (El Segundo) signed-multiply (argument parse)
8137 SMULxy{cond} Rd,Rm,Rs
8138 Error if any register is R15. */
a737bd4d 8139
c19d1205
ZW
8140static void
8141do_smul (void)
8142{
8143 inst.instruction |= inst.operands[0].reg << 16;
8144 inst.instruction |= inst.operands[1].reg;
8145 inst.instruction |= inst.operands[2].reg << 8;
8146}
a737bd4d 8147
b6702015
PB
8148/* ARM V6 srs (argument parse). The variable fields in the encoding are
8149 the same for both ARM and Thumb-2. */
a737bd4d 8150
c19d1205
ZW
8151static void
8152do_srs (void)
8153{
b6702015
PB
8154 int reg;
8155
8156 if (inst.operands[0].present)
8157 {
8158 reg = inst.operands[0].reg;
fdfde340 8159 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
8160 }
8161 else
fdfde340 8162 reg = REG_SP;
b6702015
PB
8163
8164 inst.instruction |= reg << 16;
8165 inst.instruction |= inst.operands[1].imm;
8166 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
8167 inst.instruction |= WRITE_BACK;
8168}
a737bd4d 8169
c19d1205 8170/* ARM V6 strex (argument parse). */
a737bd4d 8171
c19d1205
ZW
8172static void
8173do_strex (void)
8174{
8175 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8176 || inst.operands[2].postind || inst.operands[2].writeback
8177 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
8178 || inst.operands[2].negative
8179 /* See comment in do_ldrex(). */
8180 || (inst.operands[2].reg == REG_PC),
8181 BAD_ADDR_MODE);
a737bd4d 8182
c19d1205
ZW
8183 constraint (inst.operands[0].reg == inst.operands[1].reg
8184 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 8185
c19d1205
ZW
8186 constraint (inst.reloc.exp.X_op != O_constant
8187 || inst.reloc.exp.X_add_number != 0,
8188 _("offset must be zero in ARM encoding"));
a737bd4d 8189
c19d1205
ZW
8190 inst.instruction |= inst.operands[0].reg << 12;
8191 inst.instruction |= inst.operands[1].reg;
8192 inst.instruction |= inst.operands[2].reg << 16;
8193 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8194}
8195
8196static void
c19d1205 8197do_strexd (void)
e16bb312 8198{
c19d1205
ZW
8199 constraint (inst.operands[1].reg % 2 != 0,
8200 _("even register required"));
8201 constraint (inst.operands[2].present
8202 && inst.operands[2].reg != inst.operands[1].reg + 1,
8203 _("can only store two consecutive registers"));
8204 /* If op 2 were present and equal to PC, this function wouldn't
8205 have been called in the first place. */
8206 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8207
c19d1205
ZW
8208 constraint (inst.operands[0].reg == inst.operands[1].reg
8209 || inst.operands[0].reg == inst.operands[1].reg + 1
8210 || inst.operands[0].reg == inst.operands[3].reg,
8211 BAD_OVERLAP);
e16bb312 8212
c19d1205
ZW
8213 inst.instruction |= inst.operands[0].reg << 12;
8214 inst.instruction |= inst.operands[1].reg;
8215 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8216}
8217
c19d1205
ZW
8218/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8219 extends it to 32-bits, and adds the result to a value in another
8220 register. You can specify a rotation by 0, 8, 16, or 24 bits
8221 before extracting the 16-bit value.
8222 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8223 Condition defaults to COND_ALWAYS.
8224 Error if any register uses R15. */
8225
e16bb312 8226static void
c19d1205 8227do_sxtah (void)
e16bb312 8228{
c19d1205
ZW
8229 inst.instruction |= inst.operands[0].reg << 12;
8230 inst.instruction |= inst.operands[1].reg << 16;
8231 inst.instruction |= inst.operands[2].reg;
8232 inst.instruction |= inst.operands[3].imm << 10;
8233}
e16bb312 8234
c19d1205 8235/* ARM V6 SXTH.
e16bb312 8236
c19d1205
ZW
8237 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8238 Condition defaults to COND_ALWAYS.
8239 Error if any register uses R15. */
e16bb312
NC
8240
8241static void
c19d1205 8242do_sxth (void)
e16bb312 8243{
c19d1205
ZW
8244 inst.instruction |= inst.operands[0].reg << 12;
8245 inst.instruction |= inst.operands[1].reg;
8246 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8247}
c19d1205
ZW
8248\f
8249/* VFP instructions. In a logical order: SP variant first, monad
8250 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8251
8252static void
c19d1205 8253do_vfp_sp_monadic (void)
e16bb312 8254{
5287ad62
JB
8255 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8256 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8257}
8258
8259static void
c19d1205 8260do_vfp_sp_dyadic (void)
e16bb312 8261{
5287ad62
JB
8262 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8263 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8264 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8265}
8266
8267static void
c19d1205 8268do_vfp_sp_compare_z (void)
e16bb312 8269{
5287ad62 8270 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8271}
8272
8273static void
c19d1205 8274do_vfp_dp_sp_cvt (void)
e16bb312 8275{
5287ad62
JB
8276 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8277 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8278}
8279
8280static void
c19d1205 8281do_vfp_sp_dp_cvt (void)
e16bb312 8282{
5287ad62
JB
8283 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8284 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8285}
8286
8287static void
c19d1205 8288do_vfp_reg_from_sp (void)
e16bb312 8289{
c19d1205 8290 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8291 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8292}
8293
8294static void
c19d1205 8295do_vfp_reg2_from_sp2 (void)
e16bb312 8296{
c19d1205
ZW
8297 constraint (inst.operands[2].imm != 2,
8298 _("only two consecutive VFP SP registers allowed here"));
8299 inst.instruction |= inst.operands[0].reg << 12;
8300 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8301 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8302}
8303
8304static void
c19d1205 8305do_vfp_sp_from_reg (void)
e16bb312 8306{
5287ad62 8307 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8308 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8309}
8310
8311static void
c19d1205 8312do_vfp_sp2_from_reg2 (void)
e16bb312 8313{
c19d1205
ZW
8314 constraint (inst.operands[0].imm != 2,
8315 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8316 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8317 inst.instruction |= inst.operands[1].reg << 12;
8318 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8319}
8320
8321static void
c19d1205 8322do_vfp_sp_ldst (void)
e16bb312 8323{
5287ad62 8324 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 8325 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8326}
8327
8328static void
c19d1205 8329do_vfp_dp_ldst (void)
e16bb312 8330{
5287ad62 8331 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 8332 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8333}
8334
c19d1205 8335
e16bb312 8336static void
c19d1205 8337vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8338{
c19d1205
ZW
8339 if (inst.operands[0].writeback)
8340 inst.instruction |= WRITE_BACK;
8341 else
8342 constraint (ldstm_type != VFP_LDSTMIA,
8343 _("this addressing mode requires base-register writeback"));
8344 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8345 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 8346 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
8347}
8348
8349static void
c19d1205 8350vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8351{
c19d1205 8352 int count;
e16bb312 8353
c19d1205
ZW
8354 if (inst.operands[0].writeback)
8355 inst.instruction |= WRITE_BACK;
8356 else
8357 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8358 _("this addressing mode requires base-register writeback"));
e16bb312 8359
c19d1205 8360 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8361 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 8362
c19d1205
ZW
8363 count = inst.operands[1].imm << 1;
8364 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8365 count += 1;
e16bb312 8366
c19d1205 8367 inst.instruction |= count;
e16bb312
NC
8368}
8369
8370static void
c19d1205 8371do_vfp_sp_ldstmia (void)
e16bb312 8372{
c19d1205 8373 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8374}
8375
8376static void
c19d1205 8377do_vfp_sp_ldstmdb (void)
e16bb312 8378{
c19d1205 8379 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8380}
8381
8382static void
c19d1205 8383do_vfp_dp_ldstmia (void)
e16bb312 8384{
c19d1205 8385 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8386}
8387
8388static void
c19d1205 8389do_vfp_dp_ldstmdb (void)
e16bb312 8390{
c19d1205 8391 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8392}
8393
8394static void
c19d1205 8395do_vfp_xp_ldstmia (void)
e16bb312 8396{
c19d1205
ZW
8397 vfp_dp_ldstm (VFP_LDSTMIAX);
8398}
e16bb312 8399
c19d1205
ZW
8400static void
8401do_vfp_xp_ldstmdb (void)
8402{
8403 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 8404}
5287ad62
JB
8405
8406static void
8407do_vfp_dp_rd_rm (void)
8408{
8409 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8410 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8411}
8412
8413static void
8414do_vfp_dp_rn_rd (void)
8415{
8416 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8417 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8418}
8419
8420static void
8421do_vfp_dp_rd_rn (void)
8422{
8423 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8424 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8425}
8426
8427static void
8428do_vfp_dp_rd_rn_rm (void)
8429{
8430 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8431 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8432 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8433}
8434
8435static void
8436do_vfp_dp_rd (void)
8437{
8438 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8439}
8440
8441static void
8442do_vfp_dp_rm_rd_rn (void)
8443{
8444 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8445 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8446 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8447}
8448
8449/* VFPv3 instructions. */
8450static void
8451do_vfp_sp_const (void)
8452{
8453 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8454 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8455 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8456}
8457
8458static void
8459do_vfp_dp_const (void)
8460{
8461 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8462 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8463 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8464}
8465
8466static void
8467vfp_conv (int srcsize)
8468{
8469 unsigned immbits = srcsize - inst.operands[1].imm;
8470 inst.instruction |= (immbits & 1) << 5;
8471 inst.instruction |= (immbits >> 1);
8472}
8473
8474static void
8475do_vfp_sp_conv_16 (void)
8476{
8477 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8478 vfp_conv (16);
8479}
8480
8481static void
8482do_vfp_dp_conv_16 (void)
8483{
8484 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8485 vfp_conv (16);
8486}
8487
8488static void
8489do_vfp_sp_conv_32 (void)
8490{
8491 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8492 vfp_conv (32);
8493}
8494
8495static void
8496do_vfp_dp_conv_32 (void)
8497{
8498 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8499 vfp_conv (32);
8500}
c19d1205
ZW
8501\f
8502/* FPA instructions. Also in a logical order. */
e16bb312 8503
c19d1205
ZW
8504static void
8505do_fpa_cmp (void)
8506{
8507 inst.instruction |= inst.operands[0].reg << 16;
8508 inst.instruction |= inst.operands[1].reg;
8509}
b99bd4ef
NC
8510
8511static void
c19d1205 8512do_fpa_ldmstm (void)
b99bd4ef 8513{
c19d1205
ZW
8514 inst.instruction |= inst.operands[0].reg << 12;
8515 switch (inst.operands[1].imm)
8516 {
8517 case 1: inst.instruction |= CP_T_X; break;
8518 case 2: inst.instruction |= CP_T_Y; break;
8519 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8520 case 4: break;
8521 default: abort ();
8522 }
b99bd4ef 8523
c19d1205
ZW
8524 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8525 {
8526 /* The instruction specified "ea" or "fd", so we can only accept
8527 [Rn]{!}. The instruction does not really support stacking or
8528 unstacking, so we have to emulate these by setting appropriate
8529 bits and offsets. */
8530 constraint (inst.reloc.exp.X_op != O_constant
8531 || inst.reloc.exp.X_add_number != 0,
8532 _("this instruction does not support indexing"));
b99bd4ef 8533
c19d1205
ZW
8534 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8535 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8536
c19d1205
ZW
8537 if (!(inst.instruction & INDEX_UP))
8538 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8539
c19d1205
ZW
8540 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8541 {
8542 inst.operands[2].preind = 0;
8543 inst.operands[2].postind = 1;
8544 }
8545 }
b99bd4ef 8546
c19d1205 8547 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8548}
c19d1205
ZW
8549\f
8550/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8551
c19d1205
ZW
8552static void
8553do_iwmmxt_tandorc (void)
8554{
8555 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8556}
b99bd4ef 8557
c19d1205
ZW
8558static void
8559do_iwmmxt_textrc (void)
8560{
8561 inst.instruction |= inst.operands[0].reg << 12;
8562 inst.instruction |= inst.operands[1].imm;
8563}
b99bd4ef
NC
8564
8565static void
c19d1205 8566do_iwmmxt_textrm (void)
b99bd4ef 8567{
c19d1205
ZW
8568 inst.instruction |= inst.operands[0].reg << 12;
8569 inst.instruction |= inst.operands[1].reg << 16;
8570 inst.instruction |= inst.operands[2].imm;
8571}
b99bd4ef 8572
c19d1205
ZW
8573static void
8574do_iwmmxt_tinsr (void)
8575{
8576 inst.instruction |= inst.operands[0].reg << 16;
8577 inst.instruction |= inst.operands[1].reg << 12;
8578 inst.instruction |= inst.operands[2].imm;
8579}
b99bd4ef 8580
c19d1205
ZW
8581static void
8582do_iwmmxt_tmia (void)
8583{
8584 inst.instruction |= inst.operands[0].reg << 5;
8585 inst.instruction |= inst.operands[1].reg;
8586 inst.instruction |= inst.operands[2].reg << 12;
8587}
b99bd4ef 8588
c19d1205
ZW
8589static void
8590do_iwmmxt_waligni (void)
8591{
8592 inst.instruction |= inst.operands[0].reg << 12;
8593 inst.instruction |= inst.operands[1].reg << 16;
8594 inst.instruction |= inst.operands[2].reg;
8595 inst.instruction |= inst.operands[3].imm << 20;
8596}
b99bd4ef 8597
2d447fca
JM
8598static void
8599do_iwmmxt_wmerge (void)
8600{
8601 inst.instruction |= inst.operands[0].reg << 12;
8602 inst.instruction |= inst.operands[1].reg << 16;
8603 inst.instruction |= inst.operands[2].reg;
8604 inst.instruction |= inst.operands[3].imm << 21;
8605}
8606
c19d1205
ZW
8607static void
8608do_iwmmxt_wmov (void)
8609{
8610 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8611 inst.instruction |= inst.operands[0].reg << 12;
8612 inst.instruction |= inst.operands[1].reg << 16;
8613 inst.instruction |= inst.operands[1].reg;
8614}
b99bd4ef 8615
c19d1205
ZW
8616static void
8617do_iwmmxt_wldstbh (void)
8618{
8f06b2d8 8619 int reloc;
c19d1205 8620 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8621 if (thumb_mode)
8622 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8623 else
8624 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8625 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8626}
8627
c19d1205
ZW
8628static void
8629do_iwmmxt_wldstw (void)
8630{
8631 /* RIWR_RIWC clears .isreg for a control register. */
8632 if (!inst.operands[0].isreg)
8633 {
8634 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8635 inst.instruction |= 0xf0000000;
8636 }
b99bd4ef 8637
c19d1205
ZW
8638 inst.instruction |= inst.operands[0].reg << 12;
8639 encode_arm_cp_address (1, TRUE, TRUE, 0);
8640}
b99bd4ef
NC
8641
8642static void
c19d1205 8643do_iwmmxt_wldstd (void)
b99bd4ef 8644{
c19d1205 8645 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8646 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8647 && inst.operands[1].immisreg)
8648 {
8649 inst.instruction &= ~0x1a000ff;
8650 inst.instruction |= (0xf << 28);
8651 if (inst.operands[1].preind)
8652 inst.instruction |= PRE_INDEX;
8653 if (!inst.operands[1].negative)
8654 inst.instruction |= INDEX_UP;
8655 if (inst.operands[1].writeback)
8656 inst.instruction |= WRITE_BACK;
8657 inst.instruction |= inst.operands[1].reg << 16;
8658 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8659 inst.instruction |= inst.operands[1].imm;
8660 }
8661 else
8662 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8663}
b99bd4ef 8664
c19d1205
ZW
8665static void
8666do_iwmmxt_wshufh (void)
8667{
8668 inst.instruction |= inst.operands[0].reg << 12;
8669 inst.instruction |= inst.operands[1].reg << 16;
8670 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8671 inst.instruction |= (inst.operands[2].imm & 0x0f);
8672}
b99bd4ef 8673
c19d1205
ZW
8674static void
8675do_iwmmxt_wzero (void)
8676{
8677 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8678 inst.instruction |= inst.operands[0].reg;
8679 inst.instruction |= inst.operands[0].reg << 12;
8680 inst.instruction |= inst.operands[0].reg << 16;
8681}
2d447fca
JM
8682
8683static void
8684do_iwmmxt_wrwrwr_or_imm5 (void)
8685{
8686 if (inst.operands[2].isreg)
8687 do_rd_rn_rm ();
8688 else {
8689 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8690 _("immediate operand requires iWMMXt2"));
8691 do_rd_rn ();
8692 if (inst.operands[2].imm == 0)
8693 {
8694 switch ((inst.instruction >> 20) & 0xf)
8695 {
8696 case 4:
8697 case 5:
8698 case 6:
5f4273c7 8699 case 7:
2d447fca
JM
8700 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8701 inst.operands[2].imm = 16;
8702 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8703 break;
8704 case 8:
8705 case 9:
8706 case 10:
8707 case 11:
8708 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8709 inst.operands[2].imm = 32;
8710 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8711 break;
8712 case 12:
8713 case 13:
8714 case 14:
8715 case 15:
8716 {
8717 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8718 unsigned long wrn;
8719 wrn = (inst.instruction >> 16) & 0xf;
8720 inst.instruction &= 0xff0fff0f;
8721 inst.instruction |= wrn;
8722 /* Bail out here; the instruction is now assembled. */
8723 return;
8724 }
8725 }
8726 }
8727 /* Map 32 -> 0, etc. */
8728 inst.operands[2].imm &= 0x1f;
8729 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8730 }
8731}
c19d1205
ZW
8732\f
8733/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8734 operations first, then control, shift, and load/store. */
b99bd4ef 8735
c19d1205 8736/* Insns like "foo X,Y,Z". */
b99bd4ef 8737
c19d1205
ZW
8738static void
8739do_mav_triple (void)
8740{
8741 inst.instruction |= inst.operands[0].reg << 16;
8742 inst.instruction |= inst.operands[1].reg;
8743 inst.instruction |= inst.operands[2].reg << 12;
8744}
b99bd4ef 8745
c19d1205
ZW
8746/* Insns like "foo W,X,Y,Z".
8747 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8748
c19d1205
ZW
8749static void
8750do_mav_quad (void)
8751{
8752 inst.instruction |= inst.operands[0].reg << 5;
8753 inst.instruction |= inst.operands[1].reg << 12;
8754 inst.instruction |= inst.operands[2].reg << 16;
8755 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8756}
8757
c19d1205
ZW
8758/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8759static void
8760do_mav_dspsc (void)
a737bd4d 8761{
c19d1205
ZW
8762 inst.instruction |= inst.operands[1].reg << 12;
8763}
a737bd4d 8764
c19d1205
ZW
8765/* Maverick shift immediate instructions.
8766 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8767 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8768
c19d1205
ZW
8769static void
8770do_mav_shift (void)
8771{
8772 int imm = inst.operands[2].imm;
a737bd4d 8773
c19d1205
ZW
8774 inst.instruction |= inst.operands[0].reg << 12;
8775 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8776
c19d1205
ZW
8777 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8778 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8779 Bit 4 should be 0. */
8780 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8781
c19d1205
ZW
8782 inst.instruction |= imm;
8783}
8784\f
8785/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8786
c19d1205
ZW
8787/* Xscale multiply-accumulate (argument parse)
8788 MIAcc acc0,Rm,Rs
8789 MIAPHcc acc0,Rm,Rs
8790 MIAxycc acc0,Rm,Rs. */
a737bd4d 8791
c19d1205
ZW
8792static void
8793do_xsc_mia (void)
8794{
8795 inst.instruction |= inst.operands[1].reg;
8796 inst.instruction |= inst.operands[2].reg << 12;
8797}
a737bd4d 8798
c19d1205 8799/* Xscale move-accumulator-register (argument parse)
a737bd4d 8800
c19d1205 8801 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8802
c19d1205
ZW
8803static void
8804do_xsc_mar (void)
8805{
8806 inst.instruction |= inst.operands[1].reg << 12;
8807 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8808}
8809
c19d1205 8810/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8811
c19d1205 8812 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8813
8814static void
c19d1205 8815do_xsc_mra (void)
b99bd4ef 8816{
c19d1205
ZW
8817 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8818 inst.instruction |= inst.operands[0].reg << 12;
8819 inst.instruction |= inst.operands[1].reg << 16;
8820}
8821\f
8822/* Encoding functions relevant only to Thumb. */
b99bd4ef 8823
c19d1205
ZW
8824/* inst.operands[i] is a shifted-register operand; encode
8825 it into inst.instruction in the format used by Thumb32. */
8826
8827static void
8828encode_thumb32_shifted_operand (int i)
8829{
8830 unsigned int value = inst.reloc.exp.X_add_number;
8831 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8832
9c3c69f2
PB
8833 constraint (inst.operands[i].immisreg,
8834 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8835 inst.instruction |= inst.operands[i].reg;
8836 if (shift == SHIFT_RRX)
8837 inst.instruction |= SHIFT_ROR << 4;
8838 else
b99bd4ef 8839 {
c19d1205
ZW
8840 constraint (inst.reloc.exp.X_op != O_constant,
8841 _("expression too complex"));
8842
8843 constraint (value > 32
8844 || (value == 32 && (shift == SHIFT_LSL
8845 || shift == SHIFT_ROR)),
8846 _("shift expression is too large"));
8847
8848 if (value == 0)
8849 shift = SHIFT_LSL;
8850 else if (value == 32)
8851 value = 0;
8852
8853 inst.instruction |= shift << 4;
8854 inst.instruction |= (value & 0x1c) << 10;
8855 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8856 }
c19d1205 8857}
b99bd4ef 8858
b99bd4ef 8859
c19d1205
ZW
8860/* inst.operands[i] was set up by parse_address. Encode it into a
8861 Thumb32 format load or store instruction. Reject forms that cannot
8862 be used with such instructions. If is_t is true, reject forms that
8863 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
8864 that cannot be used with a D instruction. If it is a store insn,
8865 reject PC in Rn. */
b99bd4ef 8866
c19d1205
ZW
8867static void
8868encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8869{
5be8be5d 8870 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
8871
8872 constraint (!inst.operands[i].isreg,
53365c0d 8873 _("Instruction does not support =N addresses"));
b99bd4ef 8874
c19d1205
ZW
8875 inst.instruction |= inst.operands[i].reg << 16;
8876 if (inst.operands[i].immisreg)
b99bd4ef 8877 {
5be8be5d 8878 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
8879 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8880 constraint (inst.operands[i].negative,
8881 _("Thumb does not support negative register indexing"));
8882 constraint (inst.operands[i].postind,
8883 _("Thumb does not support register post-indexing"));
8884 constraint (inst.operands[i].writeback,
8885 _("Thumb does not support register indexing with writeback"));
8886 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8887 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8888
f40d1643 8889 inst.instruction |= inst.operands[i].imm;
c19d1205 8890 if (inst.operands[i].shifted)
b99bd4ef 8891 {
c19d1205
ZW
8892 constraint (inst.reloc.exp.X_op != O_constant,
8893 _("expression too complex"));
9c3c69f2
PB
8894 constraint (inst.reloc.exp.X_add_number < 0
8895 || inst.reloc.exp.X_add_number > 3,
c19d1205 8896 _("shift out of range"));
9c3c69f2 8897 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8898 }
8899 inst.reloc.type = BFD_RELOC_UNUSED;
8900 }
8901 else if (inst.operands[i].preind)
8902 {
5be8be5d 8903 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 8904 constraint (is_t && inst.operands[i].writeback,
c19d1205 8905 _("cannot use writeback with this instruction"));
5be8be5d
DG
8906 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
8907 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
c19d1205
ZW
8908
8909 if (is_d)
8910 {
8911 inst.instruction |= 0x01000000;
8912 if (inst.operands[i].writeback)
8913 inst.instruction |= 0x00200000;
b99bd4ef 8914 }
c19d1205 8915 else
b99bd4ef 8916 {
c19d1205
ZW
8917 inst.instruction |= 0x00000c00;
8918 if (inst.operands[i].writeback)
8919 inst.instruction |= 0x00000100;
b99bd4ef 8920 }
c19d1205 8921 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8922 }
c19d1205 8923 else if (inst.operands[i].postind)
b99bd4ef 8924 {
9c2799c2 8925 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8926 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8927 constraint (is_t, _("cannot use post-indexing with this instruction"));
8928
8929 if (is_d)
8930 inst.instruction |= 0x00200000;
8931 else
8932 inst.instruction |= 0x00000900;
8933 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8934 }
8935 else /* unindexed - only for coprocessor */
8936 inst.error = _("instruction does not accept unindexed addressing");
8937}
8938
8939/* Table of Thumb instructions which exist in both 16- and 32-bit
8940 encodings (the latter only in post-V6T2 cores). The index is the
8941 value used in the insns table below. When there is more than one
8942 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8943 holds variant (1).
8944 Also contains several pseudo-instructions used during relaxation. */
c19d1205 8945#define T16_32_TAB \
21d799b5
NC
8946 X(_adc, 4140, eb400000), \
8947 X(_adcs, 4140, eb500000), \
8948 X(_add, 1c00, eb000000), \
8949 X(_adds, 1c00, eb100000), \
8950 X(_addi, 0000, f1000000), \
8951 X(_addis, 0000, f1100000), \
8952 X(_add_pc,000f, f20f0000), \
8953 X(_add_sp,000d, f10d0000), \
8954 X(_adr, 000f, f20f0000), \
8955 X(_and, 4000, ea000000), \
8956 X(_ands, 4000, ea100000), \
8957 X(_asr, 1000, fa40f000), \
8958 X(_asrs, 1000, fa50f000), \
8959 X(_b, e000, f000b000), \
8960 X(_bcond, d000, f0008000), \
8961 X(_bic, 4380, ea200000), \
8962 X(_bics, 4380, ea300000), \
8963 X(_cmn, 42c0, eb100f00), \
8964 X(_cmp, 2800, ebb00f00), \
8965 X(_cpsie, b660, f3af8400), \
8966 X(_cpsid, b670, f3af8600), \
8967 X(_cpy, 4600, ea4f0000), \
8968 X(_dec_sp,80dd, f1ad0d00), \
8969 X(_eor, 4040, ea800000), \
8970 X(_eors, 4040, ea900000), \
8971 X(_inc_sp,00dd, f10d0d00), \
8972 X(_ldmia, c800, e8900000), \
8973 X(_ldr, 6800, f8500000), \
8974 X(_ldrb, 7800, f8100000), \
8975 X(_ldrh, 8800, f8300000), \
8976 X(_ldrsb, 5600, f9100000), \
8977 X(_ldrsh, 5e00, f9300000), \
8978 X(_ldr_pc,4800, f85f0000), \
8979 X(_ldr_pc2,4800, f85f0000), \
8980 X(_ldr_sp,9800, f85d0000), \
8981 X(_lsl, 0000, fa00f000), \
8982 X(_lsls, 0000, fa10f000), \
8983 X(_lsr, 0800, fa20f000), \
8984 X(_lsrs, 0800, fa30f000), \
8985 X(_mov, 2000, ea4f0000), \
8986 X(_movs, 2000, ea5f0000), \
8987 X(_mul, 4340, fb00f000), \
8988 X(_muls, 4340, ffffffff), /* no 32b muls */ \
8989 X(_mvn, 43c0, ea6f0000), \
8990 X(_mvns, 43c0, ea7f0000), \
8991 X(_neg, 4240, f1c00000), /* rsb #0 */ \
8992 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
8993 X(_orr, 4300, ea400000), \
8994 X(_orrs, 4300, ea500000), \
8995 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8996 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
8997 X(_rev, ba00, fa90f080), \
8998 X(_rev16, ba40, fa90f090), \
8999 X(_revsh, bac0, fa90f0b0), \
9000 X(_ror, 41c0, fa60f000), \
9001 X(_rors, 41c0, fa70f000), \
9002 X(_sbc, 4180, eb600000), \
9003 X(_sbcs, 4180, eb700000), \
9004 X(_stmia, c000, e8800000), \
9005 X(_str, 6000, f8400000), \
9006 X(_strb, 7000, f8000000), \
9007 X(_strh, 8000, f8200000), \
9008 X(_str_sp,9000, f84d0000), \
9009 X(_sub, 1e00, eba00000), \
9010 X(_subs, 1e00, ebb00000), \
9011 X(_subi, 8000, f1a00000), \
9012 X(_subis, 8000, f1b00000), \
9013 X(_sxtb, b240, fa4ff080), \
9014 X(_sxth, b200, fa0ff080), \
9015 X(_tst, 4200, ea100f00), \
9016 X(_uxtb, b2c0, fa5ff080), \
9017 X(_uxth, b280, fa1ff080), \
9018 X(_nop, bf00, f3af8000), \
9019 X(_yield, bf10, f3af8001), \
9020 X(_wfe, bf20, f3af8002), \
9021 X(_wfi, bf30, f3af8003), \
9022 X(_sev, bf40, f3af8004),
c19d1205
ZW
9023
9024/* To catch errors in encoding functions, the codes are all offset by
9025 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9026 as 16-bit instructions. */
21d799b5 9027#define X(a,b,c) T_MNEM##a
c19d1205
ZW
9028enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9029#undef X
9030
9031#define X(a,b,c) 0x##b
9032static const unsigned short thumb_op16[] = { T16_32_TAB };
9033#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9034#undef X
9035
9036#define X(a,b,c) 0x##c
9037static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
9038#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9039#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
9040#undef X
9041#undef T16_32_TAB
9042
9043/* Thumb instruction encoders, in alphabetical order. */
9044
92e90b6e 9045/* ADDW or SUBW. */
c921be7d 9046
92e90b6e
PB
9047static void
9048do_t_add_sub_w (void)
9049{
9050 int Rd, Rn;
9051
9052 Rd = inst.operands[0].reg;
9053 Rn = inst.operands[1].reg;
9054
539d4391
NC
9055 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9056 is the SP-{plus,minus}-immediate form of the instruction. */
9057 if (Rn == REG_SP)
9058 constraint (Rd == REG_PC, BAD_PC);
9059 else
9060 reject_bad_reg (Rd);
fdfde340 9061
92e90b6e
PB
9062 inst.instruction |= (Rn << 16) | (Rd << 8);
9063 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9064}
9065
c19d1205
ZW
9066/* Parse an add or subtract instruction. We get here with inst.instruction
9067 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9068
9069static void
9070do_t_add_sub (void)
9071{
9072 int Rd, Rs, Rn;
9073
9074 Rd = inst.operands[0].reg;
9075 Rs = (inst.operands[1].present
9076 ? inst.operands[1].reg /* Rd, Rs, foo */
9077 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9078
e07e6e58
NC
9079 if (Rd == REG_PC)
9080 set_it_insn_type_last ();
9081
c19d1205
ZW
9082 if (unified_syntax)
9083 {
0110f2b8
PB
9084 bfd_boolean flags;
9085 bfd_boolean narrow;
9086 int opcode;
9087
9088 flags = (inst.instruction == T_MNEM_adds
9089 || inst.instruction == T_MNEM_subs);
9090 if (flags)
e07e6e58 9091 narrow = !in_it_block ();
0110f2b8 9092 else
e07e6e58 9093 narrow = in_it_block ();
c19d1205 9094 if (!inst.operands[2].isreg)
b99bd4ef 9095 {
16805f35
PB
9096 int add;
9097
fdfde340
JM
9098 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9099
16805f35
PB
9100 add = (inst.instruction == T_MNEM_add
9101 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
9102 opcode = 0;
9103 if (inst.size_req != 4)
9104 {
0110f2b8
PB
9105 /* Attempt to use a narrow opcode, with relaxation if
9106 appropriate. */
9107 if (Rd == REG_SP && Rs == REG_SP && !flags)
9108 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9109 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9110 opcode = T_MNEM_add_sp;
9111 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9112 opcode = T_MNEM_add_pc;
9113 else if (Rd <= 7 && Rs <= 7 && narrow)
9114 {
9115 if (flags)
9116 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9117 else
9118 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9119 }
9120 if (opcode)
9121 {
9122 inst.instruction = THUMB_OP16(opcode);
9123 inst.instruction |= (Rd << 4) | Rs;
9124 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9125 if (inst.size_req != 2)
9126 inst.relax = opcode;
9127 }
9128 else
9129 constraint (inst.size_req == 2, BAD_HIREG);
9130 }
9131 if (inst.size_req == 4
9132 || (inst.size_req != 2 && !opcode))
9133 {
efd81785
PB
9134 if (Rd == REG_PC)
9135 {
fdfde340 9136 constraint (add, BAD_PC);
efd81785
PB
9137 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9138 _("only SUBS PC, LR, #const allowed"));
9139 constraint (inst.reloc.exp.X_op != O_constant,
9140 _("expression too complex"));
9141 constraint (inst.reloc.exp.X_add_number < 0
9142 || inst.reloc.exp.X_add_number > 0xff,
9143 _("immediate value out of range"));
9144 inst.instruction = T2_SUBS_PC_LR
9145 | inst.reloc.exp.X_add_number;
9146 inst.reloc.type = BFD_RELOC_UNUSED;
9147 return;
9148 }
9149 else if (Rs == REG_PC)
16805f35
PB
9150 {
9151 /* Always use addw/subw. */
9152 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9153 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9154 }
9155 else
9156 {
9157 inst.instruction = THUMB_OP32 (inst.instruction);
9158 inst.instruction = (inst.instruction & 0xe1ffffff)
9159 | 0x10000000;
9160 if (flags)
9161 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9162 else
9163 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9164 }
dc4503c6
PB
9165 inst.instruction |= Rd << 8;
9166 inst.instruction |= Rs << 16;
0110f2b8 9167 }
b99bd4ef 9168 }
c19d1205
ZW
9169 else
9170 {
9171 Rn = inst.operands[2].reg;
9172 /* See if we can do this with a 16-bit instruction. */
9173 if (!inst.operands[2].shifted && inst.size_req != 4)
9174 {
e27ec89e
PB
9175 if (Rd > 7 || Rs > 7 || Rn > 7)
9176 narrow = FALSE;
9177
9178 if (narrow)
c19d1205 9179 {
e27ec89e
PB
9180 inst.instruction = ((inst.instruction == T_MNEM_adds
9181 || inst.instruction == T_MNEM_add)
c19d1205
ZW
9182 ? T_OPCODE_ADD_R3
9183 : T_OPCODE_SUB_R3);
9184 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9185 return;
9186 }
b99bd4ef 9187
7e806470 9188 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 9189 {
7e806470
PB
9190 /* Thumb-1 cores (except v6-M) require at least one high
9191 register in a narrow non flag setting add. */
9192 if (Rd > 7 || Rn > 7
9193 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9194 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9195 {
7e806470
PB
9196 if (Rd == Rn)
9197 {
9198 Rn = Rs;
9199 Rs = Rd;
9200 }
c19d1205
ZW
9201 inst.instruction = T_OPCODE_ADD_HI;
9202 inst.instruction |= (Rd & 8) << 4;
9203 inst.instruction |= (Rd & 7);
9204 inst.instruction |= Rn << 3;
9205 return;
9206 }
c19d1205
ZW
9207 }
9208 }
c921be7d 9209
fdfde340
JM
9210 constraint (Rd == REG_PC, BAD_PC);
9211 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9212 constraint (Rs == REG_PC, BAD_PC);
9213 reject_bad_reg (Rn);
9214
c19d1205
ZW
9215 /* If we get here, it can't be done in 16 bits. */
9216 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9217 _("shift must be constant"));
9218 inst.instruction = THUMB_OP32 (inst.instruction);
9219 inst.instruction |= Rd << 8;
9220 inst.instruction |= Rs << 16;
9221 encode_thumb32_shifted_operand (2);
9222 }
9223 }
9224 else
9225 {
9226 constraint (inst.instruction == T_MNEM_adds
9227 || inst.instruction == T_MNEM_subs,
9228 BAD_THUMB32);
b99bd4ef 9229
c19d1205 9230 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9231 {
c19d1205
ZW
9232 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9233 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9234 BAD_HIREG);
9235
9236 inst.instruction = (inst.instruction == T_MNEM_add
9237 ? 0x0000 : 0x8000);
9238 inst.instruction |= (Rd << 4) | Rs;
9239 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9240 return;
9241 }
9242
c19d1205
ZW
9243 Rn = inst.operands[2].reg;
9244 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9245
c19d1205
ZW
9246 /* We now have Rd, Rs, and Rn set to registers. */
9247 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9248 {
c19d1205
ZW
9249 /* Can't do this for SUB. */
9250 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9251 inst.instruction = T_OPCODE_ADD_HI;
9252 inst.instruction |= (Rd & 8) << 4;
9253 inst.instruction |= (Rd & 7);
9254 if (Rs == Rd)
9255 inst.instruction |= Rn << 3;
9256 else if (Rn == Rd)
9257 inst.instruction |= Rs << 3;
9258 else
9259 constraint (1, _("dest must overlap one source register"));
9260 }
9261 else
9262 {
9263 inst.instruction = (inst.instruction == T_MNEM_add
9264 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9265 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9266 }
b99bd4ef 9267 }
b99bd4ef
NC
9268}
9269
c19d1205
ZW
9270static void
9271do_t_adr (void)
9272{
fdfde340
JM
9273 unsigned Rd;
9274
9275 Rd = inst.operands[0].reg;
9276 reject_bad_reg (Rd);
9277
9278 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9279 {
9280 /* Defer to section relaxation. */
9281 inst.relax = inst.instruction;
9282 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9283 inst.instruction |= Rd << 4;
0110f2b8
PB
9284 }
9285 else if (unified_syntax && inst.size_req != 2)
e9f89963 9286 {
0110f2b8 9287 /* Generate a 32-bit opcode. */
e9f89963 9288 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9289 inst.instruction |= Rd << 8;
e9f89963
PB
9290 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9291 inst.reloc.pc_rel = 1;
9292 }
9293 else
9294 {
0110f2b8 9295 /* Generate a 16-bit opcode. */
e9f89963
PB
9296 inst.instruction = THUMB_OP16 (inst.instruction);
9297 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9298 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9299 inst.reloc.pc_rel = 1;
b99bd4ef 9300
fdfde340 9301 inst.instruction |= Rd << 4;
e9f89963 9302 }
c19d1205 9303}
b99bd4ef 9304
c19d1205
ZW
9305/* Arithmetic instructions for which there is just one 16-bit
9306 instruction encoding, and it allows only two low registers.
9307 For maximal compatibility with ARM syntax, we allow three register
9308 operands even when Thumb-32 instructions are not available, as long
9309 as the first two are identical. For instance, both "sbc r0,r1" and
9310 "sbc r0,r0,r1" are allowed. */
b99bd4ef 9311static void
c19d1205 9312do_t_arit3 (void)
b99bd4ef 9313{
c19d1205 9314 int Rd, Rs, Rn;
b99bd4ef 9315
c19d1205
ZW
9316 Rd = inst.operands[0].reg;
9317 Rs = (inst.operands[1].present
9318 ? inst.operands[1].reg /* Rd, Rs, foo */
9319 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9320 Rn = inst.operands[2].reg;
b99bd4ef 9321
fdfde340
JM
9322 reject_bad_reg (Rd);
9323 reject_bad_reg (Rs);
9324 if (inst.operands[2].isreg)
9325 reject_bad_reg (Rn);
9326
c19d1205 9327 if (unified_syntax)
b99bd4ef 9328 {
c19d1205
ZW
9329 if (!inst.operands[2].isreg)
9330 {
9331 /* For an immediate, we always generate a 32-bit opcode;
9332 section relaxation will shrink it later if possible. */
9333 inst.instruction = THUMB_OP32 (inst.instruction);
9334 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9335 inst.instruction |= Rd << 8;
9336 inst.instruction |= Rs << 16;
9337 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9338 }
9339 else
9340 {
e27ec89e
PB
9341 bfd_boolean narrow;
9342
c19d1205 9343 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9344 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9345 narrow = !in_it_block ();
e27ec89e 9346 else
e07e6e58 9347 narrow = in_it_block ();
e27ec89e
PB
9348
9349 if (Rd > 7 || Rn > 7 || Rs > 7)
9350 narrow = FALSE;
9351 if (inst.operands[2].shifted)
9352 narrow = FALSE;
9353 if (inst.size_req == 4)
9354 narrow = FALSE;
9355
9356 if (narrow
c19d1205
ZW
9357 && Rd == Rs)
9358 {
9359 inst.instruction = THUMB_OP16 (inst.instruction);
9360 inst.instruction |= Rd;
9361 inst.instruction |= Rn << 3;
9362 return;
9363 }
b99bd4ef 9364
c19d1205
ZW
9365 /* If we get here, it can't be done in 16 bits. */
9366 constraint (inst.operands[2].shifted
9367 && inst.operands[2].immisreg,
9368 _("shift must be constant"));
9369 inst.instruction = THUMB_OP32 (inst.instruction);
9370 inst.instruction |= Rd << 8;
9371 inst.instruction |= Rs << 16;
9372 encode_thumb32_shifted_operand (2);
9373 }
a737bd4d 9374 }
c19d1205 9375 else
b99bd4ef 9376 {
c19d1205
ZW
9377 /* On its face this is a lie - the instruction does set the
9378 flags. However, the only supported mnemonic in this mode
9379 says it doesn't. */
9380 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9381
c19d1205
ZW
9382 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9383 _("unshifted register required"));
9384 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9385 constraint (Rd != Rs,
9386 _("dest and source1 must be the same register"));
a737bd4d 9387
c19d1205
ZW
9388 inst.instruction = THUMB_OP16 (inst.instruction);
9389 inst.instruction |= Rd;
9390 inst.instruction |= Rn << 3;
b99bd4ef 9391 }
a737bd4d 9392}
b99bd4ef 9393
c19d1205
ZW
9394/* Similarly, but for instructions where the arithmetic operation is
9395 commutative, so we can allow either of them to be different from
9396 the destination operand in a 16-bit instruction. For instance, all
9397 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9398 accepted. */
9399static void
9400do_t_arit3c (void)
a737bd4d 9401{
c19d1205 9402 int Rd, Rs, Rn;
b99bd4ef 9403
c19d1205
ZW
9404 Rd = inst.operands[0].reg;
9405 Rs = (inst.operands[1].present
9406 ? inst.operands[1].reg /* Rd, Rs, foo */
9407 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9408 Rn = inst.operands[2].reg;
c921be7d 9409
fdfde340
JM
9410 reject_bad_reg (Rd);
9411 reject_bad_reg (Rs);
9412 if (inst.operands[2].isreg)
9413 reject_bad_reg (Rn);
a737bd4d 9414
c19d1205 9415 if (unified_syntax)
a737bd4d 9416 {
c19d1205 9417 if (!inst.operands[2].isreg)
b99bd4ef 9418 {
c19d1205
ZW
9419 /* For an immediate, we always generate a 32-bit opcode;
9420 section relaxation will shrink it later if possible. */
9421 inst.instruction = THUMB_OP32 (inst.instruction);
9422 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9423 inst.instruction |= Rd << 8;
9424 inst.instruction |= Rs << 16;
9425 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9426 }
c19d1205 9427 else
a737bd4d 9428 {
e27ec89e
PB
9429 bfd_boolean narrow;
9430
c19d1205 9431 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9432 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9433 narrow = !in_it_block ();
e27ec89e 9434 else
e07e6e58 9435 narrow = in_it_block ();
e27ec89e
PB
9436
9437 if (Rd > 7 || Rn > 7 || Rs > 7)
9438 narrow = FALSE;
9439 if (inst.operands[2].shifted)
9440 narrow = FALSE;
9441 if (inst.size_req == 4)
9442 narrow = FALSE;
9443
9444 if (narrow)
a737bd4d 9445 {
c19d1205 9446 if (Rd == Rs)
a737bd4d 9447 {
c19d1205
ZW
9448 inst.instruction = THUMB_OP16 (inst.instruction);
9449 inst.instruction |= Rd;
9450 inst.instruction |= Rn << 3;
9451 return;
a737bd4d 9452 }
c19d1205 9453 if (Rd == Rn)
a737bd4d 9454 {
c19d1205
ZW
9455 inst.instruction = THUMB_OP16 (inst.instruction);
9456 inst.instruction |= Rd;
9457 inst.instruction |= Rs << 3;
9458 return;
a737bd4d
NC
9459 }
9460 }
c19d1205
ZW
9461
9462 /* If we get here, it can't be done in 16 bits. */
9463 constraint (inst.operands[2].shifted
9464 && inst.operands[2].immisreg,
9465 _("shift must be constant"));
9466 inst.instruction = THUMB_OP32 (inst.instruction);
9467 inst.instruction |= Rd << 8;
9468 inst.instruction |= Rs << 16;
9469 encode_thumb32_shifted_operand (2);
a737bd4d 9470 }
b99bd4ef 9471 }
c19d1205
ZW
9472 else
9473 {
9474 /* On its face this is a lie - the instruction does set the
9475 flags. However, the only supported mnemonic in this mode
9476 says it doesn't. */
9477 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9478
c19d1205
ZW
9479 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9480 _("unshifted register required"));
9481 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9482
9483 inst.instruction = THUMB_OP16 (inst.instruction);
9484 inst.instruction |= Rd;
9485
9486 if (Rd == Rs)
9487 inst.instruction |= Rn << 3;
9488 else if (Rd == Rn)
9489 inst.instruction |= Rs << 3;
9490 else
9491 constraint (1, _("dest must overlap one source register"));
9492 }
a737bd4d
NC
9493}
9494
62b3e311
PB
9495static void
9496do_t_barrier (void)
9497{
9498 if (inst.operands[0].present)
9499 {
9500 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
9501 && inst.operands[0].imm > 0xf
9502 && inst.operands[0].imm < 0x0,
bd3ba5d1 9503 _("bad barrier type"));
62b3e311
PB
9504 inst.instruction |= inst.operands[0].imm;
9505 }
9506 else
9507 inst.instruction |= 0xf;
9508}
9509
c19d1205
ZW
9510static void
9511do_t_bfc (void)
a737bd4d 9512{
fdfde340 9513 unsigned Rd;
c19d1205
ZW
9514 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9515 constraint (msb > 32, _("bit-field extends past end of register"));
9516 /* The instruction encoding stores the LSB and MSB,
9517 not the LSB and width. */
fdfde340
JM
9518 Rd = inst.operands[0].reg;
9519 reject_bad_reg (Rd);
9520 inst.instruction |= Rd << 8;
c19d1205
ZW
9521 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9522 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9523 inst.instruction |= msb - 1;
b99bd4ef
NC
9524}
9525
c19d1205
ZW
9526static void
9527do_t_bfi (void)
b99bd4ef 9528{
fdfde340 9529 int Rd, Rn;
c19d1205 9530 unsigned int msb;
b99bd4ef 9531
fdfde340
JM
9532 Rd = inst.operands[0].reg;
9533 reject_bad_reg (Rd);
9534
c19d1205
ZW
9535 /* #0 in second position is alternative syntax for bfc, which is
9536 the same instruction but with REG_PC in the Rm field. */
9537 if (!inst.operands[1].isreg)
fdfde340
JM
9538 Rn = REG_PC;
9539 else
9540 {
9541 Rn = inst.operands[1].reg;
9542 reject_bad_reg (Rn);
9543 }
b99bd4ef 9544
c19d1205
ZW
9545 msb = inst.operands[2].imm + inst.operands[3].imm;
9546 constraint (msb > 32, _("bit-field extends past end of register"));
9547 /* The instruction encoding stores the LSB and MSB,
9548 not the LSB and width. */
fdfde340
JM
9549 inst.instruction |= Rd << 8;
9550 inst.instruction |= Rn << 16;
c19d1205
ZW
9551 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9552 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9553 inst.instruction |= msb - 1;
b99bd4ef
NC
9554}
9555
c19d1205
ZW
9556static void
9557do_t_bfx (void)
b99bd4ef 9558{
fdfde340
JM
9559 unsigned Rd, Rn;
9560
9561 Rd = inst.operands[0].reg;
9562 Rn = inst.operands[1].reg;
9563
9564 reject_bad_reg (Rd);
9565 reject_bad_reg (Rn);
9566
c19d1205
ZW
9567 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9568 _("bit-field extends past end of register"));
fdfde340
JM
9569 inst.instruction |= Rd << 8;
9570 inst.instruction |= Rn << 16;
c19d1205
ZW
9571 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9572 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9573 inst.instruction |= inst.operands[3].imm - 1;
9574}
b99bd4ef 9575
c19d1205
ZW
9576/* ARM V5 Thumb BLX (argument parse)
9577 BLX <target_addr> which is BLX(1)
9578 BLX <Rm> which is BLX(2)
9579 Unfortunately, there are two different opcodes for this mnemonic.
9580 So, the insns[].value is not used, and the code here zaps values
9581 into inst.instruction.
b99bd4ef 9582
c19d1205
ZW
9583 ??? How to take advantage of the additional two bits of displacement
9584 available in Thumb32 mode? Need new relocation? */
b99bd4ef 9585
c19d1205
ZW
9586static void
9587do_t_blx (void)
9588{
e07e6e58
NC
9589 set_it_insn_type_last ();
9590
c19d1205 9591 if (inst.operands[0].isreg)
fdfde340
JM
9592 {
9593 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9594 /* We have a register, so this is BLX(2). */
9595 inst.instruction |= inst.operands[0].reg << 3;
9596 }
b99bd4ef
NC
9597 else
9598 {
c19d1205 9599 /* No register. This must be BLX(1). */
2fc8bdac 9600 inst.instruction = 0xf000e800;
00adf2d4 9601 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 9602 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9603 }
9604}
9605
c19d1205
ZW
9606static void
9607do_t_branch (void)
b99bd4ef 9608{
0110f2b8 9609 int opcode;
dfa9f0d5
PB
9610 int cond;
9611
e07e6e58
NC
9612 cond = inst.cond;
9613 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9614
9615 if (in_it_block ())
dfa9f0d5
PB
9616 {
9617 /* Conditional branches inside IT blocks are encoded as unconditional
9618 branches. */
9619 cond = COND_ALWAYS;
dfa9f0d5
PB
9620 }
9621 else
9622 cond = inst.cond;
9623
9624 if (cond != COND_ALWAYS)
0110f2b8
PB
9625 opcode = T_MNEM_bcond;
9626 else
9627 opcode = inst.instruction;
9628
9629 if (unified_syntax && inst.size_req == 4)
c19d1205 9630 {
0110f2b8 9631 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9632 if (cond == COND_ALWAYS)
0110f2b8 9633 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9634 else
9635 {
9c2799c2 9636 gas_assert (cond != 0xF);
dfa9f0d5 9637 inst.instruction |= cond << 22;
c19d1205
ZW
9638 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9639 }
9640 }
b99bd4ef
NC
9641 else
9642 {
0110f2b8 9643 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9644 if (cond == COND_ALWAYS)
c19d1205
ZW
9645 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9646 else
b99bd4ef 9647 {
dfa9f0d5 9648 inst.instruction |= cond << 8;
c19d1205 9649 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9650 }
0110f2b8
PB
9651 /* Allow section relaxation. */
9652 if (unified_syntax && inst.size_req != 2)
9653 inst.relax = opcode;
b99bd4ef 9654 }
c19d1205
ZW
9655
9656 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9657}
9658
9659static void
c19d1205 9660do_t_bkpt (void)
b99bd4ef 9661{
dfa9f0d5
PB
9662 constraint (inst.cond != COND_ALWAYS,
9663 _("instruction is always unconditional"));
c19d1205 9664 if (inst.operands[0].present)
b99bd4ef 9665 {
c19d1205
ZW
9666 constraint (inst.operands[0].imm > 255,
9667 _("immediate value out of range"));
9668 inst.instruction |= inst.operands[0].imm;
e07e6e58 9669 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 9670 }
b99bd4ef
NC
9671}
9672
9673static void
c19d1205 9674do_t_branch23 (void)
b99bd4ef 9675{
e07e6e58 9676 set_it_insn_type_last ();
c19d1205 9677 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
9678 inst.reloc.pc_rel = 1;
9679
4343666d 9680#if defined(OBJ_COFF)
c19d1205
ZW
9681 /* If the destination of the branch is a defined symbol which does not have
9682 the THUMB_FUNC attribute, then we must be calling a function which has
9683 the (interfacearm) attribute. We look for the Thumb entry point to that
9684 function and change the branch to refer to that function instead. */
9685 if ( inst.reloc.exp.X_op == O_symbol
9686 && inst.reloc.exp.X_add_symbol != NULL
9687 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9688 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9689 inst.reloc.exp.X_add_symbol =
9690 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 9691#endif
90e4755a
RE
9692}
9693
9694static void
c19d1205 9695do_t_bx (void)
90e4755a 9696{
e07e6e58 9697 set_it_insn_type_last ();
c19d1205
ZW
9698 inst.instruction |= inst.operands[0].reg << 3;
9699 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9700 should cause the alignment to be checked once it is known. This is
9701 because BX PC only works if the instruction is word aligned. */
9702}
90e4755a 9703
c19d1205
ZW
9704static void
9705do_t_bxj (void)
9706{
fdfde340 9707 int Rm;
90e4755a 9708
e07e6e58 9709 set_it_insn_type_last ();
fdfde340
JM
9710 Rm = inst.operands[0].reg;
9711 reject_bad_reg (Rm);
9712 inst.instruction |= Rm << 16;
90e4755a
RE
9713}
9714
9715static void
c19d1205 9716do_t_clz (void)
90e4755a 9717{
fdfde340
JM
9718 unsigned Rd;
9719 unsigned Rm;
9720
9721 Rd = inst.operands[0].reg;
9722 Rm = inst.operands[1].reg;
9723
9724 reject_bad_reg (Rd);
9725 reject_bad_reg (Rm);
9726
9727 inst.instruction |= Rd << 8;
9728 inst.instruction |= Rm << 16;
9729 inst.instruction |= Rm;
c19d1205 9730}
90e4755a 9731
dfa9f0d5
PB
9732static void
9733do_t_cps (void)
9734{
e07e6e58 9735 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
9736 inst.instruction |= inst.operands[0].imm;
9737}
9738
c19d1205
ZW
9739static void
9740do_t_cpsi (void)
9741{
e07e6e58 9742 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 9743 if (unified_syntax
62b3e311
PB
9744 && (inst.operands[1].present || inst.size_req == 4)
9745 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9746 {
c19d1205
ZW
9747 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9748 inst.instruction = 0xf3af8000;
9749 inst.instruction |= imod << 9;
9750 inst.instruction |= inst.operands[0].imm << 5;
9751 if (inst.operands[1].present)
9752 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9753 }
c19d1205 9754 else
90e4755a 9755 {
62b3e311
PB
9756 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9757 && (inst.operands[0].imm & 4),
9758 _("selected processor does not support 'A' form "
9759 "of this instruction"));
9760 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9761 _("Thumb does not support the 2-argument "
9762 "form of this instruction"));
9763 inst.instruction |= inst.operands[0].imm;
90e4755a 9764 }
90e4755a
RE
9765}
9766
c19d1205
ZW
9767/* THUMB CPY instruction (argument parse). */
9768
90e4755a 9769static void
c19d1205 9770do_t_cpy (void)
90e4755a 9771{
c19d1205 9772 if (inst.size_req == 4)
90e4755a 9773 {
c19d1205
ZW
9774 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9775 inst.instruction |= inst.operands[0].reg << 8;
9776 inst.instruction |= inst.operands[1].reg;
90e4755a 9777 }
c19d1205 9778 else
90e4755a 9779 {
c19d1205
ZW
9780 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9781 inst.instruction |= (inst.operands[0].reg & 0x7);
9782 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9783 }
90e4755a
RE
9784}
9785
90e4755a 9786static void
25fe350b 9787do_t_cbz (void)
90e4755a 9788{
e07e6e58 9789 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
9790 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9791 inst.instruction |= inst.operands[0].reg;
9792 inst.reloc.pc_rel = 1;
9793 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9794}
90e4755a 9795
62b3e311
PB
9796static void
9797do_t_dbg (void)
9798{
9799 inst.instruction |= inst.operands[0].imm;
9800}
9801
9802static void
9803do_t_div (void)
9804{
fdfde340
JM
9805 unsigned Rd, Rn, Rm;
9806
9807 Rd = inst.operands[0].reg;
9808 Rn = (inst.operands[1].present
9809 ? inst.operands[1].reg : Rd);
9810 Rm = inst.operands[2].reg;
9811
9812 reject_bad_reg (Rd);
9813 reject_bad_reg (Rn);
9814 reject_bad_reg (Rm);
9815
9816 inst.instruction |= Rd << 8;
9817 inst.instruction |= Rn << 16;
9818 inst.instruction |= Rm;
62b3e311
PB
9819}
9820
c19d1205
ZW
9821static void
9822do_t_hint (void)
9823{
9824 if (unified_syntax && inst.size_req == 4)
9825 inst.instruction = THUMB_OP32 (inst.instruction);
9826 else
9827 inst.instruction = THUMB_OP16 (inst.instruction);
9828}
90e4755a 9829
c19d1205
ZW
9830static void
9831do_t_it (void)
9832{
9833 unsigned int cond = inst.operands[0].imm;
e27ec89e 9834
e07e6e58
NC
9835 set_it_insn_type (IT_INSN);
9836 now_it.mask = (inst.instruction & 0xf) | 0x10;
9837 now_it.cc = cond;
e27ec89e
PB
9838
9839 /* If the condition is a negative condition, invert the mask. */
c19d1205 9840 if ((cond & 0x1) == 0x0)
90e4755a 9841 {
c19d1205 9842 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9843
c19d1205
ZW
9844 if ((mask & 0x7) == 0)
9845 /* no conversion needed */;
9846 else if ((mask & 0x3) == 0)
e27ec89e
PB
9847 mask ^= 0x8;
9848 else if ((mask & 0x1) == 0)
9849 mask ^= 0xC;
c19d1205 9850 else
e27ec89e 9851 mask ^= 0xE;
90e4755a 9852
e27ec89e
PB
9853 inst.instruction &= 0xfff0;
9854 inst.instruction |= mask;
c19d1205 9855 }
90e4755a 9856
c19d1205
ZW
9857 inst.instruction |= cond << 4;
9858}
90e4755a 9859
3c707909
PB
9860/* Helper function used for both push/pop and ldm/stm. */
9861static void
9862encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9863{
9864 bfd_boolean load;
9865
9866 load = (inst.instruction & (1 << 20)) != 0;
9867
9868 if (mask & (1 << 13))
9869 inst.error = _("SP not allowed in register list");
1e5b0379
NC
9870
9871 if ((mask & (1 << base)) != 0
9872 && writeback)
9873 inst.error = _("having the base register in the register list when "
9874 "using write back is UNPREDICTABLE");
9875
3c707909
PB
9876 if (load)
9877 {
e07e6e58
NC
9878 if (mask & (1 << 15))
9879 {
9880 if (mask & (1 << 14))
9881 inst.error = _("LR and PC should not both be in register list");
9882 else
9883 set_it_insn_type_last ();
9884 }
3c707909
PB
9885 }
9886 else
9887 {
9888 if (mask & (1 << 15))
9889 inst.error = _("PC not allowed in register list");
3c707909
PB
9890 }
9891
9892 if ((mask & (mask - 1)) == 0)
9893 {
9894 /* Single register transfers implemented as str/ldr. */
9895 if (writeback)
9896 {
9897 if (inst.instruction & (1 << 23))
9898 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9899 else
9900 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9901 }
9902 else
9903 {
9904 if (inst.instruction & (1 << 23))
9905 inst.instruction = 0x00800000; /* ia -> [base] */
9906 else
9907 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9908 }
9909
9910 inst.instruction |= 0xf8400000;
9911 if (load)
9912 inst.instruction |= 0x00100000;
9913
5f4273c7 9914 mask = ffs (mask) - 1;
3c707909
PB
9915 mask <<= 12;
9916 }
9917 else if (writeback)
9918 inst.instruction |= WRITE_BACK;
9919
9920 inst.instruction |= mask;
9921 inst.instruction |= base << 16;
9922}
9923
c19d1205
ZW
9924static void
9925do_t_ldmstm (void)
9926{
9927 /* This really doesn't seem worth it. */
9928 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9929 _("expression too complex"));
9930 constraint (inst.operands[1].writeback,
9931 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9932
c19d1205
ZW
9933 if (unified_syntax)
9934 {
3c707909
PB
9935 bfd_boolean narrow;
9936 unsigned mask;
9937
9938 narrow = FALSE;
c19d1205
ZW
9939 /* See if we can use a 16-bit instruction. */
9940 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9941 && inst.size_req != 4
3c707909 9942 && !(inst.operands[1].imm & ~0xff))
90e4755a 9943 {
3c707909 9944 mask = 1 << inst.operands[0].reg;
90e4755a 9945
eab4f823 9946 if (inst.operands[0].reg <= 7)
90e4755a 9947 {
3c707909 9948 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
9949 ? inst.operands[0].writeback
9950 : (inst.operands[0].writeback
9951 == !(inst.operands[1].imm & mask)))
9952 {
9953 if (inst.instruction == T_MNEM_stmia
9954 && (inst.operands[1].imm & mask)
9955 && (inst.operands[1].imm & (mask - 1)))
9956 as_warn (_("value stored for r%d is UNKNOWN"),
9957 inst.operands[0].reg);
3c707909 9958
eab4f823
MGD
9959 inst.instruction = THUMB_OP16 (inst.instruction);
9960 inst.instruction |= inst.operands[0].reg << 8;
9961 inst.instruction |= inst.operands[1].imm;
9962 narrow = TRUE;
9963 }
9964 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
9965 {
9966 /* This means 1 register in reg list one of 3 situations:
9967 1. Instruction is stmia, but without writeback.
9968 2. lmdia without writeback, but with Rn not in
9969 reglist.
9970 3. ldmia with writeback, but with Rn in reglist.
9971 Case 3 is UNPREDICTABLE behaviour, so we handle
9972 case 1 and 2 which can be converted into a 16-bit
9973 str or ldr. The SP cases are handled below. */
9974 unsigned long opcode;
9975 /* First, record an error for Case 3. */
9976 if (inst.operands[1].imm & mask
9977 && inst.operands[0].writeback)
9978 inst.error =
9979 _("having the base register in the register list when "
9980 "using write back is UNPREDICTABLE");
9981
9982 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
9983 : T_MNEM_ldr);
9984 inst.instruction = THUMB_OP16 (opcode);
9985 inst.instruction |= inst.operands[0].reg << 3;
9986 inst.instruction |= (ffs (inst.operands[1].imm)-1);
9987 narrow = TRUE;
9988 }
90e4755a 9989 }
eab4f823 9990 else if (inst.operands[0] .reg == REG_SP)
90e4755a 9991 {
eab4f823
MGD
9992 if (inst.operands[0].writeback)
9993 {
9994 inst.instruction =
9995 THUMB_OP16 (inst.instruction == T_MNEM_stmia
9996 ? T_MNEM_push : T_MNEM_pop);
9997 inst.instruction |= inst.operands[1].imm;
9998 narrow = TRUE;
9999 }
10000 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10001 {
10002 inst.instruction =
10003 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10004 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10005 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10006 narrow = TRUE;
10007 }
90e4755a 10008 }
3c707909
PB
10009 }
10010
10011 if (!narrow)
10012 {
c19d1205
ZW
10013 if (inst.instruction < 0xffff)
10014 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 10015
5f4273c7
NC
10016 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10017 inst.operands[0].writeback);
90e4755a
RE
10018 }
10019 }
c19d1205 10020 else
90e4755a 10021 {
c19d1205
ZW
10022 constraint (inst.operands[0].reg > 7
10023 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
10024 constraint (inst.instruction != T_MNEM_ldmia
10025 && inst.instruction != T_MNEM_stmia,
10026 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 10027 if (inst.instruction == T_MNEM_stmia)
f03698e6 10028 {
c19d1205
ZW
10029 if (!inst.operands[0].writeback)
10030 as_warn (_("this instruction will write back the base register"));
10031 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10032 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 10033 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 10034 inst.operands[0].reg);
f03698e6 10035 }
c19d1205 10036 else
90e4755a 10037 {
c19d1205
ZW
10038 if (!inst.operands[0].writeback
10039 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10040 as_warn (_("this instruction will write back the base register"));
10041 else if (inst.operands[0].writeback
10042 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10043 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
10044 }
10045
c19d1205
ZW
10046 inst.instruction = THUMB_OP16 (inst.instruction);
10047 inst.instruction |= inst.operands[0].reg << 8;
10048 inst.instruction |= inst.operands[1].imm;
10049 }
10050}
e28cd48c 10051
c19d1205
ZW
10052static void
10053do_t_ldrex (void)
10054{
10055 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10056 || inst.operands[1].postind || inst.operands[1].writeback
10057 || inst.operands[1].immisreg || inst.operands[1].shifted
10058 || inst.operands[1].negative,
01cfc07f 10059 BAD_ADDR_MODE);
e28cd48c 10060
5be8be5d
DG
10061 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10062
c19d1205
ZW
10063 inst.instruction |= inst.operands[0].reg << 12;
10064 inst.instruction |= inst.operands[1].reg << 16;
10065 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10066}
e28cd48c 10067
c19d1205
ZW
10068static void
10069do_t_ldrexd (void)
10070{
10071 if (!inst.operands[1].present)
1cac9012 10072 {
c19d1205
ZW
10073 constraint (inst.operands[0].reg == REG_LR,
10074 _("r14 not allowed as first register "
10075 "when second register is omitted"));
10076 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 10077 }
c19d1205
ZW
10078 constraint (inst.operands[0].reg == inst.operands[1].reg,
10079 BAD_OVERLAP);
b99bd4ef 10080
c19d1205
ZW
10081 inst.instruction |= inst.operands[0].reg << 12;
10082 inst.instruction |= inst.operands[1].reg << 8;
10083 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10084}
10085
10086static void
c19d1205 10087do_t_ldst (void)
b99bd4ef 10088{
0110f2b8
PB
10089 unsigned long opcode;
10090 int Rn;
10091
e07e6e58
NC
10092 if (inst.operands[0].isreg
10093 && !inst.operands[0].preind
10094 && inst.operands[0].reg == REG_PC)
10095 set_it_insn_type_last ();
10096
0110f2b8 10097 opcode = inst.instruction;
c19d1205 10098 if (unified_syntax)
b99bd4ef 10099 {
53365c0d
PB
10100 if (!inst.operands[1].isreg)
10101 {
10102 if (opcode <= 0xffff)
10103 inst.instruction = THUMB_OP32 (opcode);
10104 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10105 return;
10106 }
0110f2b8
PB
10107 if (inst.operands[1].isreg
10108 && !inst.operands[1].writeback
c19d1205
ZW
10109 && !inst.operands[1].shifted && !inst.operands[1].postind
10110 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
10111 && opcode <= 0xffff
10112 && inst.size_req != 4)
c19d1205 10113 {
0110f2b8
PB
10114 /* Insn may have a 16-bit form. */
10115 Rn = inst.operands[1].reg;
10116 if (inst.operands[1].immisreg)
10117 {
10118 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 10119 /* [Rn, Rik] */
0110f2b8
PB
10120 if (Rn <= 7 && inst.operands[1].imm <= 7)
10121 goto op16;
5be8be5d
DG
10122 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10123 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
10124 }
10125 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10126 && opcode != T_MNEM_ldrsb)
10127 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10128 || (Rn == REG_SP && opcode == T_MNEM_str))
10129 {
10130 /* [Rn, #const] */
10131 if (Rn > 7)
10132 {
10133 if (Rn == REG_PC)
10134 {
10135 if (inst.reloc.pc_rel)
10136 opcode = T_MNEM_ldr_pc2;
10137 else
10138 opcode = T_MNEM_ldr_pc;
10139 }
10140 else
10141 {
10142 if (opcode == T_MNEM_ldr)
10143 opcode = T_MNEM_ldr_sp;
10144 else
10145 opcode = T_MNEM_str_sp;
10146 }
10147 inst.instruction = inst.operands[0].reg << 8;
10148 }
10149 else
10150 {
10151 inst.instruction = inst.operands[0].reg;
10152 inst.instruction |= inst.operands[1].reg << 3;
10153 }
10154 inst.instruction |= THUMB_OP16 (opcode);
10155 if (inst.size_req == 2)
10156 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10157 else
10158 inst.relax = opcode;
10159 return;
10160 }
c19d1205 10161 }
0110f2b8 10162 /* Definitely a 32-bit variant. */
5be8be5d
DG
10163
10164 /* Do some validations regarding addressing modes. */
10165 if (inst.operands[1].immisreg && opcode != T_MNEM_ldr
10166 && opcode != T_MNEM_str)
10167 reject_bad_reg (inst.operands[1].imm);
10168
0110f2b8 10169 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
10170 inst.instruction |= inst.operands[0].reg << 12;
10171 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
10172 return;
10173 }
10174
c19d1205
ZW
10175 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10176
10177 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 10178 {
c19d1205
ZW
10179 /* Only [Rn,Rm] is acceptable. */
10180 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10181 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10182 || inst.operands[1].postind || inst.operands[1].shifted
10183 || inst.operands[1].negative,
10184 _("Thumb does not support this addressing mode"));
10185 inst.instruction = THUMB_OP16 (inst.instruction);
10186 goto op16;
b99bd4ef 10187 }
5f4273c7 10188
c19d1205
ZW
10189 inst.instruction = THUMB_OP16 (inst.instruction);
10190 if (!inst.operands[1].isreg)
10191 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10192 return;
b99bd4ef 10193
c19d1205
ZW
10194 constraint (!inst.operands[1].preind
10195 || inst.operands[1].shifted
10196 || inst.operands[1].writeback,
10197 _("Thumb does not support this addressing mode"));
10198 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 10199 {
c19d1205
ZW
10200 constraint (inst.instruction & 0x0600,
10201 _("byte or halfword not valid for base register"));
10202 constraint (inst.operands[1].reg == REG_PC
10203 && !(inst.instruction & THUMB_LOAD_BIT),
10204 _("r15 based store not allowed"));
10205 constraint (inst.operands[1].immisreg,
10206 _("invalid base register for register offset"));
b99bd4ef 10207
c19d1205
ZW
10208 if (inst.operands[1].reg == REG_PC)
10209 inst.instruction = T_OPCODE_LDR_PC;
10210 else if (inst.instruction & THUMB_LOAD_BIT)
10211 inst.instruction = T_OPCODE_LDR_SP;
10212 else
10213 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 10214
c19d1205
ZW
10215 inst.instruction |= inst.operands[0].reg << 8;
10216 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10217 return;
10218 }
90e4755a 10219
c19d1205
ZW
10220 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10221 if (!inst.operands[1].immisreg)
10222 {
10223 /* Immediate offset. */
10224 inst.instruction |= inst.operands[0].reg;
10225 inst.instruction |= inst.operands[1].reg << 3;
10226 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10227 return;
10228 }
90e4755a 10229
c19d1205
ZW
10230 /* Register offset. */
10231 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10232 constraint (inst.operands[1].negative,
10233 _("Thumb does not support this addressing mode"));
90e4755a 10234
c19d1205
ZW
10235 op16:
10236 switch (inst.instruction)
10237 {
10238 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10239 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10240 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10241 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10242 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10243 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10244 case 0x5600 /* ldrsb */:
10245 case 0x5e00 /* ldrsh */: break;
10246 default: abort ();
10247 }
90e4755a 10248
c19d1205
ZW
10249 inst.instruction |= inst.operands[0].reg;
10250 inst.instruction |= inst.operands[1].reg << 3;
10251 inst.instruction |= inst.operands[1].imm << 6;
10252}
90e4755a 10253
c19d1205
ZW
10254static void
10255do_t_ldstd (void)
10256{
10257 if (!inst.operands[1].present)
b99bd4ef 10258 {
c19d1205
ZW
10259 inst.operands[1].reg = inst.operands[0].reg + 1;
10260 constraint (inst.operands[0].reg == REG_LR,
10261 _("r14 not allowed here"));
b99bd4ef 10262 }
c19d1205
ZW
10263 inst.instruction |= inst.operands[0].reg << 12;
10264 inst.instruction |= inst.operands[1].reg << 8;
10265 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
10266}
10267
c19d1205
ZW
10268static void
10269do_t_ldstt (void)
10270{
10271 inst.instruction |= inst.operands[0].reg << 12;
10272 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10273}
a737bd4d 10274
b99bd4ef 10275static void
c19d1205 10276do_t_mla (void)
b99bd4ef 10277{
fdfde340 10278 unsigned Rd, Rn, Rm, Ra;
c921be7d 10279
fdfde340
JM
10280 Rd = inst.operands[0].reg;
10281 Rn = inst.operands[1].reg;
10282 Rm = inst.operands[2].reg;
10283 Ra = inst.operands[3].reg;
10284
10285 reject_bad_reg (Rd);
10286 reject_bad_reg (Rn);
10287 reject_bad_reg (Rm);
10288 reject_bad_reg (Ra);
10289
10290 inst.instruction |= Rd << 8;
10291 inst.instruction |= Rn << 16;
10292 inst.instruction |= Rm;
10293 inst.instruction |= Ra << 12;
c19d1205 10294}
b99bd4ef 10295
c19d1205
ZW
10296static void
10297do_t_mlal (void)
10298{
fdfde340
JM
10299 unsigned RdLo, RdHi, Rn, Rm;
10300
10301 RdLo = inst.operands[0].reg;
10302 RdHi = inst.operands[1].reg;
10303 Rn = inst.operands[2].reg;
10304 Rm = inst.operands[3].reg;
10305
10306 reject_bad_reg (RdLo);
10307 reject_bad_reg (RdHi);
10308 reject_bad_reg (Rn);
10309 reject_bad_reg (Rm);
10310
10311 inst.instruction |= RdLo << 12;
10312 inst.instruction |= RdHi << 8;
10313 inst.instruction |= Rn << 16;
10314 inst.instruction |= Rm;
c19d1205 10315}
b99bd4ef 10316
c19d1205
ZW
10317static void
10318do_t_mov_cmp (void)
10319{
fdfde340
JM
10320 unsigned Rn, Rm;
10321
10322 Rn = inst.operands[0].reg;
10323 Rm = inst.operands[1].reg;
10324
e07e6e58
NC
10325 if (Rn == REG_PC)
10326 set_it_insn_type_last ();
10327
c19d1205 10328 if (unified_syntax)
b99bd4ef 10329 {
c19d1205
ZW
10330 int r0off = (inst.instruction == T_MNEM_mov
10331 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 10332 unsigned long opcode;
3d388997
PB
10333 bfd_boolean narrow;
10334 bfd_boolean low_regs;
10335
fdfde340 10336 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 10337 opcode = inst.instruction;
e07e6e58 10338 if (in_it_block ())
0110f2b8 10339 narrow = opcode != T_MNEM_movs;
3d388997 10340 else
0110f2b8 10341 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
10342 if (inst.size_req == 4
10343 || inst.operands[1].shifted)
10344 narrow = FALSE;
10345
efd81785
PB
10346 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10347 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10348 && !inst.operands[1].shifted
fdfde340
JM
10349 && Rn == REG_PC
10350 && Rm == REG_LR)
efd81785
PB
10351 {
10352 inst.instruction = T2_SUBS_PC_LR;
10353 return;
10354 }
10355
fdfde340
JM
10356 if (opcode == T_MNEM_cmp)
10357 {
10358 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
10359 if (narrow)
10360 {
10361 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10362 but valid. */
10363 warn_deprecated_sp (Rm);
10364 /* R15 was documented as a valid choice for Rm in ARMv6,
10365 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10366 tools reject R15, so we do too. */
10367 constraint (Rm == REG_PC, BAD_PC);
10368 }
10369 else
10370 reject_bad_reg (Rm);
fdfde340
JM
10371 }
10372 else if (opcode == T_MNEM_mov
10373 || opcode == T_MNEM_movs)
10374 {
10375 if (inst.operands[1].isreg)
10376 {
10377 if (opcode == T_MNEM_movs)
10378 {
10379 reject_bad_reg (Rn);
10380 reject_bad_reg (Rm);
10381 }
76fa04a4
MGD
10382 else if (narrow)
10383 {
10384 /* This is mov.n. */
10385 if ((Rn == REG_SP || Rn == REG_PC)
10386 && (Rm == REG_SP || Rm == REG_PC))
10387 {
10388 as_warn (_("Use of r%u as a source register is "
10389 "deprecated when r%u is the destination "
10390 "register."), Rm, Rn);
10391 }
10392 }
10393 else
10394 {
10395 /* This is mov.w. */
10396 constraint (Rn == REG_PC, BAD_PC);
10397 constraint (Rm == REG_PC, BAD_PC);
10398 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
10399 }
fdfde340
JM
10400 }
10401 else
10402 reject_bad_reg (Rn);
10403 }
10404
c19d1205
ZW
10405 if (!inst.operands[1].isreg)
10406 {
0110f2b8 10407 /* Immediate operand. */
e07e6e58 10408 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
10409 narrow = 0;
10410 if (low_regs && narrow)
10411 {
10412 inst.instruction = THUMB_OP16 (opcode);
fdfde340 10413 inst.instruction |= Rn << 8;
0110f2b8
PB
10414 if (inst.size_req == 2)
10415 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10416 else
10417 inst.relax = opcode;
10418 }
10419 else
10420 {
10421 inst.instruction = THUMB_OP32 (inst.instruction);
10422 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10423 inst.instruction |= Rn << r0off;
0110f2b8
PB
10424 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10425 }
c19d1205 10426 }
728ca7c9
PB
10427 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10428 && (inst.instruction == T_MNEM_mov
10429 || inst.instruction == T_MNEM_movs))
10430 {
10431 /* Register shifts are encoded as separate shift instructions. */
10432 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10433
e07e6e58 10434 if (in_it_block ())
728ca7c9
PB
10435 narrow = !flags;
10436 else
10437 narrow = flags;
10438
10439 if (inst.size_req == 4)
10440 narrow = FALSE;
10441
10442 if (!low_regs || inst.operands[1].imm > 7)
10443 narrow = FALSE;
10444
fdfde340 10445 if (Rn != Rm)
728ca7c9
PB
10446 narrow = FALSE;
10447
10448 switch (inst.operands[1].shift_kind)
10449 {
10450 case SHIFT_LSL:
10451 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10452 break;
10453 case SHIFT_ASR:
10454 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10455 break;
10456 case SHIFT_LSR:
10457 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10458 break;
10459 case SHIFT_ROR:
10460 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10461 break;
10462 default:
5f4273c7 10463 abort ();
728ca7c9
PB
10464 }
10465
10466 inst.instruction = opcode;
10467 if (narrow)
10468 {
fdfde340 10469 inst.instruction |= Rn;
728ca7c9
PB
10470 inst.instruction |= inst.operands[1].imm << 3;
10471 }
10472 else
10473 {
10474 if (flags)
10475 inst.instruction |= CONDS_BIT;
10476
fdfde340
JM
10477 inst.instruction |= Rn << 8;
10478 inst.instruction |= Rm << 16;
728ca7c9
PB
10479 inst.instruction |= inst.operands[1].imm;
10480 }
10481 }
3d388997 10482 else if (!narrow)
c19d1205 10483 {
728ca7c9
PB
10484 /* Some mov with immediate shift have narrow variants.
10485 Register shifts are handled above. */
10486 if (low_regs && inst.operands[1].shifted
10487 && (inst.instruction == T_MNEM_mov
10488 || inst.instruction == T_MNEM_movs))
10489 {
e07e6e58 10490 if (in_it_block ())
728ca7c9
PB
10491 narrow = (inst.instruction == T_MNEM_mov);
10492 else
10493 narrow = (inst.instruction == T_MNEM_movs);
10494 }
10495
10496 if (narrow)
10497 {
10498 switch (inst.operands[1].shift_kind)
10499 {
10500 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10501 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10502 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10503 default: narrow = FALSE; break;
10504 }
10505 }
10506
10507 if (narrow)
10508 {
fdfde340
JM
10509 inst.instruction |= Rn;
10510 inst.instruction |= Rm << 3;
728ca7c9
PB
10511 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10512 }
10513 else
10514 {
10515 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10516 inst.instruction |= Rn << r0off;
728ca7c9
PB
10517 encode_thumb32_shifted_operand (1);
10518 }
c19d1205
ZW
10519 }
10520 else
10521 switch (inst.instruction)
10522 {
10523 case T_MNEM_mov:
10524 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
10525 inst.instruction |= (Rn & 0x8) << 4;
10526 inst.instruction |= (Rn & 0x7);
10527 inst.instruction |= Rm << 3;
c19d1205 10528 break;
b99bd4ef 10529
c19d1205
ZW
10530 case T_MNEM_movs:
10531 /* We know we have low registers at this point.
941a8a52
MGD
10532 Generate LSLS Rd, Rs, #0. */
10533 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
10534 inst.instruction |= Rn;
10535 inst.instruction |= Rm << 3;
c19d1205
ZW
10536 break;
10537
10538 case T_MNEM_cmp:
3d388997 10539 if (low_regs)
c19d1205
ZW
10540 {
10541 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
10542 inst.instruction |= Rn;
10543 inst.instruction |= Rm << 3;
c19d1205
ZW
10544 }
10545 else
10546 {
10547 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
10548 inst.instruction |= (Rn & 0x8) << 4;
10549 inst.instruction |= (Rn & 0x7);
10550 inst.instruction |= Rm << 3;
c19d1205
ZW
10551 }
10552 break;
10553 }
b99bd4ef
NC
10554 return;
10555 }
10556
c19d1205 10557 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
10558
10559 /* PR 10443: Do not silently ignore shifted operands. */
10560 constraint (inst.operands[1].shifted,
10561 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10562
c19d1205 10563 if (inst.operands[1].isreg)
b99bd4ef 10564 {
fdfde340 10565 if (Rn < 8 && Rm < 8)
b99bd4ef 10566 {
c19d1205
ZW
10567 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10568 since a MOV instruction produces unpredictable results. */
10569 if (inst.instruction == T_OPCODE_MOV_I8)
10570 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 10571 else
c19d1205 10572 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 10573
fdfde340
JM
10574 inst.instruction |= Rn;
10575 inst.instruction |= Rm << 3;
b99bd4ef
NC
10576 }
10577 else
10578 {
c19d1205
ZW
10579 if (inst.instruction == T_OPCODE_MOV_I8)
10580 inst.instruction = T_OPCODE_MOV_HR;
10581 else
10582 inst.instruction = T_OPCODE_CMP_HR;
10583 do_t_cpy ();
b99bd4ef
NC
10584 }
10585 }
c19d1205 10586 else
b99bd4ef 10587 {
fdfde340 10588 constraint (Rn > 7,
c19d1205 10589 _("only lo regs allowed with immediate"));
fdfde340 10590 inst.instruction |= Rn << 8;
c19d1205
ZW
10591 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10592 }
10593}
b99bd4ef 10594
c19d1205
ZW
10595static void
10596do_t_mov16 (void)
10597{
fdfde340 10598 unsigned Rd;
b6895b4f
PB
10599 bfd_vma imm;
10600 bfd_boolean top;
10601
10602 top = (inst.instruction & 0x00800000) != 0;
10603 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10604 {
10605 constraint (top, _(":lower16: not allowed this instruction"));
10606 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10607 }
10608 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10609 {
10610 constraint (!top, _(":upper16: not allowed this instruction"));
10611 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10612 }
10613
fdfde340
JM
10614 Rd = inst.operands[0].reg;
10615 reject_bad_reg (Rd);
10616
10617 inst.instruction |= Rd << 8;
b6895b4f
PB
10618 if (inst.reloc.type == BFD_RELOC_UNUSED)
10619 {
10620 imm = inst.reloc.exp.X_add_number;
10621 inst.instruction |= (imm & 0xf000) << 4;
10622 inst.instruction |= (imm & 0x0800) << 15;
10623 inst.instruction |= (imm & 0x0700) << 4;
10624 inst.instruction |= (imm & 0x00ff);
10625 }
c19d1205 10626}
b99bd4ef 10627
c19d1205
ZW
10628static void
10629do_t_mvn_tst (void)
10630{
fdfde340 10631 unsigned Rn, Rm;
c921be7d 10632
fdfde340
JM
10633 Rn = inst.operands[0].reg;
10634 Rm = inst.operands[1].reg;
10635
10636 if (inst.instruction == T_MNEM_cmp
10637 || inst.instruction == T_MNEM_cmn)
10638 constraint (Rn == REG_PC, BAD_PC);
10639 else
10640 reject_bad_reg (Rn);
10641 reject_bad_reg (Rm);
10642
c19d1205
ZW
10643 if (unified_syntax)
10644 {
10645 int r0off = (inst.instruction == T_MNEM_mvn
10646 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
10647 bfd_boolean narrow;
10648
10649 if (inst.size_req == 4
10650 || inst.instruction > 0xffff
10651 || inst.operands[1].shifted
fdfde340 10652 || Rn > 7 || Rm > 7)
3d388997
PB
10653 narrow = FALSE;
10654 else if (inst.instruction == T_MNEM_cmn)
10655 narrow = TRUE;
10656 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10657 narrow = !in_it_block ();
3d388997 10658 else
e07e6e58 10659 narrow = in_it_block ();
3d388997 10660
c19d1205 10661 if (!inst.operands[1].isreg)
b99bd4ef 10662 {
c19d1205
ZW
10663 /* For an immediate, we always generate a 32-bit opcode;
10664 section relaxation will shrink it later if possible. */
10665 if (inst.instruction < 0xffff)
10666 inst.instruction = THUMB_OP32 (inst.instruction);
10667 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10668 inst.instruction |= Rn << r0off;
c19d1205 10669 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10670 }
c19d1205 10671 else
b99bd4ef 10672 {
c19d1205 10673 /* See if we can do this with a 16-bit instruction. */
3d388997 10674 if (narrow)
b99bd4ef 10675 {
c19d1205 10676 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10677 inst.instruction |= Rn;
10678 inst.instruction |= Rm << 3;
b99bd4ef 10679 }
c19d1205 10680 else
b99bd4ef 10681 {
c19d1205
ZW
10682 constraint (inst.operands[1].shifted
10683 && inst.operands[1].immisreg,
10684 _("shift must be constant"));
10685 if (inst.instruction < 0xffff)
10686 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10687 inst.instruction |= Rn << r0off;
c19d1205 10688 encode_thumb32_shifted_operand (1);
b99bd4ef 10689 }
b99bd4ef
NC
10690 }
10691 }
10692 else
10693 {
c19d1205
ZW
10694 constraint (inst.instruction > 0xffff
10695 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10696 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10697 _("unshifted register required"));
fdfde340 10698 constraint (Rn > 7 || Rm > 7,
c19d1205 10699 BAD_HIREG);
b99bd4ef 10700
c19d1205 10701 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10702 inst.instruction |= Rn;
10703 inst.instruction |= Rm << 3;
b99bd4ef 10704 }
b99bd4ef
NC
10705}
10706
b05fe5cf 10707static void
c19d1205 10708do_t_mrs (void)
b05fe5cf 10709{
fdfde340 10710 unsigned Rd;
62b3e311 10711 int flags;
037e8744
JB
10712
10713 if (do_vfp_nsyn_mrs () == SUCCESS)
10714 return;
10715
62b3e311
PB
10716 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10717 if (flags == 0)
10718 {
7e806470 10719 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10720 _("selected processor does not support "
10721 "requested special purpose register"));
10722 }
10723 else
10724 {
10725 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10726 _("selected processor does not support "
44bf2362 10727 "requested special purpose register"));
62b3e311
PB
10728 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10729 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10730 _("'CPSR' or 'SPSR' expected"));
10731 }
5f4273c7 10732
fdfde340
JM
10733 Rd = inst.operands[0].reg;
10734 reject_bad_reg (Rd);
10735
10736 inst.instruction |= Rd << 8;
62b3e311
PB
10737 inst.instruction |= (flags & SPSR_BIT) >> 2;
10738 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 10739}
b05fe5cf 10740
c19d1205
ZW
10741static void
10742do_t_msr (void)
10743{
62b3e311 10744 int flags;
fdfde340 10745 unsigned Rn;
62b3e311 10746
037e8744
JB
10747 if (do_vfp_nsyn_msr () == SUCCESS)
10748 return;
10749
c19d1205
ZW
10750 constraint (!inst.operands[1].isreg,
10751 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
10752 flags = inst.operands[0].imm;
10753 if (flags & ~0xff)
10754 {
10755 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10756 _("selected processor does not support "
10757 "requested special purpose register"));
10758 }
10759 else
10760 {
7e806470 10761 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10762 _("selected processor does not support "
10763 "requested special purpose register"));
10764 flags |= PSR_f;
10765 }
c921be7d 10766
fdfde340
JM
10767 Rn = inst.operands[1].reg;
10768 reject_bad_reg (Rn);
10769
62b3e311
PB
10770 inst.instruction |= (flags & SPSR_BIT) >> 2;
10771 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10772 inst.instruction |= (flags & 0xff);
fdfde340 10773 inst.instruction |= Rn << 16;
c19d1205 10774}
b05fe5cf 10775
c19d1205
ZW
10776static void
10777do_t_mul (void)
10778{
17828f45 10779 bfd_boolean narrow;
fdfde340 10780 unsigned Rd, Rn, Rm;
17828f45 10781
c19d1205
ZW
10782 if (!inst.operands[2].present)
10783 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 10784
fdfde340
JM
10785 Rd = inst.operands[0].reg;
10786 Rn = inst.operands[1].reg;
10787 Rm = inst.operands[2].reg;
10788
17828f45 10789 if (unified_syntax)
b05fe5cf 10790 {
17828f45 10791 if (inst.size_req == 4
fdfde340
JM
10792 || (Rd != Rn
10793 && Rd != Rm)
10794 || Rn > 7
10795 || Rm > 7)
17828f45
JM
10796 narrow = FALSE;
10797 else if (inst.instruction == T_MNEM_muls)
e07e6e58 10798 narrow = !in_it_block ();
17828f45 10799 else
e07e6e58 10800 narrow = in_it_block ();
b05fe5cf 10801 }
c19d1205 10802 else
b05fe5cf 10803 {
17828f45 10804 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 10805 constraint (Rn > 7 || Rm > 7,
c19d1205 10806 BAD_HIREG);
17828f45
JM
10807 narrow = TRUE;
10808 }
b05fe5cf 10809
17828f45
JM
10810 if (narrow)
10811 {
10812 /* 16-bit MULS/Conditional MUL. */
c19d1205 10813 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10814 inst.instruction |= Rd;
b05fe5cf 10815
fdfde340
JM
10816 if (Rd == Rn)
10817 inst.instruction |= Rm << 3;
10818 else if (Rd == Rm)
10819 inst.instruction |= Rn << 3;
c19d1205
ZW
10820 else
10821 constraint (1, _("dest must overlap one source register"));
10822 }
17828f45
JM
10823 else
10824 {
e07e6e58
NC
10825 constraint (inst.instruction != T_MNEM_mul,
10826 _("Thumb-2 MUL must not set flags"));
17828f45
JM
10827 /* 32-bit MUL. */
10828 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10829 inst.instruction |= Rd << 8;
10830 inst.instruction |= Rn << 16;
10831 inst.instruction |= Rm << 0;
10832
10833 reject_bad_reg (Rd);
10834 reject_bad_reg (Rn);
10835 reject_bad_reg (Rm);
17828f45 10836 }
c19d1205 10837}
b05fe5cf 10838
c19d1205
ZW
10839static void
10840do_t_mull (void)
10841{
fdfde340 10842 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 10843
fdfde340
JM
10844 RdLo = inst.operands[0].reg;
10845 RdHi = inst.operands[1].reg;
10846 Rn = inst.operands[2].reg;
10847 Rm = inst.operands[3].reg;
10848
10849 reject_bad_reg (RdLo);
10850 reject_bad_reg (RdHi);
10851 reject_bad_reg (Rn);
10852 reject_bad_reg (Rm);
10853
10854 inst.instruction |= RdLo << 12;
10855 inst.instruction |= RdHi << 8;
10856 inst.instruction |= Rn << 16;
10857 inst.instruction |= Rm;
10858
10859 if (RdLo == RdHi)
c19d1205
ZW
10860 as_tsktsk (_("rdhi and rdlo must be different"));
10861}
b05fe5cf 10862
c19d1205
ZW
10863static void
10864do_t_nop (void)
10865{
e07e6e58
NC
10866 set_it_insn_type (NEUTRAL_IT_INSN);
10867
c19d1205
ZW
10868 if (unified_syntax)
10869 {
10870 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 10871 {
c19d1205
ZW
10872 inst.instruction = THUMB_OP32 (inst.instruction);
10873 inst.instruction |= inst.operands[0].imm;
10874 }
10875 else
10876 {
bc2d1808
NC
10877 /* PR9722: Check for Thumb2 availability before
10878 generating a thumb2 nop instruction. */
afa62d5e 10879 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
10880 {
10881 inst.instruction = THUMB_OP16 (inst.instruction);
10882 inst.instruction |= inst.operands[0].imm << 4;
10883 }
10884 else
10885 inst.instruction = 0x46c0;
c19d1205
ZW
10886 }
10887 }
10888 else
10889 {
10890 constraint (inst.operands[0].present,
10891 _("Thumb does not support NOP with hints"));
10892 inst.instruction = 0x46c0;
10893 }
10894}
b05fe5cf 10895
c19d1205
ZW
10896static void
10897do_t_neg (void)
10898{
10899 if (unified_syntax)
10900 {
3d388997
PB
10901 bfd_boolean narrow;
10902
10903 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10904 narrow = !in_it_block ();
3d388997 10905 else
e07e6e58 10906 narrow = in_it_block ();
3d388997
PB
10907 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10908 narrow = FALSE;
10909 if (inst.size_req == 4)
10910 narrow = FALSE;
10911
10912 if (!narrow)
c19d1205
ZW
10913 {
10914 inst.instruction = THUMB_OP32 (inst.instruction);
10915 inst.instruction |= inst.operands[0].reg << 8;
10916 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
10917 }
10918 else
10919 {
c19d1205
ZW
10920 inst.instruction = THUMB_OP16 (inst.instruction);
10921 inst.instruction |= inst.operands[0].reg;
10922 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
10923 }
10924 }
10925 else
10926 {
c19d1205
ZW
10927 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10928 BAD_HIREG);
10929 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10930
10931 inst.instruction = THUMB_OP16 (inst.instruction);
10932 inst.instruction |= inst.operands[0].reg;
10933 inst.instruction |= inst.operands[1].reg << 3;
10934 }
10935}
10936
1c444d06
JM
10937static void
10938do_t_orn (void)
10939{
10940 unsigned Rd, Rn;
10941
10942 Rd = inst.operands[0].reg;
10943 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10944
fdfde340
JM
10945 reject_bad_reg (Rd);
10946 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10947 reject_bad_reg (Rn);
10948
1c444d06
JM
10949 inst.instruction |= Rd << 8;
10950 inst.instruction |= Rn << 16;
10951
10952 if (!inst.operands[2].isreg)
10953 {
10954 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10955 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10956 }
10957 else
10958 {
10959 unsigned Rm;
10960
10961 Rm = inst.operands[2].reg;
fdfde340 10962 reject_bad_reg (Rm);
1c444d06
JM
10963
10964 constraint (inst.operands[2].shifted
10965 && inst.operands[2].immisreg,
10966 _("shift must be constant"));
10967 encode_thumb32_shifted_operand (2);
10968 }
10969}
10970
c19d1205
ZW
10971static void
10972do_t_pkhbt (void)
10973{
fdfde340
JM
10974 unsigned Rd, Rn, Rm;
10975
10976 Rd = inst.operands[0].reg;
10977 Rn = inst.operands[1].reg;
10978 Rm = inst.operands[2].reg;
10979
10980 reject_bad_reg (Rd);
10981 reject_bad_reg (Rn);
10982 reject_bad_reg (Rm);
10983
10984 inst.instruction |= Rd << 8;
10985 inst.instruction |= Rn << 16;
10986 inst.instruction |= Rm;
c19d1205
ZW
10987 if (inst.operands[3].present)
10988 {
10989 unsigned int val = inst.reloc.exp.X_add_number;
10990 constraint (inst.reloc.exp.X_op != O_constant,
10991 _("expression too complex"));
10992 inst.instruction |= (val & 0x1c) << 10;
10993 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 10994 }
c19d1205 10995}
b05fe5cf 10996
c19d1205
ZW
10997static void
10998do_t_pkhtb (void)
10999{
11000 if (!inst.operands[3].present)
1ef52f49
NC
11001 {
11002 unsigned Rtmp;
11003
11004 inst.instruction &= ~0x00000020;
11005
11006 /* PR 10168. Swap the Rm and Rn registers. */
11007 Rtmp = inst.operands[1].reg;
11008 inst.operands[1].reg = inst.operands[2].reg;
11009 inst.operands[2].reg = Rtmp;
11010 }
c19d1205 11011 do_t_pkhbt ();
b05fe5cf
ZW
11012}
11013
c19d1205
ZW
11014static void
11015do_t_pld (void)
11016{
fdfde340
JM
11017 if (inst.operands[0].immisreg)
11018 reject_bad_reg (inst.operands[0].imm);
11019
c19d1205
ZW
11020 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11021}
b05fe5cf 11022
c19d1205
ZW
11023static void
11024do_t_push_pop (void)
b99bd4ef 11025{
e9f89963 11026 unsigned mask;
5f4273c7 11027
c19d1205
ZW
11028 constraint (inst.operands[0].writeback,
11029 _("push/pop do not support {reglist}^"));
11030 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11031 _("expression too complex"));
b99bd4ef 11032
e9f89963
PB
11033 mask = inst.operands[0].imm;
11034 if ((mask & ~0xff) == 0)
3c707909 11035 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 11036 else if ((inst.instruction == T_MNEM_push
e9f89963 11037 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 11038 || (inst.instruction == T_MNEM_pop
e9f89963 11039 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 11040 {
c19d1205
ZW
11041 inst.instruction = THUMB_OP16 (inst.instruction);
11042 inst.instruction |= THUMB_PP_PC_LR;
3c707909 11043 inst.instruction |= mask & 0xff;
c19d1205
ZW
11044 }
11045 else if (unified_syntax)
11046 {
3c707909 11047 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 11048 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
11049 }
11050 else
11051 {
11052 inst.error = _("invalid register list to push/pop instruction");
11053 return;
11054 }
c19d1205 11055}
b99bd4ef 11056
c19d1205
ZW
11057static void
11058do_t_rbit (void)
11059{
fdfde340
JM
11060 unsigned Rd, Rm;
11061
11062 Rd = inst.operands[0].reg;
11063 Rm = inst.operands[1].reg;
11064
11065 reject_bad_reg (Rd);
11066 reject_bad_reg (Rm);
11067
11068 inst.instruction |= Rd << 8;
11069 inst.instruction |= Rm << 16;
11070 inst.instruction |= Rm;
c19d1205 11071}
b99bd4ef 11072
c19d1205
ZW
11073static void
11074do_t_rev (void)
11075{
fdfde340
JM
11076 unsigned Rd, Rm;
11077
11078 Rd = inst.operands[0].reg;
11079 Rm = inst.operands[1].reg;
11080
11081 reject_bad_reg (Rd);
11082 reject_bad_reg (Rm);
11083
11084 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
11085 && inst.size_req != 4)
11086 {
11087 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11088 inst.instruction |= Rd;
11089 inst.instruction |= Rm << 3;
c19d1205
ZW
11090 }
11091 else if (unified_syntax)
11092 {
11093 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11094 inst.instruction |= Rd << 8;
11095 inst.instruction |= Rm << 16;
11096 inst.instruction |= Rm;
c19d1205
ZW
11097 }
11098 else
11099 inst.error = BAD_HIREG;
11100}
b99bd4ef 11101
1c444d06
JM
11102static void
11103do_t_rrx (void)
11104{
11105 unsigned Rd, Rm;
11106
11107 Rd = inst.operands[0].reg;
11108 Rm = inst.operands[1].reg;
11109
fdfde340
JM
11110 reject_bad_reg (Rd);
11111 reject_bad_reg (Rm);
c921be7d 11112
1c444d06
JM
11113 inst.instruction |= Rd << 8;
11114 inst.instruction |= Rm;
11115}
11116
c19d1205
ZW
11117static void
11118do_t_rsb (void)
11119{
fdfde340 11120 unsigned Rd, Rs;
b99bd4ef 11121
c19d1205
ZW
11122 Rd = inst.operands[0].reg;
11123 Rs = (inst.operands[1].present
11124 ? inst.operands[1].reg /* Rd, Rs, foo */
11125 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 11126
fdfde340
JM
11127 reject_bad_reg (Rd);
11128 reject_bad_reg (Rs);
11129 if (inst.operands[2].isreg)
11130 reject_bad_reg (inst.operands[2].reg);
11131
c19d1205
ZW
11132 inst.instruction |= Rd << 8;
11133 inst.instruction |= Rs << 16;
11134 if (!inst.operands[2].isreg)
11135 {
026d3abb
PB
11136 bfd_boolean narrow;
11137
11138 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 11139 narrow = !in_it_block ();
026d3abb 11140 else
e07e6e58 11141 narrow = in_it_block ();
026d3abb
PB
11142
11143 if (Rd > 7 || Rs > 7)
11144 narrow = FALSE;
11145
11146 if (inst.size_req == 4 || !unified_syntax)
11147 narrow = FALSE;
11148
11149 if (inst.reloc.exp.X_op != O_constant
11150 || inst.reloc.exp.X_add_number != 0)
11151 narrow = FALSE;
11152
11153 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11154 relaxation, but it doesn't seem worth the hassle. */
11155 if (narrow)
11156 {
11157 inst.reloc.type = BFD_RELOC_UNUSED;
11158 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11159 inst.instruction |= Rs << 3;
11160 inst.instruction |= Rd;
11161 }
11162 else
11163 {
11164 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11165 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11166 }
c19d1205
ZW
11167 }
11168 else
11169 encode_thumb32_shifted_operand (2);
11170}
b99bd4ef 11171
c19d1205
ZW
11172static void
11173do_t_setend (void)
11174{
e07e6e58 11175 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11176 if (inst.operands[0].imm)
11177 inst.instruction |= 0x8;
11178}
b99bd4ef 11179
c19d1205
ZW
11180static void
11181do_t_shift (void)
11182{
11183 if (!inst.operands[1].present)
11184 inst.operands[1].reg = inst.operands[0].reg;
11185
11186 if (unified_syntax)
11187 {
3d388997
PB
11188 bfd_boolean narrow;
11189 int shift_kind;
11190
11191 switch (inst.instruction)
11192 {
11193 case T_MNEM_asr:
11194 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11195 case T_MNEM_lsl:
11196 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11197 case T_MNEM_lsr:
11198 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11199 case T_MNEM_ror:
11200 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11201 default: abort ();
11202 }
11203
11204 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11205 narrow = !in_it_block ();
3d388997 11206 else
e07e6e58 11207 narrow = in_it_block ();
3d388997
PB
11208 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11209 narrow = FALSE;
11210 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11211 narrow = FALSE;
11212 if (inst.operands[2].isreg
11213 && (inst.operands[1].reg != inst.operands[0].reg
11214 || inst.operands[2].reg > 7))
11215 narrow = FALSE;
11216 if (inst.size_req == 4)
11217 narrow = FALSE;
11218
fdfde340
JM
11219 reject_bad_reg (inst.operands[0].reg);
11220 reject_bad_reg (inst.operands[1].reg);
c921be7d 11221
3d388997 11222 if (!narrow)
c19d1205
ZW
11223 {
11224 if (inst.operands[2].isreg)
b99bd4ef 11225 {
fdfde340 11226 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
11227 inst.instruction = THUMB_OP32 (inst.instruction);
11228 inst.instruction |= inst.operands[0].reg << 8;
11229 inst.instruction |= inst.operands[1].reg << 16;
11230 inst.instruction |= inst.operands[2].reg;
11231 }
11232 else
11233 {
11234 inst.operands[1].shifted = 1;
3d388997 11235 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
11236 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11237 ? T_MNEM_movs : T_MNEM_mov);
11238 inst.instruction |= inst.operands[0].reg << 8;
11239 encode_thumb32_shifted_operand (1);
11240 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11241 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
11242 }
11243 }
11244 else
11245 {
c19d1205 11246 if (inst.operands[2].isreg)
b99bd4ef 11247 {
3d388997 11248 switch (shift_kind)
b99bd4ef 11249 {
3d388997
PB
11250 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11251 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11252 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11253 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 11254 default: abort ();
b99bd4ef 11255 }
5f4273c7 11256
c19d1205
ZW
11257 inst.instruction |= inst.operands[0].reg;
11258 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
11259 }
11260 else
11261 {
3d388997 11262 switch (shift_kind)
b99bd4ef 11263 {
3d388997
PB
11264 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11265 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11266 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 11267 default: abort ();
b99bd4ef 11268 }
c19d1205
ZW
11269 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11270 inst.instruction |= inst.operands[0].reg;
11271 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11272 }
11273 }
c19d1205
ZW
11274 }
11275 else
11276 {
11277 constraint (inst.operands[0].reg > 7
11278 || inst.operands[1].reg > 7, BAD_HIREG);
11279 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 11280
c19d1205
ZW
11281 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11282 {
11283 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11284 constraint (inst.operands[0].reg != inst.operands[1].reg,
11285 _("source1 and dest must be same register"));
b99bd4ef 11286
c19d1205
ZW
11287 switch (inst.instruction)
11288 {
11289 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11290 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11291 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11292 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11293 default: abort ();
11294 }
5f4273c7 11295
c19d1205
ZW
11296 inst.instruction |= inst.operands[0].reg;
11297 inst.instruction |= inst.operands[2].reg << 3;
11298 }
11299 else
b99bd4ef 11300 {
c19d1205
ZW
11301 switch (inst.instruction)
11302 {
11303 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11304 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11305 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11306 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11307 default: abort ();
11308 }
11309 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11310 inst.instruction |= inst.operands[0].reg;
11311 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11312 }
11313 }
b99bd4ef
NC
11314}
11315
11316static void
c19d1205 11317do_t_simd (void)
b99bd4ef 11318{
fdfde340
JM
11319 unsigned Rd, Rn, Rm;
11320
11321 Rd = inst.operands[0].reg;
11322 Rn = inst.operands[1].reg;
11323 Rm = inst.operands[2].reg;
11324
11325 reject_bad_reg (Rd);
11326 reject_bad_reg (Rn);
11327 reject_bad_reg (Rm);
11328
11329 inst.instruction |= Rd << 8;
11330 inst.instruction |= Rn << 16;
11331 inst.instruction |= Rm;
c19d1205 11332}
b99bd4ef 11333
03ee1b7f
NC
11334static void
11335do_t_simd2 (void)
11336{
11337 unsigned Rd, Rn, Rm;
11338
11339 Rd = inst.operands[0].reg;
11340 Rm = inst.operands[1].reg;
11341 Rn = inst.operands[2].reg;
11342
11343 reject_bad_reg (Rd);
11344 reject_bad_reg (Rn);
11345 reject_bad_reg (Rm);
11346
11347 inst.instruction |= Rd << 8;
11348 inst.instruction |= Rn << 16;
11349 inst.instruction |= Rm;
11350}
11351
c19d1205 11352static void
3eb17e6b 11353do_t_smc (void)
c19d1205
ZW
11354{
11355 unsigned int value = inst.reloc.exp.X_add_number;
11356 constraint (inst.reloc.exp.X_op != O_constant,
11357 _("expression too complex"));
11358 inst.reloc.type = BFD_RELOC_UNUSED;
11359 inst.instruction |= (value & 0xf000) >> 12;
11360 inst.instruction |= (value & 0x0ff0);
11361 inst.instruction |= (value & 0x000f) << 16;
11362}
b99bd4ef 11363
c19d1205 11364static void
3a21c15a 11365do_t_ssat_usat (int bias)
c19d1205 11366{
fdfde340
JM
11367 unsigned Rd, Rn;
11368
11369 Rd = inst.operands[0].reg;
11370 Rn = inst.operands[2].reg;
11371
11372 reject_bad_reg (Rd);
11373 reject_bad_reg (Rn);
11374
11375 inst.instruction |= Rd << 8;
3a21c15a 11376 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 11377 inst.instruction |= Rn << 16;
b99bd4ef 11378
c19d1205 11379 if (inst.operands[3].present)
b99bd4ef 11380 {
3a21c15a
NC
11381 offsetT shift_amount = inst.reloc.exp.X_add_number;
11382
11383 inst.reloc.type = BFD_RELOC_UNUSED;
11384
c19d1205
ZW
11385 constraint (inst.reloc.exp.X_op != O_constant,
11386 _("expression too complex"));
b99bd4ef 11387
3a21c15a 11388 if (shift_amount != 0)
6189168b 11389 {
3a21c15a
NC
11390 constraint (shift_amount > 31,
11391 _("shift expression is too large"));
11392
c19d1205 11393 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
11394 inst.instruction |= 0x00200000; /* sh bit. */
11395
11396 inst.instruction |= (shift_amount & 0x1c) << 10;
11397 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
11398 }
11399 }
b99bd4ef 11400}
c921be7d 11401
3a21c15a
NC
11402static void
11403do_t_ssat (void)
11404{
11405 do_t_ssat_usat (1);
11406}
b99bd4ef 11407
0dd132b6 11408static void
c19d1205 11409do_t_ssat16 (void)
0dd132b6 11410{
fdfde340
JM
11411 unsigned Rd, Rn;
11412
11413 Rd = inst.operands[0].reg;
11414 Rn = inst.operands[2].reg;
11415
11416 reject_bad_reg (Rd);
11417 reject_bad_reg (Rn);
11418
11419 inst.instruction |= Rd << 8;
c19d1205 11420 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 11421 inst.instruction |= Rn << 16;
c19d1205 11422}
0dd132b6 11423
c19d1205
ZW
11424static void
11425do_t_strex (void)
11426{
11427 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11428 || inst.operands[2].postind || inst.operands[2].writeback
11429 || inst.operands[2].immisreg || inst.operands[2].shifted
11430 || inst.operands[2].negative,
01cfc07f 11431 BAD_ADDR_MODE);
0dd132b6 11432
5be8be5d
DG
11433 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11434
c19d1205
ZW
11435 inst.instruction |= inst.operands[0].reg << 8;
11436 inst.instruction |= inst.operands[1].reg << 12;
11437 inst.instruction |= inst.operands[2].reg << 16;
11438 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
11439}
11440
b99bd4ef 11441static void
c19d1205 11442do_t_strexd (void)
b99bd4ef 11443{
c19d1205
ZW
11444 if (!inst.operands[2].present)
11445 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 11446
c19d1205
ZW
11447 constraint (inst.operands[0].reg == inst.operands[1].reg
11448 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 11449 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 11450 BAD_OVERLAP);
b99bd4ef 11451
c19d1205
ZW
11452 inst.instruction |= inst.operands[0].reg;
11453 inst.instruction |= inst.operands[1].reg << 12;
11454 inst.instruction |= inst.operands[2].reg << 8;
11455 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
11456}
11457
11458static void
c19d1205 11459do_t_sxtah (void)
b99bd4ef 11460{
fdfde340
JM
11461 unsigned Rd, Rn, Rm;
11462
11463 Rd = inst.operands[0].reg;
11464 Rn = inst.operands[1].reg;
11465 Rm = inst.operands[2].reg;
11466
11467 reject_bad_reg (Rd);
11468 reject_bad_reg (Rn);
11469 reject_bad_reg (Rm);
11470
11471 inst.instruction |= Rd << 8;
11472 inst.instruction |= Rn << 16;
11473 inst.instruction |= Rm;
c19d1205
ZW
11474 inst.instruction |= inst.operands[3].imm << 4;
11475}
b99bd4ef 11476
c19d1205
ZW
11477static void
11478do_t_sxth (void)
11479{
fdfde340
JM
11480 unsigned Rd, Rm;
11481
11482 Rd = inst.operands[0].reg;
11483 Rm = inst.operands[1].reg;
11484
11485 reject_bad_reg (Rd);
11486 reject_bad_reg (Rm);
c921be7d
NC
11487
11488 if (inst.instruction <= 0xffff
11489 && inst.size_req != 4
fdfde340 11490 && Rd <= 7 && Rm <= 7
c19d1205 11491 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 11492 {
c19d1205 11493 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11494 inst.instruction |= Rd;
11495 inst.instruction |= Rm << 3;
b99bd4ef 11496 }
c19d1205 11497 else if (unified_syntax)
b99bd4ef 11498 {
c19d1205
ZW
11499 if (inst.instruction <= 0xffff)
11500 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11501 inst.instruction |= Rd << 8;
11502 inst.instruction |= Rm;
c19d1205 11503 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 11504 }
c19d1205 11505 else
b99bd4ef 11506 {
c19d1205
ZW
11507 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11508 _("Thumb encoding does not support rotation"));
11509 constraint (1, BAD_HIREG);
b99bd4ef 11510 }
c19d1205 11511}
b99bd4ef 11512
c19d1205
ZW
11513static void
11514do_t_swi (void)
11515{
11516 inst.reloc.type = BFD_RELOC_ARM_SWI;
11517}
b99bd4ef 11518
92e90b6e
PB
11519static void
11520do_t_tb (void)
11521{
fdfde340 11522 unsigned Rn, Rm;
92e90b6e
PB
11523 int half;
11524
11525 half = (inst.instruction & 0x10) != 0;
e07e6e58 11526 set_it_insn_type_last ();
dfa9f0d5
PB
11527 constraint (inst.operands[0].immisreg,
11528 _("instruction requires register index"));
fdfde340
JM
11529
11530 Rn = inst.operands[0].reg;
11531 Rm = inst.operands[0].imm;
c921be7d 11532
fdfde340
JM
11533 constraint (Rn == REG_SP, BAD_SP);
11534 reject_bad_reg (Rm);
11535
92e90b6e
PB
11536 constraint (!half && inst.operands[0].shifted,
11537 _("instruction does not allow shifted index"));
fdfde340 11538 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
11539}
11540
c19d1205
ZW
11541static void
11542do_t_usat (void)
11543{
3a21c15a 11544 do_t_ssat_usat (0);
b99bd4ef
NC
11545}
11546
11547static void
c19d1205 11548do_t_usat16 (void)
b99bd4ef 11549{
fdfde340
JM
11550 unsigned Rd, Rn;
11551
11552 Rd = inst.operands[0].reg;
11553 Rn = inst.operands[2].reg;
11554
11555 reject_bad_reg (Rd);
11556 reject_bad_reg (Rn);
11557
11558 inst.instruction |= Rd << 8;
c19d1205 11559 inst.instruction |= inst.operands[1].imm;
fdfde340 11560 inst.instruction |= Rn << 16;
b99bd4ef 11561}
c19d1205 11562
5287ad62 11563/* Neon instruction encoder helpers. */
5f4273c7 11564
5287ad62 11565/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 11566
5287ad62
JB
11567/* An "invalid" code for the following tables. */
11568#define N_INV -1u
11569
11570struct neon_tab_entry
b99bd4ef 11571{
5287ad62
JB
11572 unsigned integer;
11573 unsigned float_or_poly;
11574 unsigned scalar_or_imm;
11575};
5f4273c7 11576
5287ad62
JB
11577/* Map overloaded Neon opcodes to their respective encodings. */
11578#define NEON_ENC_TAB \
11579 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11580 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11581 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11582 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11583 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11584 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11585 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11586 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11587 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11588 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11589 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11590 /* Register variants of the following two instructions are encoded as
e07e6e58 11591 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
11592 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11593 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
11594 X(vfma, N_INV, 0x0000c10, N_INV), \
11595 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
11596 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11597 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11598 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11599 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11600 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11601 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11602 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11603 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11604 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11605 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11606 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11607 X(vshl, 0x0000400, N_INV, 0x0800510), \
11608 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11609 X(vand, 0x0000110, N_INV, 0x0800030), \
11610 X(vbic, 0x0100110, N_INV, 0x0800030), \
11611 X(veor, 0x1000110, N_INV, N_INV), \
11612 X(vorn, 0x0300110, N_INV, 0x0800010), \
11613 X(vorr, 0x0200110, N_INV, 0x0800010), \
11614 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11615 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11616 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11617 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11618 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11619 X(vst1, 0x0000000, 0x0800000, N_INV), \
11620 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11621 X(vst2, 0x0000100, 0x0800100, N_INV), \
11622 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11623 X(vst3, 0x0000200, 0x0800200, N_INV), \
11624 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11625 X(vst4, 0x0000300, 0x0800300, N_INV), \
11626 X(vmovn, 0x1b20200, N_INV, N_INV), \
11627 X(vtrn, 0x1b20080, N_INV, N_INV), \
11628 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
11629 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11630 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
11631 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11632 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
11633 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11634 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
11635 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11636 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11637 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11638 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
11639
11640enum neon_opc
11641{
11642#define X(OPC,I,F,S) N_MNEM_##OPC
11643NEON_ENC_TAB
11644#undef X
11645};
b99bd4ef 11646
5287ad62
JB
11647static const struct neon_tab_entry neon_enc_tab[] =
11648{
11649#define X(OPC,I,F,S) { (I), (F), (S) }
11650NEON_ENC_TAB
11651#undef X
11652};
b99bd4ef 11653
88714cb8
DG
11654/* Do not use these macros; instead, use NEON_ENCODE defined below. */
11655#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11656#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11657#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11658#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11659#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11660#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11661#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11662#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11663#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11664#define NEON_ENC_SINGLE_(X) \
037e8744 11665 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 11666#define NEON_ENC_DOUBLE_(X) \
037e8744 11667 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 11668
88714cb8
DG
11669#define NEON_ENCODE(type, inst) \
11670 do \
11671 { \
11672 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
11673 inst.is_neon = 1; \
11674 } \
11675 while (0)
11676
11677#define check_neon_suffixes \
11678 do \
11679 { \
11680 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
11681 { \
11682 as_bad (_("invalid neon suffix for non neon instruction")); \
11683 return; \
11684 } \
11685 } \
11686 while (0)
11687
037e8744
JB
11688/* Define shapes for instruction operands. The following mnemonic characters
11689 are used in this table:
5287ad62 11690
037e8744 11691 F - VFP S<n> register
5287ad62
JB
11692 D - Neon D<n> register
11693 Q - Neon Q<n> register
11694 I - Immediate
11695 S - Scalar
11696 R - ARM register
11697 L - D<n> register list
5f4273c7 11698
037e8744
JB
11699 This table is used to generate various data:
11700 - enumerations of the form NS_DDR to be used as arguments to
11701 neon_select_shape.
11702 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 11703 - a table used to drive neon_select_shape. */
b99bd4ef 11704
037e8744
JB
11705#define NEON_SHAPE_DEF \
11706 X(3, (D, D, D), DOUBLE), \
11707 X(3, (Q, Q, Q), QUAD), \
11708 X(3, (D, D, I), DOUBLE), \
11709 X(3, (Q, Q, I), QUAD), \
11710 X(3, (D, D, S), DOUBLE), \
11711 X(3, (Q, Q, S), QUAD), \
11712 X(2, (D, D), DOUBLE), \
11713 X(2, (Q, Q), QUAD), \
11714 X(2, (D, S), DOUBLE), \
11715 X(2, (Q, S), QUAD), \
11716 X(2, (D, R), DOUBLE), \
11717 X(2, (Q, R), QUAD), \
11718 X(2, (D, I), DOUBLE), \
11719 X(2, (Q, I), QUAD), \
11720 X(3, (D, L, D), DOUBLE), \
11721 X(2, (D, Q), MIXED), \
11722 X(2, (Q, D), MIXED), \
11723 X(3, (D, Q, I), MIXED), \
11724 X(3, (Q, D, I), MIXED), \
11725 X(3, (Q, D, D), MIXED), \
11726 X(3, (D, Q, Q), MIXED), \
11727 X(3, (Q, Q, D), MIXED), \
11728 X(3, (Q, D, S), MIXED), \
11729 X(3, (D, Q, S), MIXED), \
11730 X(4, (D, D, D, I), DOUBLE), \
11731 X(4, (Q, Q, Q, I), QUAD), \
11732 X(2, (F, F), SINGLE), \
11733 X(3, (F, F, F), SINGLE), \
11734 X(2, (F, I), SINGLE), \
11735 X(2, (F, D), MIXED), \
11736 X(2, (D, F), MIXED), \
11737 X(3, (F, F, I), MIXED), \
11738 X(4, (R, R, F, F), SINGLE), \
11739 X(4, (F, F, R, R), SINGLE), \
11740 X(3, (D, R, R), DOUBLE), \
11741 X(3, (R, R, D), DOUBLE), \
11742 X(2, (S, R), SINGLE), \
11743 X(2, (R, S), SINGLE), \
11744 X(2, (F, R), SINGLE), \
11745 X(2, (R, F), SINGLE)
11746
11747#define S2(A,B) NS_##A##B
11748#define S3(A,B,C) NS_##A##B##C
11749#define S4(A,B,C,D) NS_##A##B##C##D
11750
11751#define X(N, L, C) S##N L
11752
5287ad62
JB
11753enum neon_shape
11754{
037e8744
JB
11755 NEON_SHAPE_DEF,
11756 NS_NULL
5287ad62 11757};
b99bd4ef 11758
037e8744
JB
11759#undef X
11760#undef S2
11761#undef S3
11762#undef S4
11763
11764enum neon_shape_class
11765{
11766 SC_SINGLE,
11767 SC_DOUBLE,
11768 SC_QUAD,
11769 SC_MIXED
11770};
11771
11772#define X(N, L, C) SC_##C
11773
11774static enum neon_shape_class neon_shape_class[] =
11775{
11776 NEON_SHAPE_DEF
11777};
11778
11779#undef X
11780
11781enum neon_shape_el
11782{
11783 SE_F,
11784 SE_D,
11785 SE_Q,
11786 SE_I,
11787 SE_S,
11788 SE_R,
11789 SE_L
11790};
11791
11792/* Register widths of above. */
11793static unsigned neon_shape_el_size[] =
11794{
11795 32,
11796 64,
11797 128,
11798 0,
11799 32,
11800 32,
11801 0
11802};
11803
11804struct neon_shape_info
11805{
11806 unsigned els;
11807 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11808};
11809
11810#define S2(A,B) { SE_##A, SE_##B }
11811#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11812#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11813
11814#define X(N, L, C) { N, S##N L }
11815
11816static struct neon_shape_info neon_shape_tab[] =
11817{
11818 NEON_SHAPE_DEF
11819};
11820
11821#undef X
11822#undef S2
11823#undef S3
11824#undef S4
11825
5287ad62
JB
11826/* Bit masks used in type checking given instructions.
11827 'N_EQK' means the type must be the same as (or based on in some way) the key
11828 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11829 set, various other bits can be set as well in order to modify the meaning of
11830 the type constraint. */
11831
11832enum neon_type_mask
11833{
8e79c3df
CM
11834 N_S8 = 0x0000001,
11835 N_S16 = 0x0000002,
11836 N_S32 = 0x0000004,
11837 N_S64 = 0x0000008,
11838 N_U8 = 0x0000010,
11839 N_U16 = 0x0000020,
11840 N_U32 = 0x0000040,
11841 N_U64 = 0x0000080,
11842 N_I8 = 0x0000100,
11843 N_I16 = 0x0000200,
11844 N_I32 = 0x0000400,
11845 N_I64 = 0x0000800,
11846 N_8 = 0x0001000,
11847 N_16 = 0x0002000,
11848 N_32 = 0x0004000,
11849 N_64 = 0x0008000,
11850 N_P8 = 0x0010000,
11851 N_P16 = 0x0020000,
11852 N_F16 = 0x0040000,
11853 N_F32 = 0x0080000,
11854 N_F64 = 0x0100000,
c921be7d
NC
11855 N_KEY = 0x1000000, /* Key element (main type specifier). */
11856 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 11857 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
c921be7d
NC
11858 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
11859 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
11860 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
11861 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
11862 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
11863 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
11864 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 11865 N_UTYP = 0,
037e8744 11866 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
11867};
11868
dcbf9037
JB
11869#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11870
5287ad62
JB
11871#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11872#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11873#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11874#define N_SUF_32 (N_SU_32 | N_F32)
11875#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11876#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11877
11878/* Pass this as the first type argument to neon_check_type to ignore types
11879 altogether. */
11880#define N_IGNORE_TYPE (N_KEY | N_EQK)
11881
037e8744
JB
11882/* Select a "shape" for the current instruction (describing register types or
11883 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11884 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11885 function of operand parsing, so this function doesn't need to be called.
11886 Shapes should be listed in order of decreasing length. */
5287ad62
JB
11887
11888static enum neon_shape
037e8744 11889neon_select_shape (enum neon_shape shape, ...)
5287ad62 11890{
037e8744
JB
11891 va_list ap;
11892 enum neon_shape first_shape = shape;
5287ad62
JB
11893
11894 /* Fix missing optional operands. FIXME: we don't know at this point how
11895 many arguments we should have, so this makes the assumption that we have
11896 > 1. This is true of all current Neon opcodes, I think, but may not be
11897 true in the future. */
11898 if (!inst.operands[1].present)
11899 inst.operands[1] = inst.operands[0];
11900
037e8744 11901 va_start (ap, shape);
5f4273c7 11902
21d799b5 11903 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
11904 {
11905 unsigned j;
11906 int matches = 1;
11907
11908 for (j = 0; j < neon_shape_tab[shape].els; j++)
11909 {
11910 if (!inst.operands[j].present)
11911 {
11912 matches = 0;
11913 break;
11914 }
11915
11916 switch (neon_shape_tab[shape].el[j])
11917 {
11918 case SE_F:
11919 if (!(inst.operands[j].isreg
11920 && inst.operands[j].isvec
11921 && inst.operands[j].issingle
11922 && !inst.operands[j].isquad))
11923 matches = 0;
11924 break;
11925
11926 case SE_D:
11927 if (!(inst.operands[j].isreg
11928 && inst.operands[j].isvec
11929 && !inst.operands[j].isquad
11930 && !inst.operands[j].issingle))
11931 matches = 0;
11932 break;
11933
11934 case SE_R:
11935 if (!(inst.operands[j].isreg
11936 && !inst.operands[j].isvec))
11937 matches = 0;
11938 break;
11939
11940 case SE_Q:
11941 if (!(inst.operands[j].isreg
11942 && inst.operands[j].isvec
11943 && inst.operands[j].isquad
11944 && !inst.operands[j].issingle))
11945 matches = 0;
11946 break;
11947
11948 case SE_I:
11949 if (!(!inst.operands[j].isreg
11950 && !inst.operands[j].isscalar))
11951 matches = 0;
11952 break;
11953
11954 case SE_S:
11955 if (!(!inst.operands[j].isreg
11956 && inst.operands[j].isscalar))
11957 matches = 0;
11958 break;
11959
11960 case SE_L:
11961 break;
11962 }
3fde54a2
JZ
11963 if (!matches)
11964 break;
037e8744
JB
11965 }
11966 if (matches)
5287ad62 11967 break;
037e8744 11968 }
5f4273c7 11969
037e8744 11970 va_end (ap);
5287ad62 11971
037e8744
JB
11972 if (shape == NS_NULL && first_shape != NS_NULL)
11973 first_error (_("invalid instruction shape"));
5287ad62 11974
037e8744
JB
11975 return shape;
11976}
5287ad62 11977
037e8744
JB
11978/* True if SHAPE is predominantly a quadword operation (most of the time, this
11979 means the Q bit should be set). */
11980
11981static int
11982neon_quad (enum neon_shape shape)
11983{
11984 return neon_shape_class[shape] == SC_QUAD;
5287ad62 11985}
037e8744 11986
5287ad62
JB
11987static void
11988neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11989 unsigned *g_size)
11990{
11991 /* Allow modification to be made to types which are constrained to be
11992 based on the key element, based on bits set alongside N_EQK. */
11993 if ((typebits & N_EQK) != 0)
11994 {
11995 if ((typebits & N_HLF) != 0)
11996 *g_size /= 2;
11997 else if ((typebits & N_DBL) != 0)
11998 *g_size *= 2;
11999 if ((typebits & N_SGN) != 0)
12000 *g_type = NT_signed;
12001 else if ((typebits & N_UNS) != 0)
12002 *g_type = NT_unsigned;
12003 else if ((typebits & N_INT) != 0)
12004 *g_type = NT_integer;
12005 else if ((typebits & N_FLT) != 0)
12006 *g_type = NT_float;
dcbf9037
JB
12007 else if ((typebits & N_SIZ) != 0)
12008 *g_type = NT_untyped;
5287ad62
JB
12009 }
12010}
5f4273c7 12011
5287ad62
JB
12012/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12013 operand type, i.e. the single type specified in a Neon instruction when it
12014 is the only one given. */
12015
12016static struct neon_type_el
12017neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12018{
12019 struct neon_type_el dest = *key;
5f4273c7 12020
9c2799c2 12021 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 12022
5287ad62
JB
12023 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12024
12025 return dest;
12026}
12027
12028/* Convert Neon type and size into compact bitmask representation. */
12029
12030static enum neon_type_mask
12031type_chk_of_el_type (enum neon_el_type type, unsigned size)
12032{
12033 switch (type)
12034 {
12035 case NT_untyped:
12036 switch (size)
12037 {
12038 case 8: return N_8;
12039 case 16: return N_16;
12040 case 32: return N_32;
12041 case 64: return N_64;
12042 default: ;
12043 }
12044 break;
12045
12046 case NT_integer:
12047 switch (size)
12048 {
12049 case 8: return N_I8;
12050 case 16: return N_I16;
12051 case 32: return N_I32;
12052 case 64: return N_I64;
12053 default: ;
12054 }
12055 break;
12056
12057 case NT_float:
037e8744
JB
12058 switch (size)
12059 {
8e79c3df 12060 case 16: return N_F16;
037e8744
JB
12061 case 32: return N_F32;
12062 case 64: return N_F64;
12063 default: ;
12064 }
5287ad62
JB
12065 break;
12066
12067 case NT_poly:
12068 switch (size)
12069 {
12070 case 8: return N_P8;
12071 case 16: return N_P16;
12072 default: ;
12073 }
12074 break;
12075
12076 case NT_signed:
12077 switch (size)
12078 {
12079 case 8: return N_S8;
12080 case 16: return N_S16;
12081 case 32: return N_S32;
12082 case 64: return N_S64;
12083 default: ;
12084 }
12085 break;
12086
12087 case NT_unsigned:
12088 switch (size)
12089 {
12090 case 8: return N_U8;
12091 case 16: return N_U16;
12092 case 32: return N_U32;
12093 case 64: return N_U64;
12094 default: ;
12095 }
12096 break;
12097
12098 default: ;
12099 }
5f4273c7 12100
5287ad62
JB
12101 return N_UTYP;
12102}
12103
12104/* Convert compact Neon bitmask type representation to a type and size. Only
12105 handles the case where a single bit is set in the mask. */
12106
dcbf9037 12107static int
5287ad62
JB
12108el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12109 enum neon_type_mask mask)
12110{
dcbf9037
JB
12111 if ((mask & N_EQK) != 0)
12112 return FAIL;
12113
5287ad62
JB
12114 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12115 *size = 8;
dcbf9037 12116 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 12117 *size = 16;
dcbf9037 12118 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 12119 *size = 32;
037e8744 12120 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 12121 *size = 64;
dcbf9037
JB
12122 else
12123 return FAIL;
12124
5287ad62
JB
12125 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12126 *type = NT_signed;
dcbf9037 12127 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 12128 *type = NT_unsigned;
dcbf9037 12129 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 12130 *type = NT_integer;
dcbf9037 12131 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 12132 *type = NT_untyped;
dcbf9037 12133 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 12134 *type = NT_poly;
037e8744 12135 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 12136 *type = NT_float;
dcbf9037
JB
12137 else
12138 return FAIL;
5f4273c7 12139
dcbf9037 12140 return SUCCESS;
5287ad62
JB
12141}
12142
12143/* Modify a bitmask of allowed types. This is only needed for type
12144 relaxation. */
12145
12146static unsigned
12147modify_types_allowed (unsigned allowed, unsigned mods)
12148{
12149 unsigned size;
12150 enum neon_el_type type;
12151 unsigned destmask;
12152 int i;
5f4273c7 12153
5287ad62 12154 destmask = 0;
5f4273c7 12155
5287ad62
JB
12156 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12157 {
21d799b5
NC
12158 if (el_type_of_type_chk (&type, &size,
12159 (enum neon_type_mask) (allowed & i)) == SUCCESS)
dcbf9037
JB
12160 {
12161 neon_modify_type_size (mods, &type, &size);
12162 destmask |= type_chk_of_el_type (type, size);
12163 }
5287ad62 12164 }
5f4273c7 12165
5287ad62
JB
12166 return destmask;
12167}
12168
12169/* Check type and return type classification.
12170 The manual states (paraphrase): If one datatype is given, it indicates the
12171 type given in:
12172 - the second operand, if there is one
12173 - the operand, if there is no second operand
12174 - the result, if there are no operands.
12175 This isn't quite good enough though, so we use a concept of a "key" datatype
12176 which is set on a per-instruction basis, which is the one which matters when
12177 only one data type is written.
12178 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 12179 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
12180
12181static struct neon_type_el
12182neon_check_type (unsigned els, enum neon_shape ns, ...)
12183{
12184 va_list ap;
12185 unsigned i, pass, key_el = 0;
12186 unsigned types[NEON_MAX_TYPE_ELS];
12187 enum neon_el_type k_type = NT_invtype;
12188 unsigned k_size = -1u;
12189 struct neon_type_el badtype = {NT_invtype, -1};
12190 unsigned key_allowed = 0;
12191
12192 /* Optional registers in Neon instructions are always (not) in operand 1.
12193 Fill in the missing operand here, if it was omitted. */
12194 if (els > 1 && !inst.operands[1].present)
12195 inst.operands[1] = inst.operands[0];
12196
12197 /* Suck up all the varargs. */
12198 va_start (ap, ns);
12199 for (i = 0; i < els; i++)
12200 {
12201 unsigned thisarg = va_arg (ap, unsigned);
12202 if (thisarg == N_IGNORE_TYPE)
12203 {
12204 va_end (ap);
12205 return badtype;
12206 }
12207 types[i] = thisarg;
12208 if ((thisarg & N_KEY) != 0)
12209 key_el = i;
12210 }
12211 va_end (ap);
12212
dcbf9037
JB
12213 if (inst.vectype.elems > 0)
12214 for (i = 0; i < els; i++)
12215 if (inst.operands[i].vectype.type != NT_invtype)
12216 {
12217 first_error (_("types specified in both the mnemonic and operands"));
12218 return badtype;
12219 }
12220
5287ad62
JB
12221 /* Duplicate inst.vectype elements here as necessary.
12222 FIXME: No idea if this is exactly the same as the ARM assembler,
12223 particularly when an insn takes one register and one non-register
12224 operand. */
12225 if (inst.vectype.elems == 1 && els > 1)
12226 {
12227 unsigned j;
12228 inst.vectype.elems = els;
12229 inst.vectype.el[key_el] = inst.vectype.el[0];
12230 for (j = 0; j < els; j++)
dcbf9037
JB
12231 if (j != key_el)
12232 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12233 types[j]);
12234 }
12235 else if (inst.vectype.elems == 0 && els > 0)
12236 {
12237 unsigned j;
12238 /* No types were given after the mnemonic, so look for types specified
12239 after each operand. We allow some flexibility here; as long as the
12240 "key" operand has a type, we can infer the others. */
12241 for (j = 0; j < els; j++)
12242 if (inst.operands[j].vectype.type != NT_invtype)
12243 inst.vectype.el[j] = inst.operands[j].vectype;
12244
12245 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 12246 {
dcbf9037
JB
12247 for (j = 0; j < els; j++)
12248 if (inst.operands[j].vectype.type == NT_invtype)
12249 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12250 types[j]);
12251 }
12252 else
12253 {
12254 first_error (_("operand types can't be inferred"));
12255 return badtype;
5287ad62
JB
12256 }
12257 }
12258 else if (inst.vectype.elems != els)
12259 {
dcbf9037 12260 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
12261 return badtype;
12262 }
12263
12264 for (pass = 0; pass < 2; pass++)
12265 {
12266 for (i = 0; i < els; i++)
12267 {
12268 unsigned thisarg = types[i];
12269 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12270 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12271 enum neon_el_type g_type = inst.vectype.el[i].type;
12272 unsigned g_size = inst.vectype.el[i].size;
12273
12274 /* Decay more-specific signed & unsigned types to sign-insensitive
12275 integer types if sign-specific variants are unavailable. */
12276 if ((g_type == NT_signed || g_type == NT_unsigned)
12277 && (types_allowed & N_SU_ALL) == 0)
12278 g_type = NT_integer;
12279
12280 /* If only untyped args are allowed, decay any more specific types to
12281 them. Some instructions only care about signs for some element
12282 sizes, so handle that properly. */
12283 if ((g_size == 8 && (types_allowed & N_8) != 0)
12284 || (g_size == 16 && (types_allowed & N_16) != 0)
12285 || (g_size == 32 && (types_allowed & N_32) != 0)
12286 || (g_size == 64 && (types_allowed & N_64) != 0))
12287 g_type = NT_untyped;
12288
12289 if (pass == 0)
12290 {
12291 if ((thisarg & N_KEY) != 0)
12292 {
12293 k_type = g_type;
12294 k_size = g_size;
12295 key_allowed = thisarg & ~N_KEY;
12296 }
12297 }
12298 else
12299 {
037e8744
JB
12300 if ((thisarg & N_VFP) != 0)
12301 {
99b253c5
NC
12302 enum neon_shape_el regshape;
12303 unsigned regwidth, match;
12304
12305 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12306 if (ns == NS_NULL)
12307 {
12308 first_error (_("invalid instruction shape"));
12309 return badtype;
12310 }
12311 regshape = neon_shape_tab[ns].el[i];
12312 regwidth = neon_shape_el_size[regshape];
037e8744
JB
12313
12314 /* In VFP mode, operands must match register widths. If we
12315 have a key operand, use its width, else use the width of
12316 the current operand. */
12317 if (k_size != -1u)
12318 match = k_size;
12319 else
12320 match = g_size;
12321
12322 if (regwidth != match)
12323 {
12324 first_error (_("operand size must match register width"));
12325 return badtype;
12326 }
12327 }
5f4273c7 12328
5287ad62
JB
12329 if ((thisarg & N_EQK) == 0)
12330 {
12331 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12332
12333 if ((given_type & types_allowed) == 0)
12334 {
dcbf9037 12335 first_error (_("bad type in Neon instruction"));
5287ad62
JB
12336 return badtype;
12337 }
12338 }
12339 else
12340 {
12341 enum neon_el_type mod_k_type = k_type;
12342 unsigned mod_k_size = k_size;
12343 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12344 if (g_type != mod_k_type || g_size != mod_k_size)
12345 {
dcbf9037 12346 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
12347 return badtype;
12348 }
12349 }
12350 }
12351 }
12352 }
12353
12354 return inst.vectype.el[key_el];
12355}
12356
037e8744 12357/* Neon-style VFP instruction forwarding. */
5287ad62 12358
037e8744
JB
12359/* Thumb VFP instructions have 0xE in the condition field. */
12360
12361static void
12362do_vfp_cond_or_thumb (void)
5287ad62 12363{
88714cb8
DG
12364 inst.is_neon = 1;
12365
5287ad62 12366 if (thumb_mode)
037e8744 12367 inst.instruction |= 0xe0000000;
5287ad62 12368 else
037e8744 12369 inst.instruction |= inst.cond << 28;
5287ad62
JB
12370}
12371
037e8744
JB
12372/* Look up and encode a simple mnemonic, for use as a helper function for the
12373 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12374 etc. It is assumed that operand parsing has already been done, and that the
12375 operands are in the form expected by the given opcode (this isn't necessarily
12376 the same as the form in which they were parsed, hence some massaging must
12377 take place before this function is called).
12378 Checks current arch version against that in the looked-up opcode. */
5287ad62 12379
037e8744
JB
12380static void
12381do_vfp_nsyn_opcode (const char *opname)
5287ad62 12382{
037e8744 12383 const struct asm_opcode *opcode;
5f4273c7 12384
21d799b5 12385 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 12386
037e8744
JB
12387 if (!opcode)
12388 abort ();
5287ad62 12389
037e8744
JB
12390 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12391 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12392 _(BAD_FPU));
5287ad62 12393
88714cb8
DG
12394 inst.is_neon = 1;
12395
037e8744
JB
12396 if (thumb_mode)
12397 {
12398 inst.instruction = opcode->tvalue;
12399 opcode->tencode ();
12400 }
12401 else
12402 {
12403 inst.instruction = (inst.cond << 28) | opcode->avalue;
12404 opcode->aencode ();
12405 }
12406}
5287ad62
JB
12407
12408static void
037e8744 12409do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 12410{
037e8744
JB
12411 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12412
12413 if (rs == NS_FFF)
12414 {
12415 if (is_add)
12416 do_vfp_nsyn_opcode ("fadds");
12417 else
12418 do_vfp_nsyn_opcode ("fsubs");
12419 }
12420 else
12421 {
12422 if (is_add)
12423 do_vfp_nsyn_opcode ("faddd");
12424 else
12425 do_vfp_nsyn_opcode ("fsubd");
12426 }
12427}
12428
12429/* Check operand types to see if this is a VFP instruction, and if so call
12430 PFN (). */
12431
12432static int
12433try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12434{
12435 enum neon_shape rs;
12436 struct neon_type_el et;
12437
12438 switch (args)
12439 {
12440 case 2:
12441 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12442 et = neon_check_type (2, rs,
12443 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12444 break;
5f4273c7 12445
037e8744
JB
12446 case 3:
12447 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12448 et = neon_check_type (3, rs,
12449 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12450 break;
12451
12452 default:
12453 abort ();
12454 }
12455
12456 if (et.type != NT_invtype)
12457 {
12458 pfn (rs);
12459 return SUCCESS;
12460 }
037e8744 12461
99b253c5 12462 inst.error = NULL;
037e8744
JB
12463 return FAIL;
12464}
12465
12466static void
12467do_vfp_nsyn_mla_mls (enum neon_shape rs)
12468{
12469 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 12470
037e8744
JB
12471 if (rs == NS_FFF)
12472 {
12473 if (is_mla)
12474 do_vfp_nsyn_opcode ("fmacs");
12475 else
1ee69515 12476 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
12477 }
12478 else
12479 {
12480 if (is_mla)
12481 do_vfp_nsyn_opcode ("fmacd");
12482 else
1ee69515 12483 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
12484 }
12485}
12486
62f3b8c8
PB
12487static void
12488do_vfp_nsyn_fma_fms (enum neon_shape rs)
12489{
12490 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12491
12492 if (rs == NS_FFF)
12493 {
12494 if (is_fma)
12495 do_vfp_nsyn_opcode ("ffmas");
12496 else
12497 do_vfp_nsyn_opcode ("ffnmas");
12498 }
12499 else
12500 {
12501 if (is_fma)
12502 do_vfp_nsyn_opcode ("ffmad");
12503 else
12504 do_vfp_nsyn_opcode ("ffnmad");
12505 }
12506}
12507
037e8744
JB
12508static void
12509do_vfp_nsyn_mul (enum neon_shape rs)
12510{
12511 if (rs == NS_FFF)
12512 do_vfp_nsyn_opcode ("fmuls");
12513 else
12514 do_vfp_nsyn_opcode ("fmuld");
12515}
12516
12517static void
12518do_vfp_nsyn_abs_neg (enum neon_shape rs)
12519{
12520 int is_neg = (inst.instruction & 0x80) != 0;
12521 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12522
12523 if (rs == NS_FF)
12524 {
12525 if (is_neg)
12526 do_vfp_nsyn_opcode ("fnegs");
12527 else
12528 do_vfp_nsyn_opcode ("fabss");
12529 }
12530 else
12531 {
12532 if (is_neg)
12533 do_vfp_nsyn_opcode ("fnegd");
12534 else
12535 do_vfp_nsyn_opcode ("fabsd");
12536 }
12537}
12538
12539/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12540 insns belong to Neon, and are handled elsewhere. */
12541
12542static void
12543do_vfp_nsyn_ldm_stm (int is_dbmode)
12544{
12545 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12546 if (is_ldm)
12547 {
12548 if (is_dbmode)
12549 do_vfp_nsyn_opcode ("fldmdbs");
12550 else
12551 do_vfp_nsyn_opcode ("fldmias");
12552 }
12553 else
12554 {
12555 if (is_dbmode)
12556 do_vfp_nsyn_opcode ("fstmdbs");
12557 else
12558 do_vfp_nsyn_opcode ("fstmias");
12559 }
12560}
12561
037e8744
JB
12562static void
12563do_vfp_nsyn_sqrt (void)
12564{
12565 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12566 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12567
037e8744
JB
12568 if (rs == NS_FF)
12569 do_vfp_nsyn_opcode ("fsqrts");
12570 else
12571 do_vfp_nsyn_opcode ("fsqrtd");
12572}
12573
12574static void
12575do_vfp_nsyn_div (void)
12576{
12577 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12578 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12579 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12580
037e8744
JB
12581 if (rs == NS_FFF)
12582 do_vfp_nsyn_opcode ("fdivs");
12583 else
12584 do_vfp_nsyn_opcode ("fdivd");
12585}
12586
12587static void
12588do_vfp_nsyn_nmul (void)
12589{
12590 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12591 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12592 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12593
037e8744
JB
12594 if (rs == NS_FFF)
12595 {
88714cb8 12596 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12597 do_vfp_sp_dyadic ();
12598 }
12599 else
12600 {
88714cb8 12601 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12602 do_vfp_dp_rd_rn_rm ();
12603 }
12604 do_vfp_cond_or_thumb ();
12605}
12606
12607static void
12608do_vfp_nsyn_cmp (void)
12609{
12610 if (inst.operands[1].isreg)
12611 {
12612 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12613 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12614
037e8744
JB
12615 if (rs == NS_FF)
12616 {
88714cb8 12617 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12618 do_vfp_sp_monadic ();
12619 }
12620 else
12621 {
88714cb8 12622 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12623 do_vfp_dp_rd_rm ();
12624 }
12625 }
12626 else
12627 {
12628 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12629 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12630
12631 switch (inst.instruction & 0x0fffffff)
12632 {
12633 case N_MNEM_vcmp:
12634 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12635 break;
12636 case N_MNEM_vcmpe:
12637 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12638 break;
12639 default:
12640 abort ();
12641 }
5f4273c7 12642
037e8744
JB
12643 if (rs == NS_FI)
12644 {
88714cb8 12645 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12646 do_vfp_sp_compare_z ();
12647 }
12648 else
12649 {
88714cb8 12650 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12651 do_vfp_dp_rd ();
12652 }
12653 }
12654 do_vfp_cond_or_thumb ();
12655}
12656
12657static void
12658nsyn_insert_sp (void)
12659{
12660 inst.operands[1] = inst.operands[0];
12661 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 12662 inst.operands[0].reg = REG_SP;
037e8744
JB
12663 inst.operands[0].isreg = 1;
12664 inst.operands[0].writeback = 1;
12665 inst.operands[0].present = 1;
12666}
12667
12668static void
12669do_vfp_nsyn_push (void)
12670{
12671 nsyn_insert_sp ();
12672 if (inst.operands[1].issingle)
12673 do_vfp_nsyn_opcode ("fstmdbs");
12674 else
12675 do_vfp_nsyn_opcode ("fstmdbd");
12676}
12677
12678static void
12679do_vfp_nsyn_pop (void)
12680{
12681 nsyn_insert_sp ();
12682 if (inst.operands[1].issingle)
22b5b651 12683 do_vfp_nsyn_opcode ("fldmias");
037e8744 12684 else
22b5b651 12685 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
12686}
12687
12688/* Fix up Neon data-processing instructions, ORing in the correct bits for
12689 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12690
88714cb8
DG
12691static void
12692neon_dp_fixup (struct arm_it* insn)
037e8744 12693{
88714cb8
DG
12694 unsigned int i = insn->instruction;
12695 insn->is_neon = 1;
12696
037e8744
JB
12697 if (thumb_mode)
12698 {
12699 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12700 if (i & (1 << 24))
12701 i |= 1 << 28;
5f4273c7 12702
037e8744 12703 i &= ~(1 << 24);
5f4273c7 12704
037e8744
JB
12705 i |= 0xef000000;
12706 }
12707 else
12708 i |= 0xf2000000;
5f4273c7 12709
88714cb8 12710 insn->instruction = i;
037e8744
JB
12711}
12712
12713/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12714 (0, 1, 2, 3). */
12715
12716static unsigned
12717neon_logbits (unsigned x)
12718{
12719 return ffs (x) - 4;
12720}
12721
12722#define LOW4(R) ((R) & 0xf)
12723#define HI1(R) (((R) >> 4) & 1)
12724
12725/* Encode insns with bit pattern:
12726
12727 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12728 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 12729
037e8744
JB
12730 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12731 different meaning for some instruction. */
12732
12733static void
12734neon_three_same (int isquad, int ubit, int size)
12735{
12736 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12737 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12738 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12739 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12740 inst.instruction |= LOW4 (inst.operands[2].reg);
12741 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12742 inst.instruction |= (isquad != 0) << 6;
12743 inst.instruction |= (ubit != 0) << 24;
12744 if (size != -1)
12745 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12746
88714cb8 12747 neon_dp_fixup (&inst);
037e8744
JB
12748}
12749
12750/* Encode instructions of the form:
12751
12752 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12753 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
12754
12755 Don't write size if SIZE == -1. */
12756
12757static void
12758neon_two_same (int qbit, int ubit, int size)
12759{
12760 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12761 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12762 inst.instruction |= LOW4 (inst.operands[1].reg);
12763 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12764 inst.instruction |= (qbit != 0) << 6;
12765 inst.instruction |= (ubit != 0) << 24;
12766
12767 if (size != -1)
12768 inst.instruction |= neon_logbits (size) << 18;
12769
88714cb8 12770 neon_dp_fixup (&inst);
5287ad62
JB
12771}
12772
12773/* Neon instruction encoders, in approximate order of appearance. */
12774
12775static void
12776do_neon_dyadic_i_su (void)
12777{
037e8744 12778 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12779 struct neon_type_el et = neon_check_type (3, rs,
12780 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 12781 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12782}
12783
12784static void
12785do_neon_dyadic_i64_su (void)
12786{
037e8744 12787 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12788 struct neon_type_el et = neon_check_type (3, rs,
12789 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 12790 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12791}
12792
12793static void
12794neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12795 unsigned immbits)
12796{
12797 unsigned size = et.size >> 3;
12798 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12799 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12800 inst.instruction |= LOW4 (inst.operands[1].reg);
12801 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12802 inst.instruction |= (isquad != 0) << 6;
12803 inst.instruction |= immbits << 16;
12804 inst.instruction |= (size >> 3) << 7;
12805 inst.instruction |= (size & 0x7) << 19;
12806 if (write_ubit)
12807 inst.instruction |= (uval != 0) << 24;
12808
88714cb8 12809 neon_dp_fixup (&inst);
5287ad62
JB
12810}
12811
12812static void
12813do_neon_shl_imm (void)
12814{
12815 if (!inst.operands[2].isreg)
12816 {
037e8744 12817 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12818 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
88714cb8 12819 NEON_ENCODE (IMMED, inst);
037e8744 12820 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
12821 }
12822 else
12823 {
037e8744 12824 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12825 struct neon_type_el et = neon_check_type (3, rs,
12826 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12827 unsigned int tmp;
12828
12829 /* VSHL/VQSHL 3-register variants have syntax such as:
12830 vshl.xx Dd, Dm, Dn
12831 whereas other 3-register operations encoded by neon_three_same have
12832 syntax like:
12833 vadd.xx Dd, Dn, Dm
12834 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12835 here. */
12836 tmp = inst.operands[2].reg;
12837 inst.operands[2].reg = inst.operands[1].reg;
12838 inst.operands[1].reg = tmp;
88714cb8 12839 NEON_ENCODE (INTEGER, inst);
037e8744 12840 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12841 }
12842}
12843
12844static void
12845do_neon_qshl_imm (void)
12846{
12847 if (!inst.operands[2].isreg)
12848 {
037e8744 12849 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12850 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 12851
88714cb8 12852 NEON_ENCODE (IMMED, inst);
037e8744 12853 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
12854 inst.operands[2].imm);
12855 }
12856 else
12857 {
037e8744 12858 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12859 struct neon_type_el et = neon_check_type (3, rs,
12860 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12861 unsigned int tmp;
12862
12863 /* See note in do_neon_shl_imm. */
12864 tmp = inst.operands[2].reg;
12865 inst.operands[2].reg = inst.operands[1].reg;
12866 inst.operands[1].reg = tmp;
88714cb8 12867 NEON_ENCODE (INTEGER, inst);
037e8744 12868 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12869 }
12870}
12871
627907b7
JB
12872static void
12873do_neon_rshl (void)
12874{
12875 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12876 struct neon_type_el et = neon_check_type (3, rs,
12877 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12878 unsigned int tmp;
12879
12880 tmp = inst.operands[2].reg;
12881 inst.operands[2].reg = inst.operands[1].reg;
12882 inst.operands[1].reg = tmp;
12883 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12884}
12885
5287ad62
JB
12886static int
12887neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12888{
036dc3f7
PB
12889 /* Handle .I8 pseudo-instructions. */
12890 if (size == 8)
5287ad62 12891 {
5287ad62
JB
12892 /* Unfortunately, this will make everything apart from zero out-of-range.
12893 FIXME is this the intended semantics? There doesn't seem much point in
12894 accepting .I8 if so. */
12895 immediate |= immediate << 8;
12896 size = 16;
036dc3f7
PB
12897 }
12898
12899 if (size >= 32)
12900 {
12901 if (immediate == (immediate & 0x000000ff))
12902 {
12903 *immbits = immediate;
12904 return 0x1;
12905 }
12906 else if (immediate == (immediate & 0x0000ff00))
12907 {
12908 *immbits = immediate >> 8;
12909 return 0x3;
12910 }
12911 else if (immediate == (immediate & 0x00ff0000))
12912 {
12913 *immbits = immediate >> 16;
12914 return 0x5;
12915 }
12916 else if (immediate == (immediate & 0xff000000))
12917 {
12918 *immbits = immediate >> 24;
12919 return 0x7;
12920 }
12921 if ((immediate & 0xffff) != (immediate >> 16))
12922 goto bad_immediate;
12923 immediate &= 0xffff;
5287ad62
JB
12924 }
12925
12926 if (immediate == (immediate & 0x000000ff))
12927 {
12928 *immbits = immediate;
036dc3f7 12929 return 0x9;
5287ad62
JB
12930 }
12931 else if (immediate == (immediate & 0x0000ff00))
12932 {
12933 *immbits = immediate >> 8;
036dc3f7 12934 return 0xb;
5287ad62
JB
12935 }
12936
12937 bad_immediate:
dcbf9037 12938 first_error (_("immediate value out of range"));
5287ad62
JB
12939 return FAIL;
12940}
12941
12942/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12943 A, B, C, D. */
12944
12945static int
12946neon_bits_same_in_bytes (unsigned imm)
12947{
12948 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12949 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12950 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12951 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12952}
12953
12954/* For immediate of above form, return 0bABCD. */
12955
12956static unsigned
12957neon_squash_bits (unsigned imm)
12958{
12959 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12960 | ((imm & 0x01000000) >> 21);
12961}
12962
136da414 12963/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
12964
12965static unsigned
12966neon_qfloat_bits (unsigned imm)
12967{
136da414 12968 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
12969}
12970
12971/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12972 the instruction. *OP is passed as the initial value of the op field, and
12973 may be set to a different value depending on the constant (i.e.
12974 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 12975 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 12976 try smaller element sizes. */
5287ad62
JB
12977
12978static int
c96612cc
JB
12979neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12980 unsigned *immbits, int *op, int size,
12981 enum neon_el_type type)
5287ad62 12982{
c96612cc
JB
12983 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12984 float. */
12985 if (type == NT_float && !float_p)
12986 return FAIL;
12987
136da414
JB
12988 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12989 {
12990 if (size != 32 || *op == 1)
12991 return FAIL;
12992 *immbits = neon_qfloat_bits (immlo);
12993 return 0xf;
12994 }
036dc3f7
PB
12995
12996 if (size == 64)
5287ad62 12997 {
036dc3f7
PB
12998 if (neon_bits_same_in_bytes (immhi)
12999 && neon_bits_same_in_bytes (immlo))
13000 {
13001 if (*op == 1)
13002 return FAIL;
13003 *immbits = (neon_squash_bits (immhi) << 4)
13004 | neon_squash_bits (immlo);
13005 *op = 1;
13006 return 0xe;
13007 }
13008
13009 if (immhi != immlo)
13010 return FAIL;
5287ad62 13011 }
036dc3f7
PB
13012
13013 if (size >= 32)
5287ad62 13014 {
036dc3f7
PB
13015 if (immlo == (immlo & 0x000000ff))
13016 {
13017 *immbits = immlo;
13018 return 0x0;
13019 }
13020 else if (immlo == (immlo & 0x0000ff00))
13021 {
13022 *immbits = immlo >> 8;
13023 return 0x2;
13024 }
13025 else if (immlo == (immlo & 0x00ff0000))
13026 {
13027 *immbits = immlo >> 16;
13028 return 0x4;
13029 }
13030 else if (immlo == (immlo & 0xff000000))
13031 {
13032 *immbits = immlo >> 24;
13033 return 0x6;
13034 }
13035 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13036 {
13037 *immbits = (immlo >> 8) & 0xff;
13038 return 0xc;
13039 }
13040 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13041 {
13042 *immbits = (immlo >> 16) & 0xff;
13043 return 0xd;
13044 }
13045
13046 if ((immlo & 0xffff) != (immlo >> 16))
13047 return FAIL;
13048 immlo &= 0xffff;
5287ad62 13049 }
036dc3f7
PB
13050
13051 if (size >= 16)
5287ad62 13052 {
036dc3f7
PB
13053 if (immlo == (immlo & 0x000000ff))
13054 {
13055 *immbits = immlo;
13056 return 0x8;
13057 }
13058 else if (immlo == (immlo & 0x0000ff00))
13059 {
13060 *immbits = immlo >> 8;
13061 return 0xa;
13062 }
13063
13064 if ((immlo & 0xff) != (immlo >> 8))
13065 return FAIL;
13066 immlo &= 0xff;
5287ad62 13067 }
036dc3f7
PB
13068
13069 if (immlo == (immlo & 0x000000ff))
5287ad62 13070 {
036dc3f7
PB
13071 /* Don't allow MVN with 8-bit immediate. */
13072 if (*op == 1)
13073 return FAIL;
13074 *immbits = immlo;
13075 return 0xe;
5287ad62 13076 }
5287ad62
JB
13077
13078 return FAIL;
13079}
13080
13081/* Write immediate bits [7:0] to the following locations:
13082
13083 |28/24|23 19|18 16|15 4|3 0|
13084 | 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|
13085
13086 This function is used by VMOV/VMVN/VORR/VBIC. */
13087
13088static void
13089neon_write_immbits (unsigned immbits)
13090{
13091 inst.instruction |= immbits & 0xf;
13092 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13093 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13094}
13095
13096/* Invert low-order SIZE bits of XHI:XLO. */
13097
13098static void
13099neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13100{
13101 unsigned immlo = xlo ? *xlo : 0;
13102 unsigned immhi = xhi ? *xhi : 0;
13103
13104 switch (size)
13105 {
13106 case 8:
13107 immlo = (~immlo) & 0xff;
13108 break;
13109
13110 case 16:
13111 immlo = (~immlo) & 0xffff;
13112 break;
13113
13114 case 64:
13115 immhi = (~immhi) & 0xffffffff;
13116 /* fall through. */
13117
13118 case 32:
13119 immlo = (~immlo) & 0xffffffff;
13120 break;
13121
13122 default:
13123 abort ();
13124 }
13125
13126 if (xlo)
13127 *xlo = immlo;
13128
13129 if (xhi)
13130 *xhi = immhi;
13131}
13132
13133static void
13134do_neon_logic (void)
13135{
13136 if (inst.operands[2].present && inst.operands[2].isreg)
13137 {
037e8744 13138 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13139 neon_check_type (3, rs, N_IGNORE_TYPE);
13140 /* U bit and size field were set as part of the bitmask. */
88714cb8 13141 NEON_ENCODE (INTEGER, inst);
037e8744 13142 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13143 }
13144 else
13145 {
4316f0d2
DG
13146 const int three_ops_form = (inst.operands[2].present
13147 && !inst.operands[2].isreg);
13148 const int immoperand = (three_ops_form ? 2 : 1);
13149 enum neon_shape rs = (three_ops_form
13150 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13151 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744
JB
13152 struct neon_type_el et = neon_check_type (2, rs,
13153 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 13154 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
13155 unsigned immbits;
13156 int cmode;
5f4273c7 13157
5287ad62
JB
13158 if (et.type == NT_invtype)
13159 return;
5f4273c7 13160
4316f0d2
DG
13161 if (three_ops_form)
13162 constraint (inst.operands[0].reg != inst.operands[1].reg,
13163 _("first and second operands shall be the same register"));
13164
88714cb8 13165 NEON_ENCODE (IMMED, inst);
5287ad62 13166
4316f0d2 13167 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
13168 if (et.size == 64)
13169 {
13170 /* .i64 is a pseudo-op, so the immediate must be a repeating
13171 pattern. */
4316f0d2
DG
13172 if (immbits != (inst.operands[immoperand].regisimm ?
13173 inst.operands[immoperand].reg : 0))
036dc3f7
PB
13174 {
13175 /* Set immbits to an invalid constant. */
13176 immbits = 0xdeadbeef;
13177 }
13178 }
13179
5287ad62
JB
13180 switch (opcode)
13181 {
13182 case N_MNEM_vbic:
036dc3f7 13183 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13184 break;
5f4273c7 13185
5287ad62 13186 case N_MNEM_vorr:
036dc3f7 13187 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13188 break;
5f4273c7 13189
5287ad62
JB
13190 case N_MNEM_vand:
13191 /* Pseudo-instruction for VBIC. */
5287ad62
JB
13192 neon_invert_size (&immbits, 0, et.size);
13193 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13194 break;
5f4273c7 13195
5287ad62
JB
13196 case N_MNEM_vorn:
13197 /* Pseudo-instruction for VORR. */
5287ad62
JB
13198 neon_invert_size (&immbits, 0, et.size);
13199 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13200 break;
5f4273c7 13201
5287ad62
JB
13202 default:
13203 abort ();
13204 }
13205
13206 if (cmode == FAIL)
13207 return;
13208
037e8744 13209 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13210 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13211 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13212 inst.instruction |= cmode << 8;
13213 neon_write_immbits (immbits);
5f4273c7 13214
88714cb8 13215 neon_dp_fixup (&inst);
5287ad62
JB
13216 }
13217}
13218
13219static void
13220do_neon_bitfield (void)
13221{
037e8744 13222 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 13223 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 13224 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13225}
13226
13227static void
dcbf9037
JB
13228neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13229 unsigned destbits)
5287ad62 13230{
037e8744 13231 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
13232 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13233 types | N_KEY);
5287ad62
JB
13234 if (et.type == NT_float)
13235 {
88714cb8 13236 NEON_ENCODE (FLOAT, inst);
037e8744 13237 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13238 }
13239 else
13240 {
88714cb8 13241 NEON_ENCODE (INTEGER, inst);
037e8744 13242 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
13243 }
13244}
13245
13246static void
13247do_neon_dyadic_if_su (void)
13248{
dcbf9037 13249 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13250}
13251
13252static void
13253do_neon_dyadic_if_su_d (void)
13254{
13255 /* This version only allow D registers, but that constraint is enforced during
13256 operand parsing so we don't need to do anything extra here. */
dcbf9037 13257 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13258}
13259
5287ad62
JB
13260static void
13261do_neon_dyadic_if_i_d (void)
13262{
428e3f1f
PB
13263 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13264 affected if we specify unsigned args. */
13265 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
13266}
13267
037e8744
JB
13268enum vfp_or_neon_is_neon_bits
13269{
13270 NEON_CHECK_CC = 1,
13271 NEON_CHECK_ARCH = 2
13272};
13273
13274/* Call this function if an instruction which may have belonged to the VFP or
13275 Neon instruction sets, but turned out to be a Neon instruction (due to the
13276 operand types involved, etc.). We have to check and/or fix-up a couple of
13277 things:
13278
13279 - Make sure the user hasn't attempted to make a Neon instruction
13280 conditional.
13281 - Alter the value in the condition code field if necessary.
13282 - Make sure that the arch supports Neon instructions.
13283
13284 Which of these operations take place depends on bits from enum
13285 vfp_or_neon_is_neon_bits.
13286
13287 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13288 current instruction's condition is COND_ALWAYS, the condition field is
13289 changed to inst.uncond_value. This is necessary because instructions shared
13290 between VFP and Neon may be conditional for the VFP variants only, and the
13291 unconditional Neon version must have, e.g., 0xF in the condition field. */
13292
13293static int
13294vfp_or_neon_is_neon (unsigned check)
13295{
13296 /* Conditions are always legal in Thumb mode (IT blocks). */
13297 if (!thumb_mode && (check & NEON_CHECK_CC))
13298 {
13299 if (inst.cond != COND_ALWAYS)
13300 {
13301 first_error (_(BAD_COND));
13302 return FAIL;
13303 }
13304 if (inst.uncond_value != -1)
13305 inst.instruction |= inst.uncond_value << 28;
13306 }
5f4273c7 13307
037e8744
JB
13308 if ((check & NEON_CHECK_ARCH)
13309 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13310 {
13311 first_error (_(BAD_FPU));
13312 return FAIL;
13313 }
5f4273c7 13314
037e8744
JB
13315 return SUCCESS;
13316}
13317
5287ad62
JB
13318static void
13319do_neon_addsub_if_i (void)
13320{
037e8744
JB
13321 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13322 return;
13323
13324 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13325 return;
13326
5287ad62
JB
13327 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13328 affected if we specify unsigned args. */
dcbf9037 13329 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
13330}
13331
13332/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13333 result to be:
13334 V<op> A,B (A is operand 0, B is operand 2)
13335 to mean:
13336 V<op> A,B,A
13337 not:
13338 V<op> A,B,B
13339 so handle that case specially. */
13340
13341static void
13342neon_exchange_operands (void)
13343{
13344 void *scratch = alloca (sizeof (inst.operands[0]));
13345 if (inst.operands[1].present)
13346 {
13347 /* Swap operands[1] and operands[2]. */
13348 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13349 inst.operands[1] = inst.operands[2];
13350 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13351 }
13352 else
13353 {
13354 inst.operands[1] = inst.operands[2];
13355 inst.operands[2] = inst.operands[0];
13356 }
13357}
13358
13359static void
13360neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13361{
13362 if (inst.operands[2].isreg)
13363 {
13364 if (invert)
13365 neon_exchange_operands ();
dcbf9037 13366 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
13367 }
13368 else
13369 {
037e8744 13370 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
13371 struct neon_type_el et = neon_check_type (2, rs,
13372 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 13373
88714cb8 13374 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13375 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13376 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13377 inst.instruction |= LOW4 (inst.operands[1].reg);
13378 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13379 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13380 inst.instruction |= (et.type == NT_float) << 10;
13381 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13382
88714cb8 13383 neon_dp_fixup (&inst);
5287ad62
JB
13384 }
13385}
13386
13387static void
13388do_neon_cmp (void)
13389{
13390 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13391}
13392
13393static void
13394do_neon_cmp_inv (void)
13395{
13396 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13397}
13398
13399static void
13400do_neon_ceq (void)
13401{
13402 neon_compare (N_IF_32, N_IF_32, FALSE);
13403}
13404
13405/* For multiply instructions, we have the possibility of 16-bit or 32-bit
13406 scalars, which are encoded in 5 bits, M : Rm.
13407 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13408 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13409 index in M. */
13410
13411static unsigned
13412neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13413{
dcbf9037
JB
13414 unsigned regno = NEON_SCALAR_REG (scalar);
13415 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
13416
13417 switch (elsize)
13418 {
13419 case 16:
13420 if (regno > 7 || elno > 3)
13421 goto bad_scalar;
13422 return regno | (elno << 3);
5f4273c7 13423
5287ad62
JB
13424 case 32:
13425 if (regno > 15 || elno > 1)
13426 goto bad_scalar;
13427 return regno | (elno << 4);
13428
13429 default:
13430 bad_scalar:
dcbf9037 13431 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
13432 }
13433
13434 return 0;
13435}
13436
13437/* Encode multiply / multiply-accumulate scalar instructions. */
13438
13439static void
13440neon_mul_mac (struct neon_type_el et, int ubit)
13441{
dcbf9037
JB
13442 unsigned scalar;
13443
13444 /* Give a more helpful error message if we have an invalid type. */
13445 if (et.type == NT_invtype)
13446 return;
5f4273c7 13447
dcbf9037 13448 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
13449 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13450 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13451 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13452 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13453 inst.instruction |= LOW4 (scalar);
13454 inst.instruction |= HI1 (scalar) << 5;
13455 inst.instruction |= (et.type == NT_float) << 8;
13456 inst.instruction |= neon_logbits (et.size) << 20;
13457 inst.instruction |= (ubit != 0) << 24;
13458
88714cb8 13459 neon_dp_fixup (&inst);
5287ad62
JB
13460}
13461
13462static void
13463do_neon_mac_maybe_scalar (void)
13464{
037e8744
JB
13465 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13466 return;
13467
13468 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13469 return;
13470
5287ad62
JB
13471 if (inst.operands[2].isscalar)
13472 {
037e8744 13473 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13474 struct neon_type_el et = neon_check_type (3, rs,
13475 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 13476 NEON_ENCODE (SCALAR, inst);
037e8744 13477 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13478 }
13479 else
428e3f1f
PB
13480 {
13481 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13482 affected if we specify unsigned args. */
13483 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13484 }
5287ad62
JB
13485}
13486
62f3b8c8
PB
13487static void
13488do_neon_fmac (void)
13489{
13490 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13491 return;
13492
13493 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13494 return;
13495
13496 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13497}
13498
5287ad62
JB
13499static void
13500do_neon_tst (void)
13501{
037e8744 13502 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13503 struct neon_type_el et = neon_check_type (3, rs,
13504 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 13505 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13506}
13507
13508/* VMUL with 3 registers allows the P8 type. The scalar version supports the
13509 same types as the MAC equivalents. The polynomial type for this instruction
13510 is encoded the same as the integer type. */
13511
13512static void
13513do_neon_mul (void)
13514{
037e8744
JB
13515 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13516 return;
13517
13518 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13519 return;
13520
5287ad62
JB
13521 if (inst.operands[2].isscalar)
13522 do_neon_mac_maybe_scalar ();
13523 else
dcbf9037 13524 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
13525}
13526
13527static void
13528do_neon_qdmulh (void)
13529{
13530 if (inst.operands[2].isscalar)
13531 {
037e8744 13532 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13533 struct neon_type_el et = neon_check_type (3, rs,
13534 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13535 NEON_ENCODE (SCALAR, inst);
037e8744 13536 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13537 }
13538 else
13539 {
037e8744 13540 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13541 struct neon_type_el et = neon_check_type (3, rs,
13542 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13543 NEON_ENCODE (INTEGER, inst);
5287ad62 13544 /* The U bit (rounding) comes from bit mask. */
037e8744 13545 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13546 }
13547}
13548
13549static void
13550do_neon_fcmp_absolute (void)
13551{
037e8744 13552 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13553 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13554 /* Size field comes from bit mask. */
037e8744 13555 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
13556}
13557
13558static void
13559do_neon_fcmp_absolute_inv (void)
13560{
13561 neon_exchange_operands ();
13562 do_neon_fcmp_absolute ();
13563}
13564
13565static void
13566do_neon_step (void)
13567{
037e8744 13568 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 13569 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 13570 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13571}
13572
13573static void
13574do_neon_abs_neg (void)
13575{
037e8744
JB
13576 enum neon_shape rs;
13577 struct neon_type_el et;
5f4273c7 13578
037e8744
JB
13579 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13580 return;
13581
13582 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13583 return;
13584
13585 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13586 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 13587
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);
13591 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13592 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13593 inst.instruction |= (et.type == NT_float) << 10;
13594 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13595
88714cb8 13596 neon_dp_fixup (&inst);
5287ad62
JB
13597}
13598
13599static void
13600do_neon_sli (void)
13601{
037e8744 13602 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13603 struct neon_type_el et = neon_check_type (2, rs,
13604 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13605 int imm = inst.operands[2].imm;
13606 constraint (imm < 0 || (unsigned)imm >= et.size,
13607 _("immediate out of range for insert"));
037e8744 13608 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13609}
13610
13611static void
13612do_neon_sri (void)
13613{
037e8744 13614 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13615 struct neon_type_el et = neon_check_type (2, rs,
13616 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13617 int imm = inst.operands[2].imm;
13618 constraint (imm < 1 || (unsigned)imm > et.size,
13619 _("immediate out of range for insert"));
037e8744 13620 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
13621}
13622
13623static void
13624do_neon_qshlu_imm (void)
13625{
037e8744 13626 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13627 struct neon_type_el et = neon_check_type (2, rs,
13628 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13629 int imm = inst.operands[2].imm;
13630 constraint (imm < 0 || (unsigned)imm >= et.size,
13631 _("immediate out of range for shift"));
13632 /* Only encodes the 'U present' variant of the instruction.
13633 In this case, signed types have OP (bit 8) set to 0.
13634 Unsigned types have OP set to 1. */
13635 inst.instruction |= (et.type == NT_unsigned) << 8;
13636 /* The rest of the bits are the same as other immediate shifts. */
037e8744 13637 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13638}
13639
13640static void
13641do_neon_qmovn (void)
13642{
13643 struct neon_type_el et = neon_check_type (2, NS_DQ,
13644 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13645 /* Saturating move where operands can be signed or unsigned, and the
13646 destination has the same signedness. */
88714cb8 13647 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13648 if (et.type == NT_unsigned)
13649 inst.instruction |= 0xc0;
13650 else
13651 inst.instruction |= 0x80;
13652 neon_two_same (0, 1, et.size / 2);
13653}
13654
13655static void
13656do_neon_qmovun (void)
13657{
13658 struct neon_type_el et = neon_check_type (2, NS_DQ,
13659 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13660 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 13661 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13662 neon_two_same (0, 1, et.size / 2);
13663}
13664
13665static void
13666do_neon_rshift_sat_narrow (void)
13667{
13668 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13669 or unsigned. If operands are unsigned, results must also be unsigned. */
13670 struct neon_type_el et = neon_check_type (2, NS_DQI,
13671 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13672 int imm = inst.operands[2].imm;
13673 /* This gets the bounds check, size encoding and immediate bits calculation
13674 right. */
13675 et.size /= 2;
5f4273c7 13676
5287ad62
JB
13677 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13678 VQMOVN.I<size> <Dd>, <Qm>. */
13679 if (imm == 0)
13680 {
13681 inst.operands[2].present = 0;
13682 inst.instruction = N_MNEM_vqmovn;
13683 do_neon_qmovn ();
13684 return;
13685 }
5f4273c7 13686
5287ad62
JB
13687 constraint (imm < 1 || (unsigned)imm > et.size,
13688 _("immediate out of range"));
13689 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13690}
13691
13692static void
13693do_neon_rshift_sat_narrow_u (void)
13694{
13695 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13696 or unsigned. If operands are unsigned, results must also be unsigned. */
13697 struct neon_type_el et = neon_check_type (2, NS_DQI,
13698 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13699 int imm = inst.operands[2].imm;
13700 /* This gets the bounds check, size encoding and immediate bits calculation
13701 right. */
13702 et.size /= 2;
13703
13704 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13705 VQMOVUN.I<size> <Dd>, <Qm>. */
13706 if (imm == 0)
13707 {
13708 inst.operands[2].present = 0;
13709 inst.instruction = N_MNEM_vqmovun;
13710 do_neon_qmovun ();
13711 return;
13712 }
13713
13714 constraint (imm < 1 || (unsigned)imm > et.size,
13715 _("immediate out of range"));
13716 /* FIXME: The manual is kind of unclear about what value U should have in
13717 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13718 must be 1. */
13719 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13720}
13721
13722static void
13723do_neon_movn (void)
13724{
13725 struct neon_type_el et = neon_check_type (2, NS_DQ,
13726 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 13727 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13728 neon_two_same (0, 1, et.size / 2);
13729}
13730
13731static void
13732do_neon_rshift_narrow (void)
13733{
13734 struct neon_type_el et = neon_check_type (2, NS_DQI,
13735 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13736 int imm = inst.operands[2].imm;
13737 /* This gets the bounds check, size encoding and immediate bits calculation
13738 right. */
13739 et.size /= 2;
5f4273c7 13740
5287ad62
JB
13741 /* If immediate is zero then we are a pseudo-instruction for
13742 VMOVN.I<size> <Dd>, <Qm> */
13743 if (imm == 0)
13744 {
13745 inst.operands[2].present = 0;
13746 inst.instruction = N_MNEM_vmovn;
13747 do_neon_movn ();
13748 return;
13749 }
5f4273c7 13750
5287ad62
JB
13751 constraint (imm < 1 || (unsigned)imm > et.size,
13752 _("immediate out of range for narrowing operation"));
13753 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13754}
13755
13756static void
13757do_neon_shll (void)
13758{
13759 /* FIXME: Type checking when lengthening. */
13760 struct neon_type_el et = neon_check_type (2, NS_QDI,
13761 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13762 unsigned imm = inst.operands[2].imm;
13763
13764 if (imm == et.size)
13765 {
13766 /* Maximum shift variant. */
88714cb8 13767 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13768 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13769 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13770 inst.instruction |= LOW4 (inst.operands[1].reg);
13771 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13772 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13773
88714cb8 13774 neon_dp_fixup (&inst);
5287ad62
JB
13775 }
13776 else
13777 {
13778 /* A more-specific type check for non-max versions. */
13779 et = neon_check_type (2, NS_QDI,
13780 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 13781 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13782 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13783 }
13784}
13785
037e8744 13786/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
13787 the current instruction is. */
13788
13789static int
13790neon_cvt_flavour (enum neon_shape rs)
13791{
037e8744
JB
13792#define CVT_VAR(C,X,Y) \
13793 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13794 if (et.type != NT_invtype) \
13795 { \
13796 inst.error = NULL; \
13797 return (C); \
5287ad62
JB
13798 }
13799 struct neon_type_el et;
037e8744
JB
13800 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13801 || rs == NS_FF) ? N_VFP : 0;
13802 /* The instruction versions which take an immediate take one register
13803 argument, which is extended to the width of the full register. Thus the
13804 "source" and "destination" registers must have the same width. Hack that
13805 here by making the size equal to the key (wider, in this case) operand. */
13806 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 13807
5287ad62
JB
13808 CVT_VAR (0, N_S32, N_F32);
13809 CVT_VAR (1, N_U32, N_F32);
13810 CVT_VAR (2, N_F32, N_S32);
13811 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
13812 /* Half-precision conversions. */
13813 CVT_VAR (4, N_F32, N_F16);
13814 CVT_VAR (5, N_F16, N_F32);
5f4273c7 13815
037e8744 13816 whole_reg = N_VFP;
5f4273c7 13817
037e8744 13818 /* VFP instructions. */
8e79c3df
CM
13819 CVT_VAR (6, N_F32, N_F64);
13820 CVT_VAR (7, N_F64, N_F32);
13821 CVT_VAR (8, N_S32, N_F64 | key);
13822 CVT_VAR (9, N_U32, N_F64 | key);
13823 CVT_VAR (10, N_F64 | key, N_S32);
13824 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 13825 /* VFP instructions with bitshift. */
8e79c3df
CM
13826 CVT_VAR (12, N_F32 | key, N_S16);
13827 CVT_VAR (13, N_F32 | key, N_U16);
13828 CVT_VAR (14, N_F64 | key, N_S16);
13829 CVT_VAR (15, N_F64 | key, N_U16);
13830 CVT_VAR (16, N_S16, N_F32 | key);
13831 CVT_VAR (17, N_U16, N_F32 | key);
13832 CVT_VAR (18, N_S16, N_F64 | key);
13833 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 13834
5287ad62
JB
13835 return -1;
13836#undef CVT_VAR
13837}
13838
037e8744
JB
13839/* Neon-syntax VFP conversions. */
13840
5287ad62 13841static void
037e8744 13842do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 13843{
037e8744 13844 const char *opname = 0;
5f4273c7 13845
037e8744 13846 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 13847 {
037e8744
JB
13848 /* Conversions with immediate bitshift. */
13849 const char *enc[] =
13850 {
13851 "ftosls",
13852 "ftouls",
13853 "fsltos",
13854 "fultos",
13855 NULL,
13856 NULL,
8e79c3df
CM
13857 NULL,
13858 NULL,
037e8744
JB
13859 "ftosld",
13860 "ftould",
13861 "fsltod",
13862 "fultod",
13863 "fshtos",
13864 "fuhtos",
13865 "fshtod",
13866 "fuhtod",
13867 "ftoshs",
13868 "ftouhs",
13869 "ftoshd",
13870 "ftouhd"
13871 };
13872
13873 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13874 {
13875 opname = enc[flavour];
13876 constraint (inst.operands[0].reg != inst.operands[1].reg,
13877 _("operands 0 and 1 must be the same register"));
13878 inst.operands[1] = inst.operands[2];
13879 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13880 }
5287ad62
JB
13881 }
13882 else
13883 {
037e8744
JB
13884 /* Conversions without bitshift. */
13885 const char *enc[] =
13886 {
13887 "ftosis",
13888 "ftouis",
13889 "fsitos",
13890 "fuitos",
8e79c3df
CM
13891 "NULL",
13892 "NULL",
037e8744
JB
13893 "fcvtsd",
13894 "fcvtds",
13895 "ftosid",
13896 "ftouid",
13897 "fsitod",
13898 "fuitod"
13899 };
13900
13901 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13902 opname = enc[flavour];
13903 }
13904
13905 if (opname)
13906 do_vfp_nsyn_opcode (opname);
13907}
13908
13909static void
13910do_vfp_nsyn_cvtz (void)
13911{
13912 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13913 int flavour = neon_cvt_flavour (rs);
13914 const char *enc[] =
13915 {
13916 "ftosizs",
13917 "ftouizs",
13918 NULL,
13919 NULL,
13920 NULL,
13921 NULL,
8e79c3df
CM
13922 NULL,
13923 NULL,
037e8744
JB
13924 "ftosizd",
13925 "ftouizd"
13926 };
13927
13928 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13929 do_vfp_nsyn_opcode (enc[flavour]);
13930}
f31fef98 13931
037e8744 13932static void
e3e535bc 13933do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
037e8744
JB
13934{
13935 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 13936 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
13937 int flavour = neon_cvt_flavour (rs);
13938
e3e535bc
NC
13939 /* PR11109: Handle round-to-zero for VCVT conversions. */
13940 if (round_to_zero
13941 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
13942 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
13943 && (rs == NS_FD || rs == NS_FF))
13944 {
13945 do_vfp_nsyn_cvtz ();
13946 return;
13947 }
13948
037e8744 13949 /* VFP rather than Neon conversions. */
8e79c3df 13950 if (flavour >= 6)
037e8744
JB
13951 {
13952 do_vfp_nsyn_cvt (rs, flavour);
13953 return;
13954 }
13955
13956 switch (rs)
13957 {
13958 case NS_DDI:
13959 case NS_QQI:
13960 {
35997600
NC
13961 unsigned immbits;
13962 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13963
037e8744
JB
13964 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13965 return;
13966
13967 /* Fixed-point conversion with #0 immediate is encoded as an
13968 integer conversion. */
13969 if (inst.operands[2].present && inst.operands[2].imm == 0)
13970 goto int_encode;
35997600 13971 immbits = 32 - inst.operands[2].imm;
88714cb8 13972 NEON_ENCODE (IMMED, inst);
037e8744
JB
13973 if (flavour != -1)
13974 inst.instruction |= enctab[flavour];
13975 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13976 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13977 inst.instruction |= LOW4 (inst.operands[1].reg);
13978 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13979 inst.instruction |= neon_quad (rs) << 6;
13980 inst.instruction |= 1 << 21;
13981 inst.instruction |= immbits << 16;
13982
88714cb8 13983 neon_dp_fixup (&inst);
037e8744
JB
13984 }
13985 break;
13986
13987 case NS_DD:
13988 case NS_QQ:
13989 int_encode:
13990 {
13991 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13992
88714cb8 13993 NEON_ENCODE (INTEGER, inst);
037e8744
JB
13994
13995 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13996 return;
13997
13998 if (flavour != -1)
13999 inst.instruction |= enctab[flavour];
14000
14001 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14002 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14003 inst.instruction |= LOW4 (inst.operands[1].reg);
14004 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14005 inst.instruction |= neon_quad (rs) << 6;
14006 inst.instruction |= 2 << 18;
14007
88714cb8 14008 neon_dp_fixup (&inst);
037e8744
JB
14009 }
14010 break;
14011
8e79c3df
CM
14012 /* Half-precision conversions for Advanced SIMD -- neon. */
14013 case NS_QD:
14014 case NS_DQ:
14015
14016 if ((rs == NS_DQ)
14017 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14018 {
14019 as_bad (_("operand size must match register width"));
14020 break;
14021 }
14022
14023 if ((rs == NS_QD)
14024 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14025 {
14026 as_bad (_("operand size must match register width"));
14027 break;
14028 }
14029
14030 if (rs == NS_DQ)
14031 inst.instruction = 0x3b60600;
14032 else
14033 inst.instruction = 0x3b60700;
14034
14035 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14036 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14037 inst.instruction |= LOW4 (inst.operands[1].reg);
14038 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 14039 neon_dp_fixup (&inst);
8e79c3df
CM
14040 break;
14041
037e8744
JB
14042 default:
14043 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
14044 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 14045 }
5287ad62
JB
14046}
14047
e3e535bc
NC
14048static void
14049do_neon_cvtr (void)
14050{
14051 do_neon_cvt_1 (FALSE);
14052}
14053
14054static void
14055do_neon_cvt (void)
14056{
14057 do_neon_cvt_1 (TRUE);
14058}
14059
8e79c3df
CM
14060static void
14061do_neon_cvtb (void)
14062{
14063 inst.instruction = 0xeb20a40;
14064
14065 /* The sizes are attached to the mnemonic. */
14066 if (inst.vectype.el[0].type != NT_invtype
14067 && inst.vectype.el[0].size == 16)
14068 inst.instruction |= 0x00010000;
14069
14070 /* Programmer's syntax: the sizes are attached to the operands. */
14071 else if (inst.operands[0].vectype.type != NT_invtype
14072 && inst.operands[0].vectype.size == 16)
14073 inst.instruction |= 0x00010000;
14074
14075 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14076 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
14077 do_vfp_cond_or_thumb ();
14078}
14079
14080
14081static void
14082do_neon_cvtt (void)
14083{
14084 do_neon_cvtb ();
14085 inst.instruction |= 0x80;
14086}
14087
5287ad62
JB
14088static void
14089neon_move_immediate (void)
14090{
037e8744
JB
14091 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14092 struct neon_type_el et = neon_check_type (2, rs,
14093 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 14094 unsigned immlo, immhi = 0, immbits;
c96612cc 14095 int op, cmode, float_p;
5287ad62 14096
037e8744
JB
14097 constraint (et.type == NT_invtype,
14098 _("operand size must be specified for immediate VMOV"));
14099
5287ad62
JB
14100 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14101 op = (inst.instruction & (1 << 5)) != 0;
14102
14103 immlo = inst.operands[1].imm;
14104 if (inst.operands[1].regisimm)
14105 immhi = inst.operands[1].reg;
14106
14107 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14108 _("immediate has bits set outside the operand size"));
14109
c96612cc
JB
14110 float_p = inst.operands[1].immisfloat;
14111
14112 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 14113 et.size, et.type)) == FAIL)
5287ad62
JB
14114 {
14115 /* Invert relevant bits only. */
14116 neon_invert_size (&immlo, &immhi, et.size);
14117 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14118 with one or the other; those cases are caught by
14119 neon_cmode_for_move_imm. */
14120 op = !op;
c96612cc
JB
14121 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
14122 &op, et.size, et.type)) == FAIL)
5287ad62 14123 {
dcbf9037 14124 first_error (_("immediate out of range"));
5287ad62
JB
14125 return;
14126 }
14127 }
14128
14129 inst.instruction &= ~(1 << 5);
14130 inst.instruction |= op << 5;
14131
14132 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14133 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 14134 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14135 inst.instruction |= cmode << 8;
14136
14137 neon_write_immbits (immbits);
14138}
14139
14140static void
14141do_neon_mvn (void)
14142{
14143 if (inst.operands[1].isreg)
14144 {
037e8744 14145 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 14146
88714cb8 14147 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14148 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14149 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14150 inst.instruction |= LOW4 (inst.operands[1].reg);
14151 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14152 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14153 }
14154 else
14155 {
88714cb8 14156 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14157 neon_move_immediate ();
14158 }
14159
88714cb8 14160 neon_dp_fixup (&inst);
5287ad62
JB
14161}
14162
14163/* Encode instructions of form:
14164
14165 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 14166 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
14167
14168static void
14169neon_mixed_length (struct neon_type_el et, unsigned size)
14170{
14171 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14172 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14173 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14174 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14175 inst.instruction |= LOW4 (inst.operands[2].reg);
14176 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14177 inst.instruction |= (et.type == NT_unsigned) << 24;
14178 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14179
88714cb8 14180 neon_dp_fixup (&inst);
5287ad62
JB
14181}
14182
14183static void
14184do_neon_dyadic_long (void)
14185{
14186 /* FIXME: Type checking for lengthening op. */
14187 struct neon_type_el et = neon_check_type (3, NS_QDD,
14188 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14189 neon_mixed_length (et, et.size);
14190}
14191
14192static void
14193do_neon_abal (void)
14194{
14195 struct neon_type_el et = neon_check_type (3, NS_QDD,
14196 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14197 neon_mixed_length (et, et.size);
14198}
14199
14200static void
14201neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14202{
14203 if (inst.operands[2].isscalar)
14204 {
dcbf9037
JB
14205 struct neon_type_el et = neon_check_type (3, NS_QDS,
14206 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 14207 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14208 neon_mul_mac (et, et.type == NT_unsigned);
14209 }
14210 else
14211 {
14212 struct neon_type_el et = neon_check_type (3, NS_QDD,
14213 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 14214 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14215 neon_mixed_length (et, et.size);
14216 }
14217}
14218
14219static void
14220do_neon_mac_maybe_scalar_long (void)
14221{
14222 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14223}
14224
14225static void
14226do_neon_dyadic_wide (void)
14227{
14228 struct neon_type_el et = neon_check_type (3, NS_QQD,
14229 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14230 neon_mixed_length (et, et.size);
14231}
14232
14233static void
14234do_neon_dyadic_narrow (void)
14235{
14236 struct neon_type_el et = neon_check_type (3, NS_QDD,
14237 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
14238 /* Operand sign is unimportant, and the U bit is part of the opcode,
14239 so force the operand type to integer. */
14240 et.type = NT_integer;
5287ad62
JB
14241 neon_mixed_length (et, et.size / 2);
14242}
14243
14244static void
14245do_neon_mul_sat_scalar_long (void)
14246{
14247 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14248}
14249
14250static void
14251do_neon_vmull (void)
14252{
14253 if (inst.operands[2].isscalar)
14254 do_neon_mac_maybe_scalar_long ();
14255 else
14256 {
14257 struct neon_type_el et = neon_check_type (3, NS_QDD,
14258 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14259 if (et.type == NT_poly)
88714cb8 14260 NEON_ENCODE (POLY, inst);
5287ad62 14261 else
88714cb8 14262 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14263 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14264 zero. Should be OK as-is. */
14265 neon_mixed_length (et, et.size);
14266 }
14267}
14268
14269static void
14270do_neon_ext (void)
14271{
037e8744 14272 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
14273 struct neon_type_el et = neon_check_type (3, rs,
14274 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14275 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
14276
14277 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14278 _("shift out of range"));
5287ad62
JB
14279 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14280 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14281 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14282 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14283 inst.instruction |= LOW4 (inst.operands[2].reg);
14284 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 14285 inst.instruction |= neon_quad (rs) << 6;
5287ad62 14286 inst.instruction |= imm << 8;
5f4273c7 14287
88714cb8 14288 neon_dp_fixup (&inst);
5287ad62
JB
14289}
14290
14291static void
14292do_neon_rev (void)
14293{
037e8744 14294 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14295 struct neon_type_el et = neon_check_type (2, rs,
14296 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14297 unsigned op = (inst.instruction >> 7) & 3;
14298 /* N (width of reversed regions) is encoded as part of the bitmask. We
14299 extract it here to check the elements to be reversed are smaller.
14300 Otherwise we'd get a reserved instruction. */
14301 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 14302 gas_assert (elsize != 0);
5287ad62
JB
14303 constraint (et.size >= elsize,
14304 _("elements must be smaller than reversal region"));
037e8744 14305 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14306}
14307
14308static void
14309do_neon_dup (void)
14310{
14311 if (inst.operands[1].isscalar)
14312 {
037e8744 14313 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
14314 struct neon_type_el et = neon_check_type (2, rs,
14315 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 14316 unsigned sizebits = et.size >> 3;
dcbf9037 14317 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 14318 int logsize = neon_logbits (et.size);
dcbf9037 14319 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
14320
14321 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14322 return;
14323
88714cb8 14324 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14325 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14326 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14327 inst.instruction |= LOW4 (dm);
14328 inst.instruction |= HI1 (dm) << 5;
037e8744 14329 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14330 inst.instruction |= x << 17;
14331 inst.instruction |= sizebits << 16;
5f4273c7 14332
88714cb8 14333 neon_dp_fixup (&inst);
5287ad62
JB
14334 }
14335 else
14336 {
037e8744
JB
14337 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14338 struct neon_type_el et = neon_check_type (2, rs,
14339 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 14340 /* Duplicate ARM register to lanes of vector. */
88714cb8 14341 NEON_ENCODE (ARMREG, inst);
5287ad62
JB
14342 switch (et.size)
14343 {
14344 case 8: inst.instruction |= 0x400000; break;
14345 case 16: inst.instruction |= 0x000020; break;
14346 case 32: inst.instruction |= 0x000000; break;
14347 default: break;
14348 }
14349 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14350 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14351 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 14352 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
14353 /* The encoding for this instruction is identical for the ARM and Thumb
14354 variants, except for the condition field. */
037e8744 14355 do_vfp_cond_or_thumb ();
5287ad62
JB
14356 }
14357}
14358
14359/* VMOV has particularly many variations. It can be one of:
14360 0. VMOV<c><q> <Qd>, <Qm>
14361 1. VMOV<c><q> <Dd>, <Dm>
14362 (Register operations, which are VORR with Rm = Rn.)
14363 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14364 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14365 (Immediate loads.)
14366 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14367 (ARM register to scalar.)
14368 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14369 (Two ARM registers to vector.)
14370 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14371 (Scalar to ARM register.)
14372 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14373 (Vector to two ARM registers.)
037e8744
JB
14374 8. VMOV.F32 <Sd>, <Sm>
14375 9. VMOV.F64 <Dd>, <Dm>
14376 (VFP register moves.)
14377 10. VMOV.F32 <Sd>, #imm
14378 11. VMOV.F64 <Dd>, #imm
14379 (VFP float immediate load.)
14380 12. VMOV <Rd>, <Sm>
14381 (VFP single to ARM reg.)
14382 13. VMOV <Sd>, <Rm>
14383 (ARM reg to VFP single.)
14384 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14385 (Two ARM regs to two VFP singles.)
14386 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14387 (Two VFP singles to two ARM regs.)
5f4273c7 14388
037e8744
JB
14389 These cases can be disambiguated using neon_select_shape, except cases 1/9
14390 and 3/11 which depend on the operand type too.
5f4273c7 14391
5287ad62 14392 All the encoded bits are hardcoded by this function.
5f4273c7 14393
b7fc2769
JB
14394 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14395 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 14396
5287ad62 14397 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 14398 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
14399
14400static void
14401do_neon_mov (void)
14402{
037e8744
JB
14403 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14404 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14405 NS_NULL);
14406 struct neon_type_el et;
14407 const char *ldconst = 0;
5287ad62 14408
037e8744 14409 switch (rs)
5287ad62 14410 {
037e8744
JB
14411 case NS_DD: /* case 1/9. */
14412 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14413 /* It is not an error here if no type is given. */
14414 inst.error = NULL;
14415 if (et.type == NT_float && et.size == 64)
5287ad62 14416 {
037e8744
JB
14417 do_vfp_nsyn_opcode ("fcpyd");
14418 break;
5287ad62 14419 }
037e8744 14420 /* fall through. */
5287ad62 14421
037e8744
JB
14422 case NS_QQ: /* case 0/1. */
14423 {
14424 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14425 return;
14426 /* The architecture manual I have doesn't explicitly state which
14427 value the U bit should have for register->register moves, but
14428 the equivalent VORR instruction has U = 0, so do that. */
14429 inst.instruction = 0x0200110;
14430 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14431 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14432 inst.instruction |= LOW4 (inst.operands[1].reg);
14433 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14434 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14435 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14436 inst.instruction |= neon_quad (rs) << 6;
14437
88714cb8 14438 neon_dp_fixup (&inst);
037e8744
JB
14439 }
14440 break;
5f4273c7 14441
037e8744
JB
14442 case NS_DI: /* case 3/11. */
14443 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14444 inst.error = NULL;
14445 if (et.type == NT_float && et.size == 64)
5287ad62 14446 {
037e8744
JB
14447 /* case 11 (fconstd). */
14448 ldconst = "fconstd";
14449 goto encode_fconstd;
5287ad62 14450 }
037e8744
JB
14451 /* fall through. */
14452
14453 case NS_QI: /* case 2/3. */
14454 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14455 return;
14456 inst.instruction = 0x0800010;
14457 neon_move_immediate ();
88714cb8 14458 neon_dp_fixup (&inst);
5287ad62 14459 break;
5f4273c7 14460
037e8744
JB
14461 case NS_SR: /* case 4. */
14462 {
14463 unsigned bcdebits = 0;
91d6fa6a 14464 int logsize;
037e8744
JB
14465 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14466 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14467
91d6fa6a
NC
14468 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14469 logsize = neon_logbits (et.size);
14470
037e8744
JB
14471 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14472 _(BAD_FPU));
14473 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14474 && et.size != 32, _(BAD_FPU));
14475 constraint (et.type == NT_invtype, _("bad type for scalar"));
14476 constraint (x >= 64 / et.size, _("scalar index out of range"));
14477
14478 switch (et.size)
14479 {
14480 case 8: bcdebits = 0x8; break;
14481 case 16: bcdebits = 0x1; break;
14482 case 32: bcdebits = 0x0; break;
14483 default: ;
14484 }
14485
14486 bcdebits |= x << logsize;
14487
14488 inst.instruction = 0xe000b10;
14489 do_vfp_cond_or_thumb ();
14490 inst.instruction |= LOW4 (dn) << 16;
14491 inst.instruction |= HI1 (dn) << 7;
14492 inst.instruction |= inst.operands[1].reg << 12;
14493 inst.instruction |= (bcdebits & 3) << 5;
14494 inst.instruction |= (bcdebits >> 2) << 21;
14495 }
14496 break;
5f4273c7 14497
037e8744 14498 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 14499 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 14500 _(BAD_FPU));
b7fc2769 14501
037e8744
JB
14502 inst.instruction = 0xc400b10;
14503 do_vfp_cond_or_thumb ();
14504 inst.instruction |= LOW4 (inst.operands[0].reg);
14505 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14506 inst.instruction |= inst.operands[1].reg << 12;
14507 inst.instruction |= inst.operands[2].reg << 16;
14508 break;
5f4273c7 14509
037e8744
JB
14510 case NS_RS: /* case 6. */
14511 {
91d6fa6a 14512 unsigned logsize;
037e8744
JB
14513 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14514 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14515 unsigned abcdebits = 0;
14516
91d6fa6a
NC
14517 et = neon_check_type (2, NS_NULL,
14518 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14519 logsize = neon_logbits (et.size);
14520
037e8744
JB
14521 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14522 _(BAD_FPU));
14523 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14524 && et.size != 32, _(BAD_FPU));
14525 constraint (et.type == NT_invtype, _("bad type for scalar"));
14526 constraint (x >= 64 / et.size, _("scalar index out of range"));
14527
14528 switch (et.size)
14529 {
14530 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14531 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14532 case 32: abcdebits = 0x00; break;
14533 default: ;
14534 }
14535
14536 abcdebits |= x << logsize;
14537 inst.instruction = 0xe100b10;
14538 do_vfp_cond_or_thumb ();
14539 inst.instruction |= LOW4 (dn) << 16;
14540 inst.instruction |= HI1 (dn) << 7;
14541 inst.instruction |= inst.operands[0].reg << 12;
14542 inst.instruction |= (abcdebits & 3) << 5;
14543 inst.instruction |= (abcdebits >> 2) << 21;
14544 }
14545 break;
5f4273c7 14546
037e8744
JB
14547 case NS_RRD: /* case 7 (fmrrd). */
14548 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14549 _(BAD_FPU));
14550
14551 inst.instruction = 0xc500b10;
14552 do_vfp_cond_or_thumb ();
14553 inst.instruction |= inst.operands[0].reg << 12;
14554 inst.instruction |= inst.operands[1].reg << 16;
14555 inst.instruction |= LOW4 (inst.operands[2].reg);
14556 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14557 break;
5f4273c7 14558
037e8744
JB
14559 case NS_FF: /* case 8 (fcpys). */
14560 do_vfp_nsyn_opcode ("fcpys");
14561 break;
5f4273c7 14562
037e8744
JB
14563 case NS_FI: /* case 10 (fconsts). */
14564 ldconst = "fconsts";
14565 encode_fconstd:
14566 if (is_quarter_float (inst.operands[1].imm))
5287ad62 14567 {
037e8744
JB
14568 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14569 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
14570 }
14571 else
037e8744
JB
14572 first_error (_("immediate out of range"));
14573 break;
5f4273c7 14574
037e8744
JB
14575 case NS_RF: /* case 12 (fmrs). */
14576 do_vfp_nsyn_opcode ("fmrs");
14577 break;
5f4273c7 14578
037e8744
JB
14579 case NS_FR: /* case 13 (fmsr). */
14580 do_vfp_nsyn_opcode ("fmsr");
14581 break;
5f4273c7 14582
037e8744
JB
14583 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14584 (one of which is a list), but we have parsed four. Do some fiddling to
14585 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14586 expect. */
14587 case NS_RRFF: /* case 14 (fmrrs). */
14588 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14589 _("VFP registers must be adjacent"));
14590 inst.operands[2].imm = 2;
14591 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14592 do_vfp_nsyn_opcode ("fmrrs");
14593 break;
5f4273c7 14594
037e8744
JB
14595 case NS_FFRR: /* case 15 (fmsrr). */
14596 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14597 _("VFP registers must be adjacent"));
14598 inst.operands[1] = inst.operands[2];
14599 inst.operands[2] = inst.operands[3];
14600 inst.operands[0].imm = 2;
14601 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14602 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 14603 break;
5f4273c7 14604
5287ad62
JB
14605 default:
14606 abort ();
14607 }
14608}
14609
14610static void
14611do_neon_rshift_round_imm (void)
14612{
037e8744 14613 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14614 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14615 int imm = inst.operands[2].imm;
14616
14617 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14618 if (imm == 0)
14619 {
14620 inst.operands[2].present = 0;
14621 do_neon_mov ();
14622 return;
14623 }
14624
14625 constraint (imm < 1 || (unsigned)imm > et.size,
14626 _("immediate out of range for shift"));
037e8744 14627 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
14628 et.size - imm);
14629}
14630
14631static void
14632do_neon_movl (void)
14633{
14634 struct neon_type_el et = neon_check_type (2, NS_QD,
14635 N_EQK | N_DBL, N_SU_32 | N_KEY);
14636 unsigned sizebits = et.size >> 3;
14637 inst.instruction |= sizebits << 19;
14638 neon_two_same (0, et.type == NT_unsigned, -1);
14639}
14640
14641static void
14642do_neon_trn (void)
14643{
037e8744 14644 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14645 struct neon_type_el et = neon_check_type (2, rs,
14646 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 14647 NEON_ENCODE (INTEGER, inst);
037e8744 14648 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14649}
14650
14651static void
14652do_neon_zip_uzp (void)
14653{
037e8744 14654 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14655 struct neon_type_el et = neon_check_type (2, rs,
14656 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14657 if (rs == NS_DD && et.size == 32)
14658 {
14659 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14660 inst.instruction = N_MNEM_vtrn;
14661 do_neon_trn ();
14662 return;
14663 }
037e8744 14664 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14665}
14666
14667static void
14668do_neon_sat_abs_neg (void)
14669{
037e8744 14670 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14671 struct neon_type_el et = neon_check_type (2, rs,
14672 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14673 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14674}
14675
14676static void
14677do_neon_pair_long (void)
14678{
037e8744 14679 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14680 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14681 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14682 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 14683 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14684}
14685
14686static void
14687do_neon_recip_est (void)
14688{
037e8744 14689 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14690 struct neon_type_el et = neon_check_type (2, rs,
14691 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
14692 inst.instruction |= (et.type == NT_float) << 8;
037e8744 14693 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14694}
14695
14696static void
14697do_neon_cls (void)
14698{
037e8744 14699 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14700 struct neon_type_el et = neon_check_type (2, rs,
14701 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14702 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14703}
14704
14705static void
14706do_neon_clz (void)
14707{
037e8744 14708 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14709 struct neon_type_el et = neon_check_type (2, rs,
14710 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 14711 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14712}
14713
14714static void
14715do_neon_cnt (void)
14716{
037e8744 14717 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14718 struct neon_type_el et = neon_check_type (2, rs,
14719 N_EQK | N_INT, N_8 | N_KEY);
037e8744 14720 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14721}
14722
14723static void
14724do_neon_swp (void)
14725{
037e8744
JB
14726 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14727 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
14728}
14729
14730static void
14731do_neon_tbl_tbx (void)
14732{
14733 unsigned listlenbits;
dcbf9037 14734 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 14735
5287ad62
JB
14736 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14737 {
dcbf9037 14738 first_error (_("bad list length for table lookup"));
5287ad62
JB
14739 return;
14740 }
5f4273c7 14741
5287ad62
JB
14742 listlenbits = inst.operands[1].imm - 1;
14743 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14744 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14745 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14746 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14747 inst.instruction |= LOW4 (inst.operands[2].reg);
14748 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14749 inst.instruction |= listlenbits << 8;
5f4273c7 14750
88714cb8 14751 neon_dp_fixup (&inst);
5287ad62
JB
14752}
14753
14754static void
14755do_neon_ldm_stm (void)
14756{
14757 /* P, U and L bits are part of bitmask. */
14758 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14759 unsigned offsetbits = inst.operands[1].imm * 2;
14760
037e8744
JB
14761 if (inst.operands[1].issingle)
14762 {
14763 do_vfp_nsyn_ldm_stm (is_dbmode);
14764 return;
14765 }
14766
5287ad62
JB
14767 constraint (is_dbmode && !inst.operands[0].writeback,
14768 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14769
14770 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14771 _("register list must contain at least 1 and at most 16 "
14772 "registers"));
14773
14774 inst.instruction |= inst.operands[0].reg << 16;
14775 inst.instruction |= inst.operands[0].writeback << 21;
14776 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14777 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14778
14779 inst.instruction |= offsetbits;
5f4273c7 14780
037e8744 14781 do_vfp_cond_or_thumb ();
5287ad62
JB
14782}
14783
14784static void
14785do_neon_ldr_str (void)
14786{
5287ad62 14787 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 14788
037e8744
JB
14789 if (inst.operands[0].issingle)
14790 {
cd2f129f
JB
14791 if (is_ldr)
14792 do_vfp_nsyn_opcode ("flds");
14793 else
14794 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
14795 }
14796 else
5287ad62 14797 {
cd2f129f
JB
14798 if (is_ldr)
14799 do_vfp_nsyn_opcode ("fldd");
5287ad62 14800 else
cd2f129f 14801 do_vfp_nsyn_opcode ("fstd");
5287ad62 14802 }
5287ad62
JB
14803}
14804
14805/* "interleave" version also handles non-interleaving register VLD1/VST1
14806 instructions. */
14807
14808static void
14809do_neon_ld_st_interleave (void)
14810{
037e8744 14811 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
14812 N_8 | N_16 | N_32 | N_64);
14813 unsigned alignbits = 0;
14814 unsigned idx;
14815 /* The bits in this table go:
14816 0: register stride of one (0) or two (1)
14817 1,2: register list length, minus one (1, 2, 3, 4).
14818 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14819 We use -1 for invalid entries. */
14820 const int typetable[] =
14821 {
14822 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14823 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14824 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14825 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14826 };
14827 int typebits;
14828
dcbf9037
JB
14829 if (et.type == NT_invtype)
14830 return;
14831
5287ad62
JB
14832 if (inst.operands[1].immisalign)
14833 switch (inst.operands[1].imm >> 8)
14834 {
14835 case 64: alignbits = 1; break;
14836 case 128:
e23c0ad8
JZ
14837 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
14838 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
14839 goto bad_alignment;
14840 alignbits = 2;
14841 break;
14842 case 256:
e23c0ad8 14843 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
14844 goto bad_alignment;
14845 alignbits = 3;
14846 break;
14847 default:
14848 bad_alignment:
dcbf9037 14849 first_error (_("bad alignment"));
5287ad62
JB
14850 return;
14851 }
14852
14853 inst.instruction |= alignbits << 4;
14854 inst.instruction |= neon_logbits (et.size) << 6;
14855
14856 /* Bits [4:6] of the immediate in a list specifier encode register stride
14857 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14858 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14859 up the right value for "type" in a table based on this value and the given
14860 list style, then stick it back. */
14861 idx = ((inst.operands[0].imm >> 4) & 7)
14862 | (((inst.instruction >> 8) & 3) << 3);
14863
14864 typebits = typetable[idx];
5f4273c7 14865
5287ad62
JB
14866 constraint (typebits == -1, _("bad list type for instruction"));
14867
14868 inst.instruction &= ~0xf00;
14869 inst.instruction |= typebits << 8;
14870}
14871
14872/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14873 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14874 otherwise. The variable arguments are a list of pairs of legal (size, align)
14875 values, terminated with -1. */
14876
14877static int
14878neon_alignment_bit (int size, int align, int *do_align, ...)
14879{
14880 va_list ap;
14881 int result = FAIL, thissize, thisalign;
5f4273c7 14882
5287ad62
JB
14883 if (!inst.operands[1].immisalign)
14884 {
14885 *do_align = 0;
14886 return SUCCESS;
14887 }
5f4273c7 14888
5287ad62
JB
14889 va_start (ap, do_align);
14890
14891 do
14892 {
14893 thissize = va_arg (ap, int);
14894 if (thissize == -1)
14895 break;
14896 thisalign = va_arg (ap, int);
14897
14898 if (size == thissize && align == thisalign)
14899 result = SUCCESS;
14900 }
14901 while (result != SUCCESS);
14902
14903 va_end (ap);
14904
14905 if (result == SUCCESS)
14906 *do_align = 1;
14907 else
dcbf9037 14908 first_error (_("unsupported alignment for instruction"));
5f4273c7 14909
5287ad62
JB
14910 return result;
14911}
14912
14913static void
14914do_neon_ld_st_lane (void)
14915{
037e8744 14916 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14917 int align_good, do_align = 0;
14918 int logsize = neon_logbits (et.size);
14919 int align = inst.operands[1].imm >> 8;
14920 int n = (inst.instruction >> 8) & 3;
14921 int max_el = 64 / et.size;
5f4273c7 14922
dcbf9037
JB
14923 if (et.type == NT_invtype)
14924 return;
5f4273c7 14925
5287ad62
JB
14926 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14927 _("bad list length"));
14928 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14929 _("scalar index out of range"));
14930 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14931 && et.size == 8,
14932 _("stride of 2 unavailable when element size is 8"));
5f4273c7 14933
5287ad62
JB
14934 switch (n)
14935 {
14936 case 0: /* VLD1 / VST1. */
14937 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14938 32, 32, -1);
14939 if (align_good == FAIL)
14940 return;
14941 if (do_align)
14942 {
14943 unsigned alignbits = 0;
14944 switch (et.size)
14945 {
14946 case 16: alignbits = 0x1; break;
14947 case 32: alignbits = 0x3; break;
14948 default: ;
14949 }
14950 inst.instruction |= alignbits << 4;
14951 }
14952 break;
14953
14954 case 1: /* VLD2 / VST2. */
14955 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14956 32, 64, -1);
14957 if (align_good == FAIL)
14958 return;
14959 if (do_align)
14960 inst.instruction |= 1 << 4;
14961 break;
14962
14963 case 2: /* VLD3 / VST3. */
14964 constraint (inst.operands[1].immisalign,
14965 _("can't use alignment with this instruction"));
14966 break;
14967
14968 case 3: /* VLD4 / VST4. */
14969 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14970 16, 64, 32, 64, 32, 128, -1);
14971 if (align_good == FAIL)
14972 return;
14973 if (do_align)
14974 {
14975 unsigned alignbits = 0;
14976 switch (et.size)
14977 {
14978 case 8: alignbits = 0x1; break;
14979 case 16: alignbits = 0x1; break;
14980 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14981 default: ;
14982 }
14983 inst.instruction |= alignbits << 4;
14984 }
14985 break;
14986
14987 default: ;
14988 }
14989
14990 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14991 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14992 inst.instruction |= 1 << (4 + logsize);
5f4273c7 14993
5287ad62
JB
14994 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14995 inst.instruction |= logsize << 10;
14996}
14997
14998/* Encode single n-element structure to all lanes VLD<n> instructions. */
14999
15000static void
15001do_neon_ld_dup (void)
15002{
037e8744 15003 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15004 int align_good, do_align = 0;
15005
dcbf9037
JB
15006 if (et.type == NT_invtype)
15007 return;
15008
5287ad62
JB
15009 switch ((inst.instruction >> 8) & 3)
15010 {
15011 case 0: /* VLD1. */
9c2799c2 15012 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
15013 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15014 &do_align, 16, 16, 32, 32, -1);
15015 if (align_good == FAIL)
15016 return;
15017 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15018 {
15019 case 1: break;
15020 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 15021 default: first_error (_("bad list length")); return;
5287ad62
JB
15022 }
15023 inst.instruction |= neon_logbits (et.size) << 6;
15024 break;
15025
15026 case 1: /* VLD2. */
15027 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15028 &do_align, 8, 16, 16, 32, 32, 64, -1);
15029 if (align_good == FAIL)
15030 return;
15031 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15032 _("bad list length"));
15033 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15034 inst.instruction |= 1 << 5;
15035 inst.instruction |= neon_logbits (et.size) << 6;
15036 break;
15037
15038 case 2: /* VLD3. */
15039 constraint (inst.operands[1].immisalign,
15040 _("can't use alignment with this instruction"));
15041 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15042 _("bad list length"));
15043 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15044 inst.instruction |= 1 << 5;
15045 inst.instruction |= neon_logbits (et.size) << 6;
15046 break;
15047
15048 case 3: /* VLD4. */
15049 {
15050 int align = inst.operands[1].imm >> 8;
15051 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15052 16, 64, 32, 64, 32, 128, -1);
15053 if (align_good == FAIL)
15054 return;
15055 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15056 _("bad list length"));
15057 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15058 inst.instruction |= 1 << 5;
15059 if (et.size == 32 && align == 128)
15060 inst.instruction |= 0x3 << 6;
15061 else
15062 inst.instruction |= neon_logbits (et.size) << 6;
15063 }
15064 break;
15065
15066 default: ;
15067 }
15068
15069 inst.instruction |= do_align << 4;
15070}
15071
15072/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15073 apart from bits [11:4]. */
15074
15075static void
15076do_neon_ldx_stx (void)
15077{
b1a769ed
DG
15078 if (inst.operands[1].isreg)
15079 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15080
5287ad62
JB
15081 switch (NEON_LANE (inst.operands[0].imm))
15082 {
15083 case NEON_INTERLEAVE_LANES:
88714cb8 15084 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
15085 do_neon_ld_st_interleave ();
15086 break;
5f4273c7 15087
5287ad62 15088 case NEON_ALL_LANES:
88714cb8 15089 NEON_ENCODE (DUP, inst);
5287ad62
JB
15090 do_neon_ld_dup ();
15091 break;
5f4273c7 15092
5287ad62 15093 default:
88714cb8 15094 NEON_ENCODE (LANE, inst);
5287ad62
JB
15095 do_neon_ld_st_lane ();
15096 }
15097
15098 /* L bit comes from bit mask. */
15099 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15100 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15101 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 15102
5287ad62
JB
15103 if (inst.operands[1].postind)
15104 {
15105 int postreg = inst.operands[1].imm & 0xf;
15106 constraint (!inst.operands[1].immisreg,
15107 _("post-index must be a register"));
15108 constraint (postreg == 0xd || postreg == 0xf,
15109 _("bad register for post-index"));
15110 inst.instruction |= postreg;
15111 }
15112 else if (inst.operands[1].writeback)
15113 {
15114 inst.instruction |= 0xd;
15115 }
15116 else
5f4273c7
NC
15117 inst.instruction |= 0xf;
15118
5287ad62
JB
15119 if (thumb_mode)
15120 inst.instruction |= 0xf9000000;
15121 else
15122 inst.instruction |= 0xf4000000;
15123}
5287ad62
JB
15124\f
15125/* Overall per-instruction processing. */
15126
15127/* We need to be able to fix up arbitrary expressions in some statements.
15128 This is so that we can handle symbols that are an arbitrary distance from
15129 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
15130 which returns part of an address in a form which will be valid for
15131 a data instruction. We do this by pushing the expression into a symbol
15132 in the expr_section, and creating a fix for that. */
15133
15134static void
15135fix_new_arm (fragS * frag,
15136 int where,
15137 short int size,
15138 expressionS * exp,
15139 int pc_rel,
15140 int reloc)
15141{
15142 fixS * new_fix;
15143
15144 switch (exp->X_op)
15145 {
15146 case O_constant:
15147 case O_symbol:
15148 case O_add:
15149 case O_subtract:
21d799b5
NC
15150 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
15151 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15152 break;
15153
15154 default:
21d799b5
NC
15155 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
15156 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15157 break;
15158 }
15159
15160 /* Mark whether the fix is to a THUMB instruction, or an ARM
15161 instruction. */
15162 new_fix->tc_fix_data = thumb_mode;
15163}
15164
15165/* Create a frg for an instruction requiring relaxation. */
15166static void
15167output_relax_insn (void)
15168{
15169 char * to;
15170 symbolS *sym;
0110f2b8
PB
15171 int offset;
15172
6e1cb1a6
PB
15173 /* The size of the instruction is unknown, so tie the debug info to the
15174 start of the instruction. */
15175 dwarf2_emit_insn (0);
6e1cb1a6 15176
0110f2b8
PB
15177 switch (inst.reloc.exp.X_op)
15178 {
15179 case O_symbol:
15180 sym = inst.reloc.exp.X_add_symbol;
15181 offset = inst.reloc.exp.X_add_number;
15182 break;
15183 case O_constant:
15184 sym = NULL;
15185 offset = inst.reloc.exp.X_add_number;
15186 break;
15187 default:
15188 sym = make_expr_symbol (&inst.reloc.exp);
15189 offset = 0;
15190 break;
15191 }
15192 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15193 inst.relax, sym, offset, NULL/*offset, opcode*/);
15194 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
15195}
15196
15197/* Write a 32-bit thumb instruction to buf. */
15198static void
15199put_thumb32_insn (char * buf, unsigned long insn)
15200{
15201 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15202 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15203}
15204
b99bd4ef 15205static void
c19d1205 15206output_inst (const char * str)
b99bd4ef 15207{
c19d1205 15208 char * to = NULL;
b99bd4ef 15209
c19d1205 15210 if (inst.error)
b99bd4ef 15211 {
c19d1205 15212 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
15213 return;
15214 }
5f4273c7
NC
15215 if (inst.relax)
15216 {
15217 output_relax_insn ();
0110f2b8 15218 return;
5f4273c7 15219 }
c19d1205
ZW
15220 if (inst.size == 0)
15221 return;
b99bd4ef 15222
c19d1205 15223 to = frag_more (inst.size);
8dc2430f
NC
15224 /* PR 9814: Record the thumb mode into the current frag so that we know
15225 what type of NOP padding to use, if necessary. We override any previous
15226 setting so that if the mode has changed then the NOPS that we use will
15227 match the encoding of the last instruction in the frag. */
cd000bff 15228 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
15229
15230 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 15231 {
9c2799c2 15232 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 15233 put_thumb32_insn (to, inst.instruction);
b99bd4ef 15234 }
c19d1205 15235 else if (inst.size > INSN_SIZE)
b99bd4ef 15236 {
9c2799c2 15237 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
15238 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15239 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 15240 }
c19d1205
ZW
15241 else
15242 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 15243
c19d1205
ZW
15244 if (inst.reloc.type != BFD_RELOC_UNUSED)
15245 fix_new_arm (frag_now, to - frag_now->fr_literal,
15246 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15247 inst.reloc.type);
b99bd4ef 15248
c19d1205 15249 dwarf2_emit_insn (inst.size);
c19d1205 15250}
b99bd4ef 15251
e07e6e58
NC
15252static char *
15253output_it_inst (int cond, int mask, char * to)
15254{
15255 unsigned long instruction = 0xbf00;
15256
15257 mask &= 0xf;
15258 instruction |= mask;
15259 instruction |= cond << 4;
15260
15261 if (to == NULL)
15262 {
15263 to = frag_more (2);
15264#ifdef OBJ_ELF
15265 dwarf2_emit_insn (2);
15266#endif
15267 }
15268
15269 md_number_to_chars (to, instruction, 2);
15270
15271 return to;
15272}
15273
c19d1205
ZW
15274/* Tag values used in struct asm_opcode's tag field. */
15275enum opcode_tag
15276{
15277 OT_unconditional, /* Instruction cannot be conditionalized.
15278 The ARM condition field is still 0xE. */
15279 OT_unconditionalF, /* Instruction cannot be conditionalized
15280 and carries 0xF in its ARM condition field. */
15281 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
15282 OT_csuffixF, /* Some forms of the instruction take a conditional
15283 suffix, others place 0xF where the condition field
15284 would be. */
c19d1205
ZW
15285 OT_cinfix3, /* Instruction takes a conditional infix,
15286 beginning at character index 3. (In
15287 unified mode, it becomes a suffix.) */
088fa78e
KH
15288 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15289 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
15290 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15291 character index 3, even in unified mode. Used for
15292 legacy instructions where suffix and infix forms
15293 may be ambiguous. */
c19d1205 15294 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 15295 suffix or an infix at character index 3. */
c19d1205
ZW
15296 OT_odd_infix_unc, /* This is the unconditional variant of an
15297 instruction that takes a conditional infix
15298 at an unusual position. In unified mode,
15299 this variant will accept a suffix. */
15300 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15301 are the conditional variants of instructions that
15302 take conditional infixes in unusual positions.
15303 The infix appears at character index
15304 (tag - OT_odd_infix_0). These are not accepted
15305 in unified mode. */
15306};
b99bd4ef 15307
c19d1205
ZW
15308/* Subroutine of md_assemble, responsible for looking up the primary
15309 opcode from the mnemonic the user wrote. STR points to the
15310 beginning of the mnemonic.
15311
15312 This is not simply a hash table lookup, because of conditional
15313 variants. Most instructions have conditional variants, which are
15314 expressed with a _conditional affix_ to the mnemonic. If we were
15315 to encode each conditional variant as a literal string in the opcode
15316 table, it would have approximately 20,000 entries.
15317
15318 Most mnemonics take this affix as a suffix, and in unified syntax,
15319 'most' is upgraded to 'all'. However, in the divided syntax, some
15320 instructions take the affix as an infix, notably the s-variants of
15321 the arithmetic instructions. Of those instructions, all but six
15322 have the infix appear after the third character of the mnemonic.
15323
15324 Accordingly, the algorithm for looking up primary opcodes given
15325 an identifier is:
15326
15327 1. Look up the identifier in the opcode table.
15328 If we find a match, go to step U.
15329
15330 2. Look up the last two characters of the identifier in the
15331 conditions table. If we find a match, look up the first N-2
15332 characters of the identifier in the opcode table. If we
15333 find a match, go to step CE.
15334
15335 3. Look up the fourth and fifth characters of the identifier in
15336 the conditions table. If we find a match, extract those
15337 characters from the identifier, and look up the remaining
15338 characters in the opcode table. If we find a match, go
15339 to step CM.
15340
15341 4. Fail.
15342
15343 U. Examine the tag field of the opcode structure, in case this is
15344 one of the six instructions with its conditional infix in an
15345 unusual place. If it is, the tag tells us where to find the
15346 infix; look it up in the conditions table and set inst.cond
15347 accordingly. Otherwise, this is an unconditional instruction.
15348 Again set inst.cond accordingly. Return the opcode structure.
15349
15350 CE. Examine the tag field to make sure this is an instruction that
15351 should receive a conditional suffix. If it is not, fail.
15352 Otherwise, set inst.cond from the suffix we already looked up,
15353 and return the opcode structure.
15354
15355 CM. Examine the tag field to make sure this is an instruction that
15356 should receive a conditional infix after the third character.
15357 If it is not, fail. Otherwise, undo the edits to the current
15358 line of input and proceed as for case CE. */
15359
15360static const struct asm_opcode *
15361opcode_lookup (char **str)
15362{
15363 char *end, *base;
15364 char *affix;
15365 const struct asm_opcode *opcode;
15366 const struct asm_cond *cond;
e3cb604e 15367 char save[2];
c19d1205
ZW
15368
15369 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 15370 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 15371 for (base = end = *str; *end != '\0'; end++)
721a8186 15372 if (*end == ' ' || *end == '.')
c19d1205 15373 break;
b99bd4ef 15374
c19d1205 15375 if (end == base)
c921be7d 15376 return NULL;
b99bd4ef 15377
5287ad62 15378 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 15379 if (end[0] == '.')
b99bd4ef 15380 {
5287ad62 15381 int offset = 2;
5f4273c7 15382
267d2029
JB
15383 /* The .w and .n suffixes are only valid if the unified syntax is in
15384 use. */
15385 if (unified_syntax && end[1] == 'w')
c19d1205 15386 inst.size_req = 4;
267d2029 15387 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
15388 inst.size_req = 2;
15389 else
5287ad62
JB
15390 offset = 0;
15391
15392 inst.vectype.elems = 0;
15393
15394 *str = end + offset;
b99bd4ef 15395
5f4273c7 15396 if (end[offset] == '.')
5287ad62 15397 {
267d2029
JB
15398 /* See if we have a Neon type suffix (possible in either unified or
15399 non-unified ARM syntax mode). */
dcbf9037 15400 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 15401 return NULL;
5287ad62
JB
15402 }
15403 else if (end[offset] != '\0' && end[offset] != ' ')
c921be7d 15404 return NULL;
b99bd4ef 15405 }
c19d1205
ZW
15406 else
15407 *str = end;
b99bd4ef 15408
c19d1205 15409 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5
NC
15410 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15411 end - base);
c19d1205 15412 if (opcode)
b99bd4ef 15413 {
c19d1205
ZW
15414 /* step U */
15415 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 15416 {
c19d1205
ZW
15417 inst.cond = COND_ALWAYS;
15418 return opcode;
b99bd4ef 15419 }
b99bd4ef 15420
278df34e 15421 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
15422 as_warn (_("conditional infixes are deprecated in unified syntax"));
15423 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 15424 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 15425 gas_assert (cond);
b99bd4ef 15426
c19d1205
ZW
15427 inst.cond = cond->value;
15428 return opcode;
15429 }
b99bd4ef 15430
c19d1205
ZW
15431 /* Cannot have a conditional suffix on a mnemonic of less than two
15432 characters. */
15433 if (end - base < 3)
c921be7d 15434 return NULL;
b99bd4ef 15435
c19d1205
ZW
15436 /* Look for suffixed mnemonic. */
15437 affix = end - 2;
21d799b5
NC
15438 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15439 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15440 affix - base);
c19d1205
ZW
15441 if (opcode && cond)
15442 {
15443 /* step CE */
15444 switch (opcode->tag)
15445 {
e3cb604e
PB
15446 case OT_cinfix3_legacy:
15447 /* Ignore conditional suffixes matched on infix only mnemonics. */
15448 break;
15449
c19d1205 15450 case OT_cinfix3:
088fa78e 15451 case OT_cinfix3_deprecated:
c19d1205
ZW
15452 case OT_odd_infix_unc:
15453 if (!unified_syntax)
e3cb604e 15454 return 0;
c19d1205
ZW
15455 /* else fall through */
15456
15457 case OT_csuffix:
037e8744 15458 case OT_csuffixF:
c19d1205
ZW
15459 case OT_csuf_or_in3:
15460 inst.cond = cond->value;
15461 return opcode;
15462
15463 case OT_unconditional:
15464 case OT_unconditionalF:
dfa9f0d5 15465 if (thumb_mode)
c921be7d 15466 inst.cond = cond->value;
dfa9f0d5
PB
15467 else
15468 {
c921be7d 15469 /* Delayed diagnostic. */
dfa9f0d5
PB
15470 inst.error = BAD_COND;
15471 inst.cond = COND_ALWAYS;
15472 }
c19d1205 15473 return opcode;
b99bd4ef 15474
c19d1205 15475 default:
c921be7d 15476 return NULL;
c19d1205
ZW
15477 }
15478 }
b99bd4ef 15479
c19d1205
ZW
15480 /* Cannot have a usual-position infix on a mnemonic of less than
15481 six characters (five would be a suffix). */
15482 if (end - base < 6)
c921be7d 15483 return NULL;
b99bd4ef 15484
c19d1205
ZW
15485 /* Look for infixed mnemonic in the usual position. */
15486 affix = base + 3;
21d799b5 15487 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 15488 if (!cond)
c921be7d 15489 return NULL;
e3cb604e
PB
15490
15491 memcpy (save, affix, 2);
15492 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5
NC
15493 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15494 (end - base) - 2);
e3cb604e
PB
15495 memmove (affix + 2, affix, (end - affix) - 2);
15496 memcpy (affix, save, 2);
15497
088fa78e
KH
15498 if (opcode
15499 && (opcode->tag == OT_cinfix3
15500 || opcode->tag == OT_cinfix3_deprecated
15501 || opcode->tag == OT_csuf_or_in3
15502 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 15503 {
c921be7d 15504 /* Step CM. */
278df34e 15505 if (warn_on_deprecated && unified_syntax
088fa78e
KH
15506 && (opcode->tag == OT_cinfix3
15507 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
15508 as_warn (_("conditional infixes are deprecated in unified syntax"));
15509
15510 inst.cond = cond->value;
15511 return opcode;
b99bd4ef
NC
15512 }
15513
c921be7d 15514 return NULL;
b99bd4ef
NC
15515}
15516
e07e6e58
NC
15517/* This function generates an initial IT instruction, leaving its block
15518 virtually open for the new instructions. Eventually,
15519 the mask will be updated by now_it_add_mask () each time
15520 a new instruction needs to be included in the IT block.
15521 Finally, the block is closed with close_automatic_it_block ().
15522 The block closure can be requested either from md_assemble (),
15523 a tencode (), or due to a label hook. */
15524
15525static void
15526new_automatic_it_block (int cond)
15527{
15528 now_it.state = AUTOMATIC_IT_BLOCK;
15529 now_it.mask = 0x18;
15530 now_it.cc = cond;
15531 now_it.block_length = 1;
cd000bff 15532 mapping_state (MAP_THUMB);
e07e6e58
NC
15533 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15534}
15535
15536/* Close an automatic IT block.
15537 See comments in new_automatic_it_block (). */
15538
15539static void
15540close_automatic_it_block (void)
15541{
15542 now_it.mask = 0x10;
15543 now_it.block_length = 0;
15544}
15545
15546/* Update the mask of the current automatically-generated IT
15547 instruction. See comments in new_automatic_it_block (). */
15548
15549static void
15550now_it_add_mask (int cond)
15551{
15552#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15553#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15554 | ((bitvalue) << (nbit)))
e07e6e58 15555 const int resulting_bit = (cond & 1);
c921be7d 15556
e07e6e58
NC
15557 now_it.mask &= 0xf;
15558 now_it.mask = SET_BIT_VALUE (now_it.mask,
15559 resulting_bit,
15560 (5 - now_it.block_length));
15561 now_it.mask = SET_BIT_VALUE (now_it.mask,
15562 1,
15563 ((5 - now_it.block_length) - 1) );
15564 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15565
15566#undef CLEAR_BIT
15567#undef SET_BIT_VALUE
e07e6e58
NC
15568}
15569
15570/* The IT blocks handling machinery is accessed through the these functions:
15571 it_fsm_pre_encode () from md_assemble ()
15572 set_it_insn_type () optional, from the tencode functions
15573 set_it_insn_type_last () ditto
15574 in_it_block () ditto
15575 it_fsm_post_encode () from md_assemble ()
15576 force_automatic_it_block_close () from label habdling functions
15577
15578 Rationale:
15579 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15580 initializing the IT insn type with a generic initial value depending
15581 on the inst.condition.
15582 2) During the tencode function, two things may happen:
15583 a) The tencode function overrides the IT insn type by
15584 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15585 b) The tencode function queries the IT block state by
15586 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15587
15588 Both set_it_insn_type and in_it_block run the internal FSM state
15589 handling function (handle_it_state), because: a) setting the IT insn
15590 type may incur in an invalid state (exiting the function),
15591 and b) querying the state requires the FSM to be updated.
15592 Specifically we want to avoid creating an IT block for conditional
15593 branches, so it_fsm_pre_encode is actually a guess and we can't
15594 determine whether an IT block is required until the tencode () routine
15595 has decided what type of instruction this actually it.
15596 Because of this, if set_it_insn_type and in_it_block have to be used,
15597 set_it_insn_type has to be called first.
15598
15599 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15600 determines the insn IT type depending on the inst.cond code.
15601 When a tencode () routine encodes an instruction that can be
15602 either outside an IT block, or, in the case of being inside, has to be
15603 the last one, set_it_insn_type_last () will determine the proper
15604 IT instruction type based on the inst.cond code. Otherwise,
15605 set_it_insn_type can be called for overriding that logic or
15606 for covering other cases.
15607
15608 Calling handle_it_state () may not transition the IT block state to
15609 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15610 still queried. Instead, if the FSM determines that the state should
15611 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15612 after the tencode () function: that's what it_fsm_post_encode () does.
15613
15614 Since in_it_block () calls the state handling function to get an
15615 updated state, an error may occur (due to invalid insns combination).
15616 In that case, inst.error is set.
15617 Therefore, inst.error has to be checked after the execution of
15618 the tencode () routine.
15619
15620 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15621 any pending state change (if any) that didn't take place in
15622 handle_it_state () as explained above. */
15623
15624static void
15625it_fsm_pre_encode (void)
15626{
15627 if (inst.cond != COND_ALWAYS)
15628 inst.it_insn_type = INSIDE_IT_INSN;
15629 else
15630 inst.it_insn_type = OUTSIDE_IT_INSN;
15631
15632 now_it.state_handled = 0;
15633}
15634
15635/* IT state FSM handling function. */
15636
15637static int
15638handle_it_state (void)
15639{
15640 now_it.state_handled = 1;
15641
15642 switch (now_it.state)
15643 {
15644 case OUTSIDE_IT_BLOCK:
15645 switch (inst.it_insn_type)
15646 {
15647 case OUTSIDE_IT_INSN:
15648 break;
15649
15650 case INSIDE_IT_INSN:
15651 case INSIDE_IT_LAST_INSN:
15652 if (thumb_mode == 0)
15653 {
c921be7d 15654 if (unified_syntax
e07e6e58
NC
15655 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15656 as_tsktsk (_("Warning: conditional outside an IT block"\
15657 " for Thumb."));
15658 }
15659 else
15660 {
15661 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15662 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15663 {
15664 /* Automatically generate the IT instruction. */
15665 new_automatic_it_block (inst.cond);
15666 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15667 close_automatic_it_block ();
15668 }
15669 else
15670 {
15671 inst.error = BAD_OUT_IT;
15672 return FAIL;
15673 }
15674 }
15675 break;
15676
15677 case IF_INSIDE_IT_LAST_INSN:
15678 case NEUTRAL_IT_INSN:
15679 break;
15680
15681 case IT_INSN:
15682 now_it.state = MANUAL_IT_BLOCK;
15683 now_it.block_length = 0;
15684 break;
15685 }
15686 break;
15687
15688 case AUTOMATIC_IT_BLOCK:
15689 /* Three things may happen now:
15690 a) We should increment current it block size;
15691 b) We should close current it block (closing insn or 4 insns);
15692 c) We should close current it block and start a new one (due
15693 to incompatible conditions or
15694 4 insns-length block reached). */
15695
15696 switch (inst.it_insn_type)
15697 {
15698 case OUTSIDE_IT_INSN:
15699 /* The closure of the block shall happen immediatelly,
15700 so any in_it_block () call reports the block as closed. */
15701 force_automatic_it_block_close ();
15702 break;
15703
15704 case INSIDE_IT_INSN:
15705 case INSIDE_IT_LAST_INSN:
15706 case IF_INSIDE_IT_LAST_INSN:
15707 now_it.block_length++;
15708
15709 if (now_it.block_length > 4
15710 || !now_it_compatible (inst.cond))
15711 {
15712 force_automatic_it_block_close ();
15713 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15714 new_automatic_it_block (inst.cond);
15715 }
15716 else
15717 {
15718 now_it_add_mask (inst.cond);
15719 }
15720
15721 if (now_it.state == AUTOMATIC_IT_BLOCK
15722 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15723 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15724 close_automatic_it_block ();
15725 break;
15726
15727 case NEUTRAL_IT_INSN:
15728 now_it.block_length++;
15729
15730 if (now_it.block_length > 4)
15731 force_automatic_it_block_close ();
15732 else
15733 now_it_add_mask (now_it.cc & 1);
15734 break;
15735
15736 case IT_INSN:
15737 close_automatic_it_block ();
15738 now_it.state = MANUAL_IT_BLOCK;
15739 break;
15740 }
15741 break;
15742
15743 case MANUAL_IT_BLOCK:
15744 {
15745 /* Check conditional suffixes. */
15746 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15747 int is_last;
15748 now_it.mask <<= 1;
15749 now_it.mask &= 0x1f;
15750 is_last = (now_it.mask == 0x10);
15751
15752 switch (inst.it_insn_type)
15753 {
15754 case OUTSIDE_IT_INSN:
15755 inst.error = BAD_NOT_IT;
15756 return FAIL;
15757
15758 case INSIDE_IT_INSN:
15759 if (cond != inst.cond)
15760 {
15761 inst.error = BAD_IT_COND;
15762 return FAIL;
15763 }
15764 break;
15765
15766 case INSIDE_IT_LAST_INSN:
15767 case IF_INSIDE_IT_LAST_INSN:
15768 if (cond != inst.cond)
15769 {
15770 inst.error = BAD_IT_COND;
15771 return FAIL;
15772 }
15773 if (!is_last)
15774 {
15775 inst.error = BAD_BRANCH;
15776 return FAIL;
15777 }
15778 break;
15779
15780 case NEUTRAL_IT_INSN:
15781 /* The BKPT instruction is unconditional even in an IT block. */
15782 break;
15783
15784 case IT_INSN:
15785 inst.error = BAD_IT_IT;
15786 return FAIL;
15787 }
15788 }
15789 break;
15790 }
15791
15792 return SUCCESS;
15793}
15794
15795static void
15796it_fsm_post_encode (void)
15797{
15798 int is_last;
15799
15800 if (!now_it.state_handled)
15801 handle_it_state ();
15802
15803 is_last = (now_it.mask == 0x10);
15804 if (is_last)
15805 {
15806 now_it.state = OUTSIDE_IT_BLOCK;
15807 now_it.mask = 0;
15808 }
15809}
15810
15811static void
15812force_automatic_it_block_close (void)
15813{
15814 if (now_it.state == AUTOMATIC_IT_BLOCK)
15815 {
15816 close_automatic_it_block ();
15817 now_it.state = OUTSIDE_IT_BLOCK;
15818 now_it.mask = 0;
15819 }
15820}
15821
15822static int
15823in_it_block (void)
15824{
15825 if (!now_it.state_handled)
15826 handle_it_state ();
15827
15828 return now_it.state != OUTSIDE_IT_BLOCK;
15829}
15830
c19d1205
ZW
15831void
15832md_assemble (char *str)
b99bd4ef 15833{
c19d1205
ZW
15834 char *p = str;
15835 const struct asm_opcode * opcode;
b99bd4ef 15836
c19d1205
ZW
15837 /* Align the previous label if needed. */
15838 if (last_label_seen != NULL)
b99bd4ef 15839 {
c19d1205
ZW
15840 symbol_set_frag (last_label_seen, frag_now);
15841 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15842 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
15843 }
15844
c19d1205
ZW
15845 memset (&inst, '\0', sizeof (inst));
15846 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 15847
c19d1205
ZW
15848 opcode = opcode_lookup (&p);
15849 if (!opcode)
b99bd4ef 15850 {
c19d1205 15851 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 15852 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d
NC
15853 if (! create_register_alias (str, p)
15854 && ! create_neon_reg_alias (str, p))
c19d1205 15855 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 15856
b99bd4ef
NC
15857 return;
15858 }
15859
278df34e 15860 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
15861 as_warn (_("s suffix on comparison instruction is deprecated"));
15862
037e8744
JB
15863 /* The value which unconditional instructions should have in place of the
15864 condition field. */
15865 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
15866
c19d1205 15867 if (thumb_mode)
b99bd4ef 15868 {
e74cfd16 15869 arm_feature_set variant;
8f06b2d8
PB
15870
15871 variant = cpu_variant;
15872 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
15873 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15874 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 15875 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
15876 if (!opcode->tvariant
15877 || (thumb_mode == 1
15878 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 15879 {
bf3eeda7 15880 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
b99bd4ef
NC
15881 return;
15882 }
c19d1205
ZW
15883 if (inst.cond != COND_ALWAYS && !unified_syntax
15884 && opcode->tencode != do_t_branch)
b99bd4ef 15885 {
c19d1205 15886 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
15887 return;
15888 }
15889
752d5da4 15890 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 15891 {
7e806470 15892 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
15893 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
15894 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
15895 {
15896 /* Two things are addressed here.
15897 1) Implicit require narrow instructions on Thumb-1.
15898 This avoids relaxation accidentally introducing Thumb-2
15899 instructions.
15900 2) Reject wide instructions in non Thumb-2 cores. */
15901 if (inst.size_req == 0)
15902 inst.size_req = 2;
15903 else if (inst.size_req == 4)
15904 {
bf3eeda7 15905 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
752d5da4
NC
15906 return;
15907 }
15908 }
076d447c
PB
15909 }
15910
c19d1205
ZW
15911 inst.instruction = opcode->tvalue;
15912
5be8be5d 15913 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
e07e6e58
NC
15914 {
15915 /* Prepare the it_insn_type for those encodings that don't set
15916 it. */
15917 it_fsm_pre_encode ();
c19d1205 15918
e07e6e58
NC
15919 opcode->tencode ();
15920
15921 it_fsm_post_encode ();
15922 }
e27ec89e 15923
0110f2b8 15924 if (!(inst.error || inst.relax))
b99bd4ef 15925 {
9c2799c2 15926 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
15927 inst.size = (inst.instruction > 0xffff ? 4 : 2);
15928 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 15929 {
c19d1205 15930 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
15931 return;
15932 }
15933 }
076d447c
PB
15934
15935 /* Something has gone badly wrong if we try to relax a fixed size
15936 instruction. */
9c2799c2 15937 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 15938
e74cfd16
PB
15939 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15940 *opcode->tvariant);
ee065d83 15941 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 15942 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 15943 anything other than bl/blx and v6-M instructions.
ee065d83 15944 This is overly pessimistic for relaxable instructions. */
7e806470
PB
15945 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
15946 || inst.relax)
e07e6e58
NC
15947 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15948 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
15949 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15950 arm_ext_v6t2);
cd000bff 15951
88714cb8
DG
15952 check_neon_suffixes;
15953
cd000bff 15954 if (!inst.error)
c877a2f2
NC
15955 {
15956 mapping_state (MAP_THUMB);
15957 }
c19d1205 15958 }
3e9e4fcf 15959 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 15960 {
845b51d6
PB
15961 bfd_boolean is_bx;
15962
15963 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
15964 is_bx = (opcode->aencode == do_bx);
15965
c19d1205 15966 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
15967 if (!(is_bx && fix_v4bx)
15968 && !(opcode->avariant &&
15969 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 15970 {
bf3eeda7 15971 as_bad (_("selected processor does not support ARM mode `%s'"), str);
c19d1205 15972 return;
b99bd4ef 15973 }
c19d1205 15974 if (inst.size_req)
b99bd4ef 15975 {
c19d1205
ZW
15976 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
15977 return;
b99bd4ef
NC
15978 }
15979
c19d1205
ZW
15980 inst.instruction = opcode->avalue;
15981 if (opcode->tag == OT_unconditionalF)
15982 inst.instruction |= 0xF << 28;
15983 else
15984 inst.instruction |= inst.cond << 28;
15985 inst.size = INSN_SIZE;
5be8be5d 15986 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
e07e6e58
NC
15987 {
15988 it_fsm_pre_encode ();
15989 opcode->aencode ();
15990 it_fsm_post_encode ();
15991 }
ee065d83
PB
15992 /* Arm mode bx is marked as both v4T and v5 because it's still required
15993 on a hypothetical non-thumb v5 core. */
845b51d6 15994 if (is_bx)
e74cfd16 15995 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 15996 else
e74cfd16
PB
15997 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
15998 *opcode->avariant);
88714cb8
DG
15999
16000 check_neon_suffixes;
16001
cd000bff 16002 if (!inst.error)
c877a2f2
NC
16003 {
16004 mapping_state (MAP_ARM);
16005 }
b99bd4ef 16006 }
3e9e4fcf
JB
16007 else
16008 {
16009 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
16010 "-- `%s'"), str);
16011 return;
16012 }
c19d1205
ZW
16013 output_inst (str);
16014}
b99bd4ef 16015
e07e6e58
NC
16016static void
16017check_it_blocks_finished (void)
16018{
16019#ifdef OBJ_ELF
16020 asection *sect;
16021
16022 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
16023 if (seg_info (sect)->tc_segment_info_data.current_it.state
16024 == MANUAL_IT_BLOCK)
16025 {
16026 as_warn (_("section '%s' finished with an open IT block."),
16027 sect->name);
16028 }
16029#else
16030 if (now_it.state == MANUAL_IT_BLOCK)
16031 as_warn (_("file finished with an open IT block."));
16032#endif
16033}
16034
c19d1205
ZW
16035/* Various frobbings of labels and their addresses. */
16036
16037void
16038arm_start_line_hook (void)
16039{
16040 last_label_seen = NULL;
b99bd4ef
NC
16041}
16042
c19d1205
ZW
16043void
16044arm_frob_label (symbolS * sym)
b99bd4ef 16045{
c19d1205 16046 last_label_seen = sym;
b99bd4ef 16047
c19d1205 16048 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 16049
c19d1205
ZW
16050#if defined OBJ_COFF || defined OBJ_ELF
16051 ARM_SET_INTERWORK (sym, support_interwork);
16052#endif
b99bd4ef 16053
e07e6e58
NC
16054 force_automatic_it_block_close ();
16055
5f4273c7 16056 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
16057 as Thumb functions. This is because these labels, whilst
16058 they exist inside Thumb code, are not the entry points for
16059 possible ARM->Thumb calls. Also, these labels can be used
16060 as part of a computed goto or switch statement. eg gcc
16061 can generate code that looks like this:
b99bd4ef 16062
c19d1205
ZW
16063 ldr r2, [pc, .Laaa]
16064 lsl r3, r3, #2
16065 ldr r2, [r3, r2]
16066 mov pc, r2
b99bd4ef 16067
c19d1205
ZW
16068 .Lbbb: .word .Lxxx
16069 .Lccc: .word .Lyyy
16070 ..etc...
16071 .Laaa: .word Lbbb
b99bd4ef 16072
c19d1205
ZW
16073 The first instruction loads the address of the jump table.
16074 The second instruction converts a table index into a byte offset.
16075 The third instruction gets the jump address out of the table.
16076 The fourth instruction performs the jump.
b99bd4ef 16077
c19d1205
ZW
16078 If the address stored at .Laaa is that of a symbol which has the
16079 Thumb_Func bit set, then the linker will arrange for this address
16080 to have the bottom bit set, which in turn would mean that the
16081 address computation performed by the third instruction would end
16082 up with the bottom bit set. Since the ARM is capable of unaligned
16083 word loads, the instruction would then load the incorrect address
16084 out of the jump table, and chaos would ensue. */
16085 if (label_is_thumb_function_name
16086 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
16087 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 16088 {
c19d1205
ZW
16089 /* When the address of a Thumb function is taken the bottom
16090 bit of that address should be set. This will allow
16091 interworking between Arm and Thumb functions to work
16092 correctly. */
b99bd4ef 16093
c19d1205 16094 THUMB_SET_FUNC (sym, 1);
b99bd4ef 16095
c19d1205 16096 label_is_thumb_function_name = FALSE;
b99bd4ef 16097 }
07a53e5c 16098
07a53e5c 16099 dwarf2_emit_label (sym);
b99bd4ef
NC
16100}
16101
c921be7d 16102bfd_boolean
c19d1205 16103arm_data_in_code (void)
b99bd4ef 16104{
c19d1205 16105 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 16106 {
c19d1205
ZW
16107 *input_line_pointer = '/';
16108 input_line_pointer += 5;
16109 *input_line_pointer = 0;
c921be7d 16110 return TRUE;
b99bd4ef
NC
16111 }
16112
c921be7d 16113 return FALSE;
b99bd4ef
NC
16114}
16115
c19d1205
ZW
16116char *
16117arm_canonicalize_symbol_name (char * name)
b99bd4ef 16118{
c19d1205 16119 int len;
b99bd4ef 16120
c19d1205
ZW
16121 if (thumb_mode && (len = strlen (name)) > 5
16122 && streq (name + len - 5, "/data"))
16123 *(name + len - 5) = 0;
b99bd4ef 16124
c19d1205 16125 return name;
b99bd4ef 16126}
c19d1205
ZW
16127\f
16128/* Table of all register names defined by default. The user can
16129 define additional names with .req. Note that all register names
16130 should appear in both upper and lowercase variants. Some registers
16131 also have mixed-case names. */
b99bd4ef 16132
dcbf9037 16133#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 16134#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 16135#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
16136#define REGSET(p,t) \
16137 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
16138 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
16139 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
16140 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
16141#define REGSETH(p,t) \
16142 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
16143 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
16144 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
16145 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
16146#define REGSET2(p,t) \
16147 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
16148 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
16149 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
16150 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 16151
c19d1205 16152static const struct reg_entry reg_names[] =
7ed4c4c5 16153{
c19d1205
ZW
16154 /* ARM integer registers. */
16155 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 16156
c19d1205
ZW
16157 /* ATPCS synonyms. */
16158 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
16159 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16160 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 16161
c19d1205
ZW
16162 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16163 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16164 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 16165
c19d1205
ZW
16166 /* Well-known aliases. */
16167 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16168 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16169
16170 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16171 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16172
16173 /* Coprocessor numbers. */
16174 REGSET(p, CP), REGSET(P, CP),
16175
16176 /* Coprocessor register numbers. The "cr" variants are for backward
16177 compatibility. */
16178 REGSET(c, CN), REGSET(C, CN),
16179 REGSET(cr, CN), REGSET(CR, CN),
16180
16181 /* FPA registers. */
16182 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16183 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16184
16185 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16186 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16187
16188 /* VFP SP registers. */
5287ad62
JB
16189 REGSET(s,VFS), REGSET(S,VFS),
16190 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
16191
16192 /* VFP DP Registers. */
5287ad62
JB
16193 REGSET(d,VFD), REGSET(D,VFD),
16194 /* Extra Neon DP registers. */
16195 REGSETH(d,VFD), REGSETH(D,VFD),
16196
16197 /* Neon QP registers. */
16198 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
16199
16200 /* VFP control registers. */
16201 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16202 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
16203 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16204 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16205 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16206 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
16207
16208 /* Maverick DSP coprocessor registers. */
16209 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16210 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16211
16212 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16213 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16214 REGDEF(dspsc,0,DSPSC),
16215
16216 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16217 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16218 REGDEF(DSPSC,0,DSPSC),
16219
16220 /* iWMMXt data registers - p0, c0-15. */
16221 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16222
16223 /* iWMMXt control registers - p1, c0-3. */
16224 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16225 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16226 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16227 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16228
16229 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16230 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16231 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16232 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16233 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16234
16235 /* XScale accumulator registers. */
16236 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16237};
16238#undef REGDEF
16239#undef REGNUM
16240#undef REGSET
7ed4c4c5 16241
c19d1205
ZW
16242/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16243 within psr_required_here. */
16244static const struct asm_psr psrs[] =
16245{
16246 /* Backward compatibility notation. Note that "all" is no longer
16247 truly all possible PSR bits. */
16248 {"all", PSR_c | PSR_f},
16249 {"flg", PSR_f},
16250 {"ctl", PSR_c},
16251
16252 /* Individual flags. */
16253 {"f", PSR_f},
16254 {"c", PSR_c},
16255 {"x", PSR_x},
16256 {"s", PSR_s},
59b42a0d
MGD
16257 {"g", PSR_s},
16258
c19d1205
ZW
16259 /* Combinations of flags. */
16260 {"fs", PSR_f | PSR_s},
16261 {"fx", PSR_f | PSR_x},
16262 {"fc", PSR_f | PSR_c},
16263 {"sf", PSR_s | PSR_f},
16264 {"sx", PSR_s | PSR_x},
16265 {"sc", PSR_s | PSR_c},
16266 {"xf", PSR_x | PSR_f},
16267 {"xs", PSR_x | PSR_s},
16268 {"xc", PSR_x | PSR_c},
16269 {"cf", PSR_c | PSR_f},
16270 {"cs", PSR_c | PSR_s},
16271 {"cx", PSR_c | PSR_x},
16272 {"fsx", PSR_f | PSR_s | PSR_x},
16273 {"fsc", PSR_f | PSR_s | PSR_c},
16274 {"fxs", PSR_f | PSR_x | PSR_s},
16275 {"fxc", PSR_f | PSR_x | PSR_c},
16276 {"fcs", PSR_f | PSR_c | PSR_s},
16277 {"fcx", PSR_f | PSR_c | PSR_x},
16278 {"sfx", PSR_s | PSR_f | PSR_x},
16279 {"sfc", PSR_s | PSR_f | PSR_c},
16280 {"sxf", PSR_s | PSR_x | PSR_f},
16281 {"sxc", PSR_s | PSR_x | PSR_c},
16282 {"scf", PSR_s | PSR_c | PSR_f},
16283 {"scx", PSR_s | PSR_c | PSR_x},
16284 {"xfs", PSR_x | PSR_f | PSR_s},
16285 {"xfc", PSR_x | PSR_f | PSR_c},
16286 {"xsf", PSR_x | PSR_s | PSR_f},
16287 {"xsc", PSR_x | PSR_s | PSR_c},
16288 {"xcf", PSR_x | PSR_c | PSR_f},
16289 {"xcs", PSR_x | PSR_c | PSR_s},
16290 {"cfs", PSR_c | PSR_f | PSR_s},
16291 {"cfx", PSR_c | PSR_f | PSR_x},
16292 {"csf", PSR_c | PSR_s | PSR_f},
16293 {"csx", PSR_c | PSR_s | PSR_x},
16294 {"cxf", PSR_c | PSR_x | PSR_f},
16295 {"cxs", PSR_c | PSR_x | PSR_s},
16296 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16297 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16298 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16299 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16300 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16301 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16302 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16303 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16304 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16305 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16306 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16307 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16308 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16309 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16310 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16311 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16312 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16313 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16314 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16315 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16316 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16317 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16318 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16319 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
59b42a0d
MGD
16320
16321 /* APSR flags */
16322 {"nzcvq", PSR_f},
16323 {"nzcvqg", PSR_s | PSR_f}
c19d1205
ZW
16324};
16325
62b3e311
PB
16326/* Table of V7M psr names. */
16327static const struct asm_psr v7m_psrs[] =
16328{
2b744c99
PB
16329 {"apsr", 0 }, {"APSR", 0 },
16330 {"iapsr", 1 }, {"IAPSR", 1 },
16331 {"eapsr", 2 }, {"EAPSR", 2 },
16332 {"psr", 3 }, {"PSR", 3 },
16333 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16334 {"ipsr", 5 }, {"IPSR", 5 },
16335 {"epsr", 6 }, {"EPSR", 6 },
16336 {"iepsr", 7 }, {"IEPSR", 7 },
16337 {"msp", 8 }, {"MSP", 8 },
16338 {"psp", 9 }, {"PSP", 9 },
16339 {"primask", 16}, {"PRIMASK", 16},
16340 {"basepri", 17}, {"BASEPRI", 17},
16341 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16342 {"faultmask", 19}, {"FAULTMASK", 19},
16343 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
16344};
16345
c19d1205
ZW
16346/* Table of all shift-in-operand names. */
16347static const struct asm_shift_name shift_names [] =
b99bd4ef 16348{
c19d1205
ZW
16349 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16350 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16351 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16352 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16353 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16354 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16355};
b99bd4ef 16356
c19d1205
ZW
16357/* Table of all explicit relocation names. */
16358#ifdef OBJ_ELF
16359static struct reloc_entry reloc_names[] =
16360{
16361 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16362 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16363 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16364 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16365 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16366 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16367 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16368 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16369 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16370 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6
NC
16371 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
16372 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}
c19d1205
ZW
16373};
16374#endif
b99bd4ef 16375
c19d1205
ZW
16376/* Table of all conditional affixes. 0xF is not defined as a condition code. */
16377static const struct asm_cond conds[] =
16378{
16379 {"eq", 0x0},
16380 {"ne", 0x1},
16381 {"cs", 0x2}, {"hs", 0x2},
16382 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16383 {"mi", 0x4},
16384 {"pl", 0x5},
16385 {"vs", 0x6},
16386 {"vc", 0x7},
16387 {"hi", 0x8},
16388 {"ls", 0x9},
16389 {"ge", 0xa},
16390 {"lt", 0xb},
16391 {"gt", 0xc},
16392 {"le", 0xd},
16393 {"al", 0xe}
16394};
bfae80f2 16395
62b3e311
PB
16396static struct asm_barrier_opt barrier_opt_names[] =
16397{
52e7f43d
RE
16398 { "sy", 0xf }, { "SY", 0xf },
16399 { "un", 0x7 }, { "UN", 0x7 },
16400 { "st", 0xe }, { "ST", 0xe },
16401 { "unst", 0x6 }, { "UNST", 0x6 },
16402 { "ish", 0xb }, { "ISH", 0xb },
16403 { "sh", 0xb }, { "SH", 0xb },
16404 { "ishst", 0xa }, { "ISHST", 0xa },
16405 { "shst", 0xa }, { "SHST", 0xa },
16406 { "nsh", 0x7 }, { "NSH", 0x7 },
16407 { "nshst", 0x6 }, { "NSHST", 0x6 },
16408 { "osh", 0x3 }, { "OSH", 0x3 },
16409 { "oshst", 0x2 }, { "OSHST", 0x2 }
62b3e311
PB
16410};
16411
c19d1205
ZW
16412/* Table of ARM-format instructions. */
16413
16414/* Macros for gluing together operand strings. N.B. In all cases
16415 other than OPS0, the trailing OP_stop comes from default
16416 zero-initialization of the unspecified elements of the array. */
16417#define OPS0() { OP_stop, }
16418#define OPS1(a) { OP_##a, }
16419#define OPS2(a,b) { OP_##a,OP_##b, }
16420#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16421#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16422#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16423#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16424
5be8be5d
DG
16425/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16426 This is useful when mixing operands for ARM and THUMB, i.e. using the
16427 MIX_ARM_THUMB_OPERANDS macro.
16428 In order to use these macros, prefix the number of operands with _
16429 e.g. _3. */
16430#define OPS_1(a) { a, }
16431#define OPS_2(a,b) { a,b, }
16432#define OPS_3(a,b,c) { a,b,c, }
16433#define OPS_4(a,b,c,d) { a,b,c,d, }
16434#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16435#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16436
c19d1205
ZW
16437/* These macros abstract out the exact format of the mnemonic table and
16438 save some repeated characters. */
16439
16440/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16441#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16442 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 16443 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16444
16445/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16446 a T_MNEM_xyz enumerator. */
16447#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16448 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16449#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16450 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16451
16452/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16453 infix after the third character. */
16454#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 16455 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 16456 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 16457#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 16458 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 16459 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 16460#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16461 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 16462#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16463 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16464#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16465 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 16466#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16467 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16468
16469/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16470 appear in the condition table. */
16471#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
21d799b5 16472 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
1887dd22 16473 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16474
16475#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
16476 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16477 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16478 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16479 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16480 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16481 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16482 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16483 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16484 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16485 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16486 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16487 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16488 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16489 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16490 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16491 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16492 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16493 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16494 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
16495
16496#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
16497 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16498#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
21d799b5 16499 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16500
16501/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
16502 field is still 0xE. Many of the Thumb variants can be executed
16503 conditionally, so this is checked separately. */
c19d1205 16504#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16505 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16506 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16507
16508/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16509 condition code field. */
16510#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 16511 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16512 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16513
16514/* ARM-only variants of all the above. */
6a86118a 16515#define CE(mnem, op, nops, ops, ae) \
21d799b5 16516 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
16517
16518#define C3(mnem, op, nops, ops, ae) \
16519 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16520
e3cb604e
PB
16521/* Legacy mnemonics that always have conditional infix after the third
16522 character. */
16523#define CL(mnem, op, nops, ops, ae) \
21d799b5 16524 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16525 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16526
8f06b2d8
PB
16527/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16528#define cCE(mnem, op, nops, ops, ae) \
21d799b5 16529 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16530
e3cb604e
PB
16531/* Legacy coprocessor instructions where conditional infix and conditional
16532 suffix are ambiguous. For consistency this includes all FPA instructions,
16533 not just the potentially ambiguous ones. */
16534#define cCL(mnem, op, nops, ops, ae) \
21d799b5 16535 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16536 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16537
16538/* Coprocessor, takes either a suffix or a position-3 infix
16539 (for an FPA corner case). */
16540#define C3E(mnem, op, nops, ops, ae) \
21d799b5 16541 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 16542 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16543
6a86118a 16544#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
16545 { m1 #m2 m3, OPS##nops ops, \
16546 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
16547 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16548
16549#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
16550 xCM_ (m1, , m2, op, nops, ops, ae), \
16551 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16552 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16553 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16554 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16555 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16556 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16557 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16558 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16559 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16560 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16561 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16562 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16563 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16564 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16565 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16566 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16567 xCM_ (m1, le, m2, op, nops, ops, ae), \
16568 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
16569
16570#define UE(mnem, op, nops, ops, ae) \
16571 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16572
16573#define UF(mnem, op, nops, ops, ae) \
16574 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16575
5287ad62
JB
16576/* Neon data-processing. ARM versions are unconditional with cond=0xf.
16577 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16578 use the same encoding function for each. */
16579#define NUF(mnem, op, nops, ops, enc) \
16580 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16581 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16582
16583/* Neon data processing, version which indirects through neon_enc_tab for
16584 the various overloaded versions of opcodes. */
16585#define nUF(mnem, op, nops, ops, enc) \
21d799b5 16586 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16587 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16588
16589/* Neon insn with conditional suffix for the ARM version, non-overloaded
16590 version. */
037e8744
JB
16591#define NCE_tag(mnem, op, nops, ops, enc, tag) \
16592 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
16593 THUMB_VARIANT, do_##enc, do_##enc }
16594
037e8744 16595#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 16596 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16597
16598#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 16599 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16600
5287ad62 16601/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 16602#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 16603 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16604 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16605
037e8744 16606#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 16607 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16608
16609#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 16610 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16611
c19d1205
ZW
16612#define do_0 0
16613
c19d1205 16614static const struct asm_opcode insns[] =
bfae80f2 16615{
e74cfd16
PB
16616#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
16617#define THUMB_VARIANT &arm_ext_v4t
21d799b5
NC
16618 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
16619 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
16620 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
16621 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
16622 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
16623 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
16624 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
16625 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
16626 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
16627 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
16628 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
16629 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
16630 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
16631 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
16632 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
16633 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
16634
16635 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
16636 for setting PSR flag bits. They are obsolete in V6 and do not
16637 have Thumb equivalents. */
21d799b5
NC
16638 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16639 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16640 CL("tstp", 110f000, 2, (RR, SH), cmp),
16641 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16642 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16643 CL("cmpp", 150f000, 2, (RR, SH), cmp),
16644 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16645 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16646 CL("cmnp", 170f000, 2, (RR, SH), cmp),
16647
16648 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
16649 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
16650 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
16651 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
16652
16653 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
16654 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16655 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
16656 OP_RRnpc),
16657 OP_ADDRGLDR),ldst, t_ldst),
16658 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
16659
16660 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16661 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16662 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16663 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16664 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16665 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16666
16667 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
16668 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
16669 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
16670 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 16671
c19d1205 16672 /* Pseudo ops. */
21d799b5 16673 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 16674 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 16675 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
16676
16677 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
16678 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
16679 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
16680 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
16681 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
16682 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
16683 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
16684 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
16685 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
16686 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
16687 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
16688 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
16689 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 16690
16a4cf17 16691 /* These may simplify to neg. */
21d799b5
NC
16692 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
16693 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 16694
c921be7d
NC
16695#undef THUMB_VARIANT
16696#define THUMB_VARIANT & arm_ext_v6
16697
21d799b5 16698 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
16699
16700 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
16701#undef THUMB_VARIANT
16702#define THUMB_VARIANT & arm_ext_v6t2
16703
21d799b5
NC
16704 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16705 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16706 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 16707
5be8be5d
DG
16708 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16709 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16710 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
16711 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 16712
21d799b5
NC
16713 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16714 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 16715
21d799b5
NC
16716 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16717 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
16718
16719 /* V1 instructions with no Thumb analogue at all. */
21d799b5 16720 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
16721 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16722
16723 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16724 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16725 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16726 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16727 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16728 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16729 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16730 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16731
c921be7d
NC
16732#undef ARM_VARIANT
16733#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
16734#undef THUMB_VARIANT
16735#define THUMB_VARIANT & arm_ext_v4t
16736
21d799b5
NC
16737 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16738 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 16739
c921be7d
NC
16740#undef THUMB_VARIANT
16741#define THUMB_VARIANT & arm_ext_v6t2
16742
21d799b5 16743 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
16744 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16745
16746 /* Generic coprocessor instructions. */
21d799b5
NC
16747 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16748 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16749 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16750 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16751 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16752 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 16753 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16754
c921be7d
NC
16755#undef ARM_VARIANT
16756#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
16757
21d799b5 16758 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
16759 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16760
c921be7d
NC
16761#undef ARM_VARIANT
16762#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
16763#undef THUMB_VARIANT
16764#define THUMB_VARIANT & arm_ext_msr
16765
21d799b5
NC
16766 TCE("mrs", 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
16767 TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205 16768
c921be7d
NC
16769#undef ARM_VARIANT
16770#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
16771#undef THUMB_VARIANT
16772#define THUMB_VARIANT & arm_ext_v6t2
16773
21d799b5
NC
16774 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16775 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16776 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16777 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16778 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16779 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16780 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16781 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 16782
c921be7d
NC
16783#undef ARM_VARIANT
16784#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
16785#undef THUMB_VARIANT
16786#define THUMB_VARIANT & arm_ext_v4t
16787
5be8be5d
DG
16788 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16789 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16790 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16791 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16792 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16793 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 16794
c921be7d
NC
16795#undef ARM_VARIANT
16796#define ARM_VARIANT & arm_ext_v4t_5
16797
c19d1205
ZW
16798 /* ARM Architecture 4T. */
16799 /* Note: bx (and blx) are required on V5, even if the processor does
16800 not support Thumb. */
21d799b5 16801 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 16802
c921be7d
NC
16803#undef ARM_VARIANT
16804#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
16805#undef THUMB_VARIANT
16806#define THUMB_VARIANT & arm_ext_v5t
16807
c19d1205
ZW
16808 /* Note: blx has 2 variants; the .value coded here is for
16809 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
16810 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
16811 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 16812
c921be7d
NC
16813#undef THUMB_VARIANT
16814#define THUMB_VARIANT & arm_ext_v6t2
16815
21d799b5
NC
16816 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
16817 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16818 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16819 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16820 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16821 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16822 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16823 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16824
c921be7d
NC
16825#undef ARM_VARIANT
16826#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
9e3c6df6
PB
16827#undef THUMB_VARIANT
16828#define THUMB_VARIANT &arm_ext_v5exp
c921be7d 16829
21d799b5
NC
16830 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16831 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16832 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16833 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 16834
21d799b5
NC
16835 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16836 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 16837
21d799b5
NC
16838 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16839 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16840 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16841 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 16842
21d799b5
NC
16843 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16844 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16845 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16846 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 16847
21d799b5
NC
16848 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16849 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 16850
03ee1b7f
NC
16851 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16852 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16853 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16854 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 16855
c921be7d
NC
16856#undef ARM_VARIANT
16857#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
9e3c6df6
PB
16858#undef THUMB_VARIANT
16859#define THUMB_VARIANT &arm_ext_v6t2
c921be7d 16860
21d799b5 16861 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
16862 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
16863 ldrd, t_ldstd),
16864 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
16865 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 16866
21d799b5
NC
16867 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16868 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 16869
c921be7d
NC
16870#undef ARM_VARIANT
16871#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
16872
21d799b5 16873 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 16874
c921be7d
NC
16875#undef ARM_VARIANT
16876#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
16877#undef THUMB_VARIANT
16878#define THUMB_VARIANT & arm_ext_v6
16879
21d799b5
NC
16880 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
16881 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
16882 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16883 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16884 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16885 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16886 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16887 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16888 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16889 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 16890
c921be7d
NC
16891#undef THUMB_VARIANT
16892#define THUMB_VARIANT & arm_ext_v6t2
16893
5be8be5d
DG
16894 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
16895 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16896 strex, t_strex),
21d799b5
NC
16897 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16898 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 16899
21d799b5
NC
16900 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
16901 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 16902
9e3c6df6 16903/* ARM V6 not included in V7M. */
c921be7d
NC
16904#undef THUMB_VARIANT
16905#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6
PB
16906 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16907 UF(rfeib, 9900a00, 1, (RRw), rfe),
16908 UF(rfeda, 8100a00, 1, (RRw), rfe),
16909 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16910 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16911 UF(rfefa, 9900a00, 1, (RRw), rfe),
16912 UF(rfeea, 8100a00, 1, (RRw), rfe),
16913 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16914 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
16915 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
16916 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
16917 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 16918
9e3c6df6
PB
16919/* ARM V6 not included in V7M (eg. integer SIMD). */
16920#undef THUMB_VARIANT
16921#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
16922 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
16923 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
16924 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
16925 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16926 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16927 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16928 /* Old name for QASX. */
21d799b5
NC
16929 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16930 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16931 /* Old name for QSAX. */
21d799b5
NC
16932 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16933 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16934 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16935 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16936 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16937 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16938 /* Old name for SASX. */
21d799b5
NC
16939 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16940 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16941 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16942 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16943 /* Old name for SHASX. */
21d799b5
NC
16944 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16945 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16946 /* Old name for SHSAX. */
21d799b5
NC
16947 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16948 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16949 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16950 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16951 /* Old name for SSAX. */
21d799b5
NC
16952 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16953 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16954 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16955 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16956 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16957 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16958 /* Old name for UASX. */
21d799b5
NC
16959 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16960 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16961 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16962 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16963 /* Old name for UHASX. */
21d799b5
NC
16964 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16965 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16966 /* Old name for UHSAX. */
21d799b5
NC
16967 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16968 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16969 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16970 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16971 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16972 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16973 /* Old name for UQASX. */
21d799b5
NC
16974 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16975 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16976 /* Old name for UQSAX. */
21d799b5
NC
16977 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16978 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16979 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16980 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16981 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16982 /* Old name for USAX. */
21d799b5
NC
16983 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16984 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
16985 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16986 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16987 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16988 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16989 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16990 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16991 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16992 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16993 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16994 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16995 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16996 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16997 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16998 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16999 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17000 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17001 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17002 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17003 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17004 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17005 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17006 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17007 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17008 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17009 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17010 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17011 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
17012 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
17013 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
17014 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17015 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17016 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 17017
c921be7d
NC
17018#undef ARM_VARIANT
17019#define ARM_VARIANT & arm_ext_v6k
17020#undef THUMB_VARIANT
17021#define THUMB_VARIANT & arm_ext_v6k
17022
21d799b5
NC
17023 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
17024 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
17025 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
17026 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 17027
c921be7d
NC
17028#undef THUMB_VARIANT
17029#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
17030 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
17031 ldrexd, t_ldrexd),
17032 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
17033 RRnpcb), strexd, t_strexd),
ebdca51a 17034
c921be7d
NC
17035#undef THUMB_VARIANT
17036#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
17037 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
17038 rd_rn, rd_rn),
17039 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
17040 rd_rn, rd_rn),
17041 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17042 strex, rm_rd_rn),
17043 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17044 strex, rm_rd_rn),
21d799b5 17045 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 17046
c921be7d
NC
17047#undef ARM_VARIANT
17048#define ARM_VARIANT & arm_ext_v6z
17049
21d799b5 17050 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 17051
c921be7d
NC
17052#undef ARM_VARIANT
17053#define ARM_VARIANT & arm_ext_v6t2
17054
21d799b5
NC
17055 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
17056 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
17057 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17058 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 17059
21d799b5
NC
17060 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17061 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
17062 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
17063 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 17064
5be8be5d
DG
17065 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17066 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17067 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17068 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 17069
bf3eeda7
NS
17070 /* Thumb-only instructions. */
17071#undef ARM_VARIANT
17072#define ARM_VARIANT NULL
17073 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
17074 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
17075
17076 /* ARM does not really have an IT instruction, so always allow it.
17077 The opcode is copied from Thumb in order to allow warnings in
17078 -mimplicit-it=[never | arm] modes. */
17079#undef ARM_VARIANT
17080#define ARM_VARIANT & arm_ext_v1
17081
21d799b5
NC
17082 TUE("it", bf08, bf08, 1, (COND), it, t_it),
17083 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
17084 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
17085 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
17086 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
17087 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
17088 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
17089 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
17090 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
17091 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
17092 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
17093 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
17094 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
17095 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
17096 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 17097 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
17098 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
17099 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 17100
92e90b6e 17101 /* Thumb2 only instructions. */
c921be7d
NC
17102#undef ARM_VARIANT
17103#define ARM_VARIANT NULL
92e90b6e 17104
21d799b5
NC
17105 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17106 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17107 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
17108 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
17109 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
17110 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 17111
62b3e311 17112 /* Thumb-2 hardware division instructions (R and M profiles only). */
c921be7d
NC
17113#undef THUMB_VARIANT
17114#define THUMB_VARIANT & arm_ext_div
17115
21d799b5
NC
17116 TCE("sdiv", 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
17117 TCE("udiv", 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
62b3e311 17118
7e806470 17119 /* ARM V6M/V7 instructions. */
c921be7d
NC
17120#undef ARM_VARIANT
17121#define ARM_VARIANT & arm_ext_barrier
17122#undef THUMB_VARIANT
17123#define THUMB_VARIANT & arm_ext_barrier
17124
52e7f43d
RE
17125 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
17126 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
17127 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
7e806470 17128
62b3e311 17129 /* ARM V7 instructions. */
c921be7d
NC
17130#undef ARM_VARIANT
17131#define ARM_VARIANT & arm_ext_v7
17132#undef THUMB_VARIANT
17133#define THUMB_VARIANT & arm_ext_v7
17134
21d799b5
NC
17135 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
17136 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 17137
c921be7d
NC
17138#undef ARM_VARIANT
17139#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
17140
21d799b5
NC
17141 cCE("wfs", e200110, 1, (RR), rd),
17142 cCE("rfs", e300110, 1, (RR), rd),
17143 cCE("wfc", e400110, 1, (RR), rd),
17144 cCE("rfc", e500110, 1, (RR), rd),
17145
17146 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
17147 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
17148 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
17149 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
17150
17151 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
17152 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
17153 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
17154 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
17155
17156 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
17157 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
17158 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
17159 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
17160 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
17161 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
17162 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
17163 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
17164 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
17165 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
17166 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
17167 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
17168
17169 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
17170 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
17171 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
17172 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
17173 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17174 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17175 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17176 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17177 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17178 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17179 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17180 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17181
17182 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17183 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17184 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17185 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17186 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17187 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17188 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17189 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17190 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17191 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17192 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17193 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17194
17195 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17196 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17197 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17198 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17199 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17200 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17201 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17202 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17203 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17204 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17205 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17206 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17207
17208 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17209 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17210 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17211 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17212 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17213 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17214 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17215 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17216 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17217 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17218 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17219 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17220
17221 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17222 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17223 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17224 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17225 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17226 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17227 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17228 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17229 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17230 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17231 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17232 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17233
17234 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17235 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17236 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17237 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17238 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17239 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17240 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17241 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17242 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17243 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17244 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17245 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17246
17247 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17248 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17249 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17250 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17251 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17252 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17253 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17254 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17255 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17256 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17257 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17258 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17259
17260 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17261 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17262 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17263 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17264 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17265 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17266 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17267 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17268 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17269 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17270 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17271 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17272
17273 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17274 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17275 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17276 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17277 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17278 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17279 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17280 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17281 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17282 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17283 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17284 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17285
17286 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17287 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17288 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17289 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17290 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17291 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17292 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17293 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17294 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17295 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17296 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17297 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17298
17299 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17300 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17301 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17302 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17303 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17304 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17305 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17306 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17307 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17308 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17309 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17310 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17311
17312 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17313 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17314 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17315 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17316 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17317 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17318 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17319 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17320 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17321 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17322 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17323 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17324
17325 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17326 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17327 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17328 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17329 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17330 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17331 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17332 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17333 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17334 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17335 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17336 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17337
17338 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17339 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17340 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17341 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17342 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17343 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17344 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17345 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17346 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17347 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17348 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17349 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17350
17351 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17352 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17353 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17354 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17355 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17356 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17357 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17358 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17359 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17360 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17361 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17362 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17363
17364 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17365 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17366 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17367 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17368 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17369 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17370 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17371 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17372 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17373 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17374 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17375 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17376
17377 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17378 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17379 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17380 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17381 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17382 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17383 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17384 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17385 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17386 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17387 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17388 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17389
17390 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17391 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17392 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17393 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17394 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17395 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17396 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17397 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17398 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17399 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17400 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17401 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17402
17403 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17404 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17405 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17406 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17407 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17408 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17409 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17410 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17411 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17412 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17413 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17414 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17415
17416 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17417 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17418 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17419 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17420 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17421 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17422 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17423 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17424 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17425 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17426 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17427 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17428
17429 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17430 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17431 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17432 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17433 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17434 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17435 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17436 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17437 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17438 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17439 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17440 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17441
17442 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17443 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17444 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17445 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17446 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17447 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17448 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17449 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17450 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17451 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17452 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17453 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17454
17455 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17456 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17457 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17458 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17459 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17460 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17461 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17462 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17463 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17464 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17465 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17466 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17467
17468 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17469 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17470 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17471 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17472 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17473 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17474 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17475 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17476 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17477 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17478 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17479 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17480
17481 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17482 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17483 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17484 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17485 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17486 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17487 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17488 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17489 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17490 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17491 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17492 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17493
17494 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17495 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17496 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17497 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17498 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17499 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17500 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17501 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17502 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17503 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17504 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17505 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17506
17507 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17508 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17509 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17510 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17511 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17512 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17513 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17514 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17515 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17516 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17517 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17518 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17519
17520 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17521 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17522 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17523 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17524 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17525 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17526 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17527 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17528 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17529 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17530 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17531 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17532
17533 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17534 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17535 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17536 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17537
17538 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17539 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17540 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17541 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17542 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17543 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17544 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17545 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17546 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17547 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17548 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17549 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 17550
c19d1205
ZW
17551 /* The implementation of the FIX instruction is broken on some
17552 assemblers, in that it accepts a precision specifier as well as a
17553 rounding specifier, despite the fact that this is meaningless.
17554 To be more compatible, we accept it as well, though of course it
17555 does not set any bits. */
21d799b5
NC
17556 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17557 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17558 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17559 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17560 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17561 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17562 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17563 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17564 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17565 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17566 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17567 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17568 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 17569
c19d1205 17570 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
17571#undef ARM_VARIANT
17572#define ARM_VARIANT & fpu_fpa_ext_v2
17573
21d799b5
NC
17574 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17575 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17576 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17577 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17578 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17579 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 17580
c921be7d
NC
17581#undef ARM_VARIANT
17582#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
17583
c19d1205 17584 /* Moves and type conversions. */
21d799b5
NC
17585 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
17586 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
17587 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
17588 cCE("fmstat", ef1fa10, 0, (), noargs),
f7c21dc7
NC
17589 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
17590 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
21d799b5
NC
17591 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
17592 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
17593 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
17594 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17595 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
17596 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17597 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
17598 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
17599
17600 /* Memory operations. */
21d799b5
NC
17601 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17602 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
17603 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17604 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17605 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17606 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17607 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17608 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17609 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17610 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17611 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17612 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17613 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17614 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17615 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17616 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17617 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17618 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 17619
c19d1205 17620 /* Monadic operations. */
21d799b5
NC
17621 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
17622 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
17623 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
17624
17625 /* Dyadic operations. */
21d799b5
NC
17626 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17627 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17628 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17629 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17630 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17631 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17632 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17633 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17634 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 17635
c19d1205 17636 /* Comparisons. */
21d799b5
NC
17637 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
17638 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
17639 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
17640 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 17641
62f3b8c8
PB
17642 /* Double precision load/store are still present on single precision
17643 implementations. */
17644 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17645 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
17646 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17647 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17648 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17649 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17650 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17651 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17652 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17653 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 17654
c921be7d
NC
17655#undef ARM_VARIANT
17656#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
17657
c19d1205 17658 /* Moves and type conversions. */
21d799b5
NC
17659 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17660 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17661 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17662 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
17663 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
17664 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
17665 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
17666 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17667 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
17668 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17669 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17670 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17671 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 17672
c19d1205 17673 /* Monadic operations. */
21d799b5
NC
17674 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17675 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17676 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
17677
17678 /* Dyadic operations. */
21d799b5
NC
17679 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17680 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17681 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17682 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17683 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17684 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17685 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17686 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17687 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 17688
c19d1205 17689 /* Comparisons. */
21d799b5
NC
17690 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17691 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
17692 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17693 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 17694
c921be7d
NC
17695#undef ARM_VARIANT
17696#define ARM_VARIANT & fpu_vfp_ext_v2
17697
21d799b5
NC
17698 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
17699 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
17700 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
17701 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 17702
037e8744
JB
17703/* Instructions which may belong to either the Neon or VFP instruction sets.
17704 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
17705#undef ARM_VARIANT
17706#define ARM_VARIANT & fpu_vfp_ext_v1xd
17707#undef THUMB_VARIANT
17708#define THUMB_VARIANT & fpu_vfp_ext_v1xd
17709
037e8744
JB
17710 /* These mnemonics are unique to VFP. */
17711 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
17712 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
17713 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17714 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17715 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17716 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17717 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
17718 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
17719 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
17720 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
17721
17722 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
17723 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
17724 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17725 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 17726
21d799b5
NC
17727 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17728 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
17729
17730 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17731 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17732
55881a11
MGD
17733 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17734 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17735 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17736 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17737 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17738 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
17739 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17740 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 17741
e3e535bc
NC
17742 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
17743 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
21d799b5
NC
17744 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
17745 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 17746
037e8744
JB
17747
17748 /* NOTE: All VMOV encoding is special-cased! */
17749 NCE(vmov, 0, 1, (VMOV), neon_mov),
17750 NCE(vmovq, 0, 1, (VMOV), neon_mov),
17751
c921be7d
NC
17752#undef THUMB_VARIANT
17753#define THUMB_VARIANT & fpu_neon_ext_v1
17754#undef ARM_VARIANT
17755#define ARM_VARIANT & fpu_neon_ext_v1
17756
5287ad62
JB
17757 /* Data processing with three registers of the same length. */
17758 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
17759 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
17760 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
17761 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17762 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17763 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17764 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17765 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17766 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17767 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17768 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17769 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17770 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17771 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
17772 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17773 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17774 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17775 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
17776 /* If not immediate, fall back to neon_dyadic_i64_su.
17777 shl_imm should accept I8 I16 I32 I64,
17778 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
17779 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17780 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17781 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17782 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 17783 /* Logic ops, types optional & ignored. */
4316f0d2
DG
17784 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17785 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17786 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17787 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17788 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17789 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17790 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17791 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17792 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
17793 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
17794 /* Bitfield ops, untyped. */
17795 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17796 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17797 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17798 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17799 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17800 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17801 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
17802 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17803 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17804 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17805 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17806 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17807 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
17808 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
17809 back to neon_dyadic_if_su. */
21d799b5
NC
17810 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17811 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17812 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17813 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17814 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17815 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17816 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17817 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 17818 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
17819 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
17820 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 17821 /* As above, D registers only. */
21d799b5
NC
17822 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17823 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 17824 /* Int and float variants, signedness unimportant. */
21d799b5
NC
17825 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17826 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17827 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 17828 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
17829 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17830 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
17831 /* vtst takes sizes 8, 16, 32. */
17832 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
17833 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
17834 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 17835 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 17836 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
17837 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17838 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17839 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17840 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
17841 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17842 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17843 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17844 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
17845 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17846 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17847 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17848 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
17849 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17850 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17851 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17852 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17853
17854 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 17855 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
17856 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
17857
17858 /* Data processing with two registers and a shift amount. */
17859 /* Right shifts, and variants with rounding.
17860 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
17861 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17862 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17863 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17864 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17865 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17866 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17867 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17868 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17869 /* Shift and insert. Sizes accepted 8 16 32 64. */
17870 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
17871 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
17872 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
17873 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
17874 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
17875 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
17876 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
17877 /* Right shift immediate, saturating & narrowing, with rounding variants.
17878 Types accepted S16 S32 S64 U16 U32 U64. */
17879 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17880 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17881 /* As above, unsigned. Types accepted S16 S32 S64. */
17882 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17883 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17884 /* Right shift narrowing. Types accepted I16 I32 I64. */
17885 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17886 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17887 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 17888 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 17889 /* CVT with optional immediate for fixed-point variant. */
21d799b5 17890 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 17891
4316f0d2
DG
17892 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
17893 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
17894
17895 /* Data processing, three registers of different lengths. */
17896 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
17897 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
17898 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
17899 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
17900 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
17901 /* If not scalar, fall back to neon_dyadic_long.
17902 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
17903 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17904 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
17905 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
17906 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17907 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17908 /* Dyadic, narrowing insns. Types I16 I32 I64. */
17909 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17910 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17911 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17912 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17913 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
17914 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17915 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17916 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
17917 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
17918 S16 S32 U16 U32. */
21d799b5 17919 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
17920
17921 /* Extract. Size 8. */
3b8d421e
PB
17922 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
17923 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
17924
17925 /* Two registers, miscellaneous. */
17926 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
17927 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
17928 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
17929 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
17930 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
17931 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
17932 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
17933 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
17934 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
17935 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
17936 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
17937 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
17938 /* VMOVN. Types I16 I32 I64. */
21d799b5 17939 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 17940 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 17941 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 17942 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 17943 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
17944 /* VZIP / VUZP. Sizes 8 16 32. */
17945 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
17946 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
17947 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
17948 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
17949 /* VQABS / VQNEG. Types S8 S16 S32. */
17950 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17951 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
17952 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17953 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
17954 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
17955 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
17956 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
17957 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
17958 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
17959 /* Reciprocal estimates. Types U32 F32. */
17960 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
17961 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
17962 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
17963 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
17964 /* VCLS. Types S8 S16 S32. */
17965 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
17966 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
17967 /* VCLZ. Types I8 I16 I32. */
17968 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
17969 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
17970 /* VCNT. Size 8. */
17971 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
17972 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
17973 /* Two address, untyped. */
17974 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
17975 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
17976 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
17977 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
17978 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
17979
17980 /* Table lookup. Size 8. */
17981 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17982 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17983
c921be7d
NC
17984#undef THUMB_VARIANT
17985#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
17986#undef ARM_VARIANT
17987#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
17988
5287ad62 17989 /* Neon element/structure load/store. */
21d799b5
NC
17990 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17991 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17992 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17993 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17994 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17995 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17996 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17997 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 17998
c921be7d 17999#undef THUMB_VARIANT
62f3b8c8
PB
18000#define THUMB_VARIANT &fpu_vfp_ext_v3xd
18001#undef ARM_VARIANT
18002#define ARM_VARIANT &fpu_vfp_ext_v3xd
18003 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
18004 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18005 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18006 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18007 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18008 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18009 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18010 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18011 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18012
18013#undef THUMB_VARIANT
c921be7d
NC
18014#define THUMB_VARIANT & fpu_vfp_ext_v3
18015#undef ARM_VARIANT
18016#define ARM_VARIANT & fpu_vfp_ext_v3
18017
21d799b5 18018 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 18019 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18020 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18021 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18022 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18023 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18024 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18025 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18026 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 18027
62f3b8c8
PB
18028#undef ARM_VARIANT
18029#define ARM_VARIANT &fpu_vfp_ext_fma
18030#undef THUMB_VARIANT
18031#define THUMB_VARIANT &fpu_vfp_ext_fma
18032 /* Mnemonics shared by Neon and VFP. These are included in the
18033 VFP FMA variant; NEON and VFP FMA always includes the NEON
18034 FMA instructions. */
18035 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18036 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18037 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
18038 the v form should always be used. */
18039 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18040 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18041 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18042 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18043 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18044 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18045
5287ad62 18046#undef THUMB_VARIANT
c921be7d
NC
18047#undef ARM_VARIANT
18048#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
18049
21d799b5
NC
18050 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18051 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18052 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18053 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18054 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18055 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18056 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
18057 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 18058
c921be7d
NC
18059#undef ARM_VARIANT
18060#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
18061
21d799b5
NC
18062 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
18063 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
18064 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
18065 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
18066 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
18067 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
18068 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
18069 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
18070 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
18071 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18072 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18073 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18074 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18075 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18076 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18077 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18078 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18079 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18080 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
18081 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
18082 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18083 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18084 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18085 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18086 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18087 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18088 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
18089 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
18090 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
18091 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
18092 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
18093 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
18094 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
18095 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
18096 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
18097 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
18098 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
18099 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18100 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18101 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18102 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18103 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18104 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18105 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18106 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18107 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18108 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
18109 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18110 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18111 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18112 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18113 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18114 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18115 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18116 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18117 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18118 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18119 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18120 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18121 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18122 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18123 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18124 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18125 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18126 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18127 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18128 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18129 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18130 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18131 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18132 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18133 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18134 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18135 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18136 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18137 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18138 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18139 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18140 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18141 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18142 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18143 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18144 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18145 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18146 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18147 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18148 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18149 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18150 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
18151 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18152 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18153 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18154 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18155 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18156 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18157 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18158 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18159 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18160 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18161 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18162 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18163 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18164 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18165 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18166 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18167 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18168 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18169 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18170 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18171 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18172 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
18173 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18174 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18175 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18176 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18177 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18178 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18179 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18180 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18181 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18182 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18183 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18184 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18185 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18186 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18187 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18188 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18189 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18190 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18191 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18192 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18193 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18194 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18195 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18196 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18197 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18198 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18199 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18200 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18201 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18202 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18203 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18204 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18205 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18206 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18207 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18208 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18209 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18210 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18211 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18212 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18213 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18214 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18215 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18216 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18217 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18218 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18219 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18220 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18221 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18222 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18223 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 18224
c921be7d
NC
18225#undef ARM_VARIANT
18226#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18227
21d799b5
NC
18228 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18229 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18230 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18231 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18232 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18233 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18234 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18235 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18236 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18237 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18238 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18239 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18240 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18241 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18242 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18243 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18244 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18245 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18246 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18247 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18248 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18249 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18250 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18251 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18252 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18253 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18254 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18255 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18256 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18257 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18258 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18259 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18260 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18261 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18262 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18263 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18264 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18265 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18266 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18267 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18268 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18269 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18270 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18271 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18272 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18273 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18274 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18275 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18276 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18277 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18278 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18279 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18280 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18281 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18282 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18283 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18284 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 18285
c921be7d
NC
18286#undef ARM_VARIANT
18287#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18288
21d799b5
NC
18289 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18290 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18291 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18292 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18293 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18294 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18295 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18296 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18297 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18298 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18299 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18300 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18301 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18302 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18303 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18304 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18305 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18306 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18307 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18308 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18309 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18310 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18311 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18312 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18313 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18314 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18315 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18316 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18317 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18318 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18319 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18320 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18321 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18322 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18323 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18324 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18325 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18326 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18327 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18328 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18329 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18330 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18331 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18332 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18333 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18334 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18335 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18336 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18337 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18338 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18339 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18340 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18341 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18342 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18343 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18344 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18345 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18346 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18347 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18348 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18349 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18350 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18351 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18352 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18353 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18354 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18355 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18356 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18357 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18358 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18359 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18360 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18361 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18362 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18363 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18364 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
18365};
18366#undef ARM_VARIANT
18367#undef THUMB_VARIANT
18368#undef TCE
18369#undef TCM
18370#undef TUE
18371#undef TUF
18372#undef TCC
8f06b2d8 18373#undef cCE
e3cb604e
PB
18374#undef cCL
18375#undef C3E
c19d1205
ZW
18376#undef CE
18377#undef CM
18378#undef UE
18379#undef UF
18380#undef UT
5287ad62
JB
18381#undef NUF
18382#undef nUF
18383#undef NCE
18384#undef nCE
c19d1205
ZW
18385#undef OPS0
18386#undef OPS1
18387#undef OPS2
18388#undef OPS3
18389#undef OPS4
18390#undef OPS5
18391#undef OPS6
18392#undef do_0
18393\f
18394/* MD interface: bits in the object file. */
bfae80f2 18395
c19d1205
ZW
18396/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18397 for use in the a.out file, and stores them in the array pointed to by buf.
18398 This knows about the endian-ness of the target machine and does
18399 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18400 2 (short) and 4 (long) Floating numbers are put out as a series of
18401 LITTLENUMS (shorts, here at least). */
b99bd4ef 18402
c19d1205
ZW
18403void
18404md_number_to_chars (char * buf, valueT val, int n)
18405{
18406 if (target_big_endian)
18407 number_to_chars_bigendian (buf, val, n);
18408 else
18409 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
18410}
18411
c19d1205
ZW
18412static valueT
18413md_chars_to_number (char * buf, int n)
bfae80f2 18414{
c19d1205
ZW
18415 valueT result = 0;
18416 unsigned char * where = (unsigned char *) buf;
bfae80f2 18417
c19d1205 18418 if (target_big_endian)
b99bd4ef 18419 {
c19d1205
ZW
18420 while (n--)
18421 {
18422 result <<= 8;
18423 result |= (*where++ & 255);
18424 }
b99bd4ef 18425 }
c19d1205 18426 else
b99bd4ef 18427 {
c19d1205
ZW
18428 while (n--)
18429 {
18430 result <<= 8;
18431 result |= (where[n] & 255);
18432 }
bfae80f2 18433 }
b99bd4ef 18434
c19d1205 18435 return result;
bfae80f2 18436}
b99bd4ef 18437
c19d1205 18438/* MD interface: Sections. */
b99bd4ef 18439
0110f2b8
PB
18440/* Estimate the size of a frag before relaxing. Assume everything fits in
18441 2 bytes. */
18442
c19d1205 18443int
0110f2b8 18444md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
18445 segT segtype ATTRIBUTE_UNUSED)
18446{
0110f2b8
PB
18447 fragp->fr_var = 2;
18448 return 2;
18449}
18450
18451/* Convert a machine dependent frag. */
18452
18453void
18454md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18455{
18456 unsigned long insn;
18457 unsigned long old_op;
18458 char *buf;
18459 expressionS exp;
18460 fixS *fixp;
18461 int reloc_type;
18462 int pc_rel;
18463 int opcode;
18464
18465 buf = fragp->fr_literal + fragp->fr_fix;
18466
18467 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
18468 if (fragp->fr_symbol)
18469 {
0110f2b8
PB
18470 exp.X_op = O_symbol;
18471 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
18472 }
18473 else
18474 {
0110f2b8 18475 exp.X_op = O_constant;
5f4273c7 18476 }
0110f2b8
PB
18477 exp.X_add_number = fragp->fr_offset;
18478 opcode = fragp->fr_subtype;
18479 switch (opcode)
18480 {
18481 case T_MNEM_ldr_pc:
18482 case T_MNEM_ldr_pc2:
18483 case T_MNEM_ldr_sp:
18484 case T_MNEM_str_sp:
18485 case T_MNEM_ldr:
18486 case T_MNEM_ldrb:
18487 case T_MNEM_ldrh:
18488 case T_MNEM_str:
18489 case T_MNEM_strb:
18490 case T_MNEM_strh:
18491 if (fragp->fr_var == 4)
18492 {
5f4273c7 18493 insn = THUMB_OP32 (opcode);
0110f2b8
PB
18494 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18495 {
18496 insn |= (old_op & 0x700) << 4;
18497 }
18498 else
18499 {
18500 insn |= (old_op & 7) << 12;
18501 insn |= (old_op & 0x38) << 13;
18502 }
18503 insn |= 0x00000c00;
18504 put_thumb32_insn (buf, insn);
18505 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18506 }
18507 else
18508 {
18509 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18510 }
18511 pc_rel = (opcode == T_MNEM_ldr_pc2);
18512 break;
18513 case T_MNEM_adr:
18514 if (fragp->fr_var == 4)
18515 {
18516 insn = THUMB_OP32 (opcode);
18517 insn |= (old_op & 0xf0) << 4;
18518 put_thumb32_insn (buf, insn);
18519 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18520 }
18521 else
18522 {
18523 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18524 exp.X_add_number -= 4;
18525 }
18526 pc_rel = 1;
18527 break;
18528 case T_MNEM_mov:
18529 case T_MNEM_movs:
18530 case T_MNEM_cmp:
18531 case T_MNEM_cmn:
18532 if (fragp->fr_var == 4)
18533 {
18534 int r0off = (opcode == T_MNEM_mov
18535 || opcode == T_MNEM_movs) ? 0 : 8;
18536 insn = THUMB_OP32 (opcode);
18537 insn = (insn & 0xe1ffffff) | 0x10000000;
18538 insn |= (old_op & 0x700) << r0off;
18539 put_thumb32_insn (buf, insn);
18540 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18541 }
18542 else
18543 {
18544 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18545 }
18546 pc_rel = 0;
18547 break;
18548 case T_MNEM_b:
18549 if (fragp->fr_var == 4)
18550 {
18551 insn = THUMB_OP32(opcode);
18552 put_thumb32_insn (buf, insn);
18553 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18554 }
18555 else
18556 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18557 pc_rel = 1;
18558 break;
18559 case T_MNEM_bcond:
18560 if (fragp->fr_var == 4)
18561 {
18562 insn = THUMB_OP32(opcode);
18563 insn |= (old_op & 0xf00) << 14;
18564 put_thumb32_insn (buf, insn);
18565 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18566 }
18567 else
18568 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18569 pc_rel = 1;
18570 break;
18571 case T_MNEM_add_sp:
18572 case T_MNEM_add_pc:
18573 case T_MNEM_inc_sp:
18574 case T_MNEM_dec_sp:
18575 if (fragp->fr_var == 4)
18576 {
18577 /* ??? Choose between add and addw. */
18578 insn = THUMB_OP32 (opcode);
18579 insn |= (old_op & 0xf0) << 4;
18580 put_thumb32_insn (buf, insn);
16805f35
PB
18581 if (opcode == T_MNEM_add_pc)
18582 reloc_type = BFD_RELOC_ARM_T32_IMM12;
18583 else
18584 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
18585 }
18586 else
18587 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18588 pc_rel = 0;
18589 break;
18590
18591 case T_MNEM_addi:
18592 case T_MNEM_addis:
18593 case T_MNEM_subi:
18594 case T_MNEM_subis:
18595 if (fragp->fr_var == 4)
18596 {
18597 insn = THUMB_OP32 (opcode);
18598 insn |= (old_op & 0xf0) << 4;
18599 insn |= (old_op & 0xf) << 16;
18600 put_thumb32_insn (buf, insn);
16805f35
PB
18601 if (insn & (1 << 20))
18602 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18603 else
18604 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
18605 }
18606 else
18607 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18608 pc_rel = 0;
18609 break;
18610 default:
5f4273c7 18611 abort ();
0110f2b8
PB
18612 }
18613 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 18614 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
18615 fixp->fx_file = fragp->fr_file;
18616 fixp->fx_line = fragp->fr_line;
18617 fragp->fr_fix += fragp->fr_var;
18618}
18619
18620/* Return the size of a relaxable immediate operand instruction.
18621 SHIFT and SIZE specify the form of the allowable immediate. */
18622static int
18623relax_immediate (fragS *fragp, int size, int shift)
18624{
18625 offsetT offset;
18626 offsetT mask;
18627 offsetT low;
18628
18629 /* ??? Should be able to do better than this. */
18630 if (fragp->fr_symbol)
18631 return 4;
18632
18633 low = (1 << shift) - 1;
18634 mask = (1 << (shift + size)) - (1 << shift);
18635 offset = fragp->fr_offset;
18636 /* Force misaligned offsets to 32-bit variant. */
18637 if (offset & low)
5e77afaa 18638 return 4;
0110f2b8
PB
18639 if (offset & ~mask)
18640 return 4;
18641 return 2;
18642}
18643
5e77afaa
PB
18644/* Get the address of a symbol during relaxation. */
18645static addressT
5f4273c7 18646relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
18647{
18648 fragS *sym_frag;
18649 addressT addr;
18650 symbolS *sym;
18651
18652 sym = fragp->fr_symbol;
18653 sym_frag = symbol_get_frag (sym);
18654 know (S_GET_SEGMENT (sym) != absolute_section
18655 || sym_frag == &zero_address_frag);
18656 addr = S_GET_VALUE (sym) + fragp->fr_offset;
18657
18658 /* If frag has yet to be reached on this pass, assume it will
18659 move by STRETCH just as we did. If this is not so, it will
18660 be because some frag between grows, and that will force
18661 another pass. */
18662
18663 if (stretch != 0
18664 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
18665 {
18666 fragS *f;
18667
18668 /* Adjust stretch for any alignment frag. Note that if have
18669 been expanding the earlier code, the symbol may be
18670 defined in what appears to be an earlier frag. FIXME:
18671 This doesn't handle the fr_subtype field, which specifies
18672 a maximum number of bytes to skip when doing an
18673 alignment. */
18674 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
18675 {
18676 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
18677 {
18678 if (stretch < 0)
18679 stretch = - ((- stretch)
18680 & ~ ((1 << (int) f->fr_offset) - 1));
18681 else
18682 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
18683 if (stretch == 0)
18684 break;
18685 }
18686 }
18687 if (f != NULL)
18688 addr += stretch;
18689 }
5e77afaa
PB
18690
18691 return addr;
18692}
18693
0110f2b8
PB
18694/* Return the size of a relaxable adr pseudo-instruction or PC-relative
18695 load. */
18696static int
5e77afaa 18697relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
18698{
18699 addressT addr;
18700 offsetT val;
18701
18702 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
18703 if (fragp->fr_symbol == NULL
18704 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
18705 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18706 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
18707 return 4;
18708
5f4273c7 18709 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18710 addr = fragp->fr_address + fragp->fr_fix;
18711 addr = (addr + 4) & ~3;
5e77afaa 18712 /* Force misaligned targets to 32-bit variant. */
0110f2b8 18713 if (val & 3)
5e77afaa 18714 return 4;
0110f2b8
PB
18715 val -= addr;
18716 if (val < 0 || val > 1020)
18717 return 4;
18718 return 2;
18719}
18720
18721/* Return the size of a relaxable add/sub immediate instruction. */
18722static int
18723relax_addsub (fragS *fragp, asection *sec)
18724{
18725 char *buf;
18726 int op;
18727
18728 buf = fragp->fr_literal + fragp->fr_fix;
18729 op = bfd_get_16(sec->owner, buf);
18730 if ((op & 0xf) == ((op >> 4) & 0xf))
18731 return relax_immediate (fragp, 8, 0);
18732 else
18733 return relax_immediate (fragp, 3, 0);
18734}
18735
18736
18737/* Return the size of a relaxable branch instruction. BITS is the
18738 size of the offset field in the narrow instruction. */
18739
18740static int
5e77afaa 18741relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
18742{
18743 addressT addr;
18744 offsetT val;
18745 offsetT limit;
18746
18747 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 18748 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
18749 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18750 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
18751 return 4;
18752
267bf995
RR
18753#ifdef OBJ_ELF
18754 if (S_IS_DEFINED (fragp->fr_symbol)
18755 && ARM_IS_FUNC (fragp->fr_symbol))
18756 return 4;
18757#endif
18758
5f4273c7 18759 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18760 addr = fragp->fr_address + fragp->fr_fix + 4;
18761 val -= addr;
18762
18763 /* Offset is a signed value *2 */
18764 limit = 1 << bits;
18765 if (val >= limit || val < -limit)
18766 return 4;
18767 return 2;
18768}
18769
18770
18771/* Relax a machine dependent frag. This returns the amount by which
18772 the current size of the frag should change. */
18773
18774int
5e77afaa 18775arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
18776{
18777 int oldsize;
18778 int newsize;
18779
18780 oldsize = fragp->fr_var;
18781 switch (fragp->fr_subtype)
18782 {
18783 case T_MNEM_ldr_pc2:
5f4273c7 18784 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18785 break;
18786 case T_MNEM_ldr_pc:
18787 case T_MNEM_ldr_sp:
18788 case T_MNEM_str_sp:
5f4273c7 18789 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
18790 break;
18791 case T_MNEM_ldr:
18792 case T_MNEM_str:
5f4273c7 18793 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
18794 break;
18795 case T_MNEM_ldrh:
18796 case T_MNEM_strh:
5f4273c7 18797 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
18798 break;
18799 case T_MNEM_ldrb:
18800 case T_MNEM_strb:
5f4273c7 18801 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
18802 break;
18803 case T_MNEM_adr:
5f4273c7 18804 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18805 break;
18806 case T_MNEM_mov:
18807 case T_MNEM_movs:
18808 case T_MNEM_cmp:
18809 case T_MNEM_cmn:
5f4273c7 18810 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
18811 break;
18812 case T_MNEM_b:
5f4273c7 18813 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
18814 break;
18815 case T_MNEM_bcond:
5f4273c7 18816 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
18817 break;
18818 case T_MNEM_add_sp:
18819 case T_MNEM_add_pc:
18820 newsize = relax_immediate (fragp, 8, 2);
18821 break;
18822 case T_MNEM_inc_sp:
18823 case T_MNEM_dec_sp:
18824 newsize = relax_immediate (fragp, 7, 2);
18825 break;
18826 case T_MNEM_addi:
18827 case T_MNEM_addis:
18828 case T_MNEM_subi:
18829 case T_MNEM_subis:
18830 newsize = relax_addsub (fragp, sec);
18831 break;
18832 default:
5f4273c7 18833 abort ();
0110f2b8 18834 }
5e77afaa
PB
18835
18836 fragp->fr_var = newsize;
18837 /* Freeze wide instructions that are at or before the same location as
18838 in the previous pass. This avoids infinite loops.
5f4273c7
NC
18839 Don't freeze them unconditionally because targets may be artificially
18840 misaligned by the expansion of preceding frags. */
5e77afaa 18841 if (stretch <= 0 && newsize > 2)
0110f2b8 18842 {
0110f2b8 18843 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 18844 frag_wane (fragp);
0110f2b8 18845 }
5e77afaa 18846
0110f2b8 18847 return newsize - oldsize;
c19d1205 18848}
b99bd4ef 18849
c19d1205 18850/* Round up a section size to the appropriate boundary. */
b99bd4ef 18851
c19d1205
ZW
18852valueT
18853md_section_align (segT segment ATTRIBUTE_UNUSED,
18854 valueT size)
18855{
f0927246
NC
18856#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
18857 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
18858 {
18859 /* For a.out, force the section size to be aligned. If we don't do
18860 this, BFD will align it for us, but it will not write out the
18861 final bytes of the section. This may be a bug in BFD, but it is
18862 easier to fix it here since that is how the other a.out targets
18863 work. */
18864 int align;
18865
18866 align = bfd_get_section_alignment (stdoutput, segment);
18867 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
18868 }
c19d1205 18869#endif
f0927246
NC
18870
18871 return size;
bfae80f2 18872}
b99bd4ef 18873
c19d1205
ZW
18874/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
18875 of an rs_align_code fragment. */
18876
18877void
18878arm_handle_align (fragS * fragP)
bfae80f2 18879{
e7495e45
NS
18880 static char const arm_noop[2][2][4] =
18881 {
18882 { /* ARMv1 */
18883 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
18884 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
18885 },
18886 { /* ARMv6k */
18887 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
18888 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
18889 },
18890 };
18891 static char const thumb_noop[2][2][2] =
18892 {
18893 { /* Thumb-1 */
18894 {0xc0, 0x46}, /* LE */
18895 {0x46, 0xc0}, /* BE */
18896 },
18897 { /* Thumb-2 */
18898 {0x00, 0xbf}, /* LE */
18899 {0xbf, 0x00} /* BE */
18900 }
18901 };
18902 static char const wide_thumb_noop[2][4] =
18903 { /* Wide Thumb-2 */
18904 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
18905 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
18906 };
c921be7d 18907
e7495e45 18908 unsigned bytes, fix, noop_size;
c19d1205
ZW
18909 char * p;
18910 const char * noop;
e7495e45 18911 const char *narrow_noop = NULL;
cd000bff
DJ
18912#ifdef OBJ_ELF
18913 enum mstate state;
18914#endif
bfae80f2 18915
c19d1205 18916 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
18917 return;
18918
c19d1205
ZW
18919 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
18920 p = fragP->fr_literal + fragP->fr_fix;
18921 fix = 0;
bfae80f2 18922
c19d1205
ZW
18923 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
18924 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 18925
cd000bff 18926 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 18927
cd000bff 18928 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 18929 {
e7495e45
NS
18930 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
18931 {
18932 narrow_noop = thumb_noop[1][target_big_endian];
18933 noop = wide_thumb_noop[target_big_endian];
18934 }
c19d1205 18935 else
e7495e45
NS
18936 noop = thumb_noop[0][target_big_endian];
18937 noop_size = 2;
cd000bff
DJ
18938#ifdef OBJ_ELF
18939 state = MAP_THUMB;
18940#endif
7ed4c4c5
NC
18941 }
18942 else
18943 {
e7495e45
NS
18944 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
18945 [target_big_endian];
18946 noop_size = 4;
cd000bff
DJ
18947#ifdef OBJ_ELF
18948 state = MAP_ARM;
18949#endif
7ed4c4c5 18950 }
c921be7d 18951
e7495e45 18952 fragP->fr_var = noop_size;
c921be7d 18953
c19d1205 18954 if (bytes & (noop_size - 1))
7ed4c4c5 18955 {
c19d1205 18956 fix = bytes & (noop_size - 1);
cd000bff
DJ
18957#ifdef OBJ_ELF
18958 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
18959#endif
c19d1205
ZW
18960 memset (p, 0, fix);
18961 p += fix;
18962 bytes -= fix;
a737bd4d 18963 }
a737bd4d 18964
e7495e45
NS
18965 if (narrow_noop)
18966 {
18967 if (bytes & noop_size)
18968 {
18969 /* Insert a narrow noop. */
18970 memcpy (p, narrow_noop, noop_size);
18971 p += noop_size;
18972 bytes -= noop_size;
18973 fix += noop_size;
18974 }
18975
18976 /* Use wide noops for the remainder */
18977 noop_size = 4;
18978 }
18979
c19d1205 18980 while (bytes >= noop_size)
a737bd4d 18981 {
c19d1205
ZW
18982 memcpy (p, noop, noop_size);
18983 p += noop_size;
18984 bytes -= noop_size;
18985 fix += noop_size;
a737bd4d
NC
18986 }
18987
c19d1205 18988 fragP->fr_fix += fix;
a737bd4d
NC
18989}
18990
c19d1205
ZW
18991/* Called from md_do_align. Used to create an alignment
18992 frag in a code section. */
18993
18994void
18995arm_frag_align_code (int n, int max)
bfae80f2 18996{
c19d1205 18997 char * p;
7ed4c4c5 18998
c19d1205 18999 /* We assume that there will never be a requirement
6ec8e702 19000 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 19001 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
19002 {
19003 char err_msg[128];
19004
19005 sprintf (err_msg,
19006 _("alignments greater than %d bytes not supported in .text sections."),
19007 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 19008 as_fatal ("%s", err_msg);
6ec8e702 19009 }
bfae80f2 19010
c19d1205
ZW
19011 p = frag_var (rs_align_code,
19012 MAX_MEM_FOR_RS_ALIGN_CODE,
19013 1,
19014 (relax_substateT) max,
19015 (symbolS *) NULL,
19016 (offsetT) n,
19017 (char *) NULL);
19018 *p = 0;
19019}
bfae80f2 19020
8dc2430f
NC
19021/* Perform target specific initialisation of a frag.
19022 Note - despite the name this initialisation is not done when the frag
19023 is created, but only when its type is assigned. A frag can be created
19024 and used a long time before its type is set, so beware of assuming that
19025 this initialisationis performed first. */
bfae80f2 19026
cd000bff
DJ
19027#ifndef OBJ_ELF
19028void
19029arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
19030{
19031 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 19032 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
19033}
19034
19035#else /* OBJ_ELF is defined. */
c19d1205 19036void
cd000bff 19037arm_init_frag (fragS * fragP, int max_chars)
c19d1205 19038{
8dc2430f
NC
19039 /* If the current ARM vs THUMB mode has not already
19040 been recorded into this frag then do so now. */
cd000bff
DJ
19041 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
19042 {
19043 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19044
19045 /* Record a mapping symbol for alignment frags. We will delete this
19046 later if the alignment ends up empty. */
19047 switch (fragP->fr_type)
19048 {
19049 case rs_align:
19050 case rs_align_test:
19051 case rs_fill:
19052 mapping_state_2 (MAP_DATA, max_chars);
19053 break;
19054 case rs_align_code:
19055 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
19056 break;
19057 default:
19058 break;
19059 }
19060 }
bfae80f2
RE
19061}
19062
c19d1205
ZW
19063/* When we change sections we need to issue a new mapping symbol. */
19064
19065void
19066arm_elf_change_section (void)
bfae80f2 19067{
c19d1205
ZW
19068 /* Link an unlinked unwind index table section to the .text section. */
19069 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
19070 && elf_linked_to_section (now_seg) == NULL)
19071 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
19072}
19073
c19d1205
ZW
19074int
19075arm_elf_section_type (const char * str, size_t len)
e45d0630 19076{
c19d1205
ZW
19077 if (len == 5 && strncmp (str, "exidx", 5) == 0)
19078 return SHT_ARM_EXIDX;
e45d0630 19079
c19d1205
ZW
19080 return -1;
19081}
19082\f
19083/* Code to deal with unwinding tables. */
e45d0630 19084
c19d1205 19085static void add_unwind_adjustsp (offsetT);
e45d0630 19086
5f4273c7 19087/* Generate any deferred unwind frame offset. */
e45d0630 19088
bfae80f2 19089static void
c19d1205 19090flush_pending_unwind (void)
bfae80f2 19091{
c19d1205 19092 offsetT offset;
bfae80f2 19093
c19d1205
ZW
19094 offset = unwind.pending_offset;
19095 unwind.pending_offset = 0;
19096 if (offset != 0)
19097 add_unwind_adjustsp (offset);
bfae80f2
RE
19098}
19099
c19d1205
ZW
19100/* Add an opcode to this list for this function. Two-byte opcodes should
19101 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
19102 order. */
19103
bfae80f2 19104static void
c19d1205 19105add_unwind_opcode (valueT op, int length)
bfae80f2 19106{
c19d1205
ZW
19107 /* Add any deferred stack adjustment. */
19108 if (unwind.pending_offset)
19109 flush_pending_unwind ();
bfae80f2 19110
c19d1205 19111 unwind.sp_restored = 0;
bfae80f2 19112
c19d1205 19113 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 19114 {
c19d1205
ZW
19115 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
19116 if (unwind.opcodes)
21d799b5
NC
19117 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
19118 unwind.opcode_alloc);
c19d1205 19119 else
21d799b5 19120 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 19121 }
c19d1205 19122 while (length > 0)
bfae80f2 19123 {
c19d1205
ZW
19124 length--;
19125 unwind.opcodes[unwind.opcode_count] = op & 0xff;
19126 op >>= 8;
19127 unwind.opcode_count++;
bfae80f2 19128 }
bfae80f2
RE
19129}
19130
c19d1205
ZW
19131/* Add unwind opcodes to adjust the stack pointer. */
19132
bfae80f2 19133static void
c19d1205 19134add_unwind_adjustsp (offsetT offset)
bfae80f2 19135{
c19d1205 19136 valueT op;
bfae80f2 19137
c19d1205 19138 if (offset > 0x200)
bfae80f2 19139 {
c19d1205
ZW
19140 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
19141 char bytes[5];
19142 int n;
19143 valueT o;
bfae80f2 19144
c19d1205
ZW
19145 /* Long form: 0xb2, uleb128. */
19146 /* This might not fit in a word so add the individual bytes,
19147 remembering the list is built in reverse order. */
19148 o = (valueT) ((offset - 0x204) >> 2);
19149 if (o == 0)
19150 add_unwind_opcode (0, 1);
bfae80f2 19151
c19d1205
ZW
19152 /* Calculate the uleb128 encoding of the offset. */
19153 n = 0;
19154 while (o)
19155 {
19156 bytes[n] = o & 0x7f;
19157 o >>= 7;
19158 if (o)
19159 bytes[n] |= 0x80;
19160 n++;
19161 }
19162 /* Add the insn. */
19163 for (; n; n--)
19164 add_unwind_opcode (bytes[n - 1], 1);
19165 add_unwind_opcode (0xb2, 1);
19166 }
19167 else if (offset > 0x100)
bfae80f2 19168 {
c19d1205
ZW
19169 /* Two short opcodes. */
19170 add_unwind_opcode (0x3f, 1);
19171 op = (offset - 0x104) >> 2;
19172 add_unwind_opcode (op, 1);
bfae80f2 19173 }
c19d1205
ZW
19174 else if (offset > 0)
19175 {
19176 /* Short opcode. */
19177 op = (offset - 4) >> 2;
19178 add_unwind_opcode (op, 1);
19179 }
19180 else if (offset < 0)
bfae80f2 19181 {
c19d1205
ZW
19182 offset = -offset;
19183 while (offset > 0x100)
bfae80f2 19184 {
c19d1205
ZW
19185 add_unwind_opcode (0x7f, 1);
19186 offset -= 0x100;
bfae80f2 19187 }
c19d1205
ZW
19188 op = ((offset - 4) >> 2) | 0x40;
19189 add_unwind_opcode (op, 1);
bfae80f2 19190 }
bfae80f2
RE
19191}
19192
c19d1205
ZW
19193/* Finish the list of unwind opcodes for this function. */
19194static void
19195finish_unwind_opcodes (void)
bfae80f2 19196{
c19d1205 19197 valueT op;
bfae80f2 19198
c19d1205 19199 if (unwind.fp_used)
bfae80f2 19200 {
708587a4 19201 /* Adjust sp as necessary. */
c19d1205
ZW
19202 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19203 flush_pending_unwind ();
bfae80f2 19204
c19d1205
ZW
19205 /* After restoring sp from the frame pointer. */
19206 op = 0x90 | unwind.fp_reg;
19207 add_unwind_opcode (op, 1);
19208 }
19209 else
19210 flush_pending_unwind ();
bfae80f2
RE
19211}
19212
bfae80f2 19213
c19d1205
ZW
19214/* Start an exception table entry. If idx is nonzero this is an index table
19215 entry. */
bfae80f2
RE
19216
19217static void
c19d1205 19218start_unwind_section (const segT text_seg, int idx)
bfae80f2 19219{
c19d1205
ZW
19220 const char * text_name;
19221 const char * prefix;
19222 const char * prefix_once;
19223 const char * group_name;
19224 size_t prefix_len;
19225 size_t text_len;
19226 char * sec_name;
19227 size_t sec_name_len;
19228 int type;
19229 int flags;
19230 int linkonce;
bfae80f2 19231
c19d1205 19232 if (idx)
bfae80f2 19233 {
c19d1205
ZW
19234 prefix = ELF_STRING_ARM_unwind;
19235 prefix_once = ELF_STRING_ARM_unwind_once;
19236 type = SHT_ARM_EXIDX;
bfae80f2 19237 }
c19d1205 19238 else
bfae80f2 19239 {
c19d1205
ZW
19240 prefix = ELF_STRING_ARM_unwind_info;
19241 prefix_once = ELF_STRING_ARM_unwind_info_once;
19242 type = SHT_PROGBITS;
bfae80f2
RE
19243 }
19244
c19d1205
ZW
19245 text_name = segment_name (text_seg);
19246 if (streq (text_name, ".text"))
19247 text_name = "";
19248
19249 if (strncmp (text_name, ".gnu.linkonce.t.",
19250 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 19251 {
c19d1205
ZW
19252 prefix = prefix_once;
19253 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
19254 }
19255
c19d1205
ZW
19256 prefix_len = strlen (prefix);
19257 text_len = strlen (text_name);
19258 sec_name_len = prefix_len + text_len;
21d799b5 19259 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
19260 memcpy (sec_name, prefix, prefix_len);
19261 memcpy (sec_name + prefix_len, text_name, text_len);
19262 sec_name[prefix_len + text_len] = '\0';
bfae80f2 19263
c19d1205
ZW
19264 flags = SHF_ALLOC;
19265 linkonce = 0;
19266 group_name = 0;
bfae80f2 19267
c19d1205
ZW
19268 /* Handle COMDAT group. */
19269 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 19270 {
c19d1205
ZW
19271 group_name = elf_group_name (text_seg);
19272 if (group_name == NULL)
19273 {
bd3ba5d1 19274 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
19275 segment_name (text_seg));
19276 ignore_rest_of_line ();
19277 return;
19278 }
19279 flags |= SHF_GROUP;
19280 linkonce = 1;
bfae80f2
RE
19281 }
19282
c19d1205 19283 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 19284
5f4273c7 19285 /* Set the section link for index tables. */
c19d1205
ZW
19286 if (idx)
19287 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
19288}
19289
bfae80f2 19290
c19d1205
ZW
19291/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19292 personality routine data. Returns zero, or the index table value for
19293 and inline entry. */
19294
19295static valueT
19296create_unwind_entry (int have_data)
bfae80f2 19297{
c19d1205
ZW
19298 int size;
19299 addressT where;
19300 char *ptr;
19301 /* The current word of data. */
19302 valueT data;
19303 /* The number of bytes left in this word. */
19304 int n;
bfae80f2 19305
c19d1205 19306 finish_unwind_opcodes ();
bfae80f2 19307
c19d1205
ZW
19308 /* Remember the current text section. */
19309 unwind.saved_seg = now_seg;
19310 unwind.saved_subseg = now_subseg;
bfae80f2 19311
c19d1205 19312 start_unwind_section (now_seg, 0);
bfae80f2 19313
c19d1205 19314 if (unwind.personality_routine == NULL)
bfae80f2 19315 {
c19d1205
ZW
19316 if (unwind.personality_index == -2)
19317 {
19318 if (have_data)
5f4273c7 19319 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
19320 return 1; /* EXIDX_CANTUNWIND. */
19321 }
bfae80f2 19322
c19d1205
ZW
19323 /* Use a default personality routine if none is specified. */
19324 if (unwind.personality_index == -1)
19325 {
19326 if (unwind.opcode_count > 3)
19327 unwind.personality_index = 1;
19328 else
19329 unwind.personality_index = 0;
19330 }
bfae80f2 19331
c19d1205
ZW
19332 /* Space for the personality routine entry. */
19333 if (unwind.personality_index == 0)
19334 {
19335 if (unwind.opcode_count > 3)
19336 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 19337
c19d1205
ZW
19338 if (!have_data)
19339 {
19340 /* All the data is inline in the index table. */
19341 data = 0x80;
19342 n = 3;
19343 while (unwind.opcode_count > 0)
19344 {
19345 unwind.opcode_count--;
19346 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19347 n--;
19348 }
bfae80f2 19349
c19d1205
ZW
19350 /* Pad with "finish" opcodes. */
19351 while (n--)
19352 data = (data << 8) | 0xb0;
bfae80f2 19353
c19d1205
ZW
19354 return data;
19355 }
19356 size = 0;
19357 }
19358 else
19359 /* We get two opcodes "free" in the first word. */
19360 size = unwind.opcode_count - 2;
19361 }
19362 else
19363 /* An extra byte is required for the opcode count. */
19364 size = unwind.opcode_count + 1;
bfae80f2 19365
c19d1205
ZW
19366 size = (size + 3) >> 2;
19367 if (size > 0xff)
19368 as_bad (_("too many unwind opcodes"));
bfae80f2 19369
c19d1205
ZW
19370 frag_align (2, 0, 0);
19371 record_alignment (now_seg, 2);
19372 unwind.table_entry = expr_build_dot ();
19373
19374 /* Allocate the table entry. */
19375 ptr = frag_more ((size << 2) + 4);
19376 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 19377
c19d1205 19378 switch (unwind.personality_index)
bfae80f2 19379 {
c19d1205
ZW
19380 case -1:
19381 /* ??? Should this be a PLT generating relocation? */
19382 /* Custom personality routine. */
19383 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19384 BFD_RELOC_ARM_PREL31);
bfae80f2 19385
c19d1205
ZW
19386 where += 4;
19387 ptr += 4;
bfae80f2 19388
c19d1205
ZW
19389 /* Set the first byte to the number of additional words. */
19390 data = size - 1;
19391 n = 3;
19392 break;
bfae80f2 19393
c19d1205
ZW
19394 /* ABI defined personality routines. */
19395 case 0:
19396 /* Three opcodes bytes are packed into the first word. */
19397 data = 0x80;
19398 n = 3;
19399 break;
bfae80f2 19400
c19d1205
ZW
19401 case 1:
19402 case 2:
19403 /* The size and first two opcode bytes go in the first word. */
19404 data = ((0x80 + unwind.personality_index) << 8) | size;
19405 n = 2;
19406 break;
bfae80f2 19407
c19d1205
ZW
19408 default:
19409 /* Should never happen. */
19410 abort ();
19411 }
bfae80f2 19412
c19d1205
ZW
19413 /* Pack the opcodes into words (MSB first), reversing the list at the same
19414 time. */
19415 while (unwind.opcode_count > 0)
19416 {
19417 if (n == 0)
19418 {
19419 md_number_to_chars (ptr, data, 4);
19420 ptr += 4;
19421 n = 4;
19422 data = 0;
19423 }
19424 unwind.opcode_count--;
19425 n--;
19426 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19427 }
19428
19429 /* Finish off the last word. */
19430 if (n < 4)
19431 {
19432 /* Pad with "finish" opcodes. */
19433 while (n--)
19434 data = (data << 8) | 0xb0;
19435
19436 md_number_to_chars (ptr, data, 4);
19437 }
19438
19439 if (!have_data)
19440 {
19441 /* Add an empty descriptor if there is no user-specified data. */
19442 ptr = frag_more (4);
19443 md_number_to_chars (ptr, 0, 4);
19444 }
19445
19446 return 0;
bfae80f2
RE
19447}
19448
f0927246
NC
19449
19450/* Initialize the DWARF-2 unwind information for this procedure. */
19451
19452void
19453tc_arm_frame_initial_instructions (void)
19454{
19455 cfi_add_CFA_def_cfa (REG_SP, 0);
19456}
19457#endif /* OBJ_ELF */
19458
c19d1205
ZW
19459/* Convert REGNAME to a DWARF-2 register number. */
19460
19461int
1df69f4f 19462tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 19463{
1df69f4f 19464 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
19465
19466 if (reg == FAIL)
19467 return -1;
19468
19469 return reg;
bfae80f2
RE
19470}
19471
f0927246 19472#ifdef TE_PE
c19d1205 19473void
f0927246 19474tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 19475{
91d6fa6a 19476 expressionS exp;
bfae80f2 19477
91d6fa6a
NC
19478 exp.X_op = O_secrel;
19479 exp.X_add_symbol = symbol;
19480 exp.X_add_number = 0;
19481 emit_expr (&exp, size);
f0927246
NC
19482}
19483#endif
bfae80f2 19484
c19d1205 19485/* MD interface: Symbol and relocation handling. */
bfae80f2 19486
2fc8bdac
ZW
19487/* Return the address within the segment that a PC-relative fixup is
19488 relative to. For ARM, PC-relative fixups applied to instructions
19489 are generally relative to the location of the fixup plus 8 bytes.
19490 Thumb branches are offset by 4, and Thumb loads relative to PC
19491 require special handling. */
bfae80f2 19492
c19d1205 19493long
2fc8bdac 19494md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 19495{
2fc8bdac
ZW
19496 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19497
19498 /* If this is pc-relative and we are going to emit a relocation
19499 then we just want to put out any pipeline compensation that the linker
53baae48
NC
19500 will need. Otherwise we want to use the calculated base.
19501 For WinCE we skip the bias for externals as well, since this
19502 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 19503 if (fixP->fx_pcrel
2fc8bdac 19504 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
19505 || (arm_force_relocation (fixP)
19506#ifdef TE_WINCE
19507 && !S_IS_EXTERNAL (fixP->fx_addsy)
19508#endif
19509 )))
2fc8bdac 19510 base = 0;
bfae80f2 19511
267bf995 19512
c19d1205 19513 switch (fixP->fx_r_type)
bfae80f2 19514 {
2fc8bdac
ZW
19515 /* PC relative addressing on the Thumb is slightly odd as the
19516 bottom two bits of the PC are forced to zero for the
19517 calculation. This happens *after* application of the
19518 pipeline offset. However, Thumb adrl already adjusts for
19519 this, so we need not do it again. */
c19d1205 19520 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 19521 return base & ~3;
c19d1205
ZW
19522
19523 case BFD_RELOC_ARM_THUMB_OFFSET:
19524 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 19525 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 19526 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 19527 return (base + 4) & ~3;
c19d1205 19528
2fc8bdac
ZW
19529 /* Thumb branches are simply offset by +4. */
19530 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19531 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19532 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19533 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 19534 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 19535 return base + 4;
bfae80f2 19536
267bf995 19537 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
19538 if (fixP->fx_addsy
19539 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19540 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19541 && ARM_IS_FUNC (fixP->fx_addsy)
19542 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19543 base = fixP->fx_where + fixP->fx_frag->fr_address;
19544 return base + 4;
19545
00adf2d4
JB
19546 /* BLX is like branches above, but forces the low two bits of PC to
19547 zero. */
486499d0
CL
19548 case BFD_RELOC_THUMB_PCREL_BLX:
19549 if (fixP->fx_addsy
19550 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19551 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19552 && THUMB_IS_FUNC (fixP->fx_addsy)
19553 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19554 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
19555 return (base + 4) & ~3;
19556
2fc8bdac
ZW
19557 /* ARM mode branches are offset by +8. However, the Windows CE
19558 loader expects the relocation not to take this into account. */
267bf995 19559 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
19560 if (fixP->fx_addsy
19561 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19562 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19563 && ARM_IS_FUNC (fixP->fx_addsy)
19564 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19565 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19566 return base + 8;
267bf995 19567
486499d0
CL
19568 case BFD_RELOC_ARM_PCREL_CALL:
19569 if (fixP->fx_addsy
19570 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19571 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19572 && THUMB_IS_FUNC (fixP->fx_addsy)
19573 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19574 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19575 return base + 8;
267bf995 19576
2fc8bdac 19577 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 19578 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 19579 case BFD_RELOC_ARM_PLT32:
c19d1205 19580#ifdef TE_WINCE
5f4273c7 19581 /* When handling fixups immediately, because we have already
53baae48
NC
19582 discovered the value of a symbol, or the address of the frag involved
19583 we must account for the offset by +8, as the OS loader will never see the reloc.
19584 see fixup_segment() in write.c
19585 The S_IS_EXTERNAL test handles the case of global symbols.
19586 Those need the calculated base, not just the pipe compensation the linker will need. */
19587 if (fixP->fx_pcrel
19588 && fixP->fx_addsy != NULL
19589 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19590 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
19591 return base + 8;
2fc8bdac 19592 return base;
c19d1205 19593#else
2fc8bdac 19594 return base + 8;
c19d1205 19595#endif
2fc8bdac 19596
267bf995 19597
2fc8bdac
ZW
19598 /* ARM mode loads relative to PC are also offset by +8. Unlike
19599 branches, the Windows CE loader *does* expect the relocation
19600 to take this into account. */
19601 case BFD_RELOC_ARM_OFFSET_IMM:
19602 case BFD_RELOC_ARM_OFFSET_IMM8:
19603 case BFD_RELOC_ARM_HWLITERAL:
19604 case BFD_RELOC_ARM_LITERAL:
19605 case BFD_RELOC_ARM_CP_OFF_IMM:
19606 return base + 8;
19607
19608
19609 /* Other PC-relative relocations are un-offset. */
19610 default:
19611 return base;
19612 }
bfae80f2
RE
19613}
19614
c19d1205
ZW
19615/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
19616 Otherwise we have no need to default values of symbols. */
19617
19618symbolS *
19619md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 19620{
c19d1205
ZW
19621#ifdef OBJ_ELF
19622 if (name[0] == '_' && name[1] == 'G'
19623 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
19624 {
19625 if (!GOT_symbol)
19626 {
19627 if (symbol_find (name))
bd3ba5d1 19628 as_bad (_("GOT already in the symbol table"));
bfae80f2 19629
c19d1205
ZW
19630 GOT_symbol = symbol_new (name, undefined_section,
19631 (valueT) 0, & zero_address_frag);
19632 }
bfae80f2 19633
c19d1205 19634 return GOT_symbol;
bfae80f2 19635 }
c19d1205 19636#endif
bfae80f2 19637
c921be7d 19638 return NULL;
bfae80f2
RE
19639}
19640
55cf6793 19641/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
19642 computed as two separate immediate values, added together. We
19643 already know that this value cannot be computed by just one ARM
19644 instruction. */
19645
19646static unsigned int
19647validate_immediate_twopart (unsigned int val,
19648 unsigned int * highpart)
bfae80f2 19649{
c19d1205
ZW
19650 unsigned int a;
19651 unsigned int i;
bfae80f2 19652
c19d1205
ZW
19653 for (i = 0; i < 32; i += 2)
19654 if (((a = rotate_left (val, i)) & 0xff) != 0)
19655 {
19656 if (a & 0xff00)
19657 {
19658 if (a & ~ 0xffff)
19659 continue;
19660 * highpart = (a >> 8) | ((i + 24) << 7);
19661 }
19662 else if (a & 0xff0000)
19663 {
19664 if (a & 0xff000000)
19665 continue;
19666 * highpart = (a >> 16) | ((i + 16) << 7);
19667 }
19668 else
19669 {
9c2799c2 19670 gas_assert (a & 0xff000000);
c19d1205
ZW
19671 * highpart = (a >> 24) | ((i + 8) << 7);
19672 }
bfae80f2 19673
c19d1205
ZW
19674 return (a & 0xff) | (i << 7);
19675 }
bfae80f2 19676
c19d1205 19677 return FAIL;
bfae80f2
RE
19678}
19679
c19d1205
ZW
19680static int
19681validate_offset_imm (unsigned int val, int hwse)
19682{
19683 if ((hwse && val > 255) || val > 4095)
19684 return FAIL;
19685 return val;
19686}
bfae80f2 19687
55cf6793 19688/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
19689 negative immediate constant by altering the instruction. A bit of
19690 a hack really.
19691 MOV <-> MVN
19692 AND <-> BIC
19693 ADC <-> SBC
19694 by inverting the second operand, and
19695 ADD <-> SUB
19696 CMP <-> CMN
19697 by negating the second operand. */
bfae80f2 19698
c19d1205
ZW
19699static int
19700negate_data_op (unsigned long * instruction,
19701 unsigned long value)
bfae80f2 19702{
c19d1205
ZW
19703 int op, new_inst;
19704 unsigned long negated, inverted;
bfae80f2 19705
c19d1205
ZW
19706 negated = encode_arm_immediate (-value);
19707 inverted = encode_arm_immediate (~value);
bfae80f2 19708
c19d1205
ZW
19709 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
19710 switch (op)
bfae80f2 19711 {
c19d1205
ZW
19712 /* First negates. */
19713 case OPCODE_SUB: /* ADD <-> SUB */
19714 new_inst = OPCODE_ADD;
19715 value = negated;
19716 break;
bfae80f2 19717
c19d1205
ZW
19718 case OPCODE_ADD:
19719 new_inst = OPCODE_SUB;
19720 value = negated;
19721 break;
bfae80f2 19722
c19d1205
ZW
19723 case OPCODE_CMP: /* CMP <-> CMN */
19724 new_inst = OPCODE_CMN;
19725 value = negated;
19726 break;
bfae80f2 19727
c19d1205
ZW
19728 case OPCODE_CMN:
19729 new_inst = OPCODE_CMP;
19730 value = negated;
19731 break;
bfae80f2 19732
c19d1205
ZW
19733 /* Now Inverted ops. */
19734 case OPCODE_MOV: /* MOV <-> MVN */
19735 new_inst = OPCODE_MVN;
19736 value = inverted;
19737 break;
bfae80f2 19738
c19d1205
ZW
19739 case OPCODE_MVN:
19740 new_inst = OPCODE_MOV;
19741 value = inverted;
19742 break;
bfae80f2 19743
c19d1205
ZW
19744 case OPCODE_AND: /* AND <-> BIC */
19745 new_inst = OPCODE_BIC;
19746 value = inverted;
19747 break;
bfae80f2 19748
c19d1205
ZW
19749 case OPCODE_BIC:
19750 new_inst = OPCODE_AND;
19751 value = inverted;
19752 break;
bfae80f2 19753
c19d1205
ZW
19754 case OPCODE_ADC: /* ADC <-> SBC */
19755 new_inst = OPCODE_SBC;
19756 value = inverted;
19757 break;
bfae80f2 19758
c19d1205
ZW
19759 case OPCODE_SBC:
19760 new_inst = OPCODE_ADC;
19761 value = inverted;
19762 break;
bfae80f2 19763
c19d1205
ZW
19764 /* We cannot do anything. */
19765 default:
19766 return FAIL;
b99bd4ef
NC
19767 }
19768
c19d1205
ZW
19769 if (value == (unsigned) FAIL)
19770 return FAIL;
19771
19772 *instruction &= OPCODE_MASK;
19773 *instruction |= new_inst << DATA_OP_SHIFT;
19774 return value;
b99bd4ef
NC
19775}
19776
ef8d22e6
PB
19777/* Like negate_data_op, but for Thumb-2. */
19778
19779static unsigned int
16dd5e42 19780thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
19781{
19782 int op, new_inst;
19783 int rd;
16dd5e42 19784 unsigned int negated, inverted;
ef8d22e6
PB
19785
19786 negated = encode_thumb32_immediate (-value);
19787 inverted = encode_thumb32_immediate (~value);
19788
19789 rd = (*instruction >> 8) & 0xf;
19790 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
19791 switch (op)
19792 {
19793 /* ADD <-> SUB. Includes CMP <-> CMN. */
19794 case T2_OPCODE_SUB:
19795 new_inst = T2_OPCODE_ADD;
19796 value = negated;
19797 break;
19798
19799 case T2_OPCODE_ADD:
19800 new_inst = T2_OPCODE_SUB;
19801 value = negated;
19802 break;
19803
19804 /* ORR <-> ORN. Includes MOV <-> MVN. */
19805 case T2_OPCODE_ORR:
19806 new_inst = T2_OPCODE_ORN;
19807 value = inverted;
19808 break;
19809
19810 case T2_OPCODE_ORN:
19811 new_inst = T2_OPCODE_ORR;
19812 value = inverted;
19813 break;
19814
19815 /* AND <-> BIC. TST has no inverted equivalent. */
19816 case T2_OPCODE_AND:
19817 new_inst = T2_OPCODE_BIC;
19818 if (rd == 15)
19819 value = FAIL;
19820 else
19821 value = inverted;
19822 break;
19823
19824 case T2_OPCODE_BIC:
19825 new_inst = T2_OPCODE_AND;
19826 value = inverted;
19827 break;
19828
19829 /* ADC <-> SBC */
19830 case T2_OPCODE_ADC:
19831 new_inst = T2_OPCODE_SBC;
19832 value = inverted;
19833 break;
19834
19835 case T2_OPCODE_SBC:
19836 new_inst = T2_OPCODE_ADC;
19837 value = inverted;
19838 break;
19839
19840 /* We cannot do anything. */
19841 default:
19842 return FAIL;
19843 }
19844
16dd5e42 19845 if (value == (unsigned int)FAIL)
ef8d22e6
PB
19846 return FAIL;
19847
19848 *instruction &= T2_OPCODE_MASK;
19849 *instruction |= new_inst << T2_DATA_OP_SHIFT;
19850 return value;
19851}
19852
8f06b2d8
PB
19853/* Read a 32-bit thumb instruction from buf. */
19854static unsigned long
19855get_thumb32_insn (char * buf)
19856{
19857 unsigned long insn;
19858 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
19859 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19860
19861 return insn;
19862}
19863
a8bc6c78
PB
19864
19865/* We usually want to set the low bit on the address of thumb function
19866 symbols. In particular .word foo - . should have the low bit set.
19867 Generic code tries to fold the difference of two symbols to
19868 a constant. Prevent this and force a relocation when the first symbols
19869 is a thumb function. */
c921be7d
NC
19870
19871bfd_boolean
a8bc6c78
PB
19872arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
19873{
19874 if (op == O_subtract
19875 && l->X_op == O_symbol
19876 && r->X_op == O_symbol
19877 && THUMB_IS_FUNC (l->X_add_symbol))
19878 {
19879 l->X_op = O_subtract;
19880 l->X_op_symbol = r->X_add_symbol;
19881 l->X_add_number -= r->X_add_number;
c921be7d 19882 return TRUE;
a8bc6c78 19883 }
c921be7d 19884
a8bc6c78 19885 /* Process as normal. */
c921be7d 19886 return FALSE;
a8bc6c78
PB
19887}
19888
4a42ebbc
RR
19889/* Encode Thumb2 unconditional branches and calls. The encoding
19890 for the 2 are identical for the immediate values. */
19891
19892static void
19893encode_thumb2_b_bl_offset (char * buf, offsetT value)
19894{
19895#define T2I1I2MASK ((1 << 13) | (1 << 11))
19896 offsetT newval;
19897 offsetT newval2;
19898 addressT S, I1, I2, lo, hi;
19899
19900 S = (value >> 24) & 0x01;
19901 I1 = (value >> 23) & 0x01;
19902 I2 = (value >> 22) & 0x01;
19903 hi = (value >> 12) & 0x3ff;
19904 lo = (value >> 1) & 0x7ff;
19905 newval = md_chars_to_number (buf, THUMB_SIZE);
19906 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19907 newval |= (S << 10) | hi;
19908 newval2 &= ~T2I1I2MASK;
19909 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
19910 md_number_to_chars (buf, newval, THUMB_SIZE);
19911 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19912}
19913
c19d1205 19914void
55cf6793 19915md_apply_fix (fixS * fixP,
c19d1205
ZW
19916 valueT * valP,
19917 segT seg)
19918{
19919 offsetT value = * valP;
19920 offsetT newval;
19921 unsigned int newimm;
19922 unsigned long temp;
19923 int sign;
19924 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 19925
9c2799c2 19926 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 19927
c19d1205 19928 /* Note whether this will delete the relocation. */
4962c51a 19929
c19d1205
ZW
19930 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
19931 fixP->fx_done = 1;
b99bd4ef 19932
adbaf948 19933 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 19934 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
19935 for emit_reloc. */
19936 value &= 0xffffffff;
19937 value ^= 0x80000000;
5f4273c7 19938 value -= 0x80000000;
adbaf948
ZW
19939
19940 *valP = value;
c19d1205 19941 fixP->fx_addnumber = value;
b99bd4ef 19942
adbaf948
ZW
19943 /* Same treatment for fixP->fx_offset. */
19944 fixP->fx_offset &= 0xffffffff;
19945 fixP->fx_offset ^= 0x80000000;
19946 fixP->fx_offset -= 0x80000000;
19947
c19d1205 19948 switch (fixP->fx_r_type)
b99bd4ef 19949 {
c19d1205
ZW
19950 case BFD_RELOC_NONE:
19951 /* This will need to go in the object file. */
19952 fixP->fx_done = 0;
19953 break;
b99bd4ef 19954
c19d1205
ZW
19955 case BFD_RELOC_ARM_IMMEDIATE:
19956 /* We claim that this fixup has been processed here,
19957 even if in fact we generate an error because we do
19958 not have a reloc for it, so tc_gen_reloc will reject it. */
19959 fixP->fx_done = 1;
b99bd4ef 19960
77db8e2e 19961 if (fixP->fx_addsy)
b99bd4ef 19962 {
77db8e2e 19963 const char *msg = 0;
b99bd4ef 19964
77db8e2e
NC
19965 if (! S_IS_DEFINED (fixP->fx_addsy))
19966 msg = _("undefined symbol %s used as an immediate value");
19967 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
19968 msg = _("symbol %s is in a different section");
19969 else if (S_IS_WEAK (fixP->fx_addsy))
19970 msg = _("symbol %s is weak and may be overridden later");
19971
19972 if (msg)
19973 {
19974 as_bad_where (fixP->fx_file, fixP->fx_line,
19975 msg, S_GET_NAME (fixP->fx_addsy));
19976 break;
19977 }
42e5fcbf
AS
19978 }
19979
c19d1205
ZW
19980 newimm = encode_arm_immediate (value);
19981 temp = md_chars_to_number (buf, INSN_SIZE);
19982
19983 /* If the instruction will fail, see if we can fix things up by
19984 changing the opcode. */
19985 if (newimm == (unsigned int) FAIL
19986 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 19987 {
c19d1205
ZW
19988 as_bad_where (fixP->fx_file, fixP->fx_line,
19989 _("invalid constant (%lx) after fixup"),
19990 (unsigned long) value);
19991 break;
b99bd4ef 19992 }
b99bd4ef 19993
c19d1205
ZW
19994 newimm |= (temp & 0xfffff000);
19995 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19996 break;
b99bd4ef 19997
c19d1205
ZW
19998 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19999 {
20000 unsigned int highpart = 0;
20001 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 20002
77db8e2e 20003 if (fixP->fx_addsy)
42e5fcbf 20004 {
77db8e2e 20005 const char *msg = 0;
42e5fcbf 20006
77db8e2e
NC
20007 if (! S_IS_DEFINED (fixP->fx_addsy))
20008 msg = _("undefined symbol %s used as an immediate value");
20009 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20010 msg = _("symbol %s is in a different section");
20011 else if (S_IS_WEAK (fixP->fx_addsy))
20012 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 20013
77db8e2e
NC
20014 if (msg)
20015 {
20016 as_bad_where (fixP->fx_file, fixP->fx_line,
20017 msg, S_GET_NAME (fixP->fx_addsy));
20018 break;
20019 }
20020 }
20021
c19d1205
ZW
20022 newimm = encode_arm_immediate (value);
20023 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 20024
c19d1205
ZW
20025 /* If the instruction will fail, see if we can fix things up by
20026 changing the opcode. */
20027 if (newimm == (unsigned int) FAIL
20028 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
20029 {
20030 /* No ? OK - try using two ADD instructions to generate
20031 the value. */
20032 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 20033
c19d1205
ZW
20034 /* Yes - then make sure that the second instruction is
20035 also an add. */
20036 if (newimm != (unsigned int) FAIL)
20037 newinsn = temp;
20038 /* Still No ? Try using a negated value. */
20039 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
20040 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
20041 /* Otherwise - give up. */
20042 else
20043 {
20044 as_bad_where (fixP->fx_file, fixP->fx_line,
20045 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
20046 (long) value);
20047 break;
20048 }
b99bd4ef 20049
c19d1205
ZW
20050 /* Replace the first operand in the 2nd instruction (which
20051 is the PC) with the destination register. We have
20052 already added in the PC in the first instruction and we
20053 do not want to do it again. */
20054 newinsn &= ~ 0xf0000;
20055 newinsn |= ((newinsn & 0x0f000) << 4);
20056 }
b99bd4ef 20057
c19d1205
ZW
20058 newimm |= (temp & 0xfffff000);
20059 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 20060
c19d1205
ZW
20061 highpart |= (newinsn & 0xfffff000);
20062 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
20063 }
20064 break;
b99bd4ef 20065
c19d1205 20066 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
20067 if (!fixP->fx_done && seg->use_rela_p)
20068 value = 0;
20069
c19d1205
ZW
20070 case BFD_RELOC_ARM_LITERAL:
20071 sign = value >= 0;
b99bd4ef 20072
c19d1205
ZW
20073 if (value < 0)
20074 value = - value;
b99bd4ef 20075
c19d1205 20076 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 20077 {
c19d1205
ZW
20078 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
20079 as_bad_where (fixP->fx_file, fixP->fx_line,
20080 _("invalid literal constant: pool needs to be closer"));
20081 else
20082 as_bad_where (fixP->fx_file, fixP->fx_line,
20083 _("bad immediate value for offset (%ld)"),
20084 (long) value);
20085 break;
f03698e6
RE
20086 }
20087
c19d1205
ZW
20088 newval = md_chars_to_number (buf, INSN_SIZE);
20089 newval &= 0xff7ff000;
20090 newval |= value | (sign ? INDEX_UP : 0);
20091 md_number_to_chars (buf, newval, INSN_SIZE);
20092 break;
b99bd4ef 20093
c19d1205
ZW
20094 case BFD_RELOC_ARM_OFFSET_IMM8:
20095 case BFD_RELOC_ARM_HWLITERAL:
20096 sign = value >= 0;
b99bd4ef 20097
c19d1205
ZW
20098 if (value < 0)
20099 value = - value;
b99bd4ef 20100
c19d1205 20101 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 20102 {
c19d1205
ZW
20103 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
20104 as_bad_where (fixP->fx_file, fixP->fx_line,
20105 _("invalid literal constant: pool needs to be closer"));
20106 else
f9d4405b 20107 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
20108 (long) value);
20109 break;
b99bd4ef
NC
20110 }
20111
c19d1205
ZW
20112 newval = md_chars_to_number (buf, INSN_SIZE);
20113 newval &= 0xff7ff0f0;
20114 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
20115 md_number_to_chars (buf, newval, INSN_SIZE);
20116 break;
b99bd4ef 20117
c19d1205
ZW
20118 case BFD_RELOC_ARM_T32_OFFSET_U8:
20119 if (value < 0 || value > 1020 || value % 4 != 0)
20120 as_bad_where (fixP->fx_file, fixP->fx_line,
20121 _("bad immediate value for offset (%ld)"), (long) value);
20122 value /= 4;
b99bd4ef 20123
c19d1205 20124 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
20125 newval |= value;
20126 md_number_to_chars (buf+2, newval, THUMB_SIZE);
20127 break;
b99bd4ef 20128
c19d1205
ZW
20129 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20130 /* This is a complicated relocation used for all varieties of Thumb32
20131 load/store instruction with immediate offset:
20132
20133 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
20134 *4, optional writeback(W)
20135 (doubleword load/store)
20136
20137 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
20138 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
20139 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
20140 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
20141 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
20142
20143 Uppercase letters indicate bits that are already encoded at
20144 this point. Lowercase letters are our problem. For the
20145 second block of instructions, the secondary opcode nybble
20146 (bits 8..11) is present, and bit 23 is zero, even if this is
20147 a PC-relative operation. */
20148 newval = md_chars_to_number (buf, THUMB_SIZE);
20149 newval <<= 16;
20150 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 20151
c19d1205 20152 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 20153 {
c19d1205
ZW
20154 /* Doubleword load/store: 8-bit offset, scaled by 4. */
20155 if (value >= 0)
20156 newval |= (1 << 23);
20157 else
20158 value = -value;
20159 if (value % 4 != 0)
20160 {
20161 as_bad_where (fixP->fx_file, fixP->fx_line,
20162 _("offset not a multiple of 4"));
20163 break;
20164 }
20165 value /= 4;
216d22bc 20166 if (value > 0xff)
c19d1205
ZW
20167 {
20168 as_bad_where (fixP->fx_file, fixP->fx_line,
20169 _("offset out of range"));
20170 break;
20171 }
20172 newval &= ~0xff;
b99bd4ef 20173 }
c19d1205 20174 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 20175 {
c19d1205
ZW
20176 /* PC-relative, 12-bit offset. */
20177 if (value >= 0)
20178 newval |= (1 << 23);
20179 else
20180 value = -value;
216d22bc 20181 if (value > 0xfff)
c19d1205
ZW
20182 {
20183 as_bad_where (fixP->fx_file, fixP->fx_line,
20184 _("offset out of range"));
20185 break;
20186 }
20187 newval &= ~0xfff;
b99bd4ef 20188 }
c19d1205 20189 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 20190 {
c19d1205
ZW
20191 /* Writeback: 8-bit, +/- offset. */
20192 if (value >= 0)
20193 newval |= (1 << 9);
20194 else
20195 value = -value;
216d22bc 20196 if (value > 0xff)
c19d1205
ZW
20197 {
20198 as_bad_where (fixP->fx_file, fixP->fx_line,
20199 _("offset out of range"));
20200 break;
20201 }
20202 newval &= ~0xff;
b99bd4ef 20203 }
c19d1205 20204 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 20205 {
c19d1205 20206 /* T-instruction: positive 8-bit offset. */
216d22bc 20207 if (value < 0 || value > 0xff)
b99bd4ef 20208 {
c19d1205
ZW
20209 as_bad_where (fixP->fx_file, fixP->fx_line,
20210 _("offset out of range"));
20211 break;
b99bd4ef 20212 }
c19d1205
ZW
20213 newval &= ~0xff;
20214 newval |= value;
b99bd4ef
NC
20215 }
20216 else
b99bd4ef 20217 {
c19d1205
ZW
20218 /* Positive 12-bit or negative 8-bit offset. */
20219 int limit;
20220 if (value >= 0)
b99bd4ef 20221 {
c19d1205
ZW
20222 newval |= (1 << 23);
20223 limit = 0xfff;
20224 }
20225 else
20226 {
20227 value = -value;
20228 limit = 0xff;
20229 }
20230 if (value > limit)
20231 {
20232 as_bad_where (fixP->fx_file, fixP->fx_line,
20233 _("offset out of range"));
20234 break;
b99bd4ef 20235 }
c19d1205 20236 newval &= ~limit;
b99bd4ef 20237 }
b99bd4ef 20238
c19d1205
ZW
20239 newval |= value;
20240 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20241 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20242 break;
404ff6b5 20243
c19d1205
ZW
20244 case BFD_RELOC_ARM_SHIFT_IMM:
20245 newval = md_chars_to_number (buf, INSN_SIZE);
20246 if (((unsigned long) value) > 32
20247 || (value == 32
20248 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20249 {
20250 as_bad_where (fixP->fx_file, fixP->fx_line,
20251 _("shift expression is too large"));
20252 break;
20253 }
404ff6b5 20254
c19d1205
ZW
20255 if (value == 0)
20256 /* Shifts of zero must be done as lsl. */
20257 newval &= ~0x60;
20258 else if (value == 32)
20259 value = 0;
20260 newval &= 0xfffff07f;
20261 newval |= (value & 0x1f) << 7;
20262 md_number_to_chars (buf, newval, INSN_SIZE);
20263 break;
404ff6b5 20264
c19d1205 20265 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 20266 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 20267 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 20268 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
20269 /* We claim that this fixup has been processed here,
20270 even if in fact we generate an error because we do
20271 not have a reloc for it, so tc_gen_reloc will reject it. */
20272 fixP->fx_done = 1;
404ff6b5 20273
c19d1205
ZW
20274 if (fixP->fx_addsy
20275 && ! S_IS_DEFINED (fixP->fx_addsy))
20276 {
20277 as_bad_where (fixP->fx_file, fixP->fx_line,
20278 _("undefined symbol %s used as an immediate value"),
20279 S_GET_NAME (fixP->fx_addsy));
20280 break;
20281 }
404ff6b5 20282
c19d1205
ZW
20283 newval = md_chars_to_number (buf, THUMB_SIZE);
20284 newval <<= 16;
20285 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 20286
16805f35
PB
20287 newimm = FAIL;
20288 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20289 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
20290 {
20291 newimm = encode_thumb32_immediate (value);
20292 if (newimm == (unsigned int) FAIL)
20293 newimm = thumb32_negate_data_op (&newval, value);
20294 }
16805f35
PB
20295 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20296 && newimm == (unsigned int) FAIL)
92e90b6e 20297 {
16805f35
PB
20298 /* Turn add/sum into addw/subw. */
20299 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20300 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
20301 /* No flat 12-bit imm encoding for addsw/subsw. */
20302 if ((newval & 0x00100000) == 0)
e9f89963 20303 {
40f246e3
NC
20304 /* 12 bit immediate for addw/subw. */
20305 if (value < 0)
20306 {
20307 value = -value;
20308 newval ^= 0x00a00000;
20309 }
20310 if (value > 0xfff)
20311 newimm = (unsigned int) FAIL;
20312 else
20313 newimm = value;
e9f89963 20314 }
92e90b6e 20315 }
cc8a6dd0 20316
c19d1205 20317 if (newimm == (unsigned int)FAIL)
3631a3c8 20318 {
c19d1205
ZW
20319 as_bad_where (fixP->fx_file, fixP->fx_line,
20320 _("invalid constant (%lx) after fixup"),
20321 (unsigned long) value);
20322 break;
3631a3c8
NC
20323 }
20324
c19d1205
ZW
20325 newval |= (newimm & 0x800) << 15;
20326 newval |= (newimm & 0x700) << 4;
20327 newval |= (newimm & 0x0ff);
cc8a6dd0 20328
c19d1205
ZW
20329 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20330 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20331 break;
a737bd4d 20332
3eb17e6b 20333 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
20334 if (((unsigned long) value) > 0xffff)
20335 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 20336 _("invalid smc expression"));
2fc8bdac 20337 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20338 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20339 md_number_to_chars (buf, newval, INSN_SIZE);
20340 break;
a737bd4d 20341
c19d1205 20342 case BFD_RELOC_ARM_SWI:
adbaf948 20343 if (fixP->tc_fix_data != 0)
c19d1205
ZW
20344 {
20345 if (((unsigned long) value) > 0xff)
20346 as_bad_where (fixP->fx_file, fixP->fx_line,
20347 _("invalid swi expression"));
2fc8bdac 20348 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
20349 newval |= value;
20350 md_number_to_chars (buf, newval, THUMB_SIZE);
20351 }
20352 else
20353 {
20354 if (((unsigned long) value) > 0x00ffffff)
20355 as_bad_where (fixP->fx_file, fixP->fx_line,
20356 _("invalid swi expression"));
2fc8bdac 20357 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20358 newval |= value;
20359 md_number_to_chars (buf, newval, INSN_SIZE);
20360 }
20361 break;
a737bd4d 20362
c19d1205
ZW
20363 case BFD_RELOC_ARM_MULTI:
20364 if (((unsigned long) value) > 0xffff)
20365 as_bad_where (fixP->fx_file, fixP->fx_line,
20366 _("invalid expression in load/store multiple"));
20367 newval = value | md_chars_to_number (buf, INSN_SIZE);
20368 md_number_to_chars (buf, newval, INSN_SIZE);
20369 break;
a737bd4d 20370
c19d1205 20371#ifdef OBJ_ELF
39b41c9c 20372 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
20373
20374 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20375 && fixP->fx_addsy
20376 && !S_IS_EXTERNAL (fixP->fx_addsy)
20377 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20378 && THUMB_IS_FUNC (fixP->fx_addsy))
20379 /* Flip the bl to blx. This is a simple flip
20380 bit here because we generate PCREL_CALL for
20381 unconditional bls. */
20382 {
20383 newval = md_chars_to_number (buf, INSN_SIZE);
20384 newval = newval | 0x10000000;
20385 md_number_to_chars (buf, newval, INSN_SIZE);
20386 temp = 1;
20387 fixP->fx_done = 1;
20388 }
39b41c9c
PB
20389 else
20390 temp = 3;
20391 goto arm_branch_common;
20392
20393 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
20394 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20395 && fixP->fx_addsy
20396 && !S_IS_EXTERNAL (fixP->fx_addsy)
20397 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20398 && THUMB_IS_FUNC (fixP->fx_addsy))
20399 {
20400 /* This would map to a bl<cond>, b<cond>,
20401 b<always> to a Thumb function. We
20402 need to force a relocation for this particular
20403 case. */
20404 newval = md_chars_to_number (buf, INSN_SIZE);
20405 fixP->fx_done = 0;
20406 }
20407
2fc8bdac 20408 case BFD_RELOC_ARM_PLT32:
c19d1205 20409#endif
39b41c9c
PB
20410 case BFD_RELOC_ARM_PCREL_BRANCH:
20411 temp = 3;
20412 goto arm_branch_common;
a737bd4d 20413
39b41c9c 20414 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 20415
39b41c9c 20416 temp = 1;
267bf995
RR
20417 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20418 && fixP->fx_addsy
20419 && !S_IS_EXTERNAL (fixP->fx_addsy)
20420 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20421 && ARM_IS_FUNC (fixP->fx_addsy))
20422 {
20423 /* Flip the blx to a bl and warn. */
20424 const char *name = S_GET_NAME (fixP->fx_addsy);
20425 newval = 0xeb000000;
20426 as_warn_where (fixP->fx_file, fixP->fx_line,
20427 _("blx to '%s' an ARM ISA state function changed to bl"),
20428 name);
20429 md_number_to_chars (buf, newval, INSN_SIZE);
20430 temp = 3;
20431 fixP->fx_done = 1;
20432 }
20433
20434#ifdef OBJ_ELF
20435 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20436 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20437#endif
20438
39b41c9c 20439 arm_branch_common:
c19d1205 20440 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
20441 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20442 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20443 also be be clear. */
20444 if (value & temp)
c19d1205 20445 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
20446 _("misaligned branch destination"));
20447 if ((value & (offsetT)0xfe000000) != (offsetT)0
20448 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20449 as_bad_where (fixP->fx_file, fixP->fx_line,
20450 _("branch out of range"));
a737bd4d 20451
2fc8bdac 20452 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20453 {
2fc8bdac
ZW
20454 newval = md_chars_to_number (buf, INSN_SIZE);
20455 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
20456 /* Set the H bit on BLX instructions. */
20457 if (temp == 1)
20458 {
20459 if (value & 2)
20460 newval |= 0x01000000;
20461 else
20462 newval &= ~0x01000000;
20463 }
2fc8bdac 20464 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 20465 }
c19d1205 20466 break;
a737bd4d 20467
25fe350b
MS
20468 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20469 /* CBZ can only branch forward. */
a737bd4d 20470
738755b0
MS
20471 /* Attempts to use CBZ to branch to the next instruction
20472 (which, strictly speaking, are prohibited) will be turned into
20473 no-ops.
20474
20475 FIXME: It may be better to remove the instruction completely and
20476 perform relaxation. */
20477 if (value == -2)
2fc8bdac
ZW
20478 {
20479 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 20480 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
20481 md_number_to_chars (buf, newval, THUMB_SIZE);
20482 }
738755b0
MS
20483 else
20484 {
20485 if (value & ~0x7e)
20486 as_bad_where (fixP->fx_file, fixP->fx_line,
20487 _("branch out of range"));
20488
20489 if (fixP->fx_done || !seg->use_rela_p)
20490 {
20491 newval = md_chars_to_number (buf, THUMB_SIZE);
20492 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20493 md_number_to_chars (buf, newval, THUMB_SIZE);
20494 }
20495 }
c19d1205 20496 break;
a737bd4d 20497
c19d1205 20498 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
20499 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20500 as_bad_where (fixP->fx_file, fixP->fx_line,
20501 _("branch out of range"));
a737bd4d 20502
2fc8bdac
ZW
20503 if (fixP->fx_done || !seg->use_rela_p)
20504 {
20505 newval = md_chars_to_number (buf, THUMB_SIZE);
20506 newval |= (value & 0x1ff) >> 1;
20507 md_number_to_chars (buf, newval, THUMB_SIZE);
20508 }
c19d1205 20509 break;
a737bd4d 20510
c19d1205 20511 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
20512 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20513 as_bad_where (fixP->fx_file, fixP->fx_line,
20514 _("branch out of range"));
a737bd4d 20515
2fc8bdac
ZW
20516 if (fixP->fx_done || !seg->use_rela_p)
20517 {
20518 newval = md_chars_to_number (buf, THUMB_SIZE);
20519 newval |= (value & 0xfff) >> 1;
20520 md_number_to_chars (buf, newval, THUMB_SIZE);
20521 }
c19d1205 20522 break;
a737bd4d 20523
c19d1205 20524 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
20525 if (fixP->fx_addsy
20526 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20527 && !S_IS_EXTERNAL (fixP->fx_addsy)
20528 && S_IS_DEFINED (fixP->fx_addsy)
20529 && ARM_IS_FUNC (fixP->fx_addsy)
20530 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20531 {
20532 /* Force a relocation for a branch 20 bits wide. */
20533 fixP->fx_done = 0;
20534 }
2fc8bdac
ZW
20535 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20536 as_bad_where (fixP->fx_file, fixP->fx_line,
20537 _("conditional branch out of range"));
404ff6b5 20538
2fc8bdac
ZW
20539 if (fixP->fx_done || !seg->use_rela_p)
20540 {
20541 offsetT newval2;
20542 addressT S, J1, J2, lo, hi;
404ff6b5 20543
2fc8bdac
ZW
20544 S = (value & 0x00100000) >> 20;
20545 J2 = (value & 0x00080000) >> 19;
20546 J1 = (value & 0x00040000) >> 18;
20547 hi = (value & 0x0003f000) >> 12;
20548 lo = (value & 0x00000ffe) >> 1;
6c43fab6 20549
2fc8bdac
ZW
20550 newval = md_chars_to_number (buf, THUMB_SIZE);
20551 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20552 newval |= (S << 10) | hi;
20553 newval2 |= (J1 << 13) | (J2 << 11) | lo;
20554 md_number_to_chars (buf, newval, THUMB_SIZE);
20555 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20556 }
c19d1205 20557 break;
6c43fab6 20558
c19d1205 20559 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
20560
20561 /* If there is a blx from a thumb state function to
20562 another thumb function flip this to a bl and warn
20563 about it. */
20564
20565 if (fixP->fx_addsy
20566 && S_IS_DEFINED (fixP->fx_addsy)
20567 && !S_IS_EXTERNAL (fixP->fx_addsy)
20568 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20569 && THUMB_IS_FUNC (fixP->fx_addsy))
20570 {
20571 const char *name = S_GET_NAME (fixP->fx_addsy);
20572 as_warn_where (fixP->fx_file, fixP->fx_line,
20573 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
20574 name);
20575 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20576 newval = newval | 0x1000;
20577 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20578 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20579 fixP->fx_done = 1;
20580 }
20581
20582
20583 goto thumb_bl_common;
20584
c19d1205 20585 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
20586
20587 /* A bl from Thumb state ISA to an internal ARM state function
20588 is converted to a blx. */
20589 if (fixP->fx_addsy
20590 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20591 && !S_IS_EXTERNAL (fixP->fx_addsy)
20592 && S_IS_DEFINED (fixP->fx_addsy)
20593 && ARM_IS_FUNC (fixP->fx_addsy)
20594 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20595 {
20596 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20597 newval = newval & ~0x1000;
20598 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20599 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
20600 fixP->fx_done = 1;
20601 }
20602
20603 thumb_bl_common:
20604
20605#ifdef OBJ_ELF
20606 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
20607 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20608 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20609#endif
20610
2fc8bdac
ZW
20611 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20612 /* For a BLX instruction, make sure that the relocation is rounded up
20613 to a word boundary. This follows the semantics of the instruction
20614 which specifies that bit 1 of the target address will come from bit
20615 1 of the base address. */
20616 value = (value + 1) & ~ 1;
404ff6b5 20617
2fc8bdac 20618
4a42ebbc
RR
20619 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
20620 {
20621 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
20622 {
20623 as_bad_where (fixP->fx_file, fixP->fx_line,
20624 _("branch out of range"));
20625 }
20626 else if ((value & ~0x1ffffff)
20627 && ((value & ~0x1ffffff) != ~0x1ffffff))
20628 {
20629 as_bad_where (fixP->fx_file, fixP->fx_line,
20630 _("Thumb2 branch out of range"));
20631 }
c19d1205 20632 }
4a42ebbc
RR
20633
20634 if (fixP->fx_done || !seg->use_rela_p)
20635 encode_thumb2_b_bl_offset (buf, value);
20636
c19d1205 20637 break;
404ff6b5 20638
c19d1205 20639 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
20640 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
20641 as_bad_where (fixP->fx_file, fixP->fx_line,
20642 _("branch out of range"));
6c43fab6 20643
2fc8bdac 20644 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 20645 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 20646
2fc8bdac 20647 break;
a737bd4d 20648
2fc8bdac
ZW
20649 case BFD_RELOC_8:
20650 if (fixP->fx_done || !seg->use_rela_p)
20651 md_number_to_chars (buf, value, 1);
c19d1205 20652 break;
a737bd4d 20653
c19d1205 20654 case BFD_RELOC_16:
2fc8bdac 20655 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20656 md_number_to_chars (buf, value, 2);
c19d1205 20657 break;
a737bd4d 20658
c19d1205
ZW
20659#ifdef OBJ_ELF
20660 case BFD_RELOC_ARM_TLS_GD32:
20661 case BFD_RELOC_ARM_TLS_LE32:
20662 case BFD_RELOC_ARM_TLS_IE32:
20663 case BFD_RELOC_ARM_TLS_LDM32:
20664 case BFD_RELOC_ARM_TLS_LDO32:
20665 S_SET_THREAD_LOCAL (fixP->fx_addsy);
20666 /* fall through */
6c43fab6 20667
c19d1205
ZW
20668 case BFD_RELOC_ARM_GOT32:
20669 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
20670 if (fixP->fx_done || !seg->use_rela_p)
20671 md_number_to_chars (buf, 0, 4);
c19d1205 20672 break;
b43420e6
NC
20673
20674 case BFD_RELOC_ARM_GOT_PREL:
20675 if (fixP->fx_done || !seg->use_rela_p)
20676 md_number_to_chars (buf, value, 4);
20677 break;
20678
9a6f4e97
NS
20679 case BFD_RELOC_ARM_TARGET2:
20680 /* TARGET2 is not partial-inplace, so we need to write the
20681 addend here for REL targets, because it won't be written out
20682 during reloc processing later. */
20683 if (fixP->fx_done || !seg->use_rela_p)
20684 md_number_to_chars (buf, fixP->fx_offset, 4);
20685 break;
c19d1205 20686#endif
6c43fab6 20687
c19d1205
ZW
20688 case BFD_RELOC_RVA:
20689 case BFD_RELOC_32:
20690 case BFD_RELOC_ARM_TARGET1:
20691 case BFD_RELOC_ARM_ROSEGREL32:
20692 case BFD_RELOC_ARM_SBREL32:
20693 case BFD_RELOC_32_PCREL:
f0927246
NC
20694#ifdef TE_PE
20695 case BFD_RELOC_32_SECREL:
20696#endif
2fc8bdac 20697 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
20698#ifdef TE_WINCE
20699 /* For WinCE we only do this for pcrel fixups. */
20700 if (fixP->fx_done || fixP->fx_pcrel)
20701#endif
20702 md_number_to_chars (buf, value, 4);
c19d1205 20703 break;
6c43fab6 20704
c19d1205
ZW
20705#ifdef OBJ_ELF
20706 case BFD_RELOC_ARM_PREL31:
2fc8bdac 20707 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
20708 {
20709 newval = md_chars_to_number (buf, 4) & 0x80000000;
20710 if ((value ^ (value >> 1)) & 0x40000000)
20711 {
20712 as_bad_where (fixP->fx_file, fixP->fx_line,
20713 _("rel31 relocation overflow"));
20714 }
20715 newval |= value & 0x7fffffff;
20716 md_number_to_chars (buf, newval, 4);
20717 }
20718 break;
c19d1205 20719#endif
a737bd4d 20720
c19d1205 20721 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 20722 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
20723 if (value < -1023 || value > 1023 || (value & 3))
20724 as_bad_where (fixP->fx_file, fixP->fx_line,
20725 _("co-processor offset out of range"));
20726 cp_off_common:
20727 sign = value >= 0;
20728 if (value < 0)
20729 value = -value;
8f06b2d8
PB
20730 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20731 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20732 newval = md_chars_to_number (buf, INSN_SIZE);
20733 else
20734 newval = get_thumb32_insn (buf);
20735 newval &= 0xff7fff00;
c19d1205 20736 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
20737 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20738 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20739 md_number_to_chars (buf, newval, INSN_SIZE);
20740 else
20741 put_thumb32_insn (buf, newval);
c19d1205 20742 break;
a737bd4d 20743
c19d1205 20744 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 20745 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
20746 if (value < -255 || value > 255)
20747 as_bad_where (fixP->fx_file, fixP->fx_line,
20748 _("co-processor offset out of range"));
df7849c5 20749 value *= 4;
c19d1205 20750 goto cp_off_common;
6c43fab6 20751
c19d1205
ZW
20752 case BFD_RELOC_ARM_THUMB_OFFSET:
20753 newval = md_chars_to_number (buf, THUMB_SIZE);
20754 /* Exactly what ranges, and where the offset is inserted depends
20755 on the type of instruction, we can establish this from the
20756 top 4 bits. */
20757 switch (newval >> 12)
20758 {
20759 case 4: /* PC load. */
20760 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
20761 forced to zero for these loads; md_pcrel_from has already
20762 compensated for this. */
20763 if (value & 3)
20764 as_bad_where (fixP->fx_file, fixP->fx_line,
20765 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
20766 (((unsigned long) fixP->fx_frag->fr_address
20767 + (unsigned long) fixP->fx_where) & ~3)
20768 + (unsigned long) value);
a737bd4d 20769
c19d1205
ZW
20770 if (value & ~0x3fc)
20771 as_bad_where (fixP->fx_file, fixP->fx_line,
20772 _("invalid offset, value too big (0x%08lX)"),
20773 (long) value);
a737bd4d 20774
c19d1205
ZW
20775 newval |= value >> 2;
20776 break;
a737bd4d 20777
c19d1205
ZW
20778 case 9: /* SP load/store. */
20779 if (value & ~0x3fc)
20780 as_bad_where (fixP->fx_file, fixP->fx_line,
20781 _("invalid offset, value too big (0x%08lX)"),
20782 (long) value);
20783 newval |= value >> 2;
20784 break;
6c43fab6 20785
c19d1205
ZW
20786 case 6: /* Word load/store. */
20787 if (value & ~0x7c)
20788 as_bad_where (fixP->fx_file, fixP->fx_line,
20789 _("invalid offset, value too big (0x%08lX)"),
20790 (long) value);
20791 newval |= value << 4; /* 6 - 2. */
20792 break;
a737bd4d 20793
c19d1205
ZW
20794 case 7: /* Byte load/store. */
20795 if (value & ~0x1f)
20796 as_bad_where (fixP->fx_file, fixP->fx_line,
20797 _("invalid offset, value too big (0x%08lX)"),
20798 (long) value);
20799 newval |= value << 6;
20800 break;
a737bd4d 20801
c19d1205
ZW
20802 case 8: /* Halfword load/store. */
20803 if (value & ~0x3e)
20804 as_bad_where (fixP->fx_file, fixP->fx_line,
20805 _("invalid offset, value too big (0x%08lX)"),
20806 (long) value);
20807 newval |= value << 5; /* 6 - 1. */
20808 break;
a737bd4d 20809
c19d1205
ZW
20810 default:
20811 as_bad_where (fixP->fx_file, fixP->fx_line,
20812 "Unable to process relocation for thumb opcode: %lx",
20813 (unsigned long) newval);
20814 break;
20815 }
20816 md_number_to_chars (buf, newval, THUMB_SIZE);
20817 break;
a737bd4d 20818
c19d1205
ZW
20819 case BFD_RELOC_ARM_THUMB_ADD:
20820 /* This is a complicated relocation, since we use it for all of
20821 the following immediate relocations:
a737bd4d 20822
c19d1205
ZW
20823 3bit ADD/SUB
20824 8bit ADD/SUB
20825 9bit ADD/SUB SP word-aligned
20826 10bit ADD PC/SP word-aligned
a737bd4d 20827
c19d1205
ZW
20828 The type of instruction being processed is encoded in the
20829 instruction field:
a737bd4d 20830
c19d1205
ZW
20831 0x8000 SUB
20832 0x00F0 Rd
20833 0x000F Rs
20834 */
20835 newval = md_chars_to_number (buf, THUMB_SIZE);
20836 {
20837 int rd = (newval >> 4) & 0xf;
20838 int rs = newval & 0xf;
20839 int subtract = !!(newval & 0x8000);
a737bd4d 20840
c19d1205
ZW
20841 /* Check for HI regs, only very restricted cases allowed:
20842 Adjusting SP, and using PC or SP to get an address. */
20843 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
20844 || (rs > 7 && rs != REG_SP && rs != REG_PC))
20845 as_bad_where (fixP->fx_file, fixP->fx_line,
20846 _("invalid Hi register with immediate"));
a737bd4d 20847
c19d1205
ZW
20848 /* If value is negative, choose the opposite instruction. */
20849 if (value < 0)
20850 {
20851 value = -value;
20852 subtract = !subtract;
20853 if (value < 0)
20854 as_bad_where (fixP->fx_file, fixP->fx_line,
20855 _("immediate value out of range"));
20856 }
a737bd4d 20857
c19d1205
ZW
20858 if (rd == REG_SP)
20859 {
20860 if (value & ~0x1fc)
20861 as_bad_where (fixP->fx_file, fixP->fx_line,
20862 _("invalid immediate for stack address calculation"));
20863 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
20864 newval |= value >> 2;
20865 }
20866 else if (rs == REG_PC || rs == REG_SP)
20867 {
20868 if (subtract || value & ~0x3fc)
20869 as_bad_where (fixP->fx_file, fixP->fx_line,
20870 _("invalid immediate for address calculation (value = 0x%08lX)"),
20871 (unsigned long) value);
20872 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
20873 newval |= rd << 8;
20874 newval |= value >> 2;
20875 }
20876 else if (rs == rd)
20877 {
20878 if (value & ~0xff)
20879 as_bad_where (fixP->fx_file, fixP->fx_line,
20880 _("immediate value out of range"));
20881 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
20882 newval |= (rd << 8) | value;
20883 }
20884 else
20885 {
20886 if (value & ~0x7)
20887 as_bad_where (fixP->fx_file, fixP->fx_line,
20888 _("immediate value out of range"));
20889 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
20890 newval |= rd | (rs << 3) | (value << 6);
20891 }
20892 }
20893 md_number_to_chars (buf, newval, THUMB_SIZE);
20894 break;
a737bd4d 20895
c19d1205
ZW
20896 case BFD_RELOC_ARM_THUMB_IMM:
20897 newval = md_chars_to_number (buf, THUMB_SIZE);
20898 if (value < 0 || value > 255)
20899 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 20900 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
20901 (long) value);
20902 newval |= value;
20903 md_number_to_chars (buf, newval, THUMB_SIZE);
20904 break;
a737bd4d 20905
c19d1205
ZW
20906 case BFD_RELOC_ARM_THUMB_SHIFT:
20907 /* 5bit shift value (0..32). LSL cannot take 32. */
20908 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
20909 temp = newval & 0xf800;
20910 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
20911 as_bad_where (fixP->fx_file, fixP->fx_line,
20912 _("invalid shift value: %ld"), (long) value);
20913 /* Shifts of zero must be encoded as LSL. */
20914 if (value == 0)
20915 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
20916 /* Shifts of 32 are encoded as zero. */
20917 else if (value == 32)
20918 value = 0;
20919 newval |= value << 6;
20920 md_number_to_chars (buf, newval, THUMB_SIZE);
20921 break;
a737bd4d 20922
c19d1205
ZW
20923 case BFD_RELOC_VTABLE_INHERIT:
20924 case BFD_RELOC_VTABLE_ENTRY:
20925 fixP->fx_done = 0;
20926 return;
6c43fab6 20927
b6895b4f
PB
20928 case BFD_RELOC_ARM_MOVW:
20929 case BFD_RELOC_ARM_MOVT:
20930 case BFD_RELOC_ARM_THUMB_MOVW:
20931 case BFD_RELOC_ARM_THUMB_MOVT:
20932 if (fixP->fx_done || !seg->use_rela_p)
20933 {
20934 /* REL format relocations are limited to a 16-bit addend. */
20935 if (!fixP->fx_done)
20936 {
39623e12 20937 if (value < -0x8000 || value > 0x7fff)
b6895b4f 20938 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 20939 _("offset out of range"));
b6895b4f
PB
20940 }
20941 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20942 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20943 {
20944 value >>= 16;
20945 }
20946
20947 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20948 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20949 {
20950 newval = get_thumb32_insn (buf);
20951 newval &= 0xfbf08f00;
20952 newval |= (value & 0xf000) << 4;
20953 newval |= (value & 0x0800) << 15;
20954 newval |= (value & 0x0700) << 4;
20955 newval |= (value & 0x00ff);
20956 put_thumb32_insn (buf, newval);
20957 }
20958 else
20959 {
20960 newval = md_chars_to_number (buf, 4);
20961 newval &= 0xfff0f000;
20962 newval |= value & 0x0fff;
20963 newval |= (value & 0xf000) << 4;
20964 md_number_to_chars (buf, newval, 4);
20965 }
20966 }
20967 return;
20968
4962c51a
MS
20969 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20970 case BFD_RELOC_ARM_ALU_PC_G0:
20971 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20972 case BFD_RELOC_ARM_ALU_PC_G1:
20973 case BFD_RELOC_ARM_ALU_PC_G2:
20974 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20975 case BFD_RELOC_ARM_ALU_SB_G0:
20976 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20977 case BFD_RELOC_ARM_ALU_SB_G1:
20978 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 20979 gas_assert (!fixP->fx_done);
4962c51a
MS
20980 if (!seg->use_rela_p)
20981 {
20982 bfd_vma insn;
20983 bfd_vma encoded_addend;
20984 bfd_vma addend_abs = abs (value);
20985
20986 /* Check that the absolute value of the addend can be
20987 expressed as an 8-bit constant plus a rotation. */
20988 encoded_addend = encode_arm_immediate (addend_abs);
20989 if (encoded_addend == (unsigned int) FAIL)
20990 as_bad_where (fixP->fx_file, fixP->fx_line,
20991 _("the offset 0x%08lX is not representable"),
495bde8e 20992 (unsigned long) addend_abs);
4962c51a
MS
20993
20994 /* Extract the instruction. */
20995 insn = md_chars_to_number (buf, INSN_SIZE);
20996
20997 /* If the addend is positive, use an ADD instruction.
20998 Otherwise use a SUB. Take care not to destroy the S bit. */
20999 insn &= 0xff1fffff;
21000 if (value < 0)
21001 insn |= 1 << 22;
21002 else
21003 insn |= 1 << 23;
21004
21005 /* Place the encoded addend into the first 12 bits of the
21006 instruction. */
21007 insn &= 0xfffff000;
21008 insn |= encoded_addend;
5f4273c7
NC
21009
21010 /* Update the instruction. */
4962c51a
MS
21011 md_number_to_chars (buf, insn, INSN_SIZE);
21012 }
21013 break;
21014
21015 case BFD_RELOC_ARM_LDR_PC_G0:
21016 case BFD_RELOC_ARM_LDR_PC_G1:
21017 case BFD_RELOC_ARM_LDR_PC_G2:
21018 case BFD_RELOC_ARM_LDR_SB_G0:
21019 case BFD_RELOC_ARM_LDR_SB_G1:
21020 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 21021 gas_assert (!fixP->fx_done);
4962c51a
MS
21022 if (!seg->use_rela_p)
21023 {
21024 bfd_vma insn;
21025 bfd_vma addend_abs = abs (value);
21026
21027 /* Check that the absolute value of the addend can be
21028 encoded in 12 bits. */
21029 if (addend_abs >= 0x1000)
21030 as_bad_where (fixP->fx_file, fixP->fx_line,
21031 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 21032 (unsigned long) addend_abs);
4962c51a
MS
21033
21034 /* Extract the instruction. */
21035 insn = md_chars_to_number (buf, INSN_SIZE);
21036
21037 /* If the addend is negative, clear bit 23 of the instruction.
21038 Otherwise set it. */
21039 if (value < 0)
21040 insn &= ~(1 << 23);
21041 else
21042 insn |= 1 << 23;
21043
21044 /* Place the absolute value of the addend into the first 12 bits
21045 of the instruction. */
21046 insn &= 0xfffff000;
21047 insn |= addend_abs;
5f4273c7
NC
21048
21049 /* Update the instruction. */
4962c51a
MS
21050 md_number_to_chars (buf, insn, INSN_SIZE);
21051 }
21052 break;
21053
21054 case BFD_RELOC_ARM_LDRS_PC_G0:
21055 case BFD_RELOC_ARM_LDRS_PC_G1:
21056 case BFD_RELOC_ARM_LDRS_PC_G2:
21057 case BFD_RELOC_ARM_LDRS_SB_G0:
21058 case BFD_RELOC_ARM_LDRS_SB_G1:
21059 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 21060 gas_assert (!fixP->fx_done);
4962c51a
MS
21061 if (!seg->use_rela_p)
21062 {
21063 bfd_vma insn;
21064 bfd_vma addend_abs = abs (value);
21065
21066 /* Check that the absolute value of the addend can be
21067 encoded in 8 bits. */
21068 if (addend_abs >= 0x100)
21069 as_bad_where (fixP->fx_file, fixP->fx_line,
21070 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 21071 (unsigned long) addend_abs);
4962c51a
MS
21072
21073 /* Extract the instruction. */
21074 insn = md_chars_to_number (buf, INSN_SIZE);
21075
21076 /* If the addend is negative, clear bit 23 of the instruction.
21077 Otherwise set it. */
21078 if (value < 0)
21079 insn &= ~(1 << 23);
21080 else
21081 insn |= 1 << 23;
21082
21083 /* Place the first four bits of the absolute value of the addend
21084 into the first 4 bits of the instruction, and the remaining
21085 four into bits 8 .. 11. */
21086 insn &= 0xfffff0f0;
21087 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
21088
21089 /* Update the instruction. */
4962c51a
MS
21090 md_number_to_chars (buf, insn, INSN_SIZE);
21091 }
21092 break;
21093
21094 case BFD_RELOC_ARM_LDC_PC_G0:
21095 case BFD_RELOC_ARM_LDC_PC_G1:
21096 case BFD_RELOC_ARM_LDC_PC_G2:
21097 case BFD_RELOC_ARM_LDC_SB_G0:
21098 case BFD_RELOC_ARM_LDC_SB_G1:
21099 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 21100 gas_assert (!fixP->fx_done);
4962c51a
MS
21101 if (!seg->use_rela_p)
21102 {
21103 bfd_vma insn;
21104 bfd_vma addend_abs = abs (value);
21105
21106 /* Check that the absolute value of the addend is a multiple of
21107 four and, when divided by four, fits in 8 bits. */
21108 if (addend_abs & 0x3)
21109 as_bad_where (fixP->fx_file, fixP->fx_line,
21110 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 21111 (unsigned long) addend_abs);
4962c51a
MS
21112
21113 if ((addend_abs >> 2) > 0xff)
21114 as_bad_where (fixP->fx_file, fixP->fx_line,
21115 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 21116 (unsigned long) addend_abs);
4962c51a
MS
21117
21118 /* Extract the instruction. */
21119 insn = md_chars_to_number (buf, INSN_SIZE);
21120
21121 /* If the addend is negative, clear bit 23 of the instruction.
21122 Otherwise set it. */
21123 if (value < 0)
21124 insn &= ~(1 << 23);
21125 else
21126 insn |= 1 << 23;
21127
21128 /* Place the addend (divided by four) into the first eight
21129 bits of the instruction. */
21130 insn &= 0xfffffff0;
21131 insn |= addend_abs >> 2;
5f4273c7
NC
21132
21133 /* Update the instruction. */
4962c51a
MS
21134 md_number_to_chars (buf, insn, INSN_SIZE);
21135 }
21136 break;
21137
845b51d6
PB
21138 case BFD_RELOC_ARM_V4BX:
21139 /* This will need to go in the object file. */
21140 fixP->fx_done = 0;
21141 break;
21142
c19d1205
ZW
21143 case BFD_RELOC_UNUSED:
21144 default:
21145 as_bad_where (fixP->fx_file, fixP->fx_line,
21146 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
21147 }
6c43fab6
RE
21148}
21149
c19d1205
ZW
21150/* Translate internal representation of relocation info to BFD target
21151 format. */
a737bd4d 21152
c19d1205 21153arelent *
00a97672 21154tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 21155{
c19d1205
ZW
21156 arelent * reloc;
21157 bfd_reloc_code_real_type code;
a737bd4d 21158
21d799b5 21159 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 21160
21d799b5 21161 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
21162 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
21163 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 21164
2fc8bdac 21165 if (fixp->fx_pcrel)
00a97672
RS
21166 {
21167 if (section->use_rela_p)
21168 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
21169 else
21170 fixp->fx_offset = reloc->address;
21171 }
c19d1205 21172 reloc->addend = fixp->fx_offset;
a737bd4d 21173
c19d1205 21174 switch (fixp->fx_r_type)
a737bd4d 21175 {
c19d1205
ZW
21176 case BFD_RELOC_8:
21177 if (fixp->fx_pcrel)
21178 {
21179 code = BFD_RELOC_8_PCREL;
21180 break;
21181 }
a737bd4d 21182
c19d1205
ZW
21183 case BFD_RELOC_16:
21184 if (fixp->fx_pcrel)
21185 {
21186 code = BFD_RELOC_16_PCREL;
21187 break;
21188 }
6c43fab6 21189
c19d1205
ZW
21190 case BFD_RELOC_32:
21191 if (fixp->fx_pcrel)
21192 {
21193 code = BFD_RELOC_32_PCREL;
21194 break;
21195 }
a737bd4d 21196
b6895b4f
PB
21197 case BFD_RELOC_ARM_MOVW:
21198 if (fixp->fx_pcrel)
21199 {
21200 code = BFD_RELOC_ARM_MOVW_PCREL;
21201 break;
21202 }
21203
21204 case BFD_RELOC_ARM_MOVT:
21205 if (fixp->fx_pcrel)
21206 {
21207 code = BFD_RELOC_ARM_MOVT_PCREL;
21208 break;
21209 }
21210
21211 case BFD_RELOC_ARM_THUMB_MOVW:
21212 if (fixp->fx_pcrel)
21213 {
21214 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21215 break;
21216 }
21217
21218 case BFD_RELOC_ARM_THUMB_MOVT:
21219 if (fixp->fx_pcrel)
21220 {
21221 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21222 break;
21223 }
21224
c19d1205
ZW
21225 case BFD_RELOC_NONE:
21226 case BFD_RELOC_ARM_PCREL_BRANCH:
21227 case BFD_RELOC_ARM_PCREL_BLX:
21228 case BFD_RELOC_RVA:
21229 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21230 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21231 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21232 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21233 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21234 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
21235 case BFD_RELOC_VTABLE_ENTRY:
21236 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
21237#ifdef TE_PE
21238 case BFD_RELOC_32_SECREL:
21239#endif
c19d1205
ZW
21240 code = fixp->fx_r_type;
21241 break;
a737bd4d 21242
00adf2d4
JB
21243 case BFD_RELOC_THUMB_PCREL_BLX:
21244#ifdef OBJ_ELF
21245 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21246 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21247 else
21248#endif
21249 code = BFD_RELOC_THUMB_PCREL_BLX;
21250 break;
21251
c19d1205
ZW
21252 case BFD_RELOC_ARM_LITERAL:
21253 case BFD_RELOC_ARM_HWLITERAL:
21254 /* If this is called then the a literal has
21255 been referenced across a section boundary. */
21256 as_bad_where (fixp->fx_file, fixp->fx_line,
21257 _("literal referenced across section boundary"));
21258 return NULL;
a737bd4d 21259
c19d1205
ZW
21260#ifdef OBJ_ELF
21261 case BFD_RELOC_ARM_GOT32:
21262 case BFD_RELOC_ARM_GOTOFF:
b43420e6 21263 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
21264 case BFD_RELOC_ARM_PLT32:
21265 case BFD_RELOC_ARM_TARGET1:
21266 case BFD_RELOC_ARM_ROSEGREL32:
21267 case BFD_RELOC_ARM_SBREL32:
21268 case BFD_RELOC_ARM_PREL31:
21269 case BFD_RELOC_ARM_TARGET2:
21270 case BFD_RELOC_ARM_TLS_LE32:
21271 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
21272 case BFD_RELOC_ARM_PCREL_CALL:
21273 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
21274 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21275 case BFD_RELOC_ARM_ALU_PC_G0:
21276 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21277 case BFD_RELOC_ARM_ALU_PC_G1:
21278 case BFD_RELOC_ARM_ALU_PC_G2:
21279 case BFD_RELOC_ARM_LDR_PC_G0:
21280 case BFD_RELOC_ARM_LDR_PC_G1:
21281 case BFD_RELOC_ARM_LDR_PC_G2:
21282 case BFD_RELOC_ARM_LDRS_PC_G0:
21283 case BFD_RELOC_ARM_LDRS_PC_G1:
21284 case BFD_RELOC_ARM_LDRS_PC_G2:
21285 case BFD_RELOC_ARM_LDC_PC_G0:
21286 case BFD_RELOC_ARM_LDC_PC_G1:
21287 case BFD_RELOC_ARM_LDC_PC_G2:
21288 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21289 case BFD_RELOC_ARM_ALU_SB_G0:
21290 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21291 case BFD_RELOC_ARM_ALU_SB_G1:
21292 case BFD_RELOC_ARM_ALU_SB_G2:
21293 case BFD_RELOC_ARM_LDR_SB_G0:
21294 case BFD_RELOC_ARM_LDR_SB_G1:
21295 case BFD_RELOC_ARM_LDR_SB_G2:
21296 case BFD_RELOC_ARM_LDRS_SB_G0:
21297 case BFD_RELOC_ARM_LDRS_SB_G1:
21298 case BFD_RELOC_ARM_LDRS_SB_G2:
21299 case BFD_RELOC_ARM_LDC_SB_G0:
21300 case BFD_RELOC_ARM_LDC_SB_G1:
21301 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 21302 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
21303 code = fixp->fx_r_type;
21304 break;
a737bd4d 21305
c19d1205
ZW
21306 case BFD_RELOC_ARM_TLS_GD32:
21307 case BFD_RELOC_ARM_TLS_IE32:
21308 case BFD_RELOC_ARM_TLS_LDM32:
21309 /* BFD will include the symbol's address in the addend.
21310 But we don't want that, so subtract it out again here. */
21311 if (!S_IS_COMMON (fixp->fx_addsy))
21312 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21313 code = fixp->fx_r_type;
21314 break;
21315#endif
a737bd4d 21316
c19d1205
ZW
21317 case BFD_RELOC_ARM_IMMEDIATE:
21318 as_bad_where (fixp->fx_file, fixp->fx_line,
21319 _("internal relocation (type: IMMEDIATE) not fixed up"));
21320 return NULL;
a737bd4d 21321
c19d1205
ZW
21322 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21323 as_bad_where (fixp->fx_file, fixp->fx_line,
21324 _("ADRL used for a symbol not defined in the same file"));
21325 return NULL;
a737bd4d 21326
c19d1205 21327 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
21328 if (section->use_rela_p)
21329 {
21330 code = fixp->fx_r_type;
21331 break;
21332 }
21333
c19d1205
ZW
21334 if (fixp->fx_addsy != NULL
21335 && !S_IS_DEFINED (fixp->fx_addsy)
21336 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 21337 {
c19d1205
ZW
21338 as_bad_where (fixp->fx_file, fixp->fx_line,
21339 _("undefined local label `%s'"),
21340 S_GET_NAME (fixp->fx_addsy));
21341 return NULL;
a737bd4d
NC
21342 }
21343
c19d1205
ZW
21344 as_bad_where (fixp->fx_file, fixp->fx_line,
21345 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21346 return NULL;
a737bd4d 21347
c19d1205
ZW
21348 default:
21349 {
21350 char * type;
6c43fab6 21351
c19d1205
ZW
21352 switch (fixp->fx_r_type)
21353 {
21354 case BFD_RELOC_NONE: type = "NONE"; break;
21355 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21356 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 21357 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
21358 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21359 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21360 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 21361 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 21362 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
21363 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21364 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21365 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21366 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21367 default: type = _("<unknown>"); break;
21368 }
21369 as_bad_where (fixp->fx_file, fixp->fx_line,
21370 _("cannot represent %s relocation in this object file format"),
21371 type);
21372 return NULL;
21373 }
a737bd4d 21374 }
6c43fab6 21375
c19d1205
ZW
21376#ifdef OBJ_ELF
21377 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21378 && GOT_symbol
21379 && fixp->fx_addsy == GOT_symbol)
21380 {
21381 code = BFD_RELOC_ARM_GOTPC;
21382 reloc->addend = fixp->fx_offset = reloc->address;
21383 }
21384#endif
6c43fab6 21385
c19d1205 21386 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 21387
c19d1205
ZW
21388 if (reloc->howto == NULL)
21389 {
21390 as_bad_where (fixp->fx_file, fixp->fx_line,
21391 _("cannot represent %s relocation in this object file format"),
21392 bfd_get_reloc_code_name (code));
21393 return NULL;
21394 }
6c43fab6 21395
c19d1205
ZW
21396 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21397 vtable entry to be used in the relocation's section offset. */
21398 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21399 reloc->address = fixp->fx_offset;
6c43fab6 21400
c19d1205 21401 return reloc;
6c43fab6
RE
21402}
21403
c19d1205 21404/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 21405
c19d1205
ZW
21406void
21407cons_fix_new_arm (fragS * frag,
21408 int where,
21409 int size,
21410 expressionS * exp)
6c43fab6 21411{
c19d1205
ZW
21412 bfd_reloc_code_real_type type;
21413 int pcrel = 0;
6c43fab6 21414
c19d1205
ZW
21415 /* Pick a reloc.
21416 FIXME: @@ Should look at CPU word size. */
21417 switch (size)
21418 {
21419 case 1:
21420 type = BFD_RELOC_8;
21421 break;
21422 case 2:
21423 type = BFD_RELOC_16;
21424 break;
21425 case 4:
21426 default:
21427 type = BFD_RELOC_32;
21428 break;
21429 case 8:
21430 type = BFD_RELOC_64;
21431 break;
21432 }
6c43fab6 21433
f0927246
NC
21434#ifdef TE_PE
21435 if (exp->X_op == O_secrel)
21436 {
21437 exp->X_op = O_symbol;
21438 type = BFD_RELOC_32_SECREL;
21439 }
21440#endif
21441
c19d1205
ZW
21442 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21443}
6c43fab6 21444
4343666d 21445#if defined (OBJ_COFF)
c19d1205
ZW
21446void
21447arm_validate_fix (fixS * fixP)
6c43fab6 21448{
c19d1205
ZW
21449 /* If the destination of the branch is a defined symbol which does not have
21450 the THUMB_FUNC attribute, then we must be calling a function which has
21451 the (interfacearm) attribute. We look for the Thumb entry point to that
21452 function and change the branch to refer to that function instead. */
21453 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21454 && fixP->fx_addsy != NULL
21455 && S_IS_DEFINED (fixP->fx_addsy)
21456 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 21457 {
c19d1205 21458 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 21459 }
c19d1205
ZW
21460}
21461#endif
6c43fab6 21462
267bf995 21463
c19d1205
ZW
21464int
21465arm_force_relocation (struct fix * fixp)
21466{
21467#if defined (OBJ_COFF) && defined (TE_PE)
21468 if (fixp->fx_r_type == BFD_RELOC_RVA)
21469 return 1;
21470#endif
6c43fab6 21471
267bf995
RR
21472 /* In case we have a call or a branch to a function in ARM ISA mode from
21473 a thumb function or vice-versa force the relocation. These relocations
21474 are cleared off for some cores that might have blx and simple transformations
21475 are possible. */
21476
21477#ifdef OBJ_ELF
21478 switch (fixp->fx_r_type)
21479 {
21480 case BFD_RELOC_ARM_PCREL_JUMP:
21481 case BFD_RELOC_ARM_PCREL_CALL:
21482 case BFD_RELOC_THUMB_PCREL_BLX:
21483 if (THUMB_IS_FUNC (fixp->fx_addsy))
21484 return 1;
21485 break;
21486
21487 case BFD_RELOC_ARM_PCREL_BLX:
21488 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21489 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21490 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21491 if (ARM_IS_FUNC (fixp->fx_addsy))
21492 return 1;
21493 break;
21494
21495 default:
21496 break;
21497 }
21498#endif
21499
c19d1205
ZW
21500 /* Resolve these relocations even if the symbol is extern or weak. */
21501 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21502 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 21503 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 21504 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
21505 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21506 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
21507 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 21508 return 0;
a737bd4d 21509
4962c51a
MS
21510 /* Always leave these relocations for the linker. */
21511 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21512 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21513 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21514 return 1;
21515
f0291e4c
PB
21516 /* Always generate relocations against function symbols. */
21517 if (fixp->fx_r_type == BFD_RELOC_32
21518 && fixp->fx_addsy
21519 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21520 return 1;
21521
c19d1205 21522 return generic_force_reloc (fixp);
404ff6b5
AH
21523}
21524
0ffdc86c 21525#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
21526/* Relocations against function names must be left unadjusted,
21527 so that the linker can use this information to generate interworking
21528 stubs. The MIPS version of this function
c19d1205
ZW
21529 also prevents relocations that are mips-16 specific, but I do not
21530 know why it does this.
404ff6b5 21531
c19d1205
ZW
21532 FIXME:
21533 There is one other problem that ought to be addressed here, but
21534 which currently is not: Taking the address of a label (rather
21535 than a function) and then later jumping to that address. Such
21536 addresses also ought to have their bottom bit set (assuming that
21537 they reside in Thumb code), but at the moment they will not. */
404ff6b5 21538
c19d1205
ZW
21539bfd_boolean
21540arm_fix_adjustable (fixS * fixP)
404ff6b5 21541{
c19d1205
ZW
21542 if (fixP->fx_addsy == NULL)
21543 return 1;
404ff6b5 21544
e28387c3
PB
21545 /* Preserve relocations against symbols with function type. */
21546 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 21547 return FALSE;
e28387c3 21548
c19d1205
ZW
21549 if (THUMB_IS_FUNC (fixP->fx_addsy)
21550 && fixP->fx_subsy == NULL)
c921be7d 21551 return FALSE;
a737bd4d 21552
c19d1205
ZW
21553 /* We need the symbol name for the VTABLE entries. */
21554 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
21555 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 21556 return FALSE;
404ff6b5 21557
c19d1205
ZW
21558 /* Don't allow symbols to be discarded on GOT related relocs. */
21559 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
21560 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
21561 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
21562 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
21563 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
21564 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
21565 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
21566 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
21567 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 21568 return FALSE;
a737bd4d 21569
4962c51a
MS
21570 /* Similarly for group relocations. */
21571 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21572 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21573 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 21574 return FALSE;
4962c51a 21575
79947c54
CD
21576 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
21577 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
21578 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21579 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
21580 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
21581 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21582 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
21583 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
21584 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 21585 return FALSE;
79947c54 21586
c921be7d 21587 return TRUE;
a737bd4d 21588}
0ffdc86c
NC
21589#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
21590
21591#ifdef OBJ_ELF
404ff6b5 21592
c19d1205
ZW
21593const char *
21594elf32_arm_target_format (void)
404ff6b5 21595{
c19d1205
ZW
21596#ifdef TE_SYMBIAN
21597 return (target_big_endian
21598 ? "elf32-bigarm-symbian"
21599 : "elf32-littlearm-symbian");
21600#elif defined (TE_VXWORKS)
21601 return (target_big_endian
21602 ? "elf32-bigarm-vxworks"
21603 : "elf32-littlearm-vxworks");
21604#else
21605 if (target_big_endian)
21606 return "elf32-bigarm";
21607 else
21608 return "elf32-littlearm";
21609#endif
404ff6b5
AH
21610}
21611
c19d1205
ZW
21612void
21613armelf_frob_symbol (symbolS * symp,
21614 int * puntp)
404ff6b5 21615{
c19d1205
ZW
21616 elf_frob_symbol (symp, puntp);
21617}
21618#endif
404ff6b5 21619
c19d1205 21620/* MD interface: Finalization. */
a737bd4d 21621
c19d1205
ZW
21622void
21623arm_cleanup (void)
21624{
21625 literal_pool * pool;
a737bd4d 21626
e07e6e58
NC
21627 /* Ensure that all the IT blocks are properly closed. */
21628 check_it_blocks_finished ();
21629
c19d1205
ZW
21630 for (pool = list_of_pools; pool; pool = pool->next)
21631 {
5f4273c7 21632 /* Put it at the end of the relevant section. */
c19d1205
ZW
21633 subseg_set (pool->section, pool->sub_section);
21634#ifdef OBJ_ELF
21635 arm_elf_change_section ();
21636#endif
21637 s_ltorg (0);
21638 }
404ff6b5
AH
21639}
21640
cd000bff
DJ
21641#ifdef OBJ_ELF
21642/* Remove any excess mapping symbols generated for alignment frags in
21643 SEC. We may have created a mapping symbol before a zero byte
21644 alignment; remove it if there's a mapping symbol after the
21645 alignment. */
21646static void
21647check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
21648 void *dummy ATTRIBUTE_UNUSED)
21649{
21650 segment_info_type *seginfo = seg_info (sec);
21651 fragS *fragp;
21652
21653 if (seginfo == NULL || seginfo->frchainP == NULL)
21654 return;
21655
21656 for (fragp = seginfo->frchainP->frch_root;
21657 fragp != NULL;
21658 fragp = fragp->fr_next)
21659 {
21660 symbolS *sym = fragp->tc_frag_data.last_map;
21661 fragS *next = fragp->fr_next;
21662
21663 /* Variable-sized frags have been converted to fixed size by
21664 this point. But if this was variable-sized to start with,
21665 there will be a fixed-size frag after it. So don't handle
21666 next == NULL. */
21667 if (sym == NULL || next == NULL)
21668 continue;
21669
21670 if (S_GET_VALUE (sym) < next->fr_address)
21671 /* Not at the end of this frag. */
21672 continue;
21673 know (S_GET_VALUE (sym) == next->fr_address);
21674
21675 do
21676 {
21677 if (next->tc_frag_data.first_map != NULL)
21678 {
21679 /* Next frag starts with a mapping symbol. Discard this
21680 one. */
21681 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21682 break;
21683 }
21684
21685 if (next->fr_next == NULL)
21686 {
21687 /* This mapping symbol is at the end of the section. Discard
21688 it. */
21689 know (next->fr_fix == 0 && next->fr_var == 0);
21690 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21691 break;
21692 }
21693
21694 /* As long as we have empty frags without any mapping symbols,
21695 keep looking. */
21696 /* If the next frag is non-empty and does not start with a
21697 mapping symbol, then this mapping symbol is required. */
21698 if (next->fr_address != next->fr_next->fr_address)
21699 break;
21700
21701 next = next->fr_next;
21702 }
21703 while (next != NULL);
21704 }
21705}
21706#endif
21707
c19d1205
ZW
21708/* Adjust the symbol table. This marks Thumb symbols as distinct from
21709 ARM ones. */
404ff6b5 21710
c19d1205
ZW
21711void
21712arm_adjust_symtab (void)
404ff6b5 21713{
c19d1205
ZW
21714#ifdef OBJ_COFF
21715 symbolS * sym;
404ff6b5 21716
c19d1205
ZW
21717 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21718 {
21719 if (ARM_IS_THUMB (sym))
21720 {
21721 if (THUMB_IS_FUNC (sym))
21722 {
21723 /* Mark the symbol as a Thumb function. */
21724 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
21725 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
21726 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 21727
c19d1205
ZW
21728 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
21729 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
21730 else
21731 as_bad (_("%s: unexpected function type: %d"),
21732 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
21733 }
21734 else switch (S_GET_STORAGE_CLASS (sym))
21735 {
21736 case C_EXT:
21737 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
21738 break;
21739 case C_STAT:
21740 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
21741 break;
21742 case C_LABEL:
21743 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
21744 break;
21745 default:
21746 /* Do nothing. */
21747 break;
21748 }
21749 }
a737bd4d 21750
c19d1205
ZW
21751 if (ARM_IS_INTERWORK (sym))
21752 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 21753 }
c19d1205
ZW
21754#endif
21755#ifdef OBJ_ELF
21756 symbolS * sym;
21757 char bind;
404ff6b5 21758
c19d1205 21759 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 21760 {
c19d1205
ZW
21761 if (ARM_IS_THUMB (sym))
21762 {
21763 elf_symbol_type * elf_sym;
404ff6b5 21764
c19d1205
ZW
21765 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
21766 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 21767
b0796911
PB
21768 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
21769 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
21770 {
21771 /* If it's a .thumb_func, declare it as so,
21772 otherwise tag label as .code 16. */
21773 if (THUMB_IS_FUNC (sym))
21774 elf_sym->internal_elf_sym.st_info =
21775 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 21776 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
21777 elf_sym->internal_elf_sym.st_info =
21778 ELF_ST_INFO (bind, STT_ARM_16BIT);
21779 }
21780 }
21781 }
cd000bff
DJ
21782
21783 /* Remove any overlapping mapping symbols generated by alignment frags. */
21784 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
c19d1205 21785#endif
404ff6b5
AH
21786}
21787
c19d1205 21788/* MD interface: Initialization. */
404ff6b5 21789
a737bd4d 21790static void
c19d1205 21791set_constant_flonums (void)
a737bd4d 21792{
c19d1205 21793 int i;
404ff6b5 21794
c19d1205
ZW
21795 for (i = 0; i < NUM_FLOAT_VALS; i++)
21796 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
21797 abort ();
a737bd4d 21798}
404ff6b5 21799
3e9e4fcf
JB
21800/* Auto-select Thumb mode if it's the only available instruction set for the
21801 given architecture. */
21802
21803static void
21804autoselect_thumb_from_cpu_variant (void)
21805{
21806 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
21807 opcode_select (16);
21808}
21809
c19d1205
ZW
21810void
21811md_begin (void)
a737bd4d 21812{
c19d1205
ZW
21813 unsigned mach;
21814 unsigned int i;
404ff6b5 21815
c19d1205
ZW
21816 if ( (arm_ops_hsh = hash_new ()) == NULL
21817 || (arm_cond_hsh = hash_new ()) == NULL
21818 || (arm_shift_hsh = hash_new ()) == NULL
21819 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 21820 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 21821 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
21822 || (arm_reloc_hsh = hash_new ()) == NULL
21823 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
21824 as_fatal (_("virtual memory exhausted"));
21825
21826 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 21827 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 21828 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 21829 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 21830 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 21831 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 21832 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 21833 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 21834 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0
NC
21835 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
21836 (void *) (v7m_psrs + i));
c19d1205 21837 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 21838 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
21839 for (i = 0;
21840 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
21841 i++)
d3ce72d0 21842 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 21843 (void *) (barrier_opt_names + i));
c19d1205
ZW
21844#ifdef OBJ_ELF
21845 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 21846 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
21847#endif
21848
21849 set_constant_flonums ();
404ff6b5 21850
c19d1205
ZW
21851 /* Set the cpu variant based on the command-line options. We prefer
21852 -mcpu= over -march= if both are set (as for GCC); and we prefer
21853 -mfpu= over any other way of setting the floating point unit.
21854 Use of legacy options with new options are faulted. */
e74cfd16 21855 if (legacy_cpu)
404ff6b5 21856 {
e74cfd16 21857 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
21858 as_bad (_("use of old and new-style options to set CPU type"));
21859
21860 mcpu_cpu_opt = legacy_cpu;
404ff6b5 21861 }
e74cfd16 21862 else if (!mcpu_cpu_opt)
c19d1205 21863 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 21864
e74cfd16 21865 if (legacy_fpu)
c19d1205 21866 {
e74cfd16 21867 if (mfpu_opt)
c19d1205 21868 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
21869
21870 mfpu_opt = legacy_fpu;
21871 }
e74cfd16 21872 else if (!mfpu_opt)
03b1477f 21873 {
45eb4c1b
NS
21874#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
21875 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
21876 /* Some environments specify a default FPU. If they don't, infer it
21877 from the processor. */
e74cfd16 21878 if (mcpu_fpu_opt)
03b1477f
RE
21879 mfpu_opt = mcpu_fpu_opt;
21880 else
21881 mfpu_opt = march_fpu_opt;
39c2da32 21882#else
e74cfd16 21883 mfpu_opt = &fpu_default;
39c2da32 21884#endif
03b1477f
RE
21885 }
21886
e74cfd16 21887 if (!mfpu_opt)
03b1477f 21888 {
493cb6ef 21889 if (mcpu_cpu_opt != NULL)
e74cfd16 21890 mfpu_opt = &fpu_default;
493cb6ef 21891 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 21892 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 21893 else
e74cfd16 21894 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
21895 }
21896
ee065d83 21897#ifdef CPU_DEFAULT
e74cfd16 21898 if (!mcpu_cpu_opt)
ee065d83 21899 {
e74cfd16
PB
21900 mcpu_cpu_opt = &cpu_default;
21901 selected_cpu = cpu_default;
ee065d83 21902 }
e74cfd16
PB
21903#else
21904 if (mcpu_cpu_opt)
21905 selected_cpu = *mcpu_cpu_opt;
ee065d83 21906 else
e74cfd16 21907 mcpu_cpu_opt = &arm_arch_any;
ee065d83 21908#endif
03b1477f 21909
e74cfd16 21910 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 21911
3e9e4fcf
JB
21912 autoselect_thumb_from_cpu_variant ();
21913
e74cfd16 21914 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 21915
f17c130b 21916#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 21917 {
7cc69913
NC
21918 unsigned int flags = 0;
21919
21920#if defined OBJ_ELF
21921 flags = meabi_flags;
d507cf36
PB
21922
21923 switch (meabi_flags)
33a392fb 21924 {
d507cf36 21925 case EF_ARM_EABI_UNKNOWN:
7cc69913 21926#endif
d507cf36
PB
21927 /* Set the flags in the private structure. */
21928 if (uses_apcs_26) flags |= F_APCS26;
21929 if (support_interwork) flags |= F_INTERWORK;
21930 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 21931 if (pic_code) flags |= F_PIC;
e74cfd16 21932 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
21933 flags |= F_SOFT_FLOAT;
21934
d507cf36
PB
21935 switch (mfloat_abi_opt)
21936 {
21937 case ARM_FLOAT_ABI_SOFT:
21938 case ARM_FLOAT_ABI_SOFTFP:
21939 flags |= F_SOFT_FLOAT;
21940 break;
33a392fb 21941
d507cf36
PB
21942 case ARM_FLOAT_ABI_HARD:
21943 if (flags & F_SOFT_FLOAT)
21944 as_bad (_("hard-float conflicts with specified fpu"));
21945 break;
21946 }
03b1477f 21947
e74cfd16
PB
21948 /* Using pure-endian doubles (even if soft-float). */
21949 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 21950 flags |= F_VFP_FLOAT;
f17c130b 21951
fde78edd 21952#if defined OBJ_ELF
e74cfd16 21953 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 21954 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
21955 break;
21956
8cb51566 21957 case EF_ARM_EABI_VER4:
3a4a14e9 21958 case EF_ARM_EABI_VER5:
c19d1205 21959 /* No additional flags to set. */
d507cf36
PB
21960 break;
21961
21962 default:
21963 abort ();
21964 }
7cc69913 21965#endif
b99bd4ef
NC
21966 bfd_set_private_flags (stdoutput, flags);
21967
21968 /* We have run out flags in the COFF header to encode the
21969 status of ATPCS support, so instead we create a dummy,
c19d1205 21970 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
21971 if (atpcs)
21972 {
21973 asection * sec;
21974
21975 sec = bfd_make_section (stdoutput, ".arm.atpcs");
21976
21977 if (sec != NULL)
21978 {
21979 bfd_set_section_flags
21980 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
21981 bfd_set_section_size (stdoutput, sec, 0);
21982 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
21983 }
21984 }
7cc69913 21985 }
f17c130b 21986#endif
b99bd4ef
NC
21987
21988 /* Record the CPU type as well. */
2d447fca
JM
21989 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
21990 mach = bfd_mach_arm_iWMMXt2;
21991 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 21992 mach = bfd_mach_arm_iWMMXt;
e74cfd16 21993 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 21994 mach = bfd_mach_arm_XScale;
e74cfd16 21995 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 21996 mach = bfd_mach_arm_ep9312;
e74cfd16 21997 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 21998 mach = bfd_mach_arm_5TE;
e74cfd16 21999 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 22000 {
e74cfd16 22001 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22002 mach = bfd_mach_arm_5T;
22003 else
22004 mach = bfd_mach_arm_5;
22005 }
e74cfd16 22006 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 22007 {
e74cfd16 22008 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22009 mach = bfd_mach_arm_4T;
22010 else
22011 mach = bfd_mach_arm_4;
22012 }
e74cfd16 22013 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 22014 mach = bfd_mach_arm_3M;
e74cfd16
PB
22015 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
22016 mach = bfd_mach_arm_3;
22017 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
22018 mach = bfd_mach_arm_2a;
22019 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
22020 mach = bfd_mach_arm_2;
22021 else
22022 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
22023
22024 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
22025}
22026
c19d1205 22027/* Command line processing. */
b99bd4ef 22028
c19d1205
ZW
22029/* md_parse_option
22030 Invocation line includes a switch not recognized by the base assembler.
22031 See if it's a processor-specific option.
b99bd4ef 22032
c19d1205
ZW
22033 This routine is somewhat complicated by the need for backwards
22034 compatibility (since older releases of gcc can't be changed).
22035 The new options try to make the interface as compatible as
22036 possible with GCC.
b99bd4ef 22037
c19d1205 22038 New options (supported) are:
b99bd4ef 22039
c19d1205
ZW
22040 -mcpu=<cpu name> Assemble for selected processor
22041 -march=<architecture name> Assemble for selected architecture
22042 -mfpu=<fpu architecture> Assemble for selected FPU.
22043 -EB/-mbig-endian Big-endian
22044 -EL/-mlittle-endian Little-endian
22045 -k Generate PIC code
22046 -mthumb Start in Thumb mode
22047 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 22048
278df34e 22049 -m[no-]warn-deprecated Warn about deprecated features
267bf995 22050
c19d1205 22051 For now we will also provide support for:
b99bd4ef 22052
c19d1205
ZW
22053 -mapcs-32 32-bit Program counter
22054 -mapcs-26 26-bit Program counter
22055 -macps-float Floats passed in FP registers
22056 -mapcs-reentrant Reentrant code
22057 -matpcs
22058 (sometime these will probably be replaced with -mapcs=<list of options>
22059 and -matpcs=<list of options>)
b99bd4ef 22060
c19d1205
ZW
22061 The remaining options are only supported for back-wards compatibility.
22062 Cpu variants, the arm part is optional:
22063 -m[arm]1 Currently not supported.
22064 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
22065 -m[arm]3 Arm 3 processor
22066 -m[arm]6[xx], Arm 6 processors
22067 -m[arm]7[xx][t][[d]m] Arm 7 processors
22068 -m[arm]8[10] Arm 8 processors
22069 -m[arm]9[20][tdmi] Arm 9 processors
22070 -mstrongarm[110[0]] StrongARM processors
22071 -mxscale XScale processors
22072 -m[arm]v[2345[t[e]]] Arm architectures
22073 -mall All (except the ARM1)
22074 FP variants:
22075 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
22076 -mfpe-old (No float load/store multiples)
22077 -mvfpxd VFP Single precision
22078 -mvfp All VFP
22079 -mno-fpu Disable all floating point instructions
b99bd4ef 22080
c19d1205
ZW
22081 The following CPU names are recognized:
22082 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
22083 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
22084 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
22085 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
22086 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
22087 arm10t arm10e, arm1020t, arm1020e, arm10200e,
22088 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 22089
c19d1205 22090 */
b99bd4ef 22091
c19d1205 22092const char * md_shortopts = "m:k";
b99bd4ef 22093
c19d1205
ZW
22094#ifdef ARM_BI_ENDIAN
22095#define OPTION_EB (OPTION_MD_BASE + 0)
22096#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 22097#else
c19d1205
ZW
22098#if TARGET_BYTES_BIG_ENDIAN
22099#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 22100#else
c19d1205
ZW
22101#define OPTION_EL (OPTION_MD_BASE + 1)
22102#endif
b99bd4ef 22103#endif
845b51d6 22104#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 22105
c19d1205 22106struct option md_longopts[] =
b99bd4ef 22107{
c19d1205
ZW
22108#ifdef OPTION_EB
22109 {"EB", no_argument, NULL, OPTION_EB},
22110#endif
22111#ifdef OPTION_EL
22112 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 22113#endif
845b51d6 22114 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
22115 {NULL, no_argument, NULL, 0}
22116};
b99bd4ef 22117
c19d1205 22118size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 22119
c19d1205 22120struct arm_option_table
b99bd4ef 22121{
c19d1205
ZW
22122 char *option; /* Option name to match. */
22123 char *help; /* Help information. */
22124 int *var; /* Variable to change. */
22125 int value; /* What to change it to. */
22126 char *deprecated; /* If non-null, print this message. */
22127};
b99bd4ef 22128
c19d1205
ZW
22129struct arm_option_table arm_opts[] =
22130{
22131 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
22132 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
22133 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
22134 &support_interwork, 1, NULL},
22135 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
22136 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
22137 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
22138 1, NULL},
22139 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
22140 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
22141 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
22142 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
22143 NULL},
b99bd4ef 22144
c19d1205
ZW
22145 /* These are recognized by the assembler, but have no affect on code. */
22146 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
22147 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
22148
22149 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
22150 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
22151 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
22152 {NULL, NULL, NULL, 0, NULL}
22153};
22154
22155struct arm_legacy_option_table
22156{
22157 char *option; /* Option name to match. */
22158 const arm_feature_set **var; /* Variable to change. */
22159 const arm_feature_set value; /* What to change it to. */
22160 char *deprecated; /* If non-null, print this message. */
22161};
b99bd4ef 22162
e74cfd16
PB
22163const struct arm_legacy_option_table arm_legacy_opts[] =
22164{
c19d1205
ZW
22165 /* DON'T add any new processors to this list -- we want the whole list
22166 to go away... Add them to the processors table instead. */
e74cfd16
PB
22167 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22168 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22169 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22170 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22171 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22172 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22173 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22174 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22175 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22176 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22177 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22178 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22179 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22180 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22181 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22182 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22183 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22184 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22185 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22186 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22187 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22188 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22189 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22190 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22191 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22192 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22193 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22194 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22195 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22196 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22197 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22198 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22199 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22200 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22201 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22202 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22203 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22204 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22205 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22206 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22207 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22208 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22209 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22210 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22211 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22212 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22213 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22214 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22215 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22216 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22217 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22218 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22219 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22220 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22221 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22222 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22223 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22224 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22225 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22226 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22227 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22228 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22229 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22230 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22231 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22232 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22233 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22234 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22235 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22236 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22237 N_("use -mcpu=strongarm110")},
e74cfd16 22238 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22239 N_("use -mcpu=strongarm1100")},
e74cfd16 22240 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22241 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
22242 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22243 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22244 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 22245
c19d1205 22246 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
22247 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22248 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22249 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22250 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22251 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22252 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22253 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22254 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22255 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22256 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22257 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22258 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22259 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22260 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22261 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22262 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22263 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22264 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 22265
c19d1205 22266 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
22267 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22268 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22269 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22270 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 22271 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 22272
e74cfd16 22273 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 22274};
7ed4c4c5 22275
c19d1205 22276struct arm_cpu_option_table
7ed4c4c5 22277{
c19d1205 22278 char *name;
e74cfd16 22279 const arm_feature_set value;
c19d1205
ZW
22280 /* For some CPUs we assume an FPU unless the user explicitly sets
22281 -mfpu=... */
e74cfd16 22282 const arm_feature_set default_fpu;
ee065d83
PB
22283 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22284 case. */
22285 const char *canonical_name;
c19d1205 22286};
7ed4c4c5 22287
c19d1205
ZW
22288/* This list should, at a minimum, contain all the cpu names
22289 recognized by GCC. */
e74cfd16 22290static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 22291{
ee065d83
PB
22292 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
22293 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
22294 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
22295 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22296 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22297 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22298 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22299 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22300 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22301 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22302 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22303 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22304 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22305 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22306 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22307 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22308 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22309 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22310 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22311 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22312 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22313 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22314 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22315 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22316 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22317 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22318 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22319 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22320 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22321 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22322 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22323 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22324 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22325 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22326 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22327 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22328 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22329 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22330 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22331 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
22332 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22333 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22334 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22335 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
22336 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22337 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
22338 /* For V5 or later processors we default to using VFP; but the user
22339 should really set the FPU type explicitly. */
ee065d83
PB
22340 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22341 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22342 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22343 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22344 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22345 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22346 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22347 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22348 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22349 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22350 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22351 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22352 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22353 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22354 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22355 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22356 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22357 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22358 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22359 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22360 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
7fac0536
NC
22361 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
22362 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
22363 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22364 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22365 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22366 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
4ff9b924
MGD
22367 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"},
22368 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"},
ee065d83
PB
22369 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22370 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22371 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22372 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
4ff9b924 22373 {"cortex-a5", ARM_ARCH_V7A, FPU_NONE, "Cortex-A5"},
e07e6e58 22374 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
5287ad62 22375 | FPU_NEON_EXT_V1),
4ff9b924 22376 "Cortex-A8"},
e07e6e58 22377 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
15290f0a 22378 | FPU_NEON_EXT_V1),
4ff9b924 22379 "Cortex-A9"},
dbb1f804
MGD
22380 {"cortex-a15", ARM_ARCH_V7A, FPU_ARCH_NEON_VFP_V4,
22381 "Cortex-A15"},
4ff9b924
MGD
22382 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"},
22383 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
22384 "Cortex-R4F"},
22385 {"cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"},
22386 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"},
22387 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, "Cortex-M1"},
22388 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, "Cortex-M0"},
c19d1205 22389 /* ??? XSCALE is really an architecture. */
ee065d83 22390 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22391 /* ??? iwmmxt is not a processor. */
ee065d83 22392 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 22393 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 22394 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22395 /* Maverick */
e07e6e58 22396 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
e74cfd16 22397 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 22398};
7ed4c4c5 22399
c19d1205 22400struct arm_arch_option_table
7ed4c4c5 22401{
c19d1205 22402 char *name;
e74cfd16
PB
22403 const arm_feature_set value;
22404 const arm_feature_set default_fpu;
c19d1205 22405};
7ed4c4c5 22406
c19d1205
ZW
22407/* This list should, at a minimum, contain all the architecture names
22408 recognized by GCC. */
e74cfd16 22409static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
22410{
22411 {"all", ARM_ANY, FPU_ARCH_FPA},
22412 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22413 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22414 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22415 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22416 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22417 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22418 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22419 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22420 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22421 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22422 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22423 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22424 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22425 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22426 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22427 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22428 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22429 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22430 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22431 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22432 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22433 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22434 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22435 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22436 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 22437 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
62b3e311 22438 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
22439 /* The official spelling of the ARMv7 profile variants is the dashed form.
22440 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
22441 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22442 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22443 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
22444 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22445 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22446 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
9e3c6df6 22447 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
c19d1205
ZW
22448 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22449 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 22450 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 22451 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 22452};
7ed4c4c5 22453
c19d1205 22454/* ISA extensions in the co-processor space. */
e74cfd16 22455struct arm_option_cpu_value_table
c19d1205
ZW
22456{
22457 char *name;
e74cfd16 22458 const arm_feature_set value;
c19d1205 22459};
7ed4c4c5 22460
e74cfd16 22461static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 22462{
e74cfd16
PB
22463 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
22464 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
22465 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 22466 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 22467 {NULL, ARM_ARCH_NONE}
c19d1205 22468};
7ed4c4c5 22469
c19d1205
ZW
22470/* This list should, at a minimum, contain all the fpu names
22471 recognized by GCC. */
e74cfd16 22472static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
22473{
22474 {"softfpa", FPU_NONE},
22475 {"fpe", FPU_ARCH_FPE},
22476 {"fpe2", FPU_ARCH_FPE},
22477 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22478 {"fpa", FPU_ARCH_FPA},
22479 {"fpa10", FPU_ARCH_FPA},
22480 {"fpa11", FPU_ARCH_FPA},
22481 {"arm7500fe", FPU_ARCH_FPA},
22482 {"softvfp", FPU_ARCH_VFP},
22483 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22484 {"vfp", FPU_ARCH_VFP_V2},
22485 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 22486 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
22487 {"vfp10", FPU_ARCH_VFP_V2},
22488 {"vfp10-r0", FPU_ARCH_VFP_V1},
22489 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
22490 {"vfpv2", FPU_ARCH_VFP_V2},
22491 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 22492 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 22493 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
22494 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
22495 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
22496 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
22497 {"arm1020t", FPU_ARCH_VFP_V1},
22498 {"arm1020e", FPU_ARCH_VFP_V2},
22499 {"arm1136jfs", FPU_ARCH_VFP_V2},
22500 {"arm1136jf-s", FPU_ARCH_VFP_V2},
22501 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 22502 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 22503 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
22504 {"vfpv4", FPU_ARCH_VFP_V4},
22505 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 22506 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 22507 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
e74cfd16
PB
22508 {NULL, ARM_ARCH_NONE}
22509};
22510
22511struct arm_option_value_table
22512{
22513 char *name;
22514 long value;
c19d1205 22515};
7ed4c4c5 22516
e74cfd16 22517static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
22518{
22519 {"hard", ARM_FLOAT_ABI_HARD},
22520 {"softfp", ARM_FLOAT_ABI_SOFTFP},
22521 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 22522 {NULL, 0}
c19d1205 22523};
7ed4c4c5 22524
c19d1205 22525#ifdef OBJ_ELF
3a4a14e9 22526/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 22527static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
22528{
22529 {"gnu", EF_ARM_EABI_UNKNOWN},
22530 {"4", EF_ARM_EABI_VER4},
3a4a14e9 22531 {"5", EF_ARM_EABI_VER5},
e74cfd16 22532 {NULL, 0}
c19d1205
ZW
22533};
22534#endif
7ed4c4c5 22535
c19d1205
ZW
22536struct arm_long_option_table
22537{
22538 char * option; /* Substring to match. */
22539 char * help; /* Help information. */
22540 int (* func) (char * subopt); /* Function to decode sub-option. */
22541 char * deprecated; /* If non-null, print this message. */
22542};
7ed4c4c5 22543
c921be7d 22544static bfd_boolean
e74cfd16 22545arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 22546{
21d799b5
NC
22547 arm_feature_set *ext_set = (arm_feature_set *)
22548 xmalloc (sizeof (arm_feature_set));
e74cfd16
PB
22549
22550 /* Copy the feature set, so that we can modify it. */
22551 *ext_set = **opt_p;
22552 *opt_p = ext_set;
22553
c19d1205 22554 while (str != NULL && *str != 0)
7ed4c4c5 22555 {
e74cfd16 22556 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
22557 char * ext;
22558 int optlen;
7ed4c4c5 22559
c19d1205
ZW
22560 if (*str != '+')
22561 {
22562 as_bad (_("invalid architectural extension"));
c921be7d 22563 return FALSE;
c19d1205 22564 }
7ed4c4c5 22565
c19d1205
ZW
22566 str++;
22567 ext = strchr (str, '+');
7ed4c4c5 22568
c19d1205
ZW
22569 if (ext != NULL)
22570 optlen = ext - str;
22571 else
22572 optlen = strlen (str);
7ed4c4c5 22573
c19d1205
ZW
22574 if (optlen == 0)
22575 {
22576 as_bad (_("missing architectural extension"));
c921be7d 22577 return FALSE;
c19d1205 22578 }
7ed4c4c5 22579
c19d1205
ZW
22580 for (opt = arm_extensions; opt->name != NULL; opt++)
22581 if (strncmp (opt->name, str, optlen) == 0)
22582 {
e74cfd16 22583 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
22584 break;
22585 }
7ed4c4c5 22586
c19d1205
ZW
22587 if (opt->name == NULL)
22588 {
5f4273c7 22589 as_bad (_("unknown architectural extension `%s'"), str);
c921be7d 22590 return FALSE;
c19d1205 22591 }
7ed4c4c5 22592
c19d1205
ZW
22593 str = ext;
22594 };
7ed4c4c5 22595
c921be7d 22596 return TRUE;
c19d1205 22597}
7ed4c4c5 22598
c921be7d 22599static bfd_boolean
c19d1205 22600arm_parse_cpu (char * str)
7ed4c4c5 22601{
e74cfd16 22602 const struct arm_cpu_option_table * opt;
c19d1205
ZW
22603 char * ext = strchr (str, '+');
22604 int optlen;
7ed4c4c5 22605
c19d1205
ZW
22606 if (ext != NULL)
22607 optlen = ext - str;
7ed4c4c5 22608 else
c19d1205 22609 optlen = strlen (str);
7ed4c4c5 22610
c19d1205 22611 if (optlen == 0)
7ed4c4c5 22612 {
c19d1205 22613 as_bad (_("missing cpu name `%s'"), str);
c921be7d 22614 return FALSE;
7ed4c4c5
NC
22615 }
22616
c19d1205
ZW
22617 for (opt = arm_cpus; opt->name != NULL; opt++)
22618 if (strncmp (opt->name, str, optlen) == 0)
22619 {
e74cfd16
PB
22620 mcpu_cpu_opt = &opt->value;
22621 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 22622 if (opt->canonical_name)
5f4273c7 22623 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22624 else
22625 {
22626 int i;
c921be7d 22627
ee065d83
PB
22628 for (i = 0; i < optlen; i++)
22629 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22630 selected_cpu_name[i] = 0;
22631 }
7ed4c4c5 22632
c19d1205
ZW
22633 if (ext != NULL)
22634 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 22635
c921be7d 22636 return TRUE;
c19d1205 22637 }
7ed4c4c5 22638
c19d1205 22639 as_bad (_("unknown cpu `%s'"), str);
c921be7d 22640 return FALSE;
7ed4c4c5
NC
22641}
22642
c921be7d 22643static bfd_boolean
c19d1205 22644arm_parse_arch (char * str)
7ed4c4c5 22645{
e74cfd16 22646 const struct arm_arch_option_table *opt;
c19d1205
ZW
22647 char *ext = strchr (str, '+');
22648 int optlen;
7ed4c4c5 22649
c19d1205
ZW
22650 if (ext != NULL)
22651 optlen = ext - str;
7ed4c4c5 22652 else
c19d1205 22653 optlen = strlen (str);
7ed4c4c5 22654
c19d1205 22655 if (optlen == 0)
7ed4c4c5 22656 {
c19d1205 22657 as_bad (_("missing architecture name `%s'"), str);
c921be7d 22658 return FALSE;
7ed4c4c5
NC
22659 }
22660
c19d1205
ZW
22661 for (opt = arm_archs; opt->name != NULL; opt++)
22662 if (streq (opt->name, str))
22663 {
e74cfd16
PB
22664 march_cpu_opt = &opt->value;
22665 march_fpu_opt = &opt->default_fpu;
5f4273c7 22666 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 22667
c19d1205
ZW
22668 if (ext != NULL)
22669 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 22670
c921be7d 22671 return TRUE;
c19d1205
ZW
22672 }
22673
22674 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 22675 return FALSE;
7ed4c4c5 22676}
eb043451 22677
c921be7d 22678static bfd_boolean
c19d1205
ZW
22679arm_parse_fpu (char * str)
22680{
e74cfd16 22681 const struct arm_option_cpu_value_table * opt;
b99bd4ef 22682
c19d1205
ZW
22683 for (opt = arm_fpus; opt->name != NULL; opt++)
22684 if (streq (opt->name, str))
22685 {
e74cfd16 22686 mfpu_opt = &opt->value;
c921be7d 22687 return TRUE;
c19d1205 22688 }
b99bd4ef 22689
c19d1205 22690 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 22691 return FALSE;
c19d1205
ZW
22692}
22693
c921be7d 22694static bfd_boolean
c19d1205 22695arm_parse_float_abi (char * str)
b99bd4ef 22696{
e74cfd16 22697 const struct arm_option_value_table * opt;
b99bd4ef 22698
c19d1205
ZW
22699 for (opt = arm_float_abis; opt->name != NULL; opt++)
22700 if (streq (opt->name, str))
22701 {
22702 mfloat_abi_opt = opt->value;
c921be7d 22703 return TRUE;
c19d1205 22704 }
cc8a6dd0 22705
c19d1205 22706 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 22707 return FALSE;
c19d1205 22708}
b99bd4ef 22709
c19d1205 22710#ifdef OBJ_ELF
c921be7d 22711static bfd_boolean
c19d1205
ZW
22712arm_parse_eabi (char * str)
22713{
e74cfd16 22714 const struct arm_option_value_table *opt;
cc8a6dd0 22715
c19d1205
ZW
22716 for (opt = arm_eabis; opt->name != NULL; opt++)
22717 if (streq (opt->name, str))
22718 {
22719 meabi_flags = opt->value;
c921be7d 22720 return TRUE;
c19d1205
ZW
22721 }
22722 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 22723 return FALSE;
c19d1205
ZW
22724}
22725#endif
cc8a6dd0 22726
c921be7d 22727static bfd_boolean
e07e6e58
NC
22728arm_parse_it_mode (char * str)
22729{
c921be7d 22730 bfd_boolean ret = TRUE;
e07e6e58
NC
22731
22732 if (streq ("arm", str))
22733 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
22734 else if (streq ("thumb", str))
22735 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
22736 else if (streq ("always", str))
22737 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
22738 else if (streq ("never", str))
22739 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
22740 else
22741 {
22742 as_bad (_("unknown implicit IT mode `%s', should be "\
22743 "arm, thumb, always, or never."), str);
c921be7d 22744 ret = FALSE;
e07e6e58
NC
22745 }
22746
22747 return ret;
22748}
22749
c19d1205
ZW
22750struct arm_long_option_table arm_long_opts[] =
22751{
22752 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
22753 arm_parse_cpu, NULL},
22754 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
22755 arm_parse_arch, NULL},
22756 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
22757 arm_parse_fpu, NULL},
22758 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
22759 arm_parse_float_abi, NULL},
22760#ifdef OBJ_ELF
7fac0536 22761 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
22762 arm_parse_eabi, NULL},
22763#endif
e07e6e58
NC
22764 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
22765 arm_parse_it_mode, NULL},
c19d1205
ZW
22766 {NULL, NULL, 0, NULL}
22767};
cc8a6dd0 22768
c19d1205
ZW
22769int
22770md_parse_option (int c, char * arg)
22771{
22772 struct arm_option_table *opt;
e74cfd16 22773 const struct arm_legacy_option_table *fopt;
c19d1205 22774 struct arm_long_option_table *lopt;
b99bd4ef 22775
c19d1205 22776 switch (c)
b99bd4ef 22777 {
c19d1205
ZW
22778#ifdef OPTION_EB
22779 case OPTION_EB:
22780 target_big_endian = 1;
22781 break;
22782#endif
cc8a6dd0 22783
c19d1205
ZW
22784#ifdef OPTION_EL
22785 case OPTION_EL:
22786 target_big_endian = 0;
22787 break;
22788#endif
b99bd4ef 22789
845b51d6
PB
22790 case OPTION_FIX_V4BX:
22791 fix_v4bx = TRUE;
22792 break;
22793
c19d1205
ZW
22794 case 'a':
22795 /* Listing option. Just ignore these, we don't support additional
22796 ones. */
22797 return 0;
b99bd4ef 22798
c19d1205
ZW
22799 default:
22800 for (opt = arm_opts; opt->option != NULL; opt++)
22801 {
22802 if (c == opt->option[0]
22803 && ((arg == NULL && opt->option[1] == 0)
22804 || streq (arg, opt->option + 1)))
22805 {
c19d1205 22806 /* If the option is deprecated, tell the user. */
278df34e 22807 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
22808 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22809 arg ? arg : "", _(opt->deprecated));
b99bd4ef 22810
c19d1205
ZW
22811 if (opt->var != NULL)
22812 *opt->var = opt->value;
cc8a6dd0 22813
c19d1205
ZW
22814 return 1;
22815 }
22816 }
b99bd4ef 22817
e74cfd16
PB
22818 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
22819 {
22820 if (c == fopt->option[0]
22821 && ((arg == NULL && fopt->option[1] == 0)
22822 || streq (arg, fopt->option + 1)))
22823 {
e74cfd16 22824 /* If the option is deprecated, tell the user. */
278df34e 22825 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
22826 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22827 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
22828
22829 if (fopt->var != NULL)
22830 *fopt->var = &fopt->value;
22831
22832 return 1;
22833 }
22834 }
22835
c19d1205
ZW
22836 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22837 {
22838 /* These options are expected to have an argument. */
22839 if (c == lopt->option[0]
22840 && arg != NULL
22841 && strncmp (arg, lopt->option + 1,
22842 strlen (lopt->option + 1)) == 0)
22843 {
c19d1205 22844 /* If the option is deprecated, tell the user. */
278df34e 22845 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
22846 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
22847 _(lopt->deprecated));
b99bd4ef 22848
c19d1205
ZW
22849 /* Call the sup-option parser. */
22850 return lopt->func (arg + strlen (lopt->option) - 1);
22851 }
22852 }
a737bd4d 22853
c19d1205
ZW
22854 return 0;
22855 }
a394c00f 22856
c19d1205
ZW
22857 return 1;
22858}
a394c00f 22859
c19d1205
ZW
22860void
22861md_show_usage (FILE * fp)
a394c00f 22862{
c19d1205
ZW
22863 struct arm_option_table *opt;
22864 struct arm_long_option_table *lopt;
a394c00f 22865
c19d1205 22866 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 22867
c19d1205
ZW
22868 for (opt = arm_opts; opt->option != NULL; opt++)
22869 if (opt->help != NULL)
22870 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 22871
c19d1205
ZW
22872 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22873 if (lopt->help != NULL)
22874 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 22875
c19d1205
ZW
22876#ifdef OPTION_EB
22877 fprintf (fp, _("\
22878 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
22879#endif
22880
c19d1205
ZW
22881#ifdef OPTION_EL
22882 fprintf (fp, _("\
22883 -EL assemble code for a little-endian cpu\n"));
a737bd4d 22884#endif
845b51d6
PB
22885
22886 fprintf (fp, _("\
22887 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 22888}
ee065d83
PB
22889
22890
22891#ifdef OBJ_ELF
62b3e311
PB
22892typedef struct
22893{
22894 int val;
22895 arm_feature_set flags;
22896} cpu_arch_ver_table;
22897
22898/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
22899 least features first. */
22900static const cpu_arch_ver_table cpu_arch_ver[] =
22901{
22902 {1, ARM_ARCH_V4},
22903 {2, ARM_ARCH_V4T},
22904 {3, ARM_ARCH_V5},
ee3c0378 22905 {3, ARM_ARCH_V5T},
62b3e311
PB
22906 {4, ARM_ARCH_V5TE},
22907 {5, ARM_ARCH_V5TEJ},
22908 {6, ARM_ARCH_V6},
22909 {7, ARM_ARCH_V6Z},
7e806470 22910 {9, ARM_ARCH_V6K},
91e22acd 22911 {11, ARM_ARCH_V6M},
7e806470 22912 {8, ARM_ARCH_V6T2},
62b3e311
PB
22913 {10, ARM_ARCH_V7A},
22914 {10, ARM_ARCH_V7R},
22915 {10, ARM_ARCH_V7M},
22916 {0, ARM_ARCH_NONE}
22917};
22918
ee3c0378
AS
22919/* Set an attribute if it has not already been set by the user. */
22920static void
22921aeabi_set_attribute_int (int tag, int value)
22922{
22923 if (tag < 1
22924 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22925 || !attributes_set_explicitly[tag])
22926 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
22927}
22928
22929static void
22930aeabi_set_attribute_string (int tag, const char *value)
22931{
22932 if (tag < 1
22933 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22934 || !attributes_set_explicitly[tag])
22935 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
22936}
22937
ee065d83
PB
22938/* Set the public EABI object attributes. */
22939static void
22940aeabi_set_public_attributes (void)
22941{
22942 int arch;
e74cfd16 22943 arm_feature_set flags;
62b3e311
PB
22944 arm_feature_set tmp;
22945 const cpu_arch_ver_table *p;
ee065d83
PB
22946
22947 /* Choose the architecture based on the capabilities of the requested cpu
22948 (if any) and/or the instructions actually used. */
e74cfd16
PB
22949 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
22950 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
22951 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
22952 /*Allow the user to override the reported architecture. */
22953 if (object_arch)
22954 {
22955 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
22956 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
22957 }
22958
62b3e311
PB
22959 tmp = flags;
22960 arch = 0;
22961 for (p = cpu_arch_ver; p->val; p++)
22962 {
22963 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
22964 {
22965 arch = p->val;
22966 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
22967 }
22968 }
ee065d83 22969
9e3c6df6
PB
22970 /* The table lookup above finds the last architecture to contribute
22971 a new feature. Unfortunately, Tag13 is a subset of the union of
22972 v6T2 and v7-M, so it is never seen as contributing a new feature.
22973 We can not search for the last entry which is entirely used,
22974 because if no CPU is specified we build up only those flags
22975 actually used. Perhaps we should separate out the specified
22976 and implicit cases. Avoid taking this path for -march=all by
22977 checking for contradictory v7-A / v7-M features. */
22978 if (arch == 10
22979 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
22980 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
22981 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
22982 arch = 13;
22983
ee065d83
PB
22984 /* Tag_CPU_name. */
22985 if (selected_cpu_name[0])
22986 {
91d6fa6a 22987 char *q;
ee065d83 22988
91d6fa6a
NC
22989 q = selected_cpu_name;
22990 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
22991 {
22992 int i;
5f4273c7 22993
91d6fa6a
NC
22994 q += 4;
22995 for (i = 0; q[i]; i++)
22996 q[i] = TOUPPER (q[i]);
ee065d83 22997 }
91d6fa6a 22998 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 22999 }
62f3b8c8 23000
ee065d83 23001 /* Tag_CPU_arch. */
ee3c0378 23002 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 23003
62b3e311
PB
23004 /* Tag_CPU_arch_profile. */
23005 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 23006 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 23007 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 23008 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 23009 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 23010 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
62f3b8c8 23011
ee065d83 23012 /* Tag_ARM_ISA_use. */
ee3c0378
AS
23013 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
23014 || arch == 0)
23015 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 23016
ee065d83 23017 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
23018 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
23019 || arch == 0)
23020 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
23021 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 23022
ee065d83 23023 /* Tag_VFP_arch. */
62f3b8c8
PB
23024 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
23025 aeabi_set_attribute_int (Tag_VFP_arch,
23026 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
23027 ? 5 : 6);
23028 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
ee3c0378 23029 aeabi_set_attribute_int (Tag_VFP_arch, 3);
ada65aa3 23030 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
ee3c0378
AS
23031 aeabi_set_attribute_int (Tag_VFP_arch, 4);
23032 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
23033 aeabi_set_attribute_int (Tag_VFP_arch, 2);
23034 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
23035 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
23036 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 23037
4547cb56
NC
23038 /* Tag_ABI_HardFP_use. */
23039 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
23040 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
23041 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
23042
ee065d83 23043 /* Tag_WMMX_arch. */
ee3c0378
AS
23044 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
23045 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
23046 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
23047 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 23048
ee3c0378 23049 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 23050 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
62f3b8c8
PB
23051 aeabi_set_attribute_int
23052 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
23053 ? 2 : 1));
23054
ee3c0378 23055 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
62f3b8c8 23056 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
ee3c0378 23057 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56
NC
23058
23059 /* Tag_DIV_use. */
23060 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_div))
23061 aeabi_set_attribute_int (Tag_DIV_use, 0);
23062 /* Fill this in when gas supports v7a sdiv/udiv.
23063 else if (... v7a with div extension used ...)
23064 aeabi_set_attribute_int (Tag_DIV_use, 2); */
23065 else
23066 aeabi_set_attribute_int (Tag_DIV_use, 1);
ee065d83
PB
23067}
23068
104d59d1 23069/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
23070void
23071arm_md_end (void)
23072{
ee065d83
PB
23073 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
23074 return;
23075
23076 aeabi_set_public_attributes ();
ee065d83 23077}
8463be01 23078#endif /* OBJ_ELF */
ee065d83
PB
23079
23080
23081/* Parse a .cpu directive. */
23082
23083static void
23084s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
23085{
e74cfd16 23086 const struct arm_cpu_option_table *opt;
ee065d83
PB
23087 char *name;
23088 char saved_char;
23089
23090 name = input_line_pointer;
5f4273c7 23091 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23092 input_line_pointer++;
23093 saved_char = *input_line_pointer;
23094 *input_line_pointer = 0;
23095
23096 /* Skip the first "all" entry. */
23097 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
23098 if (streq (opt->name, name))
23099 {
e74cfd16
PB
23100 mcpu_cpu_opt = &opt->value;
23101 selected_cpu = opt->value;
ee065d83 23102 if (opt->canonical_name)
5f4273c7 23103 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
23104 else
23105 {
23106 int i;
23107 for (i = 0; opt->name[i]; i++)
23108 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23109 selected_cpu_name[i] = 0;
23110 }
e74cfd16 23111 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23112 *input_line_pointer = saved_char;
23113 demand_empty_rest_of_line ();
23114 return;
23115 }
23116 as_bad (_("unknown cpu `%s'"), name);
23117 *input_line_pointer = saved_char;
23118 ignore_rest_of_line ();
23119}
23120
23121
23122/* Parse a .arch directive. */
23123
23124static void
23125s_arm_arch (int ignored ATTRIBUTE_UNUSED)
23126{
e74cfd16 23127 const struct arm_arch_option_table *opt;
ee065d83
PB
23128 char saved_char;
23129 char *name;
23130
23131 name = input_line_pointer;
5f4273c7 23132 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23133 input_line_pointer++;
23134 saved_char = *input_line_pointer;
23135 *input_line_pointer = 0;
23136
23137 /* Skip the first "all" entry. */
23138 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23139 if (streq (opt->name, name))
23140 {
e74cfd16
PB
23141 mcpu_cpu_opt = &opt->value;
23142 selected_cpu = opt->value;
5f4273c7 23143 strcpy (selected_cpu_name, opt->name);
e74cfd16 23144 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23145 *input_line_pointer = saved_char;
23146 demand_empty_rest_of_line ();
23147 return;
23148 }
23149
23150 as_bad (_("unknown architecture `%s'\n"), name);
23151 *input_line_pointer = saved_char;
23152 ignore_rest_of_line ();
23153}
23154
23155
7a1d4c38
PB
23156/* Parse a .object_arch directive. */
23157
23158static void
23159s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
23160{
23161 const struct arm_arch_option_table *opt;
23162 char saved_char;
23163 char *name;
23164
23165 name = input_line_pointer;
5f4273c7 23166 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
23167 input_line_pointer++;
23168 saved_char = *input_line_pointer;
23169 *input_line_pointer = 0;
23170
23171 /* Skip the first "all" entry. */
23172 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23173 if (streq (opt->name, name))
23174 {
23175 object_arch = &opt->value;
23176 *input_line_pointer = saved_char;
23177 demand_empty_rest_of_line ();
23178 return;
23179 }
23180
23181 as_bad (_("unknown architecture `%s'\n"), name);
23182 *input_line_pointer = saved_char;
23183 ignore_rest_of_line ();
23184}
23185
ee065d83
PB
23186/* Parse a .fpu directive. */
23187
23188static void
23189s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
23190{
e74cfd16 23191 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
23192 char saved_char;
23193 char *name;
23194
23195 name = input_line_pointer;
5f4273c7 23196 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23197 input_line_pointer++;
23198 saved_char = *input_line_pointer;
23199 *input_line_pointer = 0;
5f4273c7 23200
ee065d83
PB
23201 for (opt = arm_fpus; opt->name != NULL; opt++)
23202 if (streq (opt->name, name))
23203 {
e74cfd16
PB
23204 mfpu_opt = &opt->value;
23205 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23206 *input_line_pointer = saved_char;
23207 demand_empty_rest_of_line ();
23208 return;
23209 }
23210
23211 as_bad (_("unknown floating point format `%s'\n"), name);
23212 *input_line_pointer = saved_char;
23213 ignore_rest_of_line ();
23214}
ee065d83 23215
794ba86a 23216/* Copy symbol information. */
f31fef98 23217
794ba86a
DJ
23218void
23219arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
23220{
23221 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
23222}
e04befd0 23223
f31fef98 23224#ifdef OBJ_ELF
e04befd0
AS
23225/* Given a symbolic attribute NAME, return the proper integer value.
23226 Returns -1 if the attribute is not known. */
f31fef98 23227
e04befd0
AS
23228int
23229arm_convert_symbolic_attribute (const char *name)
23230{
f31fef98
NC
23231 static const struct
23232 {
23233 const char * name;
23234 const int tag;
23235 }
23236 attribute_table[] =
23237 {
23238 /* When you modify this table you should
23239 also modify the list in doc/c-arm.texi. */
e04befd0 23240#define T(tag) {#tag, tag}
f31fef98
NC
23241 T (Tag_CPU_raw_name),
23242 T (Tag_CPU_name),
23243 T (Tag_CPU_arch),
23244 T (Tag_CPU_arch_profile),
23245 T (Tag_ARM_ISA_use),
23246 T (Tag_THUMB_ISA_use),
75375b3e 23247 T (Tag_FP_arch),
f31fef98
NC
23248 T (Tag_VFP_arch),
23249 T (Tag_WMMX_arch),
23250 T (Tag_Advanced_SIMD_arch),
23251 T (Tag_PCS_config),
23252 T (Tag_ABI_PCS_R9_use),
23253 T (Tag_ABI_PCS_RW_data),
23254 T (Tag_ABI_PCS_RO_data),
23255 T (Tag_ABI_PCS_GOT_use),
23256 T (Tag_ABI_PCS_wchar_t),
23257 T (Tag_ABI_FP_rounding),
23258 T (Tag_ABI_FP_denormal),
23259 T (Tag_ABI_FP_exceptions),
23260 T (Tag_ABI_FP_user_exceptions),
23261 T (Tag_ABI_FP_number_model),
75375b3e 23262 T (Tag_ABI_align_needed),
f31fef98 23263 T (Tag_ABI_align8_needed),
75375b3e 23264 T (Tag_ABI_align_preserved),
f31fef98
NC
23265 T (Tag_ABI_align8_preserved),
23266 T (Tag_ABI_enum_size),
23267 T (Tag_ABI_HardFP_use),
23268 T (Tag_ABI_VFP_args),
23269 T (Tag_ABI_WMMX_args),
23270 T (Tag_ABI_optimization_goals),
23271 T (Tag_ABI_FP_optimization_goals),
23272 T (Tag_compatibility),
23273 T (Tag_CPU_unaligned_access),
75375b3e 23274 T (Tag_FP_HP_extension),
f31fef98
NC
23275 T (Tag_VFP_HP_extension),
23276 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
23277 T (Tag_MPextension_use),
23278 T (Tag_DIV_use),
f31fef98
NC
23279 T (Tag_nodefaults),
23280 T (Tag_also_compatible_with),
23281 T (Tag_conformance),
23282 T (Tag_T2EE_use),
23283 T (Tag_Virtualization_use),
cd21e546 23284 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 23285#undef T
f31fef98 23286 };
e04befd0
AS
23287 unsigned int i;
23288
23289 if (name == NULL)
23290 return -1;
23291
f31fef98 23292 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 23293 if (streq (name, attribute_table[i].name))
e04befd0
AS
23294 return attribute_table[i].tag;
23295
23296 return -1;
23297}
267bf995
RR
23298
23299
23300/* Apply sym value for relocations only in the case that
23301 they are for local symbols and you have the respective
23302 architectural feature for blx and simple switches. */
23303int
23304arm_apply_sym_value (struct fix * fixP)
23305{
23306 if (fixP->fx_addsy
23307 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23308 && !S_IS_EXTERNAL (fixP->fx_addsy))
23309 {
23310 switch (fixP->fx_r_type)
23311 {
23312 case BFD_RELOC_ARM_PCREL_BLX:
23313 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23314 if (ARM_IS_FUNC (fixP->fx_addsy))
23315 return 1;
23316 break;
23317
23318 case BFD_RELOC_ARM_PCREL_CALL:
23319 case BFD_RELOC_THUMB_PCREL_BLX:
23320 if (THUMB_IS_FUNC (fixP->fx_addsy))
23321 return 1;
23322 break;
23323
23324 default:
23325 break;
23326 }
23327
23328 }
23329 return 0;
23330}
f31fef98 23331#endif /* OBJ_ELF */
This page took 2.307655 seconds and 4 git commands to generate.