2011-06-09 Tristan Gingold <gingold@adacore.com>
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4a58c4bd 3 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
b99bd4ef
NC
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
ec2655a6 15 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
b99bd4ef 27
42a68e18 28#include "as.h"
5287ad62 29#include <limits.h>
037e8744 30#include <stdarg.h>
c19d1205 31#define NO_RELOC 0
3882b010 32#include "safe-ctype.h"
b99bd4ef
NC
33#include "subsegs.h"
34#include "obstack.h"
b99bd4ef 35
f263249b
RE
36#include "opcode/arm.h"
37
b99bd4ef
NC
38#ifdef OBJ_ELF
39#include "elf/arm.h"
a394c00f 40#include "dw2gencfi.h"
b99bd4ef
NC
41#endif
42
f0927246
NC
43#include "dwarf2dbg.h"
44
7ed4c4c5
NC
45#ifdef OBJ_ELF
46/* Must be at least the size of the largest unwind opcode (currently two). */
47#define ARM_OPCODE_CHUNK_SIZE 8
48
49/* This structure holds the unwinding state. */
50
51static struct
52{
c19d1205
ZW
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
7ed4c4c5 57 /* The segment containing the function. */
c19d1205
ZW
58 segT saved_seg;
59 subsegT saved_subseg;
7ed4c4c5
NC
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
c19d1205
ZW
62 int opcode_count;
63 int opcode_alloc;
7ed4c4c5 64 /* The number of bytes pushed to the stack. */
c19d1205 65 offsetT frame_size;
7ed4c4c5
NC
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
c19d1205 69 offsetT pending_offset;
7ed4c4c5 70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
7ed4c4c5 74 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 75 unsigned fp_used:1;
7ed4c4c5 76 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 77 unsigned sp_restored:1;
7ed4c4c5
NC
78} unwind;
79
8b1ad454
NC
80#endif /* OBJ_ELF */
81
4962c51a
MS
82/* Results from operand parsing worker functions. */
83
84typedef enum
85{
86 PARSE_OPERAND_SUCCESS,
87 PARSE_OPERAND_FAIL,
88 PARSE_OPERAND_FAIL_NO_BACKTRACK
89} parse_operand_result;
90
33a392fb
PB
91enum arm_float_abi
92{
93 ARM_FLOAT_ABI_HARD,
94 ARM_FLOAT_ABI_SOFTFP,
95 ARM_FLOAT_ABI_SOFT
96};
97
c19d1205 98/* Types of processor to assemble for. */
b99bd4ef 99#ifndef CPU_DEFAULT
8a59fff3
MGD
100/* The code that was here used to select a default CPU depending on compiler
101 pre-defines which were only present when doing native builds, thus
102 changing gas' default behaviour depending upon the build host.
103
104 If you have a target that requires a default CPU option then the you
105 should define CPU_DEFAULT here. */
b99bd4ef
NC
106#endif
107
108#ifndef FPU_DEFAULT
c820d418
MM
109# ifdef TE_LINUX
110# define FPU_DEFAULT FPU_ARCH_FPA
111# elif defined (TE_NetBSD)
112# ifdef OBJ_ELF
113# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
114# else
115 /* Legacy a.out format. */
116# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
117# endif
4e7fd91e
PB
118# elif defined (TE_VXWORKS)
119# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
120# else
121 /* For backwards compatibility, default to FPA. */
122# define FPU_DEFAULT FPU_ARCH_FPA
123# endif
124#endif /* ifndef FPU_DEFAULT */
b99bd4ef 125
c19d1205 126#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 127
e74cfd16
PB
128static arm_feature_set cpu_variant;
129static arm_feature_set arm_arch_used;
130static arm_feature_set thumb_arch_used;
b99bd4ef 131
b99bd4ef 132/* Flags stored in private area of BFD structure. */
c19d1205
ZW
133static int uses_apcs_26 = FALSE;
134static int atpcs = FALSE;
b34976b6
AM
135static int support_interwork = FALSE;
136static int uses_apcs_float = FALSE;
c19d1205 137static int pic_code = FALSE;
845b51d6 138static int fix_v4bx = FALSE;
278df34e
NS
139/* Warn on using deprecated features. */
140static int warn_on_deprecated = TRUE;
141
03b1477f
RE
142
143/* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
e74cfd16
PB
146static const arm_feature_set *legacy_cpu = NULL;
147static const arm_feature_set *legacy_fpu = NULL;
148
149static const arm_feature_set *mcpu_cpu_opt = NULL;
150static const arm_feature_set *mcpu_fpu_opt = NULL;
151static const arm_feature_set *march_cpu_opt = NULL;
152static const arm_feature_set *march_fpu_opt = NULL;
153static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 154static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
155
156/* Constants for known architecture features. */
157static const arm_feature_set fpu_default = FPU_DEFAULT;
158static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
159static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
160static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
161static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
162static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
164static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
165static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
166
167#ifdef CPU_DEFAULT
168static const arm_feature_set cpu_default = CPU_DEFAULT;
169#endif
170
171static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
172static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
173static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
174static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
175static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
176static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
177static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
178static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
179static const arm_feature_set arm_ext_v4t_5 =
180 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
181static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
182static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
183static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
184static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
185static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
186static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
e74cfd16 187static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
b2a5fbdc 188static const arm_feature_set arm_ext_v6m = ARM_FEATURE (ARM_EXT_V6M, 0);
62b3e311 189static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
9e3c6df6 190static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
7e806470
PB
191static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
192static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
193static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
194static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
195static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
196static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
9e3c6df6 197static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
7e806470 198static const arm_feature_set arm_ext_m =
b2a5fbdc 199 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, 0);
60e5ef9f 200static const arm_feature_set arm_ext_mp = ARM_FEATURE (ARM_EXT_MP, 0);
f4c65163 201static const arm_feature_set arm_ext_sec = ARM_FEATURE (ARM_EXT_SEC, 0);
b2a5fbdc 202static const arm_feature_set arm_ext_os = ARM_FEATURE (ARM_EXT_OS, 0);
eea54501 203static const arm_feature_set arm_ext_adiv = ARM_FEATURE (ARM_EXT_ADIV, 0);
90ec0d68 204static const arm_feature_set arm_ext_virt = ARM_FEATURE (ARM_EXT_VIRT, 0);
e74cfd16
PB
205
206static const arm_feature_set arm_arch_any = ARM_ANY;
207static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
208static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
209static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
251665fc 210static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
e74cfd16 211
2d447fca
JM
212static const arm_feature_set arm_cext_iwmmxt2 =
213 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
214static const arm_feature_set arm_cext_iwmmxt =
215 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
216static const arm_feature_set arm_cext_xscale =
217 ARM_FEATURE (0, ARM_CEXT_XSCALE);
218static const arm_feature_set arm_cext_maverick =
219 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
220static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
221static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
222static const arm_feature_set fpu_vfp_ext_v1xd =
223 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
224static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
225static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
62f3b8c8 226static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
5287ad62 227static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
228static const arm_feature_set fpu_vfp_ext_d32 =
229 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
230static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
231static const arm_feature_set fpu_vfp_v3_or_neon_ext =
232 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
62f3b8c8
PB
233static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
234static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
235static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
e74cfd16 236
33a392fb 237static int mfloat_abi_opt = -1;
e74cfd16
PB
238/* Record user cpu selection for object attributes. */
239static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
240/* Must be long enough to hold any of the names in arm_cpus. */
241static char selected_cpu_name[16];
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
b99bd4ef
NC
354struct arm_it
355{
c19d1205 356 const char * error;
b99bd4ef 357 unsigned long instruction;
c19d1205
ZW
358 int size;
359 int size_req;
360 int cond;
037e8744
JB
361 /* "uncond_value" is set to the value in place of the conditional field in
362 unconditional versions of the instruction, or -1 if nothing is
363 appropriate. */
364 int uncond_value;
5287ad62 365 struct neon_type vectype;
88714cb8
DG
366 /* This does not indicate an actual NEON instruction, only that
367 the mnemonic accepts neon-style type suffixes. */
368 int is_neon;
0110f2b8
PB
369 /* Set to the opcode if the instruction needs relaxation.
370 Zero if the instruction is not relaxed. */
371 unsigned long relax;
b99bd4ef
NC
372 struct
373 {
374 bfd_reloc_code_real_type type;
c19d1205
ZW
375 expressionS exp;
376 int pc_rel;
b99bd4ef 377 } reloc;
b99bd4ef 378
e07e6e58
NC
379 enum it_instruction_type it_insn_type;
380
c19d1205
ZW
381 struct
382 {
383 unsigned reg;
ca3f61f7 384 signed int imm;
dcbf9037 385 struct neon_type_el vectype;
ca3f61f7
NC
386 unsigned present : 1; /* Operand present. */
387 unsigned isreg : 1; /* Operand was a register. */
388 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
389 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
390 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 391 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
392 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
393 instructions. This allows us to disambiguate ARM <-> vector insns. */
394 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 395 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 396 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 397 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
398 unsigned hasreloc : 1; /* Operand has relocation suffix. */
399 unsigned writeback : 1; /* Operand has trailing ! */
400 unsigned preind : 1; /* Preindexed address. */
401 unsigned postind : 1; /* Postindexed address. */
402 unsigned negative : 1; /* Index register was negated. */
403 unsigned shifted : 1; /* Shift applied to operation. */
404 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 405 } operands[6];
b99bd4ef
NC
406};
407
c19d1205 408static struct arm_it inst;
b99bd4ef
NC
409
410#define NUM_FLOAT_VALS 8
411
05d2d07e 412const char * fp_const[] =
b99bd4ef
NC
413{
414 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
415};
416
c19d1205 417/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
418#define MAX_LITTLENUMS 6
419
420LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
421
422#define FAIL (-1)
423#define SUCCESS (0)
424
425#define SUFF_S 1
426#define SUFF_D 2
427#define SUFF_E 3
428#define SUFF_P 4
429
c19d1205
ZW
430#define CP_T_X 0x00008000
431#define CP_T_Y 0x00400000
b99bd4ef 432
c19d1205
ZW
433#define CONDS_BIT 0x00100000
434#define LOAD_BIT 0x00100000
b99bd4ef
NC
435
436#define DOUBLE_LOAD_FLAG 0x00000001
437
438struct asm_cond
439{
d3ce72d0 440 const char * template_name;
c921be7d 441 unsigned long value;
b99bd4ef
NC
442};
443
c19d1205 444#define COND_ALWAYS 0xE
b99bd4ef 445
b99bd4ef
NC
446struct asm_psr
447{
d3ce72d0 448 const char * template_name;
c921be7d 449 unsigned long field;
b99bd4ef
NC
450};
451
62b3e311
PB
452struct asm_barrier_opt
453{
d3ce72d0 454 const char * template_name;
c921be7d 455 unsigned long value;
62b3e311
PB
456};
457
2d2255b5 458/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
459#define SPSR_BIT (1 << 22)
460
c19d1205
ZW
461/* The individual PSR flag bits. */
462#define PSR_c (1 << 16)
463#define PSR_x (1 << 17)
464#define PSR_s (1 << 18)
465#define PSR_f (1 << 19)
b99bd4ef 466
c19d1205 467struct reloc_entry
bfae80f2 468{
c921be7d
NC
469 char * name;
470 bfd_reloc_code_real_type reloc;
bfae80f2
RE
471};
472
5287ad62 473enum vfp_reg_pos
bfae80f2 474{
5287ad62
JB
475 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
476 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
477};
478
479enum vfp_ldstm_type
480{
481 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
482};
483
dcbf9037
JB
484/* Bits for DEFINED field in neon_typed_alias. */
485#define NTA_HASTYPE 1
486#define NTA_HASINDEX 2
487
488struct neon_typed_alias
489{
c921be7d
NC
490 unsigned char defined;
491 unsigned char index;
492 struct neon_type_el eltype;
dcbf9037
JB
493};
494
c19d1205
ZW
495/* ARM register categories. This includes coprocessor numbers and various
496 architecture extensions' registers. */
497enum arm_reg_type
bfae80f2 498{
c19d1205
ZW
499 REG_TYPE_RN,
500 REG_TYPE_CP,
501 REG_TYPE_CN,
502 REG_TYPE_FN,
503 REG_TYPE_VFS,
504 REG_TYPE_VFD,
5287ad62 505 REG_TYPE_NQ,
037e8744 506 REG_TYPE_VFSD,
5287ad62 507 REG_TYPE_NDQ,
037e8744 508 REG_TYPE_NSDQ,
c19d1205
ZW
509 REG_TYPE_VFC,
510 REG_TYPE_MVF,
511 REG_TYPE_MVD,
512 REG_TYPE_MVFX,
513 REG_TYPE_MVDX,
514 REG_TYPE_MVAX,
515 REG_TYPE_DSPSC,
516 REG_TYPE_MMXWR,
517 REG_TYPE_MMXWC,
518 REG_TYPE_MMXWCG,
519 REG_TYPE_XSCALE,
90ec0d68 520 REG_TYPE_RNB
bfae80f2
RE
521};
522
dcbf9037
JB
523/* Structure for a hash table entry for a register.
524 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
525 information which states whether a vector type or index is specified (for a
526 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
527struct reg_entry
528{
c921be7d 529 const char * name;
90ec0d68 530 unsigned int number;
c921be7d
NC
531 unsigned char type;
532 unsigned char builtin;
533 struct neon_typed_alias * neon;
6c43fab6
RE
534};
535
c19d1205 536/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 537const char * const reg_expected_msgs[] =
c19d1205
ZW
538{
539 N_("ARM register expected"),
540 N_("bad or missing co-processor number"),
541 N_("co-processor register expected"),
542 N_("FPA register expected"),
543 N_("VFP single precision register expected"),
5287ad62
JB
544 N_("VFP/Neon double precision register expected"),
545 N_("Neon quad precision register expected"),
037e8744 546 N_("VFP single or double precision register expected"),
5287ad62 547 N_("Neon double or quad precision register expected"),
037e8744 548 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
549 N_("VFP system register expected"),
550 N_("Maverick MVF register expected"),
551 N_("Maverick MVD register expected"),
552 N_("Maverick MVFX register expected"),
553 N_("Maverick MVDX register expected"),
554 N_("Maverick MVAX register expected"),
555 N_("Maverick DSPSC register expected"),
556 N_("iWMMXt data register expected"),
557 N_("iWMMXt control register expected"),
558 N_("iWMMXt scalar register expected"),
559 N_("XScale accumulator register expected"),
6c43fab6
RE
560};
561
c19d1205
ZW
562/* Some well known registers that we refer to directly elsewhere. */
563#define REG_SP 13
564#define REG_LR 14
565#define REG_PC 15
404ff6b5 566
b99bd4ef
NC
567/* ARM instructions take 4bytes in the object file, Thumb instructions
568 take 2: */
c19d1205 569#define INSN_SIZE 4
b99bd4ef
NC
570
571struct asm_opcode
572{
573 /* Basic string to match. */
d3ce72d0 574 const char * template_name;
c19d1205
ZW
575
576 /* Parameters to instruction. */
5be8be5d 577 unsigned int operands[8];
c19d1205
ZW
578
579 /* Conditional tag - see opcode_lookup. */
580 unsigned int tag : 4;
b99bd4ef
NC
581
582 /* Basic instruction code. */
c19d1205 583 unsigned int avalue : 28;
b99bd4ef 584
c19d1205
ZW
585 /* Thumb-format instruction code. */
586 unsigned int tvalue;
b99bd4ef 587
90e4755a 588 /* Which architecture variant provides this instruction. */
c921be7d
NC
589 const arm_feature_set * avariant;
590 const arm_feature_set * tvariant;
c19d1205
ZW
591
592 /* Function to call to encode instruction in ARM format. */
593 void (* aencode) (void);
b99bd4ef 594
c19d1205
ZW
595 /* Function to call to encode instruction in Thumb format. */
596 void (* tencode) (void);
b99bd4ef
NC
597};
598
a737bd4d
NC
599/* Defines for various bits that we will want to toggle. */
600#define INST_IMMEDIATE 0x02000000
601#define OFFSET_REG 0x02000000
c19d1205 602#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
603#define SHIFT_BY_REG 0x00000010
604#define PRE_INDEX 0x01000000
605#define INDEX_UP 0x00800000
606#define WRITE_BACK 0x00200000
607#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 608#define CPSI_MMOD 0x00020000
90e4755a 609
a737bd4d
NC
610#define LITERAL_MASK 0xf000f000
611#define OPCODE_MASK 0xfe1fffff
612#define V4_STR_BIT 0x00000020
90e4755a 613
efd81785
PB
614#define T2_SUBS_PC_LR 0xf3de8f00
615
a737bd4d 616#define DATA_OP_SHIFT 21
90e4755a 617
ef8d22e6
PB
618#define T2_OPCODE_MASK 0xfe1fffff
619#define T2_DATA_OP_SHIFT 21
620
a737bd4d
NC
621/* Codes to distinguish the arithmetic instructions. */
622#define OPCODE_AND 0
623#define OPCODE_EOR 1
624#define OPCODE_SUB 2
625#define OPCODE_RSB 3
626#define OPCODE_ADD 4
627#define OPCODE_ADC 5
628#define OPCODE_SBC 6
629#define OPCODE_RSC 7
630#define OPCODE_TST 8
631#define OPCODE_TEQ 9
632#define OPCODE_CMP 10
633#define OPCODE_CMN 11
634#define OPCODE_ORR 12
635#define OPCODE_MOV 13
636#define OPCODE_BIC 14
637#define OPCODE_MVN 15
90e4755a 638
ef8d22e6
PB
639#define T2_OPCODE_AND 0
640#define T2_OPCODE_BIC 1
641#define T2_OPCODE_ORR 2
642#define T2_OPCODE_ORN 3
643#define T2_OPCODE_EOR 4
644#define T2_OPCODE_ADD 8
645#define T2_OPCODE_ADC 10
646#define T2_OPCODE_SBC 11
647#define T2_OPCODE_SUB 13
648#define T2_OPCODE_RSB 14
649
a737bd4d
NC
650#define T_OPCODE_MUL 0x4340
651#define T_OPCODE_TST 0x4200
652#define T_OPCODE_CMN 0x42c0
653#define T_OPCODE_NEG 0x4240
654#define T_OPCODE_MVN 0x43c0
90e4755a 655
a737bd4d
NC
656#define T_OPCODE_ADD_R3 0x1800
657#define T_OPCODE_SUB_R3 0x1a00
658#define T_OPCODE_ADD_HI 0x4400
659#define T_OPCODE_ADD_ST 0xb000
660#define T_OPCODE_SUB_ST 0xb080
661#define T_OPCODE_ADD_SP 0xa800
662#define T_OPCODE_ADD_PC 0xa000
663#define T_OPCODE_ADD_I8 0x3000
664#define T_OPCODE_SUB_I8 0x3800
665#define T_OPCODE_ADD_I3 0x1c00
666#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 667
a737bd4d
NC
668#define T_OPCODE_ASR_R 0x4100
669#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
670#define T_OPCODE_LSR_R 0x40c0
671#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
672#define T_OPCODE_ASR_I 0x1000
673#define T_OPCODE_LSL_I 0x0000
674#define T_OPCODE_LSR_I 0x0800
b99bd4ef 675
a737bd4d
NC
676#define T_OPCODE_MOV_I8 0x2000
677#define T_OPCODE_CMP_I8 0x2800
678#define T_OPCODE_CMP_LR 0x4280
679#define T_OPCODE_MOV_HR 0x4600
680#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 681
a737bd4d
NC
682#define T_OPCODE_LDR_PC 0x4800
683#define T_OPCODE_LDR_SP 0x9800
684#define T_OPCODE_STR_SP 0x9000
685#define T_OPCODE_LDR_IW 0x6800
686#define T_OPCODE_STR_IW 0x6000
687#define T_OPCODE_LDR_IH 0x8800
688#define T_OPCODE_STR_IH 0x8000
689#define T_OPCODE_LDR_IB 0x7800
690#define T_OPCODE_STR_IB 0x7000
691#define T_OPCODE_LDR_RW 0x5800
692#define T_OPCODE_STR_RW 0x5000
693#define T_OPCODE_LDR_RH 0x5a00
694#define T_OPCODE_STR_RH 0x5200
695#define T_OPCODE_LDR_RB 0x5c00
696#define T_OPCODE_STR_RB 0x5400
c9b604bd 697
a737bd4d
NC
698#define T_OPCODE_PUSH 0xb400
699#define T_OPCODE_POP 0xbc00
b99bd4ef 700
2fc8bdac 701#define T_OPCODE_BRANCH 0xe000
b99bd4ef 702
a737bd4d 703#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 704#define THUMB_PP_PC_LR 0x0100
c19d1205 705#define THUMB_LOAD_BIT 0x0800
53365c0d 706#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
707
708#define BAD_ARGS _("bad arguments to instruction")
fdfde340 709#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
710#define BAD_PC _("r15 not allowed here")
711#define BAD_COND _("instruction cannot be conditional")
712#define BAD_OVERLAP _("registers may not be the same")
713#define BAD_HIREG _("lo register required")
714#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 715#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
716#define BAD_BRANCH _("branch must be last instruction in IT block")
717#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 718#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
719#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
720#define BAD_IT_COND _("incorrect condition in IT block")
721#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 722#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
723#define BAD_PC_ADDRESSING \
724 _("cannot use register index with PC-relative addressing")
725#define BAD_PC_WRITEBACK \
726 _("cannot use writeback with PC-relative addressing")
c19d1205 727
c921be7d
NC
728static struct hash_control * arm_ops_hsh;
729static struct hash_control * arm_cond_hsh;
730static struct hash_control * arm_shift_hsh;
731static struct hash_control * arm_psr_hsh;
732static struct hash_control * arm_v7m_psr_hsh;
733static struct hash_control * arm_reg_hsh;
734static struct hash_control * arm_reloc_hsh;
735static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 736
b99bd4ef
NC
737/* Stuff needed to resolve the label ambiguity
738 As:
739 ...
740 label: <insn>
741 may differ from:
742 ...
743 label:
5f4273c7 744 <insn> */
b99bd4ef
NC
745
746symbolS * last_label_seen;
b34976b6 747static int label_is_thumb_function_name = FALSE;
e07e6e58 748
3d0c9500
NC
749/* Literal pool structure. Held on a per-section
750 and per-sub-section basis. */
a737bd4d 751
c19d1205 752#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 753typedef struct literal_pool
b99bd4ef 754{
c921be7d
NC
755 expressionS literals [MAX_LITERAL_POOL_SIZE];
756 unsigned int next_free_entry;
757 unsigned int id;
758 symbolS * symbol;
759 segT section;
760 subsegT sub_section;
761 struct literal_pool * next;
3d0c9500 762} literal_pool;
b99bd4ef 763
3d0c9500
NC
764/* Pointer to a linked list of literal pools. */
765literal_pool * list_of_pools = NULL;
e27ec89e 766
e07e6e58
NC
767#ifdef OBJ_ELF
768# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
769#else
770static struct current_it now_it;
771#endif
772
773static inline int
774now_it_compatible (int cond)
775{
776 return (cond & ~1) == (now_it.cc & ~1);
777}
778
779static inline int
780conditional_insn (void)
781{
782 return inst.cond != COND_ALWAYS;
783}
784
785static int in_it_block (void);
786
787static int handle_it_state (void);
788
789static void force_automatic_it_block_close (void);
790
c921be7d
NC
791static void it_fsm_post_encode (void);
792
e07e6e58
NC
793#define set_it_insn_type(type) \
794 do \
795 { \
796 inst.it_insn_type = type; \
797 if (handle_it_state () == FAIL) \
798 return; \
799 } \
800 while (0)
801
c921be7d
NC
802#define set_it_insn_type_nonvoid(type, failret) \
803 do \
804 { \
805 inst.it_insn_type = type; \
806 if (handle_it_state () == FAIL) \
807 return failret; \
808 } \
809 while(0)
810
e07e6e58
NC
811#define set_it_insn_type_last() \
812 do \
813 { \
814 if (inst.cond == COND_ALWAYS) \
815 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
816 else \
817 set_it_insn_type (INSIDE_IT_LAST_INSN); \
818 } \
819 while (0)
820
c19d1205 821/* Pure syntax. */
b99bd4ef 822
c19d1205
ZW
823/* This array holds the chars that always start a comment. If the
824 pre-processor is disabled, these aren't very useful. */
825const char comment_chars[] = "@";
3d0c9500 826
c19d1205
ZW
827/* This array holds the chars that only start a comment at the beginning of
828 a line. If the line seems to have the form '# 123 filename'
829 .line and .file directives will appear in the pre-processed output. */
830/* Note that input_file.c hand checks for '#' at the beginning of the
831 first line of the input file. This is because the compiler outputs
832 #NO_APP at the beginning of its output. */
833/* Also note that comments like this one will always work. */
834const char line_comment_chars[] = "#";
3d0c9500 835
c19d1205 836const char line_separator_chars[] = ";";
b99bd4ef 837
c19d1205
ZW
838/* Chars that can be used to separate mant
839 from exp in floating point numbers. */
840const char EXP_CHARS[] = "eE";
3d0c9500 841
c19d1205
ZW
842/* Chars that mean this number is a floating point constant. */
843/* As in 0f12.456 */
844/* or 0d1.2345e12 */
b99bd4ef 845
c19d1205 846const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 847
c19d1205
ZW
848/* Prefix characters that indicate the start of an immediate
849 value. */
850#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 851
c19d1205
ZW
852/* Separator character handling. */
853
854#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
855
856static inline int
857skip_past_char (char ** str, char c)
858{
859 if (**str == c)
860 {
861 (*str)++;
862 return SUCCESS;
3d0c9500 863 }
c19d1205
ZW
864 else
865 return FAIL;
866}
c921be7d 867
c19d1205 868#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 869
c19d1205
ZW
870/* Arithmetic expressions (possibly involving symbols). */
871
872/* Return TRUE if anything in the expression is a bignum. */
873
874static int
875walk_no_bignums (symbolS * sp)
876{
877 if (symbol_get_value_expression (sp)->X_op == O_big)
878 return 1;
879
880 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 881 {
c19d1205
ZW
882 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
883 || (symbol_get_value_expression (sp)->X_op_symbol
884 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
885 }
886
c19d1205 887 return 0;
3d0c9500
NC
888}
889
c19d1205
ZW
890static int in_my_get_expression = 0;
891
892/* Third argument to my_get_expression. */
893#define GE_NO_PREFIX 0
894#define GE_IMM_PREFIX 1
895#define GE_OPT_PREFIX 2
5287ad62
JB
896/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
897 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
898#define GE_OPT_PREFIX_BIG 3
a737bd4d 899
b99bd4ef 900static int
c19d1205 901my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 902{
c19d1205
ZW
903 char * save_in;
904 segT seg;
b99bd4ef 905
c19d1205
ZW
906 /* In unified syntax, all prefixes are optional. */
907 if (unified_syntax)
5287ad62
JB
908 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
909 : GE_OPT_PREFIX;
b99bd4ef 910
c19d1205 911 switch (prefix_mode)
b99bd4ef 912 {
c19d1205
ZW
913 case GE_NO_PREFIX: break;
914 case GE_IMM_PREFIX:
915 if (!is_immediate_prefix (**str))
916 {
917 inst.error = _("immediate expression requires a # prefix");
918 return FAIL;
919 }
920 (*str)++;
921 break;
922 case GE_OPT_PREFIX:
5287ad62 923 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
924 if (is_immediate_prefix (**str))
925 (*str)++;
926 break;
927 default: abort ();
928 }
b99bd4ef 929
c19d1205 930 memset (ep, 0, sizeof (expressionS));
b99bd4ef 931
c19d1205
ZW
932 save_in = input_line_pointer;
933 input_line_pointer = *str;
934 in_my_get_expression = 1;
935 seg = expression (ep);
936 in_my_get_expression = 0;
937
f86adc07 938 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 939 {
f86adc07 940 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
941 *str = input_line_pointer;
942 input_line_pointer = save_in;
943 if (inst.error == NULL)
f86adc07
NS
944 inst.error = (ep->X_op == O_absent
945 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
946 return 1;
947 }
b99bd4ef 948
c19d1205
ZW
949#ifdef OBJ_AOUT
950 if (seg != absolute_section
951 && seg != text_section
952 && seg != data_section
953 && seg != bss_section
954 && seg != undefined_section)
955 {
956 inst.error = _("bad segment");
957 *str = input_line_pointer;
958 input_line_pointer = save_in;
959 return 1;
b99bd4ef 960 }
87975d2a
AM
961#else
962 (void) seg;
c19d1205 963#endif
b99bd4ef 964
c19d1205
ZW
965 /* Get rid of any bignums now, so that we don't generate an error for which
966 we can't establish a line number later on. Big numbers are never valid
967 in instructions, which is where this routine is always called. */
5287ad62
JB
968 if (prefix_mode != GE_OPT_PREFIX_BIG
969 && (ep->X_op == O_big
970 || (ep->X_add_symbol
971 && (walk_no_bignums (ep->X_add_symbol)
972 || (ep->X_op_symbol
973 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
974 {
975 inst.error = _("invalid constant");
976 *str = input_line_pointer;
977 input_line_pointer = save_in;
978 return 1;
979 }
b99bd4ef 980
c19d1205
ZW
981 *str = input_line_pointer;
982 input_line_pointer = save_in;
983 return 0;
b99bd4ef
NC
984}
985
c19d1205
ZW
986/* Turn a string in input_line_pointer into a floating point constant
987 of type TYPE, and store the appropriate bytes in *LITP. The number
988 of LITTLENUMS emitted is stored in *SIZEP. An error message is
989 returned, or NULL on OK.
b99bd4ef 990
c19d1205
ZW
991 Note that fp constants aren't represent in the normal way on the ARM.
992 In big endian mode, things are as expected. However, in little endian
993 mode fp constants are big-endian word-wise, and little-endian byte-wise
994 within the words. For example, (double) 1.1 in big endian mode is
995 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
996 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 997
c19d1205 998 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 999
c19d1205
ZW
1000char *
1001md_atof (int type, char * litP, int * sizeP)
1002{
1003 int prec;
1004 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1005 char *t;
1006 int i;
b99bd4ef 1007
c19d1205
ZW
1008 switch (type)
1009 {
1010 case 'f':
1011 case 'F':
1012 case 's':
1013 case 'S':
1014 prec = 2;
1015 break;
b99bd4ef 1016
c19d1205
ZW
1017 case 'd':
1018 case 'D':
1019 case 'r':
1020 case 'R':
1021 prec = 4;
1022 break;
b99bd4ef 1023
c19d1205
ZW
1024 case 'x':
1025 case 'X':
499ac353 1026 prec = 5;
c19d1205 1027 break;
b99bd4ef 1028
c19d1205
ZW
1029 case 'p':
1030 case 'P':
499ac353 1031 prec = 5;
c19d1205 1032 break;
a737bd4d 1033
c19d1205
ZW
1034 default:
1035 *sizeP = 0;
499ac353 1036 return _("Unrecognized or unsupported floating point constant");
c19d1205 1037 }
b99bd4ef 1038
c19d1205
ZW
1039 t = atof_ieee (input_line_pointer, type, words);
1040 if (t)
1041 input_line_pointer = t;
499ac353 1042 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1043
c19d1205
ZW
1044 if (target_big_endian)
1045 {
1046 for (i = 0; i < prec; i++)
1047 {
499ac353
NC
1048 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1049 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1050 }
1051 }
1052 else
1053 {
e74cfd16 1054 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1055 for (i = prec - 1; i >= 0; i--)
1056 {
499ac353
NC
1057 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1058 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1059 }
1060 else
1061 /* For a 4 byte float the order of elements in `words' is 1 0.
1062 For an 8 byte float the order is 1 0 3 2. */
1063 for (i = 0; i < prec; i += 2)
1064 {
499ac353
NC
1065 md_number_to_chars (litP, (valueT) words[i + 1],
1066 sizeof (LITTLENUM_TYPE));
1067 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1068 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1069 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1070 }
1071 }
b99bd4ef 1072
499ac353 1073 return NULL;
c19d1205 1074}
b99bd4ef 1075
c19d1205
ZW
1076/* We handle all bad expressions here, so that we can report the faulty
1077 instruction in the error message. */
1078void
91d6fa6a 1079md_operand (expressionS * exp)
c19d1205
ZW
1080{
1081 if (in_my_get_expression)
91d6fa6a 1082 exp->X_op = O_illegal;
b99bd4ef
NC
1083}
1084
c19d1205 1085/* Immediate values. */
b99bd4ef 1086
c19d1205
ZW
1087/* Generic immediate-value read function for use in directives.
1088 Accepts anything that 'expression' can fold to a constant.
1089 *val receives the number. */
1090#ifdef OBJ_ELF
1091static int
1092immediate_for_directive (int *val)
b99bd4ef 1093{
c19d1205
ZW
1094 expressionS exp;
1095 exp.X_op = O_illegal;
b99bd4ef 1096
c19d1205
ZW
1097 if (is_immediate_prefix (*input_line_pointer))
1098 {
1099 input_line_pointer++;
1100 expression (&exp);
1101 }
b99bd4ef 1102
c19d1205
ZW
1103 if (exp.X_op != O_constant)
1104 {
1105 as_bad (_("expected #constant"));
1106 ignore_rest_of_line ();
1107 return FAIL;
1108 }
1109 *val = exp.X_add_number;
1110 return SUCCESS;
b99bd4ef 1111}
c19d1205 1112#endif
b99bd4ef 1113
c19d1205 1114/* Register parsing. */
b99bd4ef 1115
c19d1205
ZW
1116/* Generic register parser. CCP points to what should be the
1117 beginning of a register name. If it is indeed a valid register
1118 name, advance CCP over it and return the reg_entry structure;
1119 otherwise return NULL. Does not issue diagnostics. */
1120
1121static struct reg_entry *
1122arm_reg_parse_multi (char **ccp)
b99bd4ef 1123{
c19d1205
ZW
1124 char *start = *ccp;
1125 char *p;
1126 struct reg_entry *reg;
b99bd4ef 1127
c19d1205
ZW
1128#ifdef REGISTER_PREFIX
1129 if (*start != REGISTER_PREFIX)
01cfc07f 1130 return NULL;
c19d1205
ZW
1131 start++;
1132#endif
1133#ifdef OPTIONAL_REGISTER_PREFIX
1134 if (*start == OPTIONAL_REGISTER_PREFIX)
1135 start++;
1136#endif
b99bd4ef 1137
c19d1205
ZW
1138 p = start;
1139 if (!ISALPHA (*p) || !is_name_beginner (*p))
1140 return NULL;
b99bd4ef 1141
c19d1205
ZW
1142 do
1143 p++;
1144 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1145
1146 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1147
1148 if (!reg)
1149 return NULL;
1150
1151 *ccp = p;
1152 return reg;
b99bd4ef
NC
1153}
1154
1155static int
dcbf9037
JB
1156arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1157 enum arm_reg_type type)
b99bd4ef 1158{
c19d1205
ZW
1159 /* Alternative syntaxes are accepted for a few register classes. */
1160 switch (type)
1161 {
1162 case REG_TYPE_MVF:
1163 case REG_TYPE_MVD:
1164 case REG_TYPE_MVFX:
1165 case REG_TYPE_MVDX:
1166 /* Generic coprocessor register names are allowed for these. */
79134647 1167 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1168 return reg->number;
1169 break;
69b97547 1170
c19d1205
ZW
1171 case REG_TYPE_CP:
1172 /* For backward compatibility, a bare number is valid here. */
1173 {
1174 unsigned long processor = strtoul (start, ccp, 10);
1175 if (*ccp != start && processor <= 15)
1176 return processor;
1177 }
6057a28f 1178
c19d1205
ZW
1179 case REG_TYPE_MMXWC:
1180 /* WC includes WCG. ??? I'm not sure this is true for all
1181 instructions that take WC registers. */
79134647 1182 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1183 return reg->number;
6057a28f 1184 break;
c19d1205 1185
6057a28f 1186 default:
c19d1205 1187 break;
6057a28f
NC
1188 }
1189
dcbf9037
JB
1190 return FAIL;
1191}
1192
1193/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1194 return value is the register number or FAIL. */
1195
1196static int
1197arm_reg_parse (char **ccp, enum arm_reg_type type)
1198{
1199 char *start = *ccp;
1200 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1201 int ret;
1202
1203 /* Do not allow a scalar (reg+index) to parse as a register. */
1204 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1205 return FAIL;
1206
1207 if (reg && reg->type == type)
1208 return reg->number;
1209
1210 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1211 return ret;
1212
c19d1205
ZW
1213 *ccp = start;
1214 return FAIL;
1215}
69b97547 1216
dcbf9037
JB
1217/* Parse a Neon type specifier. *STR should point at the leading '.'
1218 character. Does no verification at this stage that the type fits the opcode
1219 properly. E.g.,
1220
1221 .i32.i32.s16
1222 .s32.f32
1223 .u16
1224
1225 Can all be legally parsed by this function.
1226
1227 Fills in neon_type struct pointer with parsed information, and updates STR
1228 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1229 type, FAIL if not. */
1230
1231static int
1232parse_neon_type (struct neon_type *type, char **str)
1233{
1234 char *ptr = *str;
1235
1236 if (type)
1237 type->elems = 0;
1238
1239 while (type->elems < NEON_MAX_TYPE_ELS)
1240 {
1241 enum neon_el_type thistype = NT_untyped;
1242 unsigned thissize = -1u;
1243
1244 if (*ptr != '.')
1245 break;
1246
1247 ptr++;
1248
1249 /* Just a size without an explicit type. */
1250 if (ISDIGIT (*ptr))
1251 goto parsesize;
1252
1253 switch (TOLOWER (*ptr))
1254 {
1255 case 'i': thistype = NT_integer; break;
1256 case 'f': thistype = NT_float; break;
1257 case 'p': thistype = NT_poly; break;
1258 case 's': thistype = NT_signed; break;
1259 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1260 case 'd':
1261 thistype = NT_float;
1262 thissize = 64;
1263 ptr++;
1264 goto done;
dcbf9037
JB
1265 default:
1266 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1267 return FAIL;
1268 }
1269
1270 ptr++;
1271
1272 /* .f is an abbreviation for .f32. */
1273 if (thistype == NT_float && !ISDIGIT (*ptr))
1274 thissize = 32;
1275 else
1276 {
1277 parsesize:
1278 thissize = strtoul (ptr, &ptr, 10);
1279
1280 if (thissize != 8 && thissize != 16 && thissize != 32
1281 && thissize != 64)
1282 {
1283 as_bad (_("bad size %d in type specifier"), thissize);
1284 return FAIL;
1285 }
1286 }
1287
037e8744 1288 done:
dcbf9037
JB
1289 if (type)
1290 {
1291 type->el[type->elems].type = thistype;
1292 type->el[type->elems].size = thissize;
1293 type->elems++;
1294 }
1295 }
1296
1297 /* Empty/missing type is not a successful parse. */
1298 if (type->elems == 0)
1299 return FAIL;
1300
1301 *str = ptr;
1302
1303 return SUCCESS;
1304}
1305
1306/* Errors may be set multiple times during parsing or bit encoding
1307 (particularly in the Neon bits), but usually the earliest error which is set
1308 will be the most meaningful. Avoid overwriting it with later (cascading)
1309 errors by calling this function. */
1310
1311static void
1312first_error (const char *err)
1313{
1314 if (!inst.error)
1315 inst.error = err;
1316}
1317
1318/* Parse a single type, e.g. ".s32", leading period included. */
1319static int
1320parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1321{
1322 char *str = *ccp;
1323 struct neon_type optype;
1324
1325 if (*str == '.')
1326 {
1327 if (parse_neon_type (&optype, &str) == SUCCESS)
1328 {
1329 if (optype.elems == 1)
1330 *vectype = optype.el[0];
1331 else
1332 {
1333 first_error (_("only one type should be specified for operand"));
1334 return FAIL;
1335 }
1336 }
1337 else
1338 {
1339 first_error (_("vector type expected"));
1340 return FAIL;
1341 }
1342 }
1343 else
1344 return FAIL;
5f4273c7 1345
dcbf9037 1346 *ccp = str;
5f4273c7 1347
dcbf9037
JB
1348 return SUCCESS;
1349}
1350
1351/* Special meanings for indices (which have a range of 0-7), which will fit into
1352 a 4-bit integer. */
1353
1354#define NEON_ALL_LANES 15
1355#define NEON_INTERLEAVE_LANES 14
1356
1357/* Parse either a register or a scalar, with an optional type. Return the
1358 register number, and optionally fill in the actual type of the register
1359 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1360 type/index information in *TYPEINFO. */
1361
1362static int
1363parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1364 enum arm_reg_type *rtype,
1365 struct neon_typed_alias *typeinfo)
1366{
1367 char *str = *ccp;
1368 struct reg_entry *reg = arm_reg_parse_multi (&str);
1369 struct neon_typed_alias atype;
1370 struct neon_type_el parsetype;
1371
1372 atype.defined = 0;
1373 atype.index = -1;
1374 atype.eltype.type = NT_invtype;
1375 atype.eltype.size = -1;
1376
1377 /* Try alternate syntax for some types of register. Note these are mutually
1378 exclusive with the Neon syntax extensions. */
1379 if (reg == NULL)
1380 {
1381 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1382 if (altreg != FAIL)
1383 *ccp = str;
1384 if (typeinfo)
1385 *typeinfo = atype;
1386 return altreg;
1387 }
1388
037e8744
JB
1389 /* Undo polymorphism when a set of register types may be accepted. */
1390 if ((type == REG_TYPE_NDQ
1391 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1392 || (type == REG_TYPE_VFSD
1393 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1394 || (type == REG_TYPE_NSDQ
1395 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1396 || reg->type == REG_TYPE_NQ))
1397 || (type == REG_TYPE_MMXWC
1398 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1399 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1400
1401 if (type != reg->type)
1402 return FAIL;
1403
1404 if (reg->neon)
1405 atype = *reg->neon;
5f4273c7 1406
dcbf9037
JB
1407 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1408 {
1409 if ((atype.defined & NTA_HASTYPE) != 0)
1410 {
1411 first_error (_("can't redefine type for operand"));
1412 return FAIL;
1413 }
1414 atype.defined |= NTA_HASTYPE;
1415 atype.eltype = parsetype;
1416 }
5f4273c7 1417
dcbf9037
JB
1418 if (skip_past_char (&str, '[') == SUCCESS)
1419 {
1420 if (type != REG_TYPE_VFD)
1421 {
1422 first_error (_("only D registers may be indexed"));
1423 return FAIL;
1424 }
5f4273c7 1425
dcbf9037
JB
1426 if ((atype.defined & NTA_HASINDEX) != 0)
1427 {
1428 first_error (_("can't change index for operand"));
1429 return FAIL;
1430 }
1431
1432 atype.defined |= NTA_HASINDEX;
1433
1434 if (skip_past_char (&str, ']') == SUCCESS)
1435 atype.index = NEON_ALL_LANES;
1436 else
1437 {
1438 expressionS exp;
1439
1440 my_get_expression (&exp, &str, GE_NO_PREFIX);
1441
1442 if (exp.X_op != O_constant)
1443 {
1444 first_error (_("constant expression required"));
1445 return FAIL;
1446 }
1447
1448 if (skip_past_char (&str, ']') == FAIL)
1449 return FAIL;
1450
1451 atype.index = exp.X_add_number;
1452 }
1453 }
5f4273c7 1454
dcbf9037
JB
1455 if (typeinfo)
1456 *typeinfo = atype;
5f4273c7 1457
dcbf9037
JB
1458 if (rtype)
1459 *rtype = type;
5f4273c7 1460
dcbf9037 1461 *ccp = str;
5f4273c7 1462
dcbf9037
JB
1463 return reg->number;
1464}
1465
1466/* Like arm_reg_parse, but allow allow the following extra features:
1467 - If RTYPE is non-zero, return the (possibly restricted) type of the
1468 register (e.g. Neon double or quad reg when either has been requested).
1469 - If this is a Neon vector type with additional type information, fill
1470 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1471 This function will fault on encountering a scalar. */
dcbf9037
JB
1472
1473static int
1474arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1475 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1476{
1477 struct neon_typed_alias atype;
1478 char *str = *ccp;
1479 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1480
1481 if (reg == FAIL)
1482 return FAIL;
1483
0855e32b
NS
1484 /* Do not allow regname(... to parse as a register. */
1485 if (*str == '(')
1486 return FAIL;
1487
dcbf9037
JB
1488 /* Do not allow a scalar (reg+index) to parse as a register. */
1489 if ((atype.defined & NTA_HASINDEX) != 0)
1490 {
1491 first_error (_("register operand expected, but got scalar"));
1492 return FAIL;
1493 }
1494
1495 if (vectype)
1496 *vectype = atype.eltype;
1497
1498 *ccp = str;
1499
1500 return reg;
1501}
1502
1503#define NEON_SCALAR_REG(X) ((X) >> 4)
1504#define NEON_SCALAR_INDEX(X) ((X) & 15)
1505
5287ad62
JB
1506/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1507 have enough information to be able to do a good job bounds-checking. So, we
1508 just do easy checks here, and do further checks later. */
1509
1510static int
dcbf9037 1511parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1512{
dcbf9037 1513 int reg;
5287ad62 1514 char *str = *ccp;
dcbf9037 1515 struct neon_typed_alias atype;
5f4273c7 1516
dcbf9037 1517 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1518
dcbf9037 1519 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1520 return FAIL;
5f4273c7 1521
dcbf9037 1522 if (atype.index == NEON_ALL_LANES)
5287ad62 1523 {
dcbf9037 1524 first_error (_("scalar must have an index"));
5287ad62
JB
1525 return FAIL;
1526 }
dcbf9037 1527 else if (atype.index >= 64 / elsize)
5287ad62 1528 {
dcbf9037 1529 first_error (_("scalar index out of range"));
5287ad62
JB
1530 return FAIL;
1531 }
5f4273c7 1532
dcbf9037
JB
1533 if (type)
1534 *type = atype.eltype;
5f4273c7 1535
5287ad62 1536 *ccp = str;
5f4273c7 1537
dcbf9037 1538 return reg * 16 + atype.index;
5287ad62
JB
1539}
1540
c19d1205 1541/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1542
c19d1205
ZW
1543static long
1544parse_reg_list (char ** strp)
1545{
1546 char * str = * strp;
1547 long range = 0;
1548 int another_range;
a737bd4d 1549
c19d1205
ZW
1550 /* We come back here if we get ranges concatenated by '+' or '|'. */
1551 do
6057a28f 1552 {
c19d1205 1553 another_range = 0;
a737bd4d 1554
c19d1205
ZW
1555 if (*str == '{')
1556 {
1557 int in_range = 0;
1558 int cur_reg = -1;
a737bd4d 1559
c19d1205
ZW
1560 str++;
1561 do
1562 {
1563 int reg;
6057a28f 1564
dcbf9037 1565 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1566 {
dcbf9037 1567 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1568 return FAIL;
1569 }
a737bd4d 1570
c19d1205
ZW
1571 if (in_range)
1572 {
1573 int i;
a737bd4d 1574
c19d1205
ZW
1575 if (reg <= cur_reg)
1576 {
dcbf9037 1577 first_error (_("bad range in register list"));
c19d1205
ZW
1578 return FAIL;
1579 }
40a18ebd 1580
c19d1205
ZW
1581 for (i = cur_reg + 1; i < reg; i++)
1582 {
1583 if (range & (1 << i))
1584 as_tsktsk
1585 (_("Warning: duplicated register (r%d) in register list"),
1586 i);
1587 else
1588 range |= 1 << i;
1589 }
1590 in_range = 0;
1591 }
a737bd4d 1592
c19d1205
ZW
1593 if (range & (1 << reg))
1594 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1595 reg);
1596 else if (reg <= cur_reg)
1597 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1598
c19d1205
ZW
1599 range |= 1 << reg;
1600 cur_reg = reg;
1601 }
1602 while (skip_past_comma (&str) != FAIL
1603 || (in_range = 1, *str++ == '-'));
1604 str--;
a737bd4d 1605
c19d1205
ZW
1606 if (*str++ != '}')
1607 {
dcbf9037 1608 first_error (_("missing `}'"));
c19d1205
ZW
1609 return FAIL;
1610 }
1611 }
1612 else
1613 {
91d6fa6a 1614 expressionS exp;
40a18ebd 1615
91d6fa6a 1616 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1617 return FAIL;
40a18ebd 1618
91d6fa6a 1619 if (exp.X_op == O_constant)
c19d1205 1620 {
91d6fa6a
NC
1621 if (exp.X_add_number
1622 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1623 {
1624 inst.error = _("invalid register mask");
1625 return FAIL;
1626 }
a737bd4d 1627
91d6fa6a 1628 if ((range & exp.X_add_number) != 0)
c19d1205 1629 {
91d6fa6a 1630 int regno = range & exp.X_add_number;
a737bd4d 1631
c19d1205
ZW
1632 regno &= -regno;
1633 regno = (1 << regno) - 1;
1634 as_tsktsk
1635 (_("Warning: duplicated register (r%d) in register list"),
1636 regno);
1637 }
a737bd4d 1638
91d6fa6a 1639 range |= exp.X_add_number;
c19d1205
ZW
1640 }
1641 else
1642 {
1643 if (inst.reloc.type != 0)
1644 {
1645 inst.error = _("expression too complex");
1646 return FAIL;
1647 }
a737bd4d 1648
91d6fa6a 1649 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1650 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1651 inst.reloc.pc_rel = 0;
1652 }
1653 }
a737bd4d 1654
c19d1205
ZW
1655 if (*str == '|' || *str == '+')
1656 {
1657 str++;
1658 another_range = 1;
1659 }
a737bd4d 1660 }
c19d1205 1661 while (another_range);
a737bd4d 1662
c19d1205
ZW
1663 *strp = str;
1664 return range;
a737bd4d
NC
1665}
1666
5287ad62
JB
1667/* Types of registers in a list. */
1668
1669enum reg_list_els
1670{
1671 REGLIST_VFP_S,
1672 REGLIST_VFP_D,
1673 REGLIST_NEON_D
1674};
1675
c19d1205
ZW
1676/* Parse a VFP register list. If the string is invalid return FAIL.
1677 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1678 register. Parses registers of type ETYPE.
1679 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1680 - Q registers can be used to specify pairs of D registers
1681 - { } can be omitted from around a singleton register list
1682 FIXME: This is not implemented, as it would require backtracking in
1683 some cases, e.g.:
1684 vtbl.8 d3,d4,d5
1685 This could be done (the meaning isn't really ambiguous), but doesn't
1686 fit in well with the current parsing framework.
dcbf9037
JB
1687 - 32 D registers may be used (also true for VFPv3).
1688 FIXME: Types are ignored in these register lists, which is probably a
1689 bug. */
6057a28f 1690
c19d1205 1691static int
037e8744 1692parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1693{
037e8744 1694 char *str = *ccp;
c19d1205
ZW
1695 int base_reg;
1696 int new_base;
21d799b5 1697 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1698 int max_regs = 0;
c19d1205
ZW
1699 int count = 0;
1700 int warned = 0;
1701 unsigned long mask = 0;
a737bd4d 1702 int i;
6057a28f 1703
037e8744 1704 if (*str != '{')
5287ad62
JB
1705 {
1706 inst.error = _("expecting {");
1707 return FAIL;
1708 }
6057a28f 1709
037e8744 1710 str++;
6057a28f 1711
5287ad62 1712 switch (etype)
c19d1205 1713 {
5287ad62 1714 case REGLIST_VFP_S:
c19d1205
ZW
1715 regtype = REG_TYPE_VFS;
1716 max_regs = 32;
5287ad62 1717 break;
5f4273c7 1718
5287ad62
JB
1719 case REGLIST_VFP_D:
1720 regtype = REG_TYPE_VFD;
b7fc2769 1721 break;
5f4273c7 1722
b7fc2769
JB
1723 case REGLIST_NEON_D:
1724 regtype = REG_TYPE_NDQ;
1725 break;
1726 }
1727
1728 if (etype != REGLIST_VFP_S)
1729 {
b1cc4aeb
PB
1730 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1731 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1732 {
1733 max_regs = 32;
1734 if (thumb_mode)
1735 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1736 fpu_vfp_ext_d32);
5287ad62
JB
1737 else
1738 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1739 fpu_vfp_ext_d32);
5287ad62
JB
1740 }
1741 else
1742 max_regs = 16;
c19d1205 1743 }
6057a28f 1744
c19d1205 1745 base_reg = max_regs;
a737bd4d 1746
c19d1205
ZW
1747 do
1748 {
5287ad62 1749 int setmask = 1, addregs = 1;
dcbf9037 1750
037e8744 1751 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1752
c19d1205 1753 if (new_base == FAIL)
a737bd4d 1754 {
dcbf9037 1755 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1756 return FAIL;
1757 }
5f4273c7 1758
b7fc2769
JB
1759 if (new_base >= max_regs)
1760 {
1761 first_error (_("register out of range in list"));
1762 return FAIL;
1763 }
5f4273c7 1764
5287ad62
JB
1765 /* Note: a value of 2 * n is returned for the register Q<n>. */
1766 if (regtype == REG_TYPE_NQ)
1767 {
1768 setmask = 3;
1769 addregs = 2;
1770 }
1771
c19d1205
ZW
1772 if (new_base < base_reg)
1773 base_reg = new_base;
a737bd4d 1774
5287ad62 1775 if (mask & (setmask << new_base))
c19d1205 1776 {
dcbf9037 1777 first_error (_("invalid register list"));
c19d1205 1778 return FAIL;
a737bd4d 1779 }
a737bd4d 1780
c19d1205
ZW
1781 if ((mask >> new_base) != 0 && ! warned)
1782 {
1783 as_tsktsk (_("register list not in ascending order"));
1784 warned = 1;
1785 }
0bbf2aa4 1786
5287ad62
JB
1787 mask |= setmask << new_base;
1788 count += addregs;
0bbf2aa4 1789
037e8744 1790 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1791 {
1792 int high_range;
0bbf2aa4 1793
037e8744 1794 str++;
0bbf2aa4 1795
037e8744 1796 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1797 == FAIL)
c19d1205
ZW
1798 {
1799 inst.error = gettext (reg_expected_msgs[regtype]);
1800 return FAIL;
1801 }
0bbf2aa4 1802
b7fc2769
JB
1803 if (high_range >= max_regs)
1804 {
1805 first_error (_("register out of range in list"));
1806 return FAIL;
1807 }
1808
5287ad62
JB
1809 if (regtype == REG_TYPE_NQ)
1810 high_range = high_range + 1;
1811
c19d1205
ZW
1812 if (high_range <= new_base)
1813 {
1814 inst.error = _("register range not in ascending order");
1815 return FAIL;
1816 }
0bbf2aa4 1817
5287ad62 1818 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1819 {
5287ad62 1820 if (mask & (setmask << new_base))
0bbf2aa4 1821 {
c19d1205
ZW
1822 inst.error = _("invalid register list");
1823 return FAIL;
0bbf2aa4 1824 }
c19d1205 1825
5287ad62
JB
1826 mask |= setmask << new_base;
1827 count += addregs;
0bbf2aa4 1828 }
0bbf2aa4 1829 }
0bbf2aa4 1830 }
037e8744 1831 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1832
037e8744 1833 str++;
0bbf2aa4 1834
c19d1205
ZW
1835 /* Sanity check -- should have raised a parse error above. */
1836 if (count == 0 || count > max_regs)
1837 abort ();
1838
1839 *pbase = base_reg;
1840
1841 /* Final test -- the registers must be consecutive. */
1842 mask >>= base_reg;
1843 for (i = 0; i < count; i++)
1844 {
1845 if ((mask & (1u << i)) == 0)
1846 {
1847 inst.error = _("non-contiguous register range");
1848 return FAIL;
1849 }
1850 }
1851
037e8744
JB
1852 *ccp = str;
1853
c19d1205 1854 return count;
b99bd4ef
NC
1855}
1856
dcbf9037
JB
1857/* True if two alias types are the same. */
1858
c921be7d 1859static bfd_boolean
dcbf9037
JB
1860neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1861{
1862 if (!a && !b)
c921be7d 1863 return TRUE;
5f4273c7 1864
dcbf9037 1865 if (!a || !b)
c921be7d 1866 return FALSE;
dcbf9037
JB
1867
1868 if (a->defined != b->defined)
c921be7d 1869 return FALSE;
5f4273c7 1870
dcbf9037
JB
1871 if ((a->defined & NTA_HASTYPE) != 0
1872 && (a->eltype.type != b->eltype.type
1873 || a->eltype.size != b->eltype.size))
c921be7d 1874 return FALSE;
dcbf9037
JB
1875
1876 if ((a->defined & NTA_HASINDEX) != 0
1877 && (a->index != b->index))
c921be7d 1878 return FALSE;
5f4273c7 1879
c921be7d 1880 return TRUE;
dcbf9037
JB
1881}
1882
5287ad62
JB
1883/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1884 The base register is put in *PBASE.
dcbf9037 1885 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1886 the return value.
1887 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1888 Bits [6:5] encode the list length (minus one).
1889 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1890
5287ad62 1891#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1892#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1893#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1894
1895static int
dcbf9037
JB
1896parse_neon_el_struct_list (char **str, unsigned *pbase,
1897 struct neon_type_el *eltype)
5287ad62
JB
1898{
1899 char *ptr = *str;
1900 int base_reg = -1;
1901 int reg_incr = -1;
1902 int count = 0;
1903 int lane = -1;
1904 int leading_brace = 0;
1905 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1906 const char *const incr_error = _("register stride must be 1 or 2");
1907 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1908 struct neon_typed_alias firsttype;
5f4273c7 1909
5287ad62
JB
1910 if (skip_past_char (&ptr, '{') == SUCCESS)
1911 leading_brace = 1;
5f4273c7 1912
5287ad62
JB
1913 do
1914 {
dcbf9037
JB
1915 struct neon_typed_alias atype;
1916 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1917
5287ad62
JB
1918 if (getreg == FAIL)
1919 {
dcbf9037 1920 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1921 return FAIL;
1922 }
5f4273c7 1923
5287ad62
JB
1924 if (base_reg == -1)
1925 {
1926 base_reg = getreg;
1927 if (rtype == REG_TYPE_NQ)
1928 {
1929 reg_incr = 1;
5287ad62 1930 }
dcbf9037 1931 firsttype = atype;
5287ad62
JB
1932 }
1933 else if (reg_incr == -1)
1934 {
1935 reg_incr = getreg - base_reg;
1936 if (reg_incr < 1 || reg_incr > 2)
1937 {
dcbf9037 1938 first_error (_(incr_error));
5287ad62
JB
1939 return FAIL;
1940 }
1941 }
1942 else if (getreg != base_reg + reg_incr * count)
1943 {
dcbf9037
JB
1944 first_error (_(incr_error));
1945 return FAIL;
1946 }
1947
c921be7d 1948 if (! neon_alias_types_same (&atype, &firsttype))
dcbf9037
JB
1949 {
1950 first_error (_(type_error));
5287ad62
JB
1951 return FAIL;
1952 }
5f4273c7 1953
5287ad62
JB
1954 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1955 modes. */
1956 if (ptr[0] == '-')
1957 {
dcbf9037 1958 struct neon_typed_alias htype;
5287ad62
JB
1959 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1960 if (lane == -1)
1961 lane = NEON_INTERLEAVE_LANES;
1962 else if (lane != NEON_INTERLEAVE_LANES)
1963 {
dcbf9037 1964 first_error (_(type_error));
5287ad62
JB
1965 return FAIL;
1966 }
1967 if (reg_incr == -1)
1968 reg_incr = 1;
1969 else if (reg_incr != 1)
1970 {
dcbf9037 1971 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1972 return FAIL;
1973 }
1974 ptr++;
dcbf9037 1975 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1976 if (hireg == FAIL)
1977 {
dcbf9037
JB
1978 first_error (_(reg_expected_msgs[rtype]));
1979 return FAIL;
1980 }
c921be7d 1981 if (! neon_alias_types_same (&htype, &firsttype))
dcbf9037
JB
1982 {
1983 first_error (_(type_error));
5287ad62
JB
1984 return FAIL;
1985 }
1986 count += hireg + dregs - getreg;
1987 continue;
1988 }
5f4273c7 1989
5287ad62
JB
1990 /* If we're using Q registers, we can't use [] or [n] syntax. */
1991 if (rtype == REG_TYPE_NQ)
1992 {
1993 count += 2;
1994 continue;
1995 }
5f4273c7 1996
dcbf9037 1997 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1998 {
dcbf9037
JB
1999 if (lane == -1)
2000 lane = atype.index;
2001 else if (lane != atype.index)
5287ad62 2002 {
dcbf9037
JB
2003 first_error (_(type_error));
2004 return FAIL;
5287ad62
JB
2005 }
2006 }
2007 else if (lane == -1)
2008 lane = NEON_INTERLEAVE_LANES;
2009 else if (lane != NEON_INTERLEAVE_LANES)
2010 {
dcbf9037 2011 first_error (_(type_error));
5287ad62
JB
2012 return FAIL;
2013 }
2014 count++;
2015 }
2016 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2017
5287ad62
JB
2018 /* No lane set by [x]. We must be interleaving structures. */
2019 if (lane == -1)
2020 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2021
5287ad62
JB
2022 /* Sanity check. */
2023 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2024 || (count > 1 && reg_incr == -1))
2025 {
dcbf9037 2026 first_error (_("error parsing element/structure list"));
5287ad62
JB
2027 return FAIL;
2028 }
2029
2030 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2031 {
dcbf9037 2032 first_error (_("expected }"));
5287ad62
JB
2033 return FAIL;
2034 }
5f4273c7 2035
5287ad62
JB
2036 if (reg_incr == -1)
2037 reg_incr = 1;
2038
dcbf9037
JB
2039 if (eltype)
2040 *eltype = firsttype.eltype;
2041
5287ad62
JB
2042 *pbase = base_reg;
2043 *str = ptr;
5f4273c7 2044
5287ad62
JB
2045 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2046}
2047
c19d1205
ZW
2048/* Parse an explicit relocation suffix on an expression. This is
2049 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2050 arm_reloc_hsh contains no entries, so this function can only
2051 succeed if there is no () after the word. Returns -1 on error,
2052 BFD_RELOC_UNUSED if there wasn't any suffix. */
2053static int
2054parse_reloc (char **str)
b99bd4ef 2055{
c19d1205
ZW
2056 struct reloc_entry *r;
2057 char *p, *q;
b99bd4ef 2058
c19d1205
ZW
2059 if (**str != '(')
2060 return BFD_RELOC_UNUSED;
b99bd4ef 2061
c19d1205
ZW
2062 p = *str + 1;
2063 q = p;
2064
2065 while (*q && *q != ')' && *q != ',')
2066 q++;
2067 if (*q != ')')
2068 return -1;
2069
21d799b5
NC
2070 if ((r = (struct reloc_entry *)
2071 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2072 return -1;
2073
2074 *str = q + 1;
2075 return r->reloc;
b99bd4ef
NC
2076}
2077
c19d1205
ZW
2078/* Directives: register aliases. */
2079
dcbf9037 2080static struct reg_entry *
90ec0d68 2081insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2082{
d3ce72d0 2083 struct reg_entry *new_reg;
c19d1205 2084 const char *name;
b99bd4ef 2085
d3ce72d0 2086 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2087 {
d3ce72d0 2088 if (new_reg->builtin)
c19d1205 2089 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2090
c19d1205
ZW
2091 /* Only warn about a redefinition if it's not defined as the
2092 same register. */
d3ce72d0 2093 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2094 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2095
d929913e 2096 return NULL;
c19d1205 2097 }
b99bd4ef 2098
c19d1205 2099 name = xstrdup (str);
d3ce72d0 2100 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2101
d3ce72d0
NC
2102 new_reg->name = name;
2103 new_reg->number = number;
2104 new_reg->type = type;
2105 new_reg->builtin = FALSE;
2106 new_reg->neon = NULL;
b99bd4ef 2107
d3ce72d0 2108 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2109 abort ();
5f4273c7 2110
d3ce72d0 2111 return new_reg;
dcbf9037
JB
2112}
2113
2114static void
2115insert_neon_reg_alias (char *str, int number, int type,
2116 struct neon_typed_alias *atype)
2117{
2118 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2119
dcbf9037
JB
2120 if (!reg)
2121 {
2122 first_error (_("attempt to redefine typed alias"));
2123 return;
2124 }
5f4273c7 2125
dcbf9037
JB
2126 if (atype)
2127 {
21d799b5
NC
2128 reg->neon = (struct neon_typed_alias *)
2129 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2130 *reg->neon = *atype;
2131 }
c19d1205 2132}
b99bd4ef 2133
c19d1205 2134/* Look for the .req directive. This is of the form:
b99bd4ef 2135
c19d1205 2136 new_register_name .req existing_register_name
b99bd4ef 2137
c19d1205 2138 If we find one, or if it looks sufficiently like one that we want to
d929913e 2139 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2140
d929913e 2141static bfd_boolean
c19d1205
ZW
2142create_register_alias (char * newname, char *p)
2143{
2144 struct reg_entry *old;
2145 char *oldname, *nbuf;
2146 size_t nlen;
b99bd4ef 2147
c19d1205
ZW
2148 /* The input scrubber ensures that whitespace after the mnemonic is
2149 collapsed to single spaces. */
2150 oldname = p;
2151 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2152 return FALSE;
b99bd4ef 2153
c19d1205
ZW
2154 oldname += 6;
2155 if (*oldname == '\0')
d929913e 2156 return FALSE;
b99bd4ef 2157
21d799b5 2158 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2159 if (!old)
b99bd4ef 2160 {
c19d1205 2161 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2162 return TRUE;
b99bd4ef
NC
2163 }
2164
c19d1205
ZW
2165 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2166 the desired alias name, and p points to its end. If not, then
2167 the desired alias name is in the global original_case_string. */
2168#ifdef TC_CASE_SENSITIVE
2169 nlen = p - newname;
2170#else
2171 newname = original_case_string;
2172 nlen = strlen (newname);
2173#endif
b99bd4ef 2174
21d799b5 2175 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2176 memcpy (nbuf, newname, nlen);
2177 nbuf[nlen] = '\0';
b99bd4ef 2178
c19d1205
ZW
2179 /* Create aliases under the new name as stated; an all-lowercase
2180 version of the new name; and an all-uppercase version of the new
2181 name. */
d929913e
NC
2182 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2183 {
2184 for (p = nbuf; *p; p++)
2185 *p = TOUPPER (*p);
c19d1205 2186
d929913e
NC
2187 if (strncmp (nbuf, newname, nlen))
2188 {
2189 /* If this attempt to create an additional alias fails, do not bother
2190 trying to create the all-lower case alias. We will fail and issue
2191 a second, duplicate error message. This situation arises when the
2192 programmer does something like:
2193 foo .req r0
2194 Foo .req r1
2195 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2196 the artificial FOO alias because it has already been created by the
d929913e
NC
2197 first .req. */
2198 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2199 return TRUE;
2200 }
c19d1205 2201
d929913e
NC
2202 for (p = nbuf; *p; p++)
2203 *p = TOLOWER (*p);
c19d1205 2204
d929913e
NC
2205 if (strncmp (nbuf, newname, nlen))
2206 insert_reg_alias (nbuf, old->number, old->type);
2207 }
c19d1205 2208
d929913e 2209 return TRUE;
b99bd4ef
NC
2210}
2211
dcbf9037
JB
2212/* Create a Neon typed/indexed register alias using directives, e.g.:
2213 X .dn d5.s32[1]
2214 Y .qn 6.s16
2215 Z .dn d7
2216 T .dn Z[0]
2217 These typed registers can be used instead of the types specified after the
2218 Neon mnemonic, so long as all operands given have types. Types can also be
2219 specified directly, e.g.:
5f4273c7 2220 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2221
c921be7d 2222static bfd_boolean
dcbf9037
JB
2223create_neon_reg_alias (char *newname, char *p)
2224{
2225 enum arm_reg_type basetype;
2226 struct reg_entry *basereg;
2227 struct reg_entry mybasereg;
2228 struct neon_type ntype;
2229 struct neon_typed_alias typeinfo;
12d6b0b7 2230 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2231 int namelen;
5f4273c7 2232
dcbf9037
JB
2233 typeinfo.defined = 0;
2234 typeinfo.eltype.type = NT_invtype;
2235 typeinfo.eltype.size = -1;
2236 typeinfo.index = -1;
5f4273c7 2237
dcbf9037 2238 nameend = p;
5f4273c7 2239
dcbf9037
JB
2240 if (strncmp (p, " .dn ", 5) == 0)
2241 basetype = REG_TYPE_VFD;
2242 else if (strncmp (p, " .qn ", 5) == 0)
2243 basetype = REG_TYPE_NQ;
2244 else
c921be7d 2245 return FALSE;
5f4273c7 2246
dcbf9037 2247 p += 5;
5f4273c7 2248
dcbf9037 2249 if (*p == '\0')
c921be7d 2250 return FALSE;
5f4273c7 2251
dcbf9037
JB
2252 basereg = arm_reg_parse_multi (&p);
2253
2254 if (basereg && basereg->type != basetype)
2255 {
2256 as_bad (_("bad type for register"));
c921be7d 2257 return FALSE;
dcbf9037
JB
2258 }
2259
2260 if (basereg == NULL)
2261 {
2262 expressionS exp;
2263 /* Try parsing as an integer. */
2264 my_get_expression (&exp, &p, GE_NO_PREFIX);
2265 if (exp.X_op != O_constant)
2266 {
2267 as_bad (_("expression must be constant"));
c921be7d 2268 return FALSE;
dcbf9037
JB
2269 }
2270 basereg = &mybasereg;
2271 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2272 : exp.X_add_number;
2273 basereg->neon = 0;
2274 }
2275
2276 if (basereg->neon)
2277 typeinfo = *basereg->neon;
2278
2279 if (parse_neon_type (&ntype, &p) == SUCCESS)
2280 {
2281 /* We got a type. */
2282 if (typeinfo.defined & NTA_HASTYPE)
2283 {
2284 as_bad (_("can't redefine the type of a register alias"));
c921be7d 2285 return FALSE;
dcbf9037 2286 }
5f4273c7 2287
dcbf9037
JB
2288 typeinfo.defined |= NTA_HASTYPE;
2289 if (ntype.elems != 1)
2290 {
2291 as_bad (_("you must specify a single type only"));
c921be7d 2292 return FALSE;
dcbf9037
JB
2293 }
2294 typeinfo.eltype = ntype.el[0];
2295 }
5f4273c7 2296
dcbf9037
JB
2297 if (skip_past_char (&p, '[') == SUCCESS)
2298 {
2299 expressionS exp;
2300 /* We got a scalar index. */
5f4273c7 2301
dcbf9037
JB
2302 if (typeinfo.defined & NTA_HASINDEX)
2303 {
2304 as_bad (_("can't redefine the index of a scalar alias"));
c921be7d 2305 return FALSE;
dcbf9037 2306 }
5f4273c7 2307
dcbf9037 2308 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2309
dcbf9037
JB
2310 if (exp.X_op != O_constant)
2311 {
2312 as_bad (_("scalar index must be constant"));
c921be7d 2313 return FALSE;
dcbf9037 2314 }
5f4273c7 2315
dcbf9037
JB
2316 typeinfo.defined |= NTA_HASINDEX;
2317 typeinfo.index = exp.X_add_number;
5f4273c7 2318
dcbf9037
JB
2319 if (skip_past_char (&p, ']') == FAIL)
2320 {
2321 as_bad (_("expecting ]"));
c921be7d 2322 return FALSE;
dcbf9037
JB
2323 }
2324 }
2325
15735687
NS
2326 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2327 the desired alias name, and p points to its end. If not, then
2328 the desired alias name is in the global original_case_string. */
2329#ifdef TC_CASE_SENSITIVE
dcbf9037 2330 namelen = nameend - newname;
15735687
NS
2331#else
2332 newname = original_case_string;
2333 namelen = strlen (newname);
2334#endif
2335
21d799b5 2336 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2337 strncpy (namebuf, newname, namelen);
2338 namebuf[namelen] = '\0';
5f4273c7 2339
dcbf9037
JB
2340 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2341 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2342
dcbf9037
JB
2343 /* Insert name in all uppercase. */
2344 for (p = namebuf; *p; p++)
2345 *p = TOUPPER (*p);
5f4273c7 2346
dcbf9037
JB
2347 if (strncmp (namebuf, newname, namelen))
2348 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2349 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2350
dcbf9037
JB
2351 /* Insert name in all lowercase. */
2352 for (p = namebuf; *p; p++)
2353 *p = TOLOWER (*p);
5f4273c7 2354
dcbf9037
JB
2355 if (strncmp (namebuf, newname, namelen))
2356 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2357 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2358
c921be7d 2359 return TRUE;
dcbf9037
JB
2360}
2361
c19d1205
ZW
2362/* Should never be called, as .req goes between the alias and the
2363 register name, not at the beginning of the line. */
c921be7d 2364
b99bd4ef 2365static void
c19d1205 2366s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2367{
c19d1205
ZW
2368 as_bad (_("invalid syntax for .req directive"));
2369}
b99bd4ef 2370
dcbf9037
JB
2371static void
2372s_dn (int a ATTRIBUTE_UNUSED)
2373{
2374 as_bad (_("invalid syntax for .dn directive"));
2375}
2376
2377static void
2378s_qn (int a ATTRIBUTE_UNUSED)
2379{
2380 as_bad (_("invalid syntax for .qn directive"));
2381}
2382
c19d1205
ZW
2383/* The .unreq directive deletes an alias which was previously defined
2384 by .req. For example:
b99bd4ef 2385
c19d1205
ZW
2386 my_alias .req r11
2387 .unreq my_alias */
b99bd4ef
NC
2388
2389static void
c19d1205 2390s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2391{
c19d1205
ZW
2392 char * name;
2393 char saved_char;
b99bd4ef 2394
c19d1205
ZW
2395 name = input_line_pointer;
2396
2397 while (*input_line_pointer != 0
2398 && *input_line_pointer != ' '
2399 && *input_line_pointer != '\n')
2400 ++input_line_pointer;
2401
2402 saved_char = *input_line_pointer;
2403 *input_line_pointer = 0;
2404
2405 if (!*name)
2406 as_bad (_("invalid syntax for .unreq directive"));
2407 else
2408 {
21d799b5
NC
2409 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2410 name);
c19d1205
ZW
2411
2412 if (!reg)
2413 as_bad (_("unknown register alias '%s'"), name);
2414 else if (reg->builtin)
a1727c1a 2415 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2416 name);
2417 else
2418 {
d929913e
NC
2419 char * p;
2420 char * nbuf;
2421
db0bc284 2422 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2423 free ((char *) reg->name);
dcbf9037
JB
2424 if (reg->neon)
2425 free (reg->neon);
c19d1205 2426 free (reg);
d929913e
NC
2427
2428 /* Also locate the all upper case and all lower case versions.
2429 Do not complain if we cannot find one or the other as it
2430 was probably deleted above. */
5f4273c7 2431
d929913e
NC
2432 nbuf = strdup (name);
2433 for (p = nbuf; *p; p++)
2434 *p = TOUPPER (*p);
21d799b5 2435 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2436 if (reg)
2437 {
db0bc284 2438 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2439 free ((char *) reg->name);
2440 if (reg->neon)
2441 free (reg->neon);
2442 free (reg);
2443 }
2444
2445 for (p = nbuf; *p; p++)
2446 *p = TOLOWER (*p);
21d799b5 2447 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2448 if (reg)
2449 {
db0bc284 2450 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2451 free ((char *) reg->name);
2452 if (reg->neon)
2453 free (reg->neon);
2454 free (reg);
2455 }
2456
2457 free (nbuf);
c19d1205
ZW
2458 }
2459 }
b99bd4ef 2460
c19d1205 2461 *input_line_pointer = saved_char;
b99bd4ef
NC
2462 demand_empty_rest_of_line ();
2463}
2464
c19d1205
ZW
2465/* Directives: Instruction set selection. */
2466
2467#ifdef OBJ_ELF
2468/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2469 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2470 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2471 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2472
cd000bff
DJ
2473/* Create a new mapping symbol for the transition to STATE. */
2474
2475static void
2476make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2477{
a737bd4d 2478 symbolS * symbolP;
c19d1205
ZW
2479 const char * symname;
2480 int type;
b99bd4ef 2481
c19d1205 2482 switch (state)
b99bd4ef 2483 {
c19d1205
ZW
2484 case MAP_DATA:
2485 symname = "$d";
2486 type = BSF_NO_FLAGS;
2487 break;
2488 case MAP_ARM:
2489 symname = "$a";
2490 type = BSF_NO_FLAGS;
2491 break;
2492 case MAP_THUMB:
2493 symname = "$t";
2494 type = BSF_NO_FLAGS;
2495 break;
c19d1205
ZW
2496 default:
2497 abort ();
2498 }
2499
cd000bff 2500 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2501 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2502
2503 switch (state)
2504 {
2505 case MAP_ARM:
2506 THUMB_SET_FUNC (symbolP, 0);
2507 ARM_SET_THUMB (symbolP, 0);
2508 ARM_SET_INTERWORK (symbolP, support_interwork);
2509 break;
2510
2511 case MAP_THUMB:
2512 THUMB_SET_FUNC (symbolP, 1);
2513 ARM_SET_THUMB (symbolP, 1);
2514 ARM_SET_INTERWORK (symbolP, support_interwork);
2515 break;
2516
2517 case MAP_DATA:
2518 default:
cd000bff
DJ
2519 break;
2520 }
2521
2522 /* Save the mapping symbols for future reference. Also check that
2523 we do not place two mapping symbols at the same offset within a
2524 frag. We'll handle overlap between frags in
2de7820f
JZ
2525 check_mapping_symbols.
2526
2527 If .fill or other data filling directive generates zero sized data,
2528 the mapping symbol for the following code will have the same value
2529 as the one generated for the data filling directive. In this case,
2530 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2531 if (value == 0)
2532 {
2de7820f
JZ
2533 if (frag->tc_frag_data.first_map != NULL)
2534 {
2535 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2536 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2537 }
cd000bff
DJ
2538 frag->tc_frag_data.first_map = symbolP;
2539 }
2540 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2541 {
2542 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2543 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2544 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2545 }
cd000bff
DJ
2546 frag->tc_frag_data.last_map = symbolP;
2547}
2548
2549/* We must sometimes convert a region marked as code to data during
2550 code alignment, if an odd number of bytes have to be padded. The
2551 code mapping symbol is pushed to an aligned address. */
2552
2553static void
2554insert_data_mapping_symbol (enum mstate state,
2555 valueT value, fragS *frag, offsetT bytes)
2556{
2557 /* If there was already a mapping symbol, remove it. */
2558 if (frag->tc_frag_data.last_map != NULL
2559 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2560 {
2561 symbolS *symp = frag->tc_frag_data.last_map;
2562
2563 if (value == 0)
2564 {
2565 know (frag->tc_frag_data.first_map == symp);
2566 frag->tc_frag_data.first_map = NULL;
2567 }
2568 frag->tc_frag_data.last_map = NULL;
2569 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2570 }
cd000bff
DJ
2571
2572 make_mapping_symbol (MAP_DATA, value, frag);
2573 make_mapping_symbol (state, value + bytes, frag);
2574}
2575
2576static void mapping_state_2 (enum mstate state, int max_chars);
2577
2578/* Set the mapping state to STATE. Only call this when about to
2579 emit some STATE bytes to the file. */
2580
2581void
2582mapping_state (enum mstate state)
2583{
940b5ce0
DJ
2584 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2585
cd000bff
DJ
2586#define TRANSITION(from, to) (mapstate == (from) && state == (to))
2587
2588 if (mapstate == state)
2589 /* The mapping symbol has already been emitted.
2590 There is nothing else to do. */
2591 return;
2592 else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2593 /* This case will be evaluated later in the next else. */
2594 return;
2595 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2596 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2597 {
2598 /* Only add the symbol if the offset is > 0:
2599 if we're at the first frag, check it's size > 0;
2600 if we're not at the first frag, then for sure
2601 the offset is > 0. */
2602 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2603 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2604
2605 if (add_symbol)
2606 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2607 }
2608
2609 mapping_state_2 (state, 0);
2610#undef TRANSITION
2611}
2612
2613/* Same as mapping_state, but MAX_CHARS bytes have already been
2614 allocated. Put the mapping symbol that far back. */
2615
2616static void
2617mapping_state_2 (enum mstate state, int max_chars)
2618{
940b5ce0
DJ
2619 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2620
2621 if (!SEG_NORMAL (now_seg))
2622 return;
2623
cd000bff
DJ
2624 if (mapstate == state)
2625 /* The mapping symbol has already been emitted.
2626 There is nothing else to do. */
2627 return;
2628
cd000bff
DJ
2629 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2630 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205
ZW
2631}
2632#else
d3106081
NS
2633#define mapping_state(x) ((void)0)
2634#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2635#endif
2636
2637/* Find the real, Thumb encoded start of a Thumb function. */
2638
4343666d 2639#ifdef OBJ_COFF
c19d1205
ZW
2640static symbolS *
2641find_real_start (symbolS * symbolP)
2642{
2643 char * real_start;
2644 const char * name = S_GET_NAME (symbolP);
2645 symbolS * new_target;
2646
2647 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2648#define STUB_NAME ".real_start_of"
2649
2650 if (name == NULL)
2651 abort ();
2652
37f6032b
ZW
2653 /* The compiler may generate BL instructions to local labels because
2654 it needs to perform a branch to a far away location. These labels
2655 do not have a corresponding ".real_start_of" label. We check
2656 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2657 the ".real_start_of" convention for nonlocal branches. */
2658 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2659 return symbolP;
2660
37f6032b 2661 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2662 new_target = symbol_find (real_start);
2663
2664 if (new_target == NULL)
2665 {
bd3ba5d1 2666 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2667 new_target = symbolP;
2668 }
2669
c19d1205
ZW
2670 return new_target;
2671}
4343666d 2672#endif
c19d1205
ZW
2673
2674static void
2675opcode_select (int width)
2676{
2677 switch (width)
2678 {
2679 case 16:
2680 if (! thumb_mode)
2681 {
e74cfd16 2682 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2683 as_bad (_("selected processor does not support THUMB opcodes"));
2684
2685 thumb_mode = 1;
2686 /* No need to force the alignment, since we will have been
2687 coming from ARM mode, which is word-aligned. */
2688 record_alignment (now_seg, 1);
2689 }
c19d1205
ZW
2690 break;
2691
2692 case 32:
2693 if (thumb_mode)
2694 {
e74cfd16 2695 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2696 as_bad (_("selected processor does not support ARM opcodes"));
2697
2698 thumb_mode = 0;
2699
2700 if (!need_pass_2)
2701 frag_align (2, 0, 0);
2702
2703 record_alignment (now_seg, 1);
2704 }
c19d1205
ZW
2705 break;
2706
2707 default:
2708 as_bad (_("invalid instruction size selected (%d)"), width);
2709 }
2710}
2711
2712static void
2713s_arm (int ignore ATTRIBUTE_UNUSED)
2714{
2715 opcode_select (32);
2716 demand_empty_rest_of_line ();
2717}
2718
2719static void
2720s_thumb (int ignore ATTRIBUTE_UNUSED)
2721{
2722 opcode_select (16);
2723 demand_empty_rest_of_line ();
2724}
2725
2726static void
2727s_code (int unused ATTRIBUTE_UNUSED)
2728{
2729 int temp;
2730
2731 temp = get_absolute_expression ();
2732 switch (temp)
2733 {
2734 case 16:
2735 case 32:
2736 opcode_select (temp);
2737 break;
2738
2739 default:
2740 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2741 }
2742}
2743
2744static void
2745s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2746{
2747 /* If we are not already in thumb mode go into it, EVEN if
2748 the target processor does not support thumb instructions.
2749 This is used by gcc/config/arm/lib1funcs.asm for example
2750 to compile interworking support functions even if the
2751 target processor should not support interworking. */
2752 if (! thumb_mode)
2753 {
2754 thumb_mode = 2;
2755 record_alignment (now_seg, 1);
2756 }
2757
2758 demand_empty_rest_of_line ();
2759}
2760
2761static void
2762s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2763{
2764 s_thumb (0);
2765
2766 /* The following label is the name/address of the start of a Thumb function.
2767 We need to know this for the interworking support. */
2768 label_is_thumb_function_name = TRUE;
2769}
2770
2771/* Perform a .set directive, but also mark the alias as
2772 being a thumb function. */
2773
2774static void
2775s_thumb_set (int equiv)
2776{
2777 /* XXX the following is a duplicate of the code for s_set() in read.c
2778 We cannot just call that code as we need to get at the symbol that
2779 is created. */
2780 char * name;
2781 char delim;
2782 char * end_name;
2783 symbolS * symbolP;
2784
2785 /* Especial apologies for the random logic:
2786 This just grew, and could be parsed much more simply!
2787 Dean - in haste. */
2788 name = input_line_pointer;
2789 delim = get_symbol_end ();
2790 end_name = input_line_pointer;
2791 *end_name = delim;
2792
2793 if (*input_line_pointer != ',')
2794 {
2795 *end_name = 0;
2796 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2797 *end_name = delim;
2798 ignore_rest_of_line ();
2799 return;
2800 }
2801
2802 input_line_pointer++;
2803 *end_name = 0;
2804
2805 if (name[0] == '.' && name[1] == '\0')
2806 {
2807 /* XXX - this should not happen to .thumb_set. */
2808 abort ();
2809 }
2810
2811 if ((symbolP = symbol_find (name)) == NULL
2812 && (symbolP = md_undefined_symbol (name)) == NULL)
2813 {
2814#ifndef NO_LISTING
2815 /* When doing symbol listings, play games with dummy fragments living
2816 outside the normal fragment chain to record the file and line info
c19d1205 2817 for this symbol. */
b99bd4ef
NC
2818 if (listing & LISTING_SYMBOLS)
2819 {
2820 extern struct list_info_struct * listing_tail;
21d799b5 2821 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2822
2823 memset (dummy_frag, 0, sizeof (fragS));
2824 dummy_frag->fr_type = rs_fill;
2825 dummy_frag->line = listing_tail;
2826 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2827 dummy_frag->fr_symbol = symbolP;
2828 }
2829 else
2830#endif
2831 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2832
2833#ifdef OBJ_COFF
2834 /* "set" symbols are local unless otherwise specified. */
2835 SF_SET_LOCAL (symbolP);
2836#endif /* OBJ_COFF */
2837 } /* Make a new symbol. */
2838
2839 symbol_table_insert (symbolP);
2840
2841 * end_name = delim;
2842
2843 if (equiv
2844 && S_IS_DEFINED (symbolP)
2845 && S_GET_SEGMENT (symbolP) != reg_section)
2846 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2847
2848 pseudo_set (symbolP);
2849
2850 demand_empty_rest_of_line ();
2851
c19d1205 2852 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2853
2854 THUMB_SET_FUNC (symbolP, 1);
2855 ARM_SET_THUMB (symbolP, 1);
2856#if defined OBJ_ELF || defined OBJ_COFF
2857 ARM_SET_INTERWORK (symbolP, support_interwork);
2858#endif
2859}
2860
c19d1205 2861/* Directives: Mode selection. */
b99bd4ef 2862
c19d1205
ZW
2863/* .syntax [unified|divided] - choose the new unified syntax
2864 (same for Arm and Thumb encoding, modulo slight differences in what
2865 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2866static void
c19d1205 2867s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2868{
c19d1205
ZW
2869 char *name, delim;
2870
2871 name = input_line_pointer;
2872 delim = get_symbol_end ();
2873
2874 if (!strcasecmp (name, "unified"))
2875 unified_syntax = TRUE;
2876 else if (!strcasecmp (name, "divided"))
2877 unified_syntax = FALSE;
2878 else
2879 {
2880 as_bad (_("unrecognized syntax mode \"%s\""), name);
2881 return;
2882 }
2883 *input_line_pointer = delim;
b99bd4ef
NC
2884 demand_empty_rest_of_line ();
2885}
2886
c19d1205
ZW
2887/* Directives: sectioning and alignment. */
2888
2889/* Same as s_align_ptwo but align 0 => align 2. */
2890
b99bd4ef 2891static void
c19d1205 2892s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2893{
a737bd4d 2894 int temp;
dce323d1 2895 bfd_boolean fill_p;
c19d1205
ZW
2896 long temp_fill;
2897 long max_alignment = 15;
b99bd4ef
NC
2898
2899 temp = get_absolute_expression ();
c19d1205
ZW
2900 if (temp > max_alignment)
2901 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2902 else if (temp < 0)
b99bd4ef 2903 {
c19d1205
ZW
2904 as_bad (_("alignment negative. 0 assumed."));
2905 temp = 0;
2906 }
b99bd4ef 2907
c19d1205
ZW
2908 if (*input_line_pointer == ',')
2909 {
2910 input_line_pointer++;
2911 temp_fill = get_absolute_expression ();
dce323d1 2912 fill_p = TRUE;
b99bd4ef 2913 }
c19d1205 2914 else
dce323d1
PB
2915 {
2916 fill_p = FALSE;
2917 temp_fill = 0;
2918 }
b99bd4ef 2919
c19d1205
ZW
2920 if (!temp)
2921 temp = 2;
b99bd4ef 2922
c19d1205
ZW
2923 /* Only make a frag if we HAVE to. */
2924 if (temp && !need_pass_2)
dce323d1
PB
2925 {
2926 if (!fill_p && subseg_text_p (now_seg))
2927 frag_align_code (temp, 0);
2928 else
2929 frag_align (temp, (int) temp_fill, 0);
2930 }
c19d1205
ZW
2931 demand_empty_rest_of_line ();
2932
2933 record_alignment (now_seg, temp);
b99bd4ef
NC
2934}
2935
c19d1205
ZW
2936static void
2937s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2938{
c19d1205
ZW
2939 /* We don't support putting frags in the BSS segment, we fake it by
2940 marking in_bss, then looking at s_skip for clues. */
2941 subseg_set (bss_section, 0);
2942 demand_empty_rest_of_line ();
cd000bff
DJ
2943
2944#ifdef md_elf_section_change_hook
2945 md_elf_section_change_hook ();
2946#endif
c19d1205 2947}
b99bd4ef 2948
c19d1205
ZW
2949static void
2950s_even (int ignore ATTRIBUTE_UNUSED)
2951{
2952 /* Never make frag if expect extra pass. */
2953 if (!need_pass_2)
2954 frag_align (1, 0, 0);
b99bd4ef 2955
c19d1205 2956 record_alignment (now_seg, 1);
b99bd4ef 2957
c19d1205 2958 demand_empty_rest_of_line ();
b99bd4ef
NC
2959}
2960
c19d1205 2961/* Directives: Literal pools. */
a737bd4d 2962
c19d1205
ZW
2963static literal_pool *
2964find_literal_pool (void)
a737bd4d 2965{
c19d1205 2966 literal_pool * pool;
a737bd4d 2967
c19d1205 2968 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2969 {
c19d1205
ZW
2970 if (pool->section == now_seg
2971 && pool->sub_section == now_subseg)
2972 break;
a737bd4d
NC
2973 }
2974
c19d1205 2975 return pool;
a737bd4d
NC
2976}
2977
c19d1205
ZW
2978static literal_pool *
2979find_or_make_literal_pool (void)
a737bd4d 2980{
c19d1205
ZW
2981 /* Next literal pool ID number. */
2982 static unsigned int latest_pool_num = 1;
2983 literal_pool * pool;
a737bd4d 2984
c19d1205 2985 pool = find_literal_pool ();
a737bd4d 2986
c19d1205 2987 if (pool == NULL)
a737bd4d 2988 {
c19d1205 2989 /* Create a new pool. */
21d799b5 2990 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
2991 if (! pool)
2992 return NULL;
a737bd4d 2993
c19d1205
ZW
2994 pool->next_free_entry = 0;
2995 pool->section = now_seg;
2996 pool->sub_section = now_subseg;
2997 pool->next = list_of_pools;
2998 pool->symbol = NULL;
2999
3000 /* Add it to the list. */
3001 list_of_pools = pool;
a737bd4d 3002 }
a737bd4d 3003
c19d1205
ZW
3004 /* New pools, and emptied pools, will have a NULL symbol. */
3005 if (pool->symbol == NULL)
a737bd4d 3006 {
c19d1205
ZW
3007 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3008 (valueT) 0, &zero_address_frag);
3009 pool->id = latest_pool_num ++;
a737bd4d
NC
3010 }
3011
c19d1205
ZW
3012 /* Done. */
3013 return pool;
a737bd4d
NC
3014}
3015
c19d1205 3016/* Add the literal in the global 'inst'
5f4273c7 3017 structure to the relevant literal pool. */
b99bd4ef
NC
3018
3019static int
c19d1205 3020add_to_lit_pool (void)
b99bd4ef 3021{
c19d1205
ZW
3022 literal_pool * pool;
3023 unsigned int entry;
b99bd4ef 3024
c19d1205
ZW
3025 pool = find_or_make_literal_pool ();
3026
3027 /* Check if this literal value is already in the pool. */
3028 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3029 {
c19d1205
ZW
3030 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3031 && (inst.reloc.exp.X_op == O_constant)
3032 && (pool->literals[entry].X_add_number
3033 == inst.reloc.exp.X_add_number)
3034 && (pool->literals[entry].X_unsigned
3035 == inst.reloc.exp.X_unsigned))
3036 break;
3037
3038 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3039 && (inst.reloc.exp.X_op == O_symbol)
3040 && (pool->literals[entry].X_add_number
3041 == inst.reloc.exp.X_add_number)
3042 && (pool->literals[entry].X_add_symbol
3043 == inst.reloc.exp.X_add_symbol)
3044 && (pool->literals[entry].X_op_symbol
3045 == inst.reloc.exp.X_op_symbol))
3046 break;
b99bd4ef
NC
3047 }
3048
c19d1205
ZW
3049 /* Do we need to create a new entry? */
3050 if (entry == pool->next_free_entry)
3051 {
3052 if (entry >= MAX_LITERAL_POOL_SIZE)
3053 {
3054 inst.error = _("literal pool overflow");
3055 return FAIL;
3056 }
3057
3058 pool->literals[entry] = inst.reloc.exp;
3059 pool->next_free_entry += 1;
3060 }
b99bd4ef 3061
c19d1205
ZW
3062 inst.reloc.exp.X_op = O_symbol;
3063 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3064 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3065
c19d1205 3066 return SUCCESS;
b99bd4ef
NC
3067}
3068
c19d1205
ZW
3069/* Can't use symbol_new here, so have to create a symbol and then at
3070 a later date assign it a value. Thats what these functions do. */
e16bb312 3071
c19d1205
ZW
3072static void
3073symbol_locate (symbolS * symbolP,
3074 const char * name, /* It is copied, the caller can modify. */
3075 segT segment, /* Segment identifier (SEG_<something>). */
3076 valueT valu, /* Symbol value. */
3077 fragS * frag) /* Associated fragment. */
3078{
3079 unsigned int name_length;
3080 char * preserved_copy_of_name;
e16bb312 3081
c19d1205
ZW
3082 name_length = strlen (name) + 1; /* +1 for \0. */
3083 obstack_grow (&notes, name, name_length);
21d799b5 3084 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3085
c19d1205
ZW
3086#ifdef tc_canonicalize_symbol_name
3087 preserved_copy_of_name =
3088 tc_canonicalize_symbol_name (preserved_copy_of_name);
3089#endif
b99bd4ef 3090
c19d1205 3091 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3092
c19d1205
ZW
3093 S_SET_SEGMENT (symbolP, segment);
3094 S_SET_VALUE (symbolP, valu);
3095 symbol_clear_list_pointers (symbolP);
b99bd4ef 3096
c19d1205 3097 symbol_set_frag (symbolP, frag);
b99bd4ef 3098
c19d1205
ZW
3099 /* Link to end of symbol chain. */
3100 {
3101 extern int symbol_table_frozen;
b99bd4ef 3102
c19d1205
ZW
3103 if (symbol_table_frozen)
3104 abort ();
3105 }
b99bd4ef 3106
c19d1205 3107 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3108
c19d1205 3109 obj_symbol_new_hook (symbolP);
b99bd4ef 3110
c19d1205
ZW
3111#ifdef tc_symbol_new_hook
3112 tc_symbol_new_hook (symbolP);
3113#endif
3114
3115#ifdef DEBUG_SYMS
3116 verify_symbol_chain (symbol_rootP, symbol_lastP);
3117#endif /* DEBUG_SYMS */
b99bd4ef
NC
3118}
3119
b99bd4ef 3120
c19d1205
ZW
3121static void
3122s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3123{
c19d1205
ZW
3124 unsigned int entry;
3125 literal_pool * pool;
3126 char sym_name[20];
b99bd4ef 3127
c19d1205
ZW
3128 pool = find_literal_pool ();
3129 if (pool == NULL
3130 || pool->symbol == NULL
3131 || pool->next_free_entry == 0)
3132 return;
b99bd4ef 3133
c19d1205 3134 mapping_state (MAP_DATA);
b99bd4ef 3135
c19d1205
ZW
3136 /* Align pool as you have word accesses.
3137 Only make a frag if we have to. */
3138 if (!need_pass_2)
3139 frag_align (2, 0, 0);
b99bd4ef 3140
c19d1205 3141 record_alignment (now_seg, 2);
b99bd4ef 3142
c19d1205 3143 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3144
c19d1205
ZW
3145 symbol_locate (pool->symbol, sym_name, now_seg,
3146 (valueT) frag_now_fix (), frag_now);
3147 symbol_table_insert (pool->symbol);
b99bd4ef 3148
c19d1205 3149 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3150
c19d1205
ZW
3151#if defined OBJ_COFF || defined OBJ_ELF
3152 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3153#endif
6c43fab6 3154
c19d1205
ZW
3155 for (entry = 0; entry < pool->next_free_entry; entry ++)
3156 /* First output the expression in the instruction to the pool. */
3157 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 3158
c19d1205
ZW
3159 /* Mark the pool as empty. */
3160 pool->next_free_entry = 0;
3161 pool->symbol = NULL;
b99bd4ef
NC
3162}
3163
c19d1205
ZW
3164#ifdef OBJ_ELF
3165/* Forward declarations for functions below, in the MD interface
3166 section. */
3167static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3168static valueT create_unwind_entry (int);
3169static void start_unwind_section (const segT, int);
3170static void add_unwind_opcode (valueT, int);
3171static void flush_pending_unwind (void);
b99bd4ef 3172
c19d1205 3173/* Directives: Data. */
b99bd4ef 3174
c19d1205
ZW
3175static void
3176s_arm_elf_cons (int nbytes)
3177{
3178 expressionS exp;
b99bd4ef 3179
c19d1205
ZW
3180#ifdef md_flush_pending_output
3181 md_flush_pending_output ();
3182#endif
b99bd4ef 3183
c19d1205 3184 if (is_it_end_of_statement ())
b99bd4ef 3185 {
c19d1205
ZW
3186 demand_empty_rest_of_line ();
3187 return;
b99bd4ef
NC
3188 }
3189
c19d1205
ZW
3190#ifdef md_cons_align
3191 md_cons_align (nbytes);
3192#endif
b99bd4ef 3193
c19d1205
ZW
3194 mapping_state (MAP_DATA);
3195 do
b99bd4ef 3196 {
c19d1205
ZW
3197 int reloc;
3198 char *base = input_line_pointer;
b99bd4ef 3199
c19d1205 3200 expression (& exp);
b99bd4ef 3201
c19d1205
ZW
3202 if (exp.X_op != O_symbol)
3203 emit_expr (&exp, (unsigned int) nbytes);
3204 else
3205 {
3206 char *before_reloc = input_line_pointer;
3207 reloc = parse_reloc (&input_line_pointer);
3208 if (reloc == -1)
3209 {
3210 as_bad (_("unrecognized relocation suffix"));
3211 ignore_rest_of_line ();
3212 return;
3213 }
3214 else if (reloc == BFD_RELOC_UNUSED)
3215 emit_expr (&exp, (unsigned int) nbytes);
3216 else
3217 {
21d799b5
NC
3218 reloc_howto_type *howto = (reloc_howto_type *)
3219 bfd_reloc_type_lookup (stdoutput,
3220 (bfd_reloc_code_real_type) reloc);
c19d1205 3221 int size = bfd_get_reloc_size (howto);
b99bd4ef 3222
2fc8bdac
ZW
3223 if (reloc == BFD_RELOC_ARM_PLT32)
3224 {
3225 as_bad (_("(plt) is only valid on branch targets"));
3226 reloc = BFD_RELOC_UNUSED;
3227 size = 0;
3228 }
3229
c19d1205 3230 if (size > nbytes)
2fc8bdac 3231 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3232 howto->name, nbytes);
3233 else
3234 {
3235 /* We've parsed an expression stopping at O_symbol.
3236 But there may be more expression left now that we
3237 have parsed the relocation marker. Parse it again.
3238 XXX Surely there is a cleaner way to do this. */
3239 char *p = input_line_pointer;
3240 int offset;
21d799b5 3241 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3242 memcpy (save_buf, base, input_line_pointer - base);
3243 memmove (base + (input_line_pointer - before_reloc),
3244 base, before_reloc - base);
3245
3246 input_line_pointer = base + (input_line_pointer-before_reloc);
3247 expression (&exp);
3248 memcpy (base, save_buf, p - base);
3249
3250 offset = nbytes - size;
3251 p = frag_more ((int) nbytes);
3252 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3253 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3254 }
3255 }
3256 }
b99bd4ef 3257 }
c19d1205 3258 while (*input_line_pointer++ == ',');
b99bd4ef 3259
c19d1205
ZW
3260 /* Put terminator back into stream. */
3261 input_line_pointer --;
3262 demand_empty_rest_of_line ();
b99bd4ef
NC
3263}
3264
c921be7d
NC
3265/* Emit an expression containing a 32-bit thumb instruction.
3266 Implementation based on put_thumb32_insn. */
3267
3268static void
3269emit_thumb32_expr (expressionS * exp)
3270{
3271 expressionS exp_high = *exp;
3272
3273 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3274 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3275 exp->X_add_number &= 0xffff;
3276 emit_expr (exp, (unsigned int) THUMB_SIZE);
3277}
3278
3279/* Guess the instruction size based on the opcode. */
3280
3281static int
3282thumb_insn_size (int opcode)
3283{
3284 if ((unsigned int) opcode < 0xe800u)
3285 return 2;
3286 else if ((unsigned int) opcode >= 0xe8000000u)
3287 return 4;
3288 else
3289 return 0;
3290}
3291
3292static bfd_boolean
3293emit_insn (expressionS *exp, int nbytes)
3294{
3295 int size = 0;
3296
3297 if (exp->X_op == O_constant)
3298 {
3299 size = nbytes;
3300
3301 if (size == 0)
3302 size = thumb_insn_size (exp->X_add_number);
3303
3304 if (size != 0)
3305 {
3306 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3307 {
3308 as_bad (_(".inst.n operand too big. "\
3309 "Use .inst.w instead"));
3310 size = 0;
3311 }
3312 else
3313 {
3314 if (now_it.state == AUTOMATIC_IT_BLOCK)
3315 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3316 else
3317 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3318
3319 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3320 emit_thumb32_expr (exp);
3321 else
3322 emit_expr (exp, (unsigned int) size);
3323
3324 it_fsm_post_encode ();
3325 }
3326 }
3327 else
3328 as_bad (_("cannot determine Thumb instruction size. " \
3329 "Use .inst.n/.inst.w instead"));
3330 }
3331 else
3332 as_bad (_("constant expression required"));
3333
3334 return (size != 0);
3335}
3336
3337/* Like s_arm_elf_cons but do not use md_cons_align and
3338 set the mapping state to MAP_ARM/MAP_THUMB. */
3339
3340static void
3341s_arm_elf_inst (int nbytes)
3342{
3343 if (is_it_end_of_statement ())
3344 {
3345 demand_empty_rest_of_line ();
3346 return;
3347 }
3348
3349 /* Calling mapping_state () here will not change ARM/THUMB,
3350 but will ensure not to be in DATA state. */
3351
3352 if (thumb_mode)
3353 mapping_state (MAP_THUMB);
3354 else
3355 {
3356 if (nbytes != 0)
3357 {
3358 as_bad (_("width suffixes are invalid in ARM mode"));
3359 ignore_rest_of_line ();
3360 return;
3361 }
3362
3363 nbytes = 4;
3364
3365 mapping_state (MAP_ARM);
3366 }
3367
3368 do
3369 {
3370 expressionS exp;
3371
3372 expression (& exp);
3373
3374 if (! emit_insn (& exp, nbytes))
3375 {
3376 ignore_rest_of_line ();
3377 return;
3378 }
3379 }
3380 while (*input_line_pointer++ == ',');
3381
3382 /* Put terminator back into stream. */
3383 input_line_pointer --;
3384 demand_empty_rest_of_line ();
3385}
b99bd4ef 3386
c19d1205 3387/* Parse a .rel31 directive. */
b99bd4ef 3388
c19d1205
ZW
3389static void
3390s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3391{
3392 expressionS exp;
3393 char *p;
3394 valueT highbit;
b99bd4ef 3395
c19d1205
ZW
3396 highbit = 0;
3397 if (*input_line_pointer == '1')
3398 highbit = 0x80000000;
3399 else if (*input_line_pointer != '0')
3400 as_bad (_("expected 0 or 1"));
b99bd4ef 3401
c19d1205
ZW
3402 input_line_pointer++;
3403 if (*input_line_pointer != ',')
3404 as_bad (_("missing comma"));
3405 input_line_pointer++;
b99bd4ef 3406
c19d1205
ZW
3407#ifdef md_flush_pending_output
3408 md_flush_pending_output ();
3409#endif
b99bd4ef 3410
c19d1205
ZW
3411#ifdef md_cons_align
3412 md_cons_align (4);
3413#endif
b99bd4ef 3414
c19d1205 3415 mapping_state (MAP_DATA);
b99bd4ef 3416
c19d1205 3417 expression (&exp);
b99bd4ef 3418
c19d1205
ZW
3419 p = frag_more (4);
3420 md_number_to_chars (p, highbit, 4);
3421 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3422 BFD_RELOC_ARM_PREL31);
b99bd4ef 3423
c19d1205 3424 demand_empty_rest_of_line ();
b99bd4ef
NC
3425}
3426
c19d1205 3427/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3428
c19d1205 3429/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3430
c19d1205
ZW
3431static void
3432s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3433{
3434 demand_empty_rest_of_line ();
921e5f0a
PB
3435 if (unwind.proc_start)
3436 {
c921be7d 3437 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3438 return;
3439 }
3440
c19d1205
ZW
3441 /* Mark the start of the function. */
3442 unwind.proc_start = expr_build_dot ();
b99bd4ef 3443
c19d1205
ZW
3444 /* Reset the rest of the unwind info. */
3445 unwind.opcode_count = 0;
3446 unwind.table_entry = NULL;
3447 unwind.personality_routine = NULL;
3448 unwind.personality_index = -1;
3449 unwind.frame_size = 0;
3450 unwind.fp_offset = 0;
fdfde340 3451 unwind.fp_reg = REG_SP;
c19d1205
ZW
3452 unwind.fp_used = 0;
3453 unwind.sp_restored = 0;
3454}
b99bd4ef 3455
b99bd4ef 3456
c19d1205
ZW
3457/* Parse a handlerdata directive. Creates the exception handling table entry
3458 for the function. */
b99bd4ef 3459
c19d1205
ZW
3460static void
3461s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3462{
3463 demand_empty_rest_of_line ();
921e5f0a 3464 if (!unwind.proc_start)
c921be7d 3465 as_bad (MISSING_FNSTART);
921e5f0a 3466
c19d1205 3467 if (unwind.table_entry)
6decc662 3468 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3469
c19d1205
ZW
3470 create_unwind_entry (1);
3471}
a737bd4d 3472
c19d1205 3473/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3474
c19d1205
ZW
3475static void
3476s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3477{
3478 long where;
3479 char *ptr;
3480 valueT val;
940b5ce0 3481 unsigned int marked_pr_dependency;
f02232aa 3482
c19d1205 3483 demand_empty_rest_of_line ();
f02232aa 3484
921e5f0a
PB
3485 if (!unwind.proc_start)
3486 {
c921be7d 3487 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3488 return;
3489 }
3490
c19d1205
ZW
3491 /* Add eh table entry. */
3492 if (unwind.table_entry == NULL)
3493 val = create_unwind_entry (0);
3494 else
3495 val = 0;
f02232aa 3496
c19d1205
ZW
3497 /* Add index table entry. This is two words. */
3498 start_unwind_section (unwind.saved_seg, 1);
3499 frag_align (2, 0, 0);
3500 record_alignment (now_seg, 2);
b99bd4ef 3501
c19d1205
ZW
3502 ptr = frag_more (8);
3503 where = frag_now_fix () - 8;
f02232aa 3504
c19d1205
ZW
3505 /* Self relative offset of the function start. */
3506 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3507 BFD_RELOC_ARM_PREL31);
f02232aa 3508
c19d1205
ZW
3509 /* Indicate dependency on EHABI-defined personality routines to the
3510 linker, if it hasn't been done already. */
940b5ce0
DJ
3511 marked_pr_dependency
3512 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3513 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3514 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3515 {
5f4273c7
NC
3516 static const char *const name[] =
3517 {
3518 "__aeabi_unwind_cpp_pr0",
3519 "__aeabi_unwind_cpp_pr1",
3520 "__aeabi_unwind_cpp_pr2"
3521 };
c19d1205
ZW
3522 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3523 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3524 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3525 |= 1 << unwind.personality_index;
c19d1205 3526 }
f02232aa 3527
c19d1205
ZW
3528 if (val)
3529 /* Inline exception table entry. */
3530 md_number_to_chars (ptr + 4, val, 4);
3531 else
3532 /* Self relative offset of the table entry. */
3533 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3534 BFD_RELOC_ARM_PREL31);
f02232aa 3535
c19d1205
ZW
3536 /* Restore the original section. */
3537 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3538
3539 unwind.proc_start = NULL;
c19d1205 3540}
f02232aa 3541
f02232aa 3542
c19d1205 3543/* Parse an unwind_cantunwind directive. */
b99bd4ef 3544
c19d1205
ZW
3545static void
3546s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3547{
3548 demand_empty_rest_of_line ();
921e5f0a 3549 if (!unwind.proc_start)
c921be7d 3550 as_bad (MISSING_FNSTART);
921e5f0a 3551
c19d1205
ZW
3552 if (unwind.personality_routine || unwind.personality_index != -1)
3553 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3554
c19d1205
ZW
3555 unwind.personality_index = -2;
3556}
b99bd4ef 3557
b99bd4ef 3558
c19d1205 3559/* Parse a personalityindex directive. */
b99bd4ef 3560
c19d1205
ZW
3561static void
3562s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3563{
3564 expressionS exp;
b99bd4ef 3565
921e5f0a 3566 if (!unwind.proc_start)
c921be7d 3567 as_bad (MISSING_FNSTART);
921e5f0a 3568
c19d1205
ZW
3569 if (unwind.personality_routine || unwind.personality_index != -1)
3570 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3571
c19d1205 3572 expression (&exp);
b99bd4ef 3573
c19d1205
ZW
3574 if (exp.X_op != O_constant
3575 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3576 {
c19d1205
ZW
3577 as_bad (_("bad personality routine number"));
3578 ignore_rest_of_line ();
3579 return;
b99bd4ef
NC
3580 }
3581
c19d1205 3582 unwind.personality_index = exp.X_add_number;
b99bd4ef 3583
c19d1205
ZW
3584 demand_empty_rest_of_line ();
3585}
e16bb312 3586
e16bb312 3587
c19d1205 3588/* Parse a personality directive. */
e16bb312 3589
c19d1205
ZW
3590static void
3591s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3592{
3593 char *name, *p, c;
a737bd4d 3594
921e5f0a 3595 if (!unwind.proc_start)
c921be7d 3596 as_bad (MISSING_FNSTART);
921e5f0a 3597
c19d1205
ZW
3598 if (unwind.personality_routine || unwind.personality_index != -1)
3599 as_bad (_("duplicate .personality directive"));
a737bd4d 3600
c19d1205
ZW
3601 name = input_line_pointer;
3602 c = get_symbol_end ();
3603 p = input_line_pointer;
3604 unwind.personality_routine = symbol_find_or_make (name);
3605 *p = c;
3606 demand_empty_rest_of_line ();
3607}
e16bb312 3608
e16bb312 3609
c19d1205 3610/* Parse a directive saving core registers. */
e16bb312 3611
c19d1205
ZW
3612static void
3613s_arm_unwind_save_core (void)
e16bb312 3614{
c19d1205
ZW
3615 valueT op;
3616 long range;
3617 int n;
e16bb312 3618
c19d1205
ZW
3619 range = parse_reg_list (&input_line_pointer);
3620 if (range == FAIL)
e16bb312 3621 {
c19d1205
ZW
3622 as_bad (_("expected register list"));
3623 ignore_rest_of_line ();
3624 return;
3625 }
e16bb312 3626
c19d1205 3627 demand_empty_rest_of_line ();
e16bb312 3628
c19d1205
ZW
3629 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3630 into .unwind_save {..., sp...}. We aren't bothered about the value of
3631 ip because it is clobbered by calls. */
3632 if (unwind.sp_restored && unwind.fp_reg == 12
3633 && (range & 0x3000) == 0x1000)
3634 {
3635 unwind.opcode_count--;
3636 unwind.sp_restored = 0;
3637 range = (range | 0x2000) & ~0x1000;
3638 unwind.pending_offset = 0;
3639 }
e16bb312 3640
01ae4198
DJ
3641 /* Pop r4-r15. */
3642 if (range & 0xfff0)
c19d1205 3643 {
01ae4198
DJ
3644 /* See if we can use the short opcodes. These pop a block of up to 8
3645 registers starting with r4, plus maybe r14. */
3646 for (n = 0; n < 8; n++)
3647 {
3648 /* Break at the first non-saved register. */
3649 if ((range & (1 << (n + 4))) == 0)
3650 break;
3651 }
3652 /* See if there are any other bits set. */
3653 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3654 {
3655 /* Use the long form. */
3656 op = 0x8000 | ((range >> 4) & 0xfff);
3657 add_unwind_opcode (op, 2);
3658 }
0dd132b6 3659 else
01ae4198
DJ
3660 {
3661 /* Use the short form. */
3662 if (range & 0x4000)
3663 op = 0xa8; /* Pop r14. */
3664 else
3665 op = 0xa0; /* Do not pop r14. */
3666 op |= (n - 1);
3667 add_unwind_opcode (op, 1);
3668 }
c19d1205 3669 }
0dd132b6 3670
c19d1205
ZW
3671 /* Pop r0-r3. */
3672 if (range & 0xf)
3673 {
3674 op = 0xb100 | (range & 0xf);
3675 add_unwind_opcode (op, 2);
0dd132b6
NC
3676 }
3677
c19d1205
ZW
3678 /* Record the number of bytes pushed. */
3679 for (n = 0; n < 16; n++)
3680 {
3681 if (range & (1 << n))
3682 unwind.frame_size += 4;
3683 }
0dd132b6
NC
3684}
3685
c19d1205
ZW
3686
3687/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3688
3689static void
c19d1205 3690s_arm_unwind_save_fpa (int reg)
b99bd4ef 3691{
c19d1205
ZW
3692 expressionS exp;
3693 int num_regs;
3694 valueT op;
b99bd4ef 3695
c19d1205
ZW
3696 /* Get Number of registers to transfer. */
3697 if (skip_past_comma (&input_line_pointer) != FAIL)
3698 expression (&exp);
3699 else
3700 exp.X_op = O_illegal;
b99bd4ef 3701
c19d1205 3702 if (exp.X_op != O_constant)
b99bd4ef 3703 {
c19d1205
ZW
3704 as_bad (_("expected , <constant>"));
3705 ignore_rest_of_line ();
b99bd4ef
NC
3706 return;
3707 }
3708
c19d1205
ZW
3709 num_regs = exp.X_add_number;
3710
3711 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3712 {
c19d1205
ZW
3713 as_bad (_("number of registers must be in the range [1:4]"));
3714 ignore_rest_of_line ();
b99bd4ef
NC
3715 return;
3716 }
3717
c19d1205 3718 demand_empty_rest_of_line ();
b99bd4ef 3719
c19d1205
ZW
3720 if (reg == 4)
3721 {
3722 /* Short form. */
3723 op = 0xb4 | (num_regs - 1);
3724 add_unwind_opcode (op, 1);
3725 }
b99bd4ef
NC
3726 else
3727 {
c19d1205
ZW
3728 /* Long form. */
3729 op = 0xc800 | (reg << 4) | (num_regs - 1);
3730 add_unwind_opcode (op, 2);
b99bd4ef 3731 }
c19d1205 3732 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3733}
3734
c19d1205 3735
fa073d69
MS
3736/* Parse a directive saving VFP registers for ARMv6 and above. */
3737
3738static void
3739s_arm_unwind_save_vfp_armv6 (void)
3740{
3741 int count;
3742 unsigned int start;
3743 valueT op;
3744 int num_vfpv3_regs = 0;
3745 int num_regs_below_16;
3746
3747 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3748 if (count == FAIL)
3749 {
3750 as_bad (_("expected register list"));
3751 ignore_rest_of_line ();
3752 return;
3753 }
3754
3755 demand_empty_rest_of_line ();
3756
3757 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3758 than FSTMX/FLDMX-style ones). */
3759
3760 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3761 if (start >= 16)
3762 num_vfpv3_regs = count;
3763 else if (start + count > 16)
3764 num_vfpv3_regs = start + count - 16;
3765
3766 if (num_vfpv3_regs > 0)
3767 {
3768 int start_offset = start > 16 ? start - 16 : 0;
3769 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3770 add_unwind_opcode (op, 2);
3771 }
3772
3773 /* Generate opcode for registers numbered in the range 0 .. 15. */
3774 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3775 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3776 if (num_regs_below_16 > 0)
3777 {
3778 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3779 add_unwind_opcode (op, 2);
3780 }
3781
3782 unwind.frame_size += count * 8;
3783}
3784
3785
3786/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3787
3788static void
c19d1205 3789s_arm_unwind_save_vfp (void)
b99bd4ef 3790{
c19d1205 3791 int count;
ca3f61f7 3792 unsigned int reg;
c19d1205 3793 valueT op;
b99bd4ef 3794
5287ad62 3795 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3796 if (count == FAIL)
b99bd4ef 3797 {
c19d1205
ZW
3798 as_bad (_("expected register list"));
3799 ignore_rest_of_line ();
b99bd4ef
NC
3800 return;
3801 }
3802
c19d1205 3803 demand_empty_rest_of_line ();
b99bd4ef 3804
c19d1205 3805 if (reg == 8)
b99bd4ef 3806 {
c19d1205
ZW
3807 /* Short form. */
3808 op = 0xb8 | (count - 1);
3809 add_unwind_opcode (op, 1);
b99bd4ef 3810 }
c19d1205 3811 else
b99bd4ef 3812 {
c19d1205
ZW
3813 /* Long form. */
3814 op = 0xb300 | (reg << 4) | (count - 1);
3815 add_unwind_opcode (op, 2);
b99bd4ef 3816 }
c19d1205
ZW
3817 unwind.frame_size += count * 8 + 4;
3818}
b99bd4ef 3819
b99bd4ef 3820
c19d1205
ZW
3821/* Parse a directive saving iWMMXt data registers. */
3822
3823static void
3824s_arm_unwind_save_mmxwr (void)
3825{
3826 int reg;
3827 int hi_reg;
3828 int i;
3829 unsigned mask = 0;
3830 valueT op;
b99bd4ef 3831
c19d1205
ZW
3832 if (*input_line_pointer == '{')
3833 input_line_pointer++;
b99bd4ef 3834
c19d1205 3835 do
b99bd4ef 3836 {
dcbf9037 3837 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3838
c19d1205 3839 if (reg == FAIL)
b99bd4ef 3840 {
9b7132d3 3841 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3842 goto error;
b99bd4ef
NC
3843 }
3844
c19d1205
ZW
3845 if (mask >> reg)
3846 as_tsktsk (_("register list not in ascending order"));
3847 mask |= 1 << reg;
b99bd4ef 3848
c19d1205
ZW
3849 if (*input_line_pointer == '-')
3850 {
3851 input_line_pointer++;
dcbf9037 3852 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3853 if (hi_reg == FAIL)
3854 {
9b7132d3 3855 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3856 goto error;
3857 }
3858 else if (reg >= hi_reg)
3859 {
3860 as_bad (_("bad register range"));
3861 goto error;
3862 }
3863 for (; reg < hi_reg; reg++)
3864 mask |= 1 << reg;
3865 }
3866 }
3867 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3868
c19d1205
ZW
3869 if (*input_line_pointer == '}')
3870 input_line_pointer++;
b99bd4ef 3871
c19d1205 3872 demand_empty_rest_of_line ();
b99bd4ef 3873
708587a4 3874 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3875 the list. */
3876 flush_pending_unwind ();
b99bd4ef 3877
c19d1205 3878 for (i = 0; i < 16; i++)
b99bd4ef 3879 {
c19d1205
ZW
3880 if (mask & (1 << i))
3881 unwind.frame_size += 8;
b99bd4ef
NC
3882 }
3883
c19d1205
ZW
3884 /* Attempt to combine with a previous opcode. We do this because gcc
3885 likes to output separate unwind directives for a single block of
3886 registers. */
3887 if (unwind.opcode_count > 0)
b99bd4ef 3888 {
c19d1205
ZW
3889 i = unwind.opcodes[unwind.opcode_count - 1];
3890 if ((i & 0xf8) == 0xc0)
3891 {
3892 i &= 7;
3893 /* Only merge if the blocks are contiguous. */
3894 if (i < 6)
3895 {
3896 if ((mask & 0xfe00) == (1 << 9))
3897 {
3898 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3899 unwind.opcode_count--;
3900 }
3901 }
3902 else if (i == 6 && unwind.opcode_count >= 2)
3903 {
3904 i = unwind.opcodes[unwind.opcode_count - 2];
3905 reg = i >> 4;
3906 i &= 0xf;
b99bd4ef 3907
c19d1205
ZW
3908 op = 0xffff << (reg - 1);
3909 if (reg > 0
87a1fd79 3910 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3911 {
3912 op = (1 << (reg + i + 1)) - 1;
3913 op &= ~((1 << reg) - 1);
3914 mask |= op;
3915 unwind.opcode_count -= 2;
3916 }
3917 }
3918 }
b99bd4ef
NC
3919 }
3920
c19d1205
ZW
3921 hi_reg = 15;
3922 /* We want to generate opcodes in the order the registers have been
3923 saved, ie. descending order. */
3924 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3925 {
c19d1205
ZW
3926 /* Save registers in blocks. */
3927 if (reg < 0
3928 || !(mask & (1 << reg)))
3929 {
3930 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3931 preceding block. */
c19d1205
ZW
3932 if (reg != hi_reg)
3933 {
3934 if (reg == 9)
3935 {
3936 /* Short form. */
3937 op = 0xc0 | (hi_reg - 10);
3938 add_unwind_opcode (op, 1);
3939 }
3940 else
3941 {
3942 /* Long form. */
3943 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3944 add_unwind_opcode (op, 2);
3945 }
3946 }
3947 hi_reg = reg - 1;
3948 }
b99bd4ef
NC
3949 }
3950
c19d1205
ZW
3951 return;
3952error:
3953 ignore_rest_of_line ();
b99bd4ef
NC
3954}
3955
3956static void
c19d1205 3957s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3958{
c19d1205
ZW
3959 int reg;
3960 int hi_reg;
3961 unsigned mask = 0;
3962 valueT op;
b99bd4ef 3963
c19d1205
ZW
3964 if (*input_line_pointer == '{')
3965 input_line_pointer++;
b99bd4ef 3966
c19d1205 3967 do
b99bd4ef 3968 {
dcbf9037 3969 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3970
c19d1205
ZW
3971 if (reg == FAIL)
3972 {
9b7132d3 3973 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3974 goto error;
3975 }
b99bd4ef 3976
c19d1205
ZW
3977 reg -= 8;
3978 if (mask >> reg)
3979 as_tsktsk (_("register list not in ascending order"));
3980 mask |= 1 << reg;
b99bd4ef 3981
c19d1205
ZW
3982 if (*input_line_pointer == '-')
3983 {
3984 input_line_pointer++;
dcbf9037 3985 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3986 if (hi_reg == FAIL)
3987 {
9b7132d3 3988 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3989 goto error;
3990 }
3991 else if (reg >= hi_reg)
3992 {
3993 as_bad (_("bad register range"));
3994 goto error;
3995 }
3996 for (; reg < hi_reg; reg++)
3997 mask |= 1 << reg;
3998 }
b99bd4ef 3999 }
c19d1205 4000 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4001
c19d1205
ZW
4002 if (*input_line_pointer == '}')
4003 input_line_pointer++;
b99bd4ef 4004
c19d1205
ZW
4005 demand_empty_rest_of_line ();
4006
708587a4 4007 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4008 the list. */
4009 flush_pending_unwind ();
b99bd4ef 4010
c19d1205 4011 for (reg = 0; reg < 16; reg++)
b99bd4ef 4012 {
c19d1205
ZW
4013 if (mask & (1 << reg))
4014 unwind.frame_size += 4;
b99bd4ef 4015 }
c19d1205
ZW
4016 op = 0xc700 | mask;
4017 add_unwind_opcode (op, 2);
4018 return;
4019error:
4020 ignore_rest_of_line ();
b99bd4ef
NC
4021}
4022
c19d1205 4023
fa073d69
MS
4024/* Parse an unwind_save directive.
4025 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4026
b99bd4ef 4027static void
fa073d69 4028s_arm_unwind_save (int arch_v6)
b99bd4ef 4029{
c19d1205
ZW
4030 char *peek;
4031 struct reg_entry *reg;
4032 bfd_boolean had_brace = FALSE;
b99bd4ef 4033
921e5f0a 4034 if (!unwind.proc_start)
c921be7d 4035 as_bad (MISSING_FNSTART);
921e5f0a 4036
c19d1205
ZW
4037 /* Figure out what sort of save we have. */
4038 peek = input_line_pointer;
b99bd4ef 4039
c19d1205 4040 if (*peek == '{')
b99bd4ef 4041 {
c19d1205
ZW
4042 had_brace = TRUE;
4043 peek++;
b99bd4ef
NC
4044 }
4045
c19d1205 4046 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4047
c19d1205 4048 if (!reg)
b99bd4ef 4049 {
c19d1205
ZW
4050 as_bad (_("register expected"));
4051 ignore_rest_of_line ();
b99bd4ef
NC
4052 return;
4053 }
4054
c19d1205 4055 switch (reg->type)
b99bd4ef 4056 {
c19d1205
ZW
4057 case REG_TYPE_FN:
4058 if (had_brace)
4059 {
4060 as_bad (_("FPA .unwind_save does not take a register list"));
4061 ignore_rest_of_line ();
4062 return;
4063 }
93ac2687 4064 input_line_pointer = peek;
c19d1205 4065 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4066 return;
c19d1205
ZW
4067
4068 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
4069 case REG_TYPE_VFD:
4070 if (arch_v6)
4071 s_arm_unwind_save_vfp_armv6 ();
4072 else
4073 s_arm_unwind_save_vfp ();
4074 return;
c19d1205
ZW
4075 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4076 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4077
4078 default:
4079 as_bad (_(".unwind_save does not support this kind of register"));
4080 ignore_rest_of_line ();
b99bd4ef 4081 }
c19d1205 4082}
b99bd4ef 4083
b99bd4ef 4084
c19d1205
ZW
4085/* Parse an unwind_movsp directive. */
4086
4087static void
4088s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4089{
4090 int reg;
4091 valueT op;
4fa3602b 4092 int offset;
c19d1205 4093
921e5f0a 4094 if (!unwind.proc_start)
c921be7d 4095 as_bad (MISSING_FNSTART);
921e5f0a 4096
dcbf9037 4097 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4098 if (reg == FAIL)
b99bd4ef 4099 {
9b7132d3 4100 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4101 ignore_rest_of_line ();
b99bd4ef
NC
4102 return;
4103 }
4fa3602b
PB
4104
4105 /* Optional constant. */
4106 if (skip_past_comma (&input_line_pointer) != FAIL)
4107 {
4108 if (immediate_for_directive (&offset) == FAIL)
4109 return;
4110 }
4111 else
4112 offset = 0;
4113
c19d1205 4114 demand_empty_rest_of_line ();
b99bd4ef 4115
c19d1205 4116 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4117 {
c19d1205 4118 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4119 return;
4120 }
4121
c19d1205
ZW
4122 if (unwind.fp_reg != REG_SP)
4123 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4124
c19d1205
ZW
4125 /* Generate opcode to restore the value. */
4126 op = 0x90 | reg;
4127 add_unwind_opcode (op, 1);
4128
4129 /* Record the information for later. */
4130 unwind.fp_reg = reg;
4fa3602b 4131 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4132 unwind.sp_restored = 1;
b05fe5cf
ZW
4133}
4134
c19d1205
ZW
4135/* Parse an unwind_pad directive. */
4136
b05fe5cf 4137static void
c19d1205 4138s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4139{
c19d1205 4140 int offset;
b05fe5cf 4141
921e5f0a 4142 if (!unwind.proc_start)
c921be7d 4143 as_bad (MISSING_FNSTART);
921e5f0a 4144
c19d1205
ZW
4145 if (immediate_for_directive (&offset) == FAIL)
4146 return;
b99bd4ef 4147
c19d1205
ZW
4148 if (offset & 3)
4149 {
4150 as_bad (_("stack increment must be multiple of 4"));
4151 ignore_rest_of_line ();
4152 return;
4153 }
b99bd4ef 4154
c19d1205
ZW
4155 /* Don't generate any opcodes, just record the details for later. */
4156 unwind.frame_size += offset;
4157 unwind.pending_offset += offset;
4158
4159 demand_empty_rest_of_line ();
4160}
4161
4162/* Parse an unwind_setfp directive. */
4163
4164static void
4165s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4166{
c19d1205
ZW
4167 int sp_reg;
4168 int fp_reg;
4169 int offset;
4170
921e5f0a 4171 if (!unwind.proc_start)
c921be7d 4172 as_bad (MISSING_FNSTART);
921e5f0a 4173
dcbf9037 4174 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4175 if (skip_past_comma (&input_line_pointer) == FAIL)
4176 sp_reg = FAIL;
4177 else
dcbf9037 4178 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4179
c19d1205
ZW
4180 if (fp_reg == FAIL || sp_reg == FAIL)
4181 {
4182 as_bad (_("expected <reg>, <reg>"));
4183 ignore_rest_of_line ();
4184 return;
4185 }
b99bd4ef 4186
c19d1205
ZW
4187 /* Optional constant. */
4188 if (skip_past_comma (&input_line_pointer) != FAIL)
4189 {
4190 if (immediate_for_directive (&offset) == FAIL)
4191 return;
4192 }
4193 else
4194 offset = 0;
a737bd4d 4195
c19d1205 4196 demand_empty_rest_of_line ();
a737bd4d 4197
fdfde340 4198 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4199 {
c19d1205
ZW
4200 as_bad (_("register must be either sp or set by a previous"
4201 "unwind_movsp directive"));
4202 return;
a737bd4d
NC
4203 }
4204
c19d1205
ZW
4205 /* Don't generate any opcodes, just record the information for later. */
4206 unwind.fp_reg = fp_reg;
4207 unwind.fp_used = 1;
fdfde340 4208 if (sp_reg == REG_SP)
c19d1205
ZW
4209 unwind.fp_offset = unwind.frame_size - offset;
4210 else
4211 unwind.fp_offset -= offset;
a737bd4d
NC
4212}
4213
c19d1205
ZW
4214/* Parse an unwind_raw directive. */
4215
4216static void
4217s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4218{
c19d1205 4219 expressionS exp;
708587a4 4220 /* This is an arbitrary limit. */
c19d1205
ZW
4221 unsigned char op[16];
4222 int count;
a737bd4d 4223
921e5f0a 4224 if (!unwind.proc_start)
c921be7d 4225 as_bad (MISSING_FNSTART);
921e5f0a 4226
c19d1205
ZW
4227 expression (&exp);
4228 if (exp.X_op == O_constant
4229 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4230 {
c19d1205
ZW
4231 unwind.frame_size += exp.X_add_number;
4232 expression (&exp);
4233 }
4234 else
4235 exp.X_op = O_illegal;
a737bd4d 4236
c19d1205
ZW
4237 if (exp.X_op != O_constant)
4238 {
4239 as_bad (_("expected <offset>, <opcode>"));
4240 ignore_rest_of_line ();
4241 return;
4242 }
a737bd4d 4243
c19d1205 4244 count = 0;
a737bd4d 4245
c19d1205
ZW
4246 /* Parse the opcode. */
4247 for (;;)
4248 {
4249 if (count >= 16)
4250 {
4251 as_bad (_("unwind opcode too long"));
4252 ignore_rest_of_line ();
a737bd4d 4253 }
c19d1205 4254 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4255 {
c19d1205
ZW
4256 as_bad (_("invalid unwind opcode"));
4257 ignore_rest_of_line ();
4258 return;
a737bd4d 4259 }
c19d1205 4260 op[count++] = exp.X_add_number;
a737bd4d 4261
c19d1205
ZW
4262 /* Parse the next byte. */
4263 if (skip_past_comma (&input_line_pointer) == FAIL)
4264 break;
a737bd4d 4265
c19d1205
ZW
4266 expression (&exp);
4267 }
b99bd4ef 4268
c19d1205
ZW
4269 /* Add the opcode bytes in reverse order. */
4270 while (count--)
4271 add_unwind_opcode (op[count], 1);
b99bd4ef 4272
c19d1205 4273 demand_empty_rest_of_line ();
b99bd4ef 4274}
ee065d83
PB
4275
4276
4277/* Parse a .eabi_attribute directive. */
4278
4279static void
4280s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4281{
ee3c0378
AS
4282 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4283
4284 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4285 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4286}
4287
0855e32b
NS
4288/* Emit a tls fix for the symbol. */
4289
4290static void
4291s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4292{
4293 char *p;
4294 expressionS exp;
4295#ifdef md_flush_pending_output
4296 md_flush_pending_output ();
4297#endif
4298
4299#ifdef md_cons_align
4300 md_cons_align (4);
4301#endif
4302
4303 /* Since we're just labelling the code, there's no need to define a
4304 mapping symbol. */
4305 expression (&exp);
4306 p = obstack_next_free (&frchain_now->frch_obstack);
4307 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4308 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4309 : BFD_RELOC_ARM_TLS_DESCSEQ);
4310}
cdf9ccec 4311#endif /* OBJ_ELF */
0855e32b 4312
ee065d83 4313static void s_arm_arch (int);
7a1d4c38 4314static void s_arm_object_arch (int);
ee065d83
PB
4315static void s_arm_cpu (int);
4316static void s_arm_fpu (int);
69133863 4317static void s_arm_arch_extension (int);
b99bd4ef 4318
f0927246
NC
4319#ifdef TE_PE
4320
4321static void
5f4273c7 4322pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4323{
4324 expressionS exp;
4325
4326 do
4327 {
4328 expression (&exp);
4329 if (exp.X_op == O_symbol)
4330 exp.X_op = O_secrel;
4331
4332 emit_expr (&exp, 4);
4333 }
4334 while (*input_line_pointer++ == ',');
4335
4336 input_line_pointer--;
4337 demand_empty_rest_of_line ();
4338}
4339#endif /* TE_PE */
4340
c19d1205
ZW
4341/* This table describes all the machine specific pseudo-ops the assembler
4342 has to support. The fields are:
4343 pseudo-op name without dot
4344 function to call to execute this pseudo-op
4345 Integer arg to pass to the function. */
b99bd4ef 4346
c19d1205 4347const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4348{
c19d1205
ZW
4349 /* Never called because '.req' does not start a line. */
4350 { "req", s_req, 0 },
dcbf9037
JB
4351 /* Following two are likewise never called. */
4352 { "dn", s_dn, 0 },
4353 { "qn", s_qn, 0 },
c19d1205
ZW
4354 { "unreq", s_unreq, 0 },
4355 { "bss", s_bss, 0 },
4356 { "align", s_align, 0 },
4357 { "arm", s_arm, 0 },
4358 { "thumb", s_thumb, 0 },
4359 { "code", s_code, 0 },
4360 { "force_thumb", s_force_thumb, 0 },
4361 { "thumb_func", s_thumb_func, 0 },
4362 { "thumb_set", s_thumb_set, 0 },
4363 { "even", s_even, 0 },
4364 { "ltorg", s_ltorg, 0 },
4365 { "pool", s_ltorg, 0 },
4366 { "syntax", s_syntax, 0 },
8463be01
PB
4367 { "cpu", s_arm_cpu, 0 },
4368 { "arch", s_arm_arch, 0 },
7a1d4c38 4369 { "object_arch", s_arm_object_arch, 0 },
8463be01 4370 { "fpu", s_arm_fpu, 0 },
69133863 4371 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4372#ifdef OBJ_ELF
c921be7d
NC
4373 { "word", s_arm_elf_cons, 4 },
4374 { "long", s_arm_elf_cons, 4 },
4375 { "inst.n", s_arm_elf_inst, 2 },
4376 { "inst.w", s_arm_elf_inst, 4 },
4377 { "inst", s_arm_elf_inst, 0 },
4378 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4379 { "fnstart", s_arm_unwind_fnstart, 0 },
4380 { "fnend", s_arm_unwind_fnend, 0 },
4381 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4382 { "personality", s_arm_unwind_personality, 0 },
4383 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4384 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4385 { "save", s_arm_unwind_save, 0 },
fa073d69 4386 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4387 { "movsp", s_arm_unwind_movsp, 0 },
4388 { "pad", s_arm_unwind_pad, 0 },
4389 { "setfp", s_arm_unwind_setfp, 0 },
4390 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4391 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4392 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4393#else
4394 { "word", cons, 4},
f0927246
NC
4395
4396 /* These are used for dwarf. */
4397 {"2byte", cons, 2},
4398 {"4byte", cons, 4},
4399 {"8byte", cons, 8},
4400 /* These are used for dwarf2. */
4401 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4402 { "loc", dwarf2_directive_loc, 0 },
4403 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4404#endif
4405 { "extend", float_cons, 'x' },
4406 { "ldouble", float_cons, 'x' },
4407 { "packed", float_cons, 'p' },
f0927246
NC
4408#ifdef TE_PE
4409 {"secrel32", pe_directive_secrel, 0},
4410#endif
c19d1205
ZW
4411 { 0, 0, 0 }
4412};
4413\f
4414/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4415
c19d1205
ZW
4416/* Generic immediate-value read function for use in insn parsing.
4417 STR points to the beginning of the immediate (the leading #);
4418 VAL receives the value; if the value is outside [MIN, MAX]
4419 issue an error. PREFIX_OPT is true if the immediate prefix is
4420 optional. */
b99bd4ef 4421
c19d1205
ZW
4422static int
4423parse_immediate (char **str, int *val, int min, int max,
4424 bfd_boolean prefix_opt)
4425{
4426 expressionS exp;
4427 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4428 if (exp.X_op != O_constant)
b99bd4ef 4429 {
c19d1205
ZW
4430 inst.error = _("constant expression required");
4431 return FAIL;
4432 }
b99bd4ef 4433
c19d1205
ZW
4434 if (exp.X_add_number < min || exp.X_add_number > max)
4435 {
4436 inst.error = _("immediate value out of range");
4437 return FAIL;
4438 }
b99bd4ef 4439
c19d1205
ZW
4440 *val = exp.X_add_number;
4441 return SUCCESS;
4442}
b99bd4ef 4443
5287ad62 4444/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4445 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4446 instructions. Puts the result directly in inst.operands[i]. */
4447
4448static int
4449parse_big_immediate (char **str, int i)
4450{
4451 expressionS exp;
4452 char *ptr = *str;
4453
4454 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4455
4456 if (exp.X_op == O_constant)
036dc3f7
PB
4457 {
4458 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4459 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4460 O_constant. We have to be careful not to break compilation for
4461 32-bit X_add_number, though. */
58ad575f 4462 if ((exp.X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7
PB
4463 {
4464 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4465 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4466 inst.operands[i].regisimm = 1;
4467 }
4468 }
5287ad62 4469 else if (exp.X_op == O_big
95b75c01 4470 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
5287ad62
JB
4471 {
4472 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4473
5287ad62
JB
4474 /* Bignums have their least significant bits in
4475 generic_bignum[0]. Make sure we put 32 bits in imm and
4476 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4477 gas_assert (parts != 0);
95b75c01
NC
4478
4479 /* Make sure that the number is not too big.
4480 PR 11972: Bignums can now be sign-extended to the
4481 size of a .octa so check that the out of range bits
4482 are all zero or all one. */
4483 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4484 {
4485 LITTLENUM_TYPE m = -1;
4486
4487 if (generic_bignum[parts * 2] != 0
4488 && generic_bignum[parts * 2] != m)
4489 return FAIL;
4490
4491 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4492 if (generic_bignum[j] != generic_bignum[j-1])
4493 return FAIL;
4494 }
4495
5287ad62
JB
4496 inst.operands[i].imm = 0;
4497 for (j = 0; j < parts; j++, idx++)
4498 inst.operands[i].imm |= generic_bignum[idx]
4499 << (LITTLENUM_NUMBER_OF_BITS * j);
4500 inst.operands[i].reg = 0;
4501 for (j = 0; j < parts; j++, idx++)
4502 inst.operands[i].reg |= generic_bignum[idx]
4503 << (LITTLENUM_NUMBER_OF_BITS * j);
4504 inst.operands[i].regisimm = 1;
4505 }
4506 else
4507 return FAIL;
5f4273c7 4508
5287ad62
JB
4509 *str = ptr;
4510
4511 return SUCCESS;
4512}
4513
c19d1205
ZW
4514/* Returns the pseudo-register number of an FPA immediate constant,
4515 or FAIL if there isn't a valid constant here. */
b99bd4ef 4516
c19d1205
ZW
4517static int
4518parse_fpa_immediate (char ** str)
4519{
4520 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4521 char * save_in;
4522 expressionS exp;
4523 int i;
4524 int j;
b99bd4ef 4525
c19d1205
ZW
4526 /* First try and match exact strings, this is to guarantee
4527 that some formats will work even for cross assembly. */
b99bd4ef 4528
c19d1205
ZW
4529 for (i = 0; fp_const[i]; i++)
4530 {
4531 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4532 {
c19d1205 4533 char *start = *str;
b99bd4ef 4534
c19d1205
ZW
4535 *str += strlen (fp_const[i]);
4536 if (is_end_of_line[(unsigned char) **str])
4537 return i + 8;
4538 *str = start;
4539 }
4540 }
b99bd4ef 4541
c19d1205
ZW
4542 /* Just because we didn't get a match doesn't mean that the constant
4543 isn't valid, just that it is in a format that we don't
4544 automatically recognize. Try parsing it with the standard
4545 expression routines. */
b99bd4ef 4546
c19d1205 4547 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4548
c19d1205
ZW
4549 /* Look for a raw floating point number. */
4550 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4551 && is_end_of_line[(unsigned char) *save_in])
4552 {
4553 for (i = 0; i < NUM_FLOAT_VALS; i++)
4554 {
4555 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4556 {
c19d1205
ZW
4557 if (words[j] != fp_values[i][j])
4558 break;
b99bd4ef
NC
4559 }
4560
c19d1205 4561 if (j == MAX_LITTLENUMS)
b99bd4ef 4562 {
c19d1205
ZW
4563 *str = save_in;
4564 return i + 8;
b99bd4ef
NC
4565 }
4566 }
4567 }
b99bd4ef 4568
c19d1205
ZW
4569 /* Try and parse a more complex expression, this will probably fail
4570 unless the code uses a floating point prefix (eg "0f"). */
4571 save_in = input_line_pointer;
4572 input_line_pointer = *str;
4573 if (expression (&exp) == absolute_section
4574 && exp.X_op == O_big
4575 && exp.X_add_number < 0)
4576 {
4577 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4578 Ditto for 15. */
4579 if (gen_to_words (words, 5, (long) 15) == 0)
4580 {
4581 for (i = 0; i < NUM_FLOAT_VALS; i++)
4582 {
4583 for (j = 0; j < MAX_LITTLENUMS; j++)
4584 {
4585 if (words[j] != fp_values[i][j])
4586 break;
4587 }
b99bd4ef 4588
c19d1205
ZW
4589 if (j == MAX_LITTLENUMS)
4590 {
4591 *str = input_line_pointer;
4592 input_line_pointer = save_in;
4593 return i + 8;
4594 }
4595 }
4596 }
b99bd4ef
NC
4597 }
4598
c19d1205
ZW
4599 *str = input_line_pointer;
4600 input_line_pointer = save_in;
4601 inst.error = _("invalid FPA immediate expression");
4602 return FAIL;
b99bd4ef
NC
4603}
4604
136da414
JB
4605/* Returns 1 if a number has "quarter-precision" float format
4606 0baBbbbbbc defgh000 00000000 00000000. */
4607
4608static int
4609is_quarter_float (unsigned imm)
4610{
4611 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4612 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4613}
4614
4615/* Parse an 8-bit "quarter-precision" floating point number of the form:
4616 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4617 The zero and minus-zero cases need special handling, since they can't be
4618 encoded in the "quarter-precision" float format, but can nonetheless be
4619 loaded as integer constants. */
136da414
JB
4620
4621static unsigned
4622parse_qfloat_immediate (char **ccp, int *immed)
4623{
4624 char *str = *ccp;
c96612cc 4625 char *fpnum;
136da414 4626 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4627 int found_fpchar = 0;
5f4273c7 4628
136da414 4629 skip_past_char (&str, '#');
5f4273c7 4630
c96612cc
JB
4631 /* We must not accidentally parse an integer as a floating-point number. Make
4632 sure that the value we parse is not an integer by checking for special
4633 characters '.' or 'e'.
4634 FIXME: This is a horrible hack, but doing better is tricky because type
4635 information isn't in a very usable state at parse time. */
4636 fpnum = str;
4637 skip_whitespace (fpnum);
4638
4639 if (strncmp (fpnum, "0x", 2) == 0)
4640 return FAIL;
4641 else
4642 {
4643 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4644 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4645 {
4646 found_fpchar = 1;
4647 break;
4648 }
4649
4650 if (!found_fpchar)
4651 return FAIL;
4652 }
5f4273c7 4653
136da414
JB
4654 if ((str = atof_ieee (str, 's', words)) != NULL)
4655 {
4656 unsigned fpword = 0;
4657 int i;
5f4273c7 4658
136da414
JB
4659 /* Our FP word must be 32 bits (single-precision FP). */
4660 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4661 {
4662 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4663 fpword |= words[i];
4664 }
5f4273c7 4665
c96612cc 4666 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4667 *immed = fpword;
4668 else
4669 return FAIL;
4670
4671 *ccp = str;
5f4273c7 4672
136da414
JB
4673 return SUCCESS;
4674 }
5f4273c7 4675
136da414
JB
4676 return FAIL;
4677}
4678
c19d1205
ZW
4679/* Shift operands. */
4680enum shift_kind
b99bd4ef 4681{
c19d1205
ZW
4682 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4683};
b99bd4ef 4684
c19d1205
ZW
4685struct asm_shift_name
4686{
4687 const char *name;
4688 enum shift_kind kind;
4689};
b99bd4ef 4690
c19d1205
ZW
4691/* Third argument to parse_shift. */
4692enum parse_shift_mode
4693{
4694 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4695 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4696 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4697 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4698 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4699};
b99bd4ef 4700
c19d1205
ZW
4701/* Parse a <shift> specifier on an ARM data processing instruction.
4702 This has three forms:
b99bd4ef 4703
c19d1205
ZW
4704 (LSL|LSR|ASL|ASR|ROR) Rs
4705 (LSL|LSR|ASL|ASR|ROR) #imm
4706 RRX
b99bd4ef 4707
c19d1205
ZW
4708 Note that ASL is assimilated to LSL in the instruction encoding, and
4709 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4710
c19d1205
ZW
4711static int
4712parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4713{
c19d1205
ZW
4714 const struct asm_shift_name *shift_name;
4715 enum shift_kind shift;
4716 char *s = *str;
4717 char *p = s;
4718 int reg;
b99bd4ef 4719
c19d1205
ZW
4720 for (p = *str; ISALPHA (*p); p++)
4721 ;
b99bd4ef 4722
c19d1205 4723 if (p == *str)
b99bd4ef 4724 {
c19d1205
ZW
4725 inst.error = _("shift expression expected");
4726 return FAIL;
b99bd4ef
NC
4727 }
4728
21d799b5
NC
4729 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4730 p - *str);
c19d1205
ZW
4731
4732 if (shift_name == NULL)
b99bd4ef 4733 {
c19d1205
ZW
4734 inst.error = _("shift expression expected");
4735 return FAIL;
b99bd4ef
NC
4736 }
4737
c19d1205 4738 shift = shift_name->kind;
b99bd4ef 4739
c19d1205
ZW
4740 switch (mode)
4741 {
4742 case NO_SHIFT_RESTRICT:
4743 case SHIFT_IMMEDIATE: break;
b99bd4ef 4744
c19d1205
ZW
4745 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4746 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4747 {
4748 inst.error = _("'LSL' or 'ASR' required");
4749 return FAIL;
4750 }
4751 break;
b99bd4ef 4752
c19d1205
ZW
4753 case SHIFT_LSL_IMMEDIATE:
4754 if (shift != SHIFT_LSL)
4755 {
4756 inst.error = _("'LSL' required");
4757 return FAIL;
4758 }
4759 break;
b99bd4ef 4760
c19d1205
ZW
4761 case SHIFT_ASR_IMMEDIATE:
4762 if (shift != SHIFT_ASR)
4763 {
4764 inst.error = _("'ASR' required");
4765 return FAIL;
4766 }
4767 break;
b99bd4ef 4768
c19d1205
ZW
4769 default: abort ();
4770 }
b99bd4ef 4771
c19d1205
ZW
4772 if (shift != SHIFT_RRX)
4773 {
4774 /* Whitespace can appear here if the next thing is a bare digit. */
4775 skip_whitespace (p);
b99bd4ef 4776
c19d1205 4777 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4778 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4779 {
4780 inst.operands[i].imm = reg;
4781 inst.operands[i].immisreg = 1;
4782 }
4783 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4784 return FAIL;
4785 }
4786 inst.operands[i].shift_kind = shift;
4787 inst.operands[i].shifted = 1;
4788 *str = p;
4789 return SUCCESS;
b99bd4ef
NC
4790}
4791
c19d1205 4792/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4793
c19d1205
ZW
4794 #<immediate>
4795 #<immediate>, <rotate>
4796 <Rm>
4797 <Rm>, <shift>
b99bd4ef 4798
c19d1205
ZW
4799 where <shift> is defined by parse_shift above, and <rotate> is a
4800 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4801 is deferred to md_apply_fix. */
b99bd4ef 4802
c19d1205
ZW
4803static int
4804parse_shifter_operand (char **str, int i)
4805{
4806 int value;
91d6fa6a 4807 expressionS exp;
b99bd4ef 4808
dcbf9037 4809 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4810 {
4811 inst.operands[i].reg = value;
4812 inst.operands[i].isreg = 1;
b99bd4ef 4813
c19d1205
ZW
4814 /* parse_shift will override this if appropriate */
4815 inst.reloc.exp.X_op = O_constant;
4816 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4817
c19d1205
ZW
4818 if (skip_past_comma (str) == FAIL)
4819 return SUCCESS;
b99bd4ef 4820
c19d1205
ZW
4821 /* Shift operation on register. */
4822 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4823 }
4824
c19d1205
ZW
4825 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4826 return FAIL;
b99bd4ef 4827
c19d1205 4828 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4829 {
c19d1205 4830 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 4831 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 4832 return FAIL;
b99bd4ef 4833
91d6fa6a 4834 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
4835 {
4836 inst.error = _("constant expression expected");
4837 return FAIL;
4838 }
b99bd4ef 4839
91d6fa6a 4840 value = exp.X_add_number;
c19d1205
ZW
4841 if (value < 0 || value > 30 || value % 2 != 0)
4842 {
4843 inst.error = _("invalid rotation");
4844 return FAIL;
4845 }
4846 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4847 {
4848 inst.error = _("invalid constant");
4849 return FAIL;
4850 }
09d92015 4851
55cf6793 4852 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4853 inst.reloc.exp.X_add_number
4854 = (((inst.reloc.exp.X_add_number << (32 - value))
4855 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4856 }
4857
c19d1205
ZW
4858 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4859 inst.reloc.pc_rel = 0;
4860 return SUCCESS;
09d92015
MM
4861}
4862
4962c51a
MS
4863/* Group relocation information. Each entry in the table contains the
4864 textual name of the relocation as may appear in assembler source
4865 and must end with a colon.
4866 Along with this textual name are the relocation codes to be used if
4867 the corresponding instruction is an ALU instruction (ADD or SUB only),
4868 an LDR, an LDRS, or an LDC. */
4869
4870struct group_reloc_table_entry
4871{
4872 const char *name;
4873 int alu_code;
4874 int ldr_code;
4875 int ldrs_code;
4876 int ldc_code;
4877};
4878
4879typedef enum
4880{
4881 /* Varieties of non-ALU group relocation. */
4882
4883 GROUP_LDR,
4884 GROUP_LDRS,
4885 GROUP_LDC
4886} group_reloc_type;
4887
4888static struct group_reloc_table_entry group_reloc_table[] =
4889 { /* Program counter relative: */
4890 { "pc_g0_nc",
4891 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4892 0, /* LDR */
4893 0, /* LDRS */
4894 0 }, /* LDC */
4895 { "pc_g0",
4896 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4897 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4898 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4899 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4900 { "pc_g1_nc",
4901 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4902 0, /* LDR */
4903 0, /* LDRS */
4904 0 }, /* LDC */
4905 { "pc_g1",
4906 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4907 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4908 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4909 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4910 { "pc_g2",
4911 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4912 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4913 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4914 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4915 /* Section base relative */
4916 { "sb_g0_nc",
4917 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4918 0, /* LDR */
4919 0, /* LDRS */
4920 0 }, /* LDC */
4921 { "sb_g0",
4922 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4923 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4924 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4925 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4926 { "sb_g1_nc",
4927 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4928 0, /* LDR */
4929 0, /* LDRS */
4930 0 }, /* LDC */
4931 { "sb_g1",
4932 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4933 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4934 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4935 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4936 { "sb_g2",
4937 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4938 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4939 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4940 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4941
4942/* Given the address of a pointer pointing to the textual name of a group
4943 relocation as may appear in assembler source, attempt to find its details
4944 in group_reloc_table. The pointer will be updated to the character after
4945 the trailing colon. On failure, FAIL will be returned; SUCCESS
4946 otherwise. On success, *entry will be updated to point at the relevant
4947 group_reloc_table entry. */
4948
4949static int
4950find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4951{
4952 unsigned int i;
4953 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4954 {
4955 int length = strlen (group_reloc_table[i].name);
4956
5f4273c7
NC
4957 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4958 && (*str)[length] == ':')
4962c51a
MS
4959 {
4960 *out = &group_reloc_table[i];
4961 *str += (length + 1);
4962 return SUCCESS;
4963 }
4964 }
4965
4966 return FAIL;
4967}
4968
4969/* Parse a <shifter_operand> for an ARM data processing instruction
4970 (as for parse_shifter_operand) where group relocations are allowed:
4971
4972 #<immediate>
4973 #<immediate>, <rotate>
4974 #:<group_reloc>:<expression>
4975 <Rm>
4976 <Rm>, <shift>
4977
4978 where <group_reloc> is one of the strings defined in group_reloc_table.
4979 The hashes are optional.
4980
4981 Everything else is as for parse_shifter_operand. */
4982
4983static parse_operand_result
4984parse_shifter_operand_group_reloc (char **str, int i)
4985{
4986 /* Determine if we have the sequence of characters #: or just :
4987 coming next. If we do, then we check for a group relocation.
4988 If we don't, punt the whole lot to parse_shifter_operand. */
4989
4990 if (((*str)[0] == '#' && (*str)[1] == ':')
4991 || (*str)[0] == ':')
4992 {
4993 struct group_reloc_table_entry *entry;
4994
4995 if ((*str)[0] == '#')
4996 (*str) += 2;
4997 else
4998 (*str)++;
4999
5000 /* Try to parse a group relocation. Anything else is an error. */
5001 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5002 {
5003 inst.error = _("unknown group relocation");
5004 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5005 }
5006
5007 /* We now have the group relocation table entry corresponding to
5008 the name in the assembler source. Next, we parse the expression. */
5009 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
5010 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5011
5012 /* Record the relocation type (always the ALU variant here). */
21d799b5 5013 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5014 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5015
5016 return PARSE_OPERAND_SUCCESS;
5017 }
5018 else
5019 return parse_shifter_operand (str, i) == SUCCESS
5020 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5021
5022 /* Never reached. */
5023}
5024
8e560766
MGD
5025/* Parse a Neon alignment expression. Information is written to
5026 inst.operands[i]. We assume the initial ':' has been skipped.
5027
5028 align .imm = align << 8, .immisalign=1, .preind=0 */
5029static parse_operand_result
5030parse_neon_alignment (char **str, int i)
5031{
5032 char *p = *str;
5033 expressionS exp;
5034
5035 my_get_expression (&exp, &p, GE_NO_PREFIX);
5036
5037 if (exp.X_op != O_constant)
5038 {
5039 inst.error = _("alignment must be constant");
5040 return PARSE_OPERAND_FAIL;
5041 }
5042
5043 inst.operands[i].imm = exp.X_add_number << 8;
5044 inst.operands[i].immisalign = 1;
5045 /* Alignments are not pre-indexes. */
5046 inst.operands[i].preind = 0;
5047
5048 *str = p;
5049 return PARSE_OPERAND_SUCCESS;
5050}
5051
c19d1205
ZW
5052/* Parse all forms of an ARM address expression. Information is written
5053 to inst.operands[i] and/or inst.reloc.
09d92015 5054
c19d1205 5055 Preindexed addressing (.preind=1):
09d92015 5056
c19d1205
ZW
5057 [Rn, #offset] .reg=Rn .reloc.exp=offset
5058 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5059 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5060 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5061
c19d1205 5062 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5063
c19d1205 5064 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5065
c19d1205
ZW
5066 [Rn], #offset .reg=Rn .reloc.exp=offset
5067 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5068 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5069 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5070
c19d1205 5071 Unindexed addressing (.preind=0, .postind=0):
09d92015 5072
c19d1205 5073 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5074
c19d1205 5075 Other:
09d92015 5076
c19d1205
ZW
5077 [Rn]{!} shorthand for [Rn,#0]{!}
5078 =immediate .isreg=0 .reloc.exp=immediate
5079 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5080
c19d1205
ZW
5081 It is the caller's responsibility to check for addressing modes not
5082 supported by the instruction, and to set inst.reloc.type. */
5083
4962c51a
MS
5084static parse_operand_result
5085parse_address_main (char **str, int i, int group_relocations,
5086 group_reloc_type group_type)
09d92015 5087{
c19d1205
ZW
5088 char *p = *str;
5089 int reg;
09d92015 5090
c19d1205 5091 if (skip_past_char (&p, '[') == FAIL)
09d92015 5092 {
c19d1205
ZW
5093 if (skip_past_char (&p, '=') == FAIL)
5094 {
974da60d 5095 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5096 inst.reloc.pc_rel = 1;
5097 inst.operands[i].reg = REG_PC;
5098 inst.operands[i].isreg = 1;
5099 inst.operands[i].preind = 1;
5100 }
974da60d 5101 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
09d92015 5102
c19d1205 5103 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 5104 return PARSE_OPERAND_FAIL;
09d92015 5105
c19d1205 5106 *str = p;
4962c51a 5107 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5108 }
5109
dcbf9037 5110 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5111 {
c19d1205 5112 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5113 return PARSE_OPERAND_FAIL;
09d92015 5114 }
c19d1205
ZW
5115 inst.operands[i].reg = reg;
5116 inst.operands[i].isreg = 1;
09d92015 5117
c19d1205 5118 if (skip_past_comma (&p) == SUCCESS)
09d92015 5119 {
c19d1205 5120 inst.operands[i].preind = 1;
09d92015 5121
c19d1205
ZW
5122 if (*p == '+') p++;
5123 else if (*p == '-') p++, inst.operands[i].negative = 1;
5124
dcbf9037 5125 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5126 {
c19d1205
ZW
5127 inst.operands[i].imm = reg;
5128 inst.operands[i].immisreg = 1;
5129
5130 if (skip_past_comma (&p) == SUCCESS)
5131 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5132 return PARSE_OPERAND_FAIL;
c19d1205 5133 }
5287ad62 5134 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5135 {
5136 /* FIXME: '@' should be used here, but it's filtered out by generic
5137 code before we get to see it here. This may be subject to
5138 change. */
5139 parse_operand_result result = parse_neon_alignment (&p, i);
5140
5141 if (result != PARSE_OPERAND_SUCCESS)
5142 return result;
5143 }
c19d1205
ZW
5144 else
5145 {
5146 if (inst.operands[i].negative)
5147 {
5148 inst.operands[i].negative = 0;
5149 p--;
5150 }
4962c51a 5151
5f4273c7
NC
5152 if (group_relocations
5153 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5154 {
5155 struct group_reloc_table_entry *entry;
5156
5157 /* Skip over the #: or : sequence. */
5158 if (*p == '#')
5159 p += 2;
5160 else
5161 p++;
5162
5163 /* Try to parse a group relocation. Anything else is an
5164 error. */
5165 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5166 {
5167 inst.error = _("unknown group relocation");
5168 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5169 }
5170
5171 /* We now have the group relocation table entry corresponding to
5172 the name in the assembler source. Next, we parse the
5173 expression. */
5174 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5175 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5176
5177 /* Record the relocation type. */
5178 switch (group_type)
5179 {
5180 case GROUP_LDR:
21d799b5 5181 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
4962c51a
MS
5182 break;
5183
5184 case GROUP_LDRS:
21d799b5 5185 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
4962c51a
MS
5186 break;
5187
5188 case GROUP_LDC:
21d799b5 5189 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
4962c51a
MS
5190 break;
5191
5192 default:
9c2799c2 5193 gas_assert (0);
4962c51a
MS
5194 }
5195
5196 if (inst.reloc.type == 0)
5197 {
5198 inst.error = _("this group relocation is not allowed on this instruction");
5199 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5200 }
5201 }
5202 else
26d97720
NS
5203 {
5204 char *q = p;
5205 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5206 return PARSE_OPERAND_FAIL;
5207 /* If the offset is 0, find out if it's a +0 or -0. */
5208 if (inst.reloc.exp.X_op == O_constant
5209 && inst.reloc.exp.X_add_number == 0)
5210 {
5211 skip_whitespace (q);
5212 if (*q == '#')
5213 {
5214 q++;
5215 skip_whitespace (q);
5216 }
5217 if (*q == '-')
5218 inst.operands[i].negative = 1;
5219 }
5220 }
09d92015
MM
5221 }
5222 }
8e560766
MGD
5223 else if (skip_past_char (&p, ':') == SUCCESS)
5224 {
5225 /* FIXME: '@' should be used here, but it's filtered out by generic code
5226 before we get to see it here. This may be subject to change. */
5227 parse_operand_result result = parse_neon_alignment (&p, i);
5228
5229 if (result != PARSE_OPERAND_SUCCESS)
5230 return result;
5231 }
09d92015 5232
c19d1205 5233 if (skip_past_char (&p, ']') == FAIL)
09d92015 5234 {
c19d1205 5235 inst.error = _("']' expected");
4962c51a 5236 return PARSE_OPERAND_FAIL;
09d92015
MM
5237 }
5238
c19d1205
ZW
5239 if (skip_past_char (&p, '!') == SUCCESS)
5240 inst.operands[i].writeback = 1;
09d92015 5241
c19d1205 5242 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5243 {
c19d1205
ZW
5244 if (skip_past_char (&p, '{') == SUCCESS)
5245 {
5246 /* [Rn], {expr} - unindexed, with option */
5247 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5248 0, 255, TRUE) == FAIL)
4962c51a 5249 return PARSE_OPERAND_FAIL;
09d92015 5250
c19d1205
ZW
5251 if (skip_past_char (&p, '}') == FAIL)
5252 {
5253 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5254 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5255 }
5256 if (inst.operands[i].preind)
5257 {
5258 inst.error = _("cannot combine index with option");
4962c51a 5259 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5260 }
5261 *str = p;
4962c51a 5262 return PARSE_OPERAND_SUCCESS;
09d92015 5263 }
c19d1205
ZW
5264 else
5265 {
5266 inst.operands[i].postind = 1;
5267 inst.operands[i].writeback = 1;
09d92015 5268
c19d1205
ZW
5269 if (inst.operands[i].preind)
5270 {
5271 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5272 return PARSE_OPERAND_FAIL;
c19d1205 5273 }
09d92015 5274
c19d1205
ZW
5275 if (*p == '+') p++;
5276 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5277
dcbf9037 5278 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5279 {
5287ad62
JB
5280 /* We might be using the immediate for alignment already. If we
5281 are, OR the register number into the low-order bits. */
5282 if (inst.operands[i].immisalign)
5283 inst.operands[i].imm |= reg;
5284 else
5285 inst.operands[i].imm = reg;
c19d1205 5286 inst.operands[i].immisreg = 1;
a737bd4d 5287
c19d1205
ZW
5288 if (skip_past_comma (&p) == SUCCESS)
5289 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5290 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5291 }
5292 else
5293 {
26d97720 5294 char *q = p;
c19d1205
ZW
5295 if (inst.operands[i].negative)
5296 {
5297 inst.operands[i].negative = 0;
5298 p--;
5299 }
5300 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5301 return PARSE_OPERAND_FAIL;
26d97720
NS
5302 /* If the offset is 0, find out if it's a +0 or -0. */
5303 if (inst.reloc.exp.X_op == O_constant
5304 && inst.reloc.exp.X_add_number == 0)
5305 {
5306 skip_whitespace (q);
5307 if (*q == '#')
5308 {
5309 q++;
5310 skip_whitespace (q);
5311 }
5312 if (*q == '-')
5313 inst.operands[i].negative = 1;
5314 }
c19d1205
ZW
5315 }
5316 }
a737bd4d
NC
5317 }
5318
c19d1205
ZW
5319 /* If at this point neither .preind nor .postind is set, we have a
5320 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5321 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5322 {
5323 inst.operands[i].preind = 1;
5324 inst.reloc.exp.X_op = O_constant;
5325 inst.reloc.exp.X_add_number = 0;
5326 }
5327 *str = p;
4962c51a
MS
5328 return PARSE_OPERAND_SUCCESS;
5329}
5330
5331static int
5332parse_address (char **str, int i)
5333{
21d799b5 5334 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
4962c51a
MS
5335 ? SUCCESS : FAIL;
5336}
5337
5338static parse_operand_result
5339parse_address_group_reloc (char **str, int i, group_reloc_type type)
5340{
5341 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5342}
5343
b6895b4f
PB
5344/* Parse an operand for a MOVW or MOVT instruction. */
5345static int
5346parse_half (char **str)
5347{
5348 char * p;
5f4273c7 5349
b6895b4f
PB
5350 p = *str;
5351 skip_past_char (&p, '#');
5f4273c7 5352 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5353 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5354 else if (strncasecmp (p, ":upper16:", 9) == 0)
5355 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5356
5357 if (inst.reloc.type != BFD_RELOC_UNUSED)
5358 {
5359 p += 9;
5f4273c7 5360 skip_whitespace (p);
b6895b4f
PB
5361 }
5362
5363 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5364 return FAIL;
5365
5366 if (inst.reloc.type == BFD_RELOC_UNUSED)
5367 {
5368 if (inst.reloc.exp.X_op != O_constant)
5369 {
5370 inst.error = _("constant expression expected");
5371 return FAIL;
5372 }
5373 if (inst.reloc.exp.X_add_number < 0
5374 || inst.reloc.exp.X_add_number > 0xffff)
5375 {
5376 inst.error = _("immediate value out of range");
5377 return FAIL;
5378 }
5379 }
5380 *str = p;
5381 return SUCCESS;
5382}
5383
c19d1205 5384/* Miscellaneous. */
a737bd4d 5385
c19d1205
ZW
5386/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5387 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5388static int
d2cd1205 5389parse_psr (char **str, bfd_boolean lhs)
09d92015 5390{
c19d1205
ZW
5391 char *p;
5392 unsigned long psr_field;
62b3e311
PB
5393 const struct asm_psr *psr;
5394 char *start;
d2cd1205 5395 bfd_boolean is_apsr = FALSE;
ac7f631b 5396 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5397
a4482bb6
NC
5398 /* PR gas/12698: If the user has specified -march=all then m_profile will
5399 be TRUE, but we want to ignore it in this case as we are building for any
5400 CPU type, including non-m variants. */
5401 if (selected_cpu.core == arm_arch_any.core)
5402 m_profile = FALSE;
5403
c19d1205
ZW
5404 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5405 feature for ease of use and backwards compatibility. */
5406 p = *str;
62b3e311 5407 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5408 {
5409 if (m_profile)
5410 goto unsupported_psr;
5411
5412 psr_field = SPSR_BIT;
5413 }
5414 else if (strncasecmp (p, "CPSR", 4) == 0)
5415 {
5416 if (m_profile)
5417 goto unsupported_psr;
5418
5419 psr_field = 0;
5420 }
5421 else if (strncasecmp (p, "APSR", 4) == 0)
5422 {
5423 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5424 and ARMv7-R architecture CPUs. */
5425 is_apsr = TRUE;
5426 psr_field = 0;
5427 }
5428 else if (m_profile)
62b3e311
PB
5429 {
5430 start = p;
5431 do
5432 p++;
5433 while (ISALNUM (*p) || *p == '_');
5434
d2cd1205
JB
5435 if (strncasecmp (start, "iapsr", 5) == 0
5436 || strncasecmp (start, "eapsr", 5) == 0
5437 || strncasecmp (start, "xpsr", 4) == 0
5438 || strncasecmp (start, "psr", 3) == 0)
5439 p = start + strcspn (start, "rR") + 1;
5440
21d799b5
NC
5441 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5442 p - start);
d2cd1205 5443
62b3e311
PB
5444 if (!psr)
5445 return FAIL;
09d92015 5446
d2cd1205
JB
5447 /* If APSR is being written, a bitfield may be specified. Note that
5448 APSR itself is handled above. */
5449 if (psr->field <= 3)
5450 {
5451 psr_field = psr->field;
5452 is_apsr = TRUE;
5453 goto check_suffix;
5454 }
5455
62b3e311 5456 *str = p;
d2cd1205
JB
5457 /* M-profile MSR instructions have the mask field set to "10", except
5458 *PSR variants which modify APSR, which may use a different mask (and
5459 have been handled already). Do that by setting the PSR_f field
5460 here. */
5461 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5462 }
d2cd1205
JB
5463 else
5464 goto unsupported_psr;
09d92015 5465
62b3e311 5466 p += 4;
d2cd1205 5467check_suffix:
c19d1205
ZW
5468 if (*p == '_')
5469 {
5470 /* A suffix follows. */
c19d1205
ZW
5471 p++;
5472 start = p;
a737bd4d 5473
c19d1205
ZW
5474 do
5475 p++;
5476 while (ISALNUM (*p) || *p == '_');
a737bd4d 5477
d2cd1205
JB
5478 if (is_apsr)
5479 {
5480 /* APSR uses a notation for bits, rather than fields. */
5481 unsigned int nzcvq_bits = 0;
5482 unsigned int g_bit = 0;
5483 char *bit;
5484
5485 for (bit = start; bit != p; bit++)
5486 {
5487 switch (TOLOWER (*bit))
5488 {
5489 case 'n':
5490 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5491 break;
5492
5493 case 'z':
5494 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5495 break;
5496
5497 case 'c':
5498 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5499 break;
5500
5501 case 'v':
5502 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5503 break;
5504
5505 case 'q':
5506 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5507 break;
5508
5509 case 'g':
5510 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5511 break;
5512
5513 default:
5514 inst.error = _("unexpected bit specified after APSR");
5515 return FAIL;
5516 }
5517 }
5518
5519 if (nzcvq_bits == 0x1f)
5520 psr_field |= PSR_f;
5521
5522 if (g_bit == 0x1)
5523 {
5524 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
5525 {
5526 inst.error = _("selected processor does not "
5527 "support DSP extension");
5528 return FAIL;
5529 }
5530
5531 psr_field |= PSR_s;
5532 }
5533
5534 if ((nzcvq_bits & 0x20) != 0
5535 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5536 || (g_bit & 0x2) != 0)
5537 {
5538 inst.error = _("bad bitmask specified after APSR");
5539 return FAIL;
5540 }
5541 }
5542 else
5543 {
5544 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5545 p - start);
5546 if (!psr)
5547 goto error;
a737bd4d 5548
d2cd1205
JB
5549 psr_field |= psr->field;
5550 }
a737bd4d 5551 }
c19d1205 5552 else
a737bd4d 5553 {
c19d1205
ZW
5554 if (ISALNUM (*p))
5555 goto error; /* Garbage after "[CS]PSR". */
5556
d2cd1205
JB
5557 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
5558 is deprecated, but allow it anyway. */
5559 if (is_apsr && lhs)
5560 {
5561 psr_field |= PSR_f;
5562 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5563 "deprecated"));
5564 }
5565 else if (!m_profile)
5566 /* These bits are never right for M-profile devices: don't set them
5567 (only code paths which read/write APSR reach here). */
5568 psr_field |= (PSR_c | PSR_f);
a737bd4d 5569 }
c19d1205
ZW
5570 *str = p;
5571 return psr_field;
a737bd4d 5572
d2cd1205
JB
5573 unsupported_psr:
5574 inst.error = _("selected processor does not support requested special "
5575 "purpose register");
5576 return FAIL;
5577
c19d1205
ZW
5578 error:
5579 inst.error = _("flag for {c}psr instruction expected");
5580 return FAIL;
a737bd4d
NC
5581}
5582
c19d1205
ZW
5583/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5584 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5585
c19d1205
ZW
5586static int
5587parse_cps_flags (char **str)
a737bd4d 5588{
c19d1205
ZW
5589 int val = 0;
5590 int saw_a_flag = 0;
5591 char *s = *str;
a737bd4d 5592
c19d1205
ZW
5593 for (;;)
5594 switch (*s++)
5595 {
5596 case '\0': case ',':
5597 goto done;
a737bd4d 5598
c19d1205
ZW
5599 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5600 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5601 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5602
c19d1205
ZW
5603 default:
5604 inst.error = _("unrecognized CPS flag");
5605 return FAIL;
5606 }
a737bd4d 5607
c19d1205
ZW
5608 done:
5609 if (saw_a_flag == 0)
a737bd4d 5610 {
c19d1205
ZW
5611 inst.error = _("missing CPS flags");
5612 return FAIL;
a737bd4d 5613 }
a737bd4d 5614
c19d1205
ZW
5615 *str = s - 1;
5616 return val;
a737bd4d
NC
5617}
5618
c19d1205
ZW
5619/* Parse an endian specifier ("BE" or "LE", case insensitive);
5620 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5621
5622static int
c19d1205 5623parse_endian_specifier (char **str)
a737bd4d 5624{
c19d1205
ZW
5625 int little_endian;
5626 char *s = *str;
a737bd4d 5627
c19d1205
ZW
5628 if (strncasecmp (s, "BE", 2))
5629 little_endian = 0;
5630 else if (strncasecmp (s, "LE", 2))
5631 little_endian = 1;
5632 else
a737bd4d 5633 {
c19d1205 5634 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5635 return FAIL;
5636 }
5637
c19d1205 5638 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5639 {
c19d1205 5640 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5641 return FAIL;
5642 }
5643
c19d1205
ZW
5644 *str = s + 2;
5645 return little_endian;
5646}
a737bd4d 5647
c19d1205
ZW
5648/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5649 value suitable for poking into the rotate field of an sxt or sxta
5650 instruction, or FAIL on error. */
5651
5652static int
5653parse_ror (char **str)
5654{
5655 int rot;
5656 char *s = *str;
5657
5658 if (strncasecmp (s, "ROR", 3) == 0)
5659 s += 3;
5660 else
a737bd4d 5661 {
c19d1205 5662 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5663 return FAIL;
5664 }
c19d1205
ZW
5665
5666 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5667 return FAIL;
5668
5669 switch (rot)
a737bd4d 5670 {
c19d1205
ZW
5671 case 0: *str = s; return 0x0;
5672 case 8: *str = s; return 0x1;
5673 case 16: *str = s; return 0x2;
5674 case 24: *str = s; return 0x3;
5675
5676 default:
5677 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5678 return FAIL;
5679 }
c19d1205 5680}
a737bd4d 5681
c19d1205
ZW
5682/* Parse a conditional code (from conds[] below). The value returned is in the
5683 range 0 .. 14, or FAIL. */
5684static int
5685parse_cond (char **str)
5686{
c462b453 5687 char *q;
c19d1205 5688 const struct asm_cond *c;
c462b453
PB
5689 int n;
5690 /* Condition codes are always 2 characters, so matching up to
5691 3 characters is sufficient. */
5692 char cond[3];
a737bd4d 5693
c462b453
PB
5694 q = *str;
5695 n = 0;
5696 while (ISALPHA (*q) && n < 3)
5697 {
e07e6e58 5698 cond[n] = TOLOWER (*q);
c462b453
PB
5699 q++;
5700 n++;
5701 }
a737bd4d 5702
21d799b5 5703 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5704 if (!c)
a737bd4d 5705 {
c19d1205 5706 inst.error = _("condition required");
a737bd4d
NC
5707 return FAIL;
5708 }
5709
c19d1205
ZW
5710 *str = q;
5711 return c->value;
5712}
5713
62b3e311
PB
5714/* Parse an option for a barrier instruction. Returns the encoding for the
5715 option, or FAIL. */
5716static int
5717parse_barrier (char **str)
5718{
5719 char *p, *q;
5720 const struct asm_barrier_opt *o;
5721
5722 p = q = *str;
5723 while (ISALPHA (*q))
5724 q++;
5725
21d799b5
NC
5726 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5727 q - p);
62b3e311
PB
5728 if (!o)
5729 return FAIL;
5730
5731 *str = q;
5732 return o->value;
5733}
5734
92e90b6e
PB
5735/* Parse the operands of a table branch instruction. Similar to a memory
5736 operand. */
5737static int
5738parse_tb (char **str)
5739{
5740 char * p = *str;
5741 int reg;
5742
5743 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5744 {
5745 inst.error = _("'[' expected");
5746 return FAIL;
5747 }
92e90b6e 5748
dcbf9037 5749 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5750 {
5751 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5752 return FAIL;
5753 }
5754 inst.operands[0].reg = reg;
5755
5756 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5757 {
5758 inst.error = _("',' expected");
5759 return FAIL;
5760 }
5f4273c7 5761
dcbf9037 5762 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5763 {
5764 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5765 return FAIL;
5766 }
5767 inst.operands[0].imm = reg;
5768
5769 if (skip_past_comma (&p) == SUCCESS)
5770 {
5771 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5772 return FAIL;
5773 if (inst.reloc.exp.X_add_number != 1)
5774 {
5775 inst.error = _("invalid shift");
5776 return FAIL;
5777 }
5778 inst.operands[0].shifted = 1;
5779 }
5780
5781 if (skip_past_char (&p, ']') == FAIL)
5782 {
5783 inst.error = _("']' expected");
5784 return FAIL;
5785 }
5786 *str = p;
5787 return SUCCESS;
5788}
5789
5287ad62
JB
5790/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5791 information on the types the operands can take and how they are encoded.
037e8744
JB
5792 Up to four operands may be read; this function handles setting the
5793 ".present" field for each read operand itself.
5287ad62
JB
5794 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5795 else returns FAIL. */
5796
5797static int
5798parse_neon_mov (char **str, int *which_operand)
5799{
5800 int i = *which_operand, val;
5801 enum arm_reg_type rtype;
5802 char *ptr = *str;
dcbf9037 5803 struct neon_type_el optype;
5f4273c7 5804
dcbf9037 5805 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5806 {
5807 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5808 inst.operands[i].reg = val;
5809 inst.operands[i].isscalar = 1;
dcbf9037 5810 inst.operands[i].vectype = optype;
5287ad62
JB
5811 inst.operands[i++].present = 1;
5812
5813 if (skip_past_comma (&ptr) == FAIL)
5814 goto wanted_comma;
5f4273c7 5815
dcbf9037 5816 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5817 goto wanted_arm;
5f4273c7 5818
5287ad62
JB
5819 inst.operands[i].reg = val;
5820 inst.operands[i].isreg = 1;
5821 inst.operands[i].present = 1;
5822 }
037e8744 5823 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5824 != FAIL)
5287ad62
JB
5825 {
5826 /* Cases 0, 1, 2, 3, 5 (D only). */
5827 if (skip_past_comma (&ptr) == FAIL)
5828 goto wanted_comma;
5f4273c7 5829
5287ad62
JB
5830 inst.operands[i].reg = val;
5831 inst.operands[i].isreg = 1;
5832 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5833 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5834 inst.operands[i].isvec = 1;
dcbf9037 5835 inst.operands[i].vectype = optype;
5287ad62
JB
5836 inst.operands[i++].present = 1;
5837
dcbf9037 5838 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5839 {
037e8744
JB
5840 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5841 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5842 inst.operands[i].reg = val;
5843 inst.operands[i].isreg = 1;
037e8744 5844 inst.operands[i].present = 1;
5287ad62
JB
5845
5846 if (rtype == REG_TYPE_NQ)
5847 {
dcbf9037 5848 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5849 return FAIL;
5850 }
037e8744
JB
5851 else if (rtype != REG_TYPE_VFS)
5852 {
5853 i++;
5854 if (skip_past_comma (&ptr) == FAIL)
5855 goto wanted_comma;
5856 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5857 goto wanted_arm;
5858 inst.operands[i].reg = val;
5859 inst.operands[i].isreg = 1;
5860 inst.operands[i].present = 1;
5861 }
5287ad62 5862 }
037e8744
JB
5863 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5864 &optype)) != FAIL)
5287ad62
JB
5865 {
5866 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5867 Case 1: VMOV<c><q> <Dd>, <Dm>
5868 Case 8: VMOV.F32 <Sd>, <Sm>
5869 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5870
5871 inst.operands[i].reg = val;
5872 inst.operands[i].isreg = 1;
5873 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5874 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5875 inst.operands[i].isvec = 1;
dcbf9037 5876 inst.operands[i].vectype = optype;
5287ad62 5877 inst.operands[i].present = 1;
5f4273c7 5878
037e8744
JB
5879 if (skip_past_comma (&ptr) == SUCCESS)
5880 {
5881 /* Case 15. */
5882 i++;
5883
5884 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5885 goto wanted_arm;
5886
5887 inst.operands[i].reg = val;
5888 inst.operands[i].isreg = 1;
5889 inst.operands[i++].present = 1;
5f4273c7 5890
037e8744
JB
5891 if (skip_past_comma (&ptr) == FAIL)
5892 goto wanted_comma;
5f4273c7 5893
037e8744
JB
5894 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5895 goto wanted_arm;
5f4273c7 5896
037e8744
JB
5897 inst.operands[i].reg = val;
5898 inst.operands[i].isreg = 1;
5899 inst.operands[i++].present = 1;
5900 }
5287ad62 5901 }
4641781c
PB
5902 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5903 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5904 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5905 Case 10: VMOV.F32 <Sd>, #<imm>
5906 Case 11: VMOV.F64 <Dd>, #<imm> */
5907 inst.operands[i].immisfloat = 1;
5908 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5909 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5910 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5911 ;
5287ad62
JB
5912 else
5913 {
dcbf9037 5914 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5915 return FAIL;
5916 }
5917 }
dcbf9037 5918 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5919 {
5920 /* Cases 6, 7. */
5921 inst.operands[i].reg = val;
5922 inst.operands[i].isreg = 1;
5923 inst.operands[i++].present = 1;
5f4273c7 5924
5287ad62
JB
5925 if (skip_past_comma (&ptr) == FAIL)
5926 goto wanted_comma;
5f4273c7 5927
dcbf9037 5928 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5929 {
5930 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5931 inst.operands[i].reg = val;
5932 inst.operands[i].isscalar = 1;
5933 inst.operands[i].present = 1;
dcbf9037 5934 inst.operands[i].vectype = optype;
5287ad62 5935 }
dcbf9037 5936 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5937 {
5938 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5939 inst.operands[i].reg = val;
5940 inst.operands[i].isreg = 1;
5941 inst.operands[i++].present = 1;
5f4273c7 5942
5287ad62
JB
5943 if (skip_past_comma (&ptr) == FAIL)
5944 goto wanted_comma;
5f4273c7 5945
037e8744 5946 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5947 == FAIL)
5287ad62 5948 {
037e8744 5949 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5950 return FAIL;
5951 }
5952
5953 inst.operands[i].reg = val;
5954 inst.operands[i].isreg = 1;
037e8744
JB
5955 inst.operands[i].isvec = 1;
5956 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5957 inst.operands[i].vectype = optype;
5287ad62 5958 inst.operands[i].present = 1;
5f4273c7 5959
037e8744
JB
5960 if (rtype == REG_TYPE_VFS)
5961 {
5962 /* Case 14. */
5963 i++;
5964 if (skip_past_comma (&ptr) == FAIL)
5965 goto wanted_comma;
5966 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5967 &optype)) == FAIL)
5968 {
5969 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5970 return FAIL;
5971 }
5972 inst.operands[i].reg = val;
5973 inst.operands[i].isreg = 1;
5974 inst.operands[i].isvec = 1;
5975 inst.operands[i].issingle = 1;
5976 inst.operands[i].vectype = optype;
5977 inst.operands[i].present = 1;
5978 }
5979 }
5980 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5981 != FAIL)
5982 {
5983 /* Case 13. */
5984 inst.operands[i].reg = val;
5985 inst.operands[i].isreg = 1;
5986 inst.operands[i].isvec = 1;
5987 inst.operands[i].issingle = 1;
5988 inst.operands[i].vectype = optype;
5989 inst.operands[i++].present = 1;
5287ad62
JB
5990 }
5991 }
5992 else
5993 {
dcbf9037 5994 first_error (_("parse error"));
5287ad62
JB
5995 return FAIL;
5996 }
5997
5998 /* Successfully parsed the operands. Update args. */
5999 *which_operand = i;
6000 *str = ptr;
6001 return SUCCESS;
6002
5f4273c7 6003 wanted_comma:
dcbf9037 6004 first_error (_("expected comma"));
5287ad62 6005 return FAIL;
5f4273c7
NC
6006
6007 wanted_arm:
dcbf9037 6008 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6009 return FAIL;
5287ad62
JB
6010}
6011
5be8be5d
DG
6012/* Use this macro when the operand constraints are different
6013 for ARM and THUMB (e.g. ldrd). */
6014#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6015 ((arm_operand) | ((thumb_operand) << 16))
6016
c19d1205
ZW
6017/* Matcher codes for parse_operands. */
6018enum operand_parse_code
6019{
6020 OP_stop, /* end of line */
6021
6022 OP_RR, /* ARM register */
6023 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6024 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6025 OP_RRnpcb, /* ARM register, not r15, in square brackets */
55881a11
MGD
6026 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
6027 optional trailing ! */
c19d1205
ZW
6028 OP_RRw, /* ARM register, not r15, optional trailing ! */
6029 OP_RCP, /* Coprocessor number */
6030 OP_RCN, /* Coprocessor register */
6031 OP_RF, /* FPA register */
6032 OP_RVS, /* VFP single precision register */
5287ad62
JB
6033 OP_RVD, /* VFP double precision register (0..15) */
6034 OP_RND, /* Neon double precision register (0..31) */
6035 OP_RNQ, /* Neon quad precision register */
037e8744 6036 OP_RVSD, /* VFP single or double precision register */
5287ad62 6037 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6038 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6039 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6040 OP_RVC, /* VFP control register */
6041 OP_RMF, /* Maverick F register */
6042 OP_RMD, /* Maverick D register */
6043 OP_RMFX, /* Maverick FX register */
6044 OP_RMDX, /* Maverick DX register */
6045 OP_RMAX, /* Maverick AX register */
6046 OP_RMDS, /* Maverick DSPSC register */
6047 OP_RIWR, /* iWMMXt wR register */
6048 OP_RIWC, /* iWMMXt wC register */
6049 OP_RIWG, /* iWMMXt wCG register */
6050 OP_RXA, /* XScale accumulator register */
6051
6052 OP_REGLST, /* ARM register list */
6053 OP_VRSLST, /* VFP single-precision register list */
6054 OP_VRDLST, /* VFP double-precision register list */
037e8744 6055 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6056 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6057 OP_NSTRLST, /* Neon element/structure list */
6058
5287ad62 6059 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6060 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 6061 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6062 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6063 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6064 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6065 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6066 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6067 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6068 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6069
6070 OP_I0, /* immediate zero */
c19d1205
ZW
6071 OP_I7, /* immediate value 0 .. 7 */
6072 OP_I15, /* 0 .. 15 */
6073 OP_I16, /* 1 .. 16 */
5287ad62 6074 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6075 OP_I31, /* 0 .. 31 */
6076 OP_I31w, /* 0 .. 31, optional trailing ! */
6077 OP_I32, /* 1 .. 32 */
5287ad62
JB
6078 OP_I32z, /* 0 .. 32 */
6079 OP_I63, /* 0 .. 63 */
c19d1205 6080 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6081 OP_I64, /* 1 .. 64 */
6082 OP_I64z, /* 0 .. 64 */
c19d1205 6083 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6084
6085 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6086 OP_I7b, /* 0 .. 7 */
6087 OP_I15b, /* 0 .. 15 */
6088 OP_I31b, /* 0 .. 31 */
6089
6090 OP_SH, /* shifter operand */
4962c51a 6091 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6092 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6093 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6094 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6095 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6096 OP_EXP, /* arbitrary expression */
6097 OP_EXPi, /* same, with optional immediate prefix */
6098 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6099 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6100
6101 OP_CPSF, /* CPS flags */
6102 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6103 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6104 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6105 OP_COND, /* conditional code */
92e90b6e 6106 OP_TB, /* Table branch. */
c19d1205 6107
037e8744
JB
6108 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6109
c19d1205
ZW
6110 OP_RRnpc_I0, /* ARM register or literal 0 */
6111 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6112 OP_RR_EXi, /* ARM register or expression with imm prefix */
6113 OP_RF_IF, /* FPA register or immediate */
6114 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6115 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6116
6117 /* Optional operands. */
6118 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6119 OP_oI31b, /* 0 .. 31 */
5287ad62 6120 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
6121 OP_oIffffb, /* 0 .. 65535 */
6122 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6123
6124 OP_oRR, /* ARM register */
6125 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6126 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6127 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6128 OP_oRND, /* Optional Neon double precision register */
6129 OP_oRNQ, /* Optional Neon quad precision register */
6130 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6131 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6132 OP_oSHll, /* LSL immediate */
6133 OP_oSHar, /* ASR immediate */
6134 OP_oSHllar, /* LSL or ASR immediate */
6135 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6136 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6137
5be8be5d
DG
6138 /* Some pre-defined mixed (ARM/THUMB) operands. */
6139 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6140 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6141 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6142
c19d1205
ZW
6143 OP_FIRST_OPTIONAL = OP_oI7b
6144};
a737bd4d 6145
c19d1205
ZW
6146/* Generic instruction operand parser. This does no encoding and no
6147 semantic validation; it merely squirrels values away in the inst
6148 structure. Returns SUCCESS or FAIL depending on whether the
6149 specified grammar matched. */
6150static int
5be8be5d 6151parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6152{
5be8be5d 6153 unsigned const int *upat = pattern;
c19d1205
ZW
6154 char *backtrack_pos = 0;
6155 const char *backtrack_error = 0;
6156 int i, val, backtrack_index = 0;
5287ad62 6157 enum arm_reg_type rtype;
4962c51a 6158 parse_operand_result result;
5be8be5d 6159 unsigned int op_parse_code;
c19d1205 6160
e07e6e58
NC
6161#define po_char_or_fail(chr) \
6162 do \
6163 { \
6164 if (skip_past_char (&str, chr) == FAIL) \
6165 goto bad_args; \
6166 } \
6167 while (0)
c19d1205 6168
e07e6e58
NC
6169#define po_reg_or_fail(regtype) \
6170 do \
dcbf9037 6171 { \
e07e6e58
NC
6172 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6173 & inst.operands[i].vectype); \
6174 if (val == FAIL) \
6175 { \
6176 first_error (_(reg_expected_msgs[regtype])); \
6177 goto failure; \
6178 } \
6179 inst.operands[i].reg = val; \
6180 inst.operands[i].isreg = 1; \
6181 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6182 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6183 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6184 || rtype == REG_TYPE_VFD \
6185 || rtype == REG_TYPE_NQ); \
dcbf9037 6186 } \
e07e6e58
NC
6187 while (0)
6188
6189#define po_reg_or_goto(regtype, label) \
6190 do \
6191 { \
6192 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6193 & inst.operands[i].vectype); \
6194 if (val == FAIL) \
6195 goto label; \
dcbf9037 6196 \
e07e6e58
NC
6197 inst.operands[i].reg = val; \
6198 inst.operands[i].isreg = 1; \
6199 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6200 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6201 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6202 || rtype == REG_TYPE_VFD \
6203 || rtype == REG_TYPE_NQ); \
6204 } \
6205 while (0)
6206
6207#define po_imm_or_fail(min, max, popt) \
6208 do \
6209 { \
6210 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6211 goto failure; \
6212 inst.operands[i].imm = val; \
6213 } \
6214 while (0)
6215
6216#define po_scalar_or_goto(elsz, label) \
6217 do \
6218 { \
6219 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6220 if (val == FAIL) \
6221 goto label; \
6222 inst.operands[i].reg = val; \
6223 inst.operands[i].isscalar = 1; \
6224 } \
6225 while (0)
6226
6227#define po_misc_or_fail(expr) \
6228 do \
6229 { \
6230 if (expr) \
6231 goto failure; \
6232 } \
6233 while (0)
6234
6235#define po_misc_or_fail_no_backtrack(expr) \
6236 do \
6237 { \
6238 result = expr; \
6239 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6240 backtrack_pos = 0; \
6241 if (result != PARSE_OPERAND_SUCCESS) \
6242 goto failure; \
6243 } \
6244 while (0)
4962c51a 6245
52e7f43d
RE
6246#define po_barrier_or_imm(str) \
6247 do \
6248 { \
6249 val = parse_barrier (&str); \
6250 if (val == FAIL) \
6251 { \
6252 if (ISALPHA (*str)) \
6253 goto failure; \
6254 else \
6255 goto immediate; \
6256 } \
6257 else \
6258 { \
6259 if ((inst.instruction & 0xf0) == 0x60 \
6260 && val != 0xf) \
6261 { \
6262 /* ISB can only take SY as an option. */ \
6263 inst.error = _("invalid barrier type"); \
6264 goto failure; \
6265 } \
6266 } \
6267 } \
6268 while (0)
6269
c19d1205
ZW
6270 skip_whitespace (str);
6271
6272 for (i = 0; upat[i] != OP_stop; i++)
6273 {
5be8be5d
DG
6274 op_parse_code = upat[i];
6275 if (op_parse_code >= 1<<16)
6276 op_parse_code = thumb ? (op_parse_code >> 16)
6277 : (op_parse_code & ((1<<16)-1));
6278
6279 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6280 {
6281 /* Remember where we are in case we need to backtrack. */
9c2799c2 6282 gas_assert (!backtrack_pos);
c19d1205
ZW
6283 backtrack_pos = str;
6284 backtrack_error = inst.error;
6285 backtrack_index = i;
6286 }
6287
b6702015 6288 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6289 po_char_or_fail (',');
6290
5be8be5d 6291 switch (op_parse_code)
c19d1205
ZW
6292 {
6293 /* Registers */
6294 case OP_oRRnpc:
5be8be5d 6295 case OP_oRRnpcsp:
c19d1205 6296 case OP_RRnpc:
5be8be5d 6297 case OP_RRnpcsp:
c19d1205
ZW
6298 case OP_oRR:
6299 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6300 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6301 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6302 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6303 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6304 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
6305 case OP_oRND:
6306 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6307 case OP_RVC:
6308 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6309 break;
6310 /* Also accept generic coprocessor regs for unknown registers. */
6311 coproc_reg:
6312 po_reg_or_fail (REG_TYPE_CN);
6313 break;
c19d1205
ZW
6314 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6315 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6316 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6317 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6318 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6319 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6320 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6321 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6322 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6323 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
6324 case OP_oRNQ:
6325 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6326 case OP_oRNDQ:
6327 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
6328 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6329 case OP_oRNSDQ:
6330 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
6331
6332 /* Neon scalar. Using an element size of 8 means that some invalid
6333 scalars are accepted here, so deal with those in later code. */
6334 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6335
5287ad62
JB
6336 case OP_RNDQ_I0:
6337 {
6338 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6339 break;
6340 try_imm0:
6341 po_imm_or_fail (0, 0, TRUE);
6342 }
6343 break;
6344
037e8744
JB
6345 case OP_RVSD_I0:
6346 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6347 break;
6348
5287ad62
JB
6349 case OP_RR_RNSC:
6350 {
6351 po_scalar_or_goto (8, try_rr);
6352 break;
6353 try_rr:
6354 po_reg_or_fail (REG_TYPE_RN);
6355 }
6356 break;
6357
037e8744
JB
6358 case OP_RNSDQ_RNSC:
6359 {
6360 po_scalar_or_goto (8, try_nsdq);
6361 break;
6362 try_nsdq:
6363 po_reg_or_fail (REG_TYPE_NSDQ);
6364 }
6365 break;
6366
5287ad62
JB
6367 case OP_RNDQ_RNSC:
6368 {
6369 po_scalar_or_goto (8, try_ndq);
6370 break;
6371 try_ndq:
6372 po_reg_or_fail (REG_TYPE_NDQ);
6373 }
6374 break;
6375
6376 case OP_RND_RNSC:
6377 {
6378 po_scalar_or_goto (8, try_vfd);
6379 break;
6380 try_vfd:
6381 po_reg_or_fail (REG_TYPE_VFD);
6382 }
6383 break;
6384
6385 case OP_VMOV:
6386 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6387 not careful then bad things might happen. */
6388 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6389 break;
6390
4316f0d2 6391 case OP_RNDQ_Ibig:
5287ad62 6392 {
4316f0d2 6393 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
5287ad62 6394 break;
4316f0d2 6395 try_immbig:
5287ad62
JB
6396 /* There's a possibility of getting a 64-bit immediate here, so
6397 we need special handling. */
6398 if (parse_big_immediate (&str, i) == FAIL)
6399 {
6400 inst.error = _("immediate value is out of range");
6401 goto failure;
6402 }
6403 }
6404 break;
6405
6406 case OP_RNDQ_I63b:
6407 {
6408 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6409 break;
6410 try_shimm:
6411 po_imm_or_fail (0, 63, TRUE);
6412 }
6413 break;
c19d1205
ZW
6414
6415 case OP_RRnpcb:
6416 po_char_or_fail ('[');
6417 po_reg_or_fail (REG_TYPE_RN);
6418 po_char_or_fail (']');
6419 break;
a737bd4d 6420
55881a11 6421 case OP_RRnpctw:
c19d1205 6422 case OP_RRw:
b6702015 6423 case OP_oRRw:
c19d1205
ZW
6424 po_reg_or_fail (REG_TYPE_RN);
6425 if (skip_past_char (&str, '!') == SUCCESS)
6426 inst.operands[i].writeback = 1;
6427 break;
6428
6429 /* Immediates */
6430 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6431 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6432 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 6433 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6434 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6435 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 6436 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6437 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
6438 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6439 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6440 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6441 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6442
6443 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6444 case OP_oI7b:
6445 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6446 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6447 case OP_oI31b:
6448 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 6449 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
6450 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6451
6452 /* Immediate variants */
6453 case OP_oI255c:
6454 po_char_or_fail ('{');
6455 po_imm_or_fail (0, 255, TRUE);
6456 po_char_or_fail ('}');
6457 break;
6458
6459 case OP_I31w:
6460 /* The expression parser chokes on a trailing !, so we have
6461 to find it first and zap it. */
6462 {
6463 char *s = str;
6464 while (*s && *s != ',')
6465 s++;
6466 if (s[-1] == '!')
6467 {
6468 s[-1] = '\0';
6469 inst.operands[i].writeback = 1;
6470 }
6471 po_imm_or_fail (0, 31, TRUE);
6472 if (str == s - 1)
6473 str = s;
6474 }
6475 break;
6476
6477 /* Expressions */
6478 case OP_EXPi: EXPi:
6479 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6480 GE_OPT_PREFIX));
6481 break;
6482
6483 case OP_EXP:
6484 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6485 GE_NO_PREFIX));
6486 break;
6487
6488 case OP_EXPr: EXPr:
6489 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6490 GE_NO_PREFIX));
6491 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6492 {
c19d1205
ZW
6493 val = parse_reloc (&str);
6494 if (val == -1)
6495 {
6496 inst.error = _("unrecognized relocation suffix");
6497 goto failure;
6498 }
6499 else if (val != BFD_RELOC_UNUSED)
6500 {
6501 inst.operands[i].imm = val;
6502 inst.operands[i].hasreloc = 1;
6503 }
a737bd4d 6504 }
c19d1205 6505 break;
a737bd4d 6506
b6895b4f
PB
6507 /* Operand for MOVW or MOVT. */
6508 case OP_HALF:
6509 po_misc_or_fail (parse_half (&str));
6510 break;
6511
e07e6e58 6512 /* Register or expression. */
c19d1205
ZW
6513 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6514 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6515
e07e6e58 6516 /* Register or immediate. */
c19d1205
ZW
6517 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6518 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6519
c19d1205
ZW
6520 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6521 IF:
6522 if (!is_immediate_prefix (*str))
6523 goto bad_args;
6524 str++;
6525 val = parse_fpa_immediate (&str);
6526 if (val == FAIL)
6527 goto failure;
6528 /* FPA immediates are encoded as registers 8-15.
6529 parse_fpa_immediate has already applied the offset. */
6530 inst.operands[i].reg = val;
6531 inst.operands[i].isreg = 1;
6532 break;
09d92015 6533
2d447fca
JM
6534 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6535 I32z: po_imm_or_fail (0, 32, FALSE); break;
6536
e07e6e58 6537 /* Two kinds of register. */
c19d1205
ZW
6538 case OP_RIWR_RIWC:
6539 {
6540 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6541 if (!rege
6542 || (rege->type != REG_TYPE_MMXWR
6543 && rege->type != REG_TYPE_MMXWC
6544 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6545 {
6546 inst.error = _("iWMMXt data or control register expected");
6547 goto failure;
6548 }
6549 inst.operands[i].reg = rege->number;
6550 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6551 }
6552 break;
09d92015 6553
41adaa5c
JM
6554 case OP_RIWC_RIWG:
6555 {
6556 struct reg_entry *rege = arm_reg_parse_multi (&str);
6557 if (!rege
6558 || (rege->type != REG_TYPE_MMXWC
6559 && rege->type != REG_TYPE_MMXWCG))
6560 {
6561 inst.error = _("iWMMXt control register expected");
6562 goto failure;
6563 }
6564 inst.operands[i].reg = rege->number;
6565 inst.operands[i].isreg = 1;
6566 }
6567 break;
6568
c19d1205
ZW
6569 /* Misc */
6570 case OP_CPSF: val = parse_cps_flags (&str); break;
6571 case OP_ENDI: val = parse_endian_specifier (&str); break;
6572 case OP_oROR: val = parse_ror (&str); break;
c19d1205 6573 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6574 case OP_oBARRIER_I15:
6575 po_barrier_or_imm (str); break;
6576 immediate:
6577 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6578 goto failure;
6579 break;
c19d1205 6580
d2cd1205
JB
6581 case OP_wPSR:
6582 case OP_rPSR:
90ec0d68
MGD
6583 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6584 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6585 {
6586 inst.error = _("Banked registers are not available with this "
6587 "architecture.");
6588 goto failure;
6589 }
6590 break;
d2cd1205
JB
6591 try_psr:
6592 val = parse_psr (&str, op_parse_code == OP_wPSR);
6593 break;
037e8744
JB
6594
6595 case OP_APSR_RR:
6596 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6597 break;
6598 try_apsr:
6599 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6600 instruction). */
6601 if (strncasecmp (str, "APSR_", 5) == 0)
6602 {
6603 unsigned found = 0;
6604 str += 5;
6605 while (found < 15)
6606 switch (*str++)
6607 {
6608 case 'c': found = (found & 1) ? 16 : found | 1; break;
6609 case 'n': found = (found & 2) ? 16 : found | 2; break;
6610 case 'z': found = (found & 4) ? 16 : found | 4; break;
6611 case 'v': found = (found & 8) ? 16 : found | 8; break;
6612 default: found = 16;
6613 }
6614 if (found != 15)
6615 goto failure;
6616 inst.operands[i].isvec = 1;
f7c21dc7
NC
6617 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6618 inst.operands[i].reg = REG_PC;
037e8744
JB
6619 }
6620 else
6621 goto failure;
6622 break;
6623
92e90b6e
PB
6624 case OP_TB:
6625 po_misc_or_fail (parse_tb (&str));
6626 break;
6627
e07e6e58 6628 /* Register lists. */
c19d1205
ZW
6629 case OP_REGLST:
6630 val = parse_reg_list (&str);
6631 if (*str == '^')
6632 {
6633 inst.operands[1].writeback = 1;
6634 str++;
6635 }
6636 break;
09d92015 6637
c19d1205 6638 case OP_VRSLST:
5287ad62 6639 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6640 break;
09d92015 6641
c19d1205 6642 case OP_VRDLST:
5287ad62 6643 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6644 break;
a737bd4d 6645
037e8744
JB
6646 case OP_VRSDLST:
6647 /* Allow Q registers too. */
6648 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6649 REGLIST_NEON_D);
6650 if (val == FAIL)
6651 {
6652 inst.error = NULL;
6653 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6654 REGLIST_VFP_S);
6655 inst.operands[i].issingle = 1;
6656 }
6657 break;
6658
5287ad62
JB
6659 case OP_NRDLST:
6660 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6661 REGLIST_NEON_D);
6662 break;
6663
6664 case OP_NSTRLST:
dcbf9037
JB
6665 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6666 &inst.operands[i].vectype);
5287ad62
JB
6667 break;
6668
c19d1205
ZW
6669 /* Addressing modes */
6670 case OP_ADDR:
6671 po_misc_or_fail (parse_address (&str, i));
6672 break;
09d92015 6673
4962c51a
MS
6674 case OP_ADDRGLDR:
6675 po_misc_or_fail_no_backtrack (
6676 parse_address_group_reloc (&str, i, GROUP_LDR));
6677 break;
6678
6679 case OP_ADDRGLDRS:
6680 po_misc_or_fail_no_backtrack (
6681 parse_address_group_reloc (&str, i, GROUP_LDRS));
6682 break;
6683
6684 case OP_ADDRGLDC:
6685 po_misc_or_fail_no_backtrack (
6686 parse_address_group_reloc (&str, i, GROUP_LDC));
6687 break;
6688
c19d1205
ZW
6689 case OP_SH:
6690 po_misc_or_fail (parse_shifter_operand (&str, i));
6691 break;
09d92015 6692
4962c51a
MS
6693 case OP_SHG:
6694 po_misc_or_fail_no_backtrack (
6695 parse_shifter_operand_group_reloc (&str, i));
6696 break;
6697
c19d1205
ZW
6698 case OP_oSHll:
6699 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6700 break;
09d92015 6701
c19d1205
ZW
6702 case OP_oSHar:
6703 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6704 break;
09d92015 6705
c19d1205
ZW
6706 case OP_oSHllar:
6707 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6708 break;
09d92015 6709
c19d1205 6710 default:
5be8be5d 6711 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 6712 }
09d92015 6713
c19d1205
ZW
6714 /* Various value-based sanity checks and shared operations. We
6715 do not signal immediate failures for the register constraints;
6716 this allows a syntax error to take precedence. */
5be8be5d 6717 switch (op_parse_code)
c19d1205
ZW
6718 {
6719 case OP_oRRnpc:
6720 case OP_RRnpc:
6721 case OP_RRnpcb:
6722 case OP_RRw:
b6702015 6723 case OP_oRRw:
c19d1205
ZW
6724 case OP_RRnpc_I0:
6725 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6726 inst.error = BAD_PC;
6727 break;
09d92015 6728
5be8be5d
DG
6729 case OP_oRRnpcsp:
6730 case OP_RRnpcsp:
6731 if (inst.operands[i].isreg)
6732 {
6733 if (inst.operands[i].reg == REG_PC)
6734 inst.error = BAD_PC;
6735 else if (inst.operands[i].reg == REG_SP)
6736 inst.error = BAD_SP;
6737 }
6738 break;
6739
55881a11
MGD
6740 case OP_RRnpctw:
6741 if (inst.operands[i].isreg
6742 && inst.operands[i].reg == REG_PC
6743 && (inst.operands[i].writeback || thumb))
6744 inst.error = BAD_PC;
6745 break;
6746
c19d1205
ZW
6747 case OP_CPSF:
6748 case OP_ENDI:
6749 case OP_oROR:
d2cd1205
JB
6750 case OP_wPSR:
6751 case OP_rPSR:
c19d1205 6752 case OP_COND:
52e7f43d 6753 case OP_oBARRIER_I15:
c19d1205
ZW
6754 case OP_REGLST:
6755 case OP_VRSLST:
6756 case OP_VRDLST:
037e8744 6757 case OP_VRSDLST:
5287ad62
JB
6758 case OP_NRDLST:
6759 case OP_NSTRLST:
c19d1205
ZW
6760 if (val == FAIL)
6761 goto failure;
6762 inst.operands[i].imm = val;
6763 break;
a737bd4d 6764
c19d1205
ZW
6765 default:
6766 break;
6767 }
09d92015 6768
c19d1205
ZW
6769 /* If we get here, this operand was successfully parsed. */
6770 inst.operands[i].present = 1;
6771 continue;
09d92015 6772
c19d1205 6773 bad_args:
09d92015 6774 inst.error = BAD_ARGS;
c19d1205
ZW
6775
6776 failure:
6777 if (!backtrack_pos)
d252fdde
PB
6778 {
6779 /* The parse routine should already have set inst.error, but set a
5f4273c7 6780 default here just in case. */
d252fdde
PB
6781 if (!inst.error)
6782 inst.error = _("syntax error");
6783 return FAIL;
6784 }
c19d1205
ZW
6785
6786 /* Do not backtrack over a trailing optional argument that
6787 absorbed some text. We will only fail again, with the
6788 'garbage following instruction' error message, which is
6789 probably less helpful than the current one. */
6790 if (backtrack_index == i && backtrack_pos != str
6791 && upat[i+1] == OP_stop)
d252fdde
PB
6792 {
6793 if (!inst.error)
6794 inst.error = _("syntax error");
6795 return FAIL;
6796 }
c19d1205
ZW
6797
6798 /* Try again, skipping the optional argument at backtrack_pos. */
6799 str = backtrack_pos;
6800 inst.error = backtrack_error;
6801 inst.operands[backtrack_index].present = 0;
6802 i = backtrack_index;
6803 backtrack_pos = 0;
09d92015 6804 }
09d92015 6805
c19d1205
ZW
6806 /* Check that we have parsed all the arguments. */
6807 if (*str != '\0' && !inst.error)
6808 inst.error = _("garbage following instruction");
09d92015 6809
c19d1205 6810 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6811}
6812
c19d1205
ZW
6813#undef po_char_or_fail
6814#undef po_reg_or_fail
6815#undef po_reg_or_goto
6816#undef po_imm_or_fail
5287ad62 6817#undef po_scalar_or_fail
52e7f43d 6818#undef po_barrier_or_imm
e07e6e58 6819
c19d1205 6820/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6821#define constraint(expr, err) \
6822 do \
c19d1205 6823 { \
e07e6e58
NC
6824 if (expr) \
6825 { \
6826 inst.error = err; \
6827 return; \
6828 } \
c19d1205 6829 } \
e07e6e58 6830 while (0)
c19d1205 6831
fdfde340
JM
6832/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6833 instructions are unpredictable if these registers are used. This
6834 is the BadReg predicate in ARM's Thumb-2 documentation. */
6835#define reject_bad_reg(reg) \
6836 do \
6837 if (reg == REG_SP || reg == REG_PC) \
6838 { \
6839 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6840 return; \
6841 } \
6842 while (0)
6843
94206790
MM
6844/* If REG is R13 (the stack pointer), warn that its use is
6845 deprecated. */
6846#define warn_deprecated_sp(reg) \
6847 do \
6848 if (warn_on_deprecated && reg == REG_SP) \
6849 as_warn (_("use of r13 is deprecated")); \
6850 while (0)
6851
c19d1205
ZW
6852/* Functions for operand encoding. ARM, then Thumb. */
6853
6854#define rotate_left(v, n) (v << n | v >> (32 - n))
6855
6856/* If VAL can be encoded in the immediate field of an ARM instruction,
6857 return the encoded form. Otherwise, return FAIL. */
6858
6859static unsigned int
6860encode_arm_immediate (unsigned int val)
09d92015 6861{
c19d1205
ZW
6862 unsigned int a, i;
6863
6864 for (i = 0; i < 32; i += 2)
6865 if ((a = rotate_left (val, i)) <= 0xff)
6866 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6867
6868 return FAIL;
09d92015
MM
6869}
6870
c19d1205
ZW
6871/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6872 return the encoded form. Otherwise, return FAIL. */
6873static unsigned int
6874encode_thumb32_immediate (unsigned int val)
09d92015 6875{
c19d1205 6876 unsigned int a, i;
09d92015 6877
9c3c69f2 6878 if (val <= 0xff)
c19d1205 6879 return val;
a737bd4d 6880
9c3c69f2 6881 for (i = 1; i <= 24; i++)
09d92015 6882 {
9c3c69f2
PB
6883 a = val >> i;
6884 if ((val & ~(0xff << i)) == 0)
6885 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6886 }
a737bd4d 6887
c19d1205
ZW
6888 a = val & 0xff;
6889 if (val == ((a << 16) | a))
6890 return 0x100 | a;
6891 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6892 return 0x300 | a;
09d92015 6893
c19d1205
ZW
6894 a = val & 0xff00;
6895 if (val == ((a << 16) | a))
6896 return 0x200 | (a >> 8);
a737bd4d 6897
c19d1205 6898 return FAIL;
09d92015 6899}
5287ad62 6900/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6901
6902static void
5287ad62
JB
6903encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6904{
6905 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6906 && reg > 15)
6907 {
b1cc4aeb 6908 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6909 {
6910 if (thumb_mode)
6911 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6912 fpu_vfp_ext_d32);
5287ad62
JB
6913 else
6914 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6915 fpu_vfp_ext_d32);
5287ad62
JB
6916 }
6917 else
6918 {
dcbf9037 6919 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6920 return;
6921 }
6922 }
6923
c19d1205 6924 switch (pos)
09d92015 6925 {
c19d1205
ZW
6926 case VFP_REG_Sd:
6927 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6928 break;
6929
6930 case VFP_REG_Sn:
6931 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6932 break;
6933
6934 case VFP_REG_Sm:
6935 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6936 break;
6937
5287ad62
JB
6938 case VFP_REG_Dd:
6939 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6940 break;
5f4273c7 6941
5287ad62
JB
6942 case VFP_REG_Dn:
6943 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6944 break;
5f4273c7 6945
5287ad62
JB
6946 case VFP_REG_Dm:
6947 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6948 break;
6949
c19d1205
ZW
6950 default:
6951 abort ();
09d92015 6952 }
09d92015
MM
6953}
6954
c19d1205 6955/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6956 if any, is handled by md_apply_fix. */
09d92015 6957static void
c19d1205 6958encode_arm_shift (int i)
09d92015 6959{
c19d1205
ZW
6960 if (inst.operands[i].shift_kind == SHIFT_RRX)
6961 inst.instruction |= SHIFT_ROR << 5;
6962 else
09d92015 6963 {
c19d1205
ZW
6964 inst.instruction |= inst.operands[i].shift_kind << 5;
6965 if (inst.operands[i].immisreg)
6966 {
6967 inst.instruction |= SHIFT_BY_REG;
6968 inst.instruction |= inst.operands[i].imm << 8;
6969 }
6970 else
6971 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6972 }
c19d1205 6973}
09d92015 6974
c19d1205
ZW
6975static void
6976encode_arm_shifter_operand (int i)
6977{
6978 if (inst.operands[i].isreg)
09d92015 6979 {
c19d1205
ZW
6980 inst.instruction |= inst.operands[i].reg;
6981 encode_arm_shift (i);
09d92015 6982 }
c19d1205
ZW
6983 else
6984 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6985}
6986
c19d1205 6987/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6988static void
c19d1205 6989encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6990{
9c2799c2 6991 gas_assert (inst.operands[i].isreg);
c19d1205 6992 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6993
c19d1205 6994 if (inst.operands[i].preind)
09d92015 6995 {
c19d1205
ZW
6996 if (is_t)
6997 {
6998 inst.error = _("instruction does not accept preindexed addressing");
6999 return;
7000 }
7001 inst.instruction |= PRE_INDEX;
7002 if (inst.operands[i].writeback)
7003 inst.instruction |= WRITE_BACK;
09d92015 7004
c19d1205
ZW
7005 }
7006 else if (inst.operands[i].postind)
7007 {
9c2799c2 7008 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7009 if (is_t)
7010 inst.instruction |= WRITE_BACK;
7011 }
7012 else /* unindexed - only for coprocessor */
09d92015 7013 {
c19d1205 7014 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7015 return;
7016 }
7017
c19d1205
ZW
7018 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7019 && (((inst.instruction & 0x000f0000) >> 16)
7020 == ((inst.instruction & 0x0000f000) >> 12)))
7021 as_warn ((inst.instruction & LOAD_BIT)
7022 ? _("destination register same as write-back base")
7023 : _("source register same as write-back base"));
09d92015
MM
7024}
7025
c19d1205
ZW
7026/* inst.operands[i] was set up by parse_address. Encode it into an
7027 ARM-format mode 2 load or store instruction. If is_t is true,
7028 reject forms that cannot be used with a T instruction (i.e. not
7029 post-indexed). */
a737bd4d 7030static void
c19d1205 7031encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7032{
5be8be5d
DG
7033 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7034
c19d1205 7035 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7036
c19d1205 7037 if (inst.operands[i].immisreg)
09d92015 7038 {
5be8be5d
DG
7039 constraint ((inst.operands[i].imm == REG_PC
7040 || (is_pc && inst.operands[i].writeback)),
7041 BAD_PC_ADDRESSING);
c19d1205
ZW
7042 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7043 inst.instruction |= inst.operands[i].imm;
7044 if (!inst.operands[i].negative)
7045 inst.instruction |= INDEX_UP;
7046 if (inst.operands[i].shifted)
7047 {
7048 if (inst.operands[i].shift_kind == SHIFT_RRX)
7049 inst.instruction |= SHIFT_ROR << 5;
7050 else
7051 {
7052 inst.instruction |= inst.operands[i].shift_kind << 5;
7053 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7054 }
7055 }
09d92015 7056 }
c19d1205 7057 else /* immediate offset in inst.reloc */
09d92015 7058 {
5be8be5d
DG
7059 if (is_pc && !inst.reloc.pc_rel)
7060 {
7061 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7062
7063 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7064 cannot use PC in addressing.
7065 PC cannot be used in writeback addressing, either. */
7066 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7067 BAD_PC_ADDRESSING);
23a10334 7068
dc5ec521 7069 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7070 if (warn_on_deprecated
7071 && !is_load
7072 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7073 as_warn (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7074 }
7075
c19d1205 7076 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7077 {
7078 /* Prefer + for zero encoded value. */
7079 if (!inst.operands[i].negative)
7080 inst.instruction |= INDEX_UP;
7081 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7082 }
09d92015 7083 }
09d92015
MM
7084}
7085
c19d1205
ZW
7086/* inst.operands[i] was set up by parse_address. Encode it into an
7087 ARM-format mode 3 load or store instruction. Reject forms that
7088 cannot be used with such instructions. If is_t is true, reject
7089 forms that cannot be used with a T instruction (i.e. not
7090 post-indexed). */
7091static void
7092encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7093{
c19d1205 7094 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7095 {
c19d1205
ZW
7096 inst.error = _("instruction does not accept scaled register index");
7097 return;
09d92015 7098 }
a737bd4d 7099
c19d1205 7100 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7101
c19d1205
ZW
7102 if (inst.operands[i].immisreg)
7103 {
5be8be5d
DG
7104 constraint ((inst.operands[i].imm == REG_PC
7105 || inst.operands[i].reg == REG_PC),
7106 BAD_PC_ADDRESSING);
c19d1205
ZW
7107 inst.instruction |= inst.operands[i].imm;
7108 if (!inst.operands[i].negative)
7109 inst.instruction |= INDEX_UP;
7110 }
7111 else /* immediate offset in inst.reloc */
7112 {
5be8be5d
DG
7113 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7114 && inst.operands[i].writeback),
7115 BAD_PC_WRITEBACK);
c19d1205
ZW
7116 inst.instruction |= HWOFFSET_IMM;
7117 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7118 {
7119 /* Prefer + for zero encoded value. */
7120 if (!inst.operands[i].negative)
7121 inst.instruction |= INDEX_UP;
7122
7123 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7124 }
c19d1205 7125 }
a737bd4d
NC
7126}
7127
c19d1205
ZW
7128/* inst.operands[i] was set up by parse_address. Encode it into an
7129 ARM-format instruction. Reject all forms which cannot be encoded
7130 into a coprocessor load/store instruction. If wb_ok is false,
7131 reject use of writeback; if unind_ok is false, reject use of
7132 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
7133 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
7134 (in which case it is preserved). */
09d92015 7135
c19d1205
ZW
7136static int
7137encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 7138{
c19d1205 7139 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7140
9c2799c2 7141 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 7142
c19d1205 7143 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 7144 {
9c2799c2 7145 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
7146 if (!unind_ok)
7147 {
7148 inst.error = _("instruction does not support unindexed addressing");
7149 return FAIL;
7150 }
7151 inst.instruction |= inst.operands[i].imm;
7152 inst.instruction |= INDEX_UP;
7153 return SUCCESS;
09d92015 7154 }
a737bd4d 7155
c19d1205
ZW
7156 if (inst.operands[i].preind)
7157 inst.instruction |= PRE_INDEX;
a737bd4d 7158
c19d1205 7159 if (inst.operands[i].writeback)
09d92015 7160 {
c19d1205
ZW
7161 if (inst.operands[i].reg == REG_PC)
7162 {
7163 inst.error = _("pc may not be used with write-back");
7164 return FAIL;
7165 }
7166 if (!wb_ok)
7167 {
7168 inst.error = _("instruction does not support writeback");
7169 return FAIL;
7170 }
7171 inst.instruction |= WRITE_BACK;
09d92015 7172 }
a737bd4d 7173
c19d1205 7174 if (reloc_override)
21d799b5 7175 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a
MS
7176 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
7177 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
7178 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
7179 {
7180 if (thumb_mode)
7181 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
7182 else
7183 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
7184 }
7185
26d97720
NS
7186 /* Prefer + for zero encoded value. */
7187 if (!inst.operands[i].negative)
7188 inst.instruction |= INDEX_UP;
7189
c19d1205
ZW
7190 return SUCCESS;
7191}
a737bd4d 7192
c19d1205
ZW
7193/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7194 Determine whether it can be performed with a move instruction; if
7195 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7196 return TRUE; if it can't, convert inst.instruction to a literal-pool
7197 load and return FALSE. If this is not a valid thing to do in the
7198 current context, set inst.error and return TRUE.
a737bd4d 7199
c19d1205
ZW
7200 inst.operands[i] describes the destination register. */
7201
c921be7d 7202static bfd_boolean
c19d1205
ZW
7203move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
7204{
53365c0d
PB
7205 unsigned long tbit;
7206
7207 if (thumb_p)
7208 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7209 else
7210 tbit = LOAD_BIT;
7211
7212 if ((inst.instruction & tbit) == 0)
09d92015 7213 {
c19d1205 7214 inst.error = _("invalid pseudo operation");
c921be7d 7215 return TRUE;
09d92015 7216 }
c19d1205 7217 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
7218 {
7219 inst.error = _("constant expression expected");
c921be7d 7220 return TRUE;
09d92015 7221 }
c19d1205 7222 if (inst.reloc.exp.X_op == O_constant)
09d92015 7223 {
c19d1205
ZW
7224 if (thumb_p)
7225 {
53365c0d 7226 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
7227 {
7228 /* This can be done with a mov(1) instruction. */
7229 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7230 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 7231 return TRUE;
c19d1205
ZW
7232 }
7233 }
7234 else
7235 {
7236 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7237 if (value != FAIL)
7238 {
7239 /* This can be done with a mov instruction. */
7240 inst.instruction &= LITERAL_MASK;
7241 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7242 inst.instruction |= value & 0xfff;
c921be7d 7243 return TRUE;
c19d1205 7244 }
09d92015 7245
c19d1205
ZW
7246 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7247 if (value != FAIL)
7248 {
7249 /* This can be done with a mvn instruction. */
7250 inst.instruction &= LITERAL_MASK;
7251 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7252 inst.instruction |= value & 0xfff;
c921be7d 7253 return TRUE;
c19d1205
ZW
7254 }
7255 }
09d92015
MM
7256 }
7257
c19d1205
ZW
7258 if (add_to_lit_pool () == FAIL)
7259 {
7260 inst.error = _("literal pool insertion failed");
c921be7d 7261 return TRUE;
c19d1205
ZW
7262 }
7263 inst.operands[1].reg = REG_PC;
7264 inst.operands[1].isreg = 1;
7265 inst.operands[1].preind = 1;
7266 inst.reloc.pc_rel = 1;
7267 inst.reloc.type = (thumb_p
7268 ? BFD_RELOC_ARM_THUMB_OFFSET
7269 : (mode_3
7270 ? BFD_RELOC_ARM_HWLITERAL
7271 : BFD_RELOC_ARM_LITERAL));
c921be7d 7272 return FALSE;
09d92015
MM
7273}
7274
5f4273c7 7275/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
7276 First some generics; their names are taken from the conventional
7277 bit positions for register arguments in ARM format instructions. */
09d92015 7278
a737bd4d 7279static void
c19d1205 7280do_noargs (void)
09d92015 7281{
c19d1205 7282}
a737bd4d 7283
c19d1205
ZW
7284static void
7285do_rd (void)
7286{
7287 inst.instruction |= inst.operands[0].reg << 12;
7288}
a737bd4d 7289
c19d1205
ZW
7290static void
7291do_rd_rm (void)
7292{
7293 inst.instruction |= inst.operands[0].reg << 12;
7294 inst.instruction |= inst.operands[1].reg;
7295}
09d92015 7296
c19d1205
ZW
7297static void
7298do_rd_rn (void)
7299{
7300 inst.instruction |= inst.operands[0].reg << 12;
7301 inst.instruction |= inst.operands[1].reg << 16;
7302}
a737bd4d 7303
c19d1205
ZW
7304static void
7305do_rn_rd (void)
7306{
7307 inst.instruction |= inst.operands[0].reg << 16;
7308 inst.instruction |= inst.operands[1].reg << 12;
7309}
09d92015 7310
c19d1205
ZW
7311static void
7312do_rd_rm_rn (void)
7313{
9a64e435 7314 unsigned Rn = inst.operands[2].reg;
708587a4 7315 /* Enforce restrictions on SWP instruction. */
9a64e435 7316 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
7317 {
7318 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7319 _("Rn must not overlap other operands"));
7320
7321 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
7322 if (warn_on_deprecated
7323 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7324 as_warn (_("swp{b} use is deprecated for this architecture"));
7325
7326 }
c19d1205
ZW
7327 inst.instruction |= inst.operands[0].reg << 12;
7328 inst.instruction |= inst.operands[1].reg;
9a64e435 7329 inst.instruction |= Rn << 16;
c19d1205 7330}
09d92015 7331
c19d1205
ZW
7332static void
7333do_rd_rn_rm (void)
7334{
7335 inst.instruction |= inst.operands[0].reg << 12;
7336 inst.instruction |= inst.operands[1].reg << 16;
7337 inst.instruction |= inst.operands[2].reg;
7338}
a737bd4d 7339
c19d1205
ZW
7340static void
7341do_rm_rd_rn (void)
7342{
5be8be5d
DG
7343 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7344 constraint (((inst.reloc.exp.X_op != O_constant
7345 && inst.reloc.exp.X_op != O_illegal)
7346 || inst.reloc.exp.X_add_number != 0),
7347 BAD_ADDR_MODE);
c19d1205
ZW
7348 inst.instruction |= inst.operands[0].reg;
7349 inst.instruction |= inst.operands[1].reg << 12;
7350 inst.instruction |= inst.operands[2].reg << 16;
7351}
09d92015 7352
c19d1205
ZW
7353static void
7354do_imm0 (void)
7355{
7356 inst.instruction |= inst.operands[0].imm;
7357}
09d92015 7358
c19d1205
ZW
7359static void
7360do_rd_cpaddr (void)
7361{
7362 inst.instruction |= inst.operands[0].reg << 12;
7363 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 7364}
a737bd4d 7365
c19d1205
ZW
7366/* ARM instructions, in alphabetical order by function name (except
7367 that wrapper functions appear immediately after the function they
7368 wrap). */
09d92015 7369
c19d1205
ZW
7370/* This is a pseudo-op of the form "adr rd, label" to be converted
7371 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
7372
7373static void
c19d1205 7374do_adr (void)
09d92015 7375{
c19d1205 7376 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7377
c19d1205
ZW
7378 /* Frag hacking will turn this into a sub instruction if the offset turns
7379 out to be negative. */
7380 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 7381 inst.reloc.pc_rel = 1;
2fc8bdac 7382 inst.reloc.exp.X_add_number -= 8;
c19d1205 7383}
b99bd4ef 7384
c19d1205
ZW
7385/* This is a pseudo-op of the form "adrl rd, label" to be converted
7386 into a relative address of the form:
7387 add rd, pc, #low(label-.-8)"
7388 add rd, rd, #high(label-.-8)" */
b99bd4ef 7389
c19d1205
ZW
7390static void
7391do_adrl (void)
7392{
7393 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7394
c19d1205
ZW
7395 /* Frag hacking will turn this into a sub instruction if the offset turns
7396 out to be negative. */
7397 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
7398 inst.reloc.pc_rel = 1;
7399 inst.size = INSN_SIZE * 2;
2fc8bdac 7400 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
7401}
7402
b99bd4ef 7403static void
c19d1205 7404do_arit (void)
b99bd4ef 7405{
c19d1205
ZW
7406 if (!inst.operands[1].present)
7407 inst.operands[1].reg = inst.operands[0].reg;
7408 inst.instruction |= inst.operands[0].reg << 12;
7409 inst.instruction |= inst.operands[1].reg << 16;
7410 encode_arm_shifter_operand (2);
7411}
b99bd4ef 7412
62b3e311
PB
7413static void
7414do_barrier (void)
7415{
7416 if (inst.operands[0].present)
7417 {
7418 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
7419 && inst.operands[0].imm > 0xf
7420 && inst.operands[0].imm < 0x0,
bd3ba5d1 7421 _("bad barrier type"));
62b3e311
PB
7422 inst.instruction |= inst.operands[0].imm;
7423 }
7424 else
7425 inst.instruction |= 0xf;
7426}
7427
c19d1205
ZW
7428static void
7429do_bfc (void)
7430{
7431 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7432 constraint (msb > 32, _("bit-field extends past end of register"));
7433 /* The instruction encoding stores the LSB and MSB,
7434 not the LSB and width. */
7435 inst.instruction |= inst.operands[0].reg << 12;
7436 inst.instruction |= inst.operands[1].imm << 7;
7437 inst.instruction |= (msb - 1) << 16;
7438}
b99bd4ef 7439
c19d1205
ZW
7440static void
7441do_bfi (void)
7442{
7443 unsigned int msb;
b99bd4ef 7444
c19d1205
ZW
7445 /* #0 in second position is alternative syntax for bfc, which is
7446 the same instruction but with REG_PC in the Rm field. */
7447 if (!inst.operands[1].isreg)
7448 inst.operands[1].reg = REG_PC;
b99bd4ef 7449
c19d1205
ZW
7450 msb = inst.operands[2].imm + inst.operands[3].imm;
7451 constraint (msb > 32, _("bit-field extends past end of register"));
7452 /* The instruction encoding stores the LSB and MSB,
7453 not the LSB and width. */
7454 inst.instruction |= inst.operands[0].reg << 12;
7455 inst.instruction |= inst.operands[1].reg;
7456 inst.instruction |= inst.operands[2].imm << 7;
7457 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7458}
7459
b99bd4ef 7460static void
c19d1205 7461do_bfx (void)
b99bd4ef 7462{
c19d1205
ZW
7463 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7464 _("bit-field extends past end of register"));
7465 inst.instruction |= inst.operands[0].reg << 12;
7466 inst.instruction |= inst.operands[1].reg;
7467 inst.instruction |= inst.operands[2].imm << 7;
7468 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7469}
09d92015 7470
c19d1205
ZW
7471/* ARM V5 breakpoint instruction (argument parse)
7472 BKPT <16 bit unsigned immediate>
7473 Instruction is not conditional.
7474 The bit pattern given in insns[] has the COND_ALWAYS condition,
7475 and it is an error if the caller tried to override that. */
b99bd4ef 7476
c19d1205
ZW
7477static void
7478do_bkpt (void)
7479{
7480 /* Top 12 of 16 bits to bits 19:8. */
7481 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7482
c19d1205
ZW
7483 /* Bottom 4 of 16 bits to bits 3:0. */
7484 inst.instruction |= inst.operands[0].imm & 0xf;
7485}
09d92015 7486
c19d1205
ZW
7487static void
7488encode_branch (int default_reloc)
7489{
7490 if (inst.operands[0].hasreloc)
7491 {
0855e32b
NS
7492 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
7493 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
7494 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
7495 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
7496 ? BFD_RELOC_ARM_PLT32
7497 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 7498 }
b99bd4ef 7499 else
9ae92b05 7500 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 7501 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7502}
7503
b99bd4ef 7504static void
c19d1205 7505do_branch (void)
b99bd4ef 7506{
39b41c9c
PB
7507#ifdef OBJ_ELF
7508 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7509 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7510 else
7511#endif
7512 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7513}
7514
7515static void
7516do_bl (void)
7517{
7518#ifdef OBJ_ELF
7519 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7520 {
7521 if (inst.cond == COND_ALWAYS)
7522 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7523 else
7524 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7525 }
7526 else
7527#endif
7528 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7529}
b99bd4ef 7530
c19d1205
ZW
7531/* ARM V5 branch-link-exchange instruction (argument parse)
7532 BLX <target_addr> ie BLX(1)
7533 BLX{<condition>} <Rm> ie BLX(2)
7534 Unfortunately, there are two different opcodes for this mnemonic.
7535 So, the insns[].value is not used, and the code here zaps values
7536 into inst.instruction.
7537 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7538
c19d1205
ZW
7539static void
7540do_blx (void)
7541{
7542 if (inst.operands[0].isreg)
b99bd4ef 7543 {
c19d1205
ZW
7544 /* Arg is a register; the opcode provided by insns[] is correct.
7545 It is not illegal to do "blx pc", just useless. */
7546 if (inst.operands[0].reg == REG_PC)
7547 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7548
c19d1205
ZW
7549 inst.instruction |= inst.operands[0].reg;
7550 }
7551 else
b99bd4ef 7552 {
c19d1205 7553 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7554 conditionally, and the opcode must be adjusted.
7555 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7556 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7557 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7558 inst.instruction = 0xfa000000;
267bf995 7559 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7560 }
c19d1205
ZW
7561}
7562
7563static void
7564do_bx (void)
7565{
845b51d6
PB
7566 bfd_boolean want_reloc;
7567
c19d1205
ZW
7568 if (inst.operands[0].reg == REG_PC)
7569 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7570
c19d1205 7571 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7572 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7573 it is for ARMv4t or earlier. */
7574 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7575 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7576 want_reloc = TRUE;
7577
5ad34203 7578#ifdef OBJ_ELF
845b51d6 7579 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7580#endif
584206db 7581 want_reloc = FALSE;
845b51d6
PB
7582
7583 if (want_reloc)
7584 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7585}
7586
c19d1205
ZW
7587
7588/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7589
7590static void
c19d1205 7591do_bxj (void)
a737bd4d 7592{
c19d1205
ZW
7593 if (inst.operands[0].reg == REG_PC)
7594 as_tsktsk (_("use of r15 in bxj is not really useful"));
7595
7596 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7597}
7598
c19d1205
ZW
7599/* Co-processor data operation:
7600 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7601 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7602static void
7603do_cdp (void)
7604{
7605 inst.instruction |= inst.operands[0].reg << 8;
7606 inst.instruction |= inst.operands[1].imm << 20;
7607 inst.instruction |= inst.operands[2].reg << 12;
7608 inst.instruction |= inst.operands[3].reg << 16;
7609 inst.instruction |= inst.operands[4].reg;
7610 inst.instruction |= inst.operands[5].imm << 5;
7611}
a737bd4d
NC
7612
7613static void
c19d1205 7614do_cmp (void)
a737bd4d 7615{
c19d1205
ZW
7616 inst.instruction |= inst.operands[0].reg << 16;
7617 encode_arm_shifter_operand (1);
a737bd4d
NC
7618}
7619
c19d1205
ZW
7620/* Transfer between coprocessor and ARM registers.
7621 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7622 MRC2
7623 MCR{cond}
7624 MCR2
7625
7626 No special properties. */
09d92015
MM
7627
7628static void
c19d1205 7629do_co_reg (void)
09d92015 7630{
fdfde340
JM
7631 unsigned Rd;
7632
7633 Rd = inst.operands[2].reg;
7634 if (thumb_mode)
7635 {
7636 if (inst.instruction == 0xee000010
7637 || inst.instruction == 0xfe000010)
7638 /* MCR, MCR2 */
7639 reject_bad_reg (Rd);
7640 else
7641 /* MRC, MRC2 */
7642 constraint (Rd == REG_SP, BAD_SP);
7643 }
7644 else
7645 {
7646 /* MCR */
7647 if (inst.instruction == 0xe000010)
7648 constraint (Rd == REG_PC, BAD_PC);
7649 }
7650
7651
c19d1205
ZW
7652 inst.instruction |= inst.operands[0].reg << 8;
7653 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7654 inst.instruction |= Rd << 12;
c19d1205
ZW
7655 inst.instruction |= inst.operands[3].reg << 16;
7656 inst.instruction |= inst.operands[4].reg;
7657 inst.instruction |= inst.operands[5].imm << 5;
7658}
09d92015 7659
c19d1205
ZW
7660/* Transfer between coprocessor register and pair of ARM registers.
7661 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7662 MCRR2
7663 MRRC{cond}
7664 MRRC2
b99bd4ef 7665
c19d1205 7666 Two XScale instructions are special cases of these:
09d92015 7667
c19d1205
ZW
7668 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7669 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7670
5f4273c7 7671 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7672
c19d1205
ZW
7673static void
7674do_co_reg2c (void)
7675{
fdfde340
JM
7676 unsigned Rd, Rn;
7677
7678 Rd = inst.operands[2].reg;
7679 Rn = inst.operands[3].reg;
7680
7681 if (thumb_mode)
7682 {
7683 reject_bad_reg (Rd);
7684 reject_bad_reg (Rn);
7685 }
7686 else
7687 {
7688 constraint (Rd == REG_PC, BAD_PC);
7689 constraint (Rn == REG_PC, BAD_PC);
7690 }
7691
c19d1205
ZW
7692 inst.instruction |= inst.operands[0].reg << 8;
7693 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7694 inst.instruction |= Rd << 12;
7695 inst.instruction |= Rn << 16;
c19d1205 7696 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7697}
7698
c19d1205
ZW
7699static void
7700do_cpsi (void)
7701{
7702 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7703 if (inst.operands[1].present)
7704 {
7705 inst.instruction |= CPSI_MMOD;
7706 inst.instruction |= inst.operands[1].imm;
7707 }
c19d1205 7708}
b99bd4ef 7709
62b3e311
PB
7710static void
7711do_dbg (void)
7712{
7713 inst.instruction |= inst.operands[0].imm;
7714}
7715
eea54501
MGD
7716static void
7717do_div (void)
7718{
7719 unsigned Rd, Rn, Rm;
7720
7721 Rd = inst.operands[0].reg;
7722 Rn = (inst.operands[1].present
7723 ? inst.operands[1].reg : Rd);
7724 Rm = inst.operands[2].reg;
7725
7726 constraint ((Rd == REG_PC), BAD_PC);
7727 constraint ((Rn == REG_PC), BAD_PC);
7728 constraint ((Rm == REG_PC), BAD_PC);
7729
7730 inst.instruction |= Rd << 16;
7731 inst.instruction |= Rn << 0;
7732 inst.instruction |= Rm << 8;
7733}
7734
b99bd4ef 7735static void
c19d1205 7736do_it (void)
b99bd4ef 7737{
c19d1205 7738 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7739 process it to do the validation as if in
7740 thumb mode, just in case the code gets
7741 assembled for thumb using the unified syntax. */
7742
c19d1205 7743 inst.size = 0;
e07e6e58
NC
7744 if (unified_syntax)
7745 {
7746 set_it_insn_type (IT_INSN);
7747 now_it.mask = (inst.instruction & 0xf) | 0x10;
7748 now_it.cc = inst.operands[0].imm;
7749 }
09d92015 7750}
b99bd4ef 7751
09d92015 7752static void
c19d1205 7753do_ldmstm (void)
ea6ef066 7754{
c19d1205
ZW
7755 int base_reg = inst.operands[0].reg;
7756 int range = inst.operands[1].imm;
ea6ef066 7757
c19d1205
ZW
7758 inst.instruction |= base_reg << 16;
7759 inst.instruction |= range;
ea6ef066 7760
c19d1205
ZW
7761 if (inst.operands[1].writeback)
7762 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7763
c19d1205 7764 if (inst.operands[0].writeback)
ea6ef066 7765 {
c19d1205
ZW
7766 inst.instruction |= WRITE_BACK;
7767 /* Check for unpredictable uses of writeback. */
7768 if (inst.instruction & LOAD_BIT)
09d92015 7769 {
c19d1205
ZW
7770 /* Not allowed in LDM type 2. */
7771 if ((inst.instruction & LDM_TYPE_2_OR_3)
7772 && ((range & (1 << REG_PC)) == 0))
7773 as_warn (_("writeback of base register is UNPREDICTABLE"));
7774 /* Only allowed if base reg not in list for other types. */
7775 else if (range & (1 << base_reg))
7776 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7777 }
7778 else /* STM. */
7779 {
7780 /* Not allowed for type 2. */
7781 if (inst.instruction & LDM_TYPE_2_OR_3)
7782 as_warn (_("writeback of base register is UNPREDICTABLE"));
7783 /* Only allowed if base reg not in list, or first in list. */
7784 else if ((range & (1 << base_reg))
7785 && (range & ((1 << base_reg) - 1)))
7786 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7787 }
ea6ef066 7788 }
a737bd4d
NC
7789}
7790
c19d1205
ZW
7791/* ARMv5TE load-consecutive (argument parse)
7792 Mode is like LDRH.
7793
7794 LDRccD R, mode
7795 STRccD R, mode. */
7796
a737bd4d 7797static void
c19d1205 7798do_ldrd (void)
a737bd4d 7799{
c19d1205
ZW
7800 constraint (inst.operands[0].reg % 2 != 0,
7801 _("first destination register must be even"));
7802 constraint (inst.operands[1].present
7803 && inst.operands[1].reg != inst.operands[0].reg + 1,
7804 _("can only load two consecutive registers"));
7805 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7806 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7807
c19d1205
ZW
7808 if (!inst.operands[1].present)
7809 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7810
c19d1205 7811 if (inst.instruction & LOAD_BIT)
a737bd4d 7812 {
c19d1205
ZW
7813 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7814 register and the first register written; we have to diagnose
7815 overlap between the base and the second register written here. */
ea6ef066 7816
c19d1205
ZW
7817 if (inst.operands[2].reg == inst.operands[1].reg
7818 && (inst.operands[2].writeback || inst.operands[2].postind))
7819 as_warn (_("base register written back, and overlaps "
7820 "second destination register"));
b05fe5cf 7821
c19d1205
ZW
7822 /* For an index-register load, the index register must not overlap the
7823 destination (even if not write-back). */
7824 else if (inst.operands[2].immisreg
ca3f61f7
NC
7825 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7826 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 7827 as_warn (_("index register overlaps destination register"));
b05fe5cf 7828 }
c19d1205
ZW
7829
7830 inst.instruction |= inst.operands[0].reg << 12;
7831 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7832}
7833
7834static void
c19d1205 7835do_ldrex (void)
b05fe5cf 7836{
c19d1205
ZW
7837 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7838 || inst.operands[1].postind || inst.operands[1].writeback
7839 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7840 || inst.operands[1].negative
7841 /* This can arise if the programmer has written
7842 strex rN, rM, foo
7843 or if they have mistakenly used a register name as the last
7844 operand, eg:
7845 strex rN, rM, rX
7846 It is very difficult to distinguish between these two cases
7847 because "rX" might actually be a label. ie the register
7848 name has been occluded by a symbol of the same name. So we
7849 just generate a general 'bad addressing mode' type error
7850 message and leave it up to the programmer to discover the
7851 true cause and fix their mistake. */
7852 || (inst.operands[1].reg == REG_PC),
7853 BAD_ADDR_MODE);
b05fe5cf 7854
c19d1205
ZW
7855 constraint (inst.reloc.exp.X_op != O_constant
7856 || inst.reloc.exp.X_add_number != 0,
7857 _("offset must be zero in ARM encoding"));
b05fe5cf 7858
5be8be5d
DG
7859 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7860
c19d1205
ZW
7861 inst.instruction |= inst.operands[0].reg << 12;
7862 inst.instruction |= inst.operands[1].reg << 16;
7863 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7864}
7865
7866static void
c19d1205 7867do_ldrexd (void)
b05fe5cf 7868{
c19d1205
ZW
7869 constraint (inst.operands[0].reg % 2 != 0,
7870 _("even register required"));
7871 constraint (inst.operands[1].present
7872 && inst.operands[1].reg != inst.operands[0].reg + 1,
7873 _("can only load two consecutive registers"));
7874 /* If op 1 were present and equal to PC, this function wouldn't
7875 have been called in the first place. */
7876 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7877
c19d1205
ZW
7878 inst.instruction |= inst.operands[0].reg << 12;
7879 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7880}
7881
7882static void
c19d1205 7883do_ldst (void)
b05fe5cf 7884{
c19d1205
ZW
7885 inst.instruction |= inst.operands[0].reg << 12;
7886 if (!inst.operands[1].isreg)
7887 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7888 return;
c19d1205 7889 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7890}
7891
7892static void
c19d1205 7893do_ldstt (void)
b05fe5cf 7894{
c19d1205
ZW
7895 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7896 reject [Rn,...]. */
7897 if (inst.operands[1].preind)
b05fe5cf 7898 {
bd3ba5d1
NC
7899 constraint (inst.reloc.exp.X_op != O_constant
7900 || inst.reloc.exp.X_add_number != 0,
c19d1205 7901 _("this instruction requires a post-indexed address"));
b05fe5cf 7902
c19d1205
ZW
7903 inst.operands[1].preind = 0;
7904 inst.operands[1].postind = 1;
7905 inst.operands[1].writeback = 1;
b05fe5cf 7906 }
c19d1205
ZW
7907 inst.instruction |= inst.operands[0].reg << 12;
7908 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7909}
b05fe5cf 7910
c19d1205 7911/* Halfword and signed-byte load/store operations. */
b05fe5cf 7912
c19d1205
ZW
7913static void
7914do_ldstv4 (void)
7915{
ff4a8d2b 7916 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7917 inst.instruction |= inst.operands[0].reg << 12;
7918 if (!inst.operands[1].isreg)
7919 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7920 return;
c19d1205 7921 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7922}
7923
7924static void
c19d1205 7925do_ldsttv4 (void)
b05fe5cf 7926{
c19d1205
ZW
7927 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7928 reject [Rn,...]. */
7929 if (inst.operands[1].preind)
b05fe5cf 7930 {
bd3ba5d1
NC
7931 constraint (inst.reloc.exp.X_op != O_constant
7932 || inst.reloc.exp.X_add_number != 0,
c19d1205 7933 _("this instruction requires a post-indexed address"));
b05fe5cf 7934
c19d1205
ZW
7935 inst.operands[1].preind = 0;
7936 inst.operands[1].postind = 1;
7937 inst.operands[1].writeback = 1;
b05fe5cf 7938 }
c19d1205
ZW
7939 inst.instruction |= inst.operands[0].reg << 12;
7940 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7941}
b05fe5cf 7942
c19d1205
ZW
7943/* Co-processor register load/store.
7944 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7945static void
7946do_lstc (void)
7947{
7948 inst.instruction |= inst.operands[0].reg << 8;
7949 inst.instruction |= inst.operands[1].reg << 12;
7950 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7951}
7952
b05fe5cf 7953static void
c19d1205 7954do_mlas (void)
b05fe5cf 7955{
8fb9d7b9 7956 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7957 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7958 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7959 && !(inst.instruction & 0x00400000))
8fb9d7b9 7960 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7961
c19d1205
ZW
7962 inst.instruction |= inst.operands[0].reg << 16;
7963 inst.instruction |= inst.operands[1].reg;
7964 inst.instruction |= inst.operands[2].reg << 8;
7965 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7966}
b05fe5cf 7967
c19d1205
ZW
7968static void
7969do_mov (void)
7970{
7971 inst.instruction |= inst.operands[0].reg << 12;
7972 encode_arm_shifter_operand (1);
7973}
b05fe5cf 7974
c19d1205
ZW
7975/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7976static void
7977do_mov16 (void)
7978{
b6895b4f
PB
7979 bfd_vma imm;
7980 bfd_boolean top;
7981
7982 top = (inst.instruction & 0x00400000) != 0;
7983 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7984 _(":lower16: not allowed this instruction"));
7985 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7986 _(":upper16: not allowed instruction"));
c19d1205 7987 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7988 if (inst.reloc.type == BFD_RELOC_UNUSED)
7989 {
7990 imm = inst.reloc.exp.X_add_number;
7991 /* The value is in two pieces: 0:11, 16:19. */
7992 inst.instruction |= (imm & 0x00000fff);
7993 inst.instruction |= (imm & 0x0000f000) << 4;
7994 }
b05fe5cf 7995}
b99bd4ef 7996
037e8744
JB
7997static void do_vfp_nsyn_opcode (const char *);
7998
7999static int
8000do_vfp_nsyn_mrs (void)
8001{
8002 if (inst.operands[0].isvec)
8003 {
8004 if (inst.operands[1].reg != 1)
8005 first_error (_("operand 1 must be FPSCR"));
8006 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8007 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8008 do_vfp_nsyn_opcode ("fmstat");
8009 }
8010 else if (inst.operands[1].isvec)
8011 do_vfp_nsyn_opcode ("fmrx");
8012 else
8013 return FAIL;
5f4273c7 8014
037e8744
JB
8015 return SUCCESS;
8016}
8017
8018static int
8019do_vfp_nsyn_msr (void)
8020{
8021 if (inst.operands[0].isvec)
8022 do_vfp_nsyn_opcode ("fmxr");
8023 else
8024 return FAIL;
8025
8026 return SUCCESS;
8027}
8028
f7c21dc7
NC
8029static void
8030do_vmrs (void)
8031{
8032 unsigned Rt = inst.operands[0].reg;
8033
8034 if (thumb_mode && inst.operands[0].reg == REG_SP)
8035 {
8036 inst.error = BAD_SP;
8037 return;
8038 }
8039
8040 /* APSR_ sets isvec. All other refs to PC are illegal. */
8041 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
8042 {
8043 inst.error = BAD_PC;
8044 return;
8045 }
8046
8047 if (inst.operands[1].reg != 1)
8048 first_error (_("operand 1 must be FPSCR"));
8049
8050 inst.instruction |= (Rt << 12);
8051}
8052
8053static void
8054do_vmsr (void)
8055{
8056 unsigned Rt = inst.operands[1].reg;
8057
8058 if (thumb_mode)
8059 reject_bad_reg (Rt);
8060 else if (Rt == REG_PC)
8061 {
8062 inst.error = BAD_PC;
8063 return;
8064 }
8065
8066 if (inst.operands[0].reg != 1)
8067 first_error (_("operand 0 must be FPSCR"));
8068
8069 inst.instruction |= (Rt << 12);
8070}
8071
b99bd4ef 8072static void
c19d1205 8073do_mrs (void)
b99bd4ef 8074{
90ec0d68
MGD
8075 unsigned br;
8076
037e8744
JB
8077 if (do_vfp_nsyn_mrs () == SUCCESS)
8078 return;
8079
ff4a8d2b 8080 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 8081 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
8082
8083 if (inst.operands[1].isreg)
8084 {
8085 br = inst.operands[1].reg;
8086 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
8087 as_bad (_("bad register for mrs"));
8088 }
8089 else
8090 {
8091 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
8092 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
8093 != (PSR_c|PSR_f),
d2cd1205 8094 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
8095 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
8096 }
8097
8098 inst.instruction |= br;
c19d1205 8099}
b99bd4ef 8100
c19d1205
ZW
8101/* Two possible forms:
8102 "{C|S}PSR_<field>, Rm",
8103 "{C|S}PSR_f, #expression". */
b99bd4ef 8104
c19d1205
ZW
8105static void
8106do_msr (void)
8107{
037e8744
JB
8108 if (do_vfp_nsyn_msr () == SUCCESS)
8109 return;
8110
c19d1205
ZW
8111 inst.instruction |= inst.operands[0].imm;
8112 if (inst.operands[1].isreg)
8113 inst.instruction |= inst.operands[1].reg;
8114 else
b99bd4ef 8115 {
c19d1205
ZW
8116 inst.instruction |= INST_IMMEDIATE;
8117 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8118 inst.reloc.pc_rel = 0;
b99bd4ef 8119 }
b99bd4ef
NC
8120}
8121
c19d1205
ZW
8122static void
8123do_mul (void)
a737bd4d 8124{
ff4a8d2b
NC
8125 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
8126
c19d1205
ZW
8127 if (!inst.operands[2].present)
8128 inst.operands[2].reg = inst.operands[0].reg;
8129 inst.instruction |= inst.operands[0].reg << 16;
8130 inst.instruction |= inst.operands[1].reg;
8131 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 8132
8fb9d7b9
MS
8133 if (inst.operands[0].reg == inst.operands[1].reg
8134 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8135 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
8136}
8137
c19d1205
ZW
8138/* Long Multiply Parser
8139 UMULL RdLo, RdHi, Rm, Rs
8140 SMULL RdLo, RdHi, Rm, Rs
8141 UMLAL RdLo, RdHi, Rm, Rs
8142 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
8143
8144static void
c19d1205 8145do_mull (void)
b99bd4ef 8146{
c19d1205
ZW
8147 inst.instruction |= inst.operands[0].reg << 12;
8148 inst.instruction |= inst.operands[1].reg << 16;
8149 inst.instruction |= inst.operands[2].reg;
8150 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 8151
682b27ad
PB
8152 /* rdhi and rdlo must be different. */
8153 if (inst.operands[0].reg == inst.operands[1].reg)
8154 as_tsktsk (_("rdhi and rdlo must be different"));
8155
8156 /* rdhi, rdlo and rm must all be different before armv6. */
8157 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 8158 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 8159 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
8160 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
8161}
b99bd4ef 8162
c19d1205
ZW
8163static void
8164do_nop (void)
8165{
e7495e45
NS
8166 if (inst.operands[0].present
8167 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
8168 {
8169 /* Architectural NOP hints are CPSR sets with no bits selected. */
8170 inst.instruction &= 0xf0000000;
e7495e45
NS
8171 inst.instruction |= 0x0320f000;
8172 if (inst.operands[0].present)
8173 inst.instruction |= inst.operands[0].imm;
c19d1205 8174 }
b99bd4ef
NC
8175}
8176
c19d1205
ZW
8177/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
8178 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
8179 Condition defaults to COND_ALWAYS.
8180 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
8181
8182static void
c19d1205 8183do_pkhbt (void)
b99bd4ef 8184{
c19d1205
ZW
8185 inst.instruction |= inst.operands[0].reg << 12;
8186 inst.instruction |= inst.operands[1].reg << 16;
8187 inst.instruction |= inst.operands[2].reg;
8188 if (inst.operands[3].present)
8189 encode_arm_shift (3);
8190}
b99bd4ef 8191
c19d1205 8192/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 8193
c19d1205
ZW
8194static void
8195do_pkhtb (void)
8196{
8197 if (!inst.operands[3].present)
b99bd4ef 8198 {
c19d1205
ZW
8199 /* If the shift specifier is omitted, turn the instruction
8200 into pkhbt rd, rm, rn. */
8201 inst.instruction &= 0xfff00010;
8202 inst.instruction |= inst.operands[0].reg << 12;
8203 inst.instruction |= inst.operands[1].reg;
8204 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8205 }
8206 else
8207 {
c19d1205
ZW
8208 inst.instruction |= inst.operands[0].reg << 12;
8209 inst.instruction |= inst.operands[1].reg << 16;
8210 inst.instruction |= inst.operands[2].reg;
8211 encode_arm_shift (3);
b99bd4ef
NC
8212 }
8213}
8214
c19d1205 8215/* ARMv5TE: Preload-Cache
60e5ef9f 8216 MP Extensions: Preload for write
c19d1205 8217
60e5ef9f 8218 PLD(W) <addr_mode>
c19d1205
ZW
8219
8220 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
8221
8222static void
c19d1205 8223do_pld (void)
b99bd4ef 8224{
c19d1205
ZW
8225 constraint (!inst.operands[0].isreg,
8226 _("'[' expected after PLD mnemonic"));
8227 constraint (inst.operands[0].postind,
8228 _("post-indexed expression used in preload instruction"));
8229 constraint (inst.operands[0].writeback,
8230 _("writeback used in preload instruction"));
8231 constraint (!inst.operands[0].preind,
8232 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
8233 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8234}
b99bd4ef 8235
62b3e311
PB
8236/* ARMv7: PLI <addr_mode> */
8237static void
8238do_pli (void)
8239{
8240 constraint (!inst.operands[0].isreg,
8241 _("'[' expected after PLI mnemonic"));
8242 constraint (inst.operands[0].postind,
8243 _("post-indexed expression used in preload instruction"));
8244 constraint (inst.operands[0].writeback,
8245 _("writeback used in preload instruction"));
8246 constraint (!inst.operands[0].preind,
8247 _("unindexed addressing used in preload instruction"));
8248 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8249 inst.instruction &= ~PRE_INDEX;
8250}
8251
c19d1205
ZW
8252static void
8253do_push_pop (void)
8254{
8255 inst.operands[1] = inst.operands[0];
8256 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8257 inst.operands[0].isreg = 1;
8258 inst.operands[0].writeback = 1;
8259 inst.operands[0].reg = REG_SP;
8260 do_ldmstm ();
8261}
b99bd4ef 8262
c19d1205
ZW
8263/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8264 word at the specified address and the following word
8265 respectively.
8266 Unconditionally executed.
8267 Error if Rn is R15. */
b99bd4ef 8268
c19d1205
ZW
8269static void
8270do_rfe (void)
8271{
8272 inst.instruction |= inst.operands[0].reg << 16;
8273 if (inst.operands[0].writeback)
8274 inst.instruction |= WRITE_BACK;
8275}
b99bd4ef 8276
c19d1205 8277/* ARM V6 ssat (argument parse). */
b99bd4ef 8278
c19d1205
ZW
8279static void
8280do_ssat (void)
8281{
8282 inst.instruction |= inst.operands[0].reg << 12;
8283 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8284 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8285
c19d1205
ZW
8286 if (inst.operands[3].present)
8287 encode_arm_shift (3);
b99bd4ef
NC
8288}
8289
c19d1205 8290/* ARM V6 usat (argument parse). */
b99bd4ef
NC
8291
8292static void
c19d1205 8293do_usat (void)
b99bd4ef 8294{
c19d1205
ZW
8295 inst.instruction |= inst.operands[0].reg << 12;
8296 inst.instruction |= inst.operands[1].imm << 16;
8297 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8298
c19d1205
ZW
8299 if (inst.operands[3].present)
8300 encode_arm_shift (3);
b99bd4ef
NC
8301}
8302
c19d1205 8303/* ARM V6 ssat16 (argument parse). */
09d92015
MM
8304
8305static void
c19d1205 8306do_ssat16 (void)
09d92015 8307{
c19d1205
ZW
8308 inst.instruction |= inst.operands[0].reg << 12;
8309 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8310 inst.instruction |= inst.operands[2].reg;
09d92015
MM
8311}
8312
c19d1205
ZW
8313static void
8314do_usat16 (void)
a737bd4d 8315{
c19d1205
ZW
8316 inst.instruction |= inst.operands[0].reg << 12;
8317 inst.instruction |= inst.operands[1].imm << 16;
8318 inst.instruction |= inst.operands[2].reg;
8319}
a737bd4d 8320
c19d1205
ZW
8321/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8322 preserving the other bits.
a737bd4d 8323
c19d1205
ZW
8324 setend <endian_specifier>, where <endian_specifier> is either
8325 BE or LE. */
a737bd4d 8326
c19d1205
ZW
8327static void
8328do_setend (void)
8329{
8330 if (inst.operands[0].imm)
8331 inst.instruction |= 0x200;
a737bd4d
NC
8332}
8333
8334static void
c19d1205 8335do_shift (void)
a737bd4d 8336{
c19d1205
ZW
8337 unsigned int Rm = (inst.operands[1].present
8338 ? inst.operands[1].reg
8339 : inst.operands[0].reg);
a737bd4d 8340
c19d1205
ZW
8341 inst.instruction |= inst.operands[0].reg << 12;
8342 inst.instruction |= Rm;
8343 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 8344 {
c19d1205
ZW
8345 inst.instruction |= inst.operands[2].reg << 8;
8346 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
8347 }
8348 else
c19d1205 8349 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
8350}
8351
09d92015 8352static void
3eb17e6b 8353do_smc (void)
09d92015 8354{
3eb17e6b 8355 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 8356 inst.reloc.pc_rel = 0;
09d92015
MM
8357}
8358
90ec0d68
MGD
8359static void
8360do_hvc (void)
8361{
8362 inst.reloc.type = BFD_RELOC_ARM_HVC;
8363 inst.reloc.pc_rel = 0;
8364}
8365
09d92015 8366static void
c19d1205 8367do_swi (void)
09d92015 8368{
c19d1205
ZW
8369 inst.reloc.type = BFD_RELOC_ARM_SWI;
8370 inst.reloc.pc_rel = 0;
09d92015
MM
8371}
8372
c19d1205
ZW
8373/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8374 SMLAxy{cond} Rd,Rm,Rs,Rn
8375 SMLAWy{cond} Rd,Rm,Rs,Rn
8376 Error if any register is R15. */
e16bb312 8377
c19d1205
ZW
8378static void
8379do_smla (void)
e16bb312 8380{
c19d1205
ZW
8381 inst.instruction |= inst.operands[0].reg << 16;
8382 inst.instruction |= inst.operands[1].reg;
8383 inst.instruction |= inst.operands[2].reg << 8;
8384 inst.instruction |= inst.operands[3].reg << 12;
8385}
a737bd4d 8386
c19d1205
ZW
8387/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8388 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8389 Error if any register is R15.
8390 Warning if Rdlo == Rdhi. */
a737bd4d 8391
c19d1205
ZW
8392static void
8393do_smlal (void)
8394{
8395 inst.instruction |= inst.operands[0].reg << 12;
8396 inst.instruction |= inst.operands[1].reg << 16;
8397 inst.instruction |= inst.operands[2].reg;
8398 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 8399
c19d1205
ZW
8400 if (inst.operands[0].reg == inst.operands[1].reg)
8401 as_tsktsk (_("rdhi and rdlo must be different"));
8402}
a737bd4d 8403
c19d1205
ZW
8404/* ARM V5E (El Segundo) signed-multiply (argument parse)
8405 SMULxy{cond} Rd,Rm,Rs
8406 Error if any register is R15. */
a737bd4d 8407
c19d1205
ZW
8408static void
8409do_smul (void)
8410{
8411 inst.instruction |= inst.operands[0].reg << 16;
8412 inst.instruction |= inst.operands[1].reg;
8413 inst.instruction |= inst.operands[2].reg << 8;
8414}
a737bd4d 8415
b6702015
PB
8416/* ARM V6 srs (argument parse). The variable fields in the encoding are
8417 the same for both ARM and Thumb-2. */
a737bd4d 8418
c19d1205
ZW
8419static void
8420do_srs (void)
8421{
b6702015
PB
8422 int reg;
8423
8424 if (inst.operands[0].present)
8425 {
8426 reg = inst.operands[0].reg;
fdfde340 8427 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
8428 }
8429 else
fdfde340 8430 reg = REG_SP;
b6702015
PB
8431
8432 inst.instruction |= reg << 16;
8433 inst.instruction |= inst.operands[1].imm;
8434 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
8435 inst.instruction |= WRITE_BACK;
8436}
a737bd4d 8437
c19d1205 8438/* ARM V6 strex (argument parse). */
a737bd4d 8439
c19d1205
ZW
8440static void
8441do_strex (void)
8442{
8443 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8444 || inst.operands[2].postind || inst.operands[2].writeback
8445 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
8446 || inst.operands[2].negative
8447 /* See comment in do_ldrex(). */
8448 || (inst.operands[2].reg == REG_PC),
8449 BAD_ADDR_MODE);
a737bd4d 8450
c19d1205
ZW
8451 constraint (inst.operands[0].reg == inst.operands[1].reg
8452 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 8453
c19d1205
ZW
8454 constraint (inst.reloc.exp.X_op != O_constant
8455 || inst.reloc.exp.X_add_number != 0,
8456 _("offset must be zero in ARM encoding"));
a737bd4d 8457
c19d1205
ZW
8458 inst.instruction |= inst.operands[0].reg << 12;
8459 inst.instruction |= inst.operands[1].reg;
8460 inst.instruction |= inst.operands[2].reg << 16;
8461 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8462}
8463
8464static void
c19d1205 8465do_strexd (void)
e16bb312 8466{
c19d1205
ZW
8467 constraint (inst.operands[1].reg % 2 != 0,
8468 _("even register required"));
8469 constraint (inst.operands[2].present
8470 && inst.operands[2].reg != inst.operands[1].reg + 1,
8471 _("can only store two consecutive registers"));
8472 /* If op 2 were present and equal to PC, this function wouldn't
8473 have been called in the first place. */
8474 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8475
c19d1205
ZW
8476 constraint (inst.operands[0].reg == inst.operands[1].reg
8477 || inst.operands[0].reg == inst.operands[1].reg + 1
8478 || inst.operands[0].reg == inst.operands[3].reg,
8479 BAD_OVERLAP);
e16bb312 8480
c19d1205
ZW
8481 inst.instruction |= inst.operands[0].reg << 12;
8482 inst.instruction |= inst.operands[1].reg;
8483 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8484}
8485
c19d1205
ZW
8486/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8487 extends it to 32-bits, and adds the result to a value in another
8488 register. You can specify a rotation by 0, 8, 16, or 24 bits
8489 before extracting the 16-bit value.
8490 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8491 Condition defaults to COND_ALWAYS.
8492 Error if any register uses R15. */
8493
e16bb312 8494static void
c19d1205 8495do_sxtah (void)
e16bb312 8496{
c19d1205
ZW
8497 inst.instruction |= inst.operands[0].reg << 12;
8498 inst.instruction |= inst.operands[1].reg << 16;
8499 inst.instruction |= inst.operands[2].reg;
8500 inst.instruction |= inst.operands[3].imm << 10;
8501}
e16bb312 8502
c19d1205 8503/* ARM V6 SXTH.
e16bb312 8504
c19d1205
ZW
8505 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8506 Condition defaults to COND_ALWAYS.
8507 Error if any register uses R15. */
e16bb312
NC
8508
8509static void
c19d1205 8510do_sxth (void)
e16bb312 8511{
c19d1205
ZW
8512 inst.instruction |= inst.operands[0].reg << 12;
8513 inst.instruction |= inst.operands[1].reg;
8514 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8515}
c19d1205
ZW
8516\f
8517/* VFP instructions. In a logical order: SP variant first, monad
8518 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8519
8520static void
c19d1205 8521do_vfp_sp_monadic (void)
e16bb312 8522{
5287ad62
JB
8523 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8524 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8525}
8526
8527static void
c19d1205 8528do_vfp_sp_dyadic (void)
e16bb312 8529{
5287ad62
JB
8530 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8531 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8532 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8533}
8534
8535static void
c19d1205 8536do_vfp_sp_compare_z (void)
e16bb312 8537{
5287ad62 8538 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8539}
8540
8541static void
c19d1205 8542do_vfp_dp_sp_cvt (void)
e16bb312 8543{
5287ad62
JB
8544 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8545 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8546}
8547
8548static void
c19d1205 8549do_vfp_sp_dp_cvt (void)
e16bb312 8550{
5287ad62
JB
8551 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8552 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8553}
8554
8555static void
c19d1205 8556do_vfp_reg_from_sp (void)
e16bb312 8557{
c19d1205 8558 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8559 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8560}
8561
8562static void
c19d1205 8563do_vfp_reg2_from_sp2 (void)
e16bb312 8564{
c19d1205
ZW
8565 constraint (inst.operands[2].imm != 2,
8566 _("only two consecutive VFP SP registers allowed here"));
8567 inst.instruction |= inst.operands[0].reg << 12;
8568 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8569 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8570}
8571
8572static void
c19d1205 8573do_vfp_sp_from_reg (void)
e16bb312 8574{
5287ad62 8575 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8576 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8577}
8578
8579static void
c19d1205 8580do_vfp_sp2_from_reg2 (void)
e16bb312 8581{
c19d1205
ZW
8582 constraint (inst.operands[0].imm != 2,
8583 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8584 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8585 inst.instruction |= inst.operands[1].reg << 12;
8586 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8587}
8588
8589static void
c19d1205 8590do_vfp_sp_ldst (void)
e16bb312 8591{
5287ad62 8592 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 8593 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8594}
8595
8596static void
c19d1205 8597do_vfp_dp_ldst (void)
e16bb312 8598{
5287ad62 8599 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 8600 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8601}
8602
c19d1205 8603
e16bb312 8604static void
c19d1205 8605vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8606{
c19d1205
ZW
8607 if (inst.operands[0].writeback)
8608 inst.instruction |= WRITE_BACK;
8609 else
8610 constraint (ldstm_type != VFP_LDSTMIA,
8611 _("this addressing mode requires base-register writeback"));
8612 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8613 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 8614 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
8615}
8616
8617static void
c19d1205 8618vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8619{
c19d1205 8620 int count;
e16bb312 8621
c19d1205
ZW
8622 if (inst.operands[0].writeback)
8623 inst.instruction |= WRITE_BACK;
8624 else
8625 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8626 _("this addressing mode requires base-register writeback"));
e16bb312 8627
c19d1205 8628 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8629 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 8630
c19d1205
ZW
8631 count = inst.operands[1].imm << 1;
8632 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8633 count += 1;
e16bb312 8634
c19d1205 8635 inst.instruction |= count;
e16bb312
NC
8636}
8637
8638static void
c19d1205 8639do_vfp_sp_ldstmia (void)
e16bb312 8640{
c19d1205 8641 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8642}
8643
8644static void
c19d1205 8645do_vfp_sp_ldstmdb (void)
e16bb312 8646{
c19d1205 8647 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8648}
8649
8650static void
c19d1205 8651do_vfp_dp_ldstmia (void)
e16bb312 8652{
c19d1205 8653 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8654}
8655
8656static void
c19d1205 8657do_vfp_dp_ldstmdb (void)
e16bb312 8658{
c19d1205 8659 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8660}
8661
8662static void
c19d1205 8663do_vfp_xp_ldstmia (void)
e16bb312 8664{
c19d1205
ZW
8665 vfp_dp_ldstm (VFP_LDSTMIAX);
8666}
e16bb312 8667
c19d1205
ZW
8668static void
8669do_vfp_xp_ldstmdb (void)
8670{
8671 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 8672}
5287ad62
JB
8673
8674static void
8675do_vfp_dp_rd_rm (void)
8676{
8677 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8678 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8679}
8680
8681static void
8682do_vfp_dp_rn_rd (void)
8683{
8684 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8685 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8686}
8687
8688static void
8689do_vfp_dp_rd_rn (void)
8690{
8691 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8692 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8693}
8694
8695static void
8696do_vfp_dp_rd_rn_rm (void)
8697{
8698 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8699 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8700 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8701}
8702
8703static void
8704do_vfp_dp_rd (void)
8705{
8706 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8707}
8708
8709static void
8710do_vfp_dp_rm_rd_rn (void)
8711{
8712 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8713 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8714 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8715}
8716
8717/* VFPv3 instructions. */
8718static void
8719do_vfp_sp_const (void)
8720{
8721 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8722 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8723 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8724}
8725
8726static void
8727do_vfp_dp_const (void)
8728{
8729 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8730 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8731 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8732}
8733
8734static void
8735vfp_conv (int srcsize)
8736{
8737 unsigned immbits = srcsize - inst.operands[1].imm;
8738 inst.instruction |= (immbits & 1) << 5;
8739 inst.instruction |= (immbits >> 1);
8740}
8741
8742static void
8743do_vfp_sp_conv_16 (void)
8744{
8745 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8746 vfp_conv (16);
8747}
8748
8749static void
8750do_vfp_dp_conv_16 (void)
8751{
8752 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8753 vfp_conv (16);
8754}
8755
8756static void
8757do_vfp_sp_conv_32 (void)
8758{
8759 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8760 vfp_conv (32);
8761}
8762
8763static void
8764do_vfp_dp_conv_32 (void)
8765{
8766 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8767 vfp_conv (32);
8768}
c19d1205
ZW
8769\f
8770/* FPA instructions. Also in a logical order. */
e16bb312 8771
c19d1205
ZW
8772static void
8773do_fpa_cmp (void)
8774{
8775 inst.instruction |= inst.operands[0].reg << 16;
8776 inst.instruction |= inst.operands[1].reg;
8777}
b99bd4ef
NC
8778
8779static void
c19d1205 8780do_fpa_ldmstm (void)
b99bd4ef 8781{
c19d1205
ZW
8782 inst.instruction |= inst.operands[0].reg << 12;
8783 switch (inst.operands[1].imm)
8784 {
8785 case 1: inst.instruction |= CP_T_X; break;
8786 case 2: inst.instruction |= CP_T_Y; break;
8787 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8788 case 4: break;
8789 default: abort ();
8790 }
b99bd4ef 8791
c19d1205
ZW
8792 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8793 {
8794 /* The instruction specified "ea" or "fd", so we can only accept
8795 [Rn]{!}. The instruction does not really support stacking or
8796 unstacking, so we have to emulate these by setting appropriate
8797 bits and offsets. */
8798 constraint (inst.reloc.exp.X_op != O_constant
8799 || inst.reloc.exp.X_add_number != 0,
8800 _("this instruction does not support indexing"));
b99bd4ef 8801
c19d1205
ZW
8802 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8803 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8804
c19d1205
ZW
8805 if (!(inst.instruction & INDEX_UP))
8806 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8807
c19d1205
ZW
8808 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8809 {
8810 inst.operands[2].preind = 0;
8811 inst.operands[2].postind = 1;
8812 }
8813 }
b99bd4ef 8814
c19d1205 8815 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8816}
c19d1205
ZW
8817\f
8818/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8819
c19d1205
ZW
8820static void
8821do_iwmmxt_tandorc (void)
8822{
8823 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8824}
b99bd4ef 8825
c19d1205
ZW
8826static void
8827do_iwmmxt_textrc (void)
8828{
8829 inst.instruction |= inst.operands[0].reg << 12;
8830 inst.instruction |= inst.operands[1].imm;
8831}
b99bd4ef
NC
8832
8833static void
c19d1205 8834do_iwmmxt_textrm (void)
b99bd4ef 8835{
c19d1205
ZW
8836 inst.instruction |= inst.operands[0].reg << 12;
8837 inst.instruction |= inst.operands[1].reg << 16;
8838 inst.instruction |= inst.operands[2].imm;
8839}
b99bd4ef 8840
c19d1205
ZW
8841static void
8842do_iwmmxt_tinsr (void)
8843{
8844 inst.instruction |= inst.operands[0].reg << 16;
8845 inst.instruction |= inst.operands[1].reg << 12;
8846 inst.instruction |= inst.operands[2].imm;
8847}
b99bd4ef 8848
c19d1205
ZW
8849static void
8850do_iwmmxt_tmia (void)
8851{
8852 inst.instruction |= inst.operands[0].reg << 5;
8853 inst.instruction |= inst.operands[1].reg;
8854 inst.instruction |= inst.operands[2].reg << 12;
8855}
b99bd4ef 8856
c19d1205
ZW
8857static void
8858do_iwmmxt_waligni (void)
8859{
8860 inst.instruction |= inst.operands[0].reg << 12;
8861 inst.instruction |= inst.operands[1].reg << 16;
8862 inst.instruction |= inst.operands[2].reg;
8863 inst.instruction |= inst.operands[3].imm << 20;
8864}
b99bd4ef 8865
2d447fca
JM
8866static void
8867do_iwmmxt_wmerge (void)
8868{
8869 inst.instruction |= inst.operands[0].reg << 12;
8870 inst.instruction |= inst.operands[1].reg << 16;
8871 inst.instruction |= inst.operands[2].reg;
8872 inst.instruction |= inst.operands[3].imm << 21;
8873}
8874
c19d1205
ZW
8875static void
8876do_iwmmxt_wmov (void)
8877{
8878 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8879 inst.instruction |= inst.operands[0].reg << 12;
8880 inst.instruction |= inst.operands[1].reg << 16;
8881 inst.instruction |= inst.operands[1].reg;
8882}
b99bd4ef 8883
c19d1205
ZW
8884static void
8885do_iwmmxt_wldstbh (void)
8886{
8f06b2d8 8887 int reloc;
c19d1205 8888 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8889 if (thumb_mode)
8890 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8891 else
8892 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8893 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8894}
8895
c19d1205
ZW
8896static void
8897do_iwmmxt_wldstw (void)
8898{
8899 /* RIWR_RIWC clears .isreg for a control register. */
8900 if (!inst.operands[0].isreg)
8901 {
8902 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8903 inst.instruction |= 0xf0000000;
8904 }
b99bd4ef 8905
c19d1205
ZW
8906 inst.instruction |= inst.operands[0].reg << 12;
8907 encode_arm_cp_address (1, TRUE, TRUE, 0);
8908}
b99bd4ef
NC
8909
8910static void
c19d1205 8911do_iwmmxt_wldstd (void)
b99bd4ef 8912{
c19d1205 8913 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8914 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8915 && inst.operands[1].immisreg)
8916 {
8917 inst.instruction &= ~0x1a000ff;
8918 inst.instruction |= (0xf << 28);
8919 if (inst.operands[1].preind)
8920 inst.instruction |= PRE_INDEX;
8921 if (!inst.operands[1].negative)
8922 inst.instruction |= INDEX_UP;
8923 if (inst.operands[1].writeback)
8924 inst.instruction |= WRITE_BACK;
8925 inst.instruction |= inst.operands[1].reg << 16;
8926 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8927 inst.instruction |= inst.operands[1].imm;
8928 }
8929 else
8930 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8931}
b99bd4ef 8932
c19d1205
ZW
8933static void
8934do_iwmmxt_wshufh (void)
8935{
8936 inst.instruction |= inst.operands[0].reg << 12;
8937 inst.instruction |= inst.operands[1].reg << 16;
8938 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8939 inst.instruction |= (inst.operands[2].imm & 0x0f);
8940}
b99bd4ef 8941
c19d1205
ZW
8942static void
8943do_iwmmxt_wzero (void)
8944{
8945 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8946 inst.instruction |= inst.operands[0].reg;
8947 inst.instruction |= inst.operands[0].reg << 12;
8948 inst.instruction |= inst.operands[0].reg << 16;
8949}
2d447fca
JM
8950
8951static void
8952do_iwmmxt_wrwrwr_or_imm5 (void)
8953{
8954 if (inst.operands[2].isreg)
8955 do_rd_rn_rm ();
8956 else {
8957 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8958 _("immediate operand requires iWMMXt2"));
8959 do_rd_rn ();
8960 if (inst.operands[2].imm == 0)
8961 {
8962 switch ((inst.instruction >> 20) & 0xf)
8963 {
8964 case 4:
8965 case 5:
8966 case 6:
5f4273c7 8967 case 7:
2d447fca
JM
8968 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8969 inst.operands[2].imm = 16;
8970 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8971 break;
8972 case 8:
8973 case 9:
8974 case 10:
8975 case 11:
8976 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8977 inst.operands[2].imm = 32;
8978 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8979 break;
8980 case 12:
8981 case 13:
8982 case 14:
8983 case 15:
8984 {
8985 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8986 unsigned long wrn;
8987 wrn = (inst.instruction >> 16) & 0xf;
8988 inst.instruction &= 0xff0fff0f;
8989 inst.instruction |= wrn;
8990 /* Bail out here; the instruction is now assembled. */
8991 return;
8992 }
8993 }
8994 }
8995 /* Map 32 -> 0, etc. */
8996 inst.operands[2].imm &= 0x1f;
8997 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8998 }
8999}
c19d1205
ZW
9000\f
9001/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
9002 operations first, then control, shift, and load/store. */
b99bd4ef 9003
c19d1205 9004/* Insns like "foo X,Y,Z". */
b99bd4ef 9005
c19d1205
ZW
9006static void
9007do_mav_triple (void)
9008{
9009 inst.instruction |= inst.operands[0].reg << 16;
9010 inst.instruction |= inst.operands[1].reg;
9011 inst.instruction |= inst.operands[2].reg << 12;
9012}
b99bd4ef 9013
c19d1205
ZW
9014/* Insns like "foo W,X,Y,Z".
9015 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 9016
c19d1205
ZW
9017static void
9018do_mav_quad (void)
9019{
9020 inst.instruction |= inst.operands[0].reg << 5;
9021 inst.instruction |= inst.operands[1].reg << 12;
9022 inst.instruction |= inst.operands[2].reg << 16;
9023 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
9024}
9025
c19d1205
ZW
9026/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
9027static void
9028do_mav_dspsc (void)
a737bd4d 9029{
c19d1205
ZW
9030 inst.instruction |= inst.operands[1].reg << 12;
9031}
a737bd4d 9032
c19d1205
ZW
9033/* Maverick shift immediate instructions.
9034 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
9035 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 9036
c19d1205
ZW
9037static void
9038do_mav_shift (void)
9039{
9040 int imm = inst.operands[2].imm;
a737bd4d 9041
c19d1205
ZW
9042 inst.instruction |= inst.operands[0].reg << 12;
9043 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 9044
c19d1205
ZW
9045 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
9046 Bits 5-7 of the insn should have bits 4-6 of the immediate.
9047 Bit 4 should be 0. */
9048 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 9049
c19d1205
ZW
9050 inst.instruction |= imm;
9051}
9052\f
9053/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 9054
c19d1205
ZW
9055/* Xscale multiply-accumulate (argument parse)
9056 MIAcc acc0,Rm,Rs
9057 MIAPHcc acc0,Rm,Rs
9058 MIAxycc acc0,Rm,Rs. */
a737bd4d 9059
c19d1205
ZW
9060static void
9061do_xsc_mia (void)
9062{
9063 inst.instruction |= inst.operands[1].reg;
9064 inst.instruction |= inst.operands[2].reg << 12;
9065}
a737bd4d 9066
c19d1205 9067/* Xscale move-accumulator-register (argument parse)
a737bd4d 9068
c19d1205 9069 MARcc acc0,RdLo,RdHi. */
b99bd4ef 9070
c19d1205
ZW
9071static void
9072do_xsc_mar (void)
9073{
9074 inst.instruction |= inst.operands[1].reg << 12;
9075 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9076}
9077
c19d1205 9078/* Xscale move-register-accumulator (argument parse)
b99bd4ef 9079
c19d1205 9080 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
9081
9082static void
c19d1205 9083do_xsc_mra (void)
b99bd4ef 9084{
c19d1205
ZW
9085 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
9086 inst.instruction |= inst.operands[0].reg << 12;
9087 inst.instruction |= inst.operands[1].reg << 16;
9088}
9089\f
9090/* Encoding functions relevant only to Thumb. */
b99bd4ef 9091
c19d1205
ZW
9092/* inst.operands[i] is a shifted-register operand; encode
9093 it into inst.instruction in the format used by Thumb32. */
9094
9095static void
9096encode_thumb32_shifted_operand (int i)
9097{
9098 unsigned int value = inst.reloc.exp.X_add_number;
9099 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 9100
9c3c69f2
PB
9101 constraint (inst.operands[i].immisreg,
9102 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
9103 inst.instruction |= inst.operands[i].reg;
9104 if (shift == SHIFT_RRX)
9105 inst.instruction |= SHIFT_ROR << 4;
9106 else
b99bd4ef 9107 {
c19d1205
ZW
9108 constraint (inst.reloc.exp.X_op != O_constant,
9109 _("expression too complex"));
9110
9111 constraint (value > 32
9112 || (value == 32 && (shift == SHIFT_LSL
9113 || shift == SHIFT_ROR)),
9114 _("shift expression is too large"));
9115
9116 if (value == 0)
9117 shift = SHIFT_LSL;
9118 else if (value == 32)
9119 value = 0;
9120
9121 inst.instruction |= shift << 4;
9122 inst.instruction |= (value & 0x1c) << 10;
9123 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 9124 }
c19d1205 9125}
b99bd4ef 9126
b99bd4ef 9127
c19d1205
ZW
9128/* inst.operands[i] was set up by parse_address. Encode it into a
9129 Thumb32 format load or store instruction. Reject forms that cannot
9130 be used with such instructions. If is_t is true, reject forms that
9131 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
9132 that cannot be used with a D instruction. If it is a store insn,
9133 reject PC in Rn. */
b99bd4ef 9134
c19d1205
ZW
9135static void
9136encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
9137{
5be8be5d 9138 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
9139
9140 constraint (!inst.operands[i].isreg,
53365c0d 9141 _("Instruction does not support =N addresses"));
b99bd4ef 9142
c19d1205
ZW
9143 inst.instruction |= inst.operands[i].reg << 16;
9144 if (inst.operands[i].immisreg)
b99bd4ef 9145 {
5be8be5d 9146 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
9147 constraint (is_t || is_d, _("cannot use register index with this instruction"));
9148 constraint (inst.operands[i].negative,
9149 _("Thumb does not support negative register indexing"));
9150 constraint (inst.operands[i].postind,
9151 _("Thumb does not support register post-indexing"));
9152 constraint (inst.operands[i].writeback,
9153 _("Thumb does not support register indexing with writeback"));
9154 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
9155 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 9156
f40d1643 9157 inst.instruction |= inst.operands[i].imm;
c19d1205 9158 if (inst.operands[i].shifted)
b99bd4ef 9159 {
c19d1205
ZW
9160 constraint (inst.reloc.exp.X_op != O_constant,
9161 _("expression too complex"));
9c3c69f2
PB
9162 constraint (inst.reloc.exp.X_add_number < 0
9163 || inst.reloc.exp.X_add_number > 3,
c19d1205 9164 _("shift out of range"));
9c3c69f2 9165 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
9166 }
9167 inst.reloc.type = BFD_RELOC_UNUSED;
9168 }
9169 else if (inst.operands[i].preind)
9170 {
5be8be5d 9171 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 9172 constraint (is_t && inst.operands[i].writeback,
c19d1205 9173 _("cannot use writeback with this instruction"));
5be8be5d
DG
9174 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
9175 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
c19d1205
ZW
9176
9177 if (is_d)
9178 {
9179 inst.instruction |= 0x01000000;
9180 if (inst.operands[i].writeback)
9181 inst.instruction |= 0x00200000;
b99bd4ef 9182 }
c19d1205 9183 else
b99bd4ef 9184 {
c19d1205
ZW
9185 inst.instruction |= 0x00000c00;
9186 if (inst.operands[i].writeback)
9187 inst.instruction |= 0x00000100;
b99bd4ef 9188 }
c19d1205 9189 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 9190 }
c19d1205 9191 else if (inst.operands[i].postind)
b99bd4ef 9192 {
9c2799c2 9193 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
9194 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
9195 constraint (is_t, _("cannot use post-indexing with this instruction"));
9196
9197 if (is_d)
9198 inst.instruction |= 0x00200000;
9199 else
9200 inst.instruction |= 0x00000900;
9201 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9202 }
9203 else /* unindexed - only for coprocessor */
9204 inst.error = _("instruction does not accept unindexed addressing");
9205}
9206
9207/* Table of Thumb instructions which exist in both 16- and 32-bit
9208 encodings (the latter only in post-V6T2 cores). The index is the
9209 value used in the insns table below. When there is more than one
9210 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
9211 holds variant (1).
9212 Also contains several pseudo-instructions used during relaxation. */
c19d1205 9213#define T16_32_TAB \
21d799b5
NC
9214 X(_adc, 4140, eb400000), \
9215 X(_adcs, 4140, eb500000), \
9216 X(_add, 1c00, eb000000), \
9217 X(_adds, 1c00, eb100000), \
9218 X(_addi, 0000, f1000000), \
9219 X(_addis, 0000, f1100000), \
9220 X(_add_pc,000f, f20f0000), \
9221 X(_add_sp,000d, f10d0000), \
9222 X(_adr, 000f, f20f0000), \
9223 X(_and, 4000, ea000000), \
9224 X(_ands, 4000, ea100000), \
9225 X(_asr, 1000, fa40f000), \
9226 X(_asrs, 1000, fa50f000), \
9227 X(_b, e000, f000b000), \
9228 X(_bcond, d000, f0008000), \
9229 X(_bic, 4380, ea200000), \
9230 X(_bics, 4380, ea300000), \
9231 X(_cmn, 42c0, eb100f00), \
9232 X(_cmp, 2800, ebb00f00), \
9233 X(_cpsie, b660, f3af8400), \
9234 X(_cpsid, b670, f3af8600), \
9235 X(_cpy, 4600, ea4f0000), \
9236 X(_dec_sp,80dd, f1ad0d00), \
9237 X(_eor, 4040, ea800000), \
9238 X(_eors, 4040, ea900000), \
9239 X(_inc_sp,00dd, f10d0d00), \
9240 X(_ldmia, c800, e8900000), \
9241 X(_ldr, 6800, f8500000), \
9242 X(_ldrb, 7800, f8100000), \
9243 X(_ldrh, 8800, f8300000), \
9244 X(_ldrsb, 5600, f9100000), \
9245 X(_ldrsh, 5e00, f9300000), \
9246 X(_ldr_pc,4800, f85f0000), \
9247 X(_ldr_pc2,4800, f85f0000), \
9248 X(_ldr_sp,9800, f85d0000), \
9249 X(_lsl, 0000, fa00f000), \
9250 X(_lsls, 0000, fa10f000), \
9251 X(_lsr, 0800, fa20f000), \
9252 X(_lsrs, 0800, fa30f000), \
9253 X(_mov, 2000, ea4f0000), \
9254 X(_movs, 2000, ea5f0000), \
9255 X(_mul, 4340, fb00f000), \
9256 X(_muls, 4340, ffffffff), /* no 32b muls */ \
9257 X(_mvn, 43c0, ea6f0000), \
9258 X(_mvns, 43c0, ea7f0000), \
9259 X(_neg, 4240, f1c00000), /* rsb #0 */ \
9260 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
9261 X(_orr, 4300, ea400000), \
9262 X(_orrs, 4300, ea500000), \
9263 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9264 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9265 X(_rev, ba00, fa90f080), \
9266 X(_rev16, ba40, fa90f090), \
9267 X(_revsh, bac0, fa90f0b0), \
9268 X(_ror, 41c0, fa60f000), \
9269 X(_rors, 41c0, fa70f000), \
9270 X(_sbc, 4180, eb600000), \
9271 X(_sbcs, 4180, eb700000), \
9272 X(_stmia, c000, e8800000), \
9273 X(_str, 6000, f8400000), \
9274 X(_strb, 7000, f8000000), \
9275 X(_strh, 8000, f8200000), \
9276 X(_str_sp,9000, f84d0000), \
9277 X(_sub, 1e00, eba00000), \
9278 X(_subs, 1e00, ebb00000), \
9279 X(_subi, 8000, f1a00000), \
9280 X(_subis, 8000, f1b00000), \
9281 X(_sxtb, b240, fa4ff080), \
9282 X(_sxth, b200, fa0ff080), \
9283 X(_tst, 4200, ea100f00), \
9284 X(_uxtb, b2c0, fa5ff080), \
9285 X(_uxth, b280, fa1ff080), \
9286 X(_nop, bf00, f3af8000), \
9287 X(_yield, bf10, f3af8001), \
9288 X(_wfe, bf20, f3af8002), \
9289 X(_wfi, bf30, f3af8003), \
9290 X(_sev, bf40, f3af8004),
c19d1205
ZW
9291
9292/* To catch errors in encoding functions, the codes are all offset by
9293 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9294 as 16-bit instructions. */
21d799b5 9295#define X(a,b,c) T_MNEM##a
c19d1205
ZW
9296enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9297#undef X
9298
9299#define X(a,b,c) 0x##b
9300static const unsigned short thumb_op16[] = { T16_32_TAB };
9301#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9302#undef X
9303
9304#define X(a,b,c) 0x##c
9305static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
9306#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9307#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
9308#undef X
9309#undef T16_32_TAB
9310
9311/* Thumb instruction encoders, in alphabetical order. */
9312
92e90b6e 9313/* ADDW or SUBW. */
c921be7d 9314
92e90b6e
PB
9315static void
9316do_t_add_sub_w (void)
9317{
9318 int Rd, Rn;
9319
9320 Rd = inst.operands[0].reg;
9321 Rn = inst.operands[1].reg;
9322
539d4391
NC
9323 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9324 is the SP-{plus,minus}-immediate form of the instruction. */
9325 if (Rn == REG_SP)
9326 constraint (Rd == REG_PC, BAD_PC);
9327 else
9328 reject_bad_reg (Rd);
fdfde340 9329
92e90b6e
PB
9330 inst.instruction |= (Rn << 16) | (Rd << 8);
9331 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9332}
9333
c19d1205
ZW
9334/* Parse an add or subtract instruction. We get here with inst.instruction
9335 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9336
9337static void
9338do_t_add_sub (void)
9339{
9340 int Rd, Rs, Rn;
9341
9342 Rd = inst.operands[0].reg;
9343 Rs = (inst.operands[1].present
9344 ? inst.operands[1].reg /* Rd, Rs, foo */
9345 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9346
e07e6e58
NC
9347 if (Rd == REG_PC)
9348 set_it_insn_type_last ();
9349
c19d1205
ZW
9350 if (unified_syntax)
9351 {
0110f2b8
PB
9352 bfd_boolean flags;
9353 bfd_boolean narrow;
9354 int opcode;
9355
9356 flags = (inst.instruction == T_MNEM_adds
9357 || inst.instruction == T_MNEM_subs);
9358 if (flags)
e07e6e58 9359 narrow = !in_it_block ();
0110f2b8 9360 else
e07e6e58 9361 narrow = in_it_block ();
c19d1205 9362 if (!inst.operands[2].isreg)
b99bd4ef 9363 {
16805f35
PB
9364 int add;
9365
fdfde340
JM
9366 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9367
16805f35
PB
9368 add = (inst.instruction == T_MNEM_add
9369 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
9370 opcode = 0;
9371 if (inst.size_req != 4)
9372 {
0110f2b8
PB
9373 /* Attempt to use a narrow opcode, with relaxation if
9374 appropriate. */
9375 if (Rd == REG_SP && Rs == REG_SP && !flags)
9376 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9377 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9378 opcode = T_MNEM_add_sp;
9379 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9380 opcode = T_MNEM_add_pc;
9381 else if (Rd <= 7 && Rs <= 7 && narrow)
9382 {
9383 if (flags)
9384 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9385 else
9386 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9387 }
9388 if (opcode)
9389 {
9390 inst.instruction = THUMB_OP16(opcode);
9391 inst.instruction |= (Rd << 4) | Rs;
9392 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9393 if (inst.size_req != 2)
9394 inst.relax = opcode;
9395 }
9396 else
9397 constraint (inst.size_req == 2, BAD_HIREG);
9398 }
9399 if (inst.size_req == 4
9400 || (inst.size_req != 2 && !opcode))
9401 {
efd81785
PB
9402 if (Rd == REG_PC)
9403 {
fdfde340 9404 constraint (add, BAD_PC);
efd81785
PB
9405 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9406 _("only SUBS PC, LR, #const allowed"));
9407 constraint (inst.reloc.exp.X_op != O_constant,
9408 _("expression too complex"));
9409 constraint (inst.reloc.exp.X_add_number < 0
9410 || inst.reloc.exp.X_add_number > 0xff,
9411 _("immediate value out of range"));
9412 inst.instruction = T2_SUBS_PC_LR
9413 | inst.reloc.exp.X_add_number;
9414 inst.reloc.type = BFD_RELOC_UNUSED;
9415 return;
9416 }
9417 else if (Rs == REG_PC)
16805f35
PB
9418 {
9419 /* Always use addw/subw. */
9420 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9421 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9422 }
9423 else
9424 {
9425 inst.instruction = THUMB_OP32 (inst.instruction);
9426 inst.instruction = (inst.instruction & 0xe1ffffff)
9427 | 0x10000000;
9428 if (flags)
9429 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9430 else
9431 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9432 }
dc4503c6
PB
9433 inst.instruction |= Rd << 8;
9434 inst.instruction |= Rs << 16;
0110f2b8 9435 }
b99bd4ef 9436 }
c19d1205
ZW
9437 else
9438 {
9439 Rn = inst.operands[2].reg;
9440 /* See if we can do this with a 16-bit instruction. */
9441 if (!inst.operands[2].shifted && inst.size_req != 4)
9442 {
e27ec89e
PB
9443 if (Rd > 7 || Rs > 7 || Rn > 7)
9444 narrow = FALSE;
9445
9446 if (narrow)
c19d1205 9447 {
e27ec89e
PB
9448 inst.instruction = ((inst.instruction == T_MNEM_adds
9449 || inst.instruction == T_MNEM_add)
c19d1205
ZW
9450 ? T_OPCODE_ADD_R3
9451 : T_OPCODE_SUB_R3);
9452 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9453 return;
9454 }
b99bd4ef 9455
7e806470 9456 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 9457 {
7e806470
PB
9458 /* Thumb-1 cores (except v6-M) require at least one high
9459 register in a narrow non flag setting add. */
9460 if (Rd > 7 || Rn > 7
9461 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9462 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9463 {
7e806470
PB
9464 if (Rd == Rn)
9465 {
9466 Rn = Rs;
9467 Rs = Rd;
9468 }
c19d1205
ZW
9469 inst.instruction = T_OPCODE_ADD_HI;
9470 inst.instruction |= (Rd & 8) << 4;
9471 inst.instruction |= (Rd & 7);
9472 inst.instruction |= Rn << 3;
9473 return;
9474 }
c19d1205
ZW
9475 }
9476 }
c921be7d 9477
fdfde340
JM
9478 constraint (Rd == REG_PC, BAD_PC);
9479 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9480 constraint (Rs == REG_PC, BAD_PC);
9481 reject_bad_reg (Rn);
9482
c19d1205
ZW
9483 /* If we get here, it can't be done in 16 bits. */
9484 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9485 _("shift must be constant"));
9486 inst.instruction = THUMB_OP32 (inst.instruction);
9487 inst.instruction |= Rd << 8;
9488 inst.instruction |= Rs << 16;
9489 encode_thumb32_shifted_operand (2);
9490 }
9491 }
9492 else
9493 {
9494 constraint (inst.instruction == T_MNEM_adds
9495 || inst.instruction == T_MNEM_subs,
9496 BAD_THUMB32);
b99bd4ef 9497
c19d1205 9498 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9499 {
c19d1205
ZW
9500 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9501 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9502 BAD_HIREG);
9503
9504 inst.instruction = (inst.instruction == T_MNEM_add
9505 ? 0x0000 : 0x8000);
9506 inst.instruction |= (Rd << 4) | Rs;
9507 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9508 return;
9509 }
9510
c19d1205
ZW
9511 Rn = inst.operands[2].reg;
9512 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9513
c19d1205
ZW
9514 /* We now have Rd, Rs, and Rn set to registers. */
9515 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9516 {
c19d1205
ZW
9517 /* Can't do this for SUB. */
9518 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9519 inst.instruction = T_OPCODE_ADD_HI;
9520 inst.instruction |= (Rd & 8) << 4;
9521 inst.instruction |= (Rd & 7);
9522 if (Rs == Rd)
9523 inst.instruction |= Rn << 3;
9524 else if (Rn == Rd)
9525 inst.instruction |= Rs << 3;
9526 else
9527 constraint (1, _("dest must overlap one source register"));
9528 }
9529 else
9530 {
9531 inst.instruction = (inst.instruction == T_MNEM_add
9532 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9533 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9534 }
b99bd4ef 9535 }
b99bd4ef
NC
9536}
9537
c19d1205
ZW
9538static void
9539do_t_adr (void)
9540{
fdfde340
JM
9541 unsigned Rd;
9542
9543 Rd = inst.operands[0].reg;
9544 reject_bad_reg (Rd);
9545
9546 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9547 {
9548 /* Defer to section relaxation. */
9549 inst.relax = inst.instruction;
9550 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9551 inst.instruction |= Rd << 4;
0110f2b8
PB
9552 }
9553 else if (unified_syntax && inst.size_req != 2)
e9f89963 9554 {
0110f2b8 9555 /* Generate a 32-bit opcode. */
e9f89963 9556 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9557 inst.instruction |= Rd << 8;
e9f89963
PB
9558 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9559 inst.reloc.pc_rel = 1;
9560 }
9561 else
9562 {
0110f2b8 9563 /* Generate a 16-bit opcode. */
e9f89963
PB
9564 inst.instruction = THUMB_OP16 (inst.instruction);
9565 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9566 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9567 inst.reloc.pc_rel = 1;
b99bd4ef 9568
fdfde340 9569 inst.instruction |= Rd << 4;
e9f89963 9570 }
c19d1205 9571}
b99bd4ef 9572
c19d1205
ZW
9573/* Arithmetic instructions for which there is just one 16-bit
9574 instruction encoding, and it allows only two low registers.
9575 For maximal compatibility with ARM syntax, we allow three register
9576 operands even when Thumb-32 instructions are not available, as long
9577 as the first two are identical. For instance, both "sbc r0,r1" and
9578 "sbc r0,r0,r1" are allowed. */
b99bd4ef 9579static void
c19d1205 9580do_t_arit3 (void)
b99bd4ef 9581{
c19d1205 9582 int Rd, Rs, Rn;
b99bd4ef 9583
c19d1205
ZW
9584 Rd = inst.operands[0].reg;
9585 Rs = (inst.operands[1].present
9586 ? inst.operands[1].reg /* Rd, Rs, foo */
9587 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9588 Rn = inst.operands[2].reg;
b99bd4ef 9589
fdfde340
JM
9590 reject_bad_reg (Rd);
9591 reject_bad_reg (Rs);
9592 if (inst.operands[2].isreg)
9593 reject_bad_reg (Rn);
9594
c19d1205 9595 if (unified_syntax)
b99bd4ef 9596 {
c19d1205
ZW
9597 if (!inst.operands[2].isreg)
9598 {
9599 /* For an immediate, we always generate a 32-bit opcode;
9600 section relaxation will shrink it later if possible. */
9601 inst.instruction = THUMB_OP32 (inst.instruction);
9602 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9603 inst.instruction |= Rd << 8;
9604 inst.instruction |= Rs << 16;
9605 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9606 }
9607 else
9608 {
e27ec89e
PB
9609 bfd_boolean narrow;
9610
c19d1205 9611 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9612 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9613 narrow = !in_it_block ();
e27ec89e 9614 else
e07e6e58 9615 narrow = in_it_block ();
e27ec89e
PB
9616
9617 if (Rd > 7 || Rn > 7 || Rs > 7)
9618 narrow = FALSE;
9619 if (inst.operands[2].shifted)
9620 narrow = FALSE;
9621 if (inst.size_req == 4)
9622 narrow = FALSE;
9623
9624 if (narrow
c19d1205
ZW
9625 && Rd == Rs)
9626 {
9627 inst.instruction = THUMB_OP16 (inst.instruction);
9628 inst.instruction |= Rd;
9629 inst.instruction |= Rn << 3;
9630 return;
9631 }
b99bd4ef 9632
c19d1205
ZW
9633 /* If we get here, it can't be done in 16 bits. */
9634 constraint (inst.operands[2].shifted
9635 && inst.operands[2].immisreg,
9636 _("shift must be constant"));
9637 inst.instruction = THUMB_OP32 (inst.instruction);
9638 inst.instruction |= Rd << 8;
9639 inst.instruction |= Rs << 16;
9640 encode_thumb32_shifted_operand (2);
9641 }
a737bd4d 9642 }
c19d1205 9643 else
b99bd4ef 9644 {
c19d1205
ZW
9645 /* On its face this is a lie - the instruction does set the
9646 flags. However, the only supported mnemonic in this mode
9647 says it doesn't. */
9648 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9649
c19d1205
ZW
9650 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9651 _("unshifted register required"));
9652 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9653 constraint (Rd != Rs,
9654 _("dest and source1 must be the same register"));
a737bd4d 9655
c19d1205
ZW
9656 inst.instruction = THUMB_OP16 (inst.instruction);
9657 inst.instruction |= Rd;
9658 inst.instruction |= Rn << 3;
b99bd4ef 9659 }
a737bd4d 9660}
b99bd4ef 9661
c19d1205
ZW
9662/* Similarly, but for instructions where the arithmetic operation is
9663 commutative, so we can allow either of them to be different from
9664 the destination operand in a 16-bit instruction. For instance, all
9665 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9666 accepted. */
9667static void
9668do_t_arit3c (void)
a737bd4d 9669{
c19d1205 9670 int Rd, Rs, Rn;
b99bd4ef 9671
c19d1205
ZW
9672 Rd = inst.operands[0].reg;
9673 Rs = (inst.operands[1].present
9674 ? inst.operands[1].reg /* Rd, Rs, foo */
9675 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9676 Rn = inst.operands[2].reg;
c921be7d 9677
fdfde340
JM
9678 reject_bad_reg (Rd);
9679 reject_bad_reg (Rs);
9680 if (inst.operands[2].isreg)
9681 reject_bad_reg (Rn);
a737bd4d 9682
c19d1205 9683 if (unified_syntax)
a737bd4d 9684 {
c19d1205 9685 if (!inst.operands[2].isreg)
b99bd4ef 9686 {
c19d1205
ZW
9687 /* For an immediate, we always generate a 32-bit opcode;
9688 section relaxation will shrink it later if possible. */
9689 inst.instruction = THUMB_OP32 (inst.instruction);
9690 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9691 inst.instruction |= Rd << 8;
9692 inst.instruction |= Rs << 16;
9693 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9694 }
c19d1205 9695 else
a737bd4d 9696 {
e27ec89e
PB
9697 bfd_boolean narrow;
9698
c19d1205 9699 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9700 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9701 narrow = !in_it_block ();
e27ec89e 9702 else
e07e6e58 9703 narrow = in_it_block ();
e27ec89e
PB
9704
9705 if (Rd > 7 || Rn > 7 || Rs > 7)
9706 narrow = FALSE;
9707 if (inst.operands[2].shifted)
9708 narrow = FALSE;
9709 if (inst.size_req == 4)
9710 narrow = FALSE;
9711
9712 if (narrow)
a737bd4d 9713 {
c19d1205 9714 if (Rd == Rs)
a737bd4d 9715 {
c19d1205
ZW
9716 inst.instruction = THUMB_OP16 (inst.instruction);
9717 inst.instruction |= Rd;
9718 inst.instruction |= Rn << 3;
9719 return;
a737bd4d 9720 }
c19d1205 9721 if (Rd == Rn)
a737bd4d 9722 {
c19d1205
ZW
9723 inst.instruction = THUMB_OP16 (inst.instruction);
9724 inst.instruction |= Rd;
9725 inst.instruction |= Rs << 3;
9726 return;
a737bd4d
NC
9727 }
9728 }
c19d1205
ZW
9729
9730 /* If we get here, it can't be done in 16 bits. */
9731 constraint (inst.operands[2].shifted
9732 && inst.operands[2].immisreg,
9733 _("shift must be constant"));
9734 inst.instruction = THUMB_OP32 (inst.instruction);
9735 inst.instruction |= Rd << 8;
9736 inst.instruction |= Rs << 16;
9737 encode_thumb32_shifted_operand (2);
a737bd4d 9738 }
b99bd4ef 9739 }
c19d1205
ZW
9740 else
9741 {
9742 /* On its face this is a lie - the instruction does set the
9743 flags. However, the only supported mnemonic in this mode
9744 says it doesn't. */
9745 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9746
c19d1205
ZW
9747 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9748 _("unshifted register required"));
9749 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9750
9751 inst.instruction = THUMB_OP16 (inst.instruction);
9752 inst.instruction |= Rd;
9753
9754 if (Rd == Rs)
9755 inst.instruction |= Rn << 3;
9756 else if (Rd == Rn)
9757 inst.instruction |= Rs << 3;
9758 else
9759 constraint (1, _("dest must overlap one source register"));
9760 }
a737bd4d
NC
9761}
9762
62b3e311
PB
9763static void
9764do_t_barrier (void)
9765{
9766 if (inst.operands[0].present)
9767 {
9768 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
9769 && inst.operands[0].imm > 0xf
9770 && inst.operands[0].imm < 0x0,
bd3ba5d1 9771 _("bad barrier type"));
62b3e311
PB
9772 inst.instruction |= inst.operands[0].imm;
9773 }
9774 else
9775 inst.instruction |= 0xf;
9776}
9777
c19d1205
ZW
9778static void
9779do_t_bfc (void)
a737bd4d 9780{
fdfde340 9781 unsigned Rd;
c19d1205
ZW
9782 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9783 constraint (msb > 32, _("bit-field extends past end of register"));
9784 /* The instruction encoding stores the LSB and MSB,
9785 not the LSB and width. */
fdfde340
JM
9786 Rd = inst.operands[0].reg;
9787 reject_bad_reg (Rd);
9788 inst.instruction |= Rd << 8;
c19d1205
ZW
9789 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9790 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9791 inst.instruction |= msb - 1;
b99bd4ef
NC
9792}
9793
c19d1205
ZW
9794static void
9795do_t_bfi (void)
b99bd4ef 9796{
fdfde340 9797 int Rd, Rn;
c19d1205 9798 unsigned int msb;
b99bd4ef 9799
fdfde340
JM
9800 Rd = inst.operands[0].reg;
9801 reject_bad_reg (Rd);
9802
c19d1205
ZW
9803 /* #0 in second position is alternative syntax for bfc, which is
9804 the same instruction but with REG_PC in the Rm field. */
9805 if (!inst.operands[1].isreg)
fdfde340
JM
9806 Rn = REG_PC;
9807 else
9808 {
9809 Rn = inst.operands[1].reg;
9810 reject_bad_reg (Rn);
9811 }
b99bd4ef 9812
c19d1205
ZW
9813 msb = inst.operands[2].imm + inst.operands[3].imm;
9814 constraint (msb > 32, _("bit-field extends past end of register"));
9815 /* The instruction encoding stores the LSB and MSB,
9816 not the LSB and width. */
fdfde340
JM
9817 inst.instruction |= Rd << 8;
9818 inst.instruction |= Rn << 16;
c19d1205
ZW
9819 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9820 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9821 inst.instruction |= msb - 1;
b99bd4ef
NC
9822}
9823
c19d1205
ZW
9824static void
9825do_t_bfx (void)
b99bd4ef 9826{
fdfde340
JM
9827 unsigned Rd, Rn;
9828
9829 Rd = inst.operands[0].reg;
9830 Rn = inst.operands[1].reg;
9831
9832 reject_bad_reg (Rd);
9833 reject_bad_reg (Rn);
9834
c19d1205
ZW
9835 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9836 _("bit-field extends past end of register"));
fdfde340
JM
9837 inst.instruction |= Rd << 8;
9838 inst.instruction |= Rn << 16;
c19d1205
ZW
9839 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9840 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9841 inst.instruction |= inst.operands[3].imm - 1;
9842}
b99bd4ef 9843
c19d1205
ZW
9844/* ARM V5 Thumb BLX (argument parse)
9845 BLX <target_addr> which is BLX(1)
9846 BLX <Rm> which is BLX(2)
9847 Unfortunately, there are two different opcodes for this mnemonic.
9848 So, the insns[].value is not used, and the code here zaps values
9849 into inst.instruction.
b99bd4ef 9850
c19d1205
ZW
9851 ??? How to take advantage of the additional two bits of displacement
9852 available in Thumb32 mode? Need new relocation? */
b99bd4ef 9853
c19d1205
ZW
9854static void
9855do_t_blx (void)
9856{
e07e6e58
NC
9857 set_it_insn_type_last ();
9858
c19d1205 9859 if (inst.operands[0].isreg)
fdfde340
JM
9860 {
9861 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9862 /* We have a register, so this is BLX(2). */
9863 inst.instruction |= inst.operands[0].reg << 3;
9864 }
b99bd4ef
NC
9865 else
9866 {
c19d1205 9867 /* No register. This must be BLX(1). */
2fc8bdac 9868 inst.instruction = 0xf000e800;
0855e32b 9869 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
9870 }
9871}
9872
c19d1205
ZW
9873static void
9874do_t_branch (void)
b99bd4ef 9875{
0110f2b8 9876 int opcode;
dfa9f0d5 9877 int cond;
9ae92b05 9878 int reloc;
dfa9f0d5 9879
e07e6e58
NC
9880 cond = inst.cond;
9881 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9882
9883 if (in_it_block ())
dfa9f0d5
PB
9884 {
9885 /* Conditional branches inside IT blocks are encoded as unconditional
9886 branches. */
9887 cond = COND_ALWAYS;
dfa9f0d5
PB
9888 }
9889 else
9890 cond = inst.cond;
9891
9892 if (cond != COND_ALWAYS)
0110f2b8
PB
9893 opcode = T_MNEM_bcond;
9894 else
9895 opcode = inst.instruction;
9896
12d6b0b7
RS
9897 if (unified_syntax
9898 && (inst.size_req == 4
10960bfb
PB
9899 || (inst.size_req != 2
9900 && (inst.operands[0].hasreloc
9901 || inst.reloc.exp.X_op == O_constant))))
c19d1205 9902 {
0110f2b8 9903 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9904 if (cond == COND_ALWAYS)
9ae92b05 9905 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9906 else
9907 {
9c2799c2 9908 gas_assert (cond != 0xF);
dfa9f0d5 9909 inst.instruction |= cond << 22;
9ae92b05 9910 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
9911 }
9912 }
b99bd4ef
NC
9913 else
9914 {
0110f2b8 9915 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9916 if (cond == COND_ALWAYS)
9ae92b05 9917 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 9918 else
b99bd4ef 9919 {
dfa9f0d5 9920 inst.instruction |= cond << 8;
9ae92b05 9921 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9922 }
0110f2b8
PB
9923 /* Allow section relaxation. */
9924 if (unified_syntax && inst.size_req != 2)
9925 inst.relax = opcode;
b99bd4ef 9926 }
9ae92b05 9927 inst.reloc.type = reloc;
c19d1205 9928 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9929}
9930
9931static void
c19d1205 9932do_t_bkpt (void)
b99bd4ef 9933{
dfa9f0d5
PB
9934 constraint (inst.cond != COND_ALWAYS,
9935 _("instruction is always unconditional"));
c19d1205 9936 if (inst.operands[0].present)
b99bd4ef 9937 {
c19d1205
ZW
9938 constraint (inst.operands[0].imm > 255,
9939 _("immediate value out of range"));
9940 inst.instruction |= inst.operands[0].imm;
e07e6e58 9941 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 9942 }
b99bd4ef
NC
9943}
9944
9945static void
c19d1205 9946do_t_branch23 (void)
b99bd4ef 9947{
e07e6e58 9948 set_it_insn_type_last ();
0855e32b
NS
9949 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
9950
9951 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
9952 this file. We used to simply ignore the PLT reloc type here --
9953 the branch encoding is now needed to deal with TLSCALL relocs.
9954 So if we see a PLT reloc now, put it back to how it used to be to
9955 keep the preexisting behaviour. */
9956 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
9957 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 9958
4343666d 9959#if defined(OBJ_COFF)
c19d1205
ZW
9960 /* If the destination of the branch is a defined symbol which does not have
9961 the THUMB_FUNC attribute, then we must be calling a function which has
9962 the (interfacearm) attribute. We look for the Thumb entry point to that
9963 function and change the branch to refer to that function instead. */
9964 if ( inst.reloc.exp.X_op == O_symbol
9965 && inst.reloc.exp.X_add_symbol != NULL
9966 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9967 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9968 inst.reloc.exp.X_add_symbol =
9969 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 9970#endif
90e4755a
RE
9971}
9972
9973static void
c19d1205 9974do_t_bx (void)
90e4755a 9975{
e07e6e58 9976 set_it_insn_type_last ();
c19d1205
ZW
9977 inst.instruction |= inst.operands[0].reg << 3;
9978 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9979 should cause the alignment to be checked once it is known. This is
9980 because BX PC only works if the instruction is word aligned. */
9981}
90e4755a 9982
c19d1205
ZW
9983static void
9984do_t_bxj (void)
9985{
fdfde340 9986 int Rm;
90e4755a 9987
e07e6e58 9988 set_it_insn_type_last ();
fdfde340
JM
9989 Rm = inst.operands[0].reg;
9990 reject_bad_reg (Rm);
9991 inst.instruction |= Rm << 16;
90e4755a
RE
9992}
9993
9994static void
c19d1205 9995do_t_clz (void)
90e4755a 9996{
fdfde340
JM
9997 unsigned Rd;
9998 unsigned Rm;
9999
10000 Rd = inst.operands[0].reg;
10001 Rm = inst.operands[1].reg;
10002
10003 reject_bad_reg (Rd);
10004 reject_bad_reg (Rm);
10005
10006 inst.instruction |= Rd << 8;
10007 inst.instruction |= Rm << 16;
10008 inst.instruction |= Rm;
c19d1205 10009}
90e4755a 10010
dfa9f0d5
PB
10011static void
10012do_t_cps (void)
10013{
e07e6e58 10014 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
10015 inst.instruction |= inst.operands[0].imm;
10016}
10017
c19d1205
ZW
10018static void
10019do_t_cpsi (void)
10020{
e07e6e58 10021 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 10022 if (unified_syntax
62b3e311
PB
10023 && (inst.operands[1].present || inst.size_req == 4)
10024 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 10025 {
c19d1205
ZW
10026 unsigned int imod = (inst.instruction & 0x0030) >> 4;
10027 inst.instruction = 0xf3af8000;
10028 inst.instruction |= imod << 9;
10029 inst.instruction |= inst.operands[0].imm << 5;
10030 if (inst.operands[1].present)
10031 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 10032 }
c19d1205 10033 else
90e4755a 10034 {
62b3e311
PB
10035 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
10036 && (inst.operands[0].imm & 4),
10037 _("selected processor does not support 'A' form "
10038 "of this instruction"));
10039 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
10040 _("Thumb does not support the 2-argument "
10041 "form of this instruction"));
10042 inst.instruction |= inst.operands[0].imm;
90e4755a 10043 }
90e4755a
RE
10044}
10045
c19d1205
ZW
10046/* THUMB CPY instruction (argument parse). */
10047
90e4755a 10048static void
c19d1205 10049do_t_cpy (void)
90e4755a 10050{
c19d1205 10051 if (inst.size_req == 4)
90e4755a 10052 {
c19d1205
ZW
10053 inst.instruction = THUMB_OP32 (T_MNEM_mov);
10054 inst.instruction |= inst.operands[0].reg << 8;
10055 inst.instruction |= inst.operands[1].reg;
90e4755a 10056 }
c19d1205 10057 else
90e4755a 10058 {
c19d1205
ZW
10059 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
10060 inst.instruction |= (inst.operands[0].reg & 0x7);
10061 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 10062 }
90e4755a
RE
10063}
10064
90e4755a 10065static void
25fe350b 10066do_t_cbz (void)
90e4755a 10067{
e07e6e58 10068 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
10069 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10070 inst.instruction |= inst.operands[0].reg;
10071 inst.reloc.pc_rel = 1;
10072 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
10073}
90e4755a 10074
62b3e311
PB
10075static void
10076do_t_dbg (void)
10077{
10078 inst.instruction |= inst.operands[0].imm;
10079}
10080
10081static void
10082do_t_div (void)
10083{
fdfde340
JM
10084 unsigned Rd, Rn, Rm;
10085
10086 Rd = inst.operands[0].reg;
10087 Rn = (inst.operands[1].present
10088 ? inst.operands[1].reg : Rd);
10089 Rm = inst.operands[2].reg;
10090
10091 reject_bad_reg (Rd);
10092 reject_bad_reg (Rn);
10093 reject_bad_reg (Rm);
10094
10095 inst.instruction |= Rd << 8;
10096 inst.instruction |= Rn << 16;
10097 inst.instruction |= Rm;
62b3e311
PB
10098}
10099
c19d1205
ZW
10100static void
10101do_t_hint (void)
10102{
10103 if (unified_syntax && inst.size_req == 4)
10104 inst.instruction = THUMB_OP32 (inst.instruction);
10105 else
10106 inst.instruction = THUMB_OP16 (inst.instruction);
10107}
90e4755a 10108
c19d1205
ZW
10109static void
10110do_t_it (void)
10111{
10112 unsigned int cond = inst.operands[0].imm;
e27ec89e 10113
e07e6e58
NC
10114 set_it_insn_type (IT_INSN);
10115 now_it.mask = (inst.instruction & 0xf) | 0x10;
10116 now_it.cc = cond;
e27ec89e
PB
10117
10118 /* If the condition is a negative condition, invert the mask. */
c19d1205 10119 if ((cond & 0x1) == 0x0)
90e4755a 10120 {
c19d1205 10121 unsigned int mask = inst.instruction & 0x000f;
90e4755a 10122
c19d1205
ZW
10123 if ((mask & 0x7) == 0)
10124 /* no conversion needed */;
10125 else if ((mask & 0x3) == 0)
e27ec89e
PB
10126 mask ^= 0x8;
10127 else if ((mask & 0x1) == 0)
10128 mask ^= 0xC;
c19d1205 10129 else
e27ec89e 10130 mask ^= 0xE;
90e4755a 10131
e27ec89e
PB
10132 inst.instruction &= 0xfff0;
10133 inst.instruction |= mask;
c19d1205 10134 }
90e4755a 10135
c19d1205
ZW
10136 inst.instruction |= cond << 4;
10137}
90e4755a 10138
3c707909
PB
10139/* Helper function used for both push/pop and ldm/stm. */
10140static void
10141encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
10142{
10143 bfd_boolean load;
10144
10145 load = (inst.instruction & (1 << 20)) != 0;
10146
10147 if (mask & (1 << 13))
10148 inst.error = _("SP not allowed in register list");
1e5b0379
NC
10149
10150 if ((mask & (1 << base)) != 0
10151 && writeback)
10152 inst.error = _("having the base register in the register list when "
10153 "using write back is UNPREDICTABLE");
10154
3c707909
PB
10155 if (load)
10156 {
e07e6e58
NC
10157 if (mask & (1 << 15))
10158 {
10159 if (mask & (1 << 14))
10160 inst.error = _("LR and PC should not both be in register list");
10161 else
10162 set_it_insn_type_last ();
10163 }
3c707909
PB
10164 }
10165 else
10166 {
10167 if (mask & (1 << 15))
10168 inst.error = _("PC not allowed in register list");
3c707909
PB
10169 }
10170
10171 if ((mask & (mask - 1)) == 0)
10172 {
10173 /* Single register transfers implemented as str/ldr. */
10174 if (writeback)
10175 {
10176 if (inst.instruction & (1 << 23))
10177 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
10178 else
10179 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
10180 }
10181 else
10182 {
10183 if (inst.instruction & (1 << 23))
10184 inst.instruction = 0x00800000; /* ia -> [base] */
10185 else
10186 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
10187 }
10188
10189 inst.instruction |= 0xf8400000;
10190 if (load)
10191 inst.instruction |= 0x00100000;
10192
5f4273c7 10193 mask = ffs (mask) - 1;
3c707909
PB
10194 mask <<= 12;
10195 }
10196 else if (writeback)
10197 inst.instruction |= WRITE_BACK;
10198
10199 inst.instruction |= mask;
10200 inst.instruction |= base << 16;
10201}
10202
c19d1205
ZW
10203static void
10204do_t_ldmstm (void)
10205{
10206 /* This really doesn't seem worth it. */
10207 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10208 _("expression too complex"));
10209 constraint (inst.operands[1].writeback,
10210 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 10211
c19d1205
ZW
10212 if (unified_syntax)
10213 {
3c707909
PB
10214 bfd_boolean narrow;
10215 unsigned mask;
10216
10217 narrow = FALSE;
c19d1205
ZW
10218 /* See if we can use a 16-bit instruction. */
10219 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
10220 && inst.size_req != 4
3c707909 10221 && !(inst.operands[1].imm & ~0xff))
90e4755a 10222 {
3c707909 10223 mask = 1 << inst.operands[0].reg;
90e4755a 10224
eab4f823 10225 if (inst.operands[0].reg <= 7)
90e4755a 10226 {
3c707909 10227 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
10228 ? inst.operands[0].writeback
10229 : (inst.operands[0].writeback
10230 == !(inst.operands[1].imm & mask)))
10231 {
10232 if (inst.instruction == T_MNEM_stmia
10233 && (inst.operands[1].imm & mask)
10234 && (inst.operands[1].imm & (mask - 1)))
10235 as_warn (_("value stored for r%d is UNKNOWN"),
10236 inst.operands[0].reg);
3c707909 10237
eab4f823
MGD
10238 inst.instruction = THUMB_OP16 (inst.instruction);
10239 inst.instruction |= inst.operands[0].reg << 8;
10240 inst.instruction |= inst.operands[1].imm;
10241 narrow = TRUE;
10242 }
10243 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10244 {
10245 /* This means 1 register in reg list one of 3 situations:
10246 1. Instruction is stmia, but without writeback.
10247 2. lmdia without writeback, but with Rn not in
10248 reglist.
10249 3. ldmia with writeback, but with Rn in reglist.
10250 Case 3 is UNPREDICTABLE behaviour, so we handle
10251 case 1 and 2 which can be converted into a 16-bit
10252 str or ldr. The SP cases are handled below. */
10253 unsigned long opcode;
10254 /* First, record an error for Case 3. */
10255 if (inst.operands[1].imm & mask
10256 && inst.operands[0].writeback)
10257 inst.error =
10258 _("having the base register in the register list when "
10259 "using write back is UNPREDICTABLE");
10260
10261 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
10262 : T_MNEM_ldr);
10263 inst.instruction = THUMB_OP16 (opcode);
10264 inst.instruction |= inst.operands[0].reg << 3;
10265 inst.instruction |= (ffs (inst.operands[1].imm)-1);
10266 narrow = TRUE;
10267 }
90e4755a 10268 }
eab4f823 10269 else if (inst.operands[0] .reg == REG_SP)
90e4755a 10270 {
eab4f823
MGD
10271 if (inst.operands[0].writeback)
10272 {
10273 inst.instruction =
10274 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10275 ? T_MNEM_push : T_MNEM_pop);
10276 inst.instruction |= inst.operands[1].imm;
10277 narrow = TRUE;
10278 }
10279 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10280 {
10281 inst.instruction =
10282 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10283 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10284 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10285 narrow = TRUE;
10286 }
90e4755a 10287 }
3c707909
PB
10288 }
10289
10290 if (!narrow)
10291 {
c19d1205
ZW
10292 if (inst.instruction < 0xffff)
10293 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 10294
5f4273c7
NC
10295 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10296 inst.operands[0].writeback);
90e4755a
RE
10297 }
10298 }
c19d1205 10299 else
90e4755a 10300 {
c19d1205
ZW
10301 constraint (inst.operands[0].reg > 7
10302 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
10303 constraint (inst.instruction != T_MNEM_ldmia
10304 && inst.instruction != T_MNEM_stmia,
10305 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 10306 if (inst.instruction == T_MNEM_stmia)
f03698e6 10307 {
c19d1205
ZW
10308 if (!inst.operands[0].writeback)
10309 as_warn (_("this instruction will write back the base register"));
10310 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10311 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 10312 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 10313 inst.operands[0].reg);
f03698e6 10314 }
c19d1205 10315 else
90e4755a 10316 {
c19d1205
ZW
10317 if (!inst.operands[0].writeback
10318 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10319 as_warn (_("this instruction will write back the base register"));
10320 else if (inst.operands[0].writeback
10321 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10322 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
10323 }
10324
c19d1205
ZW
10325 inst.instruction = THUMB_OP16 (inst.instruction);
10326 inst.instruction |= inst.operands[0].reg << 8;
10327 inst.instruction |= inst.operands[1].imm;
10328 }
10329}
e28cd48c 10330
c19d1205
ZW
10331static void
10332do_t_ldrex (void)
10333{
10334 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10335 || inst.operands[1].postind || inst.operands[1].writeback
10336 || inst.operands[1].immisreg || inst.operands[1].shifted
10337 || inst.operands[1].negative,
01cfc07f 10338 BAD_ADDR_MODE);
e28cd48c 10339
5be8be5d
DG
10340 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10341
c19d1205
ZW
10342 inst.instruction |= inst.operands[0].reg << 12;
10343 inst.instruction |= inst.operands[1].reg << 16;
10344 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10345}
e28cd48c 10346
c19d1205
ZW
10347static void
10348do_t_ldrexd (void)
10349{
10350 if (!inst.operands[1].present)
1cac9012 10351 {
c19d1205
ZW
10352 constraint (inst.operands[0].reg == REG_LR,
10353 _("r14 not allowed as first register "
10354 "when second register is omitted"));
10355 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 10356 }
c19d1205
ZW
10357 constraint (inst.operands[0].reg == inst.operands[1].reg,
10358 BAD_OVERLAP);
b99bd4ef 10359
c19d1205
ZW
10360 inst.instruction |= inst.operands[0].reg << 12;
10361 inst.instruction |= inst.operands[1].reg << 8;
10362 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10363}
10364
10365static void
c19d1205 10366do_t_ldst (void)
b99bd4ef 10367{
0110f2b8
PB
10368 unsigned long opcode;
10369 int Rn;
10370
e07e6e58
NC
10371 if (inst.operands[0].isreg
10372 && !inst.operands[0].preind
10373 && inst.operands[0].reg == REG_PC)
10374 set_it_insn_type_last ();
10375
0110f2b8 10376 opcode = inst.instruction;
c19d1205 10377 if (unified_syntax)
b99bd4ef 10378 {
53365c0d
PB
10379 if (!inst.operands[1].isreg)
10380 {
10381 if (opcode <= 0xffff)
10382 inst.instruction = THUMB_OP32 (opcode);
10383 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10384 return;
10385 }
0110f2b8
PB
10386 if (inst.operands[1].isreg
10387 && !inst.operands[1].writeback
c19d1205
ZW
10388 && !inst.operands[1].shifted && !inst.operands[1].postind
10389 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
10390 && opcode <= 0xffff
10391 && inst.size_req != 4)
c19d1205 10392 {
0110f2b8
PB
10393 /* Insn may have a 16-bit form. */
10394 Rn = inst.operands[1].reg;
10395 if (inst.operands[1].immisreg)
10396 {
10397 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 10398 /* [Rn, Rik] */
0110f2b8
PB
10399 if (Rn <= 7 && inst.operands[1].imm <= 7)
10400 goto op16;
5be8be5d
DG
10401 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10402 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
10403 }
10404 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10405 && opcode != T_MNEM_ldrsb)
10406 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10407 || (Rn == REG_SP && opcode == T_MNEM_str))
10408 {
10409 /* [Rn, #const] */
10410 if (Rn > 7)
10411 {
10412 if (Rn == REG_PC)
10413 {
10414 if (inst.reloc.pc_rel)
10415 opcode = T_MNEM_ldr_pc2;
10416 else
10417 opcode = T_MNEM_ldr_pc;
10418 }
10419 else
10420 {
10421 if (opcode == T_MNEM_ldr)
10422 opcode = T_MNEM_ldr_sp;
10423 else
10424 opcode = T_MNEM_str_sp;
10425 }
10426 inst.instruction = inst.operands[0].reg << 8;
10427 }
10428 else
10429 {
10430 inst.instruction = inst.operands[0].reg;
10431 inst.instruction |= inst.operands[1].reg << 3;
10432 }
10433 inst.instruction |= THUMB_OP16 (opcode);
10434 if (inst.size_req == 2)
10435 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10436 else
10437 inst.relax = opcode;
10438 return;
10439 }
c19d1205 10440 }
0110f2b8 10441 /* Definitely a 32-bit variant. */
5be8be5d 10442
8d67f500
NC
10443 /* Warning for Erratum 752419. */
10444 if (opcode == T_MNEM_ldr
10445 && inst.operands[0].reg == REG_SP
10446 && inst.operands[1].writeback == 1
10447 && !inst.operands[1].immisreg)
10448 {
10449 if (no_cpu_selected ()
10450 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
10451 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
10452 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
10453 as_warn (_("This instruction may be unpredictable "
10454 "if executed on M-profile cores "
10455 "with interrupts enabled."));
10456 }
10457
5be8be5d
DG
10458 /* Do some validations regarding addressing modes. */
10459 if (inst.operands[1].immisreg && opcode != T_MNEM_ldr
10460 && opcode != T_MNEM_str)
10461 reject_bad_reg (inst.operands[1].imm);
10462
0110f2b8 10463 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
10464 inst.instruction |= inst.operands[0].reg << 12;
10465 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
10466 return;
10467 }
10468
c19d1205
ZW
10469 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10470
10471 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 10472 {
c19d1205
ZW
10473 /* Only [Rn,Rm] is acceptable. */
10474 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10475 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10476 || inst.operands[1].postind || inst.operands[1].shifted
10477 || inst.operands[1].negative,
10478 _("Thumb does not support this addressing mode"));
10479 inst.instruction = THUMB_OP16 (inst.instruction);
10480 goto op16;
b99bd4ef 10481 }
5f4273c7 10482
c19d1205
ZW
10483 inst.instruction = THUMB_OP16 (inst.instruction);
10484 if (!inst.operands[1].isreg)
10485 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10486 return;
b99bd4ef 10487
c19d1205
ZW
10488 constraint (!inst.operands[1].preind
10489 || inst.operands[1].shifted
10490 || inst.operands[1].writeback,
10491 _("Thumb does not support this addressing mode"));
10492 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 10493 {
c19d1205
ZW
10494 constraint (inst.instruction & 0x0600,
10495 _("byte or halfword not valid for base register"));
10496 constraint (inst.operands[1].reg == REG_PC
10497 && !(inst.instruction & THUMB_LOAD_BIT),
10498 _("r15 based store not allowed"));
10499 constraint (inst.operands[1].immisreg,
10500 _("invalid base register for register offset"));
b99bd4ef 10501
c19d1205
ZW
10502 if (inst.operands[1].reg == REG_PC)
10503 inst.instruction = T_OPCODE_LDR_PC;
10504 else if (inst.instruction & THUMB_LOAD_BIT)
10505 inst.instruction = T_OPCODE_LDR_SP;
10506 else
10507 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 10508
c19d1205
ZW
10509 inst.instruction |= inst.operands[0].reg << 8;
10510 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10511 return;
10512 }
90e4755a 10513
c19d1205
ZW
10514 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10515 if (!inst.operands[1].immisreg)
10516 {
10517 /* Immediate offset. */
10518 inst.instruction |= inst.operands[0].reg;
10519 inst.instruction |= inst.operands[1].reg << 3;
10520 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10521 return;
10522 }
90e4755a 10523
c19d1205
ZW
10524 /* Register offset. */
10525 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10526 constraint (inst.operands[1].negative,
10527 _("Thumb does not support this addressing mode"));
90e4755a 10528
c19d1205
ZW
10529 op16:
10530 switch (inst.instruction)
10531 {
10532 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10533 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10534 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10535 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10536 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10537 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10538 case 0x5600 /* ldrsb */:
10539 case 0x5e00 /* ldrsh */: break;
10540 default: abort ();
10541 }
90e4755a 10542
c19d1205
ZW
10543 inst.instruction |= inst.operands[0].reg;
10544 inst.instruction |= inst.operands[1].reg << 3;
10545 inst.instruction |= inst.operands[1].imm << 6;
10546}
90e4755a 10547
c19d1205
ZW
10548static void
10549do_t_ldstd (void)
10550{
10551 if (!inst.operands[1].present)
b99bd4ef 10552 {
c19d1205
ZW
10553 inst.operands[1].reg = inst.operands[0].reg + 1;
10554 constraint (inst.operands[0].reg == REG_LR,
10555 _("r14 not allowed here"));
b99bd4ef 10556 }
c19d1205
ZW
10557 inst.instruction |= inst.operands[0].reg << 12;
10558 inst.instruction |= inst.operands[1].reg << 8;
10559 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
10560}
10561
c19d1205
ZW
10562static void
10563do_t_ldstt (void)
10564{
10565 inst.instruction |= inst.operands[0].reg << 12;
10566 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10567}
a737bd4d 10568
b99bd4ef 10569static void
c19d1205 10570do_t_mla (void)
b99bd4ef 10571{
fdfde340 10572 unsigned Rd, Rn, Rm, Ra;
c921be7d 10573
fdfde340
JM
10574 Rd = inst.operands[0].reg;
10575 Rn = inst.operands[1].reg;
10576 Rm = inst.operands[2].reg;
10577 Ra = inst.operands[3].reg;
10578
10579 reject_bad_reg (Rd);
10580 reject_bad_reg (Rn);
10581 reject_bad_reg (Rm);
10582 reject_bad_reg (Ra);
10583
10584 inst.instruction |= Rd << 8;
10585 inst.instruction |= Rn << 16;
10586 inst.instruction |= Rm;
10587 inst.instruction |= Ra << 12;
c19d1205 10588}
b99bd4ef 10589
c19d1205
ZW
10590static void
10591do_t_mlal (void)
10592{
fdfde340
JM
10593 unsigned RdLo, RdHi, Rn, Rm;
10594
10595 RdLo = inst.operands[0].reg;
10596 RdHi = inst.operands[1].reg;
10597 Rn = inst.operands[2].reg;
10598 Rm = inst.operands[3].reg;
10599
10600 reject_bad_reg (RdLo);
10601 reject_bad_reg (RdHi);
10602 reject_bad_reg (Rn);
10603 reject_bad_reg (Rm);
10604
10605 inst.instruction |= RdLo << 12;
10606 inst.instruction |= RdHi << 8;
10607 inst.instruction |= Rn << 16;
10608 inst.instruction |= Rm;
c19d1205 10609}
b99bd4ef 10610
c19d1205
ZW
10611static void
10612do_t_mov_cmp (void)
10613{
fdfde340
JM
10614 unsigned Rn, Rm;
10615
10616 Rn = inst.operands[0].reg;
10617 Rm = inst.operands[1].reg;
10618
e07e6e58
NC
10619 if (Rn == REG_PC)
10620 set_it_insn_type_last ();
10621
c19d1205 10622 if (unified_syntax)
b99bd4ef 10623 {
c19d1205
ZW
10624 int r0off = (inst.instruction == T_MNEM_mov
10625 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 10626 unsigned long opcode;
3d388997
PB
10627 bfd_boolean narrow;
10628 bfd_boolean low_regs;
10629
fdfde340 10630 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 10631 opcode = inst.instruction;
e07e6e58 10632 if (in_it_block ())
0110f2b8 10633 narrow = opcode != T_MNEM_movs;
3d388997 10634 else
0110f2b8 10635 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
10636 if (inst.size_req == 4
10637 || inst.operands[1].shifted)
10638 narrow = FALSE;
10639
efd81785
PB
10640 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10641 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10642 && !inst.operands[1].shifted
fdfde340
JM
10643 && Rn == REG_PC
10644 && Rm == REG_LR)
efd81785
PB
10645 {
10646 inst.instruction = T2_SUBS_PC_LR;
10647 return;
10648 }
10649
fdfde340
JM
10650 if (opcode == T_MNEM_cmp)
10651 {
10652 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
10653 if (narrow)
10654 {
10655 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10656 but valid. */
10657 warn_deprecated_sp (Rm);
10658 /* R15 was documented as a valid choice for Rm in ARMv6,
10659 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10660 tools reject R15, so we do too. */
10661 constraint (Rm == REG_PC, BAD_PC);
10662 }
10663 else
10664 reject_bad_reg (Rm);
fdfde340
JM
10665 }
10666 else if (opcode == T_MNEM_mov
10667 || opcode == T_MNEM_movs)
10668 {
10669 if (inst.operands[1].isreg)
10670 {
10671 if (opcode == T_MNEM_movs)
10672 {
10673 reject_bad_reg (Rn);
10674 reject_bad_reg (Rm);
10675 }
76fa04a4
MGD
10676 else if (narrow)
10677 {
10678 /* This is mov.n. */
10679 if ((Rn == REG_SP || Rn == REG_PC)
10680 && (Rm == REG_SP || Rm == REG_PC))
10681 {
10682 as_warn (_("Use of r%u as a source register is "
10683 "deprecated when r%u is the destination "
10684 "register."), Rm, Rn);
10685 }
10686 }
10687 else
10688 {
10689 /* This is mov.w. */
10690 constraint (Rn == REG_PC, BAD_PC);
10691 constraint (Rm == REG_PC, BAD_PC);
10692 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
10693 }
fdfde340
JM
10694 }
10695 else
10696 reject_bad_reg (Rn);
10697 }
10698
c19d1205
ZW
10699 if (!inst.operands[1].isreg)
10700 {
0110f2b8 10701 /* Immediate operand. */
e07e6e58 10702 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
10703 narrow = 0;
10704 if (low_regs && narrow)
10705 {
10706 inst.instruction = THUMB_OP16 (opcode);
fdfde340 10707 inst.instruction |= Rn << 8;
0110f2b8
PB
10708 if (inst.size_req == 2)
10709 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10710 else
10711 inst.relax = opcode;
10712 }
10713 else
10714 {
10715 inst.instruction = THUMB_OP32 (inst.instruction);
10716 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10717 inst.instruction |= Rn << r0off;
0110f2b8
PB
10718 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10719 }
c19d1205 10720 }
728ca7c9
PB
10721 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10722 && (inst.instruction == T_MNEM_mov
10723 || inst.instruction == T_MNEM_movs))
10724 {
10725 /* Register shifts are encoded as separate shift instructions. */
10726 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10727
e07e6e58 10728 if (in_it_block ())
728ca7c9
PB
10729 narrow = !flags;
10730 else
10731 narrow = flags;
10732
10733 if (inst.size_req == 4)
10734 narrow = FALSE;
10735
10736 if (!low_regs || inst.operands[1].imm > 7)
10737 narrow = FALSE;
10738
fdfde340 10739 if (Rn != Rm)
728ca7c9
PB
10740 narrow = FALSE;
10741
10742 switch (inst.operands[1].shift_kind)
10743 {
10744 case SHIFT_LSL:
10745 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10746 break;
10747 case SHIFT_ASR:
10748 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10749 break;
10750 case SHIFT_LSR:
10751 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10752 break;
10753 case SHIFT_ROR:
10754 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10755 break;
10756 default:
5f4273c7 10757 abort ();
728ca7c9
PB
10758 }
10759
10760 inst.instruction = opcode;
10761 if (narrow)
10762 {
fdfde340 10763 inst.instruction |= Rn;
728ca7c9
PB
10764 inst.instruction |= inst.operands[1].imm << 3;
10765 }
10766 else
10767 {
10768 if (flags)
10769 inst.instruction |= CONDS_BIT;
10770
fdfde340
JM
10771 inst.instruction |= Rn << 8;
10772 inst.instruction |= Rm << 16;
728ca7c9
PB
10773 inst.instruction |= inst.operands[1].imm;
10774 }
10775 }
3d388997 10776 else if (!narrow)
c19d1205 10777 {
728ca7c9
PB
10778 /* Some mov with immediate shift have narrow variants.
10779 Register shifts are handled above. */
10780 if (low_regs && inst.operands[1].shifted
10781 && (inst.instruction == T_MNEM_mov
10782 || inst.instruction == T_MNEM_movs))
10783 {
e07e6e58 10784 if (in_it_block ())
728ca7c9
PB
10785 narrow = (inst.instruction == T_MNEM_mov);
10786 else
10787 narrow = (inst.instruction == T_MNEM_movs);
10788 }
10789
10790 if (narrow)
10791 {
10792 switch (inst.operands[1].shift_kind)
10793 {
10794 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10795 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10796 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10797 default: narrow = FALSE; break;
10798 }
10799 }
10800
10801 if (narrow)
10802 {
fdfde340
JM
10803 inst.instruction |= Rn;
10804 inst.instruction |= Rm << 3;
728ca7c9
PB
10805 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10806 }
10807 else
10808 {
10809 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10810 inst.instruction |= Rn << r0off;
728ca7c9
PB
10811 encode_thumb32_shifted_operand (1);
10812 }
c19d1205
ZW
10813 }
10814 else
10815 switch (inst.instruction)
10816 {
10817 case T_MNEM_mov:
10818 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
10819 inst.instruction |= (Rn & 0x8) << 4;
10820 inst.instruction |= (Rn & 0x7);
10821 inst.instruction |= Rm << 3;
c19d1205 10822 break;
b99bd4ef 10823
c19d1205
ZW
10824 case T_MNEM_movs:
10825 /* We know we have low registers at this point.
941a8a52
MGD
10826 Generate LSLS Rd, Rs, #0. */
10827 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
10828 inst.instruction |= Rn;
10829 inst.instruction |= Rm << 3;
c19d1205
ZW
10830 break;
10831
10832 case T_MNEM_cmp:
3d388997 10833 if (low_regs)
c19d1205
ZW
10834 {
10835 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
10836 inst.instruction |= Rn;
10837 inst.instruction |= Rm << 3;
c19d1205
ZW
10838 }
10839 else
10840 {
10841 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
10842 inst.instruction |= (Rn & 0x8) << 4;
10843 inst.instruction |= (Rn & 0x7);
10844 inst.instruction |= Rm << 3;
c19d1205
ZW
10845 }
10846 break;
10847 }
b99bd4ef
NC
10848 return;
10849 }
10850
c19d1205 10851 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
10852
10853 /* PR 10443: Do not silently ignore shifted operands. */
10854 constraint (inst.operands[1].shifted,
10855 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10856
c19d1205 10857 if (inst.operands[1].isreg)
b99bd4ef 10858 {
fdfde340 10859 if (Rn < 8 && Rm < 8)
b99bd4ef 10860 {
c19d1205
ZW
10861 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10862 since a MOV instruction produces unpredictable results. */
10863 if (inst.instruction == T_OPCODE_MOV_I8)
10864 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 10865 else
c19d1205 10866 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 10867
fdfde340
JM
10868 inst.instruction |= Rn;
10869 inst.instruction |= Rm << 3;
b99bd4ef
NC
10870 }
10871 else
10872 {
c19d1205
ZW
10873 if (inst.instruction == T_OPCODE_MOV_I8)
10874 inst.instruction = T_OPCODE_MOV_HR;
10875 else
10876 inst.instruction = T_OPCODE_CMP_HR;
10877 do_t_cpy ();
b99bd4ef
NC
10878 }
10879 }
c19d1205 10880 else
b99bd4ef 10881 {
fdfde340 10882 constraint (Rn > 7,
c19d1205 10883 _("only lo regs allowed with immediate"));
fdfde340 10884 inst.instruction |= Rn << 8;
c19d1205
ZW
10885 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10886 }
10887}
b99bd4ef 10888
c19d1205
ZW
10889static void
10890do_t_mov16 (void)
10891{
fdfde340 10892 unsigned Rd;
b6895b4f
PB
10893 bfd_vma imm;
10894 bfd_boolean top;
10895
10896 top = (inst.instruction & 0x00800000) != 0;
10897 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10898 {
10899 constraint (top, _(":lower16: not allowed this instruction"));
10900 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10901 }
10902 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10903 {
10904 constraint (!top, _(":upper16: not allowed this instruction"));
10905 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10906 }
10907
fdfde340
JM
10908 Rd = inst.operands[0].reg;
10909 reject_bad_reg (Rd);
10910
10911 inst.instruction |= Rd << 8;
b6895b4f
PB
10912 if (inst.reloc.type == BFD_RELOC_UNUSED)
10913 {
10914 imm = inst.reloc.exp.X_add_number;
10915 inst.instruction |= (imm & 0xf000) << 4;
10916 inst.instruction |= (imm & 0x0800) << 15;
10917 inst.instruction |= (imm & 0x0700) << 4;
10918 inst.instruction |= (imm & 0x00ff);
10919 }
c19d1205 10920}
b99bd4ef 10921
c19d1205
ZW
10922static void
10923do_t_mvn_tst (void)
10924{
fdfde340 10925 unsigned Rn, Rm;
c921be7d 10926
fdfde340
JM
10927 Rn = inst.operands[0].reg;
10928 Rm = inst.operands[1].reg;
10929
10930 if (inst.instruction == T_MNEM_cmp
10931 || inst.instruction == T_MNEM_cmn)
10932 constraint (Rn == REG_PC, BAD_PC);
10933 else
10934 reject_bad_reg (Rn);
10935 reject_bad_reg (Rm);
10936
c19d1205
ZW
10937 if (unified_syntax)
10938 {
10939 int r0off = (inst.instruction == T_MNEM_mvn
10940 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
10941 bfd_boolean narrow;
10942
10943 if (inst.size_req == 4
10944 || inst.instruction > 0xffff
10945 || inst.operands[1].shifted
fdfde340 10946 || Rn > 7 || Rm > 7)
3d388997
PB
10947 narrow = FALSE;
10948 else if (inst.instruction == T_MNEM_cmn)
10949 narrow = TRUE;
10950 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10951 narrow = !in_it_block ();
3d388997 10952 else
e07e6e58 10953 narrow = in_it_block ();
3d388997 10954
c19d1205 10955 if (!inst.operands[1].isreg)
b99bd4ef 10956 {
c19d1205
ZW
10957 /* For an immediate, we always generate a 32-bit opcode;
10958 section relaxation will shrink it later if possible. */
10959 if (inst.instruction < 0xffff)
10960 inst.instruction = THUMB_OP32 (inst.instruction);
10961 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10962 inst.instruction |= Rn << r0off;
c19d1205 10963 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10964 }
c19d1205 10965 else
b99bd4ef 10966 {
c19d1205 10967 /* See if we can do this with a 16-bit instruction. */
3d388997 10968 if (narrow)
b99bd4ef 10969 {
c19d1205 10970 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10971 inst.instruction |= Rn;
10972 inst.instruction |= Rm << 3;
b99bd4ef 10973 }
c19d1205 10974 else
b99bd4ef 10975 {
c19d1205
ZW
10976 constraint (inst.operands[1].shifted
10977 && inst.operands[1].immisreg,
10978 _("shift must be constant"));
10979 if (inst.instruction < 0xffff)
10980 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10981 inst.instruction |= Rn << r0off;
c19d1205 10982 encode_thumb32_shifted_operand (1);
b99bd4ef 10983 }
b99bd4ef
NC
10984 }
10985 }
10986 else
10987 {
c19d1205
ZW
10988 constraint (inst.instruction > 0xffff
10989 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10990 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10991 _("unshifted register required"));
fdfde340 10992 constraint (Rn > 7 || Rm > 7,
c19d1205 10993 BAD_HIREG);
b99bd4ef 10994
c19d1205 10995 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10996 inst.instruction |= Rn;
10997 inst.instruction |= Rm << 3;
b99bd4ef 10998 }
b99bd4ef
NC
10999}
11000
b05fe5cf 11001static void
c19d1205 11002do_t_mrs (void)
b05fe5cf 11003{
fdfde340 11004 unsigned Rd;
037e8744
JB
11005
11006 if (do_vfp_nsyn_mrs () == SUCCESS)
11007 return;
11008
90ec0d68
MGD
11009 Rd = inst.operands[0].reg;
11010 reject_bad_reg (Rd);
11011 inst.instruction |= Rd << 8;
11012
11013 if (inst.operands[1].isreg)
62b3e311 11014 {
90ec0d68
MGD
11015 unsigned br = inst.operands[1].reg;
11016 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
11017 as_bad (_("bad register for mrs"));
11018
11019 inst.instruction |= br & (0xf << 16);
11020 inst.instruction |= (br & 0x300) >> 4;
11021 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
11022 }
11023 else
11024 {
90ec0d68 11025 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 11026
d2cd1205
JB
11027 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
11028 constraint (flags != 0, _("selected processor does not support "
11029 "requested special purpose register"));
90ec0d68 11030 else
d2cd1205
JB
11031 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
11032 devices). */
11033 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
11034 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 11035
90ec0d68
MGD
11036 inst.instruction |= (flags & SPSR_BIT) >> 2;
11037 inst.instruction |= inst.operands[1].imm & 0xff;
11038 inst.instruction |= 0xf0000;
11039 }
c19d1205 11040}
b05fe5cf 11041
c19d1205
ZW
11042static void
11043do_t_msr (void)
11044{
62b3e311 11045 int flags;
fdfde340 11046 unsigned Rn;
62b3e311 11047
037e8744
JB
11048 if (do_vfp_nsyn_msr () == SUCCESS)
11049 return;
11050
c19d1205
ZW
11051 constraint (!inst.operands[1].isreg,
11052 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
11053
11054 if (inst.operands[0].isreg)
11055 flags = (int)(inst.operands[0].reg);
11056 else
11057 flags = inst.operands[0].imm;
11058
d2cd1205 11059 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 11060 {
d2cd1205
JB
11061 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11062
11063 constraint ((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11064 && (bits & ~(PSR_s | PSR_f)) != 0)
11065 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11066 && bits != PSR_f),
11067 _("selected processor does not support requested special "
11068 "purpose register"));
62b3e311
PB
11069 }
11070 else
d2cd1205
JB
11071 constraint ((flags & 0xff) != 0, _("selected processor does not support "
11072 "requested special purpose register"));
c921be7d 11073
fdfde340
JM
11074 Rn = inst.operands[1].reg;
11075 reject_bad_reg (Rn);
11076
62b3e311 11077 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
11078 inst.instruction |= (flags & 0xf0000) >> 8;
11079 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 11080 inst.instruction |= (flags & 0xff);
fdfde340 11081 inst.instruction |= Rn << 16;
c19d1205 11082}
b05fe5cf 11083
c19d1205
ZW
11084static void
11085do_t_mul (void)
11086{
17828f45 11087 bfd_boolean narrow;
fdfde340 11088 unsigned Rd, Rn, Rm;
17828f45 11089
c19d1205
ZW
11090 if (!inst.operands[2].present)
11091 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 11092
fdfde340
JM
11093 Rd = inst.operands[0].reg;
11094 Rn = inst.operands[1].reg;
11095 Rm = inst.operands[2].reg;
11096
17828f45 11097 if (unified_syntax)
b05fe5cf 11098 {
17828f45 11099 if (inst.size_req == 4
fdfde340
JM
11100 || (Rd != Rn
11101 && Rd != Rm)
11102 || Rn > 7
11103 || Rm > 7)
17828f45
JM
11104 narrow = FALSE;
11105 else if (inst.instruction == T_MNEM_muls)
e07e6e58 11106 narrow = !in_it_block ();
17828f45 11107 else
e07e6e58 11108 narrow = in_it_block ();
b05fe5cf 11109 }
c19d1205 11110 else
b05fe5cf 11111 {
17828f45 11112 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 11113 constraint (Rn > 7 || Rm > 7,
c19d1205 11114 BAD_HIREG);
17828f45
JM
11115 narrow = TRUE;
11116 }
b05fe5cf 11117
17828f45
JM
11118 if (narrow)
11119 {
11120 /* 16-bit MULS/Conditional MUL. */
c19d1205 11121 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11122 inst.instruction |= Rd;
b05fe5cf 11123
fdfde340
JM
11124 if (Rd == Rn)
11125 inst.instruction |= Rm << 3;
11126 else if (Rd == Rm)
11127 inst.instruction |= Rn << 3;
c19d1205
ZW
11128 else
11129 constraint (1, _("dest must overlap one source register"));
11130 }
17828f45
JM
11131 else
11132 {
e07e6e58
NC
11133 constraint (inst.instruction != T_MNEM_mul,
11134 _("Thumb-2 MUL must not set flags"));
17828f45
JM
11135 /* 32-bit MUL. */
11136 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11137 inst.instruction |= Rd << 8;
11138 inst.instruction |= Rn << 16;
11139 inst.instruction |= Rm << 0;
11140
11141 reject_bad_reg (Rd);
11142 reject_bad_reg (Rn);
11143 reject_bad_reg (Rm);
17828f45 11144 }
c19d1205 11145}
b05fe5cf 11146
c19d1205
ZW
11147static void
11148do_t_mull (void)
11149{
fdfde340 11150 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 11151
fdfde340
JM
11152 RdLo = inst.operands[0].reg;
11153 RdHi = inst.operands[1].reg;
11154 Rn = inst.operands[2].reg;
11155 Rm = inst.operands[3].reg;
11156
11157 reject_bad_reg (RdLo);
11158 reject_bad_reg (RdHi);
11159 reject_bad_reg (Rn);
11160 reject_bad_reg (Rm);
11161
11162 inst.instruction |= RdLo << 12;
11163 inst.instruction |= RdHi << 8;
11164 inst.instruction |= Rn << 16;
11165 inst.instruction |= Rm;
11166
11167 if (RdLo == RdHi)
c19d1205
ZW
11168 as_tsktsk (_("rdhi and rdlo must be different"));
11169}
b05fe5cf 11170
c19d1205
ZW
11171static void
11172do_t_nop (void)
11173{
e07e6e58
NC
11174 set_it_insn_type (NEUTRAL_IT_INSN);
11175
c19d1205
ZW
11176 if (unified_syntax)
11177 {
11178 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 11179 {
c19d1205
ZW
11180 inst.instruction = THUMB_OP32 (inst.instruction);
11181 inst.instruction |= inst.operands[0].imm;
11182 }
11183 else
11184 {
bc2d1808
NC
11185 /* PR9722: Check for Thumb2 availability before
11186 generating a thumb2 nop instruction. */
afa62d5e 11187 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
11188 {
11189 inst.instruction = THUMB_OP16 (inst.instruction);
11190 inst.instruction |= inst.operands[0].imm << 4;
11191 }
11192 else
11193 inst.instruction = 0x46c0;
c19d1205
ZW
11194 }
11195 }
11196 else
11197 {
11198 constraint (inst.operands[0].present,
11199 _("Thumb does not support NOP with hints"));
11200 inst.instruction = 0x46c0;
11201 }
11202}
b05fe5cf 11203
c19d1205
ZW
11204static void
11205do_t_neg (void)
11206{
11207 if (unified_syntax)
11208 {
3d388997
PB
11209 bfd_boolean narrow;
11210
11211 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11212 narrow = !in_it_block ();
3d388997 11213 else
e07e6e58 11214 narrow = in_it_block ();
3d388997
PB
11215 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11216 narrow = FALSE;
11217 if (inst.size_req == 4)
11218 narrow = FALSE;
11219
11220 if (!narrow)
c19d1205
ZW
11221 {
11222 inst.instruction = THUMB_OP32 (inst.instruction);
11223 inst.instruction |= inst.operands[0].reg << 8;
11224 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
11225 }
11226 else
11227 {
c19d1205
ZW
11228 inst.instruction = THUMB_OP16 (inst.instruction);
11229 inst.instruction |= inst.operands[0].reg;
11230 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
11231 }
11232 }
11233 else
11234 {
c19d1205
ZW
11235 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
11236 BAD_HIREG);
11237 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11238
11239 inst.instruction = THUMB_OP16 (inst.instruction);
11240 inst.instruction |= inst.operands[0].reg;
11241 inst.instruction |= inst.operands[1].reg << 3;
11242 }
11243}
11244
1c444d06
JM
11245static void
11246do_t_orn (void)
11247{
11248 unsigned Rd, Rn;
11249
11250 Rd = inst.operands[0].reg;
11251 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
11252
fdfde340
JM
11253 reject_bad_reg (Rd);
11254 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
11255 reject_bad_reg (Rn);
11256
1c444d06
JM
11257 inst.instruction |= Rd << 8;
11258 inst.instruction |= Rn << 16;
11259
11260 if (!inst.operands[2].isreg)
11261 {
11262 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11263 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11264 }
11265 else
11266 {
11267 unsigned Rm;
11268
11269 Rm = inst.operands[2].reg;
fdfde340 11270 reject_bad_reg (Rm);
1c444d06
JM
11271
11272 constraint (inst.operands[2].shifted
11273 && inst.operands[2].immisreg,
11274 _("shift must be constant"));
11275 encode_thumb32_shifted_operand (2);
11276 }
11277}
11278
c19d1205
ZW
11279static void
11280do_t_pkhbt (void)
11281{
fdfde340
JM
11282 unsigned Rd, Rn, Rm;
11283
11284 Rd = inst.operands[0].reg;
11285 Rn = inst.operands[1].reg;
11286 Rm = inst.operands[2].reg;
11287
11288 reject_bad_reg (Rd);
11289 reject_bad_reg (Rn);
11290 reject_bad_reg (Rm);
11291
11292 inst.instruction |= Rd << 8;
11293 inst.instruction |= Rn << 16;
11294 inst.instruction |= Rm;
c19d1205
ZW
11295 if (inst.operands[3].present)
11296 {
11297 unsigned int val = inst.reloc.exp.X_add_number;
11298 constraint (inst.reloc.exp.X_op != O_constant,
11299 _("expression too complex"));
11300 inst.instruction |= (val & 0x1c) << 10;
11301 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 11302 }
c19d1205 11303}
b05fe5cf 11304
c19d1205
ZW
11305static void
11306do_t_pkhtb (void)
11307{
11308 if (!inst.operands[3].present)
1ef52f49
NC
11309 {
11310 unsigned Rtmp;
11311
11312 inst.instruction &= ~0x00000020;
11313
11314 /* PR 10168. Swap the Rm and Rn registers. */
11315 Rtmp = inst.operands[1].reg;
11316 inst.operands[1].reg = inst.operands[2].reg;
11317 inst.operands[2].reg = Rtmp;
11318 }
c19d1205 11319 do_t_pkhbt ();
b05fe5cf
ZW
11320}
11321
c19d1205
ZW
11322static void
11323do_t_pld (void)
11324{
fdfde340
JM
11325 if (inst.operands[0].immisreg)
11326 reject_bad_reg (inst.operands[0].imm);
11327
c19d1205
ZW
11328 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11329}
b05fe5cf 11330
c19d1205
ZW
11331static void
11332do_t_push_pop (void)
b99bd4ef 11333{
e9f89963 11334 unsigned mask;
5f4273c7 11335
c19d1205
ZW
11336 constraint (inst.operands[0].writeback,
11337 _("push/pop do not support {reglist}^"));
11338 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11339 _("expression too complex"));
b99bd4ef 11340
e9f89963
PB
11341 mask = inst.operands[0].imm;
11342 if ((mask & ~0xff) == 0)
3c707909 11343 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 11344 else if ((inst.instruction == T_MNEM_push
e9f89963 11345 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 11346 || (inst.instruction == T_MNEM_pop
e9f89963 11347 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 11348 {
c19d1205
ZW
11349 inst.instruction = THUMB_OP16 (inst.instruction);
11350 inst.instruction |= THUMB_PP_PC_LR;
3c707909 11351 inst.instruction |= mask & 0xff;
c19d1205
ZW
11352 }
11353 else if (unified_syntax)
11354 {
3c707909 11355 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 11356 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
11357 }
11358 else
11359 {
11360 inst.error = _("invalid register list to push/pop instruction");
11361 return;
11362 }
c19d1205 11363}
b99bd4ef 11364
c19d1205
ZW
11365static void
11366do_t_rbit (void)
11367{
fdfde340
JM
11368 unsigned Rd, Rm;
11369
11370 Rd = inst.operands[0].reg;
11371 Rm = inst.operands[1].reg;
11372
11373 reject_bad_reg (Rd);
11374 reject_bad_reg (Rm);
11375
11376 inst.instruction |= Rd << 8;
11377 inst.instruction |= Rm << 16;
11378 inst.instruction |= Rm;
c19d1205 11379}
b99bd4ef 11380
c19d1205
ZW
11381static void
11382do_t_rev (void)
11383{
fdfde340
JM
11384 unsigned Rd, Rm;
11385
11386 Rd = inst.operands[0].reg;
11387 Rm = inst.operands[1].reg;
11388
11389 reject_bad_reg (Rd);
11390 reject_bad_reg (Rm);
11391
11392 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
11393 && inst.size_req != 4)
11394 {
11395 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11396 inst.instruction |= Rd;
11397 inst.instruction |= Rm << 3;
c19d1205
ZW
11398 }
11399 else if (unified_syntax)
11400 {
11401 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11402 inst.instruction |= Rd << 8;
11403 inst.instruction |= Rm << 16;
11404 inst.instruction |= Rm;
c19d1205
ZW
11405 }
11406 else
11407 inst.error = BAD_HIREG;
11408}
b99bd4ef 11409
1c444d06
JM
11410static void
11411do_t_rrx (void)
11412{
11413 unsigned Rd, Rm;
11414
11415 Rd = inst.operands[0].reg;
11416 Rm = inst.operands[1].reg;
11417
fdfde340
JM
11418 reject_bad_reg (Rd);
11419 reject_bad_reg (Rm);
c921be7d 11420
1c444d06
JM
11421 inst.instruction |= Rd << 8;
11422 inst.instruction |= Rm;
11423}
11424
c19d1205
ZW
11425static void
11426do_t_rsb (void)
11427{
fdfde340 11428 unsigned Rd, Rs;
b99bd4ef 11429
c19d1205
ZW
11430 Rd = inst.operands[0].reg;
11431 Rs = (inst.operands[1].present
11432 ? inst.operands[1].reg /* Rd, Rs, foo */
11433 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 11434
fdfde340
JM
11435 reject_bad_reg (Rd);
11436 reject_bad_reg (Rs);
11437 if (inst.operands[2].isreg)
11438 reject_bad_reg (inst.operands[2].reg);
11439
c19d1205
ZW
11440 inst.instruction |= Rd << 8;
11441 inst.instruction |= Rs << 16;
11442 if (!inst.operands[2].isreg)
11443 {
026d3abb
PB
11444 bfd_boolean narrow;
11445
11446 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 11447 narrow = !in_it_block ();
026d3abb 11448 else
e07e6e58 11449 narrow = in_it_block ();
026d3abb
PB
11450
11451 if (Rd > 7 || Rs > 7)
11452 narrow = FALSE;
11453
11454 if (inst.size_req == 4 || !unified_syntax)
11455 narrow = FALSE;
11456
11457 if (inst.reloc.exp.X_op != O_constant
11458 || inst.reloc.exp.X_add_number != 0)
11459 narrow = FALSE;
11460
11461 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11462 relaxation, but it doesn't seem worth the hassle. */
11463 if (narrow)
11464 {
11465 inst.reloc.type = BFD_RELOC_UNUSED;
11466 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11467 inst.instruction |= Rs << 3;
11468 inst.instruction |= Rd;
11469 }
11470 else
11471 {
11472 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11473 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11474 }
c19d1205
ZW
11475 }
11476 else
11477 encode_thumb32_shifted_operand (2);
11478}
b99bd4ef 11479
c19d1205
ZW
11480static void
11481do_t_setend (void)
11482{
e07e6e58 11483 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11484 if (inst.operands[0].imm)
11485 inst.instruction |= 0x8;
11486}
b99bd4ef 11487
c19d1205
ZW
11488static void
11489do_t_shift (void)
11490{
11491 if (!inst.operands[1].present)
11492 inst.operands[1].reg = inst.operands[0].reg;
11493
11494 if (unified_syntax)
11495 {
3d388997
PB
11496 bfd_boolean narrow;
11497 int shift_kind;
11498
11499 switch (inst.instruction)
11500 {
11501 case T_MNEM_asr:
11502 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11503 case T_MNEM_lsl:
11504 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11505 case T_MNEM_lsr:
11506 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11507 case T_MNEM_ror:
11508 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11509 default: abort ();
11510 }
11511
11512 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11513 narrow = !in_it_block ();
3d388997 11514 else
e07e6e58 11515 narrow = in_it_block ();
3d388997
PB
11516 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11517 narrow = FALSE;
11518 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11519 narrow = FALSE;
11520 if (inst.operands[2].isreg
11521 && (inst.operands[1].reg != inst.operands[0].reg
11522 || inst.operands[2].reg > 7))
11523 narrow = FALSE;
11524 if (inst.size_req == 4)
11525 narrow = FALSE;
11526
fdfde340
JM
11527 reject_bad_reg (inst.operands[0].reg);
11528 reject_bad_reg (inst.operands[1].reg);
c921be7d 11529
3d388997 11530 if (!narrow)
c19d1205
ZW
11531 {
11532 if (inst.operands[2].isreg)
b99bd4ef 11533 {
fdfde340 11534 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
11535 inst.instruction = THUMB_OP32 (inst.instruction);
11536 inst.instruction |= inst.operands[0].reg << 8;
11537 inst.instruction |= inst.operands[1].reg << 16;
11538 inst.instruction |= inst.operands[2].reg;
11539 }
11540 else
11541 {
11542 inst.operands[1].shifted = 1;
3d388997 11543 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
11544 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11545 ? T_MNEM_movs : T_MNEM_mov);
11546 inst.instruction |= inst.operands[0].reg << 8;
11547 encode_thumb32_shifted_operand (1);
11548 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11549 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
11550 }
11551 }
11552 else
11553 {
c19d1205 11554 if (inst.operands[2].isreg)
b99bd4ef 11555 {
3d388997 11556 switch (shift_kind)
b99bd4ef 11557 {
3d388997
PB
11558 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11559 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11560 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11561 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 11562 default: abort ();
b99bd4ef 11563 }
5f4273c7 11564
c19d1205
ZW
11565 inst.instruction |= inst.operands[0].reg;
11566 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
11567 }
11568 else
11569 {
3d388997 11570 switch (shift_kind)
b99bd4ef 11571 {
3d388997
PB
11572 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11573 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11574 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 11575 default: abort ();
b99bd4ef 11576 }
c19d1205
ZW
11577 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11578 inst.instruction |= inst.operands[0].reg;
11579 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11580 }
11581 }
c19d1205
ZW
11582 }
11583 else
11584 {
11585 constraint (inst.operands[0].reg > 7
11586 || inst.operands[1].reg > 7, BAD_HIREG);
11587 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 11588
c19d1205
ZW
11589 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11590 {
11591 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11592 constraint (inst.operands[0].reg != inst.operands[1].reg,
11593 _("source1 and dest must be same register"));
b99bd4ef 11594
c19d1205
ZW
11595 switch (inst.instruction)
11596 {
11597 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11598 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11599 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11600 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11601 default: abort ();
11602 }
5f4273c7 11603
c19d1205
ZW
11604 inst.instruction |= inst.operands[0].reg;
11605 inst.instruction |= inst.operands[2].reg << 3;
11606 }
11607 else
b99bd4ef 11608 {
c19d1205
ZW
11609 switch (inst.instruction)
11610 {
11611 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11612 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11613 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11614 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11615 default: abort ();
11616 }
11617 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11618 inst.instruction |= inst.operands[0].reg;
11619 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11620 }
11621 }
b99bd4ef
NC
11622}
11623
11624static void
c19d1205 11625do_t_simd (void)
b99bd4ef 11626{
fdfde340
JM
11627 unsigned Rd, Rn, Rm;
11628
11629 Rd = inst.operands[0].reg;
11630 Rn = inst.operands[1].reg;
11631 Rm = inst.operands[2].reg;
11632
11633 reject_bad_reg (Rd);
11634 reject_bad_reg (Rn);
11635 reject_bad_reg (Rm);
11636
11637 inst.instruction |= Rd << 8;
11638 inst.instruction |= Rn << 16;
11639 inst.instruction |= Rm;
c19d1205 11640}
b99bd4ef 11641
03ee1b7f
NC
11642static void
11643do_t_simd2 (void)
11644{
11645 unsigned Rd, Rn, Rm;
11646
11647 Rd = inst.operands[0].reg;
11648 Rm = inst.operands[1].reg;
11649 Rn = inst.operands[2].reg;
11650
11651 reject_bad_reg (Rd);
11652 reject_bad_reg (Rn);
11653 reject_bad_reg (Rm);
11654
11655 inst.instruction |= Rd << 8;
11656 inst.instruction |= Rn << 16;
11657 inst.instruction |= Rm;
11658}
11659
c19d1205 11660static void
3eb17e6b 11661do_t_smc (void)
c19d1205
ZW
11662{
11663 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
11664 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
11665 _("SMC is not permitted on this architecture"));
c19d1205
ZW
11666 constraint (inst.reloc.exp.X_op != O_constant,
11667 _("expression too complex"));
11668 inst.reloc.type = BFD_RELOC_UNUSED;
11669 inst.instruction |= (value & 0xf000) >> 12;
11670 inst.instruction |= (value & 0x0ff0);
11671 inst.instruction |= (value & 0x000f) << 16;
11672}
b99bd4ef 11673
90ec0d68
MGD
11674static void
11675do_t_hvc (void)
11676{
11677 unsigned int value = inst.reloc.exp.X_add_number;
11678
11679 inst.reloc.type = BFD_RELOC_UNUSED;
11680 inst.instruction |= (value & 0x0fff);
11681 inst.instruction |= (value & 0xf000) << 4;
11682}
11683
c19d1205 11684static void
3a21c15a 11685do_t_ssat_usat (int bias)
c19d1205 11686{
fdfde340
JM
11687 unsigned Rd, Rn;
11688
11689 Rd = inst.operands[0].reg;
11690 Rn = inst.operands[2].reg;
11691
11692 reject_bad_reg (Rd);
11693 reject_bad_reg (Rn);
11694
11695 inst.instruction |= Rd << 8;
3a21c15a 11696 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 11697 inst.instruction |= Rn << 16;
b99bd4ef 11698
c19d1205 11699 if (inst.operands[3].present)
b99bd4ef 11700 {
3a21c15a
NC
11701 offsetT shift_amount = inst.reloc.exp.X_add_number;
11702
11703 inst.reloc.type = BFD_RELOC_UNUSED;
11704
c19d1205
ZW
11705 constraint (inst.reloc.exp.X_op != O_constant,
11706 _("expression too complex"));
b99bd4ef 11707
3a21c15a 11708 if (shift_amount != 0)
6189168b 11709 {
3a21c15a
NC
11710 constraint (shift_amount > 31,
11711 _("shift expression is too large"));
11712
c19d1205 11713 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
11714 inst.instruction |= 0x00200000; /* sh bit. */
11715
11716 inst.instruction |= (shift_amount & 0x1c) << 10;
11717 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
11718 }
11719 }
b99bd4ef 11720}
c921be7d 11721
3a21c15a
NC
11722static void
11723do_t_ssat (void)
11724{
11725 do_t_ssat_usat (1);
11726}
b99bd4ef 11727
0dd132b6 11728static void
c19d1205 11729do_t_ssat16 (void)
0dd132b6 11730{
fdfde340
JM
11731 unsigned Rd, Rn;
11732
11733 Rd = inst.operands[0].reg;
11734 Rn = inst.operands[2].reg;
11735
11736 reject_bad_reg (Rd);
11737 reject_bad_reg (Rn);
11738
11739 inst.instruction |= Rd << 8;
c19d1205 11740 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 11741 inst.instruction |= Rn << 16;
c19d1205 11742}
0dd132b6 11743
c19d1205
ZW
11744static void
11745do_t_strex (void)
11746{
11747 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11748 || inst.operands[2].postind || inst.operands[2].writeback
11749 || inst.operands[2].immisreg || inst.operands[2].shifted
11750 || inst.operands[2].negative,
01cfc07f 11751 BAD_ADDR_MODE);
0dd132b6 11752
5be8be5d
DG
11753 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11754
c19d1205
ZW
11755 inst.instruction |= inst.operands[0].reg << 8;
11756 inst.instruction |= inst.operands[1].reg << 12;
11757 inst.instruction |= inst.operands[2].reg << 16;
11758 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
11759}
11760
b99bd4ef 11761static void
c19d1205 11762do_t_strexd (void)
b99bd4ef 11763{
c19d1205
ZW
11764 if (!inst.operands[2].present)
11765 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 11766
c19d1205
ZW
11767 constraint (inst.operands[0].reg == inst.operands[1].reg
11768 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 11769 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 11770 BAD_OVERLAP);
b99bd4ef 11771
c19d1205
ZW
11772 inst.instruction |= inst.operands[0].reg;
11773 inst.instruction |= inst.operands[1].reg << 12;
11774 inst.instruction |= inst.operands[2].reg << 8;
11775 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
11776}
11777
11778static void
c19d1205 11779do_t_sxtah (void)
b99bd4ef 11780{
fdfde340
JM
11781 unsigned Rd, Rn, Rm;
11782
11783 Rd = inst.operands[0].reg;
11784 Rn = inst.operands[1].reg;
11785 Rm = inst.operands[2].reg;
11786
11787 reject_bad_reg (Rd);
11788 reject_bad_reg (Rn);
11789 reject_bad_reg (Rm);
11790
11791 inst.instruction |= Rd << 8;
11792 inst.instruction |= Rn << 16;
11793 inst.instruction |= Rm;
c19d1205
ZW
11794 inst.instruction |= inst.operands[3].imm << 4;
11795}
b99bd4ef 11796
c19d1205
ZW
11797static void
11798do_t_sxth (void)
11799{
fdfde340
JM
11800 unsigned Rd, Rm;
11801
11802 Rd = inst.operands[0].reg;
11803 Rm = inst.operands[1].reg;
11804
11805 reject_bad_reg (Rd);
11806 reject_bad_reg (Rm);
c921be7d
NC
11807
11808 if (inst.instruction <= 0xffff
11809 && inst.size_req != 4
fdfde340 11810 && Rd <= 7 && Rm <= 7
c19d1205 11811 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 11812 {
c19d1205 11813 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11814 inst.instruction |= Rd;
11815 inst.instruction |= Rm << 3;
b99bd4ef 11816 }
c19d1205 11817 else if (unified_syntax)
b99bd4ef 11818 {
c19d1205
ZW
11819 if (inst.instruction <= 0xffff)
11820 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11821 inst.instruction |= Rd << 8;
11822 inst.instruction |= Rm;
c19d1205 11823 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 11824 }
c19d1205 11825 else
b99bd4ef 11826 {
c19d1205
ZW
11827 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11828 _("Thumb encoding does not support rotation"));
11829 constraint (1, BAD_HIREG);
b99bd4ef 11830 }
c19d1205 11831}
b99bd4ef 11832
c19d1205
ZW
11833static void
11834do_t_swi (void)
11835{
b2a5fbdc
MGD
11836 /* We have to do the following check manually as ARM_EXT_OS only applies
11837 to ARM_EXT_V6M. */
11838 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
11839 {
ac7f631b
NC
11840 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
11841 /* This only applies to the v6m howver, not later architectures. */
11842 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
11843 as_bad (_("SVC is not permitted on this architecture"));
11844 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
11845 }
11846
c19d1205
ZW
11847 inst.reloc.type = BFD_RELOC_ARM_SWI;
11848}
b99bd4ef 11849
92e90b6e
PB
11850static void
11851do_t_tb (void)
11852{
fdfde340 11853 unsigned Rn, Rm;
92e90b6e
PB
11854 int half;
11855
11856 half = (inst.instruction & 0x10) != 0;
e07e6e58 11857 set_it_insn_type_last ();
dfa9f0d5
PB
11858 constraint (inst.operands[0].immisreg,
11859 _("instruction requires register index"));
fdfde340
JM
11860
11861 Rn = inst.operands[0].reg;
11862 Rm = inst.operands[0].imm;
c921be7d 11863
fdfde340
JM
11864 constraint (Rn == REG_SP, BAD_SP);
11865 reject_bad_reg (Rm);
11866
92e90b6e
PB
11867 constraint (!half && inst.operands[0].shifted,
11868 _("instruction does not allow shifted index"));
fdfde340 11869 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
11870}
11871
c19d1205
ZW
11872static void
11873do_t_usat (void)
11874{
3a21c15a 11875 do_t_ssat_usat (0);
b99bd4ef
NC
11876}
11877
11878static void
c19d1205 11879do_t_usat16 (void)
b99bd4ef 11880{
fdfde340
JM
11881 unsigned Rd, Rn;
11882
11883 Rd = inst.operands[0].reg;
11884 Rn = inst.operands[2].reg;
11885
11886 reject_bad_reg (Rd);
11887 reject_bad_reg (Rn);
11888
11889 inst.instruction |= Rd << 8;
c19d1205 11890 inst.instruction |= inst.operands[1].imm;
fdfde340 11891 inst.instruction |= Rn << 16;
b99bd4ef 11892}
c19d1205 11893
5287ad62 11894/* Neon instruction encoder helpers. */
5f4273c7 11895
5287ad62 11896/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 11897
5287ad62
JB
11898/* An "invalid" code for the following tables. */
11899#define N_INV -1u
11900
11901struct neon_tab_entry
b99bd4ef 11902{
5287ad62
JB
11903 unsigned integer;
11904 unsigned float_or_poly;
11905 unsigned scalar_or_imm;
11906};
5f4273c7 11907
5287ad62
JB
11908/* Map overloaded Neon opcodes to their respective encodings. */
11909#define NEON_ENC_TAB \
11910 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11911 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11912 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11913 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11914 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11915 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11916 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11917 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11918 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11919 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11920 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11921 /* Register variants of the following two instructions are encoded as
e07e6e58 11922 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
11923 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11924 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
11925 X(vfma, N_INV, 0x0000c10, N_INV), \
11926 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
11927 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11928 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11929 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11930 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11931 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11932 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11933 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11934 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11935 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11936 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11937 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11938 X(vshl, 0x0000400, N_INV, 0x0800510), \
11939 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11940 X(vand, 0x0000110, N_INV, 0x0800030), \
11941 X(vbic, 0x0100110, N_INV, 0x0800030), \
11942 X(veor, 0x1000110, N_INV, N_INV), \
11943 X(vorn, 0x0300110, N_INV, 0x0800010), \
11944 X(vorr, 0x0200110, N_INV, 0x0800010), \
11945 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11946 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11947 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11948 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11949 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11950 X(vst1, 0x0000000, 0x0800000, N_INV), \
11951 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11952 X(vst2, 0x0000100, 0x0800100, N_INV), \
11953 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11954 X(vst3, 0x0000200, 0x0800200, N_INV), \
11955 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11956 X(vst4, 0x0000300, 0x0800300, N_INV), \
11957 X(vmovn, 0x1b20200, N_INV, N_INV), \
11958 X(vtrn, 0x1b20080, N_INV, N_INV), \
11959 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
11960 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11961 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
11962 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11963 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
11964 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11965 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
11966 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11967 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11968 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11969 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
11970
11971enum neon_opc
11972{
11973#define X(OPC,I,F,S) N_MNEM_##OPC
11974NEON_ENC_TAB
11975#undef X
11976};
b99bd4ef 11977
5287ad62
JB
11978static const struct neon_tab_entry neon_enc_tab[] =
11979{
11980#define X(OPC,I,F,S) { (I), (F), (S) }
11981NEON_ENC_TAB
11982#undef X
11983};
b99bd4ef 11984
88714cb8
DG
11985/* Do not use these macros; instead, use NEON_ENCODE defined below. */
11986#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11987#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11988#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11989#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11990#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11991#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11992#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11993#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11994#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11995#define NEON_ENC_SINGLE_(X) \
037e8744 11996 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 11997#define NEON_ENC_DOUBLE_(X) \
037e8744 11998 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 11999
88714cb8
DG
12000#define NEON_ENCODE(type, inst) \
12001 do \
12002 { \
12003 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
12004 inst.is_neon = 1; \
12005 } \
12006 while (0)
12007
12008#define check_neon_suffixes \
12009 do \
12010 { \
12011 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
12012 { \
12013 as_bad (_("invalid neon suffix for non neon instruction")); \
12014 return; \
12015 } \
12016 } \
12017 while (0)
12018
037e8744
JB
12019/* Define shapes for instruction operands. The following mnemonic characters
12020 are used in this table:
5287ad62 12021
037e8744 12022 F - VFP S<n> register
5287ad62
JB
12023 D - Neon D<n> register
12024 Q - Neon Q<n> register
12025 I - Immediate
12026 S - Scalar
12027 R - ARM register
12028 L - D<n> register list
5f4273c7 12029
037e8744
JB
12030 This table is used to generate various data:
12031 - enumerations of the form NS_DDR to be used as arguments to
12032 neon_select_shape.
12033 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 12034 - a table used to drive neon_select_shape. */
b99bd4ef 12035
037e8744
JB
12036#define NEON_SHAPE_DEF \
12037 X(3, (D, D, D), DOUBLE), \
12038 X(3, (Q, Q, Q), QUAD), \
12039 X(3, (D, D, I), DOUBLE), \
12040 X(3, (Q, Q, I), QUAD), \
12041 X(3, (D, D, S), DOUBLE), \
12042 X(3, (Q, Q, S), QUAD), \
12043 X(2, (D, D), DOUBLE), \
12044 X(2, (Q, Q), QUAD), \
12045 X(2, (D, S), DOUBLE), \
12046 X(2, (Q, S), QUAD), \
12047 X(2, (D, R), DOUBLE), \
12048 X(2, (Q, R), QUAD), \
12049 X(2, (D, I), DOUBLE), \
12050 X(2, (Q, I), QUAD), \
12051 X(3, (D, L, D), DOUBLE), \
12052 X(2, (D, Q), MIXED), \
12053 X(2, (Q, D), MIXED), \
12054 X(3, (D, Q, I), MIXED), \
12055 X(3, (Q, D, I), MIXED), \
12056 X(3, (Q, D, D), MIXED), \
12057 X(3, (D, Q, Q), MIXED), \
12058 X(3, (Q, Q, D), MIXED), \
12059 X(3, (Q, D, S), MIXED), \
12060 X(3, (D, Q, S), MIXED), \
12061 X(4, (D, D, D, I), DOUBLE), \
12062 X(4, (Q, Q, Q, I), QUAD), \
12063 X(2, (F, F), SINGLE), \
12064 X(3, (F, F, F), SINGLE), \
12065 X(2, (F, I), SINGLE), \
12066 X(2, (F, D), MIXED), \
12067 X(2, (D, F), MIXED), \
12068 X(3, (F, F, I), MIXED), \
12069 X(4, (R, R, F, F), SINGLE), \
12070 X(4, (F, F, R, R), SINGLE), \
12071 X(3, (D, R, R), DOUBLE), \
12072 X(3, (R, R, D), DOUBLE), \
12073 X(2, (S, R), SINGLE), \
12074 X(2, (R, S), SINGLE), \
12075 X(2, (F, R), SINGLE), \
12076 X(2, (R, F), SINGLE)
12077
12078#define S2(A,B) NS_##A##B
12079#define S3(A,B,C) NS_##A##B##C
12080#define S4(A,B,C,D) NS_##A##B##C##D
12081
12082#define X(N, L, C) S##N L
12083
5287ad62
JB
12084enum neon_shape
12085{
037e8744
JB
12086 NEON_SHAPE_DEF,
12087 NS_NULL
5287ad62 12088};
b99bd4ef 12089
037e8744
JB
12090#undef X
12091#undef S2
12092#undef S3
12093#undef S4
12094
12095enum neon_shape_class
12096{
12097 SC_SINGLE,
12098 SC_DOUBLE,
12099 SC_QUAD,
12100 SC_MIXED
12101};
12102
12103#define X(N, L, C) SC_##C
12104
12105static enum neon_shape_class neon_shape_class[] =
12106{
12107 NEON_SHAPE_DEF
12108};
12109
12110#undef X
12111
12112enum neon_shape_el
12113{
12114 SE_F,
12115 SE_D,
12116 SE_Q,
12117 SE_I,
12118 SE_S,
12119 SE_R,
12120 SE_L
12121};
12122
12123/* Register widths of above. */
12124static unsigned neon_shape_el_size[] =
12125{
12126 32,
12127 64,
12128 128,
12129 0,
12130 32,
12131 32,
12132 0
12133};
12134
12135struct neon_shape_info
12136{
12137 unsigned els;
12138 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
12139};
12140
12141#define S2(A,B) { SE_##A, SE_##B }
12142#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
12143#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
12144
12145#define X(N, L, C) { N, S##N L }
12146
12147static struct neon_shape_info neon_shape_tab[] =
12148{
12149 NEON_SHAPE_DEF
12150};
12151
12152#undef X
12153#undef S2
12154#undef S3
12155#undef S4
12156
5287ad62
JB
12157/* Bit masks used in type checking given instructions.
12158 'N_EQK' means the type must be the same as (or based on in some way) the key
12159 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
12160 set, various other bits can be set as well in order to modify the meaning of
12161 the type constraint. */
12162
12163enum neon_type_mask
12164{
8e79c3df
CM
12165 N_S8 = 0x0000001,
12166 N_S16 = 0x0000002,
12167 N_S32 = 0x0000004,
12168 N_S64 = 0x0000008,
12169 N_U8 = 0x0000010,
12170 N_U16 = 0x0000020,
12171 N_U32 = 0x0000040,
12172 N_U64 = 0x0000080,
12173 N_I8 = 0x0000100,
12174 N_I16 = 0x0000200,
12175 N_I32 = 0x0000400,
12176 N_I64 = 0x0000800,
12177 N_8 = 0x0001000,
12178 N_16 = 0x0002000,
12179 N_32 = 0x0004000,
12180 N_64 = 0x0008000,
12181 N_P8 = 0x0010000,
12182 N_P16 = 0x0020000,
12183 N_F16 = 0x0040000,
12184 N_F32 = 0x0080000,
12185 N_F64 = 0x0100000,
c921be7d
NC
12186 N_KEY = 0x1000000, /* Key element (main type specifier). */
12187 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 12188 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
c921be7d
NC
12189 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
12190 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
12191 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
12192 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
12193 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
12194 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
12195 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 12196 N_UTYP = 0,
037e8744 12197 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
12198};
12199
dcbf9037
JB
12200#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
12201
5287ad62
JB
12202#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
12203#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
12204#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
12205#define N_SUF_32 (N_SU_32 | N_F32)
12206#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
12207#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
12208
12209/* Pass this as the first type argument to neon_check_type to ignore types
12210 altogether. */
12211#define N_IGNORE_TYPE (N_KEY | N_EQK)
12212
037e8744
JB
12213/* Select a "shape" for the current instruction (describing register types or
12214 sizes) from a list of alternatives. Return NS_NULL if the current instruction
12215 doesn't fit. For non-polymorphic shapes, checking is usually done as a
12216 function of operand parsing, so this function doesn't need to be called.
12217 Shapes should be listed in order of decreasing length. */
5287ad62
JB
12218
12219static enum neon_shape
037e8744 12220neon_select_shape (enum neon_shape shape, ...)
5287ad62 12221{
037e8744
JB
12222 va_list ap;
12223 enum neon_shape first_shape = shape;
5287ad62
JB
12224
12225 /* Fix missing optional operands. FIXME: we don't know at this point how
12226 many arguments we should have, so this makes the assumption that we have
12227 > 1. This is true of all current Neon opcodes, I think, but may not be
12228 true in the future. */
12229 if (!inst.operands[1].present)
12230 inst.operands[1] = inst.operands[0];
12231
037e8744 12232 va_start (ap, shape);
5f4273c7 12233
21d799b5 12234 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
12235 {
12236 unsigned j;
12237 int matches = 1;
12238
12239 for (j = 0; j < neon_shape_tab[shape].els; j++)
12240 {
12241 if (!inst.operands[j].present)
12242 {
12243 matches = 0;
12244 break;
12245 }
12246
12247 switch (neon_shape_tab[shape].el[j])
12248 {
12249 case SE_F:
12250 if (!(inst.operands[j].isreg
12251 && inst.operands[j].isvec
12252 && inst.operands[j].issingle
12253 && !inst.operands[j].isquad))
12254 matches = 0;
12255 break;
12256
12257 case SE_D:
12258 if (!(inst.operands[j].isreg
12259 && inst.operands[j].isvec
12260 && !inst.operands[j].isquad
12261 && !inst.operands[j].issingle))
12262 matches = 0;
12263 break;
12264
12265 case SE_R:
12266 if (!(inst.operands[j].isreg
12267 && !inst.operands[j].isvec))
12268 matches = 0;
12269 break;
12270
12271 case SE_Q:
12272 if (!(inst.operands[j].isreg
12273 && inst.operands[j].isvec
12274 && inst.operands[j].isquad
12275 && !inst.operands[j].issingle))
12276 matches = 0;
12277 break;
12278
12279 case SE_I:
12280 if (!(!inst.operands[j].isreg
12281 && !inst.operands[j].isscalar))
12282 matches = 0;
12283 break;
12284
12285 case SE_S:
12286 if (!(!inst.operands[j].isreg
12287 && inst.operands[j].isscalar))
12288 matches = 0;
12289 break;
12290
12291 case SE_L:
12292 break;
12293 }
3fde54a2
JZ
12294 if (!matches)
12295 break;
037e8744
JB
12296 }
12297 if (matches)
5287ad62 12298 break;
037e8744 12299 }
5f4273c7 12300
037e8744 12301 va_end (ap);
5287ad62 12302
037e8744
JB
12303 if (shape == NS_NULL && first_shape != NS_NULL)
12304 first_error (_("invalid instruction shape"));
5287ad62 12305
037e8744
JB
12306 return shape;
12307}
5287ad62 12308
037e8744
JB
12309/* True if SHAPE is predominantly a quadword operation (most of the time, this
12310 means the Q bit should be set). */
12311
12312static int
12313neon_quad (enum neon_shape shape)
12314{
12315 return neon_shape_class[shape] == SC_QUAD;
5287ad62 12316}
037e8744 12317
5287ad62
JB
12318static void
12319neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
12320 unsigned *g_size)
12321{
12322 /* Allow modification to be made to types which are constrained to be
12323 based on the key element, based on bits set alongside N_EQK. */
12324 if ((typebits & N_EQK) != 0)
12325 {
12326 if ((typebits & N_HLF) != 0)
12327 *g_size /= 2;
12328 else if ((typebits & N_DBL) != 0)
12329 *g_size *= 2;
12330 if ((typebits & N_SGN) != 0)
12331 *g_type = NT_signed;
12332 else if ((typebits & N_UNS) != 0)
12333 *g_type = NT_unsigned;
12334 else if ((typebits & N_INT) != 0)
12335 *g_type = NT_integer;
12336 else if ((typebits & N_FLT) != 0)
12337 *g_type = NT_float;
dcbf9037
JB
12338 else if ((typebits & N_SIZ) != 0)
12339 *g_type = NT_untyped;
5287ad62
JB
12340 }
12341}
5f4273c7 12342
5287ad62
JB
12343/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12344 operand type, i.e. the single type specified in a Neon instruction when it
12345 is the only one given. */
12346
12347static struct neon_type_el
12348neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12349{
12350 struct neon_type_el dest = *key;
5f4273c7 12351
9c2799c2 12352 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 12353
5287ad62
JB
12354 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12355
12356 return dest;
12357}
12358
12359/* Convert Neon type and size into compact bitmask representation. */
12360
12361static enum neon_type_mask
12362type_chk_of_el_type (enum neon_el_type type, unsigned size)
12363{
12364 switch (type)
12365 {
12366 case NT_untyped:
12367 switch (size)
12368 {
12369 case 8: return N_8;
12370 case 16: return N_16;
12371 case 32: return N_32;
12372 case 64: return N_64;
12373 default: ;
12374 }
12375 break;
12376
12377 case NT_integer:
12378 switch (size)
12379 {
12380 case 8: return N_I8;
12381 case 16: return N_I16;
12382 case 32: return N_I32;
12383 case 64: return N_I64;
12384 default: ;
12385 }
12386 break;
12387
12388 case NT_float:
037e8744
JB
12389 switch (size)
12390 {
8e79c3df 12391 case 16: return N_F16;
037e8744
JB
12392 case 32: return N_F32;
12393 case 64: return N_F64;
12394 default: ;
12395 }
5287ad62
JB
12396 break;
12397
12398 case NT_poly:
12399 switch (size)
12400 {
12401 case 8: return N_P8;
12402 case 16: return N_P16;
12403 default: ;
12404 }
12405 break;
12406
12407 case NT_signed:
12408 switch (size)
12409 {
12410 case 8: return N_S8;
12411 case 16: return N_S16;
12412 case 32: return N_S32;
12413 case 64: return N_S64;
12414 default: ;
12415 }
12416 break;
12417
12418 case NT_unsigned:
12419 switch (size)
12420 {
12421 case 8: return N_U8;
12422 case 16: return N_U16;
12423 case 32: return N_U32;
12424 case 64: return N_U64;
12425 default: ;
12426 }
12427 break;
12428
12429 default: ;
12430 }
5f4273c7 12431
5287ad62
JB
12432 return N_UTYP;
12433}
12434
12435/* Convert compact Neon bitmask type representation to a type and size. Only
12436 handles the case where a single bit is set in the mask. */
12437
dcbf9037 12438static int
5287ad62
JB
12439el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12440 enum neon_type_mask mask)
12441{
dcbf9037
JB
12442 if ((mask & N_EQK) != 0)
12443 return FAIL;
12444
5287ad62
JB
12445 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12446 *size = 8;
dcbf9037 12447 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 12448 *size = 16;
dcbf9037 12449 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 12450 *size = 32;
037e8744 12451 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 12452 *size = 64;
dcbf9037
JB
12453 else
12454 return FAIL;
12455
5287ad62
JB
12456 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12457 *type = NT_signed;
dcbf9037 12458 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 12459 *type = NT_unsigned;
dcbf9037 12460 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 12461 *type = NT_integer;
dcbf9037 12462 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 12463 *type = NT_untyped;
dcbf9037 12464 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 12465 *type = NT_poly;
037e8744 12466 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 12467 *type = NT_float;
dcbf9037
JB
12468 else
12469 return FAIL;
5f4273c7 12470
dcbf9037 12471 return SUCCESS;
5287ad62
JB
12472}
12473
12474/* Modify a bitmask of allowed types. This is only needed for type
12475 relaxation. */
12476
12477static unsigned
12478modify_types_allowed (unsigned allowed, unsigned mods)
12479{
12480 unsigned size;
12481 enum neon_el_type type;
12482 unsigned destmask;
12483 int i;
5f4273c7 12484
5287ad62 12485 destmask = 0;
5f4273c7 12486
5287ad62
JB
12487 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12488 {
21d799b5
NC
12489 if (el_type_of_type_chk (&type, &size,
12490 (enum neon_type_mask) (allowed & i)) == SUCCESS)
dcbf9037
JB
12491 {
12492 neon_modify_type_size (mods, &type, &size);
12493 destmask |= type_chk_of_el_type (type, size);
12494 }
5287ad62 12495 }
5f4273c7 12496
5287ad62
JB
12497 return destmask;
12498}
12499
12500/* Check type and return type classification.
12501 The manual states (paraphrase): If one datatype is given, it indicates the
12502 type given in:
12503 - the second operand, if there is one
12504 - the operand, if there is no second operand
12505 - the result, if there are no operands.
12506 This isn't quite good enough though, so we use a concept of a "key" datatype
12507 which is set on a per-instruction basis, which is the one which matters when
12508 only one data type is written.
12509 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 12510 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
12511
12512static struct neon_type_el
12513neon_check_type (unsigned els, enum neon_shape ns, ...)
12514{
12515 va_list ap;
12516 unsigned i, pass, key_el = 0;
12517 unsigned types[NEON_MAX_TYPE_ELS];
12518 enum neon_el_type k_type = NT_invtype;
12519 unsigned k_size = -1u;
12520 struct neon_type_el badtype = {NT_invtype, -1};
12521 unsigned key_allowed = 0;
12522
12523 /* Optional registers in Neon instructions are always (not) in operand 1.
12524 Fill in the missing operand here, if it was omitted. */
12525 if (els > 1 && !inst.operands[1].present)
12526 inst.operands[1] = inst.operands[0];
12527
12528 /* Suck up all the varargs. */
12529 va_start (ap, ns);
12530 for (i = 0; i < els; i++)
12531 {
12532 unsigned thisarg = va_arg (ap, unsigned);
12533 if (thisarg == N_IGNORE_TYPE)
12534 {
12535 va_end (ap);
12536 return badtype;
12537 }
12538 types[i] = thisarg;
12539 if ((thisarg & N_KEY) != 0)
12540 key_el = i;
12541 }
12542 va_end (ap);
12543
dcbf9037
JB
12544 if (inst.vectype.elems > 0)
12545 for (i = 0; i < els; i++)
12546 if (inst.operands[i].vectype.type != NT_invtype)
12547 {
12548 first_error (_("types specified in both the mnemonic and operands"));
12549 return badtype;
12550 }
12551
5287ad62
JB
12552 /* Duplicate inst.vectype elements here as necessary.
12553 FIXME: No idea if this is exactly the same as the ARM assembler,
12554 particularly when an insn takes one register and one non-register
12555 operand. */
12556 if (inst.vectype.elems == 1 && els > 1)
12557 {
12558 unsigned j;
12559 inst.vectype.elems = els;
12560 inst.vectype.el[key_el] = inst.vectype.el[0];
12561 for (j = 0; j < els; j++)
dcbf9037
JB
12562 if (j != key_el)
12563 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12564 types[j]);
12565 }
12566 else if (inst.vectype.elems == 0 && els > 0)
12567 {
12568 unsigned j;
12569 /* No types were given after the mnemonic, so look for types specified
12570 after each operand. We allow some flexibility here; as long as the
12571 "key" operand has a type, we can infer the others. */
12572 for (j = 0; j < els; j++)
12573 if (inst.operands[j].vectype.type != NT_invtype)
12574 inst.vectype.el[j] = inst.operands[j].vectype;
12575
12576 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 12577 {
dcbf9037
JB
12578 for (j = 0; j < els; j++)
12579 if (inst.operands[j].vectype.type == NT_invtype)
12580 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12581 types[j]);
12582 }
12583 else
12584 {
12585 first_error (_("operand types can't be inferred"));
12586 return badtype;
5287ad62
JB
12587 }
12588 }
12589 else if (inst.vectype.elems != els)
12590 {
dcbf9037 12591 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
12592 return badtype;
12593 }
12594
12595 for (pass = 0; pass < 2; pass++)
12596 {
12597 for (i = 0; i < els; i++)
12598 {
12599 unsigned thisarg = types[i];
12600 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12601 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12602 enum neon_el_type g_type = inst.vectype.el[i].type;
12603 unsigned g_size = inst.vectype.el[i].size;
12604
12605 /* Decay more-specific signed & unsigned types to sign-insensitive
12606 integer types if sign-specific variants are unavailable. */
12607 if ((g_type == NT_signed || g_type == NT_unsigned)
12608 && (types_allowed & N_SU_ALL) == 0)
12609 g_type = NT_integer;
12610
12611 /* If only untyped args are allowed, decay any more specific types to
12612 them. Some instructions only care about signs for some element
12613 sizes, so handle that properly. */
12614 if ((g_size == 8 && (types_allowed & N_8) != 0)
12615 || (g_size == 16 && (types_allowed & N_16) != 0)
12616 || (g_size == 32 && (types_allowed & N_32) != 0)
12617 || (g_size == 64 && (types_allowed & N_64) != 0))
12618 g_type = NT_untyped;
12619
12620 if (pass == 0)
12621 {
12622 if ((thisarg & N_KEY) != 0)
12623 {
12624 k_type = g_type;
12625 k_size = g_size;
12626 key_allowed = thisarg & ~N_KEY;
12627 }
12628 }
12629 else
12630 {
037e8744
JB
12631 if ((thisarg & N_VFP) != 0)
12632 {
99b253c5
NC
12633 enum neon_shape_el regshape;
12634 unsigned regwidth, match;
12635
12636 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12637 if (ns == NS_NULL)
12638 {
12639 first_error (_("invalid instruction shape"));
12640 return badtype;
12641 }
12642 regshape = neon_shape_tab[ns].el[i];
12643 regwidth = neon_shape_el_size[regshape];
037e8744
JB
12644
12645 /* In VFP mode, operands must match register widths. If we
12646 have a key operand, use its width, else use the width of
12647 the current operand. */
12648 if (k_size != -1u)
12649 match = k_size;
12650 else
12651 match = g_size;
12652
12653 if (regwidth != match)
12654 {
12655 first_error (_("operand size must match register width"));
12656 return badtype;
12657 }
12658 }
5f4273c7 12659
5287ad62
JB
12660 if ((thisarg & N_EQK) == 0)
12661 {
12662 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12663
12664 if ((given_type & types_allowed) == 0)
12665 {
dcbf9037 12666 first_error (_("bad type in Neon instruction"));
5287ad62
JB
12667 return badtype;
12668 }
12669 }
12670 else
12671 {
12672 enum neon_el_type mod_k_type = k_type;
12673 unsigned mod_k_size = k_size;
12674 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12675 if (g_type != mod_k_type || g_size != mod_k_size)
12676 {
dcbf9037 12677 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
12678 return badtype;
12679 }
12680 }
12681 }
12682 }
12683 }
12684
12685 return inst.vectype.el[key_el];
12686}
12687
037e8744 12688/* Neon-style VFP instruction forwarding. */
5287ad62 12689
037e8744
JB
12690/* Thumb VFP instructions have 0xE in the condition field. */
12691
12692static void
12693do_vfp_cond_or_thumb (void)
5287ad62 12694{
88714cb8
DG
12695 inst.is_neon = 1;
12696
5287ad62 12697 if (thumb_mode)
037e8744 12698 inst.instruction |= 0xe0000000;
5287ad62 12699 else
037e8744 12700 inst.instruction |= inst.cond << 28;
5287ad62
JB
12701}
12702
037e8744
JB
12703/* Look up and encode a simple mnemonic, for use as a helper function for the
12704 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12705 etc. It is assumed that operand parsing has already been done, and that the
12706 operands are in the form expected by the given opcode (this isn't necessarily
12707 the same as the form in which they were parsed, hence some massaging must
12708 take place before this function is called).
12709 Checks current arch version against that in the looked-up opcode. */
5287ad62 12710
037e8744
JB
12711static void
12712do_vfp_nsyn_opcode (const char *opname)
5287ad62 12713{
037e8744 12714 const struct asm_opcode *opcode;
5f4273c7 12715
21d799b5 12716 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 12717
037e8744
JB
12718 if (!opcode)
12719 abort ();
5287ad62 12720
037e8744
JB
12721 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12722 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12723 _(BAD_FPU));
5287ad62 12724
88714cb8
DG
12725 inst.is_neon = 1;
12726
037e8744
JB
12727 if (thumb_mode)
12728 {
12729 inst.instruction = opcode->tvalue;
12730 opcode->tencode ();
12731 }
12732 else
12733 {
12734 inst.instruction = (inst.cond << 28) | opcode->avalue;
12735 opcode->aencode ();
12736 }
12737}
5287ad62
JB
12738
12739static void
037e8744 12740do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 12741{
037e8744
JB
12742 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12743
12744 if (rs == NS_FFF)
12745 {
12746 if (is_add)
12747 do_vfp_nsyn_opcode ("fadds");
12748 else
12749 do_vfp_nsyn_opcode ("fsubs");
12750 }
12751 else
12752 {
12753 if (is_add)
12754 do_vfp_nsyn_opcode ("faddd");
12755 else
12756 do_vfp_nsyn_opcode ("fsubd");
12757 }
12758}
12759
12760/* Check operand types to see if this is a VFP instruction, and if so call
12761 PFN (). */
12762
12763static int
12764try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12765{
12766 enum neon_shape rs;
12767 struct neon_type_el et;
12768
12769 switch (args)
12770 {
12771 case 2:
12772 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12773 et = neon_check_type (2, rs,
12774 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12775 break;
5f4273c7 12776
037e8744
JB
12777 case 3:
12778 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12779 et = neon_check_type (3, rs,
12780 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12781 break;
12782
12783 default:
12784 abort ();
12785 }
12786
12787 if (et.type != NT_invtype)
12788 {
12789 pfn (rs);
12790 return SUCCESS;
12791 }
037e8744 12792
99b253c5 12793 inst.error = NULL;
037e8744
JB
12794 return FAIL;
12795}
12796
12797static void
12798do_vfp_nsyn_mla_mls (enum neon_shape rs)
12799{
12800 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 12801
037e8744
JB
12802 if (rs == NS_FFF)
12803 {
12804 if (is_mla)
12805 do_vfp_nsyn_opcode ("fmacs");
12806 else
1ee69515 12807 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
12808 }
12809 else
12810 {
12811 if (is_mla)
12812 do_vfp_nsyn_opcode ("fmacd");
12813 else
1ee69515 12814 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
12815 }
12816}
12817
62f3b8c8
PB
12818static void
12819do_vfp_nsyn_fma_fms (enum neon_shape rs)
12820{
12821 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12822
12823 if (rs == NS_FFF)
12824 {
12825 if (is_fma)
12826 do_vfp_nsyn_opcode ("ffmas");
12827 else
12828 do_vfp_nsyn_opcode ("ffnmas");
12829 }
12830 else
12831 {
12832 if (is_fma)
12833 do_vfp_nsyn_opcode ("ffmad");
12834 else
12835 do_vfp_nsyn_opcode ("ffnmad");
12836 }
12837}
12838
037e8744
JB
12839static void
12840do_vfp_nsyn_mul (enum neon_shape rs)
12841{
12842 if (rs == NS_FFF)
12843 do_vfp_nsyn_opcode ("fmuls");
12844 else
12845 do_vfp_nsyn_opcode ("fmuld");
12846}
12847
12848static void
12849do_vfp_nsyn_abs_neg (enum neon_shape rs)
12850{
12851 int is_neg = (inst.instruction & 0x80) != 0;
12852 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12853
12854 if (rs == NS_FF)
12855 {
12856 if (is_neg)
12857 do_vfp_nsyn_opcode ("fnegs");
12858 else
12859 do_vfp_nsyn_opcode ("fabss");
12860 }
12861 else
12862 {
12863 if (is_neg)
12864 do_vfp_nsyn_opcode ("fnegd");
12865 else
12866 do_vfp_nsyn_opcode ("fabsd");
12867 }
12868}
12869
12870/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12871 insns belong to Neon, and are handled elsewhere. */
12872
12873static void
12874do_vfp_nsyn_ldm_stm (int is_dbmode)
12875{
12876 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12877 if (is_ldm)
12878 {
12879 if (is_dbmode)
12880 do_vfp_nsyn_opcode ("fldmdbs");
12881 else
12882 do_vfp_nsyn_opcode ("fldmias");
12883 }
12884 else
12885 {
12886 if (is_dbmode)
12887 do_vfp_nsyn_opcode ("fstmdbs");
12888 else
12889 do_vfp_nsyn_opcode ("fstmias");
12890 }
12891}
12892
037e8744
JB
12893static void
12894do_vfp_nsyn_sqrt (void)
12895{
12896 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12897 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12898
037e8744
JB
12899 if (rs == NS_FF)
12900 do_vfp_nsyn_opcode ("fsqrts");
12901 else
12902 do_vfp_nsyn_opcode ("fsqrtd");
12903}
12904
12905static void
12906do_vfp_nsyn_div (void)
12907{
12908 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12909 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12910 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12911
037e8744
JB
12912 if (rs == NS_FFF)
12913 do_vfp_nsyn_opcode ("fdivs");
12914 else
12915 do_vfp_nsyn_opcode ("fdivd");
12916}
12917
12918static void
12919do_vfp_nsyn_nmul (void)
12920{
12921 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12922 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12923 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12924
037e8744
JB
12925 if (rs == NS_FFF)
12926 {
88714cb8 12927 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12928 do_vfp_sp_dyadic ();
12929 }
12930 else
12931 {
88714cb8 12932 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12933 do_vfp_dp_rd_rn_rm ();
12934 }
12935 do_vfp_cond_or_thumb ();
12936}
12937
12938static void
12939do_vfp_nsyn_cmp (void)
12940{
12941 if (inst.operands[1].isreg)
12942 {
12943 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12944 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12945
037e8744
JB
12946 if (rs == NS_FF)
12947 {
88714cb8 12948 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12949 do_vfp_sp_monadic ();
12950 }
12951 else
12952 {
88714cb8 12953 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12954 do_vfp_dp_rd_rm ();
12955 }
12956 }
12957 else
12958 {
12959 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12960 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12961
12962 switch (inst.instruction & 0x0fffffff)
12963 {
12964 case N_MNEM_vcmp:
12965 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12966 break;
12967 case N_MNEM_vcmpe:
12968 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12969 break;
12970 default:
12971 abort ();
12972 }
5f4273c7 12973
037e8744
JB
12974 if (rs == NS_FI)
12975 {
88714cb8 12976 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12977 do_vfp_sp_compare_z ();
12978 }
12979 else
12980 {
88714cb8 12981 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12982 do_vfp_dp_rd ();
12983 }
12984 }
12985 do_vfp_cond_or_thumb ();
12986}
12987
12988static void
12989nsyn_insert_sp (void)
12990{
12991 inst.operands[1] = inst.operands[0];
12992 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 12993 inst.operands[0].reg = REG_SP;
037e8744
JB
12994 inst.operands[0].isreg = 1;
12995 inst.operands[0].writeback = 1;
12996 inst.operands[0].present = 1;
12997}
12998
12999static void
13000do_vfp_nsyn_push (void)
13001{
13002 nsyn_insert_sp ();
13003 if (inst.operands[1].issingle)
13004 do_vfp_nsyn_opcode ("fstmdbs");
13005 else
13006 do_vfp_nsyn_opcode ("fstmdbd");
13007}
13008
13009static void
13010do_vfp_nsyn_pop (void)
13011{
13012 nsyn_insert_sp ();
13013 if (inst.operands[1].issingle)
22b5b651 13014 do_vfp_nsyn_opcode ("fldmias");
037e8744 13015 else
22b5b651 13016 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
13017}
13018
13019/* Fix up Neon data-processing instructions, ORing in the correct bits for
13020 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
13021
88714cb8
DG
13022static void
13023neon_dp_fixup (struct arm_it* insn)
037e8744 13024{
88714cb8
DG
13025 unsigned int i = insn->instruction;
13026 insn->is_neon = 1;
13027
037e8744
JB
13028 if (thumb_mode)
13029 {
13030 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
13031 if (i & (1 << 24))
13032 i |= 1 << 28;
5f4273c7 13033
037e8744 13034 i &= ~(1 << 24);
5f4273c7 13035
037e8744
JB
13036 i |= 0xef000000;
13037 }
13038 else
13039 i |= 0xf2000000;
5f4273c7 13040
88714cb8 13041 insn->instruction = i;
037e8744
JB
13042}
13043
13044/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
13045 (0, 1, 2, 3). */
13046
13047static unsigned
13048neon_logbits (unsigned x)
13049{
13050 return ffs (x) - 4;
13051}
13052
13053#define LOW4(R) ((R) & 0xf)
13054#define HI1(R) (((R) >> 4) & 1)
13055
13056/* Encode insns with bit pattern:
13057
13058 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13059 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 13060
037e8744
JB
13061 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
13062 different meaning for some instruction. */
13063
13064static void
13065neon_three_same (int isquad, int ubit, int size)
13066{
13067 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13068 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13069 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13070 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13071 inst.instruction |= LOW4 (inst.operands[2].reg);
13072 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13073 inst.instruction |= (isquad != 0) << 6;
13074 inst.instruction |= (ubit != 0) << 24;
13075 if (size != -1)
13076 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 13077
88714cb8 13078 neon_dp_fixup (&inst);
037e8744
JB
13079}
13080
13081/* Encode instructions of the form:
13082
13083 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
13084 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
13085
13086 Don't write size if SIZE == -1. */
13087
13088static void
13089neon_two_same (int qbit, int ubit, int size)
13090{
13091 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13092 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13093 inst.instruction |= LOW4 (inst.operands[1].reg);
13094 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13095 inst.instruction |= (qbit != 0) << 6;
13096 inst.instruction |= (ubit != 0) << 24;
13097
13098 if (size != -1)
13099 inst.instruction |= neon_logbits (size) << 18;
13100
88714cb8 13101 neon_dp_fixup (&inst);
5287ad62
JB
13102}
13103
13104/* Neon instruction encoders, in approximate order of appearance. */
13105
13106static void
13107do_neon_dyadic_i_su (void)
13108{
037e8744 13109 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13110 struct neon_type_el et = neon_check_type (3, rs,
13111 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 13112 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13113}
13114
13115static void
13116do_neon_dyadic_i64_su (void)
13117{
037e8744 13118 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13119 struct neon_type_el et = neon_check_type (3, rs,
13120 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 13121 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13122}
13123
13124static void
13125neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
13126 unsigned immbits)
13127{
13128 unsigned size = et.size >> 3;
13129 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13130 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13131 inst.instruction |= LOW4 (inst.operands[1].reg);
13132 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13133 inst.instruction |= (isquad != 0) << 6;
13134 inst.instruction |= immbits << 16;
13135 inst.instruction |= (size >> 3) << 7;
13136 inst.instruction |= (size & 0x7) << 19;
13137 if (write_ubit)
13138 inst.instruction |= (uval != 0) << 24;
13139
88714cb8 13140 neon_dp_fixup (&inst);
5287ad62
JB
13141}
13142
13143static void
13144do_neon_shl_imm (void)
13145{
13146 if (!inst.operands[2].isreg)
13147 {
037e8744 13148 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 13149 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
88714cb8 13150 NEON_ENCODE (IMMED, inst);
037e8744 13151 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
13152 }
13153 else
13154 {
037e8744 13155 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13156 struct neon_type_el et = neon_check_type (3, rs,
13157 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13158 unsigned int tmp;
13159
13160 /* VSHL/VQSHL 3-register variants have syntax such as:
13161 vshl.xx Dd, Dm, Dn
13162 whereas other 3-register operations encoded by neon_three_same have
13163 syntax like:
13164 vadd.xx Dd, Dn, Dm
13165 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
13166 here. */
13167 tmp = inst.operands[2].reg;
13168 inst.operands[2].reg = inst.operands[1].reg;
13169 inst.operands[1].reg = tmp;
88714cb8 13170 NEON_ENCODE (INTEGER, inst);
037e8744 13171 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13172 }
13173}
13174
13175static void
13176do_neon_qshl_imm (void)
13177{
13178 if (!inst.operands[2].isreg)
13179 {
037e8744 13180 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 13181 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 13182
88714cb8 13183 NEON_ENCODE (IMMED, inst);
037e8744 13184 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13185 inst.operands[2].imm);
13186 }
13187 else
13188 {
037e8744 13189 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13190 struct neon_type_el et = neon_check_type (3, rs,
13191 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13192 unsigned int tmp;
13193
13194 /* See note in do_neon_shl_imm. */
13195 tmp = inst.operands[2].reg;
13196 inst.operands[2].reg = inst.operands[1].reg;
13197 inst.operands[1].reg = tmp;
88714cb8 13198 NEON_ENCODE (INTEGER, inst);
037e8744 13199 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13200 }
13201}
13202
627907b7
JB
13203static void
13204do_neon_rshl (void)
13205{
13206 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13207 struct neon_type_el et = neon_check_type (3, rs,
13208 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13209 unsigned int tmp;
13210
13211 tmp = inst.operands[2].reg;
13212 inst.operands[2].reg = inst.operands[1].reg;
13213 inst.operands[1].reg = tmp;
13214 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13215}
13216
5287ad62
JB
13217static int
13218neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
13219{
036dc3f7
PB
13220 /* Handle .I8 pseudo-instructions. */
13221 if (size == 8)
5287ad62 13222 {
5287ad62
JB
13223 /* Unfortunately, this will make everything apart from zero out-of-range.
13224 FIXME is this the intended semantics? There doesn't seem much point in
13225 accepting .I8 if so. */
13226 immediate |= immediate << 8;
13227 size = 16;
036dc3f7
PB
13228 }
13229
13230 if (size >= 32)
13231 {
13232 if (immediate == (immediate & 0x000000ff))
13233 {
13234 *immbits = immediate;
13235 return 0x1;
13236 }
13237 else if (immediate == (immediate & 0x0000ff00))
13238 {
13239 *immbits = immediate >> 8;
13240 return 0x3;
13241 }
13242 else if (immediate == (immediate & 0x00ff0000))
13243 {
13244 *immbits = immediate >> 16;
13245 return 0x5;
13246 }
13247 else if (immediate == (immediate & 0xff000000))
13248 {
13249 *immbits = immediate >> 24;
13250 return 0x7;
13251 }
13252 if ((immediate & 0xffff) != (immediate >> 16))
13253 goto bad_immediate;
13254 immediate &= 0xffff;
5287ad62
JB
13255 }
13256
13257 if (immediate == (immediate & 0x000000ff))
13258 {
13259 *immbits = immediate;
036dc3f7 13260 return 0x9;
5287ad62
JB
13261 }
13262 else if (immediate == (immediate & 0x0000ff00))
13263 {
13264 *immbits = immediate >> 8;
036dc3f7 13265 return 0xb;
5287ad62
JB
13266 }
13267
13268 bad_immediate:
dcbf9037 13269 first_error (_("immediate value out of range"));
5287ad62
JB
13270 return FAIL;
13271}
13272
13273/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
13274 A, B, C, D. */
13275
13276static int
13277neon_bits_same_in_bytes (unsigned imm)
13278{
13279 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
13280 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
13281 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
13282 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
13283}
13284
13285/* For immediate of above form, return 0bABCD. */
13286
13287static unsigned
13288neon_squash_bits (unsigned imm)
13289{
13290 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
13291 | ((imm & 0x01000000) >> 21);
13292}
13293
136da414 13294/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
13295
13296static unsigned
13297neon_qfloat_bits (unsigned imm)
13298{
136da414 13299 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
13300}
13301
13302/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
13303 the instruction. *OP is passed as the initial value of the op field, and
13304 may be set to a different value depending on the constant (i.e.
13305 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 13306 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 13307 try smaller element sizes. */
5287ad62
JB
13308
13309static int
c96612cc
JB
13310neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
13311 unsigned *immbits, int *op, int size,
13312 enum neon_el_type type)
5287ad62 13313{
c96612cc
JB
13314 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13315 float. */
13316 if (type == NT_float && !float_p)
13317 return FAIL;
13318
136da414
JB
13319 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13320 {
13321 if (size != 32 || *op == 1)
13322 return FAIL;
13323 *immbits = neon_qfloat_bits (immlo);
13324 return 0xf;
13325 }
036dc3f7
PB
13326
13327 if (size == 64)
5287ad62 13328 {
036dc3f7
PB
13329 if (neon_bits_same_in_bytes (immhi)
13330 && neon_bits_same_in_bytes (immlo))
13331 {
13332 if (*op == 1)
13333 return FAIL;
13334 *immbits = (neon_squash_bits (immhi) << 4)
13335 | neon_squash_bits (immlo);
13336 *op = 1;
13337 return 0xe;
13338 }
13339
13340 if (immhi != immlo)
13341 return FAIL;
5287ad62 13342 }
036dc3f7
PB
13343
13344 if (size >= 32)
5287ad62 13345 {
036dc3f7
PB
13346 if (immlo == (immlo & 0x000000ff))
13347 {
13348 *immbits = immlo;
13349 return 0x0;
13350 }
13351 else if (immlo == (immlo & 0x0000ff00))
13352 {
13353 *immbits = immlo >> 8;
13354 return 0x2;
13355 }
13356 else if (immlo == (immlo & 0x00ff0000))
13357 {
13358 *immbits = immlo >> 16;
13359 return 0x4;
13360 }
13361 else if (immlo == (immlo & 0xff000000))
13362 {
13363 *immbits = immlo >> 24;
13364 return 0x6;
13365 }
13366 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13367 {
13368 *immbits = (immlo >> 8) & 0xff;
13369 return 0xc;
13370 }
13371 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13372 {
13373 *immbits = (immlo >> 16) & 0xff;
13374 return 0xd;
13375 }
13376
13377 if ((immlo & 0xffff) != (immlo >> 16))
13378 return FAIL;
13379 immlo &= 0xffff;
5287ad62 13380 }
036dc3f7
PB
13381
13382 if (size >= 16)
5287ad62 13383 {
036dc3f7
PB
13384 if (immlo == (immlo & 0x000000ff))
13385 {
13386 *immbits = immlo;
13387 return 0x8;
13388 }
13389 else if (immlo == (immlo & 0x0000ff00))
13390 {
13391 *immbits = immlo >> 8;
13392 return 0xa;
13393 }
13394
13395 if ((immlo & 0xff) != (immlo >> 8))
13396 return FAIL;
13397 immlo &= 0xff;
5287ad62 13398 }
036dc3f7
PB
13399
13400 if (immlo == (immlo & 0x000000ff))
5287ad62 13401 {
036dc3f7
PB
13402 /* Don't allow MVN with 8-bit immediate. */
13403 if (*op == 1)
13404 return FAIL;
13405 *immbits = immlo;
13406 return 0xe;
5287ad62 13407 }
5287ad62
JB
13408
13409 return FAIL;
13410}
13411
13412/* Write immediate bits [7:0] to the following locations:
13413
13414 |28/24|23 19|18 16|15 4|3 0|
13415 | 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|
13416
13417 This function is used by VMOV/VMVN/VORR/VBIC. */
13418
13419static void
13420neon_write_immbits (unsigned immbits)
13421{
13422 inst.instruction |= immbits & 0xf;
13423 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13424 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13425}
13426
13427/* Invert low-order SIZE bits of XHI:XLO. */
13428
13429static void
13430neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13431{
13432 unsigned immlo = xlo ? *xlo : 0;
13433 unsigned immhi = xhi ? *xhi : 0;
13434
13435 switch (size)
13436 {
13437 case 8:
13438 immlo = (~immlo) & 0xff;
13439 break;
13440
13441 case 16:
13442 immlo = (~immlo) & 0xffff;
13443 break;
13444
13445 case 64:
13446 immhi = (~immhi) & 0xffffffff;
13447 /* fall through. */
13448
13449 case 32:
13450 immlo = (~immlo) & 0xffffffff;
13451 break;
13452
13453 default:
13454 abort ();
13455 }
13456
13457 if (xlo)
13458 *xlo = immlo;
13459
13460 if (xhi)
13461 *xhi = immhi;
13462}
13463
13464static void
13465do_neon_logic (void)
13466{
13467 if (inst.operands[2].present && inst.operands[2].isreg)
13468 {
037e8744 13469 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13470 neon_check_type (3, rs, N_IGNORE_TYPE);
13471 /* U bit and size field were set as part of the bitmask. */
88714cb8 13472 NEON_ENCODE (INTEGER, inst);
037e8744 13473 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13474 }
13475 else
13476 {
4316f0d2
DG
13477 const int three_ops_form = (inst.operands[2].present
13478 && !inst.operands[2].isreg);
13479 const int immoperand = (three_ops_form ? 2 : 1);
13480 enum neon_shape rs = (three_ops_form
13481 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13482 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744
JB
13483 struct neon_type_el et = neon_check_type (2, rs,
13484 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 13485 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
13486 unsigned immbits;
13487 int cmode;
5f4273c7 13488
5287ad62
JB
13489 if (et.type == NT_invtype)
13490 return;
5f4273c7 13491
4316f0d2
DG
13492 if (three_ops_form)
13493 constraint (inst.operands[0].reg != inst.operands[1].reg,
13494 _("first and second operands shall be the same register"));
13495
88714cb8 13496 NEON_ENCODE (IMMED, inst);
5287ad62 13497
4316f0d2 13498 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
13499 if (et.size == 64)
13500 {
13501 /* .i64 is a pseudo-op, so the immediate must be a repeating
13502 pattern. */
4316f0d2
DG
13503 if (immbits != (inst.operands[immoperand].regisimm ?
13504 inst.operands[immoperand].reg : 0))
036dc3f7
PB
13505 {
13506 /* Set immbits to an invalid constant. */
13507 immbits = 0xdeadbeef;
13508 }
13509 }
13510
5287ad62
JB
13511 switch (opcode)
13512 {
13513 case N_MNEM_vbic:
036dc3f7 13514 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13515 break;
5f4273c7 13516
5287ad62 13517 case N_MNEM_vorr:
036dc3f7 13518 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13519 break;
5f4273c7 13520
5287ad62
JB
13521 case N_MNEM_vand:
13522 /* Pseudo-instruction for VBIC. */
5287ad62
JB
13523 neon_invert_size (&immbits, 0, et.size);
13524 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13525 break;
5f4273c7 13526
5287ad62
JB
13527 case N_MNEM_vorn:
13528 /* Pseudo-instruction for VORR. */
5287ad62
JB
13529 neon_invert_size (&immbits, 0, et.size);
13530 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13531 break;
5f4273c7 13532
5287ad62
JB
13533 default:
13534 abort ();
13535 }
13536
13537 if (cmode == FAIL)
13538 return;
13539
037e8744 13540 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13541 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13542 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13543 inst.instruction |= cmode << 8;
13544 neon_write_immbits (immbits);
5f4273c7 13545
88714cb8 13546 neon_dp_fixup (&inst);
5287ad62
JB
13547 }
13548}
13549
13550static void
13551do_neon_bitfield (void)
13552{
037e8744 13553 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 13554 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 13555 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13556}
13557
13558static void
dcbf9037
JB
13559neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13560 unsigned destbits)
5287ad62 13561{
037e8744 13562 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
13563 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13564 types | N_KEY);
5287ad62
JB
13565 if (et.type == NT_float)
13566 {
88714cb8 13567 NEON_ENCODE (FLOAT, inst);
037e8744 13568 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13569 }
13570 else
13571 {
88714cb8 13572 NEON_ENCODE (INTEGER, inst);
037e8744 13573 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
13574 }
13575}
13576
13577static void
13578do_neon_dyadic_if_su (void)
13579{
dcbf9037 13580 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13581}
13582
13583static void
13584do_neon_dyadic_if_su_d (void)
13585{
13586 /* This version only allow D registers, but that constraint is enforced during
13587 operand parsing so we don't need to do anything extra here. */
dcbf9037 13588 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13589}
13590
5287ad62
JB
13591static void
13592do_neon_dyadic_if_i_d (void)
13593{
428e3f1f
PB
13594 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13595 affected if we specify unsigned args. */
13596 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
13597}
13598
037e8744
JB
13599enum vfp_or_neon_is_neon_bits
13600{
13601 NEON_CHECK_CC = 1,
13602 NEON_CHECK_ARCH = 2
13603};
13604
13605/* Call this function if an instruction which may have belonged to the VFP or
13606 Neon instruction sets, but turned out to be a Neon instruction (due to the
13607 operand types involved, etc.). We have to check and/or fix-up a couple of
13608 things:
13609
13610 - Make sure the user hasn't attempted to make a Neon instruction
13611 conditional.
13612 - Alter the value in the condition code field if necessary.
13613 - Make sure that the arch supports Neon instructions.
13614
13615 Which of these operations take place depends on bits from enum
13616 vfp_or_neon_is_neon_bits.
13617
13618 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13619 current instruction's condition is COND_ALWAYS, the condition field is
13620 changed to inst.uncond_value. This is necessary because instructions shared
13621 between VFP and Neon may be conditional for the VFP variants only, and the
13622 unconditional Neon version must have, e.g., 0xF in the condition field. */
13623
13624static int
13625vfp_or_neon_is_neon (unsigned check)
13626{
13627 /* Conditions are always legal in Thumb mode (IT blocks). */
13628 if (!thumb_mode && (check & NEON_CHECK_CC))
13629 {
13630 if (inst.cond != COND_ALWAYS)
13631 {
13632 first_error (_(BAD_COND));
13633 return FAIL;
13634 }
13635 if (inst.uncond_value != -1)
13636 inst.instruction |= inst.uncond_value << 28;
13637 }
5f4273c7 13638
037e8744
JB
13639 if ((check & NEON_CHECK_ARCH)
13640 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13641 {
13642 first_error (_(BAD_FPU));
13643 return FAIL;
13644 }
5f4273c7 13645
037e8744
JB
13646 return SUCCESS;
13647}
13648
5287ad62
JB
13649static void
13650do_neon_addsub_if_i (void)
13651{
037e8744
JB
13652 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13653 return;
13654
13655 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13656 return;
13657
5287ad62
JB
13658 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13659 affected if we specify unsigned args. */
dcbf9037 13660 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
13661}
13662
13663/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13664 result to be:
13665 V<op> A,B (A is operand 0, B is operand 2)
13666 to mean:
13667 V<op> A,B,A
13668 not:
13669 V<op> A,B,B
13670 so handle that case specially. */
13671
13672static void
13673neon_exchange_operands (void)
13674{
13675 void *scratch = alloca (sizeof (inst.operands[0]));
13676 if (inst.operands[1].present)
13677 {
13678 /* Swap operands[1] and operands[2]. */
13679 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13680 inst.operands[1] = inst.operands[2];
13681 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13682 }
13683 else
13684 {
13685 inst.operands[1] = inst.operands[2];
13686 inst.operands[2] = inst.operands[0];
13687 }
13688}
13689
13690static void
13691neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13692{
13693 if (inst.operands[2].isreg)
13694 {
13695 if (invert)
13696 neon_exchange_operands ();
dcbf9037 13697 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
13698 }
13699 else
13700 {
037e8744 13701 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
13702 struct neon_type_el et = neon_check_type (2, rs,
13703 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 13704
88714cb8 13705 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13706 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13707 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13708 inst.instruction |= LOW4 (inst.operands[1].reg);
13709 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13710 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13711 inst.instruction |= (et.type == NT_float) << 10;
13712 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13713
88714cb8 13714 neon_dp_fixup (&inst);
5287ad62
JB
13715 }
13716}
13717
13718static void
13719do_neon_cmp (void)
13720{
13721 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13722}
13723
13724static void
13725do_neon_cmp_inv (void)
13726{
13727 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13728}
13729
13730static void
13731do_neon_ceq (void)
13732{
13733 neon_compare (N_IF_32, N_IF_32, FALSE);
13734}
13735
13736/* For multiply instructions, we have the possibility of 16-bit or 32-bit
13737 scalars, which are encoded in 5 bits, M : Rm.
13738 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13739 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13740 index in M. */
13741
13742static unsigned
13743neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13744{
dcbf9037
JB
13745 unsigned regno = NEON_SCALAR_REG (scalar);
13746 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
13747
13748 switch (elsize)
13749 {
13750 case 16:
13751 if (regno > 7 || elno > 3)
13752 goto bad_scalar;
13753 return regno | (elno << 3);
5f4273c7 13754
5287ad62
JB
13755 case 32:
13756 if (regno > 15 || elno > 1)
13757 goto bad_scalar;
13758 return regno | (elno << 4);
13759
13760 default:
13761 bad_scalar:
dcbf9037 13762 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
13763 }
13764
13765 return 0;
13766}
13767
13768/* Encode multiply / multiply-accumulate scalar instructions. */
13769
13770static void
13771neon_mul_mac (struct neon_type_el et, int ubit)
13772{
dcbf9037
JB
13773 unsigned scalar;
13774
13775 /* Give a more helpful error message if we have an invalid type. */
13776 if (et.type == NT_invtype)
13777 return;
5f4273c7 13778
dcbf9037 13779 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
13780 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13781 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13782 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13783 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13784 inst.instruction |= LOW4 (scalar);
13785 inst.instruction |= HI1 (scalar) << 5;
13786 inst.instruction |= (et.type == NT_float) << 8;
13787 inst.instruction |= neon_logbits (et.size) << 20;
13788 inst.instruction |= (ubit != 0) << 24;
13789
88714cb8 13790 neon_dp_fixup (&inst);
5287ad62
JB
13791}
13792
13793static void
13794do_neon_mac_maybe_scalar (void)
13795{
037e8744
JB
13796 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13797 return;
13798
13799 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13800 return;
13801
5287ad62
JB
13802 if (inst.operands[2].isscalar)
13803 {
037e8744 13804 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13805 struct neon_type_el et = neon_check_type (3, rs,
13806 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 13807 NEON_ENCODE (SCALAR, inst);
037e8744 13808 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13809 }
13810 else
428e3f1f
PB
13811 {
13812 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13813 affected if we specify unsigned args. */
13814 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13815 }
5287ad62
JB
13816}
13817
62f3b8c8
PB
13818static void
13819do_neon_fmac (void)
13820{
13821 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13822 return;
13823
13824 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13825 return;
13826
13827 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13828}
13829
5287ad62
JB
13830static void
13831do_neon_tst (void)
13832{
037e8744 13833 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13834 struct neon_type_el et = neon_check_type (3, rs,
13835 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 13836 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13837}
13838
13839/* VMUL with 3 registers allows the P8 type. The scalar version supports the
13840 same types as the MAC equivalents. The polynomial type for this instruction
13841 is encoded the same as the integer type. */
13842
13843static void
13844do_neon_mul (void)
13845{
037e8744
JB
13846 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13847 return;
13848
13849 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13850 return;
13851
5287ad62
JB
13852 if (inst.operands[2].isscalar)
13853 do_neon_mac_maybe_scalar ();
13854 else
dcbf9037 13855 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
13856}
13857
13858static void
13859do_neon_qdmulh (void)
13860{
13861 if (inst.operands[2].isscalar)
13862 {
037e8744 13863 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13864 struct neon_type_el et = neon_check_type (3, rs,
13865 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13866 NEON_ENCODE (SCALAR, inst);
037e8744 13867 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13868 }
13869 else
13870 {
037e8744 13871 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13872 struct neon_type_el et = neon_check_type (3, rs,
13873 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13874 NEON_ENCODE (INTEGER, inst);
5287ad62 13875 /* The U bit (rounding) comes from bit mask. */
037e8744 13876 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13877 }
13878}
13879
13880static void
13881do_neon_fcmp_absolute (void)
13882{
037e8744 13883 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13884 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13885 /* Size field comes from bit mask. */
037e8744 13886 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
13887}
13888
13889static void
13890do_neon_fcmp_absolute_inv (void)
13891{
13892 neon_exchange_operands ();
13893 do_neon_fcmp_absolute ();
13894}
13895
13896static void
13897do_neon_step (void)
13898{
037e8744 13899 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 13900 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 13901 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13902}
13903
13904static void
13905do_neon_abs_neg (void)
13906{
037e8744
JB
13907 enum neon_shape rs;
13908 struct neon_type_el et;
5f4273c7 13909
037e8744
JB
13910 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13911 return;
13912
13913 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13914 return;
13915
13916 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13917 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 13918
5287ad62
JB
13919 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13920 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13921 inst.instruction |= LOW4 (inst.operands[1].reg);
13922 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13923 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13924 inst.instruction |= (et.type == NT_float) << 10;
13925 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13926
88714cb8 13927 neon_dp_fixup (&inst);
5287ad62
JB
13928}
13929
13930static void
13931do_neon_sli (void)
13932{
037e8744 13933 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13934 struct neon_type_el et = neon_check_type (2, rs,
13935 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13936 int imm = inst.operands[2].imm;
13937 constraint (imm < 0 || (unsigned)imm >= et.size,
13938 _("immediate out of range for insert"));
037e8744 13939 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13940}
13941
13942static void
13943do_neon_sri (void)
13944{
037e8744 13945 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13946 struct neon_type_el et = neon_check_type (2, rs,
13947 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13948 int imm = inst.operands[2].imm;
13949 constraint (imm < 1 || (unsigned)imm > et.size,
13950 _("immediate out of range for insert"));
037e8744 13951 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
13952}
13953
13954static void
13955do_neon_qshlu_imm (void)
13956{
037e8744 13957 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13958 struct neon_type_el et = neon_check_type (2, rs,
13959 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13960 int imm = inst.operands[2].imm;
13961 constraint (imm < 0 || (unsigned)imm >= et.size,
13962 _("immediate out of range for shift"));
13963 /* Only encodes the 'U present' variant of the instruction.
13964 In this case, signed types have OP (bit 8) set to 0.
13965 Unsigned types have OP set to 1. */
13966 inst.instruction |= (et.type == NT_unsigned) << 8;
13967 /* The rest of the bits are the same as other immediate shifts. */
037e8744 13968 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13969}
13970
13971static void
13972do_neon_qmovn (void)
13973{
13974 struct neon_type_el et = neon_check_type (2, NS_DQ,
13975 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13976 /* Saturating move where operands can be signed or unsigned, and the
13977 destination has the same signedness. */
88714cb8 13978 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13979 if (et.type == NT_unsigned)
13980 inst.instruction |= 0xc0;
13981 else
13982 inst.instruction |= 0x80;
13983 neon_two_same (0, 1, et.size / 2);
13984}
13985
13986static void
13987do_neon_qmovun (void)
13988{
13989 struct neon_type_el et = neon_check_type (2, NS_DQ,
13990 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13991 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 13992 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13993 neon_two_same (0, 1, et.size / 2);
13994}
13995
13996static void
13997do_neon_rshift_sat_narrow (void)
13998{
13999 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14000 or unsigned. If operands are unsigned, results must also be unsigned. */
14001 struct neon_type_el et = neon_check_type (2, NS_DQI,
14002 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14003 int imm = inst.operands[2].imm;
14004 /* This gets the bounds check, size encoding and immediate bits calculation
14005 right. */
14006 et.size /= 2;
5f4273c7 14007
5287ad62
JB
14008 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14009 VQMOVN.I<size> <Dd>, <Qm>. */
14010 if (imm == 0)
14011 {
14012 inst.operands[2].present = 0;
14013 inst.instruction = N_MNEM_vqmovn;
14014 do_neon_qmovn ();
14015 return;
14016 }
5f4273c7 14017
5287ad62
JB
14018 constraint (imm < 1 || (unsigned)imm > et.size,
14019 _("immediate out of range"));
14020 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14021}
14022
14023static void
14024do_neon_rshift_sat_narrow_u (void)
14025{
14026 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14027 or unsigned. If operands are unsigned, results must also be unsigned. */
14028 struct neon_type_el et = neon_check_type (2, NS_DQI,
14029 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14030 int imm = inst.operands[2].imm;
14031 /* This gets the bounds check, size encoding and immediate bits calculation
14032 right. */
14033 et.size /= 2;
14034
14035 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14036 VQMOVUN.I<size> <Dd>, <Qm>. */
14037 if (imm == 0)
14038 {
14039 inst.operands[2].present = 0;
14040 inst.instruction = N_MNEM_vqmovun;
14041 do_neon_qmovun ();
14042 return;
14043 }
14044
14045 constraint (imm < 1 || (unsigned)imm > et.size,
14046 _("immediate out of range"));
14047 /* FIXME: The manual is kind of unclear about what value U should have in
14048 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
14049 must be 1. */
14050 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
14051}
14052
14053static void
14054do_neon_movn (void)
14055{
14056 struct neon_type_el et = neon_check_type (2, NS_DQ,
14057 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 14058 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14059 neon_two_same (0, 1, et.size / 2);
14060}
14061
14062static void
14063do_neon_rshift_narrow (void)
14064{
14065 struct neon_type_el et = neon_check_type (2, NS_DQI,
14066 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14067 int imm = inst.operands[2].imm;
14068 /* This gets the bounds check, size encoding and immediate bits calculation
14069 right. */
14070 et.size /= 2;
5f4273c7 14071
5287ad62
JB
14072 /* If immediate is zero then we are a pseudo-instruction for
14073 VMOVN.I<size> <Dd>, <Qm> */
14074 if (imm == 0)
14075 {
14076 inst.operands[2].present = 0;
14077 inst.instruction = N_MNEM_vmovn;
14078 do_neon_movn ();
14079 return;
14080 }
5f4273c7 14081
5287ad62
JB
14082 constraint (imm < 1 || (unsigned)imm > et.size,
14083 _("immediate out of range for narrowing operation"));
14084 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
14085}
14086
14087static void
14088do_neon_shll (void)
14089{
14090 /* FIXME: Type checking when lengthening. */
14091 struct neon_type_el et = neon_check_type (2, NS_QDI,
14092 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
14093 unsigned imm = inst.operands[2].imm;
14094
14095 if (imm == et.size)
14096 {
14097 /* Maximum shift variant. */
88714cb8 14098 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14099 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14100 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14101 inst.instruction |= LOW4 (inst.operands[1].reg);
14102 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14103 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14104
88714cb8 14105 neon_dp_fixup (&inst);
5287ad62
JB
14106 }
14107 else
14108 {
14109 /* A more-specific type check for non-max versions. */
14110 et = neon_check_type (2, NS_QDI,
14111 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 14112 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14113 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
14114 }
14115}
14116
037e8744 14117/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
14118 the current instruction is. */
14119
14120static int
14121neon_cvt_flavour (enum neon_shape rs)
14122{
037e8744
JB
14123#define CVT_VAR(C,X,Y) \
14124 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
14125 if (et.type != NT_invtype) \
14126 { \
14127 inst.error = NULL; \
14128 return (C); \
5287ad62
JB
14129 }
14130 struct neon_type_el et;
037e8744
JB
14131 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
14132 || rs == NS_FF) ? N_VFP : 0;
14133 /* The instruction versions which take an immediate take one register
14134 argument, which is extended to the width of the full register. Thus the
14135 "source" and "destination" registers must have the same width. Hack that
14136 here by making the size equal to the key (wider, in this case) operand. */
14137 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 14138
5287ad62
JB
14139 CVT_VAR (0, N_S32, N_F32);
14140 CVT_VAR (1, N_U32, N_F32);
14141 CVT_VAR (2, N_F32, N_S32);
14142 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
14143 /* Half-precision conversions. */
14144 CVT_VAR (4, N_F32, N_F16);
14145 CVT_VAR (5, N_F16, N_F32);
5f4273c7 14146
037e8744 14147 whole_reg = N_VFP;
5f4273c7 14148
037e8744 14149 /* VFP instructions. */
8e79c3df
CM
14150 CVT_VAR (6, N_F32, N_F64);
14151 CVT_VAR (7, N_F64, N_F32);
14152 CVT_VAR (8, N_S32, N_F64 | key);
14153 CVT_VAR (9, N_U32, N_F64 | key);
14154 CVT_VAR (10, N_F64 | key, N_S32);
14155 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 14156 /* VFP instructions with bitshift. */
8e79c3df
CM
14157 CVT_VAR (12, N_F32 | key, N_S16);
14158 CVT_VAR (13, N_F32 | key, N_U16);
14159 CVT_VAR (14, N_F64 | key, N_S16);
14160 CVT_VAR (15, N_F64 | key, N_U16);
14161 CVT_VAR (16, N_S16, N_F32 | key);
14162 CVT_VAR (17, N_U16, N_F32 | key);
14163 CVT_VAR (18, N_S16, N_F64 | key);
14164 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 14165
5287ad62
JB
14166 return -1;
14167#undef CVT_VAR
14168}
14169
037e8744
JB
14170/* Neon-syntax VFP conversions. */
14171
5287ad62 14172static void
037e8744 14173do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 14174{
037e8744 14175 const char *opname = 0;
5f4273c7 14176
037e8744 14177 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 14178 {
037e8744
JB
14179 /* Conversions with immediate bitshift. */
14180 const char *enc[] =
14181 {
14182 "ftosls",
14183 "ftouls",
14184 "fsltos",
14185 "fultos",
14186 NULL,
14187 NULL,
8e79c3df
CM
14188 NULL,
14189 NULL,
037e8744
JB
14190 "ftosld",
14191 "ftould",
14192 "fsltod",
14193 "fultod",
14194 "fshtos",
14195 "fuhtos",
14196 "fshtod",
14197 "fuhtod",
14198 "ftoshs",
14199 "ftouhs",
14200 "ftoshd",
14201 "ftouhd"
14202 };
14203
14204 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14205 {
14206 opname = enc[flavour];
14207 constraint (inst.operands[0].reg != inst.operands[1].reg,
14208 _("operands 0 and 1 must be the same register"));
14209 inst.operands[1] = inst.operands[2];
14210 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
14211 }
5287ad62
JB
14212 }
14213 else
14214 {
037e8744
JB
14215 /* Conversions without bitshift. */
14216 const char *enc[] =
14217 {
14218 "ftosis",
14219 "ftouis",
14220 "fsitos",
14221 "fuitos",
8e79c3df
CM
14222 "NULL",
14223 "NULL",
037e8744
JB
14224 "fcvtsd",
14225 "fcvtds",
14226 "ftosid",
14227 "ftouid",
14228 "fsitod",
14229 "fuitod"
14230 };
14231
14232 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14233 opname = enc[flavour];
14234 }
14235
14236 if (opname)
14237 do_vfp_nsyn_opcode (opname);
14238}
14239
14240static void
14241do_vfp_nsyn_cvtz (void)
14242{
14243 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
14244 int flavour = neon_cvt_flavour (rs);
14245 const char *enc[] =
14246 {
14247 "ftosizs",
14248 "ftouizs",
14249 NULL,
14250 NULL,
14251 NULL,
14252 NULL,
8e79c3df
CM
14253 NULL,
14254 NULL,
037e8744
JB
14255 "ftosizd",
14256 "ftouizd"
14257 };
14258
14259 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
14260 do_vfp_nsyn_opcode (enc[flavour]);
14261}
f31fef98 14262
037e8744 14263static void
e3e535bc 14264do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
037e8744
JB
14265{
14266 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 14267 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
14268 int flavour = neon_cvt_flavour (rs);
14269
e3e535bc
NC
14270 /* PR11109: Handle round-to-zero for VCVT conversions. */
14271 if (round_to_zero
14272 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
14273 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
14274 && (rs == NS_FD || rs == NS_FF))
14275 {
14276 do_vfp_nsyn_cvtz ();
14277 return;
14278 }
14279
037e8744 14280 /* VFP rather than Neon conversions. */
8e79c3df 14281 if (flavour >= 6)
037e8744
JB
14282 {
14283 do_vfp_nsyn_cvt (rs, flavour);
14284 return;
14285 }
14286
14287 switch (rs)
14288 {
14289 case NS_DDI:
14290 case NS_QQI:
14291 {
35997600
NC
14292 unsigned immbits;
14293 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
14294
037e8744
JB
14295 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14296 return;
14297
14298 /* Fixed-point conversion with #0 immediate is encoded as an
14299 integer conversion. */
14300 if (inst.operands[2].present && inst.operands[2].imm == 0)
14301 goto int_encode;
35997600 14302 immbits = 32 - inst.operands[2].imm;
88714cb8 14303 NEON_ENCODE (IMMED, inst);
037e8744
JB
14304 if (flavour != -1)
14305 inst.instruction |= enctab[flavour];
14306 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14307 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14308 inst.instruction |= LOW4 (inst.operands[1].reg);
14309 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14310 inst.instruction |= neon_quad (rs) << 6;
14311 inst.instruction |= 1 << 21;
14312 inst.instruction |= immbits << 16;
14313
88714cb8 14314 neon_dp_fixup (&inst);
037e8744
JB
14315 }
14316 break;
14317
14318 case NS_DD:
14319 case NS_QQ:
14320 int_encode:
14321 {
14322 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
14323
88714cb8 14324 NEON_ENCODE (INTEGER, inst);
037e8744
JB
14325
14326 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14327 return;
14328
14329 if (flavour != -1)
14330 inst.instruction |= enctab[flavour];
14331
14332 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14333 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14334 inst.instruction |= LOW4 (inst.operands[1].reg);
14335 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14336 inst.instruction |= neon_quad (rs) << 6;
14337 inst.instruction |= 2 << 18;
14338
88714cb8 14339 neon_dp_fixup (&inst);
037e8744
JB
14340 }
14341 break;
14342
8e79c3df
CM
14343 /* Half-precision conversions for Advanced SIMD -- neon. */
14344 case NS_QD:
14345 case NS_DQ:
14346
14347 if ((rs == NS_DQ)
14348 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14349 {
14350 as_bad (_("operand size must match register width"));
14351 break;
14352 }
14353
14354 if ((rs == NS_QD)
14355 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14356 {
14357 as_bad (_("operand size must match register width"));
14358 break;
14359 }
14360
14361 if (rs == NS_DQ)
14362 inst.instruction = 0x3b60600;
14363 else
14364 inst.instruction = 0x3b60700;
14365
14366 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14367 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14368 inst.instruction |= LOW4 (inst.operands[1].reg);
14369 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 14370 neon_dp_fixup (&inst);
8e79c3df
CM
14371 break;
14372
037e8744
JB
14373 default:
14374 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
14375 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 14376 }
5287ad62
JB
14377}
14378
e3e535bc
NC
14379static void
14380do_neon_cvtr (void)
14381{
14382 do_neon_cvt_1 (FALSE);
14383}
14384
14385static void
14386do_neon_cvt (void)
14387{
14388 do_neon_cvt_1 (TRUE);
14389}
14390
8e79c3df
CM
14391static void
14392do_neon_cvtb (void)
14393{
14394 inst.instruction = 0xeb20a40;
14395
14396 /* The sizes are attached to the mnemonic. */
14397 if (inst.vectype.el[0].type != NT_invtype
14398 && inst.vectype.el[0].size == 16)
14399 inst.instruction |= 0x00010000;
14400
14401 /* Programmer's syntax: the sizes are attached to the operands. */
14402 else if (inst.operands[0].vectype.type != NT_invtype
14403 && inst.operands[0].vectype.size == 16)
14404 inst.instruction |= 0x00010000;
14405
14406 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14407 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
14408 do_vfp_cond_or_thumb ();
14409}
14410
14411
14412static void
14413do_neon_cvtt (void)
14414{
14415 do_neon_cvtb ();
14416 inst.instruction |= 0x80;
14417}
14418
5287ad62
JB
14419static void
14420neon_move_immediate (void)
14421{
037e8744
JB
14422 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14423 struct neon_type_el et = neon_check_type (2, rs,
14424 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 14425 unsigned immlo, immhi = 0, immbits;
c96612cc 14426 int op, cmode, float_p;
5287ad62 14427
037e8744
JB
14428 constraint (et.type == NT_invtype,
14429 _("operand size must be specified for immediate VMOV"));
14430
5287ad62
JB
14431 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14432 op = (inst.instruction & (1 << 5)) != 0;
14433
14434 immlo = inst.operands[1].imm;
14435 if (inst.operands[1].regisimm)
14436 immhi = inst.operands[1].reg;
14437
14438 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14439 _("immediate has bits set outside the operand size"));
14440
c96612cc
JB
14441 float_p = inst.operands[1].immisfloat;
14442
14443 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 14444 et.size, et.type)) == FAIL)
5287ad62
JB
14445 {
14446 /* Invert relevant bits only. */
14447 neon_invert_size (&immlo, &immhi, et.size);
14448 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14449 with one or the other; those cases are caught by
14450 neon_cmode_for_move_imm. */
14451 op = !op;
c96612cc
JB
14452 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
14453 &op, et.size, et.type)) == FAIL)
5287ad62 14454 {
dcbf9037 14455 first_error (_("immediate out of range"));
5287ad62
JB
14456 return;
14457 }
14458 }
14459
14460 inst.instruction &= ~(1 << 5);
14461 inst.instruction |= op << 5;
14462
14463 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14464 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 14465 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14466 inst.instruction |= cmode << 8;
14467
14468 neon_write_immbits (immbits);
14469}
14470
14471static void
14472do_neon_mvn (void)
14473{
14474 if (inst.operands[1].isreg)
14475 {
037e8744 14476 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 14477
88714cb8 14478 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14479 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14480 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14481 inst.instruction |= LOW4 (inst.operands[1].reg);
14482 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14483 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14484 }
14485 else
14486 {
88714cb8 14487 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14488 neon_move_immediate ();
14489 }
14490
88714cb8 14491 neon_dp_fixup (&inst);
5287ad62
JB
14492}
14493
14494/* Encode instructions of form:
14495
14496 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 14497 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
14498
14499static void
14500neon_mixed_length (struct neon_type_el et, unsigned size)
14501{
14502 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14503 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14504 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14505 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14506 inst.instruction |= LOW4 (inst.operands[2].reg);
14507 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14508 inst.instruction |= (et.type == NT_unsigned) << 24;
14509 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14510
88714cb8 14511 neon_dp_fixup (&inst);
5287ad62
JB
14512}
14513
14514static void
14515do_neon_dyadic_long (void)
14516{
14517 /* FIXME: Type checking for lengthening op. */
14518 struct neon_type_el et = neon_check_type (3, NS_QDD,
14519 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14520 neon_mixed_length (et, et.size);
14521}
14522
14523static void
14524do_neon_abal (void)
14525{
14526 struct neon_type_el et = neon_check_type (3, NS_QDD,
14527 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14528 neon_mixed_length (et, et.size);
14529}
14530
14531static void
14532neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14533{
14534 if (inst.operands[2].isscalar)
14535 {
dcbf9037
JB
14536 struct neon_type_el et = neon_check_type (3, NS_QDS,
14537 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 14538 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14539 neon_mul_mac (et, et.type == NT_unsigned);
14540 }
14541 else
14542 {
14543 struct neon_type_el et = neon_check_type (3, NS_QDD,
14544 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 14545 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14546 neon_mixed_length (et, et.size);
14547 }
14548}
14549
14550static void
14551do_neon_mac_maybe_scalar_long (void)
14552{
14553 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14554}
14555
14556static void
14557do_neon_dyadic_wide (void)
14558{
14559 struct neon_type_el et = neon_check_type (3, NS_QQD,
14560 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14561 neon_mixed_length (et, et.size);
14562}
14563
14564static void
14565do_neon_dyadic_narrow (void)
14566{
14567 struct neon_type_el et = neon_check_type (3, NS_QDD,
14568 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
14569 /* Operand sign is unimportant, and the U bit is part of the opcode,
14570 so force the operand type to integer. */
14571 et.type = NT_integer;
5287ad62
JB
14572 neon_mixed_length (et, et.size / 2);
14573}
14574
14575static void
14576do_neon_mul_sat_scalar_long (void)
14577{
14578 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14579}
14580
14581static void
14582do_neon_vmull (void)
14583{
14584 if (inst.operands[2].isscalar)
14585 do_neon_mac_maybe_scalar_long ();
14586 else
14587 {
14588 struct neon_type_el et = neon_check_type (3, NS_QDD,
14589 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14590 if (et.type == NT_poly)
88714cb8 14591 NEON_ENCODE (POLY, inst);
5287ad62 14592 else
88714cb8 14593 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14594 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14595 zero. Should be OK as-is. */
14596 neon_mixed_length (et, et.size);
14597 }
14598}
14599
14600static void
14601do_neon_ext (void)
14602{
037e8744 14603 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
14604 struct neon_type_el et = neon_check_type (3, rs,
14605 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14606 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
14607
14608 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14609 _("shift out of range"));
5287ad62
JB
14610 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14611 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14612 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14613 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14614 inst.instruction |= LOW4 (inst.operands[2].reg);
14615 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 14616 inst.instruction |= neon_quad (rs) << 6;
5287ad62 14617 inst.instruction |= imm << 8;
5f4273c7 14618
88714cb8 14619 neon_dp_fixup (&inst);
5287ad62
JB
14620}
14621
14622static void
14623do_neon_rev (void)
14624{
037e8744 14625 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14626 struct neon_type_el et = neon_check_type (2, rs,
14627 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14628 unsigned op = (inst.instruction >> 7) & 3;
14629 /* N (width of reversed regions) is encoded as part of the bitmask. We
14630 extract it here to check the elements to be reversed are smaller.
14631 Otherwise we'd get a reserved instruction. */
14632 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 14633 gas_assert (elsize != 0);
5287ad62
JB
14634 constraint (et.size >= elsize,
14635 _("elements must be smaller than reversal region"));
037e8744 14636 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14637}
14638
14639static void
14640do_neon_dup (void)
14641{
14642 if (inst.operands[1].isscalar)
14643 {
037e8744 14644 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
14645 struct neon_type_el et = neon_check_type (2, rs,
14646 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 14647 unsigned sizebits = et.size >> 3;
dcbf9037 14648 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 14649 int logsize = neon_logbits (et.size);
dcbf9037 14650 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
14651
14652 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14653 return;
14654
88714cb8 14655 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14656 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14657 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14658 inst.instruction |= LOW4 (dm);
14659 inst.instruction |= HI1 (dm) << 5;
037e8744 14660 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14661 inst.instruction |= x << 17;
14662 inst.instruction |= sizebits << 16;
5f4273c7 14663
88714cb8 14664 neon_dp_fixup (&inst);
5287ad62
JB
14665 }
14666 else
14667 {
037e8744
JB
14668 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14669 struct neon_type_el et = neon_check_type (2, rs,
14670 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 14671 /* Duplicate ARM register to lanes of vector. */
88714cb8 14672 NEON_ENCODE (ARMREG, inst);
5287ad62
JB
14673 switch (et.size)
14674 {
14675 case 8: inst.instruction |= 0x400000; break;
14676 case 16: inst.instruction |= 0x000020; break;
14677 case 32: inst.instruction |= 0x000000; break;
14678 default: break;
14679 }
14680 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14681 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14682 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 14683 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
14684 /* The encoding for this instruction is identical for the ARM and Thumb
14685 variants, except for the condition field. */
037e8744 14686 do_vfp_cond_or_thumb ();
5287ad62
JB
14687 }
14688}
14689
14690/* VMOV has particularly many variations. It can be one of:
14691 0. VMOV<c><q> <Qd>, <Qm>
14692 1. VMOV<c><q> <Dd>, <Dm>
14693 (Register operations, which are VORR with Rm = Rn.)
14694 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14695 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14696 (Immediate loads.)
14697 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14698 (ARM register to scalar.)
14699 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14700 (Two ARM registers to vector.)
14701 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14702 (Scalar to ARM register.)
14703 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14704 (Vector to two ARM registers.)
037e8744
JB
14705 8. VMOV.F32 <Sd>, <Sm>
14706 9. VMOV.F64 <Dd>, <Dm>
14707 (VFP register moves.)
14708 10. VMOV.F32 <Sd>, #imm
14709 11. VMOV.F64 <Dd>, #imm
14710 (VFP float immediate load.)
14711 12. VMOV <Rd>, <Sm>
14712 (VFP single to ARM reg.)
14713 13. VMOV <Sd>, <Rm>
14714 (ARM reg to VFP single.)
14715 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14716 (Two ARM regs to two VFP singles.)
14717 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14718 (Two VFP singles to two ARM regs.)
5f4273c7 14719
037e8744
JB
14720 These cases can be disambiguated using neon_select_shape, except cases 1/9
14721 and 3/11 which depend on the operand type too.
5f4273c7 14722
5287ad62 14723 All the encoded bits are hardcoded by this function.
5f4273c7 14724
b7fc2769
JB
14725 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14726 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 14727
5287ad62 14728 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 14729 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
14730
14731static void
14732do_neon_mov (void)
14733{
037e8744
JB
14734 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14735 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14736 NS_NULL);
14737 struct neon_type_el et;
14738 const char *ldconst = 0;
5287ad62 14739
037e8744 14740 switch (rs)
5287ad62 14741 {
037e8744
JB
14742 case NS_DD: /* case 1/9. */
14743 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14744 /* It is not an error here if no type is given. */
14745 inst.error = NULL;
14746 if (et.type == NT_float && et.size == 64)
5287ad62 14747 {
037e8744
JB
14748 do_vfp_nsyn_opcode ("fcpyd");
14749 break;
5287ad62 14750 }
037e8744 14751 /* fall through. */
5287ad62 14752
037e8744
JB
14753 case NS_QQ: /* case 0/1. */
14754 {
14755 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14756 return;
14757 /* The architecture manual I have doesn't explicitly state which
14758 value the U bit should have for register->register moves, but
14759 the equivalent VORR instruction has U = 0, so do that. */
14760 inst.instruction = 0x0200110;
14761 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14762 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14763 inst.instruction |= LOW4 (inst.operands[1].reg);
14764 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14765 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14766 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14767 inst.instruction |= neon_quad (rs) << 6;
14768
88714cb8 14769 neon_dp_fixup (&inst);
037e8744
JB
14770 }
14771 break;
5f4273c7 14772
037e8744
JB
14773 case NS_DI: /* case 3/11. */
14774 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14775 inst.error = NULL;
14776 if (et.type == NT_float && et.size == 64)
5287ad62 14777 {
037e8744
JB
14778 /* case 11 (fconstd). */
14779 ldconst = "fconstd";
14780 goto encode_fconstd;
5287ad62 14781 }
037e8744
JB
14782 /* fall through. */
14783
14784 case NS_QI: /* case 2/3. */
14785 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14786 return;
14787 inst.instruction = 0x0800010;
14788 neon_move_immediate ();
88714cb8 14789 neon_dp_fixup (&inst);
5287ad62 14790 break;
5f4273c7 14791
037e8744
JB
14792 case NS_SR: /* case 4. */
14793 {
14794 unsigned bcdebits = 0;
91d6fa6a 14795 int logsize;
037e8744
JB
14796 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14797 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14798
91d6fa6a
NC
14799 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14800 logsize = neon_logbits (et.size);
14801
037e8744
JB
14802 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14803 _(BAD_FPU));
14804 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14805 && et.size != 32, _(BAD_FPU));
14806 constraint (et.type == NT_invtype, _("bad type for scalar"));
14807 constraint (x >= 64 / et.size, _("scalar index out of range"));
14808
14809 switch (et.size)
14810 {
14811 case 8: bcdebits = 0x8; break;
14812 case 16: bcdebits = 0x1; break;
14813 case 32: bcdebits = 0x0; break;
14814 default: ;
14815 }
14816
14817 bcdebits |= x << logsize;
14818
14819 inst.instruction = 0xe000b10;
14820 do_vfp_cond_or_thumb ();
14821 inst.instruction |= LOW4 (dn) << 16;
14822 inst.instruction |= HI1 (dn) << 7;
14823 inst.instruction |= inst.operands[1].reg << 12;
14824 inst.instruction |= (bcdebits & 3) << 5;
14825 inst.instruction |= (bcdebits >> 2) << 21;
14826 }
14827 break;
5f4273c7 14828
037e8744 14829 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 14830 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 14831 _(BAD_FPU));
b7fc2769 14832
037e8744
JB
14833 inst.instruction = 0xc400b10;
14834 do_vfp_cond_or_thumb ();
14835 inst.instruction |= LOW4 (inst.operands[0].reg);
14836 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14837 inst.instruction |= inst.operands[1].reg << 12;
14838 inst.instruction |= inst.operands[2].reg << 16;
14839 break;
5f4273c7 14840
037e8744
JB
14841 case NS_RS: /* case 6. */
14842 {
91d6fa6a 14843 unsigned logsize;
037e8744
JB
14844 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14845 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14846 unsigned abcdebits = 0;
14847
91d6fa6a
NC
14848 et = neon_check_type (2, NS_NULL,
14849 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14850 logsize = neon_logbits (et.size);
14851
037e8744
JB
14852 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14853 _(BAD_FPU));
14854 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14855 && et.size != 32, _(BAD_FPU));
14856 constraint (et.type == NT_invtype, _("bad type for scalar"));
14857 constraint (x >= 64 / et.size, _("scalar index out of range"));
14858
14859 switch (et.size)
14860 {
14861 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14862 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14863 case 32: abcdebits = 0x00; break;
14864 default: ;
14865 }
14866
14867 abcdebits |= x << logsize;
14868 inst.instruction = 0xe100b10;
14869 do_vfp_cond_or_thumb ();
14870 inst.instruction |= LOW4 (dn) << 16;
14871 inst.instruction |= HI1 (dn) << 7;
14872 inst.instruction |= inst.operands[0].reg << 12;
14873 inst.instruction |= (abcdebits & 3) << 5;
14874 inst.instruction |= (abcdebits >> 2) << 21;
14875 }
14876 break;
5f4273c7 14877
037e8744
JB
14878 case NS_RRD: /* case 7 (fmrrd). */
14879 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14880 _(BAD_FPU));
14881
14882 inst.instruction = 0xc500b10;
14883 do_vfp_cond_or_thumb ();
14884 inst.instruction |= inst.operands[0].reg << 12;
14885 inst.instruction |= inst.operands[1].reg << 16;
14886 inst.instruction |= LOW4 (inst.operands[2].reg);
14887 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14888 break;
5f4273c7 14889
037e8744
JB
14890 case NS_FF: /* case 8 (fcpys). */
14891 do_vfp_nsyn_opcode ("fcpys");
14892 break;
5f4273c7 14893
037e8744
JB
14894 case NS_FI: /* case 10 (fconsts). */
14895 ldconst = "fconsts";
14896 encode_fconstd:
14897 if (is_quarter_float (inst.operands[1].imm))
5287ad62 14898 {
037e8744
JB
14899 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14900 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
14901 }
14902 else
037e8744
JB
14903 first_error (_("immediate out of range"));
14904 break;
5f4273c7 14905
037e8744
JB
14906 case NS_RF: /* case 12 (fmrs). */
14907 do_vfp_nsyn_opcode ("fmrs");
14908 break;
5f4273c7 14909
037e8744
JB
14910 case NS_FR: /* case 13 (fmsr). */
14911 do_vfp_nsyn_opcode ("fmsr");
14912 break;
5f4273c7 14913
037e8744
JB
14914 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14915 (one of which is a list), but we have parsed four. Do some fiddling to
14916 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14917 expect. */
14918 case NS_RRFF: /* case 14 (fmrrs). */
14919 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14920 _("VFP registers must be adjacent"));
14921 inst.operands[2].imm = 2;
14922 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14923 do_vfp_nsyn_opcode ("fmrrs");
14924 break;
5f4273c7 14925
037e8744
JB
14926 case NS_FFRR: /* case 15 (fmsrr). */
14927 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14928 _("VFP registers must be adjacent"));
14929 inst.operands[1] = inst.operands[2];
14930 inst.operands[2] = inst.operands[3];
14931 inst.operands[0].imm = 2;
14932 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14933 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 14934 break;
5f4273c7 14935
5287ad62
JB
14936 default:
14937 abort ();
14938 }
14939}
14940
14941static void
14942do_neon_rshift_round_imm (void)
14943{
037e8744 14944 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14945 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14946 int imm = inst.operands[2].imm;
14947
14948 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14949 if (imm == 0)
14950 {
14951 inst.operands[2].present = 0;
14952 do_neon_mov ();
14953 return;
14954 }
14955
14956 constraint (imm < 1 || (unsigned)imm > et.size,
14957 _("immediate out of range for shift"));
037e8744 14958 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
14959 et.size - imm);
14960}
14961
14962static void
14963do_neon_movl (void)
14964{
14965 struct neon_type_el et = neon_check_type (2, NS_QD,
14966 N_EQK | N_DBL, N_SU_32 | N_KEY);
14967 unsigned sizebits = et.size >> 3;
14968 inst.instruction |= sizebits << 19;
14969 neon_two_same (0, et.type == NT_unsigned, -1);
14970}
14971
14972static void
14973do_neon_trn (void)
14974{
037e8744 14975 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14976 struct neon_type_el et = neon_check_type (2, rs,
14977 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 14978 NEON_ENCODE (INTEGER, inst);
037e8744 14979 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14980}
14981
14982static void
14983do_neon_zip_uzp (void)
14984{
037e8744 14985 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14986 struct neon_type_el et = neon_check_type (2, rs,
14987 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14988 if (rs == NS_DD && et.size == 32)
14989 {
14990 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14991 inst.instruction = N_MNEM_vtrn;
14992 do_neon_trn ();
14993 return;
14994 }
037e8744 14995 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14996}
14997
14998static void
14999do_neon_sat_abs_neg (void)
15000{
037e8744 15001 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15002 struct neon_type_el et = neon_check_type (2, rs,
15003 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 15004 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15005}
15006
15007static void
15008do_neon_pair_long (void)
15009{
037e8744 15010 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15011 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
15012 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
15013 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 15014 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15015}
15016
15017static void
15018do_neon_recip_est (void)
15019{
037e8744 15020 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15021 struct neon_type_el et = neon_check_type (2, rs,
15022 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
15023 inst.instruction |= (et.type == NT_float) << 8;
037e8744 15024 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15025}
15026
15027static void
15028do_neon_cls (void)
15029{
037e8744 15030 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15031 struct neon_type_el et = neon_check_type (2, rs,
15032 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 15033 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15034}
15035
15036static void
15037do_neon_clz (void)
15038{
037e8744 15039 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15040 struct neon_type_el et = neon_check_type (2, rs,
15041 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 15042 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15043}
15044
15045static void
15046do_neon_cnt (void)
15047{
037e8744 15048 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15049 struct neon_type_el et = neon_check_type (2, rs,
15050 N_EQK | N_INT, N_8 | N_KEY);
037e8744 15051 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15052}
15053
15054static void
15055do_neon_swp (void)
15056{
037e8744
JB
15057 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15058 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
15059}
15060
15061static void
15062do_neon_tbl_tbx (void)
15063{
15064 unsigned listlenbits;
dcbf9037 15065 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 15066
5287ad62
JB
15067 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
15068 {
dcbf9037 15069 first_error (_("bad list length for table lookup"));
5287ad62
JB
15070 return;
15071 }
5f4273c7 15072
5287ad62
JB
15073 listlenbits = inst.operands[1].imm - 1;
15074 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15075 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15076 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15077 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15078 inst.instruction |= LOW4 (inst.operands[2].reg);
15079 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15080 inst.instruction |= listlenbits << 8;
5f4273c7 15081
88714cb8 15082 neon_dp_fixup (&inst);
5287ad62
JB
15083}
15084
15085static void
15086do_neon_ldm_stm (void)
15087{
15088 /* P, U and L bits are part of bitmask. */
15089 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
15090 unsigned offsetbits = inst.operands[1].imm * 2;
15091
037e8744
JB
15092 if (inst.operands[1].issingle)
15093 {
15094 do_vfp_nsyn_ldm_stm (is_dbmode);
15095 return;
15096 }
15097
5287ad62
JB
15098 constraint (is_dbmode && !inst.operands[0].writeback,
15099 _("writeback (!) must be used for VLDMDB and VSTMDB"));
15100
15101 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15102 _("register list must contain at least 1 and at most 16 "
15103 "registers"));
15104
15105 inst.instruction |= inst.operands[0].reg << 16;
15106 inst.instruction |= inst.operands[0].writeback << 21;
15107 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15108 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
15109
15110 inst.instruction |= offsetbits;
5f4273c7 15111
037e8744 15112 do_vfp_cond_or_thumb ();
5287ad62
JB
15113}
15114
15115static void
15116do_neon_ldr_str (void)
15117{
5287ad62 15118 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 15119
6844b2c2
MGD
15120 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
15121 And is UNPREDICTABLE in thumb mode. */
15122 if (!is_ldr
15123 && inst.operands[1].reg == REG_PC
15124 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
15125 {
15126 if (!thumb_mode && warn_on_deprecated)
15127 as_warn (_("Use of PC here is deprecated"));
15128 else
15129 inst.error = _("Use of PC here is UNPREDICTABLE");
15130 }
15131
037e8744
JB
15132 if (inst.operands[0].issingle)
15133 {
cd2f129f
JB
15134 if (is_ldr)
15135 do_vfp_nsyn_opcode ("flds");
15136 else
15137 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
15138 }
15139 else
5287ad62 15140 {
cd2f129f
JB
15141 if (is_ldr)
15142 do_vfp_nsyn_opcode ("fldd");
5287ad62 15143 else
cd2f129f 15144 do_vfp_nsyn_opcode ("fstd");
5287ad62 15145 }
5287ad62
JB
15146}
15147
15148/* "interleave" version also handles non-interleaving register VLD1/VST1
15149 instructions. */
15150
15151static void
15152do_neon_ld_st_interleave (void)
15153{
037e8744 15154 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
15155 N_8 | N_16 | N_32 | N_64);
15156 unsigned alignbits = 0;
15157 unsigned idx;
15158 /* The bits in this table go:
15159 0: register stride of one (0) or two (1)
15160 1,2: register list length, minus one (1, 2, 3, 4).
15161 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
15162 We use -1 for invalid entries. */
15163 const int typetable[] =
15164 {
15165 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
15166 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
15167 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
15168 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
15169 };
15170 int typebits;
15171
dcbf9037
JB
15172 if (et.type == NT_invtype)
15173 return;
15174
5287ad62
JB
15175 if (inst.operands[1].immisalign)
15176 switch (inst.operands[1].imm >> 8)
15177 {
15178 case 64: alignbits = 1; break;
15179 case 128:
e23c0ad8
JZ
15180 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
15181 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
15182 goto bad_alignment;
15183 alignbits = 2;
15184 break;
15185 case 256:
e23c0ad8 15186 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
15187 goto bad_alignment;
15188 alignbits = 3;
15189 break;
15190 default:
15191 bad_alignment:
dcbf9037 15192 first_error (_("bad alignment"));
5287ad62
JB
15193 return;
15194 }
15195
15196 inst.instruction |= alignbits << 4;
15197 inst.instruction |= neon_logbits (et.size) << 6;
15198
15199 /* Bits [4:6] of the immediate in a list specifier encode register stride
15200 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
15201 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
15202 up the right value for "type" in a table based on this value and the given
15203 list style, then stick it back. */
15204 idx = ((inst.operands[0].imm >> 4) & 7)
15205 | (((inst.instruction >> 8) & 3) << 3);
15206
15207 typebits = typetable[idx];
5f4273c7 15208
5287ad62
JB
15209 constraint (typebits == -1, _("bad list type for instruction"));
15210
15211 inst.instruction &= ~0xf00;
15212 inst.instruction |= typebits << 8;
15213}
15214
15215/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
15216 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
15217 otherwise. The variable arguments are a list of pairs of legal (size, align)
15218 values, terminated with -1. */
15219
15220static int
15221neon_alignment_bit (int size, int align, int *do_align, ...)
15222{
15223 va_list ap;
15224 int result = FAIL, thissize, thisalign;
5f4273c7 15225
5287ad62
JB
15226 if (!inst.operands[1].immisalign)
15227 {
15228 *do_align = 0;
15229 return SUCCESS;
15230 }
5f4273c7 15231
5287ad62
JB
15232 va_start (ap, do_align);
15233
15234 do
15235 {
15236 thissize = va_arg (ap, int);
15237 if (thissize == -1)
15238 break;
15239 thisalign = va_arg (ap, int);
15240
15241 if (size == thissize && align == thisalign)
15242 result = SUCCESS;
15243 }
15244 while (result != SUCCESS);
15245
15246 va_end (ap);
15247
15248 if (result == SUCCESS)
15249 *do_align = 1;
15250 else
dcbf9037 15251 first_error (_("unsupported alignment for instruction"));
5f4273c7 15252
5287ad62
JB
15253 return result;
15254}
15255
15256static void
15257do_neon_ld_st_lane (void)
15258{
037e8744 15259 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15260 int align_good, do_align = 0;
15261 int logsize = neon_logbits (et.size);
15262 int align = inst.operands[1].imm >> 8;
15263 int n = (inst.instruction >> 8) & 3;
15264 int max_el = 64 / et.size;
5f4273c7 15265
dcbf9037
JB
15266 if (et.type == NT_invtype)
15267 return;
5f4273c7 15268
5287ad62
JB
15269 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
15270 _("bad list length"));
15271 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
15272 _("scalar index out of range"));
15273 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
15274 && et.size == 8,
15275 _("stride of 2 unavailable when element size is 8"));
5f4273c7 15276
5287ad62
JB
15277 switch (n)
15278 {
15279 case 0: /* VLD1 / VST1. */
15280 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
15281 32, 32, -1);
15282 if (align_good == FAIL)
15283 return;
15284 if (do_align)
15285 {
15286 unsigned alignbits = 0;
15287 switch (et.size)
15288 {
15289 case 16: alignbits = 0x1; break;
15290 case 32: alignbits = 0x3; break;
15291 default: ;
15292 }
15293 inst.instruction |= alignbits << 4;
15294 }
15295 break;
15296
15297 case 1: /* VLD2 / VST2. */
15298 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
15299 32, 64, -1);
15300 if (align_good == FAIL)
15301 return;
15302 if (do_align)
15303 inst.instruction |= 1 << 4;
15304 break;
15305
15306 case 2: /* VLD3 / VST3. */
15307 constraint (inst.operands[1].immisalign,
15308 _("can't use alignment with this instruction"));
15309 break;
15310
15311 case 3: /* VLD4 / VST4. */
15312 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15313 16, 64, 32, 64, 32, 128, -1);
15314 if (align_good == FAIL)
15315 return;
15316 if (do_align)
15317 {
15318 unsigned alignbits = 0;
15319 switch (et.size)
15320 {
15321 case 8: alignbits = 0x1; break;
15322 case 16: alignbits = 0x1; break;
15323 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
15324 default: ;
15325 }
15326 inst.instruction |= alignbits << 4;
15327 }
15328 break;
15329
15330 default: ;
15331 }
15332
15333 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
15334 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15335 inst.instruction |= 1 << (4 + logsize);
5f4273c7 15336
5287ad62
JB
15337 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
15338 inst.instruction |= logsize << 10;
15339}
15340
15341/* Encode single n-element structure to all lanes VLD<n> instructions. */
15342
15343static void
15344do_neon_ld_dup (void)
15345{
037e8744 15346 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15347 int align_good, do_align = 0;
15348
dcbf9037
JB
15349 if (et.type == NT_invtype)
15350 return;
15351
5287ad62
JB
15352 switch ((inst.instruction >> 8) & 3)
15353 {
15354 case 0: /* VLD1. */
9c2799c2 15355 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
15356 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15357 &do_align, 16, 16, 32, 32, -1);
15358 if (align_good == FAIL)
15359 return;
15360 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15361 {
15362 case 1: break;
15363 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 15364 default: first_error (_("bad list length")); return;
5287ad62
JB
15365 }
15366 inst.instruction |= neon_logbits (et.size) << 6;
15367 break;
15368
15369 case 1: /* VLD2. */
15370 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15371 &do_align, 8, 16, 16, 32, 32, 64, -1);
15372 if (align_good == FAIL)
15373 return;
15374 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15375 _("bad list length"));
15376 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15377 inst.instruction |= 1 << 5;
15378 inst.instruction |= neon_logbits (et.size) << 6;
15379 break;
15380
15381 case 2: /* VLD3. */
15382 constraint (inst.operands[1].immisalign,
15383 _("can't use alignment with this instruction"));
15384 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15385 _("bad list length"));
15386 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15387 inst.instruction |= 1 << 5;
15388 inst.instruction |= neon_logbits (et.size) << 6;
15389 break;
15390
15391 case 3: /* VLD4. */
15392 {
15393 int align = inst.operands[1].imm >> 8;
15394 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15395 16, 64, 32, 64, 32, 128, -1);
15396 if (align_good == FAIL)
15397 return;
15398 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15399 _("bad list length"));
15400 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15401 inst.instruction |= 1 << 5;
15402 if (et.size == 32 && align == 128)
15403 inst.instruction |= 0x3 << 6;
15404 else
15405 inst.instruction |= neon_logbits (et.size) << 6;
15406 }
15407 break;
15408
15409 default: ;
15410 }
15411
15412 inst.instruction |= do_align << 4;
15413}
15414
15415/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15416 apart from bits [11:4]. */
15417
15418static void
15419do_neon_ldx_stx (void)
15420{
b1a769ed
DG
15421 if (inst.operands[1].isreg)
15422 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15423
5287ad62
JB
15424 switch (NEON_LANE (inst.operands[0].imm))
15425 {
15426 case NEON_INTERLEAVE_LANES:
88714cb8 15427 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
15428 do_neon_ld_st_interleave ();
15429 break;
5f4273c7 15430
5287ad62 15431 case NEON_ALL_LANES:
88714cb8 15432 NEON_ENCODE (DUP, inst);
5287ad62
JB
15433 do_neon_ld_dup ();
15434 break;
5f4273c7 15435
5287ad62 15436 default:
88714cb8 15437 NEON_ENCODE (LANE, inst);
5287ad62
JB
15438 do_neon_ld_st_lane ();
15439 }
15440
15441 /* L bit comes from bit mask. */
15442 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15443 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15444 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 15445
5287ad62
JB
15446 if (inst.operands[1].postind)
15447 {
15448 int postreg = inst.operands[1].imm & 0xf;
15449 constraint (!inst.operands[1].immisreg,
15450 _("post-index must be a register"));
15451 constraint (postreg == 0xd || postreg == 0xf,
15452 _("bad register for post-index"));
15453 inst.instruction |= postreg;
15454 }
15455 else if (inst.operands[1].writeback)
15456 {
15457 inst.instruction |= 0xd;
15458 }
15459 else
5f4273c7
NC
15460 inst.instruction |= 0xf;
15461
5287ad62
JB
15462 if (thumb_mode)
15463 inst.instruction |= 0xf9000000;
15464 else
15465 inst.instruction |= 0xf4000000;
15466}
5287ad62
JB
15467\f
15468/* Overall per-instruction processing. */
15469
15470/* We need to be able to fix up arbitrary expressions in some statements.
15471 This is so that we can handle symbols that are an arbitrary distance from
15472 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
15473 which returns part of an address in a form which will be valid for
15474 a data instruction. We do this by pushing the expression into a symbol
15475 in the expr_section, and creating a fix for that. */
15476
15477static void
15478fix_new_arm (fragS * frag,
15479 int where,
15480 short int size,
15481 expressionS * exp,
15482 int pc_rel,
15483 int reloc)
15484{
15485 fixS * new_fix;
15486
15487 switch (exp->X_op)
15488 {
15489 case O_constant:
6e7ce2cd
PB
15490 if (pc_rel)
15491 {
15492 /* Create an absolute valued symbol, so we have something to
15493 refer to in the object file. Unfortunately for us, gas's
15494 generic expression parsing will already have folded out
15495 any use of .set foo/.type foo %function that may have
15496 been used to set type information of the target location,
15497 that's being specified symbolically. We have to presume
15498 the user knows what they are doing. */
15499 char name[16 + 8];
15500 symbolS *symbol;
15501
15502 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
15503
15504 symbol = symbol_find_or_make (name);
15505 S_SET_SEGMENT (symbol, absolute_section);
15506 symbol_set_frag (symbol, &zero_address_frag);
15507 S_SET_VALUE (symbol, exp->X_add_number);
15508 exp->X_op = O_symbol;
15509 exp->X_add_symbol = symbol;
15510 exp->X_add_number = 0;
15511 }
15512 /* FALLTHROUGH */
5287ad62
JB
15513 case O_symbol:
15514 case O_add:
15515 case O_subtract:
21d799b5
NC
15516 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
15517 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15518 break;
15519
15520 default:
21d799b5
NC
15521 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
15522 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15523 break;
15524 }
15525
15526 /* Mark whether the fix is to a THUMB instruction, or an ARM
15527 instruction. */
15528 new_fix->tc_fix_data = thumb_mode;
15529}
15530
15531/* Create a frg for an instruction requiring relaxation. */
15532static void
15533output_relax_insn (void)
15534{
15535 char * to;
15536 symbolS *sym;
0110f2b8
PB
15537 int offset;
15538
6e1cb1a6
PB
15539 /* The size of the instruction is unknown, so tie the debug info to the
15540 start of the instruction. */
15541 dwarf2_emit_insn (0);
6e1cb1a6 15542
0110f2b8
PB
15543 switch (inst.reloc.exp.X_op)
15544 {
15545 case O_symbol:
15546 sym = inst.reloc.exp.X_add_symbol;
15547 offset = inst.reloc.exp.X_add_number;
15548 break;
15549 case O_constant:
15550 sym = NULL;
15551 offset = inst.reloc.exp.X_add_number;
15552 break;
15553 default:
15554 sym = make_expr_symbol (&inst.reloc.exp);
15555 offset = 0;
15556 break;
15557 }
15558 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15559 inst.relax, sym, offset, NULL/*offset, opcode*/);
15560 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
15561}
15562
15563/* Write a 32-bit thumb instruction to buf. */
15564static void
15565put_thumb32_insn (char * buf, unsigned long insn)
15566{
15567 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15568 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15569}
15570
b99bd4ef 15571static void
c19d1205 15572output_inst (const char * str)
b99bd4ef 15573{
c19d1205 15574 char * to = NULL;
b99bd4ef 15575
c19d1205 15576 if (inst.error)
b99bd4ef 15577 {
c19d1205 15578 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
15579 return;
15580 }
5f4273c7
NC
15581 if (inst.relax)
15582 {
15583 output_relax_insn ();
0110f2b8 15584 return;
5f4273c7 15585 }
c19d1205
ZW
15586 if (inst.size == 0)
15587 return;
b99bd4ef 15588
c19d1205 15589 to = frag_more (inst.size);
8dc2430f
NC
15590 /* PR 9814: Record the thumb mode into the current frag so that we know
15591 what type of NOP padding to use, if necessary. We override any previous
15592 setting so that if the mode has changed then the NOPS that we use will
15593 match the encoding of the last instruction in the frag. */
cd000bff 15594 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
15595
15596 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 15597 {
9c2799c2 15598 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 15599 put_thumb32_insn (to, inst.instruction);
b99bd4ef 15600 }
c19d1205 15601 else if (inst.size > INSN_SIZE)
b99bd4ef 15602 {
9c2799c2 15603 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
15604 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15605 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 15606 }
c19d1205
ZW
15607 else
15608 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 15609
c19d1205
ZW
15610 if (inst.reloc.type != BFD_RELOC_UNUSED)
15611 fix_new_arm (frag_now, to - frag_now->fr_literal,
15612 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15613 inst.reloc.type);
b99bd4ef 15614
c19d1205 15615 dwarf2_emit_insn (inst.size);
c19d1205 15616}
b99bd4ef 15617
e07e6e58
NC
15618static char *
15619output_it_inst (int cond, int mask, char * to)
15620{
15621 unsigned long instruction = 0xbf00;
15622
15623 mask &= 0xf;
15624 instruction |= mask;
15625 instruction |= cond << 4;
15626
15627 if (to == NULL)
15628 {
15629 to = frag_more (2);
15630#ifdef OBJ_ELF
15631 dwarf2_emit_insn (2);
15632#endif
15633 }
15634
15635 md_number_to_chars (to, instruction, 2);
15636
15637 return to;
15638}
15639
c19d1205
ZW
15640/* Tag values used in struct asm_opcode's tag field. */
15641enum opcode_tag
15642{
15643 OT_unconditional, /* Instruction cannot be conditionalized.
15644 The ARM condition field is still 0xE. */
15645 OT_unconditionalF, /* Instruction cannot be conditionalized
15646 and carries 0xF in its ARM condition field. */
15647 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
15648 OT_csuffixF, /* Some forms of the instruction take a conditional
15649 suffix, others place 0xF where the condition field
15650 would be. */
c19d1205
ZW
15651 OT_cinfix3, /* Instruction takes a conditional infix,
15652 beginning at character index 3. (In
15653 unified mode, it becomes a suffix.) */
088fa78e
KH
15654 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15655 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
15656 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15657 character index 3, even in unified mode. Used for
15658 legacy instructions where suffix and infix forms
15659 may be ambiguous. */
c19d1205 15660 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 15661 suffix or an infix at character index 3. */
c19d1205
ZW
15662 OT_odd_infix_unc, /* This is the unconditional variant of an
15663 instruction that takes a conditional infix
15664 at an unusual position. In unified mode,
15665 this variant will accept a suffix. */
15666 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15667 are the conditional variants of instructions that
15668 take conditional infixes in unusual positions.
15669 The infix appears at character index
15670 (tag - OT_odd_infix_0). These are not accepted
15671 in unified mode. */
15672};
b99bd4ef 15673
c19d1205
ZW
15674/* Subroutine of md_assemble, responsible for looking up the primary
15675 opcode from the mnemonic the user wrote. STR points to the
15676 beginning of the mnemonic.
15677
15678 This is not simply a hash table lookup, because of conditional
15679 variants. Most instructions have conditional variants, which are
15680 expressed with a _conditional affix_ to the mnemonic. If we were
15681 to encode each conditional variant as a literal string in the opcode
15682 table, it would have approximately 20,000 entries.
15683
15684 Most mnemonics take this affix as a suffix, and in unified syntax,
15685 'most' is upgraded to 'all'. However, in the divided syntax, some
15686 instructions take the affix as an infix, notably the s-variants of
15687 the arithmetic instructions. Of those instructions, all but six
15688 have the infix appear after the third character of the mnemonic.
15689
15690 Accordingly, the algorithm for looking up primary opcodes given
15691 an identifier is:
15692
15693 1. Look up the identifier in the opcode table.
15694 If we find a match, go to step U.
15695
15696 2. Look up the last two characters of the identifier in the
15697 conditions table. If we find a match, look up the first N-2
15698 characters of the identifier in the opcode table. If we
15699 find a match, go to step CE.
15700
15701 3. Look up the fourth and fifth characters of the identifier in
15702 the conditions table. If we find a match, extract those
15703 characters from the identifier, and look up the remaining
15704 characters in the opcode table. If we find a match, go
15705 to step CM.
15706
15707 4. Fail.
15708
15709 U. Examine the tag field of the opcode structure, in case this is
15710 one of the six instructions with its conditional infix in an
15711 unusual place. If it is, the tag tells us where to find the
15712 infix; look it up in the conditions table and set inst.cond
15713 accordingly. Otherwise, this is an unconditional instruction.
15714 Again set inst.cond accordingly. Return the opcode structure.
15715
15716 CE. Examine the tag field to make sure this is an instruction that
15717 should receive a conditional suffix. If it is not, fail.
15718 Otherwise, set inst.cond from the suffix we already looked up,
15719 and return the opcode structure.
15720
15721 CM. Examine the tag field to make sure this is an instruction that
15722 should receive a conditional infix after the third character.
15723 If it is not, fail. Otherwise, undo the edits to the current
15724 line of input and proceed as for case CE. */
15725
15726static const struct asm_opcode *
15727opcode_lookup (char **str)
15728{
15729 char *end, *base;
15730 char *affix;
15731 const struct asm_opcode *opcode;
15732 const struct asm_cond *cond;
e3cb604e 15733 char save[2];
c19d1205
ZW
15734
15735 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 15736 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 15737 for (base = end = *str; *end != '\0'; end++)
721a8186 15738 if (*end == ' ' || *end == '.')
c19d1205 15739 break;
b99bd4ef 15740
c19d1205 15741 if (end == base)
c921be7d 15742 return NULL;
b99bd4ef 15743
5287ad62 15744 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 15745 if (end[0] == '.')
b99bd4ef 15746 {
5287ad62 15747 int offset = 2;
5f4273c7 15748
267d2029
JB
15749 /* The .w and .n suffixes are only valid if the unified syntax is in
15750 use. */
15751 if (unified_syntax && end[1] == 'w')
c19d1205 15752 inst.size_req = 4;
267d2029 15753 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
15754 inst.size_req = 2;
15755 else
5287ad62
JB
15756 offset = 0;
15757
15758 inst.vectype.elems = 0;
15759
15760 *str = end + offset;
b99bd4ef 15761
5f4273c7 15762 if (end[offset] == '.')
5287ad62 15763 {
267d2029
JB
15764 /* See if we have a Neon type suffix (possible in either unified or
15765 non-unified ARM syntax mode). */
dcbf9037 15766 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 15767 return NULL;
5287ad62
JB
15768 }
15769 else if (end[offset] != '\0' && end[offset] != ' ')
c921be7d 15770 return NULL;
b99bd4ef 15771 }
c19d1205
ZW
15772 else
15773 *str = end;
b99bd4ef 15774
c19d1205 15775 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5
NC
15776 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15777 end - base);
c19d1205 15778 if (opcode)
b99bd4ef 15779 {
c19d1205
ZW
15780 /* step U */
15781 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 15782 {
c19d1205
ZW
15783 inst.cond = COND_ALWAYS;
15784 return opcode;
b99bd4ef 15785 }
b99bd4ef 15786
278df34e 15787 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
15788 as_warn (_("conditional infixes are deprecated in unified syntax"));
15789 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 15790 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 15791 gas_assert (cond);
b99bd4ef 15792
c19d1205
ZW
15793 inst.cond = cond->value;
15794 return opcode;
15795 }
b99bd4ef 15796
c19d1205
ZW
15797 /* Cannot have a conditional suffix on a mnemonic of less than two
15798 characters. */
15799 if (end - base < 3)
c921be7d 15800 return NULL;
b99bd4ef 15801
c19d1205
ZW
15802 /* Look for suffixed mnemonic. */
15803 affix = end - 2;
21d799b5
NC
15804 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15805 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15806 affix - base);
c19d1205
ZW
15807 if (opcode && cond)
15808 {
15809 /* step CE */
15810 switch (opcode->tag)
15811 {
e3cb604e
PB
15812 case OT_cinfix3_legacy:
15813 /* Ignore conditional suffixes matched on infix only mnemonics. */
15814 break;
15815
c19d1205 15816 case OT_cinfix3:
088fa78e 15817 case OT_cinfix3_deprecated:
c19d1205
ZW
15818 case OT_odd_infix_unc:
15819 if (!unified_syntax)
e3cb604e 15820 return 0;
c19d1205
ZW
15821 /* else fall through */
15822
15823 case OT_csuffix:
037e8744 15824 case OT_csuffixF:
c19d1205
ZW
15825 case OT_csuf_or_in3:
15826 inst.cond = cond->value;
15827 return opcode;
15828
15829 case OT_unconditional:
15830 case OT_unconditionalF:
dfa9f0d5 15831 if (thumb_mode)
c921be7d 15832 inst.cond = cond->value;
dfa9f0d5
PB
15833 else
15834 {
c921be7d 15835 /* Delayed diagnostic. */
dfa9f0d5
PB
15836 inst.error = BAD_COND;
15837 inst.cond = COND_ALWAYS;
15838 }
c19d1205 15839 return opcode;
b99bd4ef 15840
c19d1205 15841 default:
c921be7d 15842 return NULL;
c19d1205
ZW
15843 }
15844 }
b99bd4ef 15845
c19d1205
ZW
15846 /* Cannot have a usual-position infix on a mnemonic of less than
15847 six characters (five would be a suffix). */
15848 if (end - base < 6)
c921be7d 15849 return NULL;
b99bd4ef 15850
c19d1205
ZW
15851 /* Look for infixed mnemonic in the usual position. */
15852 affix = base + 3;
21d799b5 15853 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 15854 if (!cond)
c921be7d 15855 return NULL;
e3cb604e
PB
15856
15857 memcpy (save, affix, 2);
15858 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5
NC
15859 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15860 (end - base) - 2);
e3cb604e
PB
15861 memmove (affix + 2, affix, (end - affix) - 2);
15862 memcpy (affix, save, 2);
15863
088fa78e
KH
15864 if (opcode
15865 && (opcode->tag == OT_cinfix3
15866 || opcode->tag == OT_cinfix3_deprecated
15867 || opcode->tag == OT_csuf_or_in3
15868 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 15869 {
c921be7d 15870 /* Step CM. */
278df34e 15871 if (warn_on_deprecated && unified_syntax
088fa78e
KH
15872 && (opcode->tag == OT_cinfix3
15873 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
15874 as_warn (_("conditional infixes are deprecated in unified syntax"));
15875
15876 inst.cond = cond->value;
15877 return opcode;
b99bd4ef
NC
15878 }
15879
c921be7d 15880 return NULL;
b99bd4ef
NC
15881}
15882
e07e6e58
NC
15883/* This function generates an initial IT instruction, leaving its block
15884 virtually open for the new instructions. Eventually,
15885 the mask will be updated by now_it_add_mask () each time
15886 a new instruction needs to be included in the IT block.
15887 Finally, the block is closed with close_automatic_it_block ().
15888 The block closure can be requested either from md_assemble (),
15889 a tencode (), or due to a label hook. */
15890
15891static void
15892new_automatic_it_block (int cond)
15893{
15894 now_it.state = AUTOMATIC_IT_BLOCK;
15895 now_it.mask = 0x18;
15896 now_it.cc = cond;
15897 now_it.block_length = 1;
cd000bff 15898 mapping_state (MAP_THUMB);
e07e6e58
NC
15899 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15900}
15901
15902/* Close an automatic IT block.
15903 See comments in new_automatic_it_block (). */
15904
15905static void
15906close_automatic_it_block (void)
15907{
15908 now_it.mask = 0x10;
15909 now_it.block_length = 0;
15910}
15911
15912/* Update the mask of the current automatically-generated IT
15913 instruction. See comments in new_automatic_it_block (). */
15914
15915static void
15916now_it_add_mask (int cond)
15917{
15918#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15919#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15920 | ((bitvalue) << (nbit)))
e07e6e58 15921 const int resulting_bit = (cond & 1);
c921be7d 15922
e07e6e58
NC
15923 now_it.mask &= 0xf;
15924 now_it.mask = SET_BIT_VALUE (now_it.mask,
15925 resulting_bit,
15926 (5 - now_it.block_length));
15927 now_it.mask = SET_BIT_VALUE (now_it.mask,
15928 1,
15929 ((5 - now_it.block_length) - 1) );
15930 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15931
15932#undef CLEAR_BIT
15933#undef SET_BIT_VALUE
e07e6e58
NC
15934}
15935
15936/* The IT blocks handling machinery is accessed through the these functions:
15937 it_fsm_pre_encode () from md_assemble ()
15938 set_it_insn_type () optional, from the tencode functions
15939 set_it_insn_type_last () ditto
15940 in_it_block () ditto
15941 it_fsm_post_encode () from md_assemble ()
15942 force_automatic_it_block_close () from label habdling functions
15943
15944 Rationale:
15945 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15946 initializing the IT insn type with a generic initial value depending
15947 on the inst.condition.
15948 2) During the tencode function, two things may happen:
15949 a) The tencode function overrides the IT insn type by
15950 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15951 b) The tencode function queries the IT block state by
15952 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15953
15954 Both set_it_insn_type and in_it_block run the internal FSM state
15955 handling function (handle_it_state), because: a) setting the IT insn
15956 type may incur in an invalid state (exiting the function),
15957 and b) querying the state requires the FSM to be updated.
15958 Specifically we want to avoid creating an IT block for conditional
15959 branches, so it_fsm_pre_encode is actually a guess and we can't
15960 determine whether an IT block is required until the tencode () routine
15961 has decided what type of instruction this actually it.
15962 Because of this, if set_it_insn_type and in_it_block have to be used,
15963 set_it_insn_type has to be called first.
15964
15965 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15966 determines the insn IT type depending on the inst.cond code.
15967 When a tencode () routine encodes an instruction that can be
15968 either outside an IT block, or, in the case of being inside, has to be
15969 the last one, set_it_insn_type_last () will determine the proper
15970 IT instruction type based on the inst.cond code. Otherwise,
15971 set_it_insn_type can be called for overriding that logic or
15972 for covering other cases.
15973
15974 Calling handle_it_state () may not transition the IT block state to
15975 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15976 still queried. Instead, if the FSM determines that the state should
15977 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15978 after the tencode () function: that's what it_fsm_post_encode () does.
15979
15980 Since in_it_block () calls the state handling function to get an
15981 updated state, an error may occur (due to invalid insns combination).
15982 In that case, inst.error is set.
15983 Therefore, inst.error has to be checked after the execution of
15984 the tencode () routine.
15985
15986 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15987 any pending state change (if any) that didn't take place in
15988 handle_it_state () as explained above. */
15989
15990static void
15991it_fsm_pre_encode (void)
15992{
15993 if (inst.cond != COND_ALWAYS)
15994 inst.it_insn_type = INSIDE_IT_INSN;
15995 else
15996 inst.it_insn_type = OUTSIDE_IT_INSN;
15997
15998 now_it.state_handled = 0;
15999}
16000
16001/* IT state FSM handling function. */
16002
16003static int
16004handle_it_state (void)
16005{
16006 now_it.state_handled = 1;
16007
16008 switch (now_it.state)
16009 {
16010 case OUTSIDE_IT_BLOCK:
16011 switch (inst.it_insn_type)
16012 {
16013 case OUTSIDE_IT_INSN:
16014 break;
16015
16016 case INSIDE_IT_INSN:
16017 case INSIDE_IT_LAST_INSN:
16018 if (thumb_mode == 0)
16019 {
c921be7d 16020 if (unified_syntax
e07e6e58
NC
16021 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
16022 as_tsktsk (_("Warning: conditional outside an IT block"\
16023 " for Thumb."));
16024 }
16025 else
16026 {
16027 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
16028 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
16029 {
16030 /* Automatically generate the IT instruction. */
16031 new_automatic_it_block (inst.cond);
16032 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
16033 close_automatic_it_block ();
16034 }
16035 else
16036 {
16037 inst.error = BAD_OUT_IT;
16038 return FAIL;
16039 }
16040 }
16041 break;
16042
16043 case IF_INSIDE_IT_LAST_INSN:
16044 case NEUTRAL_IT_INSN:
16045 break;
16046
16047 case IT_INSN:
16048 now_it.state = MANUAL_IT_BLOCK;
16049 now_it.block_length = 0;
16050 break;
16051 }
16052 break;
16053
16054 case AUTOMATIC_IT_BLOCK:
16055 /* Three things may happen now:
16056 a) We should increment current it block size;
16057 b) We should close current it block (closing insn or 4 insns);
16058 c) We should close current it block and start a new one (due
16059 to incompatible conditions or
16060 4 insns-length block reached). */
16061
16062 switch (inst.it_insn_type)
16063 {
16064 case OUTSIDE_IT_INSN:
16065 /* The closure of the block shall happen immediatelly,
16066 so any in_it_block () call reports the block as closed. */
16067 force_automatic_it_block_close ();
16068 break;
16069
16070 case INSIDE_IT_INSN:
16071 case INSIDE_IT_LAST_INSN:
16072 case IF_INSIDE_IT_LAST_INSN:
16073 now_it.block_length++;
16074
16075 if (now_it.block_length > 4
16076 || !now_it_compatible (inst.cond))
16077 {
16078 force_automatic_it_block_close ();
16079 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
16080 new_automatic_it_block (inst.cond);
16081 }
16082 else
16083 {
16084 now_it_add_mask (inst.cond);
16085 }
16086
16087 if (now_it.state == AUTOMATIC_IT_BLOCK
16088 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
16089 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
16090 close_automatic_it_block ();
16091 break;
16092
16093 case NEUTRAL_IT_INSN:
16094 now_it.block_length++;
16095
16096 if (now_it.block_length > 4)
16097 force_automatic_it_block_close ();
16098 else
16099 now_it_add_mask (now_it.cc & 1);
16100 break;
16101
16102 case IT_INSN:
16103 close_automatic_it_block ();
16104 now_it.state = MANUAL_IT_BLOCK;
16105 break;
16106 }
16107 break;
16108
16109 case MANUAL_IT_BLOCK:
16110 {
16111 /* Check conditional suffixes. */
16112 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
16113 int is_last;
16114 now_it.mask <<= 1;
16115 now_it.mask &= 0x1f;
16116 is_last = (now_it.mask == 0x10);
16117
16118 switch (inst.it_insn_type)
16119 {
16120 case OUTSIDE_IT_INSN:
16121 inst.error = BAD_NOT_IT;
16122 return FAIL;
16123
16124 case INSIDE_IT_INSN:
16125 if (cond != inst.cond)
16126 {
16127 inst.error = BAD_IT_COND;
16128 return FAIL;
16129 }
16130 break;
16131
16132 case INSIDE_IT_LAST_INSN:
16133 case IF_INSIDE_IT_LAST_INSN:
16134 if (cond != inst.cond)
16135 {
16136 inst.error = BAD_IT_COND;
16137 return FAIL;
16138 }
16139 if (!is_last)
16140 {
16141 inst.error = BAD_BRANCH;
16142 return FAIL;
16143 }
16144 break;
16145
16146 case NEUTRAL_IT_INSN:
16147 /* The BKPT instruction is unconditional even in an IT block. */
16148 break;
16149
16150 case IT_INSN:
16151 inst.error = BAD_IT_IT;
16152 return FAIL;
16153 }
16154 }
16155 break;
16156 }
16157
16158 return SUCCESS;
16159}
16160
16161static void
16162it_fsm_post_encode (void)
16163{
16164 int is_last;
16165
16166 if (!now_it.state_handled)
16167 handle_it_state ();
16168
16169 is_last = (now_it.mask == 0x10);
16170 if (is_last)
16171 {
16172 now_it.state = OUTSIDE_IT_BLOCK;
16173 now_it.mask = 0;
16174 }
16175}
16176
16177static void
16178force_automatic_it_block_close (void)
16179{
16180 if (now_it.state == AUTOMATIC_IT_BLOCK)
16181 {
16182 close_automatic_it_block ();
16183 now_it.state = OUTSIDE_IT_BLOCK;
16184 now_it.mask = 0;
16185 }
16186}
16187
16188static int
16189in_it_block (void)
16190{
16191 if (!now_it.state_handled)
16192 handle_it_state ();
16193
16194 return now_it.state != OUTSIDE_IT_BLOCK;
16195}
16196
c19d1205
ZW
16197void
16198md_assemble (char *str)
b99bd4ef 16199{
c19d1205
ZW
16200 char *p = str;
16201 const struct asm_opcode * opcode;
b99bd4ef 16202
c19d1205
ZW
16203 /* Align the previous label if needed. */
16204 if (last_label_seen != NULL)
b99bd4ef 16205 {
c19d1205
ZW
16206 symbol_set_frag (last_label_seen, frag_now);
16207 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
16208 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
16209 }
16210
c19d1205
ZW
16211 memset (&inst, '\0', sizeof (inst));
16212 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 16213
c19d1205
ZW
16214 opcode = opcode_lookup (&p);
16215 if (!opcode)
b99bd4ef 16216 {
c19d1205 16217 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 16218 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d
NC
16219 if (! create_register_alias (str, p)
16220 && ! create_neon_reg_alias (str, p))
c19d1205 16221 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 16222
b99bd4ef
NC
16223 return;
16224 }
16225
278df34e 16226 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
16227 as_warn (_("s suffix on comparison instruction is deprecated"));
16228
037e8744
JB
16229 /* The value which unconditional instructions should have in place of the
16230 condition field. */
16231 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
16232
c19d1205 16233 if (thumb_mode)
b99bd4ef 16234 {
e74cfd16 16235 arm_feature_set variant;
8f06b2d8
PB
16236
16237 variant = cpu_variant;
16238 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
16239 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
16240 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 16241 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
16242 if (!opcode->tvariant
16243 || (thumb_mode == 1
16244 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 16245 {
bf3eeda7 16246 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
b99bd4ef
NC
16247 return;
16248 }
c19d1205
ZW
16249 if (inst.cond != COND_ALWAYS && !unified_syntax
16250 && opcode->tencode != do_t_branch)
b99bd4ef 16251 {
c19d1205 16252 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
16253 return;
16254 }
16255
752d5da4 16256 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 16257 {
7e806470 16258 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
16259 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
16260 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
16261 {
16262 /* Two things are addressed here.
16263 1) Implicit require narrow instructions on Thumb-1.
16264 This avoids relaxation accidentally introducing Thumb-2
16265 instructions.
16266 2) Reject wide instructions in non Thumb-2 cores. */
16267 if (inst.size_req == 0)
16268 inst.size_req = 2;
16269 else if (inst.size_req == 4)
16270 {
bf3eeda7 16271 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
752d5da4
NC
16272 return;
16273 }
16274 }
076d447c
PB
16275 }
16276
c19d1205
ZW
16277 inst.instruction = opcode->tvalue;
16278
5be8be5d 16279 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
e07e6e58
NC
16280 {
16281 /* Prepare the it_insn_type for those encodings that don't set
16282 it. */
16283 it_fsm_pre_encode ();
c19d1205 16284
e07e6e58
NC
16285 opcode->tencode ();
16286
16287 it_fsm_post_encode ();
16288 }
e27ec89e 16289
0110f2b8 16290 if (!(inst.error || inst.relax))
b99bd4ef 16291 {
9c2799c2 16292 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
16293 inst.size = (inst.instruction > 0xffff ? 4 : 2);
16294 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 16295 {
c19d1205 16296 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
16297 return;
16298 }
16299 }
076d447c
PB
16300
16301 /* Something has gone badly wrong if we try to relax a fixed size
16302 instruction. */
9c2799c2 16303 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 16304
e74cfd16
PB
16305 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16306 *opcode->tvariant);
ee065d83 16307 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 16308 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 16309 anything other than bl/blx and v6-M instructions.
ee065d83 16310 This is overly pessimistic for relaxable instructions. */
7e806470
PB
16311 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
16312 || inst.relax)
e07e6e58
NC
16313 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
16314 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
16315 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16316 arm_ext_v6t2);
cd000bff 16317
88714cb8
DG
16318 check_neon_suffixes;
16319
cd000bff 16320 if (!inst.error)
c877a2f2
NC
16321 {
16322 mapping_state (MAP_THUMB);
16323 }
c19d1205 16324 }
3e9e4fcf 16325 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 16326 {
845b51d6
PB
16327 bfd_boolean is_bx;
16328
16329 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
16330 is_bx = (opcode->aencode == do_bx);
16331
c19d1205 16332 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
16333 if (!(is_bx && fix_v4bx)
16334 && !(opcode->avariant &&
16335 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 16336 {
bf3eeda7 16337 as_bad (_("selected processor does not support ARM mode `%s'"), str);
c19d1205 16338 return;
b99bd4ef 16339 }
c19d1205 16340 if (inst.size_req)
b99bd4ef 16341 {
c19d1205
ZW
16342 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
16343 return;
b99bd4ef
NC
16344 }
16345
c19d1205
ZW
16346 inst.instruction = opcode->avalue;
16347 if (opcode->tag == OT_unconditionalF)
16348 inst.instruction |= 0xF << 28;
16349 else
16350 inst.instruction |= inst.cond << 28;
16351 inst.size = INSN_SIZE;
5be8be5d 16352 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
e07e6e58
NC
16353 {
16354 it_fsm_pre_encode ();
16355 opcode->aencode ();
16356 it_fsm_post_encode ();
16357 }
ee065d83
PB
16358 /* Arm mode bx is marked as both v4T and v5 because it's still required
16359 on a hypothetical non-thumb v5 core. */
845b51d6 16360 if (is_bx)
e74cfd16 16361 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 16362 else
e74cfd16
PB
16363 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
16364 *opcode->avariant);
88714cb8
DG
16365
16366 check_neon_suffixes;
16367
cd000bff 16368 if (!inst.error)
c877a2f2
NC
16369 {
16370 mapping_state (MAP_ARM);
16371 }
b99bd4ef 16372 }
3e9e4fcf
JB
16373 else
16374 {
16375 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
16376 "-- `%s'"), str);
16377 return;
16378 }
c19d1205
ZW
16379 output_inst (str);
16380}
b99bd4ef 16381
e07e6e58
NC
16382static void
16383check_it_blocks_finished (void)
16384{
16385#ifdef OBJ_ELF
16386 asection *sect;
16387
16388 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
16389 if (seg_info (sect)->tc_segment_info_data.current_it.state
16390 == MANUAL_IT_BLOCK)
16391 {
16392 as_warn (_("section '%s' finished with an open IT block."),
16393 sect->name);
16394 }
16395#else
16396 if (now_it.state == MANUAL_IT_BLOCK)
16397 as_warn (_("file finished with an open IT block."));
16398#endif
16399}
16400
c19d1205
ZW
16401/* Various frobbings of labels and their addresses. */
16402
16403void
16404arm_start_line_hook (void)
16405{
16406 last_label_seen = NULL;
b99bd4ef
NC
16407}
16408
c19d1205
ZW
16409void
16410arm_frob_label (symbolS * sym)
b99bd4ef 16411{
c19d1205 16412 last_label_seen = sym;
b99bd4ef 16413
c19d1205 16414 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 16415
c19d1205
ZW
16416#if defined OBJ_COFF || defined OBJ_ELF
16417 ARM_SET_INTERWORK (sym, support_interwork);
16418#endif
b99bd4ef 16419
e07e6e58
NC
16420 force_automatic_it_block_close ();
16421
5f4273c7 16422 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
16423 as Thumb functions. This is because these labels, whilst
16424 they exist inside Thumb code, are not the entry points for
16425 possible ARM->Thumb calls. Also, these labels can be used
16426 as part of a computed goto or switch statement. eg gcc
16427 can generate code that looks like this:
b99bd4ef 16428
c19d1205
ZW
16429 ldr r2, [pc, .Laaa]
16430 lsl r3, r3, #2
16431 ldr r2, [r3, r2]
16432 mov pc, r2
b99bd4ef 16433
c19d1205
ZW
16434 .Lbbb: .word .Lxxx
16435 .Lccc: .word .Lyyy
16436 ..etc...
16437 .Laaa: .word Lbbb
b99bd4ef 16438
c19d1205
ZW
16439 The first instruction loads the address of the jump table.
16440 The second instruction converts a table index into a byte offset.
16441 The third instruction gets the jump address out of the table.
16442 The fourth instruction performs the jump.
b99bd4ef 16443
c19d1205
ZW
16444 If the address stored at .Laaa is that of a symbol which has the
16445 Thumb_Func bit set, then the linker will arrange for this address
16446 to have the bottom bit set, which in turn would mean that the
16447 address computation performed by the third instruction would end
16448 up with the bottom bit set. Since the ARM is capable of unaligned
16449 word loads, the instruction would then load the incorrect address
16450 out of the jump table, and chaos would ensue. */
16451 if (label_is_thumb_function_name
16452 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
16453 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 16454 {
c19d1205
ZW
16455 /* When the address of a Thumb function is taken the bottom
16456 bit of that address should be set. This will allow
16457 interworking between Arm and Thumb functions to work
16458 correctly. */
b99bd4ef 16459
c19d1205 16460 THUMB_SET_FUNC (sym, 1);
b99bd4ef 16461
c19d1205 16462 label_is_thumb_function_name = FALSE;
b99bd4ef 16463 }
07a53e5c 16464
07a53e5c 16465 dwarf2_emit_label (sym);
b99bd4ef
NC
16466}
16467
c921be7d 16468bfd_boolean
c19d1205 16469arm_data_in_code (void)
b99bd4ef 16470{
c19d1205 16471 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 16472 {
c19d1205
ZW
16473 *input_line_pointer = '/';
16474 input_line_pointer += 5;
16475 *input_line_pointer = 0;
c921be7d 16476 return TRUE;
b99bd4ef
NC
16477 }
16478
c921be7d 16479 return FALSE;
b99bd4ef
NC
16480}
16481
c19d1205
ZW
16482char *
16483arm_canonicalize_symbol_name (char * name)
b99bd4ef 16484{
c19d1205 16485 int len;
b99bd4ef 16486
c19d1205
ZW
16487 if (thumb_mode && (len = strlen (name)) > 5
16488 && streq (name + len - 5, "/data"))
16489 *(name + len - 5) = 0;
b99bd4ef 16490
c19d1205 16491 return name;
b99bd4ef 16492}
c19d1205
ZW
16493\f
16494/* Table of all register names defined by default. The user can
16495 define additional names with .req. Note that all register names
16496 should appear in both upper and lowercase variants. Some registers
16497 also have mixed-case names. */
b99bd4ef 16498
dcbf9037 16499#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 16500#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 16501#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
16502#define REGSET(p,t) \
16503 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
16504 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
16505 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
16506 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
16507#define REGSETH(p,t) \
16508 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
16509 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
16510 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
16511 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
16512#define REGSET2(p,t) \
16513 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
16514 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
16515 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
16516 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
16517#define SPLRBANK(base,bank,t) \
16518 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
16519 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
16520 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
16521 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
16522 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
16523 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 16524
c19d1205 16525static const struct reg_entry reg_names[] =
7ed4c4c5 16526{
c19d1205
ZW
16527 /* ARM integer registers. */
16528 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 16529
c19d1205
ZW
16530 /* ATPCS synonyms. */
16531 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
16532 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16533 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 16534
c19d1205
ZW
16535 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16536 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16537 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 16538
c19d1205
ZW
16539 /* Well-known aliases. */
16540 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16541 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16542
16543 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16544 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16545
16546 /* Coprocessor numbers. */
16547 REGSET(p, CP), REGSET(P, CP),
16548
16549 /* Coprocessor register numbers. The "cr" variants are for backward
16550 compatibility. */
16551 REGSET(c, CN), REGSET(C, CN),
16552 REGSET(cr, CN), REGSET(CR, CN),
16553
90ec0d68
MGD
16554 /* ARM banked registers. */
16555 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
16556 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
16557 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
16558 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
16559 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
16560 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
16561 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
16562
16563 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
16564 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
16565 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
16566 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
16567 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
16568 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB),
16569 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
16570 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
16571
16572 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
16573 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
16574 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
16575 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
16576 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
16577 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
16578 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
16579 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
16580 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
16581
c19d1205
ZW
16582 /* FPA registers. */
16583 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16584 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16585
16586 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16587 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16588
16589 /* VFP SP registers. */
5287ad62
JB
16590 REGSET(s,VFS), REGSET(S,VFS),
16591 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
16592
16593 /* VFP DP Registers. */
5287ad62
JB
16594 REGSET(d,VFD), REGSET(D,VFD),
16595 /* Extra Neon DP registers. */
16596 REGSETH(d,VFD), REGSETH(D,VFD),
16597
16598 /* Neon QP registers. */
16599 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
16600
16601 /* VFP control registers. */
16602 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16603 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
16604 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16605 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16606 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16607 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
16608
16609 /* Maverick DSP coprocessor registers. */
16610 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16611 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16612
16613 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16614 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16615 REGDEF(dspsc,0,DSPSC),
16616
16617 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16618 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16619 REGDEF(DSPSC,0,DSPSC),
16620
16621 /* iWMMXt data registers - p0, c0-15. */
16622 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16623
16624 /* iWMMXt control registers - p1, c0-3. */
16625 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16626 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16627 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16628 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16629
16630 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16631 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16632 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16633 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16634 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16635
16636 /* XScale accumulator registers. */
16637 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16638};
16639#undef REGDEF
16640#undef REGNUM
16641#undef REGSET
7ed4c4c5 16642
c19d1205
ZW
16643/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16644 within psr_required_here. */
16645static const struct asm_psr psrs[] =
16646{
16647 /* Backward compatibility notation. Note that "all" is no longer
16648 truly all possible PSR bits. */
16649 {"all", PSR_c | PSR_f},
16650 {"flg", PSR_f},
16651 {"ctl", PSR_c},
16652
16653 /* Individual flags. */
16654 {"f", PSR_f},
16655 {"c", PSR_c},
16656 {"x", PSR_x},
16657 {"s", PSR_s},
59b42a0d 16658
c19d1205
ZW
16659 /* Combinations of flags. */
16660 {"fs", PSR_f | PSR_s},
16661 {"fx", PSR_f | PSR_x},
16662 {"fc", PSR_f | PSR_c},
16663 {"sf", PSR_s | PSR_f},
16664 {"sx", PSR_s | PSR_x},
16665 {"sc", PSR_s | PSR_c},
16666 {"xf", PSR_x | PSR_f},
16667 {"xs", PSR_x | PSR_s},
16668 {"xc", PSR_x | PSR_c},
16669 {"cf", PSR_c | PSR_f},
16670 {"cs", PSR_c | PSR_s},
16671 {"cx", PSR_c | PSR_x},
16672 {"fsx", PSR_f | PSR_s | PSR_x},
16673 {"fsc", PSR_f | PSR_s | PSR_c},
16674 {"fxs", PSR_f | PSR_x | PSR_s},
16675 {"fxc", PSR_f | PSR_x | PSR_c},
16676 {"fcs", PSR_f | PSR_c | PSR_s},
16677 {"fcx", PSR_f | PSR_c | PSR_x},
16678 {"sfx", PSR_s | PSR_f | PSR_x},
16679 {"sfc", PSR_s | PSR_f | PSR_c},
16680 {"sxf", PSR_s | PSR_x | PSR_f},
16681 {"sxc", PSR_s | PSR_x | PSR_c},
16682 {"scf", PSR_s | PSR_c | PSR_f},
16683 {"scx", PSR_s | PSR_c | PSR_x},
16684 {"xfs", PSR_x | PSR_f | PSR_s},
16685 {"xfc", PSR_x | PSR_f | PSR_c},
16686 {"xsf", PSR_x | PSR_s | PSR_f},
16687 {"xsc", PSR_x | PSR_s | PSR_c},
16688 {"xcf", PSR_x | PSR_c | PSR_f},
16689 {"xcs", PSR_x | PSR_c | PSR_s},
16690 {"cfs", PSR_c | PSR_f | PSR_s},
16691 {"cfx", PSR_c | PSR_f | PSR_x},
16692 {"csf", PSR_c | PSR_s | PSR_f},
16693 {"csx", PSR_c | PSR_s | PSR_x},
16694 {"cxf", PSR_c | PSR_x | PSR_f},
16695 {"cxs", PSR_c | PSR_x | PSR_s},
16696 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16697 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16698 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16699 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16700 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16701 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16702 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16703 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16704 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16705 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16706 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16707 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16708 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16709 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16710 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16711 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16712 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16713 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16714 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16715 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16716 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16717 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16718 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16719 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16720};
16721
62b3e311
PB
16722/* Table of V7M psr names. */
16723static const struct asm_psr v7m_psrs[] =
16724{
2b744c99
PB
16725 {"apsr", 0 }, {"APSR", 0 },
16726 {"iapsr", 1 }, {"IAPSR", 1 },
16727 {"eapsr", 2 }, {"EAPSR", 2 },
16728 {"psr", 3 }, {"PSR", 3 },
16729 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16730 {"ipsr", 5 }, {"IPSR", 5 },
16731 {"epsr", 6 }, {"EPSR", 6 },
16732 {"iepsr", 7 }, {"IEPSR", 7 },
16733 {"msp", 8 }, {"MSP", 8 },
16734 {"psp", 9 }, {"PSP", 9 },
16735 {"primask", 16}, {"PRIMASK", 16},
16736 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
16737 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16738 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99
PB
16739 {"faultmask", 19}, {"FAULTMASK", 19},
16740 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
16741};
16742
c19d1205
ZW
16743/* Table of all shift-in-operand names. */
16744static const struct asm_shift_name shift_names [] =
b99bd4ef 16745{
c19d1205
ZW
16746 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16747 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16748 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16749 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16750 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16751 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16752};
b99bd4ef 16753
c19d1205
ZW
16754/* Table of all explicit relocation names. */
16755#ifdef OBJ_ELF
16756static struct reloc_entry reloc_names[] =
16757{
16758 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16759 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16760 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16761 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16762 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16763 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16764 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16765 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16766 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16767 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 16768 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
16769 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
16770 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
16771 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
16772 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
16773 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
16774 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
16775 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
16776};
16777#endif
b99bd4ef 16778
c19d1205
ZW
16779/* Table of all conditional affixes. 0xF is not defined as a condition code. */
16780static const struct asm_cond conds[] =
16781{
16782 {"eq", 0x0},
16783 {"ne", 0x1},
16784 {"cs", 0x2}, {"hs", 0x2},
16785 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16786 {"mi", 0x4},
16787 {"pl", 0x5},
16788 {"vs", 0x6},
16789 {"vc", 0x7},
16790 {"hi", 0x8},
16791 {"ls", 0x9},
16792 {"ge", 0xa},
16793 {"lt", 0xb},
16794 {"gt", 0xc},
16795 {"le", 0xd},
16796 {"al", 0xe}
16797};
bfae80f2 16798
62b3e311
PB
16799static struct asm_barrier_opt barrier_opt_names[] =
16800{
52e7f43d
RE
16801 { "sy", 0xf }, { "SY", 0xf },
16802 { "un", 0x7 }, { "UN", 0x7 },
16803 { "st", 0xe }, { "ST", 0xe },
16804 { "unst", 0x6 }, { "UNST", 0x6 },
16805 { "ish", 0xb }, { "ISH", 0xb },
16806 { "sh", 0xb }, { "SH", 0xb },
16807 { "ishst", 0xa }, { "ISHST", 0xa },
16808 { "shst", 0xa }, { "SHST", 0xa },
16809 { "nsh", 0x7 }, { "NSH", 0x7 },
16810 { "nshst", 0x6 }, { "NSHST", 0x6 },
16811 { "osh", 0x3 }, { "OSH", 0x3 },
16812 { "oshst", 0x2 }, { "OSHST", 0x2 }
62b3e311
PB
16813};
16814
c19d1205
ZW
16815/* Table of ARM-format instructions. */
16816
16817/* Macros for gluing together operand strings. N.B. In all cases
16818 other than OPS0, the trailing OP_stop comes from default
16819 zero-initialization of the unspecified elements of the array. */
16820#define OPS0() { OP_stop, }
16821#define OPS1(a) { OP_##a, }
16822#define OPS2(a,b) { OP_##a,OP_##b, }
16823#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16824#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16825#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16826#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16827
5be8be5d
DG
16828/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16829 This is useful when mixing operands for ARM and THUMB, i.e. using the
16830 MIX_ARM_THUMB_OPERANDS macro.
16831 In order to use these macros, prefix the number of operands with _
16832 e.g. _3. */
16833#define OPS_1(a) { a, }
16834#define OPS_2(a,b) { a,b, }
16835#define OPS_3(a,b,c) { a,b,c, }
16836#define OPS_4(a,b,c,d) { a,b,c,d, }
16837#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16838#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16839
c19d1205
ZW
16840/* These macros abstract out the exact format of the mnemonic table and
16841 save some repeated characters. */
16842
16843/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16844#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16845 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 16846 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16847
16848/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16849 a T_MNEM_xyz enumerator. */
16850#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16851 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16852#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16853 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16854
16855/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16856 infix after the third character. */
16857#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 16858 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 16859 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 16860#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 16861 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 16862 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 16863#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16864 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 16865#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16866 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16867#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16868 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 16869#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16870 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16871
16872/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16873 appear in the condition table. */
16874#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
21d799b5 16875 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
1887dd22 16876 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16877
16878#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
16879 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16880 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16881 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16882 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16883 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16884 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16885 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16886 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16887 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16888 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16889 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16890 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16891 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16892 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16893 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16894 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16895 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16896 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16897 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
16898
16899#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
16900 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16901#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
21d799b5 16902 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16903
16904/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
16905 field is still 0xE. Many of the Thumb variants can be executed
16906 conditionally, so this is checked separately. */
c19d1205 16907#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16908 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16909 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16910
16911/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16912 condition code field. */
16913#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 16914 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16915 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16916
16917/* ARM-only variants of all the above. */
6a86118a 16918#define CE(mnem, op, nops, ops, ae) \
21d799b5 16919 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
16920
16921#define C3(mnem, op, nops, ops, ae) \
16922 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16923
e3cb604e
PB
16924/* Legacy mnemonics that always have conditional infix after the third
16925 character. */
16926#define CL(mnem, op, nops, ops, ae) \
21d799b5 16927 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16928 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16929
8f06b2d8
PB
16930/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16931#define cCE(mnem, op, nops, ops, ae) \
21d799b5 16932 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16933
e3cb604e
PB
16934/* Legacy coprocessor instructions where conditional infix and conditional
16935 suffix are ambiguous. For consistency this includes all FPA instructions,
16936 not just the potentially ambiguous ones. */
16937#define cCL(mnem, op, nops, ops, ae) \
21d799b5 16938 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16939 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16940
16941/* Coprocessor, takes either a suffix or a position-3 infix
16942 (for an FPA corner case). */
16943#define C3E(mnem, op, nops, ops, ae) \
21d799b5 16944 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 16945 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16946
6a86118a 16947#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
16948 { m1 #m2 m3, OPS##nops ops, \
16949 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
16950 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16951
16952#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
16953 xCM_ (m1, , m2, op, nops, ops, ae), \
16954 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16955 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16956 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16957 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16958 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16959 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16960 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16961 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16962 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16963 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16964 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16965 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16966 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16967 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16968 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16969 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16970 xCM_ (m1, le, m2, op, nops, ops, ae), \
16971 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
16972
16973#define UE(mnem, op, nops, ops, ae) \
16974 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16975
16976#define UF(mnem, op, nops, ops, ae) \
16977 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16978
5287ad62
JB
16979/* Neon data-processing. ARM versions are unconditional with cond=0xf.
16980 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16981 use the same encoding function for each. */
16982#define NUF(mnem, op, nops, ops, enc) \
16983 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16984 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16985
16986/* Neon data processing, version which indirects through neon_enc_tab for
16987 the various overloaded versions of opcodes. */
16988#define nUF(mnem, op, nops, ops, enc) \
21d799b5 16989 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16990 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16991
16992/* Neon insn with conditional suffix for the ARM version, non-overloaded
16993 version. */
037e8744
JB
16994#define NCE_tag(mnem, op, nops, ops, enc, tag) \
16995 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
16996 THUMB_VARIANT, do_##enc, do_##enc }
16997
037e8744 16998#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 16999 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
17000
17001#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 17002 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 17003
5287ad62 17004/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 17005#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 17006 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
17007 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17008
037e8744 17009#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 17010 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
17011
17012#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 17013 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 17014
c19d1205
ZW
17015#define do_0 0
17016
c19d1205 17017static const struct asm_opcode insns[] =
bfae80f2 17018{
e74cfd16
PB
17019#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
17020#define THUMB_VARIANT &arm_ext_v4t
21d799b5
NC
17021 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
17022 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
17023 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
17024 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
17025 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
17026 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
17027 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
17028 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
17029 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
17030 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
17031 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
17032 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
17033 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
17034 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
17035 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
17036 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
17037
17038 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
17039 for setting PSR flag bits. They are obsolete in V6 and do not
17040 have Thumb equivalents. */
21d799b5
NC
17041 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17042 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17043 CL("tstp", 110f000, 2, (RR, SH), cmp),
17044 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17045 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17046 CL("cmpp", 150f000, 2, (RR, SH), cmp),
17047 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17048 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17049 CL("cmnp", 170f000, 2, (RR, SH), cmp),
17050
17051 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
17052 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
17053 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
17054 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
17055
17056 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
17057 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17058 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
17059 OP_RRnpc),
17060 OP_ADDRGLDR),ldst, t_ldst),
17061 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
17062
17063 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17064 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17065 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17066 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17067 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17068 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17069
17070 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
17071 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
17072 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
17073 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 17074
c19d1205 17075 /* Pseudo ops. */
21d799b5 17076 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 17077 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 17078 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
17079
17080 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
17081 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
17082 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
17083 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
17084 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
17085 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
17086 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
17087 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
17088 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
17089 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
17090 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
17091 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
17092 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 17093
16a4cf17 17094 /* These may simplify to neg. */
21d799b5
NC
17095 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
17096 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 17097
c921be7d
NC
17098#undef THUMB_VARIANT
17099#define THUMB_VARIANT & arm_ext_v6
17100
21d799b5 17101 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
17102
17103 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
17104#undef THUMB_VARIANT
17105#define THUMB_VARIANT & arm_ext_v6t2
17106
21d799b5
NC
17107 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17108 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17109 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 17110
5be8be5d
DG
17111 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17112 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17113 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
17114 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 17115
21d799b5
NC
17116 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17117 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 17118
21d799b5
NC
17119 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17120 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
17121
17122 /* V1 instructions with no Thumb analogue at all. */
21d799b5 17123 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
17124 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
17125
17126 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
17127 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
17128 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
17129 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
17130 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
17131 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
17132 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
17133 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
17134
c921be7d
NC
17135#undef ARM_VARIANT
17136#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
17137#undef THUMB_VARIANT
17138#define THUMB_VARIANT & arm_ext_v4t
17139
21d799b5
NC
17140 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
17141 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 17142
c921be7d
NC
17143#undef THUMB_VARIANT
17144#define THUMB_VARIANT & arm_ext_v6t2
17145
21d799b5 17146 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
17147 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
17148
17149 /* Generic coprocessor instructions. */
21d799b5
NC
17150 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17151 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17152 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17153 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17154 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17155 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 17156 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 17157
c921be7d
NC
17158#undef ARM_VARIANT
17159#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
17160
21d799b5 17161 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
17162 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
17163
c921be7d
NC
17164#undef ARM_VARIANT
17165#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
17166#undef THUMB_VARIANT
17167#define THUMB_VARIANT & arm_ext_msr
17168
d2cd1205
JB
17169 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
17170 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 17171
c921be7d
NC
17172#undef ARM_VARIANT
17173#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
17174#undef THUMB_VARIANT
17175#define THUMB_VARIANT & arm_ext_v6t2
17176
21d799b5
NC
17177 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17178 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17179 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17180 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17181 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17182 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17183 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17184 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 17185
c921be7d
NC
17186#undef ARM_VARIANT
17187#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
17188#undef THUMB_VARIANT
17189#define THUMB_VARIANT & arm_ext_v4t
17190
5be8be5d
DG
17191 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17192 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17193 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17194 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17195 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17196 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 17197
c921be7d
NC
17198#undef ARM_VARIANT
17199#define ARM_VARIANT & arm_ext_v4t_5
17200
c19d1205
ZW
17201 /* ARM Architecture 4T. */
17202 /* Note: bx (and blx) are required on V5, even if the processor does
17203 not support Thumb. */
21d799b5 17204 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 17205
c921be7d
NC
17206#undef ARM_VARIANT
17207#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
17208#undef THUMB_VARIANT
17209#define THUMB_VARIANT & arm_ext_v5t
17210
c19d1205
ZW
17211 /* Note: blx has 2 variants; the .value coded here is for
17212 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
17213 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
17214 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 17215
c921be7d
NC
17216#undef THUMB_VARIANT
17217#define THUMB_VARIANT & arm_ext_v6t2
17218
21d799b5
NC
17219 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
17220 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17221 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17222 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17223 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17224 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17225 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17226 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 17227
c921be7d
NC
17228#undef ARM_VARIANT
17229#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
9e3c6df6
PB
17230#undef THUMB_VARIANT
17231#define THUMB_VARIANT &arm_ext_v5exp
c921be7d 17232
21d799b5
NC
17233 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17234 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17235 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17236 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 17237
21d799b5
NC
17238 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17239 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 17240
21d799b5
NC
17241 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17242 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17243 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17244 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 17245
21d799b5
NC
17246 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17247 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17248 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17249 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 17250
21d799b5
NC
17251 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17252 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 17253
03ee1b7f
NC
17254 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17255 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17256 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17257 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 17258
c921be7d
NC
17259#undef ARM_VARIANT
17260#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
9e3c6df6
PB
17261#undef THUMB_VARIANT
17262#define THUMB_VARIANT &arm_ext_v6t2
c921be7d 17263
21d799b5 17264 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
17265 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
17266 ldrd, t_ldstd),
17267 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
17268 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 17269
21d799b5
NC
17270 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17271 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 17272
c921be7d
NC
17273#undef ARM_VARIANT
17274#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
17275
21d799b5 17276 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 17277
c921be7d
NC
17278#undef ARM_VARIANT
17279#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
17280#undef THUMB_VARIANT
17281#define THUMB_VARIANT & arm_ext_v6
17282
21d799b5
NC
17283 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
17284 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
17285 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17286 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17287 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17288 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17289 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17290 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17291 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17292 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 17293
c921be7d
NC
17294#undef THUMB_VARIANT
17295#define THUMB_VARIANT & arm_ext_v6t2
17296
5be8be5d
DG
17297 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
17298 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17299 strex, t_strex),
21d799b5
NC
17300 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17301 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 17302
21d799b5
NC
17303 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
17304 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 17305
9e3c6df6 17306/* ARM V6 not included in V7M. */
c921be7d
NC
17307#undef THUMB_VARIANT
17308#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6
PB
17309 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17310 UF(rfeib, 9900a00, 1, (RRw), rfe),
17311 UF(rfeda, 8100a00, 1, (RRw), rfe),
17312 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17313 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17314 UF(rfefa, 9900a00, 1, (RRw), rfe),
17315 UF(rfeea, 8100a00, 1, (RRw), rfe),
17316 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17317 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
17318 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
17319 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
17320 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 17321
9e3c6df6
PB
17322/* ARM V6 not included in V7M (eg. integer SIMD). */
17323#undef THUMB_VARIANT
17324#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
17325 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
17326 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
17327 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
17328 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17329 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17330 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17331 /* Old name for QASX. */
21d799b5
NC
17332 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17333 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17334 /* Old name for QSAX. */
21d799b5
NC
17335 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17336 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17337 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17338 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17339 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17340 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17341 /* Old name for SASX. */
21d799b5
NC
17342 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17343 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17344 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17345 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17346 /* Old name for SHASX. */
21d799b5
NC
17347 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17348 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17349 /* Old name for SHSAX. */
21d799b5
NC
17350 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17351 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17352 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17353 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17354 /* Old name for SSAX. */
21d799b5
NC
17355 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17356 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17357 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17358 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17359 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17360 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17361 /* Old name for UASX. */
21d799b5
NC
17362 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17363 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17364 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17365 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17366 /* Old name for UHASX. */
21d799b5
NC
17367 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17368 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17369 /* Old name for UHSAX. */
21d799b5
NC
17370 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17371 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17372 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17373 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17374 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17375 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17376 /* Old name for UQASX. */
21d799b5
NC
17377 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17378 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17379 /* Old name for UQSAX. */
21d799b5
NC
17380 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17381 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17382 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17383 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17384 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17385 /* Old name for USAX. */
21d799b5
NC
17386 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17387 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
17388 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17389 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17390 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17391 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17392 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17393 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17394 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17395 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17396 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17397 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17398 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17399 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17400 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17401 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17402 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17403 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17404 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17405 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17406 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17407 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17408 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17409 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17410 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17411 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17412 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17413 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17414 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
17415 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
17416 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
17417 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17418 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17419 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 17420
c921be7d
NC
17421#undef ARM_VARIANT
17422#define ARM_VARIANT & arm_ext_v6k
17423#undef THUMB_VARIANT
17424#define THUMB_VARIANT & arm_ext_v6k
17425
21d799b5
NC
17426 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
17427 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
17428 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
17429 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 17430
c921be7d
NC
17431#undef THUMB_VARIANT
17432#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
17433 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
17434 ldrexd, t_ldrexd),
17435 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
17436 RRnpcb), strexd, t_strexd),
ebdca51a 17437
c921be7d
NC
17438#undef THUMB_VARIANT
17439#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
17440 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
17441 rd_rn, rd_rn),
17442 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
17443 rd_rn, rd_rn),
17444 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17445 strex, rm_rd_rn),
17446 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17447 strex, rm_rd_rn),
21d799b5 17448 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 17449
c921be7d 17450#undef ARM_VARIANT
f4c65163
MGD
17451#define ARM_VARIANT & arm_ext_sec
17452#undef THUMB_VARIANT
17453#define THUMB_VARIANT & arm_ext_sec
c921be7d 17454
21d799b5 17455 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 17456
90ec0d68
MGD
17457#undef ARM_VARIANT
17458#define ARM_VARIANT & arm_ext_virt
17459#undef THUMB_VARIANT
17460#define THUMB_VARIANT & arm_ext_virt
17461
17462 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
17463 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
17464
c921be7d
NC
17465#undef ARM_VARIANT
17466#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
17467#undef THUMB_VARIANT
17468#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 17469
21d799b5
NC
17470 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
17471 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
17472 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17473 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 17474
21d799b5
NC
17475 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17476 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
17477 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
17478 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 17479
5be8be5d
DG
17480 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17481 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17482 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17483 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 17484
bf3eeda7
NS
17485 /* Thumb-only instructions. */
17486#undef ARM_VARIANT
17487#define ARM_VARIANT NULL
17488 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
17489 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
17490
17491 /* ARM does not really have an IT instruction, so always allow it.
17492 The opcode is copied from Thumb in order to allow warnings in
17493 -mimplicit-it=[never | arm] modes. */
17494#undef ARM_VARIANT
17495#define ARM_VARIANT & arm_ext_v1
17496
21d799b5
NC
17497 TUE("it", bf08, bf08, 1, (COND), it, t_it),
17498 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
17499 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
17500 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
17501 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
17502 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
17503 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
17504 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
17505 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
17506 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
17507 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
17508 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
17509 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
17510 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
17511 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 17512 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
17513 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
17514 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 17515
92e90b6e 17516 /* Thumb2 only instructions. */
c921be7d
NC
17517#undef ARM_VARIANT
17518#define ARM_VARIANT NULL
92e90b6e 17519
21d799b5
NC
17520 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17521 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17522 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
17523 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
17524 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
17525 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 17526
eea54501
MGD
17527 /* Hardware division instructions. */
17528#undef ARM_VARIANT
17529#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
17530#undef THUMB_VARIANT
17531#define THUMB_VARIANT & arm_ext_div
17532
eea54501
MGD
17533 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
17534 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 17535
7e806470 17536 /* ARM V6M/V7 instructions. */
c921be7d
NC
17537#undef ARM_VARIANT
17538#define ARM_VARIANT & arm_ext_barrier
17539#undef THUMB_VARIANT
17540#define THUMB_VARIANT & arm_ext_barrier
17541
52e7f43d
RE
17542 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
17543 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
17544 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
7e806470 17545
62b3e311 17546 /* ARM V7 instructions. */
c921be7d
NC
17547#undef ARM_VARIANT
17548#define ARM_VARIANT & arm_ext_v7
17549#undef THUMB_VARIANT
17550#define THUMB_VARIANT & arm_ext_v7
17551
21d799b5
NC
17552 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
17553 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 17554
60e5ef9f
MGD
17555#undef ARM_VARIANT
17556#define ARM_VARIANT & arm_ext_mp
17557#undef THUMB_VARIANT
17558#define THUMB_VARIANT & arm_ext_mp
17559
17560 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
17561
c921be7d
NC
17562#undef ARM_VARIANT
17563#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
17564
21d799b5
NC
17565 cCE("wfs", e200110, 1, (RR), rd),
17566 cCE("rfs", e300110, 1, (RR), rd),
17567 cCE("wfc", e400110, 1, (RR), rd),
17568 cCE("rfc", e500110, 1, (RR), rd),
17569
17570 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
17571 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
17572 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
17573 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
17574
17575 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
17576 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
17577 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
17578 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
17579
17580 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
17581 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
17582 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
17583 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
17584 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
17585 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
17586 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
17587 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
17588 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
17589 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
17590 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
17591 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
17592
17593 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
17594 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
17595 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
17596 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
17597 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17598 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17599 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17600 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17601 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17602 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17603 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17604 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17605
17606 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17607 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17608 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17609 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17610 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17611 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17612 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17613 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17614 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17615 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17616 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17617 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17618
17619 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17620 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17621 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17622 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17623 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17624 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17625 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17626 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17627 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17628 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17629 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17630 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17631
17632 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17633 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17634 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17635 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17636 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17637 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17638 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17639 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17640 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17641 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17642 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17643 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17644
17645 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17646 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17647 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17648 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17649 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17650 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17651 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17652 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17653 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17654 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17655 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17656 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17657
17658 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17659 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17660 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17661 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17662 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17663 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17664 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17665 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17666 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17667 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17668 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17669 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17670
17671 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17672 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17673 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17674 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17675 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17676 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17677 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17678 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17679 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17680 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17681 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17682 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17683
17684 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17685 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17686 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17687 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17688 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17689 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17690 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17691 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17692 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17693 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17694 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17695 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17696
17697 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17698 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17699 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17700 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17701 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17702 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17703 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17704 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17705 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17706 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17707 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17708 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17709
17710 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17711 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17712 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17713 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17714 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17715 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17716 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17717 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17718 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17719 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17720 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17721 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17722
17723 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17724 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17725 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17726 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17727 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17728 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17729 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17730 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17731 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17732 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17733 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17734 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17735
17736 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17737 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17738 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17739 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17740 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17741 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17742 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17743 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17744 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17745 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17746 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17747 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17748
17749 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17750 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17751 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17752 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17753 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17754 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17755 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17756 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17757 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17758 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17759 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17760 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17761
17762 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17763 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17764 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17765 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17766 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17767 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17768 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17769 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17770 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17771 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17772 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17773 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17774
17775 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17776 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17777 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17778 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17779 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17780 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17781 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17782 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17783 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17784 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17785 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17786 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17787
17788 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17789 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17790 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17791 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17792 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17793 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17794 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17795 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17796 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17797 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17798 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17799 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17800
17801 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17802 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17803 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17804 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17805 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17806 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17807 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17808 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17809 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17810 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17811 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17812 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17813
17814 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17815 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17816 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17817 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17818 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17819 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17820 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17821 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17822 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17823 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17824 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17825 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17826
17827 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17828 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17829 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17830 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17831 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17832 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17833 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17834 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17835 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17836 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17837 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17838 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17839
17840 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17841 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17842 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17843 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17844 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17845 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17846 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17847 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17848 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17849 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17850 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17851 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17852
17853 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17854 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17855 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17856 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17857 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17858 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17859 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17860 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17861 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17862 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17863 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17864 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17865
17866 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17867 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17868 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17869 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17870 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17871 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17872 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17873 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17874 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17875 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17876 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17877 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17878
17879 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17880 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17881 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17882 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17883 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17884 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17885 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17886 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17887 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17888 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17889 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17890 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17891
17892 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17893 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17894 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17895 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17896 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17897 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17898 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17899 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17900 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17901 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17902 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17903 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17904
17905 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17906 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17907 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17908 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17909 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17910 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17911 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17912 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17913 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17914 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17915 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17916 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17917
17918 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17919 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17920 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17921 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17922 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17923 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17924 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17925 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17926 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17927 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17928 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17929 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17930
17931 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17932 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17933 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17934 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17935 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17936 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17937 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17938 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17939 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17940 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17941 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17942 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17943
17944 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17945 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17946 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17947 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17948 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17949 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17950 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17951 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17952 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17953 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17954 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17955 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17956
17957 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17958 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17959 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17960 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17961
17962 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17963 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17964 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17965 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17966 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17967 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17968 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17969 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17970 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17971 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17972 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17973 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 17974
c19d1205
ZW
17975 /* The implementation of the FIX instruction is broken on some
17976 assemblers, in that it accepts a precision specifier as well as a
17977 rounding specifier, despite the fact that this is meaningless.
17978 To be more compatible, we accept it as well, though of course it
17979 does not set any bits. */
21d799b5
NC
17980 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17981 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17982 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17983 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17984 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17985 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17986 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17987 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17988 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17989 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17990 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17991 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17992 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 17993
c19d1205 17994 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
17995#undef ARM_VARIANT
17996#define ARM_VARIANT & fpu_fpa_ext_v2
17997
21d799b5
NC
17998 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17999 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18000 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18001 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18002 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18003 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 18004
c921be7d
NC
18005#undef ARM_VARIANT
18006#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
18007
c19d1205 18008 /* Moves and type conversions. */
21d799b5
NC
18009 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
18010 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
18011 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
18012 cCE("fmstat", ef1fa10, 0, (), noargs),
f7c21dc7
NC
18013 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
18014 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
21d799b5
NC
18015 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
18016 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
18017 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
18018 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18019 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
18020 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18021 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
18022 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
18023
18024 /* Memory operations. */
21d799b5
NC
18025 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
18026 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
18027 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18028 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18029 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18030 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18031 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18032 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18033 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18034 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18035 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18036 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18037 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18038 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18039 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18040 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18041 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18042 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 18043
c19d1205 18044 /* Monadic operations. */
21d799b5
NC
18045 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
18046 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
18047 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
18048
18049 /* Dyadic operations. */
21d799b5
NC
18050 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18051 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18052 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18053 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18054 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18055 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18056 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18057 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18058 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 18059
c19d1205 18060 /* Comparisons. */
21d799b5
NC
18061 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
18062 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
18063 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
18064 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 18065
62f3b8c8
PB
18066 /* Double precision load/store are still present on single precision
18067 implementations. */
18068 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
18069 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
18070 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18071 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18072 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18073 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18074 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18075 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18076 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18077 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 18078
c921be7d
NC
18079#undef ARM_VARIANT
18080#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
18081
c19d1205 18082 /* Moves and type conversions. */
21d799b5
NC
18083 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18084 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18085 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18086 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
18087 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
18088 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
18089 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
18090 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18091 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
18092 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18093 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18094 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18095 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 18096
c19d1205 18097 /* Monadic operations. */
21d799b5
NC
18098 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18099 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18100 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
18101
18102 /* Dyadic operations. */
21d799b5
NC
18103 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18104 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18105 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18106 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18107 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18108 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18109 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18110 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18111 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 18112
c19d1205 18113 /* Comparisons. */
21d799b5
NC
18114 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18115 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
18116 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18117 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 18118
c921be7d
NC
18119#undef ARM_VARIANT
18120#define ARM_VARIANT & fpu_vfp_ext_v2
18121
21d799b5
NC
18122 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
18123 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
18124 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
18125 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 18126
037e8744
JB
18127/* Instructions which may belong to either the Neon or VFP instruction sets.
18128 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
18129#undef ARM_VARIANT
18130#define ARM_VARIANT & fpu_vfp_ext_v1xd
18131#undef THUMB_VARIANT
18132#define THUMB_VARIANT & fpu_vfp_ext_v1xd
18133
037e8744
JB
18134 /* These mnemonics are unique to VFP. */
18135 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
18136 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
18137 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18138 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18139 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18140 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
18141 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
18142 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
18143 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
18144 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
18145
18146 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
18147 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
18148 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
18149 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 18150
21d799b5
NC
18151 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
18152 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
18153
18154 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18155 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18156
55881a11
MGD
18157 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18158 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18159 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18160 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18161 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18162 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
18163 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
18164 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 18165
e3e535bc
NC
18166 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
18167 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
21d799b5
NC
18168 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
18169 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 18170
037e8744
JB
18171
18172 /* NOTE: All VMOV encoding is special-cased! */
18173 NCE(vmov, 0, 1, (VMOV), neon_mov),
18174 NCE(vmovq, 0, 1, (VMOV), neon_mov),
18175
c921be7d
NC
18176#undef THUMB_VARIANT
18177#define THUMB_VARIANT & fpu_neon_ext_v1
18178#undef ARM_VARIANT
18179#define ARM_VARIANT & fpu_neon_ext_v1
18180
5287ad62
JB
18181 /* Data processing with three registers of the same length. */
18182 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
18183 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
18184 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
18185 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18186 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18187 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18188 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18189 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18190 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18191 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
18192 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18193 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
18194 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18195 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
18196 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18197 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
18198 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18199 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
18200 /* If not immediate, fall back to neon_dyadic_i64_su.
18201 shl_imm should accept I8 I16 I32 I64,
18202 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
18203 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
18204 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
18205 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
18206 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 18207 /* Logic ops, types optional & ignored. */
4316f0d2
DG
18208 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18209 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18210 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18211 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18212 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18213 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18214 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18215 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18216 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
18217 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
18218 /* Bitfield ops, untyped. */
18219 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18220 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18221 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18222 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18223 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18224 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18225 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
18226 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18227 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18228 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18229 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18230 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18231 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
18232 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
18233 back to neon_dyadic_if_su. */
21d799b5
NC
18234 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18235 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18236 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18237 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18238 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18239 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
18240 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18241 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 18242 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
18243 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
18244 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 18245 /* As above, D registers only. */
21d799b5
NC
18246 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
18247 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 18248 /* Int and float variants, signedness unimportant. */
21d799b5
NC
18249 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18250 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18251 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 18252 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
18253 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
18254 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
18255 /* vtst takes sizes 8, 16, 32. */
18256 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
18257 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
18258 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 18259 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 18260 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
18261 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18262 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
18263 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18264 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
18265 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18266 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
18267 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18268 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
18269 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18270 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
18271 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18272 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
18273 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18274 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18275 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18276 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18277
18278 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 18279 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
18280 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
18281
18282 /* Data processing with two registers and a shift amount. */
18283 /* Right shifts, and variants with rounding.
18284 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
18285 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18286 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18287 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18288 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18289 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18290 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18291 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18292 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18293 /* Shift and insert. Sizes accepted 8 16 32 64. */
18294 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
18295 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
18296 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
18297 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
18298 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
18299 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
18300 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
18301 /* Right shift immediate, saturating & narrowing, with rounding variants.
18302 Types accepted S16 S32 S64 U16 U32 U64. */
18303 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18304 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18305 /* As above, unsigned. Types accepted S16 S32 S64. */
18306 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18307 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18308 /* Right shift narrowing. Types accepted I16 I32 I64. */
18309 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18310 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18311 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 18312 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 18313 /* CVT with optional immediate for fixed-point variant. */
21d799b5 18314 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 18315
4316f0d2
DG
18316 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
18317 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
18318
18319 /* Data processing, three registers of different lengths. */
18320 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
18321 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
18322 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
18323 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
18324 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
18325 /* If not scalar, fall back to neon_dyadic_long.
18326 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
18327 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
18328 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
18329 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
18330 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18331 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18332 /* Dyadic, narrowing insns. Types I16 I32 I64. */
18333 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18334 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18335 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18336 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18337 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
18338 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18339 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18340 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
18341 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
18342 S16 S32 U16 U32. */
21d799b5 18343 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
18344
18345 /* Extract. Size 8. */
3b8d421e
PB
18346 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
18347 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
18348
18349 /* Two registers, miscellaneous. */
18350 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
18351 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
18352 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
18353 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
18354 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
18355 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
18356 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
18357 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
18358 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
18359 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
18360 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
18361 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
18362 /* VMOVN. Types I16 I32 I64. */
21d799b5 18363 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 18364 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 18365 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 18366 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 18367 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
18368 /* VZIP / VUZP. Sizes 8 16 32. */
18369 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
18370 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
18371 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
18372 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
18373 /* VQABS / VQNEG. Types S8 S16 S32. */
18374 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18375 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
18376 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18377 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
18378 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
18379 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
18380 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
18381 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
18382 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
18383 /* Reciprocal estimates. Types U32 F32. */
18384 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
18385 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
18386 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
18387 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
18388 /* VCLS. Types S8 S16 S32. */
18389 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
18390 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
18391 /* VCLZ. Types I8 I16 I32. */
18392 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
18393 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
18394 /* VCNT. Size 8. */
18395 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
18396 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
18397 /* Two address, untyped. */
18398 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
18399 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
18400 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
18401 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
18402 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
18403
18404 /* Table lookup. Size 8. */
18405 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18406 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18407
c921be7d
NC
18408#undef THUMB_VARIANT
18409#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
18410#undef ARM_VARIANT
18411#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
18412
5287ad62 18413 /* Neon element/structure load/store. */
21d799b5
NC
18414 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18415 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18416 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18417 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18418 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18419 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18420 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18421 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 18422
c921be7d 18423#undef THUMB_VARIANT
62f3b8c8
PB
18424#define THUMB_VARIANT &fpu_vfp_ext_v3xd
18425#undef ARM_VARIANT
18426#define ARM_VARIANT &fpu_vfp_ext_v3xd
18427 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
18428 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18429 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18430 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18431 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18432 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18433 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18434 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18435 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18436
18437#undef THUMB_VARIANT
c921be7d
NC
18438#define THUMB_VARIANT & fpu_vfp_ext_v3
18439#undef ARM_VARIANT
18440#define ARM_VARIANT & fpu_vfp_ext_v3
18441
21d799b5 18442 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 18443 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18444 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18445 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18446 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18447 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18448 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18449 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18450 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 18451
62f3b8c8
PB
18452#undef ARM_VARIANT
18453#define ARM_VARIANT &fpu_vfp_ext_fma
18454#undef THUMB_VARIANT
18455#define THUMB_VARIANT &fpu_vfp_ext_fma
18456 /* Mnemonics shared by Neon and VFP. These are included in the
18457 VFP FMA variant; NEON and VFP FMA always includes the NEON
18458 FMA instructions. */
18459 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18460 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18461 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
18462 the v form should always be used. */
18463 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18464 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18465 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18466 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18467 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18468 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18469
5287ad62 18470#undef THUMB_VARIANT
c921be7d
NC
18471#undef ARM_VARIANT
18472#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
18473
21d799b5
NC
18474 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18475 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18476 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18477 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18478 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18479 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18480 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
18481 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 18482
c921be7d
NC
18483#undef ARM_VARIANT
18484#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
18485
21d799b5
NC
18486 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
18487 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
18488 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
18489 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
18490 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
18491 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
18492 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
18493 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
18494 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
18495 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18496 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18497 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18498 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18499 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18500 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18501 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18502 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18503 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18504 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
18505 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
18506 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18507 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18508 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18509 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18510 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18511 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18512 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
18513 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
18514 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
18515 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
18516 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
18517 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
18518 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
18519 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
18520 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
18521 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
18522 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
18523 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18524 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18525 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18526 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18527 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18528 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18529 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18530 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18531 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18532 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
18533 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18534 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18535 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18536 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18537 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18538 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18539 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18540 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18541 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18542 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18543 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18544 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18545 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18546 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18547 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18548 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18549 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18550 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18551 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18552 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18553 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18554 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18555 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18556 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18557 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18558 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18559 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18560 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18561 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18562 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18563 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18564 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18565 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18566 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18567 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18568 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18569 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18570 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18571 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18572 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18573 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18574 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
18575 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18576 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18577 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18578 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18579 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18580 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18581 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18582 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18583 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18584 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18585 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18586 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18587 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18588 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18589 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18590 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18591 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18592 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18593 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18594 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18595 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18596 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
18597 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18598 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18599 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18600 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18601 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18602 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18603 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18604 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18605 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18606 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18607 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18608 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18609 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18610 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18611 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18612 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18613 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18614 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18615 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18616 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18617 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18618 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18619 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18620 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18621 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18622 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18623 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18624 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18625 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18626 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18627 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18628 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18629 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18630 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18631 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18632 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18633 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18634 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18635 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18636 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18637 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18638 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18639 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18640 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18641 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18642 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18643 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18644 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18645 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18646 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18647 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 18648
c921be7d
NC
18649#undef ARM_VARIANT
18650#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18651
21d799b5
NC
18652 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18653 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18654 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18655 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18656 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18657 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18658 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18659 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18660 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18661 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18662 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18663 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18664 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18665 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18666 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18667 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18668 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18669 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18670 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18671 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18672 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18673 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18674 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18675 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18676 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18677 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18678 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18679 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18680 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18681 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18682 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18683 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18684 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18685 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18686 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18687 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18688 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18689 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18690 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18691 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18692 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18693 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18694 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18695 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18696 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18697 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18698 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18699 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18700 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18701 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18702 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18703 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18704 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18705 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18706 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18707 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18708 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 18709
c921be7d
NC
18710#undef ARM_VARIANT
18711#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18712
21d799b5
NC
18713 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18714 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18715 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18716 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18717 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18718 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18719 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18720 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18721 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18722 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18723 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18724 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18725 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18726 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18727 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18728 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18729 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18730 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18731 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18732 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18733 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18734 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18735 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18736 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18737 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18738 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18739 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18740 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18741 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18742 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18743 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18744 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18745 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18746 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18747 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18748 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18749 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18750 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18751 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18752 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18753 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18754 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18755 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18756 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18757 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18758 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18759 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18760 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18761 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18762 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18763 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18764 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18765 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18766 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18767 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18768 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18769 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18770 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18771 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18772 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18773 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18774 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18775 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18776 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18777 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18778 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18779 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18780 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18781 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18782 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18783 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18784 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18785 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18786 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18787 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18788 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
18789};
18790#undef ARM_VARIANT
18791#undef THUMB_VARIANT
18792#undef TCE
18793#undef TCM
18794#undef TUE
18795#undef TUF
18796#undef TCC
8f06b2d8 18797#undef cCE
e3cb604e
PB
18798#undef cCL
18799#undef C3E
c19d1205
ZW
18800#undef CE
18801#undef CM
18802#undef UE
18803#undef UF
18804#undef UT
5287ad62
JB
18805#undef NUF
18806#undef nUF
18807#undef NCE
18808#undef nCE
c19d1205
ZW
18809#undef OPS0
18810#undef OPS1
18811#undef OPS2
18812#undef OPS3
18813#undef OPS4
18814#undef OPS5
18815#undef OPS6
18816#undef do_0
18817\f
18818/* MD interface: bits in the object file. */
bfae80f2 18819
c19d1205
ZW
18820/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18821 for use in the a.out file, and stores them in the array pointed to by buf.
18822 This knows about the endian-ness of the target machine and does
18823 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18824 2 (short) and 4 (long) Floating numbers are put out as a series of
18825 LITTLENUMS (shorts, here at least). */
b99bd4ef 18826
c19d1205
ZW
18827void
18828md_number_to_chars (char * buf, valueT val, int n)
18829{
18830 if (target_big_endian)
18831 number_to_chars_bigendian (buf, val, n);
18832 else
18833 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
18834}
18835
c19d1205
ZW
18836static valueT
18837md_chars_to_number (char * buf, int n)
bfae80f2 18838{
c19d1205
ZW
18839 valueT result = 0;
18840 unsigned char * where = (unsigned char *) buf;
bfae80f2 18841
c19d1205 18842 if (target_big_endian)
b99bd4ef 18843 {
c19d1205
ZW
18844 while (n--)
18845 {
18846 result <<= 8;
18847 result |= (*where++ & 255);
18848 }
b99bd4ef 18849 }
c19d1205 18850 else
b99bd4ef 18851 {
c19d1205
ZW
18852 while (n--)
18853 {
18854 result <<= 8;
18855 result |= (where[n] & 255);
18856 }
bfae80f2 18857 }
b99bd4ef 18858
c19d1205 18859 return result;
bfae80f2 18860}
b99bd4ef 18861
c19d1205 18862/* MD interface: Sections. */
b99bd4ef 18863
0110f2b8
PB
18864/* Estimate the size of a frag before relaxing. Assume everything fits in
18865 2 bytes. */
18866
c19d1205 18867int
0110f2b8 18868md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
18869 segT segtype ATTRIBUTE_UNUSED)
18870{
0110f2b8
PB
18871 fragp->fr_var = 2;
18872 return 2;
18873}
18874
18875/* Convert a machine dependent frag. */
18876
18877void
18878md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18879{
18880 unsigned long insn;
18881 unsigned long old_op;
18882 char *buf;
18883 expressionS exp;
18884 fixS *fixp;
18885 int reloc_type;
18886 int pc_rel;
18887 int opcode;
18888
18889 buf = fragp->fr_literal + fragp->fr_fix;
18890
18891 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
18892 if (fragp->fr_symbol)
18893 {
0110f2b8
PB
18894 exp.X_op = O_symbol;
18895 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
18896 }
18897 else
18898 {
0110f2b8 18899 exp.X_op = O_constant;
5f4273c7 18900 }
0110f2b8
PB
18901 exp.X_add_number = fragp->fr_offset;
18902 opcode = fragp->fr_subtype;
18903 switch (opcode)
18904 {
18905 case T_MNEM_ldr_pc:
18906 case T_MNEM_ldr_pc2:
18907 case T_MNEM_ldr_sp:
18908 case T_MNEM_str_sp:
18909 case T_MNEM_ldr:
18910 case T_MNEM_ldrb:
18911 case T_MNEM_ldrh:
18912 case T_MNEM_str:
18913 case T_MNEM_strb:
18914 case T_MNEM_strh:
18915 if (fragp->fr_var == 4)
18916 {
5f4273c7 18917 insn = THUMB_OP32 (opcode);
0110f2b8
PB
18918 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18919 {
18920 insn |= (old_op & 0x700) << 4;
18921 }
18922 else
18923 {
18924 insn |= (old_op & 7) << 12;
18925 insn |= (old_op & 0x38) << 13;
18926 }
18927 insn |= 0x00000c00;
18928 put_thumb32_insn (buf, insn);
18929 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18930 }
18931 else
18932 {
18933 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18934 }
18935 pc_rel = (opcode == T_MNEM_ldr_pc2);
18936 break;
18937 case T_MNEM_adr:
18938 if (fragp->fr_var == 4)
18939 {
18940 insn = THUMB_OP32 (opcode);
18941 insn |= (old_op & 0xf0) << 4;
18942 put_thumb32_insn (buf, insn);
18943 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18944 }
18945 else
18946 {
18947 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18948 exp.X_add_number -= 4;
18949 }
18950 pc_rel = 1;
18951 break;
18952 case T_MNEM_mov:
18953 case T_MNEM_movs:
18954 case T_MNEM_cmp:
18955 case T_MNEM_cmn:
18956 if (fragp->fr_var == 4)
18957 {
18958 int r0off = (opcode == T_MNEM_mov
18959 || opcode == T_MNEM_movs) ? 0 : 8;
18960 insn = THUMB_OP32 (opcode);
18961 insn = (insn & 0xe1ffffff) | 0x10000000;
18962 insn |= (old_op & 0x700) << r0off;
18963 put_thumb32_insn (buf, insn);
18964 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18965 }
18966 else
18967 {
18968 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18969 }
18970 pc_rel = 0;
18971 break;
18972 case T_MNEM_b:
18973 if (fragp->fr_var == 4)
18974 {
18975 insn = THUMB_OP32(opcode);
18976 put_thumb32_insn (buf, insn);
18977 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18978 }
18979 else
18980 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18981 pc_rel = 1;
18982 break;
18983 case T_MNEM_bcond:
18984 if (fragp->fr_var == 4)
18985 {
18986 insn = THUMB_OP32(opcode);
18987 insn |= (old_op & 0xf00) << 14;
18988 put_thumb32_insn (buf, insn);
18989 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18990 }
18991 else
18992 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18993 pc_rel = 1;
18994 break;
18995 case T_MNEM_add_sp:
18996 case T_MNEM_add_pc:
18997 case T_MNEM_inc_sp:
18998 case T_MNEM_dec_sp:
18999 if (fragp->fr_var == 4)
19000 {
19001 /* ??? Choose between add and addw. */
19002 insn = THUMB_OP32 (opcode);
19003 insn |= (old_op & 0xf0) << 4;
19004 put_thumb32_insn (buf, insn);
16805f35
PB
19005 if (opcode == T_MNEM_add_pc)
19006 reloc_type = BFD_RELOC_ARM_T32_IMM12;
19007 else
19008 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
19009 }
19010 else
19011 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19012 pc_rel = 0;
19013 break;
19014
19015 case T_MNEM_addi:
19016 case T_MNEM_addis:
19017 case T_MNEM_subi:
19018 case T_MNEM_subis:
19019 if (fragp->fr_var == 4)
19020 {
19021 insn = THUMB_OP32 (opcode);
19022 insn |= (old_op & 0xf0) << 4;
19023 insn |= (old_op & 0xf) << 16;
19024 put_thumb32_insn (buf, insn);
16805f35
PB
19025 if (insn & (1 << 20))
19026 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
19027 else
19028 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
19029 }
19030 else
19031 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19032 pc_rel = 0;
19033 break;
19034 default:
5f4273c7 19035 abort ();
0110f2b8
PB
19036 }
19037 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 19038 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
19039 fixp->fx_file = fragp->fr_file;
19040 fixp->fx_line = fragp->fr_line;
19041 fragp->fr_fix += fragp->fr_var;
19042}
19043
19044/* Return the size of a relaxable immediate operand instruction.
19045 SHIFT and SIZE specify the form of the allowable immediate. */
19046static int
19047relax_immediate (fragS *fragp, int size, int shift)
19048{
19049 offsetT offset;
19050 offsetT mask;
19051 offsetT low;
19052
19053 /* ??? Should be able to do better than this. */
19054 if (fragp->fr_symbol)
19055 return 4;
19056
19057 low = (1 << shift) - 1;
19058 mask = (1 << (shift + size)) - (1 << shift);
19059 offset = fragp->fr_offset;
19060 /* Force misaligned offsets to 32-bit variant. */
19061 if (offset & low)
5e77afaa 19062 return 4;
0110f2b8
PB
19063 if (offset & ~mask)
19064 return 4;
19065 return 2;
19066}
19067
5e77afaa
PB
19068/* Get the address of a symbol during relaxation. */
19069static addressT
5f4273c7 19070relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
19071{
19072 fragS *sym_frag;
19073 addressT addr;
19074 symbolS *sym;
19075
19076 sym = fragp->fr_symbol;
19077 sym_frag = symbol_get_frag (sym);
19078 know (S_GET_SEGMENT (sym) != absolute_section
19079 || sym_frag == &zero_address_frag);
19080 addr = S_GET_VALUE (sym) + fragp->fr_offset;
19081
19082 /* If frag has yet to be reached on this pass, assume it will
19083 move by STRETCH just as we did. If this is not so, it will
19084 be because some frag between grows, and that will force
19085 another pass. */
19086
19087 if (stretch != 0
19088 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
19089 {
19090 fragS *f;
19091
19092 /* Adjust stretch for any alignment frag. Note that if have
19093 been expanding the earlier code, the symbol may be
19094 defined in what appears to be an earlier frag. FIXME:
19095 This doesn't handle the fr_subtype field, which specifies
19096 a maximum number of bytes to skip when doing an
19097 alignment. */
19098 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
19099 {
19100 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
19101 {
19102 if (stretch < 0)
19103 stretch = - ((- stretch)
19104 & ~ ((1 << (int) f->fr_offset) - 1));
19105 else
19106 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
19107 if (stretch == 0)
19108 break;
19109 }
19110 }
19111 if (f != NULL)
19112 addr += stretch;
19113 }
5e77afaa
PB
19114
19115 return addr;
19116}
19117
0110f2b8
PB
19118/* Return the size of a relaxable adr pseudo-instruction or PC-relative
19119 load. */
19120static int
5e77afaa 19121relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
19122{
19123 addressT addr;
19124 offsetT val;
19125
19126 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
19127 if (fragp->fr_symbol == NULL
19128 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
19129 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19130 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
19131 return 4;
19132
5f4273c7 19133 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
19134 addr = fragp->fr_address + fragp->fr_fix;
19135 addr = (addr + 4) & ~3;
5e77afaa 19136 /* Force misaligned targets to 32-bit variant. */
0110f2b8 19137 if (val & 3)
5e77afaa 19138 return 4;
0110f2b8
PB
19139 val -= addr;
19140 if (val < 0 || val > 1020)
19141 return 4;
19142 return 2;
19143}
19144
19145/* Return the size of a relaxable add/sub immediate instruction. */
19146static int
19147relax_addsub (fragS *fragp, asection *sec)
19148{
19149 char *buf;
19150 int op;
19151
19152 buf = fragp->fr_literal + fragp->fr_fix;
19153 op = bfd_get_16(sec->owner, buf);
19154 if ((op & 0xf) == ((op >> 4) & 0xf))
19155 return relax_immediate (fragp, 8, 0);
19156 else
19157 return relax_immediate (fragp, 3, 0);
19158}
19159
19160
19161/* Return the size of a relaxable branch instruction. BITS is the
19162 size of the offset field in the narrow instruction. */
19163
19164static int
5e77afaa 19165relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
19166{
19167 addressT addr;
19168 offsetT val;
19169 offsetT limit;
19170
19171 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 19172 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
19173 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19174 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
19175 return 4;
19176
267bf995
RR
19177#ifdef OBJ_ELF
19178 if (S_IS_DEFINED (fragp->fr_symbol)
19179 && ARM_IS_FUNC (fragp->fr_symbol))
19180 return 4;
0d9b4b55
NC
19181
19182 /* PR 12532. Global symbols with default visibility might
19183 be preempted, so do not relax relocations to them. */
19184 if ((ELF_ST_VISIBILITY (S_GET_OTHER (fragp->fr_symbol)) == STV_DEFAULT)
19185 && (! S_IS_LOCAL (fragp->fr_symbol)))
19186 return 4;
267bf995
RR
19187#endif
19188
5f4273c7 19189 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
19190 addr = fragp->fr_address + fragp->fr_fix + 4;
19191 val -= addr;
19192
19193 /* Offset is a signed value *2 */
19194 limit = 1 << bits;
19195 if (val >= limit || val < -limit)
19196 return 4;
19197 return 2;
19198}
19199
19200
19201/* Relax a machine dependent frag. This returns the amount by which
19202 the current size of the frag should change. */
19203
19204int
5e77afaa 19205arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
19206{
19207 int oldsize;
19208 int newsize;
19209
19210 oldsize = fragp->fr_var;
19211 switch (fragp->fr_subtype)
19212 {
19213 case T_MNEM_ldr_pc2:
5f4273c7 19214 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
19215 break;
19216 case T_MNEM_ldr_pc:
19217 case T_MNEM_ldr_sp:
19218 case T_MNEM_str_sp:
5f4273c7 19219 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
19220 break;
19221 case T_MNEM_ldr:
19222 case T_MNEM_str:
5f4273c7 19223 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
19224 break;
19225 case T_MNEM_ldrh:
19226 case T_MNEM_strh:
5f4273c7 19227 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
19228 break;
19229 case T_MNEM_ldrb:
19230 case T_MNEM_strb:
5f4273c7 19231 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
19232 break;
19233 case T_MNEM_adr:
5f4273c7 19234 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
19235 break;
19236 case T_MNEM_mov:
19237 case T_MNEM_movs:
19238 case T_MNEM_cmp:
19239 case T_MNEM_cmn:
5f4273c7 19240 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
19241 break;
19242 case T_MNEM_b:
5f4273c7 19243 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
19244 break;
19245 case T_MNEM_bcond:
5f4273c7 19246 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
19247 break;
19248 case T_MNEM_add_sp:
19249 case T_MNEM_add_pc:
19250 newsize = relax_immediate (fragp, 8, 2);
19251 break;
19252 case T_MNEM_inc_sp:
19253 case T_MNEM_dec_sp:
19254 newsize = relax_immediate (fragp, 7, 2);
19255 break;
19256 case T_MNEM_addi:
19257 case T_MNEM_addis:
19258 case T_MNEM_subi:
19259 case T_MNEM_subis:
19260 newsize = relax_addsub (fragp, sec);
19261 break;
19262 default:
5f4273c7 19263 abort ();
0110f2b8 19264 }
5e77afaa
PB
19265
19266 fragp->fr_var = newsize;
19267 /* Freeze wide instructions that are at or before the same location as
19268 in the previous pass. This avoids infinite loops.
5f4273c7
NC
19269 Don't freeze them unconditionally because targets may be artificially
19270 misaligned by the expansion of preceding frags. */
5e77afaa 19271 if (stretch <= 0 && newsize > 2)
0110f2b8 19272 {
0110f2b8 19273 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 19274 frag_wane (fragp);
0110f2b8 19275 }
5e77afaa 19276
0110f2b8 19277 return newsize - oldsize;
c19d1205 19278}
b99bd4ef 19279
c19d1205 19280/* Round up a section size to the appropriate boundary. */
b99bd4ef 19281
c19d1205
ZW
19282valueT
19283md_section_align (segT segment ATTRIBUTE_UNUSED,
19284 valueT size)
19285{
f0927246
NC
19286#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
19287 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
19288 {
19289 /* For a.out, force the section size to be aligned. If we don't do
19290 this, BFD will align it for us, but it will not write out the
19291 final bytes of the section. This may be a bug in BFD, but it is
19292 easier to fix it here since that is how the other a.out targets
19293 work. */
19294 int align;
19295
19296 align = bfd_get_section_alignment (stdoutput, segment);
19297 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
19298 }
c19d1205 19299#endif
f0927246
NC
19300
19301 return size;
bfae80f2 19302}
b99bd4ef 19303
c19d1205
ZW
19304/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
19305 of an rs_align_code fragment. */
19306
19307void
19308arm_handle_align (fragS * fragP)
bfae80f2 19309{
e7495e45
NS
19310 static char const arm_noop[2][2][4] =
19311 {
19312 { /* ARMv1 */
19313 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
19314 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
19315 },
19316 { /* ARMv6k */
19317 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
19318 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
19319 },
19320 };
19321 static char const thumb_noop[2][2][2] =
19322 {
19323 { /* Thumb-1 */
19324 {0xc0, 0x46}, /* LE */
19325 {0x46, 0xc0}, /* BE */
19326 },
19327 { /* Thumb-2 */
19328 {0x00, 0xbf}, /* LE */
19329 {0xbf, 0x00} /* BE */
19330 }
19331 };
19332 static char const wide_thumb_noop[2][4] =
19333 { /* Wide Thumb-2 */
19334 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
19335 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
19336 };
c921be7d 19337
e7495e45 19338 unsigned bytes, fix, noop_size;
c19d1205
ZW
19339 char * p;
19340 const char * noop;
e7495e45 19341 const char *narrow_noop = NULL;
cd000bff
DJ
19342#ifdef OBJ_ELF
19343 enum mstate state;
19344#endif
bfae80f2 19345
c19d1205 19346 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
19347 return;
19348
c19d1205
ZW
19349 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
19350 p = fragP->fr_literal + fragP->fr_fix;
19351 fix = 0;
bfae80f2 19352
c19d1205
ZW
19353 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
19354 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 19355
cd000bff 19356 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 19357
cd000bff 19358 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 19359 {
e7495e45
NS
19360 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
19361 {
19362 narrow_noop = thumb_noop[1][target_big_endian];
19363 noop = wide_thumb_noop[target_big_endian];
19364 }
c19d1205 19365 else
e7495e45
NS
19366 noop = thumb_noop[0][target_big_endian];
19367 noop_size = 2;
cd000bff
DJ
19368#ifdef OBJ_ELF
19369 state = MAP_THUMB;
19370#endif
7ed4c4c5
NC
19371 }
19372 else
19373 {
e7495e45
NS
19374 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
19375 [target_big_endian];
19376 noop_size = 4;
cd000bff
DJ
19377#ifdef OBJ_ELF
19378 state = MAP_ARM;
19379#endif
7ed4c4c5 19380 }
c921be7d 19381
e7495e45 19382 fragP->fr_var = noop_size;
c921be7d 19383
c19d1205 19384 if (bytes & (noop_size - 1))
7ed4c4c5 19385 {
c19d1205 19386 fix = bytes & (noop_size - 1);
cd000bff
DJ
19387#ifdef OBJ_ELF
19388 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
19389#endif
c19d1205
ZW
19390 memset (p, 0, fix);
19391 p += fix;
19392 bytes -= fix;
a737bd4d 19393 }
a737bd4d 19394
e7495e45
NS
19395 if (narrow_noop)
19396 {
19397 if (bytes & noop_size)
19398 {
19399 /* Insert a narrow noop. */
19400 memcpy (p, narrow_noop, noop_size);
19401 p += noop_size;
19402 bytes -= noop_size;
19403 fix += noop_size;
19404 }
19405
19406 /* Use wide noops for the remainder */
19407 noop_size = 4;
19408 }
19409
c19d1205 19410 while (bytes >= noop_size)
a737bd4d 19411 {
c19d1205
ZW
19412 memcpy (p, noop, noop_size);
19413 p += noop_size;
19414 bytes -= noop_size;
19415 fix += noop_size;
a737bd4d
NC
19416 }
19417
c19d1205 19418 fragP->fr_fix += fix;
a737bd4d
NC
19419}
19420
c19d1205
ZW
19421/* Called from md_do_align. Used to create an alignment
19422 frag in a code section. */
19423
19424void
19425arm_frag_align_code (int n, int max)
bfae80f2 19426{
c19d1205 19427 char * p;
7ed4c4c5 19428
c19d1205 19429 /* We assume that there will never be a requirement
6ec8e702 19430 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 19431 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
19432 {
19433 char err_msg[128];
19434
19435 sprintf (err_msg,
19436 _("alignments greater than %d bytes not supported in .text sections."),
19437 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 19438 as_fatal ("%s", err_msg);
6ec8e702 19439 }
bfae80f2 19440
c19d1205
ZW
19441 p = frag_var (rs_align_code,
19442 MAX_MEM_FOR_RS_ALIGN_CODE,
19443 1,
19444 (relax_substateT) max,
19445 (symbolS *) NULL,
19446 (offsetT) n,
19447 (char *) NULL);
19448 *p = 0;
19449}
bfae80f2 19450
8dc2430f
NC
19451/* Perform target specific initialisation of a frag.
19452 Note - despite the name this initialisation is not done when the frag
19453 is created, but only when its type is assigned. A frag can be created
19454 and used a long time before its type is set, so beware of assuming that
19455 this initialisationis performed first. */
bfae80f2 19456
cd000bff
DJ
19457#ifndef OBJ_ELF
19458void
19459arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
19460{
19461 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 19462 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
19463}
19464
19465#else /* OBJ_ELF is defined. */
c19d1205 19466void
cd000bff 19467arm_init_frag (fragS * fragP, int max_chars)
c19d1205 19468{
8dc2430f
NC
19469 /* If the current ARM vs THUMB mode has not already
19470 been recorded into this frag then do so now. */
cd000bff
DJ
19471 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
19472 {
19473 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19474
19475 /* Record a mapping symbol for alignment frags. We will delete this
19476 later if the alignment ends up empty. */
19477 switch (fragP->fr_type)
19478 {
19479 case rs_align:
19480 case rs_align_test:
19481 case rs_fill:
19482 mapping_state_2 (MAP_DATA, max_chars);
19483 break;
19484 case rs_align_code:
19485 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
19486 break;
19487 default:
19488 break;
19489 }
19490 }
bfae80f2
RE
19491}
19492
c19d1205
ZW
19493/* When we change sections we need to issue a new mapping symbol. */
19494
19495void
19496arm_elf_change_section (void)
bfae80f2 19497{
c19d1205
ZW
19498 /* Link an unlinked unwind index table section to the .text section. */
19499 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
19500 && elf_linked_to_section (now_seg) == NULL)
19501 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
19502}
19503
c19d1205
ZW
19504int
19505arm_elf_section_type (const char * str, size_t len)
e45d0630 19506{
c19d1205
ZW
19507 if (len == 5 && strncmp (str, "exidx", 5) == 0)
19508 return SHT_ARM_EXIDX;
e45d0630 19509
c19d1205
ZW
19510 return -1;
19511}
19512\f
19513/* Code to deal with unwinding tables. */
e45d0630 19514
c19d1205 19515static void add_unwind_adjustsp (offsetT);
e45d0630 19516
5f4273c7 19517/* Generate any deferred unwind frame offset. */
e45d0630 19518
bfae80f2 19519static void
c19d1205 19520flush_pending_unwind (void)
bfae80f2 19521{
c19d1205 19522 offsetT offset;
bfae80f2 19523
c19d1205
ZW
19524 offset = unwind.pending_offset;
19525 unwind.pending_offset = 0;
19526 if (offset != 0)
19527 add_unwind_adjustsp (offset);
bfae80f2
RE
19528}
19529
c19d1205
ZW
19530/* Add an opcode to this list for this function. Two-byte opcodes should
19531 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
19532 order. */
19533
bfae80f2 19534static void
c19d1205 19535add_unwind_opcode (valueT op, int length)
bfae80f2 19536{
c19d1205
ZW
19537 /* Add any deferred stack adjustment. */
19538 if (unwind.pending_offset)
19539 flush_pending_unwind ();
bfae80f2 19540
c19d1205 19541 unwind.sp_restored = 0;
bfae80f2 19542
c19d1205 19543 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 19544 {
c19d1205
ZW
19545 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
19546 if (unwind.opcodes)
21d799b5
NC
19547 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
19548 unwind.opcode_alloc);
c19d1205 19549 else
21d799b5 19550 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 19551 }
c19d1205 19552 while (length > 0)
bfae80f2 19553 {
c19d1205
ZW
19554 length--;
19555 unwind.opcodes[unwind.opcode_count] = op & 0xff;
19556 op >>= 8;
19557 unwind.opcode_count++;
bfae80f2 19558 }
bfae80f2
RE
19559}
19560
c19d1205
ZW
19561/* Add unwind opcodes to adjust the stack pointer. */
19562
bfae80f2 19563static void
c19d1205 19564add_unwind_adjustsp (offsetT offset)
bfae80f2 19565{
c19d1205 19566 valueT op;
bfae80f2 19567
c19d1205 19568 if (offset > 0x200)
bfae80f2 19569 {
c19d1205
ZW
19570 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
19571 char bytes[5];
19572 int n;
19573 valueT o;
bfae80f2 19574
c19d1205
ZW
19575 /* Long form: 0xb2, uleb128. */
19576 /* This might not fit in a word so add the individual bytes,
19577 remembering the list is built in reverse order. */
19578 o = (valueT) ((offset - 0x204) >> 2);
19579 if (o == 0)
19580 add_unwind_opcode (0, 1);
bfae80f2 19581
c19d1205
ZW
19582 /* Calculate the uleb128 encoding of the offset. */
19583 n = 0;
19584 while (o)
19585 {
19586 bytes[n] = o & 0x7f;
19587 o >>= 7;
19588 if (o)
19589 bytes[n] |= 0x80;
19590 n++;
19591 }
19592 /* Add the insn. */
19593 for (; n; n--)
19594 add_unwind_opcode (bytes[n - 1], 1);
19595 add_unwind_opcode (0xb2, 1);
19596 }
19597 else if (offset > 0x100)
bfae80f2 19598 {
c19d1205
ZW
19599 /* Two short opcodes. */
19600 add_unwind_opcode (0x3f, 1);
19601 op = (offset - 0x104) >> 2;
19602 add_unwind_opcode (op, 1);
bfae80f2 19603 }
c19d1205
ZW
19604 else if (offset > 0)
19605 {
19606 /* Short opcode. */
19607 op = (offset - 4) >> 2;
19608 add_unwind_opcode (op, 1);
19609 }
19610 else if (offset < 0)
bfae80f2 19611 {
c19d1205
ZW
19612 offset = -offset;
19613 while (offset > 0x100)
bfae80f2 19614 {
c19d1205
ZW
19615 add_unwind_opcode (0x7f, 1);
19616 offset -= 0x100;
bfae80f2 19617 }
c19d1205
ZW
19618 op = ((offset - 4) >> 2) | 0x40;
19619 add_unwind_opcode (op, 1);
bfae80f2 19620 }
bfae80f2
RE
19621}
19622
c19d1205
ZW
19623/* Finish the list of unwind opcodes for this function. */
19624static void
19625finish_unwind_opcodes (void)
bfae80f2 19626{
c19d1205 19627 valueT op;
bfae80f2 19628
c19d1205 19629 if (unwind.fp_used)
bfae80f2 19630 {
708587a4 19631 /* Adjust sp as necessary. */
c19d1205
ZW
19632 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19633 flush_pending_unwind ();
bfae80f2 19634
c19d1205
ZW
19635 /* After restoring sp from the frame pointer. */
19636 op = 0x90 | unwind.fp_reg;
19637 add_unwind_opcode (op, 1);
19638 }
19639 else
19640 flush_pending_unwind ();
bfae80f2
RE
19641}
19642
bfae80f2 19643
c19d1205
ZW
19644/* Start an exception table entry. If idx is nonzero this is an index table
19645 entry. */
bfae80f2
RE
19646
19647static void
c19d1205 19648start_unwind_section (const segT text_seg, int idx)
bfae80f2 19649{
c19d1205
ZW
19650 const char * text_name;
19651 const char * prefix;
19652 const char * prefix_once;
19653 const char * group_name;
19654 size_t prefix_len;
19655 size_t text_len;
19656 char * sec_name;
19657 size_t sec_name_len;
19658 int type;
19659 int flags;
19660 int linkonce;
bfae80f2 19661
c19d1205 19662 if (idx)
bfae80f2 19663 {
c19d1205
ZW
19664 prefix = ELF_STRING_ARM_unwind;
19665 prefix_once = ELF_STRING_ARM_unwind_once;
19666 type = SHT_ARM_EXIDX;
bfae80f2 19667 }
c19d1205 19668 else
bfae80f2 19669 {
c19d1205
ZW
19670 prefix = ELF_STRING_ARM_unwind_info;
19671 prefix_once = ELF_STRING_ARM_unwind_info_once;
19672 type = SHT_PROGBITS;
bfae80f2
RE
19673 }
19674
c19d1205
ZW
19675 text_name = segment_name (text_seg);
19676 if (streq (text_name, ".text"))
19677 text_name = "";
19678
19679 if (strncmp (text_name, ".gnu.linkonce.t.",
19680 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 19681 {
c19d1205
ZW
19682 prefix = prefix_once;
19683 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
19684 }
19685
c19d1205
ZW
19686 prefix_len = strlen (prefix);
19687 text_len = strlen (text_name);
19688 sec_name_len = prefix_len + text_len;
21d799b5 19689 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
19690 memcpy (sec_name, prefix, prefix_len);
19691 memcpy (sec_name + prefix_len, text_name, text_len);
19692 sec_name[prefix_len + text_len] = '\0';
bfae80f2 19693
c19d1205
ZW
19694 flags = SHF_ALLOC;
19695 linkonce = 0;
19696 group_name = 0;
bfae80f2 19697
c19d1205
ZW
19698 /* Handle COMDAT group. */
19699 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 19700 {
c19d1205
ZW
19701 group_name = elf_group_name (text_seg);
19702 if (group_name == NULL)
19703 {
bd3ba5d1 19704 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
19705 segment_name (text_seg));
19706 ignore_rest_of_line ();
19707 return;
19708 }
19709 flags |= SHF_GROUP;
19710 linkonce = 1;
bfae80f2
RE
19711 }
19712
c19d1205 19713 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 19714
5f4273c7 19715 /* Set the section link for index tables. */
c19d1205
ZW
19716 if (idx)
19717 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
19718}
19719
bfae80f2 19720
c19d1205
ZW
19721/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19722 personality routine data. Returns zero, or the index table value for
19723 and inline entry. */
19724
19725static valueT
19726create_unwind_entry (int have_data)
bfae80f2 19727{
c19d1205
ZW
19728 int size;
19729 addressT where;
19730 char *ptr;
19731 /* The current word of data. */
19732 valueT data;
19733 /* The number of bytes left in this word. */
19734 int n;
bfae80f2 19735
c19d1205 19736 finish_unwind_opcodes ();
bfae80f2 19737
c19d1205
ZW
19738 /* Remember the current text section. */
19739 unwind.saved_seg = now_seg;
19740 unwind.saved_subseg = now_subseg;
bfae80f2 19741
c19d1205 19742 start_unwind_section (now_seg, 0);
bfae80f2 19743
c19d1205 19744 if (unwind.personality_routine == NULL)
bfae80f2 19745 {
c19d1205
ZW
19746 if (unwind.personality_index == -2)
19747 {
19748 if (have_data)
5f4273c7 19749 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
19750 return 1; /* EXIDX_CANTUNWIND. */
19751 }
bfae80f2 19752
c19d1205
ZW
19753 /* Use a default personality routine if none is specified. */
19754 if (unwind.personality_index == -1)
19755 {
19756 if (unwind.opcode_count > 3)
19757 unwind.personality_index = 1;
19758 else
19759 unwind.personality_index = 0;
19760 }
bfae80f2 19761
c19d1205
ZW
19762 /* Space for the personality routine entry. */
19763 if (unwind.personality_index == 0)
19764 {
19765 if (unwind.opcode_count > 3)
19766 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 19767
c19d1205
ZW
19768 if (!have_data)
19769 {
19770 /* All the data is inline in the index table. */
19771 data = 0x80;
19772 n = 3;
19773 while (unwind.opcode_count > 0)
19774 {
19775 unwind.opcode_count--;
19776 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19777 n--;
19778 }
bfae80f2 19779
c19d1205
ZW
19780 /* Pad with "finish" opcodes. */
19781 while (n--)
19782 data = (data << 8) | 0xb0;
bfae80f2 19783
c19d1205
ZW
19784 return data;
19785 }
19786 size = 0;
19787 }
19788 else
19789 /* We get two opcodes "free" in the first word. */
19790 size = unwind.opcode_count - 2;
19791 }
19792 else
19793 /* An extra byte is required for the opcode count. */
19794 size = unwind.opcode_count + 1;
bfae80f2 19795
c19d1205
ZW
19796 size = (size + 3) >> 2;
19797 if (size > 0xff)
19798 as_bad (_("too many unwind opcodes"));
bfae80f2 19799
c19d1205
ZW
19800 frag_align (2, 0, 0);
19801 record_alignment (now_seg, 2);
19802 unwind.table_entry = expr_build_dot ();
19803
19804 /* Allocate the table entry. */
19805 ptr = frag_more ((size << 2) + 4);
19806 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 19807
c19d1205 19808 switch (unwind.personality_index)
bfae80f2 19809 {
c19d1205
ZW
19810 case -1:
19811 /* ??? Should this be a PLT generating relocation? */
19812 /* Custom personality routine. */
19813 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19814 BFD_RELOC_ARM_PREL31);
bfae80f2 19815
c19d1205
ZW
19816 where += 4;
19817 ptr += 4;
bfae80f2 19818
c19d1205
ZW
19819 /* Set the first byte to the number of additional words. */
19820 data = size - 1;
19821 n = 3;
19822 break;
bfae80f2 19823
c19d1205
ZW
19824 /* ABI defined personality routines. */
19825 case 0:
19826 /* Three opcodes bytes are packed into the first word. */
19827 data = 0x80;
19828 n = 3;
19829 break;
bfae80f2 19830
c19d1205
ZW
19831 case 1:
19832 case 2:
19833 /* The size and first two opcode bytes go in the first word. */
19834 data = ((0x80 + unwind.personality_index) << 8) | size;
19835 n = 2;
19836 break;
bfae80f2 19837
c19d1205
ZW
19838 default:
19839 /* Should never happen. */
19840 abort ();
19841 }
bfae80f2 19842
c19d1205
ZW
19843 /* Pack the opcodes into words (MSB first), reversing the list at the same
19844 time. */
19845 while (unwind.opcode_count > 0)
19846 {
19847 if (n == 0)
19848 {
19849 md_number_to_chars (ptr, data, 4);
19850 ptr += 4;
19851 n = 4;
19852 data = 0;
19853 }
19854 unwind.opcode_count--;
19855 n--;
19856 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19857 }
19858
19859 /* Finish off the last word. */
19860 if (n < 4)
19861 {
19862 /* Pad with "finish" opcodes. */
19863 while (n--)
19864 data = (data << 8) | 0xb0;
19865
19866 md_number_to_chars (ptr, data, 4);
19867 }
19868
19869 if (!have_data)
19870 {
19871 /* Add an empty descriptor if there is no user-specified data. */
19872 ptr = frag_more (4);
19873 md_number_to_chars (ptr, 0, 4);
19874 }
19875
19876 return 0;
bfae80f2
RE
19877}
19878
f0927246
NC
19879
19880/* Initialize the DWARF-2 unwind information for this procedure. */
19881
19882void
19883tc_arm_frame_initial_instructions (void)
19884{
19885 cfi_add_CFA_def_cfa (REG_SP, 0);
19886}
19887#endif /* OBJ_ELF */
19888
c19d1205
ZW
19889/* Convert REGNAME to a DWARF-2 register number. */
19890
19891int
1df69f4f 19892tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 19893{
1df69f4f 19894 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
19895
19896 if (reg == FAIL)
19897 return -1;
19898
19899 return reg;
bfae80f2
RE
19900}
19901
f0927246 19902#ifdef TE_PE
c19d1205 19903void
f0927246 19904tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 19905{
91d6fa6a 19906 expressionS exp;
bfae80f2 19907
91d6fa6a
NC
19908 exp.X_op = O_secrel;
19909 exp.X_add_symbol = symbol;
19910 exp.X_add_number = 0;
19911 emit_expr (&exp, size);
f0927246
NC
19912}
19913#endif
bfae80f2 19914
c19d1205 19915/* MD interface: Symbol and relocation handling. */
bfae80f2 19916
2fc8bdac
ZW
19917/* Return the address within the segment that a PC-relative fixup is
19918 relative to. For ARM, PC-relative fixups applied to instructions
19919 are generally relative to the location of the fixup plus 8 bytes.
19920 Thumb branches are offset by 4, and Thumb loads relative to PC
19921 require special handling. */
bfae80f2 19922
c19d1205 19923long
2fc8bdac 19924md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 19925{
2fc8bdac
ZW
19926 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19927
19928 /* If this is pc-relative and we are going to emit a relocation
19929 then we just want to put out any pipeline compensation that the linker
53baae48
NC
19930 will need. Otherwise we want to use the calculated base.
19931 For WinCE we skip the bias for externals as well, since this
19932 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 19933 if (fixP->fx_pcrel
2fc8bdac 19934 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
19935 || (arm_force_relocation (fixP)
19936#ifdef TE_WINCE
19937 && !S_IS_EXTERNAL (fixP->fx_addsy)
19938#endif
19939 )))
2fc8bdac 19940 base = 0;
bfae80f2 19941
267bf995 19942
c19d1205 19943 switch (fixP->fx_r_type)
bfae80f2 19944 {
2fc8bdac
ZW
19945 /* PC relative addressing on the Thumb is slightly odd as the
19946 bottom two bits of the PC are forced to zero for the
19947 calculation. This happens *after* application of the
19948 pipeline offset. However, Thumb adrl already adjusts for
19949 this, so we need not do it again. */
c19d1205 19950 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 19951 return base & ~3;
c19d1205
ZW
19952
19953 case BFD_RELOC_ARM_THUMB_OFFSET:
19954 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 19955 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 19956 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 19957 return (base + 4) & ~3;
c19d1205 19958
2fc8bdac
ZW
19959 /* Thumb branches are simply offset by +4. */
19960 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19961 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19962 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19963 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 19964 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 19965 return base + 4;
bfae80f2 19966
267bf995 19967 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
19968 if (fixP->fx_addsy
19969 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 19970 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
19971 && ARM_IS_FUNC (fixP->fx_addsy)
19972 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19973 base = fixP->fx_where + fixP->fx_frag->fr_address;
19974 return base + 4;
19975
00adf2d4
JB
19976 /* BLX is like branches above, but forces the low two bits of PC to
19977 zero. */
486499d0
CL
19978 case BFD_RELOC_THUMB_PCREL_BLX:
19979 if (fixP->fx_addsy
19980 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 19981 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
19982 && THUMB_IS_FUNC (fixP->fx_addsy)
19983 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19984 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
19985 return (base + 4) & ~3;
19986
2fc8bdac
ZW
19987 /* ARM mode branches are offset by +8. However, the Windows CE
19988 loader expects the relocation not to take this into account. */
267bf995 19989 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
19990 if (fixP->fx_addsy
19991 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 19992 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
19993 && ARM_IS_FUNC (fixP->fx_addsy)
19994 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19995 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19996 return base + 8;
267bf995 19997
486499d0
CL
19998 case BFD_RELOC_ARM_PCREL_CALL:
19999 if (fixP->fx_addsy
20000 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20001 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20002 && THUMB_IS_FUNC (fixP->fx_addsy)
20003 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20004 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 20005 return base + 8;
267bf995 20006
2fc8bdac 20007 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 20008 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 20009 case BFD_RELOC_ARM_PLT32:
c19d1205 20010#ifdef TE_WINCE
5f4273c7 20011 /* When handling fixups immediately, because we have already
53baae48
NC
20012 discovered the value of a symbol, or the address of the frag involved
20013 we must account for the offset by +8, as the OS loader will never see the reloc.
20014 see fixup_segment() in write.c
20015 The S_IS_EXTERNAL test handles the case of global symbols.
20016 Those need the calculated base, not just the pipe compensation the linker will need. */
20017 if (fixP->fx_pcrel
20018 && fixP->fx_addsy != NULL
20019 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20020 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
20021 return base + 8;
2fc8bdac 20022 return base;
c19d1205 20023#else
2fc8bdac 20024 return base + 8;
c19d1205 20025#endif
2fc8bdac 20026
267bf995 20027
2fc8bdac
ZW
20028 /* ARM mode loads relative to PC are also offset by +8. Unlike
20029 branches, the Windows CE loader *does* expect the relocation
20030 to take this into account. */
20031 case BFD_RELOC_ARM_OFFSET_IMM:
20032 case BFD_RELOC_ARM_OFFSET_IMM8:
20033 case BFD_RELOC_ARM_HWLITERAL:
20034 case BFD_RELOC_ARM_LITERAL:
20035 case BFD_RELOC_ARM_CP_OFF_IMM:
20036 return base + 8;
20037
20038
20039 /* Other PC-relative relocations are un-offset. */
20040 default:
20041 return base;
20042 }
bfae80f2
RE
20043}
20044
c19d1205
ZW
20045/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
20046 Otherwise we have no need to default values of symbols. */
20047
20048symbolS *
20049md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 20050{
c19d1205
ZW
20051#ifdef OBJ_ELF
20052 if (name[0] == '_' && name[1] == 'G'
20053 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
20054 {
20055 if (!GOT_symbol)
20056 {
20057 if (symbol_find (name))
bd3ba5d1 20058 as_bad (_("GOT already in the symbol table"));
bfae80f2 20059
c19d1205
ZW
20060 GOT_symbol = symbol_new (name, undefined_section,
20061 (valueT) 0, & zero_address_frag);
20062 }
bfae80f2 20063
c19d1205 20064 return GOT_symbol;
bfae80f2 20065 }
c19d1205 20066#endif
bfae80f2 20067
c921be7d 20068 return NULL;
bfae80f2
RE
20069}
20070
55cf6793 20071/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
20072 computed as two separate immediate values, added together. We
20073 already know that this value cannot be computed by just one ARM
20074 instruction. */
20075
20076static unsigned int
20077validate_immediate_twopart (unsigned int val,
20078 unsigned int * highpart)
bfae80f2 20079{
c19d1205
ZW
20080 unsigned int a;
20081 unsigned int i;
bfae80f2 20082
c19d1205
ZW
20083 for (i = 0; i < 32; i += 2)
20084 if (((a = rotate_left (val, i)) & 0xff) != 0)
20085 {
20086 if (a & 0xff00)
20087 {
20088 if (a & ~ 0xffff)
20089 continue;
20090 * highpart = (a >> 8) | ((i + 24) << 7);
20091 }
20092 else if (a & 0xff0000)
20093 {
20094 if (a & 0xff000000)
20095 continue;
20096 * highpart = (a >> 16) | ((i + 16) << 7);
20097 }
20098 else
20099 {
9c2799c2 20100 gas_assert (a & 0xff000000);
c19d1205
ZW
20101 * highpart = (a >> 24) | ((i + 8) << 7);
20102 }
bfae80f2 20103
c19d1205
ZW
20104 return (a & 0xff) | (i << 7);
20105 }
bfae80f2 20106
c19d1205 20107 return FAIL;
bfae80f2
RE
20108}
20109
c19d1205
ZW
20110static int
20111validate_offset_imm (unsigned int val, int hwse)
20112{
20113 if ((hwse && val > 255) || val > 4095)
20114 return FAIL;
20115 return val;
20116}
bfae80f2 20117
55cf6793 20118/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
20119 negative immediate constant by altering the instruction. A bit of
20120 a hack really.
20121 MOV <-> MVN
20122 AND <-> BIC
20123 ADC <-> SBC
20124 by inverting the second operand, and
20125 ADD <-> SUB
20126 CMP <-> CMN
20127 by negating the second operand. */
bfae80f2 20128
c19d1205
ZW
20129static int
20130negate_data_op (unsigned long * instruction,
20131 unsigned long value)
bfae80f2 20132{
c19d1205
ZW
20133 int op, new_inst;
20134 unsigned long negated, inverted;
bfae80f2 20135
c19d1205
ZW
20136 negated = encode_arm_immediate (-value);
20137 inverted = encode_arm_immediate (~value);
bfae80f2 20138
c19d1205
ZW
20139 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
20140 switch (op)
bfae80f2 20141 {
c19d1205
ZW
20142 /* First negates. */
20143 case OPCODE_SUB: /* ADD <-> SUB */
20144 new_inst = OPCODE_ADD;
20145 value = negated;
20146 break;
bfae80f2 20147
c19d1205
ZW
20148 case OPCODE_ADD:
20149 new_inst = OPCODE_SUB;
20150 value = negated;
20151 break;
bfae80f2 20152
c19d1205
ZW
20153 case OPCODE_CMP: /* CMP <-> CMN */
20154 new_inst = OPCODE_CMN;
20155 value = negated;
20156 break;
bfae80f2 20157
c19d1205
ZW
20158 case OPCODE_CMN:
20159 new_inst = OPCODE_CMP;
20160 value = negated;
20161 break;
bfae80f2 20162
c19d1205
ZW
20163 /* Now Inverted ops. */
20164 case OPCODE_MOV: /* MOV <-> MVN */
20165 new_inst = OPCODE_MVN;
20166 value = inverted;
20167 break;
bfae80f2 20168
c19d1205
ZW
20169 case OPCODE_MVN:
20170 new_inst = OPCODE_MOV;
20171 value = inverted;
20172 break;
bfae80f2 20173
c19d1205
ZW
20174 case OPCODE_AND: /* AND <-> BIC */
20175 new_inst = OPCODE_BIC;
20176 value = inverted;
20177 break;
bfae80f2 20178
c19d1205
ZW
20179 case OPCODE_BIC:
20180 new_inst = OPCODE_AND;
20181 value = inverted;
20182 break;
bfae80f2 20183
c19d1205
ZW
20184 case OPCODE_ADC: /* ADC <-> SBC */
20185 new_inst = OPCODE_SBC;
20186 value = inverted;
20187 break;
bfae80f2 20188
c19d1205
ZW
20189 case OPCODE_SBC:
20190 new_inst = OPCODE_ADC;
20191 value = inverted;
20192 break;
bfae80f2 20193
c19d1205
ZW
20194 /* We cannot do anything. */
20195 default:
20196 return FAIL;
b99bd4ef
NC
20197 }
20198
c19d1205
ZW
20199 if (value == (unsigned) FAIL)
20200 return FAIL;
20201
20202 *instruction &= OPCODE_MASK;
20203 *instruction |= new_inst << DATA_OP_SHIFT;
20204 return value;
b99bd4ef
NC
20205}
20206
ef8d22e6
PB
20207/* Like negate_data_op, but for Thumb-2. */
20208
20209static unsigned int
16dd5e42 20210thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
20211{
20212 int op, new_inst;
20213 int rd;
16dd5e42 20214 unsigned int negated, inverted;
ef8d22e6
PB
20215
20216 negated = encode_thumb32_immediate (-value);
20217 inverted = encode_thumb32_immediate (~value);
20218
20219 rd = (*instruction >> 8) & 0xf;
20220 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
20221 switch (op)
20222 {
20223 /* ADD <-> SUB. Includes CMP <-> CMN. */
20224 case T2_OPCODE_SUB:
20225 new_inst = T2_OPCODE_ADD;
20226 value = negated;
20227 break;
20228
20229 case T2_OPCODE_ADD:
20230 new_inst = T2_OPCODE_SUB;
20231 value = negated;
20232 break;
20233
20234 /* ORR <-> ORN. Includes MOV <-> MVN. */
20235 case T2_OPCODE_ORR:
20236 new_inst = T2_OPCODE_ORN;
20237 value = inverted;
20238 break;
20239
20240 case T2_OPCODE_ORN:
20241 new_inst = T2_OPCODE_ORR;
20242 value = inverted;
20243 break;
20244
20245 /* AND <-> BIC. TST has no inverted equivalent. */
20246 case T2_OPCODE_AND:
20247 new_inst = T2_OPCODE_BIC;
20248 if (rd == 15)
20249 value = FAIL;
20250 else
20251 value = inverted;
20252 break;
20253
20254 case T2_OPCODE_BIC:
20255 new_inst = T2_OPCODE_AND;
20256 value = inverted;
20257 break;
20258
20259 /* ADC <-> SBC */
20260 case T2_OPCODE_ADC:
20261 new_inst = T2_OPCODE_SBC;
20262 value = inverted;
20263 break;
20264
20265 case T2_OPCODE_SBC:
20266 new_inst = T2_OPCODE_ADC;
20267 value = inverted;
20268 break;
20269
20270 /* We cannot do anything. */
20271 default:
20272 return FAIL;
20273 }
20274
16dd5e42 20275 if (value == (unsigned int)FAIL)
ef8d22e6
PB
20276 return FAIL;
20277
20278 *instruction &= T2_OPCODE_MASK;
20279 *instruction |= new_inst << T2_DATA_OP_SHIFT;
20280 return value;
20281}
20282
8f06b2d8
PB
20283/* Read a 32-bit thumb instruction from buf. */
20284static unsigned long
20285get_thumb32_insn (char * buf)
20286{
20287 unsigned long insn;
20288 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
20289 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20290
20291 return insn;
20292}
20293
a8bc6c78
PB
20294
20295/* We usually want to set the low bit on the address of thumb function
20296 symbols. In particular .word foo - . should have the low bit set.
20297 Generic code tries to fold the difference of two symbols to
20298 a constant. Prevent this and force a relocation when the first symbols
20299 is a thumb function. */
c921be7d
NC
20300
20301bfd_boolean
a8bc6c78
PB
20302arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
20303{
20304 if (op == O_subtract
20305 && l->X_op == O_symbol
20306 && r->X_op == O_symbol
20307 && THUMB_IS_FUNC (l->X_add_symbol))
20308 {
20309 l->X_op = O_subtract;
20310 l->X_op_symbol = r->X_add_symbol;
20311 l->X_add_number -= r->X_add_number;
c921be7d 20312 return TRUE;
a8bc6c78 20313 }
c921be7d 20314
a8bc6c78 20315 /* Process as normal. */
c921be7d 20316 return FALSE;
a8bc6c78
PB
20317}
20318
4a42ebbc
RR
20319/* Encode Thumb2 unconditional branches and calls. The encoding
20320 for the 2 are identical for the immediate values. */
20321
20322static void
20323encode_thumb2_b_bl_offset (char * buf, offsetT value)
20324{
20325#define T2I1I2MASK ((1 << 13) | (1 << 11))
20326 offsetT newval;
20327 offsetT newval2;
20328 addressT S, I1, I2, lo, hi;
20329
20330 S = (value >> 24) & 0x01;
20331 I1 = (value >> 23) & 0x01;
20332 I2 = (value >> 22) & 0x01;
20333 hi = (value >> 12) & 0x3ff;
20334 lo = (value >> 1) & 0x7ff;
20335 newval = md_chars_to_number (buf, THUMB_SIZE);
20336 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20337 newval |= (S << 10) | hi;
20338 newval2 &= ~T2I1I2MASK;
20339 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
20340 md_number_to_chars (buf, newval, THUMB_SIZE);
20341 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20342}
20343
c19d1205 20344void
55cf6793 20345md_apply_fix (fixS * fixP,
c19d1205
ZW
20346 valueT * valP,
20347 segT seg)
20348{
20349 offsetT value = * valP;
20350 offsetT newval;
20351 unsigned int newimm;
20352 unsigned long temp;
20353 int sign;
20354 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 20355
9c2799c2 20356 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 20357
c19d1205 20358 /* Note whether this will delete the relocation. */
4962c51a 20359
c19d1205
ZW
20360 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
20361 fixP->fx_done = 1;
b99bd4ef 20362
adbaf948 20363 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 20364 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
20365 for emit_reloc. */
20366 value &= 0xffffffff;
20367 value ^= 0x80000000;
5f4273c7 20368 value -= 0x80000000;
adbaf948
ZW
20369
20370 *valP = value;
c19d1205 20371 fixP->fx_addnumber = value;
b99bd4ef 20372
adbaf948
ZW
20373 /* Same treatment for fixP->fx_offset. */
20374 fixP->fx_offset &= 0xffffffff;
20375 fixP->fx_offset ^= 0x80000000;
20376 fixP->fx_offset -= 0x80000000;
20377
c19d1205 20378 switch (fixP->fx_r_type)
b99bd4ef 20379 {
c19d1205
ZW
20380 case BFD_RELOC_NONE:
20381 /* This will need to go in the object file. */
20382 fixP->fx_done = 0;
20383 break;
b99bd4ef 20384
c19d1205
ZW
20385 case BFD_RELOC_ARM_IMMEDIATE:
20386 /* We claim that this fixup has been processed here,
20387 even if in fact we generate an error because we do
20388 not have a reloc for it, so tc_gen_reloc will reject it. */
20389 fixP->fx_done = 1;
b99bd4ef 20390
77db8e2e 20391 if (fixP->fx_addsy)
b99bd4ef 20392 {
77db8e2e 20393 const char *msg = 0;
b99bd4ef 20394
77db8e2e
NC
20395 if (! S_IS_DEFINED (fixP->fx_addsy))
20396 msg = _("undefined symbol %s used as an immediate value");
20397 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20398 msg = _("symbol %s is in a different section");
20399 else if (S_IS_WEAK (fixP->fx_addsy))
20400 msg = _("symbol %s is weak and may be overridden later");
20401
20402 if (msg)
20403 {
20404 as_bad_where (fixP->fx_file, fixP->fx_line,
20405 msg, S_GET_NAME (fixP->fx_addsy));
20406 break;
20407 }
42e5fcbf
AS
20408 }
20409
c19d1205
ZW
20410 newimm = encode_arm_immediate (value);
20411 temp = md_chars_to_number (buf, INSN_SIZE);
20412
20413 /* If the instruction will fail, see if we can fix things up by
20414 changing the opcode. */
20415 if (newimm == (unsigned int) FAIL
20416 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 20417 {
c19d1205
ZW
20418 as_bad_where (fixP->fx_file, fixP->fx_line,
20419 _("invalid constant (%lx) after fixup"),
20420 (unsigned long) value);
20421 break;
b99bd4ef 20422 }
b99bd4ef 20423
c19d1205
ZW
20424 newimm |= (temp & 0xfffff000);
20425 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20426 break;
b99bd4ef 20427
c19d1205
ZW
20428 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20429 {
20430 unsigned int highpart = 0;
20431 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 20432
77db8e2e 20433 if (fixP->fx_addsy)
42e5fcbf 20434 {
77db8e2e 20435 const char *msg = 0;
42e5fcbf 20436
77db8e2e
NC
20437 if (! S_IS_DEFINED (fixP->fx_addsy))
20438 msg = _("undefined symbol %s used as an immediate value");
20439 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20440 msg = _("symbol %s is in a different section");
20441 else if (S_IS_WEAK (fixP->fx_addsy))
20442 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 20443
77db8e2e
NC
20444 if (msg)
20445 {
20446 as_bad_where (fixP->fx_file, fixP->fx_line,
20447 msg, S_GET_NAME (fixP->fx_addsy));
20448 break;
20449 }
20450 }
20451
c19d1205
ZW
20452 newimm = encode_arm_immediate (value);
20453 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 20454
c19d1205
ZW
20455 /* If the instruction will fail, see if we can fix things up by
20456 changing the opcode. */
20457 if (newimm == (unsigned int) FAIL
20458 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
20459 {
20460 /* No ? OK - try using two ADD instructions to generate
20461 the value. */
20462 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 20463
c19d1205
ZW
20464 /* Yes - then make sure that the second instruction is
20465 also an add. */
20466 if (newimm != (unsigned int) FAIL)
20467 newinsn = temp;
20468 /* Still No ? Try using a negated value. */
20469 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
20470 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
20471 /* Otherwise - give up. */
20472 else
20473 {
20474 as_bad_where (fixP->fx_file, fixP->fx_line,
20475 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
20476 (long) value);
20477 break;
20478 }
b99bd4ef 20479
c19d1205
ZW
20480 /* Replace the first operand in the 2nd instruction (which
20481 is the PC) with the destination register. We have
20482 already added in the PC in the first instruction and we
20483 do not want to do it again. */
20484 newinsn &= ~ 0xf0000;
20485 newinsn |= ((newinsn & 0x0f000) << 4);
20486 }
b99bd4ef 20487
c19d1205
ZW
20488 newimm |= (temp & 0xfffff000);
20489 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 20490
c19d1205
ZW
20491 highpart |= (newinsn & 0xfffff000);
20492 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
20493 }
20494 break;
b99bd4ef 20495
c19d1205 20496 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
20497 if (!fixP->fx_done && seg->use_rela_p)
20498 value = 0;
20499
c19d1205 20500 case BFD_RELOC_ARM_LITERAL:
26d97720 20501 sign = value > 0;
b99bd4ef 20502
c19d1205
ZW
20503 if (value < 0)
20504 value = - value;
b99bd4ef 20505
c19d1205 20506 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 20507 {
c19d1205
ZW
20508 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
20509 as_bad_where (fixP->fx_file, fixP->fx_line,
20510 _("invalid literal constant: pool needs to be closer"));
20511 else
20512 as_bad_where (fixP->fx_file, fixP->fx_line,
20513 _("bad immediate value for offset (%ld)"),
20514 (long) value);
20515 break;
f03698e6
RE
20516 }
20517
c19d1205 20518 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
20519 if (value == 0)
20520 newval &= 0xfffff000;
20521 else
20522 {
20523 newval &= 0xff7ff000;
20524 newval |= value | (sign ? INDEX_UP : 0);
20525 }
c19d1205
ZW
20526 md_number_to_chars (buf, newval, INSN_SIZE);
20527 break;
b99bd4ef 20528
c19d1205
ZW
20529 case BFD_RELOC_ARM_OFFSET_IMM8:
20530 case BFD_RELOC_ARM_HWLITERAL:
26d97720 20531 sign = value > 0;
b99bd4ef 20532
c19d1205
ZW
20533 if (value < 0)
20534 value = - value;
b99bd4ef 20535
c19d1205 20536 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 20537 {
c19d1205
ZW
20538 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
20539 as_bad_where (fixP->fx_file, fixP->fx_line,
20540 _("invalid literal constant: pool needs to be closer"));
20541 else
f9d4405b 20542 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
20543 (long) value);
20544 break;
b99bd4ef
NC
20545 }
20546
c19d1205 20547 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
20548 if (value == 0)
20549 newval &= 0xfffff0f0;
20550 else
20551 {
20552 newval &= 0xff7ff0f0;
20553 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
20554 }
c19d1205
ZW
20555 md_number_to_chars (buf, newval, INSN_SIZE);
20556 break;
b99bd4ef 20557
c19d1205
ZW
20558 case BFD_RELOC_ARM_T32_OFFSET_U8:
20559 if (value < 0 || value > 1020 || value % 4 != 0)
20560 as_bad_where (fixP->fx_file, fixP->fx_line,
20561 _("bad immediate value for offset (%ld)"), (long) value);
20562 value /= 4;
b99bd4ef 20563
c19d1205 20564 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
20565 newval |= value;
20566 md_number_to_chars (buf+2, newval, THUMB_SIZE);
20567 break;
b99bd4ef 20568
c19d1205
ZW
20569 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20570 /* This is a complicated relocation used for all varieties of Thumb32
20571 load/store instruction with immediate offset:
20572
20573 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
20574 *4, optional writeback(W)
20575 (doubleword load/store)
20576
20577 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
20578 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
20579 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
20580 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
20581 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
20582
20583 Uppercase letters indicate bits that are already encoded at
20584 this point. Lowercase letters are our problem. For the
20585 second block of instructions, the secondary opcode nybble
20586 (bits 8..11) is present, and bit 23 is zero, even if this is
20587 a PC-relative operation. */
20588 newval = md_chars_to_number (buf, THUMB_SIZE);
20589 newval <<= 16;
20590 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 20591
c19d1205 20592 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 20593 {
c19d1205
ZW
20594 /* Doubleword load/store: 8-bit offset, scaled by 4. */
20595 if (value >= 0)
20596 newval |= (1 << 23);
20597 else
20598 value = -value;
20599 if (value % 4 != 0)
20600 {
20601 as_bad_where (fixP->fx_file, fixP->fx_line,
20602 _("offset not a multiple of 4"));
20603 break;
20604 }
20605 value /= 4;
216d22bc 20606 if (value > 0xff)
c19d1205
ZW
20607 {
20608 as_bad_where (fixP->fx_file, fixP->fx_line,
20609 _("offset out of range"));
20610 break;
20611 }
20612 newval &= ~0xff;
b99bd4ef 20613 }
c19d1205 20614 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 20615 {
c19d1205
ZW
20616 /* PC-relative, 12-bit offset. */
20617 if (value >= 0)
20618 newval |= (1 << 23);
20619 else
20620 value = -value;
216d22bc 20621 if (value > 0xfff)
c19d1205
ZW
20622 {
20623 as_bad_where (fixP->fx_file, fixP->fx_line,
20624 _("offset out of range"));
20625 break;
20626 }
20627 newval &= ~0xfff;
b99bd4ef 20628 }
c19d1205 20629 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 20630 {
c19d1205
ZW
20631 /* Writeback: 8-bit, +/- offset. */
20632 if (value >= 0)
20633 newval |= (1 << 9);
20634 else
20635 value = -value;
216d22bc 20636 if (value > 0xff)
c19d1205
ZW
20637 {
20638 as_bad_where (fixP->fx_file, fixP->fx_line,
20639 _("offset out of range"));
20640 break;
20641 }
20642 newval &= ~0xff;
b99bd4ef 20643 }
c19d1205 20644 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 20645 {
c19d1205 20646 /* T-instruction: positive 8-bit offset. */
216d22bc 20647 if (value < 0 || value > 0xff)
b99bd4ef 20648 {
c19d1205
ZW
20649 as_bad_where (fixP->fx_file, fixP->fx_line,
20650 _("offset out of range"));
20651 break;
b99bd4ef 20652 }
c19d1205
ZW
20653 newval &= ~0xff;
20654 newval |= value;
b99bd4ef
NC
20655 }
20656 else
b99bd4ef 20657 {
c19d1205
ZW
20658 /* Positive 12-bit or negative 8-bit offset. */
20659 int limit;
20660 if (value >= 0)
b99bd4ef 20661 {
c19d1205
ZW
20662 newval |= (1 << 23);
20663 limit = 0xfff;
20664 }
20665 else
20666 {
20667 value = -value;
20668 limit = 0xff;
20669 }
20670 if (value > limit)
20671 {
20672 as_bad_where (fixP->fx_file, fixP->fx_line,
20673 _("offset out of range"));
20674 break;
b99bd4ef 20675 }
c19d1205 20676 newval &= ~limit;
b99bd4ef 20677 }
b99bd4ef 20678
c19d1205
ZW
20679 newval |= value;
20680 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20681 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20682 break;
404ff6b5 20683
c19d1205
ZW
20684 case BFD_RELOC_ARM_SHIFT_IMM:
20685 newval = md_chars_to_number (buf, INSN_SIZE);
20686 if (((unsigned long) value) > 32
20687 || (value == 32
20688 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20689 {
20690 as_bad_where (fixP->fx_file, fixP->fx_line,
20691 _("shift expression is too large"));
20692 break;
20693 }
404ff6b5 20694
c19d1205
ZW
20695 if (value == 0)
20696 /* Shifts of zero must be done as lsl. */
20697 newval &= ~0x60;
20698 else if (value == 32)
20699 value = 0;
20700 newval &= 0xfffff07f;
20701 newval |= (value & 0x1f) << 7;
20702 md_number_to_chars (buf, newval, INSN_SIZE);
20703 break;
404ff6b5 20704
c19d1205 20705 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 20706 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 20707 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 20708 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
20709 /* We claim that this fixup has been processed here,
20710 even if in fact we generate an error because we do
20711 not have a reloc for it, so tc_gen_reloc will reject it. */
20712 fixP->fx_done = 1;
404ff6b5 20713
c19d1205
ZW
20714 if (fixP->fx_addsy
20715 && ! S_IS_DEFINED (fixP->fx_addsy))
20716 {
20717 as_bad_where (fixP->fx_file, fixP->fx_line,
20718 _("undefined symbol %s used as an immediate value"),
20719 S_GET_NAME (fixP->fx_addsy));
20720 break;
20721 }
404ff6b5 20722
c19d1205
ZW
20723 newval = md_chars_to_number (buf, THUMB_SIZE);
20724 newval <<= 16;
20725 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 20726
16805f35
PB
20727 newimm = FAIL;
20728 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20729 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
20730 {
20731 newimm = encode_thumb32_immediate (value);
20732 if (newimm == (unsigned int) FAIL)
20733 newimm = thumb32_negate_data_op (&newval, value);
20734 }
16805f35
PB
20735 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20736 && newimm == (unsigned int) FAIL)
92e90b6e 20737 {
16805f35
PB
20738 /* Turn add/sum into addw/subw. */
20739 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20740 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
20741 /* No flat 12-bit imm encoding for addsw/subsw. */
20742 if ((newval & 0x00100000) == 0)
e9f89963 20743 {
40f246e3
NC
20744 /* 12 bit immediate for addw/subw. */
20745 if (value < 0)
20746 {
20747 value = -value;
20748 newval ^= 0x00a00000;
20749 }
20750 if (value > 0xfff)
20751 newimm = (unsigned int) FAIL;
20752 else
20753 newimm = value;
e9f89963 20754 }
92e90b6e 20755 }
cc8a6dd0 20756
c19d1205 20757 if (newimm == (unsigned int)FAIL)
3631a3c8 20758 {
c19d1205
ZW
20759 as_bad_where (fixP->fx_file, fixP->fx_line,
20760 _("invalid constant (%lx) after fixup"),
20761 (unsigned long) value);
20762 break;
3631a3c8
NC
20763 }
20764
c19d1205
ZW
20765 newval |= (newimm & 0x800) << 15;
20766 newval |= (newimm & 0x700) << 4;
20767 newval |= (newimm & 0x0ff);
cc8a6dd0 20768
c19d1205
ZW
20769 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20770 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20771 break;
a737bd4d 20772
3eb17e6b 20773 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
20774 if (((unsigned long) value) > 0xffff)
20775 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 20776 _("invalid smc expression"));
2fc8bdac 20777 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20778 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20779 md_number_to_chars (buf, newval, INSN_SIZE);
20780 break;
a737bd4d 20781
90ec0d68
MGD
20782 case BFD_RELOC_ARM_HVC:
20783 if (((unsigned long) value) > 0xffff)
20784 as_bad_where (fixP->fx_file, fixP->fx_line,
20785 _("invalid hvc expression"));
20786 newval = md_chars_to_number (buf, INSN_SIZE);
20787 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20788 md_number_to_chars (buf, newval, INSN_SIZE);
20789 break;
20790
c19d1205 20791 case BFD_RELOC_ARM_SWI:
adbaf948 20792 if (fixP->tc_fix_data != 0)
c19d1205
ZW
20793 {
20794 if (((unsigned long) value) > 0xff)
20795 as_bad_where (fixP->fx_file, fixP->fx_line,
20796 _("invalid swi expression"));
2fc8bdac 20797 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
20798 newval |= value;
20799 md_number_to_chars (buf, newval, THUMB_SIZE);
20800 }
20801 else
20802 {
20803 if (((unsigned long) value) > 0x00ffffff)
20804 as_bad_where (fixP->fx_file, fixP->fx_line,
20805 _("invalid swi expression"));
2fc8bdac 20806 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20807 newval |= value;
20808 md_number_to_chars (buf, newval, INSN_SIZE);
20809 }
20810 break;
a737bd4d 20811
c19d1205
ZW
20812 case BFD_RELOC_ARM_MULTI:
20813 if (((unsigned long) value) > 0xffff)
20814 as_bad_where (fixP->fx_file, fixP->fx_line,
20815 _("invalid expression in load/store multiple"));
20816 newval = value | md_chars_to_number (buf, INSN_SIZE);
20817 md_number_to_chars (buf, newval, INSN_SIZE);
20818 break;
a737bd4d 20819
c19d1205 20820#ifdef OBJ_ELF
39b41c9c 20821 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
20822
20823 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20824 && fixP->fx_addsy
34e77a92 20825 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20826 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20827 && THUMB_IS_FUNC (fixP->fx_addsy))
20828 /* Flip the bl to blx. This is a simple flip
20829 bit here because we generate PCREL_CALL for
20830 unconditional bls. */
20831 {
20832 newval = md_chars_to_number (buf, INSN_SIZE);
20833 newval = newval | 0x10000000;
20834 md_number_to_chars (buf, newval, INSN_SIZE);
20835 temp = 1;
20836 fixP->fx_done = 1;
20837 }
39b41c9c
PB
20838 else
20839 temp = 3;
20840 goto arm_branch_common;
20841
20842 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
20843 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20844 && fixP->fx_addsy
34e77a92 20845 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20846 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20847 && THUMB_IS_FUNC (fixP->fx_addsy))
20848 {
20849 /* This would map to a bl<cond>, b<cond>,
20850 b<always> to a Thumb function. We
20851 need to force a relocation for this particular
20852 case. */
20853 newval = md_chars_to_number (buf, INSN_SIZE);
20854 fixP->fx_done = 0;
20855 }
20856
2fc8bdac 20857 case BFD_RELOC_ARM_PLT32:
c19d1205 20858#endif
39b41c9c
PB
20859 case BFD_RELOC_ARM_PCREL_BRANCH:
20860 temp = 3;
20861 goto arm_branch_common;
a737bd4d 20862
39b41c9c 20863 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 20864
39b41c9c 20865 temp = 1;
267bf995
RR
20866 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20867 && fixP->fx_addsy
34e77a92 20868 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20869 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20870 && ARM_IS_FUNC (fixP->fx_addsy))
20871 {
20872 /* Flip the blx to a bl and warn. */
20873 const char *name = S_GET_NAME (fixP->fx_addsy);
20874 newval = 0xeb000000;
20875 as_warn_where (fixP->fx_file, fixP->fx_line,
20876 _("blx to '%s' an ARM ISA state function changed to bl"),
20877 name);
20878 md_number_to_chars (buf, newval, INSN_SIZE);
20879 temp = 3;
20880 fixP->fx_done = 1;
20881 }
20882
20883#ifdef OBJ_ELF
20884 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20885 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20886#endif
20887
39b41c9c 20888 arm_branch_common:
c19d1205 20889 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
20890 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20891 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20892 also be be clear. */
20893 if (value & temp)
c19d1205 20894 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
20895 _("misaligned branch destination"));
20896 if ((value & (offsetT)0xfe000000) != (offsetT)0
20897 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20898 as_bad_where (fixP->fx_file, fixP->fx_line,
20899 _("branch out of range"));
a737bd4d 20900
2fc8bdac 20901 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20902 {
2fc8bdac
ZW
20903 newval = md_chars_to_number (buf, INSN_SIZE);
20904 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
20905 /* Set the H bit on BLX instructions. */
20906 if (temp == 1)
20907 {
20908 if (value & 2)
20909 newval |= 0x01000000;
20910 else
20911 newval &= ~0x01000000;
20912 }
2fc8bdac 20913 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 20914 }
c19d1205 20915 break;
a737bd4d 20916
25fe350b
MS
20917 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20918 /* CBZ can only branch forward. */
a737bd4d 20919
738755b0
MS
20920 /* Attempts to use CBZ to branch to the next instruction
20921 (which, strictly speaking, are prohibited) will be turned into
20922 no-ops.
20923
20924 FIXME: It may be better to remove the instruction completely and
20925 perform relaxation. */
20926 if (value == -2)
2fc8bdac
ZW
20927 {
20928 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 20929 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
20930 md_number_to_chars (buf, newval, THUMB_SIZE);
20931 }
738755b0
MS
20932 else
20933 {
20934 if (value & ~0x7e)
20935 as_bad_where (fixP->fx_file, fixP->fx_line,
20936 _("branch out of range"));
20937
20938 if (fixP->fx_done || !seg->use_rela_p)
20939 {
20940 newval = md_chars_to_number (buf, THUMB_SIZE);
20941 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20942 md_number_to_chars (buf, newval, THUMB_SIZE);
20943 }
20944 }
c19d1205 20945 break;
a737bd4d 20946
c19d1205 20947 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
20948 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20949 as_bad_where (fixP->fx_file, fixP->fx_line,
20950 _("branch out of range"));
a737bd4d 20951
2fc8bdac
ZW
20952 if (fixP->fx_done || !seg->use_rela_p)
20953 {
20954 newval = md_chars_to_number (buf, THUMB_SIZE);
20955 newval |= (value & 0x1ff) >> 1;
20956 md_number_to_chars (buf, newval, THUMB_SIZE);
20957 }
c19d1205 20958 break;
a737bd4d 20959
c19d1205 20960 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
20961 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20962 as_bad_where (fixP->fx_file, fixP->fx_line,
20963 _("branch out of range"));
a737bd4d 20964
2fc8bdac
ZW
20965 if (fixP->fx_done || !seg->use_rela_p)
20966 {
20967 newval = md_chars_to_number (buf, THUMB_SIZE);
20968 newval |= (value & 0xfff) >> 1;
20969 md_number_to_chars (buf, newval, THUMB_SIZE);
20970 }
c19d1205 20971 break;
a737bd4d 20972
c19d1205 20973 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
20974 if (fixP->fx_addsy
20975 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20976 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20977 && ARM_IS_FUNC (fixP->fx_addsy)
20978 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20979 {
20980 /* Force a relocation for a branch 20 bits wide. */
20981 fixP->fx_done = 0;
20982 }
2fc8bdac
ZW
20983 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20984 as_bad_where (fixP->fx_file, fixP->fx_line,
20985 _("conditional branch out of range"));
404ff6b5 20986
2fc8bdac
ZW
20987 if (fixP->fx_done || !seg->use_rela_p)
20988 {
20989 offsetT newval2;
20990 addressT S, J1, J2, lo, hi;
404ff6b5 20991
2fc8bdac
ZW
20992 S = (value & 0x00100000) >> 20;
20993 J2 = (value & 0x00080000) >> 19;
20994 J1 = (value & 0x00040000) >> 18;
20995 hi = (value & 0x0003f000) >> 12;
20996 lo = (value & 0x00000ffe) >> 1;
6c43fab6 20997
2fc8bdac
ZW
20998 newval = md_chars_to_number (buf, THUMB_SIZE);
20999 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21000 newval |= (S << 10) | hi;
21001 newval2 |= (J1 << 13) | (J2 << 11) | lo;
21002 md_number_to_chars (buf, newval, THUMB_SIZE);
21003 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
21004 }
c19d1205 21005 break;
6c43fab6 21006
c19d1205 21007 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
21008
21009 /* If there is a blx from a thumb state function to
21010 another thumb function flip this to a bl and warn
21011 about it. */
21012
21013 if (fixP->fx_addsy
34e77a92 21014 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21015 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21016 && THUMB_IS_FUNC (fixP->fx_addsy))
21017 {
21018 const char *name = S_GET_NAME (fixP->fx_addsy);
21019 as_warn_where (fixP->fx_file, fixP->fx_line,
21020 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
21021 name);
21022 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21023 newval = newval | 0x1000;
21024 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
21025 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
21026 fixP->fx_done = 1;
21027 }
21028
21029
21030 goto thumb_bl_common;
21031
c19d1205 21032 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
21033
21034 /* A bl from Thumb state ISA to an internal ARM state function
21035 is converted to a blx. */
21036 if (fixP->fx_addsy
21037 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21038 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21039 && ARM_IS_FUNC (fixP->fx_addsy)
21040 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21041 {
21042 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21043 newval = newval & ~0x1000;
21044 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
21045 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
21046 fixP->fx_done = 1;
21047 }
21048
21049 thumb_bl_common:
21050
21051#ifdef OBJ_ELF
21052 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
21053 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
21054 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
21055#endif
21056
2fc8bdac
ZW
21057 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
21058 /* For a BLX instruction, make sure that the relocation is rounded up
21059 to a word boundary. This follows the semantics of the instruction
21060 which specifies that bit 1 of the target address will come from bit
21061 1 of the base address. */
21062 value = (value + 1) & ~ 1;
404ff6b5 21063
2fc8bdac 21064
4a42ebbc
RR
21065 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
21066 {
21067 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
21068 {
21069 as_bad_where (fixP->fx_file, fixP->fx_line,
21070 _("branch out of range"));
21071 }
21072 else if ((value & ~0x1ffffff)
21073 && ((value & ~0x1ffffff) != ~0x1ffffff))
21074 {
21075 as_bad_where (fixP->fx_file, fixP->fx_line,
21076 _("Thumb2 branch out of range"));
21077 }
c19d1205 21078 }
4a42ebbc
RR
21079
21080 if (fixP->fx_done || !seg->use_rela_p)
21081 encode_thumb2_b_bl_offset (buf, value);
21082
c19d1205 21083 break;
404ff6b5 21084
c19d1205 21085 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
21086 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
21087 as_bad_where (fixP->fx_file, fixP->fx_line,
21088 _("branch out of range"));
6c43fab6 21089
2fc8bdac 21090 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 21091 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 21092
2fc8bdac 21093 break;
a737bd4d 21094
2fc8bdac
ZW
21095 case BFD_RELOC_8:
21096 if (fixP->fx_done || !seg->use_rela_p)
21097 md_number_to_chars (buf, value, 1);
c19d1205 21098 break;
a737bd4d 21099
c19d1205 21100 case BFD_RELOC_16:
2fc8bdac 21101 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 21102 md_number_to_chars (buf, value, 2);
c19d1205 21103 break;
a737bd4d 21104
c19d1205 21105#ifdef OBJ_ELF
0855e32b
NS
21106 case BFD_RELOC_ARM_TLS_CALL:
21107 case BFD_RELOC_ARM_THM_TLS_CALL:
21108 case BFD_RELOC_ARM_TLS_DESCSEQ:
21109 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
21110 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21111 break;
21112
21113 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
21114 case BFD_RELOC_ARM_TLS_GD32:
21115 case BFD_RELOC_ARM_TLS_LE32:
21116 case BFD_RELOC_ARM_TLS_IE32:
21117 case BFD_RELOC_ARM_TLS_LDM32:
21118 case BFD_RELOC_ARM_TLS_LDO32:
21119 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21120 /* fall through */
6c43fab6 21121
c19d1205
ZW
21122 case BFD_RELOC_ARM_GOT32:
21123 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
21124 if (fixP->fx_done || !seg->use_rela_p)
21125 md_number_to_chars (buf, 0, 4);
c19d1205 21126 break;
b43420e6
NC
21127
21128 case BFD_RELOC_ARM_GOT_PREL:
21129 if (fixP->fx_done || !seg->use_rela_p)
21130 md_number_to_chars (buf, value, 4);
21131 break;
21132
9a6f4e97
NS
21133 case BFD_RELOC_ARM_TARGET2:
21134 /* TARGET2 is not partial-inplace, so we need to write the
21135 addend here for REL targets, because it won't be written out
21136 during reloc processing later. */
21137 if (fixP->fx_done || !seg->use_rela_p)
21138 md_number_to_chars (buf, fixP->fx_offset, 4);
21139 break;
c19d1205 21140#endif
6c43fab6 21141
c19d1205
ZW
21142 case BFD_RELOC_RVA:
21143 case BFD_RELOC_32:
21144 case BFD_RELOC_ARM_TARGET1:
21145 case BFD_RELOC_ARM_ROSEGREL32:
21146 case BFD_RELOC_ARM_SBREL32:
21147 case BFD_RELOC_32_PCREL:
f0927246
NC
21148#ifdef TE_PE
21149 case BFD_RELOC_32_SECREL:
21150#endif
2fc8bdac 21151 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
21152#ifdef TE_WINCE
21153 /* For WinCE we only do this for pcrel fixups. */
21154 if (fixP->fx_done || fixP->fx_pcrel)
21155#endif
21156 md_number_to_chars (buf, value, 4);
c19d1205 21157 break;
6c43fab6 21158
c19d1205
ZW
21159#ifdef OBJ_ELF
21160 case BFD_RELOC_ARM_PREL31:
2fc8bdac 21161 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
21162 {
21163 newval = md_chars_to_number (buf, 4) & 0x80000000;
21164 if ((value ^ (value >> 1)) & 0x40000000)
21165 {
21166 as_bad_where (fixP->fx_file, fixP->fx_line,
21167 _("rel31 relocation overflow"));
21168 }
21169 newval |= value & 0x7fffffff;
21170 md_number_to_chars (buf, newval, 4);
21171 }
21172 break;
c19d1205 21173#endif
a737bd4d 21174
c19d1205 21175 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 21176 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
21177 if (value < -1023 || value > 1023 || (value & 3))
21178 as_bad_where (fixP->fx_file, fixP->fx_line,
21179 _("co-processor offset out of range"));
21180 cp_off_common:
26d97720 21181 sign = value > 0;
c19d1205
ZW
21182 if (value < 0)
21183 value = -value;
8f06b2d8
PB
21184 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21185 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21186 newval = md_chars_to_number (buf, INSN_SIZE);
21187 else
21188 newval = get_thumb32_insn (buf);
26d97720
NS
21189 if (value == 0)
21190 newval &= 0xffffff00;
21191 else
21192 {
21193 newval &= 0xff7fff00;
21194 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
21195 }
8f06b2d8
PB
21196 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21197 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21198 md_number_to_chars (buf, newval, INSN_SIZE);
21199 else
21200 put_thumb32_insn (buf, newval);
c19d1205 21201 break;
a737bd4d 21202
c19d1205 21203 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 21204 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
21205 if (value < -255 || value > 255)
21206 as_bad_where (fixP->fx_file, fixP->fx_line,
21207 _("co-processor offset out of range"));
df7849c5 21208 value *= 4;
c19d1205 21209 goto cp_off_common;
6c43fab6 21210
c19d1205
ZW
21211 case BFD_RELOC_ARM_THUMB_OFFSET:
21212 newval = md_chars_to_number (buf, THUMB_SIZE);
21213 /* Exactly what ranges, and where the offset is inserted depends
21214 on the type of instruction, we can establish this from the
21215 top 4 bits. */
21216 switch (newval >> 12)
21217 {
21218 case 4: /* PC load. */
21219 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
21220 forced to zero for these loads; md_pcrel_from has already
21221 compensated for this. */
21222 if (value & 3)
21223 as_bad_where (fixP->fx_file, fixP->fx_line,
21224 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
21225 (((unsigned long) fixP->fx_frag->fr_address
21226 + (unsigned long) fixP->fx_where) & ~3)
21227 + (unsigned long) value);
a737bd4d 21228
c19d1205
ZW
21229 if (value & ~0x3fc)
21230 as_bad_where (fixP->fx_file, fixP->fx_line,
21231 _("invalid offset, value too big (0x%08lX)"),
21232 (long) value);
a737bd4d 21233
c19d1205
ZW
21234 newval |= value >> 2;
21235 break;
a737bd4d 21236
c19d1205
ZW
21237 case 9: /* SP load/store. */
21238 if (value & ~0x3fc)
21239 as_bad_where (fixP->fx_file, fixP->fx_line,
21240 _("invalid offset, value too big (0x%08lX)"),
21241 (long) value);
21242 newval |= value >> 2;
21243 break;
6c43fab6 21244
c19d1205
ZW
21245 case 6: /* Word load/store. */
21246 if (value & ~0x7c)
21247 as_bad_where (fixP->fx_file, fixP->fx_line,
21248 _("invalid offset, value too big (0x%08lX)"),
21249 (long) value);
21250 newval |= value << 4; /* 6 - 2. */
21251 break;
a737bd4d 21252
c19d1205
ZW
21253 case 7: /* Byte load/store. */
21254 if (value & ~0x1f)
21255 as_bad_where (fixP->fx_file, fixP->fx_line,
21256 _("invalid offset, value too big (0x%08lX)"),
21257 (long) value);
21258 newval |= value << 6;
21259 break;
a737bd4d 21260
c19d1205
ZW
21261 case 8: /* Halfword load/store. */
21262 if (value & ~0x3e)
21263 as_bad_where (fixP->fx_file, fixP->fx_line,
21264 _("invalid offset, value too big (0x%08lX)"),
21265 (long) value);
21266 newval |= value << 5; /* 6 - 1. */
21267 break;
a737bd4d 21268
c19d1205
ZW
21269 default:
21270 as_bad_where (fixP->fx_file, fixP->fx_line,
21271 "Unable to process relocation for thumb opcode: %lx",
21272 (unsigned long) newval);
21273 break;
21274 }
21275 md_number_to_chars (buf, newval, THUMB_SIZE);
21276 break;
a737bd4d 21277
c19d1205
ZW
21278 case BFD_RELOC_ARM_THUMB_ADD:
21279 /* This is a complicated relocation, since we use it for all of
21280 the following immediate relocations:
a737bd4d 21281
c19d1205
ZW
21282 3bit ADD/SUB
21283 8bit ADD/SUB
21284 9bit ADD/SUB SP word-aligned
21285 10bit ADD PC/SP word-aligned
a737bd4d 21286
c19d1205
ZW
21287 The type of instruction being processed is encoded in the
21288 instruction field:
a737bd4d 21289
c19d1205
ZW
21290 0x8000 SUB
21291 0x00F0 Rd
21292 0x000F Rs
21293 */
21294 newval = md_chars_to_number (buf, THUMB_SIZE);
21295 {
21296 int rd = (newval >> 4) & 0xf;
21297 int rs = newval & 0xf;
21298 int subtract = !!(newval & 0x8000);
a737bd4d 21299
c19d1205
ZW
21300 /* Check for HI regs, only very restricted cases allowed:
21301 Adjusting SP, and using PC or SP to get an address. */
21302 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
21303 || (rs > 7 && rs != REG_SP && rs != REG_PC))
21304 as_bad_where (fixP->fx_file, fixP->fx_line,
21305 _("invalid Hi register with immediate"));
a737bd4d 21306
c19d1205
ZW
21307 /* If value is negative, choose the opposite instruction. */
21308 if (value < 0)
21309 {
21310 value = -value;
21311 subtract = !subtract;
21312 if (value < 0)
21313 as_bad_where (fixP->fx_file, fixP->fx_line,
21314 _("immediate value out of range"));
21315 }
a737bd4d 21316
c19d1205
ZW
21317 if (rd == REG_SP)
21318 {
21319 if (value & ~0x1fc)
21320 as_bad_where (fixP->fx_file, fixP->fx_line,
21321 _("invalid immediate for stack address calculation"));
21322 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
21323 newval |= value >> 2;
21324 }
21325 else if (rs == REG_PC || rs == REG_SP)
21326 {
21327 if (subtract || value & ~0x3fc)
21328 as_bad_where (fixP->fx_file, fixP->fx_line,
21329 _("invalid immediate for address calculation (value = 0x%08lX)"),
21330 (unsigned long) value);
21331 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
21332 newval |= rd << 8;
21333 newval |= value >> 2;
21334 }
21335 else if (rs == rd)
21336 {
21337 if (value & ~0xff)
21338 as_bad_where (fixP->fx_file, fixP->fx_line,
21339 _("immediate value out of range"));
21340 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
21341 newval |= (rd << 8) | value;
21342 }
21343 else
21344 {
21345 if (value & ~0x7)
21346 as_bad_where (fixP->fx_file, fixP->fx_line,
21347 _("immediate value out of range"));
21348 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
21349 newval |= rd | (rs << 3) | (value << 6);
21350 }
21351 }
21352 md_number_to_chars (buf, newval, THUMB_SIZE);
21353 break;
a737bd4d 21354
c19d1205
ZW
21355 case BFD_RELOC_ARM_THUMB_IMM:
21356 newval = md_chars_to_number (buf, THUMB_SIZE);
21357 if (value < 0 || value > 255)
21358 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 21359 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
21360 (long) value);
21361 newval |= value;
21362 md_number_to_chars (buf, newval, THUMB_SIZE);
21363 break;
a737bd4d 21364
c19d1205
ZW
21365 case BFD_RELOC_ARM_THUMB_SHIFT:
21366 /* 5bit shift value (0..32). LSL cannot take 32. */
21367 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
21368 temp = newval & 0xf800;
21369 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
21370 as_bad_where (fixP->fx_file, fixP->fx_line,
21371 _("invalid shift value: %ld"), (long) value);
21372 /* Shifts of zero must be encoded as LSL. */
21373 if (value == 0)
21374 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
21375 /* Shifts of 32 are encoded as zero. */
21376 else if (value == 32)
21377 value = 0;
21378 newval |= value << 6;
21379 md_number_to_chars (buf, newval, THUMB_SIZE);
21380 break;
a737bd4d 21381
c19d1205
ZW
21382 case BFD_RELOC_VTABLE_INHERIT:
21383 case BFD_RELOC_VTABLE_ENTRY:
21384 fixP->fx_done = 0;
21385 return;
6c43fab6 21386
b6895b4f
PB
21387 case BFD_RELOC_ARM_MOVW:
21388 case BFD_RELOC_ARM_MOVT:
21389 case BFD_RELOC_ARM_THUMB_MOVW:
21390 case BFD_RELOC_ARM_THUMB_MOVT:
21391 if (fixP->fx_done || !seg->use_rela_p)
21392 {
21393 /* REL format relocations are limited to a 16-bit addend. */
21394 if (!fixP->fx_done)
21395 {
39623e12 21396 if (value < -0x8000 || value > 0x7fff)
b6895b4f 21397 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 21398 _("offset out of range"));
b6895b4f
PB
21399 }
21400 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21401 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21402 {
21403 value >>= 16;
21404 }
21405
21406 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21407 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21408 {
21409 newval = get_thumb32_insn (buf);
21410 newval &= 0xfbf08f00;
21411 newval |= (value & 0xf000) << 4;
21412 newval |= (value & 0x0800) << 15;
21413 newval |= (value & 0x0700) << 4;
21414 newval |= (value & 0x00ff);
21415 put_thumb32_insn (buf, newval);
21416 }
21417 else
21418 {
21419 newval = md_chars_to_number (buf, 4);
21420 newval &= 0xfff0f000;
21421 newval |= value & 0x0fff;
21422 newval |= (value & 0xf000) << 4;
21423 md_number_to_chars (buf, newval, 4);
21424 }
21425 }
21426 return;
21427
4962c51a
MS
21428 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21429 case BFD_RELOC_ARM_ALU_PC_G0:
21430 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21431 case BFD_RELOC_ARM_ALU_PC_G1:
21432 case BFD_RELOC_ARM_ALU_PC_G2:
21433 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21434 case BFD_RELOC_ARM_ALU_SB_G0:
21435 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21436 case BFD_RELOC_ARM_ALU_SB_G1:
21437 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 21438 gas_assert (!fixP->fx_done);
4962c51a
MS
21439 if (!seg->use_rela_p)
21440 {
21441 bfd_vma insn;
21442 bfd_vma encoded_addend;
21443 bfd_vma addend_abs = abs (value);
21444
21445 /* Check that the absolute value of the addend can be
21446 expressed as an 8-bit constant plus a rotation. */
21447 encoded_addend = encode_arm_immediate (addend_abs);
21448 if (encoded_addend == (unsigned int) FAIL)
21449 as_bad_where (fixP->fx_file, fixP->fx_line,
21450 _("the offset 0x%08lX is not representable"),
495bde8e 21451 (unsigned long) addend_abs);
4962c51a
MS
21452
21453 /* Extract the instruction. */
21454 insn = md_chars_to_number (buf, INSN_SIZE);
21455
21456 /* If the addend is positive, use an ADD instruction.
21457 Otherwise use a SUB. Take care not to destroy the S bit. */
21458 insn &= 0xff1fffff;
21459 if (value < 0)
21460 insn |= 1 << 22;
21461 else
21462 insn |= 1 << 23;
21463
21464 /* Place the encoded addend into the first 12 bits of the
21465 instruction. */
21466 insn &= 0xfffff000;
21467 insn |= encoded_addend;
5f4273c7
NC
21468
21469 /* Update the instruction. */
4962c51a
MS
21470 md_number_to_chars (buf, insn, INSN_SIZE);
21471 }
21472 break;
21473
21474 case BFD_RELOC_ARM_LDR_PC_G0:
21475 case BFD_RELOC_ARM_LDR_PC_G1:
21476 case BFD_RELOC_ARM_LDR_PC_G2:
21477 case BFD_RELOC_ARM_LDR_SB_G0:
21478 case BFD_RELOC_ARM_LDR_SB_G1:
21479 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 21480 gas_assert (!fixP->fx_done);
4962c51a
MS
21481 if (!seg->use_rela_p)
21482 {
21483 bfd_vma insn;
21484 bfd_vma addend_abs = abs (value);
21485
21486 /* Check that the absolute value of the addend can be
21487 encoded in 12 bits. */
21488 if (addend_abs >= 0x1000)
21489 as_bad_where (fixP->fx_file, fixP->fx_line,
21490 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 21491 (unsigned long) addend_abs);
4962c51a
MS
21492
21493 /* Extract the instruction. */
21494 insn = md_chars_to_number (buf, INSN_SIZE);
21495
21496 /* If the addend is negative, clear bit 23 of the instruction.
21497 Otherwise set it. */
21498 if (value < 0)
21499 insn &= ~(1 << 23);
21500 else
21501 insn |= 1 << 23;
21502
21503 /* Place the absolute value of the addend into the first 12 bits
21504 of the instruction. */
21505 insn &= 0xfffff000;
21506 insn |= addend_abs;
5f4273c7
NC
21507
21508 /* Update the instruction. */
4962c51a
MS
21509 md_number_to_chars (buf, insn, INSN_SIZE);
21510 }
21511 break;
21512
21513 case BFD_RELOC_ARM_LDRS_PC_G0:
21514 case BFD_RELOC_ARM_LDRS_PC_G1:
21515 case BFD_RELOC_ARM_LDRS_PC_G2:
21516 case BFD_RELOC_ARM_LDRS_SB_G0:
21517 case BFD_RELOC_ARM_LDRS_SB_G1:
21518 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 21519 gas_assert (!fixP->fx_done);
4962c51a
MS
21520 if (!seg->use_rela_p)
21521 {
21522 bfd_vma insn;
21523 bfd_vma addend_abs = abs (value);
21524
21525 /* Check that the absolute value of the addend can be
21526 encoded in 8 bits. */
21527 if (addend_abs >= 0x100)
21528 as_bad_where (fixP->fx_file, fixP->fx_line,
21529 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 21530 (unsigned long) addend_abs);
4962c51a
MS
21531
21532 /* Extract the instruction. */
21533 insn = md_chars_to_number (buf, INSN_SIZE);
21534
21535 /* If the addend is negative, clear bit 23 of the instruction.
21536 Otherwise set it. */
21537 if (value < 0)
21538 insn &= ~(1 << 23);
21539 else
21540 insn |= 1 << 23;
21541
21542 /* Place the first four bits of the absolute value of the addend
21543 into the first 4 bits of the instruction, and the remaining
21544 four into bits 8 .. 11. */
21545 insn &= 0xfffff0f0;
21546 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
21547
21548 /* Update the instruction. */
4962c51a
MS
21549 md_number_to_chars (buf, insn, INSN_SIZE);
21550 }
21551 break;
21552
21553 case BFD_RELOC_ARM_LDC_PC_G0:
21554 case BFD_RELOC_ARM_LDC_PC_G1:
21555 case BFD_RELOC_ARM_LDC_PC_G2:
21556 case BFD_RELOC_ARM_LDC_SB_G0:
21557 case BFD_RELOC_ARM_LDC_SB_G1:
21558 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 21559 gas_assert (!fixP->fx_done);
4962c51a
MS
21560 if (!seg->use_rela_p)
21561 {
21562 bfd_vma insn;
21563 bfd_vma addend_abs = abs (value);
21564
21565 /* Check that the absolute value of the addend is a multiple of
21566 four and, when divided by four, fits in 8 bits. */
21567 if (addend_abs & 0x3)
21568 as_bad_where (fixP->fx_file, fixP->fx_line,
21569 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 21570 (unsigned long) addend_abs);
4962c51a
MS
21571
21572 if ((addend_abs >> 2) > 0xff)
21573 as_bad_where (fixP->fx_file, fixP->fx_line,
21574 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 21575 (unsigned long) addend_abs);
4962c51a
MS
21576
21577 /* Extract the instruction. */
21578 insn = md_chars_to_number (buf, INSN_SIZE);
21579
21580 /* If the addend is negative, clear bit 23 of the instruction.
21581 Otherwise set it. */
21582 if (value < 0)
21583 insn &= ~(1 << 23);
21584 else
21585 insn |= 1 << 23;
21586
21587 /* Place the addend (divided by four) into the first eight
21588 bits of the instruction. */
21589 insn &= 0xfffffff0;
21590 insn |= addend_abs >> 2;
5f4273c7
NC
21591
21592 /* Update the instruction. */
4962c51a
MS
21593 md_number_to_chars (buf, insn, INSN_SIZE);
21594 }
21595 break;
21596
845b51d6
PB
21597 case BFD_RELOC_ARM_V4BX:
21598 /* This will need to go in the object file. */
21599 fixP->fx_done = 0;
21600 break;
21601
c19d1205
ZW
21602 case BFD_RELOC_UNUSED:
21603 default:
21604 as_bad_where (fixP->fx_file, fixP->fx_line,
21605 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
21606 }
6c43fab6
RE
21607}
21608
c19d1205
ZW
21609/* Translate internal representation of relocation info to BFD target
21610 format. */
a737bd4d 21611
c19d1205 21612arelent *
00a97672 21613tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 21614{
c19d1205
ZW
21615 arelent * reloc;
21616 bfd_reloc_code_real_type code;
a737bd4d 21617
21d799b5 21618 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 21619
21d799b5 21620 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
21621 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
21622 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 21623
2fc8bdac 21624 if (fixp->fx_pcrel)
00a97672
RS
21625 {
21626 if (section->use_rela_p)
21627 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
21628 else
21629 fixp->fx_offset = reloc->address;
21630 }
c19d1205 21631 reloc->addend = fixp->fx_offset;
a737bd4d 21632
c19d1205 21633 switch (fixp->fx_r_type)
a737bd4d 21634 {
c19d1205
ZW
21635 case BFD_RELOC_8:
21636 if (fixp->fx_pcrel)
21637 {
21638 code = BFD_RELOC_8_PCREL;
21639 break;
21640 }
a737bd4d 21641
c19d1205
ZW
21642 case BFD_RELOC_16:
21643 if (fixp->fx_pcrel)
21644 {
21645 code = BFD_RELOC_16_PCREL;
21646 break;
21647 }
6c43fab6 21648
c19d1205
ZW
21649 case BFD_RELOC_32:
21650 if (fixp->fx_pcrel)
21651 {
21652 code = BFD_RELOC_32_PCREL;
21653 break;
21654 }
a737bd4d 21655
b6895b4f
PB
21656 case BFD_RELOC_ARM_MOVW:
21657 if (fixp->fx_pcrel)
21658 {
21659 code = BFD_RELOC_ARM_MOVW_PCREL;
21660 break;
21661 }
21662
21663 case BFD_RELOC_ARM_MOVT:
21664 if (fixp->fx_pcrel)
21665 {
21666 code = BFD_RELOC_ARM_MOVT_PCREL;
21667 break;
21668 }
21669
21670 case BFD_RELOC_ARM_THUMB_MOVW:
21671 if (fixp->fx_pcrel)
21672 {
21673 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21674 break;
21675 }
21676
21677 case BFD_RELOC_ARM_THUMB_MOVT:
21678 if (fixp->fx_pcrel)
21679 {
21680 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21681 break;
21682 }
21683
c19d1205
ZW
21684 case BFD_RELOC_NONE:
21685 case BFD_RELOC_ARM_PCREL_BRANCH:
21686 case BFD_RELOC_ARM_PCREL_BLX:
21687 case BFD_RELOC_RVA:
21688 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21689 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21690 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21691 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21692 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21693 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
21694 case BFD_RELOC_VTABLE_ENTRY:
21695 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
21696#ifdef TE_PE
21697 case BFD_RELOC_32_SECREL:
21698#endif
c19d1205
ZW
21699 code = fixp->fx_r_type;
21700 break;
a737bd4d 21701
00adf2d4
JB
21702 case BFD_RELOC_THUMB_PCREL_BLX:
21703#ifdef OBJ_ELF
21704 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21705 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21706 else
21707#endif
21708 code = BFD_RELOC_THUMB_PCREL_BLX;
21709 break;
21710
c19d1205
ZW
21711 case BFD_RELOC_ARM_LITERAL:
21712 case BFD_RELOC_ARM_HWLITERAL:
21713 /* If this is called then the a literal has
21714 been referenced across a section boundary. */
21715 as_bad_where (fixp->fx_file, fixp->fx_line,
21716 _("literal referenced across section boundary"));
21717 return NULL;
a737bd4d 21718
c19d1205 21719#ifdef OBJ_ELF
0855e32b
NS
21720 case BFD_RELOC_ARM_TLS_CALL:
21721 case BFD_RELOC_ARM_THM_TLS_CALL:
21722 case BFD_RELOC_ARM_TLS_DESCSEQ:
21723 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
21724 case BFD_RELOC_ARM_GOT32:
21725 case BFD_RELOC_ARM_GOTOFF:
b43420e6 21726 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
21727 case BFD_RELOC_ARM_PLT32:
21728 case BFD_RELOC_ARM_TARGET1:
21729 case BFD_RELOC_ARM_ROSEGREL32:
21730 case BFD_RELOC_ARM_SBREL32:
21731 case BFD_RELOC_ARM_PREL31:
21732 case BFD_RELOC_ARM_TARGET2:
21733 case BFD_RELOC_ARM_TLS_LE32:
21734 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
21735 case BFD_RELOC_ARM_PCREL_CALL:
21736 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
21737 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21738 case BFD_RELOC_ARM_ALU_PC_G0:
21739 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21740 case BFD_RELOC_ARM_ALU_PC_G1:
21741 case BFD_RELOC_ARM_ALU_PC_G2:
21742 case BFD_RELOC_ARM_LDR_PC_G0:
21743 case BFD_RELOC_ARM_LDR_PC_G1:
21744 case BFD_RELOC_ARM_LDR_PC_G2:
21745 case BFD_RELOC_ARM_LDRS_PC_G0:
21746 case BFD_RELOC_ARM_LDRS_PC_G1:
21747 case BFD_RELOC_ARM_LDRS_PC_G2:
21748 case BFD_RELOC_ARM_LDC_PC_G0:
21749 case BFD_RELOC_ARM_LDC_PC_G1:
21750 case BFD_RELOC_ARM_LDC_PC_G2:
21751 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21752 case BFD_RELOC_ARM_ALU_SB_G0:
21753 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21754 case BFD_RELOC_ARM_ALU_SB_G1:
21755 case BFD_RELOC_ARM_ALU_SB_G2:
21756 case BFD_RELOC_ARM_LDR_SB_G0:
21757 case BFD_RELOC_ARM_LDR_SB_G1:
21758 case BFD_RELOC_ARM_LDR_SB_G2:
21759 case BFD_RELOC_ARM_LDRS_SB_G0:
21760 case BFD_RELOC_ARM_LDRS_SB_G1:
21761 case BFD_RELOC_ARM_LDRS_SB_G2:
21762 case BFD_RELOC_ARM_LDC_SB_G0:
21763 case BFD_RELOC_ARM_LDC_SB_G1:
21764 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 21765 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
21766 code = fixp->fx_r_type;
21767 break;
a737bd4d 21768
0855e32b 21769 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
21770 case BFD_RELOC_ARM_TLS_GD32:
21771 case BFD_RELOC_ARM_TLS_IE32:
21772 case BFD_RELOC_ARM_TLS_LDM32:
21773 /* BFD will include the symbol's address in the addend.
21774 But we don't want that, so subtract it out again here. */
21775 if (!S_IS_COMMON (fixp->fx_addsy))
21776 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21777 code = fixp->fx_r_type;
21778 break;
21779#endif
a737bd4d 21780
c19d1205
ZW
21781 case BFD_RELOC_ARM_IMMEDIATE:
21782 as_bad_where (fixp->fx_file, fixp->fx_line,
21783 _("internal relocation (type: IMMEDIATE) not fixed up"));
21784 return NULL;
a737bd4d 21785
c19d1205
ZW
21786 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21787 as_bad_where (fixp->fx_file, fixp->fx_line,
21788 _("ADRL used for a symbol not defined in the same file"));
21789 return NULL;
a737bd4d 21790
c19d1205 21791 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
21792 if (section->use_rela_p)
21793 {
21794 code = fixp->fx_r_type;
21795 break;
21796 }
21797
c19d1205
ZW
21798 if (fixp->fx_addsy != NULL
21799 && !S_IS_DEFINED (fixp->fx_addsy)
21800 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 21801 {
c19d1205
ZW
21802 as_bad_where (fixp->fx_file, fixp->fx_line,
21803 _("undefined local label `%s'"),
21804 S_GET_NAME (fixp->fx_addsy));
21805 return NULL;
a737bd4d
NC
21806 }
21807
c19d1205
ZW
21808 as_bad_where (fixp->fx_file, fixp->fx_line,
21809 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21810 return NULL;
a737bd4d 21811
c19d1205
ZW
21812 default:
21813 {
21814 char * type;
6c43fab6 21815
c19d1205
ZW
21816 switch (fixp->fx_r_type)
21817 {
21818 case BFD_RELOC_NONE: type = "NONE"; break;
21819 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21820 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 21821 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
21822 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21823 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21824 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 21825 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 21826 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
21827 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21828 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21829 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21830 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21831 default: type = _("<unknown>"); break;
21832 }
21833 as_bad_where (fixp->fx_file, fixp->fx_line,
21834 _("cannot represent %s relocation in this object file format"),
21835 type);
21836 return NULL;
21837 }
a737bd4d 21838 }
6c43fab6 21839
c19d1205
ZW
21840#ifdef OBJ_ELF
21841 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21842 && GOT_symbol
21843 && fixp->fx_addsy == GOT_symbol)
21844 {
21845 code = BFD_RELOC_ARM_GOTPC;
21846 reloc->addend = fixp->fx_offset = reloc->address;
21847 }
21848#endif
6c43fab6 21849
c19d1205 21850 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 21851
c19d1205
ZW
21852 if (reloc->howto == NULL)
21853 {
21854 as_bad_where (fixp->fx_file, fixp->fx_line,
21855 _("cannot represent %s relocation in this object file format"),
21856 bfd_get_reloc_code_name (code));
21857 return NULL;
21858 }
6c43fab6 21859
c19d1205
ZW
21860 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21861 vtable entry to be used in the relocation's section offset. */
21862 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21863 reloc->address = fixp->fx_offset;
6c43fab6 21864
c19d1205 21865 return reloc;
6c43fab6
RE
21866}
21867
c19d1205 21868/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 21869
c19d1205
ZW
21870void
21871cons_fix_new_arm (fragS * frag,
21872 int where,
21873 int size,
21874 expressionS * exp)
6c43fab6 21875{
c19d1205
ZW
21876 bfd_reloc_code_real_type type;
21877 int pcrel = 0;
6c43fab6 21878
c19d1205
ZW
21879 /* Pick a reloc.
21880 FIXME: @@ Should look at CPU word size. */
21881 switch (size)
21882 {
21883 case 1:
21884 type = BFD_RELOC_8;
21885 break;
21886 case 2:
21887 type = BFD_RELOC_16;
21888 break;
21889 case 4:
21890 default:
21891 type = BFD_RELOC_32;
21892 break;
21893 case 8:
21894 type = BFD_RELOC_64;
21895 break;
21896 }
6c43fab6 21897
f0927246
NC
21898#ifdef TE_PE
21899 if (exp->X_op == O_secrel)
21900 {
21901 exp->X_op = O_symbol;
21902 type = BFD_RELOC_32_SECREL;
21903 }
21904#endif
21905
c19d1205
ZW
21906 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21907}
6c43fab6 21908
4343666d 21909#if defined (OBJ_COFF)
c19d1205
ZW
21910void
21911arm_validate_fix (fixS * fixP)
6c43fab6 21912{
c19d1205
ZW
21913 /* If the destination of the branch is a defined symbol which does not have
21914 the THUMB_FUNC attribute, then we must be calling a function which has
21915 the (interfacearm) attribute. We look for the Thumb entry point to that
21916 function and change the branch to refer to that function instead. */
21917 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21918 && fixP->fx_addsy != NULL
21919 && S_IS_DEFINED (fixP->fx_addsy)
21920 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 21921 {
c19d1205 21922 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 21923 }
c19d1205
ZW
21924}
21925#endif
6c43fab6 21926
267bf995 21927
c19d1205
ZW
21928int
21929arm_force_relocation (struct fix * fixp)
21930{
21931#if defined (OBJ_COFF) && defined (TE_PE)
21932 if (fixp->fx_r_type == BFD_RELOC_RVA)
21933 return 1;
21934#endif
6c43fab6 21935
267bf995
RR
21936 /* In case we have a call or a branch to a function in ARM ISA mode from
21937 a thumb function or vice-versa force the relocation. These relocations
21938 are cleared off for some cores that might have blx and simple transformations
21939 are possible. */
21940
21941#ifdef OBJ_ELF
21942 switch (fixp->fx_r_type)
21943 {
21944 case BFD_RELOC_ARM_PCREL_JUMP:
21945 case BFD_RELOC_ARM_PCREL_CALL:
21946 case BFD_RELOC_THUMB_PCREL_BLX:
21947 if (THUMB_IS_FUNC (fixp->fx_addsy))
21948 return 1;
21949 break;
21950
21951 case BFD_RELOC_ARM_PCREL_BLX:
21952 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21953 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21954 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21955 if (ARM_IS_FUNC (fixp->fx_addsy))
21956 return 1;
21957 break;
21958
21959 default:
21960 break;
21961 }
21962#endif
21963
b5884301
PB
21964 /* Resolve these relocations even if the symbol is extern or weak.
21965 Technically this is probably wrong due to symbol preemption.
21966 In practice these relocations do not have enough range to be useful
21967 at dynamic link time, and some code (e.g. in the Linux kernel)
21968 expects these references to be resolved. */
c19d1205
ZW
21969 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21970 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 21971 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 21972 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
21973 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21974 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
21975 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 21976 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
21977 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21978 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
21979 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
21980 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
21981 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
21982 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 21983 return 0;
a737bd4d 21984
4962c51a
MS
21985 /* Always leave these relocations for the linker. */
21986 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21987 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21988 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21989 return 1;
21990
f0291e4c
PB
21991 /* Always generate relocations against function symbols. */
21992 if (fixp->fx_r_type == BFD_RELOC_32
21993 && fixp->fx_addsy
21994 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21995 return 1;
21996
c19d1205 21997 return generic_force_reloc (fixp);
404ff6b5
AH
21998}
21999
0ffdc86c 22000#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
22001/* Relocations against function names must be left unadjusted,
22002 so that the linker can use this information to generate interworking
22003 stubs. The MIPS version of this function
c19d1205
ZW
22004 also prevents relocations that are mips-16 specific, but I do not
22005 know why it does this.
404ff6b5 22006
c19d1205
ZW
22007 FIXME:
22008 There is one other problem that ought to be addressed here, but
22009 which currently is not: Taking the address of a label (rather
22010 than a function) and then later jumping to that address. Such
22011 addresses also ought to have their bottom bit set (assuming that
22012 they reside in Thumb code), but at the moment they will not. */
404ff6b5 22013
c19d1205
ZW
22014bfd_boolean
22015arm_fix_adjustable (fixS * fixP)
404ff6b5 22016{
c19d1205
ZW
22017 if (fixP->fx_addsy == NULL)
22018 return 1;
404ff6b5 22019
e28387c3
PB
22020 /* Preserve relocations against symbols with function type. */
22021 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 22022 return FALSE;
e28387c3 22023
c19d1205
ZW
22024 if (THUMB_IS_FUNC (fixP->fx_addsy)
22025 && fixP->fx_subsy == NULL)
c921be7d 22026 return FALSE;
a737bd4d 22027
c19d1205
ZW
22028 /* We need the symbol name for the VTABLE entries. */
22029 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
22030 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 22031 return FALSE;
404ff6b5 22032
c19d1205
ZW
22033 /* Don't allow symbols to be discarded on GOT related relocs. */
22034 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
22035 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
22036 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
22037 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
22038 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
22039 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
22040 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
22041 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
22042 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
22043 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
22044 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
22045 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
22046 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 22047 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 22048 return FALSE;
a737bd4d 22049
4962c51a
MS
22050 /* Similarly for group relocations. */
22051 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22052 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22053 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 22054 return FALSE;
4962c51a 22055
79947c54
CD
22056 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
22057 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
22058 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
22059 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
22060 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
22061 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
22062 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
22063 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
22064 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 22065 return FALSE;
79947c54 22066
c921be7d 22067 return TRUE;
a737bd4d 22068}
0ffdc86c
NC
22069#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
22070
22071#ifdef OBJ_ELF
404ff6b5 22072
c19d1205
ZW
22073const char *
22074elf32_arm_target_format (void)
404ff6b5 22075{
c19d1205
ZW
22076#ifdef TE_SYMBIAN
22077 return (target_big_endian
22078 ? "elf32-bigarm-symbian"
22079 : "elf32-littlearm-symbian");
22080#elif defined (TE_VXWORKS)
22081 return (target_big_endian
22082 ? "elf32-bigarm-vxworks"
22083 : "elf32-littlearm-vxworks");
22084#else
22085 if (target_big_endian)
22086 return "elf32-bigarm";
22087 else
22088 return "elf32-littlearm";
22089#endif
404ff6b5
AH
22090}
22091
c19d1205
ZW
22092void
22093armelf_frob_symbol (symbolS * symp,
22094 int * puntp)
404ff6b5 22095{
c19d1205
ZW
22096 elf_frob_symbol (symp, puntp);
22097}
22098#endif
404ff6b5 22099
c19d1205 22100/* MD interface: Finalization. */
a737bd4d 22101
c19d1205
ZW
22102void
22103arm_cleanup (void)
22104{
22105 literal_pool * pool;
a737bd4d 22106
e07e6e58
NC
22107 /* Ensure that all the IT blocks are properly closed. */
22108 check_it_blocks_finished ();
22109
c19d1205
ZW
22110 for (pool = list_of_pools; pool; pool = pool->next)
22111 {
5f4273c7 22112 /* Put it at the end of the relevant section. */
c19d1205
ZW
22113 subseg_set (pool->section, pool->sub_section);
22114#ifdef OBJ_ELF
22115 arm_elf_change_section ();
22116#endif
22117 s_ltorg (0);
22118 }
404ff6b5
AH
22119}
22120
cd000bff
DJ
22121#ifdef OBJ_ELF
22122/* Remove any excess mapping symbols generated for alignment frags in
22123 SEC. We may have created a mapping symbol before a zero byte
22124 alignment; remove it if there's a mapping symbol after the
22125 alignment. */
22126static void
22127check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
22128 void *dummy ATTRIBUTE_UNUSED)
22129{
22130 segment_info_type *seginfo = seg_info (sec);
22131 fragS *fragp;
22132
22133 if (seginfo == NULL || seginfo->frchainP == NULL)
22134 return;
22135
22136 for (fragp = seginfo->frchainP->frch_root;
22137 fragp != NULL;
22138 fragp = fragp->fr_next)
22139 {
22140 symbolS *sym = fragp->tc_frag_data.last_map;
22141 fragS *next = fragp->fr_next;
22142
22143 /* Variable-sized frags have been converted to fixed size by
22144 this point. But if this was variable-sized to start with,
22145 there will be a fixed-size frag after it. So don't handle
22146 next == NULL. */
22147 if (sym == NULL || next == NULL)
22148 continue;
22149
22150 if (S_GET_VALUE (sym) < next->fr_address)
22151 /* Not at the end of this frag. */
22152 continue;
22153 know (S_GET_VALUE (sym) == next->fr_address);
22154
22155 do
22156 {
22157 if (next->tc_frag_data.first_map != NULL)
22158 {
22159 /* Next frag starts with a mapping symbol. Discard this
22160 one. */
22161 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22162 break;
22163 }
22164
22165 if (next->fr_next == NULL)
22166 {
22167 /* This mapping symbol is at the end of the section. Discard
22168 it. */
22169 know (next->fr_fix == 0 && next->fr_var == 0);
22170 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22171 break;
22172 }
22173
22174 /* As long as we have empty frags without any mapping symbols,
22175 keep looking. */
22176 /* If the next frag is non-empty and does not start with a
22177 mapping symbol, then this mapping symbol is required. */
22178 if (next->fr_address != next->fr_next->fr_address)
22179 break;
22180
22181 next = next->fr_next;
22182 }
22183 while (next != NULL);
22184 }
22185}
22186#endif
22187
c19d1205
ZW
22188/* Adjust the symbol table. This marks Thumb symbols as distinct from
22189 ARM ones. */
404ff6b5 22190
c19d1205
ZW
22191void
22192arm_adjust_symtab (void)
404ff6b5 22193{
c19d1205
ZW
22194#ifdef OBJ_COFF
22195 symbolS * sym;
404ff6b5 22196
c19d1205
ZW
22197 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
22198 {
22199 if (ARM_IS_THUMB (sym))
22200 {
22201 if (THUMB_IS_FUNC (sym))
22202 {
22203 /* Mark the symbol as a Thumb function. */
22204 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
22205 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
22206 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 22207
c19d1205
ZW
22208 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
22209 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
22210 else
22211 as_bad (_("%s: unexpected function type: %d"),
22212 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
22213 }
22214 else switch (S_GET_STORAGE_CLASS (sym))
22215 {
22216 case C_EXT:
22217 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
22218 break;
22219 case C_STAT:
22220 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
22221 break;
22222 case C_LABEL:
22223 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
22224 break;
22225 default:
22226 /* Do nothing. */
22227 break;
22228 }
22229 }
a737bd4d 22230
c19d1205
ZW
22231 if (ARM_IS_INTERWORK (sym))
22232 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 22233 }
c19d1205
ZW
22234#endif
22235#ifdef OBJ_ELF
22236 symbolS * sym;
22237 char bind;
404ff6b5 22238
c19d1205 22239 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 22240 {
c19d1205
ZW
22241 if (ARM_IS_THUMB (sym))
22242 {
22243 elf_symbol_type * elf_sym;
404ff6b5 22244
c19d1205
ZW
22245 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
22246 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 22247
b0796911
PB
22248 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
22249 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
22250 {
22251 /* If it's a .thumb_func, declare it as so,
22252 otherwise tag label as .code 16. */
22253 if (THUMB_IS_FUNC (sym))
35fc36a8
RS
22254 elf_sym->internal_elf_sym.st_target_internal
22255 = ST_BRANCH_TO_THUMB;
3ba67470 22256 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
22257 elf_sym->internal_elf_sym.st_info =
22258 ELF_ST_INFO (bind, STT_ARM_16BIT);
22259 }
22260 }
22261 }
cd000bff
DJ
22262
22263 /* Remove any overlapping mapping symbols generated by alignment frags. */
22264 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
22265 /* Now do generic ELF adjustments. */
22266 elf_adjust_symtab ();
c19d1205 22267#endif
404ff6b5
AH
22268}
22269
c19d1205 22270/* MD interface: Initialization. */
404ff6b5 22271
a737bd4d 22272static void
c19d1205 22273set_constant_flonums (void)
a737bd4d 22274{
c19d1205 22275 int i;
404ff6b5 22276
c19d1205
ZW
22277 for (i = 0; i < NUM_FLOAT_VALS; i++)
22278 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
22279 abort ();
a737bd4d 22280}
404ff6b5 22281
3e9e4fcf
JB
22282/* Auto-select Thumb mode if it's the only available instruction set for the
22283 given architecture. */
22284
22285static void
22286autoselect_thumb_from_cpu_variant (void)
22287{
22288 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
22289 opcode_select (16);
22290}
22291
c19d1205
ZW
22292void
22293md_begin (void)
a737bd4d 22294{
c19d1205
ZW
22295 unsigned mach;
22296 unsigned int i;
404ff6b5 22297
c19d1205
ZW
22298 if ( (arm_ops_hsh = hash_new ()) == NULL
22299 || (arm_cond_hsh = hash_new ()) == NULL
22300 || (arm_shift_hsh = hash_new ()) == NULL
22301 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 22302 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 22303 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
22304 || (arm_reloc_hsh = hash_new ()) == NULL
22305 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
22306 as_fatal (_("virtual memory exhausted"));
22307
22308 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 22309 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 22310 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 22311 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 22312 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 22313 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 22314 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 22315 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 22316 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0
NC
22317 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
22318 (void *) (v7m_psrs + i));
c19d1205 22319 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 22320 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
22321 for (i = 0;
22322 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
22323 i++)
d3ce72d0 22324 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 22325 (void *) (barrier_opt_names + i));
c19d1205
ZW
22326#ifdef OBJ_ELF
22327 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 22328 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
22329#endif
22330
22331 set_constant_flonums ();
404ff6b5 22332
c19d1205
ZW
22333 /* Set the cpu variant based on the command-line options. We prefer
22334 -mcpu= over -march= if both are set (as for GCC); and we prefer
22335 -mfpu= over any other way of setting the floating point unit.
22336 Use of legacy options with new options are faulted. */
e74cfd16 22337 if (legacy_cpu)
404ff6b5 22338 {
e74cfd16 22339 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
22340 as_bad (_("use of old and new-style options to set CPU type"));
22341
22342 mcpu_cpu_opt = legacy_cpu;
404ff6b5 22343 }
e74cfd16 22344 else if (!mcpu_cpu_opt)
c19d1205 22345 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 22346
e74cfd16 22347 if (legacy_fpu)
c19d1205 22348 {
e74cfd16 22349 if (mfpu_opt)
c19d1205 22350 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
22351
22352 mfpu_opt = legacy_fpu;
22353 }
e74cfd16 22354 else if (!mfpu_opt)
03b1477f 22355 {
45eb4c1b
NS
22356#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
22357 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
22358 /* Some environments specify a default FPU. If they don't, infer it
22359 from the processor. */
e74cfd16 22360 if (mcpu_fpu_opt)
03b1477f
RE
22361 mfpu_opt = mcpu_fpu_opt;
22362 else
22363 mfpu_opt = march_fpu_opt;
39c2da32 22364#else
e74cfd16 22365 mfpu_opt = &fpu_default;
39c2da32 22366#endif
03b1477f
RE
22367 }
22368
e74cfd16 22369 if (!mfpu_opt)
03b1477f 22370 {
493cb6ef 22371 if (mcpu_cpu_opt != NULL)
e74cfd16 22372 mfpu_opt = &fpu_default;
493cb6ef 22373 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 22374 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 22375 else
e74cfd16 22376 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
22377 }
22378
ee065d83 22379#ifdef CPU_DEFAULT
e74cfd16 22380 if (!mcpu_cpu_opt)
ee065d83 22381 {
e74cfd16
PB
22382 mcpu_cpu_opt = &cpu_default;
22383 selected_cpu = cpu_default;
ee065d83 22384 }
e74cfd16
PB
22385#else
22386 if (mcpu_cpu_opt)
22387 selected_cpu = *mcpu_cpu_opt;
ee065d83 22388 else
e74cfd16 22389 mcpu_cpu_opt = &arm_arch_any;
ee065d83 22390#endif
03b1477f 22391
e74cfd16 22392 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 22393
3e9e4fcf
JB
22394 autoselect_thumb_from_cpu_variant ();
22395
e74cfd16 22396 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 22397
f17c130b 22398#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 22399 {
7cc69913
NC
22400 unsigned int flags = 0;
22401
22402#if defined OBJ_ELF
22403 flags = meabi_flags;
d507cf36
PB
22404
22405 switch (meabi_flags)
33a392fb 22406 {
d507cf36 22407 case EF_ARM_EABI_UNKNOWN:
7cc69913 22408#endif
d507cf36
PB
22409 /* Set the flags in the private structure. */
22410 if (uses_apcs_26) flags |= F_APCS26;
22411 if (support_interwork) flags |= F_INTERWORK;
22412 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 22413 if (pic_code) flags |= F_PIC;
e74cfd16 22414 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
22415 flags |= F_SOFT_FLOAT;
22416
d507cf36
PB
22417 switch (mfloat_abi_opt)
22418 {
22419 case ARM_FLOAT_ABI_SOFT:
22420 case ARM_FLOAT_ABI_SOFTFP:
22421 flags |= F_SOFT_FLOAT;
22422 break;
33a392fb 22423
d507cf36
PB
22424 case ARM_FLOAT_ABI_HARD:
22425 if (flags & F_SOFT_FLOAT)
22426 as_bad (_("hard-float conflicts with specified fpu"));
22427 break;
22428 }
03b1477f 22429
e74cfd16
PB
22430 /* Using pure-endian doubles (even if soft-float). */
22431 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 22432 flags |= F_VFP_FLOAT;
f17c130b 22433
fde78edd 22434#if defined OBJ_ELF
e74cfd16 22435 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 22436 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
22437 break;
22438
8cb51566 22439 case EF_ARM_EABI_VER4:
3a4a14e9 22440 case EF_ARM_EABI_VER5:
c19d1205 22441 /* No additional flags to set. */
d507cf36
PB
22442 break;
22443
22444 default:
22445 abort ();
22446 }
7cc69913 22447#endif
b99bd4ef
NC
22448 bfd_set_private_flags (stdoutput, flags);
22449
22450 /* We have run out flags in the COFF header to encode the
22451 status of ATPCS support, so instead we create a dummy,
c19d1205 22452 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
22453 if (atpcs)
22454 {
22455 asection * sec;
22456
22457 sec = bfd_make_section (stdoutput, ".arm.atpcs");
22458
22459 if (sec != NULL)
22460 {
22461 bfd_set_section_flags
22462 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
22463 bfd_set_section_size (stdoutput, sec, 0);
22464 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
22465 }
22466 }
7cc69913 22467 }
f17c130b 22468#endif
b99bd4ef
NC
22469
22470 /* Record the CPU type as well. */
2d447fca
JM
22471 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
22472 mach = bfd_mach_arm_iWMMXt2;
22473 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 22474 mach = bfd_mach_arm_iWMMXt;
e74cfd16 22475 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 22476 mach = bfd_mach_arm_XScale;
e74cfd16 22477 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 22478 mach = bfd_mach_arm_ep9312;
e74cfd16 22479 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 22480 mach = bfd_mach_arm_5TE;
e74cfd16 22481 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 22482 {
e74cfd16 22483 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22484 mach = bfd_mach_arm_5T;
22485 else
22486 mach = bfd_mach_arm_5;
22487 }
e74cfd16 22488 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 22489 {
e74cfd16 22490 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22491 mach = bfd_mach_arm_4T;
22492 else
22493 mach = bfd_mach_arm_4;
22494 }
e74cfd16 22495 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 22496 mach = bfd_mach_arm_3M;
e74cfd16
PB
22497 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
22498 mach = bfd_mach_arm_3;
22499 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
22500 mach = bfd_mach_arm_2a;
22501 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
22502 mach = bfd_mach_arm_2;
22503 else
22504 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
22505
22506 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
22507}
22508
c19d1205 22509/* Command line processing. */
b99bd4ef 22510
c19d1205
ZW
22511/* md_parse_option
22512 Invocation line includes a switch not recognized by the base assembler.
22513 See if it's a processor-specific option.
b99bd4ef 22514
c19d1205
ZW
22515 This routine is somewhat complicated by the need for backwards
22516 compatibility (since older releases of gcc can't be changed).
22517 The new options try to make the interface as compatible as
22518 possible with GCC.
b99bd4ef 22519
c19d1205 22520 New options (supported) are:
b99bd4ef 22521
c19d1205
ZW
22522 -mcpu=<cpu name> Assemble for selected processor
22523 -march=<architecture name> Assemble for selected architecture
22524 -mfpu=<fpu architecture> Assemble for selected FPU.
22525 -EB/-mbig-endian Big-endian
22526 -EL/-mlittle-endian Little-endian
22527 -k Generate PIC code
22528 -mthumb Start in Thumb mode
22529 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 22530
278df34e 22531 -m[no-]warn-deprecated Warn about deprecated features
267bf995 22532
c19d1205 22533 For now we will also provide support for:
b99bd4ef 22534
c19d1205
ZW
22535 -mapcs-32 32-bit Program counter
22536 -mapcs-26 26-bit Program counter
22537 -macps-float Floats passed in FP registers
22538 -mapcs-reentrant Reentrant code
22539 -matpcs
22540 (sometime these will probably be replaced with -mapcs=<list of options>
22541 and -matpcs=<list of options>)
b99bd4ef 22542
c19d1205
ZW
22543 The remaining options are only supported for back-wards compatibility.
22544 Cpu variants, the arm part is optional:
22545 -m[arm]1 Currently not supported.
22546 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
22547 -m[arm]3 Arm 3 processor
22548 -m[arm]6[xx], Arm 6 processors
22549 -m[arm]7[xx][t][[d]m] Arm 7 processors
22550 -m[arm]8[10] Arm 8 processors
22551 -m[arm]9[20][tdmi] Arm 9 processors
22552 -mstrongarm[110[0]] StrongARM processors
22553 -mxscale XScale processors
22554 -m[arm]v[2345[t[e]]] Arm architectures
22555 -mall All (except the ARM1)
22556 FP variants:
22557 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
22558 -mfpe-old (No float load/store multiples)
22559 -mvfpxd VFP Single precision
22560 -mvfp All VFP
22561 -mno-fpu Disable all floating point instructions
b99bd4ef 22562
c19d1205
ZW
22563 The following CPU names are recognized:
22564 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
22565 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
22566 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
22567 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
22568 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
22569 arm10t arm10e, arm1020t, arm1020e, arm10200e,
22570 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 22571
c19d1205 22572 */
b99bd4ef 22573
c19d1205 22574const char * md_shortopts = "m:k";
b99bd4ef 22575
c19d1205
ZW
22576#ifdef ARM_BI_ENDIAN
22577#define OPTION_EB (OPTION_MD_BASE + 0)
22578#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 22579#else
c19d1205
ZW
22580#if TARGET_BYTES_BIG_ENDIAN
22581#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 22582#else
c19d1205
ZW
22583#define OPTION_EL (OPTION_MD_BASE + 1)
22584#endif
b99bd4ef 22585#endif
845b51d6 22586#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 22587
c19d1205 22588struct option md_longopts[] =
b99bd4ef 22589{
c19d1205
ZW
22590#ifdef OPTION_EB
22591 {"EB", no_argument, NULL, OPTION_EB},
22592#endif
22593#ifdef OPTION_EL
22594 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 22595#endif
845b51d6 22596 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
22597 {NULL, no_argument, NULL, 0}
22598};
b99bd4ef 22599
c19d1205 22600size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 22601
c19d1205 22602struct arm_option_table
b99bd4ef 22603{
c19d1205
ZW
22604 char *option; /* Option name to match. */
22605 char *help; /* Help information. */
22606 int *var; /* Variable to change. */
22607 int value; /* What to change it to. */
22608 char *deprecated; /* If non-null, print this message. */
22609};
b99bd4ef 22610
c19d1205
ZW
22611struct arm_option_table arm_opts[] =
22612{
22613 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
22614 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
22615 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
22616 &support_interwork, 1, NULL},
22617 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
22618 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
22619 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
22620 1, NULL},
22621 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
22622 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
22623 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
22624 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
22625 NULL},
b99bd4ef 22626
c19d1205
ZW
22627 /* These are recognized by the assembler, but have no affect on code. */
22628 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
22629 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
22630
22631 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
22632 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
22633 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
22634 {NULL, NULL, NULL, 0, NULL}
22635};
22636
22637struct arm_legacy_option_table
22638{
22639 char *option; /* Option name to match. */
22640 const arm_feature_set **var; /* Variable to change. */
22641 const arm_feature_set value; /* What to change it to. */
22642 char *deprecated; /* If non-null, print this message. */
22643};
b99bd4ef 22644
e74cfd16
PB
22645const struct arm_legacy_option_table arm_legacy_opts[] =
22646{
c19d1205
ZW
22647 /* DON'T add any new processors to this list -- we want the whole list
22648 to go away... Add them to the processors table instead. */
e74cfd16
PB
22649 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22650 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22651 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22652 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22653 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22654 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22655 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22656 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22657 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22658 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22659 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22660 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22661 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22662 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22663 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22664 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22665 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22666 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22667 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22668 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22669 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22670 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22671 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22672 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22673 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22674 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22675 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22676 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22677 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22678 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22679 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22680 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22681 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22682 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22683 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22684 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22685 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22686 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22687 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22688 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22689 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22690 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22691 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22692 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22693 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22694 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22695 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22696 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22697 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22698 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22699 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22700 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22701 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22702 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22703 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22704 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22705 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22706 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22707 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22708 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22709 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22710 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22711 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22712 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22713 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22714 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22715 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22716 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22717 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22718 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22719 N_("use -mcpu=strongarm110")},
e74cfd16 22720 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22721 N_("use -mcpu=strongarm1100")},
e74cfd16 22722 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22723 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
22724 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22725 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22726 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 22727
c19d1205 22728 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
22729 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22730 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22731 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22732 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22733 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22734 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22735 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22736 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22737 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22738 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22739 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22740 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22741 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22742 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22743 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22744 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22745 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22746 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 22747
c19d1205 22748 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
22749 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22750 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22751 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22752 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 22753 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 22754
e74cfd16 22755 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 22756};
7ed4c4c5 22757
c19d1205 22758struct arm_cpu_option_table
7ed4c4c5 22759{
c19d1205 22760 char *name;
e74cfd16 22761 const arm_feature_set value;
c19d1205
ZW
22762 /* For some CPUs we assume an FPU unless the user explicitly sets
22763 -mfpu=... */
e74cfd16 22764 const arm_feature_set default_fpu;
ee065d83
PB
22765 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22766 case. */
22767 const char *canonical_name;
c19d1205 22768};
7ed4c4c5 22769
c19d1205
ZW
22770/* This list should, at a minimum, contain all the cpu names
22771 recognized by GCC. */
e74cfd16 22772static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 22773{
ee065d83
PB
22774 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
22775 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
22776 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
22777 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22778 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22779 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22780 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22781 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22782 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22783 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22784 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22785 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22786 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22787 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22788 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22789 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22790 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22791 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22792 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22793 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22794 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22795 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22796 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22797 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22798 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22799 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22800 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22801 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22802 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22803 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22804 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22805 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22806 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22807 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22808 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22809 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22810 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22811 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22812 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22813 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
22814 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22815 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22816 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22817 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
22818 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22819 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
22820 /* For V5 or later processors we default to using VFP; but the user
22821 should really set the FPU type explicitly. */
ee065d83
PB
22822 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22823 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22824 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22825 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22826 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22827 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22828 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22829 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22830 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22831 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22832 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22833 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22834 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22835 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22836 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22837 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22838 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22839 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22840 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22841 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22842 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
4a58c4bd
NC
22843 {"fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22844 {"fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22845 {"fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22846 {"fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
7fac0536 22847 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
22848 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22849 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22850 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22851 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
4ff9b924
MGD
22852 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"},
22853 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"},
ee065d83
PB
22854 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22855 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22856 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22857 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
f4c65163
MGD
22858 {"cortex-a5", ARM_ARCH_V7A_MP_SEC,
22859 FPU_NONE, "Cortex-A5"},
22860 {"cortex-a8", ARM_ARCH_V7A_SEC,
22861 ARM_FEATURE (0, FPU_VFP_V3
5287ad62 22862 | FPU_NEON_EXT_V1),
4ff9b924 22863 "Cortex-A8"},
f4c65163
MGD
22864 {"cortex-a9", ARM_ARCH_V7A_MP_SEC,
22865 ARM_FEATURE (0, FPU_VFP_V3
15290f0a 22866 | FPU_NEON_EXT_V1),
4ff9b924 22867 "Cortex-A9"},
90ec0d68 22868 {"cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
eea54501 22869 FPU_ARCH_NEON_VFP_V4,
dbb1f804 22870 "Cortex-A15"},
4ff9b924
MGD
22871 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"},
22872 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
22873 "Cortex-R4F"},
3b2f0793
PB
22874 {"cortex-r5", ARM_ARCH_V7R_IDIV,
22875 FPU_NONE, "Cortex-R5"},
4ff9b924
MGD
22876 {"cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"},
22877 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"},
b2a5fbdc
MGD
22878 {"cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"},
22879 {"cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"},
c19d1205 22880 /* ??? XSCALE is really an architecture. */
ee065d83 22881 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22882 /* ??? iwmmxt is not a processor. */
ee065d83 22883 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 22884 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 22885 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22886 /* Maverick */
e07e6e58 22887 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
e74cfd16 22888 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 22889};
7ed4c4c5 22890
c19d1205 22891struct arm_arch_option_table
7ed4c4c5 22892{
c19d1205 22893 char *name;
e74cfd16
PB
22894 const arm_feature_set value;
22895 const arm_feature_set default_fpu;
c19d1205 22896};
7ed4c4c5 22897
c19d1205
ZW
22898/* This list should, at a minimum, contain all the architecture names
22899 recognized by GCC. */
e74cfd16 22900static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
22901{
22902 {"all", ARM_ANY, FPU_ARCH_FPA},
22903 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22904 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22905 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22906 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22907 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22908 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22909 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22910 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22911 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22912 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22913 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22914 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22915 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22916 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22917 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22918 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22919 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22920 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22921 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22922 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22923 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22924 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22925 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22926 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22927 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 22928 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
b2a5fbdc 22929 {"armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP},
62b3e311 22930 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
22931 /* The official spelling of the ARMv7 profile variants is the dashed form.
22932 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
22933 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22934 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22935 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
22936 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22937 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22938 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
9e3c6df6 22939 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
c19d1205
ZW
22940 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22941 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 22942 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 22943 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 22944};
7ed4c4c5 22945
69133863
MGD
22946/* ISA extensions in the co-processor and main instruction set space. */
22947struct arm_option_extension_value_table
c19d1205
ZW
22948{
22949 char *name;
e74cfd16 22950 const arm_feature_set value;
69133863 22951 const arm_feature_set allowed_archs;
c19d1205 22952};
7ed4c4c5 22953
69133863
MGD
22954/* The following table must be in alphabetical order with a NULL last entry.
22955 */
22956static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 22957{
eea54501 22958 {"idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0),
3b2f0793 22959 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)},
69133863
MGD
22960 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY},
22961 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY},
22962 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY},
60e5ef9f
MGD
22963 {"mp", ARM_FEATURE (ARM_EXT_MP, 0),
22964 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)},
b2a5fbdc
MGD
22965 {"os", ARM_FEATURE (ARM_EXT_OS, 0),
22966 ARM_FEATURE (ARM_EXT_V6M, 0)},
f4c65163
MGD
22967 {"sec", ARM_FEATURE (ARM_EXT_SEC, 0),
22968 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)},
90ec0d68
MGD
22969 {"virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV | ARM_EXT_DIV, 0),
22970 ARM_FEATURE (ARM_EXT_V7A, 0)},
69133863 22971 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY},
60e5ef9f 22972 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
69133863
MGD
22973};
22974
22975/* ISA floating-point and Advanced SIMD extensions. */
22976struct arm_option_fpu_value_table
22977{
22978 char *name;
22979 const arm_feature_set value;
c19d1205 22980};
7ed4c4c5 22981
c19d1205
ZW
22982/* This list should, at a minimum, contain all the fpu names
22983 recognized by GCC. */
69133863 22984static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
22985{
22986 {"softfpa", FPU_NONE},
22987 {"fpe", FPU_ARCH_FPE},
22988 {"fpe2", FPU_ARCH_FPE},
22989 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22990 {"fpa", FPU_ARCH_FPA},
22991 {"fpa10", FPU_ARCH_FPA},
22992 {"fpa11", FPU_ARCH_FPA},
22993 {"arm7500fe", FPU_ARCH_FPA},
22994 {"softvfp", FPU_ARCH_VFP},
22995 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22996 {"vfp", FPU_ARCH_VFP_V2},
22997 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 22998 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
22999 {"vfp10", FPU_ARCH_VFP_V2},
23000 {"vfp10-r0", FPU_ARCH_VFP_V1},
23001 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
23002 {"vfpv2", FPU_ARCH_VFP_V2},
23003 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 23004 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 23005 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
23006 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
23007 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
23008 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
23009 {"arm1020t", FPU_ARCH_VFP_V1},
23010 {"arm1020e", FPU_ARCH_VFP_V2},
23011 {"arm1136jfs", FPU_ARCH_VFP_V2},
23012 {"arm1136jf-s", FPU_ARCH_VFP_V2},
23013 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 23014 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 23015 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
23016 {"vfpv4", FPU_ARCH_VFP_V4},
23017 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 23018 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 23019 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
e74cfd16
PB
23020 {NULL, ARM_ARCH_NONE}
23021};
23022
23023struct arm_option_value_table
23024{
23025 char *name;
23026 long value;
c19d1205 23027};
7ed4c4c5 23028
e74cfd16 23029static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
23030{
23031 {"hard", ARM_FLOAT_ABI_HARD},
23032 {"softfp", ARM_FLOAT_ABI_SOFTFP},
23033 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 23034 {NULL, 0}
c19d1205 23035};
7ed4c4c5 23036
c19d1205 23037#ifdef OBJ_ELF
3a4a14e9 23038/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 23039static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
23040{
23041 {"gnu", EF_ARM_EABI_UNKNOWN},
23042 {"4", EF_ARM_EABI_VER4},
3a4a14e9 23043 {"5", EF_ARM_EABI_VER5},
e74cfd16 23044 {NULL, 0}
c19d1205
ZW
23045};
23046#endif
7ed4c4c5 23047
c19d1205
ZW
23048struct arm_long_option_table
23049{
23050 char * option; /* Substring to match. */
23051 char * help; /* Help information. */
23052 int (* func) (char * subopt); /* Function to decode sub-option. */
23053 char * deprecated; /* If non-null, print this message. */
23054};
7ed4c4c5 23055
c921be7d 23056static bfd_boolean
e74cfd16 23057arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 23058{
21d799b5
NC
23059 arm_feature_set *ext_set = (arm_feature_set *)
23060 xmalloc (sizeof (arm_feature_set));
e74cfd16 23061
69133863
MGD
23062 /* We insist on extensions being specified in alphabetical order, and with
23063 extensions being added before being removed. We achieve this by having
23064 the global ARM_EXTENSIONS table in alphabetical order, and using the
23065 ADDING_VALUE variable to indicate whether we are adding an extension (1)
23066 or removing it (0) and only allowing it to change in the order
23067 -1 -> 1 -> 0. */
23068 const struct arm_option_extension_value_table * opt = NULL;
23069 int adding_value = -1;
23070
e74cfd16
PB
23071 /* Copy the feature set, so that we can modify it. */
23072 *ext_set = **opt_p;
23073 *opt_p = ext_set;
23074
c19d1205 23075 while (str != NULL && *str != 0)
7ed4c4c5 23076 {
c19d1205 23077 char * ext;
69133863 23078 size_t optlen;
7ed4c4c5 23079
c19d1205
ZW
23080 if (*str != '+')
23081 {
23082 as_bad (_("invalid architectural extension"));
c921be7d 23083 return FALSE;
c19d1205 23084 }
7ed4c4c5 23085
c19d1205
ZW
23086 str++;
23087 ext = strchr (str, '+');
7ed4c4c5 23088
c19d1205
ZW
23089 if (ext != NULL)
23090 optlen = ext - str;
23091 else
23092 optlen = strlen (str);
7ed4c4c5 23093
69133863
MGD
23094 if (optlen >= 2
23095 && strncmp (str, "no", 2) == 0)
23096 {
23097 if (adding_value != 0)
23098 {
23099 adding_value = 0;
23100 opt = arm_extensions;
23101 }
23102
23103 optlen -= 2;
23104 str += 2;
23105 }
23106 else if (optlen > 0)
23107 {
23108 if (adding_value == -1)
23109 {
23110 adding_value = 1;
23111 opt = arm_extensions;
23112 }
23113 else if (adding_value != 1)
23114 {
23115 as_bad (_("must specify extensions to add before specifying "
23116 "those to remove"));
23117 return FALSE;
23118 }
23119 }
23120
c19d1205
ZW
23121 if (optlen == 0)
23122 {
23123 as_bad (_("missing architectural extension"));
c921be7d 23124 return FALSE;
c19d1205 23125 }
7ed4c4c5 23126
69133863
MGD
23127 gas_assert (adding_value != -1);
23128 gas_assert (opt != NULL);
23129
23130 /* Scan over the options table trying to find an exact match. */
23131 for (; opt->name != NULL; opt++)
23132 if (strncmp (opt->name, str, optlen) == 0
23133 && strlen (opt->name) == optlen)
c19d1205 23134 {
69133863
MGD
23135 /* Check we can apply the extension to this architecture. */
23136 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
23137 {
23138 as_bad (_("extension does not apply to the base architecture"));
23139 return FALSE;
23140 }
23141
23142 /* Add or remove the extension. */
23143 if (adding_value)
23144 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
23145 else
23146 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
23147
c19d1205
ZW
23148 break;
23149 }
7ed4c4c5 23150
c19d1205
ZW
23151 if (opt->name == NULL)
23152 {
69133863
MGD
23153 /* Did we fail to find an extension because it wasn't specified in
23154 alphabetical order, or because it does not exist? */
23155
23156 for (opt = arm_extensions; opt->name != NULL; opt++)
23157 if (strncmp (opt->name, str, optlen) == 0)
23158 break;
23159
23160 if (opt->name == NULL)
23161 as_bad (_("unknown architectural extension `%s'"), str);
23162 else
23163 as_bad (_("architectural extensions must be specified in "
23164 "alphabetical order"));
23165
c921be7d 23166 return FALSE;
c19d1205 23167 }
69133863
MGD
23168 else
23169 {
23170 /* We should skip the extension we've just matched the next time
23171 round. */
23172 opt++;
23173 }
7ed4c4c5 23174
c19d1205
ZW
23175 str = ext;
23176 };
7ed4c4c5 23177
c921be7d 23178 return TRUE;
c19d1205 23179}
7ed4c4c5 23180
c921be7d 23181static bfd_boolean
c19d1205 23182arm_parse_cpu (char * str)
7ed4c4c5 23183{
e74cfd16 23184 const struct arm_cpu_option_table * opt;
c19d1205
ZW
23185 char * ext = strchr (str, '+');
23186 int optlen;
7ed4c4c5 23187
c19d1205
ZW
23188 if (ext != NULL)
23189 optlen = ext - str;
7ed4c4c5 23190 else
c19d1205 23191 optlen = strlen (str);
7ed4c4c5 23192
c19d1205 23193 if (optlen == 0)
7ed4c4c5 23194 {
c19d1205 23195 as_bad (_("missing cpu name `%s'"), str);
c921be7d 23196 return FALSE;
7ed4c4c5
NC
23197 }
23198
c19d1205
ZW
23199 for (opt = arm_cpus; opt->name != NULL; opt++)
23200 if (strncmp (opt->name, str, optlen) == 0)
23201 {
e74cfd16
PB
23202 mcpu_cpu_opt = &opt->value;
23203 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 23204 if (opt->canonical_name)
5f4273c7 23205 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
23206 else
23207 {
23208 int i;
c921be7d 23209
ee065d83
PB
23210 for (i = 0; i < optlen; i++)
23211 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23212 selected_cpu_name[i] = 0;
23213 }
7ed4c4c5 23214
c19d1205
ZW
23215 if (ext != NULL)
23216 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 23217
c921be7d 23218 return TRUE;
c19d1205 23219 }
7ed4c4c5 23220
c19d1205 23221 as_bad (_("unknown cpu `%s'"), str);
c921be7d 23222 return FALSE;
7ed4c4c5
NC
23223}
23224
c921be7d 23225static bfd_boolean
c19d1205 23226arm_parse_arch (char * str)
7ed4c4c5 23227{
e74cfd16 23228 const struct arm_arch_option_table *opt;
c19d1205
ZW
23229 char *ext = strchr (str, '+');
23230 int optlen;
7ed4c4c5 23231
c19d1205
ZW
23232 if (ext != NULL)
23233 optlen = ext - str;
7ed4c4c5 23234 else
c19d1205 23235 optlen = strlen (str);
7ed4c4c5 23236
c19d1205 23237 if (optlen == 0)
7ed4c4c5 23238 {
c19d1205 23239 as_bad (_("missing architecture name `%s'"), str);
c921be7d 23240 return FALSE;
7ed4c4c5
NC
23241 }
23242
c19d1205 23243 for (opt = arm_archs; opt->name != NULL; opt++)
69133863 23244 if (strncmp (opt->name, str, optlen) == 0)
c19d1205 23245 {
e74cfd16
PB
23246 march_cpu_opt = &opt->value;
23247 march_fpu_opt = &opt->default_fpu;
5f4273c7 23248 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 23249
c19d1205
ZW
23250 if (ext != NULL)
23251 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 23252
c921be7d 23253 return TRUE;
c19d1205
ZW
23254 }
23255
23256 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 23257 return FALSE;
7ed4c4c5 23258}
eb043451 23259
c921be7d 23260static bfd_boolean
c19d1205
ZW
23261arm_parse_fpu (char * str)
23262{
69133863 23263 const struct arm_option_fpu_value_table * opt;
b99bd4ef 23264
c19d1205
ZW
23265 for (opt = arm_fpus; opt->name != NULL; opt++)
23266 if (streq (opt->name, str))
23267 {
e74cfd16 23268 mfpu_opt = &opt->value;
c921be7d 23269 return TRUE;
c19d1205 23270 }
b99bd4ef 23271
c19d1205 23272 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 23273 return FALSE;
c19d1205
ZW
23274}
23275
c921be7d 23276static bfd_boolean
c19d1205 23277arm_parse_float_abi (char * str)
b99bd4ef 23278{
e74cfd16 23279 const struct arm_option_value_table * opt;
b99bd4ef 23280
c19d1205
ZW
23281 for (opt = arm_float_abis; opt->name != NULL; opt++)
23282 if (streq (opt->name, str))
23283 {
23284 mfloat_abi_opt = opt->value;
c921be7d 23285 return TRUE;
c19d1205 23286 }
cc8a6dd0 23287
c19d1205 23288 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 23289 return FALSE;
c19d1205 23290}
b99bd4ef 23291
c19d1205 23292#ifdef OBJ_ELF
c921be7d 23293static bfd_boolean
c19d1205
ZW
23294arm_parse_eabi (char * str)
23295{
e74cfd16 23296 const struct arm_option_value_table *opt;
cc8a6dd0 23297
c19d1205
ZW
23298 for (opt = arm_eabis; opt->name != NULL; opt++)
23299 if (streq (opt->name, str))
23300 {
23301 meabi_flags = opt->value;
c921be7d 23302 return TRUE;
c19d1205
ZW
23303 }
23304 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 23305 return FALSE;
c19d1205
ZW
23306}
23307#endif
cc8a6dd0 23308
c921be7d 23309static bfd_boolean
e07e6e58
NC
23310arm_parse_it_mode (char * str)
23311{
c921be7d 23312 bfd_boolean ret = TRUE;
e07e6e58
NC
23313
23314 if (streq ("arm", str))
23315 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
23316 else if (streq ("thumb", str))
23317 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
23318 else if (streq ("always", str))
23319 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
23320 else if (streq ("never", str))
23321 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
23322 else
23323 {
23324 as_bad (_("unknown implicit IT mode `%s', should be "\
23325 "arm, thumb, always, or never."), str);
c921be7d 23326 ret = FALSE;
e07e6e58
NC
23327 }
23328
23329 return ret;
23330}
23331
c19d1205
ZW
23332struct arm_long_option_table arm_long_opts[] =
23333{
23334 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
23335 arm_parse_cpu, NULL},
23336 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
23337 arm_parse_arch, NULL},
23338 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
23339 arm_parse_fpu, NULL},
23340 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
23341 arm_parse_float_abi, NULL},
23342#ifdef OBJ_ELF
7fac0536 23343 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
23344 arm_parse_eabi, NULL},
23345#endif
e07e6e58
NC
23346 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
23347 arm_parse_it_mode, NULL},
c19d1205
ZW
23348 {NULL, NULL, 0, NULL}
23349};
cc8a6dd0 23350
c19d1205
ZW
23351int
23352md_parse_option (int c, char * arg)
23353{
23354 struct arm_option_table *opt;
e74cfd16 23355 const struct arm_legacy_option_table *fopt;
c19d1205 23356 struct arm_long_option_table *lopt;
b99bd4ef 23357
c19d1205 23358 switch (c)
b99bd4ef 23359 {
c19d1205
ZW
23360#ifdef OPTION_EB
23361 case OPTION_EB:
23362 target_big_endian = 1;
23363 break;
23364#endif
cc8a6dd0 23365
c19d1205
ZW
23366#ifdef OPTION_EL
23367 case OPTION_EL:
23368 target_big_endian = 0;
23369 break;
23370#endif
b99bd4ef 23371
845b51d6
PB
23372 case OPTION_FIX_V4BX:
23373 fix_v4bx = TRUE;
23374 break;
23375
c19d1205
ZW
23376 case 'a':
23377 /* Listing option. Just ignore these, we don't support additional
23378 ones. */
23379 return 0;
b99bd4ef 23380
c19d1205
ZW
23381 default:
23382 for (opt = arm_opts; opt->option != NULL; opt++)
23383 {
23384 if (c == opt->option[0]
23385 && ((arg == NULL && opt->option[1] == 0)
23386 || streq (arg, opt->option + 1)))
23387 {
c19d1205 23388 /* If the option is deprecated, tell the user. */
278df34e 23389 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
23390 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23391 arg ? arg : "", _(opt->deprecated));
b99bd4ef 23392
c19d1205
ZW
23393 if (opt->var != NULL)
23394 *opt->var = opt->value;
cc8a6dd0 23395
c19d1205
ZW
23396 return 1;
23397 }
23398 }
b99bd4ef 23399
e74cfd16
PB
23400 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
23401 {
23402 if (c == fopt->option[0]
23403 && ((arg == NULL && fopt->option[1] == 0)
23404 || streq (arg, fopt->option + 1)))
23405 {
e74cfd16 23406 /* If the option is deprecated, tell the user. */
278df34e 23407 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
23408 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23409 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
23410
23411 if (fopt->var != NULL)
23412 *fopt->var = &fopt->value;
23413
23414 return 1;
23415 }
23416 }
23417
c19d1205
ZW
23418 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23419 {
23420 /* These options are expected to have an argument. */
23421 if (c == lopt->option[0]
23422 && arg != NULL
23423 && strncmp (arg, lopt->option + 1,
23424 strlen (lopt->option + 1)) == 0)
23425 {
c19d1205 23426 /* If the option is deprecated, tell the user. */
278df34e 23427 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
23428 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
23429 _(lopt->deprecated));
b99bd4ef 23430
c19d1205
ZW
23431 /* Call the sup-option parser. */
23432 return lopt->func (arg + strlen (lopt->option) - 1);
23433 }
23434 }
a737bd4d 23435
c19d1205
ZW
23436 return 0;
23437 }
a394c00f 23438
c19d1205
ZW
23439 return 1;
23440}
a394c00f 23441
c19d1205
ZW
23442void
23443md_show_usage (FILE * fp)
a394c00f 23444{
c19d1205
ZW
23445 struct arm_option_table *opt;
23446 struct arm_long_option_table *lopt;
a394c00f 23447
c19d1205 23448 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 23449
c19d1205
ZW
23450 for (opt = arm_opts; opt->option != NULL; opt++)
23451 if (opt->help != NULL)
23452 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 23453
c19d1205
ZW
23454 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23455 if (lopt->help != NULL)
23456 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 23457
c19d1205
ZW
23458#ifdef OPTION_EB
23459 fprintf (fp, _("\
23460 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
23461#endif
23462
c19d1205
ZW
23463#ifdef OPTION_EL
23464 fprintf (fp, _("\
23465 -EL assemble code for a little-endian cpu\n"));
a737bd4d 23466#endif
845b51d6
PB
23467
23468 fprintf (fp, _("\
23469 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 23470}
ee065d83
PB
23471
23472
23473#ifdef OBJ_ELF
62b3e311
PB
23474typedef struct
23475{
23476 int val;
23477 arm_feature_set flags;
23478} cpu_arch_ver_table;
23479
23480/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
23481 least features first. */
23482static const cpu_arch_ver_table cpu_arch_ver[] =
23483{
23484 {1, ARM_ARCH_V4},
23485 {2, ARM_ARCH_V4T},
23486 {3, ARM_ARCH_V5},
ee3c0378 23487 {3, ARM_ARCH_V5T},
62b3e311
PB
23488 {4, ARM_ARCH_V5TE},
23489 {5, ARM_ARCH_V5TEJ},
23490 {6, ARM_ARCH_V6},
7e806470 23491 {9, ARM_ARCH_V6K},
f4c65163 23492 {7, ARM_ARCH_V6Z},
91e22acd 23493 {11, ARM_ARCH_V6M},
b2a5fbdc 23494 {12, ARM_ARCH_V6SM},
7e806470 23495 {8, ARM_ARCH_V6T2},
62b3e311
PB
23496 {10, ARM_ARCH_V7A},
23497 {10, ARM_ARCH_V7R},
23498 {10, ARM_ARCH_V7M},
23499 {0, ARM_ARCH_NONE}
23500};
23501
ee3c0378
AS
23502/* Set an attribute if it has not already been set by the user. */
23503static void
23504aeabi_set_attribute_int (int tag, int value)
23505{
23506 if (tag < 1
23507 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23508 || !attributes_set_explicitly[tag])
23509 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
23510}
23511
23512static void
23513aeabi_set_attribute_string (int tag, const char *value)
23514{
23515 if (tag < 1
23516 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23517 || !attributes_set_explicitly[tag])
23518 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
23519}
23520
ee065d83
PB
23521/* Set the public EABI object attributes. */
23522static void
23523aeabi_set_public_attributes (void)
23524{
23525 int arch;
90ec0d68 23526 int virt_sec = 0;
e74cfd16 23527 arm_feature_set flags;
62b3e311
PB
23528 arm_feature_set tmp;
23529 const cpu_arch_ver_table *p;
ee065d83
PB
23530
23531 /* Choose the architecture based on the capabilities of the requested cpu
23532 (if any) and/or the instructions actually used. */
e74cfd16
PB
23533 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
23534 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
23535 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
23536 /*Allow the user to override the reported architecture. */
23537 if (object_arch)
23538 {
23539 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
23540 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
23541 }
23542
251665fc
MGD
23543 /* We need to make sure that the attributes do not identify us as v6S-M
23544 when the only v6S-M feature in use is the Operating System Extensions. */
23545 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
23546 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
23547 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
23548
62b3e311
PB
23549 tmp = flags;
23550 arch = 0;
23551 for (p = cpu_arch_ver; p->val; p++)
23552 {
23553 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
23554 {
23555 arch = p->val;
23556 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
23557 }
23558 }
ee065d83 23559
9e3c6df6
PB
23560 /* The table lookup above finds the last architecture to contribute
23561 a new feature. Unfortunately, Tag13 is a subset of the union of
23562 v6T2 and v7-M, so it is never seen as contributing a new feature.
23563 We can not search for the last entry which is entirely used,
23564 because if no CPU is specified we build up only those flags
23565 actually used. Perhaps we should separate out the specified
23566 and implicit cases. Avoid taking this path for -march=all by
23567 checking for contradictory v7-A / v7-M features. */
23568 if (arch == 10
23569 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
23570 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
23571 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
23572 arch = 13;
23573
ee065d83
PB
23574 /* Tag_CPU_name. */
23575 if (selected_cpu_name[0])
23576 {
91d6fa6a 23577 char *q;
ee065d83 23578
91d6fa6a
NC
23579 q = selected_cpu_name;
23580 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
23581 {
23582 int i;
5f4273c7 23583
91d6fa6a
NC
23584 q += 4;
23585 for (i = 0; q[i]; i++)
23586 q[i] = TOUPPER (q[i]);
ee065d83 23587 }
91d6fa6a 23588 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 23589 }
62f3b8c8 23590
ee065d83 23591 /* Tag_CPU_arch. */
ee3c0378 23592 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 23593
62b3e311
PB
23594 /* Tag_CPU_arch_profile. */
23595 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 23596 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 23597 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 23598 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 23599 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 23600 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
62f3b8c8 23601
ee065d83 23602 /* Tag_ARM_ISA_use. */
ee3c0378
AS
23603 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
23604 || arch == 0)
23605 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 23606
ee065d83 23607 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
23608 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
23609 || arch == 0)
23610 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
23611 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 23612
ee065d83 23613 /* Tag_VFP_arch. */
62f3b8c8
PB
23614 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
23615 aeabi_set_attribute_int (Tag_VFP_arch,
23616 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
23617 ? 5 : 6);
23618 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
ee3c0378 23619 aeabi_set_attribute_int (Tag_VFP_arch, 3);
ada65aa3 23620 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
ee3c0378
AS
23621 aeabi_set_attribute_int (Tag_VFP_arch, 4);
23622 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
23623 aeabi_set_attribute_int (Tag_VFP_arch, 2);
23624 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
23625 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
23626 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 23627
4547cb56
NC
23628 /* Tag_ABI_HardFP_use. */
23629 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
23630 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
23631 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
23632
ee065d83 23633 /* Tag_WMMX_arch. */
ee3c0378
AS
23634 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
23635 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
23636 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
23637 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 23638
ee3c0378 23639 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 23640 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
62f3b8c8
PB
23641 aeabi_set_attribute_int
23642 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
23643 ? 2 : 1));
23644
ee3c0378 23645 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
62f3b8c8 23646 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
ee3c0378 23647 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56
NC
23648
23649 /* Tag_DIV_use. */
eea54501
MGD
23650 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv))
23651 aeabi_set_attribute_int (Tag_DIV_use, 2);
23652 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_div))
4547cb56 23653 aeabi_set_attribute_int (Tag_DIV_use, 0);
4547cb56
NC
23654 else
23655 aeabi_set_attribute_int (Tag_DIV_use, 1);
60e5ef9f
MGD
23656
23657 /* Tag_MP_extension_use. */
23658 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
23659 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
23660
23661 /* Tag Virtualization_use. */
23662 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
23663 virt_sec |= 1;
23664 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
23665 virt_sec |= 2;
23666 if (virt_sec != 0)
23667 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
23668}
23669
104d59d1 23670/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
23671void
23672arm_md_end (void)
23673{
ee065d83
PB
23674 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
23675 return;
23676
23677 aeabi_set_public_attributes ();
ee065d83 23678}
8463be01 23679#endif /* OBJ_ELF */
ee065d83
PB
23680
23681
23682/* Parse a .cpu directive. */
23683
23684static void
23685s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
23686{
e74cfd16 23687 const struct arm_cpu_option_table *opt;
ee065d83
PB
23688 char *name;
23689 char saved_char;
23690
23691 name = input_line_pointer;
5f4273c7 23692 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23693 input_line_pointer++;
23694 saved_char = *input_line_pointer;
23695 *input_line_pointer = 0;
23696
23697 /* Skip the first "all" entry. */
23698 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
23699 if (streq (opt->name, name))
23700 {
e74cfd16
PB
23701 mcpu_cpu_opt = &opt->value;
23702 selected_cpu = opt->value;
ee065d83 23703 if (opt->canonical_name)
5f4273c7 23704 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
23705 else
23706 {
23707 int i;
23708 for (i = 0; opt->name[i]; i++)
23709 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23710 selected_cpu_name[i] = 0;
23711 }
e74cfd16 23712 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23713 *input_line_pointer = saved_char;
23714 demand_empty_rest_of_line ();
23715 return;
23716 }
23717 as_bad (_("unknown cpu `%s'"), name);
23718 *input_line_pointer = saved_char;
23719 ignore_rest_of_line ();
23720}
23721
23722
23723/* Parse a .arch directive. */
23724
23725static void
23726s_arm_arch (int ignored ATTRIBUTE_UNUSED)
23727{
e74cfd16 23728 const struct arm_arch_option_table *opt;
ee065d83
PB
23729 char saved_char;
23730 char *name;
23731
23732 name = input_line_pointer;
5f4273c7 23733 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23734 input_line_pointer++;
23735 saved_char = *input_line_pointer;
23736 *input_line_pointer = 0;
23737
23738 /* Skip the first "all" entry. */
23739 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23740 if (streq (opt->name, name))
23741 {
e74cfd16
PB
23742 mcpu_cpu_opt = &opt->value;
23743 selected_cpu = opt->value;
5f4273c7 23744 strcpy (selected_cpu_name, opt->name);
e74cfd16 23745 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23746 *input_line_pointer = saved_char;
23747 demand_empty_rest_of_line ();
23748 return;
23749 }
23750
23751 as_bad (_("unknown architecture `%s'\n"), name);
23752 *input_line_pointer = saved_char;
23753 ignore_rest_of_line ();
23754}
23755
23756
7a1d4c38
PB
23757/* Parse a .object_arch directive. */
23758
23759static void
23760s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
23761{
23762 const struct arm_arch_option_table *opt;
23763 char saved_char;
23764 char *name;
23765
23766 name = input_line_pointer;
5f4273c7 23767 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
23768 input_line_pointer++;
23769 saved_char = *input_line_pointer;
23770 *input_line_pointer = 0;
23771
23772 /* Skip the first "all" entry. */
23773 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23774 if (streq (opt->name, name))
23775 {
23776 object_arch = &opt->value;
23777 *input_line_pointer = saved_char;
23778 demand_empty_rest_of_line ();
23779 return;
23780 }
23781
23782 as_bad (_("unknown architecture `%s'\n"), name);
23783 *input_line_pointer = saved_char;
23784 ignore_rest_of_line ();
23785}
23786
69133863
MGD
23787/* Parse a .arch_extension directive. */
23788
23789static void
23790s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
23791{
23792 const struct arm_option_extension_value_table *opt;
23793 char saved_char;
23794 char *name;
23795 int adding_value = 1;
23796
23797 name = input_line_pointer;
23798 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23799 input_line_pointer++;
23800 saved_char = *input_line_pointer;
23801 *input_line_pointer = 0;
23802
23803 if (strlen (name) >= 2
23804 && strncmp (name, "no", 2) == 0)
23805 {
23806 adding_value = 0;
23807 name += 2;
23808 }
23809
23810 for (opt = arm_extensions; opt->name != NULL; opt++)
23811 if (streq (opt->name, name))
23812 {
23813 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
23814 {
23815 as_bad (_("architectural extension `%s' is not allowed for the "
23816 "current base architecture"), name);
23817 break;
23818 }
23819
23820 if (adding_value)
23821 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
23822 else
23823 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
23824
23825 mcpu_cpu_opt = &selected_cpu;
23826 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23827 *input_line_pointer = saved_char;
23828 demand_empty_rest_of_line ();
23829 return;
23830 }
23831
23832 if (opt->name == NULL)
23833 as_bad (_("unknown architecture `%s'\n"), name);
23834
23835 *input_line_pointer = saved_char;
23836 ignore_rest_of_line ();
23837}
23838
ee065d83
PB
23839/* Parse a .fpu directive. */
23840
23841static void
23842s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
23843{
69133863 23844 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
23845 char saved_char;
23846 char *name;
23847
23848 name = input_line_pointer;
5f4273c7 23849 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23850 input_line_pointer++;
23851 saved_char = *input_line_pointer;
23852 *input_line_pointer = 0;
5f4273c7 23853
ee065d83
PB
23854 for (opt = arm_fpus; opt->name != NULL; opt++)
23855 if (streq (opt->name, name))
23856 {
e74cfd16
PB
23857 mfpu_opt = &opt->value;
23858 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23859 *input_line_pointer = saved_char;
23860 demand_empty_rest_of_line ();
23861 return;
23862 }
23863
23864 as_bad (_("unknown floating point format `%s'\n"), name);
23865 *input_line_pointer = saved_char;
23866 ignore_rest_of_line ();
23867}
ee065d83 23868
794ba86a 23869/* Copy symbol information. */
f31fef98 23870
794ba86a
DJ
23871void
23872arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
23873{
23874 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
23875}
e04befd0 23876
f31fef98 23877#ifdef OBJ_ELF
e04befd0
AS
23878/* Given a symbolic attribute NAME, return the proper integer value.
23879 Returns -1 if the attribute is not known. */
f31fef98 23880
e04befd0
AS
23881int
23882arm_convert_symbolic_attribute (const char *name)
23883{
f31fef98
NC
23884 static const struct
23885 {
23886 const char * name;
23887 const int tag;
23888 }
23889 attribute_table[] =
23890 {
23891 /* When you modify this table you should
23892 also modify the list in doc/c-arm.texi. */
e04befd0 23893#define T(tag) {#tag, tag}
f31fef98
NC
23894 T (Tag_CPU_raw_name),
23895 T (Tag_CPU_name),
23896 T (Tag_CPU_arch),
23897 T (Tag_CPU_arch_profile),
23898 T (Tag_ARM_ISA_use),
23899 T (Tag_THUMB_ISA_use),
75375b3e 23900 T (Tag_FP_arch),
f31fef98
NC
23901 T (Tag_VFP_arch),
23902 T (Tag_WMMX_arch),
23903 T (Tag_Advanced_SIMD_arch),
23904 T (Tag_PCS_config),
23905 T (Tag_ABI_PCS_R9_use),
23906 T (Tag_ABI_PCS_RW_data),
23907 T (Tag_ABI_PCS_RO_data),
23908 T (Tag_ABI_PCS_GOT_use),
23909 T (Tag_ABI_PCS_wchar_t),
23910 T (Tag_ABI_FP_rounding),
23911 T (Tag_ABI_FP_denormal),
23912 T (Tag_ABI_FP_exceptions),
23913 T (Tag_ABI_FP_user_exceptions),
23914 T (Tag_ABI_FP_number_model),
75375b3e 23915 T (Tag_ABI_align_needed),
f31fef98 23916 T (Tag_ABI_align8_needed),
75375b3e 23917 T (Tag_ABI_align_preserved),
f31fef98
NC
23918 T (Tag_ABI_align8_preserved),
23919 T (Tag_ABI_enum_size),
23920 T (Tag_ABI_HardFP_use),
23921 T (Tag_ABI_VFP_args),
23922 T (Tag_ABI_WMMX_args),
23923 T (Tag_ABI_optimization_goals),
23924 T (Tag_ABI_FP_optimization_goals),
23925 T (Tag_compatibility),
23926 T (Tag_CPU_unaligned_access),
75375b3e 23927 T (Tag_FP_HP_extension),
f31fef98
NC
23928 T (Tag_VFP_HP_extension),
23929 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
23930 T (Tag_MPextension_use),
23931 T (Tag_DIV_use),
f31fef98
NC
23932 T (Tag_nodefaults),
23933 T (Tag_also_compatible_with),
23934 T (Tag_conformance),
23935 T (Tag_T2EE_use),
23936 T (Tag_Virtualization_use),
cd21e546 23937 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 23938#undef T
f31fef98 23939 };
e04befd0
AS
23940 unsigned int i;
23941
23942 if (name == NULL)
23943 return -1;
23944
f31fef98 23945 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 23946 if (streq (name, attribute_table[i].name))
e04befd0
AS
23947 return attribute_table[i].tag;
23948
23949 return -1;
23950}
267bf995
RR
23951
23952
23953/* Apply sym value for relocations only in the case that
23954 they are for local symbols and you have the respective
23955 architectural feature for blx and simple switches. */
23956int
23957arm_apply_sym_value (struct fix * fixP)
23958{
23959 if (fixP->fx_addsy
23960 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
34e77a92 23961 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
23962 {
23963 switch (fixP->fx_r_type)
23964 {
23965 case BFD_RELOC_ARM_PCREL_BLX:
23966 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23967 if (ARM_IS_FUNC (fixP->fx_addsy))
23968 return 1;
23969 break;
23970
23971 case BFD_RELOC_ARM_PCREL_CALL:
23972 case BFD_RELOC_THUMB_PCREL_BLX:
23973 if (THUMB_IS_FUNC (fixP->fx_addsy))
23974 return 1;
23975 break;
23976
23977 default:
23978 break;
23979 }
23980
23981 }
23982 return 0;
23983}
f31fef98 23984#endif /* OBJ_ELF */
This page took 2.878202 seconds and 4 git commands to generate.