* config/tc-arm.c (arm_ext_v6m): New variable.
[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);
e74cfd16 187static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
b2a5fbdc 188static const arm_feature_set arm_ext_v6m = ARM_FEATURE (ARM_EXT_V6M, 0);
62b3e311 189static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
9e3c6df6 190static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
7e806470
PB
191static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
192static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
193static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
194static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
195static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
196static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
9e3c6df6 197static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
7e806470 198static const arm_feature_set arm_ext_m =
b2a5fbdc 199 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, 0);
60e5ef9f 200static const arm_feature_set arm_ext_mp = ARM_FEATURE (ARM_EXT_MP, 0);
f4c65163 201static const arm_feature_set arm_ext_sec = ARM_FEATURE (ARM_EXT_SEC, 0);
b2a5fbdc 202static const arm_feature_set arm_ext_os = ARM_FEATURE (ARM_EXT_OS, 0);
e74cfd16
PB
203
204static const arm_feature_set arm_arch_any = ARM_ANY;
205static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
206static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
207static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
208
2d447fca
JM
209static const arm_feature_set arm_cext_iwmmxt2 =
210 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
211static const arm_feature_set arm_cext_iwmmxt =
212 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
213static const arm_feature_set arm_cext_xscale =
214 ARM_FEATURE (0, ARM_CEXT_XSCALE);
215static const arm_feature_set arm_cext_maverick =
216 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
217static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
218static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
219static const arm_feature_set fpu_vfp_ext_v1xd =
220 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
221static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
222static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
62f3b8c8 223static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
5287ad62 224static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
225static const arm_feature_set fpu_vfp_ext_d32 =
226 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
227static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
228static const arm_feature_set fpu_vfp_v3_or_neon_ext =
229 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
62f3b8c8
PB
230static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
231static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
232static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
e74cfd16 233
33a392fb 234static int mfloat_abi_opt = -1;
e74cfd16
PB
235/* Record user cpu selection for object attributes. */
236static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
237/* Must be long enough to hold any of the names in arm_cpus. */
238static char selected_cpu_name[16];
7cc69913 239#ifdef OBJ_ELF
deeaaff8
DJ
240# ifdef EABI_DEFAULT
241static int meabi_flags = EABI_DEFAULT;
242# else
d507cf36 243static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 244# endif
e1da3f5b 245
ee3c0378
AS
246static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
247
e1da3f5b 248bfd_boolean
5f4273c7 249arm_is_eabi (void)
e1da3f5b
PB
250{
251 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
252}
7cc69913 253#endif
b99bd4ef 254
b99bd4ef 255#ifdef OBJ_ELF
c19d1205 256/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
257symbolS * GOT_symbol;
258#endif
259
b99bd4ef
NC
260/* 0: assemble for ARM,
261 1: assemble for Thumb,
262 2: assemble for Thumb even though target CPU does not support thumb
263 instructions. */
264static int thumb_mode = 0;
8dc2430f
NC
265/* A value distinct from the possible values for thumb_mode that we
266 can use to record whether thumb_mode has been copied into the
267 tc_frag_data field of a frag. */
268#define MODE_RECORDED (1 << 4)
b99bd4ef 269
e07e6e58
NC
270/* Specifies the intrinsic IT insn behavior mode. */
271enum implicit_it_mode
272{
273 IMPLICIT_IT_MODE_NEVER = 0x00,
274 IMPLICIT_IT_MODE_ARM = 0x01,
275 IMPLICIT_IT_MODE_THUMB = 0x02,
276 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
277};
278static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
279
c19d1205
ZW
280/* If unified_syntax is true, we are processing the new unified
281 ARM/Thumb syntax. Important differences from the old ARM mode:
282
283 - Immediate operands do not require a # prefix.
284 - Conditional affixes always appear at the end of the
285 instruction. (For backward compatibility, those instructions
286 that formerly had them in the middle, continue to accept them
287 there.)
288 - The IT instruction may appear, and if it does is validated
289 against subsequent conditional affixes. It does not generate
290 machine code.
291
292 Important differences from the old Thumb mode:
293
294 - Immediate operands do not require a # prefix.
295 - Most of the V6T2 instructions are only available in unified mode.
296 - The .N and .W suffixes are recognized and honored (it is an error
297 if they cannot be honored).
298 - All instructions set the flags if and only if they have an 's' affix.
299 - Conditional affixes may be used. They are validated against
300 preceding IT instructions. Unlike ARM mode, you cannot use a
301 conditional affix except in the scope of an IT instruction. */
302
303static bfd_boolean unified_syntax = FALSE;
b99bd4ef 304
5287ad62
JB
305enum neon_el_type
306{
dcbf9037 307 NT_invtype,
5287ad62
JB
308 NT_untyped,
309 NT_integer,
310 NT_float,
311 NT_poly,
312 NT_signed,
dcbf9037 313 NT_unsigned
5287ad62
JB
314};
315
316struct neon_type_el
317{
318 enum neon_el_type type;
319 unsigned size;
320};
321
322#define NEON_MAX_TYPE_ELS 4
323
324struct neon_type
325{
326 struct neon_type_el el[NEON_MAX_TYPE_ELS];
327 unsigned elems;
328};
329
e07e6e58
NC
330enum it_instruction_type
331{
332 OUTSIDE_IT_INSN,
333 INSIDE_IT_INSN,
334 INSIDE_IT_LAST_INSN,
335 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
336 if inside, should be the last one. */
337 NEUTRAL_IT_INSN, /* This could be either inside or outside,
338 i.e. BKPT and NOP. */
339 IT_INSN /* The IT insn has been parsed. */
340};
341
b99bd4ef
NC
342struct arm_it
343{
c19d1205 344 const char * error;
b99bd4ef 345 unsigned long instruction;
c19d1205
ZW
346 int size;
347 int size_req;
348 int cond;
037e8744
JB
349 /* "uncond_value" is set to the value in place of the conditional field in
350 unconditional versions of the instruction, or -1 if nothing is
351 appropriate. */
352 int uncond_value;
5287ad62 353 struct neon_type vectype;
88714cb8
DG
354 /* This does not indicate an actual NEON instruction, only that
355 the mnemonic accepts neon-style type suffixes. */
356 int is_neon;
0110f2b8
PB
357 /* Set to the opcode if the instruction needs relaxation.
358 Zero if the instruction is not relaxed. */
359 unsigned long relax;
b99bd4ef
NC
360 struct
361 {
362 bfd_reloc_code_real_type type;
c19d1205
ZW
363 expressionS exp;
364 int pc_rel;
b99bd4ef 365 } reloc;
b99bd4ef 366
e07e6e58
NC
367 enum it_instruction_type it_insn_type;
368
c19d1205
ZW
369 struct
370 {
371 unsigned reg;
ca3f61f7 372 signed int imm;
dcbf9037 373 struct neon_type_el vectype;
ca3f61f7
NC
374 unsigned present : 1; /* Operand present. */
375 unsigned isreg : 1; /* Operand was a register. */
376 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
377 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
378 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 379 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
380 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
381 instructions. This allows us to disambiguate ARM <-> vector insns. */
382 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 383 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 384 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 385 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
386 unsigned hasreloc : 1; /* Operand has relocation suffix. */
387 unsigned writeback : 1; /* Operand has trailing ! */
388 unsigned preind : 1; /* Preindexed address. */
389 unsigned postind : 1; /* Postindexed address. */
390 unsigned negative : 1; /* Index register was negated. */
391 unsigned shifted : 1; /* Shift applied to operation. */
392 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 393 } operands[6];
b99bd4ef
NC
394};
395
c19d1205 396static struct arm_it inst;
b99bd4ef
NC
397
398#define NUM_FLOAT_VALS 8
399
05d2d07e 400const char * fp_const[] =
b99bd4ef
NC
401{
402 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
403};
404
c19d1205 405/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
406#define MAX_LITTLENUMS 6
407
408LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
409
410#define FAIL (-1)
411#define SUCCESS (0)
412
413#define SUFF_S 1
414#define SUFF_D 2
415#define SUFF_E 3
416#define SUFF_P 4
417
c19d1205
ZW
418#define CP_T_X 0x00008000
419#define CP_T_Y 0x00400000
b99bd4ef 420
c19d1205
ZW
421#define CONDS_BIT 0x00100000
422#define LOAD_BIT 0x00100000
b99bd4ef
NC
423
424#define DOUBLE_LOAD_FLAG 0x00000001
425
426struct asm_cond
427{
d3ce72d0 428 const char * template_name;
c921be7d 429 unsigned long value;
b99bd4ef
NC
430};
431
c19d1205 432#define COND_ALWAYS 0xE
b99bd4ef 433
b99bd4ef
NC
434struct asm_psr
435{
d3ce72d0 436 const char * template_name;
c921be7d 437 unsigned long field;
b99bd4ef
NC
438};
439
62b3e311
PB
440struct asm_barrier_opt
441{
d3ce72d0 442 const char * template_name;
c921be7d 443 unsigned long value;
62b3e311
PB
444};
445
2d2255b5 446/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
447#define SPSR_BIT (1 << 22)
448
c19d1205
ZW
449/* The individual PSR flag bits. */
450#define PSR_c (1 << 16)
451#define PSR_x (1 << 17)
452#define PSR_s (1 << 18)
453#define PSR_f (1 << 19)
b99bd4ef 454
c19d1205 455struct reloc_entry
bfae80f2 456{
c921be7d
NC
457 char * name;
458 bfd_reloc_code_real_type reloc;
bfae80f2
RE
459};
460
5287ad62 461enum vfp_reg_pos
bfae80f2 462{
5287ad62
JB
463 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
464 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
465};
466
467enum vfp_ldstm_type
468{
469 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
470};
471
dcbf9037
JB
472/* Bits for DEFINED field in neon_typed_alias. */
473#define NTA_HASTYPE 1
474#define NTA_HASINDEX 2
475
476struct neon_typed_alias
477{
c921be7d
NC
478 unsigned char defined;
479 unsigned char index;
480 struct neon_type_el eltype;
dcbf9037
JB
481};
482
c19d1205
ZW
483/* ARM register categories. This includes coprocessor numbers and various
484 architecture extensions' registers. */
485enum arm_reg_type
bfae80f2 486{
c19d1205
ZW
487 REG_TYPE_RN,
488 REG_TYPE_CP,
489 REG_TYPE_CN,
490 REG_TYPE_FN,
491 REG_TYPE_VFS,
492 REG_TYPE_VFD,
5287ad62 493 REG_TYPE_NQ,
037e8744 494 REG_TYPE_VFSD,
5287ad62 495 REG_TYPE_NDQ,
037e8744 496 REG_TYPE_NSDQ,
c19d1205
ZW
497 REG_TYPE_VFC,
498 REG_TYPE_MVF,
499 REG_TYPE_MVD,
500 REG_TYPE_MVFX,
501 REG_TYPE_MVDX,
502 REG_TYPE_MVAX,
503 REG_TYPE_DSPSC,
504 REG_TYPE_MMXWR,
505 REG_TYPE_MMXWC,
506 REG_TYPE_MMXWCG,
507 REG_TYPE_XSCALE,
bfae80f2
RE
508};
509
dcbf9037
JB
510/* Structure for a hash table entry for a register.
511 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
512 information which states whether a vector type or index is specified (for a
513 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
514struct reg_entry
515{
c921be7d
NC
516 const char * name;
517 unsigned char number;
518 unsigned char type;
519 unsigned char builtin;
520 struct neon_typed_alias * neon;
6c43fab6
RE
521};
522
c19d1205 523/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 524const char * const reg_expected_msgs[] =
c19d1205
ZW
525{
526 N_("ARM register expected"),
527 N_("bad or missing co-processor number"),
528 N_("co-processor register expected"),
529 N_("FPA register expected"),
530 N_("VFP single precision register expected"),
5287ad62
JB
531 N_("VFP/Neon double precision register expected"),
532 N_("Neon quad precision register expected"),
037e8744 533 N_("VFP single or double precision register expected"),
5287ad62 534 N_("Neon double or quad precision register expected"),
037e8744 535 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
536 N_("VFP system register expected"),
537 N_("Maverick MVF register expected"),
538 N_("Maverick MVD register expected"),
539 N_("Maverick MVFX register expected"),
540 N_("Maverick MVDX register expected"),
541 N_("Maverick MVAX register expected"),
542 N_("Maverick DSPSC register expected"),
543 N_("iWMMXt data register expected"),
544 N_("iWMMXt control register expected"),
545 N_("iWMMXt scalar register expected"),
546 N_("XScale accumulator register expected"),
6c43fab6
RE
547};
548
c19d1205
ZW
549/* Some well known registers that we refer to directly elsewhere. */
550#define REG_SP 13
551#define REG_LR 14
552#define REG_PC 15
404ff6b5 553
b99bd4ef
NC
554/* ARM instructions take 4bytes in the object file, Thumb instructions
555 take 2: */
c19d1205 556#define INSN_SIZE 4
b99bd4ef
NC
557
558struct asm_opcode
559{
560 /* Basic string to match. */
d3ce72d0 561 const char * template_name;
c19d1205
ZW
562
563 /* Parameters to instruction. */
5be8be5d 564 unsigned int operands[8];
c19d1205
ZW
565
566 /* Conditional tag - see opcode_lookup. */
567 unsigned int tag : 4;
b99bd4ef
NC
568
569 /* Basic instruction code. */
c19d1205 570 unsigned int avalue : 28;
b99bd4ef 571
c19d1205
ZW
572 /* Thumb-format instruction code. */
573 unsigned int tvalue;
b99bd4ef 574
90e4755a 575 /* Which architecture variant provides this instruction. */
c921be7d
NC
576 const arm_feature_set * avariant;
577 const arm_feature_set * tvariant;
c19d1205
ZW
578
579 /* Function to call to encode instruction in ARM format. */
580 void (* aencode) (void);
b99bd4ef 581
c19d1205
ZW
582 /* Function to call to encode instruction in Thumb format. */
583 void (* tencode) (void);
b99bd4ef
NC
584};
585
a737bd4d
NC
586/* Defines for various bits that we will want to toggle. */
587#define INST_IMMEDIATE 0x02000000
588#define OFFSET_REG 0x02000000
c19d1205 589#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
590#define SHIFT_BY_REG 0x00000010
591#define PRE_INDEX 0x01000000
592#define INDEX_UP 0x00800000
593#define WRITE_BACK 0x00200000
594#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 595#define CPSI_MMOD 0x00020000
90e4755a 596
a737bd4d
NC
597#define LITERAL_MASK 0xf000f000
598#define OPCODE_MASK 0xfe1fffff
599#define V4_STR_BIT 0x00000020
90e4755a 600
efd81785
PB
601#define T2_SUBS_PC_LR 0xf3de8f00
602
a737bd4d 603#define DATA_OP_SHIFT 21
90e4755a 604
ef8d22e6
PB
605#define T2_OPCODE_MASK 0xfe1fffff
606#define T2_DATA_OP_SHIFT 21
607
a737bd4d
NC
608/* Codes to distinguish the arithmetic instructions. */
609#define OPCODE_AND 0
610#define OPCODE_EOR 1
611#define OPCODE_SUB 2
612#define OPCODE_RSB 3
613#define OPCODE_ADD 4
614#define OPCODE_ADC 5
615#define OPCODE_SBC 6
616#define OPCODE_RSC 7
617#define OPCODE_TST 8
618#define OPCODE_TEQ 9
619#define OPCODE_CMP 10
620#define OPCODE_CMN 11
621#define OPCODE_ORR 12
622#define OPCODE_MOV 13
623#define OPCODE_BIC 14
624#define OPCODE_MVN 15
90e4755a 625
ef8d22e6
PB
626#define T2_OPCODE_AND 0
627#define T2_OPCODE_BIC 1
628#define T2_OPCODE_ORR 2
629#define T2_OPCODE_ORN 3
630#define T2_OPCODE_EOR 4
631#define T2_OPCODE_ADD 8
632#define T2_OPCODE_ADC 10
633#define T2_OPCODE_SBC 11
634#define T2_OPCODE_SUB 13
635#define T2_OPCODE_RSB 14
636
a737bd4d
NC
637#define T_OPCODE_MUL 0x4340
638#define T_OPCODE_TST 0x4200
639#define T_OPCODE_CMN 0x42c0
640#define T_OPCODE_NEG 0x4240
641#define T_OPCODE_MVN 0x43c0
90e4755a 642
a737bd4d
NC
643#define T_OPCODE_ADD_R3 0x1800
644#define T_OPCODE_SUB_R3 0x1a00
645#define T_OPCODE_ADD_HI 0x4400
646#define T_OPCODE_ADD_ST 0xb000
647#define T_OPCODE_SUB_ST 0xb080
648#define T_OPCODE_ADD_SP 0xa800
649#define T_OPCODE_ADD_PC 0xa000
650#define T_OPCODE_ADD_I8 0x3000
651#define T_OPCODE_SUB_I8 0x3800
652#define T_OPCODE_ADD_I3 0x1c00
653#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 654
a737bd4d
NC
655#define T_OPCODE_ASR_R 0x4100
656#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
657#define T_OPCODE_LSR_R 0x40c0
658#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
659#define T_OPCODE_ASR_I 0x1000
660#define T_OPCODE_LSL_I 0x0000
661#define T_OPCODE_LSR_I 0x0800
b99bd4ef 662
a737bd4d
NC
663#define T_OPCODE_MOV_I8 0x2000
664#define T_OPCODE_CMP_I8 0x2800
665#define T_OPCODE_CMP_LR 0x4280
666#define T_OPCODE_MOV_HR 0x4600
667#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 668
a737bd4d
NC
669#define T_OPCODE_LDR_PC 0x4800
670#define T_OPCODE_LDR_SP 0x9800
671#define T_OPCODE_STR_SP 0x9000
672#define T_OPCODE_LDR_IW 0x6800
673#define T_OPCODE_STR_IW 0x6000
674#define T_OPCODE_LDR_IH 0x8800
675#define T_OPCODE_STR_IH 0x8000
676#define T_OPCODE_LDR_IB 0x7800
677#define T_OPCODE_STR_IB 0x7000
678#define T_OPCODE_LDR_RW 0x5800
679#define T_OPCODE_STR_RW 0x5000
680#define T_OPCODE_LDR_RH 0x5a00
681#define T_OPCODE_STR_RH 0x5200
682#define T_OPCODE_LDR_RB 0x5c00
683#define T_OPCODE_STR_RB 0x5400
c9b604bd 684
a737bd4d
NC
685#define T_OPCODE_PUSH 0xb400
686#define T_OPCODE_POP 0xbc00
b99bd4ef 687
2fc8bdac 688#define T_OPCODE_BRANCH 0xe000
b99bd4ef 689
a737bd4d 690#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 691#define THUMB_PP_PC_LR 0x0100
c19d1205 692#define THUMB_LOAD_BIT 0x0800
53365c0d 693#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
694
695#define BAD_ARGS _("bad arguments to instruction")
fdfde340 696#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
697#define BAD_PC _("r15 not allowed here")
698#define BAD_COND _("instruction cannot be conditional")
699#define BAD_OVERLAP _("registers may not be the same")
700#define BAD_HIREG _("lo register required")
701#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 702#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
703#define BAD_BRANCH _("branch must be last instruction in IT block")
704#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 705#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
706#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
707#define BAD_IT_COND _("incorrect condition in IT block")
708#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 709#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
710#define BAD_PC_ADDRESSING \
711 _("cannot use register index with PC-relative addressing")
712#define BAD_PC_WRITEBACK \
713 _("cannot use writeback with PC-relative addressing")
c19d1205 714
c921be7d
NC
715static struct hash_control * arm_ops_hsh;
716static struct hash_control * arm_cond_hsh;
717static struct hash_control * arm_shift_hsh;
718static struct hash_control * arm_psr_hsh;
719static struct hash_control * arm_v7m_psr_hsh;
720static struct hash_control * arm_reg_hsh;
721static struct hash_control * arm_reloc_hsh;
722static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 723
b99bd4ef
NC
724/* Stuff needed to resolve the label ambiguity
725 As:
726 ...
727 label: <insn>
728 may differ from:
729 ...
730 label:
5f4273c7 731 <insn> */
b99bd4ef
NC
732
733symbolS * last_label_seen;
b34976b6 734static int label_is_thumb_function_name = FALSE;
e07e6e58 735
3d0c9500
NC
736/* Literal pool structure. Held on a per-section
737 and per-sub-section basis. */
a737bd4d 738
c19d1205 739#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 740typedef struct literal_pool
b99bd4ef 741{
c921be7d
NC
742 expressionS literals [MAX_LITERAL_POOL_SIZE];
743 unsigned int next_free_entry;
744 unsigned int id;
745 symbolS * symbol;
746 segT section;
747 subsegT sub_section;
748 struct literal_pool * next;
3d0c9500 749} literal_pool;
b99bd4ef 750
3d0c9500
NC
751/* Pointer to a linked list of literal pools. */
752literal_pool * list_of_pools = NULL;
e27ec89e 753
e07e6e58
NC
754#ifdef OBJ_ELF
755# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
756#else
757static struct current_it now_it;
758#endif
759
760static inline int
761now_it_compatible (int cond)
762{
763 return (cond & ~1) == (now_it.cc & ~1);
764}
765
766static inline int
767conditional_insn (void)
768{
769 return inst.cond != COND_ALWAYS;
770}
771
772static int in_it_block (void);
773
774static int handle_it_state (void);
775
776static void force_automatic_it_block_close (void);
777
c921be7d
NC
778static void it_fsm_post_encode (void);
779
e07e6e58
NC
780#define set_it_insn_type(type) \
781 do \
782 { \
783 inst.it_insn_type = type; \
784 if (handle_it_state () == FAIL) \
785 return; \
786 } \
787 while (0)
788
c921be7d
NC
789#define set_it_insn_type_nonvoid(type, failret) \
790 do \
791 { \
792 inst.it_insn_type = type; \
793 if (handle_it_state () == FAIL) \
794 return failret; \
795 } \
796 while(0)
797
e07e6e58
NC
798#define set_it_insn_type_last() \
799 do \
800 { \
801 if (inst.cond == COND_ALWAYS) \
802 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
803 else \
804 set_it_insn_type (INSIDE_IT_LAST_INSN); \
805 } \
806 while (0)
807
c19d1205 808/* Pure syntax. */
b99bd4ef 809
c19d1205
ZW
810/* This array holds the chars that always start a comment. If the
811 pre-processor is disabled, these aren't very useful. */
812const char comment_chars[] = "@";
3d0c9500 813
c19d1205
ZW
814/* This array holds the chars that only start a comment at the beginning of
815 a line. If the line seems to have the form '# 123 filename'
816 .line and .file directives will appear in the pre-processed output. */
817/* Note that input_file.c hand checks for '#' at the beginning of the
818 first line of the input file. This is because the compiler outputs
819 #NO_APP at the beginning of its output. */
820/* Also note that comments like this one will always work. */
821const char line_comment_chars[] = "#";
3d0c9500 822
c19d1205 823const char line_separator_chars[] = ";";
b99bd4ef 824
c19d1205
ZW
825/* Chars that can be used to separate mant
826 from exp in floating point numbers. */
827const char EXP_CHARS[] = "eE";
3d0c9500 828
c19d1205
ZW
829/* Chars that mean this number is a floating point constant. */
830/* As in 0f12.456 */
831/* or 0d1.2345e12 */
b99bd4ef 832
c19d1205 833const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 834
c19d1205
ZW
835/* Prefix characters that indicate the start of an immediate
836 value. */
837#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 838
c19d1205
ZW
839/* Separator character handling. */
840
841#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
842
843static inline int
844skip_past_char (char ** str, char c)
845{
846 if (**str == c)
847 {
848 (*str)++;
849 return SUCCESS;
3d0c9500 850 }
c19d1205
ZW
851 else
852 return FAIL;
853}
c921be7d 854
c19d1205 855#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 856
c19d1205
ZW
857/* Arithmetic expressions (possibly involving symbols). */
858
859/* Return TRUE if anything in the expression is a bignum. */
860
861static int
862walk_no_bignums (symbolS * sp)
863{
864 if (symbol_get_value_expression (sp)->X_op == O_big)
865 return 1;
866
867 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 868 {
c19d1205
ZW
869 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
870 || (symbol_get_value_expression (sp)->X_op_symbol
871 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
872 }
873
c19d1205 874 return 0;
3d0c9500
NC
875}
876
c19d1205
ZW
877static int in_my_get_expression = 0;
878
879/* Third argument to my_get_expression. */
880#define GE_NO_PREFIX 0
881#define GE_IMM_PREFIX 1
882#define GE_OPT_PREFIX 2
5287ad62
JB
883/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
884 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
885#define GE_OPT_PREFIX_BIG 3
a737bd4d 886
b99bd4ef 887static int
c19d1205 888my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 889{
c19d1205
ZW
890 char * save_in;
891 segT seg;
b99bd4ef 892
c19d1205
ZW
893 /* In unified syntax, all prefixes are optional. */
894 if (unified_syntax)
5287ad62
JB
895 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
896 : GE_OPT_PREFIX;
b99bd4ef 897
c19d1205 898 switch (prefix_mode)
b99bd4ef 899 {
c19d1205
ZW
900 case GE_NO_PREFIX: break;
901 case GE_IMM_PREFIX:
902 if (!is_immediate_prefix (**str))
903 {
904 inst.error = _("immediate expression requires a # prefix");
905 return FAIL;
906 }
907 (*str)++;
908 break;
909 case GE_OPT_PREFIX:
5287ad62 910 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
911 if (is_immediate_prefix (**str))
912 (*str)++;
913 break;
914 default: abort ();
915 }
b99bd4ef 916
c19d1205 917 memset (ep, 0, sizeof (expressionS));
b99bd4ef 918
c19d1205
ZW
919 save_in = input_line_pointer;
920 input_line_pointer = *str;
921 in_my_get_expression = 1;
922 seg = expression (ep);
923 in_my_get_expression = 0;
924
f86adc07 925 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 926 {
f86adc07 927 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
928 *str = input_line_pointer;
929 input_line_pointer = save_in;
930 if (inst.error == NULL)
f86adc07
NS
931 inst.error = (ep->X_op == O_absent
932 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
933 return 1;
934 }
b99bd4ef 935
c19d1205
ZW
936#ifdef OBJ_AOUT
937 if (seg != absolute_section
938 && seg != text_section
939 && seg != data_section
940 && seg != bss_section
941 && seg != undefined_section)
942 {
943 inst.error = _("bad segment");
944 *str = input_line_pointer;
945 input_line_pointer = save_in;
946 return 1;
b99bd4ef 947 }
87975d2a
AM
948#else
949 (void) seg;
c19d1205 950#endif
b99bd4ef 951
c19d1205
ZW
952 /* Get rid of any bignums now, so that we don't generate an error for which
953 we can't establish a line number later on. Big numbers are never valid
954 in instructions, which is where this routine is always called. */
5287ad62
JB
955 if (prefix_mode != GE_OPT_PREFIX_BIG
956 && (ep->X_op == O_big
957 || (ep->X_add_symbol
958 && (walk_no_bignums (ep->X_add_symbol)
959 || (ep->X_op_symbol
960 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
961 {
962 inst.error = _("invalid constant");
963 *str = input_line_pointer;
964 input_line_pointer = save_in;
965 return 1;
966 }
b99bd4ef 967
c19d1205
ZW
968 *str = input_line_pointer;
969 input_line_pointer = save_in;
970 return 0;
b99bd4ef
NC
971}
972
c19d1205
ZW
973/* Turn a string in input_line_pointer into a floating point constant
974 of type TYPE, and store the appropriate bytes in *LITP. The number
975 of LITTLENUMS emitted is stored in *SIZEP. An error message is
976 returned, or NULL on OK.
b99bd4ef 977
c19d1205
ZW
978 Note that fp constants aren't represent in the normal way on the ARM.
979 In big endian mode, things are as expected. However, in little endian
980 mode fp constants are big-endian word-wise, and little-endian byte-wise
981 within the words. For example, (double) 1.1 in big endian mode is
982 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
983 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 984
c19d1205 985 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 986
c19d1205
ZW
987char *
988md_atof (int type, char * litP, int * sizeP)
989{
990 int prec;
991 LITTLENUM_TYPE words[MAX_LITTLENUMS];
992 char *t;
993 int i;
b99bd4ef 994
c19d1205
ZW
995 switch (type)
996 {
997 case 'f':
998 case 'F':
999 case 's':
1000 case 'S':
1001 prec = 2;
1002 break;
b99bd4ef 1003
c19d1205
ZW
1004 case 'd':
1005 case 'D':
1006 case 'r':
1007 case 'R':
1008 prec = 4;
1009 break;
b99bd4ef 1010
c19d1205
ZW
1011 case 'x':
1012 case 'X':
499ac353 1013 prec = 5;
c19d1205 1014 break;
b99bd4ef 1015
c19d1205
ZW
1016 case 'p':
1017 case 'P':
499ac353 1018 prec = 5;
c19d1205 1019 break;
a737bd4d 1020
c19d1205
ZW
1021 default:
1022 *sizeP = 0;
499ac353 1023 return _("Unrecognized or unsupported floating point constant");
c19d1205 1024 }
b99bd4ef 1025
c19d1205
ZW
1026 t = atof_ieee (input_line_pointer, type, words);
1027 if (t)
1028 input_line_pointer = t;
499ac353 1029 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1030
c19d1205
ZW
1031 if (target_big_endian)
1032 {
1033 for (i = 0; i < prec; i++)
1034 {
499ac353
NC
1035 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1036 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1037 }
1038 }
1039 else
1040 {
e74cfd16 1041 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1042 for (i = prec - 1; i >= 0; i--)
1043 {
499ac353
NC
1044 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1045 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1046 }
1047 else
1048 /* For a 4 byte float the order of elements in `words' is 1 0.
1049 For an 8 byte float the order is 1 0 3 2. */
1050 for (i = 0; i < prec; i += 2)
1051 {
499ac353
NC
1052 md_number_to_chars (litP, (valueT) words[i + 1],
1053 sizeof (LITTLENUM_TYPE));
1054 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1055 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1056 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1057 }
1058 }
b99bd4ef 1059
499ac353 1060 return NULL;
c19d1205 1061}
b99bd4ef 1062
c19d1205
ZW
1063/* We handle all bad expressions here, so that we can report the faulty
1064 instruction in the error message. */
1065void
91d6fa6a 1066md_operand (expressionS * exp)
c19d1205
ZW
1067{
1068 if (in_my_get_expression)
91d6fa6a 1069 exp->X_op = O_illegal;
b99bd4ef
NC
1070}
1071
c19d1205 1072/* Immediate values. */
b99bd4ef 1073
c19d1205
ZW
1074/* Generic immediate-value read function for use in directives.
1075 Accepts anything that 'expression' can fold to a constant.
1076 *val receives the number. */
1077#ifdef OBJ_ELF
1078static int
1079immediate_for_directive (int *val)
b99bd4ef 1080{
c19d1205
ZW
1081 expressionS exp;
1082 exp.X_op = O_illegal;
b99bd4ef 1083
c19d1205
ZW
1084 if (is_immediate_prefix (*input_line_pointer))
1085 {
1086 input_line_pointer++;
1087 expression (&exp);
1088 }
b99bd4ef 1089
c19d1205
ZW
1090 if (exp.X_op != O_constant)
1091 {
1092 as_bad (_("expected #constant"));
1093 ignore_rest_of_line ();
1094 return FAIL;
1095 }
1096 *val = exp.X_add_number;
1097 return SUCCESS;
b99bd4ef 1098}
c19d1205 1099#endif
b99bd4ef 1100
c19d1205 1101/* Register parsing. */
b99bd4ef 1102
c19d1205
ZW
1103/* Generic register parser. CCP points to what should be the
1104 beginning of a register name. If it is indeed a valid register
1105 name, advance CCP over it and return the reg_entry structure;
1106 otherwise return NULL. Does not issue diagnostics. */
1107
1108static struct reg_entry *
1109arm_reg_parse_multi (char **ccp)
b99bd4ef 1110{
c19d1205
ZW
1111 char *start = *ccp;
1112 char *p;
1113 struct reg_entry *reg;
b99bd4ef 1114
c19d1205
ZW
1115#ifdef REGISTER_PREFIX
1116 if (*start != REGISTER_PREFIX)
01cfc07f 1117 return NULL;
c19d1205
ZW
1118 start++;
1119#endif
1120#ifdef OPTIONAL_REGISTER_PREFIX
1121 if (*start == OPTIONAL_REGISTER_PREFIX)
1122 start++;
1123#endif
b99bd4ef 1124
c19d1205
ZW
1125 p = start;
1126 if (!ISALPHA (*p) || !is_name_beginner (*p))
1127 return NULL;
b99bd4ef 1128
c19d1205
ZW
1129 do
1130 p++;
1131 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1132
1133 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1134
1135 if (!reg)
1136 return NULL;
1137
1138 *ccp = p;
1139 return reg;
b99bd4ef
NC
1140}
1141
1142static int
dcbf9037
JB
1143arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1144 enum arm_reg_type type)
b99bd4ef 1145{
c19d1205
ZW
1146 /* Alternative syntaxes are accepted for a few register classes. */
1147 switch (type)
1148 {
1149 case REG_TYPE_MVF:
1150 case REG_TYPE_MVD:
1151 case REG_TYPE_MVFX:
1152 case REG_TYPE_MVDX:
1153 /* Generic coprocessor register names are allowed for these. */
79134647 1154 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1155 return reg->number;
1156 break;
69b97547 1157
c19d1205
ZW
1158 case REG_TYPE_CP:
1159 /* For backward compatibility, a bare number is valid here. */
1160 {
1161 unsigned long processor = strtoul (start, ccp, 10);
1162 if (*ccp != start && processor <= 15)
1163 return processor;
1164 }
6057a28f 1165
c19d1205
ZW
1166 case REG_TYPE_MMXWC:
1167 /* WC includes WCG. ??? I'm not sure this is true for all
1168 instructions that take WC registers. */
79134647 1169 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1170 return reg->number;
6057a28f 1171 break;
c19d1205 1172
6057a28f 1173 default:
c19d1205 1174 break;
6057a28f
NC
1175 }
1176
dcbf9037
JB
1177 return FAIL;
1178}
1179
1180/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1181 return value is the register number or FAIL. */
1182
1183static int
1184arm_reg_parse (char **ccp, enum arm_reg_type type)
1185{
1186 char *start = *ccp;
1187 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1188 int ret;
1189
1190 /* Do not allow a scalar (reg+index) to parse as a register. */
1191 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1192 return FAIL;
1193
1194 if (reg && reg->type == type)
1195 return reg->number;
1196
1197 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1198 return ret;
1199
c19d1205
ZW
1200 *ccp = start;
1201 return FAIL;
1202}
69b97547 1203
dcbf9037
JB
1204/* Parse a Neon type specifier. *STR should point at the leading '.'
1205 character. Does no verification at this stage that the type fits the opcode
1206 properly. E.g.,
1207
1208 .i32.i32.s16
1209 .s32.f32
1210 .u16
1211
1212 Can all be legally parsed by this function.
1213
1214 Fills in neon_type struct pointer with parsed information, and updates STR
1215 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1216 type, FAIL if not. */
1217
1218static int
1219parse_neon_type (struct neon_type *type, char **str)
1220{
1221 char *ptr = *str;
1222
1223 if (type)
1224 type->elems = 0;
1225
1226 while (type->elems < NEON_MAX_TYPE_ELS)
1227 {
1228 enum neon_el_type thistype = NT_untyped;
1229 unsigned thissize = -1u;
1230
1231 if (*ptr != '.')
1232 break;
1233
1234 ptr++;
1235
1236 /* Just a size without an explicit type. */
1237 if (ISDIGIT (*ptr))
1238 goto parsesize;
1239
1240 switch (TOLOWER (*ptr))
1241 {
1242 case 'i': thistype = NT_integer; break;
1243 case 'f': thistype = NT_float; break;
1244 case 'p': thistype = NT_poly; break;
1245 case 's': thistype = NT_signed; break;
1246 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1247 case 'd':
1248 thistype = NT_float;
1249 thissize = 64;
1250 ptr++;
1251 goto done;
dcbf9037
JB
1252 default:
1253 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1254 return FAIL;
1255 }
1256
1257 ptr++;
1258
1259 /* .f is an abbreviation for .f32. */
1260 if (thistype == NT_float && !ISDIGIT (*ptr))
1261 thissize = 32;
1262 else
1263 {
1264 parsesize:
1265 thissize = strtoul (ptr, &ptr, 10);
1266
1267 if (thissize != 8 && thissize != 16 && thissize != 32
1268 && thissize != 64)
1269 {
1270 as_bad (_("bad size %d in type specifier"), thissize);
1271 return FAIL;
1272 }
1273 }
1274
037e8744 1275 done:
dcbf9037
JB
1276 if (type)
1277 {
1278 type->el[type->elems].type = thistype;
1279 type->el[type->elems].size = thissize;
1280 type->elems++;
1281 }
1282 }
1283
1284 /* Empty/missing type is not a successful parse. */
1285 if (type->elems == 0)
1286 return FAIL;
1287
1288 *str = ptr;
1289
1290 return SUCCESS;
1291}
1292
1293/* Errors may be set multiple times during parsing or bit encoding
1294 (particularly in the Neon bits), but usually the earliest error which is set
1295 will be the most meaningful. Avoid overwriting it with later (cascading)
1296 errors by calling this function. */
1297
1298static void
1299first_error (const char *err)
1300{
1301 if (!inst.error)
1302 inst.error = err;
1303}
1304
1305/* Parse a single type, e.g. ".s32", leading period included. */
1306static int
1307parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1308{
1309 char *str = *ccp;
1310 struct neon_type optype;
1311
1312 if (*str == '.')
1313 {
1314 if (parse_neon_type (&optype, &str) == SUCCESS)
1315 {
1316 if (optype.elems == 1)
1317 *vectype = optype.el[0];
1318 else
1319 {
1320 first_error (_("only one type should be specified for operand"));
1321 return FAIL;
1322 }
1323 }
1324 else
1325 {
1326 first_error (_("vector type expected"));
1327 return FAIL;
1328 }
1329 }
1330 else
1331 return FAIL;
5f4273c7 1332
dcbf9037 1333 *ccp = str;
5f4273c7 1334
dcbf9037
JB
1335 return SUCCESS;
1336}
1337
1338/* Special meanings for indices (which have a range of 0-7), which will fit into
1339 a 4-bit integer. */
1340
1341#define NEON_ALL_LANES 15
1342#define NEON_INTERLEAVE_LANES 14
1343
1344/* Parse either a register or a scalar, with an optional type. Return the
1345 register number, and optionally fill in the actual type of the register
1346 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1347 type/index information in *TYPEINFO. */
1348
1349static int
1350parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1351 enum arm_reg_type *rtype,
1352 struct neon_typed_alias *typeinfo)
1353{
1354 char *str = *ccp;
1355 struct reg_entry *reg = arm_reg_parse_multi (&str);
1356 struct neon_typed_alias atype;
1357 struct neon_type_el parsetype;
1358
1359 atype.defined = 0;
1360 atype.index = -1;
1361 atype.eltype.type = NT_invtype;
1362 atype.eltype.size = -1;
1363
1364 /* Try alternate syntax for some types of register. Note these are mutually
1365 exclusive with the Neon syntax extensions. */
1366 if (reg == NULL)
1367 {
1368 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1369 if (altreg != FAIL)
1370 *ccp = str;
1371 if (typeinfo)
1372 *typeinfo = atype;
1373 return altreg;
1374 }
1375
037e8744
JB
1376 /* Undo polymorphism when a set of register types may be accepted. */
1377 if ((type == REG_TYPE_NDQ
1378 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1379 || (type == REG_TYPE_VFSD
1380 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1381 || (type == REG_TYPE_NSDQ
1382 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1383 || reg->type == REG_TYPE_NQ))
1384 || (type == REG_TYPE_MMXWC
1385 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1386 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1387
1388 if (type != reg->type)
1389 return FAIL;
1390
1391 if (reg->neon)
1392 atype = *reg->neon;
5f4273c7 1393
dcbf9037
JB
1394 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1395 {
1396 if ((atype.defined & NTA_HASTYPE) != 0)
1397 {
1398 first_error (_("can't redefine type for operand"));
1399 return FAIL;
1400 }
1401 atype.defined |= NTA_HASTYPE;
1402 atype.eltype = parsetype;
1403 }
5f4273c7 1404
dcbf9037
JB
1405 if (skip_past_char (&str, '[') == SUCCESS)
1406 {
1407 if (type != REG_TYPE_VFD)
1408 {
1409 first_error (_("only D registers may be indexed"));
1410 return FAIL;
1411 }
5f4273c7 1412
dcbf9037
JB
1413 if ((atype.defined & NTA_HASINDEX) != 0)
1414 {
1415 first_error (_("can't change index for operand"));
1416 return FAIL;
1417 }
1418
1419 atype.defined |= NTA_HASINDEX;
1420
1421 if (skip_past_char (&str, ']') == SUCCESS)
1422 atype.index = NEON_ALL_LANES;
1423 else
1424 {
1425 expressionS exp;
1426
1427 my_get_expression (&exp, &str, GE_NO_PREFIX);
1428
1429 if (exp.X_op != O_constant)
1430 {
1431 first_error (_("constant expression required"));
1432 return FAIL;
1433 }
1434
1435 if (skip_past_char (&str, ']') == FAIL)
1436 return FAIL;
1437
1438 atype.index = exp.X_add_number;
1439 }
1440 }
5f4273c7 1441
dcbf9037
JB
1442 if (typeinfo)
1443 *typeinfo = atype;
5f4273c7 1444
dcbf9037
JB
1445 if (rtype)
1446 *rtype = type;
5f4273c7 1447
dcbf9037 1448 *ccp = str;
5f4273c7 1449
dcbf9037
JB
1450 return reg->number;
1451}
1452
1453/* Like arm_reg_parse, but allow allow the following extra features:
1454 - If RTYPE is non-zero, return the (possibly restricted) type of the
1455 register (e.g. Neon double or quad reg when either has been requested).
1456 - If this is a Neon vector type with additional type information, fill
1457 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1458 This function will fault on encountering a scalar. */
dcbf9037
JB
1459
1460static int
1461arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1462 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1463{
1464 struct neon_typed_alias atype;
1465 char *str = *ccp;
1466 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1467
1468 if (reg == FAIL)
1469 return FAIL;
1470
1471 /* Do not allow a scalar (reg+index) to parse as a register. */
1472 if ((atype.defined & NTA_HASINDEX) != 0)
1473 {
1474 first_error (_("register operand expected, but got scalar"));
1475 return FAIL;
1476 }
1477
1478 if (vectype)
1479 *vectype = atype.eltype;
1480
1481 *ccp = str;
1482
1483 return reg;
1484}
1485
1486#define NEON_SCALAR_REG(X) ((X) >> 4)
1487#define NEON_SCALAR_INDEX(X) ((X) & 15)
1488
5287ad62
JB
1489/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1490 have enough information to be able to do a good job bounds-checking. So, we
1491 just do easy checks here, and do further checks later. */
1492
1493static int
dcbf9037 1494parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1495{
dcbf9037 1496 int reg;
5287ad62 1497 char *str = *ccp;
dcbf9037 1498 struct neon_typed_alias atype;
5f4273c7 1499
dcbf9037 1500 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1501
dcbf9037 1502 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1503 return FAIL;
5f4273c7 1504
dcbf9037 1505 if (atype.index == NEON_ALL_LANES)
5287ad62 1506 {
dcbf9037 1507 first_error (_("scalar must have an index"));
5287ad62
JB
1508 return FAIL;
1509 }
dcbf9037 1510 else if (atype.index >= 64 / elsize)
5287ad62 1511 {
dcbf9037 1512 first_error (_("scalar index out of range"));
5287ad62
JB
1513 return FAIL;
1514 }
5f4273c7 1515
dcbf9037
JB
1516 if (type)
1517 *type = atype.eltype;
5f4273c7 1518
5287ad62 1519 *ccp = str;
5f4273c7 1520
dcbf9037 1521 return reg * 16 + atype.index;
5287ad62
JB
1522}
1523
c19d1205 1524/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1525
c19d1205
ZW
1526static long
1527parse_reg_list (char ** strp)
1528{
1529 char * str = * strp;
1530 long range = 0;
1531 int another_range;
a737bd4d 1532
c19d1205
ZW
1533 /* We come back here if we get ranges concatenated by '+' or '|'. */
1534 do
6057a28f 1535 {
c19d1205 1536 another_range = 0;
a737bd4d 1537
c19d1205
ZW
1538 if (*str == '{')
1539 {
1540 int in_range = 0;
1541 int cur_reg = -1;
a737bd4d 1542
c19d1205
ZW
1543 str++;
1544 do
1545 {
1546 int reg;
6057a28f 1547
dcbf9037 1548 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1549 {
dcbf9037 1550 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1551 return FAIL;
1552 }
a737bd4d 1553
c19d1205
ZW
1554 if (in_range)
1555 {
1556 int i;
a737bd4d 1557
c19d1205
ZW
1558 if (reg <= cur_reg)
1559 {
dcbf9037 1560 first_error (_("bad range in register list"));
c19d1205
ZW
1561 return FAIL;
1562 }
40a18ebd 1563
c19d1205
ZW
1564 for (i = cur_reg + 1; i < reg; i++)
1565 {
1566 if (range & (1 << i))
1567 as_tsktsk
1568 (_("Warning: duplicated register (r%d) in register list"),
1569 i);
1570 else
1571 range |= 1 << i;
1572 }
1573 in_range = 0;
1574 }
a737bd4d 1575
c19d1205
ZW
1576 if (range & (1 << reg))
1577 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1578 reg);
1579 else if (reg <= cur_reg)
1580 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1581
c19d1205
ZW
1582 range |= 1 << reg;
1583 cur_reg = reg;
1584 }
1585 while (skip_past_comma (&str) != FAIL
1586 || (in_range = 1, *str++ == '-'));
1587 str--;
a737bd4d 1588
c19d1205
ZW
1589 if (*str++ != '}')
1590 {
dcbf9037 1591 first_error (_("missing `}'"));
c19d1205
ZW
1592 return FAIL;
1593 }
1594 }
1595 else
1596 {
91d6fa6a 1597 expressionS exp;
40a18ebd 1598
91d6fa6a 1599 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1600 return FAIL;
40a18ebd 1601
91d6fa6a 1602 if (exp.X_op == O_constant)
c19d1205 1603 {
91d6fa6a
NC
1604 if (exp.X_add_number
1605 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1606 {
1607 inst.error = _("invalid register mask");
1608 return FAIL;
1609 }
a737bd4d 1610
91d6fa6a 1611 if ((range & exp.X_add_number) != 0)
c19d1205 1612 {
91d6fa6a 1613 int regno = range & exp.X_add_number;
a737bd4d 1614
c19d1205
ZW
1615 regno &= -regno;
1616 regno = (1 << regno) - 1;
1617 as_tsktsk
1618 (_("Warning: duplicated register (r%d) in register list"),
1619 regno);
1620 }
a737bd4d 1621
91d6fa6a 1622 range |= exp.X_add_number;
c19d1205
ZW
1623 }
1624 else
1625 {
1626 if (inst.reloc.type != 0)
1627 {
1628 inst.error = _("expression too complex");
1629 return FAIL;
1630 }
a737bd4d 1631
91d6fa6a 1632 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1633 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1634 inst.reloc.pc_rel = 0;
1635 }
1636 }
a737bd4d 1637
c19d1205
ZW
1638 if (*str == '|' || *str == '+')
1639 {
1640 str++;
1641 another_range = 1;
1642 }
a737bd4d 1643 }
c19d1205 1644 while (another_range);
a737bd4d 1645
c19d1205
ZW
1646 *strp = str;
1647 return range;
a737bd4d
NC
1648}
1649
5287ad62
JB
1650/* Types of registers in a list. */
1651
1652enum reg_list_els
1653{
1654 REGLIST_VFP_S,
1655 REGLIST_VFP_D,
1656 REGLIST_NEON_D
1657};
1658
c19d1205
ZW
1659/* Parse a VFP register list. If the string is invalid return FAIL.
1660 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1661 register. Parses registers of type ETYPE.
1662 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1663 - Q registers can be used to specify pairs of D registers
1664 - { } can be omitted from around a singleton register list
1665 FIXME: This is not implemented, as it would require backtracking in
1666 some cases, e.g.:
1667 vtbl.8 d3,d4,d5
1668 This could be done (the meaning isn't really ambiguous), but doesn't
1669 fit in well with the current parsing framework.
dcbf9037
JB
1670 - 32 D registers may be used (also true for VFPv3).
1671 FIXME: Types are ignored in these register lists, which is probably a
1672 bug. */
6057a28f 1673
c19d1205 1674static int
037e8744 1675parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1676{
037e8744 1677 char *str = *ccp;
c19d1205
ZW
1678 int base_reg;
1679 int new_base;
21d799b5 1680 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1681 int max_regs = 0;
c19d1205
ZW
1682 int count = 0;
1683 int warned = 0;
1684 unsigned long mask = 0;
a737bd4d 1685 int i;
6057a28f 1686
037e8744 1687 if (*str != '{')
5287ad62
JB
1688 {
1689 inst.error = _("expecting {");
1690 return FAIL;
1691 }
6057a28f 1692
037e8744 1693 str++;
6057a28f 1694
5287ad62 1695 switch (etype)
c19d1205 1696 {
5287ad62 1697 case REGLIST_VFP_S:
c19d1205
ZW
1698 regtype = REG_TYPE_VFS;
1699 max_regs = 32;
5287ad62 1700 break;
5f4273c7 1701
5287ad62
JB
1702 case REGLIST_VFP_D:
1703 regtype = REG_TYPE_VFD;
b7fc2769 1704 break;
5f4273c7 1705
b7fc2769
JB
1706 case REGLIST_NEON_D:
1707 regtype = REG_TYPE_NDQ;
1708 break;
1709 }
1710
1711 if (etype != REGLIST_VFP_S)
1712 {
b1cc4aeb
PB
1713 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1714 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1715 {
1716 max_regs = 32;
1717 if (thumb_mode)
1718 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1719 fpu_vfp_ext_d32);
5287ad62
JB
1720 else
1721 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1722 fpu_vfp_ext_d32);
5287ad62
JB
1723 }
1724 else
1725 max_regs = 16;
c19d1205 1726 }
6057a28f 1727
c19d1205 1728 base_reg = max_regs;
a737bd4d 1729
c19d1205
ZW
1730 do
1731 {
5287ad62 1732 int setmask = 1, addregs = 1;
dcbf9037 1733
037e8744 1734 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1735
c19d1205 1736 if (new_base == FAIL)
a737bd4d 1737 {
dcbf9037 1738 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1739 return FAIL;
1740 }
5f4273c7 1741
b7fc2769
JB
1742 if (new_base >= max_regs)
1743 {
1744 first_error (_("register out of range in list"));
1745 return FAIL;
1746 }
5f4273c7 1747
5287ad62
JB
1748 /* Note: a value of 2 * n is returned for the register Q<n>. */
1749 if (regtype == REG_TYPE_NQ)
1750 {
1751 setmask = 3;
1752 addregs = 2;
1753 }
1754
c19d1205
ZW
1755 if (new_base < base_reg)
1756 base_reg = new_base;
a737bd4d 1757
5287ad62 1758 if (mask & (setmask << new_base))
c19d1205 1759 {
dcbf9037 1760 first_error (_("invalid register list"));
c19d1205 1761 return FAIL;
a737bd4d 1762 }
a737bd4d 1763
c19d1205
ZW
1764 if ((mask >> new_base) != 0 && ! warned)
1765 {
1766 as_tsktsk (_("register list not in ascending order"));
1767 warned = 1;
1768 }
0bbf2aa4 1769
5287ad62
JB
1770 mask |= setmask << new_base;
1771 count += addregs;
0bbf2aa4 1772
037e8744 1773 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1774 {
1775 int high_range;
0bbf2aa4 1776
037e8744 1777 str++;
0bbf2aa4 1778
037e8744 1779 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1780 == FAIL)
c19d1205
ZW
1781 {
1782 inst.error = gettext (reg_expected_msgs[regtype]);
1783 return FAIL;
1784 }
0bbf2aa4 1785
b7fc2769
JB
1786 if (high_range >= max_regs)
1787 {
1788 first_error (_("register out of range in list"));
1789 return FAIL;
1790 }
1791
5287ad62
JB
1792 if (regtype == REG_TYPE_NQ)
1793 high_range = high_range + 1;
1794
c19d1205
ZW
1795 if (high_range <= new_base)
1796 {
1797 inst.error = _("register range not in ascending order");
1798 return FAIL;
1799 }
0bbf2aa4 1800
5287ad62 1801 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1802 {
5287ad62 1803 if (mask & (setmask << new_base))
0bbf2aa4 1804 {
c19d1205
ZW
1805 inst.error = _("invalid register list");
1806 return FAIL;
0bbf2aa4 1807 }
c19d1205 1808
5287ad62
JB
1809 mask |= setmask << new_base;
1810 count += addregs;
0bbf2aa4 1811 }
0bbf2aa4 1812 }
0bbf2aa4 1813 }
037e8744 1814 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1815
037e8744 1816 str++;
0bbf2aa4 1817
c19d1205
ZW
1818 /* Sanity check -- should have raised a parse error above. */
1819 if (count == 0 || count > max_regs)
1820 abort ();
1821
1822 *pbase = base_reg;
1823
1824 /* Final test -- the registers must be consecutive. */
1825 mask >>= base_reg;
1826 for (i = 0; i < count; i++)
1827 {
1828 if ((mask & (1u << i)) == 0)
1829 {
1830 inst.error = _("non-contiguous register range");
1831 return FAIL;
1832 }
1833 }
1834
037e8744
JB
1835 *ccp = str;
1836
c19d1205 1837 return count;
b99bd4ef
NC
1838}
1839
dcbf9037
JB
1840/* True if two alias types are the same. */
1841
c921be7d 1842static bfd_boolean
dcbf9037
JB
1843neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1844{
1845 if (!a && !b)
c921be7d 1846 return TRUE;
5f4273c7 1847
dcbf9037 1848 if (!a || !b)
c921be7d 1849 return FALSE;
dcbf9037
JB
1850
1851 if (a->defined != b->defined)
c921be7d 1852 return FALSE;
5f4273c7 1853
dcbf9037
JB
1854 if ((a->defined & NTA_HASTYPE) != 0
1855 && (a->eltype.type != b->eltype.type
1856 || a->eltype.size != b->eltype.size))
c921be7d 1857 return FALSE;
dcbf9037
JB
1858
1859 if ((a->defined & NTA_HASINDEX) != 0
1860 && (a->index != b->index))
c921be7d 1861 return FALSE;
5f4273c7 1862
c921be7d 1863 return TRUE;
dcbf9037
JB
1864}
1865
5287ad62
JB
1866/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1867 The base register is put in *PBASE.
dcbf9037 1868 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1869 the return value.
1870 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1871 Bits [6:5] encode the list length (minus one).
1872 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1873
5287ad62 1874#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1875#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1876#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1877
1878static int
dcbf9037
JB
1879parse_neon_el_struct_list (char **str, unsigned *pbase,
1880 struct neon_type_el *eltype)
5287ad62
JB
1881{
1882 char *ptr = *str;
1883 int base_reg = -1;
1884 int reg_incr = -1;
1885 int count = 0;
1886 int lane = -1;
1887 int leading_brace = 0;
1888 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1889 const char *const incr_error = _("register stride must be 1 or 2");
1890 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1891 struct neon_typed_alias firsttype;
5f4273c7 1892
5287ad62
JB
1893 if (skip_past_char (&ptr, '{') == SUCCESS)
1894 leading_brace = 1;
5f4273c7 1895
5287ad62
JB
1896 do
1897 {
dcbf9037
JB
1898 struct neon_typed_alias atype;
1899 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1900
5287ad62
JB
1901 if (getreg == FAIL)
1902 {
dcbf9037 1903 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1904 return FAIL;
1905 }
5f4273c7 1906
5287ad62
JB
1907 if (base_reg == -1)
1908 {
1909 base_reg = getreg;
1910 if (rtype == REG_TYPE_NQ)
1911 {
1912 reg_incr = 1;
5287ad62 1913 }
dcbf9037 1914 firsttype = atype;
5287ad62
JB
1915 }
1916 else if (reg_incr == -1)
1917 {
1918 reg_incr = getreg - base_reg;
1919 if (reg_incr < 1 || reg_incr > 2)
1920 {
dcbf9037 1921 first_error (_(incr_error));
5287ad62
JB
1922 return FAIL;
1923 }
1924 }
1925 else if (getreg != base_reg + reg_incr * count)
1926 {
dcbf9037
JB
1927 first_error (_(incr_error));
1928 return FAIL;
1929 }
1930
c921be7d 1931 if (! neon_alias_types_same (&atype, &firsttype))
dcbf9037
JB
1932 {
1933 first_error (_(type_error));
5287ad62
JB
1934 return FAIL;
1935 }
5f4273c7 1936
5287ad62
JB
1937 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1938 modes. */
1939 if (ptr[0] == '-')
1940 {
dcbf9037 1941 struct neon_typed_alias htype;
5287ad62
JB
1942 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1943 if (lane == -1)
1944 lane = NEON_INTERLEAVE_LANES;
1945 else if (lane != NEON_INTERLEAVE_LANES)
1946 {
dcbf9037 1947 first_error (_(type_error));
5287ad62
JB
1948 return FAIL;
1949 }
1950 if (reg_incr == -1)
1951 reg_incr = 1;
1952 else if (reg_incr != 1)
1953 {
dcbf9037 1954 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1955 return FAIL;
1956 }
1957 ptr++;
dcbf9037 1958 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1959 if (hireg == FAIL)
1960 {
dcbf9037
JB
1961 first_error (_(reg_expected_msgs[rtype]));
1962 return FAIL;
1963 }
c921be7d 1964 if (! neon_alias_types_same (&htype, &firsttype))
dcbf9037
JB
1965 {
1966 first_error (_(type_error));
5287ad62
JB
1967 return FAIL;
1968 }
1969 count += hireg + dregs - getreg;
1970 continue;
1971 }
5f4273c7 1972
5287ad62
JB
1973 /* If we're using Q registers, we can't use [] or [n] syntax. */
1974 if (rtype == REG_TYPE_NQ)
1975 {
1976 count += 2;
1977 continue;
1978 }
5f4273c7 1979
dcbf9037 1980 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1981 {
dcbf9037
JB
1982 if (lane == -1)
1983 lane = atype.index;
1984 else if (lane != atype.index)
5287ad62 1985 {
dcbf9037
JB
1986 first_error (_(type_error));
1987 return FAIL;
5287ad62
JB
1988 }
1989 }
1990 else if (lane == -1)
1991 lane = NEON_INTERLEAVE_LANES;
1992 else if (lane != NEON_INTERLEAVE_LANES)
1993 {
dcbf9037 1994 first_error (_(type_error));
5287ad62
JB
1995 return FAIL;
1996 }
1997 count++;
1998 }
1999 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2000
5287ad62
JB
2001 /* No lane set by [x]. We must be interleaving structures. */
2002 if (lane == -1)
2003 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2004
5287ad62
JB
2005 /* Sanity check. */
2006 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2007 || (count > 1 && reg_incr == -1))
2008 {
dcbf9037 2009 first_error (_("error parsing element/structure list"));
5287ad62
JB
2010 return FAIL;
2011 }
2012
2013 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2014 {
dcbf9037 2015 first_error (_("expected }"));
5287ad62
JB
2016 return FAIL;
2017 }
5f4273c7 2018
5287ad62
JB
2019 if (reg_incr == -1)
2020 reg_incr = 1;
2021
dcbf9037
JB
2022 if (eltype)
2023 *eltype = firsttype.eltype;
2024
5287ad62
JB
2025 *pbase = base_reg;
2026 *str = ptr;
5f4273c7 2027
5287ad62
JB
2028 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2029}
2030
c19d1205
ZW
2031/* Parse an explicit relocation suffix on an expression. This is
2032 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2033 arm_reloc_hsh contains no entries, so this function can only
2034 succeed if there is no () after the word. Returns -1 on error,
2035 BFD_RELOC_UNUSED if there wasn't any suffix. */
2036static int
2037parse_reloc (char **str)
b99bd4ef 2038{
c19d1205
ZW
2039 struct reloc_entry *r;
2040 char *p, *q;
b99bd4ef 2041
c19d1205
ZW
2042 if (**str != '(')
2043 return BFD_RELOC_UNUSED;
b99bd4ef 2044
c19d1205
ZW
2045 p = *str + 1;
2046 q = p;
2047
2048 while (*q && *q != ')' && *q != ',')
2049 q++;
2050 if (*q != ')')
2051 return -1;
2052
21d799b5
NC
2053 if ((r = (struct reloc_entry *)
2054 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2055 return -1;
2056
2057 *str = q + 1;
2058 return r->reloc;
b99bd4ef
NC
2059}
2060
c19d1205
ZW
2061/* Directives: register aliases. */
2062
dcbf9037 2063static struct reg_entry *
c19d1205 2064insert_reg_alias (char *str, int number, int type)
b99bd4ef 2065{
d3ce72d0 2066 struct reg_entry *new_reg;
c19d1205 2067 const char *name;
b99bd4ef 2068
d3ce72d0 2069 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2070 {
d3ce72d0 2071 if (new_reg->builtin)
c19d1205 2072 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2073
c19d1205
ZW
2074 /* Only warn about a redefinition if it's not defined as the
2075 same register. */
d3ce72d0 2076 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2077 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2078
d929913e 2079 return NULL;
c19d1205 2080 }
b99bd4ef 2081
c19d1205 2082 name = xstrdup (str);
d3ce72d0 2083 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2084
d3ce72d0
NC
2085 new_reg->name = name;
2086 new_reg->number = number;
2087 new_reg->type = type;
2088 new_reg->builtin = FALSE;
2089 new_reg->neon = NULL;
b99bd4ef 2090
d3ce72d0 2091 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2092 abort ();
5f4273c7 2093
d3ce72d0 2094 return new_reg;
dcbf9037
JB
2095}
2096
2097static void
2098insert_neon_reg_alias (char *str, int number, int type,
2099 struct neon_typed_alias *atype)
2100{
2101 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2102
dcbf9037
JB
2103 if (!reg)
2104 {
2105 first_error (_("attempt to redefine typed alias"));
2106 return;
2107 }
5f4273c7 2108
dcbf9037
JB
2109 if (atype)
2110 {
21d799b5
NC
2111 reg->neon = (struct neon_typed_alias *)
2112 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2113 *reg->neon = *atype;
2114 }
c19d1205 2115}
b99bd4ef 2116
c19d1205 2117/* Look for the .req directive. This is of the form:
b99bd4ef 2118
c19d1205 2119 new_register_name .req existing_register_name
b99bd4ef 2120
c19d1205 2121 If we find one, or if it looks sufficiently like one that we want to
d929913e 2122 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2123
d929913e 2124static bfd_boolean
c19d1205
ZW
2125create_register_alias (char * newname, char *p)
2126{
2127 struct reg_entry *old;
2128 char *oldname, *nbuf;
2129 size_t nlen;
b99bd4ef 2130
c19d1205
ZW
2131 /* The input scrubber ensures that whitespace after the mnemonic is
2132 collapsed to single spaces. */
2133 oldname = p;
2134 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2135 return FALSE;
b99bd4ef 2136
c19d1205
ZW
2137 oldname += 6;
2138 if (*oldname == '\0')
d929913e 2139 return FALSE;
b99bd4ef 2140
21d799b5 2141 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2142 if (!old)
b99bd4ef 2143 {
c19d1205 2144 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2145 return TRUE;
b99bd4ef
NC
2146 }
2147
c19d1205
ZW
2148 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2149 the desired alias name, and p points to its end. If not, then
2150 the desired alias name is in the global original_case_string. */
2151#ifdef TC_CASE_SENSITIVE
2152 nlen = p - newname;
2153#else
2154 newname = original_case_string;
2155 nlen = strlen (newname);
2156#endif
b99bd4ef 2157
21d799b5 2158 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2159 memcpy (nbuf, newname, nlen);
2160 nbuf[nlen] = '\0';
b99bd4ef 2161
c19d1205
ZW
2162 /* Create aliases under the new name as stated; an all-lowercase
2163 version of the new name; and an all-uppercase version of the new
2164 name. */
d929913e
NC
2165 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2166 {
2167 for (p = nbuf; *p; p++)
2168 *p = TOUPPER (*p);
c19d1205 2169
d929913e
NC
2170 if (strncmp (nbuf, newname, nlen))
2171 {
2172 /* If this attempt to create an additional alias fails, do not bother
2173 trying to create the all-lower case alias. We will fail and issue
2174 a second, duplicate error message. This situation arises when the
2175 programmer does something like:
2176 foo .req r0
2177 Foo .req r1
2178 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2179 the artificial FOO alias because it has already been created by the
d929913e
NC
2180 first .req. */
2181 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2182 return TRUE;
2183 }
c19d1205 2184
d929913e
NC
2185 for (p = nbuf; *p; p++)
2186 *p = TOLOWER (*p);
c19d1205 2187
d929913e
NC
2188 if (strncmp (nbuf, newname, nlen))
2189 insert_reg_alias (nbuf, old->number, old->type);
2190 }
c19d1205 2191
d929913e 2192 return TRUE;
b99bd4ef
NC
2193}
2194
dcbf9037
JB
2195/* Create a Neon typed/indexed register alias using directives, e.g.:
2196 X .dn d5.s32[1]
2197 Y .qn 6.s16
2198 Z .dn d7
2199 T .dn Z[0]
2200 These typed registers can be used instead of the types specified after the
2201 Neon mnemonic, so long as all operands given have types. Types can also be
2202 specified directly, e.g.:
5f4273c7 2203 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2204
c921be7d 2205static bfd_boolean
dcbf9037
JB
2206create_neon_reg_alias (char *newname, char *p)
2207{
2208 enum arm_reg_type basetype;
2209 struct reg_entry *basereg;
2210 struct reg_entry mybasereg;
2211 struct neon_type ntype;
2212 struct neon_typed_alias typeinfo;
2213 char *namebuf, *nameend;
2214 int namelen;
5f4273c7 2215
dcbf9037
JB
2216 typeinfo.defined = 0;
2217 typeinfo.eltype.type = NT_invtype;
2218 typeinfo.eltype.size = -1;
2219 typeinfo.index = -1;
5f4273c7 2220
dcbf9037 2221 nameend = p;
5f4273c7 2222
dcbf9037
JB
2223 if (strncmp (p, " .dn ", 5) == 0)
2224 basetype = REG_TYPE_VFD;
2225 else if (strncmp (p, " .qn ", 5) == 0)
2226 basetype = REG_TYPE_NQ;
2227 else
c921be7d 2228 return FALSE;
5f4273c7 2229
dcbf9037 2230 p += 5;
5f4273c7 2231
dcbf9037 2232 if (*p == '\0')
c921be7d 2233 return FALSE;
5f4273c7 2234
dcbf9037
JB
2235 basereg = arm_reg_parse_multi (&p);
2236
2237 if (basereg && basereg->type != basetype)
2238 {
2239 as_bad (_("bad type for register"));
c921be7d 2240 return FALSE;
dcbf9037
JB
2241 }
2242
2243 if (basereg == NULL)
2244 {
2245 expressionS exp;
2246 /* Try parsing as an integer. */
2247 my_get_expression (&exp, &p, GE_NO_PREFIX);
2248 if (exp.X_op != O_constant)
2249 {
2250 as_bad (_("expression must be constant"));
c921be7d 2251 return FALSE;
dcbf9037
JB
2252 }
2253 basereg = &mybasereg;
2254 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2255 : exp.X_add_number;
2256 basereg->neon = 0;
2257 }
2258
2259 if (basereg->neon)
2260 typeinfo = *basereg->neon;
2261
2262 if (parse_neon_type (&ntype, &p) == SUCCESS)
2263 {
2264 /* We got a type. */
2265 if (typeinfo.defined & NTA_HASTYPE)
2266 {
2267 as_bad (_("can't redefine the type of a register alias"));
c921be7d 2268 return FALSE;
dcbf9037 2269 }
5f4273c7 2270
dcbf9037
JB
2271 typeinfo.defined |= NTA_HASTYPE;
2272 if (ntype.elems != 1)
2273 {
2274 as_bad (_("you must specify a single type only"));
c921be7d 2275 return FALSE;
dcbf9037
JB
2276 }
2277 typeinfo.eltype = ntype.el[0];
2278 }
5f4273c7 2279
dcbf9037
JB
2280 if (skip_past_char (&p, '[') == SUCCESS)
2281 {
2282 expressionS exp;
2283 /* We got a scalar index. */
5f4273c7 2284
dcbf9037
JB
2285 if (typeinfo.defined & NTA_HASINDEX)
2286 {
2287 as_bad (_("can't redefine the index of a scalar alias"));
c921be7d 2288 return FALSE;
dcbf9037 2289 }
5f4273c7 2290
dcbf9037 2291 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2292
dcbf9037
JB
2293 if (exp.X_op != O_constant)
2294 {
2295 as_bad (_("scalar index must be constant"));
c921be7d 2296 return FALSE;
dcbf9037 2297 }
5f4273c7 2298
dcbf9037
JB
2299 typeinfo.defined |= NTA_HASINDEX;
2300 typeinfo.index = exp.X_add_number;
5f4273c7 2301
dcbf9037
JB
2302 if (skip_past_char (&p, ']') == FAIL)
2303 {
2304 as_bad (_("expecting ]"));
c921be7d 2305 return FALSE;
dcbf9037
JB
2306 }
2307 }
2308
15735687
NS
2309 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2310 the desired alias name, and p points to its end. If not, then
2311 the desired alias name is in the global original_case_string. */
2312#ifdef TC_CASE_SENSITIVE
dcbf9037 2313 namelen = nameend - newname;
15735687
NS
2314#else
2315 newname = original_case_string;
2316 namelen = strlen (newname);
2317#endif
2318
21d799b5 2319 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2320 strncpy (namebuf, newname, namelen);
2321 namebuf[namelen] = '\0';
5f4273c7 2322
dcbf9037
JB
2323 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2324 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2325
dcbf9037
JB
2326 /* Insert name in all uppercase. */
2327 for (p = namebuf; *p; p++)
2328 *p = TOUPPER (*p);
5f4273c7 2329
dcbf9037
JB
2330 if (strncmp (namebuf, newname, namelen))
2331 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2332 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2333
dcbf9037
JB
2334 /* Insert name in all lowercase. */
2335 for (p = namebuf; *p; p++)
2336 *p = TOLOWER (*p);
5f4273c7 2337
dcbf9037
JB
2338 if (strncmp (namebuf, newname, namelen))
2339 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2340 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2341
c921be7d 2342 return TRUE;
dcbf9037
JB
2343}
2344
c19d1205
ZW
2345/* Should never be called, as .req goes between the alias and the
2346 register name, not at the beginning of the line. */
c921be7d 2347
b99bd4ef 2348static void
c19d1205 2349s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2350{
c19d1205
ZW
2351 as_bad (_("invalid syntax for .req directive"));
2352}
b99bd4ef 2353
dcbf9037
JB
2354static void
2355s_dn (int a ATTRIBUTE_UNUSED)
2356{
2357 as_bad (_("invalid syntax for .dn directive"));
2358}
2359
2360static void
2361s_qn (int a ATTRIBUTE_UNUSED)
2362{
2363 as_bad (_("invalid syntax for .qn directive"));
2364}
2365
c19d1205
ZW
2366/* The .unreq directive deletes an alias which was previously defined
2367 by .req. For example:
b99bd4ef 2368
c19d1205
ZW
2369 my_alias .req r11
2370 .unreq my_alias */
b99bd4ef
NC
2371
2372static void
c19d1205 2373s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2374{
c19d1205
ZW
2375 char * name;
2376 char saved_char;
b99bd4ef 2377
c19d1205
ZW
2378 name = input_line_pointer;
2379
2380 while (*input_line_pointer != 0
2381 && *input_line_pointer != ' '
2382 && *input_line_pointer != '\n')
2383 ++input_line_pointer;
2384
2385 saved_char = *input_line_pointer;
2386 *input_line_pointer = 0;
2387
2388 if (!*name)
2389 as_bad (_("invalid syntax for .unreq directive"));
2390 else
2391 {
21d799b5
NC
2392 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2393 name);
c19d1205
ZW
2394
2395 if (!reg)
2396 as_bad (_("unknown register alias '%s'"), name);
2397 else if (reg->builtin)
2398 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2399 name);
2400 else
2401 {
d929913e
NC
2402 char * p;
2403 char * nbuf;
2404
db0bc284 2405 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2406 free ((char *) reg->name);
dcbf9037
JB
2407 if (reg->neon)
2408 free (reg->neon);
c19d1205 2409 free (reg);
d929913e
NC
2410
2411 /* Also locate the all upper case and all lower case versions.
2412 Do not complain if we cannot find one or the other as it
2413 was probably deleted above. */
5f4273c7 2414
d929913e
NC
2415 nbuf = strdup (name);
2416 for (p = nbuf; *p; p++)
2417 *p = TOUPPER (*p);
21d799b5 2418 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2419 if (reg)
2420 {
db0bc284 2421 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2422 free ((char *) reg->name);
2423 if (reg->neon)
2424 free (reg->neon);
2425 free (reg);
2426 }
2427
2428 for (p = nbuf; *p; p++)
2429 *p = TOLOWER (*p);
21d799b5 2430 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2431 if (reg)
2432 {
db0bc284 2433 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2434 free ((char *) reg->name);
2435 if (reg->neon)
2436 free (reg->neon);
2437 free (reg);
2438 }
2439
2440 free (nbuf);
c19d1205
ZW
2441 }
2442 }
b99bd4ef 2443
c19d1205 2444 *input_line_pointer = saved_char;
b99bd4ef
NC
2445 demand_empty_rest_of_line ();
2446}
2447
c19d1205
ZW
2448/* Directives: Instruction set selection. */
2449
2450#ifdef OBJ_ELF
2451/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2452 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2453 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2454 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2455
cd000bff
DJ
2456/* Create a new mapping symbol for the transition to STATE. */
2457
2458static void
2459make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2460{
a737bd4d 2461 symbolS * symbolP;
c19d1205
ZW
2462 const char * symname;
2463 int type;
b99bd4ef 2464
c19d1205 2465 switch (state)
b99bd4ef 2466 {
c19d1205
ZW
2467 case MAP_DATA:
2468 symname = "$d";
2469 type = BSF_NO_FLAGS;
2470 break;
2471 case MAP_ARM:
2472 symname = "$a";
2473 type = BSF_NO_FLAGS;
2474 break;
2475 case MAP_THUMB:
2476 symname = "$t";
2477 type = BSF_NO_FLAGS;
2478 break;
c19d1205
ZW
2479 default:
2480 abort ();
2481 }
2482
cd000bff 2483 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2484 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2485
2486 switch (state)
2487 {
2488 case MAP_ARM:
2489 THUMB_SET_FUNC (symbolP, 0);
2490 ARM_SET_THUMB (symbolP, 0);
2491 ARM_SET_INTERWORK (symbolP, support_interwork);
2492 break;
2493
2494 case MAP_THUMB:
2495 THUMB_SET_FUNC (symbolP, 1);
2496 ARM_SET_THUMB (symbolP, 1);
2497 ARM_SET_INTERWORK (symbolP, support_interwork);
2498 break;
2499
2500 case MAP_DATA:
2501 default:
cd000bff
DJ
2502 break;
2503 }
2504
2505 /* Save the mapping symbols for future reference. Also check that
2506 we do not place two mapping symbols at the same offset within a
2507 frag. We'll handle overlap between frags in
2de7820f
JZ
2508 check_mapping_symbols.
2509
2510 If .fill or other data filling directive generates zero sized data,
2511 the mapping symbol for the following code will have the same value
2512 as the one generated for the data filling directive. In this case,
2513 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2514 if (value == 0)
2515 {
2de7820f
JZ
2516 if (frag->tc_frag_data.first_map != NULL)
2517 {
2518 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2519 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2520 }
cd000bff
DJ
2521 frag->tc_frag_data.first_map = symbolP;
2522 }
2523 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2524 {
2525 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2526 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2527 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2528 }
cd000bff
DJ
2529 frag->tc_frag_data.last_map = symbolP;
2530}
2531
2532/* We must sometimes convert a region marked as code to data during
2533 code alignment, if an odd number of bytes have to be padded. The
2534 code mapping symbol is pushed to an aligned address. */
2535
2536static void
2537insert_data_mapping_symbol (enum mstate state,
2538 valueT value, fragS *frag, offsetT bytes)
2539{
2540 /* If there was already a mapping symbol, remove it. */
2541 if (frag->tc_frag_data.last_map != NULL
2542 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2543 {
2544 symbolS *symp = frag->tc_frag_data.last_map;
2545
2546 if (value == 0)
2547 {
2548 know (frag->tc_frag_data.first_map == symp);
2549 frag->tc_frag_data.first_map = NULL;
2550 }
2551 frag->tc_frag_data.last_map = NULL;
2552 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2553 }
cd000bff
DJ
2554
2555 make_mapping_symbol (MAP_DATA, value, frag);
2556 make_mapping_symbol (state, value + bytes, frag);
2557}
2558
2559static void mapping_state_2 (enum mstate state, int max_chars);
2560
2561/* Set the mapping state to STATE. Only call this when about to
2562 emit some STATE bytes to the file. */
2563
2564void
2565mapping_state (enum mstate state)
2566{
940b5ce0
DJ
2567 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2568
cd000bff
DJ
2569#define TRANSITION(from, to) (mapstate == (from) && state == (to))
2570
2571 if (mapstate == state)
2572 /* The mapping symbol has already been emitted.
2573 There is nothing else to do. */
2574 return;
2575 else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2576 /* This case will be evaluated later in the next else. */
2577 return;
2578 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2579 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2580 {
2581 /* Only add the symbol if the offset is > 0:
2582 if we're at the first frag, check it's size > 0;
2583 if we're not at the first frag, then for sure
2584 the offset is > 0. */
2585 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2586 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2587
2588 if (add_symbol)
2589 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2590 }
2591
2592 mapping_state_2 (state, 0);
2593#undef TRANSITION
2594}
2595
2596/* Same as mapping_state, but MAX_CHARS bytes have already been
2597 allocated. Put the mapping symbol that far back. */
2598
2599static void
2600mapping_state_2 (enum mstate state, int max_chars)
2601{
940b5ce0
DJ
2602 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2603
2604 if (!SEG_NORMAL (now_seg))
2605 return;
2606
cd000bff
DJ
2607 if (mapstate == state)
2608 /* The mapping symbol has already been emitted.
2609 There is nothing else to do. */
2610 return;
2611
cd000bff
DJ
2612 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2613 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205
ZW
2614}
2615#else
d3106081
NS
2616#define mapping_state(x) ((void)0)
2617#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2618#endif
2619
2620/* Find the real, Thumb encoded start of a Thumb function. */
2621
4343666d 2622#ifdef OBJ_COFF
c19d1205
ZW
2623static symbolS *
2624find_real_start (symbolS * symbolP)
2625{
2626 char * real_start;
2627 const char * name = S_GET_NAME (symbolP);
2628 symbolS * new_target;
2629
2630 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2631#define STUB_NAME ".real_start_of"
2632
2633 if (name == NULL)
2634 abort ();
2635
37f6032b
ZW
2636 /* The compiler may generate BL instructions to local labels because
2637 it needs to perform a branch to a far away location. These labels
2638 do not have a corresponding ".real_start_of" label. We check
2639 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2640 the ".real_start_of" convention for nonlocal branches. */
2641 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2642 return symbolP;
2643
37f6032b 2644 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2645 new_target = symbol_find (real_start);
2646
2647 if (new_target == NULL)
2648 {
bd3ba5d1 2649 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2650 new_target = symbolP;
2651 }
2652
c19d1205
ZW
2653 return new_target;
2654}
4343666d 2655#endif
c19d1205
ZW
2656
2657static void
2658opcode_select (int width)
2659{
2660 switch (width)
2661 {
2662 case 16:
2663 if (! thumb_mode)
2664 {
e74cfd16 2665 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2666 as_bad (_("selected processor does not support THUMB opcodes"));
2667
2668 thumb_mode = 1;
2669 /* No need to force the alignment, since we will have been
2670 coming from ARM mode, which is word-aligned. */
2671 record_alignment (now_seg, 1);
2672 }
c19d1205
ZW
2673 break;
2674
2675 case 32:
2676 if (thumb_mode)
2677 {
e74cfd16 2678 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2679 as_bad (_("selected processor does not support ARM opcodes"));
2680
2681 thumb_mode = 0;
2682
2683 if (!need_pass_2)
2684 frag_align (2, 0, 0);
2685
2686 record_alignment (now_seg, 1);
2687 }
c19d1205
ZW
2688 break;
2689
2690 default:
2691 as_bad (_("invalid instruction size selected (%d)"), width);
2692 }
2693}
2694
2695static void
2696s_arm (int ignore ATTRIBUTE_UNUSED)
2697{
2698 opcode_select (32);
2699 demand_empty_rest_of_line ();
2700}
2701
2702static void
2703s_thumb (int ignore ATTRIBUTE_UNUSED)
2704{
2705 opcode_select (16);
2706 demand_empty_rest_of_line ();
2707}
2708
2709static void
2710s_code (int unused ATTRIBUTE_UNUSED)
2711{
2712 int temp;
2713
2714 temp = get_absolute_expression ();
2715 switch (temp)
2716 {
2717 case 16:
2718 case 32:
2719 opcode_select (temp);
2720 break;
2721
2722 default:
2723 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2724 }
2725}
2726
2727static void
2728s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2729{
2730 /* If we are not already in thumb mode go into it, EVEN if
2731 the target processor does not support thumb instructions.
2732 This is used by gcc/config/arm/lib1funcs.asm for example
2733 to compile interworking support functions even if the
2734 target processor should not support interworking. */
2735 if (! thumb_mode)
2736 {
2737 thumb_mode = 2;
2738 record_alignment (now_seg, 1);
2739 }
2740
2741 demand_empty_rest_of_line ();
2742}
2743
2744static void
2745s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2746{
2747 s_thumb (0);
2748
2749 /* The following label is the name/address of the start of a Thumb function.
2750 We need to know this for the interworking support. */
2751 label_is_thumb_function_name = TRUE;
2752}
2753
2754/* Perform a .set directive, but also mark the alias as
2755 being a thumb function. */
2756
2757static void
2758s_thumb_set (int equiv)
2759{
2760 /* XXX the following is a duplicate of the code for s_set() in read.c
2761 We cannot just call that code as we need to get at the symbol that
2762 is created. */
2763 char * name;
2764 char delim;
2765 char * end_name;
2766 symbolS * symbolP;
2767
2768 /* Especial apologies for the random logic:
2769 This just grew, and could be parsed much more simply!
2770 Dean - in haste. */
2771 name = input_line_pointer;
2772 delim = get_symbol_end ();
2773 end_name = input_line_pointer;
2774 *end_name = delim;
2775
2776 if (*input_line_pointer != ',')
2777 {
2778 *end_name = 0;
2779 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2780 *end_name = delim;
2781 ignore_rest_of_line ();
2782 return;
2783 }
2784
2785 input_line_pointer++;
2786 *end_name = 0;
2787
2788 if (name[0] == '.' && name[1] == '\0')
2789 {
2790 /* XXX - this should not happen to .thumb_set. */
2791 abort ();
2792 }
2793
2794 if ((symbolP = symbol_find (name)) == NULL
2795 && (symbolP = md_undefined_symbol (name)) == NULL)
2796 {
2797#ifndef NO_LISTING
2798 /* When doing symbol listings, play games with dummy fragments living
2799 outside the normal fragment chain to record the file and line info
c19d1205 2800 for this symbol. */
b99bd4ef
NC
2801 if (listing & LISTING_SYMBOLS)
2802 {
2803 extern struct list_info_struct * listing_tail;
21d799b5 2804 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2805
2806 memset (dummy_frag, 0, sizeof (fragS));
2807 dummy_frag->fr_type = rs_fill;
2808 dummy_frag->line = listing_tail;
2809 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2810 dummy_frag->fr_symbol = symbolP;
2811 }
2812 else
2813#endif
2814 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2815
2816#ifdef OBJ_COFF
2817 /* "set" symbols are local unless otherwise specified. */
2818 SF_SET_LOCAL (symbolP);
2819#endif /* OBJ_COFF */
2820 } /* Make a new symbol. */
2821
2822 symbol_table_insert (symbolP);
2823
2824 * end_name = delim;
2825
2826 if (equiv
2827 && S_IS_DEFINED (symbolP)
2828 && S_GET_SEGMENT (symbolP) != reg_section)
2829 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2830
2831 pseudo_set (symbolP);
2832
2833 demand_empty_rest_of_line ();
2834
c19d1205 2835 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2836
2837 THUMB_SET_FUNC (symbolP, 1);
2838 ARM_SET_THUMB (symbolP, 1);
2839#if defined OBJ_ELF || defined OBJ_COFF
2840 ARM_SET_INTERWORK (symbolP, support_interwork);
2841#endif
2842}
2843
c19d1205 2844/* Directives: Mode selection. */
b99bd4ef 2845
c19d1205
ZW
2846/* .syntax [unified|divided] - choose the new unified syntax
2847 (same for Arm and Thumb encoding, modulo slight differences in what
2848 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2849static void
c19d1205 2850s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2851{
c19d1205
ZW
2852 char *name, delim;
2853
2854 name = input_line_pointer;
2855 delim = get_symbol_end ();
2856
2857 if (!strcasecmp (name, "unified"))
2858 unified_syntax = TRUE;
2859 else if (!strcasecmp (name, "divided"))
2860 unified_syntax = FALSE;
2861 else
2862 {
2863 as_bad (_("unrecognized syntax mode \"%s\""), name);
2864 return;
2865 }
2866 *input_line_pointer = delim;
b99bd4ef
NC
2867 demand_empty_rest_of_line ();
2868}
2869
c19d1205
ZW
2870/* Directives: sectioning and alignment. */
2871
2872/* Same as s_align_ptwo but align 0 => align 2. */
2873
b99bd4ef 2874static void
c19d1205 2875s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2876{
a737bd4d 2877 int temp;
dce323d1 2878 bfd_boolean fill_p;
c19d1205
ZW
2879 long temp_fill;
2880 long max_alignment = 15;
b99bd4ef
NC
2881
2882 temp = get_absolute_expression ();
c19d1205
ZW
2883 if (temp > max_alignment)
2884 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2885 else if (temp < 0)
b99bd4ef 2886 {
c19d1205
ZW
2887 as_bad (_("alignment negative. 0 assumed."));
2888 temp = 0;
2889 }
b99bd4ef 2890
c19d1205
ZW
2891 if (*input_line_pointer == ',')
2892 {
2893 input_line_pointer++;
2894 temp_fill = get_absolute_expression ();
dce323d1 2895 fill_p = TRUE;
b99bd4ef 2896 }
c19d1205 2897 else
dce323d1
PB
2898 {
2899 fill_p = FALSE;
2900 temp_fill = 0;
2901 }
b99bd4ef 2902
c19d1205
ZW
2903 if (!temp)
2904 temp = 2;
b99bd4ef 2905
c19d1205
ZW
2906 /* Only make a frag if we HAVE to. */
2907 if (temp && !need_pass_2)
dce323d1
PB
2908 {
2909 if (!fill_p && subseg_text_p (now_seg))
2910 frag_align_code (temp, 0);
2911 else
2912 frag_align (temp, (int) temp_fill, 0);
2913 }
c19d1205
ZW
2914 demand_empty_rest_of_line ();
2915
2916 record_alignment (now_seg, temp);
b99bd4ef
NC
2917}
2918
c19d1205
ZW
2919static void
2920s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2921{
c19d1205
ZW
2922 /* We don't support putting frags in the BSS segment, we fake it by
2923 marking in_bss, then looking at s_skip for clues. */
2924 subseg_set (bss_section, 0);
2925 demand_empty_rest_of_line ();
cd000bff
DJ
2926
2927#ifdef md_elf_section_change_hook
2928 md_elf_section_change_hook ();
2929#endif
c19d1205 2930}
b99bd4ef 2931
c19d1205
ZW
2932static void
2933s_even (int ignore ATTRIBUTE_UNUSED)
2934{
2935 /* Never make frag if expect extra pass. */
2936 if (!need_pass_2)
2937 frag_align (1, 0, 0);
b99bd4ef 2938
c19d1205 2939 record_alignment (now_seg, 1);
b99bd4ef 2940
c19d1205 2941 demand_empty_rest_of_line ();
b99bd4ef
NC
2942}
2943
c19d1205 2944/* Directives: Literal pools. */
a737bd4d 2945
c19d1205
ZW
2946static literal_pool *
2947find_literal_pool (void)
a737bd4d 2948{
c19d1205 2949 literal_pool * pool;
a737bd4d 2950
c19d1205 2951 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2952 {
c19d1205
ZW
2953 if (pool->section == now_seg
2954 && pool->sub_section == now_subseg)
2955 break;
a737bd4d
NC
2956 }
2957
c19d1205 2958 return pool;
a737bd4d
NC
2959}
2960
c19d1205
ZW
2961static literal_pool *
2962find_or_make_literal_pool (void)
a737bd4d 2963{
c19d1205
ZW
2964 /* Next literal pool ID number. */
2965 static unsigned int latest_pool_num = 1;
2966 literal_pool * pool;
a737bd4d 2967
c19d1205 2968 pool = find_literal_pool ();
a737bd4d 2969
c19d1205 2970 if (pool == NULL)
a737bd4d 2971 {
c19d1205 2972 /* Create a new pool. */
21d799b5 2973 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
2974 if (! pool)
2975 return NULL;
a737bd4d 2976
c19d1205
ZW
2977 pool->next_free_entry = 0;
2978 pool->section = now_seg;
2979 pool->sub_section = now_subseg;
2980 pool->next = list_of_pools;
2981 pool->symbol = NULL;
2982
2983 /* Add it to the list. */
2984 list_of_pools = pool;
a737bd4d 2985 }
a737bd4d 2986
c19d1205
ZW
2987 /* New pools, and emptied pools, will have a NULL symbol. */
2988 if (pool->symbol == NULL)
a737bd4d 2989 {
c19d1205
ZW
2990 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2991 (valueT) 0, &zero_address_frag);
2992 pool->id = latest_pool_num ++;
a737bd4d
NC
2993 }
2994
c19d1205
ZW
2995 /* Done. */
2996 return pool;
a737bd4d
NC
2997}
2998
c19d1205 2999/* Add the literal in the global 'inst'
5f4273c7 3000 structure to the relevant literal pool. */
b99bd4ef
NC
3001
3002static int
c19d1205 3003add_to_lit_pool (void)
b99bd4ef 3004{
c19d1205
ZW
3005 literal_pool * pool;
3006 unsigned int entry;
b99bd4ef 3007
c19d1205
ZW
3008 pool = find_or_make_literal_pool ();
3009
3010 /* Check if this literal value is already in the pool. */
3011 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3012 {
c19d1205
ZW
3013 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3014 && (inst.reloc.exp.X_op == O_constant)
3015 && (pool->literals[entry].X_add_number
3016 == inst.reloc.exp.X_add_number)
3017 && (pool->literals[entry].X_unsigned
3018 == inst.reloc.exp.X_unsigned))
3019 break;
3020
3021 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3022 && (inst.reloc.exp.X_op == O_symbol)
3023 && (pool->literals[entry].X_add_number
3024 == inst.reloc.exp.X_add_number)
3025 && (pool->literals[entry].X_add_symbol
3026 == inst.reloc.exp.X_add_symbol)
3027 && (pool->literals[entry].X_op_symbol
3028 == inst.reloc.exp.X_op_symbol))
3029 break;
b99bd4ef
NC
3030 }
3031
c19d1205
ZW
3032 /* Do we need to create a new entry? */
3033 if (entry == pool->next_free_entry)
3034 {
3035 if (entry >= MAX_LITERAL_POOL_SIZE)
3036 {
3037 inst.error = _("literal pool overflow");
3038 return FAIL;
3039 }
3040
3041 pool->literals[entry] = inst.reloc.exp;
3042 pool->next_free_entry += 1;
3043 }
b99bd4ef 3044
c19d1205
ZW
3045 inst.reloc.exp.X_op = O_symbol;
3046 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3047 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3048
c19d1205 3049 return SUCCESS;
b99bd4ef
NC
3050}
3051
c19d1205
ZW
3052/* Can't use symbol_new here, so have to create a symbol and then at
3053 a later date assign it a value. Thats what these functions do. */
e16bb312 3054
c19d1205
ZW
3055static void
3056symbol_locate (symbolS * symbolP,
3057 const char * name, /* It is copied, the caller can modify. */
3058 segT segment, /* Segment identifier (SEG_<something>). */
3059 valueT valu, /* Symbol value. */
3060 fragS * frag) /* Associated fragment. */
3061{
3062 unsigned int name_length;
3063 char * preserved_copy_of_name;
e16bb312 3064
c19d1205
ZW
3065 name_length = strlen (name) + 1; /* +1 for \0. */
3066 obstack_grow (&notes, name, name_length);
21d799b5 3067 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3068
c19d1205
ZW
3069#ifdef tc_canonicalize_symbol_name
3070 preserved_copy_of_name =
3071 tc_canonicalize_symbol_name (preserved_copy_of_name);
3072#endif
b99bd4ef 3073
c19d1205 3074 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3075
c19d1205
ZW
3076 S_SET_SEGMENT (symbolP, segment);
3077 S_SET_VALUE (symbolP, valu);
3078 symbol_clear_list_pointers (symbolP);
b99bd4ef 3079
c19d1205 3080 symbol_set_frag (symbolP, frag);
b99bd4ef 3081
c19d1205
ZW
3082 /* Link to end of symbol chain. */
3083 {
3084 extern int symbol_table_frozen;
b99bd4ef 3085
c19d1205
ZW
3086 if (symbol_table_frozen)
3087 abort ();
3088 }
b99bd4ef 3089
c19d1205 3090 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3091
c19d1205 3092 obj_symbol_new_hook (symbolP);
b99bd4ef 3093
c19d1205
ZW
3094#ifdef tc_symbol_new_hook
3095 tc_symbol_new_hook (symbolP);
3096#endif
3097
3098#ifdef DEBUG_SYMS
3099 verify_symbol_chain (symbol_rootP, symbol_lastP);
3100#endif /* DEBUG_SYMS */
b99bd4ef
NC
3101}
3102
b99bd4ef 3103
c19d1205
ZW
3104static void
3105s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3106{
c19d1205
ZW
3107 unsigned int entry;
3108 literal_pool * pool;
3109 char sym_name[20];
b99bd4ef 3110
c19d1205
ZW
3111 pool = find_literal_pool ();
3112 if (pool == NULL
3113 || pool->symbol == NULL
3114 || pool->next_free_entry == 0)
3115 return;
b99bd4ef 3116
c19d1205 3117 mapping_state (MAP_DATA);
b99bd4ef 3118
c19d1205
ZW
3119 /* Align pool as you have word accesses.
3120 Only make a frag if we have to. */
3121 if (!need_pass_2)
3122 frag_align (2, 0, 0);
b99bd4ef 3123
c19d1205 3124 record_alignment (now_seg, 2);
b99bd4ef 3125
c19d1205 3126 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3127
c19d1205
ZW
3128 symbol_locate (pool->symbol, sym_name, now_seg,
3129 (valueT) frag_now_fix (), frag_now);
3130 symbol_table_insert (pool->symbol);
b99bd4ef 3131
c19d1205 3132 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3133
c19d1205
ZW
3134#if defined OBJ_COFF || defined OBJ_ELF
3135 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3136#endif
6c43fab6 3137
c19d1205
ZW
3138 for (entry = 0; entry < pool->next_free_entry; entry ++)
3139 /* First output the expression in the instruction to the pool. */
3140 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 3141
c19d1205
ZW
3142 /* Mark the pool as empty. */
3143 pool->next_free_entry = 0;
3144 pool->symbol = NULL;
b99bd4ef
NC
3145}
3146
c19d1205
ZW
3147#ifdef OBJ_ELF
3148/* Forward declarations for functions below, in the MD interface
3149 section. */
3150static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3151static valueT create_unwind_entry (int);
3152static void start_unwind_section (const segT, int);
3153static void add_unwind_opcode (valueT, int);
3154static void flush_pending_unwind (void);
b99bd4ef 3155
c19d1205 3156/* Directives: Data. */
b99bd4ef 3157
c19d1205
ZW
3158static void
3159s_arm_elf_cons (int nbytes)
3160{
3161 expressionS exp;
b99bd4ef 3162
c19d1205
ZW
3163#ifdef md_flush_pending_output
3164 md_flush_pending_output ();
3165#endif
b99bd4ef 3166
c19d1205 3167 if (is_it_end_of_statement ())
b99bd4ef 3168 {
c19d1205
ZW
3169 demand_empty_rest_of_line ();
3170 return;
b99bd4ef
NC
3171 }
3172
c19d1205
ZW
3173#ifdef md_cons_align
3174 md_cons_align (nbytes);
3175#endif
b99bd4ef 3176
c19d1205
ZW
3177 mapping_state (MAP_DATA);
3178 do
b99bd4ef 3179 {
c19d1205
ZW
3180 int reloc;
3181 char *base = input_line_pointer;
b99bd4ef 3182
c19d1205 3183 expression (& exp);
b99bd4ef 3184
c19d1205
ZW
3185 if (exp.X_op != O_symbol)
3186 emit_expr (&exp, (unsigned int) nbytes);
3187 else
3188 {
3189 char *before_reloc = input_line_pointer;
3190 reloc = parse_reloc (&input_line_pointer);
3191 if (reloc == -1)
3192 {
3193 as_bad (_("unrecognized relocation suffix"));
3194 ignore_rest_of_line ();
3195 return;
3196 }
3197 else if (reloc == BFD_RELOC_UNUSED)
3198 emit_expr (&exp, (unsigned int) nbytes);
3199 else
3200 {
21d799b5
NC
3201 reloc_howto_type *howto = (reloc_howto_type *)
3202 bfd_reloc_type_lookup (stdoutput,
3203 (bfd_reloc_code_real_type) reloc);
c19d1205 3204 int size = bfd_get_reloc_size (howto);
b99bd4ef 3205
2fc8bdac
ZW
3206 if (reloc == BFD_RELOC_ARM_PLT32)
3207 {
3208 as_bad (_("(plt) is only valid on branch targets"));
3209 reloc = BFD_RELOC_UNUSED;
3210 size = 0;
3211 }
3212
c19d1205 3213 if (size > nbytes)
2fc8bdac 3214 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3215 howto->name, nbytes);
3216 else
3217 {
3218 /* We've parsed an expression stopping at O_symbol.
3219 But there may be more expression left now that we
3220 have parsed the relocation marker. Parse it again.
3221 XXX Surely there is a cleaner way to do this. */
3222 char *p = input_line_pointer;
3223 int offset;
21d799b5 3224 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3225 memcpy (save_buf, base, input_line_pointer - base);
3226 memmove (base + (input_line_pointer - before_reloc),
3227 base, before_reloc - base);
3228
3229 input_line_pointer = base + (input_line_pointer-before_reloc);
3230 expression (&exp);
3231 memcpy (base, save_buf, p - base);
3232
3233 offset = nbytes - size;
3234 p = frag_more ((int) nbytes);
3235 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3236 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3237 }
3238 }
3239 }
b99bd4ef 3240 }
c19d1205 3241 while (*input_line_pointer++ == ',');
b99bd4ef 3242
c19d1205
ZW
3243 /* Put terminator back into stream. */
3244 input_line_pointer --;
3245 demand_empty_rest_of_line ();
b99bd4ef
NC
3246}
3247
c921be7d
NC
3248/* Emit an expression containing a 32-bit thumb instruction.
3249 Implementation based on put_thumb32_insn. */
3250
3251static void
3252emit_thumb32_expr (expressionS * exp)
3253{
3254 expressionS exp_high = *exp;
3255
3256 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3257 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3258 exp->X_add_number &= 0xffff;
3259 emit_expr (exp, (unsigned int) THUMB_SIZE);
3260}
3261
3262/* Guess the instruction size based on the opcode. */
3263
3264static int
3265thumb_insn_size (int opcode)
3266{
3267 if ((unsigned int) opcode < 0xe800u)
3268 return 2;
3269 else if ((unsigned int) opcode >= 0xe8000000u)
3270 return 4;
3271 else
3272 return 0;
3273}
3274
3275static bfd_boolean
3276emit_insn (expressionS *exp, int nbytes)
3277{
3278 int size = 0;
3279
3280 if (exp->X_op == O_constant)
3281 {
3282 size = nbytes;
3283
3284 if (size == 0)
3285 size = thumb_insn_size (exp->X_add_number);
3286
3287 if (size != 0)
3288 {
3289 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3290 {
3291 as_bad (_(".inst.n operand too big. "\
3292 "Use .inst.w instead"));
3293 size = 0;
3294 }
3295 else
3296 {
3297 if (now_it.state == AUTOMATIC_IT_BLOCK)
3298 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3299 else
3300 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3301
3302 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3303 emit_thumb32_expr (exp);
3304 else
3305 emit_expr (exp, (unsigned int) size);
3306
3307 it_fsm_post_encode ();
3308 }
3309 }
3310 else
3311 as_bad (_("cannot determine Thumb instruction size. " \
3312 "Use .inst.n/.inst.w instead"));
3313 }
3314 else
3315 as_bad (_("constant expression required"));
3316
3317 return (size != 0);
3318}
3319
3320/* Like s_arm_elf_cons but do not use md_cons_align and
3321 set the mapping state to MAP_ARM/MAP_THUMB. */
3322
3323static void
3324s_arm_elf_inst (int nbytes)
3325{
3326 if (is_it_end_of_statement ())
3327 {
3328 demand_empty_rest_of_line ();
3329 return;
3330 }
3331
3332 /* Calling mapping_state () here will not change ARM/THUMB,
3333 but will ensure not to be in DATA state. */
3334
3335 if (thumb_mode)
3336 mapping_state (MAP_THUMB);
3337 else
3338 {
3339 if (nbytes != 0)
3340 {
3341 as_bad (_("width suffixes are invalid in ARM mode"));
3342 ignore_rest_of_line ();
3343 return;
3344 }
3345
3346 nbytes = 4;
3347
3348 mapping_state (MAP_ARM);
3349 }
3350
3351 do
3352 {
3353 expressionS exp;
3354
3355 expression (& exp);
3356
3357 if (! emit_insn (& exp, nbytes))
3358 {
3359 ignore_rest_of_line ();
3360 return;
3361 }
3362 }
3363 while (*input_line_pointer++ == ',');
3364
3365 /* Put terminator back into stream. */
3366 input_line_pointer --;
3367 demand_empty_rest_of_line ();
3368}
b99bd4ef 3369
c19d1205 3370/* Parse a .rel31 directive. */
b99bd4ef 3371
c19d1205
ZW
3372static void
3373s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3374{
3375 expressionS exp;
3376 char *p;
3377 valueT highbit;
b99bd4ef 3378
c19d1205
ZW
3379 highbit = 0;
3380 if (*input_line_pointer == '1')
3381 highbit = 0x80000000;
3382 else if (*input_line_pointer != '0')
3383 as_bad (_("expected 0 or 1"));
b99bd4ef 3384
c19d1205
ZW
3385 input_line_pointer++;
3386 if (*input_line_pointer != ',')
3387 as_bad (_("missing comma"));
3388 input_line_pointer++;
b99bd4ef 3389
c19d1205
ZW
3390#ifdef md_flush_pending_output
3391 md_flush_pending_output ();
3392#endif
b99bd4ef 3393
c19d1205
ZW
3394#ifdef md_cons_align
3395 md_cons_align (4);
3396#endif
b99bd4ef 3397
c19d1205 3398 mapping_state (MAP_DATA);
b99bd4ef 3399
c19d1205 3400 expression (&exp);
b99bd4ef 3401
c19d1205
ZW
3402 p = frag_more (4);
3403 md_number_to_chars (p, highbit, 4);
3404 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3405 BFD_RELOC_ARM_PREL31);
b99bd4ef 3406
c19d1205 3407 demand_empty_rest_of_line ();
b99bd4ef
NC
3408}
3409
c19d1205 3410/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3411
c19d1205 3412/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3413
c19d1205
ZW
3414static void
3415s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3416{
3417 demand_empty_rest_of_line ();
921e5f0a
PB
3418 if (unwind.proc_start)
3419 {
c921be7d 3420 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3421 return;
3422 }
3423
c19d1205
ZW
3424 /* Mark the start of the function. */
3425 unwind.proc_start = expr_build_dot ();
b99bd4ef 3426
c19d1205
ZW
3427 /* Reset the rest of the unwind info. */
3428 unwind.opcode_count = 0;
3429 unwind.table_entry = NULL;
3430 unwind.personality_routine = NULL;
3431 unwind.personality_index = -1;
3432 unwind.frame_size = 0;
3433 unwind.fp_offset = 0;
fdfde340 3434 unwind.fp_reg = REG_SP;
c19d1205
ZW
3435 unwind.fp_used = 0;
3436 unwind.sp_restored = 0;
3437}
b99bd4ef 3438
b99bd4ef 3439
c19d1205
ZW
3440/* Parse a handlerdata directive. Creates the exception handling table entry
3441 for the function. */
b99bd4ef 3442
c19d1205
ZW
3443static void
3444s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3445{
3446 demand_empty_rest_of_line ();
921e5f0a 3447 if (!unwind.proc_start)
c921be7d 3448 as_bad (MISSING_FNSTART);
921e5f0a 3449
c19d1205 3450 if (unwind.table_entry)
6decc662 3451 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3452
c19d1205
ZW
3453 create_unwind_entry (1);
3454}
a737bd4d 3455
c19d1205 3456/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3457
c19d1205
ZW
3458static void
3459s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3460{
3461 long where;
3462 char *ptr;
3463 valueT val;
940b5ce0 3464 unsigned int marked_pr_dependency;
f02232aa 3465
c19d1205 3466 demand_empty_rest_of_line ();
f02232aa 3467
921e5f0a
PB
3468 if (!unwind.proc_start)
3469 {
c921be7d 3470 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3471 return;
3472 }
3473
c19d1205
ZW
3474 /* Add eh table entry. */
3475 if (unwind.table_entry == NULL)
3476 val = create_unwind_entry (0);
3477 else
3478 val = 0;
f02232aa 3479
c19d1205
ZW
3480 /* Add index table entry. This is two words. */
3481 start_unwind_section (unwind.saved_seg, 1);
3482 frag_align (2, 0, 0);
3483 record_alignment (now_seg, 2);
b99bd4ef 3484
c19d1205
ZW
3485 ptr = frag_more (8);
3486 where = frag_now_fix () - 8;
f02232aa 3487
c19d1205
ZW
3488 /* Self relative offset of the function start. */
3489 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3490 BFD_RELOC_ARM_PREL31);
f02232aa 3491
c19d1205
ZW
3492 /* Indicate dependency on EHABI-defined personality routines to the
3493 linker, if it hasn't been done already. */
940b5ce0
DJ
3494 marked_pr_dependency
3495 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3496 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3497 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3498 {
5f4273c7
NC
3499 static const char *const name[] =
3500 {
3501 "__aeabi_unwind_cpp_pr0",
3502 "__aeabi_unwind_cpp_pr1",
3503 "__aeabi_unwind_cpp_pr2"
3504 };
c19d1205
ZW
3505 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3506 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3507 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3508 |= 1 << unwind.personality_index;
c19d1205 3509 }
f02232aa 3510
c19d1205
ZW
3511 if (val)
3512 /* Inline exception table entry. */
3513 md_number_to_chars (ptr + 4, val, 4);
3514 else
3515 /* Self relative offset of the table entry. */
3516 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3517 BFD_RELOC_ARM_PREL31);
f02232aa 3518
c19d1205
ZW
3519 /* Restore the original section. */
3520 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3521
3522 unwind.proc_start = NULL;
c19d1205 3523}
f02232aa 3524
f02232aa 3525
c19d1205 3526/* Parse an unwind_cantunwind directive. */
b99bd4ef 3527
c19d1205
ZW
3528static void
3529s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3530{
3531 demand_empty_rest_of_line ();
921e5f0a 3532 if (!unwind.proc_start)
c921be7d 3533 as_bad (MISSING_FNSTART);
921e5f0a 3534
c19d1205
ZW
3535 if (unwind.personality_routine || unwind.personality_index != -1)
3536 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3537
c19d1205
ZW
3538 unwind.personality_index = -2;
3539}
b99bd4ef 3540
b99bd4ef 3541
c19d1205 3542/* Parse a personalityindex directive. */
b99bd4ef 3543
c19d1205
ZW
3544static void
3545s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3546{
3547 expressionS exp;
b99bd4ef 3548
921e5f0a 3549 if (!unwind.proc_start)
c921be7d 3550 as_bad (MISSING_FNSTART);
921e5f0a 3551
c19d1205
ZW
3552 if (unwind.personality_routine || unwind.personality_index != -1)
3553 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3554
c19d1205 3555 expression (&exp);
b99bd4ef 3556
c19d1205
ZW
3557 if (exp.X_op != O_constant
3558 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3559 {
c19d1205
ZW
3560 as_bad (_("bad personality routine number"));
3561 ignore_rest_of_line ();
3562 return;
b99bd4ef
NC
3563 }
3564
c19d1205 3565 unwind.personality_index = exp.X_add_number;
b99bd4ef 3566
c19d1205
ZW
3567 demand_empty_rest_of_line ();
3568}
e16bb312 3569
e16bb312 3570
c19d1205 3571/* Parse a personality directive. */
e16bb312 3572
c19d1205
ZW
3573static void
3574s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3575{
3576 char *name, *p, c;
a737bd4d 3577
921e5f0a 3578 if (!unwind.proc_start)
c921be7d 3579 as_bad (MISSING_FNSTART);
921e5f0a 3580
c19d1205
ZW
3581 if (unwind.personality_routine || unwind.personality_index != -1)
3582 as_bad (_("duplicate .personality directive"));
a737bd4d 3583
c19d1205
ZW
3584 name = input_line_pointer;
3585 c = get_symbol_end ();
3586 p = input_line_pointer;
3587 unwind.personality_routine = symbol_find_or_make (name);
3588 *p = c;
3589 demand_empty_rest_of_line ();
3590}
e16bb312 3591
e16bb312 3592
c19d1205 3593/* Parse a directive saving core registers. */
e16bb312 3594
c19d1205
ZW
3595static void
3596s_arm_unwind_save_core (void)
e16bb312 3597{
c19d1205
ZW
3598 valueT op;
3599 long range;
3600 int n;
e16bb312 3601
c19d1205
ZW
3602 range = parse_reg_list (&input_line_pointer);
3603 if (range == FAIL)
e16bb312 3604 {
c19d1205
ZW
3605 as_bad (_("expected register list"));
3606 ignore_rest_of_line ();
3607 return;
3608 }
e16bb312 3609
c19d1205 3610 demand_empty_rest_of_line ();
e16bb312 3611
c19d1205
ZW
3612 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3613 into .unwind_save {..., sp...}. We aren't bothered about the value of
3614 ip because it is clobbered by calls. */
3615 if (unwind.sp_restored && unwind.fp_reg == 12
3616 && (range & 0x3000) == 0x1000)
3617 {
3618 unwind.opcode_count--;
3619 unwind.sp_restored = 0;
3620 range = (range | 0x2000) & ~0x1000;
3621 unwind.pending_offset = 0;
3622 }
e16bb312 3623
01ae4198
DJ
3624 /* Pop r4-r15. */
3625 if (range & 0xfff0)
c19d1205 3626 {
01ae4198
DJ
3627 /* See if we can use the short opcodes. These pop a block of up to 8
3628 registers starting with r4, plus maybe r14. */
3629 for (n = 0; n < 8; n++)
3630 {
3631 /* Break at the first non-saved register. */
3632 if ((range & (1 << (n + 4))) == 0)
3633 break;
3634 }
3635 /* See if there are any other bits set. */
3636 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3637 {
3638 /* Use the long form. */
3639 op = 0x8000 | ((range >> 4) & 0xfff);
3640 add_unwind_opcode (op, 2);
3641 }
0dd132b6 3642 else
01ae4198
DJ
3643 {
3644 /* Use the short form. */
3645 if (range & 0x4000)
3646 op = 0xa8; /* Pop r14. */
3647 else
3648 op = 0xa0; /* Do not pop r14. */
3649 op |= (n - 1);
3650 add_unwind_opcode (op, 1);
3651 }
c19d1205 3652 }
0dd132b6 3653
c19d1205
ZW
3654 /* Pop r0-r3. */
3655 if (range & 0xf)
3656 {
3657 op = 0xb100 | (range & 0xf);
3658 add_unwind_opcode (op, 2);
0dd132b6
NC
3659 }
3660
c19d1205
ZW
3661 /* Record the number of bytes pushed. */
3662 for (n = 0; n < 16; n++)
3663 {
3664 if (range & (1 << n))
3665 unwind.frame_size += 4;
3666 }
0dd132b6
NC
3667}
3668
c19d1205
ZW
3669
3670/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3671
3672static void
c19d1205 3673s_arm_unwind_save_fpa (int reg)
b99bd4ef 3674{
c19d1205
ZW
3675 expressionS exp;
3676 int num_regs;
3677 valueT op;
b99bd4ef 3678
c19d1205
ZW
3679 /* Get Number of registers to transfer. */
3680 if (skip_past_comma (&input_line_pointer) != FAIL)
3681 expression (&exp);
3682 else
3683 exp.X_op = O_illegal;
b99bd4ef 3684
c19d1205 3685 if (exp.X_op != O_constant)
b99bd4ef 3686 {
c19d1205
ZW
3687 as_bad (_("expected , <constant>"));
3688 ignore_rest_of_line ();
b99bd4ef
NC
3689 return;
3690 }
3691
c19d1205
ZW
3692 num_regs = exp.X_add_number;
3693
3694 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3695 {
c19d1205
ZW
3696 as_bad (_("number of registers must be in the range [1:4]"));
3697 ignore_rest_of_line ();
b99bd4ef
NC
3698 return;
3699 }
3700
c19d1205 3701 demand_empty_rest_of_line ();
b99bd4ef 3702
c19d1205
ZW
3703 if (reg == 4)
3704 {
3705 /* Short form. */
3706 op = 0xb4 | (num_regs - 1);
3707 add_unwind_opcode (op, 1);
3708 }
b99bd4ef
NC
3709 else
3710 {
c19d1205
ZW
3711 /* Long form. */
3712 op = 0xc800 | (reg << 4) | (num_regs - 1);
3713 add_unwind_opcode (op, 2);
b99bd4ef 3714 }
c19d1205 3715 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3716}
3717
c19d1205 3718
fa073d69
MS
3719/* Parse a directive saving VFP registers for ARMv6 and above. */
3720
3721static void
3722s_arm_unwind_save_vfp_armv6 (void)
3723{
3724 int count;
3725 unsigned int start;
3726 valueT op;
3727 int num_vfpv3_regs = 0;
3728 int num_regs_below_16;
3729
3730 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3731 if (count == FAIL)
3732 {
3733 as_bad (_("expected register list"));
3734 ignore_rest_of_line ();
3735 return;
3736 }
3737
3738 demand_empty_rest_of_line ();
3739
3740 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3741 than FSTMX/FLDMX-style ones). */
3742
3743 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3744 if (start >= 16)
3745 num_vfpv3_regs = count;
3746 else if (start + count > 16)
3747 num_vfpv3_regs = start + count - 16;
3748
3749 if (num_vfpv3_regs > 0)
3750 {
3751 int start_offset = start > 16 ? start - 16 : 0;
3752 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3753 add_unwind_opcode (op, 2);
3754 }
3755
3756 /* Generate opcode for registers numbered in the range 0 .. 15. */
3757 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3758 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3759 if (num_regs_below_16 > 0)
3760 {
3761 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3762 add_unwind_opcode (op, 2);
3763 }
3764
3765 unwind.frame_size += count * 8;
3766}
3767
3768
3769/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3770
3771static void
c19d1205 3772s_arm_unwind_save_vfp (void)
b99bd4ef 3773{
c19d1205 3774 int count;
ca3f61f7 3775 unsigned int reg;
c19d1205 3776 valueT op;
b99bd4ef 3777
5287ad62 3778 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3779 if (count == FAIL)
b99bd4ef 3780 {
c19d1205
ZW
3781 as_bad (_("expected register list"));
3782 ignore_rest_of_line ();
b99bd4ef
NC
3783 return;
3784 }
3785
c19d1205 3786 demand_empty_rest_of_line ();
b99bd4ef 3787
c19d1205 3788 if (reg == 8)
b99bd4ef 3789 {
c19d1205
ZW
3790 /* Short form. */
3791 op = 0xb8 | (count - 1);
3792 add_unwind_opcode (op, 1);
b99bd4ef 3793 }
c19d1205 3794 else
b99bd4ef 3795 {
c19d1205
ZW
3796 /* Long form. */
3797 op = 0xb300 | (reg << 4) | (count - 1);
3798 add_unwind_opcode (op, 2);
b99bd4ef 3799 }
c19d1205
ZW
3800 unwind.frame_size += count * 8 + 4;
3801}
b99bd4ef 3802
b99bd4ef 3803
c19d1205
ZW
3804/* Parse a directive saving iWMMXt data registers. */
3805
3806static void
3807s_arm_unwind_save_mmxwr (void)
3808{
3809 int reg;
3810 int hi_reg;
3811 int i;
3812 unsigned mask = 0;
3813 valueT op;
b99bd4ef 3814
c19d1205
ZW
3815 if (*input_line_pointer == '{')
3816 input_line_pointer++;
b99bd4ef 3817
c19d1205 3818 do
b99bd4ef 3819 {
dcbf9037 3820 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3821
c19d1205 3822 if (reg == FAIL)
b99bd4ef 3823 {
9b7132d3 3824 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3825 goto error;
b99bd4ef
NC
3826 }
3827
c19d1205
ZW
3828 if (mask >> reg)
3829 as_tsktsk (_("register list not in ascending order"));
3830 mask |= 1 << reg;
b99bd4ef 3831
c19d1205
ZW
3832 if (*input_line_pointer == '-')
3833 {
3834 input_line_pointer++;
dcbf9037 3835 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3836 if (hi_reg == FAIL)
3837 {
9b7132d3 3838 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3839 goto error;
3840 }
3841 else if (reg >= hi_reg)
3842 {
3843 as_bad (_("bad register range"));
3844 goto error;
3845 }
3846 for (; reg < hi_reg; reg++)
3847 mask |= 1 << reg;
3848 }
3849 }
3850 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3851
c19d1205
ZW
3852 if (*input_line_pointer == '}')
3853 input_line_pointer++;
b99bd4ef 3854
c19d1205 3855 demand_empty_rest_of_line ();
b99bd4ef 3856
708587a4 3857 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3858 the list. */
3859 flush_pending_unwind ();
b99bd4ef 3860
c19d1205 3861 for (i = 0; i < 16; i++)
b99bd4ef 3862 {
c19d1205
ZW
3863 if (mask & (1 << i))
3864 unwind.frame_size += 8;
b99bd4ef
NC
3865 }
3866
c19d1205
ZW
3867 /* Attempt to combine with a previous opcode. We do this because gcc
3868 likes to output separate unwind directives for a single block of
3869 registers. */
3870 if (unwind.opcode_count > 0)
b99bd4ef 3871 {
c19d1205
ZW
3872 i = unwind.opcodes[unwind.opcode_count - 1];
3873 if ((i & 0xf8) == 0xc0)
3874 {
3875 i &= 7;
3876 /* Only merge if the blocks are contiguous. */
3877 if (i < 6)
3878 {
3879 if ((mask & 0xfe00) == (1 << 9))
3880 {
3881 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3882 unwind.opcode_count--;
3883 }
3884 }
3885 else if (i == 6 && unwind.opcode_count >= 2)
3886 {
3887 i = unwind.opcodes[unwind.opcode_count - 2];
3888 reg = i >> 4;
3889 i &= 0xf;
b99bd4ef 3890
c19d1205
ZW
3891 op = 0xffff << (reg - 1);
3892 if (reg > 0
87a1fd79 3893 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3894 {
3895 op = (1 << (reg + i + 1)) - 1;
3896 op &= ~((1 << reg) - 1);
3897 mask |= op;
3898 unwind.opcode_count -= 2;
3899 }
3900 }
3901 }
b99bd4ef
NC
3902 }
3903
c19d1205
ZW
3904 hi_reg = 15;
3905 /* We want to generate opcodes in the order the registers have been
3906 saved, ie. descending order. */
3907 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3908 {
c19d1205
ZW
3909 /* Save registers in blocks. */
3910 if (reg < 0
3911 || !(mask & (1 << reg)))
3912 {
3913 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3914 preceding block. */
c19d1205
ZW
3915 if (reg != hi_reg)
3916 {
3917 if (reg == 9)
3918 {
3919 /* Short form. */
3920 op = 0xc0 | (hi_reg - 10);
3921 add_unwind_opcode (op, 1);
3922 }
3923 else
3924 {
3925 /* Long form. */
3926 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3927 add_unwind_opcode (op, 2);
3928 }
3929 }
3930 hi_reg = reg - 1;
3931 }
b99bd4ef
NC
3932 }
3933
c19d1205
ZW
3934 return;
3935error:
3936 ignore_rest_of_line ();
b99bd4ef
NC
3937}
3938
3939static void
c19d1205 3940s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3941{
c19d1205
ZW
3942 int reg;
3943 int hi_reg;
3944 unsigned mask = 0;
3945 valueT op;
b99bd4ef 3946
c19d1205
ZW
3947 if (*input_line_pointer == '{')
3948 input_line_pointer++;
b99bd4ef 3949
c19d1205 3950 do
b99bd4ef 3951 {
dcbf9037 3952 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3953
c19d1205
ZW
3954 if (reg == FAIL)
3955 {
9b7132d3 3956 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3957 goto error;
3958 }
b99bd4ef 3959
c19d1205
ZW
3960 reg -= 8;
3961 if (mask >> reg)
3962 as_tsktsk (_("register list not in ascending order"));
3963 mask |= 1 << reg;
b99bd4ef 3964
c19d1205
ZW
3965 if (*input_line_pointer == '-')
3966 {
3967 input_line_pointer++;
dcbf9037 3968 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3969 if (hi_reg == FAIL)
3970 {
9b7132d3 3971 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3972 goto error;
3973 }
3974 else if (reg >= hi_reg)
3975 {
3976 as_bad (_("bad register range"));
3977 goto error;
3978 }
3979 for (; reg < hi_reg; reg++)
3980 mask |= 1 << reg;
3981 }
b99bd4ef 3982 }
c19d1205 3983 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3984
c19d1205
ZW
3985 if (*input_line_pointer == '}')
3986 input_line_pointer++;
b99bd4ef 3987
c19d1205
ZW
3988 demand_empty_rest_of_line ();
3989
708587a4 3990 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3991 the list. */
3992 flush_pending_unwind ();
b99bd4ef 3993
c19d1205 3994 for (reg = 0; reg < 16; reg++)
b99bd4ef 3995 {
c19d1205
ZW
3996 if (mask & (1 << reg))
3997 unwind.frame_size += 4;
b99bd4ef 3998 }
c19d1205
ZW
3999 op = 0xc700 | mask;
4000 add_unwind_opcode (op, 2);
4001 return;
4002error:
4003 ignore_rest_of_line ();
b99bd4ef
NC
4004}
4005
c19d1205 4006
fa073d69
MS
4007/* Parse an unwind_save directive.
4008 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4009
b99bd4ef 4010static void
fa073d69 4011s_arm_unwind_save (int arch_v6)
b99bd4ef 4012{
c19d1205
ZW
4013 char *peek;
4014 struct reg_entry *reg;
4015 bfd_boolean had_brace = FALSE;
b99bd4ef 4016
921e5f0a 4017 if (!unwind.proc_start)
c921be7d 4018 as_bad (MISSING_FNSTART);
921e5f0a 4019
c19d1205
ZW
4020 /* Figure out what sort of save we have. */
4021 peek = input_line_pointer;
b99bd4ef 4022
c19d1205 4023 if (*peek == '{')
b99bd4ef 4024 {
c19d1205
ZW
4025 had_brace = TRUE;
4026 peek++;
b99bd4ef
NC
4027 }
4028
c19d1205 4029 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4030
c19d1205 4031 if (!reg)
b99bd4ef 4032 {
c19d1205
ZW
4033 as_bad (_("register expected"));
4034 ignore_rest_of_line ();
b99bd4ef
NC
4035 return;
4036 }
4037
c19d1205 4038 switch (reg->type)
b99bd4ef 4039 {
c19d1205
ZW
4040 case REG_TYPE_FN:
4041 if (had_brace)
4042 {
4043 as_bad (_("FPA .unwind_save does not take a register list"));
4044 ignore_rest_of_line ();
4045 return;
4046 }
93ac2687 4047 input_line_pointer = peek;
c19d1205 4048 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4049 return;
c19d1205
ZW
4050
4051 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
4052 case REG_TYPE_VFD:
4053 if (arch_v6)
4054 s_arm_unwind_save_vfp_armv6 ();
4055 else
4056 s_arm_unwind_save_vfp ();
4057 return;
c19d1205
ZW
4058 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4059 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4060
4061 default:
4062 as_bad (_(".unwind_save does not support this kind of register"));
4063 ignore_rest_of_line ();
b99bd4ef 4064 }
c19d1205 4065}
b99bd4ef 4066
b99bd4ef 4067
c19d1205
ZW
4068/* Parse an unwind_movsp directive. */
4069
4070static void
4071s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4072{
4073 int reg;
4074 valueT op;
4fa3602b 4075 int offset;
c19d1205 4076
921e5f0a 4077 if (!unwind.proc_start)
c921be7d 4078 as_bad (MISSING_FNSTART);
921e5f0a 4079
dcbf9037 4080 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4081 if (reg == FAIL)
b99bd4ef 4082 {
9b7132d3 4083 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4084 ignore_rest_of_line ();
b99bd4ef
NC
4085 return;
4086 }
4fa3602b
PB
4087
4088 /* Optional constant. */
4089 if (skip_past_comma (&input_line_pointer) != FAIL)
4090 {
4091 if (immediate_for_directive (&offset) == FAIL)
4092 return;
4093 }
4094 else
4095 offset = 0;
4096
c19d1205 4097 demand_empty_rest_of_line ();
b99bd4ef 4098
c19d1205 4099 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4100 {
c19d1205 4101 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4102 return;
4103 }
4104
c19d1205
ZW
4105 if (unwind.fp_reg != REG_SP)
4106 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4107
c19d1205
ZW
4108 /* Generate opcode to restore the value. */
4109 op = 0x90 | reg;
4110 add_unwind_opcode (op, 1);
4111
4112 /* Record the information for later. */
4113 unwind.fp_reg = reg;
4fa3602b 4114 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4115 unwind.sp_restored = 1;
b05fe5cf
ZW
4116}
4117
c19d1205
ZW
4118/* Parse an unwind_pad directive. */
4119
b05fe5cf 4120static void
c19d1205 4121s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4122{
c19d1205 4123 int offset;
b05fe5cf 4124
921e5f0a 4125 if (!unwind.proc_start)
c921be7d 4126 as_bad (MISSING_FNSTART);
921e5f0a 4127
c19d1205
ZW
4128 if (immediate_for_directive (&offset) == FAIL)
4129 return;
b99bd4ef 4130
c19d1205
ZW
4131 if (offset & 3)
4132 {
4133 as_bad (_("stack increment must be multiple of 4"));
4134 ignore_rest_of_line ();
4135 return;
4136 }
b99bd4ef 4137
c19d1205
ZW
4138 /* Don't generate any opcodes, just record the details for later. */
4139 unwind.frame_size += offset;
4140 unwind.pending_offset += offset;
4141
4142 demand_empty_rest_of_line ();
4143}
4144
4145/* Parse an unwind_setfp directive. */
4146
4147static void
4148s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4149{
c19d1205
ZW
4150 int sp_reg;
4151 int fp_reg;
4152 int offset;
4153
921e5f0a 4154 if (!unwind.proc_start)
c921be7d 4155 as_bad (MISSING_FNSTART);
921e5f0a 4156
dcbf9037 4157 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4158 if (skip_past_comma (&input_line_pointer) == FAIL)
4159 sp_reg = FAIL;
4160 else
dcbf9037 4161 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4162
c19d1205
ZW
4163 if (fp_reg == FAIL || sp_reg == FAIL)
4164 {
4165 as_bad (_("expected <reg>, <reg>"));
4166 ignore_rest_of_line ();
4167 return;
4168 }
b99bd4ef 4169
c19d1205
ZW
4170 /* Optional constant. */
4171 if (skip_past_comma (&input_line_pointer) != FAIL)
4172 {
4173 if (immediate_for_directive (&offset) == FAIL)
4174 return;
4175 }
4176 else
4177 offset = 0;
a737bd4d 4178
c19d1205 4179 demand_empty_rest_of_line ();
a737bd4d 4180
fdfde340 4181 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4182 {
c19d1205
ZW
4183 as_bad (_("register must be either sp or set by a previous"
4184 "unwind_movsp directive"));
4185 return;
a737bd4d
NC
4186 }
4187
c19d1205
ZW
4188 /* Don't generate any opcodes, just record the information for later. */
4189 unwind.fp_reg = fp_reg;
4190 unwind.fp_used = 1;
fdfde340 4191 if (sp_reg == REG_SP)
c19d1205
ZW
4192 unwind.fp_offset = unwind.frame_size - offset;
4193 else
4194 unwind.fp_offset -= offset;
a737bd4d
NC
4195}
4196
c19d1205
ZW
4197/* Parse an unwind_raw directive. */
4198
4199static void
4200s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4201{
c19d1205 4202 expressionS exp;
708587a4 4203 /* This is an arbitrary limit. */
c19d1205
ZW
4204 unsigned char op[16];
4205 int count;
a737bd4d 4206
921e5f0a 4207 if (!unwind.proc_start)
c921be7d 4208 as_bad (MISSING_FNSTART);
921e5f0a 4209
c19d1205
ZW
4210 expression (&exp);
4211 if (exp.X_op == O_constant
4212 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4213 {
c19d1205
ZW
4214 unwind.frame_size += exp.X_add_number;
4215 expression (&exp);
4216 }
4217 else
4218 exp.X_op = O_illegal;
a737bd4d 4219
c19d1205
ZW
4220 if (exp.X_op != O_constant)
4221 {
4222 as_bad (_("expected <offset>, <opcode>"));
4223 ignore_rest_of_line ();
4224 return;
4225 }
a737bd4d 4226
c19d1205 4227 count = 0;
a737bd4d 4228
c19d1205
ZW
4229 /* Parse the opcode. */
4230 for (;;)
4231 {
4232 if (count >= 16)
4233 {
4234 as_bad (_("unwind opcode too long"));
4235 ignore_rest_of_line ();
a737bd4d 4236 }
c19d1205 4237 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4238 {
c19d1205
ZW
4239 as_bad (_("invalid unwind opcode"));
4240 ignore_rest_of_line ();
4241 return;
a737bd4d 4242 }
c19d1205 4243 op[count++] = exp.X_add_number;
a737bd4d 4244
c19d1205
ZW
4245 /* Parse the next byte. */
4246 if (skip_past_comma (&input_line_pointer) == FAIL)
4247 break;
a737bd4d 4248
c19d1205
ZW
4249 expression (&exp);
4250 }
b99bd4ef 4251
c19d1205
ZW
4252 /* Add the opcode bytes in reverse order. */
4253 while (count--)
4254 add_unwind_opcode (op[count], 1);
b99bd4ef 4255
c19d1205 4256 demand_empty_rest_of_line ();
b99bd4ef 4257}
ee065d83
PB
4258
4259
4260/* Parse a .eabi_attribute directive. */
4261
4262static void
4263s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4264{
ee3c0378
AS
4265 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4266
4267 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4268 attributes_set_explicitly[tag] = 1;
ee065d83 4269}
8463be01 4270#endif /* OBJ_ELF */
ee065d83
PB
4271
4272static void s_arm_arch (int);
7a1d4c38 4273static void s_arm_object_arch (int);
ee065d83
PB
4274static void s_arm_cpu (int);
4275static void s_arm_fpu (int);
69133863 4276static void s_arm_arch_extension (int);
b99bd4ef 4277
f0927246
NC
4278#ifdef TE_PE
4279
4280static void
5f4273c7 4281pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4282{
4283 expressionS exp;
4284
4285 do
4286 {
4287 expression (&exp);
4288 if (exp.X_op == O_symbol)
4289 exp.X_op = O_secrel;
4290
4291 emit_expr (&exp, 4);
4292 }
4293 while (*input_line_pointer++ == ',');
4294
4295 input_line_pointer--;
4296 demand_empty_rest_of_line ();
4297}
4298#endif /* TE_PE */
4299
c19d1205
ZW
4300/* This table describes all the machine specific pseudo-ops the assembler
4301 has to support. The fields are:
4302 pseudo-op name without dot
4303 function to call to execute this pseudo-op
4304 Integer arg to pass to the function. */
b99bd4ef 4305
c19d1205 4306const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4307{
c19d1205
ZW
4308 /* Never called because '.req' does not start a line. */
4309 { "req", s_req, 0 },
dcbf9037
JB
4310 /* Following two are likewise never called. */
4311 { "dn", s_dn, 0 },
4312 { "qn", s_qn, 0 },
c19d1205
ZW
4313 { "unreq", s_unreq, 0 },
4314 { "bss", s_bss, 0 },
4315 { "align", s_align, 0 },
4316 { "arm", s_arm, 0 },
4317 { "thumb", s_thumb, 0 },
4318 { "code", s_code, 0 },
4319 { "force_thumb", s_force_thumb, 0 },
4320 { "thumb_func", s_thumb_func, 0 },
4321 { "thumb_set", s_thumb_set, 0 },
4322 { "even", s_even, 0 },
4323 { "ltorg", s_ltorg, 0 },
4324 { "pool", s_ltorg, 0 },
4325 { "syntax", s_syntax, 0 },
8463be01
PB
4326 { "cpu", s_arm_cpu, 0 },
4327 { "arch", s_arm_arch, 0 },
7a1d4c38 4328 { "object_arch", s_arm_object_arch, 0 },
8463be01 4329 { "fpu", s_arm_fpu, 0 },
69133863 4330 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4331#ifdef OBJ_ELF
c921be7d
NC
4332 { "word", s_arm_elf_cons, 4 },
4333 { "long", s_arm_elf_cons, 4 },
4334 { "inst.n", s_arm_elf_inst, 2 },
4335 { "inst.w", s_arm_elf_inst, 4 },
4336 { "inst", s_arm_elf_inst, 0 },
4337 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4338 { "fnstart", s_arm_unwind_fnstart, 0 },
4339 { "fnend", s_arm_unwind_fnend, 0 },
4340 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4341 { "personality", s_arm_unwind_personality, 0 },
4342 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4343 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4344 { "save", s_arm_unwind_save, 0 },
fa073d69 4345 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4346 { "movsp", s_arm_unwind_movsp, 0 },
4347 { "pad", s_arm_unwind_pad, 0 },
4348 { "setfp", s_arm_unwind_setfp, 0 },
4349 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4350 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
4351#else
4352 { "word", cons, 4},
f0927246
NC
4353
4354 /* These are used for dwarf. */
4355 {"2byte", cons, 2},
4356 {"4byte", cons, 4},
4357 {"8byte", cons, 8},
4358 /* These are used for dwarf2. */
4359 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4360 { "loc", dwarf2_directive_loc, 0 },
4361 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4362#endif
4363 { "extend", float_cons, 'x' },
4364 { "ldouble", float_cons, 'x' },
4365 { "packed", float_cons, 'p' },
f0927246
NC
4366#ifdef TE_PE
4367 {"secrel32", pe_directive_secrel, 0},
4368#endif
c19d1205
ZW
4369 { 0, 0, 0 }
4370};
4371\f
4372/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4373
c19d1205
ZW
4374/* Generic immediate-value read function for use in insn parsing.
4375 STR points to the beginning of the immediate (the leading #);
4376 VAL receives the value; if the value is outside [MIN, MAX]
4377 issue an error. PREFIX_OPT is true if the immediate prefix is
4378 optional. */
b99bd4ef 4379
c19d1205
ZW
4380static int
4381parse_immediate (char **str, int *val, int min, int max,
4382 bfd_boolean prefix_opt)
4383{
4384 expressionS exp;
4385 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4386 if (exp.X_op != O_constant)
b99bd4ef 4387 {
c19d1205
ZW
4388 inst.error = _("constant expression required");
4389 return FAIL;
4390 }
b99bd4ef 4391
c19d1205
ZW
4392 if (exp.X_add_number < min || exp.X_add_number > max)
4393 {
4394 inst.error = _("immediate value out of range");
4395 return FAIL;
4396 }
b99bd4ef 4397
c19d1205
ZW
4398 *val = exp.X_add_number;
4399 return SUCCESS;
4400}
b99bd4ef 4401
5287ad62 4402/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4403 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4404 instructions. Puts the result directly in inst.operands[i]. */
4405
4406static int
4407parse_big_immediate (char **str, int i)
4408{
4409 expressionS exp;
4410 char *ptr = *str;
4411
4412 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4413
4414 if (exp.X_op == O_constant)
036dc3f7
PB
4415 {
4416 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4417 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4418 O_constant. We have to be careful not to break compilation for
4419 32-bit X_add_number, though. */
4420 if ((exp.X_add_number & ~0xffffffffl) != 0)
4421 {
4422 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4423 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4424 inst.operands[i].regisimm = 1;
4425 }
4426 }
5287ad62 4427 else if (exp.X_op == O_big
95b75c01 4428 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
5287ad62
JB
4429 {
4430 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4431
5287ad62
JB
4432 /* Bignums have their least significant bits in
4433 generic_bignum[0]. Make sure we put 32 bits in imm and
4434 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4435 gas_assert (parts != 0);
95b75c01
NC
4436
4437 /* Make sure that the number is not too big.
4438 PR 11972: Bignums can now be sign-extended to the
4439 size of a .octa so check that the out of range bits
4440 are all zero or all one. */
4441 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4442 {
4443 LITTLENUM_TYPE m = -1;
4444
4445 if (generic_bignum[parts * 2] != 0
4446 && generic_bignum[parts * 2] != m)
4447 return FAIL;
4448
4449 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4450 if (generic_bignum[j] != generic_bignum[j-1])
4451 return FAIL;
4452 }
4453
5287ad62
JB
4454 inst.operands[i].imm = 0;
4455 for (j = 0; j < parts; j++, idx++)
4456 inst.operands[i].imm |= generic_bignum[idx]
4457 << (LITTLENUM_NUMBER_OF_BITS * j);
4458 inst.operands[i].reg = 0;
4459 for (j = 0; j < parts; j++, idx++)
4460 inst.operands[i].reg |= generic_bignum[idx]
4461 << (LITTLENUM_NUMBER_OF_BITS * j);
4462 inst.operands[i].regisimm = 1;
4463 }
4464 else
4465 return FAIL;
5f4273c7 4466
5287ad62
JB
4467 *str = ptr;
4468
4469 return SUCCESS;
4470}
4471
c19d1205
ZW
4472/* Returns the pseudo-register number of an FPA immediate constant,
4473 or FAIL if there isn't a valid constant here. */
b99bd4ef 4474
c19d1205
ZW
4475static int
4476parse_fpa_immediate (char ** str)
4477{
4478 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4479 char * save_in;
4480 expressionS exp;
4481 int i;
4482 int j;
b99bd4ef 4483
c19d1205
ZW
4484 /* First try and match exact strings, this is to guarantee
4485 that some formats will work even for cross assembly. */
b99bd4ef 4486
c19d1205
ZW
4487 for (i = 0; fp_const[i]; i++)
4488 {
4489 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4490 {
c19d1205 4491 char *start = *str;
b99bd4ef 4492
c19d1205
ZW
4493 *str += strlen (fp_const[i]);
4494 if (is_end_of_line[(unsigned char) **str])
4495 return i + 8;
4496 *str = start;
4497 }
4498 }
b99bd4ef 4499
c19d1205
ZW
4500 /* Just because we didn't get a match doesn't mean that the constant
4501 isn't valid, just that it is in a format that we don't
4502 automatically recognize. Try parsing it with the standard
4503 expression routines. */
b99bd4ef 4504
c19d1205 4505 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4506
c19d1205
ZW
4507 /* Look for a raw floating point number. */
4508 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4509 && is_end_of_line[(unsigned char) *save_in])
4510 {
4511 for (i = 0; i < NUM_FLOAT_VALS; i++)
4512 {
4513 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4514 {
c19d1205
ZW
4515 if (words[j] != fp_values[i][j])
4516 break;
b99bd4ef
NC
4517 }
4518
c19d1205 4519 if (j == MAX_LITTLENUMS)
b99bd4ef 4520 {
c19d1205
ZW
4521 *str = save_in;
4522 return i + 8;
b99bd4ef
NC
4523 }
4524 }
4525 }
b99bd4ef 4526
c19d1205
ZW
4527 /* Try and parse a more complex expression, this will probably fail
4528 unless the code uses a floating point prefix (eg "0f"). */
4529 save_in = input_line_pointer;
4530 input_line_pointer = *str;
4531 if (expression (&exp) == absolute_section
4532 && exp.X_op == O_big
4533 && exp.X_add_number < 0)
4534 {
4535 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4536 Ditto for 15. */
4537 if (gen_to_words (words, 5, (long) 15) == 0)
4538 {
4539 for (i = 0; i < NUM_FLOAT_VALS; i++)
4540 {
4541 for (j = 0; j < MAX_LITTLENUMS; j++)
4542 {
4543 if (words[j] != fp_values[i][j])
4544 break;
4545 }
b99bd4ef 4546
c19d1205
ZW
4547 if (j == MAX_LITTLENUMS)
4548 {
4549 *str = input_line_pointer;
4550 input_line_pointer = save_in;
4551 return i + 8;
4552 }
4553 }
4554 }
b99bd4ef
NC
4555 }
4556
c19d1205
ZW
4557 *str = input_line_pointer;
4558 input_line_pointer = save_in;
4559 inst.error = _("invalid FPA immediate expression");
4560 return FAIL;
b99bd4ef
NC
4561}
4562
136da414
JB
4563/* Returns 1 if a number has "quarter-precision" float format
4564 0baBbbbbbc defgh000 00000000 00000000. */
4565
4566static int
4567is_quarter_float (unsigned imm)
4568{
4569 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4570 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4571}
4572
4573/* Parse an 8-bit "quarter-precision" floating point number of the form:
4574 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4575 The zero and minus-zero cases need special handling, since they can't be
4576 encoded in the "quarter-precision" float format, but can nonetheless be
4577 loaded as integer constants. */
136da414
JB
4578
4579static unsigned
4580parse_qfloat_immediate (char **ccp, int *immed)
4581{
4582 char *str = *ccp;
c96612cc 4583 char *fpnum;
136da414 4584 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4585 int found_fpchar = 0;
5f4273c7 4586
136da414 4587 skip_past_char (&str, '#');
5f4273c7 4588
c96612cc
JB
4589 /* We must not accidentally parse an integer as a floating-point number. Make
4590 sure that the value we parse is not an integer by checking for special
4591 characters '.' or 'e'.
4592 FIXME: This is a horrible hack, but doing better is tricky because type
4593 information isn't in a very usable state at parse time. */
4594 fpnum = str;
4595 skip_whitespace (fpnum);
4596
4597 if (strncmp (fpnum, "0x", 2) == 0)
4598 return FAIL;
4599 else
4600 {
4601 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4602 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4603 {
4604 found_fpchar = 1;
4605 break;
4606 }
4607
4608 if (!found_fpchar)
4609 return FAIL;
4610 }
5f4273c7 4611
136da414
JB
4612 if ((str = atof_ieee (str, 's', words)) != NULL)
4613 {
4614 unsigned fpword = 0;
4615 int i;
5f4273c7 4616
136da414
JB
4617 /* Our FP word must be 32 bits (single-precision FP). */
4618 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4619 {
4620 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4621 fpword |= words[i];
4622 }
5f4273c7 4623
c96612cc 4624 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4625 *immed = fpword;
4626 else
4627 return FAIL;
4628
4629 *ccp = str;
5f4273c7 4630
136da414
JB
4631 return SUCCESS;
4632 }
5f4273c7 4633
136da414
JB
4634 return FAIL;
4635}
4636
c19d1205
ZW
4637/* Shift operands. */
4638enum shift_kind
b99bd4ef 4639{
c19d1205
ZW
4640 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4641};
b99bd4ef 4642
c19d1205
ZW
4643struct asm_shift_name
4644{
4645 const char *name;
4646 enum shift_kind kind;
4647};
b99bd4ef 4648
c19d1205
ZW
4649/* Third argument to parse_shift. */
4650enum parse_shift_mode
4651{
4652 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4653 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4654 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4655 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4656 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4657};
b99bd4ef 4658
c19d1205
ZW
4659/* Parse a <shift> specifier on an ARM data processing instruction.
4660 This has three forms:
b99bd4ef 4661
c19d1205
ZW
4662 (LSL|LSR|ASL|ASR|ROR) Rs
4663 (LSL|LSR|ASL|ASR|ROR) #imm
4664 RRX
b99bd4ef 4665
c19d1205
ZW
4666 Note that ASL is assimilated to LSL in the instruction encoding, and
4667 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4668
c19d1205
ZW
4669static int
4670parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4671{
c19d1205
ZW
4672 const struct asm_shift_name *shift_name;
4673 enum shift_kind shift;
4674 char *s = *str;
4675 char *p = s;
4676 int reg;
b99bd4ef 4677
c19d1205
ZW
4678 for (p = *str; ISALPHA (*p); p++)
4679 ;
b99bd4ef 4680
c19d1205 4681 if (p == *str)
b99bd4ef 4682 {
c19d1205
ZW
4683 inst.error = _("shift expression expected");
4684 return FAIL;
b99bd4ef
NC
4685 }
4686
21d799b5
NC
4687 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4688 p - *str);
c19d1205
ZW
4689
4690 if (shift_name == NULL)
b99bd4ef 4691 {
c19d1205
ZW
4692 inst.error = _("shift expression expected");
4693 return FAIL;
b99bd4ef
NC
4694 }
4695
c19d1205 4696 shift = shift_name->kind;
b99bd4ef 4697
c19d1205
ZW
4698 switch (mode)
4699 {
4700 case NO_SHIFT_RESTRICT:
4701 case SHIFT_IMMEDIATE: break;
b99bd4ef 4702
c19d1205
ZW
4703 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4704 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4705 {
4706 inst.error = _("'LSL' or 'ASR' required");
4707 return FAIL;
4708 }
4709 break;
b99bd4ef 4710
c19d1205
ZW
4711 case SHIFT_LSL_IMMEDIATE:
4712 if (shift != SHIFT_LSL)
4713 {
4714 inst.error = _("'LSL' required");
4715 return FAIL;
4716 }
4717 break;
b99bd4ef 4718
c19d1205
ZW
4719 case SHIFT_ASR_IMMEDIATE:
4720 if (shift != SHIFT_ASR)
4721 {
4722 inst.error = _("'ASR' required");
4723 return FAIL;
4724 }
4725 break;
b99bd4ef 4726
c19d1205
ZW
4727 default: abort ();
4728 }
b99bd4ef 4729
c19d1205
ZW
4730 if (shift != SHIFT_RRX)
4731 {
4732 /* Whitespace can appear here if the next thing is a bare digit. */
4733 skip_whitespace (p);
b99bd4ef 4734
c19d1205 4735 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4736 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4737 {
4738 inst.operands[i].imm = reg;
4739 inst.operands[i].immisreg = 1;
4740 }
4741 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4742 return FAIL;
4743 }
4744 inst.operands[i].shift_kind = shift;
4745 inst.operands[i].shifted = 1;
4746 *str = p;
4747 return SUCCESS;
b99bd4ef
NC
4748}
4749
c19d1205 4750/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4751
c19d1205
ZW
4752 #<immediate>
4753 #<immediate>, <rotate>
4754 <Rm>
4755 <Rm>, <shift>
b99bd4ef 4756
c19d1205
ZW
4757 where <shift> is defined by parse_shift above, and <rotate> is a
4758 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4759 is deferred to md_apply_fix. */
b99bd4ef 4760
c19d1205
ZW
4761static int
4762parse_shifter_operand (char **str, int i)
4763{
4764 int value;
91d6fa6a 4765 expressionS exp;
b99bd4ef 4766
dcbf9037 4767 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4768 {
4769 inst.operands[i].reg = value;
4770 inst.operands[i].isreg = 1;
b99bd4ef 4771
c19d1205
ZW
4772 /* parse_shift will override this if appropriate */
4773 inst.reloc.exp.X_op = O_constant;
4774 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4775
c19d1205
ZW
4776 if (skip_past_comma (str) == FAIL)
4777 return SUCCESS;
b99bd4ef 4778
c19d1205
ZW
4779 /* Shift operation on register. */
4780 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4781 }
4782
c19d1205
ZW
4783 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4784 return FAIL;
b99bd4ef 4785
c19d1205 4786 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4787 {
c19d1205 4788 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 4789 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 4790 return FAIL;
b99bd4ef 4791
91d6fa6a 4792 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
4793 {
4794 inst.error = _("constant expression expected");
4795 return FAIL;
4796 }
b99bd4ef 4797
91d6fa6a 4798 value = exp.X_add_number;
c19d1205
ZW
4799 if (value < 0 || value > 30 || value % 2 != 0)
4800 {
4801 inst.error = _("invalid rotation");
4802 return FAIL;
4803 }
4804 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4805 {
4806 inst.error = _("invalid constant");
4807 return FAIL;
4808 }
09d92015 4809
55cf6793 4810 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4811 inst.reloc.exp.X_add_number
4812 = (((inst.reloc.exp.X_add_number << (32 - value))
4813 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4814 }
4815
c19d1205
ZW
4816 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4817 inst.reloc.pc_rel = 0;
4818 return SUCCESS;
09d92015
MM
4819}
4820
4962c51a
MS
4821/* Group relocation information. Each entry in the table contains the
4822 textual name of the relocation as may appear in assembler source
4823 and must end with a colon.
4824 Along with this textual name are the relocation codes to be used if
4825 the corresponding instruction is an ALU instruction (ADD or SUB only),
4826 an LDR, an LDRS, or an LDC. */
4827
4828struct group_reloc_table_entry
4829{
4830 const char *name;
4831 int alu_code;
4832 int ldr_code;
4833 int ldrs_code;
4834 int ldc_code;
4835};
4836
4837typedef enum
4838{
4839 /* Varieties of non-ALU group relocation. */
4840
4841 GROUP_LDR,
4842 GROUP_LDRS,
4843 GROUP_LDC
4844} group_reloc_type;
4845
4846static struct group_reloc_table_entry group_reloc_table[] =
4847 { /* Program counter relative: */
4848 { "pc_g0_nc",
4849 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4850 0, /* LDR */
4851 0, /* LDRS */
4852 0 }, /* LDC */
4853 { "pc_g0",
4854 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4855 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4856 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4857 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4858 { "pc_g1_nc",
4859 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4860 0, /* LDR */
4861 0, /* LDRS */
4862 0 }, /* LDC */
4863 { "pc_g1",
4864 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4865 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4866 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4867 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4868 { "pc_g2",
4869 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4870 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4871 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4872 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4873 /* Section base relative */
4874 { "sb_g0_nc",
4875 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4876 0, /* LDR */
4877 0, /* LDRS */
4878 0 }, /* LDC */
4879 { "sb_g0",
4880 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4881 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4882 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4883 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4884 { "sb_g1_nc",
4885 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4886 0, /* LDR */
4887 0, /* LDRS */
4888 0 }, /* LDC */
4889 { "sb_g1",
4890 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4891 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4892 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4893 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4894 { "sb_g2",
4895 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4896 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4897 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4898 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4899
4900/* Given the address of a pointer pointing to the textual name of a group
4901 relocation as may appear in assembler source, attempt to find its details
4902 in group_reloc_table. The pointer will be updated to the character after
4903 the trailing colon. On failure, FAIL will be returned; SUCCESS
4904 otherwise. On success, *entry will be updated to point at the relevant
4905 group_reloc_table entry. */
4906
4907static int
4908find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4909{
4910 unsigned int i;
4911 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4912 {
4913 int length = strlen (group_reloc_table[i].name);
4914
5f4273c7
NC
4915 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4916 && (*str)[length] == ':')
4962c51a
MS
4917 {
4918 *out = &group_reloc_table[i];
4919 *str += (length + 1);
4920 return SUCCESS;
4921 }
4922 }
4923
4924 return FAIL;
4925}
4926
4927/* Parse a <shifter_operand> for an ARM data processing instruction
4928 (as for parse_shifter_operand) where group relocations are allowed:
4929
4930 #<immediate>
4931 #<immediate>, <rotate>
4932 #:<group_reloc>:<expression>
4933 <Rm>
4934 <Rm>, <shift>
4935
4936 where <group_reloc> is one of the strings defined in group_reloc_table.
4937 The hashes are optional.
4938
4939 Everything else is as for parse_shifter_operand. */
4940
4941static parse_operand_result
4942parse_shifter_operand_group_reloc (char **str, int i)
4943{
4944 /* Determine if we have the sequence of characters #: or just :
4945 coming next. If we do, then we check for a group relocation.
4946 If we don't, punt the whole lot to parse_shifter_operand. */
4947
4948 if (((*str)[0] == '#' && (*str)[1] == ':')
4949 || (*str)[0] == ':')
4950 {
4951 struct group_reloc_table_entry *entry;
4952
4953 if ((*str)[0] == '#')
4954 (*str) += 2;
4955 else
4956 (*str)++;
4957
4958 /* Try to parse a group relocation. Anything else is an error. */
4959 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4960 {
4961 inst.error = _("unknown group relocation");
4962 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4963 }
4964
4965 /* We now have the group relocation table entry corresponding to
4966 the name in the assembler source. Next, we parse the expression. */
4967 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4968 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4969
4970 /* Record the relocation type (always the ALU variant here). */
21d799b5 4971 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 4972 gas_assert (inst.reloc.type != 0);
4962c51a
MS
4973
4974 return PARSE_OPERAND_SUCCESS;
4975 }
4976 else
4977 return parse_shifter_operand (str, i) == SUCCESS
4978 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4979
4980 /* Never reached. */
4981}
4982
8e560766
MGD
4983/* Parse a Neon alignment expression. Information is written to
4984 inst.operands[i]. We assume the initial ':' has been skipped.
4985
4986 align .imm = align << 8, .immisalign=1, .preind=0 */
4987static parse_operand_result
4988parse_neon_alignment (char **str, int i)
4989{
4990 char *p = *str;
4991 expressionS exp;
4992
4993 my_get_expression (&exp, &p, GE_NO_PREFIX);
4994
4995 if (exp.X_op != O_constant)
4996 {
4997 inst.error = _("alignment must be constant");
4998 return PARSE_OPERAND_FAIL;
4999 }
5000
5001 inst.operands[i].imm = exp.X_add_number << 8;
5002 inst.operands[i].immisalign = 1;
5003 /* Alignments are not pre-indexes. */
5004 inst.operands[i].preind = 0;
5005
5006 *str = p;
5007 return PARSE_OPERAND_SUCCESS;
5008}
5009
c19d1205
ZW
5010/* Parse all forms of an ARM address expression. Information is written
5011 to inst.operands[i] and/or inst.reloc.
09d92015 5012
c19d1205 5013 Preindexed addressing (.preind=1):
09d92015 5014
c19d1205
ZW
5015 [Rn, #offset] .reg=Rn .reloc.exp=offset
5016 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5017 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5018 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5019
c19d1205 5020 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5021
c19d1205 5022 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5023
c19d1205
ZW
5024 [Rn], #offset .reg=Rn .reloc.exp=offset
5025 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5026 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5027 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5028
c19d1205 5029 Unindexed addressing (.preind=0, .postind=0):
09d92015 5030
c19d1205 5031 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5032
c19d1205 5033 Other:
09d92015 5034
c19d1205
ZW
5035 [Rn]{!} shorthand for [Rn,#0]{!}
5036 =immediate .isreg=0 .reloc.exp=immediate
5037 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5038
c19d1205
ZW
5039 It is the caller's responsibility to check for addressing modes not
5040 supported by the instruction, and to set inst.reloc.type. */
5041
4962c51a
MS
5042static parse_operand_result
5043parse_address_main (char **str, int i, int group_relocations,
5044 group_reloc_type group_type)
09d92015 5045{
c19d1205
ZW
5046 char *p = *str;
5047 int reg;
09d92015 5048
c19d1205 5049 if (skip_past_char (&p, '[') == FAIL)
09d92015 5050 {
c19d1205
ZW
5051 if (skip_past_char (&p, '=') == FAIL)
5052 {
974da60d 5053 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5054 inst.reloc.pc_rel = 1;
5055 inst.operands[i].reg = REG_PC;
5056 inst.operands[i].isreg = 1;
5057 inst.operands[i].preind = 1;
5058 }
974da60d 5059 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
09d92015 5060
c19d1205 5061 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 5062 return PARSE_OPERAND_FAIL;
09d92015 5063
c19d1205 5064 *str = p;
4962c51a 5065 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5066 }
5067
dcbf9037 5068 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5069 {
c19d1205 5070 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5071 return PARSE_OPERAND_FAIL;
09d92015 5072 }
c19d1205
ZW
5073 inst.operands[i].reg = reg;
5074 inst.operands[i].isreg = 1;
09d92015 5075
c19d1205 5076 if (skip_past_comma (&p) == SUCCESS)
09d92015 5077 {
c19d1205 5078 inst.operands[i].preind = 1;
09d92015 5079
c19d1205
ZW
5080 if (*p == '+') p++;
5081 else if (*p == '-') p++, inst.operands[i].negative = 1;
5082
dcbf9037 5083 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5084 {
c19d1205
ZW
5085 inst.operands[i].imm = reg;
5086 inst.operands[i].immisreg = 1;
5087
5088 if (skip_past_comma (&p) == SUCCESS)
5089 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5090 return PARSE_OPERAND_FAIL;
c19d1205 5091 }
5287ad62 5092 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5093 {
5094 /* FIXME: '@' should be used here, but it's filtered out by generic
5095 code before we get to see it here. This may be subject to
5096 change. */
5097 parse_operand_result result = parse_neon_alignment (&p, i);
5098
5099 if (result != PARSE_OPERAND_SUCCESS)
5100 return result;
5101 }
c19d1205
ZW
5102 else
5103 {
5104 if (inst.operands[i].negative)
5105 {
5106 inst.operands[i].negative = 0;
5107 p--;
5108 }
4962c51a 5109
5f4273c7
NC
5110 if (group_relocations
5111 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5112 {
5113 struct group_reloc_table_entry *entry;
5114
5115 /* Skip over the #: or : sequence. */
5116 if (*p == '#')
5117 p += 2;
5118 else
5119 p++;
5120
5121 /* Try to parse a group relocation. Anything else is an
5122 error. */
5123 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5124 {
5125 inst.error = _("unknown group relocation");
5126 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5127 }
5128
5129 /* We now have the group relocation table entry corresponding to
5130 the name in the assembler source. Next, we parse the
5131 expression. */
5132 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5133 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5134
5135 /* Record the relocation type. */
5136 switch (group_type)
5137 {
5138 case GROUP_LDR:
21d799b5 5139 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
4962c51a
MS
5140 break;
5141
5142 case GROUP_LDRS:
21d799b5 5143 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
4962c51a
MS
5144 break;
5145
5146 case GROUP_LDC:
21d799b5 5147 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
4962c51a
MS
5148 break;
5149
5150 default:
9c2799c2 5151 gas_assert (0);
4962c51a
MS
5152 }
5153
5154 if (inst.reloc.type == 0)
5155 {
5156 inst.error = _("this group relocation is not allowed on this instruction");
5157 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5158 }
5159 }
5160 else
5161 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5162 return PARSE_OPERAND_FAIL;
09d92015
MM
5163 }
5164 }
8e560766
MGD
5165 else if (skip_past_char (&p, ':') == SUCCESS)
5166 {
5167 /* FIXME: '@' should be used here, but it's filtered out by generic code
5168 before we get to see it here. This may be subject to change. */
5169 parse_operand_result result = parse_neon_alignment (&p, i);
5170
5171 if (result != PARSE_OPERAND_SUCCESS)
5172 return result;
5173 }
09d92015 5174
c19d1205 5175 if (skip_past_char (&p, ']') == FAIL)
09d92015 5176 {
c19d1205 5177 inst.error = _("']' expected");
4962c51a 5178 return PARSE_OPERAND_FAIL;
09d92015
MM
5179 }
5180
c19d1205
ZW
5181 if (skip_past_char (&p, '!') == SUCCESS)
5182 inst.operands[i].writeback = 1;
09d92015 5183
c19d1205 5184 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5185 {
c19d1205
ZW
5186 if (skip_past_char (&p, '{') == SUCCESS)
5187 {
5188 /* [Rn], {expr} - unindexed, with option */
5189 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5190 0, 255, TRUE) == FAIL)
4962c51a 5191 return PARSE_OPERAND_FAIL;
09d92015 5192
c19d1205
ZW
5193 if (skip_past_char (&p, '}') == FAIL)
5194 {
5195 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5196 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5197 }
5198 if (inst.operands[i].preind)
5199 {
5200 inst.error = _("cannot combine index with option");
4962c51a 5201 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5202 }
5203 *str = p;
4962c51a 5204 return PARSE_OPERAND_SUCCESS;
09d92015 5205 }
c19d1205
ZW
5206 else
5207 {
5208 inst.operands[i].postind = 1;
5209 inst.operands[i].writeback = 1;
09d92015 5210
c19d1205
ZW
5211 if (inst.operands[i].preind)
5212 {
5213 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5214 return PARSE_OPERAND_FAIL;
c19d1205 5215 }
09d92015 5216
c19d1205
ZW
5217 if (*p == '+') p++;
5218 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5219
dcbf9037 5220 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5221 {
5287ad62
JB
5222 /* We might be using the immediate for alignment already. If we
5223 are, OR the register number into the low-order bits. */
5224 if (inst.operands[i].immisalign)
5225 inst.operands[i].imm |= reg;
5226 else
5227 inst.operands[i].imm = reg;
c19d1205 5228 inst.operands[i].immisreg = 1;
a737bd4d 5229
c19d1205
ZW
5230 if (skip_past_comma (&p) == SUCCESS)
5231 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5232 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5233 }
5234 else
5235 {
5236 if (inst.operands[i].negative)
5237 {
5238 inst.operands[i].negative = 0;
5239 p--;
5240 }
5241 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5242 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5243 }
5244 }
a737bd4d
NC
5245 }
5246
c19d1205
ZW
5247 /* If at this point neither .preind nor .postind is set, we have a
5248 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5249 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5250 {
5251 inst.operands[i].preind = 1;
5252 inst.reloc.exp.X_op = O_constant;
5253 inst.reloc.exp.X_add_number = 0;
5254 }
5255 *str = p;
4962c51a
MS
5256 return PARSE_OPERAND_SUCCESS;
5257}
5258
5259static int
5260parse_address (char **str, int i)
5261{
21d799b5 5262 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
4962c51a
MS
5263 ? SUCCESS : FAIL;
5264}
5265
5266static parse_operand_result
5267parse_address_group_reloc (char **str, int i, group_reloc_type type)
5268{
5269 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5270}
5271
b6895b4f
PB
5272/* Parse an operand for a MOVW or MOVT instruction. */
5273static int
5274parse_half (char **str)
5275{
5276 char * p;
5f4273c7 5277
b6895b4f
PB
5278 p = *str;
5279 skip_past_char (&p, '#');
5f4273c7 5280 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5281 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5282 else if (strncasecmp (p, ":upper16:", 9) == 0)
5283 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5284
5285 if (inst.reloc.type != BFD_RELOC_UNUSED)
5286 {
5287 p += 9;
5f4273c7 5288 skip_whitespace (p);
b6895b4f
PB
5289 }
5290
5291 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5292 return FAIL;
5293
5294 if (inst.reloc.type == BFD_RELOC_UNUSED)
5295 {
5296 if (inst.reloc.exp.X_op != O_constant)
5297 {
5298 inst.error = _("constant expression expected");
5299 return FAIL;
5300 }
5301 if (inst.reloc.exp.X_add_number < 0
5302 || inst.reloc.exp.X_add_number > 0xffff)
5303 {
5304 inst.error = _("immediate value out of range");
5305 return FAIL;
5306 }
5307 }
5308 *str = p;
5309 return SUCCESS;
5310}
5311
c19d1205 5312/* Miscellaneous. */
a737bd4d 5313
c19d1205
ZW
5314/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5315 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5316static int
5317parse_psr (char **str)
09d92015 5318{
c19d1205
ZW
5319 char *p;
5320 unsigned long psr_field;
62b3e311
PB
5321 const struct asm_psr *psr;
5322 char *start;
09d92015 5323
c19d1205
ZW
5324 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5325 feature for ease of use and backwards compatibility. */
5326 p = *str;
62b3e311 5327 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 5328 psr_field = SPSR_BIT;
59b42a0d
MGD
5329 else if (strncasecmp (p, "CPSR", 4) == 0
5330 || (strncasecmp (p, "APSR", 4) == 0
5331 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)))
c19d1205
ZW
5332 psr_field = 0;
5333 else
62b3e311
PB
5334 {
5335 start = p;
5336 do
5337 p++;
5338 while (ISALNUM (*p) || *p == '_');
5339
21d799b5
NC
5340 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5341 p - start);
62b3e311
PB
5342 if (!psr)
5343 return FAIL;
09d92015 5344
62b3e311
PB
5345 *str = p;
5346 return psr->field;
5347 }
09d92015 5348
62b3e311 5349 p += 4;
c19d1205
ZW
5350 if (*p == '_')
5351 {
5352 /* A suffix follows. */
c19d1205
ZW
5353 p++;
5354 start = p;
a737bd4d 5355
c19d1205
ZW
5356 do
5357 p++;
5358 while (ISALNUM (*p) || *p == '_');
a737bd4d 5359
21d799b5
NC
5360 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5361 p - start);
c19d1205
ZW
5362 if (!psr)
5363 goto error;
a737bd4d 5364
c19d1205 5365 psr_field |= psr->field;
a737bd4d 5366 }
c19d1205 5367 else
a737bd4d 5368 {
c19d1205
ZW
5369 if (ISALNUM (*p))
5370 goto error; /* Garbage after "[CS]PSR". */
5371
5372 psr_field |= (PSR_c | PSR_f);
a737bd4d 5373 }
c19d1205
ZW
5374 *str = p;
5375 return psr_field;
a737bd4d 5376
c19d1205
ZW
5377 error:
5378 inst.error = _("flag for {c}psr instruction expected");
5379 return FAIL;
a737bd4d
NC
5380}
5381
c19d1205
ZW
5382/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5383 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5384
c19d1205
ZW
5385static int
5386parse_cps_flags (char **str)
a737bd4d 5387{
c19d1205
ZW
5388 int val = 0;
5389 int saw_a_flag = 0;
5390 char *s = *str;
a737bd4d 5391
c19d1205
ZW
5392 for (;;)
5393 switch (*s++)
5394 {
5395 case '\0': case ',':
5396 goto done;
a737bd4d 5397
c19d1205
ZW
5398 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5399 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5400 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5401
c19d1205
ZW
5402 default:
5403 inst.error = _("unrecognized CPS flag");
5404 return FAIL;
5405 }
a737bd4d 5406
c19d1205
ZW
5407 done:
5408 if (saw_a_flag == 0)
a737bd4d 5409 {
c19d1205
ZW
5410 inst.error = _("missing CPS flags");
5411 return FAIL;
a737bd4d 5412 }
a737bd4d 5413
c19d1205
ZW
5414 *str = s - 1;
5415 return val;
a737bd4d
NC
5416}
5417
c19d1205
ZW
5418/* Parse an endian specifier ("BE" or "LE", case insensitive);
5419 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5420
5421static int
c19d1205 5422parse_endian_specifier (char **str)
a737bd4d 5423{
c19d1205
ZW
5424 int little_endian;
5425 char *s = *str;
a737bd4d 5426
c19d1205
ZW
5427 if (strncasecmp (s, "BE", 2))
5428 little_endian = 0;
5429 else if (strncasecmp (s, "LE", 2))
5430 little_endian = 1;
5431 else
a737bd4d 5432 {
c19d1205 5433 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5434 return FAIL;
5435 }
5436
c19d1205 5437 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5438 {
c19d1205 5439 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5440 return FAIL;
5441 }
5442
c19d1205
ZW
5443 *str = s + 2;
5444 return little_endian;
5445}
a737bd4d 5446
c19d1205
ZW
5447/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5448 value suitable for poking into the rotate field of an sxt or sxta
5449 instruction, or FAIL on error. */
5450
5451static int
5452parse_ror (char **str)
5453{
5454 int rot;
5455 char *s = *str;
5456
5457 if (strncasecmp (s, "ROR", 3) == 0)
5458 s += 3;
5459 else
a737bd4d 5460 {
c19d1205 5461 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5462 return FAIL;
5463 }
c19d1205
ZW
5464
5465 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5466 return FAIL;
5467
5468 switch (rot)
a737bd4d 5469 {
c19d1205
ZW
5470 case 0: *str = s; return 0x0;
5471 case 8: *str = s; return 0x1;
5472 case 16: *str = s; return 0x2;
5473 case 24: *str = s; return 0x3;
5474
5475 default:
5476 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5477 return FAIL;
5478 }
c19d1205 5479}
a737bd4d 5480
c19d1205
ZW
5481/* Parse a conditional code (from conds[] below). The value returned is in the
5482 range 0 .. 14, or FAIL. */
5483static int
5484parse_cond (char **str)
5485{
c462b453 5486 char *q;
c19d1205 5487 const struct asm_cond *c;
c462b453
PB
5488 int n;
5489 /* Condition codes are always 2 characters, so matching up to
5490 3 characters is sufficient. */
5491 char cond[3];
a737bd4d 5492
c462b453
PB
5493 q = *str;
5494 n = 0;
5495 while (ISALPHA (*q) && n < 3)
5496 {
e07e6e58 5497 cond[n] = TOLOWER (*q);
c462b453
PB
5498 q++;
5499 n++;
5500 }
a737bd4d 5501
21d799b5 5502 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5503 if (!c)
a737bd4d 5504 {
c19d1205 5505 inst.error = _("condition required");
a737bd4d
NC
5506 return FAIL;
5507 }
5508
c19d1205
ZW
5509 *str = q;
5510 return c->value;
5511}
5512
62b3e311
PB
5513/* Parse an option for a barrier instruction. Returns the encoding for the
5514 option, or FAIL. */
5515static int
5516parse_barrier (char **str)
5517{
5518 char *p, *q;
5519 const struct asm_barrier_opt *o;
5520
5521 p = q = *str;
5522 while (ISALPHA (*q))
5523 q++;
5524
21d799b5
NC
5525 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5526 q - p);
62b3e311
PB
5527 if (!o)
5528 return FAIL;
5529
5530 *str = q;
5531 return o->value;
5532}
5533
92e90b6e
PB
5534/* Parse the operands of a table branch instruction. Similar to a memory
5535 operand. */
5536static int
5537parse_tb (char **str)
5538{
5539 char * p = *str;
5540 int reg;
5541
5542 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5543 {
5544 inst.error = _("'[' expected");
5545 return FAIL;
5546 }
92e90b6e 5547
dcbf9037 5548 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5549 {
5550 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5551 return FAIL;
5552 }
5553 inst.operands[0].reg = reg;
5554
5555 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5556 {
5557 inst.error = _("',' expected");
5558 return FAIL;
5559 }
5f4273c7 5560
dcbf9037 5561 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5562 {
5563 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5564 return FAIL;
5565 }
5566 inst.operands[0].imm = reg;
5567
5568 if (skip_past_comma (&p) == SUCCESS)
5569 {
5570 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5571 return FAIL;
5572 if (inst.reloc.exp.X_add_number != 1)
5573 {
5574 inst.error = _("invalid shift");
5575 return FAIL;
5576 }
5577 inst.operands[0].shifted = 1;
5578 }
5579
5580 if (skip_past_char (&p, ']') == FAIL)
5581 {
5582 inst.error = _("']' expected");
5583 return FAIL;
5584 }
5585 *str = p;
5586 return SUCCESS;
5587}
5588
5287ad62
JB
5589/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5590 information on the types the operands can take and how they are encoded.
037e8744
JB
5591 Up to four operands may be read; this function handles setting the
5592 ".present" field for each read operand itself.
5287ad62
JB
5593 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5594 else returns FAIL. */
5595
5596static int
5597parse_neon_mov (char **str, int *which_operand)
5598{
5599 int i = *which_operand, val;
5600 enum arm_reg_type rtype;
5601 char *ptr = *str;
dcbf9037 5602 struct neon_type_el optype;
5f4273c7 5603
dcbf9037 5604 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5605 {
5606 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5607 inst.operands[i].reg = val;
5608 inst.operands[i].isscalar = 1;
dcbf9037 5609 inst.operands[i].vectype = optype;
5287ad62
JB
5610 inst.operands[i++].present = 1;
5611
5612 if (skip_past_comma (&ptr) == FAIL)
5613 goto wanted_comma;
5f4273c7 5614
dcbf9037 5615 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5616 goto wanted_arm;
5f4273c7 5617
5287ad62
JB
5618 inst.operands[i].reg = val;
5619 inst.operands[i].isreg = 1;
5620 inst.operands[i].present = 1;
5621 }
037e8744 5622 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5623 != FAIL)
5287ad62
JB
5624 {
5625 /* Cases 0, 1, 2, 3, 5 (D only). */
5626 if (skip_past_comma (&ptr) == FAIL)
5627 goto wanted_comma;
5f4273c7 5628
5287ad62
JB
5629 inst.operands[i].reg = val;
5630 inst.operands[i].isreg = 1;
5631 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5632 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5633 inst.operands[i].isvec = 1;
dcbf9037 5634 inst.operands[i].vectype = optype;
5287ad62
JB
5635 inst.operands[i++].present = 1;
5636
dcbf9037 5637 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5638 {
037e8744
JB
5639 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5640 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5641 inst.operands[i].reg = val;
5642 inst.operands[i].isreg = 1;
037e8744 5643 inst.operands[i].present = 1;
5287ad62
JB
5644
5645 if (rtype == REG_TYPE_NQ)
5646 {
dcbf9037 5647 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5648 return FAIL;
5649 }
037e8744
JB
5650 else if (rtype != REG_TYPE_VFS)
5651 {
5652 i++;
5653 if (skip_past_comma (&ptr) == FAIL)
5654 goto wanted_comma;
5655 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5656 goto wanted_arm;
5657 inst.operands[i].reg = val;
5658 inst.operands[i].isreg = 1;
5659 inst.operands[i].present = 1;
5660 }
5287ad62 5661 }
037e8744
JB
5662 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5663 &optype)) != FAIL)
5287ad62
JB
5664 {
5665 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5666 Case 1: VMOV<c><q> <Dd>, <Dm>
5667 Case 8: VMOV.F32 <Sd>, <Sm>
5668 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5669
5670 inst.operands[i].reg = val;
5671 inst.operands[i].isreg = 1;
5672 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5673 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5674 inst.operands[i].isvec = 1;
dcbf9037 5675 inst.operands[i].vectype = optype;
5287ad62 5676 inst.operands[i].present = 1;
5f4273c7 5677
037e8744
JB
5678 if (skip_past_comma (&ptr) == SUCCESS)
5679 {
5680 /* Case 15. */
5681 i++;
5682
5683 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5684 goto wanted_arm;
5685
5686 inst.operands[i].reg = val;
5687 inst.operands[i].isreg = 1;
5688 inst.operands[i++].present = 1;
5f4273c7 5689
037e8744
JB
5690 if (skip_past_comma (&ptr) == FAIL)
5691 goto wanted_comma;
5f4273c7 5692
037e8744
JB
5693 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5694 goto wanted_arm;
5f4273c7 5695
037e8744
JB
5696 inst.operands[i].reg = val;
5697 inst.operands[i].isreg = 1;
5698 inst.operands[i++].present = 1;
5699 }
5287ad62 5700 }
4641781c
PB
5701 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5702 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5703 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5704 Case 10: VMOV.F32 <Sd>, #<imm>
5705 Case 11: VMOV.F64 <Dd>, #<imm> */
5706 inst.operands[i].immisfloat = 1;
5707 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5708 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5709 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5710 ;
5287ad62
JB
5711 else
5712 {
dcbf9037 5713 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5714 return FAIL;
5715 }
5716 }
dcbf9037 5717 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5718 {
5719 /* Cases 6, 7. */
5720 inst.operands[i].reg = val;
5721 inst.operands[i].isreg = 1;
5722 inst.operands[i++].present = 1;
5f4273c7 5723
5287ad62
JB
5724 if (skip_past_comma (&ptr) == FAIL)
5725 goto wanted_comma;
5f4273c7 5726
dcbf9037 5727 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5728 {
5729 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5730 inst.operands[i].reg = val;
5731 inst.operands[i].isscalar = 1;
5732 inst.operands[i].present = 1;
dcbf9037 5733 inst.operands[i].vectype = optype;
5287ad62 5734 }
dcbf9037 5735 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5736 {
5737 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5738 inst.operands[i].reg = val;
5739 inst.operands[i].isreg = 1;
5740 inst.operands[i++].present = 1;
5f4273c7 5741
5287ad62
JB
5742 if (skip_past_comma (&ptr) == FAIL)
5743 goto wanted_comma;
5f4273c7 5744
037e8744 5745 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5746 == FAIL)
5287ad62 5747 {
037e8744 5748 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5749 return FAIL;
5750 }
5751
5752 inst.operands[i].reg = val;
5753 inst.operands[i].isreg = 1;
037e8744
JB
5754 inst.operands[i].isvec = 1;
5755 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5756 inst.operands[i].vectype = optype;
5287ad62 5757 inst.operands[i].present = 1;
5f4273c7 5758
037e8744
JB
5759 if (rtype == REG_TYPE_VFS)
5760 {
5761 /* Case 14. */
5762 i++;
5763 if (skip_past_comma (&ptr) == FAIL)
5764 goto wanted_comma;
5765 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5766 &optype)) == FAIL)
5767 {
5768 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5769 return FAIL;
5770 }
5771 inst.operands[i].reg = val;
5772 inst.operands[i].isreg = 1;
5773 inst.operands[i].isvec = 1;
5774 inst.operands[i].issingle = 1;
5775 inst.operands[i].vectype = optype;
5776 inst.operands[i].present = 1;
5777 }
5778 }
5779 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5780 != FAIL)
5781 {
5782 /* Case 13. */
5783 inst.operands[i].reg = val;
5784 inst.operands[i].isreg = 1;
5785 inst.operands[i].isvec = 1;
5786 inst.operands[i].issingle = 1;
5787 inst.operands[i].vectype = optype;
5788 inst.operands[i++].present = 1;
5287ad62
JB
5789 }
5790 }
5791 else
5792 {
dcbf9037 5793 first_error (_("parse error"));
5287ad62
JB
5794 return FAIL;
5795 }
5796
5797 /* Successfully parsed the operands. Update args. */
5798 *which_operand = i;
5799 *str = ptr;
5800 return SUCCESS;
5801
5f4273c7 5802 wanted_comma:
dcbf9037 5803 first_error (_("expected comma"));
5287ad62 5804 return FAIL;
5f4273c7
NC
5805
5806 wanted_arm:
dcbf9037 5807 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5808 return FAIL;
5287ad62
JB
5809}
5810
5be8be5d
DG
5811/* Use this macro when the operand constraints are different
5812 for ARM and THUMB (e.g. ldrd). */
5813#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
5814 ((arm_operand) | ((thumb_operand) << 16))
5815
c19d1205
ZW
5816/* Matcher codes for parse_operands. */
5817enum operand_parse_code
5818{
5819 OP_stop, /* end of line */
5820
5821 OP_RR, /* ARM register */
5822 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 5823 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 5824 OP_RRnpcb, /* ARM register, not r15, in square brackets */
55881a11
MGD
5825 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
5826 optional trailing ! */
c19d1205
ZW
5827 OP_RRw, /* ARM register, not r15, optional trailing ! */
5828 OP_RCP, /* Coprocessor number */
5829 OP_RCN, /* Coprocessor register */
5830 OP_RF, /* FPA register */
5831 OP_RVS, /* VFP single precision register */
5287ad62
JB
5832 OP_RVD, /* VFP double precision register (0..15) */
5833 OP_RND, /* Neon double precision register (0..31) */
5834 OP_RNQ, /* Neon quad precision register */
037e8744 5835 OP_RVSD, /* VFP single or double precision register */
5287ad62 5836 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5837 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5838 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5839 OP_RVC, /* VFP control register */
5840 OP_RMF, /* Maverick F register */
5841 OP_RMD, /* Maverick D register */
5842 OP_RMFX, /* Maverick FX register */
5843 OP_RMDX, /* Maverick DX register */
5844 OP_RMAX, /* Maverick AX register */
5845 OP_RMDS, /* Maverick DSPSC register */
5846 OP_RIWR, /* iWMMXt wR register */
5847 OP_RIWC, /* iWMMXt wC register */
5848 OP_RIWG, /* iWMMXt wCG register */
5849 OP_RXA, /* XScale accumulator register */
5850
5851 OP_REGLST, /* ARM register list */
5852 OP_VRSLST, /* VFP single-precision register list */
5853 OP_VRDLST, /* VFP double-precision register list */
037e8744 5854 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5855 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5856 OP_NSTRLST, /* Neon element/structure list */
5857
5287ad62 5858 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5859 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5860 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5861 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5862 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5863 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5864 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 5865 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 5866 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5867 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5868
5869 OP_I0, /* immediate zero */
c19d1205
ZW
5870 OP_I7, /* immediate value 0 .. 7 */
5871 OP_I15, /* 0 .. 15 */
5872 OP_I16, /* 1 .. 16 */
5287ad62 5873 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5874 OP_I31, /* 0 .. 31 */
5875 OP_I31w, /* 0 .. 31, optional trailing ! */
5876 OP_I32, /* 1 .. 32 */
5287ad62
JB
5877 OP_I32z, /* 0 .. 32 */
5878 OP_I63, /* 0 .. 63 */
c19d1205 5879 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5880 OP_I64, /* 1 .. 64 */
5881 OP_I64z, /* 0 .. 64 */
c19d1205 5882 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5883
5884 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5885 OP_I7b, /* 0 .. 7 */
5886 OP_I15b, /* 0 .. 15 */
5887 OP_I31b, /* 0 .. 31 */
5888
5889 OP_SH, /* shifter operand */
4962c51a 5890 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5891 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5892 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5893 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5894 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5895 OP_EXP, /* arbitrary expression */
5896 OP_EXPi, /* same, with optional immediate prefix */
5897 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5898 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5899
5900 OP_CPSF, /* CPS flags */
5901 OP_ENDI, /* Endianness specifier */
5902 OP_PSR, /* CPSR/SPSR mask for msr */
5903 OP_COND, /* conditional code */
92e90b6e 5904 OP_TB, /* Table branch. */
c19d1205 5905
037e8744
JB
5906 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5907 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5908
c19d1205
ZW
5909 OP_RRnpc_I0, /* ARM register or literal 0 */
5910 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5911 OP_RR_EXi, /* ARM register or expression with imm prefix */
5912 OP_RF_IF, /* FPA register or immediate */
5913 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5914 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5915
5916 /* Optional operands. */
5917 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5918 OP_oI31b, /* 0 .. 31 */
5287ad62 5919 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5920 OP_oIffffb, /* 0 .. 65535 */
5921 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5922
5923 OP_oRR, /* ARM register */
5924 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 5925 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 5926 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5927 OP_oRND, /* Optional Neon double precision register */
5928 OP_oRNQ, /* Optional Neon quad precision register */
5929 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5930 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5931 OP_oSHll, /* LSL immediate */
5932 OP_oSHar, /* ASR immediate */
5933 OP_oSHllar, /* LSL or ASR immediate */
5934 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 5935 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 5936
5be8be5d
DG
5937 /* Some pre-defined mixed (ARM/THUMB) operands. */
5938 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
5939 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
5940 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
5941
c19d1205
ZW
5942 OP_FIRST_OPTIONAL = OP_oI7b
5943};
a737bd4d 5944
c19d1205
ZW
5945/* Generic instruction operand parser. This does no encoding and no
5946 semantic validation; it merely squirrels values away in the inst
5947 structure. Returns SUCCESS or FAIL depending on whether the
5948 specified grammar matched. */
5949static int
5be8be5d 5950parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 5951{
5be8be5d 5952 unsigned const int *upat = pattern;
c19d1205
ZW
5953 char *backtrack_pos = 0;
5954 const char *backtrack_error = 0;
5955 int i, val, backtrack_index = 0;
5287ad62 5956 enum arm_reg_type rtype;
4962c51a 5957 parse_operand_result result;
5be8be5d 5958 unsigned int op_parse_code;
c19d1205 5959
e07e6e58
NC
5960#define po_char_or_fail(chr) \
5961 do \
5962 { \
5963 if (skip_past_char (&str, chr) == FAIL) \
5964 goto bad_args; \
5965 } \
5966 while (0)
c19d1205 5967
e07e6e58
NC
5968#define po_reg_or_fail(regtype) \
5969 do \
dcbf9037 5970 { \
e07e6e58
NC
5971 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5972 & inst.operands[i].vectype); \
5973 if (val == FAIL) \
5974 { \
5975 first_error (_(reg_expected_msgs[regtype])); \
5976 goto failure; \
5977 } \
5978 inst.operands[i].reg = val; \
5979 inst.operands[i].isreg = 1; \
5980 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5981 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5982 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5983 || rtype == REG_TYPE_VFD \
5984 || rtype == REG_TYPE_NQ); \
dcbf9037 5985 } \
e07e6e58
NC
5986 while (0)
5987
5988#define po_reg_or_goto(regtype, label) \
5989 do \
5990 { \
5991 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5992 & inst.operands[i].vectype); \
5993 if (val == FAIL) \
5994 goto label; \
dcbf9037 5995 \
e07e6e58
NC
5996 inst.operands[i].reg = val; \
5997 inst.operands[i].isreg = 1; \
5998 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5999 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6000 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6001 || rtype == REG_TYPE_VFD \
6002 || rtype == REG_TYPE_NQ); \
6003 } \
6004 while (0)
6005
6006#define po_imm_or_fail(min, max, popt) \
6007 do \
6008 { \
6009 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6010 goto failure; \
6011 inst.operands[i].imm = val; \
6012 } \
6013 while (0)
6014
6015#define po_scalar_or_goto(elsz, label) \
6016 do \
6017 { \
6018 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6019 if (val == FAIL) \
6020 goto label; \
6021 inst.operands[i].reg = val; \
6022 inst.operands[i].isscalar = 1; \
6023 } \
6024 while (0)
6025
6026#define po_misc_or_fail(expr) \
6027 do \
6028 { \
6029 if (expr) \
6030 goto failure; \
6031 } \
6032 while (0)
6033
6034#define po_misc_or_fail_no_backtrack(expr) \
6035 do \
6036 { \
6037 result = expr; \
6038 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6039 backtrack_pos = 0; \
6040 if (result != PARSE_OPERAND_SUCCESS) \
6041 goto failure; \
6042 } \
6043 while (0)
4962c51a 6044
52e7f43d
RE
6045#define po_barrier_or_imm(str) \
6046 do \
6047 { \
6048 val = parse_barrier (&str); \
6049 if (val == FAIL) \
6050 { \
6051 if (ISALPHA (*str)) \
6052 goto failure; \
6053 else \
6054 goto immediate; \
6055 } \
6056 else \
6057 { \
6058 if ((inst.instruction & 0xf0) == 0x60 \
6059 && val != 0xf) \
6060 { \
6061 /* ISB can only take SY as an option. */ \
6062 inst.error = _("invalid barrier type"); \
6063 goto failure; \
6064 } \
6065 } \
6066 } \
6067 while (0)
6068
c19d1205
ZW
6069 skip_whitespace (str);
6070
6071 for (i = 0; upat[i] != OP_stop; i++)
6072 {
5be8be5d
DG
6073 op_parse_code = upat[i];
6074 if (op_parse_code >= 1<<16)
6075 op_parse_code = thumb ? (op_parse_code >> 16)
6076 : (op_parse_code & ((1<<16)-1));
6077
6078 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6079 {
6080 /* Remember where we are in case we need to backtrack. */
9c2799c2 6081 gas_assert (!backtrack_pos);
c19d1205
ZW
6082 backtrack_pos = str;
6083 backtrack_error = inst.error;
6084 backtrack_index = i;
6085 }
6086
b6702015 6087 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6088 po_char_or_fail (',');
6089
5be8be5d 6090 switch (op_parse_code)
c19d1205
ZW
6091 {
6092 /* Registers */
6093 case OP_oRRnpc:
5be8be5d 6094 case OP_oRRnpcsp:
c19d1205 6095 case OP_RRnpc:
5be8be5d 6096 case OP_RRnpcsp:
c19d1205
ZW
6097 case OP_oRR:
6098 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6099 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6100 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6101 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6102 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6103 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
6104 case OP_oRND:
6105 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6106 case OP_RVC:
6107 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6108 break;
6109 /* Also accept generic coprocessor regs for unknown registers. */
6110 coproc_reg:
6111 po_reg_or_fail (REG_TYPE_CN);
6112 break;
c19d1205
ZW
6113 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6114 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6115 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6116 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6117 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6118 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6119 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6120 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6121 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6122 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
6123 case OP_oRNQ:
6124 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6125 case OP_oRNDQ:
6126 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
6127 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6128 case OP_oRNSDQ:
6129 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
6130
6131 /* Neon scalar. Using an element size of 8 means that some invalid
6132 scalars are accepted here, so deal with those in later code. */
6133 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6134
5287ad62
JB
6135 case OP_RNDQ_I0:
6136 {
6137 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6138 break;
6139 try_imm0:
6140 po_imm_or_fail (0, 0, TRUE);
6141 }
6142 break;
6143
037e8744
JB
6144 case OP_RVSD_I0:
6145 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6146 break;
6147
5287ad62
JB
6148 case OP_RR_RNSC:
6149 {
6150 po_scalar_or_goto (8, try_rr);
6151 break;
6152 try_rr:
6153 po_reg_or_fail (REG_TYPE_RN);
6154 }
6155 break;
6156
037e8744
JB
6157 case OP_RNSDQ_RNSC:
6158 {
6159 po_scalar_or_goto (8, try_nsdq);
6160 break;
6161 try_nsdq:
6162 po_reg_or_fail (REG_TYPE_NSDQ);
6163 }
6164 break;
6165
5287ad62
JB
6166 case OP_RNDQ_RNSC:
6167 {
6168 po_scalar_or_goto (8, try_ndq);
6169 break;
6170 try_ndq:
6171 po_reg_or_fail (REG_TYPE_NDQ);
6172 }
6173 break;
6174
6175 case OP_RND_RNSC:
6176 {
6177 po_scalar_or_goto (8, try_vfd);
6178 break;
6179 try_vfd:
6180 po_reg_or_fail (REG_TYPE_VFD);
6181 }
6182 break;
6183
6184 case OP_VMOV:
6185 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6186 not careful then bad things might happen. */
6187 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6188 break;
6189
4316f0d2 6190 case OP_RNDQ_Ibig:
5287ad62 6191 {
4316f0d2 6192 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
5287ad62 6193 break;
4316f0d2 6194 try_immbig:
5287ad62
JB
6195 /* There's a possibility of getting a 64-bit immediate here, so
6196 we need special handling. */
6197 if (parse_big_immediate (&str, i) == FAIL)
6198 {
6199 inst.error = _("immediate value is out of range");
6200 goto failure;
6201 }
6202 }
6203 break;
6204
6205 case OP_RNDQ_I63b:
6206 {
6207 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6208 break;
6209 try_shimm:
6210 po_imm_or_fail (0, 63, TRUE);
6211 }
6212 break;
c19d1205
ZW
6213
6214 case OP_RRnpcb:
6215 po_char_or_fail ('[');
6216 po_reg_or_fail (REG_TYPE_RN);
6217 po_char_or_fail (']');
6218 break;
a737bd4d 6219
55881a11 6220 case OP_RRnpctw:
c19d1205 6221 case OP_RRw:
b6702015 6222 case OP_oRRw:
c19d1205
ZW
6223 po_reg_or_fail (REG_TYPE_RN);
6224 if (skip_past_char (&str, '!') == SUCCESS)
6225 inst.operands[i].writeback = 1;
6226 break;
6227
6228 /* Immediates */
6229 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6230 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6231 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 6232 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6233 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6234 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 6235 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6236 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
6237 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6238 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6239 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6240 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6241
6242 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6243 case OP_oI7b:
6244 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6245 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6246 case OP_oI31b:
6247 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 6248 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
6249 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6250
6251 /* Immediate variants */
6252 case OP_oI255c:
6253 po_char_or_fail ('{');
6254 po_imm_or_fail (0, 255, TRUE);
6255 po_char_or_fail ('}');
6256 break;
6257
6258 case OP_I31w:
6259 /* The expression parser chokes on a trailing !, so we have
6260 to find it first and zap it. */
6261 {
6262 char *s = str;
6263 while (*s && *s != ',')
6264 s++;
6265 if (s[-1] == '!')
6266 {
6267 s[-1] = '\0';
6268 inst.operands[i].writeback = 1;
6269 }
6270 po_imm_or_fail (0, 31, TRUE);
6271 if (str == s - 1)
6272 str = s;
6273 }
6274 break;
6275
6276 /* Expressions */
6277 case OP_EXPi: EXPi:
6278 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6279 GE_OPT_PREFIX));
6280 break;
6281
6282 case OP_EXP:
6283 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6284 GE_NO_PREFIX));
6285 break;
6286
6287 case OP_EXPr: EXPr:
6288 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6289 GE_NO_PREFIX));
6290 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6291 {
c19d1205
ZW
6292 val = parse_reloc (&str);
6293 if (val == -1)
6294 {
6295 inst.error = _("unrecognized relocation suffix");
6296 goto failure;
6297 }
6298 else if (val != BFD_RELOC_UNUSED)
6299 {
6300 inst.operands[i].imm = val;
6301 inst.operands[i].hasreloc = 1;
6302 }
a737bd4d 6303 }
c19d1205 6304 break;
a737bd4d 6305
b6895b4f
PB
6306 /* Operand for MOVW or MOVT. */
6307 case OP_HALF:
6308 po_misc_or_fail (parse_half (&str));
6309 break;
6310
e07e6e58 6311 /* Register or expression. */
c19d1205
ZW
6312 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6313 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6314
e07e6e58 6315 /* Register or immediate. */
c19d1205
ZW
6316 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6317 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6318
c19d1205
ZW
6319 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6320 IF:
6321 if (!is_immediate_prefix (*str))
6322 goto bad_args;
6323 str++;
6324 val = parse_fpa_immediate (&str);
6325 if (val == FAIL)
6326 goto failure;
6327 /* FPA immediates are encoded as registers 8-15.
6328 parse_fpa_immediate has already applied the offset. */
6329 inst.operands[i].reg = val;
6330 inst.operands[i].isreg = 1;
6331 break;
09d92015 6332
2d447fca
JM
6333 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6334 I32z: po_imm_or_fail (0, 32, FALSE); break;
6335
e07e6e58 6336 /* Two kinds of register. */
c19d1205
ZW
6337 case OP_RIWR_RIWC:
6338 {
6339 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6340 if (!rege
6341 || (rege->type != REG_TYPE_MMXWR
6342 && rege->type != REG_TYPE_MMXWC
6343 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6344 {
6345 inst.error = _("iWMMXt data or control register expected");
6346 goto failure;
6347 }
6348 inst.operands[i].reg = rege->number;
6349 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6350 }
6351 break;
09d92015 6352
41adaa5c
JM
6353 case OP_RIWC_RIWG:
6354 {
6355 struct reg_entry *rege = arm_reg_parse_multi (&str);
6356 if (!rege
6357 || (rege->type != REG_TYPE_MMXWC
6358 && rege->type != REG_TYPE_MMXWCG))
6359 {
6360 inst.error = _("iWMMXt control register expected");
6361 goto failure;
6362 }
6363 inst.operands[i].reg = rege->number;
6364 inst.operands[i].isreg = 1;
6365 }
6366 break;
6367
c19d1205
ZW
6368 /* Misc */
6369 case OP_CPSF: val = parse_cps_flags (&str); break;
6370 case OP_ENDI: val = parse_endian_specifier (&str); break;
6371 case OP_oROR: val = parse_ror (&str); break;
6372 case OP_PSR: val = parse_psr (&str); break;
6373 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6374 case OP_oBARRIER_I15:
6375 po_barrier_or_imm (str); break;
6376 immediate:
6377 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6378 goto failure;
6379 break;
c19d1205 6380
037e8744
JB
6381 case OP_RVC_PSR:
6382 po_reg_or_goto (REG_TYPE_VFC, try_psr);
6383 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6384 break;
6385 try_psr:
6386 val = parse_psr (&str);
6387 break;
6388
6389 case OP_APSR_RR:
6390 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6391 break;
6392 try_apsr:
6393 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6394 instruction). */
6395 if (strncasecmp (str, "APSR_", 5) == 0)
6396 {
6397 unsigned found = 0;
6398 str += 5;
6399 while (found < 15)
6400 switch (*str++)
6401 {
6402 case 'c': found = (found & 1) ? 16 : found | 1; break;
6403 case 'n': found = (found & 2) ? 16 : found | 2; break;
6404 case 'z': found = (found & 4) ? 16 : found | 4; break;
6405 case 'v': found = (found & 8) ? 16 : found | 8; break;
6406 default: found = 16;
6407 }
6408 if (found != 15)
6409 goto failure;
6410 inst.operands[i].isvec = 1;
f7c21dc7
NC
6411 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6412 inst.operands[i].reg = REG_PC;
037e8744
JB
6413 }
6414 else
6415 goto failure;
6416 break;
6417
92e90b6e
PB
6418 case OP_TB:
6419 po_misc_or_fail (parse_tb (&str));
6420 break;
6421
e07e6e58 6422 /* Register lists. */
c19d1205
ZW
6423 case OP_REGLST:
6424 val = parse_reg_list (&str);
6425 if (*str == '^')
6426 {
6427 inst.operands[1].writeback = 1;
6428 str++;
6429 }
6430 break;
09d92015 6431
c19d1205 6432 case OP_VRSLST:
5287ad62 6433 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6434 break;
09d92015 6435
c19d1205 6436 case OP_VRDLST:
5287ad62 6437 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6438 break;
a737bd4d 6439
037e8744
JB
6440 case OP_VRSDLST:
6441 /* Allow Q registers too. */
6442 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6443 REGLIST_NEON_D);
6444 if (val == FAIL)
6445 {
6446 inst.error = NULL;
6447 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6448 REGLIST_VFP_S);
6449 inst.operands[i].issingle = 1;
6450 }
6451 break;
6452
5287ad62
JB
6453 case OP_NRDLST:
6454 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6455 REGLIST_NEON_D);
6456 break;
6457
6458 case OP_NSTRLST:
dcbf9037
JB
6459 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6460 &inst.operands[i].vectype);
5287ad62
JB
6461 break;
6462
c19d1205
ZW
6463 /* Addressing modes */
6464 case OP_ADDR:
6465 po_misc_or_fail (parse_address (&str, i));
6466 break;
09d92015 6467
4962c51a
MS
6468 case OP_ADDRGLDR:
6469 po_misc_or_fail_no_backtrack (
6470 parse_address_group_reloc (&str, i, GROUP_LDR));
6471 break;
6472
6473 case OP_ADDRGLDRS:
6474 po_misc_or_fail_no_backtrack (
6475 parse_address_group_reloc (&str, i, GROUP_LDRS));
6476 break;
6477
6478 case OP_ADDRGLDC:
6479 po_misc_or_fail_no_backtrack (
6480 parse_address_group_reloc (&str, i, GROUP_LDC));
6481 break;
6482
c19d1205
ZW
6483 case OP_SH:
6484 po_misc_or_fail (parse_shifter_operand (&str, i));
6485 break;
09d92015 6486
4962c51a
MS
6487 case OP_SHG:
6488 po_misc_or_fail_no_backtrack (
6489 parse_shifter_operand_group_reloc (&str, i));
6490 break;
6491
c19d1205
ZW
6492 case OP_oSHll:
6493 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6494 break;
09d92015 6495
c19d1205
ZW
6496 case OP_oSHar:
6497 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6498 break;
09d92015 6499
c19d1205
ZW
6500 case OP_oSHllar:
6501 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6502 break;
09d92015 6503
c19d1205 6504 default:
5be8be5d 6505 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 6506 }
09d92015 6507
c19d1205
ZW
6508 /* Various value-based sanity checks and shared operations. We
6509 do not signal immediate failures for the register constraints;
6510 this allows a syntax error to take precedence. */
5be8be5d 6511 switch (op_parse_code)
c19d1205
ZW
6512 {
6513 case OP_oRRnpc:
6514 case OP_RRnpc:
6515 case OP_RRnpcb:
6516 case OP_RRw:
b6702015 6517 case OP_oRRw:
c19d1205
ZW
6518 case OP_RRnpc_I0:
6519 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6520 inst.error = BAD_PC;
6521 break;
09d92015 6522
5be8be5d
DG
6523 case OP_oRRnpcsp:
6524 case OP_RRnpcsp:
6525 if (inst.operands[i].isreg)
6526 {
6527 if (inst.operands[i].reg == REG_PC)
6528 inst.error = BAD_PC;
6529 else if (inst.operands[i].reg == REG_SP)
6530 inst.error = BAD_SP;
6531 }
6532 break;
6533
55881a11
MGD
6534 case OP_RRnpctw:
6535 if (inst.operands[i].isreg
6536 && inst.operands[i].reg == REG_PC
6537 && (inst.operands[i].writeback || thumb))
6538 inst.error = BAD_PC;
6539 break;
6540
c19d1205
ZW
6541 case OP_CPSF:
6542 case OP_ENDI:
6543 case OP_oROR:
6544 case OP_PSR:
037e8744 6545 case OP_RVC_PSR:
c19d1205 6546 case OP_COND:
52e7f43d 6547 case OP_oBARRIER_I15:
c19d1205
ZW
6548 case OP_REGLST:
6549 case OP_VRSLST:
6550 case OP_VRDLST:
037e8744 6551 case OP_VRSDLST:
5287ad62
JB
6552 case OP_NRDLST:
6553 case OP_NSTRLST:
c19d1205
ZW
6554 if (val == FAIL)
6555 goto failure;
6556 inst.operands[i].imm = val;
6557 break;
a737bd4d 6558
c19d1205
ZW
6559 default:
6560 break;
6561 }
09d92015 6562
c19d1205
ZW
6563 /* If we get here, this operand was successfully parsed. */
6564 inst.operands[i].present = 1;
6565 continue;
09d92015 6566
c19d1205 6567 bad_args:
09d92015 6568 inst.error = BAD_ARGS;
c19d1205
ZW
6569
6570 failure:
6571 if (!backtrack_pos)
d252fdde
PB
6572 {
6573 /* The parse routine should already have set inst.error, but set a
5f4273c7 6574 default here just in case. */
d252fdde
PB
6575 if (!inst.error)
6576 inst.error = _("syntax error");
6577 return FAIL;
6578 }
c19d1205
ZW
6579
6580 /* Do not backtrack over a trailing optional argument that
6581 absorbed some text. We will only fail again, with the
6582 'garbage following instruction' error message, which is
6583 probably less helpful than the current one. */
6584 if (backtrack_index == i && backtrack_pos != str
6585 && upat[i+1] == OP_stop)
d252fdde
PB
6586 {
6587 if (!inst.error)
6588 inst.error = _("syntax error");
6589 return FAIL;
6590 }
c19d1205
ZW
6591
6592 /* Try again, skipping the optional argument at backtrack_pos. */
6593 str = backtrack_pos;
6594 inst.error = backtrack_error;
6595 inst.operands[backtrack_index].present = 0;
6596 i = backtrack_index;
6597 backtrack_pos = 0;
09d92015 6598 }
09d92015 6599
c19d1205
ZW
6600 /* Check that we have parsed all the arguments. */
6601 if (*str != '\0' && !inst.error)
6602 inst.error = _("garbage following instruction");
09d92015 6603
c19d1205 6604 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6605}
6606
c19d1205
ZW
6607#undef po_char_or_fail
6608#undef po_reg_or_fail
6609#undef po_reg_or_goto
6610#undef po_imm_or_fail
5287ad62 6611#undef po_scalar_or_fail
52e7f43d 6612#undef po_barrier_or_imm
e07e6e58 6613
c19d1205 6614/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6615#define constraint(expr, err) \
6616 do \
c19d1205 6617 { \
e07e6e58
NC
6618 if (expr) \
6619 { \
6620 inst.error = err; \
6621 return; \
6622 } \
c19d1205 6623 } \
e07e6e58 6624 while (0)
c19d1205 6625
fdfde340
JM
6626/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6627 instructions are unpredictable if these registers are used. This
6628 is the BadReg predicate in ARM's Thumb-2 documentation. */
6629#define reject_bad_reg(reg) \
6630 do \
6631 if (reg == REG_SP || reg == REG_PC) \
6632 { \
6633 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6634 return; \
6635 } \
6636 while (0)
6637
94206790
MM
6638/* If REG is R13 (the stack pointer), warn that its use is
6639 deprecated. */
6640#define warn_deprecated_sp(reg) \
6641 do \
6642 if (warn_on_deprecated && reg == REG_SP) \
6643 as_warn (_("use of r13 is deprecated")); \
6644 while (0)
6645
c19d1205
ZW
6646/* Functions for operand encoding. ARM, then Thumb. */
6647
6648#define rotate_left(v, n) (v << n | v >> (32 - n))
6649
6650/* If VAL can be encoded in the immediate field of an ARM instruction,
6651 return the encoded form. Otherwise, return FAIL. */
6652
6653static unsigned int
6654encode_arm_immediate (unsigned int val)
09d92015 6655{
c19d1205
ZW
6656 unsigned int a, i;
6657
6658 for (i = 0; i < 32; i += 2)
6659 if ((a = rotate_left (val, i)) <= 0xff)
6660 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6661
6662 return FAIL;
09d92015
MM
6663}
6664
c19d1205
ZW
6665/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6666 return the encoded form. Otherwise, return FAIL. */
6667static unsigned int
6668encode_thumb32_immediate (unsigned int val)
09d92015 6669{
c19d1205 6670 unsigned int a, i;
09d92015 6671
9c3c69f2 6672 if (val <= 0xff)
c19d1205 6673 return val;
a737bd4d 6674
9c3c69f2 6675 for (i = 1; i <= 24; i++)
09d92015 6676 {
9c3c69f2
PB
6677 a = val >> i;
6678 if ((val & ~(0xff << i)) == 0)
6679 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6680 }
a737bd4d 6681
c19d1205
ZW
6682 a = val & 0xff;
6683 if (val == ((a << 16) | a))
6684 return 0x100 | a;
6685 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6686 return 0x300 | a;
09d92015 6687
c19d1205
ZW
6688 a = val & 0xff00;
6689 if (val == ((a << 16) | a))
6690 return 0x200 | (a >> 8);
a737bd4d 6691
c19d1205 6692 return FAIL;
09d92015 6693}
5287ad62 6694/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6695
6696static void
5287ad62
JB
6697encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6698{
6699 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6700 && reg > 15)
6701 {
b1cc4aeb 6702 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6703 {
6704 if (thumb_mode)
6705 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6706 fpu_vfp_ext_d32);
5287ad62
JB
6707 else
6708 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6709 fpu_vfp_ext_d32);
5287ad62
JB
6710 }
6711 else
6712 {
dcbf9037 6713 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6714 return;
6715 }
6716 }
6717
c19d1205 6718 switch (pos)
09d92015 6719 {
c19d1205
ZW
6720 case VFP_REG_Sd:
6721 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6722 break;
6723
6724 case VFP_REG_Sn:
6725 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6726 break;
6727
6728 case VFP_REG_Sm:
6729 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6730 break;
6731
5287ad62
JB
6732 case VFP_REG_Dd:
6733 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6734 break;
5f4273c7 6735
5287ad62
JB
6736 case VFP_REG_Dn:
6737 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6738 break;
5f4273c7 6739
5287ad62
JB
6740 case VFP_REG_Dm:
6741 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6742 break;
6743
c19d1205
ZW
6744 default:
6745 abort ();
09d92015 6746 }
09d92015
MM
6747}
6748
c19d1205 6749/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6750 if any, is handled by md_apply_fix. */
09d92015 6751static void
c19d1205 6752encode_arm_shift (int i)
09d92015 6753{
c19d1205
ZW
6754 if (inst.operands[i].shift_kind == SHIFT_RRX)
6755 inst.instruction |= SHIFT_ROR << 5;
6756 else
09d92015 6757 {
c19d1205
ZW
6758 inst.instruction |= inst.operands[i].shift_kind << 5;
6759 if (inst.operands[i].immisreg)
6760 {
6761 inst.instruction |= SHIFT_BY_REG;
6762 inst.instruction |= inst.operands[i].imm << 8;
6763 }
6764 else
6765 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6766 }
c19d1205 6767}
09d92015 6768
c19d1205
ZW
6769static void
6770encode_arm_shifter_operand (int i)
6771{
6772 if (inst.operands[i].isreg)
09d92015 6773 {
c19d1205
ZW
6774 inst.instruction |= inst.operands[i].reg;
6775 encode_arm_shift (i);
09d92015 6776 }
c19d1205
ZW
6777 else
6778 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6779}
6780
c19d1205 6781/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6782static void
c19d1205 6783encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6784{
9c2799c2 6785 gas_assert (inst.operands[i].isreg);
c19d1205 6786 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6787
c19d1205 6788 if (inst.operands[i].preind)
09d92015 6789 {
c19d1205
ZW
6790 if (is_t)
6791 {
6792 inst.error = _("instruction does not accept preindexed addressing");
6793 return;
6794 }
6795 inst.instruction |= PRE_INDEX;
6796 if (inst.operands[i].writeback)
6797 inst.instruction |= WRITE_BACK;
09d92015 6798
c19d1205
ZW
6799 }
6800 else if (inst.operands[i].postind)
6801 {
9c2799c2 6802 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
6803 if (is_t)
6804 inst.instruction |= WRITE_BACK;
6805 }
6806 else /* unindexed - only for coprocessor */
09d92015 6807 {
c19d1205 6808 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6809 return;
6810 }
6811
c19d1205
ZW
6812 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6813 && (((inst.instruction & 0x000f0000) >> 16)
6814 == ((inst.instruction & 0x0000f000) >> 12)))
6815 as_warn ((inst.instruction & LOAD_BIT)
6816 ? _("destination register same as write-back base")
6817 : _("source register same as write-back base"));
09d92015
MM
6818}
6819
c19d1205
ZW
6820/* inst.operands[i] was set up by parse_address. Encode it into an
6821 ARM-format mode 2 load or store instruction. If is_t is true,
6822 reject forms that cannot be used with a T instruction (i.e. not
6823 post-indexed). */
a737bd4d 6824static void
c19d1205 6825encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6826{
5be8be5d
DG
6827 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
6828
c19d1205 6829 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6830
c19d1205 6831 if (inst.operands[i].immisreg)
09d92015 6832 {
5be8be5d
DG
6833 constraint ((inst.operands[i].imm == REG_PC
6834 || (is_pc && inst.operands[i].writeback)),
6835 BAD_PC_ADDRESSING);
c19d1205
ZW
6836 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6837 inst.instruction |= inst.operands[i].imm;
6838 if (!inst.operands[i].negative)
6839 inst.instruction |= INDEX_UP;
6840 if (inst.operands[i].shifted)
6841 {
6842 if (inst.operands[i].shift_kind == SHIFT_RRX)
6843 inst.instruction |= SHIFT_ROR << 5;
6844 else
6845 {
6846 inst.instruction |= inst.operands[i].shift_kind << 5;
6847 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6848 }
6849 }
09d92015 6850 }
c19d1205 6851 else /* immediate offset in inst.reloc */
09d92015 6852 {
5be8be5d
DG
6853 if (is_pc && !inst.reloc.pc_rel)
6854 {
6855 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
6856
6857 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
6858 cannot use PC in addressing.
6859 PC cannot be used in writeback addressing, either. */
6860 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 6861 BAD_PC_ADDRESSING);
23a10334 6862
dc5ec521 6863 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
6864 if (warn_on_deprecated
6865 && !is_load
6866 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
6867 as_warn (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
6868 }
6869
c19d1205
ZW
6870 if (inst.reloc.type == BFD_RELOC_UNUSED)
6871 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6872 }
09d92015
MM
6873}
6874
c19d1205
ZW
6875/* inst.operands[i] was set up by parse_address. Encode it into an
6876 ARM-format mode 3 load or store instruction. Reject forms that
6877 cannot be used with such instructions. If is_t is true, reject
6878 forms that cannot be used with a T instruction (i.e. not
6879 post-indexed). */
6880static void
6881encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6882{
c19d1205 6883 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6884 {
c19d1205
ZW
6885 inst.error = _("instruction does not accept scaled register index");
6886 return;
09d92015 6887 }
a737bd4d 6888
c19d1205 6889 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6890
c19d1205
ZW
6891 if (inst.operands[i].immisreg)
6892 {
5be8be5d
DG
6893 constraint ((inst.operands[i].imm == REG_PC
6894 || inst.operands[i].reg == REG_PC),
6895 BAD_PC_ADDRESSING);
c19d1205
ZW
6896 inst.instruction |= inst.operands[i].imm;
6897 if (!inst.operands[i].negative)
6898 inst.instruction |= INDEX_UP;
6899 }
6900 else /* immediate offset in inst.reloc */
6901 {
5be8be5d
DG
6902 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
6903 && inst.operands[i].writeback),
6904 BAD_PC_WRITEBACK);
c19d1205
ZW
6905 inst.instruction |= HWOFFSET_IMM;
6906 if (inst.reloc.type == BFD_RELOC_UNUSED)
6907 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6908 }
a737bd4d
NC
6909}
6910
c19d1205
ZW
6911/* inst.operands[i] was set up by parse_address. Encode it into an
6912 ARM-format instruction. Reject all forms which cannot be encoded
6913 into a coprocessor load/store instruction. If wb_ok is false,
6914 reject use of writeback; if unind_ok is false, reject use of
6915 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6916 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6917 (in which case it is preserved). */
09d92015 6918
c19d1205
ZW
6919static int
6920encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6921{
c19d1205 6922 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6923
9c2799c2 6924 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6925
c19d1205 6926 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6927 {
9c2799c2 6928 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
6929 if (!unind_ok)
6930 {
6931 inst.error = _("instruction does not support unindexed addressing");
6932 return FAIL;
6933 }
6934 inst.instruction |= inst.operands[i].imm;
6935 inst.instruction |= INDEX_UP;
6936 return SUCCESS;
09d92015 6937 }
a737bd4d 6938
c19d1205
ZW
6939 if (inst.operands[i].preind)
6940 inst.instruction |= PRE_INDEX;
a737bd4d 6941
c19d1205 6942 if (inst.operands[i].writeback)
09d92015 6943 {
c19d1205
ZW
6944 if (inst.operands[i].reg == REG_PC)
6945 {
6946 inst.error = _("pc may not be used with write-back");
6947 return FAIL;
6948 }
6949 if (!wb_ok)
6950 {
6951 inst.error = _("instruction does not support writeback");
6952 return FAIL;
6953 }
6954 inst.instruction |= WRITE_BACK;
09d92015 6955 }
a737bd4d 6956
c19d1205 6957 if (reloc_override)
21d799b5 6958 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a
MS
6959 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6960 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6961 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6962 {
6963 if (thumb_mode)
6964 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6965 else
6966 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6967 }
6968
c19d1205
ZW
6969 return SUCCESS;
6970}
a737bd4d 6971
c19d1205
ZW
6972/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6973 Determine whether it can be performed with a move instruction; if
6974 it can, convert inst.instruction to that move instruction and
c921be7d
NC
6975 return TRUE; if it can't, convert inst.instruction to a literal-pool
6976 load and return FALSE. If this is not a valid thing to do in the
6977 current context, set inst.error and return TRUE.
a737bd4d 6978
c19d1205
ZW
6979 inst.operands[i] describes the destination register. */
6980
c921be7d 6981static bfd_boolean
c19d1205
ZW
6982move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6983{
53365c0d
PB
6984 unsigned long tbit;
6985
6986 if (thumb_p)
6987 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6988 else
6989 tbit = LOAD_BIT;
6990
6991 if ((inst.instruction & tbit) == 0)
09d92015 6992 {
c19d1205 6993 inst.error = _("invalid pseudo operation");
c921be7d 6994 return TRUE;
09d92015 6995 }
c19d1205 6996 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6997 {
6998 inst.error = _("constant expression expected");
c921be7d 6999 return TRUE;
09d92015 7000 }
c19d1205 7001 if (inst.reloc.exp.X_op == O_constant)
09d92015 7002 {
c19d1205
ZW
7003 if (thumb_p)
7004 {
53365c0d 7005 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
7006 {
7007 /* This can be done with a mov(1) instruction. */
7008 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7009 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 7010 return TRUE;
c19d1205
ZW
7011 }
7012 }
7013 else
7014 {
7015 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7016 if (value != FAIL)
7017 {
7018 /* This can be done with a mov instruction. */
7019 inst.instruction &= LITERAL_MASK;
7020 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7021 inst.instruction |= value & 0xfff;
c921be7d 7022 return TRUE;
c19d1205 7023 }
09d92015 7024
c19d1205
ZW
7025 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7026 if (value != FAIL)
7027 {
7028 /* This can be done with a mvn instruction. */
7029 inst.instruction &= LITERAL_MASK;
7030 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7031 inst.instruction |= value & 0xfff;
c921be7d 7032 return TRUE;
c19d1205
ZW
7033 }
7034 }
09d92015
MM
7035 }
7036
c19d1205
ZW
7037 if (add_to_lit_pool () == FAIL)
7038 {
7039 inst.error = _("literal pool insertion failed");
c921be7d 7040 return TRUE;
c19d1205
ZW
7041 }
7042 inst.operands[1].reg = REG_PC;
7043 inst.operands[1].isreg = 1;
7044 inst.operands[1].preind = 1;
7045 inst.reloc.pc_rel = 1;
7046 inst.reloc.type = (thumb_p
7047 ? BFD_RELOC_ARM_THUMB_OFFSET
7048 : (mode_3
7049 ? BFD_RELOC_ARM_HWLITERAL
7050 : BFD_RELOC_ARM_LITERAL));
c921be7d 7051 return FALSE;
09d92015
MM
7052}
7053
5f4273c7 7054/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
7055 First some generics; their names are taken from the conventional
7056 bit positions for register arguments in ARM format instructions. */
09d92015 7057
a737bd4d 7058static void
c19d1205 7059do_noargs (void)
09d92015 7060{
c19d1205 7061}
a737bd4d 7062
c19d1205
ZW
7063static void
7064do_rd (void)
7065{
7066 inst.instruction |= inst.operands[0].reg << 12;
7067}
a737bd4d 7068
c19d1205
ZW
7069static void
7070do_rd_rm (void)
7071{
7072 inst.instruction |= inst.operands[0].reg << 12;
7073 inst.instruction |= inst.operands[1].reg;
7074}
09d92015 7075
c19d1205
ZW
7076static void
7077do_rd_rn (void)
7078{
7079 inst.instruction |= inst.operands[0].reg << 12;
7080 inst.instruction |= inst.operands[1].reg << 16;
7081}
a737bd4d 7082
c19d1205
ZW
7083static void
7084do_rn_rd (void)
7085{
7086 inst.instruction |= inst.operands[0].reg << 16;
7087 inst.instruction |= inst.operands[1].reg << 12;
7088}
09d92015 7089
c19d1205
ZW
7090static void
7091do_rd_rm_rn (void)
7092{
9a64e435 7093 unsigned Rn = inst.operands[2].reg;
708587a4 7094 /* Enforce restrictions on SWP instruction. */
9a64e435 7095 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
7096 {
7097 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7098 _("Rn must not overlap other operands"));
7099
7100 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
7101 if (warn_on_deprecated
7102 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7103 as_warn (_("swp{b} use is deprecated for this architecture"));
7104
7105 }
c19d1205
ZW
7106 inst.instruction |= inst.operands[0].reg << 12;
7107 inst.instruction |= inst.operands[1].reg;
9a64e435 7108 inst.instruction |= Rn << 16;
c19d1205 7109}
09d92015 7110
c19d1205
ZW
7111static void
7112do_rd_rn_rm (void)
7113{
7114 inst.instruction |= inst.operands[0].reg << 12;
7115 inst.instruction |= inst.operands[1].reg << 16;
7116 inst.instruction |= inst.operands[2].reg;
7117}
a737bd4d 7118
c19d1205
ZW
7119static void
7120do_rm_rd_rn (void)
7121{
5be8be5d
DG
7122 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7123 constraint (((inst.reloc.exp.X_op != O_constant
7124 && inst.reloc.exp.X_op != O_illegal)
7125 || inst.reloc.exp.X_add_number != 0),
7126 BAD_ADDR_MODE);
c19d1205
ZW
7127 inst.instruction |= inst.operands[0].reg;
7128 inst.instruction |= inst.operands[1].reg << 12;
7129 inst.instruction |= inst.operands[2].reg << 16;
7130}
09d92015 7131
c19d1205
ZW
7132static void
7133do_imm0 (void)
7134{
7135 inst.instruction |= inst.operands[0].imm;
7136}
09d92015 7137
c19d1205
ZW
7138static void
7139do_rd_cpaddr (void)
7140{
7141 inst.instruction |= inst.operands[0].reg << 12;
7142 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 7143}
a737bd4d 7144
c19d1205
ZW
7145/* ARM instructions, in alphabetical order by function name (except
7146 that wrapper functions appear immediately after the function they
7147 wrap). */
09d92015 7148
c19d1205
ZW
7149/* This is a pseudo-op of the form "adr rd, label" to be converted
7150 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
7151
7152static void
c19d1205 7153do_adr (void)
09d92015 7154{
c19d1205 7155 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7156
c19d1205
ZW
7157 /* Frag hacking will turn this into a sub instruction if the offset turns
7158 out to be negative. */
7159 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 7160 inst.reloc.pc_rel = 1;
2fc8bdac 7161 inst.reloc.exp.X_add_number -= 8;
c19d1205 7162}
b99bd4ef 7163
c19d1205
ZW
7164/* This is a pseudo-op of the form "adrl rd, label" to be converted
7165 into a relative address of the form:
7166 add rd, pc, #low(label-.-8)"
7167 add rd, rd, #high(label-.-8)" */
b99bd4ef 7168
c19d1205
ZW
7169static void
7170do_adrl (void)
7171{
7172 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7173
c19d1205
ZW
7174 /* Frag hacking will turn this into a sub instruction if the offset turns
7175 out to be negative. */
7176 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
7177 inst.reloc.pc_rel = 1;
7178 inst.size = INSN_SIZE * 2;
2fc8bdac 7179 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
7180}
7181
b99bd4ef 7182static void
c19d1205 7183do_arit (void)
b99bd4ef 7184{
c19d1205
ZW
7185 if (!inst.operands[1].present)
7186 inst.operands[1].reg = inst.operands[0].reg;
7187 inst.instruction |= inst.operands[0].reg << 12;
7188 inst.instruction |= inst.operands[1].reg << 16;
7189 encode_arm_shifter_operand (2);
7190}
b99bd4ef 7191
62b3e311
PB
7192static void
7193do_barrier (void)
7194{
7195 if (inst.operands[0].present)
7196 {
7197 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
7198 && inst.operands[0].imm > 0xf
7199 && inst.operands[0].imm < 0x0,
bd3ba5d1 7200 _("bad barrier type"));
62b3e311
PB
7201 inst.instruction |= inst.operands[0].imm;
7202 }
7203 else
7204 inst.instruction |= 0xf;
7205}
7206
c19d1205
ZW
7207static void
7208do_bfc (void)
7209{
7210 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7211 constraint (msb > 32, _("bit-field extends past end of register"));
7212 /* The instruction encoding stores the LSB and MSB,
7213 not the LSB and width. */
7214 inst.instruction |= inst.operands[0].reg << 12;
7215 inst.instruction |= inst.operands[1].imm << 7;
7216 inst.instruction |= (msb - 1) << 16;
7217}
b99bd4ef 7218
c19d1205
ZW
7219static void
7220do_bfi (void)
7221{
7222 unsigned int msb;
b99bd4ef 7223
c19d1205
ZW
7224 /* #0 in second position is alternative syntax for bfc, which is
7225 the same instruction but with REG_PC in the Rm field. */
7226 if (!inst.operands[1].isreg)
7227 inst.operands[1].reg = REG_PC;
b99bd4ef 7228
c19d1205
ZW
7229 msb = inst.operands[2].imm + inst.operands[3].imm;
7230 constraint (msb > 32, _("bit-field extends past end of register"));
7231 /* The instruction encoding stores the LSB and MSB,
7232 not the LSB and width. */
7233 inst.instruction |= inst.operands[0].reg << 12;
7234 inst.instruction |= inst.operands[1].reg;
7235 inst.instruction |= inst.operands[2].imm << 7;
7236 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7237}
7238
b99bd4ef 7239static void
c19d1205 7240do_bfx (void)
b99bd4ef 7241{
c19d1205
ZW
7242 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7243 _("bit-field extends past end of register"));
7244 inst.instruction |= inst.operands[0].reg << 12;
7245 inst.instruction |= inst.operands[1].reg;
7246 inst.instruction |= inst.operands[2].imm << 7;
7247 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7248}
09d92015 7249
c19d1205
ZW
7250/* ARM V5 breakpoint instruction (argument parse)
7251 BKPT <16 bit unsigned immediate>
7252 Instruction is not conditional.
7253 The bit pattern given in insns[] has the COND_ALWAYS condition,
7254 and it is an error if the caller tried to override that. */
b99bd4ef 7255
c19d1205
ZW
7256static void
7257do_bkpt (void)
7258{
7259 /* Top 12 of 16 bits to bits 19:8. */
7260 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7261
c19d1205
ZW
7262 /* Bottom 4 of 16 bits to bits 3:0. */
7263 inst.instruction |= inst.operands[0].imm & 0xf;
7264}
09d92015 7265
c19d1205
ZW
7266static void
7267encode_branch (int default_reloc)
7268{
7269 if (inst.operands[0].hasreloc)
7270 {
7271 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
7272 _("the only suffix valid here is '(plt)'"));
267bf995 7273 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 7274 }
b99bd4ef 7275 else
c19d1205 7276 {
21d799b5 7277 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
c19d1205 7278 }
2fc8bdac 7279 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7280}
7281
b99bd4ef 7282static void
c19d1205 7283do_branch (void)
b99bd4ef 7284{
39b41c9c
PB
7285#ifdef OBJ_ELF
7286 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7287 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7288 else
7289#endif
7290 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7291}
7292
7293static void
7294do_bl (void)
7295{
7296#ifdef OBJ_ELF
7297 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7298 {
7299 if (inst.cond == COND_ALWAYS)
7300 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7301 else
7302 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7303 }
7304 else
7305#endif
7306 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7307}
b99bd4ef 7308
c19d1205
ZW
7309/* ARM V5 branch-link-exchange instruction (argument parse)
7310 BLX <target_addr> ie BLX(1)
7311 BLX{<condition>} <Rm> ie BLX(2)
7312 Unfortunately, there are two different opcodes for this mnemonic.
7313 So, the insns[].value is not used, and the code here zaps values
7314 into inst.instruction.
7315 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7316
c19d1205
ZW
7317static void
7318do_blx (void)
7319{
7320 if (inst.operands[0].isreg)
b99bd4ef 7321 {
c19d1205
ZW
7322 /* Arg is a register; the opcode provided by insns[] is correct.
7323 It is not illegal to do "blx pc", just useless. */
7324 if (inst.operands[0].reg == REG_PC)
7325 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7326
c19d1205
ZW
7327 inst.instruction |= inst.operands[0].reg;
7328 }
7329 else
b99bd4ef 7330 {
c19d1205 7331 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7332 conditionally, and the opcode must be adjusted.
7333 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7334 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7335 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7336 inst.instruction = 0xfa000000;
267bf995 7337 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7338 }
c19d1205
ZW
7339}
7340
7341static void
7342do_bx (void)
7343{
845b51d6
PB
7344 bfd_boolean want_reloc;
7345
c19d1205
ZW
7346 if (inst.operands[0].reg == REG_PC)
7347 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7348
c19d1205 7349 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7350 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7351 it is for ARMv4t or earlier. */
7352 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7353 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7354 want_reloc = TRUE;
7355
5ad34203 7356#ifdef OBJ_ELF
845b51d6 7357 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7358#endif
584206db 7359 want_reloc = FALSE;
845b51d6
PB
7360
7361 if (want_reloc)
7362 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7363}
7364
c19d1205
ZW
7365
7366/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7367
7368static void
c19d1205 7369do_bxj (void)
a737bd4d 7370{
c19d1205
ZW
7371 if (inst.operands[0].reg == REG_PC)
7372 as_tsktsk (_("use of r15 in bxj is not really useful"));
7373
7374 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7375}
7376
c19d1205
ZW
7377/* Co-processor data operation:
7378 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7379 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7380static void
7381do_cdp (void)
7382{
7383 inst.instruction |= inst.operands[0].reg << 8;
7384 inst.instruction |= inst.operands[1].imm << 20;
7385 inst.instruction |= inst.operands[2].reg << 12;
7386 inst.instruction |= inst.operands[3].reg << 16;
7387 inst.instruction |= inst.operands[4].reg;
7388 inst.instruction |= inst.operands[5].imm << 5;
7389}
a737bd4d
NC
7390
7391static void
c19d1205 7392do_cmp (void)
a737bd4d 7393{
c19d1205
ZW
7394 inst.instruction |= inst.operands[0].reg << 16;
7395 encode_arm_shifter_operand (1);
a737bd4d
NC
7396}
7397
c19d1205
ZW
7398/* Transfer between coprocessor and ARM registers.
7399 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7400 MRC2
7401 MCR{cond}
7402 MCR2
7403
7404 No special properties. */
09d92015
MM
7405
7406static void
c19d1205 7407do_co_reg (void)
09d92015 7408{
fdfde340
JM
7409 unsigned Rd;
7410
7411 Rd = inst.operands[2].reg;
7412 if (thumb_mode)
7413 {
7414 if (inst.instruction == 0xee000010
7415 || inst.instruction == 0xfe000010)
7416 /* MCR, MCR2 */
7417 reject_bad_reg (Rd);
7418 else
7419 /* MRC, MRC2 */
7420 constraint (Rd == REG_SP, BAD_SP);
7421 }
7422 else
7423 {
7424 /* MCR */
7425 if (inst.instruction == 0xe000010)
7426 constraint (Rd == REG_PC, BAD_PC);
7427 }
7428
7429
c19d1205
ZW
7430 inst.instruction |= inst.operands[0].reg << 8;
7431 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7432 inst.instruction |= Rd << 12;
c19d1205
ZW
7433 inst.instruction |= inst.operands[3].reg << 16;
7434 inst.instruction |= inst.operands[4].reg;
7435 inst.instruction |= inst.operands[5].imm << 5;
7436}
09d92015 7437
c19d1205
ZW
7438/* Transfer between coprocessor register and pair of ARM registers.
7439 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7440 MCRR2
7441 MRRC{cond}
7442 MRRC2
b99bd4ef 7443
c19d1205 7444 Two XScale instructions are special cases of these:
09d92015 7445
c19d1205
ZW
7446 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7447 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7448
5f4273c7 7449 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7450
c19d1205
ZW
7451static void
7452do_co_reg2c (void)
7453{
fdfde340
JM
7454 unsigned Rd, Rn;
7455
7456 Rd = inst.operands[2].reg;
7457 Rn = inst.operands[3].reg;
7458
7459 if (thumb_mode)
7460 {
7461 reject_bad_reg (Rd);
7462 reject_bad_reg (Rn);
7463 }
7464 else
7465 {
7466 constraint (Rd == REG_PC, BAD_PC);
7467 constraint (Rn == REG_PC, BAD_PC);
7468 }
7469
c19d1205
ZW
7470 inst.instruction |= inst.operands[0].reg << 8;
7471 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7472 inst.instruction |= Rd << 12;
7473 inst.instruction |= Rn << 16;
c19d1205 7474 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7475}
7476
c19d1205
ZW
7477static void
7478do_cpsi (void)
7479{
7480 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7481 if (inst.operands[1].present)
7482 {
7483 inst.instruction |= CPSI_MMOD;
7484 inst.instruction |= inst.operands[1].imm;
7485 }
c19d1205 7486}
b99bd4ef 7487
62b3e311
PB
7488static void
7489do_dbg (void)
7490{
7491 inst.instruction |= inst.operands[0].imm;
7492}
7493
b99bd4ef 7494static void
c19d1205 7495do_it (void)
b99bd4ef 7496{
c19d1205 7497 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7498 process it to do the validation as if in
7499 thumb mode, just in case the code gets
7500 assembled for thumb using the unified syntax. */
7501
c19d1205 7502 inst.size = 0;
e07e6e58
NC
7503 if (unified_syntax)
7504 {
7505 set_it_insn_type (IT_INSN);
7506 now_it.mask = (inst.instruction & 0xf) | 0x10;
7507 now_it.cc = inst.operands[0].imm;
7508 }
09d92015 7509}
b99bd4ef 7510
09d92015 7511static void
c19d1205 7512do_ldmstm (void)
ea6ef066 7513{
c19d1205
ZW
7514 int base_reg = inst.operands[0].reg;
7515 int range = inst.operands[1].imm;
ea6ef066 7516
c19d1205
ZW
7517 inst.instruction |= base_reg << 16;
7518 inst.instruction |= range;
ea6ef066 7519
c19d1205
ZW
7520 if (inst.operands[1].writeback)
7521 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7522
c19d1205 7523 if (inst.operands[0].writeback)
ea6ef066 7524 {
c19d1205
ZW
7525 inst.instruction |= WRITE_BACK;
7526 /* Check for unpredictable uses of writeback. */
7527 if (inst.instruction & LOAD_BIT)
09d92015 7528 {
c19d1205
ZW
7529 /* Not allowed in LDM type 2. */
7530 if ((inst.instruction & LDM_TYPE_2_OR_3)
7531 && ((range & (1 << REG_PC)) == 0))
7532 as_warn (_("writeback of base register is UNPREDICTABLE"));
7533 /* Only allowed if base reg not in list for other types. */
7534 else if (range & (1 << base_reg))
7535 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7536 }
7537 else /* STM. */
7538 {
7539 /* Not allowed for type 2. */
7540 if (inst.instruction & LDM_TYPE_2_OR_3)
7541 as_warn (_("writeback of base register is UNPREDICTABLE"));
7542 /* Only allowed if base reg not in list, or first in list. */
7543 else if ((range & (1 << base_reg))
7544 && (range & ((1 << base_reg) - 1)))
7545 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7546 }
ea6ef066 7547 }
a737bd4d
NC
7548}
7549
c19d1205
ZW
7550/* ARMv5TE load-consecutive (argument parse)
7551 Mode is like LDRH.
7552
7553 LDRccD R, mode
7554 STRccD R, mode. */
7555
a737bd4d 7556static void
c19d1205 7557do_ldrd (void)
a737bd4d 7558{
c19d1205
ZW
7559 constraint (inst.operands[0].reg % 2 != 0,
7560 _("first destination register must be even"));
7561 constraint (inst.operands[1].present
7562 && inst.operands[1].reg != inst.operands[0].reg + 1,
7563 _("can only load two consecutive registers"));
7564 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7565 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7566
c19d1205
ZW
7567 if (!inst.operands[1].present)
7568 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7569
c19d1205 7570 if (inst.instruction & LOAD_BIT)
a737bd4d 7571 {
c19d1205
ZW
7572 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7573 register and the first register written; we have to diagnose
7574 overlap between the base and the second register written here. */
ea6ef066 7575
c19d1205
ZW
7576 if (inst.operands[2].reg == inst.operands[1].reg
7577 && (inst.operands[2].writeback || inst.operands[2].postind))
7578 as_warn (_("base register written back, and overlaps "
7579 "second destination register"));
b05fe5cf 7580
c19d1205
ZW
7581 /* For an index-register load, the index register must not overlap the
7582 destination (even if not write-back). */
7583 else if (inst.operands[2].immisreg
ca3f61f7
NC
7584 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7585 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 7586 as_warn (_("index register overlaps destination register"));
b05fe5cf 7587 }
c19d1205
ZW
7588
7589 inst.instruction |= inst.operands[0].reg << 12;
7590 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7591}
7592
7593static void
c19d1205 7594do_ldrex (void)
b05fe5cf 7595{
c19d1205
ZW
7596 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7597 || inst.operands[1].postind || inst.operands[1].writeback
7598 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7599 || inst.operands[1].negative
7600 /* This can arise if the programmer has written
7601 strex rN, rM, foo
7602 or if they have mistakenly used a register name as the last
7603 operand, eg:
7604 strex rN, rM, rX
7605 It is very difficult to distinguish between these two cases
7606 because "rX" might actually be a label. ie the register
7607 name has been occluded by a symbol of the same name. So we
7608 just generate a general 'bad addressing mode' type error
7609 message and leave it up to the programmer to discover the
7610 true cause and fix their mistake. */
7611 || (inst.operands[1].reg == REG_PC),
7612 BAD_ADDR_MODE);
b05fe5cf 7613
c19d1205
ZW
7614 constraint (inst.reloc.exp.X_op != O_constant
7615 || inst.reloc.exp.X_add_number != 0,
7616 _("offset must be zero in ARM encoding"));
b05fe5cf 7617
5be8be5d
DG
7618 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7619
c19d1205
ZW
7620 inst.instruction |= inst.operands[0].reg << 12;
7621 inst.instruction |= inst.operands[1].reg << 16;
7622 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7623}
7624
7625static void
c19d1205 7626do_ldrexd (void)
b05fe5cf 7627{
c19d1205
ZW
7628 constraint (inst.operands[0].reg % 2 != 0,
7629 _("even register required"));
7630 constraint (inst.operands[1].present
7631 && inst.operands[1].reg != inst.operands[0].reg + 1,
7632 _("can only load two consecutive registers"));
7633 /* If op 1 were present and equal to PC, this function wouldn't
7634 have been called in the first place. */
7635 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7636
c19d1205
ZW
7637 inst.instruction |= inst.operands[0].reg << 12;
7638 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7639}
7640
7641static void
c19d1205 7642do_ldst (void)
b05fe5cf 7643{
c19d1205
ZW
7644 inst.instruction |= inst.operands[0].reg << 12;
7645 if (!inst.operands[1].isreg)
7646 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7647 return;
c19d1205 7648 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7649}
7650
7651static void
c19d1205 7652do_ldstt (void)
b05fe5cf 7653{
c19d1205
ZW
7654 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7655 reject [Rn,...]. */
7656 if (inst.operands[1].preind)
b05fe5cf 7657 {
bd3ba5d1
NC
7658 constraint (inst.reloc.exp.X_op != O_constant
7659 || inst.reloc.exp.X_add_number != 0,
c19d1205 7660 _("this instruction requires a post-indexed address"));
b05fe5cf 7661
c19d1205
ZW
7662 inst.operands[1].preind = 0;
7663 inst.operands[1].postind = 1;
7664 inst.operands[1].writeback = 1;
b05fe5cf 7665 }
c19d1205
ZW
7666 inst.instruction |= inst.operands[0].reg << 12;
7667 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7668}
b05fe5cf 7669
c19d1205 7670/* Halfword and signed-byte load/store operations. */
b05fe5cf 7671
c19d1205
ZW
7672static void
7673do_ldstv4 (void)
7674{
ff4a8d2b 7675 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7676 inst.instruction |= inst.operands[0].reg << 12;
7677 if (!inst.operands[1].isreg)
7678 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7679 return;
c19d1205 7680 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7681}
7682
7683static void
c19d1205 7684do_ldsttv4 (void)
b05fe5cf 7685{
c19d1205
ZW
7686 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7687 reject [Rn,...]. */
7688 if (inst.operands[1].preind)
b05fe5cf 7689 {
bd3ba5d1
NC
7690 constraint (inst.reloc.exp.X_op != O_constant
7691 || inst.reloc.exp.X_add_number != 0,
c19d1205 7692 _("this instruction requires a post-indexed address"));
b05fe5cf 7693
c19d1205
ZW
7694 inst.operands[1].preind = 0;
7695 inst.operands[1].postind = 1;
7696 inst.operands[1].writeback = 1;
b05fe5cf 7697 }
c19d1205
ZW
7698 inst.instruction |= inst.operands[0].reg << 12;
7699 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7700}
b05fe5cf 7701
c19d1205
ZW
7702/* Co-processor register load/store.
7703 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7704static void
7705do_lstc (void)
7706{
7707 inst.instruction |= inst.operands[0].reg << 8;
7708 inst.instruction |= inst.operands[1].reg << 12;
7709 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7710}
7711
b05fe5cf 7712static void
c19d1205 7713do_mlas (void)
b05fe5cf 7714{
8fb9d7b9 7715 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7716 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7717 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7718 && !(inst.instruction & 0x00400000))
8fb9d7b9 7719 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7720
c19d1205
ZW
7721 inst.instruction |= inst.operands[0].reg << 16;
7722 inst.instruction |= inst.operands[1].reg;
7723 inst.instruction |= inst.operands[2].reg << 8;
7724 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7725}
b05fe5cf 7726
c19d1205
ZW
7727static void
7728do_mov (void)
7729{
7730 inst.instruction |= inst.operands[0].reg << 12;
7731 encode_arm_shifter_operand (1);
7732}
b05fe5cf 7733
c19d1205
ZW
7734/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7735static void
7736do_mov16 (void)
7737{
b6895b4f
PB
7738 bfd_vma imm;
7739 bfd_boolean top;
7740
7741 top = (inst.instruction & 0x00400000) != 0;
7742 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7743 _(":lower16: not allowed this instruction"));
7744 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7745 _(":upper16: not allowed instruction"));
c19d1205 7746 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7747 if (inst.reloc.type == BFD_RELOC_UNUSED)
7748 {
7749 imm = inst.reloc.exp.X_add_number;
7750 /* The value is in two pieces: 0:11, 16:19. */
7751 inst.instruction |= (imm & 0x00000fff);
7752 inst.instruction |= (imm & 0x0000f000) << 4;
7753 }
b05fe5cf 7754}
b99bd4ef 7755
037e8744
JB
7756static void do_vfp_nsyn_opcode (const char *);
7757
7758static int
7759do_vfp_nsyn_mrs (void)
7760{
7761 if (inst.operands[0].isvec)
7762 {
7763 if (inst.operands[1].reg != 1)
7764 first_error (_("operand 1 must be FPSCR"));
7765 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7766 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7767 do_vfp_nsyn_opcode ("fmstat");
7768 }
7769 else if (inst.operands[1].isvec)
7770 do_vfp_nsyn_opcode ("fmrx");
7771 else
7772 return FAIL;
5f4273c7 7773
037e8744
JB
7774 return SUCCESS;
7775}
7776
7777static int
7778do_vfp_nsyn_msr (void)
7779{
7780 if (inst.operands[0].isvec)
7781 do_vfp_nsyn_opcode ("fmxr");
7782 else
7783 return FAIL;
7784
7785 return SUCCESS;
7786}
7787
f7c21dc7
NC
7788static void
7789do_vmrs (void)
7790{
7791 unsigned Rt = inst.operands[0].reg;
7792
7793 if (thumb_mode && inst.operands[0].reg == REG_SP)
7794 {
7795 inst.error = BAD_SP;
7796 return;
7797 }
7798
7799 /* APSR_ sets isvec. All other refs to PC are illegal. */
7800 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
7801 {
7802 inst.error = BAD_PC;
7803 return;
7804 }
7805
7806 if (inst.operands[1].reg != 1)
7807 first_error (_("operand 1 must be FPSCR"));
7808
7809 inst.instruction |= (Rt << 12);
7810}
7811
7812static void
7813do_vmsr (void)
7814{
7815 unsigned Rt = inst.operands[1].reg;
7816
7817 if (thumb_mode)
7818 reject_bad_reg (Rt);
7819 else if (Rt == REG_PC)
7820 {
7821 inst.error = BAD_PC;
7822 return;
7823 }
7824
7825 if (inst.operands[0].reg != 1)
7826 first_error (_("operand 0 must be FPSCR"));
7827
7828 inst.instruction |= (Rt << 12);
7829}
7830
b99bd4ef 7831static void
c19d1205 7832do_mrs (void)
b99bd4ef 7833{
037e8744
JB
7834 if (do_vfp_nsyn_mrs () == SUCCESS)
7835 return;
7836
c19d1205
ZW
7837 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7838 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7839 != (PSR_c|PSR_f),
7840 _("'CPSR' or 'SPSR' expected"));
ff4a8d2b 7841 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7842 inst.instruction |= inst.operands[0].reg << 12;
7843 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7844}
b99bd4ef 7845
c19d1205
ZW
7846/* Two possible forms:
7847 "{C|S}PSR_<field>, Rm",
7848 "{C|S}PSR_f, #expression". */
b99bd4ef 7849
c19d1205
ZW
7850static void
7851do_msr (void)
7852{
037e8744
JB
7853 if (do_vfp_nsyn_msr () == SUCCESS)
7854 return;
7855
c19d1205
ZW
7856 inst.instruction |= inst.operands[0].imm;
7857 if (inst.operands[1].isreg)
7858 inst.instruction |= inst.operands[1].reg;
7859 else
b99bd4ef 7860 {
c19d1205
ZW
7861 inst.instruction |= INST_IMMEDIATE;
7862 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7863 inst.reloc.pc_rel = 0;
b99bd4ef 7864 }
b99bd4ef
NC
7865}
7866
c19d1205
ZW
7867static void
7868do_mul (void)
a737bd4d 7869{
ff4a8d2b
NC
7870 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
7871
c19d1205
ZW
7872 if (!inst.operands[2].present)
7873 inst.operands[2].reg = inst.operands[0].reg;
7874 inst.instruction |= inst.operands[0].reg << 16;
7875 inst.instruction |= inst.operands[1].reg;
7876 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7877
8fb9d7b9
MS
7878 if (inst.operands[0].reg == inst.operands[1].reg
7879 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7880 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7881}
7882
c19d1205
ZW
7883/* Long Multiply Parser
7884 UMULL RdLo, RdHi, Rm, Rs
7885 SMULL RdLo, RdHi, Rm, Rs
7886 UMLAL RdLo, RdHi, Rm, Rs
7887 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7888
7889static void
c19d1205 7890do_mull (void)
b99bd4ef 7891{
c19d1205
ZW
7892 inst.instruction |= inst.operands[0].reg << 12;
7893 inst.instruction |= inst.operands[1].reg << 16;
7894 inst.instruction |= inst.operands[2].reg;
7895 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7896
682b27ad
PB
7897 /* rdhi and rdlo must be different. */
7898 if (inst.operands[0].reg == inst.operands[1].reg)
7899 as_tsktsk (_("rdhi and rdlo must be different"));
7900
7901 /* rdhi, rdlo and rm must all be different before armv6. */
7902 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7903 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7904 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7905 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7906}
b99bd4ef 7907
c19d1205
ZW
7908static void
7909do_nop (void)
7910{
e7495e45
NS
7911 if (inst.operands[0].present
7912 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
7913 {
7914 /* Architectural NOP hints are CPSR sets with no bits selected. */
7915 inst.instruction &= 0xf0000000;
e7495e45
NS
7916 inst.instruction |= 0x0320f000;
7917 if (inst.operands[0].present)
7918 inst.instruction |= inst.operands[0].imm;
c19d1205 7919 }
b99bd4ef
NC
7920}
7921
c19d1205
ZW
7922/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7923 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7924 Condition defaults to COND_ALWAYS.
7925 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7926
7927static void
c19d1205 7928do_pkhbt (void)
b99bd4ef 7929{
c19d1205
ZW
7930 inst.instruction |= inst.operands[0].reg << 12;
7931 inst.instruction |= inst.operands[1].reg << 16;
7932 inst.instruction |= inst.operands[2].reg;
7933 if (inst.operands[3].present)
7934 encode_arm_shift (3);
7935}
b99bd4ef 7936
c19d1205 7937/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7938
c19d1205
ZW
7939static void
7940do_pkhtb (void)
7941{
7942 if (!inst.operands[3].present)
b99bd4ef 7943 {
c19d1205
ZW
7944 /* If the shift specifier is omitted, turn the instruction
7945 into pkhbt rd, rm, rn. */
7946 inst.instruction &= 0xfff00010;
7947 inst.instruction |= inst.operands[0].reg << 12;
7948 inst.instruction |= inst.operands[1].reg;
7949 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7950 }
7951 else
7952 {
c19d1205
ZW
7953 inst.instruction |= inst.operands[0].reg << 12;
7954 inst.instruction |= inst.operands[1].reg << 16;
7955 inst.instruction |= inst.operands[2].reg;
7956 encode_arm_shift (3);
b99bd4ef
NC
7957 }
7958}
7959
c19d1205 7960/* ARMv5TE: Preload-Cache
60e5ef9f 7961 MP Extensions: Preload for write
c19d1205 7962
60e5ef9f 7963 PLD(W) <addr_mode>
c19d1205
ZW
7964
7965 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7966
7967static void
c19d1205 7968do_pld (void)
b99bd4ef 7969{
c19d1205
ZW
7970 constraint (!inst.operands[0].isreg,
7971 _("'[' expected after PLD mnemonic"));
7972 constraint (inst.operands[0].postind,
7973 _("post-indexed expression used in preload instruction"));
7974 constraint (inst.operands[0].writeback,
7975 _("writeback used in preload instruction"));
7976 constraint (!inst.operands[0].preind,
7977 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7978 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7979}
b99bd4ef 7980
62b3e311
PB
7981/* ARMv7: PLI <addr_mode> */
7982static void
7983do_pli (void)
7984{
7985 constraint (!inst.operands[0].isreg,
7986 _("'[' expected after PLI mnemonic"));
7987 constraint (inst.operands[0].postind,
7988 _("post-indexed expression used in preload instruction"));
7989 constraint (inst.operands[0].writeback,
7990 _("writeback used in preload instruction"));
7991 constraint (!inst.operands[0].preind,
7992 _("unindexed addressing used in preload instruction"));
7993 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7994 inst.instruction &= ~PRE_INDEX;
7995}
7996
c19d1205
ZW
7997static void
7998do_push_pop (void)
7999{
8000 inst.operands[1] = inst.operands[0];
8001 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8002 inst.operands[0].isreg = 1;
8003 inst.operands[0].writeback = 1;
8004 inst.operands[0].reg = REG_SP;
8005 do_ldmstm ();
8006}
b99bd4ef 8007
c19d1205
ZW
8008/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8009 word at the specified address and the following word
8010 respectively.
8011 Unconditionally executed.
8012 Error if Rn is R15. */
b99bd4ef 8013
c19d1205
ZW
8014static void
8015do_rfe (void)
8016{
8017 inst.instruction |= inst.operands[0].reg << 16;
8018 if (inst.operands[0].writeback)
8019 inst.instruction |= WRITE_BACK;
8020}
b99bd4ef 8021
c19d1205 8022/* ARM V6 ssat (argument parse). */
b99bd4ef 8023
c19d1205
ZW
8024static void
8025do_ssat (void)
8026{
8027 inst.instruction |= inst.operands[0].reg << 12;
8028 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8029 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8030
c19d1205
ZW
8031 if (inst.operands[3].present)
8032 encode_arm_shift (3);
b99bd4ef
NC
8033}
8034
c19d1205 8035/* ARM V6 usat (argument parse). */
b99bd4ef
NC
8036
8037static void
c19d1205 8038do_usat (void)
b99bd4ef 8039{
c19d1205
ZW
8040 inst.instruction |= inst.operands[0].reg << 12;
8041 inst.instruction |= inst.operands[1].imm << 16;
8042 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8043
c19d1205
ZW
8044 if (inst.operands[3].present)
8045 encode_arm_shift (3);
b99bd4ef
NC
8046}
8047
c19d1205 8048/* ARM V6 ssat16 (argument parse). */
09d92015
MM
8049
8050static void
c19d1205 8051do_ssat16 (void)
09d92015 8052{
c19d1205
ZW
8053 inst.instruction |= inst.operands[0].reg << 12;
8054 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8055 inst.instruction |= inst.operands[2].reg;
09d92015
MM
8056}
8057
c19d1205
ZW
8058static void
8059do_usat16 (void)
a737bd4d 8060{
c19d1205
ZW
8061 inst.instruction |= inst.operands[0].reg << 12;
8062 inst.instruction |= inst.operands[1].imm << 16;
8063 inst.instruction |= inst.operands[2].reg;
8064}
a737bd4d 8065
c19d1205
ZW
8066/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8067 preserving the other bits.
a737bd4d 8068
c19d1205
ZW
8069 setend <endian_specifier>, where <endian_specifier> is either
8070 BE or LE. */
a737bd4d 8071
c19d1205
ZW
8072static void
8073do_setend (void)
8074{
8075 if (inst.operands[0].imm)
8076 inst.instruction |= 0x200;
a737bd4d
NC
8077}
8078
8079static void
c19d1205 8080do_shift (void)
a737bd4d 8081{
c19d1205
ZW
8082 unsigned int Rm = (inst.operands[1].present
8083 ? inst.operands[1].reg
8084 : inst.operands[0].reg);
a737bd4d 8085
c19d1205
ZW
8086 inst.instruction |= inst.operands[0].reg << 12;
8087 inst.instruction |= Rm;
8088 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 8089 {
c19d1205
ZW
8090 inst.instruction |= inst.operands[2].reg << 8;
8091 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
8092 }
8093 else
c19d1205 8094 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
8095}
8096
09d92015 8097static void
3eb17e6b 8098do_smc (void)
09d92015 8099{
3eb17e6b 8100 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 8101 inst.reloc.pc_rel = 0;
09d92015
MM
8102}
8103
09d92015 8104static void
c19d1205 8105do_swi (void)
09d92015 8106{
c19d1205
ZW
8107 inst.reloc.type = BFD_RELOC_ARM_SWI;
8108 inst.reloc.pc_rel = 0;
09d92015
MM
8109}
8110
c19d1205
ZW
8111/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8112 SMLAxy{cond} Rd,Rm,Rs,Rn
8113 SMLAWy{cond} Rd,Rm,Rs,Rn
8114 Error if any register is R15. */
e16bb312 8115
c19d1205
ZW
8116static void
8117do_smla (void)
e16bb312 8118{
c19d1205
ZW
8119 inst.instruction |= inst.operands[0].reg << 16;
8120 inst.instruction |= inst.operands[1].reg;
8121 inst.instruction |= inst.operands[2].reg << 8;
8122 inst.instruction |= inst.operands[3].reg << 12;
8123}
a737bd4d 8124
c19d1205
ZW
8125/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8126 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8127 Error if any register is R15.
8128 Warning if Rdlo == Rdhi. */
a737bd4d 8129
c19d1205
ZW
8130static void
8131do_smlal (void)
8132{
8133 inst.instruction |= inst.operands[0].reg << 12;
8134 inst.instruction |= inst.operands[1].reg << 16;
8135 inst.instruction |= inst.operands[2].reg;
8136 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 8137
c19d1205
ZW
8138 if (inst.operands[0].reg == inst.operands[1].reg)
8139 as_tsktsk (_("rdhi and rdlo must be different"));
8140}
a737bd4d 8141
c19d1205
ZW
8142/* ARM V5E (El Segundo) signed-multiply (argument parse)
8143 SMULxy{cond} Rd,Rm,Rs
8144 Error if any register is R15. */
a737bd4d 8145
c19d1205
ZW
8146static void
8147do_smul (void)
8148{
8149 inst.instruction |= inst.operands[0].reg << 16;
8150 inst.instruction |= inst.operands[1].reg;
8151 inst.instruction |= inst.operands[2].reg << 8;
8152}
a737bd4d 8153
b6702015
PB
8154/* ARM V6 srs (argument parse). The variable fields in the encoding are
8155 the same for both ARM and Thumb-2. */
a737bd4d 8156
c19d1205
ZW
8157static void
8158do_srs (void)
8159{
b6702015
PB
8160 int reg;
8161
8162 if (inst.operands[0].present)
8163 {
8164 reg = inst.operands[0].reg;
fdfde340 8165 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
8166 }
8167 else
fdfde340 8168 reg = REG_SP;
b6702015
PB
8169
8170 inst.instruction |= reg << 16;
8171 inst.instruction |= inst.operands[1].imm;
8172 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
8173 inst.instruction |= WRITE_BACK;
8174}
a737bd4d 8175
c19d1205 8176/* ARM V6 strex (argument parse). */
a737bd4d 8177
c19d1205
ZW
8178static void
8179do_strex (void)
8180{
8181 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8182 || inst.operands[2].postind || inst.operands[2].writeback
8183 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
8184 || inst.operands[2].negative
8185 /* See comment in do_ldrex(). */
8186 || (inst.operands[2].reg == REG_PC),
8187 BAD_ADDR_MODE);
a737bd4d 8188
c19d1205
ZW
8189 constraint (inst.operands[0].reg == inst.operands[1].reg
8190 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 8191
c19d1205
ZW
8192 constraint (inst.reloc.exp.X_op != O_constant
8193 || inst.reloc.exp.X_add_number != 0,
8194 _("offset must be zero in ARM encoding"));
a737bd4d 8195
c19d1205
ZW
8196 inst.instruction |= inst.operands[0].reg << 12;
8197 inst.instruction |= inst.operands[1].reg;
8198 inst.instruction |= inst.operands[2].reg << 16;
8199 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8200}
8201
8202static void
c19d1205 8203do_strexd (void)
e16bb312 8204{
c19d1205
ZW
8205 constraint (inst.operands[1].reg % 2 != 0,
8206 _("even register required"));
8207 constraint (inst.operands[2].present
8208 && inst.operands[2].reg != inst.operands[1].reg + 1,
8209 _("can only store two consecutive registers"));
8210 /* If op 2 were present and equal to PC, this function wouldn't
8211 have been called in the first place. */
8212 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8213
c19d1205
ZW
8214 constraint (inst.operands[0].reg == inst.operands[1].reg
8215 || inst.operands[0].reg == inst.operands[1].reg + 1
8216 || inst.operands[0].reg == inst.operands[3].reg,
8217 BAD_OVERLAP);
e16bb312 8218
c19d1205
ZW
8219 inst.instruction |= inst.operands[0].reg << 12;
8220 inst.instruction |= inst.operands[1].reg;
8221 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8222}
8223
c19d1205
ZW
8224/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8225 extends it to 32-bits, and adds the result to a value in another
8226 register. You can specify a rotation by 0, 8, 16, or 24 bits
8227 before extracting the 16-bit value.
8228 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8229 Condition defaults to COND_ALWAYS.
8230 Error if any register uses R15. */
8231
e16bb312 8232static void
c19d1205 8233do_sxtah (void)
e16bb312 8234{
c19d1205
ZW
8235 inst.instruction |= inst.operands[0].reg << 12;
8236 inst.instruction |= inst.operands[1].reg << 16;
8237 inst.instruction |= inst.operands[2].reg;
8238 inst.instruction |= inst.operands[3].imm << 10;
8239}
e16bb312 8240
c19d1205 8241/* ARM V6 SXTH.
e16bb312 8242
c19d1205
ZW
8243 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8244 Condition defaults to COND_ALWAYS.
8245 Error if any register uses R15. */
e16bb312
NC
8246
8247static void
c19d1205 8248do_sxth (void)
e16bb312 8249{
c19d1205
ZW
8250 inst.instruction |= inst.operands[0].reg << 12;
8251 inst.instruction |= inst.operands[1].reg;
8252 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8253}
c19d1205
ZW
8254\f
8255/* VFP instructions. In a logical order: SP variant first, monad
8256 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8257
8258static void
c19d1205 8259do_vfp_sp_monadic (void)
e16bb312 8260{
5287ad62
JB
8261 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8262 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8263}
8264
8265static void
c19d1205 8266do_vfp_sp_dyadic (void)
e16bb312 8267{
5287ad62
JB
8268 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8269 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8270 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8271}
8272
8273static void
c19d1205 8274do_vfp_sp_compare_z (void)
e16bb312 8275{
5287ad62 8276 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8277}
8278
8279static void
c19d1205 8280do_vfp_dp_sp_cvt (void)
e16bb312 8281{
5287ad62
JB
8282 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8283 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8284}
8285
8286static void
c19d1205 8287do_vfp_sp_dp_cvt (void)
e16bb312 8288{
5287ad62
JB
8289 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8290 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8291}
8292
8293static void
c19d1205 8294do_vfp_reg_from_sp (void)
e16bb312 8295{
c19d1205 8296 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8297 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8298}
8299
8300static void
c19d1205 8301do_vfp_reg2_from_sp2 (void)
e16bb312 8302{
c19d1205
ZW
8303 constraint (inst.operands[2].imm != 2,
8304 _("only two consecutive VFP SP registers allowed here"));
8305 inst.instruction |= inst.operands[0].reg << 12;
8306 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8307 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8308}
8309
8310static void
c19d1205 8311do_vfp_sp_from_reg (void)
e16bb312 8312{
5287ad62 8313 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8314 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8315}
8316
8317static void
c19d1205 8318do_vfp_sp2_from_reg2 (void)
e16bb312 8319{
c19d1205
ZW
8320 constraint (inst.operands[0].imm != 2,
8321 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8322 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8323 inst.instruction |= inst.operands[1].reg << 12;
8324 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8325}
8326
8327static void
c19d1205 8328do_vfp_sp_ldst (void)
e16bb312 8329{
5287ad62 8330 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 8331 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8332}
8333
8334static void
c19d1205 8335do_vfp_dp_ldst (void)
e16bb312 8336{
5287ad62 8337 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 8338 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8339}
8340
c19d1205 8341
e16bb312 8342static void
c19d1205 8343vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8344{
c19d1205
ZW
8345 if (inst.operands[0].writeback)
8346 inst.instruction |= WRITE_BACK;
8347 else
8348 constraint (ldstm_type != VFP_LDSTMIA,
8349 _("this addressing mode requires base-register writeback"));
8350 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8351 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 8352 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
8353}
8354
8355static void
c19d1205 8356vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8357{
c19d1205 8358 int count;
e16bb312 8359
c19d1205
ZW
8360 if (inst.operands[0].writeback)
8361 inst.instruction |= WRITE_BACK;
8362 else
8363 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8364 _("this addressing mode requires base-register writeback"));
e16bb312 8365
c19d1205 8366 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8367 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 8368
c19d1205
ZW
8369 count = inst.operands[1].imm << 1;
8370 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8371 count += 1;
e16bb312 8372
c19d1205 8373 inst.instruction |= count;
e16bb312
NC
8374}
8375
8376static void
c19d1205 8377do_vfp_sp_ldstmia (void)
e16bb312 8378{
c19d1205 8379 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8380}
8381
8382static void
c19d1205 8383do_vfp_sp_ldstmdb (void)
e16bb312 8384{
c19d1205 8385 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8386}
8387
8388static void
c19d1205 8389do_vfp_dp_ldstmia (void)
e16bb312 8390{
c19d1205 8391 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8392}
8393
8394static void
c19d1205 8395do_vfp_dp_ldstmdb (void)
e16bb312 8396{
c19d1205 8397 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8398}
8399
8400static void
c19d1205 8401do_vfp_xp_ldstmia (void)
e16bb312 8402{
c19d1205
ZW
8403 vfp_dp_ldstm (VFP_LDSTMIAX);
8404}
e16bb312 8405
c19d1205
ZW
8406static void
8407do_vfp_xp_ldstmdb (void)
8408{
8409 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 8410}
5287ad62
JB
8411
8412static void
8413do_vfp_dp_rd_rm (void)
8414{
8415 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8416 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8417}
8418
8419static void
8420do_vfp_dp_rn_rd (void)
8421{
8422 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8423 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8424}
8425
8426static void
8427do_vfp_dp_rd_rn (void)
8428{
8429 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8430 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8431}
8432
8433static void
8434do_vfp_dp_rd_rn_rm (void)
8435{
8436 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8437 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8438 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8439}
8440
8441static void
8442do_vfp_dp_rd (void)
8443{
8444 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8445}
8446
8447static void
8448do_vfp_dp_rm_rd_rn (void)
8449{
8450 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8451 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8452 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8453}
8454
8455/* VFPv3 instructions. */
8456static void
8457do_vfp_sp_const (void)
8458{
8459 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8460 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8461 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8462}
8463
8464static void
8465do_vfp_dp_const (void)
8466{
8467 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8468 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8469 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8470}
8471
8472static void
8473vfp_conv (int srcsize)
8474{
8475 unsigned immbits = srcsize - inst.operands[1].imm;
8476 inst.instruction |= (immbits & 1) << 5;
8477 inst.instruction |= (immbits >> 1);
8478}
8479
8480static void
8481do_vfp_sp_conv_16 (void)
8482{
8483 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8484 vfp_conv (16);
8485}
8486
8487static void
8488do_vfp_dp_conv_16 (void)
8489{
8490 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8491 vfp_conv (16);
8492}
8493
8494static void
8495do_vfp_sp_conv_32 (void)
8496{
8497 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8498 vfp_conv (32);
8499}
8500
8501static void
8502do_vfp_dp_conv_32 (void)
8503{
8504 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8505 vfp_conv (32);
8506}
c19d1205
ZW
8507\f
8508/* FPA instructions. Also in a logical order. */
e16bb312 8509
c19d1205
ZW
8510static void
8511do_fpa_cmp (void)
8512{
8513 inst.instruction |= inst.operands[0].reg << 16;
8514 inst.instruction |= inst.operands[1].reg;
8515}
b99bd4ef
NC
8516
8517static void
c19d1205 8518do_fpa_ldmstm (void)
b99bd4ef 8519{
c19d1205
ZW
8520 inst.instruction |= inst.operands[0].reg << 12;
8521 switch (inst.operands[1].imm)
8522 {
8523 case 1: inst.instruction |= CP_T_X; break;
8524 case 2: inst.instruction |= CP_T_Y; break;
8525 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8526 case 4: break;
8527 default: abort ();
8528 }
b99bd4ef 8529
c19d1205
ZW
8530 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8531 {
8532 /* The instruction specified "ea" or "fd", so we can only accept
8533 [Rn]{!}. The instruction does not really support stacking or
8534 unstacking, so we have to emulate these by setting appropriate
8535 bits and offsets. */
8536 constraint (inst.reloc.exp.X_op != O_constant
8537 || inst.reloc.exp.X_add_number != 0,
8538 _("this instruction does not support indexing"));
b99bd4ef 8539
c19d1205
ZW
8540 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8541 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8542
c19d1205
ZW
8543 if (!(inst.instruction & INDEX_UP))
8544 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8545
c19d1205
ZW
8546 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8547 {
8548 inst.operands[2].preind = 0;
8549 inst.operands[2].postind = 1;
8550 }
8551 }
b99bd4ef 8552
c19d1205 8553 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8554}
c19d1205
ZW
8555\f
8556/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8557
c19d1205
ZW
8558static void
8559do_iwmmxt_tandorc (void)
8560{
8561 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8562}
b99bd4ef 8563
c19d1205
ZW
8564static void
8565do_iwmmxt_textrc (void)
8566{
8567 inst.instruction |= inst.operands[0].reg << 12;
8568 inst.instruction |= inst.operands[1].imm;
8569}
b99bd4ef
NC
8570
8571static void
c19d1205 8572do_iwmmxt_textrm (void)
b99bd4ef 8573{
c19d1205
ZW
8574 inst.instruction |= inst.operands[0].reg << 12;
8575 inst.instruction |= inst.operands[1].reg << 16;
8576 inst.instruction |= inst.operands[2].imm;
8577}
b99bd4ef 8578
c19d1205
ZW
8579static void
8580do_iwmmxt_tinsr (void)
8581{
8582 inst.instruction |= inst.operands[0].reg << 16;
8583 inst.instruction |= inst.operands[1].reg << 12;
8584 inst.instruction |= inst.operands[2].imm;
8585}
b99bd4ef 8586
c19d1205
ZW
8587static void
8588do_iwmmxt_tmia (void)
8589{
8590 inst.instruction |= inst.operands[0].reg << 5;
8591 inst.instruction |= inst.operands[1].reg;
8592 inst.instruction |= inst.operands[2].reg << 12;
8593}
b99bd4ef 8594
c19d1205
ZW
8595static void
8596do_iwmmxt_waligni (void)
8597{
8598 inst.instruction |= inst.operands[0].reg << 12;
8599 inst.instruction |= inst.operands[1].reg << 16;
8600 inst.instruction |= inst.operands[2].reg;
8601 inst.instruction |= inst.operands[3].imm << 20;
8602}
b99bd4ef 8603
2d447fca
JM
8604static void
8605do_iwmmxt_wmerge (void)
8606{
8607 inst.instruction |= inst.operands[0].reg << 12;
8608 inst.instruction |= inst.operands[1].reg << 16;
8609 inst.instruction |= inst.operands[2].reg;
8610 inst.instruction |= inst.operands[3].imm << 21;
8611}
8612
c19d1205
ZW
8613static void
8614do_iwmmxt_wmov (void)
8615{
8616 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8617 inst.instruction |= inst.operands[0].reg << 12;
8618 inst.instruction |= inst.operands[1].reg << 16;
8619 inst.instruction |= inst.operands[1].reg;
8620}
b99bd4ef 8621
c19d1205
ZW
8622static void
8623do_iwmmxt_wldstbh (void)
8624{
8f06b2d8 8625 int reloc;
c19d1205 8626 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8627 if (thumb_mode)
8628 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8629 else
8630 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8631 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8632}
8633
c19d1205
ZW
8634static void
8635do_iwmmxt_wldstw (void)
8636{
8637 /* RIWR_RIWC clears .isreg for a control register. */
8638 if (!inst.operands[0].isreg)
8639 {
8640 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8641 inst.instruction |= 0xf0000000;
8642 }
b99bd4ef 8643
c19d1205
ZW
8644 inst.instruction |= inst.operands[0].reg << 12;
8645 encode_arm_cp_address (1, TRUE, TRUE, 0);
8646}
b99bd4ef
NC
8647
8648static void
c19d1205 8649do_iwmmxt_wldstd (void)
b99bd4ef 8650{
c19d1205 8651 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8652 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8653 && inst.operands[1].immisreg)
8654 {
8655 inst.instruction &= ~0x1a000ff;
8656 inst.instruction |= (0xf << 28);
8657 if (inst.operands[1].preind)
8658 inst.instruction |= PRE_INDEX;
8659 if (!inst.operands[1].negative)
8660 inst.instruction |= INDEX_UP;
8661 if (inst.operands[1].writeback)
8662 inst.instruction |= WRITE_BACK;
8663 inst.instruction |= inst.operands[1].reg << 16;
8664 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8665 inst.instruction |= inst.operands[1].imm;
8666 }
8667 else
8668 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8669}
b99bd4ef 8670
c19d1205
ZW
8671static void
8672do_iwmmxt_wshufh (void)
8673{
8674 inst.instruction |= inst.operands[0].reg << 12;
8675 inst.instruction |= inst.operands[1].reg << 16;
8676 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8677 inst.instruction |= (inst.operands[2].imm & 0x0f);
8678}
b99bd4ef 8679
c19d1205
ZW
8680static void
8681do_iwmmxt_wzero (void)
8682{
8683 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8684 inst.instruction |= inst.operands[0].reg;
8685 inst.instruction |= inst.operands[0].reg << 12;
8686 inst.instruction |= inst.operands[0].reg << 16;
8687}
2d447fca
JM
8688
8689static void
8690do_iwmmxt_wrwrwr_or_imm5 (void)
8691{
8692 if (inst.operands[2].isreg)
8693 do_rd_rn_rm ();
8694 else {
8695 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8696 _("immediate operand requires iWMMXt2"));
8697 do_rd_rn ();
8698 if (inst.operands[2].imm == 0)
8699 {
8700 switch ((inst.instruction >> 20) & 0xf)
8701 {
8702 case 4:
8703 case 5:
8704 case 6:
5f4273c7 8705 case 7:
2d447fca
JM
8706 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8707 inst.operands[2].imm = 16;
8708 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8709 break;
8710 case 8:
8711 case 9:
8712 case 10:
8713 case 11:
8714 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8715 inst.operands[2].imm = 32;
8716 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8717 break;
8718 case 12:
8719 case 13:
8720 case 14:
8721 case 15:
8722 {
8723 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8724 unsigned long wrn;
8725 wrn = (inst.instruction >> 16) & 0xf;
8726 inst.instruction &= 0xff0fff0f;
8727 inst.instruction |= wrn;
8728 /* Bail out here; the instruction is now assembled. */
8729 return;
8730 }
8731 }
8732 }
8733 /* Map 32 -> 0, etc. */
8734 inst.operands[2].imm &= 0x1f;
8735 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8736 }
8737}
c19d1205
ZW
8738\f
8739/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8740 operations first, then control, shift, and load/store. */
b99bd4ef 8741
c19d1205 8742/* Insns like "foo X,Y,Z". */
b99bd4ef 8743
c19d1205
ZW
8744static void
8745do_mav_triple (void)
8746{
8747 inst.instruction |= inst.operands[0].reg << 16;
8748 inst.instruction |= inst.operands[1].reg;
8749 inst.instruction |= inst.operands[2].reg << 12;
8750}
b99bd4ef 8751
c19d1205
ZW
8752/* Insns like "foo W,X,Y,Z".
8753 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8754
c19d1205
ZW
8755static void
8756do_mav_quad (void)
8757{
8758 inst.instruction |= inst.operands[0].reg << 5;
8759 inst.instruction |= inst.operands[1].reg << 12;
8760 inst.instruction |= inst.operands[2].reg << 16;
8761 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8762}
8763
c19d1205
ZW
8764/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8765static void
8766do_mav_dspsc (void)
a737bd4d 8767{
c19d1205
ZW
8768 inst.instruction |= inst.operands[1].reg << 12;
8769}
a737bd4d 8770
c19d1205
ZW
8771/* Maverick shift immediate instructions.
8772 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8773 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8774
c19d1205
ZW
8775static void
8776do_mav_shift (void)
8777{
8778 int imm = inst.operands[2].imm;
a737bd4d 8779
c19d1205
ZW
8780 inst.instruction |= inst.operands[0].reg << 12;
8781 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8782
c19d1205
ZW
8783 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8784 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8785 Bit 4 should be 0. */
8786 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8787
c19d1205
ZW
8788 inst.instruction |= imm;
8789}
8790\f
8791/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8792
c19d1205
ZW
8793/* Xscale multiply-accumulate (argument parse)
8794 MIAcc acc0,Rm,Rs
8795 MIAPHcc acc0,Rm,Rs
8796 MIAxycc acc0,Rm,Rs. */
a737bd4d 8797
c19d1205
ZW
8798static void
8799do_xsc_mia (void)
8800{
8801 inst.instruction |= inst.operands[1].reg;
8802 inst.instruction |= inst.operands[2].reg << 12;
8803}
a737bd4d 8804
c19d1205 8805/* Xscale move-accumulator-register (argument parse)
a737bd4d 8806
c19d1205 8807 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8808
c19d1205
ZW
8809static void
8810do_xsc_mar (void)
8811{
8812 inst.instruction |= inst.operands[1].reg << 12;
8813 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8814}
8815
c19d1205 8816/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8817
c19d1205 8818 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8819
8820static void
c19d1205 8821do_xsc_mra (void)
b99bd4ef 8822{
c19d1205
ZW
8823 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8824 inst.instruction |= inst.operands[0].reg << 12;
8825 inst.instruction |= inst.operands[1].reg << 16;
8826}
8827\f
8828/* Encoding functions relevant only to Thumb. */
b99bd4ef 8829
c19d1205
ZW
8830/* inst.operands[i] is a shifted-register operand; encode
8831 it into inst.instruction in the format used by Thumb32. */
8832
8833static void
8834encode_thumb32_shifted_operand (int i)
8835{
8836 unsigned int value = inst.reloc.exp.X_add_number;
8837 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8838
9c3c69f2
PB
8839 constraint (inst.operands[i].immisreg,
8840 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8841 inst.instruction |= inst.operands[i].reg;
8842 if (shift == SHIFT_RRX)
8843 inst.instruction |= SHIFT_ROR << 4;
8844 else
b99bd4ef 8845 {
c19d1205
ZW
8846 constraint (inst.reloc.exp.X_op != O_constant,
8847 _("expression too complex"));
8848
8849 constraint (value > 32
8850 || (value == 32 && (shift == SHIFT_LSL
8851 || shift == SHIFT_ROR)),
8852 _("shift expression is too large"));
8853
8854 if (value == 0)
8855 shift = SHIFT_LSL;
8856 else if (value == 32)
8857 value = 0;
8858
8859 inst.instruction |= shift << 4;
8860 inst.instruction |= (value & 0x1c) << 10;
8861 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8862 }
c19d1205 8863}
b99bd4ef 8864
b99bd4ef 8865
c19d1205
ZW
8866/* inst.operands[i] was set up by parse_address. Encode it into a
8867 Thumb32 format load or store instruction. Reject forms that cannot
8868 be used with such instructions. If is_t is true, reject forms that
8869 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
8870 that cannot be used with a D instruction. If it is a store insn,
8871 reject PC in Rn. */
b99bd4ef 8872
c19d1205
ZW
8873static void
8874encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8875{
5be8be5d 8876 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
8877
8878 constraint (!inst.operands[i].isreg,
53365c0d 8879 _("Instruction does not support =N addresses"));
b99bd4ef 8880
c19d1205
ZW
8881 inst.instruction |= inst.operands[i].reg << 16;
8882 if (inst.operands[i].immisreg)
b99bd4ef 8883 {
5be8be5d 8884 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
8885 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8886 constraint (inst.operands[i].negative,
8887 _("Thumb does not support negative register indexing"));
8888 constraint (inst.operands[i].postind,
8889 _("Thumb does not support register post-indexing"));
8890 constraint (inst.operands[i].writeback,
8891 _("Thumb does not support register indexing with writeback"));
8892 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8893 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8894
f40d1643 8895 inst.instruction |= inst.operands[i].imm;
c19d1205 8896 if (inst.operands[i].shifted)
b99bd4ef 8897 {
c19d1205
ZW
8898 constraint (inst.reloc.exp.X_op != O_constant,
8899 _("expression too complex"));
9c3c69f2
PB
8900 constraint (inst.reloc.exp.X_add_number < 0
8901 || inst.reloc.exp.X_add_number > 3,
c19d1205 8902 _("shift out of range"));
9c3c69f2 8903 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8904 }
8905 inst.reloc.type = BFD_RELOC_UNUSED;
8906 }
8907 else if (inst.operands[i].preind)
8908 {
5be8be5d 8909 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 8910 constraint (is_t && inst.operands[i].writeback,
c19d1205 8911 _("cannot use writeback with this instruction"));
5be8be5d
DG
8912 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
8913 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
c19d1205
ZW
8914
8915 if (is_d)
8916 {
8917 inst.instruction |= 0x01000000;
8918 if (inst.operands[i].writeback)
8919 inst.instruction |= 0x00200000;
b99bd4ef 8920 }
c19d1205 8921 else
b99bd4ef 8922 {
c19d1205
ZW
8923 inst.instruction |= 0x00000c00;
8924 if (inst.operands[i].writeback)
8925 inst.instruction |= 0x00000100;
b99bd4ef 8926 }
c19d1205 8927 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8928 }
c19d1205 8929 else if (inst.operands[i].postind)
b99bd4ef 8930 {
9c2799c2 8931 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8932 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8933 constraint (is_t, _("cannot use post-indexing with this instruction"));
8934
8935 if (is_d)
8936 inst.instruction |= 0x00200000;
8937 else
8938 inst.instruction |= 0x00000900;
8939 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8940 }
8941 else /* unindexed - only for coprocessor */
8942 inst.error = _("instruction does not accept unindexed addressing");
8943}
8944
8945/* Table of Thumb instructions which exist in both 16- and 32-bit
8946 encodings (the latter only in post-V6T2 cores). The index is the
8947 value used in the insns table below. When there is more than one
8948 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8949 holds variant (1).
8950 Also contains several pseudo-instructions used during relaxation. */
c19d1205 8951#define T16_32_TAB \
21d799b5
NC
8952 X(_adc, 4140, eb400000), \
8953 X(_adcs, 4140, eb500000), \
8954 X(_add, 1c00, eb000000), \
8955 X(_adds, 1c00, eb100000), \
8956 X(_addi, 0000, f1000000), \
8957 X(_addis, 0000, f1100000), \
8958 X(_add_pc,000f, f20f0000), \
8959 X(_add_sp,000d, f10d0000), \
8960 X(_adr, 000f, f20f0000), \
8961 X(_and, 4000, ea000000), \
8962 X(_ands, 4000, ea100000), \
8963 X(_asr, 1000, fa40f000), \
8964 X(_asrs, 1000, fa50f000), \
8965 X(_b, e000, f000b000), \
8966 X(_bcond, d000, f0008000), \
8967 X(_bic, 4380, ea200000), \
8968 X(_bics, 4380, ea300000), \
8969 X(_cmn, 42c0, eb100f00), \
8970 X(_cmp, 2800, ebb00f00), \
8971 X(_cpsie, b660, f3af8400), \
8972 X(_cpsid, b670, f3af8600), \
8973 X(_cpy, 4600, ea4f0000), \
8974 X(_dec_sp,80dd, f1ad0d00), \
8975 X(_eor, 4040, ea800000), \
8976 X(_eors, 4040, ea900000), \
8977 X(_inc_sp,00dd, f10d0d00), \
8978 X(_ldmia, c800, e8900000), \
8979 X(_ldr, 6800, f8500000), \
8980 X(_ldrb, 7800, f8100000), \
8981 X(_ldrh, 8800, f8300000), \
8982 X(_ldrsb, 5600, f9100000), \
8983 X(_ldrsh, 5e00, f9300000), \
8984 X(_ldr_pc,4800, f85f0000), \
8985 X(_ldr_pc2,4800, f85f0000), \
8986 X(_ldr_sp,9800, f85d0000), \
8987 X(_lsl, 0000, fa00f000), \
8988 X(_lsls, 0000, fa10f000), \
8989 X(_lsr, 0800, fa20f000), \
8990 X(_lsrs, 0800, fa30f000), \
8991 X(_mov, 2000, ea4f0000), \
8992 X(_movs, 2000, ea5f0000), \
8993 X(_mul, 4340, fb00f000), \
8994 X(_muls, 4340, ffffffff), /* no 32b muls */ \
8995 X(_mvn, 43c0, ea6f0000), \
8996 X(_mvns, 43c0, ea7f0000), \
8997 X(_neg, 4240, f1c00000), /* rsb #0 */ \
8998 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
8999 X(_orr, 4300, ea400000), \
9000 X(_orrs, 4300, ea500000), \
9001 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9002 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9003 X(_rev, ba00, fa90f080), \
9004 X(_rev16, ba40, fa90f090), \
9005 X(_revsh, bac0, fa90f0b0), \
9006 X(_ror, 41c0, fa60f000), \
9007 X(_rors, 41c0, fa70f000), \
9008 X(_sbc, 4180, eb600000), \
9009 X(_sbcs, 4180, eb700000), \
9010 X(_stmia, c000, e8800000), \
9011 X(_str, 6000, f8400000), \
9012 X(_strb, 7000, f8000000), \
9013 X(_strh, 8000, f8200000), \
9014 X(_str_sp,9000, f84d0000), \
9015 X(_sub, 1e00, eba00000), \
9016 X(_subs, 1e00, ebb00000), \
9017 X(_subi, 8000, f1a00000), \
9018 X(_subis, 8000, f1b00000), \
9019 X(_sxtb, b240, fa4ff080), \
9020 X(_sxth, b200, fa0ff080), \
9021 X(_tst, 4200, ea100f00), \
9022 X(_uxtb, b2c0, fa5ff080), \
9023 X(_uxth, b280, fa1ff080), \
9024 X(_nop, bf00, f3af8000), \
9025 X(_yield, bf10, f3af8001), \
9026 X(_wfe, bf20, f3af8002), \
9027 X(_wfi, bf30, f3af8003), \
9028 X(_sev, bf40, f3af8004),
c19d1205
ZW
9029
9030/* To catch errors in encoding functions, the codes are all offset by
9031 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9032 as 16-bit instructions. */
21d799b5 9033#define X(a,b,c) T_MNEM##a
c19d1205
ZW
9034enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9035#undef X
9036
9037#define X(a,b,c) 0x##b
9038static const unsigned short thumb_op16[] = { T16_32_TAB };
9039#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9040#undef X
9041
9042#define X(a,b,c) 0x##c
9043static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
9044#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9045#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
9046#undef X
9047#undef T16_32_TAB
9048
9049/* Thumb instruction encoders, in alphabetical order. */
9050
92e90b6e 9051/* ADDW or SUBW. */
c921be7d 9052
92e90b6e
PB
9053static void
9054do_t_add_sub_w (void)
9055{
9056 int Rd, Rn;
9057
9058 Rd = inst.operands[0].reg;
9059 Rn = inst.operands[1].reg;
9060
539d4391
NC
9061 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9062 is the SP-{plus,minus}-immediate form of the instruction. */
9063 if (Rn == REG_SP)
9064 constraint (Rd == REG_PC, BAD_PC);
9065 else
9066 reject_bad_reg (Rd);
fdfde340 9067
92e90b6e
PB
9068 inst.instruction |= (Rn << 16) | (Rd << 8);
9069 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9070}
9071
c19d1205
ZW
9072/* Parse an add or subtract instruction. We get here with inst.instruction
9073 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9074
9075static void
9076do_t_add_sub (void)
9077{
9078 int Rd, Rs, Rn;
9079
9080 Rd = inst.operands[0].reg;
9081 Rs = (inst.operands[1].present
9082 ? inst.operands[1].reg /* Rd, Rs, foo */
9083 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9084
e07e6e58
NC
9085 if (Rd == REG_PC)
9086 set_it_insn_type_last ();
9087
c19d1205
ZW
9088 if (unified_syntax)
9089 {
0110f2b8
PB
9090 bfd_boolean flags;
9091 bfd_boolean narrow;
9092 int opcode;
9093
9094 flags = (inst.instruction == T_MNEM_adds
9095 || inst.instruction == T_MNEM_subs);
9096 if (flags)
e07e6e58 9097 narrow = !in_it_block ();
0110f2b8 9098 else
e07e6e58 9099 narrow = in_it_block ();
c19d1205 9100 if (!inst.operands[2].isreg)
b99bd4ef 9101 {
16805f35
PB
9102 int add;
9103
fdfde340
JM
9104 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9105
16805f35
PB
9106 add = (inst.instruction == T_MNEM_add
9107 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
9108 opcode = 0;
9109 if (inst.size_req != 4)
9110 {
0110f2b8
PB
9111 /* Attempt to use a narrow opcode, with relaxation if
9112 appropriate. */
9113 if (Rd == REG_SP && Rs == REG_SP && !flags)
9114 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9115 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9116 opcode = T_MNEM_add_sp;
9117 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9118 opcode = T_MNEM_add_pc;
9119 else if (Rd <= 7 && Rs <= 7 && narrow)
9120 {
9121 if (flags)
9122 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9123 else
9124 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9125 }
9126 if (opcode)
9127 {
9128 inst.instruction = THUMB_OP16(opcode);
9129 inst.instruction |= (Rd << 4) | Rs;
9130 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9131 if (inst.size_req != 2)
9132 inst.relax = opcode;
9133 }
9134 else
9135 constraint (inst.size_req == 2, BAD_HIREG);
9136 }
9137 if (inst.size_req == 4
9138 || (inst.size_req != 2 && !opcode))
9139 {
efd81785
PB
9140 if (Rd == REG_PC)
9141 {
fdfde340 9142 constraint (add, BAD_PC);
efd81785
PB
9143 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9144 _("only SUBS PC, LR, #const allowed"));
9145 constraint (inst.reloc.exp.X_op != O_constant,
9146 _("expression too complex"));
9147 constraint (inst.reloc.exp.X_add_number < 0
9148 || inst.reloc.exp.X_add_number > 0xff,
9149 _("immediate value out of range"));
9150 inst.instruction = T2_SUBS_PC_LR
9151 | inst.reloc.exp.X_add_number;
9152 inst.reloc.type = BFD_RELOC_UNUSED;
9153 return;
9154 }
9155 else if (Rs == REG_PC)
16805f35
PB
9156 {
9157 /* Always use addw/subw. */
9158 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9159 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9160 }
9161 else
9162 {
9163 inst.instruction = THUMB_OP32 (inst.instruction);
9164 inst.instruction = (inst.instruction & 0xe1ffffff)
9165 | 0x10000000;
9166 if (flags)
9167 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9168 else
9169 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9170 }
dc4503c6
PB
9171 inst.instruction |= Rd << 8;
9172 inst.instruction |= Rs << 16;
0110f2b8 9173 }
b99bd4ef 9174 }
c19d1205
ZW
9175 else
9176 {
9177 Rn = inst.operands[2].reg;
9178 /* See if we can do this with a 16-bit instruction. */
9179 if (!inst.operands[2].shifted && inst.size_req != 4)
9180 {
e27ec89e
PB
9181 if (Rd > 7 || Rs > 7 || Rn > 7)
9182 narrow = FALSE;
9183
9184 if (narrow)
c19d1205 9185 {
e27ec89e
PB
9186 inst.instruction = ((inst.instruction == T_MNEM_adds
9187 || inst.instruction == T_MNEM_add)
c19d1205
ZW
9188 ? T_OPCODE_ADD_R3
9189 : T_OPCODE_SUB_R3);
9190 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9191 return;
9192 }
b99bd4ef 9193
7e806470 9194 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 9195 {
7e806470
PB
9196 /* Thumb-1 cores (except v6-M) require at least one high
9197 register in a narrow non flag setting add. */
9198 if (Rd > 7 || Rn > 7
9199 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9200 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9201 {
7e806470
PB
9202 if (Rd == Rn)
9203 {
9204 Rn = Rs;
9205 Rs = Rd;
9206 }
c19d1205
ZW
9207 inst.instruction = T_OPCODE_ADD_HI;
9208 inst.instruction |= (Rd & 8) << 4;
9209 inst.instruction |= (Rd & 7);
9210 inst.instruction |= Rn << 3;
9211 return;
9212 }
c19d1205
ZW
9213 }
9214 }
c921be7d 9215
fdfde340
JM
9216 constraint (Rd == REG_PC, BAD_PC);
9217 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9218 constraint (Rs == REG_PC, BAD_PC);
9219 reject_bad_reg (Rn);
9220
c19d1205
ZW
9221 /* If we get here, it can't be done in 16 bits. */
9222 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9223 _("shift must be constant"));
9224 inst.instruction = THUMB_OP32 (inst.instruction);
9225 inst.instruction |= Rd << 8;
9226 inst.instruction |= Rs << 16;
9227 encode_thumb32_shifted_operand (2);
9228 }
9229 }
9230 else
9231 {
9232 constraint (inst.instruction == T_MNEM_adds
9233 || inst.instruction == T_MNEM_subs,
9234 BAD_THUMB32);
b99bd4ef 9235
c19d1205 9236 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9237 {
c19d1205
ZW
9238 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9239 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9240 BAD_HIREG);
9241
9242 inst.instruction = (inst.instruction == T_MNEM_add
9243 ? 0x0000 : 0x8000);
9244 inst.instruction |= (Rd << 4) | Rs;
9245 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9246 return;
9247 }
9248
c19d1205
ZW
9249 Rn = inst.operands[2].reg;
9250 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9251
c19d1205
ZW
9252 /* We now have Rd, Rs, and Rn set to registers. */
9253 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9254 {
c19d1205
ZW
9255 /* Can't do this for SUB. */
9256 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9257 inst.instruction = T_OPCODE_ADD_HI;
9258 inst.instruction |= (Rd & 8) << 4;
9259 inst.instruction |= (Rd & 7);
9260 if (Rs == Rd)
9261 inst.instruction |= Rn << 3;
9262 else if (Rn == Rd)
9263 inst.instruction |= Rs << 3;
9264 else
9265 constraint (1, _("dest must overlap one source register"));
9266 }
9267 else
9268 {
9269 inst.instruction = (inst.instruction == T_MNEM_add
9270 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9271 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9272 }
b99bd4ef 9273 }
b99bd4ef
NC
9274}
9275
c19d1205
ZW
9276static void
9277do_t_adr (void)
9278{
fdfde340
JM
9279 unsigned Rd;
9280
9281 Rd = inst.operands[0].reg;
9282 reject_bad_reg (Rd);
9283
9284 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9285 {
9286 /* Defer to section relaxation. */
9287 inst.relax = inst.instruction;
9288 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9289 inst.instruction |= Rd << 4;
0110f2b8
PB
9290 }
9291 else if (unified_syntax && inst.size_req != 2)
e9f89963 9292 {
0110f2b8 9293 /* Generate a 32-bit opcode. */
e9f89963 9294 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9295 inst.instruction |= Rd << 8;
e9f89963
PB
9296 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9297 inst.reloc.pc_rel = 1;
9298 }
9299 else
9300 {
0110f2b8 9301 /* Generate a 16-bit opcode. */
e9f89963
PB
9302 inst.instruction = THUMB_OP16 (inst.instruction);
9303 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9304 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9305 inst.reloc.pc_rel = 1;
b99bd4ef 9306
fdfde340 9307 inst.instruction |= Rd << 4;
e9f89963 9308 }
c19d1205 9309}
b99bd4ef 9310
c19d1205
ZW
9311/* Arithmetic instructions for which there is just one 16-bit
9312 instruction encoding, and it allows only two low registers.
9313 For maximal compatibility with ARM syntax, we allow three register
9314 operands even when Thumb-32 instructions are not available, as long
9315 as the first two are identical. For instance, both "sbc r0,r1" and
9316 "sbc r0,r0,r1" are allowed. */
b99bd4ef 9317static void
c19d1205 9318do_t_arit3 (void)
b99bd4ef 9319{
c19d1205 9320 int Rd, Rs, Rn;
b99bd4ef 9321
c19d1205
ZW
9322 Rd = inst.operands[0].reg;
9323 Rs = (inst.operands[1].present
9324 ? inst.operands[1].reg /* Rd, Rs, foo */
9325 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9326 Rn = inst.operands[2].reg;
b99bd4ef 9327
fdfde340
JM
9328 reject_bad_reg (Rd);
9329 reject_bad_reg (Rs);
9330 if (inst.operands[2].isreg)
9331 reject_bad_reg (Rn);
9332
c19d1205 9333 if (unified_syntax)
b99bd4ef 9334 {
c19d1205
ZW
9335 if (!inst.operands[2].isreg)
9336 {
9337 /* For an immediate, we always generate a 32-bit opcode;
9338 section relaxation will shrink it later if possible. */
9339 inst.instruction = THUMB_OP32 (inst.instruction);
9340 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9341 inst.instruction |= Rd << 8;
9342 inst.instruction |= Rs << 16;
9343 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9344 }
9345 else
9346 {
e27ec89e
PB
9347 bfd_boolean narrow;
9348
c19d1205 9349 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9350 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9351 narrow = !in_it_block ();
e27ec89e 9352 else
e07e6e58 9353 narrow = in_it_block ();
e27ec89e
PB
9354
9355 if (Rd > 7 || Rn > 7 || Rs > 7)
9356 narrow = FALSE;
9357 if (inst.operands[2].shifted)
9358 narrow = FALSE;
9359 if (inst.size_req == 4)
9360 narrow = FALSE;
9361
9362 if (narrow
c19d1205
ZW
9363 && Rd == Rs)
9364 {
9365 inst.instruction = THUMB_OP16 (inst.instruction);
9366 inst.instruction |= Rd;
9367 inst.instruction |= Rn << 3;
9368 return;
9369 }
b99bd4ef 9370
c19d1205
ZW
9371 /* If we get here, it can't be done in 16 bits. */
9372 constraint (inst.operands[2].shifted
9373 && inst.operands[2].immisreg,
9374 _("shift must be constant"));
9375 inst.instruction = THUMB_OP32 (inst.instruction);
9376 inst.instruction |= Rd << 8;
9377 inst.instruction |= Rs << 16;
9378 encode_thumb32_shifted_operand (2);
9379 }
a737bd4d 9380 }
c19d1205 9381 else
b99bd4ef 9382 {
c19d1205
ZW
9383 /* On its face this is a lie - the instruction does set the
9384 flags. However, the only supported mnemonic in this mode
9385 says it doesn't. */
9386 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9387
c19d1205
ZW
9388 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9389 _("unshifted register required"));
9390 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9391 constraint (Rd != Rs,
9392 _("dest and source1 must be the same register"));
a737bd4d 9393
c19d1205
ZW
9394 inst.instruction = THUMB_OP16 (inst.instruction);
9395 inst.instruction |= Rd;
9396 inst.instruction |= Rn << 3;
b99bd4ef 9397 }
a737bd4d 9398}
b99bd4ef 9399
c19d1205
ZW
9400/* Similarly, but for instructions where the arithmetic operation is
9401 commutative, so we can allow either of them to be different from
9402 the destination operand in a 16-bit instruction. For instance, all
9403 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9404 accepted. */
9405static void
9406do_t_arit3c (void)
a737bd4d 9407{
c19d1205 9408 int Rd, Rs, Rn;
b99bd4ef 9409
c19d1205
ZW
9410 Rd = inst.operands[0].reg;
9411 Rs = (inst.operands[1].present
9412 ? inst.operands[1].reg /* Rd, Rs, foo */
9413 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9414 Rn = inst.operands[2].reg;
c921be7d 9415
fdfde340
JM
9416 reject_bad_reg (Rd);
9417 reject_bad_reg (Rs);
9418 if (inst.operands[2].isreg)
9419 reject_bad_reg (Rn);
a737bd4d 9420
c19d1205 9421 if (unified_syntax)
a737bd4d 9422 {
c19d1205 9423 if (!inst.operands[2].isreg)
b99bd4ef 9424 {
c19d1205
ZW
9425 /* For an immediate, we always generate a 32-bit opcode;
9426 section relaxation will shrink it later if possible. */
9427 inst.instruction = THUMB_OP32 (inst.instruction);
9428 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9429 inst.instruction |= Rd << 8;
9430 inst.instruction |= Rs << 16;
9431 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9432 }
c19d1205 9433 else
a737bd4d 9434 {
e27ec89e
PB
9435 bfd_boolean narrow;
9436
c19d1205 9437 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9438 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9439 narrow = !in_it_block ();
e27ec89e 9440 else
e07e6e58 9441 narrow = in_it_block ();
e27ec89e
PB
9442
9443 if (Rd > 7 || Rn > 7 || Rs > 7)
9444 narrow = FALSE;
9445 if (inst.operands[2].shifted)
9446 narrow = FALSE;
9447 if (inst.size_req == 4)
9448 narrow = FALSE;
9449
9450 if (narrow)
a737bd4d 9451 {
c19d1205 9452 if (Rd == Rs)
a737bd4d 9453 {
c19d1205
ZW
9454 inst.instruction = THUMB_OP16 (inst.instruction);
9455 inst.instruction |= Rd;
9456 inst.instruction |= Rn << 3;
9457 return;
a737bd4d 9458 }
c19d1205 9459 if (Rd == Rn)
a737bd4d 9460 {
c19d1205
ZW
9461 inst.instruction = THUMB_OP16 (inst.instruction);
9462 inst.instruction |= Rd;
9463 inst.instruction |= Rs << 3;
9464 return;
a737bd4d
NC
9465 }
9466 }
c19d1205
ZW
9467
9468 /* If we get here, it can't be done in 16 bits. */
9469 constraint (inst.operands[2].shifted
9470 && inst.operands[2].immisreg,
9471 _("shift must be constant"));
9472 inst.instruction = THUMB_OP32 (inst.instruction);
9473 inst.instruction |= Rd << 8;
9474 inst.instruction |= Rs << 16;
9475 encode_thumb32_shifted_operand (2);
a737bd4d 9476 }
b99bd4ef 9477 }
c19d1205
ZW
9478 else
9479 {
9480 /* On its face this is a lie - the instruction does set the
9481 flags. However, the only supported mnemonic in this mode
9482 says it doesn't. */
9483 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9484
c19d1205
ZW
9485 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9486 _("unshifted register required"));
9487 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9488
9489 inst.instruction = THUMB_OP16 (inst.instruction);
9490 inst.instruction |= Rd;
9491
9492 if (Rd == Rs)
9493 inst.instruction |= Rn << 3;
9494 else if (Rd == Rn)
9495 inst.instruction |= Rs << 3;
9496 else
9497 constraint (1, _("dest must overlap one source register"));
9498 }
a737bd4d
NC
9499}
9500
62b3e311
PB
9501static void
9502do_t_barrier (void)
9503{
9504 if (inst.operands[0].present)
9505 {
9506 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
9507 && inst.operands[0].imm > 0xf
9508 && inst.operands[0].imm < 0x0,
bd3ba5d1 9509 _("bad barrier type"));
62b3e311
PB
9510 inst.instruction |= inst.operands[0].imm;
9511 }
9512 else
9513 inst.instruction |= 0xf;
9514}
9515
c19d1205
ZW
9516static void
9517do_t_bfc (void)
a737bd4d 9518{
fdfde340 9519 unsigned Rd;
c19d1205
ZW
9520 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9521 constraint (msb > 32, _("bit-field extends past end of register"));
9522 /* The instruction encoding stores the LSB and MSB,
9523 not the LSB and width. */
fdfde340
JM
9524 Rd = inst.operands[0].reg;
9525 reject_bad_reg (Rd);
9526 inst.instruction |= Rd << 8;
c19d1205
ZW
9527 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9528 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9529 inst.instruction |= msb - 1;
b99bd4ef
NC
9530}
9531
c19d1205
ZW
9532static void
9533do_t_bfi (void)
b99bd4ef 9534{
fdfde340 9535 int Rd, Rn;
c19d1205 9536 unsigned int msb;
b99bd4ef 9537
fdfde340
JM
9538 Rd = inst.operands[0].reg;
9539 reject_bad_reg (Rd);
9540
c19d1205
ZW
9541 /* #0 in second position is alternative syntax for bfc, which is
9542 the same instruction but with REG_PC in the Rm field. */
9543 if (!inst.operands[1].isreg)
fdfde340
JM
9544 Rn = REG_PC;
9545 else
9546 {
9547 Rn = inst.operands[1].reg;
9548 reject_bad_reg (Rn);
9549 }
b99bd4ef 9550
c19d1205
ZW
9551 msb = inst.operands[2].imm + inst.operands[3].imm;
9552 constraint (msb > 32, _("bit-field extends past end of register"));
9553 /* The instruction encoding stores the LSB and MSB,
9554 not the LSB and width. */
fdfde340
JM
9555 inst.instruction |= Rd << 8;
9556 inst.instruction |= Rn << 16;
c19d1205
ZW
9557 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9558 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9559 inst.instruction |= msb - 1;
b99bd4ef
NC
9560}
9561
c19d1205
ZW
9562static void
9563do_t_bfx (void)
b99bd4ef 9564{
fdfde340
JM
9565 unsigned Rd, Rn;
9566
9567 Rd = inst.operands[0].reg;
9568 Rn = inst.operands[1].reg;
9569
9570 reject_bad_reg (Rd);
9571 reject_bad_reg (Rn);
9572
c19d1205
ZW
9573 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9574 _("bit-field extends past end of register"));
fdfde340
JM
9575 inst.instruction |= Rd << 8;
9576 inst.instruction |= Rn << 16;
c19d1205
ZW
9577 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9578 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9579 inst.instruction |= inst.operands[3].imm - 1;
9580}
b99bd4ef 9581
c19d1205
ZW
9582/* ARM V5 Thumb BLX (argument parse)
9583 BLX <target_addr> which is BLX(1)
9584 BLX <Rm> which is BLX(2)
9585 Unfortunately, there are two different opcodes for this mnemonic.
9586 So, the insns[].value is not used, and the code here zaps values
9587 into inst.instruction.
b99bd4ef 9588
c19d1205
ZW
9589 ??? How to take advantage of the additional two bits of displacement
9590 available in Thumb32 mode? Need new relocation? */
b99bd4ef 9591
c19d1205
ZW
9592static void
9593do_t_blx (void)
9594{
e07e6e58
NC
9595 set_it_insn_type_last ();
9596
c19d1205 9597 if (inst.operands[0].isreg)
fdfde340
JM
9598 {
9599 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9600 /* We have a register, so this is BLX(2). */
9601 inst.instruction |= inst.operands[0].reg << 3;
9602 }
b99bd4ef
NC
9603 else
9604 {
c19d1205 9605 /* No register. This must be BLX(1). */
2fc8bdac 9606 inst.instruction = 0xf000e800;
00adf2d4 9607 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 9608 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9609 }
9610}
9611
c19d1205
ZW
9612static void
9613do_t_branch (void)
b99bd4ef 9614{
0110f2b8 9615 int opcode;
dfa9f0d5
PB
9616 int cond;
9617
e07e6e58
NC
9618 cond = inst.cond;
9619 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9620
9621 if (in_it_block ())
dfa9f0d5
PB
9622 {
9623 /* Conditional branches inside IT blocks are encoded as unconditional
9624 branches. */
9625 cond = COND_ALWAYS;
dfa9f0d5
PB
9626 }
9627 else
9628 cond = inst.cond;
9629
9630 if (cond != COND_ALWAYS)
0110f2b8
PB
9631 opcode = T_MNEM_bcond;
9632 else
9633 opcode = inst.instruction;
9634
9635 if (unified_syntax && inst.size_req == 4)
c19d1205 9636 {
0110f2b8 9637 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9638 if (cond == COND_ALWAYS)
0110f2b8 9639 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9640 else
9641 {
9c2799c2 9642 gas_assert (cond != 0xF);
dfa9f0d5 9643 inst.instruction |= cond << 22;
c19d1205
ZW
9644 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9645 }
9646 }
b99bd4ef
NC
9647 else
9648 {
0110f2b8 9649 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9650 if (cond == COND_ALWAYS)
c19d1205
ZW
9651 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9652 else
b99bd4ef 9653 {
dfa9f0d5 9654 inst.instruction |= cond << 8;
c19d1205 9655 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9656 }
0110f2b8
PB
9657 /* Allow section relaxation. */
9658 if (unified_syntax && inst.size_req != 2)
9659 inst.relax = opcode;
b99bd4ef 9660 }
c19d1205
ZW
9661
9662 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9663}
9664
9665static void
c19d1205 9666do_t_bkpt (void)
b99bd4ef 9667{
dfa9f0d5
PB
9668 constraint (inst.cond != COND_ALWAYS,
9669 _("instruction is always unconditional"));
c19d1205 9670 if (inst.operands[0].present)
b99bd4ef 9671 {
c19d1205
ZW
9672 constraint (inst.operands[0].imm > 255,
9673 _("immediate value out of range"));
9674 inst.instruction |= inst.operands[0].imm;
e07e6e58 9675 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 9676 }
b99bd4ef
NC
9677}
9678
9679static void
c19d1205 9680do_t_branch23 (void)
b99bd4ef 9681{
e07e6e58 9682 set_it_insn_type_last ();
c19d1205 9683 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
9684 inst.reloc.pc_rel = 1;
9685
4343666d 9686#if defined(OBJ_COFF)
c19d1205
ZW
9687 /* If the destination of the branch is a defined symbol which does not have
9688 the THUMB_FUNC attribute, then we must be calling a function which has
9689 the (interfacearm) attribute. We look for the Thumb entry point to that
9690 function and change the branch to refer to that function instead. */
9691 if ( inst.reloc.exp.X_op == O_symbol
9692 && inst.reloc.exp.X_add_symbol != NULL
9693 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9694 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9695 inst.reloc.exp.X_add_symbol =
9696 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 9697#endif
90e4755a
RE
9698}
9699
9700static void
c19d1205 9701do_t_bx (void)
90e4755a 9702{
e07e6e58 9703 set_it_insn_type_last ();
c19d1205
ZW
9704 inst.instruction |= inst.operands[0].reg << 3;
9705 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9706 should cause the alignment to be checked once it is known. This is
9707 because BX PC only works if the instruction is word aligned. */
9708}
90e4755a 9709
c19d1205
ZW
9710static void
9711do_t_bxj (void)
9712{
fdfde340 9713 int Rm;
90e4755a 9714
e07e6e58 9715 set_it_insn_type_last ();
fdfde340
JM
9716 Rm = inst.operands[0].reg;
9717 reject_bad_reg (Rm);
9718 inst.instruction |= Rm << 16;
90e4755a
RE
9719}
9720
9721static void
c19d1205 9722do_t_clz (void)
90e4755a 9723{
fdfde340
JM
9724 unsigned Rd;
9725 unsigned Rm;
9726
9727 Rd = inst.operands[0].reg;
9728 Rm = inst.operands[1].reg;
9729
9730 reject_bad_reg (Rd);
9731 reject_bad_reg (Rm);
9732
9733 inst.instruction |= Rd << 8;
9734 inst.instruction |= Rm << 16;
9735 inst.instruction |= Rm;
c19d1205 9736}
90e4755a 9737
dfa9f0d5
PB
9738static void
9739do_t_cps (void)
9740{
e07e6e58 9741 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
9742 inst.instruction |= inst.operands[0].imm;
9743}
9744
c19d1205
ZW
9745static void
9746do_t_cpsi (void)
9747{
e07e6e58 9748 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 9749 if (unified_syntax
62b3e311
PB
9750 && (inst.operands[1].present || inst.size_req == 4)
9751 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9752 {
c19d1205
ZW
9753 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9754 inst.instruction = 0xf3af8000;
9755 inst.instruction |= imod << 9;
9756 inst.instruction |= inst.operands[0].imm << 5;
9757 if (inst.operands[1].present)
9758 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9759 }
c19d1205 9760 else
90e4755a 9761 {
62b3e311
PB
9762 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9763 && (inst.operands[0].imm & 4),
9764 _("selected processor does not support 'A' form "
9765 "of this instruction"));
9766 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9767 _("Thumb does not support the 2-argument "
9768 "form of this instruction"));
9769 inst.instruction |= inst.operands[0].imm;
90e4755a 9770 }
90e4755a
RE
9771}
9772
c19d1205
ZW
9773/* THUMB CPY instruction (argument parse). */
9774
90e4755a 9775static void
c19d1205 9776do_t_cpy (void)
90e4755a 9777{
c19d1205 9778 if (inst.size_req == 4)
90e4755a 9779 {
c19d1205
ZW
9780 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9781 inst.instruction |= inst.operands[0].reg << 8;
9782 inst.instruction |= inst.operands[1].reg;
90e4755a 9783 }
c19d1205 9784 else
90e4755a 9785 {
c19d1205
ZW
9786 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9787 inst.instruction |= (inst.operands[0].reg & 0x7);
9788 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9789 }
90e4755a
RE
9790}
9791
90e4755a 9792static void
25fe350b 9793do_t_cbz (void)
90e4755a 9794{
e07e6e58 9795 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
9796 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9797 inst.instruction |= inst.operands[0].reg;
9798 inst.reloc.pc_rel = 1;
9799 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9800}
90e4755a 9801
62b3e311
PB
9802static void
9803do_t_dbg (void)
9804{
9805 inst.instruction |= inst.operands[0].imm;
9806}
9807
9808static void
9809do_t_div (void)
9810{
fdfde340
JM
9811 unsigned Rd, Rn, Rm;
9812
9813 Rd = inst.operands[0].reg;
9814 Rn = (inst.operands[1].present
9815 ? inst.operands[1].reg : Rd);
9816 Rm = inst.operands[2].reg;
9817
9818 reject_bad_reg (Rd);
9819 reject_bad_reg (Rn);
9820 reject_bad_reg (Rm);
9821
9822 inst.instruction |= Rd << 8;
9823 inst.instruction |= Rn << 16;
9824 inst.instruction |= Rm;
62b3e311
PB
9825}
9826
c19d1205
ZW
9827static void
9828do_t_hint (void)
9829{
9830 if (unified_syntax && inst.size_req == 4)
9831 inst.instruction = THUMB_OP32 (inst.instruction);
9832 else
9833 inst.instruction = THUMB_OP16 (inst.instruction);
9834}
90e4755a 9835
c19d1205
ZW
9836static void
9837do_t_it (void)
9838{
9839 unsigned int cond = inst.operands[0].imm;
e27ec89e 9840
e07e6e58
NC
9841 set_it_insn_type (IT_INSN);
9842 now_it.mask = (inst.instruction & 0xf) | 0x10;
9843 now_it.cc = cond;
e27ec89e
PB
9844
9845 /* If the condition is a negative condition, invert the mask. */
c19d1205 9846 if ((cond & 0x1) == 0x0)
90e4755a 9847 {
c19d1205 9848 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9849
c19d1205
ZW
9850 if ((mask & 0x7) == 0)
9851 /* no conversion needed */;
9852 else if ((mask & 0x3) == 0)
e27ec89e
PB
9853 mask ^= 0x8;
9854 else if ((mask & 0x1) == 0)
9855 mask ^= 0xC;
c19d1205 9856 else
e27ec89e 9857 mask ^= 0xE;
90e4755a 9858
e27ec89e
PB
9859 inst.instruction &= 0xfff0;
9860 inst.instruction |= mask;
c19d1205 9861 }
90e4755a 9862
c19d1205
ZW
9863 inst.instruction |= cond << 4;
9864}
90e4755a 9865
3c707909
PB
9866/* Helper function used for both push/pop and ldm/stm. */
9867static void
9868encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9869{
9870 bfd_boolean load;
9871
9872 load = (inst.instruction & (1 << 20)) != 0;
9873
9874 if (mask & (1 << 13))
9875 inst.error = _("SP not allowed in register list");
1e5b0379
NC
9876
9877 if ((mask & (1 << base)) != 0
9878 && writeback)
9879 inst.error = _("having the base register in the register list when "
9880 "using write back is UNPREDICTABLE");
9881
3c707909
PB
9882 if (load)
9883 {
e07e6e58
NC
9884 if (mask & (1 << 15))
9885 {
9886 if (mask & (1 << 14))
9887 inst.error = _("LR and PC should not both be in register list");
9888 else
9889 set_it_insn_type_last ();
9890 }
3c707909
PB
9891 }
9892 else
9893 {
9894 if (mask & (1 << 15))
9895 inst.error = _("PC not allowed in register list");
3c707909
PB
9896 }
9897
9898 if ((mask & (mask - 1)) == 0)
9899 {
9900 /* Single register transfers implemented as str/ldr. */
9901 if (writeback)
9902 {
9903 if (inst.instruction & (1 << 23))
9904 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9905 else
9906 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9907 }
9908 else
9909 {
9910 if (inst.instruction & (1 << 23))
9911 inst.instruction = 0x00800000; /* ia -> [base] */
9912 else
9913 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9914 }
9915
9916 inst.instruction |= 0xf8400000;
9917 if (load)
9918 inst.instruction |= 0x00100000;
9919
5f4273c7 9920 mask = ffs (mask) - 1;
3c707909
PB
9921 mask <<= 12;
9922 }
9923 else if (writeback)
9924 inst.instruction |= WRITE_BACK;
9925
9926 inst.instruction |= mask;
9927 inst.instruction |= base << 16;
9928}
9929
c19d1205
ZW
9930static void
9931do_t_ldmstm (void)
9932{
9933 /* This really doesn't seem worth it. */
9934 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9935 _("expression too complex"));
9936 constraint (inst.operands[1].writeback,
9937 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9938
c19d1205
ZW
9939 if (unified_syntax)
9940 {
3c707909
PB
9941 bfd_boolean narrow;
9942 unsigned mask;
9943
9944 narrow = FALSE;
c19d1205
ZW
9945 /* See if we can use a 16-bit instruction. */
9946 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9947 && inst.size_req != 4
3c707909 9948 && !(inst.operands[1].imm & ~0xff))
90e4755a 9949 {
3c707909 9950 mask = 1 << inst.operands[0].reg;
90e4755a 9951
eab4f823 9952 if (inst.operands[0].reg <= 7)
90e4755a 9953 {
3c707909 9954 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
9955 ? inst.operands[0].writeback
9956 : (inst.operands[0].writeback
9957 == !(inst.operands[1].imm & mask)))
9958 {
9959 if (inst.instruction == T_MNEM_stmia
9960 && (inst.operands[1].imm & mask)
9961 && (inst.operands[1].imm & (mask - 1)))
9962 as_warn (_("value stored for r%d is UNKNOWN"),
9963 inst.operands[0].reg);
3c707909 9964
eab4f823
MGD
9965 inst.instruction = THUMB_OP16 (inst.instruction);
9966 inst.instruction |= inst.operands[0].reg << 8;
9967 inst.instruction |= inst.operands[1].imm;
9968 narrow = TRUE;
9969 }
9970 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
9971 {
9972 /* This means 1 register in reg list one of 3 situations:
9973 1. Instruction is stmia, but without writeback.
9974 2. lmdia without writeback, but with Rn not in
9975 reglist.
9976 3. ldmia with writeback, but with Rn in reglist.
9977 Case 3 is UNPREDICTABLE behaviour, so we handle
9978 case 1 and 2 which can be converted into a 16-bit
9979 str or ldr. The SP cases are handled below. */
9980 unsigned long opcode;
9981 /* First, record an error for Case 3. */
9982 if (inst.operands[1].imm & mask
9983 && inst.operands[0].writeback)
9984 inst.error =
9985 _("having the base register in the register list when "
9986 "using write back is UNPREDICTABLE");
9987
9988 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
9989 : T_MNEM_ldr);
9990 inst.instruction = THUMB_OP16 (opcode);
9991 inst.instruction |= inst.operands[0].reg << 3;
9992 inst.instruction |= (ffs (inst.operands[1].imm)-1);
9993 narrow = TRUE;
9994 }
90e4755a 9995 }
eab4f823 9996 else if (inst.operands[0] .reg == REG_SP)
90e4755a 9997 {
eab4f823
MGD
9998 if (inst.operands[0].writeback)
9999 {
10000 inst.instruction =
10001 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10002 ? T_MNEM_push : T_MNEM_pop);
10003 inst.instruction |= inst.operands[1].imm;
10004 narrow = TRUE;
10005 }
10006 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10007 {
10008 inst.instruction =
10009 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10010 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10011 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10012 narrow = TRUE;
10013 }
90e4755a 10014 }
3c707909
PB
10015 }
10016
10017 if (!narrow)
10018 {
c19d1205
ZW
10019 if (inst.instruction < 0xffff)
10020 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 10021
5f4273c7
NC
10022 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10023 inst.operands[0].writeback);
90e4755a
RE
10024 }
10025 }
c19d1205 10026 else
90e4755a 10027 {
c19d1205
ZW
10028 constraint (inst.operands[0].reg > 7
10029 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
10030 constraint (inst.instruction != T_MNEM_ldmia
10031 && inst.instruction != T_MNEM_stmia,
10032 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 10033 if (inst.instruction == T_MNEM_stmia)
f03698e6 10034 {
c19d1205
ZW
10035 if (!inst.operands[0].writeback)
10036 as_warn (_("this instruction will write back the base register"));
10037 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10038 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 10039 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 10040 inst.operands[0].reg);
f03698e6 10041 }
c19d1205 10042 else
90e4755a 10043 {
c19d1205
ZW
10044 if (!inst.operands[0].writeback
10045 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10046 as_warn (_("this instruction will write back the base register"));
10047 else if (inst.operands[0].writeback
10048 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10049 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
10050 }
10051
c19d1205
ZW
10052 inst.instruction = THUMB_OP16 (inst.instruction);
10053 inst.instruction |= inst.operands[0].reg << 8;
10054 inst.instruction |= inst.operands[1].imm;
10055 }
10056}
e28cd48c 10057
c19d1205
ZW
10058static void
10059do_t_ldrex (void)
10060{
10061 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10062 || inst.operands[1].postind || inst.operands[1].writeback
10063 || inst.operands[1].immisreg || inst.operands[1].shifted
10064 || inst.operands[1].negative,
01cfc07f 10065 BAD_ADDR_MODE);
e28cd48c 10066
5be8be5d
DG
10067 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10068
c19d1205
ZW
10069 inst.instruction |= inst.operands[0].reg << 12;
10070 inst.instruction |= inst.operands[1].reg << 16;
10071 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10072}
e28cd48c 10073
c19d1205
ZW
10074static void
10075do_t_ldrexd (void)
10076{
10077 if (!inst.operands[1].present)
1cac9012 10078 {
c19d1205
ZW
10079 constraint (inst.operands[0].reg == REG_LR,
10080 _("r14 not allowed as first register "
10081 "when second register is omitted"));
10082 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 10083 }
c19d1205
ZW
10084 constraint (inst.operands[0].reg == inst.operands[1].reg,
10085 BAD_OVERLAP);
b99bd4ef 10086
c19d1205
ZW
10087 inst.instruction |= inst.operands[0].reg << 12;
10088 inst.instruction |= inst.operands[1].reg << 8;
10089 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10090}
10091
10092static void
c19d1205 10093do_t_ldst (void)
b99bd4ef 10094{
0110f2b8
PB
10095 unsigned long opcode;
10096 int Rn;
10097
e07e6e58
NC
10098 if (inst.operands[0].isreg
10099 && !inst.operands[0].preind
10100 && inst.operands[0].reg == REG_PC)
10101 set_it_insn_type_last ();
10102
0110f2b8 10103 opcode = inst.instruction;
c19d1205 10104 if (unified_syntax)
b99bd4ef 10105 {
53365c0d
PB
10106 if (!inst.operands[1].isreg)
10107 {
10108 if (opcode <= 0xffff)
10109 inst.instruction = THUMB_OP32 (opcode);
10110 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10111 return;
10112 }
0110f2b8
PB
10113 if (inst.operands[1].isreg
10114 && !inst.operands[1].writeback
c19d1205
ZW
10115 && !inst.operands[1].shifted && !inst.operands[1].postind
10116 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
10117 && opcode <= 0xffff
10118 && inst.size_req != 4)
c19d1205 10119 {
0110f2b8
PB
10120 /* Insn may have a 16-bit form. */
10121 Rn = inst.operands[1].reg;
10122 if (inst.operands[1].immisreg)
10123 {
10124 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 10125 /* [Rn, Rik] */
0110f2b8
PB
10126 if (Rn <= 7 && inst.operands[1].imm <= 7)
10127 goto op16;
5be8be5d
DG
10128 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10129 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
10130 }
10131 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10132 && opcode != T_MNEM_ldrsb)
10133 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10134 || (Rn == REG_SP && opcode == T_MNEM_str))
10135 {
10136 /* [Rn, #const] */
10137 if (Rn > 7)
10138 {
10139 if (Rn == REG_PC)
10140 {
10141 if (inst.reloc.pc_rel)
10142 opcode = T_MNEM_ldr_pc2;
10143 else
10144 opcode = T_MNEM_ldr_pc;
10145 }
10146 else
10147 {
10148 if (opcode == T_MNEM_ldr)
10149 opcode = T_MNEM_ldr_sp;
10150 else
10151 opcode = T_MNEM_str_sp;
10152 }
10153 inst.instruction = inst.operands[0].reg << 8;
10154 }
10155 else
10156 {
10157 inst.instruction = inst.operands[0].reg;
10158 inst.instruction |= inst.operands[1].reg << 3;
10159 }
10160 inst.instruction |= THUMB_OP16 (opcode);
10161 if (inst.size_req == 2)
10162 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10163 else
10164 inst.relax = opcode;
10165 return;
10166 }
c19d1205 10167 }
0110f2b8 10168 /* Definitely a 32-bit variant. */
5be8be5d
DG
10169
10170 /* Do some validations regarding addressing modes. */
10171 if (inst.operands[1].immisreg && opcode != T_MNEM_ldr
10172 && opcode != T_MNEM_str)
10173 reject_bad_reg (inst.operands[1].imm);
10174
0110f2b8 10175 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
10176 inst.instruction |= inst.operands[0].reg << 12;
10177 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
10178 return;
10179 }
10180
c19d1205
ZW
10181 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10182
10183 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 10184 {
c19d1205
ZW
10185 /* Only [Rn,Rm] is acceptable. */
10186 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10187 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10188 || inst.operands[1].postind || inst.operands[1].shifted
10189 || inst.operands[1].negative,
10190 _("Thumb does not support this addressing mode"));
10191 inst.instruction = THUMB_OP16 (inst.instruction);
10192 goto op16;
b99bd4ef 10193 }
5f4273c7 10194
c19d1205
ZW
10195 inst.instruction = THUMB_OP16 (inst.instruction);
10196 if (!inst.operands[1].isreg)
10197 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10198 return;
b99bd4ef 10199
c19d1205
ZW
10200 constraint (!inst.operands[1].preind
10201 || inst.operands[1].shifted
10202 || inst.operands[1].writeback,
10203 _("Thumb does not support this addressing mode"));
10204 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 10205 {
c19d1205
ZW
10206 constraint (inst.instruction & 0x0600,
10207 _("byte or halfword not valid for base register"));
10208 constraint (inst.operands[1].reg == REG_PC
10209 && !(inst.instruction & THUMB_LOAD_BIT),
10210 _("r15 based store not allowed"));
10211 constraint (inst.operands[1].immisreg,
10212 _("invalid base register for register offset"));
b99bd4ef 10213
c19d1205
ZW
10214 if (inst.operands[1].reg == REG_PC)
10215 inst.instruction = T_OPCODE_LDR_PC;
10216 else if (inst.instruction & THUMB_LOAD_BIT)
10217 inst.instruction = T_OPCODE_LDR_SP;
10218 else
10219 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 10220
c19d1205
ZW
10221 inst.instruction |= inst.operands[0].reg << 8;
10222 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10223 return;
10224 }
90e4755a 10225
c19d1205
ZW
10226 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10227 if (!inst.operands[1].immisreg)
10228 {
10229 /* Immediate offset. */
10230 inst.instruction |= inst.operands[0].reg;
10231 inst.instruction |= inst.operands[1].reg << 3;
10232 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10233 return;
10234 }
90e4755a 10235
c19d1205
ZW
10236 /* Register offset. */
10237 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10238 constraint (inst.operands[1].negative,
10239 _("Thumb does not support this addressing mode"));
90e4755a 10240
c19d1205
ZW
10241 op16:
10242 switch (inst.instruction)
10243 {
10244 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10245 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10246 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10247 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10248 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10249 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10250 case 0x5600 /* ldrsb */:
10251 case 0x5e00 /* ldrsh */: break;
10252 default: abort ();
10253 }
90e4755a 10254
c19d1205
ZW
10255 inst.instruction |= inst.operands[0].reg;
10256 inst.instruction |= inst.operands[1].reg << 3;
10257 inst.instruction |= inst.operands[1].imm << 6;
10258}
90e4755a 10259
c19d1205
ZW
10260static void
10261do_t_ldstd (void)
10262{
10263 if (!inst.operands[1].present)
b99bd4ef 10264 {
c19d1205
ZW
10265 inst.operands[1].reg = inst.operands[0].reg + 1;
10266 constraint (inst.operands[0].reg == REG_LR,
10267 _("r14 not allowed here"));
b99bd4ef 10268 }
c19d1205
ZW
10269 inst.instruction |= inst.operands[0].reg << 12;
10270 inst.instruction |= inst.operands[1].reg << 8;
10271 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
10272}
10273
c19d1205
ZW
10274static void
10275do_t_ldstt (void)
10276{
10277 inst.instruction |= inst.operands[0].reg << 12;
10278 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10279}
a737bd4d 10280
b99bd4ef 10281static void
c19d1205 10282do_t_mla (void)
b99bd4ef 10283{
fdfde340 10284 unsigned Rd, Rn, Rm, Ra;
c921be7d 10285
fdfde340
JM
10286 Rd = inst.operands[0].reg;
10287 Rn = inst.operands[1].reg;
10288 Rm = inst.operands[2].reg;
10289 Ra = inst.operands[3].reg;
10290
10291 reject_bad_reg (Rd);
10292 reject_bad_reg (Rn);
10293 reject_bad_reg (Rm);
10294 reject_bad_reg (Ra);
10295
10296 inst.instruction |= Rd << 8;
10297 inst.instruction |= Rn << 16;
10298 inst.instruction |= Rm;
10299 inst.instruction |= Ra << 12;
c19d1205 10300}
b99bd4ef 10301
c19d1205
ZW
10302static void
10303do_t_mlal (void)
10304{
fdfde340
JM
10305 unsigned RdLo, RdHi, Rn, Rm;
10306
10307 RdLo = inst.operands[0].reg;
10308 RdHi = inst.operands[1].reg;
10309 Rn = inst.operands[2].reg;
10310 Rm = inst.operands[3].reg;
10311
10312 reject_bad_reg (RdLo);
10313 reject_bad_reg (RdHi);
10314 reject_bad_reg (Rn);
10315 reject_bad_reg (Rm);
10316
10317 inst.instruction |= RdLo << 12;
10318 inst.instruction |= RdHi << 8;
10319 inst.instruction |= Rn << 16;
10320 inst.instruction |= Rm;
c19d1205 10321}
b99bd4ef 10322
c19d1205
ZW
10323static void
10324do_t_mov_cmp (void)
10325{
fdfde340
JM
10326 unsigned Rn, Rm;
10327
10328 Rn = inst.operands[0].reg;
10329 Rm = inst.operands[1].reg;
10330
e07e6e58
NC
10331 if (Rn == REG_PC)
10332 set_it_insn_type_last ();
10333
c19d1205 10334 if (unified_syntax)
b99bd4ef 10335 {
c19d1205
ZW
10336 int r0off = (inst.instruction == T_MNEM_mov
10337 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 10338 unsigned long opcode;
3d388997
PB
10339 bfd_boolean narrow;
10340 bfd_boolean low_regs;
10341
fdfde340 10342 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 10343 opcode = inst.instruction;
e07e6e58 10344 if (in_it_block ())
0110f2b8 10345 narrow = opcode != T_MNEM_movs;
3d388997 10346 else
0110f2b8 10347 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
10348 if (inst.size_req == 4
10349 || inst.operands[1].shifted)
10350 narrow = FALSE;
10351
efd81785
PB
10352 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10353 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10354 && !inst.operands[1].shifted
fdfde340
JM
10355 && Rn == REG_PC
10356 && Rm == REG_LR)
efd81785
PB
10357 {
10358 inst.instruction = T2_SUBS_PC_LR;
10359 return;
10360 }
10361
fdfde340
JM
10362 if (opcode == T_MNEM_cmp)
10363 {
10364 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
10365 if (narrow)
10366 {
10367 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10368 but valid. */
10369 warn_deprecated_sp (Rm);
10370 /* R15 was documented as a valid choice for Rm in ARMv6,
10371 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10372 tools reject R15, so we do too. */
10373 constraint (Rm == REG_PC, BAD_PC);
10374 }
10375 else
10376 reject_bad_reg (Rm);
fdfde340
JM
10377 }
10378 else if (opcode == T_MNEM_mov
10379 || opcode == T_MNEM_movs)
10380 {
10381 if (inst.operands[1].isreg)
10382 {
10383 if (opcode == T_MNEM_movs)
10384 {
10385 reject_bad_reg (Rn);
10386 reject_bad_reg (Rm);
10387 }
76fa04a4
MGD
10388 else if (narrow)
10389 {
10390 /* This is mov.n. */
10391 if ((Rn == REG_SP || Rn == REG_PC)
10392 && (Rm == REG_SP || Rm == REG_PC))
10393 {
10394 as_warn (_("Use of r%u as a source register is "
10395 "deprecated when r%u is the destination "
10396 "register."), Rm, Rn);
10397 }
10398 }
10399 else
10400 {
10401 /* This is mov.w. */
10402 constraint (Rn == REG_PC, BAD_PC);
10403 constraint (Rm == REG_PC, BAD_PC);
10404 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
10405 }
fdfde340
JM
10406 }
10407 else
10408 reject_bad_reg (Rn);
10409 }
10410
c19d1205
ZW
10411 if (!inst.operands[1].isreg)
10412 {
0110f2b8 10413 /* Immediate operand. */
e07e6e58 10414 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
10415 narrow = 0;
10416 if (low_regs && narrow)
10417 {
10418 inst.instruction = THUMB_OP16 (opcode);
fdfde340 10419 inst.instruction |= Rn << 8;
0110f2b8
PB
10420 if (inst.size_req == 2)
10421 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10422 else
10423 inst.relax = opcode;
10424 }
10425 else
10426 {
10427 inst.instruction = THUMB_OP32 (inst.instruction);
10428 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10429 inst.instruction |= Rn << r0off;
0110f2b8
PB
10430 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10431 }
c19d1205 10432 }
728ca7c9
PB
10433 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10434 && (inst.instruction == T_MNEM_mov
10435 || inst.instruction == T_MNEM_movs))
10436 {
10437 /* Register shifts are encoded as separate shift instructions. */
10438 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10439
e07e6e58 10440 if (in_it_block ())
728ca7c9
PB
10441 narrow = !flags;
10442 else
10443 narrow = flags;
10444
10445 if (inst.size_req == 4)
10446 narrow = FALSE;
10447
10448 if (!low_regs || inst.operands[1].imm > 7)
10449 narrow = FALSE;
10450
fdfde340 10451 if (Rn != Rm)
728ca7c9
PB
10452 narrow = FALSE;
10453
10454 switch (inst.operands[1].shift_kind)
10455 {
10456 case SHIFT_LSL:
10457 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10458 break;
10459 case SHIFT_ASR:
10460 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10461 break;
10462 case SHIFT_LSR:
10463 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10464 break;
10465 case SHIFT_ROR:
10466 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10467 break;
10468 default:
5f4273c7 10469 abort ();
728ca7c9
PB
10470 }
10471
10472 inst.instruction = opcode;
10473 if (narrow)
10474 {
fdfde340 10475 inst.instruction |= Rn;
728ca7c9
PB
10476 inst.instruction |= inst.operands[1].imm << 3;
10477 }
10478 else
10479 {
10480 if (flags)
10481 inst.instruction |= CONDS_BIT;
10482
fdfde340
JM
10483 inst.instruction |= Rn << 8;
10484 inst.instruction |= Rm << 16;
728ca7c9
PB
10485 inst.instruction |= inst.operands[1].imm;
10486 }
10487 }
3d388997 10488 else if (!narrow)
c19d1205 10489 {
728ca7c9
PB
10490 /* Some mov with immediate shift have narrow variants.
10491 Register shifts are handled above. */
10492 if (low_regs && inst.operands[1].shifted
10493 && (inst.instruction == T_MNEM_mov
10494 || inst.instruction == T_MNEM_movs))
10495 {
e07e6e58 10496 if (in_it_block ())
728ca7c9
PB
10497 narrow = (inst.instruction == T_MNEM_mov);
10498 else
10499 narrow = (inst.instruction == T_MNEM_movs);
10500 }
10501
10502 if (narrow)
10503 {
10504 switch (inst.operands[1].shift_kind)
10505 {
10506 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10507 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10508 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10509 default: narrow = FALSE; break;
10510 }
10511 }
10512
10513 if (narrow)
10514 {
fdfde340
JM
10515 inst.instruction |= Rn;
10516 inst.instruction |= Rm << 3;
728ca7c9
PB
10517 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10518 }
10519 else
10520 {
10521 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10522 inst.instruction |= Rn << r0off;
728ca7c9
PB
10523 encode_thumb32_shifted_operand (1);
10524 }
c19d1205
ZW
10525 }
10526 else
10527 switch (inst.instruction)
10528 {
10529 case T_MNEM_mov:
10530 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
10531 inst.instruction |= (Rn & 0x8) << 4;
10532 inst.instruction |= (Rn & 0x7);
10533 inst.instruction |= Rm << 3;
c19d1205 10534 break;
b99bd4ef 10535
c19d1205
ZW
10536 case T_MNEM_movs:
10537 /* We know we have low registers at this point.
941a8a52
MGD
10538 Generate LSLS Rd, Rs, #0. */
10539 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
10540 inst.instruction |= Rn;
10541 inst.instruction |= Rm << 3;
c19d1205
ZW
10542 break;
10543
10544 case T_MNEM_cmp:
3d388997 10545 if (low_regs)
c19d1205
ZW
10546 {
10547 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
10548 inst.instruction |= Rn;
10549 inst.instruction |= Rm << 3;
c19d1205
ZW
10550 }
10551 else
10552 {
10553 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
10554 inst.instruction |= (Rn & 0x8) << 4;
10555 inst.instruction |= (Rn & 0x7);
10556 inst.instruction |= Rm << 3;
c19d1205
ZW
10557 }
10558 break;
10559 }
b99bd4ef
NC
10560 return;
10561 }
10562
c19d1205 10563 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
10564
10565 /* PR 10443: Do not silently ignore shifted operands. */
10566 constraint (inst.operands[1].shifted,
10567 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10568
c19d1205 10569 if (inst.operands[1].isreg)
b99bd4ef 10570 {
fdfde340 10571 if (Rn < 8 && Rm < 8)
b99bd4ef 10572 {
c19d1205
ZW
10573 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10574 since a MOV instruction produces unpredictable results. */
10575 if (inst.instruction == T_OPCODE_MOV_I8)
10576 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 10577 else
c19d1205 10578 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 10579
fdfde340
JM
10580 inst.instruction |= Rn;
10581 inst.instruction |= Rm << 3;
b99bd4ef
NC
10582 }
10583 else
10584 {
c19d1205
ZW
10585 if (inst.instruction == T_OPCODE_MOV_I8)
10586 inst.instruction = T_OPCODE_MOV_HR;
10587 else
10588 inst.instruction = T_OPCODE_CMP_HR;
10589 do_t_cpy ();
b99bd4ef
NC
10590 }
10591 }
c19d1205 10592 else
b99bd4ef 10593 {
fdfde340 10594 constraint (Rn > 7,
c19d1205 10595 _("only lo regs allowed with immediate"));
fdfde340 10596 inst.instruction |= Rn << 8;
c19d1205
ZW
10597 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10598 }
10599}
b99bd4ef 10600
c19d1205
ZW
10601static void
10602do_t_mov16 (void)
10603{
fdfde340 10604 unsigned Rd;
b6895b4f
PB
10605 bfd_vma imm;
10606 bfd_boolean top;
10607
10608 top = (inst.instruction & 0x00800000) != 0;
10609 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10610 {
10611 constraint (top, _(":lower16: not allowed this instruction"));
10612 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10613 }
10614 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10615 {
10616 constraint (!top, _(":upper16: not allowed this instruction"));
10617 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10618 }
10619
fdfde340
JM
10620 Rd = inst.operands[0].reg;
10621 reject_bad_reg (Rd);
10622
10623 inst.instruction |= Rd << 8;
b6895b4f
PB
10624 if (inst.reloc.type == BFD_RELOC_UNUSED)
10625 {
10626 imm = inst.reloc.exp.X_add_number;
10627 inst.instruction |= (imm & 0xf000) << 4;
10628 inst.instruction |= (imm & 0x0800) << 15;
10629 inst.instruction |= (imm & 0x0700) << 4;
10630 inst.instruction |= (imm & 0x00ff);
10631 }
c19d1205 10632}
b99bd4ef 10633
c19d1205
ZW
10634static void
10635do_t_mvn_tst (void)
10636{
fdfde340 10637 unsigned Rn, Rm;
c921be7d 10638
fdfde340
JM
10639 Rn = inst.operands[0].reg;
10640 Rm = inst.operands[1].reg;
10641
10642 if (inst.instruction == T_MNEM_cmp
10643 || inst.instruction == T_MNEM_cmn)
10644 constraint (Rn == REG_PC, BAD_PC);
10645 else
10646 reject_bad_reg (Rn);
10647 reject_bad_reg (Rm);
10648
c19d1205
ZW
10649 if (unified_syntax)
10650 {
10651 int r0off = (inst.instruction == T_MNEM_mvn
10652 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
10653 bfd_boolean narrow;
10654
10655 if (inst.size_req == 4
10656 || inst.instruction > 0xffff
10657 || inst.operands[1].shifted
fdfde340 10658 || Rn > 7 || Rm > 7)
3d388997
PB
10659 narrow = FALSE;
10660 else if (inst.instruction == T_MNEM_cmn)
10661 narrow = TRUE;
10662 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10663 narrow = !in_it_block ();
3d388997 10664 else
e07e6e58 10665 narrow = in_it_block ();
3d388997 10666
c19d1205 10667 if (!inst.operands[1].isreg)
b99bd4ef 10668 {
c19d1205
ZW
10669 /* For an immediate, we always generate a 32-bit opcode;
10670 section relaxation will shrink it later if possible. */
10671 if (inst.instruction < 0xffff)
10672 inst.instruction = THUMB_OP32 (inst.instruction);
10673 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10674 inst.instruction |= Rn << r0off;
c19d1205 10675 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10676 }
c19d1205 10677 else
b99bd4ef 10678 {
c19d1205 10679 /* See if we can do this with a 16-bit instruction. */
3d388997 10680 if (narrow)
b99bd4ef 10681 {
c19d1205 10682 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10683 inst.instruction |= Rn;
10684 inst.instruction |= Rm << 3;
b99bd4ef 10685 }
c19d1205 10686 else
b99bd4ef 10687 {
c19d1205
ZW
10688 constraint (inst.operands[1].shifted
10689 && inst.operands[1].immisreg,
10690 _("shift must be constant"));
10691 if (inst.instruction < 0xffff)
10692 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10693 inst.instruction |= Rn << r0off;
c19d1205 10694 encode_thumb32_shifted_operand (1);
b99bd4ef 10695 }
b99bd4ef
NC
10696 }
10697 }
10698 else
10699 {
c19d1205
ZW
10700 constraint (inst.instruction > 0xffff
10701 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10702 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10703 _("unshifted register required"));
fdfde340 10704 constraint (Rn > 7 || Rm > 7,
c19d1205 10705 BAD_HIREG);
b99bd4ef 10706
c19d1205 10707 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10708 inst.instruction |= Rn;
10709 inst.instruction |= Rm << 3;
b99bd4ef 10710 }
b99bd4ef
NC
10711}
10712
b05fe5cf 10713static void
c19d1205 10714do_t_mrs (void)
b05fe5cf 10715{
fdfde340 10716 unsigned Rd;
62b3e311 10717 int flags;
037e8744
JB
10718
10719 if (do_vfp_nsyn_mrs () == SUCCESS)
10720 return;
10721
62b3e311
PB
10722 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10723 if (flags == 0)
10724 {
7e806470 10725 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10726 _("selected processor does not support "
10727 "requested special purpose register"));
10728 }
10729 else
10730 {
10731 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10732 _("selected processor does not support "
44bf2362 10733 "requested special purpose register"));
62b3e311
PB
10734 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10735 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10736 _("'CPSR' or 'SPSR' expected"));
10737 }
5f4273c7 10738
fdfde340
JM
10739 Rd = inst.operands[0].reg;
10740 reject_bad_reg (Rd);
10741
10742 inst.instruction |= Rd << 8;
62b3e311
PB
10743 inst.instruction |= (flags & SPSR_BIT) >> 2;
10744 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 10745}
b05fe5cf 10746
c19d1205
ZW
10747static void
10748do_t_msr (void)
10749{
62b3e311 10750 int flags;
fdfde340 10751 unsigned Rn;
62b3e311 10752
037e8744
JB
10753 if (do_vfp_nsyn_msr () == SUCCESS)
10754 return;
10755
c19d1205
ZW
10756 constraint (!inst.operands[1].isreg,
10757 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
10758 flags = inst.operands[0].imm;
10759 if (flags & ~0xff)
10760 {
10761 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10762 _("selected processor does not support "
10763 "requested special purpose register"));
10764 }
10765 else
10766 {
7e806470 10767 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10768 _("selected processor does not support "
10769 "requested special purpose register"));
10770 flags |= PSR_f;
10771 }
c921be7d 10772
fdfde340
JM
10773 Rn = inst.operands[1].reg;
10774 reject_bad_reg (Rn);
10775
62b3e311
PB
10776 inst.instruction |= (flags & SPSR_BIT) >> 2;
10777 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10778 inst.instruction |= (flags & 0xff);
fdfde340 10779 inst.instruction |= Rn << 16;
c19d1205 10780}
b05fe5cf 10781
c19d1205
ZW
10782static void
10783do_t_mul (void)
10784{
17828f45 10785 bfd_boolean narrow;
fdfde340 10786 unsigned Rd, Rn, Rm;
17828f45 10787
c19d1205
ZW
10788 if (!inst.operands[2].present)
10789 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 10790
fdfde340
JM
10791 Rd = inst.operands[0].reg;
10792 Rn = inst.operands[1].reg;
10793 Rm = inst.operands[2].reg;
10794
17828f45 10795 if (unified_syntax)
b05fe5cf 10796 {
17828f45 10797 if (inst.size_req == 4
fdfde340
JM
10798 || (Rd != Rn
10799 && Rd != Rm)
10800 || Rn > 7
10801 || Rm > 7)
17828f45
JM
10802 narrow = FALSE;
10803 else if (inst.instruction == T_MNEM_muls)
e07e6e58 10804 narrow = !in_it_block ();
17828f45 10805 else
e07e6e58 10806 narrow = in_it_block ();
b05fe5cf 10807 }
c19d1205 10808 else
b05fe5cf 10809 {
17828f45 10810 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 10811 constraint (Rn > 7 || Rm > 7,
c19d1205 10812 BAD_HIREG);
17828f45
JM
10813 narrow = TRUE;
10814 }
b05fe5cf 10815
17828f45
JM
10816 if (narrow)
10817 {
10818 /* 16-bit MULS/Conditional MUL. */
c19d1205 10819 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10820 inst.instruction |= Rd;
b05fe5cf 10821
fdfde340
JM
10822 if (Rd == Rn)
10823 inst.instruction |= Rm << 3;
10824 else if (Rd == Rm)
10825 inst.instruction |= Rn << 3;
c19d1205
ZW
10826 else
10827 constraint (1, _("dest must overlap one source register"));
10828 }
17828f45
JM
10829 else
10830 {
e07e6e58
NC
10831 constraint (inst.instruction != T_MNEM_mul,
10832 _("Thumb-2 MUL must not set flags"));
17828f45
JM
10833 /* 32-bit MUL. */
10834 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10835 inst.instruction |= Rd << 8;
10836 inst.instruction |= Rn << 16;
10837 inst.instruction |= Rm << 0;
10838
10839 reject_bad_reg (Rd);
10840 reject_bad_reg (Rn);
10841 reject_bad_reg (Rm);
17828f45 10842 }
c19d1205 10843}
b05fe5cf 10844
c19d1205
ZW
10845static void
10846do_t_mull (void)
10847{
fdfde340 10848 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 10849
fdfde340
JM
10850 RdLo = inst.operands[0].reg;
10851 RdHi = inst.operands[1].reg;
10852 Rn = inst.operands[2].reg;
10853 Rm = inst.operands[3].reg;
10854
10855 reject_bad_reg (RdLo);
10856 reject_bad_reg (RdHi);
10857 reject_bad_reg (Rn);
10858 reject_bad_reg (Rm);
10859
10860 inst.instruction |= RdLo << 12;
10861 inst.instruction |= RdHi << 8;
10862 inst.instruction |= Rn << 16;
10863 inst.instruction |= Rm;
10864
10865 if (RdLo == RdHi)
c19d1205
ZW
10866 as_tsktsk (_("rdhi and rdlo must be different"));
10867}
b05fe5cf 10868
c19d1205
ZW
10869static void
10870do_t_nop (void)
10871{
e07e6e58
NC
10872 set_it_insn_type (NEUTRAL_IT_INSN);
10873
c19d1205
ZW
10874 if (unified_syntax)
10875 {
10876 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 10877 {
c19d1205
ZW
10878 inst.instruction = THUMB_OP32 (inst.instruction);
10879 inst.instruction |= inst.operands[0].imm;
10880 }
10881 else
10882 {
bc2d1808
NC
10883 /* PR9722: Check for Thumb2 availability before
10884 generating a thumb2 nop instruction. */
afa62d5e 10885 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
10886 {
10887 inst.instruction = THUMB_OP16 (inst.instruction);
10888 inst.instruction |= inst.operands[0].imm << 4;
10889 }
10890 else
10891 inst.instruction = 0x46c0;
c19d1205
ZW
10892 }
10893 }
10894 else
10895 {
10896 constraint (inst.operands[0].present,
10897 _("Thumb does not support NOP with hints"));
10898 inst.instruction = 0x46c0;
10899 }
10900}
b05fe5cf 10901
c19d1205
ZW
10902static void
10903do_t_neg (void)
10904{
10905 if (unified_syntax)
10906 {
3d388997
PB
10907 bfd_boolean narrow;
10908
10909 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10910 narrow = !in_it_block ();
3d388997 10911 else
e07e6e58 10912 narrow = in_it_block ();
3d388997
PB
10913 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10914 narrow = FALSE;
10915 if (inst.size_req == 4)
10916 narrow = FALSE;
10917
10918 if (!narrow)
c19d1205
ZW
10919 {
10920 inst.instruction = THUMB_OP32 (inst.instruction);
10921 inst.instruction |= inst.operands[0].reg << 8;
10922 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
10923 }
10924 else
10925 {
c19d1205
ZW
10926 inst.instruction = THUMB_OP16 (inst.instruction);
10927 inst.instruction |= inst.operands[0].reg;
10928 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
10929 }
10930 }
10931 else
10932 {
c19d1205
ZW
10933 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10934 BAD_HIREG);
10935 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10936
10937 inst.instruction = THUMB_OP16 (inst.instruction);
10938 inst.instruction |= inst.operands[0].reg;
10939 inst.instruction |= inst.operands[1].reg << 3;
10940 }
10941}
10942
1c444d06
JM
10943static void
10944do_t_orn (void)
10945{
10946 unsigned Rd, Rn;
10947
10948 Rd = inst.operands[0].reg;
10949 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10950
fdfde340
JM
10951 reject_bad_reg (Rd);
10952 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10953 reject_bad_reg (Rn);
10954
1c444d06
JM
10955 inst.instruction |= Rd << 8;
10956 inst.instruction |= Rn << 16;
10957
10958 if (!inst.operands[2].isreg)
10959 {
10960 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10961 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10962 }
10963 else
10964 {
10965 unsigned Rm;
10966
10967 Rm = inst.operands[2].reg;
fdfde340 10968 reject_bad_reg (Rm);
1c444d06
JM
10969
10970 constraint (inst.operands[2].shifted
10971 && inst.operands[2].immisreg,
10972 _("shift must be constant"));
10973 encode_thumb32_shifted_operand (2);
10974 }
10975}
10976
c19d1205
ZW
10977static void
10978do_t_pkhbt (void)
10979{
fdfde340
JM
10980 unsigned Rd, Rn, Rm;
10981
10982 Rd = inst.operands[0].reg;
10983 Rn = inst.operands[1].reg;
10984 Rm = inst.operands[2].reg;
10985
10986 reject_bad_reg (Rd);
10987 reject_bad_reg (Rn);
10988 reject_bad_reg (Rm);
10989
10990 inst.instruction |= Rd << 8;
10991 inst.instruction |= Rn << 16;
10992 inst.instruction |= Rm;
c19d1205
ZW
10993 if (inst.operands[3].present)
10994 {
10995 unsigned int val = inst.reloc.exp.X_add_number;
10996 constraint (inst.reloc.exp.X_op != O_constant,
10997 _("expression too complex"));
10998 inst.instruction |= (val & 0x1c) << 10;
10999 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 11000 }
c19d1205 11001}
b05fe5cf 11002
c19d1205
ZW
11003static void
11004do_t_pkhtb (void)
11005{
11006 if (!inst.operands[3].present)
1ef52f49
NC
11007 {
11008 unsigned Rtmp;
11009
11010 inst.instruction &= ~0x00000020;
11011
11012 /* PR 10168. Swap the Rm and Rn registers. */
11013 Rtmp = inst.operands[1].reg;
11014 inst.operands[1].reg = inst.operands[2].reg;
11015 inst.operands[2].reg = Rtmp;
11016 }
c19d1205 11017 do_t_pkhbt ();
b05fe5cf
ZW
11018}
11019
c19d1205
ZW
11020static void
11021do_t_pld (void)
11022{
fdfde340
JM
11023 if (inst.operands[0].immisreg)
11024 reject_bad_reg (inst.operands[0].imm);
11025
c19d1205
ZW
11026 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11027}
b05fe5cf 11028
c19d1205
ZW
11029static void
11030do_t_push_pop (void)
b99bd4ef 11031{
e9f89963 11032 unsigned mask;
5f4273c7 11033
c19d1205
ZW
11034 constraint (inst.operands[0].writeback,
11035 _("push/pop do not support {reglist}^"));
11036 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11037 _("expression too complex"));
b99bd4ef 11038
e9f89963
PB
11039 mask = inst.operands[0].imm;
11040 if ((mask & ~0xff) == 0)
3c707909 11041 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 11042 else if ((inst.instruction == T_MNEM_push
e9f89963 11043 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 11044 || (inst.instruction == T_MNEM_pop
e9f89963 11045 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 11046 {
c19d1205
ZW
11047 inst.instruction = THUMB_OP16 (inst.instruction);
11048 inst.instruction |= THUMB_PP_PC_LR;
3c707909 11049 inst.instruction |= mask & 0xff;
c19d1205
ZW
11050 }
11051 else if (unified_syntax)
11052 {
3c707909 11053 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 11054 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
11055 }
11056 else
11057 {
11058 inst.error = _("invalid register list to push/pop instruction");
11059 return;
11060 }
c19d1205 11061}
b99bd4ef 11062
c19d1205
ZW
11063static void
11064do_t_rbit (void)
11065{
fdfde340
JM
11066 unsigned Rd, Rm;
11067
11068 Rd = inst.operands[0].reg;
11069 Rm = inst.operands[1].reg;
11070
11071 reject_bad_reg (Rd);
11072 reject_bad_reg (Rm);
11073
11074 inst.instruction |= Rd << 8;
11075 inst.instruction |= Rm << 16;
11076 inst.instruction |= Rm;
c19d1205 11077}
b99bd4ef 11078
c19d1205
ZW
11079static void
11080do_t_rev (void)
11081{
fdfde340
JM
11082 unsigned Rd, Rm;
11083
11084 Rd = inst.operands[0].reg;
11085 Rm = inst.operands[1].reg;
11086
11087 reject_bad_reg (Rd);
11088 reject_bad_reg (Rm);
11089
11090 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
11091 && inst.size_req != 4)
11092 {
11093 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11094 inst.instruction |= Rd;
11095 inst.instruction |= Rm << 3;
c19d1205
ZW
11096 }
11097 else if (unified_syntax)
11098 {
11099 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11100 inst.instruction |= Rd << 8;
11101 inst.instruction |= Rm << 16;
11102 inst.instruction |= Rm;
c19d1205
ZW
11103 }
11104 else
11105 inst.error = BAD_HIREG;
11106}
b99bd4ef 11107
1c444d06
JM
11108static void
11109do_t_rrx (void)
11110{
11111 unsigned Rd, Rm;
11112
11113 Rd = inst.operands[0].reg;
11114 Rm = inst.operands[1].reg;
11115
fdfde340
JM
11116 reject_bad_reg (Rd);
11117 reject_bad_reg (Rm);
c921be7d 11118
1c444d06
JM
11119 inst.instruction |= Rd << 8;
11120 inst.instruction |= Rm;
11121}
11122
c19d1205
ZW
11123static void
11124do_t_rsb (void)
11125{
fdfde340 11126 unsigned Rd, Rs;
b99bd4ef 11127
c19d1205
ZW
11128 Rd = inst.operands[0].reg;
11129 Rs = (inst.operands[1].present
11130 ? inst.operands[1].reg /* Rd, Rs, foo */
11131 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 11132
fdfde340
JM
11133 reject_bad_reg (Rd);
11134 reject_bad_reg (Rs);
11135 if (inst.operands[2].isreg)
11136 reject_bad_reg (inst.operands[2].reg);
11137
c19d1205
ZW
11138 inst.instruction |= Rd << 8;
11139 inst.instruction |= Rs << 16;
11140 if (!inst.operands[2].isreg)
11141 {
026d3abb
PB
11142 bfd_boolean narrow;
11143
11144 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 11145 narrow = !in_it_block ();
026d3abb 11146 else
e07e6e58 11147 narrow = in_it_block ();
026d3abb
PB
11148
11149 if (Rd > 7 || Rs > 7)
11150 narrow = FALSE;
11151
11152 if (inst.size_req == 4 || !unified_syntax)
11153 narrow = FALSE;
11154
11155 if (inst.reloc.exp.X_op != O_constant
11156 || inst.reloc.exp.X_add_number != 0)
11157 narrow = FALSE;
11158
11159 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11160 relaxation, but it doesn't seem worth the hassle. */
11161 if (narrow)
11162 {
11163 inst.reloc.type = BFD_RELOC_UNUSED;
11164 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11165 inst.instruction |= Rs << 3;
11166 inst.instruction |= Rd;
11167 }
11168 else
11169 {
11170 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11171 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11172 }
c19d1205
ZW
11173 }
11174 else
11175 encode_thumb32_shifted_operand (2);
11176}
b99bd4ef 11177
c19d1205
ZW
11178static void
11179do_t_setend (void)
11180{
e07e6e58 11181 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11182 if (inst.operands[0].imm)
11183 inst.instruction |= 0x8;
11184}
b99bd4ef 11185
c19d1205
ZW
11186static void
11187do_t_shift (void)
11188{
11189 if (!inst.operands[1].present)
11190 inst.operands[1].reg = inst.operands[0].reg;
11191
11192 if (unified_syntax)
11193 {
3d388997
PB
11194 bfd_boolean narrow;
11195 int shift_kind;
11196
11197 switch (inst.instruction)
11198 {
11199 case T_MNEM_asr:
11200 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11201 case T_MNEM_lsl:
11202 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11203 case T_MNEM_lsr:
11204 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11205 case T_MNEM_ror:
11206 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11207 default: abort ();
11208 }
11209
11210 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11211 narrow = !in_it_block ();
3d388997 11212 else
e07e6e58 11213 narrow = in_it_block ();
3d388997
PB
11214 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11215 narrow = FALSE;
11216 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11217 narrow = FALSE;
11218 if (inst.operands[2].isreg
11219 && (inst.operands[1].reg != inst.operands[0].reg
11220 || inst.operands[2].reg > 7))
11221 narrow = FALSE;
11222 if (inst.size_req == 4)
11223 narrow = FALSE;
11224
fdfde340
JM
11225 reject_bad_reg (inst.operands[0].reg);
11226 reject_bad_reg (inst.operands[1].reg);
c921be7d 11227
3d388997 11228 if (!narrow)
c19d1205
ZW
11229 {
11230 if (inst.operands[2].isreg)
b99bd4ef 11231 {
fdfde340 11232 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
11233 inst.instruction = THUMB_OP32 (inst.instruction);
11234 inst.instruction |= inst.operands[0].reg << 8;
11235 inst.instruction |= inst.operands[1].reg << 16;
11236 inst.instruction |= inst.operands[2].reg;
11237 }
11238 else
11239 {
11240 inst.operands[1].shifted = 1;
3d388997 11241 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
11242 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11243 ? T_MNEM_movs : T_MNEM_mov);
11244 inst.instruction |= inst.operands[0].reg << 8;
11245 encode_thumb32_shifted_operand (1);
11246 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11247 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
11248 }
11249 }
11250 else
11251 {
c19d1205 11252 if (inst.operands[2].isreg)
b99bd4ef 11253 {
3d388997 11254 switch (shift_kind)
b99bd4ef 11255 {
3d388997
PB
11256 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11257 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11258 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11259 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 11260 default: abort ();
b99bd4ef 11261 }
5f4273c7 11262
c19d1205
ZW
11263 inst.instruction |= inst.operands[0].reg;
11264 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
11265 }
11266 else
11267 {
3d388997 11268 switch (shift_kind)
b99bd4ef 11269 {
3d388997
PB
11270 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11271 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11272 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 11273 default: abort ();
b99bd4ef 11274 }
c19d1205
ZW
11275 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11276 inst.instruction |= inst.operands[0].reg;
11277 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11278 }
11279 }
c19d1205
ZW
11280 }
11281 else
11282 {
11283 constraint (inst.operands[0].reg > 7
11284 || inst.operands[1].reg > 7, BAD_HIREG);
11285 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 11286
c19d1205
ZW
11287 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11288 {
11289 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11290 constraint (inst.operands[0].reg != inst.operands[1].reg,
11291 _("source1 and dest must be same register"));
b99bd4ef 11292
c19d1205
ZW
11293 switch (inst.instruction)
11294 {
11295 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11296 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11297 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11298 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11299 default: abort ();
11300 }
5f4273c7 11301
c19d1205
ZW
11302 inst.instruction |= inst.operands[0].reg;
11303 inst.instruction |= inst.operands[2].reg << 3;
11304 }
11305 else
b99bd4ef 11306 {
c19d1205
ZW
11307 switch (inst.instruction)
11308 {
11309 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11310 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11311 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11312 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11313 default: abort ();
11314 }
11315 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11316 inst.instruction |= inst.operands[0].reg;
11317 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11318 }
11319 }
b99bd4ef
NC
11320}
11321
11322static void
c19d1205 11323do_t_simd (void)
b99bd4ef 11324{
fdfde340
JM
11325 unsigned Rd, Rn, Rm;
11326
11327 Rd = inst.operands[0].reg;
11328 Rn = inst.operands[1].reg;
11329 Rm = inst.operands[2].reg;
11330
11331 reject_bad_reg (Rd);
11332 reject_bad_reg (Rn);
11333 reject_bad_reg (Rm);
11334
11335 inst.instruction |= Rd << 8;
11336 inst.instruction |= Rn << 16;
11337 inst.instruction |= Rm;
c19d1205 11338}
b99bd4ef 11339
03ee1b7f
NC
11340static void
11341do_t_simd2 (void)
11342{
11343 unsigned Rd, Rn, Rm;
11344
11345 Rd = inst.operands[0].reg;
11346 Rm = inst.operands[1].reg;
11347 Rn = inst.operands[2].reg;
11348
11349 reject_bad_reg (Rd);
11350 reject_bad_reg (Rn);
11351 reject_bad_reg (Rm);
11352
11353 inst.instruction |= Rd << 8;
11354 inst.instruction |= Rn << 16;
11355 inst.instruction |= Rm;
11356}
11357
c19d1205 11358static void
3eb17e6b 11359do_t_smc (void)
c19d1205
ZW
11360{
11361 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
11362 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
11363 _("SMC is not permitted on this architecture"));
c19d1205
ZW
11364 constraint (inst.reloc.exp.X_op != O_constant,
11365 _("expression too complex"));
11366 inst.reloc.type = BFD_RELOC_UNUSED;
11367 inst.instruction |= (value & 0xf000) >> 12;
11368 inst.instruction |= (value & 0x0ff0);
11369 inst.instruction |= (value & 0x000f) << 16;
11370}
b99bd4ef 11371
c19d1205 11372static void
3a21c15a 11373do_t_ssat_usat (int bias)
c19d1205 11374{
fdfde340
JM
11375 unsigned Rd, Rn;
11376
11377 Rd = inst.operands[0].reg;
11378 Rn = inst.operands[2].reg;
11379
11380 reject_bad_reg (Rd);
11381 reject_bad_reg (Rn);
11382
11383 inst.instruction |= Rd << 8;
3a21c15a 11384 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 11385 inst.instruction |= Rn << 16;
b99bd4ef 11386
c19d1205 11387 if (inst.operands[3].present)
b99bd4ef 11388 {
3a21c15a
NC
11389 offsetT shift_amount = inst.reloc.exp.X_add_number;
11390
11391 inst.reloc.type = BFD_RELOC_UNUSED;
11392
c19d1205
ZW
11393 constraint (inst.reloc.exp.X_op != O_constant,
11394 _("expression too complex"));
b99bd4ef 11395
3a21c15a 11396 if (shift_amount != 0)
6189168b 11397 {
3a21c15a
NC
11398 constraint (shift_amount > 31,
11399 _("shift expression is too large"));
11400
c19d1205 11401 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
11402 inst.instruction |= 0x00200000; /* sh bit. */
11403
11404 inst.instruction |= (shift_amount & 0x1c) << 10;
11405 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
11406 }
11407 }
b99bd4ef 11408}
c921be7d 11409
3a21c15a
NC
11410static void
11411do_t_ssat (void)
11412{
11413 do_t_ssat_usat (1);
11414}
b99bd4ef 11415
0dd132b6 11416static void
c19d1205 11417do_t_ssat16 (void)
0dd132b6 11418{
fdfde340
JM
11419 unsigned Rd, Rn;
11420
11421 Rd = inst.operands[0].reg;
11422 Rn = inst.operands[2].reg;
11423
11424 reject_bad_reg (Rd);
11425 reject_bad_reg (Rn);
11426
11427 inst.instruction |= Rd << 8;
c19d1205 11428 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 11429 inst.instruction |= Rn << 16;
c19d1205 11430}
0dd132b6 11431
c19d1205
ZW
11432static void
11433do_t_strex (void)
11434{
11435 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11436 || inst.operands[2].postind || inst.operands[2].writeback
11437 || inst.operands[2].immisreg || inst.operands[2].shifted
11438 || inst.operands[2].negative,
01cfc07f 11439 BAD_ADDR_MODE);
0dd132b6 11440
5be8be5d
DG
11441 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11442
c19d1205
ZW
11443 inst.instruction |= inst.operands[0].reg << 8;
11444 inst.instruction |= inst.operands[1].reg << 12;
11445 inst.instruction |= inst.operands[2].reg << 16;
11446 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
11447}
11448
b99bd4ef 11449static void
c19d1205 11450do_t_strexd (void)
b99bd4ef 11451{
c19d1205
ZW
11452 if (!inst.operands[2].present)
11453 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 11454
c19d1205
ZW
11455 constraint (inst.operands[0].reg == inst.operands[1].reg
11456 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 11457 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 11458 BAD_OVERLAP);
b99bd4ef 11459
c19d1205
ZW
11460 inst.instruction |= inst.operands[0].reg;
11461 inst.instruction |= inst.operands[1].reg << 12;
11462 inst.instruction |= inst.operands[2].reg << 8;
11463 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
11464}
11465
11466static void
c19d1205 11467do_t_sxtah (void)
b99bd4ef 11468{
fdfde340
JM
11469 unsigned Rd, Rn, Rm;
11470
11471 Rd = inst.operands[0].reg;
11472 Rn = inst.operands[1].reg;
11473 Rm = inst.operands[2].reg;
11474
11475 reject_bad_reg (Rd);
11476 reject_bad_reg (Rn);
11477 reject_bad_reg (Rm);
11478
11479 inst.instruction |= Rd << 8;
11480 inst.instruction |= Rn << 16;
11481 inst.instruction |= Rm;
c19d1205
ZW
11482 inst.instruction |= inst.operands[3].imm << 4;
11483}
b99bd4ef 11484
c19d1205
ZW
11485static void
11486do_t_sxth (void)
11487{
fdfde340
JM
11488 unsigned Rd, Rm;
11489
11490 Rd = inst.operands[0].reg;
11491 Rm = inst.operands[1].reg;
11492
11493 reject_bad_reg (Rd);
11494 reject_bad_reg (Rm);
c921be7d
NC
11495
11496 if (inst.instruction <= 0xffff
11497 && inst.size_req != 4
fdfde340 11498 && Rd <= 7 && Rm <= 7
c19d1205 11499 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 11500 {
c19d1205 11501 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11502 inst.instruction |= Rd;
11503 inst.instruction |= Rm << 3;
b99bd4ef 11504 }
c19d1205 11505 else if (unified_syntax)
b99bd4ef 11506 {
c19d1205
ZW
11507 if (inst.instruction <= 0xffff)
11508 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11509 inst.instruction |= Rd << 8;
11510 inst.instruction |= Rm;
c19d1205 11511 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 11512 }
c19d1205 11513 else
b99bd4ef 11514 {
c19d1205
ZW
11515 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11516 _("Thumb encoding does not support rotation"));
11517 constraint (1, BAD_HIREG);
b99bd4ef 11518 }
c19d1205 11519}
b99bd4ef 11520
c19d1205
ZW
11521static void
11522do_t_swi (void)
11523{
b2a5fbdc
MGD
11524 /* We have to do the following check manually as ARM_EXT_OS only applies
11525 to ARM_EXT_V6M. */
11526 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
11527 {
11528 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os))
11529 as_bad (_("SVC is not permitted on this architecture"));
11530 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
11531 }
11532
c19d1205
ZW
11533 inst.reloc.type = BFD_RELOC_ARM_SWI;
11534}
b99bd4ef 11535
92e90b6e
PB
11536static void
11537do_t_tb (void)
11538{
fdfde340 11539 unsigned Rn, Rm;
92e90b6e
PB
11540 int half;
11541
11542 half = (inst.instruction & 0x10) != 0;
e07e6e58 11543 set_it_insn_type_last ();
dfa9f0d5
PB
11544 constraint (inst.operands[0].immisreg,
11545 _("instruction requires register index"));
fdfde340
JM
11546
11547 Rn = inst.operands[0].reg;
11548 Rm = inst.operands[0].imm;
c921be7d 11549
fdfde340
JM
11550 constraint (Rn == REG_SP, BAD_SP);
11551 reject_bad_reg (Rm);
11552
92e90b6e
PB
11553 constraint (!half && inst.operands[0].shifted,
11554 _("instruction does not allow shifted index"));
fdfde340 11555 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
11556}
11557
c19d1205
ZW
11558static void
11559do_t_usat (void)
11560{
3a21c15a 11561 do_t_ssat_usat (0);
b99bd4ef
NC
11562}
11563
11564static void
c19d1205 11565do_t_usat16 (void)
b99bd4ef 11566{
fdfde340
JM
11567 unsigned Rd, Rn;
11568
11569 Rd = inst.operands[0].reg;
11570 Rn = inst.operands[2].reg;
11571
11572 reject_bad_reg (Rd);
11573 reject_bad_reg (Rn);
11574
11575 inst.instruction |= Rd << 8;
c19d1205 11576 inst.instruction |= inst.operands[1].imm;
fdfde340 11577 inst.instruction |= Rn << 16;
b99bd4ef 11578}
c19d1205 11579
5287ad62 11580/* Neon instruction encoder helpers. */
5f4273c7 11581
5287ad62 11582/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 11583
5287ad62
JB
11584/* An "invalid" code for the following tables. */
11585#define N_INV -1u
11586
11587struct neon_tab_entry
b99bd4ef 11588{
5287ad62
JB
11589 unsigned integer;
11590 unsigned float_or_poly;
11591 unsigned scalar_or_imm;
11592};
5f4273c7 11593
5287ad62
JB
11594/* Map overloaded Neon opcodes to their respective encodings. */
11595#define NEON_ENC_TAB \
11596 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11597 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11598 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11599 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11600 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11601 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11602 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11603 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11604 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11605 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11606 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11607 /* Register variants of the following two instructions are encoded as
e07e6e58 11608 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
11609 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11610 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
11611 X(vfma, N_INV, 0x0000c10, N_INV), \
11612 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
11613 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11614 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11615 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11616 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11617 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11618 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11619 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11620 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11621 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11622 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11623 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11624 X(vshl, 0x0000400, N_INV, 0x0800510), \
11625 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11626 X(vand, 0x0000110, N_INV, 0x0800030), \
11627 X(vbic, 0x0100110, N_INV, 0x0800030), \
11628 X(veor, 0x1000110, N_INV, N_INV), \
11629 X(vorn, 0x0300110, N_INV, 0x0800010), \
11630 X(vorr, 0x0200110, N_INV, 0x0800010), \
11631 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11632 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11633 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11634 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11635 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11636 X(vst1, 0x0000000, 0x0800000, N_INV), \
11637 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11638 X(vst2, 0x0000100, 0x0800100, N_INV), \
11639 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11640 X(vst3, 0x0000200, 0x0800200, N_INV), \
11641 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11642 X(vst4, 0x0000300, 0x0800300, N_INV), \
11643 X(vmovn, 0x1b20200, N_INV, N_INV), \
11644 X(vtrn, 0x1b20080, N_INV, N_INV), \
11645 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
11646 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11647 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
11648 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11649 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
11650 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11651 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
11652 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11653 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11654 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11655 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
11656
11657enum neon_opc
11658{
11659#define X(OPC,I,F,S) N_MNEM_##OPC
11660NEON_ENC_TAB
11661#undef X
11662};
b99bd4ef 11663
5287ad62
JB
11664static const struct neon_tab_entry neon_enc_tab[] =
11665{
11666#define X(OPC,I,F,S) { (I), (F), (S) }
11667NEON_ENC_TAB
11668#undef X
11669};
b99bd4ef 11670
88714cb8
DG
11671/* Do not use these macros; instead, use NEON_ENCODE defined below. */
11672#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11673#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11674#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11675#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11676#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11677#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11678#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11679#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11680#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11681#define NEON_ENC_SINGLE_(X) \
037e8744 11682 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 11683#define NEON_ENC_DOUBLE_(X) \
037e8744 11684 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 11685
88714cb8
DG
11686#define NEON_ENCODE(type, inst) \
11687 do \
11688 { \
11689 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
11690 inst.is_neon = 1; \
11691 } \
11692 while (0)
11693
11694#define check_neon_suffixes \
11695 do \
11696 { \
11697 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
11698 { \
11699 as_bad (_("invalid neon suffix for non neon instruction")); \
11700 return; \
11701 } \
11702 } \
11703 while (0)
11704
037e8744
JB
11705/* Define shapes for instruction operands. The following mnemonic characters
11706 are used in this table:
5287ad62 11707
037e8744 11708 F - VFP S<n> register
5287ad62
JB
11709 D - Neon D<n> register
11710 Q - Neon Q<n> register
11711 I - Immediate
11712 S - Scalar
11713 R - ARM register
11714 L - D<n> register list
5f4273c7 11715
037e8744
JB
11716 This table is used to generate various data:
11717 - enumerations of the form NS_DDR to be used as arguments to
11718 neon_select_shape.
11719 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 11720 - a table used to drive neon_select_shape. */
b99bd4ef 11721
037e8744
JB
11722#define NEON_SHAPE_DEF \
11723 X(3, (D, D, D), DOUBLE), \
11724 X(3, (Q, Q, Q), QUAD), \
11725 X(3, (D, D, I), DOUBLE), \
11726 X(3, (Q, Q, I), QUAD), \
11727 X(3, (D, D, S), DOUBLE), \
11728 X(3, (Q, Q, S), QUAD), \
11729 X(2, (D, D), DOUBLE), \
11730 X(2, (Q, Q), QUAD), \
11731 X(2, (D, S), DOUBLE), \
11732 X(2, (Q, S), QUAD), \
11733 X(2, (D, R), DOUBLE), \
11734 X(2, (Q, R), QUAD), \
11735 X(2, (D, I), DOUBLE), \
11736 X(2, (Q, I), QUAD), \
11737 X(3, (D, L, D), DOUBLE), \
11738 X(2, (D, Q), MIXED), \
11739 X(2, (Q, D), MIXED), \
11740 X(3, (D, Q, I), MIXED), \
11741 X(3, (Q, D, I), MIXED), \
11742 X(3, (Q, D, D), MIXED), \
11743 X(3, (D, Q, Q), MIXED), \
11744 X(3, (Q, Q, D), MIXED), \
11745 X(3, (Q, D, S), MIXED), \
11746 X(3, (D, Q, S), MIXED), \
11747 X(4, (D, D, D, I), DOUBLE), \
11748 X(4, (Q, Q, Q, I), QUAD), \
11749 X(2, (F, F), SINGLE), \
11750 X(3, (F, F, F), SINGLE), \
11751 X(2, (F, I), SINGLE), \
11752 X(2, (F, D), MIXED), \
11753 X(2, (D, F), MIXED), \
11754 X(3, (F, F, I), MIXED), \
11755 X(4, (R, R, F, F), SINGLE), \
11756 X(4, (F, F, R, R), SINGLE), \
11757 X(3, (D, R, R), DOUBLE), \
11758 X(3, (R, R, D), DOUBLE), \
11759 X(2, (S, R), SINGLE), \
11760 X(2, (R, S), SINGLE), \
11761 X(2, (F, R), SINGLE), \
11762 X(2, (R, F), SINGLE)
11763
11764#define S2(A,B) NS_##A##B
11765#define S3(A,B,C) NS_##A##B##C
11766#define S4(A,B,C,D) NS_##A##B##C##D
11767
11768#define X(N, L, C) S##N L
11769
5287ad62
JB
11770enum neon_shape
11771{
037e8744
JB
11772 NEON_SHAPE_DEF,
11773 NS_NULL
5287ad62 11774};
b99bd4ef 11775
037e8744
JB
11776#undef X
11777#undef S2
11778#undef S3
11779#undef S4
11780
11781enum neon_shape_class
11782{
11783 SC_SINGLE,
11784 SC_DOUBLE,
11785 SC_QUAD,
11786 SC_MIXED
11787};
11788
11789#define X(N, L, C) SC_##C
11790
11791static enum neon_shape_class neon_shape_class[] =
11792{
11793 NEON_SHAPE_DEF
11794};
11795
11796#undef X
11797
11798enum neon_shape_el
11799{
11800 SE_F,
11801 SE_D,
11802 SE_Q,
11803 SE_I,
11804 SE_S,
11805 SE_R,
11806 SE_L
11807};
11808
11809/* Register widths of above. */
11810static unsigned neon_shape_el_size[] =
11811{
11812 32,
11813 64,
11814 128,
11815 0,
11816 32,
11817 32,
11818 0
11819};
11820
11821struct neon_shape_info
11822{
11823 unsigned els;
11824 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11825};
11826
11827#define S2(A,B) { SE_##A, SE_##B }
11828#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11829#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11830
11831#define X(N, L, C) { N, S##N L }
11832
11833static struct neon_shape_info neon_shape_tab[] =
11834{
11835 NEON_SHAPE_DEF
11836};
11837
11838#undef X
11839#undef S2
11840#undef S3
11841#undef S4
11842
5287ad62
JB
11843/* Bit masks used in type checking given instructions.
11844 'N_EQK' means the type must be the same as (or based on in some way) the key
11845 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11846 set, various other bits can be set as well in order to modify the meaning of
11847 the type constraint. */
11848
11849enum neon_type_mask
11850{
8e79c3df
CM
11851 N_S8 = 0x0000001,
11852 N_S16 = 0x0000002,
11853 N_S32 = 0x0000004,
11854 N_S64 = 0x0000008,
11855 N_U8 = 0x0000010,
11856 N_U16 = 0x0000020,
11857 N_U32 = 0x0000040,
11858 N_U64 = 0x0000080,
11859 N_I8 = 0x0000100,
11860 N_I16 = 0x0000200,
11861 N_I32 = 0x0000400,
11862 N_I64 = 0x0000800,
11863 N_8 = 0x0001000,
11864 N_16 = 0x0002000,
11865 N_32 = 0x0004000,
11866 N_64 = 0x0008000,
11867 N_P8 = 0x0010000,
11868 N_P16 = 0x0020000,
11869 N_F16 = 0x0040000,
11870 N_F32 = 0x0080000,
11871 N_F64 = 0x0100000,
c921be7d
NC
11872 N_KEY = 0x1000000, /* Key element (main type specifier). */
11873 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 11874 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
c921be7d
NC
11875 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
11876 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
11877 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
11878 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
11879 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
11880 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
11881 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 11882 N_UTYP = 0,
037e8744 11883 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
11884};
11885
dcbf9037
JB
11886#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11887
5287ad62
JB
11888#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11889#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11890#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11891#define N_SUF_32 (N_SU_32 | N_F32)
11892#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11893#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11894
11895/* Pass this as the first type argument to neon_check_type to ignore types
11896 altogether. */
11897#define N_IGNORE_TYPE (N_KEY | N_EQK)
11898
037e8744
JB
11899/* Select a "shape" for the current instruction (describing register types or
11900 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11901 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11902 function of operand parsing, so this function doesn't need to be called.
11903 Shapes should be listed in order of decreasing length. */
5287ad62
JB
11904
11905static enum neon_shape
037e8744 11906neon_select_shape (enum neon_shape shape, ...)
5287ad62 11907{
037e8744
JB
11908 va_list ap;
11909 enum neon_shape first_shape = shape;
5287ad62
JB
11910
11911 /* Fix missing optional operands. FIXME: we don't know at this point how
11912 many arguments we should have, so this makes the assumption that we have
11913 > 1. This is true of all current Neon opcodes, I think, but may not be
11914 true in the future. */
11915 if (!inst.operands[1].present)
11916 inst.operands[1] = inst.operands[0];
11917
037e8744 11918 va_start (ap, shape);
5f4273c7 11919
21d799b5 11920 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
11921 {
11922 unsigned j;
11923 int matches = 1;
11924
11925 for (j = 0; j < neon_shape_tab[shape].els; j++)
11926 {
11927 if (!inst.operands[j].present)
11928 {
11929 matches = 0;
11930 break;
11931 }
11932
11933 switch (neon_shape_tab[shape].el[j])
11934 {
11935 case SE_F:
11936 if (!(inst.operands[j].isreg
11937 && inst.operands[j].isvec
11938 && inst.operands[j].issingle
11939 && !inst.operands[j].isquad))
11940 matches = 0;
11941 break;
11942
11943 case SE_D:
11944 if (!(inst.operands[j].isreg
11945 && inst.operands[j].isvec
11946 && !inst.operands[j].isquad
11947 && !inst.operands[j].issingle))
11948 matches = 0;
11949 break;
11950
11951 case SE_R:
11952 if (!(inst.operands[j].isreg
11953 && !inst.operands[j].isvec))
11954 matches = 0;
11955 break;
11956
11957 case SE_Q:
11958 if (!(inst.operands[j].isreg
11959 && inst.operands[j].isvec
11960 && inst.operands[j].isquad
11961 && !inst.operands[j].issingle))
11962 matches = 0;
11963 break;
11964
11965 case SE_I:
11966 if (!(!inst.operands[j].isreg
11967 && !inst.operands[j].isscalar))
11968 matches = 0;
11969 break;
11970
11971 case SE_S:
11972 if (!(!inst.operands[j].isreg
11973 && inst.operands[j].isscalar))
11974 matches = 0;
11975 break;
11976
11977 case SE_L:
11978 break;
11979 }
3fde54a2
JZ
11980 if (!matches)
11981 break;
037e8744
JB
11982 }
11983 if (matches)
5287ad62 11984 break;
037e8744 11985 }
5f4273c7 11986
037e8744 11987 va_end (ap);
5287ad62 11988
037e8744
JB
11989 if (shape == NS_NULL && first_shape != NS_NULL)
11990 first_error (_("invalid instruction shape"));
5287ad62 11991
037e8744
JB
11992 return shape;
11993}
5287ad62 11994
037e8744
JB
11995/* True if SHAPE is predominantly a quadword operation (most of the time, this
11996 means the Q bit should be set). */
11997
11998static int
11999neon_quad (enum neon_shape shape)
12000{
12001 return neon_shape_class[shape] == SC_QUAD;
5287ad62 12002}
037e8744 12003
5287ad62
JB
12004static void
12005neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
12006 unsigned *g_size)
12007{
12008 /* Allow modification to be made to types which are constrained to be
12009 based on the key element, based on bits set alongside N_EQK. */
12010 if ((typebits & N_EQK) != 0)
12011 {
12012 if ((typebits & N_HLF) != 0)
12013 *g_size /= 2;
12014 else if ((typebits & N_DBL) != 0)
12015 *g_size *= 2;
12016 if ((typebits & N_SGN) != 0)
12017 *g_type = NT_signed;
12018 else if ((typebits & N_UNS) != 0)
12019 *g_type = NT_unsigned;
12020 else if ((typebits & N_INT) != 0)
12021 *g_type = NT_integer;
12022 else if ((typebits & N_FLT) != 0)
12023 *g_type = NT_float;
dcbf9037
JB
12024 else if ((typebits & N_SIZ) != 0)
12025 *g_type = NT_untyped;
5287ad62
JB
12026 }
12027}
5f4273c7 12028
5287ad62
JB
12029/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12030 operand type, i.e. the single type specified in a Neon instruction when it
12031 is the only one given. */
12032
12033static struct neon_type_el
12034neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12035{
12036 struct neon_type_el dest = *key;
5f4273c7 12037
9c2799c2 12038 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 12039
5287ad62
JB
12040 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12041
12042 return dest;
12043}
12044
12045/* Convert Neon type and size into compact bitmask representation. */
12046
12047static enum neon_type_mask
12048type_chk_of_el_type (enum neon_el_type type, unsigned size)
12049{
12050 switch (type)
12051 {
12052 case NT_untyped:
12053 switch (size)
12054 {
12055 case 8: return N_8;
12056 case 16: return N_16;
12057 case 32: return N_32;
12058 case 64: return N_64;
12059 default: ;
12060 }
12061 break;
12062
12063 case NT_integer:
12064 switch (size)
12065 {
12066 case 8: return N_I8;
12067 case 16: return N_I16;
12068 case 32: return N_I32;
12069 case 64: return N_I64;
12070 default: ;
12071 }
12072 break;
12073
12074 case NT_float:
037e8744
JB
12075 switch (size)
12076 {
8e79c3df 12077 case 16: return N_F16;
037e8744
JB
12078 case 32: return N_F32;
12079 case 64: return N_F64;
12080 default: ;
12081 }
5287ad62
JB
12082 break;
12083
12084 case NT_poly:
12085 switch (size)
12086 {
12087 case 8: return N_P8;
12088 case 16: return N_P16;
12089 default: ;
12090 }
12091 break;
12092
12093 case NT_signed:
12094 switch (size)
12095 {
12096 case 8: return N_S8;
12097 case 16: return N_S16;
12098 case 32: return N_S32;
12099 case 64: return N_S64;
12100 default: ;
12101 }
12102 break;
12103
12104 case NT_unsigned:
12105 switch (size)
12106 {
12107 case 8: return N_U8;
12108 case 16: return N_U16;
12109 case 32: return N_U32;
12110 case 64: return N_U64;
12111 default: ;
12112 }
12113 break;
12114
12115 default: ;
12116 }
5f4273c7 12117
5287ad62
JB
12118 return N_UTYP;
12119}
12120
12121/* Convert compact Neon bitmask type representation to a type and size. Only
12122 handles the case where a single bit is set in the mask. */
12123
dcbf9037 12124static int
5287ad62
JB
12125el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12126 enum neon_type_mask mask)
12127{
dcbf9037
JB
12128 if ((mask & N_EQK) != 0)
12129 return FAIL;
12130
5287ad62
JB
12131 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12132 *size = 8;
dcbf9037 12133 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 12134 *size = 16;
dcbf9037 12135 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 12136 *size = 32;
037e8744 12137 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 12138 *size = 64;
dcbf9037
JB
12139 else
12140 return FAIL;
12141
5287ad62
JB
12142 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12143 *type = NT_signed;
dcbf9037 12144 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 12145 *type = NT_unsigned;
dcbf9037 12146 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 12147 *type = NT_integer;
dcbf9037 12148 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 12149 *type = NT_untyped;
dcbf9037 12150 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 12151 *type = NT_poly;
037e8744 12152 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 12153 *type = NT_float;
dcbf9037
JB
12154 else
12155 return FAIL;
5f4273c7 12156
dcbf9037 12157 return SUCCESS;
5287ad62
JB
12158}
12159
12160/* Modify a bitmask of allowed types. This is only needed for type
12161 relaxation. */
12162
12163static unsigned
12164modify_types_allowed (unsigned allowed, unsigned mods)
12165{
12166 unsigned size;
12167 enum neon_el_type type;
12168 unsigned destmask;
12169 int i;
5f4273c7 12170
5287ad62 12171 destmask = 0;
5f4273c7 12172
5287ad62
JB
12173 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12174 {
21d799b5
NC
12175 if (el_type_of_type_chk (&type, &size,
12176 (enum neon_type_mask) (allowed & i)) == SUCCESS)
dcbf9037
JB
12177 {
12178 neon_modify_type_size (mods, &type, &size);
12179 destmask |= type_chk_of_el_type (type, size);
12180 }
5287ad62 12181 }
5f4273c7 12182
5287ad62
JB
12183 return destmask;
12184}
12185
12186/* Check type and return type classification.
12187 The manual states (paraphrase): If one datatype is given, it indicates the
12188 type given in:
12189 - the second operand, if there is one
12190 - the operand, if there is no second operand
12191 - the result, if there are no operands.
12192 This isn't quite good enough though, so we use a concept of a "key" datatype
12193 which is set on a per-instruction basis, which is the one which matters when
12194 only one data type is written.
12195 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 12196 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
12197
12198static struct neon_type_el
12199neon_check_type (unsigned els, enum neon_shape ns, ...)
12200{
12201 va_list ap;
12202 unsigned i, pass, key_el = 0;
12203 unsigned types[NEON_MAX_TYPE_ELS];
12204 enum neon_el_type k_type = NT_invtype;
12205 unsigned k_size = -1u;
12206 struct neon_type_el badtype = {NT_invtype, -1};
12207 unsigned key_allowed = 0;
12208
12209 /* Optional registers in Neon instructions are always (not) in operand 1.
12210 Fill in the missing operand here, if it was omitted. */
12211 if (els > 1 && !inst.operands[1].present)
12212 inst.operands[1] = inst.operands[0];
12213
12214 /* Suck up all the varargs. */
12215 va_start (ap, ns);
12216 for (i = 0; i < els; i++)
12217 {
12218 unsigned thisarg = va_arg (ap, unsigned);
12219 if (thisarg == N_IGNORE_TYPE)
12220 {
12221 va_end (ap);
12222 return badtype;
12223 }
12224 types[i] = thisarg;
12225 if ((thisarg & N_KEY) != 0)
12226 key_el = i;
12227 }
12228 va_end (ap);
12229
dcbf9037
JB
12230 if (inst.vectype.elems > 0)
12231 for (i = 0; i < els; i++)
12232 if (inst.operands[i].vectype.type != NT_invtype)
12233 {
12234 first_error (_("types specified in both the mnemonic and operands"));
12235 return badtype;
12236 }
12237
5287ad62
JB
12238 /* Duplicate inst.vectype elements here as necessary.
12239 FIXME: No idea if this is exactly the same as the ARM assembler,
12240 particularly when an insn takes one register and one non-register
12241 operand. */
12242 if (inst.vectype.elems == 1 && els > 1)
12243 {
12244 unsigned j;
12245 inst.vectype.elems = els;
12246 inst.vectype.el[key_el] = inst.vectype.el[0];
12247 for (j = 0; j < els; j++)
dcbf9037
JB
12248 if (j != key_el)
12249 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12250 types[j]);
12251 }
12252 else if (inst.vectype.elems == 0 && els > 0)
12253 {
12254 unsigned j;
12255 /* No types were given after the mnemonic, so look for types specified
12256 after each operand. We allow some flexibility here; as long as the
12257 "key" operand has a type, we can infer the others. */
12258 for (j = 0; j < els; j++)
12259 if (inst.operands[j].vectype.type != NT_invtype)
12260 inst.vectype.el[j] = inst.operands[j].vectype;
12261
12262 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 12263 {
dcbf9037
JB
12264 for (j = 0; j < els; j++)
12265 if (inst.operands[j].vectype.type == NT_invtype)
12266 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12267 types[j]);
12268 }
12269 else
12270 {
12271 first_error (_("operand types can't be inferred"));
12272 return badtype;
5287ad62
JB
12273 }
12274 }
12275 else if (inst.vectype.elems != els)
12276 {
dcbf9037 12277 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
12278 return badtype;
12279 }
12280
12281 for (pass = 0; pass < 2; pass++)
12282 {
12283 for (i = 0; i < els; i++)
12284 {
12285 unsigned thisarg = types[i];
12286 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12287 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12288 enum neon_el_type g_type = inst.vectype.el[i].type;
12289 unsigned g_size = inst.vectype.el[i].size;
12290
12291 /* Decay more-specific signed & unsigned types to sign-insensitive
12292 integer types if sign-specific variants are unavailable. */
12293 if ((g_type == NT_signed || g_type == NT_unsigned)
12294 && (types_allowed & N_SU_ALL) == 0)
12295 g_type = NT_integer;
12296
12297 /* If only untyped args are allowed, decay any more specific types to
12298 them. Some instructions only care about signs for some element
12299 sizes, so handle that properly. */
12300 if ((g_size == 8 && (types_allowed & N_8) != 0)
12301 || (g_size == 16 && (types_allowed & N_16) != 0)
12302 || (g_size == 32 && (types_allowed & N_32) != 0)
12303 || (g_size == 64 && (types_allowed & N_64) != 0))
12304 g_type = NT_untyped;
12305
12306 if (pass == 0)
12307 {
12308 if ((thisarg & N_KEY) != 0)
12309 {
12310 k_type = g_type;
12311 k_size = g_size;
12312 key_allowed = thisarg & ~N_KEY;
12313 }
12314 }
12315 else
12316 {
037e8744
JB
12317 if ((thisarg & N_VFP) != 0)
12318 {
99b253c5
NC
12319 enum neon_shape_el regshape;
12320 unsigned regwidth, match;
12321
12322 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12323 if (ns == NS_NULL)
12324 {
12325 first_error (_("invalid instruction shape"));
12326 return badtype;
12327 }
12328 regshape = neon_shape_tab[ns].el[i];
12329 regwidth = neon_shape_el_size[regshape];
037e8744
JB
12330
12331 /* In VFP mode, operands must match register widths. If we
12332 have a key operand, use its width, else use the width of
12333 the current operand. */
12334 if (k_size != -1u)
12335 match = k_size;
12336 else
12337 match = g_size;
12338
12339 if (regwidth != match)
12340 {
12341 first_error (_("operand size must match register width"));
12342 return badtype;
12343 }
12344 }
5f4273c7 12345
5287ad62
JB
12346 if ((thisarg & N_EQK) == 0)
12347 {
12348 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12349
12350 if ((given_type & types_allowed) == 0)
12351 {
dcbf9037 12352 first_error (_("bad type in Neon instruction"));
5287ad62
JB
12353 return badtype;
12354 }
12355 }
12356 else
12357 {
12358 enum neon_el_type mod_k_type = k_type;
12359 unsigned mod_k_size = k_size;
12360 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12361 if (g_type != mod_k_type || g_size != mod_k_size)
12362 {
dcbf9037 12363 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
12364 return badtype;
12365 }
12366 }
12367 }
12368 }
12369 }
12370
12371 return inst.vectype.el[key_el];
12372}
12373
037e8744 12374/* Neon-style VFP instruction forwarding. */
5287ad62 12375
037e8744
JB
12376/* Thumb VFP instructions have 0xE in the condition field. */
12377
12378static void
12379do_vfp_cond_or_thumb (void)
5287ad62 12380{
88714cb8
DG
12381 inst.is_neon = 1;
12382
5287ad62 12383 if (thumb_mode)
037e8744 12384 inst.instruction |= 0xe0000000;
5287ad62 12385 else
037e8744 12386 inst.instruction |= inst.cond << 28;
5287ad62
JB
12387}
12388
037e8744
JB
12389/* Look up and encode a simple mnemonic, for use as a helper function for the
12390 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12391 etc. It is assumed that operand parsing has already been done, and that the
12392 operands are in the form expected by the given opcode (this isn't necessarily
12393 the same as the form in which they were parsed, hence some massaging must
12394 take place before this function is called).
12395 Checks current arch version against that in the looked-up opcode. */
5287ad62 12396
037e8744
JB
12397static void
12398do_vfp_nsyn_opcode (const char *opname)
5287ad62 12399{
037e8744 12400 const struct asm_opcode *opcode;
5f4273c7 12401
21d799b5 12402 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 12403
037e8744
JB
12404 if (!opcode)
12405 abort ();
5287ad62 12406
037e8744
JB
12407 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12408 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12409 _(BAD_FPU));
5287ad62 12410
88714cb8
DG
12411 inst.is_neon = 1;
12412
037e8744
JB
12413 if (thumb_mode)
12414 {
12415 inst.instruction = opcode->tvalue;
12416 opcode->tencode ();
12417 }
12418 else
12419 {
12420 inst.instruction = (inst.cond << 28) | opcode->avalue;
12421 opcode->aencode ();
12422 }
12423}
5287ad62
JB
12424
12425static void
037e8744 12426do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 12427{
037e8744
JB
12428 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12429
12430 if (rs == NS_FFF)
12431 {
12432 if (is_add)
12433 do_vfp_nsyn_opcode ("fadds");
12434 else
12435 do_vfp_nsyn_opcode ("fsubs");
12436 }
12437 else
12438 {
12439 if (is_add)
12440 do_vfp_nsyn_opcode ("faddd");
12441 else
12442 do_vfp_nsyn_opcode ("fsubd");
12443 }
12444}
12445
12446/* Check operand types to see if this is a VFP instruction, and if so call
12447 PFN (). */
12448
12449static int
12450try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12451{
12452 enum neon_shape rs;
12453 struct neon_type_el et;
12454
12455 switch (args)
12456 {
12457 case 2:
12458 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12459 et = neon_check_type (2, rs,
12460 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12461 break;
5f4273c7 12462
037e8744
JB
12463 case 3:
12464 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12465 et = neon_check_type (3, rs,
12466 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12467 break;
12468
12469 default:
12470 abort ();
12471 }
12472
12473 if (et.type != NT_invtype)
12474 {
12475 pfn (rs);
12476 return SUCCESS;
12477 }
037e8744 12478
99b253c5 12479 inst.error = NULL;
037e8744
JB
12480 return FAIL;
12481}
12482
12483static void
12484do_vfp_nsyn_mla_mls (enum neon_shape rs)
12485{
12486 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 12487
037e8744
JB
12488 if (rs == NS_FFF)
12489 {
12490 if (is_mla)
12491 do_vfp_nsyn_opcode ("fmacs");
12492 else
1ee69515 12493 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
12494 }
12495 else
12496 {
12497 if (is_mla)
12498 do_vfp_nsyn_opcode ("fmacd");
12499 else
1ee69515 12500 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
12501 }
12502}
12503
62f3b8c8
PB
12504static void
12505do_vfp_nsyn_fma_fms (enum neon_shape rs)
12506{
12507 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12508
12509 if (rs == NS_FFF)
12510 {
12511 if (is_fma)
12512 do_vfp_nsyn_opcode ("ffmas");
12513 else
12514 do_vfp_nsyn_opcode ("ffnmas");
12515 }
12516 else
12517 {
12518 if (is_fma)
12519 do_vfp_nsyn_opcode ("ffmad");
12520 else
12521 do_vfp_nsyn_opcode ("ffnmad");
12522 }
12523}
12524
037e8744
JB
12525static void
12526do_vfp_nsyn_mul (enum neon_shape rs)
12527{
12528 if (rs == NS_FFF)
12529 do_vfp_nsyn_opcode ("fmuls");
12530 else
12531 do_vfp_nsyn_opcode ("fmuld");
12532}
12533
12534static void
12535do_vfp_nsyn_abs_neg (enum neon_shape rs)
12536{
12537 int is_neg = (inst.instruction & 0x80) != 0;
12538 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12539
12540 if (rs == NS_FF)
12541 {
12542 if (is_neg)
12543 do_vfp_nsyn_opcode ("fnegs");
12544 else
12545 do_vfp_nsyn_opcode ("fabss");
12546 }
12547 else
12548 {
12549 if (is_neg)
12550 do_vfp_nsyn_opcode ("fnegd");
12551 else
12552 do_vfp_nsyn_opcode ("fabsd");
12553 }
12554}
12555
12556/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12557 insns belong to Neon, and are handled elsewhere. */
12558
12559static void
12560do_vfp_nsyn_ldm_stm (int is_dbmode)
12561{
12562 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12563 if (is_ldm)
12564 {
12565 if (is_dbmode)
12566 do_vfp_nsyn_opcode ("fldmdbs");
12567 else
12568 do_vfp_nsyn_opcode ("fldmias");
12569 }
12570 else
12571 {
12572 if (is_dbmode)
12573 do_vfp_nsyn_opcode ("fstmdbs");
12574 else
12575 do_vfp_nsyn_opcode ("fstmias");
12576 }
12577}
12578
037e8744
JB
12579static void
12580do_vfp_nsyn_sqrt (void)
12581{
12582 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12583 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12584
037e8744
JB
12585 if (rs == NS_FF)
12586 do_vfp_nsyn_opcode ("fsqrts");
12587 else
12588 do_vfp_nsyn_opcode ("fsqrtd");
12589}
12590
12591static void
12592do_vfp_nsyn_div (void)
12593{
12594 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12595 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12596 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12597
037e8744
JB
12598 if (rs == NS_FFF)
12599 do_vfp_nsyn_opcode ("fdivs");
12600 else
12601 do_vfp_nsyn_opcode ("fdivd");
12602}
12603
12604static void
12605do_vfp_nsyn_nmul (void)
12606{
12607 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12608 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12609 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12610
037e8744
JB
12611 if (rs == NS_FFF)
12612 {
88714cb8 12613 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12614 do_vfp_sp_dyadic ();
12615 }
12616 else
12617 {
88714cb8 12618 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12619 do_vfp_dp_rd_rn_rm ();
12620 }
12621 do_vfp_cond_or_thumb ();
12622}
12623
12624static void
12625do_vfp_nsyn_cmp (void)
12626{
12627 if (inst.operands[1].isreg)
12628 {
12629 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12630 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12631
037e8744
JB
12632 if (rs == NS_FF)
12633 {
88714cb8 12634 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12635 do_vfp_sp_monadic ();
12636 }
12637 else
12638 {
88714cb8 12639 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12640 do_vfp_dp_rd_rm ();
12641 }
12642 }
12643 else
12644 {
12645 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12646 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12647
12648 switch (inst.instruction & 0x0fffffff)
12649 {
12650 case N_MNEM_vcmp:
12651 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12652 break;
12653 case N_MNEM_vcmpe:
12654 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12655 break;
12656 default:
12657 abort ();
12658 }
5f4273c7 12659
037e8744
JB
12660 if (rs == NS_FI)
12661 {
88714cb8 12662 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12663 do_vfp_sp_compare_z ();
12664 }
12665 else
12666 {
88714cb8 12667 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12668 do_vfp_dp_rd ();
12669 }
12670 }
12671 do_vfp_cond_or_thumb ();
12672}
12673
12674static void
12675nsyn_insert_sp (void)
12676{
12677 inst.operands[1] = inst.operands[0];
12678 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 12679 inst.operands[0].reg = REG_SP;
037e8744
JB
12680 inst.operands[0].isreg = 1;
12681 inst.operands[0].writeback = 1;
12682 inst.operands[0].present = 1;
12683}
12684
12685static void
12686do_vfp_nsyn_push (void)
12687{
12688 nsyn_insert_sp ();
12689 if (inst.operands[1].issingle)
12690 do_vfp_nsyn_opcode ("fstmdbs");
12691 else
12692 do_vfp_nsyn_opcode ("fstmdbd");
12693}
12694
12695static void
12696do_vfp_nsyn_pop (void)
12697{
12698 nsyn_insert_sp ();
12699 if (inst.operands[1].issingle)
22b5b651 12700 do_vfp_nsyn_opcode ("fldmias");
037e8744 12701 else
22b5b651 12702 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
12703}
12704
12705/* Fix up Neon data-processing instructions, ORing in the correct bits for
12706 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12707
88714cb8
DG
12708static void
12709neon_dp_fixup (struct arm_it* insn)
037e8744 12710{
88714cb8
DG
12711 unsigned int i = insn->instruction;
12712 insn->is_neon = 1;
12713
037e8744
JB
12714 if (thumb_mode)
12715 {
12716 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12717 if (i & (1 << 24))
12718 i |= 1 << 28;
5f4273c7 12719
037e8744 12720 i &= ~(1 << 24);
5f4273c7 12721
037e8744
JB
12722 i |= 0xef000000;
12723 }
12724 else
12725 i |= 0xf2000000;
5f4273c7 12726
88714cb8 12727 insn->instruction = i;
037e8744
JB
12728}
12729
12730/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12731 (0, 1, 2, 3). */
12732
12733static unsigned
12734neon_logbits (unsigned x)
12735{
12736 return ffs (x) - 4;
12737}
12738
12739#define LOW4(R) ((R) & 0xf)
12740#define HI1(R) (((R) >> 4) & 1)
12741
12742/* Encode insns with bit pattern:
12743
12744 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12745 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 12746
037e8744
JB
12747 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12748 different meaning for some instruction. */
12749
12750static void
12751neon_three_same (int isquad, int ubit, int size)
12752{
12753 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12754 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12755 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12756 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12757 inst.instruction |= LOW4 (inst.operands[2].reg);
12758 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12759 inst.instruction |= (isquad != 0) << 6;
12760 inst.instruction |= (ubit != 0) << 24;
12761 if (size != -1)
12762 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12763
88714cb8 12764 neon_dp_fixup (&inst);
037e8744
JB
12765}
12766
12767/* Encode instructions of the form:
12768
12769 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12770 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
12771
12772 Don't write size if SIZE == -1. */
12773
12774static void
12775neon_two_same (int qbit, int ubit, int size)
12776{
12777 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12778 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12779 inst.instruction |= LOW4 (inst.operands[1].reg);
12780 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12781 inst.instruction |= (qbit != 0) << 6;
12782 inst.instruction |= (ubit != 0) << 24;
12783
12784 if (size != -1)
12785 inst.instruction |= neon_logbits (size) << 18;
12786
88714cb8 12787 neon_dp_fixup (&inst);
5287ad62
JB
12788}
12789
12790/* Neon instruction encoders, in approximate order of appearance. */
12791
12792static void
12793do_neon_dyadic_i_su (void)
12794{
037e8744 12795 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12796 struct neon_type_el et = neon_check_type (3, rs,
12797 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 12798 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12799}
12800
12801static void
12802do_neon_dyadic_i64_su (void)
12803{
037e8744 12804 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12805 struct neon_type_el et = neon_check_type (3, rs,
12806 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 12807 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12808}
12809
12810static void
12811neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12812 unsigned immbits)
12813{
12814 unsigned size = et.size >> 3;
12815 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12816 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12817 inst.instruction |= LOW4 (inst.operands[1].reg);
12818 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12819 inst.instruction |= (isquad != 0) << 6;
12820 inst.instruction |= immbits << 16;
12821 inst.instruction |= (size >> 3) << 7;
12822 inst.instruction |= (size & 0x7) << 19;
12823 if (write_ubit)
12824 inst.instruction |= (uval != 0) << 24;
12825
88714cb8 12826 neon_dp_fixup (&inst);
5287ad62
JB
12827}
12828
12829static void
12830do_neon_shl_imm (void)
12831{
12832 if (!inst.operands[2].isreg)
12833 {
037e8744 12834 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12835 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
88714cb8 12836 NEON_ENCODE (IMMED, inst);
037e8744 12837 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
12838 }
12839 else
12840 {
037e8744 12841 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12842 struct neon_type_el et = neon_check_type (3, rs,
12843 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12844 unsigned int tmp;
12845
12846 /* VSHL/VQSHL 3-register variants have syntax such as:
12847 vshl.xx Dd, Dm, Dn
12848 whereas other 3-register operations encoded by neon_three_same have
12849 syntax like:
12850 vadd.xx Dd, Dn, Dm
12851 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12852 here. */
12853 tmp = inst.operands[2].reg;
12854 inst.operands[2].reg = inst.operands[1].reg;
12855 inst.operands[1].reg = tmp;
88714cb8 12856 NEON_ENCODE (INTEGER, inst);
037e8744 12857 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12858 }
12859}
12860
12861static void
12862do_neon_qshl_imm (void)
12863{
12864 if (!inst.operands[2].isreg)
12865 {
037e8744 12866 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12867 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 12868
88714cb8 12869 NEON_ENCODE (IMMED, inst);
037e8744 12870 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
12871 inst.operands[2].imm);
12872 }
12873 else
12874 {
037e8744 12875 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12876 struct neon_type_el et = neon_check_type (3, rs,
12877 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12878 unsigned int tmp;
12879
12880 /* See note in do_neon_shl_imm. */
12881 tmp = inst.operands[2].reg;
12882 inst.operands[2].reg = inst.operands[1].reg;
12883 inst.operands[1].reg = tmp;
88714cb8 12884 NEON_ENCODE (INTEGER, inst);
037e8744 12885 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12886 }
12887}
12888
627907b7
JB
12889static void
12890do_neon_rshl (void)
12891{
12892 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12893 struct neon_type_el et = neon_check_type (3, rs,
12894 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12895 unsigned int tmp;
12896
12897 tmp = inst.operands[2].reg;
12898 inst.operands[2].reg = inst.operands[1].reg;
12899 inst.operands[1].reg = tmp;
12900 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12901}
12902
5287ad62
JB
12903static int
12904neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12905{
036dc3f7
PB
12906 /* Handle .I8 pseudo-instructions. */
12907 if (size == 8)
5287ad62 12908 {
5287ad62
JB
12909 /* Unfortunately, this will make everything apart from zero out-of-range.
12910 FIXME is this the intended semantics? There doesn't seem much point in
12911 accepting .I8 if so. */
12912 immediate |= immediate << 8;
12913 size = 16;
036dc3f7
PB
12914 }
12915
12916 if (size >= 32)
12917 {
12918 if (immediate == (immediate & 0x000000ff))
12919 {
12920 *immbits = immediate;
12921 return 0x1;
12922 }
12923 else if (immediate == (immediate & 0x0000ff00))
12924 {
12925 *immbits = immediate >> 8;
12926 return 0x3;
12927 }
12928 else if (immediate == (immediate & 0x00ff0000))
12929 {
12930 *immbits = immediate >> 16;
12931 return 0x5;
12932 }
12933 else if (immediate == (immediate & 0xff000000))
12934 {
12935 *immbits = immediate >> 24;
12936 return 0x7;
12937 }
12938 if ((immediate & 0xffff) != (immediate >> 16))
12939 goto bad_immediate;
12940 immediate &= 0xffff;
5287ad62
JB
12941 }
12942
12943 if (immediate == (immediate & 0x000000ff))
12944 {
12945 *immbits = immediate;
036dc3f7 12946 return 0x9;
5287ad62
JB
12947 }
12948 else if (immediate == (immediate & 0x0000ff00))
12949 {
12950 *immbits = immediate >> 8;
036dc3f7 12951 return 0xb;
5287ad62
JB
12952 }
12953
12954 bad_immediate:
dcbf9037 12955 first_error (_("immediate value out of range"));
5287ad62
JB
12956 return FAIL;
12957}
12958
12959/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12960 A, B, C, D. */
12961
12962static int
12963neon_bits_same_in_bytes (unsigned imm)
12964{
12965 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12966 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12967 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12968 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12969}
12970
12971/* For immediate of above form, return 0bABCD. */
12972
12973static unsigned
12974neon_squash_bits (unsigned imm)
12975{
12976 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12977 | ((imm & 0x01000000) >> 21);
12978}
12979
136da414 12980/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
12981
12982static unsigned
12983neon_qfloat_bits (unsigned imm)
12984{
136da414 12985 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
12986}
12987
12988/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12989 the instruction. *OP is passed as the initial value of the op field, and
12990 may be set to a different value depending on the constant (i.e.
12991 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 12992 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 12993 try smaller element sizes. */
5287ad62
JB
12994
12995static int
c96612cc
JB
12996neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12997 unsigned *immbits, int *op, int size,
12998 enum neon_el_type type)
5287ad62 12999{
c96612cc
JB
13000 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13001 float. */
13002 if (type == NT_float && !float_p)
13003 return FAIL;
13004
136da414
JB
13005 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13006 {
13007 if (size != 32 || *op == 1)
13008 return FAIL;
13009 *immbits = neon_qfloat_bits (immlo);
13010 return 0xf;
13011 }
036dc3f7
PB
13012
13013 if (size == 64)
5287ad62 13014 {
036dc3f7
PB
13015 if (neon_bits_same_in_bytes (immhi)
13016 && neon_bits_same_in_bytes (immlo))
13017 {
13018 if (*op == 1)
13019 return FAIL;
13020 *immbits = (neon_squash_bits (immhi) << 4)
13021 | neon_squash_bits (immlo);
13022 *op = 1;
13023 return 0xe;
13024 }
13025
13026 if (immhi != immlo)
13027 return FAIL;
5287ad62 13028 }
036dc3f7
PB
13029
13030 if (size >= 32)
5287ad62 13031 {
036dc3f7
PB
13032 if (immlo == (immlo & 0x000000ff))
13033 {
13034 *immbits = immlo;
13035 return 0x0;
13036 }
13037 else if (immlo == (immlo & 0x0000ff00))
13038 {
13039 *immbits = immlo >> 8;
13040 return 0x2;
13041 }
13042 else if (immlo == (immlo & 0x00ff0000))
13043 {
13044 *immbits = immlo >> 16;
13045 return 0x4;
13046 }
13047 else if (immlo == (immlo & 0xff000000))
13048 {
13049 *immbits = immlo >> 24;
13050 return 0x6;
13051 }
13052 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13053 {
13054 *immbits = (immlo >> 8) & 0xff;
13055 return 0xc;
13056 }
13057 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13058 {
13059 *immbits = (immlo >> 16) & 0xff;
13060 return 0xd;
13061 }
13062
13063 if ((immlo & 0xffff) != (immlo >> 16))
13064 return FAIL;
13065 immlo &= 0xffff;
5287ad62 13066 }
036dc3f7
PB
13067
13068 if (size >= 16)
5287ad62 13069 {
036dc3f7
PB
13070 if (immlo == (immlo & 0x000000ff))
13071 {
13072 *immbits = immlo;
13073 return 0x8;
13074 }
13075 else if (immlo == (immlo & 0x0000ff00))
13076 {
13077 *immbits = immlo >> 8;
13078 return 0xa;
13079 }
13080
13081 if ((immlo & 0xff) != (immlo >> 8))
13082 return FAIL;
13083 immlo &= 0xff;
5287ad62 13084 }
036dc3f7
PB
13085
13086 if (immlo == (immlo & 0x000000ff))
5287ad62 13087 {
036dc3f7
PB
13088 /* Don't allow MVN with 8-bit immediate. */
13089 if (*op == 1)
13090 return FAIL;
13091 *immbits = immlo;
13092 return 0xe;
5287ad62 13093 }
5287ad62
JB
13094
13095 return FAIL;
13096}
13097
13098/* Write immediate bits [7:0] to the following locations:
13099
13100 |28/24|23 19|18 16|15 4|3 0|
13101 | 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|
13102
13103 This function is used by VMOV/VMVN/VORR/VBIC. */
13104
13105static void
13106neon_write_immbits (unsigned immbits)
13107{
13108 inst.instruction |= immbits & 0xf;
13109 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13110 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13111}
13112
13113/* Invert low-order SIZE bits of XHI:XLO. */
13114
13115static void
13116neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13117{
13118 unsigned immlo = xlo ? *xlo : 0;
13119 unsigned immhi = xhi ? *xhi : 0;
13120
13121 switch (size)
13122 {
13123 case 8:
13124 immlo = (~immlo) & 0xff;
13125 break;
13126
13127 case 16:
13128 immlo = (~immlo) & 0xffff;
13129 break;
13130
13131 case 64:
13132 immhi = (~immhi) & 0xffffffff;
13133 /* fall through. */
13134
13135 case 32:
13136 immlo = (~immlo) & 0xffffffff;
13137 break;
13138
13139 default:
13140 abort ();
13141 }
13142
13143 if (xlo)
13144 *xlo = immlo;
13145
13146 if (xhi)
13147 *xhi = immhi;
13148}
13149
13150static void
13151do_neon_logic (void)
13152{
13153 if (inst.operands[2].present && inst.operands[2].isreg)
13154 {
037e8744 13155 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13156 neon_check_type (3, rs, N_IGNORE_TYPE);
13157 /* U bit and size field were set as part of the bitmask. */
88714cb8 13158 NEON_ENCODE (INTEGER, inst);
037e8744 13159 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13160 }
13161 else
13162 {
4316f0d2
DG
13163 const int three_ops_form = (inst.operands[2].present
13164 && !inst.operands[2].isreg);
13165 const int immoperand = (three_ops_form ? 2 : 1);
13166 enum neon_shape rs = (three_ops_form
13167 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13168 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744
JB
13169 struct neon_type_el et = neon_check_type (2, rs,
13170 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 13171 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
13172 unsigned immbits;
13173 int cmode;
5f4273c7 13174
5287ad62
JB
13175 if (et.type == NT_invtype)
13176 return;
5f4273c7 13177
4316f0d2
DG
13178 if (three_ops_form)
13179 constraint (inst.operands[0].reg != inst.operands[1].reg,
13180 _("first and second operands shall be the same register"));
13181
88714cb8 13182 NEON_ENCODE (IMMED, inst);
5287ad62 13183
4316f0d2 13184 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
13185 if (et.size == 64)
13186 {
13187 /* .i64 is a pseudo-op, so the immediate must be a repeating
13188 pattern. */
4316f0d2
DG
13189 if (immbits != (inst.operands[immoperand].regisimm ?
13190 inst.operands[immoperand].reg : 0))
036dc3f7
PB
13191 {
13192 /* Set immbits to an invalid constant. */
13193 immbits = 0xdeadbeef;
13194 }
13195 }
13196
5287ad62
JB
13197 switch (opcode)
13198 {
13199 case N_MNEM_vbic:
036dc3f7 13200 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13201 break;
5f4273c7 13202
5287ad62 13203 case N_MNEM_vorr:
036dc3f7 13204 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13205 break;
5f4273c7 13206
5287ad62
JB
13207 case N_MNEM_vand:
13208 /* Pseudo-instruction for VBIC. */
5287ad62
JB
13209 neon_invert_size (&immbits, 0, et.size);
13210 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13211 break;
5f4273c7 13212
5287ad62
JB
13213 case N_MNEM_vorn:
13214 /* Pseudo-instruction for VORR. */
5287ad62
JB
13215 neon_invert_size (&immbits, 0, et.size);
13216 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13217 break;
5f4273c7 13218
5287ad62
JB
13219 default:
13220 abort ();
13221 }
13222
13223 if (cmode == FAIL)
13224 return;
13225
037e8744 13226 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13227 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13228 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13229 inst.instruction |= cmode << 8;
13230 neon_write_immbits (immbits);
5f4273c7 13231
88714cb8 13232 neon_dp_fixup (&inst);
5287ad62
JB
13233 }
13234}
13235
13236static void
13237do_neon_bitfield (void)
13238{
037e8744 13239 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 13240 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 13241 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13242}
13243
13244static void
dcbf9037
JB
13245neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13246 unsigned destbits)
5287ad62 13247{
037e8744 13248 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
13249 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13250 types | N_KEY);
5287ad62
JB
13251 if (et.type == NT_float)
13252 {
88714cb8 13253 NEON_ENCODE (FLOAT, inst);
037e8744 13254 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13255 }
13256 else
13257 {
88714cb8 13258 NEON_ENCODE (INTEGER, inst);
037e8744 13259 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
13260 }
13261}
13262
13263static void
13264do_neon_dyadic_if_su (void)
13265{
dcbf9037 13266 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13267}
13268
13269static void
13270do_neon_dyadic_if_su_d (void)
13271{
13272 /* This version only allow D registers, but that constraint is enforced during
13273 operand parsing so we don't need to do anything extra here. */
dcbf9037 13274 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13275}
13276
5287ad62
JB
13277static void
13278do_neon_dyadic_if_i_d (void)
13279{
428e3f1f
PB
13280 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13281 affected if we specify unsigned args. */
13282 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
13283}
13284
037e8744
JB
13285enum vfp_or_neon_is_neon_bits
13286{
13287 NEON_CHECK_CC = 1,
13288 NEON_CHECK_ARCH = 2
13289};
13290
13291/* Call this function if an instruction which may have belonged to the VFP or
13292 Neon instruction sets, but turned out to be a Neon instruction (due to the
13293 operand types involved, etc.). We have to check and/or fix-up a couple of
13294 things:
13295
13296 - Make sure the user hasn't attempted to make a Neon instruction
13297 conditional.
13298 - Alter the value in the condition code field if necessary.
13299 - Make sure that the arch supports Neon instructions.
13300
13301 Which of these operations take place depends on bits from enum
13302 vfp_or_neon_is_neon_bits.
13303
13304 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13305 current instruction's condition is COND_ALWAYS, the condition field is
13306 changed to inst.uncond_value. This is necessary because instructions shared
13307 between VFP and Neon may be conditional for the VFP variants only, and the
13308 unconditional Neon version must have, e.g., 0xF in the condition field. */
13309
13310static int
13311vfp_or_neon_is_neon (unsigned check)
13312{
13313 /* Conditions are always legal in Thumb mode (IT blocks). */
13314 if (!thumb_mode && (check & NEON_CHECK_CC))
13315 {
13316 if (inst.cond != COND_ALWAYS)
13317 {
13318 first_error (_(BAD_COND));
13319 return FAIL;
13320 }
13321 if (inst.uncond_value != -1)
13322 inst.instruction |= inst.uncond_value << 28;
13323 }
5f4273c7 13324
037e8744
JB
13325 if ((check & NEON_CHECK_ARCH)
13326 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13327 {
13328 first_error (_(BAD_FPU));
13329 return FAIL;
13330 }
5f4273c7 13331
037e8744
JB
13332 return SUCCESS;
13333}
13334
5287ad62
JB
13335static void
13336do_neon_addsub_if_i (void)
13337{
037e8744
JB
13338 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13339 return;
13340
13341 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13342 return;
13343
5287ad62
JB
13344 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13345 affected if we specify unsigned args. */
dcbf9037 13346 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
13347}
13348
13349/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13350 result to be:
13351 V<op> A,B (A is operand 0, B is operand 2)
13352 to mean:
13353 V<op> A,B,A
13354 not:
13355 V<op> A,B,B
13356 so handle that case specially. */
13357
13358static void
13359neon_exchange_operands (void)
13360{
13361 void *scratch = alloca (sizeof (inst.operands[0]));
13362 if (inst.operands[1].present)
13363 {
13364 /* Swap operands[1] and operands[2]. */
13365 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13366 inst.operands[1] = inst.operands[2];
13367 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13368 }
13369 else
13370 {
13371 inst.operands[1] = inst.operands[2];
13372 inst.operands[2] = inst.operands[0];
13373 }
13374}
13375
13376static void
13377neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13378{
13379 if (inst.operands[2].isreg)
13380 {
13381 if (invert)
13382 neon_exchange_operands ();
dcbf9037 13383 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
13384 }
13385 else
13386 {
037e8744 13387 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
13388 struct neon_type_el et = neon_check_type (2, rs,
13389 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 13390
88714cb8 13391 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13392 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13393 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13394 inst.instruction |= LOW4 (inst.operands[1].reg);
13395 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13396 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13397 inst.instruction |= (et.type == NT_float) << 10;
13398 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13399
88714cb8 13400 neon_dp_fixup (&inst);
5287ad62
JB
13401 }
13402}
13403
13404static void
13405do_neon_cmp (void)
13406{
13407 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13408}
13409
13410static void
13411do_neon_cmp_inv (void)
13412{
13413 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13414}
13415
13416static void
13417do_neon_ceq (void)
13418{
13419 neon_compare (N_IF_32, N_IF_32, FALSE);
13420}
13421
13422/* For multiply instructions, we have the possibility of 16-bit or 32-bit
13423 scalars, which are encoded in 5 bits, M : Rm.
13424 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13425 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13426 index in M. */
13427
13428static unsigned
13429neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13430{
dcbf9037
JB
13431 unsigned regno = NEON_SCALAR_REG (scalar);
13432 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
13433
13434 switch (elsize)
13435 {
13436 case 16:
13437 if (regno > 7 || elno > 3)
13438 goto bad_scalar;
13439 return regno | (elno << 3);
5f4273c7 13440
5287ad62
JB
13441 case 32:
13442 if (regno > 15 || elno > 1)
13443 goto bad_scalar;
13444 return regno | (elno << 4);
13445
13446 default:
13447 bad_scalar:
dcbf9037 13448 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
13449 }
13450
13451 return 0;
13452}
13453
13454/* Encode multiply / multiply-accumulate scalar instructions. */
13455
13456static void
13457neon_mul_mac (struct neon_type_el et, int ubit)
13458{
dcbf9037
JB
13459 unsigned scalar;
13460
13461 /* Give a more helpful error message if we have an invalid type. */
13462 if (et.type == NT_invtype)
13463 return;
5f4273c7 13464
dcbf9037 13465 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
13466 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13467 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13468 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13469 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13470 inst.instruction |= LOW4 (scalar);
13471 inst.instruction |= HI1 (scalar) << 5;
13472 inst.instruction |= (et.type == NT_float) << 8;
13473 inst.instruction |= neon_logbits (et.size) << 20;
13474 inst.instruction |= (ubit != 0) << 24;
13475
88714cb8 13476 neon_dp_fixup (&inst);
5287ad62
JB
13477}
13478
13479static void
13480do_neon_mac_maybe_scalar (void)
13481{
037e8744
JB
13482 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13483 return;
13484
13485 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13486 return;
13487
5287ad62
JB
13488 if (inst.operands[2].isscalar)
13489 {
037e8744 13490 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13491 struct neon_type_el et = neon_check_type (3, rs,
13492 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 13493 NEON_ENCODE (SCALAR, inst);
037e8744 13494 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13495 }
13496 else
428e3f1f
PB
13497 {
13498 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13499 affected if we specify unsigned args. */
13500 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13501 }
5287ad62
JB
13502}
13503
62f3b8c8
PB
13504static void
13505do_neon_fmac (void)
13506{
13507 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13508 return;
13509
13510 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13511 return;
13512
13513 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13514}
13515
5287ad62
JB
13516static void
13517do_neon_tst (void)
13518{
037e8744 13519 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13520 struct neon_type_el et = neon_check_type (3, rs,
13521 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 13522 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13523}
13524
13525/* VMUL with 3 registers allows the P8 type. The scalar version supports the
13526 same types as the MAC equivalents. The polynomial type for this instruction
13527 is encoded the same as the integer type. */
13528
13529static void
13530do_neon_mul (void)
13531{
037e8744
JB
13532 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13533 return;
13534
13535 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13536 return;
13537
5287ad62
JB
13538 if (inst.operands[2].isscalar)
13539 do_neon_mac_maybe_scalar ();
13540 else
dcbf9037 13541 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
13542}
13543
13544static void
13545do_neon_qdmulh (void)
13546{
13547 if (inst.operands[2].isscalar)
13548 {
037e8744 13549 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13550 struct neon_type_el et = neon_check_type (3, rs,
13551 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13552 NEON_ENCODE (SCALAR, inst);
037e8744 13553 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13554 }
13555 else
13556 {
037e8744 13557 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13558 struct neon_type_el et = neon_check_type (3, rs,
13559 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13560 NEON_ENCODE (INTEGER, inst);
5287ad62 13561 /* The U bit (rounding) comes from bit mask. */
037e8744 13562 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13563 }
13564}
13565
13566static void
13567do_neon_fcmp_absolute (void)
13568{
037e8744 13569 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13570 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13571 /* Size field comes from bit mask. */
037e8744 13572 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
13573}
13574
13575static void
13576do_neon_fcmp_absolute_inv (void)
13577{
13578 neon_exchange_operands ();
13579 do_neon_fcmp_absolute ();
13580}
13581
13582static void
13583do_neon_step (void)
13584{
037e8744 13585 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 13586 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 13587 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13588}
13589
13590static void
13591do_neon_abs_neg (void)
13592{
037e8744
JB
13593 enum neon_shape rs;
13594 struct neon_type_el et;
5f4273c7 13595
037e8744
JB
13596 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13597 return;
13598
13599 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13600 return;
13601
13602 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13603 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 13604
5287ad62
JB
13605 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13606 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13607 inst.instruction |= LOW4 (inst.operands[1].reg);
13608 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13609 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13610 inst.instruction |= (et.type == NT_float) << 10;
13611 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13612
88714cb8 13613 neon_dp_fixup (&inst);
5287ad62
JB
13614}
13615
13616static void
13617do_neon_sli (void)
13618{
037e8744 13619 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13620 struct neon_type_el et = neon_check_type (2, rs,
13621 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13622 int imm = inst.operands[2].imm;
13623 constraint (imm < 0 || (unsigned)imm >= et.size,
13624 _("immediate out of range for insert"));
037e8744 13625 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13626}
13627
13628static void
13629do_neon_sri (void)
13630{
037e8744 13631 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13632 struct neon_type_el et = neon_check_type (2, rs,
13633 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13634 int imm = inst.operands[2].imm;
13635 constraint (imm < 1 || (unsigned)imm > et.size,
13636 _("immediate out of range for insert"));
037e8744 13637 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
13638}
13639
13640static void
13641do_neon_qshlu_imm (void)
13642{
037e8744 13643 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13644 struct neon_type_el et = neon_check_type (2, rs,
13645 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13646 int imm = inst.operands[2].imm;
13647 constraint (imm < 0 || (unsigned)imm >= et.size,
13648 _("immediate out of range for shift"));
13649 /* Only encodes the 'U present' variant of the instruction.
13650 In this case, signed types have OP (bit 8) set to 0.
13651 Unsigned types have OP set to 1. */
13652 inst.instruction |= (et.type == NT_unsigned) << 8;
13653 /* The rest of the bits are the same as other immediate shifts. */
037e8744 13654 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13655}
13656
13657static void
13658do_neon_qmovn (void)
13659{
13660 struct neon_type_el et = neon_check_type (2, NS_DQ,
13661 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13662 /* Saturating move where operands can be signed or unsigned, and the
13663 destination has the same signedness. */
88714cb8 13664 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13665 if (et.type == NT_unsigned)
13666 inst.instruction |= 0xc0;
13667 else
13668 inst.instruction |= 0x80;
13669 neon_two_same (0, 1, et.size / 2);
13670}
13671
13672static void
13673do_neon_qmovun (void)
13674{
13675 struct neon_type_el et = neon_check_type (2, NS_DQ,
13676 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13677 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 13678 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13679 neon_two_same (0, 1, et.size / 2);
13680}
13681
13682static void
13683do_neon_rshift_sat_narrow (void)
13684{
13685 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13686 or unsigned. If operands are unsigned, results must also be unsigned. */
13687 struct neon_type_el et = neon_check_type (2, NS_DQI,
13688 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13689 int imm = inst.operands[2].imm;
13690 /* This gets the bounds check, size encoding and immediate bits calculation
13691 right. */
13692 et.size /= 2;
5f4273c7 13693
5287ad62
JB
13694 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13695 VQMOVN.I<size> <Dd>, <Qm>. */
13696 if (imm == 0)
13697 {
13698 inst.operands[2].present = 0;
13699 inst.instruction = N_MNEM_vqmovn;
13700 do_neon_qmovn ();
13701 return;
13702 }
5f4273c7 13703
5287ad62
JB
13704 constraint (imm < 1 || (unsigned)imm > et.size,
13705 _("immediate out of range"));
13706 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13707}
13708
13709static void
13710do_neon_rshift_sat_narrow_u (void)
13711{
13712 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13713 or unsigned. If operands are unsigned, results must also be unsigned. */
13714 struct neon_type_el et = neon_check_type (2, NS_DQI,
13715 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13716 int imm = inst.operands[2].imm;
13717 /* This gets the bounds check, size encoding and immediate bits calculation
13718 right. */
13719 et.size /= 2;
13720
13721 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13722 VQMOVUN.I<size> <Dd>, <Qm>. */
13723 if (imm == 0)
13724 {
13725 inst.operands[2].present = 0;
13726 inst.instruction = N_MNEM_vqmovun;
13727 do_neon_qmovun ();
13728 return;
13729 }
13730
13731 constraint (imm < 1 || (unsigned)imm > et.size,
13732 _("immediate out of range"));
13733 /* FIXME: The manual is kind of unclear about what value U should have in
13734 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13735 must be 1. */
13736 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13737}
13738
13739static void
13740do_neon_movn (void)
13741{
13742 struct neon_type_el et = neon_check_type (2, NS_DQ,
13743 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 13744 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13745 neon_two_same (0, 1, et.size / 2);
13746}
13747
13748static void
13749do_neon_rshift_narrow (void)
13750{
13751 struct neon_type_el et = neon_check_type (2, NS_DQI,
13752 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13753 int imm = inst.operands[2].imm;
13754 /* This gets the bounds check, size encoding and immediate bits calculation
13755 right. */
13756 et.size /= 2;
5f4273c7 13757
5287ad62
JB
13758 /* If immediate is zero then we are a pseudo-instruction for
13759 VMOVN.I<size> <Dd>, <Qm> */
13760 if (imm == 0)
13761 {
13762 inst.operands[2].present = 0;
13763 inst.instruction = N_MNEM_vmovn;
13764 do_neon_movn ();
13765 return;
13766 }
5f4273c7 13767
5287ad62
JB
13768 constraint (imm < 1 || (unsigned)imm > et.size,
13769 _("immediate out of range for narrowing operation"));
13770 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13771}
13772
13773static void
13774do_neon_shll (void)
13775{
13776 /* FIXME: Type checking when lengthening. */
13777 struct neon_type_el et = neon_check_type (2, NS_QDI,
13778 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13779 unsigned imm = inst.operands[2].imm;
13780
13781 if (imm == et.size)
13782 {
13783 /* Maximum shift variant. */
88714cb8 13784 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13785 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13786 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13787 inst.instruction |= LOW4 (inst.operands[1].reg);
13788 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13789 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13790
88714cb8 13791 neon_dp_fixup (&inst);
5287ad62
JB
13792 }
13793 else
13794 {
13795 /* A more-specific type check for non-max versions. */
13796 et = neon_check_type (2, NS_QDI,
13797 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 13798 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13799 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13800 }
13801}
13802
037e8744 13803/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
13804 the current instruction is. */
13805
13806static int
13807neon_cvt_flavour (enum neon_shape rs)
13808{
037e8744
JB
13809#define CVT_VAR(C,X,Y) \
13810 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13811 if (et.type != NT_invtype) \
13812 { \
13813 inst.error = NULL; \
13814 return (C); \
5287ad62
JB
13815 }
13816 struct neon_type_el et;
037e8744
JB
13817 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13818 || rs == NS_FF) ? N_VFP : 0;
13819 /* The instruction versions which take an immediate take one register
13820 argument, which is extended to the width of the full register. Thus the
13821 "source" and "destination" registers must have the same width. Hack that
13822 here by making the size equal to the key (wider, in this case) operand. */
13823 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 13824
5287ad62
JB
13825 CVT_VAR (0, N_S32, N_F32);
13826 CVT_VAR (1, N_U32, N_F32);
13827 CVT_VAR (2, N_F32, N_S32);
13828 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
13829 /* Half-precision conversions. */
13830 CVT_VAR (4, N_F32, N_F16);
13831 CVT_VAR (5, N_F16, N_F32);
5f4273c7 13832
037e8744 13833 whole_reg = N_VFP;
5f4273c7 13834
037e8744 13835 /* VFP instructions. */
8e79c3df
CM
13836 CVT_VAR (6, N_F32, N_F64);
13837 CVT_VAR (7, N_F64, N_F32);
13838 CVT_VAR (8, N_S32, N_F64 | key);
13839 CVT_VAR (9, N_U32, N_F64 | key);
13840 CVT_VAR (10, N_F64 | key, N_S32);
13841 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 13842 /* VFP instructions with bitshift. */
8e79c3df
CM
13843 CVT_VAR (12, N_F32 | key, N_S16);
13844 CVT_VAR (13, N_F32 | key, N_U16);
13845 CVT_VAR (14, N_F64 | key, N_S16);
13846 CVT_VAR (15, N_F64 | key, N_U16);
13847 CVT_VAR (16, N_S16, N_F32 | key);
13848 CVT_VAR (17, N_U16, N_F32 | key);
13849 CVT_VAR (18, N_S16, N_F64 | key);
13850 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 13851
5287ad62
JB
13852 return -1;
13853#undef CVT_VAR
13854}
13855
037e8744
JB
13856/* Neon-syntax VFP conversions. */
13857
5287ad62 13858static void
037e8744 13859do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 13860{
037e8744 13861 const char *opname = 0;
5f4273c7 13862
037e8744 13863 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 13864 {
037e8744
JB
13865 /* Conversions with immediate bitshift. */
13866 const char *enc[] =
13867 {
13868 "ftosls",
13869 "ftouls",
13870 "fsltos",
13871 "fultos",
13872 NULL,
13873 NULL,
8e79c3df
CM
13874 NULL,
13875 NULL,
037e8744
JB
13876 "ftosld",
13877 "ftould",
13878 "fsltod",
13879 "fultod",
13880 "fshtos",
13881 "fuhtos",
13882 "fshtod",
13883 "fuhtod",
13884 "ftoshs",
13885 "ftouhs",
13886 "ftoshd",
13887 "ftouhd"
13888 };
13889
13890 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13891 {
13892 opname = enc[flavour];
13893 constraint (inst.operands[0].reg != inst.operands[1].reg,
13894 _("operands 0 and 1 must be the same register"));
13895 inst.operands[1] = inst.operands[2];
13896 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13897 }
5287ad62
JB
13898 }
13899 else
13900 {
037e8744
JB
13901 /* Conversions without bitshift. */
13902 const char *enc[] =
13903 {
13904 "ftosis",
13905 "ftouis",
13906 "fsitos",
13907 "fuitos",
8e79c3df
CM
13908 "NULL",
13909 "NULL",
037e8744
JB
13910 "fcvtsd",
13911 "fcvtds",
13912 "ftosid",
13913 "ftouid",
13914 "fsitod",
13915 "fuitod"
13916 };
13917
13918 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13919 opname = enc[flavour];
13920 }
13921
13922 if (opname)
13923 do_vfp_nsyn_opcode (opname);
13924}
13925
13926static void
13927do_vfp_nsyn_cvtz (void)
13928{
13929 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13930 int flavour = neon_cvt_flavour (rs);
13931 const char *enc[] =
13932 {
13933 "ftosizs",
13934 "ftouizs",
13935 NULL,
13936 NULL,
13937 NULL,
13938 NULL,
8e79c3df
CM
13939 NULL,
13940 NULL,
037e8744
JB
13941 "ftosizd",
13942 "ftouizd"
13943 };
13944
13945 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13946 do_vfp_nsyn_opcode (enc[flavour]);
13947}
f31fef98 13948
037e8744 13949static void
e3e535bc 13950do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
037e8744
JB
13951{
13952 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 13953 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
13954 int flavour = neon_cvt_flavour (rs);
13955
e3e535bc
NC
13956 /* PR11109: Handle round-to-zero for VCVT conversions. */
13957 if (round_to_zero
13958 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
13959 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
13960 && (rs == NS_FD || rs == NS_FF))
13961 {
13962 do_vfp_nsyn_cvtz ();
13963 return;
13964 }
13965
037e8744 13966 /* VFP rather than Neon conversions. */
8e79c3df 13967 if (flavour >= 6)
037e8744
JB
13968 {
13969 do_vfp_nsyn_cvt (rs, flavour);
13970 return;
13971 }
13972
13973 switch (rs)
13974 {
13975 case NS_DDI:
13976 case NS_QQI:
13977 {
35997600
NC
13978 unsigned immbits;
13979 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13980
037e8744
JB
13981 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13982 return;
13983
13984 /* Fixed-point conversion with #0 immediate is encoded as an
13985 integer conversion. */
13986 if (inst.operands[2].present && inst.operands[2].imm == 0)
13987 goto int_encode;
35997600 13988 immbits = 32 - inst.operands[2].imm;
88714cb8 13989 NEON_ENCODE (IMMED, inst);
037e8744
JB
13990 if (flavour != -1)
13991 inst.instruction |= enctab[flavour];
13992 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13993 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13994 inst.instruction |= LOW4 (inst.operands[1].reg);
13995 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13996 inst.instruction |= neon_quad (rs) << 6;
13997 inst.instruction |= 1 << 21;
13998 inst.instruction |= immbits << 16;
13999
88714cb8 14000 neon_dp_fixup (&inst);
037e8744
JB
14001 }
14002 break;
14003
14004 case NS_DD:
14005 case NS_QQ:
14006 int_encode:
14007 {
14008 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
14009
88714cb8 14010 NEON_ENCODE (INTEGER, inst);
037e8744
JB
14011
14012 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14013 return;
14014
14015 if (flavour != -1)
14016 inst.instruction |= enctab[flavour];
14017
14018 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14019 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14020 inst.instruction |= LOW4 (inst.operands[1].reg);
14021 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14022 inst.instruction |= neon_quad (rs) << 6;
14023 inst.instruction |= 2 << 18;
14024
88714cb8 14025 neon_dp_fixup (&inst);
037e8744
JB
14026 }
14027 break;
14028
8e79c3df
CM
14029 /* Half-precision conversions for Advanced SIMD -- neon. */
14030 case NS_QD:
14031 case NS_DQ:
14032
14033 if ((rs == NS_DQ)
14034 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14035 {
14036 as_bad (_("operand size must match register width"));
14037 break;
14038 }
14039
14040 if ((rs == NS_QD)
14041 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14042 {
14043 as_bad (_("operand size must match register width"));
14044 break;
14045 }
14046
14047 if (rs == NS_DQ)
14048 inst.instruction = 0x3b60600;
14049 else
14050 inst.instruction = 0x3b60700;
14051
14052 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14053 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14054 inst.instruction |= LOW4 (inst.operands[1].reg);
14055 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 14056 neon_dp_fixup (&inst);
8e79c3df
CM
14057 break;
14058
037e8744
JB
14059 default:
14060 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
14061 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 14062 }
5287ad62
JB
14063}
14064
e3e535bc
NC
14065static void
14066do_neon_cvtr (void)
14067{
14068 do_neon_cvt_1 (FALSE);
14069}
14070
14071static void
14072do_neon_cvt (void)
14073{
14074 do_neon_cvt_1 (TRUE);
14075}
14076
8e79c3df
CM
14077static void
14078do_neon_cvtb (void)
14079{
14080 inst.instruction = 0xeb20a40;
14081
14082 /* The sizes are attached to the mnemonic. */
14083 if (inst.vectype.el[0].type != NT_invtype
14084 && inst.vectype.el[0].size == 16)
14085 inst.instruction |= 0x00010000;
14086
14087 /* Programmer's syntax: the sizes are attached to the operands. */
14088 else if (inst.operands[0].vectype.type != NT_invtype
14089 && inst.operands[0].vectype.size == 16)
14090 inst.instruction |= 0x00010000;
14091
14092 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14093 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
14094 do_vfp_cond_or_thumb ();
14095}
14096
14097
14098static void
14099do_neon_cvtt (void)
14100{
14101 do_neon_cvtb ();
14102 inst.instruction |= 0x80;
14103}
14104
5287ad62
JB
14105static void
14106neon_move_immediate (void)
14107{
037e8744
JB
14108 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14109 struct neon_type_el et = neon_check_type (2, rs,
14110 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 14111 unsigned immlo, immhi = 0, immbits;
c96612cc 14112 int op, cmode, float_p;
5287ad62 14113
037e8744
JB
14114 constraint (et.type == NT_invtype,
14115 _("operand size must be specified for immediate VMOV"));
14116
5287ad62
JB
14117 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14118 op = (inst.instruction & (1 << 5)) != 0;
14119
14120 immlo = inst.operands[1].imm;
14121 if (inst.operands[1].regisimm)
14122 immhi = inst.operands[1].reg;
14123
14124 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14125 _("immediate has bits set outside the operand size"));
14126
c96612cc
JB
14127 float_p = inst.operands[1].immisfloat;
14128
14129 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 14130 et.size, et.type)) == FAIL)
5287ad62
JB
14131 {
14132 /* Invert relevant bits only. */
14133 neon_invert_size (&immlo, &immhi, et.size);
14134 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14135 with one or the other; those cases are caught by
14136 neon_cmode_for_move_imm. */
14137 op = !op;
c96612cc
JB
14138 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
14139 &op, et.size, et.type)) == FAIL)
5287ad62 14140 {
dcbf9037 14141 first_error (_("immediate out of range"));
5287ad62
JB
14142 return;
14143 }
14144 }
14145
14146 inst.instruction &= ~(1 << 5);
14147 inst.instruction |= op << 5;
14148
14149 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14150 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 14151 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14152 inst.instruction |= cmode << 8;
14153
14154 neon_write_immbits (immbits);
14155}
14156
14157static void
14158do_neon_mvn (void)
14159{
14160 if (inst.operands[1].isreg)
14161 {
037e8744 14162 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 14163
88714cb8 14164 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14165 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14166 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14167 inst.instruction |= LOW4 (inst.operands[1].reg);
14168 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14169 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14170 }
14171 else
14172 {
88714cb8 14173 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14174 neon_move_immediate ();
14175 }
14176
88714cb8 14177 neon_dp_fixup (&inst);
5287ad62
JB
14178}
14179
14180/* Encode instructions of form:
14181
14182 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 14183 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
14184
14185static void
14186neon_mixed_length (struct neon_type_el et, unsigned size)
14187{
14188 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14189 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14190 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14191 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14192 inst.instruction |= LOW4 (inst.operands[2].reg);
14193 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14194 inst.instruction |= (et.type == NT_unsigned) << 24;
14195 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14196
88714cb8 14197 neon_dp_fixup (&inst);
5287ad62
JB
14198}
14199
14200static void
14201do_neon_dyadic_long (void)
14202{
14203 /* FIXME: Type checking for lengthening op. */
14204 struct neon_type_el et = neon_check_type (3, NS_QDD,
14205 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14206 neon_mixed_length (et, et.size);
14207}
14208
14209static void
14210do_neon_abal (void)
14211{
14212 struct neon_type_el et = neon_check_type (3, NS_QDD,
14213 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14214 neon_mixed_length (et, et.size);
14215}
14216
14217static void
14218neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14219{
14220 if (inst.operands[2].isscalar)
14221 {
dcbf9037
JB
14222 struct neon_type_el et = neon_check_type (3, NS_QDS,
14223 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 14224 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14225 neon_mul_mac (et, et.type == NT_unsigned);
14226 }
14227 else
14228 {
14229 struct neon_type_el et = neon_check_type (3, NS_QDD,
14230 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 14231 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14232 neon_mixed_length (et, et.size);
14233 }
14234}
14235
14236static void
14237do_neon_mac_maybe_scalar_long (void)
14238{
14239 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14240}
14241
14242static void
14243do_neon_dyadic_wide (void)
14244{
14245 struct neon_type_el et = neon_check_type (3, NS_QQD,
14246 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14247 neon_mixed_length (et, et.size);
14248}
14249
14250static void
14251do_neon_dyadic_narrow (void)
14252{
14253 struct neon_type_el et = neon_check_type (3, NS_QDD,
14254 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
14255 /* Operand sign is unimportant, and the U bit is part of the opcode,
14256 so force the operand type to integer. */
14257 et.type = NT_integer;
5287ad62
JB
14258 neon_mixed_length (et, et.size / 2);
14259}
14260
14261static void
14262do_neon_mul_sat_scalar_long (void)
14263{
14264 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14265}
14266
14267static void
14268do_neon_vmull (void)
14269{
14270 if (inst.operands[2].isscalar)
14271 do_neon_mac_maybe_scalar_long ();
14272 else
14273 {
14274 struct neon_type_el et = neon_check_type (3, NS_QDD,
14275 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14276 if (et.type == NT_poly)
88714cb8 14277 NEON_ENCODE (POLY, inst);
5287ad62 14278 else
88714cb8 14279 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14280 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14281 zero. Should be OK as-is. */
14282 neon_mixed_length (et, et.size);
14283 }
14284}
14285
14286static void
14287do_neon_ext (void)
14288{
037e8744 14289 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
14290 struct neon_type_el et = neon_check_type (3, rs,
14291 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14292 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
14293
14294 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14295 _("shift out of range"));
5287ad62
JB
14296 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14297 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14298 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14299 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14300 inst.instruction |= LOW4 (inst.operands[2].reg);
14301 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 14302 inst.instruction |= neon_quad (rs) << 6;
5287ad62 14303 inst.instruction |= imm << 8;
5f4273c7 14304
88714cb8 14305 neon_dp_fixup (&inst);
5287ad62
JB
14306}
14307
14308static void
14309do_neon_rev (void)
14310{
037e8744 14311 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14312 struct neon_type_el et = neon_check_type (2, rs,
14313 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14314 unsigned op = (inst.instruction >> 7) & 3;
14315 /* N (width of reversed regions) is encoded as part of the bitmask. We
14316 extract it here to check the elements to be reversed are smaller.
14317 Otherwise we'd get a reserved instruction. */
14318 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 14319 gas_assert (elsize != 0);
5287ad62
JB
14320 constraint (et.size >= elsize,
14321 _("elements must be smaller than reversal region"));
037e8744 14322 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14323}
14324
14325static void
14326do_neon_dup (void)
14327{
14328 if (inst.operands[1].isscalar)
14329 {
037e8744 14330 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
14331 struct neon_type_el et = neon_check_type (2, rs,
14332 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 14333 unsigned sizebits = et.size >> 3;
dcbf9037 14334 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 14335 int logsize = neon_logbits (et.size);
dcbf9037 14336 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
14337
14338 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14339 return;
14340
88714cb8 14341 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14342 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14343 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14344 inst.instruction |= LOW4 (dm);
14345 inst.instruction |= HI1 (dm) << 5;
037e8744 14346 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14347 inst.instruction |= x << 17;
14348 inst.instruction |= sizebits << 16;
5f4273c7 14349
88714cb8 14350 neon_dp_fixup (&inst);
5287ad62
JB
14351 }
14352 else
14353 {
037e8744
JB
14354 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14355 struct neon_type_el et = neon_check_type (2, rs,
14356 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 14357 /* Duplicate ARM register to lanes of vector. */
88714cb8 14358 NEON_ENCODE (ARMREG, inst);
5287ad62
JB
14359 switch (et.size)
14360 {
14361 case 8: inst.instruction |= 0x400000; break;
14362 case 16: inst.instruction |= 0x000020; break;
14363 case 32: inst.instruction |= 0x000000; break;
14364 default: break;
14365 }
14366 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14367 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14368 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 14369 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
14370 /* The encoding for this instruction is identical for the ARM and Thumb
14371 variants, except for the condition field. */
037e8744 14372 do_vfp_cond_or_thumb ();
5287ad62
JB
14373 }
14374}
14375
14376/* VMOV has particularly many variations. It can be one of:
14377 0. VMOV<c><q> <Qd>, <Qm>
14378 1. VMOV<c><q> <Dd>, <Dm>
14379 (Register operations, which are VORR with Rm = Rn.)
14380 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14381 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14382 (Immediate loads.)
14383 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14384 (ARM register to scalar.)
14385 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14386 (Two ARM registers to vector.)
14387 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14388 (Scalar to ARM register.)
14389 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14390 (Vector to two ARM registers.)
037e8744
JB
14391 8. VMOV.F32 <Sd>, <Sm>
14392 9. VMOV.F64 <Dd>, <Dm>
14393 (VFP register moves.)
14394 10. VMOV.F32 <Sd>, #imm
14395 11. VMOV.F64 <Dd>, #imm
14396 (VFP float immediate load.)
14397 12. VMOV <Rd>, <Sm>
14398 (VFP single to ARM reg.)
14399 13. VMOV <Sd>, <Rm>
14400 (ARM reg to VFP single.)
14401 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14402 (Two ARM regs to two VFP singles.)
14403 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14404 (Two VFP singles to two ARM regs.)
5f4273c7 14405
037e8744
JB
14406 These cases can be disambiguated using neon_select_shape, except cases 1/9
14407 and 3/11 which depend on the operand type too.
5f4273c7 14408
5287ad62 14409 All the encoded bits are hardcoded by this function.
5f4273c7 14410
b7fc2769
JB
14411 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14412 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 14413
5287ad62 14414 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 14415 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
14416
14417static void
14418do_neon_mov (void)
14419{
037e8744
JB
14420 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14421 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14422 NS_NULL);
14423 struct neon_type_el et;
14424 const char *ldconst = 0;
5287ad62 14425
037e8744 14426 switch (rs)
5287ad62 14427 {
037e8744
JB
14428 case NS_DD: /* case 1/9. */
14429 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14430 /* It is not an error here if no type is given. */
14431 inst.error = NULL;
14432 if (et.type == NT_float && et.size == 64)
5287ad62 14433 {
037e8744
JB
14434 do_vfp_nsyn_opcode ("fcpyd");
14435 break;
5287ad62 14436 }
037e8744 14437 /* fall through. */
5287ad62 14438
037e8744
JB
14439 case NS_QQ: /* case 0/1. */
14440 {
14441 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14442 return;
14443 /* The architecture manual I have doesn't explicitly state which
14444 value the U bit should have for register->register moves, but
14445 the equivalent VORR instruction has U = 0, so do that. */
14446 inst.instruction = 0x0200110;
14447 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14448 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14449 inst.instruction |= LOW4 (inst.operands[1].reg);
14450 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14451 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14452 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14453 inst.instruction |= neon_quad (rs) << 6;
14454
88714cb8 14455 neon_dp_fixup (&inst);
037e8744
JB
14456 }
14457 break;
5f4273c7 14458
037e8744
JB
14459 case NS_DI: /* case 3/11. */
14460 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14461 inst.error = NULL;
14462 if (et.type == NT_float && et.size == 64)
5287ad62 14463 {
037e8744
JB
14464 /* case 11 (fconstd). */
14465 ldconst = "fconstd";
14466 goto encode_fconstd;
5287ad62 14467 }
037e8744
JB
14468 /* fall through. */
14469
14470 case NS_QI: /* case 2/3. */
14471 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14472 return;
14473 inst.instruction = 0x0800010;
14474 neon_move_immediate ();
88714cb8 14475 neon_dp_fixup (&inst);
5287ad62 14476 break;
5f4273c7 14477
037e8744
JB
14478 case NS_SR: /* case 4. */
14479 {
14480 unsigned bcdebits = 0;
91d6fa6a 14481 int logsize;
037e8744
JB
14482 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14483 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14484
91d6fa6a
NC
14485 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14486 logsize = neon_logbits (et.size);
14487
037e8744
JB
14488 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14489 _(BAD_FPU));
14490 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14491 && et.size != 32, _(BAD_FPU));
14492 constraint (et.type == NT_invtype, _("bad type for scalar"));
14493 constraint (x >= 64 / et.size, _("scalar index out of range"));
14494
14495 switch (et.size)
14496 {
14497 case 8: bcdebits = 0x8; break;
14498 case 16: bcdebits = 0x1; break;
14499 case 32: bcdebits = 0x0; break;
14500 default: ;
14501 }
14502
14503 bcdebits |= x << logsize;
14504
14505 inst.instruction = 0xe000b10;
14506 do_vfp_cond_or_thumb ();
14507 inst.instruction |= LOW4 (dn) << 16;
14508 inst.instruction |= HI1 (dn) << 7;
14509 inst.instruction |= inst.operands[1].reg << 12;
14510 inst.instruction |= (bcdebits & 3) << 5;
14511 inst.instruction |= (bcdebits >> 2) << 21;
14512 }
14513 break;
5f4273c7 14514
037e8744 14515 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 14516 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 14517 _(BAD_FPU));
b7fc2769 14518
037e8744
JB
14519 inst.instruction = 0xc400b10;
14520 do_vfp_cond_or_thumb ();
14521 inst.instruction |= LOW4 (inst.operands[0].reg);
14522 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14523 inst.instruction |= inst.operands[1].reg << 12;
14524 inst.instruction |= inst.operands[2].reg << 16;
14525 break;
5f4273c7 14526
037e8744
JB
14527 case NS_RS: /* case 6. */
14528 {
91d6fa6a 14529 unsigned logsize;
037e8744
JB
14530 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14531 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14532 unsigned abcdebits = 0;
14533
91d6fa6a
NC
14534 et = neon_check_type (2, NS_NULL,
14535 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14536 logsize = neon_logbits (et.size);
14537
037e8744
JB
14538 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14539 _(BAD_FPU));
14540 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14541 && et.size != 32, _(BAD_FPU));
14542 constraint (et.type == NT_invtype, _("bad type for scalar"));
14543 constraint (x >= 64 / et.size, _("scalar index out of range"));
14544
14545 switch (et.size)
14546 {
14547 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14548 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14549 case 32: abcdebits = 0x00; break;
14550 default: ;
14551 }
14552
14553 abcdebits |= x << logsize;
14554 inst.instruction = 0xe100b10;
14555 do_vfp_cond_or_thumb ();
14556 inst.instruction |= LOW4 (dn) << 16;
14557 inst.instruction |= HI1 (dn) << 7;
14558 inst.instruction |= inst.operands[0].reg << 12;
14559 inst.instruction |= (abcdebits & 3) << 5;
14560 inst.instruction |= (abcdebits >> 2) << 21;
14561 }
14562 break;
5f4273c7 14563
037e8744
JB
14564 case NS_RRD: /* case 7 (fmrrd). */
14565 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14566 _(BAD_FPU));
14567
14568 inst.instruction = 0xc500b10;
14569 do_vfp_cond_or_thumb ();
14570 inst.instruction |= inst.operands[0].reg << 12;
14571 inst.instruction |= inst.operands[1].reg << 16;
14572 inst.instruction |= LOW4 (inst.operands[2].reg);
14573 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14574 break;
5f4273c7 14575
037e8744
JB
14576 case NS_FF: /* case 8 (fcpys). */
14577 do_vfp_nsyn_opcode ("fcpys");
14578 break;
5f4273c7 14579
037e8744
JB
14580 case NS_FI: /* case 10 (fconsts). */
14581 ldconst = "fconsts";
14582 encode_fconstd:
14583 if (is_quarter_float (inst.operands[1].imm))
5287ad62 14584 {
037e8744
JB
14585 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14586 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
14587 }
14588 else
037e8744
JB
14589 first_error (_("immediate out of range"));
14590 break;
5f4273c7 14591
037e8744
JB
14592 case NS_RF: /* case 12 (fmrs). */
14593 do_vfp_nsyn_opcode ("fmrs");
14594 break;
5f4273c7 14595
037e8744
JB
14596 case NS_FR: /* case 13 (fmsr). */
14597 do_vfp_nsyn_opcode ("fmsr");
14598 break;
5f4273c7 14599
037e8744
JB
14600 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14601 (one of which is a list), but we have parsed four. Do some fiddling to
14602 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14603 expect. */
14604 case NS_RRFF: /* case 14 (fmrrs). */
14605 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14606 _("VFP registers must be adjacent"));
14607 inst.operands[2].imm = 2;
14608 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14609 do_vfp_nsyn_opcode ("fmrrs");
14610 break;
5f4273c7 14611
037e8744
JB
14612 case NS_FFRR: /* case 15 (fmsrr). */
14613 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14614 _("VFP registers must be adjacent"));
14615 inst.operands[1] = inst.operands[2];
14616 inst.operands[2] = inst.operands[3];
14617 inst.operands[0].imm = 2;
14618 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14619 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 14620 break;
5f4273c7 14621
5287ad62
JB
14622 default:
14623 abort ();
14624 }
14625}
14626
14627static void
14628do_neon_rshift_round_imm (void)
14629{
037e8744 14630 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14631 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14632 int imm = inst.operands[2].imm;
14633
14634 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14635 if (imm == 0)
14636 {
14637 inst.operands[2].present = 0;
14638 do_neon_mov ();
14639 return;
14640 }
14641
14642 constraint (imm < 1 || (unsigned)imm > et.size,
14643 _("immediate out of range for shift"));
037e8744 14644 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
14645 et.size - imm);
14646}
14647
14648static void
14649do_neon_movl (void)
14650{
14651 struct neon_type_el et = neon_check_type (2, NS_QD,
14652 N_EQK | N_DBL, N_SU_32 | N_KEY);
14653 unsigned sizebits = et.size >> 3;
14654 inst.instruction |= sizebits << 19;
14655 neon_two_same (0, et.type == NT_unsigned, -1);
14656}
14657
14658static void
14659do_neon_trn (void)
14660{
037e8744 14661 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14662 struct neon_type_el et = neon_check_type (2, rs,
14663 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 14664 NEON_ENCODE (INTEGER, inst);
037e8744 14665 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14666}
14667
14668static void
14669do_neon_zip_uzp (void)
14670{
037e8744 14671 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14672 struct neon_type_el et = neon_check_type (2, rs,
14673 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14674 if (rs == NS_DD && et.size == 32)
14675 {
14676 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14677 inst.instruction = N_MNEM_vtrn;
14678 do_neon_trn ();
14679 return;
14680 }
037e8744 14681 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14682}
14683
14684static void
14685do_neon_sat_abs_neg (void)
14686{
037e8744 14687 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14688 struct neon_type_el et = neon_check_type (2, rs,
14689 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14690 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14691}
14692
14693static void
14694do_neon_pair_long (void)
14695{
037e8744 14696 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14697 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14698 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14699 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 14700 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14701}
14702
14703static void
14704do_neon_recip_est (void)
14705{
037e8744 14706 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14707 struct neon_type_el et = neon_check_type (2, rs,
14708 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
14709 inst.instruction |= (et.type == NT_float) << 8;
037e8744 14710 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14711}
14712
14713static void
14714do_neon_cls (void)
14715{
037e8744 14716 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14717 struct neon_type_el et = neon_check_type (2, rs,
14718 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14719 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14720}
14721
14722static void
14723do_neon_clz (void)
14724{
037e8744 14725 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14726 struct neon_type_el et = neon_check_type (2, rs,
14727 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 14728 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14729}
14730
14731static void
14732do_neon_cnt (void)
14733{
037e8744 14734 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14735 struct neon_type_el et = neon_check_type (2, rs,
14736 N_EQK | N_INT, N_8 | N_KEY);
037e8744 14737 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14738}
14739
14740static void
14741do_neon_swp (void)
14742{
037e8744
JB
14743 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14744 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
14745}
14746
14747static void
14748do_neon_tbl_tbx (void)
14749{
14750 unsigned listlenbits;
dcbf9037 14751 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 14752
5287ad62
JB
14753 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14754 {
dcbf9037 14755 first_error (_("bad list length for table lookup"));
5287ad62
JB
14756 return;
14757 }
5f4273c7 14758
5287ad62
JB
14759 listlenbits = inst.operands[1].imm - 1;
14760 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14761 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14762 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14763 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14764 inst.instruction |= LOW4 (inst.operands[2].reg);
14765 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14766 inst.instruction |= listlenbits << 8;
5f4273c7 14767
88714cb8 14768 neon_dp_fixup (&inst);
5287ad62
JB
14769}
14770
14771static void
14772do_neon_ldm_stm (void)
14773{
14774 /* P, U and L bits are part of bitmask. */
14775 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14776 unsigned offsetbits = inst.operands[1].imm * 2;
14777
037e8744
JB
14778 if (inst.operands[1].issingle)
14779 {
14780 do_vfp_nsyn_ldm_stm (is_dbmode);
14781 return;
14782 }
14783
5287ad62
JB
14784 constraint (is_dbmode && !inst.operands[0].writeback,
14785 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14786
14787 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14788 _("register list must contain at least 1 and at most 16 "
14789 "registers"));
14790
14791 inst.instruction |= inst.operands[0].reg << 16;
14792 inst.instruction |= inst.operands[0].writeback << 21;
14793 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14794 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14795
14796 inst.instruction |= offsetbits;
5f4273c7 14797
037e8744 14798 do_vfp_cond_or_thumb ();
5287ad62
JB
14799}
14800
14801static void
14802do_neon_ldr_str (void)
14803{
5287ad62 14804 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 14805
037e8744
JB
14806 if (inst.operands[0].issingle)
14807 {
cd2f129f
JB
14808 if (is_ldr)
14809 do_vfp_nsyn_opcode ("flds");
14810 else
14811 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
14812 }
14813 else
5287ad62 14814 {
cd2f129f
JB
14815 if (is_ldr)
14816 do_vfp_nsyn_opcode ("fldd");
5287ad62 14817 else
cd2f129f 14818 do_vfp_nsyn_opcode ("fstd");
5287ad62 14819 }
5287ad62
JB
14820}
14821
14822/* "interleave" version also handles non-interleaving register VLD1/VST1
14823 instructions. */
14824
14825static void
14826do_neon_ld_st_interleave (void)
14827{
037e8744 14828 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
14829 N_8 | N_16 | N_32 | N_64);
14830 unsigned alignbits = 0;
14831 unsigned idx;
14832 /* The bits in this table go:
14833 0: register stride of one (0) or two (1)
14834 1,2: register list length, minus one (1, 2, 3, 4).
14835 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14836 We use -1 for invalid entries. */
14837 const int typetable[] =
14838 {
14839 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14840 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14841 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14842 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14843 };
14844 int typebits;
14845
dcbf9037
JB
14846 if (et.type == NT_invtype)
14847 return;
14848
5287ad62
JB
14849 if (inst.operands[1].immisalign)
14850 switch (inst.operands[1].imm >> 8)
14851 {
14852 case 64: alignbits = 1; break;
14853 case 128:
e23c0ad8
JZ
14854 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
14855 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
14856 goto bad_alignment;
14857 alignbits = 2;
14858 break;
14859 case 256:
e23c0ad8 14860 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
14861 goto bad_alignment;
14862 alignbits = 3;
14863 break;
14864 default:
14865 bad_alignment:
dcbf9037 14866 first_error (_("bad alignment"));
5287ad62
JB
14867 return;
14868 }
14869
14870 inst.instruction |= alignbits << 4;
14871 inst.instruction |= neon_logbits (et.size) << 6;
14872
14873 /* Bits [4:6] of the immediate in a list specifier encode register stride
14874 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14875 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14876 up the right value for "type" in a table based on this value and the given
14877 list style, then stick it back. */
14878 idx = ((inst.operands[0].imm >> 4) & 7)
14879 | (((inst.instruction >> 8) & 3) << 3);
14880
14881 typebits = typetable[idx];
5f4273c7 14882
5287ad62
JB
14883 constraint (typebits == -1, _("bad list type for instruction"));
14884
14885 inst.instruction &= ~0xf00;
14886 inst.instruction |= typebits << 8;
14887}
14888
14889/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14890 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14891 otherwise. The variable arguments are a list of pairs of legal (size, align)
14892 values, terminated with -1. */
14893
14894static int
14895neon_alignment_bit (int size, int align, int *do_align, ...)
14896{
14897 va_list ap;
14898 int result = FAIL, thissize, thisalign;
5f4273c7 14899
5287ad62
JB
14900 if (!inst.operands[1].immisalign)
14901 {
14902 *do_align = 0;
14903 return SUCCESS;
14904 }
5f4273c7 14905
5287ad62
JB
14906 va_start (ap, do_align);
14907
14908 do
14909 {
14910 thissize = va_arg (ap, int);
14911 if (thissize == -1)
14912 break;
14913 thisalign = va_arg (ap, int);
14914
14915 if (size == thissize && align == thisalign)
14916 result = SUCCESS;
14917 }
14918 while (result != SUCCESS);
14919
14920 va_end (ap);
14921
14922 if (result == SUCCESS)
14923 *do_align = 1;
14924 else
dcbf9037 14925 first_error (_("unsupported alignment for instruction"));
5f4273c7 14926
5287ad62
JB
14927 return result;
14928}
14929
14930static void
14931do_neon_ld_st_lane (void)
14932{
037e8744 14933 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14934 int align_good, do_align = 0;
14935 int logsize = neon_logbits (et.size);
14936 int align = inst.operands[1].imm >> 8;
14937 int n = (inst.instruction >> 8) & 3;
14938 int max_el = 64 / et.size;
5f4273c7 14939
dcbf9037
JB
14940 if (et.type == NT_invtype)
14941 return;
5f4273c7 14942
5287ad62
JB
14943 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14944 _("bad list length"));
14945 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14946 _("scalar index out of range"));
14947 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14948 && et.size == 8,
14949 _("stride of 2 unavailable when element size is 8"));
5f4273c7 14950
5287ad62
JB
14951 switch (n)
14952 {
14953 case 0: /* VLD1 / VST1. */
14954 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14955 32, 32, -1);
14956 if (align_good == FAIL)
14957 return;
14958 if (do_align)
14959 {
14960 unsigned alignbits = 0;
14961 switch (et.size)
14962 {
14963 case 16: alignbits = 0x1; break;
14964 case 32: alignbits = 0x3; break;
14965 default: ;
14966 }
14967 inst.instruction |= alignbits << 4;
14968 }
14969 break;
14970
14971 case 1: /* VLD2 / VST2. */
14972 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14973 32, 64, -1);
14974 if (align_good == FAIL)
14975 return;
14976 if (do_align)
14977 inst.instruction |= 1 << 4;
14978 break;
14979
14980 case 2: /* VLD3 / VST3. */
14981 constraint (inst.operands[1].immisalign,
14982 _("can't use alignment with this instruction"));
14983 break;
14984
14985 case 3: /* VLD4 / VST4. */
14986 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14987 16, 64, 32, 64, 32, 128, -1);
14988 if (align_good == FAIL)
14989 return;
14990 if (do_align)
14991 {
14992 unsigned alignbits = 0;
14993 switch (et.size)
14994 {
14995 case 8: alignbits = 0x1; break;
14996 case 16: alignbits = 0x1; break;
14997 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14998 default: ;
14999 }
15000 inst.instruction |= alignbits << 4;
15001 }
15002 break;
15003
15004 default: ;
15005 }
15006
15007 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
15008 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15009 inst.instruction |= 1 << (4 + logsize);
5f4273c7 15010
5287ad62
JB
15011 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
15012 inst.instruction |= logsize << 10;
15013}
15014
15015/* Encode single n-element structure to all lanes VLD<n> instructions. */
15016
15017static void
15018do_neon_ld_dup (void)
15019{
037e8744 15020 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15021 int align_good, do_align = 0;
15022
dcbf9037
JB
15023 if (et.type == NT_invtype)
15024 return;
15025
5287ad62
JB
15026 switch ((inst.instruction >> 8) & 3)
15027 {
15028 case 0: /* VLD1. */
9c2799c2 15029 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
15030 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15031 &do_align, 16, 16, 32, 32, -1);
15032 if (align_good == FAIL)
15033 return;
15034 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15035 {
15036 case 1: break;
15037 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 15038 default: first_error (_("bad list length")); return;
5287ad62
JB
15039 }
15040 inst.instruction |= neon_logbits (et.size) << 6;
15041 break;
15042
15043 case 1: /* VLD2. */
15044 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15045 &do_align, 8, 16, 16, 32, 32, 64, -1);
15046 if (align_good == FAIL)
15047 return;
15048 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15049 _("bad list length"));
15050 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15051 inst.instruction |= 1 << 5;
15052 inst.instruction |= neon_logbits (et.size) << 6;
15053 break;
15054
15055 case 2: /* VLD3. */
15056 constraint (inst.operands[1].immisalign,
15057 _("can't use alignment with this instruction"));
15058 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15059 _("bad list length"));
15060 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15061 inst.instruction |= 1 << 5;
15062 inst.instruction |= neon_logbits (et.size) << 6;
15063 break;
15064
15065 case 3: /* VLD4. */
15066 {
15067 int align = inst.operands[1].imm >> 8;
15068 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15069 16, 64, 32, 64, 32, 128, -1);
15070 if (align_good == FAIL)
15071 return;
15072 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15073 _("bad list length"));
15074 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15075 inst.instruction |= 1 << 5;
15076 if (et.size == 32 && align == 128)
15077 inst.instruction |= 0x3 << 6;
15078 else
15079 inst.instruction |= neon_logbits (et.size) << 6;
15080 }
15081 break;
15082
15083 default: ;
15084 }
15085
15086 inst.instruction |= do_align << 4;
15087}
15088
15089/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15090 apart from bits [11:4]. */
15091
15092static void
15093do_neon_ldx_stx (void)
15094{
b1a769ed
DG
15095 if (inst.operands[1].isreg)
15096 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15097
5287ad62
JB
15098 switch (NEON_LANE (inst.operands[0].imm))
15099 {
15100 case NEON_INTERLEAVE_LANES:
88714cb8 15101 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
15102 do_neon_ld_st_interleave ();
15103 break;
5f4273c7 15104
5287ad62 15105 case NEON_ALL_LANES:
88714cb8 15106 NEON_ENCODE (DUP, inst);
5287ad62
JB
15107 do_neon_ld_dup ();
15108 break;
5f4273c7 15109
5287ad62 15110 default:
88714cb8 15111 NEON_ENCODE (LANE, inst);
5287ad62
JB
15112 do_neon_ld_st_lane ();
15113 }
15114
15115 /* L bit comes from bit mask. */
15116 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15117 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15118 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 15119
5287ad62
JB
15120 if (inst.operands[1].postind)
15121 {
15122 int postreg = inst.operands[1].imm & 0xf;
15123 constraint (!inst.operands[1].immisreg,
15124 _("post-index must be a register"));
15125 constraint (postreg == 0xd || postreg == 0xf,
15126 _("bad register for post-index"));
15127 inst.instruction |= postreg;
15128 }
15129 else if (inst.operands[1].writeback)
15130 {
15131 inst.instruction |= 0xd;
15132 }
15133 else
5f4273c7
NC
15134 inst.instruction |= 0xf;
15135
5287ad62
JB
15136 if (thumb_mode)
15137 inst.instruction |= 0xf9000000;
15138 else
15139 inst.instruction |= 0xf4000000;
15140}
5287ad62
JB
15141\f
15142/* Overall per-instruction processing. */
15143
15144/* We need to be able to fix up arbitrary expressions in some statements.
15145 This is so that we can handle symbols that are an arbitrary distance from
15146 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
15147 which returns part of an address in a form which will be valid for
15148 a data instruction. We do this by pushing the expression into a symbol
15149 in the expr_section, and creating a fix for that. */
15150
15151static void
15152fix_new_arm (fragS * frag,
15153 int where,
15154 short int size,
15155 expressionS * exp,
15156 int pc_rel,
15157 int reloc)
15158{
15159 fixS * new_fix;
15160
15161 switch (exp->X_op)
15162 {
15163 case O_constant:
15164 case O_symbol:
15165 case O_add:
15166 case O_subtract:
21d799b5
NC
15167 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
15168 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15169 break;
15170
15171 default:
21d799b5
NC
15172 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
15173 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15174 break;
15175 }
15176
15177 /* Mark whether the fix is to a THUMB instruction, or an ARM
15178 instruction. */
15179 new_fix->tc_fix_data = thumb_mode;
15180}
15181
15182/* Create a frg for an instruction requiring relaxation. */
15183static void
15184output_relax_insn (void)
15185{
15186 char * to;
15187 symbolS *sym;
0110f2b8
PB
15188 int offset;
15189
6e1cb1a6
PB
15190 /* The size of the instruction is unknown, so tie the debug info to the
15191 start of the instruction. */
15192 dwarf2_emit_insn (0);
6e1cb1a6 15193
0110f2b8
PB
15194 switch (inst.reloc.exp.X_op)
15195 {
15196 case O_symbol:
15197 sym = inst.reloc.exp.X_add_symbol;
15198 offset = inst.reloc.exp.X_add_number;
15199 break;
15200 case O_constant:
15201 sym = NULL;
15202 offset = inst.reloc.exp.X_add_number;
15203 break;
15204 default:
15205 sym = make_expr_symbol (&inst.reloc.exp);
15206 offset = 0;
15207 break;
15208 }
15209 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15210 inst.relax, sym, offset, NULL/*offset, opcode*/);
15211 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
15212}
15213
15214/* Write a 32-bit thumb instruction to buf. */
15215static void
15216put_thumb32_insn (char * buf, unsigned long insn)
15217{
15218 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15219 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15220}
15221
b99bd4ef 15222static void
c19d1205 15223output_inst (const char * str)
b99bd4ef 15224{
c19d1205 15225 char * to = NULL;
b99bd4ef 15226
c19d1205 15227 if (inst.error)
b99bd4ef 15228 {
c19d1205 15229 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
15230 return;
15231 }
5f4273c7
NC
15232 if (inst.relax)
15233 {
15234 output_relax_insn ();
0110f2b8 15235 return;
5f4273c7 15236 }
c19d1205
ZW
15237 if (inst.size == 0)
15238 return;
b99bd4ef 15239
c19d1205 15240 to = frag_more (inst.size);
8dc2430f
NC
15241 /* PR 9814: Record the thumb mode into the current frag so that we know
15242 what type of NOP padding to use, if necessary. We override any previous
15243 setting so that if the mode has changed then the NOPS that we use will
15244 match the encoding of the last instruction in the frag. */
cd000bff 15245 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
15246
15247 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 15248 {
9c2799c2 15249 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 15250 put_thumb32_insn (to, inst.instruction);
b99bd4ef 15251 }
c19d1205 15252 else if (inst.size > INSN_SIZE)
b99bd4ef 15253 {
9c2799c2 15254 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
15255 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15256 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 15257 }
c19d1205
ZW
15258 else
15259 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 15260
c19d1205
ZW
15261 if (inst.reloc.type != BFD_RELOC_UNUSED)
15262 fix_new_arm (frag_now, to - frag_now->fr_literal,
15263 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15264 inst.reloc.type);
b99bd4ef 15265
c19d1205 15266 dwarf2_emit_insn (inst.size);
c19d1205 15267}
b99bd4ef 15268
e07e6e58
NC
15269static char *
15270output_it_inst (int cond, int mask, char * to)
15271{
15272 unsigned long instruction = 0xbf00;
15273
15274 mask &= 0xf;
15275 instruction |= mask;
15276 instruction |= cond << 4;
15277
15278 if (to == NULL)
15279 {
15280 to = frag_more (2);
15281#ifdef OBJ_ELF
15282 dwarf2_emit_insn (2);
15283#endif
15284 }
15285
15286 md_number_to_chars (to, instruction, 2);
15287
15288 return to;
15289}
15290
c19d1205
ZW
15291/* Tag values used in struct asm_opcode's tag field. */
15292enum opcode_tag
15293{
15294 OT_unconditional, /* Instruction cannot be conditionalized.
15295 The ARM condition field is still 0xE. */
15296 OT_unconditionalF, /* Instruction cannot be conditionalized
15297 and carries 0xF in its ARM condition field. */
15298 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
15299 OT_csuffixF, /* Some forms of the instruction take a conditional
15300 suffix, others place 0xF where the condition field
15301 would be. */
c19d1205
ZW
15302 OT_cinfix3, /* Instruction takes a conditional infix,
15303 beginning at character index 3. (In
15304 unified mode, it becomes a suffix.) */
088fa78e
KH
15305 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15306 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
15307 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15308 character index 3, even in unified mode. Used for
15309 legacy instructions where suffix and infix forms
15310 may be ambiguous. */
c19d1205 15311 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 15312 suffix or an infix at character index 3. */
c19d1205
ZW
15313 OT_odd_infix_unc, /* This is the unconditional variant of an
15314 instruction that takes a conditional infix
15315 at an unusual position. In unified mode,
15316 this variant will accept a suffix. */
15317 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15318 are the conditional variants of instructions that
15319 take conditional infixes in unusual positions.
15320 The infix appears at character index
15321 (tag - OT_odd_infix_0). These are not accepted
15322 in unified mode. */
15323};
b99bd4ef 15324
c19d1205
ZW
15325/* Subroutine of md_assemble, responsible for looking up the primary
15326 opcode from the mnemonic the user wrote. STR points to the
15327 beginning of the mnemonic.
15328
15329 This is not simply a hash table lookup, because of conditional
15330 variants. Most instructions have conditional variants, which are
15331 expressed with a _conditional affix_ to the mnemonic. If we were
15332 to encode each conditional variant as a literal string in the opcode
15333 table, it would have approximately 20,000 entries.
15334
15335 Most mnemonics take this affix as a suffix, and in unified syntax,
15336 'most' is upgraded to 'all'. However, in the divided syntax, some
15337 instructions take the affix as an infix, notably the s-variants of
15338 the arithmetic instructions. Of those instructions, all but six
15339 have the infix appear after the third character of the mnemonic.
15340
15341 Accordingly, the algorithm for looking up primary opcodes given
15342 an identifier is:
15343
15344 1. Look up the identifier in the opcode table.
15345 If we find a match, go to step U.
15346
15347 2. Look up the last two characters of the identifier in the
15348 conditions table. If we find a match, look up the first N-2
15349 characters of the identifier in the opcode table. If we
15350 find a match, go to step CE.
15351
15352 3. Look up the fourth and fifth characters of the identifier in
15353 the conditions table. If we find a match, extract those
15354 characters from the identifier, and look up the remaining
15355 characters in the opcode table. If we find a match, go
15356 to step CM.
15357
15358 4. Fail.
15359
15360 U. Examine the tag field of the opcode structure, in case this is
15361 one of the six instructions with its conditional infix in an
15362 unusual place. If it is, the tag tells us where to find the
15363 infix; look it up in the conditions table and set inst.cond
15364 accordingly. Otherwise, this is an unconditional instruction.
15365 Again set inst.cond accordingly. Return the opcode structure.
15366
15367 CE. Examine the tag field to make sure this is an instruction that
15368 should receive a conditional suffix. If it is not, fail.
15369 Otherwise, set inst.cond from the suffix we already looked up,
15370 and return the opcode structure.
15371
15372 CM. Examine the tag field to make sure this is an instruction that
15373 should receive a conditional infix after the third character.
15374 If it is not, fail. Otherwise, undo the edits to the current
15375 line of input and proceed as for case CE. */
15376
15377static const struct asm_opcode *
15378opcode_lookup (char **str)
15379{
15380 char *end, *base;
15381 char *affix;
15382 const struct asm_opcode *opcode;
15383 const struct asm_cond *cond;
e3cb604e 15384 char save[2];
c19d1205
ZW
15385
15386 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 15387 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 15388 for (base = end = *str; *end != '\0'; end++)
721a8186 15389 if (*end == ' ' || *end == '.')
c19d1205 15390 break;
b99bd4ef 15391
c19d1205 15392 if (end == base)
c921be7d 15393 return NULL;
b99bd4ef 15394
5287ad62 15395 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 15396 if (end[0] == '.')
b99bd4ef 15397 {
5287ad62 15398 int offset = 2;
5f4273c7 15399
267d2029
JB
15400 /* The .w and .n suffixes are only valid if the unified syntax is in
15401 use. */
15402 if (unified_syntax && end[1] == 'w')
c19d1205 15403 inst.size_req = 4;
267d2029 15404 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
15405 inst.size_req = 2;
15406 else
5287ad62
JB
15407 offset = 0;
15408
15409 inst.vectype.elems = 0;
15410
15411 *str = end + offset;
b99bd4ef 15412
5f4273c7 15413 if (end[offset] == '.')
5287ad62 15414 {
267d2029
JB
15415 /* See if we have a Neon type suffix (possible in either unified or
15416 non-unified ARM syntax mode). */
dcbf9037 15417 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 15418 return NULL;
5287ad62
JB
15419 }
15420 else if (end[offset] != '\0' && end[offset] != ' ')
c921be7d 15421 return NULL;
b99bd4ef 15422 }
c19d1205
ZW
15423 else
15424 *str = end;
b99bd4ef 15425
c19d1205 15426 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5
NC
15427 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15428 end - base);
c19d1205 15429 if (opcode)
b99bd4ef 15430 {
c19d1205
ZW
15431 /* step U */
15432 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 15433 {
c19d1205
ZW
15434 inst.cond = COND_ALWAYS;
15435 return opcode;
b99bd4ef 15436 }
b99bd4ef 15437
278df34e 15438 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
15439 as_warn (_("conditional infixes are deprecated in unified syntax"));
15440 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 15441 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 15442 gas_assert (cond);
b99bd4ef 15443
c19d1205
ZW
15444 inst.cond = cond->value;
15445 return opcode;
15446 }
b99bd4ef 15447
c19d1205
ZW
15448 /* Cannot have a conditional suffix on a mnemonic of less than two
15449 characters. */
15450 if (end - base < 3)
c921be7d 15451 return NULL;
b99bd4ef 15452
c19d1205
ZW
15453 /* Look for suffixed mnemonic. */
15454 affix = end - 2;
21d799b5
NC
15455 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15456 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15457 affix - base);
c19d1205
ZW
15458 if (opcode && cond)
15459 {
15460 /* step CE */
15461 switch (opcode->tag)
15462 {
e3cb604e
PB
15463 case OT_cinfix3_legacy:
15464 /* Ignore conditional suffixes matched on infix only mnemonics. */
15465 break;
15466
c19d1205 15467 case OT_cinfix3:
088fa78e 15468 case OT_cinfix3_deprecated:
c19d1205
ZW
15469 case OT_odd_infix_unc:
15470 if (!unified_syntax)
e3cb604e 15471 return 0;
c19d1205
ZW
15472 /* else fall through */
15473
15474 case OT_csuffix:
037e8744 15475 case OT_csuffixF:
c19d1205
ZW
15476 case OT_csuf_or_in3:
15477 inst.cond = cond->value;
15478 return opcode;
15479
15480 case OT_unconditional:
15481 case OT_unconditionalF:
dfa9f0d5 15482 if (thumb_mode)
c921be7d 15483 inst.cond = cond->value;
dfa9f0d5
PB
15484 else
15485 {
c921be7d 15486 /* Delayed diagnostic. */
dfa9f0d5
PB
15487 inst.error = BAD_COND;
15488 inst.cond = COND_ALWAYS;
15489 }
c19d1205 15490 return opcode;
b99bd4ef 15491
c19d1205 15492 default:
c921be7d 15493 return NULL;
c19d1205
ZW
15494 }
15495 }
b99bd4ef 15496
c19d1205
ZW
15497 /* Cannot have a usual-position infix on a mnemonic of less than
15498 six characters (five would be a suffix). */
15499 if (end - base < 6)
c921be7d 15500 return NULL;
b99bd4ef 15501
c19d1205
ZW
15502 /* Look for infixed mnemonic in the usual position. */
15503 affix = base + 3;
21d799b5 15504 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 15505 if (!cond)
c921be7d 15506 return NULL;
e3cb604e
PB
15507
15508 memcpy (save, affix, 2);
15509 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5
NC
15510 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15511 (end - base) - 2);
e3cb604e
PB
15512 memmove (affix + 2, affix, (end - affix) - 2);
15513 memcpy (affix, save, 2);
15514
088fa78e
KH
15515 if (opcode
15516 && (opcode->tag == OT_cinfix3
15517 || opcode->tag == OT_cinfix3_deprecated
15518 || opcode->tag == OT_csuf_or_in3
15519 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 15520 {
c921be7d 15521 /* Step CM. */
278df34e 15522 if (warn_on_deprecated && unified_syntax
088fa78e
KH
15523 && (opcode->tag == OT_cinfix3
15524 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
15525 as_warn (_("conditional infixes are deprecated in unified syntax"));
15526
15527 inst.cond = cond->value;
15528 return opcode;
b99bd4ef
NC
15529 }
15530
c921be7d 15531 return NULL;
b99bd4ef
NC
15532}
15533
e07e6e58
NC
15534/* This function generates an initial IT instruction, leaving its block
15535 virtually open for the new instructions. Eventually,
15536 the mask will be updated by now_it_add_mask () each time
15537 a new instruction needs to be included in the IT block.
15538 Finally, the block is closed with close_automatic_it_block ().
15539 The block closure can be requested either from md_assemble (),
15540 a tencode (), or due to a label hook. */
15541
15542static void
15543new_automatic_it_block (int cond)
15544{
15545 now_it.state = AUTOMATIC_IT_BLOCK;
15546 now_it.mask = 0x18;
15547 now_it.cc = cond;
15548 now_it.block_length = 1;
cd000bff 15549 mapping_state (MAP_THUMB);
e07e6e58
NC
15550 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15551}
15552
15553/* Close an automatic IT block.
15554 See comments in new_automatic_it_block (). */
15555
15556static void
15557close_automatic_it_block (void)
15558{
15559 now_it.mask = 0x10;
15560 now_it.block_length = 0;
15561}
15562
15563/* Update the mask of the current automatically-generated IT
15564 instruction. See comments in new_automatic_it_block (). */
15565
15566static void
15567now_it_add_mask (int cond)
15568{
15569#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15570#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15571 | ((bitvalue) << (nbit)))
e07e6e58 15572 const int resulting_bit = (cond & 1);
c921be7d 15573
e07e6e58
NC
15574 now_it.mask &= 0xf;
15575 now_it.mask = SET_BIT_VALUE (now_it.mask,
15576 resulting_bit,
15577 (5 - now_it.block_length));
15578 now_it.mask = SET_BIT_VALUE (now_it.mask,
15579 1,
15580 ((5 - now_it.block_length) - 1) );
15581 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15582
15583#undef CLEAR_BIT
15584#undef SET_BIT_VALUE
e07e6e58
NC
15585}
15586
15587/* The IT blocks handling machinery is accessed through the these functions:
15588 it_fsm_pre_encode () from md_assemble ()
15589 set_it_insn_type () optional, from the tencode functions
15590 set_it_insn_type_last () ditto
15591 in_it_block () ditto
15592 it_fsm_post_encode () from md_assemble ()
15593 force_automatic_it_block_close () from label habdling functions
15594
15595 Rationale:
15596 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15597 initializing the IT insn type with a generic initial value depending
15598 on the inst.condition.
15599 2) During the tencode function, two things may happen:
15600 a) The tencode function overrides the IT insn type by
15601 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15602 b) The tencode function queries the IT block state by
15603 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15604
15605 Both set_it_insn_type and in_it_block run the internal FSM state
15606 handling function (handle_it_state), because: a) setting the IT insn
15607 type may incur in an invalid state (exiting the function),
15608 and b) querying the state requires the FSM to be updated.
15609 Specifically we want to avoid creating an IT block for conditional
15610 branches, so it_fsm_pre_encode is actually a guess and we can't
15611 determine whether an IT block is required until the tencode () routine
15612 has decided what type of instruction this actually it.
15613 Because of this, if set_it_insn_type and in_it_block have to be used,
15614 set_it_insn_type has to be called first.
15615
15616 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15617 determines the insn IT type depending on the inst.cond code.
15618 When a tencode () routine encodes an instruction that can be
15619 either outside an IT block, or, in the case of being inside, has to be
15620 the last one, set_it_insn_type_last () will determine the proper
15621 IT instruction type based on the inst.cond code. Otherwise,
15622 set_it_insn_type can be called for overriding that logic or
15623 for covering other cases.
15624
15625 Calling handle_it_state () may not transition the IT block state to
15626 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15627 still queried. Instead, if the FSM determines that the state should
15628 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15629 after the tencode () function: that's what it_fsm_post_encode () does.
15630
15631 Since in_it_block () calls the state handling function to get an
15632 updated state, an error may occur (due to invalid insns combination).
15633 In that case, inst.error is set.
15634 Therefore, inst.error has to be checked after the execution of
15635 the tencode () routine.
15636
15637 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15638 any pending state change (if any) that didn't take place in
15639 handle_it_state () as explained above. */
15640
15641static void
15642it_fsm_pre_encode (void)
15643{
15644 if (inst.cond != COND_ALWAYS)
15645 inst.it_insn_type = INSIDE_IT_INSN;
15646 else
15647 inst.it_insn_type = OUTSIDE_IT_INSN;
15648
15649 now_it.state_handled = 0;
15650}
15651
15652/* IT state FSM handling function. */
15653
15654static int
15655handle_it_state (void)
15656{
15657 now_it.state_handled = 1;
15658
15659 switch (now_it.state)
15660 {
15661 case OUTSIDE_IT_BLOCK:
15662 switch (inst.it_insn_type)
15663 {
15664 case OUTSIDE_IT_INSN:
15665 break;
15666
15667 case INSIDE_IT_INSN:
15668 case INSIDE_IT_LAST_INSN:
15669 if (thumb_mode == 0)
15670 {
c921be7d 15671 if (unified_syntax
e07e6e58
NC
15672 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15673 as_tsktsk (_("Warning: conditional outside an IT block"\
15674 " for Thumb."));
15675 }
15676 else
15677 {
15678 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15679 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15680 {
15681 /* Automatically generate the IT instruction. */
15682 new_automatic_it_block (inst.cond);
15683 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15684 close_automatic_it_block ();
15685 }
15686 else
15687 {
15688 inst.error = BAD_OUT_IT;
15689 return FAIL;
15690 }
15691 }
15692 break;
15693
15694 case IF_INSIDE_IT_LAST_INSN:
15695 case NEUTRAL_IT_INSN:
15696 break;
15697
15698 case IT_INSN:
15699 now_it.state = MANUAL_IT_BLOCK;
15700 now_it.block_length = 0;
15701 break;
15702 }
15703 break;
15704
15705 case AUTOMATIC_IT_BLOCK:
15706 /* Three things may happen now:
15707 a) We should increment current it block size;
15708 b) We should close current it block (closing insn or 4 insns);
15709 c) We should close current it block and start a new one (due
15710 to incompatible conditions or
15711 4 insns-length block reached). */
15712
15713 switch (inst.it_insn_type)
15714 {
15715 case OUTSIDE_IT_INSN:
15716 /* The closure of the block shall happen immediatelly,
15717 so any in_it_block () call reports the block as closed. */
15718 force_automatic_it_block_close ();
15719 break;
15720
15721 case INSIDE_IT_INSN:
15722 case INSIDE_IT_LAST_INSN:
15723 case IF_INSIDE_IT_LAST_INSN:
15724 now_it.block_length++;
15725
15726 if (now_it.block_length > 4
15727 || !now_it_compatible (inst.cond))
15728 {
15729 force_automatic_it_block_close ();
15730 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15731 new_automatic_it_block (inst.cond);
15732 }
15733 else
15734 {
15735 now_it_add_mask (inst.cond);
15736 }
15737
15738 if (now_it.state == AUTOMATIC_IT_BLOCK
15739 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15740 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15741 close_automatic_it_block ();
15742 break;
15743
15744 case NEUTRAL_IT_INSN:
15745 now_it.block_length++;
15746
15747 if (now_it.block_length > 4)
15748 force_automatic_it_block_close ();
15749 else
15750 now_it_add_mask (now_it.cc & 1);
15751 break;
15752
15753 case IT_INSN:
15754 close_automatic_it_block ();
15755 now_it.state = MANUAL_IT_BLOCK;
15756 break;
15757 }
15758 break;
15759
15760 case MANUAL_IT_BLOCK:
15761 {
15762 /* Check conditional suffixes. */
15763 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15764 int is_last;
15765 now_it.mask <<= 1;
15766 now_it.mask &= 0x1f;
15767 is_last = (now_it.mask == 0x10);
15768
15769 switch (inst.it_insn_type)
15770 {
15771 case OUTSIDE_IT_INSN:
15772 inst.error = BAD_NOT_IT;
15773 return FAIL;
15774
15775 case INSIDE_IT_INSN:
15776 if (cond != inst.cond)
15777 {
15778 inst.error = BAD_IT_COND;
15779 return FAIL;
15780 }
15781 break;
15782
15783 case INSIDE_IT_LAST_INSN:
15784 case IF_INSIDE_IT_LAST_INSN:
15785 if (cond != inst.cond)
15786 {
15787 inst.error = BAD_IT_COND;
15788 return FAIL;
15789 }
15790 if (!is_last)
15791 {
15792 inst.error = BAD_BRANCH;
15793 return FAIL;
15794 }
15795 break;
15796
15797 case NEUTRAL_IT_INSN:
15798 /* The BKPT instruction is unconditional even in an IT block. */
15799 break;
15800
15801 case IT_INSN:
15802 inst.error = BAD_IT_IT;
15803 return FAIL;
15804 }
15805 }
15806 break;
15807 }
15808
15809 return SUCCESS;
15810}
15811
15812static void
15813it_fsm_post_encode (void)
15814{
15815 int is_last;
15816
15817 if (!now_it.state_handled)
15818 handle_it_state ();
15819
15820 is_last = (now_it.mask == 0x10);
15821 if (is_last)
15822 {
15823 now_it.state = OUTSIDE_IT_BLOCK;
15824 now_it.mask = 0;
15825 }
15826}
15827
15828static void
15829force_automatic_it_block_close (void)
15830{
15831 if (now_it.state == AUTOMATIC_IT_BLOCK)
15832 {
15833 close_automatic_it_block ();
15834 now_it.state = OUTSIDE_IT_BLOCK;
15835 now_it.mask = 0;
15836 }
15837}
15838
15839static int
15840in_it_block (void)
15841{
15842 if (!now_it.state_handled)
15843 handle_it_state ();
15844
15845 return now_it.state != OUTSIDE_IT_BLOCK;
15846}
15847
c19d1205
ZW
15848void
15849md_assemble (char *str)
b99bd4ef 15850{
c19d1205
ZW
15851 char *p = str;
15852 const struct asm_opcode * opcode;
b99bd4ef 15853
c19d1205
ZW
15854 /* Align the previous label if needed. */
15855 if (last_label_seen != NULL)
b99bd4ef 15856 {
c19d1205
ZW
15857 symbol_set_frag (last_label_seen, frag_now);
15858 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15859 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
15860 }
15861
c19d1205
ZW
15862 memset (&inst, '\0', sizeof (inst));
15863 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 15864
c19d1205
ZW
15865 opcode = opcode_lookup (&p);
15866 if (!opcode)
b99bd4ef 15867 {
c19d1205 15868 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 15869 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d
NC
15870 if (! create_register_alias (str, p)
15871 && ! create_neon_reg_alias (str, p))
c19d1205 15872 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 15873
b99bd4ef
NC
15874 return;
15875 }
15876
278df34e 15877 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
15878 as_warn (_("s suffix on comparison instruction is deprecated"));
15879
037e8744
JB
15880 /* The value which unconditional instructions should have in place of the
15881 condition field. */
15882 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
15883
c19d1205 15884 if (thumb_mode)
b99bd4ef 15885 {
e74cfd16 15886 arm_feature_set variant;
8f06b2d8
PB
15887
15888 variant = cpu_variant;
15889 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
15890 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15891 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 15892 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
15893 if (!opcode->tvariant
15894 || (thumb_mode == 1
15895 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 15896 {
bf3eeda7 15897 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
b99bd4ef
NC
15898 return;
15899 }
c19d1205
ZW
15900 if (inst.cond != COND_ALWAYS && !unified_syntax
15901 && opcode->tencode != do_t_branch)
b99bd4ef 15902 {
c19d1205 15903 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
15904 return;
15905 }
15906
752d5da4 15907 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 15908 {
7e806470 15909 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
15910 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
15911 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
15912 {
15913 /* Two things are addressed here.
15914 1) Implicit require narrow instructions on Thumb-1.
15915 This avoids relaxation accidentally introducing Thumb-2
15916 instructions.
15917 2) Reject wide instructions in non Thumb-2 cores. */
15918 if (inst.size_req == 0)
15919 inst.size_req = 2;
15920 else if (inst.size_req == 4)
15921 {
bf3eeda7 15922 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
752d5da4
NC
15923 return;
15924 }
15925 }
076d447c
PB
15926 }
15927
c19d1205
ZW
15928 inst.instruction = opcode->tvalue;
15929
5be8be5d 15930 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
e07e6e58
NC
15931 {
15932 /* Prepare the it_insn_type for those encodings that don't set
15933 it. */
15934 it_fsm_pre_encode ();
c19d1205 15935
e07e6e58
NC
15936 opcode->tencode ();
15937
15938 it_fsm_post_encode ();
15939 }
e27ec89e 15940
0110f2b8 15941 if (!(inst.error || inst.relax))
b99bd4ef 15942 {
9c2799c2 15943 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
15944 inst.size = (inst.instruction > 0xffff ? 4 : 2);
15945 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 15946 {
c19d1205 15947 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
15948 return;
15949 }
15950 }
076d447c
PB
15951
15952 /* Something has gone badly wrong if we try to relax a fixed size
15953 instruction. */
9c2799c2 15954 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 15955
e74cfd16
PB
15956 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15957 *opcode->tvariant);
ee065d83 15958 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 15959 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 15960 anything other than bl/blx and v6-M instructions.
ee065d83 15961 This is overly pessimistic for relaxable instructions. */
7e806470
PB
15962 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
15963 || inst.relax)
e07e6e58
NC
15964 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15965 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
15966 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15967 arm_ext_v6t2);
cd000bff 15968
88714cb8
DG
15969 check_neon_suffixes;
15970
cd000bff 15971 if (!inst.error)
c877a2f2
NC
15972 {
15973 mapping_state (MAP_THUMB);
15974 }
c19d1205 15975 }
3e9e4fcf 15976 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 15977 {
845b51d6
PB
15978 bfd_boolean is_bx;
15979
15980 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
15981 is_bx = (opcode->aencode == do_bx);
15982
c19d1205 15983 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
15984 if (!(is_bx && fix_v4bx)
15985 && !(opcode->avariant &&
15986 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 15987 {
bf3eeda7 15988 as_bad (_("selected processor does not support ARM mode `%s'"), str);
c19d1205 15989 return;
b99bd4ef 15990 }
c19d1205 15991 if (inst.size_req)
b99bd4ef 15992 {
c19d1205
ZW
15993 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
15994 return;
b99bd4ef
NC
15995 }
15996
c19d1205
ZW
15997 inst.instruction = opcode->avalue;
15998 if (opcode->tag == OT_unconditionalF)
15999 inst.instruction |= 0xF << 28;
16000 else
16001 inst.instruction |= inst.cond << 28;
16002 inst.size = INSN_SIZE;
5be8be5d 16003 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
e07e6e58
NC
16004 {
16005 it_fsm_pre_encode ();
16006 opcode->aencode ();
16007 it_fsm_post_encode ();
16008 }
ee065d83
PB
16009 /* Arm mode bx is marked as both v4T and v5 because it's still required
16010 on a hypothetical non-thumb v5 core. */
845b51d6 16011 if (is_bx)
e74cfd16 16012 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 16013 else
e74cfd16
PB
16014 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
16015 *opcode->avariant);
88714cb8
DG
16016
16017 check_neon_suffixes;
16018
cd000bff 16019 if (!inst.error)
c877a2f2
NC
16020 {
16021 mapping_state (MAP_ARM);
16022 }
b99bd4ef 16023 }
3e9e4fcf
JB
16024 else
16025 {
16026 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
16027 "-- `%s'"), str);
16028 return;
16029 }
c19d1205
ZW
16030 output_inst (str);
16031}
b99bd4ef 16032
e07e6e58
NC
16033static void
16034check_it_blocks_finished (void)
16035{
16036#ifdef OBJ_ELF
16037 asection *sect;
16038
16039 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
16040 if (seg_info (sect)->tc_segment_info_data.current_it.state
16041 == MANUAL_IT_BLOCK)
16042 {
16043 as_warn (_("section '%s' finished with an open IT block."),
16044 sect->name);
16045 }
16046#else
16047 if (now_it.state == MANUAL_IT_BLOCK)
16048 as_warn (_("file finished with an open IT block."));
16049#endif
16050}
16051
c19d1205
ZW
16052/* Various frobbings of labels and their addresses. */
16053
16054void
16055arm_start_line_hook (void)
16056{
16057 last_label_seen = NULL;
b99bd4ef
NC
16058}
16059
c19d1205
ZW
16060void
16061arm_frob_label (symbolS * sym)
b99bd4ef 16062{
c19d1205 16063 last_label_seen = sym;
b99bd4ef 16064
c19d1205 16065 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 16066
c19d1205
ZW
16067#if defined OBJ_COFF || defined OBJ_ELF
16068 ARM_SET_INTERWORK (sym, support_interwork);
16069#endif
b99bd4ef 16070
e07e6e58
NC
16071 force_automatic_it_block_close ();
16072
5f4273c7 16073 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
16074 as Thumb functions. This is because these labels, whilst
16075 they exist inside Thumb code, are not the entry points for
16076 possible ARM->Thumb calls. Also, these labels can be used
16077 as part of a computed goto or switch statement. eg gcc
16078 can generate code that looks like this:
b99bd4ef 16079
c19d1205
ZW
16080 ldr r2, [pc, .Laaa]
16081 lsl r3, r3, #2
16082 ldr r2, [r3, r2]
16083 mov pc, r2
b99bd4ef 16084
c19d1205
ZW
16085 .Lbbb: .word .Lxxx
16086 .Lccc: .word .Lyyy
16087 ..etc...
16088 .Laaa: .word Lbbb
b99bd4ef 16089
c19d1205
ZW
16090 The first instruction loads the address of the jump table.
16091 The second instruction converts a table index into a byte offset.
16092 The third instruction gets the jump address out of the table.
16093 The fourth instruction performs the jump.
b99bd4ef 16094
c19d1205
ZW
16095 If the address stored at .Laaa is that of a symbol which has the
16096 Thumb_Func bit set, then the linker will arrange for this address
16097 to have the bottom bit set, which in turn would mean that the
16098 address computation performed by the third instruction would end
16099 up with the bottom bit set. Since the ARM is capable of unaligned
16100 word loads, the instruction would then load the incorrect address
16101 out of the jump table, and chaos would ensue. */
16102 if (label_is_thumb_function_name
16103 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
16104 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 16105 {
c19d1205
ZW
16106 /* When the address of a Thumb function is taken the bottom
16107 bit of that address should be set. This will allow
16108 interworking between Arm and Thumb functions to work
16109 correctly. */
b99bd4ef 16110
c19d1205 16111 THUMB_SET_FUNC (sym, 1);
b99bd4ef 16112
c19d1205 16113 label_is_thumb_function_name = FALSE;
b99bd4ef 16114 }
07a53e5c 16115
07a53e5c 16116 dwarf2_emit_label (sym);
b99bd4ef
NC
16117}
16118
c921be7d 16119bfd_boolean
c19d1205 16120arm_data_in_code (void)
b99bd4ef 16121{
c19d1205 16122 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 16123 {
c19d1205
ZW
16124 *input_line_pointer = '/';
16125 input_line_pointer += 5;
16126 *input_line_pointer = 0;
c921be7d 16127 return TRUE;
b99bd4ef
NC
16128 }
16129
c921be7d 16130 return FALSE;
b99bd4ef
NC
16131}
16132
c19d1205
ZW
16133char *
16134arm_canonicalize_symbol_name (char * name)
b99bd4ef 16135{
c19d1205 16136 int len;
b99bd4ef 16137
c19d1205
ZW
16138 if (thumb_mode && (len = strlen (name)) > 5
16139 && streq (name + len - 5, "/data"))
16140 *(name + len - 5) = 0;
b99bd4ef 16141
c19d1205 16142 return name;
b99bd4ef 16143}
c19d1205
ZW
16144\f
16145/* Table of all register names defined by default. The user can
16146 define additional names with .req. Note that all register names
16147 should appear in both upper and lowercase variants. Some registers
16148 also have mixed-case names. */
b99bd4ef 16149
dcbf9037 16150#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 16151#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 16152#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
16153#define REGSET(p,t) \
16154 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
16155 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
16156 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
16157 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
16158#define REGSETH(p,t) \
16159 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
16160 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
16161 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
16162 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
16163#define REGSET2(p,t) \
16164 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
16165 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
16166 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
16167 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 16168
c19d1205 16169static const struct reg_entry reg_names[] =
7ed4c4c5 16170{
c19d1205
ZW
16171 /* ARM integer registers. */
16172 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 16173
c19d1205
ZW
16174 /* ATPCS synonyms. */
16175 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
16176 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16177 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 16178
c19d1205
ZW
16179 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16180 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16181 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 16182
c19d1205
ZW
16183 /* Well-known aliases. */
16184 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16185 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16186
16187 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16188 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16189
16190 /* Coprocessor numbers. */
16191 REGSET(p, CP), REGSET(P, CP),
16192
16193 /* Coprocessor register numbers. The "cr" variants are for backward
16194 compatibility. */
16195 REGSET(c, CN), REGSET(C, CN),
16196 REGSET(cr, CN), REGSET(CR, CN),
16197
16198 /* FPA registers. */
16199 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16200 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16201
16202 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16203 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16204
16205 /* VFP SP registers. */
5287ad62
JB
16206 REGSET(s,VFS), REGSET(S,VFS),
16207 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
16208
16209 /* VFP DP Registers. */
5287ad62
JB
16210 REGSET(d,VFD), REGSET(D,VFD),
16211 /* Extra Neon DP registers. */
16212 REGSETH(d,VFD), REGSETH(D,VFD),
16213
16214 /* Neon QP registers. */
16215 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
16216
16217 /* VFP control registers. */
16218 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16219 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
16220 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16221 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16222 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16223 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
16224
16225 /* Maverick DSP coprocessor registers. */
16226 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16227 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16228
16229 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16230 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16231 REGDEF(dspsc,0,DSPSC),
16232
16233 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16234 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16235 REGDEF(DSPSC,0,DSPSC),
16236
16237 /* iWMMXt data registers - p0, c0-15. */
16238 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16239
16240 /* iWMMXt control registers - p1, c0-3. */
16241 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16242 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16243 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16244 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16245
16246 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16247 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16248 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16249 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16250 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16251
16252 /* XScale accumulator registers. */
16253 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16254};
16255#undef REGDEF
16256#undef REGNUM
16257#undef REGSET
7ed4c4c5 16258
c19d1205
ZW
16259/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16260 within psr_required_here. */
16261static const struct asm_psr psrs[] =
16262{
16263 /* Backward compatibility notation. Note that "all" is no longer
16264 truly all possible PSR bits. */
16265 {"all", PSR_c | PSR_f},
16266 {"flg", PSR_f},
16267 {"ctl", PSR_c},
16268
16269 /* Individual flags. */
16270 {"f", PSR_f},
16271 {"c", PSR_c},
16272 {"x", PSR_x},
16273 {"s", PSR_s},
59b42a0d
MGD
16274 {"g", PSR_s},
16275
c19d1205
ZW
16276 /* Combinations of flags. */
16277 {"fs", PSR_f | PSR_s},
16278 {"fx", PSR_f | PSR_x},
16279 {"fc", PSR_f | PSR_c},
16280 {"sf", PSR_s | PSR_f},
16281 {"sx", PSR_s | PSR_x},
16282 {"sc", PSR_s | PSR_c},
16283 {"xf", PSR_x | PSR_f},
16284 {"xs", PSR_x | PSR_s},
16285 {"xc", PSR_x | PSR_c},
16286 {"cf", PSR_c | PSR_f},
16287 {"cs", PSR_c | PSR_s},
16288 {"cx", PSR_c | PSR_x},
16289 {"fsx", PSR_f | PSR_s | PSR_x},
16290 {"fsc", PSR_f | PSR_s | PSR_c},
16291 {"fxs", PSR_f | PSR_x | PSR_s},
16292 {"fxc", PSR_f | PSR_x | PSR_c},
16293 {"fcs", PSR_f | PSR_c | PSR_s},
16294 {"fcx", PSR_f | PSR_c | PSR_x},
16295 {"sfx", PSR_s | PSR_f | PSR_x},
16296 {"sfc", PSR_s | PSR_f | PSR_c},
16297 {"sxf", PSR_s | PSR_x | PSR_f},
16298 {"sxc", PSR_s | PSR_x | PSR_c},
16299 {"scf", PSR_s | PSR_c | PSR_f},
16300 {"scx", PSR_s | PSR_c | PSR_x},
16301 {"xfs", PSR_x | PSR_f | PSR_s},
16302 {"xfc", PSR_x | PSR_f | PSR_c},
16303 {"xsf", PSR_x | PSR_s | PSR_f},
16304 {"xsc", PSR_x | PSR_s | PSR_c},
16305 {"xcf", PSR_x | PSR_c | PSR_f},
16306 {"xcs", PSR_x | PSR_c | PSR_s},
16307 {"cfs", PSR_c | PSR_f | PSR_s},
16308 {"cfx", PSR_c | PSR_f | PSR_x},
16309 {"csf", PSR_c | PSR_s | PSR_f},
16310 {"csx", PSR_c | PSR_s | PSR_x},
16311 {"cxf", PSR_c | PSR_x | PSR_f},
16312 {"cxs", PSR_c | PSR_x | PSR_s},
16313 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16314 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16315 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16316 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16317 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16318 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16319 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16320 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16321 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16322 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16323 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16324 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16325 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16326 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16327 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16328 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16329 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16330 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16331 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16332 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16333 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16334 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16335 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16336 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
59b42a0d
MGD
16337
16338 /* APSR flags */
16339 {"nzcvq", PSR_f},
16340 {"nzcvqg", PSR_s | PSR_f}
c19d1205
ZW
16341};
16342
62b3e311
PB
16343/* Table of V7M psr names. */
16344static const struct asm_psr v7m_psrs[] =
16345{
2b744c99
PB
16346 {"apsr", 0 }, {"APSR", 0 },
16347 {"iapsr", 1 }, {"IAPSR", 1 },
16348 {"eapsr", 2 }, {"EAPSR", 2 },
16349 {"psr", 3 }, {"PSR", 3 },
16350 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16351 {"ipsr", 5 }, {"IPSR", 5 },
16352 {"epsr", 6 }, {"EPSR", 6 },
16353 {"iepsr", 7 }, {"IEPSR", 7 },
16354 {"msp", 8 }, {"MSP", 8 },
16355 {"psp", 9 }, {"PSP", 9 },
16356 {"primask", 16}, {"PRIMASK", 16},
16357 {"basepri", 17}, {"BASEPRI", 17},
16358 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16359 {"faultmask", 19}, {"FAULTMASK", 19},
16360 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
16361};
16362
c19d1205
ZW
16363/* Table of all shift-in-operand names. */
16364static const struct asm_shift_name shift_names [] =
b99bd4ef 16365{
c19d1205
ZW
16366 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16367 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16368 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16369 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16370 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16371 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16372};
b99bd4ef 16373
c19d1205
ZW
16374/* Table of all explicit relocation names. */
16375#ifdef OBJ_ELF
16376static struct reloc_entry reloc_names[] =
16377{
16378 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16379 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16380 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16381 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16382 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16383 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16384 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16385 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16386 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16387 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6
NC
16388 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
16389 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}
c19d1205
ZW
16390};
16391#endif
b99bd4ef 16392
c19d1205
ZW
16393/* Table of all conditional affixes. 0xF is not defined as a condition code. */
16394static const struct asm_cond conds[] =
16395{
16396 {"eq", 0x0},
16397 {"ne", 0x1},
16398 {"cs", 0x2}, {"hs", 0x2},
16399 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16400 {"mi", 0x4},
16401 {"pl", 0x5},
16402 {"vs", 0x6},
16403 {"vc", 0x7},
16404 {"hi", 0x8},
16405 {"ls", 0x9},
16406 {"ge", 0xa},
16407 {"lt", 0xb},
16408 {"gt", 0xc},
16409 {"le", 0xd},
16410 {"al", 0xe}
16411};
bfae80f2 16412
62b3e311
PB
16413static struct asm_barrier_opt barrier_opt_names[] =
16414{
52e7f43d
RE
16415 { "sy", 0xf }, { "SY", 0xf },
16416 { "un", 0x7 }, { "UN", 0x7 },
16417 { "st", 0xe }, { "ST", 0xe },
16418 { "unst", 0x6 }, { "UNST", 0x6 },
16419 { "ish", 0xb }, { "ISH", 0xb },
16420 { "sh", 0xb }, { "SH", 0xb },
16421 { "ishst", 0xa }, { "ISHST", 0xa },
16422 { "shst", 0xa }, { "SHST", 0xa },
16423 { "nsh", 0x7 }, { "NSH", 0x7 },
16424 { "nshst", 0x6 }, { "NSHST", 0x6 },
16425 { "osh", 0x3 }, { "OSH", 0x3 },
16426 { "oshst", 0x2 }, { "OSHST", 0x2 }
62b3e311
PB
16427};
16428
c19d1205
ZW
16429/* Table of ARM-format instructions. */
16430
16431/* Macros for gluing together operand strings. N.B. In all cases
16432 other than OPS0, the trailing OP_stop comes from default
16433 zero-initialization of the unspecified elements of the array. */
16434#define OPS0() { OP_stop, }
16435#define OPS1(a) { OP_##a, }
16436#define OPS2(a,b) { OP_##a,OP_##b, }
16437#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16438#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16439#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16440#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16441
5be8be5d
DG
16442/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16443 This is useful when mixing operands for ARM and THUMB, i.e. using the
16444 MIX_ARM_THUMB_OPERANDS macro.
16445 In order to use these macros, prefix the number of operands with _
16446 e.g. _3. */
16447#define OPS_1(a) { a, }
16448#define OPS_2(a,b) { a,b, }
16449#define OPS_3(a,b,c) { a,b,c, }
16450#define OPS_4(a,b,c,d) { a,b,c,d, }
16451#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16452#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16453
c19d1205
ZW
16454/* These macros abstract out the exact format of the mnemonic table and
16455 save some repeated characters. */
16456
16457/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16458#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16459 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 16460 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16461
16462/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16463 a T_MNEM_xyz enumerator. */
16464#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16465 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16466#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16467 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16468
16469/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16470 infix after the third character. */
16471#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 16472 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 16473 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 16474#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 16475 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 16476 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 16477#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16478 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 16479#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16480 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16481#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16482 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 16483#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16484 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16485
16486/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16487 appear in the condition table. */
16488#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
21d799b5 16489 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
1887dd22 16490 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16491
16492#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
16493 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16494 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16495 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16496 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16497 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16498 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16499 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16500 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16501 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16502 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16503 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16504 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16505 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16506 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16507 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16508 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16509 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16510 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16511 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
16512
16513#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
16514 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16515#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
21d799b5 16516 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16517
16518/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
16519 field is still 0xE. Many of the Thumb variants can be executed
16520 conditionally, so this is checked separately. */
c19d1205 16521#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16522 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16523 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16524
16525/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16526 condition code field. */
16527#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 16528 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16529 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16530
16531/* ARM-only variants of all the above. */
6a86118a 16532#define CE(mnem, op, nops, ops, ae) \
21d799b5 16533 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
16534
16535#define C3(mnem, op, nops, ops, ae) \
16536 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16537
e3cb604e
PB
16538/* Legacy mnemonics that always have conditional infix after the third
16539 character. */
16540#define CL(mnem, op, nops, ops, ae) \
21d799b5 16541 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16542 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16543
8f06b2d8
PB
16544/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16545#define cCE(mnem, op, nops, ops, ae) \
21d799b5 16546 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16547
e3cb604e
PB
16548/* Legacy coprocessor instructions where conditional infix and conditional
16549 suffix are ambiguous. For consistency this includes all FPA instructions,
16550 not just the potentially ambiguous ones. */
16551#define cCL(mnem, op, nops, ops, ae) \
21d799b5 16552 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16553 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16554
16555/* Coprocessor, takes either a suffix or a position-3 infix
16556 (for an FPA corner case). */
16557#define C3E(mnem, op, nops, ops, ae) \
21d799b5 16558 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 16559 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16560
6a86118a 16561#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
16562 { m1 #m2 m3, OPS##nops ops, \
16563 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
16564 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16565
16566#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
16567 xCM_ (m1, , m2, op, nops, ops, ae), \
16568 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16569 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16570 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16571 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16572 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16573 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16574 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16575 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16576 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16577 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16578 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16579 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16580 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16581 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16582 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16583 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16584 xCM_ (m1, le, m2, op, nops, ops, ae), \
16585 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
16586
16587#define UE(mnem, op, nops, ops, ae) \
16588 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16589
16590#define UF(mnem, op, nops, ops, ae) \
16591 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16592
5287ad62
JB
16593/* Neon data-processing. ARM versions are unconditional with cond=0xf.
16594 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16595 use the same encoding function for each. */
16596#define NUF(mnem, op, nops, ops, enc) \
16597 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16598 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16599
16600/* Neon data processing, version which indirects through neon_enc_tab for
16601 the various overloaded versions of opcodes. */
16602#define nUF(mnem, op, nops, ops, enc) \
21d799b5 16603 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16604 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16605
16606/* Neon insn with conditional suffix for the ARM version, non-overloaded
16607 version. */
037e8744
JB
16608#define NCE_tag(mnem, op, nops, ops, enc, tag) \
16609 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
16610 THUMB_VARIANT, do_##enc, do_##enc }
16611
037e8744 16612#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 16613 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16614
16615#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 16616 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16617
5287ad62 16618/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 16619#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 16620 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16621 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16622
037e8744 16623#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 16624 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16625
16626#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 16627 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16628
c19d1205
ZW
16629#define do_0 0
16630
c19d1205 16631static const struct asm_opcode insns[] =
bfae80f2 16632{
e74cfd16
PB
16633#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
16634#define THUMB_VARIANT &arm_ext_v4t
21d799b5
NC
16635 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
16636 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
16637 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
16638 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
16639 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
16640 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
16641 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
16642 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
16643 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
16644 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
16645 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
16646 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
16647 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
16648 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
16649 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
16650 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
16651
16652 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
16653 for setting PSR flag bits. They are obsolete in V6 and do not
16654 have Thumb equivalents. */
21d799b5
NC
16655 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16656 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16657 CL("tstp", 110f000, 2, (RR, SH), cmp),
16658 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16659 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16660 CL("cmpp", 150f000, 2, (RR, SH), cmp),
16661 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16662 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16663 CL("cmnp", 170f000, 2, (RR, SH), cmp),
16664
16665 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
16666 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
16667 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
16668 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
16669
16670 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
16671 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16672 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
16673 OP_RRnpc),
16674 OP_ADDRGLDR),ldst, t_ldst),
16675 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
16676
16677 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16678 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16679 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16680 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16681 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16682 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16683
16684 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
16685 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
16686 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
16687 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 16688
c19d1205 16689 /* Pseudo ops. */
21d799b5 16690 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 16691 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 16692 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
16693
16694 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
16695 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
16696 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
16697 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
16698 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
16699 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
16700 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
16701 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
16702 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
16703 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
16704 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
16705 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
16706 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 16707
16a4cf17 16708 /* These may simplify to neg. */
21d799b5
NC
16709 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
16710 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 16711
c921be7d
NC
16712#undef THUMB_VARIANT
16713#define THUMB_VARIANT & arm_ext_v6
16714
21d799b5 16715 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
16716
16717 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
16718#undef THUMB_VARIANT
16719#define THUMB_VARIANT & arm_ext_v6t2
16720
21d799b5
NC
16721 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16722 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16723 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 16724
5be8be5d
DG
16725 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16726 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16727 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
16728 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 16729
21d799b5
NC
16730 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16731 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 16732
21d799b5
NC
16733 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16734 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
16735
16736 /* V1 instructions with no Thumb analogue at all. */
21d799b5 16737 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
16738 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16739
16740 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16741 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16742 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16743 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16744 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16745 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16746 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16747 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16748
c921be7d
NC
16749#undef ARM_VARIANT
16750#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
16751#undef THUMB_VARIANT
16752#define THUMB_VARIANT & arm_ext_v4t
16753
21d799b5
NC
16754 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16755 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 16756
c921be7d
NC
16757#undef THUMB_VARIANT
16758#define THUMB_VARIANT & arm_ext_v6t2
16759
21d799b5 16760 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
16761 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16762
16763 /* Generic coprocessor instructions. */
21d799b5
NC
16764 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16765 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16766 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16767 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16768 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16769 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 16770 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16771
c921be7d
NC
16772#undef ARM_VARIANT
16773#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
16774
21d799b5 16775 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
16776 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16777
c921be7d
NC
16778#undef ARM_VARIANT
16779#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
16780#undef THUMB_VARIANT
16781#define THUMB_VARIANT & arm_ext_msr
16782
21d799b5
NC
16783 TCE("mrs", 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
16784 TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205 16785
c921be7d
NC
16786#undef ARM_VARIANT
16787#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
16788#undef THUMB_VARIANT
16789#define THUMB_VARIANT & arm_ext_v6t2
16790
21d799b5
NC
16791 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16792 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16793 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16794 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16795 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16796 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16797 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16798 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 16799
c921be7d
NC
16800#undef ARM_VARIANT
16801#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
16802#undef THUMB_VARIANT
16803#define THUMB_VARIANT & arm_ext_v4t
16804
5be8be5d
DG
16805 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16806 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16807 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16808 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16809 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16810 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 16811
c921be7d
NC
16812#undef ARM_VARIANT
16813#define ARM_VARIANT & arm_ext_v4t_5
16814
c19d1205
ZW
16815 /* ARM Architecture 4T. */
16816 /* Note: bx (and blx) are required on V5, even if the processor does
16817 not support Thumb. */
21d799b5 16818 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 16819
c921be7d
NC
16820#undef ARM_VARIANT
16821#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
16822#undef THUMB_VARIANT
16823#define THUMB_VARIANT & arm_ext_v5t
16824
c19d1205
ZW
16825 /* Note: blx has 2 variants; the .value coded here is for
16826 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
16827 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
16828 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 16829
c921be7d
NC
16830#undef THUMB_VARIANT
16831#define THUMB_VARIANT & arm_ext_v6t2
16832
21d799b5
NC
16833 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
16834 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16835 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16836 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16837 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16838 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16839 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16840 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16841
c921be7d
NC
16842#undef ARM_VARIANT
16843#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
9e3c6df6
PB
16844#undef THUMB_VARIANT
16845#define THUMB_VARIANT &arm_ext_v5exp
c921be7d 16846
21d799b5
NC
16847 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16848 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16849 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16850 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 16851
21d799b5
NC
16852 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16853 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 16854
21d799b5
NC
16855 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16856 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16857 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16858 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 16859
21d799b5
NC
16860 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16861 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16862 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16863 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 16864
21d799b5
NC
16865 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16866 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 16867
03ee1b7f
NC
16868 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16869 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16870 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16871 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 16872
c921be7d
NC
16873#undef ARM_VARIANT
16874#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
9e3c6df6
PB
16875#undef THUMB_VARIANT
16876#define THUMB_VARIANT &arm_ext_v6t2
c921be7d 16877
21d799b5 16878 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
16879 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
16880 ldrd, t_ldstd),
16881 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
16882 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 16883
21d799b5
NC
16884 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16885 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 16886
c921be7d
NC
16887#undef ARM_VARIANT
16888#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
16889
21d799b5 16890 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 16891
c921be7d
NC
16892#undef ARM_VARIANT
16893#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
16894#undef THUMB_VARIANT
16895#define THUMB_VARIANT & arm_ext_v6
16896
21d799b5
NC
16897 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
16898 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
16899 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16900 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16901 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16902 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16903 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16904 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16905 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16906 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 16907
c921be7d
NC
16908#undef THUMB_VARIANT
16909#define THUMB_VARIANT & arm_ext_v6t2
16910
5be8be5d
DG
16911 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
16912 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16913 strex, t_strex),
21d799b5
NC
16914 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16915 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 16916
21d799b5
NC
16917 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
16918 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 16919
9e3c6df6 16920/* ARM V6 not included in V7M. */
c921be7d
NC
16921#undef THUMB_VARIANT
16922#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6
PB
16923 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16924 UF(rfeib, 9900a00, 1, (RRw), rfe),
16925 UF(rfeda, 8100a00, 1, (RRw), rfe),
16926 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16927 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16928 UF(rfefa, 9900a00, 1, (RRw), rfe),
16929 UF(rfeea, 8100a00, 1, (RRw), rfe),
16930 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16931 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
16932 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
16933 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
16934 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 16935
9e3c6df6
PB
16936/* ARM V6 not included in V7M (eg. integer SIMD). */
16937#undef THUMB_VARIANT
16938#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
16939 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
16940 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
16941 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
16942 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16943 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16944 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16945 /* Old name for QASX. */
21d799b5
NC
16946 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16947 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16948 /* Old name for QSAX. */
21d799b5
NC
16949 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16950 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16951 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16952 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16953 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16954 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16955 /* Old name for SASX. */
21d799b5
NC
16956 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16957 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16958 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16959 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16960 /* Old name for SHASX. */
21d799b5
NC
16961 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16962 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16963 /* Old name for SHSAX. */
21d799b5
NC
16964 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16965 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16966 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16967 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16968 /* Old name for SSAX. */
21d799b5
NC
16969 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16970 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16971 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16972 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16973 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16974 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16975 /* Old name for UASX. */
21d799b5
NC
16976 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16977 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16978 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16979 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16980 /* Old name for UHASX. */
21d799b5
NC
16981 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16982 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16983 /* Old name for UHSAX. */
21d799b5
NC
16984 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16985 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16986 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16987 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16988 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16989 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16990 /* Old name for UQASX. */
21d799b5
NC
16991 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16992 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16993 /* Old name for UQSAX. */
21d799b5
NC
16994 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16995 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16996 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16997 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16998 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16999 /* Old name for USAX. */
21d799b5
NC
17000 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17001 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
17002 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17003 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17004 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17005 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17006 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17007 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17008 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17009 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17010 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17011 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17012 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17013 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17014 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17015 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17016 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17017 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17018 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17019 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17020 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17021 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17022 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17023 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17024 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17025 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17026 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17027 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17028 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
17029 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
17030 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
17031 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17032 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17033 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 17034
c921be7d
NC
17035#undef ARM_VARIANT
17036#define ARM_VARIANT & arm_ext_v6k
17037#undef THUMB_VARIANT
17038#define THUMB_VARIANT & arm_ext_v6k
17039
21d799b5
NC
17040 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
17041 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
17042 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
17043 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 17044
c921be7d
NC
17045#undef THUMB_VARIANT
17046#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
17047 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
17048 ldrexd, t_ldrexd),
17049 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
17050 RRnpcb), strexd, t_strexd),
ebdca51a 17051
c921be7d
NC
17052#undef THUMB_VARIANT
17053#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
17054 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
17055 rd_rn, rd_rn),
17056 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
17057 rd_rn, rd_rn),
17058 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17059 strex, rm_rd_rn),
17060 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17061 strex, rm_rd_rn),
21d799b5 17062 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 17063
c921be7d 17064#undef ARM_VARIANT
f4c65163
MGD
17065#define ARM_VARIANT & arm_ext_sec
17066#undef THUMB_VARIANT
17067#define THUMB_VARIANT & arm_ext_sec
c921be7d 17068
21d799b5 17069 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 17070
c921be7d
NC
17071#undef ARM_VARIANT
17072#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
17073#undef THUMB_VARIANT
17074#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 17075
21d799b5
NC
17076 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
17077 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
17078 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17079 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 17080
21d799b5
NC
17081 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17082 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
17083 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
17084 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 17085
5be8be5d
DG
17086 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17087 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17088 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17089 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 17090
bf3eeda7
NS
17091 /* Thumb-only instructions. */
17092#undef ARM_VARIANT
17093#define ARM_VARIANT NULL
17094 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
17095 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
17096
17097 /* ARM does not really have an IT instruction, so always allow it.
17098 The opcode is copied from Thumb in order to allow warnings in
17099 -mimplicit-it=[never | arm] modes. */
17100#undef ARM_VARIANT
17101#define ARM_VARIANT & arm_ext_v1
17102
21d799b5
NC
17103 TUE("it", bf08, bf08, 1, (COND), it, t_it),
17104 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
17105 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
17106 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
17107 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
17108 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
17109 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
17110 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
17111 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
17112 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
17113 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
17114 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
17115 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
17116 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
17117 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 17118 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
17119 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
17120 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 17121
92e90b6e 17122 /* Thumb2 only instructions. */
c921be7d
NC
17123#undef ARM_VARIANT
17124#define ARM_VARIANT NULL
92e90b6e 17125
21d799b5
NC
17126 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17127 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17128 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
17129 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
17130 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
17131 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 17132
62b3e311 17133 /* Thumb-2 hardware division instructions (R and M profiles only). */
c921be7d
NC
17134#undef THUMB_VARIANT
17135#define THUMB_VARIANT & arm_ext_div
17136
21d799b5
NC
17137 TCE("sdiv", 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
17138 TCE("udiv", 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
62b3e311 17139
7e806470 17140 /* ARM V6M/V7 instructions. */
c921be7d
NC
17141#undef ARM_VARIANT
17142#define ARM_VARIANT & arm_ext_barrier
17143#undef THUMB_VARIANT
17144#define THUMB_VARIANT & arm_ext_barrier
17145
52e7f43d
RE
17146 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
17147 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
17148 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
7e806470 17149
62b3e311 17150 /* ARM V7 instructions. */
c921be7d
NC
17151#undef ARM_VARIANT
17152#define ARM_VARIANT & arm_ext_v7
17153#undef THUMB_VARIANT
17154#define THUMB_VARIANT & arm_ext_v7
17155
21d799b5
NC
17156 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
17157 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 17158
60e5ef9f
MGD
17159#undef ARM_VARIANT
17160#define ARM_VARIANT & arm_ext_mp
17161#undef THUMB_VARIANT
17162#define THUMB_VARIANT & arm_ext_mp
17163
17164 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
17165
c921be7d
NC
17166#undef ARM_VARIANT
17167#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
17168
21d799b5
NC
17169 cCE("wfs", e200110, 1, (RR), rd),
17170 cCE("rfs", e300110, 1, (RR), rd),
17171 cCE("wfc", e400110, 1, (RR), rd),
17172 cCE("rfc", e500110, 1, (RR), rd),
17173
17174 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
17175 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
17176 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
17177 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
17178
17179 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
17180 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
17181 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
17182 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
17183
17184 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
17185 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
17186 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
17187 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
17188 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
17189 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
17190 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
17191 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
17192 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
17193 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
17194 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
17195 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
17196
17197 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
17198 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
17199 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
17200 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
17201 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17202 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17203 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17204 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17205 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17206 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17207 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17208 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17209
17210 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17211 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17212 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17213 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17214 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17215 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17216 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17217 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17218 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17219 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17220 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17221 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17222
17223 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17224 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17225 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17226 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17227 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17228 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17229 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17230 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17231 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17232 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17233 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17234 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17235
17236 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17237 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17238 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17239 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17240 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17241 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17242 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17243 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17244 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17245 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17246 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17247 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17248
17249 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17250 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17251 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17252 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17253 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17254 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17255 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17256 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17257 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17258 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17259 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17260 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17261
17262 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17263 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17264 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17265 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17266 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17267 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17268 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17269 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17270 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17271 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17272 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17273 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17274
17275 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17276 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17277 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17278 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17279 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17280 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17281 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17282 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17283 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17284 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17285 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17286 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17287
17288 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17289 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17290 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17291 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17292 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17293 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17294 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17295 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17296 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17297 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17298 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17299 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17300
17301 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17302 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17303 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17304 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17305 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17306 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17307 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17308 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17309 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17310 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17311 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17312 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17313
17314 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17315 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17316 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17317 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17318 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17319 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17320 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17321 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17322 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17323 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17324 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17325 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17326
17327 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17328 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17329 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17330 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17331 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17332 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17333 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17334 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17335 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17336 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17337 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17338 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17339
17340 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17341 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17342 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17343 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17344 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17345 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17346 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17347 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17348 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17349 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17350 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17351 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17352
17353 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17354 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17355 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17356 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17357 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17358 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17359 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17360 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17361 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17362 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17363 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17364 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17365
17366 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17367 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17368 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17369 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17370 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17371 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17372 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17373 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17374 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17375 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17376 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17377 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17378
17379 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17380 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17381 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17382 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17383 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17384 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17385 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17386 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17387 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17388 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17389 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17390 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17391
17392 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17393 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17394 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17395 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17396 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17397 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17398 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17399 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17400 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17401 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17402 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17403 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17404
17405 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17406 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17407 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17408 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17409 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17410 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17411 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17412 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17413 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17414 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17415 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17416 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17417
17418 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17419 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17420 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17421 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17422 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17423 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17424 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17425 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17426 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17427 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17428 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17429 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17430
17431 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17432 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17433 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17434 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17435 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17436 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17437 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17438 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17439 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17440 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17441 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17442 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17443
17444 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17445 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17446 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17447 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17448 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17449 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17450 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17451 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17452 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17453 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17454 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17455 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17456
17457 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17458 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17459 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17460 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17461 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17462 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17463 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17464 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17465 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17466 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17467 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17468 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17469
17470 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17471 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17472 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17473 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17474 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17475 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17476 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17477 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17478 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17479 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17480 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17481 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17482
17483 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17484 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17485 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17486 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17487 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17488 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17489 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17490 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17491 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17492 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17493 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17494 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17495
17496 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17497 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17498 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17499 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17500 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17501 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17502 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17503 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17504 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17505 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17506 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17507 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17508
17509 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17510 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17511 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17512 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17513 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17514 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17515 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17516 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17517 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17518 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17519 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17520 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17521
17522 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17523 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17524 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17525 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17526 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17527 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17528 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17529 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17530 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17531 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17532 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17533 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17534
17535 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17536 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17537 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17538 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17539 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17540 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17541 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17542 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17543 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17544 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17545 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17546 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17547
17548 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17549 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17550 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17551 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17552 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17553 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17554 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17555 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17556 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17557 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17558 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17559 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17560
17561 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17562 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17563 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17564 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17565
17566 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17567 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17568 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17569 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17570 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17571 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17572 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17573 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17574 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17575 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17576 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17577 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 17578
c19d1205
ZW
17579 /* The implementation of the FIX instruction is broken on some
17580 assemblers, in that it accepts a precision specifier as well as a
17581 rounding specifier, despite the fact that this is meaningless.
17582 To be more compatible, we accept it as well, though of course it
17583 does not set any bits. */
21d799b5
NC
17584 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17585 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17586 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17587 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17588 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17589 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17590 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17591 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17592 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17593 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17594 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17595 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17596 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 17597
c19d1205 17598 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
17599#undef ARM_VARIANT
17600#define ARM_VARIANT & fpu_fpa_ext_v2
17601
21d799b5
NC
17602 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17603 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17604 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17605 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17606 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17607 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 17608
c921be7d
NC
17609#undef ARM_VARIANT
17610#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
17611
c19d1205 17612 /* Moves and type conversions. */
21d799b5
NC
17613 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
17614 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
17615 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
17616 cCE("fmstat", ef1fa10, 0, (), noargs),
f7c21dc7
NC
17617 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
17618 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
21d799b5
NC
17619 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
17620 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
17621 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
17622 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17623 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
17624 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17625 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
17626 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
17627
17628 /* Memory operations. */
21d799b5
NC
17629 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17630 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
17631 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17632 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17633 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17634 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17635 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17636 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17637 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17638 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17639 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17640 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17641 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17642 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17643 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17644 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17645 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17646 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 17647
c19d1205 17648 /* Monadic operations. */
21d799b5
NC
17649 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
17650 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
17651 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
17652
17653 /* Dyadic operations. */
21d799b5
NC
17654 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17655 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17656 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17657 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17658 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17659 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17660 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17661 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17662 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 17663
c19d1205 17664 /* Comparisons. */
21d799b5
NC
17665 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
17666 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
17667 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
17668 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 17669
62f3b8c8
PB
17670 /* Double precision load/store are still present on single precision
17671 implementations. */
17672 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17673 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
17674 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17675 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17676 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17677 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17678 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17679 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17680 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17681 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 17682
c921be7d
NC
17683#undef ARM_VARIANT
17684#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
17685
c19d1205 17686 /* Moves and type conversions. */
21d799b5
NC
17687 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17688 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17689 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17690 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
17691 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
17692 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
17693 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
17694 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17695 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
17696 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17697 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17698 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17699 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 17700
c19d1205 17701 /* Monadic operations. */
21d799b5
NC
17702 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17703 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17704 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
17705
17706 /* Dyadic operations. */
21d799b5
NC
17707 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17708 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17709 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17710 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17711 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17712 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17713 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17714 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17715 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 17716
c19d1205 17717 /* Comparisons. */
21d799b5
NC
17718 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17719 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
17720 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17721 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 17722
c921be7d
NC
17723#undef ARM_VARIANT
17724#define ARM_VARIANT & fpu_vfp_ext_v2
17725
21d799b5
NC
17726 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
17727 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
17728 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
17729 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 17730
037e8744
JB
17731/* Instructions which may belong to either the Neon or VFP instruction sets.
17732 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
17733#undef ARM_VARIANT
17734#define ARM_VARIANT & fpu_vfp_ext_v1xd
17735#undef THUMB_VARIANT
17736#define THUMB_VARIANT & fpu_vfp_ext_v1xd
17737
037e8744
JB
17738 /* These mnemonics are unique to VFP. */
17739 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
17740 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
17741 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17742 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17743 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17744 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17745 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
17746 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
17747 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
17748 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
17749
17750 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
17751 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
17752 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17753 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 17754
21d799b5
NC
17755 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17756 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
17757
17758 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17759 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17760
55881a11
MGD
17761 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17762 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17763 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17764 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17765 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17766 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
17767 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17768 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 17769
e3e535bc
NC
17770 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
17771 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
21d799b5
NC
17772 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
17773 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 17774
037e8744
JB
17775
17776 /* NOTE: All VMOV encoding is special-cased! */
17777 NCE(vmov, 0, 1, (VMOV), neon_mov),
17778 NCE(vmovq, 0, 1, (VMOV), neon_mov),
17779
c921be7d
NC
17780#undef THUMB_VARIANT
17781#define THUMB_VARIANT & fpu_neon_ext_v1
17782#undef ARM_VARIANT
17783#define ARM_VARIANT & fpu_neon_ext_v1
17784
5287ad62
JB
17785 /* Data processing with three registers of the same length. */
17786 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
17787 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
17788 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
17789 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17790 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17791 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17792 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17793 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17794 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17795 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17796 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17797 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17798 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17799 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
17800 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17801 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17802 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17803 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
17804 /* If not immediate, fall back to neon_dyadic_i64_su.
17805 shl_imm should accept I8 I16 I32 I64,
17806 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
17807 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17808 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17809 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17810 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 17811 /* Logic ops, types optional & ignored. */
4316f0d2
DG
17812 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17813 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17814 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17815 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17816 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17817 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17818 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17819 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17820 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
17821 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
17822 /* Bitfield ops, untyped. */
17823 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17824 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17825 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17826 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17827 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17828 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17829 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
17830 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17831 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17832 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17833 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17834 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17835 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
17836 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
17837 back to neon_dyadic_if_su. */
21d799b5
NC
17838 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17839 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17840 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17841 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17842 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17843 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17844 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17845 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 17846 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
17847 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
17848 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 17849 /* As above, D registers only. */
21d799b5
NC
17850 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17851 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 17852 /* Int and float variants, signedness unimportant. */
21d799b5
NC
17853 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17854 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17855 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 17856 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
17857 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17858 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
17859 /* vtst takes sizes 8, 16, 32. */
17860 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
17861 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
17862 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 17863 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 17864 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
17865 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17866 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17867 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17868 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
17869 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17870 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17871 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17872 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
17873 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17874 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17875 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17876 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
17877 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17878 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17879 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17880 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17881
17882 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 17883 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
17884 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
17885
17886 /* Data processing with two registers and a shift amount. */
17887 /* Right shifts, and variants with rounding.
17888 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
17889 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17890 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17891 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17892 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17893 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17894 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17895 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17896 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17897 /* Shift and insert. Sizes accepted 8 16 32 64. */
17898 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
17899 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
17900 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
17901 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
17902 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
17903 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
17904 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
17905 /* Right shift immediate, saturating & narrowing, with rounding variants.
17906 Types accepted S16 S32 S64 U16 U32 U64. */
17907 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17908 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17909 /* As above, unsigned. Types accepted S16 S32 S64. */
17910 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17911 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17912 /* Right shift narrowing. Types accepted I16 I32 I64. */
17913 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17914 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17915 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 17916 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 17917 /* CVT with optional immediate for fixed-point variant. */
21d799b5 17918 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 17919
4316f0d2
DG
17920 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
17921 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
17922
17923 /* Data processing, three registers of different lengths. */
17924 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
17925 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
17926 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
17927 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
17928 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
17929 /* If not scalar, fall back to neon_dyadic_long.
17930 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
17931 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17932 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
17933 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
17934 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17935 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17936 /* Dyadic, narrowing insns. Types I16 I32 I64. */
17937 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17938 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17939 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17940 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17941 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
17942 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17943 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17944 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
17945 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
17946 S16 S32 U16 U32. */
21d799b5 17947 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
17948
17949 /* Extract. Size 8. */
3b8d421e
PB
17950 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
17951 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
17952
17953 /* Two registers, miscellaneous. */
17954 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
17955 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
17956 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
17957 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
17958 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
17959 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
17960 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
17961 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
17962 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
17963 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
17964 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
17965 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
17966 /* VMOVN. Types I16 I32 I64. */
21d799b5 17967 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 17968 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 17969 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 17970 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 17971 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
17972 /* VZIP / VUZP. Sizes 8 16 32. */
17973 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
17974 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
17975 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
17976 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
17977 /* VQABS / VQNEG. Types S8 S16 S32. */
17978 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17979 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
17980 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17981 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
17982 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
17983 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
17984 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
17985 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
17986 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
17987 /* Reciprocal estimates. Types U32 F32. */
17988 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
17989 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
17990 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
17991 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
17992 /* VCLS. Types S8 S16 S32. */
17993 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
17994 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
17995 /* VCLZ. Types I8 I16 I32. */
17996 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
17997 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
17998 /* VCNT. Size 8. */
17999 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
18000 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
18001 /* Two address, untyped. */
18002 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
18003 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
18004 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
18005 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
18006 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
18007
18008 /* Table lookup. Size 8. */
18009 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18010 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18011
c921be7d
NC
18012#undef THUMB_VARIANT
18013#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
18014#undef ARM_VARIANT
18015#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
18016
5287ad62 18017 /* Neon element/structure load/store. */
21d799b5
NC
18018 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18019 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18020 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18021 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18022 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18023 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18024 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18025 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 18026
c921be7d 18027#undef THUMB_VARIANT
62f3b8c8
PB
18028#define THUMB_VARIANT &fpu_vfp_ext_v3xd
18029#undef ARM_VARIANT
18030#define ARM_VARIANT &fpu_vfp_ext_v3xd
18031 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
18032 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18033 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18034 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18035 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18036 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18037 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18038 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18039 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18040
18041#undef THUMB_VARIANT
c921be7d
NC
18042#define THUMB_VARIANT & fpu_vfp_ext_v3
18043#undef ARM_VARIANT
18044#define ARM_VARIANT & fpu_vfp_ext_v3
18045
21d799b5 18046 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 18047 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18048 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18049 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18050 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18051 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18052 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18053 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18054 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 18055
62f3b8c8
PB
18056#undef ARM_VARIANT
18057#define ARM_VARIANT &fpu_vfp_ext_fma
18058#undef THUMB_VARIANT
18059#define THUMB_VARIANT &fpu_vfp_ext_fma
18060 /* Mnemonics shared by Neon and VFP. These are included in the
18061 VFP FMA variant; NEON and VFP FMA always includes the NEON
18062 FMA instructions. */
18063 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18064 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18065 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
18066 the v form should always be used. */
18067 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18068 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18069 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18070 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18071 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18072 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18073
5287ad62 18074#undef THUMB_VARIANT
c921be7d
NC
18075#undef ARM_VARIANT
18076#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
18077
21d799b5
NC
18078 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18079 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18080 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18081 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18082 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18083 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18084 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
18085 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 18086
c921be7d
NC
18087#undef ARM_VARIANT
18088#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
18089
21d799b5
NC
18090 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
18091 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
18092 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
18093 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
18094 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
18095 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
18096 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
18097 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
18098 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
18099 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18100 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18101 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18102 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18103 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18104 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18105 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18106 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18107 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18108 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
18109 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
18110 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18111 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18112 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18113 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18114 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18115 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18116 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
18117 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
18118 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
18119 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
18120 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
18121 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
18122 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
18123 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
18124 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
18125 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
18126 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
18127 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18128 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18129 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18130 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18131 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18132 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18133 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18134 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18135 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18136 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
18137 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18138 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18139 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18140 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18141 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18142 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18143 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18144 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18145 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18146 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18147 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18148 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18149 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18150 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18151 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18152 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18153 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18154 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18155 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18156 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18157 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18158 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18159 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18160 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18161 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18162 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18163 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18164 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18165 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18166 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18167 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18168 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18169 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18170 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18171 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18172 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18173 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18174 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18175 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18176 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18177 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18178 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
18179 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18180 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18181 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18182 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18183 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18184 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18185 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18186 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18187 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18188 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18189 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18190 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18191 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18192 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18193 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18194 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18195 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18196 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18197 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18198 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18199 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18200 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
18201 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18202 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18203 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18204 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18205 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18206 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18207 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18208 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18209 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18210 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18211 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18212 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18213 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18214 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18215 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18216 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18217 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18218 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18219 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18220 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18221 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18222 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18223 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18224 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18225 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18226 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18227 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18228 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18229 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18230 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18231 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18232 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18233 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18234 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18235 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18236 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18237 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18238 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18239 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18240 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18241 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18242 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18243 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18244 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18245 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18246 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18247 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18248 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18249 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18250 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18251 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 18252
c921be7d
NC
18253#undef ARM_VARIANT
18254#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18255
21d799b5
NC
18256 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18257 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18258 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18259 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18260 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18261 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18262 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18263 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18264 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18265 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18266 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18267 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18268 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18269 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18270 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18271 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18272 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18273 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18274 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18275 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18276 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18277 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18278 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18279 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18280 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18281 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18282 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18283 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18284 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18285 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18286 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18287 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18288 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18289 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18290 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18291 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18292 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18293 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18294 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18295 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18296 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18297 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18298 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18299 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18300 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18301 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18302 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18303 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18304 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18305 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18306 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18307 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18308 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18309 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18310 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18311 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18312 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 18313
c921be7d
NC
18314#undef ARM_VARIANT
18315#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18316
21d799b5
NC
18317 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18318 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18319 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18320 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18321 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18322 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18323 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18324 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18325 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18326 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18327 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18328 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18329 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18330 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18331 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18332 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18333 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18334 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18335 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18336 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18337 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18338 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18339 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18340 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18341 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18342 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18343 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18344 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18345 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18346 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18347 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18348 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18349 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18350 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18351 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18352 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18353 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18354 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18355 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18356 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18357 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18358 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18359 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18360 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18361 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18362 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18363 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18364 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18365 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18366 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18367 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18368 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18369 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18370 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18371 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18372 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18373 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18374 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18375 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18376 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18377 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18378 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18379 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18380 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18381 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18382 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18383 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18384 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18385 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18386 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18387 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18388 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18389 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18390 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18391 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18392 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
18393};
18394#undef ARM_VARIANT
18395#undef THUMB_VARIANT
18396#undef TCE
18397#undef TCM
18398#undef TUE
18399#undef TUF
18400#undef TCC
8f06b2d8 18401#undef cCE
e3cb604e
PB
18402#undef cCL
18403#undef C3E
c19d1205
ZW
18404#undef CE
18405#undef CM
18406#undef UE
18407#undef UF
18408#undef UT
5287ad62
JB
18409#undef NUF
18410#undef nUF
18411#undef NCE
18412#undef nCE
c19d1205
ZW
18413#undef OPS0
18414#undef OPS1
18415#undef OPS2
18416#undef OPS3
18417#undef OPS4
18418#undef OPS5
18419#undef OPS6
18420#undef do_0
18421\f
18422/* MD interface: bits in the object file. */
bfae80f2 18423
c19d1205
ZW
18424/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18425 for use in the a.out file, and stores them in the array pointed to by buf.
18426 This knows about the endian-ness of the target machine and does
18427 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18428 2 (short) and 4 (long) Floating numbers are put out as a series of
18429 LITTLENUMS (shorts, here at least). */
b99bd4ef 18430
c19d1205
ZW
18431void
18432md_number_to_chars (char * buf, valueT val, int n)
18433{
18434 if (target_big_endian)
18435 number_to_chars_bigendian (buf, val, n);
18436 else
18437 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
18438}
18439
c19d1205
ZW
18440static valueT
18441md_chars_to_number (char * buf, int n)
bfae80f2 18442{
c19d1205
ZW
18443 valueT result = 0;
18444 unsigned char * where = (unsigned char *) buf;
bfae80f2 18445
c19d1205 18446 if (target_big_endian)
b99bd4ef 18447 {
c19d1205
ZW
18448 while (n--)
18449 {
18450 result <<= 8;
18451 result |= (*where++ & 255);
18452 }
b99bd4ef 18453 }
c19d1205 18454 else
b99bd4ef 18455 {
c19d1205
ZW
18456 while (n--)
18457 {
18458 result <<= 8;
18459 result |= (where[n] & 255);
18460 }
bfae80f2 18461 }
b99bd4ef 18462
c19d1205 18463 return result;
bfae80f2 18464}
b99bd4ef 18465
c19d1205 18466/* MD interface: Sections. */
b99bd4ef 18467
0110f2b8
PB
18468/* Estimate the size of a frag before relaxing. Assume everything fits in
18469 2 bytes. */
18470
c19d1205 18471int
0110f2b8 18472md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
18473 segT segtype ATTRIBUTE_UNUSED)
18474{
0110f2b8
PB
18475 fragp->fr_var = 2;
18476 return 2;
18477}
18478
18479/* Convert a machine dependent frag. */
18480
18481void
18482md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18483{
18484 unsigned long insn;
18485 unsigned long old_op;
18486 char *buf;
18487 expressionS exp;
18488 fixS *fixp;
18489 int reloc_type;
18490 int pc_rel;
18491 int opcode;
18492
18493 buf = fragp->fr_literal + fragp->fr_fix;
18494
18495 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
18496 if (fragp->fr_symbol)
18497 {
0110f2b8
PB
18498 exp.X_op = O_symbol;
18499 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
18500 }
18501 else
18502 {
0110f2b8 18503 exp.X_op = O_constant;
5f4273c7 18504 }
0110f2b8
PB
18505 exp.X_add_number = fragp->fr_offset;
18506 opcode = fragp->fr_subtype;
18507 switch (opcode)
18508 {
18509 case T_MNEM_ldr_pc:
18510 case T_MNEM_ldr_pc2:
18511 case T_MNEM_ldr_sp:
18512 case T_MNEM_str_sp:
18513 case T_MNEM_ldr:
18514 case T_MNEM_ldrb:
18515 case T_MNEM_ldrh:
18516 case T_MNEM_str:
18517 case T_MNEM_strb:
18518 case T_MNEM_strh:
18519 if (fragp->fr_var == 4)
18520 {
5f4273c7 18521 insn = THUMB_OP32 (opcode);
0110f2b8
PB
18522 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18523 {
18524 insn |= (old_op & 0x700) << 4;
18525 }
18526 else
18527 {
18528 insn |= (old_op & 7) << 12;
18529 insn |= (old_op & 0x38) << 13;
18530 }
18531 insn |= 0x00000c00;
18532 put_thumb32_insn (buf, insn);
18533 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18534 }
18535 else
18536 {
18537 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18538 }
18539 pc_rel = (opcode == T_MNEM_ldr_pc2);
18540 break;
18541 case T_MNEM_adr:
18542 if (fragp->fr_var == 4)
18543 {
18544 insn = THUMB_OP32 (opcode);
18545 insn |= (old_op & 0xf0) << 4;
18546 put_thumb32_insn (buf, insn);
18547 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18548 }
18549 else
18550 {
18551 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18552 exp.X_add_number -= 4;
18553 }
18554 pc_rel = 1;
18555 break;
18556 case T_MNEM_mov:
18557 case T_MNEM_movs:
18558 case T_MNEM_cmp:
18559 case T_MNEM_cmn:
18560 if (fragp->fr_var == 4)
18561 {
18562 int r0off = (opcode == T_MNEM_mov
18563 || opcode == T_MNEM_movs) ? 0 : 8;
18564 insn = THUMB_OP32 (opcode);
18565 insn = (insn & 0xe1ffffff) | 0x10000000;
18566 insn |= (old_op & 0x700) << r0off;
18567 put_thumb32_insn (buf, insn);
18568 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18569 }
18570 else
18571 {
18572 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18573 }
18574 pc_rel = 0;
18575 break;
18576 case T_MNEM_b:
18577 if (fragp->fr_var == 4)
18578 {
18579 insn = THUMB_OP32(opcode);
18580 put_thumb32_insn (buf, insn);
18581 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18582 }
18583 else
18584 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18585 pc_rel = 1;
18586 break;
18587 case T_MNEM_bcond:
18588 if (fragp->fr_var == 4)
18589 {
18590 insn = THUMB_OP32(opcode);
18591 insn |= (old_op & 0xf00) << 14;
18592 put_thumb32_insn (buf, insn);
18593 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18594 }
18595 else
18596 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18597 pc_rel = 1;
18598 break;
18599 case T_MNEM_add_sp:
18600 case T_MNEM_add_pc:
18601 case T_MNEM_inc_sp:
18602 case T_MNEM_dec_sp:
18603 if (fragp->fr_var == 4)
18604 {
18605 /* ??? Choose between add and addw. */
18606 insn = THUMB_OP32 (opcode);
18607 insn |= (old_op & 0xf0) << 4;
18608 put_thumb32_insn (buf, insn);
16805f35
PB
18609 if (opcode == T_MNEM_add_pc)
18610 reloc_type = BFD_RELOC_ARM_T32_IMM12;
18611 else
18612 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
18613 }
18614 else
18615 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18616 pc_rel = 0;
18617 break;
18618
18619 case T_MNEM_addi:
18620 case T_MNEM_addis:
18621 case T_MNEM_subi:
18622 case T_MNEM_subis:
18623 if (fragp->fr_var == 4)
18624 {
18625 insn = THUMB_OP32 (opcode);
18626 insn |= (old_op & 0xf0) << 4;
18627 insn |= (old_op & 0xf) << 16;
18628 put_thumb32_insn (buf, insn);
16805f35
PB
18629 if (insn & (1 << 20))
18630 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18631 else
18632 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
18633 }
18634 else
18635 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18636 pc_rel = 0;
18637 break;
18638 default:
5f4273c7 18639 abort ();
0110f2b8
PB
18640 }
18641 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 18642 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
18643 fixp->fx_file = fragp->fr_file;
18644 fixp->fx_line = fragp->fr_line;
18645 fragp->fr_fix += fragp->fr_var;
18646}
18647
18648/* Return the size of a relaxable immediate operand instruction.
18649 SHIFT and SIZE specify the form of the allowable immediate. */
18650static int
18651relax_immediate (fragS *fragp, int size, int shift)
18652{
18653 offsetT offset;
18654 offsetT mask;
18655 offsetT low;
18656
18657 /* ??? Should be able to do better than this. */
18658 if (fragp->fr_symbol)
18659 return 4;
18660
18661 low = (1 << shift) - 1;
18662 mask = (1 << (shift + size)) - (1 << shift);
18663 offset = fragp->fr_offset;
18664 /* Force misaligned offsets to 32-bit variant. */
18665 if (offset & low)
5e77afaa 18666 return 4;
0110f2b8
PB
18667 if (offset & ~mask)
18668 return 4;
18669 return 2;
18670}
18671
5e77afaa
PB
18672/* Get the address of a symbol during relaxation. */
18673static addressT
5f4273c7 18674relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
18675{
18676 fragS *sym_frag;
18677 addressT addr;
18678 symbolS *sym;
18679
18680 sym = fragp->fr_symbol;
18681 sym_frag = symbol_get_frag (sym);
18682 know (S_GET_SEGMENT (sym) != absolute_section
18683 || sym_frag == &zero_address_frag);
18684 addr = S_GET_VALUE (sym) + fragp->fr_offset;
18685
18686 /* If frag has yet to be reached on this pass, assume it will
18687 move by STRETCH just as we did. If this is not so, it will
18688 be because some frag between grows, and that will force
18689 another pass. */
18690
18691 if (stretch != 0
18692 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
18693 {
18694 fragS *f;
18695
18696 /* Adjust stretch for any alignment frag. Note that if have
18697 been expanding the earlier code, the symbol may be
18698 defined in what appears to be an earlier frag. FIXME:
18699 This doesn't handle the fr_subtype field, which specifies
18700 a maximum number of bytes to skip when doing an
18701 alignment. */
18702 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
18703 {
18704 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
18705 {
18706 if (stretch < 0)
18707 stretch = - ((- stretch)
18708 & ~ ((1 << (int) f->fr_offset) - 1));
18709 else
18710 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
18711 if (stretch == 0)
18712 break;
18713 }
18714 }
18715 if (f != NULL)
18716 addr += stretch;
18717 }
5e77afaa
PB
18718
18719 return addr;
18720}
18721
0110f2b8
PB
18722/* Return the size of a relaxable adr pseudo-instruction or PC-relative
18723 load. */
18724static int
5e77afaa 18725relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
18726{
18727 addressT addr;
18728 offsetT val;
18729
18730 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
18731 if (fragp->fr_symbol == NULL
18732 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
18733 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18734 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
18735 return 4;
18736
5f4273c7 18737 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18738 addr = fragp->fr_address + fragp->fr_fix;
18739 addr = (addr + 4) & ~3;
5e77afaa 18740 /* Force misaligned targets to 32-bit variant. */
0110f2b8 18741 if (val & 3)
5e77afaa 18742 return 4;
0110f2b8
PB
18743 val -= addr;
18744 if (val < 0 || val > 1020)
18745 return 4;
18746 return 2;
18747}
18748
18749/* Return the size of a relaxable add/sub immediate instruction. */
18750static int
18751relax_addsub (fragS *fragp, asection *sec)
18752{
18753 char *buf;
18754 int op;
18755
18756 buf = fragp->fr_literal + fragp->fr_fix;
18757 op = bfd_get_16(sec->owner, buf);
18758 if ((op & 0xf) == ((op >> 4) & 0xf))
18759 return relax_immediate (fragp, 8, 0);
18760 else
18761 return relax_immediate (fragp, 3, 0);
18762}
18763
18764
18765/* Return the size of a relaxable branch instruction. BITS is the
18766 size of the offset field in the narrow instruction. */
18767
18768static int
5e77afaa 18769relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
18770{
18771 addressT addr;
18772 offsetT val;
18773 offsetT limit;
18774
18775 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 18776 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
18777 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18778 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
18779 return 4;
18780
267bf995
RR
18781#ifdef OBJ_ELF
18782 if (S_IS_DEFINED (fragp->fr_symbol)
18783 && ARM_IS_FUNC (fragp->fr_symbol))
18784 return 4;
18785#endif
18786
5f4273c7 18787 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18788 addr = fragp->fr_address + fragp->fr_fix + 4;
18789 val -= addr;
18790
18791 /* Offset is a signed value *2 */
18792 limit = 1 << bits;
18793 if (val >= limit || val < -limit)
18794 return 4;
18795 return 2;
18796}
18797
18798
18799/* Relax a machine dependent frag. This returns the amount by which
18800 the current size of the frag should change. */
18801
18802int
5e77afaa 18803arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
18804{
18805 int oldsize;
18806 int newsize;
18807
18808 oldsize = fragp->fr_var;
18809 switch (fragp->fr_subtype)
18810 {
18811 case T_MNEM_ldr_pc2:
5f4273c7 18812 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18813 break;
18814 case T_MNEM_ldr_pc:
18815 case T_MNEM_ldr_sp:
18816 case T_MNEM_str_sp:
5f4273c7 18817 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
18818 break;
18819 case T_MNEM_ldr:
18820 case T_MNEM_str:
5f4273c7 18821 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
18822 break;
18823 case T_MNEM_ldrh:
18824 case T_MNEM_strh:
5f4273c7 18825 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
18826 break;
18827 case T_MNEM_ldrb:
18828 case T_MNEM_strb:
5f4273c7 18829 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
18830 break;
18831 case T_MNEM_adr:
5f4273c7 18832 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18833 break;
18834 case T_MNEM_mov:
18835 case T_MNEM_movs:
18836 case T_MNEM_cmp:
18837 case T_MNEM_cmn:
5f4273c7 18838 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
18839 break;
18840 case T_MNEM_b:
5f4273c7 18841 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
18842 break;
18843 case T_MNEM_bcond:
5f4273c7 18844 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
18845 break;
18846 case T_MNEM_add_sp:
18847 case T_MNEM_add_pc:
18848 newsize = relax_immediate (fragp, 8, 2);
18849 break;
18850 case T_MNEM_inc_sp:
18851 case T_MNEM_dec_sp:
18852 newsize = relax_immediate (fragp, 7, 2);
18853 break;
18854 case T_MNEM_addi:
18855 case T_MNEM_addis:
18856 case T_MNEM_subi:
18857 case T_MNEM_subis:
18858 newsize = relax_addsub (fragp, sec);
18859 break;
18860 default:
5f4273c7 18861 abort ();
0110f2b8 18862 }
5e77afaa
PB
18863
18864 fragp->fr_var = newsize;
18865 /* Freeze wide instructions that are at or before the same location as
18866 in the previous pass. This avoids infinite loops.
5f4273c7
NC
18867 Don't freeze them unconditionally because targets may be artificially
18868 misaligned by the expansion of preceding frags. */
5e77afaa 18869 if (stretch <= 0 && newsize > 2)
0110f2b8 18870 {
0110f2b8 18871 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 18872 frag_wane (fragp);
0110f2b8 18873 }
5e77afaa 18874
0110f2b8 18875 return newsize - oldsize;
c19d1205 18876}
b99bd4ef 18877
c19d1205 18878/* Round up a section size to the appropriate boundary. */
b99bd4ef 18879
c19d1205
ZW
18880valueT
18881md_section_align (segT segment ATTRIBUTE_UNUSED,
18882 valueT size)
18883{
f0927246
NC
18884#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
18885 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
18886 {
18887 /* For a.out, force the section size to be aligned. If we don't do
18888 this, BFD will align it for us, but it will not write out the
18889 final bytes of the section. This may be a bug in BFD, but it is
18890 easier to fix it here since that is how the other a.out targets
18891 work. */
18892 int align;
18893
18894 align = bfd_get_section_alignment (stdoutput, segment);
18895 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
18896 }
c19d1205 18897#endif
f0927246
NC
18898
18899 return size;
bfae80f2 18900}
b99bd4ef 18901
c19d1205
ZW
18902/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
18903 of an rs_align_code fragment. */
18904
18905void
18906arm_handle_align (fragS * fragP)
bfae80f2 18907{
e7495e45
NS
18908 static char const arm_noop[2][2][4] =
18909 {
18910 { /* ARMv1 */
18911 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
18912 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
18913 },
18914 { /* ARMv6k */
18915 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
18916 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
18917 },
18918 };
18919 static char const thumb_noop[2][2][2] =
18920 {
18921 { /* Thumb-1 */
18922 {0xc0, 0x46}, /* LE */
18923 {0x46, 0xc0}, /* BE */
18924 },
18925 { /* Thumb-2 */
18926 {0x00, 0xbf}, /* LE */
18927 {0xbf, 0x00} /* BE */
18928 }
18929 };
18930 static char const wide_thumb_noop[2][4] =
18931 { /* Wide Thumb-2 */
18932 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
18933 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
18934 };
c921be7d 18935
e7495e45 18936 unsigned bytes, fix, noop_size;
c19d1205
ZW
18937 char * p;
18938 const char * noop;
e7495e45 18939 const char *narrow_noop = NULL;
cd000bff
DJ
18940#ifdef OBJ_ELF
18941 enum mstate state;
18942#endif
bfae80f2 18943
c19d1205 18944 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
18945 return;
18946
c19d1205
ZW
18947 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
18948 p = fragP->fr_literal + fragP->fr_fix;
18949 fix = 0;
bfae80f2 18950
c19d1205
ZW
18951 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
18952 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 18953
cd000bff 18954 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 18955
cd000bff 18956 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 18957 {
e7495e45
NS
18958 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
18959 {
18960 narrow_noop = thumb_noop[1][target_big_endian];
18961 noop = wide_thumb_noop[target_big_endian];
18962 }
c19d1205 18963 else
e7495e45
NS
18964 noop = thumb_noop[0][target_big_endian];
18965 noop_size = 2;
cd000bff
DJ
18966#ifdef OBJ_ELF
18967 state = MAP_THUMB;
18968#endif
7ed4c4c5
NC
18969 }
18970 else
18971 {
e7495e45
NS
18972 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
18973 [target_big_endian];
18974 noop_size = 4;
cd000bff
DJ
18975#ifdef OBJ_ELF
18976 state = MAP_ARM;
18977#endif
7ed4c4c5 18978 }
c921be7d 18979
e7495e45 18980 fragP->fr_var = noop_size;
c921be7d 18981
c19d1205 18982 if (bytes & (noop_size - 1))
7ed4c4c5 18983 {
c19d1205 18984 fix = bytes & (noop_size - 1);
cd000bff
DJ
18985#ifdef OBJ_ELF
18986 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
18987#endif
c19d1205
ZW
18988 memset (p, 0, fix);
18989 p += fix;
18990 bytes -= fix;
a737bd4d 18991 }
a737bd4d 18992
e7495e45
NS
18993 if (narrow_noop)
18994 {
18995 if (bytes & noop_size)
18996 {
18997 /* Insert a narrow noop. */
18998 memcpy (p, narrow_noop, noop_size);
18999 p += noop_size;
19000 bytes -= noop_size;
19001 fix += noop_size;
19002 }
19003
19004 /* Use wide noops for the remainder */
19005 noop_size = 4;
19006 }
19007
c19d1205 19008 while (bytes >= noop_size)
a737bd4d 19009 {
c19d1205
ZW
19010 memcpy (p, noop, noop_size);
19011 p += noop_size;
19012 bytes -= noop_size;
19013 fix += noop_size;
a737bd4d
NC
19014 }
19015
c19d1205 19016 fragP->fr_fix += fix;
a737bd4d
NC
19017}
19018
c19d1205
ZW
19019/* Called from md_do_align. Used to create an alignment
19020 frag in a code section. */
19021
19022void
19023arm_frag_align_code (int n, int max)
bfae80f2 19024{
c19d1205 19025 char * p;
7ed4c4c5 19026
c19d1205 19027 /* We assume that there will never be a requirement
6ec8e702 19028 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 19029 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
19030 {
19031 char err_msg[128];
19032
19033 sprintf (err_msg,
19034 _("alignments greater than %d bytes not supported in .text sections."),
19035 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 19036 as_fatal ("%s", err_msg);
6ec8e702 19037 }
bfae80f2 19038
c19d1205
ZW
19039 p = frag_var (rs_align_code,
19040 MAX_MEM_FOR_RS_ALIGN_CODE,
19041 1,
19042 (relax_substateT) max,
19043 (symbolS *) NULL,
19044 (offsetT) n,
19045 (char *) NULL);
19046 *p = 0;
19047}
bfae80f2 19048
8dc2430f
NC
19049/* Perform target specific initialisation of a frag.
19050 Note - despite the name this initialisation is not done when the frag
19051 is created, but only when its type is assigned. A frag can be created
19052 and used a long time before its type is set, so beware of assuming that
19053 this initialisationis performed first. */
bfae80f2 19054
cd000bff
DJ
19055#ifndef OBJ_ELF
19056void
19057arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
19058{
19059 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 19060 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
19061}
19062
19063#else /* OBJ_ELF is defined. */
c19d1205 19064void
cd000bff 19065arm_init_frag (fragS * fragP, int max_chars)
c19d1205 19066{
8dc2430f
NC
19067 /* If the current ARM vs THUMB mode has not already
19068 been recorded into this frag then do so now. */
cd000bff
DJ
19069 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
19070 {
19071 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19072
19073 /* Record a mapping symbol for alignment frags. We will delete this
19074 later if the alignment ends up empty. */
19075 switch (fragP->fr_type)
19076 {
19077 case rs_align:
19078 case rs_align_test:
19079 case rs_fill:
19080 mapping_state_2 (MAP_DATA, max_chars);
19081 break;
19082 case rs_align_code:
19083 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
19084 break;
19085 default:
19086 break;
19087 }
19088 }
bfae80f2
RE
19089}
19090
c19d1205
ZW
19091/* When we change sections we need to issue a new mapping symbol. */
19092
19093void
19094arm_elf_change_section (void)
bfae80f2 19095{
c19d1205
ZW
19096 /* Link an unlinked unwind index table section to the .text section. */
19097 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
19098 && elf_linked_to_section (now_seg) == NULL)
19099 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
19100}
19101
c19d1205
ZW
19102int
19103arm_elf_section_type (const char * str, size_t len)
e45d0630 19104{
c19d1205
ZW
19105 if (len == 5 && strncmp (str, "exidx", 5) == 0)
19106 return SHT_ARM_EXIDX;
e45d0630 19107
c19d1205
ZW
19108 return -1;
19109}
19110\f
19111/* Code to deal with unwinding tables. */
e45d0630 19112
c19d1205 19113static void add_unwind_adjustsp (offsetT);
e45d0630 19114
5f4273c7 19115/* Generate any deferred unwind frame offset. */
e45d0630 19116
bfae80f2 19117static void
c19d1205 19118flush_pending_unwind (void)
bfae80f2 19119{
c19d1205 19120 offsetT offset;
bfae80f2 19121
c19d1205
ZW
19122 offset = unwind.pending_offset;
19123 unwind.pending_offset = 0;
19124 if (offset != 0)
19125 add_unwind_adjustsp (offset);
bfae80f2
RE
19126}
19127
c19d1205
ZW
19128/* Add an opcode to this list for this function. Two-byte opcodes should
19129 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
19130 order. */
19131
bfae80f2 19132static void
c19d1205 19133add_unwind_opcode (valueT op, int length)
bfae80f2 19134{
c19d1205
ZW
19135 /* Add any deferred stack adjustment. */
19136 if (unwind.pending_offset)
19137 flush_pending_unwind ();
bfae80f2 19138
c19d1205 19139 unwind.sp_restored = 0;
bfae80f2 19140
c19d1205 19141 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 19142 {
c19d1205
ZW
19143 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
19144 if (unwind.opcodes)
21d799b5
NC
19145 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
19146 unwind.opcode_alloc);
c19d1205 19147 else
21d799b5 19148 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 19149 }
c19d1205 19150 while (length > 0)
bfae80f2 19151 {
c19d1205
ZW
19152 length--;
19153 unwind.opcodes[unwind.opcode_count] = op & 0xff;
19154 op >>= 8;
19155 unwind.opcode_count++;
bfae80f2 19156 }
bfae80f2
RE
19157}
19158
c19d1205
ZW
19159/* Add unwind opcodes to adjust the stack pointer. */
19160
bfae80f2 19161static void
c19d1205 19162add_unwind_adjustsp (offsetT offset)
bfae80f2 19163{
c19d1205 19164 valueT op;
bfae80f2 19165
c19d1205 19166 if (offset > 0x200)
bfae80f2 19167 {
c19d1205
ZW
19168 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
19169 char bytes[5];
19170 int n;
19171 valueT o;
bfae80f2 19172
c19d1205
ZW
19173 /* Long form: 0xb2, uleb128. */
19174 /* This might not fit in a word so add the individual bytes,
19175 remembering the list is built in reverse order. */
19176 o = (valueT) ((offset - 0x204) >> 2);
19177 if (o == 0)
19178 add_unwind_opcode (0, 1);
bfae80f2 19179
c19d1205
ZW
19180 /* Calculate the uleb128 encoding of the offset. */
19181 n = 0;
19182 while (o)
19183 {
19184 bytes[n] = o & 0x7f;
19185 o >>= 7;
19186 if (o)
19187 bytes[n] |= 0x80;
19188 n++;
19189 }
19190 /* Add the insn. */
19191 for (; n; n--)
19192 add_unwind_opcode (bytes[n - 1], 1);
19193 add_unwind_opcode (0xb2, 1);
19194 }
19195 else if (offset > 0x100)
bfae80f2 19196 {
c19d1205
ZW
19197 /* Two short opcodes. */
19198 add_unwind_opcode (0x3f, 1);
19199 op = (offset - 0x104) >> 2;
19200 add_unwind_opcode (op, 1);
bfae80f2 19201 }
c19d1205
ZW
19202 else if (offset > 0)
19203 {
19204 /* Short opcode. */
19205 op = (offset - 4) >> 2;
19206 add_unwind_opcode (op, 1);
19207 }
19208 else if (offset < 0)
bfae80f2 19209 {
c19d1205
ZW
19210 offset = -offset;
19211 while (offset > 0x100)
bfae80f2 19212 {
c19d1205
ZW
19213 add_unwind_opcode (0x7f, 1);
19214 offset -= 0x100;
bfae80f2 19215 }
c19d1205
ZW
19216 op = ((offset - 4) >> 2) | 0x40;
19217 add_unwind_opcode (op, 1);
bfae80f2 19218 }
bfae80f2
RE
19219}
19220
c19d1205
ZW
19221/* Finish the list of unwind opcodes for this function. */
19222static void
19223finish_unwind_opcodes (void)
bfae80f2 19224{
c19d1205 19225 valueT op;
bfae80f2 19226
c19d1205 19227 if (unwind.fp_used)
bfae80f2 19228 {
708587a4 19229 /* Adjust sp as necessary. */
c19d1205
ZW
19230 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19231 flush_pending_unwind ();
bfae80f2 19232
c19d1205
ZW
19233 /* After restoring sp from the frame pointer. */
19234 op = 0x90 | unwind.fp_reg;
19235 add_unwind_opcode (op, 1);
19236 }
19237 else
19238 flush_pending_unwind ();
bfae80f2
RE
19239}
19240
bfae80f2 19241
c19d1205
ZW
19242/* Start an exception table entry. If idx is nonzero this is an index table
19243 entry. */
bfae80f2
RE
19244
19245static void
c19d1205 19246start_unwind_section (const segT text_seg, int idx)
bfae80f2 19247{
c19d1205
ZW
19248 const char * text_name;
19249 const char * prefix;
19250 const char * prefix_once;
19251 const char * group_name;
19252 size_t prefix_len;
19253 size_t text_len;
19254 char * sec_name;
19255 size_t sec_name_len;
19256 int type;
19257 int flags;
19258 int linkonce;
bfae80f2 19259
c19d1205 19260 if (idx)
bfae80f2 19261 {
c19d1205
ZW
19262 prefix = ELF_STRING_ARM_unwind;
19263 prefix_once = ELF_STRING_ARM_unwind_once;
19264 type = SHT_ARM_EXIDX;
bfae80f2 19265 }
c19d1205 19266 else
bfae80f2 19267 {
c19d1205
ZW
19268 prefix = ELF_STRING_ARM_unwind_info;
19269 prefix_once = ELF_STRING_ARM_unwind_info_once;
19270 type = SHT_PROGBITS;
bfae80f2
RE
19271 }
19272
c19d1205
ZW
19273 text_name = segment_name (text_seg);
19274 if (streq (text_name, ".text"))
19275 text_name = "";
19276
19277 if (strncmp (text_name, ".gnu.linkonce.t.",
19278 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 19279 {
c19d1205
ZW
19280 prefix = prefix_once;
19281 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
19282 }
19283
c19d1205
ZW
19284 prefix_len = strlen (prefix);
19285 text_len = strlen (text_name);
19286 sec_name_len = prefix_len + text_len;
21d799b5 19287 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
19288 memcpy (sec_name, prefix, prefix_len);
19289 memcpy (sec_name + prefix_len, text_name, text_len);
19290 sec_name[prefix_len + text_len] = '\0';
bfae80f2 19291
c19d1205
ZW
19292 flags = SHF_ALLOC;
19293 linkonce = 0;
19294 group_name = 0;
bfae80f2 19295
c19d1205
ZW
19296 /* Handle COMDAT group. */
19297 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 19298 {
c19d1205
ZW
19299 group_name = elf_group_name (text_seg);
19300 if (group_name == NULL)
19301 {
bd3ba5d1 19302 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
19303 segment_name (text_seg));
19304 ignore_rest_of_line ();
19305 return;
19306 }
19307 flags |= SHF_GROUP;
19308 linkonce = 1;
bfae80f2
RE
19309 }
19310
c19d1205 19311 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 19312
5f4273c7 19313 /* Set the section link for index tables. */
c19d1205
ZW
19314 if (idx)
19315 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
19316}
19317
bfae80f2 19318
c19d1205
ZW
19319/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19320 personality routine data. Returns zero, or the index table value for
19321 and inline entry. */
19322
19323static valueT
19324create_unwind_entry (int have_data)
bfae80f2 19325{
c19d1205
ZW
19326 int size;
19327 addressT where;
19328 char *ptr;
19329 /* The current word of data. */
19330 valueT data;
19331 /* The number of bytes left in this word. */
19332 int n;
bfae80f2 19333
c19d1205 19334 finish_unwind_opcodes ();
bfae80f2 19335
c19d1205
ZW
19336 /* Remember the current text section. */
19337 unwind.saved_seg = now_seg;
19338 unwind.saved_subseg = now_subseg;
bfae80f2 19339
c19d1205 19340 start_unwind_section (now_seg, 0);
bfae80f2 19341
c19d1205 19342 if (unwind.personality_routine == NULL)
bfae80f2 19343 {
c19d1205
ZW
19344 if (unwind.personality_index == -2)
19345 {
19346 if (have_data)
5f4273c7 19347 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
19348 return 1; /* EXIDX_CANTUNWIND. */
19349 }
bfae80f2 19350
c19d1205
ZW
19351 /* Use a default personality routine if none is specified. */
19352 if (unwind.personality_index == -1)
19353 {
19354 if (unwind.opcode_count > 3)
19355 unwind.personality_index = 1;
19356 else
19357 unwind.personality_index = 0;
19358 }
bfae80f2 19359
c19d1205
ZW
19360 /* Space for the personality routine entry. */
19361 if (unwind.personality_index == 0)
19362 {
19363 if (unwind.opcode_count > 3)
19364 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 19365
c19d1205
ZW
19366 if (!have_data)
19367 {
19368 /* All the data is inline in the index table. */
19369 data = 0x80;
19370 n = 3;
19371 while (unwind.opcode_count > 0)
19372 {
19373 unwind.opcode_count--;
19374 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19375 n--;
19376 }
bfae80f2 19377
c19d1205
ZW
19378 /* Pad with "finish" opcodes. */
19379 while (n--)
19380 data = (data << 8) | 0xb0;
bfae80f2 19381
c19d1205
ZW
19382 return data;
19383 }
19384 size = 0;
19385 }
19386 else
19387 /* We get two opcodes "free" in the first word. */
19388 size = unwind.opcode_count - 2;
19389 }
19390 else
19391 /* An extra byte is required for the opcode count. */
19392 size = unwind.opcode_count + 1;
bfae80f2 19393
c19d1205
ZW
19394 size = (size + 3) >> 2;
19395 if (size > 0xff)
19396 as_bad (_("too many unwind opcodes"));
bfae80f2 19397
c19d1205
ZW
19398 frag_align (2, 0, 0);
19399 record_alignment (now_seg, 2);
19400 unwind.table_entry = expr_build_dot ();
19401
19402 /* Allocate the table entry. */
19403 ptr = frag_more ((size << 2) + 4);
19404 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 19405
c19d1205 19406 switch (unwind.personality_index)
bfae80f2 19407 {
c19d1205
ZW
19408 case -1:
19409 /* ??? Should this be a PLT generating relocation? */
19410 /* Custom personality routine. */
19411 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19412 BFD_RELOC_ARM_PREL31);
bfae80f2 19413
c19d1205
ZW
19414 where += 4;
19415 ptr += 4;
bfae80f2 19416
c19d1205
ZW
19417 /* Set the first byte to the number of additional words. */
19418 data = size - 1;
19419 n = 3;
19420 break;
bfae80f2 19421
c19d1205
ZW
19422 /* ABI defined personality routines. */
19423 case 0:
19424 /* Three opcodes bytes are packed into the first word. */
19425 data = 0x80;
19426 n = 3;
19427 break;
bfae80f2 19428
c19d1205
ZW
19429 case 1:
19430 case 2:
19431 /* The size and first two opcode bytes go in the first word. */
19432 data = ((0x80 + unwind.personality_index) << 8) | size;
19433 n = 2;
19434 break;
bfae80f2 19435
c19d1205
ZW
19436 default:
19437 /* Should never happen. */
19438 abort ();
19439 }
bfae80f2 19440
c19d1205
ZW
19441 /* Pack the opcodes into words (MSB first), reversing the list at the same
19442 time. */
19443 while (unwind.opcode_count > 0)
19444 {
19445 if (n == 0)
19446 {
19447 md_number_to_chars (ptr, data, 4);
19448 ptr += 4;
19449 n = 4;
19450 data = 0;
19451 }
19452 unwind.opcode_count--;
19453 n--;
19454 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19455 }
19456
19457 /* Finish off the last word. */
19458 if (n < 4)
19459 {
19460 /* Pad with "finish" opcodes. */
19461 while (n--)
19462 data = (data << 8) | 0xb0;
19463
19464 md_number_to_chars (ptr, data, 4);
19465 }
19466
19467 if (!have_data)
19468 {
19469 /* Add an empty descriptor if there is no user-specified data. */
19470 ptr = frag_more (4);
19471 md_number_to_chars (ptr, 0, 4);
19472 }
19473
19474 return 0;
bfae80f2
RE
19475}
19476
f0927246
NC
19477
19478/* Initialize the DWARF-2 unwind information for this procedure. */
19479
19480void
19481tc_arm_frame_initial_instructions (void)
19482{
19483 cfi_add_CFA_def_cfa (REG_SP, 0);
19484}
19485#endif /* OBJ_ELF */
19486
c19d1205
ZW
19487/* Convert REGNAME to a DWARF-2 register number. */
19488
19489int
1df69f4f 19490tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 19491{
1df69f4f 19492 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
19493
19494 if (reg == FAIL)
19495 return -1;
19496
19497 return reg;
bfae80f2
RE
19498}
19499
f0927246 19500#ifdef TE_PE
c19d1205 19501void
f0927246 19502tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 19503{
91d6fa6a 19504 expressionS exp;
bfae80f2 19505
91d6fa6a
NC
19506 exp.X_op = O_secrel;
19507 exp.X_add_symbol = symbol;
19508 exp.X_add_number = 0;
19509 emit_expr (&exp, size);
f0927246
NC
19510}
19511#endif
bfae80f2 19512
c19d1205 19513/* MD interface: Symbol and relocation handling. */
bfae80f2 19514
2fc8bdac
ZW
19515/* Return the address within the segment that a PC-relative fixup is
19516 relative to. For ARM, PC-relative fixups applied to instructions
19517 are generally relative to the location of the fixup plus 8 bytes.
19518 Thumb branches are offset by 4, and Thumb loads relative to PC
19519 require special handling. */
bfae80f2 19520
c19d1205 19521long
2fc8bdac 19522md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 19523{
2fc8bdac
ZW
19524 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19525
19526 /* If this is pc-relative and we are going to emit a relocation
19527 then we just want to put out any pipeline compensation that the linker
53baae48
NC
19528 will need. Otherwise we want to use the calculated base.
19529 For WinCE we skip the bias for externals as well, since this
19530 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 19531 if (fixP->fx_pcrel
2fc8bdac 19532 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
19533 || (arm_force_relocation (fixP)
19534#ifdef TE_WINCE
19535 && !S_IS_EXTERNAL (fixP->fx_addsy)
19536#endif
19537 )))
2fc8bdac 19538 base = 0;
bfae80f2 19539
267bf995 19540
c19d1205 19541 switch (fixP->fx_r_type)
bfae80f2 19542 {
2fc8bdac
ZW
19543 /* PC relative addressing on the Thumb is slightly odd as the
19544 bottom two bits of the PC are forced to zero for the
19545 calculation. This happens *after* application of the
19546 pipeline offset. However, Thumb adrl already adjusts for
19547 this, so we need not do it again. */
c19d1205 19548 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 19549 return base & ~3;
c19d1205
ZW
19550
19551 case BFD_RELOC_ARM_THUMB_OFFSET:
19552 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 19553 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 19554 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 19555 return (base + 4) & ~3;
c19d1205 19556
2fc8bdac
ZW
19557 /* Thumb branches are simply offset by +4. */
19558 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19559 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19560 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19561 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 19562 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 19563 return base + 4;
bfae80f2 19564
267bf995 19565 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
19566 if (fixP->fx_addsy
19567 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19568 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19569 && ARM_IS_FUNC (fixP->fx_addsy)
19570 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19571 base = fixP->fx_where + fixP->fx_frag->fr_address;
19572 return base + 4;
19573
00adf2d4
JB
19574 /* BLX is like branches above, but forces the low two bits of PC to
19575 zero. */
486499d0
CL
19576 case BFD_RELOC_THUMB_PCREL_BLX:
19577 if (fixP->fx_addsy
19578 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19579 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19580 && THUMB_IS_FUNC (fixP->fx_addsy)
19581 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19582 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
19583 return (base + 4) & ~3;
19584
2fc8bdac
ZW
19585 /* ARM mode branches are offset by +8. However, the Windows CE
19586 loader expects the relocation not to take this into account. */
267bf995 19587 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
19588 if (fixP->fx_addsy
19589 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19590 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19591 && ARM_IS_FUNC (fixP->fx_addsy)
19592 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19593 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19594 return base + 8;
267bf995 19595
486499d0
CL
19596 case BFD_RELOC_ARM_PCREL_CALL:
19597 if (fixP->fx_addsy
19598 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19599 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19600 && THUMB_IS_FUNC (fixP->fx_addsy)
19601 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19602 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19603 return base + 8;
267bf995 19604
2fc8bdac 19605 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 19606 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 19607 case BFD_RELOC_ARM_PLT32:
c19d1205 19608#ifdef TE_WINCE
5f4273c7 19609 /* When handling fixups immediately, because we have already
53baae48
NC
19610 discovered the value of a symbol, or the address of the frag involved
19611 we must account for the offset by +8, as the OS loader will never see the reloc.
19612 see fixup_segment() in write.c
19613 The S_IS_EXTERNAL test handles the case of global symbols.
19614 Those need the calculated base, not just the pipe compensation the linker will need. */
19615 if (fixP->fx_pcrel
19616 && fixP->fx_addsy != NULL
19617 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19618 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
19619 return base + 8;
2fc8bdac 19620 return base;
c19d1205 19621#else
2fc8bdac 19622 return base + 8;
c19d1205 19623#endif
2fc8bdac 19624
267bf995 19625
2fc8bdac
ZW
19626 /* ARM mode loads relative to PC are also offset by +8. Unlike
19627 branches, the Windows CE loader *does* expect the relocation
19628 to take this into account. */
19629 case BFD_RELOC_ARM_OFFSET_IMM:
19630 case BFD_RELOC_ARM_OFFSET_IMM8:
19631 case BFD_RELOC_ARM_HWLITERAL:
19632 case BFD_RELOC_ARM_LITERAL:
19633 case BFD_RELOC_ARM_CP_OFF_IMM:
19634 return base + 8;
19635
19636
19637 /* Other PC-relative relocations are un-offset. */
19638 default:
19639 return base;
19640 }
bfae80f2
RE
19641}
19642
c19d1205
ZW
19643/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
19644 Otherwise we have no need to default values of symbols. */
19645
19646symbolS *
19647md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 19648{
c19d1205
ZW
19649#ifdef OBJ_ELF
19650 if (name[0] == '_' && name[1] == 'G'
19651 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
19652 {
19653 if (!GOT_symbol)
19654 {
19655 if (symbol_find (name))
bd3ba5d1 19656 as_bad (_("GOT already in the symbol table"));
bfae80f2 19657
c19d1205
ZW
19658 GOT_symbol = symbol_new (name, undefined_section,
19659 (valueT) 0, & zero_address_frag);
19660 }
bfae80f2 19661
c19d1205 19662 return GOT_symbol;
bfae80f2 19663 }
c19d1205 19664#endif
bfae80f2 19665
c921be7d 19666 return NULL;
bfae80f2
RE
19667}
19668
55cf6793 19669/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
19670 computed as two separate immediate values, added together. We
19671 already know that this value cannot be computed by just one ARM
19672 instruction. */
19673
19674static unsigned int
19675validate_immediate_twopart (unsigned int val,
19676 unsigned int * highpart)
bfae80f2 19677{
c19d1205
ZW
19678 unsigned int a;
19679 unsigned int i;
bfae80f2 19680
c19d1205
ZW
19681 for (i = 0; i < 32; i += 2)
19682 if (((a = rotate_left (val, i)) & 0xff) != 0)
19683 {
19684 if (a & 0xff00)
19685 {
19686 if (a & ~ 0xffff)
19687 continue;
19688 * highpart = (a >> 8) | ((i + 24) << 7);
19689 }
19690 else if (a & 0xff0000)
19691 {
19692 if (a & 0xff000000)
19693 continue;
19694 * highpart = (a >> 16) | ((i + 16) << 7);
19695 }
19696 else
19697 {
9c2799c2 19698 gas_assert (a & 0xff000000);
c19d1205
ZW
19699 * highpart = (a >> 24) | ((i + 8) << 7);
19700 }
bfae80f2 19701
c19d1205
ZW
19702 return (a & 0xff) | (i << 7);
19703 }
bfae80f2 19704
c19d1205 19705 return FAIL;
bfae80f2
RE
19706}
19707
c19d1205
ZW
19708static int
19709validate_offset_imm (unsigned int val, int hwse)
19710{
19711 if ((hwse && val > 255) || val > 4095)
19712 return FAIL;
19713 return val;
19714}
bfae80f2 19715
55cf6793 19716/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
19717 negative immediate constant by altering the instruction. A bit of
19718 a hack really.
19719 MOV <-> MVN
19720 AND <-> BIC
19721 ADC <-> SBC
19722 by inverting the second operand, and
19723 ADD <-> SUB
19724 CMP <-> CMN
19725 by negating the second operand. */
bfae80f2 19726
c19d1205
ZW
19727static int
19728negate_data_op (unsigned long * instruction,
19729 unsigned long value)
bfae80f2 19730{
c19d1205
ZW
19731 int op, new_inst;
19732 unsigned long negated, inverted;
bfae80f2 19733
c19d1205
ZW
19734 negated = encode_arm_immediate (-value);
19735 inverted = encode_arm_immediate (~value);
bfae80f2 19736
c19d1205
ZW
19737 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
19738 switch (op)
bfae80f2 19739 {
c19d1205
ZW
19740 /* First negates. */
19741 case OPCODE_SUB: /* ADD <-> SUB */
19742 new_inst = OPCODE_ADD;
19743 value = negated;
19744 break;
bfae80f2 19745
c19d1205
ZW
19746 case OPCODE_ADD:
19747 new_inst = OPCODE_SUB;
19748 value = negated;
19749 break;
bfae80f2 19750
c19d1205
ZW
19751 case OPCODE_CMP: /* CMP <-> CMN */
19752 new_inst = OPCODE_CMN;
19753 value = negated;
19754 break;
bfae80f2 19755
c19d1205
ZW
19756 case OPCODE_CMN:
19757 new_inst = OPCODE_CMP;
19758 value = negated;
19759 break;
bfae80f2 19760
c19d1205
ZW
19761 /* Now Inverted ops. */
19762 case OPCODE_MOV: /* MOV <-> MVN */
19763 new_inst = OPCODE_MVN;
19764 value = inverted;
19765 break;
bfae80f2 19766
c19d1205
ZW
19767 case OPCODE_MVN:
19768 new_inst = OPCODE_MOV;
19769 value = inverted;
19770 break;
bfae80f2 19771
c19d1205
ZW
19772 case OPCODE_AND: /* AND <-> BIC */
19773 new_inst = OPCODE_BIC;
19774 value = inverted;
19775 break;
bfae80f2 19776
c19d1205
ZW
19777 case OPCODE_BIC:
19778 new_inst = OPCODE_AND;
19779 value = inverted;
19780 break;
bfae80f2 19781
c19d1205
ZW
19782 case OPCODE_ADC: /* ADC <-> SBC */
19783 new_inst = OPCODE_SBC;
19784 value = inverted;
19785 break;
bfae80f2 19786
c19d1205
ZW
19787 case OPCODE_SBC:
19788 new_inst = OPCODE_ADC;
19789 value = inverted;
19790 break;
bfae80f2 19791
c19d1205
ZW
19792 /* We cannot do anything. */
19793 default:
19794 return FAIL;
b99bd4ef
NC
19795 }
19796
c19d1205
ZW
19797 if (value == (unsigned) FAIL)
19798 return FAIL;
19799
19800 *instruction &= OPCODE_MASK;
19801 *instruction |= new_inst << DATA_OP_SHIFT;
19802 return value;
b99bd4ef
NC
19803}
19804
ef8d22e6
PB
19805/* Like negate_data_op, but for Thumb-2. */
19806
19807static unsigned int
16dd5e42 19808thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
19809{
19810 int op, new_inst;
19811 int rd;
16dd5e42 19812 unsigned int negated, inverted;
ef8d22e6
PB
19813
19814 negated = encode_thumb32_immediate (-value);
19815 inverted = encode_thumb32_immediate (~value);
19816
19817 rd = (*instruction >> 8) & 0xf;
19818 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
19819 switch (op)
19820 {
19821 /* ADD <-> SUB. Includes CMP <-> CMN. */
19822 case T2_OPCODE_SUB:
19823 new_inst = T2_OPCODE_ADD;
19824 value = negated;
19825 break;
19826
19827 case T2_OPCODE_ADD:
19828 new_inst = T2_OPCODE_SUB;
19829 value = negated;
19830 break;
19831
19832 /* ORR <-> ORN. Includes MOV <-> MVN. */
19833 case T2_OPCODE_ORR:
19834 new_inst = T2_OPCODE_ORN;
19835 value = inverted;
19836 break;
19837
19838 case T2_OPCODE_ORN:
19839 new_inst = T2_OPCODE_ORR;
19840 value = inverted;
19841 break;
19842
19843 /* AND <-> BIC. TST has no inverted equivalent. */
19844 case T2_OPCODE_AND:
19845 new_inst = T2_OPCODE_BIC;
19846 if (rd == 15)
19847 value = FAIL;
19848 else
19849 value = inverted;
19850 break;
19851
19852 case T2_OPCODE_BIC:
19853 new_inst = T2_OPCODE_AND;
19854 value = inverted;
19855 break;
19856
19857 /* ADC <-> SBC */
19858 case T2_OPCODE_ADC:
19859 new_inst = T2_OPCODE_SBC;
19860 value = inverted;
19861 break;
19862
19863 case T2_OPCODE_SBC:
19864 new_inst = T2_OPCODE_ADC;
19865 value = inverted;
19866 break;
19867
19868 /* We cannot do anything. */
19869 default:
19870 return FAIL;
19871 }
19872
16dd5e42 19873 if (value == (unsigned int)FAIL)
ef8d22e6
PB
19874 return FAIL;
19875
19876 *instruction &= T2_OPCODE_MASK;
19877 *instruction |= new_inst << T2_DATA_OP_SHIFT;
19878 return value;
19879}
19880
8f06b2d8
PB
19881/* Read a 32-bit thumb instruction from buf. */
19882static unsigned long
19883get_thumb32_insn (char * buf)
19884{
19885 unsigned long insn;
19886 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
19887 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19888
19889 return insn;
19890}
19891
a8bc6c78
PB
19892
19893/* We usually want to set the low bit on the address of thumb function
19894 symbols. In particular .word foo - . should have the low bit set.
19895 Generic code tries to fold the difference of two symbols to
19896 a constant. Prevent this and force a relocation when the first symbols
19897 is a thumb function. */
c921be7d
NC
19898
19899bfd_boolean
a8bc6c78
PB
19900arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
19901{
19902 if (op == O_subtract
19903 && l->X_op == O_symbol
19904 && r->X_op == O_symbol
19905 && THUMB_IS_FUNC (l->X_add_symbol))
19906 {
19907 l->X_op = O_subtract;
19908 l->X_op_symbol = r->X_add_symbol;
19909 l->X_add_number -= r->X_add_number;
c921be7d 19910 return TRUE;
a8bc6c78 19911 }
c921be7d 19912
a8bc6c78 19913 /* Process as normal. */
c921be7d 19914 return FALSE;
a8bc6c78
PB
19915}
19916
4a42ebbc
RR
19917/* Encode Thumb2 unconditional branches and calls. The encoding
19918 for the 2 are identical for the immediate values. */
19919
19920static void
19921encode_thumb2_b_bl_offset (char * buf, offsetT value)
19922{
19923#define T2I1I2MASK ((1 << 13) | (1 << 11))
19924 offsetT newval;
19925 offsetT newval2;
19926 addressT S, I1, I2, lo, hi;
19927
19928 S = (value >> 24) & 0x01;
19929 I1 = (value >> 23) & 0x01;
19930 I2 = (value >> 22) & 0x01;
19931 hi = (value >> 12) & 0x3ff;
19932 lo = (value >> 1) & 0x7ff;
19933 newval = md_chars_to_number (buf, THUMB_SIZE);
19934 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19935 newval |= (S << 10) | hi;
19936 newval2 &= ~T2I1I2MASK;
19937 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
19938 md_number_to_chars (buf, newval, THUMB_SIZE);
19939 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19940}
19941
c19d1205 19942void
55cf6793 19943md_apply_fix (fixS * fixP,
c19d1205
ZW
19944 valueT * valP,
19945 segT seg)
19946{
19947 offsetT value = * valP;
19948 offsetT newval;
19949 unsigned int newimm;
19950 unsigned long temp;
19951 int sign;
19952 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 19953
9c2799c2 19954 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 19955
c19d1205 19956 /* Note whether this will delete the relocation. */
4962c51a 19957
c19d1205
ZW
19958 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
19959 fixP->fx_done = 1;
b99bd4ef 19960
adbaf948 19961 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 19962 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
19963 for emit_reloc. */
19964 value &= 0xffffffff;
19965 value ^= 0x80000000;
5f4273c7 19966 value -= 0x80000000;
adbaf948
ZW
19967
19968 *valP = value;
c19d1205 19969 fixP->fx_addnumber = value;
b99bd4ef 19970
adbaf948
ZW
19971 /* Same treatment for fixP->fx_offset. */
19972 fixP->fx_offset &= 0xffffffff;
19973 fixP->fx_offset ^= 0x80000000;
19974 fixP->fx_offset -= 0x80000000;
19975
c19d1205 19976 switch (fixP->fx_r_type)
b99bd4ef 19977 {
c19d1205
ZW
19978 case BFD_RELOC_NONE:
19979 /* This will need to go in the object file. */
19980 fixP->fx_done = 0;
19981 break;
b99bd4ef 19982
c19d1205
ZW
19983 case BFD_RELOC_ARM_IMMEDIATE:
19984 /* We claim that this fixup has been processed here,
19985 even if in fact we generate an error because we do
19986 not have a reloc for it, so tc_gen_reloc will reject it. */
19987 fixP->fx_done = 1;
b99bd4ef 19988
77db8e2e 19989 if (fixP->fx_addsy)
b99bd4ef 19990 {
77db8e2e 19991 const char *msg = 0;
b99bd4ef 19992
77db8e2e
NC
19993 if (! S_IS_DEFINED (fixP->fx_addsy))
19994 msg = _("undefined symbol %s used as an immediate value");
19995 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
19996 msg = _("symbol %s is in a different section");
19997 else if (S_IS_WEAK (fixP->fx_addsy))
19998 msg = _("symbol %s is weak and may be overridden later");
19999
20000 if (msg)
20001 {
20002 as_bad_where (fixP->fx_file, fixP->fx_line,
20003 msg, S_GET_NAME (fixP->fx_addsy));
20004 break;
20005 }
42e5fcbf
AS
20006 }
20007
c19d1205
ZW
20008 newimm = encode_arm_immediate (value);
20009 temp = md_chars_to_number (buf, INSN_SIZE);
20010
20011 /* If the instruction will fail, see if we can fix things up by
20012 changing the opcode. */
20013 if (newimm == (unsigned int) FAIL
20014 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 20015 {
c19d1205
ZW
20016 as_bad_where (fixP->fx_file, fixP->fx_line,
20017 _("invalid constant (%lx) after fixup"),
20018 (unsigned long) value);
20019 break;
b99bd4ef 20020 }
b99bd4ef 20021
c19d1205
ZW
20022 newimm |= (temp & 0xfffff000);
20023 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20024 break;
b99bd4ef 20025
c19d1205
ZW
20026 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20027 {
20028 unsigned int highpart = 0;
20029 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 20030
77db8e2e 20031 if (fixP->fx_addsy)
42e5fcbf 20032 {
77db8e2e 20033 const char *msg = 0;
42e5fcbf 20034
77db8e2e
NC
20035 if (! S_IS_DEFINED (fixP->fx_addsy))
20036 msg = _("undefined symbol %s used as an immediate value");
20037 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20038 msg = _("symbol %s is in a different section");
20039 else if (S_IS_WEAK (fixP->fx_addsy))
20040 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 20041
77db8e2e
NC
20042 if (msg)
20043 {
20044 as_bad_where (fixP->fx_file, fixP->fx_line,
20045 msg, S_GET_NAME (fixP->fx_addsy));
20046 break;
20047 }
20048 }
20049
c19d1205
ZW
20050 newimm = encode_arm_immediate (value);
20051 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 20052
c19d1205
ZW
20053 /* If the instruction will fail, see if we can fix things up by
20054 changing the opcode. */
20055 if (newimm == (unsigned int) FAIL
20056 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
20057 {
20058 /* No ? OK - try using two ADD instructions to generate
20059 the value. */
20060 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 20061
c19d1205
ZW
20062 /* Yes - then make sure that the second instruction is
20063 also an add. */
20064 if (newimm != (unsigned int) FAIL)
20065 newinsn = temp;
20066 /* Still No ? Try using a negated value. */
20067 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
20068 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
20069 /* Otherwise - give up. */
20070 else
20071 {
20072 as_bad_where (fixP->fx_file, fixP->fx_line,
20073 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
20074 (long) value);
20075 break;
20076 }
b99bd4ef 20077
c19d1205
ZW
20078 /* Replace the first operand in the 2nd instruction (which
20079 is the PC) with the destination register. We have
20080 already added in the PC in the first instruction and we
20081 do not want to do it again. */
20082 newinsn &= ~ 0xf0000;
20083 newinsn |= ((newinsn & 0x0f000) << 4);
20084 }
b99bd4ef 20085
c19d1205
ZW
20086 newimm |= (temp & 0xfffff000);
20087 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 20088
c19d1205
ZW
20089 highpart |= (newinsn & 0xfffff000);
20090 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
20091 }
20092 break;
b99bd4ef 20093
c19d1205 20094 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
20095 if (!fixP->fx_done && seg->use_rela_p)
20096 value = 0;
20097
c19d1205
ZW
20098 case BFD_RELOC_ARM_LITERAL:
20099 sign = value >= 0;
b99bd4ef 20100
c19d1205
ZW
20101 if (value < 0)
20102 value = - value;
b99bd4ef 20103
c19d1205 20104 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 20105 {
c19d1205
ZW
20106 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
20107 as_bad_where (fixP->fx_file, fixP->fx_line,
20108 _("invalid literal constant: pool needs to be closer"));
20109 else
20110 as_bad_where (fixP->fx_file, fixP->fx_line,
20111 _("bad immediate value for offset (%ld)"),
20112 (long) value);
20113 break;
f03698e6
RE
20114 }
20115
c19d1205
ZW
20116 newval = md_chars_to_number (buf, INSN_SIZE);
20117 newval &= 0xff7ff000;
20118 newval |= value | (sign ? INDEX_UP : 0);
20119 md_number_to_chars (buf, newval, INSN_SIZE);
20120 break;
b99bd4ef 20121
c19d1205
ZW
20122 case BFD_RELOC_ARM_OFFSET_IMM8:
20123 case BFD_RELOC_ARM_HWLITERAL:
20124 sign = value >= 0;
b99bd4ef 20125
c19d1205
ZW
20126 if (value < 0)
20127 value = - value;
b99bd4ef 20128
c19d1205 20129 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 20130 {
c19d1205
ZW
20131 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
20132 as_bad_where (fixP->fx_file, fixP->fx_line,
20133 _("invalid literal constant: pool needs to be closer"));
20134 else
f9d4405b 20135 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
20136 (long) value);
20137 break;
b99bd4ef
NC
20138 }
20139
c19d1205
ZW
20140 newval = md_chars_to_number (buf, INSN_SIZE);
20141 newval &= 0xff7ff0f0;
20142 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
20143 md_number_to_chars (buf, newval, INSN_SIZE);
20144 break;
b99bd4ef 20145
c19d1205
ZW
20146 case BFD_RELOC_ARM_T32_OFFSET_U8:
20147 if (value < 0 || value > 1020 || value % 4 != 0)
20148 as_bad_where (fixP->fx_file, fixP->fx_line,
20149 _("bad immediate value for offset (%ld)"), (long) value);
20150 value /= 4;
b99bd4ef 20151
c19d1205 20152 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
20153 newval |= value;
20154 md_number_to_chars (buf+2, newval, THUMB_SIZE);
20155 break;
b99bd4ef 20156
c19d1205
ZW
20157 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20158 /* This is a complicated relocation used for all varieties of Thumb32
20159 load/store instruction with immediate offset:
20160
20161 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
20162 *4, optional writeback(W)
20163 (doubleword load/store)
20164
20165 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
20166 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
20167 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
20168 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
20169 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
20170
20171 Uppercase letters indicate bits that are already encoded at
20172 this point. Lowercase letters are our problem. For the
20173 second block of instructions, the secondary opcode nybble
20174 (bits 8..11) is present, and bit 23 is zero, even if this is
20175 a PC-relative operation. */
20176 newval = md_chars_to_number (buf, THUMB_SIZE);
20177 newval <<= 16;
20178 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 20179
c19d1205 20180 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 20181 {
c19d1205
ZW
20182 /* Doubleword load/store: 8-bit offset, scaled by 4. */
20183 if (value >= 0)
20184 newval |= (1 << 23);
20185 else
20186 value = -value;
20187 if (value % 4 != 0)
20188 {
20189 as_bad_where (fixP->fx_file, fixP->fx_line,
20190 _("offset not a multiple of 4"));
20191 break;
20192 }
20193 value /= 4;
216d22bc 20194 if (value > 0xff)
c19d1205
ZW
20195 {
20196 as_bad_where (fixP->fx_file, fixP->fx_line,
20197 _("offset out of range"));
20198 break;
20199 }
20200 newval &= ~0xff;
b99bd4ef 20201 }
c19d1205 20202 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 20203 {
c19d1205
ZW
20204 /* PC-relative, 12-bit offset. */
20205 if (value >= 0)
20206 newval |= (1 << 23);
20207 else
20208 value = -value;
216d22bc 20209 if (value > 0xfff)
c19d1205
ZW
20210 {
20211 as_bad_where (fixP->fx_file, fixP->fx_line,
20212 _("offset out of range"));
20213 break;
20214 }
20215 newval &= ~0xfff;
b99bd4ef 20216 }
c19d1205 20217 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 20218 {
c19d1205
ZW
20219 /* Writeback: 8-bit, +/- offset. */
20220 if (value >= 0)
20221 newval |= (1 << 9);
20222 else
20223 value = -value;
216d22bc 20224 if (value > 0xff)
c19d1205
ZW
20225 {
20226 as_bad_where (fixP->fx_file, fixP->fx_line,
20227 _("offset out of range"));
20228 break;
20229 }
20230 newval &= ~0xff;
b99bd4ef 20231 }
c19d1205 20232 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 20233 {
c19d1205 20234 /* T-instruction: positive 8-bit offset. */
216d22bc 20235 if (value < 0 || value > 0xff)
b99bd4ef 20236 {
c19d1205
ZW
20237 as_bad_where (fixP->fx_file, fixP->fx_line,
20238 _("offset out of range"));
20239 break;
b99bd4ef 20240 }
c19d1205
ZW
20241 newval &= ~0xff;
20242 newval |= value;
b99bd4ef
NC
20243 }
20244 else
b99bd4ef 20245 {
c19d1205
ZW
20246 /* Positive 12-bit or negative 8-bit offset. */
20247 int limit;
20248 if (value >= 0)
b99bd4ef 20249 {
c19d1205
ZW
20250 newval |= (1 << 23);
20251 limit = 0xfff;
20252 }
20253 else
20254 {
20255 value = -value;
20256 limit = 0xff;
20257 }
20258 if (value > limit)
20259 {
20260 as_bad_where (fixP->fx_file, fixP->fx_line,
20261 _("offset out of range"));
20262 break;
b99bd4ef 20263 }
c19d1205 20264 newval &= ~limit;
b99bd4ef 20265 }
b99bd4ef 20266
c19d1205
ZW
20267 newval |= value;
20268 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20269 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20270 break;
404ff6b5 20271
c19d1205
ZW
20272 case BFD_RELOC_ARM_SHIFT_IMM:
20273 newval = md_chars_to_number (buf, INSN_SIZE);
20274 if (((unsigned long) value) > 32
20275 || (value == 32
20276 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20277 {
20278 as_bad_where (fixP->fx_file, fixP->fx_line,
20279 _("shift expression is too large"));
20280 break;
20281 }
404ff6b5 20282
c19d1205
ZW
20283 if (value == 0)
20284 /* Shifts of zero must be done as lsl. */
20285 newval &= ~0x60;
20286 else if (value == 32)
20287 value = 0;
20288 newval &= 0xfffff07f;
20289 newval |= (value & 0x1f) << 7;
20290 md_number_to_chars (buf, newval, INSN_SIZE);
20291 break;
404ff6b5 20292
c19d1205 20293 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 20294 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 20295 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 20296 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
20297 /* We claim that this fixup has been processed here,
20298 even if in fact we generate an error because we do
20299 not have a reloc for it, so tc_gen_reloc will reject it. */
20300 fixP->fx_done = 1;
404ff6b5 20301
c19d1205
ZW
20302 if (fixP->fx_addsy
20303 && ! S_IS_DEFINED (fixP->fx_addsy))
20304 {
20305 as_bad_where (fixP->fx_file, fixP->fx_line,
20306 _("undefined symbol %s used as an immediate value"),
20307 S_GET_NAME (fixP->fx_addsy));
20308 break;
20309 }
404ff6b5 20310
c19d1205
ZW
20311 newval = md_chars_to_number (buf, THUMB_SIZE);
20312 newval <<= 16;
20313 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 20314
16805f35
PB
20315 newimm = FAIL;
20316 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20317 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
20318 {
20319 newimm = encode_thumb32_immediate (value);
20320 if (newimm == (unsigned int) FAIL)
20321 newimm = thumb32_negate_data_op (&newval, value);
20322 }
16805f35
PB
20323 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20324 && newimm == (unsigned int) FAIL)
92e90b6e 20325 {
16805f35
PB
20326 /* Turn add/sum into addw/subw. */
20327 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20328 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
20329 /* No flat 12-bit imm encoding for addsw/subsw. */
20330 if ((newval & 0x00100000) == 0)
e9f89963 20331 {
40f246e3
NC
20332 /* 12 bit immediate for addw/subw. */
20333 if (value < 0)
20334 {
20335 value = -value;
20336 newval ^= 0x00a00000;
20337 }
20338 if (value > 0xfff)
20339 newimm = (unsigned int) FAIL;
20340 else
20341 newimm = value;
e9f89963 20342 }
92e90b6e 20343 }
cc8a6dd0 20344
c19d1205 20345 if (newimm == (unsigned int)FAIL)
3631a3c8 20346 {
c19d1205
ZW
20347 as_bad_where (fixP->fx_file, fixP->fx_line,
20348 _("invalid constant (%lx) after fixup"),
20349 (unsigned long) value);
20350 break;
3631a3c8
NC
20351 }
20352
c19d1205
ZW
20353 newval |= (newimm & 0x800) << 15;
20354 newval |= (newimm & 0x700) << 4;
20355 newval |= (newimm & 0x0ff);
cc8a6dd0 20356
c19d1205
ZW
20357 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20358 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20359 break;
a737bd4d 20360
3eb17e6b 20361 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
20362 if (((unsigned long) value) > 0xffff)
20363 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 20364 _("invalid smc expression"));
2fc8bdac 20365 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20366 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20367 md_number_to_chars (buf, newval, INSN_SIZE);
20368 break;
a737bd4d 20369
c19d1205 20370 case BFD_RELOC_ARM_SWI:
adbaf948 20371 if (fixP->tc_fix_data != 0)
c19d1205
ZW
20372 {
20373 if (((unsigned long) value) > 0xff)
20374 as_bad_where (fixP->fx_file, fixP->fx_line,
20375 _("invalid swi expression"));
2fc8bdac 20376 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
20377 newval |= value;
20378 md_number_to_chars (buf, newval, THUMB_SIZE);
20379 }
20380 else
20381 {
20382 if (((unsigned long) value) > 0x00ffffff)
20383 as_bad_where (fixP->fx_file, fixP->fx_line,
20384 _("invalid swi expression"));
2fc8bdac 20385 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20386 newval |= value;
20387 md_number_to_chars (buf, newval, INSN_SIZE);
20388 }
20389 break;
a737bd4d 20390
c19d1205
ZW
20391 case BFD_RELOC_ARM_MULTI:
20392 if (((unsigned long) value) > 0xffff)
20393 as_bad_where (fixP->fx_file, fixP->fx_line,
20394 _("invalid expression in load/store multiple"));
20395 newval = value | md_chars_to_number (buf, INSN_SIZE);
20396 md_number_to_chars (buf, newval, INSN_SIZE);
20397 break;
a737bd4d 20398
c19d1205 20399#ifdef OBJ_ELF
39b41c9c 20400 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
20401
20402 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20403 && fixP->fx_addsy
20404 && !S_IS_EXTERNAL (fixP->fx_addsy)
20405 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20406 && THUMB_IS_FUNC (fixP->fx_addsy))
20407 /* Flip the bl to blx. This is a simple flip
20408 bit here because we generate PCREL_CALL for
20409 unconditional bls. */
20410 {
20411 newval = md_chars_to_number (buf, INSN_SIZE);
20412 newval = newval | 0x10000000;
20413 md_number_to_chars (buf, newval, INSN_SIZE);
20414 temp = 1;
20415 fixP->fx_done = 1;
20416 }
39b41c9c
PB
20417 else
20418 temp = 3;
20419 goto arm_branch_common;
20420
20421 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
20422 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20423 && fixP->fx_addsy
20424 && !S_IS_EXTERNAL (fixP->fx_addsy)
20425 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20426 && THUMB_IS_FUNC (fixP->fx_addsy))
20427 {
20428 /* This would map to a bl<cond>, b<cond>,
20429 b<always> to a Thumb function. We
20430 need to force a relocation for this particular
20431 case. */
20432 newval = md_chars_to_number (buf, INSN_SIZE);
20433 fixP->fx_done = 0;
20434 }
20435
2fc8bdac 20436 case BFD_RELOC_ARM_PLT32:
c19d1205 20437#endif
39b41c9c
PB
20438 case BFD_RELOC_ARM_PCREL_BRANCH:
20439 temp = 3;
20440 goto arm_branch_common;
a737bd4d 20441
39b41c9c 20442 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 20443
39b41c9c 20444 temp = 1;
267bf995
RR
20445 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20446 && fixP->fx_addsy
20447 && !S_IS_EXTERNAL (fixP->fx_addsy)
20448 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20449 && ARM_IS_FUNC (fixP->fx_addsy))
20450 {
20451 /* Flip the blx to a bl and warn. */
20452 const char *name = S_GET_NAME (fixP->fx_addsy);
20453 newval = 0xeb000000;
20454 as_warn_where (fixP->fx_file, fixP->fx_line,
20455 _("blx to '%s' an ARM ISA state function changed to bl"),
20456 name);
20457 md_number_to_chars (buf, newval, INSN_SIZE);
20458 temp = 3;
20459 fixP->fx_done = 1;
20460 }
20461
20462#ifdef OBJ_ELF
20463 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20464 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20465#endif
20466
39b41c9c 20467 arm_branch_common:
c19d1205 20468 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
20469 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20470 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20471 also be be clear. */
20472 if (value & temp)
c19d1205 20473 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
20474 _("misaligned branch destination"));
20475 if ((value & (offsetT)0xfe000000) != (offsetT)0
20476 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20477 as_bad_where (fixP->fx_file, fixP->fx_line,
20478 _("branch out of range"));
a737bd4d 20479
2fc8bdac 20480 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20481 {
2fc8bdac
ZW
20482 newval = md_chars_to_number (buf, INSN_SIZE);
20483 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
20484 /* Set the H bit on BLX instructions. */
20485 if (temp == 1)
20486 {
20487 if (value & 2)
20488 newval |= 0x01000000;
20489 else
20490 newval &= ~0x01000000;
20491 }
2fc8bdac 20492 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 20493 }
c19d1205 20494 break;
a737bd4d 20495
25fe350b
MS
20496 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20497 /* CBZ can only branch forward. */
a737bd4d 20498
738755b0
MS
20499 /* Attempts to use CBZ to branch to the next instruction
20500 (which, strictly speaking, are prohibited) will be turned into
20501 no-ops.
20502
20503 FIXME: It may be better to remove the instruction completely and
20504 perform relaxation. */
20505 if (value == -2)
2fc8bdac
ZW
20506 {
20507 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 20508 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
20509 md_number_to_chars (buf, newval, THUMB_SIZE);
20510 }
738755b0
MS
20511 else
20512 {
20513 if (value & ~0x7e)
20514 as_bad_where (fixP->fx_file, fixP->fx_line,
20515 _("branch out of range"));
20516
20517 if (fixP->fx_done || !seg->use_rela_p)
20518 {
20519 newval = md_chars_to_number (buf, THUMB_SIZE);
20520 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20521 md_number_to_chars (buf, newval, THUMB_SIZE);
20522 }
20523 }
c19d1205 20524 break;
a737bd4d 20525
c19d1205 20526 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
20527 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20528 as_bad_where (fixP->fx_file, fixP->fx_line,
20529 _("branch out of range"));
a737bd4d 20530
2fc8bdac
ZW
20531 if (fixP->fx_done || !seg->use_rela_p)
20532 {
20533 newval = md_chars_to_number (buf, THUMB_SIZE);
20534 newval |= (value & 0x1ff) >> 1;
20535 md_number_to_chars (buf, newval, THUMB_SIZE);
20536 }
c19d1205 20537 break;
a737bd4d 20538
c19d1205 20539 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
20540 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20541 as_bad_where (fixP->fx_file, fixP->fx_line,
20542 _("branch out of range"));
a737bd4d 20543
2fc8bdac
ZW
20544 if (fixP->fx_done || !seg->use_rela_p)
20545 {
20546 newval = md_chars_to_number (buf, THUMB_SIZE);
20547 newval |= (value & 0xfff) >> 1;
20548 md_number_to_chars (buf, newval, THUMB_SIZE);
20549 }
c19d1205 20550 break;
a737bd4d 20551
c19d1205 20552 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
20553 if (fixP->fx_addsy
20554 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20555 && !S_IS_EXTERNAL (fixP->fx_addsy)
20556 && S_IS_DEFINED (fixP->fx_addsy)
20557 && ARM_IS_FUNC (fixP->fx_addsy)
20558 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20559 {
20560 /* Force a relocation for a branch 20 bits wide. */
20561 fixP->fx_done = 0;
20562 }
2fc8bdac
ZW
20563 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20564 as_bad_where (fixP->fx_file, fixP->fx_line,
20565 _("conditional branch out of range"));
404ff6b5 20566
2fc8bdac
ZW
20567 if (fixP->fx_done || !seg->use_rela_p)
20568 {
20569 offsetT newval2;
20570 addressT S, J1, J2, lo, hi;
404ff6b5 20571
2fc8bdac
ZW
20572 S = (value & 0x00100000) >> 20;
20573 J2 = (value & 0x00080000) >> 19;
20574 J1 = (value & 0x00040000) >> 18;
20575 hi = (value & 0x0003f000) >> 12;
20576 lo = (value & 0x00000ffe) >> 1;
6c43fab6 20577
2fc8bdac
ZW
20578 newval = md_chars_to_number (buf, THUMB_SIZE);
20579 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20580 newval |= (S << 10) | hi;
20581 newval2 |= (J1 << 13) | (J2 << 11) | lo;
20582 md_number_to_chars (buf, newval, THUMB_SIZE);
20583 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20584 }
c19d1205 20585 break;
6c43fab6 20586
c19d1205 20587 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
20588
20589 /* If there is a blx from a thumb state function to
20590 another thumb function flip this to a bl and warn
20591 about it. */
20592
20593 if (fixP->fx_addsy
20594 && S_IS_DEFINED (fixP->fx_addsy)
20595 && !S_IS_EXTERNAL (fixP->fx_addsy)
20596 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20597 && THUMB_IS_FUNC (fixP->fx_addsy))
20598 {
20599 const char *name = S_GET_NAME (fixP->fx_addsy);
20600 as_warn_where (fixP->fx_file, fixP->fx_line,
20601 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
20602 name);
20603 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20604 newval = newval | 0x1000;
20605 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20606 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20607 fixP->fx_done = 1;
20608 }
20609
20610
20611 goto thumb_bl_common;
20612
c19d1205 20613 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
20614
20615 /* A bl from Thumb state ISA to an internal ARM state function
20616 is converted to a blx. */
20617 if (fixP->fx_addsy
20618 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20619 && !S_IS_EXTERNAL (fixP->fx_addsy)
20620 && S_IS_DEFINED (fixP->fx_addsy)
20621 && ARM_IS_FUNC (fixP->fx_addsy)
20622 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20623 {
20624 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20625 newval = newval & ~0x1000;
20626 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20627 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
20628 fixP->fx_done = 1;
20629 }
20630
20631 thumb_bl_common:
20632
20633#ifdef OBJ_ELF
20634 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
20635 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20636 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20637#endif
20638
2fc8bdac
ZW
20639 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20640 /* For a BLX instruction, make sure that the relocation is rounded up
20641 to a word boundary. This follows the semantics of the instruction
20642 which specifies that bit 1 of the target address will come from bit
20643 1 of the base address. */
20644 value = (value + 1) & ~ 1;
404ff6b5 20645
2fc8bdac 20646
4a42ebbc
RR
20647 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
20648 {
20649 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
20650 {
20651 as_bad_where (fixP->fx_file, fixP->fx_line,
20652 _("branch out of range"));
20653 }
20654 else if ((value & ~0x1ffffff)
20655 && ((value & ~0x1ffffff) != ~0x1ffffff))
20656 {
20657 as_bad_where (fixP->fx_file, fixP->fx_line,
20658 _("Thumb2 branch out of range"));
20659 }
c19d1205 20660 }
4a42ebbc
RR
20661
20662 if (fixP->fx_done || !seg->use_rela_p)
20663 encode_thumb2_b_bl_offset (buf, value);
20664
c19d1205 20665 break;
404ff6b5 20666
c19d1205 20667 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
20668 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
20669 as_bad_where (fixP->fx_file, fixP->fx_line,
20670 _("branch out of range"));
6c43fab6 20671
2fc8bdac 20672 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 20673 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 20674
2fc8bdac 20675 break;
a737bd4d 20676
2fc8bdac
ZW
20677 case BFD_RELOC_8:
20678 if (fixP->fx_done || !seg->use_rela_p)
20679 md_number_to_chars (buf, value, 1);
c19d1205 20680 break;
a737bd4d 20681
c19d1205 20682 case BFD_RELOC_16:
2fc8bdac 20683 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20684 md_number_to_chars (buf, value, 2);
c19d1205 20685 break;
a737bd4d 20686
c19d1205
ZW
20687#ifdef OBJ_ELF
20688 case BFD_RELOC_ARM_TLS_GD32:
20689 case BFD_RELOC_ARM_TLS_LE32:
20690 case BFD_RELOC_ARM_TLS_IE32:
20691 case BFD_RELOC_ARM_TLS_LDM32:
20692 case BFD_RELOC_ARM_TLS_LDO32:
20693 S_SET_THREAD_LOCAL (fixP->fx_addsy);
20694 /* fall through */
6c43fab6 20695
c19d1205
ZW
20696 case BFD_RELOC_ARM_GOT32:
20697 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
20698 if (fixP->fx_done || !seg->use_rela_p)
20699 md_number_to_chars (buf, 0, 4);
c19d1205 20700 break;
b43420e6
NC
20701
20702 case BFD_RELOC_ARM_GOT_PREL:
20703 if (fixP->fx_done || !seg->use_rela_p)
20704 md_number_to_chars (buf, value, 4);
20705 break;
20706
9a6f4e97
NS
20707 case BFD_RELOC_ARM_TARGET2:
20708 /* TARGET2 is not partial-inplace, so we need to write the
20709 addend here for REL targets, because it won't be written out
20710 during reloc processing later. */
20711 if (fixP->fx_done || !seg->use_rela_p)
20712 md_number_to_chars (buf, fixP->fx_offset, 4);
20713 break;
c19d1205 20714#endif
6c43fab6 20715
c19d1205
ZW
20716 case BFD_RELOC_RVA:
20717 case BFD_RELOC_32:
20718 case BFD_RELOC_ARM_TARGET1:
20719 case BFD_RELOC_ARM_ROSEGREL32:
20720 case BFD_RELOC_ARM_SBREL32:
20721 case BFD_RELOC_32_PCREL:
f0927246
NC
20722#ifdef TE_PE
20723 case BFD_RELOC_32_SECREL:
20724#endif
2fc8bdac 20725 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
20726#ifdef TE_WINCE
20727 /* For WinCE we only do this for pcrel fixups. */
20728 if (fixP->fx_done || fixP->fx_pcrel)
20729#endif
20730 md_number_to_chars (buf, value, 4);
c19d1205 20731 break;
6c43fab6 20732
c19d1205
ZW
20733#ifdef OBJ_ELF
20734 case BFD_RELOC_ARM_PREL31:
2fc8bdac 20735 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
20736 {
20737 newval = md_chars_to_number (buf, 4) & 0x80000000;
20738 if ((value ^ (value >> 1)) & 0x40000000)
20739 {
20740 as_bad_where (fixP->fx_file, fixP->fx_line,
20741 _("rel31 relocation overflow"));
20742 }
20743 newval |= value & 0x7fffffff;
20744 md_number_to_chars (buf, newval, 4);
20745 }
20746 break;
c19d1205 20747#endif
a737bd4d 20748
c19d1205 20749 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 20750 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
20751 if (value < -1023 || value > 1023 || (value & 3))
20752 as_bad_where (fixP->fx_file, fixP->fx_line,
20753 _("co-processor offset out of range"));
20754 cp_off_common:
20755 sign = value >= 0;
20756 if (value < 0)
20757 value = -value;
8f06b2d8
PB
20758 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20759 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20760 newval = md_chars_to_number (buf, INSN_SIZE);
20761 else
20762 newval = get_thumb32_insn (buf);
20763 newval &= 0xff7fff00;
c19d1205 20764 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
20765 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20766 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20767 md_number_to_chars (buf, newval, INSN_SIZE);
20768 else
20769 put_thumb32_insn (buf, newval);
c19d1205 20770 break;
a737bd4d 20771
c19d1205 20772 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 20773 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
20774 if (value < -255 || value > 255)
20775 as_bad_where (fixP->fx_file, fixP->fx_line,
20776 _("co-processor offset out of range"));
df7849c5 20777 value *= 4;
c19d1205 20778 goto cp_off_common;
6c43fab6 20779
c19d1205
ZW
20780 case BFD_RELOC_ARM_THUMB_OFFSET:
20781 newval = md_chars_to_number (buf, THUMB_SIZE);
20782 /* Exactly what ranges, and where the offset is inserted depends
20783 on the type of instruction, we can establish this from the
20784 top 4 bits. */
20785 switch (newval >> 12)
20786 {
20787 case 4: /* PC load. */
20788 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
20789 forced to zero for these loads; md_pcrel_from has already
20790 compensated for this. */
20791 if (value & 3)
20792 as_bad_where (fixP->fx_file, fixP->fx_line,
20793 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
20794 (((unsigned long) fixP->fx_frag->fr_address
20795 + (unsigned long) fixP->fx_where) & ~3)
20796 + (unsigned long) value);
a737bd4d 20797
c19d1205
ZW
20798 if (value & ~0x3fc)
20799 as_bad_where (fixP->fx_file, fixP->fx_line,
20800 _("invalid offset, value too big (0x%08lX)"),
20801 (long) value);
a737bd4d 20802
c19d1205
ZW
20803 newval |= value >> 2;
20804 break;
a737bd4d 20805
c19d1205
ZW
20806 case 9: /* SP load/store. */
20807 if (value & ~0x3fc)
20808 as_bad_where (fixP->fx_file, fixP->fx_line,
20809 _("invalid offset, value too big (0x%08lX)"),
20810 (long) value);
20811 newval |= value >> 2;
20812 break;
6c43fab6 20813
c19d1205
ZW
20814 case 6: /* Word load/store. */
20815 if (value & ~0x7c)
20816 as_bad_where (fixP->fx_file, fixP->fx_line,
20817 _("invalid offset, value too big (0x%08lX)"),
20818 (long) value);
20819 newval |= value << 4; /* 6 - 2. */
20820 break;
a737bd4d 20821
c19d1205
ZW
20822 case 7: /* Byte load/store. */
20823 if (value & ~0x1f)
20824 as_bad_where (fixP->fx_file, fixP->fx_line,
20825 _("invalid offset, value too big (0x%08lX)"),
20826 (long) value);
20827 newval |= value << 6;
20828 break;
a737bd4d 20829
c19d1205
ZW
20830 case 8: /* Halfword load/store. */
20831 if (value & ~0x3e)
20832 as_bad_where (fixP->fx_file, fixP->fx_line,
20833 _("invalid offset, value too big (0x%08lX)"),
20834 (long) value);
20835 newval |= value << 5; /* 6 - 1. */
20836 break;
a737bd4d 20837
c19d1205
ZW
20838 default:
20839 as_bad_where (fixP->fx_file, fixP->fx_line,
20840 "Unable to process relocation for thumb opcode: %lx",
20841 (unsigned long) newval);
20842 break;
20843 }
20844 md_number_to_chars (buf, newval, THUMB_SIZE);
20845 break;
a737bd4d 20846
c19d1205
ZW
20847 case BFD_RELOC_ARM_THUMB_ADD:
20848 /* This is a complicated relocation, since we use it for all of
20849 the following immediate relocations:
a737bd4d 20850
c19d1205
ZW
20851 3bit ADD/SUB
20852 8bit ADD/SUB
20853 9bit ADD/SUB SP word-aligned
20854 10bit ADD PC/SP word-aligned
a737bd4d 20855
c19d1205
ZW
20856 The type of instruction being processed is encoded in the
20857 instruction field:
a737bd4d 20858
c19d1205
ZW
20859 0x8000 SUB
20860 0x00F0 Rd
20861 0x000F Rs
20862 */
20863 newval = md_chars_to_number (buf, THUMB_SIZE);
20864 {
20865 int rd = (newval >> 4) & 0xf;
20866 int rs = newval & 0xf;
20867 int subtract = !!(newval & 0x8000);
a737bd4d 20868
c19d1205
ZW
20869 /* Check for HI regs, only very restricted cases allowed:
20870 Adjusting SP, and using PC or SP to get an address. */
20871 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
20872 || (rs > 7 && rs != REG_SP && rs != REG_PC))
20873 as_bad_where (fixP->fx_file, fixP->fx_line,
20874 _("invalid Hi register with immediate"));
a737bd4d 20875
c19d1205
ZW
20876 /* If value is negative, choose the opposite instruction. */
20877 if (value < 0)
20878 {
20879 value = -value;
20880 subtract = !subtract;
20881 if (value < 0)
20882 as_bad_where (fixP->fx_file, fixP->fx_line,
20883 _("immediate value out of range"));
20884 }
a737bd4d 20885
c19d1205
ZW
20886 if (rd == REG_SP)
20887 {
20888 if (value & ~0x1fc)
20889 as_bad_where (fixP->fx_file, fixP->fx_line,
20890 _("invalid immediate for stack address calculation"));
20891 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
20892 newval |= value >> 2;
20893 }
20894 else if (rs == REG_PC || rs == REG_SP)
20895 {
20896 if (subtract || value & ~0x3fc)
20897 as_bad_where (fixP->fx_file, fixP->fx_line,
20898 _("invalid immediate for address calculation (value = 0x%08lX)"),
20899 (unsigned long) value);
20900 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
20901 newval |= rd << 8;
20902 newval |= value >> 2;
20903 }
20904 else if (rs == rd)
20905 {
20906 if (value & ~0xff)
20907 as_bad_where (fixP->fx_file, fixP->fx_line,
20908 _("immediate value out of range"));
20909 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
20910 newval |= (rd << 8) | value;
20911 }
20912 else
20913 {
20914 if (value & ~0x7)
20915 as_bad_where (fixP->fx_file, fixP->fx_line,
20916 _("immediate value out of range"));
20917 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
20918 newval |= rd | (rs << 3) | (value << 6);
20919 }
20920 }
20921 md_number_to_chars (buf, newval, THUMB_SIZE);
20922 break;
a737bd4d 20923
c19d1205
ZW
20924 case BFD_RELOC_ARM_THUMB_IMM:
20925 newval = md_chars_to_number (buf, THUMB_SIZE);
20926 if (value < 0 || value > 255)
20927 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 20928 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
20929 (long) value);
20930 newval |= value;
20931 md_number_to_chars (buf, newval, THUMB_SIZE);
20932 break;
a737bd4d 20933
c19d1205
ZW
20934 case BFD_RELOC_ARM_THUMB_SHIFT:
20935 /* 5bit shift value (0..32). LSL cannot take 32. */
20936 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
20937 temp = newval & 0xf800;
20938 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
20939 as_bad_where (fixP->fx_file, fixP->fx_line,
20940 _("invalid shift value: %ld"), (long) value);
20941 /* Shifts of zero must be encoded as LSL. */
20942 if (value == 0)
20943 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
20944 /* Shifts of 32 are encoded as zero. */
20945 else if (value == 32)
20946 value = 0;
20947 newval |= value << 6;
20948 md_number_to_chars (buf, newval, THUMB_SIZE);
20949 break;
a737bd4d 20950
c19d1205
ZW
20951 case BFD_RELOC_VTABLE_INHERIT:
20952 case BFD_RELOC_VTABLE_ENTRY:
20953 fixP->fx_done = 0;
20954 return;
6c43fab6 20955
b6895b4f
PB
20956 case BFD_RELOC_ARM_MOVW:
20957 case BFD_RELOC_ARM_MOVT:
20958 case BFD_RELOC_ARM_THUMB_MOVW:
20959 case BFD_RELOC_ARM_THUMB_MOVT:
20960 if (fixP->fx_done || !seg->use_rela_p)
20961 {
20962 /* REL format relocations are limited to a 16-bit addend. */
20963 if (!fixP->fx_done)
20964 {
39623e12 20965 if (value < -0x8000 || value > 0x7fff)
b6895b4f 20966 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 20967 _("offset out of range"));
b6895b4f
PB
20968 }
20969 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20970 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20971 {
20972 value >>= 16;
20973 }
20974
20975 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20976 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20977 {
20978 newval = get_thumb32_insn (buf);
20979 newval &= 0xfbf08f00;
20980 newval |= (value & 0xf000) << 4;
20981 newval |= (value & 0x0800) << 15;
20982 newval |= (value & 0x0700) << 4;
20983 newval |= (value & 0x00ff);
20984 put_thumb32_insn (buf, newval);
20985 }
20986 else
20987 {
20988 newval = md_chars_to_number (buf, 4);
20989 newval &= 0xfff0f000;
20990 newval |= value & 0x0fff;
20991 newval |= (value & 0xf000) << 4;
20992 md_number_to_chars (buf, newval, 4);
20993 }
20994 }
20995 return;
20996
4962c51a
MS
20997 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20998 case BFD_RELOC_ARM_ALU_PC_G0:
20999 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21000 case BFD_RELOC_ARM_ALU_PC_G1:
21001 case BFD_RELOC_ARM_ALU_PC_G2:
21002 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21003 case BFD_RELOC_ARM_ALU_SB_G0:
21004 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21005 case BFD_RELOC_ARM_ALU_SB_G1:
21006 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 21007 gas_assert (!fixP->fx_done);
4962c51a
MS
21008 if (!seg->use_rela_p)
21009 {
21010 bfd_vma insn;
21011 bfd_vma encoded_addend;
21012 bfd_vma addend_abs = abs (value);
21013
21014 /* Check that the absolute value of the addend can be
21015 expressed as an 8-bit constant plus a rotation. */
21016 encoded_addend = encode_arm_immediate (addend_abs);
21017 if (encoded_addend == (unsigned int) FAIL)
21018 as_bad_where (fixP->fx_file, fixP->fx_line,
21019 _("the offset 0x%08lX is not representable"),
495bde8e 21020 (unsigned long) addend_abs);
4962c51a
MS
21021
21022 /* Extract the instruction. */
21023 insn = md_chars_to_number (buf, INSN_SIZE);
21024
21025 /* If the addend is positive, use an ADD instruction.
21026 Otherwise use a SUB. Take care not to destroy the S bit. */
21027 insn &= 0xff1fffff;
21028 if (value < 0)
21029 insn |= 1 << 22;
21030 else
21031 insn |= 1 << 23;
21032
21033 /* Place the encoded addend into the first 12 bits of the
21034 instruction. */
21035 insn &= 0xfffff000;
21036 insn |= encoded_addend;
5f4273c7
NC
21037
21038 /* Update the instruction. */
4962c51a
MS
21039 md_number_to_chars (buf, insn, INSN_SIZE);
21040 }
21041 break;
21042
21043 case BFD_RELOC_ARM_LDR_PC_G0:
21044 case BFD_RELOC_ARM_LDR_PC_G1:
21045 case BFD_RELOC_ARM_LDR_PC_G2:
21046 case BFD_RELOC_ARM_LDR_SB_G0:
21047 case BFD_RELOC_ARM_LDR_SB_G1:
21048 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 21049 gas_assert (!fixP->fx_done);
4962c51a
MS
21050 if (!seg->use_rela_p)
21051 {
21052 bfd_vma insn;
21053 bfd_vma addend_abs = abs (value);
21054
21055 /* Check that the absolute value of the addend can be
21056 encoded in 12 bits. */
21057 if (addend_abs >= 0x1000)
21058 as_bad_where (fixP->fx_file, fixP->fx_line,
21059 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 21060 (unsigned long) addend_abs);
4962c51a
MS
21061
21062 /* Extract the instruction. */
21063 insn = md_chars_to_number (buf, INSN_SIZE);
21064
21065 /* If the addend is negative, clear bit 23 of the instruction.
21066 Otherwise set it. */
21067 if (value < 0)
21068 insn &= ~(1 << 23);
21069 else
21070 insn |= 1 << 23;
21071
21072 /* Place the absolute value of the addend into the first 12 bits
21073 of the instruction. */
21074 insn &= 0xfffff000;
21075 insn |= addend_abs;
5f4273c7
NC
21076
21077 /* Update the instruction. */
4962c51a
MS
21078 md_number_to_chars (buf, insn, INSN_SIZE);
21079 }
21080 break;
21081
21082 case BFD_RELOC_ARM_LDRS_PC_G0:
21083 case BFD_RELOC_ARM_LDRS_PC_G1:
21084 case BFD_RELOC_ARM_LDRS_PC_G2:
21085 case BFD_RELOC_ARM_LDRS_SB_G0:
21086 case BFD_RELOC_ARM_LDRS_SB_G1:
21087 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 21088 gas_assert (!fixP->fx_done);
4962c51a
MS
21089 if (!seg->use_rela_p)
21090 {
21091 bfd_vma insn;
21092 bfd_vma addend_abs = abs (value);
21093
21094 /* Check that the absolute value of the addend can be
21095 encoded in 8 bits. */
21096 if (addend_abs >= 0x100)
21097 as_bad_where (fixP->fx_file, fixP->fx_line,
21098 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 21099 (unsigned long) addend_abs);
4962c51a
MS
21100
21101 /* Extract the instruction. */
21102 insn = md_chars_to_number (buf, INSN_SIZE);
21103
21104 /* If the addend is negative, clear bit 23 of the instruction.
21105 Otherwise set it. */
21106 if (value < 0)
21107 insn &= ~(1 << 23);
21108 else
21109 insn |= 1 << 23;
21110
21111 /* Place the first four bits of the absolute value of the addend
21112 into the first 4 bits of the instruction, and the remaining
21113 four into bits 8 .. 11. */
21114 insn &= 0xfffff0f0;
21115 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
21116
21117 /* Update the instruction. */
4962c51a
MS
21118 md_number_to_chars (buf, insn, INSN_SIZE);
21119 }
21120 break;
21121
21122 case BFD_RELOC_ARM_LDC_PC_G0:
21123 case BFD_RELOC_ARM_LDC_PC_G1:
21124 case BFD_RELOC_ARM_LDC_PC_G2:
21125 case BFD_RELOC_ARM_LDC_SB_G0:
21126 case BFD_RELOC_ARM_LDC_SB_G1:
21127 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 21128 gas_assert (!fixP->fx_done);
4962c51a
MS
21129 if (!seg->use_rela_p)
21130 {
21131 bfd_vma insn;
21132 bfd_vma addend_abs = abs (value);
21133
21134 /* Check that the absolute value of the addend is a multiple of
21135 four and, when divided by four, fits in 8 bits. */
21136 if (addend_abs & 0x3)
21137 as_bad_where (fixP->fx_file, fixP->fx_line,
21138 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 21139 (unsigned long) addend_abs);
4962c51a
MS
21140
21141 if ((addend_abs >> 2) > 0xff)
21142 as_bad_where (fixP->fx_file, fixP->fx_line,
21143 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 21144 (unsigned long) addend_abs);
4962c51a
MS
21145
21146 /* Extract the instruction. */
21147 insn = md_chars_to_number (buf, INSN_SIZE);
21148
21149 /* If the addend is negative, clear bit 23 of the instruction.
21150 Otherwise set it. */
21151 if (value < 0)
21152 insn &= ~(1 << 23);
21153 else
21154 insn |= 1 << 23;
21155
21156 /* Place the addend (divided by four) into the first eight
21157 bits of the instruction. */
21158 insn &= 0xfffffff0;
21159 insn |= addend_abs >> 2;
5f4273c7
NC
21160
21161 /* Update the instruction. */
4962c51a
MS
21162 md_number_to_chars (buf, insn, INSN_SIZE);
21163 }
21164 break;
21165
845b51d6
PB
21166 case BFD_RELOC_ARM_V4BX:
21167 /* This will need to go in the object file. */
21168 fixP->fx_done = 0;
21169 break;
21170
c19d1205
ZW
21171 case BFD_RELOC_UNUSED:
21172 default:
21173 as_bad_where (fixP->fx_file, fixP->fx_line,
21174 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
21175 }
6c43fab6
RE
21176}
21177
c19d1205
ZW
21178/* Translate internal representation of relocation info to BFD target
21179 format. */
a737bd4d 21180
c19d1205 21181arelent *
00a97672 21182tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 21183{
c19d1205
ZW
21184 arelent * reloc;
21185 bfd_reloc_code_real_type code;
a737bd4d 21186
21d799b5 21187 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 21188
21d799b5 21189 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
21190 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
21191 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 21192
2fc8bdac 21193 if (fixp->fx_pcrel)
00a97672
RS
21194 {
21195 if (section->use_rela_p)
21196 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
21197 else
21198 fixp->fx_offset = reloc->address;
21199 }
c19d1205 21200 reloc->addend = fixp->fx_offset;
a737bd4d 21201
c19d1205 21202 switch (fixp->fx_r_type)
a737bd4d 21203 {
c19d1205
ZW
21204 case BFD_RELOC_8:
21205 if (fixp->fx_pcrel)
21206 {
21207 code = BFD_RELOC_8_PCREL;
21208 break;
21209 }
a737bd4d 21210
c19d1205
ZW
21211 case BFD_RELOC_16:
21212 if (fixp->fx_pcrel)
21213 {
21214 code = BFD_RELOC_16_PCREL;
21215 break;
21216 }
6c43fab6 21217
c19d1205
ZW
21218 case BFD_RELOC_32:
21219 if (fixp->fx_pcrel)
21220 {
21221 code = BFD_RELOC_32_PCREL;
21222 break;
21223 }
a737bd4d 21224
b6895b4f
PB
21225 case BFD_RELOC_ARM_MOVW:
21226 if (fixp->fx_pcrel)
21227 {
21228 code = BFD_RELOC_ARM_MOVW_PCREL;
21229 break;
21230 }
21231
21232 case BFD_RELOC_ARM_MOVT:
21233 if (fixp->fx_pcrel)
21234 {
21235 code = BFD_RELOC_ARM_MOVT_PCREL;
21236 break;
21237 }
21238
21239 case BFD_RELOC_ARM_THUMB_MOVW:
21240 if (fixp->fx_pcrel)
21241 {
21242 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21243 break;
21244 }
21245
21246 case BFD_RELOC_ARM_THUMB_MOVT:
21247 if (fixp->fx_pcrel)
21248 {
21249 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21250 break;
21251 }
21252
c19d1205
ZW
21253 case BFD_RELOC_NONE:
21254 case BFD_RELOC_ARM_PCREL_BRANCH:
21255 case BFD_RELOC_ARM_PCREL_BLX:
21256 case BFD_RELOC_RVA:
21257 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21258 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21259 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21260 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21261 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21262 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
21263 case BFD_RELOC_VTABLE_ENTRY:
21264 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
21265#ifdef TE_PE
21266 case BFD_RELOC_32_SECREL:
21267#endif
c19d1205
ZW
21268 code = fixp->fx_r_type;
21269 break;
a737bd4d 21270
00adf2d4
JB
21271 case BFD_RELOC_THUMB_PCREL_BLX:
21272#ifdef OBJ_ELF
21273 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21274 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21275 else
21276#endif
21277 code = BFD_RELOC_THUMB_PCREL_BLX;
21278 break;
21279
c19d1205
ZW
21280 case BFD_RELOC_ARM_LITERAL:
21281 case BFD_RELOC_ARM_HWLITERAL:
21282 /* If this is called then the a literal has
21283 been referenced across a section boundary. */
21284 as_bad_where (fixp->fx_file, fixp->fx_line,
21285 _("literal referenced across section boundary"));
21286 return NULL;
a737bd4d 21287
c19d1205
ZW
21288#ifdef OBJ_ELF
21289 case BFD_RELOC_ARM_GOT32:
21290 case BFD_RELOC_ARM_GOTOFF:
b43420e6 21291 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
21292 case BFD_RELOC_ARM_PLT32:
21293 case BFD_RELOC_ARM_TARGET1:
21294 case BFD_RELOC_ARM_ROSEGREL32:
21295 case BFD_RELOC_ARM_SBREL32:
21296 case BFD_RELOC_ARM_PREL31:
21297 case BFD_RELOC_ARM_TARGET2:
21298 case BFD_RELOC_ARM_TLS_LE32:
21299 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
21300 case BFD_RELOC_ARM_PCREL_CALL:
21301 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
21302 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21303 case BFD_RELOC_ARM_ALU_PC_G0:
21304 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21305 case BFD_RELOC_ARM_ALU_PC_G1:
21306 case BFD_RELOC_ARM_ALU_PC_G2:
21307 case BFD_RELOC_ARM_LDR_PC_G0:
21308 case BFD_RELOC_ARM_LDR_PC_G1:
21309 case BFD_RELOC_ARM_LDR_PC_G2:
21310 case BFD_RELOC_ARM_LDRS_PC_G0:
21311 case BFD_RELOC_ARM_LDRS_PC_G1:
21312 case BFD_RELOC_ARM_LDRS_PC_G2:
21313 case BFD_RELOC_ARM_LDC_PC_G0:
21314 case BFD_RELOC_ARM_LDC_PC_G1:
21315 case BFD_RELOC_ARM_LDC_PC_G2:
21316 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21317 case BFD_RELOC_ARM_ALU_SB_G0:
21318 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21319 case BFD_RELOC_ARM_ALU_SB_G1:
21320 case BFD_RELOC_ARM_ALU_SB_G2:
21321 case BFD_RELOC_ARM_LDR_SB_G0:
21322 case BFD_RELOC_ARM_LDR_SB_G1:
21323 case BFD_RELOC_ARM_LDR_SB_G2:
21324 case BFD_RELOC_ARM_LDRS_SB_G0:
21325 case BFD_RELOC_ARM_LDRS_SB_G1:
21326 case BFD_RELOC_ARM_LDRS_SB_G2:
21327 case BFD_RELOC_ARM_LDC_SB_G0:
21328 case BFD_RELOC_ARM_LDC_SB_G1:
21329 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 21330 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
21331 code = fixp->fx_r_type;
21332 break;
a737bd4d 21333
c19d1205
ZW
21334 case BFD_RELOC_ARM_TLS_GD32:
21335 case BFD_RELOC_ARM_TLS_IE32:
21336 case BFD_RELOC_ARM_TLS_LDM32:
21337 /* BFD will include the symbol's address in the addend.
21338 But we don't want that, so subtract it out again here. */
21339 if (!S_IS_COMMON (fixp->fx_addsy))
21340 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21341 code = fixp->fx_r_type;
21342 break;
21343#endif
a737bd4d 21344
c19d1205
ZW
21345 case BFD_RELOC_ARM_IMMEDIATE:
21346 as_bad_where (fixp->fx_file, fixp->fx_line,
21347 _("internal relocation (type: IMMEDIATE) not fixed up"));
21348 return NULL;
a737bd4d 21349
c19d1205
ZW
21350 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21351 as_bad_where (fixp->fx_file, fixp->fx_line,
21352 _("ADRL used for a symbol not defined in the same file"));
21353 return NULL;
a737bd4d 21354
c19d1205 21355 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
21356 if (section->use_rela_p)
21357 {
21358 code = fixp->fx_r_type;
21359 break;
21360 }
21361
c19d1205
ZW
21362 if (fixp->fx_addsy != NULL
21363 && !S_IS_DEFINED (fixp->fx_addsy)
21364 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 21365 {
c19d1205
ZW
21366 as_bad_where (fixp->fx_file, fixp->fx_line,
21367 _("undefined local label `%s'"),
21368 S_GET_NAME (fixp->fx_addsy));
21369 return NULL;
a737bd4d
NC
21370 }
21371
c19d1205
ZW
21372 as_bad_where (fixp->fx_file, fixp->fx_line,
21373 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21374 return NULL;
a737bd4d 21375
c19d1205
ZW
21376 default:
21377 {
21378 char * type;
6c43fab6 21379
c19d1205
ZW
21380 switch (fixp->fx_r_type)
21381 {
21382 case BFD_RELOC_NONE: type = "NONE"; break;
21383 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21384 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 21385 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
21386 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21387 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21388 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 21389 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 21390 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
21391 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21392 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21393 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21394 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21395 default: type = _("<unknown>"); break;
21396 }
21397 as_bad_where (fixp->fx_file, fixp->fx_line,
21398 _("cannot represent %s relocation in this object file format"),
21399 type);
21400 return NULL;
21401 }
a737bd4d 21402 }
6c43fab6 21403
c19d1205
ZW
21404#ifdef OBJ_ELF
21405 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21406 && GOT_symbol
21407 && fixp->fx_addsy == GOT_symbol)
21408 {
21409 code = BFD_RELOC_ARM_GOTPC;
21410 reloc->addend = fixp->fx_offset = reloc->address;
21411 }
21412#endif
6c43fab6 21413
c19d1205 21414 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 21415
c19d1205
ZW
21416 if (reloc->howto == NULL)
21417 {
21418 as_bad_where (fixp->fx_file, fixp->fx_line,
21419 _("cannot represent %s relocation in this object file format"),
21420 bfd_get_reloc_code_name (code));
21421 return NULL;
21422 }
6c43fab6 21423
c19d1205
ZW
21424 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21425 vtable entry to be used in the relocation's section offset. */
21426 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21427 reloc->address = fixp->fx_offset;
6c43fab6 21428
c19d1205 21429 return reloc;
6c43fab6
RE
21430}
21431
c19d1205 21432/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 21433
c19d1205
ZW
21434void
21435cons_fix_new_arm (fragS * frag,
21436 int where,
21437 int size,
21438 expressionS * exp)
6c43fab6 21439{
c19d1205
ZW
21440 bfd_reloc_code_real_type type;
21441 int pcrel = 0;
6c43fab6 21442
c19d1205
ZW
21443 /* Pick a reloc.
21444 FIXME: @@ Should look at CPU word size. */
21445 switch (size)
21446 {
21447 case 1:
21448 type = BFD_RELOC_8;
21449 break;
21450 case 2:
21451 type = BFD_RELOC_16;
21452 break;
21453 case 4:
21454 default:
21455 type = BFD_RELOC_32;
21456 break;
21457 case 8:
21458 type = BFD_RELOC_64;
21459 break;
21460 }
6c43fab6 21461
f0927246
NC
21462#ifdef TE_PE
21463 if (exp->X_op == O_secrel)
21464 {
21465 exp->X_op = O_symbol;
21466 type = BFD_RELOC_32_SECREL;
21467 }
21468#endif
21469
c19d1205
ZW
21470 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21471}
6c43fab6 21472
4343666d 21473#if defined (OBJ_COFF)
c19d1205
ZW
21474void
21475arm_validate_fix (fixS * fixP)
6c43fab6 21476{
c19d1205
ZW
21477 /* If the destination of the branch is a defined symbol which does not have
21478 the THUMB_FUNC attribute, then we must be calling a function which has
21479 the (interfacearm) attribute. We look for the Thumb entry point to that
21480 function and change the branch to refer to that function instead. */
21481 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21482 && fixP->fx_addsy != NULL
21483 && S_IS_DEFINED (fixP->fx_addsy)
21484 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 21485 {
c19d1205 21486 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 21487 }
c19d1205
ZW
21488}
21489#endif
6c43fab6 21490
267bf995 21491
c19d1205
ZW
21492int
21493arm_force_relocation (struct fix * fixp)
21494{
21495#if defined (OBJ_COFF) && defined (TE_PE)
21496 if (fixp->fx_r_type == BFD_RELOC_RVA)
21497 return 1;
21498#endif
6c43fab6 21499
267bf995
RR
21500 /* In case we have a call or a branch to a function in ARM ISA mode from
21501 a thumb function or vice-versa force the relocation. These relocations
21502 are cleared off for some cores that might have blx and simple transformations
21503 are possible. */
21504
21505#ifdef OBJ_ELF
21506 switch (fixp->fx_r_type)
21507 {
21508 case BFD_RELOC_ARM_PCREL_JUMP:
21509 case BFD_RELOC_ARM_PCREL_CALL:
21510 case BFD_RELOC_THUMB_PCREL_BLX:
21511 if (THUMB_IS_FUNC (fixp->fx_addsy))
21512 return 1;
21513 break;
21514
21515 case BFD_RELOC_ARM_PCREL_BLX:
21516 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21517 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21518 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21519 if (ARM_IS_FUNC (fixp->fx_addsy))
21520 return 1;
21521 break;
21522
21523 default:
21524 break;
21525 }
21526#endif
21527
c19d1205
ZW
21528 /* Resolve these relocations even if the symbol is extern or weak. */
21529 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21530 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 21531 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 21532 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
21533 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21534 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
21535 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 21536 return 0;
a737bd4d 21537
4962c51a
MS
21538 /* Always leave these relocations for the linker. */
21539 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21540 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21541 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21542 return 1;
21543
f0291e4c
PB
21544 /* Always generate relocations against function symbols. */
21545 if (fixp->fx_r_type == BFD_RELOC_32
21546 && fixp->fx_addsy
21547 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21548 return 1;
21549
c19d1205 21550 return generic_force_reloc (fixp);
404ff6b5
AH
21551}
21552
0ffdc86c 21553#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
21554/* Relocations against function names must be left unadjusted,
21555 so that the linker can use this information to generate interworking
21556 stubs. The MIPS version of this function
c19d1205
ZW
21557 also prevents relocations that are mips-16 specific, but I do not
21558 know why it does this.
404ff6b5 21559
c19d1205
ZW
21560 FIXME:
21561 There is one other problem that ought to be addressed here, but
21562 which currently is not: Taking the address of a label (rather
21563 than a function) and then later jumping to that address. Such
21564 addresses also ought to have their bottom bit set (assuming that
21565 they reside in Thumb code), but at the moment they will not. */
404ff6b5 21566
c19d1205
ZW
21567bfd_boolean
21568arm_fix_adjustable (fixS * fixP)
404ff6b5 21569{
c19d1205
ZW
21570 if (fixP->fx_addsy == NULL)
21571 return 1;
404ff6b5 21572
e28387c3
PB
21573 /* Preserve relocations against symbols with function type. */
21574 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 21575 return FALSE;
e28387c3 21576
c19d1205
ZW
21577 if (THUMB_IS_FUNC (fixP->fx_addsy)
21578 && fixP->fx_subsy == NULL)
c921be7d 21579 return FALSE;
a737bd4d 21580
c19d1205
ZW
21581 /* We need the symbol name for the VTABLE entries. */
21582 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
21583 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 21584 return FALSE;
404ff6b5 21585
c19d1205
ZW
21586 /* Don't allow symbols to be discarded on GOT related relocs. */
21587 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
21588 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
21589 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
21590 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
21591 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
21592 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
21593 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
21594 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
21595 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 21596 return FALSE;
a737bd4d 21597
4962c51a
MS
21598 /* Similarly for group relocations. */
21599 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21600 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21601 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 21602 return FALSE;
4962c51a 21603
79947c54
CD
21604 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
21605 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
21606 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21607 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
21608 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
21609 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21610 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
21611 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
21612 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 21613 return FALSE;
79947c54 21614
c921be7d 21615 return TRUE;
a737bd4d 21616}
0ffdc86c
NC
21617#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
21618
21619#ifdef OBJ_ELF
404ff6b5 21620
c19d1205
ZW
21621const char *
21622elf32_arm_target_format (void)
404ff6b5 21623{
c19d1205
ZW
21624#ifdef TE_SYMBIAN
21625 return (target_big_endian
21626 ? "elf32-bigarm-symbian"
21627 : "elf32-littlearm-symbian");
21628#elif defined (TE_VXWORKS)
21629 return (target_big_endian
21630 ? "elf32-bigarm-vxworks"
21631 : "elf32-littlearm-vxworks");
21632#else
21633 if (target_big_endian)
21634 return "elf32-bigarm";
21635 else
21636 return "elf32-littlearm";
21637#endif
404ff6b5
AH
21638}
21639
c19d1205
ZW
21640void
21641armelf_frob_symbol (symbolS * symp,
21642 int * puntp)
404ff6b5 21643{
c19d1205
ZW
21644 elf_frob_symbol (symp, puntp);
21645}
21646#endif
404ff6b5 21647
c19d1205 21648/* MD interface: Finalization. */
a737bd4d 21649
c19d1205
ZW
21650void
21651arm_cleanup (void)
21652{
21653 literal_pool * pool;
a737bd4d 21654
e07e6e58
NC
21655 /* Ensure that all the IT blocks are properly closed. */
21656 check_it_blocks_finished ();
21657
c19d1205
ZW
21658 for (pool = list_of_pools; pool; pool = pool->next)
21659 {
5f4273c7 21660 /* Put it at the end of the relevant section. */
c19d1205
ZW
21661 subseg_set (pool->section, pool->sub_section);
21662#ifdef OBJ_ELF
21663 arm_elf_change_section ();
21664#endif
21665 s_ltorg (0);
21666 }
404ff6b5
AH
21667}
21668
cd000bff
DJ
21669#ifdef OBJ_ELF
21670/* Remove any excess mapping symbols generated for alignment frags in
21671 SEC. We may have created a mapping symbol before a zero byte
21672 alignment; remove it if there's a mapping symbol after the
21673 alignment. */
21674static void
21675check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
21676 void *dummy ATTRIBUTE_UNUSED)
21677{
21678 segment_info_type *seginfo = seg_info (sec);
21679 fragS *fragp;
21680
21681 if (seginfo == NULL || seginfo->frchainP == NULL)
21682 return;
21683
21684 for (fragp = seginfo->frchainP->frch_root;
21685 fragp != NULL;
21686 fragp = fragp->fr_next)
21687 {
21688 symbolS *sym = fragp->tc_frag_data.last_map;
21689 fragS *next = fragp->fr_next;
21690
21691 /* Variable-sized frags have been converted to fixed size by
21692 this point. But if this was variable-sized to start with,
21693 there will be a fixed-size frag after it. So don't handle
21694 next == NULL. */
21695 if (sym == NULL || next == NULL)
21696 continue;
21697
21698 if (S_GET_VALUE (sym) < next->fr_address)
21699 /* Not at the end of this frag. */
21700 continue;
21701 know (S_GET_VALUE (sym) == next->fr_address);
21702
21703 do
21704 {
21705 if (next->tc_frag_data.first_map != NULL)
21706 {
21707 /* Next frag starts with a mapping symbol. Discard this
21708 one. */
21709 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21710 break;
21711 }
21712
21713 if (next->fr_next == NULL)
21714 {
21715 /* This mapping symbol is at the end of the section. Discard
21716 it. */
21717 know (next->fr_fix == 0 && next->fr_var == 0);
21718 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21719 break;
21720 }
21721
21722 /* As long as we have empty frags without any mapping symbols,
21723 keep looking. */
21724 /* If the next frag is non-empty and does not start with a
21725 mapping symbol, then this mapping symbol is required. */
21726 if (next->fr_address != next->fr_next->fr_address)
21727 break;
21728
21729 next = next->fr_next;
21730 }
21731 while (next != NULL);
21732 }
21733}
21734#endif
21735
c19d1205
ZW
21736/* Adjust the symbol table. This marks Thumb symbols as distinct from
21737 ARM ones. */
404ff6b5 21738
c19d1205
ZW
21739void
21740arm_adjust_symtab (void)
404ff6b5 21741{
c19d1205
ZW
21742#ifdef OBJ_COFF
21743 symbolS * sym;
404ff6b5 21744
c19d1205
ZW
21745 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21746 {
21747 if (ARM_IS_THUMB (sym))
21748 {
21749 if (THUMB_IS_FUNC (sym))
21750 {
21751 /* Mark the symbol as a Thumb function. */
21752 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
21753 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
21754 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 21755
c19d1205
ZW
21756 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
21757 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
21758 else
21759 as_bad (_("%s: unexpected function type: %d"),
21760 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
21761 }
21762 else switch (S_GET_STORAGE_CLASS (sym))
21763 {
21764 case C_EXT:
21765 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
21766 break;
21767 case C_STAT:
21768 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
21769 break;
21770 case C_LABEL:
21771 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
21772 break;
21773 default:
21774 /* Do nothing. */
21775 break;
21776 }
21777 }
a737bd4d 21778
c19d1205
ZW
21779 if (ARM_IS_INTERWORK (sym))
21780 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 21781 }
c19d1205
ZW
21782#endif
21783#ifdef OBJ_ELF
21784 symbolS * sym;
21785 char bind;
404ff6b5 21786
c19d1205 21787 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 21788 {
c19d1205
ZW
21789 if (ARM_IS_THUMB (sym))
21790 {
21791 elf_symbol_type * elf_sym;
404ff6b5 21792
c19d1205
ZW
21793 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
21794 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 21795
b0796911
PB
21796 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
21797 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
21798 {
21799 /* If it's a .thumb_func, declare it as so,
21800 otherwise tag label as .code 16. */
21801 if (THUMB_IS_FUNC (sym))
21802 elf_sym->internal_elf_sym.st_info =
21803 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 21804 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
21805 elf_sym->internal_elf_sym.st_info =
21806 ELF_ST_INFO (bind, STT_ARM_16BIT);
21807 }
21808 }
21809 }
cd000bff
DJ
21810
21811 /* Remove any overlapping mapping symbols generated by alignment frags. */
21812 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
c19d1205 21813#endif
404ff6b5
AH
21814}
21815
c19d1205 21816/* MD interface: Initialization. */
404ff6b5 21817
a737bd4d 21818static void
c19d1205 21819set_constant_flonums (void)
a737bd4d 21820{
c19d1205 21821 int i;
404ff6b5 21822
c19d1205
ZW
21823 for (i = 0; i < NUM_FLOAT_VALS; i++)
21824 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
21825 abort ();
a737bd4d 21826}
404ff6b5 21827
3e9e4fcf
JB
21828/* Auto-select Thumb mode if it's the only available instruction set for the
21829 given architecture. */
21830
21831static void
21832autoselect_thumb_from_cpu_variant (void)
21833{
21834 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
21835 opcode_select (16);
21836}
21837
c19d1205
ZW
21838void
21839md_begin (void)
a737bd4d 21840{
c19d1205
ZW
21841 unsigned mach;
21842 unsigned int i;
404ff6b5 21843
c19d1205
ZW
21844 if ( (arm_ops_hsh = hash_new ()) == NULL
21845 || (arm_cond_hsh = hash_new ()) == NULL
21846 || (arm_shift_hsh = hash_new ()) == NULL
21847 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 21848 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 21849 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
21850 || (arm_reloc_hsh = hash_new ()) == NULL
21851 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
21852 as_fatal (_("virtual memory exhausted"));
21853
21854 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 21855 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 21856 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 21857 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 21858 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 21859 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 21860 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 21861 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 21862 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0
NC
21863 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
21864 (void *) (v7m_psrs + i));
c19d1205 21865 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 21866 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
21867 for (i = 0;
21868 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
21869 i++)
d3ce72d0 21870 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 21871 (void *) (barrier_opt_names + i));
c19d1205
ZW
21872#ifdef OBJ_ELF
21873 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 21874 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
21875#endif
21876
21877 set_constant_flonums ();
404ff6b5 21878
c19d1205
ZW
21879 /* Set the cpu variant based on the command-line options. We prefer
21880 -mcpu= over -march= if both are set (as for GCC); and we prefer
21881 -mfpu= over any other way of setting the floating point unit.
21882 Use of legacy options with new options are faulted. */
e74cfd16 21883 if (legacy_cpu)
404ff6b5 21884 {
e74cfd16 21885 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
21886 as_bad (_("use of old and new-style options to set CPU type"));
21887
21888 mcpu_cpu_opt = legacy_cpu;
404ff6b5 21889 }
e74cfd16 21890 else if (!mcpu_cpu_opt)
c19d1205 21891 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 21892
e74cfd16 21893 if (legacy_fpu)
c19d1205 21894 {
e74cfd16 21895 if (mfpu_opt)
c19d1205 21896 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
21897
21898 mfpu_opt = legacy_fpu;
21899 }
e74cfd16 21900 else if (!mfpu_opt)
03b1477f 21901 {
45eb4c1b
NS
21902#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
21903 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
21904 /* Some environments specify a default FPU. If they don't, infer it
21905 from the processor. */
e74cfd16 21906 if (mcpu_fpu_opt)
03b1477f
RE
21907 mfpu_opt = mcpu_fpu_opt;
21908 else
21909 mfpu_opt = march_fpu_opt;
39c2da32 21910#else
e74cfd16 21911 mfpu_opt = &fpu_default;
39c2da32 21912#endif
03b1477f
RE
21913 }
21914
e74cfd16 21915 if (!mfpu_opt)
03b1477f 21916 {
493cb6ef 21917 if (mcpu_cpu_opt != NULL)
e74cfd16 21918 mfpu_opt = &fpu_default;
493cb6ef 21919 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 21920 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 21921 else
e74cfd16 21922 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
21923 }
21924
ee065d83 21925#ifdef CPU_DEFAULT
e74cfd16 21926 if (!mcpu_cpu_opt)
ee065d83 21927 {
e74cfd16
PB
21928 mcpu_cpu_opt = &cpu_default;
21929 selected_cpu = cpu_default;
ee065d83 21930 }
e74cfd16
PB
21931#else
21932 if (mcpu_cpu_opt)
21933 selected_cpu = *mcpu_cpu_opt;
ee065d83 21934 else
e74cfd16 21935 mcpu_cpu_opt = &arm_arch_any;
ee065d83 21936#endif
03b1477f 21937
e74cfd16 21938 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 21939
3e9e4fcf
JB
21940 autoselect_thumb_from_cpu_variant ();
21941
e74cfd16 21942 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 21943
f17c130b 21944#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 21945 {
7cc69913
NC
21946 unsigned int flags = 0;
21947
21948#if defined OBJ_ELF
21949 flags = meabi_flags;
d507cf36
PB
21950
21951 switch (meabi_flags)
33a392fb 21952 {
d507cf36 21953 case EF_ARM_EABI_UNKNOWN:
7cc69913 21954#endif
d507cf36
PB
21955 /* Set the flags in the private structure. */
21956 if (uses_apcs_26) flags |= F_APCS26;
21957 if (support_interwork) flags |= F_INTERWORK;
21958 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 21959 if (pic_code) flags |= F_PIC;
e74cfd16 21960 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
21961 flags |= F_SOFT_FLOAT;
21962
d507cf36
PB
21963 switch (mfloat_abi_opt)
21964 {
21965 case ARM_FLOAT_ABI_SOFT:
21966 case ARM_FLOAT_ABI_SOFTFP:
21967 flags |= F_SOFT_FLOAT;
21968 break;
33a392fb 21969
d507cf36
PB
21970 case ARM_FLOAT_ABI_HARD:
21971 if (flags & F_SOFT_FLOAT)
21972 as_bad (_("hard-float conflicts with specified fpu"));
21973 break;
21974 }
03b1477f 21975
e74cfd16
PB
21976 /* Using pure-endian doubles (even if soft-float). */
21977 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 21978 flags |= F_VFP_FLOAT;
f17c130b 21979
fde78edd 21980#if defined OBJ_ELF
e74cfd16 21981 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 21982 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
21983 break;
21984
8cb51566 21985 case EF_ARM_EABI_VER4:
3a4a14e9 21986 case EF_ARM_EABI_VER5:
c19d1205 21987 /* No additional flags to set. */
d507cf36
PB
21988 break;
21989
21990 default:
21991 abort ();
21992 }
7cc69913 21993#endif
b99bd4ef
NC
21994 bfd_set_private_flags (stdoutput, flags);
21995
21996 /* We have run out flags in the COFF header to encode the
21997 status of ATPCS support, so instead we create a dummy,
c19d1205 21998 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
21999 if (atpcs)
22000 {
22001 asection * sec;
22002
22003 sec = bfd_make_section (stdoutput, ".arm.atpcs");
22004
22005 if (sec != NULL)
22006 {
22007 bfd_set_section_flags
22008 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
22009 bfd_set_section_size (stdoutput, sec, 0);
22010 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
22011 }
22012 }
7cc69913 22013 }
f17c130b 22014#endif
b99bd4ef
NC
22015
22016 /* Record the CPU type as well. */
2d447fca
JM
22017 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
22018 mach = bfd_mach_arm_iWMMXt2;
22019 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 22020 mach = bfd_mach_arm_iWMMXt;
e74cfd16 22021 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 22022 mach = bfd_mach_arm_XScale;
e74cfd16 22023 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 22024 mach = bfd_mach_arm_ep9312;
e74cfd16 22025 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 22026 mach = bfd_mach_arm_5TE;
e74cfd16 22027 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 22028 {
e74cfd16 22029 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22030 mach = bfd_mach_arm_5T;
22031 else
22032 mach = bfd_mach_arm_5;
22033 }
e74cfd16 22034 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 22035 {
e74cfd16 22036 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22037 mach = bfd_mach_arm_4T;
22038 else
22039 mach = bfd_mach_arm_4;
22040 }
e74cfd16 22041 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 22042 mach = bfd_mach_arm_3M;
e74cfd16
PB
22043 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
22044 mach = bfd_mach_arm_3;
22045 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
22046 mach = bfd_mach_arm_2a;
22047 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
22048 mach = bfd_mach_arm_2;
22049 else
22050 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
22051
22052 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
22053}
22054
c19d1205 22055/* Command line processing. */
b99bd4ef 22056
c19d1205
ZW
22057/* md_parse_option
22058 Invocation line includes a switch not recognized by the base assembler.
22059 See if it's a processor-specific option.
b99bd4ef 22060
c19d1205
ZW
22061 This routine is somewhat complicated by the need for backwards
22062 compatibility (since older releases of gcc can't be changed).
22063 The new options try to make the interface as compatible as
22064 possible with GCC.
b99bd4ef 22065
c19d1205 22066 New options (supported) are:
b99bd4ef 22067
c19d1205
ZW
22068 -mcpu=<cpu name> Assemble for selected processor
22069 -march=<architecture name> Assemble for selected architecture
22070 -mfpu=<fpu architecture> Assemble for selected FPU.
22071 -EB/-mbig-endian Big-endian
22072 -EL/-mlittle-endian Little-endian
22073 -k Generate PIC code
22074 -mthumb Start in Thumb mode
22075 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 22076
278df34e 22077 -m[no-]warn-deprecated Warn about deprecated features
267bf995 22078
c19d1205 22079 For now we will also provide support for:
b99bd4ef 22080
c19d1205
ZW
22081 -mapcs-32 32-bit Program counter
22082 -mapcs-26 26-bit Program counter
22083 -macps-float Floats passed in FP registers
22084 -mapcs-reentrant Reentrant code
22085 -matpcs
22086 (sometime these will probably be replaced with -mapcs=<list of options>
22087 and -matpcs=<list of options>)
b99bd4ef 22088
c19d1205
ZW
22089 The remaining options are only supported for back-wards compatibility.
22090 Cpu variants, the arm part is optional:
22091 -m[arm]1 Currently not supported.
22092 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
22093 -m[arm]3 Arm 3 processor
22094 -m[arm]6[xx], Arm 6 processors
22095 -m[arm]7[xx][t][[d]m] Arm 7 processors
22096 -m[arm]8[10] Arm 8 processors
22097 -m[arm]9[20][tdmi] Arm 9 processors
22098 -mstrongarm[110[0]] StrongARM processors
22099 -mxscale XScale processors
22100 -m[arm]v[2345[t[e]]] Arm architectures
22101 -mall All (except the ARM1)
22102 FP variants:
22103 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
22104 -mfpe-old (No float load/store multiples)
22105 -mvfpxd VFP Single precision
22106 -mvfp All VFP
22107 -mno-fpu Disable all floating point instructions
b99bd4ef 22108
c19d1205
ZW
22109 The following CPU names are recognized:
22110 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
22111 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
22112 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
22113 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
22114 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
22115 arm10t arm10e, arm1020t, arm1020e, arm10200e,
22116 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 22117
c19d1205 22118 */
b99bd4ef 22119
c19d1205 22120const char * md_shortopts = "m:k";
b99bd4ef 22121
c19d1205
ZW
22122#ifdef ARM_BI_ENDIAN
22123#define OPTION_EB (OPTION_MD_BASE + 0)
22124#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 22125#else
c19d1205
ZW
22126#if TARGET_BYTES_BIG_ENDIAN
22127#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 22128#else
c19d1205
ZW
22129#define OPTION_EL (OPTION_MD_BASE + 1)
22130#endif
b99bd4ef 22131#endif
845b51d6 22132#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 22133
c19d1205 22134struct option md_longopts[] =
b99bd4ef 22135{
c19d1205
ZW
22136#ifdef OPTION_EB
22137 {"EB", no_argument, NULL, OPTION_EB},
22138#endif
22139#ifdef OPTION_EL
22140 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 22141#endif
845b51d6 22142 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
22143 {NULL, no_argument, NULL, 0}
22144};
b99bd4ef 22145
c19d1205 22146size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 22147
c19d1205 22148struct arm_option_table
b99bd4ef 22149{
c19d1205
ZW
22150 char *option; /* Option name to match. */
22151 char *help; /* Help information. */
22152 int *var; /* Variable to change. */
22153 int value; /* What to change it to. */
22154 char *deprecated; /* If non-null, print this message. */
22155};
b99bd4ef 22156
c19d1205
ZW
22157struct arm_option_table arm_opts[] =
22158{
22159 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
22160 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
22161 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
22162 &support_interwork, 1, NULL},
22163 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
22164 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
22165 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
22166 1, NULL},
22167 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
22168 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
22169 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
22170 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
22171 NULL},
b99bd4ef 22172
c19d1205
ZW
22173 /* These are recognized by the assembler, but have no affect on code. */
22174 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
22175 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
22176
22177 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
22178 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
22179 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
22180 {NULL, NULL, NULL, 0, NULL}
22181};
22182
22183struct arm_legacy_option_table
22184{
22185 char *option; /* Option name to match. */
22186 const arm_feature_set **var; /* Variable to change. */
22187 const arm_feature_set value; /* What to change it to. */
22188 char *deprecated; /* If non-null, print this message. */
22189};
b99bd4ef 22190
e74cfd16
PB
22191const struct arm_legacy_option_table arm_legacy_opts[] =
22192{
c19d1205
ZW
22193 /* DON'T add any new processors to this list -- we want the whole list
22194 to go away... Add them to the processors table instead. */
e74cfd16
PB
22195 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22196 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22197 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22198 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22199 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22200 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22201 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22202 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22203 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22204 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22205 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22206 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22207 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22208 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22209 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22210 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22211 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22212 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22213 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22214 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22215 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22216 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22217 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22218 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22219 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22220 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22221 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22222 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22223 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22224 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22225 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22226 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22227 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22228 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22229 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22230 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22231 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22232 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22233 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22234 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22235 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22236 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22237 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22238 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22239 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22240 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22241 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22242 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22243 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22244 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22245 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22246 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22247 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22248 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22249 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22250 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22251 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22252 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22253 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22254 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22255 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22256 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22257 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22258 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22259 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22260 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22261 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22262 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22263 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22264 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22265 N_("use -mcpu=strongarm110")},
e74cfd16 22266 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22267 N_("use -mcpu=strongarm1100")},
e74cfd16 22268 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22269 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
22270 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22271 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22272 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 22273
c19d1205 22274 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
22275 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22276 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22277 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22278 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22279 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22280 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22281 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22282 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22283 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22284 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22285 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22286 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22287 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22288 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22289 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22290 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22291 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22292 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 22293
c19d1205 22294 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
22295 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22296 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22297 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22298 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 22299 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 22300
e74cfd16 22301 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 22302};
7ed4c4c5 22303
c19d1205 22304struct arm_cpu_option_table
7ed4c4c5 22305{
c19d1205 22306 char *name;
e74cfd16 22307 const arm_feature_set value;
c19d1205
ZW
22308 /* For some CPUs we assume an FPU unless the user explicitly sets
22309 -mfpu=... */
e74cfd16 22310 const arm_feature_set default_fpu;
ee065d83
PB
22311 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22312 case. */
22313 const char *canonical_name;
c19d1205 22314};
7ed4c4c5 22315
c19d1205
ZW
22316/* This list should, at a minimum, contain all the cpu names
22317 recognized by GCC. */
e74cfd16 22318static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 22319{
ee065d83
PB
22320 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
22321 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
22322 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
22323 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22324 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22325 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22326 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22327 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22328 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22329 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22330 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22331 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22332 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22333 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22334 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22335 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22336 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22337 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22338 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22339 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22340 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22341 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22342 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22343 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22344 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22345 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22346 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22347 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22348 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22349 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22350 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22351 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22352 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22353 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22354 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22355 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22356 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22357 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22358 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22359 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
22360 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22361 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22362 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22363 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
22364 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22365 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
22366 /* For V5 or later processors we default to using VFP; but the user
22367 should really set the FPU type explicitly. */
ee065d83
PB
22368 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22369 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22370 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22371 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22372 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22373 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22374 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22375 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22376 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22377 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22378 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22379 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22380 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22381 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22382 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22383 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22384 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22385 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22386 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22387 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22388 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
7fac0536
NC
22389 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
22390 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
22391 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22392 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22393 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22394 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
4ff9b924
MGD
22395 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"},
22396 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"},
ee065d83
PB
22397 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22398 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22399 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22400 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
f4c65163
MGD
22401 {"cortex-a5", ARM_ARCH_V7A_MP_SEC,
22402 FPU_NONE, "Cortex-A5"},
22403 {"cortex-a8", ARM_ARCH_V7A_SEC,
22404 ARM_FEATURE (0, FPU_VFP_V3
5287ad62 22405 | FPU_NEON_EXT_V1),
4ff9b924 22406 "Cortex-A8"},
f4c65163
MGD
22407 {"cortex-a9", ARM_ARCH_V7A_MP_SEC,
22408 ARM_FEATURE (0, FPU_VFP_V3
15290f0a 22409 | FPU_NEON_EXT_V1),
4ff9b924 22410 "Cortex-A9"},
f4c65163
MGD
22411 {"cortex-a15", ARM_ARCH_V7A_MP_SEC,
22412 FPU_ARCH_NEON_VFP_V4,
dbb1f804 22413 "Cortex-A15"},
4ff9b924
MGD
22414 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"},
22415 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
22416 "Cortex-R4F"},
22417 {"cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"},
22418 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"},
b2a5fbdc
MGD
22419 {"cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"},
22420 {"cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"},
c19d1205 22421 /* ??? XSCALE is really an architecture. */
ee065d83 22422 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22423 /* ??? iwmmxt is not a processor. */
ee065d83 22424 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 22425 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 22426 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22427 /* Maverick */
e07e6e58 22428 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
e74cfd16 22429 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 22430};
7ed4c4c5 22431
c19d1205 22432struct arm_arch_option_table
7ed4c4c5 22433{
c19d1205 22434 char *name;
e74cfd16
PB
22435 const arm_feature_set value;
22436 const arm_feature_set default_fpu;
c19d1205 22437};
7ed4c4c5 22438
c19d1205
ZW
22439/* This list should, at a minimum, contain all the architecture names
22440 recognized by GCC. */
e74cfd16 22441static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
22442{
22443 {"all", ARM_ANY, FPU_ARCH_FPA},
22444 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22445 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22446 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22447 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22448 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22449 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22450 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22451 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22452 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22453 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22454 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22455 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22456 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22457 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22458 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22459 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22460 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22461 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22462 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22463 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22464 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22465 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22466 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22467 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22468 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 22469 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
b2a5fbdc 22470 {"armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP},
62b3e311 22471 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
22472 /* The official spelling of the ARMv7 profile variants is the dashed form.
22473 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
22474 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22475 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22476 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
22477 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22478 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22479 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
9e3c6df6 22480 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
c19d1205
ZW
22481 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22482 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 22483 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 22484 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 22485};
7ed4c4c5 22486
69133863
MGD
22487/* ISA extensions in the co-processor and main instruction set space. */
22488struct arm_option_extension_value_table
c19d1205
ZW
22489{
22490 char *name;
e74cfd16 22491 const arm_feature_set value;
69133863 22492 const arm_feature_set allowed_archs;
c19d1205 22493};
7ed4c4c5 22494
69133863
MGD
22495/* The following table must be in alphabetical order with a NULL last entry.
22496 */
22497static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 22498{
69133863
MGD
22499 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY},
22500 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY},
22501 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY},
60e5ef9f
MGD
22502 {"mp", ARM_FEATURE (ARM_EXT_MP, 0),
22503 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)},
b2a5fbdc
MGD
22504 {"os", ARM_FEATURE (ARM_EXT_OS, 0),
22505 ARM_FEATURE (ARM_EXT_V6M, 0)},
f4c65163
MGD
22506 {"sec", ARM_FEATURE (ARM_EXT_SEC, 0),
22507 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)},
69133863 22508 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY},
60e5ef9f 22509 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
69133863
MGD
22510};
22511
22512/* ISA floating-point and Advanced SIMD extensions. */
22513struct arm_option_fpu_value_table
22514{
22515 char *name;
22516 const arm_feature_set value;
c19d1205 22517};
7ed4c4c5 22518
c19d1205
ZW
22519/* This list should, at a minimum, contain all the fpu names
22520 recognized by GCC. */
69133863 22521static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
22522{
22523 {"softfpa", FPU_NONE},
22524 {"fpe", FPU_ARCH_FPE},
22525 {"fpe2", FPU_ARCH_FPE},
22526 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22527 {"fpa", FPU_ARCH_FPA},
22528 {"fpa10", FPU_ARCH_FPA},
22529 {"fpa11", FPU_ARCH_FPA},
22530 {"arm7500fe", FPU_ARCH_FPA},
22531 {"softvfp", FPU_ARCH_VFP},
22532 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22533 {"vfp", FPU_ARCH_VFP_V2},
22534 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 22535 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
22536 {"vfp10", FPU_ARCH_VFP_V2},
22537 {"vfp10-r0", FPU_ARCH_VFP_V1},
22538 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
22539 {"vfpv2", FPU_ARCH_VFP_V2},
22540 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 22541 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 22542 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
22543 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
22544 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
22545 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
22546 {"arm1020t", FPU_ARCH_VFP_V1},
22547 {"arm1020e", FPU_ARCH_VFP_V2},
22548 {"arm1136jfs", FPU_ARCH_VFP_V2},
22549 {"arm1136jf-s", FPU_ARCH_VFP_V2},
22550 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 22551 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 22552 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
22553 {"vfpv4", FPU_ARCH_VFP_V4},
22554 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 22555 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 22556 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
e74cfd16
PB
22557 {NULL, ARM_ARCH_NONE}
22558};
22559
22560struct arm_option_value_table
22561{
22562 char *name;
22563 long value;
c19d1205 22564};
7ed4c4c5 22565
e74cfd16 22566static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
22567{
22568 {"hard", ARM_FLOAT_ABI_HARD},
22569 {"softfp", ARM_FLOAT_ABI_SOFTFP},
22570 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 22571 {NULL, 0}
c19d1205 22572};
7ed4c4c5 22573
c19d1205 22574#ifdef OBJ_ELF
3a4a14e9 22575/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 22576static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
22577{
22578 {"gnu", EF_ARM_EABI_UNKNOWN},
22579 {"4", EF_ARM_EABI_VER4},
3a4a14e9 22580 {"5", EF_ARM_EABI_VER5},
e74cfd16 22581 {NULL, 0}
c19d1205
ZW
22582};
22583#endif
7ed4c4c5 22584
c19d1205
ZW
22585struct arm_long_option_table
22586{
22587 char * option; /* Substring to match. */
22588 char * help; /* Help information. */
22589 int (* func) (char * subopt); /* Function to decode sub-option. */
22590 char * deprecated; /* If non-null, print this message. */
22591};
7ed4c4c5 22592
c921be7d 22593static bfd_boolean
e74cfd16 22594arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 22595{
21d799b5
NC
22596 arm_feature_set *ext_set = (arm_feature_set *)
22597 xmalloc (sizeof (arm_feature_set));
e74cfd16 22598
69133863
MGD
22599 /* We insist on extensions being specified in alphabetical order, and with
22600 extensions being added before being removed. We achieve this by having
22601 the global ARM_EXTENSIONS table in alphabetical order, and using the
22602 ADDING_VALUE variable to indicate whether we are adding an extension (1)
22603 or removing it (0) and only allowing it to change in the order
22604 -1 -> 1 -> 0. */
22605 const struct arm_option_extension_value_table * opt = NULL;
22606 int adding_value = -1;
22607
e74cfd16
PB
22608 /* Copy the feature set, so that we can modify it. */
22609 *ext_set = **opt_p;
22610 *opt_p = ext_set;
22611
c19d1205 22612 while (str != NULL && *str != 0)
7ed4c4c5 22613 {
c19d1205 22614 char * ext;
69133863 22615 size_t optlen;
7ed4c4c5 22616
c19d1205
ZW
22617 if (*str != '+')
22618 {
22619 as_bad (_("invalid architectural extension"));
c921be7d 22620 return FALSE;
c19d1205 22621 }
7ed4c4c5 22622
c19d1205
ZW
22623 str++;
22624 ext = strchr (str, '+');
7ed4c4c5 22625
c19d1205
ZW
22626 if (ext != NULL)
22627 optlen = ext - str;
22628 else
22629 optlen = strlen (str);
7ed4c4c5 22630
69133863
MGD
22631 if (optlen >= 2
22632 && strncmp (str, "no", 2) == 0)
22633 {
22634 if (adding_value != 0)
22635 {
22636 adding_value = 0;
22637 opt = arm_extensions;
22638 }
22639
22640 optlen -= 2;
22641 str += 2;
22642 }
22643 else if (optlen > 0)
22644 {
22645 if (adding_value == -1)
22646 {
22647 adding_value = 1;
22648 opt = arm_extensions;
22649 }
22650 else if (adding_value != 1)
22651 {
22652 as_bad (_("must specify extensions to add before specifying "
22653 "those to remove"));
22654 return FALSE;
22655 }
22656 }
22657
c19d1205
ZW
22658 if (optlen == 0)
22659 {
22660 as_bad (_("missing architectural extension"));
c921be7d 22661 return FALSE;
c19d1205 22662 }
7ed4c4c5 22663
69133863
MGD
22664 gas_assert (adding_value != -1);
22665 gas_assert (opt != NULL);
22666
22667 /* Scan over the options table trying to find an exact match. */
22668 for (; opt->name != NULL; opt++)
22669 if (strncmp (opt->name, str, optlen) == 0
22670 && strlen (opt->name) == optlen)
c19d1205 22671 {
69133863
MGD
22672 /* Check we can apply the extension to this architecture. */
22673 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
22674 {
22675 as_bad (_("extension does not apply to the base architecture"));
22676 return FALSE;
22677 }
22678
22679 /* Add or remove the extension. */
22680 if (adding_value)
22681 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
22682 else
22683 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
22684
c19d1205
ZW
22685 break;
22686 }
7ed4c4c5 22687
c19d1205
ZW
22688 if (opt->name == NULL)
22689 {
69133863
MGD
22690 /* Did we fail to find an extension because it wasn't specified in
22691 alphabetical order, or because it does not exist? */
22692
22693 for (opt = arm_extensions; opt->name != NULL; opt++)
22694 if (strncmp (opt->name, str, optlen) == 0)
22695 break;
22696
22697 if (opt->name == NULL)
22698 as_bad (_("unknown architectural extension `%s'"), str);
22699 else
22700 as_bad (_("architectural extensions must be specified in "
22701 "alphabetical order"));
22702
c921be7d 22703 return FALSE;
c19d1205 22704 }
69133863
MGD
22705 else
22706 {
22707 /* We should skip the extension we've just matched the next time
22708 round. */
22709 opt++;
22710 }
7ed4c4c5 22711
c19d1205
ZW
22712 str = ext;
22713 };
7ed4c4c5 22714
c921be7d 22715 return TRUE;
c19d1205 22716}
7ed4c4c5 22717
c921be7d 22718static bfd_boolean
c19d1205 22719arm_parse_cpu (char * str)
7ed4c4c5 22720{
e74cfd16 22721 const struct arm_cpu_option_table * opt;
c19d1205
ZW
22722 char * ext = strchr (str, '+');
22723 int optlen;
7ed4c4c5 22724
c19d1205
ZW
22725 if (ext != NULL)
22726 optlen = ext - str;
7ed4c4c5 22727 else
c19d1205 22728 optlen = strlen (str);
7ed4c4c5 22729
c19d1205 22730 if (optlen == 0)
7ed4c4c5 22731 {
c19d1205 22732 as_bad (_("missing cpu name `%s'"), str);
c921be7d 22733 return FALSE;
7ed4c4c5
NC
22734 }
22735
c19d1205
ZW
22736 for (opt = arm_cpus; opt->name != NULL; opt++)
22737 if (strncmp (opt->name, str, optlen) == 0)
22738 {
e74cfd16
PB
22739 mcpu_cpu_opt = &opt->value;
22740 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 22741 if (opt->canonical_name)
5f4273c7 22742 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22743 else
22744 {
22745 int i;
c921be7d 22746
ee065d83
PB
22747 for (i = 0; i < optlen; i++)
22748 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22749 selected_cpu_name[i] = 0;
22750 }
7ed4c4c5 22751
c19d1205
ZW
22752 if (ext != NULL)
22753 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 22754
c921be7d 22755 return TRUE;
c19d1205 22756 }
7ed4c4c5 22757
c19d1205 22758 as_bad (_("unknown cpu `%s'"), str);
c921be7d 22759 return FALSE;
7ed4c4c5
NC
22760}
22761
c921be7d 22762static bfd_boolean
c19d1205 22763arm_parse_arch (char * str)
7ed4c4c5 22764{
e74cfd16 22765 const struct arm_arch_option_table *opt;
c19d1205
ZW
22766 char *ext = strchr (str, '+');
22767 int optlen;
7ed4c4c5 22768
c19d1205
ZW
22769 if (ext != NULL)
22770 optlen = ext - str;
7ed4c4c5 22771 else
c19d1205 22772 optlen = strlen (str);
7ed4c4c5 22773
c19d1205 22774 if (optlen == 0)
7ed4c4c5 22775 {
c19d1205 22776 as_bad (_("missing architecture name `%s'"), str);
c921be7d 22777 return FALSE;
7ed4c4c5
NC
22778 }
22779
c19d1205 22780 for (opt = arm_archs; opt->name != NULL; opt++)
69133863 22781 if (strncmp (opt->name, str, optlen) == 0)
c19d1205 22782 {
e74cfd16
PB
22783 march_cpu_opt = &opt->value;
22784 march_fpu_opt = &opt->default_fpu;
5f4273c7 22785 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 22786
c19d1205
ZW
22787 if (ext != NULL)
22788 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 22789
c921be7d 22790 return TRUE;
c19d1205
ZW
22791 }
22792
22793 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 22794 return FALSE;
7ed4c4c5 22795}
eb043451 22796
c921be7d 22797static bfd_boolean
c19d1205
ZW
22798arm_parse_fpu (char * str)
22799{
69133863 22800 const struct arm_option_fpu_value_table * opt;
b99bd4ef 22801
c19d1205
ZW
22802 for (opt = arm_fpus; opt->name != NULL; opt++)
22803 if (streq (opt->name, str))
22804 {
e74cfd16 22805 mfpu_opt = &opt->value;
c921be7d 22806 return TRUE;
c19d1205 22807 }
b99bd4ef 22808
c19d1205 22809 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 22810 return FALSE;
c19d1205
ZW
22811}
22812
c921be7d 22813static bfd_boolean
c19d1205 22814arm_parse_float_abi (char * str)
b99bd4ef 22815{
e74cfd16 22816 const struct arm_option_value_table * opt;
b99bd4ef 22817
c19d1205
ZW
22818 for (opt = arm_float_abis; opt->name != NULL; opt++)
22819 if (streq (opt->name, str))
22820 {
22821 mfloat_abi_opt = opt->value;
c921be7d 22822 return TRUE;
c19d1205 22823 }
cc8a6dd0 22824
c19d1205 22825 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 22826 return FALSE;
c19d1205 22827}
b99bd4ef 22828
c19d1205 22829#ifdef OBJ_ELF
c921be7d 22830static bfd_boolean
c19d1205
ZW
22831arm_parse_eabi (char * str)
22832{
e74cfd16 22833 const struct arm_option_value_table *opt;
cc8a6dd0 22834
c19d1205
ZW
22835 for (opt = arm_eabis; opt->name != NULL; opt++)
22836 if (streq (opt->name, str))
22837 {
22838 meabi_flags = opt->value;
c921be7d 22839 return TRUE;
c19d1205
ZW
22840 }
22841 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 22842 return FALSE;
c19d1205
ZW
22843}
22844#endif
cc8a6dd0 22845
c921be7d 22846static bfd_boolean
e07e6e58
NC
22847arm_parse_it_mode (char * str)
22848{
c921be7d 22849 bfd_boolean ret = TRUE;
e07e6e58
NC
22850
22851 if (streq ("arm", str))
22852 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
22853 else if (streq ("thumb", str))
22854 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
22855 else if (streq ("always", str))
22856 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
22857 else if (streq ("never", str))
22858 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
22859 else
22860 {
22861 as_bad (_("unknown implicit IT mode `%s', should be "\
22862 "arm, thumb, always, or never."), str);
c921be7d 22863 ret = FALSE;
e07e6e58
NC
22864 }
22865
22866 return ret;
22867}
22868
c19d1205
ZW
22869struct arm_long_option_table arm_long_opts[] =
22870{
22871 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
22872 arm_parse_cpu, NULL},
22873 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
22874 arm_parse_arch, NULL},
22875 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
22876 arm_parse_fpu, NULL},
22877 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
22878 arm_parse_float_abi, NULL},
22879#ifdef OBJ_ELF
7fac0536 22880 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
22881 arm_parse_eabi, NULL},
22882#endif
e07e6e58
NC
22883 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
22884 arm_parse_it_mode, NULL},
c19d1205
ZW
22885 {NULL, NULL, 0, NULL}
22886};
cc8a6dd0 22887
c19d1205
ZW
22888int
22889md_parse_option (int c, char * arg)
22890{
22891 struct arm_option_table *opt;
e74cfd16 22892 const struct arm_legacy_option_table *fopt;
c19d1205 22893 struct arm_long_option_table *lopt;
b99bd4ef 22894
c19d1205 22895 switch (c)
b99bd4ef 22896 {
c19d1205
ZW
22897#ifdef OPTION_EB
22898 case OPTION_EB:
22899 target_big_endian = 1;
22900 break;
22901#endif
cc8a6dd0 22902
c19d1205
ZW
22903#ifdef OPTION_EL
22904 case OPTION_EL:
22905 target_big_endian = 0;
22906 break;
22907#endif
b99bd4ef 22908
845b51d6
PB
22909 case OPTION_FIX_V4BX:
22910 fix_v4bx = TRUE;
22911 break;
22912
c19d1205
ZW
22913 case 'a':
22914 /* Listing option. Just ignore these, we don't support additional
22915 ones. */
22916 return 0;
b99bd4ef 22917
c19d1205
ZW
22918 default:
22919 for (opt = arm_opts; opt->option != NULL; opt++)
22920 {
22921 if (c == opt->option[0]
22922 && ((arg == NULL && opt->option[1] == 0)
22923 || streq (arg, opt->option + 1)))
22924 {
c19d1205 22925 /* If the option is deprecated, tell the user. */
278df34e 22926 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
22927 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22928 arg ? arg : "", _(opt->deprecated));
b99bd4ef 22929
c19d1205
ZW
22930 if (opt->var != NULL)
22931 *opt->var = opt->value;
cc8a6dd0 22932
c19d1205
ZW
22933 return 1;
22934 }
22935 }
b99bd4ef 22936
e74cfd16
PB
22937 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
22938 {
22939 if (c == fopt->option[0]
22940 && ((arg == NULL && fopt->option[1] == 0)
22941 || streq (arg, fopt->option + 1)))
22942 {
e74cfd16 22943 /* If the option is deprecated, tell the user. */
278df34e 22944 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
22945 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22946 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
22947
22948 if (fopt->var != NULL)
22949 *fopt->var = &fopt->value;
22950
22951 return 1;
22952 }
22953 }
22954
c19d1205
ZW
22955 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22956 {
22957 /* These options are expected to have an argument. */
22958 if (c == lopt->option[0]
22959 && arg != NULL
22960 && strncmp (arg, lopt->option + 1,
22961 strlen (lopt->option + 1)) == 0)
22962 {
c19d1205 22963 /* If the option is deprecated, tell the user. */
278df34e 22964 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
22965 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
22966 _(lopt->deprecated));
b99bd4ef 22967
c19d1205
ZW
22968 /* Call the sup-option parser. */
22969 return lopt->func (arg + strlen (lopt->option) - 1);
22970 }
22971 }
a737bd4d 22972
c19d1205
ZW
22973 return 0;
22974 }
a394c00f 22975
c19d1205
ZW
22976 return 1;
22977}
a394c00f 22978
c19d1205
ZW
22979void
22980md_show_usage (FILE * fp)
a394c00f 22981{
c19d1205
ZW
22982 struct arm_option_table *opt;
22983 struct arm_long_option_table *lopt;
a394c00f 22984
c19d1205 22985 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 22986
c19d1205
ZW
22987 for (opt = arm_opts; opt->option != NULL; opt++)
22988 if (opt->help != NULL)
22989 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 22990
c19d1205
ZW
22991 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22992 if (lopt->help != NULL)
22993 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 22994
c19d1205
ZW
22995#ifdef OPTION_EB
22996 fprintf (fp, _("\
22997 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
22998#endif
22999
c19d1205
ZW
23000#ifdef OPTION_EL
23001 fprintf (fp, _("\
23002 -EL assemble code for a little-endian cpu\n"));
a737bd4d 23003#endif
845b51d6
PB
23004
23005 fprintf (fp, _("\
23006 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 23007}
ee065d83
PB
23008
23009
23010#ifdef OBJ_ELF
62b3e311
PB
23011typedef struct
23012{
23013 int val;
23014 arm_feature_set flags;
23015} cpu_arch_ver_table;
23016
23017/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
23018 least features first. */
23019static const cpu_arch_ver_table cpu_arch_ver[] =
23020{
23021 {1, ARM_ARCH_V4},
23022 {2, ARM_ARCH_V4T},
23023 {3, ARM_ARCH_V5},
ee3c0378 23024 {3, ARM_ARCH_V5T},
62b3e311
PB
23025 {4, ARM_ARCH_V5TE},
23026 {5, ARM_ARCH_V5TEJ},
23027 {6, ARM_ARCH_V6},
7e806470 23028 {9, ARM_ARCH_V6K},
f4c65163 23029 {7, ARM_ARCH_V6Z},
91e22acd 23030 {11, ARM_ARCH_V6M},
b2a5fbdc 23031 {12, ARM_ARCH_V6SM},
7e806470 23032 {8, ARM_ARCH_V6T2},
62b3e311
PB
23033 {10, ARM_ARCH_V7A},
23034 {10, ARM_ARCH_V7R},
23035 {10, ARM_ARCH_V7M},
23036 {0, ARM_ARCH_NONE}
23037};
23038
ee3c0378
AS
23039/* Set an attribute if it has not already been set by the user. */
23040static void
23041aeabi_set_attribute_int (int tag, int value)
23042{
23043 if (tag < 1
23044 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23045 || !attributes_set_explicitly[tag])
23046 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
23047}
23048
23049static void
23050aeabi_set_attribute_string (int tag, const char *value)
23051{
23052 if (tag < 1
23053 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23054 || !attributes_set_explicitly[tag])
23055 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
23056}
23057
ee065d83
PB
23058/* Set the public EABI object attributes. */
23059static void
23060aeabi_set_public_attributes (void)
23061{
23062 int arch;
e74cfd16 23063 arm_feature_set flags;
62b3e311
PB
23064 arm_feature_set tmp;
23065 const cpu_arch_ver_table *p;
ee065d83
PB
23066
23067 /* Choose the architecture based on the capabilities of the requested cpu
23068 (if any) and/or the instructions actually used. */
e74cfd16
PB
23069 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
23070 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
23071 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
23072 /*Allow the user to override the reported architecture. */
23073 if (object_arch)
23074 {
23075 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
23076 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
23077 }
23078
62b3e311
PB
23079 tmp = flags;
23080 arch = 0;
23081 for (p = cpu_arch_ver; p->val; p++)
23082 {
23083 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
23084 {
23085 arch = p->val;
23086 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
23087 }
23088 }
ee065d83 23089
9e3c6df6
PB
23090 /* The table lookup above finds the last architecture to contribute
23091 a new feature. Unfortunately, Tag13 is a subset of the union of
23092 v6T2 and v7-M, so it is never seen as contributing a new feature.
23093 We can not search for the last entry which is entirely used,
23094 because if no CPU is specified we build up only those flags
23095 actually used. Perhaps we should separate out the specified
23096 and implicit cases. Avoid taking this path for -march=all by
23097 checking for contradictory v7-A / v7-M features. */
23098 if (arch == 10
23099 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
23100 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
23101 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
23102 arch = 13;
23103
ee065d83
PB
23104 /* Tag_CPU_name. */
23105 if (selected_cpu_name[0])
23106 {
91d6fa6a 23107 char *q;
ee065d83 23108
91d6fa6a
NC
23109 q = selected_cpu_name;
23110 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
23111 {
23112 int i;
5f4273c7 23113
91d6fa6a
NC
23114 q += 4;
23115 for (i = 0; q[i]; i++)
23116 q[i] = TOUPPER (q[i]);
ee065d83 23117 }
91d6fa6a 23118 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 23119 }
62f3b8c8 23120
ee065d83 23121 /* Tag_CPU_arch. */
ee3c0378 23122 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 23123
62b3e311
PB
23124 /* Tag_CPU_arch_profile. */
23125 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 23126 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 23127 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 23128 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 23129 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 23130 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
62f3b8c8 23131
ee065d83 23132 /* Tag_ARM_ISA_use. */
ee3c0378
AS
23133 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
23134 || arch == 0)
23135 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 23136
ee065d83 23137 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
23138 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
23139 || arch == 0)
23140 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
23141 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 23142
ee065d83 23143 /* Tag_VFP_arch. */
62f3b8c8
PB
23144 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
23145 aeabi_set_attribute_int (Tag_VFP_arch,
23146 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
23147 ? 5 : 6);
23148 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
ee3c0378 23149 aeabi_set_attribute_int (Tag_VFP_arch, 3);
ada65aa3 23150 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
ee3c0378
AS
23151 aeabi_set_attribute_int (Tag_VFP_arch, 4);
23152 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
23153 aeabi_set_attribute_int (Tag_VFP_arch, 2);
23154 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
23155 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
23156 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 23157
4547cb56
NC
23158 /* Tag_ABI_HardFP_use. */
23159 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
23160 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
23161 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
23162
ee065d83 23163 /* Tag_WMMX_arch. */
ee3c0378
AS
23164 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
23165 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
23166 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
23167 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 23168
ee3c0378 23169 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 23170 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
62f3b8c8
PB
23171 aeabi_set_attribute_int
23172 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
23173 ? 2 : 1));
23174
ee3c0378 23175 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
62f3b8c8 23176 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
ee3c0378 23177 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56
NC
23178
23179 /* Tag_DIV_use. */
23180 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_div))
23181 aeabi_set_attribute_int (Tag_DIV_use, 0);
23182 /* Fill this in when gas supports v7a sdiv/udiv.
23183 else if (... v7a with div extension used ...)
23184 aeabi_set_attribute_int (Tag_DIV_use, 2); */
23185 else
23186 aeabi_set_attribute_int (Tag_DIV_use, 1);
60e5ef9f
MGD
23187
23188 /* Tag_MP_extension_use. */
23189 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
23190 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
23191
23192 /* Tag Virtualization_use. */
23193 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
23194 aeabi_set_attribute_int (Tag_Virtualization_use, 1);
ee065d83
PB
23195}
23196
104d59d1 23197/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
23198void
23199arm_md_end (void)
23200{
ee065d83
PB
23201 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
23202 return;
23203
23204 aeabi_set_public_attributes ();
ee065d83 23205}
8463be01 23206#endif /* OBJ_ELF */
ee065d83
PB
23207
23208
23209/* Parse a .cpu directive. */
23210
23211static void
23212s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
23213{
e74cfd16 23214 const struct arm_cpu_option_table *opt;
ee065d83
PB
23215 char *name;
23216 char saved_char;
23217
23218 name = input_line_pointer;
5f4273c7 23219 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23220 input_line_pointer++;
23221 saved_char = *input_line_pointer;
23222 *input_line_pointer = 0;
23223
23224 /* Skip the first "all" entry. */
23225 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
23226 if (streq (opt->name, name))
23227 {
e74cfd16
PB
23228 mcpu_cpu_opt = &opt->value;
23229 selected_cpu = opt->value;
ee065d83 23230 if (opt->canonical_name)
5f4273c7 23231 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
23232 else
23233 {
23234 int i;
23235 for (i = 0; opt->name[i]; i++)
23236 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23237 selected_cpu_name[i] = 0;
23238 }
e74cfd16 23239 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23240 *input_line_pointer = saved_char;
23241 demand_empty_rest_of_line ();
23242 return;
23243 }
23244 as_bad (_("unknown cpu `%s'"), name);
23245 *input_line_pointer = saved_char;
23246 ignore_rest_of_line ();
23247}
23248
23249
23250/* Parse a .arch directive. */
23251
23252static void
23253s_arm_arch (int ignored ATTRIBUTE_UNUSED)
23254{
e74cfd16 23255 const struct arm_arch_option_table *opt;
ee065d83
PB
23256 char saved_char;
23257 char *name;
23258
23259 name = input_line_pointer;
5f4273c7 23260 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23261 input_line_pointer++;
23262 saved_char = *input_line_pointer;
23263 *input_line_pointer = 0;
23264
23265 /* Skip the first "all" entry. */
23266 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23267 if (streq (opt->name, name))
23268 {
e74cfd16
PB
23269 mcpu_cpu_opt = &opt->value;
23270 selected_cpu = opt->value;
5f4273c7 23271 strcpy (selected_cpu_name, opt->name);
e74cfd16 23272 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23273 *input_line_pointer = saved_char;
23274 demand_empty_rest_of_line ();
23275 return;
23276 }
23277
23278 as_bad (_("unknown architecture `%s'\n"), name);
23279 *input_line_pointer = saved_char;
23280 ignore_rest_of_line ();
23281}
23282
23283
7a1d4c38
PB
23284/* Parse a .object_arch directive. */
23285
23286static void
23287s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
23288{
23289 const struct arm_arch_option_table *opt;
23290 char saved_char;
23291 char *name;
23292
23293 name = input_line_pointer;
5f4273c7 23294 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
23295 input_line_pointer++;
23296 saved_char = *input_line_pointer;
23297 *input_line_pointer = 0;
23298
23299 /* Skip the first "all" entry. */
23300 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23301 if (streq (opt->name, name))
23302 {
23303 object_arch = &opt->value;
23304 *input_line_pointer = saved_char;
23305 demand_empty_rest_of_line ();
23306 return;
23307 }
23308
23309 as_bad (_("unknown architecture `%s'\n"), name);
23310 *input_line_pointer = saved_char;
23311 ignore_rest_of_line ();
23312}
23313
69133863
MGD
23314/* Parse a .arch_extension directive. */
23315
23316static void
23317s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
23318{
23319 const struct arm_option_extension_value_table *opt;
23320 char saved_char;
23321 char *name;
23322 int adding_value = 1;
23323
23324 name = input_line_pointer;
23325 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23326 input_line_pointer++;
23327 saved_char = *input_line_pointer;
23328 *input_line_pointer = 0;
23329
23330 if (strlen (name) >= 2
23331 && strncmp (name, "no", 2) == 0)
23332 {
23333 adding_value = 0;
23334 name += 2;
23335 }
23336
23337 for (opt = arm_extensions; opt->name != NULL; opt++)
23338 if (streq (opt->name, name))
23339 {
23340 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
23341 {
23342 as_bad (_("architectural extension `%s' is not allowed for the "
23343 "current base architecture"), name);
23344 break;
23345 }
23346
23347 if (adding_value)
23348 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
23349 else
23350 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
23351
23352 mcpu_cpu_opt = &selected_cpu;
23353 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23354 *input_line_pointer = saved_char;
23355 demand_empty_rest_of_line ();
23356 return;
23357 }
23358
23359 if (opt->name == NULL)
23360 as_bad (_("unknown architecture `%s'\n"), name);
23361
23362 *input_line_pointer = saved_char;
23363 ignore_rest_of_line ();
23364}
23365
ee065d83
PB
23366/* Parse a .fpu directive. */
23367
23368static void
23369s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
23370{
69133863 23371 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
23372 char saved_char;
23373 char *name;
23374
23375 name = input_line_pointer;
5f4273c7 23376 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23377 input_line_pointer++;
23378 saved_char = *input_line_pointer;
23379 *input_line_pointer = 0;
5f4273c7 23380
ee065d83
PB
23381 for (opt = arm_fpus; opt->name != NULL; opt++)
23382 if (streq (opt->name, name))
23383 {
e74cfd16
PB
23384 mfpu_opt = &opt->value;
23385 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23386 *input_line_pointer = saved_char;
23387 demand_empty_rest_of_line ();
23388 return;
23389 }
23390
23391 as_bad (_("unknown floating point format `%s'\n"), name);
23392 *input_line_pointer = saved_char;
23393 ignore_rest_of_line ();
23394}
ee065d83 23395
794ba86a 23396/* Copy symbol information. */
f31fef98 23397
794ba86a
DJ
23398void
23399arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
23400{
23401 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
23402}
e04befd0 23403
f31fef98 23404#ifdef OBJ_ELF
e04befd0
AS
23405/* Given a symbolic attribute NAME, return the proper integer value.
23406 Returns -1 if the attribute is not known. */
f31fef98 23407
e04befd0
AS
23408int
23409arm_convert_symbolic_attribute (const char *name)
23410{
f31fef98
NC
23411 static const struct
23412 {
23413 const char * name;
23414 const int tag;
23415 }
23416 attribute_table[] =
23417 {
23418 /* When you modify this table you should
23419 also modify the list in doc/c-arm.texi. */
e04befd0 23420#define T(tag) {#tag, tag}
f31fef98
NC
23421 T (Tag_CPU_raw_name),
23422 T (Tag_CPU_name),
23423 T (Tag_CPU_arch),
23424 T (Tag_CPU_arch_profile),
23425 T (Tag_ARM_ISA_use),
23426 T (Tag_THUMB_ISA_use),
75375b3e 23427 T (Tag_FP_arch),
f31fef98
NC
23428 T (Tag_VFP_arch),
23429 T (Tag_WMMX_arch),
23430 T (Tag_Advanced_SIMD_arch),
23431 T (Tag_PCS_config),
23432 T (Tag_ABI_PCS_R9_use),
23433 T (Tag_ABI_PCS_RW_data),
23434 T (Tag_ABI_PCS_RO_data),
23435 T (Tag_ABI_PCS_GOT_use),
23436 T (Tag_ABI_PCS_wchar_t),
23437 T (Tag_ABI_FP_rounding),
23438 T (Tag_ABI_FP_denormal),
23439 T (Tag_ABI_FP_exceptions),
23440 T (Tag_ABI_FP_user_exceptions),
23441 T (Tag_ABI_FP_number_model),
75375b3e 23442 T (Tag_ABI_align_needed),
f31fef98 23443 T (Tag_ABI_align8_needed),
75375b3e 23444 T (Tag_ABI_align_preserved),
f31fef98
NC
23445 T (Tag_ABI_align8_preserved),
23446 T (Tag_ABI_enum_size),
23447 T (Tag_ABI_HardFP_use),
23448 T (Tag_ABI_VFP_args),
23449 T (Tag_ABI_WMMX_args),
23450 T (Tag_ABI_optimization_goals),
23451 T (Tag_ABI_FP_optimization_goals),
23452 T (Tag_compatibility),
23453 T (Tag_CPU_unaligned_access),
75375b3e 23454 T (Tag_FP_HP_extension),
f31fef98
NC
23455 T (Tag_VFP_HP_extension),
23456 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
23457 T (Tag_MPextension_use),
23458 T (Tag_DIV_use),
f31fef98
NC
23459 T (Tag_nodefaults),
23460 T (Tag_also_compatible_with),
23461 T (Tag_conformance),
23462 T (Tag_T2EE_use),
23463 T (Tag_Virtualization_use),
cd21e546 23464 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 23465#undef T
f31fef98 23466 };
e04befd0
AS
23467 unsigned int i;
23468
23469 if (name == NULL)
23470 return -1;
23471
f31fef98 23472 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 23473 if (streq (name, attribute_table[i].name))
e04befd0
AS
23474 return attribute_table[i].tag;
23475
23476 return -1;
23477}
267bf995
RR
23478
23479
23480/* Apply sym value for relocations only in the case that
23481 they are for local symbols and you have the respective
23482 architectural feature for blx and simple switches. */
23483int
23484arm_apply_sym_value (struct fix * fixP)
23485{
23486 if (fixP->fx_addsy
23487 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23488 && !S_IS_EXTERNAL (fixP->fx_addsy))
23489 {
23490 switch (fixP->fx_r_type)
23491 {
23492 case BFD_RELOC_ARM_PCREL_BLX:
23493 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23494 if (ARM_IS_FUNC (fixP->fx_addsy))
23495 return 1;
23496 break;
23497
23498 case BFD_RELOC_ARM_PCREL_CALL:
23499 case BFD_RELOC_THUMB_PCREL_BLX:
23500 if (THUMB_IS_FUNC (fixP->fx_addsy))
23501 return 1;
23502 break;
23503
23504 default:
23505 break;
23506 }
23507
23508 }
23509 return 0;
23510}
f31fef98 23511#endif /* OBJ_ELF */
This page took 2.313259 seconds and 4 git commands to generate.