]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
* m68k-tdep.c (m68k_reg_struct_return_p): Accept complex types.
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
fa94de6b 3 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
b99bd4ef
NC
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
ec2655a6 15 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
b99bd4ef 27
42a68e18 28#include "as.h"
5287ad62 29#include <limits.h>
037e8744 30#include <stdarg.h>
c19d1205 31#define NO_RELOC 0
3882b010 32#include "safe-ctype.h"
b99bd4ef
NC
33#include "subsegs.h"
34#include "obstack.h"
3da1d841 35#include "libiberty.h"
f263249b
RE
36#include "opcode/arm.h"
37
b99bd4ef
NC
38#ifdef OBJ_ELF
39#include "elf/arm.h"
a394c00f 40#include "dw2gencfi.h"
b99bd4ef
NC
41#endif
42
f0927246
NC
43#include "dwarf2dbg.h"
44
7ed4c4c5
NC
45#ifdef OBJ_ELF
46/* Must be at least the size of the largest unwind opcode (currently two). */
47#define ARM_OPCODE_CHUNK_SIZE 8
48
49/* This structure holds the unwinding state. */
50
51static struct
52{
c19d1205
ZW
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
7ed4c4c5 57 /* The segment containing the function. */
c19d1205
ZW
58 segT saved_seg;
59 subsegT saved_subseg;
7ed4c4c5
NC
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
c19d1205
ZW
62 int opcode_count;
63 int opcode_alloc;
7ed4c4c5 64 /* The number of bytes pushed to the stack. */
c19d1205 65 offsetT frame_size;
7ed4c4c5
NC
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
c19d1205 69 offsetT pending_offset;
7ed4c4c5 70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
7ed4c4c5 74 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 75 unsigned fp_used:1;
7ed4c4c5 76 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 77 unsigned sp_restored:1;
7ed4c4c5
NC
78} unwind;
79
8b1ad454
NC
80#endif /* OBJ_ELF */
81
4962c51a
MS
82/* Results from operand parsing worker functions. */
83
84typedef enum
85{
86 PARSE_OPERAND_SUCCESS,
87 PARSE_OPERAND_FAIL,
88 PARSE_OPERAND_FAIL_NO_BACKTRACK
89} parse_operand_result;
90
33a392fb
PB
91enum arm_float_abi
92{
93 ARM_FLOAT_ABI_HARD,
94 ARM_FLOAT_ABI_SOFTFP,
95 ARM_FLOAT_ABI_SOFT
96};
97
c19d1205 98/* Types of processor to assemble for. */
b99bd4ef 99#ifndef CPU_DEFAULT
8a59fff3 100/* The code that was here used to select a default CPU depending on compiler
fa94de6b 101 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
102 changing gas' default behaviour depending upon the build host.
103
104 If you have a target that requires a default CPU option then the you
105 should define CPU_DEFAULT here. */
b99bd4ef
NC
106#endif
107
108#ifndef FPU_DEFAULT
c820d418
MM
109# ifdef TE_LINUX
110# define FPU_DEFAULT FPU_ARCH_FPA
111# elif defined (TE_NetBSD)
112# ifdef OBJ_ELF
113# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
114# else
115 /* Legacy a.out format. */
116# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
117# endif
4e7fd91e
PB
118# elif defined (TE_VXWORKS)
119# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
120# else
121 /* For backwards compatibility, default to FPA. */
122# define FPU_DEFAULT FPU_ARCH_FPA
123# endif
124#endif /* ifndef FPU_DEFAULT */
b99bd4ef 125
c19d1205 126#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 127
e74cfd16
PB
128static arm_feature_set cpu_variant;
129static arm_feature_set arm_arch_used;
130static arm_feature_set thumb_arch_used;
b99bd4ef 131
b99bd4ef 132/* Flags stored in private area of BFD structure. */
c19d1205
ZW
133static int uses_apcs_26 = FALSE;
134static int atpcs = FALSE;
b34976b6
AM
135static int support_interwork = FALSE;
136static int uses_apcs_float = FALSE;
c19d1205 137static int pic_code = FALSE;
845b51d6 138static int fix_v4bx = FALSE;
278df34e
NS
139/* Warn on using deprecated features. */
140static int warn_on_deprecated = TRUE;
141
03b1477f
RE
142
143/* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
e74cfd16
PB
146static const arm_feature_set *legacy_cpu = NULL;
147static const arm_feature_set *legacy_fpu = NULL;
148
149static const arm_feature_set *mcpu_cpu_opt = NULL;
150static const arm_feature_set *mcpu_fpu_opt = NULL;
151static const arm_feature_set *march_cpu_opt = NULL;
152static const arm_feature_set *march_fpu_opt = NULL;
153static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 154static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
155
156/* Constants for known architecture features. */
157static const arm_feature_set fpu_default = FPU_DEFAULT;
158static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
159static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
160static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
161static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
162static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
164static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
165static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
166
167#ifdef CPU_DEFAULT
168static const arm_feature_set cpu_default = CPU_DEFAULT;
169#endif
170
171static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
172static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
173static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
174static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
175static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
176static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
177static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
178static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
179static const arm_feature_set arm_ext_v4t_5 =
180 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
181static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
182static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
183static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
184static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
185static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
186static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
e74cfd16 187static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
b2a5fbdc 188static const arm_feature_set arm_ext_v6m = ARM_FEATURE (ARM_EXT_V6M, 0);
62b3e311 189static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
9e3c6df6 190static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
7e806470
PB
191static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
192static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
193static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
194static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
195static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
196static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
9e3c6df6 197static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
7e806470 198static const arm_feature_set arm_ext_m =
b2a5fbdc 199 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, 0);
60e5ef9f 200static const arm_feature_set arm_ext_mp = ARM_FEATURE (ARM_EXT_MP, 0);
f4c65163 201static const arm_feature_set arm_ext_sec = ARM_FEATURE (ARM_EXT_SEC, 0);
b2a5fbdc 202static const arm_feature_set arm_ext_os = ARM_FEATURE (ARM_EXT_OS, 0);
eea54501 203static const arm_feature_set arm_ext_adiv = ARM_FEATURE (ARM_EXT_ADIV, 0);
90ec0d68 204static const arm_feature_set arm_ext_virt = ARM_FEATURE (ARM_EXT_VIRT, 0);
e74cfd16
PB
205
206static const arm_feature_set arm_arch_any = ARM_ANY;
207static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
208static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
209static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
251665fc 210static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
e74cfd16 211
2d447fca
JM
212static const arm_feature_set arm_cext_iwmmxt2 =
213 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
214static const arm_feature_set arm_cext_iwmmxt =
215 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
216static const arm_feature_set arm_cext_xscale =
217 ARM_FEATURE (0, ARM_CEXT_XSCALE);
218static const arm_feature_set arm_cext_maverick =
219 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
220static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
221static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
222static const arm_feature_set fpu_vfp_ext_v1xd =
223 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
224static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
225static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
62f3b8c8 226static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
5287ad62 227static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
228static const arm_feature_set fpu_vfp_ext_d32 =
229 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
230static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
231static const arm_feature_set fpu_vfp_v3_or_neon_ext =
232 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
62f3b8c8
PB
233static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
234static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
235static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
e74cfd16 236
33a392fb 237static int mfloat_abi_opt = -1;
e74cfd16
PB
238/* Record user cpu selection for object attributes. */
239static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
240/* Must be long enough to hold any of the names in arm_cpus. */
241static char selected_cpu_name[16];
8d67f500
NC
242
243/* Return if no cpu was selected on command-line. */
244static bfd_boolean
245no_cpu_selected (void)
246{
247 return selected_cpu.core == arm_arch_none.core
248 && selected_cpu.coproc == arm_arch_none.coproc;
249}
250
7cc69913 251#ifdef OBJ_ELF
deeaaff8
DJ
252# ifdef EABI_DEFAULT
253static int meabi_flags = EABI_DEFAULT;
254# else
d507cf36 255static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 256# endif
e1da3f5b 257
ee3c0378
AS
258static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
259
e1da3f5b 260bfd_boolean
5f4273c7 261arm_is_eabi (void)
e1da3f5b
PB
262{
263 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
264}
7cc69913 265#endif
b99bd4ef 266
b99bd4ef 267#ifdef OBJ_ELF
c19d1205 268/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
269symbolS * GOT_symbol;
270#endif
271
b99bd4ef
NC
272/* 0: assemble for ARM,
273 1: assemble for Thumb,
274 2: assemble for Thumb even though target CPU does not support thumb
275 instructions. */
276static int thumb_mode = 0;
8dc2430f
NC
277/* A value distinct from the possible values for thumb_mode that we
278 can use to record whether thumb_mode has been copied into the
279 tc_frag_data field of a frag. */
280#define MODE_RECORDED (1 << 4)
b99bd4ef 281
e07e6e58
NC
282/* Specifies the intrinsic IT insn behavior mode. */
283enum implicit_it_mode
284{
285 IMPLICIT_IT_MODE_NEVER = 0x00,
286 IMPLICIT_IT_MODE_ARM = 0x01,
287 IMPLICIT_IT_MODE_THUMB = 0x02,
288 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
289};
290static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
291
c19d1205
ZW
292/* If unified_syntax is true, we are processing the new unified
293 ARM/Thumb syntax. Important differences from the old ARM mode:
294
295 - Immediate operands do not require a # prefix.
296 - Conditional affixes always appear at the end of the
297 instruction. (For backward compatibility, those instructions
298 that formerly had them in the middle, continue to accept them
299 there.)
300 - The IT instruction may appear, and if it does is validated
301 against subsequent conditional affixes. It does not generate
302 machine code.
303
304 Important differences from the old Thumb mode:
305
306 - Immediate operands do not require a # prefix.
307 - Most of the V6T2 instructions are only available in unified mode.
308 - The .N and .W suffixes are recognized and honored (it is an error
309 if they cannot be honored).
310 - All instructions set the flags if and only if they have an 's' affix.
311 - Conditional affixes may be used. They are validated against
312 preceding IT instructions. Unlike ARM mode, you cannot use a
313 conditional affix except in the scope of an IT instruction. */
314
315static bfd_boolean unified_syntax = FALSE;
b99bd4ef 316
5287ad62
JB
317enum neon_el_type
318{
dcbf9037 319 NT_invtype,
5287ad62
JB
320 NT_untyped,
321 NT_integer,
322 NT_float,
323 NT_poly,
324 NT_signed,
dcbf9037 325 NT_unsigned
5287ad62
JB
326};
327
328struct neon_type_el
329{
330 enum neon_el_type type;
331 unsigned size;
332};
333
334#define NEON_MAX_TYPE_ELS 4
335
336struct neon_type
337{
338 struct neon_type_el el[NEON_MAX_TYPE_ELS];
339 unsigned elems;
340};
341
e07e6e58
NC
342enum it_instruction_type
343{
344 OUTSIDE_IT_INSN,
345 INSIDE_IT_INSN,
346 INSIDE_IT_LAST_INSN,
347 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
348 if inside, should be the last one. */
349 NEUTRAL_IT_INSN, /* This could be either inside or outside,
350 i.e. BKPT and NOP. */
351 IT_INSN /* The IT insn has been parsed. */
352};
353
ad6cec43
MGD
354/* The maximum number of operands we need. */
355#define ARM_IT_MAX_OPERANDS 6
356
b99bd4ef
NC
357struct arm_it
358{
c19d1205 359 const char * error;
b99bd4ef 360 unsigned long instruction;
c19d1205
ZW
361 int size;
362 int size_req;
363 int cond;
037e8744
JB
364 /* "uncond_value" is set to the value in place of the conditional field in
365 unconditional versions of the instruction, or -1 if nothing is
366 appropriate. */
367 int uncond_value;
5287ad62 368 struct neon_type vectype;
88714cb8
DG
369 /* This does not indicate an actual NEON instruction, only that
370 the mnemonic accepts neon-style type suffixes. */
371 int is_neon;
0110f2b8
PB
372 /* Set to the opcode if the instruction needs relaxation.
373 Zero if the instruction is not relaxed. */
374 unsigned long relax;
b99bd4ef
NC
375 struct
376 {
377 bfd_reloc_code_real_type type;
c19d1205
ZW
378 expressionS exp;
379 int pc_rel;
b99bd4ef 380 } reloc;
b99bd4ef 381
e07e6e58
NC
382 enum it_instruction_type it_insn_type;
383
c19d1205
ZW
384 struct
385 {
386 unsigned reg;
ca3f61f7 387 signed int imm;
dcbf9037 388 struct neon_type_el vectype;
ca3f61f7
NC
389 unsigned present : 1; /* Operand present. */
390 unsigned isreg : 1; /* Operand was a register. */
391 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
392 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
393 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 394 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
395 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
396 instructions. This allows us to disambiguate ARM <-> vector insns. */
397 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 398 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 399 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 400 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
401 unsigned hasreloc : 1; /* Operand has relocation suffix. */
402 unsigned writeback : 1; /* Operand has trailing ! */
403 unsigned preind : 1; /* Preindexed address. */
404 unsigned postind : 1; /* Postindexed address. */
405 unsigned negative : 1; /* Index register was negated. */
406 unsigned shifted : 1; /* Shift applied to operation. */
407 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 408 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
409};
410
c19d1205 411static struct arm_it inst;
b99bd4ef
NC
412
413#define NUM_FLOAT_VALS 8
414
05d2d07e 415const char * fp_const[] =
b99bd4ef
NC
416{
417 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
418};
419
c19d1205 420/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
421#define MAX_LITTLENUMS 6
422
423LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
424
425#define FAIL (-1)
426#define SUCCESS (0)
427
428#define SUFF_S 1
429#define SUFF_D 2
430#define SUFF_E 3
431#define SUFF_P 4
432
c19d1205
ZW
433#define CP_T_X 0x00008000
434#define CP_T_Y 0x00400000
b99bd4ef 435
c19d1205
ZW
436#define CONDS_BIT 0x00100000
437#define LOAD_BIT 0x00100000
b99bd4ef
NC
438
439#define DOUBLE_LOAD_FLAG 0x00000001
440
441struct asm_cond
442{
d3ce72d0 443 const char * template_name;
c921be7d 444 unsigned long value;
b99bd4ef
NC
445};
446
c19d1205 447#define COND_ALWAYS 0xE
b99bd4ef 448
b99bd4ef
NC
449struct asm_psr
450{
d3ce72d0 451 const char * template_name;
c921be7d 452 unsigned long field;
b99bd4ef
NC
453};
454
62b3e311
PB
455struct asm_barrier_opt
456{
d3ce72d0 457 const char * template_name;
c921be7d 458 unsigned long value;
62b3e311
PB
459};
460
2d2255b5 461/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
462#define SPSR_BIT (1 << 22)
463
c19d1205
ZW
464/* The individual PSR flag bits. */
465#define PSR_c (1 << 16)
466#define PSR_x (1 << 17)
467#define PSR_s (1 << 18)
468#define PSR_f (1 << 19)
b99bd4ef 469
c19d1205 470struct reloc_entry
bfae80f2 471{
c921be7d
NC
472 char * name;
473 bfd_reloc_code_real_type reloc;
bfae80f2
RE
474};
475
5287ad62 476enum vfp_reg_pos
bfae80f2 477{
5287ad62
JB
478 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
479 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
480};
481
482enum vfp_ldstm_type
483{
484 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
485};
486
dcbf9037
JB
487/* Bits for DEFINED field in neon_typed_alias. */
488#define NTA_HASTYPE 1
489#define NTA_HASINDEX 2
490
491struct neon_typed_alias
492{
c921be7d
NC
493 unsigned char defined;
494 unsigned char index;
495 struct neon_type_el eltype;
dcbf9037
JB
496};
497
c19d1205
ZW
498/* ARM register categories. This includes coprocessor numbers and various
499 architecture extensions' registers. */
500enum arm_reg_type
bfae80f2 501{
c19d1205
ZW
502 REG_TYPE_RN,
503 REG_TYPE_CP,
504 REG_TYPE_CN,
505 REG_TYPE_FN,
506 REG_TYPE_VFS,
507 REG_TYPE_VFD,
5287ad62 508 REG_TYPE_NQ,
037e8744 509 REG_TYPE_VFSD,
5287ad62 510 REG_TYPE_NDQ,
037e8744 511 REG_TYPE_NSDQ,
c19d1205
ZW
512 REG_TYPE_VFC,
513 REG_TYPE_MVF,
514 REG_TYPE_MVD,
515 REG_TYPE_MVFX,
516 REG_TYPE_MVDX,
517 REG_TYPE_MVAX,
518 REG_TYPE_DSPSC,
519 REG_TYPE_MMXWR,
520 REG_TYPE_MMXWC,
521 REG_TYPE_MMXWCG,
522 REG_TYPE_XSCALE,
90ec0d68 523 REG_TYPE_RNB
bfae80f2
RE
524};
525
dcbf9037
JB
526/* Structure for a hash table entry for a register.
527 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
528 information which states whether a vector type or index is specified (for a
529 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
530struct reg_entry
531{
c921be7d 532 const char * name;
90ec0d68 533 unsigned int number;
c921be7d
NC
534 unsigned char type;
535 unsigned char builtin;
536 struct neon_typed_alias * neon;
6c43fab6
RE
537};
538
c19d1205 539/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 540const char * const reg_expected_msgs[] =
c19d1205
ZW
541{
542 N_("ARM register expected"),
543 N_("bad or missing co-processor number"),
544 N_("co-processor register expected"),
545 N_("FPA register expected"),
546 N_("VFP single precision register expected"),
5287ad62
JB
547 N_("VFP/Neon double precision register expected"),
548 N_("Neon quad precision register expected"),
037e8744 549 N_("VFP single or double precision register expected"),
5287ad62 550 N_("Neon double or quad precision register expected"),
037e8744 551 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
552 N_("VFP system register expected"),
553 N_("Maverick MVF register expected"),
554 N_("Maverick MVD register expected"),
555 N_("Maverick MVFX register expected"),
556 N_("Maverick MVDX register expected"),
557 N_("Maverick MVAX register expected"),
558 N_("Maverick DSPSC register expected"),
559 N_("iWMMXt data register expected"),
560 N_("iWMMXt control register expected"),
561 N_("iWMMXt scalar register expected"),
562 N_("XScale accumulator register expected"),
6c43fab6
RE
563};
564
c19d1205 565/* Some well known registers that we refer to directly elsewhere. */
bd340a04 566#define REG_R12 12
c19d1205
ZW
567#define REG_SP 13
568#define REG_LR 14
569#define REG_PC 15
404ff6b5 570
b99bd4ef
NC
571/* ARM instructions take 4bytes in the object file, Thumb instructions
572 take 2: */
c19d1205 573#define INSN_SIZE 4
b99bd4ef
NC
574
575struct asm_opcode
576{
577 /* Basic string to match. */
d3ce72d0 578 const char * template_name;
c19d1205
ZW
579
580 /* Parameters to instruction. */
5be8be5d 581 unsigned int operands[8];
c19d1205
ZW
582
583 /* Conditional tag - see opcode_lookup. */
584 unsigned int tag : 4;
b99bd4ef
NC
585
586 /* Basic instruction code. */
c19d1205 587 unsigned int avalue : 28;
b99bd4ef 588
c19d1205
ZW
589 /* Thumb-format instruction code. */
590 unsigned int tvalue;
b99bd4ef 591
90e4755a 592 /* Which architecture variant provides this instruction. */
c921be7d
NC
593 const arm_feature_set * avariant;
594 const arm_feature_set * tvariant;
c19d1205
ZW
595
596 /* Function to call to encode instruction in ARM format. */
597 void (* aencode) (void);
b99bd4ef 598
c19d1205
ZW
599 /* Function to call to encode instruction in Thumb format. */
600 void (* tencode) (void);
b99bd4ef
NC
601};
602
a737bd4d
NC
603/* Defines for various bits that we will want to toggle. */
604#define INST_IMMEDIATE 0x02000000
605#define OFFSET_REG 0x02000000
c19d1205 606#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
607#define SHIFT_BY_REG 0x00000010
608#define PRE_INDEX 0x01000000
609#define INDEX_UP 0x00800000
610#define WRITE_BACK 0x00200000
611#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 612#define CPSI_MMOD 0x00020000
90e4755a 613
a737bd4d
NC
614#define LITERAL_MASK 0xf000f000
615#define OPCODE_MASK 0xfe1fffff
616#define V4_STR_BIT 0x00000020
90e4755a 617
efd81785
PB
618#define T2_SUBS_PC_LR 0xf3de8f00
619
a737bd4d 620#define DATA_OP_SHIFT 21
90e4755a 621
ef8d22e6
PB
622#define T2_OPCODE_MASK 0xfe1fffff
623#define T2_DATA_OP_SHIFT 21
624
6530b175
NC
625#define A_COND_MASK 0xf0000000
626#define A_PUSH_POP_OP_MASK 0x0fff0000
627
628/* Opcodes for pushing/poping registers to/from the stack. */
629#define A1_OPCODE_PUSH 0x092d0000
630#define A2_OPCODE_PUSH 0x052d0004
631#define A2_OPCODE_POP 0x049d0004
632
a737bd4d
NC
633/* Codes to distinguish the arithmetic instructions. */
634#define OPCODE_AND 0
635#define OPCODE_EOR 1
636#define OPCODE_SUB 2
637#define OPCODE_RSB 3
638#define OPCODE_ADD 4
639#define OPCODE_ADC 5
640#define OPCODE_SBC 6
641#define OPCODE_RSC 7
642#define OPCODE_TST 8
643#define OPCODE_TEQ 9
644#define OPCODE_CMP 10
645#define OPCODE_CMN 11
646#define OPCODE_ORR 12
647#define OPCODE_MOV 13
648#define OPCODE_BIC 14
649#define OPCODE_MVN 15
90e4755a 650
ef8d22e6
PB
651#define T2_OPCODE_AND 0
652#define T2_OPCODE_BIC 1
653#define T2_OPCODE_ORR 2
654#define T2_OPCODE_ORN 3
655#define T2_OPCODE_EOR 4
656#define T2_OPCODE_ADD 8
657#define T2_OPCODE_ADC 10
658#define T2_OPCODE_SBC 11
659#define T2_OPCODE_SUB 13
660#define T2_OPCODE_RSB 14
661
a737bd4d
NC
662#define T_OPCODE_MUL 0x4340
663#define T_OPCODE_TST 0x4200
664#define T_OPCODE_CMN 0x42c0
665#define T_OPCODE_NEG 0x4240
666#define T_OPCODE_MVN 0x43c0
90e4755a 667
a737bd4d
NC
668#define T_OPCODE_ADD_R3 0x1800
669#define T_OPCODE_SUB_R3 0x1a00
670#define T_OPCODE_ADD_HI 0x4400
671#define T_OPCODE_ADD_ST 0xb000
672#define T_OPCODE_SUB_ST 0xb080
673#define T_OPCODE_ADD_SP 0xa800
674#define T_OPCODE_ADD_PC 0xa000
675#define T_OPCODE_ADD_I8 0x3000
676#define T_OPCODE_SUB_I8 0x3800
677#define T_OPCODE_ADD_I3 0x1c00
678#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 679
a737bd4d
NC
680#define T_OPCODE_ASR_R 0x4100
681#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
682#define T_OPCODE_LSR_R 0x40c0
683#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
684#define T_OPCODE_ASR_I 0x1000
685#define T_OPCODE_LSL_I 0x0000
686#define T_OPCODE_LSR_I 0x0800
b99bd4ef 687
a737bd4d
NC
688#define T_OPCODE_MOV_I8 0x2000
689#define T_OPCODE_CMP_I8 0x2800
690#define T_OPCODE_CMP_LR 0x4280
691#define T_OPCODE_MOV_HR 0x4600
692#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 693
a737bd4d
NC
694#define T_OPCODE_LDR_PC 0x4800
695#define T_OPCODE_LDR_SP 0x9800
696#define T_OPCODE_STR_SP 0x9000
697#define T_OPCODE_LDR_IW 0x6800
698#define T_OPCODE_STR_IW 0x6000
699#define T_OPCODE_LDR_IH 0x8800
700#define T_OPCODE_STR_IH 0x8000
701#define T_OPCODE_LDR_IB 0x7800
702#define T_OPCODE_STR_IB 0x7000
703#define T_OPCODE_LDR_RW 0x5800
704#define T_OPCODE_STR_RW 0x5000
705#define T_OPCODE_LDR_RH 0x5a00
706#define T_OPCODE_STR_RH 0x5200
707#define T_OPCODE_LDR_RB 0x5c00
708#define T_OPCODE_STR_RB 0x5400
c9b604bd 709
a737bd4d
NC
710#define T_OPCODE_PUSH 0xb400
711#define T_OPCODE_POP 0xbc00
b99bd4ef 712
2fc8bdac 713#define T_OPCODE_BRANCH 0xe000
b99bd4ef 714
a737bd4d 715#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 716#define THUMB_PP_PC_LR 0x0100
c19d1205 717#define THUMB_LOAD_BIT 0x0800
53365c0d 718#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
719
720#define BAD_ARGS _("bad arguments to instruction")
fdfde340 721#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
722#define BAD_PC _("r15 not allowed here")
723#define BAD_COND _("instruction cannot be conditional")
724#define BAD_OVERLAP _("registers may not be the same")
725#define BAD_HIREG _("lo register required")
726#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 727#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
728#define BAD_BRANCH _("branch must be last instruction in IT block")
729#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 730#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
731#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
732#define BAD_IT_COND _("incorrect condition in IT block")
733#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 734#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
735#define BAD_PC_ADDRESSING \
736 _("cannot use register index with PC-relative addressing")
737#define BAD_PC_WRITEBACK \
738 _("cannot use writeback with PC-relative addressing")
08f10d51 739#define BAD_RANGE _("branch out of range")
c19d1205 740
c921be7d
NC
741static struct hash_control * arm_ops_hsh;
742static struct hash_control * arm_cond_hsh;
743static struct hash_control * arm_shift_hsh;
744static struct hash_control * arm_psr_hsh;
745static struct hash_control * arm_v7m_psr_hsh;
746static struct hash_control * arm_reg_hsh;
747static struct hash_control * arm_reloc_hsh;
748static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 749
b99bd4ef
NC
750/* Stuff needed to resolve the label ambiguity
751 As:
752 ...
753 label: <insn>
754 may differ from:
755 ...
756 label:
5f4273c7 757 <insn> */
b99bd4ef
NC
758
759symbolS * last_label_seen;
b34976b6 760static int label_is_thumb_function_name = FALSE;
e07e6e58 761
3d0c9500
NC
762/* Literal pool structure. Held on a per-section
763 and per-sub-section basis. */
a737bd4d 764
c19d1205 765#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 766typedef struct literal_pool
b99bd4ef 767{
c921be7d
NC
768 expressionS literals [MAX_LITERAL_POOL_SIZE];
769 unsigned int next_free_entry;
770 unsigned int id;
771 symbolS * symbol;
772 segT section;
773 subsegT sub_section;
a8040cf2
NC
774#ifdef OBJ_ELF
775 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
776#endif
c921be7d 777 struct literal_pool * next;
3d0c9500 778} literal_pool;
b99bd4ef 779
3d0c9500
NC
780/* Pointer to a linked list of literal pools. */
781literal_pool * list_of_pools = NULL;
e27ec89e 782
e07e6e58
NC
783#ifdef OBJ_ELF
784# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
785#else
786static struct current_it now_it;
787#endif
788
789static inline int
790now_it_compatible (int cond)
791{
792 return (cond & ~1) == (now_it.cc & ~1);
793}
794
795static inline int
796conditional_insn (void)
797{
798 return inst.cond != COND_ALWAYS;
799}
800
801static int in_it_block (void);
802
803static int handle_it_state (void);
804
805static void force_automatic_it_block_close (void);
806
c921be7d
NC
807static void it_fsm_post_encode (void);
808
e07e6e58
NC
809#define set_it_insn_type(type) \
810 do \
811 { \
812 inst.it_insn_type = type; \
813 if (handle_it_state () == FAIL) \
814 return; \
815 } \
816 while (0)
817
c921be7d
NC
818#define set_it_insn_type_nonvoid(type, failret) \
819 do \
820 { \
821 inst.it_insn_type = type; \
822 if (handle_it_state () == FAIL) \
823 return failret; \
824 } \
825 while(0)
826
e07e6e58
NC
827#define set_it_insn_type_last() \
828 do \
829 { \
830 if (inst.cond == COND_ALWAYS) \
831 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
832 else \
833 set_it_insn_type (INSIDE_IT_LAST_INSN); \
834 } \
835 while (0)
836
c19d1205 837/* Pure syntax. */
b99bd4ef 838
c19d1205
ZW
839/* This array holds the chars that always start a comment. If the
840 pre-processor is disabled, these aren't very useful. */
841const char comment_chars[] = "@";
3d0c9500 842
c19d1205
ZW
843/* This array holds the chars that only start a comment at the beginning of
844 a line. If the line seems to have the form '# 123 filename'
845 .line and .file directives will appear in the pre-processed output. */
846/* Note that input_file.c hand checks for '#' at the beginning of the
847 first line of the input file. This is because the compiler outputs
848 #NO_APP at the beginning of its output. */
849/* Also note that comments like this one will always work. */
850const char line_comment_chars[] = "#";
3d0c9500 851
c19d1205 852const char line_separator_chars[] = ";";
b99bd4ef 853
c19d1205
ZW
854/* Chars that can be used to separate mant
855 from exp in floating point numbers. */
856const char EXP_CHARS[] = "eE";
3d0c9500 857
c19d1205
ZW
858/* Chars that mean this number is a floating point constant. */
859/* As in 0f12.456 */
860/* or 0d1.2345e12 */
b99bd4ef 861
c19d1205 862const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 863
c19d1205
ZW
864/* Prefix characters that indicate the start of an immediate
865 value. */
866#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 867
c19d1205
ZW
868/* Separator character handling. */
869
870#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
871
872static inline int
873skip_past_char (char ** str, char c)
874{
875 if (**str == c)
876 {
877 (*str)++;
878 return SUCCESS;
3d0c9500 879 }
c19d1205
ZW
880 else
881 return FAIL;
882}
c921be7d 883
c19d1205 884#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 885
c19d1205
ZW
886/* Arithmetic expressions (possibly involving symbols). */
887
888/* Return TRUE if anything in the expression is a bignum. */
889
890static int
891walk_no_bignums (symbolS * sp)
892{
893 if (symbol_get_value_expression (sp)->X_op == O_big)
894 return 1;
895
896 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 897 {
c19d1205
ZW
898 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
899 || (symbol_get_value_expression (sp)->X_op_symbol
900 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
901 }
902
c19d1205 903 return 0;
3d0c9500
NC
904}
905
c19d1205
ZW
906static int in_my_get_expression = 0;
907
908/* Third argument to my_get_expression. */
909#define GE_NO_PREFIX 0
910#define GE_IMM_PREFIX 1
911#define GE_OPT_PREFIX 2
5287ad62
JB
912/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
913 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
914#define GE_OPT_PREFIX_BIG 3
a737bd4d 915
b99bd4ef 916static int
c19d1205 917my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 918{
c19d1205
ZW
919 char * save_in;
920 segT seg;
b99bd4ef 921
c19d1205
ZW
922 /* In unified syntax, all prefixes are optional. */
923 if (unified_syntax)
5287ad62
JB
924 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
925 : GE_OPT_PREFIX;
b99bd4ef 926
c19d1205 927 switch (prefix_mode)
b99bd4ef 928 {
c19d1205
ZW
929 case GE_NO_PREFIX: break;
930 case GE_IMM_PREFIX:
931 if (!is_immediate_prefix (**str))
932 {
933 inst.error = _("immediate expression requires a # prefix");
934 return FAIL;
935 }
936 (*str)++;
937 break;
938 case GE_OPT_PREFIX:
5287ad62 939 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
940 if (is_immediate_prefix (**str))
941 (*str)++;
942 break;
943 default: abort ();
944 }
b99bd4ef 945
c19d1205 946 memset (ep, 0, sizeof (expressionS));
b99bd4ef 947
c19d1205
ZW
948 save_in = input_line_pointer;
949 input_line_pointer = *str;
950 in_my_get_expression = 1;
951 seg = expression (ep);
952 in_my_get_expression = 0;
953
f86adc07 954 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 955 {
f86adc07 956 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
957 *str = input_line_pointer;
958 input_line_pointer = save_in;
959 if (inst.error == NULL)
f86adc07
NS
960 inst.error = (ep->X_op == O_absent
961 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
962 return 1;
963 }
b99bd4ef 964
c19d1205
ZW
965#ifdef OBJ_AOUT
966 if (seg != absolute_section
967 && seg != text_section
968 && seg != data_section
969 && seg != bss_section
970 && seg != undefined_section)
971 {
972 inst.error = _("bad segment");
973 *str = input_line_pointer;
974 input_line_pointer = save_in;
975 return 1;
b99bd4ef 976 }
87975d2a
AM
977#else
978 (void) seg;
c19d1205 979#endif
b99bd4ef 980
c19d1205
ZW
981 /* Get rid of any bignums now, so that we don't generate an error for which
982 we can't establish a line number later on. Big numbers are never valid
983 in instructions, which is where this routine is always called. */
5287ad62
JB
984 if (prefix_mode != GE_OPT_PREFIX_BIG
985 && (ep->X_op == O_big
986 || (ep->X_add_symbol
987 && (walk_no_bignums (ep->X_add_symbol)
988 || (ep->X_op_symbol
989 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
990 {
991 inst.error = _("invalid constant");
992 *str = input_line_pointer;
993 input_line_pointer = save_in;
994 return 1;
995 }
b99bd4ef 996
c19d1205
ZW
997 *str = input_line_pointer;
998 input_line_pointer = save_in;
999 return 0;
b99bd4ef
NC
1000}
1001
c19d1205
ZW
1002/* Turn a string in input_line_pointer into a floating point constant
1003 of type TYPE, and store the appropriate bytes in *LITP. The number
1004 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1005 returned, or NULL on OK.
b99bd4ef 1006
c19d1205
ZW
1007 Note that fp constants aren't represent in the normal way on the ARM.
1008 In big endian mode, things are as expected. However, in little endian
1009 mode fp constants are big-endian word-wise, and little-endian byte-wise
1010 within the words. For example, (double) 1.1 in big endian mode is
1011 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1012 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1013
c19d1205 1014 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1015
c19d1205
ZW
1016char *
1017md_atof (int type, char * litP, int * sizeP)
1018{
1019 int prec;
1020 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1021 char *t;
1022 int i;
b99bd4ef 1023
c19d1205
ZW
1024 switch (type)
1025 {
1026 case 'f':
1027 case 'F':
1028 case 's':
1029 case 'S':
1030 prec = 2;
1031 break;
b99bd4ef 1032
c19d1205
ZW
1033 case 'd':
1034 case 'D':
1035 case 'r':
1036 case 'R':
1037 prec = 4;
1038 break;
b99bd4ef 1039
c19d1205
ZW
1040 case 'x':
1041 case 'X':
499ac353 1042 prec = 5;
c19d1205 1043 break;
b99bd4ef 1044
c19d1205
ZW
1045 case 'p':
1046 case 'P':
499ac353 1047 prec = 5;
c19d1205 1048 break;
a737bd4d 1049
c19d1205
ZW
1050 default:
1051 *sizeP = 0;
499ac353 1052 return _("Unrecognized or unsupported floating point constant");
c19d1205 1053 }
b99bd4ef 1054
c19d1205
ZW
1055 t = atof_ieee (input_line_pointer, type, words);
1056 if (t)
1057 input_line_pointer = t;
499ac353 1058 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1059
c19d1205
ZW
1060 if (target_big_endian)
1061 {
1062 for (i = 0; i < prec; i++)
1063 {
499ac353
NC
1064 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1065 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1066 }
1067 }
1068 else
1069 {
e74cfd16 1070 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1071 for (i = prec - 1; i >= 0; i--)
1072 {
499ac353
NC
1073 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1074 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1075 }
1076 else
1077 /* For a 4 byte float the order of elements in `words' is 1 0.
1078 For an 8 byte float the order is 1 0 3 2. */
1079 for (i = 0; i < prec; i += 2)
1080 {
499ac353
NC
1081 md_number_to_chars (litP, (valueT) words[i + 1],
1082 sizeof (LITTLENUM_TYPE));
1083 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1084 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1085 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1086 }
1087 }
b99bd4ef 1088
499ac353 1089 return NULL;
c19d1205 1090}
b99bd4ef 1091
c19d1205
ZW
1092/* We handle all bad expressions here, so that we can report the faulty
1093 instruction in the error message. */
1094void
91d6fa6a 1095md_operand (expressionS * exp)
c19d1205
ZW
1096{
1097 if (in_my_get_expression)
91d6fa6a 1098 exp->X_op = O_illegal;
b99bd4ef
NC
1099}
1100
c19d1205 1101/* Immediate values. */
b99bd4ef 1102
c19d1205
ZW
1103/* Generic immediate-value read function for use in directives.
1104 Accepts anything that 'expression' can fold to a constant.
1105 *val receives the number. */
1106#ifdef OBJ_ELF
1107static int
1108immediate_for_directive (int *val)
b99bd4ef 1109{
c19d1205
ZW
1110 expressionS exp;
1111 exp.X_op = O_illegal;
b99bd4ef 1112
c19d1205
ZW
1113 if (is_immediate_prefix (*input_line_pointer))
1114 {
1115 input_line_pointer++;
1116 expression (&exp);
1117 }
b99bd4ef 1118
c19d1205
ZW
1119 if (exp.X_op != O_constant)
1120 {
1121 as_bad (_("expected #constant"));
1122 ignore_rest_of_line ();
1123 return FAIL;
1124 }
1125 *val = exp.X_add_number;
1126 return SUCCESS;
b99bd4ef 1127}
c19d1205 1128#endif
b99bd4ef 1129
c19d1205 1130/* Register parsing. */
b99bd4ef 1131
c19d1205
ZW
1132/* Generic register parser. CCP points to what should be the
1133 beginning of a register name. If it is indeed a valid register
1134 name, advance CCP over it and return the reg_entry structure;
1135 otherwise return NULL. Does not issue diagnostics. */
1136
1137static struct reg_entry *
1138arm_reg_parse_multi (char **ccp)
b99bd4ef 1139{
c19d1205
ZW
1140 char *start = *ccp;
1141 char *p;
1142 struct reg_entry *reg;
b99bd4ef 1143
c19d1205
ZW
1144#ifdef REGISTER_PREFIX
1145 if (*start != REGISTER_PREFIX)
01cfc07f 1146 return NULL;
c19d1205
ZW
1147 start++;
1148#endif
1149#ifdef OPTIONAL_REGISTER_PREFIX
1150 if (*start == OPTIONAL_REGISTER_PREFIX)
1151 start++;
1152#endif
b99bd4ef 1153
c19d1205
ZW
1154 p = start;
1155 if (!ISALPHA (*p) || !is_name_beginner (*p))
1156 return NULL;
b99bd4ef 1157
c19d1205
ZW
1158 do
1159 p++;
1160 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1161
1162 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1163
1164 if (!reg)
1165 return NULL;
1166
1167 *ccp = p;
1168 return reg;
b99bd4ef
NC
1169}
1170
1171static int
dcbf9037
JB
1172arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1173 enum arm_reg_type type)
b99bd4ef 1174{
c19d1205
ZW
1175 /* Alternative syntaxes are accepted for a few register classes. */
1176 switch (type)
1177 {
1178 case REG_TYPE_MVF:
1179 case REG_TYPE_MVD:
1180 case REG_TYPE_MVFX:
1181 case REG_TYPE_MVDX:
1182 /* Generic coprocessor register names are allowed for these. */
79134647 1183 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1184 return reg->number;
1185 break;
69b97547 1186
c19d1205
ZW
1187 case REG_TYPE_CP:
1188 /* For backward compatibility, a bare number is valid here. */
1189 {
1190 unsigned long processor = strtoul (start, ccp, 10);
1191 if (*ccp != start && processor <= 15)
1192 return processor;
1193 }
6057a28f 1194
c19d1205
ZW
1195 case REG_TYPE_MMXWC:
1196 /* WC includes WCG. ??? I'm not sure this is true for all
1197 instructions that take WC registers. */
79134647 1198 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1199 return reg->number;
6057a28f 1200 break;
c19d1205 1201
6057a28f 1202 default:
c19d1205 1203 break;
6057a28f
NC
1204 }
1205
dcbf9037
JB
1206 return FAIL;
1207}
1208
1209/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1210 return value is the register number or FAIL. */
1211
1212static int
1213arm_reg_parse (char **ccp, enum arm_reg_type type)
1214{
1215 char *start = *ccp;
1216 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1217 int ret;
1218
1219 /* Do not allow a scalar (reg+index) to parse as a register. */
1220 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1221 return FAIL;
1222
1223 if (reg && reg->type == type)
1224 return reg->number;
1225
1226 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1227 return ret;
1228
c19d1205
ZW
1229 *ccp = start;
1230 return FAIL;
1231}
69b97547 1232
dcbf9037
JB
1233/* Parse a Neon type specifier. *STR should point at the leading '.'
1234 character. Does no verification at this stage that the type fits the opcode
1235 properly. E.g.,
1236
1237 .i32.i32.s16
1238 .s32.f32
1239 .u16
1240
1241 Can all be legally parsed by this function.
1242
1243 Fills in neon_type struct pointer with parsed information, and updates STR
1244 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1245 type, FAIL if not. */
1246
1247static int
1248parse_neon_type (struct neon_type *type, char **str)
1249{
1250 char *ptr = *str;
1251
1252 if (type)
1253 type->elems = 0;
1254
1255 while (type->elems < NEON_MAX_TYPE_ELS)
1256 {
1257 enum neon_el_type thistype = NT_untyped;
1258 unsigned thissize = -1u;
1259
1260 if (*ptr != '.')
1261 break;
1262
1263 ptr++;
1264
1265 /* Just a size without an explicit type. */
1266 if (ISDIGIT (*ptr))
1267 goto parsesize;
1268
1269 switch (TOLOWER (*ptr))
1270 {
1271 case 'i': thistype = NT_integer; break;
1272 case 'f': thistype = NT_float; break;
1273 case 'p': thistype = NT_poly; break;
1274 case 's': thistype = NT_signed; break;
1275 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1276 case 'd':
1277 thistype = NT_float;
1278 thissize = 64;
1279 ptr++;
1280 goto done;
dcbf9037
JB
1281 default:
1282 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1283 return FAIL;
1284 }
1285
1286 ptr++;
1287
1288 /* .f is an abbreviation for .f32. */
1289 if (thistype == NT_float && !ISDIGIT (*ptr))
1290 thissize = 32;
1291 else
1292 {
1293 parsesize:
1294 thissize = strtoul (ptr, &ptr, 10);
1295
1296 if (thissize != 8 && thissize != 16 && thissize != 32
1297 && thissize != 64)
1298 {
1299 as_bad (_("bad size %d in type specifier"), thissize);
1300 return FAIL;
1301 }
1302 }
1303
037e8744 1304 done:
dcbf9037
JB
1305 if (type)
1306 {
1307 type->el[type->elems].type = thistype;
1308 type->el[type->elems].size = thissize;
1309 type->elems++;
1310 }
1311 }
1312
1313 /* Empty/missing type is not a successful parse. */
1314 if (type->elems == 0)
1315 return FAIL;
1316
1317 *str = ptr;
1318
1319 return SUCCESS;
1320}
1321
1322/* Errors may be set multiple times during parsing or bit encoding
1323 (particularly in the Neon bits), but usually the earliest error which is set
1324 will be the most meaningful. Avoid overwriting it with later (cascading)
1325 errors by calling this function. */
1326
1327static void
1328first_error (const char *err)
1329{
1330 if (!inst.error)
1331 inst.error = err;
1332}
1333
1334/* Parse a single type, e.g. ".s32", leading period included. */
1335static int
1336parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1337{
1338 char *str = *ccp;
1339 struct neon_type optype;
1340
1341 if (*str == '.')
1342 {
1343 if (parse_neon_type (&optype, &str) == SUCCESS)
1344 {
1345 if (optype.elems == 1)
1346 *vectype = optype.el[0];
1347 else
1348 {
1349 first_error (_("only one type should be specified for operand"));
1350 return FAIL;
1351 }
1352 }
1353 else
1354 {
1355 first_error (_("vector type expected"));
1356 return FAIL;
1357 }
1358 }
1359 else
1360 return FAIL;
5f4273c7 1361
dcbf9037 1362 *ccp = str;
5f4273c7 1363
dcbf9037
JB
1364 return SUCCESS;
1365}
1366
1367/* Special meanings for indices (which have a range of 0-7), which will fit into
1368 a 4-bit integer. */
1369
1370#define NEON_ALL_LANES 15
1371#define NEON_INTERLEAVE_LANES 14
1372
1373/* Parse either a register or a scalar, with an optional type. Return the
1374 register number, and optionally fill in the actual type of the register
1375 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1376 type/index information in *TYPEINFO. */
1377
1378static int
1379parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1380 enum arm_reg_type *rtype,
1381 struct neon_typed_alias *typeinfo)
1382{
1383 char *str = *ccp;
1384 struct reg_entry *reg = arm_reg_parse_multi (&str);
1385 struct neon_typed_alias atype;
1386 struct neon_type_el parsetype;
1387
1388 atype.defined = 0;
1389 atype.index = -1;
1390 atype.eltype.type = NT_invtype;
1391 atype.eltype.size = -1;
1392
1393 /* Try alternate syntax for some types of register. Note these are mutually
1394 exclusive with the Neon syntax extensions. */
1395 if (reg == NULL)
1396 {
1397 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1398 if (altreg != FAIL)
1399 *ccp = str;
1400 if (typeinfo)
1401 *typeinfo = atype;
1402 return altreg;
1403 }
1404
037e8744
JB
1405 /* Undo polymorphism when a set of register types may be accepted. */
1406 if ((type == REG_TYPE_NDQ
1407 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1408 || (type == REG_TYPE_VFSD
1409 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1410 || (type == REG_TYPE_NSDQ
1411 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1412 || reg->type == REG_TYPE_NQ))
1413 || (type == REG_TYPE_MMXWC
1414 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1415 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1416
1417 if (type != reg->type)
1418 return FAIL;
1419
1420 if (reg->neon)
1421 atype = *reg->neon;
5f4273c7 1422
dcbf9037
JB
1423 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1424 {
1425 if ((atype.defined & NTA_HASTYPE) != 0)
1426 {
1427 first_error (_("can't redefine type for operand"));
1428 return FAIL;
1429 }
1430 atype.defined |= NTA_HASTYPE;
1431 atype.eltype = parsetype;
1432 }
5f4273c7 1433
dcbf9037
JB
1434 if (skip_past_char (&str, '[') == SUCCESS)
1435 {
1436 if (type != REG_TYPE_VFD)
1437 {
1438 first_error (_("only D registers may be indexed"));
1439 return FAIL;
1440 }
5f4273c7 1441
dcbf9037
JB
1442 if ((atype.defined & NTA_HASINDEX) != 0)
1443 {
1444 first_error (_("can't change index for operand"));
1445 return FAIL;
1446 }
1447
1448 atype.defined |= NTA_HASINDEX;
1449
1450 if (skip_past_char (&str, ']') == SUCCESS)
1451 atype.index = NEON_ALL_LANES;
1452 else
1453 {
1454 expressionS exp;
1455
1456 my_get_expression (&exp, &str, GE_NO_PREFIX);
1457
1458 if (exp.X_op != O_constant)
1459 {
1460 first_error (_("constant expression required"));
1461 return FAIL;
1462 }
1463
1464 if (skip_past_char (&str, ']') == FAIL)
1465 return FAIL;
1466
1467 atype.index = exp.X_add_number;
1468 }
1469 }
5f4273c7 1470
dcbf9037
JB
1471 if (typeinfo)
1472 *typeinfo = atype;
5f4273c7 1473
dcbf9037
JB
1474 if (rtype)
1475 *rtype = type;
5f4273c7 1476
dcbf9037 1477 *ccp = str;
5f4273c7 1478
dcbf9037
JB
1479 return reg->number;
1480}
1481
1482/* Like arm_reg_parse, but allow allow the following extra features:
1483 - If RTYPE is non-zero, return the (possibly restricted) type of the
1484 register (e.g. Neon double or quad reg when either has been requested).
1485 - If this is a Neon vector type with additional type information, fill
1486 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1487 This function will fault on encountering a scalar. */
dcbf9037
JB
1488
1489static int
1490arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1491 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1492{
1493 struct neon_typed_alias atype;
1494 char *str = *ccp;
1495 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1496
1497 if (reg == FAIL)
1498 return FAIL;
1499
0855e32b
NS
1500 /* Do not allow regname(... to parse as a register. */
1501 if (*str == '(')
1502 return FAIL;
1503
dcbf9037
JB
1504 /* Do not allow a scalar (reg+index) to parse as a register. */
1505 if ((atype.defined & NTA_HASINDEX) != 0)
1506 {
1507 first_error (_("register operand expected, but got scalar"));
1508 return FAIL;
1509 }
1510
1511 if (vectype)
1512 *vectype = atype.eltype;
1513
1514 *ccp = str;
1515
1516 return reg;
1517}
1518
1519#define NEON_SCALAR_REG(X) ((X) >> 4)
1520#define NEON_SCALAR_INDEX(X) ((X) & 15)
1521
5287ad62
JB
1522/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1523 have enough information to be able to do a good job bounds-checking. So, we
1524 just do easy checks here, and do further checks later. */
1525
1526static int
dcbf9037 1527parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1528{
dcbf9037 1529 int reg;
5287ad62 1530 char *str = *ccp;
dcbf9037 1531 struct neon_typed_alias atype;
5f4273c7 1532
dcbf9037 1533 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1534
dcbf9037 1535 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1536 return FAIL;
5f4273c7 1537
dcbf9037 1538 if (atype.index == NEON_ALL_LANES)
5287ad62 1539 {
dcbf9037 1540 first_error (_("scalar must have an index"));
5287ad62
JB
1541 return FAIL;
1542 }
dcbf9037 1543 else if (atype.index >= 64 / elsize)
5287ad62 1544 {
dcbf9037 1545 first_error (_("scalar index out of range"));
5287ad62
JB
1546 return FAIL;
1547 }
5f4273c7 1548
dcbf9037
JB
1549 if (type)
1550 *type = atype.eltype;
5f4273c7 1551
5287ad62 1552 *ccp = str;
5f4273c7 1553
dcbf9037 1554 return reg * 16 + atype.index;
5287ad62
JB
1555}
1556
c19d1205 1557/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1558
c19d1205
ZW
1559static long
1560parse_reg_list (char ** strp)
1561{
1562 char * str = * strp;
1563 long range = 0;
1564 int another_range;
a737bd4d 1565
c19d1205
ZW
1566 /* We come back here if we get ranges concatenated by '+' or '|'. */
1567 do
6057a28f 1568 {
c19d1205 1569 another_range = 0;
a737bd4d 1570
c19d1205
ZW
1571 if (*str == '{')
1572 {
1573 int in_range = 0;
1574 int cur_reg = -1;
a737bd4d 1575
c19d1205
ZW
1576 str++;
1577 do
1578 {
1579 int reg;
6057a28f 1580
dcbf9037 1581 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1582 {
dcbf9037 1583 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1584 return FAIL;
1585 }
a737bd4d 1586
c19d1205
ZW
1587 if (in_range)
1588 {
1589 int i;
a737bd4d 1590
c19d1205
ZW
1591 if (reg <= cur_reg)
1592 {
dcbf9037 1593 first_error (_("bad range in register list"));
c19d1205
ZW
1594 return FAIL;
1595 }
40a18ebd 1596
c19d1205
ZW
1597 for (i = cur_reg + 1; i < reg; i++)
1598 {
1599 if (range & (1 << i))
1600 as_tsktsk
1601 (_("Warning: duplicated register (r%d) in register list"),
1602 i);
1603 else
1604 range |= 1 << i;
1605 }
1606 in_range = 0;
1607 }
a737bd4d 1608
c19d1205
ZW
1609 if (range & (1 << reg))
1610 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1611 reg);
1612 else if (reg <= cur_reg)
1613 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1614
c19d1205
ZW
1615 range |= 1 << reg;
1616 cur_reg = reg;
1617 }
1618 while (skip_past_comma (&str) != FAIL
1619 || (in_range = 1, *str++ == '-'));
1620 str--;
a737bd4d 1621
c19d1205
ZW
1622 if (*str++ != '}')
1623 {
dcbf9037 1624 first_error (_("missing `}'"));
c19d1205
ZW
1625 return FAIL;
1626 }
1627 }
1628 else
1629 {
91d6fa6a 1630 expressionS exp;
40a18ebd 1631
91d6fa6a 1632 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1633 return FAIL;
40a18ebd 1634
91d6fa6a 1635 if (exp.X_op == O_constant)
c19d1205 1636 {
91d6fa6a
NC
1637 if (exp.X_add_number
1638 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1639 {
1640 inst.error = _("invalid register mask");
1641 return FAIL;
1642 }
a737bd4d 1643
91d6fa6a 1644 if ((range & exp.X_add_number) != 0)
c19d1205 1645 {
91d6fa6a 1646 int regno = range & exp.X_add_number;
a737bd4d 1647
c19d1205
ZW
1648 regno &= -regno;
1649 regno = (1 << regno) - 1;
1650 as_tsktsk
1651 (_("Warning: duplicated register (r%d) in register list"),
1652 regno);
1653 }
a737bd4d 1654
91d6fa6a 1655 range |= exp.X_add_number;
c19d1205
ZW
1656 }
1657 else
1658 {
1659 if (inst.reloc.type != 0)
1660 {
1661 inst.error = _("expression too complex");
1662 return FAIL;
1663 }
a737bd4d 1664
91d6fa6a 1665 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1666 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1667 inst.reloc.pc_rel = 0;
1668 }
1669 }
a737bd4d 1670
c19d1205
ZW
1671 if (*str == '|' || *str == '+')
1672 {
1673 str++;
1674 another_range = 1;
1675 }
a737bd4d 1676 }
c19d1205 1677 while (another_range);
a737bd4d 1678
c19d1205
ZW
1679 *strp = str;
1680 return range;
a737bd4d
NC
1681}
1682
5287ad62
JB
1683/* Types of registers in a list. */
1684
1685enum reg_list_els
1686{
1687 REGLIST_VFP_S,
1688 REGLIST_VFP_D,
1689 REGLIST_NEON_D
1690};
1691
c19d1205
ZW
1692/* Parse a VFP register list. If the string is invalid return FAIL.
1693 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1694 register. Parses registers of type ETYPE.
1695 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1696 - Q registers can be used to specify pairs of D registers
1697 - { } can be omitted from around a singleton register list
1698 FIXME: This is not implemented, as it would require backtracking in
1699 some cases, e.g.:
1700 vtbl.8 d3,d4,d5
1701 This could be done (the meaning isn't really ambiguous), but doesn't
1702 fit in well with the current parsing framework.
dcbf9037
JB
1703 - 32 D registers may be used (also true for VFPv3).
1704 FIXME: Types are ignored in these register lists, which is probably a
1705 bug. */
6057a28f 1706
c19d1205 1707static int
037e8744 1708parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1709{
037e8744 1710 char *str = *ccp;
c19d1205
ZW
1711 int base_reg;
1712 int new_base;
21d799b5 1713 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1714 int max_regs = 0;
c19d1205
ZW
1715 int count = 0;
1716 int warned = 0;
1717 unsigned long mask = 0;
a737bd4d 1718 int i;
6057a28f 1719
037e8744 1720 if (*str != '{')
5287ad62
JB
1721 {
1722 inst.error = _("expecting {");
1723 return FAIL;
1724 }
6057a28f 1725
037e8744 1726 str++;
6057a28f 1727
5287ad62 1728 switch (etype)
c19d1205 1729 {
5287ad62 1730 case REGLIST_VFP_S:
c19d1205
ZW
1731 regtype = REG_TYPE_VFS;
1732 max_regs = 32;
5287ad62 1733 break;
5f4273c7 1734
5287ad62
JB
1735 case REGLIST_VFP_D:
1736 regtype = REG_TYPE_VFD;
b7fc2769 1737 break;
5f4273c7 1738
b7fc2769
JB
1739 case REGLIST_NEON_D:
1740 regtype = REG_TYPE_NDQ;
1741 break;
1742 }
1743
1744 if (etype != REGLIST_VFP_S)
1745 {
b1cc4aeb
PB
1746 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1747 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1748 {
1749 max_regs = 32;
1750 if (thumb_mode)
1751 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1752 fpu_vfp_ext_d32);
5287ad62
JB
1753 else
1754 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1755 fpu_vfp_ext_d32);
5287ad62
JB
1756 }
1757 else
1758 max_regs = 16;
c19d1205 1759 }
6057a28f 1760
c19d1205 1761 base_reg = max_regs;
a737bd4d 1762
c19d1205
ZW
1763 do
1764 {
5287ad62 1765 int setmask = 1, addregs = 1;
dcbf9037 1766
037e8744 1767 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1768
c19d1205 1769 if (new_base == FAIL)
a737bd4d 1770 {
dcbf9037 1771 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1772 return FAIL;
1773 }
5f4273c7 1774
b7fc2769
JB
1775 if (new_base >= max_regs)
1776 {
1777 first_error (_("register out of range in list"));
1778 return FAIL;
1779 }
5f4273c7 1780
5287ad62
JB
1781 /* Note: a value of 2 * n is returned for the register Q<n>. */
1782 if (regtype == REG_TYPE_NQ)
1783 {
1784 setmask = 3;
1785 addregs = 2;
1786 }
1787
c19d1205
ZW
1788 if (new_base < base_reg)
1789 base_reg = new_base;
a737bd4d 1790
5287ad62 1791 if (mask & (setmask << new_base))
c19d1205 1792 {
dcbf9037 1793 first_error (_("invalid register list"));
c19d1205 1794 return FAIL;
a737bd4d 1795 }
a737bd4d 1796
c19d1205
ZW
1797 if ((mask >> new_base) != 0 && ! warned)
1798 {
1799 as_tsktsk (_("register list not in ascending order"));
1800 warned = 1;
1801 }
0bbf2aa4 1802
5287ad62
JB
1803 mask |= setmask << new_base;
1804 count += addregs;
0bbf2aa4 1805
037e8744 1806 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1807 {
1808 int high_range;
0bbf2aa4 1809
037e8744 1810 str++;
0bbf2aa4 1811
037e8744 1812 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1813 == FAIL)
c19d1205
ZW
1814 {
1815 inst.error = gettext (reg_expected_msgs[regtype]);
1816 return FAIL;
1817 }
0bbf2aa4 1818
b7fc2769
JB
1819 if (high_range >= max_regs)
1820 {
1821 first_error (_("register out of range in list"));
1822 return FAIL;
1823 }
1824
5287ad62
JB
1825 if (regtype == REG_TYPE_NQ)
1826 high_range = high_range + 1;
1827
c19d1205
ZW
1828 if (high_range <= new_base)
1829 {
1830 inst.error = _("register range not in ascending order");
1831 return FAIL;
1832 }
0bbf2aa4 1833
5287ad62 1834 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1835 {
5287ad62 1836 if (mask & (setmask << new_base))
0bbf2aa4 1837 {
c19d1205
ZW
1838 inst.error = _("invalid register list");
1839 return FAIL;
0bbf2aa4 1840 }
c19d1205 1841
5287ad62
JB
1842 mask |= setmask << new_base;
1843 count += addregs;
0bbf2aa4 1844 }
0bbf2aa4 1845 }
0bbf2aa4 1846 }
037e8744 1847 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1848
037e8744 1849 str++;
0bbf2aa4 1850
c19d1205
ZW
1851 /* Sanity check -- should have raised a parse error above. */
1852 if (count == 0 || count > max_regs)
1853 abort ();
1854
1855 *pbase = base_reg;
1856
1857 /* Final test -- the registers must be consecutive. */
1858 mask >>= base_reg;
1859 for (i = 0; i < count; i++)
1860 {
1861 if ((mask & (1u << i)) == 0)
1862 {
1863 inst.error = _("non-contiguous register range");
1864 return FAIL;
1865 }
1866 }
1867
037e8744
JB
1868 *ccp = str;
1869
c19d1205 1870 return count;
b99bd4ef
NC
1871}
1872
dcbf9037
JB
1873/* True if two alias types are the same. */
1874
c921be7d 1875static bfd_boolean
dcbf9037
JB
1876neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1877{
1878 if (!a && !b)
c921be7d 1879 return TRUE;
5f4273c7 1880
dcbf9037 1881 if (!a || !b)
c921be7d 1882 return FALSE;
dcbf9037
JB
1883
1884 if (a->defined != b->defined)
c921be7d 1885 return FALSE;
5f4273c7 1886
dcbf9037
JB
1887 if ((a->defined & NTA_HASTYPE) != 0
1888 && (a->eltype.type != b->eltype.type
1889 || a->eltype.size != b->eltype.size))
c921be7d 1890 return FALSE;
dcbf9037
JB
1891
1892 if ((a->defined & NTA_HASINDEX) != 0
1893 && (a->index != b->index))
c921be7d 1894 return FALSE;
5f4273c7 1895
c921be7d 1896 return TRUE;
dcbf9037
JB
1897}
1898
5287ad62
JB
1899/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1900 The base register is put in *PBASE.
dcbf9037 1901 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1902 the return value.
1903 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1904 Bits [6:5] encode the list length (minus one).
1905 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1906
5287ad62 1907#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1908#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1909#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1910
1911static int
dcbf9037
JB
1912parse_neon_el_struct_list (char **str, unsigned *pbase,
1913 struct neon_type_el *eltype)
5287ad62
JB
1914{
1915 char *ptr = *str;
1916 int base_reg = -1;
1917 int reg_incr = -1;
1918 int count = 0;
1919 int lane = -1;
1920 int leading_brace = 0;
1921 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1922 const char *const incr_error = _("register stride must be 1 or 2");
1923 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1924 struct neon_typed_alias firsttype;
5f4273c7 1925
5287ad62
JB
1926 if (skip_past_char (&ptr, '{') == SUCCESS)
1927 leading_brace = 1;
5f4273c7 1928
5287ad62
JB
1929 do
1930 {
dcbf9037
JB
1931 struct neon_typed_alias atype;
1932 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1933
5287ad62
JB
1934 if (getreg == FAIL)
1935 {
dcbf9037 1936 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1937 return FAIL;
1938 }
5f4273c7 1939
5287ad62
JB
1940 if (base_reg == -1)
1941 {
1942 base_reg = getreg;
1943 if (rtype == REG_TYPE_NQ)
1944 {
1945 reg_incr = 1;
5287ad62 1946 }
dcbf9037 1947 firsttype = atype;
5287ad62
JB
1948 }
1949 else if (reg_incr == -1)
1950 {
1951 reg_incr = getreg - base_reg;
1952 if (reg_incr < 1 || reg_incr > 2)
1953 {
dcbf9037 1954 first_error (_(incr_error));
5287ad62
JB
1955 return FAIL;
1956 }
1957 }
1958 else if (getreg != base_reg + reg_incr * count)
1959 {
dcbf9037
JB
1960 first_error (_(incr_error));
1961 return FAIL;
1962 }
1963
c921be7d 1964 if (! neon_alias_types_same (&atype, &firsttype))
dcbf9037
JB
1965 {
1966 first_error (_(type_error));
5287ad62
JB
1967 return FAIL;
1968 }
5f4273c7 1969
5287ad62
JB
1970 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1971 modes. */
1972 if (ptr[0] == '-')
1973 {
dcbf9037 1974 struct neon_typed_alias htype;
5287ad62
JB
1975 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1976 if (lane == -1)
1977 lane = NEON_INTERLEAVE_LANES;
1978 else if (lane != NEON_INTERLEAVE_LANES)
1979 {
dcbf9037 1980 first_error (_(type_error));
5287ad62
JB
1981 return FAIL;
1982 }
1983 if (reg_incr == -1)
1984 reg_incr = 1;
1985 else if (reg_incr != 1)
1986 {
dcbf9037 1987 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1988 return FAIL;
1989 }
1990 ptr++;
dcbf9037 1991 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1992 if (hireg == FAIL)
1993 {
dcbf9037
JB
1994 first_error (_(reg_expected_msgs[rtype]));
1995 return FAIL;
1996 }
c921be7d 1997 if (! neon_alias_types_same (&htype, &firsttype))
dcbf9037
JB
1998 {
1999 first_error (_(type_error));
5287ad62
JB
2000 return FAIL;
2001 }
2002 count += hireg + dregs - getreg;
2003 continue;
2004 }
5f4273c7 2005
5287ad62
JB
2006 /* If we're using Q registers, we can't use [] or [n] syntax. */
2007 if (rtype == REG_TYPE_NQ)
2008 {
2009 count += 2;
2010 continue;
2011 }
5f4273c7 2012
dcbf9037 2013 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 2014 {
dcbf9037
JB
2015 if (lane == -1)
2016 lane = atype.index;
2017 else if (lane != atype.index)
5287ad62 2018 {
dcbf9037
JB
2019 first_error (_(type_error));
2020 return FAIL;
5287ad62
JB
2021 }
2022 }
2023 else if (lane == -1)
2024 lane = NEON_INTERLEAVE_LANES;
2025 else if (lane != NEON_INTERLEAVE_LANES)
2026 {
dcbf9037 2027 first_error (_(type_error));
5287ad62
JB
2028 return FAIL;
2029 }
2030 count++;
2031 }
2032 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2033
5287ad62
JB
2034 /* No lane set by [x]. We must be interleaving structures. */
2035 if (lane == -1)
2036 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2037
5287ad62
JB
2038 /* Sanity check. */
2039 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2040 || (count > 1 && reg_incr == -1))
2041 {
dcbf9037 2042 first_error (_("error parsing element/structure list"));
5287ad62
JB
2043 return FAIL;
2044 }
2045
2046 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2047 {
dcbf9037 2048 first_error (_("expected }"));
5287ad62
JB
2049 return FAIL;
2050 }
5f4273c7 2051
5287ad62
JB
2052 if (reg_incr == -1)
2053 reg_incr = 1;
2054
dcbf9037
JB
2055 if (eltype)
2056 *eltype = firsttype.eltype;
2057
5287ad62
JB
2058 *pbase = base_reg;
2059 *str = ptr;
5f4273c7 2060
5287ad62
JB
2061 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2062}
2063
c19d1205
ZW
2064/* Parse an explicit relocation suffix on an expression. This is
2065 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2066 arm_reloc_hsh contains no entries, so this function can only
2067 succeed if there is no () after the word. Returns -1 on error,
2068 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2069
c19d1205
ZW
2070static int
2071parse_reloc (char **str)
b99bd4ef 2072{
c19d1205
ZW
2073 struct reloc_entry *r;
2074 char *p, *q;
b99bd4ef 2075
c19d1205
ZW
2076 if (**str != '(')
2077 return BFD_RELOC_UNUSED;
b99bd4ef 2078
c19d1205
ZW
2079 p = *str + 1;
2080 q = p;
2081
2082 while (*q && *q != ')' && *q != ',')
2083 q++;
2084 if (*q != ')')
2085 return -1;
2086
21d799b5
NC
2087 if ((r = (struct reloc_entry *)
2088 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2089 return -1;
2090
2091 *str = q + 1;
2092 return r->reloc;
b99bd4ef
NC
2093}
2094
c19d1205
ZW
2095/* Directives: register aliases. */
2096
dcbf9037 2097static struct reg_entry *
90ec0d68 2098insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2099{
d3ce72d0 2100 struct reg_entry *new_reg;
c19d1205 2101 const char *name;
b99bd4ef 2102
d3ce72d0 2103 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2104 {
d3ce72d0 2105 if (new_reg->builtin)
c19d1205 2106 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2107
c19d1205
ZW
2108 /* Only warn about a redefinition if it's not defined as the
2109 same register. */
d3ce72d0 2110 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2111 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2112
d929913e 2113 return NULL;
c19d1205 2114 }
b99bd4ef 2115
c19d1205 2116 name = xstrdup (str);
d3ce72d0 2117 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2118
d3ce72d0
NC
2119 new_reg->name = name;
2120 new_reg->number = number;
2121 new_reg->type = type;
2122 new_reg->builtin = FALSE;
2123 new_reg->neon = NULL;
b99bd4ef 2124
d3ce72d0 2125 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2126 abort ();
5f4273c7 2127
d3ce72d0 2128 return new_reg;
dcbf9037
JB
2129}
2130
2131static void
2132insert_neon_reg_alias (char *str, int number, int type,
2133 struct neon_typed_alias *atype)
2134{
2135 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2136
dcbf9037
JB
2137 if (!reg)
2138 {
2139 first_error (_("attempt to redefine typed alias"));
2140 return;
2141 }
5f4273c7 2142
dcbf9037
JB
2143 if (atype)
2144 {
21d799b5
NC
2145 reg->neon = (struct neon_typed_alias *)
2146 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2147 *reg->neon = *atype;
2148 }
c19d1205 2149}
b99bd4ef 2150
c19d1205 2151/* Look for the .req directive. This is of the form:
b99bd4ef 2152
c19d1205 2153 new_register_name .req existing_register_name
b99bd4ef 2154
c19d1205 2155 If we find one, or if it looks sufficiently like one that we want to
d929913e 2156 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2157
d929913e 2158static bfd_boolean
c19d1205
ZW
2159create_register_alias (char * newname, char *p)
2160{
2161 struct reg_entry *old;
2162 char *oldname, *nbuf;
2163 size_t nlen;
b99bd4ef 2164
c19d1205
ZW
2165 /* The input scrubber ensures that whitespace after the mnemonic is
2166 collapsed to single spaces. */
2167 oldname = p;
2168 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2169 return FALSE;
b99bd4ef 2170
c19d1205
ZW
2171 oldname += 6;
2172 if (*oldname == '\0')
d929913e 2173 return FALSE;
b99bd4ef 2174
21d799b5 2175 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2176 if (!old)
b99bd4ef 2177 {
c19d1205 2178 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2179 return TRUE;
b99bd4ef
NC
2180 }
2181
c19d1205
ZW
2182 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2183 the desired alias name, and p points to its end. If not, then
2184 the desired alias name is in the global original_case_string. */
2185#ifdef TC_CASE_SENSITIVE
2186 nlen = p - newname;
2187#else
2188 newname = original_case_string;
2189 nlen = strlen (newname);
2190#endif
b99bd4ef 2191
21d799b5 2192 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2193 memcpy (nbuf, newname, nlen);
2194 nbuf[nlen] = '\0';
b99bd4ef 2195
c19d1205
ZW
2196 /* Create aliases under the new name as stated; an all-lowercase
2197 version of the new name; and an all-uppercase version of the new
2198 name. */
d929913e
NC
2199 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2200 {
2201 for (p = nbuf; *p; p++)
2202 *p = TOUPPER (*p);
c19d1205 2203
d929913e
NC
2204 if (strncmp (nbuf, newname, nlen))
2205 {
2206 /* If this attempt to create an additional alias fails, do not bother
2207 trying to create the all-lower case alias. We will fail and issue
2208 a second, duplicate error message. This situation arises when the
2209 programmer does something like:
2210 foo .req r0
2211 Foo .req r1
2212 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2213 the artificial FOO alias because it has already been created by the
d929913e
NC
2214 first .req. */
2215 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2216 return TRUE;
2217 }
c19d1205 2218
d929913e
NC
2219 for (p = nbuf; *p; p++)
2220 *p = TOLOWER (*p);
c19d1205 2221
d929913e
NC
2222 if (strncmp (nbuf, newname, nlen))
2223 insert_reg_alias (nbuf, old->number, old->type);
2224 }
c19d1205 2225
d929913e 2226 return TRUE;
b99bd4ef
NC
2227}
2228
dcbf9037
JB
2229/* Create a Neon typed/indexed register alias using directives, e.g.:
2230 X .dn d5.s32[1]
2231 Y .qn 6.s16
2232 Z .dn d7
2233 T .dn Z[0]
2234 These typed registers can be used instead of the types specified after the
2235 Neon mnemonic, so long as all operands given have types. Types can also be
2236 specified directly, e.g.:
5f4273c7 2237 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2238
c921be7d 2239static bfd_boolean
dcbf9037
JB
2240create_neon_reg_alias (char *newname, char *p)
2241{
2242 enum arm_reg_type basetype;
2243 struct reg_entry *basereg;
2244 struct reg_entry mybasereg;
2245 struct neon_type ntype;
2246 struct neon_typed_alias typeinfo;
12d6b0b7 2247 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2248 int namelen;
5f4273c7 2249
dcbf9037
JB
2250 typeinfo.defined = 0;
2251 typeinfo.eltype.type = NT_invtype;
2252 typeinfo.eltype.size = -1;
2253 typeinfo.index = -1;
5f4273c7 2254
dcbf9037 2255 nameend = p;
5f4273c7 2256
dcbf9037
JB
2257 if (strncmp (p, " .dn ", 5) == 0)
2258 basetype = REG_TYPE_VFD;
2259 else if (strncmp (p, " .qn ", 5) == 0)
2260 basetype = REG_TYPE_NQ;
2261 else
c921be7d 2262 return FALSE;
5f4273c7 2263
dcbf9037 2264 p += 5;
5f4273c7 2265
dcbf9037 2266 if (*p == '\0')
c921be7d 2267 return FALSE;
5f4273c7 2268
dcbf9037
JB
2269 basereg = arm_reg_parse_multi (&p);
2270
2271 if (basereg && basereg->type != basetype)
2272 {
2273 as_bad (_("bad type for register"));
c921be7d 2274 return FALSE;
dcbf9037
JB
2275 }
2276
2277 if (basereg == NULL)
2278 {
2279 expressionS exp;
2280 /* Try parsing as an integer. */
2281 my_get_expression (&exp, &p, GE_NO_PREFIX);
2282 if (exp.X_op != O_constant)
2283 {
2284 as_bad (_("expression must be constant"));
c921be7d 2285 return FALSE;
dcbf9037
JB
2286 }
2287 basereg = &mybasereg;
2288 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2289 : exp.X_add_number;
2290 basereg->neon = 0;
2291 }
2292
2293 if (basereg->neon)
2294 typeinfo = *basereg->neon;
2295
2296 if (parse_neon_type (&ntype, &p) == SUCCESS)
2297 {
2298 /* We got a type. */
2299 if (typeinfo.defined & NTA_HASTYPE)
2300 {
2301 as_bad (_("can't redefine the type of a register alias"));
c921be7d 2302 return FALSE;
dcbf9037 2303 }
5f4273c7 2304
dcbf9037
JB
2305 typeinfo.defined |= NTA_HASTYPE;
2306 if (ntype.elems != 1)
2307 {
2308 as_bad (_("you must specify a single type only"));
c921be7d 2309 return FALSE;
dcbf9037
JB
2310 }
2311 typeinfo.eltype = ntype.el[0];
2312 }
5f4273c7 2313
dcbf9037
JB
2314 if (skip_past_char (&p, '[') == SUCCESS)
2315 {
2316 expressionS exp;
2317 /* We got a scalar index. */
5f4273c7 2318
dcbf9037
JB
2319 if (typeinfo.defined & NTA_HASINDEX)
2320 {
2321 as_bad (_("can't redefine the index of a scalar alias"));
c921be7d 2322 return FALSE;
dcbf9037 2323 }
5f4273c7 2324
dcbf9037 2325 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2326
dcbf9037
JB
2327 if (exp.X_op != O_constant)
2328 {
2329 as_bad (_("scalar index must be constant"));
c921be7d 2330 return FALSE;
dcbf9037 2331 }
5f4273c7 2332
dcbf9037
JB
2333 typeinfo.defined |= NTA_HASINDEX;
2334 typeinfo.index = exp.X_add_number;
5f4273c7 2335
dcbf9037
JB
2336 if (skip_past_char (&p, ']') == FAIL)
2337 {
2338 as_bad (_("expecting ]"));
c921be7d 2339 return FALSE;
dcbf9037
JB
2340 }
2341 }
2342
15735687
NS
2343 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2344 the desired alias name, and p points to its end. If not, then
2345 the desired alias name is in the global original_case_string. */
2346#ifdef TC_CASE_SENSITIVE
dcbf9037 2347 namelen = nameend - newname;
15735687
NS
2348#else
2349 newname = original_case_string;
2350 namelen = strlen (newname);
2351#endif
2352
21d799b5 2353 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2354 strncpy (namebuf, newname, namelen);
2355 namebuf[namelen] = '\0';
5f4273c7 2356
dcbf9037
JB
2357 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2358 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2359
dcbf9037
JB
2360 /* Insert name in all uppercase. */
2361 for (p = namebuf; *p; p++)
2362 *p = TOUPPER (*p);
5f4273c7 2363
dcbf9037
JB
2364 if (strncmp (namebuf, newname, namelen))
2365 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2366 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2367
dcbf9037
JB
2368 /* Insert name in all lowercase. */
2369 for (p = namebuf; *p; p++)
2370 *p = TOLOWER (*p);
5f4273c7 2371
dcbf9037
JB
2372 if (strncmp (namebuf, newname, namelen))
2373 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2374 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2375
c921be7d 2376 return TRUE;
dcbf9037
JB
2377}
2378
c19d1205
ZW
2379/* Should never be called, as .req goes between the alias and the
2380 register name, not at the beginning of the line. */
c921be7d 2381
b99bd4ef 2382static void
c19d1205 2383s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2384{
c19d1205
ZW
2385 as_bad (_("invalid syntax for .req directive"));
2386}
b99bd4ef 2387
dcbf9037
JB
2388static void
2389s_dn (int a ATTRIBUTE_UNUSED)
2390{
2391 as_bad (_("invalid syntax for .dn directive"));
2392}
2393
2394static void
2395s_qn (int a ATTRIBUTE_UNUSED)
2396{
2397 as_bad (_("invalid syntax for .qn directive"));
2398}
2399
c19d1205
ZW
2400/* The .unreq directive deletes an alias which was previously defined
2401 by .req. For example:
b99bd4ef 2402
c19d1205
ZW
2403 my_alias .req r11
2404 .unreq my_alias */
b99bd4ef
NC
2405
2406static void
c19d1205 2407s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2408{
c19d1205
ZW
2409 char * name;
2410 char saved_char;
b99bd4ef 2411
c19d1205
ZW
2412 name = input_line_pointer;
2413
2414 while (*input_line_pointer != 0
2415 && *input_line_pointer != ' '
2416 && *input_line_pointer != '\n')
2417 ++input_line_pointer;
2418
2419 saved_char = *input_line_pointer;
2420 *input_line_pointer = 0;
2421
2422 if (!*name)
2423 as_bad (_("invalid syntax for .unreq directive"));
2424 else
2425 {
21d799b5
NC
2426 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2427 name);
c19d1205
ZW
2428
2429 if (!reg)
2430 as_bad (_("unknown register alias '%s'"), name);
2431 else if (reg->builtin)
a1727c1a 2432 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2433 name);
2434 else
2435 {
d929913e
NC
2436 char * p;
2437 char * nbuf;
2438
db0bc284 2439 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2440 free ((char *) reg->name);
dcbf9037
JB
2441 if (reg->neon)
2442 free (reg->neon);
c19d1205 2443 free (reg);
d929913e
NC
2444
2445 /* Also locate the all upper case and all lower case versions.
2446 Do not complain if we cannot find one or the other as it
2447 was probably deleted above. */
5f4273c7 2448
d929913e
NC
2449 nbuf = strdup (name);
2450 for (p = nbuf; *p; p++)
2451 *p = TOUPPER (*p);
21d799b5 2452 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2453 if (reg)
2454 {
db0bc284 2455 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2456 free ((char *) reg->name);
2457 if (reg->neon)
2458 free (reg->neon);
2459 free (reg);
2460 }
2461
2462 for (p = nbuf; *p; p++)
2463 *p = TOLOWER (*p);
21d799b5 2464 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2465 if (reg)
2466 {
db0bc284 2467 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2468 free ((char *) reg->name);
2469 if (reg->neon)
2470 free (reg->neon);
2471 free (reg);
2472 }
2473
2474 free (nbuf);
c19d1205
ZW
2475 }
2476 }
b99bd4ef 2477
c19d1205 2478 *input_line_pointer = saved_char;
b99bd4ef
NC
2479 demand_empty_rest_of_line ();
2480}
2481
c19d1205
ZW
2482/* Directives: Instruction set selection. */
2483
2484#ifdef OBJ_ELF
2485/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2486 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2487 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2488 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2489
cd000bff
DJ
2490/* Create a new mapping symbol for the transition to STATE. */
2491
2492static void
2493make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2494{
a737bd4d 2495 symbolS * symbolP;
c19d1205
ZW
2496 const char * symname;
2497 int type;
b99bd4ef 2498
c19d1205 2499 switch (state)
b99bd4ef 2500 {
c19d1205
ZW
2501 case MAP_DATA:
2502 symname = "$d";
2503 type = BSF_NO_FLAGS;
2504 break;
2505 case MAP_ARM:
2506 symname = "$a";
2507 type = BSF_NO_FLAGS;
2508 break;
2509 case MAP_THUMB:
2510 symname = "$t";
2511 type = BSF_NO_FLAGS;
2512 break;
c19d1205
ZW
2513 default:
2514 abort ();
2515 }
2516
cd000bff 2517 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2518 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2519
2520 switch (state)
2521 {
2522 case MAP_ARM:
2523 THUMB_SET_FUNC (symbolP, 0);
2524 ARM_SET_THUMB (symbolP, 0);
2525 ARM_SET_INTERWORK (symbolP, support_interwork);
2526 break;
2527
2528 case MAP_THUMB:
2529 THUMB_SET_FUNC (symbolP, 1);
2530 ARM_SET_THUMB (symbolP, 1);
2531 ARM_SET_INTERWORK (symbolP, support_interwork);
2532 break;
2533
2534 case MAP_DATA:
2535 default:
cd000bff
DJ
2536 break;
2537 }
2538
2539 /* Save the mapping symbols for future reference. Also check that
2540 we do not place two mapping symbols at the same offset within a
2541 frag. We'll handle overlap between frags in
2de7820f
JZ
2542 check_mapping_symbols.
2543
2544 If .fill or other data filling directive generates zero sized data,
2545 the mapping symbol for the following code will have the same value
2546 as the one generated for the data filling directive. In this case,
2547 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2548 if (value == 0)
2549 {
2de7820f
JZ
2550 if (frag->tc_frag_data.first_map != NULL)
2551 {
2552 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2553 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2554 }
cd000bff
DJ
2555 frag->tc_frag_data.first_map = symbolP;
2556 }
2557 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2558 {
2559 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2560 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2561 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2562 }
cd000bff
DJ
2563 frag->tc_frag_data.last_map = symbolP;
2564}
2565
2566/* We must sometimes convert a region marked as code to data during
2567 code alignment, if an odd number of bytes have to be padded. The
2568 code mapping symbol is pushed to an aligned address. */
2569
2570static void
2571insert_data_mapping_symbol (enum mstate state,
2572 valueT value, fragS *frag, offsetT bytes)
2573{
2574 /* If there was already a mapping symbol, remove it. */
2575 if (frag->tc_frag_data.last_map != NULL
2576 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2577 {
2578 symbolS *symp = frag->tc_frag_data.last_map;
2579
2580 if (value == 0)
2581 {
2582 know (frag->tc_frag_data.first_map == symp);
2583 frag->tc_frag_data.first_map = NULL;
2584 }
2585 frag->tc_frag_data.last_map = NULL;
2586 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2587 }
cd000bff
DJ
2588
2589 make_mapping_symbol (MAP_DATA, value, frag);
2590 make_mapping_symbol (state, value + bytes, frag);
2591}
2592
2593static void mapping_state_2 (enum mstate state, int max_chars);
2594
2595/* Set the mapping state to STATE. Only call this when about to
2596 emit some STATE bytes to the file. */
2597
2598void
2599mapping_state (enum mstate state)
2600{
940b5ce0
DJ
2601 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2602
cd000bff
DJ
2603#define TRANSITION(from, to) (mapstate == (from) && state == (to))
2604
2605 if (mapstate == state)
2606 /* The mapping symbol has already been emitted.
2607 There is nothing else to do. */
2608 return;
49c62a33
NC
2609
2610 if (state == MAP_ARM || state == MAP_THUMB)
2611 /* PR gas/12931
2612 All ARM instructions require 4-byte alignment.
2613 (Almost) all Thumb instructions require 2-byte alignment.
2614
2615 When emitting instructions into any section, mark the section
2616 appropriately.
2617
2618 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2619 but themselves require 2-byte alignment; this applies to some
2620 PC- relative forms. However, these cases will invovle implicit
2621 literal pool generation or an explicit .align >=2, both of
2622 which will cause the section to me marked with sufficient
2623 alignment. Thus, we don't handle those cases here. */
2624 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2625
2626 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
cd000bff
DJ
2627 /* This case will be evaluated later in the next else. */
2628 return;
2629 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2630 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2631 {
2632 /* Only add the symbol if the offset is > 0:
2633 if we're at the first frag, check it's size > 0;
2634 if we're not at the first frag, then for sure
2635 the offset is > 0. */
2636 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2637 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2638
2639 if (add_symbol)
2640 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2641 }
2642
2643 mapping_state_2 (state, 0);
2644#undef TRANSITION
2645}
2646
2647/* Same as mapping_state, but MAX_CHARS bytes have already been
2648 allocated. Put the mapping symbol that far back. */
2649
2650static void
2651mapping_state_2 (enum mstate state, int max_chars)
2652{
940b5ce0
DJ
2653 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2654
2655 if (!SEG_NORMAL (now_seg))
2656 return;
2657
cd000bff
DJ
2658 if (mapstate == state)
2659 /* The mapping symbol has already been emitted.
2660 There is nothing else to do. */
2661 return;
2662
cd000bff
DJ
2663 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2664 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205
ZW
2665}
2666#else
d3106081
NS
2667#define mapping_state(x) ((void)0)
2668#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2669#endif
2670
2671/* Find the real, Thumb encoded start of a Thumb function. */
2672
4343666d 2673#ifdef OBJ_COFF
c19d1205
ZW
2674static symbolS *
2675find_real_start (symbolS * symbolP)
2676{
2677 char * real_start;
2678 const char * name = S_GET_NAME (symbolP);
2679 symbolS * new_target;
2680
2681 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2682#define STUB_NAME ".real_start_of"
2683
2684 if (name == NULL)
2685 abort ();
2686
37f6032b
ZW
2687 /* The compiler may generate BL instructions to local labels because
2688 it needs to perform a branch to a far away location. These labels
2689 do not have a corresponding ".real_start_of" label. We check
2690 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2691 the ".real_start_of" convention for nonlocal branches. */
2692 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2693 return symbolP;
2694
37f6032b 2695 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2696 new_target = symbol_find (real_start);
2697
2698 if (new_target == NULL)
2699 {
bd3ba5d1 2700 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2701 new_target = symbolP;
2702 }
2703
c19d1205
ZW
2704 return new_target;
2705}
4343666d 2706#endif
c19d1205
ZW
2707
2708static void
2709opcode_select (int width)
2710{
2711 switch (width)
2712 {
2713 case 16:
2714 if (! thumb_mode)
2715 {
e74cfd16 2716 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2717 as_bad (_("selected processor does not support THUMB opcodes"));
2718
2719 thumb_mode = 1;
2720 /* No need to force the alignment, since we will have been
2721 coming from ARM mode, which is word-aligned. */
2722 record_alignment (now_seg, 1);
2723 }
c19d1205
ZW
2724 break;
2725
2726 case 32:
2727 if (thumb_mode)
2728 {
e74cfd16 2729 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2730 as_bad (_("selected processor does not support ARM opcodes"));
2731
2732 thumb_mode = 0;
2733
2734 if (!need_pass_2)
2735 frag_align (2, 0, 0);
2736
2737 record_alignment (now_seg, 1);
2738 }
c19d1205
ZW
2739 break;
2740
2741 default:
2742 as_bad (_("invalid instruction size selected (%d)"), width);
2743 }
2744}
2745
2746static void
2747s_arm (int ignore ATTRIBUTE_UNUSED)
2748{
2749 opcode_select (32);
2750 demand_empty_rest_of_line ();
2751}
2752
2753static void
2754s_thumb (int ignore ATTRIBUTE_UNUSED)
2755{
2756 opcode_select (16);
2757 demand_empty_rest_of_line ();
2758}
2759
2760static void
2761s_code (int unused ATTRIBUTE_UNUSED)
2762{
2763 int temp;
2764
2765 temp = get_absolute_expression ();
2766 switch (temp)
2767 {
2768 case 16:
2769 case 32:
2770 opcode_select (temp);
2771 break;
2772
2773 default:
2774 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2775 }
2776}
2777
2778static void
2779s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2780{
2781 /* If we are not already in thumb mode go into it, EVEN if
2782 the target processor does not support thumb instructions.
2783 This is used by gcc/config/arm/lib1funcs.asm for example
2784 to compile interworking support functions even if the
2785 target processor should not support interworking. */
2786 if (! thumb_mode)
2787 {
2788 thumb_mode = 2;
2789 record_alignment (now_seg, 1);
2790 }
2791
2792 demand_empty_rest_of_line ();
2793}
2794
2795static void
2796s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2797{
2798 s_thumb (0);
2799
2800 /* The following label is the name/address of the start of a Thumb function.
2801 We need to know this for the interworking support. */
2802 label_is_thumb_function_name = TRUE;
2803}
2804
2805/* Perform a .set directive, but also mark the alias as
2806 being a thumb function. */
2807
2808static void
2809s_thumb_set (int equiv)
2810{
2811 /* XXX the following is a duplicate of the code for s_set() in read.c
2812 We cannot just call that code as we need to get at the symbol that
2813 is created. */
2814 char * name;
2815 char delim;
2816 char * end_name;
2817 symbolS * symbolP;
2818
2819 /* Especial apologies for the random logic:
2820 This just grew, and could be parsed much more simply!
2821 Dean - in haste. */
2822 name = input_line_pointer;
2823 delim = get_symbol_end ();
2824 end_name = input_line_pointer;
2825 *end_name = delim;
2826
2827 if (*input_line_pointer != ',')
2828 {
2829 *end_name = 0;
2830 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2831 *end_name = delim;
2832 ignore_rest_of_line ();
2833 return;
2834 }
2835
2836 input_line_pointer++;
2837 *end_name = 0;
2838
2839 if (name[0] == '.' && name[1] == '\0')
2840 {
2841 /* XXX - this should not happen to .thumb_set. */
2842 abort ();
2843 }
2844
2845 if ((symbolP = symbol_find (name)) == NULL
2846 && (symbolP = md_undefined_symbol (name)) == NULL)
2847 {
2848#ifndef NO_LISTING
2849 /* When doing symbol listings, play games with dummy fragments living
2850 outside the normal fragment chain to record the file and line info
c19d1205 2851 for this symbol. */
b99bd4ef
NC
2852 if (listing & LISTING_SYMBOLS)
2853 {
2854 extern struct list_info_struct * listing_tail;
21d799b5 2855 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2856
2857 memset (dummy_frag, 0, sizeof (fragS));
2858 dummy_frag->fr_type = rs_fill;
2859 dummy_frag->line = listing_tail;
2860 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2861 dummy_frag->fr_symbol = symbolP;
2862 }
2863 else
2864#endif
2865 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2866
2867#ifdef OBJ_COFF
2868 /* "set" symbols are local unless otherwise specified. */
2869 SF_SET_LOCAL (symbolP);
2870#endif /* OBJ_COFF */
2871 } /* Make a new symbol. */
2872
2873 symbol_table_insert (symbolP);
2874
2875 * end_name = delim;
2876
2877 if (equiv
2878 && S_IS_DEFINED (symbolP)
2879 && S_GET_SEGMENT (symbolP) != reg_section)
2880 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2881
2882 pseudo_set (symbolP);
2883
2884 demand_empty_rest_of_line ();
2885
c19d1205 2886 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2887
2888 THUMB_SET_FUNC (symbolP, 1);
2889 ARM_SET_THUMB (symbolP, 1);
2890#if defined OBJ_ELF || defined OBJ_COFF
2891 ARM_SET_INTERWORK (symbolP, support_interwork);
2892#endif
2893}
2894
c19d1205 2895/* Directives: Mode selection. */
b99bd4ef 2896
c19d1205
ZW
2897/* .syntax [unified|divided] - choose the new unified syntax
2898 (same for Arm and Thumb encoding, modulo slight differences in what
2899 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2900static void
c19d1205 2901s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2902{
c19d1205
ZW
2903 char *name, delim;
2904
2905 name = input_line_pointer;
2906 delim = get_symbol_end ();
2907
2908 if (!strcasecmp (name, "unified"))
2909 unified_syntax = TRUE;
2910 else if (!strcasecmp (name, "divided"))
2911 unified_syntax = FALSE;
2912 else
2913 {
2914 as_bad (_("unrecognized syntax mode \"%s\""), name);
2915 return;
2916 }
2917 *input_line_pointer = delim;
b99bd4ef
NC
2918 demand_empty_rest_of_line ();
2919}
2920
c19d1205
ZW
2921/* Directives: sectioning and alignment. */
2922
2923/* Same as s_align_ptwo but align 0 => align 2. */
2924
b99bd4ef 2925static void
c19d1205 2926s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2927{
a737bd4d 2928 int temp;
dce323d1 2929 bfd_boolean fill_p;
c19d1205
ZW
2930 long temp_fill;
2931 long max_alignment = 15;
b99bd4ef
NC
2932
2933 temp = get_absolute_expression ();
c19d1205
ZW
2934 if (temp > max_alignment)
2935 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2936 else if (temp < 0)
b99bd4ef 2937 {
c19d1205
ZW
2938 as_bad (_("alignment negative. 0 assumed."));
2939 temp = 0;
2940 }
b99bd4ef 2941
c19d1205
ZW
2942 if (*input_line_pointer == ',')
2943 {
2944 input_line_pointer++;
2945 temp_fill = get_absolute_expression ();
dce323d1 2946 fill_p = TRUE;
b99bd4ef 2947 }
c19d1205 2948 else
dce323d1
PB
2949 {
2950 fill_p = FALSE;
2951 temp_fill = 0;
2952 }
b99bd4ef 2953
c19d1205
ZW
2954 if (!temp)
2955 temp = 2;
b99bd4ef 2956
c19d1205
ZW
2957 /* Only make a frag if we HAVE to. */
2958 if (temp && !need_pass_2)
dce323d1
PB
2959 {
2960 if (!fill_p && subseg_text_p (now_seg))
2961 frag_align_code (temp, 0);
2962 else
2963 frag_align (temp, (int) temp_fill, 0);
2964 }
c19d1205
ZW
2965 demand_empty_rest_of_line ();
2966
2967 record_alignment (now_seg, temp);
b99bd4ef
NC
2968}
2969
c19d1205
ZW
2970static void
2971s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2972{
c19d1205
ZW
2973 /* We don't support putting frags in the BSS segment, we fake it by
2974 marking in_bss, then looking at s_skip for clues. */
2975 subseg_set (bss_section, 0);
2976 demand_empty_rest_of_line ();
cd000bff
DJ
2977
2978#ifdef md_elf_section_change_hook
2979 md_elf_section_change_hook ();
2980#endif
c19d1205 2981}
b99bd4ef 2982
c19d1205
ZW
2983static void
2984s_even (int ignore ATTRIBUTE_UNUSED)
2985{
2986 /* Never make frag if expect extra pass. */
2987 if (!need_pass_2)
2988 frag_align (1, 0, 0);
b99bd4ef 2989
c19d1205 2990 record_alignment (now_seg, 1);
b99bd4ef 2991
c19d1205 2992 demand_empty_rest_of_line ();
b99bd4ef
NC
2993}
2994
c19d1205 2995/* Directives: Literal pools. */
a737bd4d 2996
c19d1205
ZW
2997static literal_pool *
2998find_literal_pool (void)
a737bd4d 2999{
c19d1205 3000 literal_pool * pool;
a737bd4d 3001
c19d1205 3002 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3003 {
c19d1205
ZW
3004 if (pool->section == now_seg
3005 && pool->sub_section == now_subseg)
3006 break;
a737bd4d
NC
3007 }
3008
c19d1205 3009 return pool;
a737bd4d
NC
3010}
3011
c19d1205
ZW
3012static literal_pool *
3013find_or_make_literal_pool (void)
a737bd4d 3014{
c19d1205
ZW
3015 /* Next literal pool ID number. */
3016 static unsigned int latest_pool_num = 1;
3017 literal_pool * pool;
a737bd4d 3018
c19d1205 3019 pool = find_literal_pool ();
a737bd4d 3020
c19d1205 3021 if (pool == NULL)
a737bd4d 3022 {
c19d1205 3023 /* Create a new pool. */
21d799b5 3024 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
3025 if (! pool)
3026 return NULL;
a737bd4d 3027
c19d1205
ZW
3028 pool->next_free_entry = 0;
3029 pool->section = now_seg;
3030 pool->sub_section = now_subseg;
3031 pool->next = list_of_pools;
3032 pool->symbol = NULL;
3033
3034 /* Add it to the list. */
3035 list_of_pools = pool;
a737bd4d 3036 }
a737bd4d 3037
c19d1205
ZW
3038 /* New pools, and emptied pools, will have a NULL symbol. */
3039 if (pool->symbol == NULL)
a737bd4d 3040 {
c19d1205
ZW
3041 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3042 (valueT) 0, &zero_address_frag);
3043 pool->id = latest_pool_num ++;
a737bd4d
NC
3044 }
3045
c19d1205
ZW
3046 /* Done. */
3047 return pool;
a737bd4d
NC
3048}
3049
c19d1205 3050/* Add the literal in the global 'inst'
5f4273c7 3051 structure to the relevant literal pool. */
b99bd4ef
NC
3052
3053static int
c19d1205 3054add_to_lit_pool (void)
b99bd4ef 3055{
c19d1205
ZW
3056 literal_pool * pool;
3057 unsigned int entry;
b99bd4ef 3058
c19d1205
ZW
3059 pool = find_or_make_literal_pool ();
3060
3061 /* Check if this literal value is already in the pool. */
3062 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3063 {
c19d1205
ZW
3064 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3065 && (inst.reloc.exp.X_op == O_constant)
3066 && (pool->literals[entry].X_add_number
3067 == inst.reloc.exp.X_add_number)
3068 && (pool->literals[entry].X_unsigned
3069 == inst.reloc.exp.X_unsigned))
3070 break;
3071
3072 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3073 && (inst.reloc.exp.X_op == O_symbol)
3074 && (pool->literals[entry].X_add_number
3075 == inst.reloc.exp.X_add_number)
3076 && (pool->literals[entry].X_add_symbol
3077 == inst.reloc.exp.X_add_symbol)
3078 && (pool->literals[entry].X_op_symbol
3079 == inst.reloc.exp.X_op_symbol))
3080 break;
b99bd4ef
NC
3081 }
3082
c19d1205
ZW
3083 /* Do we need to create a new entry? */
3084 if (entry == pool->next_free_entry)
3085 {
3086 if (entry >= MAX_LITERAL_POOL_SIZE)
3087 {
3088 inst.error = _("literal pool overflow");
3089 return FAIL;
3090 }
3091
3092 pool->literals[entry] = inst.reloc.exp;
a8040cf2
NC
3093#ifdef OBJ_ELF
3094 /* PR ld/12974: Record the location of the first source line to reference
3095 this entry in the literal pool. If it turns out during linking that the
3096 symbol does not exist we will be able to give an accurate line number for
3097 the (first use of the) missing reference. */
3098 if (debug_type == DEBUG_DWARF2)
3099 dwarf2_where (pool->locs + entry);
3100#endif
c19d1205
ZW
3101 pool->next_free_entry += 1;
3102 }
b99bd4ef 3103
c19d1205
ZW
3104 inst.reloc.exp.X_op = O_symbol;
3105 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3106 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3107
c19d1205 3108 return SUCCESS;
b99bd4ef
NC
3109}
3110
c19d1205
ZW
3111/* Can't use symbol_new here, so have to create a symbol and then at
3112 a later date assign it a value. Thats what these functions do. */
e16bb312 3113
c19d1205
ZW
3114static void
3115symbol_locate (symbolS * symbolP,
3116 const char * name, /* It is copied, the caller can modify. */
3117 segT segment, /* Segment identifier (SEG_<something>). */
3118 valueT valu, /* Symbol value. */
3119 fragS * frag) /* Associated fragment. */
3120{
3121 unsigned int name_length;
3122 char * preserved_copy_of_name;
e16bb312 3123
c19d1205
ZW
3124 name_length = strlen (name) + 1; /* +1 for \0. */
3125 obstack_grow (&notes, name, name_length);
21d799b5 3126 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3127
c19d1205
ZW
3128#ifdef tc_canonicalize_symbol_name
3129 preserved_copy_of_name =
3130 tc_canonicalize_symbol_name (preserved_copy_of_name);
3131#endif
b99bd4ef 3132
c19d1205 3133 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3134
c19d1205
ZW
3135 S_SET_SEGMENT (symbolP, segment);
3136 S_SET_VALUE (symbolP, valu);
3137 symbol_clear_list_pointers (symbolP);
b99bd4ef 3138
c19d1205 3139 symbol_set_frag (symbolP, frag);
b99bd4ef 3140
c19d1205
ZW
3141 /* Link to end of symbol chain. */
3142 {
3143 extern int symbol_table_frozen;
b99bd4ef 3144
c19d1205
ZW
3145 if (symbol_table_frozen)
3146 abort ();
3147 }
b99bd4ef 3148
c19d1205 3149 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3150
c19d1205 3151 obj_symbol_new_hook (symbolP);
b99bd4ef 3152
c19d1205
ZW
3153#ifdef tc_symbol_new_hook
3154 tc_symbol_new_hook (symbolP);
3155#endif
3156
3157#ifdef DEBUG_SYMS
3158 verify_symbol_chain (symbol_rootP, symbol_lastP);
3159#endif /* DEBUG_SYMS */
b99bd4ef
NC
3160}
3161
b99bd4ef 3162
c19d1205
ZW
3163static void
3164s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3165{
c19d1205
ZW
3166 unsigned int entry;
3167 literal_pool * pool;
3168 char sym_name[20];
b99bd4ef 3169
c19d1205
ZW
3170 pool = find_literal_pool ();
3171 if (pool == NULL
3172 || pool->symbol == NULL
3173 || pool->next_free_entry == 0)
3174 return;
b99bd4ef 3175
c19d1205 3176 mapping_state (MAP_DATA);
b99bd4ef 3177
c19d1205
ZW
3178 /* Align pool as you have word accesses.
3179 Only make a frag if we have to. */
3180 if (!need_pass_2)
3181 frag_align (2, 0, 0);
b99bd4ef 3182
c19d1205 3183 record_alignment (now_seg, 2);
b99bd4ef 3184
c19d1205 3185 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3186
c19d1205
ZW
3187 symbol_locate (pool->symbol, sym_name, now_seg,
3188 (valueT) frag_now_fix (), frag_now);
3189 symbol_table_insert (pool->symbol);
b99bd4ef 3190
c19d1205 3191 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3192
c19d1205
ZW
3193#if defined OBJ_COFF || defined OBJ_ELF
3194 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3195#endif
6c43fab6 3196
c19d1205 3197 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3198 {
3199#ifdef OBJ_ELF
3200 if (debug_type == DEBUG_DWARF2)
3201 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3202#endif
3203 /* First output the expression in the instruction to the pool. */
3204 emit_expr (&(pool->literals[entry]), 4); /* .word */
3205 }
b99bd4ef 3206
c19d1205
ZW
3207 /* Mark the pool as empty. */
3208 pool->next_free_entry = 0;
3209 pool->symbol = NULL;
b99bd4ef
NC
3210}
3211
c19d1205
ZW
3212#ifdef OBJ_ELF
3213/* Forward declarations for functions below, in the MD interface
3214 section. */
3215static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3216static valueT create_unwind_entry (int);
3217static void start_unwind_section (const segT, int);
3218static void add_unwind_opcode (valueT, int);
3219static void flush_pending_unwind (void);
b99bd4ef 3220
c19d1205 3221/* Directives: Data. */
b99bd4ef 3222
c19d1205
ZW
3223static void
3224s_arm_elf_cons (int nbytes)
3225{
3226 expressionS exp;
b99bd4ef 3227
c19d1205
ZW
3228#ifdef md_flush_pending_output
3229 md_flush_pending_output ();
3230#endif
b99bd4ef 3231
c19d1205 3232 if (is_it_end_of_statement ())
b99bd4ef 3233 {
c19d1205
ZW
3234 demand_empty_rest_of_line ();
3235 return;
b99bd4ef
NC
3236 }
3237
c19d1205
ZW
3238#ifdef md_cons_align
3239 md_cons_align (nbytes);
3240#endif
b99bd4ef 3241
c19d1205
ZW
3242 mapping_state (MAP_DATA);
3243 do
b99bd4ef 3244 {
c19d1205
ZW
3245 int reloc;
3246 char *base = input_line_pointer;
b99bd4ef 3247
c19d1205 3248 expression (& exp);
b99bd4ef 3249
c19d1205
ZW
3250 if (exp.X_op != O_symbol)
3251 emit_expr (&exp, (unsigned int) nbytes);
3252 else
3253 {
3254 char *before_reloc = input_line_pointer;
3255 reloc = parse_reloc (&input_line_pointer);
3256 if (reloc == -1)
3257 {
3258 as_bad (_("unrecognized relocation suffix"));
3259 ignore_rest_of_line ();
3260 return;
3261 }
3262 else if (reloc == BFD_RELOC_UNUSED)
3263 emit_expr (&exp, (unsigned int) nbytes);
3264 else
3265 {
21d799b5
NC
3266 reloc_howto_type *howto = (reloc_howto_type *)
3267 bfd_reloc_type_lookup (stdoutput,
3268 (bfd_reloc_code_real_type) reloc);
c19d1205 3269 int size = bfd_get_reloc_size (howto);
b99bd4ef 3270
2fc8bdac
ZW
3271 if (reloc == BFD_RELOC_ARM_PLT32)
3272 {
3273 as_bad (_("(plt) is only valid on branch targets"));
3274 reloc = BFD_RELOC_UNUSED;
3275 size = 0;
3276 }
3277
c19d1205 3278 if (size > nbytes)
2fc8bdac 3279 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3280 howto->name, nbytes);
3281 else
3282 {
3283 /* We've parsed an expression stopping at O_symbol.
3284 But there may be more expression left now that we
3285 have parsed the relocation marker. Parse it again.
3286 XXX Surely there is a cleaner way to do this. */
3287 char *p = input_line_pointer;
3288 int offset;
21d799b5 3289 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3290 memcpy (save_buf, base, input_line_pointer - base);
3291 memmove (base + (input_line_pointer - before_reloc),
3292 base, before_reloc - base);
3293
3294 input_line_pointer = base + (input_line_pointer-before_reloc);
3295 expression (&exp);
3296 memcpy (base, save_buf, p - base);
3297
3298 offset = nbytes - size;
3299 p = frag_more ((int) nbytes);
3300 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3301 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3302 }
3303 }
3304 }
b99bd4ef 3305 }
c19d1205 3306 while (*input_line_pointer++ == ',');
b99bd4ef 3307
c19d1205
ZW
3308 /* Put terminator back into stream. */
3309 input_line_pointer --;
3310 demand_empty_rest_of_line ();
b99bd4ef
NC
3311}
3312
c921be7d
NC
3313/* Emit an expression containing a 32-bit thumb instruction.
3314 Implementation based on put_thumb32_insn. */
3315
3316static void
3317emit_thumb32_expr (expressionS * exp)
3318{
3319 expressionS exp_high = *exp;
3320
3321 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3322 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3323 exp->X_add_number &= 0xffff;
3324 emit_expr (exp, (unsigned int) THUMB_SIZE);
3325}
3326
3327/* Guess the instruction size based on the opcode. */
3328
3329static int
3330thumb_insn_size (int opcode)
3331{
3332 if ((unsigned int) opcode < 0xe800u)
3333 return 2;
3334 else if ((unsigned int) opcode >= 0xe8000000u)
3335 return 4;
3336 else
3337 return 0;
3338}
3339
3340static bfd_boolean
3341emit_insn (expressionS *exp, int nbytes)
3342{
3343 int size = 0;
3344
3345 if (exp->X_op == O_constant)
3346 {
3347 size = nbytes;
3348
3349 if (size == 0)
3350 size = thumb_insn_size (exp->X_add_number);
3351
3352 if (size != 0)
3353 {
3354 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3355 {
3356 as_bad (_(".inst.n operand too big. "\
3357 "Use .inst.w instead"));
3358 size = 0;
3359 }
3360 else
3361 {
3362 if (now_it.state == AUTOMATIC_IT_BLOCK)
3363 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3364 else
3365 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3366
3367 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3368 emit_thumb32_expr (exp);
3369 else
3370 emit_expr (exp, (unsigned int) size);
3371
3372 it_fsm_post_encode ();
3373 }
3374 }
3375 else
3376 as_bad (_("cannot determine Thumb instruction size. " \
3377 "Use .inst.n/.inst.w instead"));
3378 }
3379 else
3380 as_bad (_("constant expression required"));
3381
3382 return (size != 0);
3383}
3384
3385/* Like s_arm_elf_cons but do not use md_cons_align and
3386 set the mapping state to MAP_ARM/MAP_THUMB. */
3387
3388static void
3389s_arm_elf_inst (int nbytes)
3390{
3391 if (is_it_end_of_statement ())
3392 {
3393 demand_empty_rest_of_line ();
3394 return;
3395 }
3396
3397 /* Calling mapping_state () here will not change ARM/THUMB,
3398 but will ensure not to be in DATA state. */
3399
3400 if (thumb_mode)
3401 mapping_state (MAP_THUMB);
3402 else
3403 {
3404 if (nbytes != 0)
3405 {
3406 as_bad (_("width suffixes are invalid in ARM mode"));
3407 ignore_rest_of_line ();
3408 return;
3409 }
3410
3411 nbytes = 4;
3412
3413 mapping_state (MAP_ARM);
3414 }
3415
3416 do
3417 {
3418 expressionS exp;
3419
3420 expression (& exp);
3421
3422 if (! emit_insn (& exp, nbytes))
3423 {
3424 ignore_rest_of_line ();
3425 return;
3426 }
3427 }
3428 while (*input_line_pointer++ == ',');
3429
3430 /* Put terminator back into stream. */
3431 input_line_pointer --;
3432 demand_empty_rest_of_line ();
3433}
b99bd4ef 3434
c19d1205 3435/* Parse a .rel31 directive. */
b99bd4ef 3436
c19d1205
ZW
3437static void
3438s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3439{
3440 expressionS exp;
3441 char *p;
3442 valueT highbit;
b99bd4ef 3443
c19d1205
ZW
3444 highbit = 0;
3445 if (*input_line_pointer == '1')
3446 highbit = 0x80000000;
3447 else if (*input_line_pointer != '0')
3448 as_bad (_("expected 0 or 1"));
b99bd4ef 3449
c19d1205
ZW
3450 input_line_pointer++;
3451 if (*input_line_pointer != ',')
3452 as_bad (_("missing comma"));
3453 input_line_pointer++;
b99bd4ef 3454
c19d1205
ZW
3455#ifdef md_flush_pending_output
3456 md_flush_pending_output ();
3457#endif
b99bd4ef 3458
c19d1205
ZW
3459#ifdef md_cons_align
3460 md_cons_align (4);
3461#endif
b99bd4ef 3462
c19d1205 3463 mapping_state (MAP_DATA);
b99bd4ef 3464
c19d1205 3465 expression (&exp);
b99bd4ef 3466
c19d1205
ZW
3467 p = frag_more (4);
3468 md_number_to_chars (p, highbit, 4);
3469 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3470 BFD_RELOC_ARM_PREL31);
b99bd4ef 3471
c19d1205 3472 demand_empty_rest_of_line ();
b99bd4ef
NC
3473}
3474
c19d1205 3475/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3476
c19d1205 3477/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3478
c19d1205
ZW
3479static void
3480s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3481{
3482 demand_empty_rest_of_line ();
921e5f0a
PB
3483 if (unwind.proc_start)
3484 {
c921be7d 3485 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3486 return;
3487 }
3488
c19d1205
ZW
3489 /* Mark the start of the function. */
3490 unwind.proc_start = expr_build_dot ();
b99bd4ef 3491
c19d1205
ZW
3492 /* Reset the rest of the unwind info. */
3493 unwind.opcode_count = 0;
3494 unwind.table_entry = NULL;
3495 unwind.personality_routine = NULL;
3496 unwind.personality_index = -1;
3497 unwind.frame_size = 0;
3498 unwind.fp_offset = 0;
fdfde340 3499 unwind.fp_reg = REG_SP;
c19d1205
ZW
3500 unwind.fp_used = 0;
3501 unwind.sp_restored = 0;
3502}
b99bd4ef 3503
b99bd4ef 3504
c19d1205
ZW
3505/* Parse a handlerdata directive. Creates the exception handling table entry
3506 for the function. */
b99bd4ef 3507
c19d1205
ZW
3508static void
3509s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3510{
3511 demand_empty_rest_of_line ();
921e5f0a 3512 if (!unwind.proc_start)
c921be7d 3513 as_bad (MISSING_FNSTART);
921e5f0a 3514
c19d1205 3515 if (unwind.table_entry)
6decc662 3516 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3517
c19d1205
ZW
3518 create_unwind_entry (1);
3519}
a737bd4d 3520
c19d1205 3521/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3522
c19d1205
ZW
3523static void
3524s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3525{
3526 long where;
3527 char *ptr;
3528 valueT val;
940b5ce0 3529 unsigned int marked_pr_dependency;
f02232aa 3530
c19d1205 3531 demand_empty_rest_of_line ();
f02232aa 3532
921e5f0a
PB
3533 if (!unwind.proc_start)
3534 {
c921be7d 3535 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3536 return;
3537 }
3538
c19d1205
ZW
3539 /* Add eh table entry. */
3540 if (unwind.table_entry == NULL)
3541 val = create_unwind_entry (0);
3542 else
3543 val = 0;
f02232aa 3544
c19d1205
ZW
3545 /* Add index table entry. This is two words. */
3546 start_unwind_section (unwind.saved_seg, 1);
3547 frag_align (2, 0, 0);
3548 record_alignment (now_seg, 2);
b99bd4ef 3549
c19d1205 3550 ptr = frag_more (8);
5011093d 3551 memset (ptr, 0, 8);
c19d1205 3552 where = frag_now_fix () - 8;
f02232aa 3553
c19d1205
ZW
3554 /* Self relative offset of the function start. */
3555 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3556 BFD_RELOC_ARM_PREL31);
f02232aa 3557
c19d1205
ZW
3558 /* Indicate dependency on EHABI-defined personality routines to the
3559 linker, if it hasn't been done already. */
940b5ce0
DJ
3560 marked_pr_dependency
3561 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3562 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3563 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3564 {
5f4273c7
NC
3565 static const char *const name[] =
3566 {
3567 "__aeabi_unwind_cpp_pr0",
3568 "__aeabi_unwind_cpp_pr1",
3569 "__aeabi_unwind_cpp_pr2"
3570 };
c19d1205
ZW
3571 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3572 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3573 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3574 |= 1 << unwind.personality_index;
c19d1205 3575 }
f02232aa 3576
c19d1205
ZW
3577 if (val)
3578 /* Inline exception table entry. */
3579 md_number_to_chars (ptr + 4, val, 4);
3580 else
3581 /* Self relative offset of the table entry. */
3582 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3583 BFD_RELOC_ARM_PREL31);
f02232aa 3584
c19d1205
ZW
3585 /* Restore the original section. */
3586 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3587
3588 unwind.proc_start = NULL;
c19d1205 3589}
f02232aa 3590
f02232aa 3591
c19d1205 3592/* Parse an unwind_cantunwind directive. */
b99bd4ef 3593
c19d1205
ZW
3594static void
3595s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3596{
3597 demand_empty_rest_of_line ();
921e5f0a 3598 if (!unwind.proc_start)
c921be7d 3599 as_bad (MISSING_FNSTART);
921e5f0a 3600
c19d1205
ZW
3601 if (unwind.personality_routine || unwind.personality_index != -1)
3602 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3603
c19d1205
ZW
3604 unwind.personality_index = -2;
3605}
b99bd4ef 3606
b99bd4ef 3607
c19d1205 3608/* Parse a personalityindex directive. */
b99bd4ef 3609
c19d1205
ZW
3610static void
3611s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3612{
3613 expressionS exp;
b99bd4ef 3614
921e5f0a 3615 if (!unwind.proc_start)
c921be7d 3616 as_bad (MISSING_FNSTART);
921e5f0a 3617
c19d1205
ZW
3618 if (unwind.personality_routine || unwind.personality_index != -1)
3619 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3620
c19d1205 3621 expression (&exp);
b99bd4ef 3622
c19d1205
ZW
3623 if (exp.X_op != O_constant
3624 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3625 {
c19d1205
ZW
3626 as_bad (_("bad personality routine number"));
3627 ignore_rest_of_line ();
3628 return;
b99bd4ef
NC
3629 }
3630
c19d1205 3631 unwind.personality_index = exp.X_add_number;
b99bd4ef 3632
c19d1205
ZW
3633 demand_empty_rest_of_line ();
3634}
e16bb312 3635
e16bb312 3636
c19d1205 3637/* Parse a personality directive. */
e16bb312 3638
c19d1205
ZW
3639static void
3640s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3641{
3642 char *name, *p, c;
a737bd4d 3643
921e5f0a 3644 if (!unwind.proc_start)
c921be7d 3645 as_bad (MISSING_FNSTART);
921e5f0a 3646
c19d1205
ZW
3647 if (unwind.personality_routine || unwind.personality_index != -1)
3648 as_bad (_("duplicate .personality directive"));
a737bd4d 3649
c19d1205
ZW
3650 name = input_line_pointer;
3651 c = get_symbol_end ();
3652 p = input_line_pointer;
3653 unwind.personality_routine = symbol_find_or_make (name);
3654 *p = c;
3655 demand_empty_rest_of_line ();
3656}
e16bb312 3657
e16bb312 3658
c19d1205 3659/* Parse a directive saving core registers. */
e16bb312 3660
c19d1205
ZW
3661static void
3662s_arm_unwind_save_core (void)
e16bb312 3663{
c19d1205
ZW
3664 valueT op;
3665 long range;
3666 int n;
e16bb312 3667
c19d1205
ZW
3668 range = parse_reg_list (&input_line_pointer);
3669 if (range == FAIL)
e16bb312 3670 {
c19d1205
ZW
3671 as_bad (_("expected register list"));
3672 ignore_rest_of_line ();
3673 return;
3674 }
e16bb312 3675
c19d1205 3676 demand_empty_rest_of_line ();
e16bb312 3677
c19d1205
ZW
3678 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3679 into .unwind_save {..., sp...}. We aren't bothered about the value of
3680 ip because it is clobbered by calls. */
3681 if (unwind.sp_restored && unwind.fp_reg == 12
3682 && (range & 0x3000) == 0x1000)
3683 {
3684 unwind.opcode_count--;
3685 unwind.sp_restored = 0;
3686 range = (range | 0x2000) & ~0x1000;
3687 unwind.pending_offset = 0;
3688 }
e16bb312 3689
01ae4198
DJ
3690 /* Pop r4-r15. */
3691 if (range & 0xfff0)
c19d1205 3692 {
01ae4198
DJ
3693 /* See if we can use the short opcodes. These pop a block of up to 8
3694 registers starting with r4, plus maybe r14. */
3695 for (n = 0; n < 8; n++)
3696 {
3697 /* Break at the first non-saved register. */
3698 if ((range & (1 << (n + 4))) == 0)
3699 break;
3700 }
3701 /* See if there are any other bits set. */
3702 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3703 {
3704 /* Use the long form. */
3705 op = 0x8000 | ((range >> 4) & 0xfff);
3706 add_unwind_opcode (op, 2);
3707 }
0dd132b6 3708 else
01ae4198
DJ
3709 {
3710 /* Use the short form. */
3711 if (range & 0x4000)
3712 op = 0xa8; /* Pop r14. */
3713 else
3714 op = 0xa0; /* Do not pop r14. */
3715 op |= (n - 1);
3716 add_unwind_opcode (op, 1);
3717 }
c19d1205 3718 }
0dd132b6 3719
c19d1205
ZW
3720 /* Pop r0-r3. */
3721 if (range & 0xf)
3722 {
3723 op = 0xb100 | (range & 0xf);
3724 add_unwind_opcode (op, 2);
0dd132b6
NC
3725 }
3726
c19d1205
ZW
3727 /* Record the number of bytes pushed. */
3728 for (n = 0; n < 16; n++)
3729 {
3730 if (range & (1 << n))
3731 unwind.frame_size += 4;
3732 }
0dd132b6
NC
3733}
3734
c19d1205
ZW
3735
3736/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3737
3738static void
c19d1205 3739s_arm_unwind_save_fpa (int reg)
b99bd4ef 3740{
c19d1205
ZW
3741 expressionS exp;
3742 int num_regs;
3743 valueT op;
b99bd4ef 3744
c19d1205
ZW
3745 /* Get Number of registers to transfer. */
3746 if (skip_past_comma (&input_line_pointer) != FAIL)
3747 expression (&exp);
3748 else
3749 exp.X_op = O_illegal;
b99bd4ef 3750
c19d1205 3751 if (exp.X_op != O_constant)
b99bd4ef 3752 {
c19d1205
ZW
3753 as_bad (_("expected , <constant>"));
3754 ignore_rest_of_line ();
b99bd4ef
NC
3755 return;
3756 }
3757
c19d1205
ZW
3758 num_regs = exp.X_add_number;
3759
3760 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3761 {
c19d1205
ZW
3762 as_bad (_("number of registers must be in the range [1:4]"));
3763 ignore_rest_of_line ();
b99bd4ef
NC
3764 return;
3765 }
3766
c19d1205 3767 demand_empty_rest_of_line ();
b99bd4ef 3768
c19d1205
ZW
3769 if (reg == 4)
3770 {
3771 /* Short form. */
3772 op = 0xb4 | (num_regs - 1);
3773 add_unwind_opcode (op, 1);
3774 }
b99bd4ef
NC
3775 else
3776 {
c19d1205
ZW
3777 /* Long form. */
3778 op = 0xc800 | (reg << 4) | (num_regs - 1);
3779 add_unwind_opcode (op, 2);
b99bd4ef 3780 }
c19d1205 3781 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3782}
3783
c19d1205 3784
fa073d69
MS
3785/* Parse a directive saving VFP registers for ARMv6 and above. */
3786
3787static void
3788s_arm_unwind_save_vfp_armv6 (void)
3789{
3790 int count;
3791 unsigned int start;
3792 valueT op;
3793 int num_vfpv3_regs = 0;
3794 int num_regs_below_16;
3795
3796 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3797 if (count == FAIL)
3798 {
3799 as_bad (_("expected register list"));
3800 ignore_rest_of_line ();
3801 return;
3802 }
3803
3804 demand_empty_rest_of_line ();
3805
3806 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3807 than FSTMX/FLDMX-style ones). */
3808
3809 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3810 if (start >= 16)
3811 num_vfpv3_regs = count;
3812 else if (start + count > 16)
3813 num_vfpv3_regs = start + count - 16;
3814
3815 if (num_vfpv3_regs > 0)
3816 {
3817 int start_offset = start > 16 ? start - 16 : 0;
3818 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3819 add_unwind_opcode (op, 2);
3820 }
3821
3822 /* Generate opcode for registers numbered in the range 0 .. 15. */
3823 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3824 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3825 if (num_regs_below_16 > 0)
3826 {
3827 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3828 add_unwind_opcode (op, 2);
3829 }
3830
3831 unwind.frame_size += count * 8;
3832}
3833
3834
3835/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3836
3837static void
c19d1205 3838s_arm_unwind_save_vfp (void)
b99bd4ef 3839{
c19d1205 3840 int count;
ca3f61f7 3841 unsigned int reg;
c19d1205 3842 valueT op;
b99bd4ef 3843
5287ad62 3844 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3845 if (count == FAIL)
b99bd4ef 3846 {
c19d1205
ZW
3847 as_bad (_("expected register list"));
3848 ignore_rest_of_line ();
b99bd4ef
NC
3849 return;
3850 }
3851
c19d1205 3852 demand_empty_rest_of_line ();
b99bd4ef 3853
c19d1205 3854 if (reg == 8)
b99bd4ef 3855 {
c19d1205
ZW
3856 /* Short form. */
3857 op = 0xb8 | (count - 1);
3858 add_unwind_opcode (op, 1);
b99bd4ef 3859 }
c19d1205 3860 else
b99bd4ef 3861 {
c19d1205
ZW
3862 /* Long form. */
3863 op = 0xb300 | (reg << 4) | (count - 1);
3864 add_unwind_opcode (op, 2);
b99bd4ef 3865 }
c19d1205
ZW
3866 unwind.frame_size += count * 8 + 4;
3867}
b99bd4ef 3868
b99bd4ef 3869
c19d1205
ZW
3870/* Parse a directive saving iWMMXt data registers. */
3871
3872static void
3873s_arm_unwind_save_mmxwr (void)
3874{
3875 int reg;
3876 int hi_reg;
3877 int i;
3878 unsigned mask = 0;
3879 valueT op;
b99bd4ef 3880
c19d1205
ZW
3881 if (*input_line_pointer == '{')
3882 input_line_pointer++;
b99bd4ef 3883
c19d1205 3884 do
b99bd4ef 3885 {
dcbf9037 3886 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3887
c19d1205 3888 if (reg == FAIL)
b99bd4ef 3889 {
9b7132d3 3890 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3891 goto error;
b99bd4ef
NC
3892 }
3893
c19d1205
ZW
3894 if (mask >> reg)
3895 as_tsktsk (_("register list not in ascending order"));
3896 mask |= 1 << reg;
b99bd4ef 3897
c19d1205
ZW
3898 if (*input_line_pointer == '-')
3899 {
3900 input_line_pointer++;
dcbf9037 3901 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3902 if (hi_reg == FAIL)
3903 {
9b7132d3 3904 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3905 goto error;
3906 }
3907 else if (reg >= hi_reg)
3908 {
3909 as_bad (_("bad register range"));
3910 goto error;
3911 }
3912 for (; reg < hi_reg; reg++)
3913 mask |= 1 << reg;
3914 }
3915 }
3916 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3917
c19d1205
ZW
3918 if (*input_line_pointer == '}')
3919 input_line_pointer++;
b99bd4ef 3920
c19d1205 3921 demand_empty_rest_of_line ();
b99bd4ef 3922
708587a4 3923 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3924 the list. */
3925 flush_pending_unwind ();
b99bd4ef 3926
c19d1205 3927 for (i = 0; i < 16; i++)
b99bd4ef 3928 {
c19d1205
ZW
3929 if (mask & (1 << i))
3930 unwind.frame_size += 8;
b99bd4ef
NC
3931 }
3932
c19d1205
ZW
3933 /* Attempt to combine with a previous opcode. We do this because gcc
3934 likes to output separate unwind directives for a single block of
3935 registers. */
3936 if (unwind.opcode_count > 0)
b99bd4ef 3937 {
c19d1205
ZW
3938 i = unwind.opcodes[unwind.opcode_count - 1];
3939 if ((i & 0xf8) == 0xc0)
3940 {
3941 i &= 7;
3942 /* Only merge if the blocks are contiguous. */
3943 if (i < 6)
3944 {
3945 if ((mask & 0xfe00) == (1 << 9))
3946 {
3947 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3948 unwind.opcode_count--;
3949 }
3950 }
3951 else if (i == 6 && unwind.opcode_count >= 2)
3952 {
3953 i = unwind.opcodes[unwind.opcode_count - 2];
3954 reg = i >> 4;
3955 i &= 0xf;
b99bd4ef 3956
c19d1205
ZW
3957 op = 0xffff << (reg - 1);
3958 if (reg > 0
87a1fd79 3959 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3960 {
3961 op = (1 << (reg + i + 1)) - 1;
3962 op &= ~((1 << reg) - 1);
3963 mask |= op;
3964 unwind.opcode_count -= 2;
3965 }
3966 }
3967 }
b99bd4ef
NC
3968 }
3969
c19d1205
ZW
3970 hi_reg = 15;
3971 /* We want to generate opcodes in the order the registers have been
3972 saved, ie. descending order. */
3973 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3974 {
c19d1205
ZW
3975 /* Save registers in blocks. */
3976 if (reg < 0
3977 || !(mask & (1 << reg)))
3978 {
3979 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3980 preceding block. */
c19d1205
ZW
3981 if (reg != hi_reg)
3982 {
3983 if (reg == 9)
3984 {
3985 /* Short form. */
3986 op = 0xc0 | (hi_reg - 10);
3987 add_unwind_opcode (op, 1);
3988 }
3989 else
3990 {
3991 /* Long form. */
3992 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3993 add_unwind_opcode (op, 2);
3994 }
3995 }
3996 hi_reg = reg - 1;
3997 }
b99bd4ef
NC
3998 }
3999
c19d1205
ZW
4000 return;
4001error:
4002 ignore_rest_of_line ();
b99bd4ef
NC
4003}
4004
4005static void
c19d1205 4006s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4007{
c19d1205
ZW
4008 int reg;
4009 int hi_reg;
4010 unsigned mask = 0;
4011 valueT op;
b99bd4ef 4012
c19d1205
ZW
4013 if (*input_line_pointer == '{')
4014 input_line_pointer++;
b99bd4ef 4015
c19d1205 4016 do
b99bd4ef 4017 {
dcbf9037 4018 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4019
c19d1205
ZW
4020 if (reg == FAIL)
4021 {
9b7132d3 4022 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4023 goto error;
4024 }
b99bd4ef 4025
c19d1205
ZW
4026 reg -= 8;
4027 if (mask >> reg)
4028 as_tsktsk (_("register list not in ascending order"));
4029 mask |= 1 << reg;
b99bd4ef 4030
c19d1205
ZW
4031 if (*input_line_pointer == '-')
4032 {
4033 input_line_pointer++;
dcbf9037 4034 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4035 if (hi_reg == FAIL)
4036 {
9b7132d3 4037 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4038 goto error;
4039 }
4040 else if (reg >= hi_reg)
4041 {
4042 as_bad (_("bad register range"));
4043 goto error;
4044 }
4045 for (; reg < hi_reg; reg++)
4046 mask |= 1 << reg;
4047 }
b99bd4ef 4048 }
c19d1205 4049 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4050
c19d1205
ZW
4051 if (*input_line_pointer == '}')
4052 input_line_pointer++;
b99bd4ef 4053
c19d1205
ZW
4054 demand_empty_rest_of_line ();
4055
708587a4 4056 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4057 the list. */
4058 flush_pending_unwind ();
b99bd4ef 4059
c19d1205 4060 for (reg = 0; reg < 16; reg++)
b99bd4ef 4061 {
c19d1205
ZW
4062 if (mask & (1 << reg))
4063 unwind.frame_size += 4;
b99bd4ef 4064 }
c19d1205
ZW
4065 op = 0xc700 | mask;
4066 add_unwind_opcode (op, 2);
4067 return;
4068error:
4069 ignore_rest_of_line ();
b99bd4ef
NC
4070}
4071
c19d1205 4072
fa073d69
MS
4073/* Parse an unwind_save directive.
4074 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4075
b99bd4ef 4076static void
fa073d69 4077s_arm_unwind_save (int arch_v6)
b99bd4ef 4078{
c19d1205
ZW
4079 char *peek;
4080 struct reg_entry *reg;
4081 bfd_boolean had_brace = FALSE;
b99bd4ef 4082
921e5f0a 4083 if (!unwind.proc_start)
c921be7d 4084 as_bad (MISSING_FNSTART);
921e5f0a 4085
c19d1205
ZW
4086 /* Figure out what sort of save we have. */
4087 peek = input_line_pointer;
b99bd4ef 4088
c19d1205 4089 if (*peek == '{')
b99bd4ef 4090 {
c19d1205
ZW
4091 had_brace = TRUE;
4092 peek++;
b99bd4ef
NC
4093 }
4094
c19d1205 4095 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4096
c19d1205 4097 if (!reg)
b99bd4ef 4098 {
c19d1205
ZW
4099 as_bad (_("register expected"));
4100 ignore_rest_of_line ();
b99bd4ef
NC
4101 return;
4102 }
4103
c19d1205 4104 switch (reg->type)
b99bd4ef 4105 {
c19d1205
ZW
4106 case REG_TYPE_FN:
4107 if (had_brace)
4108 {
4109 as_bad (_("FPA .unwind_save does not take a register list"));
4110 ignore_rest_of_line ();
4111 return;
4112 }
93ac2687 4113 input_line_pointer = peek;
c19d1205 4114 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4115 return;
c19d1205
ZW
4116
4117 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
4118 case REG_TYPE_VFD:
4119 if (arch_v6)
4120 s_arm_unwind_save_vfp_armv6 ();
4121 else
4122 s_arm_unwind_save_vfp ();
4123 return;
c19d1205
ZW
4124 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4125 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4126
4127 default:
4128 as_bad (_(".unwind_save does not support this kind of register"));
4129 ignore_rest_of_line ();
b99bd4ef 4130 }
c19d1205 4131}
b99bd4ef 4132
b99bd4ef 4133
c19d1205
ZW
4134/* Parse an unwind_movsp directive. */
4135
4136static void
4137s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4138{
4139 int reg;
4140 valueT op;
4fa3602b 4141 int offset;
c19d1205 4142
921e5f0a 4143 if (!unwind.proc_start)
c921be7d 4144 as_bad (MISSING_FNSTART);
921e5f0a 4145
dcbf9037 4146 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4147 if (reg == FAIL)
b99bd4ef 4148 {
9b7132d3 4149 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4150 ignore_rest_of_line ();
b99bd4ef
NC
4151 return;
4152 }
4fa3602b
PB
4153
4154 /* Optional constant. */
4155 if (skip_past_comma (&input_line_pointer) != FAIL)
4156 {
4157 if (immediate_for_directive (&offset) == FAIL)
4158 return;
4159 }
4160 else
4161 offset = 0;
4162
c19d1205 4163 demand_empty_rest_of_line ();
b99bd4ef 4164
c19d1205 4165 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4166 {
c19d1205 4167 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4168 return;
4169 }
4170
c19d1205
ZW
4171 if (unwind.fp_reg != REG_SP)
4172 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4173
c19d1205
ZW
4174 /* Generate opcode to restore the value. */
4175 op = 0x90 | reg;
4176 add_unwind_opcode (op, 1);
4177
4178 /* Record the information for later. */
4179 unwind.fp_reg = reg;
4fa3602b 4180 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4181 unwind.sp_restored = 1;
b05fe5cf
ZW
4182}
4183
c19d1205
ZW
4184/* Parse an unwind_pad directive. */
4185
b05fe5cf 4186static void
c19d1205 4187s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4188{
c19d1205 4189 int offset;
b05fe5cf 4190
921e5f0a 4191 if (!unwind.proc_start)
c921be7d 4192 as_bad (MISSING_FNSTART);
921e5f0a 4193
c19d1205
ZW
4194 if (immediate_for_directive (&offset) == FAIL)
4195 return;
b99bd4ef 4196
c19d1205
ZW
4197 if (offset & 3)
4198 {
4199 as_bad (_("stack increment must be multiple of 4"));
4200 ignore_rest_of_line ();
4201 return;
4202 }
b99bd4ef 4203
c19d1205
ZW
4204 /* Don't generate any opcodes, just record the details for later. */
4205 unwind.frame_size += offset;
4206 unwind.pending_offset += offset;
4207
4208 demand_empty_rest_of_line ();
4209}
4210
4211/* Parse an unwind_setfp directive. */
4212
4213static void
4214s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4215{
c19d1205
ZW
4216 int sp_reg;
4217 int fp_reg;
4218 int offset;
4219
921e5f0a 4220 if (!unwind.proc_start)
c921be7d 4221 as_bad (MISSING_FNSTART);
921e5f0a 4222
dcbf9037 4223 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4224 if (skip_past_comma (&input_line_pointer) == FAIL)
4225 sp_reg = FAIL;
4226 else
dcbf9037 4227 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4228
c19d1205
ZW
4229 if (fp_reg == FAIL || sp_reg == FAIL)
4230 {
4231 as_bad (_("expected <reg>, <reg>"));
4232 ignore_rest_of_line ();
4233 return;
4234 }
b99bd4ef 4235
c19d1205
ZW
4236 /* Optional constant. */
4237 if (skip_past_comma (&input_line_pointer) != FAIL)
4238 {
4239 if (immediate_for_directive (&offset) == FAIL)
4240 return;
4241 }
4242 else
4243 offset = 0;
a737bd4d 4244
c19d1205 4245 demand_empty_rest_of_line ();
a737bd4d 4246
fdfde340 4247 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4248 {
c19d1205
ZW
4249 as_bad (_("register must be either sp or set by a previous"
4250 "unwind_movsp directive"));
4251 return;
a737bd4d
NC
4252 }
4253
c19d1205
ZW
4254 /* Don't generate any opcodes, just record the information for later. */
4255 unwind.fp_reg = fp_reg;
4256 unwind.fp_used = 1;
fdfde340 4257 if (sp_reg == REG_SP)
c19d1205
ZW
4258 unwind.fp_offset = unwind.frame_size - offset;
4259 else
4260 unwind.fp_offset -= offset;
a737bd4d
NC
4261}
4262
c19d1205
ZW
4263/* Parse an unwind_raw directive. */
4264
4265static void
4266s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4267{
c19d1205 4268 expressionS exp;
708587a4 4269 /* This is an arbitrary limit. */
c19d1205
ZW
4270 unsigned char op[16];
4271 int count;
a737bd4d 4272
921e5f0a 4273 if (!unwind.proc_start)
c921be7d 4274 as_bad (MISSING_FNSTART);
921e5f0a 4275
c19d1205
ZW
4276 expression (&exp);
4277 if (exp.X_op == O_constant
4278 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4279 {
c19d1205
ZW
4280 unwind.frame_size += exp.X_add_number;
4281 expression (&exp);
4282 }
4283 else
4284 exp.X_op = O_illegal;
a737bd4d 4285
c19d1205
ZW
4286 if (exp.X_op != O_constant)
4287 {
4288 as_bad (_("expected <offset>, <opcode>"));
4289 ignore_rest_of_line ();
4290 return;
4291 }
a737bd4d 4292
c19d1205 4293 count = 0;
a737bd4d 4294
c19d1205
ZW
4295 /* Parse the opcode. */
4296 for (;;)
4297 {
4298 if (count >= 16)
4299 {
4300 as_bad (_("unwind opcode too long"));
4301 ignore_rest_of_line ();
a737bd4d 4302 }
c19d1205 4303 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4304 {
c19d1205
ZW
4305 as_bad (_("invalid unwind opcode"));
4306 ignore_rest_of_line ();
4307 return;
a737bd4d 4308 }
c19d1205 4309 op[count++] = exp.X_add_number;
a737bd4d 4310
c19d1205
ZW
4311 /* Parse the next byte. */
4312 if (skip_past_comma (&input_line_pointer) == FAIL)
4313 break;
a737bd4d 4314
c19d1205
ZW
4315 expression (&exp);
4316 }
b99bd4ef 4317
c19d1205
ZW
4318 /* Add the opcode bytes in reverse order. */
4319 while (count--)
4320 add_unwind_opcode (op[count], 1);
b99bd4ef 4321
c19d1205 4322 demand_empty_rest_of_line ();
b99bd4ef 4323}
ee065d83
PB
4324
4325
4326/* Parse a .eabi_attribute directive. */
4327
4328static void
4329s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4330{
ee3c0378
AS
4331 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4332
4333 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4334 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4335}
4336
0855e32b
NS
4337/* Emit a tls fix for the symbol. */
4338
4339static void
4340s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4341{
4342 char *p;
4343 expressionS exp;
4344#ifdef md_flush_pending_output
4345 md_flush_pending_output ();
4346#endif
4347
4348#ifdef md_cons_align
4349 md_cons_align (4);
4350#endif
4351
4352 /* Since we're just labelling the code, there's no need to define a
4353 mapping symbol. */
4354 expression (&exp);
4355 p = obstack_next_free (&frchain_now->frch_obstack);
4356 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4357 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4358 : BFD_RELOC_ARM_TLS_DESCSEQ);
4359}
cdf9ccec 4360#endif /* OBJ_ELF */
0855e32b 4361
ee065d83 4362static void s_arm_arch (int);
7a1d4c38 4363static void s_arm_object_arch (int);
ee065d83
PB
4364static void s_arm_cpu (int);
4365static void s_arm_fpu (int);
69133863 4366static void s_arm_arch_extension (int);
b99bd4ef 4367
f0927246
NC
4368#ifdef TE_PE
4369
4370static void
5f4273c7 4371pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4372{
4373 expressionS exp;
4374
4375 do
4376 {
4377 expression (&exp);
4378 if (exp.X_op == O_symbol)
4379 exp.X_op = O_secrel;
4380
4381 emit_expr (&exp, 4);
4382 }
4383 while (*input_line_pointer++ == ',');
4384
4385 input_line_pointer--;
4386 demand_empty_rest_of_line ();
4387}
4388#endif /* TE_PE */
4389
c19d1205
ZW
4390/* This table describes all the machine specific pseudo-ops the assembler
4391 has to support. The fields are:
4392 pseudo-op name without dot
4393 function to call to execute this pseudo-op
4394 Integer arg to pass to the function. */
b99bd4ef 4395
c19d1205 4396const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4397{
c19d1205
ZW
4398 /* Never called because '.req' does not start a line. */
4399 { "req", s_req, 0 },
dcbf9037
JB
4400 /* Following two are likewise never called. */
4401 { "dn", s_dn, 0 },
4402 { "qn", s_qn, 0 },
c19d1205
ZW
4403 { "unreq", s_unreq, 0 },
4404 { "bss", s_bss, 0 },
4405 { "align", s_align, 0 },
4406 { "arm", s_arm, 0 },
4407 { "thumb", s_thumb, 0 },
4408 { "code", s_code, 0 },
4409 { "force_thumb", s_force_thumb, 0 },
4410 { "thumb_func", s_thumb_func, 0 },
4411 { "thumb_set", s_thumb_set, 0 },
4412 { "even", s_even, 0 },
4413 { "ltorg", s_ltorg, 0 },
4414 { "pool", s_ltorg, 0 },
4415 { "syntax", s_syntax, 0 },
8463be01
PB
4416 { "cpu", s_arm_cpu, 0 },
4417 { "arch", s_arm_arch, 0 },
7a1d4c38 4418 { "object_arch", s_arm_object_arch, 0 },
8463be01 4419 { "fpu", s_arm_fpu, 0 },
69133863 4420 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4421#ifdef OBJ_ELF
c921be7d
NC
4422 { "word", s_arm_elf_cons, 4 },
4423 { "long", s_arm_elf_cons, 4 },
4424 { "inst.n", s_arm_elf_inst, 2 },
4425 { "inst.w", s_arm_elf_inst, 4 },
4426 { "inst", s_arm_elf_inst, 0 },
4427 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4428 { "fnstart", s_arm_unwind_fnstart, 0 },
4429 { "fnend", s_arm_unwind_fnend, 0 },
4430 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4431 { "personality", s_arm_unwind_personality, 0 },
4432 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4433 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4434 { "save", s_arm_unwind_save, 0 },
fa073d69 4435 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4436 { "movsp", s_arm_unwind_movsp, 0 },
4437 { "pad", s_arm_unwind_pad, 0 },
4438 { "setfp", s_arm_unwind_setfp, 0 },
4439 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4440 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4441 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4442#else
4443 { "word", cons, 4},
f0927246
NC
4444
4445 /* These are used for dwarf. */
4446 {"2byte", cons, 2},
4447 {"4byte", cons, 4},
4448 {"8byte", cons, 8},
4449 /* These are used for dwarf2. */
4450 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4451 { "loc", dwarf2_directive_loc, 0 },
4452 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4453#endif
4454 { "extend", float_cons, 'x' },
4455 { "ldouble", float_cons, 'x' },
4456 { "packed", float_cons, 'p' },
f0927246
NC
4457#ifdef TE_PE
4458 {"secrel32", pe_directive_secrel, 0},
4459#endif
c19d1205
ZW
4460 { 0, 0, 0 }
4461};
4462\f
4463/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4464
c19d1205
ZW
4465/* Generic immediate-value read function for use in insn parsing.
4466 STR points to the beginning of the immediate (the leading #);
4467 VAL receives the value; if the value is outside [MIN, MAX]
4468 issue an error. PREFIX_OPT is true if the immediate prefix is
4469 optional. */
b99bd4ef 4470
c19d1205
ZW
4471static int
4472parse_immediate (char **str, int *val, int min, int max,
4473 bfd_boolean prefix_opt)
4474{
4475 expressionS exp;
4476 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4477 if (exp.X_op != O_constant)
b99bd4ef 4478 {
c19d1205
ZW
4479 inst.error = _("constant expression required");
4480 return FAIL;
4481 }
b99bd4ef 4482
c19d1205
ZW
4483 if (exp.X_add_number < min || exp.X_add_number > max)
4484 {
4485 inst.error = _("immediate value out of range");
4486 return FAIL;
4487 }
b99bd4ef 4488
c19d1205
ZW
4489 *val = exp.X_add_number;
4490 return SUCCESS;
4491}
b99bd4ef 4492
5287ad62 4493/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4494 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4495 instructions. Puts the result directly in inst.operands[i]. */
4496
4497static int
4498parse_big_immediate (char **str, int i)
4499{
4500 expressionS exp;
4501 char *ptr = *str;
4502
4503 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4504
4505 if (exp.X_op == O_constant)
036dc3f7
PB
4506 {
4507 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4508 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4509 O_constant. We have to be careful not to break compilation for
4510 32-bit X_add_number, though. */
58ad575f 4511 if ((exp.X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7
PB
4512 {
4513 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4514 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4515 inst.operands[i].regisimm = 1;
4516 }
4517 }
5287ad62 4518 else if (exp.X_op == O_big
95b75c01 4519 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
5287ad62
JB
4520 {
4521 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4522
5287ad62
JB
4523 /* Bignums have their least significant bits in
4524 generic_bignum[0]. Make sure we put 32 bits in imm and
4525 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4526 gas_assert (parts != 0);
95b75c01
NC
4527
4528 /* Make sure that the number is not too big.
4529 PR 11972: Bignums can now be sign-extended to the
4530 size of a .octa so check that the out of range bits
4531 are all zero or all one. */
4532 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4533 {
4534 LITTLENUM_TYPE m = -1;
4535
4536 if (generic_bignum[parts * 2] != 0
4537 && generic_bignum[parts * 2] != m)
4538 return FAIL;
4539
4540 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4541 if (generic_bignum[j] != generic_bignum[j-1])
4542 return FAIL;
4543 }
4544
5287ad62
JB
4545 inst.operands[i].imm = 0;
4546 for (j = 0; j < parts; j++, idx++)
4547 inst.operands[i].imm |= generic_bignum[idx]
4548 << (LITTLENUM_NUMBER_OF_BITS * j);
4549 inst.operands[i].reg = 0;
4550 for (j = 0; j < parts; j++, idx++)
4551 inst.operands[i].reg |= generic_bignum[idx]
4552 << (LITTLENUM_NUMBER_OF_BITS * j);
4553 inst.operands[i].regisimm = 1;
4554 }
4555 else
4556 return FAIL;
5f4273c7 4557
5287ad62
JB
4558 *str = ptr;
4559
4560 return SUCCESS;
4561}
4562
c19d1205
ZW
4563/* Returns the pseudo-register number of an FPA immediate constant,
4564 or FAIL if there isn't a valid constant here. */
b99bd4ef 4565
c19d1205
ZW
4566static int
4567parse_fpa_immediate (char ** str)
4568{
4569 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4570 char * save_in;
4571 expressionS exp;
4572 int i;
4573 int j;
b99bd4ef 4574
c19d1205
ZW
4575 /* First try and match exact strings, this is to guarantee
4576 that some formats will work even for cross assembly. */
b99bd4ef 4577
c19d1205
ZW
4578 for (i = 0; fp_const[i]; i++)
4579 {
4580 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4581 {
c19d1205 4582 char *start = *str;
b99bd4ef 4583
c19d1205
ZW
4584 *str += strlen (fp_const[i]);
4585 if (is_end_of_line[(unsigned char) **str])
4586 return i + 8;
4587 *str = start;
4588 }
4589 }
b99bd4ef 4590
c19d1205
ZW
4591 /* Just because we didn't get a match doesn't mean that the constant
4592 isn't valid, just that it is in a format that we don't
4593 automatically recognize. Try parsing it with the standard
4594 expression routines. */
b99bd4ef 4595
c19d1205 4596 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4597
c19d1205
ZW
4598 /* Look for a raw floating point number. */
4599 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4600 && is_end_of_line[(unsigned char) *save_in])
4601 {
4602 for (i = 0; i < NUM_FLOAT_VALS; i++)
4603 {
4604 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4605 {
c19d1205
ZW
4606 if (words[j] != fp_values[i][j])
4607 break;
b99bd4ef
NC
4608 }
4609
c19d1205 4610 if (j == MAX_LITTLENUMS)
b99bd4ef 4611 {
c19d1205
ZW
4612 *str = save_in;
4613 return i + 8;
b99bd4ef
NC
4614 }
4615 }
4616 }
b99bd4ef 4617
c19d1205
ZW
4618 /* Try and parse a more complex expression, this will probably fail
4619 unless the code uses a floating point prefix (eg "0f"). */
4620 save_in = input_line_pointer;
4621 input_line_pointer = *str;
4622 if (expression (&exp) == absolute_section
4623 && exp.X_op == O_big
4624 && exp.X_add_number < 0)
4625 {
4626 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4627 Ditto for 15. */
4628 if (gen_to_words (words, 5, (long) 15) == 0)
4629 {
4630 for (i = 0; i < NUM_FLOAT_VALS; i++)
4631 {
4632 for (j = 0; j < MAX_LITTLENUMS; j++)
4633 {
4634 if (words[j] != fp_values[i][j])
4635 break;
4636 }
b99bd4ef 4637
c19d1205
ZW
4638 if (j == MAX_LITTLENUMS)
4639 {
4640 *str = input_line_pointer;
4641 input_line_pointer = save_in;
4642 return i + 8;
4643 }
4644 }
4645 }
b99bd4ef
NC
4646 }
4647
c19d1205
ZW
4648 *str = input_line_pointer;
4649 input_line_pointer = save_in;
4650 inst.error = _("invalid FPA immediate expression");
4651 return FAIL;
b99bd4ef
NC
4652}
4653
136da414
JB
4654/* Returns 1 if a number has "quarter-precision" float format
4655 0baBbbbbbc defgh000 00000000 00000000. */
4656
4657static int
4658is_quarter_float (unsigned imm)
4659{
4660 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4661 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4662}
4663
4664/* Parse an 8-bit "quarter-precision" floating point number of the form:
4665 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4666 The zero and minus-zero cases need special handling, since they can't be
4667 encoded in the "quarter-precision" float format, but can nonetheless be
4668 loaded as integer constants. */
136da414
JB
4669
4670static unsigned
4671parse_qfloat_immediate (char **ccp, int *immed)
4672{
4673 char *str = *ccp;
c96612cc 4674 char *fpnum;
136da414 4675 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4676 int found_fpchar = 0;
5f4273c7 4677
136da414 4678 skip_past_char (&str, '#');
5f4273c7 4679
c96612cc
JB
4680 /* We must not accidentally parse an integer as a floating-point number. Make
4681 sure that the value we parse is not an integer by checking for special
4682 characters '.' or 'e'.
4683 FIXME: This is a horrible hack, but doing better is tricky because type
4684 information isn't in a very usable state at parse time. */
4685 fpnum = str;
4686 skip_whitespace (fpnum);
4687
4688 if (strncmp (fpnum, "0x", 2) == 0)
4689 return FAIL;
4690 else
4691 {
4692 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4693 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4694 {
4695 found_fpchar = 1;
4696 break;
4697 }
4698
4699 if (!found_fpchar)
4700 return FAIL;
4701 }
5f4273c7 4702
136da414
JB
4703 if ((str = atof_ieee (str, 's', words)) != NULL)
4704 {
4705 unsigned fpword = 0;
4706 int i;
5f4273c7 4707
136da414
JB
4708 /* Our FP word must be 32 bits (single-precision FP). */
4709 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4710 {
4711 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4712 fpword |= words[i];
4713 }
5f4273c7 4714
c96612cc 4715 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4716 *immed = fpword;
4717 else
4718 return FAIL;
4719
4720 *ccp = str;
5f4273c7 4721
136da414
JB
4722 return SUCCESS;
4723 }
5f4273c7 4724
136da414
JB
4725 return FAIL;
4726}
4727
c19d1205
ZW
4728/* Shift operands. */
4729enum shift_kind
b99bd4ef 4730{
c19d1205
ZW
4731 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4732};
b99bd4ef 4733
c19d1205
ZW
4734struct asm_shift_name
4735{
4736 const char *name;
4737 enum shift_kind kind;
4738};
b99bd4ef 4739
c19d1205
ZW
4740/* Third argument to parse_shift. */
4741enum parse_shift_mode
4742{
4743 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4744 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4745 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4746 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4747 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4748};
b99bd4ef 4749
c19d1205
ZW
4750/* Parse a <shift> specifier on an ARM data processing instruction.
4751 This has three forms:
b99bd4ef 4752
c19d1205
ZW
4753 (LSL|LSR|ASL|ASR|ROR) Rs
4754 (LSL|LSR|ASL|ASR|ROR) #imm
4755 RRX
b99bd4ef 4756
c19d1205
ZW
4757 Note that ASL is assimilated to LSL in the instruction encoding, and
4758 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4759
c19d1205
ZW
4760static int
4761parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4762{
c19d1205
ZW
4763 const struct asm_shift_name *shift_name;
4764 enum shift_kind shift;
4765 char *s = *str;
4766 char *p = s;
4767 int reg;
b99bd4ef 4768
c19d1205
ZW
4769 for (p = *str; ISALPHA (*p); p++)
4770 ;
b99bd4ef 4771
c19d1205 4772 if (p == *str)
b99bd4ef 4773 {
c19d1205
ZW
4774 inst.error = _("shift expression expected");
4775 return FAIL;
b99bd4ef
NC
4776 }
4777
21d799b5
NC
4778 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4779 p - *str);
c19d1205
ZW
4780
4781 if (shift_name == NULL)
b99bd4ef 4782 {
c19d1205
ZW
4783 inst.error = _("shift expression expected");
4784 return FAIL;
b99bd4ef
NC
4785 }
4786
c19d1205 4787 shift = shift_name->kind;
b99bd4ef 4788
c19d1205
ZW
4789 switch (mode)
4790 {
4791 case NO_SHIFT_RESTRICT:
4792 case SHIFT_IMMEDIATE: break;
b99bd4ef 4793
c19d1205
ZW
4794 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4795 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4796 {
4797 inst.error = _("'LSL' or 'ASR' required");
4798 return FAIL;
4799 }
4800 break;
b99bd4ef 4801
c19d1205
ZW
4802 case SHIFT_LSL_IMMEDIATE:
4803 if (shift != SHIFT_LSL)
4804 {
4805 inst.error = _("'LSL' required");
4806 return FAIL;
4807 }
4808 break;
b99bd4ef 4809
c19d1205
ZW
4810 case SHIFT_ASR_IMMEDIATE:
4811 if (shift != SHIFT_ASR)
4812 {
4813 inst.error = _("'ASR' required");
4814 return FAIL;
4815 }
4816 break;
b99bd4ef 4817
c19d1205
ZW
4818 default: abort ();
4819 }
b99bd4ef 4820
c19d1205
ZW
4821 if (shift != SHIFT_RRX)
4822 {
4823 /* Whitespace can appear here if the next thing is a bare digit. */
4824 skip_whitespace (p);
b99bd4ef 4825
c19d1205 4826 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4827 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4828 {
4829 inst.operands[i].imm = reg;
4830 inst.operands[i].immisreg = 1;
4831 }
4832 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4833 return FAIL;
4834 }
4835 inst.operands[i].shift_kind = shift;
4836 inst.operands[i].shifted = 1;
4837 *str = p;
4838 return SUCCESS;
b99bd4ef
NC
4839}
4840
c19d1205 4841/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4842
c19d1205
ZW
4843 #<immediate>
4844 #<immediate>, <rotate>
4845 <Rm>
4846 <Rm>, <shift>
b99bd4ef 4847
c19d1205
ZW
4848 where <shift> is defined by parse_shift above, and <rotate> is a
4849 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4850 is deferred to md_apply_fix. */
b99bd4ef 4851
c19d1205
ZW
4852static int
4853parse_shifter_operand (char **str, int i)
4854{
4855 int value;
91d6fa6a 4856 expressionS exp;
b99bd4ef 4857
dcbf9037 4858 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4859 {
4860 inst.operands[i].reg = value;
4861 inst.operands[i].isreg = 1;
b99bd4ef 4862
c19d1205
ZW
4863 /* parse_shift will override this if appropriate */
4864 inst.reloc.exp.X_op = O_constant;
4865 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4866
c19d1205
ZW
4867 if (skip_past_comma (str) == FAIL)
4868 return SUCCESS;
b99bd4ef 4869
c19d1205
ZW
4870 /* Shift operation on register. */
4871 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4872 }
4873
c19d1205
ZW
4874 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4875 return FAIL;
b99bd4ef 4876
c19d1205 4877 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4878 {
c19d1205 4879 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 4880 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 4881 return FAIL;
b99bd4ef 4882
91d6fa6a 4883 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
4884 {
4885 inst.error = _("constant expression expected");
4886 return FAIL;
4887 }
b99bd4ef 4888
91d6fa6a 4889 value = exp.X_add_number;
c19d1205
ZW
4890 if (value < 0 || value > 30 || value % 2 != 0)
4891 {
4892 inst.error = _("invalid rotation");
4893 return FAIL;
4894 }
4895 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4896 {
4897 inst.error = _("invalid constant");
4898 return FAIL;
4899 }
09d92015 4900
a415b1cd
JB
4901 /* Encode as specified. */
4902 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
4903 return SUCCESS;
09d92015
MM
4904 }
4905
c19d1205
ZW
4906 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4907 inst.reloc.pc_rel = 0;
4908 return SUCCESS;
09d92015
MM
4909}
4910
4962c51a
MS
4911/* Group relocation information. Each entry in the table contains the
4912 textual name of the relocation as may appear in assembler source
4913 and must end with a colon.
4914 Along with this textual name are the relocation codes to be used if
4915 the corresponding instruction is an ALU instruction (ADD or SUB only),
4916 an LDR, an LDRS, or an LDC. */
4917
4918struct group_reloc_table_entry
4919{
4920 const char *name;
4921 int alu_code;
4922 int ldr_code;
4923 int ldrs_code;
4924 int ldc_code;
4925};
4926
4927typedef enum
4928{
4929 /* Varieties of non-ALU group relocation. */
4930
4931 GROUP_LDR,
4932 GROUP_LDRS,
4933 GROUP_LDC
4934} group_reloc_type;
4935
4936static struct group_reloc_table_entry group_reloc_table[] =
4937 { /* Program counter relative: */
4938 { "pc_g0_nc",
4939 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4940 0, /* LDR */
4941 0, /* LDRS */
4942 0 }, /* LDC */
4943 { "pc_g0",
4944 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4945 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4946 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4947 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4948 { "pc_g1_nc",
4949 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4950 0, /* LDR */
4951 0, /* LDRS */
4952 0 }, /* LDC */
4953 { "pc_g1",
4954 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4955 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4956 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4957 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4958 { "pc_g2",
4959 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4960 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4961 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4962 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4963 /* Section base relative */
4964 { "sb_g0_nc",
4965 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4966 0, /* LDR */
4967 0, /* LDRS */
4968 0 }, /* LDC */
4969 { "sb_g0",
4970 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4971 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4972 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4973 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4974 { "sb_g1_nc",
4975 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4976 0, /* LDR */
4977 0, /* LDRS */
4978 0 }, /* LDC */
4979 { "sb_g1",
4980 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4981 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4982 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4983 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4984 { "sb_g2",
4985 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4986 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4987 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4988 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4989
4990/* Given the address of a pointer pointing to the textual name of a group
4991 relocation as may appear in assembler source, attempt to find its details
4992 in group_reloc_table. The pointer will be updated to the character after
4993 the trailing colon. On failure, FAIL will be returned; SUCCESS
4994 otherwise. On success, *entry will be updated to point at the relevant
4995 group_reloc_table entry. */
4996
4997static int
4998find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4999{
5000 unsigned int i;
5001 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5002 {
5003 int length = strlen (group_reloc_table[i].name);
5004
5f4273c7
NC
5005 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5006 && (*str)[length] == ':')
4962c51a
MS
5007 {
5008 *out = &group_reloc_table[i];
5009 *str += (length + 1);
5010 return SUCCESS;
5011 }
5012 }
5013
5014 return FAIL;
5015}
5016
5017/* Parse a <shifter_operand> for an ARM data processing instruction
5018 (as for parse_shifter_operand) where group relocations are allowed:
5019
5020 #<immediate>
5021 #<immediate>, <rotate>
5022 #:<group_reloc>:<expression>
5023 <Rm>
5024 <Rm>, <shift>
5025
5026 where <group_reloc> is one of the strings defined in group_reloc_table.
5027 The hashes are optional.
5028
5029 Everything else is as for parse_shifter_operand. */
5030
5031static parse_operand_result
5032parse_shifter_operand_group_reloc (char **str, int i)
5033{
5034 /* Determine if we have the sequence of characters #: or just :
5035 coming next. If we do, then we check for a group relocation.
5036 If we don't, punt the whole lot to parse_shifter_operand. */
5037
5038 if (((*str)[0] == '#' && (*str)[1] == ':')
5039 || (*str)[0] == ':')
5040 {
5041 struct group_reloc_table_entry *entry;
5042
5043 if ((*str)[0] == '#')
5044 (*str) += 2;
5045 else
5046 (*str)++;
5047
5048 /* Try to parse a group relocation. Anything else is an error. */
5049 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5050 {
5051 inst.error = _("unknown group relocation");
5052 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5053 }
5054
5055 /* We now have the group relocation table entry corresponding to
5056 the name in the assembler source. Next, we parse the expression. */
5057 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
5058 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5059
5060 /* Record the relocation type (always the ALU variant here). */
21d799b5 5061 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5062 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5063
5064 return PARSE_OPERAND_SUCCESS;
5065 }
5066 else
5067 return parse_shifter_operand (str, i) == SUCCESS
5068 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5069
5070 /* Never reached. */
5071}
5072
8e560766
MGD
5073/* Parse a Neon alignment expression. Information is written to
5074 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5075
8e560766
MGD
5076 align .imm = align << 8, .immisalign=1, .preind=0 */
5077static parse_operand_result
5078parse_neon_alignment (char **str, int i)
5079{
5080 char *p = *str;
5081 expressionS exp;
5082
5083 my_get_expression (&exp, &p, GE_NO_PREFIX);
5084
5085 if (exp.X_op != O_constant)
5086 {
5087 inst.error = _("alignment must be constant");
5088 return PARSE_OPERAND_FAIL;
5089 }
5090
5091 inst.operands[i].imm = exp.X_add_number << 8;
5092 inst.operands[i].immisalign = 1;
5093 /* Alignments are not pre-indexes. */
5094 inst.operands[i].preind = 0;
5095
5096 *str = p;
5097 return PARSE_OPERAND_SUCCESS;
5098}
5099
c19d1205
ZW
5100/* Parse all forms of an ARM address expression. Information is written
5101 to inst.operands[i] and/or inst.reloc.
09d92015 5102
c19d1205 5103 Preindexed addressing (.preind=1):
09d92015 5104
c19d1205
ZW
5105 [Rn, #offset] .reg=Rn .reloc.exp=offset
5106 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5107 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5108 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5109
c19d1205 5110 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5111
c19d1205 5112 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5113
c19d1205
ZW
5114 [Rn], #offset .reg=Rn .reloc.exp=offset
5115 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5116 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5117 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5118
c19d1205 5119 Unindexed addressing (.preind=0, .postind=0):
09d92015 5120
c19d1205 5121 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5122
c19d1205 5123 Other:
09d92015 5124
c19d1205
ZW
5125 [Rn]{!} shorthand for [Rn,#0]{!}
5126 =immediate .isreg=0 .reloc.exp=immediate
5127 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5128
c19d1205
ZW
5129 It is the caller's responsibility to check for addressing modes not
5130 supported by the instruction, and to set inst.reloc.type. */
5131
4962c51a
MS
5132static parse_operand_result
5133parse_address_main (char **str, int i, int group_relocations,
5134 group_reloc_type group_type)
09d92015 5135{
c19d1205
ZW
5136 char *p = *str;
5137 int reg;
09d92015 5138
c19d1205 5139 if (skip_past_char (&p, '[') == FAIL)
09d92015 5140 {
c19d1205
ZW
5141 if (skip_past_char (&p, '=') == FAIL)
5142 {
974da60d 5143 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5144 inst.reloc.pc_rel = 1;
5145 inst.operands[i].reg = REG_PC;
5146 inst.operands[i].isreg = 1;
5147 inst.operands[i].preind = 1;
5148 }
974da60d 5149 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
09d92015 5150
c19d1205 5151 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 5152 return PARSE_OPERAND_FAIL;
09d92015 5153
c19d1205 5154 *str = p;
4962c51a 5155 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5156 }
5157
dcbf9037 5158 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5159 {
c19d1205 5160 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5161 return PARSE_OPERAND_FAIL;
09d92015 5162 }
c19d1205
ZW
5163 inst.operands[i].reg = reg;
5164 inst.operands[i].isreg = 1;
09d92015 5165
c19d1205 5166 if (skip_past_comma (&p) == SUCCESS)
09d92015 5167 {
c19d1205 5168 inst.operands[i].preind = 1;
09d92015 5169
c19d1205
ZW
5170 if (*p == '+') p++;
5171 else if (*p == '-') p++, inst.operands[i].negative = 1;
5172
dcbf9037 5173 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5174 {
c19d1205
ZW
5175 inst.operands[i].imm = reg;
5176 inst.operands[i].immisreg = 1;
5177
5178 if (skip_past_comma (&p) == SUCCESS)
5179 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5180 return PARSE_OPERAND_FAIL;
c19d1205 5181 }
5287ad62 5182 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5183 {
5184 /* FIXME: '@' should be used here, but it's filtered out by generic
5185 code before we get to see it here. This may be subject to
5186 change. */
5187 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5188
8e560766
MGD
5189 if (result != PARSE_OPERAND_SUCCESS)
5190 return result;
5191 }
c19d1205
ZW
5192 else
5193 {
5194 if (inst.operands[i].negative)
5195 {
5196 inst.operands[i].negative = 0;
5197 p--;
5198 }
4962c51a 5199
5f4273c7
NC
5200 if (group_relocations
5201 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5202 {
5203 struct group_reloc_table_entry *entry;
5204
5205 /* Skip over the #: or : sequence. */
5206 if (*p == '#')
5207 p += 2;
5208 else
5209 p++;
5210
5211 /* Try to parse a group relocation. Anything else is an
5212 error. */
5213 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5214 {
5215 inst.error = _("unknown group relocation");
5216 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5217 }
5218
5219 /* We now have the group relocation table entry corresponding to
5220 the name in the assembler source. Next, we parse the
5221 expression. */
5222 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5223 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5224
5225 /* Record the relocation type. */
5226 switch (group_type)
5227 {
5228 case GROUP_LDR:
21d799b5 5229 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
4962c51a
MS
5230 break;
5231
5232 case GROUP_LDRS:
21d799b5 5233 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
4962c51a
MS
5234 break;
5235
5236 case GROUP_LDC:
21d799b5 5237 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
4962c51a
MS
5238 break;
5239
5240 default:
9c2799c2 5241 gas_assert (0);
4962c51a
MS
5242 }
5243
5244 if (inst.reloc.type == 0)
5245 {
5246 inst.error = _("this group relocation is not allowed on this instruction");
5247 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5248 }
5249 }
5250 else
26d97720
NS
5251 {
5252 char *q = p;
5253 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5254 return PARSE_OPERAND_FAIL;
5255 /* If the offset is 0, find out if it's a +0 or -0. */
5256 if (inst.reloc.exp.X_op == O_constant
5257 && inst.reloc.exp.X_add_number == 0)
5258 {
5259 skip_whitespace (q);
5260 if (*q == '#')
5261 {
5262 q++;
5263 skip_whitespace (q);
5264 }
5265 if (*q == '-')
5266 inst.operands[i].negative = 1;
5267 }
5268 }
09d92015
MM
5269 }
5270 }
8e560766
MGD
5271 else if (skip_past_char (&p, ':') == SUCCESS)
5272 {
5273 /* FIXME: '@' should be used here, but it's filtered out by generic code
5274 before we get to see it here. This may be subject to change. */
5275 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5276
8e560766
MGD
5277 if (result != PARSE_OPERAND_SUCCESS)
5278 return result;
5279 }
09d92015 5280
c19d1205 5281 if (skip_past_char (&p, ']') == FAIL)
09d92015 5282 {
c19d1205 5283 inst.error = _("']' expected");
4962c51a 5284 return PARSE_OPERAND_FAIL;
09d92015
MM
5285 }
5286
c19d1205
ZW
5287 if (skip_past_char (&p, '!') == SUCCESS)
5288 inst.operands[i].writeback = 1;
09d92015 5289
c19d1205 5290 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5291 {
c19d1205
ZW
5292 if (skip_past_char (&p, '{') == SUCCESS)
5293 {
5294 /* [Rn], {expr} - unindexed, with option */
5295 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5296 0, 255, TRUE) == FAIL)
4962c51a 5297 return PARSE_OPERAND_FAIL;
09d92015 5298
c19d1205
ZW
5299 if (skip_past_char (&p, '}') == FAIL)
5300 {
5301 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5302 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5303 }
5304 if (inst.operands[i].preind)
5305 {
5306 inst.error = _("cannot combine index with option");
4962c51a 5307 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5308 }
5309 *str = p;
4962c51a 5310 return PARSE_OPERAND_SUCCESS;
09d92015 5311 }
c19d1205
ZW
5312 else
5313 {
5314 inst.operands[i].postind = 1;
5315 inst.operands[i].writeback = 1;
09d92015 5316
c19d1205
ZW
5317 if (inst.operands[i].preind)
5318 {
5319 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5320 return PARSE_OPERAND_FAIL;
c19d1205 5321 }
09d92015 5322
c19d1205
ZW
5323 if (*p == '+') p++;
5324 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5325
dcbf9037 5326 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5327 {
5287ad62
JB
5328 /* We might be using the immediate for alignment already. If we
5329 are, OR the register number into the low-order bits. */
5330 if (inst.operands[i].immisalign)
5331 inst.operands[i].imm |= reg;
5332 else
5333 inst.operands[i].imm = reg;
c19d1205 5334 inst.operands[i].immisreg = 1;
a737bd4d 5335
c19d1205
ZW
5336 if (skip_past_comma (&p) == SUCCESS)
5337 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5338 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5339 }
5340 else
5341 {
26d97720 5342 char *q = p;
c19d1205
ZW
5343 if (inst.operands[i].negative)
5344 {
5345 inst.operands[i].negative = 0;
5346 p--;
5347 }
5348 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5349 return PARSE_OPERAND_FAIL;
26d97720
NS
5350 /* If the offset is 0, find out if it's a +0 or -0. */
5351 if (inst.reloc.exp.X_op == O_constant
5352 && inst.reloc.exp.X_add_number == 0)
5353 {
5354 skip_whitespace (q);
5355 if (*q == '#')
5356 {
5357 q++;
5358 skip_whitespace (q);
5359 }
5360 if (*q == '-')
5361 inst.operands[i].negative = 1;
5362 }
c19d1205
ZW
5363 }
5364 }
a737bd4d
NC
5365 }
5366
c19d1205
ZW
5367 /* If at this point neither .preind nor .postind is set, we have a
5368 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5369 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5370 {
5371 inst.operands[i].preind = 1;
5372 inst.reloc.exp.X_op = O_constant;
5373 inst.reloc.exp.X_add_number = 0;
5374 }
5375 *str = p;
4962c51a
MS
5376 return PARSE_OPERAND_SUCCESS;
5377}
5378
5379static int
5380parse_address (char **str, int i)
5381{
21d799b5 5382 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
4962c51a
MS
5383 ? SUCCESS : FAIL;
5384}
5385
5386static parse_operand_result
5387parse_address_group_reloc (char **str, int i, group_reloc_type type)
5388{
5389 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5390}
5391
b6895b4f
PB
5392/* Parse an operand for a MOVW or MOVT instruction. */
5393static int
5394parse_half (char **str)
5395{
5396 char * p;
5f4273c7 5397
b6895b4f
PB
5398 p = *str;
5399 skip_past_char (&p, '#');
5f4273c7 5400 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5401 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5402 else if (strncasecmp (p, ":upper16:", 9) == 0)
5403 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5404
5405 if (inst.reloc.type != BFD_RELOC_UNUSED)
5406 {
5407 p += 9;
5f4273c7 5408 skip_whitespace (p);
b6895b4f
PB
5409 }
5410
5411 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5412 return FAIL;
5413
5414 if (inst.reloc.type == BFD_RELOC_UNUSED)
5415 {
5416 if (inst.reloc.exp.X_op != O_constant)
5417 {
5418 inst.error = _("constant expression expected");
5419 return FAIL;
5420 }
5421 if (inst.reloc.exp.X_add_number < 0
5422 || inst.reloc.exp.X_add_number > 0xffff)
5423 {
5424 inst.error = _("immediate value out of range");
5425 return FAIL;
5426 }
5427 }
5428 *str = p;
5429 return SUCCESS;
5430}
5431
c19d1205 5432/* Miscellaneous. */
a737bd4d 5433
c19d1205
ZW
5434/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5435 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5436static int
d2cd1205 5437parse_psr (char **str, bfd_boolean lhs)
09d92015 5438{
c19d1205
ZW
5439 char *p;
5440 unsigned long psr_field;
62b3e311
PB
5441 const struct asm_psr *psr;
5442 char *start;
d2cd1205 5443 bfd_boolean is_apsr = FALSE;
ac7f631b 5444 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5445
a4482bb6
NC
5446 /* PR gas/12698: If the user has specified -march=all then m_profile will
5447 be TRUE, but we want to ignore it in this case as we are building for any
5448 CPU type, including non-m variants. */
5449 if (selected_cpu.core == arm_arch_any.core)
5450 m_profile = FALSE;
5451
c19d1205
ZW
5452 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5453 feature for ease of use and backwards compatibility. */
5454 p = *str;
62b3e311 5455 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5456 {
5457 if (m_profile)
5458 goto unsupported_psr;
fa94de6b 5459
d2cd1205
JB
5460 psr_field = SPSR_BIT;
5461 }
5462 else if (strncasecmp (p, "CPSR", 4) == 0)
5463 {
5464 if (m_profile)
5465 goto unsupported_psr;
5466
5467 psr_field = 0;
5468 }
5469 else if (strncasecmp (p, "APSR", 4) == 0)
5470 {
5471 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5472 and ARMv7-R architecture CPUs. */
5473 is_apsr = TRUE;
5474 psr_field = 0;
5475 }
5476 else if (m_profile)
62b3e311
PB
5477 {
5478 start = p;
5479 do
5480 p++;
5481 while (ISALNUM (*p) || *p == '_');
5482
d2cd1205
JB
5483 if (strncasecmp (start, "iapsr", 5) == 0
5484 || strncasecmp (start, "eapsr", 5) == 0
5485 || strncasecmp (start, "xpsr", 4) == 0
5486 || strncasecmp (start, "psr", 3) == 0)
5487 p = start + strcspn (start, "rR") + 1;
5488
21d799b5
NC
5489 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5490 p - start);
d2cd1205 5491
62b3e311
PB
5492 if (!psr)
5493 return FAIL;
09d92015 5494
d2cd1205
JB
5495 /* If APSR is being written, a bitfield may be specified. Note that
5496 APSR itself is handled above. */
5497 if (psr->field <= 3)
5498 {
5499 psr_field = psr->field;
5500 is_apsr = TRUE;
5501 goto check_suffix;
5502 }
5503
62b3e311 5504 *str = p;
d2cd1205
JB
5505 /* M-profile MSR instructions have the mask field set to "10", except
5506 *PSR variants which modify APSR, which may use a different mask (and
5507 have been handled already). Do that by setting the PSR_f field
5508 here. */
5509 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5510 }
d2cd1205
JB
5511 else
5512 goto unsupported_psr;
09d92015 5513
62b3e311 5514 p += 4;
d2cd1205 5515check_suffix:
c19d1205
ZW
5516 if (*p == '_')
5517 {
5518 /* A suffix follows. */
c19d1205
ZW
5519 p++;
5520 start = p;
a737bd4d 5521
c19d1205
ZW
5522 do
5523 p++;
5524 while (ISALNUM (*p) || *p == '_');
a737bd4d 5525
d2cd1205
JB
5526 if (is_apsr)
5527 {
5528 /* APSR uses a notation for bits, rather than fields. */
5529 unsigned int nzcvq_bits = 0;
5530 unsigned int g_bit = 0;
5531 char *bit;
fa94de6b 5532
d2cd1205
JB
5533 for (bit = start; bit != p; bit++)
5534 {
5535 switch (TOLOWER (*bit))
5536 {
5537 case 'n':
5538 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5539 break;
5540
5541 case 'z':
5542 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5543 break;
5544
5545 case 'c':
5546 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5547 break;
5548
5549 case 'v':
5550 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5551 break;
fa94de6b 5552
d2cd1205
JB
5553 case 'q':
5554 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5555 break;
fa94de6b 5556
d2cd1205
JB
5557 case 'g':
5558 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5559 break;
fa94de6b 5560
d2cd1205
JB
5561 default:
5562 inst.error = _("unexpected bit specified after APSR");
5563 return FAIL;
5564 }
5565 }
fa94de6b 5566
d2cd1205
JB
5567 if (nzcvq_bits == 0x1f)
5568 psr_field |= PSR_f;
fa94de6b 5569
d2cd1205
JB
5570 if (g_bit == 0x1)
5571 {
5572 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
5573 {
5574 inst.error = _("selected processor does not "
5575 "support DSP extension");
5576 return FAIL;
5577 }
5578
5579 psr_field |= PSR_s;
5580 }
fa94de6b 5581
d2cd1205
JB
5582 if ((nzcvq_bits & 0x20) != 0
5583 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5584 || (g_bit & 0x2) != 0)
5585 {
5586 inst.error = _("bad bitmask specified after APSR");
5587 return FAIL;
5588 }
5589 }
5590 else
5591 {
5592 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5593 p - start);
5594 if (!psr)
5595 goto error;
a737bd4d 5596
d2cd1205
JB
5597 psr_field |= psr->field;
5598 }
a737bd4d 5599 }
c19d1205 5600 else
a737bd4d 5601 {
c19d1205
ZW
5602 if (ISALNUM (*p))
5603 goto error; /* Garbage after "[CS]PSR". */
5604
d2cd1205
JB
5605 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
5606 is deprecated, but allow it anyway. */
5607 if (is_apsr && lhs)
5608 {
5609 psr_field |= PSR_f;
5610 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5611 "deprecated"));
5612 }
5613 else if (!m_profile)
5614 /* These bits are never right for M-profile devices: don't set them
5615 (only code paths which read/write APSR reach here). */
5616 psr_field |= (PSR_c | PSR_f);
a737bd4d 5617 }
c19d1205
ZW
5618 *str = p;
5619 return psr_field;
a737bd4d 5620
d2cd1205
JB
5621 unsupported_psr:
5622 inst.error = _("selected processor does not support requested special "
5623 "purpose register");
5624 return FAIL;
5625
c19d1205
ZW
5626 error:
5627 inst.error = _("flag for {c}psr instruction expected");
5628 return FAIL;
a737bd4d
NC
5629}
5630
c19d1205
ZW
5631/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5632 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5633
c19d1205
ZW
5634static int
5635parse_cps_flags (char **str)
a737bd4d 5636{
c19d1205
ZW
5637 int val = 0;
5638 int saw_a_flag = 0;
5639 char *s = *str;
a737bd4d 5640
c19d1205
ZW
5641 for (;;)
5642 switch (*s++)
5643 {
5644 case '\0': case ',':
5645 goto done;
a737bd4d 5646
c19d1205
ZW
5647 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5648 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5649 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5650
c19d1205
ZW
5651 default:
5652 inst.error = _("unrecognized CPS flag");
5653 return FAIL;
5654 }
a737bd4d 5655
c19d1205
ZW
5656 done:
5657 if (saw_a_flag == 0)
a737bd4d 5658 {
c19d1205
ZW
5659 inst.error = _("missing CPS flags");
5660 return FAIL;
a737bd4d 5661 }
a737bd4d 5662
c19d1205
ZW
5663 *str = s - 1;
5664 return val;
a737bd4d
NC
5665}
5666
c19d1205
ZW
5667/* Parse an endian specifier ("BE" or "LE", case insensitive);
5668 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5669
5670static int
c19d1205 5671parse_endian_specifier (char **str)
a737bd4d 5672{
c19d1205
ZW
5673 int little_endian;
5674 char *s = *str;
a737bd4d 5675
c19d1205
ZW
5676 if (strncasecmp (s, "BE", 2))
5677 little_endian = 0;
5678 else if (strncasecmp (s, "LE", 2))
5679 little_endian = 1;
5680 else
a737bd4d 5681 {
c19d1205 5682 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5683 return FAIL;
5684 }
5685
c19d1205 5686 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5687 {
c19d1205 5688 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5689 return FAIL;
5690 }
5691
c19d1205
ZW
5692 *str = s + 2;
5693 return little_endian;
5694}
a737bd4d 5695
c19d1205
ZW
5696/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5697 value suitable for poking into the rotate field of an sxt or sxta
5698 instruction, or FAIL on error. */
5699
5700static int
5701parse_ror (char **str)
5702{
5703 int rot;
5704 char *s = *str;
5705
5706 if (strncasecmp (s, "ROR", 3) == 0)
5707 s += 3;
5708 else
a737bd4d 5709 {
c19d1205 5710 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5711 return FAIL;
5712 }
c19d1205
ZW
5713
5714 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5715 return FAIL;
5716
5717 switch (rot)
a737bd4d 5718 {
c19d1205
ZW
5719 case 0: *str = s; return 0x0;
5720 case 8: *str = s; return 0x1;
5721 case 16: *str = s; return 0x2;
5722 case 24: *str = s; return 0x3;
5723
5724 default:
5725 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5726 return FAIL;
5727 }
c19d1205 5728}
a737bd4d 5729
c19d1205
ZW
5730/* Parse a conditional code (from conds[] below). The value returned is in the
5731 range 0 .. 14, or FAIL. */
5732static int
5733parse_cond (char **str)
5734{
c462b453 5735 char *q;
c19d1205 5736 const struct asm_cond *c;
c462b453
PB
5737 int n;
5738 /* Condition codes are always 2 characters, so matching up to
5739 3 characters is sufficient. */
5740 char cond[3];
a737bd4d 5741
c462b453
PB
5742 q = *str;
5743 n = 0;
5744 while (ISALPHA (*q) && n < 3)
5745 {
e07e6e58 5746 cond[n] = TOLOWER (*q);
c462b453
PB
5747 q++;
5748 n++;
5749 }
a737bd4d 5750
21d799b5 5751 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5752 if (!c)
a737bd4d 5753 {
c19d1205 5754 inst.error = _("condition required");
a737bd4d
NC
5755 return FAIL;
5756 }
5757
c19d1205
ZW
5758 *str = q;
5759 return c->value;
5760}
5761
62b3e311
PB
5762/* Parse an option for a barrier instruction. Returns the encoding for the
5763 option, or FAIL. */
5764static int
5765parse_barrier (char **str)
5766{
5767 char *p, *q;
5768 const struct asm_barrier_opt *o;
5769
5770 p = q = *str;
5771 while (ISALPHA (*q))
5772 q++;
5773
21d799b5
NC
5774 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5775 q - p);
62b3e311
PB
5776 if (!o)
5777 return FAIL;
5778
5779 *str = q;
5780 return o->value;
5781}
5782
92e90b6e
PB
5783/* Parse the operands of a table branch instruction. Similar to a memory
5784 operand. */
5785static int
5786parse_tb (char **str)
5787{
5788 char * p = *str;
5789 int reg;
5790
5791 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5792 {
5793 inst.error = _("'[' expected");
5794 return FAIL;
5795 }
92e90b6e 5796
dcbf9037 5797 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5798 {
5799 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5800 return FAIL;
5801 }
5802 inst.operands[0].reg = reg;
5803
5804 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5805 {
5806 inst.error = _("',' expected");
5807 return FAIL;
5808 }
5f4273c7 5809
dcbf9037 5810 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5811 {
5812 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5813 return FAIL;
5814 }
5815 inst.operands[0].imm = reg;
5816
5817 if (skip_past_comma (&p) == SUCCESS)
5818 {
5819 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5820 return FAIL;
5821 if (inst.reloc.exp.X_add_number != 1)
5822 {
5823 inst.error = _("invalid shift");
5824 return FAIL;
5825 }
5826 inst.operands[0].shifted = 1;
5827 }
5828
5829 if (skip_past_char (&p, ']') == FAIL)
5830 {
5831 inst.error = _("']' expected");
5832 return FAIL;
5833 }
5834 *str = p;
5835 return SUCCESS;
5836}
5837
5287ad62
JB
5838/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5839 information on the types the operands can take and how they are encoded.
037e8744
JB
5840 Up to four operands may be read; this function handles setting the
5841 ".present" field for each read operand itself.
5287ad62
JB
5842 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5843 else returns FAIL. */
5844
5845static int
5846parse_neon_mov (char **str, int *which_operand)
5847{
5848 int i = *which_operand, val;
5849 enum arm_reg_type rtype;
5850 char *ptr = *str;
dcbf9037 5851 struct neon_type_el optype;
5f4273c7 5852
dcbf9037 5853 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5854 {
5855 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5856 inst.operands[i].reg = val;
5857 inst.operands[i].isscalar = 1;
dcbf9037 5858 inst.operands[i].vectype = optype;
5287ad62
JB
5859 inst.operands[i++].present = 1;
5860
5861 if (skip_past_comma (&ptr) == FAIL)
5862 goto wanted_comma;
5f4273c7 5863
dcbf9037 5864 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5865 goto wanted_arm;
5f4273c7 5866
5287ad62
JB
5867 inst.operands[i].reg = val;
5868 inst.operands[i].isreg = 1;
5869 inst.operands[i].present = 1;
5870 }
037e8744 5871 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5872 != FAIL)
5287ad62
JB
5873 {
5874 /* Cases 0, 1, 2, 3, 5 (D only). */
5875 if (skip_past_comma (&ptr) == FAIL)
5876 goto wanted_comma;
5f4273c7 5877
5287ad62
JB
5878 inst.operands[i].reg = val;
5879 inst.operands[i].isreg = 1;
5880 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5881 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5882 inst.operands[i].isvec = 1;
dcbf9037 5883 inst.operands[i].vectype = optype;
5287ad62
JB
5884 inst.operands[i++].present = 1;
5885
dcbf9037 5886 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5887 {
037e8744
JB
5888 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5889 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5890 inst.operands[i].reg = val;
5891 inst.operands[i].isreg = 1;
037e8744 5892 inst.operands[i].present = 1;
5287ad62
JB
5893
5894 if (rtype == REG_TYPE_NQ)
5895 {
dcbf9037 5896 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5897 return FAIL;
5898 }
037e8744
JB
5899 else if (rtype != REG_TYPE_VFS)
5900 {
5901 i++;
5902 if (skip_past_comma (&ptr) == FAIL)
5903 goto wanted_comma;
5904 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5905 goto wanted_arm;
5906 inst.operands[i].reg = val;
5907 inst.operands[i].isreg = 1;
5908 inst.operands[i].present = 1;
5909 }
5287ad62 5910 }
037e8744
JB
5911 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5912 &optype)) != FAIL)
5287ad62
JB
5913 {
5914 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5915 Case 1: VMOV<c><q> <Dd>, <Dm>
5916 Case 8: VMOV.F32 <Sd>, <Sm>
5917 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5918
5919 inst.operands[i].reg = val;
5920 inst.operands[i].isreg = 1;
5921 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5922 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5923 inst.operands[i].isvec = 1;
dcbf9037 5924 inst.operands[i].vectype = optype;
5287ad62 5925 inst.operands[i].present = 1;
5f4273c7 5926
037e8744
JB
5927 if (skip_past_comma (&ptr) == SUCCESS)
5928 {
5929 /* Case 15. */
5930 i++;
5931
5932 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5933 goto wanted_arm;
5934
5935 inst.operands[i].reg = val;
5936 inst.operands[i].isreg = 1;
5937 inst.operands[i++].present = 1;
5f4273c7 5938
037e8744
JB
5939 if (skip_past_comma (&ptr) == FAIL)
5940 goto wanted_comma;
5f4273c7 5941
037e8744
JB
5942 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5943 goto wanted_arm;
5f4273c7 5944
037e8744
JB
5945 inst.operands[i].reg = val;
5946 inst.operands[i].isreg = 1;
1b11b49f 5947 inst.operands[i].present = 1;
037e8744 5948 }
5287ad62 5949 }
4641781c
PB
5950 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5951 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5952 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5953 Case 10: VMOV.F32 <Sd>, #<imm>
5954 Case 11: VMOV.F64 <Dd>, #<imm> */
5955 inst.operands[i].immisfloat = 1;
5956 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5957 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5958 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5959 ;
5287ad62
JB
5960 else
5961 {
dcbf9037 5962 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5963 return FAIL;
5964 }
5965 }
dcbf9037 5966 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5967 {
5968 /* Cases 6, 7. */
5969 inst.operands[i].reg = val;
5970 inst.operands[i].isreg = 1;
5971 inst.operands[i++].present = 1;
5f4273c7 5972
5287ad62
JB
5973 if (skip_past_comma (&ptr) == FAIL)
5974 goto wanted_comma;
5f4273c7 5975
dcbf9037 5976 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5977 {
5978 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5979 inst.operands[i].reg = val;
5980 inst.operands[i].isscalar = 1;
5981 inst.operands[i].present = 1;
dcbf9037 5982 inst.operands[i].vectype = optype;
5287ad62 5983 }
dcbf9037 5984 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5985 {
5986 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5987 inst.operands[i].reg = val;
5988 inst.operands[i].isreg = 1;
5989 inst.operands[i++].present = 1;
5f4273c7 5990
5287ad62
JB
5991 if (skip_past_comma (&ptr) == FAIL)
5992 goto wanted_comma;
5f4273c7 5993
037e8744 5994 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5995 == FAIL)
5287ad62 5996 {
037e8744 5997 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5998 return FAIL;
5999 }
6000
6001 inst.operands[i].reg = val;
6002 inst.operands[i].isreg = 1;
037e8744
JB
6003 inst.operands[i].isvec = 1;
6004 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 6005 inst.operands[i].vectype = optype;
5287ad62 6006 inst.operands[i].present = 1;
5f4273c7 6007
037e8744
JB
6008 if (rtype == REG_TYPE_VFS)
6009 {
6010 /* Case 14. */
6011 i++;
6012 if (skip_past_comma (&ptr) == FAIL)
6013 goto wanted_comma;
6014 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6015 &optype)) == FAIL)
6016 {
6017 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6018 return FAIL;
6019 }
6020 inst.operands[i].reg = val;
6021 inst.operands[i].isreg = 1;
6022 inst.operands[i].isvec = 1;
6023 inst.operands[i].issingle = 1;
6024 inst.operands[i].vectype = optype;
6025 inst.operands[i].present = 1;
6026 }
6027 }
6028 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
6029 != FAIL)
6030 {
6031 /* Case 13. */
6032 inst.operands[i].reg = val;
6033 inst.operands[i].isreg = 1;
6034 inst.operands[i].isvec = 1;
6035 inst.operands[i].issingle = 1;
6036 inst.operands[i].vectype = optype;
1b11b49f 6037 inst.operands[i].present = 1;
5287ad62
JB
6038 }
6039 }
6040 else
6041 {
dcbf9037 6042 first_error (_("parse error"));
5287ad62
JB
6043 return FAIL;
6044 }
6045
6046 /* Successfully parsed the operands. Update args. */
6047 *which_operand = i;
6048 *str = ptr;
6049 return SUCCESS;
6050
5f4273c7 6051 wanted_comma:
dcbf9037 6052 first_error (_("expected comma"));
5287ad62 6053 return FAIL;
5f4273c7
NC
6054
6055 wanted_arm:
dcbf9037 6056 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6057 return FAIL;
5287ad62
JB
6058}
6059
5be8be5d
DG
6060/* Use this macro when the operand constraints are different
6061 for ARM and THUMB (e.g. ldrd). */
6062#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6063 ((arm_operand) | ((thumb_operand) << 16))
6064
c19d1205
ZW
6065/* Matcher codes for parse_operands. */
6066enum operand_parse_code
6067{
6068 OP_stop, /* end of line */
6069
6070 OP_RR, /* ARM register */
6071 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6072 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6073 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6074 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6075 optional trailing ! */
c19d1205
ZW
6076 OP_RRw, /* ARM register, not r15, optional trailing ! */
6077 OP_RCP, /* Coprocessor number */
6078 OP_RCN, /* Coprocessor register */
6079 OP_RF, /* FPA register */
6080 OP_RVS, /* VFP single precision register */
5287ad62
JB
6081 OP_RVD, /* VFP double precision register (0..15) */
6082 OP_RND, /* Neon double precision register (0..31) */
6083 OP_RNQ, /* Neon quad precision register */
037e8744 6084 OP_RVSD, /* VFP single or double precision register */
5287ad62 6085 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6086 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6087 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6088 OP_RVC, /* VFP control register */
6089 OP_RMF, /* Maverick F register */
6090 OP_RMD, /* Maverick D register */
6091 OP_RMFX, /* Maverick FX register */
6092 OP_RMDX, /* Maverick DX register */
6093 OP_RMAX, /* Maverick AX register */
6094 OP_RMDS, /* Maverick DSPSC register */
6095 OP_RIWR, /* iWMMXt wR register */
6096 OP_RIWC, /* iWMMXt wC register */
6097 OP_RIWG, /* iWMMXt wCG register */
6098 OP_RXA, /* XScale accumulator register */
6099
6100 OP_REGLST, /* ARM register list */
6101 OP_VRSLST, /* VFP single-precision register list */
6102 OP_VRDLST, /* VFP double-precision register list */
037e8744 6103 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6104 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6105 OP_NSTRLST, /* Neon element/structure list */
6106
5287ad62 6107 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6108 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 6109 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6110 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6111 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6112 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6113 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6114 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6115 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6116 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6117
6118 OP_I0, /* immediate zero */
c19d1205
ZW
6119 OP_I7, /* immediate value 0 .. 7 */
6120 OP_I15, /* 0 .. 15 */
6121 OP_I16, /* 1 .. 16 */
5287ad62 6122 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6123 OP_I31, /* 0 .. 31 */
6124 OP_I31w, /* 0 .. 31, optional trailing ! */
6125 OP_I32, /* 1 .. 32 */
5287ad62
JB
6126 OP_I32z, /* 0 .. 32 */
6127 OP_I63, /* 0 .. 63 */
c19d1205 6128 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6129 OP_I64, /* 1 .. 64 */
6130 OP_I64z, /* 0 .. 64 */
c19d1205 6131 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6132
6133 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6134 OP_I7b, /* 0 .. 7 */
6135 OP_I15b, /* 0 .. 15 */
6136 OP_I31b, /* 0 .. 31 */
6137
6138 OP_SH, /* shifter operand */
4962c51a 6139 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6140 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6141 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6142 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6143 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6144 OP_EXP, /* arbitrary expression */
6145 OP_EXPi, /* same, with optional immediate prefix */
6146 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6147 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6148
6149 OP_CPSF, /* CPS flags */
6150 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6151 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6152 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6153 OP_COND, /* conditional code */
92e90b6e 6154 OP_TB, /* Table branch. */
c19d1205 6155
037e8744
JB
6156 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6157
c19d1205
ZW
6158 OP_RRnpc_I0, /* ARM register or literal 0 */
6159 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6160 OP_RR_EXi, /* ARM register or expression with imm prefix */
6161 OP_RF_IF, /* FPA register or immediate */
6162 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6163 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6164
6165 /* Optional operands. */
6166 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6167 OP_oI31b, /* 0 .. 31 */
5287ad62 6168 OP_oI32b, /* 1 .. 32 */
5f1af56b 6169 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6170 OP_oIffffb, /* 0 .. 65535 */
6171 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6172
6173 OP_oRR, /* ARM register */
6174 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6175 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6176 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6177 OP_oRND, /* Optional Neon double precision register */
6178 OP_oRNQ, /* Optional Neon quad precision register */
6179 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6180 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6181 OP_oSHll, /* LSL immediate */
6182 OP_oSHar, /* ASR immediate */
6183 OP_oSHllar, /* LSL or ASR immediate */
6184 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6185 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6186
5be8be5d
DG
6187 /* Some pre-defined mixed (ARM/THUMB) operands. */
6188 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6189 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6190 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6191
c19d1205
ZW
6192 OP_FIRST_OPTIONAL = OP_oI7b
6193};
a737bd4d 6194
c19d1205
ZW
6195/* Generic instruction operand parser. This does no encoding and no
6196 semantic validation; it merely squirrels values away in the inst
6197 structure. Returns SUCCESS or FAIL depending on whether the
6198 specified grammar matched. */
6199static int
5be8be5d 6200parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6201{
5be8be5d 6202 unsigned const int *upat = pattern;
c19d1205
ZW
6203 char *backtrack_pos = 0;
6204 const char *backtrack_error = 0;
99aad254 6205 int i, val = 0, backtrack_index = 0;
5287ad62 6206 enum arm_reg_type rtype;
4962c51a 6207 parse_operand_result result;
5be8be5d 6208 unsigned int op_parse_code;
c19d1205 6209
e07e6e58
NC
6210#define po_char_or_fail(chr) \
6211 do \
6212 { \
6213 if (skip_past_char (&str, chr) == FAIL) \
6214 goto bad_args; \
6215 } \
6216 while (0)
c19d1205 6217
e07e6e58
NC
6218#define po_reg_or_fail(regtype) \
6219 do \
dcbf9037 6220 { \
e07e6e58
NC
6221 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6222 & inst.operands[i].vectype); \
6223 if (val == FAIL) \
6224 { \
6225 first_error (_(reg_expected_msgs[regtype])); \
6226 goto failure; \
6227 } \
6228 inst.operands[i].reg = val; \
6229 inst.operands[i].isreg = 1; \
6230 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6231 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6232 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6233 || rtype == REG_TYPE_VFD \
6234 || rtype == REG_TYPE_NQ); \
dcbf9037 6235 } \
e07e6e58
NC
6236 while (0)
6237
6238#define po_reg_or_goto(regtype, label) \
6239 do \
6240 { \
6241 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6242 & inst.operands[i].vectype); \
6243 if (val == FAIL) \
6244 goto label; \
dcbf9037 6245 \
e07e6e58
NC
6246 inst.operands[i].reg = val; \
6247 inst.operands[i].isreg = 1; \
6248 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6249 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6250 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6251 || rtype == REG_TYPE_VFD \
6252 || rtype == REG_TYPE_NQ); \
6253 } \
6254 while (0)
6255
6256#define po_imm_or_fail(min, max, popt) \
6257 do \
6258 { \
6259 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6260 goto failure; \
6261 inst.operands[i].imm = val; \
6262 } \
6263 while (0)
6264
6265#define po_scalar_or_goto(elsz, label) \
6266 do \
6267 { \
6268 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6269 if (val == FAIL) \
6270 goto label; \
6271 inst.operands[i].reg = val; \
6272 inst.operands[i].isscalar = 1; \
6273 } \
6274 while (0)
6275
6276#define po_misc_or_fail(expr) \
6277 do \
6278 { \
6279 if (expr) \
6280 goto failure; \
6281 } \
6282 while (0)
6283
6284#define po_misc_or_fail_no_backtrack(expr) \
6285 do \
6286 { \
6287 result = expr; \
6288 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6289 backtrack_pos = 0; \
6290 if (result != PARSE_OPERAND_SUCCESS) \
6291 goto failure; \
6292 } \
6293 while (0)
4962c51a 6294
52e7f43d
RE
6295#define po_barrier_or_imm(str) \
6296 do \
6297 { \
6298 val = parse_barrier (&str); \
6299 if (val == FAIL) \
6300 { \
6301 if (ISALPHA (*str)) \
6302 goto failure; \
6303 else \
6304 goto immediate; \
6305 } \
6306 else \
6307 { \
6308 if ((inst.instruction & 0xf0) == 0x60 \
6309 && val != 0xf) \
6310 { \
6311 /* ISB can only take SY as an option. */ \
6312 inst.error = _("invalid barrier type"); \
6313 goto failure; \
6314 } \
6315 } \
6316 } \
6317 while (0)
6318
c19d1205
ZW
6319 skip_whitespace (str);
6320
6321 for (i = 0; upat[i] != OP_stop; i++)
6322 {
5be8be5d
DG
6323 op_parse_code = upat[i];
6324 if (op_parse_code >= 1<<16)
6325 op_parse_code = thumb ? (op_parse_code >> 16)
6326 : (op_parse_code & ((1<<16)-1));
6327
6328 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6329 {
6330 /* Remember where we are in case we need to backtrack. */
9c2799c2 6331 gas_assert (!backtrack_pos);
c19d1205
ZW
6332 backtrack_pos = str;
6333 backtrack_error = inst.error;
6334 backtrack_index = i;
6335 }
6336
b6702015 6337 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6338 po_char_or_fail (',');
6339
5be8be5d 6340 switch (op_parse_code)
c19d1205
ZW
6341 {
6342 /* Registers */
6343 case OP_oRRnpc:
5be8be5d 6344 case OP_oRRnpcsp:
c19d1205 6345 case OP_RRnpc:
5be8be5d 6346 case OP_RRnpcsp:
c19d1205
ZW
6347 case OP_oRR:
6348 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6349 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6350 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6351 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6352 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6353 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
6354 case OP_oRND:
6355 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6356 case OP_RVC:
6357 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6358 break;
6359 /* Also accept generic coprocessor regs for unknown registers. */
6360 coproc_reg:
6361 po_reg_or_fail (REG_TYPE_CN);
6362 break;
c19d1205
ZW
6363 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6364 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6365 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6366 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6367 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6368 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6369 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6370 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6371 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6372 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
6373 case OP_oRNQ:
6374 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6375 case OP_oRNDQ:
6376 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
6377 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6378 case OP_oRNSDQ:
6379 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
6380
6381 /* Neon scalar. Using an element size of 8 means that some invalid
6382 scalars are accepted here, so deal with those in later code. */
6383 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6384
5287ad62
JB
6385 case OP_RNDQ_I0:
6386 {
6387 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6388 break;
6389 try_imm0:
6390 po_imm_or_fail (0, 0, TRUE);
6391 }
6392 break;
6393
037e8744
JB
6394 case OP_RVSD_I0:
6395 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6396 break;
6397
5287ad62
JB
6398 case OP_RR_RNSC:
6399 {
6400 po_scalar_or_goto (8, try_rr);
6401 break;
6402 try_rr:
6403 po_reg_or_fail (REG_TYPE_RN);
6404 }
6405 break;
6406
037e8744
JB
6407 case OP_RNSDQ_RNSC:
6408 {
6409 po_scalar_or_goto (8, try_nsdq);
6410 break;
6411 try_nsdq:
6412 po_reg_or_fail (REG_TYPE_NSDQ);
6413 }
6414 break;
6415
5287ad62
JB
6416 case OP_RNDQ_RNSC:
6417 {
6418 po_scalar_or_goto (8, try_ndq);
6419 break;
6420 try_ndq:
6421 po_reg_or_fail (REG_TYPE_NDQ);
6422 }
6423 break;
6424
6425 case OP_RND_RNSC:
6426 {
6427 po_scalar_or_goto (8, try_vfd);
6428 break;
6429 try_vfd:
6430 po_reg_or_fail (REG_TYPE_VFD);
6431 }
6432 break;
6433
6434 case OP_VMOV:
6435 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6436 not careful then bad things might happen. */
6437 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6438 break;
6439
4316f0d2 6440 case OP_RNDQ_Ibig:
5287ad62 6441 {
4316f0d2 6442 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
5287ad62 6443 break;
4316f0d2 6444 try_immbig:
5287ad62
JB
6445 /* There's a possibility of getting a 64-bit immediate here, so
6446 we need special handling. */
6447 if (parse_big_immediate (&str, i) == FAIL)
6448 {
6449 inst.error = _("immediate value is out of range");
6450 goto failure;
6451 }
6452 }
6453 break;
6454
6455 case OP_RNDQ_I63b:
6456 {
6457 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6458 break;
6459 try_shimm:
6460 po_imm_or_fail (0, 63, TRUE);
6461 }
6462 break;
c19d1205
ZW
6463
6464 case OP_RRnpcb:
6465 po_char_or_fail ('[');
6466 po_reg_or_fail (REG_TYPE_RN);
6467 po_char_or_fail (']');
6468 break;
a737bd4d 6469
55881a11 6470 case OP_RRnpctw:
c19d1205 6471 case OP_RRw:
b6702015 6472 case OP_oRRw:
c19d1205
ZW
6473 po_reg_or_fail (REG_TYPE_RN);
6474 if (skip_past_char (&str, '!') == SUCCESS)
6475 inst.operands[i].writeback = 1;
6476 break;
6477
6478 /* Immediates */
6479 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6480 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6481 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 6482 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6483 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6484 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 6485 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6486 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
6487 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6488 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6489 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6490 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6491
6492 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6493 case OP_oI7b:
6494 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6495 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6496 case OP_oI31b:
6497 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 6498 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5f1af56b 6499 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6500 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6501
6502 /* Immediate variants */
6503 case OP_oI255c:
6504 po_char_or_fail ('{');
6505 po_imm_or_fail (0, 255, TRUE);
6506 po_char_or_fail ('}');
6507 break;
6508
6509 case OP_I31w:
6510 /* The expression parser chokes on a trailing !, so we have
6511 to find it first and zap it. */
6512 {
6513 char *s = str;
6514 while (*s && *s != ',')
6515 s++;
6516 if (s[-1] == '!')
6517 {
6518 s[-1] = '\0';
6519 inst.operands[i].writeback = 1;
6520 }
6521 po_imm_or_fail (0, 31, TRUE);
6522 if (str == s - 1)
6523 str = s;
6524 }
6525 break;
6526
6527 /* Expressions */
6528 case OP_EXPi: EXPi:
6529 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6530 GE_OPT_PREFIX));
6531 break;
6532
6533 case OP_EXP:
6534 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6535 GE_NO_PREFIX));
6536 break;
6537
6538 case OP_EXPr: EXPr:
6539 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6540 GE_NO_PREFIX));
6541 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6542 {
c19d1205
ZW
6543 val = parse_reloc (&str);
6544 if (val == -1)
6545 {
6546 inst.error = _("unrecognized relocation suffix");
6547 goto failure;
6548 }
6549 else if (val != BFD_RELOC_UNUSED)
6550 {
6551 inst.operands[i].imm = val;
6552 inst.operands[i].hasreloc = 1;
6553 }
a737bd4d 6554 }
c19d1205 6555 break;
a737bd4d 6556
b6895b4f
PB
6557 /* Operand for MOVW or MOVT. */
6558 case OP_HALF:
6559 po_misc_or_fail (parse_half (&str));
6560 break;
6561
e07e6e58 6562 /* Register or expression. */
c19d1205
ZW
6563 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6564 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6565
e07e6e58 6566 /* Register or immediate. */
c19d1205
ZW
6567 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6568 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6569
c19d1205
ZW
6570 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6571 IF:
6572 if (!is_immediate_prefix (*str))
6573 goto bad_args;
6574 str++;
6575 val = parse_fpa_immediate (&str);
6576 if (val == FAIL)
6577 goto failure;
6578 /* FPA immediates are encoded as registers 8-15.
6579 parse_fpa_immediate has already applied the offset. */
6580 inst.operands[i].reg = val;
6581 inst.operands[i].isreg = 1;
6582 break;
09d92015 6583
2d447fca
JM
6584 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6585 I32z: po_imm_or_fail (0, 32, FALSE); break;
6586
e07e6e58 6587 /* Two kinds of register. */
c19d1205
ZW
6588 case OP_RIWR_RIWC:
6589 {
6590 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6591 if (!rege
6592 || (rege->type != REG_TYPE_MMXWR
6593 && rege->type != REG_TYPE_MMXWC
6594 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6595 {
6596 inst.error = _("iWMMXt data or control register expected");
6597 goto failure;
6598 }
6599 inst.operands[i].reg = rege->number;
6600 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6601 }
6602 break;
09d92015 6603
41adaa5c
JM
6604 case OP_RIWC_RIWG:
6605 {
6606 struct reg_entry *rege = arm_reg_parse_multi (&str);
6607 if (!rege
6608 || (rege->type != REG_TYPE_MMXWC
6609 && rege->type != REG_TYPE_MMXWCG))
6610 {
6611 inst.error = _("iWMMXt control register expected");
6612 goto failure;
6613 }
6614 inst.operands[i].reg = rege->number;
6615 inst.operands[i].isreg = 1;
6616 }
6617 break;
6618
c19d1205
ZW
6619 /* Misc */
6620 case OP_CPSF: val = parse_cps_flags (&str); break;
6621 case OP_ENDI: val = parse_endian_specifier (&str); break;
6622 case OP_oROR: val = parse_ror (&str); break;
c19d1205 6623 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6624 case OP_oBARRIER_I15:
6625 po_barrier_or_imm (str); break;
6626 immediate:
6627 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6628 goto failure;
6629 break;
c19d1205 6630
fa94de6b 6631 case OP_wPSR:
d2cd1205 6632 case OP_rPSR:
90ec0d68
MGD
6633 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6634 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6635 {
6636 inst.error = _("Banked registers are not available with this "
6637 "architecture.");
6638 goto failure;
6639 }
6640 break;
d2cd1205
JB
6641 try_psr:
6642 val = parse_psr (&str, op_parse_code == OP_wPSR);
6643 break;
037e8744
JB
6644
6645 case OP_APSR_RR:
6646 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6647 break;
6648 try_apsr:
6649 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6650 instruction). */
6651 if (strncasecmp (str, "APSR_", 5) == 0)
6652 {
6653 unsigned found = 0;
6654 str += 5;
6655 while (found < 15)
6656 switch (*str++)
6657 {
6658 case 'c': found = (found & 1) ? 16 : found | 1; break;
6659 case 'n': found = (found & 2) ? 16 : found | 2; break;
6660 case 'z': found = (found & 4) ? 16 : found | 4; break;
6661 case 'v': found = (found & 8) ? 16 : found | 8; break;
6662 default: found = 16;
6663 }
6664 if (found != 15)
6665 goto failure;
6666 inst.operands[i].isvec = 1;
f7c21dc7
NC
6667 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6668 inst.operands[i].reg = REG_PC;
037e8744
JB
6669 }
6670 else
6671 goto failure;
6672 break;
6673
92e90b6e
PB
6674 case OP_TB:
6675 po_misc_or_fail (parse_tb (&str));
6676 break;
6677
e07e6e58 6678 /* Register lists. */
c19d1205
ZW
6679 case OP_REGLST:
6680 val = parse_reg_list (&str);
6681 if (*str == '^')
6682 {
6683 inst.operands[1].writeback = 1;
6684 str++;
6685 }
6686 break;
09d92015 6687
c19d1205 6688 case OP_VRSLST:
5287ad62 6689 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6690 break;
09d92015 6691
c19d1205 6692 case OP_VRDLST:
5287ad62 6693 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6694 break;
a737bd4d 6695
037e8744
JB
6696 case OP_VRSDLST:
6697 /* Allow Q registers too. */
6698 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6699 REGLIST_NEON_D);
6700 if (val == FAIL)
6701 {
6702 inst.error = NULL;
6703 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6704 REGLIST_VFP_S);
6705 inst.operands[i].issingle = 1;
6706 }
6707 break;
6708
5287ad62
JB
6709 case OP_NRDLST:
6710 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6711 REGLIST_NEON_D);
6712 break;
6713
6714 case OP_NSTRLST:
dcbf9037
JB
6715 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6716 &inst.operands[i].vectype);
5287ad62
JB
6717 break;
6718
c19d1205
ZW
6719 /* Addressing modes */
6720 case OP_ADDR:
6721 po_misc_or_fail (parse_address (&str, i));
6722 break;
09d92015 6723
4962c51a
MS
6724 case OP_ADDRGLDR:
6725 po_misc_or_fail_no_backtrack (
6726 parse_address_group_reloc (&str, i, GROUP_LDR));
6727 break;
6728
6729 case OP_ADDRGLDRS:
6730 po_misc_or_fail_no_backtrack (
6731 parse_address_group_reloc (&str, i, GROUP_LDRS));
6732 break;
6733
6734 case OP_ADDRGLDC:
6735 po_misc_or_fail_no_backtrack (
6736 parse_address_group_reloc (&str, i, GROUP_LDC));
6737 break;
6738
c19d1205
ZW
6739 case OP_SH:
6740 po_misc_or_fail (parse_shifter_operand (&str, i));
6741 break;
09d92015 6742
4962c51a
MS
6743 case OP_SHG:
6744 po_misc_or_fail_no_backtrack (
6745 parse_shifter_operand_group_reloc (&str, i));
6746 break;
6747
c19d1205
ZW
6748 case OP_oSHll:
6749 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6750 break;
09d92015 6751
c19d1205
ZW
6752 case OP_oSHar:
6753 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6754 break;
09d92015 6755
c19d1205
ZW
6756 case OP_oSHllar:
6757 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6758 break;
09d92015 6759
c19d1205 6760 default:
5be8be5d 6761 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 6762 }
09d92015 6763
c19d1205
ZW
6764 /* Various value-based sanity checks and shared operations. We
6765 do not signal immediate failures for the register constraints;
6766 this allows a syntax error to take precedence. */
5be8be5d 6767 switch (op_parse_code)
c19d1205
ZW
6768 {
6769 case OP_oRRnpc:
6770 case OP_RRnpc:
6771 case OP_RRnpcb:
6772 case OP_RRw:
b6702015 6773 case OP_oRRw:
c19d1205
ZW
6774 case OP_RRnpc_I0:
6775 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6776 inst.error = BAD_PC;
6777 break;
09d92015 6778
5be8be5d
DG
6779 case OP_oRRnpcsp:
6780 case OP_RRnpcsp:
6781 if (inst.operands[i].isreg)
6782 {
6783 if (inst.operands[i].reg == REG_PC)
6784 inst.error = BAD_PC;
6785 else if (inst.operands[i].reg == REG_SP)
6786 inst.error = BAD_SP;
6787 }
6788 break;
6789
55881a11 6790 case OP_RRnpctw:
fa94de6b
RM
6791 if (inst.operands[i].isreg
6792 && inst.operands[i].reg == REG_PC
55881a11
MGD
6793 && (inst.operands[i].writeback || thumb))
6794 inst.error = BAD_PC;
6795 break;
6796
c19d1205
ZW
6797 case OP_CPSF:
6798 case OP_ENDI:
6799 case OP_oROR:
d2cd1205
JB
6800 case OP_wPSR:
6801 case OP_rPSR:
c19d1205 6802 case OP_COND:
52e7f43d 6803 case OP_oBARRIER_I15:
c19d1205
ZW
6804 case OP_REGLST:
6805 case OP_VRSLST:
6806 case OP_VRDLST:
037e8744 6807 case OP_VRSDLST:
5287ad62
JB
6808 case OP_NRDLST:
6809 case OP_NSTRLST:
c19d1205
ZW
6810 if (val == FAIL)
6811 goto failure;
6812 inst.operands[i].imm = val;
6813 break;
a737bd4d 6814
c19d1205
ZW
6815 default:
6816 break;
6817 }
09d92015 6818
c19d1205
ZW
6819 /* If we get here, this operand was successfully parsed. */
6820 inst.operands[i].present = 1;
6821 continue;
09d92015 6822
c19d1205 6823 bad_args:
09d92015 6824 inst.error = BAD_ARGS;
c19d1205
ZW
6825
6826 failure:
6827 if (!backtrack_pos)
d252fdde
PB
6828 {
6829 /* The parse routine should already have set inst.error, but set a
5f4273c7 6830 default here just in case. */
d252fdde
PB
6831 if (!inst.error)
6832 inst.error = _("syntax error");
6833 return FAIL;
6834 }
c19d1205
ZW
6835
6836 /* Do not backtrack over a trailing optional argument that
6837 absorbed some text. We will only fail again, with the
6838 'garbage following instruction' error message, which is
6839 probably less helpful than the current one. */
6840 if (backtrack_index == i && backtrack_pos != str
6841 && upat[i+1] == OP_stop)
d252fdde
PB
6842 {
6843 if (!inst.error)
6844 inst.error = _("syntax error");
6845 return FAIL;
6846 }
c19d1205
ZW
6847
6848 /* Try again, skipping the optional argument at backtrack_pos. */
6849 str = backtrack_pos;
6850 inst.error = backtrack_error;
6851 inst.operands[backtrack_index].present = 0;
6852 i = backtrack_index;
6853 backtrack_pos = 0;
09d92015 6854 }
09d92015 6855
c19d1205
ZW
6856 /* Check that we have parsed all the arguments. */
6857 if (*str != '\0' && !inst.error)
6858 inst.error = _("garbage following instruction");
09d92015 6859
c19d1205 6860 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6861}
6862
c19d1205
ZW
6863#undef po_char_or_fail
6864#undef po_reg_or_fail
6865#undef po_reg_or_goto
6866#undef po_imm_or_fail
5287ad62 6867#undef po_scalar_or_fail
52e7f43d 6868#undef po_barrier_or_imm
e07e6e58 6869
c19d1205 6870/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6871#define constraint(expr, err) \
6872 do \
c19d1205 6873 { \
e07e6e58
NC
6874 if (expr) \
6875 { \
6876 inst.error = err; \
6877 return; \
6878 } \
c19d1205 6879 } \
e07e6e58 6880 while (0)
c19d1205 6881
fdfde340
JM
6882/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6883 instructions are unpredictable if these registers are used. This
6884 is the BadReg predicate in ARM's Thumb-2 documentation. */
6885#define reject_bad_reg(reg) \
6886 do \
6887 if (reg == REG_SP || reg == REG_PC) \
6888 { \
6889 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6890 return; \
6891 } \
6892 while (0)
6893
94206790
MM
6894/* If REG is R13 (the stack pointer), warn that its use is
6895 deprecated. */
6896#define warn_deprecated_sp(reg) \
6897 do \
6898 if (warn_on_deprecated && reg == REG_SP) \
6899 as_warn (_("use of r13 is deprecated")); \
6900 while (0)
6901
c19d1205
ZW
6902/* Functions for operand encoding. ARM, then Thumb. */
6903
6904#define rotate_left(v, n) (v << n | v >> (32 - n))
6905
6906/* If VAL can be encoded in the immediate field of an ARM instruction,
6907 return the encoded form. Otherwise, return FAIL. */
6908
6909static unsigned int
6910encode_arm_immediate (unsigned int val)
09d92015 6911{
c19d1205
ZW
6912 unsigned int a, i;
6913
6914 for (i = 0; i < 32; i += 2)
6915 if ((a = rotate_left (val, i)) <= 0xff)
6916 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6917
6918 return FAIL;
09d92015
MM
6919}
6920
c19d1205
ZW
6921/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6922 return the encoded form. Otherwise, return FAIL. */
6923static unsigned int
6924encode_thumb32_immediate (unsigned int val)
09d92015 6925{
c19d1205 6926 unsigned int a, i;
09d92015 6927
9c3c69f2 6928 if (val <= 0xff)
c19d1205 6929 return val;
a737bd4d 6930
9c3c69f2 6931 for (i = 1; i <= 24; i++)
09d92015 6932 {
9c3c69f2
PB
6933 a = val >> i;
6934 if ((val & ~(0xff << i)) == 0)
6935 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6936 }
a737bd4d 6937
c19d1205
ZW
6938 a = val & 0xff;
6939 if (val == ((a << 16) | a))
6940 return 0x100 | a;
6941 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6942 return 0x300 | a;
09d92015 6943
c19d1205
ZW
6944 a = val & 0xff00;
6945 if (val == ((a << 16) | a))
6946 return 0x200 | (a >> 8);
a737bd4d 6947
c19d1205 6948 return FAIL;
09d92015 6949}
5287ad62 6950/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6951
6952static void
5287ad62
JB
6953encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6954{
6955 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6956 && reg > 15)
6957 {
b1cc4aeb 6958 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6959 {
6960 if (thumb_mode)
6961 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6962 fpu_vfp_ext_d32);
5287ad62
JB
6963 else
6964 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6965 fpu_vfp_ext_d32);
5287ad62
JB
6966 }
6967 else
6968 {
dcbf9037 6969 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6970 return;
6971 }
6972 }
6973
c19d1205 6974 switch (pos)
09d92015 6975 {
c19d1205
ZW
6976 case VFP_REG_Sd:
6977 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6978 break;
6979
6980 case VFP_REG_Sn:
6981 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6982 break;
6983
6984 case VFP_REG_Sm:
6985 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6986 break;
6987
5287ad62
JB
6988 case VFP_REG_Dd:
6989 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6990 break;
5f4273c7 6991
5287ad62
JB
6992 case VFP_REG_Dn:
6993 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6994 break;
5f4273c7 6995
5287ad62
JB
6996 case VFP_REG_Dm:
6997 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6998 break;
6999
c19d1205
ZW
7000 default:
7001 abort ();
09d92015 7002 }
09d92015
MM
7003}
7004
c19d1205 7005/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7006 if any, is handled by md_apply_fix. */
09d92015 7007static void
c19d1205 7008encode_arm_shift (int i)
09d92015 7009{
c19d1205
ZW
7010 if (inst.operands[i].shift_kind == SHIFT_RRX)
7011 inst.instruction |= SHIFT_ROR << 5;
7012 else
09d92015 7013 {
c19d1205
ZW
7014 inst.instruction |= inst.operands[i].shift_kind << 5;
7015 if (inst.operands[i].immisreg)
7016 {
7017 inst.instruction |= SHIFT_BY_REG;
7018 inst.instruction |= inst.operands[i].imm << 8;
7019 }
7020 else
7021 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7022 }
c19d1205 7023}
09d92015 7024
c19d1205
ZW
7025static void
7026encode_arm_shifter_operand (int i)
7027{
7028 if (inst.operands[i].isreg)
09d92015 7029 {
c19d1205
ZW
7030 inst.instruction |= inst.operands[i].reg;
7031 encode_arm_shift (i);
09d92015 7032 }
c19d1205 7033 else
a415b1cd
JB
7034 {
7035 inst.instruction |= INST_IMMEDIATE;
7036 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7037 inst.instruction |= inst.operands[i].imm;
7038 }
09d92015
MM
7039}
7040
c19d1205 7041/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7042static void
c19d1205 7043encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7044{
2b2f5df9
NC
7045 /* PR 14260:
7046 Generate an error if the operand is not a register. */
7047 constraint (!inst.operands[i].isreg,
7048 _("Instruction does not support =N addresses"));
7049
c19d1205 7050 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7051
c19d1205 7052 if (inst.operands[i].preind)
09d92015 7053 {
c19d1205
ZW
7054 if (is_t)
7055 {
7056 inst.error = _("instruction does not accept preindexed addressing");
7057 return;
7058 }
7059 inst.instruction |= PRE_INDEX;
7060 if (inst.operands[i].writeback)
7061 inst.instruction |= WRITE_BACK;
09d92015 7062
c19d1205
ZW
7063 }
7064 else if (inst.operands[i].postind)
7065 {
9c2799c2 7066 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7067 if (is_t)
7068 inst.instruction |= WRITE_BACK;
7069 }
7070 else /* unindexed - only for coprocessor */
09d92015 7071 {
c19d1205 7072 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7073 return;
7074 }
7075
c19d1205
ZW
7076 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7077 && (((inst.instruction & 0x000f0000) >> 16)
7078 == ((inst.instruction & 0x0000f000) >> 12)))
7079 as_warn ((inst.instruction & LOAD_BIT)
7080 ? _("destination register same as write-back base")
7081 : _("source register same as write-back base"));
09d92015
MM
7082}
7083
c19d1205
ZW
7084/* inst.operands[i] was set up by parse_address. Encode it into an
7085 ARM-format mode 2 load or store instruction. If is_t is true,
7086 reject forms that cannot be used with a T instruction (i.e. not
7087 post-indexed). */
a737bd4d 7088static void
c19d1205 7089encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7090{
5be8be5d
DG
7091 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7092
c19d1205 7093 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7094
c19d1205 7095 if (inst.operands[i].immisreg)
09d92015 7096 {
5be8be5d
DG
7097 constraint ((inst.operands[i].imm == REG_PC
7098 || (is_pc && inst.operands[i].writeback)),
7099 BAD_PC_ADDRESSING);
c19d1205
ZW
7100 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7101 inst.instruction |= inst.operands[i].imm;
7102 if (!inst.operands[i].negative)
7103 inst.instruction |= INDEX_UP;
7104 if (inst.operands[i].shifted)
7105 {
7106 if (inst.operands[i].shift_kind == SHIFT_RRX)
7107 inst.instruction |= SHIFT_ROR << 5;
7108 else
7109 {
7110 inst.instruction |= inst.operands[i].shift_kind << 5;
7111 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7112 }
7113 }
09d92015 7114 }
c19d1205 7115 else /* immediate offset in inst.reloc */
09d92015 7116 {
5be8be5d
DG
7117 if (is_pc && !inst.reloc.pc_rel)
7118 {
7119 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7120
7121 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7122 cannot use PC in addressing.
7123 PC cannot be used in writeback addressing, either. */
7124 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7125 BAD_PC_ADDRESSING);
23a10334 7126
dc5ec521 7127 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7128 if (warn_on_deprecated
7129 && !is_load
7130 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7131 as_warn (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7132 }
7133
c19d1205 7134 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7135 {
7136 /* Prefer + for zero encoded value. */
7137 if (!inst.operands[i].negative)
7138 inst.instruction |= INDEX_UP;
7139 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7140 }
09d92015 7141 }
09d92015
MM
7142}
7143
c19d1205
ZW
7144/* inst.operands[i] was set up by parse_address. Encode it into an
7145 ARM-format mode 3 load or store instruction. Reject forms that
7146 cannot be used with such instructions. If is_t is true, reject
7147 forms that cannot be used with a T instruction (i.e. not
7148 post-indexed). */
7149static void
7150encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7151{
c19d1205 7152 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7153 {
c19d1205
ZW
7154 inst.error = _("instruction does not accept scaled register index");
7155 return;
09d92015 7156 }
a737bd4d 7157
c19d1205 7158 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7159
c19d1205
ZW
7160 if (inst.operands[i].immisreg)
7161 {
5be8be5d
DG
7162 constraint ((inst.operands[i].imm == REG_PC
7163 || inst.operands[i].reg == REG_PC),
7164 BAD_PC_ADDRESSING);
c19d1205
ZW
7165 inst.instruction |= inst.operands[i].imm;
7166 if (!inst.operands[i].negative)
7167 inst.instruction |= INDEX_UP;
7168 }
7169 else /* immediate offset in inst.reloc */
7170 {
5be8be5d
DG
7171 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7172 && inst.operands[i].writeback),
7173 BAD_PC_WRITEBACK);
c19d1205
ZW
7174 inst.instruction |= HWOFFSET_IMM;
7175 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7176 {
7177 /* Prefer + for zero encoded value. */
7178 if (!inst.operands[i].negative)
7179 inst.instruction |= INDEX_UP;
7180
7181 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7182 }
c19d1205 7183 }
a737bd4d
NC
7184}
7185
c19d1205
ZW
7186/* inst.operands[i] was set up by parse_address. Encode it into an
7187 ARM-format instruction. Reject all forms which cannot be encoded
7188 into a coprocessor load/store instruction. If wb_ok is false,
7189 reject use of writeback; if unind_ok is false, reject use of
7190 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
7191 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
7192 (in which case it is preserved). */
09d92015 7193
c19d1205
ZW
7194static int
7195encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 7196{
c19d1205 7197 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7198
9c2799c2 7199 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 7200
c19d1205 7201 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 7202 {
9c2799c2 7203 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
7204 if (!unind_ok)
7205 {
7206 inst.error = _("instruction does not support unindexed addressing");
7207 return FAIL;
7208 }
7209 inst.instruction |= inst.operands[i].imm;
7210 inst.instruction |= INDEX_UP;
7211 return SUCCESS;
09d92015 7212 }
a737bd4d 7213
c19d1205
ZW
7214 if (inst.operands[i].preind)
7215 inst.instruction |= PRE_INDEX;
a737bd4d 7216
c19d1205 7217 if (inst.operands[i].writeback)
09d92015 7218 {
c19d1205
ZW
7219 if (inst.operands[i].reg == REG_PC)
7220 {
7221 inst.error = _("pc may not be used with write-back");
7222 return FAIL;
7223 }
7224 if (!wb_ok)
7225 {
7226 inst.error = _("instruction does not support writeback");
7227 return FAIL;
7228 }
7229 inst.instruction |= WRITE_BACK;
09d92015 7230 }
a737bd4d 7231
c19d1205 7232 if (reloc_override)
21d799b5 7233 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a
MS
7234 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
7235 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
7236 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
7237 {
7238 if (thumb_mode)
7239 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
7240 else
7241 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
7242 }
7243
26d97720
NS
7244 /* Prefer + for zero encoded value. */
7245 if (!inst.operands[i].negative)
7246 inst.instruction |= INDEX_UP;
7247
c19d1205
ZW
7248 return SUCCESS;
7249}
a737bd4d 7250
c19d1205
ZW
7251/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7252 Determine whether it can be performed with a move instruction; if
7253 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7254 return TRUE; if it can't, convert inst.instruction to a literal-pool
7255 load and return FALSE. If this is not a valid thing to do in the
7256 current context, set inst.error and return TRUE.
a737bd4d 7257
c19d1205
ZW
7258 inst.operands[i] describes the destination register. */
7259
c921be7d 7260static bfd_boolean
c19d1205
ZW
7261move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
7262{
53365c0d
PB
7263 unsigned long tbit;
7264
7265 if (thumb_p)
7266 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7267 else
7268 tbit = LOAD_BIT;
7269
7270 if ((inst.instruction & tbit) == 0)
09d92015 7271 {
c19d1205 7272 inst.error = _("invalid pseudo operation");
c921be7d 7273 return TRUE;
09d92015 7274 }
c19d1205 7275 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
7276 {
7277 inst.error = _("constant expression expected");
c921be7d 7278 return TRUE;
09d92015 7279 }
c19d1205 7280 if (inst.reloc.exp.X_op == O_constant)
09d92015 7281 {
c19d1205
ZW
7282 if (thumb_p)
7283 {
53365c0d 7284 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
7285 {
7286 /* This can be done with a mov(1) instruction. */
7287 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7288 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 7289 return TRUE;
c19d1205
ZW
7290 }
7291 }
7292 else
7293 {
7294 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7295 if (value != FAIL)
7296 {
7297 /* This can be done with a mov instruction. */
7298 inst.instruction &= LITERAL_MASK;
7299 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7300 inst.instruction |= value & 0xfff;
c921be7d 7301 return TRUE;
c19d1205 7302 }
09d92015 7303
c19d1205
ZW
7304 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7305 if (value != FAIL)
7306 {
7307 /* This can be done with a mvn instruction. */
7308 inst.instruction &= LITERAL_MASK;
7309 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7310 inst.instruction |= value & 0xfff;
c921be7d 7311 return TRUE;
c19d1205
ZW
7312 }
7313 }
09d92015
MM
7314 }
7315
c19d1205
ZW
7316 if (add_to_lit_pool () == FAIL)
7317 {
7318 inst.error = _("literal pool insertion failed");
c921be7d 7319 return TRUE;
c19d1205
ZW
7320 }
7321 inst.operands[1].reg = REG_PC;
7322 inst.operands[1].isreg = 1;
7323 inst.operands[1].preind = 1;
7324 inst.reloc.pc_rel = 1;
7325 inst.reloc.type = (thumb_p
7326 ? BFD_RELOC_ARM_THUMB_OFFSET
7327 : (mode_3
7328 ? BFD_RELOC_ARM_HWLITERAL
7329 : BFD_RELOC_ARM_LITERAL));
c921be7d 7330 return FALSE;
09d92015
MM
7331}
7332
5f4273c7 7333/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
7334 First some generics; their names are taken from the conventional
7335 bit positions for register arguments in ARM format instructions. */
09d92015 7336
a737bd4d 7337static void
c19d1205 7338do_noargs (void)
09d92015 7339{
c19d1205 7340}
a737bd4d 7341
c19d1205
ZW
7342static void
7343do_rd (void)
7344{
7345 inst.instruction |= inst.operands[0].reg << 12;
7346}
a737bd4d 7347
c19d1205
ZW
7348static void
7349do_rd_rm (void)
7350{
7351 inst.instruction |= inst.operands[0].reg << 12;
7352 inst.instruction |= inst.operands[1].reg;
7353}
09d92015 7354
c19d1205
ZW
7355static void
7356do_rd_rn (void)
7357{
7358 inst.instruction |= inst.operands[0].reg << 12;
7359 inst.instruction |= inst.operands[1].reg << 16;
7360}
a737bd4d 7361
c19d1205
ZW
7362static void
7363do_rn_rd (void)
7364{
7365 inst.instruction |= inst.operands[0].reg << 16;
7366 inst.instruction |= inst.operands[1].reg << 12;
7367}
09d92015 7368
c19d1205
ZW
7369static void
7370do_rd_rm_rn (void)
7371{
9a64e435 7372 unsigned Rn = inst.operands[2].reg;
708587a4 7373 /* Enforce restrictions on SWP instruction. */
9a64e435 7374 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
7375 {
7376 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7377 _("Rn must not overlap other operands"));
7378
7379 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
7380 if (warn_on_deprecated
7381 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7382 as_warn (_("swp{b} use is deprecated for this architecture"));
7383
7384 }
c19d1205
ZW
7385 inst.instruction |= inst.operands[0].reg << 12;
7386 inst.instruction |= inst.operands[1].reg;
9a64e435 7387 inst.instruction |= Rn << 16;
c19d1205 7388}
09d92015 7389
c19d1205
ZW
7390static void
7391do_rd_rn_rm (void)
7392{
7393 inst.instruction |= inst.operands[0].reg << 12;
7394 inst.instruction |= inst.operands[1].reg << 16;
7395 inst.instruction |= inst.operands[2].reg;
7396}
a737bd4d 7397
c19d1205
ZW
7398static void
7399do_rm_rd_rn (void)
7400{
5be8be5d
DG
7401 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7402 constraint (((inst.reloc.exp.X_op != O_constant
7403 && inst.reloc.exp.X_op != O_illegal)
7404 || inst.reloc.exp.X_add_number != 0),
7405 BAD_ADDR_MODE);
c19d1205
ZW
7406 inst.instruction |= inst.operands[0].reg;
7407 inst.instruction |= inst.operands[1].reg << 12;
7408 inst.instruction |= inst.operands[2].reg << 16;
7409}
09d92015 7410
c19d1205
ZW
7411static void
7412do_imm0 (void)
7413{
7414 inst.instruction |= inst.operands[0].imm;
7415}
09d92015 7416
c19d1205
ZW
7417static void
7418do_rd_cpaddr (void)
7419{
7420 inst.instruction |= inst.operands[0].reg << 12;
7421 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 7422}
a737bd4d 7423
c19d1205
ZW
7424/* ARM instructions, in alphabetical order by function name (except
7425 that wrapper functions appear immediately after the function they
7426 wrap). */
09d92015 7427
c19d1205
ZW
7428/* This is a pseudo-op of the form "adr rd, label" to be converted
7429 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
7430
7431static void
c19d1205 7432do_adr (void)
09d92015 7433{
c19d1205 7434 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7435
c19d1205
ZW
7436 /* Frag hacking will turn this into a sub instruction if the offset turns
7437 out to be negative. */
7438 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 7439 inst.reloc.pc_rel = 1;
2fc8bdac 7440 inst.reloc.exp.X_add_number -= 8;
c19d1205 7441}
b99bd4ef 7442
c19d1205
ZW
7443/* This is a pseudo-op of the form "adrl rd, label" to be converted
7444 into a relative address of the form:
7445 add rd, pc, #low(label-.-8)"
7446 add rd, rd, #high(label-.-8)" */
b99bd4ef 7447
c19d1205
ZW
7448static void
7449do_adrl (void)
7450{
7451 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7452
c19d1205
ZW
7453 /* Frag hacking will turn this into a sub instruction if the offset turns
7454 out to be negative. */
7455 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
7456 inst.reloc.pc_rel = 1;
7457 inst.size = INSN_SIZE * 2;
2fc8bdac 7458 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
7459}
7460
b99bd4ef 7461static void
c19d1205 7462do_arit (void)
b99bd4ef 7463{
c19d1205
ZW
7464 if (!inst.operands[1].present)
7465 inst.operands[1].reg = inst.operands[0].reg;
7466 inst.instruction |= inst.operands[0].reg << 12;
7467 inst.instruction |= inst.operands[1].reg << 16;
7468 encode_arm_shifter_operand (2);
7469}
b99bd4ef 7470
62b3e311
PB
7471static void
7472do_barrier (void)
7473{
7474 if (inst.operands[0].present)
7475 {
7476 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
7477 && inst.operands[0].imm > 0xf
7478 && inst.operands[0].imm < 0x0,
bd3ba5d1 7479 _("bad barrier type"));
62b3e311
PB
7480 inst.instruction |= inst.operands[0].imm;
7481 }
7482 else
7483 inst.instruction |= 0xf;
7484}
7485
c19d1205
ZW
7486static void
7487do_bfc (void)
7488{
7489 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7490 constraint (msb > 32, _("bit-field extends past end of register"));
7491 /* The instruction encoding stores the LSB and MSB,
7492 not the LSB and width. */
7493 inst.instruction |= inst.operands[0].reg << 12;
7494 inst.instruction |= inst.operands[1].imm << 7;
7495 inst.instruction |= (msb - 1) << 16;
7496}
b99bd4ef 7497
c19d1205
ZW
7498static void
7499do_bfi (void)
7500{
7501 unsigned int msb;
b99bd4ef 7502
c19d1205
ZW
7503 /* #0 in second position is alternative syntax for bfc, which is
7504 the same instruction but with REG_PC in the Rm field. */
7505 if (!inst.operands[1].isreg)
7506 inst.operands[1].reg = REG_PC;
b99bd4ef 7507
c19d1205
ZW
7508 msb = inst.operands[2].imm + inst.operands[3].imm;
7509 constraint (msb > 32, _("bit-field extends past end of register"));
7510 /* The instruction encoding stores the LSB and MSB,
7511 not the LSB and width. */
7512 inst.instruction |= inst.operands[0].reg << 12;
7513 inst.instruction |= inst.operands[1].reg;
7514 inst.instruction |= inst.operands[2].imm << 7;
7515 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7516}
7517
b99bd4ef 7518static void
c19d1205 7519do_bfx (void)
b99bd4ef 7520{
c19d1205
ZW
7521 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7522 _("bit-field extends past end of register"));
7523 inst.instruction |= inst.operands[0].reg << 12;
7524 inst.instruction |= inst.operands[1].reg;
7525 inst.instruction |= inst.operands[2].imm << 7;
7526 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7527}
09d92015 7528
c19d1205
ZW
7529/* ARM V5 breakpoint instruction (argument parse)
7530 BKPT <16 bit unsigned immediate>
7531 Instruction is not conditional.
7532 The bit pattern given in insns[] has the COND_ALWAYS condition,
7533 and it is an error if the caller tried to override that. */
b99bd4ef 7534
c19d1205
ZW
7535static void
7536do_bkpt (void)
7537{
7538 /* Top 12 of 16 bits to bits 19:8. */
7539 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7540
c19d1205
ZW
7541 /* Bottom 4 of 16 bits to bits 3:0. */
7542 inst.instruction |= inst.operands[0].imm & 0xf;
7543}
09d92015 7544
c19d1205
ZW
7545static void
7546encode_branch (int default_reloc)
7547{
7548 if (inst.operands[0].hasreloc)
7549 {
0855e32b
NS
7550 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
7551 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
7552 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
7553 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
7554 ? BFD_RELOC_ARM_PLT32
7555 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 7556 }
b99bd4ef 7557 else
9ae92b05 7558 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 7559 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7560}
7561
b99bd4ef 7562static void
c19d1205 7563do_branch (void)
b99bd4ef 7564{
39b41c9c
PB
7565#ifdef OBJ_ELF
7566 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7567 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7568 else
7569#endif
7570 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7571}
7572
7573static void
7574do_bl (void)
7575{
7576#ifdef OBJ_ELF
7577 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7578 {
7579 if (inst.cond == COND_ALWAYS)
7580 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7581 else
7582 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7583 }
7584 else
7585#endif
7586 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7587}
b99bd4ef 7588
c19d1205
ZW
7589/* ARM V5 branch-link-exchange instruction (argument parse)
7590 BLX <target_addr> ie BLX(1)
7591 BLX{<condition>} <Rm> ie BLX(2)
7592 Unfortunately, there are two different opcodes for this mnemonic.
7593 So, the insns[].value is not used, and the code here zaps values
7594 into inst.instruction.
7595 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7596
c19d1205
ZW
7597static void
7598do_blx (void)
7599{
7600 if (inst.operands[0].isreg)
b99bd4ef 7601 {
c19d1205
ZW
7602 /* Arg is a register; the opcode provided by insns[] is correct.
7603 It is not illegal to do "blx pc", just useless. */
7604 if (inst.operands[0].reg == REG_PC)
7605 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7606
c19d1205
ZW
7607 inst.instruction |= inst.operands[0].reg;
7608 }
7609 else
b99bd4ef 7610 {
c19d1205 7611 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7612 conditionally, and the opcode must be adjusted.
7613 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7614 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7615 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7616 inst.instruction = 0xfa000000;
267bf995 7617 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7618 }
c19d1205
ZW
7619}
7620
7621static void
7622do_bx (void)
7623{
845b51d6
PB
7624 bfd_boolean want_reloc;
7625
c19d1205
ZW
7626 if (inst.operands[0].reg == REG_PC)
7627 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7628
c19d1205 7629 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7630 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7631 it is for ARMv4t or earlier. */
7632 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7633 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7634 want_reloc = TRUE;
7635
5ad34203 7636#ifdef OBJ_ELF
845b51d6 7637 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7638#endif
584206db 7639 want_reloc = FALSE;
845b51d6
PB
7640
7641 if (want_reloc)
7642 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7643}
7644
c19d1205
ZW
7645
7646/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7647
7648static void
c19d1205 7649do_bxj (void)
a737bd4d 7650{
c19d1205
ZW
7651 if (inst.operands[0].reg == REG_PC)
7652 as_tsktsk (_("use of r15 in bxj is not really useful"));
7653
7654 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7655}
7656
c19d1205
ZW
7657/* Co-processor data operation:
7658 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7659 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7660static void
7661do_cdp (void)
7662{
7663 inst.instruction |= inst.operands[0].reg << 8;
7664 inst.instruction |= inst.operands[1].imm << 20;
7665 inst.instruction |= inst.operands[2].reg << 12;
7666 inst.instruction |= inst.operands[3].reg << 16;
7667 inst.instruction |= inst.operands[4].reg;
7668 inst.instruction |= inst.operands[5].imm << 5;
7669}
a737bd4d
NC
7670
7671static void
c19d1205 7672do_cmp (void)
a737bd4d 7673{
c19d1205
ZW
7674 inst.instruction |= inst.operands[0].reg << 16;
7675 encode_arm_shifter_operand (1);
a737bd4d
NC
7676}
7677
c19d1205
ZW
7678/* Transfer between coprocessor and ARM registers.
7679 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7680 MRC2
7681 MCR{cond}
7682 MCR2
7683
7684 No special properties. */
09d92015
MM
7685
7686static void
c19d1205 7687do_co_reg (void)
09d92015 7688{
fdfde340
JM
7689 unsigned Rd;
7690
7691 Rd = inst.operands[2].reg;
7692 if (thumb_mode)
7693 {
7694 if (inst.instruction == 0xee000010
7695 || inst.instruction == 0xfe000010)
7696 /* MCR, MCR2 */
7697 reject_bad_reg (Rd);
7698 else
7699 /* MRC, MRC2 */
7700 constraint (Rd == REG_SP, BAD_SP);
7701 }
7702 else
7703 {
7704 /* MCR */
7705 if (inst.instruction == 0xe000010)
7706 constraint (Rd == REG_PC, BAD_PC);
7707 }
7708
7709
c19d1205
ZW
7710 inst.instruction |= inst.operands[0].reg << 8;
7711 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7712 inst.instruction |= Rd << 12;
c19d1205
ZW
7713 inst.instruction |= inst.operands[3].reg << 16;
7714 inst.instruction |= inst.operands[4].reg;
7715 inst.instruction |= inst.operands[5].imm << 5;
7716}
09d92015 7717
c19d1205
ZW
7718/* Transfer between coprocessor register and pair of ARM registers.
7719 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7720 MCRR2
7721 MRRC{cond}
7722 MRRC2
b99bd4ef 7723
c19d1205 7724 Two XScale instructions are special cases of these:
09d92015 7725
c19d1205
ZW
7726 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7727 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7728
5f4273c7 7729 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7730
c19d1205
ZW
7731static void
7732do_co_reg2c (void)
7733{
fdfde340
JM
7734 unsigned Rd, Rn;
7735
7736 Rd = inst.operands[2].reg;
7737 Rn = inst.operands[3].reg;
7738
7739 if (thumb_mode)
7740 {
7741 reject_bad_reg (Rd);
7742 reject_bad_reg (Rn);
7743 }
7744 else
7745 {
7746 constraint (Rd == REG_PC, BAD_PC);
7747 constraint (Rn == REG_PC, BAD_PC);
7748 }
7749
c19d1205
ZW
7750 inst.instruction |= inst.operands[0].reg << 8;
7751 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7752 inst.instruction |= Rd << 12;
7753 inst.instruction |= Rn << 16;
c19d1205 7754 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7755}
7756
c19d1205
ZW
7757static void
7758do_cpsi (void)
7759{
7760 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7761 if (inst.operands[1].present)
7762 {
7763 inst.instruction |= CPSI_MMOD;
7764 inst.instruction |= inst.operands[1].imm;
7765 }
c19d1205 7766}
b99bd4ef 7767
62b3e311
PB
7768static void
7769do_dbg (void)
7770{
7771 inst.instruction |= inst.operands[0].imm;
7772}
7773
eea54501
MGD
7774static void
7775do_div (void)
7776{
7777 unsigned Rd, Rn, Rm;
7778
7779 Rd = inst.operands[0].reg;
7780 Rn = (inst.operands[1].present
7781 ? inst.operands[1].reg : Rd);
7782 Rm = inst.operands[2].reg;
7783
7784 constraint ((Rd == REG_PC), BAD_PC);
7785 constraint ((Rn == REG_PC), BAD_PC);
7786 constraint ((Rm == REG_PC), BAD_PC);
7787
7788 inst.instruction |= Rd << 16;
7789 inst.instruction |= Rn << 0;
7790 inst.instruction |= Rm << 8;
7791}
7792
b99bd4ef 7793static void
c19d1205 7794do_it (void)
b99bd4ef 7795{
c19d1205 7796 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7797 process it to do the validation as if in
7798 thumb mode, just in case the code gets
7799 assembled for thumb using the unified syntax. */
7800
c19d1205 7801 inst.size = 0;
e07e6e58
NC
7802 if (unified_syntax)
7803 {
7804 set_it_insn_type (IT_INSN);
7805 now_it.mask = (inst.instruction & 0xf) | 0x10;
7806 now_it.cc = inst.operands[0].imm;
7807 }
09d92015 7808}
b99bd4ef 7809
6530b175
NC
7810/* If there is only one register in the register list,
7811 then return its register number. Otherwise return -1. */
7812static int
7813only_one_reg_in_list (int range)
7814{
7815 int i = ffs (range) - 1;
7816 return (i > 15 || range != (1 << i)) ? -1 : i;
7817}
7818
09d92015 7819static void
6530b175 7820encode_ldmstm(int from_push_pop_mnem)
ea6ef066 7821{
c19d1205
ZW
7822 int base_reg = inst.operands[0].reg;
7823 int range = inst.operands[1].imm;
6530b175 7824 int one_reg;
ea6ef066 7825
c19d1205
ZW
7826 inst.instruction |= base_reg << 16;
7827 inst.instruction |= range;
ea6ef066 7828
c19d1205
ZW
7829 if (inst.operands[1].writeback)
7830 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7831
c19d1205 7832 if (inst.operands[0].writeback)
ea6ef066 7833 {
c19d1205
ZW
7834 inst.instruction |= WRITE_BACK;
7835 /* Check for unpredictable uses of writeback. */
7836 if (inst.instruction & LOAD_BIT)
09d92015 7837 {
c19d1205
ZW
7838 /* Not allowed in LDM type 2. */
7839 if ((inst.instruction & LDM_TYPE_2_OR_3)
7840 && ((range & (1 << REG_PC)) == 0))
7841 as_warn (_("writeback of base register is UNPREDICTABLE"));
7842 /* Only allowed if base reg not in list for other types. */
7843 else if (range & (1 << base_reg))
7844 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7845 }
7846 else /* STM. */
7847 {
7848 /* Not allowed for type 2. */
7849 if (inst.instruction & LDM_TYPE_2_OR_3)
7850 as_warn (_("writeback of base register is UNPREDICTABLE"));
7851 /* Only allowed if base reg not in list, or first in list. */
7852 else if ((range & (1 << base_reg))
7853 && (range & ((1 << base_reg) - 1)))
7854 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7855 }
ea6ef066 7856 }
6530b175
NC
7857
7858 /* If PUSH/POP has only one register, then use the A2 encoding. */
7859 one_reg = only_one_reg_in_list (range);
7860 if (from_push_pop_mnem && one_reg >= 0)
7861 {
7862 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
7863
7864 inst.instruction &= A_COND_MASK;
7865 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
7866 inst.instruction |= one_reg << 12;
7867 }
7868}
7869
7870static void
7871do_ldmstm (void)
7872{
7873 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
7874}
7875
c19d1205
ZW
7876/* ARMv5TE load-consecutive (argument parse)
7877 Mode is like LDRH.
7878
7879 LDRccD R, mode
7880 STRccD R, mode. */
7881
a737bd4d 7882static void
c19d1205 7883do_ldrd (void)
a737bd4d 7884{
c19d1205 7885 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 7886 _("first transfer register must be even"));
c19d1205
ZW
7887 constraint (inst.operands[1].present
7888 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 7889 _("can only transfer two consecutive registers"));
c19d1205
ZW
7890 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7891 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7892
c19d1205
ZW
7893 if (!inst.operands[1].present)
7894 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7895
c56791bb
RE
7896 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7897 register and the first register written; we have to diagnose
7898 overlap between the base and the second register written here. */
ea6ef066 7899
c56791bb
RE
7900 if (inst.operands[2].reg == inst.operands[1].reg
7901 && (inst.operands[2].writeback || inst.operands[2].postind))
7902 as_warn (_("base register written back, and overlaps "
7903 "second transfer register"));
b05fe5cf 7904
c56791bb
RE
7905 if (!(inst.instruction & V4_STR_BIT))
7906 {
c19d1205 7907 /* For an index-register load, the index register must not overlap the
c56791bb
RE
7908 destination (even if not write-back). */
7909 if (inst.operands[2].immisreg
7910 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7911 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
7912 as_warn (_("index register overlaps transfer register"));
b05fe5cf 7913 }
c19d1205
ZW
7914 inst.instruction |= inst.operands[0].reg << 12;
7915 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7916}
7917
7918static void
c19d1205 7919do_ldrex (void)
b05fe5cf 7920{
c19d1205
ZW
7921 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7922 || inst.operands[1].postind || inst.operands[1].writeback
7923 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7924 || inst.operands[1].negative
7925 /* This can arise if the programmer has written
7926 strex rN, rM, foo
7927 or if they have mistakenly used a register name as the last
7928 operand, eg:
7929 strex rN, rM, rX
7930 It is very difficult to distinguish between these two cases
7931 because "rX" might actually be a label. ie the register
7932 name has been occluded by a symbol of the same name. So we
7933 just generate a general 'bad addressing mode' type error
7934 message and leave it up to the programmer to discover the
7935 true cause and fix their mistake. */
7936 || (inst.operands[1].reg == REG_PC),
7937 BAD_ADDR_MODE);
b05fe5cf 7938
c19d1205
ZW
7939 constraint (inst.reloc.exp.X_op != O_constant
7940 || inst.reloc.exp.X_add_number != 0,
7941 _("offset must be zero in ARM encoding"));
b05fe5cf 7942
5be8be5d
DG
7943 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7944
c19d1205
ZW
7945 inst.instruction |= inst.operands[0].reg << 12;
7946 inst.instruction |= inst.operands[1].reg << 16;
7947 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7948}
7949
7950static void
c19d1205 7951do_ldrexd (void)
b05fe5cf 7952{
c19d1205
ZW
7953 constraint (inst.operands[0].reg % 2 != 0,
7954 _("even register required"));
7955 constraint (inst.operands[1].present
7956 && inst.operands[1].reg != inst.operands[0].reg + 1,
7957 _("can only load two consecutive registers"));
7958 /* If op 1 were present and equal to PC, this function wouldn't
7959 have been called in the first place. */
7960 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7961
c19d1205
ZW
7962 inst.instruction |= inst.operands[0].reg << 12;
7963 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7964}
7965
1be5fd2e
NC
7966/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
7967 which is not a multiple of four is UNPREDICTABLE. */
7968static void
7969check_ldr_r15_aligned (void)
7970{
7971 constraint (!(inst.operands[1].immisreg)
7972 && (inst.operands[0].reg == REG_PC
7973 && inst.operands[1].reg == REG_PC
7974 && (inst.reloc.exp.X_add_number & 0x3)),
7975 _("ldr to register 15 must be 4-byte alligned"));
7976}
7977
b05fe5cf 7978static void
c19d1205 7979do_ldst (void)
b05fe5cf 7980{
c19d1205
ZW
7981 inst.instruction |= inst.operands[0].reg << 12;
7982 if (!inst.operands[1].isreg)
7983 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7984 return;
c19d1205 7985 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 7986 check_ldr_r15_aligned ();
b05fe5cf
ZW
7987}
7988
7989static void
c19d1205 7990do_ldstt (void)
b05fe5cf 7991{
c19d1205
ZW
7992 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7993 reject [Rn,...]. */
7994 if (inst.operands[1].preind)
b05fe5cf 7995 {
bd3ba5d1
NC
7996 constraint (inst.reloc.exp.X_op != O_constant
7997 || inst.reloc.exp.X_add_number != 0,
c19d1205 7998 _("this instruction requires a post-indexed address"));
b05fe5cf 7999
c19d1205
ZW
8000 inst.operands[1].preind = 0;
8001 inst.operands[1].postind = 1;
8002 inst.operands[1].writeback = 1;
b05fe5cf 8003 }
c19d1205
ZW
8004 inst.instruction |= inst.operands[0].reg << 12;
8005 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8006}
b05fe5cf 8007
c19d1205 8008/* Halfword and signed-byte load/store operations. */
b05fe5cf 8009
c19d1205
ZW
8010static void
8011do_ldstv4 (void)
8012{
ff4a8d2b 8013 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8014 inst.instruction |= inst.operands[0].reg << 12;
8015 if (!inst.operands[1].isreg)
8016 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 8017 return;
c19d1205 8018 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
8019}
8020
8021static void
c19d1205 8022do_ldsttv4 (void)
b05fe5cf 8023{
c19d1205
ZW
8024 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8025 reject [Rn,...]. */
8026 if (inst.operands[1].preind)
b05fe5cf 8027 {
bd3ba5d1
NC
8028 constraint (inst.reloc.exp.X_op != O_constant
8029 || inst.reloc.exp.X_add_number != 0,
c19d1205 8030 _("this instruction requires a post-indexed address"));
b05fe5cf 8031
c19d1205
ZW
8032 inst.operands[1].preind = 0;
8033 inst.operands[1].postind = 1;
8034 inst.operands[1].writeback = 1;
b05fe5cf 8035 }
c19d1205
ZW
8036 inst.instruction |= inst.operands[0].reg << 12;
8037 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8038}
b05fe5cf 8039
c19d1205
ZW
8040/* Co-processor register load/store.
8041 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8042static void
8043do_lstc (void)
8044{
8045 inst.instruction |= inst.operands[0].reg << 8;
8046 inst.instruction |= inst.operands[1].reg << 12;
8047 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
8048}
8049
b05fe5cf 8050static void
c19d1205 8051do_mlas (void)
b05fe5cf 8052{
8fb9d7b9 8053 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 8054 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 8055 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 8056 && !(inst.instruction & 0x00400000))
8fb9d7b9 8057 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 8058
c19d1205
ZW
8059 inst.instruction |= inst.operands[0].reg << 16;
8060 inst.instruction |= inst.operands[1].reg;
8061 inst.instruction |= inst.operands[2].reg << 8;
8062 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 8063}
b05fe5cf 8064
c19d1205
ZW
8065static void
8066do_mov (void)
8067{
8068 inst.instruction |= inst.operands[0].reg << 12;
8069 encode_arm_shifter_operand (1);
8070}
b05fe5cf 8071
c19d1205
ZW
8072/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8073static void
8074do_mov16 (void)
8075{
b6895b4f
PB
8076 bfd_vma imm;
8077 bfd_boolean top;
8078
8079 top = (inst.instruction & 0x00400000) != 0;
8080 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8081 _(":lower16: not allowed this instruction"));
8082 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8083 _(":upper16: not allowed instruction"));
c19d1205 8084 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
8085 if (inst.reloc.type == BFD_RELOC_UNUSED)
8086 {
8087 imm = inst.reloc.exp.X_add_number;
8088 /* The value is in two pieces: 0:11, 16:19. */
8089 inst.instruction |= (imm & 0x00000fff);
8090 inst.instruction |= (imm & 0x0000f000) << 4;
8091 }
b05fe5cf 8092}
b99bd4ef 8093
037e8744
JB
8094static void do_vfp_nsyn_opcode (const char *);
8095
8096static int
8097do_vfp_nsyn_mrs (void)
8098{
8099 if (inst.operands[0].isvec)
8100 {
8101 if (inst.operands[1].reg != 1)
8102 first_error (_("operand 1 must be FPSCR"));
8103 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8104 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8105 do_vfp_nsyn_opcode ("fmstat");
8106 }
8107 else if (inst.operands[1].isvec)
8108 do_vfp_nsyn_opcode ("fmrx");
8109 else
8110 return FAIL;
5f4273c7 8111
037e8744
JB
8112 return SUCCESS;
8113}
8114
8115static int
8116do_vfp_nsyn_msr (void)
8117{
8118 if (inst.operands[0].isvec)
8119 do_vfp_nsyn_opcode ("fmxr");
8120 else
8121 return FAIL;
8122
8123 return SUCCESS;
8124}
8125
f7c21dc7
NC
8126static void
8127do_vmrs (void)
8128{
8129 unsigned Rt = inst.operands[0].reg;
fa94de6b 8130
f7c21dc7
NC
8131 if (thumb_mode && inst.operands[0].reg == REG_SP)
8132 {
8133 inst.error = BAD_SP;
8134 return;
8135 }
8136
8137 /* APSR_ sets isvec. All other refs to PC are illegal. */
8138 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
8139 {
8140 inst.error = BAD_PC;
8141 return;
8142 }
8143
7465e07a
NC
8144 switch (inst.operands[1].reg)
8145 {
8146 case 0: /* FPSID */
8147 case 1: /* FPSCR */
8148 case 6: /* MVFR1 */
8149 case 7: /* MVFR0 */
8150 case 8: /* FPEXC */
8151 inst.instruction |= (inst.operands[1].reg << 16);
8152 break;
8153 default:
8154 first_error (_("operand 1 must be a VFP extension System Register"));
8155 }
f7c21dc7
NC
8156
8157 inst.instruction |= (Rt << 12);
8158}
8159
8160static void
8161do_vmsr (void)
8162{
8163 unsigned Rt = inst.operands[1].reg;
fa94de6b 8164
f7c21dc7
NC
8165 if (thumb_mode)
8166 reject_bad_reg (Rt);
8167 else if (Rt == REG_PC)
8168 {
8169 inst.error = BAD_PC;
8170 return;
8171 }
8172
7465e07a
NC
8173 switch (inst.operands[0].reg)
8174 {
8175 case 0: /* FPSID */
8176 case 1: /* FPSCR */
8177 case 8: /* FPEXC */
8178 inst.instruction |= (inst.operands[0].reg << 16);
8179 break;
8180 default:
8181 first_error (_("operand 0 must be FPSID or FPSCR pr FPEXC"));
8182 }
f7c21dc7
NC
8183
8184 inst.instruction |= (Rt << 12);
8185}
8186
b99bd4ef 8187static void
c19d1205 8188do_mrs (void)
b99bd4ef 8189{
90ec0d68
MGD
8190 unsigned br;
8191
037e8744
JB
8192 if (do_vfp_nsyn_mrs () == SUCCESS)
8193 return;
8194
ff4a8d2b 8195 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 8196 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
8197
8198 if (inst.operands[1].isreg)
8199 {
8200 br = inst.operands[1].reg;
8201 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
8202 as_bad (_("bad register for mrs"));
8203 }
8204 else
8205 {
8206 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
8207 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
8208 != (PSR_c|PSR_f),
d2cd1205 8209 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
8210 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
8211 }
8212
8213 inst.instruction |= br;
c19d1205 8214}
b99bd4ef 8215
c19d1205
ZW
8216/* Two possible forms:
8217 "{C|S}PSR_<field>, Rm",
8218 "{C|S}PSR_f, #expression". */
b99bd4ef 8219
c19d1205
ZW
8220static void
8221do_msr (void)
8222{
037e8744
JB
8223 if (do_vfp_nsyn_msr () == SUCCESS)
8224 return;
8225
c19d1205
ZW
8226 inst.instruction |= inst.operands[0].imm;
8227 if (inst.operands[1].isreg)
8228 inst.instruction |= inst.operands[1].reg;
8229 else
b99bd4ef 8230 {
c19d1205
ZW
8231 inst.instruction |= INST_IMMEDIATE;
8232 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8233 inst.reloc.pc_rel = 0;
b99bd4ef 8234 }
b99bd4ef
NC
8235}
8236
c19d1205
ZW
8237static void
8238do_mul (void)
a737bd4d 8239{
ff4a8d2b
NC
8240 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
8241
c19d1205
ZW
8242 if (!inst.operands[2].present)
8243 inst.operands[2].reg = inst.operands[0].reg;
8244 inst.instruction |= inst.operands[0].reg << 16;
8245 inst.instruction |= inst.operands[1].reg;
8246 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 8247
8fb9d7b9
MS
8248 if (inst.operands[0].reg == inst.operands[1].reg
8249 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8250 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
8251}
8252
c19d1205
ZW
8253/* Long Multiply Parser
8254 UMULL RdLo, RdHi, Rm, Rs
8255 SMULL RdLo, RdHi, Rm, Rs
8256 UMLAL RdLo, RdHi, Rm, Rs
8257 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
8258
8259static void
c19d1205 8260do_mull (void)
b99bd4ef 8261{
c19d1205
ZW
8262 inst.instruction |= inst.operands[0].reg << 12;
8263 inst.instruction |= inst.operands[1].reg << 16;
8264 inst.instruction |= inst.operands[2].reg;
8265 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 8266
682b27ad
PB
8267 /* rdhi and rdlo must be different. */
8268 if (inst.operands[0].reg == inst.operands[1].reg)
8269 as_tsktsk (_("rdhi and rdlo must be different"));
8270
8271 /* rdhi, rdlo and rm must all be different before armv6. */
8272 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 8273 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 8274 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
8275 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
8276}
b99bd4ef 8277
c19d1205
ZW
8278static void
8279do_nop (void)
8280{
e7495e45
NS
8281 if (inst.operands[0].present
8282 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
8283 {
8284 /* Architectural NOP hints are CPSR sets with no bits selected. */
8285 inst.instruction &= 0xf0000000;
e7495e45
NS
8286 inst.instruction |= 0x0320f000;
8287 if (inst.operands[0].present)
8288 inst.instruction |= inst.operands[0].imm;
c19d1205 8289 }
b99bd4ef
NC
8290}
8291
c19d1205
ZW
8292/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
8293 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
8294 Condition defaults to COND_ALWAYS.
8295 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
8296
8297static void
c19d1205 8298do_pkhbt (void)
b99bd4ef 8299{
c19d1205
ZW
8300 inst.instruction |= inst.operands[0].reg << 12;
8301 inst.instruction |= inst.operands[1].reg << 16;
8302 inst.instruction |= inst.operands[2].reg;
8303 if (inst.operands[3].present)
8304 encode_arm_shift (3);
8305}
b99bd4ef 8306
c19d1205 8307/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 8308
c19d1205
ZW
8309static void
8310do_pkhtb (void)
8311{
8312 if (!inst.operands[3].present)
b99bd4ef 8313 {
c19d1205
ZW
8314 /* If the shift specifier is omitted, turn the instruction
8315 into pkhbt rd, rm, rn. */
8316 inst.instruction &= 0xfff00010;
8317 inst.instruction |= inst.operands[0].reg << 12;
8318 inst.instruction |= inst.operands[1].reg;
8319 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8320 }
8321 else
8322 {
c19d1205
ZW
8323 inst.instruction |= inst.operands[0].reg << 12;
8324 inst.instruction |= inst.operands[1].reg << 16;
8325 inst.instruction |= inst.operands[2].reg;
8326 encode_arm_shift (3);
b99bd4ef
NC
8327 }
8328}
8329
c19d1205 8330/* ARMv5TE: Preload-Cache
60e5ef9f 8331 MP Extensions: Preload for write
c19d1205 8332
60e5ef9f 8333 PLD(W) <addr_mode>
c19d1205
ZW
8334
8335 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
8336
8337static void
c19d1205 8338do_pld (void)
b99bd4ef 8339{
c19d1205
ZW
8340 constraint (!inst.operands[0].isreg,
8341 _("'[' expected after PLD mnemonic"));
8342 constraint (inst.operands[0].postind,
8343 _("post-indexed expression used in preload instruction"));
8344 constraint (inst.operands[0].writeback,
8345 _("writeback used in preload instruction"));
8346 constraint (!inst.operands[0].preind,
8347 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
8348 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8349}
b99bd4ef 8350
62b3e311
PB
8351/* ARMv7: PLI <addr_mode> */
8352static void
8353do_pli (void)
8354{
8355 constraint (!inst.operands[0].isreg,
8356 _("'[' expected after PLI mnemonic"));
8357 constraint (inst.operands[0].postind,
8358 _("post-indexed expression used in preload instruction"));
8359 constraint (inst.operands[0].writeback,
8360 _("writeback used in preload instruction"));
8361 constraint (!inst.operands[0].preind,
8362 _("unindexed addressing used in preload instruction"));
8363 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8364 inst.instruction &= ~PRE_INDEX;
8365}
8366
c19d1205
ZW
8367static void
8368do_push_pop (void)
8369{
8370 inst.operands[1] = inst.operands[0];
8371 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8372 inst.operands[0].isreg = 1;
8373 inst.operands[0].writeback = 1;
8374 inst.operands[0].reg = REG_SP;
6530b175 8375 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 8376}
b99bd4ef 8377
c19d1205
ZW
8378/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8379 word at the specified address and the following word
8380 respectively.
8381 Unconditionally executed.
8382 Error if Rn is R15. */
b99bd4ef 8383
c19d1205
ZW
8384static void
8385do_rfe (void)
8386{
8387 inst.instruction |= inst.operands[0].reg << 16;
8388 if (inst.operands[0].writeback)
8389 inst.instruction |= WRITE_BACK;
8390}
b99bd4ef 8391
c19d1205 8392/* ARM V6 ssat (argument parse). */
b99bd4ef 8393
c19d1205
ZW
8394static void
8395do_ssat (void)
8396{
8397 inst.instruction |= inst.operands[0].reg << 12;
8398 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8399 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8400
c19d1205
ZW
8401 if (inst.operands[3].present)
8402 encode_arm_shift (3);
b99bd4ef
NC
8403}
8404
c19d1205 8405/* ARM V6 usat (argument parse). */
b99bd4ef
NC
8406
8407static void
c19d1205 8408do_usat (void)
b99bd4ef 8409{
c19d1205
ZW
8410 inst.instruction |= inst.operands[0].reg << 12;
8411 inst.instruction |= inst.operands[1].imm << 16;
8412 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8413
c19d1205
ZW
8414 if (inst.operands[3].present)
8415 encode_arm_shift (3);
b99bd4ef
NC
8416}
8417
c19d1205 8418/* ARM V6 ssat16 (argument parse). */
09d92015
MM
8419
8420static void
c19d1205 8421do_ssat16 (void)
09d92015 8422{
c19d1205
ZW
8423 inst.instruction |= inst.operands[0].reg << 12;
8424 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8425 inst.instruction |= inst.operands[2].reg;
09d92015
MM
8426}
8427
c19d1205
ZW
8428static void
8429do_usat16 (void)
a737bd4d 8430{
c19d1205
ZW
8431 inst.instruction |= inst.operands[0].reg << 12;
8432 inst.instruction |= inst.operands[1].imm << 16;
8433 inst.instruction |= inst.operands[2].reg;
8434}
a737bd4d 8435
c19d1205
ZW
8436/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8437 preserving the other bits.
a737bd4d 8438
c19d1205
ZW
8439 setend <endian_specifier>, where <endian_specifier> is either
8440 BE or LE. */
a737bd4d 8441
c19d1205
ZW
8442static void
8443do_setend (void)
8444{
8445 if (inst.operands[0].imm)
8446 inst.instruction |= 0x200;
a737bd4d
NC
8447}
8448
8449static void
c19d1205 8450do_shift (void)
a737bd4d 8451{
c19d1205
ZW
8452 unsigned int Rm = (inst.operands[1].present
8453 ? inst.operands[1].reg
8454 : inst.operands[0].reg);
a737bd4d 8455
c19d1205
ZW
8456 inst.instruction |= inst.operands[0].reg << 12;
8457 inst.instruction |= Rm;
8458 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 8459 {
c19d1205
ZW
8460 inst.instruction |= inst.operands[2].reg << 8;
8461 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
8462 /* PR 12854: Error on extraneous shifts. */
8463 constraint (inst.operands[2].shifted,
8464 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
8465 }
8466 else
c19d1205 8467 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
8468}
8469
09d92015 8470static void
3eb17e6b 8471do_smc (void)
09d92015 8472{
3eb17e6b 8473 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 8474 inst.reloc.pc_rel = 0;
09d92015
MM
8475}
8476
90ec0d68
MGD
8477static void
8478do_hvc (void)
8479{
8480 inst.reloc.type = BFD_RELOC_ARM_HVC;
8481 inst.reloc.pc_rel = 0;
8482}
8483
09d92015 8484static void
c19d1205 8485do_swi (void)
09d92015 8486{
c19d1205
ZW
8487 inst.reloc.type = BFD_RELOC_ARM_SWI;
8488 inst.reloc.pc_rel = 0;
09d92015
MM
8489}
8490
c19d1205
ZW
8491/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8492 SMLAxy{cond} Rd,Rm,Rs,Rn
8493 SMLAWy{cond} Rd,Rm,Rs,Rn
8494 Error if any register is R15. */
e16bb312 8495
c19d1205
ZW
8496static void
8497do_smla (void)
e16bb312 8498{
c19d1205
ZW
8499 inst.instruction |= inst.operands[0].reg << 16;
8500 inst.instruction |= inst.operands[1].reg;
8501 inst.instruction |= inst.operands[2].reg << 8;
8502 inst.instruction |= inst.operands[3].reg << 12;
8503}
a737bd4d 8504
c19d1205
ZW
8505/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8506 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8507 Error if any register is R15.
8508 Warning if Rdlo == Rdhi. */
a737bd4d 8509
c19d1205
ZW
8510static void
8511do_smlal (void)
8512{
8513 inst.instruction |= inst.operands[0].reg << 12;
8514 inst.instruction |= inst.operands[1].reg << 16;
8515 inst.instruction |= inst.operands[2].reg;
8516 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 8517
c19d1205
ZW
8518 if (inst.operands[0].reg == inst.operands[1].reg)
8519 as_tsktsk (_("rdhi and rdlo must be different"));
8520}
a737bd4d 8521
c19d1205
ZW
8522/* ARM V5E (El Segundo) signed-multiply (argument parse)
8523 SMULxy{cond} Rd,Rm,Rs
8524 Error if any register is R15. */
a737bd4d 8525
c19d1205
ZW
8526static void
8527do_smul (void)
8528{
8529 inst.instruction |= inst.operands[0].reg << 16;
8530 inst.instruction |= inst.operands[1].reg;
8531 inst.instruction |= inst.operands[2].reg << 8;
8532}
a737bd4d 8533
b6702015
PB
8534/* ARM V6 srs (argument parse). The variable fields in the encoding are
8535 the same for both ARM and Thumb-2. */
a737bd4d 8536
c19d1205
ZW
8537static void
8538do_srs (void)
8539{
b6702015
PB
8540 int reg;
8541
8542 if (inst.operands[0].present)
8543 {
8544 reg = inst.operands[0].reg;
fdfde340 8545 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
8546 }
8547 else
fdfde340 8548 reg = REG_SP;
b6702015
PB
8549
8550 inst.instruction |= reg << 16;
8551 inst.instruction |= inst.operands[1].imm;
8552 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
8553 inst.instruction |= WRITE_BACK;
8554}
a737bd4d 8555
c19d1205 8556/* ARM V6 strex (argument parse). */
a737bd4d 8557
c19d1205
ZW
8558static void
8559do_strex (void)
8560{
8561 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8562 || inst.operands[2].postind || inst.operands[2].writeback
8563 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
8564 || inst.operands[2].negative
8565 /* See comment in do_ldrex(). */
8566 || (inst.operands[2].reg == REG_PC),
8567 BAD_ADDR_MODE);
a737bd4d 8568
c19d1205
ZW
8569 constraint (inst.operands[0].reg == inst.operands[1].reg
8570 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 8571
c19d1205
ZW
8572 constraint (inst.reloc.exp.X_op != O_constant
8573 || inst.reloc.exp.X_add_number != 0,
8574 _("offset must be zero in ARM encoding"));
a737bd4d 8575
c19d1205
ZW
8576 inst.instruction |= inst.operands[0].reg << 12;
8577 inst.instruction |= inst.operands[1].reg;
8578 inst.instruction |= inst.operands[2].reg << 16;
8579 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8580}
8581
877807f8
NC
8582static void
8583do_t_strexbh (void)
8584{
8585 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8586 || inst.operands[2].postind || inst.operands[2].writeback
8587 || inst.operands[2].immisreg || inst.operands[2].shifted
8588 || inst.operands[2].negative,
8589 BAD_ADDR_MODE);
8590
8591 constraint (inst.operands[0].reg == inst.operands[1].reg
8592 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8593
8594 do_rm_rd_rn ();
8595}
8596
e16bb312 8597static void
c19d1205 8598do_strexd (void)
e16bb312 8599{
c19d1205
ZW
8600 constraint (inst.operands[1].reg % 2 != 0,
8601 _("even register required"));
8602 constraint (inst.operands[2].present
8603 && inst.operands[2].reg != inst.operands[1].reg + 1,
8604 _("can only store two consecutive registers"));
8605 /* If op 2 were present and equal to PC, this function wouldn't
8606 have been called in the first place. */
8607 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8608
c19d1205
ZW
8609 constraint (inst.operands[0].reg == inst.operands[1].reg
8610 || inst.operands[0].reg == inst.operands[1].reg + 1
8611 || inst.operands[0].reg == inst.operands[3].reg,
8612 BAD_OVERLAP);
e16bb312 8613
c19d1205
ZW
8614 inst.instruction |= inst.operands[0].reg << 12;
8615 inst.instruction |= inst.operands[1].reg;
8616 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8617}
8618
c19d1205
ZW
8619/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8620 extends it to 32-bits, and adds the result to a value in another
8621 register. You can specify a rotation by 0, 8, 16, or 24 bits
8622 before extracting the 16-bit value.
8623 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8624 Condition defaults to COND_ALWAYS.
8625 Error if any register uses R15. */
8626
e16bb312 8627static void
c19d1205 8628do_sxtah (void)
e16bb312 8629{
c19d1205
ZW
8630 inst.instruction |= inst.operands[0].reg << 12;
8631 inst.instruction |= inst.operands[1].reg << 16;
8632 inst.instruction |= inst.operands[2].reg;
8633 inst.instruction |= inst.operands[3].imm << 10;
8634}
e16bb312 8635
c19d1205 8636/* ARM V6 SXTH.
e16bb312 8637
c19d1205
ZW
8638 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8639 Condition defaults to COND_ALWAYS.
8640 Error if any register uses R15. */
e16bb312
NC
8641
8642static void
c19d1205 8643do_sxth (void)
e16bb312 8644{
c19d1205
ZW
8645 inst.instruction |= inst.operands[0].reg << 12;
8646 inst.instruction |= inst.operands[1].reg;
8647 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8648}
c19d1205
ZW
8649\f
8650/* VFP instructions. In a logical order: SP variant first, monad
8651 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8652
8653static void
c19d1205 8654do_vfp_sp_monadic (void)
e16bb312 8655{
5287ad62
JB
8656 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8657 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8658}
8659
8660static void
c19d1205 8661do_vfp_sp_dyadic (void)
e16bb312 8662{
5287ad62
JB
8663 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8664 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8665 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8666}
8667
8668static void
c19d1205 8669do_vfp_sp_compare_z (void)
e16bb312 8670{
5287ad62 8671 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8672}
8673
8674static void
c19d1205 8675do_vfp_dp_sp_cvt (void)
e16bb312 8676{
5287ad62
JB
8677 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8678 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8679}
8680
8681static void
c19d1205 8682do_vfp_sp_dp_cvt (void)
e16bb312 8683{
5287ad62
JB
8684 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8685 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8686}
8687
8688static void
c19d1205 8689do_vfp_reg_from_sp (void)
e16bb312 8690{
c19d1205 8691 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8692 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8693}
8694
8695static void
c19d1205 8696do_vfp_reg2_from_sp2 (void)
e16bb312 8697{
c19d1205
ZW
8698 constraint (inst.operands[2].imm != 2,
8699 _("only two consecutive VFP SP registers allowed here"));
8700 inst.instruction |= inst.operands[0].reg << 12;
8701 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8702 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8703}
8704
8705static void
c19d1205 8706do_vfp_sp_from_reg (void)
e16bb312 8707{
5287ad62 8708 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8709 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8710}
8711
8712static void
c19d1205 8713do_vfp_sp2_from_reg2 (void)
e16bb312 8714{
c19d1205
ZW
8715 constraint (inst.operands[0].imm != 2,
8716 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8717 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8718 inst.instruction |= inst.operands[1].reg << 12;
8719 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8720}
8721
8722static void
c19d1205 8723do_vfp_sp_ldst (void)
e16bb312 8724{
5287ad62 8725 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 8726 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8727}
8728
8729static void
c19d1205 8730do_vfp_dp_ldst (void)
e16bb312 8731{
5287ad62 8732 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 8733 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8734}
8735
c19d1205 8736
e16bb312 8737static void
c19d1205 8738vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8739{
c19d1205
ZW
8740 if (inst.operands[0].writeback)
8741 inst.instruction |= WRITE_BACK;
8742 else
8743 constraint (ldstm_type != VFP_LDSTMIA,
8744 _("this addressing mode requires base-register writeback"));
8745 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8746 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 8747 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
8748}
8749
8750static void
c19d1205 8751vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8752{
c19d1205 8753 int count;
e16bb312 8754
c19d1205
ZW
8755 if (inst.operands[0].writeback)
8756 inst.instruction |= WRITE_BACK;
8757 else
8758 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8759 _("this addressing mode requires base-register writeback"));
e16bb312 8760
c19d1205 8761 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8762 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 8763
c19d1205
ZW
8764 count = inst.operands[1].imm << 1;
8765 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8766 count += 1;
e16bb312 8767
c19d1205 8768 inst.instruction |= count;
e16bb312
NC
8769}
8770
8771static void
c19d1205 8772do_vfp_sp_ldstmia (void)
e16bb312 8773{
c19d1205 8774 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8775}
8776
8777static void
c19d1205 8778do_vfp_sp_ldstmdb (void)
e16bb312 8779{
c19d1205 8780 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8781}
8782
8783static void
c19d1205 8784do_vfp_dp_ldstmia (void)
e16bb312 8785{
c19d1205 8786 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8787}
8788
8789static void
c19d1205 8790do_vfp_dp_ldstmdb (void)
e16bb312 8791{
c19d1205 8792 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8793}
8794
8795static void
c19d1205 8796do_vfp_xp_ldstmia (void)
e16bb312 8797{
c19d1205
ZW
8798 vfp_dp_ldstm (VFP_LDSTMIAX);
8799}
e16bb312 8800
c19d1205
ZW
8801static void
8802do_vfp_xp_ldstmdb (void)
8803{
8804 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 8805}
5287ad62
JB
8806
8807static void
8808do_vfp_dp_rd_rm (void)
8809{
8810 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8811 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8812}
8813
8814static void
8815do_vfp_dp_rn_rd (void)
8816{
8817 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8818 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8819}
8820
8821static void
8822do_vfp_dp_rd_rn (void)
8823{
8824 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8825 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8826}
8827
8828static void
8829do_vfp_dp_rd_rn_rm (void)
8830{
8831 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8832 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8833 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8834}
8835
8836static void
8837do_vfp_dp_rd (void)
8838{
8839 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8840}
8841
8842static void
8843do_vfp_dp_rm_rd_rn (void)
8844{
8845 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8846 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8847 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8848}
8849
8850/* VFPv3 instructions. */
8851static void
8852do_vfp_sp_const (void)
8853{
8854 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8855 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8856 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8857}
8858
8859static void
8860do_vfp_dp_const (void)
8861{
8862 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8863 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8864 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8865}
8866
8867static void
8868vfp_conv (int srcsize)
8869{
5f1af56b
MGD
8870 int immbits = srcsize - inst.operands[1].imm;
8871
fa94de6b
RM
8872 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
8873 {
5f1af56b
MGD
8874 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
8875 i.e. immbits must be in range 0 - 16. */
8876 inst.error = _("immediate value out of range, expected range [0, 16]");
8877 return;
8878 }
fa94de6b 8879 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
8880 {
8881 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
8882 i.e. immbits must be in range 0 - 31. */
8883 inst.error = _("immediate value out of range, expected range [1, 32]");
8884 return;
8885 }
8886
5287ad62
JB
8887 inst.instruction |= (immbits & 1) << 5;
8888 inst.instruction |= (immbits >> 1);
8889}
8890
8891static void
8892do_vfp_sp_conv_16 (void)
8893{
8894 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8895 vfp_conv (16);
8896}
8897
8898static void
8899do_vfp_dp_conv_16 (void)
8900{
8901 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8902 vfp_conv (16);
8903}
8904
8905static void
8906do_vfp_sp_conv_32 (void)
8907{
8908 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8909 vfp_conv (32);
8910}
8911
8912static void
8913do_vfp_dp_conv_32 (void)
8914{
8915 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8916 vfp_conv (32);
8917}
c19d1205
ZW
8918\f
8919/* FPA instructions. Also in a logical order. */
e16bb312 8920
c19d1205
ZW
8921static void
8922do_fpa_cmp (void)
8923{
8924 inst.instruction |= inst.operands[0].reg << 16;
8925 inst.instruction |= inst.operands[1].reg;
8926}
b99bd4ef
NC
8927
8928static void
c19d1205 8929do_fpa_ldmstm (void)
b99bd4ef 8930{
c19d1205
ZW
8931 inst.instruction |= inst.operands[0].reg << 12;
8932 switch (inst.operands[1].imm)
8933 {
8934 case 1: inst.instruction |= CP_T_X; break;
8935 case 2: inst.instruction |= CP_T_Y; break;
8936 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8937 case 4: break;
8938 default: abort ();
8939 }
b99bd4ef 8940
c19d1205
ZW
8941 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8942 {
8943 /* The instruction specified "ea" or "fd", so we can only accept
8944 [Rn]{!}. The instruction does not really support stacking or
8945 unstacking, so we have to emulate these by setting appropriate
8946 bits and offsets. */
8947 constraint (inst.reloc.exp.X_op != O_constant
8948 || inst.reloc.exp.X_add_number != 0,
8949 _("this instruction does not support indexing"));
b99bd4ef 8950
c19d1205
ZW
8951 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8952 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8953
c19d1205
ZW
8954 if (!(inst.instruction & INDEX_UP))
8955 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8956
c19d1205
ZW
8957 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8958 {
8959 inst.operands[2].preind = 0;
8960 inst.operands[2].postind = 1;
8961 }
8962 }
b99bd4ef 8963
c19d1205 8964 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8965}
c19d1205
ZW
8966\f
8967/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8968
c19d1205
ZW
8969static void
8970do_iwmmxt_tandorc (void)
8971{
8972 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8973}
b99bd4ef 8974
c19d1205
ZW
8975static void
8976do_iwmmxt_textrc (void)
8977{
8978 inst.instruction |= inst.operands[0].reg << 12;
8979 inst.instruction |= inst.operands[1].imm;
8980}
b99bd4ef
NC
8981
8982static void
c19d1205 8983do_iwmmxt_textrm (void)
b99bd4ef 8984{
c19d1205
ZW
8985 inst.instruction |= inst.operands[0].reg << 12;
8986 inst.instruction |= inst.operands[1].reg << 16;
8987 inst.instruction |= inst.operands[2].imm;
8988}
b99bd4ef 8989
c19d1205
ZW
8990static void
8991do_iwmmxt_tinsr (void)
8992{
8993 inst.instruction |= inst.operands[0].reg << 16;
8994 inst.instruction |= inst.operands[1].reg << 12;
8995 inst.instruction |= inst.operands[2].imm;
8996}
b99bd4ef 8997
c19d1205
ZW
8998static void
8999do_iwmmxt_tmia (void)
9000{
9001 inst.instruction |= inst.operands[0].reg << 5;
9002 inst.instruction |= inst.operands[1].reg;
9003 inst.instruction |= inst.operands[2].reg << 12;
9004}
b99bd4ef 9005
c19d1205
ZW
9006static void
9007do_iwmmxt_waligni (void)
9008{
9009 inst.instruction |= inst.operands[0].reg << 12;
9010 inst.instruction |= inst.operands[1].reg << 16;
9011 inst.instruction |= inst.operands[2].reg;
9012 inst.instruction |= inst.operands[3].imm << 20;
9013}
b99bd4ef 9014
2d447fca
JM
9015static void
9016do_iwmmxt_wmerge (void)
9017{
9018 inst.instruction |= inst.operands[0].reg << 12;
9019 inst.instruction |= inst.operands[1].reg << 16;
9020 inst.instruction |= inst.operands[2].reg;
9021 inst.instruction |= inst.operands[3].imm << 21;
9022}
9023
c19d1205
ZW
9024static void
9025do_iwmmxt_wmov (void)
9026{
9027 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9028 inst.instruction |= inst.operands[0].reg << 12;
9029 inst.instruction |= inst.operands[1].reg << 16;
9030 inst.instruction |= inst.operands[1].reg;
9031}
b99bd4ef 9032
c19d1205
ZW
9033static void
9034do_iwmmxt_wldstbh (void)
9035{
8f06b2d8 9036 int reloc;
c19d1205 9037 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
9038 if (thumb_mode)
9039 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9040 else
9041 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9042 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
9043}
9044
c19d1205
ZW
9045static void
9046do_iwmmxt_wldstw (void)
9047{
9048 /* RIWR_RIWC clears .isreg for a control register. */
9049 if (!inst.operands[0].isreg)
9050 {
9051 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9052 inst.instruction |= 0xf0000000;
9053 }
b99bd4ef 9054
c19d1205
ZW
9055 inst.instruction |= inst.operands[0].reg << 12;
9056 encode_arm_cp_address (1, TRUE, TRUE, 0);
9057}
b99bd4ef
NC
9058
9059static void
c19d1205 9060do_iwmmxt_wldstd (void)
b99bd4ef 9061{
c19d1205 9062 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
9063 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9064 && inst.operands[1].immisreg)
9065 {
9066 inst.instruction &= ~0x1a000ff;
9067 inst.instruction |= (0xf << 28);
9068 if (inst.operands[1].preind)
9069 inst.instruction |= PRE_INDEX;
9070 if (!inst.operands[1].negative)
9071 inst.instruction |= INDEX_UP;
9072 if (inst.operands[1].writeback)
9073 inst.instruction |= WRITE_BACK;
9074 inst.instruction |= inst.operands[1].reg << 16;
9075 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9076 inst.instruction |= inst.operands[1].imm;
9077 }
9078 else
9079 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 9080}
b99bd4ef 9081
c19d1205
ZW
9082static void
9083do_iwmmxt_wshufh (void)
9084{
9085 inst.instruction |= inst.operands[0].reg << 12;
9086 inst.instruction |= inst.operands[1].reg << 16;
9087 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
9088 inst.instruction |= (inst.operands[2].imm & 0x0f);
9089}
b99bd4ef 9090
c19d1205
ZW
9091static void
9092do_iwmmxt_wzero (void)
9093{
9094 /* WZERO reg is an alias for WANDN reg, reg, reg. */
9095 inst.instruction |= inst.operands[0].reg;
9096 inst.instruction |= inst.operands[0].reg << 12;
9097 inst.instruction |= inst.operands[0].reg << 16;
9098}
2d447fca
JM
9099
9100static void
9101do_iwmmxt_wrwrwr_or_imm5 (void)
9102{
9103 if (inst.operands[2].isreg)
9104 do_rd_rn_rm ();
9105 else {
9106 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
9107 _("immediate operand requires iWMMXt2"));
9108 do_rd_rn ();
9109 if (inst.operands[2].imm == 0)
9110 {
9111 switch ((inst.instruction >> 20) & 0xf)
9112 {
9113 case 4:
9114 case 5:
9115 case 6:
5f4273c7 9116 case 7:
2d447fca
JM
9117 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
9118 inst.operands[2].imm = 16;
9119 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
9120 break;
9121 case 8:
9122 case 9:
9123 case 10:
9124 case 11:
9125 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
9126 inst.operands[2].imm = 32;
9127 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
9128 break;
9129 case 12:
9130 case 13:
9131 case 14:
9132 case 15:
9133 {
9134 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
9135 unsigned long wrn;
9136 wrn = (inst.instruction >> 16) & 0xf;
9137 inst.instruction &= 0xff0fff0f;
9138 inst.instruction |= wrn;
9139 /* Bail out here; the instruction is now assembled. */
9140 return;
9141 }
9142 }
9143 }
9144 /* Map 32 -> 0, etc. */
9145 inst.operands[2].imm &= 0x1f;
9146 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
9147 }
9148}
c19d1205
ZW
9149\f
9150/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
9151 operations first, then control, shift, and load/store. */
b99bd4ef 9152
c19d1205 9153/* Insns like "foo X,Y,Z". */
b99bd4ef 9154
c19d1205
ZW
9155static void
9156do_mav_triple (void)
9157{
9158 inst.instruction |= inst.operands[0].reg << 16;
9159 inst.instruction |= inst.operands[1].reg;
9160 inst.instruction |= inst.operands[2].reg << 12;
9161}
b99bd4ef 9162
c19d1205
ZW
9163/* Insns like "foo W,X,Y,Z".
9164 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 9165
c19d1205
ZW
9166static void
9167do_mav_quad (void)
9168{
9169 inst.instruction |= inst.operands[0].reg << 5;
9170 inst.instruction |= inst.operands[1].reg << 12;
9171 inst.instruction |= inst.operands[2].reg << 16;
9172 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
9173}
9174
c19d1205
ZW
9175/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
9176static void
9177do_mav_dspsc (void)
a737bd4d 9178{
c19d1205
ZW
9179 inst.instruction |= inst.operands[1].reg << 12;
9180}
a737bd4d 9181
c19d1205
ZW
9182/* Maverick shift immediate instructions.
9183 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
9184 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 9185
c19d1205
ZW
9186static void
9187do_mav_shift (void)
9188{
9189 int imm = inst.operands[2].imm;
a737bd4d 9190
c19d1205
ZW
9191 inst.instruction |= inst.operands[0].reg << 12;
9192 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 9193
c19d1205
ZW
9194 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
9195 Bits 5-7 of the insn should have bits 4-6 of the immediate.
9196 Bit 4 should be 0. */
9197 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 9198
c19d1205
ZW
9199 inst.instruction |= imm;
9200}
9201\f
9202/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 9203
c19d1205
ZW
9204/* Xscale multiply-accumulate (argument parse)
9205 MIAcc acc0,Rm,Rs
9206 MIAPHcc acc0,Rm,Rs
9207 MIAxycc acc0,Rm,Rs. */
a737bd4d 9208
c19d1205
ZW
9209static void
9210do_xsc_mia (void)
9211{
9212 inst.instruction |= inst.operands[1].reg;
9213 inst.instruction |= inst.operands[2].reg << 12;
9214}
a737bd4d 9215
c19d1205 9216/* Xscale move-accumulator-register (argument parse)
a737bd4d 9217
c19d1205 9218 MARcc acc0,RdLo,RdHi. */
b99bd4ef 9219
c19d1205
ZW
9220static void
9221do_xsc_mar (void)
9222{
9223 inst.instruction |= inst.operands[1].reg << 12;
9224 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9225}
9226
c19d1205 9227/* Xscale move-register-accumulator (argument parse)
b99bd4ef 9228
c19d1205 9229 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
9230
9231static void
c19d1205 9232do_xsc_mra (void)
b99bd4ef 9233{
c19d1205
ZW
9234 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
9235 inst.instruction |= inst.operands[0].reg << 12;
9236 inst.instruction |= inst.operands[1].reg << 16;
9237}
9238\f
9239/* Encoding functions relevant only to Thumb. */
b99bd4ef 9240
c19d1205
ZW
9241/* inst.operands[i] is a shifted-register operand; encode
9242 it into inst.instruction in the format used by Thumb32. */
9243
9244static void
9245encode_thumb32_shifted_operand (int i)
9246{
9247 unsigned int value = inst.reloc.exp.X_add_number;
9248 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 9249
9c3c69f2
PB
9250 constraint (inst.operands[i].immisreg,
9251 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
9252 inst.instruction |= inst.operands[i].reg;
9253 if (shift == SHIFT_RRX)
9254 inst.instruction |= SHIFT_ROR << 4;
9255 else
b99bd4ef 9256 {
c19d1205
ZW
9257 constraint (inst.reloc.exp.X_op != O_constant,
9258 _("expression too complex"));
9259
9260 constraint (value > 32
9261 || (value == 32 && (shift == SHIFT_LSL
9262 || shift == SHIFT_ROR)),
9263 _("shift expression is too large"));
9264
9265 if (value == 0)
9266 shift = SHIFT_LSL;
9267 else if (value == 32)
9268 value = 0;
9269
9270 inst.instruction |= shift << 4;
9271 inst.instruction |= (value & 0x1c) << 10;
9272 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 9273 }
c19d1205 9274}
b99bd4ef 9275
b99bd4ef 9276
c19d1205
ZW
9277/* inst.operands[i] was set up by parse_address. Encode it into a
9278 Thumb32 format load or store instruction. Reject forms that cannot
9279 be used with such instructions. If is_t is true, reject forms that
9280 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
9281 that cannot be used with a D instruction. If it is a store insn,
9282 reject PC in Rn. */
b99bd4ef 9283
c19d1205
ZW
9284static void
9285encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
9286{
5be8be5d 9287 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
9288
9289 constraint (!inst.operands[i].isreg,
53365c0d 9290 _("Instruction does not support =N addresses"));
b99bd4ef 9291
c19d1205
ZW
9292 inst.instruction |= inst.operands[i].reg << 16;
9293 if (inst.operands[i].immisreg)
b99bd4ef 9294 {
5be8be5d 9295 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
9296 constraint (is_t || is_d, _("cannot use register index with this instruction"));
9297 constraint (inst.operands[i].negative,
9298 _("Thumb does not support negative register indexing"));
9299 constraint (inst.operands[i].postind,
9300 _("Thumb does not support register post-indexing"));
9301 constraint (inst.operands[i].writeback,
9302 _("Thumb does not support register indexing with writeback"));
9303 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
9304 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 9305
f40d1643 9306 inst.instruction |= inst.operands[i].imm;
c19d1205 9307 if (inst.operands[i].shifted)
b99bd4ef 9308 {
c19d1205
ZW
9309 constraint (inst.reloc.exp.X_op != O_constant,
9310 _("expression too complex"));
9c3c69f2
PB
9311 constraint (inst.reloc.exp.X_add_number < 0
9312 || inst.reloc.exp.X_add_number > 3,
c19d1205 9313 _("shift out of range"));
9c3c69f2 9314 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
9315 }
9316 inst.reloc.type = BFD_RELOC_UNUSED;
9317 }
9318 else if (inst.operands[i].preind)
9319 {
5be8be5d 9320 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 9321 constraint (is_t && inst.operands[i].writeback,
c19d1205 9322 _("cannot use writeback with this instruction"));
5be8be5d
DG
9323 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
9324 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
c19d1205
ZW
9325
9326 if (is_d)
9327 {
9328 inst.instruction |= 0x01000000;
9329 if (inst.operands[i].writeback)
9330 inst.instruction |= 0x00200000;
b99bd4ef 9331 }
c19d1205 9332 else
b99bd4ef 9333 {
c19d1205
ZW
9334 inst.instruction |= 0x00000c00;
9335 if (inst.operands[i].writeback)
9336 inst.instruction |= 0x00000100;
b99bd4ef 9337 }
c19d1205 9338 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 9339 }
c19d1205 9340 else if (inst.operands[i].postind)
b99bd4ef 9341 {
9c2799c2 9342 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
9343 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
9344 constraint (is_t, _("cannot use post-indexing with this instruction"));
9345
9346 if (is_d)
9347 inst.instruction |= 0x00200000;
9348 else
9349 inst.instruction |= 0x00000900;
9350 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9351 }
9352 else /* unindexed - only for coprocessor */
9353 inst.error = _("instruction does not accept unindexed addressing");
9354}
9355
9356/* Table of Thumb instructions which exist in both 16- and 32-bit
9357 encodings (the latter only in post-V6T2 cores). The index is the
9358 value used in the insns table below. When there is more than one
9359 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
9360 holds variant (1).
9361 Also contains several pseudo-instructions used during relaxation. */
c19d1205 9362#define T16_32_TAB \
21d799b5
NC
9363 X(_adc, 4140, eb400000), \
9364 X(_adcs, 4140, eb500000), \
9365 X(_add, 1c00, eb000000), \
9366 X(_adds, 1c00, eb100000), \
9367 X(_addi, 0000, f1000000), \
9368 X(_addis, 0000, f1100000), \
9369 X(_add_pc,000f, f20f0000), \
9370 X(_add_sp,000d, f10d0000), \
9371 X(_adr, 000f, f20f0000), \
9372 X(_and, 4000, ea000000), \
9373 X(_ands, 4000, ea100000), \
9374 X(_asr, 1000, fa40f000), \
9375 X(_asrs, 1000, fa50f000), \
9376 X(_b, e000, f000b000), \
9377 X(_bcond, d000, f0008000), \
9378 X(_bic, 4380, ea200000), \
9379 X(_bics, 4380, ea300000), \
9380 X(_cmn, 42c0, eb100f00), \
9381 X(_cmp, 2800, ebb00f00), \
9382 X(_cpsie, b660, f3af8400), \
9383 X(_cpsid, b670, f3af8600), \
9384 X(_cpy, 4600, ea4f0000), \
9385 X(_dec_sp,80dd, f1ad0d00), \
9386 X(_eor, 4040, ea800000), \
9387 X(_eors, 4040, ea900000), \
9388 X(_inc_sp,00dd, f10d0d00), \
9389 X(_ldmia, c800, e8900000), \
9390 X(_ldr, 6800, f8500000), \
9391 X(_ldrb, 7800, f8100000), \
9392 X(_ldrh, 8800, f8300000), \
9393 X(_ldrsb, 5600, f9100000), \
9394 X(_ldrsh, 5e00, f9300000), \
9395 X(_ldr_pc,4800, f85f0000), \
9396 X(_ldr_pc2,4800, f85f0000), \
9397 X(_ldr_sp,9800, f85d0000), \
9398 X(_lsl, 0000, fa00f000), \
9399 X(_lsls, 0000, fa10f000), \
9400 X(_lsr, 0800, fa20f000), \
9401 X(_lsrs, 0800, fa30f000), \
9402 X(_mov, 2000, ea4f0000), \
9403 X(_movs, 2000, ea5f0000), \
9404 X(_mul, 4340, fb00f000), \
9405 X(_muls, 4340, ffffffff), /* no 32b muls */ \
9406 X(_mvn, 43c0, ea6f0000), \
9407 X(_mvns, 43c0, ea7f0000), \
9408 X(_neg, 4240, f1c00000), /* rsb #0 */ \
9409 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
9410 X(_orr, 4300, ea400000), \
9411 X(_orrs, 4300, ea500000), \
9412 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9413 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9414 X(_rev, ba00, fa90f080), \
9415 X(_rev16, ba40, fa90f090), \
9416 X(_revsh, bac0, fa90f0b0), \
9417 X(_ror, 41c0, fa60f000), \
9418 X(_rors, 41c0, fa70f000), \
9419 X(_sbc, 4180, eb600000), \
9420 X(_sbcs, 4180, eb700000), \
9421 X(_stmia, c000, e8800000), \
9422 X(_str, 6000, f8400000), \
9423 X(_strb, 7000, f8000000), \
9424 X(_strh, 8000, f8200000), \
9425 X(_str_sp,9000, f84d0000), \
9426 X(_sub, 1e00, eba00000), \
9427 X(_subs, 1e00, ebb00000), \
9428 X(_subi, 8000, f1a00000), \
9429 X(_subis, 8000, f1b00000), \
9430 X(_sxtb, b240, fa4ff080), \
9431 X(_sxth, b200, fa0ff080), \
9432 X(_tst, 4200, ea100f00), \
9433 X(_uxtb, b2c0, fa5ff080), \
9434 X(_uxth, b280, fa1ff080), \
9435 X(_nop, bf00, f3af8000), \
9436 X(_yield, bf10, f3af8001), \
9437 X(_wfe, bf20, f3af8002), \
9438 X(_wfi, bf30, f3af8003), \
9439 X(_sev, bf40, f3af8004),
c19d1205
ZW
9440
9441/* To catch errors in encoding functions, the codes are all offset by
9442 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9443 as 16-bit instructions. */
21d799b5 9444#define X(a,b,c) T_MNEM##a
c19d1205
ZW
9445enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9446#undef X
9447
9448#define X(a,b,c) 0x##b
9449static const unsigned short thumb_op16[] = { T16_32_TAB };
9450#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9451#undef X
9452
9453#define X(a,b,c) 0x##c
9454static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
9455#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9456#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
9457#undef X
9458#undef T16_32_TAB
9459
9460/* Thumb instruction encoders, in alphabetical order. */
9461
92e90b6e 9462/* ADDW or SUBW. */
c921be7d 9463
92e90b6e
PB
9464static void
9465do_t_add_sub_w (void)
9466{
9467 int Rd, Rn;
9468
9469 Rd = inst.operands[0].reg;
9470 Rn = inst.operands[1].reg;
9471
539d4391
NC
9472 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9473 is the SP-{plus,minus}-immediate form of the instruction. */
9474 if (Rn == REG_SP)
9475 constraint (Rd == REG_PC, BAD_PC);
9476 else
9477 reject_bad_reg (Rd);
fdfde340 9478
92e90b6e
PB
9479 inst.instruction |= (Rn << 16) | (Rd << 8);
9480 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9481}
9482
c19d1205
ZW
9483/* Parse an add or subtract instruction. We get here with inst.instruction
9484 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9485
9486static void
9487do_t_add_sub (void)
9488{
9489 int Rd, Rs, Rn;
9490
9491 Rd = inst.operands[0].reg;
9492 Rs = (inst.operands[1].present
9493 ? inst.operands[1].reg /* Rd, Rs, foo */
9494 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9495
e07e6e58
NC
9496 if (Rd == REG_PC)
9497 set_it_insn_type_last ();
9498
c19d1205
ZW
9499 if (unified_syntax)
9500 {
0110f2b8
PB
9501 bfd_boolean flags;
9502 bfd_boolean narrow;
9503 int opcode;
9504
9505 flags = (inst.instruction == T_MNEM_adds
9506 || inst.instruction == T_MNEM_subs);
9507 if (flags)
e07e6e58 9508 narrow = !in_it_block ();
0110f2b8 9509 else
e07e6e58 9510 narrow = in_it_block ();
c19d1205 9511 if (!inst.operands[2].isreg)
b99bd4ef 9512 {
16805f35
PB
9513 int add;
9514
fdfde340
JM
9515 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9516
16805f35
PB
9517 add = (inst.instruction == T_MNEM_add
9518 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
9519 opcode = 0;
9520 if (inst.size_req != 4)
9521 {
0110f2b8
PB
9522 /* Attempt to use a narrow opcode, with relaxation if
9523 appropriate. */
9524 if (Rd == REG_SP && Rs == REG_SP && !flags)
9525 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9526 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9527 opcode = T_MNEM_add_sp;
9528 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9529 opcode = T_MNEM_add_pc;
9530 else if (Rd <= 7 && Rs <= 7 && narrow)
9531 {
9532 if (flags)
9533 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9534 else
9535 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9536 }
9537 if (opcode)
9538 {
9539 inst.instruction = THUMB_OP16(opcode);
9540 inst.instruction |= (Rd << 4) | Rs;
9541 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9542 if (inst.size_req != 2)
9543 inst.relax = opcode;
9544 }
9545 else
9546 constraint (inst.size_req == 2, BAD_HIREG);
9547 }
9548 if (inst.size_req == 4
9549 || (inst.size_req != 2 && !opcode))
9550 {
efd81785
PB
9551 if (Rd == REG_PC)
9552 {
fdfde340 9553 constraint (add, BAD_PC);
efd81785
PB
9554 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9555 _("only SUBS PC, LR, #const allowed"));
9556 constraint (inst.reloc.exp.X_op != O_constant,
9557 _("expression too complex"));
9558 constraint (inst.reloc.exp.X_add_number < 0
9559 || inst.reloc.exp.X_add_number > 0xff,
9560 _("immediate value out of range"));
9561 inst.instruction = T2_SUBS_PC_LR
9562 | inst.reloc.exp.X_add_number;
9563 inst.reloc.type = BFD_RELOC_UNUSED;
9564 return;
9565 }
9566 else if (Rs == REG_PC)
16805f35
PB
9567 {
9568 /* Always use addw/subw. */
9569 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9570 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9571 }
9572 else
9573 {
9574 inst.instruction = THUMB_OP32 (inst.instruction);
9575 inst.instruction = (inst.instruction & 0xe1ffffff)
9576 | 0x10000000;
9577 if (flags)
9578 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9579 else
9580 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9581 }
dc4503c6
PB
9582 inst.instruction |= Rd << 8;
9583 inst.instruction |= Rs << 16;
0110f2b8 9584 }
b99bd4ef 9585 }
c19d1205
ZW
9586 else
9587 {
5f4cb198
NC
9588 unsigned int value = inst.reloc.exp.X_add_number;
9589 unsigned int shift = inst.operands[2].shift_kind;
9590
c19d1205
ZW
9591 Rn = inst.operands[2].reg;
9592 /* See if we can do this with a 16-bit instruction. */
9593 if (!inst.operands[2].shifted && inst.size_req != 4)
9594 {
e27ec89e
PB
9595 if (Rd > 7 || Rs > 7 || Rn > 7)
9596 narrow = FALSE;
9597
9598 if (narrow)
c19d1205 9599 {
e27ec89e
PB
9600 inst.instruction = ((inst.instruction == T_MNEM_adds
9601 || inst.instruction == T_MNEM_add)
c19d1205
ZW
9602 ? T_OPCODE_ADD_R3
9603 : T_OPCODE_SUB_R3);
9604 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9605 return;
9606 }
b99bd4ef 9607
7e806470 9608 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 9609 {
7e806470
PB
9610 /* Thumb-1 cores (except v6-M) require at least one high
9611 register in a narrow non flag setting add. */
9612 if (Rd > 7 || Rn > 7
9613 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9614 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9615 {
7e806470
PB
9616 if (Rd == Rn)
9617 {
9618 Rn = Rs;
9619 Rs = Rd;
9620 }
c19d1205
ZW
9621 inst.instruction = T_OPCODE_ADD_HI;
9622 inst.instruction |= (Rd & 8) << 4;
9623 inst.instruction |= (Rd & 7);
9624 inst.instruction |= Rn << 3;
9625 return;
9626 }
c19d1205
ZW
9627 }
9628 }
c921be7d 9629
fdfde340
JM
9630 constraint (Rd == REG_PC, BAD_PC);
9631 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9632 constraint (Rs == REG_PC, BAD_PC);
9633 reject_bad_reg (Rn);
9634
c19d1205
ZW
9635 /* If we get here, it can't be done in 16 bits. */
9636 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9637 _("shift must be constant"));
9638 inst.instruction = THUMB_OP32 (inst.instruction);
9639 inst.instruction |= Rd << 8;
9640 inst.instruction |= Rs << 16;
5f4cb198
NC
9641 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
9642 _("shift value over 3 not allowed in thumb mode"));
9643 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
9644 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
9645 encode_thumb32_shifted_operand (2);
9646 }
9647 }
9648 else
9649 {
9650 constraint (inst.instruction == T_MNEM_adds
9651 || inst.instruction == T_MNEM_subs,
9652 BAD_THUMB32);
b99bd4ef 9653
c19d1205 9654 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9655 {
c19d1205
ZW
9656 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9657 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9658 BAD_HIREG);
9659
9660 inst.instruction = (inst.instruction == T_MNEM_add
9661 ? 0x0000 : 0x8000);
9662 inst.instruction |= (Rd << 4) | Rs;
9663 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9664 return;
9665 }
9666
c19d1205
ZW
9667 Rn = inst.operands[2].reg;
9668 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9669
c19d1205
ZW
9670 /* We now have Rd, Rs, and Rn set to registers. */
9671 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9672 {
c19d1205
ZW
9673 /* Can't do this for SUB. */
9674 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9675 inst.instruction = T_OPCODE_ADD_HI;
9676 inst.instruction |= (Rd & 8) << 4;
9677 inst.instruction |= (Rd & 7);
9678 if (Rs == Rd)
9679 inst.instruction |= Rn << 3;
9680 else if (Rn == Rd)
9681 inst.instruction |= Rs << 3;
9682 else
9683 constraint (1, _("dest must overlap one source register"));
9684 }
9685 else
9686 {
9687 inst.instruction = (inst.instruction == T_MNEM_add
9688 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9689 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9690 }
b99bd4ef 9691 }
b99bd4ef
NC
9692}
9693
c19d1205
ZW
9694static void
9695do_t_adr (void)
9696{
fdfde340
JM
9697 unsigned Rd;
9698
9699 Rd = inst.operands[0].reg;
9700 reject_bad_reg (Rd);
9701
9702 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9703 {
9704 /* Defer to section relaxation. */
9705 inst.relax = inst.instruction;
9706 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9707 inst.instruction |= Rd << 4;
0110f2b8
PB
9708 }
9709 else if (unified_syntax && inst.size_req != 2)
e9f89963 9710 {
0110f2b8 9711 /* Generate a 32-bit opcode. */
e9f89963 9712 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9713 inst.instruction |= Rd << 8;
e9f89963
PB
9714 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9715 inst.reloc.pc_rel = 1;
9716 }
9717 else
9718 {
0110f2b8 9719 /* Generate a 16-bit opcode. */
e9f89963
PB
9720 inst.instruction = THUMB_OP16 (inst.instruction);
9721 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9722 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9723 inst.reloc.pc_rel = 1;
b99bd4ef 9724
fdfde340 9725 inst.instruction |= Rd << 4;
e9f89963 9726 }
c19d1205 9727}
b99bd4ef 9728
c19d1205
ZW
9729/* Arithmetic instructions for which there is just one 16-bit
9730 instruction encoding, and it allows only two low registers.
9731 For maximal compatibility with ARM syntax, we allow three register
9732 operands even when Thumb-32 instructions are not available, as long
9733 as the first two are identical. For instance, both "sbc r0,r1" and
9734 "sbc r0,r0,r1" are allowed. */
b99bd4ef 9735static void
c19d1205 9736do_t_arit3 (void)
b99bd4ef 9737{
c19d1205 9738 int Rd, Rs, Rn;
b99bd4ef 9739
c19d1205
ZW
9740 Rd = inst.operands[0].reg;
9741 Rs = (inst.operands[1].present
9742 ? inst.operands[1].reg /* Rd, Rs, foo */
9743 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9744 Rn = inst.operands[2].reg;
b99bd4ef 9745
fdfde340
JM
9746 reject_bad_reg (Rd);
9747 reject_bad_reg (Rs);
9748 if (inst.operands[2].isreg)
9749 reject_bad_reg (Rn);
9750
c19d1205 9751 if (unified_syntax)
b99bd4ef 9752 {
c19d1205
ZW
9753 if (!inst.operands[2].isreg)
9754 {
9755 /* For an immediate, we always generate a 32-bit opcode;
9756 section relaxation will shrink it later if possible. */
9757 inst.instruction = THUMB_OP32 (inst.instruction);
9758 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9759 inst.instruction |= Rd << 8;
9760 inst.instruction |= Rs << 16;
9761 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9762 }
9763 else
9764 {
e27ec89e
PB
9765 bfd_boolean narrow;
9766
c19d1205 9767 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9768 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9769 narrow = !in_it_block ();
e27ec89e 9770 else
e07e6e58 9771 narrow = in_it_block ();
e27ec89e
PB
9772
9773 if (Rd > 7 || Rn > 7 || Rs > 7)
9774 narrow = FALSE;
9775 if (inst.operands[2].shifted)
9776 narrow = FALSE;
9777 if (inst.size_req == 4)
9778 narrow = FALSE;
9779
9780 if (narrow
c19d1205
ZW
9781 && Rd == Rs)
9782 {
9783 inst.instruction = THUMB_OP16 (inst.instruction);
9784 inst.instruction |= Rd;
9785 inst.instruction |= Rn << 3;
9786 return;
9787 }
b99bd4ef 9788
c19d1205
ZW
9789 /* If we get here, it can't be done in 16 bits. */
9790 constraint (inst.operands[2].shifted
9791 && inst.operands[2].immisreg,
9792 _("shift must be constant"));
9793 inst.instruction = THUMB_OP32 (inst.instruction);
9794 inst.instruction |= Rd << 8;
9795 inst.instruction |= Rs << 16;
9796 encode_thumb32_shifted_operand (2);
9797 }
a737bd4d 9798 }
c19d1205 9799 else
b99bd4ef 9800 {
c19d1205
ZW
9801 /* On its face this is a lie - the instruction does set the
9802 flags. However, the only supported mnemonic in this mode
9803 says it doesn't. */
9804 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9805
c19d1205
ZW
9806 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9807 _("unshifted register required"));
9808 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9809 constraint (Rd != Rs,
9810 _("dest and source1 must be the same register"));
a737bd4d 9811
c19d1205
ZW
9812 inst.instruction = THUMB_OP16 (inst.instruction);
9813 inst.instruction |= Rd;
9814 inst.instruction |= Rn << 3;
b99bd4ef 9815 }
a737bd4d 9816}
b99bd4ef 9817
c19d1205
ZW
9818/* Similarly, but for instructions where the arithmetic operation is
9819 commutative, so we can allow either of them to be different from
9820 the destination operand in a 16-bit instruction. For instance, all
9821 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9822 accepted. */
9823static void
9824do_t_arit3c (void)
a737bd4d 9825{
c19d1205 9826 int Rd, Rs, Rn;
b99bd4ef 9827
c19d1205
ZW
9828 Rd = inst.operands[0].reg;
9829 Rs = (inst.operands[1].present
9830 ? inst.operands[1].reg /* Rd, Rs, foo */
9831 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9832 Rn = inst.operands[2].reg;
c921be7d 9833
fdfde340
JM
9834 reject_bad_reg (Rd);
9835 reject_bad_reg (Rs);
9836 if (inst.operands[2].isreg)
9837 reject_bad_reg (Rn);
a737bd4d 9838
c19d1205 9839 if (unified_syntax)
a737bd4d 9840 {
c19d1205 9841 if (!inst.operands[2].isreg)
b99bd4ef 9842 {
c19d1205
ZW
9843 /* For an immediate, we always generate a 32-bit opcode;
9844 section relaxation will shrink it later if possible. */
9845 inst.instruction = THUMB_OP32 (inst.instruction);
9846 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9847 inst.instruction |= Rd << 8;
9848 inst.instruction |= Rs << 16;
9849 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9850 }
c19d1205 9851 else
a737bd4d 9852 {
e27ec89e
PB
9853 bfd_boolean narrow;
9854
c19d1205 9855 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9856 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9857 narrow = !in_it_block ();
e27ec89e 9858 else
e07e6e58 9859 narrow = in_it_block ();
e27ec89e
PB
9860
9861 if (Rd > 7 || Rn > 7 || Rs > 7)
9862 narrow = FALSE;
9863 if (inst.operands[2].shifted)
9864 narrow = FALSE;
9865 if (inst.size_req == 4)
9866 narrow = FALSE;
9867
9868 if (narrow)
a737bd4d 9869 {
c19d1205 9870 if (Rd == Rs)
a737bd4d 9871 {
c19d1205
ZW
9872 inst.instruction = THUMB_OP16 (inst.instruction);
9873 inst.instruction |= Rd;
9874 inst.instruction |= Rn << 3;
9875 return;
a737bd4d 9876 }
c19d1205 9877 if (Rd == Rn)
a737bd4d 9878 {
c19d1205
ZW
9879 inst.instruction = THUMB_OP16 (inst.instruction);
9880 inst.instruction |= Rd;
9881 inst.instruction |= Rs << 3;
9882 return;
a737bd4d
NC
9883 }
9884 }
c19d1205
ZW
9885
9886 /* If we get here, it can't be done in 16 bits. */
9887 constraint (inst.operands[2].shifted
9888 && inst.operands[2].immisreg,
9889 _("shift must be constant"));
9890 inst.instruction = THUMB_OP32 (inst.instruction);
9891 inst.instruction |= Rd << 8;
9892 inst.instruction |= Rs << 16;
9893 encode_thumb32_shifted_operand (2);
a737bd4d 9894 }
b99bd4ef 9895 }
c19d1205
ZW
9896 else
9897 {
9898 /* On its face this is a lie - the instruction does set the
9899 flags. However, the only supported mnemonic in this mode
9900 says it doesn't. */
9901 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9902
c19d1205
ZW
9903 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9904 _("unshifted register required"));
9905 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9906
9907 inst.instruction = THUMB_OP16 (inst.instruction);
9908 inst.instruction |= Rd;
9909
9910 if (Rd == Rs)
9911 inst.instruction |= Rn << 3;
9912 else if (Rd == Rn)
9913 inst.instruction |= Rs << 3;
9914 else
9915 constraint (1, _("dest must overlap one source register"));
9916 }
a737bd4d
NC
9917}
9918
62b3e311
PB
9919static void
9920do_t_barrier (void)
9921{
9922 if (inst.operands[0].present)
9923 {
9924 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
9925 && inst.operands[0].imm > 0xf
9926 && inst.operands[0].imm < 0x0,
bd3ba5d1 9927 _("bad barrier type"));
62b3e311
PB
9928 inst.instruction |= inst.operands[0].imm;
9929 }
9930 else
9931 inst.instruction |= 0xf;
9932}
9933
c19d1205
ZW
9934static void
9935do_t_bfc (void)
a737bd4d 9936{
fdfde340 9937 unsigned Rd;
c19d1205
ZW
9938 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9939 constraint (msb > 32, _("bit-field extends past end of register"));
9940 /* The instruction encoding stores the LSB and MSB,
9941 not the LSB and width. */
fdfde340
JM
9942 Rd = inst.operands[0].reg;
9943 reject_bad_reg (Rd);
9944 inst.instruction |= Rd << 8;
c19d1205
ZW
9945 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9946 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9947 inst.instruction |= msb - 1;
b99bd4ef
NC
9948}
9949
c19d1205
ZW
9950static void
9951do_t_bfi (void)
b99bd4ef 9952{
fdfde340 9953 int Rd, Rn;
c19d1205 9954 unsigned int msb;
b99bd4ef 9955
fdfde340
JM
9956 Rd = inst.operands[0].reg;
9957 reject_bad_reg (Rd);
9958
c19d1205
ZW
9959 /* #0 in second position is alternative syntax for bfc, which is
9960 the same instruction but with REG_PC in the Rm field. */
9961 if (!inst.operands[1].isreg)
fdfde340
JM
9962 Rn = REG_PC;
9963 else
9964 {
9965 Rn = inst.operands[1].reg;
9966 reject_bad_reg (Rn);
9967 }
b99bd4ef 9968
c19d1205
ZW
9969 msb = inst.operands[2].imm + inst.operands[3].imm;
9970 constraint (msb > 32, _("bit-field extends past end of register"));
9971 /* The instruction encoding stores the LSB and MSB,
9972 not the LSB and width. */
fdfde340
JM
9973 inst.instruction |= Rd << 8;
9974 inst.instruction |= Rn << 16;
c19d1205
ZW
9975 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9976 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9977 inst.instruction |= msb - 1;
b99bd4ef
NC
9978}
9979
c19d1205
ZW
9980static void
9981do_t_bfx (void)
b99bd4ef 9982{
fdfde340
JM
9983 unsigned Rd, Rn;
9984
9985 Rd = inst.operands[0].reg;
9986 Rn = inst.operands[1].reg;
9987
9988 reject_bad_reg (Rd);
9989 reject_bad_reg (Rn);
9990
c19d1205
ZW
9991 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9992 _("bit-field extends past end of register"));
fdfde340
JM
9993 inst.instruction |= Rd << 8;
9994 inst.instruction |= Rn << 16;
c19d1205
ZW
9995 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9996 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9997 inst.instruction |= inst.operands[3].imm - 1;
9998}
b99bd4ef 9999
c19d1205
ZW
10000/* ARM V5 Thumb BLX (argument parse)
10001 BLX <target_addr> which is BLX(1)
10002 BLX <Rm> which is BLX(2)
10003 Unfortunately, there are two different opcodes for this mnemonic.
10004 So, the insns[].value is not used, and the code here zaps values
10005 into inst.instruction.
b99bd4ef 10006
c19d1205
ZW
10007 ??? How to take advantage of the additional two bits of displacement
10008 available in Thumb32 mode? Need new relocation? */
b99bd4ef 10009
c19d1205
ZW
10010static void
10011do_t_blx (void)
10012{
e07e6e58
NC
10013 set_it_insn_type_last ();
10014
c19d1205 10015 if (inst.operands[0].isreg)
fdfde340
JM
10016 {
10017 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10018 /* We have a register, so this is BLX(2). */
10019 inst.instruction |= inst.operands[0].reg << 3;
10020 }
b99bd4ef
NC
10021 else
10022 {
c19d1205 10023 /* No register. This must be BLX(1). */
2fc8bdac 10024 inst.instruction = 0xf000e800;
0855e32b 10025 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
10026 }
10027}
10028
c19d1205
ZW
10029static void
10030do_t_branch (void)
b99bd4ef 10031{
0110f2b8 10032 int opcode;
dfa9f0d5 10033 int cond;
9ae92b05 10034 int reloc;
dfa9f0d5 10035
e07e6e58
NC
10036 cond = inst.cond;
10037 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10038
10039 if (in_it_block ())
dfa9f0d5
PB
10040 {
10041 /* Conditional branches inside IT blocks are encoded as unconditional
10042 branches. */
10043 cond = COND_ALWAYS;
dfa9f0d5
PB
10044 }
10045 else
10046 cond = inst.cond;
10047
10048 if (cond != COND_ALWAYS)
0110f2b8
PB
10049 opcode = T_MNEM_bcond;
10050 else
10051 opcode = inst.instruction;
10052
12d6b0b7
RS
10053 if (unified_syntax
10054 && (inst.size_req == 4
10960bfb
PB
10055 || (inst.size_req != 2
10056 && (inst.operands[0].hasreloc
10057 || inst.reloc.exp.X_op == O_constant))))
c19d1205 10058 {
0110f2b8 10059 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 10060 if (cond == COND_ALWAYS)
9ae92b05 10061 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
10062 else
10063 {
9c2799c2 10064 gas_assert (cond != 0xF);
dfa9f0d5 10065 inst.instruction |= cond << 22;
9ae92b05 10066 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
10067 }
10068 }
b99bd4ef
NC
10069 else
10070 {
0110f2b8 10071 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 10072 if (cond == COND_ALWAYS)
9ae92b05 10073 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 10074 else
b99bd4ef 10075 {
dfa9f0d5 10076 inst.instruction |= cond << 8;
9ae92b05 10077 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 10078 }
0110f2b8
PB
10079 /* Allow section relaxation. */
10080 if (unified_syntax && inst.size_req != 2)
10081 inst.relax = opcode;
b99bd4ef 10082 }
9ae92b05 10083 inst.reloc.type = reloc;
c19d1205 10084 inst.reloc.pc_rel = 1;
b99bd4ef
NC
10085}
10086
10087static void
c19d1205 10088do_t_bkpt (void)
b99bd4ef 10089{
dfa9f0d5
PB
10090 constraint (inst.cond != COND_ALWAYS,
10091 _("instruction is always unconditional"));
c19d1205 10092 if (inst.operands[0].present)
b99bd4ef 10093 {
c19d1205
ZW
10094 constraint (inst.operands[0].imm > 255,
10095 _("immediate value out of range"));
10096 inst.instruction |= inst.operands[0].imm;
e07e6e58 10097 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 10098 }
b99bd4ef
NC
10099}
10100
10101static void
c19d1205 10102do_t_branch23 (void)
b99bd4ef 10103{
e07e6e58 10104 set_it_insn_type_last ();
0855e32b 10105 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 10106
0855e32b
NS
10107 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
10108 this file. We used to simply ignore the PLT reloc type here --
10109 the branch encoding is now needed to deal with TLSCALL relocs.
10110 So if we see a PLT reloc now, put it back to how it used to be to
10111 keep the preexisting behaviour. */
10112 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
10113 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 10114
4343666d 10115#if defined(OBJ_COFF)
c19d1205
ZW
10116 /* If the destination of the branch is a defined symbol which does not have
10117 the THUMB_FUNC attribute, then we must be calling a function which has
10118 the (interfacearm) attribute. We look for the Thumb entry point to that
10119 function and change the branch to refer to that function instead. */
10120 if ( inst.reloc.exp.X_op == O_symbol
10121 && inst.reloc.exp.X_add_symbol != NULL
10122 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10123 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10124 inst.reloc.exp.X_add_symbol =
10125 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 10126#endif
90e4755a
RE
10127}
10128
10129static void
c19d1205 10130do_t_bx (void)
90e4755a 10131{
e07e6e58 10132 set_it_insn_type_last ();
c19d1205
ZW
10133 inst.instruction |= inst.operands[0].reg << 3;
10134 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
10135 should cause the alignment to be checked once it is known. This is
10136 because BX PC only works if the instruction is word aligned. */
10137}
90e4755a 10138
c19d1205
ZW
10139static void
10140do_t_bxj (void)
10141{
fdfde340 10142 int Rm;
90e4755a 10143
e07e6e58 10144 set_it_insn_type_last ();
fdfde340
JM
10145 Rm = inst.operands[0].reg;
10146 reject_bad_reg (Rm);
10147 inst.instruction |= Rm << 16;
90e4755a
RE
10148}
10149
10150static void
c19d1205 10151do_t_clz (void)
90e4755a 10152{
fdfde340
JM
10153 unsigned Rd;
10154 unsigned Rm;
10155
10156 Rd = inst.operands[0].reg;
10157 Rm = inst.operands[1].reg;
10158
10159 reject_bad_reg (Rd);
10160 reject_bad_reg (Rm);
10161
10162 inst.instruction |= Rd << 8;
10163 inst.instruction |= Rm << 16;
10164 inst.instruction |= Rm;
c19d1205 10165}
90e4755a 10166
dfa9f0d5
PB
10167static void
10168do_t_cps (void)
10169{
e07e6e58 10170 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
10171 inst.instruction |= inst.operands[0].imm;
10172}
10173
c19d1205
ZW
10174static void
10175do_t_cpsi (void)
10176{
e07e6e58 10177 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 10178 if (unified_syntax
62b3e311
PB
10179 && (inst.operands[1].present || inst.size_req == 4)
10180 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 10181 {
c19d1205
ZW
10182 unsigned int imod = (inst.instruction & 0x0030) >> 4;
10183 inst.instruction = 0xf3af8000;
10184 inst.instruction |= imod << 9;
10185 inst.instruction |= inst.operands[0].imm << 5;
10186 if (inst.operands[1].present)
10187 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 10188 }
c19d1205 10189 else
90e4755a 10190 {
62b3e311
PB
10191 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
10192 && (inst.operands[0].imm & 4),
10193 _("selected processor does not support 'A' form "
10194 "of this instruction"));
10195 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
10196 _("Thumb does not support the 2-argument "
10197 "form of this instruction"));
10198 inst.instruction |= inst.operands[0].imm;
90e4755a 10199 }
90e4755a
RE
10200}
10201
c19d1205
ZW
10202/* THUMB CPY instruction (argument parse). */
10203
90e4755a 10204static void
c19d1205 10205do_t_cpy (void)
90e4755a 10206{
c19d1205 10207 if (inst.size_req == 4)
90e4755a 10208 {
c19d1205
ZW
10209 inst.instruction = THUMB_OP32 (T_MNEM_mov);
10210 inst.instruction |= inst.operands[0].reg << 8;
10211 inst.instruction |= inst.operands[1].reg;
90e4755a 10212 }
c19d1205 10213 else
90e4755a 10214 {
c19d1205
ZW
10215 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
10216 inst.instruction |= (inst.operands[0].reg & 0x7);
10217 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 10218 }
90e4755a
RE
10219}
10220
90e4755a 10221static void
25fe350b 10222do_t_cbz (void)
90e4755a 10223{
e07e6e58 10224 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
10225 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10226 inst.instruction |= inst.operands[0].reg;
10227 inst.reloc.pc_rel = 1;
10228 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
10229}
90e4755a 10230
62b3e311
PB
10231static void
10232do_t_dbg (void)
10233{
10234 inst.instruction |= inst.operands[0].imm;
10235}
10236
10237static void
10238do_t_div (void)
10239{
fdfde340
JM
10240 unsigned Rd, Rn, Rm;
10241
10242 Rd = inst.operands[0].reg;
10243 Rn = (inst.operands[1].present
10244 ? inst.operands[1].reg : Rd);
10245 Rm = inst.operands[2].reg;
10246
10247 reject_bad_reg (Rd);
10248 reject_bad_reg (Rn);
10249 reject_bad_reg (Rm);
10250
10251 inst.instruction |= Rd << 8;
10252 inst.instruction |= Rn << 16;
10253 inst.instruction |= Rm;
62b3e311
PB
10254}
10255
c19d1205
ZW
10256static void
10257do_t_hint (void)
10258{
10259 if (unified_syntax && inst.size_req == 4)
10260 inst.instruction = THUMB_OP32 (inst.instruction);
10261 else
10262 inst.instruction = THUMB_OP16 (inst.instruction);
10263}
90e4755a 10264
c19d1205
ZW
10265static void
10266do_t_it (void)
10267{
10268 unsigned int cond = inst.operands[0].imm;
e27ec89e 10269
e07e6e58
NC
10270 set_it_insn_type (IT_INSN);
10271 now_it.mask = (inst.instruction & 0xf) | 0x10;
10272 now_it.cc = cond;
e27ec89e
PB
10273
10274 /* If the condition is a negative condition, invert the mask. */
c19d1205 10275 if ((cond & 0x1) == 0x0)
90e4755a 10276 {
c19d1205 10277 unsigned int mask = inst.instruction & 0x000f;
90e4755a 10278
c19d1205
ZW
10279 if ((mask & 0x7) == 0)
10280 /* no conversion needed */;
10281 else if ((mask & 0x3) == 0)
e27ec89e
PB
10282 mask ^= 0x8;
10283 else if ((mask & 0x1) == 0)
10284 mask ^= 0xC;
c19d1205 10285 else
e27ec89e 10286 mask ^= 0xE;
90e4755a 10287
e27ec89e
PB
10288 inst.instruction &= 0xfff0;
10289 inst.instruction |= mask;
c19d1205 10290 }
90e4755a 10291
c19d1205
ZW
10292 inst.instruction |= cond << 4;
10293}
90e4755a 10294
3c707909
PB
10295/* Helper function used for both push/pop and ldm/stm. */
10296static void
10297encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
10298{
10299 bfd_boolean load;
10300
10301 load = (inst.instruction & (1 << 20)) != 0;
10302
10303 if (mask & (1 << 13))
10304 inst.error = _("SP not allowed in register list");
1e5b0379
NC
10305
10306 if ((mask & (1 << base)) != 0
10307 && writeback)
10308 inst.error = _("having the base register in the register list when "
10309 "using write back is UNPREDICTABLE");
10310
3c707909
PB
10311 if (load)
10312 {
e07e6e58
NC
10313 if (mask & (1 << 15))
10314 {
10315 if (mask & (1 << 14))
10316 inst.error = _("LR and PC should not both be in register list");
10317 else
10318 set_it_insn_type_last ();
10319 }
3c707909
PB
10320 }
10321 else
10322 {
10323 if (mask & (1 << 15))
10324 inst.error = _("PC not allowed in register list");
3c707909
PB
10325 }
10326
10327 if ((mask & (mask - 1)) == 0)
10328 {
10329 /* Single register transfers implemented as str/ldr. */
10330 if (writeback)
10331 {
10332 if (inst.instruction & (1 << 23))
10333 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
10334 else
10335 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
10336 }
10337 else
10338 {
10339 if (inst.instruction & (1 << 23))
10340 inst.instruction = 0x00800000; /* ia -> [base] */
10341 else
10342 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
10343 }
10344
10345 inst.instruction |= 0xf8400000;
10346 if (load)
10347 inst.instruction |= 0x00100000;
10348
5f4273c7 10349 mask = ffs (mask) - 1;
3c707909
PB
10350 mask <<= 12;
10351 }
10352 else if (writeback)
10353 inst.instruction |= WRITE_BACK;
10354
10355 inst.instruction |= mask;
10356 inst.instruction |= base << 16;
10357}
10358
c19d1205
ZW
10359static void
10360do_t_ldmstm (void)
10361{
10362 /* This really doesn't seem worth it. */
10363 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10364 _("expression too complex"));
10365 constraint (inst.operands[1].writeback,
10366 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 10367
c19d1205
ZW
10368 if (unified_syntax)
10369 {
3c707909
PB
10370 bfd_boolean narrow;
10371 unsigned mask;
10372
10373 narrow = FALSE;
c19d1205
ZW
10374 /* See if we can use a 16-bit instruction. */
10375 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
10376 && inst.size_req != 4
3c707909 10377 && !(inst.operands[1].imm & ~0xff))
90e4755a 10378 {
3c707909 10379 mask = 1 << inst.operands[0].reg;
90e4755a 10380
eab4f823 10381 if (inst.operands[0].reg <= 7)
90e4755a 10382 {
3c707909 10383 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
10384 ? inst.operands[0].writeback
10385 : (inst.operands[0].writeback
10386 == !(inst.operands[1].imm & mask)))
10387 {
10388 if (inst.instruction == T_MNEM_stmia
10389 && (inst.operands[1].imm & mask)
10390 && (inst.operands[1].imm & (mask - 1)))
10391 as_warn (_("value stored for r%d is UNKNOWN"),
10392 inst.operands[0].reg);
3c707909 10393
eab4f823
MGD
10394 inst.instruction = THUMB_OP16 (inst.instruction);
10395 inst.instruction |= inst.operands[0].reg << 8;
10396 inst.instruction |= inst.operands[1].imm;
10397 narrow = TRUE;
10398 }
10399 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10400 {
10401 /* This means 1 register in reg list one of 3 situations:
10402 1. Instruction is stmia, but without writeback.
10403 2. lmdia without writeback, but with Rn not in
10404 reglist.
10405 3. ldmia with writeback, but with Rn in reglist.
10406 Case 3 is UNPREDICTABLE behaviour, so we handle
10407 case 1 and 2 which can be converted into a 16-bit
10408 str or ldr. The SP cases are handled below. */
10409 unsigned long opcode;
10410 /* First, record an error for Case 3. */
10411 if (inst.operands[1].imm & mask
10412 && inst.operands[0].writeback)
fa94de6b 10413 inst.error =
eab4f823
MGD
10414 _("having the base register in the register list when "
10415 "using write back is UNPREDICTABLE");
fa94de6b
RM
10416
10417 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
10418 : T_MNEM_ldr);
10419 inst.instruction = THUMB_OP16 (opcode);
10420 inst.instruction |= inst.operands[0].reg << 3;
10421 inst.instruction |= (ffs (inst.operands[1].imm)-1);
10422 narrow = TRUE;
10423 }
90e4755a 10424 }
eab4f823 10425 else if (inst.operands[0] .reg == REG_SP)
90e4755a 10426 {
eab4f823
MGD
10427 if (inst.operands[0].writeback)
10428 {
fa94de6b 10429 inst.instruction =
eab4f823
MGD
10430 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10431 ? T_MNEM_push : T_MNEM_pop);
10432 inst.instruction |= inst.operands[1].imm;
10433 narrow = TRUE;
10434 }
10435 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10436 {
fa94de6b 10437 inst.instruction =
eab4f823
MGD
10438 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10439 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10440 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10441 narrow = TRUE;
10442 }
90e4755a 10443 }
3c707909
PB
10444 }
10445
10446 if (!narrow)
10447 {
c19d1205
ZW
10448 if (inst.instruction < 0xffff)
10449 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 10450
5f4273c7
NC
10451 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10452 inst.operands[0].writeback);
90e4755a
RE
10453 }
10454 }
c19d1205 10455 else
90e4755a 10456 {
c19d1205
ZW
10457 constraint (inst.operands[0].reg > 7
10458 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
10459 constraint (inst.instruction != T_MNEM_ldmia
10460 && inst.instruction != T_MNEM_stmia,
10461 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 10462 if (inst.instruction == T_MNEM_stmia)
f03698e6 10463 {
c19d1205
ZW
10464 if (!inst.operands[0].writeback)
10465 as_warn (_("this instruction will write back the base register"));
10466 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10467 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 10468 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 10469 inst.operands[0].reg);
f03698e6 10470 }
c19d1205 10471 else
90e4755a 10472 {
c19d1205
ZW
10473 if (!inst.operands[0].writeback
10474 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10475 as_warn (_("this instruction will write back the base register"));
10476 else if (inst.operands[0].writeback
10477 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10478 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
10479 }
10480
c19d1205
ZW
10481 inst.instruction = THUMB_OP16 (inst.instruction);
10482 inst.instruction |= inst.operands[0].reg << 8;
10483 inst.instruction |= inst.operands[1].imm;
10484 }
10485}
e28cd48c 10486
c19d1205
ZW
10487static void
10488do_t_ldrex (void)
10489{
10490 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10491 || inst.operands[1].postind || inst.operands[1].writeback
10492 || inst.operands[1].immisreg || inst.operands[1].shifted
10493 || inst.operands[1].negative,
01cfc07f 10494 BAD_ADDR_MODE);
e28cd48c 10495
5be8be5d
DG
10496 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10497
c19d1205
ZW
10498 inst.instruction |= inst.operands[0].reg << 12;
10499 inst.instruction |= inst.operands[1].reg << 16;
10500 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10501}
e28cd48c 10502
c19d1205
ZW
10503static void
10504do_t_ldrexd (void)
10505{
10506 if (!inst.operands[1].present)
1cac9012 10507 {
c19d1205
ZW
10508 constraint (inst.operands[0].reg == REG_LR,
10509 _("r14 not allowed as first register "
10510 "when second register is omitted"));
10511 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 10512 }
c19d1205
ZW
10513 constraint (inst.operands[0].reg == inst.operands[1].reg,
10514 BAD_OVERLAP);
b99bd4ef 10515
c19d1205
ZW
10516 inst.instruction |= inst.operands[0].reg << 12;
10517 inst.instruction |= inst.operands[1].reg << 8;
10518 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10519}
10520
10521static void
c19d1205 10522do_t_ldst (void)
b99bd4ef 10523{
0110f2b8
PB
10524 unsigned long opcode;
10525 int Rn;
10526
e07e6e58
NC
10527 if (inst.operands[0].isreg
10528 && !inst.operands[0].preind
10529 && inst.operands[0].reg == REG_PC)
10530 set_it_insn_type_last ();
10531
0110f2b8 10532 opcode = inst.instruction;
c19d1205 10533 if (unified_syntax)
b99bd4ef 10534 {
53365c0d
PB
10535 if (!inst.operands[1].isreg)
10536 {
10537 if (opcode <= 0xffff)
10538 inst.instruction = THUMB_OP32 (opcode);
10539 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10540 return;
10541 }
0110f2b8
PB
10542 if (inst.operands[1].isreg
10543 && !inst.operands[1].writeback
c19d1205
ZW
10544 && !inst.operands[1].shifted && !inst.operands[1].postind
10545 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
10546 && opcode <= 0xffff
10547 && inst.size_req != 4)
c19d1205 10548 {
0110f2b8
PB
10549 /* Insn may have a 16-bit form. */
10550 Rn = inst.operands[1].reg;
10551 if (inst.operands[1].immisreg)
10552 {
10553 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 10554 /* [Rn, Rik] */
0110f2b8
PB
10555 if (Rn <= 7 && inst.operands[1].imm <= 7)
10556 goto op16;
5be8be5d
DG
10557 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10558 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
10559 }
10560 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10561 && opcode != T_MNEM_ldrsb)
10562 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10563 || (Rn == REG_SP && opcode == T_MNEM_str))
10564 {
10565 /* [Rn, #const] */
10566 if (Rn > 7)
10567 {
10568 if (Rn == REG_PC)
10569 {
10570 if (inst.reloc.pc_rel)
10571 opcode = T_MNEM_ldr_pc2;
10572 else
10573 opcode = T_MNEM_ldr_pc;
10574 }
10575 else
10576 {
10577 if (opcode == T_MNEM_ldr)
10578 opcode = T_MNEM_ldr_sp;
10579 else
10580 opcode = T_MNEM_str_sp;
10581 }
10582 inst.instruction = inst.operands[0].reg << 8;
10583 }
10584 else
10585 {
10586 inst.instruction = inst.operands[0].reg;
10587 inst.instruction |= inst.operands[1].reg << 3;
10588 }
10589 inst.instruction |= THUMB_OP16 (opcode);
10590 if (inst.size_req == 2)
10591 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10592 else
10593 inst.relax = opcode;
10594 return;
10595 }
c19d1205 10596 }
0110f2b8 10597 /* Definitely a 32-bit variant. */
5be8be5d 10598
8d67f500
NC
10599 /* Warning for Erratum 752419. */
10600 if (opcode == T_MNEM_ldr
10601 && inst.operands[0].reg == REG_SP
10602 && inst.operands[1].writeback == 1
10603 && !inst.operands[1].immisreg)
10604 {
10605 if (no_cpu_selected ()
10606 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
10607 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
10608 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
10609 as_warn (_("This instruction may be unpredictable "
10610 "if executed on M-profile cores "
10611 "with interrupts enabled."));
10612 }
10613
5be8be5d 10614 /* Do some validations regarding addressing modes. */
1be5fd2e 10615 if (inst.operands[1].immisreg)
5be8be5d
DG
10616 reject_bad_reg (inst.operands[1].imm);
10617
1be5fd2e
NC
10618 constraint (inst.operands[1].writeback == 1
10619 && inst.operands[0].reg == inst.operands[1].reg,
10620 BAD_OVERLAP);
10621
0110f2b8 10622 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
10623 inst.instruction |= inst.operands[0].reg << 12;
10624 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 10625 check_ldr_r15_aligned ();
b99bd4ef
NC
10626 return;
10627 }
10628
c19d1205
ZW
10629 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10630
10631 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 10632 {
c19d1205
ZW
10633 /* Only [Rn,Rm] is acceptable. */
10634 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10635 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10636 || inst.operands[1].postind || inst.operands[1].shifted
10637 || inst.operands[1].negative,
10638 _("Thumb does not support this addressing mode"));
10639 inst.instruction = THUMB_OP16 (inst.instruction);
10640 goto op16;
b99bd4ef 10641 }
5f4273c7 10642
c19d1205
ZW
10643 inst.instruction = THUMB_OP16 (inst.instruction);
10644 if (!inst.operands[1].isreg)
10645 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10646 return;
b99bd4ef 10647
c19d1205
ZW
10648 constraint (!inst.operands[1].preind
10649 || inst.operands[1].shifted
10650 || inst.operands[1].writeback,
10651 _("Thumb does not support this addressing mode"));
10652 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 10653 {
c19d1205
ZW
10654 constraint (inst.instruction & 0x0600,
10655 _("byte or halfword not valid for base register"));
10656 constraint (inst.operands[1].reg == REG_PC
10657 && !(inst.instruction & THUMB_LOAD_BIT),
10658 _("r15 based store not allowed"));
10659 constraint (inst.operands[1].immisreg,
10660 _("invalid base register for register offset"));
b99bd4ef 10661
c19d1205
ZW
10662 if (inst.operands[1].reg == REG_PC)
10663 inst.instruction = T_OPCODE_LDR_PC;
10664 else if (inst.instruction & THUMB_LOAD_BIT)
10665 inst.instruction = T_OPCODE_LDR_SP;
10666 else
10667 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 10668
c19d1205
ZW
10669 inst.instruction |= inst.operands[0].reg << 8;
10670 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10671 return;
10672 }
90e4755a 10673
c19d1205
ZW
10674 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10675 if (!inst.operands[1].immisreg)
10676 {
10677 /* Immediate offset. */
10678 inst.instruction |= inst.operands[0].reg;
10679 inst.instruction |= inst.operands[1].reg << 3;
10680 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10681 return;
10682 }
90e4755a 10683
c19d1205
ZW
10684 /* Register offset. */
10685 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10686 constraint (inst.operands[1].negative,
10687 _("Thumb does not support this addressing mode"));
90e4755a 10688
c19d1205
ZW
10689 op16:
10690 switch (inst.instruction)
10691 {
10692 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10693 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10694 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10695 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10696 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10697 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10698 case 0x5600 /* ldrsb */:
10699 case 0x5e00 /* ldrsh */: break;
10700 default: abort ();
10701 }
90e4755a 10702
c19d1205
ZW
10703 inst.instruction |= inst.operands[0].reg;
10704 inst.instruction |= inst.operands[1].reg << 3;
10705 inst.instruction |= inst.operands[1].imm << 6;
10706}
90e4755a 10707
c19d1205
ZW
10708static void
10709do_t_ldstd (void)
10710{
10711 if (!inst.operands[1].present)
b99bd4ef 10712 {
c19d1205
ZW
10713 inst.operands[1].reg = inst.operands[0].reg + 1;
10714 constraint (inst.operands[0].reg == REG_LR,
10715 _("r14 not allowed here"));
bd340a04
MGD
10716 constraint (inst.operands[0].reg == REG_R12,
10717 _("r12 not allowed here"));
b99bd4ef 10718 }
bd340a04
MGD
10719
10720 if (inst.operands[2].writeback
10721 && (inst.operands[0].reg == inst.operands[2].reg
10722 || inst.operands[1].reg == inst.operands[2].reg))
10723 as_warn (_("base register written back, and overlaps "
10724 "one of transfer registers"));
10725
c19d1205
ZW
10726 inst.instruction |= inst.operands[0].reg << 12;
10727 inst.instruction |= inst.operands[1].reg << 8;
10728 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
10729}
10730
c19d1205
ZW
10731static void
10732do_t_ldstt (void)
10733{
10734 inst.instruction |= inst.operands[0].reg << 12;
10735 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10736}
a737bd4d 10737
b99bd4ef 10738static void
c19d1205 10739do_t_mla (void)
b99bd4ef 10740{
fdfde340 10741 unsigned Rd, Rn, Rm, Ra;
c921be7d 10742
fdfde340
JM
10743 Rd = inst.operands[0].reg;
10744 Rn = inst.operands[1].reg;
10745 Rm = inst.operands[2].reg;
10746 Ra = inst.operands[3].reg;
10747
10748 reject_bad_reg (Rd);
10749 reject_bad_reg (Rn);
10750 reject_bad_reg (Rm);
10751 reject_bad_reg (Ra);
10752
10753 inst.instruction |= Rd << 8;
10754 inst.instruction |= Rn << 16;
10755 inst.instruction |= Rm;
10756 inst.instruction |= Ra << 12;
c19d1205 10757}
b99bd4ef 10758
c19d1205
ZW
10759static void
10760do_t_mlal (void)
10761{
fdfde340
JM
10762 unsigned RdLo, RdHi, Rn, Rm;
10763
10764 RdLo = inst.operands[0].reg;
10765 RdHi = inst.operands[1].reg;
10766 Rn = inst.operands[2].reg;
10767 Rm = inst.operands[3].reg;
10768
10769 reject_bad_reg (RdLo);
10770 reject_bad_reg (RdHi);
10771 reject_bad_reg (Rn);
10772 reject_bad_reg (Rm);
10773
10774 inst.instruction |= RdLo << 12;
10775 inst.instruction |= RdHi << 8;
10776 inst.instruction |= Rn << 16;
10777 inst.instruction |= Rm;
c19d1205 10778}
b99bd4ef 10779
c19d1205
ZW
10780static void
10781do_t_mov_cmp (void)
10782{
fdfde340
JM
10783 unsigned Rn, Rm;
10784
10785 Rn = inst.operands[0].reg;
10786 Rm = inst.operands[1].reg;
10787
e07e6e58
NC
10788 if (Rn == REG_PC)
10789 set_it_insn_type_last ();
10790
c19d1205 10791 if (unified_syntax)
b99bd4ef 10792 {
c19d1205
ZW
10793 int r0off = (inst.instruction == T_MNEM_mov
10794 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 10795 unsigned long opcode;
3d388997
PB
10796 bfd_boolean narrow;
10797 bfd_boolean low_regs;
10798
fdfde340 10799 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 10800 opcode = inst.instruction;
e07e6e58 10801 if (in_it_block ())
0110f2b8 10802 narrow = opcode != T_MNEM_movs;
3d388997 10803 else
0110f2b8 10804 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
10805 if (inst.size_req == 4
10806 || inst.operands[1].shifted)
10807 narrow = FALSE;
10808
efd81785
PB
10809 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10810 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10811 && !inst.operands[1].shifted
fdfde340
JM
10812 && Rn == REG_PC
10813 && Rm == REG_LR)
efd81785
PB
10814 {
10815 inst.instruction = T2_SUBS_PC_LR;
10816 return;
10817 }
10818
fdfde340
JM
10819 if (opcode == T_MNEM_cmp)
10820 {
10821 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
10822 if (narrow)
10823 {
10824 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10825 but valid. */
10826 warn_deprecated_sp (Rm);
10827 /* R15 was documented as a valid choice for Rm in ARMv6,
10828 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10829 tools reject R15, so we do too. */
10830 constraint (Rm == REG_PC, BAD_PC);
10831 }
10832 else
10833 reject_bad_reg (Rm);
fdfde340
JM
10834 }
10835 else if (opcode == T_MNEM_mov
10836 || opcode == T_MNEM_movs)
10837 {
10838 if (inst.operands[1].isreg)
10839 {
10840 if (opcode == T_MNEM_movs)
10841 {
10842 reject_bad_reg (Rn);
10843 reject_bad_reg (Rm);
10844 }
76fa04a4
MGD
10845 else if (narrow)
10846 {
10847 /* This is mov.n. */
10848 if ((Rn == REG_SP || Rn == REG_PC)
10849 && (Rm == REG_SP || Rm == REG_PC))
10850 {
10851 as_warn (_("Use of r%u as a source register is "
10852 "deprecated when r%u is the destination "
10853 "register."), Rm, Rn);
10854 }
10855 }
10856 else
10857 {
10858 /* This is mov.w. */
10859 constraint (Rn == REG_PC, BAD_PC);
10860 constraint (Rm == REG_PC, BAD_PC);
10861 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
10862 }
fdfde340
JM
10863 }
10864 else
10865 reject_bad_reg (Rn);
10866 }
10867
c19d1205
ZW
10868 if (!inst.operands[1].isreg)
10869 {
0110f2b8 10870 /* Immediate operand. */
e07e6e58 10871 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
10872 narrow = 0;
10873 if (low_regs && narrow)
10874 {
10875 inst.instruction = THUMB_OP16 (opcode);
fdfde340 10876 inst.instruction |= Rn << 8;
0110f2b8
PB
10877 if (inst.size_req == 2)
10878 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10879 else
10880 inst.relax = opcode;
10881 }
10882 else
10883 {
10884 inst.instruction = THUMB_OP32 (inst.instruction);
10885 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10886 inst.instruction |= Rn << r0off;
0110f2b8
PB
10887 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10888 }
c19d1205 10889 }
728ca7c9
PB
10890 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10891 && (inst.instruction == T_MNEM_mov
10892 || inst.instruction == T_MNEM_movs))
10893 {
10894 /* Register shifts are encoded as separate shift instructions. */
10895 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10896
e07e6e58 10897 if (in_it_block ())
728ca7c9
PB
10898 narrow = !flags;
10899 else
10900 narrow = flags;
10901
10902 if (inst.size_req == 4)
10903 narrow = FALSE;
10904
10905 if (!low_regs || inst.operands[1].imm > 7)
10906 narrow = FALSE;
10907
fdfde340 10908 if (Rn != Rm)
728ca7c9
PB
10909 narrow = FALSE;
10910
10911 switch (inst.operands[1].shift_kind)
10912 {
10913 case SHIFT_LSL:
10914 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10915 break;
10916 case SHIFT_ASR:
10917 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10918 break;
10919 case SHIFT_LSR:
10920 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10921 break;
10922 case SHIFT_ROR:
10923 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10924 break;
10925 default:
5f4273c7 10926 abort ();
728ca7c9
PB
10927 }
10928
10929 inst.instruction = opcode;
10930 if (narrow)
10931 {
fdfde340 10932 inst.instruction |= Rn;
728ca7c9
PB
10933 inst.instruction |= inst.operands[1].imm << 3;
10934 }
10935 else
10936 {
10937 if (flags)
10938 inst.instruction |= CONDS_BIT;
10939
fdfde340
JM
10940 inst.instruction |= Rn << 8;
10941 inst.instruction |= Rm << 16;
728ca7c9
PB
10942 inst.instruction |= inst.operands[1].imm;
10943 }
10944 }
3d388997 10945 else if (!narrow)
c19d1205 10946 {
728ca7c9
PB
10947 /* Some mov with immediate shift have narrow variants.
10948 Register shifts are handled above. */
10949 if (low_regs && inst.operands[1].shifted
10950 && (inst.instruction == T_MNEM_mov
10951 || inst.instruction == T_MNEM_movs))
10952 {
e07e6e58 10953 if (in_it_block ())
728ca7c9
PB
10954 narrow = (inst.instruction == T_MNEM_mov);
10955 else
10956 narrow = (inst.instruction == T_MNEM_movs);
10957 }
10958
10959 if (narrow)
10960 {
10961 switch (inst.operands[1].shift_kind)
10962 {
10963 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10964 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10965 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10966 default: narrow = FALSE; break;
10967 }
10968 }
10969
10970 if (narrow)
10971 {
fdfde340
JM
10972 inst.instruction |= Rn;
10973 inst.instruction |= Rm << 3;
728ca7c9
PB
10974 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10975 }
10976 else
10977 {
10978 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10979 inst.instruction |= Rn << r0off;
728ca7c9
PB
10980 encode_thumb32_shifted_operand (1);
10981 }
c19d1205
ZW
10982 }
10983 else
10984 switch (inst.instruction)
10985 {
10986 case T_MNEM_mov:
837b3435 10987 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
10988 results. Don't allow this. */
10989 if (low_regs)
10990 {
10991 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
10992 "MOV Rd, Rs with two low registers is not "
10993 "permitted on this architecture");
fa94de6b 10994 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
10995 arm_ext_v6);
10996 }
10997
c19d1205 10998 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
10999 inst.instruction |= (Rn & 0x8) << 4;
11000 inst.instruction |= (Rn & 0x7);
11001 inst.instruction |= Rm << 3;
c19d1205 11002 break;
b99bd4ef 11003
c19d1205
ZW
11004 case T_MNEM_movs:
11005 /* We know we have low registers at this point.
941a8a52
MGD
11006 Generate LSLS Rd, Rs, #0. */
11007 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
11008 inst.instruction |= Rn;
11009 inst.instruction |= Rm << 3;
c19d1205
ZW
11010 break;
11011
11012 case T_MNEM_cmp:
3d388997 11013 if (low_regs)
c19d1205
ZW
11014 {
11015 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
11016 inst.instruction |= Rn;
11017 inst.instruction |= Rm << 3;
c19d1205
ZW
11018 }
11019 else
11020 {
11021 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
11022 inst.instruction |= (Rn & 0x8) << 4;
11023 inst.instruction |= (Rn & 0x7);
11024 inst.instruction |= Rm << 3;
c19d1205
ZW
11025 }
11026 break;
11027 }
b99bd4ef
NC
11028 return;
11029 }
11030
c19d1205 11031 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
11032
11033 /* PR 10443: Do not silently ignore shifted operands. */
11034 constraint (inst.operands[1].shifted,
11035 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
11036
c19d1205 11037 if (inst.operands[1].isreg)
b99bd4ef 11038 {
fdfde340 11039 if (Rn < 8 && Rm < 8)
b99bd4ef 11040 {
c19d1205
ZW
11041 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11042 since a MOV instruction produces unpredictable results. */
11043 if (inst.instruction == T_OPCODE_MOV_I8)
11044 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 11045 else
c19d1205 11046 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 11047
fdfde340
JM
11048 inst.instruction |= Rn;
11049 inst.instruction |= Rm << 3;
b99bd4ef
NC
11050 }
11051 else
11052 {
c19d1205
ZW
11053 if (inst.instruction == T_OPCODE_MOV_I8)
11054 inst.instruction = T_OPCODE_MOV_HR;
11055 else
11056 inst.instruction = T_OPCODE_CMP_HR;
11057 do_t_cpy ();
b99bd4ef
NC
11058 }
11059 }
c19d1205 11060 else
b99bd4ef 11061 {
fdfde340 11062 constraint (Rn > 7,
c19d1205 11063 _("only lo regs allowed with immediate"));
fdfde340 11064 inst.instruction |= Rn << 8;
c19d1205
ZW
11065 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11066 }
11067}
b99bd4ef 11068
c19d1205
ZW
11069static void
11070do_t_mov16 (void)
11071{
fdfde340 11072 unsigned Rd;
b6895b4f
PB
11073 bfd_vma imm;
11074 bfd_boolean top;
11075
11076 top = (inst.instruction & 0x00800000) != 0;
11077 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
11078 {
11079 constraint (top, _(":lower16: not allowed this instruction"));
11080 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
11081 }
11082 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
11083 {
11084 constraint (!top, _(":upper16: not allowed this instruction"));
11085 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
11086 }
11087
fdfde340
JM
11088 Rd = inst.operands[0].reg;
11089 reject_bad_reg (Rd);
11090
11091 inst.instruction |= Rd << 8;
b6895b4f
PB
11092 if (inst.reloc.type == BFD_RELOC_UNUSED)
11093 {
11094 imm = inst.reloc.exp.X_add_number;
11095 inst.instruction |= (imm & 0xf000) << 4;
11096 inst.instruction |= (imm & 0x0800) << 15;
11097 inst.instruction |= (imm & 0x0700) << 4;
11098 inst.instruction |= (imm & 0x00ff);
11099 }
c19d1205 11100}
b99bd4ef 11101
c19d1205
ZW
11102static void
11103do_t_mvn_tst (void)
11104{
fdfde340 11105 unsigned Rn, Rm;
c921be7d 11106
fdfde340
JM
11107 Rn = inst.operands[0].reg;
11108 Rm = inst.operands[1].reg;
11109
11110 if (inst.instruction == T_MNEM_cmp
11111 || inst.instruction == T_MNEM_cmn)
11112 constraint (Rn == REG_PC, BAD_PC);
11113 else
11114 reject_bad_reg (Rn);
11115 reject_bad_reg (Rm);
11116
c19d1205
ZW
11117 if (unified_syntax)
11118 {
11119 int r0off = (inst.instruction == T_MNEM_mvn
11120 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
11121 bfd_boolean narrow;
11122
11123 if (inst.size_req == 4
11124 || inst.instruction > 0xffff
11125 || inst.operands[1].shifted
fdfde340 11126 || Rn > 7 || Rm > 7)
3d388997
PB
11127 narrow = FALSE;
11128 else if (inst.instruction == T_MNEM_cmn)
11129 narrow = TRUE;
11130 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11131 narrow = !in_it_block ();
3d388997 11132 else
e07e6e58 11133 narrow = in_it_block ();
3d388997 11134
c19d1205 11135 if (!inst.operands[1].isreg)
b99bd4ef 11136 {
c19d1205
ZW
11137 /* For an immediate, we always generate a 32-bit opcode;
11138 section relaxation will shrink it later if possible. */
11139 if (inst.instruction < 0xffff)
11140 inst.instruction = THUMB_OP32 (inst.instruction);
11141 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11142 inst.instruction |= Rn << r0off;
c19d1205 11143 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11144 }
c19d1205 11145 else
b99bd4ef 11146 {
c19d1205 11147 /* See if we can do this with a 16-bit instruction. */
3d388997 11148 if (narrow)
b99bd4ef 11149 {
c19d1205 11150 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11151 inst.instruction |= Rn;
11152 inst.instruction |= Rm << 3;
b99bd4ef 11153 }
c19d1205 11154 else
b99bd4ef 11155 {
c19d1205
ZW
11156 constraint (inst.operands[1].shifted
11157 && inst.operands[1].immisreg,
11158 _("shift must be constant"));
11159 if (inst.instruction < 0xffff)
11160 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11161 inst.instruction |= Rn << r0off;
c19d1205 11162 encode_thumb32_shifted_operand (1);
b99bd4ef 11163 }
b99bd4ef
NC
11164 }
11165 }
11166 else
11167 {
c19d1205
ZW
11168 constraint (inst.instruction > 0xffff
11169 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
11170 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
11171 _("unshifted register required"));
fdfde340 11172 constraint (Rn > 7 || Rm > 7,
c19d1205 11173 BAD_HIREG);
b99bd4ef 11174
c19d1205 11175 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11176 inst.instruction |= Rn;
11177 inst.instruction |= Rm << 3;
b99bd4ef 11178 }
b99bd4ef
NC
11179}
11180
b05fe5cf 11181static void
c19d1205 11182do_t_mrs (void)
b05fe5cf 11183{
fdfde340 11184 unsigned Rd;
037e8744
JB
11185
11186 if (do_vfp_nsyn_mrs () == SUCCESS)
11187 return;
11188
90ec0d68
MGD
11189 Rd = inst.operands[0].reg;
11190 reject_bad_reg (Rd);
11191 inst.instruction |= Rd << 8;
11192
11193 if (inst.operands[1].isreg)
62b3e311 11194 {
90ec0d68
MGD
11195 unsigned br = inst.operands[1].reg;
11196 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
11197 as_bad (_("bad register for mrs"));
11198
11199 inst.instruction |= br & (0xf << 16);
11200 inst.instruction |= (br & 0x300) >> 4;
11201 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
11202 }
11203 else
11204 {
90ec0d68 11205 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 11206
d2cd1205 11207 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
11208 {
11209 /* PR gas/12698: The constraint is only applied for m_profile.
11210 If the user has specified -march=all, we want to ignore it as
11211 we are building for any CPU type, including non-m variants. */
11212 bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core;
11213 constraint ((flags != 0) && m_profile, _("selected processor does "
11214 "not support requested special purpose register"));
11215 }
90ec0d68 11216 else
d2cd1205
JB
11217 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
11218 devices). */
11219 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
11220 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 11221
90ec0d68
MGD
11222 inst.instruction |= (flags & SPSR_BIT) >> 2;
11223 inst.instruction |= inst.operands[1].imm & 0xff;
11224 inst.instruction |= 0xf0000;
11225 }
c19d1205 11226}
b05fe5cf 11227
c19d1205
ZW
11228static void
11229do_t_msr (void)
11230{
62b3e311 11231 int flags;
fdfde340 11232 unsigned Rn;
62b3e311 11233
037e8744
JB
11234 if (do_vfp_nsyn_msr () == SUCCESS)
11235 return;
11236
c19d1205
ZW
11237 constraint (!inst.operands[1].isreg,
11238 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
11239
11240 if (inst.operands[0].isreg)
11241 flags = (int)(inst.operands[0].reg);
11242 else
11243 flags = inst.operands[0].imm;
11244
d2cd1205 11245 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 11246 {
d2cd1205
JB
11247 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11248
1a43faaf
NC
11249 /* PR gas/12698: The constraint is only applied for m_profile.
11250 If the user has specified -march=all, we want to ignore it as
11251 we are building for any CPU type, including non-m variants. */
11252 bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core;
11253 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11254 && (bits & ~(PSR_s | PSR_f)) != 0)
11255 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11256 && bits != PSR_f)) && m_profile,
11257 _("selected processor does not support requested special "
11258 "purpose register"));
62b3e311
PB
11259 }
11260 else
d2cd1205
JB
11261 constraint ((flags & 0xff) != 0, _("selected processor does not support "
11262 "requested special purpose register"));
c921be7d 11263
fdfde340
JM
11264 Rn = inst.operands[1].reg;
11265 reject_bad_reg (Rn);
11266
62b3e311 11267 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
11268 inst.instruction |= (flags & 0xf0000) >> 8;
11269 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 11270 inst.instruction |= (flags & 0xff);
fdfde340 11271 inst.instruction |= Rn << 16;
c19d1205 11272}
b05fe5cf 11273
c19d1205
ZW
11274static void
11275do_t_mul (void)
11276{
17828f45 11277 bfd_boolean narrow;
fdfde340 11278 unsigned Rd, Rn, Rm;
17828f45 11279
c19d1205
ZW
11280 if (!inst.operands[2].present)
11281 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 11282
fdfde340
JM
11283 Rd = inst.operands[0].reg;
11284 Rn = inst.operands[1].reg;
11285 Rm = inst.operands[2].reg;
11286
17828f45 11287 if (unified_syntax)
b05fe5cf 11288 {
17828f45 11289 if (inst.size_req == 4
fdfde340
JM
11290 || (Rd != Rn
11291 && Rd != Rm)
11292 || Rn > 7
11293 || Rm > 7)
17828f45
JM
11294 narrow = FALSE;
11295 else if (inst.instruction == T_MNEM_muls)
e07e6e58 11296 narrow = !in_it_block ();
17828f45 11297 else
e07e6e58 11298 narrow = in_it_block ();
b05fe5cf 11299 }
c19d1205 11300 else
b05fe5cf 11301 {
17828f45 11302 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 11303 constraint (Rn > 7 || Rm > 7,
c19d1205 11304 BAD_HIREG);
17828f45
JM
11305 narrow = TRUE;
11306 }
b05fe5cf 11307
17828f45
JM
11308 if (narrow)
11309 {
11310 /* 16-bit MULS/Conditional MUL. */
c19d1205 11311 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11312 inst.instruction |= Rd;
b05fe5cf 11313
fdfde340
JM
11314 if (Rd == Rn)
11315 inst.instruction |= Rm << 3;
11316 else if (Rd == Rm)
11317 inst.instruction |= Rn << 3;
c19d1205
ZW
11318 else
11319 constraint (1, _("dest must overlap one source register"));
11320 }
17828f45
JM
11321 else
11322 {
e07e6e58
NC
11323 constraint (inst.instruction != T_MNEM_mul,
11324 _("Thumb-2 MUL must not set flags"));
17828f45
JM
11325 /* 32-bit MUL. */
11326 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11327 inst.instruction |= Rd << 8;
11328 inst.instruction |= Rn << 16;
11329 inst.instruction |= Rm << 0;
11330
11331 reject_bad_reg (Rd);
11332 reject_bad_reg (Rn);
11333 reject_bad_reg (Rm);
17828f45 11334 }
c19d1205 11335}
b05fe5cf 11336
c19d1205
ZW
11337static void
11338do_t_mull (void)
11339{
fdfde340 11340 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 11341
fdfde340
JM
11342 RdLo = inst.operands[0].reg;
11343 RdHi = inst.operands[1].reg;
11344 Rn = inst.operands[2].reg;
11345 Rm = inst.operands[3].reg;
11346
11347 reject_bad_reg (RdLo);
11348 reject_bad_reg (RdHi);
11349 reject_bad_reg (Rn);
11350 reject_bad_reg (Rm);
11351
11352 inst.instruction |= RdLo << 12;
11353 inst.instruction |= RdHi << 8;
11354 inst.instruction |= Rn << 16;
11355 inst.instruction |= Rm;
11356
11357 if (RdLo == RdHi)
c19d1205
ZW
11358 as_tsktsk (_("rdhi and rdlo must be different"));
11359}
b05fe5cf 11360
c19d1205
ZW
11361static void
11362do_t_nop (void)
11363{
e07e6e58
NC
11364 set_it_insn_type (NEUTRAL_IT_INSN);
11365
c19d1205
ZW
11366 if (unified_syntax)
11367 {
11368 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 11369 {
c19d1205
ZW
11370 inst.instruction = THUMB_OP32 (inst.instruction);
11371 inst.instruction |= inst.operands[0].imm;
11372 }
11373 else
11374 {
bc2d1808
NC
11375 /* PR9722: Check for Thumb2 availability before
11376 generating a thumb2 nop instruction. */
afa62d5e 11377 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
11378 {
11379 inst.instruction = THUMB_OP16 (inst.instruction);
11380 inst.instruction |= inst.operands[0].imm << 4;
11381 }
11382 else
11383 inst.instruction = 0x46c0;
c19d1205
ZW
11384 }
11385 }
11386 else
11387 {
11388 constraint (inst.operands[0].present,
11389 _("Thumb does not support NOP with hints"));
11390 inst.instruction = 0x46c0;
11391 }
11392}
b05fe5cf 11393
c19d1205
ZW
11394static void
11395do_t_neg (void)
11396{
11397 if (unified_syntax)
11398 {
3d388997
PB
11399 bfd_boolean narrow;
11400
11401 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11402 narrow = !in_it_block ();
3d388997 11403 else
e07e6e58 11404 narrow = in_it_block ();
3d388997
PB
11405 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11406 narrow = FALSE;
11407 if (inst.size_req == 4)
11408 narrow = FALSE;
11409
11410 if (!narrow)
c19d1205
ZW
11411 {
11412 inst.instruction = THUMB_OP32 (inst.instruction);
11413 inst.instruction |= inst.operands[0].reg << 8;
11414 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
11415 }
11416 else
11417 {
c19d1205
ZW
11418 inst.instruction = THUMB_OP16 (inst.instruction);
11419 inst.instruction |= inst.operands[0].reg;
11420 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
11421 }
11422 }
11423 else
11424 {
c19d1205
ZW
11425 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
11426 BAD_HIREG);
11427 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11428
11429 inst.instruction = THUMB_OP16 (inst.instruction);
11430 inst.instruction |= inst.operands[0].reg;
11431 inst.instruction |= inst.operands[1].reg << 3;
11432 }
11433}
11434
1c444d06
JM
11435static void
11436do_t_orn (void)
11437{
11438 unsigned Rd, Rn;
11439
11440 Rd = inst.operands[0].reg;
11441 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
11442
fdfde340
JM
11443 reject_bad_reg (Rd);
11444 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
11445 reject_bad_reg (Rn);
11446
1c444d06
JM
11447 inst.instruction |= Rd << 8;
11448 inst.instruction |= Rn << 16;
11449
11450 if (!inst.operands[2].isreg)
11451 {
11452 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11453 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11454 }
11455 else
11456 {
11457 unsigned Rm;
11458
11459 Rm = inst.operands[2].reg;
fdfde340 11460 reject_bad_reg (Rm);
1c444d06
JM
11461
11462 constraint (inst.operands[2].shifted
11463 && inst.operands[2].immisreg,
11464 _("shift must be constant"));
11465 encode_thumb32_shifted_operand (2);
11466 }
11467}
11468
c19d1205
ZW
11469static void
11470do_t_pkhbt (void)
11471{
fdfde340
JM
11472 unsigned Rd, Rn, Rm;
11473
11474 Rd = inst.operands[0].reg;
11475 Rn = inst.operands[1].reg;
11476 Rm = inst.operands[2].reg;
11477
11478 reject_bad_reg (Rd);
11479 reject_bad_reg (Rn);
11480 reject_bad_reg (Rm);
11481
11482 inst.instruction |= Rd << 8;
11483 inst.instruction |= Rn << 16;
11484 inst.instruction |= Rm;
c19d1205
ZW
11485 if (inst.operands[3].present)
11486 {
11487 unsigned int val = inst.reloc.exp.X_add_number;
11488 constraint (inst.reloc.exp.X_op != O_constant,
11489 _("expression too complex"));
11490 inst.instruction |= (val & 0x1c) << 10;
11491 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 11492 }
c19d1205 11493}
b05fe5cf 11494
c19d1205
ZW
11495static void
11496do_t_pkhtb (void)
11497{
11498 if (!inst.operands[3].present)
1ef52f49
NC
11499 {
11500 unsigned Rtmp;
11501
11502 inst.instruction &= ~0x00000020;
11503
11504 /* PR 10168. Swap the Rm and Rn registers. */
11505 Rtmp = inst.operands[1].reg;
11506 inst.operands[1].reg = inst.operands[2].reg;
11507 inst.operands[2].reg = Rtmp;
11508 }
c19d1205 11509 do_t_pkhbt ();
b05fe5cf
ZW
11510}
11511
c19d1205
ZW
11512static void
11513do_t_pld (void)
11514{
fdfde340
JM
11515 if (inst.operands[0].immisreg)
11516 reject_bad_reg (inst.operands[0].imm);
11517
c19d1205
ZW
11518 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11519}
b05fe5cf 11520
c19d1205
ZW
11521static void
11522do_t_push_pop (void)
b99bd4ef 11523{
e9f89963 11524 unsigned mask;
5f4273c7 11525
c19d1205
ZW
11526 constraint (inst.operands[0].writeback,
11527 _("push/pop do not support {reglist}^"));
11528 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11529 _("expression too complex"));
b99bd4ef 11530
e9f89963
PB
11531 mask = inst.operands[0].imm;
11532 if ((mask & ~0xff) == 0)
3c707909 11533 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 11534 else if ((inst.instruction == T_MNEM_push
e9f89963 11535 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 11536 || (inst.instruction == T_MNEM_pop
e9f89963 11537 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 11538 {
c19d1205
ZW
11539 inst.instruction = THUMB_OP16 (inst.instruction);
11540 inst.instruction |= THUMB_PP_PC_LR;
3c707909 11541 inst.instruction |= mask & 0xff;
c19d1205
ZW
11542 }
11543 else if (unified_syntax)
11544 {
3c707909 11545 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 11546 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
11547 }
11548 else
11549 {
11550 inst.error = _("invalid register list to push/pop instruction");
11551 return;
11552 }
c19d1205 11553}
b99bd4ef 11554
c19d1205
ZW
11555static void
11556do_t_rbit (void)
11557{
fdfde340
JM
11558 unsigned Rd, Rm;
11559
11560 Rd = inst.operands[0].reg;
11561 Rm = inst.operands[1].reg;
11562
11563 reject_bad_reg (Rd);
11564 reject_bad_reg (Rm);
11565
11566 inst.instruction |= Rd << 8;
11567 inst.instruction |= Rm << 16;
11568 inst.instruction |= Rm;
c19d1205 11569}
b99bd4ef 11570
c19d1205
ZW
11571static void
11572do_t_rev (void)
11573{
fdfde340
JM
11574 unsigned Rd, Rm;
11575
11576 Rd = inst.operands[0].reg;
11577 Rm = inst.operands[1].reg;
11578
11579 reject_bad_reg (Rd);
11580 reject_bad_reg (Rm);
11581
11582 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
11583 && inst.size_req != 4)
11584 {
11585 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11586 inst.instruction |= Rd;
11587 inst.instruction |= Rm << 3;
c19d1205
ZW
11588 }
11589 else if (unified_syntax)
11590 {
11591 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11592 inst.instruction |= Rd << 8;
11593 inst.instruction |= Rm << 16;
11594 inst.instruction |= Rm;
c19d1205
ZW
11595 }
11596 else
11597 inst.error = BAD_HIREG;
11598}
b99bd4ef 11599
1c444d06
JM
11600static void
11601do_t_rrx (void)
11602{
11603 unsigned Rd, Rm;
11604
11605 Rd = inst.operands[0].reg;
11606 Rm = inst.operands[1].reg;
11607
fdfde340
JM
11608 reject_bad_reg (Rd);
11609 reject_bad_reg (Rm);
c921be7d 11610
1c444d06
JM
11611 inst.instruction |= Rd << 8;
11612 inst.instruction |= Rm;
11613}
11614
c19d1205
ZW
11615static void
11616do_t_rsb (void)
11617{
fdfde340 11618 unsigned Rd, Rs;
b99bd4ef 11619
c19d1205
ZW
11620 Rd = inst.operands[0].reg;
11621 Rs = (inst.operands[1].present
11622 ? inst.operands[1].reg /* Rd, Rs, foo */
11623 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 11624
fdfde340
JM
11625 reject_bad_reg (Rd);
11626 reject_bad_reg (Rs);
11627 if (inst.operands[2].isreg)
11628 reject_bad_reg (inst.operands[2].reg);
11629
c19d1205
ZW
11630 inst.instruction |= Rd << 8;
11631 inst.instruction |= Rs << 16;
11632 if (!inst.operands[2].isreg)
11633 {
026d3abb
PB
11634 bfd_boolean narrow;
11635
11636 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 11637 narrow = !in_it_block ();
026d3abb 11638 else
e07e6e58 11639 narrow = in_it_block ();
026d3abb
PB
11640
11641 if (Rd > 7 || Rs > 7)
11642 narrow = FALSE;
11643
11644 if (inst.size_req == 4 || !unified_syntax)
11645 narrow = FALSE;
11646
11647 if (inst.reloc.exp.X_op != O_constant
11648 || inst.reloc.exp.X_add_number != 0)
11649 narrow = FALSE;
11650
11651 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11652 relaxation, but it doesn't seem worth the hassle. */
11653 if (narrow)
11654 {
11655 inst.reloc.type = BFD_RELOC_UNUSED;
11656 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11657 inst.instruction |= Rs << 3;
11658 inst.instruction |= Rd;
11659 }
11660 else
11661 {
11662 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11663 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11664 }
c19d1205
ZW
11665 }
11666 else
11667 encode_thumb32_shifted_operand (2);
11668}
b99bd4ef 11669
c19d1205
ZW
11670static void
11671do_t_setend (void)
11672{
e07e6e58 11673 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11674 if (inst.operands[0].imm)
11675 inst.instruction |= 0x8;
11676}
b99bd4ef 11677
c19d1205
ZW
11678static void
11679do_t_shift (void)
11680{
11681 if (!inst.operands[1].present)
11682 inst.operands[1].reg = inst.operands[0].reg;
11683
11684 if (unified_syntax)
11685 {
3d388997
PB
11686 bfd_boolean narrow;
11687 int shift_kind;
11688
11689 switch (inst.instruction)
11690 {
11691 case T_MNEM_asr:
11692 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11693 case T_MNEM_lsl:
11694 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11695 case T_MNEM_lsr:
11696 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11697 case T_MNEM_ror:
11698 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11699 default: abort ();
11700 }
11701
11702 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11703 narrow = !in_it_block ();
3d388997 11704 else
e07e6e58 11705 narrow = in_it_block ();
3d388997
PB
11706 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11707 narrow = FALSE;
11708 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11709 narrow = FALSE;
11710 if (inst.operands[2].isreg
11711 && (inst.operands[1].reg != inst.operands[0].reg
11712 || inst.operands[2].reg > 7))
11713 narrow = FALSE;
11714 if (inst.size_req == 4)
11715 narrow = FALSE;
11716
fdfde340
JM
11717 reject_bad_reg (inst.operands[0].reg);
11718 reject_bad_reg (inst.operands[1].reg);
c921be7d 11719
3d388997 11720 if (!narrow)
c19d1205
ZW
11721 {
11722 if (inst.operands[2].isreg)
b99bd4ef 11723 {
fdfde340 11724 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
11725 inst.instruction = THUMB_OP32 (inst.instruction);
11726 inst.instruction |= inst.operands[0].reg << 8;
11727 inst.instruction |= inst.operands[1].reg << 16;
11728 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
11729
11730 /* PR 12854: Error on extraneous shifts. */
11731 constraint (inst.operands[2].shifted,
11732 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
11733 }
11734 else
11735 {
11736 inst.operands[1].shifted = 1;
3d388997 11737 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
11738 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11739 ? T_MNEM_movs : T_MNEM_mov);
11740 inst.instruction |= inst.operands[0].reg << 8;
11741 encode_thumb32_shifted_operand (1);
11742 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11743 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
11744 }
11745 }
11746 else
11747 {
c19d1205 11748 if (inst.operands[2].isreg)
b99bd4ef 11749 {
3d388997 11750 switch (shift_kind)
b99bd4ef 11751 {
3d388997
PB
11752 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11753 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11754 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11755 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 11756 default: abort ();
b99bd4ef 11757 }
5f4273c7 11758
c19d1205
ZW
11759 inst.instruction |= inst.operands[0].reg;
11760 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
11761
11762 /* PR 12854: Error on extraneous shifts. */
11763 constraint (inst.operands[2].shifted,
11764 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
11765 }
11766 else
11767 {
3d388997 11768 switch (shift_kind)
b99bd4ef 11769 {
3d388997
PB
11770 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11771 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11772 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 11773 default: abort ();
b99bd4ef 11774 }
c19d1205
ZW
11775 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11776 inst.instruction |= inst.operands[0].reg;
11777 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11778 }
11779 }
c19d1205
ZW
11780 }
11781 else
11782 {
11783 constraint (inst.operands[0].reg > 7
11784 || inst.operands[1].reg > 7, BAD_HIREG);
11785 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 11786
c19d1205
ZW
11787 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11788 {
11789 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11790 constraint (inst.operands[0].reg != inst.operands[1].reg,
11791 _("source1 and dest must be same register"));
b99bd4ef 11792
c19d1205
ZW
11793 switch (inst.instruction)
11794 {
11795 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11796 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11797 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11798 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11799 default: abort ();
11800 }
5f4273c7 11801
c19d1205
ZW
11802 inst.instruction |= inst.operands[0].reg;
11803 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
11804
11805 /* PR 12854: Error on extraneous shifts. */
11806 constraint (inst.operands[2].shifted,
11807 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
11808 }
11809 else
b99bd4ef 11810 {
c19d1205
ZW
11811 switch (inst.instruction)
11812 {
11813 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11814 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11815 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11816 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11817 default: abort ();
11818 }
11819 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11820 inst.instruction |= inst.operands[0].reg;
11821 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11822 }
11823 }
b99bd4ef
NC
11824}
11825
11826static void
c19d1205 11827do_t_simd (void)
b99bd4ef 11828{
fdfde340
JM
11829 unsigned Rd, Rn, Rm;
11830
11831 Rd = inst.operands[0].reg;
11832 Rn = inst.operands[1].reg;
11833 Rm = inst.operands[2].reg;
11834
11835 reject_bad_reg (Rd);
11836 reject_bad_reg (Rn);
11837 reject_bad_reg (Rm);
11838
11839 inst.instruction |= Rd << 8;
11840 inst.instruction |= Rn << 16;
11841 inst.instruction |= Rm;
c19d1205 11842}
b99bd4ef 11843
03ee1b7f
NC
11844static void
11845do_t_simd2 (void)
11846{
11847 unsigned Rd, Rn, Rm;
11848
11849 Rd = inst.operands[0].reg;
11850 Rm = inst.operands[1].reg;
11851 Rn = inst.operands[2].reg;
11852
11853 reject_bad_reg (Rd);
11854 reject_bad_reg (Rn);
11855 reject_bad_reg (Rm);
11856
11857 inst.instruction |= Rd << 8;
11858 inst.instruction |= Rn << 16;
11859 inst.instruction |= Rm;
11860}
11861
c19d1205 11862static void
3eb17e6b 11863do_t_smc (void)
c19d1205
ZW
11864{
11865 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
11866 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
11867 _("SMC is not permitted on this architecture"));
c19d1205
ZW
11868 constraint (inst.reloc.exp.X_op != O_constant,
11869 _("expression too complex"));
11870 inst.reloc.type = BFD_RELOC_UNUSED;
11871 inst.instruction |= (value & 0xf000) >> 12;
11872 inst.instruction |= (value & 0x0ff0);
11873 inst.instruction |= (value & 0x000f) << 16;
11874}
b99bd4ef 11875
90ec0d68
MGD
11876static void
11877do_t_hvc (void)
11878{
11879 unsigned int value = inst.reloc.exp.X_add_number;
11880
11881 inst.reloc.type = BFD_RELOC_UNUSED;
11882 inst.instruction |= (value & 0x0fff);
11883 inst.instruction |= (value & 0xf000) << 4;
11884}
11885
c19d1205 11886static void
3a21c15a 11887do_t_ssat_usat (int bias)
c19d1205 11888{
fdfde340
JM
11889 unsigned Rd, Rn;
11890
11891 Rd = inst.operands[0].reg;
11892 Rn = inst.operands[2].reg;
11893
11894 reject_bad_reg (Rd);
11895 reject_bad_reg (Rn);
11896
11897 inst.instruction |= Rd << 8;
3a21c15a 11898 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 11899 inst.instruction |= Rn << 16;
b99bd4ef 11900
c19d1205 11901 if (inst.operands[3].present)
b99bd4ef 11902 {
3a21c15a
NC
11903 offsetT shift_amount = inst.reloc.exp.X_add_number;
11904
11905 inst.reloc.type = BFD_RELOC_UNUSED;
11906
c19d1205
ZW
11907 constraint (inst.reloc.exp.X_op != O_constant,
11908 _("expression too complex"));
b99bd4ef 11909
3a21c15a 11910 if (shift_amount != 0)
6189168b 11911 {
3a21c15a
NC
11912 constraint (shift_amount > 31,
11913 _("shift expression is too large"));
11914
c19d1205 11915 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
11916 inst.instruction |= 0x00200000; /* sh bit. */
11917
11918 inst.instruction |= (shift_amount & 0x1c) << 10;
11919 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
11920 }
11921 }
b99bd4ef 11922}
c921be7d 11923
3a21c15a
NC
11924static void
11925do_t_ssat (void)
11926{
11927 do_t_ssat_usat (1);
11928}
b99bd4ef 11929
0dd132b6 11930static void
c19d1205 11931do_t_ssat16 (void)
0dd132b6 11932{
fdfde340
JM
11933 unsigned Rd, Rn;
11934
11935 Rd = inst.operands[0].reg;
11936 Rn = inst.operands[2].reg;
11937
11938 reject_bad_reg (Rd);
11939 reject_bad_reg (Rn);
11940
11941 inst.instruction |= Rd << 8;
c19d1205 11942 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 11943 inst.instruction |= Rn << 16;
c19d1205 11944}
0dd132b6 11945
c19d1205
ZW
11946static void
11947do_t_strex (void)
11948{
11949 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11950 || inst.operands[2].postind || inst.operands[2].writeback
11951 || inst.operands[2].immisreg || inst.operands[2].shifted
11952 || inst.operands[2].negative,
01cfc07f 11953 BAD_ADDR_MODE);
0dd132b6 11954
5be8be5d
DG
11955 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11956
c19d1205
ZW
11957 inst.instruction |= inst.operands[0].reg << 8;
11958 inst.instruction |= inst.operands[1].reg << 12;
11959 inst.instruction |= inst.operands[2].reg << 16;
11960 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
11961}
11962
b99bd4ef 11963static void
c19d1205 11964do_t_strexd (void)
b99bd4ef 11965{
c19d1205
ZW
11966 if (!inst.operands[2].present)
11967 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 11968
c19d1205
ZW
11969 constraint (inst.operands[0].reg == inst.operands[1].reg
11970 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 11971 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 11972 BAD_OVERLAP);
b99bd4ef 11973
c19d1205
ZW
11974 inst.instruction |= inst.operands[0].reg;
11975 inst.instruction |= inst.operands[1].reg << 12;
11976 inst.instruction |= inst.operands[2].reg << 8;
11977 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
11978}
11979
11980static void
c19d1205 11981do_t_sxtah (void)
b99bd4ef 11982{
fdfde340
JM
11983 unsigned Rd, Rn, Rm;
11984
11985 Rd = inst.operands[0].reg;
11986 Rn = inst.operands[1].reg;
11987 Rm = inst.operands[2].reg;
11988
11989 reject_bad_reg (Rd);
11990 reject_bad_reg (Rn);
11991 reject_bad_reg (Rm);
11992
11993 inst.instruction |= Rd << 8;
11994 inst.instruction |= Rn << 16;
11995 inst.instruction |= Rm;
c19d1205
ZW
11996 inst.instruction |= inst.operands[3].imm << 4;
11997}
b99bd4ef 11998
c19d1205
ZW
11999static void
12000do_t_sxth (void)
12001{
fdfde340
JM
12002 unsigned Rd, Rm;
12003
12004 Rd = inst.operands[0].reg;
12005 Rm = inst.operands[1].reg;
12006
12007 reject_bad_reg (Rd);
12008 reject_bad_reg (Rm);
c921be7d
NC
12009
12010 if (inst.instruction <= 0xffff
12011 && inst.size_req != 4
fdfde340 12012 && Rd <= 7 && Rm <= 7
c19d1205 12013 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 12014 {
c19d1205 12015 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12016 inst.instruction |= Rd;
12017 inst.instruction |= Rm << 3;
b99bd4ef 12018 }
c19d1205 12019 else if (unified_syntax)
b99bd4ef 12020 {
c19d1205
ZW
12021 if (inst.instruction <= 0xffff)
12022 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12023 inst.instruction |= Rd << 8;
12024 inst.instruction |= Rm;
c19d1205 12025 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 12026 }
c19d1205 12027 else
b99bd4ef 12028 {
c19d1205
ZW
12029 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
12030 _("Thumb encoding does not support rotation"));
12031 constraint (1, BAD_HIREG);
b99bd4ef 12032 }
c19d1205 12033}
b99bd4ef 12034
c19d1205
ZW
12035static void
12036do_t_swi (void)
12037{
b2a5fbdc
MGD
12038 /* We have to do the following check manually as ARM_EXT_OS only applies
12039 to ARM_EXT_V6M. */
12040 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
12041 {
ac7f631b
NC
12042 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
12043 /* This only applies to the v6m howver, not later architectures. */
12044 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
12045 as_bad (_("SVC is not permitted on this architecture"));
12046 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
12047 }
12048
c19d1205
ZW
12049 inst.reloc.type = BFD_RELOC_ARM_SWI;
12050}
b99bd4ef 12051
92e90b6e
PB
12052static void
12053do_t_tb (void)
12054{
fdfde340 12055 unsigned Rn, Rm;
92e90b6e
PB
12056 int half;
12057
12058 half = (inst.instruction & 0x10) != 0;
e07e6e58 12059 set_it_insn_type_last ();
dfa9f0d5
PB
12060 constraint (inst.operands[0].immisreg,
12061 _("instruction requires register index"));
fdfde340
JM
12062
12063 Rn = inst.operands[0].reg;
12064 Rm = inst.operands[0].imm;
c921be7d 12065
fdfde340
JM
12066 constraint (Rn == REG_SP, BAD_SP);
12067 reject_bad_reg (Rm);
12068
92e90b6e
PB
12069 constraint (!half && inst.operands[0].shifted,
12070 _("instruction does not allow shifted index"));
fdfde340 12071 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
12072}
12073
c19d1205
ZW
12074static void
12075do_t_usat (void)
12076{
3a21c15a 12077 do_t_ssat_usat (0);
b99bd4ef
NC
12078}
12079
12080static void
c19d1205 12081do_t_usat16 (void)
b99bd4ef 12082{
fdfde340
JM
12083 unsigned Rd, Rn;
12084
12085 Rd = inst.operands[0].reg;
12086 Rn = inst.operands[2].reg;
12087
12088 reject_bad_reg (Rd);
12089 reject_bad_reg (Rn);
12090
12091 inst.instruction |= Rd << 8;
c19d1205 12092 inst.instruction |= inst.operands[1].imm;
fdfde340 12093 inst.instruction |= Rn << 16;
b99bd4ef 12094}
c19d1205 12095
5287ad62 12096/* Neon instruction encoder helpers. */
5f4273c7 12097
5287ad62 12098/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 12099
5287ad62
JB
12100/* An "invalid" code for the following tables. */
12101#define N_INV -1u
12102
12103struct neon_tab_entry
b99bd4ef 12104{
5287ad62
JB
12105 unsigned integer;
12106 unsigned float_or_poly;
12107 unsigned scalar_or_imm;
12108};
5f4273c7 12109
5287ad62
JB
12110/* Map overloaded Neon opcodes to their respective encodings. */
12111#define NEON_ENC_TAB \
12112 X(vabd, 0x0000700, 0x1200d00, N_INV), \
12113 X(vmax, 0x0000600, 0x0000f00, N_INV), \
12114 X(vmin, 0x0000610, 0x0200f00, N_INV), \
12115 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
12116 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
12117 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
12118 X(vadd, 0x0000800, 0x0000d00, N_INV), \
12119 X(vsub, 0x1000800, 0x0200d00, N_INV), \
12120 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
12121 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
12122 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
12123 /* Register variants of the following two instructions are encoded as
e07e6e58 12124 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
12125 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
12126 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
12127 X(vfma, N_INV, 0x0000c10, N_INV), \
12128 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
12129 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
12130 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
12131 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
12132 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
12133 X(vmlal, 0x0800800, N_INV, 0x0800240), \
12134 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
12135 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
12136 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
12137 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
12138 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
12139 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
12140 X(vshl, 0x0000400, N_INV, 0x0800510), \
12141 X(vqshl, 0x0000410, N_INV, 0x0800710), \
12142 X(vand, 0x0000110, N_INV, 0x0800030), \
12143 X(vbic, 0x0100110, N_INV, 0x0800030), \
12144 X(veor, 0x1000110, N_INV, N_INV), \
12145 X(vorn, 0x0300110, N_INV, 0x0800010), \
12146 X(vorr, 0x0200110, N_INV, 0x0800010), \
12147 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
12148 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
12149 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
12150 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
12151 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
12152 X(vst1, 0x0000000, 0x0800000, N_INV), \
12153 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
12154 X(vst2, 0x0000100, 0x0800100, N_INV), \
12155 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
12156 X(vst3, 0x0000200, 0x0800200, N_INV), \
12157 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
12158 X(vst4, 0x0000300, 0x0800300, N_INV), \
12159 X(vmovn, 0x1b20200, N_INV, N_INV), \
12160 X(vtrn, 0x1b20080, N_INV, N_INV), \
12161 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
12162 X(vqmovun, 0x1b20240, N_INV, N_INV), \
12163 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
12164 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
12165 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
12166 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
12167 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
12168 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
12169 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
12170 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
12171 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
12172
12173enum neon_opc
12174{
12175#define X(OPC,I,F,S) N_MNEM_##OPC
12176NEON_ENC_TAB
12177#undef X
12178};
b99bd4ef 12179
5287ad62
JB
12180static const struct neon_tab_entry neon_enc_tab[] =
12181{
12182#define X(OPC,I,F,S) { (I), (F), (S) }
12183NEON_ENC_TAB
12184#undef X
12185};
b99bd4ef 12186
88714cb8
DG
12187/* Do not use these macros; instead, use NEON_ENCODE defined below. */
12188#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12189#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12190#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12191#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12192#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12193#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12194#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12195#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12196#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12197#define NEON_ENC_SINGLE_(X) \
037e8744 12198 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 12199#define NEON_ENC_DOUBLE_(X) \
037e8744 12200 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 12201
88714cb8
DG
12202#define NEON_ENCODE(type, inst) \
12203 do \
12204 { \
12205 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
12206 inst.is_neon = 1; \
12207 } \
12208 while (0)
12209
12210#define check_neon_suffixes \
12211 do \
12212 { \
12213 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
12214 { \
12215 as_bad (_("invalid neon suffix for non neon instruction")); \
12216 return; \
12217 } \
12218 } \
12219 while (0)
12220
037e8744
JB
12221/* Define shapes for instruction operands. The following mnemonic characters
12222 are used in this table:
5287ad62 12223
037e8744 12224 F - VFP S<n> register
5287ad62
JB
12225 D - Neon D<n> register
12226 Q - Neon Q<n> register
12227 I - Immediate
12228 S - Scalar
12229 R - ARM register
12230 L - D<n> register list
5f4273c7 12231
037e8744
JB
12232 This table is used to generate various data:
12233 - enumerations of the form NS_DDR to be used as arguments to
12234 neon_select_shape.
12235 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 12236 - a table used to drive neon_select_shape. */
b99bd4ef 12237
037e8744
JB
12238#define NEON_SHAPE_DEF \
12239 X(3, (D, D, D), DOUBLE), \
12240 X(3, (Q, Q, Q), QUAD), \
12241 X(3, (D, D, I), DOUBLE), \
12242 X(3, (Q, Q, I), QUAD), \
12243 X(3, (D, D, S), DOUBLE), \
12244 X(3, (Q, Q, S), QUAD), \
12245 X(2, (D, D), DOUBLE), \
12246 X(2, (Q, Q), QUAD), \
12247 X(2, (D, S), DOUBLE), \
12248 X(2, (Q, S), QUAD), \
12249 X(2, (D, R), DOUBLE), \
12250 X(2, (Q, R), QUAD), \
12251 X(2, (D, I), DOUBLE), \
12252 X(2, (Q, I), QUAD), \
12253 X(3, (D, L, D), DOUBLE), \
12254 X(2, (D, Q), MIXED), \
12255 X(2, (Q, D), MIXED), \
12256 X(3, (D, Q, I), MIXED), \
12257 X(3, (Q, D, I), MIXED), \
12258 X(3, (Q, D, D), MIXED), \
12259 X(3, (D, Q, Q), MIXED), \
12260 X(3, (Q, Q, D), MIXED), \
12261 X(3, (Q, D, S), MIXED), \
12262 X(3, (D, Q, S), MIXED), \
12263 X(4, (D, D, D, I), DOUBLE), \
12264 X(4, (Q, Q, Q, I), QUAD), \
12265 X(2, (F, F), SINGLE), \
12266 X(3, (F, F, F), SINGLE), \
12267 X(2, (F, I), SINGLE), \
12268 X(2, (F, D), MIXED), \
12269 X(2, (D, F), MIXED), \
12270 X(3, (F, F, I), MIXED), \
12271 X(4, (R, R, F, F), SINGLE), \
12272 X(4, (F, F, R, R), SINGLE), \
12273 X(3, (D, R, R), DOUBLE), \
12274 X(3, (R, R, D), DOUBLE), \
12275 X(2, (S, R), SINGLE), \
12276 X(2, (R, S), SINGLE), \
12277 X(2, (F, R), SINGLE), \
12278 X(2, (R, F), SINGLE)
12279
12280#define S2(A,B) NS_##A##B
12281#define S3(A,B,C) NS_##A##B##C
12282#define S4(A,B,C,D) NS_##A##B##C##D
12283
12284#define X(N, L, C) S##N L
12285
5287ad62
JB
12286enum neon_shape
12287{
037e8744
JB
12288 NEON_SHAPE_DEF,
12289 NS_NULL
5287ad62 12290};
b99bd4ef 12291
037e8744
JB
12292#undef X
12293#undef S2
12294#undef S3
12295#undef S4
12296
12297enum neon_shape_class
12298{
12299 SC_SINGLE,
12300 SC_DOUBLE,
12301 SC_QUAD,
12302 SC_MIXED
12303};
12304
12305#define X(N, L, C) SC_##C
12306
12307static enum neon_shape_class neon_shape_class[] =
12308{
12309 NEON_SHAPE_DEF
12310};
12311
12312#undef X
12313
12314enum neon_shape_el
12315{
12316 SE_F,
12317 SE_D,
12318 SE_Q,
12319 SE_I,
12320 SE_S,
12321 SE_R,
12322 SE_L
12323};
12324
12325/* Register widths of above. */
12326static unsigned neon_shape_el_size[] =
12327{
12328 32,
12329 64,
12330 128,
12331 0,
12332 32,
12333 32,
12334 0
12335};
12336
12337struct neon_shape_info
12338{
12339 unsigned els;
12340 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
12341};
12342
12343#define S2(A,B) { SE_##A, SE_##B }
12344#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
12345#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
12346
12347#define X(N, L, C) { N, S##N L }
12348
12349static struct neon_shape_info neon_shape_tab[] =
12350{
12351 NEON_SHAPE_DEF
12352};
12353
12354#undef X
12355#undef S2
12356#undef S3
12357#undef S4
12358
5287ad62
JB
12359/* Bit masks used in type checking given instructions.
12360 'N_EQK' means the type must be the same as (or based on in some way) the key
12361 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
12362 set, various other bits can be set as well in order to modify the meaning of
12363 the type constraint. */
12364
12365enum neon_type_mask
12366{
8e79c3df
CM
12367 N_S8 = 0x0000001,
12368 N_S16 = 0x0000002,
12369 N_S32 = 0x0000004,
12370 N_S64 = 0x0000008,
12371 N_U8 = 0x0000010,
12372 N_U16 = 0x0000020,
12373 N_U32 = 0x0000040,
12374 N_U64 = 0x0000080,
12375 N_I8 = 0x0000100,
12376 N_I16 = 0x0000200,
12377 N_I32 = 0x0000400,
12378 N_I64 = 0x0000800,
12379 N_8 = 0x0001000,
12380 N_16 = 0x0002000,
12381 N_32 = 0x0004000,
12382 N_64 = 0x0008000,
12383 N_P8 = 0x0010000,
12384 N_P16 = 0x0020000,
12385 N_F16 = 0x0040000,
12386 N_F32 = 0x0080000,
12387 N_F64 = 0x0100000,
c921be7d
NC
12388 N_KEY = 0x1000000, /* Key element (main type specifier). */
12389 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 12390 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
c921be7d
NC
12391 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
12392 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
12393 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
12394 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
12395 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
12396 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
12397 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 12398 N_UTYP = 0,
037e8744 12399 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
12400};
12401
dcbf9037
JB
12402#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
12403
5287ad62
JB
12404#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
12405#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
12406#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
12407#define N_SUF_32 (N_SU_32 | N_F32)
12408#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
12409#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
12410
12411/* Pass this as the first type argument to neon_check_type to ignore types
12412 altogether. */
12413#define N_IGNORE_TYPE (N_KEY | N_EQK)
12414
037e8744
JB
12415/* Select a "shape" for the current instruction (describing register types or
12416 sizes) from a list of alternatives. Return NS_NULL if the current instruction
12417 doesn't fit. For non-polymorphic shapes, checking is usually done as a
12418 function of operand parsing, so this function doesn't need to be called.
12419 Shapes should be listed in order of decreasing length. */
5287ad62
JB
12420
12421static enum neon_shape
037e8744 12422neon_select_shape (enum neon_shape shape, ...)
5287ad62 12423{
037e8744
JB
12424 va_list ap;
12425 enum neon_shape first_shape = shape;
5287ad62
JB
12426
12427 /* Fix missing optional operands. FIXME: we don't know at this point how
12428 many arguments we should have, so this makes the assumption that we have
12429 > 1. This is true of all current Neon opcodes, I think, but may not be
12430 true in the future. */
12431 if (!inst.operands[1].present)
12432 inst.operands[1] = inst.operands[0];
12433
037e8744 12434 va_start (ap, shape);
5f4273c7 12435
21d799b5 12436 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
12437 {
12438 unsigned j;
12439 int matches = 1;
12440
12441 for (j = 0; j < neon_shape_tab[shape].els; j++)
12442 {
12443 if (!inst.operands[j].present)
12444 {
12445 matches = 0;
12446 break;
12447 }
12448
12449 switch (neon_shape_tab[shape].el[j])
12450 {
12451 case SE_F:
12452 if (!(inst.operands[j].isreg
12453 && inst.operands[j].isvec
12454 && inst.operands[j].issingle
12455 && !inst.operands[j].isquad))
12456 matches = 0;
12457 break;
12458
12459 case SE_D:
12460 if (!(inst.operands[j].isreg
12461 && inst.operands[j].isvec
12462 && !inst.operands[j].isquad
12463 && !inst.operands[j].issingle))
12464 matches = 0;
12465 break;
12466
12467 case SE_R:
12468 if (!(inst.operands[j].isreg
12469 && !inst.operands[j].isvec))
12470 matches = 0;
12471 break;
12472
12473 case SE_Q:
12474 if (!(inst.operands[j].isreg
12475 && inst.operands[j].isvec
12476 && inst.operands[j].isquad
12477 && !inst.operands[j].issingle))
12478 matches = 0;
12479 break;
12480
12481 case SE_I:
12482 if (!(!inst.operands[j].isreg
12483 && !inst.operands[j].isscalar))
12484 matches = 0;
12485 break;
12486
12487 case SE_S:
12488 if (!(!inst.operands[j].isreg
12489 && inst.operands[j].isscalar))
12490 matches = 0;
12491 break;
12492
12493 case SE_L:
12494 break;
12495 }
3fde54a2
JZ
12496 if (!matches)
12497 break;
037e8744 12498 }
ad6cec43
MGD
12499 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
12500 /* We've matched all the entries in the shape table, and we don't
12501 have any left over operands which have not been matched. */
5287ad62 12502 break;
037e8744 12503 }
5f4273c7 12504
037e8744 12505 va_end (ap);
5287ad62 12506
037e8744
JB
12507 if (shape == NS_NULL && first_shape != NS_NULL)
12508 first_error (_("invalid instruction shape"));
5287ad62 12509
037e8744
JB
12510 return shape;
12511}
5287ad62 12512
037e8744
JB
12513/* True if SHAPE is predominantly a quadword operation (most of the time, this
12514 means the Q bit should be set). */
12515
12516static int
12517neon_quad (enum neon_shape shape)
12518{
12519 return neon_shape_class[shape] == SC_QUAD;
5287ad62 12520}
037e8744 12521
5287ad62
JB
12522static void
12523neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
12524 unsigned *g_size)
12525{
12526 /* Allow modification to be made to types which are constrained to be
12527 based on the key element, based on bits set alongside N_EQK. */
12528 if ((typebits & N_EQK) != 0)
12529 {
12530 if ((typebits & N_HLF) != 0)
12531 *g_size /= 2;
12532 else if ((typebits & N_DBL) != 0)
12533 *g_size *= 2;
12534 if ((typebits & N_SGN) != 0)
12535 *g_type = NT_signed;
12536 else if ((typebits & N_UNS) != 0)
12537 *g_type = NT_unsigned;
12538 else if ((typebits & N_INT) != 0)
12539 *g_type = NT_integer;
12540 else if ((typebits & N_FLT) != 0)
12541 *g_type = NT_float;
dcbf9037
JB
12542 else if ((typebits & N_SIZ) != 0)
12543 *g_type = NT_untyped;
5287ad62
JB
12544 }
12545}
5f4273c7 12546
5287ad62
JB
12547/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12548 operand type, i.e. the single type specified in a Neon instruction when it
12549 is the only one given. */
12550
12551static struct neon_type_el
12552neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12553{
12554 struct neon_type_el dest = *key;
5f4273c7 12555
9c2799c2 12556 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 12557
5287ad62
JB
12558 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12559
12560 return dest;
12561}
12562
12563/* Convert Neon type and size into compact bitmask representation. */
12564
12565static enum neon_type_mask
12566type_chk_of_el_type (enum neon_el_type type, unsigned size)
12567{
12568 switch (type)
12569 {
12570 case NT_untyped:
12571 switch (size)
12572 {
12573 case 8: return N_8;
12574 case 16: return N_16;
12575 case 32: return N_32;
12576 case 64: return N_64;
12577 default: ;
12578 }
12579 break;
12580
12581 case NT_integer:
12582 switch (size)
12583 {
12584 case 8: return N_I8;
12585 case 16: return N_I16;
12586 case 32: return N_I32;
12587 case 64: return N_I64;
12588 default: ;
12589 }
12590 break;
12591
12592 case NT_float:
037e8744
JB
12593 switch (size)
12594 {
8e79c3df 12595 case 16: return N_F16;
037e8744
JB
12596 case 32: return N_F32;
12597 case 64: return N_F64;
12598 default: ;
12599 }
5287ad62
JB
12600 break;
12601
12602 case NT_poly:
12603 switch (size)
12604 {
12605 case 8: return N_P8;
12606 case 16: return N_P16;
12607 default: ;
12608 }
12609 break;
12610
12611 case NT_signed:
12612 switch (size)
12613 {
12614 case 8: return N_S8;
12615 case 16: return N_S16;
12616 case 32: return N_S32;
12617 case 64: return N_S64;
12618 default: ;
12619 }
12620 break;
12621
12622 case NT_unsigned:
12623 switch (size)
12624 {
12625 case 8: return N_U8;
12626 case 16: return N_U16;
12627 case 32: return N_U32;
12628 case 64: return N_U64;
12629 default: ;
12630 }
12631 break;
12632
12633 default: ;
12634 }
5f4273c7 12635
5287ad62
JB
12636 return N_UTYP;
12637}
12638
12639/* Convert compact Neon bitmask type representation to a type and size. Only
12640 handles the case where a single bit is set in the mask. */
12641
dcbf9037 12642static int
5287ad62
JB
12643el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12644 enum neon_type_mask mask)
12645{
dcbf9037
JB
12646 if ((mask & N_EQK) != 0)
12647 return FAIL;
12648
5287ad62
JB
12649 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12650 *size = 8;
dcbf9037 12651 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 12652 *size = 16;
dcbf9037 12653 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 12654 *size = 32;
037e8744 12655 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 12656 *size = 64;
dcbf9037
JB
12657 else
12658 return FAIL;
12659
5287ad62
JB
12660 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12661 *type = NT_signed;
dcbf9037 12662 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 12663 *type = NT_unsigned;
dcbf9037 12664 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 12665 *type = NT_integer;
dcbf9037 12666 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 12667 *type = NT_untyped;
dcbf9037 12668 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 12669 *type = NT_poly;
037e8744 12670 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 12671 *type = NT_float;
dcbf9037
JB
12672 else
12673 return FAIL;
5f4273c7 12674
dcbf9037 12675 return SUCCESS;
5287ad62
JB
12676}
12677
12678/* Modify a bitmask of allowed types. This is only needed for type
12679 relaxation. */
12680
12681static unsigned
12682modify_types_allowed (unsigned allowed, unsigned mods)
12683{
12684 unsigned size;
12685 enum neon_el_type type;
12686 unsigned destmask;
12687 int i;
5f4273c7 12688
5287ad62 12689 destmask = 0;
5f4273c7 12690
5287ad62
JB
12691 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12692 {
21d799b5
NC
12693 if (el_type_of_type_chk (&type, &size,
12694 (enum neon_type_mask) (allowed & i)) == SUCCESS)
dcbf9037
JB
12695 {
12696 neon_modify_type_size (mods, &type, &size);
12697 destmask |= type_chk_of_el_type (type, size);
12698 }
5287ad62 12699 }
5f4273c7 12700
5287ad62
JB
12701 return destmask;
12702}
12703
12704/* Check type and return type classification.
12705 The manual states (paraphrase): If one datatype is given, it indicates the
12706 type given in:
12707 - the second operand, if there is one
12708 - the operand, if there is no second operand
12709 - the result, if there are no operands.
12710 This isn't quite good enough though, so we use a concept of a "key" datatype
12711 which is set on a per-instruction basis, which is the one which matters when
12712 only one data type is written.
12713 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 12714 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
12715
12716static struct neon_type_el
12717neon_check_type (unsigned els, enum neon_shape ns, ...)
12718{
12719 va_list ap;
12720 unsigned i, pass, key_el = 0;
12721 unsigned types[NEON_MAX_TYPE_ELS];
12722 enum neon_el_type k_type = NT_invtype;
12723 unsigned k_size = -1u;
12724 struct neon_type_el badtype = {NT_invtype, -1};
12725 unsigned key_allowed = 0;
12726
12727 /* Optional registers in Neon instructions are always (not) in operand 1.
12728 Fill in the missing operand here, if it was omitted. */
12729 if (els > 1 && !inst.operands[1].present)
12730 inst.operands[1] = inst.operands[0];
12731
12732 /* Suck up all the varargs. */
12733 va_start (ap, ns);
12734 for (i = 0; i < els; i++)
12735 {
12736 unsigned thisarg = va_arg (ap, unsigned);
12737 if (thisarg == N_IGNORE_TYPE)
12738 {
12739 va_end (ap);
12740 return badtype;
12741 }
12742 types[i] = thisarg;
12743 if ((thisarg & N_KEY) != 0)
12744 key_el = i;
12745 }
12746 va_end (ap);
12747
dcbf9037
JB
12748 if (inst.vectype.elems > 0)
12749 for (i = 0; i < els; i++)
12750 if (inst.operands[i].vectype.type != NT_invtype)
12751 {
12752 first_error (_("types specified in both the mnemonic and operands"));
12753 return badtype;
12754 }
12755
5287ad62
JB
12756 /* Duplicate inst.vectype elements here as necessary.
12757 FIXME: No idea if this is exactly the same as the ARM assembler,
12758 particularly when an insn takes one register and one non-register
12759 operand. */
12760 if (inst.vectype.elems == 1 && els > 1)
12761 {
12762 unsigned j;
12763 inst.vectype.elems = els;
12764 inst.vectype.el[key_el] = inst.vectype.el[0];
12765 for (j = 0; j < els; j++)
dcbf9037
JB
12766 if (j != key_el)
12767 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12768 types[j]);
12769 }
12770 else if (inst.vectype.elems == 0 && els > 0)
12771 {
12772 unsigned j;
12773 /* No types were given after the mnemonic, so look for types specified
12774 after each operand. We allow some flexibility here; as long as the
12775 "key" operand has a type, we can infer the others. */
12776 for (j = 0; j < els; j++)
12777 if (inst.operands[j].vectype.type != NT_invtype)
12778 inst.vectype.el[j] = inst.operands[j].vectype;
12779
12780 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 12781 {
dcbf9037
JB
12782 for (j = 0; j < els; j++)
12783 if (inst.operands[j].vectype.type == NT_invtype)
12784 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12785 types[j]);
12786 }
12787 else
12788 {
12789 first_error (_("operand types can't be inferred"));
12790 return badtype;
5287ad62
JB
12791 }
12792 }
12793 else if (inst.vectype.elems != els)
12794 {
dcbf9037 12795 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
12796 return badtype;
12797 }
12798
12799 for (pass = 0; pass < 2; pass++)
12800 {
12801 for (i = 0; i < els; i++)
12802 {
12803 unsigned thisarg = types[i];
12804 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12805 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12806 enum neon_el_type g_type = inst.vectype.el[i].type;
12807 unsigned g_size = inst.vectype.el[i].size;
12808
12809 /* Decay more-specific signed & unsigned types to sign-insensitive
12810 integer types if sign-specific variants are unavailable. */
12811 if ((g_type == NT_signed || g_type == NT_unsigned)
12812 && (types_allowed & N_SU_ALL) == 0)
12813 g_type = NT_integer;
12814
12815 /* If only untyped args are allowed, decay any more specific types to
12816 them. Some instructions only care about signs for some element
12817 sizes, so handle that properly. */
12818 if ((g_size == 8 && (types_allowed & N_8) != 0)
12819 || (g_size == 16 && (types_allowed & N_16) != 0)
12820 || (g_size == 32 && (types_allowed & N_32) != 0)
12821 || (g_size == 64 && (types_allowed & N_64) != 0))
12822 g_type = NT_untyped;
12823
12824 if (pass == 0)
12825 {
12826 if ((thisarg & N_KEY) != 0)
12827 {
12828 k_type = g_type;
12829 k_size = g_size;
12830 key_allowed = thisarg & ~N_KEY;
12831 }
12832 }
12833 else
12834 {
037e8744
JB
12835 if ((thisarg & N_VFP) != 0)
12836 {
99b253c5
NC
12837 enum neon_shape_el regshape;
12838 unsigned regwidth, match;
12839
12840 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12841 if (ns == NS_NULL)
12842 {
12843 first_error (_("invalid instruction shape"));
12844 return badtype;
12845 }
12846 regshape = neon_shape_tab[ns].el[i];
12847 regwidth = neon_shape_el_size[regshape];
037e8744
JB
12848
12849 /* In VFP mode, operands must match register widths. If we
12850 have a key operand, use its width, else use the width of
12851 the current operand. */
12852 if (k_size != -1u)
12853 match = k_size;
12854 else
12855 match = g_size;
12856
12857 if (regwidth != match)
12858 {
12859 first_error (_("operand size must match register width"));
12860 return badtype;
12861 }
12862 }
5f4273c7 12863
5287ad62
JB
12864 if ((thisarg & N_EQK) == 0)
12865 {
12866 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12867
12868 if ((given_type & types_allowed) == 0)
12869 {
dcbf9037 12870 first_error (_("bad type in Neon instruction"));
5287ad62
JB
12871 return badtype;
12872 }
12873 }
12874 else
12875 {
12876 enum neon_el_type mod_k_type = k_type;
12877 unsigned mod_k_size = k_size;
12878 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12879 if (g_type != mod_k_type || g_size != mod_k_size)
12880 {
dcbf9037 12881 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
12882 return badtype;
12883 }
12884 }
12885 }
12886 }
12887 }
12888
12889 return inst.vectype.el[key_el];
12890}
12891
037e8744 12892/* Neon-style VFP instruction forwarding. */
5287ad62 12893
037e8744
JB
12894/* Thumb VFP instructions have 0xE in the condition field. */
12895
12896static void
12897do_vfp_cond_or_thumb (void)
5287ad62 12898{
88714cb8
DG
12899 inst.is_neon = 1;
12900
5287ad62 12901 if (thumb_mode)
037e8744 12902 inst.instruction |= 0xe0000000;
5287ad62 12903 else
037e8744 12904 inst.instruction |= inst.cond << 28;
5287ad62
JB
12905}
12906
037e8744
JB
12907/* Look up and encode a simple mnemonic, for use as a helper function for the
12908 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12909 etc. It is assumed that operand parsing has already been done, and that the
12910 operands are in the form expected by the given opcode (this isn't necessarily
12911 the same as the form in which they were parsed, hence some massaging must
12912 take place before this function is called).
12913 Checks current arch version against that in the looked-up opcode. */
5287ad62 12914
037e8744
JB
12915static void
12916do_vfp_nsyn_opcode (const char *opname)
5287ad62 12917{
037e8744 12918 const struct asm_opcode *opcode;
5f4273c7 12919
21d799b5 12920 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 12921
037e8744
JB
12922 if (!opcode)
12923 abort ();
5287ad62 12924
037e8744
JB
12925 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12926 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12927 _(BAD_FPU));
5287ad62 12928
88714cb8
DG
12929 inst.is_neon = 1;
12930
037e8744
JB
12931 if (thumb_mode)
12932 {
12933 inst.instruction = opcode->tvalue;
12934 opcode->tencode ();
12935 }
12936 else
12937 {
12938 inst.instruction = (inst.cond << 28) | opcode->avalue;
12939 opcode->aencode ();
12940 }
12941}
5287ad62
JB
12942
12943static void
037e8744 12944do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 12945{
037e8744
JB
12946 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12947
12948 if (rs == NS_FFF)
12949 {
12950 if (is_add)
12951 do_vfp_nsyn_opcode ("fadds");
12952 else
12953 do_vfp_nsyn_opcode ("fsubs");
12954 }
12955 else
12956 {
12957 if (is_add)
12958 do_vfp_nsyn_opcode ("faddd");
12959 else
12960 do_vfp_nsyn_opcode ("fsubd");
12961 }
12962}
12963
12964/* Check operand types to see if this is a VFP instruction, and if so call
12965 PFN (). */
12966
12967static int
12968try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12969{
12970 enum neon_shape rs;
12971 struct neon_type_el et;
12972
12973 switch (args)
12974 {
12975 case 2:
12976 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12977 et = neon_check_type (2, rs,
12978 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12979 break;
5f4273c7 12980
037e8744
JB
12981 case 3:
12982 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12983 et = neon_check_type (3, rs,
12984 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12985 break;
12986
12987 default:
12988 abort ();
12989 }
12990
12991 if (et.type != NT_invtype)
12992 {
12993 pfn (rs);
12994 return SUCCESS;
12995 }
037e8744 12996
99b253c5 12997 inst.error = NULL;
037e8744
JB
12998 return FAIL;
12999}
13000
13001static void
13002do_vfp_nsyn_mla_mls (enum neon_shape rs)
13003{
13004 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 13005
037e8744
JB
13006 if (rs == NS_FFF)
13007 {
13008 if (is_mla)
13009 do_vfp_nsyn_opcode ("fmacs");
13010 else
1ee69515 13011 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
13012 }
13013 else
13014 {
13015 if (is_mla)
13016 do_vfp_nsyn_opcode ("fmacd");
13017 else
1ee69515 13018 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
13019 }
13020}
13021
62f3b8c8
PB
13022static void
13023do_vfp_nsyn_fma_fms (enum neon_shape rs)
13024{
13025 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
13026
13027 if (rs == NS_FFF)
13028 {
13029 if (is_fma)
13030 do_vfp_nsyn_opcode ("ffmas");
13031 else
13032 do_vfp_nsyn_opcode ("ffnmas");
13033 }
13034 else
13035 {
13036 if (is_fma)
13037 do_vfp_nsyn_opcode ("ffmad");
13038 else
13039 do_vfp_nsyn_opcode ("ffnmad");
13040 }
13041}
13042
037e8744
JB
13043static void
13044do_vfp_nsyn_mul (enum neon_shape rs)
13045{
13046 if (rs == NS_FFF)
13047 do_vfp_nsyn_opcode ("fmuls");
13048 else
13049 do_vfp_nsyn_opcode ("fmuld");
13050}
13051
13052static void
13053do_vfp_nsyn_abs_neg (enum neon_shape rs)
13054{
13055 int is_neg = (inst.instruction & 0x80) != 0;
13056 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
13057
13058 if (rs == NS_FF)
13059 {
13060 if (is_neg)
13061 do_vfp_nsyn_opcode ("fnegs");
13062 else
13063 do_vfp_nsyn_opcode ("fabss");
13064 }
13065 else
13066 {
13067 if (is_neg)
13068 do_vfp_nsyn_opcode ("fnegd");
13069 else
13070 do_vfp_nsyn_opcode ("fabsd");
13071 }
13072}
13073
13074/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
13075 insns belong to Neon, and are handled elsewhere. */
13076
13077static void
13078do_vfp_nsyn_ldm_stm (int is_dbmode)
13079{
13080 int is_ldm = (inst.instruction & (1 << 20)) != 0;
13081 if (is_ldm)
13082 {
13083 if (is_dbmode)
13084 do_vfp_nsyn_opcode ("fldmdbs");
13085 else
13086 do_vfp_nsyn_opcode ("fldmias");
13087 }
13088 else
13089 {
13090 if (is_dbmode)
13091 do_vfp_nsyn_opcode ("fstmdbs");
13092 else
13093 do_vfp_nsyn_opcode ("fstmias");
13094 }
13095}
13096
037e8744
JB
13097static void
13098do_vfp_nsyn_sqrt (void)
13099{
13100 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13101 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13102
037e8744
JB
13103 if (rs == NS_FF)
13104 do_vfp_nsyn_opcode ("fsqrts");
13105 else
13106 do_vfp_nsyn_opcode ("fsqrtd");
13107}
13108
13109static void
13110do_vfp_nsyn_div (void)
13111{
13112 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13113 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13114 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13115
037e8744
JB
13116 if (rs == NS_FFF)
13117 do_vfp_nsyn_opcode ("fdivs");
13118 else
13119 do_vfp_nsyn_opcode ("fdivd");
13120}
13121
13122static void
13123do_vfp_nsyn_nmul (void)
13124{
13125 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13126 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13127 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13128
037e8744
JB
13129 if (rs == NS_FFF)
13130 {
88714cb8 13131 NEON_ENCODE (SINGLE, inst);
037e8744
JB
13132 do_vfp_sp_dyadic ();
13133 }
13134 else
13135 {
88714cb8 13136 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
13137 do_vfp_dp_rd_rn_rm ();
13138 }
13139 do_vfp_cond_or_thumb ();
13140}
13141
13142static void
13143do_vfp_nsyn_cmp (void)
13144{
13145 if (inst.operands[1].isreg)
13146 {
13147 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13148 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13149
037e8744
JB
13150 if (rs == NS_FF)
13151 {
88714cb8 13152 NEON_ENCODE (SINGLE, inst);
037e8744
JB
13153 do_vfp_sp_monadic ();
13154 }
13155 else
13156 {
88714cb8 13157 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
13158 do_vfp_dp_rd_rm ();
13159 }
13160 }
13161 else
13162 {
13163 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
13164 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
13165
13166 switch (inst.instruction & 0x0fffffff)
13167 {
13168 case N_MNEM_vcmp:
13169 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
13170 break;
13171 case N_MNEM_vcmpe:
13172 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
13173 break;
13174 default:
13175 abort ();
13176 }
5f4273c7 13177
037e8744
JB
13178 if (rs == NS_FI)
13179 {
88714cb8 13180 NEON_ENCODE (SINGLE, inst);
037e8744
JB
13181 do_vfp_sp_compare_z ();
13182 }
13183 else
13184 {
88714cb8 13185 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
13186 do_vfp_dp_rd ();
13187 }
13188 }
13189 do_vfp_cond_or_thumb ();
13190}
13191
13192static void
13193nsyn_insert_sp (void)
13194{
13195 inst.operands[1] = inst.operands[0];
13196 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 13197 inst.operands[0].reg = REG_SP;
037e8744
JB
13198 inst.operands[0].isreg = 1;
13199 inst.operands[0].writeback = 1;
13200 inst.operands[0].present = 1;
13201}
13202
13203static void
13204do_vfp_nsyn_push (void)
13205{
13206 nsyn_insert_sp ();
13207 if (inst.operands[1].issingle)
13208 do_vfp_nsyn_opcode ("fstmdbs");
13209 else
13210 do_vfp_nsyn_opcode ("fstmdbd");
13211}
13212
13213static void
13214do_vfp_nsyn_pop (void)
13215{
13216 nsyn_insert_sp ();
13217 if (inst.operands[1].issingle)
22b5b651 13218 do_vfp_nsyn_opcode ("fldmias");
037e8744 13219 else
22b5b651 13220 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
13221}
13222
13223/* Fix up Neon data-processing instructions, ORing in the correct bits for
13224 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
13225
88714cb8
DG
13226static void
13227neon_dp_fixup (struct arm_it* insn)
037e8744 13228{
88714cb8
DG
13229 unsigned int i = insn->instruction;
13230 insn->is_neon = 1;
13231
037e8744
JB
13232 if (thumb_mode)
13233 {
13234 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
13235 if (i & (1 << 24))
13236 i |= 1 << 28;
5f4273c7 13237
037e8744 13238 i &= ~(1 << 24);
5f4273c7 13239
037e8744
JB
13240 i |= 0xef000000;
13241 }
13242 else
13243 i |= 0xf2000000;
5f4273c7 13244
88714cb8 13245 insn->instruction = i;
037e8744
JB
13246}
13247
13248/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
13249 (0, 1, 2, 3). */
13250
13251static unsigned
13252neon_logbits (unsigned x)
13253{
13254 return ffs (x) - 4;
13255}
13256
13257#define LOW4(R) ((R) & 0xf)
13258#define HI1(R) (((R) >> 4) & 1)
13259
13260/* Encode insns with bit pattern:
13261
13262 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13263 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 13264
037e8744
JB
13265 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
13266 different meaning for some instruction. */
13267
13268static void
13269neon_three_same (int isquad, int ubit, int size)
13270{
13271 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13272 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13273 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13274 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13275 inst.instruction |= LOW4 (inst.operands[2].reg);
13276 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13277 inst.instruction |= (isquad != 0) << 6;
13278 inst.instruction |= (ubit != 0) << 24;
13279 if (size != -1)
13280 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 13281
88714cb8 13282 neon_dp_fixup (&inst);
037e8744
JB
13283}
13284
13285/* Encode instructions of the form:
13286
13287 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
13288 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
13289
13290 Don't write size if SIZE == -1. */
13291
13292static void
13293neon_two_same (int qbit, int ubit, int size)
13294{
13295 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13296 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13297 inst.instruction |= LOW4 (inst.operands[1].reg);
13298 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13299 inst.instruction |= (qbit != 0) << 6;
13300 inst.instruction |= (ubit != 0) << 24;
13301
13302 if (size != -1)
13303 inst.instruction |= neon_logbits (size) << 18;
13304
88714cb8 13305 neon_dp_fixup (&inst);
5287ad62
JB
13306}
13307
13308/* Neon instruction encoders, in approximate order of appearance. */
13309
13310static void
13311do_neon_dyadic_i_su (void)
13312{
037e8744 13313 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13314 struct neon_type_el et = neon_check_type (3, rs,
13315 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 13316 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13317}
13318
13319static void
13320do_neon_dyadic_i64_su (void)
13321{
037e8744 13322 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13323 struct neon_type_el et = neon_check_type (3, rs,
13324 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 13325 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13326}
13327
13328static void
13329neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
13330 unsigned immbits)
13331{
13332 unsigned size = et.size >> 3;
13333 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13334 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13335 inst.instruction |= LOW4 (inst.operands[1].reg);
13336 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13337 inst.instruction |= (isquad != 0) << 6;
13338 inst.instruction |= immbits << 16;
13339 inst.instruction |= (size >> 3) << 7;
13340 inst.instruction |= (size & 0x7) << 19;
13341 if (write_ubit)
13342 inst.instruction |= (uval != 0) << 24;
13343
88714cb8 13344 neon_dp_fixup (&inst);
5287ad62
JB
13345}
13346
13347static void
13348do_neon_shl_imm (void)
13349{
13350 if (!inst.operands[2].isreg)
13351 {
037e8744 13352 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 13353 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
88714cb8 13354 NEON_ENCODE (IMMED, inst);
037e8744 13355 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
13356 }
13357 else
13358 {
037e8744 13359 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13360 struct neon_type_el et = neon_check_type (3, rs,
13361 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13362 unsigned int tmp;
13363
13364 /* VSHL/VQSHL 3-register variants have syntax such as:
13365 vshl.xx Dd, Dm, Dn
13366 whereas other 3-register operations encoded by neon_three_same have
13367 syntax like:
13368 vadd.xx Dd, Dn, Dm
13369 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
13370 here. */
13371 tmp = inst.operands[2].reg;
13372 inst.operands[2].reg = inst.operands[1].reg;
13373 inst.operands[1].reg = tmp;
88714cb8 13374 NEON_ENCODE (INTEGER, inst);
037e8744 13375 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13376 }
13377}
13378
13379static void
13380do_neon_qshl_imm (void)
13381{
13382 if (!inst.operands[2].isreg)
13383 {
037e8744 13384 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 13385 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 13386
88714cb8 13387 NEON_ENCODE (IMMED, inst);
037e8744 13388 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13389 inst.operands[2].imm);
13390 }
13391 else
13392 {
037e8744 13393 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13394 struct neon_type_el et = neon_check_type (3, rs,
13395 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13396 unsigned int tmp;
13397
13398 /* See note in do_neon_shl_imm. */
13399 tmp = inst.operands[2].reg;
13400 inst.operands[2].reg = inst.operands[1].reg;
13401 inst.operands[1].reg = tmp;
88714cb8 13402 NEON_ENCODE (INTEGER, inst);
037e8744 13403 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13404 }
13405}
13406
627907b7
JB
13407static void
13408do_neon_rshl (void)
13409{
13410 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13411 struct neon_type_el et = neon_check_type (3, rs,
13412 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13413 unsigned int tmp;
13414
13415 tmp = inst.operands[2].reg;
13416 inst.operands[2].reg = inst.operands[1].reg;
13417 inst.operands[1].reg = tmp;
13418 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13419}
13420
5287ad62
JB
13421static int
13422neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
13423{
036dc3f7
PB
13424 /* Handle .I8 pseudo-instructions. */
13425 if (size == 8)
5287ad62 13426 {
5287ad62
JB
13427 /* Unfortunately, this will make everything apart from zero out-of-range.
13428 FIXME is this the intended semantics? There doesn't seem much point in
13429 accepting .I8 if so. */
13430 immediate |= immediate << 8;
13431 size = 16;
036dc3f7
PB
13432 }
13433
13434 if (size >= 32)
13435 {
13436 if (immediate == (immediate & 0x000000ff))
13437 {
13438 *immbits = immediate;
13439 return 0x1;
13440 }
13441 else if (immediate == (immediate & 0x0000ff00))
13442 {
13443 *immbits = immediate >> 8;
13444 return 0x3;
13445 }
13446 else if (immediate == (immediate & 0x00ff0000))
13447 {
13448 *immbits = immediate >> 16;
13449 return 0x5;
13450 }
13451 else if (immediate == (immediate & 0xff000000))
13452 {
13453 *immbits = immediate >> 24;
13454 return 0x7;
13455 }
13456 if ((immediate & 0xffff) != (immediate >> 16))
13457 goto bad_immediate;
13458 immediate &= 0xffff;
5287ad62
JB
13459 }
13460
13461 if (immediate == (immediate & 0x000000ff))
13462 {
13463 *immbits = immediate;
036dc3f7 13464 return 0x9;
5287ad62
JB
13465 }
13466 else if (immediate == (immediate & 0x0000ff00))
13467 {
13468 *immbits = immediate >> 8;
036dc3f7 13469 return 0xb;
5287ad62
JB
13470 }
13471
13472 bad_immediate:
dcbf9037 13473 first_error (_("immediate value out of range"));
5287ad62
JB
13474 return FAIL;
13475}
13476
13477/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
13478 A, B, C, D. */
13479
13480static int
13481neon_bits_same_in_bytes (unsigned imm)
13482{
13483 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
13484 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
13485 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
13486 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
13487}
13488
13489/* For immediate of above form, return 0bABCD. */
13490
13491static unsigned
13492neon_squash_bits (unsigned imm)
13493{
13494 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
13495 | ((imm & 0x01000000) >> 21);
13496}
13497
136da414 13498/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
13499
13500static unsigned
13501neon_qfloat_bits (unsigned imm)
13502{
136da414 13503 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
13504}
13505
13506/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
13507 the instruction. *OP is passed as the initial value of the op field, and
13508 may be set to a different value depending on the constant (i.e.
13509 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 13510 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 13511 try smaller element sizes. */
5287ad62
JB
13512
13513static int
c96612cc
JB
13514neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
13515 unsigned *immbits, int *op, int size,
13516 enum neon_el_type type)
5287ad62 13517{
c96612cc
JB
13518 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13519 float. */
13520 if (type == NT_float && !float_p)
13521 return FAIL;
13522
136da414
JB
13523 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13524 {
13525 if (size != 32 || *op == 1)
13526 return FAIL;
13527 *immbits = neon_qfloat_bits (immlo);
13528 return 0xf;
13529 }
036dc3f7
PB
13530
13531 if (size == 64)
5287ad62 13532 {
036dc3f7
PB
13533 if (neon_bits_same_in_bytes (immhi)
13534 && neon_bits_same_in_bytes (immlo))
13535 {
13536 if (*op == 1)
13537 return FAIL;
13538 *immbits = (neon_squash_bits (immhi) << 4)
13539 | neon_squash_bits (immlo);
13540 *op = 1;
13541 return 0xe;
13542 }
13543
13544 if (immhi != immlo)
13545 return FAIL;
5287ad62 13546 }
036dc3f7
PB
13547
13548 if (size >= 32)
5287ad62 13549 {
036dc3f7
PB
13550 if (immlo == (immlo & 0x000000ff))
13551 {
13552 *immbits = immlo;
13553 return 0x0;
13554 }
13555 else if (immlo == (immlo & 0x0000ff00))
13556 {
13557 *immbits = immlo >> 8;
13558 return 0x2;
13559 }
13560 else if (immlo == (immlo & 0x00ff0000))
13561 {
13562 *immbits = immlo >> 16;
13563 return 0x4;
13564 }
13565 else if (immlo == (immlo & 0xff000000))
13566 {
13567 *immbits = immlo >> 24;
13568 return 0x6;
13569 }
13570 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13571 {
13572 *immbits = (immlo >> 8) & 0xff;
13573 return 0xc;
13574 }
13575 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13576 {
13577 *immbits = (immlo >> 16) & 0xff;
13578 return 0xd;
13579 }
13580
13581 if ((immlo & 0xffff) != (immlo >> 16))
13582 return FAIL;
13583 immlo &= 0xffff;
5287ad62 13584 }
036dc3f7
PB
13585
13586 if (size >= 16)
5287ad62 13587 {
036dc3f7
PB
13588 if (immlo == (immlo & 0x000000ff))
13589 {
13590 *immbits = immlo;
13591 return 0x8;
13592 }
13593 else if (immlo == (immlo & 0x0000ff00))
13594 {
13595 *immbits = immlo >> 8;
13596 return 0xa;
13597 }
13598
13599 if ((immlo & 0xff) != (immlo >> 8))
13600 return FAIL;
13601 immlo &= 0xff;
5287ad62 13602 }
036dc3f7
PB
13603
13604 if (immlo == (immlo & 0x000000ff))
5287ad62 13605 {
036dc3f7
PB
13606 /* Don't allow MVN with 8-bit immediate. */
13607 if (*op == 1)
13608 return FAIL;
13609 *immbits = immlo;
13610 return 0xe;
5287ad62 13611 }
5287ad62
JB
13612
13613 return FAIL;
13614}
13615
13616/* Write immediate bits [7:0] to the following locations:
13617
13618 |28/24|23 19|18 16|15 4|3 0|
13619 | 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|
13620
13621 This function is used by VMOV/VMVN/VORR/VBIC. */
13622
13623static void
13624neon_write_immbits (unsigned immbits)
13625{
13626 inst.instruction |= immbits & 0xf;
13627 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13628 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13629}
13630
13631/* Invert low-order SIZE bits of XHI:XLO. */
13632
13633static void
13634neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13635{
13636 unsigned immlo = xlo ? *xlo : 0;
13637 unsigned immhi = xhi ? *xhi : 0;
13638
13639 switch (size)
13640 {
13641 case 8:
13642 immlo = (~immlo) & 0xff;
13643 break;
13644
13645 case 16:
13646 immlo = (~immlo) & 0xffff;
13647 break;
13648
13649 case 64:
13650 immhi = (~immhi) & 0xffffffff;
13651 /* fall through. */
13652
13653 case 32:
13654 immlo = (~immlo) & 0xffffffff;
13655 break;
13656
13657 default:
13658 abort ();
13659 }
13660
13661 if (xlo)
13662 *xlo = immlo;
13663
13664 if (xhi)
13665 *xhi = immhi;
13666}
13667
13668static void
13669do_neon_logic (void)
13670{
13671 if (inst.operands[2].present && inst.operands[2].isreg)
13672 {
037e8744 13673 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13674 neon_check_type (3, rs, N_IGNORE_TYPE);
13675 /* U bit and size field were set as part of the bitmask. */
88714cb8 13676 NEON_ENCODE (INTEGER, inst);
037e8744 13677 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13678 }
13679 else
13680 {
4316f0d2
DG
13681 const int three_ops_form = (inst.operands[2].present
13682 && !inst.operands[2].isreg);
13683 const int immoperand = (three_ops_form ? 2 : 1);
13684 enum neon_shape rs = (three_ops_form
13685 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13686 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744
JB
13687 struct neon_type_el et = neon_check_type (2, rs,
13688 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 13689 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
13690 unsigned immbits;
13691 int cmode;
5f4273c7 13692
5287ad62
JB
13693 if (et.type == NT_invtype)
13694 return;
5f4273c7 13695
4316f0d2
DG
13696 if (three_ops_form)
13697 constraint (inst.operands[0].reg != inst.operands[1].reg,
13698 _("first and second operands shall be the same register"));
13699
88714cb8 13700 NEON_ENCODE (IMMED, inst);
5287ad62 13701
4316f0d2 13702 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
13703 if (et.size == 64)
13704 {
13705 /* .i64 is a pseudo-op, so the immediate must be a repeating
13706 pattern. */
4316f0d2
DG
13707 if (immbits != (inst.operands[immoperand].regisimm ?
13708 inst.operands[immoperand].reg : 0))
036dc3f7
PB
13709 {
13710 /* Set immbits to an invalid constant. */
13711 immbits = 0xdeadbeef;
13712 }
13713 }
13714
5287ad62
JB
13715 switch (opcode)
13716 {
13717 case N_MNEM_vbic:
036dc3f7 13718 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13719 break;
5f4273c7 13720
5287ad62 13721 case N_MNEM_vorr:
036dc3f7 13722 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13723 break;
5f4273c7 13724
5287ad62
JB
13725 case N_MNEM_vand:
13726 /* Pseudo-instruction for VBIC. */
5287ad62
JB
13727 neon_invert_size (&immbits, 0, et.size);
13728 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13729 break;
5f4273c7 13730
5287ad62
JB
13731 case N_MNEM_vorn:
13732 /* Pseudo-instruction for VORR. */
5287ad62
JB
13733 neon_invert_size (&immbits, 0, et.size);
13734 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13735 break;
5f4273c7 13736
5287ad62
JB
13737 default:
13738 abort ();
13739 }
13740
13741 if (cmode == FAIL)
13742 return;
13743
037e8744 13744 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13745 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13746 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13747 inst.instruction |= cmode << 8;
13748 neon_write_immbits (immbits);
5f4273c7 13749
88714cb8 13750 neon_dp_fixup (&inst);
5287ad62
JB
13751 }
13752}
13753
13754static void
13755do_neon_bitfield (void)
13756{
037e8744 13757 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 13758 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 13759 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13760}
13761
13762static void
dcbf9037
JB
13763neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13764 unsigned destbits)
5287ad62 13765{
037e8744 13766 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
13767 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13768 types | N_KEY);
5287ad62
JB
13769 if (et.type == NT_float)
13770 {
88714cb8 13771 NEON_ENCODE (FLOAT, inst);
037e8744 13772 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13773 }
13774 else
13775 {
88714cb8 13776 NEON_ENCODE (INTEGER, inst);
037e8744 13777 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
13778 }
13779}
13780
13781static void
13782do_neon_dyadic_if_su (void)
13783{
dcbf9037 13784 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13785}
13786
13787static void
13788do_neon_dyadic_if_su_d (void)
13789{
13790 /* This version only allow D registers, but that constraint is enforced during
13791 operand parsing so we don't need to do anything extra here. */
dcbf9037 13792 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13793}
13794
5287ad62
JB
13795static void
13796do_neon_dyadic_if_i_d (void)
13797{
428e3f1f
PB
13798 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13799 affected if we specify unsigned args. */
13800 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
13801}
13802
037e8744
JB
13803enum vfp_or_neon_is_neon_bits
13804{
13805 NEON_CHECK_CC = 1,
13806 NEON_CHECK_ARCH = 2
13807};
13808
13809/* Call this function if an instruction which may have belonged to the VFP or
13810 Neon instruction sets, but turned out to be a Neon instruction (due to the
13811 operand types involved, etc.). We have to check and/or fix-up a couple of
13812 things:
13813
13814 - Make sure the user hasn't attempted to make a Neon instruction
13815 conditional.
13816 - Alter the value in the condition code field if necessary.
13817 - Make sure that the arch supports Neon instructions.
13818
13819 Which of these operations take place depends on bits from enum
13820 vfp_or_neon_is_neon_bits.
13821
13822 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13823 current instruction's condition is COND_ALWAYS, the condition field is
13824 changed to inst.uncond_value. This is necessary because instructions shared
13825 between VFP and Neon may be conditional for the VFP variants only, and the
13826 unconditional Neon version must have, e.g., 0xF in the condition field. */
13827
13828static int
13829vfp_or_neon_is_neon (unsigned check)
13830{
13831 /* Conditions are always legal in Thumb mode (IT blocks). */
13832 if (!thumb_mode && (check & NEON_CHECK_CC))
13833 {
13834 if (inst.cond != COND_ALWAYS)
13835 {
13836 first_error (_(BAD_COND));
13837 return FAIL;
13838 }
13839 if (inst.uncond_value != -1)
13840 inst.instruction |= inst.uncond_value << 28;
13841 }
5f4273c7 13842
037e8744
JB
13843 if ((check & NEON_CHECK_ARCH)
13844 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13845 {
13846 first_error (_(BAD_FPU));
13847 return FAIL;
13848 }
5f4273c7 13849
037e8744
JB
13850 return SUCCESS;
13851}
13852
5287ad62
JB
13853static void
13854do_neon_addsub_if_i (void)
13855{
037e8744
JB
13856 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13857 return;
13858
13859 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13860 return;
13861
5287ad62
JB
13862 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13863 affected if we specify unsigned args. */
dcbf9037 13864 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
13865}
13866
13867/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13868 result to be:
13869 V<op> A,B (A is operand 0, B is operand 2)
13870 to mean:
13871 V<op> A,B,A
13872 not:
13873 V<op> A,B,B
13874 so handle that case specially. */
13875
13876static void
13877neon_exchange_operands (void)
13878{
13879 void *scratch = alloca (sizeof (inst.operands[0]));
13880 if (inst.operands[1].present)
13881 {
13882 /* Swap operands[1] and operands[2]. */
13883 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13884 inst.operands[1] = inst.operands[2];
13885 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13886 }
13887 else
13888 {
13889 inst.operands[1] = inst.operands[2];
13890 inst.operands[2] = inst.operands[0];
13891 }
13892}
13893
13894static void
13895neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13896{
13897 if (inst.operands[2].isreg)
13898 {
13899 if (invert)
13900 neon_exchange_operands ();
dcbf9037 13901 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
13902 }
13903 else
13904 {
037e8744 13905 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
13906 struct neon_type_el et = neon_check_type (2, rs,
13907 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 13908
88714cb8 13909 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13910 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13911 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13912 inst.instruction |= LOW4 (inst.operands[1].reg);
13913 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13914 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13915 inst.instruction |= (et.type == NT_float) << 10;
13916 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13917
88714cb8 13918 neon_dp_fixup (&inst);
5287ad62
JB
13919 }
13920}
13921
13922static void
13923do_neon_cmp (void)
13924{
13925 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13926}
13927
13928static void
13929do_neon_cmp_inv (void)
13930{
13931 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13932}
13933
13934static void
13935do_neon_ceq (void)
13936{
13937 neon_compare (N_IF_32, N_IF_32, FALSE);
13938}
13939
13940/* For multiply instructions, we have the possibility of 16-bit or 32-bit
13941 scalars, which are encoded in 5 bits, M : Rm.
13942 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13943 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13944 index in M. */
13945
13946static unsigned
13947neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13948{
dcbf9037
JB
13949 unsigned regno = NEON_SCALAR_REG (scalar);
13950 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
13951
13952 switch (elsize)
13953 {
13954 case 16:
13955 if (regno > 7 || elno > 3)
13956 goto bad_scalar;
13957 return regno | (elno << 3);
5f4273c7 13958
5287ad62
JB
13959 case 32:
13960 if (regno > 15 || elno > 1)
13961 goto bad_scalar;
13962 return regno | (elno << 4);
13963
13964 default:
13965 bad_scalar:
dcbf9037 13966 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
13967 }
13968
13969 return 0;
13970}
13971
13972/* Encode multiply / multiply-accumulate scalar instructions. */
13973
13974static void
13975neon_mul_mac (struct neon_type_el et, int ubit)
13976{
dcbf9037
JB
13977 unsigned scalar;
13978
13979 /* Give a more helpful error message if we have an invalid type. */
13980 if (et.type == NT_invtype)
13981 return;
5f4273c7 13982
dcbf9037 13983 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
13984 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13985 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13986 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13987 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13988 inst.instruction |= LOW4 (scalar);
13989 inst.instruction |= HI1 (scalar) << 5;
13990 inst.instruction |= (et.type == NT_float) << 8;
13991 inst.instruction |= neon_logbits (et.size) << 20;
13992 inst.instruction |= (ubit != 0) << 24;
13993
88714cb8 13994 neon_dp_fixup (&inst);
5287ad62
JB
13995}
13996
13997static void
13998do_neon_mac_maybe_scalar (void)
13999{
037e8744
JB
14000 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14001 return;
14002
14003 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14004 return;
14005
5287ad62
JB
14006 if (inst.operands[2].isscalar)
14007 {
037e8744 14008 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
14009 struct neon_type_el et = neon_check_type (3, rs,
14010 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 14011 NEON_ENCODE (SCALAR, inst);
037e8744 14012 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14013 }
14014 else
428e3f1f
PB
14015 {
14016 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14017 affected if we specify unsigned args. */
14018 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14019 }
5287ad62
JB
14020}
14021
62f3b8c8
PB
14022static void
14023do_neon_fmac (void)
14024{
14025 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
14026 return;
14027
14028 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14029 return;
14030
14031 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14032}
14033
5287ad62
JB
14034static void
14035do_neon_tst (void)
14036{
037e8744 14037 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14038 struct neon_type_el et = neon_check_type (3, rs,
14039 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 14040 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14041}
14042
14043/* VMUL with 3 registers allows the P8 type. The scalar version supports the
14044 same types as the MAC equivalents. The polynomial type for this instruction
14045 is encoded the same as the integer type. */
14046
14047static void
14048do_neon_mul (void)
14049{
037e8744
JB
14050 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14051 return;
14052
14053 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14054 return;
14055
5287ad62
JB
14056 if (inst.operands[2].isscalar)
14057 do_neon_mac_maybe_scalar ();
14058 else
dcbf9037 14059 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
14060}
14061
14062static void
14063do_neon_qdmulh (void)
14064{
14065 if (inst.operands[2].isscalar)
14066 {
037e8744 14067 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
14068 struct neon_type_el et = neon_check_type (3, rs,
14069 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14070 NEON_ENCODE (SCALAR, inst);
037e8744 14071 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14072 }
14073 else
14074 {
037e8744 14075 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14076 struct neon_type_el et = neon_check_type (3, rs,
14077 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14078 NEON_ENCODE (INTEGER, inst);
5287ad62 14079 /* The U bit (rounding) comes from bit mask. */
037e8744 14080 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14081 }
14082}
14083
14084static void
14085do_neon_fcmp_absolute (void)
14086{
037e8744 14087 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14088 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14089 /* Size field comes from bit mask. */
037e8744 14090 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
14091}
14092
14093static void
14094do_neon_fcmp_absolute_inv (void)
14095{
14096 neon_exchange_operands ();
14097 do_neon_fcmp_absolute ();
14098}
14099
14100static void
14101do_neon_step (void)
14102{
037e8744 14103 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14104 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 14105 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14106}
14107
14108static void
14109do_neon_abs_neg (void)
14110{
037e8744
JB
14111 enum neon_shape rs;
14112 struct neon_type_el et;
5f4273c7 14113
037e8744
JB
14114 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
14115 return;
14116
14117 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14118 return;
14119
14120 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14121 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 14122
5287ad62
JB
14123 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14124 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14125 inst.instruction |= LOW4 (inst.operands[1].reg);
14126 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14127 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14128 inst.instruction |= (et.type == NT_float) << 10;
14129 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14130
88714cb8 14131 neon_dp_fixup (&inst);
5287ad62
JB
14132}
14133
14134static void
14135do_neon_sli (void)
14136{
037e8744 14137 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14138 struct neon_type_el et = neon_check_type (2, rs,
14139 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14140 int imm = inst.operands[2].imm;
14141 constraint (imm < 0 || (unsigned)imm >= et.size,
14142 _("immediate out of range for insert"));
037e8744 14143 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14144}
14145
14146static void
14147do_neon_sri (void)
14148{
037e8744 14149 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14150 struct neon_type_el et = neon_check_type (2, rs,
14151 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14152 int imm = inst.operands[2].imm;
14153 constraint (imm < 1 || (unsigned)imm > et.size,
14154 _("immediate out of range for insert"));
037e8744 14155 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
14156}
14157
14158static void
14159do_neon_qshlu_imm (void)
14160{
037e8744 14161 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14162 struct neon_type_el et = neon_check_type (2, rs,
14163 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14164 int imm = inst.operands[2].imm;
14165 constraint (imm < 0 || (unsigned)imm >= et.size,
14166 _("immediate out of range for shift"));
14167 /* Only encodes the 'U present' variant of the instruction.
14168 In this case, signed types have OP (bit 8) set to 0.
14169 Unsigned types have OP set to 1. */
14170 inst.instruction |= (et.type == NT_unsigned) << 8;
14171 /* The rest of the bits are the same as other immediate shifts. */
037e8744 14172 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14173}
14174
14175static void
14176do_neon_qmovn (void)
14177{
14178 struct neon_type_el et = neon_check_type (2, NS_DQ,
14179 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14180 /* Saturating move where operands can be signed or unsigned, and the
14181 destination has the same signedness. */
88714cb8 14182 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14183 if (et.type == NT_unsigned)
14184 inst.instruction |= 0xc0;
14185 else
14186 inst.instruction |= 0x80;
14187 neon_two_same (0, 1, et.size / 2);
14188}
14189
14190static void
14191do_neon_qmovun (void)
14192{
14193 struct neon_type_el et = neon_check_type (2, NS_DQ,
14194 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14195 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 14196 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14197 neon_two_same (0, 1, et.size / 2);
14198}
14199
14200static void
14201do_neon_rshift_sat_narrow (void)
14202{
14203 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14204 or unsigned. If operands are unsigned, results must also be unsigned. */
14205 struct neon_type_el et = neon_check_type (2, NS_DQI,
14206 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14207 int imm = inst.operands[2].imm;
14208 /* This gets the bounds check, size encoding and immediate bits calculation
14209 right. */
14210 et.size /= 2;
5f4273c7 14211
5287ad62
JB
14212 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14213 VQMOVN.I<size> <Dd>, <Qm>. */
14214 if (imm == 0)
14215 {
14216 inst.operands[2].present = 0;
14217 inst.instruction = N_MNEM_vqmovn;
14218 do_neon_qmovn ();
14219 return;
14220 }
5f4273c7 14221
5287ad62
JB
14222 constraint (imm < 1 || (unsigned)imm > et.size,
14223 _("immediate out of range"));
14224 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14225}
14226
14227static void
14228do_neon_rshift_sat_narrow_u (void)
14229{
14230 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14231 or unsigned. If operands are unsigned, results must also be unsigned. */
14232 struct neon_type_el et = neon_check_type (2, NS_DQI,
14233 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14234 int imm = inst.operands[2].imm;
14235 /* This gets the bounds check, size encoding and immediate bits calculation
14236 right. */
14237 et.size /= 2;
14238
14239 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14240 VQMOVUN.I<size> <Dd>, <Qm>. */
14241 if (imm == 0)
14242 {
14243 inst.operands[2].present = 0;
14244 inst.instruction = N_MNEM_vqmovun;
14245 do_neon_qmovun ();
14246 return;
14247 }
14248
14249 constraint (imm < 1 || (unsigned)imm > et.size,
14250 _("immediate out of range"));
14251 /* FIXME: The manual is kind of unclear about what value U should have in
14252 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
14253 must be 1. */
14254 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
14255}
14256
14257static void
14258do_neon_movn (void)
14259{
14260 struct neon_type_el et = neon_check_type (2, NS_DQ,
14261 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 14262 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14263 neon_two_same (0, 1, et.size / 2);
14264}
14265
14266static void
14267do_neon_rshift_narrow (void)
14268{
14269 struct neon_type_el et = neon_check_type (2, NS_DQI,
14270 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14271 int imm = inst.operands[2].imm;
14272 /* This gets the bounds check, size encoding and immediate bits calculation
14273 right. */
14274 et.size /= 2;
5f4273c7 14275
5287ad62
JB
14276 /* If immediate is zero then we are a pseudo-instruction for
14277 VMOVN.I<size> <Dd>, <Qm> */
14278 if (imm == 0)
14279 {
14280 inst.operands[2].present = 0;
14281 inst.instruction = N_MNEM_vmovn;
14282 do_neon_movn ();
14283 return;
14284 }
5f4273c7 14285
5287ad62
JB
14286 constraint (imm < 1 || (unsigned)imm > et.size,
14287 _("immediate out of range for narrowing operation"));
14288 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
14289}
14290
14291static void
14292do_neon_shll (void)
14293{
14294 /* FIXME: Type checking when lengthening. */
14295 struct neon_type_el et = neon_check_type (2, NS_QDI,
14296 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
14297 unsigned imm = inst.operands[2].imm;
14298
14299 if (imm == et.size)
14300 {
14301 /* Maximum shift variant. */
88714cb8 14302 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14303 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14304 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14305 inst.instruction |= LOW4 (inst.operands[1].reg);
14306 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14307 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14308
88714cb8 14309 neon_dp_fixup (&inst);
5287ad62
JB
14310 }
14311 else
14312 {
14313 /* A more-specific type check for non-max versions. */
14314 et = neon_check_type (2, NS_QDI,
14315 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 14316 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14317 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
14318 }
14319}
14320
037e8744 14321/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
14322 the current instruction is. */
14323
14324static int
14325neon_cvt_flavour (enum neon_shape rs)
14326{
037e8744
JB
14327#define CVT_VAR(C,X,Y) \
14328 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
14329 if (et.type != NT_invtype) \
14330 { \
14331 inst.error = NULL; \
14332 return (C); \
5287ad62
JB
14333 }
14334 struct neon_type_el et;
037e8744
JB
14335 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
14336 || rs == NS_FF) ? N_VFP : 0;
14337 /* The instruction versions which take an immediate take one register
14338 argument, which is extended to the width of the full register. Thus the
14339 "source" and "destination" registers must have the same width. Hack that
14340 here by making the size equal to the key (wider, in this case) operand. */
14341 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 14342
5287ad62
JB
14343 CVT_VAR (0, N_S32, N_F32);
14344 CVT_VAR (1, N_U32, N_F32);
14345 CVT_VAR (2, N_F32, N_S32);
14346 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
14347 /* Half-precision conversions. */
14348 CVT_VAR (4, N_F32, N_F16);
14349 CVT_VAR (5, N_F16, N_F32);
5f4273c7 14350
037e8744 14351 whole_reg = N_VFP;
5f4273c7 14352
037e8744 14353 /* VFP instructions. */
8e79c3df
CM
14354 CVT_VAR (6, N_F32, N_F64);
14355 CVT_VAR (7, N_F64, N_F32);
14356 CVT_VAR (8, N_S32, N_F64 | key);
14357 CVT_VAR (9, N_U32, N_F64 | key);
14358 CVT_VAR (10, N_F64 | key, N_S32);
14359 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 14360 /* VFP instructions with bitshift. */
8e79c3df
CM
14361 CVT_VAR (12, N_F32 | key, N_S16);
14362 CVT_VAR (13, N_F32 | key, N_U16);
14363 CVT_VAR (14, N_F64 | key, N_S16);
14364 CVT_VAR (15, N_F64 | key, N_U16);
14365 CVT_VAR (16, N_S16, N_F32 | key);
14366 CVT_VAR (17, N_U16, N_F32 | key);
14367 CVT_VAR (18, N_S16, N_F64 | key);
14368 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 14369
5287ad62
JB
14370 return -1;
14371#undef CVT_VAR
14372}
14373
037e8744
JB
14374/* Neon-syntax VFP conversions. */
14375
5287ad62 14376static void
037e8744 14377do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 14378{
037e8744 14379 const char *opname = 0;
5f4273c7 14380
037e8744 14381 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 14382 {
037e8744
JB
14383 /* Conversions with immediate bitshift. */
14384 const char *enc[] =
14385 {
14386 "ftosls",
14387 "ftouls",
14388 "fsltos",
14389 "fultos",
14390 NULL,
14391 NULL,
8e79c3df
CM
14392 NULL,
14393 NULL,
037e8744
JB
14394 "ftosld",
14395 "ftould",
14396 "fsltod",
14397 "fultod",
14398 "fshtos",
14399 "fuhtos",
14400 "fshtod",
14401 "fuhtod",
14402 "ftoshs",
14403 "ftouhs",
14404 "ftoshd",
14405 "ftouhd"
14406 };
14407
14408 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14409 {
14410 opname = enc[flavour];
14411 constraint (inst.operands[0].reg != inst.operands[1].reg,
14412 _("operands 0 and 1 must be the same register"));
14413 inst.operands[1] = inst.operands[2];
14414 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
14415 }
5287ad62
JB
14416 }
14417 else
14418 {
037e8744
JB
14419 /* Conversions without bitshift. */
14420 const char *enc[] =
14421 {
14422 "ftosis",
14423 "ftouis",
14424 "fsitos",
14425 "fuitos",
8e79c3df
CM
14426 "NULL",
14427 "NULL",
037e8744
JB
14428 "fcvtsd",
14429 "fcvtds",
14430 "ftosid",
14431 "ftouid",
14432 "fsitod",
14433 "fuitod"
14434 };
14435
14436 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14437 opname = enc[flavour];
14438 }
14439
14440 if (opname)
14441 do_vfp_nsyn_opcode (opname);
14442}
14443
14444static void
14445do_vfp_nsyn_cvtz (void)
14446{
14447 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
14448 int flavour = neon_cvt_flavour (rs);
14449 const char *enc[] =
14450 {
14451 "ftosizs",
14452 "ftouizs",
14453 NULL,
14454 NULL,
14455 NULL,
14456 NULL,
8e79c3df
CM
14457 NULL,
14458 NULL,
037e8744
JB
14459 "ftosizd",
14460 "ftouizd"
14461 };
14462
14463 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
14464 do_vfp_nsyn_opcode (enc[flavour]);
14465}
f31fef98 14466
037e8744 14467static void
e3e535bc 14468do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
037e8744
JB
14469{
14470 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 14471 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
14472 int flavour = neon_cvt_flavour (rs);
14473
e3e535bc
NC
14474 /* PR11109: Handle round-to-zero for VCVT conversions. */
14475 if (round_to_zero
14476 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
14477 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
14478 && (rs == NS_FD || rs == NS_FF))
14479 {
14480 do_vfp_nsyn_cvtz ();
14481 return;
14482 }
14483
037e8744 14484 /* VFP rather than Neon conversions. */
8e79c3df 14485 if (flavour >= 6)
037e8744
JB
14486 {
14487 do_vfp_nsyn_cvt (rs, flavour);
14488 return;
14489 }
14490
14491 switch (rs)
14492 {
14493 case NS_DDI:
14494 case NS_QQI:
14495 {
35997600
NC
14496 unsigned immbits;
14497 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
14498
037e8744
JB
14499 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14500 return;
14501
14502 /* Fixed-point conversion with #0 immediate is encoded as an
14503 integer conversion. */
14504 if (inst.operands[2].present && inst.operands[2].imm == 0)
14505 goto int_encode;
35997600 14506 immbits = 32 - inst.operands[2].imm;
88714cb8 14507 NEON_ENCODE (IMMED, inst);
037e8744
JB
14508 if (flavour != -1)
14509 inst.instruction |= enctab[flavour];
14510 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14511 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14512 inst.instruction |= LOW4 (inst.operands[1].reg);
14513 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14514 inst.instruction |= neon_quad (rs) << 6;
14515 inst.instruction |= 1 << 21;
14516 inst.instruction |= immbits << 16;
14517
88714cb8 14518 neon_dp_fixup (&inst);
037e8744
JB
14519 }
14520 break;
14521
14522 case NS_DD:
14523 case NS_QQ:
14524 int_encode:
14525 {
14526 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
14527
88714cb8 14528 NEON_ENCODE (INTEGER, inst);
037e8744
JB
14529
14530 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14531 return;
14532
14533 if (flavour != -1)
14534 inst.instruction |= enctab[flavour];
14535
14536 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14537 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14538 inst.instruction |= LOW4 (inst.operands[1].reg);
14539 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14540 inst.instruction |= neon_quad (rs) << 6;
14541 inst.instruction |= 2 << 18;
14542
88714cb8 14543 neon_dp_fixup (&inst);
037e8744
JB
14544 }
14545 break;
14546
8e79c3df
CM
14547 /* Half-precision conversions for Advanced SIMD -- neon. */
14548 case NS_QD:
14549 case NS_DQ:
14550
14551 if ((rs == NS_DQ)
14552 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14553 {
14554 as_bad (_("operand size must match register width"));
14555 break;
14556 }
14557
14558 if ((rs == NS_QD)
14559 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14560 {
14561 as_bad (_("operand size must match register width"));
14562 break;
14563 }
14564
14565 if (rs == NS_DQ)
14566 inst.instruction = 0x3b60600;
14567 else
14568 inst.instruction = 0x3b60700;
14569
14570 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14571 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14572 inst.instruction |= LOW4 (inst.operands[1].reg);
14573 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 14574 neon_dp_fixup (&inst);
8e79c3df
CM
14575 break;
14576
037e8744
JB
14577 default:
14578 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
14579 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 14580 }
5287ad62
JB
14581}
14582
e3e535bc
NC
14583static void
14584do_neon_cvtr (void)
14585{
14586 do_neon_cvt_1 (FALSE);
14587}
14588
14589static void
14590do_neon_cvt (void)
14591{
14592 do_neon_cvt_1 (TRUE);
14593}
14594
8e79c3df
CM
14595static void
14596do_neon_cvtb (void)
14597{
14598 inst.instruction = 0xeb20a40;
14599
14600 /* The sizes are attached to the mnemonic. */
14601 if (inst.vectype.el[0].type != NT_invtype
14602 && inst.vectype.el[0].size == 16)
14603 inst.instruction |= 0x00010000;
14604
14605 /* Programmer's syntax: the sizes are attached to the operands. */
14606 else if (inst.operands[0].vectype.type != NT_invtype
14607 && inst.operands[0].vectype.size == 16)
14608 inst.instruction |= 0x00010000;
14609
14610 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14611 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
14612 do_vfp_cond_or_thumb ();
14613}
14614
14615
14616static void
14617do_neon_cvtt (void)
14618{
14619 do_neon_cvtb ();
14620 inst.instruction |= 0x80;
14621}
14622
5287ad62
JB
14623static void
14624neon_move_immediate (void)
14625{
037e8744
JB
14626 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14627 struct neon_type_el et = neon_check_type (2, rs,
14628 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 14629 unsigned immlo, immhi = 0, immbits;
c96612cc 14630 int op, cmode, float_p;
5287ad62 14631
037e8744
JB
14632 constraint (et.type == NT_invtype,
14633 _("operand size must be specified for immediate VMOV"));
14634
5287ad62
JB
14635 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14636 op = (inst.instruction & (1 << 5)) != 0;
14637
14638 immlo = inst.operands[1].imm;
14639 if (inst.operands[1].regisimm)
14640 immhi = inst.operands[1].reg;
14641
14642 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14643 _("immediate has bits set outside the operand size"));
14644
c96612cc
JB
14645 float_p = inst.operands[1].immisfloat;
14646
14647 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 14648 et.size, et.type)) == FAIL)
5287ad62
JB
14649 {
14650 /* Invert relevant bits only. */
14651 neon_invert_size (&immlo, &immhi, et.size);
14652 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14653 with one or the other; those cases are caught by
14654 neon_cmode_for_move_imm. */
14655 op = !op;
c96612cc
JB
14656 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
14657 &op, et.size, et.type)) == FAIL)
5287ad62 14658 {
dcbf9037 14659 first_error (_("immediate out of range"));
5287ad62
JB
14660 return;
14661 }
14662 }
14663
14664 inst.instruction &= ~(1 << 5);
14665 inst.instruction |= op << 5;
14666
14667 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14668 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 14669 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14670 inst.instruction |= cmode << 8;
14671
14672 neon_write_immbits (immbits);
14673}
14674
14675static void
14676do_neon_mvn (void)
14677{
14678 if (inst.operands[1].isreg)
14679 {
037e8744 14680 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 14681
88714cb8 14682 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14683 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14684 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14685 inst.instruction |= LOW4 (inst.operands[1].reg);
14686 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14687 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14688 }
14689 else
14690 {
88714cb8 14691 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14692 neon_move_immediate ();
14693 }
14694
88714cb8 14695 neon_dp_fixup (&inst);
5287ad62
JB
14696}
14697
14698/* Encode instructions of form:
14699
14700 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 14701 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
14702
14703static void
14704neon_mixed_length (struct neon_type_el et, unsigned size)
14705{
14706 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14707 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14708 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14709 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14710 inst.instruction |= LOW4 (inst.operands[2].reg);
14711 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14712 inst.instruction |= (et.type == NT_unsigned) << 24;
14713 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14714
88714cb8 14715 neon_dp_fixup (&inst);
5287ad62
JB
14716}
14717
14718static void
14719do_neon_dyadic_long (void)
14720{
14721 /* FIXME: Type checking for lengthening op. */
14722 struct neon_type_el et = neon_check_type (3, NS_QDD,
14723 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14724 neon_mixed_length (et, et.size);
14725}
14726
14727static void
14728do_neon_abal (void)
14729{
14730 struct neon_type_el et = neon_check_type (3, NS_QDD,
14731 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14732 neon_mixed_length (et, et.size);
14733}
14734
14735static void
14736neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14737{
14738 if (inst.operands[2].isscalar)
14739 {
dcbf9037
JB
14740 struct neon_type_el et = neon_check_type (3, NS_QDS,
14741 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 14742 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14743 neon_mul_mac (et, et.type == NT_unsigned);
14744 }
14745 else
14746 {
14747 struct neon_type_el et = neon_check_type (3, NS_QDD,
14748 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 14749 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14750 neon_mixed_length (et, et.size);
14751 }
14752}
14753
14754static void
14755do_neon_mac_maybe_scalar_long (void)
14756{
14757 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14758}
14759
14760static void
14761do_neon_dyadic_wide (void)
14762{
14763 struct neon_type_el et = neon_check_type (3, NS_QQD,
14764 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14765 neon_mixed_length (et, et.size);
14766}
14767
14768static void
14769do_neon_dyadic_narrow (void)
14770{
14771 struct neon_type_el et = neon_check_type (3, NS_QDD,
14772 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
14773 /* Operand sign is unimportant, and the U bit is part of the opcode,
14774 so force the operand type to integer. */
14775 et.type = NT_integer;
5287ad62
JB
14776 neon_mixed_length (et, et.size / 2);
14777}
14778
14779static void
14780do_neon_mul_sat_scalar_long (void)
14781{
14782 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14783}
14784
14785static void
14786do_neon_vmull (void)
14787{
14788 if (inst.operands[2].isscalar)
14789 do_neon_mac_maybe_scalar_long ();
14790 else
14791 {
14792 struct neon_type_el et = neon_check_type (3, NS_QDD,
14793 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14794 if (et.type == NT_poly)
88714cb8 14795 NEON_ENCODE (POLY, inst);
5287ad62 14796 else
88714cb8 14797 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14798 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14799 zero. Should be OK as-is. */
14800 neon_mixed_length (et, et.size);
14801 }
14802}
14803
14804static void
14805do_neon_ext (void)
14806{
037e8744 14807 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
14808 struct neon_type_el et = neon_check_type (3, rs,
14809 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14810 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
14811
14812 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14813 _("shift out of range"));
5287ad62
JB
14814 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14815 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14816 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14817 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14818 inst.instruction |= LOW4 (inst.operands[2].reg);
14819 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 14820 inst.instruction |= neon_quad (rs) << 6;
5287ad62 14821 inst.instruction |= imm << 8;
5f4273c7 14822
88714cb8 14823 neon_dp_fixup (&inst);
5287ad62
JB
14824}
14825
14826static void
14827do_neon_rev (void)
14828{
037e8744 14829 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14830 struct neon_type_el et = neon_check_type (2, rs,
14831 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14832 unsigned op = (inst.instruction >> 7) & 3;
14833 /* N (width of reversed regions) is encoded as part of the bitmask. We
14834 extract it here to check the elements to be reversed are smaller.
14835 Otherwise we'd get a reserved instruction. */
14836 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 14837 gas_assert (elsize != 0);
5287ad62
JB
14838 constraint (et.size >= elsize,
14839 _("elements must be smaller than reversal region"));
037e8744 14840 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14841}
14842
14843static void
14844do_neon_dup (void)
14845{
14846 if (inst.operands[1].isscalar)
14847 {
037e8744 14848 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
14849 struct neon_type_el et = neon_check_type (2, rs,
14850 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 14851 unsigned sizebits = et.size >> 3;
dcbf9037 14852 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 14853 int logsize = neon_logbits (et.size);
dcbf9037 14854 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
14855
14856 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14857 return;
14858
88714cb8 14859 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14860 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14861 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14862 inst.instruction |= LOW4 (dm);
14863 inst.instruction |= HI1 (dm) << 5;
037e8744 14864 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14865 inst.instruction |= x << 17;
14866 inst.instruction |= sizebits << 16;
5f4273c7 14867
88714cb8 14868 neon_dp_fixup (&inst);
5287ad62
JB
14869 }
14870 else
14871 {
037e8744
JB
14872 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14873 struct neon_type_el et = neon_check_type (2, rs,
14874 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 14875 /* Duplicate ARM register to lanes of vector. */
88714cb8 14876 NEON_ENCODE (ARMREG, inst);
5287ad62
JB
14877 switch (et.size)
14878 {
14879 case 8: inst.instruction |= 0x400000; break;
14880 case 16: inst.instruction |= 0x000020; break;
14881 case 32: inst.instruction |= 0x000000; break;
14882 default: break;
14883 }
14884 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14885 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14886 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 14887 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
14888 /* The encoding for this instruction is identical for the ARM and Thumb
14889 variants, except for the condition field. */
037e8744 14890 do_vfp_cond_or_thumb ();
5287ad62
JB
14891 }
14892}
14893
14894/* VMOV has particularly many variations. It can be one of:
14895 0. VMOV<c><q> <Qd>, <Qm>
14896 1. VMOV<c><q> <Dd>, <Dm>
14897 (Register operations, which are VORR with Rm = Rn.)
14898 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14899 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14900 (Immediate loads.)
14901 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14902 (ARM register to scalar.)
14903 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14904 (Two ARM registers to vector.)
14905 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14906 (Scalar to ARM register.)
14907 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14908 (Vector to two ARM registers.)
037e8744
JB
14909 8. VMOV.F32 <Sd>, <Sm>
14910 9. VMOV.F64 <Dd>, <Dm>
14911 (VFP register moves.)
14912 10. VMOV.F32 <Sd>, #imm
14913 11. VMOV.F64 <Dd>, #imm
14914 (VFP float immediate load.)
14915 12. VMOV <Rd>, <Sm>
14916 (VFP single to ARM reg.)
14917 13. VMOV <Sd>, <Rm>
14918 (ARM reg to VFP single.)
14919 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14920 (Two ARM regs to two VFP singles.)
14921 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14922 (Two VFP singles to two ARM regs.)
5f4273c7 14923
037e8744
JB
14924 These cases can be disambiguated using neon_select_shape, except cases 1/9
14925 and 3/11 which depend on the operand type too.
5f4273c7 14926
5287ad62 14927 All the encoded bits are hardcoded by this function.
5f4273c7 14928
b7fc2769
JB
14929 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14930 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 14931
5287ad62 14932 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 14933 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
14934
14935static void
14936do_neon_mov (void)
14937{
037e8744
JB
14938 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14939 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14940 NS_NULL);
14941 struct neon_type_el et;
14942 const char *ldconst = 0;
5287ad62 14943
037e8744 14944 switch (rs)
5287ad62 14945 {
037e8744
JB
14946 case NS_DD: /* case 1/9. */
14947 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14948 /* It is not an error here if no type is given. */
14949 inst.error = NULL;
14950 if (et.type == NT_float && et.size == 64)
5287ad62 14951 {
037e8744
JB
14952 do_vfp_nsyn_opcode ("fcpyd");
14953 break;
5287ad62 14954 }
037e8744 14955 /* fall through. */
5287ad62 14956
037e8744
JB
14957 case NS_QQ: /* case 0/1. */
14958 {
14959 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14960 return;
14961 /* The architecture manual I have doesn't explicitly state which
14962 value the U bit should have for register->register moves, but
14963 the equivalent VORR instruction has U = 0, so do that. */
14964 inst.instruction = 0x0200110;
14965 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14966 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14967 inst.instruction |= LOW4 (inst.operands[1].reg);
14968 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14969 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14970 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14971 inst.instruction |= neon_quad (rs) << 6;
14972
88714cb8 14973 neon_dp_fixup (&inst);
037e8744
JB
14974 }
14975 break;
5f4273c7 14976
037e8744
JB
14977 case NS_DI: /* case 3/11. */
14978 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14979 inst.error = NULL;
14980 if (et.type == NT_float && et.size == 64)
5287ad62 14981 {
037e8744
JB
14982 /* case 11 (fconstd). */
14983 ldconst = "fconstd";
14984 goto encode_fconstd;
5287ad62 14985 }
037e8744
JB
14986 /* fall through. */
14987
14988 case NS_QI: /* case 2/3. */
14989 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14990 return;
14991 inst.instruction = 0x0800010;
14992 neon_move_immediate ();
88714cb8 14993 neon_dp_fixup (&inst);
5287ad62 14994 break;
5f4273c7 14995
037e8744
JB
14996 case NS_SR: /* case 4. */
14997 {
14998 unsigned bcdebits = 0;
91d6fa6a 14999 int logsize;
037e8744
JB
15000 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
15001 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
15002
91d6fa6a
NC
15003 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
15004 logsize = neon_logbits (et.size);
15005
037e8744
JB
15006 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15007 _(BAD_FPU));
15008 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15009 && et.size != 32, _(BAD_FPU));
15010 constraint (et.type == NT_invtype, _("bad type for scalar"));
15011 constraint (x >= 64 / et.size, _("scalar index out of range"));
15012
15013 switch (et.size)
15014 {
15015 case 8: bcdebits = 0x8; break;
15016 case 16: bcdebits = 0x1; break;
15017 case 32: bcdebits = 0x0; break;
15018 default: ;
15019 }
15020
15021 bcdebits |= x << logsize;
15022
15023 inst.instruction = 0xe000b10;
15024 do_vfp_cond_or_thumb ();
15025 inst.instruction |= LOW4 (dn) << 16;
15026 inst.instruction |= HI1 (dn) << 7;
15027 inst.instruction |= inst.operands[1].reg << 12;
15028 inst.instruction |= (bcdebits & 3) << 5;
15029 inst.instruction |= (bcdebits >> 2) << 21;
15030 }
15031 break;
5f4273c7 15032
037e8744 15033 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 15034 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 15035 _(BAD_FPU));
b7fc2769 15036
037e8744
JB
15037 inst.instruction = 0xc400b10;
15038 do_vfp_cond_or_thumb ();
15039 inst.instruction |= LOW4 (inst.operands[0].reg);
15040 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
15041 inst.instruction |= inst.operands[1].reg << 12;
15042 inst.instruction |= inst.operands[2].reg << 16;
15043 break;
5f4273c7 15044
037e8744
JB
15045 case NS_RS: /* case 6. */
15046 {
91d6fa6a 15047 unsigned logsize;
037e8744
JB
15048 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
15049 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
15050 unsigned abcdebits = 0;
15051
91d6fa6a
NC
15052 et = neon_check_type (2, NS_NULL,
15053 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
15054 logsize = neon_logbits (et.size);
15055
037e8744
JB
15056 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15057 _(BAD_FPU));
15058 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15059 && et.size != 32, _(BAD_FPU));
15060 constraint (et.type == NT_invtype, _("bad type for scalar"));
15061 constraint (x >= 64 / et.size, _("scalar index out of range"));
15062
15063 switch (et.size)
15064 {
15065 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
15066 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
15067 case 32: abcdebits = 0x00; break;
15068 default: ;
15069 }
15070
15071 abcdebits |= x << logsize;
15072 inst.instruction = 0xe100b10;
15073 do_vfp_cond_or_thumb ();
15074 inst.instruction |= LOW4 (dn) << 16;
15075 inst.instruction |= HI1 (dn) << 7;
15076 inst.instruction |= inst.operands[0].reg << 12;
15077 inst.instruction |= (abcdebits & 3) << 5;
15078 inst.instruction |= (abcdebits >> 2) << 21;
15079 }
15080 break;
5f4273c7 15081
037e8744
JB
15082 case NS_RRD: /* case 7 (fmrrd). */
15083 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
15084 _(BAD_FPU));
15085
15086 inst.instruction = 0xc500b10;
15087 do_vfp_cond_or_thumb ();
15088 inst.instruction |= inst.operands[0].reg << 12;
15089 inst.instruction |= inst.operands[1].reg << 16;
15090 inst.instruction |= LOW4 (inst.operands[2].reg);
15091 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15092 break;
5f4273c7 15093
037e8744
JB
15094 case NS_FF: /* case 8 (fcpys). */
15095 do_vfp_nsyn_opcode ("fcpys");
15096 break;
5f4273c7 15097
037e8744
JB
15098 case NS_FI: /* case 10 (fconsts). */
15099 ldconst = "fconsts";
15100 encode_fconstd:
15101 if (is_quarter_float (inst.operands[1].imm))
5287ad62 15102 {
037e8744
JB
15103 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
15104 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
15105 }
15106 else
037e8744
JB
15107 first_error (_("immediate out of range"));
15108 break;
5f4273c7 15109
037e8744
JB
15110 case NS_RF: /* case 12 (fmrs). */
15111 do_vfp_nsyn_opcode ("fmrs");
15112 break;
5f4273c7 15113
037e8744
JB
15114 case NS_FR: /* case 13 (fmsr). */
15115 do_vfp_nsyn_opcode ("fmsr");
15116 break;
5f4273c7 15117
037e8744
JB
15118 /* The encoders for the fmrrs and fmsrr instructions expect three operands
15119 (one of which is a list), but we have parsed four. Do some fiddling to
15120 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
15121 expect. */
15122 case NS_RRFF: /* case 14 (fmrrs). */
15123 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
15124 _("VFP registers must be adjacent"));
15125 inst.operands[2].imm = 2;
15126 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15127 do_vfp_nsyn_opcode ("fmrrs");
15128 break;
5f4273c7 15129
037e8744
JB
15130 case NS_FFRR: /* case 15 (fmsrr). */
15131 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
15132 _("VFP registers must be adjacent"));
15133 inst.operands[1] = inst.operands[2];
15134 inst.operands[2] = inst.operands[3];
15135 inst.operands[0].imm = 2;
15136 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15137 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 15138 break;
5f4273c7 15139
5287ad62
JB
15140 default:
15141 abort ();
15142 }
15143}
15144
15145static void
15146do_neon_rshift_round_imm (void)
15147{
037e8744 15148 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15149 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
15150 int imm = inst.operands[2].imm;
15151
15152 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
15153 if (imm == 0)
15154 {
15155 inst.operands[2].present = 0;
15156 do_neon_mov ();
15157 return;
15158 }
15159
15160 constraint (imm < 1 || (unsigned)imm > et.size,
15161 _("immediate out of range for shift"));
037e8744 15162 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
15163 et.size - imm);
15164}
15165
15166static void
15167do_neon_movl (void)
15168{
15169 struct neon_type_el et = neon_check_type (2, NS_QD,
15170 N_EQK | N_DBL, N_SU_32 | N_KEY);
15171 unsigned sizebits = et.size >> 3;
15172 inst.instruction |= sizebits << 19;
15173 neon_two_same (0, et.type == NT_unsigned, -1);
15174}
15175
15176static void
15177do_neon_trn (void)
15178{
037e8744 15179 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15180 struct neon_type_el et = neon_check_type (2, rs,
15181 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 15182 NEON_ENCODE (INTEGER, inst);
037e8744 15183 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15184}
15185
15186static void
15187do_neon_zip_uzp (void)
15188{
037e8744 15189 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15190 struct neon_type_el et = neon_check_type (2, rs,
15191 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15192 if (rs == NS_DD && et.size == 32)
15193 {
15194 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
15195 inst.instruction = N_MNEM_vtrn;
15196 do_neon_trn ();
15197 return;
15198 }
037e8744 15199 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15200}
15201
15202static void
15203do_neon_sat_abs_neg (void)
15204{
037e8744 15205 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15206 struct neon_type_el et = neon_check_type (2, rs,
15207 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 15208 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15209}
15210
15211static void
15212do_neon_pair_long (void)
15213{
037e8744 15214 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15215 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
15216 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
15217 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 15218 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15219}
15220
15221static void
15222do_neon_recip_est (void)
15223{
037e8744 15224 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15225 struct neon_type_el et = neon_check_type (2, rs,
15226 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
15227 inst.instruction |= (et.type == NT_float) << 8;
037e8744 15228 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15229}
15230
15231static void
15232do_neon_cls (void)
15233{
037e8744 15234 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15235 struct neon_type_el et = neon_check_type (2, rs,
15236 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 15237 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15238}
15239
15240static void
15241do_neon_clz (void)
15242{
037e8744 15243 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15244 struct neon_type_el et = neon_check_type (2, rs,
15245 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 15246 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15247}
15248
15249static void
15250do_neon_cnt (void)
15251{
037e8744 15252 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15253 struct neon_type_el et = neon_check_type (2, rs,
15254 N_EQK | N_INT, N_8 | N_KEY);
037e8744 15255 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15256}
15257
15258static void
15259do_neon_swp (void)
15260{
037e8744
JB
15261 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15262 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
15263}
15264
15265static void
15266do_neon_tbl_tbx (void)
15267{
15268 unsigned listlenbits;
dcbf9037 15269 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 15270
5287ad62
JB
15271 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
15272 {
dcbf9037 15273 first_error (_("bad list length for table lookup"));
5287ad62
JB
15274 return;
15275 }
5f4273c7 15276
5287ad62
JB
15277 listlenbits = inst.operands[1].imm - 1;
15278 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15279 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15280 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15281 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15282 inst.instruction |= LOW4 (inst.operands[2].reg);
15283 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15284 inst.instruction |= listlenbits << 8;
5f4273c7 15285
88714cb8 15286 neon_dp_fixup (&inst);
5287ad62
JB
15287}
15288
15289static void
15290do_neon_ldm_stm (void)
15291{
15292 /* P, U and L bits are part of bitmask. */
15293 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
15294 unsigned offsetbits = inst.operands[1].imm * 2;
15295
037e8744
JB
15296 if (inst.operands[1].issingle)
15297 {
15298 do_vfp_nsyn_ldm_stm (is_dbmode);
15299 return;
15300 }
15301
5287ad62
JB
15302 constraint (is_dbmode && !inst.operands[0].writeback,
15303 _("writeback (!) must be used for VLDMDB and VSTMDB"));
15304
15305 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15306 _("register list must contain at least 1 and at most 16 "
15307 "registers"));
15308
15309 inst.instruction |= inst.operands[0].reg << 16;
15310 inst.instruction |= inst.operands[0].writeback << 21;
15311 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15312 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
15313
15314 inst.instruction |= offsetbits;
5f4273c7 15315
037e8744 15316 do_vfp_cond_or_thumb ();
5287ad62
JB
15317}
15318
15319static void
15320do_neon_ldr_str (void)
15321{
5287ad62 15322 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 15323
6844b2c2
MGD
15324 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
15325 And is UNPREDICTABLE in thumb mode. */
fa94de6b 15326 if (!is_ldr
6844b2c2
MGD
15327 && inst.operands[1].reg == REG_PC
15328 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
15329 {
15330 if (!thumb_mode && warn_on_deprecated)
15331 as_warn (_("Use of PC here is deprecated"));
15332 else
15333 inst.error = _("Use of PC here is UNPREDICTABLE");
15334 }
15335
037e8744
JB
15336 if (inst.operands[0].issingle)
15337 {
cd2f129f
JB
15338 if (is_ldr)
15339 do_vfp_nsyn_opcode ("flds");
15340 else
15341 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
15342 }
15343 else
5287ad62 15344 {
cd2f129f
JB
15345 if (is_ldr)
15346 do_vfp_nsyn_opcode ("fldd");
5287ad62 15347 else
cd2f129f 15348 do_vfp_nsyn_opcode ("fstd");
5287ad62 15349 }
5287ad62
JB
15350}
15351
15352/* "interleave" version also handles non-interleaving register VLD1/VST1
15353 instructions. */
15354
15355static void
15356do_neon_ld_st_interleave (void)
15357{
037e8744 15358 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
15359 N_8 | N_16 | N_32 | N_64);
15360 unsigned alignbits = 0;
15361 unsigned idx;
15362 /* The bits in this table go:
15363 0: register stride of one (0) or two (1)
15364 1,2: register list length, minus one (1, 2, 3, 4).
15365 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
15366 We use -1 for invalid entries. */
15367 const int typetable[] =
15368 {
15369 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
15370 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
15371 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
15372 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
15373 };
15374 int typebits;
15375
dcbf9037
JB
15376 if (et.type == NT_invtype)
15377 return;
15378
5287ad62
JB
15379 if (inst.operands[1].immisalign)
15380 switch (inst.operands[1].imm >> 8)
15381 {
15382 case 64: alignbits = 1; break;
15383 case 128:
e23c0ad8
JZ
15384 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
15385 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
15386 goto bad_alignment;
15387 alignbits = 2;
15388 break;
15389 case 256:
e23c0ad8 15390 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
15391 goto bad_alignment;
15392 alignbits = 3;
15393 break;
15394 default:
15395 bad_alignment:
dcbf9037 15396 first_error (_("bad alignment"));
5287ad62
JB
15397 return;
15398 }
15399
15400 inst.instruction |= alignbits << 4;
15401 inst.instruction |= neon_logbits (et.size) << 6;
15402
15403 /* Bits [4:6] of the immediate in a list specifier encode register stride
15404 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
15405 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
15406 up the right value for "type" in a table based on this value and the given
15407 list style, then stick it back. */
15408 idx = ((inst.operands[0].imm >> 4) & 7)
15409 | (((inst.instruction >> 8) & 3) << 3);
15410
15411 typebits = typetable[idx];
5f4273c7 15412
5287ad62
JB
15413 constraint (typebits == -1, _("bad list type for instruction"));
15414
15415 inst.instruction &= ~0xf00;
15416 inst.instruction |= typebits << 8;
15417}
15418
15419/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
15420 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
15421 otherwise. The variable arguments are a list of pairs of legal (size, align)
15422 values, terminated with -1. */
15423
15424static int
15425neon_alignment_bit (int size, int align, int *do_align, ...)
15426{
15427 va_list ap;
15428 int result = FAIL, thissize, thisalign;
5f4273c7 15429
5287ad62
JB
15430 if (!inst.operands[1].immisalign)
15431 {
15432 *do_align = 0;
15433 return SUCCESS;
15434 }
5f4273c7 15435
5287ad62
JB
15436 va_start (ap, do_align);
15437
15438 do
15439 {
15440 thissize = va_arg (ap, int);
15441 if (thissize == -1)
15442 break;
15443 thisalign = va_arg (ap, int);
15444
15445 if (size == thissize && align == thisalign)
15446 result = SUCCESS;
15447 }
15448 while (result != SUCCESS);
15449
15450 va_end (ap);
15451
15452 if (result == SUCCESS)
15453 *do_align = 1;
15454 else
dcbf9037 15455 first_error (_("unsupported alignment for instruction"));
5f4273c7 15456
5287ad62
JB
15457 return result;
15458}
15459
15460static void
15461do_neon_ld_st_lane (void)
15462{
037e8744 15463 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15464 int align_good, do_align = 0;
15465 int logsize = neon_logbits (et.size);
15466 int align = inst.operands[1].imm >> 8;
15467 int n = (inst.instruction >> 8) & 3;
15468 int max_el = 64 / et.size;
5f4273c7 15469
dcbf9037
JB
15470 if (et.type == NT_invtype)
15471 return;
5f4273c7 15472
5287ad62
JB
15473 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
15474 _("bad list length"));
15475 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
15476 _("scalar index out of range"));
15477 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
15478 && et.size == 8,
15479 _("stride of 2 unavailable when element size is 8"));
5f4273c7 15480
5287ad62
JB
15481 switch (n)
15482 {
15483 case 0: /* VLD1 / VST1. */
15484 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
15485 32, 32, -1);
15486 if (align_good == FAIL)
15487 return;
15488 if (do_align)
15489 {
15490 unsigned alignbits = 0;
15491 switch (et.size)
15492 {
15493 case 16: alignbits = 0x1; break;
15494 case 32: alignbits = 0x3; break;
15495 default: ;
15496 }
15497 inst.instruction |= alignbits << 4;
15498 }
15499 break;
15500
15501 case 1: /* VLD2 / VST2. */
15502 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
15503 32, 64, -1);
15504 if (align_good == FAIL)
15505 return;
15506 if (do_align)
15507 inst.instruction |= 1 << 4;
15508 break;
15509
15510 case 2: /* VLD3 / VST3. */
15511 constraint (inst.operands[1].immisalign,
15512 _("can't use alignment with this instruction"));
15513 break;
15514
15515 case 3: /* VLD4 / VST4. */
15516 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15517 16, 64, 32, 64, 32, 128, -1);
15518 if (align_good == FAIL)
15519 return;
15520 if (do_align)
15521 {
15522 unsigned alignbits = 0;
15523 switch (et.size)
15524 {
15525 case 8: alignbits = 0x1; break;
15526 case 16: alignbits = 0x1; break;
15527 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
15528 default: ;
15529 }
15530 inst.instruction |= alignbits << 4;
15531 }
15532 break;
15533
15534 default: ;
15535 }
15536
15537 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
15538 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15539 inst.instruction |= 1 << (4 + logsize);
5f4273c7 15540
5287ad62
JB
15541 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
15542 inst.instruction |= logsize << 10;
15543}
15544
15545/* Encode single n-element structure to all lanes VLD<n> instructions. */
15546
15547static void
15548do_neon_ld_dup (void)
15549{
037e8744 15550 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15551 int align_good, do_align = 0;
15552
dcbf9037
JB
15553 if (et.type == NT_invtype)
15554 return;
15555
5287ad62
JB
15556 switch ((inst.instruction >> 8) & 3)
15557 {
15558 case 0: /* VLD1. */
9c2799c2 15559 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
15560 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15561 &do_align, 16, 16, 32, 32, -1);
15562 if (align_good == FAIL)
15563 return;
15564 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15565 {
15566 case 1: break;
15567 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 15568 default: first_error (_("bad list length")); return;
5287ad62
JB
15569 }
15570 inst.instruction |= neon_logbits (et.size) << 6;
15571 break;
15572
15573 case 1: /* VLD2. */
15574 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15575 &do_align, 8, 16, 16, 32, 32, 64, -1);
15576 if (align_good == FAIL)
15577 return;
15578 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15579 _("bad list length"));
15580 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15581 inst.instruction |= 1 << 5;
15582 inst.instruction |= neon_logbits (et.size) << 6;
15583 break;
15584
15585 case 2: /* VLD3. */
15586 constraint (inst.operands[1].immisalign,
15587 _("can't use alignment with this instruction"));
15588 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15589 _("bad list length"));
15590 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15591 inst.instruction |= 1 << 5;
15592 inst.instruction |= neon_logbits (et.size) << 6;
15593 break;
15594
15595 case 3: /* VLD4. */
15596 {
15597 int align = inst.operands[1].imm >> 8;
15598 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15599 16, 64, 32, 64, 32, 128, -1);
15600 if (align_good == FAIL)
15601 return;
15602 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15603 _("bad list length"));
15604 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15605 inst.instruction |= 1 << 5;
15606 if (et.size == 32 && align == 128)
15607 inst.instruction |= 0x3 << 6;
15608 else
15609 inst.instruction |= neon_logbits (et.size) << 6;
15610 }
15611 break;
15612
15613 default: ;
15614 }
15615
15616 inst.instruction |= do_align << 4;
15617}
15618
15619/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15620 apart from bits [11:4]. */
15621
15622static void
15623do_neon_ldx_stx (void)
15624{
b1a769ed
DG
15625 if (inst.operands[1].isreg)
15626 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15627
5287ad62
JB
15628 switch (NEON_LANE (inst.operands[0].imm))
15629 {
15630 case NEON_INTERLEAVE_LANES:
88714cb8 15631 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
15632 do_neon_ld_st_interleave ();
15633 break;
5f4273c7 15634
5287ad62 15635 case NEON_ALL_LANES:
88714cb8 15636 NEON_ENCODE (DUP, inst);
5287ad62
JB
15637 do_neon_ld_dup ();
15638 break;
5f4273c7 15639
5287ad62 15640 default:
88714cb8 15641 NEON_ENCODE (LANE, inst);
5287ad62
JB
15642 do_neon_ld_st_lane ();
15643 }
15644
15645 /* L bit comes from bit mask. */
15646 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15647 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15648 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 15649
5287ad62
JB
15650 if (inst.operands[1].postind)
15651 {
15652 int postreg = inst.operands[1].imm & 0xf;
15653 constraint (!inst.operands[1].immisreg,
15654 _("post-index must be a register"));
15655 constraint (postreg == 0xd || postreg == 0xf,
15656 _("bad register for post-index"));
15657 inst.instruction |= postreg;
15658 }
15659 else if (inst.operands[1].writeback)
15660 {
15661 inst.instruction |= 0xd;
15662 }
15663 else
5f4273c7
NC
15664 inst.instruction |= 0xf;
15665
5287ad62
JB
15666 if (thumb_mode)
15667 inst.instruction |= 0xf9000000;
15668 else
15669 inst.instruction |= 0xf4000000;
15670}
5287ad62
JB
15671\f
15672/* Overall per-instruction processing. */
15673
15674/* We need to be able to fix up arbitrary expressions in some statements.
15675 This is so that we can handle symbols that are an arbitrary distance from
15676 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
15677 which returns part of an address in a form which will be valid for
15678 a data instruction. We do this by pushing the expression into a symbol
15679 in the expr_section, and creating a fix for that. */
15680
15681static void
15682fix_new_arm (fragS * frag,
15683 int where,
15684 short int size,
15685 expressionS * exp,
15686 int pc_rel,
15687 int reloc)
15688{
15689 fixS * new_fix;
15690
15691 switch (exp->X_op)
15692 {
15693 case O_constant:
6e7ce2cd
PB
15694 if (pc_rel)
15695 {
15696 /* Create an absolute valued symbol, so we have something to
15697 refer to in the object file. Unfortunately for us, gas's
15698 generic expression parsing will already have folded out
15699 any use of .set foo/.type foo %function that may have
15700 been used to set type information of the target location,
15701 that's being specified symbolically. We have to presume
15702 the user knows what they are doing. */
15703 char name[16 + 8];
15704 symbolS *symbol;
15705
15706 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
15707
15708 symbol = symbol_find_or_make (name);
15709 S_SET_SEGMENT (symbol, absolute_section);
15710 symbol_set_frag (symbol, &zero_address_frag);
15711 S_SET_VALUE (symbol, exp->X_add_number);
15712 exp->X_op = O_symbol;
15713 exp->X_add_symbol = symbol;
15714 exp->X_add_number = 0;
15715 }
15716 /* FALLTHROUGH */
5287ad62
JB
15717 case O_symbol:
15718 case O_add:
15719 case O_subtract:
21d799b5
NC
15720 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
15721 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15722 break;
15723
15724 default:
21d799b5
NC
15725 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
15726 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15727 break;
15728 }
15729
15730 /* Mark whether the fix is to a THUMB instruction, or an ARM
15731 instruction. */
15732 new_fix->tc_fix_data = thumb_mode;
15733}
15734
15735/* Create a frg for an instruction requiring relaxation. */
15736static void
15737output_relax_insn (void)
15738{
15739 char * to;
15740 symbolS *sym;
0110f2b8
PB
15741 int offset;
15742
6e1cb1a6
PB
15743 /* The size of the instruction is unknown, so tie the debug info to the
15744 start of the instruction. */
15745 dwarf2_emit_insn (0);
6e1cb1a6 15746
0110f2b8
PB
15747 switch (inst.reloc.exp.X_op)
15748 {
15749 case O_symbol:
15750 sym = inst.reloc.exp.X_add_symbol;
15751 offset = inst.reloc.exp.X_add_number;
15752 break;
15753 case O_constant:
15754 sym = NULL;
15755 offset = inst.reloc.exp.X_add_number;
15756 break;
15757 default:
15758 sym = make_expr_symbol (&inst.reloc.exp);
15759 offset = 0;
15760 break;
15761 }
15762 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15763 inst.relax, sym, offset, NULL/*offset, opcode*/);
15764 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
15765}
15766
15767/* Write a 32-bit thumb instruction to buf. */
15768static void
15769put_thumb32_insn (char * buf, unsigned long insn)
15770{
15771 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15772 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15773}
15774
b99bd4ef 15775static void
c19d1205 15776output_inst (const char * str)
b99bd4ef 15777{
c19d1205 15778 char * to = NULL;
b99bd4ef 15779
c19d1205 15780 if (inst.error)
b99bd4ef 15781 {
c19d1205 15782 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
15783 return;
15784 }
5f4273c7
NC
15785 if (inst.relax)
15786 {
15787 output_relax_insn ();
0110f2b8 15788 return;
5f4273c7 15789 }
c19d1205
ZW
15790 if (inst.size == 0)
15791 return;
b99bd4ef 15792
c19d1205 15793 to = frag_more (inst.size);
8dc2430f
NC
15794 /* PR 9814: Record the thumb mode into the current frag so that we know
15795 what type of NOP padding to use, if necessary. We override any previous
15796 setting so that if the mode has changed then the NOPS that we use will
15797 match the encoding of the last instruction in the frag. */
cd000bff 15798 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
15799
15800 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 15801 {
9c2799c2 15802 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 15803 put_thumb32_insn (to, inst.instruction);
b99bd4ef 15804 }
c19d1205 15805 else if (inst.size > INSN_SIZE)
b99bd4ef 15806 {
9c2799c2 15807 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
15808 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15809 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 15810 }
c19d1205
ZW
15811 else
15812 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 15813
c19d1205
ZW
15814 if (inst.reloc.type != BFD_RELOC_UNUSED)
15815 fix_new_arm (frag_now, to - frag_now->fr_literal,
15816 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15817 inst.reloc.type);
b99bd4ef 15818
c19d1205 15819 dwarf2_emit_insn (inst.size);
c19d1205 15820}
b99bd4ef 15821
e07e6e58
NC
15822static char *
15823output_it_inst (int cond, int mask, char * to)
15824{
15825 unsigned long instruction = 0xbf00;
15826
15827 mask &= 0xf;
15828 instruction |= mask;
15829 instruction |= cond << 4;
15830
15831 if (to == NULL)
15832 {
15833 to = frag_more (2);
15834#ifdef OBJ_ELF
15835 dwarf2_emit_insn (2);
15836#endif
15837 }
15838
15839 md_number_to_chars (to, instruction, 2);
15840
15841 return to;
15842}
15843
c19d1205
ZW
15844/* Tag values used in struct asm_opcode's tag field. */
15845enum opcode_tag
15846{
15847 OT_unconditional, /* Instruction cannot be conditionalized.
15848 The ARM condition field is still 0xE. */
15849 OT_unconditionalF, /* Instruction cannot be conditionalized
15850 and carries 0xF in its ARM condition field. */
15851 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
15852 OT_csuffixF, /* Some forms of the instruction take a conditional
15853 suffix, others place 0xF where the condition field
15854 would be. */
c19d1205
ZW
15855 OT_cinfix3, /* Instruction takes a conditional infix,
15856 beginning at character index 3. (In
15857 unified mode, it becomes a suffix.) */
088fa78e
KH
15858 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15859 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
15860 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15861 character index 3, even in unified mode. Used for
15862 legacy instructions where suffix and infix forms
15863 may be ambiguous. */
c19d1205 15864 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 15865 suffix or an infix at character index 3. */
c19d1205
ZW
15866 OT_odd_infix_unc, /* This is the unconditional variant of an
15867 instruction that takes a conditional infix
15868 at an unusual position. In unified mode,
15869 this variant will accept a suffix. */
15870 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15871 are the conditional variants of instructions that
15872 take conditional infixes in unusual positions.
15873 The infix appears at character index
15874 (tag - OT_odd_infix_0). These are not accepted
15875 in unified mode. */
15876};
b99bd4ef 15877
c19d1205
ZW
15878/* Subroutine of md_assemble, responsible for looking up the primary
15879 opcode from the mnemonic the user wrote. STR points to the
15880 beginning of the mnemonic.
15881
15882 This is not simply a hash table lookup, because of conditional
15883 variants. Most instructions have conditional variants, which are
15884 expressed with a _conditional affix_ to the mnemonic. If we were
15885 to encode each conditional variant as a literal string in the opcode
15886 table, it would have approximately 20,000 entries.
15887
15888 Most mnemonics take this affix as a suffix, and in unified syntax,
15889 'most' is upgraded to 'all'. However, in the divided syntax, some
15890 instructions take the affix as an infix, notably the s-variants of
15891 the arithmetic instructions. Of those instructions, all but six
15892 have the infix appear after the third character of the mnemonic.
15893
15894 Accordingly, the algorithm for looking up primary opcodes given
15895 an identifier is:
15896
15897 1. Look up the identifier in the opcode table.
15898 If we find a match, go to step U.
15899
15900 2. Look up the last two characters of the identifier in the
15901 conditions table. If we find a match, look up the first N-2
15902 characters of the identifier in the opcode table. If we
15903 find a match, go to step CE.
15904
15905 3. Look up the fourth and fifth characters of the identifier in
15906 the conditions table. If we find a match, extract those
15907 characters from the identifier, and look up the remaining
15908 characters in the opcode table. If we find a match, go
15909 to step CM.
15910
15911 4. Fail.
15912
15913 U. Examine the tag field of the opcode structure, in case this is
15914 one of the six instructions with its conditional infix in an
15915 unusual place. If it is, the tag tells us where to find the
15916 infix; look it up in the conditions table and set inst.cond
15917 accordingly. Otherwise, this is an unconditional instruction.
15918 Again set inst.cond accordingly. Return the opcode structure.
15919
15920 CE. Examine the tag field to make sure this is an instruction that
15921 should receive a conditional suffix. If it is not, fail.
15922 Otherwise, set inst.cond from the suffix we already looked up,
15923 and return the opcode structure.
15924
15925 CM. Examine the tag field to make sure this is an instruction that
15926 should receive a conditional infix after the third character.
15927 If it is not, fail. Otherwise, undo the edits to the current
15928 line of input and proceed as for case CE. */
15929
15930static const struct asm_opcode *
15931opcode_lookup (char **str)
15932{
15933 char *end, *base;
15934 char *affix;
15935 const struct asm_opcode *opcode;
15936 const struct asm_cond *cond;
e3cb604e 15937 char save[2];
c19d1205
ZW
15938
15939 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 15940 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 15941 for (base = end = *str; *end != '\0'; end++)
721a8186 15942 if (*end == ' ' || *end == '.')
c19d1205 15943 break;
b99bd4ef 15944
c19d1205 15945 if (end == base)
c921be7d 15946 return NULL;
b99bd4ef 15947
5287ad62 15948 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 15949 if (end[0] == '.')
b99bd4ef 15950 {
5287ad62 15951 int offset = 2;
5f4273c7 15952
267d2029
JB
15953 /* The .w and .n suffixes are only valid if the unified syntax is in
15954 use. */
15955 if (unified_syntax && end[1] == 'w')
c19d1205 15956 inst.size_req = 4;
267d2029 15957 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
15958 inst.size_req = 2;
15959 else
5287ad62
JB
15960 offset = 0;
15961
15962 inst.vectype.elems = 0;
15963
15964 *str = end + offset;
b99bd4ef 15965
5f4273c7 15966 if (end[offset] == '.')
5287ad62 15967 {
267d2029
JB
15968 /* See if we have a Neon type suffix (possible in either unified or
15969 non-unified ARM syntax mode). */
dcbf9037 15970 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 15971 return NULL;
5287ad62
JB
15972 }
15973 else if (end[offset] != '\0' && end[offset] != ' ')
c921be7d 15974 return NULL;
b99bd4ef 15975 }
c19d1205
ZW
15976 else
15977 *str = end;
b99bd4ef 15978
c19d1205 15979 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5
NC
15980 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15981 end - base);
c19d1205 15982 if (opcode)
b99bd4ef 15983 {
c19d1205
ZW
15984 /* step U */
15985 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 15986 {
c19d1205
ZW
15987 inst.cond = COND_ALWAYS;
15988 return opcode;
b99bd4ef 15989 }
b99bd4ef 15990
278df34e 15991 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
15992 as_warn (_("conditional infixes are deprecated in unified syntax"));
15993 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 15994 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 15995 gas_assert (cond);
b99bd4ef 15996
c19d1205
ZW
15997 inst.cond = cond->value;
15998 return opcode;
15999 }
b99bd4ef 16000
c19d1205
ZW
16001 /* Cannot have a conditional suffix on a mnemonic of less than two
16002 characters. */
16003 if (end - base < 3)
c921be7d 16004 return NULL;
b99bd4ef 16005
c19d1205
ZW
16006 /* Look for suffixed mnemonic. */
16007 affix = end - 2;
21d799b5
NC
16008 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
16009 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16010 affix - base);
c19d1205
ZW
16011 if (opcode && cond)
16012 {
16013 /* step CE */
16014 switch (opcode->tag)
16015 {
e3cb604e
PB
16016 case OT_cinfix3_legacy:
16017 /* Ignore conditional suffixes matched on infix only mnemonics. */
16018 break;
16019
c19d1205 16020 case OT_cinfix3:
088fa78e 16021 case OT_cinfix3_deprecated:
c19d1205
ZW
16022 case OT_odd_infix_unc:
16023 if (!unified_syntax)
e3cb604e 16024 return 0;
c19d1205
ZW
16025 /* else fall through */
16026
16027 case OT_csuffix:
037e8744 16028 case OT_csuffixF:
c19d1205
ZW
16029 case OT_csuf_or_in3:
16030 inst.cond = cond->value;
16031 return opcode;
16032
16033 case OT_unconditional:
16034 case OT_unconditionalF:
dfa9f0d5 16035 if (thumb_mode)
c921be7d 16036 inst.cond = cond->value;
dfa9f0d5
PB
16037 else
16038 {
c921be7d 16039 /* Delayed diagnostic. */
dfa9f0d5
PB
16040 inst.error = BAD_COND;
16041 inst.cond = COND_ALWAYS;
16042 }
c19d1205 16043 return opcode;
b99bd4ef 16044
c19d1205 16045 default:
c921be7d 16046 return NULL;
c19d1205
ZW
16047 }
16048 }
b99bd4ef 16049
c19d1205
ZW
16050 /* Cannot have a usual-position infix on a mnemonic of less than
16051 six characters (five would be a suffix). */
16052 if (end - base < 6)
c921be7d 16053 return NULL;
b99bd4ef 16054
c19d1205
ZW
16055 /* Look for infixed mnemonic in the usual position. */
16056 affix = base + 3;
21d799b5 16057 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 16058 if (!cond)
c921be7d 16059 return NULL;
e3cb604e
PB
16060
16061 memcpy (save, affix, 2);
16062 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5
NC
16063 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16064 (end - base) - 2);
e3cb604e
PB
16065 memmove (affix + 2, affix, (end - affix) - 2);
16066 memcpy (affix, save, 2);
16067
088fa78e
KH
16068 if (opcode
16069 && (opcode->tag == OT_cinfix3
16070 || opcode->tag == OT_cinfix3_deprecated
16071 || opcode->tag == OT_csuf_or_in3
16072 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 16073 {
c921be7d 16074 /* Step CM. */
278df34e 16075 if (warn_on_deprecated && unified_syntax
088fa78e
KH
16076 && (opcode->tag == OT_cinfix3
16077 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
16078 as_warn (_("conditional infixes are deprecated in unified syntax"));
16079
16080 inst.cond = cond->value;
16081 return opcode;
b99bd4ef
NC
16082 }
16083
c921be7d 16084 return NULL;
b99bd4ef
NC
16085}
16086
e07e6e58
NC
16087/* This function generates an initial IT instruction, leaving its block
16088 virtually open for the new instructions. Eventually,
16089 the mask will be updated by now_it_add_mask () each time
16090 a new instruction needs to be included in the IT block.
16091 Finally, the block is closed with close_automatic_it_block ().
16092 The block closure can be requested either from md_assemble (),
16093 a tencode (), or due to a label hook. */
16094
16095static void
16096new_automatic_it_block (int cond)
16097{
16098 now_it.state = AUTOMATIC_IT_BLOCK;
16099 now_it.mask = 0x18;
16100 now_it.cc = cond;
16101 now_it.block_length = 1;
cd000bff 16102 mapping_state (MAP_THUMB);
e07e6e58
NC
16103 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
16104}
16105
16106/* Close an automatic IT block.
16107 See comments in new_automatic_it_block (). */
16108
16109static void
16110close_automatic_it_block (void)
16111{
16112 now_it.mask = 0x10;
16113 now_it.block_length = 0;
16114}
16115
16116/* Update the mask of the current automatically-generated IT
16117 instruction. See comments in new_automatic_it_block (). */
16118
16119static void
16120now_it_add_mask (int cond)
16121{
16122#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
16123#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
16124 | ((bitvalue) << (nbit)))
e07e6e58 16125 const int resulting_bit = (cond & 1);
c921be7d 16126
e07e6e58
NC
16127 now_it.mask &= 0xf;
16128 now_it.mask = SET_BIT_VALUE (now_it.mask,
16129 resulting_bit,
16130 (5 - now_it.block_length));
16131 now_it.mask = SET_BIT_VALUE (now_it.mask,
16132 1,
16133 ((5 - now_it.block_length) - 1) );
16134 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
16135
16136#undef CLEAR_BIT
16137#undef SET_BIT_VALUE
e07e6e58
NC
16138}
16139
16140/* The IT blocks handling machinery is accessed through the these functions:
16141 it_fsm_pre_encode () from md_assemble ()
16142 set_it_insn_type () optional, from the tencode functions
16143 set_it_insn_type_last () ditto
16144 in_it_block () ditto
16145 it_fsm_post_encode () from md_assemble ()
16146 force_automatic_it_block_close () from label habdling functions
16147
16148 Rationale:
16149 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
16150 initializing the IT insn type with a generic initial value depending
16151 on the inst.condition.
16152 2) During the tencode function, two things may happen:
16153 a) The tencode function overrides the IT insn type by
16154 calling either set_it_insn_type (type) or set_it_insn_type_last ().
16155 b) The tencode function queries the IT block state by
16156 calling in_it_block () (i.e. to determine narrow/not narrow mode).
16157
16158 Both set_it_insn_type and in_it_block run the internal FSM state
16159 handling function (handle_it_state), because: a) setting the IT insn
16160 type may incur in an invalid state (exiting the function),
16161 and b) querying the state requires the FSM to be updated.
16162 Specifically we want to avoid creating an IT block for conditional
16163 branches, so it_fsm_pre_encode is actually a guess and we can't
16164 determine whether an IT block is required until the tencode () routine
16165 has decided what type of instruction this actually it.
16166 Because of this, if set_it_insn_type and in_it_block have to be used,
16167 set_it_insn_type has to be called first.
16168
16169 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
16170 determines the insn IT type depending on the inst.cond code.
16171 When a tencode () routine encodes an instruction that can be
16172 either outside an IT block, or, in the case of being inside, has to be
16173 the last one, set_it_insn_type_last () will determine the proper
16174 IT instruction type based on the inst.cond code. Otherwise,
16175 set_it_insn_type can be called for overriding that logic or
16176 for covering other cases.
16177
16178 Calling handle_it_state () may not transition the IT block state to
16179 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
16180 still queried. Instead, if the FSM determines that the state should
16181 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
16182 after the tencode () function: that's what it_fsm_post_encode () does.
16183
16184 Since in_it_block () calls the state handling function to get an
16185 updated state, an error may occur (due to invalid insns combination).
16186 In that case, inst.error is set.
16187 Therefore, inst.error has to be checked after the execution of
16188 the tencode () routine.
16189
16190 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
16191 any pending state change (if any) that didn't take place in
16192 handle_it_state () as explained above. */
16193
16194static void
16195it_fsm_pre_encode (void)
16196{
16197 if (inst.cond != COND_ALWAYS)
16198 inst.it_insn_type = INSIDE_IT_INSN;
16199 else
16200 inst.it_insn_type = OUTSIDE_IT_INSN;
16201
16202 now_it.state_handled = 0;
16203}
16204
16205/* IT state FSM handling function. */
16206
16207static int
16208handle_it_state (void)
16209{
16210 now_it.state_handled = 1;
16211
16212 switch (now_it.state)
16213 {
16214 case OUTSIDE_IT_BLOCK:
16215 switch (inst.it_insn_type)
16216 {
16217 case OUTSIDE_IT_INSN:
16218 break;
16219
16220 case INSIDE_IT_INSN:
16221 case INSIDE_IT_LAST_INSN:
16222 if (thumb_mode == 0)
16223 {
c921be7d 16224 if (unified_syntax
e07e6e58
NC
16225 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
16226 as_tsktsk (_("Warning: conditional outside an IT block"\
16227 " for Thumb."));
16228 }
16229 else
16230 {
16231 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
16232 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
16233 {
16234 /* Automatically generate the IT instruction. */
16235 new_automatic_it_block (inst.cond);
16236 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
16237 close_automatic_it_block ();
16238 }
16239 else
16240 {
16241 inst.error = BAD_OUT_IT;
16242 return FAIL;
16243 }
16244 }
16245 break;
16246
16247 case IF_INSIDE_IT_LAST_INSN:
16248 case NEUTRAL_IT_INSN:
16249 break;
16250
16251 case IT_INSN:
16252 now_it.state = MANUAL_IT_BLOCK;
16253 now_it.block_length = 0;
16254 break;
16255 }
16256 break;
16257
16258 case AUTOMATIC_IT_BLOCK:
16259 /* Three things may happen now:
16260 a) We should increment current it block size;
16261 b) We should close current it block (closing insn or 4 insns);
16262 c) We should close current it block and start a new one (due
16263 to incompatible conditions or
16264 4 insns-length block reached). */
16265
16266 switch (inst.it_insn_type)
16267 {
16268 case OUTSIDE_IT_INSN:
16269 /* The closure of the block shall happen immediatelly,
16270 so any in_it_block () call reports the block as closed. */
16271 force_automatic_it_block_close ();
16272 break;
16273
16274 case INSIDE_IT_INSN:
16275 case INSIDE_IT_LAST_INSN:
16276 case IF_INSIDE_IT_LAST_INSN:
16277 now_it.block_length++;
16278
16279 if (now_it.block_length > 4
16280 || !now_it_compatible (inst.cond))
16281 {
16282 force_automatic_it_block_close ();
16283 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
16284 new_automatic_it_block (inst.cond);
16285 }
16286 else
16287 {
16288 now_it_add_mask (inst.cond);
16289 }
16290
16291 if (now_it.state == AUTOMATIC_IT_BLOCK
16292 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
16293 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
16294 close_automatic_it_block ();
16295 break;
16296
16297 case NEUTRAL_IT_INSN:
16298 now_it.block_length++;
16299
16300 if (now_it.block_length > 4)
16301 force_automatic_it_block_close ();
16302 else
16303 now_it_add_mask (now_it.cc & 1);
16304 break;
16305
16306 case IT_INSN:
16307 close_automatic_it_block ();
16308 now_it.state = MANUAL_IT_BLOCK;
16309 break;
16310 }
16311 break;
16312
16313 case MANUAL_IT_BLOCK:
16314 {
16315 /* Check conditional suffixes. */
16316 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
16317 int is_last;
16318 now_it.mask <<= 1;
16319 now_it.mask &= 0x1f;
16320 is_last = (now_it.mask == 0x10);
16321
16322 switch (inst.it_insn_type)
16323 {
16324 case OUTSIDE_IT_INSN:
16325 inst.error = BAD_NOT_IT;
16326 return FAIL;
16327
16328 case INSIDE_IT_INSN:
16329 if (cond != inst.cond)
16330 {
16331 inst.error = BAD_IT_COND;
16332 return FAIL;
16333 }
16334 break;
16335
16336 case INSIDE_IT_LAST_INSN:
16337 case IF_INSIDE_IT_LAST_INSN:
16338 if (cond != inst.cond)
16339 {
16340 inst.error = BAD_IT_COND;
16341 return FAIL;
16342 }
16343 if (!is_last)
16344 {
16345 inst.error = BAD_BRANCH;
16346 return FAIL;
16347 }
16348 break;
16349
16350 case NEUTRAL_IT_INSN:
16351 /* The BKPT instruction is unconditional even in an IT block. */
16352 break;
16353
16354 case IT_INSN:
16355 inst.error = BAD_IT_IT;
16356 return FAIL;
16357 }
16358 }
16359 break;
16360 }
16361
16362 return SUCCESS;
16363}
16364
16365static void
16366it_fsm_post_encode (void)
16367{
16368 int is_last;
16369
16370 if (!now_it.state_handled)
16371 handle_it_state ();
16372
16373 is_last = (now_it.mask == 0x10);
16374 if (is_last)
16375 {
16376 now_it.state = OUTSIDE_IT_BLOCK;
16377 now_it.mask = 0;
16378 }
16379}
16380
16381static void
16382force_automatic_it_block_close (void)
16383{
16384 if (now_it.state == AUTOMATIC_IT_BLOCK)
16385 {
16386 close_automatic_it_block ();
16387 now_it.state = OUTSIDE_IT_BLOCK;
16388 now_it.mask = 0;
16389 }
16390}
16391
16392static int
16393in_it_block (void)
16394{
16395 if (!now_it.state_handled)
16396 handle_it_state ();
16397
16398 return now_it.state != OUTSIDE_IT_BLOCK;
16399}
16400
c19d1205
ZW
16401void
16402md_assemble (char *str)
b99bd4ef 16403{
c19d1205
ZW
16404 char *p = str;
16405 const struct asm_opcode * opcode;
b99bd4ef 16406
c19d1205
ZW
16407 /* Align the previous label if needed. */
16408 if (last_label_seen != NULL)
b99bd4ef 16409 {
c19d1205
ZW
16410 symbol_set_frag (last_label_seen, frag_now);
16411 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
16412 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
16413 }
16414
c19d1205
ZW
16415 memset (&inst, '\0', sizeof (inst));
16416 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 16417
c19d1205
ZW
16418 opcode = opcode_lookup (&p);
16419 if (!opcode)
b99bd4ef 16420 {
c19d1205 16421 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 16422 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d
NC
16423 if (! create_register_alias (str, p)
16424 && ! create_neon_reg_alias (str, p))
c19d1205 16425 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 16426
b99bd4ef
NC
16427 return;
16428 }
16429
278df34e 16430 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
16431 as_warn (_("s suffix on comparison instruction is deprecated"));
16432
037e8744
JB
16433 /* The value which unconditional instructions should have in place of the
16434 condition field. */
16435 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
16436
c19d1205 16437 if (thumb_mode)
b99bd4ef 16438 {
e74cfd16 16439 arm_feature_set variant;
8f06b2d8
PB
16440
16441 variant = cpu_variant;
16442 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
16443 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
16444 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 16445 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
16446 if (!opcode->tvariant
16447 || (thumb_mode == 1
16448 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 16449 {
bf3eeda7 16450 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
b99bd4ef
NC
16451 return;
16452 }
c19d1205
ZW
16453 if (inst.cond != COND_ALWAYS && !unified_syntax
16454 && opcode->tencode != do_t_branch)
b99bd4ef 16455 {
c19d1205 16456 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
16457 return;
16458 }
16459
752d5da4 16460 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 16461 {
7e806470 16462 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
16463 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
16464 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
16465 {
16466 /* Two things are addressed here.
16467 1) Implicit require narrow instructions on Thumb-1.
16468 This avoids relaxation accidentally introducing Thumb-2
16469 instructions.
16470 2) Reject wide instructions in non Thumb-2 cores. */
16471 if (inst.size_req == 0)
16472 inst.size_req = 2;
16473 else if (inst.size_req == 4)
16474 {
bf3eeda7 16475 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
752d5da4
NC
16476 return;
16477 }
16478 }
076d447c
PB
16479 }
16480
c19d1205
ZW
16481 inst.instruction = opcode->tvalue;
16482
5be8be5d 16483 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
e07e6e58
NC
16484 {
16485 /* Prepare the it_insn_type for those encodings that don't set
16486 it. */
16487 it_fsm_pre_encode ();
c19d1205 16488
e07e6e58
NC
16489 opcode->tencode ();
16490
16491 it_fsm_post_encode ();
16492 }
e27ec89e 16493
0110f2b8 16494 if (!(inst.error || inst.relax))
b99bd4ef 16495 {
9c2799c2 16496 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
16497 inst.size = (inst.instruction > 0xffff ? 4 : 2);
16498 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 16499 {
c19d1205 16500 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
16501 return;
16502 }
16503 }
076d447c
PB
16504
16505 /* Something has gone badly wrong if we try to relax a fixed size
16506 instruction. */
9c2799c2 16507 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 16508
e74cfd16
PB
16509 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16510 *opcode->tvariant);
ee065d83 16511 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 16512 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 16513 anything other than bl/blx and v6-M instructions.
ee065d83 16514 This is overly pessimistic for relaxable instructions. */
7e806470
PB
16515 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
16516 || inst.relax)
e07e6e58
NC
16517 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
16518 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
16519 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16520 arm_ext_v6t2);
cd000bff 16521
88714cb8
DG
16522 check_neon_suffixes;
16523
cd000bff 16524 if (!inst.error)
c877a2f2
NC
16525 {
16526 mapping_state (MAP_THUMB);
16527 }
c19d1205 16528 }
3e9e4fcf 16529 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 16530 {
845b51d6
PB
16531 bfd_boolean is_bx;
16532
16533 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
16534 is_bx = (opcode->aencode == do_bx);
16535
c19d1205 16536 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
16537 if (!(is_bx && fix_v4bx)
16538 && !(opcode->avariant &&
16539 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 16540 {
bf3eeda7 16541 as_bad (_("selected processor does not support ARM mode `%s'"), str);
c19d1205 16542 return;
b99bd4ef 16543 }
c19d1205 16544 if (inst.size_req)
b99bd4ef 16545 {
c19d1205
ZW
16546 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
16547 return;
b99bd4ef
NC
16548 }
16549
c19d1205
ZW
16550 inst.instruction = opcode->avalue;
16551 if (opcode->tag == OT_unconditionalF)
16552 inst.instruction |= 0xF << 28;
16553 else
16554 inst.instruction |= inst.cond << 28;
16555 inst.size = INSN_SIZE;
5be8be5d 16556 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
e07e6e58
NC
16557 {
16558 it_fsm_pre_encode ();
16559 opcode->aencode ();
16560 it_fsm_post_encode ();
16561 }
ee065d83
PB
16562 /* Arm mode bx is marked as both v4T and v5 because it's still required
16563 on a hypothetical non-thumb v5 core. */
845b51d6 16564 if (is_bx)
e74cfd16 16565 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 16566 else
e74cfd16
PB
16567 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
16568 *opcode->avariant);
88714cb8
DG
16569
16570 check_neon_suffixes;
16571
cd000bff 16572 if (!inst.error)
c877a2f2
NC
16573 {
16574 mapping_state (MAP_ARM);
16575 }
b99bd4ef 16576 }
3e9e4fcf
JB
16577 else
16578 {
16579 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
16580 "-- `%s'"), str);
16581 return;
16582 }
c19d1205
ZW
16583 output_inst (str);
16584}
b99bd4ef 16585
e07e6e58
NC
16586static void
16587check_it_blocks_finished (void)
16588{
16589#ifdef OBJ_ELF
16590 asection *sect;
16591
16592 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
16593 if (seg_info (sect)->tc_segment_info_data.current_it.state
16594 == MANUAL_IT_BLOCK)
16595 {
16596 as_warn (_("section '%s' finished with an open IT block."),
16597 sect->name);
16598 }
16599#else
16600 if (now_it.state == MANUAL_IT_BLOCK)
16601 as_warn (_("file finished with an open IT block."));
16602#endif
16603}
16604
c19d1205
ZW
16605/* Various frobbings of labels and their addresses. */
16606
16607void
16608arm_start_line_hook (void)
16609{
16610 last_label_seen = NULL;
b99bd4ef
NC
16611}
16612
c19d1205
ZW
16613void
16614arm_frob_label (symbolS * sym)
b99bd4ef 16615{
c19d1205 16616 last_label_seen = sym;
b99bd4ef 16617
c19d1205 16618 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 16619
c19d1205
ZW
16620#if defined OBJ_COFF || defined OBJ_ELF
16621 ARM_SET_INTERWORK (sym, support_interwork);
16622#endif
b99bd4ef 16623
e07e6e58
NC
16624 force_automatic_it_block_close ();
16625
5f4273c7 16626 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
16627 as Thumb functions. This is because these labels, whilst
16628 they exist inside Thumb code, are not the entry points for
16629 possible ARM->Thumb calls. Also, these labels can be used
16630 as part of a computed goto or switch statement. eg gcc
16631 can generate code that looks like this:
b99bd4ef 16632
c19d1205
ZW
16633 ldr r2, [pc, .Laaa]
16634 lsl r3, r3, #2
16635 ldr r2, [r3, r2]
16636 mov pc, r2
b99bd4ef 16637
c19d1205
ZW
16638 .Lbbb: .word .Lxxx
16639 .Lccc: .word .Lyyy
16640 ..etc...
16641 .Laaa: .word Lbbb
b99bd4ef 16642
c19d1205
ZW
16643 The first instruction loads the address of the jump table.
16644 The second instruction converts a table index into a byte offset.
16645 The third instruction gets the jump address out of the table.
16646 The fourth instruction performs the jump.
b99bd4ef 16647
c19d1205
ZW
16648 If the address stored at .Laaa is that of a symbol which has the
16649 Thumb_Func bit set, then the linker will arrange for this address
16650 to have the bottom bit set, which in turn would mean that the
16651 address computation performed by the third instruction would end
16652 up with the bottom bit set. Since the ARM is capable of unaligned
16653 word loads, the instruction would then load the incorrect address
16654 out of the jump table, and chaos would ensue. */
16655 if (label_is_thumb_function_name
16656 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
16657 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 16658 {
c19d1205
ZW
16659 /* When the address of a Thumb function is taken the bottom
16660 bit of that address should be set. This will allow
16661 interworking between Arm and Thumb functions to work
16662 correctly. */
b99bd4ef 16663
c19d1205 16664 THUMB_SET_FUNC (sym, 1);
b99bd4ef 16665
c19d1205 16666 label_is_thumb_function_name = FALSE;
b99bd4ef 16667 }
07a53e5c 16668
07a53e5c 16669 dwarf2_emit_label (sym);
b99bd4ef
NC
16670}
16671
c921be7d 16672bfd_boolean
c19d1205 16673arm_data_in_code (void)
b99bd4ef 16674{
c19d1205 16675 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 16676 {
c19d1205
ZW
16677 *input_line_pointer = '/';
16678 input_line_pointer += 5;
16679 *input_line_pointer = 0;
c921be7d 16680 return TRUE;
b99bd4ef
NC
16681 }
16682
c921be7d 16683 return FALSE;
b99bd4ef
NC
16684}
16685
c19d1205
ZW
16686char *
16687arm_canonicalize_symbol_name (char * name)
b99bd4ef 16688{
c19d1205 16689 int len;
b99bd4ef 16690
c19d1205
ZW
16691 if (thumb_mode && (len = strlen (name)) > 5
16692 && streq (name + len - 5, "/data"))
16693 *(name + len - 5) = 0;
b99bd4ef 16694
c19d1205 16695 return name;
b99bd4ef 16696}
c19d1205
ZW
16697\f
16698/* Table of all register names defined by default. The user can
16699 define additional names with .req. Note that all register names
16700 should appear in both upper and lowercase variants. Some registers
16701 also have mixed-case names. */
b99bd4ef 16702
dcbf9037 16703#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 16704#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 16705#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
16706#define REGSET(p,t) \
16707 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
16708 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
16709 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
16710 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
16711#define REGSETH(p,t) \
16712 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
16713 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
16714 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
16715 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
16716#define REGSET2(p,t) \
16717 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
16718 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
16719 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
16720 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
16721#define SPLRBANK(base,bank,t) \
16722 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
16723 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
16724 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
16725 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
16726 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
16727 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 16728
c19d1205 16729static const struct reg_entry reg_names[] =
7ed4c4c5 16730{
c19d1205
ZW
16731 /* ARM integer registers. */
16732 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 16733
c19d1205
ZW
16734 /* ATPCS synonyms. */
16735 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
16736 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16737 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 16738
c19d1205
ZW
16739 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16740 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16741 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 16742
c19d1205
ZW
16743 /* Well-known aliases. */
16744 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16745 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16746
16747 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16748 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16749
16750 /* Coprocessor numbers. */
16751 REGSET(p, CP), REGSET(P, CP),
16752
16753 /* Coprocessor register numbers. The "cr" variants are for backward
16754 compatibility. */
16755 REGSET(c, CN), REGSET(C, CN),
16756 REGSET(cr, CN), REGSET(CR, CN),
16757
90ec0d68
MGD
16758 /* ARM banked registers. */
16759 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
16760 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
16761 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
16762 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
16763 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
16764 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
16765 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
16766
16767 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
16768 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
16769 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
16770 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
16771 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
16772 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB),
16773 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
16774 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
16775
16776 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
16777 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
16778 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
16779 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
16780 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
16781 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
16782 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 16783 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
16784 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
16785
c19d1205
ZW
16786 /* FPA registers. */
16787 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16788 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16789
16790 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16791 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16792
16793 /* VFP SP registers. */
5287ad62
JB
16794 REGSET(s,VFS), REGSET(S,VFS),
16795 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
16796
16797 /* VFP DP Registers. */
5287ad62
JB
16798 REGSET(d,VFD), REGSET(D,VFD),
16799 /* Extra Neon DP registers. */
16800 REGSETH(d,VFD), REGSETH(D,VFD),
16801
16802 /* Neon QP registers. */
16803 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
16804
16805 /* VFP control registers. */
16806 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16807 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
16808 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16809 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16810 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16811 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
16812
16813 /* Maverick DSP coprocessor registers. */
16814 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16815 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16816
16817 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16818 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16819 REGDEF(dspsc,0,DSPSC),
16820
16821 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16822 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16823 REGDEF(DSPSC,0,DSPSC),
16824
16825 /* iWMMXt data registers - p0, c0-15. */
16826 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16827
16828 /* iWMMXt control registers - p1, c0-3. */
16829 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16830 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16831 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16832 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16833
16834 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16835 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16836 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16837 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16838 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16839
16840 /* XScale accumulator registers. */
16841 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16842};
16843#undef REGDEF
16844#undef REGNUM
16845#undef REGSET
7ed4c4c5 16846
c19d1205
ZW
16847/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16848 within psr_required_here. */
16849static const struct asm_psr psrs[] =
16850{
16851 /* Backward compatibility notation. Note that "all" is no longer
16852 truly all possible PSR bits. */
16853 {"all", PSR_c | PSR_f},
16854 {"flg", PSR_f},
16855 {"ctl", PSR_c},
16856
16857 /* Individual flags. */
16858 {"f", PSR_f},
16859 {"c", PSR_c},
16860 {"x", PSR_x},
16861 {"s", PSR_s},
59b42a0d 16862
c19d1205
ZW
16863 /* Combinations of flags. */
16864 {"fs", PSR_f | PSR_s},
16865 {"fx", PSR_f | PSR_x},
16866 {"fc", PSR_f | PSR_c},
16867 {"sf", PSR_s | PSR_f},
16868 {"sx", PSR_s | PSR_x},
16869 {"sc", PSR_s | PSR_c},
16870 {"xf", PSR_x | PSR_f},
16871 {"xs", PSR_x | PSR_s},
16872 {"xc", PSR_x | PSR_c},
16873 {"cf", PSR_c | PSR_f},
16874 {"cs", PSR_c | PSR_s},
16875 {"cx", PSR_c | PSR_x},
16876 {"fsx", PSR_f | PSR_s | PSR_x},
16877 {"fsc", PSR_f | PSR_s | PSR_c},
16878 {"fxs", PSR_f | PSR_x | PSR_s},
16879 {"fxc", PSR_f | PSR_x | PSR_c},
16880 {"fcs", PSR_f | PSR_c | PSR_s},
16881 {"fcx", PSR_f | PSR_c | PSR_x},
16882 {"sfx", PSR_s | PSR_f | PSR_x},
16883 {"sfc", PSR_s | PSR_f | PSR_c},
16884 {"sxf", PSR_s | PSR_x | PSR_f},
16885 {"sxc", PSR_s | PSR_x | PSR_c},
16886 {"scf", PSR_s | PSR_c | PSR_f},
16887 {"scx", PSR_s | PSR_c | PSR_x},
16888 {"xfs", PSR_x | PSR_f | PSR_s},
16889 {"xfc", PSR_x | PSR_f | PSR_c},
16890 {"xsf", PSR_x | PSR_s | PSR_f},
16891 {"xsc", PSR_x | PSR_s | PSR_c},
16892 {"xcf", PSR_x | PSR_c | PSR_f},
16893 {"xcs", PSR_x | PSR_c | PSR_s},
16894 {"cfs", PSR_c | PSR_f | PSR_s},
16895 {"cfx", PSR_c | PSR_f | PSR_x},
16896 {"csf", PSR_c | PSR_s | PSR_f},
16897 {"csx", PSR_c | PSR_s | PSR_x},
16898 {"cxf", PSR_c | PSR_x | PSR_f},
16899 {"cxs", PSR_c | PSR_x | PSR_s},
16900 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16901 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16902 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16903 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16904 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16905 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16906 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16907 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16908 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16909 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16910 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16911 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16912 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16913 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16914 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16915 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16916 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16917 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16918 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16919 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16920 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16921 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16922 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16923 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16924};
16925
62b3e311
PB
16926/* Table of V7M psr names. */
16927static const struct asm_psr v7m_psrs[] =
16928{
2b744c99
PB
16929 {"apsr", 0 }, {"APSR", 0 },
16930 {"iapsr", 1 }, {"IAPSR", 1 },
16931 {"eapsr", 2 }, {"EAPSR", 2 },
16932 {"psr", 3 }, {"PSR", 3 },
16933 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16934 {"ipsr", 5 }, {"IPSR", 5 },
16935 {"epsr", 6 }, {"EPSR", 6 },
16936 {"iepsr", 7 }, {"IEPSR", 7 },
16937 {"msp", 8 }, {"MSP", 8 },
16938 {"psp", 9 }, {"PSP", 9 },
16939 {"primask", 16}, {"PRIMASK", 16},
16940 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
16941 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16942 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99
PB
16943 {"faultmask", 19}, {"FAULTMASK", 19},
16944 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
16945};
16946
c19d1205
ZW
16947/* Table of all shift-in-operand names. */
16948static const struct asm_shift_name shift_names [] =
b99bd4ef 16949{
c19d1205
ZW
16950 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16951 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16952 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16953 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16954 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16955 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16956};
b99bd4ef 16957
c19d1205
ZW
16958/* Table of all explicit relocation names. */
16959#ifdef OBJ_ELF
16960static struct reloc_entry reloc_names[] =
16961{
16962 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16963 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16964 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16965 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16966 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16967 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16968 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16969 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16970 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16971 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 16972 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
16973 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
16974 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
16975 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
16976 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
16977 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
16978 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
16979 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
16980};
16981#endif
b99bd4ef 16982
c19d1205
ZW
16983/* Table of all conditional affixes. 0xF is not defined as a condition code. */
16984static const struct asm_cond conds[] =
16985{
16986 {"eq", 0x0},
16987 {"ne", 0x1},
16988 {"cs", 0x2}, {"hs", 0x2},
16989 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16990 {"mi", 0x4},
16991 {"pl", 0x5},
16992 {"vs", 0x6},
16993 {"vc", 0x7},
16994 {"hi", 0x8},
16995 {"ls", 0x9},
16996 {"ge", 0xa},
16997 {"lt", 0xb},
16998 {"gt", 0xc},
16999 {"le", 0xd},
17000 {"al", 0xe}
17001};
bfae80f2 17002
62b3e311
PB
17003static struct asm_barrier_opt barrier_opt_names[] =
17004{
52e7f43d
RE
17005 { "sy", 0xf }, { "SY", 0xf },
17006 { "un", 0x7 }, { "UN", 0x7 },
17007 { "st", 0xe }, { "ST", 0xe },
17008 { "unst", 0x6 }, { "UNST", 0x6 },
17009 { "ish", 0xb }, { "ISH", 0xb },
17010 { "sh", 0xb }, { "SH", 0xb },
17011 { "ishst", 0xa }, { "ISHST", 0xa },
17012 { "shst", 0xa }, { "SHST", 0xa },
17013 { "nsh", 0x7 }, { "NSH", 0x7 },
17014 { "nshst", 0x6 }, { "NSHST", 0x6 },
17015 { "osh", 0x3 }, { "OSH", 0x3 },
17016 { "oshst", 0x2 }, { "OSHST", 0x2 }
62b3e311
PB
17017};
17018
c19d1205
ZW
17019/* Table of ARM-format instructions. */
17020
17021/* Macros for gluing together operand strings. N.B. In all cases
17022 other than OPS0, the trailing OP_stop comes from default
17023 zero-initialization of the unspecified elements of the array. */
17024#define OPS0() { OP_stop, }
17025#define OPS1(a) { OP_##a, }
17026#define OPS2(a,b) { OP_##a,OP_##b, }
17027#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
17028#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
17029#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
17030#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
17031
5be8be5d
DG
17032/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
17033 This is useful when mixing operands for ARM and THUMB, i.e. using the
17034 MIX_ARM_THUMB_OPERANDS macro.
17035 In order to use these macros, prefix the number of operands with _
17036 e.g. _3. */
17037#define OPS_1(a) { a, }
17038#define OPS_2(a,b) { a,b, }
17039#define OPS_3(a,b,c) { a,b,c, }
17040#define OPS_4(a,b,c,d) { a,b,c,d, }
17041#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
17042#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
17043
c19d1205
ZW
17044/* These macros abstract out the exact format of the mnemonic table and
17045 save some repeated characters. */
17046
17047/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
17048#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 17049 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 17050 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
17051
17052/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
17053 a T_MNEM_xyz enumerator. */
17054#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 17055 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 17056#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 17057 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
17058
17059/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
17060 infix after the third character. */
17061#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 17062 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 17063 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 17064#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 17065 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 17066 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 17067#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 17068 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 17069#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 17070 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 17071#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 17072 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 17073#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 17074 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
17075
17076/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
17077 appear in the condition table. */
17078#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
21d799b5 17079 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
1887dd22 17080 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
17081
17082#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
17083 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
17084 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
17085 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
17086 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
17087 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
17088 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
17089 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
17090 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
17091 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
17092 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
17093 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
17094 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
17095 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
17096 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
17097 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
17098 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
17099 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
17100 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
17101 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
17102
17103#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
17104 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
17105#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
21d799b5 17106 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
17107
17108/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
17109 field is still 0xE. Many of the Thumb variants can be executed
17110 conditionally, so this is checked separately. */
c19d1205 17111#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 17112 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 17113 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
17114
17115/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
17116 condition code field. */
17117#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 17118 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 17119 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
17120
17121/* ARM-only variants of all the above. */
6a86118a 17122#define CE(mnem, op, nops, ops, ae) \
21d799b5 17123 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
17124
17125#define C3(mnem, op, nops, ops, ae) \
17126 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17127
e3cb604e
PB
17128/* Legacy mnemonics that always have conditional infix after the third
17129 character. */
17130#define CL(mnem, op, nops, ops, ae) \
21d799b5 17131 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
17132 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17133
8f06b2d8
PB
17134/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
17135#define cCE(mnem, op, nops, ops, ae) \
21d799b5 17136 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 17137
e3cb604e
PB
17138/* Legacy coprocessor instructions where conditional infix and conditional
17139 suffix are ambiguous. For consistency this includes all FPA instructions,
17140 not just the potentially ambiguous ones. */
17141#define cCL(mnem, op, nops, ops, ae) \
21d799b5 17142 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
17143 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17144
17145/* Coprocessor, takes either a suffix or a position-3 infix
17146 (for an FPA corner case). */
17147#define C3E(mnem, op, nops, ops, ae) \
21d799b5 17148 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 17149 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 17150
6a86118a 17151#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
17152 { m1 #m2 m3, OPS##nops ops, \
17153 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
17154 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17155
17156#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
17157 xCM_ (m1, , m2, op, nops, ops, ae), \
17158 xCM_ (m1, eq, m2, op, nops, ops, ae), \
17159 xCM_ (m1, ne, m2, op, nops, ops, ae), \
17160 xCM_ (m1, cs, m2, op, nops, ops, ae), \
17161 xCM_ (m1, hs, m2, op, nops, ops, ae), \
17162 xCM_ (m1, cc, m2, op, nops, ops, ae), \
17163 xCM_ (m1, ul, m2, op, nops, ops, ae), \
17164 xCM_ (m1, lo, m2, op, nops, ops, ae), \
17165 xCM_ (m1, mi, m2, op, nops, ops, ae), \
17166 xCM_ (m1, pl, m2, op, nops, ops, ae), \
17167 xCM_ (m1, vs, m2, op, nops, ops, ae), \
17168 xCM_ (m1, vc, m2, op, nops, ops, ae), \
17169 xCM_ (m1, hi, m2, op, nops, ops, ae), \
17170 xCM_ (m1, ls, m2, op, nops, ops, ae), \
17171 xCM_ (m1, ge, m2, op, nops, ops, ae), \
17172 xCM_ (m1, lt, m2, op, nops, ops, ae), \
17173 xCM_ (m1, gt, m2, op, nops, ops, ae), \
17174 xCM_ (m1, le, m2, op, nops, ops, ae), \
17175 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
17176
17177#define UE(mnem, op, nops, ops, ae) \
17178 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17179
17180#define UF(mnem, op, nops, ops, ae) \
17181 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17182
5287ad62
JB
17183/* Neon data-processing. ARM versions are unconditional with cond=0xf.
17184 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
17185 use the same encoding function for each. */
17186#define NUF(mnem, op, nops, ops, enc) \
17187 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
17188 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17189
17190/* Neon data processing, version which indirects through neon_enc_tab for
17191 the various overloaded versions of opcodes. */
17192#define nUF(mnem, op, nops, ops, enc) \
21d799b5 17193 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
17194 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17195
17196/* Neon insn with conditional suffix for the ARM version, non-overloaded
17197 version. */
037e8744
JB
17198#define NCE_tag(mnem, op, nops, ops, enc, tag) \
17199 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
17200 THUMB_VARIANT, do_##enc, do_##enc }
17201
037e8744 17202#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 17203 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
17204
17205#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 17206 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 17207
5287ad62 17208/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 17209#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 17210 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
17211 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17212
037e8744 17213#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 17214 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
17215
17216#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 17217 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 17218
c19d1205
ZW
17219#define do_0 0
17220
c19d1205 17221static const struct asm_opcode insns[] =
bfae80f2 17222{
e74cfd16
PB
17223#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
17224#define THUMB_VARIANT &arm_ext_v4t
21d799b5
NC
17225 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
17226 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
17227 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
17228 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
17229 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
17230 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
17231 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
17232 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
17233 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
17234 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
17235 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
17236 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
17237 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
17238 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
17239 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
17240 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
17241
17242 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
17243 for setting PSR flag bits. They are obsolete in V6 and do not
17244 have Thumb equivalents. */
21d799b5
NC
17245 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17246 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17247 CL("tstp", 110f000, 2, (RR, SH), cmp),
17248 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17249 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17250 CL("cmpp", 150f000, 2, (RR, SH), cmp),
17251 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17252 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17253 CL("cmnp", 170f000, 2, (RR, SH), cmp),
17254
17255 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
17256 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
17257 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
17258 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
17259
17260 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
17261 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17262 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
17263 OP_RRnpc),
17264 OP_ADDRGLDR),ldst, t_ldst),
17265 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
17266
17267 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17268 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17269 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17270 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17271 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17272 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17273
17274 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
17275 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
17276 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
17277 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 17278
c19d1205 17279 /* Pseudo ops. */
21d799b5 17280 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 17281 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 17282 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
17283
17284 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
17285 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
17286 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
17287 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
17288 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
17289 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
17290 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
17291 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
17292 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
17293 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
17294 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
17295 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
17296 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 17297
16a4cf17 17298 /* These may simplify to neg. */
21d799b5
NC
17299 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
17300 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 17301
c921be7d
NC
17302#undef THUMB_VARIANT
17303#define THUMB_VARIANT & arm_ext_v6
17304
21d799b5 17305 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
17306
17307 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
17308#undef THUMB_VARIANT
17309#define THUMB_VARIANT & arm_ext_v6t2
17310
21d799b5
NC
17311 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17312 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17313 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 17314
5be8be5d
DG
17315 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17316 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17317 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
17318 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 17319
21d799b5
NC
17320 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17321 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 17322
21d799b5
NC
17323 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17324 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
17325
17326 /* V1 instructions with no Thumb analogue at all. */
21d799b5 17327 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
17328 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
17329
17330 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
17331 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
17332 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
17333 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
17334 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
17335 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
17336 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
17337 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
17338
c921be7d
NC
17339#undef ARM_VARIANT
17340#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
17341#undef THUMB_VARIANT
17342#define THUMB_VARIANT & arm_ext_v4t
17343
21d799b5
NC
17344 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
17345 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 17346
c921be7d
NC
17347#undef THUMB_VARIANT
17348#define THUMB_VARIANT & arm_ext_v6t2
17349
21d799b5 17350 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
17351 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
17352
17353 /* Generic coprocessor instructions. */
21d799b5
NC
17354 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17355 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17356 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17357 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17358 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17359 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 17360 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 17361
c921be7d
NC
17362#undef ARM_VARIANT
17363#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
17364
21d799b5 17365 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
17366 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
17367
c921be7d
NC
17368#undef ARM_VARIANT
17369#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
17370#undef THUMB_VARIANT
17371#define THUMB_VARIANT & arm_ext_msr
17372
d2cd1205
JB
17373 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
17374 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 17375
c921be7d
NC
17376#undef ARM_VARIANT
17377#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
17378#undef THUMB_VARIANT
17379#define THUMB_VARIANT & arm_ext_v6t2
17380
21d799b5
NC
17381 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17382 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17383 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17384 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17385 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17386 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17387 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17388 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 17389
c921be7d
NC
17390#undef ARM_VARIANT
17391#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
17392#undef THUMB_VARIANT
17393#define THUMB_VARIANT & arm_ext_v4t
17394
5be8be5d
DG
17395 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17396 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17397 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17398 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17399 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17400 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 17401
c921be7d
NC
17402#undef ARM_VARIANT
17403#define ARM_VARIANT & arm_ext_v4t_5
17404
c19d1205
ZW
17405 /* ARM Architecture 4T. */
17406 /* Note: bx (and blx) are required on V5, even if the processor does
17407 not support Thumb. */
21d799b5 17408 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 17409
c921be7d
NC
17410#undef ARM_VARIANT
17411#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
17412#undef THUMB_VARIANT
17413#define THUMB_VARIANT & arm_ext_v5t
17414
c19d1205
ZW
17415 /* Note: blx has 2 variants; the .value coded here is for
17416 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
17417 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
17418 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 17419
c921be7d
NC
17420#undef THUMB_VARIANT
17421#define THUMB_VARIANT & arm_ext_v6t2
17422
21d799b5
NC
17423 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
17424 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17425 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17426 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17427 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17428 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17429 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17430 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 17431
c921be7d
NC
17432#undef ARM_VARIANT
17433#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
9e3c6df6
PB
17434#undef THUMB_VARIANT
17435#define THUMB_VARIANT &arm_ext_v5exp
c921be7d 17436
21d799b5
NC
17437 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17438 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17439 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17440 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 17441
21d799b5
NC
17442 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17443 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 17444
21d799b5
NC
17445 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17446 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17447 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17448 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 17449
21d799b5
NC
17450 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17451 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17452 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17453 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 17454
21d799b5
NC
17455 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17456 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 17457
03ee1b7f
NC
17458 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17459 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17460 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17461 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 17462
c921be7d
NC
17463#undef ARM_VARIANT
17464#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
9e3c6df6
PB
17465#undef THUMB_VARIANT
17466#define THUMB_VARIANT &arm_ext_v6t2
c921be7d 17467
21d799b5 17468 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
17469 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
17470 ldrd, t_ldstd),
17471 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
17472 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 17473
21d799b5
NC
17474 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17475 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 17476
c921be7d
NC
17477#undef ARM_VARIANT
17478#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
17479
21d799b5 17480 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 17481
c921be7d
NC
17482#undef ARM_VARIANT
17483#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
17484#undef THUMB_VARIANT
17485#define THUMB_VARIANT & arm_ext_v6
17486
21d799b5
NC
17487 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
17488 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
17489 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17490 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17491 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17492 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17493 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17494 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17495 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17496 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 17497
c921be7d
NC
17498#undef THUMB_VARIANT
17499#define THUMB_VARIANT & arm_ext_v6t2
17500
5be8be5d
DG
17501 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
17502 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17503 strex, t_strex),
21d799b5
NC
17504 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17505 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 17506
21d799b5
NC
17507 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
17508 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 17509
9e3c6df6 17510/* ARM V6 not included in V7M. */
c921be7d
NC
17511#undef THUMB_VARIANT
17512#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6
PB
17513 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17514 UF(rfeib, 9900a00, 1, (RRw), rfe),
17515 UF(rfeda, 8100a00, 1, (RRw), rfe),
17516 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17517 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17518 UF(rfefa, 9900a00, 1, (RRw), rfe),
17519 UF(rfeea, 8100a00, 1, (RRw), rfe),
17520 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17521 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
17522 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
17523 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
17524 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 17525
9e3c6df6
PB
17526/* ARM V6 not included in V7M (eg. integer SIMD). */
17527#undef THUMB_VARIANT
17528#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
17529 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
17530 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
17531 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
17532 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17533 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17534 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17535 /* Old name for QASX. */
21d799b5
NC
17536 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17537 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17538 /* Old name for QSAX. */
21d799b5
NC
17539 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17540 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17541 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17542 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17543 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17544 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17545 /* Old name for SASX. */
21d799b5
NC
17546 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17547 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17548 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17549 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17550 /* Old name for SHASX. */
21d799b5
NC
17551 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17552 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17553 /* Old name for SHSAX. */
21d799b5
NC
17554 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17555 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17556 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17557 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17558 /* Old name for SSAX. */
21d799b5
NC
17559 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17560 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17561 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17562 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17563 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17564 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17565 /* Old name for UASX. */
21d799b5
NC
17566 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17567 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17568 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17569 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17570 /* Old name for UHASX. */
21d799b5
NC
17571 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17572 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17573 /* Old name for UHSAX. */
21d799b5
NC
17574 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17575 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17576 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17577 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17578 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17579 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17580 /* Old name for UQASX. */
21d799b5
NC
17581 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17582 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17583 /* Old name for UQSAX. */
21d799b5
NC
17584 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17585 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17586 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17587 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17588 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17589 /* Old name for USAX. */
21d799b5
NC
17590 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17591 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
17592 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17593 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17594 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17595 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17596 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17597 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17598 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17599 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17600 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17601 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17602 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17603 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17604 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17605 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17606 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17607 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17608 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17609 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17610 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17611 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17612 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17613 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17614 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17615 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17616 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17617 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17618 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
17619 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
17620 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
17621 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17622 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17623 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 17624
c921be7d
NC
17625#undef ARM_VARIANT
17626#define ARM_VARIANT & arm_ext_v6k
17627#undef THUMB_VARIANT
17628#define THUMB_VARIANT & arm_ext_v6k
17629
21d799b5
NC
17630 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
17631 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
17632 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
17633 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 17634
c921be7d
NC
17635#undef THUMB_VARIANT
17636#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
17637 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
17638 ldrexd, t_ldrexd),
17639 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
17640 RRnpcb), strexd, t_strexd),
ebdca51a 17641
c921be7d
NC
17642#undef THUMB_VARIANT
17643#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
17644 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
17645 rd_rn, rd_rn),
17646 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
17647 rd_rn, rd_rn),
17648 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 17649 strex, t_strexbh),
5be8be5d 17650 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 17651 strex, t_strexbh),
21d799b5 17652 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 17653
c921be7d 17654#undef ARM_VARIANT
f4c65163
MGD
17655#define ARM_VARIANT & arm_ext_sec
17656#undef THUMB_VARIANT
17657#define THUMB_VARIANT & arm_ext_sec
c921be7d 17658
21d799b5 17659 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 17660
90ec0d68
MGD
17661#undef ARM_VARIANT
17662#define ARM_VARIANT & arm_ext_virt
17663#undef THUMB_VARIANT
17664#define THUMB_VARIANT & arm_ext_virt
17665
17666 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
17667 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
17668
c921be7d
NC
17669#undef ARM_VARIANT
17670#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
17671#undef THUMB_VARIANT
17672#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 17673
21d799b5
NC
17674 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
17675 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
17676 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17677 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 17678
21d799b5
NC
17679 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17680 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
17681 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
17682 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 17683
5be8be5d
DG
17684 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17685 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17686 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17687 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 17688
bf3eeda7
NS
17689 /* Thumb-only instructions. */
17690#undef ARM_VARIANT
17691#define ARM_VARIANT NULL
17692 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
17693 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
17694
17695 /* ARM does not really have an IT instruction, so always allow it.
17696 The opcode is copied from Thumb in order to allow warnings in
17697 -mimplicit-it=[never | arm] modes. */
17698#undef ARM_VARIANT
17699#define ARM_VARIANT & arm_ext_v1
17700
21d799b5
NC
17701 TUE("it", bf08, bf08, 1, (COND), it, t_it),
17702 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
17703 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
17704 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
17705 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
17706 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
17707 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
17708 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
17709 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
17710 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
17711 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
17712 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
17713 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
17714 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
17715 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 17716 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
17717 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
17718 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 17719
92e90b6e 17720 /* Thumb2 only instructions. */
c921be7d
NC
17721#undef ARM_VARIANT
17722#define ARM_VARIANT NULL
92e90b6e 17723
21d799b5
NC
17724 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17725 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17726 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
17727 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
17728 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
17729 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 17730
eea54501
MGD
17731 /* Hardware division instructions. */
17732#undef ARM_VARIANT
17733#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
17734#undef THUMB_VARIANT
17735#define THUMB_VARIANT & arm_ext_div
17736
eea54501
MGD
17737 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
17738 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 17739
7e806470 17740 /* ARM V6M/V7 instructions. */
c921be7d
NC
17741#undef ARM_VARIANT
17742#define ARM_VARIANT & arm_ext_barrier
17743#undef THUMB_VARIANT
17744#define THUMB_VARIANT & arm_ext_barrier
17745
52e7f43d
RE
17746 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
17747 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
17748 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
7e806470 17749
62b3e311 17750 /* ARM V7 instructions. */
c921be7d
NC
17751#undef ARM_VARIANT
17752#define ARM_VARIANT & arm_ext_v7
17753#undef THUMB_VARIANT
17754#define THUMB_VARIANT & arm_ext_v7
17755
21d799b5
NC
17756 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
17757 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 17758
60e5ef9f
MGD
17759#undef ARM_VARIANT
17760#define ARM_VARIANT & arm_ext_mp
17761#undef THUMB_VARIANT
17762#define THUMB_VARIANT & arm_ext_mp
17763
17764 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
17765
c921be7d
NC
17766#undef ARM_VARIANT
17767#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
17768
21d799b5
NC
17769 cCE("wfs", e200110, 1, (RR), rd),
17770 cCE("rfs", e300110, 1, (RR), rd),
17771 cCE("wfc", e400110, 1, (RR), rd),
17772 cCE("rfc", e500110, 1, (RR), rd),
17773
17774 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
17775 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
17776 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
17777 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
17778
17779 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
17780 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
17781 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
17782 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
17783
17784 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
17785 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
17786 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
17787 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
17788 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
17789 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
17790 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
17791 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
17792 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
17793 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
17794 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
17795 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
17796
17797 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
17798 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
17799 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
17800 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
17801 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17802 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17803 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17804 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17805 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17806 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17807 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17808 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17809
17810 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17811 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17812 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17813 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17814 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17815 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17816 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17817 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17818 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17819 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17820 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17821 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17822
17823 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17824 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17825 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17826 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17827 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17828 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17829 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17830 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17831 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17832 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17833 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17834 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17835
17836 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17837 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17838 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17839 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17840 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17841 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17842 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17843 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17844 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17845 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17846 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17847 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17848
17849 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17850 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17851 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17852 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17853 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17854 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17855 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17856 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17857 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17858 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17859 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17860 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17861
17862 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17863 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17864 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17865 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17866 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17867 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17868 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17869 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17870 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17871 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17872 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17873 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17874
17875 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17876 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17877 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17878 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17879 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17880 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17881 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17882 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17883 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17884 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17885 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17886 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17887
17888 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17889 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17890 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17891 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17892 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17893 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17894 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17895 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17896 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17897 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17898 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17899 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17900
17901 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17902 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17903 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17904 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17905 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17906 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17907 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17908 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17909 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17910 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17911 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17912 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17913
17914 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17915 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17916 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17917 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17918 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17919 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17920 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17921 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17922 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17923 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17924 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17925 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17926
17927 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17928 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17929 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17930 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17931 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17932 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17933 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17934 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17935 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17936 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17937 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17938 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17939
17940 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17941 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17942 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17943 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17944 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17945 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17946 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17947 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17948 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17949 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17950 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17951 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17952
17953 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17954 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17955 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17956 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17957 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17958 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17959 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17960 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17961 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17962 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17963 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17964 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17965
17966 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17967 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17968 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17969 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17970 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17971 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17972 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17973 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17974 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17975 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17976 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17977 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17978
17979 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17980 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17981 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17982 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17983 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17984 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17985 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17986 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17987 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17988 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17989 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17990 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17991
17992 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17993 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17994 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17995 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17996 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17997 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17998 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17999 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18000 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
18001 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
18002 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
18003 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
18004
18005 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
18006 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
18007 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
18008 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
18009 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
18010 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18011 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18012 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18013 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
18014 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
18015 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
18016 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
18017
18018 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
18019 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
18020 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
18021 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
18022 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
18023 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18024 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18025 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18026 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
18027 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
18028 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
18029 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
18030
18031 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
18032 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
18033 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
18034 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
18035 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
18036 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18037 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18038 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18039 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
18040 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
18041 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
18042 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
18043
18044 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
18045 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
18046 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
18047 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
18048 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
18049 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18050 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18051 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18052 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
18053 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
18054 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
18055 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
18056
18057 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
18058 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
18059 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
18060 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
18061 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
18062 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18063 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18064 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18065 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
18066 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
18067 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
18068 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
18069
18070 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
18071 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
18072 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
18073 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
18074 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
18075 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18076 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18077 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18078 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
18079 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
18080 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
18081 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
18082
18083 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
18084 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
18085 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
18086 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
18087 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
18088 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18089 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18090 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18091 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
18092 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
18093 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
18094 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
18095
18096 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
18097 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
18098 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
18099 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
18100 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
18101 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18102 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18103 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18104 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
18105 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
18106 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
18107 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
18108
18109 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
18110 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
18111 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
18112 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
18113 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
18114 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18115 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18116 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18117 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
18118 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
18119 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
18120 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
18121
18122 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18123 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18124 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18125 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18126 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18127 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18128 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18129 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18130 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18131 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18132 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18133 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18134
18135 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18136 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18137 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18138 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18139 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18140 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18141 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18142 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18143 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18144 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18145 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18146 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18147
18148 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18149 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18150 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18151 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18152 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18153 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18154 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18155 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18156 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18157 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18158 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18159 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18160
18161 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
18162 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
18163 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
18164 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
18165
18166 cCL("flts", e000110, 2, (RF, RR), rn_rd),
18167 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
18168 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
18169 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
18170 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
18171 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
18172 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
18173 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
18174 cCL("flte", e080110, 2, (RF, RR), rn_rd),
18175 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
18176 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
18177 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 18178
c19d1205
ZW
18179 /* The implementation of the FIX instruction is broken on some
18180 assemblers, in that it accepts a precision specifier as well as a
18181 rounding specifier, despite the fact that this is meaningless.
18182 To be more compatible, we accept it as well, though of course it
18183 does not set any bits. */
21d799b5
NC
18184 cCE("fix", e100110, 2, (RR, RF), rd_rm),
18185 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
18186 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
18187 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
18188 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
18189 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
18190 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
18191 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
18192 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
18193 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
18194 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
18195 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
18196 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 18197
c19d1205 18198 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
18199#undef ARM_VARIANT
18200#define ARM_VARIANT & fpu_fpa_ext_v2
18201
21d799b5
NC
18202 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18203 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18204 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18205 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18206 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18207 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 18208
c921be7d
NC
18209#undef ARM_VARIANT
18210#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
18211
c19d1205 18212 /* Moves and type conversions. */
21d799b5
NC
18213 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
18214 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
18215 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
18216 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
18217 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
18218 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
18219 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
18220 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
18221 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
18222 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18223 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
18224 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18225 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
18226 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
18227
18228 /* Memory operations. */
21d799b5
NC
18229 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
18230 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
18231 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18232 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18233 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18234 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18235 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18236 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18237 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18238 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18239 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18240 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18241 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18242 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18243 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18244 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18245 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18246 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 18247
c19d1205 18248 /* Monadic operations. */
21d799b5
NC
18249 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
18250 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
18251 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
18252
18253 /* Dyadic operations. */
21d799b5
NC
18254 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18255 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18256 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18257 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18258 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18259 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18260 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18261 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18262 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 18263
c19d1205 18264 /* Comparisons. */
21d799b5
NC
18265 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
18266 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
18267 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
18268 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 18269
62f3b8c8
PB
18270 /* Double precision load/store are still present on single precision
18271 implementations. */
18272 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
18273 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
18274 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18275 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18276 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18277 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18278 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18279 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18280 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18281 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 18282
c921be7d
NC
18283#undef ARM_VARIANT
18284#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
18285
c19d1205 18286 /* Moves and type conversions. */
21d799b5
NC
18287 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18288 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18289 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18290 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
18291 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
18292 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
18293 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
18294 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18295 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
18296 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18297 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18298 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18299 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 18300
c19d1205 18301 /* Monadic operations. */
21d799b5
NC
18302 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18303 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18304 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
18305
18306 /* Dyadic operations. */
21d799b5
NC
18307 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18308 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18309 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18310 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18311 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18312 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18313 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18314 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18315 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 18316
c19d1205 18317 /* Comparisons. */
21d799b5
NC
18318 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18319 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
18320 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18321 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 18322
c921be7d
NC
18323#undef ARM_VARIANT
18324#define ARM_VARIANT & fpu_vfp_ext_v2
18325
21d799b5
NC
18326 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
18327 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
18328 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
18329 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 18330
037e8744
JB
18331/* Instructions which may belong to either the Neon or VFP instruction sets.
18332 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
18333#undef ARM_VARIANT
18334#define ARM_VARIANT & fpu_vfp_ext_v1xd
18335#undef THUMB_VARIANT
18336#define THUMB_VARIANT & fpu_vfp_ext_v1xd
18337
037e8744
JB
18338 /* These mnemonics are unique to VFP. */
18339 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
18340 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
18341 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18342 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18343 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18344 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
18345 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
18346 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
18347 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
18348 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
18349
18350 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
18351 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
18352 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
18353 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 18354
21d799b5
NC
18355 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
18356 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
18357
18358 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18359 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18360
55881a11
MGD
18361 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18362 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18363 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18364 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18365 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18366 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
18367 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
18368 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 18369
5f1af56b 18370 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 18371 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
21d799b5
NC
18372 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
18373 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 18374
037e8744
JB
18375
18376 /* NOTE: All VMOV encoding is special-cased! */
18377 NCE(vmov, 0, 1, (VMOV), neon_mov),
18378 NCE(vmovq, 0, 1, (VMOV), neon_mov),
18379
c921be7d
NC
18380#undef THUMB_VARIANT
18381#define THUMB_VARIANT & fpu_neon_ext_v1
18382#undef ARM_VARIANT
18383#define ARM_VARIANT & fpu_neon_ext_v1
18384
5287ad62
JB
18385 /* Data processing with three registers of the same length. */
18386 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
18387 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
18388 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
18389 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18390 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18391 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18392 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18393 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18394 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18395 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
18396 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18397 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
18398 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18399 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
18400 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18401 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
18402 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18403 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
18404 /* If not immediate, fall back to neon_dyadic_i64_su.
18405 shl_imm should accept I8 I16 I32 I64,
18406 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
18407 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
18408 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
18409 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
18410 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 18411 /* Logic ops, types optional & ignored. */
4316f0d2
DG
18412 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18413 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18414 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18415 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18416 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18417 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18418 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18419 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18420 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
18421 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
18422 /* Bitfield ops, untyped. */
18423 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18424 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18425 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18426 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18427 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18428 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18429 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
18430 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18431 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18432 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18433 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18434 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18435 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
18436 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
18437 back to neon_dyadic_if_su. */
21d799b5
NC
18438 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18439 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18440 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18441 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18442 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18443 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
18444 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18445 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 18446 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
18447 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
18448 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 18449 /* As above, D registers only. */
21d799b5
NC
18450 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
18451 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 18452 /* Int and float variants, signedness unimportant. */
21d799b5
NC
18453 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18454 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18455 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 18456 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
18457 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
18458 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
18459 /* vtst takes sizes 8, 16, 32. */
18460 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
18461 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
18462 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 18463 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 18464 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
18465 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18466 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
18467 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18468 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
18469 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18470 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
18471 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18472 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
18473 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18474 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
18475 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18476 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
18477 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18478 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18479 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18480 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18481
18482 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 18483 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
18484 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
18485
18486 /* Data processing with two registers and a shift amount. */
18487 /* Right shifts, and variants with rounding.
18488 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
18489 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18490 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18491 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18492 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18493 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18494 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18495 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18496 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18497 /* Shift and insert. Sizes accepted 8 16 32 64. */
18498 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
18499 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
18500 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
18501 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
18502 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
18503 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
18504 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
18505 /* Right shift immediate, saturating & narrowing, with rounding variants.
18506 Types accepted S16 S32 S64 U16 U32 U64. */
18507 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18508 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18509 /* As above, unsigned. Types accepted S16 S32 S64. */
18510 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18511 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18512 /* Right shift narrowing. Types accepted I16 I32 I64. */
18513 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18514 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18515 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 18516 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 18517 /* CVT with optional immediate for fixed-point variant. */
21d799b5 18518 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 18519
4316f0d2
DG
18520 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
18521 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
18522
18523 /* Data processing, three registers of different lengths. */
18524 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
18525 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
18526 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
18527 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
18528 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
18529 /* If not scalar, fall back to neon_dyadic_long.
18530 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
18531 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
18532 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
18533 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
18534 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18535 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18536 /* Dyadic, narrowing insns. Types I16 I32 I64. */
18537 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18538 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18539 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18540 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18541 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
18542 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18543 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18544 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
18545 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
18546 S16 S32 U16 U32. */
21d799b5 18547 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
18548
18549 /* Extract. Size 8. */
3b8d421e
PB
18550 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
18551 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
18552
18553 /* Two registers, miscellaneous. */
18554 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
18555 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
18556 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
18557 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
18558 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
18559 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
18560 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
18561 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
18562 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
18563 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
18564 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
18565 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
18566 /* VMOVN. Types I16 I32 I64. */
21d799b5 18567 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 18568 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 18569 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 18570 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 18571 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
18572 /* VZIP / VUZP. Sizes 8 16 32. */
18573 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
18574 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
18575 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
18576 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
18577 /* VQABS / VQNEG. Types S8 S16 S32. */
18578 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18579 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
18580 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18581 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
18582 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
18583 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
18584 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
18585 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
18586 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
18587 /* Reciprocal estimates. Types U32 F32. */
18588 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
18589 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
18590 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
18591 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
18592 /* VCLS. Types S8 S16 S32. */
18593 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
18594 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
18595 /* VCLZ. Types I8 I16 I32. */
18596 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
18597 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
18598 /* VCNT. Size 8. */
18599 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
18600 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
18601 /* Two address, untyped. */
18602 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
18603 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
18604 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
18605 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
18606 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
18607
18608 /* Table lookup. Size 8. */
18609 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18610 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18611
c921be7d
NC
18612#undef THUMB_VARIANT
18613#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
18614#undef ARM_VARIANT
18615#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
18616
5287ad62 18617 /* Neon element/structure load/store. */
21d799b5
NC
18618 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18619 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18620 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18621 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18622 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18623 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18624 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18625 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 18626
c921be7d 18627#undef THUMB_VARIANT
62f3b8c8
PB
18628#define THUMB_VARIANT &fpu_vfp_ext_v3xd
18629#undef ARM_VARIANT
18630#define ARM_VARIANT &fpu_vfp_ext_v3xd
18631 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
18632 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18633 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18634 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18635 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18636 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18637 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18638 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18639 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18640
18641#undef THUMB_VARIANT
c921be7d
NC
18642#define THUMB_VARIANT & fpu_vfp_ext_v3
18643#undef ARM_VARIANT
18644#define ARM_VARIANT & fpu_vfp_ext_v3
18645
21d799b5 18646 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 18647 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18648 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18649 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18650 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18651 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18652 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18653 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18654 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 18655
62f3b8c8
PB
18656#undef ARM_VARIANT
18657#define ARM_VARIANT &fpu_vfp_ext_fma
18658#undef THUMB_VARIANT
18659#define THUMB_VARIANT &fpu_vfp_ext_fma
18660 /* Mnemonics shared by Neon and VFP. These are included in the
18661 VFP FMA variant; NEON and VFP FMA always includes the NEON
18662 FMA instructions. */
18663 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18664 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18665 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
18666 the v form should always be used. */
18667 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18668 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18669 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18670 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18671 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18672 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18673
5287ad62 18674#undef THUMB_VARIANT
c921be7d
NC
18675#undef ARM_VARIANT
18676#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
18677
21d799b5
NC
18678 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18679 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18680 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18681 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18682 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18683 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18684 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
18685 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 18686
c921be7d
NC
18687#undef ARM_VARIANT
18688#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
18689
21d799b5
NC
18690 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
18691 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
18692 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
18693 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
18694 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
18695 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
18696 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
18697 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
18698 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
18699 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18700 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18701 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18702 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18703 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18704 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18705 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18706 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18707 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18708 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
18709 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
18710 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18711 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18712 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18713 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18714 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18715 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18716 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
18717 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
18718 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
18719 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
18720 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
18721 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
18722 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
18723 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
18724 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
18725 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
18726 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
18727 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18728 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18729 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18730 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18731 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18732 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18733 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18734 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18735 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18736 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
18737 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18738 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18739 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18740 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18741 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18742 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18743 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18744 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18745 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18746 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18747 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18748 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18749 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18750 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18751 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18752 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18753 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18754 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18755 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18756 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18757 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18758 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18759 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18760 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18761 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18762 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18763 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18764 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18765 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18766 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18767 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18768 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18769 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18770 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18771 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18772 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18773 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18774 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18775 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18776 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18777 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18778 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
18779 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18780 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18781 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18782 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18783 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18784 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18785 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18786 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18787 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18788 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18789 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18790 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18791 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18792 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18793 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18794 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18795 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18796 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18797 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18798 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18799 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18800 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
18801 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18802 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18803 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18804 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18805 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18806 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18807 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18808 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18809 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18810 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18811 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18812 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18813 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18814 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18815 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18816 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18817 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18818 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18819 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18820 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18821 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18822 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18823 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18824 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18825 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18826 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18827 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18828 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18829 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18830 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18831 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18832 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18833 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18834 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18835 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18836 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18837 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18838 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18839 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18840 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18841 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18842 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18843 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18844 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18845 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18846 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18847 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18848 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18849 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18850 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18851 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 18852
c921be7d
NC
18853#undef ARM_VARIANT
18854#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18855
21d799b5
NC
18856 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18857 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18858 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18859 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18860 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18861 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18862 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18863 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18864 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18865 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18866 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18867 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18868 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18869 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18870 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18871 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18872 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18873 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18874 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18875 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18876 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18877 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18878 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18879 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18880 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18881 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18882 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18883 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18884 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18885 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18886 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18887 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18888 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18889 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18890 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18891 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18892 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18893 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18894 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18895 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18896 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18897 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18898 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18899 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18900 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18901 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18902 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18903 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18904 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18905 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18906 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18907 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18908 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18909 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18910 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18911 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18912 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 18913
c921be7d
NC
18914#undef ARM_VARIANT
18915#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18916
21d799b5
NC
18917 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18918 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18919 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18920 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18921 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18922 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18923 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18924 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18925 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18926 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18927 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18928 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18929 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18930 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18931 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18932 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18933 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18934 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18935 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18936 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18937 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18938 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18939 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18940 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18941 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18942 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18943 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18944 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18945 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18946 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18947 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18948 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18949 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18950 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18951 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18952 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18953 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18954 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18955 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18956 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18957 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18958 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18959 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18960 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18961 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18962 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18963 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18964 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18965 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18966 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18967 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18968 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18969 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18970 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18971 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18972 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18973 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18974 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18975 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18976 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18977 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18978 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18979 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18980 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18981 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18982 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18983 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18984 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18985 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18986 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18987 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18988 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18989 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18990 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18991 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18992 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
18993};
18994#undef ARM_VARIANT
18995#undef THUMB_VARIANT
18996#undef TCE
18997#undef TCM
18998#undef TUE
18999#undef TUF
19000#undef TCC
8f06b2d8 19001#undef cCE
e3cb604e
PB
19002#undef cCL
19003#undef C3E
c19d1205
ZW
19004#undef CE
19005#undef CM
19006#undef UE
19007#undef UF
19008#undef UT
5287ad62
JB
19009#undef NUF
19010#undef nUF
19011#undef NCE
19012#undef nCE
c19d1205
ZW
19013#undef OPS0
19014#undef OPS1
19015#undef OPS2
19016#undef OPS3
19017#undef OPS4
19018#undef OPS5
19019#undef OPS6
19020#undef do_0
19021\f
19022/* MD interface: bits in the object file. */
bfae80f2 19023
c19d1205
ZW
19024/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
19025 for use in the a.out file, and stores them in the array pointed to by buf.
19026 This knows about the endian-ness of the target machine and does
19027 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
19028 2 (short) and 4 (long) Floating numbers are put out as a series of
19029 LITTLENUMS (shorts, here at least). */
b99bd4ef 19030
c19d1205
ZW
19031void
19032md_number_to_chars (char * buf, valueT val, int n)
19033{
19034 if (target_big_endian)
19035 number_to_chars_bigendian (buf, val, n);
19036 else
19037 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
19038}
19039
c19d1205
ZW
19040static valueT
19041md_chars_to_number (char * buf, int n)
bfae80f2 19042{
c19d1205
ZW
19043 valueT result = 0;
19044 unsigned char * where = (unsigned char *) buf;
bfae80f2 19045
c19d1205 19046 if (target_big_endian)
b99bd4ef 19047 {
c19d1205
ZW
19048 while (n--)
19049 {
19050 result <<= 8;
19051 result |= (*where++ & 255);
19052 }
b99bd4ef 19053 }
c19d1205 19054 else
b99bd4ef 19055 {
c19d1205
ZW
19056 while (n--)
19057 {
19058 result <<= 8;
19059 result |= (where[n] & 255);
19060 }
bfae80f2 19061 }
b99bd4ef 19062
c19d1205 19063 return result;
bfae80f2 19064}
b99bd4ef 19065
c19d1205 19066/* MD interface: Sections. */
b99bd4ef 19067
fa94de6b
RM
19068/* Calculate the maximum variable size (i.e., excluding fr_fix)
19069 that an rs_machine_dependent frag may reach. */
19070
19071unsigned int
19072arm_frag_max_var (fragS *fragp)
19073{
19074 /* We only use rs_machine_dependent for variable-size Thumb instructions,
19075 which are either THUMB_SIZE (2) or INSN_SIZE (4).
19076
19077 Note that we generate relaxable instructions even for cases that don't
19078 really need it, like an immediate that's a trivial constant. So we're
19079 overestimating the instruction size for some of those cases. Rather
19080 than putting more intelligence here, it would probably be better to
19081 avoid generating a relaxation frag in the first place when it can be
19082 determined up front that a short instruction will suffice. */
19083
19084 gas_assert (fragp->fr_type == rs_machine_dependent);
19085 return INSN_SIZE;
19086}
19087
0110f2b8
PB
19088/* Estimate the size of a frag before relaxing. Assume everything fits in
19089 2 bytes. */
19090
c19d1205 19091int
0110f2b8 19092md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
19093 segT segtype ATTRIBUTE_UNUSED)
19094{
0110f2b8
PB
19095 fragp->fr_var = 2;
19096 return 2;
19097}
19098
19099/* Convert a machine dependent frag. */
19100
19101void
19102md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
19103{
19104 unsigned long insn;
19105 unsigned long old_op;
19106 char *buf;
19107 expressionS exp;
19108 fixS *fixp;
19109 int reloc_type;
19110 int pc_rel;
19111 int opcode;
19112
19113 buf = fragp->fr_literal + fragp->fr_fix;
19114
19115 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
19116 if (fragp->fr_symbol)
19117 {
0110f2b8
PB
19118 exp.X_op = O_symbol;
19119 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
19120 }
19121 else
19122 {
0110f2b8 19123 exp.X_op = O_constant;
5f4273c7 19124 }
0110f2b8
PB
19125 exp.X_add_number = fragp->fr_offset;
19126 opcode = fragp->fr_subtype;
19127 switch (opcode)
19128 {
19129 case T_MNEM_ldr_pc:
19130 case T_MNEM_ldr_pc2:
19131 case T_MNEM_ldr_sp:
19132 case T_MNEM_str_sp:
19133 case T_MNEM_ldr:
19134 case T_MNEM_ldrb:
19135 case T_MNEM_ldrh:
19136 case T_MNEM_str:
19137 case T_MNEM_strb:
19138 case T_MNEM_strh:
19139 if (fragp->fr_var == 4)
19140 {
5f4273c7 19141 insn = THUMB_OP32 (opcode);
0110f2b8
PB
19142 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
19143 {
19144 insn |= (old_op & 0x700) << 4;
19145 }
19146 else
19147 {
19148 insn |= (old_op & 7) << 12;
19149 insn |= (old_op & 0x38) << 13;
19150 }
19151 insn |= 0x00000c00;
19152 put_thumb32_insn (buf, insn);
19153 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
19154 }
19155 else
19156 {
19157 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
19158 }
19159 pc_rel = (opcode == T_MNEM_ldr_pc2);
19160 break;
19161 case T_MNEM_adr:
19162 if (fragp->fr_var == 4)
19163 {
19164 insn = THUMB_OP32 (opcode);
19165 insn |= (old_op & 0xf0) << 4;
19166 put_thumb32_insn (buf, insn);
19167 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
19168 }
19169 else
19170 {
19171 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19172 exp.X_add_number -= 4;
19173 }
19174 pc_rel = 1;
19175 break;
19176 case T_MNEM_mov:
19177 case T_MNEM_movs:
19178 case T_MNEM_cmp:
19179 case T_MNEM_cmn:
19180 if (fragp->fr_var == 4)
19181 {
19182 int r0off = (opcode == T_MNEM_mov
19183 || opcode == T_MNEM_movs) ? 0 : 8;
19184 insn = THUMB_OP32 (opcode);
19185 insn = (insn & 0xe1ffffff) | 0x10000000;
19186 insn |= (old_op & 0x700) << r0off;
19187 put_thumb32_insn (buf, insn);
19188 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
19189 }
19190 else
19191 {
19192 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
19193 }
19194 pc_rel = 0;
19195 break;
19196 case T_MNEM_b:
19197 if (fragp->fr_var == 4)
19198 {
19199 insn = THUMB_OP32(opcode);
19200 put_thumb32_insn (buf, insn);
19201 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
19202 }
19203 else
19204 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
19205 pc_rel = 1;
19206 break;
19207 case T_MNEM_bcond:
19208 if (fragp->fr_var == 4)
19209 {
19210 insn = THUMB_OP32(opcode);
19211 insn |= (old_op & 0xf00) << 14;
19212 put_thumb32_insn (buf, insn);
19213 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
19214 }
19215 else
19216 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
19217 pc_rel = 1;
19218 break;
19219 case T_MNEM_add_sp:
19220 case T_MNEM_add_pc:
19221 case T_MNEM_inc_sp:
19222 case T_MNEM_dec_sp:
19223 if (fragp->fr_var == 4)
19224 {
19225 /* ??? Choose between add and addw. */
19226 insn = THUMB_OP32 (opcode);
19227 insn |= (old_op & 0xf0) << 4;
19228 put_thumb32_insn (buf, insn);
16805f35
PB
19229 if (opcode == T_MNEM_add_pc)
19230 reloc_type = BFD_RELOC_ARM_T32_IMM12;
19231 else
19232 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
19233 }
19234 else
19235 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19236 pc_rel = 0;
19237 break;
19238
19239 case T_MNEM_addi:
19240 case T_MNEM_addis:
19241 case T_MNEM_subi:
19242 case T_MNEM_subis:
19243 if (fragp->fr_var == 4)
19244 {
19245 insn = THUMB_OP32 (opcode);
19246 insn |= (old_op & 0xf0) << 4;
19247 insn |= (old_op & 0xf) << 16;
19248 put_thumb32_insn (buf, insn);
16805f35
PB
19249 if (insn & (1 << 20))
19250 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
19251 else
19252 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
19253 }
19254 else
19255 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19256 pc_rel = 0;
19257 break;
19258 default:
5f4273c7 19259 abort ();
0110f2b8
PB
19260 }
19261 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 19262 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
19263 fixp->fx_file = fragp->fr_file;
19264 fixp->fx_line = fragp->fr_line;
19265 fragp->fr_fix += fragp->fr_var;
19266}
19267
19268/* Return the size of a relaxable immediate operand instruction.
19269 SHIFT and SIZE specify the form of the allowable immediate. */
19270static int
19271relax_immediate (fragS *fragp, int size, int shift)
19272{
19273 offsetT offset;
19274 offsetT mask;
19275 offsetT low;
19276
19277 /* ??? Should be able to do better than this. */
19278 if (fragp->fr_symbol)
19279 return 4;
19280
19281 low = (1 << shift) - 1;
19282 mask = (1 << (shift + size)) - (1 << shift);
19283 offset = fragp->fr_offset;
19284 /* Force misaligned offsets to 32-bit variant. */
19285 if (offset & low)
5e77afaa 19286 return 4;
0110f2b8
PB
19287 if (offset & ~mask)
19288 return 4;
19289 return 2;
19290}
19291
5e77afaa
PB
19292/* Get the address of a symbol during relaxation. */
19293static addressT
5f4273c7 19294relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
19295{
19296 fragS *sym_frag;
19297 addressT addr;
19298 symbolS *sym;
19299
19300 sym = fragp->fr_symbol;
19301 sym_frag = symbol_get_frag (sym);
19302 know (S_GET_SEGMENT (sym) != absolute_section
19303 || sym_frag == &zero_address_frag);
19304 addr = S_GET_VALUE (sym) + fragp->fr_offset;
19305
19306 /* If frag has yet to be reached on this pass, assume it will
19307 move by STRETCH just as we did. If this is not so, it will
19308 be because some frag between grows, and that will force
19309 another pass. */
19310
19311 if (stretch != 0
19312 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
19313 {
19314 fragS *f;
19315
19316 /* Adjust stretch for any alignment frag. Note that if have
19317 been expanding the earlier code, the symbol may be
19318 defined in what appears to be an earlier frag. FIXME:
19319 This doesn't handle the fr_subtype field, which specifies
19320 a maximum number of bytes to skip when doing an
19321 alignment. */
19322 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
19323 {
19324 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
19325 {
19326 if (stretch < 0)
19327 stretch = - ((- stretch)
19328 & ~ ((1 << (int) f->fr_offset) - 1));
19329 else
19330 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
19331 if (stretch == 0)
19332 break;
19333 }
19334 }
19335 if (f != NULL)
19336 addr += stretch;
19337 }
5e77afaa
PB
19338
19339 return addr;
19340}
19341
0110f2b8
PB
19342/* Return the size of a relaxable adr pseudo-instruction or PC-relative
19343 load. */
19344static int
5e77afaa 19345relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
19346{
19347 addressT addr;
19348 offsetT val;
19349
19350 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
19351 if (fragp->fr_symbol == NULL
19352 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
19353 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19354 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
19355 return 4;
19356
5f4273c7 19357 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
19358 addr = fragp->fr_address + fragp->fr_fix;
19359 addr = (addr + 4) & ~3;
5e77afaa 19360 /* Force misaligned targets to 32-bit variant. */
0110f2b8 19361 if (val & 3)
5e77afaa 19362 return 4;
0110f2b8
PB
19363 val -= addr;
19364 if (val < 0 || val > 1020)
19365 return 4;
19366 return 2;
19367}
19368
19369/* Return the size of a relaxable add/sub immediate instruction. */
19370static int
19371relax_addsub (fragS *fragp, asection *sec)
19372{
19373 char *buf;
19374 int op;
19375
19376 buf = fragp->fr_literal + fragp->fr_fix;
19377 op = bfd_get_16(sec->owner, buf);
19378 if ((op & 0xf) == ((op >> 4) & 0xf))
19379 return relax_immediate (fragp, 8, 0);
19380 else
19381 return relax_immediate (fragp, 3, 0);
19382}
19383
19384
19385/* Return the size of a relaxable branch instruction. BITS is the
19386 size of the offset field in the narrow instruction. */
19387
19388static int
5e77afaa 19389relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
19390{
19391 addressT addr;
19392 offsetT val;
19393 offsetT limit;
19394
19395 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 19396 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
19397 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19398 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
19399 return 4;
19400
267bf995
RR
19401#ifdef OBJ_ELF
19402 if (S_IS_DEFINED (fragp->fr_symbol)
19403 && ARM_IS_FUNC (fragp->fr_symbol))
19404 return 4;
0d9b4b55
NC
19405
19406 /* PR 12532. Global symbols with default visibility might
19407 be preempted, so do not relax relocations to them. */
19408 if ((ELF_ST_VISIBILITY (S_GET_OTHER (fragp->fr_symbol)) == STV_DEFAULT)
19409 && (! S_IS_LOCAL (fragp->fr_symbol)))
19410 return 4;
267bf995
RR
19411#endif
19412
5f4273c7 19413 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
19414 addr = fragp->fr_address + fragp->fr_fix + 4;
19415 val -= addr;
19416
19417 /* Offset is a signed value *2 */
19418 limit = 1 << bits;
19419 if (val >= limit || val < -limit)
19420 return 4;
19421 return 2;
19422}
19423
19424
19425/* Relax a machine dependent frag. This returns the amount by which
19426 the current size of the frag should change. */
19427
19428int
5e77afaa 19429arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
19430{
19431 int oldsize;
19432 int newsize;
19433
19434 oldsize = fragp->fr_var;
19435 switch (fragp->fr_subtype)
19436 {
19437 case T_MNEM_ldr_pc2:
5f4273c7 19438 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
19439 break;
19440 case T_MNEM_ldr_pc:
19441 case T_MNEM_ldr_sp:
19442 case T_MNEM_str_sp:
5f4273c7 19443 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
19444 break;
19445 case T_MNEM_ldr:
19446 case T_MNEM_str:
5f4273c7 19447 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
19448 break;
19449 case T_MNEM_ldrh:
19450 case T_MNEM_strh:
5f4273c7 19451 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
19452 break;
19453 case T_MNEM_ldrb:
19454 case T_MNEM_strb:
5f4273c7 19455 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
19456 break;
19457 case T_MNEM_adr:
5f4273c7 19458 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
19459 break;
19460 case T_MNEM_mov:
19461 case T_MNEM_movs:
19462 case T_MNEM_cmp:
19463 case T_MNEM_cmn:
5f4273c7 19464 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
19465 break;
19466 case T_MNEM_b:
5f4273c7 19467 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
19468 break;
19469 case T_MNEM_bcond:
5f4273c7 19470 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
19471 break;
19472 case T_MNEM_add_sp:
19473 case T_MNEM_add_pc:
19474 newsize = relax_immediate (fragp, 8, 2);
19475 break;
19476 case T_MNEM_inc_sp:
19477 case T_MNEM_dec_sp:
19478 newsize = relax_immediate (fragp, 7, 2);
19479 break;
19480 case T_MNEM_addi:
19481 case T_MNEM_addis:
19482 case T_MNEM_subi:
19483 case T_MNEM_subis:
19484 newsize = relax_addsub (fragp, sec);
19485 break;
19486 default:
5f4273c7 19487 abort ();
0110f2b8 19488 }
5e77afaa
PB
19489
19490 fragp->fr_var = newsize;
19491 /* Freeze wide instructions that are at or before the same location as
19492 in the previous pass. This avoids infinite loops.
5f4273c7
NC
19493 Don't freeze them unconditionally because targets may be artificially
19494 misaligned by the expansion of preceding frags. */
5e77afaa 19495 if (stretch <= 0 && newsize > 2)
0110f2b8 19496 {
0110f2b8 19497 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 19498 frag_wane (fragp);
0110f2b8 19499 }
5e77afaa 19500
0110f2b8 19501 return newsize - oldsize;
c19d1205 19502}
b99bd4ef 19503
c19d1205 19504/* Round up a section size to the appropriate boundary. */
b99bd4ef 19505
c19d1205
ZW
19506valueT
19507md_section_align (segT segment ATTRIBUTE_UNUSED,
19508 valueT size)
19509{
f0927246
NC
19510#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
19511 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
19512 {
19513 /* For a.out, force the section size to be aligned. If we don't do
19514 this, BFD will align it for us, but it will not write out the
19515 final bytes of the section. This may be a bug in BFD, but it is
19516 easier to fix it here since that is how the other a.out targets
19517 work. */
19518 int align;
19519
19520 align = bfd_get_section_alignment (stdoutput, segment);
19521 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
19522 }
c19d1205 19523#endif
f0927246
NC
19524
19525 return size;
bfae80f2 19526}
b99bd4ef 19527
c19d1205
ZW
19528/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
19529 of an rs_align_code fragment. */
19530
19531void
19532arm_handle_align (fragS * fragP)
bfae80f2 19533{
e7495e45
NS
19534 static char const arm_noop[2][2][4] =
19535 {
19536 { /* ARMv1 */
19537 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
19538 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
19539 },
19540 { /* ARMv6k */
19541 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
19542 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
19543 },
19544 };
19545 static char const thumb_noop[2][2][2] =
19546 {
19547 { /* Thumb-1 */
19548 {0xc0, 0x46}, /* LE */
19549 {0x46, 0xc0}, /* BE */
19550 },
19551 { /* Thumb-2 */
19552 {0x00, 0xbf}, /* LE */
19553 {0xbf, 0x00} /* BE */
19554 }
19555 };
19556 static char const wide_thumb_noop[2][4] =
19557 { /* Wide Thumb-2 */
19558 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
19559 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
19560 };
c921be7d 19561
e7495e45 19562 unsigned bytes, fix, noop_size;
c19d1205
ZW
19563 char * p;
19564 const char * noop;
e7495e45 19565 const char *narrow_noop = NULL;
cd000bff
DJ
19566#ifdef OBJ_ELF
19567 enum mstate state;
19568#endif
bfae80f2 19569
c19d1205 19570 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
19571 return;
19572
c19d1205
ZW
19573 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
19574 p = fragP->fr_literal + fragP->fr_fix;
19575 fix = 0;
bfae80f2 19576
c19d1205
ZW
19577 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
19578 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 19579
cd000bff 19580 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 19581
cd000bff 19582 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 19583 {
e7495e45
NS
19584 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
19585 {
19586 narrow_noop = thumb_noop[1][target_big_endian];
19587 noop = wide_thumb_noop[target_big_endian];
19588 }
c19d1205 19589 else
e7495e45
NS
19590 noop = thumb_noop[0][target_big_endian];
19591 noop_size = 2;
cd000bff
DJ
19592#ifdef OBJ_ELF
19593 state = MAP_THUMB;
19594#endif
7ed4c4c5
NC
19595 }
19596 else
19597 {
e7495e45
NS
19598 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
19599 [target_big_endian];
19600 noop_size = 4;
cd000bff
DJ
19601#ifdef OBJ_ELF
19602 state = MAP_ARM;
19603#endif
7ed4c4c5 19604 }
c921be7d 19605
e7495e45 19606 fragP->fr_var = noop_size;
c921be7d 19607
c19d1205 19608 if (bytes & (noop_size - 1))
7ed4c4c5 19609 {
c19d1205 19610 fix = bytes & (noop_size - 1);
cd000bff
DJ
19611#ifdef OBJ_ELF
19612 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
19613#endif
c19d1205
ZW
19614 memset (p, 0, fix);
19615 p += fix;
19616 bytes -= fix;
a737bd4d 19617 }
a737bd4d 19618
e7495e45
NS
19619 if (narrow_noop)
19620 {
19621 if (bytes & noop_size)
19622 {
19623 /* Insert a narrow noop. */
19624 memcpy (p, narrow_noop, noop_size);
19625 p += noop_size;
19626 bytes -= noop_size;
19627 fix += noop_size;
19628 }
19629
19630 /* Use wide noops for the remainder */
19631 noop_size = 4;
19632 }
19633
c19d1205 19634 while (bytes >= noop_size)
a737bd4d 19635 {
c19d1205
ZW
19636 memcpy (p, noop, noop_size);
19637 p += noop_size;
19638 bytes -= noop_size;
19639 fix += noop_size;
a737bd4d
NC
19640 }
19641
c19d1205 19642 fragP->fr_fix += fix;
a737bd4d
NC
19643}
19644
c19d1205
ZW
19645/* Called from md_do_align. Used to create an alignment
19646 frag in a code section. */
19647
19648void
19649arm_frag_align_code (int n, int max)
bfae80f2 19650{
c19d1205 19651 char * p;
7ed4c4c5 19652
c19d1205 19653 /* We assume that there will never be a requirement
6ec8e702 19654 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 19655 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
19656 {
19657 char err_msg[128];
19658
fa94de6b 19659 sprintf (err_msg,
6ec8e702
NC
19660 _("alignments greater than %d bytes not supported in .text sections."),
19661 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 19662 as_fatal ("%s", err_msg);
6ec8e702 19663 }
bfae80f2 19664
c19d1205
ZW
19665 p = frag_var (rs_align_code,
19666 MAX_MEM_FOR_RS_ALIGN_CODE,
19667 1,
19668 (relax_substateT) max,
19669 (symbolS *) NULL,
19670 (offsetT) n,
19671 (char *) NULL);
19672 *p = 0;
19673}
bfae80f2 19674
8dc2430f
NC
19675/* Perform target specific initialisation of a frag.
19676 Note - despite the name this initialisation is not done when the frag
19677 is created, but only when its type is assigned. A frag can be created
19678 and used a long time before its type is set, so beware of assuming that
19679 this initialisationis performed first. */
bfae80f2 19680
cd000bff
DJ
19681#ifndef OBJ_ELF
19682void
19683arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
19684{
19685 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 19686 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
19687}
19688
19689#else /* OBJ_ELF is defined. */
c19d1205 19690void
cd000bff 19691arm_init_frag (fragS * fragP, int max_chars)
c19d1205 19692{
8dc2430f
NC
19693 /* If the current ARM vs THUMB mode has not already
19694 been recorded into this frag then do so now. */
cd000bff
DJ
19695 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
19696 {
19697 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19698
19699 /* Record a mapping symbol for alignment frags. We will delete this
19700 later if the alignment ends up empty. */
19701 switch (fragP->fr_type)
19702 {
19703 case rs_align:
19704 case rs_align_test:
19705 case rs_fill:
19706 mapping_state_2 (MAP_DATA, max_chars);
19707 break;
19708 case rs_align_code:
19709 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
19710 break;
19711 default:
19712 break;
19713 }
19714 }
bfae80f2
RE
19715}
19716
c19d1205
ZW
19717/* When we change sections we need to issue a new mapping symbol. */
19718
19719void
19720arm_elf_change_section (void)
bfae80f2 19721{
c19d1205
ZW
19722 /* Link an unlinked unwind index table section to the .text section. */
19723 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
19724 && elf_linked_to_section (now_seg) == NULL)
19725 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
19726}
19727
c19d1205
ZW
19728int
19729arm_elf_section_type (const char * str, size_t len)
e45d0630 19730{
c19d1205
ZW
19731 if (len == 5 && strncmp (str, "exidx", 5) == 0)
19732 return SHT_ARM_EXIDX;
e45d0630 19733
c19d1205
ZW
19734 return -1;
19735}
19736\f
19737/* Code to deal with unwinding tables. */
e45d0630 19738
c19d1205 19739static void add_unwind_adjustsp (offsetT);
e45d0630 19740
5f4273c7 19741/* Generate any deferred unwind frame offset. */
e45d0630 19742
bfae80f2 19743static void
c19d1205 19744flush_pending_unwind (void)
bfae80f2 19745{
c19d1205 19746 offsetT offset;
bfae80f2 19747
c19d1205
ZW
19748 offset = unwind.pending_offset;
19749 unwind.pending_offset = 0;
19750 if (offset != 0)
19751 add_unwind_adjustsp (offset);
bfae80f2
RE
19752}
19753
c19d1205
ZW
19754/* Add an opcode to this list for this function. Two-byte opcodes should
19755 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
19756 order. */
19757
bfae80f2 19758static void
c19d1205 19759add_unwind_opcode (valueT op, int length)
bfae80f2 19760{
c19d1205
ZW
19761 /* Add any deferred stack adjustment. */
19762 if (unwind.pending_offset)
19763 flush_pending_unwind ();
bfae80f2 19764
c19d1205 19765 unwind.sp_restored = 0;
bfae80f2 19766
c19d1205 19767 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 19768 {
c19d1205
ZW
19769 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
19770 if (unwind.opcodes)
21d799b5
NC
19771 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
19772 unwind.opcode_alloc);
c19d1205 19773 else
21d799b5 19774 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 19775 }
c19d1205 19776 while (length > 0)
bfae80f2 19777 {
c19d1205
ZW
19778 length--;
19779 unwind.opcodes[unwind.opcode_count] = op & 0xff;
19780 op >>= 8;
19781 unwind.opcode_count++;
bfae80f2 19782 }
bfae80f2
RE
19783}
19784
c19d1205
ZW
19785/* Add unwind opcodes to adjust the stack pointer. */
19786
bfae80f2 19787static void
c19d1205 19788add_unwind_adjustsp (offsetT offset)
bfae80f2 19789{
c19d1205 19790 valueT op;
bfae80f2 19791
c19d1205 19792 if (offset > 0x200)
bfae80f2 19793 {
c19d1205
ZW
19794 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
19795 char bytes[5];
19796 int n;
19797 valueT o;
bfae80f2 19798
c19d1205
ZW
19799 /* Long form: 0xb2, uleb128. */
19800 /* This might not fit in a word so add the individual bytes,
19801 remembering the list is built in reverse order. */
19802 o = (valueT) ((offset - 0x204) >> 2);
19803 if (o == 0)
19804 add_unwind_opcode (0, 1);
bfae80f2 19805
c19d1205
ZW
19806 /* Calculate the uleb128 encoding of the offset. */
19807 n = 0;
19808 while (o)
19809 {
19810 bytes[n] = o & 0x7f;
19811 o >>= 7;
19812 if (o)
19813 bytes[n] |= 0x80;
19814 n++;
19815 }
19816 /* Add the insn. */
19817 for (; n; n--)
19818 add_unwind_opcode (bytes[n - 1], 1);
19819 add_unwind_opcode (0xb2, 1);
19820 }
19821 else if (offset > 0x100)
bfae80f2 19822 {
c19d1205
ZW
19823 /* Two short opcodes. */
19824 add_unwind_opcode (0x3f, 1);
19825 op = (offset - 0x104) >> 2;
19826 add_unwind_opcode (op, 1);
bfae80f2 19827 }
c19d1205
ZW
19828 else if (offset > 0)
19829 {
19830 /* Short opcode. */
19831 op = (offset - 4) >> 2;
19832 add_unwind_opcode (op, 1);
19833 }
19834 else if (offset < 0)
bfae80f2 19835 {
c19d1205
ZW
19836 offset = -offset;
19837 while (offset > 0x100)
bfae80f2 19838 {
c19d1205
ZW
19839 add_unwind_opcode (0x7f, 1);
19840 offset -= 0x100;
bfae80f2 19841 }
c19d1205
ZW
19842 op = ((offset - 4) >> 2) | 0x40;
19843 add_unwind_opcode (op, 1);
bfae80f2 19844 }
bfae80f2
RE
19845}
19846
c19d1205
ZW
19847/* Finish the list of unwind opcodes for this function. */
19848static void
19849finish_unwind_opcodes (void)
bfae80f2 19850{
c19d1205 19851 valueT op;
bfae80f2 19852
c19d1205 19853 if (unwind.fp_used)
bfae80f2 19854 {
708587a4 19855 /* Adjust sp as necessary. */
c19d1205
ZW
19856 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19857 flush_pending_unwind ();
bfae80f2 19858
c19d1205
ZW
19859 /* After restoring sp from the frame pointer. */
19860 op = 0x90 | unwind.fp_reg;
19861 add_unwind_opcode (op, 1);
19862 }
19863 else
19864 flush_pending_unwind ();
bfae80f2
RE
19865}
19866
bfae80f2 19867
c19d1205
ZW
19868/* Start an exception table entry. If idx is nonzero this is an index table
19869 entry. */
bfae80f2
RE
19870
19871static void
c19d1205 19872start_unwind_section (const segT text_seg, int idx)
bfae80f2 19873{
c19d1205
ZW
19874 const char * text_name;
19875 const char * prefix;
19876 const char * prefix_once;
19877 const char * group_name;
19878 size_t prefix_len;
19879 size_t text_len;
19880 char * sec_name;
19881 size_t sec_name_len;
19882 int type;
19883 int flags;
19884 int linkonce;
bfae80f2 19885
c19d1205 19886 if (idx)
bfae80f2 19887 {
c19d1205
ZW
19888 prefix = ELF_STRING_ARM_unwind;
19889 prefix_once = ELF_STRING_ARM_unwind_once;
19890 type = SHT_ARM_EXIDX;
bfae80f2 19891 }
c19d1205 19892 else
bfae80f2 19893 {
c19d1205
ZW
19894 prefix = ELF_STRING_ARM_unwind_info;
19895 prefix_once = ELF_STRING_ARM_unwind_info_once;
19896 type = SHT_PROGBITS;
bfae80f2
RE
19897 }
19898
c19d1205
ZW
19899 text_name = segment_name (text_seg);
19900 if (streq (text_name, ".text"))
19901 text_name = "";
19902
19903 if (strncmp (text_name, ".gnu.linkonce.t.",
19904 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 19905 {
c19d1205
ZW
19906 prefix = prefix_once;
19907 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
19908 }
19909
c19d1205
ZW
19910 prefix_len = strlen (prefix);
19911 text_len = strlen (text_name);
19912 sec_name_len = prefix_len + text_len;
21d799b5 19913 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
19914 memcpy (sec_name, prefix, prefix_len);
19915 memcpy (sec_name + prefix_len, text_name, text_len);
19916 sec_name[prefix_len + text_len] = '\0';
bfae80f2 19917
c19d1205
ZW
19918 flags = SHF_ALLOC;
19919 linkonce = 0;
19920 group_name = 0;
bfae80f2 19921
c19d1205
ZW
19922 /* Handle COMDAT group. */
19923 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 19924 {
c19d1205
ZW
19925 group_name = elf_group_name (text_seg);
19926 if (group_name == NULL)
19927 {
bd3ba5d1 19928 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
19929 segment_name (text_seg));
19930 ignore_rest_of_line ();
19931 return;
19932 }
19933 flags |= SHF_GROUP;
19934 linkonce = 1;
bfae80f2
RE
19935 }
19936
c19d1205 19937 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 19938
5f4273c7 19939 /* Set the section link for index tables. */
c19d1205
ZW
19940 if (idx)
19941 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
19942}
19943
bfae80f2 19944
c19d1205
ZW
19945/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19946 personality routine data. Returns zero, or the index table value for
19947 and inline entry. */
19948
19949static valueT
19950create_unwind_entry (int have_data)
bfae80f2 19951{
c19d1205
ZW
19952 int size;
19953 addressT where;
19954 char *ptr;
19955 /* The current word of data. */
19956 valueT data;
19957 /* The number of bytes left in this word. */
19958 int n;
bfae80f2 19959
c19d1205 19960 finish_unwind_opcodes ();
bfae80f2 19961
c19d1205
ZW
19962 /* Remember the current text section. */
19963 unwind.saved_seg = now_seg;
19964 unwind.saved_subseg = now_subseg;
bfae80f2 19965
c19d1205 19966 start_unwind_section (now_seg, 0);
bfae80f2 19967
c19d1205 19968 if (unwind.personality_routine == NULL)
bfae80f2 19969 {
c19d1205
ZW
19970 if (unwind.personality_index == -2)
19971 {
19972 if (have_data)
5f4273c7 19973 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
19974 return 1; /* EXIDX_CANTUNWIND. */
19975 }
bfae80f2 19976
c19d1205
ZW
19977 /* Use a default personality routine if none is specified. */
19978 if (unwind.personality_index == -1)
19979 {
19980 if (unwind.opcode_count > 3)
19981 unwind.personality_index = 1;
19982 else
19983 unwind.personality_index = 0;
19984 }
bfae80f2 19985
c19d1205
ZW
19986 /* Space for the personality routine entry. */
19987 if (unwind.personality_index == 0)
19988 {
19989 if (unwind.opcode_count > 3)
19990 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 19991
c19d1205
ZW
19992 if (!have_data)
19993 {
19994 /* All the data is inline in the index table. */
19995 data = 0x80;
19996 n = 3;
19997 while (unwind.opcode_count > 0)
19998 {
19999 unwind.opcode_count--;
20000 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
20001 n--;
20002 }
bfae80f2 20003
c19d1205
ZW
20004 /* Pad with "finish" opcodes. */
20005 while (n--)
20006 data = (data << 8) | 0xb0;
bfae80f2 20007
c19d1205
ZW
20008 return data;
20009 }
20010 size = 0;
20011 }
20012 else
20013 /* We get two opcodes "free" in the first word. */
20014 size = unwind.opcode_count - 2;
20015 }
20016 else
5011093d
NC
20017 {
20018 gas_assert (unwind.personality_index == -1);
20019
20020 /* An extra byte is required for the opcode count. */
20021 size = unwind.opcode_count + 1;
20022 }
bfae80f2 20023
c19d1205
ZW
20024 size = (size + 3) >> 2;
20025 if (size > 0xff)
20026 as_bad (_("too many unwind opcodes"));
bfae80f2 20027
c19d1205
ZW
20028 frag_align (2, 0, 0);
20029 record_alignment (now_seg, 2);
20030 unwind.table_entry = expr_build_dot ();
20031
20032 /* Allocate the table entry. */
20033 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
20034 /* PR 13449: Zero the table entries in case some of them are not used. */
20035 memset (ptr, 0, (size << 2) + 4);
c19d1205 20036 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 20037
c19d1205 20038 switch (unwind.personality_index)
bfae80f2 20039 {
c19d1205
ZW
20040 case -1:
20041 /* ??? Should this be a PLT generating relocation? */
20042 /* Custom personality routine. */
20043 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
20044 BFD_RELOC_ARM_PREL31);
bfae80f2 20045
c19d1205
ZW
20046 where += 4;
20047 ptr += 4;
bfae80f2 20048
c19d1205 20049 /* Set the first byte to the number of additional words. */
5011093d 20050 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
20051 n = 3;
20052 break;
bfae80f2 20053
c19d1205
ZW
20054 /* ABI defined personality routines. */
20055 case 0:
20056 /* Three opcodes bytes are packed into the first word. */
20057 data = 0x80;
20058 n = 3;
20059 break;
bfae80f2 20060
c19d1205
ZW
20061 case 1:
20062 case 2:
20063 /* The size and first two opcode bytes go in the first word. */
20064 data = ((0x80 + unwind.personality_index) << 8) | size;
20065 n = 2;
20066 break;
bfae80f2 20067
c19d1205
ZW
20068 default:
20069 /* Should never happen. */
20070 abort ();
20071 }
bfae80f2 20072
c19d1205
ZW
20073 /* Pack the opcodes into words (MSB first), reversing the list at the same
20074 time. */
20075 while (unwind.opcode_count > 0)
20076 {
20077 if (n == 0)
20078 {
20079 md_number_to_chars (ptr, data, 4);
20080 ptr += 4;
20081 n = 4;
20082 data = 0;
20083 }
20084 unwind.opcode_count--;
20085 n--;
20086 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
20087 }
20088
20089 /* Finish off the last word. */
20090 if (n < 4)
20091 {
20092 /* Pad with "finish" opcodes. */
20093 while (n--)
20094 data = (data << 8) | 0xb0;
20095
20096 md_number_to_chars (ptr, data, 4);
20097 }
20098
20099 if (!have_data)
20100 {
20101 /* Add an empty descriptor if there is no user-specified data. */
20102 ptr = frag_more (4);
20103 md_number_to_chars (ptr, 0, 4);
20104 }
20105
20106 return 0;
bfae80f2
RE
20107}
20108
f0927246
NC
20109
20110/* Initialize the DWARF-2 unwind information for this procedure. */
20111
20112void
20113tc_arm_frame_initial_instructions (void)
20114{
20115 cfi_add_CFA_def_cfa (REG_SP, 0);
20116}
20117#endif /* OBJ_ELF */
20118
c19d1205
ZW
20119/* Convert REGNAME to a DWARF-2 register number. */
20120
20121int
1df69f4f 20122tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 20123{
1df69f4f 20124 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
20125
20126 if (reg == FAIL)
20127 return -1;
20128
20129 return reg;
bfae80f2
RE
20130}
20131
f0927246 20132#ifdef TE_PE
c19d1205 20133void
f0927246 20134tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 20135{
91d6fa6a 20136 expressionS exp;
bfae80f2 20137
91d6fa6a
NC
20138 exp.X_op = O_secrel;
20139 exp.X_add_symbol = symbol;
20140 exp.X_add_number = 0;
20141 emit_expr (&exp, size);
f0927246
NC
20142}
20143#endif
bfae80f2 20144
c19d1205 20145/* MD interface: Symbol and relocation handling. */
bfae80f2 20146
2fc8bdac
ZW
20147/* Return the address within the segment that a PC-relative fixup is
20148 relative to. For ARM, PC-relative fixups applied to instructions
20149 are generally relative to the location of the fixup plus 8 bytes.
20150 Thumb branches are offset by 4, and Thumb loads relative to PC
20151 require special handling. */
bfae80f2 20152
c19d1205 20153long
2fc8bdac 20154md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 20155{
2fc8bdac
ZW
20156 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
20157
20158 /* If this is pc-relative and we are going to emit a relocation
20159 then we just want to put out any pipeline compensation that the linker
53baae48
NC
20160 will need. Otherwise we want to use the calculated base.
20161 For WinCE we skip the bias for externals as well, since this
20162 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 20163 if (fixP->fx_pcrel
2fc8bdac 20164 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
20165 || (arm_force_relocation (fixP)
20166#ifdef TE_WINCE
20167 && !S_IS_EXTERNAL (fixP->fx_addsy)
20168#endif
20169 )))
2fc8bdac 20170 base = 0;
bfae80f2 20171
267bf995 20172
c19d1205 20173 switch (fixP->fx_r_type)
bfae80f2 20174 {
2fc8bdac
ZW
20175 /* PC relative addressing on the Thumb is slightly odd as the
20176 bottom two bits of the PC are forced to zero for the
20177 calculation. This happens *after* application of the
20178 pipeline offset. However, Thumb adrl already adjusts for
20179 this, so we need not do it again. */
c19d1205 20180 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 20181 return base & ~3;
c19d1205
ZW
20182
20183 case BFD_RELOC_ARM_THUMB_OFFSET:
20184 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 20185 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 20186 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 20187 return (base + 4) & ~3;
c19d1205 20188
2fc8bdac
ZW
20189 /* Thumb branches are simply offset by +4. */
20190 case BFD_RELOC_THUMB_PCREL_BRANCH7:
20191 case BFD_RELOC_THUMB_PCREL_BRANCH9:
20192 case BFD_RELOC_THUMB_PCREL_BRANCH12:
20193 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 20194 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 20195 return base + 4;
bfae80f2 20196
267bf995 20197 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
20198 if (fixP->fx_addsy
20199 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20200 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20201 && ARM_IS_FUNC (fixP->fx_addsy)
20202 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20203 base = fixP->fx_where + fixP->fx_frag->fr_address;
20204 return base + 4;
20205
00adf2d4
JB
20206 /* BLX is like branches above, but forces the low two bits of PC to
20207 zero. */
486499d0
CL
20208 case BFD_RELOC_THUMB_PCREL_BLX:
20209 if (fixP->fx_addsy
20210 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20211 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20212 && THUMB_IS_FUNC (fixP->fx_addsy)
20213 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20214 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
20215 return (base + 4) & ~3;
20216
2fc8bdac
ZW
20217 /* ARM mode branches are offset by +8. However, the Windows CE
20218 loader expects the relocation not to take this into account. */
267bf995 20219 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
20220 if (fixP->fx_addsy
20221 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20222 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20223 && ARM_IS_FUNC (fixP->fx_addsy)
20224 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20225 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 20226 return base + 8;
267bf995 20227
486499d0
CL
20228 case BFD_RELOC_ARM_PCREL_CALL:
20229 if (fixP->fx_addsy
20230 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20231 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20232 && THUMB_IS_FUNC (fixP->fx_addsy)
20233 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20234 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 20235 return base + 8;
267bf995 20236
2fc8bdac 20237 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 20238 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 20239 case BFD_RELOC_ARM_PLT32:
c19d1205 20240#ifdef TE_WINCE
5f4273c7 20241 /* When handling fixups immediately, because we have already
53baae48
NC
20242 discovered the value of a symbol, or the address of the frag involved
20243 we must account for the offset by +8, as the OS loader will never see the reloc.
20244 see fixup_segment() in write.c
20245 The S_IS_EXTERNAL test handles the case of global symbols.
20246 Those need the calculated base, not just the pipe compensation the linker will need. */
20247 if (fixP->fx_pcrel
20248 && fixP->fx_addsy != NULL
20249 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20250 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
20251 return base + 8;
2fc8bdac 20252 return base;
c19d1205 20253#else
2fc8bdac 20254 return base + 8;
c19d1205 20255#endif
2fc8bdac 20256
267bf995 20257
2fc8bdac
ZW
20258 /* ARM mode loads relative to PC are also offset by +8. Unlike
20259 branches, the Windows CE loader *does* expect the relocation
20260 to take this into account. */
20261 case BFD_RELOC_ARM_OFFSET_IMM:
20262 case BFD_RELOC_ARM_OFFSET_IMM8:
20263 case BFD_RELOC_ARM_HWLITERAL:
20264 case BFD_RELOC_ARM_LITERAL:
20265 case BFD_RELOC_ARM_CP_OFF_IMM:
20266 return base + 8;
20267
20268
20269 /* Other PC-relative relocations are un-offset. */
20270 default:
20271 return base;
20272 }
bfae80f2
RE
20273}
20274
c19d1205
ZW
20275/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
20276 Otherwise we have no need to default values of symbols. */
20277
20278symbolS *
20279md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 20280{
c19d1205
ZW
20281#ifdef OBJ_ELF
20282 if (name[0] == '_' && name[1] == 'G'
20283 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
20284 {
20285 if (!GOT_symbol)
20286 {
20287 if (symbol_find (name))
bd3ba5d1 20288 as_bad (_("GOT already in the symbol table"));
bfae80f2 20289
c19d1205
ZW
20290 GOT_symbol = symbol_new (name, undefined_section,
20291 (valueT) 0, & zero_address_frag);
20292 }
bfae80f2 20293
c19d1205 20294 return GOT_symbol;
bfae80f2 20295 }
c19d1205 20296#endif
bfae80f2 20297
c921be7d 20298 return NULL;
bfae80f2
RE
20299}
20300
55cf6793 20301/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
20302 computed as two separate immediate values, added together. We
20303 already know that this value cannot be computed by just one ARM
20304 instruction. */
20305
20306static unsigned int
20307validate_immediate_twopart (unsigned int val,
20308 unsigned int * highpart)
bfae80f2 20309{
c19d1205
ZW
20310 unsigned int a;
20311 unsigned int i;
bfae80f2 20312
c19d1205
ZW
20313 for (i = 0; i < 32; i += 2)
20314 if (((a = rotate_left (val, i)) & 0xff) != 0)
20315 {
20316 if (a & 0xff00)
20317 {
20318 if (a & ~ 0xffff)
20319 continue;
20320 * highpart = (a >> 8) | ((i + 24) << 7);
20321 }
20322 else if (a & 0xff0000)
20323 {
20324 if (a & 0xff000000)
20325 continue;
20326 * highpart = (a >> 16) | ((i + 16) << 7);
20327 }
20328 else
20329 {
9c2799c2 20330 gas_assert (a & 0xff000000);
c19d1205
ZW
20331 * highpart = (a >> 24) | ((i + 8) << 7);
20332 }
bfae80f2 20333
c19d1205
ZW
20334 return (a & 0xff) | (i << 7);
20335 }
bfae80f2 20336
c19d1205 20337 return FAIL;
bfae80f2
RE
20338}
20339
c19d1205
ZW
20340static int
20341validate_offset_imm (unsigned int val, int hwse)
20342{
20343 if ((hwse && val > 255) || val > 4095)
20344 return FAIL;
20345 return val;
20346}
bfae80f2 20347
55cf6793 20348/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
20349 negative immediate constant by altering the instruction. A bit of
20350 a hack really.
20351 MOV <-> MVN
20352 AND <-> BIC
20353 ADC <-> SBC
20354 by inverting the second operand, and
20355 ADD <-> SUB
20356 CMP <-> CMN
20357 by negating the second operand. */
bfae80f2 20358
c19d1205
ZW
20359static int
20360negate_data_op (unsigned long * instruction,
20361 unsigned long value)
bfae80f2 20362{
c19d1205
ZW
20363 int op, new_inst;
20364 unsigned long negated, inverted;
bfae80f2 20365
c19d1205
ZW
20366 negated = encode_arm_immediate (-value);
20367 inverted = encode_arm_immediate (~value);
bfae80f2 20368
c19d1205
ZW
20369 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
20370 switch (op)
bfae80f2 20371 {
c19d1205
ZW
20372 /* First negates. */
20373 case OPCODE_SUB: /* ADD <-> SUB */
20374 new_inst = OPCODE_ADD;
20375 value = negated;
20376 break;
bfae80f2 20377
c19d1205
ZW
20378 case OPCODE_ADD:
20379 new_inst = OPCODE_SUB;
20380 value = negated;
20381 break;
bfae80f2 20382
c19d1205
ZW
20383 case OPCODE_CMP: /* CMP <-> CMN */
20384 new_inst = OPCODE_CMN;
20385 value = negated;
20386 break;
bfae80f2 20387
c19d1205
ZW
20388 case OPCODE_CMN:
20389 new_inst = OPCODE_CMP;
20390 value = negated;
20391 break;
bfae80f2 20392
c19d1205
ZW
20393 /* Now Inverted ops. */
20394 case OPCODE_MOV: /* MOV <-> MVN */
20395 new_inst = OPCODE_MVN;
20396 value = inverted;
20397 break;
bfae80f2 20398
c19d1205
ZW
20399 case OPCODE_MVN:
20400 new_inst = OPCODE_MOV;
20401 value = inverted;
20402 break;
bfae80f2 20403
c19d1205
ZW
20404 case OPCODE_AND: /* AND <-> BIC */
20405 new_inst = OPCODE_BIC;
20406 value = inverted;
20407 break;
bfae80f2 20408
c19d1205
ZW
20409 case OPCODE_BIC:
20410 new_inst = OPCODE_AND;
20411 value = inverted;
20412 break;
bfae80f2 20413
c19d1205
ZW
20414 case OPCODE_ADC: /* ADC <-> SBC */
20415 new_inst = OPCODE_SBC;
20416 value = inverted;
20417 break;
bfae80f2 20418
c19d1205
ZW
20419 case OPCODE_SBC:
20420 new_inst = OPCODE_ADC;
20421 value = inverted;
20422 break;
bfae80f2 20423
c19d1205
ZW
20424 /* We cannot do anything. */
20425 default:
20426 return FAIL;
b99bd4ef
NC
20427 }
20428
c19d1205
ZW
20429 if (value == (unsigned) FAIL)
20430 return FAIL;
20431
20432 *instruction &= OPCODE_MASK;
20433 *instruction |= new_inst << DATA_OP_SHIFT;
20434 return value;
b99bd4ef
NC
20435}
20436
ef8d22e6
PB
20437/* Like negate_data_op, but for Thumb-2. */
20438
20439static unsigned int
16dd5e42 20440thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
20441{
20442 int op, new_inst;
20443 int rd;
16dd5e42 20444 unsigned int negated, inverted;
ef8d22e6
PB
20445
20446 negated = encode_thumb32_immediate (-value);
20447 inverted = encode_thumb32_immediate (~value);
20448
20449 rd = (*instruction >> 8) & 0xf;
20450 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
20451 switch (op)
20452 {
20453 /* ADD <-> SUB. Includes CMP <-> CMN. */
20454 case T2_OPCODE_SUB:
20455 new_inst = T2_OPCODE_ADD;
20456 value = negated;
20457 break;
20458
20459 case T2_OPCODE_ADD:
20460 new_inst = T2_OPCODE_SUB;
20461 value = negated;
20462 break;
20463
20464 /* ORR <-> ORN. Includes MOV <-> MVN. */
20465 case T2_OPCODE_ORR:
20466 new_inst = T2_OPCODE_ORN;
20467 value = inverted;
20468 break;
20469
20470 case T2_OPCODE_ORN:
20471 new_inst = T2_OPCODE_ORR;
20472 value = inverted;
20473 break;
20474
20475 /* AND <-> BIC. TST has no inverted equivalent. */
20476 case T2_OPCODE_AND:
20477 new_inst = T2_OPCODE_BIC;
20478 if (rd == 15)
20479 value = FAIL;
20480 else
20481 value = inverted;
20482 break;
20483
20484 case T2_OPCODE_BIC:
20485 new_inst = T2_OPCODE_AND;
20486 value = inverted;
20487 break;
20488
20489 /* ADC <-> SBC */
20490 case T2_OPCODE_ADC:
20491 new_inst = T2_OPCODE_SBC;
20492 value = inverted;
20493 break;
20494
20495 case T2_OPCODE_SBC:
20496 new_inst = T2_OPCODE_ADC;
20497 value = inverted;
20498 break;
20499
20500 /* We cannot do anything. */
20501 default:
20502 return FAIL;
20503 }
20504
16dd5e42 20505 if (value == (unsigned int)FAIL)
ef8d22e6
PB
20506 return FAIL;
20507
20508 *instruction &= T2_OPCODE_MASK;
20509 *instruction |= new_inst << T2_DATA_OP_SHIFT;
20510 return value;
20511}
20512
8f06b2d8
PB
20513/* Read a 32-bit thumb instruction from buf. */
20514static unsigned long
20515get_thumb32_insn (char * buf)
20516{
20517 unsigned long insn;
20518 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
20519 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20520
20521 return insn;
20522}
20523
a8bc6c78
PB
20524
20525/* We usually want to set the low bit on the address of thumb function
20526 symbols. In particular .word foo - . should have the low bit set.
20527 Generic code tries to fold the difference of two symbols to
20528 a constant. Prevent this and force a relocation when the first symbols
20529 is a thumb function. */
c921be7d
NC
20530
20531bfd_boolean
a8bc6c78
PB
20532arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
20533{
20534 if (op == O_subtract
20535 && l->X_op == O_symbol
20536 && r->X_op == O_symbol
20537 && THUMB_IS_FUNC (l->X_add_symbol))
20538 {
20539 l->X_op = O_subtract;
20540 l->X_op_symbol = r->X_add_symbol;
20541 l->X_add_number -= r->X_add_number;
c921be7d 20542 return TRUE;
a8bc6c78 20543 }
c921be7d 20544
a8bc6c78 20545 /* Process as normal. */
c921be7d 20546 return FALSE;
a8bc6c78
PB
20547}
20548
4a42ebbc
RR
20549/* Encode Thumb2 unconditional branches and calls. The encoding
20550 for the 2 are identical for the immediate values. */
20551
20552static void
20553encode_thumb2_b_bl_offset (char * buf, offsetT value)
20554{
20555#define T2I1I2MASK ((1 << 13) | (1 << 11))
20556 offsetT newval;
20557 offsetT newval2;
20558 addressT S, I1, I2, lo, hi;
20559
20560 S = (value >> 24) & 0x01;
20561 I1 = (value >> 23) & 0x01;
20562 I2 = (value >> 22) & 0x01;
20563 hi = (value >> 12) & 0x3ff;
fa94de6b 20564 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
20565 newval = md_chars_to_number (buf, THUMB_SIZE);
20566 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20567 newval |= (S << 10) | hi;
20568 newval2 &= ~T2I1I2MASK;
20569 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
20570 md_number_to_chars (buf, newval, THUMB_SIZE);
20571 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20572}
20573
c19d1205 20574void
55cf6793 20575md_apply_fix (fixS * fixP,
c19d1205
ZW
20576 valueT * valP,
20577 segT seg)
20578{
20579 offsetT value = * valP;
20580 offsetT newval;
20581 unsigned int newimm;
20582 unsigned long temp;
20583 int sign;
20584 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 20585
9c2799c2 20586 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 20587
c19d1205 20588 /* Note whether this will delete the relocation. */
4962c51a 20589
c19d1205
ZW
20590 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
20591 fixP->fx_done = 1;
b99bd4ef 20592
adbaf948 20593 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 20594 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
20595 for emit_reloc. */
20596 value &= 0xffffffff;
20597 value ^= 0x80000000;
5f4273c7 20598 value -= 0x80000000;
adbaf948
ZW
20599
20600 *valP = value;
c19d1205 20601 fixP->fx_addnumber = value;
b99bd4ef 20602
adbaf948
ZW
20603 /* Same treatment for fixP->fx_offset. */
20604 fixP->fx_offset &= 0xffffffff;
20605 fixP->fx_offset ^= 0x80000000;
20606 fixP->fx_offset -= 0x80000000;
20607
c19d1205 20608 switch (fixP->fx_r_type)
b99bd4ef 20609 {
c19d1205
ZW
20610 case BFD_RELOC_NONE:
20611 /* This will need to go in the object file. */
20612 fixP->fx_done = 0;
20613 break;
b99bd4ef 20614
c19d1205
ZW
20615 case BFD_RELOC_ARM_IMMEDIATE:
20616 /* We claim that this fixup has been processed here,
20617 even if in fact we generate an error because we do
20618 not have a reloc for it, so tc_gen_reloc will reject it. */
20619 fixP->fx_done = 1;
b99bd4ef 20620
77db8e2e 20621 if (fixP->fx_addsy)
b99bd4ef 20622 {
77db8e2e 20623 const char *msg = 0;
b99bd4ef 20624
77db8e2e
NC
20625 if (! S_IS_DEFINED (fixP->fx_addsy))
20626 msg = _("undefined symbol %s used as an immediate value");
20627 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20628 msg = _("symbol %s is in a different section");
20629 else if (S_IS_WEAK (fixP->fx_addsy))
20630 msg = _("symbol %s is weak and may be overridden later");
20631
20632 if (msg)
20633 {
20634 as_bad_where (fixP->fx_file, fixP->fx_line,
20635 msg, S_GET_NAME (fixP->fx_addsy));
20636 break;
20637 }
42e5fcbf
AS
20638 }
20639
c19d1205
ZW
20640 newimm = encode_arm_immediate (value);
20641 temp = md_chars_to_number (buf, INSN_SIZE);
20642
20643 /* If the instruction will fail, see if we can fix things up by
20644 changing the opcode. */
20645 if (newimm == (unsigned int) FAIL
20646 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 20647 {
c19d1205
ZW
20648 as_bad_where (fixP->fx_file, fixP->fx_line,
20649 _("invalid constant (%lx) after fixup"),
20650 (unsigned long) value);
20651 break;
b99bd4ef 20652 }
b99bd4ef 20653
c19d1205
ZW
20654 newimm |= (temp & 0xfffff000);
20655 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20656 break;
b99bd4ef 20657
c19d1205
ZW
20658 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20659 {
20660 unsigned int highpart = 0;
20661 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 20662
77db8e2e 20663 if (fixP->fx_addsy)
42e5fcbf 20664 {
77db8e2e 20665 const char *msg = 0;
42e5fcbf 20666
77db8e2e
NC
20667 if (! S_IS_DEFINED (fixP->fx_addsy))
20668 msg = _("undefined symbol %s used as an immediate value");
20669 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20670 msg = _("symbol %s is in a different section");
20671 else if (S_IS_WEAK (fixP->fx_addsy))
20672 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 20673
77db8e2e
NC
20674 if (msg)
20675 {
20676 as_bad_where (fixP->fx_file, fixP->fx_line,
20677 msg, S_GET_NAME (fixP->fx_addsy));
20678 break;
20679 }
20680 }
fa94de6b 20681
c19d1205
ZW
20682 newimm = encode_arm_immediate (value);
20683 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 20684
c19d1205
ZW
20685 /* If the instruction will fail, see if we can fix things up by
20686 changing the opcode. */
20687 if (newimm == (unsigned int) FAIL
20688 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
20689 {
20690 /* No ? OK - try using two ADD instructions to generate
20691 the value. */
20692 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 20693
c19d1205
ZW
20694 /* Yes - then make sure that the second instruction is
20695 also an add. */
20696 if (newimm != (unsigned int) FAIL)
20697 newinsn = temp;
20698 /* Still No ? Try using a negated value. */
20699 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
20700 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
20701 /* Otherwise - give up. */
20702 else
20703 {
20704 as_bad_where (fixP->fx_file, fixP->fx_line,
20705 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
20706 (long) value);
20707 break;
20708 }
b99bd4ef 20709
c19d1205
ZW
20710 /* Replace the first operand in the 2nd instruction (which
20711 is the PC) with the destination register. We have
20712 already added in the PC in the first instruction and we
20713 do not want to do it again. */
20714 newinsn &= ~ 0xf0000;
20715 newinsn |= ((newinsn & 0x0f000) << 4);
20716 }
b99bd4ef 20717
c19d1205
ZW
20718 newimm |= (temp & 0xfffff000);
20719 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 20720
c19d1205
ZW
20721 highpart |= (newinsn & 0xfffff000);
20722 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
20723 }
20724 break;
b99bd4ef 20725
c19d1205 20726 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
20727 if (!fixP->fx_done && seg->use_rela_p)
20728 value = 0;
20729
c19d1205 20730 case BFD_RELOC_ARM_LITERAL:
26d97720 20731 sign = value > 0;
b99bd4ef 20732
c19d1205
ZW
20733 if (value < 0)
20734 value = - value;
b99bd4ef 20735
c19d1205 20736 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 20737 {
c19d1205
ZW
20738 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
20739 as_bad_where (fixP->fx_file, fixP->fx_line,
20740 _("invalid literal constant: pool needs to be closer"));
20741 else
20742 as_bad_where (fixP->fx_file, fixP->fx_line,
20743 _("bad immediate value for offset (%ld)"),
20744 (long) value);
20745 break;
f03698e6
RE
20746 }
20747
c19d1205 20748 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
20749 if (value == 0)
20750 newval &= 0xfffff000;
20751 else
20752 {
20753 newval &= 0xff7ff000;
20754 newval |= value | (sign ? INDEX_UP : 0);
20755 }
c19d1205
ZW
20756 md_number_to_chars (buf, newval, INSN_SIZE);
20757 break;
b99bd4ef 20758
c19d1205
ZW
20759 case BFD_RELOC_ARM_OFFSET_IMM8:
20760 case BFD_RELOC_ARM_HWLITERAL:
26d97720 20761 sign = value > 0;
b99bd4ef 20762
c19d1205
ZW
20763 if (value < 0)
20764 value = - value;
b99bd4ef 20765
c19d1205 20766 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 20767 {
c19d1205
ZW
20768 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
20769 as_bad_where (fixP->fx_file, fixP->fx_line,
20770 _("invalid literal constant: pool needs to be closer"));
20771 else
f9d4405b 20772 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
20773 (long) value);
20774 break;
b99bd4ef
NC
20775 }
20776
c19d1205 20777 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
20778 if (value == 0)
20779 newval &= 0xfffff0f0;
20780 else
20781 {
20782 newval &= 0xff7ff0f0;
20783 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
20784 }
c19d1205
ZW
20785 md_number_to_chars (buf, newval, INSN_SIZE);
20786 break;
b99bd4ef 20787
c19d1205
ZW
20788 case BFD_RELOC_ARM_T32_OFFSET_U8:
20789 if (value < 0 || value > 1020 || value % 4 != 0)
20790 as_bad_where (fixP->fx_file, fixP->fx_line,
20791 _("bad immediate value for offset (%ld)"), (long) value);
20792 value /= 4;
b99bd4ef 20793
c19d1205 20794 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
20795 newval |= value;
20796 md_number_to_chars (buf+2, newval, THUMB_SIZE);
20797 break;
b99bd4ef 20798
c19d1205
ZW
20799 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20800 /* This is a complicated relocation used for all varieties of Thumb32
20801 load/store instruction with immediate offset:
20802
20803 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
20804 *4, optional writeback(W)
20805 (doubleword load/store)
20806
20807 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
20808 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
20809 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
20810 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
20811 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
20812
20813 Uppercase letters indicate bits that are already encoded at
20814 this point. Lowercase letters are our problem. For the
20815 second block of instructions, the secondary opcode nybble
20816 (bits 8..11) is present, and bit 23 is zero, even if this is
20817 a PC-relative operation. */
20818 newval = md_chars_to_number (buf, THUMB_SIZE);
20819 newval <<= 16;
20820 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 20821
c19d1205 20822 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 20823 {
c19d1205
ZW
20824 /* Doubleword load/store: 8-bit offset, scaled by 4. */
20825 if (value >= 0)
20826 newval |= (1 << 23);
20827 else
20828 value = -value;
20829 if (value % 4 != 0)
20830 {
20831 as_bad_where (fixP->fx_file, fixP->fx_line,
20832 _("offset not a multiple of 4"));
20833 break;
20834 }
20835 value /= 4;
216d22bc 20836 if (value > 0xff)
c19d1205
ZW
20837 {
20838 as_bad_where (fixP->fx_file, fixP->fx_line,
20839 _("offset out of range"));
20840 break;
20841 }
20842 newval &= ~0xff;
b99bd4ef 20843 }
c19d1205 20844 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 20845 {
c19d1205
ZW
20846 /* PC-relative, 12-bit offset. */
20847 if (value >= 0)
20848 newval |= (1 << 23);
20849 else
20850 value = -value;
216d22bc 20851 if (value > 0xfff)
c19d1205
ZW
20852 {
20853 as_bad_where (fixP->fx_file, fixP->fx_line,
20854 _("offset out of range"));
20855 break;
20856 }
20857 newval &= ~0xfff;
b99bd4ef 20858 }
c19d1205 20859 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 20860 {
c19d1205
ZW
20861 /* Writeback: 8-bit, +/- offset. */
20862 if (value >= 0)
20863 newval |= (1 << 9);
20864 else
20865 value = -value;
216d22bc 20866 if (value > 0xff)
c19d1205
ZW
20867 {
20868 as_bad_where (fixP->fx_file, fixP->fx_line,
20869 _("offset out of range"));
20870 break;
20871 }
20872 newval &= ~0xff;
b99bd4ef 20873 }
c19d1205 20874 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 20875 {
c19d1205 20876 /* T-instruction: positive 8-bit offset. */
216d22bc 20877 if (value < 0 || value > 0xff)
b99bd4ef 20878 {
c19d1205
ZW
20879 as_bad_where (fixP->fx_file, fixP->fx_line,
20880 _("offset out of range"));
20881 break;
b99bd4ef 20882 }
c19d1205
ZW
20883 newval &= ~0xff;
20884 newval |= value;
b99bd4ef
NC
20885 }
20886 else
b99bd4ef 20887 {
c19d1205
ZW
20888 /* Positive 12-bit or negative 8-bit offset. */
20889 int limit;
20890 if (value >= 0)
b99bd4ef 20891 {
c19d1205
ZW
20892 newval |= (1 << 23);
20893 limit = 0xfff;
20894 }
20895 else
20896 {
20897 value = -value;
20898 limit = 0xff;
20899 }
20900 if (value > limit)
20901 {
20902 as_bad_where (fixP->fx_file, fixP->fx_line,
20903 _("offset out of range"));
20904 break;
b99bd4ef 20905 }
c19d1205 20906 newval &= ~limit;
b99bd4ef 20907 }
b99bd4ef 20908
c19d1205
ZW
20909 newval |= value;
20910 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20911 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20912 break;
404ff6b5 20913
c19d1205
ZW
20914 case BFD_RELOC_ARM_SHIFT_IMM:
20915 newval = md_chars_to_number (buf, INSN_SIZE);
20916 if (((unsigned long) value) > 32
20917 || (value == 32
20918 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20919 {
20920 as_bad_where (fixP->fx_file, fixP->fx_line,
20921 _("shift expression is too large"));
20922 break;
20923 }
404ff6b5 20924
c19d1205
ZW
20925 if (value == 0)
20926 /* Shifts of zero must be done as lsl. */
20927 newval &= ~0x60;
20928 else if (value == 32)
20929 value = 0;
20930 newval &= 0xfffff07f;
20931 newval |= (value & 0x1f) << 7;
20932 md_number_to_chars (buf, newval, INSN_SIZE);
20933 break;
404ff6b5 20934
c19d1205 20935 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 20936 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 20937 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 20938 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
20939 /* We claim that this fixup has been processed here,
20940 even if in fact we generate an error because we do
20941 not have a reloc for it, so tc_gen_reloc will reject it. */
20942 fixP->fx_done = 1;
404ff6b5 20943
c19d1205
ZW
20944 if (fixP->fx_addsy
20945 && ! S_IS_DEFINED (fixP->fx_addsy))
20946 {
20947 as_bad_where (fixP->fx_file, fixP->fx_line,
20948 _("undefined symbol %s used as an immediate value"),
20949 S_GET_NAME (fixP->fx_addsy));
20950 break;
20951 }
404ff6b5 20952
c19d1205
ZW
20953 newval = md_chars_to_number (buf, THUMB_SIZE);
20954 newval <<= 16;
20955 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 20956
16805f35
PB
20957 newimm = FAIL;
20958 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20959 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
20960 {
20961 newimm = encode_thumb32_immediate (value);
20962 if (newimm == (unsigned int) FAIL)
20963 newimm = thumb32_negate_data_op (&newval, value);
20964 }
16805f35
PB
20965 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20966 && newimm == (unsigned int) FAIL)
92e90b6e 20967 {
16805f35
PB
20968 /* Turn add/sum into addw/subw. */
20969 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20970 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
20971 /* No flat 12-bit imm encoding for addsw/subsw. */
20972 if ((newval & 0x00100000) == 0)
e9f89963 20973 {
40f246e3
NC
20974 /* 12 bit immediate for addw/subw. */
20975 if (value < 0)
20976 {
20977 value = -value;
20978 newval ^= 0x00a00000;
20979 }
20980 if (value > 0xfff)
20981 newimm = (unsigned int) FAIL;
20982 else
20983 newimm = value;
e9f89963 20984 }
92e90b6e 20985 }
cc8a6dd0 20986
c19d1205 20987 if (newimm == (unsigned int)FAIL)
3631a3c8 20988 {
c19d1205
ZW
20989 as_bad_where (fixP->fx_file, fixP->fx_line,
20990 _("invalid constant (%lx) after fixup"),
20991 (unsigned long) value);
20992 break;
3631a3c8
NC
20993 }
20994
c19d1205
ZW
20995 newval |= (newimm & 0x800) << 15;
20996 newval |= (newimm & 0x700) << 4;
20997 newval |= (newimm & 0x0ff);
cc8a6dd0 20998
c19d1205
ZW
20999 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
21000 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
21001 break;
a737bd4d 21002
3eb17e6b 21003 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
21004 if (((unsigned long) value) > 0xffff)
21005 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 21006 _("invalid smc expression"));
2fc8bdac 21007 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
21008 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
21009 md_number_to_chars (buf, newval, INSN_SIZE);
21010 break;
a737bd4d 21011
90ec0d68
MGD
21012 case BFD_RELOC_ARM_HVC:
21013 if (((unsigned long) value) > 0xffff)
21014 as_bad_where (fixP->fx_file, fixP->fx_line,
21015 _("invalid hvc expression"));
21016 newval = md_chars_to_number (buf, INSN_SIZE);
21017 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
21018 md_number_to_chars (buf, newval, INSN_SIZE);
21019 break;
21020
c19d1205 21021 case BFD_RELOC_ARM_SWI:
adbaf948 21022 if (fixP->tc_fix_data != 0)
c19d1205
ZW
21023 {
21024 if (((unsigned long) value) > 0xff)
21025 as_bad_where (fixP->fx_file, fixP->fx_line,
21026 _("invalid swi expression"));
2fc8bdac 21027 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
21028 newval |= value;
21029 md_number_to_chars (buf, newval, THUMB_SIZE);
21030 }
21031 else
21032 {
21033 if (((unsigned long) value) > 0x00ffffff)
21034 as_bad_where (fixP->fx_file, fixP->fx_line,
21035 _("invalid swi expression"));
2fc8bdac 21036 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
21037 newval |= value;
21038 md_number_to_chars (buf, newval, INSN_SIZE);
21039 }
21040 break;
a737bd4d 21041
c19d1205
ZW
21042 case BFD_RELOC_ARM_MULTI:
21043 if (((unsigned long) value) > 0xffff)
21044 as_bad_where (fixP->fx_file, fixP->fx_line,
21045 _("invalid expression in load/store multiple"));
21046 newval = value | md_chars_to_number (buf, INSN_SIZE);
21047 md_number_to_chars (buf, newval, INSN_SIZE);
21048 break;
a737bd4d 21049
c19d1205 21050#ifdef OBJ_ELF
39b41c9c 21051 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
21052
21053 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21054 && fixP->fx_addsy
34e77a92 21055 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21056 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21057 && THUMB_IS_FUNC (fixP->fx_addsy))
21058 /* Flip the bl to blx. This is a simple flip
21059 bit here because we generate PCREL_CALL for
21060 unconditional bls. */
21061 {
21062 newval = md_chars_to_number (buf, INSN_SIZE);
21063 newval = newval | 0x10000000;
21064 md_number_to_chars (buf, newval, INSN_SIZE);
21065 temp = 1;
21066 fixP->fx_done = 1;
21067 }
39b41c9c
PB
21068 else
21069 temp = 3;
21070 goto arm_branch_common;
21071
21072 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
21073 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21074 && fixP->fx_addsy
34e77a92 21075 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21076 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21077 && THUMB_IS_FUNC (fixP->fx_addsy))
21078 {
21079 /* This would map to a bl<cond>, b<cond>,
21080 b<always> to a Thumb function. We
21081 need to force a relocation for this particular
21082 case. */
21083 newval = md_chars_to_number (buf, INSN_SIZE);
21084 fixP->fx_done = 0;
21085 }
21086
2fc8bdac 21087 case BFD_RELOC_ARM_PLT32:
c19d1205 21088#endif
39b41c9c
PB
21089 case BFD_RELOC_ARM_PCREL_BRANCH:
21090 temp = 3;
21091 goto arm_branch_common;
a737bd4d 21092
39b41c9c 21093 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 21094
39b41c9c 21095 temp = 1;
267bf995
RR
21096 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21097 && fixP->fx_addsy
34e77a92 21098 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21099 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21100 && ARM_IS_FUNC (fixP->fx_addsy))
21101 {
21102 /* Flip the blx to a bl and warn. */
21103 const char *name = S_GET_NAME (fixP->fx_addsy);
21104 newval = 0xeb000000;
21105 as_warn_where (fixP->fx_file, fixP->fx_line,
21106 _("blx to '%s' an ARM ISA state function changed to bl"),
21107 name);
21108 md_number_to_chars (buf, newval, INSN_SIZE);
21109 temp = 3;
21110 fixP->fx_done = 1;
21111 }
21112
21113#ifdef OBJ_ELF
21114 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21115 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
21116#endif
21117
39b41c9c 21118 arm_branch_common:
c19d1205 21119 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
21120 instruction, in a 24 bit, signed field. Bits 26 through 32 either
21121 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
21122 also be be clear. */
21123 if (value & temp)
c19d1205 21124 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
21125 _("misaligned branch destination"));
21126 if ((value & (offsetT)0xfe000000) != (offsetT)0
21127 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 21128 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 21129
2fc8bdac 21130 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 21131 {
2fc8bdac
ZW
21132 newval = md_chars_to_number (buf, INSN_SIZE);
21133 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
21134 /* Set the H bit on BLX instructions. */
21135 if (temp == 1)
21136 {
21137 if (value & 2)
21138 newval |= 0x01000000;
21139 else
21140 newval &= ~0x01000000;
21141 }
2fc8bdac 21142 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 21143 }
c19d1205 21144 break;
a737bd4d 21145
25fe350b
MS
21146 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
21147 /* CBZ can only branch forward. */
a737bd4d 21148
738755b0
MS
21149 /* Attempts to use CBZ to branch to the next instruction
21150 (which, strictly speaking, are prohibited) will be turned into
21151 no-ops.
21152
21153 FIXME: It may be better to remove the instruction completely and
21154 perform relaxation. */
21155 if (value == -2)
2fc8bdac
ZW
21156 {
21157 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 21158 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
21159 md_number_to_chars (buf, newval, THUMB_SIZE);
21160 }
738755b0
MS
21161 else
21162 {
21163 if (value & ~0x7e)
08f10d51 21164 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0
MS
21165
21166 if (fixP->fx_done || !seg->use_rela_p)
21167 {
21168 newval = md_chars_to_number (buf, THUMB_SIZE);
21169 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
21170 md_number_to_chars (buf, newval, THUMB_SIZE);
21171 }
21172 }
c19d1205 21173 break;
a737bd4d 21174
c19d1205 21175 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 21176 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 21177 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 21178
2fc8bdac
ZW
21179 if (fixP->fx_done || !seg->use_rela_p)
21180 {
21181 newval = md_chars_to_number (buf, THUMB_SIZE);
21182 newval |= (value & 0x1ff) >> 1;
21183 md_number_to_chars (buf, newval, THUMB_SIZE);
21184 }
c19d1205 21185 break;
a737bd4d 21186
c19d1205 21187 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 21188 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 21189 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 21190
2fc8bdac
ZW
21191 if (fixP->fx_done || !seg->use_rela_p)
21192 {
21193 newval = md_chars_to_number (buf, THUMB_SIZE);
21194 newval |= (value & 0xfff) >> 1;
21195 md_number_to_chars (buf, newval, THUMB_SIZE);
21196 }
c19d1205 21197 break;
a737bd4d 21198
c19d1205 21199 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
21200 if (fixP->fx_addsy
21201 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21202 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21203 && ARM_IS_FUNC (fixP->fx_addsy)
21204 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21205 {
21206 /* Force a relocation for a branch 20 bits wide. */
21207 fixP->fx_done = 0;
21208 }
08f10d51 21209 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
21210 as_bad_where (fixP->fx_file, fixP->fx_line,
21211 _("conditional branch out of range"));
404ff6b5 21212
2fc8bdac
ZW
21213 if (fixP->fx_done || !seg->use_rela_p)
21214 {
21215 offsetT newval2;
21216 addressT S, J1, J2, lo, hi;
404ff6b5 21217
2fc8bdac
ZW
21218 S = (value & 0x00100000) >> 20;
21219 J2 = (value & 0x00080000) >> 19;
21220 J1 = (value & 0x00040000) >> 18;
21221 hi = (value & 0x0003f000) >> 12;
21222 lo = (value & 0x00000ffe) >> 1;
6c43fab6 21223
2fc8bdac
ZW
21224 newval = md_chars_to_number (buf, THUMB_SIZE);
21225 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21226 newval |= (S << 10) | hi;
21227 newval2 |= (J1 << 13) | (J2 << 11) | lo;
21228 md_number_to_chars (buf, newval, THUMB_SIZE);
21229 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
21230 }
c19d1205 21231 break;
6c43fab6 21232
c19d1205 21233 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
21234 /* If there is a blx from a thumb state function to
21235 another thumb function flip this to a bl and warn
21236 about it. */
21237
21238 if (fixP->fx_addsy
34e77a92 21239 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21240 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21241 && THUMB_IS_FUNC (fixP->fx_addsy))
21242 {
21243 const char *name = S_GET_NAME (fixP->fx_addsy);
21244 as_warn_where (fixP->fx_file, fixP->fx_line,
21245 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
21246 name);
21247 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21248 newval = newval | 0x1000;
21249 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
21250 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
21251 fixP->fx_done = 1;
21252 }
21253
21254
21255 goto thumb_bl_common;
21256
c19d1205 21257 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
21258 /* A bl from Thumb state ISA to an internal ARM state function
21259 is converted to a blx. */
21260 if (fixP->fx_addsy
21261 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21262 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21263 && ARM_IS_FUNC (fixP->fx_addsy)
21264 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21265 {
21266 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21267 newval = newval & ~0x1000;
21268 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
21269 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
21270 fixP->fx_done = 1;
21271 }
21272
21273 thumb_bl_common:
21274
21275#ifdef OBJ_ELF
2b2f5df9
NC
21276 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
21277 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
267bf995
RR
21278 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
21279#endif
21280
2fc8bdac
ZW
21281 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
21282 /* For a BLX instruction, make sure that the relocation is rounded up
21283 to a word boundary. This follows the semantics of the instruction
21284 which specifies that bit 1 of the target address will come from bit
21285 1 of the base address. */
21286 value = (value + 1) & ~ 1;
404ff6b5 21287
2b2f5df9
NC
21288 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
21289 {
21290 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
21291 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21292 else if ((value & ~0x1ffffff)
21293 && ((value & ~0x1ffffff) != ~0x1ffffff))
21294 as_bad_where (fixP->fx_file, fixP->fx_line,
21295 _("Thumb2 branch out of range"));
21296 }
4a42ebbc
RR
21297
21298 if (fixP->fx_done || !seg->use_rela_p)
21299 encode_thumb2_b_bl_offset (buf, value);
21300
c19d1205 21301 break;
404ff6b5 21302
c19d1205 21303 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
21304 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
21305 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 21306
2fc8bdac 21307 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 21308 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 21309
2fc8bdac 21310 break;
a737bd4d 21311
2fc8bdac
ZW
21312 case BFD_RELOC_8:
21313 if (fixP->fx_done || !seg->use_rela_p)
21314 md_number_to_chars (buf, value, 1);
c19d1205 21315 break;
a737bd4d 21316
c19d1205 21317 case BFD_RELOC_16:
2fc8bdac 21318 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 21319 md_number_to_chars (buf, value, 2);
c19d1205 21320 break;
a737bd4d 21321
c19d1205 21322#ifdef OBJ_ELF
0855e32b
NS
21323 case BFD_RELOC_ARM_TLS_CALL:
21324 case BFD_RELOC_ARM_THM_TLS_CALL:
21325 case BFD_RELOC_ARM_TLS_DESCSEQ:
21326 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
21327 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21328 break;
21329
21330 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
21331 case BFD_RELOC_ARM_TLS_GD32:
21332 case BFD_RELOC_ARM_TLS_LE32:
21333 case BFD_RELOC_ARM_TLS_IE32:
21334 case BFD_RELOC_ARM_TLS_LDM32:
21335 case BFD_RELOC_ARM_TLS_LDO32:
21336 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21337 /* fall through */
6c43fab6 21338
c19d1205
ZW
21339 case BFD_RELOC_ARM_GOT32:
21340 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
21341 if (fixP->fx_done || !seg->use_rela_p)
21342 md_number_to_chars (buf, 0, 4);
c19d1205 21343 break;
b43420e6
NC
21344
21345 case BFD_RELOC_ARM_GOT_PREL:
21346 if (fixP->fx_done || !seg->use_rela_p)
21347 md_number_to_chars (buf, value, 4);
21348 break;
21349
9a6f4e97
NS
21350 case BFD_RELOC_ARM_TARGET2:
21351 /* TARGET2 is not partial-inplace, so we need to write the
21352 addend here for REL targets, because it won't be written out
21353 during reloc processing later. */
21354 if (fixP->fx_done || !seg->use_rela_p)
21355 md_number_to_chars (buf, fixP->fx_offset, 4);
21356 break;
c19d1205 21357#endif
6c43fab6 21358
c19d1205
ZW
21359 case BFD_RELOC_RVA:
21360 case BFD_RELOC_32:
21361 case BFD_RELOC_ARM_TARGET1:
21362 case BFD_RELOC_ARM_ROSEGREL32:
21363 case BFD_RELOC_ARM_SBREL32:
21364 case BFD_RELOC_32_PCREL:
f0927246
NC
21365#ifdef TE_PE
21366 case BFD_RELOC_32_SECREL:
21367#endif
2fc8bdac 21368 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
21369#ifdef TE_WINCE
21370 /* For WinCE we only do this for pcrel fixups. */
21371 if (fixP->fx_done || fixP->fx_pcrel)
21372#endif
21373 md_number_to_chars (buf, value, 4);
c19d1205 21374 break;
6c43fab6 21375
c19d1205
ZW
21376#ifdef OBJ_ELF
21377 case BFD_RELOC_ARM_PREL31:
2fc8bdac 21378 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
21379 {
21380 newval = md_chars_to_number (buf, 4) & 0x80000000;
21381 if ((value ^ (value >> 1)) & 0x40000000)
21382 {
21383 as_bad_where (fixP->fx_file, fixP->fx_line,
21384 _("rel31 relocation overflow"));
21385 }
21386 newval |= value & 0x7fffffff;
21387 md_number_to_chars (buf, newval, 4);
21388 }
21389 break;
c19d1205 21390#endif
a737bd4d 21391
c19d1205 21392 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 21393 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
21394 if (value < -1023 || value > 1023 || (value & 3))
21395 as_bad_where (fixP->fx_file, fixP->fx_line,
21396 _("co-processor offset out of range"));
21397 cp_off_common:
26d97720 21398 sign = value > 0;
c19d1205
ZW
21399 if (value < 0)
21400 value = -value;
8f06b2d8
PB
21401 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21402 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21403 newval = md_chars_to_number (buf, INSN_SIZE);
21404 else
21405 newval = get_thumb32_insn (buf);
26d97720
NS
21406 if (value == 0)
21407 newval &= 0xffffff00;
21408 else
21409 {
21410 newval &= 0xff7fff00;
21411 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
21412 }
8f06b2d8
PB
21413 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21414 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21415 md_number_to_chars (buf, newval, INSN_SIZE);
21416 else
21417 put_thumb32_insn (buf, newval);
c19d1205 21418 break;
a737bd4d 21419
c19d1205 21420 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 21421 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
21422 if (value < -255 || value > 255)
21423 as_bad_where (fixP->fx_file, fixP->fx_line,
21424 _("co-processor offset out of range"));
df7849c5 21425 value *= 4;
c19d1205 21426 goto cp_off_common;
6c43fab6 21427
c19d1205
ZW
21428 case BFD_RELOC_ARM_THUMB_OFFSET:
21429 newval = md_chars_to_number (buf, THUMB_SIZE);
21430 /* Exactly what ranges, and where the offset is inserted depends
21431 on the type of instruction, we can establish this from the
21432 top 4 bits. */
21433 switch (newval >> 12)
21434 {
21435 case 4: /* PC load. */
21436 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
21437 forced to zero for these loads; md_pcrel_from has already
21438 compensated for this. */
21439 if (value & 3)
21440 as_bad_where (fixP->fx_file, fixP->fx_line,
21441 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
21442 (((unsigned long) fixP->fx_frag->fr_address
21443 + (unsigned long) fixP->fx_where) & ~3)
21444 + (unsigned long) value);
a737bd4d 21445
c19d1205
ZW
21446 if (value & ~0x3fc)
21447 as_bad_where (fixP->fx_file, fixP->fx_line,
21448 _("invalid offset, value too big (0x%08lX)"),
21449 (long) value);
a737bd4d 21450
c19d1205
ZW
21451 newval |= value >> 2;
21452 break;
a737bd4d 21453
c19d1205
ZW
21454 case 9: /* SP load/store. */
21455 if (value & ~0x3fc)
21456 as_bad_where (fixP->fx_file, fixP->fx_line,
21457 _("invalid offset, value too big (0x%08lX)"),
21458 (long) value);
21459 newval |= value >> 2;
21460 break;
6c43fab6 21461
c19d1205
ZW
21462 case 6: /* Word load/store. */
21463 if (value & ~0x7c)
21464 as_bad_where (fixP->fx_file, fixP->fx_line,
21465 _("invalid offset, value too big (0x%08lX)"),
21466 (long) value);
21467 newval |= value << 4; /* 6 - 2. */
21468 break;
a737bd4d 21469
c19d1205
ZW
21470 case 7: /* Byte load/store. */
21471 if (value & ~0x1f)
21472 as_bad_where (fixP->fx_file, fixP->fx_line,
21473 _("invalid offset, value too big (0x%08lX)"),
21474 (long) value);
21475 newval |= value << 6;
21476 break;
a737bd4d 21477
c19d1205
ZW
21478 case 8: /* Halfword load/store. */
21479 if (value & ~0x3e)
21480 as_bad_where (fixP->fx_file, fixP->fx_line,
21481 _("invalid offset, value too big (0x%08lX)"),
21482 (long) value);
21483 newval |= value << 5; /* 6 - 1. */
21484 break;
a737bd4d 21485
c19d1205
ZW
21486 default:
21487 as_bad_where (fixP->fx_file, fixP->fx_line,
21488 "Unable to process relocation for thumb opcode: %lx",
21489 (unsigned long) newval);
21490 break;
21491 }
21492 md_number_to_chars (buf, newval, THUMB_SIZE);
21493 break;
a737bd4d 21494
c19d1205
ZW
21495 case BFD_RELOC_ARM_THUMB_ADD:
21496 /* This is a complicated relocation, since we use it for all of
21497 the following immediate relocations:
a737bd4d 21498
c19d1205
ZW
21499 3bit ADD/SUB
21500 8bit ADD/SUB
21501 9bit ADD/SUB SP word-aligned
21502 10bit ADD PC/SP word-aligned
a737bd4d 21503
c19d1205
ZW
21504 The type of instruction being processed is encoded in the
21505 instruction field:
a737bd4d 21506
c19d1205
ZW
21507 0x8000 SUB
21508 0x00F0 Rd
21509 0x000F Rs
21510 */
21511 newval = md_chars_to_number (buf, THUMB_SIZE);
21512 {
21513 int rd = (newval >> 4) & 0xf;
21514 int rs = newval & 0xf;
21515 int subtract = !!(newval & 0x8000);
a737bd4d 21516
c19d1205
ZW
21517 /* Check for HI regs, only very restricted cases allowed:
21518 Adjusting SP, and using PC or SP to get an address. */
21519 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
21520 || (rs > 7 && rs != REG_SP && rs != REG_PC))
21521 as_bad_where (fixP->fx_file, fixP->fx_line,
21522 _("invalid Hi register with immediate"));
a737bd4d 21523
c19d1205
ZW
21524 /* If value is negative, choose the opposite instruction. */
21525 if (value < 0)
21526 {
21527 value = -value;
21528 subtract = !subtract;
21529 if (value < 0)
21530 as_bad_where (fixP->fx_file, fixP->fx_line,
21531 _("immediate value out of range"));
21532 }
a737bd4d 21533
c19d1205
ZW
21534 if (rd == REG_SP)
21535 {
21536 if (value & ~0x1fc)
21537 as_bad_where (fixP->fx_file, fixP->fx_line,
21538 _("invalid immediate for stack address calculation"));
21539 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
21540 newval |= value >> 2;
21541 }
21542 else if (rs == REG_PC || rs == REG_SP)
21543 {
21544 if (subtract || value & ~0x3fc)
21545 as_bad_where (fixP->fx_file, fixP->fx_line,
21546 _("invalid immediate for address calculation (value = 0x%08lX)"),
21547 (unsigned long) value);
21548 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
21549 newval |= rd << 8;
21550 newval |= value >> 2;
21551 }
21552 else if (rs == rd)
21553 {
21554 if (value & ~0xff)
21555 as_bad_where (fixP->fx_file, fixP->fx_line,
21556 _("immediate value out of range"));
21557 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
21558 newval |= (rd << 8) | value;
21559 }
21560 else
21561 {
21562 if (value & ~0x7)
21563 as_bad_where (fixP->fx_file, fixP->fx_line,
21564 _("immediate value out of range"));
21565 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
21566 newval |= rd | (rs << 3) | (value << 6);
21567 }
21568 }
21569 md_number_to_chars (buf, newval, THUMB_SIZE);
21570 break;
a737bd4d 21571
c19d1205
ZW
21572 case BFD_RELOC_ARM_THUMB_IMM:
21573 newval = md_chars_to_number (buf, THUMB_SIZE);
21574 if (value < 0 || value > 255)
21575 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 21576 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
21577 (long) value);
21578 newval |= value;
21579 md_number_to_chars (buf, newval, THUMB_SIZE);
21580 break;
a737bd4d 21581
c19d1205
ZW
21582 case BFD_RELOC_ARM_THUMB_SHIFT:
21583 /* 5bit shift value (0..32). LSL cannot take 32. */
21584 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
21585 temp = newval & 0xf800;
21586 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
21587 as_bad_where (fixP->fx_file, fixP->fx_line,
21588 _("invalid shift value: %ld"), (long) value);
21589 /* Shifts of zero must be encoded as LSL. */
21590 if (value == 0)
21591 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
21592 /* Shifts of 32 are encoded as zero. */
21593 else if (value == 32)
21594 value = 0;
21595 newval |= value << 6;
21596 md_number_to_chars (buf, newval, THUMB_SIZE);
21597 break;
a737bd4d 21598
c19d1205
ZW
21599 case BFD_RELOC_VTABLE_INHERIT:
21600 case BFD_RELOC_VTABLE_ENTRY:
21601 fixP->fx_done = 0;
21602 return;
6c43fab6 21603
b6895b4f
PB
21604 case BFD_RELOC_ARM_MOVW:
21605 case BFD_RELOC_ARM_MOVT:
21606 case BFD_RELOC_ARM_THUMB_MOVW:
21607 case BFD_RELOC_ARM_THUMB_MOVT:
21608 if (fixP->fx_done || !seg->use_rela_p)
21609 {
21610 /* REL format relocations are limited to a 16-bit addend. */
21611 if (!fixP->fx_done)
21612 {
39623e12 21613 if (value < -0x8000 || value > 0x7fff)
b6895b4f 21614 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 21615 _("offset out of range"));
b6895b4f
PB
21616 }
21617 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21618 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21619 {
21620 value >>= 16;
21621 }
21622
21623 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21624 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21625 {
21626 newval = get_thumb32_insn (buf);
21627 newval &= 0xfbf08f00;
21628 newval |= (value & 0xf000) << 4;
21629 newval |= (value & 0x0800) << 15;
21630 newval |= (value & 0x0700) << 4;
21631 newval |= (value & 0x00ff);
21632 put_thumb32_insn (buf, newval);
21633 }
21634 else
21635 {
21636 newval = md_chars_to_number (buf, 4);
21637 newval &= 0xfff0f000;
21638 newval |= value & 0x0fff;
21639 newval |= (value & 0xf000) << 4;
21640 md_number_to_chars (buf, newval, 4);
21641 }
21642 }
21643 return;
21644
4962c51a
MS
21645 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21646 case BFD_RELOC_ARM_ALU_PC_G0:
21647 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21648 case BFD_RELOC_ARM_ALU_PC_G1:
21649 case BFD_RELOC_ARM_ALU_PC_G2:
21650 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21651 case BFD_RELOC_ARM_ALU_SB_G0:
21652 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21653 case BFD_RELOC_ARM_ALU_SB_G1:
21654 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 21655 gas_assert (!fixP->fx_done);
4962c51a
MS
21656 if (!seg->use_rela_p)
21657 {
21658 bfd_vma insn;
21659 bfd_vma encoded_addend;
21660 bfd_vma addend_abs = abs (value);
21661
21662 /* Check that the absolute value of the addend can be
21663 expressed as an 8-bit constant plus a rotation. */
21664 encoded_addend = encode_arm_immediate (addend_abs);
21665 if (encoded_addend == (unsigned int) FAIL)
21666 as_bad_where (fixP->fx_file, fixP->fx_line,
21667 _("the offset 0x%08lX is not representable"),
495bde8e 21668 (unsigned long) addend_abs);
4962c51a
MS
21669
21670 /* Extract the instruction. */
21671 insn = md_chars_to_number (buf, INSN_SIZE);
21672
21673 /* If the addend is positive, use an ADD instruction.
21674 Otherwise use a SUB. Take care not to destroy the S bit. */
21675 insn &= 0xff1fffff;
21676 if (value < 0)
21677 insn |= 1 << 22;
21678 else
21679 insn |= 1 << 23;
21680
21681 /* Place the encoded addend into the first 12 bits of the
21682 instruction. */
21683 insn &= 0xfffff000;
21684 insn |= encoded_addend;
5f4273c7
NC
21685
21686 /* Update the instruction. */
4962c51a
MS
21687 md_number_to_chars (buf, insn, INSN_SIZE);
21688 }
21689 break;
21690
21691 case BFD_RELOC_ARM_LDR_PC_G0:
21692 case BFD_RELOC_ARM_LDR_PC_G1:
21693 case BFD_RELOC_ARM_LDR_PC_G2:
21694 case BFD_RELOC_ARM_LDR_SB_G0:
21695 case BFD_RELOC_ARM_LDR_SB_G1:
21696 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 21697 gas_assert (!fixP->fx_done);
4962c51a
MS
21698 if (!seg->use_rela_p)
21699 {
21700 bfd_vma insn;
21701 bfd_vma addend_abs = abs (value);
21702
21703 /* Check that the absolute value of the addend can be
21704 encoded in 12 bits. */
21705 if (addend_abs >= 0x1000)
21706 as_bad_where (fixP->fx_file, fixP->fx_line,
21707 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 21708 (unsigned long) addend_abs);
4962c51a
MS
21709
21710 /* Extract the instruction. */
21711 insn = md_chars_to_number (buf, INSN_SIZE);
21712
21713 /* If the addend is negative, clear bit 23 of the instruction.
21714 Otherwise set it. */
21715 if (value < 0)
21716 insn &= ~(1 << 23);
21717 else
21718 insn |= 1 << 23;
21719
21720 /* Place the absolute value of the addend into the first 12 bits
21721 of the instruction. */
21722 insn &= 0xfffff000;
21723 insn |= addend_abs;
5f4273c7
NC
21724
21725 /* Update the instruction. */
4962c51a
MS
21726 md_number_to_chars (buf, insn, INSN_SIZE);
21727 }
21728 break;
21729
21730 case BFD_RELOC_ARM_LDRS_PC_G0:
21731 case BFD_RELOC_ARM_LDRS_PC_G1:
21732 case BFD_RELOC_ARM_LDRS_PC_G2:
21733 case BFD_RELOC_ARM_LDRS_SB_G0:
21734 case BFD_RELOC_ARM_LDRS_SB_G1:
21735 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 21736 gas_assert (!fixP->fx_done);
4962c51a
MS
21737 if (!seg->use_rela_p)
21738 {
21739 bfd_vma insn;
21740 bfd_vma addend_abs = abs (value);
21741
21742 /* Check that the absolute value of the addend can be
21743 encoded in 8 bits. */
21744 if (addend_abs >= 0x100)
21745 as_bad_where (fixP->fx_file, fixP->fx_line,
21746 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 21747 (unsigned long) addend_abs);
4962c51a
MS
21748
21749 /* Extract the instruction. */
21750 insn = md_chars_to_number (buf, INSN_SIZE);
21751
21752 /* If the addend is negative, clear bit 23 of the instruction.
21753 Otherwise set it. */
21754 if (value < 0)
21755 insn &= ~(1 << 23);
21756 else
21757 insn |= 1 << 23;
21758
21759 /* Place the first four bits of the absolute value of the addend
21760 into the first 4 bits of the instruction, and the remaining
21761 four into bits 8 .. 11. */
21762 insn &= 0xfffff0f0;
21763 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
21764
21765 /* Update the instruction. */
4962c51a
MS
21766 md_number_to_chars (buf, insn, INSN_SIZE);
21767 }
21768 break;
21769
21770 case BFD_RELOC_ARM_LDC_PC_G0:
21771 case BFD_RELOC_ARM_LDC_PC_G1:
21772 case BFD_RELOC_ARM_LDC_PC_G2:
21773 case BFD_RELOC_ARM_LDC_SB_G0:
21774 case BFD_RELOC_ARM_LDC_SB_G1:
21775 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 21776 gas_assert (!fixP->fx_done);
4962c51a
MS
21777 if (!seg->use_rela_p)
21778 {
21779 bfd_vma insn;
21780 bfd_vma addend_abs = abs (value);
21781
21782 /* Check that the absolute value of the addend is a multiple of
21783 four and, when divided by four, fits in 8 bits. */
21784 if (addend_abs & 0x3)
21785 as_bad_where (fixP->fx_file, fixP->fx_line,
21786 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 21787 (unsigned long) addend_abs);
4962c51a
MS
21788
21789 if ((addend_abs >> 2) > 0xff)
21790 as_bad_where (fixP->fx_file, fixP->fx_line,
21791 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 21792 (unsigned long) addend_abs);
4962c51a
MS
21793
21794 /* Extract the instruction. */
21795 insn = md_chars_to_number (buf, INSN_SIZE);
21796
21797 /* If the addend is negative, clear bit 23 of the instruction.
21798 Otherwise set it. */
21799 if (value < 0)
21800 insn &= ~(1 << 23);
21801 else
21802 insn |= 1 << 23;
21803
21804 /* Place the addend (divided by four) into the first eight
21805 bits of the instruction. */
21806 insn &= 0xfffffff0;
21807 insn |= addend_abs >> 2;
5f4273c7
NC
21808
21809 /* Update the instruction. */
4962c51a
MS
21810 md_number_to_chars (buf, insn, INSN_SIZE);
21811 }
21812 break;
21813
845b51d6
PB
21814 case BFD_RELOC_ARM_V4BX:
21815 /* This will need to go in the object file. */
21816 fixP->fx_done = 0;
21817 break;
21818
c19d1205
ZW
21819 case BFD_RELOC_UNUSED:
21820 default:
21821 as_bad_where (fixP->fx_file, fixP->fx_line,
21822 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
21823 }
6c43fab6
RE
21824}
21825
c19d1205
ZW
21826/* Translate internal representation of relocation info to BFD target
21827 format. */
a737bd4d 21828
c19d1205 21829arelent *
00a97672 21830tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 21831{
c19d1205
ZW
21832 arelent * reloc;
21833 bfd_reloc_code_real_type code;
a737bd4d 21834
21d799b5 21835 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 21836
21d799b5 21837 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
21838 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
21839 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 21840
2fc8bdac 21841 if (fixp->fx_pcrel)
00a97672
RS
21842 {
21843 if (section->use_rela_p)
21844 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
21845 else
21846 fixp->fx_offset = reloc->address;
21847 }
c19d1205 21848 reloc->addend = fixp->fx_offset;
a737bd4d 21849
c19d1205 21850 switch (fixp->fx_r_type)
a737bd4d 21851 {
c19d1205
ZW
21852 case BFD_RELOC_8:
21853 if (fixp->fx_pcrel)
21854 {
21855 code = BFD_RELOC_8_PCREL;
21856 break;
21857 }
a737bd4d 21858
c19d1205
ZW
21859 case BFD_RELOC_16:
21860 if (fixp->fx_pcrel)
21861 {
21862 code = BFD_RELOC_16_PCREL;
21863 break;
21864 }
6c43fab6 21865
c19d1205
ZW
21866 case BFD_RELOC_32:
21867 if (fixp->fx_pcrel)
21868 {
21869 code = BFD_RELOC_32_PCREL;
21870 break;
21871 }
a737bd4d 21872
b6895b4f
PB
21873 case BFD_RELOC_ARM_MOVW:
21874 if (fixp->fx_pcrel)
21875 {
21876 code = BFD_RELOC_ARM_MOVW_PCREL;
21877 break;
21878 }
21879
21880 case BFD_RELOC_ARM_MOVT:
21881 if (fixp->fx_pcrel)
21882 {
21883 code = BFD_RELOC_ARM_MOVT_PCREL;
21884 break;
21885 }
21886
21887 case BFD_RELOC_ARM_THUMB_MOVW:
21888 if (fixp->fx_pcrel)
21889 {
21890 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21891 break;
21892 }
21893
21894 case BFD_RELOC_ARM_THUMB_MOVT:
21895 if (fixp->fx_pcrel)
21896 {
21897 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21898 break;
21899 }
21900
c19d1205
ZW
21901 case BFD_RELOC_NONE:
21902 case BFD_RELOC_ARM_PCREL_BRANCH:
21903 case BFD_RELOC_ARM_PCREL_BLX:
21904 case BFD_RELOC_RVA:
21905 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21906 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21907 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21908 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21909 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21910 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
21911 case BFD_RELOC_VTABLE_ENTRY:
21912 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
21913#ifdef TE_PE
21914 case BFD_RELOC_32_SECREL:
21915#endif
c19d1205
ZW
21916 code = fixp->fx_r_type;
21917 break;
a737bd4d 21918
00adf2d4
JB
21919 case BFD_RELOC_THUMB_PCREL_BLX:
21920#ifdef OBJ_ELF
21921 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21922 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21923 else
21924#endif
21925 code = BFD_RELOC_THUMB_PCREL_BLX;
21926 break;
21927
c19d1205
ZW
21928 case BFD_RELOC_ARM_LITERAL:
21929 case BFD_RELOC_ARM_HWLITERAL:
21930 /* If this is called then the a literal has
21931 been referenced across a section boundary. */
21932 as_bad_where (fixp->fx_file, fixp->fx_line,
21933 _("literal referenced across section boundary"));
21934 return NULL;
a737bd4d 21935
c19d1205 21936#ifdef OBJ_ELF
0855e32b
NS
21937 case BFD_RELOC_ARM_TLS_CALL:
21938 case BFD_RELOC_ARM_THM_TLS_CALL:
21939 case BFD_RELOC_ARM_TLS_DESCSEQ:
21940 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
21941 case BFD_RELOC_ARM_GOT32:
21942 case BFD_RELOC_ARM_GOTOFF:
b43420e6 21943 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
21944 case BFD_RELOC_ARM_PLT32:
21945 case BFD_RELOC_ARM_TARGET1:
21946 case BFD_RELOC_ARM_ROSEGREL32:
21947 case BFD_RELOC_ARM_SBREL32:
21948 case BFD_RELOC_ARM_PREL31:
21949 case BFD_RELOC_ARM_TARGET2:
21950 case BFD_RELOC_ARM_TLS_LE32:
21951 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
21952 case BFD_RELOC_ARM_PCREL_CALL:
21953 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
21954 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21955 case BFD_RELOC_ARM_ALU_PC_G0:
21956 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21957 case BFD_RELOC_ARM_ALU_PC_G1:
21958 case BFD_RELOC_ARM_ALU_PC_G2:
21959 case BFD_RELOC_ARM_LDR_PC_G0:
21960 case BFD_RELOC_ARM_LDR_PC_G1:
21961 case BFD_RELOC_ARM_LDR_PC_G2:
21962 case BFD_RELOC_ARM_LDRS_PC_G0:
21963 case BFD_RELOC_ARM_LDRS_PC_G1:
21964 case BFD_RELOC_ARM_LDRS_PC_G2:
21965 case BFD_RELOC_ARM_LDC_PC_G0:
21966 case BFD_RELOC_ARM_LDC_PC_G1:
21967 case BFD_RELOC_ARM_LDC_PC_G2:
21968 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21969 case BFD_RELOC_ARM_ALU_SB_G0:
21970 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21971 case BFD_RELOC_ARM_ALU_SB_G1:
21972 case BFD_RELOC_ARM_ALU_SB_G2:
21973 case BFD_RELOC_ARM_LDR_SB_G0:
21974 case BFD_RELOC_ARM_LDR_SB_G1:
21975 case BFD_RELOC_ARM_LDR_SB_G2:
21976 case BFD_RELOC_ARM_LDRS_SB_G0:
21977 case BFD_RELOC_ARM_LDRS_SB_G1:
21978 case BFD_RELOC_ARM_LDRS_SB_G2:
21979 case BFD_RELOC_ARM_LDC_SB_G0:
21980 case BFD_RELOC_ARM_LDC_SB_G1:
21981 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 21982 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
21983 code = fixp->fx_r_type;
21984 break;
a737bd4d 21985
0855e32b 21986 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
21987 case BFD_RELOC_ARM_TLS_GD32:
21988 case BFD_RELOC_ARM_TLS_IE32:
21989 case BFD_RELOC_ARM_TLS_LDM32:
21990 /* BFD will include the symbol's address in the addend.
21991 But we don't want that, so subtract it out again here. */
21992 if (!S_IS_COMMON (fixp->fx_addsy))
21993 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21994 code = fixp->fx_r_type;
21995 break;
21996#endif
a737bd4d 21997
c19d1205
ZW
21998 case BFD_RELOC_ARM_IMMEDIATE:
21999 as_bad_where (fixp->fx_file, fixp->fx_line,
22000 _("internal relocation (type: IMMEDIATE) not fixed up"));
22001 return NULL;
a737bd4d 22002
c19d1205
ZW
22003 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22004 as_bad_where (fixp->fx_file, fixp->fx_line,
22005 _("ADRL used for a symbol not defined in the same file"));
22006 return NULL;
a737bd4d 22007
c19d1205 22008 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
22009 if (section->use_rela_p)
22010 {
22011 code = fixp->fx_r_type;
22012 break;
22013 }
22014
c19d1205
ZW
22015 if (fixp->fx_addsy != NULL
22016 && !S_IS_DEFINED (fixp->fx_addsy)
22017 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 22018 {
c19d1205
ZW
22019 as_bad_where (fixp->fx_file, fixp->fx_line,
22020 _("undefined local label `%s'"),
22021 S_GET_NAME (fixp->fx_addsy));
22022 return NULL;
a737bd4d
NC
22023 }
22024
c19d1205
ZW
22025 as_bad_where (fixp->fx_file, fixp->fx_line,
22026 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
22027 return NULL;
a737bd4d 22028
c19d1205
ZW
22029 default:
22030 {
22031 char * type;
6c43fab6 22032
c19d1205
ZW
22033 switch (fixp->fx_r_type)
22034 {
22035 case BFD_RELOC_NONE: type = "NONE"; break;
22036 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
22037 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 22038 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
22039 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
22040 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
22041 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 22042 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 22043 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
22044 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
22045 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
22046 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
22047 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
22048 default: type = _("<unknown>"); break;
22049 }
22050 as_bad_where (fixp->fx_file, fixp->fx_line,
22051 _("cannot represent %s relocation in this object file format"),
22052 type);
22053 return NULL;
22054 }
a737bd4d 22055 }
6c43fab6 22056
c19d1205
ZW
22057#ifdef OBJ_ELF
22058 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
22059 && GOT_symbol
22060 && fixp->fx_addsy == GOT_symbol)
22061 {
22062 code = BFD_RELOC_ARM_GOTPC;
22063 reloc->addend = fixp->fx_offset = reloc->address;
22064 }
22065#endif
6c43fab6 22066
c19d1205 22067 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 22068
c19d1205
ZW
22069 if (reloc->howto == NULL)
22070 {
22071 as_bad_where (fixp->fx_file, fixp->fx_line,
22072 _("cannot represent %s relocation in this object file format"),
22073 bfd_get_reloc_code_name (code));
22074 return NULL;
22075 }
6c43fab6 22076
c19d1205
ZW
22077 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
22078 vtable entry to be used in the relocation's section offset. */
22079 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
22080 reloc->address = fixp->fx_offset;
6c43fab6 22081
c19d1205 22082 return reloc;
6c43fab6
RE
22083}
22084
c19d1205 22085/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 22086
c19d1205
ZW
22087void
22088cons_fix_new_arm (fragS * frag,
22089 int where,
22090 int size,
22091 expressionS * exp)
6c43fab6 22092{
c19d1205
ZW
22093 bfd_reloc_code_real_type type;
22094 int pcrel = 0;
6c43fab6 22095
c19d1205
ZW
22096 /* Pick a reloc.
22097 FIXME: @@ Should look at CPU word size. */
22098 switch (size)
22099 {
22100 case 1:
22101 type = BFD_RELOC_8;
22102 break;
22103 case 2:
22104 type = BFD_RELOC_16;
22105 break;
22106 case 4:
22107 default:
22108 type = BFD_RELOC_32;
22109 break;
22110 case 8:
22111 type = BFD_RELOC_64;
22112 break;
22113 }
6c43fab6 22114
f0927246
NC
22115#ifdef TE_PE
22116 if (exp->X_op == O_secrel)
22117 {
22118 exp->X_op = O_symbol;
22119 type = BFD_RELOC_32_SECREL;
22120 }
22121#endif
22122
c19d1205
ZW
22123 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
22124}
6c43fab6 22125
4343666d 22126#if defined (OBJ_COFF)
c19d1205
ZW
22127void
22128arm_validate_fix (fixS * fixP)
6c43fab6 22129{
c19d1205
ZW
22130 /* If the destination of the branch is a defined symbol which does not have
22131 the THUMB_FUNC attribute, then we must be calling a function which has
22132 the (interfacearm) attribute. We look for the Thumb entry point to that
22133 function and change the branch to refer to that function instead. */
22134 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
22135 && fixP->fx_addsy != NULL
22136 && S_IS_DEFINED (fixP->fx_addsy)
22137 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 22138 {
c19d1205 22139 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 22140 }
c19d1205
ZW
22141}
22142#endif
6c43fab6 22143
267bf995 22144
c19d1205
ZW
22145int
22146arm_force_relocation (struct fix * fixp)
22147{
22148#if defined (OBJ_COFF) && defined (TE_PE)
22149 if (fixp->fx_r_type == BFD_RELOC_RVA)
22150 return 1;
22151#endif
6c43fab6 22152
267bf995
RR
22153 /* In case we have a call or a branch to a function in ARM ISA mode from
22154 a thumb function or vice-versa force the relocation. These relocations
22155 are cleared off for some cores that might have blx and simple transformations
22156 are possible. */
22157
22158#ifdef OBJ_ELF
22159 switch (fixp->fx_r_type)
22160 {
22161 case BFD_RELOC_ARM_PCREL_JUMP:
22162 case BFD_RELOC_ARM_PCREL_CALL:
22163 case BFD_RELOC_THUMB_PCREL_BLX:
22164 if (THUMB_IS_FUNC (fixp->fx_addsy))
22165 return 1;
22166 break;
22167
22168 case BFD_RELOC_ARM_PCREL_BLX:
22169 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22170 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22171 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22172 if (ARM_IS_FUNC (fixp->fx_addsy))
22173 return 1;
22174 break;
22175
22176 default:
22177 break;
22178 }
22179#endif
22180
b5884301
PB
22181 /* Resolve these relocations even if the symbol is extern or weak.
22182 Technically this is probably wrong due to symbol preemption.
22183 In practice these relocations do not have enough range to be useful
22184 at dynamic link time, and some code (e.g. in the Linux kernel)
22185 expects these references to be resolved. */
c19d1205
ZW
22186 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
22187 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 22188 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 22189 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
22190 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22191 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
22192 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 22193 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
22194 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22195 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
22196 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
22197 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
22198 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
22199 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 22200 return 0;
a737bd4d 22201
4962c51a
MS
22202 /* Always leave these relocations for the linker. */
22203 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22204 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22205 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
22206 return 1;
22207
f0291e4c
PB
22208 /* Always generate relocations against function symbols. */
22209 if (fixp->fx_r_type == BFD_RELOC_32
22210 && fixp->fx_addsy
22211 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
22212 return 1;
22213
c19d1205 22214 return generic_force_reloc (fixp);
404ff6b5
AH
22215}
22216
0ffdc86c 22217#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
22218/* Relocations against function names must be left unadjusted,
22219 so that the linker can use this information to generate interworking
22220 stubs. The MIPS version of this function
c19d1205
ZW
22221 also prevents relocations that are mips-16 specific, but I do not
22222 know why it does this.
404ff6b5 22223
c19d1205
ZW
22224 FIXME:
22225 There is one other problem that ought to be addressed here, but
22226 which currently is not: Taking the address of a label (rather
22227 than a function) and then later jumping to that address. Such
22228 addresses also ought to have their bottom bit set (assuming that
22229 they reside in Thumb code), but at the moment they will not. */
404ff6b5 22230
c19d1205
ZW
22231bfd_boolean
22232arm_fix_adjustable (fixS * fixP)
404ff6b5 22233{
c19d1205
ZW
22234 if (fixP->fx_addsy == NULL)
22235 return 1;
404ff6b5 22236
e28387c3
PB
22237 /* Preserve relocations against symbols with function type. */
22238 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 22239 return FALSE;
e28387c3 22240
c19d1205
ZW
22241 if (THUMB_IS_FUNC (fixP->fx_addsy)
22242 && fixP->fx_subsy == NULL)
c921be7d 22243 return FALSE;
a737bd4d 22244
c19d1205
ZW
22245 /* We need the symbol name for the VTABLE entries. */
22246 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
22247 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 22248 return FALSE;
404ff6b5 22249
c19d1205
ZW
22250 /* Don't allow symbols to be discarded on GOT related relocs. */
22251 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
22252 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
22253 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
22254 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
22255 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
22256 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
22257 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
22258 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
22259 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
22260 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
22261 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
22262 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
22263 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 22264 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 22265 return FALSE;
a737bd4d 22266
4962c51a
MS
22267 /* Similarly for group relocations. */
22268 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22269 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22270 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 22271 return FALSE;
4962c51a 22272
79947c54
CD
22273 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
22274 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
22275 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
22276 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
22277 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
22278 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
22279 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
22280 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
22281 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 22282 return FALSE;
79947c54 22283
c921be7d 22284 return TRUE;
a737bd4d 22285}
0ffdc86c
NC
22286#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
22287
22288#ifdef OBJ_ELF
404ff6b5 22289
c19d1205
ZW
22290const char *
22291elf32_arm_target_format (void)
404ff6b5 22292{
c19d1205
ZW
22293#ifdef TE_SYMBIAN
22294 return (target_big_endian
22295 ? "elf32-bigarm-symbian"
22296 : "elf32-littlearm-symbian");
22297#elif defined (TE_VXWORKS)
22298 return (target_big_endian
22299 ? "elf32-bigarm-vxworks"
22300 : "elf32-littlearm-vxworks");
b38cadfb
NC
22301#elif defined (TE_NACL)
22302 return (target_big_endian
22303 ? "elf32-bigarm-nacl"
22304 : "elf32-littlearm-nacl");
c19d1205
ZW
22305#else
22306 if (target_big_endian)
22307 return "elf32-bigarm";
22308 else
22309 return "elf32-littlearm";
22310#endif
404ff6b5
AH
22311}
22312
c19d1205
ZW
22313void
22314armelf_frob_symbol (symbolS * symp,
22315 int * puntp)
404ff6b5 22316{
c19d1205
ZW
22317 elf_frob_symbol (symp, puntp);
22318}
22319#endif
404ff6b5 22320
c19d1205 22321/* MD interface: Finalization. */
a737bd4d 22322
c19d1205
ZW
22323void
22324arm_cleanup (void)
22325{
22326 literal_pool * pool;
a737bd4d 22327
e07e6e58
NC
22328 /* Ensure that all the IT blocks are properly closed. */
22329 check_it_blocks_finished ();
22330
c19d1205
ZW
22331 for (pool = list_of_pools; pool; pool = pool->next)
22332 {
5f4273c7 22333 /* Put it at the end of the relevant section. */
c19d1205
ZW
22334 subseg_set (pool->section, pool->sub_section);
22335#ifdef OBJ_ELF
22336 arm_elf_change_section ();
22337#endif
22338 s_ltorg (0);
22339 }
404ff6b5
AH
22340}
22341
cd000bff
DJ
22342#ifdef OBJ_ELF
22343/* Remove any excess mapping symbols generated for alignment frags in
22344 SEC. We may have created a mapping symbol before a zero byte
22345 alignment; remove it if there's a mapping symbol after the
22346 alignment. */
22347static void
22348check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
22349 void *dummy ATTRIBUTE_UNUSED)
22350{
22351 segment_info_type *seginfo = seg_info (sec);
22352 fragS *fragp;
22353
22354 if (seginfo == NULL || seginfo->frchainP == NULL)
22355 return;
22356
22357 for (fragp = seginfo->frchainP->frch_root;
22358 fragp != NULL;
22359 fragp = fragp->fr_next)
22360 {
22361 symbolS *sym = fragp->tc_frag_data.last_map;
22362 fragS *next = fragp->fr_next;
22363
22364 /* Variable-sized frags have been converted to fixed size by
22365 this point. But if this was variable-sized to start with,
22366 there will be a fixed-size frag after it. So don't handle
22367 next == NULL. */
22368 if (sym == NULL || next == NULL)
22369 continue;
22370
22371 if (S_GET_VALUE (sym) < next->fr_address)
22372 /* Not at the end of this frag. */
22373 continue;
22374 know (S_GET_VALUE (sym) == next->fr_address);
22375
22376 do
22377 {
22378 if (next->tc_frag_data.first_map != NULL)
22379 {
22380 /* Next frag starts with a mapping symbol. Discard this
22381 one. */
22382 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22383 break;
22384 }
22385
22386 if (next->fr_next == NULL)
22387 {
22388 /* This mapping symbol is at the end of the section. Discard
22389 it. */
22390 know (next->fr_fix == 0 && next->fr_var == 0);
22391 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22392 break;
22393 }
22394
22395 /* As long as we have empty frags without any mapping symbols,
22396 keep looking. */
22397 /* If the next frag is non-empty and does not start with a
22398 mapping symbol, then this mapping symbol is required. */
22399 if (next->fr_address != next->fr_next->fr_address)
22400 break;
22401
22402 next = next->fr_next;
22403 }
22404 while (next != NULL);
22405 }
22406}
22407#endif
22408
c19d1205
ZW
22409/* Adjust the symbol table. This marks Thumb symbols as distinct from
22410 ARM ones. */
404ff6b5 22411
c19d1205
ZW
22412void
22413arm_adjust_symtab (void)
404ff6b5 22414{
c19d1205
ZW
22415#ifdef OBJ_COFF
22416 symbolS * sym;
404ff6b5 22417
c19d1205
ZW
22418 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
22419 {
22420 if (ARM_IS_THUMB (sym))
22421 {
22422 if (THUMB_IS_FUNC (sym))
22423 {
22424 /* Mark the symbol as a Thumb function. */
22425 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
22426 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
22427 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 22428
c19d1205
ZW
22429 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
22430 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
22431 else
22432 as_bad (_("%s: unexpected function type: %d"),
22433 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
22434 }
22435 else switch (S_GET_STORAGE_CLASS (sym))
22436 {
22437 case C_EXT:
22438 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
22439 break;
22440 case C_STAT:
22441 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
22442 break;
22443 case C_LABEL:
22444 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
22445 break;
22446 default:
22447 /* Do nothing. */
22448 break;
22449 }
22450 }
a737bd4d 22451
c19d1205
ZW
22452 if (ARM_IS_INTERWORK (sym))
22453 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 22454 }
c19d1205
ZW
22455#endif
22456#ifdef OBJ_ELF
22457 symbolS * sym;
22458 char bind;
404ff6b5 22459
c19d1205 22460 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 22461 {
c19d1205
ZW
22462 if (ARM_IS_THUMB (sym))
22463 {
22464 elf_symbol_type * elf_sym;
404ff6b5 22465
c19d1205
ZW
22466 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
22467 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 22468
b0796911
PB
22469 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
22470 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
22471 {
22472 /* If it's a .thumb_func, declare it as so,
22473 otherwise tag label as .code 16. */
22474 if (THUMB_IS_FUNC (sym))
35fc36a8
RS
22475 elf_sym->internal_elf_sym.st_target_internal
22476 = ST_BRANCH_TO_THUMB;
3ba67470 22477 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
22478 elf_sym->internal_elf_sym.st_info =
22479 ELF_ST_INFO (bind, STT_ARM_16BIT);
22480 }
22481 }
22482 }
cd000bff
DJ
22483
22484 /* Remove any overlapping mapping symbols generated by alignment frags. */
22485 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
22486 /* Now do generic ELF adjustments. */
22487 elf_adjust_symtab ();
c19d1205 22488#endif
404ff6b5
AH
22489}
22490
c19d1205 22491/* MD interface: Initialization. */
404ff6b5 22492
a737bd4d 22493static void
c19d1205 22494set_constant_flonums (void)
a737bd4d 22495{
c19d1205 22496 int i;
404ff6b5 22497
c19d1205
ZW
22498 for (i = 0; i < NUM_FLOAT_VALS; i++)
22499 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
22500 abort ();
a737bd4d 22501}
404ff6b5 22502
3e9e4fcf
JB
22503/* Auto-select Thumb mode if it's the only available instruction set for the
22504 given architecture. */
22505
22506static void
22507autoselect_thumb_from_cpu_variant (void)
22508{
22509 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
22510 opcode_select (16);
22511}
22512
c19d1205
ZW
22513void
22514md_begin (void)
a737bd4d 22515{
c19d1205
ZW
22516 unsigned mach;
22517 unsigned int i;
404ff6b5 22518
c19d1205
ZW
22519 if ( (arm_ops_hsh = hash_new ()) == NULL
22520 || (arm_cond_hsh = hash_new ()) == NULL
22521 || (arm_shift_hsh = hash_new ()) == NULL
22522 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 22523 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 22524 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
22525 || (arm_reloc_hsh = hash_new ()) == NULL
22526 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
22527 as_fatal (_("virtual memory exhausted"));
22528
22529 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 22530 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 22531 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 22532 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 22533 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 22534 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 22535 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 22536 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 22537 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0
NC
22538 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
22539 (void *) (v7m_psrs + i));
c19d1205 22540 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 22541 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
22542 for (i = 0;
22543 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
22544 i++)
d3ce72d0 22545 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 22546 (void *) (barrier_opt_names + i));
c19d1205 22547#ifdef OBJ_ELF
3da1d841
NC
22548 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
22549 {
22550 struct reloc_entry * entry = reloc_names + i;
22551
22552 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
22553 /* This makes encode_branch() use the EABI versions of this relocation. */
22554 entry->reloc = BFD_RELOC_UNUSED;
22555
22556 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
22557 }
c19d1205
ZW
22558#endif
22559
22560 set_constant_flonums ();
404ff6b5 22561
c19d1205
ZW
22562 /* Set the cpu variant based on the command-line options. We prefer
22563 -mcpu= over -march= if both are set (as for GCC); and we prefer
22564 -mfpu= over any other way of setting the floating point unit.
22565 Use of legacy options with new options are faulted. */
e74cfd16 22566 if (legacy_cpu)
404ff6b5 22567 {
e74cfd16 22568 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
22569 as_bad (_("use of old and new-style options to set CPU type"));
22570
22571 mcpu_cpu_opt = legacy_cpu;
404ff6b5 22572 }
e74cfd16 22573 else if (!mcpu_cpu_opt)
c19d1205 22574 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 22575
e74cfd16 22576 if (legacy_fpu)
c19d1205 22577 {
e74cfd16 22578 if (mfpu_opt)
c19d1205 22579 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
22580
22581 mfpu_opt = legacy_fpu;
22582 }
e74cfd16 22583 else if (!mfpu_opt)
03b1477f 22584 {
45eb4c1b
NS
22585#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
22586 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
22587 /* Some environments specify a default FPU. If they don't, infer it
22588 from the processor. */
e74cfd16 22589 if (mcpu_fpu_opt)
03b1477f
RE
22590 mfpu_opt = mcpu_fpu_opt;
22591 else
22592 mfpu_opt = march_fpu_opt;
39c2da32 22593#else
e74cfd16 22594 mfpu_opt = &fpu_default;
39c2da32 22595#endif
03b1477f
RE
22596 }
22597
e74cfd16 22598 if (!mfpu_opt)
03b1477f 22599 {
493cb6ef 22600 if (mcpu_cpu_opt != NULL)
e74cfd16 22601 mfpu_opt = &fpu_default;
493cb6ef 22602 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 22603 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 22604 else
e74cfd16 22605 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
22606 }
22607
ee065d83 22608#ifdef CPU_DEFAULT
e74cfd16 22609 if (!mcpu_cpu_opt)
ee065d83 22610 {
e74cfd16
PB
22611 mcpu_cpu_opt = &cpu_default;
22612 selected_cpu = cpu_default;
ee065d83 22613 }
e74cfd16
PB
22614#else
22615 if (mcpu_cpu_opt)
22616 selected_cpu = *mcpu_cpu_opt;
ee065d83 22617 else
e74cfd16 22618 mcpu_cpu_opt = &arm_arch_any;
ee065d83 22619#endif
03b1477f 22620
e74cfd16 22621 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 22622
3e9e4fcf
JB
22623 autoselect_thumb_from_cpu_variant ();
22624
e74cfd16 22625 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 22626
f17c130b 22627#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 22628 {
7cc69913
NC
22629 unsigned int flags = 0;
22630
22631#if defined OBJ_ELF
22632 flags = meabi_flags;
d507cf36
PB
22633
22634 switch (meabi_flags)
33a392fb 22635 {
d507cf36 22636 case EF_ARM_EABI_UNKNOWN:
7cc69913 22637#endif
d507cf36
PB
22638 /* Set the flags in the private structure. */
22639 if (uses_apcs_26) flags |= F_APCS26;
22640 if (support_interwork) flags |= F_INTERWORK;
22641 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 22642 if (pic_code) flags |= F_PIC;
e74cfd16 22643 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
22644 flags |= F_SOFT_FLOAT;
22645
d507cf36
PB
22646 switch (mfloat_abi_opt)
22647 {
22648 case ARM_FLOAT_ABI_SOFT:
22649 case ARM_FLOAT_ABI_SOFTFP:
22650 flags |= F_SOFT_FLOAT;
22651 break;
33a392fb 22652
d507cf36
PB
22653 case ARM_FLOAT_ABI_HARD:
22654 if (flags & F_SOFT_FLOAT)
22655 as_bad (_("hard-float conflicts with specified fpu"));
22656 break;
22657 }
03b1477f 22658
e74cfd16
PB
22659 /* Using pure-endian doubles (even if soft-float). */
22660 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 22661 flags |= F_VFP_FLOAT;
f17c130b 22662
fde78edd 22663#if defined OBJ_ELF
e74cfd16 22664 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 22665 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
22666 break;
22667
8cb51566 22668 case EF_ARM_EABI_VER4:
3a4a14e9 22669 case EF_ARM_EABI_VER5:
c19d1205 22670 /* No additional flags to set. */
d507cf36
PB
22671 break;
22672
22673 default:
22674 abort ();
22675 }
7cc69913 22676#endif
b99bd4ef
NC
22677 bfd_set_private_flags (stdoutput, flags);
22678
22679 /* We have run out flags in the COFF header to encode the
22680 status of ATPCS support, so instead we create a dummy,
c19d1205 22681 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
22682 if (atpcs)
22683 {
22684 asection * sec;
22685
22686 sec = bfd_make_section (stdoutput, ".arm.atpcs");
22687
22688 if (sec != NULL)
22689 {
22690 bfd_set_section_flags
22691 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
22692 bfd_set_section_size (stdoutput, sec, 0);
22693 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
22694 }
22695 }
7cc69913 22696 }
f17c130b 22697#endif
b99bd4ef
NC
22698
22699 /* Record the CPU type as well. */
2d447fca
JM
22700 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
22701 mach = bfd_mach_arm_iWMMXt2;
22702 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 22703 mach = bfd_mach_arm_iWMMXt;
e74cfd16 22704 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 22705 mach = bfd_mach_arm_XScale;
e74cfd16 22706 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 22707 mach = bfd_mach_arm_ep9312;
e74cfd16 22708 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 22709 mach = bfd_mach_arm_5TE;
e74cfd16 22710 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 22711 {
e74cfd16 22712 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22713 mach = bfd_mach_arm_5T;
22714 else
22715 mach = bfd_mach_arm_5;
22716 }
e74cfd16 22717 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 22718 {
e74cfd16 22719 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22720 mach = bfd_mach_arm_4T;
22721 else
22722 mach = bfd_mach_arm_4;
22723 }
e74cfd16 22724 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 22725 mach = bfd_mach_arm_3M;
e74cfd16
PB
22726 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
22727 mach = bfd_mach_arm_3;
22728 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
22729 mach = bfd_mach_arm_2a;
22730 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
22731 mach = bfd_mach_arm_2;
22732 else
22733 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
22734
22735 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
22736}
22737
c19d1205 22738/* Command line processing. */
b99bd4ef 22739
c19d1205
ZW
22740/* md_parse_option
22741 Invocation line includes a switch not recognized by the base assembler.
22742 See if it's a processor-specific option.
b99bd4ef 22743
c19d1205
ZW
22744 This routine is somewhat complicated by the need for backwards
22745 compatibility (since older releases of gcc can't be changed).
22746 The new options try to make the interface as compatible as
22747 possible with GCC.
b99bd4ef 22748
c19d1205 22749 New options (supported) are:
b99bd4ef 22750
c19d1205
ZW
22751 -mcpu=<cpu name> Assemble for selected processor
22752 -march=<architecture name> Assemble for selected architecture
22753 -mfpu=<fpu architecture> Assemble for selected FPU.
22754 -EB/-mbig-endian Big-endian
22755 -EL/-mlittle-endian Little-endian
22756 -k Generate PIC code
22757 -mthumb Start in Thumb mode
22758 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 22759
278df34e 22760 -m[no-]warn-deprecated Warn about deprecated features
267bf995 22761
c19d1205 22762 For now we will also provide support for:
b99bd4ef 22763
c19d1205
ZW
22764 -mapcs-32 32-bit Program counter
22765 -mapcs-26 26-bit Program counter
22766 -macps-float Floats passed in FP registers
22767 -mapcs-reentrant Reentrant code
22768 -matpcs
22769 (sometime these will probably be replaced with -mapcs=<list of options>
22770 and -matpcs=<list of options>)
b99bd4ef 22771
c19d1205
ZW
22772 The remaining options are only supported for back-wards compatibility.
22773 Cpu variants, the arm part is optional:
22774 -m[arm]1 Currently not supported.
22775 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
22776 -m[arm]3 Arm 3 processor
22777 -m[arm]6[xx], Arm 6 processors
22778 -m[arm]7[xx][t][[d]m] Arm 7 processors
22779 -m[arm]8[10] Arm 8 processors
22780 -m[arm]9[20][tdmi] Arm 9 processors
22781 -mstrongarm[110[0]] StrongARM processors
22782 -mxscale XScale processors
22783 -m[arm]v[2345[t[e]]] Arm architectures
22784 -mall All (except the ARM1)
22785 FP variants:
22786 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
22787 -mfpe-old (No float load/store multiples)
22788 -mvfpxd VFP Single precision
22789 -mvfp All VFP
22790 -mno-fpu Disable all floating point instructions
b99bd4ef 22791
c19d1205
ZW
22792 The following CPU names are recognized:
22793 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
22794 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
22795 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
22796 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
22797 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
22798 arm10t arm10e, arm1020t, arm1020e, arm10200e,
22799 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 22800
c19d1205 22801 */
b99bd4ef 22802
c19d1205 22803const char * md_shortopts = "m:k";
b99bd4ef 22804
c19d1205
ZW
22805#ifdef ARM_BI_ENDIAN
22806#define OPTION_EB (OPTION_MD_BASE + 0)
22807#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 22808#else
c19d1205
ZW
22809#if TARGET_BYTES_BIG_ENDIAN
22810#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 22811#else
c19d1205
ZW
22812#define OPTION_EL (OPTION_MD_BASE + 1)
22813#endif
b99bd4ef 22814#endif
845b51d6 22815#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 22816
c19d1205 22817struct option md_longopts[] =
b99bd4ef 22818{
c19d1205
ZW
22819#ifdef OPTION_EB
22820 {"EB", no_argument, NULL, OPTION_EB},
22821#endif
22822#ifdef OPTION_EL
22823 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 22824#endif
845b51d6 22825 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
22826 {NULL, no_argument, NULL, 0}
22827};
b99bd4ef 22828
c19d1205 22829size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 22830
c19d1205 22831struct arm_option_table
b99bd4ef 22832{
c19d1205
ZW
22833 char *option; /* Option name to match. */
22834 char *help; /* Help information. */
22835 int *var; /* Variable to change. */
22836 int value; /* What to change it to. */
22837 char *deprecated; /* If non-null, print this message. */
22838};
b99bd4ef 22839
c19d1205
ZW
22840struct arm_option_table arm_opts[] =
22841{
22842 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
22843 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
22844 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
22845 &support_interwork, 1, NULL},
22846 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
22847 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
22848 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
22849 1, NULL},
22850 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
22851 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
22852 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
22853 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
22854 NULL},
b99bd4ef 22855
c19d1205
ZW
22856 /* These are recognized by the assembler, but have no affect on code. */
22857 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
22858 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
22859
22860 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
22861 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
22862 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
22863 {NULL, NULL, NULL, 0, NULL}
22864};
22865
22866struct arm_legacy_option_table
22867{
22868 char *option; /* Option name to match. */
22869 const arm_feature_set **var; /* Variable to change. */
22870 const arm_feature_set value; /* What to change it to. */
22871 char *deprecated; /* If non-null, print this message. */
22872};
b99bd4ef 22873
e74cfd16
PB
22874const struct arm_legacy_option_table arm_legacy_opts[] =
22875{
c19d1205
ZW
22876 /* DON'T add any new processors to this list -- we want the whole list
22877 to go away... Add them to the processors table instead. */
e74cfd16
PB
22878 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22879 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22880 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22881 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22882 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22883 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22884 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22885 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22886 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22887 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22888 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22889 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22890 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22891 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22892 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22893 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22894 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22895 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22896 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22897 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22898 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22899 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22900 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22901 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22902 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22903 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22904 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22905 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22906 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22907 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22908 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22909 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22910 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22911 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22912 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22913 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22914 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22915 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22916 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22917 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22918 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22919 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22920 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22921 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22922 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22923 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22924 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22925 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22926 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22927 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22928 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22929 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22930 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22931 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22932 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22933 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22934 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22935 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22936 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22937 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22938 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22939 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22940 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22941 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22942 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22943 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22944 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22945 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22946 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22947 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22948 N_("use -mcpu=strongarm110")},
e74cfd16 22949 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22950 N_("use -mcpu=strongarm1100")},
e74cfd16 22951 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22952 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
22953 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22954 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22955 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 22956
c19d1205 22957 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
22958 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22959 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22960 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22961 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22962 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22963 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22964 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22965 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22966 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22967 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22968 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22969 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22970 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22971 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22972 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22973 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22974 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22975 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 22976
c19d1205 22977 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
22978 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22979 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22980 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22981 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 22982 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 22983
e74cfd16 22984 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 22985};
7ed4c4c5 22986
c19d1205 22987struct arm_cpu_option_table
7ed4c4c5 22988{
c19d1205 22989 char *name;
f3bad469 22990 size_t name_len;
e74cfd16 22991 const arm_feature_set value;
c19d1205
ZW
22992 /* For some CPUs we assume an FPU unless the user explicitly sets
22993 -mfpu=... */
e74cfd16 22994 const arm_feature_set default_fpu;
ee065d83
PB
22995 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22996 case. */
22997 const char *canonical_name;
c19d1205 22998};
7ed4c4c5 22999
c19d1205
ZW
23000/* This list should, at a minimum, contain all the cpu names
23001 recognized by GCC. */
f3bad469 23002#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 23003static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 23004{
f3bad469
MGD
23005 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
23006 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
23007 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
23008 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
23009 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
23010 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23011 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23012 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23013 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23014 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23015 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23016 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23017 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23018 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23019 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23020 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23021 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23022 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23023 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23024 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23025 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23026 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23027 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23028 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23029 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23030 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23031 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23032 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23033 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23034 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23035 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23036 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23037 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23038 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23039 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23040 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23041 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23042 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23043 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23044 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
23045 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23046 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23047 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23048 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23049 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23050 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
23051 /* For V5 or later processors we default to using VFP; but the user
23052 should really set the FPU type explicitly. */
f3bad469
MGD
23053 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23054 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23055 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
23056 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
23057 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
23058 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23059 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
23060 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23061 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23062 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
23063 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23064 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23065 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23066 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23067 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23068 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
23069 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23070 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23071 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23072 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
23073 "ARM1026EJ-S"),
23074 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
23075 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23076 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23077 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23078 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23079 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23080 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
23081 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
23082 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
23083 "ARM1136JF-S"),
23084 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
23085 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
23086 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
23087 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
23088 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
23089 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL),
23090 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL),
23091 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
23092 FPU_NONE, "Cortex-A5"),
23093 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
23094 FPU_ARCH_NEON_VFP_V4,
23095 "Cortex-A7"),
23096 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
23097 ARM_FEATURE (0, FPU_VFP_V3
5287ad62 23098 | FPU_NEON_EXT_V1),
f3bad469
MGD
23099 "Cortex-A8"),
23100 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
23101 ARM_FEATURE (0, FPU_VFP_V3
15290f0a 23102 | FPU_NEON_EXT_V1),
f3bad469
MGD
23103 "Cortex-A9"),
23104 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
23105 FPU_ARCH_NEON_VFP_V4,
23106 "Cortex-A15"),
23107 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
23108 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
23109 "Cortex-R4F"),
23110 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
23111 FPU_NONE, "Cortex-R5"),
23112 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
23113 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
23114 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
23115 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 23116 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
c19d1205 23117 /* ??? XSCALE is really an architecture. */
f3bad469 23118 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 23119 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
23120 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
23121 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
23122 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 23123 /* Maverick */
f3bad469
MGD
23124 ARM_CPU_OPT ("ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
23125 FPU_ARCH_MAVERICK,
23126 "ARM920T"),
23127 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 23128};
f3bad469 23129#undef ARM_CPU_OPT
7ed4c4c5 23130
c19d1205 23131struct arm_arch_option_table
7ed4c4c5 23132{
c19d1205 23133 char *name;
f3bad469 23134 size_t name_len;
e74cfd16
PB
23135 const arm_feature_set value;
23136 const arm_feature_set default_fpu;
c19d1205 23137};
7ed4c4c5 23138
c19d1205
ZW
23139/* This list should, at a minimum, contain all the architecture names
23140 recognized by GCC. */
f3bad469 23141#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 23142static const struct arm_arch_option_table arm_archs[] =
c19d1205 23143{
f3bad469
MGD
23144 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
23145 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
23146 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
23147 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
23148 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
23149 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
23150 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
23151 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
23152 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
23153 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
23154 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
23155 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
23156 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
23157 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
23158 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
23159 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
23160 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
23161 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
23162 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
23163 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
23164 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
23165 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP),
23166 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
23167 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
23168 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
23169 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP),
23170 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
23171 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
23172 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
23173 /* The official spelling of the ARMv7 profile variants is the dashed form.
23174 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469
MGD
23175 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
23176 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
23177 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
23178 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
23179 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
23180 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
23181 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
23182 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
23183 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
23184 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
23185 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 23186};
f3bad469 23187#undef ARM_ARCH_OPT
7ed4c4c5 23188
69133863
MGD
23189/* ISA extensions in the co-processor and main instruction set space. */
23190struct arm_option_extension_value_table
c19d1205
ZW
23191{
23192 char *name;
f3bad469 23193 size_t name_len;
e74cfd16 23194 const arm_feature_set value;
69133863 23195 const arm_feature_set allowed_archs;
c19d1205 23196};
7ed4c4c5 23197
69133863
MGD
23198/* The following table must be in alphabetical order with a NULL last entry.
23199 */
f3bad469 23200#define ARM_EXT_OPT(N, V, AA) { N, sizeof (N) - 1, V, AA }
69133863 23201static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 23202{
f3bad469
MGD
23203 ARM_EXT_OPT ("idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0),
23204 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
23205 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY),
23206 ARM_EXT_OPT ("iwmmxt2",
23207 ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY),
23208 ARM_EXT_OPT ("maverick",
23209 ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY),
23210 ARM_EXT_OPT ("mp", ARM_FEATURE (ARM_EXT_MP, 0),
23211 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
23212 ARM_EXT_OPT ("os", ARM_FEATURE (ARM_EXT_OS, 0),
23213 ARM_FEATURE (ARM_EXT_V6M, 0)),
23214 ARM_EXT_OPT ("sec", ARM_FEATURE (ARM_EXT_SEC, 0),
23215 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)),
23216 ARM_EXT_OPT ("virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV
23217 | ARM_EXT_DIV, 0),
23218 ARM_FEATURE (ARM_EXT_V7A, 0)),
23219 ARM_EXT_OPT ("xscale",ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY),
23220 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
69133863 23221};
f3bad469 23222#undef ARM_EXT_OPT
69133863
MGD
23223
23224/* ISA floating-point and Advanced SIMD extensions. */
23225struct arm_option_fpu_value_table
23226{
23227 char *name;
23228 const arm_feature_set value;
c19d1205 23229};
7ed4c4c5 23230
c19d1205
ZW
23231/* This list should, at a minimum, contain all the fpu names
23232 recognized by GCC. */
69133863 23233static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
23234{
23235 {"softfpa", FPU_NONE},
23236 {"fpe", FPU_ARCH_FPE},
23237 {"fpe2", FPU_ARCH_FPE},
23238 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
23239 {"fpa", FPU_ARCH_FPA},
23240 {"fpa10", FPU_ARCH_FPA},
23241 {"fpa11", FPU_ARCH_FPA},
23242 {"arm7500fe", FPU_ARCH_FPA},
23243 {"softvfp", FPU_ARCH_VFP},
23244 {"softvfp+vfp", FPU_ARCH_VFP_V2},
23245 {"vfp", FPU_ARCH_VFP_V2},
23246 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 23247 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
23248 {"vfp10", FPU_ARCH_VFP_V2},
23249 {"vfp10-r0", FPU_ARCH_VFP_V1},
23250 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
23251 {"vfpv2", FPU_ARCH_VFP_V2},
23252 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 23253 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 23254 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
23255 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
23256 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
23257 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
23258 {"arm1020t", FPU_ARCH_VFP_V1},
23259 {"arm1020e", FPU_ARCH_VFP_V2},
23260 {"arm1136jfs", FPU_ARCH_VFP_V2},
23261 {"arm1136jf-s", FPU_ARCH_VFP_V2},
23262 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 23263 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 23264 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
23265 {"vfpv4", FPU_ARCH_VFP_V4},
23266 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 23267 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 23268 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
e74cfd16
PB
23269 {NULL, ARM_ARCH_NONE}
23270};
23271
23272struct arm_option_value_table
23273{
23274 char *name;
23275 long value;
c19d1205 23276};
7ed4c4c5 23277
e74cfd16 23278static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
23279{
23280 {"hard", ARM_FLOAT_ABI_HARD},
23281 {"softfp", ARM_FLOAT_ABI_SOFTFP},
23282 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 23283 {NULL, 0}
c19d1205 23284};
7ed4c4c5 23285
c19d1205 23286#ifdef OBJ_ELF
3a4a14e9 23287/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 23288static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
23289{
23290 {"gnu", EF_ARM_EABI_UNKNOWN},
23291 {"4", EF_ARM_EABI_VER4},
3a4a14e9 23292 {"5", EF_ARM_EABI_VER5},
e74cfd16 23293 {NULL, 0}
c19d1205
ZW
23294};
23295#endif
7ed4c4c5 23296
c19d1205
ZW
23297struct arm_long_option_table
23298{
23299 char * option; /* Substring to match. */
23300 char * help; /* Help information. */
23301 int (* func) (char * subopt); /* Function to decode sub-option. */
23302 char * deprecated; /* If non-null, print this message. */
23303};
7ed4c4c5 23304
c921be7d 23305static bfd_boolean
f3bad469 23306arm_parse_extension (char *str, const arm_feature_set **opt_p)
7ed4c4c5 23307{
21d799b5
NC
23308 arm_feature_set *ext_set = (arm_feature_set *)
23309 xmalloc (sizeof (arm_feature_set));
e74cfd16 23310
69133863 23311 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
23312 extensions being added before being removed. We achieve this by having
23313 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 23314 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 23315 or removing it (0) and only allowing it to change in the order
69133863
MGD
23316 -1 -> 1 -> 0. */
23317 const struct arm_option_extension_value_table * opt = NULL;
23318 int adding_value = -1;
23319
e74cfd16
PB
23320 /* Copy the feature set, so that we can modify it. */
23321 *ext_set = **opt_p;
23322 *opt_p = ext_set;
23323
c19d1205 23324 while (str != NULL && *str != 0)
7ed4c4c5 23325 {
f3bad469
MGD
23326 char *ext;
23327 size_t len;
7ed4c4c5 23328
c19d1205
ZW
23329 if (*str != '+')
23330 {
23331 as_bad (_("invalid architectural extension"));
c921be7d 23332 return FALSE;
c19d1205 23333 }
7ed4c4c5 23334
c19d1205
ZW
23335 str++;
23336 ext = strchr (str, '+');
7ed4c4c5 23337
c19d1205 23338 if (ext != NULL)
f3bad469 23339 len = ext - str;
c19d1205 23340 else
f3bad469 23341 len = strlen (str);
7ed4c4c5 23342
f3bad469 23343 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
23344 {
23345 if (adding_value != 0)
23346 {
23347 adding_value = 0;
23348 opt = arm_extensions;
23349 }
23350
f3bad469 23351 len -= 2;
69133863
MGD
23352 str += 2;
23353 }
f3bad469 23354 else if (len > 0)
69133863
MGD
23355 {
23356 if (adding_value == -1)
23357 {
23358 adding_value = 1;
23359 opt = arm_extensions;
23360 }
23361 else if (adding_value != 1)
23362 {
23363 as_bad (_("must specify extensions to add before specifying "
23364 "those to remove"));
23365 return FALSE;
23366 }
23367 }
23368
f3bad469 23369 if (len == 0)
c19d1205
ZW
23370 {
23371 as_bad (_("missing architectural extension"));
c921be7d 23372 return FALSE;
c19d1205 23373 }
7ed4c4c5 23374
69133863
MGD
23375 gas_assert (adding_value != -1);
23376 gas_assert (opt != NULL);
23377
23378 /* Scan over the options table trying to find an exact match. */
23379 for (; opt->name != NULL; opt++)
f3bad469 23380 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 23381 {
69133863
MGD
23382 /* Check we can apply the extension to this architecture. */
23383 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
23384 {
23385 as_bad (_("extension does not apply to the base architecture"));
23386 return FALSE;
23387 }
23388
23389 /* Add or remove the extension. */
23390 if (adding_value)
23391 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
23392 else
23393 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
23394
c19d1205
ZW
23395 break;
23396 }
7ed4c4c5 23397
c19d1205
ZW
23398 if (opt->name == NULL)
23399 {
69133863
MGD
23400 /* Did we fail to find an extension because it wasn't specified in
23401 alphabetical order, or because it does not exist? */
23402
23403 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 23404 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
23405 break;
23406
23407 if (opt->name == NULL)
23408 as_bad (_("unknown architectural extension `%s'"), str);
23409 else
23410 as_bad (_("architectural extensions must be specified in "
23411 "alphabetical order"));
23412
c921be7d 23413 return FALSE;
c19d1205 23414 }
69133863
MGD
23415 else
23416 {
23417 /* We should skip the extension we've just matched the next time
23418 round. */
23419 opt++;
23420 }
7ed4c4c5 23421
c19d1205
ZW
23422 str = ext;
23423 };
7ed4c4c5 23424
c921be7d 23425 return TRUE;
c19d1205 23426}
7ed4c4c5 23427
c921be7d 23428static bfd_boolean
f3bad469 23429arm_parse_cpu (char *str)
7ed4c4c5 23430{
f3bad469
MGD
23431 const struct arm_cpu_option_table *opt;
23432 char *ext = strchr (str, '+');
23433 size_t len;
7ed4c4c5 23434
c19d1205 23435 if (ext != NULL)
f3bad469 23436 len = ext - str;
7ed4c4c5 23437 else
f3bad469 23438 len = strlen (str);
7ed4c4c5 23439
f3bad469 23440 if (len == 0)
7ed4c4c5 23441 {
c19d1205 23442 as_bad (_("missing cpu name `%s'"), str);
c921be7d 23443 return FALSE;
7ed4c4c5
NC
23444 }
23445
c19d1205 23446 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 23447 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 23448 {
e74cfd16
PB
23449 mcpu_cpu_opt = &opt->value;
23450 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 23451 if (opt->canonical_name)
5f4273c7 23452 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
23453 else
23454 {
f3bad469 23455 size_t i;
c921be7d 23456
f3bad469 23457 for (i = 0; i < len; i++)
ee065d83
PB
23458 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23459 selected_cpu_name[i] = 0;
23460 }
7ed4c4c5 23461
c19d1205
ZW
23462 if (ext != NULL)
23463 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 23464
c921be7d 23465 return TRUE;
c19d1205 23466 }
7ed4c4c5 23467
c19d1205 23468 as_bad (_("unknown cpu `%s'"), str);
c921be7d 23469 return FALSE;
7ed4c4c5
NC
23470}
23471
c921be7d 23472static bfd_boolean
f3bad469 23473arm_parse_arch (char *str)
7ed4c4c5 23474{
e74cfd16 23475 const struct arm_arch_option_table *opt;
c19d1205 23476 char *ext = strchr (str, '+');
f3bad469 23477 size_t len;
7ed4c4c5 23478
c19d1205 23479 if (ext != NULL)
f3bad469 23480 len = ext - str;
7ed4c4c5 23481 else
f3bad469 23482 len = strlen (str);
7ed4c4c5 23483
f3bad469 23484 if (len == 0)
7ed4c4c5 23485 {
c19d1205 23486 as_bad (_("missing architecture name `%s'"), str);
c921be7d 23487 return FALSE;
7ed4c4c5
NC
23488 }
23489
c19d1205 23490 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 23491 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 23492 {
e74cfd16
PB
23493 march_cpu_opt = &opt->value;
23494 march_fpu_opt = &opt->default_fpu;
5f4273c7 23495 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 23496
c19d1205
ZW
23497 if (ext != NULL)
23498 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 23499
c921be7d 23500 return TRUE;
c19d1205
ZW
23501 }
23502
23503 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 23504 return FALSE;
7ed4c4c5 23505}
eb043451 23506
c921be7d 23507static bfd_boolean
c19d1205
ZW
23508arm_parse_fpu (char * str)
23509{
69133863 23510 const struct arm_option_fpu_value_table * opt;
b99bd4ef 23511
c19d1205
ZW
23512 for (opt = arm_fpus; opt->name != NULL; opt++)
23513 if (streq (opt->name, str))
23514 {
e74cfd16 23515 mfpu_opt = &opt->value;
c921be7d 23516 return TRUE;
c19d1205 23517 }
b99bd4ef 23518
c19d1205 23519 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 23520 return FALSE;
c19d1205
ZW
23521}
23522
c921be7d 23523static bfd_boolean
c19d1205 23524arm_parse_float_abi (char * str)
b99bd4ef 23525{
e74cfd16 23526 const struct arm_option_value_table * opt;
b99bd4ef 23527
c19d1205
ZW
23528 for (opt = arm_float_abis; opt->name != NULL; opt++)
23529 if (streq (opt->name, str))
23530 {
23531 mfloat_abi_opt = opt->value;
c921be7d 23532 return TRUE;
c19d1205 23533 }
cc8a6dd0 23534
c19d1205 23535 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 23536 return FALSE;
c19d1205 23537}
b99bd4ef 23538
c19d1205 23539#ifdef OBJ_ELF
c921be7d 23540static bfd_boolean
c19d1205
ZW
23541arm_parse_eabi (char * str)
23542{
e74cfd16 23543 const struct arm_option_value_table *opt;
cc8a6dd0 23544
c19d1205
ZW
23545 for (opt = arm_eabis; opt->name != NULL; opt++)
23546 if (streq (opt->name, str))
23547 {
23548 meabi_flags = opt->value;
c921be7d 23549 return TRUE;
c19d1205
ZW
23550 }
23551 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 23552 return FALSE;
c19d1205
ZW
23553}
23554#endif
cc8a6dd0 23555
c921be7d 23556static bfd_boolean
e07e6e58
NC
23557arm_parse_it_mode (char * str)
23558{
c921be7d 23559 bfd_boolean ret = TRUE;
e07e6e58
NC
23560
23561 if (streq ("arm", str))
23562 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
23563 else if (streq ("thumb", str))
23564 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
23565 else if (streq ("always", str))
23566 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
23567 else if (streq ("never", str))
23568 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
23569 else
23570 {
23571 as_bad (_("unknown implicit IT mode `%s', should be "\
23572 "arm, thumb, always, or never."), str);
c921be7d 23573 ret = FALSE;
e07e6e58
NC
23574 }
23575
23576 return ret;
23577}
23578
c19d1205
ZW
23579struct arm_long_option_table arm_long_opts[] =
23580{
23581 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
23582 arm_parse_cpu, NULL},
23583 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
23584 arm_parse_arch, NULL},
23585 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
23586 arm_parse_fpu, NULL},
23587 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
23588 arm_parse_float_abi, NULL},
23589#ifdef OBJ_ELF
7fac0536 23590 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
23591 arm_parse_eabi, NULL},
23592#endif
e07e6e58
NC
23593 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
23594 arm_parse_it_mode, NULL},
c19d1205
ZW
23595 {NULL, NULL, 0, NULL}
23596};
cc8a6dd0 23597
c19d1205
ZW
23598int
23599md_parse_option (int c, char * arg)
23600{
23601 struct arm_option_table *opt;
e74cfd16 23602 const struct arm_legacy_option_table *fopt;
c19d1205 23603 struct arm_long_option_table *lopt;
b99bd4ef 23604
c19d1205 23605 switch (c)
b99bd4ef 23606 {
c19d1205
ZW
23607#ifdef OPTION_EB
23608 case OPTION_EB:
23609 target_big_endian = 1;
23610 break;
23611#endif
cc8a6dd0 23612
c19d1205
ZW
23613#ifdef OPTION_EL
23614 case OPTION_EL:
23615 target_big_endian = 0;
23616 break;
23617#endif
b99bd4ef 23618
845b51d6
PB
23619 case OPTION_FIX_V4BX:
23620 fix_v4bx = TRUE;
23621 break;
23622
c19d1205
ZW
23623 case 'a':
23624 /* Listing option. Just ignore these, we don't support additional
23625 ones. */
23626 return 0;
b99bd4ef 23627
c19d1205
ZW
23628 default:
23629 for (opt = arm_opts; opt->option != NULL; opt++)
23630 {
23631 if (c == opt->option[0]
23632 && ((arg == NULL && opt->option[1] == 0)
23633 || streq (arg, opt->option + 1)))
23634 {
c19d1205 23635 /* If the option is deprecated, tell the user. */
278df34e 23636 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
23637 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23638 arg ? arg : "", _(opt->deprecated));
b99bd4ef 23639
c19d1205
ZW
23640 if (opt->var != NULL)
23641 *opt->var = opt->value;
cc8a6dd0 23642
c19d1205
ZW
23643 return 1;
23644 }
23645 }
b99bd4ef 23646
e74cfd16
PB
23647 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
23648 {
23649 if (c == fopt->option[0]
23650 && ((arg == NULL && fopt->option[1] == 0)
23651 || streq (arg, fopt->option + 1)))
23652 {
e74cfd16 23653 /* If the option is deprecated, tell the user. */
278df34e 23654 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
23655 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23656 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
23657
23658 if (fopt->var != NULL)
23659 *fopt->var = &fopt->value;
23660
23661 return 1;
23662 }
23663 }
23664
c19d1205
ZW
23665 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23666 {
23667 /* These options are expected to have an argument. */
23668 if (c == lopt->option[0]
23669 && arg != NULL
23670 && strncmp (arg, lopt->option + 1,
23671 strlen (lopt->option + 1)) == 0)
23672 {
c19d1205 23673 /* If the option is deprecated, tell the user. */
278df34e 23674 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
23675 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
23676 _(lopt->deprecated));
b99bd4ef 23677
c19d1205
ZW
23678 /* Call the sup-option parser. */
23679 return lopt->func (arg + strlen (lopt->option) - 1);
23680 }
23681 }
a737bd4d 23682
c19d1205
ZW
23683 return 0;
23684 }
a394c00f 23685
c19d1205
ZW
23686 return 1;
23687}
a394c00f 23688
c19d1205
ZW
23689void
23690md_show_usage (FILE * fp)
a394c00f 23691{
c19d1205
ZW
23692 struct arm_option_table *opt;
23693 struct arm_long_option_table *lopt;
a394c00f 23694
c19d1205 23695 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 23696
c19d1205
ZW
23697 for (opt = arm_opts; opt->option != NULL; opt++)
23698 if (opt->help != NULL)
23699 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 23700
c19d1205
ZW
23701 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23702 if (lopt->help != NULL)
23703 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 23704
c19d1205
ZW
23705#ifdef OPTION_EB
23706 fprintf (fp, _("\
23707 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
23708#endif
23709
c19d1205
ZW
23710#ifdef OPTION_EL
23711 fprintf (fp, _("\
23712 -EL assemble code for a little-endian cpu\n"));
a737bd4d 23713#endif
845b51d6
PB
23714
23715 fprintf (fp, _("\
23716 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 23717}
ee065d83
PB
23718
23719
23720#ifdef OBJ_ELF
62b3e311
PB
23721typedef struct
23722{
23723 int val;
23724 arm_feature_set flags;
23725} cpu_arch_ver_table;
23726
23727/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
23728 least features first. */
23729static const cpu_arch_ver_table cpu_arch_ver[] =
23730{
23731 {1, ARM_ARCH_V4},
23732 {2, ARM_ARCH_V4T},
23733 {3, ARM_ARCH_V5},
ee3c0378 23734 {3, ARM_ARCH_V5T},
62b3e311
PB
23735 {4, ARM_ARCH_V5TE},
23736 {5, ARM_ARCH_V5TEJ},
23737 {6, ARM_ARCH_V6},
7e806470 23738 {9, ARM_ARCH_V6K},
f4c65163 23739 {7, ARM_ARCH_V6Z},
91e22acd 23740 {11, ARM_ARCH_V6M},
b2a5fbdc 23741 {12, ARM_ARCH_V6SM},
7e806470 23742 {8, ARM_ARCH_V6T2},
62b3e311
PB
23743 {10, ARM_ARCH_V7A},
23744 {10, ARM_ARCH_V7R},
23745 {10, ARM_ARCH_V7M},
23746 {0, ARM_ARCH_NONE}
23747};
23748
ee3c0378
AS
23749/* Set an attribute if it has not already been set by the user. */
23750static void
23751aeabi_set_attribute_int (int tag, int value)
23752{
23753 if (tag < 1
23754 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23755 || !attributes_set_explicitly[tag])
23756 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
23757}
23758
23759static void
23760aeabi_set_attribute_string (int tag, const char *value)
23761{
23762 if (tag < 1
23763 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23764 || !attributes_set_explicitly[tag])
23765 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
23766}
23767
ee065d83
PB
23768/* Set the public EABI object attributes. */
23769static void
23770aeabi_set_public_attributes (void)
23771{
23772 int arch;
69239280 23773 char profile;
90ec0d68 23774 int virt_sec = 0;
e74cfd16 23775 arm_feature_set flags;
62b3e311
PB
23776 arm_feature_set tmp;
23777 const cpu_arch_ver_table *p;
ee065d83
PB
23778
23779 /* Choose the architecture based on the capabilities of the requested cpu
23780 (if any) and/or the instructions actually used. */
e74cfd16
PB
23781 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
23782 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
23783 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
23784
23785 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
23786 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
23787
23788 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
23789 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
23790
23791 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
23792 if (object_arch)
23793 {
23794 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
23795 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
23796 }
23797
251665fc
MGD
23798 /* We need to make sure that the attributes do not identify us as v6S-M
23799 when the only v6S-M feature in use is the Operating System Extensions. */
23800 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
23801 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
23802 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
23803
62b3e311
PB
23804 tmp = flags;
23805 arch = 0;
23806 for (p = cpu_arch_ver; p->val; p++)
23807 {
23808 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
23809 {
23810 arch = p->val;
23811 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
23812 }
23813 }
ee065d83 23814
9e3c6df6
PB
23815 /* The table lookup above finds the last architecture to contribute
23816 a new feature. Unfortunately, Tag13 is a subset of the union of
23817 v6T2 and v7-M, so it is never seen as contributing a new feature.
23818 We can not search for the last entry which is entirely used,
23819 because if no CPU is specified we build up only those flags
23820 actually used. Perhaps we should separate out the specified
23821 and implicit cases. Avoid taking this path for -march=all by
23822 checking for contradictory v7-A / v7-M features. */
23823 if (arch == 10
23824 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
23825 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
23826 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
23827 arch = 13;
23828
ee065d83
PB
23829 /* Tag_CPU_name. */
23830 if (selected_cpu_name[0])
23831 {
91d6fa6a 23832 char *q;
ee065d83 23833
91d6fa6a
NC
23834 q = selected_cpu_name;
23835 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
23836 {
23837 int i;
5f4273c7 23838
91d6fa6a
NC
23839 q += 4;
23840 for (i = 0; q[i]; i++)
23841 q[i] = TOUPPER (q[i]);
ee065d83 23842 }
91d6fa6a 23843 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 23844 }
62f3b8c8 23845
ee065d83 23846 /* Tag_CPU_arch. */
ee3c0378 23847 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 23848
62b3e311
PB
23849 /* Tag_CPU_arch_profile. */
23850 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
69239280 23851 profile = 'A';
62b3e311 23852 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 23853 profile = 'R';
7e806470 23854 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
23855 profile = 'M';
23856 else
23857 profile = '\0';
23858
23859 if (profile != '\0')
23860 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 23861
ee065d83 23862 /* Tag_ARM_ISA_use. */
ee3c0378
AS
23863 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
23864 || arch == 0)
23865 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 23866
ee065d83 23867 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
23868 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
23869 || arch == 0)
23870 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
23871 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 23872
ee065d83 23873 /* Tag_VFP_arch. */
62f3b8c8
PB
23874 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
23875 aeabi_set_attribute_int (Tag_VFP_arch,
23876 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
23877 ? 5 : 6);
23878 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
ee3c0378 23879 aeabi_set_attribute_int (Tag_VFP_arch, 3);
ada65aa3 23880 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
ee3c0378
AS
23881 aeabi_set_attribute_int (Tag_VFP_arch, 4);
23882 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
23883 aeabi_set_attribute_int (Tag_VFP_arch, 2);
23884 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
23885 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
23886 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 23887
4547cb56
NC
23888 /* Tag_ABI_HardFP_use. */
23889 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
23890 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
23891 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
23892
ee065d83 23893 /* Tag_WMMX_arch. */
ee3c0378
AS
23894 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
23895 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
23896 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
23897 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 23898
ee3c0378 23899 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 23900 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
62f3b8c8
PB
23901 aeabi_set_attribute_int
23902 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
23903 ? 2 : 1));
fa94de6b 23904
ee3c0378 23905 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
62f3b8c8 23906 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
ee3c0378 23907 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 23908
69239280
MGD
23909 /* Tag_DIV_use.
23910
23911 We set Tag_DIV_use to two when integer divide instructions have been used
23912 in ARM state, or when Thumb integer divide instructions have been used,
23913 but we have no architecture profile set, nor have we any ARM instructions.
23914
23915 For new architectures we will have to check these tests. */
23916 gas_assert (arch <= TAG_CPU_ARCH_V7E_M);
23917 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
23918 || (profile == '\0'
23919 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
23920 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 23921 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
23922
23923 /* Tag_MP_extension_use. */
23924 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
23925 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
23926
23927 /* Tag Virtualization_use. */
23928 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
23929 virt_sec |= 1;
23930 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
23931 virt_sec |= 2;
23932 if (virt_sec != 0)
23933 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
23934}
23935
104d59d1 23936/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
23937void
23938arm_md_end (void)
23939{
ee065d83
PB
23940 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
23941 return;
23942
23943 aeabi_set_public_attributes ();
ee065d83 23944}
8463be01 23945#endif /* OBJ_ELF */
ee065d83
PB
23946
23947
23948/* Parse a .cpu directive. */
23949
23950static void
23951s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
23952{
e74cfd16 23953 const struct arm_cpu_option_table *opt;
ee065d83
PB
23954 char *name;
23955 char saved_char;
23956
23957 name = input_line_pointer;
5f4273c7 23958 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23959 input_line_pointer++;
23960 saved_char = *input_line_pointer;
23961 *input_line_pointer = 0;
23962
23963 /* Skip the first "all" entry. */
23964 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
23965 if (streq (opt->name, name))
23966 {
e74cfd16
PB
23967 mcpu_cpu_opt = &opt->value;
23968 selected_cpu = opt->value;
ee065d83 23969 if (opt->canonical_name)
5f4273c7 23970 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
23971 else
23972 {
23973 int i;
23974 for (i = 0; opt->name[i]; i++)
23975 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 23976
ee065d83
PB
23977 selected_cpu_name[i] = 0;
23978 }
e74cfd16 23979 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23980 *input_line_pointer = saved_char;
23981 demand_empty_rest_of_line ();
23982 return;
23983 }
23984 as_bad (_("unknown cpu `%s'"), name);
23985 *input_line_pointer = saved_char;
23986 ignore_rest_of_line ();
23987}
23988
23989
23990/* Parse a .arch directive. */
23991
23992static void
23993s_arm_arch (int ignored ATTRIBUTE_UNUSED)
23994{
e74cfd16 23995 const struct arm_arch_option_table *opt;
ee065d83
PB
23996 char saved_char;
23997 char *name;
23998
23999 name = input_line_pointer;
5f4273c7 24000 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
24001 input_line_pointer++;
24002 saved_char = *input_line_pointer;
24003 *input_line_pointer = 0;
24004
24005 /* Skip the first "all" entry. */
24006 for (opt = arm_archs + 1; opt->name != NULL; opt++)
24007 if (streq (opt->name, name))
24008 {
e74cfd16
PB
24009 mcpu_cpu_opt = &opt->value;
24010 selected_cpu = opt->value;
5f4273c7 24011 strcpy (selected_cpu_name, opt->name);
e74cfd16 24012 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
24013 *input_line_pointer = saved_char;
24014 demand_empty_rest_of_line ();
24015 return;
24016 }
24017
24018 as_bad (_("unknown architecture `%s'\n"), name);
24019 *input_line_pointer = saved_char;
24020 ignore_rest_of_line ();
24021}
24022
24023
7a1d4c38
PB
24024/* Parse a .object_arch directive. */
24025
24026static void
24027s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
24028{
24029 const struct arm_arch_option_table *opt;
24030 char saved_char;
24031 char *name;
24032
24033 name = input_line_pointer;
5f4273c7 24034 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
24035 input_line_pointer++;
24036 saved_char = *input_line_pointer;
24037 *input_line_pointer = 0;
24038
24039 /* Skip the first "all" entry. */
24040 for (opt = arm_archs + 1; opt->name != NULL; opt++)
24041 if (streq (opt->name, name))
24042 {
24043 object_arch = &opt->value;
24044 *input_line_pointer = saved_char;
24045 demand_empty_rest_of_line ();
24046 return;
24047 }
24048
24049 as_bad (_("unknown architecture `%s'\n"), name);
24050 *input_line_pointer = saved_char;
24051 ignore_rest_of_line ();
24052}
24053
69133863
MGD
24054/* Parse a .arch_extension directive. */
24055
24056static void
24057s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
24058{
24059 const struct arm_option_extension_value_table *opt;
24060 char saved_char;
24061 char *name;
24062 int adding_value = 1;
24063
24064 name = input_line_pointer;
24065 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24066 input_line_pointer++;
24067 saved_char = *input_line_pointer;
24068 *input_line_pointer = 0;
24069
24070 if (strlen (name) >= 2
24071 && strncmp (name, "no", 2) == 0)
24072 {
24073 adding_value = 0;
24074 name += 2;
24075 }
24076
24077 for (opt = arm_extensions; opt->name != NULL; opt++)
24078 if (streq (opt->name, name))
24079 {
24080 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
24081 {
24082 as_bad (_("architectural extension `%s' is not allowed for the "
24083 "current base architecture"), name);
24084 break;
24085 }
24086
24087 if (adding_value)
24088 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
24089 else
24090 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
24091
24092 mcpu_cpu_opt = &selected_cpu;
24093 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24094 *input_line_pointer = saved_char;
24095 demand_empty_rest_of_line ();
24096 return;
24097 }
24098
24099 if (opt->name == NULL)
24100 as_bad (_("unknown architecture `%s'\n"), name);
24101
24102 *input_line_pointer = saved_char;
24103 ignore_rest_of_line ();
24104}
24105
ee065d83
PB
24106/* Parse a .fpu directive. */
24107
24108static void
24109s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
24110{
69133863 24111 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
24112 char saved_char;
24113 char *name;
24114
24115 name = input_line_pointer;
5f4273c7 24116 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
24117 input_line_pointer++;
24118 saved_char = *input_line_pointer;
24119 *input_line_pointer = 0;
5f4273c7 24120
ee065d83
PB
24121 for (opt = arm_fpus; opt->name != NULL; opt++)
24122 if (streq (opt->name, name))
24123 {
e74cfd16
PB
24124 mfpu_opt = &opt->value;
24125 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
24126 *input_line_pointer = saved_char;
24127 demand_empty_rest_of_line ();
24128 return;
24129 }
24130
24131 as_bad (_("unknown floating point format `%s'\n"), name);
24132 *input_line_pointer = saved_char;
24133 ignore_rest_of_line ();
24134}
ee065d83 24135
794ba86a 24136/* Copy symbol information. */
f31fef98 24137
794ba86a
DJ
24138void
24139arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
24140{
24141 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
24142}
e04befd0 24143
f31fef98 24144#ifdef OBJ_ELF
e04befd0
AS
24145/* Given a symbolic attribute NAME, return the proper integer value.
24146 Returns -1 if the attribute is not known. */
f31fef98 24147
e04befd0
AS
24148int
24149arm_convert_symbolic_attribute (const char *name)
24150{
f31fef98
NC
24151 static const struct
24152 {
24153 const char * name;
24154 const int tag;
24155 }
24156 attribute_table[] =
24157 {
24158 /* When you modify this table you should
24159 also modify the list in doc/c-arm.texi. */
e04befd0 24160#define T(tag) {#tag, tag}
f31fef98
NC
24161 T (Tag_CPU_raw_name),
24162 T (Tag_CPU_name),
24163 T (Tag_CPU_arch),
24164 T (Tag_CPU_arch_profile),
24165 T (Tag_ARM_ISA_use),
24166 T (Tag_THUMB_ISA_use),
75375b3e 24167 T (Tag_FP_arch),
f31fef98
NC
24168 T (Tag_VFP_arch),
24169 T (Tag_WMMX_arch),
24170 T (Tag_Advanced_SIMD_arch),
24171 T (Tag_PCS_config),
24172 T (Tag_ABI_PCS_R9_use),
24173 T (Tag_ABI_PCS_RW_data),
24174 T (Tag_ABI_PCS_RO_data),
24175 T (Tag_ABI_PCS_GOT_use),
24176 T (Tag_ABI_PCS_wchar_t),
24177 T (Tag_ABI_FP_rounding),
24178 T (Tag_ABI_FP_denormal),
24179 T (Tag_ABI_FP_exceptions),
24180 T (Tag_ABI_FP_user_exceptions),
24181 T (Tag_ABI_FP_number_model),
75375b3e 24182 T (Tag_ABI_align_needed),
f31fef98 24183 T (Tag_ABI_align8_needed),
75375b3e 24184 T (Tag_ABI_align_preserved),
f31fef98
NC
24185 T (Tag_ABI_align8_preserved),
24186 T (Tag_ABI_enum_size),
24187 T (Tag_ABI_HardFP_use),
24188 T (Tag_ABI_VFP_args),
24189 T (Tag_ABI_WMMX_args),
24190 T (Tag_ABI_optimization_goals),
24191 T (Tag_ABI_FP_optimization_goals),
24192 T (Tag_compatibility),
24193 T (Tag_CPU_unaligned_access),
75375b3e 24194 T (Tag_FP_HP_extension),
f31fef98
NC
24195 T (Tag_VFP_HP_extension),
24196 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
24197 T (Tag_MPextension_use),
24198 T (Tag_DIV_use),
f31fef98
NC
24199 T (Tag_nodefaults),
24200 T (Tag_also_compatible_with),
24201 T (Tag_conformance),
24202 T (Tag_T2EE_use),
24203 T (Tag_Virtualization_use),
cd21e546 24204 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 24205#undef T
f31fef98 24206 };
e04befd0
AS
24207 unsigned int i;
24208
24209 if (name == NULL)
24210 return -1;
24211
f31fef98 24212 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 24213 if (streq (name, attribute_table[i].name))
e04befd0
AS
24214 return attribute_table[i].tag;
24215
24216 return -1;
24217}
267bf995
RR
24218
24219
24220/* Apply sym value for relocations only in the case that
24221 they are for local symbols and you have the respective
24222 architectural feature for blx and simple switches. */
24223int
24224arm_apply_sym_value (struct fix * fixP)
24225{
24226 if (fixP->fx_addsy
24227 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
34e77a92 24228 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
24229 {
24230 switch (fixP->fx_r_type)
24231 {
24232 case BFD_RELOC_ARM_PCREL_BLX:
24233 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24234 if (ARM_IS_FUNC (fixP->fx_addsy))
24235 return 1;
24236 break;
24237
24238 case BFD_RELOC_ARM_PCREL_CALL:
24239 case BFD_RELOC_THUMB_PCREL_BLX:
24240 if (THUMB_IS_FUNC (fixP->fx_addsy))
24241 return 1;
24242 break;
24243
24244 default:
24245 break;
24246 }
24247
24248 }
24249 return 0;
24250}
f31fef98 24251#endif /* OBJ_ELF */