]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
2011-08-01 Tristan Gingold <gingold@adacore.com>
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
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")
08f10d51 727#define BAD_RANGE _("branch out of range")
c19d1205 728
c921be7d
NC
729static struct hash_control * arm_ops_hsh;
730static struct hash_control * arm_cond_hsh;
731static struct hash_control * arm_shift_hsh;
732static struct hash_control * arm_psr_hsh;
733static struct hash_control * arm_v7m_psr_hsh;
734static struct hash_control * arm_reg_hsh;
735static struct hash_control * arm_reloc_hsh;
736static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 737
b99bd4ef
NC
738/* Stuff needed to resolve the label ambiguity
739 As:
740 ...
741 label: <insn>
742 may differ from:
743 ...
744 label:
5f4273c7 745 <insn> */
b99bd4ef
NC
746
747symbolS * last_label_seen;
b34976b6 748static int label_is_thumb_function_name = FALSE;
e07e6e58 749
3d0c9500
NC
750/* Literal pool structure. Held on a per-section
751 and per-sub-section basis. */
a737bd4d 752
c19d1205 753#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 754typedef struct literal_pool
b99bd4ef 755{
c921be7d
NC
756 expressionS literals [MAX_LITERAL_POOL_SIZE];
757 unsigned int next_free_entry;
758 unsigned int id;
759 symbolS * symbol;
760 segT section;
761 subsegT sub_section;
762 struct literal_pool * next;
3d0c9500 763} literal_pool;
b99bd4ef 764
3d0c9500
NC
765/* Pointer to a linked list of literal pools. */
766literal_pool * list_of_pools = NULL;
e27ec89e 767
e07e6e58
NC
768#ifdef OBJ_ELF
769# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
770#else
771static struct current_it now_it;
772#endif
773
774static inline int
775now_it_compatible (int cond)
776{
777 return (cond & ~1) == (now_it.cc & ~1);
778}
779
780static inline int
781conditional_insn (void)
782{
783 return inst.cond != COND_ALWAYS;
784}
785
786static int in_it_block (void);
787
788static int handle_it_state (void);
789
790static void force_automatic_it_block_close (void);
791
c921be7d
NC
792static void it_fsm_post_encode (void);
793
e07e6e58
NC
794#define set_it_insn_type(type) \
795 do \
796 { \
797 inst.it_insn_type = type; \
798 if (handle_it_state () == FAIL) \
799 return; \
800 } \
801 while (0)
802
c921be7d
NC
803#define set_it_insn_type_nonvoid(type, failret) \
804 do \
805 { \
806 inst.it_insn_type = type; \
807 if (handle_it_state () == FAIL) \
808 return failret; \
809 } \
810 while(0)
811
e07e6e58
NC
812#define set_it_insn_type_last() \
813 do \
814 { \
815 if (inst.cond == COND_ALWAYS) \
816 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
817 else \
818 set_it_insn_type (INSIDE_IT_LAST_INSN); \
819 } \
820 while (0)
821
c19d1205 822/* Pure syntax. */
b99bd4ef 823
c19d1205
ZW
824/* This array holds the chars that always start a comment. If the
825 pre-processor is disabled, these aren't very useful. */
826const char comment_chars[] = "@";
3d0c9500 827
c19d1205
ZW
828/* This array holds the chars that only start a comment at the beginning of
829 a line. If the line seems to have the form '# 123 filename'
830 .line and .file directives will appear in the pre-processed output. */
831/* Note that input_file.c hand checks for '#' at the beginning of the
832 first line of the input file. This is because the compiler outputs
833 #NO_APP at the beginning of its output. */
834/* Also note that comments like this one will always work. */
835const char line_comment_chars[] = "#";
3d0c9500 836
c19d1205 837const char line_separator_chars[] = ";";
b99bd4ef 838
c19d1205
ZW
839/* Chars that can be used to separate mant
840 from exp in floating point numbers. */
841const char EXP_CHARS[] = "eE";
3d0c9500 842
c19d1205
ZW
843/* Chars that mean this number is a floating point constant. */
844/* As in 0f12.456 */
845/* or 0d1.2345e12 */
b99bd4ef 846
c19d1205 847const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 848
c19d1205
ZW
849/* Prefix characters that indicate the start of an immediate
850 value. */
851#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 852
c19d1205
ZW
853/* Separator character handling. */
854
855#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
856
857static inline int
858skip_past_char (char ** str, char c)
859{
860 if (**str == c)
861 {
862 (*str)++;
863 return SUCCESS;
3d0c9500 864 }
c19d1205
ZW
865 else
866 return FAIL;
867}
c921be7d 868
c19d1205 869#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 870
c19d1205
ZW
871/* Arithmetic expressions (possibly involving symbols). */
872
873/* Return TRUE if anything in the expression is a bignum. */
874
875static int
876walk_no_bignums (symbolS * sp)
877{
878 if (symbol_get_value_expression (sp)->X_op == O_big)
879 return 1;
880
881 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 882 {
c19d1205
ZW
883 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
884 || (symbol_get_value_expression (sp)->X_op_symbol
885 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
886 }
887
c19d1205 888 return 0;
3d0c9500
NC
889}
890
c19d1205
ZW
891static int in_my_get_expression = 0;
892
893/* Third argument to my_get_expression. */
894#define GE_NO_PREFIX 0
895#define GE_IMM_PREFIX 1
896#define GE_OPT_PREFIX 2
5287ad62
JB
897/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
898 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
899#define GE_OPT_PREFIX_BIG 3
a737bd4d 900
b99bd4ef 901static int
c19d1205 902my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 903{
c19d1205
ZW
904 char * save_in;
905 segT seg;
b99bd4ef 906
c19d1205
ZW
907 /* In unified syntax, all prefixes are optional. */
908 if (unified_syntax)
5287ad62
JB
909 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
910 : GE_OPT_PREFIX;
b99bd4ef 911
c19d1205 912 switch (prefix_mode)
b99bd4ef 913 {
c19d1205
ZW
914 case GE_NO_PREFIX: break;
915 case GE_IMM_PREFIX:
916 if (!is_immediate_prefix (**str))
917 {
918 inst.error = _("immediate expression requires a # prefix");
919 return FAIL;
920 }
921 (*str)++;
922 break;
923 case GE_OPT_PREFIX:
5287ad62 924 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
925 if (is_immediate_prefix (**str))
926 (*str)++;
927 break;
928 default: abort ();
929 }
b99bd4ef 930
c19d1205 931 memset (ep, 0, sizeof (expressionS));
b99bd4ef 932
c19d1205
ZW
933 save_in = input_line_pointer;
934 input_line_pointer = *str;
935 in_my_get_expression = 1;
936 seg = expression (ep);
937 in_my_get_expression = 0;
938
f86adc07 939 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 940 {
f86adc07 941 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
942 *str = input_line_pointer;
943 input_line_pointer = save_in;
944 if (inst.error == NULL)
f86adc07
NS
945 inst.error = (ep->X_op == O_absent
946 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
947 return 1;
948 }
b99bd4ef 949
c19d1205
ZW
950#ifdef OBJ_AOUT
951 if (seg != absolute_section
952 && seg != text_section
953 && seg != data_section
954 && seg != bss_section
955 && seg != undefined_section)
956 {
957 inst.error = _("bad segment");
958 *str = input_line_pointer;
959 input_line_pointer = save_in;
960 return 1;
b99bd4ef 961 }
87975d2a
AM
962#else
963 (void) seg;
c19d1205 964#endif
b99bd4ef 965
c19d1205
ZW
966 /* Get rid of any bignums now, so that we don't generate an error for which
967 we can't establish a line number later on. Big numbers are never valid
968 in instructions, which is where this routine is always called. */
5287ad62
JB
969 if (prefix_mode != GE_OPT_PREFIX_BIG
970 && (ep->X_op == O_big
971 || (ep->X_add_symbol
972 && (walk_no_bignums (ep->X_add_symbol)
973 || (ep->X_op_symbol
974 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
975 {
976 inst.error = _("invalid constant");
977 *str = input_line_pointer;
978 input_line_pointer = save_in;
979 return 1;
980 }
b99bd4ef 981
c19d1205
ZW
982 *str = input_line_pointer;
983 input_line_pointer = save_in;
984 return 0;
b99bd4ef
NC
985}
986
c19d1205
ZW
987/* Turn a string in input_line_pointer into a floating point constant
988 of type TYPE, and store the appropriate bytes in *LITP. The number
989 of LITTLENUMS emitted is stored in *SIZEP. An error message is
990 returned, or NULL on OK.
b99bd4ef 991
c19d1205
ZW
992 Note that fp constants aren't represent in the normal way on the ARM.
993 In big endian mode, things are as expected. However, in little endian
994 mode fp constants are big-endian word-wise, and little-endian byte-wise
995 within the words. For example, (double) 1.1 in big endian mode is
996 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
997 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 998
c19d1205 999 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1000
c19d1205
ZW
1001char *
1002md_atof (int type, char * litP, int * sizeP)
1003{
1004 int prec;
1005 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1006 char *t;
1007 int i;
b99bd4ef 1008
c19d1205
ZW
1009 switch (type)
1010 {
1011 case 'f':
1012 case 'F':
1013 case 's':
1014 case 'S':
1015 prec = 2;
1016 break;
b99bd4ef 1017
c19d1205
ZW
1018 case 'd':
1019 case 'D':
1020 case 'r':
1021 case 'R':
1022 prec = 4;
1023 break;
b99bd4ef 1024
c19d1205
ZW
1025 case 'x':
1026 case 'X':
499ac353 1027 prec = 5;
c19d1205 1028 break;
b99bd4ef 1029
c19d1205
ZW
1030 case 'p':
1031 case 'P':
499ac353 1032 prec = 5;
c19d1205 1033 break;
a737bd4d 1034
c19d1205
ZW
1035 default:
1036 *sizeP = 0;
499ac353 1037 return _("Unrecognized or unsupported floating point constant");
c19d1205 1038 }
b99bd4ef 1039
c19d1205
ZW
1040 t = atof_ieee (input_line_pointer, type, words);
1041 if (t)
1042 input_line_pointer = t;
499ac353 1043 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1044
c19d1205
ZW
1045 if (target_big_endian)
1046 {
1047 for (i = 0; i < prec; i++)
1048 {
499ac353
NC
1049 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1050 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1051 }
1052 }
1053 else
1054 {
e74cfd16 1055 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1056 for (i = prec - 1; i >= 0; i--)
1057 {
499ac353
NC
1058 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1059 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1060 }
1061 else
1062 /* For a 4 byte float the order of elements in `words' is 1 0.
1063 For an 8 byte float the order is 1 0 3 2. */
1064 for (i = 0; i < prec; i += 2)
1065 {
499ac353
NC
1066 md_number_to_chars (litP, (valueT) words[i + 1],
1067 sizeof (LITTLENUM_TYPE));
1068 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1069 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1070 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1071 }
1072 }
b99bd4ef 1073
499ac353 1074 return NULL;
c19d1205 1075}
b99bd4ef 1076
c19d1205
ZW
1077/* We handle all bad expressions here, so that we can report the faulty
1078 instruction in the error message. */
1079void
91d6fa6a 1080md_operand (expressionS * exp)
c19d1205
ZW
1081{
1082 if (in_my_get_expression)
91d6fa6a 1083 exp->X_op = O_illegal;
b99bd4ef
NC
1084}
1085
c19d1205 1086/* Immediate values. */
b99bd4ef 1087
c19d1205
ZW
1088/* Generic immediate-value read function for use in directives.
1089 Accepts anything that 'expression' can fold to a constant.
1090 *val receives the number. */
1091#ifdef OBJ_ELF
1092static int
1093immediate_for_directive (int *val)
b99bd4ef 1094{
c19d1205
ZW
1095 expressionS exp;
1096 exp.X_op = O_illegal;
b99bd4ef 1097
c19d1205
ZW
1098 if (is_immediate_prefix (*input_line_pointer))
1099 {
1100 input_line_pointer++;
1101 expression (&exp);
1102 }
b99bd4ef 1103
c19d1205
ZW
1104 if (exp.X_op != O_constant)
1105 {
1106 as_bad (_("expected #constant"));
1107 ignore_rest_of_line ();
1108 return FAIL;
1109 }
1110 *val = exp.X_add_number;
1111 return SUCCESS;
b99bd4ef 1112}
c19d1205 1113#endif
b99bd4ef 1114
c19d1205 1115/* Register parsing. */
b99bd4ef 1116
c19d1205
ZW
1117/* Generic register parser. CCP points to what should be the
1118 beginning of a register name. If it is indeed a valid register
1119 name, advance CCP over it and return the reg_entry structure;
1120 otherwise return NULL. Does not issue diagnostics. */
1121
1122static struct reg_entry *
1123arm_reg_parse_multi (char **ccp)
b99bd4ef 1124{
c19d1205
ZW
1125 char *start = *ccp;
1126 char *p;
1127 struct reg_entry *reg;
b99bd4ef 1128
c19d1205
ZW
1129#ifdef REGISTER_PREFIX
1130 if (*start != REGISTER_PREFIX)
01cfc07f 1131 return NULL;
c19d1205
ZW
1132 start++;
1133#endif
1134#ifdef OPTIONAL_REGISTER_PREFIX
1135 if (*start == OPTIONAL_REGISTER_PREFIX)
1136 start++;
1137#endif
b99bd4ef 1138
c19d1205
ZW
1139 p = start;
1140 if (!ISALPHA (*p) || !is_name_beginner (*p))
1141 return NULL;
b99bd4ef 1142
c19d1205
ZW
1143 do
1144 p++;
1145 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1146
1147 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1148
1149 if (!reg)
1150 return NULL;
1151
1152 *ccp = p;
1153 return reg;
b99bd4ef
NC
1154}
1155
1156static int
dcbf9037
JB
1157arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1158 enum arm_reg_type type)
b99bd4ef 1159{
c19d1205
ZW
1160 /* Alternative syntaxes are accepted for a few register classes. */
1161 switch (type)
1162 {
1163 case REG_TYPE_MVF:
1164 case REG_TYPE_MVD:
1165 case REG_TYPE_MVFX:
1166 case REG_TYPE_MVDX:
1167 /* Generic coprocessor register names are allowed for these. */
79134647 1168 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1169 return reg->number;
1170 break;
69b97547 1171
c19d1205
ZW
1172 case REG_TYPE_CP:
1173 /* For backward compatibility, a bare number is valid here. */
1174 {
1175 unsigned long processor = strtoul (start, ccp, 10);
1176 if (*ccp != start && processor <= 15)
1177 return processor;
1178 }
6057a28f 1179
c19d1205
ZW
1180 case REG_TYPE_MMXWC:
1181 /* WC includes WCG. ??? I'm not sure this is true for all
1182 instructions that take WC registers. */
79134647 1183 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1184 return reg->number;
6057a28f 1185 break;
c19d1205 1186
6057a28f 1187 default:
c19d1205 1188 break;
6057a28f
NC
1189 }
1190
dcbf9037
JB
1191 return FAIL;
1192}
1193
1194/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1195 return value is the register number or FAIL. */
1196
1197static int
1198arm_reg_parse (char **ccp, enum arm_reg_type type)
1199{
1200 char *start = *ccp;
1201 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1202 int ret;
1203
1204 /* Do not allow a scalar (reg+index) to parse as a register. */
1205 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1206 return FAIL;
1207
1208 if (reg && reg->type == type)
1209 return reg->number;
1210
1211 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1212 return ret;
1213
c19d1205
ZW
1214 *ccp = start;
1215 return FAIL;
1216}
69b97547 1217
dcbf9037
JB
1218/* Parse a Neon type specifier. *STR should point at the leading '.'
1219 character. Does no verification at this stage that the type fits the opcode
1220 properly. E.g.,
1221
1222 .i32.i32.s16
1223 .s32.f32
1224 .u16
1225
1226 Can all be legally parsed by this function.
1227
1228 Fills in neon_type struct pointer with parsed information, and updates STR
1229 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1230 type, FAIL if not. */
1231
1232static int
1233parse_neon_type (struct neon_type *type, char **str)
1234{
1235 char *ptr = *str;
1236
1237 if (type)
1238 type->elems = 0;
1239
1240 while (type->elems < NEON_MAX_TYPE_ELS)
1241 {
1242 enum neon_el_type thistype = NT_untyped;
1243 unsigned thissize = -1u;
1244
1245 if (*ptr != '.')
1246 break;
1247
1248 ptr++;
1249
1250 /* Just a size without an explicit type. */
1251 if (ISDIGIT (*ptr))
1252 goto parsesize;
1253
1254 switch (TOLOWER (*ptr))
1255 {
1256 case 'i': thistype = NT_integer; break;
1257 case 'f': thistype = NT_float; break;
1258 case 'p': thistype = NT_poly; break;
1259 case 's': thistype = NT_signed; break;
1260 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1261 case 'd':
1262 thistype = NT_float;
1263 thissize = 64;
1264 ptr++;
1265 goto done;
dcbf9037
JB
1266 default:
1267 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1268 return FAIL;
1269 }
1270
1271 ptr++;
1272
1273 /* .f is an abbreviation for .f32. */
1274 if (thistype == NT_float && !ISDIGIT (*ptr))
1275 thissize = 32;
1276 else
1277 {
1278 parsesize:
1279 thissize = strtoul (ptr, &ptr, 10);
1280
1281 if (thissize != 8 && thissize != 16 && thissize != 32
1282 && thissize != 64)
1283 {
1284 as_bad (_("bad size %d in type specifier"), thissize);
1285 return FAIL;
1286 }
1287 }
1288
037e8744 1289 done:
dcbf9037
JB
1290 if (type)
1291 {
1292 type->el[type->elems].type = thistype;
1293 type->el[type->elems].size = thissize;
1294 type->elems++;
1295 }
1296 }
1297
1298 /* Empty/missing type is not a successful parse. */
1299 if (type->elems == 0)
1300 return FAIL;
1301
1302 *str = ptr;
1303
1304 return SUCCESS;
1305}
1306
1307/* Errors may be set multiple times during parsing or bit encoding
1308 (particularly in the Neon bits), but usually the earliest error which is set
1309 will be the most meaningful. Avoid overwriting it with later (cascading)
1310 errors by calling this function. */
1311
1312static void
1313first_error (const char *err)
1314{
1315 if (!inst.error)
1316 inst.error = err;
1317}
1318
1319/* Parse a single type, e.g. ".s32", leading period included. */
1320static int
1321parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1322{
1323 char *str = *ccp;
1324 struct neon_type optype;
1325
1326 if (*str == '.')
1327 {
1328 if (parse_neon_type (&optype, &str) == SUCCESS)
1329 {
1330 if (optype.elems == 1)
1331 *vectype = optype.el[0];
1332 else
1333 {
1334 first_error (_("only one type should be specified for operand"));
1335 return FAIL;
1336 }
1337 }
1338 else
1339 {
1340 first_error (_("vector type expected"));
1341 return FAIL;
1342 }
1343 }
1344 else
1345 return FAIL;
5f4273c7 1346
dcbf9037 1347 *ccp = str;
5f4273c7 1348
dcbf9037
JB
1349 return SUCCESS;
1350}
1351
1352/* Special meanings for indices (which have a range of 0-7), which will fit into
1353 a 4-bit integer. */
1354
1355#define NEON_ALL_LANES 15
1356#define NEON_INTERLEAVE_LANES 14
1357
1358/* Parse either a register or a scalar, with an optional type. Return the
1359 register number, and optionally fill in the actual type of the register
1360 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1361 type/index information in *TYPEINFO. */
1362
1363static int
1364parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1365 enum arm_reg_type *rtype,
1366 struct neon_typed_alias *typeinfo)
1367{
1368 char *str = *ccp;
1369 struct reg_entry *reg = arm_reg_parse_multi (&str);
1370 struct neon_typed_alias atype;
1371 struct neon_type_el parsetype;
1372
1373 atype.defined = 0;
1374 atype.index = -1;
1375 atype.eltype.type = NT_invtype;
1376 atype.eltype.size = -1;
1377
1378 /* Try alternate syntax for some types of register. Note these are mutually
1379 exclusive with the Neon syntax extensions. */
1380 if (reg == NULL)
1381 {
1382 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1383 if (altreg != FAIL)
1384 *ccp = str;
1385 if (typeinfo)
1386 *typeinfo = atype;
1387 return altreg;
1388 }
1389
037e8744
JB
1390 /* Undo polymorphism when a set of register types may be accepted. */
1391 if ((type == REG_TYPE_NDQ
1392 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1393 || (type == REG_TYPE_VFSD
1394 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1395 || (type == REG_TYPE_NSDQ
1396 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1397 || reg->type == REG_TYPE_NQ))
1398 || (type == REG_TYPE_MMXWC
1399 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1400 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1401
1402 if (type != reg->type)
1403 return FAIL;
1404
1405 if (reg->neon)
1406 atype = *reg->neon;
5f4273c7 1407
dcbf9037
JB
1408 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1409 {
1410 if ((atype.defined & NTA_HASTYPE) != 0)
1411 {
1412 first_error (_("can't redefine type for operand"));
1413 return FAIL;
1414 }
1415 atype.defined |= NTA_HASTYPE;
1416 atype.eltype = parsetype;
1417 }
5f4273c7 1418
dcbf9037
JB
1419 if (skip_past_char (&str, '[') == SUCCESS)
1420 {
1421 if (type != REG_TYPE_VFD)
1422 {
1423 first_error (_("only D registers may be indexed"));
1424 return FAIL;
1425 }
5f4273c7 1426
dcbf9037
JB
1427 if ((atype.defined & NTA_HASINDEX) != 0)
1428 {
1429 first_error (_("can't change index for operand"));
1430 return FAIL;
1431 }
1432
1433 atype.defined |= NTA_HASINDEX;
1434
1435 if (skip_past_char (&str, ']') == SUCCESS)
1436 atype.index = NEON_ALL_LANES;
1437 else
1438 {
1439 expressionS exp;
1440
1441 my_get_expression (&exp, &str, GE_NO_PREFIX);
1442
1443 if (exp.X_op != O_constant)
1444 {
1445 first_error (_("constant expression required"));
1446 return FAIL;
1447 }
1448
1449 if (skip_past_char (&str, ']') == FAIL)
1450 return FAIL;
1451
1452 atype.index = exp.X_add_number;
1453 }
1454 }
5f4273c7 1455
dcbf9037
JB
1456 if (typeinfo)
1457 *typeinfo = atype;
5f4273c7 1458
dcbf9037
JB
1459 if (rtype)
1460 *rtype = type;
5f4273c7 1461
dcbf9037 1462 *ccp = str;
5f4273c7 1463
dcbf9037
JB
1464 return reg->number;
1465}
1466
1467/* Like arm_reg_parse, but allow allow the following extra features:
1468 - If RTYPE is non-zero, return the (possibly restricted) type of the
1469 register (e.g. Neon double or quad reg when either has been requested).
1470 - If this is a Neon vector type with additional type information, fill
1471 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1472 This function will fault on encountering a scalar. */
dcbf9037
JB
1473
1474static int
1475arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1476 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1477{
1478 struct neon_typed_alias atype;
1479 char *str = *ccp;
1480 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1481
1482 if (reg == FAIL)
1483 return FAIL;
1484
0855e32b
NS
1485 /* Do not allow regname(... to parse as a register. */
1486 if (*str == '(')
1487 return FAIL;
1488
dcbf9037
JB
1489 /* Do not allow a scalar (reg+index) to parse as a register. */
1490 if ((atype.defined & NTA_HASINDEX) != 0)
1491 {
1492 first_error (_("register operand expected, but got scalar"));
1493 return FAIL;
1494 }
1495
1496 if (vectype)
1497 *vectype = atype.eltype;
1498
1499 *ccp = str;
1500
1501 return reg;
1502}
1503
1504#define NEON_SCALAR_REG(X) ((X) >> 4)
1505#define NEON_SCALAR_INDEX(X) ((X) & 15)
1506
5287ad62
JB
1507/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1508 have enough information to be able to do a good job bounds-checking. So, we
1509 just do easy checks here, and do further checks later. */
1510
1511static int
dcbf9037 1512parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1513{
dcbf9037 1514 int reg;
5287ad62 1515 char *str = *ccp;
dcbf9037 1516 struct neon_typed_alias atype;
5f4273c7 1517
dcbf9037 1518 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1519
dcbf9037 1520 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1521 return FAIL;
5f4273c7 1522
dcbf9037 1523 if (atype.index == NEON_ALL_LANES)
5287ad62 1524 {
dcbf9037 1525 first_error (_("scalar must have an index"));
5287ad62
JB
1526 return FAIL;
1527 }
dcbf9037 1528 else if (atype.index >= 64 / elsize)
5287ad62 1529 {
dcbf9037 1530 first_error (_("scalar index out of range"));
5287ad62
JB
1531 return FAIL;
1532 }
5f4273c7 1533
dcbf9037
JB
1534 if (type)
1535 *type = atype.eltype;
5f4273c7 1536
5287ad62 1537 *ccp = str;
5f4273c7 1538
dcbf9037 1539 return reg * 16 + atype.index;
5287ad62
JB
1540}
1541
c19d1205 1542/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1543
c19d1205
ZW
1544static long
1545parse_reg_list (char ** strp)
1546{
1547 char * str = * strp;
1548 long range = 0;
1549 int another_range;
a737bd4d 1550
c19d1205
ZW
1551 /* We come back here if we get ranges concatenated by '+' or '|'. */
1552 do
6057a28f 1553 {
c19d1205 1554 another_range = 0;
a737bd4d 1555
c19d1205
ZW
1556 if (*str == '{')
1557 {
1558 int in_range = 0;
1559 int cur_reg = -1;
a737bd4d 1560
c19d1205
ZW
1561 str++;
1562 do
1563 {
1564 int reg;
6057a28f 1565
dcbf9037 1566 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1567 {
dcbf9037 1568 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1569 return FAIL;
1570 }
a737bd4d 1571
c19d1205
ZW
1572 if (in_range)
1573 {
1574 int i;
a737bd4d 1575
c19d1205
ZW
1576 if (reg <= cur_reg)
1577 {
dcbf9037 1578 first_error (_("bad range in register list"));
c19d1205
ZW
1579 return FAIL;
1580 }
40a18ebd 1581
c19d1205
ZW
1582 for (i = cur_reg + 1; i < reg; i++)
1583 {
1584 if (range & (1 << i))
1585 as_tsktsk
1586 (_("Warning: duplicated register (r%d) in register list"),
1587 i);
1588 else
1589 range |= 1 << i;
1590 }
1591 in_range = 0;
1592 }
a737bd4d 1593
c19d1205
ZW
1594 if (range & (1 << reg))
1595 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1596 reg);
1597 else if (reg <= cur_reg)
1598 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1599
c19d1205
ZW
1600 range |= 1 << reg;
1601 cur_reg = reg;
1602 }
1603 while (skip_past_comma (&str) != FAIL
1604 || (in_range = 1, *str++ == '-'));
1605 str--;
a737bd4d 1606
c19d1205
ZW
1607 if (*str++ != '}')
1608 {
dcbf9037 1609 first_error (_("missing `}'"));
c19d1205
ZW
1610 return FAIL;
1611 }
1612 }
1613 else
1614 {
91d6fa6a 1615 expressionS exp;
40a18ebd 1616
91d6fa6a 1617 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1618 return FAIL;
40a18ebd 1619
91d6fa6a 1620 if (exp.X_op == O_constant)
c19d1205 1621 {
91d6fa6a
NC
1622 if (exp.X_add_number
1623 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1624 {
1625 inst.error = _("invalid register mask");
1626 return FAIL;
1627 }
a737bd4d 1628
91d6fa6a 1629 if ((range & exp.X_add_number) != 0)
c19d1205 1630 {
91d6fa6a 1631 int regno = range & exp.X_add_number;
a737bd4d 1632
c19d1205
ZW
1633 regno &= -regno;
1634 regno = (1 << regno) - 1;
1635 as_tsktsk
1636 (_("Warning: duplicated register (r%d) in register list"),
1637 regno);
1638 }
a737bd4d 1639
91d6fa6a 1640 range |= exp.X_add_number;
c19d1205
ZW
1641 }
1642 else
1643 {
1644 if (inst.reloc.type != 0)
1645 {
1646 inst.error = _("expression too complex");
1647 return FAIL;
1648 }
a737bd4d 1649
91d6fa6a 1650 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1651 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1652 inst.reloc.pc_rel = 0;
1653 }
1654 }
a737bd4d 1655
c19d1205
ZW
1656 if (*str == '|' || *str == '+')
1657 {
1658 str++;
1659 another_range = 1;
1660 }
a737bd4d 1661 }
c19d1205 1662 while (another_range);
a737bd4d 1663
c19d1205
ZW
1664 *strp = str;
1665 return range;
a737bd4d
NC
1666}
1667
5287ad62
JB
1668/* Types of registers in a list. */
1669
1670enum reg_list_els
1671{
1672 REGLIST_VFP_S,
1673 REGLIST_VFP_D,
1674 REGLIST_NEON_D
1675};
1676
c19d1205
ZW
1677/* Parse a VFP register list. If the string is invalid return FAIL.
1678 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1679 register. Parses registers of type ETYPE.
1680 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1681 - Q registers can be used to specify pairs of D registers
1682 - { } can be omitted from around a singleton register list
1683 FIXME: This is not implemented, as it would require backtracking in
1684 some cases, e.g.:
1685 vtbl.8 d3,d4,d5
1686 This could be done (the meaning isn't really ambiguous), but doesn't
1687 fit in well with the current parsing framework.
dcbf9037
JB
1688 - 32 D registers may be used (also true for VFPv3).
1689 FIXME: Types are ignored in these register lists, which is probably a
1690 bug. */
6057a28f 1691
c19d1205 1692static int
037e8744 1693parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1694{
037e8744 1695 char *str = *ccp;
c19d1205
ZW
1696 int base_reg;
1697 int new_base;
21d799b5 1698 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1699 int max_regs = 0;
c19d1205
ZW
1700 int count = 0;
1701 int warned = 0;
1702 unsigned long mask = 0;
a737bd4d 1703 int i;
6057a28f 1704
037e8744 1705 if (*str != '{')
5287ad62
JB
1706 {
1707 inst.error = _("expecting {");
1708 return FAIL;
1709 }
6057a28f 1710
037e8744 1711 str++;
6057a28f 1712
5287ad62 1713 switch (etype)
c19d1205 1714 {
5287ad62 1715 case REGLIST_VFP_S:
c19d1205
ZW
1716 regtype = REG_TYPE_VFS;
1717 max_regs = 32;
5287ad62 1718 break;
5f4273c7 1719
5287ad62
JB
1720 case REGLIST_VFP_D:
1721 regtype = REG_TYPE_VFD;
b7fc2769 1722 break;
5f4273c7 1723
b7fc2769
JB
1724 case REGLIST_NEON_D:
1725 regtype = REG_TYPE_NDQ;
1726 break;
1727 }
1728
1729 if (etype != REGLIST_VFP_S)
1730 {
b1cc4aeb
PB
1731 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1732 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1733 {
1734 max_regs = 32;
1735 if (thumb_mode)
1736 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1737 fpu_vfp_ext_d32);
5287ad62
JB
1738 else
1739 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1740 fpu_vfp_ext_d32);
5287ad62
JB
1741 }
1742 else
1743 max_regs = 16;
c19d1205 1744 }
6057a28f 1745
c19d1205 1746 base_reg = max_regs;
a737bd4d 1747
c19d1205
ZW
1748 do
1749 {
5287ad62 1750 int setmask = 1, addregs = 1;
dcbf9037 1751
037e8744 1752 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1753
c19d1205 1754 if (new_base == FAIL)
a737bd4d 1755 {
dcbf9037 1756 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1757 return FAIL;
1758 }
5f4273c7 1759
b7fc2769
JB
1760 if (new_base >= max_regs)
1761 {
1762 first_error (_("register out of range in list"));
1763 return FAIL;
1764 }
5f4273c7 1765
5287ad62
JB
1766 /* Note: a value of 2 * n is returned for the register Q<n>. */
1767 if (regtype == REG_TYPE_NQ)
1768 {
1769 setmask = 3;
1770 addregs = 2;
1771 }
1772
c19d1205
ZW
1773 if (new_base < base_reg)
1774 base_reg = new_base;
a737bd4d 1775
5287ad62 1776 if (mask & (setmask << new_base))
c19d1205 1777 {
dcbf9037 1778 first_error (_("invalid register list"));
c19d1205 1779 return FAIL;
a737bd4d 1780 }
a737bd4d 1781
c19d1205
ZW
1782 if ((mask >> new_base) != 0 && ! warned)
1783 {
1784 as_tsktsk (_("register list not in ascending order"));
1785 warned = 1;
1786 }
0bbf2aa4 1787
5287ad62
JB
1788 mask |= setmask << new_base;
1789 count += addregs;
0bbf2aa4 1790
037e8744 1791 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1792 {
1793 int high_range;
0bbf2aa4 1794
037e8744 1795 str++;
0bbf2aa4 1796
037e8744 1797 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1798 == FAIL)
c19d1205
ZW
1799 {
1800 inst.error = gettext (reg_expected_msgs[regtype]);
1801 return FAIL;
1802 }
0bbf2aa4 1803
b7fc2769
JB
1804 if (high_range >= max_regs)
1805 {
1806 first_error (_("register out of range in list"));
1807 return FAIL;
1808 }
1809
5287ad62
JB
1810 if (regtype == REG_TYPE_NQ)
1811 high_range = high_range + 1;
1812
c19d1205
ZW
1813 if (high_range <= new_base)
1814 {
1815 inst.error = _("register range not in ascending order");
1816 return FAIL;
1817 }
0bbf2aa4 1818
5287ad62 1819 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1820 {
5287ad62 1821 if (mask & (setmask << new_base))
0bbf2aa4 1822 {
c19d1205
ZW
1823 inst.error = _("invalid register list");
1824 return FAIL;
0bbf2aa4 1825 }
c19d1205 1826
5287ad62
JB
1827 mask |= setmask << new_base;
1828 count += addregs;
0bbf2aa4 1829 }
0bbf2aa4 1830 }
0bbf2aa4 1831 }
037e8744 1832 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1833
037e8744 1834 str++;
0bbf2aa4 1835
c19d1205
ZW
1836 /* Sanity check -- should have raised a parse error above. */
1837 if (count == 0 || count > max_regs)
1838 abort ();
1839
1840 *pbase = base_reg;
1841
1842 /* Final test -- the registers must be consecutive. */
1843 mask >>= base_reg;
1844 for (i = 0; i < count; i++)
1845 {
1846 if ((mask & (1u << i)) == 0)
1847 {
1848 inst.error = _("non-contiguous register range");
1849 return FAIL;
1850 }
1851 }
1852
037e8744
JB
1853 *ccp = str;
1854
c19d1205 1855 return count;
b99bd4ef
NC
1856}
1857
dcbf9037
JB
1858/* True if two alias types are the same. */
1859
c921be7d 1860static bfd_boolean
dcbf9037
JB
1861neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1862{
1863 if (!a && !b)
c921be7d 1864 return TRUE;
5f4273c7 1865
dcbf9037 1866 if (!a || !b)
c921be7d 1867 return FALSE;
dcbf9037
JB
1868
1869 if (a->defined != b->defined)
c921be7d 1870 return FALSE;
5f4273c7 1871
dcbf9037
JB
1872 if ((a->defined & NTA_HASTYPE) != 0
1873 && (a->eltype.type != b->eltype.type
1874 || a->eltype.size != b->eltype.size))
c921be7d 1875 return FALSE;
dcbf9037
JB
1876
1877 if ((a->defined & NTA_HASINDEX) != 0
1878 && (a->index != b->index))
c921be7d 1879 return FALSE;
5f4273c7 1880
c921be7d 1881 return TRUE;
dcbf9037
JB
1882}
1883
5287ad62
JB
1884/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1885 The base register is put in *PBASE.
dcbf9037 1886 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1887 the return value.
1888 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1889 Bits [6:5] encode the list length (minus one).
1890 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1891
5287ad62 1892#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1893#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1894#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1895
1896static int
dcbf9037
JB
1897parse_neon_el_struct_list (char **str, unsigned *pbase,
1898 struct neon_type_el *eltype)
5287ad62
JB
1899{
1900 char *ptr = *str;
1901 int base_reg = -1;
1902 int reg_incr = -1;
1903 int count = 0;
1904 int lane = -1;
1905 int leading_brace = 0;
1906 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1907 const char *const incr_error = _("register stride must be 1 or 2");
1908 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1909 struct neon_typed_alias firsttype;
5f4273c7 1910
5287ad62
JB
1911 if (skip_past_char (&ptr, '{') == SUCCESS)
1912 leading_brace = 1;
5f4273c7 1913
5287ad62
JB
1914 do
1915 {
dcbf9037
JB
1916 struct neon_typed_alias atype;
1917 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1918
5287ad62
JB
1919 if (getreg == FAIL)
1920 {
dcbf9037 1921 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1922 return FAIL;
1923 }
5f4273c7 1924
5287ad62
JB
1925 if (base_reg == -1)
1926 {
1927 base_reg = getreg;
1928 if (rtype == REG_TYPE_NQ)
1929 {
1930 reg_incr = 1;
5287ad62 1931 }
dcbf9037 1932 firsttype = atype;
5287ad62
JB
1933 }
1934 else if (reg_incr == -1)
1935 {
1936 reg_incr = getreg - base_reg;
1937 if (reg_incr < 1 || reg_incr > 2)
1938 {
dcbf9037 1939 first_error (_(incr_error));
5287ad62
JB
1940 return FAIL;
1941 }
1942 }
1943 else if (getreg != base_reg + reg_incr * count)
1944 {
dcbf9037
JB
1945 first_error (_(incr_error));
1946 return FAIL;
1947 }
1948
c921be7d 1949 if (! neon_alias_types_same (&atype, &firsttype))
dcbf9037
JB
1950 {
1951 first_error (_(type_error));
5287ad62
JB
1952 return FAIL;
1953 }
5f4273c7 1954
5287ad62
JB
1955 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1956 modes. */
1957 if (ptr[0] == '-')
1958 {
dcbf9037 1959 struct neon_typed_alias htype;
5287ad62
JB
1960 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1961 if (lane == -1)
1962 lane = NEON_INTERLEAVE_LANES;
1963 else if (lane != NEON_INTERLEAVE_LANES)
1964 {
dcbf9037 1965 first_error (_(type_error));
5287ad62
JB
1966 return FAIL;
1967 }
1968 if (reg_incr == -1)
1969 reg_incr = 1;
1970 else if (reg_incr != 1)
1971 {
dcbf9037 1972 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1973 return FAIL;
1974 }
1975 ptr++;
dcbf9037 1976 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1977 if (hireg == FAIL)
1978 {
dcbf9037
JB
1979 first_error (_(reg_expected_msgs[rtype]));
1980 return FAIL;
1981 }
c921be7d 1982 if (! neon_alias_types_same (&htype, &firsttype))
dcbf9037
JB
1983 {
1984 first_error (_(type_error));
5287ad62
JB
1985 return FAIL;
1986 }
1987 count += hireg + dregs - getreg;
1988 continue;
1989 }
5f4273c7 1990
5287ad62
JB
1991 /* If we're using Q registers, we can't use [] or [n] syntax. */
1992 if (rtype == REG_TYPE_NQ)
1993 {
1994 count += 2;
1995 continue;
1996 }
5f4273c7 1997
dcbf9037 1998 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1999 {
dcbf9037
JB
2000 if (lane == -1)
2001 lane = atype.index;
2002 else if (lane != atype.index)
5287ad62 2003 {
dcbf9037
JB
2004 first_error (_(type_error));
2005 return FAIL;
5287ad62
JB
2006 }
2007 }
2008 else if (lane == -1)
2009 lane = NEON_INTERLEAVE_LANES;
2010 else if (lane != NEON_INTERLEAVE_LANES)
2011 {
dcbf9037 2012 first_error (_(type_error));
5287ad62
JB
2013 return FAIL;
2014 }
2015 count++;
2016 }
2017 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2018
5287ad62
JB
2019 /* No lane set by [x]. We must be interleaving structures. */
2020 if (lane == -1)
2021 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2022
5287ad62
JB
2023 /* Sanity check. */
2024 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2025 || (count > 1 && reg_incr == -1))
2026 {
dcbf9037 2027 first_error (_("error parsing element/structure list"));
5287ad62
JB
2028 return FAIL;
2029 }
2030
2031 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2032 {
dcbf9037 2033 first_error (_("expected }"));
5287ad62
JB
2034 return FAIL;
2035 }
5f4273c7 2036
5287ad62
JB
2037 if (reg_incr == -1)
2038 reg_incr = 1;
2039
dcbf9037
JB
2040 if (eltype)
2041 *eltype = firsttype.eltype;
2042
5287ad62
JB
2043 *pbase = base_reg;
2044 *str = ptr;
5f4273c7 2045
5287ad62
JB
2046 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2047}
2048
c19d1205
ZW
2049/* Parse an explicit relocation suffix on an expression. This is
2050 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2051 arm_reloc_hsh contains no entries, so this function can only
2052 succeed if there is no () after the word. Returns -1 on error,
2053 BFD_RELOC_UNUSED if there wasn't any suffix. */
2054static int
2055parse_reloc (char **str)
b99bd4ef 2056{
c19d1205
ZW
2057 struct reloc_entry *r;
2058 char *p, *q;
b99bd4ef 2059
c19d1205
ZW
2060 if (**str != '(')
2061 return BFD_RELOC_UNUSED;
b99bd4ef 2062
c19d1205
ZW
2063 p = *str + 1;
2064 q = p;
2065
2066 while (*q && *q != ')' && *q != ',')
2067 q++;
2068 if (*q != ')')
2069 return -1;
2070
21d799b5
NC
2071 if ((r = (struct reloc_entry *)
2072 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2073 return -1;
2074
2075 *str = q + 1;
2076 return r->reloc;
b99bd4ef
NC
2077}
2078
c19d1205
ZW
2079/* Directives: register aliases. */
2080
dcbf9037 2081static struct reg_entry *
90ec0d68 2082insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2083{
d3ce72d0 2084 struct reg_entry *new_reg;
c19d1205 2085 const char *name;
b99bd4ef 2086
d3ce72d0 2087 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2088 {
d3ce72d0 2089 if (new_reg->builtin)
c19d1205 2090 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2091
c19d1205
ZW
2092 /* Only warn about a redefinition if it's not defined as the
2093 same register. */
d3ce72d0 2094 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2095 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2096
d929913e 2097 return NULL;
c19d1205 2098 }
b99bd4ef 2099
c19d1205 2100 name = xstrdup (str);
d3ce72d0 2101 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2102
d3ce72d0
NC
2103 new_reg->name = name;
2104 new_reg->number = number;
2105 new_reg->type = type;
2106 new_reg->builtin = FALSE;
2107 new_reg->neon = NULL;
b99bd4ef 2108
d3ce72d0 2109 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2110 abort ();
5f4273c7 2111
d3ce72d0 2112 return new_reg;
dcbf9037
JB
2113}
2114
2115static void
2116insert_neon_reg_alias (char *str, int number, int type,
2117 struct neon_typed_alias *atype)
2118{
2119 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2120
dcbf9037
JB
2121 if (!reg)
2122 {
2123 first_error (_("attempt to redefine typed alias"));
2124 return;
2125 }
5f4273c7 2126
dcbf9037
JB
2127 if (atype)
2128 {
21d799b5
NC
2129 reg->neon = (struct neon_typed_alias *)
2130 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2131 *reg->neon = *atype;
2132 }
c19d1205 2133}
b99bd4ef 2134
c19d1205 2135/* Look for the .req directive. This is of the form:
b99bd4ef 2136
c19d1205 2137 new_register_name .req existing_register_name
b99bd4ef 2138
c19d1205 2139 If we find one, or if it looks sufficiently like one that we want to
d929913e 2140 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2141
d929913e 2142static bfd_boolean
c19d1205
ZW
2143create_register_alias (char * newname, char *p)
2144{
2145 struct reg_entry *old;
2146 char *oldname, *nbuf;
2147 size_t nlen;
b99bd4ef 2148
c19d1205
ZW
2149 /* The input scrubber ensures that whitespace after the mnemonic is
2150 collapsed to single spaces. */
2151 oldname = p;
2152 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2153 return FALSE;
b99bd4ef 2154
c19d1205
ZW
2155 oldname += 6;
2156 if (*oldname == '\0')
d929913e 2157 return FALSE;
b99bd4ef 2158
21d799b5 2159 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2160 if (!old)
b99bd4ef 2161 {
c19d1205 2162 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2163 return TRUE;
b99bd4ef
NC
2164 }
2165
c19d1205
ZW
2166 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2167 the desired alias name, and p points to its end. If not, then
2168 the desired alias name is in the global original_case_string. */
2169#ifdef TC_CASE_SENSITIVE
2170 nlen = p - newname;
2171#else
2172 newname = original_case_string;
2173 nlen = strlen (newname);
2174#endif
b99bd4ef 2175
21d799b5 2176 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2177 memcpy (nbuf, newname, nlen);
2178 nbuf[nlen] = '\0';
b99bd4ef 2179
c19d1205
ZW
2180 /* Create aliases under the new name as stated; an all-lowercase
2181 version of the new name; and an all-uppercase version of the new
2182 name. */
d929913e
NC
2183 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2184 {
2185 for (p = nbuf; *p; p++)
2186 *p = TOUPPER (*p);
c19d1205 2187
d929913e
NC
2188 if (strncmp (nbuf, newname, nlen))
2189 {
2190 /* If this attempt to create an additional alias fails, do not bother
2191 trying to create the all-lower case alias. We will fail and issue
2192 a second, duplicate error message. This situation arises when the
2193 programmer does something like:
2194 foo .req r0
2195 Foo .req r1
2196 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2197 the artificial FOO alias because it has already been created by the
d929913e
NC
2198 first .req. */
2199 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2200 return TRUE;
2201 }
c19d1205 2202
d929913e
NC
2203 for (p = nbuf; *p; p++)
2204 *p = TOLOWER (*p);
c19d1205 2205
d929913e
NC
2206 if (strncmp (nbuf, newname, nlen))
2207 insert_reg_alias (nbuf, old->number, old->type);
2208 }
c19d1205 2209
d929913e 2210 return TRUE;
b99bd4ef
NC
2211}
2212
dcbf9037
JB
2213/* Create a Neon typed/indexed register alias using directives, e.g.:
2214 X .dn d5.s32[1]
2215 Y .qn 6.s16
2216 Z .dn d7
2217 T .dn Z[0]
2218 These typed registers can be used instead of the types specified after the
2219 Neon mnemonic, so long as all operands given have types. Types can also be
2220 specified directly, e.g.:
5f4273c7 2221 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2222
c921be7d 2223static bfd_boolean
dcbf9037
JB
2224create_neon_reg_alias (char *newname, char *p)
2225{
2226 enum arm_reg_type basetype;
2227 struct reg_entry *basereg;
2228 struct reg_entry mybasereg;
2229 struct neon_type ntype;
2230 struct neon_typed_alias typeinfo;
12d6b0b7 2231 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2232 int namelen;
5f4273c7 2233
dcbf9037
JB
2234 typeinfo.defined = 0;
2235 typeinfo.eltype.type = NT_invtype;
2236 typeinfo.eltype.size = -1;
2237 typeinfo.index = -1;
5f4273c7 2238
dcbf9037 2239 nameend = p;
5f4273c7 2240
dcbf9037
JB
2241 if (strncmp (p, " .dn ", 5) == 0)
2242 basetype = REG_TYPE_VFD;
2243 else if (strncmp (p, " .qn ", 5) == 0)
2244 basetype = REG_TYPE_NQ;
2245 else
c921be7d 2246 return FALSE;
5f4273c7 2247
dcbf9037 2248 p += 5;
5f4273c7 2249
dcbf9037 2250 if (*p == '\0')
c921be7d 2251 return FALSE;
5f4273c7 2252
dcbf9037
JB
2253 basereg = arm_reg_parse_multi (&p);
2254
2255 if (basereg && basereg->type != basetype)
2256 {
2257 as_bad (_("bad type for register"));
c921be7d 2258 return FALSE;
dcbf9037
JB
2259 }
2260
2261 if (basereg == NULL)
2262 {
2263 expressionS exp;
2264 /* Try parsing as an integer. */
2265 my_get_expression (&exp, &p, GE_NO_PREFIX);
2266 if (exp.X_op != O_constant)
2267 {
2268 as_bad (_("expression must be constant"));
c921be7d 2269 return FALSE;
dcbf9037
JB
2270 }
2271 basereg = &mybasereg;
2272 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2273 : exp.X_add_number;
2274 basereg->neon = 0;
2275 }
2276
2277 if (basereg->neon)
2278 typeinfo = *basereg->neon;
2279
2280 if (parse_neon_type (&ntype, &p) == SUCCESS)
2281 {
2282 /* We got a type. */
2283 if (typeinfo.defined & NTA_HASTYPE)
2284 {
2285 as_bad (_("can't redefine the type of a register alias"));
c921be7d 2286 return FALSE;
dcbf9037 2287 }
5f4273c7 2288
dcbf9037
JB
2289 typeinfo.defined |= NTA_HASTYPE;
2290 if (ntype.elems != 1)
2291 {
2292 as_bad (_("you must specify a single type only"));
c921be7d 2293 return FALSE;
dcbf9037
JB
2294 }
2295 typeinfo.eltype = ntype.el[0];
2296 }
5f4273c7 2297
dcbf9037
JB
2298 if (skip_past_char (&p, '[') == SUCCESS)
2299 {
2300 expressionS exp;
2301 /* We got a scalar index. */
5f4273c7 2302
dcbf9037
JB
2303 if (typeinfo.defined & NTA_HASINDEX)
2304 {
2305 as_bad (_("can't redefine the index of a scalar alias"));
c921be7d 2306 return FALSE;
dcbf9037 2307 }
5f4273c7 2308
dcbf9037 2309 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2310
dcbf9037
JB
2311 if (exp.X_op != O_constant)
2312 {
2313 as_bad (_("scalar index must be constant"));
c921be7d 2314 return FALSE;
dcbf9037 2315 }
5f4273c7 2316
dcbf9037
JB
2317 typeinfo.defined |= NTA_HASINDEX;
2318 typeinfo.index = exp.X_add_number;
5f4273c7 2319
dcbf9037
JB
2320 if (skip_past_char (&p, ']') == FAIL)
2321 {
2322 as_bad (_("expecting ]"));
c921be7d 2323 return FALSE;
dcbf9037
JB
2324 }
2325 }
2326
15735687
NS
2327 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2328 the desired alias name, and p points to its end. If not, then
2329 the desired alias name is in the global original_case_string. */
2330#ifdef TC_CASE_SENSITIVE
dcbf9037 2331 namelen = nameend - newname;
15735687
NS
2332#else
2333 newname = original_case_string;
2334 namelen = strlen (newname);
2335#endif
2336
21d799b5 2337 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2338 strncpy (namebuf, newname, namelen);
2339 namebuf[namelen] = '\0';
5f4273c7 2340
dcbf9037
JB
2341 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2342 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2343
dcbf9037
JB
2344 /* Insert name in all uppercase. */
2345 for (p = namebuf; *p; p++)
2346 *p = TOUPPER (*p);
5f4273c7 2347
dcbf9037
JB
2348 if (strncmp (namebuf, newname, namelen))
2349 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2350 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2351
dcbf9037
JB
2352 /* Insert name in all lowercase. */
2353 for (p = namebuf; *p; p++)
2354 *p = TOLOWER (*p);
5f4273c7 2355
dcbf9037
JB
2356 if (strncmp (namebuf, newname, namelen))
2357 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2358 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2359
c921be7d 2360 return TRUE;
dcbf9037
JB
2361}
2362
c19d1205
ZW
2363/* Should never be called, as .req goes between the alias and the
2364 register name, not at the beginning of the line. */
c921be7d 2365
b99bd4ef 2366static void
c19d1205 2367s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2368{
c19d1205
ZW
2369 as_bad (_("invalid syntax for .req directive"));
2370}
b99bd4ef 2371
dcbf9037
JB
2372static void
2373s_dn (int a ATTRIBUTE_UNUSED)
2374{
2375 as_bad (_("invalid syntax for .dn directive"));
2376}
2377
2378static void
2379s_qn (int a ATTRIBUTE_UNUSED)
2380{
2381 as_bad (_("invalid syntax for .qn directive"));
2382}
2383
c19d1205
ZW
2384/* The .unreq directive deletes an alias which was previously defined
2385 by .req. For example:
b99bd4ef 2386
c19d1205
ZW
2387 my_alias .req r11
2388 .unreq my_alias */
b99bd4ef
NC
2389
2390static void
c19d1205 2391s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2392{
c19d1205
ZW
2393 char * name;
2394 char saved_char;
b99bd4ef 2395
c19d1205
ZW
2396 name = input_line_pointer;
2397
2398 while (*input_line_pointer != 0
2399 && *input_line_pointer != ' '
2400 && *input_line_pointer != '\n')
2401 ++input_line_pointer;
2402
2403 saved_char = *input_line_pointer;
2404 *input_line_pointer = 0;
2405
2406 if (!*name)
2407 as_bad (_("invalid syntax for .unreq directive"));
2408 else
2409 {
21d799b5
NC
2410 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2411 name);
c19d1205
ZW
2412
2413 if (!reg)
2414 as_bad (_("unknown register alias '%s'"), name);
2415 else if (reg->builtin)
a1727c1a 2416 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2417 name);
2418 else
2419 {
d929913e
NC
2420 char * p;
2421 char * nbuf;
2422
db0bc284 2423 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2424 free ((char *) reg->name);
dcbf9037
JB
2425 if (reg->neon)
2426 free (reg->neon);
c19d1205 2427 free (reg);
d929913e
NC
2428
2429 /* Also locate the all upper case and all lower case versions.
2430 Do not complain if we cannot find one or the other as it
2431 was probably deleted above. */
5f4273c7 2432
d929913e
NC
2433 nbuf = strdup (name);
2434 for (p = nbuf; *p; p++)
2435 *p = TOUPPER (*p);
21d799b5 2436 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2437 if (reg)
2438 {
db0bc284 2439 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2440 free ((char *) reg->name);
2441 if (reg->neon)
2442 free (reg->neon);
2443 free (reg);
2444 }
2445
2446 for (p = nbuf; *p; p++)
2447 *p = TOLOWER (*p);
21d799b5 2448 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2449 if (reg)
2450 {
db0bc284 2451 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2452 free ((char *) reg->name);
2453 if (reg->neon)
2454 free (reg->neon);
2455 free (reg);
2456 }
2457
2458 free (nbuf);
c19d1205
ZW
2459 }
2460 }
b99bd4ef 2461
c19d1205 2462 *input_line_pointer = saved_char;
b99bd4ef
NC
2463 demand_empty_rest_of_line ();
2464}
2465
c19d1205
ZW
2466/* Directives: Instruction set selection. */
2467
2468#ifdef OBJ_ELF
2469/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2470 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2471 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2472 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2473
cd000bff
DJ
2474/* Create a new mapping symbol for the transition to STATE. */
2475
2476static void
2477make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2478{
a737bd4d 2479 symbolS * symbolP;
c19d1205
ZW
2480 const char * symname;
2481 int type;
b99bd4ef 2482
c19d1205 2483 switch (state)
b99bd4ef 2484 {
c19d1205
ZW
2485 case MAP_DATA:
2486 symname = "$d";
2487 type = BSF_NO_FLAGS;
2488 break;
2489 case MAP_ARM:
2490 symname = "$a";
2491 type = BSF_NO_FLAGS;
2492 break;
2493 case MAP_THUMB:
2494 symname = "$t";
2495 type = BSF_NO_FLAGS;
2496 break;
c19d1205
ZW
2497 default:
2498 abort ();
2499 }
2500
cd000bff 2501 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2502 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2503
2504 switch (state)
2505 {
2506 case MAP_ARM:
2507 THUMB_SET_FUNC (symbolP, 0);
2508 ARM_SET_THUMB (symbolP, 0);
2509 ARM_SET_INTERWORK (symbolP, support_interwork);
2510 break;
2511
2512 case MAP_THUMB:
2513 THUMB_SET_FUNC (symbolP, 1);
2514 ARM_SET_THUMB (symbolP, 1);
2515 ARM_SET_INTERWORK (symbolP, support_interwork);
2516 break;
2517
2518 case MAP_DATA:
2519 default:
cd000bff
DJ
2520 break;
2521 }
2522
2523 /* Save the mapping symbols for future reference. Also check that
2524 we do not place two mapping symbols at the same offset within a
2525 frag. We'll handle overlap between frags in
2de7820f
JZ
2526 check_mapping_symbols.
2527
2528 If .fill or other data filling directive generates zero sized data,
2529 the mapping symbol for the following code will have the same value
2530 as the one generated for the data filling directive. In this case,
2531 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2532 if (value == 0)
2533 {
2de7820f
JZ
2534 if (frag->tc_frag_data.first_map != NULL)
2535 {
2536 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2537 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2538 }
cd000bff
DJ
2539 frag->tc_frag_data.first_map = symbolP;
2540 }
2541 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2542 {
2543 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2544 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2545 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2546 }
cd000bff
DJ
2547 frag->tc_frag_data.last_map = symbolP;
2548}
2549
2550/* We must sometimes convert a region marked as code to data during
2551 code alignment, if an odd number of bytes have to be padded. The
2552 code mapping symbol is pushed to an aligned address. */
2553
2554static void
2555insert_data_mapping_symbol (enum mstate state,
2556 valueT value, fragS *frag, offsetT bytes)
2557{
2558 /* If there was already a mapping symbol, remove it. */
2559 if (frag->tc_frag_data.last_map != NULL
2560 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2561 {
2562 symbolS *symp = frag->tc_frag_data.last_map;
2563
2564 if (value == 0)
2565 {
2566 know (frag->tc_frag_data.first_map == symp);
2567 frag->tc_frag_data.first_map = NULL;
2568 }
2569 frag->tc_frag_data.last_map = NULL;
2570 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2571 }
cd000bff
DJ
2572
2573 make_mapping_symbol (MAP_DATA, value, frag);
2574 make_mapping_symbol (state, value + bytes, frag);
2575}
2576
2577static void mapping_state_2 (enum mstate state, int max_chars);
2578
2579/* Set the mapping state to STATE. Only call this when about to
2580 emit some STATE bytes to the file. */
2581
2582void
2583mapping_state (enum mstate state)
2584{
940b5ce0
DJ
2585 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2586
cd000bff
DJ
2587#define TRANSITION(from, to) (mapstate == (from) && state == (to))
2588
2589 if (mapstate == state)
2590 /* The mapping symbol has already been emitted.
2591 There is nothing else to do. */
2592 return;
49c62a33
NC
2593
2594 if (state == MAP_ARM || state == MAP_THUMB)
2595 /* PR gas/12931
2596 All ARM instructions require 4-byte alignment.
2597 (Almost) all Thumb instructions require 2-byte alignment.
2598
2599 When emitting instructions into any section, mark the section
2600 appropriately.
2601
2602 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2603 but themselves require 2-byte alignment; this applies to some
2604 PC- relative forms. However, these cases will invovle implicit
2605 literal pool generation or an explicit .align >=2, both of
2606 which will cause the section to me marked with sufficient
2607 alignment. Thus, we don't handle those cases here. */
2608 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2609
2610 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
cd000bff
DJ
2611 /* This case will be evaluated later in the next else. */
2612 return;
2613 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2614 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2615 {
2616 /* Only add the symbol if the offset is > 0:
2617 if we're at the first frag, check it's size > 0;
2618 if we're not at the first frag, then for sure
2619 the offset is > 0. */
2620 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2621 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2622
2623 if (add_symbol)
2624 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2625 }
2626
2627 mapping_state_2 (state, 0);
2628#undef TRANSITION
2629}
2630
2631/* Same as mapping_state, but MAX_CHARS bytes have already been
2632 allocated. Put the mapping symbol that far back. */
2633
2634static void
2635mapping_state_2 (enum mstate state, int max_chars)
2636{
940b5ce0
DJ
2637 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2638
2639 if (!SEG_NORMAL (now_seg))
2640 return;
2641
cd000bff
DJ
2642 if (mapstate == state)
2643 /* The mapping symbol has already been emitted.
2644 There is nothing else to do. */
2645 return;
2646
cd000bff
DJ
2647 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2648 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205
ZW
2649}
2650#else
d3106081
NS
2651#define mapping_state(x) ((void)0)
2652#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2653#endif
2654
2655/* Find the real, Thumb encoded start of a Thumb function. */
2656
4343666d 2657#ifdef OBJ_COFF
c19d1205
ZW
2658static symbolS *
2659find_real_start (symbolS * symbolP)
2660{
2661 char * real_start;
2662 const char * name = S_GET_NAME (symbolP);
2663 symbolS * new_target;
2664
2665 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2666#define STUB_NAME ".real_start_of"
2667
2668 if (name == NULL)
2669 abort ();
2670
37f6032b
ZW
2671 /* The compiler may generate BL instructions to local labels because
2672 it needs to perform a branch to a far away location. These labels
2673 do not have a corresponding ".real_start_of" label. We check
2674 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2675 the ".real_start_of" convention for nonlocal branches. */
2676 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2677 return symbolP;
2678
37f6032b 2679 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2680 new_target = symbol_find (real_start);
2681
2682 if (new_target == NULL)
2683 {
bd3ba5d1 2684 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2685 new_target = symbolP;
2686 }
2687
c19d1205
ZW
2688 return new_target;
2689}
4343666d 2690#endif
c19d1205
ZW
2691
2692static void
2693opcode_select (int width)
2694{
2695 switch (width)
2696 {
2697 case 16:
2698 if (! thumb_mode)
2699 {
e74cfd16 2700 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2701 as_bad (_("selected processor does not support THUMB opcodes"));
2702
2703 thumb_mode = 1;
2704 /* No need to force the alignment, since we will have been
2705 coming from ARM mode, which is word-aligned. */
2706 record_alignment (now_seg, 1);
2707 }
c19d1205
ZW
2708 break;
2709
2710 case 32:
2711 if (thumb_mode)
2712 {
e74cfd16 2713 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2714 as_bad (_("selected processor does not support ARM opcodes"));
2715
2716 thumb_mode = 0;
2717
2718 if (!need_pass_2)
2719 frag_align (2, 0, 0);
2720
2721 record_alignment (now_seg, 1);
2722 }
c19d1205
ZW
2723 break;
2724
2725 default:
2726 as_bad (_("invalid instruction size selected (%d)"), width);
2727 }
2728}
2729
2730static void
2731s_arm (int ignore ATTRIBUTE_UNUSED)
2732{
2733 opcode_select (32);
2734 demand_empty_rest_of_line ();
2735}
2736
2737static void
2738s_thumb (int ignore ATTRIBUTE_UNUSED)
2739{
2740 opcode_select (16);
2741 demand_empty_rest_of_line ();
2742}
2743
2744static void
2745s_code (int unused ATTRIBUTE_UNUSED)
2746{
2747 int temp;
2748
2749 temp = get_absolute_expression ();
2750 switch (temp)
2751 {
2752 case 16:
2753 case 32:
2754 opcode_select (temp);
2755 break;
2756
2757 default:
2758 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2759 }
2760}
2761
2762static void
2763s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2764{
2765 /* If we are not already in thumb mode go into it, EVEN if
2766 the target processor does not support thumb instructions.
2767 This is used by gcc/config/arm/lib1funcs.asm for example
2768 to compile interworking support functions even if the
2769 target processor should not support interworking. */
2770 if (! thumb_mode)
2771 {
2772 thumb_mode = 2;
2773 record_alignment (now_seg, 1);
2774 }
2775
2776 demand_empty_rest_of_line ();
2777}
2778
2779static void
2780s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2781{
2782 s_thumb (0);
2783
2784 /* The following label is the name/address of the start of a Thumb function.
2785 We need to know this for the interworking support. */
2786 label_is_thumb_function_name = TRUE;
2787}
2788
2789/* Perform a .set directive, but also mark the alias as
2790 being a thumb function. */
2791
2792static void
2793s_thumb_set (int equiv)
2794{
2795 /* XXX the following is a duplicate of the code for s_set() in read.c
2796 We cannot just call that code as we need to get at the symbol that
2797 is created. */
2798 char * name;
2799 char delim;
2800 char * end_name;
2801 symbolS * symbolP;
2802
2803 /* Especial apologies for the random logic:
2804 This just grew, and could be parsed much more simply!
2805 Dean - in haste. */
2806 name = input_line_pointer;
2807 delim = get_symbol_end ();
2808 end_name = input_line_pointer;
2809 *end_name = delim;
2810
2811 if (*input_line_pointer != ',')
2812 {
2813 *end_name = 0;
2814 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2815 *end_name = delim;
2816 ignore_rest_of_line ();
2817 return;
2818 }
2819
2820 input_line_pointer++;
2821 *end_name = 0;
2822
2823 if (name[0] == '.' && name[1] == '\0')
2824 {
2825 /* XXX - this should not happen to .thumb_set. */
2826 abort ();
2827 }
2828
2829 if ((symbolP = symbol_find (name)) == NULL
2830 && (symbolP = md_undefined_symbol (name)) == NULL)
2831 {
2832#ifndef NO_LISTING
2833 /* When doing symbol listings, play games with dummy fragments living
2834 outside the normal fragment chain to record the file and line info
c19d1205 2835 for this symbol. */
b99bd4ef
NC
2836 if (listing & LISTING_SYMBOLS)
2837 {
2838 extern struct list_info_struct * listing_tail;
21d799b5 2839 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2840
2841 memset (dummy_frag, 0, sizeof (fragS));
2842 dummy_frag->fr_type = rs_fill;
2843 dummy_frag->line = listing_tail;
2844 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2845 dummy_frag->fr_symbol = symbolP;
2846 }
2847 else
2848#endif
2849 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2850
2851#ifdef OBJ_COFF
2852 /* "set" symbols are local unless otherwise specified. */
2853 SF_SET_LOCAL (symbolP);
2854#endif /* OBJ_COFF */
2855 } /* Make a new symbol. */
2856
2857 symbol_table_insert (symbolP);
2858
2859 * end_name = delim;
2860
2861 if (equiv
2862 && S_IS_DEFINED (symbolP)
2863 && S_GET_SEGMENT (symbolP) != reg_section)
2864 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2865
2866 pseudo_set (symbolP);
2867
2868 demand_empty_rest_of_line ();
2869
c19d1205 2870 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2871
2872 THUMB_SET_FUNC (symbolP, 1);
2873 ARM_SET_THUMB (symbolP, 1);
2874#if defined OBJ_ELF || defined OBJ_COFF
2875 ARM_SET_INTERWORK (symbolP, support_interwork);
2876#endif
2877}
2878
c19d1205 2879/* Directives: Mode selection. */
b99bd4ef 2880
c19d1205
ZW
2881/* .syntax [unified|divided] - choose the new unified syntax
2882 (same for Arm and Thumb encoding, modulo slight differences in what
2883 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2884static void
c19d1205 2885s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2886{
c19d1205
ZW
2887 char *name, delim;
2888
2889 name = input_line_pointer;
2890 delim = get_symbol_end ();
2891
2892 if (!strcasecmp (name, "unified"))
2893 unified_syntax = TRUE;
2894 else if (!strcasecmp (name, "divided"))
2895 unified_syntax = FALSE;
2896 else
2897 {
2898 as_bad (_("unrecognized syntax mode \"%s\""), name);
2899 return;
2900 }
2901 *input_line_pointer = delim;
b99bd4ef
NC
2902 demand_empty_rest_of_line ();
2903}
2904
c19d1205
ZW
2905/* Directives: sectioning and alignment. */
2906
2907/* Same as s_align_ptwo but align 0 => align 2. */
2908
b99bd4ef 2909static void
c19d1205 2910s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2911{
a737bd4d 2912 int temp;
dce323d1 2913 bfd_boolean fill_p;
c19d1205
ZW
2914 long temp_fill;
2915 long max_alignment = 15;
b99bd4ef
NC
2916
2917 temp = get_absolute_expression ();
c19d1205
ZW
2918 if (temp > max_alignment)
2919 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2920 else if (temp < 0)
b99bd4ef 2921 {
c19d1205
ZW
2922 as_bad (_("alignment negative. 0 assumed."));
2923 temp = 0;
2924 }
b99bd4ef 2925
c19d1205
ZW
2926 if (*input_line_pointer == ',')
2927 {
2928 input_line_pointer++;
2929 temp_fill = get_absolute_expression ();
dce323d1 2930 fill_p = TRUE;
b99bd4ef 2931 }
c19d1205 2932 else
dce323d1
PB
2933 {
2934 fill_p = FALSE;
2935 temp_fill = 0;
2936 }
b99bd4ef 2937
c19d1205
ZW
2938 if (!temp)
2939 temp = 2;
b99bd4ef 2940
c19d1205
ZW
2941 /* Only make a frag if we HAVE to. */
2942 if (temp && !need_pass_2)
dce323d1
PB
2943 {
2944 if (!fill_p && subseg_text_p (now_seg))
2945 frag_align_code (temp, 0);
2946 else
2947 frag_align (temp, (int) temp_fill, 0);
2948 }
c19d1205
ZW
2949 demand_empty_rest_of_line ();
2950
2951 record_alignment (now_seg, temp);
b99bd4ef
NC
2952}
2953
c19d1205
ZW
2954static void
2955s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2956{
c19d1205
ZW
2957 /* We don't support putting frags in the BSS segment, we fake it by
2958 marking in_bss, then looking at s_skip for clues. */
2959 subseg_set (bss_section, 0);
2960 demand_empty_rest_of_line ();
cd000bff
DJ
2961
2962#ifdef md_elf_section_change_hook
2963 md_elf_section_change_hook ();
2964#endif
c19d1205 2965}
b99bd4ef 2966
c19d1205
ZW
2967static void
2968s_even (int ignore ATTRIBUTE_UNUSED)
2969{
2970 /* Never make frag if expect extra pass. */
2971 if (!need_pass_2)
2972 frag_align (1, 0, 0);
b99bd4ef 2973
c19d1205 2974 record_alignment (now_seg, 1);
b99bd4ef 2975
c19d1205 2976 demand_empty_rest_of_line ();
b99bd4ef
NC
2977}
2978
c19d1205 2979/* Directives: Literal pools. */
a737bd4d 2980
c19d1205
ZW
2981static literal_pool *
2982find_literal_pool (void)
a737bd4d 2983{
c19d1205 2984 literal_pool * pool;
a737bd4d 2985
c19d1205 2986 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2987 {
c19d1205
ZW
2988 if (pool->section == now_seg
2989 && pool->sub_section == now_subseg)
2990 break;
a737bd4d
NC
2991 }
2992
c19d1205 2993 return pool;
a737bd4d
NC
2994}
2995
c19d1205
ZW
2996static literal_pool *
2997find_or_make_literal_pool (void)
a737bd4d 2998{
c19d1205
ZW
2999 /* Next literal pool ID number. */
3000 static unsigned int latest_pool_num = 1;
3001 literal_pool * pool;
a737bd4d 3002
c19d1205 3003 pool = find_literal_pool ();
a737bd4d 3004
c19d1205 3005 if (pool == NULL)
a737bd4d 3006 {
c19d1205 3007 /* Create a new pool. */
21d799b5 3008 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
3009 if (! pool)
3010 return NULL;
a737bd4d 3011
c19d1205
ZW
3012 pool->next_free_entry = 0;
3013 pool->section = now_seg;
3014 pool->sub_section = now_subseg;
3015 pool->next = list_of_pools;
3016 pool->symbol = NULL;
3017
3018 /* Add it to the list. */
3019 list_of_pools = pool;
a737bd4d 3020 }
a737bd4d 3021
c19d1205
ZW
3022 /* New pools, and emptied pools, will have a NULL symbol. */
3023 if (pool->symbol == NULL)
a737bd4d 3024 {
c19d1205
ZW
3025 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3026 (valueT) 0, &zero_address_frag);
3027 pool->id = latest_pool_num ++;
a737bd4d
NC
3028 }
3029
c19d1205
ZW
3030 /* Done. */
3031 return pool;
a737bd4d
NC
3032}
3033
c19d1205 3034/* Add the literal in the global 'inst'
5f4273c7 3035 structure to the relevant literal pool. */
b99bd4ef
NC
3036
3037static int
c19d1205 3038add_to_lit_pool (void)
b99bd4ef 3039{
c19d1205
ZW
3040 literal_pool * pool;
3041 unsigned int entry;
b99bd4ef 3042
c19d1205
ZW
3043 pool = find_or_make_literal_pool ();
3044
3045 /* Check if this literal value is already in the pool. */
3046 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3047 {
c19d1205
ZW
3048 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3049 && (inst.reloc.exp.X_op == O_constant)
3050 && (pool->literals[entry].X_add_number
3051 == inst.reloc.exp.X_add_number)
3052 && (pool->literals[entry].X_unsigned
3053 == inst.reloc.exp.X_unsigned))
3054 break;
3055
3056 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3057 && (inst.reloc.exp.X_op == O_symbol)
3058 && (pool->literals[entry].X_add_number
3059 == inst.reloc.exp.X_add_number)
3060 && (pool->literals[entry].X_add_symbol
3061 == inst.reloc.exp.X_add_symbol)
3062 && (pool->literals[entry].X_op_symbol
3063 == inst.reloc.exp.X_op_symbol))
3064 break;
b99bd4ef
NC
3065 }
3066
c19d1205
ZW
3067 /* Do we need to create a new entry? */
3068 if (entry == pool->next_free_entry)
3069 {
3070 if (entry >= MAX_LITERAL_POOL_SIZE)
3071 {
3072 inst.error = _("literal pool overflow");
3073 return FAIL;
3074 }
3075
3076 pool->literals[entry] = inst.reloc.exp;
3077 pool->next_free_entry += 1;
3078 }
b99bd4ef 3079
c19d1205
ZW
3080 inst.reloc.exp.X_op = O_symbol;
3081 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3082 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3083
c19d1205 3084 return SUCCESS;
b99bd4ef
NC
3085}
3086
c19d1205
ZW
3087/* Can't use symbol_new here, so have to create a symbol and then at
3088 a later date assign it a value. Thats what these functions do. */
e16bb312 3089
c19d1205
ZW
3090static void
3091symbol_locate (symbolS * symbolP,
3092 const char * name, /* It is copied, the caller can modify. */
3093 segT segment, /* Segment identifier (SEG_<something>). */
3094 valueT valu, /* Symbol value. */
3095 fragS * frag) /* Associated fragment. */
3096{
3097 unsigned int name_length;
3098 char * preserved_copy_of_name;
e16bb312 3099
c19d1205
ZW
3100 name_length = strlen (name) + 1; /* +1 for \0. */
3101 obstack_grow (&notes, name, name_length);
21d799b5 3102 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3103
c19d1205
ZW
3104#ifdef tc_canonicalize_symbol_name
3105 preserved_copy_of_name =
3106 tc_canonicalize_symbol_name (preserved_copy_of_name);
3107#endif
b99bd4ef 3108
c19d1205 3109 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3110
c19d1205
ZW
3111 S_SET_SEGMENT (symbolP, segment);
3112 S_SET_VALUE (symbolP, valu);
3113 symbol_clear_list_pointers (symbolP);
b99bd4ef 3114
c19d1205 3115 symbol_set_frag (symbolP, frag);
b99bd4ef 3116
c19d1205
ZW
3117 /* Link to end of symbol chain. */
3118 {
3119 extern int symbol_table_frozen;
b99bd4ef 3120
c19d1205
ZW
3121 if (symbol_table_frozen)
3122 abort ();
3123 }
b99bd4ef 3124
c19d1205 3125 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3126
c19d1205 3127 obj_symbol_new_hook (symbolP);
b99bd4ef 3128
c19d1205
ZW
3129#ifdef tc_symbol_new_hook
3130 tc_symbol_new_hook (symbolP);
3131#endif
3132
3133#ifdef DEBUG_SYMS
3134 verify_symbol_chain (symbol_rootP, symbol_lastP);
3135#endif /* DEBUG_SYMS */
b99bd4ef
NC
3136}
3137
b99bd4ef 3138
c19d1205
ZW
3139static void
3140s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3141{
c19d1205
ZW
3142 unsigned int entry;
3143 literal_pool * pool;
3144 char sym_name[20];
b99bd4ef 3145
c19d1205
ZW
3146 pool = find_literal_pool ();
3147 if (pool == NULL
3148 || pool->symbol == NULL
3149 || pool->next_free_entry == 0)
3150 return;
b99bd4ef 3151
c19d1205 3152 mapping_state (MAP_DATA);
b99bd4ef 3153
c19d1205
ZW
3154 /* Align pool as you have word accesses.
3155 Only make a frag if we have to. */
3156 if (!need_pass_2)
3157 frag_align (2, 0, 0);
b99bd4ef 3158
c19d1205 3159 record_alignment (now_seg, 2);
b99bd4ef 3160
c19d1205 3161 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3162
c19d1205
ZW
3163 symbol_locate (pool->symbol, sym_name, now_seg,
3164 (valueT) frag_now_fix (), frag_now);
3165 symbol_table_insert (pool->symbol);
b99bd4ef 3166
c19d1205 3167 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3168
c19d1205
ZW
3169#if defined OBJ_COFF || defined OBJ_ELF
3170 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3171#endif
6c43fab6 3172
c19d1205
ZW
3173 for (entry = 0; entry < pool->next_free_entry; entry ++)
3174 /* First output the expression in the instruction to the pool. */
3175 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 3176
c19d1205
ZW
3177 /* Mark the pool as empty. */
3178 pool->next_free_entry = 0;
3179 pool->symbol = NULL;
b99bd4ef
NC
3180}
3181
c19d1205
ZW
3182#ifdef OBJ_ELF
3183/* Forward declarations for functions below, in the MD interface
3184 section. */
3185static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3186static valueT create_unwind_entry (int);
3187static void start_unwind_section (const segT, int);
3188static void add_unwind_opcode (valueT, int);
3189static void flush_pending_unwind (void);
b99bd4ef 3190
c19d1205 3191/* Directives: Data. */
b99bd4ef 3192
c19d1205
ZW
3193static void
3194s_arm_elf_cons (int nbytes)
3195{
3196 expressionS exp;
b99bd4ef 3197
c19d1205
ZW
3198#ifdef md_flush_pending_output
3199 md_flush_pending_output ();
3200#endif
b99bd4ef 3201
c19d1205 3202 if (is_it_end_of_statement ())
b99bd4ef 3203 {
c19d1205
ZW
3204 demand_empty_rest_of_line ();
3205 return;
b99bd4ef
NC
3206 }
3207
c19d1205
ZW
3208#ifdef md_cons_align
3209 md_cons_align (nbytes);
3210#endif
b99bd4ef 3211
c19d1205
ZW
3212 mapping_state (MAP_DATA);
3213 do
b99bd4ef 3214 {
c19d1205
ZW
3215 int reloc;
3216 char *base = input_line_pointer;
b99bd4ef 3217
c19d1205 3218 expression (& exp);
b99bd4ef 3219
c19d1205
ZW
3220 if (exp.X_op != O_symbol)
3221 emit_expr (&exp, (unsigned int) nbytes);
3222 else
3223 {
3224 char *before_reloc = input_line_pointer;
3225 reloc = parse_reloc (&input_line_pointer);
3226 if (reloc == -1)
3227 {
3228 as_bad (_("unrecognized relocation suffix"));
3229 ignore_rest_of_line ();
3230 return;
3231 }
3232 else if (reloc == BFD_RELOC_UNUSED)
3233 emit_expr (&exp, (unsigned int) nbytes);
3234 else
3235 {
21d799b5
NC
3236 reloc_howto_type *howto = (reloc_howto_type *)
3237 bfd_reloc_type_lookup (stdoutput,
3238 (bfd_reloc_code_real_type) reloc);
c19d1205 3239 int size = bfd_get_reloc_size (howto);
b99bd4ef 3240
2fc8bdac
ZW
3241 if (reloc == BFD_RELOC_ARM_PLT32)
3242 {
3243 as_bad (_("(plt) is only valid on branch targets"));
3244 reloc = BFD_RELOC_UNUSED;
3245 size = 0;
3246 }
3247
c19d1205 3248 if (size > nbytes)
2fc8bdac 3249 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3250 howto->name, nbytes);
3251 else
3252 {
3253 /* We've parsed an expression stopping at O_symbol.
3254 But there may be more expression left now that we
3255 have parsed the relocation marker. Parse it again.
3256 XXX Surely there is a cleaner way to do this. */
3257 char *p = input_line_pointer;
3258 int offset;
21d799b5 3259 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3260 memcpy (save_buf, base, input_line_pointer - base);
3261 memmove (base + (input_line_pointer - before_reloc),
3262 base, before_reloc - base);
3263
3264 input_line_pointer = base + (input_line_pointer-before_reloc);
3265 expression (&exp);
3266 memcpy (base, save_buf, p - base);
3267
3268 offset = nbytes - size;
3269 p = frag_more ((int) nbytes);
3270 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3271 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3272 }
3273 }
3274 }
b99bd4ef 3275 }
c19d1205 3276 while (*input_line_pointer++ == ',');
b99bd4ef 3277
c19d1205
ZW
3278 /* Put terminator back into stream. */
3279 input_line_pointer --;
3280 demand_empty_rest_of_line ();
b99bd4ef
NC
3281}
3282
c921be7d
NC
3283/* Emit an expression containing a 32-bit thumb instruction.
3284 Implementation based on put_thumb32_insn. */
3285
3286static void
3287emit_thumb32_expr (expressionS * exp)
3288{
3289 expressionS exp_high = *exp;
3290
3291 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3292 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3293 exp->X_add_number &= 0xffff;
3294 emit_expr (exp, (unsigned int) THUMB_SIZE);
3295}
3296
3297/* Guess the instruction size based on the opcode. */
3298
3299static int
3300thumb_insn_size (int opcode)
3301{
3302 if ((unsigned int) opcode < 0xe800u)
3303 return 2;
3304 else if ((unsigned int) opcode >= 0xe8000000u)
3305 return 4;
3306 else
3307 return 0;
3308}
3309
3310static bfd_boolean
3311emit_insn (expressionS *exp, int nbytes)
3312{
3313 int size = 0;
3314
3315 if (exp->X_op == O_constant)
3316 {
3317 size = nbytes;
3318
3319 if (size == 0)
3320 size = thumb_insn_size (exp->X_add_number);
3321
3322 if (size != 0)
3323 {
3324 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3325 {
3326 as_bad (_(".inst.n operand too big. "\
3327 "Use .inst.w instead"));
3328 size = 0;
3329 }
3330 else
3331 {
3332 if (now_it.state == AUTOMATIC_IT_BLOCK)
3333 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3334 else
3335 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3336
3337 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3338 emit_thumb32_expr (exp);
3339 else
3340 emit_expr (exp, (unsigned int) size);
3341
3342 it_fsm_post_encode ();
3343 }
3344 }
3345 else
3346 as_bad (_("cannot determine Thumb instruction size. " \
3347 "Use .inst.n/.inst.w instead"));
3348 }
3349 else
3350 as_bad (_("constant expression required"));
3351
3352 return (size != 0);
3353}
3354
3355/* Like s_arm_elf_cons but do not use md_cons_align and
3356 set the mapping state to MAP_ARM/MAP_THUMB. */
3357
3358static void
3359s_arm_elf_inst (int nbytes)
3360{
3361 if (is_it_end_of_statement ())
3362 {
3363 demand_empty_rest_of_line ();
3364 return;
3365 }
3366
3367 /* Calling mapping_state () here will not change ARM/THUMB,
3368 but will ensure not to be in DATA state. */
3369
3370 if (thumb_mode)
3371 mapping_state (MAP_THUMB);
3372 else
3373 {
3374 if (nbytes != 0)
3375 {
3376 as_bad (_("width suffixes are invalid in ARM mode"));
3377 ignore_rest_of_line ();
3378 return;
3379 }
3380
3381 nbytes = 4;
3382
3383 mapping_state (MAP_ARM);
3384 }
3385
3386 do
3387 {
3388 expressionS exp;
3389
3390 expression (& exp);
3391
3392 if (! emit_insn (& exp, nbytes))
3393 {
3394 ignore_rest_of_line ();
3395 return;
3396 }
3397 }
3398 while (*input_line_pointer++ == ',');
3399
3400 /* Put terminator back into stream. */
3401 input_line_pointer --;
3402 demand_empty_rest_of_line ();
3403}
b99bd4ef 3404
c19d1205 3405/* Parse a .rel31 directive. */
b99bd4ef 3406
c19d1205
ZW
3407static void
3408s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3409{
3410 expressionS exp;
3411 char *p;
3412 valueT highbit;
b99bd4ef 3413
c19d1205
ZW
3414 highbit = 0;
3415 if (*input_line_pointer == '1')
3416 highbit = 0x80000000;
3417 else if (*input_line_pointer != '0')
3418 as_bad (_("expected 0 or 1"));
b99bd4ef 3419
c19d1205
ZW
3420 input_line_pointer++;
3421 if (*input_line_pointer != ',')
3422 as_bad (_("missing comma"));
3423 input_line_pointer++;
b99bd4ef 3424
c19d1205
ZW
3425#ifdef md_flush_pending_output
3426 md_flush_pending_output ();
3427#endif
b99bd4ef 3428
c19d1205
ZW
3429#ifdef md_cons_align
3430 md_cons_align (4);
3431#endif
b99bd4ef 3432
c19d1205 3433 mapping_state (MAP_DATA);
b99bd4ef 3434
c19d1205 3435 expression (&exp);
b99bd4ef 3436
c19d1205
ZW
3437 p = frag_more (4);
3438 md_number_to_chars (p, highbit, 4);
3439 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3440 BFD_RELOC_ARM_PREL31);
b99bd4ef 3441
c19d1205 3442 demand_empty_rest_of_line ();
b99bd4ef
NC
3443}
3444
c19d1205 3445/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3446
c19d1205 3447/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3448
c19d1205
ZW
3449static void
3450s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3451{
3452 demand_empty_rest_of_line ();
921e5f0a
PB
3453 if (unwind.proc_start)
3454 {
c921be7d 3455 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3456 return;
3457 }
3458
c19d1205
ZW
3459 /* Mark the start of the function. */
3460 unwind.proc_start = expr_build_dot ();
b99bd4ef 3461
c19d1205
ZW
3462 /* Reset the rest of the unwind info. */
3463 unwind.opcode_count = 0;
3464 unwind.table_entry = NULL;
3465 unwind.personality_routine = NULL;
3466 unwind.personality_index = -1;
3467 unwind.frame_size = 0;
3468 unwind.fp_offset = 0;
fdfde340 3469 unwind.fp_reg = REG_SP;
c19d1205
ZW
3470 unwind.fp_used = 0;
3471 unwind.sp_restored = 0;
3472}
b99bd4ef 3473
b99bd4ef 3474
c19d1205
ZW
3475/* Parse a handlerdata directive. Creates the exception handling table entry
3476 for the function. */
b99bd4ef 3477
c19d1205
ZW
3478static void
3479s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3480{
3481 demand_empty_rest_of_line ();
921e5f0a 3482 if (!unwind.proc_start)
c921be7d 3483 as_bad (MISSING_FNSTART);
921e5f0a 3484
c19d1205 3485 if (unwind.table_entry)
6decc662 3486 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3487
c19d1205
ZW
3488 create_unwind_entry (1);
3489}
a737bd4d 3490
c19d1205 3491/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3492
c19d1205
ZW
3493static void
3494s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3495{
3496 long where;
3497 char *ptr;
3498 valueT val;
940b5ce0 3499 unsigned int marked_pr_dependency;
f02232aa 3500
c19d1205 3501 demand_empty_rest_of_line ();
f02232aa 3502
921e5f0a
PB
3503 if (!unwind.proc_start)
3504 {
c921be7d 3505 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3506 return;
3507 }
3508
c19d1205
ZW
3509 /* Add eh table entry. */
3510 if (unwind.table_entry == NULL)
3511 val = create_unwind_entry (0);
3512 else
3513 val = 0;
f02232aa 3514
c19d1205
ZW
3515 /* Add index table entry. This is two words. */
3516 start_unwind_section (unwind.saved_seg, 1);
3517 frag_align (2, 0, 0);
3518 record_alignment (now_seg, 2);
b99bd4ef 3519
c19d1205
ZW
3520 ptr = frag_more (8);
3521 where = frag_now_fix () - 8;
f02232aa 3522
c19d1205
ZW
3523 /* Self relative offset of the function start. */
3524 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3525 BFD_RELOC_ARM_PREL31);
f02232aa 3526
c19d1205
ZW
3527 /* Indicate dependency on EHABI-defined personality routines to the
3528 linker, if it hasn't been done already. */
940b5ce0
DJ
3529 marked_pr_dependency
3530 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3531 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3532 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3533 {
5f4273c7
NC
3534 static const char *const name[] =
3535 {
3536 "__aeabi_unwind_cpp_pr0",
3537 "__aeabi_unwind_cpp_pr1",
3538 "__aeabi_unwind_cpp_pr2"
3539 };
c19d1205
ZW
3540 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3541 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3542 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3543 |= 1 << unwind.personality_index;
c19d1205 3544 }
f02232aa 3545
c19d1205
ZW
3546 if (val)
3547 /* Inline exception table entry. */
3548 md_number_to_chars (ptr + 4, val, 4);
3549 else
3550 /* Self relative offset of the table entry. */
3551 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3552 BFD_RELOC_ARM_PREL31);
f02232aa 3553
c19d1205
ZW
3554 /* Restore the original section. */
3555 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3556
3557 unwind.proc_start = NULL;
c19d1205 3558}
f02232aa 3559
f02232aa 3560
c19d1205 3561/* Parse an unwind_cantunwind directive. */
b99bd4ef 3562
c19d1205
ZW
3563static void
3564s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3565{
3566 demand_empty_rest_of_line ();
921e5f0a 3567 if (!unwind.proc_start)
c921be7d 3568 as_bad (MISSING_FNSTART);
921e5f0a 3569
c19d1205
ZW
3570 if (unwind.personality_routine || unwind.personality_index != -1)
3571 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3572
c19d1205
ZW
3573 unwind.personality_index = -2;
3574}
b99bd4ef 3575
b99bd4ef 3576
c19d1205 3577/* Parse a personalityindex directive. */
b99bd4ef 3578
c19d1205
ZW
3579static void
3580s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3581{
3582 expressionS exp;
b99bd4ef 3583
921e5f0a 3584 if (!unwind.proc_start)
c921be7d 3585 as_bad (MISSING_FNSTART);
921e5f0a 3586
c19d1205
ZW
3587 if (unwind.personality_routine || unwind.personality_index != -1)
3588 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3589
c19d1205 3590 expression (&exp);
b99bd4ef 3591
c19d1205
ZW
3592 if (exp.X_op != O_constant
3593 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3594 {
c19d1205
ZW
3595 as_bad (_("bad personality routine number"));
3596 ignore_rest_of_line ();
3597 return;
b99bd4ef
NC
3598 }
3599
c19d1205 3600 unwind.personality_index = exp.X_add_number;
b99bd4ef 3601
c19d1205
ZW
3602 demand_empty_rest_of_line ();
3603}
e16bb312 3604
e16bb312 3605
c19d1205 3606/* Parse a personality directive. */
e16bb312 3607
c19d1205
ZW
3608static void
3609s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3610{
3611 char *name, *p, c;
a737bd4d 3612
921e5f0a 3613 if (!unwind.proc_start)
c921be7d 3614 as_bad (MISSING_FNSTART);
921e5f0a 3615
c19d1205
ZW
3616 if (unwind.personality_routine || unwind.personality_index != -1)
3617 as_bad (_("duplicate .personality directive"));
a737bd4d 3618
c19d1205
ZW
3619 name = input_line_pointer;
3620 c = get_symbol_end ();
3621 p = input_line_pointer;
3622 unwind.personality_routine = symbol_find_or_make (name);
3623 *p = c;
3624 demand_empty_rest_of_line ();
3625}
e16bb312 3626
e16bb312 3627
c19d1205 3628/* Parse a directive saving core registers. */
e16bb312 3629
c19d1205
ZW
3630static void
3631s_arm_unwind_save_core (void)
e16bb312 3632{
c19d1205
ZW
3633 valueT op;
3634 long range;
3635 int n;
e16bb312 3636
c19d1205
ZW
3637 range = parse_reg_list (&input_line_pointer);
3638 if (range == FAIL)
e16bb312 3639 {
c19d1205
ZW
3640 as_bad (_("expected register list"));
3641 ignore_rest_of_line ();
3642 return;
3643 }
e16bb312 3644
c19d1205 3645 demand_empty_rest_of_line ();
e16bb312 3646
c19d1205
ZW
3647 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3648 into .unwind_save {..., sp...}. We aren't bothered about the value of
3649 ip because it is clobbered by calls. */
3650 if (unwind.sp_restored && unwind.fp_reg == 12
3651 && (range & 0x3000) == 0x1000)
3652 {
3653 unwind.opcode_count--;
3654 unwind.sp_restored = 0;
3655 range = (range | 0x2000) & ~0x1000;
3656 unwind.pending_offset = 0;
3657 }
e16bb312 3658
01ae4198
DJ
3659 /* Pop r4-r15. */
3660 if (range & 0xfff0)
c19d1205 3661 {
01ae4198
DJ
3662 /* See if we can use the short opcodes. These pop a block of up to 8
3663 registers starting with r4, plus maybe r14. */
3664 for (n = 0; n < 8; n++)
3665 {
3666 /* Break at the first non-saved register. */
3667 if ((range & (1 << (n + 4))) == 0)
3668 break;
3669 }
3670 /* See if there are any other bits set. */
3671 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3672 {
3673 /* Use the long form. */
3674 op = 0x8000 | ((range >> 4) & 0xfff);
3675 add_unwind_opcode (op, 2);
3676 }
0dd132b6 3677 else
01ae4198
DJ
3678 {
3679 /* Use the short form. */
3680 if (range & 0x4000)
3681 op = 0xa8; /* Pop r14. */
3682 else
3683 op = 0xa0; /* Do not pop r14. */
3684 op |= (n - 1);
3685 add_unwind_opcode (op, 1);
3686 }
c19d1205 3687 }
0dd132b6 3688
c19d1205
ZW
3689 /* Pop r0-r3. */
3690 if (range & 0xf)
3691 {
3692 op = 0xb100 | (range & 0xf);
3693 add_unwind_opcode (op, 2);
0dd132b6
NC
3694 }
3695
c19d1205
ZW
3696 /* Record the number of bytes pushed. */
3697 for (n = 0; n < 16; n++)
3698 {
3699 if (range & (1 << n))
3700 unwind.frame_size += 4;
3701 }
0dd132b6
NC
3702}
3703
c19d1205
ZW
3704
3705/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3706
3707static void
c19d1205 3708s_arm_unwind_save_fpa (int reg)
b99bd4ef 3709{
c19d1205
ZW
3710 expressionS exp;
3711 int num_regs;
3712 valueT op;
b99bd4ef 3713
c19d1205
ZW
3714 /* Get Number of registers to transfer. */
3715 if (skip_past_comma (&input_line_pointer) != FAIL)
3716 expression (&exp);
3717 else
3718 exp.X_op = O_illegal;
b99bd4ef 3719
c19d1205 3720 if (exp.X_op != O_constant)
b99bd4ef 3721 {
c19d1205
ZW
3722 as_bad (_("expected , <constant>"));
3723 ignore_rest_of_line ();
b99bd4ef
NC
3724 return;
3725 }
3726
c19d1205
ZW
3727 num_regs = exp.X_add_number;
3728
3729 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3730 {
c19d1205
ZW
3731 as_bad (_("number of registers must be in the range [1:4]"));
3732 ignore_rest_of_line ();
b99bd4ef
NC
3733 return;
3734 }
3735
c19d1205 3736 demand_empty_rest_of_line ();
b99bd4ef 3737
c19d1205
ZW
3738 if (reg == 4)
3739 {
3740 /* Short form. */
3741 op = 0xb4 | (num_regs - 1);
3742 add_unwind_opcode (op, 1);
3743 }
b99bd4ef
NC
3744 else
3745 {
c19d1205
ZW
3746 /* Long form. */
3747 op = 0xc800 | (reg << 4) | (num_regs - 1);
3748 add_unwind_opcode (op, 2);
b99bd4ef 3749 }
c19d1205 3750 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3751}
3752
c19d1205 3753
fa073d69
MS
3754/* Parse a directive saving VFP registers for ARMv6 and above. */
3755
3756static void
3757s_arm_unwind_save_vfp_armv6 (void)
3758{
3759 int count;
3760 unsigned int start;
3761 valueT op;
3762 int num_vfpv3_regs = 0;
3763 int num_regs_below_16;
3764
3765 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3766 if (count == FAIL)
3767 {
3768 as_bad (_("expected register list"));
3769 ignore_rest_of_line ();
3770 return;
3771 }
3772
3773 demand_empty_rest_of_line ();
3774
3775 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3776 than FSTMX/FLDMX-style ones). */
3777
3778 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3779 if (start >= 16)
3780 num_vfpv3_regs = count;
3781 else if (start + count > 16)
3782 num_vfpv3_regs = start + count - 16;
3783
3784 if (num_vfpv3_regs > 0)
3785 {
3786 int start_offset = start > 16 ? start - 16 : 0;
3787 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3788 add_unwind_opcode (op, 2);
3789 }
3790
3791 /* Generate opcode for registers numbered in the range 0 .. 15. */
3792 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3793 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3794 if (num_regs_below_16 > 0)
3795 {
3796 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3797 add_unwind_opcode (op, 2);
3798 }
3799
3800 unwind.frame_size += count * 8;
3801}
3802
3803
3804/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3805
3806static void
c19d1205 3807s_arm_unwind_save_vfp (void)
b99bd4ef 3808{
c19d1205 3809 int count;
ca3f61f7 3810 unsigned int reg;
c19d1205 3811 valueT op;
b99bd4ef 3812
5287ad62 3813 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3814 if (count == FAIL)
b99bd4ef 3815 {
c19d1205
ZW
3816 as_bad (_("expected register list"));
3817 ignore_rest_of_line ();
b99bd4ef
NC
3818 return;
3819 }
3820
c19d1205 3821 demand_empty_rest_of_line ();
b99bd4ef 3822
c19d1205 3823 if (reg == 8)
b99bd4ef 3824 {
c19d1205
ZW
3825 /* Short form. */
3826 op = 0xb8 | (count - 1);
3827 add_unwind_opcode (op, 1);
b99bd4ef 3828 }
c19d1205 3829 else
b99bd4ef 3830 {
c19d1205
ZW
3831 /* Long form. */
3832 op = 0xb300 | (reg << 4) | (count - 1);
3833 add_unwind_opcode (op, 2);
b99bd4ef 3834 }
c19d1205
ZW
3835 unwind.frame_size += count * 8 + 4;
3836}
b99bd4ef 3837
b99bd4ef 3838
c19d1205
ZW
3839/* Parse a directive saving iWMMXt data registers. */
3840
3841static void
3842s_arm_unwind_save_mmxwr (void)
3843{
3844 int reg;
3845 int hi_reg;
3846 int i;
3847 unsigned mask = 0;
3848 valueT op;
b99bd4ef 3849
c19d1205
ZW
3850 if (*input_line_pointer == '{')
3851 input_line_pointer++;
b99bd4ef 3852
c19d1205 3853 do
b99bd4ef 3854 {
dcbf9037 3855 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3856
c19d1205 3857 if (reg == FAIL)
b99bd4ef 3858 {
9b7132d3 3859 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3860 goto error;
b99bd4ef
NC
3861 }
3862
c19d1205
ZW
3863 if (mask >> reg)
3864 as_tsktsk (_("register list not in ascending order"));
3865 mask |= 1 << reg;
b99bd4ef 3866
c19d1205
ZW
3867 if (*input_line_pointer == '-')
3868 {
3869 input_line_pointer++;
dcbf9037 3870 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3871 if (hi_reg == FAIL)
3872 {
9b7132d3 3873 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3874 goto error;
3875 }
3876 else if (reg >= hi_reg)
3877 {
3878 as_bad (_("bad register range"));
3879 goto error;
3880 }
3881 for (; reg < hi_reg; reg++)
3882 mask |= 1 << reg;
3883 }
3884 }
3885 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3886
c19d1205
ZW
3887 if (*input_line_pointer == '}')
3888 input_line_pointer++;
b99bd4ef 3889
c19d1205 3890 demand_empty_rest_of_line ();
b99bd4ef 3891
708587a4 3892 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3893 the list. */
3894 flush_pending_unwind ();
b99bd4ef 3895
c19d1205 3896 for (i = 0; i < 16; i++)
b99bd4ef 3897 {
c19d1205
ZW
3898 if (mask & (1 << i))
3899 unwind.frame_size += 8;
b99bd4ef
NC
3900 }
3901
c19d1205
ZW
3902 /* Attempt to combine with a previous opcode. We do this because gcc
3903 likes to output separate unwind directives for a single block of
3904 registers. */
3905 if (unwind.opcode_count > 0)
b99bd4ef 3906 {
c19d1205
ZW
3907 i = unwind.opcodes[unwind.opcode_count - 1];
3908 if ((i & 0xf8) == 0xc0)
3909 {
3910 i &= 7;
3911 /* Only merge if the blocks are contiguous. */
3912 if (i < 6)
3913 {
3914 if ((mask & 0xfe00) == (1 << 9))
3915 {
3916 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3917 unwind.opcode_count--;
3918 }
3919 }
3920 else if (i == 6 && unwind.opcode_count >= 2)
3921 {
3922 i = unwind.opcodes[unwind.opcode_count - 2];
3923 reg = i >> 4;
3924 i &= 0xf;
b99bd4ef 3925
c19d1205
ZW
3926 op = 0xffff << (reg - 1);
3927 if (reg > 0
87a1fd79 3928 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3929 {
3930 op = (1 << (reg + i + 1)) - 1;
3931 op &= ~((1 << reg) - 1);
3932 mask |= op;
3933 unwind.opcode_count -= 2;
3934 }
3935 }
3936 }
b99bd4ef
NC
3937 }
3938
c19d1205
ZW
3939 hi_reg = 15;
3940 /* We want to generate opcodes in the order the registers have been
3941 saved, ie. descending order. */
3942 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3943 {
c19d1205
ZW
3944 /* Save registers in blocks. */
3945 if (reg < 0
3946 || !(mask & (1 << reg)))
3947 {
3948 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3949 preceding block. */
c19d1205
ZW
3950 if (reg != hi_reg)
3951 {
3952 if (reg == 9)
3953 {
3954 /* Short form. */
3955 op = 0xc0 | (hi_reg - 10);
3956 add_unwind_opcode (op, 1);
3957 }
3958 else
3959 {
3960 /* Long form. */
3961 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3962 add_unwind_opcode (op, 2);
3963 }
3964 }
3965 hi_reg = reg - 1;
3966 }
b99bd4ef
NC
3967 }
3968
c19d1205
ZW
3969 return;
3970error:
3971 ignore_rest_of_line ();
b99bd4ef
NC
3972}
3973
3974static void
c19d1205 3975s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3976{
c19d1205
ZW
3977 int reg;
3978 int hi_reg;
3979 unsigned mask = 0;
3980 valueT op;
b99bd4ef 3981
c19d1205
ZW
3982 if (*input_line_pointer == '{')
3983 input_line_pointer++;
b99bd4ef 3984
c19d1205 3985 do
b99bd4ef 3986 {
dcbf9037 3987 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3988
c19d1205
ZW
3989 if (reg == FAIL)
3990 {
9b7132d3 3991 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3992 goto error;
3993 }
b99bd4ef 3994
c19d1205
ZW
3995 reg -= 8;
3996 if (mask >> reg)
3997 as_tsktsk (_("register list not in ascending order"));
3998 mask |= 1 << reg;
b99bd4ef 3999
c19d1205
ZW
4000 if (*input_line_pointer == '-')
4001 {
4002 input_line_pointer++;
dcbf9037 4003 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4004 if (hi_reg == FAIL)
4005 {
9b7132d3 4006 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4007 goto error;
4008 }
4009 else if (reg >= hi_reg)
4010 {
4011 as_bad (_("bad register range"));
4012 goto error;
4013 }
4014 for (; reg < hi_reg; reg++)
4015 mask |= 1 << reg;
4016 }
b99bd4ef 4017 }
c19d1205 4018 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4019
c19d1205
ZW
4020 if (*input_line_pointer == '}')
4021 input_line_pointer++;
b99bd4ef 4022
c19d1205
ZW
4023 demand_empty_rest_of_line ();
4024
708587a4 4025 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4026 the list. */
4027 flush_pending_unwind ();
b99bd4ef 4028
c19d1205 4029 for (reg = 0; reg < 16; reg++)
b99bd4ef 4030 {
c19d1205
ZW
4031 if (mask & (1 << reg))
4032 unwind.frame_size += 4;
b99bd4ef 4033 }
c19d1205
ZW
4034 op = 0xc700 | mask;
4035 add_unwind_opcode (op, 2);
4036 return;
4037error:
4038 ignore_rest_of_line ();
b99bd4ef
NC
4039}
4040
c19d1205 4041
fa073d69
MS
4042/* Parse an unwind_save directive.
4043 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4044
b99bd4ef 4045static void
fa073d69 4046s_arm_unwind_save (int arch_v6)
b99bd4ef 4047{
c19d1205
ZW
4048 char *peek;
4049 struct reg_entry *reg;
4050 bfd_boolean had_brace = FALSE;
b99bd4ef 4051
921e5f0a 4052 if (!unwind.proc_start)
c921be7d 4053 as_bad (MISSING_FNSTART);
921e5f0a 4054
c19d1205
ZW
4055 /* Figure out what sort of save we have. */
4056 peek = input_line_pointer;
b99bd4ef 4057
c19d1205 4058 if (*peek == '{')
b99bd4ef 4059 {
c19d1205
ZW
4060 had_brace = TRUE;
4061 peek++;
b99bd4ef
NC
4062 }
4063
c19d1205 4064 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4065
c19d1205 4066 if (!reg)
b99bd4ef 4067 {
c19d1205
ZW
4068 as_bad (_("register expected"));
4069 ignore_rest_of_line ();
b99bd4ef
NC
4070 return;
4071 }
4072
c19d1205 4073 switch (reg->type)
b99bd4ef 4074 {
c19d1205
ZW
4075 case REG_TYPE_FN:
4076 if (had_brace)
4077 {
4078 as_bad (_("FPA .unwind_save does not take a register list"));
4079 ignore_rest_of_line ();
4080 return;
4081 }
93ac2687 4082 input_line_pointer = peek;
c19d1205 4083 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4084 return;
c19d1205
ZW
4085
4086 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
4087 case REG_TYPE_VFD:
4088 if (arch_v6)
4089 s_arm_unwind_save_vfp_armv6 ();
4090 else
4091 s_arm_unwind_save_vfp ();
4092 return;
c19d1205
ZW
4093 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4094 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4095
4096 default:
4097 as_bad (_(".unwind_save does not support this kind of register"));
4098 ignore_rest_of_line ();
b99bd4ef 4099 }
c19d1205 4100}
b99bd4ef 4101
b99bd4ef 4102
c19d1205
ZW
4103/* Parse an unwind_movsp directive. */
4104
4105static void
4106s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4107{
4108 int reg;
4109 valueT op;
4fa3602b 4110 int offset;
c19d1205 4111
921e5f0a 4112 if (!unwind.proc_start)
c921be7d 4113 as_bad (MISSING_FNSTART);
921e5f0a 4114
dcbf9037 4115 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4116 if (reg == FAIL)
b99bd4ef 4117 {
9b7132d3 4118 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4119 ignore_rest_of_line ();
b99bd4ef
NC
4120 return;
4121 }
4fa3602b
PB
4122
4123 /* Optional constant. */
4124 if (skip_past_comma (&input_line_pointer) != FAIL)
4125 {
4126 if (immediate_for_directive (&offset) == FAIL)
4127 return;
4128 }
4129 else
4130 offset = 0;
4131
c19d1205 4132 demand_empty_rest_of_line ();
b99bd4ef 4133
c19d1205 4134 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4135 {
c19d1205 4136 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4137 return;
4138 }
4139
c19d1205
ZW
4140 if (unwind.fp_reg != REG_SP)
4141 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4142
c19d1205
ZW
4143 /* Generate opcode to restore the value. */
4144 op = 0x90 | reg;
4145 add_unwind_opcode (op, 1);
4146
4147 /* Record the information for later. */
4148 unwind.fp_reg = reg;
4fa3602b 4149 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4150 unwind.sp_restored = 1;
b05fe5cf
ZW
4151}
4152
c19d1205
ZW
4153/* Parse an unwind_pad directive. */
4154
b05fe5cf 4155static void
c19d1205 4156s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4157{
c19d1205 4158 int offset;
b05fe5cf 4159
921e5f0a 4160 if (!unwind.proc_start)
c921be7d 4161 as_bad (MISSING_FNSTART);
921e5f0a 4162
c19d1205
ZW
4163 if (immediate_for_directive (&offset) == FAIL)
4164 return;
b99bd4ef 4165
c19d1205
ZW
4166 if (offset & 3)
4167 {
4168 as_bad (_("stack increment must be multiple of 4"));
4169 ignore_rest_of_line ();
4170 return;
4171 }
b99bd4ef 4172
c19d1205
ZW
4173 /* Don't generate any opcodes, just record the details for later. */
4174 unwind.frame_size += offset;
4175 unwind.pending_offset += offset;
4176
4177 demand_empty_rest_of_line ();
4178}
4179
4180/* Parse an unwind_setfp directive. */
4181
4182static void
4183s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4184{
c19d1205
ZW
4185 int sp_reg;
4186 int fp_reg;
4187 int offset;
4188
921e5f0a 4189 if (!unwind.proc_start)
c921be7d 4190 as_bad (MISSING_FNSTART);
921e5f0a 4191
dcbf9037 4192 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4193 if (skip_past_comma (&input_line_pointer) == FAIL)
4194 sp_reg = FAIL;
4195 else
dcbf9037 4196 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4197
c19d1205
ZW
4198 if (fp_reg == FAIL || sp_reg == FAIL)
4199 {
4200 as_bad (_("expected <reg>, <reg>"));
4201 ignore_rest_of_line ();
4202 return;
4203 }
b99bd4ef 4204
c19d1205
ZW
4205 /* Optional constant. */
4206 if (skip_past_comma (&input_line_pointer) != FAIL)
4207 {
4208 if (immediate_for_directive (&offset) == FAIL)
4209 return;
4210 }
4211 else
4212 offset = 0;
a737bd4d 4213
c19d1205 4214 demand_empty_rest_of_line ();
a737bd4d 4215
fdfde340 4216 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4217 {
c19d1205
ZW
4218 as_bad (_("register must be either sp or set by a previous"
4219 "unwind_movsp directive"));
4220 return;
a737bd4d
NC
4221 }
4222
c19d1205
ZW
4223 /* Don't generate any opcodes, just record the information for later. */
4224 unwind.fp_reg = fp_reg;
4225 unwind.fp_used = 1;
fdfde340 4226 if (sp_reg == REG_SP)
c19d1205
ZW
4227 unwind.fp_offset = unwind.frame_size - offset;
4228 else
4229 unwind.fp_offset -= offset;
a737bd4d
NC
4230}
4231
c19d1205
ZW
4232/* Parse an unwind_raw directive. */
4233
4234static void
4235s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4236{
c19d1205 4237 expressionS exp;
708587a4 4238 /* This is an arbitrary limit. */
c19d1205
ZW
4239 unsigned char op[16];
4240 int count;
a737bd4d 4241
921e5f0a 4242 if (!unwind.proc_start)
c921be7d 4243 as_bad (MISSING_FNSTART);
921e5f0a 4244
c19d1205
ZW
4245 expression (&exp);
4246 if (exp.X_op == O_constant
4247 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4248 {
c19d1205
ZW
4249 unwind.frame_size += exp.X_add_number;
4250 expression (&exp);
4251 }
4252 else
4253 exp.X_op = O_illegal;
a737bd4d 4254
c19d1205
ZW
4255 if (exp.X_op != O_constant)
4256 {
4257 as_bad (_("expected <offset>, <opcode>"));
4258 ignore_rest_of_line ();
4259 return;
4260 }
a737bd4d 4261
c19d1205 4262 count = 0;
a737bd4d 4263
c19d1205
ZW
4264 /* Parse the opcode. */
4265 for (;;)
4266 {
4267 if (count >= 16)
4268 {
4269 as_bad (_("unwind opcode too long"));
4270 ignore_rest_of_line ();
a737bd4d 4271 }
c19d1205 4272 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4273 {
c19d1205
ZW
4274 as_bad (_("invalid unwind opcode"));
4275 ignore_rest_of_line ();
4276 return;
a737bd4d 4277 }
c19d1205 4278 op[count++] = exp.X_add_number;
a737bd4d 4279
c19d1205
ZW
4280 /* Parse the next byte. */
4281 if (skip_past_comma (&input_line_pointer) == FAIL)
4282 break;
a737bd4d 4283
c19d1205
ZW
4284 expression (&exp);
4285 }
b99bd4ef 4286
c19d1205
ZW
4287 /* Add the opcode bytes in reverse order. */
4288 while (count--)
4289 add_unwind_opcode (op[count], 1);
b99bd4ef 4290
c19d1205 4291 demand_empty_rest_of_line ();
b99bd4ef 4292}
ee065d83
PB
4293
4294
4295/* Parse a .eabi_attribute directive. */
4296
4297static void
4298s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4299{
ee3c0378
AS
4300 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4301
4302 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4303 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4304}
4305
0855e32b
NS
4306/* Emit a tls fix for the symbol. */
4307
4308static void
4309s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4310{
4311 char *p;
4312 expressionS exp;
4313#ifdef md_flush_pending_output
4314 md_flush_pending_output ();
4315#endif
4316
4317#ifdef md_cons_align
4318 md_cons_align (4);
4319#endif
4320
4321 /* Since we're just labelling the code, there's no need to define a
4322 mapping symbol. */
4323 expression (&exp);
4324 p = obstack_next_free (&frchain_now->frch_obstack);
4325 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4326 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4327 : BFD_RELOC_ARM_TLS_DESCSEQ);
4328}
cdf9ccec 4329#endif /* OBJ_ELF */
0855e32b 4330
ee065d83 4331static void s_arm_arch (int);
7a1d4c38 4332static void s_arm_object_arch (int);
ee065d83
PB
4333static void s_arm_cpu (int);
4334static void s_arm_fpu (int);
69133863 4335static void s_arm_arch_extension (int);
b99bd4ef 4336
f0927246
NC
4337#ifdef TE_PE
4338
4339static void
5f4273c7 4340pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4341{
4342 expressionS exp;
4343
4344 do
4345 {
4346 expression (&exp);
4347 if (exp.X_op == O_symbol)
4348 exp.X_op = O_secrel;
4349
4350 emit_expr (&exp, 4);
4351 }
4352 while (*input_line_pointer++ == ',');
4353
4354 input_line_pointer--;
4355 demand_empty_rest_of_line ();
4356}
4357#endif /* TE_PE */
4358
c19d1205
ZW
4359/* This table describes all the machine specific pseudo-ops the assembler
4360 has to support. The fields are:
4361 pseudo-op name without dot
4362 function to call to execute this pseudo-op
4363 Integer arg to pass to the function. */
b99bd4ef 4364
c19d1205 4365const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4366{
c19d1205
ZW
4367 /* Never called because '.req' does not start a line. */
4368 { "req", s_req, 0 },
dcbf9037
JB
4369 /* Following two are likewise never called. */
4370 { "dn", s_dn, 0 },
4371 { "qn", s_qn, 0 },
c19d1205
ZW
4372 { "unreq", s_unreq, 0 },
4373 { "bss", s_bss, 0 },
4374 { "align", s_align, 0 },
4375 { "arm", s_arm, 0 },
4376 { "thumb", s_thumb, 0 },
4377 { "code", s_code, 0 },
4378 { "force_thumb", s_force_thumb, 0 },
4379 { "thumb_func", s_thumb_func, 0 },
4380 { "thumb_set", s_thumb_set, 0 },
4381 { "even", s_even, 0 },
4382 { "ltorg", s_ltorg, 0 },
4383 { "pool", s_ltorg, 0 },
4384 { "syntax", s_syntax, 0 },
8463be01
PB
4385 { "cpu", s_arm_cpu, 0 },
4386 { "arch", s_arm_arch, 0 },
7a1d4c38 4387 { "object_arch", s_arm_object_arch, 0 },
8463be01 4388 { "fpu", s_arm_fpu, 0 },
69133863 4389 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4390#ifdef OBJ_ELF
c921be7d
NC
4391 { "word", s_arm_elf_cons, 4 },
4392 { "long", s_arm_elf_cons, 4 },
4393 { "inst.n", s_arm_elf_inst, 2 },
4394 { "inst.w", s_arm_elf_inst, 4 },
4395 { "inst", s_arm_elf_inst, 0 },
4396 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4397 { "fnstart", s_arm_unwind_fnstart, 0 },
4398 { "fnend", s_arm_unwind_fnend, 0 },
4399 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4400 { "personality", s_arm_unwind_personality, 0 },
4401 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4402 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4403 { "save", s_arm_unwind_save, 0 },
fa073d69 4404 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4405 { "movsp", s_arm_unwind_movsp, 0 },
4406 { "pad", s_arm_unwind_pad, 0 },
4407 { "setfp", s_arm_unwind_setfp, 0 },
4408 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4409 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4410 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4411#else
4412 { "word", cons, 4},
f0927246
NC
4413
4414 /* These are used for dwarf. */
4415 {"2byte", cons, 2},
4416 {"4byte", cons, 4},
4417 {"8byte", cons, 8},
4418 /* These are used for dwarf2. */
4419 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4420 { "loc", dwarf2_directive_loc, 0 },
4421 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4422#endif
4423 { "extend", float_cons, 'x' },
4424 { "ldouble", float_cons, 'x' },
4425 { "packed", float_cons, 'p' },
f0927246
NC
4426#ifdef TE_PE
4427 {"secrel32", pe_directive_secrel, 0},
4428#endif
c19d1205
ZW
4429 { 0, 0, 0 }
4430};
4431\f
4432/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4433
c19d1205
ZW
4434/* Generic immediate-value read function for use in insn parsing.
4435 STR points to the beginning of the immediate (the leading #);
4436 VAL receives the value; if the value is outside [MIN, MAX]
4437 issue an error. PREFIX_OPT is true if the immediate prefix is
4438 optional. */
b99bd4ef 4439
c19d1205
ZW
4440static int
4441parse_immediate (char **str, int *val, int min, int max,
4442 bfd_boolean prefix_opt)
4443{
4444 expressionS exp;
4445 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4446 if (exp.X_op != O_constant)
b99bd4ef 4447 {
c19d1205
ZW
4448 inst.error = _("constant expression required");
4449 return FAIL;
4450 }
b99bd4ef 4451
c19d1205
ZW
4452 if (exp.X_add_number < min || exp.X_add_number > max)
4453 {
4454 inst.error = _("immediate value out of range");
4455 return FAIL;
4456 }
b99bd4ef 4457
c19d1205
ZW
4458 *val = exp.X_add_number;
4459 return SUCCESS;
4460}
b99bd4ef 4461
5287ad62 4462/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4463 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4464 instructions. Puts the result directly in inst.operands[i]. */
4465
4466static int
4467parse_big_immediate (char **str, int i)
4468{
4469 expressionS exp;
4470 char *ptr = *str;
4471
4472 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4473
4474 if (exp.X_op == O_constant)
036dc3f7
PB
4475 {
4476 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4477 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4478 O_constant. We have to be careful not to break compilation for
4479 32-bit X_add_number, though. */
58ad575f 4480 if ((exp.X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7
PB
4481 {
4482 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4483 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4484 inst.operands[i].regisimm = 1;
4485 }
4486 }
5287ad62 4487 else if (exp.X_op == O_big
95b75c01 4488 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
5287ad62
JB
4489 {
4490 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4491
5287ad62
JB
4492 /* Bignums have their least significant bits in
4493 generic_bignum[0]. Make sure we put 32 bits in imm and
4494 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4495 gas_assert (parts != 0);
95b75c01
NC
4496
4497 /* Make sure that the number is not too big.
4498 PR 11972: Bignums can now be sign-extended to the
4499 size of a .octa so check that the out of range bits
4500 are all zero or all one. */
4501 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4502 {
4503 LITTLENUM_TYPE m = -1;
4504
4505 if (generic_bignum[parts * 2] != 0
4506 && generic_bignum[parts * 2] != m)
4507 return FAIL;
4508
4509 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4510 if (generic_bignum[j] != generic_bignum[j-1])
4511 return FAIL;
4512 }
4513
5287ad62
JB
4514 inst.operands[i].imm = 0;
4515 for (j = 0; j < parts; j++, idx++)
4516 inst.operands[i].imm |= generic_bignum[idx]
4517 << (LITTLENUM_NUMBER_OF_BITS * j);
4518 inst.operands[i].reg = 0;
4519 for (j = 0; j < parts; j++, idx++)
4520 inst.operands[i].reg |= generic_bignum[idx]
4521 << (LITTLENUM_NUMBER_OF_BITS * j);
4522 inst.operands[i].regisimm = 1;
4523 }
4524 else
4525 return FAIL;
5f4273c7 4526
5287ad62
JB
4527 *str = ptr;
4528
4529 return SUCCESS;
4530}
4531
c19d1205
ZW
4532/* Returns the pseudo-register number of an FPA immediate constant,
4533 or FAIL if there isn't a valid constant here. */
b99bd4ef 4534
c19d1205
ZW
4535static int
4536parse_fpa_immediate (char ** str)
4537{
4538 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4539 char * save_in;
4540 expressionS exp;
4541 int i;
4542 int j;
b99bd4ef 4543
c19d1205
ZW
4544 /* First try and match exact strings, this is to guarantee
4545 that some formats will work even for cross assembly. */
b99bd4ef 4546
c19d1205
ZW
4547 for (i = 0; fp_const[i]; i++)
4548 {
4549 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4550 {
c19d1205 4551 char *start = *str;
b99bd4ef 4552
c19d1205
ZW
4553 *str += strlen (fp_const[i]);
4554 if (is_end_of_line[(unsigned char) **str])
4555 return i + 8;
4556 *str = start;
4557 }
4558 }
b99bd4ef 4559
c19d1205
ZW
4560 /* Just because we didn't get a match doesn't mean that the constant
4561 isn't valid, just that it is in a format that we don't
4562 automatically recognize. Try parsing it with the standard
4563 expression routines. */
b99bd4ef 4564
c19d1205 4565 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4566
c19d1205
ZW
4567 /* Look for a raw floating point number. */
4568 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4569 && is_end_of_line[(unsigned char) *save_in])
4570 {
4571 for (i = 0; i < NUM_FLOAT_VALS; i++)
4572 {
4573 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4574 {
c19d1205
ZW
4575 if (words[j] != fp_values[i][j])
4576 break;
b99bd4ef
NC
4577 }
4578
c19d1205 4579 if (j == MAX_LITTLENUMS)
b99bd4ef 4580 {
c19d1205
ZW
4581 *str = save_in;
4582 return i + 8;
b99bd4ef
NC
4583 }
4584 }
4585 }
b99bd4ef 4586
c19d1205
ZW
4587 /* Try and parse a more complex expression, this will probably fail
4588 unless the code uses a floating point prefix (eg "0f"). */
4589 save_in = input_line_pointer;
4590 input_line_pointer = *str;
4591 if (expression (&exp) == absolute_section
4592 && exp.X_op == O_big
4593 && exp.X_add_number < 0)
4594 {
4595 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4596 Ditto for 15. */
4597 if (gen_to_words (words, 5, (long) 15) == 0)
4598 {
4599 for (i = 0; i < NUM_FLOAT_VALS; i++)
4600 {
4601 for (j = 0; j < MAX_LITTLENUMS; j++)
4602 {
4603 if (words[j] != fp_values[i][j])
4604 break;
4605 }
b99bd4ef 4606
c19d1205
ZW
4607 if (j == MAX_LITTLENUMS)
4608 {
4609 *str = input_line_pointer;
4610 input_line_pointer = save_in;
4611 return i + 8;
4612 }
4613 }
4614 }
b99bd4ef
NC
4615 }
4616
c19d1205
ZW
4617 *str = input_line_pointer;
4618 input_line_pointer = save_in;
4619 inst.error = _("invalid FPA immediate expression");
4620 return FAIL;
b99bd4ef
NC
4621}
4622
136da414
JB
4623/* Returns 1 if a number has "quarter-precision" float format
4624 0baBbbbbbc defgh000 00000000 00000000. */
4625
4626static int
4627is_quarter_float (unsigned imm)
4628{
4629 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4630 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4631}
4632
4633/* Parse an 8-bit "quarter-precision" floating point number of the form:
4634 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4635 The zero and minus-zero cases need special handling, since they can't be
4636 encoded in the "quarter-precision" float format, but can nonetheless be
4637 loaded as integer constants. */
136da414
JB
4638
4639static unsigned
4640parse_qfloat_immediate (char **ccp, int *immed)
4641{
4642 char *str = *ccp;
c96612cc 4643 char *fpnum;
136da414 4644 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4645 int found_fpchar = 0;
5f4273c7 4646
136da414 4647 skip_past_char (&str, '#');
5f4273c7 4648
c96612cc
JB
4649 /* We must not accidentally parse an integer as a floating-point number. Make
4650 sure that the value we parse is not an integer by checking for special
4651 characters '.' or 'e'.
4652 FIXME: This is a horrible hack, but doing better is tricky because type
4653 information isn't in a very usable state at parse time. */
4654 fpnum = str;
4655 skip_whitespace (fpnum);
4656
4657 if (strncmp (fpnum, "0x", 2) == 0)
4658 return FAIL;
4659 else
4660 {
4661 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4662 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4663 {
4664 found_fpchar = 1;
4665 break;
4666 }
4667
4668 if (!found_fpchar)
4669 return FAIL;
4670 }
5f4273c7 4671
136da414
JB
4672 if ((str = atof_ieee (str, 's', words)) != NULL)
4673 {
4674 unsigned fpword = 0;
4675 int i;
5f4273c7 4676
136da414
JB
4677 /* Our FP word must be 32 bits (single-precision FP). */
4678 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4679 {
4680 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4681 fpword |= words[i];
4682 }
5f4273c7 4683
c96612cc 4684 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4685 *immed = fpword;
4686 else
4687 return FAIL;
4688
4689 *ccp = str;
5f4273c7 4690
136da414
JB
4691 return SUCCESS;
4692 }
5f4273c7 4693
136da414
JB
4694 return FAIL;
4695}
4696
c19d1205
ZW
4697/* Shift operands. */
4698enum shift_kind
b99bd4ef 4699{
c19d1205
ZW
4700 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4701};
b99bd4ef 4702
c19d1205
ZW
4703struct asm_shift_name
4704{
4705 const char *name;
4706 enum shift_kind kind;
4707};
b99bd4ef 4708
c19d1205
ZW
4709/* Third argument to parse_shift. */
4710enum parse_shift_mode
4711{
4712 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4713 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4714 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4715 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4716 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4717};
b99bd4ef 4718
c19d1205
ZW
4719/* Parse a <shift> specifier on an ARM data processing instruction.
4720 This has three forms:
b99bd4ef 4721
c19d1205
ZW
4722 (LSL|LSR|ASL|ASR|ROR) Rs
4723 (LSL|LSR|ASL|ASR|ROR) #imm
4724 RRX
b99bd4ef 4725
c19d1205
ZW
4726 Note that ASL is assimilated to LSL in the instruction encoding, and
4727 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4728
c19d1205
ZW
4729static int
4730parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4731{
c19d1205
ZW
4732 const struct asm_shift_name *shift_name;
4733 enum shift_kind shift;
4734 char *s = *str;
4735 char *p = s;
4736 int reg;
b99bd4ef 4737
c19d1205
ZW
4738 for (p = *str; ISALPHA (*p); p++)
4739 ;
b99bd4ef 4740
c19d1205 4741 if (p == *str)
b99bd4ef 4742 {
c19d1205
ZW
4743 inst.error = _("shift expression expected");
4744 return FAIL;
b99bd4ef
NC
4745 }
4746
21d799b5
NC
4747 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4748 p - *str);
c19d1205
ZW
4749
4750 if (shift_name == NULL)
b99bd4ef 4751 {
c19d1205
ZW
4752 inst.error = _("shift expression expected");
4753 return FAIL;
b99bd4ef
NC
4754 }
4755
c19d1205 4756 shift = shift_name->kind;
b99bd4ef 4757
c19d1205
ZW
4758 switch (mode)
4759 {
4760 case NO_SHIFT_RESTRICT:
4761 case SHIFT_IMMEDIATE: break;
b99bd4ef 4762
c19d1205
ZW
4763 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4764 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4765 {
4766 inst.error = _("'LSL' or 'ASR' required");
4767 return FAIL;
4768 }
4769 break;
b99bd4ef 4770
c19d1205
ZW
4771 case SHIFT_LSL_IMMEDIATE:
4772 if (shift != SHIFT_LSL)
4773 {
4774 inst.error = _("'LSL' required");
4775 return FAIL;
4776 }
4777 break;
b99bd4ef 4778
c19d1205
ZW
4779 case SHIFT_ASR_IMMEDIATE:
4780 if (shift != SHIFT_ASR)
4781 {
4782 inst.error = _("'ASR' required");
4783 return FAIL;
4784 }
4785 break;
b99bd4ef 4786
c19d1205
ZW
4787 default: abort ();
4788 }
b99bd4ef 4789
c19d1205
ZW
4790 if (shift != SHIFT_RRX)
4791 {
4792 /* Whitespace can appear here if the next thing is a bare digit. */
4793 skip_whitespace (p);
b99bd4ef 4794
c19d1205 4795 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4796 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4797 {
4798 inst.operands[i].imm = reg;
4799 inst.operands[i].immisreg = 1;
4800 }
4801 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4802 return FAIL;
4803 }
4804 inst.operands[i].shift_kind = shift;
4805 inst.operands[i].shifted = 1;
4806 *str = p;
4807 return SUCCESS;
b99bd4ef
NC
4808}
4809
c19d1205 4810/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4811
c19d1205
ZW
4812 #<immediate>
4813 #<immediate>, <rotate>
4814 <Rm>
4815 <Rm>, <shift>
b99bd4ef 4816
c19d1205
ZW
4817 where <shift> is defined by parse_shift above, and <rotate> is a
4818 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4819 is deferred to md_apply_fix. */
b99bd4ef 4820
c19d1205
ZW
4821static int
4822parse_shifter_operand (char **str, int i)
4823{
4824 int value;
91d6fa6a 4825 expressionS exp;
b99bd4ef 4826
dcbf9037 4827 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4828 {
4829 inst.operands[i].reg = value;
4830 inst.operands[i].isreg = 1;
b99bd4ef 4831
c19d1205
ZW
4832 /* parse_shift will override this if appropriate */
4833 inst.reloc.exp.X_op = O_constant;
4834 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4835
c19d1205
ZW
4836 if (skip_past_comma (str) == FAIL)
4837 return SUCCESS;
b99bd4ef 4838
c19d1205
ZW
4839 /* Shift operation on register. */
4840 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4841 }
4842
c19d1205
ZW
4843 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4844 return FAIL;
b99bd4ef 4845
c19d1205 4846 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4847 {
c19d1205 4848 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 4849 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 4850 return FAIL;
b99bd4ef 4851
91d6fa6a 4852 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
4853 {
4854 inst.error = _("constant expression expected");
4855 return FAIL;
4856 }
b99bd4ef 4857
91d6fa6a 4858 value = exp.X_add_number;
c19d1205
ZW
4859 if (value < 0 || value > 30 || value % 2 != 0)
4860 {
4861 inst.error = _("invalid rotation");
4862 return FAIL;
4863 }
4864 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4865 {
4866 inst.error = _("invalid constant");
4867 return FAIL;
4868 }
09d92015 4869
55cf6793 4870 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4871 inst.reloc.exp.X_add_number
4872 = (((inst.reloc.exp.X_add_number << (32 - value))
4873 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4874 }
4875
c19d1205
ZW
4876 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4877 inst.reloc.pc_rel = 0;
4878 return SUCCESS;
09d92015
MM
4879}
4880
4962c51a
MS
4881/* Group relocation information. Each entry in the table contains the
4882 textual name of the relocation as may appear in assembler source
4883 and must end with a colon.
4884 Along with this textual name are the relocation codes to be used if
4885 the corresponding instruction is an ALU instruction (ADD or SUB only),
4886 an LDR, an LDRS, or an LDC. */
4887
4888struct group_reloc_table_entry
4889{
4890 const char *name;
4891 int alu_code;
4892 int ldr_code;
4893 int ldrs_code;
4894 int ldc_code;
4895};
4896
4897typedef enum
4898{
4899 /* Varieties of non-ALU group relocation. */
4900
4901 GROUP_LDR,
4902 GROUP_LDRS,
4903 GROUP_LDC
4904} group_reloc_type;
4905
4906static struct group_reloc_table_entry group_reloc_table[] =
4907 { /* Program counter relative: */
4908 { "pc_g0_nc",
4909 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4910 0, /* LDR */
4911 0, /* LDRS */
4912 0 }, /* LDC */
4913 { "pc_g0",
4914 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4915 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4916 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4917 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4918 { "pc_g1_nc",
4919 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4920 0, /* LDR */
4921 0, /* LDRS */
4922 0 }, /* LDC */
4923 { "pc_g1",
4924 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4925 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4926 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4927 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4928 { "pc_g2",
4929 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4930 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4931 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4932 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4933 /* Section base relative */
4934 { "sb_g0_nc",
4935 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4936 0, /* LDR */
4937 0, /* LDRS */
4938 0 }, /* LDC */
4939 { "sb_g0",
4940 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4941 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4942 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4943 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4944 { "sb_g1_nc",
4945 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4946 0, /* LDR */
4947 0, /* LDRS */
4948 0 }, /* LDC */
4949 { "sb_g1",
4950 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4951 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4952 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4953 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4954 { "sb_g2",
4955 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4956 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4957 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4958 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4959
4960/* Given the address of a pointer pointing to the textual name of a group
4961 relocation as may appear in assembler source, attempt to find its details
4962 in group_reloc_table. The pointer will be updated to the character after
4963 the trailing colon. On failure, FAIL will be returned; SUCCESS
4964 otherwise. On success, *entry will be updated to point at the relevant
4965 group_reloc_table entry. */
4966
4967static int
4968find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4969{
4970 unsigned int i;
4971 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4972 {
4973 int length = strlen (group_reloc_table[i].name);
4974
5f4273c7
NC
4975 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4976 && (*str)[length] == ':')
4962c51a
MS
4977 {
4978 *out = &group_reloc_table[i];
4979 *str += (length + 1);
4980 return SUCCESS;
4981 }
4982 }
4983
4984 return FAIL;
4985}
4986
4987/* Parse a <shifter_operand> for an ARM data processing instruction
4988 (as for parse_shifter_operand) where group relocations are allowed:
4989
4990 #<immediate>
4991 #<immediate>, <rotate>
4992 #:<group_reloc>:<expression>
4993 <Rm>
4994 <Rm>, <shift>
4995
4996 where <group_reloc> is one of the strings defined in group_reloc_table.
4997 The hashes are optional.
4998
4999 Everything else is as for parse_shifter_operand. */
5000
5001static parse_operand_result
5002parse_shifter_operand_group_reloc (char **str, int i)
5003{
5004 /* Determine if we have the sequence of characters #: or just :
5005 coming next. If we do, then we check for a group relocation.
5006 If we don't, punt the whole lot to parse_shifter_operand. */
5007
5008 if (((*str)[0] == '#' && (*str)[1] == ':')
5009 || (*str)[0] == ':')
5010 {
5011 struct group_reloc_table_entry *entry;
5012
5013 if ((*str)[0] == '#')
5014 (*str) += 2;
5015 else
5016 (*str)++;
5017
5018 /* Try to parse a group relocation. Anything else is an error. */
5019 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5020 {
5021 inst.error = _("unknown group relocation");
5022 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5023 }
5024
5025 /* We now have the group relocation table entry corresponding to
5026 the name in the assembler source. Next, we parse the expression. */
5027 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
5028 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5029
5030 /* Record the relocation type (always the ALU variant here). */
21d799b5 5031 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5032 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5033
5034 return PARSE_OPERAND_SUCCESS;
5035 }
5036 else
5037 return parse_shifter_operand (str, i) == SUCCESS
5038 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5039
5040 /* Never reached. */
5041}
5042
8e560766
MGD
5043/* Parse a Neon alignment expression. Information is written to
5044 inst.operands[i]. We assume the initial ':' has been skipped.
5045
5046 align .imm = align << 8, .immisalign=1, .preind=0 */
5047static parse_operand_result
5048parse_neon_alignment (char **str, int i)
5049{
5050 char *p = *str;
5051 expressionS exp;
5052
5053 my_get_expression (&exp, &p, GE_NO_PREFIX);
5054
5055 if (exp.X_op != O_constant)
5056 {
5057 inst.error = _("alignment must be constant");
5058 return PARSE_OPERAND_FAIL;
5059 }
5060
5061 inst.operands[i].imm = exp.X_add_number << 8;
5062 inst.operands[i].immisalign = 1;
5063 /* Alignments are not pre-indexes. */
5064 inst.operands[i].preind = 0;
5065
5066 *str = p;
5067 return PARSE_OPERAND_SUCCESS;
5068}
5069
c19d1205
ZW
5070/* Parse all forms of an ARM address expression. Information is written
5071 to inst.operands[i] and/or inst.reloc.
09d92015 5072
c19d1205 5073 Preindexed addressing (.preind=1):
09d92015 5074
c19d1205
ZW
5075 [Rn, #offset] .reg=Rn .reloc.exp=offset
5076 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5077 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5078 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5079
c19d1205 5080 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5081
c19d1205 5082 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5083
c19d1205
ZW
5084 [Rn], #offset .reg=Rn .reloc.exp=offset
5085 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5086 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5087 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5088
c19d1205 5089 Unindexed addressing (.preind=0, .postind=0):
09d92015 5090
c19d1205 5091 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5092
c19d1205 5093 Other:
09d92015 5094
c19d1205
ZW
5095 [Rn]{!} shorthand for [Rn,#0]{!}
5096 =immediate .isreg=0 .reloc.exp=immediate
5097 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5098
c19d1205
ZW
5099 It is the caller's responsibility to check for addressing modes not
5100 supported by the instruction, and to set inst.reloc.type. */
5101
4962c51a
MS
5102static parse_operand_result
5103parse_address_main (char **str, int i, int group_relocations,
5104 group_reloc_type group_type)
09d92015 5105{
c19d1205
ZW
5106 char *p = *str;
5107 int reg;
09d92015 5108
c19d1205 5109 if (skip_past_char (&p, '[') == FAIL)
09d92015 5110 {
c19d1205
ZW
5111 if (skip_past_char (&p, '=') == FAIL)
5112 {
974da60d 5113 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5114 inst.reloc.pc_rel = 1;
5115 inst.operands[i].reg = REG_PC;
5116 inst.operands[i].isreg = 1;
5117 inst.operands[i].preind = 1;
5118 }
974da60d 5119 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
09d92015 5120
c19d1205 5121 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 5122 return PARSE_OPERAND_FAIL;
09d92015 5123
c19d1205 5124 *str = p;
4962c51a 5125 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5126 }
5127
dcbf9037 5128 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5129 {
c19d1205 5130 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5131 return PARSE_OPERAND_FAIL;
09d92015 5132 }
c19d1205
ZW
5133 inst.operands[i].reg = reg;
5134 inst.operands[i].isreg = 1;
09d92015 5135
c19d1205 5136 if (skip_past_comma (&p) == SUCCESS)
09d92015 5137 {
c19d1205 5138 inst.operands[i].preind = 1;
09d92015 5139
c19d1205
ZW
5140 if (*p == '+') p++;
5141 else if (*p == '-') p++, inst.operands[i].negative = 1;
5142
dcbf9037 5143 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5144 {
c19d1205
ZW
5145 inst.operands[i].imm = reg;
5146 inst.operands[i].immisreg = 1;
5147
5148 if (skip_past_comma (&p) == SUCCESS)
5149 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5150 return PARSE_OPERAND_FAIL;
c19d1205 5151 }
5287ad62 5152 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5153 {
5154 /* FIXME: '@' should be used here, but it's filtered out by generic
5155 code before we get to see it here. This may be subject to
5156 change. */
5157 parse_operand_result result = parse_neon_alignment (&p, i);
5158
5159 if (result != PARSE_OPERAND_SUCCESS)
5160 return result;
5161 }
c19d1205
ZW
5162 else
5163 {
5164 if (inst.operands[i].negative)
5165 {
5166 inst.operands[i].negative = 0;
5167 p--;
5168 }
4962c51a 5169
5f4273c7
NC
5170 if (group_relocations
5171 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5172 {
5173 struct group_reloc_table_entry *entry;
5174
5175 /* Skip over the #: or : sequence. */
5176 if (*p == '#')
5177 p += 2;
5178 else
5179 p++;
5180
5181 /* Try to parse a group relocation. Anything else is an
5182 error. */
5183 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5184 {
5185 inst.error = _("unknown group relocation");
5186 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5187 }
5188
5189 /* We now have the group relocation table entry corresponding to
5190 the name in the assembler source. Next, we parse the
5191 expression. */
5192 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5193 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5194
5195 /* Record the relocation type. */
5196 switch (group_type)
5197 {
5198 case GROUP_LDR:
21d799b5 5199 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
4962c51a
MS
5200 break;
5201
5202 case GROUP_LDRS:
21d799b5 5203 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
4962c51a
MS
5204 break;
5205
5206 case GROUP_LDC:
21d799b5 5207 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
4962c51a
MS
5208 break;
5209
5210 default:
9c2799c2 5211 gas_assert (0);
4962c51a
MS
5212 }
5213
5214 if (inst.reloc.type == 0)
5215 {
5216 inst.error = _("this group relocation is not allowed on this instruction");
5217 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5218 }
5219 }
5220 else
26d97720
NS
5221 {
5222 char *q = p;
5223 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5224 return PARSE_OPERAND_FAIL;
5225 /* If the offset is 0, find out if it's a +0 or -0. */
5226 if (inst.reloc.exp.X_op == O_constant
5227 && inst.reloc.exp.X_add_number == 0)
5228 {
5229 skip_whitespace (q);
5230 if (*q == '#')
5231 {
5232 q++;
5233 skip_whitespace (q);
5234 }
5235 if (*q == '-')
5236 inst.operands[i].negative = 1;
5237 }
5238 }
09d92015
MM
5239 }
5240 }
8e560766
MGD
5241 else if (skip_past_char (&p, ':') == SUCCESS)
5242 {
5243 /* FIXME: '@' should be used here, but it's filtered out by generic code
5244 before we get to see it here. This may be subject to change. */
5245 parse_operand_result result = parse_neon_alignment (&p, i);
5246
5247 if (result != PARSE_OPERAND_SUCCESS)
5248 return result;
5249 }
09d92015 5250
c19d1205 5251 if (skip_past_char (&p, ']') == FAIL)
09d92015 5252 {
c19d1205 5253 inst.error = _("']' expected");
4962c51a 5254 return PARSE_OPERAND_FAIL;
09d92015
MM
5255 }
5256
c19d1205
ZW
5257 if (skip_past_char (&p, '!') == SUCCESS)
5258 inst.operands[i].writeback = 1;
09d92015 5259
c19d1205 5260 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5261 {
c19d1205
ZW
5262 if (skip_past_char (&p, '{') == SUCCESS)
5263 {
5264 /* [Rn], {expr} - unindexed, with option */
5265 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5266 0, 255, TRUE) == FAIL)
4962c51a 5267 return PARSE_OPERAND_FAIL;
09d92015 5268
c19d1205
ZW
5269 if (skip_past_char (&p, '}') == FAIL)
5270 {
5271 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5272 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5273 }
5274 if (inst.operands[i].preind)
5275 {
5276 inst.error = _("cannot combine index with option");
4962c51a 5277 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5278 }
5279 *str = p;
4962c51a 5280 return PARSE_OPERAND_SUCCESS;
09d92015 5281 }
c19d1205
ZW
5282 else
5283 {
5284 inst.operands[i].postind = 1;
5285 inst.operands[i].writeback = 1;
09d92015 5286
c19d1205
ZW
5287 if (inst.operands[i].preind)
5288 {
5289 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5290 return PARSE_OPERAND_FAIL;
c19d1205 5291 }
09d92015 5292
c19d1205
ZW
5293 if (*p == '+') p++;
5294 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5295
dcbf9037 5296 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5297 {
5287ad62
JB
5298 /* We might be using the immediate for alignment already. If we
5299 are, OR the register number into the low-order bits. */
5300 if (inst.operands[i].immisalign)
5301 inst.operands[i].imm |= reg;
5302 else
5303 inst.operands[i].imm = reg;
c19d1205 5304 inst.operands[i].immisreg = 1;
a737bd4d 5305
c19d1205
ZW
5306 if (skip_past_comma (&p) == SUCCESS)
5307 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5308 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5309 }
5310 else
5311 {
26d97720 5312 char *q = p;
c19d1205
ZW
5313 if (inst.operands[i].negative)
5314 {
5315 inst.operands[i].negative = 0;
5316 p--;
5317 }
5318 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5319 return PARSE_OPERAND_FAIL;
26d97720
NS
5320 /* If the offset is 0, find out if it's a +0 or -0. */
5321 if (inst.reloc.exp.X_op == O_constant
5322 && inst.reloc.exp.X_add_number == 0)
5323 {
5324 skip_whitespace (q);
5325 if (*q == '#')
5326 {
5327 q++;
5328 skip_whitespace (q);
5329 }
5330 if (*q == '-')
5331 inst.operands[i].negative = 1;
5332 }
c19d1205
ZW
5333 }
5334 }
a737bd4d
NC
5335 }
5336
c19d1205
ZW
5337 /* If at this point neither .preind nor .postind is set, we have a
5338 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5339 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5340 {
5341 inst.operands[i].preind = 1;
5342 inst.reloc.exp.X_op = O_constant;
5343 inst.reloc.exp.X_add_number = 0;
5344 }
5345 *str = p;
4962c51a
MS
5346 return PARSE_OPERAND_SUCCESS;
5347}
5348
5349static int
5350parse_address (char **str, int i)
5351{
21d799b5 5352 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
4962c51a
MS
5353 ? SUCCESS : FAIL;
5354}
5355
5356static parse_operand_result
5357parse_address_group_reloc (char **str, int i, group_reloc_type type)
5358{
5359 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5360}
5361
b6895b4f
PB
5362/* Parse an operand for a MOVW or MOVT instruction. */
5363static int
5364parse_half (char **str)
5365{
5366 char * p;
5f4273c7 5367
b6895b4f
PB
5368 p = *str;
5369 skip_past_char (&p, '#');
5f4273c7 5370 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5371 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5372 else if (strncasecmp (p, ":upper16:", 9) == 0)
5373 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5374
5375 if (inst.reloc.type != BFD_RELOC_UNUSED)
5376 {
5377 p += 9;
5f4273c7 5378 skip_whitespace (p);
b6895b4f
PB
5379 }
5380
5381 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5382 return FAIL;
5383
5384 if (inst.reloc.type == BFD_RELOC_UNUSED)
5385 {
5386 if (inst.reloc.exp.X_op != O_constant)
5387 {
5388 inst.error = _("constant expression expected");
5389 return FAIL;
5390 }
5391 if (inst.reloc.exp.X_add_number < 0
5392 || inst.reloc.exp.X_add_number > 0xffff)
5393 {
5394 inst.error = _("immediate value out of range");
5395 return FAIL;
5396 }
5397 }
5398 *str = p;
5399 return SUCCESS;
5400}
5401
c19d1205 5402/* Miscellaneous. */
a737bd4d 5403
c19d1205
ZW
5404/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5405 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5406static int
d2cd1205 5407parse_psr (char **str, bfd_boolean lhs)
09d92015 5408{
c19d1205
ZW
5409 char *p;
5410 unsigned long psr_field;
62b3e311
PB
5411 const struct asm_psr *psr;
5412 char *start;
d2cd1205 5413 bfd_boolean is_apsr = FALSE;
ac7f631b 5414 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5415
a4482bb6
NC
5416 /* PR gas/12698: If the user has specified -march=all then m_profile will
5417 be TRUE, but we want to ignore it in this case as we are building for any
5418 CPU type, including non-m variants. */
5419 if (selected_cpu.core == arm_arch_any.core)
5420 m_profile = FALSE;
5421
c19d1205
ZW
5422 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5423 feature for ease of use and backwards compatibility. */
5424 p = *str;
62b3e311 5425 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5426 {
5427 if (m_profile)
5428 goto unsupported_psr;
5429
5430 psr_field = SPSR_BIT;
5431 }
5432 else if (strncasecmp (p, "CPSR", 4) == 0)
5433 {
5434 if (m_profile)
5435 goto unsupported_psr;
5436
5437 psr_field = 0;
5438 }
5439 else if (strncasecmp (p, "APSR", 4) == 0)
5440 {
5441 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5442 and ARMv7-R architecture CPUs. */
5443 is_apsr = TRUE;
5444 psr_field = 0;
5445 }
5446 else if (m_profile)
62b3e311
PB
5447 {
5448 start = p;
5449 do
5450 p++;
5451 while (ISALNUM (*p) || *p == '_');
5452
d2cd1205
JB
5453 if (strncasecmp (start, "iapsr", 5) == 0
5454 || strncasecmp (start, "eapsr", 5) == 0
5455 || strncasecmp (start, "xpsr", 4) == 0
5456 || strncasecmp (start, "psr", 3) == 0)
5457 p = start + strcspn (start, "rR") + 1;
5458
21d799b5
NC
5459 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5460 p - start);
d2cd1205 5461
62b3e311
PB
5462 if (!psr)
5463 return FAIL;
09d92015 5464
d2cd1205
JB
5465 /* If APSR is being written, a bitfield may be specified. Note that
5466 APSR itself is handled above. */
5467 if (psr->field <= 3)
5468 {
5469 psr_field = psr->field;
5470 is_apsr = TRUE;
5471 goto check_suffix;
5472 }
5473
62b3e311 5474 *str = p;
d2cd1205
JB
5475 /* M-profile MSR instructions have the mask field set to "10", except
5476 *PSR variants which modify APSR, which may use a different mask (and
5477 have been handled already). Do that by setting the PSR_f field
5478 here. */
5479 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5480 }
d2cd1205
JB
5481 else
5482 goto unsupported_psr;
09d92015 5483
62b3e311 5484 p += 4;
d2cd1205 5485check_suffix:
c19d1205
ZW
5486 if (*p == '_')
5487 {
5488 /* A suffix follows. */
c19d1205
ZW
5489 p++;
5490 start = p;
a737bd4d 5491
c19d1205
ZW
5492 do
5493 p++;
5494 while (ISALNUM (*p) || *p == '_');
a737bd4d 5495
d2cd1205
JB
5496 if (is_apsr)
5497 {
5498 /* APSR uses a notation for bits, rather than fields. */
5499 unsigned int nzcvq_bits = 0;
5500 unsigned int g_bit = 0;
5501 char *bit;
5502
5503 for (bit = start; bit != p; bit++)
5504 {
5505 switch (TOLOWER (*bit))
5506 {
5507 case 'n':
5508 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5509 break;
5510
5511 case 'z':
5512 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5513 break;
5514
5515 case 'c':
5516 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5517 break;
5518
5519 case 'v':
5520 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5521 break;
5522
5523 case 'q':
5524 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5525 break;
5526
5527 case 'g':
5528 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5529 break;
5530
5531 default:
5532 inst.error = _("unexpected bit specified after APSR");
5533 return FAIL;
5534 }
5535 }
5536
5537 if (nzcvq_bits == 0x1f)
5538 psr_field |= PSR_f;
5539
5540 if (g_bit == 0x1)
5541 {
5542 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
5543 {
5544 inst.error = _("selected processor does not "
5545 "support DSP extension");
5546 return FAIL;
5547 }
5548
5549 psr_field |= PSR_s;
5550 }
5551
5552 if ((nzcvq_bits & 0x20) != 0
5553 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5554 || (g_bit & 0x2) != 0)
5555 {
5556 inst.error = _("bad bitmask specified after APSR");
5557 return FAIL;
5558 }
5559 }
5560 else
5561 {
5562 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5563 p - start);
5564 if (!psr)
5565 goto error;
a737bd4d 5566
d2cd1205
JB
5567 psr_field |= psr->field;
5568 }
a737bd4d 5569 }
c19d1205 5570 else
a737bd4d 5571 {
c19d1205
ZW
5572 if (ISALNUM (*p))
5573 goto error; /* Garbage after "[CS]PSR". */
5574
d2cd1205
JB
5575 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
5576 is deprecated, but allow it anyway. */
5577 if (is_apsr && lhs)
5578 {
5579 psr_field |= PSR_f;
5580 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5581 "deprecated"));
5582 }
5583 else if (!m_profile)
5584 /* These bits are never right for M-profile devices: don't set them
5585 (only code paths which read/write APSR reach here). */
5586 psr_field |= (PSR_c | PSR_f);
a737bd4d 5587 }
c19d1205
ZW
5588 *str = p;
5589 return psr_field;
a737bd4d 5590
d2cd1205
JB
5591 unsupported_psr:
5592 inst.error = _("selected processor does not support requested special "
5593 "purpose register");
5594 return FAIL;
5595
c19d1205
ZW
5596 error:
5597 inst.error = _("flag for {c}psr instruction expected");
5598 return FAIL;
a737bd4d
NC
5599}
5600
c19d1205
ZW
5601/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5602 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5603
c19d1205
ZW
5604static int
5605parse_cps_flags (char **str)
a737bd4d 5606{
c19d1205
ZW
5607 int val = 0;
5608 int saw_a_flag = 0;
5609 char *s = *str;
a737bd4d 5610
c19d1205
ZW
5611 for (;;)
5612 switch (*s++)
5613 {
5614 case '\0': case ',':
5615 goto done;
a737bd4d 5616
c19d1205
ZW
5617 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5618 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5619 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5620
c19d1205
ZW
5621 default:
5622 inst.error = _("unrecognized CPS flag");
5623 return FAIL;
5624 }
a737bd4d 5625
c19d1205
ZW
5626 done:
5627 if (saw_a_flag == 0)
a737bd4d 5628 {
c19d1205
ZW
5629 inst.error = _("missing CPS flags");
5630 return FAIL;
a737bd4d 5631 }
a737bd4d 5632
c19d1205
ZW
5633 *str = s - 1;
5634 return val;
a737bd4d
NC
5635}
5636
c19d1205
ZW
5637/* Parse an endian specifier ("BE" or "LE", case insensitive);
5638 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5639
5640static int
c19d1205 5641parse_endian_specifier (char **str)
a737bd4d 5642{
c19d1205
ZW
5643 int little_endian;
5644 char *s = *str;
a737bd4d 5645
c19d1205
ZW
5646 if (strncasecmp (s, "BE", 2))
5647 little_endian = 0;
5648 else if (strncasecmp (s, "LE", 2))
5649 little_endian = 1;
5650 else
a737bd4d 5651 {
c19d1205 5652 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5653 return FAIL;
5654 }
5655
c19d1205 5656 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5657 {
c19d1205 5658 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5659 return FAIL;
5660 }
5661
c19d1205
ZW
5662 *str = s + 2;
5663 return little_endian;
5664}
a737bd4d 5665
c19d1205
ZW
5666/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5667 value suitable for poking into the rotate field of an sxt or sxta
5668 instruction, or FAIL on error. */
5669
5670static int
5671parse_ror (char **str)
5672{
5673 int rot;
5674 char *s = *str;
5675
5676 if (strncasecmp (s, "ROR", 3) == 0)
5677 s += 3;
5678 else
a737bd4d 5679 {
c19d1205 5680 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5681 return FAIL;
5682 }
c19d1205
ZW
5683
5684 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5685 return FAIL;
5686
5687 switch (rot)
a737bd4d 5688 {
c19d1205
ZW
5689 case 0: *str = s; return 0x0;
5690 case 8: *str = s; return 0x1;
5691 case 16: *str = s; return 0x2;
5692 case 24: *str = s; return 0x3;
5693
5694 default:
5695 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5696 return FAIL;
5697 }
c19d1205 5698}
a737bd4d 5699
c19d1205
ZW
5700/* Parse a conditional code (from conds[] below). The value returned is in the
5701 range 0 .. 14, or FAIL. */
5702static int
5703parse_cond (char **str)
5704{
c462b453 5705 char *q;
c19d1205 5706 const struct asm_cond *c;
c462b453
PB
5707 int n;
5708 /* Condition codes are always 2 characters, so matching up to
5709 3 characters is sufficient. */
5710 char cond[3];
a737bd4d 5711
c462b453
PB
5712 q = *str;
5713 n = 0;
5714 while (ISALPHA (*q) && n < 3)
5715 {
e07e6e58 5716 cond[n] = TOLOWER (*q);
c462b453
PB
5717 q++;
5718 n++;
5719 }
a737bd4d 5720
21d799b5 5721 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5722 if (!c)
a737bd4d 5723 {
c19d1205 5724 inst.error = _("condition required");
a737bd4d
NC
5725 return FAIL;
5726 }
5727
c19d1205
ZW
5728 *str = q;
5729 return c->value;
5730}
5731
62b3e311
PB
5732/* Parse an option for a barrier instruction. Returns the encoding for the
5733 option, or FAIL. */
5734static int
5735parse_barrier (char **str)
5736{
5737 char *p, *q;
5738 const struct asm_barrier_opt *o;
5739
5740 p = q = *str;
5741 while (ISALPHA (*q))
5742 q++;
5743
21d799b5
NC
5744 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5745 q - p);
62b3e311
PB
5746 if (!o)
5747 return FAIL;
5748
5749 *str = q;
5750 return o->value;
5751}
5752
92e90b6e
PB
5753/* Parse the operands of a table branch instruction. Similar to a memory
5754 operand. */
5755static int
5756parse_tb (char **str)
5757{
5758 char * p = *str;
5759 int reg;
5760
5761 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5762 {
5763 inst.error = _("'[' expected");
5764 return FAIL;
5765 }
92e90b6e 5766
dcbf9037 5767 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5768 {
5769 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5770 return FAIL;
5771 }
5772 inst.operands[0].reg = reg;
5773
5774 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5775 {
5776 inst.error = _("',' expected");
5777 return FAIL;
5778 }
5f4273c7 5779
dcbf9037 5780 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5781 {
5782 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5783 return FAIL;
5784 }
5785 inst.operands[0].imm = reg;
5786
5787 if (skip_past_comma (&p) == SUCCESS)
5788 {
5789 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5790 return FAIL;
5791 if (inst.reloc.exp.X_add_number != 1)
5792 {
5793 inst.error = _("invalid shift");
5794 return FAIL;
5795 }
5796 inst.operands[0].shifted = 1;
5797 }
5798
5799 if (skip_past_char (&p, ']') == FAIL)
5800 {
5801 inst.error = _("']' expected");
5802 return FAIL;
5803 }
5804 *str = p;
5805 return SUCCESS;
5806}
5807
5287ad62
JB
5808/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5809 information on the types the operands can take and how they are encoded.
037e8744
JB
5810 Up to four operands may be read; this function handles setting the
5811 ".present" field for each read operand itself.
5287ad62
JB
5812 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5813 else returns FAIL. */
5814
5815static int
5816parse_neon_mov (char **str, int *which_operand)
5817{
5818 int i = *which_operand, val;
5819 enum arm_reg_type rtype;
5820 char *ptr = *str;
dcbf9037 5821 struct neon_type_el optype;
5f4273c7 5822
dcbf9037 5823 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5824 {
5825 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5826 inst.operands[i].reg = val;
5827 inst.operands[i].isscalar = 1;
dcbf9037 5828 inst.operands[i].vectype = optype;
5287ad62
JB
5829 inst.operands[i++].present = 1;
5830
5831 if (skip_past_comma (&ptr) == FAIL)
5832 goto wanted_comma;
5f4273c7 5833
dcbf9037 5834 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5835 goto wanted_arm;
5f4273c7 5836
5287ad62
JB
5837 inst.operands[i].reg = val;
5838 inst.operands[i].isreg = 1;
5839 inst.operands[i].present = 1;
5840 }
037e8744 5841 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5842 != FAIL)
5287ad62
JB
5843 {
5844 /* Cases 0, 1, 2, 3, 5 (D only). */
5845 if (skip_past_comma (&ptr) == FAIL)
5846 goto wanted_comma;
5f4273c7 5847
5287ad62
JB
5848 inst.operands[i].reg = val;
5849 inst.operands[i].isreg = 1;
5850 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5851 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5852 inst.operands[i].isvec = 1;
dcbf9037 5853 inst.operands[i].vectype = optype;
5287ad62
JB
5854 inst.operands[i++].present = 1;
5855
dcbf9037 5856 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5857 {
037e8744
JB
5858 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5859 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5860 inst.operands[i].reg = val;
5861 inst.operands[i].isreg = 1;
037e8744 5862 inst.operands[i].present = 1;
5287ad62
JB
5863
5864 if (rtype == REG_TYPE_NQ)
5865 {
dcbf9037 5866 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5867 return FAIL;
5868 }
037e8744
JB
5869 else if (rtype != REG_TYPE_VFS)
5870 {
5871 i++;
5872 if (skip_past_comma (&ptr) == FAIL)
5873 goto wanted_comma;
5874 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5875 goto wanted_arm;
5876 inst.operands[i].reg = val;
5877 inst.operands[i].isreg = 1;
5878 inst.operands[i].present = 1;
5879 }
5287ad62 5880 }
037e8744
JB
5881 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5882 &optype)) != FAIL)
5287ad62
JB
5883 {
5884 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5885 Case 1: VMOV<c><q> <Dd>, <Dm>
5886 Case 8: VMOV.F32 <Sd>, <Sm>
5887 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5888
5889 inst.operands[i].reg = val;
5890 inst.operands[i].isreg = 1;
5891 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5892 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5893 inst.operands[i].isvec = 1;
dcbf9037 5894 inst.operands[i].vectype = optype;
5287ad62 5895 inst.operands[i].present = 1;
5f4273c7 5896
037e8744
JB
5897 if (skip_past_comma (&ptr) == SUCCESS)
5898 {
5899 /* Case 15. */
5900 i++;
5901
5902 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5903 goto wanted_arm;
5904
5905 inst.operands[i].reg = val;
5906 inst.operands[i].isreg = 1;
5907 inst.operands[i++].present = 1;
5f4273c7 5908
037e8744
JB
5909 if (skip_past_comma (&ptr) == FAIL)
5910 goto wanted_comma;
5f4273c7 5911
037e8744
JB
5912 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5913 goto wanted_arm;
5f4273c7 5914
037e8744
JB
5915 inst.operands[i].reg = val;
5916 inst.operands[i].isreg = 1;
5917 inst.operands[i++].present = 1;
5918 }
5287ad62 5919 }
4641781c
PB
5920 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5921 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5922 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5923 Case 10: VMOV.F32 <Sd>, #<imm>
5924 Case 11: VMOV.F64 <Dd>, #<imm> */
5925 inst.operands[i].immisfloat = 1;
5926 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5927 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5928 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5929 ;
5287ad62
JB
5930 else
5931 {
dcbf9037 5932 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5933 return FAIL;
5934 }
5935 }
dcbf9037 5936 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5937 {
5938 /* Cases 6, 7. */
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
dcbf9037 5946 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5947 {
5948 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5949 inst.operands[i].reg = val;
5950 inst.operands[i].isscalar = 1;
5951 inst.operands[i].present = 1;
dcbf9037 5952 inst.operands[i].vectype = optype;
5287ad62 5953 }
dcbf9037 5954 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5955 {
5956 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5957 inst.operands[i].reg = val;
5958 inst.operands[i].isreg = 1;
5959 inst.operands[i++].present = 1;
5f4273c7 5960
5287ad62
JB
5961 if (skip_past_comma (&ptr) == FAIL)
5962 goto wanted_comma;
5f4273c7 5963
037e8744 5964 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5965 == FAIL)
5287ad62 5966 {
037e8744 5967 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5968 return FAIL;
5969 }
5970
5971 inst.operands[i].reg = val;
5972 inst.operands[i].isreg = 1;
037e8744
JB
5973 inst.operands[i].isvec = 1;
5974 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5975 inst.operands[i].vectype = optype;
5287ad62 5976 inst.operands[i].present = 1;
5f4273c7 5977
037e8744
JB
5978 if (rtype == REG_TYPE_VFS)
5979 {
5980 /* Case 14. */
5981 i++;
5982 if (skip_past_comma (&ptr) == FAIL)
5983 goto wanted_comma;
5984 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5985 &optype)) == FAIL)
5986 {
5987 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5988 return FAIL;
5989 }
5990 inst.operands[i].reg = val;
5991 inst.operands[i].isreg = 1;
5992 inst.operands[i].isvec = 1;
5993 inst.operands[i].issingle = 1;
5994 inst.operands[i].vectype = optype;
5995 inst.operands[i].present = 1;
5996 }
5997 }
5998 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5999 != FAIL)
6000 {
6001 /* Case 13. */
6002 inst.operands[i].reg = val;
6003 inst.operands[i].isreg = 1;
6004 inst.operands[i].isvec = 1;
6005 inst.operands[i].issingle = 1;
6006 inst.operands[i].vectype = optype;
6007 inst.operands[i++].present = 1;
5287ad62
JB
6008 }
6009 }
6010 else
6011 {
dcbf9037 6012 first_error (_("parse error"));
5287ad62
JB
6013 return FAIL;
6014 }
6015
6016 /* Successfully parsed the operands. Update args. */
6017 *which_operand = i;
6018 *str = ptr;
6019 return SUCCESS;
6020
5f4273c7 6021 wanted_comma:
dcbf9037 6022 first_error (_("expected comma"));
5287ad62 6023 return FAIL;
5f4273c7
NC
6024
6025 wanted_arm:
dcbf9037 6026 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6027 return FAIL;
5287ad62
JB
6028}
6029
5be8be5d
DG
6030/* Use this macro when the operand constraints are different
6031 for ARM and THUMB (e.g. ldrd). */
6032#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6033 ((arm_operand) | ((thumb_operand) << 16))
6034
c19d1205
ZW
6035/* Matcher codes for parse_operands. */
6036enum operand_parse_code
6037{
6038 OP_stop, /* end of line */
6039
6040 OP_RR, /* ARM register */
6041 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6042 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6043 OP_RRnpcb, /* ARM register, not r15, in square brackets */
55881a11
MGD
6044 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
6045 optional trailing ! */
c19d1205
ZW
6046 OP_RRw, /* ARM register, not r15, optional trailing ! */
6047 OP_RCP, /* Coprocessor number */
6048 OP_RCN, /* Coprocessor register */
6049 OP_RF, /* FPA register */
6050 OP_RVS, /* VFP single precision register */
5287ad62
JB
6051 OP_RVD, /* VFP double precision register (0..15) */
6052 OP_RND, /* Neon double precision register (0..31) */
6053 OP_RNQ, /* Neon quad precision register */
037e8744 6054 OP_RVSD, /* VFP single or double precision register */
5287ad62 6055 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6056 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6057 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6058 OP_RVC, /* VFP control register */
6059 OP_RMF, /* Maverick F register */
6060 OP_RMD, /* Maverick D register */
6061 OP_RMFX, /* Maverick FX register */
6062 OP_RMDX, /* Maverick DX register */
6063 OP_RMAX, /* Maverick AX register */
6064 OP_RMDS, /* Maverick DSPSC register */
6065 OP_RIWR, /* iWMMXt wR register */
6066 OP_RIWC, /* iWMMXt wC register */
6067 OP_RIWG, /* iWMMXt wCG register */
6068 OP_RXA, /* XScale accumulator register */
6069
6070 OP_REGLST, /* ARM register list */
6071 OP_VRSLST, /* VFP single-precision register list */
6072 OP_VRDLST, /* VFP double-precision register list */
037e8744 6073 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6074 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6075 OP_NSTRLST, /* Neon element/structure list */
6076
5287ad62 6077 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6078 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 6079 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6080 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6081 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6082 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6083 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6084 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6085 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6086 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6087
6088 OP_I0, /* immediate zero */
c19d1205
ZW
6089 OP_I7, /* immediate value 0 .. 7 */
6090 OP_I15, /* 0 .. 15 */
6091 OP_I16, /* 1 .. 16 */
5287ad62 6092 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6093 OP_I31, /* 0 .. 31 */
6094 OP_I31w, /* 0 .. 31, optional trailing ! */
6095 OP_I32, /* 1 .. 32 */
5287ad62
JB
6096 OP_I32z, /* 0 .. 32 */
6097 OP_I63, /* 0 .. 63 */
c19d1205 6098 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6099 OP_I64, /* 1 .. 64 */
6100 OP_I64z, /* 0 .. 64 */
c19d1205 6101 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6102
6103 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6104 OP_I7b, /* 0 .. 7 */
6105 OP_I15b, /* 0 .. 15 */
6106 OP_I31b, /* 0 .. 31 */
6107
6108 OP_SH, /* shifter operand */
4962c51a 6109 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6110 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6111 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6112 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6113 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6114 OP_EXP, /* arbitrary expression */
6115 OP_EXPi, /* same, with optional immediate prefix */
6116 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6117 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6118
6119 OP_CPSF, /* CPS flags */
6120 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6121 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6122 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6123 OP_COND, /* conditional code */
92e90b6e 6124 OP_TB, /* Table branch. */
c19d1205 6125
037e8744
JB
6126 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6127
c19d1205
ZW
6128 OP_RRnpc_I0, /* ARM register or literal 0 */
6129 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6130 OP_RR_EXi, /* ARM register or expression with imm prefix */
6131 OP_RF_IF, /* FPA register or immediate */
6132 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6133 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6134
6135 /* Optional operands. */
6136 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6137 OP_oI31b, /* 0 .. 31 */
5287ad62 6138 OP_oI32b, /* 1 .. 32 */
5f1af56b 6139 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6140 OP_oIffffb, /* 0 .. 65535 */
6141 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6142
6143 OP_oRR, /* ARM register */
6144 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6145 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6146 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6147 OP_oRND, /* Optional Neon double precision register */
6148 OP_oRNQ, /* Optional Neon quad precision register */
6149 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6150 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6151 OP_oSHll, /* LSL immediate */
6152 OP_oSHar, /* ASR immediate */
6153 OP_oSHllar, /* LSL or ASR immediate */
6154 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6155 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6156
5be8be5d
DG
6157 /* Some pre-defined mixed (ARM/THUMB) operands. */
6158 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6159 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6160 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6161
c19d1205
ZW
6162 OP_FIRST_OPTIONAL = OP_oI7b
6163};
a737bd4d 6164
c19d1205
ZW
6165/* Generic instruction operand parser. This does no encoding and no
6166 semantic validation; it merely squirrels values away in the inst
6167 structure. Returns SUCCESS or FAIL depending on whether the
6168 specified grammar matched. */
6169static int
5be8be5d 6170parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6171{
5be8be5d 6172 unsigned const int *upat = pattern;
c19d1205
ZW
6173 char *backtrack_pos = 0;
6174 const char *backtrack_error = 0;
6175 int i, val, backtrack_index = 0;
5287ad62 6176 enum arm_reg_type rtype;
4962c51a 6177 parse_operand_result result;
5be8be5d 6178 unsigned int op_parse_code;
c19d1205 6179
e07e6e58
NC
6180#define po_char_or_fail(chr) \
6181 do \
6182 { \
6183 if (skip_past_char (&str, chr) == FAIL) \
6184 goto bad_args; \
6185 } \
6186 while (0)
c19d1205 6187
e07e6e58
NC
6188#define po_reg_or_fail(regtype) \
6189 do \
dcbf9037 6190 { \
e07e6e58
NC
6191 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6192 & inst.operands[i].vectype); \
6193 if (val == FAIL) \
6194 { \
6195 first_error (_(reg_expected_msgs[regtype])); \
6196 goto failure; \
6197 } \
6198 inst.operands[i].reg = val; \
6199 inst.operands[i].isreg = 1; \
6200 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6201 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6202 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6203 || rtype == REG_TYPE_VFD \
6204 || rtype == REG_TYPE_NQ); \
dcbf9037 6205 } \
e07e6e58
NC
6206 while (0)
6207
6208#define po_reg_or_goto(regtype, label) \
6209 do \
6210 { \
6211 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6212 & inst.operands[i].vectype); \
6213 if (val == FAIL) \
6214 goto label; \
dcbf9037 6215 \
e07e6e58
NC
6216 inst.operands[i].reg = val; \
6217 inst.operands[i].isreg = 1; \
6218 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6219 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6220 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6221 || rtype == REG_TYPE_VFD \
6222 || rtype == REG_TYPE_NQ); \
6223 } \
6224 while (0)
6225
6226#define po_imm_or_fail(min, max, popt) \
6227 do \
6228 { \
6229 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6230 goto failure; \
6231 inst.operands[i].imm = val; \
6232 } \
6233 while (0)
6234
6235#define po_scalar_or_goto(elsz, label) \
6236 do \
6237 { \
6238 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6239 if (val == FAIL) \
6240 goto label; \
6241 inst.operands[i].reg = val; \
6242 inst.operands[i].isscalar = 1; \
6243 } \
6244 while (0)
6245
6246#define po_misc_or_fail(expr) \
6247 do \
6248 { \
6249 if (expr) \
6250 goto failure; \
6251 } \
6252 while (0)
6253
6254#define po_misc_or_fail_no_backtrack(expr) \
6255 do \
6256 { \
6257 result = expr; \
6258 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6259 backtrack_pos = 0; \
6260 if (result != PARSE_OPERAND_SUCCESS) \
6261 goto failure; \
6262 } \
6263 while (0)
4962c51a 6264
52e7f43d
RE
6265#define po_barrier_or_imm(str) \
6266 do \
6267 { \
6268 val = parse_barrier (&str); \
6269 if (val == FAIL) \
6270 { \
6271 if (ISALPHA (*str)) \
6272 goto failure; \
6273 else \
6274 goto immediate; \
6275 } \
6276 else \
6277 { \
6278 if ((inst.instruction & 0xf0) == 0x60 \
6279 && val != 0xf) \
6280 { \
6281 /* ISB can only take SY as an option. */ \
6282 inst.error = _("invalid barrier type"); \
6283 goto failure; \
6284 } \
6285 } \
6286 } \
6287 while (0)
6288
c19d1205
ZW
6289 skip_whitespace (str);
6290
6291 for (i = 0; upat[i] != OP_stop; i++)
6292 {
5be8be5d
DG
6293 op_parse_code = upat[i];
6294 if (op_parse_code >= 1<<16)
6295 op_parse_code = thumb ? (op_parse_code >> 16)
6296 : (op_parse_code & ((1<<16)-1));
6297
6298 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6299 {
6300 /* Remember where we are in case we need to backtrack. */
9c2799c2 6301 gas_assert (!backtrack_pos);
c19d1205
ZW
6302 backtrack_pos = str;
6303 backtrack_error = inst.error;
6304 backtrack_index = i;
6305 }
6306
b6702015 6307 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6308 po_char_or_fail (',');
6309
5be8be5d 6310 switch (op_parse_code)
c19d1205
ZW
6311 {
6312 /* Registers */
6313 case OP_oRRnpc:
5be8be5d 6314 case OP_oRRnpcsp:
c19d1205 6315 case OP_RRnpc:
5be8be5d 6316 case OP_RRnpcsp:
c19d1205
ZW
6317 case OP_oRR:
6318 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6319 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6320 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6321 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6322 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6323 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
6324 case OP_oRND:
6325 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6326 case OP_RVC:
6327 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6328 break;
6329 /* Also accept generic coprocessor regs for unknown registers. */
6330 coproc_reg:
6331 po_reg_or_fail (REG_TYPE_CN);
6332 break;
c19d1205
ZW
6333 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6334 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6335 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6336 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6337 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6338 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6339 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6340 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6341 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6342 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
6343 case OP_oRNQ:
6344 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6345 case OP_oRNDQ:
6346 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
6347 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6348 case OP_oRNSDQ:
6349 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
6350
6351 /* Neon scalar. Using an element size of 8 means that some invalid
6352 scalars are accepted here, so deal with those in later code. */
6353 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6354
5287ad62
JB
6355 case OP_RNDQ_I0:
6356 {
6357 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6358 break;
6359 try_imm0:
6360 po_imm_or_fail (0, 0, TRUE);
6361 }
6362 break;
6363
037e8744
JB
6364 case OP_RVSD_I0:
6365 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6366 break;
6367
5287ad62
JB
6368 case OP_RR_RNSC:
6369 {
6370 po_scalar_or_goto (8, try_rr);
6371 break;
6372 try_rr:
6373 po_reg_or_fail (REG_TYPE_RN);
6374 }
6375 break;
6376
037e8744
JB
6377 case OP_RNSDQ_RNSC:
6378 {
6379 po_scalar_or_goto (8, try_nsdq);
6380 break;
6381 try_nsdq:
6382 po_reg_or_fail (REG_TYPE_NSDQ);
6383 }
6384 break;
6385
5287ad62
JB
6386 case OP_RNDQ_RNSC:
6387 {
6388 po_scalar_or_goto (8, try_ndq);
6389 break;
6390 try_ndq:
6391 po_reg_or_fail (REG_TYPE_NDQ);
6392 }
6393 break;
6394
6395 case OP_RND_RNSC:
6396 {
6397 po_scalar_or_goto (8, try_vfd);
6398 break;
6399 try_vfd:
6400 po_reg_or_fail (REG_TYPE_VFD);
6401 }
6402 break;
6403
6404 case OP_VMOV:
6405 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6406 not careful then bad things might happen. */
6407 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6408 break;
6409
4316f0d2 6410 case OP_RNDQ_Ibig:
5287ad62 6411 {
4316f0d2 6412 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
5287ad62 6413 break;
4316f0d2 6414 try_immbig:
5287ad62
JB
6415 /* There's a possibility of getting a 64-bit immediate here, so
6416 we need special handling. */
6417 if (parse_big_immediate (&str, i) == FAIL)
6418 {
6419 inst.error = _("immediate value is out of range");
6420 goto failure;
6421 }
6422 }
6423 break;
6424
6425 case OP_RNDQ_I63b:
6426 {
6427 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6428 break;
6429 try_shimm:
6430 po_imm_or_fail (0, 63, TRUE);
6431 }
6432 break;
c19d1205
ZW
6433
6434 case OP_RRnpcb:
6435 po_char_or_fail ('[');
6436 po_reg_or_fail (REG_TYPE_RN);
6437 po_char_or_fail (']');
6438 break;
a737bd4d 6439
55881a11 6440 case OP_RRnpctw:
c19d1205 6441 case OP_RRw:
b6702015 6442 case OP_oRRw:
c19d1205
ZW
6443 po_reg_or_fail (REG_TYPE_RN);
6444 if (skip_past_char (&str, '!') == SUCCESS)
6445 inst.operands[i].writeback = 1;
6446 break;
6447
6448 /* Immediates */
6449 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6450 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6451 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 6452 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6453 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6454 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 6455 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6456 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
6457 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6458 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6459 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6460 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6461
6462 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6463 case OP_oI7b:
6464 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6465 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6466 case OP_oI31b:
6467 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 6468 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5f1af56b 6469 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6470 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6471
6472 /* Immediate variants */
6473 case OP_oI255c:
6474 po_char_or_fail ('{');
6475 po_imm_or_fail (0, 255, TRUE);
6476 po_char_or_fail ('}');
6477 break;
6478
6479 case OP_I31w:
6480 /* The expression parser chokes on a trailing !, so we have
6481 to find it first and zap it. */
6482 {
6483 char *s = str;
6484 while (*s && *s != ',')
6485 s++;
6486 if (s[-1] == '!')
6487 {
6488 s[-1] = '\0';
6489 inst.operands[i].writeback = 1;
6490 }
6491 po_imm_or_fail (0, 31, TRUE);
6492 if (str == s - 1)
6493 str = s;
6494 }
6495 break;
6496
6497 /* Expressions */
6498 case OP_EXPi: EXPi:
6499 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6500 GE_OPT_PREFIX));
6501 break;
6502
6503 case OP_EXP:
6504 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6505 GE_NO_PREFIX));
6506 break;
6507
6508 case OP_EXPr: EXPr:
6509 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6510 GE_NO_PREFIX));
6511 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6512 {
c19d1205
ZW
6513 val = parse_reloc (&str);
6514 if (val == -1)
6515 {
6516 inst.error = _("unrecognized relocation suffix");
6517 goto failure;
6518 }
6519 else if (val != BFD_RELOC_UNUSED)
6520 {
6521 inst.operands[i].imm = val;
6522 inst.operands[i].hasreloc = 1;
6523 }
a737bd4d 6524 }
c19d1205 6525 break;
a737bd4d 6526
b6895b4f
PB
6527 /* Operand for MOVW or MOVT. */
6528 case OP_HALF:
6529 po_misc_or_fail (parse_half (&str));
6530 break;
6531
e07e6e58 6532 /* Register or expression. */
c19d1205
ZW
6533 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6534 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6535
e07e6e58 6536 /* Register or immediate. */
c19d1205
ZW
6537 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6538 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6539
c19d1205
ZW
6540 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6541 IF:
6542 if (!is_immediate_prefix (*str))
6543 goto bad_args;
6544 str++;
6545 val = parse_fpa_immediate (&str);
6546 if (val == FAIL)
6547 goto failure;
6548 /* FPA immediates are encoded as registers 8-15.
6549 parse_fpa_immediate has already applied the offset. */
6550 inst.operands[i].reg = val;
6551 inst.operands[i].isreg = 1;
6552 break;
09d92015 6553
2d447fca
JM
6554 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6555 I32z: po_imm_or_fail (0, 32, FALSE); break;
6556
e07e6e58 6557 /* Two kinds of register. */
c19d1205
ZW
6558 case OP_RIWR_RIWC:
6559 {
6560 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6561 if (!rege
6562 || (rege->type != REG_TYPE_MMXWR
6563 && rege->type != REG_TYPE_MMXWC
6564 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6565 {
6566 inst.error = _("iWMMXt data or control register expected");
6567 goto failure;
6568 }
6569 inst.operands[i].reg = rege->number;
6570 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6571 }
6572 break;
09d92015 6573
41adaa5c
JM
6574 case OP_RIWC_RIWG:
6575 {
6576 struct reg_entry *rege = arm_reg_parse_multi (&str);
6577 if (!rege
6578 || (rege->type != REG_TYPE_MMXWC
6579 && rege->type != REG_TYPE_MMXWCG))
6580 {
6581 inst.error = _("iWMMXt control register expected");
6582 goto failure;
6583 }
6584 inst.operands[i].reg = rege->number;
6585 inst.operands[i].isreg = 1;
6586 }
6587 break;
6588
c19d1205
ZW
6589 /* Misc */
6590 case OP_CPSF: val = parse_cps_flags (&str); break;
6591 case OP_ENDI: val = parse_endian_specifier (&str); break;
6592 case OP_oROR: val = parse_ror (&str); break;
c19d1205 6593 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6594 case OP_oBARRIER_I15:
6595 po_barrier_or_imm (str); break;
6596 immediate:
6597 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6598 goto failure;
6599 break;
c19d1205 6600
d2cd1205
JB
6601 case OP_wPSR:
6602 case OP_rPSR:
90ec0d68
MGD
6603 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6604 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6605 {
6606 inst.error = _("Banked registers are not available with this "
6607 "architecture.");
6608 goto failure;
6609 }
6610 break;
d2cd1205
JB
6611 try_psr:
6612 val = parse_psr (&str, op_parse_code == OP_wPSR);
6613 break;
037e8744
JB
6614
6615 case OP_APSR_RR:
6616 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6617 break;
6618 try_apsr:
6619 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6620 instruction). */
6621 if (strncasecmp (str, "APSR_", 5) == 0)
6622 {
6623 unsigned found = 0;
6624 str += 5;
6625 while (found < 15)
6626 switch (*str++)
6627 {
6628 case 'c': found = (found & 1) ? 16 : found | 1; break;
6629 case 'n': found = (found & 2) ? 16 : found | 2; break;
6630 case 'z': found = (found & 4) ? 16 : found | 4; break;
6631 case 'v': found = (found & 8) ? 16 : found | 8; break;
6632 default: found = 16;
6633 }
6634 if (found != 15)
6635 goto failure;
6636 inst.operands[i].isvec = 1;
f7c21dc7
NC
6637 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6638 inst.operands[i].reg = REG_PC;
037e8744
JB
6639 }
6640 else
6641 goto failure;
6642 break;
6643
92e90b6e
PB
6644 case OP_TB:
6645 po_misc_or_fail (parse_tb (&str));
6646 break;
6647
e07e6e58 6648 /* Register lists. */
c19d1205
ZW
6649 case OP_REGLST:
6650 val = parse_reg_list (&str);
6651 if (*str == '^')
6652 {
6653 inst.operands[1].writeback = 1;
6654 str++;
6655 }
6656 break;
09d92015 6657
c19d1205 6658 case OP_VRSLST:
5287ad62 6659 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6660 break;
09d92015 6661
c19d1205 6662 case OP_VRDLST:
5287ad62 6663 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6664 break;
a737bd4d 6665
037e8744
JB
6666 case OP_VRSDLST:
6667 /* Allow Q registers too. */
6668 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6669 REGLIST_NEON_D);
6670 if (val == FAIL)
6671 {
6672 inst.error = NULL;
6673 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6674 REGLIST_VFP_S);
6675 inst.operands[i].issingle = 1;
6676 }
6677 break;
6678
5287ad62
JB
6679 case OP_NRDLST:
6680 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6681 REGLIST_NEON_D);
6682 break;
6683
6684 case OP_NSTRLST:
dcbf9037
JB
6685 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6686 &inst.operands[i].vectype);
5287ad62
JB
6687 break;
6688
c19d1205
ZW
6689 /* Addressing modes */
6690 case OP_ADDR:
6691 po_misc_or_fail (parse_address (&str, i));
6692 break;
09d92015 6693
4962c51a
MS
6694 case OP_ADDRGLDR:
6695 po_misc_or_fail_no_backtrack (
6696 parse_address_group_reloc (&str, i, GROUP_LDR));
6697 break;
6698
6699 case OP_ADDRGLDRS:
6700 po_misc_or_fail_no_backtrack (
6701 parse_address_group_reloc (&str, i, GROUP_LDRS));
6702 break;
6703
6704 case OP_ADDRGLDC:
6705 po_misc_or_fail_no_backtrack (
6706 parse_address_group_reloc (&str, i, GROUP_LDC));
6707 break;
6708
c19d1205
ZW
6709 case OP_SH:
6710 po_misc_or_fail (parse_shifter_operand (&str, i));
6711 break;
09d92015 6712
4962c51a
MS
6713 case OP_SHG:
6714 po_misc_or_fail_no_backtrack (
6715 parse_shifter_operand_group_reloc (&str, i));
6716 break;
6717
c19d1205
ZW
6718 case OP_oSHll:
6719 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6720 break;
09d92015 6721
c19d1205
ZW
6722 case OP_oSHar:
6723 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6724 break;
09d92015 6725
c19d1205
ZW
6726 case OP_oSHllar:
6727 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6728 break;
09d92015 6729
c19d1205 6730 default:
5be8be5d 6731 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 6732 }
09d92015 6733
c19d1205
ZW
6734 /* Various value-based sanity checks and shared operations. We
6735 do not signal immediate failures for the register constraints;
6736 this allows a syntax error to take precedence. */
5be8be5d 6737 switch (op_parse_code)
c19d1205
ZW
6738 {
6739 case OP_oRRnpc:
6740 case OP_RRnpc:
6741 case OP_RRnpcb:
6742 case OP_RRw:
b6702015 6743 case OP_oRRw:
c19d1205
ZW
6744 case OP_RRnpc_I0:
6745 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6746 inst.error = BAD_PC;
6747 break;
09d92015 6748
5be8be5d
DG
6749 case OP_oRRnpcsp:
6750 case OP_RRnpcsp:
6751 if (inst.operands[i].isreg)
6752 {
6753 if (inst.operands[i].reg == REG_PC)
6754 inst.error = BAD_PC;
6755 else if (inst.operands[i].reg == REG_SP)
6756 inst.error = BAD_SP;
6757 }
6758 break;
6759
55881a11
MGD
6760 case OP_RRnpctw:
6761 if (inst.operands[i].isreg
6762 && inst.operands[i].reg == REG_PC
6763 && (inst.operands[i].writeback || thumb))
6764 inst.error = BAD_PC;
6765 break;
6766
c19d1205
ZW
6767 case OP_CPSF:
6768 case OP_ENDI:
6769 case OP_oROR:
d2cd1205
JB
6770 case OP_wPSR:
6771 case OP_rPSR:
c19d1205 6772 case OP_COND:
52e7f43d 6773 case OP_oBARRIER_I15:
c19d1205
ZW
6774 case OP_REGLST:
6775 case OP_VRSLST:
6776 case OP_VRDLST:
037e8744 6777 case OP_VRSDLST:
5287ad62
JB
6778 case OP_NRDLST:
6779 case OP_NSTRLST:
c19d1205
ZW
6780 if (val == FAIL)
6781 goto failure;
6782 inst.operands[i].imm = val;
6783 break;
a737bd4d 6784
c19d1205
ZW
6785 default:
6786 break;
6787 }
09d92015 6788
c19d1205
ZW
6789 /* If we get here, this operand was successfully parsed. */
6790 inst.operands[i].present = 1;
6791 continue;
09d92015 6792
c19d1205 6793 bad_args:
09d92015 6794 inst.error = BAD_ARGS;
c19d1205
ZW
6795
6796 failure:
6797 if (!backtrack_pos)
d252fdde
PB
6798 {
6799 /* The parse routine should already have set inst.error, but set a
5f4273c7 6800 default here just in case. */
d252fdde
PB
6801 if (!inst.error)
6802 inst.error = _("syntax error");
6803 return FAIL;
6804 }
c19d1205
ZW
6805
6806 /* Do not backtrack over a trailing optional argument that
6807 absorbed some text. We will only fail again, with the
6808 'garbage following instruction' error message, which is
6809 probably less helpful than the current one. */
6810 if (backtrack_index == i && backtrack_pos != str
6811 && upat[i+1] == OP_stop)
d252fdde
PB
6812 {
6813 if (!inst.error)
6814 inst.error = _("syntax error");
6815 return FAIL;
6816 }
c19d1205
ZW
6817
6818 /* Try again, skipping the optional argument at backtrack_pos. */
6819 str = backtrack_pos;
6820 inst.error = backtrack_error;
6821 inst.operands[backtrack_index].present = 0;
6822 i = backtrack_index;
6823 backtrack_pos = 0;
09d92015 6824 }
09d92015 6825
c19d1205
ZW
6826 /* Check that we have parsed all the arguments. */
6827 if (*str != '\0' && !inst.error)
6828 inst.error = _("garbage following instruction");
09d92015 6829
c19d1205 6830 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6831}
6832
c19d1205
ZW
6833#undef po_char_or_fail
6834#undef po_reg_or_fail
6835#undef po_reg_or_goto
6836#undef po_imm_or_fail
5287ad62 6837#undef po_scalar_or_fail
52e7f43d 6838#undef po_barrier_or_imm
e07e6e58 6839
c19d1205 6840/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6841#define constraint(expr, err) \
6842 do \
c19d1205 6843 { \
e07e6e58
NC
6844 if (expr) \
6845 { \
6846 inst.error = err; \
6847 return; \
6848 } \
c19d1205 6849 } \
e07e6e58 6850 while (0)
c19d1205 6851
fdfde340
JM
6852/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6853 instructions are unpredictable if these registers are used. This
6854 is the BadReg predicate in ARM's Thumb-2 documentation. */
6855#define reject_bad_reg(reg) \
6856 do \
6857 if (reg == REG_SP || reg == REG_PC) \
6858 { \
6859 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6860 return; \
6861 } \
6862 while (0)
6863
94206790
MM
6864/* If REG is R13 (the stack pointer), warn that its use is
6865 deprecated. */
6866#define warn_deprecated_sp(reg) \
6867 do \
6868 if (warn_on_deprecated && reg == REG_SP) \
6869 as_warn (_("use of r13 is deprecated")); \
6870 while (0)
6871
c19d1205
ZW
6872/* Functions for operand encoding. ARM, then Thumb. */
6873
6874#define rotate_left(v, n) (v << n | v >> (32 - n))
6875
6876/* If VAL can be encoded in the immediate field of an ARM instruction,
6877 return the encoded form. Otherwise, return FAIL. */
6878
6879static unsigned int
6880encode_arm_immediate (unsigned int val)
09d92015 6881{
c19d1205
ZW
6882 unsigned int a, i;
6883
6884 for (i = 0; i < 32; i += 2)
6885 if ((a = rotate_left (val, i)) <= 0xff)
6886 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6887
6888 return FAIL;
09d92015
MM
6889}
6890
c19d1205
ZW
6891/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6892 return the encoded form. Otherwise, return FAIL. */
6893static unsigned int
6894encode_thumb32_immediate (unsigned int val)
09d92015 6895{
c19d1205 6896 unsigned int a, i;
09d92015 6897
9c3c69f2 6898 if (val <= 0xff)
c19d1205 6899 return val;
a737bd4d 6900
9c3c69f2 6901 for (i = 1; i <= 24; i++)
09d92015 6902 {
9c3c69f2
PB
6903 a = val >> i;
6904 if ((val & ~(0xff << i)) == 0)
6905 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6906 }
a737bd4d 6907
c19d1205
ZW
6908 a = val & 0xff;
6909 if (val == ((a << 16) | a))
6910 return 0x100 | a;
6911 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6912 return 0x300 | a;
09d92015 6913
c19d1205
ZW
6914 a = val & 0xff00;
6915 if (val == ((a << 16) | a))
6916 return 0x200 | (a >> 8);
a737bd4d 6917
c19d1205 6918 return FAIL;
09d92015 6919}
5287ad62 6920/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6921
6922static void
5287ad62
JB
6923encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6924{
6925 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6926 && reg > 15)
6927 {
b1cc4aeb 6928 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6929 {
6930 if (thumb_mode)
6931 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6932 fpu_vfp_ext_d32);
5287ad62
JB
6933 else
6934 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6935 fpu_vfp_ext_d32);
5287ad62
JB
6936 }
6937 else
6938 {
dcbf9037 6939 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6940 return;
6941 }
6942 }
6943
c19d1205 6944 switch (pos)
09d92015 6945 {
c19d1205
ZW
6946 case VFP_REG_Sd:
6947 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6948 break;
6949
6950 case VFP_REG_Sn:
6951 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6952 break;
6953
6954 case VFP_REG_Sm:
6955 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6956 break;
6957
5287ad62
JB
6958 case VFP_REG_Dd:
6959 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6960 break;
5f4273c7 6961
5287ad62
JB
6962 case VFP_REG_Dn:
6963 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6964 break;
5f4273c7 6965
5287ad62
JB
6966 case VFP_REG_Dm:
6967 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6968 break;
6969
c19d1205
ZW
6970 default:
6971 abort ();
09d92015 6972 }
09d92015
MM
6973}
6974
c19d1205 6975/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6976 if any, is handled by md_apply_fix. */
09d92015 6977static void
c19d1205 6978encode_arm_shift (int i)
09d92015 6979{
c19d1205
ZW
6980 if (inst.operands[i].shift_kind == SHIFT_RRX)
6981 inst.instruction |= SHIFT_ROR << 5;
6982 else
09d92015 6983 {
c19d1205
ZW
6984 inst.instruction |= inst.operands[i].shift_kind << 5;
6985 if (inst.operands[i].immisreg)
6986 {
6987 inst.instruction |= SHIFT_BY_REG;
6988 inst.instruction |= inst.operands[i].imm << 8;
6989 }
6990 else
6991 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6992 }
c19d1205 6993}
09d92015 6994
c19d1205
ZW
6995static void
6996encode_arm_shifter_operand (int i)
6997{
6998 if (inst.operands[i].isreg)
09d92015 6999 {
c19d1205
ZW
7000 inst.instruction |= inst.operands[i].reg;
7001 encode_arm_shift (i);
09d92015 7002 }
c19d1205
ZW
7003 else
7004 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
7005}
7006
c19d1205 7007/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7008static void
c19d1205 7009encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7010{
9c2799c2 7011 gas_assert (inst.operands[i].isreg);
c19d1205 7012 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7013
c19d1205 7014 if (inst.operands[i].preind)
09d92015 7015 {
c19d1205
ZW
7016 if (is_t)
7017 {
7018 inst.error = _("instruction does not accept preindexed addressing");
7019 return;
7020 }
7021 inst.instruction |= PRE_INDEX;
7022 if (inst.operands[i].writeback)
7023 inst.instruction |= WRITE_BACK;
09d92015 7024
c19d1205
ZW
7025 }
7026 else if (inst.operands[i].postind)
7027 {
9c2799c2 7028 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7029 if (is_t)
7030 inst.instruction |= WRITE_BACK;
7031 }
7032 else /* unindexed - only for coprocessor */
09d92015 7033 {
c19d1205 7034 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7035 return;
7036 }
7037
c19d1205
ZW
7038 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7039 && (((inst.instruction & 0x000f0000) >> 16)
7040 == ((inst.instruction & 0x0000f000) >> 12)))
7041 as_warn ((inst.instruction & LOAD_BIT)
7042 ? _("destination register same as write-back base")
7043 : _("source register same as write-back base"));
09d92015
MM
7044}
7045
c19d1205
ZW
7046/* inst.operands[i] was set up by parse_address. Encode it into an
7047 ARM-format mode 2 load or store instruction. If is_t is true,
7048 reject forms that cannot be used with a T instruction (i.e. not
7049 post-indexed). */
a737bd4d 7050static void
c19d1205 7051encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7052{
5be8be5d
DG
7053 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7054
c19d1205 7055 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7056
c19d1205 7057 if (inst.operands[i].immisreg)
09d92015 7058 {
5be8be5d
DG
7059 constraint ((inst.operands[i].imm == REG_PC
7060 || (is_pc && inst.operands[i].writeback)),
7061 BAD_PC_ADDRESSING);
c19d1205
ZW
7062 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7063 inst.instruction |= inst.operands[i].imm;
7064 if (!inst.operands[i].negative)
7065 inst.instruction |= INDEX_UP;
7066 if (inst.operands[i].shifted)
7067 {
7068 if (inst.operands[i].shift_kind == SHIFT_RRX)
7069 inst.instruction |= SHIFT_ROR << 5;
7070 else
7071 {
7072 inst.instruction |= inst.operands[i].shift_kind << 5;
7073 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7074 }
7075 }
09d92015 7076 }
c19d1205 7077 else /* immediate offset in inst.reloc */
09d92015 7078 {
5be8be5d
DG
7079 if (is_pc && !inst.reloc.pc_rel)
7080 {
7081 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7082
7083 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7084 cannot use PC in addressing.
7085 PC cannot be used in writeback addressing, either. */
7086 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7087 BAD_PC_ADDRESSING);
23a10334 7088
dc5ec521 7089 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7090 if (warn_on_deprecated
7091 && !is_load
7092 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7093 as_warn (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7094 }
7095
c19d1205 7096 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7097 {
7098 /* Prefer + for zero encoded value. */
7099 if (!inst.operands[i].negative)
7100 inst.instruction |= INDEX_UP;
7101 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7102 }
09d92015 7103 }
09d92015
MM
7104}
7105
c19d1205
ZW
7106/* inst.operands[i] was set up by parse_address. Encode it into an
7107 ARM-format mode 3 load or store instruction. Reject forms that
7108 cannot be used with such instructions. If is_t is true, reject
7109 forms that cannot be used with a T instruction (i.e. not
7110 post-indexed). */
7111static void
7112encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7113{
c19d1205 7114 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7115 {
c19d1205
ZW
7116 inst.error = _("instruction does not accept scaled register index");
7117 return;
09d92015 7118 }
a737bd4d 7119
c19d1205 7120 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7121
c19d1205
ZW
7122 if (inst.operands[i].immisreg)
7123 {
5be8be5d
DG
7124 constraint ((inst.operands[i].imm == REG_PC
7125 || inst.operands[i].reg == REG_PC),
7126 BAD_PC_ADDRESSING);
c19d1205
ZW
7127 inst.instruction |= inst.operands[i].imm;
7128 if (!inst.operands[i].negative)
7129 inst.instruction |= INDEX_UP;
7130 }
7131 else /* immediate offset in inst.reloc */
7132 {
5be8be5d
DG
7133 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7134 && inst.operands[i].writeback),
7135 BAD_PC_WRITEBACK);
c19d1205
ZW
7136 inst.instruction |= HWOFFSET_IMM;
7137 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7138 {
7139 /* Prefer + for zero encoded value. */
7140 if (!inst.operands[i].negative)
7141 inst.instruction |= INDEX_UP;
7142
7143 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7144 }
c19d1205 7145 }
a737bd4d
NC
7146}
7147
c19d1205
ZW
7148/* inst.operands[i] was set up by parse_address. Encode it into an
7149 ARM-format instruction. Reject all forms which cannot be encoded
7150 into a coprocessor load/store instruction. If wb_ok is false,
7151 reject use of writeback; if unind_ok is false, reject use of
7152 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
7153 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
7154 (in which case it is preserved). */
09d92015 7155
c19d1205
ZW
7156static int
7157encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 7158{
c19d1205 7159 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7160
9c2799c2 7161 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 7162
c19d1205 7163 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 7164 {
9c2799c2 7165 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
7166 if (!unind_ok)
7167 {
7168 inst.error = _("instruction does not support unindexed addressing");
7169 return FAIL;
7170 }
7171 inst.instruction |= inst.operands[i].imm;
7172 inst.instruction |= INDEX_UP;
7173 return SUCCESS;
09d92015 7174 }
a737bd4d 7175
c19d1205
ZW
7176 if (inst.operands[i].preind)
7177 inst.instruction |= PRE_INDEX;
a737bd4d 7178
c19d1205 7179 if (inst.operands[i].writeback)
09d92015 7180 {
c19d1205
ZW
7181 if (inst.operands[i].reg == REG_PC)
7182 {
7183 inst.error = _("pc may not be used with write-back");
7184 return FAIL;
7185 }
7186 if (!wb_ok)
7187 {
7188 inst.error = _("instruction does not support writeback");
7189 return FAIL;
7190 }
7191 inst.instruction |= WRITE_BACK;
09d92015 7192 }
a737bd4d 7193
c19d1205 7194 if (reloc_override)
21d799b5 7195 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a
MS
7196 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
7197 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
7198 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
7199 {
7200 if (thumb_mode)
7201 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
7202 else
7203 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
7204 }
7205
26d97720
NS
7206 /* Prefer + for zero encoded value. */
7207 if (!inst.operands[i].negative)
7208 inst.instruction |= INDEX_UP;
7209
c19d1205
ZW
7210 return SUCCESS;
7211}
a737bd4d 7212
c19d1205
ZW
7213/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7214 Determine whether it can be performed with a move instruction; if
7215 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7216 return TRUE; if it can't, convert inst.instruction to a literal-pool
7217 load and return FALSE. If this is not a valid thing to do in the
7218 current context, set inst.error and return TRUE.
a737bd4d 7219
c19d1205
ZW
7220 inst.operands[i] describes the destination register. */
7221
c921be7d 7222static bfd_boolean
c19d1205
ZW
7223move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
7224{
53365c0d
PB
7225 unsigned long tbit;
7226
7227 if (thumb_p)
7228 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7229 else
7230 tbit = LOAD_BIT;
7231
7232 if ((inst.instruction & tbit) == 0)
09d92015 7233 {
c19d1205 7234 inst.error = _("invalid pseudo operation");
c921be7d 7235 return TRUE;
09d92015 7236 }
c19d1205 7237 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
7238 {
7239 inst.error = _("constant expression expected");
c921be7d 7240 return TRUE;
09d92015 7241 }
c19d1205 7242 if (inst.reloc.exp.X_op == O_constant)
09d92015 7243 {
c19d1205
ZW
7244 if (thumb_p)
7245 {
53365c0d 7246 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
7247 {
7248 /* This can be done with a mov(1) instruction. */
7249 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7250 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 7251 return TRUE;
c19d1205
ZW
7252 }
7253 }
7254 else
7255 {
7256 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7257 if (value != FAIL)
7258 {
7259 /* This can be done with a mov instruction. */
7260 inst.instruction &= LITERAL_MASK;
7261 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7262 inst.instruction |= value & 0xfff;
c921be7d 7263 return TRUE;
c19d1205 7264 }
09d92015 7265
c19d1205
ZW
7266 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7267 if (value != FAIL)
7268 {
7269 /* This can be done with a mvn instruction. */
7270 inst.instruction &= LITERAL_MASK;
7271 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7272 inst.instruction |= value & 0xfff;
c921be7d 7273 return TRUE;
c19d1205
ZW
7274 }
7275 }
09d92015
MM
7276 }
7277
c19d1205
ZW
7278 if (add_to_lit_pool () == FAIL)
7279 {
7280 inst.error = _("literal pool insertion failed");
c921be7d 7281 return TRUE;
c19d1205
ZW
7282 }
7283 inst.operands[1].reg = REG_PC;
7284 inst.operands[1].isreg = 1;
7285 inst.operands[1].preind = 1;
7286 inst.reloc.pc_rel = 1;
7287 inst.reloc.type = (thumb_p
7288 ? BFD_RELOC_ARM_THUMB_OFFSET
7289 : (mode_3
7290 ? BFD_RELOC_ARM_HWLITERAL
7291 : BFD_RELOC_ARM_LITERAL));
c921be7d 7292 return FALSE;
09d92015
MM
7293}
7294
5f4273c7 7295/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
7296 First some generics; their names are taken from the conventional
7297 bit positions for register arguments in ARM format instructions. */
09d92015 7298
a737bd4d 7299static void
c19d1205 7300do_noargs (void)
09d92015 7301{
c19d1205 7302}
a737bd4d 7303
c19d1205
ZW
7304static void
7305do_rd (void)
7306{
7307 inst.instruction |= inst.operands[0].reg << 12;
7308}
a737bd4d 7309
c19d1205
ZW
7310static void
7311do_rd_rm (void)
7312{
7313 inst.instruction |= inst.operands[0].reg << 12;
7314 inst.instruction |= inst.operands[1].reg;
7315}
09d92015 7316
c19d1205
ZW
7317static void
7318do_rd_rn (void)
7319{
7320 inst.instruction |= inst.operands[0].reg << 12;
7321 inst.instruction |= inst.operands[1].reg << 16;
7322}
a737bd4d 7323
c19d1205
ZW
7324static void
7325do_rn_rd (void)
7326{
7327 inst.instruction |= inst.operands[0].reg << 16;
7328 inst.instruction |= inst.operands[1].reg << 12;
7329}
09d92015 7330
c19d1205
ZW
7331static void
7332do_rd_rm_rn (void)
7333{
9a64e435 7334 unsigned Rn = inst.operands[2].reg;
708587a4 7335 /* Enforce restrictions on SWP instruction. */
9a64e435 7336 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
7337 {
7338 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7339 _("Rn must not overlap other operands"));
7340
7341 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
7342 if (warn_on_deprecated
7343 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7344 as_warn (_("swp{b} use is deprecated for this architecture"));
7345
7346 }
c19d1205
ZW
7347 inst.instruction |= inst.operands[0].reg << 12;
7348 inst.instruction |= inst.operands[1].reg;
9a64e435 7349 inst.instruction |= Rn << 16;
c19d1205 7350}
09d92015 7351
c19d1205
ZW
7352static void
7353do_rd_rn_rm (void)
7354{
7355 inst.instruction |= inst.operands[0].reg << 12;
7356 inst.instruction |= inst.operands[1].reg << 16;
7357 inst.instruction |= inst.operands[2].reg;
7358}
a737bd4d 7359
c19d1205
ZW
7360static void
7361do_rm_rd_rn (void)
7362{
5be8be5d
DG
7363 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7364 constraint (((inst.reloc.exp.X_op != O_constant
7365 && inst.reloc.exp.X_op != O_illegal)
7366 || inst.reloc.exp.X_add_number != 0),
7367 BAD_ADDR_MODE);
c19d1205
ZW
7368 inst.instruction |= inst.operands[0].reg;
7369 inst.instruction |= inst.operands[1].reg << 12;
7370 inst.instruction |= inst.operands[2].reg << 16;
7371}
09d92015 7372
c19d1205
ZW
7373static void
7374do_imm0 (void)
7375{
7376 inst.instruction |= inst.operands[0].imm;
7377}
09d92015 7378
c19d1205
ZW
7379static void
7380do_rd_cpaddr (void)
7381{
7382 inst.instruction |= inst.operands[0].reg << 12;
7383 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 7384}
a737bd4d 7385
c19d1205
ZW
7386/* ARM instructions, in alphabetical order by function name (except
7387 that wrapper functions appear immediately after the function they
7388 wrap). */
09d92015 7389
c19d1205
ZW
7390/* This is a pseudo-op of the form "adr rd, label" to be converted
7391 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
7392
7393static void
c19d1205 7394do_adr (void)
09d92015 7395{
c19d1205 7396 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7397
c19d1205
ZW
7398 /* Frag hacking will turn this into a sub instruction if the offset turns
7399 out to be negative. */
7400 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 7401 inst.reloc.pc_rel = 1;
2fc8bdac 7402 inst.reloc.exp.X_add_number -= 8;
c19d1205 7403}
b99bd4ef 7404
c19d1205
ZW
7405/* This is a pseudo-op of the form "adrl rd, label" to be converted
7406 into a relative address of the form:
7407 add rd, pc, #low(label-.-8)"
7408 add rd, rd, #high(label-.-8)" */
b99bd4ef 7409
c19d1205
ZW
7410static void
7411do_adrl (void)
7412{
7413 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7414
c19d1205
ZW
7415 /* Frag hacking will turn this into a sub instruction if the offset turns
7416 out to be negative. */
7417 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
7418 inst.reloc.pc_rel = 1;
7419 inst.size = INSN_SIZE * 2;
2fc8bdac 7420 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
7421}
7422
b99bd4ef 7423static void
c19d1205 7424do_arit (void)
b99bd4ef 7425{
c19d1205
ZW
7426 if (!inst.operands[1].present)
7427 inst.operands[1].reg = inst.operands[0].reg;
7428 inst.instruction |= inst.operands[0].reg << 12;
7429 inst.instruction |= inst.operands[1].reg << 16;
7430 encode_arm_shifter_operand (2);
7431}
b99bd4ef 7432
62b3e311
PB
7433static void
7434do_barrier (void)
7435{
7436 if (inst.operands[0].present)
7437 {
7438 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
7439 && inst.operands[0].imm > 0xf
7440 && inst.operands[0].imm < 0x0,
bd3ba5d1 7441 _("bad barrier type"));
62b3e311
PB
7442 inst.instruction |= inst.operands[0].imm;
7443 }
7444 else
7445 inst.instruction |= 0xf;
7446}
7447
c19d1205
ZW
7448static void
7449do_bfc (void)
7450{
7451 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7452 constraint (msb > 32, _("bit-field extends past end of register"));
7453 /* The instruction encoding stores the LSB and MSB,
7454 not the LSB and width. */
7455 inst.instruction |= inst.operands[0].reg << 12;
7456 inst.instruction |= inst.operands[1].imm << 7;
7457 inst.instruction |= (msb - 1) << 16;
7458}
b99bd4ef 7459
c19d1205
ZW
7460static void
7461do_bfi (void)
7462{
7463 unsigned int msb;
b99bd4ef 7464
c19d1205
ZW
7465 /* #0 in second position is alternative syntax for bfc, which is
7466 the same instruction but with REG_PC in the Rm field. */
7467 if (!inst.operands[1].isreg)
7468 inst.operands[1].reg = REG_PC;
b99bd4ef 7469
c19d1205
ZW
7470 msb = inst.operands[2].imm + inst.operands[3].imm;
7471 constraint (msb > 32, _("bit-field extends past end of register"));
7472 /* The instruction encoding stores the LSB and MSB,
7473 not the LSB and width. */
7474 inst.instruction |= inst.operands[0].reg << 12;
7475 inst.instruction |= inst.operands[1].reg;
7476 inst.instruction |= inst.operands[2].imm << 7;
7477 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7478}
7479
b99bd4ef 7480static void
c19d1205 7481do_bfx (void)
b99bd4ef 7482{
c19d1205
ZW
7483 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7484 _("bit-field extends past end of register"));
7485 inst.instruction |= inst.operands[0].reg << 12;
7486 inst.instruction |= inst.operands[1].reg;
7487 inst.instruction |= inst.operands[2].imm << 7;
7488 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7489}
09d92015 7490
c19d1205
ZW
7491/* ARM V5 breakpoint instruction (argument parse)
7492 BKPT <16 bit unsigned immediate>
7493 Instruction is not conditional.
7494 The bit pattern given in insns[] has the COND_ALWAYS condition,
7495 and it is an error if the caller tried to override that. */
b99bd4ef 7496
c19d1205
ZW
7497static void
7498do_bkpt (void)
7499{
7500 /* Top 12 of 16 bits to bits 19:8. */
7501 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7502
c19d1205
ZW
7503 /* Bottom 4 of 16 bits to bits 3:0. */
7504 inst.instruction |= inst.operands[0].imm & 0xf;
7505}
09d92015 7506
c19d1205
ZW
7507static void
7508encode_branch (int default_reloc)
7509{
7510 if (inst.operands[0].hasreloc)
7511 {
0855e32b
NS
7512 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
7513 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
7514 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
7515 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
7516 ? BFD_RELOC_ARM_PLT32
7517 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 7518 }
b99bd4ef 7519 else
9ae92b05 7520 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 7521 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7522}
7523
b99bd4ef 7524static void
c19d1205 7525do_branch (void)
b99bd4ef 7526{
39b41c9c
PB
7527#ifdef OBJ_ELF
7528 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7529 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7530 else
7531#endif
7532 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7533}
7534
7535static void
7536do_bl (void)
7537{
7538#ifdef OBJ_ELF
7539 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7540 {
7541 if (inst.cond == COND_ALWAYS)
7542 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7543 else
7544 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7545 }
7546 else
7547#endif
7548 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7549}
b99bd4ef 7550
c19d1205
ZW
7551/* ARM V5 branch-link-exchange instruction (argument parse)
7552 BLX <target_addr> ie BLX(1)
7553 BLX{<condition>} <Rm> ie BLX(2)
7554 Unfortunately, there are two different opcodes for this mnemonic.
7555 So, the insns[].value is not used, and the code here zaps values
7556 into inst.instruction.
7557 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7558
c19d1205
ZW
7559static void
7560do_blx (void)
7561{
7562 if (inst.operands[0].isreg)
b99bd4ef 7563 {
c19d1205
ZW
7564 /* Arg is a register; the opcode provided by insns[] is correct.
7565 It is not illegal to do "blx pc", just useless. */
7566 if (inst.operands[0].reg == REG_PC)
7567 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7568
c19d1205
ZW
7569 inst.instruction |= inst.operands[0].reg;
7570 }
7571 else
b99bd4ef 7572 {
c19d1205 7573 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7574 conditionally, and the opcode must be adjusted.
7575 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7576 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7577 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7578 inst.instruction = 0xfa000000;
267bf995 7579 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7580 }
c19d1205
ZW
7581}
7582
7583static void
7584do_bx (void)
7585{
845b51d6
PB
7586 bfd_boolean want_reloc;
7587
c19d1205
ZW
7588 if (inst.operands[0].reg == REG_PC)
7589 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7590
c19d1205 7591 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7592 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7593 it is for ARMv4t or earlier. */
7594 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7595 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7596 want_reloc = TRUE;
7597
5ad34203 7598#ifdef OBJ_ELF
845b51d6 7599 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7600#endif
584206db 7601 want_reloc = FALSE;
845b51d6
PB
7602
7603 if (want_reloc)
7604 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7605}
7606
c19d1205
ZW
7607
7608/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7609
7610static void
c19d1205 7611do_bxj (void)
a737bd4d 7612{
c19d1205
ZW
7613 if (inst.operands[0].reg == REG_PC)
7614 as_tsktsk (_("use of r15 in bxj is not really useful"));
7615
7616 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7617}
7618
c19d1205
ZW
7619/* Co-processor data operation:
7620 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7621 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7622static void
7623do_cdp (void)
7624{
7625 inst.instruction |= inst.operands[0].reg << 8;
7626 inst.instruction |= inst.operands[1].imm << 20;
7627 inst.instruction |= inst.operands[2].reg << 12;
7628 inst.instruction |= inst.operands[3].reg << 16;
7629 inst.instruction |= inst.operands[4].reg;
7630 inst.instruction |= inst.operands[5].imm << 5;
7631}
a737bd4d
NC
7632
7633static void
c19d1205 7634do_cmp (void)
a737bd4d 7635{
c19d1205
ZW
7636 inst.instruction |= inst.operands[0].reg << 16;
7637 encode_arm_shifter_operand (1);
a737bd4d
NC
7638}
7639
c19d1205
ZW
7640/* Transfer between coprocessor and ARM registers.
7641 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7642 MRC2
7643 MCR{cond}
7644 MCR2
7645
7646 No special properties. */
09d92015
MM
7647
7648static void
c19d1205 7649do_co_reg (void)
09d92015 7650{
fdfde340
JM
7651 unsigned Rd;
7652
7653 Rd = inst.operands[2].reg;
7654 if (thumb_mode)
7655 {
7656 if (inst.instruction == 0xee000010
7657 || inst.instruction == 0xfe000010)
7658 /* MCR, MCR2 */
7659 reject_bad_reg (Rd);
7660 else
7661 /* MRC, MRC2 */
7662 constraint (Rd == REG_SP, BAD_SP);
7663 }
7664 else
7665 {
7666 /* MCR */
7667 if (inst.instruction == 0xe000010)
7668 constraint (Rd == REG_PC, BAD_PC);
7669 }
7670
7671
c19d1205
ZW
7672 inst.instruction |= inst.operands[0].reg << 8;
7673 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7674 inst.instruction |= Rd << 12;
c19d1205
ZW
7675 inst.instruction |= inst.operands[3].reg << 16;
7676 inst.instruction |= inst.operands[4].reg;
7677 inst.instruction |= inst.operands[5].imm << 5;
7678}
09d92015 7679
c19d1205
ZW
7680/* Transfer between coprocessor register and pair of ARM registers.
7681 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7682 MCRR2
7683 MRRC{cond}
7684 MRRC2
b99bd4ef 7685
c19d1205 7686 Two XScale instructions are special cases of these:
09d92015 7687
c19d1205
ZW
7688 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7689 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7690
5f4273c7 7691 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7692
c19d1205
ZW
7693static void
7694do_co_reg2c (void)
7695{
fdfde340
JM
7696 unsigned Rd, Rn;
7697
7698 Rd = inst.operands[2].reg;
7699 Rn = inst.operands[3].reg;
7700
7701 if (thumb_mode)
7702 {
7703 reject_bad_reg (Rd);
7704 reject_bad_reg (Rn);
7705 }
7706 else
7707 {
7708 constraint (Rd == REG_PC, BAD_PC);
7709 constraint (Rn == REG_PC, BAD_PC);
7710 }
7711
c19d1205
ZW
7712 inst.instruction |= inst.operands[0].reg << 8;
7713 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7714 inst.instruction |= Rd << 12;
7715 inst.instruction |= Rn << 16;
c19d1205 7716 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7717}
7718
c19d1205
ZW
7719static void
7720do_cpsi (void)
7721{
7722 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7723 if (inst.operands[1].present)
7724 {
7725 inst.instruction |= CPSI_MMOD;
7726 inst.instruction |= inst.operands[1].imm;
7727 }
c19d1205 7728}
b99bd4ef 7729
62b3e311
PB
7730static void
7731do_dbg (void)
7732{
7733 inst.instruction |= inst.operands[0].imm;
7734}
7735
eea54501
MGD
7736static void
7737do_div (void)
7738{
7739 unsigned Rd, Rn, Rm;
7740
7741 Rd = inst.operands[0].reg;
7742 Rn = (inst.operands[1].present
7743 ? inst.operands[1].reg : Rd);
7744 Rm = inst.operands[2].reg;
7745
7746 constraint ((Rd == REG_PC), BAD_PC);
7747 constraint ((Rn == REG_PC), BAD_PC);
7748 constraint ((Rm == REG_PC), BAD_PC);
7749
7750 inst.instruction |= Rd << 16;
7751 inst.instruction |= Rn << 0;
7752 inst.instruction |= Rm << 8;
7753}
7754
b99bd4ef 7755static void
c19d1205 7756do_it (void)
b99bd4ef 7757{
c19d1205 7758 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7759 process it to do the validation as if in
7760 thumb mode, just in case the code gets
7761 assembled for thumb using the unified syntax. */
7762
c19d1205 7763 inst.size = 0;
e07e6e58
NC
7764 if (unified_syntax)
7765 {
7766 set_it_insn_type (IT_INSN);
7767 now_it.mask = (inst.instruction & 0xf) | 0x10;
7768 now_it.cc = inst.operands[0].imm;
7769 }
09d92015 7770}
b99bd4ef 7771
09d92015 7772static void
c19d1205 7773do_ldmstm (void)
ea6ef066 7774{
c19d1205
ZW
7775 int base_reg = inst.operands[0].reg;
7776 int range = inst.operands[1].imm;
ea6ef066 7777
c19d1205
ZW
7778 inst.instruction |= base_reg << 16;
7779 inst.instruction |= range;
ea6ef066 7780
c19d1205
ZW
7781 if (inst.operands[1].writeback)
7782 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7783
c19d1205 7784 if (inst.operands[0].writeback)
ea6ef066 7785 {
c19d1205
ZW
7786 inst.instruction |= WRITE_BACK;
7787 /* Check for unpredictable uses of writeback. */
7788 if (inst.instruction & LOAD_BIT)
09d92015 7789 {
c19d1205
ZW
7790 /* Not allowed in LDM type 2. */
7791 if ((inst.instruction & LDM_TYPE_2_OR_3)
7792 && ((range & (1 << REG_PC)) == 0))
7793 as_warn (_("writeback of base register is UNPREDICTABLE"));
7794 /* Only allowed if base reg not in list for other types. */
7795 else if (range & (1 << base_reg))
7796 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7797 }
7798 else /* STM. */
7799 {
7800 /* Not allowed for type 2. */
7801 if (inst.instruction & LDM_TYPE_2_OR_3)
7802 as_warn (_("writeback of base register is UNPREDICTABLE"));
7803 /* Only allowed if base reg not in list, or first in list. */
7804 else if ((range & (1 << base_reg))
7805 && (range & ((1 << base_reg) - 1)))
7806 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7807 }
ea6ef066 7808 }
a737bd4d
NC
7809}
7810
c19d1205
ZW
7811/* ARMv5TE load-consecutive (argument parse)
7812 Mode is like LDRH.
7813
7814 LDRccD R, mode
7815 STRccD R, mode. */
7816
a737bd4d 7817static void
c19d1205 7818do_ldrd (void)
a737bd4d 7819{
c19d1205 7820 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 7821 _("first transfer register must be even"));
c19d1205
ZW
7822 constraint (inst.operands[1].present
7823 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 7824 _("can only transfer two consecutive registers"));
c19d1205
ZW
7825 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7826 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7827
c19d1205
ZW
7828 if (!inst.operands[1].present)
7829 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7830
c56791bb
RE
7831 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7832 register and the first register written; we have to diagnose
7833 overlap between the base and the second register written here. */
ea6ef066 7834
c56791bb
RE
7835 if (inst.operands[2].reg == inst.operands[1].reg
7836 && (inst.operands[2].writeback || inst.operands[2].postind))
7837 as_warn (_("base register written back, and overlaps "
7838 "second transfer register"));
b05fe5cf 7839
c56791bb
RE
7840 if (!(inst.instruction & V4_STR_BIT))
7841 {
c19d1205 7842 /* For an index-register load, the index register must not overlap the
c56791bb
RE
7843 destination (even if not write-back). */
7844 if (inst.operands[2].immisreg
7845 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7846 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
7847 as_warn (_("index register overlaps transfer register"));
b05fe5cf 7848 }
c19d1205
ZW
7849 inst.instruction |= inst.operands[0].reg << 12;
7850 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7851}
7852
7853static void
c19d1205 7854do_ldrex (void)
b05fe5cf 7855{
c19d1205
ZW
7856 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7857 || inst.operands[1].postind || inst.operands[1].writeback
7858 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7859 || inst.operands[1].negative
7860 /* This can arise if the programmer has written
7861 strex rN, rM, foo
7862 or if they have mistakenly used a register name as the last
7863 operand, eg:
7864 strex rN, rM, rX
7865 It is very difficult to distinguish between these two cases
7866 because "rX" might actually be a label. ie the register
7867 name has been occluded by a symbol of the same name. So we
7868 just generate a general 'bad addressing mode' type error
7869 message and leave it up to the programmer to discover the
7870 true cause and fix their mistake. */
7871 || (inst.operands[1].reg == REG_PC),
7872 BAD_ADDR_MODE);
b05fe5cf 7873
c19d1205
ZW
7874 constraint (inst.reloc.exp.X_op != O_constant
7875 || inst.reloc.exp.X_add_number != 0,
7876 _("offset must be zero in ARM encoding"));
b05fe5cf 7877
5be8be5d
DG
7878 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7879
c19d1205
ZW
7880 inst.instruction |= inst.operands[0].reg << 12;
7881 inst.instruction |= inst.operands[1].reg << 16;
7882 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7883}
7884
7885static void
c19d1205 7886do_ldrexd (void)
b05fe5cf 7887{
c19d1205
ZW
7888 constraint (inst.operands[0].reg % 2 != 0,
7889 _("even register required"));
7890 constraint (inst.operands[1].present
7891 && inst.operands[1].reg != inst.operands[0].reg + 1,
7892 _("can only load two consecutive registers"));
7893 /* If op 1 were present and equal to PC, this function wouldn't
7894 have been called in the first place. */
7895 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7896
c19d1205
ZW
7897 inst.instruction |= inst.operands[0].reg << 12;
7898 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7899}
7900
7901static void
c19d1205 7902do_ldst (void)
b05fe5cf 7903{
c19d1205
ZW
7904 inst.instruction |= inst.operands[0].reg << 12;
7905 if (!inst.operands[1].isreg)
7906 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7907 return;
c19d1205 7908 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7909}
7910
7911static void
c19d1205 7912do_ldstt (void)
b05fe5cf 7913{
c19d1205
ZW
7914 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7915 reject [Rn,...]. */
7916 if (inst.operands[1].preind)
b05fe5cf 7917 {
bd3ba5d1
NC
7918 constraint (inst.reloc.exp.X_op != O_constant
7919 || inst.reloc.exp.X_add_number != 0,
c19d1205 7920 _("this instruction requires a post-indexed address"));
b05fe5cf 7921
c19d1205
ZW
7922 inst.operands[1].preind = 0;
7923 inst.operands[1].postind = 1;
7924 inst.operands[1].writeback = 1;
b05fe5cf 7925 }
c19d1205
ZW
7926 inst.instruction |= inst.operands[0].reg << 12;
7927 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7928}
b05fe5cf 7929
c19d1205 7930/* Halfword and signed-byte load/store operations. */
b05fe5cf 7931
c19d1205
ZW
7932static void
7933do_ldstv4 (void)
7934{
ff4a8d2b 7935 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7936 inst.instruction |= inst.operands[0].reg << 12;
7937 if (!inst.operands[1].isreg)
7938 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7939 return;
c19d1205 7940 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7941}
7942
7943static void
c19d1205 7944do_ldsttv4 (void)
b05fe5cf 7945{
c19d1205
ZW
7946 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7947 reject [Rn,...]. */
7948 if (inst.operands[1].preind)
b05fe5cf 7949 {
bd3ba5d1
NC
7950 constraint (inst.reloc.exp.X_op != O_constant
7951 || inst.reloc.exp.X_add_number != 0,
c19d1205 7952 _("this instruction requires a post-indexed address"));
b05fe5cf 7953
c19d1205
ZW
7954 inst.operands[1].preind = 0;
7955 inst.operands[1].postind = 1;
7956 inst.operands[1].writeback = 1;
b05fe5cf 7957 }
c19d1205
ZW
7958 inst.instruction |= inst.operands[0].reg << 12;
7959 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7960}
b05fe5cf 7961
c19d1205
ZW
7962/* Co-processor register load/store.
7963 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7964static void
7965do_lstc (void)
7966{
7967 inst.instruction |= inst.operands[0].reg << 8;
7968 inst.instruction |= inst.operands[1].reg << 12;
7969 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7970}
7971
b05fe5cf 7972static void
c19d1205 7973do_mlas (void)
b05fe5cf 7974{
8fb9d7b9 7975 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7976 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7977 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7978 && !(inst.instruction & 0x00400000))
8fb9d7b9 7979 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7980
c19d1205
ZW
7981 inst.instruction |= inst.operands[0].reg << 16;
7982 inst.instruction |= inst.operands[1].reg;
7983 inst.instruction |= inst.operands[2].reg << 8;
7984 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7985}
b05fe5cf 7986
c19d1205
ZW
7987static void
7988do_mov (void)
7989{
7990 inst.instruction |= inst.operands[0].reg << 12;
7991 encode_arm_shifter_operand (1);
7992}
b05fe5cf 7993
c19d1205
ZW
7994/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7995static void
7996do_mov16 (void)
7997{
b6895b4f
PB
7998 bfd_vma imm;
7999 bfd_boolean top;
8000
8001 top = (inst.instruction & 0x00400000) != 0;
8002 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8003 _(":lower16: not allowed this instruction"));
8004 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8005 _(":upper16: not allowed instruction"));
c19d1205 8006 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
8007 if (inst.reloc.type == BFD_RELOC_UNUSED)
8008 {
8009 imm = inst.reloc.exp.X_add_number;
8010 /* The value is in two pieces: 0:11, 16:19. */
8011 inst.instruction |= (imm & 0x00000fff);
8012 inst.instruction |= (imm & 0x0000f000) << 4;
8013 }
b05fe5cf 8014}
b99bd4ef 8015
037e8744
JB
8016static void do_vfp_nsyn_opcode (const char *);
8017
8018static int
8019do_vfp_nsyn_mrs (void)
8020{
8021 if (inst.operands[0].isvec)
8022 {
8023 if (inst.operands[1].reg != 1)
8024 first_error (_("operand 1 must be FPSCR"));
8025 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8026 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8027 do_vfp_nsyn_opcode ("fmstat");
8028 }
8029 else if (inst.operands[1].isvec)
8030 do_vfp_nsyn_opcode ("fmrx");
8031 else
8032 return FAIL;
5f4273c7 8033
037e8744
JB
8034 return SUCCESS;
8035}
8036
8037static int
8038do_vfp_nsyn_msr (void)
8039{
8040 if (inst.operands[0].isvec)
8041 do_vfp_nsyn_opcode ("fmxr");
8042 else
8043 return FAIL;
8044
8045 return SUCCESS;
8046}
8047
f7c21dc7
NC
8048static void
8049do_vmrs (void)
8050{
8051 unsigned Rt = inst.operands[0].reg;
8052
8053 if (thumb_mode && inst.operands[0].reg == REG_SP)
8054 {
8055 inst.error = BAD_SP;
8056 return;
8057 }
8058
8059 /* APSR_ sets isvec. All other refs to PC are illegal. */
8060 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
8061 {
8062 inst.error = BAD_PC;
8063 return;
8064 }
8065
8066 if (inst.operands[1].reg != 1)
8067 first_error (_("operand 1 must be FPSCR"));
8068
8069 inst.instruction |= (Rt << 12);
8070}
8071
8072static void
8073do_vmsr (void)
8074{
8075 unsigned Rt = inst.operands[1].reg;
8076
8077 if (thumb_mode)
8078 reject_bad_reg (Rt);
8079 else if (Rt == REG_PC)
8080 {
8081 inst.error = BAD_PC;
8082 return;
8083 }
8084
8085 if (inst.operands[0].reg != 1)
8086 first_error (_("operand 0 must be FPSCR"));
8087
8088 inst.instruction |= (Rt << 12);
8089}
8090
b99bd4ef 8091static void
c19d1205 8092do_mrs (void)
b99bd4ef 8093{
90ec0d68
MGD
8094 unsigned br;
8095
037e8744
JB
8096 if (do_vfp_nsyn_mrs () == SUCCESS)
8097 return;
8098
ff4a8d2b 8099 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 8100 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
8101
8102 if (inst.operands[1].isreg)
8103 {
8104 br = inst.operands[1].reg;
8105 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
8106 as_bad (_("bad register for mrs"));
8107 }
8108 else
8109 {
8110 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
8111 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
8112 != (PSR_c|PSR_f),
d2cd1205 8113 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
8114 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
8115 }
8116
8117 inst.instruction |= br;
c19d1205 8118}
b99bd4ef 8119
c19d1205
ZW
8120/* Two possible forms:
8121 "{C|S}PSR_<field>, Rm",
8122 "{C|S}PSR_f, #expression". */
b99bd4ef 8123
c19d1205
ZW
8124static void
8125do_msr (void)
8126{
037e8744
JB
8127 if (do_vfp_nsyn_msr () == SUCCESS)
8128 return;
8129
c19d1205
ZW
8130 inst.instruction |= inst.operands[0].imm;
8131 if (inst.operands[1].isreg)
8132 inst.instruction |= inst.operands[1].reg;
8133 else
b99bd4ef 8134 {
c19d1205
ZW
8135 inst.instruction |= INST_IMMEDIATE;
8136 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8137 inst.reloc.pc_rel = 0;
b99bd4ef 8138 }
b99bd4ef
NC
8139}
8140
c19d1205
ZW
8141static void
8142do_mul (void)
a737bd4d 8143{
ff4a8d2b
NC
8144 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
8145
c19d1205
ZW
8146 if (!inst.operands[2].present)
8147 inst.operands[2].reg = inst.operands[0].reg;
8148 inst.instruction |= inst.operands[0].reg << 16;
8149 inst.instruction |= inst.operands[1].reg;
8150 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 8151
8fb9d7b9
MS
8152 if (inst.operands[0].reg == inst.operands[1].reg
8153 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8154 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
8155}
8156
c19d1205
ZW
8157/* Long Multiply Parser
8158 UMULL RdLo, RdHi, Rm, Rs
8159 SMULL RdLo, RdHi, Rm, Rs
8160 UMLAL RdLo, RdHi, Rm, Rs
8161 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
8162
8163static void
c19d1205 8164do_mull (void)
b99bd4ef 8165{
c19d1205
ZW
8166 inst.instruction |= inst.operands[0].reg << 12;
8167 inst.instruction |= inst.operands[1].reg << 16;
8168 inst.instruction |= inst.operands[2].reg;
8169 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 8170
682b27ad
PB
8171 /* rdhi and rdlo must be different. */
8172 if (inst.operands[0].reg == inst.operands[1].reg)
8173 as_tsktsk (_("rdhi and rdlo must be different"));
8174
8175 /* rdhi, rdlo and rm must all be different before armv6. */
8176 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 8177 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 8178 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
8179 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
8180}
b99bd4ef 8181
c19d1205
ZW
8182static void
8183do_nop (void)
8184{
e7495e45
NS
8185 if (inst.operands[0].present
8186 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
8187 {
8188 /* Architectural NOP hints are CPSR sets with no bits selected. */
8189 inst.instruction &= 0xf0000000;
e7495e45
NS
8190 inst.instruction |= 0x0320f000;
8191 if (inst.operands[0].present)
8192 inst.instruction |= inst.operands[0].imm;
c19d1205 8193 }
b99bd4ef
NC
8194}
8195
c19d1205
ZW
8196/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
8197 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
8198 Condition defaults to COND_ALWAYS.
8199 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
8200
8201static void
c19d1205 8202do_pkhbt (void)
b99bd4ef 8203{
c19d1205
ZW
8204 inst.instruction |= inst.operands[0].reg << 12;
8205 inst.instruction |= inst.operands[1].reg << 16;
8206 inst.instruction |= inst.operands[2].reg;
8207 if (inst.operands[3].present)
8208 encode_arm_shift (3);
8209}
b99bd4ef 8210
c19d1205 8211/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 8212
c19d1205
ZW
8213static void
8214do_pkhtb (void)
8215{
8216 if (!inst.operands[3].present)
b99bd4ef 8217 {
c19d1205
ZW
8218 /* If the shift specifier is omitted, turn the instruction
8219 into pkhbt rd, rm, rn. */
8220 inst.instruction &= 0xfff00010;
8221 inst.instruction |= inst.operands[0].reg << 12;
8222 inst.instruction |= inst.operands[1].reg;
8223 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8224 }
8225 else
8226 {
c19d1205
ZW
8227 inst.instruction |= inst.operands[0].reg << 12;
8228 inst.instruction |= inst.operands[1].reg << 16;
8229 inst.instruction |= inst.operands[2].reg;
8230 encode_arm_shift (3);
b99bd4ef
NC
8231 }
8232}
8233
c19d1205 8234/* ARMv5TE: Preload-Cache
60e5ef9f 8235 MP Extensions: Preload for write
c19d1205 8236
60e5ef9f 8237 PLD(W) <addr_mode>
c19d1205
ZW
8238
8239 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
8240
8241static void
c19d1205 8242do_pld (void)
b99bd4ef 8243{
c19d1205
ZW
8244 constraint (!inst.operands[0].isreg,
8245 _("'[' expected after PLD mnemonic"));
8246 constraint (inst.operands[0].postind,
8247 _("post-indexed expression used in preload instruction"));
8248 constraint (inst.operands[0].writeback,
8249 _("writeback used in preload instruction"));
8250 constraint (!inst.operands[0].preind,
8251 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
8252 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8253}
b99bd4ef 8254
62b3e311
PB
8255/* ARMv7: PLI <addr_mode> */
8256static void
8257do_pli (void)
8258{
8259 constraint (!inst.operands[0].isreg,
8260 _("'[' expected after PLI mnemonic"));
8261 constraint (inst.operands[0].postind,
8262 _("post-indexed expression used in preload instruction"));
8263 constraint (inst.operands[0].writeback,
8264 _("writeback used in preload instruction"));
8265 constraint (!inst.operands[0].preind,
8266 _("unindexed addressing used in preload instruction"));
8267 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8268 inst.instruction &= ~PRE_INDEX;
8269}
8270
c19d1205
ZW
8271static void
8272do_push_pop (void)
8273{
8274 inst.operands[1] = inst.operands[0];
8275 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8276 inst.operands[0].isreg = 1;
8277 inst.operands[0].writeback = 1;
8278 inst.operands[0].reg = REG_SP;
8279 do_ldmstm ();
8280}
b99bd4ef 8281
c19d1205
ZW
8282/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8283 word at the specified address and the following word
8284 respectively.
8285 Unconditionally executed.
8286 Error if Rn is R15. */
b99bd4ef 8287
c19d1205
ZW
8288static void
8289do_rfe (void)
8290{
8291 inst.instruction |= inst.operands[0].reg << 16;
8292 if (inst.operands[0].writeback)
8293 inst.instruction |= WRITE_BACK;
8294}
b99bd4ef 8295
c19d1205 8296/* ARM V6 ssat (argument parse). */
b99bd4ef 8297
c19d1205
ZW
8298static void
8299do_ssat (void)
8300{
8301 inst.instruction |= inst.operands[0].reg << 12;
8302 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8303 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8304
c19d1205
ZW
8305 if (inst.operands[3].present)
8306 encode_arm_shift (3);
b99bd4ef
NC
8307}
8308
c19d1205 8309/* ARM V6 usat (argument parse). */
b99bd4ef
NC
8310
8311static void
c19d1205 8312do_usat (void)
b99bd4ef 8313{
c19d1205
ZW
8314 inst.instruction |= inst.operands[0].reg << 12;
8315 inst.instruction |= inst.operands[1].imm << 16;
8316 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8317
c19d1205
ZW
8318 if (inst.operands[3].present)
8319 encode_arm_shift (3);
b99bd4ef
NC
8320}
8321
c19d1205 8322/* ARM V6 ssat16 (argument parse). */
09d92015
MM
8323
8324static void
c19d1205 8325do_ssat16 (void)
09d92015 8326{
c19d1205
ZW
8327 inst.instruction |= inst.operands[0].reg << 12;
8328 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8329 inst.instruction |= inst.operands[2].reg;
09d92015
MM
8330}
8331
c19d1205
ZW
8332static void
8333do_usat16 (void)
a737bd4d 8334{
c19d1205
ZW
8335 inst.instruction |= inst.operands[0].reg << 12;
8336 inst.instruction |= inst.operands[1].imm << 16;
8337 inst.instruction |= inst.operands[2].reg;
8338}
a737bd4d 8339
c19d1205
ZW
8340/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8341 preserving the other bits.
a737bd4d 8342
c19d1205
ZW
8343 setend <endian_specifier>, where <endian_specifier> is either
8344 BE or LE. */
a737bd4d 8345
c19d1205
ZW
8346static void
8347do_setend (void)
8348{
8349 if (inst.operands[0].imm)
8350 inst.instruction |= 0x200;
a737bd4d
NC
8351}
8352
8353static void
c19d1205 8354do_shift (void)
a737bd4d 8355{
c19d1205
ZW
8356 unsigned int Rm = (inst.operands[1].present
8357 ? inst.operands[1].reg
8358 : inst.operands[0].reg);
a737bd4d 8359
c19d1205
ZW
8360 inst.instruction |= inst.operands[0].reg << 12;
8361 inst.instruction |= Rm;
8362 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 8363 {
c19d1205
ZW
8364 inst.instruction |= inst.operands[2].reg << 8;
8365 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
8366 /* PR 12854: Error on extraneous shifts. */
8367 constraint (inst.operands[2].shifted,
8368 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
8369 }
8370 else
c19d1205 8371 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
8372}
8373
09d92015 8374static void
3eb17e6b 8375do_smc (void)
09d92015 8376{
3eb17e6b 8377 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 8378 inst.reloc.pc_rel = 0;
09d92015
MM
8379}
8380
90ec0d68
MGD
8381static void
8382do_hvc (void)
8383{
8384 inst.reloc.type = BFD_RELOC_ARM_HVC;
8385 inst.reloc.pc_rel = 0;
8386}
8387
09d92015 8388static void
c19d1205 8389do_swi (void)
09d92015 8390{
c19d1205
ZW
8391 inst.reloc.type = BFD_RELOC_ARM_SWI;
8392 inst.reloc.pc_rel = 0;
09d92015
MM
8393}
8394
c19d1205
ZW
8395/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8396 SMLAxy{cond} Rd,Rm,Rs,Rn
8397 SMLAWy{cond} Rd,Rm,Rs,Rn
8398 Error if any register is R15. */
e16bb312 8399
c19d1205
ZW
8400static void
8401do_smla (void)
e16bb312 8402{
c19d1205
ZW
8403 inst.instruction |= inst.operands[0].reg << 16;
8404 inst.instruction |= inst.operands[1].reg;
8405 inst.instruction |= inst.operands[2].reg << 8;
8406 inst.instruction |= inst.operands[3].reg << 12;
8407}
a737bd4d 8408
c19d1205
ZW
8409/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8410 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8411 Error if any register is R15.
8412 Warning if Rdlo == Rdhi. */
a737bd4d 8413
c19d1205
ZW
8414static void
8415do_smlal (void)
8416{
8417 inst.instruction |= inst.operands[0].reg << 12;
8418 inst.instruction |= inst.operands[1].reg << 16;
8419 inst.instruction |= inst.operands[2].reg;
8420 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 8421
c19d1205
ZW
8422 if (inst.operands[0].reg == inst.operands[1].reg)
8423 as_tsktsk (_("rdhi and rdlo must be different"));
8424}
a737bd4d 8425
c19d1205
ZW
8426/* ARM V5E (El Segundo) signed-multiply (argument parse)
8427 SMULxy{cond} Rd,Rm,Rs
8428 Error if any register is R15. */
a737bd4d 8429
c19d1205
ZW
8430static void
8431do_smul (void)
8432{
8433 inst.instruction |= inst.operands[0].reg << 16;
8434 inst.instruction |= inst.operands[1].reg;
8435 inst.instruction |= inst.operands[2].reg << 8;
8436}
a737bd4d 8437
b6702015
PB
8438/* ARM V6 srs (argument parse). The variable fields in the encoding are
8439 the same for both ARM and Thumb-2. */
a737bd4d 8440
c19d1205
ZW
8441static void
8442do_srs (void)
8443{
b6702015
PB
8444 int reg;
8445
8446 if (inst.operands[0].present)
8447 {
8448 reg = inst.operands[0].reg;
fdfde340 8449 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
8450 }
8451 else
fdfde340 8452 reg = REG_SP;
b6702015
PB
8453
8454 inst.instruction |= reg << 16;
8455 inst.instruction |= inst.operands[1].imm;
8456 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
8457 inst.instruction |= WRITE_BACK;
8458}
a737bd4d 8459
c19d1205 8460/* ARM V6 strex (argument parse). */
a737bd4d 8461
c19d1205
ZW
8462static void
8463do_strex (void)
8464{
8465 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8466 || inst.operands[2].postind || inst.operands[2].writeback
8467 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
8468 || inst.operands[2].negative
8469 /* See comment in do_ldrex(). */
8470 || (inst.operands[2].reg == REG_PC),
8471 BAD_ADDR_MODE);
a737bd4d 8472
c19d1205
ZW
8473 constraint (inst.operands[0].reg == inst.operands[1].reg
8474 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 8475
c19d1205
ZW
8476 constraint (inst.reloc.exp.X_op != O_constant
8477 || inst.reloc.exp.X_add_number != 0,
8478 _("offset must be zero in ARM encoding"));
a737bd4d 8479
c19d1205
ZW
8480 inst.instruction |= inst.operands[0].reg << 12;
8481 inst.instruction |= inst.operands[1].reg;
8482 inst.instruction |= inst.operands[2].reg << 16;
8483 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8484}
8485
8486static void
c19d1205 8487do_strexd (void)
e16bb312 8488{
c19d1205
ZW
8489 constraint (inst.operands[1].reg % 2 != 0,
8490 _("even register required"));
8491 constraint (inst.operands[2].present
8492 && inst.operands[2].reg != inst.operands[1].reg + 1,
8493 _("can only store two consecutive registers"));
8494 /* If op 2 were present and equal to PC, this function wouldn't
8495 have been called in the first place. */
8496 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8497
c19d1205
ZW
8498 constraint (inst.operands[0].reg == inst.operands[1].reg
8499 || inst.operands[0].reg == inst.operands[1].reg + 1
8500 || inst.operands[0].reg == inst.operands[3].reg,
8501 BAD_OVERLAP);
e16bb312 8502
c19d1205
ZW
8503 inst.instruction |= inst.operands[0].reg << 12;
8504 inst.instruction |= inst.operands[1].reg;
8505 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8506}
8507
c19d1205
ZW
8508/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8509 extends it to 32-bits, and adds the result to a value in another
8510 register. You can specify a rotation by 0, 8, 16, or 24 bits
8511 before extracting the 16-bit value.
8512 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8513 Condition defaults to COND_ALWAYS.
8514 Error if any register uses R15. */
8515
e16bb312 8516static void
c19d1205 8517do_sxtah (void)
e16bb312 8518{
c19d1205
ZW
8519 inst.instruction |= inst.operands[0].reg << 12;
8520 inst.instruction |= inst.operands[1].reg << 16;
8521 inst.instruction |= inst.operands[2].reg;
8522 inst.instruction |= inst.operands[3].imm << 10;
8523}
e16bb312 8524
c19d1205 8525/* ARM V6 SXTH.
e16bb312 8526
c19d1205
ZW
8527 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8528 Condition defaults to COND_ALWAYS.
8529 Error if any register uses R15. */
e16bb312
NC
8530
8531static void
c19d1205 8532do_sxth (void)
e16bb312 8533{
c19d1205
ZW
8534 inst.instruction |= inst.operands[0].reg << 12;
8535 inst.instruction |= inst.operands[1].reg;
8536 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8537}
c19d1205
ZW
8538\f
8539/* VFP instructions. In a logical order: SP variant first, monad
8540 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8541
8542static void
c19d1205 8543do_vfp_sp_monadic (void)
e16bb312 8544{
5287ad62
JB
8545 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8546 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8547}
8548
8549static void
c19d1205 8550do_vfp_sp_dyadic (void)
e16bb312 8551{
5287ad62
JB
8552 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8553 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8554 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8555}
8556
8557static void
c19d1205 8558do_vfp_sp_compare_z (void)
e16bb312 8559{
5287ad62 8560 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8561}
8562
8563static void
c19d1205 8564do_vfp_dp_sp_cvt (void)
e16bb312 8565{
5287ad62
JB
8566 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8567 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8568}
8569
8570static void
c19d1205 8571do_vfp_sp_dp_cvt (void)
e16bb312 8572{
5287ad62
JB
8573 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8574 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8575}
8576
8577static void
c19d1205 8578do_vfp_reg_from_sp (void)
e16bb312 8579{
c19d1205 8580 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8581 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8582}
8583
8584static void
c19d1205 8585do_vfp_reg2_from_sp2 (void)
e16bb312 8586{
c19d1205
ZW
8587 constraint (inst.operands[2].imm != 2,
8588 _("only two consecutive VFP SP registers allowed here"));
8589 inst.instruction |= inst.operands[0].reg << 12;
8590 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8591 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8592}
8593
8594static void
c19d1205 8595do_vfp_sp_from_reg (void)
e16bb312 8596{
5287ad62 8597 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8598 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8599}
8600
8601static void
c19d1205 8602do_vfp_sp2_from_reg2 (void)
e16bb312 8603{
c19d1205
ZW
8604 constraint (inst.operands[0].imm != 2,
8605 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8606 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8607 inst.instruction |= inst.operands[1].reg << 12;
8608 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8609}
8610
8611static void
c19d1205 8612do_vfp_sp_ldst (void)
e16bb312 8613{
5287ad62 8614 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 8615 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8616}
8617
8618static void
c19d1205 8619do_vfp_dp_ldst (void)
e16bb312 8620{
5287ad62 8621 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 8622 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8623}
8624
c19d1205 8625
e16bb312 8626static void
c19d1205 8627vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8628{
c19d1205
ZW
8629 if (inst.operands[0].writeback)
8630 inst.instruction |= WRITE_BACK;
8631 else
8632 constraint (ldstm_type != VFP_LDSTMIA,
8633 _("this addressing mode requires base-register writeback"));
8634 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8635 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 8636 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
8637}
8638
8639static void
c19d1205 8640vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8641{
c19d1205 8642 int count;
e16bb312 8643
c19d1205
ZW
8644 if (inst.operands[0].writeback)
8645 inst.instruction |= WRITE_BACK;
8646 else
8647 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8648 _("this addressing mode requires base-register writeback"));
e16bb312 8649
c19d1205 8650 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8651 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 8652
c19d1205
ZW
8653 count = inst.operands[1].imm << 1;
8654 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8655 count += 1;
e16bb312 8656
c19d1205 8657 inst.instruction |= count;
e16bb312
NC
8658}
8659
8660static void
c19d1205 8661do_vfp_sp_ldstmia (void)
e16bb312 8662{
c19d1205 8663 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8664}
8665
8666static void
c19d1205 8667do_vfp_sp_ldstmdb (void)
e16bb312 8668{
c19d1205 8669 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8670}
8671
8672static void
c19d1205 8673do_vfp_dp_ldstmia (void)
e16bb312 8674{
c19d1205 8675 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8676}
8677
8678static void
c19d1205 8679do_vfp_dp_ldstmdb (void)
e16bb312 8680{
c19d1205 8681 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8682}
8683
8684static void
c19d1205 8685do_vfp_xp_ldstmia (void)
e16bb312 8686{
c19d1205
ZW
8687 vfp_dp_ldstm (VFP_LDSTMIAX);
8688}
e16bb312 8689
c19d1205
ZW
8690static void
8691do_vfp_xp_ldstmdb (void)
8692{
8693 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 8694}
5287ad62
JB
8695
8696static void
8697do_vfp_dp_rd_rm (void)
8698{
8699 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8700 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8701}
8702
8703static void
8704do_vfp_dp_rn_rd (void)
8705{
8706 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8707 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8708}
8709
8710static void
8711do_vfp_dp_rd_rn (void)
8712{
8713 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8714 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8715}
8716
8717static void
8718do_vfp_dp_rd_rn_rm (void)
8719{
8720 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8721 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8722 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8723}
8724
8725static void
8726do_vfp_dp_rd (void)
8727{
8728 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8729}
8730
8731static void
8732do_vfp_dp_rm_rd_rn (void)
8733{
8734 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8735 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8736 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8737}
8738
8739/* VFPv3 instructions. */
8740static void
8741do_vfp_sp_const (void)
8742{
8743 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8744 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8745 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8746}
8747
8748static void
8749do_vfp_dp_const (void)
8750{
8751 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8752 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8753 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8754}
8755
8756static void
8757vfp_conv (int srcsize)
8758{
5f1af56b
MGD
8759 int immbits = srcsize - inst.operands[1].imm;
8760
8761 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
8762 {
8763 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
8764 i.e. immbits must be in range 0 - 16. */
8765 inst.error = _("immediate value out of range, expected range [0, 16]");
8766 return;
8767 }
8768 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
8769 {
8770 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
8771 i.e. immbits must be in range 0 - 31. */
8772 inst.error = _("immediate value out of range, expected range [1, 32]");
8773 return;
8774 }
8775
5287ad62
JB
8776 inst.instruction |= (immbits & 1) << 5;
8777 inst.instruction |= (immbits >> 1);
8778}
8779
8780static void
8781do_vfp_sp_conv_16 (void)
8782{
8783 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8784 vfp_conv (16);
8785}
8786
8787static void
8788do_vfp_dp_conv_16 (void)
8789{
8790 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8791 vfp_conv (16);
8792}
8793
8794static void
8795do_vfp_sp_conv_32 (void)
8796{
8797 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8798 vfp_conv (32);
8799}
8800
8801static void
8802do_vfp_dp_conv_32 (void)
8803{
8804 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8805 vfp_conv (32);
8806}
c19d1205
ZW
8807\f
8808/* FPA instructions. Also in a logical order. */
e16bb312 8809
c19d1205
ZW
8810static void
8811do_fpa_cmp (void)
8812{
8813 inst.instruction |= inst.operands[0].reg << 16;
8814 inst.instruction |= inst.operands[1].reg;
8815}
b99bd4ef
NC
8816
8817static void
c19d1205 8818do_fpa_ldmstm (void)
b99bd4ef 8819{
c19d1205
ZW
8820 inst.instruction |= inst.operands[0].reg << 12;
8821 switch (inst.operands[1].imm)
8822 {
8823 case 1: inst.instruction |= CP_T_X; break;
8824 case 2: inst.instruction |= CP_T_Y; break;
8825 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8826 case 4: break;
8827 default: abort ();
8828 }
b99bd4ef 8829
c19d1205
ZW
8830 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8831 {
8832 /* The instruction specified "ea" or "fd", so we can only accept
8833 [Rn]{!}. The instruction does not really support stacking or
8834 unstacking, so we have to emulate these by setting appropriate
8835 bits and offsets. */
8836 constraint (inst.reloc.exp.X_op != O_constant
8837 || inst.reloc.exp.X_add_number != 0,
8838 _("this instruction does not support indexing"));
b99bd4ef 8839
c19d1205
ZW
8840 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8841 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8842
c19d1205
ZW
8843 if (!(inst.instruction & INDEX_UP))
8844 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8845
c19d1205
ZW
8846 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8847 {
8848 inst.operands[2].preind = 0;
8849 inst.operands[2].postind = 1;
8850 }
8851 }
b99bd4ef 8852
c19d1205 8853 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8854}
c19d1205
ZW
8855\f
8856/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8857
c19d1205
ZW
8858static void
8859do_iwmmxt_tandorc (void)
8860{
8861 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8862}
b99bd4ef 8863
c19d1205
ZW
8864static void
8865do_iwmmxt_textrc (void)
8866{
8867 inst.instruction |= inst.operands[0].reg << 12;
8868 inst.instruction |= inst.operands[1].imm;
8869}
b99bd4ef
NC
8870
8871static void
c19d1205 8872do_iwmmxt_textrm (void)
b99bd4ef 8873{
c19d1205
ZW
8874 inst.instruction |= inst.operands[0].reg << 12;
8875 inst.instruction |= inst.operands[1].reg << 16;
8876 inst.instruction |= inst.operands[2].imm;
8877}
b99bd4ef 8878
c19d1205
ZW
8879static void
8880do_iwmmxt_tinsr (void)
8881{
8882 inst.instruction |= inst.operands[0].reg << 16;
8883 inst.instruction |= inst.operands[1].reg << 12;
8884 inst.instruction |= inst.operands[2].imm;
8885}
b99bd4ef 8886
c19d1205
ZW
8887static void
8888do_iwmmxt_tmia (void)
8889{
8890 inst.instruction |= inst.operands[0].reg << 5;
8891 inst.instruction |= inst.operands[1].reg;
8892 inst.instruction |= inst.operands[2].reg << 12;
8893}
b99bd4ef 8894
c19d1205
ZW
8895static void
8896do_iwmmxt_waligni (void)
8897{
8898 inst.instruction |= inst.operands[0].reg << 12;
8899 inst.instruction |= inst.operands[1].reg << 16;
8900 inst.instruction |= inst.operands[2].reg;
8901 inst.instruction |= inst.operands[3].imm << 20;
8902}
b99bd4ef 8903
2d447fca
JM
8904static void
8905do_iwmmxt_wmerge (void)
8906{
8907 inst.instruction |= inst.operands[0].reg << 12;
8908 inst.instruction |= inst.operands[1].reg << 16;
8909 inst.instruction |= inst.operands[2].reg;
8910 inst.instruction |= inst.operands[3].imm << 21;
8911}
8912
c19d1205
ZW
8913static void
8914do_iwmmxt_wmov (void)
8915{
8916 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8917 inst.instruction |= inst.operands[0].reg << 12;
8918 inst.instruction |= inst.operands[1].reg << 16;
8919 inst.instruction |= inst.operands[1].reg;
8920}
b99bd4ef 8921
c19d1205
ZW
8922static void
8923do_iwmmxt_wldstbh (void)
8924{
8f06b2d8 8925 int reloc;
c19d1205 8926 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8927 if (thumb_mode)
8928 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8929 else
8930 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8931 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8932}
8933
c19d1205
ZW
8934static void
8935do_iwmmxt_wldstw (void)
8936{
8937 /* RIWR_RIWC clears .isreg for a control register. */
8938 if (!inst.operands[0].isreg)
8939 {
8940 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8941 inst.instruction |= 0xf0000000;
8942 }
b99bd4ef 8943
c19d1205
ZW
8944 inst.instruction |= inst.operands[0].reg << 12;
8945 encode_arm_cp_address (1, TRUE, TRUE, 0);
8946}
b99bd4ef
NC
8947
8948static void
c19d1205 8949do_iwmmxt_wldstd (void)
b99bd4ef 8950{
c19d1205 8951 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8952 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8953 && inst.operands[1].immisreg)
8954 {
8955 inst.instruction &= ~0x1a000ff;
8956 inst.instruction |= (0xf << 28);
8957 if (inst.operands[1].preind)
8958 inst.instruction |= PRE_INDEX;
8959 if (!inst.operands[1].negative)
8960 inst.instruction |= INDEX_UP;
8961 if (inst.operands[1].writeback)
8962 inst.instruction |= WRITE_BACK;
8963 inst.instruction |= inst.operands[1].reg << 16;
8964 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8965 inst.instruction |= inst.operands[1].imm;
8966 }
8967 else
8968 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8969}
b99bd4ef 8970
c19d1205
ZW
8971static void
8972do_iwmmxt_wshufh (void)
8973{
8974 inst.instruction |= inst.operands[0].reg << 12;
8975 inst.instruction |= inst.operands[1].reg << 16;
8976 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8977 inst.instruction |= (inst.operands[2].imm & 0x0f);
8978}
b99bd4ef 8979
c19d1205
ZW
8980static void
8981do_iwmmxt_wzero (void)
8982{
8983 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8984 inst.instruction |= inst.operands[0].reg;
8985 inst.instruction |= inst.operands[0].reg << 12;
8986 inst.instruction |= inst.operands[0].reg << 16;
8987}
2d447fca
JM
8988
8989static void
8990do_iwmmxt_wrwrwr_or_imm5 (void)
8991{
8992 if (inst.operands[2].isreg)
8993 do_rd_rn_rm ();
8994 else {
8995 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8996 _("immediate operand requires iWMMXt2"));
8997 do_rd_rn ();
8998 if (inst.operands[2].imm == 0)
8999 {
9000 switch ((inst.instruction >> 20) & 0xf)
9001 {
9002 case 4:
9003 case 5:
9004 case 6:
5f4273c7 9005 case 7:
2d447fca
JM
9006 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
9007 inst.operands[2].imm = 16;
9008 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
9009 break;
9010 case 8:
9011 case 9:
9012 case 10:
9013 case 11:
9014 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
9015 inst.operands[2].imm = 32;
9016 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
9017 break;
9018 case 12:
9019 case 13:
9020 case 14:
9021 case 15:
9022 {
9023 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
9024 unsigned long wrn;
9025 wrn = (inst.instruction >> 16) & 0xf;
9026 inst.instruction &= 0xff0fff0f;
9027 inst.instruction |= wrn;
9028 /* Bail out here; the instruction is now assembled. */
9029 return;
9030 }
9031 }
9032 }
9033 /* Map 32 -> 0, etc. */
9034 inst.operands[2].imm &= 0x1f;
9035 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
9036 }
9037}
c19d1205
ZW
9038\f
9039/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
9040 operations first, then control, shift, and load/store. */
b99bd4ef 9041
c19d1205 9042/* Insns like "foo X,Y,Z". */
b99bd4ef 9043
c19d1205
ZW
9044static void
9045do_mav_triple (void)
9046{
9047 inst.instruction |= inst.operands[0].reg << 16;
9048 inst.instruction |= inst.operands[1].reg;
9049 inst.instruction |= inst.operands[2].reg << 12;
9050}
b99bd4ef 9051
c19d1205
ZW
9052/* Insns like "foo W,X,Y,Z".
9053 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 9054
c19d1205
ZW
9055static void
9056do_mav_quad (void)
9057{
9058 inst.instruction |= inst.operands[0].reg << 5;
9059 inst.instruction |= inst.operands[1].reg << 12;
9060 inst.instruction |= inst.operands[2].reg << 16;
9061 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
9062}
9063
c19d1205
ZW
9064/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
9065static void
9066do_mav_dspsc (void)
a737bd4d 9067{
c19d1205
ZW
9068 inst.instruction |= inst.operands[1].reg << 12;
9069}
a737bd4d 9070
c19d1205
ZW
9071/* Maverick shift immediate instructions.
9072 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
9073 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 9074
c19d1205
ZW
9075static void
9076do_mav_shift (void)
9077{
9078 int imm = inst.operands[2].imm;
a737bd4d 9079
c19d1205
ZW
9080 inst.instruction |= inst.operands[0].reg << 12;
9081 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 9082
c19d1205
ZW
9083 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
9084 Bits 5-7 of the insn should have bits 4-6 of the immediate.
9085 Bit 4 should be 0. */
9086 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 9087
c19d1205
ZW
9088 inst.instruction |= imm;
9089}
9090\f
9091/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 9092
c19d1205
ZW
9093/* Xscale multiply-accumulate (argument parse)
9094 MIAcc acc0,Rm,Rs
9095 MIAPHcc acc0,Rm,Rs
9096 MIAxycc acc0,Rm,Rs. */
a737bd4d 9097
c19d1205
ZW
9098static void
9099do_xsc_mia (void)
9100{
9101 inst.instruction |= inst.operands[1].reg;
9102 inst.instruction |= inst.operands[2].reg << 12;
9103}
a737bd4d 9104
c19d1205 9105/* Xscale move-accumulator-register (argument parse)
a737bd4d 9106
c19d1205 9107 MARcc acc0,RdLo,RdHi. */
b99bd4ef 9108
c19d1205
ZW
9109static void
9110do_xsc_mar (void)
9111{
9112 inst.instruction |= inst.operands[1].reg << 12;
9113 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9114}
9115
c19d1205 9116/* Xscale move-register-accumulator (argument parse)
b99bd4ef 9117
c19d1205 9118 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
9119
9120static void
c19d1205 9121do_xsc_mra (void)
b99bd4ef 9122{
c19d1205
ZW
9123 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
9124 inst.instruction |= inst.operands[0].reg << 12;
9125 inst.instruction |= inst.operands[1].reg << 16;
9126}
9127\f
9128/* Encoding functions relevant only to Thumb. */
b99bd4ef 9129
c19d1205
ZW
9130/* inst.operands[i] is a shifted-register operand; encode
9131 it into inst.instruction in the format used by Thumb32. */
9132
9133static void
9134encode_thumb32_shifted_operand (int i)
9135{
9136 unsigned int value = inst.reloc.exp.X_add_number;
9137 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 9138
9c3c69f2
PB
9139 constraint (inst.operands[i].immisreg,
9140 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
9141 inst.instruction |= inst.operands[i].reg;
9142 if (shift == SHIFT_RRX)
9143 inst.instruction |= SHIFT_ROR << 4;
9144 else
b99bd4ef 9145 {
c19d1205
ZW
9146 constraint (inst.reloc.exp.X_op != O_constant,
9147 _("expression too complex"));
9148
9149 constraint (value > 32
9150 || (value == 32 && (shift == SHIFT_LSL
9151 || shift == SHIFT_ROR)),
9152 _("shift expression is too large"));
9153
9154 if (value == 0)
9155 shift = SHIFT_LSL;
9156 else if (value == 32)
9157 value = 0;
9158
9159 inst.instruction |= shift << 4;
9160 inst.instruction |= (value & 0x1c) << 10;
9161 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 9162 }
c19d1205 9163}
b99bd4ef 9164
b99bd4ef 9165
c19d1205
ZW
9166/* inst.operands[i] was set up by parse_address. Encode it into a
9167 Thumb32 format load or store instruction. Reject forms that cannot
9168 be used with such instructions. If is_t is true, reject forms that
9169 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
9170 that cannot be used with a D instruction. If it is a store insn,
9171 reject PC in Rn. */
b99bd4ef 9172
c19d1205
ZW
9173static void
9174encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
9175{
5be8be5d 9176 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
9177
9178 constraint (!inst.operands[i].isreg,
53365c0d 9179 _("Instruction does not support =N addresses"));
b99bd4ef 9180
c19d1205
ZW
9181 inst.instruction |= inst.operands[i].reg << 16;
9182 if (inst.operands[i].immisreg)
b99bd4ef 9183 {
5be8be5d 9184 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
9185 constraint (is_t || is_d, _("cannot use register index with this instruction"));
9186 constraint (inst.operands[i].negative,
9187 _("Thumb does not support negative register indexing"));
9188 constraint (inst.operands[i].postind,
9189 _("Thumb does not support register post-indexing"));
9190 constraint (inst.operands[i].writeback,
9191 _("Thumb does not support register indexing with writeback"));
9192 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
9193 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 9194
f40d1643 9195 inst.instruction |= inst.operands[i].imm;
c19d1205 9196 if (inst.operands[i].shifted)
b99bd4ef 9197 {
c19d1205
ZW
9198 constraint (inst.reloc.exp.X_op != O_constant,
9199 _("expression too complex"));
9c3c69f2
PB
9200 constraint (inst.reloc.exp.X_add_number < 0
9201 || inst.reloc.exp.X_add_number > 3,
c19d1205 9202 _("shift out of range"));
9c3c69f2 9203 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
9204 }
9205 inst.reloc.type = BFD_RELOC_UNUSED;
9206 }
9207 else if (inst.operands[i].preind)
9208 {
5be8be5d 9209 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 9210 constraint (is_t && inst.operands[i].writeback,
c19d1205 9211 _("cannot use writeback with this instruction"));
5be8be5d
DG
9212 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
9213 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
c19d1205
ZW
9214
9215 if (is_d)
9216 {
9217 inst.instruction |= 0x01000000;
9218 if (inst.operands[i].writeback)
9219 inst.instruction |= 0x00200000;
b99bd4ef 9220 }
c19d1205 9221 else
b99bd4ef 9222 {
c19d1205
ZW
9223 inst.instruction |= 0x00000c00;
9224 if (inst.operands[i].writeback)
9225 inst.instruction |= 0x00000100;
b99bd4ef 9226 }
c19d1205 9227 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 9228 }
c19d1205 9229 else if (inst.operands[i].postind)
b99bd4ef 9230 {
9c2799c2 9231 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
9232 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
9233 constraint (is_t, _("cannot use post-indexing with this instruction"));
9234
9235 if (is_d)
9236 inst.instruction |= 0x00200000;
9237 else
9238 inst.instruction |= 0x00000900;
9239 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9240 }
9241 else /* unindexed - only for coprocessor */
9242 inst.error = _("instruction does not accept unindexed addressing");
9243}
9244
9245/* Table of Thumb instructions which exist in both 16- and 32-bit
9246 encodings (the latter only in post-V6T2 cores). The index is the
9247 value used in the insns table below. When there is more than one
9248 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
9249 holds variant (1).
9250 Also contains several pseudo-instructions used during relaxation. */
c19d1205 9251#define T16_32_TAB \
21d799b5
NC
9252 X(_adc, 4140, eb400000), \
9253 X(_adcs, 4140, eb500000), \
9254 X(_add, 1c00, eb000000), \
9255 X(_adds, 1c00, eb100000), \
9256 X(_addi, 0000, f1000000), \
9257 X(_addis, 0000, f1100000), \
9258 X(_add_pc,000f, f20f0000), \
9259 X(_add_sp,000d, f10d0000), \
9260 X(_adr, 000f, f20f0000), \
9261 X(_and, 4000, ea000000), \
9262 X(_ands, 4000, ea100000), \
9263 X(_asr, 1000, fa40f000), \
9264 X(_asrs, 1000, fa50f000), \
9265 X(_b, e000, f000b000), \
9266 X(_bcond, d000, f0008000), \
9267 X(_bic, 4380, ea200000), \
9268 X(_bics, 4380, ea300000), \
9269 X(_cmn, 42c0, eb100f00), \
9270 X(_cmp, 2800, ebb00f00), \
9271 X(_cpsie, b660, f3af8400), \
9272 X(_cpsid, b670, f3af8600), \
9273 X(_cpy, 4600, ea4f0000), \
9274 X(_dec_sp,80dd, f1ad0d00), \
9275 X(_eor, 4040, ea800000), \
9276 X(_eors, 4040, ea900000), \
9277 X(_inc_sp,00dd, f10d0d00), \
9278 X(_ldmia, c800, e8900000), \
9279 X(_ldr, 6800, f8500000), \
9280 X(_ldrb, 7800, f8100000), \
9281 X(_ldrh, 8800, f8300000), \
9282 X(_ldrsb, 5600, f9100000), \
9283 X(_ldrsh, 5e00, f9300000), \
9284 X(_ldr_pc,4800, f85f0000), \
9285 X(_ldr_pc2,4800, f85f0000), \
9286 X(_ldr_sp,9800, f85d0000), \
9287 X(_lsl, 0000, fa00f000), \
9288 X(_lsls, 0000, fa10f000), \
9289 X(_lsr, 0800, fa20f000), \
9290 X(_lsrs, 0800, fa30f000), \
9291 X(_mov, 2000, ea4f0000), \
9292 X(_movs, 2000, ea5f0000), \
9293 X(_mul, 4340, fb00f000), \
9294 X(_muls, 4340, ffffffff), /* no 32b muls */ \
9295 X(_mvn, 43c0, ea6f0000), \
9296 X(_mvns, 43c0, ea7f0000), \
9297 X(_neg, 4240, f1c00000), /* rsb #0 */ \
9298 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
9299 X(_orr, 4300, ea400000), \
9300 X(_orrs, 4300, ea500000), \
9301 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9302 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9303 X(_rev, ba00, fa90f080), \
9304 X(_rev16, ba40, fa90f090), \
9305 X(_revsh, bac0, fa90f0b0), \
9306 X(_ror, 41c0, fa60f000), \
9307 X(_rors, 41c0, fa70f000), \
9308 X(_sbc, 4180, eb600000), \
9309 X(_sbcs, 4180, eb700000), \
9310 X(_stmia, c000, e8800000), \
9311 X(_str, 6000, f8400000), \
9312 X(_strb, 7000, f8000000), \
9313 X(_strh, 8000, f8200000), \
9314 X(_str_sp,9000, f84d0000), \
9315 X(_sub, 1e00, eba00000), \
9316 X(_subs, 1e00, ebb00000), \
9317 X(_subi, 8000, f1a00000), \
9318 X(_subis, 8000, f1b00000), \
9319 X(_sxtb, b240, fa4ff080), \
9320 X(_sxth, b200, fa0ff080), \
9321 X(_tst, 4200, ea100f00), \
9322 X(_uxtb, b2c0, fa5ff080), \
9323 X(_uxth, b280, fa1ff080), \
9324 X(_nop, bf00, f3af8000), \
9325 X(_yield, bf10, f3af8001), \
9326 X(_wfe, bf20, f3af8002), \
9327 X(_wfi, bf30, f3af8003), \
9328 X(_sev, bf40, f3af8004),
c19d1205
ZW
9329
9330/* To catch errors in encoding functions, the codes are all offset by
9331 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9332 as 16-bit instructions. */
21d799b5 9333#define X(a,b,c) T_MNEM##a
c19d1205
ZW
9334enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9335#undef X
9336
9337#define X(a,b,c) 0x##b
9338static const unsigned short thumb_op16[] = { T16_32_TAB };
9339#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9340#undef X
9341
9342#define X(a,b,c) 0x##c
9343static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
9344#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9345#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
9346#undef X
9347#undef T16_32_TAB
9348
9349/* Thumb instruction encoders, in alphabetical order. */
9350
92e90b6e 9351/* ADDW or SUBW. */
c921be7d 9352
92e90b6e
PB
9353static void
9354do_t_add_sub_w (void)
9355{
9356 int Rd, Rn;
9357
9358 Rd = inst.operands[0].reg;
9359 Rn = inst.operands[1].reg;
9360
539d4391
NC
9361 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9362 is the SP-{plus,minus}-immediate form of the instruction. */
9363 if (Rn == REG_SP)
9364 constraint (Rd == REG_PC, BAD_PC);
9365 else
9366 reject_bad_reg (Rd);
fdfde340 9367
92e90b6e
PB
9368 inst.instruction |= (Rn << 16) | (Rd << 8);
9369 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9370}
9371
c19d1205
ZW
9372/* Parse an add or subtract instruction. We get here with inst.instruction
9373 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9374
9375static void
9376do_t_add_sub (void)
9377{
9378 int Rd, Rs, Rn;
9379
9380 Rd = inst.operands[0].reg;
9381 Rs = (inst.operands[1].present
9382 ? inst.operands[1].reg /* Rd, Rs, foo */
9383 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9384
e07e6e58
NC
9385 if (Rd == REG_PC)
9386 set_it_insn_type_last ();
9387
c19d1205
ZW
9388 if (unified_syntax)
9389 {
0110f2b8
PB
9390 bfd_boolean flags;
9391 bfd_boolean narrow;
9392 int opcode;
9393
9394 flags = (inst.instruction == T_MNEM_adds
9395 || inst.instruction == T_MNEM_subs);
9396 if (flags)
e07e6e58 9397 narrow = !in_it_block ();
0110f2b8 9398 else
e07e6e58 9399 narrow = in_it_block ();
c19d1205 9400 if (!inst.operands[2].isreg)
b99bd4ef 9401 {
16805f35
PB
9402 int add;
9403
fdfde340
JM
9404 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9405
16805f35
PB
9406 add = (inst.instruction == T_MNEM_add
9407 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
9408 opcode = 0;
9409 if (inst.size_req != 4)
9410 {
0110f2b8
PB
9411 /* Attempt to use a narrow opcode, with relaxation if
9412 appropriate. */
9413 if (Rd == REG_SP && Rs == REG_SP && !flags)
9414 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9415 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9416 opcode = T_MNEM_add_sp;
9417 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9418 opcode = T_MNEM_add_pc;
9419 else if (Rd <= 7 && Rs <= 7 && narrow)
9420 {
9421 if (flags)
9422 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9423 else
9424 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9425 }
9426 if (opcode)
9427 {
9428 inst.instruction = THUMB_OP16(opcode);
9429 inst.instruction |= (Rd << 4) | Rs;
9430 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9431 if (inst.size_req != 2)
9432 inst.relax = opcode;
9433 }
9434 else
9435 constraint (inst.size_req == 2, BAD_HIREG);
9436 }
9437 if (inst.size_req == 4
9438 || (inst.size_req != 2 && !opcode))
9439 {
efd81785
PB
9440 if (Rd == REG_PC)
9441 {
fdfde340 9442 constraint (add, BAD_PC);
efd81785
PB
9443 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9444 _("only SUBS PC, LR, #const allowed"));
9445 constraint (inst.reloc.exp.X_op != O_constant,
9446 _("expression too complex"));
9447 constraint (inst.reloc.exp.X_add_number < 0
9448 || inst.reloc.exp.X_add_number > 0xff,
9449 _("immediate value out of range"));
9450 inst.instruction = T2_SUBS_PC_LR
9451 | inst.reloc.exp.X_add_number;
9452 inst.reloc.type = BFD_RELOC_UNUSED;
9453 return;
9454 }
9455 else if (Rs == REG_PC)
16805f35
PB
9456 {
9457 /* Always use addw/subw. */
9458 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9459 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9460 }
9461 else
9462 {
9463 inst.instruction = THUMB_OP32 (inst.instruction);
9464 inst.instruction = (inst.instruction & 0xe1ffffff)
9465 | 0x10000000;
9466 if (flags)
9467 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9468 else
9469 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9470 }
dc4503c6
PB
9471 inst.instruction |= Rd << 8;
9472 inst.instruction |= Rs << 16;
0110f2b8 9473 }
b99bd4ef 9474 }
c19d1205
ZW
9475 else
9476 {
5f4cb198
NC
9477 unsigned int value = inst.reloc.exp.X_add_number;
9478 unsigned int shift = inst.operands[2].shift_kind;
9479
c19d1205
ZW
9480 Rn = inst.operands[2].reg;
9481 /* See if we can do this with a 16-bit instruction. */
9482 if (!inst.operands[2].shifted && inst.size_req != 4)
9483 {
e27ec89e
PB
9484 if (Rd > 7 || Rs > 7 || Rn > 7)
9485 narrow = FALSE;
9486
9487 if (narrow)
c19d1205 9488 {
e27ec89e
PB
9489 inst.instruction = ((inst.instruction == T_MNEM_adds
9490 || inst.instruction == T_MNEM_add)
c19d1205
ZW
9491 ? T_OPCODE_ADD_R3
9492 : T_OPCODE_SUB_R3);
9493 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9494 return;
9495 }
b99bd4ef 9496
7e806470 9497 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 9498 {
7e806470
PB
9499 /* Thumb-1 cores (except v6-M) require at least one high
9500 register in a narrow non flag setting add. */
9501 if (Rd > 7 || Rn > 7
9502 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9503 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9504 {
7e806470
PB
9505 if (Rd == Rn)
9506 {
9507 Rn = Rs;
9508 Rs = Rd;
9509 }
c19d1205
ZW
9510 inst.instruction = T_OPCODE_ADD_HI;
9511 inst.instruction |= (Rd & 8) << 4;
9512 inst.instruction |= (Rd & 7);
9513 inst.instruction |= Rn << 3;
9514 return;
9515 }
c19d1205
ZW
9516 }
9517 }
c921be7d 9518
fdfde340
JM
9519 constraint (Rd == REG_PC, BAD_PC);
9520 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9521 constraint (Rs == REG_PC, BAD_PC);
9522 reject_bad_reg (Rn);
9523
c19d1205
ZW
9524 /* If we get here, it can't be done in 16 bits. */
9525 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9526 _("shift must be constant"));
9527 inst.instruction = THUMB_OP32 (inst.instruction);
9528 inst.instruction |= Rd << 8;
9529 inst.instruction |= Rs << 16;
5f4cb198
NC
9530 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
9531 _("shift value over 3 not allowed in thumb mode"));
9532 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
9533 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
9534 encode_thumb32_shifted_operand (2);
9535 }
9536 }
9537 else
9538 {
9539 constraint (inst.instruction == T_MNEM_adds
9540 || inst.instruction == T_MNEM_subs,
9541 BAD_THUMB32);
b99bd4ef 9542
c19d1205 9543 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9544 {
c19d1205
ZW
9545 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9546 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9547 BAD_HIREG);
9548
9549 inst.instruction = (inst.instruction == T_MNEM_add
9550 ? 0x0000 : 0x8000);
9551 inst.instruction |= (Rd << 4) | Rs;
9552 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9553 return;
9554 }
9555
c19d1205
ZW
9556 Rn = inst.operands[2].reg;
9557 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9558
c19d1205
ZW
9559 /* We now have Rd, Rs, and Rn set to registers. */
9560 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9561 {
c19d1205
ZW
9562 /* Can't do this for SUB. */
9563 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9564 inst.instruction = T_OPCODE_ADD_HI;
9565 inst.instruction |= (Rd & 8) << 4;
9566 inst.instruction |= (Rd & 7);
9567 if (Rs == Rd)
9568 inst.instruction |= Rn << 3;
9569 else if (Rn == Rd)
9570 inst.instruction |= Rs << 3;
9571 else
9572 constraint (1, _("dest must overlap one source register"));
9573 }
9574 else
9575 {
9576 inst.instruction = (inst.instruction == T_MNEM_add
9577 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9578 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9579 }
b99bd4ef 9580 }
b99bd4ef
NC
9581}
9582
c19d1205
ZW
9583static void
9584do_t_adr (void)
9585{
fdfde340
JM
9586 unsigned Rd;
9587
9588 Rd = inst.operands[0].reg;
9589 reject_bad_reg (Rd);
9590
9591 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9592 {
9593 /* Defer to section relaxation. */
9594 inst.relax = inst.instruction;
9595 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9596 inst.instruction |= Rd << 4;
0110f2b8
PB
9597 }
9598 else if (unified_syntax && inst.size_req != 2)
e9f89963 9599 {
0110f2b8 9600 /* Generate a 32-bit opcode. */
e9f89963 9601 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9602 inst.instruction |= Rd << 8;
e9f89963
PB
9603 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9604 inst.reloc.pc_rel = 1;
9605 }
9606 else
9607 {
0110f2b8 9608 /* Generate a 16-bit opcode. */
e9f89963
PB
9609 inst.instruction = THUMB_OP16 (inst.instruction);
9610 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9611 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9612 inst.reloc.pc_rel = 1;
b99bd4ef 9613
fdfde340 9614 inst.instruction |= Rd << 4;
e9f89963 9615 }
c19d1205 9616}
b99bd4ef 9617
c19d1205
ZW
9618/* Arithmetic instructions for which there is just one 16-bit
9619 instruction encoding, and it allows only two low registers.
9620 For maximal compatibility with ARM syntax, we allow three register
9621 operands even when Thumb-32 instructions are not available, as long
9622 as the first two are identical. For instance, both "sbc r0,r1" and
9623 "sbc r0,r0,r1" are allowed. */
b99bd4ef 9624static void
c19d1205 9625do_t_arit3 (void)
b99bd4ef 9626{
c19d1205 9627 int Rd, Rs, Rn;
b99bd4ef 9628
c19d1205
ZW
9629 Rd = inst.operands[0].reg;
9630 Rs = (inst.operands[1].present
9631 ? inst.operands[1].reg /* Rd, Rs, foo */
9632 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9633 Rn = inst.operands[2].reg;
b99bd4ef 9634
fdfde340
JM
9635 reject_bad_reg (Rd);
9636 reject_bad_reg (Rs);
9637 if (inst.operands[2].isreg)
9638 reject_bad_reg (Rn);
9639
c19d1205 9640 if (unified_syntax)
b99bd4ef 9641 {
c19d1205
ZW
9642 if (!inst.operands[2].isreg)
9643 {
9644 /* For an immediate, we always generate a 32-bit opcode;
9645 section relaxation will shrink it later if possible. */
9646 inst.instruction = THUMB_OP32 (inst.instruction);
9647 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9648 inst.instruction |= Rd << 8;
9649 inst.instruction |= Rs << 16;
9650 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9651 }
9652 else
9653 {
e27ec89e
PB
9654 bfd_boolean narrow;
9655
c19d1205 9656 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9657 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9658 narrow = !in_it_block ();
e27ec89e 9659 else
e07e6e58 9660 narrow = in_it_block ();
e27ec89e
PB
9661
9662 if (Rd > 7 || Rn > 7 || Rs > 7)
9663 narrow = FALSE;
9664 if (inst.operands[2].shifted)
9665 narrow = FALSE;
9666 if (inst.size_req == 4)
9667 narrow = FALSE;
9668
9669 if (narrow
c19d1205
ZW
9670 && Rd == Rs)
9671 {
9672 inst.instruction = THUMB_OP16 (inst.instruction);
9673 inst.instruction |= Rd;
9674 inst.instruction |= Rn << 3;
9675 return;
9676 }
b99bd4ef 9677
c19d1205
ZW
9678 /* If we get here, it can't be done in 16 bits. */
9679 constraint (inst.operands[2].shifted
9680 && inst.operands[2].immisreg,
9681 _("shift must be constant"));
9682 inst.instruction = THUMB_OP32 (inst.instruction);
9683 inst.instruction |= Rd << 8;
9684 inst.instruction |= Rs << 16;
9685 encode_thumb32_shifted_operand (2);
9686 }
a737bd4d 9687 }
c19d1205 9688 else
b99bd4ef 9689 {
c19d1205
ZW
9690 /* On its face this is a lie - the instruction does set the
9691 flags. However, the only supported mnemonic in this mode
9692 says it doesn't. */
9693 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9694
c19d1205
ZW
9695 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9696 _("unshifted register required"));
9697 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9698 constraint (Rd != Rs,
9699 _("dest and source1 must be the same register"));
a737bd4d 9700
c19d1205
ZW
9701 inst.instruction = THUMB_OP16 (inst.instruction);
9702 inst.instruction |= Rd;
9703 inst.instruction |= Rn << 3;
b99bd4ef 9704 }
a737bd4d 9705}
b99bd4ef 9706
c19d1205
ZW
9707/* Similarly, but for instructions where the arithmetic operation is
9708 commutative, so we can allow either of them to be different from
9709 the destination operand in a 16-bit instruction. For instance, all
9710 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9711 accepted. */
9712static void
9713do_t_arit3c (void)
a737bd4d 9714{
c19d1205 9715 int Rd, Rs, Rn;
b99bd4ef 9716
c19d1205
ZW
9717 Rd = inst.operands[0].reg;
9718 Rs = (inst.operands[1].present
9719 ? inst.operands[1].reg /* Rd, Rs, foo */
9720 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9721 Rn = inst.operands[2].reg;
c921be7d 9722
fdfde340
JM
9723 reject_bad_reg (Rd);
9724 reject_bad_reg (Rs);
9725 if (inst.operands[2].isreg)
9726 reject_bad_reg (Rn);
a737bd4d 9727
c19d1205 9728 if (unified_syntax)
a737bd4d 9729 {
c19d1205 9730 if (!inst.operands[2].isreg)
b99bd4ef 9731 {
c19d1205
ZW
9732 /* For an immediate, we always generate a 32-bit opcode;
9733 section relaxation will shrink it later if possible. */
9734 inst.instruction = THUMB_OP32 (inst.instruction);
9735 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9736 inst.instruction |= Rd << 8;
9737 inst.instruction |= Rs << 16;
9738 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9739 }
c19d1205 9740 else
a737bd4d 9741 {
e27ec89e
PB
9742 bfd_boolean narrow;
9743
c19d1205 9744 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9745 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9746 narrow = !in_it_block ();
e27ec89e 9747 else
e07e6e58 9748 narrow = in_it_block ();
e27ec89e
PB
9749
9750 if (Rd > 7 || Rn > 7 || Rs > 7)
9751 narrow = FALSE;
9752 if (inst.operands[2].shifted)
9753 narrow = FALSE;
9754 if (inst.size_req == 4)
9755 narrow = FALSE;
9756
9757 if (narrow)
a737bd4d 9758 {
c19d1205 9759 if (Rd == Rs)
a737bd4d 9760 {
c19d1205
ZW
9761 inst.instruction = THUMB_OP16 (inst.instruction);
9762 inst.instruction |= Rd;
9763 inst.instruction |= Rn << 3;
9764 return;
a737bd4d 9765 }
c19d1205 9766 if (Rd == Rn)
a737bd4d 9767 {
c19d1205
ZW
9768 inst.instruction = THUMB_OP16 (inst.instruction);
9769 inst.instruction |= Rd;
9770 inst.instruction |= Rs << 3;
9771 return;
a737bd4d
NC
9772 }
9773 }
c19d1205
ZW
9774
9775 /* If we get here, it can't be done in 16 bits. */
9776 constraint (inst.operands[2].shifted
9777 && inst.operands[2].immisreg,
9778 _("shift must be constant"));
9779 inst.instruction = THUMB_OP32 (inst.instruction);
9780 inst.instruction |= Rd << 8;
9781 inst.instruction |= Rs << 16;
9782 encode_thumb32_shifted_operand (2);
a737bd4d 9783 }
b99bd4ef 9784 }
c19d1205
ZW
9785 else
9786 {
9787 /* On its face this is a lie - the instruction does set the
9788 flags. However, the only supported mnemonic in this mode
9789 says it doesn't. */
9790 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9791
c19d1205
ZW
9792 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9793 _("unshifted register required"));
9794 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9795
9796 inst.instruction = THUMB_OP16 (inst.instruction);
9797 inst.instruction |= Rd;
9798
9799 if (Rd == Rs)
9800 inst.instruction |= Rn << 3;
9801 else if (Rd == Rn)
9802 inst.instruction |= Rs << 3;
9803 else
9804 constraint (1, _("dest must overlap one source register"));
9805 }
a737bd4d
NC
9806}
9807
62b3e311
PB
9808static void
9809do_t_barrier (void)
9810{
9811 if (inst.operands[0].present)
9812 {
9813 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
9814 && inst.operands[0].imm > 0xf
9815 && inst.operands[0].imm < 0x0,
bd3ba5d1 9816 _("bad barrier type"));
62b3e311
PB
9817 inst.instruction |= inst.operands[0].imm;
9818 }
9819 else
9820 inst.instruction |= 0xf;
9821}
9822
c19d1205
ZW
9823static void
9824do_t_bfc (void)
a737bd4d 9825{
fdfde340 9826 unsigned Rd;
c19d1205
ZW
9827 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9828 constraint (msb > 32, _("bit-field extends past end of register"));
9829 /* The instruction encoding stores the LSB and MSB,
9830 not the LSB and width. */
fdfde340
JM
9831 Rd = inst.operands[0].reg;
9832 reject_bad_reg (Rd);
9833 inst.instruction |= Rd << 8;
c19d1205
ZW
9834 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9835 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9836 inst.instruction |= msb - 1;
b99bd4ef
NC
9837}
9838
c19d1205
ZW
9839static void
9840do_t_bfi (void)
b99bd4ef 9841{
fdfde340 9842 int Rd, Rn;
c19d1205 9843 unsigned int msb;
b99bd4ef 9844
fdfde340
JM
9845 Rd = inst.operands[0].reg;
9846 reject_bad_reg (Rd);
9847
c19d1205
ZW
9848 /* #0 in second position is alternative syntax for bfc, which is
9849 the same instruction but with REG_PC in the Rm field. */
9850 if (!inst.operands[1].isreg)
fdfde340
JM
9851 Rn = REG_PC;
9852 else
9853 {
9854 Rn = inst.operands[1].reg;
9855 reject_bad_reg (Rn);
9856 }
b99bd4ef 9857
c19d1205
ZW
9858 msb = inst.operands[2].imm + inst.operands[3].imm;
9859 constraint (msb > 32, _("bit-field extends past end of register"));
9860 /* The instruction encoding stores the LSB and MSB,
9861 not the LSB and width. */
fdfde340
JM
9862 inst.instruction |= Rd << 8;
9863 inst.instruction |= Rn << 16;
c19d1205
ZW
9864 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9865 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9866 inst.instruction |= msb - 1;
b99bd4ef
NC
9867}
9868
c19d1205
ZW
9869static void
9870do_t_bfx (void)
b99bd4ef 9871{
fdfde340
JM
9872 unsigned Rd, Rn;
9873
9874 Rd = inst.operands[0].reg;
9875 Rn = inst.operands[1].reg;
9876
9877 reject_bad_reg (Rd);
9878 reject_bad_reg (Rn);
9879
c19d1205
ZW
9880 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9881 _("bit-field extends past end of register"));
fdfde340
JM
9882 inst.instruction |= Rd << 8;
9883 inst.instruction |= Rn << 16;
c19d1205
ZW
9884 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9885 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9886 inst.instruction |= inst.operands[3].imm - 1;
9887}
b99bd4ef 9888
c19d1205
ZW
9889/* ARM V5 Thumb BLX (argument parse)
9890 BLX <target_addr> which is BLX(1)
9891 BLX <Rm> which is BLX(2)
9892 Unfortunately, there are two different opcodes for this mnemonic.
9893 So, the insns[].value is not used, and the code here zaps values
9894 into inst.instruction.
b99bd4ef 9895
c19d1205
ZW
9896 ??? How to take advantage of the additional two bits of displacement
9897 available in Thumb32 mode? Need new relocation? */
b99bd4ef 9898
c19d1205
ZW
9899static void
9900do_t_blx (void)
9901{
e07e6e58
NC
9902 set_it_insn_type_last ();
9903
c19d1205 9904 if (inst.operands[0].isreg)
fdfde340
JM
9905 {
9906 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9907 /* We have a register, so this is BLX(2). */
9908 inst.instruction |= inst.operands[0].reg << 3;
9909 }
b99bd4ef
NC
9910 else
9911 {
c19d1205 9912 /* No register. This must be BLX(1). */
2fc8bdac 9913 inst.instruction = 0xf000e800;
0855e32b 9914 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
9915 }
9916}
9917
c19d1205
ZW
9918static void
9919do_t_branch (void)
b99bd4ef 9920{
0110f2b8 9921 int opcode;
dfa9f0d5 9922 int cond;
9ae92b05 9923 int reloc;
dfa9f0d5 9924
e07e6e58
NC
9925 cond = inst.cond;
9926 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9927
9928 if (in_it_block ())
dfa9f0d5
PB
9929 {
9930 /* Conditional branches inside IT blocks are encoded as unconditional
9931 branches. */
9932 cond = COND_ALWAYS;
dfa9f0d5
PB
9933 }
9934 else
9935 cond = inst.cond;
9936
9937 if (cond != COND_ALWAYS)
0110f2b8
PB
9938 opcode = T_MNEM_bcond;
9939 else
9940 opcode = inst.instruction;
9941
12d6b0b7
RS
9942 if (unified_syntax
9943 && (inst.size_req == 4
10960bfb
PB
9944 || (inst.size_req != 2
9945 && (inst.operands[0].hasreloc
9946 || inst.reloc.exp.X_op == O_constant))))
c19d1205 9947 {
0110f2b8 9948 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9949 if (cond == COND_ALWAYS)
9ae92b05 9950 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9951 else
9952 {
9c2799c2 9953 gas_assert (cond != 0xF);
dfa9f0d5 9954 inst.instruction |= cond << 22;
9ae92b05 9955 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
9956 }
9957 }
b99bd4ef
NC
9958 else
9959 {
0110f2b8 9960 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9961 if (cond == COND_ALWAYS)
9ae92b05 9962 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 9963 else
b99bd4ef 9964 {
dfa9f0d5 9965 inst.instruction |= cond << 8;
9ae92b05 9966 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9967 }
0110f2b8
PB
9968 /* Allow section relaxation. */
9969 if (unified_syntax && inst.size_req != 2)
9970 inst.relax = opcode;
b99bd4ef 9971 }
9ae92b05 9972 inst.reloc.type = reloc;
c19d1205 9973 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9974}
9975
9976static void
c19d1205 9977do_t_bkpt (void)
b99bd4ef 9978{
dfa9f0d5
PB
9979 constraint (inst.cond != COND_ALWAYS,
9980 _("instruction is always unconditional"));
c19d1205 9981 if (inst.operands[0].present)
b99bd4ef 9982 {
c19d1205
ZW
9983 constraint (inst.operands[0].imm > 255,
9984 _("immediate value out of range"));
9985 inst.instruction |= inst.operands[0].imm;
e07e6e58 9986 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 9987 }
b99bd4ef
NC
9988}
9989
9990static void
c19d1205 9991do_t_branch23 (void)
b99bd4ef 9992{
e07e6e58 9993 set_it_insn_type_last ();
0855e32b
NS
9994 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
9995
9996 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
9997 this file. We used to simply ignore the PLT reloc type here --
9998 the branch encoding is now needed to deal with TLSCALL relocs.
9999 So if we see a PLT reloc now, put it back to how it used to be to
10000 keep the preexisting behaviour. */
10001 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
10002 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 10003
4343666d 10004#if defined(OBJ_COFF)
c19d1205
ZW
10005 /* If the destination of the branch is a defined symbol which does not have
10006 the THUMB_FUNC attribute, then we must be calling a function which has
10007 the (interfacearm) attribute. We look for the Thumb entry point to that
10008 function and change the branch to refer to that function instead. */
10009 if ( inst.reloc.exp.X_op == O_symbol
10010 && inst.reloc.exp.X_add_symbol != NULL
10011 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10012 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10013 inst.reloc.exp.X_add_symbol =
10014 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 10015#endif
90e4755a
RE
10016}
10017
10018static void
c19d1205 10019do_t_bx (void)
90e4755a 10020{
e07e6e58 10021 set_it_insn_type_last ();
c19d1205
ZW
10022 inst.instruction |= inst.operands[0].reg << 3;
10023 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
10024 should cause the alignment to be checked once it is known. This is
10025 because BX PC only works if the instruction is word aligned. */
10026}
90e4755a 10027
c19d1205
ZW
10028static void
10029do_t_bxj (void)
10030{
fdfde340 10031 int Rm;
90e4755a 10032
e07e6e58 10033 set_it_insn_type_last ();
fdfde340
JM
10034 Rm = inst.operands[0].reg;
10035 reject_bad_reg (Rm);
10036 inst.instruction |= Rm << 16;
90e4755a
RE
10037}
10038
10039static void
c19d1205 10040do_t_clz (void)
90e4755a 10041{
fdfde340
JM
10042 unsigned Rd;
10043 unsigned Rm;
10044
10045 Rd = inst.operands[0].reg;
10046 Rm = inst.operands[1].reg;
10047
10048 reject_bad_reg (Rd);
10049 reject_bad_reg (Rm);
10050
10051 inst.instruction |= Rd << 8;
10052 inst.instruction |= Rm << 16;
10053 inst.instruction |= Rm;
c19d1205 10054}
90e4755a 10055
dfa9f0d5
PB
10056static void
10057do_t_cps (void)
10058{
e07e6e58 10059 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
10060 inst.instruction |= inst.operands[0].imm;
10061}
10062
c19d1205
ZW
10063static void
10064do_t_cpsi (void)
10065{
e07e6e58 10066 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 10067 if (unified_syntax
62b3e311
PB
10068 && (inst.operands[1].present || inst.size_req == 4)
10069 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 10070 {
c19d1205
ZW
10071 unsigned int imod = (inst.instruction & 0x0030) >> 4;
10072 inst.instruction = 0xf3af8000;
10073 inst.instruction |= imod << 9;
10074 inst.instruction |= inst.operands[0].imm << 5;
10075 if (inst.operands[1].present)
10076 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 10077 }
c19d1205 10078 else
90e4755a 10079 {
62b3e311
PB
10080 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
10081 && (inst.operands[0].imm & 4),
10082 _("selected processor does not support 'A' form "
10083 "of this instruction"));
10084 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
10085 _("Thumb does not support the 2-argument "
10086 "form of this instruction"));
10087 inst.instruction |= inst.operands[0].imm;
90e4755a 10088 }
90e4755a
RE
10089}
10090
c19d1205
ZW
10091/* THUMB CPY instruction (argument parse). */
10092
90e4755a 10093static void
c19d1205 10094do_t_cpy (void)
90e4755a 10095{
c19d1205 10096 if (inst.size_req == 4)
90e4755a 10097 {
c19d1205
ZW
10098 inst.instruction = THUMB_OP32 (T_MNEM_mov);
10099 inst.instruction |= inst.operands[0].reg << 8;
10100 inst.instruction |= inst.operands[1].reg;
90e4755a 10101 }
c19d1205 10102 else
90e4755a 10103 {
c19d1205
ZW
10104 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
10105 inst.instruction |= (inst.operands[0].reg & 0x7);
10106 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 10107 }
90e4755a
RE
10108}
10109
90e4755a 10110static void
25fe350b 10111do_t_cbz (void)
90e4755a 10112{
e07e6e58 10113 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
10114 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10115 inst.instruction |= inst.operands[0].reg;
10116 inst.reloc.pc_rel = 1;
10117 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
10118}
90e4755a 10119
62b3e311
PB
10120static void
10121do_t_dbg (void)
10122{
10123 inst.instruction |= inst.operands[0].imm;
10124}
10125
10126static void
10127do_t_div (void)
10128{
fdfde340
JM
10129 unsigned Rd, Rn, Rm;
10130
10131 Rd = inst.operands[0].reg;
10132 Rn = (inst.operands[1].present
10133 ? inst.operands[1].reg : Rd);
10134 Rm = inst.operands[2].reg;
10135
10136 reject_bad_reg (Rd);
10137 reject_bad_reg (Rn);
10138 reject_bad_reg (Rm);
10139
10140 inst.instruction |= Rd << 8;
10141 inst.instruction |= Rn << 16;
10142 inst.instruction |= Rm;
62b3e311
PB
10143}
10144
c19d1205
ZW
10145static void
10146do_t_hint (void)
10147{
10148 if (unified_syntax && inst.size_req == 4)
10149 inst.instruction = THUMB_OP32 (inst.instruction);
10150 else
10151 inst.instruction = THUMB_OP16 (inst.instruction);
10152}
90e4755a 10153
c19d1205
ZW
10154static void
10155do_t_it (void)
10156{
10157 unsigned int cond = inst.operands[0].imm;
e27ec89e 10158
e07e6e58
NC
10159 set_it_insn_type (IT_INSN);
10160 now_it.mask = (inst.instruction & 0xf) | 0x10;
10161 now_it.cc = cond;
e27ec89e
PB
10162
10163 /* If the condition is a negative condition, invert the mask. */
c19d1205 10164 if ((cond & 0x1) == 0x0)
90e4755a 10165 {
c19d1205 10166 unsigned int mask = inst.instruction & 0x000f;
90e4755a 10167
c19d1205
ZW
10168 if ((mask & 0x7) == 0)
10169 /* no conversion needed */;
10170 else if ((mask & 0x3) == 0)
e27ec89e
PB
10171 mask ^= 0x8;
10172 else if ((mask & 0x1) == 0)
10173 mask ^= 0xC;
c19d1205 10174 else
e27ec89e 10175 mask ^= 0xE;
90e4755a 10176
e27ec89e
PB
10177 inst.instruction &= 0xfff0;
10178 inst.instruction |= mask;
c19d1205 10179 }
90e4755a 10180
c19d1205
ZW
10181 inst.instruction |= cond << 4;
10182}
90e4755a 10183
3c707909
PB
10184/* Helper function used for both push/pop and ldm/stm. */
10185static void
10186encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
10187{
10188 bfd_boolean load;
10189
10190 load = (inst.instruction & (1 << 20)) != 0;
10191
10192 if (mask & (1 << 13))
10193 inst.error = _("SP not allowed in register list");
1e5b0379
NC
10194
10195 if ((mask & (1 << base)) != 0
10196 && writeback)
10197 inst.error = _("having the base register in the register list when "
10198 "using write back is UNPREDICTABLE");
10199
3c707909
PB
10200 if (load)
10201 {
e07e6e58
NC
10202 if (mask & (1 << 15))
10203 {
10204 if (mask & (1 << 14))
10205 inst.error = _("LR and PC should not both be in register list");
10206 else
10207 set_it_insn_type_last ();
10208 }
3c707909
PB
10209 }
10210 else
10211 {
10212 if (mask & (1 << 15))
10213 inst.error = _("PC not allowed in register list");
3c707909
PB
10214 }
10215
10216 if ((mask & (mask - 1)) == 0)
10217 {
10218 /* Single register transfers implemented as str/ldr. */
10219 if (writeback)
10220 {
10221 if (inst.instruction & (1 << 23))
10222 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
10223 else
10224 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
10225 }
10226 else
10227 {
10228 if (inst.instruction & (1 << 23))
10229 inst.instruction = 0x00800000; /* ia -> [base] */
10230 else
10231 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
10232 }
10233
10234 inst.instruction |= 0xf8400000;
10235 if (load)
10236 inst.instruction |= 0x00100000;
10237
5f4273c7 10238 mask = ffs (mask) - 1;
3c707909
PB
10239 mask <<= 12;
10240 }
10241 else if (writeback)
10242 inst.instruction |= WRITE_BACK;
10243
10244 inst.instruction |= mask;
10245 inst.instruction |= base << 16;
10246}
10247
c19d1205
ZW
10248static void
10249do_t_ldmstm (void)
10250{
10251 /* This really doesn't seem worth it. */
10252 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10253 _("expression too complex"));
10254 constraint (inst.operands[1].writeback,
10255 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 10256
c19d1205
ZW
10257 if (unified_syntax)
10258 {
3c707909
PB
10259 bfd_boolean narrow;
10260 unsigned mask;
10261
10262 narrow = FALSE;
c19d1205
ZW
10263 /* See if we can use a 16-bit instruction. */
10264 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
10265 && inst.size_req != 4
3c707909 10266 && !(inst.operands[1].imm & ~0xff))
90e4755a 10267 {
3c707909 10268 mask = 1 << inst.operands[0].reg;
90e4755a 10269
eab4f823 10270 if (inst.operands[0].reg <= 7)
90e4755a 10271 {
3c707909 10272 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
10273 ? inst.operands[0].writeback
10274 : (inst.operands[0].writeback
10275 == !(inst.operands[1].imm & mask)))
10276 {
10277 if (inst.instruction == T_MNEM_stmia
10278 && (inst.operands[1].imm & mask)
10279 && (inst.operands[1].imm & (mask - 1)))
10280 as_warn (_("value stored for r%d is UNKNOWN"),
10281 inst.operands[0].reg);
3c707909 10282
eab4f823
MGD
10283 inst.instruction = THUMB_OP16 (inst.instruction);
10284 inst.instruction |= inst.operands[0].reg << 8;
10285 inst.instruction |= inst.operands[1].imm;
10286 narrow = TRUE;
10287 }
10288 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10289 {
10290 /* This means 1 register in reg list one of 3 situations:
10291 1. Instruction is stmia, but without writeback.
10292 2. lmdia without writeback, but with Rn not in
10293 reglist.
10294 3. ldmia with writeback, but with Rn in reglist.
10295 Case 3 is UNPREDICTABLE behaviour, so we handle
10296 case 1 and 2 which can be converted into a 16-bit
10297 str or ldr. The SP cases are handled below. */
10298 unsigned long opcode;
10299 /* First, record an error for Case 3. */
10300 if (inst.operands[1].imm & mask
10301 && inst.operands[0].writeback)
10302 inst.error =
10303 _("having the base register in the register list when "
10304 "using write back is UNPREDICTABLE");
10305
10306 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
10307 : T_MNEM_ldr);
10308 inst.instruction = THUMB_OP16 (opcode);
10309 inst.instruction |= inst.operands[0].reg << 3;
10310 inst.instruction |= (ffs (inst.operands[1].imm)-1);
10311 narrow = TRUE;
10312 }
90e4755a 10313 }
eab4f823 10314 else if (inst.operands[0] .reg == REG_SP)
90e4755a 10315 {
eab4f823
MGD
10316 if (inst.operands[0].writeback)
10317 {
10318 inst.instruction =
10319 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10320 ? T_MNEM_push : T_MNEM_pop);
10321 inst.instruction |= inst.operands[1].imm;
10322 narrow = TRUE;
10323 }
10324 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10325 {
10326 inst.instruction =
10327 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10328 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10329 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10330 narrow = TRUE;
10331 }
90e4755a 10332 }
3c707909
PB
10333 }
10334
10335 if (!narrow)
10336 {
c19d1205
ZW
10337 if (inst.instruction < 0xffff)
10338 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 10339
5f4273c7
NC
10340 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10341 inst.operands[0].writeback);
90e4755a
RE
10342 }
10343 }
c19d1205 10344 else
90e4755a 10345 {
c19d1205
ZW
10346 constraint (inst.operands[0].reg > 7
10347 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
10348 constraint (inst.instruction != T_MNEM_ldmia
10349 && inst.instruction != T_MNEM_stmia,
10350 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 10351 if (inst.instruction == T_MNEM_stmia)
f03698e6 10352 {
c19d1205
ZW
10353 if (!inst.operands[0].writeback)
10354 as_warn (_("this instruction will write back the base register"));
10355 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10356 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 10357 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 10358 inst.operands[0].reg);
f03698e6 10359 }
c19d1205 10360 else
90e4755a 10361 {
c19d1205
ZW
10362 if (!inst.operands[0].writeback
10363 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10364 as_warn (_("this instruction will write back the base register"));
10365 else if (inst.operands[0].writeback
10366 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10367 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
10368 }
10369
c19d1205
ZW
10370 inst.instruction = THUMB_OP16 (inst.instruction);
10371 inst.instruction |= inst.operands[0].reg << 8;
10372 inst.instruction |= inst.operands[1].imm;
10373 }
10374}
e28cd48c 10375
c19d1205
ZW
10376static void
10377do_t_ldrex (void)
10378{
10379 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10380 || inst.operands[1].postind || inst.operands[1].writeback
10381 || inst.operands[1].immisreg || inst.operands[1].shifted
10382 || inst.operands[1].negative,
01cfc07f 10383 BAD_ADDR_MODE);
e28cd48c 10384
5be8be5d
DG
10385 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10386
c19d1205
ZW
10387 inst.instruction |= inst.operands[0].reg << 12;
10388 inst.instruction |= inst.operands[1].reg << 16;
10389 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10390}
e28cd48c 10391
c19d1205
ZW
10392static void
10393do_t_ldrexd (void)
10394{
10395 if (!inst.operands[1].present)
1cac9012 10396 {
c19d1205
ZW
10397 constraint (inst.operands[0].reg == REG_LR,
10398 _("r14 not allowed as first register "
10399 "when second register is omitted"));
10400 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 10401 }
c19d1205
ZW
10402 constraint (inst.operands[0].reg == inst.operands[1].reg,
10403 BAD_OVERLAP);
b99bd4ef 10404
c19d1205
ZW
10405 inst.instruction |= inst.operands[0].reg << 12;
10406 inst.instruction |= inst.operands[1].reg << 8;
10407 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10408}
10409
10410static void
c19d1205 10411do_t_ldst (void)
b99bd4ef 10412{
0110f2b8
PB
10413 unsigned long opcode;
10414 int Rn;
10415
e07e6e58
NC
10416 if (inst.operands[0].isreg
10417 && !inst.operands[0].preind
10418 && inst.operands[0].reg == REG_PC)
10419 set_it_insn_type_last ();
10420
0110f2b8 10421 opcode = inst.instruction;
c19d1205 10422 if (unified_syntax)
b99bd4ef 10423 {
53365c0d
PB
10424 if (!inst.operands[1].isreg)
10425 {
10426 if (opcode <= 0xffff)
10427 inst.instruction = THUMB_OP32 (opcode);
10428 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10429 return;
10430 }
0110f2b8
PB
10431 if (inst.operands[1].isreg
10432 && !inst.operands[1].writeback
c19d1205
ZW
10433 && !inst.operands[1].shifted && !inst.operands[1].postind
10434 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
10435 && opcode <= 0xffff
10436 && inst.size_req != 4)
c19d1205 10437 {
0110f2b8
PB
10438 /* Insn may have a 16-bit form. */
10439 Rn = inst.operands[1].reg;
10440 if (inst.operands[1].immisreg)
10441 {
10442 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 10443 /* [Rn, Rik] */
0110f2b8
PB
10444 if (Rn <= 7 && inst.operands[1].imm <= 7)
10445 goto op16;
5be8be5d
DG
10446 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10447 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
10448 }
10449 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10450 && opcode != T_MNEM_ldrsb)
10451 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10452 || (Rn == REG_SP && opcode == T_MNEM_str))
10453 {
10454 /* [Rn, #const] */
10455 if (Rn > 7)
10456 {
10457 if (Rn == REG_PC)
10458 {
10459 if (inst.reloc.pc_rel)
10460 opcode = T_MNEM_ldr_pc2;
10461 else
10462 opcode = T_MNEM_ldr_pc;
10463 }
10464 else
10465 {
10466 if (opcode == T_MNEM_ldr)
10467 opcode = T_MNEM_ldr_sp;
10468 else
10469 opcode = T_MNEM_str_sp;
10470 }
10471 inst.instruction = inst.operands[0].reg << 8;
10472 }
10473 else
10474 {
10475 inst.instruction = inst.operands[0].reg;
10476 inst.instruction |= inst.operands[1].reg << 3;
10477 }
10478 inst.instruction |= THUMB_OP16 (opcode);
10479 if (inst.size_req == 2)
10480 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10481 else
10482 inst.relax = opcode;
10483 return;
10484 }
c19d1205 10485 }
0110f2b8 10486 /* Definitely a 32-bit variant. */
5be8be5d 10487
8d67f500
NC
10488 /* Warning for Erratum 752419. */
10489 if (opcode == T_MNEM_ldr
10490 && inst.operands[0].reg == REG_SP
10491 && inst.operands[1].writeback == 1
10492 && !inst.operands[1].immisreg)
10493 {
10494 if (no_cpu_selected ()
10495 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
10496 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
10497 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
10498 as_warn (_("This instruction may be unpredictable "
10499 "if executed on M-profile cores "
10500 "with interrupts enabled."));
10501 }
10502
5be8be5d
DG
10503 /* Do some validations regarding addressing modes. */
10504 if (inst.operands[1].immisreg && opcode != T_MNEM_ldr
10505 && opcode != T_MNEM_str)
10506 reject_bad_reg (inst.operands[1].imm);
10507
0110f2b8 10508 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
10509 inst.instruction |= inst.operands[0].reg << 12;
10510 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
10511 return;
10512 }
10513
c19d1205
ZW
10514 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10515
10516 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 10517 {
c19d1205
ZW
10518 /* Only [Rn,Rm] is acceptable. */
10519 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10520 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10521 || inst.operands[1].postind || inst.operands[1].shifted
10522 || inst.operands[1].negative,
10523 _("Thumb does not support this addressing mode"));
10524 inst.instruction = THUMB_OP16 (inst.instruction);
10525 goto op16;
b99bd4ef 10526 }
5f4273c7 10527
c19d1205
ZW
10528 inst.instruction = THUMB_OP16 (inst.instruction);
10529 if (!inst.operands[1].isreg)
10530 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10531 return;
b99bd4ef 10532
c19d1205
ZW
10533 constraint (!inst.operands[1].preind
10534 || inst.operands[1].shifted
10535 || inst.operands[1].writeback,
10536 _("Thumb does not support this addressing mode"));
10537 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 10538 {
c19d1205
ZW
10539 constraint (inst.instruction & 0x0600,
10540 _("byte or halfword not valid for base register"));
10541 constraint (inst.operands[1].reg == REG_PC
10542 && !(inst.instruction & THUMB_LOAD_BIT),
10543 _("r15 based store not allowed"));
10544 constraint (inst.operands[1].immisreg,
10545 _("invalid base register for register offset"));
b99bd4ef 10546
c19d1205
ZW
10547 if (inst.operands[1].reg == REG_PC)
10548 inst.instruction = T_OPCODE_LDR_PC;
10549 else if (inst.instruction & THUMB_LOAD_BIT)
10550 inst.instruction = T_OPCODE_LDR_SP;
10551 else
10552 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 10553
c19d1205
ZW
10554 inst.instruction |= inst.operands[0].reg << 8;
10555 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10556 return;
10557 }
90e4755a 10558
c19d1205
ZW
10559 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10560 if (!inst.operands[1].immisreg)
10561 {
10562 /* Immediate offset. */
10563 inst.instruction |= inst.operands[0].reg;
10564 inst.instruction |= inst.operands[1].reg << 3;
10565 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10566 return;
10567 }
90e4755a 10568
c19d1205
ZW
10569 /* Register offset. */
10570 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10571 constraint (inst.operands[1].negative,
10572 _("Thumb does not support this addressing mode"));
90e4755a 10573
c19d1205
ZW
10574 op16:
10575 switch (inst.instruction)
10576 {
10577 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10578 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10579 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10580 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10581 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10582 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10583 case 0x5600 /* ldrsb */:
10584 case 0x5e00 /* ldrsh */: break;
10585 default: abort ();
10586 }
90e4755a 10587
c19d1205
ZW
10588 inst.instruction |= inst.operands[0].reg;
10589 inst.instruction |= inst.operands[1].reg << 3;
10590 inst.instruction |= inst.operands[1].imm << 6;
10591}
90e4755a 10592
c19d1205
ZW
10593static void
10594do_t_ldstd (void)
10595{
10596 if (!inst.operands[1].present)
b99bd4ef 10597 {
c19d1205
ZW
10598 inst.operands[1].reg = inst.operands[0].reg + 1;
10599 constraint (inst.operands[0].reg == REG_LR,
10600 _("r14 not allowed here"));
b99bd4ef 10601 }
c19d1205
ZW
10602 inst.instruction |= inst.operands[0].reg << 12;
10603 inst.instruction |= inst.operands[1].reg << 8;
10604 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
10605}
10606
c19d1205
ZW
10607static void
10608do_t_ldstt (void)
10609{
10610 inst.instruction |= inst.operands[0].reg << 12;
10611 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10612}
a737bd4d 10613
b99bd4ef 10614static void
c19d1205 10615do_t_mla (void)
b99bd4ef 10616{
fdfde340 10617 unsigned Rd, Rn, Rm, Ra;
c921be7d 10618
fdfde340
JM
10619 Rd = inst.operands[0].reg;
10620 Rn = inst.operands[1].reg;
10621 Rm = inst.operands[2].reg;
10622 Ra = inst.operands[3].reg;
10623
10624 reject_bad_reg (Rd);
10625 reject_bad_reg (Rn);
10626 reject_bad_reg (Rm);
10627 reject_bad_reg (Ra);
10628
10629 inst.instruction |= Rd << 8;
10630 inst.instruction |= Rn << 16;
10631 inst.instruction |= Rm;
10632 inst.instruction |= Ra << 12;
c19d1205 10633}
b99bd4ef 10634
c19d1205
ZW
10635static void
10636do_t_mlal (void)
10637{
fdfde340
JM
10638 unsigned RdLo, RdHi, Rn, Rm;
10639
10640 RdLo = inst.operands[0].reg;
10641 RdHi = inst.operands[1].reg;
10642 Rn = inst.operands[2].reg;
10643 Rm = inst.operands[3].reg;
10644
10645 reject_bad_reg (RdLo);
10646 reject_bad_reg (RdHi);
10647 reject_bad_reg (Rn);
10648 reject_bad_reg (Rm);
10649
10650 inst.instruction |= RdLo << 12;
10651 inst.instruction |= RdHi << 8;
10652 inst.instruction |= Rn << 16;
10653 inst.instruction |= Rm;
c19d1205 10654}
b99bd4ef 10655
c19d1205
ZW
10656static void
10657do_t_mov_cmp (void)
10658{
fdfde340
JM
10659 unsigned Rn, Rm;
10660
10661 Rn = inst.operands[0].reg;
10662 Rm = inst.operands[1].reg;
10663
e07e6e58
NC
10664 if (Rn == REG_PC)
10665 set_it_insn_type_last ();
10666
c19d1205 10667 if (unified_syntax)
b99bd4ef 10668 {
c19d1205
ZW
10669 int r0off = (inst.instruction == T_MNEM_mov
10670 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 10671 unsigned long opcode;
3d388997
PB
10672 bfd_boolean narrow;
10673 bfd_boolean low_regs;
10674
fdfde340 10675 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 10676 opcode = inst.instruction;
e07e6e58 10677 if (in_it_block ())
0110f2b8 10678 narrow = opcode != T_MNEM_movs;
3d388997 10679 else
0110f2b8 10680 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
10681 if (inst.size_req == 4
10682 || inst.operands[1].shifted)
10683 narrow = FALSE;
10684
efd81785
PB
10685 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10686 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10687 && !inst.operands[1].shifted
fdfde340
JM
10688 && Rn == REG_PC
10689 && Rm == REG_LR)
efd81785
PB
10690 {
10691 inst.instruction = T2_SUBS_PC_LR;
10692 return;
10693 }
10694
fdfde340
JM
10695 if (opcode == T_MNEM_cmp)
10696 {
10697 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
10698 if (narrow)
10699 {
10700 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10701 but valid. */
10702 warn_deprecated_sp (Rm);
10703 /* R15 was documented as a valid choice for Rm in ARMv6,
10704 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10705 tools reject R15, so we do too. */
10706 constraint (Rm == REG_PC, BAD_PC);
10707 }
10708 else
10709 reject_bad_reg (Rm);
fdfde340
JM
10710 }
10711 else if (opcode == T_MNEM_mov
10712 || opcode == T_MNEM_movs)
10713 {
10714 if (inst.operands[1].isreg)
10715 {
10716 if (opcode == T_MNEM_movs)
10717 {
10718 reject_bad_reg (Rn);
10719 reject_bad_reg (Rm);
10720 }
76fa04a4
MGD
10721 else if (narrow)
10722 {
10723 /* This is mov.n. */
10724 if ((Rn == REG_SP || Rn == REG_PC)
10725 && (Rm == REG_SP || Rm == REG_PC))
10726 {
10727 as_warn (_("Use of r%u as a source register is "
10728 "deprecated when r%u is the destination "
10729 "register."), Rm, Rn);
10730 }
10731 }
10732 else
10733 {
10734 /* This is mov.w. */
10735 constraint (Rn == REG_PC, BAD_PC);
10736 constraint (Rm == REG_PC, BAD_PC);
10737 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
10738 }
fdfde340
JM
10739 }
10740 else
10741 reject_bad_reg (Rn);
10742 }
10743
c19d1205
ZW
10744 if (!inst.operands[1].isreg)
10745 {
0110f2b8 10746 /* Immediate operand. */
e07e6e58 10747 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
10748 narrow = 0;
10749 if (low_regs && narrow)
10750 {
10751 inst.instruction = THUMB_OP16 (opcode);
fdfde340 10752 inst.instruction |= Rn << 8;
0110f2b8
PB
10753 if (inst.size_req == 2)
10754 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10755 else
10756 inst.relax = opcode;
10757 }
10758 else
10759 {
10760 inst.instruction = THUMB_OP32 (inst.instruction);
10761 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10762 inst.instruction |= Rn << r0off;
0110f2b8
PB
10763 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10764 }
c19d1205 10765 }
728ca7c9
PB
10766 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10767 && (inst.instruction == T_MNEM_mov
10768 || inst.instruction == T_MNEM_movs))
10769 {
10770 /* Register shifts are encoded as separate shift instructions. */
10771 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10772
e07e6e58 10773 if (in_it_block ())
728ca7c9
PB
10774 narrow = !flags;
10775 else
10776 narrow = flags;
10777
10778 if (inst.size_req == 4)
10779 narrow = FALSE;
10780
10781 if (!low_regs || inst.operands[1].imm > 7)
10782 narrow = FALSE;
10783
fdfde340 10784 if (Rn != Rm)
728ca7c9
PB
10785 narrow = FALSE;
10786
10787 switch (inst.operands[1].shift_kind)
10788 {
10789 case SHIFT_LSL:
10790 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10791 break;
10792 case SHIFT_ASR:
10793 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10794 break;
10795 case SHIFT_LSR:
10796 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10797 break;
10798 case SHIFT_ROR:
10799 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10800 break;
10801 default:
5f4273c7 10802 abort ();
728ca7c9
PB
10803 }
10804
10805 inst.instruction = opcode;
10806 if (narrow)
10807 {
fdfde340 10808 inst.instruction |= Rn;
728ca7c9
PB
10809 inst.instruction |= inst.operands[1].imm << 3;
10810 }
10811 else
10812 {
10813 if (flags)
10814 inst.instruction |= CONDS_BIT;
10815
fdfde340
JM
10816 inst.instruction |= Rn << 8;
10817 inst.instruction |= Rm << 16;
728ca7c9
PB
10818 inst.instruction |= inst.operands[1].imm;
10819 }
10820 }
3d388997 10821 else if (!narrow)
c19d1205 10822 {
728ca7c9
PB
10823 /* Some mov with immediate shift have narrow variants.
10824 Register shifts are handled above. */
10825 if (low_regs && inst.operands[1].shifted
10826 && (inst.instruction == T_MNEM_mov
10827 || inst.instruction == T_MNEM_movs))
10828 {
e07e6e58 10829 if (in_it_block ())
728ca7c9
PB
10830 narrow = (inst.instruction == T_MNEM_mov);
10831 else
10832 narrow = (inst.instruction == T_MNEM_movs);
10833 }
10834
10835 if (narrow)
10836 {
10837 switch (inst.operands[1].shift_kind)
10838 {
10839 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10840 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10841 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10842 default: narrow = FALSE; break;
10843 }
10844 }
10845
10846 if (narrow)
10847 {
fdfde340
JM
10848 inst.instruction |= Rn;
10849 inst.instruction |= Rm << 3;
728ca7c9
PB
10850 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10851 }
10852 else
10853 {
10854 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10855 inst.instruction |= Rn << r0off;
728ca7c9
PB
10856 encode_thumb32_shifted_operand (1);
10857 }
c19d1205
ZW
10858 }
10859 else
10860 switch (inst.instruction)
10861 {
10862 case T_MNEM_mov:
10863 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
10864 inst.instruction |= (Rn & 0x8) << 4;
10865 inst.instruction |= (Rn & 0x7);
10866 inst.instruction |= Rm << 3;
c19d1205 10867 break;
b99bd4ef 10868
c19d1205
ZW
10869 case T_MNEM_movs:
10870 /* We know we have low registers at this point.
941a8a52
MGD
10871 Generate LSLS Rd, Rs, #0. */
10872 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
10873 inst.instruction |= Rn;
10874 inst.instruction |= Rm << 3;
c19d1205
ZW
10875 break;
10876
10877 case T_MNEM_cmp:
3d388997 10878 if (low_regs)
c19d1205
ZW
10879 {
10880 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
10881 inst.instruction |= Rn;
10882 inst.instruction |= Rm << 3;
c19d1205
ZW
10883 }
10884 else
10885 {
10886 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
10887 inst.instruction |= (Rn & 0x8) << 4;
10888 inst.instruction |= (Rn & 0x7);
10889 inst.instruction |= Rm << 3;
c19d1205
ZW
10890 }
10891 break;
10892 }
b99bd4ef
NC
10893 return;
10894 }
10895
c19d1205 10896 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
10897
10898 /* PR 10443: Do not silently ignore shifted operands. */
10899 constraint (inst.operands[1].shifted,
10900 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10901
c19d1205 10902 if (inst.operands[1].isreg)
b99bd4ef 10903 {
fdfde340 10904 if (Rn < 8 && Rm < 8)
b99bd4ef 10905 {
c19d1205
ZW
10906 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10907 since a MOV instruction produces unpredictable results. */
10908 if (inst.instruction == T_OPCODE_MOV_I8)
10909 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 10910 else
c19d1205 10911 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 10912
fdfde340
JM
10913 inst.instruction |= Rn;
10914 inst.instruction |= Rm << 3;
b99bd4ef
NC
10915 }
10916 else
10917 {
c19d1205
ZW
10918 if (inst.instruction == T_OPCODE_MOV_I8)
10919 inst.instruction = T_OPCODE_MOV_HR;
10920 else
10921 inst.instruction = T_OPCODE_CMP_HR;
10922 do_t_cpy ();
b99bd4ef
NC
10923 }
10924 }
c19d1205 10925 else
b99bd4ef 10926 {
fdfde340 10927 constraint (Rn > 7,
c19d1205 10928 _("only lo regs allowed with immediate"));
fdfde340 10929 inst.instruction |= Rn << 8;
c19d1205
ZW
10930 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10931 }
10932}
b99bd4ef 10933
c19d1205
ZW
10934static void
10935do_t_mov16 (void)
10936{
fdfde340 10937 unsigned Rd;
b6895b4f
PB
10938 bfd_vma imm;
10939 bfd_boolean top;
10940
10941 top = (inst.instruction & 0x00800000) != 0;
10942 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10943 {
10944 constraint (top, _(":lower16: not allowed this instruction"));
10945 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10946 }
10947 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10948 {
10949 constraint (!top, _(":upper16: not allowed this instruction"));
10950 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10951 }
10952
fdfde340
JM
10953 Rd = inst.operands[0].reg;
10954 reject_bad_reg (Rd);
10955
10956 inst.instruction |= Rd << 8;
b6895b4f
PB
10957 if (inst.reloc.type == BFD_RELOC_UNUSED)
10958 {
10959 imm = inst.reloc.exp.X_add_number;
10960 inst.instruction |= (imm & 0xf000) << 4;
10961 inst.instruction |= (imm & 0x0800) << 15;
10962 inst.instruction |= (imm & 0x0700) << 4;
10963 inst.instruction |= (imm & 0x00ff);
10964 }
c19d1205 10965}
b99bd4ef 10966
c19d1205
ZW
10967static void
10968do_t_mvn_tst (void)
10969{
fdfde340 10970 unsigned Rn, Rm;
c921be7d 10971
fdfde340
JM
10972 Rn = inst.operands[0].reg;
10973 Rm = inst.operands[1].reg;
10974
10975 if (inst.instruction == T_MNEM_cmp
10976 || inst.instruction == T_MNEM_cmn)
10977 constraint (Rn == REG_PC, BAD_PC);
10978 else
10979 reject_bad_reg (Rn);
10980 reject_bad_reg (Rm);
10981
c19d1205
ZW
10982 if (unified_syntax)
10983 {
10984 int r0off = (inst.instruction == T_MNEM_mvn
10985 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
10986 bfd_boolean narrow;
10987
10988 if (inst.size_req == 4
10989 || inst.instruction > 0xffff
10990 || inst.operands[1].shifted
fdfde340 10991 || Rn > 7 || Rm > 7)
3d388997
PB
10992 narrow = FALSE;
10993 else if (inst.instruction == T_MNEM_cmn)
10994 narrow = TRUE;
10995 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10996 narrow = !in_it_block ();
3d388997 10997 else
e07e6e58 10998 narrow = in_it_block ();
3d388997 10999
c19d1205 11000 if (!inst.operands[1].isreg)
b99bd4ef 11001 {
c19d1205
ZW
11002 /* For an immediate, we always generate a 32-bit opcode;
11003 section relaxation will shrink it later if possible. */
11004 if (inst.instruction < 0xffff)
11005 inst.instruction = THUMB_OP32 (inst.instruction);
11006 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11007 inst.instruction |= Rn << r0off;
c19d1205 11008 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11009 }
c19d1205 11010 else
b99bd4ef 11011 {
c19d1205 11012 /* See if we can do this with a 16-bit instruction. */
3d388997 11013 if (narrow)
b99bd4ef 11014 {
c19d1205 11015 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11016 inst.instruction |= Rn;
11017 inst.instruction |= Rm << 3;
b99bd4ef 11018 }
c19d1205 11019 else
b99bd4ef 11020 {
c19d1205
ZW
11021 constraint (inst.operands[1].shifted
11022 && inst.operands[1].immisreg,
11023 _("shift must be constant"));
11024 if (inst.instruction < 0xffff)
11025 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11026 inst.instruction |= Rn << r0off;
c19d1205 11027 encode_thumb32_shifted_operand (1);
b99bd4ef 11028 }
b99bd4ef
NC
11029 }
11030 }
11031 else
11032 {
c19d1205
ZW
11033 constraint (inst.instruction > 0xffff
11034 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
11035 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
11036 _("unshifted register required"));
fdfde340 11037 constraint (Rn > 7 || Rm > 7,
c19d1205 11038 BAD_HIREG);
b99bd4ef 11039
c19d1205 11040 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11041 inst.instruction |= Rn;
11042 inst.instruction |= Rm << 3;
b99bd4ef 11043 }
b99bd4ef
NC
11044}
11045
b05fe5cf 11046static void
c19d1205 11047do_t_mrs (void)
b05fe5cf 11048{
fdfde340 11049 unsigned Rd;
037e8744
JB
11050
11051 if (do_vfp_nsyn_mrs () == SUCCESS)
11052 return;
11053
90ec0d68
MGD
11054 Rd = inst.operands[0].reg;
11055 reject_bad_reg (Rd);
11056 inst.instruction |= Rd << 8;
11057
11058 if (inst.operands[1].isreg)
62b3e311 11059 {
90ec0d68
MGD
11060 unsigned br = inst.operands[1].reg;
11061 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
11062 as_bad (_("bad register for mrs"));
11063
11064 inst.instruction |= br & (0xf << 16);
11065 inst.instruction |= (br & 0x300) >> 4;
11066 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
11067 }
11068 else
11069 {
90ec0d68 11070 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 11071
d2cd1205
JB
11072 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
11073 constraint (flags != 0, _("selected processor does not support "
11074 "requested special purpose register"));
90ec0d68 11075 else
d2cd1205
JB
11076 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
11077 devices). */
11078 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
11079 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 11080
90ec0d68
MGD
11081 inst.instruction |= (flags & SPSR_BIT) >> 2;
11082 inst.instruction |= inst.operands[1].imm & 0xff;
11083 inst.instruction |= 0xf0000;
11084 }
c19d1205 11085}
b05fe5cf 11086
c19d1205
ZW
11087static void
11088do_t_msr (void)
11089{
62b3e311 11090 int flags;
fdfde340 11091 unsigned Rn;
62b3e311 11092
037e8744
JB
11093 if (do_vfp_nsyn_msr () == SUCCESS)
11094 return;
11095
c19d1205
ZW
11096 constraint (!inst.operands[1].isreg,
11097 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
11098
11099 if (inst.operands[0].isreg)
11100 flags = (int)(inst.operands[0].reg);
11101 else
11102 flags = inst.operands[0].imm;
11103
d2cd1205 11104 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 11105 {
d2cd1205
JB
11106 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11107
11108 constraint ((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11109 && (bits & ~(PSR_s | PSR_f)) != 0)
11110 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11111 && bits != PSR_f),
11112 _("selected processor does not support requested special "
11113 "purpose register"));
62b3e311
PB
11114 }
11115 else
d2cd1205
JB
11116 constraint ((flags & 0xff) != 0, _("selected processor does not support "
11117 "requested special purpose register"));
c921be7d 11118
fdfde340
JM
11119 Rn = inst.operands[1].reg;
11120 reject_bad_reg (Rn);
11121
62b3e311 11122 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
11123 inst.instruction |= (flags & 0xf0000) >> 8;
11124 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 11125 inst.instruction |= (flags & 0xff);
fdfde340 11126 inst.instruction |= Rn << 16;
c19d1205 11127}
b05fe5cf 11128
c19d1205
ZW
11129static void
11130do_t_mul (void)
11131{
17828f45 11132 bfd_boolean narrow;
fdfde340 11133 unsigned Rd, Rn, Rm;
17828f45 11134
c19d1205
ZW
11135 if (!inst.operands[2].present)
11136 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 11137
fdfde340
JM
11138 Rd = inst.operands[0].reg;
11139 Rn = inst.operands[1].reg;
11140 Rm = inst.operands[2].reg;
11141
17828f45 11142 if (unified_syntax)
b05fe5cf 11143 {
17828f45 11144 if (inst.size_req == 4
fdfde340
JM
11145 || (Rd != Rn
11146 && Rd != Rm)
11147 || Rn > 7
11148 || Rm > 7)
17828f45
JM
11149 narrow = FALSE;
11150 else if (inst.instruction == T_MNEM_muls)
e07e6e58 11151 narrow = !in_it_block ();
17828f45 11152 else
e07e6e58 11153 narrow = in_it_block ();
b05fe5cf 11154 }
c19d1205 11155 else
b05fe5cf 11156 {
17828f45 11157 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 11158 constraint (Rn > 7 || Rm > 7,
c19d1205 11159 BAD_HIREG);
17828f45
JM
11160 narrow = TRUE;
11161 }
b05fe5cf 11162
17828f45
JM
11163 if (narrow)
11164 {
11165 /* 16-bit MULS/Conditional MUL. */
c19d1205 11166 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11167 inst.instruction |= Rd;
b05fe5cf 11168
fdfde340
JM
11169 if (Rd == Rn)
11170 inst.instruction |= Rm << 3;
11171 else if (Rd == Rm)
11172 inst.instruction |= Rn << 3;
c19d1205
ZW
11173 else
11174 constraint (1, _("dest must overlap one source register"));
11175 }
17828f45
JM
11176 else
11177 {
e07e6e58
NC
11178 constraint (inst.instruction != T_MNEM_mul,
11179 _("Thumb-2 MUL must not set flags"));
17828f45
JM
11180 /* 32-bit MUL. */
11181 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11182 inst.instruction |= Rd << 8;
11183 inst.instruction |= Rn << 16;
11184 inst.instruction |= Rm << 0;
11185
11186 reject_bad_reg (Rd);
11187 reject_bad_reg (Rn);
11188 reject_bad_reg (Rm);
17828f45 11189 }
c19d1205 11190}
b05fe5cf 11191
c19d1205
ZW
11192static void
11193do_t_mull (void)
11194{
fdfde340 11195 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 11196
fdfde340
JM
11197 RdLo = inst.operands[0].reg;
11198 RdHi = inst.operands[1].reg;
11199 Rn = inst.operands[2].reg;
11200 Rm = inst.operands[3].reg;
11201
11202 reject_bad_reg (RdLo);
11203 reject_bad_reg (RdHi);
11204 reject_bad_reg (Rn);
11205 reject_bad_reg (Rm);
11206
11207 inst.instruction |= RdLo << 12;
11208 inst.instruction |= RdHi << 8;
11209 inst.instruction |= Rn << 16;
11210 inst.instruction |= Rm;
11211
11212 if (RdLo == RdHi)
c19d1205
ZW
11213 as_tsktsk (_("rdhi and rdlo must be different"));
11214}
b05fe5cf 11215
c19d1205
ZW
11216static void
11217do_t_nop (void)
11218{
e07e6e58
NC
11219 set_it_insn_type (NEUTRAL_IT_INSN);
11220
c19d1205
ZW
11221 if (unified_syntax)
11222 {
11223 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 11224 {
c19d1205
ZW
11225 inst.instruction = THUMB_OP32 (inst.instruction);
11226 inst.instruction |= inst.operands[0].imm;
11227 }
11228 else
11229 {
bc2d1808
NC
11230 /* PR9722: Check for Thumb2 availability before
11231 generating a thumb2 nop instruction. */
afa62d5e 11232 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
11233 {
11234 inst.instruction = THUMB_OP16 (inst.instruction);
11235 inst.instruction |= inst.operands[0].imm << 4;
11236 }
11237 else
11238 inst.instruction = 0x46c0;
c19d1205
ZW
11239 }
11240 }
11241 else
11242 {
11243 constraint (inst.operands[0].present,
11244 _("Thumb does not support NOP with hints"));
11245 inst.instruction = 0x46c0;
11246 }
11247}
b05fe5cf 11248
c19d1205
ZW
11249static void
11250do_t_neg (void)
11251{
11252 if (unified_syntax)
11253 {
3d388997
PB
11254 bfd_boolean narrow;
11255
11256 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11257 narrow = !in_it_block ();
3d388997 11258 else
e07e6e58 11259 narrow = in_it_block ();
3d388997
PB
11260 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11261 narrow = FALSE;
11262 if (inst.size_req == 4)
11263 narrow = FALSE;
11264
11265 if (!narrow)
c19d1205
ZW
11266 {
11267 inst.instruction = THUMB_OP32 (inst.instruction);
11268 inst.instruction |= inst.operands[0].reg << 8;
11269 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
11270 }
11271 else
11272 {
c19d1205
ZW
11273 inst.instruction = THUMB_OP16 (inst.instruction);
11274 inst.instruction |= inst.operands[0].reg;
11275 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
11276 }
11277 }
11278 else
11279 {
c19d1205
ZW
11280 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
11281 BAD_HIREG);
11282 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11283
11284 inst.instruction = THUMB_OP16 (inst.instruction);
11285 inst.instruction |= inst.operands[0].reg;
11286 inst.instruction |= inst.operands[1].reg << 3;
11287 }
11288}
11289
1c444d06
JM
11290static void
11291do_t_orn (void)
11292{
11293 unsigned Rd, Rn;
11294
11295 Rd = inst.operands[0].reg;
11296 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
11297
fdfde340
JM
11298 reject_bad_reg (Rd);
11299 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
11300 reject_bad_reg (Rn);
11301
1c444d06
JM
11302 inst.instruction |= Rd << 8;
11303 inst.instruction |= Rn << 16;
11304
11305 if (!inst.operands[2].isreg)
11306 {
11307 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11308 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11309 }
11310 else
11311 {
11312 unsigned Rm;
11313
11314 Rm = inst.operands[2].reg;
fdfde340 11315 reject_bad_reg (Rm);
1c444d06
JM
11316
11317 constraint (inst.operands[2].shifted
11318 && inst.operands[2].immisreg,
11319 _("shift must be constant"));
11320 encode_thumb32_shifted_operand (2);
11321 }
11322}
11323
c19d1205
ZW
11324static void
11325do_t_pkhbt (void)
11326{
fdfde340
JM
11327 unsigned Rd, Rn, Rm;
11328
11329 Rd = inst.operands[0].reg;
11330 Rn = inst.operands[1].reg;
11331 Rm = inst.operands[2].reg;
11332
11333 reject_bad_reg (Rd);
11334 reject_bad_reg (Rn);
11335 reject_bad_reg (Rm);
11336
11337 inst.instruction |= Rd << 8;
11338 inst.instruction |= Rn << 16;
11339 inst.instruction |= Rm;
c19d1205
ZW
11340 if (inst.operands[3].present)
11341 {
11342 unsigned int val = inst.reloc.exp.X_add_number;
11343 constraint (inst.reloc.exp.X_op != O_constant,
11344 _("expression too complex"));
11345 inst.instruction |= (val & 0x1c) << 10;
11346 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 11347 }
c19d1205 11348}
b05fe5cf 11349
c19d1205
ZW
11350static void
11351do_t_pkhtb (void)
11352{
11353 if (!inst.operands[3].present)
1ef52f49
NC
11354 {
11355 unsigned Rtmp;
11356
11357 inst.instruction &= ~0x00000020;
11358
11359 /* PR 10168. Swap the Rm and Rn registers. */
11360 Rtmp = inst.operands[1].reg;
11361 inst.operands[1].reg = inst.operands[2].reg;
11362 inst.operands[2].reg = Rtmp;
11363 }
c19d1205 11364 do_t_pkhbt ();
b05fe5cf
ZW
11365}
11366
c19d1205
ZW
11367static void
11368do_t_pld (void)
11369{
fdfde340
JM
11370 if (inst.operands[0].immisreg)
11371 reject_bad_reg (inst.operands[0].imm);
11372
c19d1205
ZW
11373 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11374}
b05fe5cf 11375
c19d1205
ZW
11376static void
11377do_t_push_pop (void)
b99bd4ef 11378{
e9f89963 11379 unsigned mask;
5f4273c7 11380
c19d1205
ZW
11381 constraint (inst.operands[0].writeback,
11382 _("push/pop do not support {reglist}^"));
11383 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11384 _("expression too complex"));
b99bd4ef 11385
e9f89963
PB
11386 mask = inst.operands[0].imm;
11387 if ((mask & ~0xff) == 0)
3c707909 11388 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 11389 else if ((inst.instruction == T_MNEM_push
e9f89963 11390 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 11391 || (inst.instruction == T_MNEM_pop
e9f89963 11392 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 11393 {
c19d1205
ZW
11394 inst.instruction = THUMB_OP16 (inst.instruction);
11395 inst.instruction |= THUMB_PP_PC_LR;
3c707909 11396 inst.instruction |= mask & 0xff;
c19d1205
ZW
11397 }
11398 else if (unified_syntax)
11399 {
3c707909 11400 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 11401 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
11402 }
11403 else
11404 {
11405 inst.error = _("invalid register list to push/pop instruction");
11406 return;
11407 }
c19d1205 11408}
b99bd4ef 11409
c19d1205
ZW
11410static void
11411do_t_rbit (void)
11412{
fdfde340
JM
11413 unsigned Rd, Rm;
11414
11415 Rd = inst.operands[0].reg;
11416 Rm = inst.operands[1].reg;
11417
11418 reject_bad_reg (Rd);
11419 reject_bad_reg (Rm);
11420
11421 inst.instruction |= Rd << 8;
11422 inst.instruction |= Rm << 16;
11423 inst.instruction |= Rm;
c19d1205 11424}
b99bd4ef 11425
c19d1205
ZW
11426static void
11427do_t_rev (void)
11428{
fdfde340
JM
11429 unsigned Rd, Rm;
11430
11431 Rd = inst.operands[0].reg;
11432 Rm = inst.operands[1].reg;
11433
11434 reject_bad_reg (Rd);
11435 reject_bad_reg (Rm);
11436
11437 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
11438 && inst.size_req != 4)
11439 {
11440 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11441 inst.instruction |= Rd;
11442 inst.instruction |= Rm << 3;
c19d1205
ZW
11443 }
11444 else if (unified_syntax)
11445 {
11446 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11447 inst.instruction |= Rd << 8;
11448 inst.instruction |= Rm << 16;
11449 inst.instruction |= Rm;
c19d1205
ZW
11450 }
11451 else
11452 inst.error = BAD_HIREG;
11453}
b99bd4ef 11454
1c444d06
JM
11455static void
11456do_t_rrx (void)
11457{
11458 unsigned Rd, Rm;
11459
11460 Rd = inst.operands[0].reg;
11461 Rm = inst.operands[1].reg;
11462
fdfde340
JM
11463 reject_bad_reg (Rd);
11464 reject_bad_reg (Rm);
c921be7d 11465
1c444d06
JM
11466 inst.instruction |= Rd << 8;
11467 inst.instruction |= Rm;
11468}
11469
c19d1205
ZW
11470static void
11471do_t_rsb (void)
11472{
fdfde340 11473 unsigned Rd, Rs;
b99bd4ef 11474
c19d1205
ZW
11475 Rd = inst.operands[0].reg;
11476 Rs = (inst.operands[1].present
11477 ? inst.operands[1].reg /* Rd, Rs, foo */
11478 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 11479
fdfde340
JM
11480 reject_bad_reg (Rd);
11481 reject_bad_reg (Rs);
11482 if (inst.operands[2].isreg)
11483 reject_bad_reg (inst.operands[2].reg);
11484
c19d1205
ZW
11485 inst.instruction |= Rd << 8;
11486 inst.instruction |= Rs << 16;
11487 if (!inst.operands[2].isreg)
11488 {
026d3abb
PB
11489 bfd_boolean narrow;
11490
11491 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 11492 narrow = !in_it_block ();
026d3abb 11493 else
e07e6e58 11494 narrow = in_it_block ();
026d3abb
PB
11495
11496 if (Rd > 7 || Rs > 7)
11497 narrow = FALSE;
11498
11499 if (inst.size_req == 4 || !unified_syntax)
11500 narrow = FALSE;
11501
11502 if (inst.reloc.exp.X_op != O_constant
11503 || inst.reloc.exp.X_add_number != 0)
11504 narrow = FALSE;
11505
11506 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11507 relaxation, but it doesn't seem worth the hassle. */
11508 if (narrow)
11509 {
11510 inst.reloc.type = BFD_RELOC_UNUSED;
11511 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11512 inst.instruction |= Rs << 3;
11513 inst.instruction |= Rd;
11514 }
11515 else
11516 {
11517 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11518 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11519 }
c19d1205
ZW
11520 }
11521 else
11522 encode_thumb32_shifted_operand (2);
11523}
b99bd4ef 11524
c19d1205
ZW
11525static void
11526do_t_setend (void)
11527{
e07e6e58 11528 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11529 if (inst.operands[0].imm)
11530 inst.instruction |= 0x8;
11531}
b99bd4ef 11532
c19d1205
ZW
11533static void
11534do_t_shift (void)
11535{
11536 if (!inst.operands[1].present)
11537 inst.operands[1].reg = inst.operands[0].reg;
11538
11539 if (unified_syntax)
11540 {
3d388997
PB
11541 bfd_boolean narrow;
11542 int shift_kind;
11543
11544 switch (inst.instruction)
11545 {
11546 case T_MNEM_asr:
11547 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11548 case T_MNEM_lsl:
11549 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11550 case T_MNEM_lsr:
11551 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11552 case T_MNEM_ror:
11553 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11554 default: abort ();
11555 }
11556
11557 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11558 narrow = !in_it_block ();
3d388997 11559 else
e07e6e58 11560 narrow = in_it_block ();
3d388997
PB
11561 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11562 narrow = FALSE;
11563 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11564 narrow = FALSE;
11565 if (inst.operands[2].isreg
11566 && (inst.operands[1].reg != inst.operands[0].reg
11567 || inst.operands[2].reg > 7))
11568 narrow = FALSE;
11569 if (inst.size_req == 4)
11570 narrow = FALSE;
11571
fdfde340
JM
11572 reject_bad_reg (inst.operands[0].reg);
11573 reject_bad_reg (inst.operands[1].reg);
c921be7d 11574
3d388997 11575 if (!narrow)
c19d1205
ZW
11576 {
11577 if (inst.operands[2].isreg)
b99bd4ef 11578 {
fdfde340 11579 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
11580 inst.instruction = THUMB_OP32 (inst.instruction);
11581 inst.instruction |= inst.operands[0].reg << 8;
11582 inst.instruction |= inst.operands[1].reg << 16;
11583 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
11584
11585 /* PR 12854: Error on extraneous shifts. */
11586 constraint (inst.operands[2].shifted,
11587 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
11588 }
11589 else
11590 {
11591 inst.operands[1].shifted = 1;
3d388997 11592 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
11593 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11594 ? T_MNEM_movs : T_MNEM_mov);
11595 inst.instruction |= inst.operands[0].reg << 8;
11596 encode_thumb32_shifted_operand (1);
11597 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11598 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
11599 }
11600 }
11601 else
11602 {
c19d1205 11603 if (inst.operands[2].isreg)
b99bd4ef 11604 {
3d388997 11605 switch (shift_kind)
b99bd4ef 11606 {
3d388997
PB
11607 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11608 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11609 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11610 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 11611 default: abort ();
b99bd4ef 11612 }
5f4273c7 11613
c19d1205
ZW
11614 inst.instruction |= inst.operands[0].reg;
11615 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
11616
11617 /* PR 12854: Error on extraneous shifts. */
11618 constraint (inst.operands[2].shifted,
11619 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
11620 }
11621 else
11622 {
3d388997 11623 switch (shift_kind)
b99bd4ef 11624 {
3d388997
PB
11625 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11626 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11627 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 11628 default: abort ();
b99bd4ef 11629 }
c19d1205
ZW
11630 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11631 inst.instruction |= inst.operands[0].reg;
11632 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11633 }
11634 }
c19d1205
ZW
11635 }
11636 else
11637 {
11638 constraint (inst.operands[0].reg > 7
11639 || inst.operands[1].reg > 7, BAD_HIREG);
11640 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 11641
c19d1205
ZW
11642 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11643 {
11644 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11645 constraint (inst.operands[0].reg != inst.operands[1].reg,
11646 _("source1 and dest must be same register"));
b99bd4ef 11647
c19d1205
ZW
11648 switch (inst.instruction)
11649 {
11650 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11651 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11652 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11653 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11654 default: abort ();
11655 }
5f4273c7 11656
c19d1205
ZW
11657 inst.instruction |= inst.operands[0].reg;
11658 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
11659
11660 /* PR 12854: Error on extraneous shifts. */
11661 constraint (inst.operands[2].shifted,
11662 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
11663 }
11664 else
b99bd4ef 11665 {
c19d1205
ZW
11666 switch (inst.instruction)
11667 {
11668 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11669 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11670 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11671 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11672 default: abort ();
11673 }
11674 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11675 inst.instruction |= inst.operands[0].reg;
11676 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11677 }
11678 }
b99bd4ef
NC
11679}
11680
11681static void
c19d1205 11682do_t_simd (void)
b99bd4ef 11683{
fdfde340
JM
11684 unsigned Rd, Rn, Rm;
11685
11686 Rd = inst.operands[0].reg;
11687 Rn = inst.operands[1].reg;
11688 Rm = inst.operands[2].reg;
11689
11690 reject_bad_reg (Rd);
11691 reject_bad_reg (Rn);
11692 reject_bad_reg (Rm);
11693
11694 inst.instruction |= Rd << 8;
11695 inst.instruction |= Rn << 16;
11696 inst.instruction |= Rm;
c19d1205 11697}
b99bd4ef 11698
03ee1b7f
NC
11699static void
11700do_t_simd2 (void)
11701{
11702 unsigned Rd, Rn, Rm;
11703
11704 Rd = inst.operands[0].reg;
11705 Rm = inst.operands[1].reg;
11706 Rn = inst.operands[2].reg;
11707
11708 reject_bad_reg (Rd);
11709 reject_bad_reg (Rn);
11710 reject_bad_reg (Rm);
11711
11712 inst.instruction |= Rd << 8;
11713 inst.instruction |= Rn << 16;
11714 inst.instruction |= Rm;
11715}
11716
c19d1205 11717static void
3eb17e6b 11718do_t_smc (void)
c19d1205
ZW
11719{
11720 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
11721 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
11722 _("SMC is not permitted on this architecture"));
c19d1205
ZW
11723 constraint (inst.reloc.exp.X_op != O_constant,
11724 _("expression too complex"));
11725 inst.reloc.type = BFD_RELOC_UNUSED;
11726 inst.instruction |= (value & 0xf000) >> 12;
11727 inst.instruction |= (value & 0x0ff0);
11728 inst.instruction |= (value & 0x000f) << 16;
11729}
b99bd4ef 11730
90ec0d68
MGD
11731static void
11732do_t_hvc (void)
11733{
11734 unsigned int value = inst.reloc.exp.X_add_number;
11735
11736 inst.reloc.type = BFD_RELOC_UNUSED;
11737 inst.instruction |= (value & 0x0fff);
11738 inst.instruction |= (value & 0xf000) << 4;
11739}
11740
c19d1205 11741static void
3a21c15a 11742do_t_ssat_usat (int bias)
c19d1205 11743{
fdfde340
JM
11744 unsigned Rd, Rn;
11745
11746 Rd = inst.operands[0].reg;
11747 Rn = inst.operands[2].reg;
11748
11749 reject_bad_reg (Rd);
11750 reject_bad_reg (Rn);
11751
11752 inst.instruction |= Rd << 8;
3a21c15a 11753 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 11754 inst.instruction |= Rn << 16;
b99bd4ef 11755
c19d1205 11756 if (inst.operands[3].present)
b99bd4ef 11757 {
3a21c15a
NC
11758 offsetT shift_amount = inst.reloc.exp.X_add_number;
11759
11760 inst.reloc.type = BFD_RELOC_UNUSED;
11761
c19d1205
ZW
11762 constraint (inst.reloc.exp.X_op != O_constant,
11763 _("expression too complex"));
b99bd4ef 11764
3a21c15a 11765 if (shift_amount != 0)
6189168b 11766 {
3a21c15a
NC
11767 constraint (shift_amount > 31,
11768 _("shift expression is too large"));
11769
c19d1205 11770 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
11771 inst.instruction |= 0x00200000; /* sh bit. */
11772
11773 inst.instruction |= (shift_amount & 0x1c) << 10;
11774 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
11775 }
11776 }
b99bd4ef 11777}
c921be7d 11778
3a21c15a
NC
11779static void
11780do_t_ssat (void)
11781{
11782 do_t_ssat_usat (1);
11783}
b99bd4ef 11784
0dd132b6 11785static void
c19d1205 11786do_t_ssat16 (void)
0dd132b6 11787{
fdfde340
JM
11788 unsigned Rd, Rn;
11789
11790 Rd = inst.operands[0].reg;
11791 Rn = inst.operands[2].reg;
11792
11793 reject_bad_reg (Rd);
11794 reject_bad_reg (Rn);
11795
11796 inst.instruction |= Rd << 8;
c19d1205 11797 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 11798 inst.instruction |= Rn << 16;
c19d1205 11799}
0dd132b6 11800
c19d1205
ZW
11801static void
11802do_t_strex (void)
11803{
11804 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11805 || inst.operands[2].postind || inst.operands[2].writeback
11806 || inst.operands[2].immisreg || inst.operands[2].shifted
11807 || inst.operands[2].negative,
01cfc07f 11808 BAD_ADDR_MODE);
0dd132b6 11809
5be8be5d
DG
11810 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11811
c19d1205
ZW
11812 inst.instruction |= inst.operands[0].reg << 8;
11813 inst.instruction |= inst.operands[1].reg << 12;
11814 inst.instruction |= inst.operands[2].reg << 16;
11815 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
11816}
11817
b99bd4ef 11818static void
c19d1205 11819do_t_strexd (void)
b99bd4ef 11820{
c19d1205
ZW
11821 if (!inst.operands[2].present)
11822 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 11823
c19d1205
ZW
11824 constraint (inst.operands[0].reg == inst.operands[1].reg
11825 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 11826 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 11827 BAD_OVERLAP);
b99bd4ef 11828
c19d1205
ZW
11829 inst.instruction |= inst.operands[0].reg;
11830 inst.instruction |= inst.operands[1].reg << 12;
11831 inst.instruction |= inst.operands[2].reg << 8;
11832 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
11833}
11834
11835static void
c19d1205 11836do_t_sxtah (void)
b99bd4ef 11837{
fdfde340
JM
11838 unsigned Rd, Rn, Rm;
11839
11840 Rd = inst.operands[0].reg;
11841 Rn = inst.operands[1].reg;
11842 Rm = inst.operands[2].reg;
11843
11844 reject_bad_reg (Rd);
11845 reject_bad_reg (Rn);
11846 reject_bad_reg (Rm);
11847
11848 inst.instruction |= Rd << 8;
11849 inst.instruction |= Rn << 16;
11850 inst.instruction |= Rm;
c19d1205
ZW
11851 inst.instruction |= inst.operands[3].imm << 4;
11852}
b99bd4ef 11853
c19d1205
ZW
11854static void
11855do_t_sxth (void)
11856{
fdfde340
JM
11857 unsigned Rd, Rm;
11858
11859 Rd = inst.operands[0].reg;
11860 Rm = inst.operands[1].reg;
11861
11862 reject_bad_reg (Rd);
11863 reject_bad_reg (Rm);
c921be7d
NC
11864
11865 if (inst.instruction <= 0xffff
11866 && inst.size_req != 4
fdfde340 11867 && Rd <= 7 && Rm <= 7
c19d1205 11868 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 11869 {
c19d1205 11870 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11871 inst.instruction |= Rd;
11872 inst.instruction |= Rm << 3;
b99bd4ef 11873 }
c19d1205 11874 else if (unified_syntax)
b99bd4ef 11875 {
c19d1205
ZW
11876 if (inst.instruction <= 0xffff)
11877 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11878 inst.instruction |= Rd << 8;
11879 inst.instruction |= Rm;
c19d1205 11880 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 11881 }
c19d1205 11882 else
b99bd4ef 11883 {
c19d1205
ZW
11884 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11885 _("Thumb encoding does not support rotation"));
11886 constraint (1, BAD_HIREG);
b99bd4ef 11887 }
c19d1205 11888}
b99bd4ef 11889
c19d1205
ZW
11890static void
11891do_t_swi (void)
11892{
b2a5fbdc
MGD
11893 /* We have to do the following check manually as ARM_EXT_OS only applies
11894 to ARM_EXT_V6M. */
11895 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
11896 {
ac7f631b
NC
11897 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
11898 /* This only applies to the v6m howver, not later architectures. */
11899 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
11900 as_bad (_("SVC is not permitted on this architecture"));
11901 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
11902 }
11903
c19d1205
ZW
11904 inst.reloc.type = BFD_RELOC_ARM_SWI;
11905}
b99bd4ef 11906
92e90b6e
PB
11907static void
11908do_t_tb (void)
11909{
fdfde340 11910 unsigned Rn, Rm;
92e90b6e
PB
11911 int half;
11912
11913 half = (inst.instruction & 0x10) != 0;
e07e6e58 11914 set_it_insn_type_last ();
dfa9f0d5
PB
11915 constraint (inst.operands[0].immisreg,
11916 _("instruction requires register index"));
fdfde340
JM
11917
11918 Rn = inst.operands[0].reg;
11919 Rm = inst.operands[0].imm;
c921be7d 11920
fdfde340
JM
11921 constraint (Rn == REG_SP, BAD_SP);
11922 reject_bad_reg (Rm);
11923
92e90b6e
PB
11924 constraint (!half && inst.operands[0].shifted,
11925 _("instruction does not allow shifted index"));
fdfde340 11926 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
11927}
11928
c19d1205
ZW
11929static void
11930do_t_usat (void)
11931{
3a21c15a 11932 do_t_ssat_usat (0);
b99bd4ef
NC
11933}
11934
11935static void
c19d1205 11936do_t_usat16 (void)
b99bd4ef 11937{
fdfde340
JM
11938 unsigned Rd, Rn;
11939
11940 Rd = inst.operands[0].reg;
11941 Rn = inst.operands[2].reg;
11942
11943 reject_bad_reg (Rd);
11944 reject_bad_reg (Rn);
11945
11946 inst.instruction |= Rd << 8;
c19d1205 11947 inst.instruction |= inst.operands[1].imm;
fdfde340 11948 inst.instruction |= Rn << 16;
b99bd4ef 11949}
c19d1205 11950
5287ad62 11951/* Neon instruction encoder helpers. */
5f4273c7 11952
5287ad62 11953/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 11954
5287ad62
JB
11955/* An "invalid" code for the following tables. */
11956#define N_INV -1u
11957
11958struct neon_tab_entry
b99bd4ef 11959{
5287ad62
JB
11960 unsigned integer;
11961 unsigned float_or_poly;
11962 unsigned scalar_or_imm;
11963};
5f4273c7 11964
5287ad62
JB
11965/* Map overloaded Neon opcodes to their respective encodings. */
11966#define NEON_ENC_TAB \
11967 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11968 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11969 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11970 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11971 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11972 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11973 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11974 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11975 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11976 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11977 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11978 /* Register variants of the following two instructions are encoded as
e07e6e58 11979 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
11980 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11981 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
11982 X(vfma, N_INV, 0x0000c10, N_INV), \
11983 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
11984 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11985 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11986 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11987 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11988 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11989 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11990 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11991 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11992 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11993 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11994 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11995 X(vshl, 0x0000400, N_INV, 0x0800510), \
11996 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11997 X(vand, 0x0000110, N_INV, 0x0800030), \
11998 X(vbic, 0x0100110, N_INV, 0x0800030), \
11999 X(veor, 0x1000110, N_INV, N_INV), \
12000 X(vorn, 0x0300110, N_INV, 0x0800010), \
12001 X(vorr, 0x0200110, N_INV, 0x0800010), \
12002 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
12003 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
12004 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
12005 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
12006 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
12007 X(vst1, 0x0000000, 0x0800000, N_INV), \
12008 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
12009 X(vst2, 0x0000100, 0x0800100, N_INV), \
12010 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
12011 X(vst3, 0x0000200, 0x0800200, N_INV), \
12012 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
12013 X(vst4, 0x0000300, 0x0800300, N_INV), \
12014 X(vmovn, 0x1b20200, N_INV, N_INV), \
12015 X(vtrn, 0x1b20080, N_INV, N_INV), \
12016 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
12017 X(vqmovun, 0x1b20240, N_INV, N_INV), \
12018 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
12019 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
12020 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
12021 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
12022 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
12023 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
12024 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
12025 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
12026 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
12027
12028enum neon_opc
12029{
12030#define X(OPC,I,F,S) N_MNEM_##OPC
12031NEON_ENC_TAB
12032#undef X
12033};
b99bd4ef 12034
5287ad62
JB
12035static const struct neon_tab_entry neon_enc_tab[] =
12036{
12037#define X(OPC,I,F,S) { (I), (F), (S) }
12038NEON_ENC_TAB
12039#undef X
12040};
b99bd4ef 12041
88714cb8
DG
12042/* Do not use these macros; instead, use NEON_ENCODE defined below. */
12043#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12044#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12045#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12046#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12047#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12048#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12049#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12050#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12051#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12052#define NEON_ENC_SINGLE_(X) \
037e8744 12053 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 12054#define NEON_ENC_DOUBLE_(X) \
037e8744 12055 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 12056
88714cb8
DG
12057#define NEON_ENCODE(type, inst) \
12058 do \
12059 { \
12060 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
12061 inst.is_neon = 1; \
12062 } \
12063 while (0)
12064
12065#define check_neon_suffixes \
12066 do \
12067 { \
12068 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
12069 { \
12070 as_bad (_("invalid neon suffix for non neon instruction")); \
12071 return; \
12072 } \
12073 } \
12074 while (0)
12075
037e8744
JB
12076/* Define shapes for instruction operands. The following mnemonic characters
12077 are used in this table:
5287ad62 12078
037e8744 12079 F - VFP S<n> register
5287ad62
JB
12080 D - Neon D<n> register
12081 Q - Neon Q<n> register
12082 I - Immediate
12083 S - Scalar
12084 R - ARM register
12085 L - D<n> register list
5f4273c7 12086
037e8744
JB
12087 This table is used to generate various data:
12088 - enumerations of the form NS_DDR to be used as arguments to
12089 neon_select_shape.
12090 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 12091 - a table used to drive neon_select_shape. */
b99bd4ef 12092
037e8744
JB
12093#define NEON_SHAPE_DEF \
12094 X(3, (D, D, D), DOUBLE), \
12095 X(3, (Q, Q, Q), QUAD), \
12096 X(3, (D, D, I), DOUBLE), \
12097 X(3, (Q, Q, I), QUAD), \
12098 X(3, (D, D, S), DOUBLE), \
12099 X(3, (Q, Q, S), QUAD), \
12100 X(2, (D, D), DOUBLE), \
12101 X(2, (Q, Q), QUAD), \
12102 X(2, (D, S), DOUBLE), \
12103 X(2, (Q, S), QUAD), \
12104 X(2, (D, R), DOUBLE), \
12105 X(2, (Q, R), QUAD), \
12106 X(2, (D, I), DOUBLE), \
12107 X(2, (Q, I), QUAD), \
12108 X(3, (D, L, D), DOUBLE), \
12109 X(2, (D, Q), MIXED), \
12110 X(2, (Q, D), MIXED), \
12111 X(3, (D, Q, I), MIXED), \
12112 X(3, (Q, D, I), MIXED), \
12113 X(3, (Q, D, D), MIXED), \
12114 X(3, (D, Q, Q), MIXED), \
12115 X(3, (Q, Q, D), MIXED), \
12116 X(3, (Q, D, S), MIXED), \
12117 X(3, (D, Q, S), MIXED), \
12118 X(4, (D, D, D, I), DOUBLE), \
12119 X(4, (Q, Q, Q, I), QUAD), \
12120 X(2, (F, F), SINGLE), \
12121 X(3, (F, F, F), SINGLE), \
12122 X(2, (F, I), SINGLE), \
12123 X(2, (F, D), MIXED), \
12124 X(2, (D, F), MIXED), \
12125 X(3, (F, F, I), MIXED), \
12126 X(4, (R, R, F, F), SINGLE), \
12127 X(4, (F, F, R, R), SINGLE), \
12128 X(3, (D, R, R), DOUBLE), \
12129 X(3, (R, R, D), DOUBLE), \
12130 X(2, (S, R), SINGLE), \
12131 X(2, (R, S), SINGLE), \
12132 X(2, (F, R), SINGLE), \
12133 X(2, (R, F), SINGLE)
12134
12135#define S2(A,B) NS_##A##B
12136#define S3(A,B,C) NS_##A##B##C
12137#define S4(A,B,C,D) NS_##A##B##C##D
12138
12139#define X(N, L, C) S##N L
12140
5287ad62
JB
12141enum neon_shape
12142{
037e8744
JB
12143 NEON_SHAPE_DEF,
12144 NS_NULL
5287ad62 12145};
b99bd4ef 12146
037e8744
JB
12147#undef X
12148#undef S2
12149#undef S3
12150#undef S4
12151
12152enum neon_shape_class
12153{
12154 SC_SINGLE,
12155 SC_DOUBLE,
12156 SC_QUAD,
12157 SC_MIXED
12158};
12159
12160#define X(N, L, C) SC_##C
12161
12162static enum neon_shape_class neon_shape_class[] =
12163{
12164 NEON_SHAPE_DEF
12165};
12166
12167#undef X
12168
12169enum neon_shape_el
12170{
12171 SE_F,
12172 SE_D,
12173 SE_Q,
12174 SE_I,
12175 SE_S,
12176 SE_R,
12177 SE_L
12178};
12179
12180/* Register widths of above. */
12181static unsigned neon_shape_el_size[] =
12182{
12183 32,
12184 64,
12185 128,
12186 0,
12187 32,
12188 32,
12189 0
12190};
12191
12192struct neon_shape_info
12193{
12194 unsigned els;
12195 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
12196};
12197
12198#define S2(A,B) { SE_##A, SE_##B }
12199#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
12200#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
12201
12202#define X(N, L, C) { N, S##N L }
12203
12204static struct neon_shape_info neon_shape_tab[] =
12205{
12206 NEON_SHAPE_DEF
12207};
12208
12209#undef X
12210#undef S2
12211#undef S3
12212#undef S4
12213
5287ad62
JB
12214/* Bit masks used in type checking given instructions.
12215 'N_EQK' means the type must be the same as (or based on in some way) the key
12216 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
12217 set, various other bits can be set as well in order to modify the meaning of
12218 the type constraint. */
12219
12220enum neon_type_mask
12221{
8e79c3df
CM
12222 N_S8 = 0x0000001,
12223 N_S16 = 0x0000002,
12224 N_S32 = 0x0000004,
12225 N_S64 = 0x0000008,
12226 N_U8 = 0x0000010,
12227 N_U16 = 0x0000020,
12228 N_U32 = 0x0000040,
12229 N_U64 = 0x0000080,
12230 N_I8 = 0x0000100,
12231 N_I16 = 0x0000200,
12232 N_I32 = 0x0000400,
12233 N_I64 = 0x0000800,
12234 N_8 = 0x0001000,
12235 N_16 = 0x0002000,
12236 N_32 = 0x0004000,
12237 N_64 = 0x0008000,
12238 N_P8 = 0x0010000,
12239 N_P16 = 0x0020000,
12240 N_F16 = 0x0040000,
12241 N_F32 = 0x0080000,
12242 N_F64 = 0x0100000,
c921be7d
NC
12243 N_KEY = 0x1000000, /* Key element (main type specifier). */
12244 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 12245 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
c921be7d
NC
12246 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
12247 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
12248 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
12249 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
12250 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
12251 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
12252 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 12253 N_UTYP = 0,
037e8744 12254 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
12255};
12256
dcbf9037
JB
12257#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
12258
5287ad62
JB
12259#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
12260#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
12261#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
12262#define N_SUF_32 (N_SU_32 | N_F32)
12263#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
12264#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
12265
12266/* Pass this as the first type argument to neon_check_type to ignore types
12267 altogether. */
12268#define N_IGNORE_TYPE (N_KEY | N_EQK)
12269
037e8744
JB
12270/* Select a "shape" for the current instruction (describing register types or
12271 sizes) from a list of alternatives. Return NS_NULL if the current instruction
12272 doesn't fit. For non-polymorphic shapes, checking is usually done as a
12273 function of operand parsing, so this function doesn't need to be called.
12274 Shapes should be listed in order of decreasing length. */
5287ad62
JB
12275
12276static enum neon_shape
037e8744 12277neon_select_shape (enum neon_shape shape, ...)
5287ad62 12278{
037e8744
JB
12279 va_list ap;
12280 enum neon_shape first_shape = shape;
5287ad62
JB
12281
12282 /* Fix missing optional operands. FIXME: we don't know at this point how
12283 many arguments we should have, so this makes the assumption that we have
12284 > 1. This is true of all current Neon opcodes, I think, but may not be
12285 true in the future. */
12286 if (!inst.operands[1].present)
12287 inst.operands[1] = inst.operands[0];
12288
037e8744 12289 va_start (ap, shape);
5f4273c7 12290
21d799b5 12291 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
12292 {
12293 unsigned j;
12294 int matches = 1;
12295
12296 for (j = 0; j < neon_shape_tab[shape].els; j++)
12297 {
12298 if (!inst.operands[j].present)
12299 {
12300 matches = 0;
12301 break;
12302 }
12303
12304 switch (neon_shape_tab[shape].el[j])
12305 {
12306 case SE_F:
12307 if (!(inst.operands[j].isreg
12308 && inst.operands[j].isvec
12309 && inst.operands[j].issingle
12310 && !inst.operands[j].isquad))
12311 matches = 0;
12312 break;
12313
12314 case SE_D:
12315 if (!(inst.operands[j].isreg
12316 && inst.operands[j].isvec
12317 && !inst.operands[j].isquad
12318 && !inst.operands[j].issingle))
12319 matches = 0;
12320 break;
12321
12322 case SE_R:
12323 if (!(inst.operands[j].isreg
12324 && !inst.operands[j].isvec))
12325 matches = 0;
12326 break;
12327
12328 case SE_Q:
12329 if (!(inst.operands[j].isreg
12330 && inst.operands[j].isvec
12331 && inst.operands[j].isquad
12332 && !inst.operands[j].issingle))
12333 matches = 0;
12334 break;
12335
12336 case SE_I:
12337 if (!(!inst.operands[j].isreg
12338 && !inst.operands[j].isscalar))
12339 matches = 0;
12340 break;
12341
12342 case SE_S:
12343 if (!(!inst.operands[j].isreg
12344 && inst.operands[j].isscalar))
12345 matches = 0;
12346 break;
12347
12348 case SE_L:
12349 break;
12350 }
3fde54a2
JZ
12351 if (!matches)
12352 break;
037e8744
JB
12353 }
12354 if (matches)
5287ad62 12355 break;
037e8744 12356 }
5f4273c7 12357
037e8744 12358 va_end (ap);
5287ad62 12359
037e8744
JB
12360 if (shape == NS_NULL && first_shape != NS_NULL)
12361 first_error (_("invalid instruction shape"));
5287ad62 12362
037e8744
JB
12363 return shape;
12364}
5287ad62 12365
037e8744
JB
12366/* True if SHAPE is predominantly a quadword operation (most of the time, this
12367 means the Q bit should be set). */
12368
12369static int
12370neon_quad (enum neon_shape shape)
12371{
12372 return neon_shape_class[shape] == SC_QUAD;
5287ad62 12373}
037e8744 12374
5287ad62
JB
12375static void
12376neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
12377 unsigned *g_size)
12378{
12379 /* Allow modification to be made to types which are constrained to be
12380 based on the key element, based on bits set alongside N_EQK. */
12381 if ((typebits & N_EQK) != 0)
12382 {
12383 if ((typebits & N_HLF) != 0)
12384 *g_size /= 2;
12385 else if ((typebits & N_DBL) != 0)
12386 *g_size *= 2;
12387 if ((typebits & N_SGN) != 0)
12388 *g_type = NT_signed;
12389 else if ((typebits & N_UNS) != 0)
12390 *g_type = NT_unsigned;
12391 else if ((typebits & N_INT) != 0)
12392 *g_type = NT_integer;
12393 else if ((typebits & N_FLT) != 0)
12394 *g_type = NT_float;
dcbf9037
JB
12395 else if ((typebits & N_SIZ) != 0)
12396 *g_type = NT_untyped;
5287ad62
JB
12397 }
12398}
5f4273c7 12399
5287ad62
JB
12400/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12401 operand type, i.e. the single type specified in a Neon instruction when it
12402 is the only one given. */
12403
12404static struct neon_type_el
12405neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12406{
12407 struct neon_type_el dest = *key;
5f4273c7 12408
9c2799c2 12409 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 12410
5287ad62
JB
12411 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12412
12413 return dest;
12414}
12415
12416/* Convert Neon type and size into compact bitmask representation. */
12417
12418static enum neon_type_mask
12419type_chk_of_el_type (enum neon_el_type type, unsigned size)
12420{
12421 switch (type)
12422 {
12423 case NT_untyped:
12424 switch (size)
12425 {
12426 case 8: return N_8;
12427 case 16: return N_16;
12428 case 32: return N_32;
12429 case 64: return N_64;
12430 default: ;
12431 }
12432 break;
12433
12434 case NT_integer:
12435 switch (size)
12436 {
12437 case 8: return N_I8;
12438 case 16: return N_I16;
12439 case 32: return N_I32;
12440 case 64: return N_I64;
12441 default: ;
12442 }
12443 break;
12444
12445 case NT_float:
037e8744
JB
12446 switch (size)
12447 {
8e79c3df 12448 case 16: return N_F16;
037e8744
JB
12449 case 32: return N_F32;
12450 case 64: return N_F64;
12451 default: ;
12452 }
5287ad62
JB
12453 break;
12454
12455 case NT_poly:
12456 switch (size)
12457 {
12458 case 8: return N_P8;
12459 case 16: return N_P16;
12460 default: ;
12461 }
12462 break;
12463
12464 case NT_signed:
12465 switch (size)
12466 {
12467 case 8: return N_S8;
12468 case 16: return N_S16;
12469 case 32: return N_S32;
12470 case 64: return N_S64;
12471 default: ;
12472 }
12473 break;
12474
12475 case NT_unsigned:
12476 switch (size)
12477 {
12478 case 8: return N_U8;
12479 case 16: return N_U16;
12480 case 32: return N_U32;
12481 case 64: return N_U64;
12482 default: ;
12483 }
12484 break;
12485
12486 default: ;
12487 }
5f4273c7 12488
5287ad62
JB
12489 return N_UTYP;
12490}
12491
12492/* Convert compact Neon bitmask type representation to a type and size. Only
12493 handles the case where a single bit is set in the mask. */
12494
dcbf9037 12495static int
5287ad62
JB
12496el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12497 enum neon_type_mask mask)
12498{
dcbf9037
JB
12499 if ((mask & N_EQK) != 0)
12500 return FAIL;
12501
5287ad62
JB
12502 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12503 *size = 8;
dcbf9037 12504 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 12505 *size = 16;
dcbf9037 12506 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 12507 *size = 32;
037e8744 12508 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 12509 *size = 64;
dcbf9037
JB
12510 else
12511 return FAIL;
12512
5287ad62
JB
12513 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12514 *type = NT_signed;
dcbf9037 12515 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 12516 *type = NT_unsigned;
dcbf9037 12517 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 12518 *type = NT_integer;
dcbf9037 12519 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 12520 *type = NT_untyped;
dcbf9037 12521 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 12522 *type = NT_poly;
037e8744 12523 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 12524 *type = NT_float;
dcbf9037
JB
12525 else
12526 return FAIL;
5f4273c7 12527
dcbf9037 12528 return SUCCESS;
5287ad62
JB
12529}
12530
12531/* Modify a bitmask of allowed types. This is only needed for type
12532 relaxation. */
12533
12534static unsigned
12535modify_types_allowed (unsigned allowed, unsigned mods)
12536{
12537 unsigned size;
12538 enum neon_el_type type;
12539 unsigned destmask;
12540 int i;
5f4273c7 12541
5287ad62 12542 destmask = 0;
5f4273c7 12543
5287ad62
JB
12544 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12545 {
21d799b5
NC
12546 if (el_type_of_type_chk (&type, &size,
12547 (enum neon_type_mask) (allowed & i)) == SUCCESS)
dcbf9037
JB
12548 {
12549 neon_modify_type_size (mods, &type, &size);
12550 destmask |= type_chk_of_el_type (type, size);
12551 }
5287ad62 12552 }
5f4273c7 12553
5287ad62
JB
12554 return destmask;
12555}
12556
12557/* Check type and return type classification.
12558 The manual states (paraphrase): If one datatype is given, it indicates the
12559 type given in:
12560 - the second operand, if there is one
12561 - the operand, if there is no second operand
12562 - the result, if there are no operands.
12563 This isn't quite good enough though, so we use a concept of a "key" datatype
12564 which is set on a per-instruction basis, which is the one which matters when
12565 only one data type is written.
12566 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 12567 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
12568
12569static struct neon_type_el
12570neon_check_type (unsigned els, enum neon_shape ns, ...)
12571{
12572 va_list ap;
12573 unsigned i, pass, key_el = 0;
12574 unsigned types[NEON_MAX_TYPE_ELS];
12575 enum neon_el_type k_type = NT_invtype;
12576 unsigned k_size = -1u;
12577 struct neon_type_el badtype = {NT_invtype, -1};
12578 unsigned key_allowed = 0;
12579
12580 /* Optional registers in Neon instructions are always (not) in operand 1.
12581 Fill in the missing operand here, if it was omitted. */
12582 if (els > 1 && !inst.operands[1].present)
12583 inst.operands[1] = inst.operands[0];
12584
12585 /* Suck up all the varargs. */
12586 va_start (ap, ns);
12587 for (i = 0; i < els; i++)
12588 {
12589 unsigned thisarg = va_arg (ap, unsigned);
12590 if (thisarg == N_IGNORE_TYPE)
12591 {
12592 va_end (ap);
12593 return badtype;
12594 }
12595 types[i] = thisarg;
12596 if ((thisarg & N_KEY) != 0)
12597 key_el = i;
12598 }
12599 va_end (ap);
12600
dcbf9037
JB
12601 if (inst.vectype.elems > 0)
12602 for (i = 0; i < els; i++)
12603 if (inst.operands[i].vectype.type != NT_invtype)
12604 {
12605 first_error (_("types specified in both the mnemonic and operands"));
12606 return badtype;
12607 }
12608
5287ad62
JB
12609 /* Duplicate inst.vectype elements here as necessary.
12610 FIXME: No idea if this is exactly the same as the ARM assembler,
12611 particularly when an insn takes one register and one non-register
12612 operand. */
12613 if (inst.vectype.elems == 1 && els > 1)
12614 {
12615 unsigned j;
12616 inst.vectype.elems = els;
12617 inst.vectype.el[key_el] = inst.vectype.el[0];
12618 for (j = 0; j < els; j++)
dcbf9037
JB
12619 if (j != key_el)
12620 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12621 types[j]);
12622 }
12623 else if (inst.vectype.elems == 0 && els > 0)
12624 {
12625 unsigned j;
12626 /* No types were given after the mnemonic, so look for types specified
12627 after each operand. We allow some flexibility here; as long as the
12628 "key" operand has a type, we can infer the others. */
12629 for (j = 0; j < els; j++)
12630 if (inst.operands[j].vectype.type != NT_invtype)
12631 inst.vectype.el[j] = inst.operands[j].vectype;
12632
12633 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 12634 {
dcbf9037
JB
12635 for (j = 0; j < els; j++)
12636 if (inst.operands[j].vectype.type == NT_invtype)
12637 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12638 types[j]);
12639 }
12640 else
12641 {
12642 first_error (_("operand types can't be inferred"));
12643 return badtype;
5287ad62
JB
12644 }
12645 }
12646 else if (inst.vectype.elems != els)
12647 {
dcbf9037 12648 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
12649 return badtype;
12650 }
12651
12652 for (pass = 0; pass < 2; pass++)
12653 {
12654 for (i = 0; i < els; i++)
12655 {
12656 unsigned thisarg = types[i];
12657 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12658 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12659 enum neon_el_type g_type = inst.vectype.el[i].type;
12660 unsigned g_size = inst.vectype.el[i].size;
12661
12662 /* Decay more-specific signed & unsigned types to sign-insensitive
12663 integer types if sign-specific variants are unavailable. */
12664 if ((g_type == NT_signed || g_type == NT_unsigned)
12665 && (types_allowed & N_SU_ALL) == 0)
12666 g_type = NT_integer;
12667
12668 /* If only untyped args are allowed, decay any more specific types to
12669 them. Some instructions only care about signs for some element
12670 sizes, so handle that properly. */
12671 if ((g_size == 8 && (types_allowed & N_8) != 0)
12672 || (g_size == 16 && (types_allowed & N_16) != 0)
12673 || (g_size == 32 && (types_allowed & N_32) != 0)
12674 || (g_size == 64 && (types_allowed & N_64) != 0))
12675 g_type = NT_untyped;
12676
12677 if (pass == 0)
12678 {
12679 if ((thisarg & N_KEY) != 0)
12680 {
12681 k_type = g_type;
12682 k_size = g_size;
12683 key_allowed = thisarg & ~N_KEY;
12684 }
12685 }
12686 else
12687 {
037e8744
JB
12688 if ((thisarg & N_VFP) != 0)
12689 {
99b253c5
NC
12690 enum neon_shape_el regshape;
12691 unsigned regwidth, match;
12692
12693 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12694 if (ns == NS_NULL)
12695 {
12696 first_error (_("invalid instruction shape"));
12697 return badtype;
12698 }
12699 regshape = neon_shape_tab[ns].el[i];
12700 regwidth = neon_shape_el_size[regshape];
037e8744
JB
12701
12702 /* In VFP mode, operands must match register widths. If we
12703 have a key operand, use its width, else use the width of
12704 the current operand. */
12705 if (k_size != -1u)
12706 match = k_size;
12707 else
12708 match = g_size;
12709
12710 if (regwidth != match)
12711 {
12712 first_error (_("operand size must match register width"));
12713 return badtype;
12714 }
12715 }
5f4273c7 12716
5287ad62
JB
12717 if ((thisarg & N_EQK) == 0)
12718 {
12719 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12720
12721 if ((given_type & types_allowed) == 0)
12722 {
dcbf9037 12723 first_error (_("bad type in Neon instruction"));
5287ad62
JB
12724 return badtype;
12725 }
12726 }
12727 else
12728 {
12729 enum neon_el_type mod_k_type = k_type;
12730 unsigned mod_k_size = k_size;
12731 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12732 if (g_type != mod_k_type || g_size != mod_k_size)
12733 {
dcbf9037 12734 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
12735 return badtype;
12736 }
12737 }
12738 }
12739 }
12740 }
12741
12742 return inst.vectype.el[key_el];
12743}
12744
037e8744 12745/* Neon-style VFP instruction forwarding. */
5287ad62 12746
037e8744
JB
12747/* Thumb VFP instructions have 0xE in the condition field. */
12748
12749static void
12750do_vfp_cond_or_thumb (void)
5287ad62 12751{
88714cb8
DG
12752 inst.is_neon = 1;
12753
5287ad62 12754 if (thumb_mode)
037e8744 12755 inst.instruction |= 0xe0000000;
5287ad62 12756 else
037e8744 12757 inst.instruction |= inst.cond << 28;
5287ad62
JB
12758}
12759
037e8744
JB
12760/* Look up and encode a simple mnemonic, for use as a helper function for the
12761 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12762 etc. It is assumed that operand parsing has already been done, and that the
12763 operands are in the form expected by the given opcode (this isn't necessarily
12764 the same as the form in which they were parsed, hence some massaging must
12765 take place before this function is called).
12766 Checks current arch version against that in the looked-up opcode. */
5287ad62 12767
037e8744
JB
12768static void
12769do_vfp_nsyn_opcode (const char *opname)
5287ad62 12770{
037e8744 12771 const struct asm_opcode *opcode;
5f4273c7 12772
21d799b5 12773 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 12774
037e8744
JB
12775 if (!opcode)
12776 abort ();
5287ad62 12777
037e8744
JB
12778 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12779 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12780 _(BAD_FPU));
5287ad62 12781
88714cb8
DG
12782 inst.is_neon = 1;
12783
037e8744
JB
12784 if (thumb_mode)
12785 {
12786 inst.instruction = opcode->tvalue;
12787 opcode->tencode ();
12788 }
12789 else
12790 {
12791 inst.instruction = (inst.cond << 28) | opcode->avalue;
12792 opcode->aencode ();
12793 }
12794}
5287ad62
JB
12795
12796static void
037e8744 12797do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 12798{
037e8744
JB
12799 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12800
12801 if (rs == NS_FFF)
12802 {
12803 if (is_add)
12804 do_vfp_nsyn_opcode ("fadds");
12805 else
12806 do_vfp_nsyn_opcode ("fsubs");
12807 }
12808 else
12809 {
12810 if (is_add)
12811 do_vfp_nsyn_opcode ("faddd");
12812 else
12813 do_vfp_nsyn_opcode ("fsubd");
12814 }
12815}
12816
12817/* Check operand types to see if this is a VFP instruction, and if so call
12818 PFN (). */
12819
12820static int
12821try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12822{
12823 enum neon_shape rs;
12824 struct neon_type_el et;
12825
12826 switch (args)
12827 {
12828 case 2:
12829 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12830 et = neon_check_type (2, rs,
12831 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12832 break;
5f4273c7 12833
037e8744
JB
12834 case 3:
12835 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12836 et = neon_check_type (3, rs,
12837 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12838 break;
12839
12840 default:
12841 abort ();
12842 }
12843
12844 if (et.type != NT_invtype)
12845 {
12846 pfn (rs);
12847 return SUCCESS;
12848 }
037e8744 12849
99b253c5 12850 inst.error = NULL;
037e8744
JB
12851 return FAIL;
12852}
12853
12854static void
12855do_vfp_nsyn_mla_mls (enum neon_shape rs)
12856{
12857 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 12858
037e8744
JB
12859 if (rs == NS_FFF)
12860 {
12861 if (is_mla)
12862 do_vfp_nsyn_opcode ("fmacs");
12863 else
1ee69515 12864 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
12865 }
12866 else
12867 {
12868 if (is_mla)
12869 do_vfp_nsyn_opcode ("fmacd");
12870 else
1ee69515 12871 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
12872 }
12873}
12874
62f3b8c8
PB
12875static void
12876do_vfp_nsyn_fma_fms (enum neon_shape rs)
12877{
12878 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12879
12880 if (rs == NS_FFF)
12881 {
12882 if (is_fma)
12883 do_vfp_nsyn_opcode ("ffmas");
12884 else
12885 do_vfp_nsyn_opcode ("ffnmas");
12886 }
12887 else
12888 {
12889 if (is_fma)
12890 do_vfp_nsyn_opcode ("ffmad");
12891 else
12892 do_vfp_nsyn_opcode ("ffnmad");
12893 }
12894}
12895
037e8744
JB
12896static void
12897do_vfp_nsyn_mul (enum neon_shape rs)
12898{
12899 if (rs == NS_FFF)
12900 do_vfp_nsyn_opcode ("fmuls");
12901 else
12902 do_vfp_nsyn_opcode ("fmuld");
12903}
12904
12905static void
12906do_vfp_nsyn_abs_neg (enum neon_shape rs)
12907{
12908 int is_neg = (inst.instruction & 0x80) != 0;
12909 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12910
12911 if (rs == NS_FF)
12912 {
12913 if (is_neg)
12914 do_vfp_nsyn_opcode ("fnegs");
12915 else
12916 do_vfp_nsyn_opcode ("fabss");
12917 }
12918 else
12919 {
12920 if (is_neg)
12921 do_vfp_nsyn_opcode ("fnegd");
12922 else
12923 do_vfp_nsyn_opcode ("fabsd");
12924 }
12925}
12926
12927/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12928 insns belong to Neon, and are handled elsewhere. */
12929
12930static void
12931do_vfp_nsyn_ldm_stm (int is_dbmode)
12932{
12933 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12934 if (is_ldm)
12935 {
12936 if (is_dbmode)
12937 do_vfp_nsyn_opcode ("fldmdbs");
12938 else
12939 do_vfp_nsyn_opcode ("fldmias");
12940 }
12941 else
12942 {
12943 if (is_dbmode)
12944 do_vfp_nsyn_opcode ("fstmdbs");
12945 else
12946 do_vfp_nsyn_opcode ("fstmias");
12947 }
12948}
12949
037e8744
JB
12950static void
12951do_vfp_nsyn_sqrt (void)
12952{
12953 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12954 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12955
037e8744
JB
12956 if (rs == NS_FF)
12957 do_vfp_nsyn_opcode ("fsqrts");
12958 else
12959 do_vfp_nsyn_opcode ("fsqrtd");
12960}
12961
12962static void
12963do_vfp_nsyn_div (void)
12964{
12965 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12966 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12967 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12968
037e8744
JB
12969 if (rs == NS_FFF)
12970 do_vfp_nsyn_opcode ("fdivs");
12971 else
12972 do_vfp_nsyn_opcode ("fdivd");
12973}
12974
12975static void
12976do_vfp_nsyn_nmul (void)
12977{
12978 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12979 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12980 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12981
037e8744
JB
12982 if (rs == NS_FFF)
12983 {
88714cb8 12984 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12985 do_vfp_sp_dyadic ();
12986 }
12987 else
12988 {
88714cb8 12989 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12990 do_vfp_dp_rd_rn_rm ();
12991 }
12992 do_vfp_cond_or_thumb ();
12993}
12994
12995static void
12996do_vfp_nsyn_cmp (void)
12997{
12998 if (inst.operands[1].isreg)
12999 {
13000 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13001 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13002
037e8744
JB
13003 if (rs == NS_FF)
13004 {
88714cb8 13005 NEON_ENCODE (SINGLE, inst);
037e8744
JB
13006 do_vfp_sp_monadic ();
13007 }
13008 else
13009 {
88714cb8 13010 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
13011 do_vfp_dp_rd_rm ();
13012 }
13013 }
13014 else
13015 {
13016 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
13017 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
13018
13019 switch (inst.instruction & 0x0fffffff)
13020 {
13021 case N_MNEM_vcmp:
13022 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
13023 break;
13024 case N_MNEM_vcmpe:
13025 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
13026 break;
13027 default:
13028 abort ();
13029 }
5f4273c7 13030
037e8744
JB
13031 if (rs == NS_FI)
13032 {
88714cb8 13033 NEON_ENCODE (SINGLE, inst);
037e8744
JB
13034 do_vfp_sp_compare_z ();
13035 }
13036 else
13037 {
88714cb8 13038 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
13039 do_vfp_dp_rd ();
13040 }
13041 }
13042 do_vfp_cond_or_thumb ();
13043}
13044
13045static void
13046nsyn_insert_sp (void)
13047{
13048 inst.operands[1] = inst.operands[0];
13049 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 13050 inst.operands[0].reg = REG_SP;
037e8744
JB
13051 inst.operands[0].isreg = 1;
13052 inst.operands[0].writeback = 1;
13053 inst.operands[0].present = 1;
13054}
13055
13056static void
13057do_vfp_nsyn_push (void)
13058{
13059 nsyn_insert_sp ();
13060 if (inst.operands[1].issingle)
13061 do_vfp_nsyn_opcode ("fstmdbs");
13062 else
13063 do_vfp_nsyn_opcode ("fstmdbd");
13064}
13065
13066static void
13067do_vfp_nsyn_pop (void)
13068{
13069 nsyn_insert_sp ();
13070 if (inst.operands[1].issingle)
22b5b651 13071 do_vfp_nsyn_opcode ("fldmias");
037e8744 13072 else
22b5b651 13073 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
13074}
13075
13076/* Fix up Neon data-processing instructions, ORing in the correct bits for
13077 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
13078
88714cb8
DG
13079static void
13080neon_dp_fixup (struct arm_it* insn)
037e8744 13081{
88714cb8
DG
13082 unsigned int i = insn->instruction;
13083 insn->is_neon = 1;
13084
037e8744
JB
13085 if (thumb_mode)
13086 {
13087 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
13088 if (i & (1 << 24))
13089 i |= 1 << 28;
5f4273c7 13090
037e8744 13091 i &= ~(1 << 24);
5f4273c7 13092
037e8744
JB
13093 i |= 0xef000000;
13094 }
13095 else
13096 i |= 0xf2000000;
5f4273c7 13097
88714cb8 13098 insn->instruction = i;
037e8744
JB
13099}
13100
13101/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
13102 (0, 1, 2, 3). */
13103
13104static unsigned
13105neon_logbits (unsigned x)
13106{
13107 return ffs (x) - 4;
13108}
13109
13110#define LOW4(R) ((R) & 0xf)
13111#define HI1(R) (((R) >> 4) & 1)
13112
13113/* Encode insns with bit pattern:
13114
13115 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13116 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 13117
037e8744
JB
13118 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
13119 different meaning for some instruction. */
13120
13121static void
13122neon_three_same (int isquad, int ubit, int size)
13123{
13124 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13125 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13126 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13127 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13128 inst.instruction |= LOW4 (inst.operands[2].reg);
13129 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13130 inst.instruction |= (isquad != 0) << 6;
13131 inst.instruction |= (ubit != 0) << 24;
13132 if (size != -1)
13133 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 13134
88714cb8 13135 neon_dp_fixup (&inst);
037e8744
JB
13136}
13137
13138/* Encode instructions of the form:
13139
13140 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
13141 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
13142
13143 Don't write size if SIZE == -1. */
13144
13145static void
13146neon_two_same (int qbit, int ubit, int size)
13147{
13148 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13149 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13150 inst.instruction |= LOW4 (inst.operands[1].reg);
13151 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13152 inst.instruction |= (qbit != 0) << 6;
13153 inst.instruction |= (ubit != 0) << 24;
13154
13155 if (size != -1)
13156 inst.instruction |= neon_logbits (size) << 18;
13157
88714cb8 13158 neon_dp_fixup (&inst);
5287ad62
JB
13159}
13160
13161/* Neon instruction encoders, in approximate order of appearance. */
13162
13163static void
13164do_neon_dyadic_i_su (void)
13165{
037e8744 13166 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13167 struct neon_type_el et = neon_check_type (3, rs,
13168 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 13169 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13170}
13171
13172static void
13173do_neon_dyadic_i64_su (void)
13174{
037e8744 13175 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13176 struct neon_type_el et = neon_check_type (3, rs,
13177 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 13178 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13179}
13180
13181static void
13182neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
13183 unsigned immbits)
13184{
13185 unsigned size = et.size >> 3;
13186 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13187 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13188 inst.instruction |= LOW4 (inst.operands[1].reg);
13189 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13190 inst.instruction |= (isquad != 0) << 6;
13191 inst.instruction |= immbits << 16;
13192 inst.instruction |= (size >> 3) << 7;
13193 inst.instruction |= (size & 0x7) << 19;
13194 if (write_ubit)
13195 inst.instruction |= (uval != 0) << 24;
13196
88714cb8 13197 neon_dp_fixup (&inst);
5287ad62
JB
13198}
13199
13200static void
13201do_neon_shl_imm (void)
13202{
13203 if (!inst.operands[2].isreg)
13204 {
037e8744 13205 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 13206 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
88714cb8 13207 NEON_ENCODE (IMMED, inst);
037e8744 13208 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
13209 }
13210 else
13211 {
037e8744 13212 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13213 struct neon_type_el et = neon_check_type (3, rs,
13214 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13215 unsigned int tmp;
13216
13217 /* VSHL/VQSHL 3-register variants have syntax such as:
13218 vshl.xx Dd, Dm, Dn
13219 whereas other 3-register operations encoded by neon_three_same have
13220 syntax like:
13221 vadd.xx Dd, Dn, Dm
13222 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
13223 here. */
13224 tmp = inst.operands[2].reg;
13225 inst.operands[2].reg = inst.operands[1].reg;
13226 inst.operands[1].reg = tmp;
88714cb8 13227 NEON_ENCODE (INTEGER, inst);
037e8744 13228 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13229 }
13230}
13231
13232static void
13233do_neon_qshl_imm (void)
13234{
13235 if (!inst.operands[2].isreg)
13236 {
037e8744 13237 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 13238 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 13239
88714cb8 13240 NEON_ENCODE (IMMED, inst);
037e8744 13241 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13242 inst.operands[2].imm);
13243 }
13244 else
13245 {
037e8744 13246 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13247 struct neon_type_el et = neon_check_type (3, rs,
13248 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13249 unsigned int tmp;
13250
13251 /* See note in do_neon_shl_imm. */
13252 tmp = inst.operands[2].reg;
13253 inst.operands[2].reg = inst.operands[1].reg;
13254 inst.operands[1].reg = tmp;
88714cb8 13255 NEON_ENCODE (INTEGER, inst);
037e8744 13256 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13257 }
13258}
13259
627907b7
JB
13260static void
13261do_neon_rshl (void)
13262{
13263 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13264 struct neon_type_el et = neon_check_type (3, rs,
13265 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13266 unsigned int tmp;
13267
13268 tmp = inst.operands[2].reg;
13269 inst.operands[2].reg = inst.operands[1].reg;
13270 inst.operands[1].reg = tmp;
13271 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13272}
13273
5287ad62
JB
13274static int
13275neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
13276{
036dc3f7
PB
13277 /* Handle .I8 pseudo-instructions. */
13278 if (size == 8)
5287ad62 13279 {
5287ad62
JB
13280 /* Unfortunately, this will make everything apart from zero out-of-range.
13281 FIXME is this the intended semantics? There doesn't seem much point in
13282 accepting .I8 if so. */
13283 immediate |= immediate << 8;
13284 size = 16;
036dc3f7
PB
13285 }
13286
13287 if (size >= 32)
13288 {
13289 if (immediate == (immediate & 0x000000ff))
13290 {
13291 *immbits = immediate;
13292 return 0x1;
13293 }
13294 else if (immediate == (immediate & 0x0000ff00))
13295 {
13296 *immbits = immediate >> 8;
13297 return 0x3;
13298 }
13299 else if (immediate == (immediate & 0x00ff0000))
13300 {
13301 *immbits = immediate >> 16;
13302 return 0x5;
13303 }
13304 else if (immediate == (immediate & 0xff000000))
13305 {
13306 *immbits = immediate >> 24;
13307 return 0x7;
13308 }
13309 if ((immediate & 0xffff) != (immediate >> 16))
13310 goto bad_immediate;
13311 immediate &= 0xffff;
5287ad62
JB
13312 }
13313
13314 if (immediate == (immediate & 0x000000ff))
13315 {
13316 *immbits = immediate;
036dc3f7 13317 return 0x9;
5287ad62
JB
13318 }
13319 else if (immediate == (immediate & 0x0000ff00))
13320 {
13321 *immbits = immediate >> 8;
036dc3f7 13322 return 0xb;
5287ad62
JB
13323 }
13324
13325 bad_immediate:
dcbf9037 13326 first_error (_("immediate value out of range"));
5287ad62
JB
13327 return FAIL;
13328}
13329
13330/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
13331 A, B, C, D. */
13332
13333static int
13334neon_bits_same_in_bytes (unsigned imm)
13335{
13336 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
13337 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
13338 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
13339 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
13340}
13341
13342/* For immediate of above form, return 0bABCD. */
13343
13344static unsigned
13345neon_squash_bits (unsigned imm)
13346{
13347 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
13348 | ((imm & 0x01000000) >> 21);
13349}
13350
136da414 13351/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
13352
13353static unsigned
13354neon_qfloat_bits (unsigned imm)
13355{
136da414 13356 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
13357}
13358
13359/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
13360 the instruction. *OP is passed as the initial value of the op field, and
13361 may be set to a different value depending on the constant (i.e.
13362 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 13363 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 13364 try smaller element sizes. */
5287ad62
JB
13365
13366static int
c96612cc
JB
13367neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
13368 unsigned *immbits, int *op, int size,
13369 enum neon_el_type type)
5287ad62 13370{
c96612cc
JB
13371 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13372 float. */
13373 if (type == NT_float && !float_p)
13374 return FAIL;
13375
136da414
JB
13376 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13377 {
13378 if (size != 32 || *op == 1)
13379 return FAIL;
13380 *immbits = neon_qfloat_bits (immlo);
13381 return 0xf;
13382 }
036dc3f7
PB
13383
13384 if (size == 64)
5287ad62 13385 {
036dc3f7
PB
13386 if (neon_bits_same_in_bytes (immhi)
13387 && neon_bits_same_in_bytes (immlo))
13388 {
13389 if (*op == 1)
13390 return FAIL;
13391 *immbits = (neon_squash_bits (immhi) << 4)
13392 | neon_squash_bits (immlo);
13393 *op = 1;
13394 return 0xe;
13395 }
13396
13397 if (immhi != immlo)
13398 return FAIL;
5287ad62 13399 }
036dc3f7
PB
13400
13401 if (size >= 32)
5287ad62 13402 {
036dc3f7
PB
13403 if (immlo == (immlo & 0x000000ff))
13404 {
13405 *immbits = immlo;
13406 return 0x0;
13407 }
13408 else if (immlo == (immlo & 0x0000ff00))
13409 {
13410 *immbits = immlo >> 8;
13411 return 0x2;
13412 }
13413 else if (immlo == (immlo & 0x00ff0000))
13414 {
13415 *immbits = immlo >> 16;
13416 return 0x4;
13417 }
13418 else if (immlo == (immlo & 0xff000000))
13419 {
13420 *immbits = immlo >> 24;
13421 return 0x6;
13422 }
13423 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13424 {
13425 *immbits = (immlo >> 8) & 0xff;
13426 return 0xc;
13427 }
13428 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13429 {
13430 *immbits = (immlo >> 16) & 0xff;
13431 return 0xd;
13432 }
13433
13434 if ((immlo & 0xffff) != (immlo >> 16))
13435 return FAIL;
13436 immlo &= 0xffff;
5287ad62 13437 }
036dc3f7
PB
13438
13439 if (size >= 16)
5287ad62 13440 {
036dc3f7
PB
13441 if (immlo == (immlo & 0x000000ff))
13442 {
13443 *immbits = immlo;
13444 return 0x8;
13445 }
13446 else if (immlo == (immlo & 0x0000ff00))
13447 {
13448 *immbits = immlo >> 8;
13449 return 0xa;
13450 }
13451
13452 if ((immlo & 0xff) != (immlo >> 8))
13453 return FAIL;
13454 immlo &= 0xff;
5287ad62 13455 }
036dc3f7
PB
13456
13457 if (immlo == (immlo & 0x000000ff))
5287ad62 13458 {
036dc3f7
PB
13459 /* Don't allow MVN with 8-bit immediate. */
13460 if (*op == 1)
13461 return FAIL;
13462 *immbits = immlo;
13463 return 0xe;
5287ad62 13464 }
5287ad62
JB
13465
13466 return FAIL;
13467}
13468
13469/* Write immediate bits [7:0] to the following locations:
13470
13471 |28/24|23 19|18 16|15 4|3 0|
13472 | 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|
13473
13474 This function is used by VMOV/VMVN/VORR/VBIC. */
13475
13476static void
13477neon_write_immbits (unsigned immbits)
13478{
13479 inst.instruction |= immbits & 0xf;
13480 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13481 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13482}
13483
13484/* Invert low-order SIZE bits of XHI:XLO. */
13485
13486static void
13487neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13488{
13489 unsigned immlo = xlo ? *xlo : 0;
13490 unsigned immhi = xhi ? *xhi : 0;
13491
13492 switch (size)
13493 {
13494 case 8:
13495 immlo = (~immlo) & 0xff;
13496 break;
13497
13498 case 16:
13499 immlo = (~immlo) & 0xffff;
13500 break;
13501
13502 case 64:
13503 immhi = (~immhi) & 0xffffffff;
13504 /* fall through. */
13505
13506 case 32:
13507 immlo = (~immlo) & 0xffffffff;
13508 break;
13509
13510 default:
13511 abort ();
13512 }
13513
13514 if (xlo)
13515 *xlo = immlo;
13516
13517 if (xhi)
13518 *xhi = immhi;
13519}
13520
13521static void
13522do_neon_logic (void)
13523{
13524 if (inst.operands[2].present && inst.operands[2].isreg)
13525 {
037e8744 13526 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13527 neon_check_type (3, rs, N_IGNORE_TYPE);
13528 /* U bit and size field were set as part of the bitmask. */
88714cb8 13529 NEON_ENCODE (INTEGER, inst);
037e8744 13530 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13531 }
13532 else
13533 {
4316f0d2
DG
13534 const int three_ops_form = (inst.operands[2].present
13535 && !inst.operands[2].isreg);
13536 const int immoperand = (three_ops_form ? 2 : 1);
13537 enum neon_shape rs = (three_ops_form
13538 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13539 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744
JB
13540 struct neon_type_el et = neon_check_type (2, rs,
13541 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 13542 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
13543 unsigned immbits;
13544 int cmode;
5f4273c7 13545
5287ad62
JB
13546 if (et.type == NT_invtype)
13547 return;
5f4273c7 13548
4316f0d2
DG
13549 if (three_ops_form)
13550 constraint (inst.operands[0].reg != inst.operands[1].reg,
13551 _("first and second operands shall be the same register"));
13552
88714cb8 13553 NEON_ENCODE (IMMED, inst);
5287ad62 13554
4316f0d2 13555 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
13556 if (et.size == 64)
13557 {
13558 /* .i64 is a pseudo-op, so the immediate must be a repeating
13559 pattern. */
4316f0d2
DG
13560 if (immbits != (inst.operands[immoperand].regisimm ?
13561 inst.operands[immoperand].reg : 0))
036dc3f7
PB
13562 {
13563 /* Set immbits to an invalid constant. */
13564 immbits = 0xdeadbeef;
13565 }
13566 }
13567
5287ad62
JB
13568 switch (opcode)
13569 {
13570 case N_MNEM_vbic:
036dc3f7 13571 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13572 break;
5f4273c7 13573
5287ad62 13574 case N_MNEM_vorr:
036dc3f7 13575 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13576 break;
5f4273c7 13577
5287ad62
JB
13578 case N_MNEM_vand:
13579 /* Pseudo-instruction for VBIC. */
5287ad62
JB
13580 neon_invert_size (&immbits, 0, et.size);
13581 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13582 break;
5f4273c7 13583
5287ad62
JB
13584 case N_MNEM_vorn:
13585 /* Pseudo-instruction for VORR. */
5287ad62
JB
13586 neon_invert_size (&immbits, 0, et.size);
13587 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13588 break;
5f4273c7 13589
5287ad62
JB
13590 default:
13591 abort ();
13592 }
13593
13594 if (cmode == FAIL)
13595 return;
13596
037e8744 13597 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13598 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13599 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13600 inst.instruction |= cmode << 8;
13601 neon_write_immbits (immbits);
5f4273c7 13602
88714cb8 13603 neon_dp_fixup (&inst);
5287ad62
JB
13604 }
13605}
13606
13607static void
13608do_neon_bitfield (void)
13609{
037e8744 13610 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 13611 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 13612 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13613}
13614
13615static void
dcbf9037
JB
13616neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13617 unsigned destbits)
5287ad62 13618{
037e8744 13619 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
13620 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13621 types | N_KEY);
5287ad62
JB
13622 if (et.type == NT_float)
13623 {
88714cb8 13624 NEON_ENCODE (FLOAT, inst);
037e8744 13625 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13626 }
13627 else
13628 {
88714cb8 13629 NEON_ENCODE (INTEGER, inst);
037e8744 13630 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
13631 }
13632}
13633
13634static void
13635do_neon_dyadic_if_su (void)
13636{
dcbf9037 13637 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13638}
13639
13640static void
13641do_neon_dyadic_if_su_d (void)
13642{
13643 /* This version only allow D registers, but that constraint is enforced during
13644 operand parsing so we don't need to do anything extra here. */
dcbf9037 13645 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13646}
13647
5287ad62
JB
13648static void
13649do_neon_dyadic_if_i_d (void)
13650{
428e3f1f
PB
13651 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13652 affected if we specify unsigned args. */
13653 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
13654}
13655
037e8744
JB
13656enum vfp_or_neon_is_neon_bits
13657{
13658 NEON_CHECK_CC = 1,
13659 NEON_CHECK_ARCH = 2
13660};
13661
13662/* Call this function if an instruction which may have belonged to the VFP or
13663 Neon instruction sets, but turned out to be a Neon instruction (due to the
13664 operand types involved, etc.). We have to check and/or fix-up a couple of
13665 things:
13666
13667 - Make sure the user hasn't attempted to make a Neon instruction
13668 conditional.
13669 - Alter the value in the condition code field if necessary.
13670 - Make sure that the arch supports Neon instructions.
13671
13672 Which of these operations take place depends on bits from enum
13673 vfp_or_neon_is_neon_bits.
13674
13675 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13676 current instruction's condition is COND_ALWAYS, the condition field is
13677 changed to inst.uncond_value. This is necessary because instructions shared
13678 between VFP and Neon may be conditional for the VFP variants only, and the
13679 unconditional Neon version must have, e.g., 0xF in the condition field. */
13680
13681static int
13682vfp_or_neon_is_neon (unsigned check)
13683{
13684 /* Conditions are always legal in Thumb mode (IT blocks). */
13685 if (!thumb_mode && (check & NEON_CHECK_CC))
13686 {
13687 if (inst.cond != COND_ALWAYS)
13688 {
13689 first_error (_(BAD_COND));
13690 return FAIL;
13691 }
13692 if (inst.uncond_value != -1)
13693 inst.instruction |= inst.uncond_value << 28;
13694 }
5f4273c7 13695
037e8744
JB
13696 if ((check & NEON_CHECK_ARCH)
13697 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13698 {
13699 first_error (_(BAD_FPU));
13700 return FAIL;
13701 }
5f4273c7 13702
037e8744
JB
13703 return SUCCESS;
13704}
13705
5287ad62
JB
13706static void
13707do_neon_addsub_if_i (void)
13708{
037e8744
JB
13709 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13710 return;
13711
13712 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13713 return;
13714
5287ad62
JB
13715 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13716 affected if we specify unsigned args. */
dcbf9037 13717 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
13718}
13719
13720/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13721 result to be:
13722 V<op> A,B (A is operand 0, B is operand 2)
13723 to mean:
13724 V<op> A,B,A
13725 not:
13726 V<op> A,B,B
13727 so handle that case specially. */
13728
13729static void
13730neon_exchange_operands (void)
13731{
13732 void *scratch = alloca (sizeof (inst.operands[0]));
13733 if (inst.operands[1].present)
13734 {
13735 /* Swap operands[1] and operands[2]. */
13736 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13737 inst.operands[1] = inst.operands[2];
13738 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13739 }
13740 else
13741 {
13742 inst.operands[1] = inst.operands[2];
13743 inst.operands[2] = inst.operands[0];
13744 }
13745}
13746
13747static void
13748neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13749{
13750 if (inst.operands[2].isreg)
13751 {
13752 if (invert)
13753 neon_exchange_operands ();
dcbf9037 13754 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
13755 }
13756 else
13757 {
037e8744 13758 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
13759 struct neon_type_el et = neon_check_type (2, rs,
13760 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 13761
88714cb8 13762 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13763 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13764 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13765 inst.instruction |= LOW4 (inst.operands[1].reg);
13766 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13767 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13768 inst.instruction |= (et.type == NT_float) << 10;
13769 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13770
88714cb8 13771 neon_dp_fixup (&inst);
5287ad62
JB
13772 }
13773}
13774
13775static void
13776do_neon_cmp (void)
13777{
13778 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13779}
13780
13781static void
13782do_neon_cmp_inv (void)
13783{
13784 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13785}
13786
13787static void
13788do_neon_ceq (void)
13789{
13790 neon_compare (N_IF_32, N_IF_32, FALSE);
13791}
13792
13793/* For multiply instructions, we have the possibility of 16-bit or 32-bit
13794 scalars, which are encoded in 5 bits, M : Rm.
13795 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13796 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13797 index in M. */
13798
13799static unsigned
13800neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13801{
dcbf9037
JB
13802 unsigned regno = NEON_SCALAR_REG (scalar);
13803 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
13804
13805 switch (elsize)
13806 {
13807 case 16:
13808 if (regno > 7 || elno > 3)
13809 goto bad_scalar;
13810 return regno | (elno << 3);
5f4273c7 13811
5287ad62
JB
13812 case 32:
13813 if (regno > 15 || elno > 1)
13814 goto bad_scalar;
13815 return regno | (elno << 4);
13816
13817 default:
13818 bad_scalar:
dcbf9037 13819 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
13820 }
13821
13822 return 0;
13823}
13824
13825/* Encode multiply / multiply-accumulate scalar instructions. */
13826
13827static void
13828neon_mul_mac (struct neon_type_el et, int ubit)
13829{
dcbf9037
JB
13830 unsigned scalar;
13831
13832 /* Give a more helpful error message if we have an invalid type. */
13833 if (et.type == NT_invtype)
13834 return;
5f4273c7 13835
dcbf9037 13836 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
13837 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13838 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13839 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13840 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13841 inst.instruction |= LOW4 (scalar);
13842 inst.instruction |= HI1 (scalar) << 5;
13843 inst.instruction |= (et.type == NT_float) << 8;
13844 inst.instruction |= neon_logbits (et.size) << 20;
13845 inst.instruction |= (ubit != 0) << 24;
13846
88714cb8 13847 neon_dp_fixup (&inst);
5287ad62
JB
13848}
13849
13850static void
13851do_neon_mac_maybe_scalar (void)
13852{
037e8744
JB
13853 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13854 return;
13855
13856 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13857 return;
13858
5287ad62
JB
13859 if (inst.operands[2].isscalar)
13860 {
037e8744 13861 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13862 struct neon_type_el et = neon_check_type (3, rs,
13863 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 13864 NEON_ENCODE (SCALAR, inst);
037e8744 13865 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13866 }
13867 else
428e3f1f
PB
13868 {
13869 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13870 affected if we specify unsigned args. */
13871 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13872 }
5287ad62
JB
13873}
13874
62f3b8c8
PB
13875static void
13876do_neon_fmac (void)
13877{
13878 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13879 return;
13880
13881 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13882 return;
13883
13884 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13885}
13886
5287ad62
JB
13887static void
13888do_neon_tst (void)
13889{
037e8744 13890 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13891 struct neon_type_el et = neon_check_type (3, rs,
13892 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 13893 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13894}
13895
13896/* VMUL with 3 registers allows the P8 type. The scalar version supports the
13897 same types as the MAC equivalents. The polynomial type for this instruction
13898 is encoded the same as the integer type. */
13899
13900static void
13901do_neon_mul (void)
13902{
037e8744
JB
13903 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13904 return;
13905
13906 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13907 return;
13908
5287ad62
JB
13909 if (inst.operands[2].isscalar)
13910 do_neon_mac_maybe_scalar ();
13911 else
dcbf9037 13912 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
13913}
13914
13915static void
13916do_neon_qdmulh (void)
13917{
13918 if (inst.operands[2].isscalar)
13919 {
037e8744 13920 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13921 struct neon_type_el et = neon_check_type (3, rs,
13922 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13923 NEON_ENCODE (SCALAR, inst);
037e8744 13924 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13925 }
13926 else
13927 {
037e8744 13928 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13929 struct neon_type_el et = neon_check_type (3, rs,
13930 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13931 NEON_ENCODE (INTEGER, inst);
5287ad62 13932 /* The U bit (rounding) comes from bit mask. */
037e8744 13933 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13934 }
13935}
13936
13937static void
13938do_neon_fcmp_absolute (void)
13939{
037e8744 13940 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13941 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13942 /* Size field comes from bit mask. */
037e8744 13943 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
13944}
13945
13946static void
13947do_neon_fcmp_absolute_inv (void)
13948{
13949 neon_exchange_operands ();
13950 do_neon_fcmp_absolute ();
13951}
13952
13953static void
13954do_neon_step (void)
13955{
037e8744 13956 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 13957 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 13958 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13959}
13960
13961static void
13962do_neon_abs_neg (void)
13963{
037e8744
JB
13964 enum neon_shape rs;
13965 struct neon_type_el et;
5f4273c7 13966
037e8744
JB
13967 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13968 return;
13969
13970 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13971 return;
13972
13973 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13974 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 13975
5287ad62
JB
13976 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13977 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13978 inst.instruction |= LOW4 (inst.operands[1].reg);
13979 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13980 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13981 inst.instruction |= (et.type == NT_float) << 10;
13982 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13983
88714cb8 13984 neon_dp_fixup (&inst);
5287ad62
JB
13985}
13986
13987static void
13988do_neon_sli (void)
13989{
037e8744 13990 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13991 struct neon_type_el et = neon_check_type (2, rs,
13992 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13993 int imm = inst.operands[2].imm;
13994 constraint (imm < 0 || (unsigned)imm >= et.size,
13995 _("immediate out of range for insert"));
037e8744 13996 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13997}
13998
13999static void
14000do_neon_sri (void)
14001{
037e8744 14002 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14003 struct neon_type_el et = neon_check_type (2, rs,
14004 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14005 int imm = inst.operands[2].imm;
14006 constraint (imm < 1 || (unsigned)imm > et.size,
14007 _("immediate out of range for insert"));
037e8744 14008 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
14009}
14010
14011static void
14012do_neon_qshlu_imm (void)
14013{
037e8744 14014 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14015 struct neon_type_el et = neon_check_type (2, rs,
14016 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14017 int imm = inst.operands[2].imm;
14018 constraint (imm < 0 || (unsigned)imm >= et.size,
14019 _("immediate out of range for shift"));
14020 /* Only encodes the 'U present' variant of the instruction.
14021 In this case, signed types have OP (bit 8) set to 0.
14022 Unsigned types have OP set to 1. */
14023 inst.instruction |= (et.type == NT_unsigned) << 8;
14024 /* The rest of the bits are the same as other immediate shifts. */
037e8744 14025 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14026}
14027
14028static void
14029do_neon_qmovn (void)
14030{
14031 struct neon_type_el et = neon_check_type (2, NS_DQ,
14032 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14033 /* Saturating move where operands can be signed or unsigned, and the
14034 destination has the same signedness. */
88714cb8 14035 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14036 if (et.type == NT_unsigned)
14037 inst.instruction |= 0xc0;
14038 else
14039 inst.instruction |= 0x80;
14040 neon_two_same (0, 1, et.size / 2);
14041}
14042
14043static void
14044do_neon_qmovun (void)
14045{
14046 struct neon_type_el et = neon_check_type (2, NS_DQ,
14047 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14048 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 14049 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14050 neon_two_same (0, 1, et.size / 2);
14051}
14052
14053static void
14054do_neon_rshift_sat_narrow (void)
14055{
14056 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14057 or unsigned. If operands are unsigned, results must also be unsigned. */
14058 struct neon_type_el et = neon_check_type (2, NS_DQI,
14059 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14060 int imm = inst.operands[2].imm;
14061 /* This gets the bounds check, size encoding and immediate bits calculation
14062 right. */
14063 et.size /= 2;
5f4273c7 14064
5287ad62
JB
14065 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14066 VQMOVN.I<size> <Dd>, <Qm>. */
14067 if (imm == 0)
14068 {
14069 inst.operands[2].present = 0;
14070 inst.instruction = N_MNEM_vqmovn;
14071 do_neon_qmovn ();
14072 return;
14073 }
5f4273c7 14074
5287ad62
JB
14075 constraint (imm < 1 || (unsigned)imm > et.size,
14076 _("immediate out of range"));
14077 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14078}
14079
14080static void
14081do_neon_rshift_sat_narrow_u (void)
14082{
14083 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14084 or unsigned. If operands are unsigned, results must also be unsigned. */
14085 struct neon_type_el et = neon_check_type (2, NS_DQI,
14086 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14087 int imm = inst.operands[2].imm;
14088 /* This gets the bounds check, size encoding and immediate bits calculation
14089 right. */
14090 et.size /= 2;
14091
14092 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14093 VQMOVUN.I<size> <Dd>, <Qm>. */
14094 if (imm == 0)
14095 {
14096 inst.operands[2].present = 0;
14097 inst.instruction = N_MNEM_vqmovun;
14098 do_neon_qmovun ();
14099 return;
14100 }
14101
14102 constraint (imm < 1 || (unsigned)imm > et.size,
14103 _("immediate out of range"));
14104 /* FIXME: The manual is kind of unclear about what value U should have in
14105 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
14106 must be 1. */
14107 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
14108}
14109
14110static void
14111do_neon_movn (void)
14112{
14113 struct neon_type_el et = neon_check_type (2, NS_DQ,
14114 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 14115 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14116 neon_two_same (0, 1, et.size / 2);
14117}
14118
14119static void
14120do_neon_rshift_narrow (void)
14121{
14122 struct neon_type_el et = neon_check_type (2, NS_DQI,
14123 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14124 int imm = inst.operands[2].imm;
14125 /* This gets the bounds check, size encoding and immediate bits calculation
14126 right. */
14127 et.size /= 2;
5f4273c7 14128
5287ad62
JB
14129 /* If immediate is zero then we are a pseudo-instruction for
14130 VMOVN.I<size> <Dd>, <Qm> */
14131 if (imm == 0)
14132 {
14133 inst.operands[2].present = 0;
14134 inst.instruction = N_MNEM_vmovn;
14135 do_neon_movn ();
14136 return;
14137 }
5f4273c7 14138
5287ad62
JB
14139 constraint (imm < 1 || (unsigned)imm > et.size,
14140 _("immediate out of range for narrowing operation"));
14141 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
14142}
14143
14144static void
14145do_neon_shll (void)
14146{
14147 /* FIXME: Type checking when lengthening. */
14148 struct neon_type_el et = neon_check_type (2, NS_QDI,
14149 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
14150 unsigned imm = inst.operands[2].imm;
14151
14152 if (imm == et.size)
14153 {
14154 /* Maximum shift variant. */
88714cb8 14155 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14156 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14157 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14158 inst.instruction |= LOW4 (inst.operands[1].reg);
14159 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14160 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14161
88714cb8 14162 neon_dp_fixup (&inst);
5287ad62
JB
14163 }
14164 else
14165 {
14166 /* A more-specific type check for non-max versions. */
14167 et = neon_check_type (2, NS_QDI,
14168 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 14169 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14170 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
14171 }
14172}
14173
037e8744 14174/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
14175 the current instruction is. */
14176
14177static int
14178neon_cvt_flavour (enum neon_shape rs)
14179{
037e8744
JB
14180#define CVT_VAR(C,X,Y) \
14181 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
14182 if (et.type != NT_invtype) \
14183 { \
14184 inst.error = NULL; \
14185 return (C); \
5287ad62
JB
14186 }
14187 struct neon_type_el et;
037e8744
JB
14188 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
14189 || rs == NS_FF) ? N_VFP : 0;
14190 /* The instruction versions which take an immediate take one register
14191 argument, which is extended to the width of the full register. Thus the
14192 "source" and "destination" registers must have the same width. Hack that
14193 here by making the size equal to the key (wider, in this case) operand. */
14194 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 14195
5287ad62
JB
14196 CVT_VAR (0, N_S32, N_F32);
14197 CVT_VAR (1, N_U32, N_F32);
14198 CVT_VAR (2, N_F32, N_S32);
14199 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
14200 /* Half-precision conversions. */
14201 CVT_VAR (4, N_F32, N_F16);
14202 CVT_VAR (5, N_F16, N_F32);
5f4273c7 14203
037e8744 14204 whole_reg = N_VFP;
5f4273c7 14205
037e8744 14206 /* VFP instructions. */
8e79c3df
CM
14207 CVT_VAR (6, N_F32, N_F64);
14208 CVT_VAR (7, N_F64, N_F32);
14209 CVT_VAR (8, N_S32, N_F64 | key);
14210 CVT_VAR (9, N_U32, N_F64 | key);
14211 CVT_VAR (10, N_F64 | key, N_S32);
14212 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 14213 /* VFP instructions with bitshift. */
8e79c3df
CM
14214 CVT_VAR (12, N_F32 | key, N_S16);
14215 CVT_VAR (13, N_F32 | key, N_U16);
14216 CVT_VAR (14, N_F64 | key, N_S16);
14217 CVT_VAR (15, N_F64 | key, N_U16);
14218 CVT_VAR (16, N_S16, N_F32 | key);
14219 CVT_VAR (17, N_U16, N_F32 | key);
14220 CVT_VAR (18, N_S16, N_F64 | key);
14221 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 14222
5287ad62
JB
14223 return -1;
14224#undef CVT_VAR
14225}
14226
037e8744
JB
14227/* Neon-syntax VFP conversions. */
14228
5287ad62 14229static void
037e8744 14230do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 14231{
037e8744 14232 const char *opname = 0;
5f4273c7 14233
037e8744 14234 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 14235 {
037e8744
JB
14236 /* Conversions with immediate bitshift. */
14237 const char *enc[] =
14238 {
14239 "ftosls",
14240 "ftouls",
14241 "fsltos",
14242 "fultos",
14243 NULL,
14244 NULL,
8e79c3df
CM
14245 NULL,
14246 NULL,
037e8744
JB
14247 "ftosld",
14248 "ftould",
14249 "fsltod",
14250 "fultod",
14251 "fshtos",
14252 "fuhtos",
14253 "fshtod",
14254 "fuhtod",
14255 "ftoshs",
14256 "ftouhs",
14257 "ftoshd",
14258 "ftouhd"
14259 };
14260
14261 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14262 {
14263 opname = enc[flavour];
14264 constraint (inst.operands[0].reg != inst.operands[1].reg,
14265 _("operands 0 and 1 must be the same register"));
14266 inst.operands[1] = inst.operands[2];
14267 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
14268 }
5287ad62
JB
14269 }
14270 else
14271 {
037e8744
JB
14272 /* Conversions without bitshift. */
14273 const char *enc[] =
14274 {
14275 "ftosis",
14276 "ftouis",
14277 "fsitos",
14278 "fuitos",
8e79c3df
CM
14279 "NULL",
14280 "NULL",
037e8744
JB
14281 "fcvtsd",
14282 "fcvtds",
14283 "ftosid",
14284 "ftouid",
14285 "fsitod",
14286 "fuitod"
14287 };
14288
14289 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14290 opname = enc[flavour];
14291 }
14292
14293 if (opname)
14294 do_vfp_nsyn_opcode (opname);
14295}
14296
14297static void
14298do_vfp_nsyn_cvtz (void)
14299{
14300 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
14301 int flavour = neon_cvt_flavour (rs);
14302 const char *enc[] =
14303 {
14304 "ftosizs",
14305 "ftouizs",
14306 NULL,
14307 NULL,
14308 NULL,
14309 NULL,
8e79c3df
CM
14310 NULL,
14311 NULL,
037e8744
JB
14312 "ftosizd",
14313 "ftouizd"
14314 };
14315
14316 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
14317 do_vfp_nsyn_opcode (enc[flavour]);
14318}
f31fef98 14319
037e8744 14320static void
e3e535bc 14321do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
037e8744
JB
14322{
14323 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 14324 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
14325 int flavour = neon_cvt_flavour (rs);
14326
e3e535bc
NC
14327 /* PR11109: Handle round-to-zero for VCVT conversions. */
14328 if (round_to_zero
14329 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
14330 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
14331 && (rs == NS_FD || rs == NS_FF))
14332 {
14333 do_vfp_nsyn_cvtz ();
14334 return;
14335 }
14336
037e8744 14337 /* VFP rather than Neon conversions. */
8e79c3df 14338 if (flavour >= 6)
037e8744
JB
14339 {
14340 do_vfp_nsyn_cvt (rs, flavour);
14341 return;
14342 }
14343
14344 switch (rs)
14345 {
14346 case NS_DDI:
14347 case NS_QQI:
14348 {
35997600
NC
14349 unsigned immbits;
14350 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
14351
037e8744
JB
14352 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14353 return;
14354
14355 /* Fixed-point conversion with #0 immediate is encoded as an
14356 integer conversion. */
14357 if (inst.operands[2].present && inst.operands[2].imm == 0)
14358 goto int_encode;
35997600 14359 immbits = 32 - inst.operands[2].imm;
88714cb8 14360 NEON_ENCODE (IMMED, inst);
037e8744
JB
14361 if (flavour != -1)
14362 inst.instruction |= enctab[flavour];
14363 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14364 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14365 inst.instruction |= LOW4 (inst.operands[1].reg);
14366 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14367 inst.instruction |= neon_quad (rs) << 6;
14368 inst.instruction |= 1 << 21;
14369 inst.instruction |= immbits << 16;
14370
88714cb8 14371 neon_dp_fixup (&inst);
037e8744
JB
14372 }
14373 break;
14374
14375 case NS_DD:
14376 case NS_QQ:
14377 int_encode:
14378 {
14379 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
14380
88714cb8 14381 NEON_ENCODE (INTEGER, inst);
037e8744
JB
14382
14383 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14384 return;
14385
14386 if (flavour != -1)
14387 inst.instruction |= enctab[flavour];
14388
14389 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14390 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14391 inst.instruction |= LOW4 (inst.operands[1].reg);
14392 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14393 inst.instruction |= neon_quad (rs) << 6;
14394 inst.instruction |= 2 << 18;
14395
88714cb8 14396 neon_dp_fixup (&inst);
037e8744
JB
14397 }
14398 break;
14399
8e79c3df
CM
14400 /* Half-precision conversions for Advanced SIMD -- neon. */
14401 case NS_QD:
14402 case NS_DQ:
14403
14404 if ((rs == NS_DQ)
14405 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14406 {
14407 as_bad (_("operand size must match register width"));
14408 break;
14409 }
14410
14411 if ((rs == NS_QD)
14412 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14413 {
14414 as_bad (_("operand size must match register width"));
14415 break;
14416 }
14417
14418 if (rs == NS_DQ)
14419 inst.instruction = 0x3b60600;
14420 else
14421 inst.instruction = 0x3b60700;
14422
14423 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14424 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14425 inst.instruction |= LOW4 (inst.operands[1].reg);
14426 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 14427 neon_dp_fixup (&inst);
8e79c3df
CM
14428 break;
14429
037e8744
JB
14430 default:
14431 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
14432 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 14433 }
5287ad62
JB
14434}
14435
e3e535bc
NC
14436static void
14437do_neon_cvtr (void)
14438{
14439 do_neon_cvt_1 (FALSE);
14440}
14441
14442static void
14443do_neon_cvt (void)
14444{
14445 do_neon_cvt_1 (TRUE);
14446}
14447
8e79c3df
CM
14448static void
14449do_neon_cvtb (void)
14450{
14451 inst.instruction = 0xeb20a40;
14452
14453 /* The sizes are attached to the mnemonic. */
14454 if (inst.vectype.el[0].type != NT_invtype
14455 && inst.vectype.el[0].size == 16)
14456 inst.instruction |= 0x00010000;
14457
14458 /* Programmer's syntax: the sizes are attached to the operands. */
14459 else if (inst.operands[0].vectype.type != NT_invtype
14460 && inst.operands[0].vectype.size == 16)
14461 inst.instruction |= 0x00010000;
14462
14463 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14464 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
14465 do_vfp_cond_or_thumb ();
14466}
14467
14468
14469static void
14470do_neon_cvtt (void)
14471{
14472 do_neon_cvtb ();
14473 inst.instruction |= 0x80;
14474}
14475
5287ad62
JB
14476static void
14477neon_move_immediate (void)
14478{
037e8744
JB
14479 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14480 struct neon_type_el et = neon_check_type (2, rs,
14481 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 14482 unsigned immlo, immhi = 0, immbits;
c96612cc 14483 int op, cmode, float_p;
5287ad62 14484
037e8744
JB
14485 constraint (et.type == NT_invtype,
14486 _("operand size must be specified for immediate VMOV"));
14487
5287ad62
JB
14488 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14489 op = (inst.instruction & (1 << 5)) != 0;
14490
14491 immlo = inst.operands[1].imm;
14492 if (inst.operands[1].regisimm)
14493 immhi = inst.operands[1].reg;
14494
14495 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14496 _("immediate has bits set outside the operand size"));
14497
c96612cc
JB
14498 float_p = inst.operands[1].immisfloat;
14499
14500 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 14501 et.size, et.type)) == FAIL)
5287ad62
JB
14502 {
14503 /* Invert relevant bits only. */
14504 neon_invert_size (&immlo, &immhi, et.size);
14505 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14506 with one or the other; those cases are caught by
14507 neon_cmode_for_move_imm. */
14508 op = !op;
c96612cc
JB
14509 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
14510 &op, et.size, et.type)) == FAIL)
5287ad62 14511 {
dcbf9037 14512 first_error (_("immediate out of range"));
5287ad62
JB
14513 return;
14514 }
14515 }
14516
14517 inst.instruction &= ~(1 << 5);
14518 inst.instruction |= op << 5;
14519
14520 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14521 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 14522 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14523 inst.instruction |= cmode << 8;
14524
14525 neon_write_immbits (immbits);
14526}
14527
14528static void
14529do_neon_mvn (void)
14530{
14531 if (inst.operands[1].isreg)
14532 {
037e8744 14533 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 14534
88714cb8 14535 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14536 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14537 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14538 inst.instruction |= LOW4 (inst.operands[1].reg);
14539 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14540 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14541 }
14542 else
14543 {
88714cb8 14544 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14545 neon_move_immediate ();
14546 }
14547
88714cb8 14548 neon_dp_fixup (&inst);
5287ad62
JB
14549}
14550
14551/* Encode instructions of form:
14552
14553 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 14554 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
14555
14556static void
14557neon_mixed_length (struct neon_type_el et, unsigned size)
14558{
14559 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14560 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14561 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14562 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14563 inst.instruction |= LOW4 (inst.operands[2].reg);
14564 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14565 inst.instruction |= (et.type == NT_unsigned) << 24;
14566 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14567
88714cb8 14568 neon_dp_fixup (&inst);
5287ad62
JB
14569}
14570
14571static void
14572do_neon_dyadic_long (void)
14573{
14574 /* FIXME: Type checking for lengthening op. */
14575 struct neon_type_el et = neon_check_type (3, NS_QDD,
14576 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14577 neon_mixed_length (et, et.size);
14578}
14579
14580static void
14581do_neon_abal (void)
14582{
14583 struct neon_type_el et = neon_check_type (3, NS_QDD,
14584 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14585 neon_mixed_length (et, et.size);
14586}
14587
14588static void
14589neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14590{
14591 if (inst.operands[2].isscalar)
14592 {
dcbf9037
JB
14593 struct neon_type_el et = neon_check_type (3, NS_QDS,
14594 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 14595 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14596 neon_mul_mac (et, et.type == NT_unsigned);
14597 }
14598 else
14599 {
14600 struct neon_type_el et = neon_check_type (3, NS_QDD,
14601 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 14602 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14603 neon_mixed_length (et, et.size);
14604 }
14605}
14606
14607static void
14608do_neon_mac_maybe_scalar_long (void)
14609{
14610 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14611}
14612
14613static void
14614do_neon_dyadic_wide (void)
14615{
14616 struct neon_type_el et = neon_check_type (3, NS_QQD,
14617 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14618 neon_mixed_length (et, et.size);
14619}
14620
14621static void
14622do_neon_dyadic_narrow (void)
14623{
14624 struct neon_type_el et = neon_check_type (3, NS_QDD,
14625 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
14626 /* Operand sign is unimportant, and the U bit is part of the opcode,
14627 so force the operand type to integer. */
14628 et.type = NT_integer;
5287ad62
JB
14629 neon_mixed_length (et, et.size / 2);
14630}
14631
14632static void
14633do_neon_mul_sat_scalar_long (void)
14634{
14635 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14636}
14637
14638static void
14639do_neon_vmull (void)
14640{
14641 if (inst.operands[2].isscalar)
14642 do_neon_mac_maybe_scalar_long ();
14643 else
14644 {
14645 struct neon_type_el et = neon_check_type (3, NS_QDD,
14646 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14647 if (et.type == NT_poly)
88714cb8 14648 NEON_ENCODE (POLY, inst);
5287ad62 14649 else
88714cb8 14650 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14651 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14652 zero. Should be OK as-is. */
14653 neon_mixed_length (et, et.size);
14654 }
14655}
14656
14657static void
14658do_neon_ext (void)
14659{
037e8744 14660 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
14661 struct neon_type_el et = neon_check_type (3, rs,
14662 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14663 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
14664
14665 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14666 _("shift out of range"));
5287ad62
JB
14667 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14668 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14669 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14670 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14671 inst.instruction |= LOW4 (inst.operands[2].reg);
14672 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 14673 inst.instruction |= neon_quad (rs) << 6;
5287ad62 14674 inst.instruction |= imm << 8;
5f4273c7 14675
88714cb8 14676 neon_dp_fixup (&inst);
5287ad62
JB
14677}
14678
14679static void
14680do_neon_rev (void)
14681{
037e8744 14682 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14683 struct neon_type_el et = neon_check_type (2, rs,
14684 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14685 unsigned op = (inst.instruction >> 7) & 3;
14686 /* N (width of reversed regions) is encoded as part of the bitmask. We
14687 extract it here to check the elements to be reversed are smaller.
14688 Otherwise we'd get a reserved instruction. */
14689 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 14690 gas_assert (elsize != 0);
5287ad62
JB
14691 constraint (et.size >= elsize,
14692 _("elements must be smaller than reversal region"));
037e8744 14693 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14694}
14695
14696static void
14697do_neon_dup (void)
14698{
14699 if (inst.operands[1].isscalar)
14700 {
037e8744 14701 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
14702 struct neon_type_el et = neon_check_type (2, rs,
14703 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 14704 unsigned sizebits = et.size >> 3;
dcbf9037 14705 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 14706 int logsize = neon_logbits (et.size);
dcbf9037 14707 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
14708
14709 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14710 return;
14711
88714cb8 14712 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14713 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14714 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14715 inst.instruction |= LOW4 (dm);
14716 inst.instruction |= HI1 (dm) << 5;
037e8744 14717 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14718 inst.instruction |= x << 17;
14719 inst.instruction |= sizebits << 16;
5f4273c7 14720
88714cb8 14721 neon_dp_fixup (&inst);
5287ad62
JB
14722 }
14723 else
14724 {
037e8744
JB
14725 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14726 struct neon_type_el et = neon_check_type (2, rs,
14727 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 14728 /* Duplicate ARM register to lanes of vector. */
88714cb8 14729 NEON_ENCODE (ARMREG, inst);
5287ad62
JB
14730 switch (et.size)
14731 {
14732 case 8: inst.instruction |= 0x400000; break;
14733 case 16: inst.instruction |= 0x000020; break;
14734 case 32: inst.instruction |= 0x000000; break;
14735 default: break;
14736 }
14737 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14738 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14739 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 14740 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
14741 /* The encoding for this instruction is identical for the ARM and Thumb
14742 variants, except for the condition field. */
037e8744 14743 do_vfp_cond_or_thumb ();
5287ad62
JB
14744 }
14745}
14746
14747/* VMOV has particularly many variations. It can be one of:
14748 0. VMOV<c><q> <Qd>, <Qm>
14749 1. VMOV<c><q> <Dd>, <Dm>
14750 (Register operations, which are VORR with Rm = Rn.)
14751 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14752 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14753 (Immediate loads.)
14754 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14755 (ARM register to scalar.)
14756 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14757 (Two ARM registers to vector.)
14758 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14759 (Scalar to ARM register.)
14760 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14761 (Vector to two ARM registers.)
037e8744
JB
14762 8. VMOV.F32 <Sd>, <Sm>
14763 9. VMOV.F64 <Dd>, <Dm>
14764 (VFP register moves.)
14765 10. VMOV.F32 <Sd>, #imm
14766 11. VMOV.F64 <Dd>, #imm
14767 (VFP float immediate load.)
14768 12. VMOV <Rd>, <Sm>
14769 (VFP single to ARM reg.)
14770 13. VMOV <Sd>, <Rm>
14771 (ARM reg to VFP single.)
14772 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14773 (Two ARM regs to two VFP singles.)
14774 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14775 (Two VFP singles to two ARM regs.)
5f4273c7 14776
037e8744
JB
14777 These cases can be disambiguated using neon_select_shape, except cases 1/9
14778 and 3/11 which depend on the operand type too.
5f4273c7 14779
5287ad62 14780 All the encoded bits are hardcoded by this function.
5f4273c7 14781
b7fc2769
JB
14782 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14783 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 14784
5287ad62 14785 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 14786 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
14787
14788static void
14789do_neon_mov (void)
14790{
037e8744
JB
14791 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14792 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14793 NS_NULL);
14794 struct neon_type_el et;
14795 const char *ldconst = 0;
5287ad62 14796
037e8744 14797 switch (rs)
5287ad62 14798 {
037e8744
JB
14799 case NS_DD: /* case 1/9. */
14800 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14801 /* It is not an error here if no type is given. */
14802 inst.error = NULL;
14803 if (et.type == NT_float && et.size == 64)
5287ad62 14804 {
037e8744
JB
14805 do_vfp_nsyn_opcode ("fcpyd");
14806 break;
5287ad62 14807 }
037e8744 14808 /* fall through. */
5287ad62 14809
037e8744
JB
14810 case NS_QQ: /* case 0/1. */
14811 {
14812 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14813 return;
14814 /* The architecture manual I have doesn't explicitly state which
14815 value the U bit should have for register->register moves, but
14816 the equivalent VORR instruction has U = 0, so do that. */
14817 inst.instruction = 0x0200110;
14818 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14819 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14820 inst.instruction |= LOW4 (inst.operands[1].reg);
14821 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14822 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14823 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14824 inst.instruction |= neon_quad (rs) << 6;
14825
88714cb8 14826 neon_dp_fixup (&inst);
037e8744
JB
14827 }
14828 break;
5f4273c7 14829
037e8744
JB
14830 case NS_DI: /* case 3/11. */
14831 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14832 inst.error = NULL;
14833 if (et.type == NT_float && et.size == 64)
5287ad62 14834 {
037e8744
JB
14835 /* case 11 (fconstd). */
14836 ldconst = "fconstd";
14837 goto encode_fconstd;
5287ad62 14838 }
037e8744
JB
14839 /* fall through. */
14840
14841 case NS_QI: /* case 2/3. */
14842 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14843 return;
14844 inst.instruction = 0x0800010;
14845 neon_move_immediate ();
88714cb8 14846 neon_dp_fixup (&inst);
5287ad62 14847 break;
5f4273c7 14848
037e8744
JB
14849 case NS_SR: /* case 4. */
14850 {
14851 unsigned bcdebits = 0;
91d6fa6a 14852 int logsize;
037e8744
JB
14853 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14854 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14855
91d6fa6a
NC
14856 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14857 logsize = neon_logbits (et.size);
14858
037e8744
JB
14859 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14860 _(BAD_FPU));
14861 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14862 && et.size != 32, _(BAD_FPU));
14863 constraint (et.type == NT_invtype, _("bad type for scalar"));
14864 constraint (x >= 64 / et.size, _("scalar index out of range"));
14865
14866 switch (et.size)
14867 {
14868 case 8: bcdebits = 0x8; break;
14869 case 16: bcdebits = 0x1; break;
14870 case 32: bcdebits = 0x0; break;
14871 default: ;
14872 }
14873
14874 bcdebits |= x << logsize;
14875
14876 inst.instruction = 0xe000b10;
14877 do_vfp_cond_or_thumb ();
14878 inst.instruction |= LOW4 (dn) << 16;
14879 inst.instruction |= HI1 (dn) << 7;
14880 inst.instruction |= inst.operands[1].reg << 12;
14881 inst.instruction |= (bcdebits & 3) << 5;
14882 inst.instruction |= (bcdebits >> 2) << 21;
14883 }
14884 break;
5f4273c7 14885
037e8744 14886 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 14887 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 14888 _(BAD_FPU));
b7fc2769 14889
037e8744
JB
14890 inst.instruction = 0xc400b10;
14891 do_vfp_cond_or_thumb ();
14892 inst.instruction |= LOW4 (inst.operands[0].reg);
14893 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14894 inst.instruction |= inst.operands[1].reg << 12;
14895 inst.instruction |= inst.operands[2].reg << 16;
14896 break;
5f4273c7 14897
037e8744
JB
14898 case NS_RS: /* case 6. */
14899 {
91d6fa6a 14900 unsigned logsize;
037e8744
JB
14901 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14902 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14903 unsigned abcdebits = 0;
14904
91d6fa6a
NC
14905 et = neon_check_type (2, NS_NULL,
14906 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14907 logsize = neon_logbits (et.size);
14908
037e8744
JB
14909 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14910 _(BAD_FPU));
14911 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14912 && et.size != 32, _(BAD_FPU));
14913 constraint (et.type == NT_invtype, _("bad type for scalar"));
14914 constraint (x >= 64 / et.size, _("scalar index out of range"));
14915
14916 switch (et.size)
14917 {
14918 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14919 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14920 case 32: abcdebits = 0x00; break;
14921 default: ;
14922 }
14923
14924 abcdebits |= x << logsize;
14925 inst.instruction = 0xe100b10;
14926 do_vfp_cond_or_thumb ();
14927 inst.instruction |= LOW4 (dn) << 16;
14928 inst.instruction |= HI1 (dn) << 7;
14929 inst.instruction |= inst.operands[0].reg << 12;
14930 inst.instruction |= (abcdebits & 3) << 5;
14931 inst.instruction |= (abcdebits >> 2) << 21;
14932 }
14933 break;
5f4273c7 14934
037e8744
JB
14935 case NS_RRD: /* case 7 (fmrrd). */
14936 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14937 _(BAD_FPU));
14938
14939 inst.instruction = 0xc500b10;
14940 do_vfp_cond_or_thumb ();
14941 inst.instruction |= inst.operands[0].reg << 12;
14942 inst.instruction |= inst.operands[1].reg << 16;
14943 inst.instruction |= LOW4 (inst.operands[2].reg);
14944 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14945 break;
5f4273c7 14946
037e8744
JB
14947 case NS_FF: /* case 8 (fcpys). */
14948 do_vfp_nsyn_opcode ("fcpys");
14949 break;
5f4273c7 14950
037e8744
JB
14951 case NS_FI: /* case 10 (fconsts). */
14952 ldconst = "fconsts";
14953 encode_fconstd:
14954 if (is_quarter_float (inst.operands[1].imm))
5287ad62 14955 {
037e8744
JB
14956 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14957 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
14958 }
14959 else
037e8744
JB
14960 first_error (_("immediate out of range"));
14961 break;
5f4273c7 14962
037e8744
JB
14963 case NS_RF: /* case 12 (fmrs). */
14964 do_vfp_nsyn_opcode ("fmrs");
14965 break;
5f4273c7 14966
037e8744
JB
14967 case NS_FR: /* case 13 (fmsr). */
14968 do_vfp_nsyn_opcode ("fmsr");
14969 break;
5f4273c7 14970
037e8744
JB
14971 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14972 (one of which is a list), but we have parsed four. Do some fiddling to
14973 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14974 expect. */
14975 case NS_RRFF: /* case 14 (fmrrs). */
14976 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14977 _("VFP registers must be adjacent"));
14978 inst.operands[2].imm = 2;
14979 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14980 do_vfp_nsyn_opcode ("fmrrs");
14981 break;
5f4273c7 14982
037e8744
JB
14983 case NS_FFRR: /* case 15 (fmsrr). */
14984 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14985 _("VFP registers must be adjacent"));
14986 inst.operands[1] = inst.operands[2];
14987 inst.operands[2] = inst.operands[3];
14988 inst.operands[0].imm = 2;
14989 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14990 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 14991 break;
5f4273c7 14992
5287ad62
JB
14993 default:
14994 abort ();
14995 }
14996}
14997
14998static void
14999do_neon_rshift_round_imm (void)
15000{
037e8744 15001 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15002 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
15003 int imm = inst.operands[2].imm;
15004
15005 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
15006 if (imm == 0)
15007 {
15008 inst.operands[2].present = 0;
15009 do_neon_mov ();
15010 return;
15011 }
15012
15013 constraint (imm < 1 || (unsigned)imm > et.size,
15014 _("immediate out of range for shift"));
037e8744 15015 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
15016 et.size - imm);
15017}
15018
15019static void
15020do_neon_movl (void)
15021{
15022 struct neon_type_el et = neon_check_type (2, NS_QD,
15023 N_EQK | N_DBL, N_SU_32 | N_KEY);
15024 unsigned sizebits = et.size >> 3;
15025 inst.instruction |= sizebits << 19;
15026 neon_two_same (0, et.type == NT_unsigned, -1);
15027}
15028
15029static void
15030do_neon_trn (void)
15031{
037e8744 15032 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15033 struct neon_type_el et = neon_check_type (2, rs,
15034 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 15035 NEON_ENCODE (INTEGER, inst);
037e8744 15036 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15037}
15038
15039static void
15040do_neon_zip_uzp (void)
15041{
037e8744 15042 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15043 struct neon_type_el et = neon_check_type (2, rs,
15044 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15045 if (rs == NS_DD && et.size == 32)
15046 {
15047 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
15048 inst.instruction = N_MNEM_vtrn;
15049 do_neon_trn ();
15050 return;
15051 }
037e8744 15052 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15053}
15054
15055static void
15056do_neon_sat_abs_neg (void)
15057{
037e8744 15058 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15059 struct neon_type_el et = neon_check_type (2, rs,
15060 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 15061 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15062}
15063
15064static void
15065do_neon_pair_long (void)
15066{
037e8744 15067 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15068 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
15069 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
15070 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 15071 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15072}
15073
15074static void
15075do_neon_recip_est (void)
15076{
037e8744 15077 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15078 struct neon_type_el et = neon_check_type (2, rs,
15079 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
15080 inst.instruction |= (et.type == NT_float) << 8;
037e8744 15081 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15082}
15083
15084static void
15085do_neon_cls (void)
15086{
037e8744 15087 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15088 struct neon_type_el et = neon_check_type (2, rs,
15089 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 15090 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15091}
15092
15093static void
15094do_neon_clz (void)
15095{
037e8744 15096 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15097 struct neon_type_el et = neon_check_type (2, rs,
15098 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 15099 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15100}
15101
15102static void
15103do_neon_cnt (void)
15104{
037e8744 15105 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15106 struct neon_type_el et = neon_check_type (2, rs,
15107 N_EQK | N_INT, N_8 | N_KEY);
037e8744 15108 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15109}
15110
15111static void
15112do_neon_swp (void)
15113{
037e8744
JB
15114 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15115 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
15116}
15117
15118static void
15119do_neon_tbl_tbx (void)
15120{
15121 unsigned listlenbits;
dcbf9037 15122 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 15123
5287ad62
JB
15124 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
15125 {
dcbf9037 15126 first_error (_("bad list length for table lookup"));
5287ad62
JB
15127 return;
15128 }
5f4273c7 15129
5287ad62
JB
15130 listlenbits = inst.operands[1].imm - 1;
15131 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15132 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15133 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15134 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15135 inst.instruction |= LOW4 (inst.operands[2].reg);
15136 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15137 inst.instruction |= listlenbits << 8;
5f4273c7 15138
88714cb8 15139 neon_dp_fixup (&inst);
5287ad62
JB
15140}
15141
15142static void
15143do_neon_ldm_stm (void)
15144{
15145 /* P, U and L bits are part of bitmask. */
15146 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
15147 unsigned offsetbits = inst.operands[1].imm * 2;
15148
037e8744
JB
15149 if (inst.operands[1].issingle)
15150 {
15151 do_vfp_nsyn_ldm_stm (is_dbmode);
15152 return;
15153 }
15154
5287ad62
JB
15155 constraint (is_dbmode && !inst.operands[0].writeback,
15156 _("writeback (!) must be used for VLDMDB and VSTMDB"));
15157
15158 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15159 _("register list must contain at least 1 and at most 16 "
15160 "registers"));
15161
15162 inst.instruction |= inst.operands[0].reg << 16;
15163 inst.instruction |= inst.operands[0].writeback << 21;
15164 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15165 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
15166
15167 inst.instruction |= offsetbits;
5f4273c7 15168
037e8744 15169 do_vfp_cond_or_thumb ();
5287ad62
JB
15170}
15171
15172static void
15173do_neon_ldr_str (void)
15174{
5287ad62 15175 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 15176
6844b2c2
MGD
15177 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
15178 And is UNPREDICTABLE in thumb mode. */
15179 if (!is_ldr
15180 && inst.operands[1].reg == REG_PC
15181 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
15182 {
15183 if (!thumb_mode && warn_on_deprecated)
15184 as_warn (_("Use of PC here is deprecated"));
15185 else
15186 inst.error = _("Use of PC here is UNPREDICTABLE");
15187 }
15188
037e8744
JB
15189 if (inst.operands[0].issingle)
15190 {
cd2f129f
JB
15191 if (is_ldr)
15192 do_vfp_nsyn_opcode ("flds");
15193 else
15194 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
15195 }
15196 else
5287ad62 15197 {
cd2f129f
JB
15198 if (is_ldr)
15199 do_vfp_nsyn_opcode ("fldd");
5287ad62 15200 else
cd2f129f 15201 do_vfp_nsyn_opcode ("fstd");
5287ad62 15202 }
5287ad62
JB
15203}
15204
15205/* "interleave" version also handles non-interleaving register VLD1/VST1
15206 instructions. */
15207
15208static void
15209do_neon_ld_st_interleave (void)
15210{
037e8744 15211 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
15212 N_8 | N_16 | N_32 | N_64);
15213 unsigned alignbits = 0;
15214 unsigned idx;
15215 /* The bits in this table go:
15216 0: register stride of one (0) or two (1)
15217 1,2: register list length, minus one (1, 2, 3, 4).
15218 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
15219 We use -1 for invalid entries. */
15220 const int typetable[] =
15221 {
15222 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
15223 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
15224 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
15225 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
15226 };
15227 int typebits;
15228
dcbf9037
JB
15229 if (et.type == NT_invtype)
15230 return;
15231
5287ad62
JB
15232 if (inst.operands[1].immisalign)
15233 switch (inst.operands[1].imm >> 8)
15234 {
15235 case 64: alignbits = 1; break;
15236 case 128:
e23c0ad8
JZ
15237 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
15238 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
15239 goto bad_alignment;
15240 alignbits = 2;
15241 break;
15242 case 256:
e23c0ad8 15243 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
15244 goto bad_alignment;
15245 alignbits = 3;
15246 break;
15247 default:
15248 bad_alignment:
dcbf9037 15249 first_error (_("bad alignment"));
5287ad62
JB
15250 return;
15251 }
15252
15253 inst.instruction |= alignbits << 4;
15254 inst.instruction |= neon_logbits (et.size) << 6;
15255
15256 /* Bits [4:6] of the immediate in a list specifier encode register stride
15257 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
15258 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
15259 up the right value for "type" in a table based on this value and the given
15260 list style, then stick it back. */
15261 idx = ((inst.operands[0].imm >> 4) & 7)
15262 | (((inst.instruction >> 8) & 3) << 3);
15263
15264 typebits = typetable[idx];
5f4273c7 15265
5287ad62
JB
15266 constraint (typebits == -1, _("bad list type for instruction"));
15267
15268 inst.instruction &= ~0xf00;
15269 inst.instruction |= typebits << 8;
15270}
15271
15272/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
15273 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
15274 otherwise. The variable arguments are a list of pairs of legal (size, align)
15275 values, terminated with -1. */
15276
15277static int
15278neon_alignment_bit (int size, int align, int *do_align, ...)
15279{
15280 va_list ap;
15281 int result = FAIL, thissize, thisalign;
5f4273c7 15282
5287ad62
JB
15283 if (!inst.operands[1].immisalign)
15284 {
15285 *do_align = 0;
15286 return SUCCESS;
15287 }
5f4273c7 15288
5287ad62
JB
15289 va_start (ap, do_align);
15290
15291 do
15292 {
15293 thissize = va_arg (ap, int);
15294 if (thissize == -1)
15295 break;
15296 thisalign = va_arg (ap, int);
15297
15298 if (size == thissize && align == thisalign)
15299 result = SUCCESS;
15300 }
15301 while (result != SUCCESS);
15302
15303 va_end (ap);
15304
15305 if (result == SUCCESS)
15306 *do_align = 1;
15307 else
dcbf9037 15308 first_error (_("unsupported alignment for instruction"));
5f4273c7 15309
5287ad62
JB
15310 return result;
15311}
15312
15313static void
15314do_neon_ld_st_lane (void)
15315{
037e8744 15316 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15317 int align_good, do_align = 0;
15318 int logsize = neon_logbits (et.size);
15319 int align = inst.operands[1].imm >> 8;
15320 int n = (inst.instruction >> 8) & 3;
15321 int max_el = 64 / et.size;
5f4273c7 15322
dcbf9037
JB
15323 if (et.type == NT_invtype)
15324 return;
5f4273c7 15325
5287ad62
JB
15326 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
15327 _("bad list length"));
15328 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
15329 _("scalar index out of range"));
15330 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
15331 && et.size == 8,
15332 _("stride of 2 unavailable when element size is 8"));
5f4273c7 15333
5287ad62
JB
15334 switch (n)
15335 {
15336 case 0: /* VLD1 / VST1. */
15337 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
15338 32, 32, -1);
15339 if (align_good == FAIL)
15340 return;
15341 if (do_align)
15342 {
15343 unsigned alignbits = 0;
15344 switch (et.size)
15345 {
15346 case 16: alignbits = 0x1; break;
15347 case 32: alignbits = 0x3; break;
15348 default: ;
15349 }
15350 inst.instruction |= alignbits << 4;
15351 }
15352 break;
15353
15354 case 1: /* VLD2 / VST2. */
15355 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
15356 32, 64, -1);
15357 if (align_good == FAIL)
15358 return;
15359 if (do_align)
15360 inst.instruction |= 1 << 4;
15361 break;
15362
15363 case 2: /* VLD3 / VST3. */
15364 constraint (inst.operands[1].immisalign,
15365 _("can't use alignment with this instruction"));
15366 break;
15367
15368 case 3: /* VLD4 / VST4. */
15369 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15370 16, 64, 32, 64, 32, 128, -1);
15371 if (align_good == FAIL)
15372 return;
15373 if (do_align)
15374 {
15375 unsigned alignbits = 0;
15376 switch (et.size)
15377 {
15378 case 8: alignbits = 0x1; break;
15379 case 16: alignbits = 0x1; break;
15380 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
15381 default: ;
15382 }
15383 inst.instruction |= alignbits << 4;
15384 }
15385 break;
15386
15387 default: ;
15388 }
15389
15390 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
15391 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15392 inst.instruction |= 1 << (4 + logsize);
5f4273c7 15393
5287ad62
JB
15394 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
15395 inst.instruction |= logsize << 10;
15396}
15397
15398/* Encode single n-element structure to all lanes VLD<n> instructions. */
15399
15400static void
15401do_neon_ld_dup (void)
15402{
037e8744 15403 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15404 int align_good, do_align = 0;
15405
dcbf9037
JB
15406 if (et.type == NT_invtype)
15407 return;
15408
5287ad62
JB
15409 switch ((inst.instruction >> 8) & 3)
15410 {
15411 case 0: /* VLD1. */
9c2799c2 15412 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
15413 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15414 &do_align, 16, 16, 32, 32, -1);
15415 if (align_good == FAIL)
15416 return;
15417 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15418 {
15419 case 1: break;
15420 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 15421 default: first_error (_("bad list length")); return;
5287ad62
JB
15422 }
15423 inst.instruction |= neon_logbits (et.size) << 6;
15424 break;
15425
15426 case 1: /* VLD2. */
15427 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15428 &do_align, 8, 16, 16, 32, 32, 64, -1);
15429 if (align_good == FAIL)
15430 return;
15431 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15432 _("bad list length"));
15433 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15434 inst.instruction |= 1 << 5;
15435 inst.instruction |= neon_logbits (et.size) << 6;
15436 break;
15437
15438 case 2: /* VLD3. */
15439 constraint (inst.operands[1].immisalign,
15440 _("can't use alignment with this instruction"));
15441 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15442 _("bad list length"));
15443 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15444 inst.instruction |= 1 << 5;
15445 inst.instruction |= neon_logbits (et.size) << 6;
15446 break;
15447
15448 case 3: /* VLD4. */
15449 {
15450 int align = inst.operands[1].imm >> 8;
15451 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15452 16, 64, 32, 64, 32, 128, -1);
15453 if (align_good == FAIL)
15454 return;
15455 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15456 _("bad list length"));
15457 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15458 inst.instruction |= 1 << 5;
15459 if (et.size == 32 && align == 128)
15460 inst.instruction |= 0x3 << 6;
15461 else
15462 inst.instruction |= neon_logbits (et.size) << 6;
15463 }
15464 break;
15465
15466 default: ;
15467 }
15468
15469 inst.instruction |= do_align << 4;
15470}
15471
15472/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15473 apart from bits [11:4]. */
15474
15475static void
15476do_neon_ldx_stx (void)
15477{
b1a769ed
DG
15478 if (inst.operands[1].isreg)
15479 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15480
5287ad62
JB
15481 switch (NEON_LANE (inst.operands[0].imm))
15482 {
15483 case NEON_INTERLEAVE_LANES:
88714cb8 15484 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
15485 do_neon_ld_st_interleave ();
15486 break;
5f4273c7 15487
5287ad62 15488 case NEON_ALL_LANES:
88714cb8 15489 NEON_ENCODE (DUP, inst);
5287ad62
JB
15490 do_neon_ld_dup ();
15491 break;
5f4273c7 15492
5287ad62 15493 default:
88714cb8 15494 NEON_ENCODE (LANE, inst);
5287ad62
JB
15495 do_neon_ld_st_lane ();
15496 }
15497
15498 /* L bit comes from bit mask. */
15499 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15500 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15501 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 15502
5287ad62
JB
15503 if (inst.operands[1].postind)
15504 {
15505 int postreg = inst.operands[1].imm & 0xf;
15506 constraint (!inst.operands[1].immisreg,
15507 _("post-index must be a register"));
15508 constraint (postreg == 0xd || postreg == 0xf,
15509 _("bad register for post-index"));
15510 inst.instruction |= postreg;
15511 }
15512 else if (inst.operands[1].writeback)
15513 {
15514 inst.instruction |= 0xd;
15515 }
15516 else
5f4273c7
NC
15517 inst.instruction |= 0xf;
15518
5287ad62
JB
15519 if (thumb_mode)
15520 inst.instruction |= 0xf9000000;
15521 else
15522 inst.instruction |= 0xf4000000;
15523}
5287ad62
JB
15524\f
15525/* Overall per-instruction processing. */
15526
15527/* We need to be able to fix up arbitrary expressions in some statements.
15528 This is so that we can handle symbols that are an arbitrary distance from
15529 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
15530 which returns part of an address in a form which will be valid for
15531 a data instruction. We do this by pushing the expression into a symbol
15532 in the expr_section, and creating a fix for that. */
15533
15534static void
15535fix_new_arm (fragS * frag,
15536 int where,
15537 short int size,
15538 expressionS * exp,
15539 int pc_rel,
15540 int reloc)
15541{
15542 fixS * new_fix;
15543
15544 switch (exp->X_op)
15545 {
15546 case O_constant:
6e7ce2cd
PB
15547 if (pc_rel)
15548 {
15549 /* Create an absolute valued symbol, so we have something to
15550 refer to in the object file. Unfortunately for us, gas's
15551 generic expression parsing will already have folded out
15552 any use of .set foo/.type foo %function that may have
15553 been used to set type information of the target location,
15554 that's being specified symbolically. We have to presume
15555 the user knows what they are doing. */
15556 char name[16 + 8];
15557 symbolS *symbol;
15558
15559 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
15560
15561 symbol = symbol_find_or_make (name);
15562 S_SET_SEGMENT (symbol, absolute_section);
15563 symbol_set_frag (symbol, &zero_address_frag);
15564 S_SET_VALUE (symbol, exp->X_add_number);
15565 exp->X_op = O_symbol;
15566 exp->X_add_symbol = symbol;
15567 exp->X_add_number = 0;
15568 }
15569 /* FALLTHROUGH */
5287ad62
JB
15570 case O_symbol:
15571 case O_add:
15572 case O_subtract:
21d799b5
NC
15573 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
15574 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15575 break;
15576
15577 default:
21d799b5
NC
15578 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
15579 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15580 break;
15581 }
15582
15583 /* Mark whether the fix is to a THUMB instruction, or an ARM
15584 instruction. */
15585 new_fix->tc_fix_data = thumb_mode;
15586}
15587
15588/* Create a frg for an instruction requiring relaxation. */
15589static void
15590output_relax_insn (void)
15591{
15592 char * to;
15593 symbolS *sym;
0110f2b8
PB
15594 int offset;
15595
6e1cb1a6
PB
15596 /* The size of the instruction is unknown, so tie the debug info to the
15597 start of the instruction. */
15598 dwarf2_emit_insn (0);
6e1cb1a6 15599
0110f2b8
PB
15600 switch (inst.reloc.exp.X_op)
15601 {
15602 case O_symbol:
15603 sym = inst.reloc.exp.X_add_symbol;
15604 offset = inst.reloc.exp.X_add_number;
15605 break;
15606 case O_constant:
15607 sym = NULL;
15608 offset = inst.reloc.exp.X_add_number;
15609 break;
15610 default:
15611 sym = make_expr_symbol (&inst.reloc.exp);
15612 offset = 0;
15613 break;
15614 }
15615 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15616 inst.relax, sym, offset, NULL/*offset, opcode*/);
15617 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
15618}
15619
15620/* Write a 32-bit thumb instruction to buf. */
15621static void
15622put_thumb32_insn (char * buf, unsigned long insn)
15623{
15624 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15625 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15626}
15627
b99bd4ef 15628static void
c19d1205 15629output_inst (const char * str)
b99bd4ef 15630{
c19d1205 15631 char * to = NULL;
b99bd4ef 15632
c19d1205 15633 if (inst.error)
b99bd4ef 15634 {
c19d1205 15635 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
15636 return;
15637 }
5f4273c7
NC
15638 if (inst.relax)
15639 {
15640 output_relax_insn ();
0110f2b8 15641 return;
5f4273c7 15642 }
c19d1205
ZW
15643 if (inst.size == 0)
15644 return;
b99bd4ef 15645
c19d1205 15646 to = frag_more (inst.size);
8dc2430f
NC
15647 /* PR 9814: Record the thumb mode into the current frag so that we know
15648 what type of NOP padding to use, if necessary. We override any previous
15649 setting so that if the mode has changed then the NOPS that we use will
15650 match the encoding of the last instruction in the frag. */
cd000bff 15651 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
15652
15653 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 15654 {
9c2799c2 15655 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 15656 put_thumb32_insn (to, inst.instruction);
b99bd4ef 15657 }
c19d1205 15658 else if (inst.size > INSN_SIZE)
b99bd4ef 15659 {
9c2799c2 15660 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
15661 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15662 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 15663 }
c19d1205
ZW
15664 else
15665 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 15666
c19d1205
ZW
15667 if (inst.reloc.type != BFD_RELOC_UNUSED)
15668 fix_new_arm (frag_now, to - frag_now->fr_literal,
15669 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15670 inst.reloc.type);
b99bd4ef 15671
c19d1205 15672 dwarf2_emit_insn (inst.size);
c19d1205 15673}
b99bd4ef 15674
e07e6e58
NC
15675static char *
15676output_it_inst (int cond, int mask, char * to)
15677{
15678 unsigned long instruction = 0xbf00;
15679
15680 mask &= 0xf;
15681 instruction |= mask;
15682 instruction |= cond << 4;
15683
15684 if (to == NULL)
15685 {
15686 to = frag_more (2);
15687#ifdef OBJ_ELF
15688 dwarf2_emit_insn (2);
15689#endif
15690 }
15691
15692 md_number_to_chars (to, instruction, 2);
15693
15694 return to;
15695}
15696
c19d1205
ZW
15697/* Tag values used in struct asm_opcode's tag field. */
15698enum opcode_tag
15699{
15700 OT_unconditional, /* Instruction cannot be conditionalized.
15701 The ARM condition field is still 0xE. */
15702 OT_unconditionalF, /* Instruction cannot be conditionalized
15703 and carries 0xF in its ARM condition field. */
15704 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
15705 OT_csuffixF, /* Some forms of the instruction take a conditional
15706 suffix, others place 0xF where the condition field
15707 would be. */
c19d1205
ZW
15708 OT_cinfix3, /* Instruction takes a conditional infix,
15709 beginning at character index 3. (In
15710 unified mode, it becomes a suffix.) */
088fa78e
KH
15711 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15712 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
15713 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15714 character index 3, even in unified mode. Used for
15715 legacy instructions where suffix and infix forms
15716 may be ambiguous. */
c19d1205 15717 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 15718 suffix or an infix at character index 3. */
c19d1205
ZW
15719 OT_odd_infix_unc, /* This is the unconditional variant of an
15720 instruction that takes a conditional infix
15721 at an unusual position. In unified mode,
15722 this variant will accept a suffix. */
15723 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15724 are the conditional variants of instructions that
15725 take conditional infixes in unusual positions.
15726 The infix appears at character index
15727 (tag - OT_odd_infix_0). These are not accepted
15728 in unified mode. */
15729};
b99bd4ef 15730
c19d1205
ZW
15731/* Subroutine of md_assemble, responsible for looking up the primary
15732 opcode from the mnemonic the user wrote. STR points to the
15733 beginning of the mnemonic.
15734
15735 This is not simply a hash table lookup, because of conditional
15736 variants. Most instructions have conditional variants, which are
15737 expressed with a _conditional affix_ to the mnemonic. If we were
15738 to encode each conditional variant as a literal string in the opcode
15739 table, it would have approximately 20,000 entries.
15740
15741 Most mnemonics take this affix as a suffix, and in unified syntax,
15742 'most' is upgraded to 'all'. However, in the divided syntax, some
15743 instructions take the affix as an infix, notably the s-variants of
15744 the arithmetic instructions. Of those instructions, all but six
15745 have the infix appear after the third character of the mnemonic.
15746
15747 Accordingly, the algorithm for looking up primary opcodes given
15748 an identifier is:
15749
15750 1. Look up the identifier in the opcode table.
15751 If we find a match, go to step U.
15752
15753 2. Look up the last two characters of the identifier in the
15754 conditions table. If we find a match, look up the first N-2
15755 characters of the identifier in the opcode table. If we
15756 find a match, go to step CE.
15757
15758 3. Look up the fourth and fifth characters of the identifier in
15759 the conditions table. If we find a match, extract those
15760 characters from the identifier, and look up the remaining
15761 characters in the opcode table. If we find a match, go
15762 to step CM.
15763
15764 4. Fail.
15765
15766 U. Examine the tag field of the opcode structure, in case this is
15767 one of the six instructions with its conditional infix in an
15768 unusual place. If it is, the tag tells us where to find the
15769 infix; look it up in the conditions table and set inst.cond
15770 accordingly. Otherwise, this is an unconditional instruction.
15771 Again set inst.cond accordingly. Return the opcode structure.
15772
15773 CE. Examine the tag field to make sure this is an instruction that
15774 should receive a conditional suffix. If it is not, fail.
15775 Otherwise, set inst.cond from the suffix we already looked up,
15776 and return the opcode structure.
15777
15778 CM. Examine the tag field to make sure this is an instruction that
15779 should receive a conditional infix after the third character.
15780 If it is not, fail. Otherwise, undo the edits to the current
15781 line of input and proceed as for case CE. */
15782
15783static const struct asm_opcode *
15784opcode_lookup (char **str)
15785{
15786 char *end, *base;
15787 char *affix;
15788 const struct asm_opcode *opcode;
15789 const struct asm_cond *cond;
e3cb604e 15790 char save[2];
c19d1205
ZW
15791
15792 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 15793 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 15794 for (base = end = *str; *end != '\0'; end++)
721a8186 15795 if (*end == ' ' || *end == '.')
c19d1205 15796 break;
b99bd4ef 15797
c19d1205 15798 if (end == base)
c921be7d 15799 return NULL;
b99bd4ef 15800
5287ad62 15801 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 15802 if (end[0] == '.')
b99bd4ef 15803 {
5287ad62 15804 int offset = 2;
5f4273c7 15805
267d2029
JB
15806 /* The .w and .n suffixes are only valid if the unified syntax is in
15807 use. */
15808 if (unified_syntax && end[1] == 'w')
c19d1205 15809 inst.size_req = 4;
267d2029 15810 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
15811 inst.size_req = 2;
15812 else
5287ad62
JB
15813 offset = 0;
15814
15815 inst.vectype.elems = 0;
15816
15817 *str = end + offset;
b99bd4ef 15818
5f4273c7 15819 if (end[offset] == '.')
5287ad62 15820 {
267d2029
JB
15821 /* See if we have a Neon type suffix (possible in either unified or
15822 non-unified ARM syntax mode). */
dcbf9037 15823 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 15824 return NULL;
5287ad62
JB
15825 }
15826 else if (end[offset] != '\0' && end[offset] != ' ')
c921be7d 15827 return NULL;
b99bd4ef 15828 }
c19d1205
ZW
15829 else
15830 *str = end;
b99bd4ef 15831
c19d1205 15832 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5
NC
15833 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15834 end - base);
c19d1205 15835 if (opcode)
b99bd4ef 15836 {
c19d1205
ZW
15837 /* step U */
15838 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 15839 {
c19d1205
ZW
15840 inst.cond = COND_ALWAYS;
15841 return opcode;
b99bd4ef 15842 }
b99bd4ef 15843
278df34e 15844 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
15845 as_warn (_("conditional infixes are deprecated in unified syntax"));
15846 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 15847 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 15848 gas_assert (cond);
b99bd4ef 15849
c19d1205
ZW
15850 inst.cond = cond->value;
15851 return opcode;
15852 }
b99bd4ef 15853
c19d1205
ZW
15854 /* Cannot have a conditional suffix on a mnemonic of less than two
15855 characters. */
15856 if (end - base < 3)
c921be7d 15857 return NULL;
b99bd4ef 15858
c19d1205
ZW
15859 /* Look for suffixed mnemonic. */
15860 affix = end - 2;
21d799b5
NC
15861 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15862 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15863 affix - base);
c19d1205
ZW
15864 if (opcode && cond)
15865 {
15866 /* step CE */
15867 switch (opcode->tag)
15868 {
e3cb604e
PB
15869 case OT_cinfix3_legacy:
15870 /* Ignore conditional suffixes matched on infix only mnemonics. */
15871 break;
15872
c19d1205 15873 case OT_cinfix3:
088fa78e 15874 case OT_cinfix3_deprecated:
c19d1205
ZW
15875 case OT_odd_infix_unc:
15876 if (!unified_syntax)
e3cb604e 15877 return 0;
c19d1205
ZW
15878 /* else fall through */
15879
15880 case OT_csuffix:
037e8744 15881 case OT_csuffixF:
c19d1205
ZW
15882 case OT_csuf_or_in3:
15883 inst.cond = cond->value;
15884 return opcode;
15885
15886 case OT_unconditional:
15887 case OT_unconditionalF:
dfa9f0d5 15888 if (thumb_mode)
c921be7d 15889 inst.cond = cond->value;
dfa9f0d5
PB
15890 else
15891 {
c921be7d 15892 /* Delayed diagnostic. */
dfa9f0d5
PB
15893 inst.error = BAD_COND;
15894 inst.cond = COND_ALWAYS;
15895 }
c19d1205 15896 return opcode;
b99bd4ef 15897
c19d1205 15898 default:
c921be7d 15899 return NULL;
c19d1205
ZW
15900 }
15901 }
b99bd4ef 15902
c19d1205
ZW
15903 /* Cannot have a usual-position infix on a mnemonic of less than
15904 six characters (five would be a suffix). */
15905 if (end - base < 6)
c921be7d 15906 return NULL;
b99bd4ef 15907
c19d1205
ZW
15908 /* Look for infixed mnemonic in the usual position. */
15909 affix = base + 3;
21d799b5 15910 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 15911 if (!cond)
c921be7d 15912 return NULL;
e3cb604e
PB
15913
15914 memcpy (save, affix, 2);
15915 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5
NC
15916 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15917 (end - base) - 2);
e3cb604e
PB
15918 memmove (affix + 2, affix, (end - affix) - 2);
15919 memcpy (affix, save, 2);
15920
088fa78e
KH
15921 if (opcode
15922 && (opcode->tag == OT_cinfix3
15923 || opcode->tag == OT_cinfix3_deprecated
15924 || opcode->tag == OT_csuf_or_in3
15925 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 15926 {
c921be7d 15927 /* Step CM. */
278df34e 15928 if (warn_on_deprecated && unified_syntax
088fa78e
KH
15929 && (opcode->tag == OT_cinfix3
15930 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
15931 as_warn (_("conditional infixes are deprecated in unified syntax"));
15932
15933 inst.cond = cond->value;
15934 return opcode;
b99bd4ef
NC
15935 }
15936
c921be7d 15937 return NULL;
b99bd4ef
NC
15938}
15939
e07e6e58
NC
15940/* This function generates an initial IT instruction, leaving its block
15941 virtually open for the new instructions. Eventually,
15942 the mask will be updated by now_it_add_mask () each time
15943 a new instruction needs to be included in the IT block.
15944 Finally, the block is closed with close_automatic_it_block ().
15945 The block closure can be requested either from md_assemble (),
15946 a tencode (), or due to a label hook. */
15947
15948static void
15949new_automatic_it_block (int cond)
15950{
15951 now_it.state = AUTOMATIC_IT_BLOCK;
15952 now_it.mask = 0x18;
15953 now_it.cc = cond;
15954 now_it.block_length = 1;
cd000bff 15955 mapping_state (MAP_THUMB);
e07e6e58
NC
15956 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15957}
15958
15959/* Close an automatic IT block.
15960 See comments in new_automatic_it_block (). */
15961
15962static void
15963close_automatic_it_block (void)
15964{
15965 now_it.mask = 0x10;
15966 now_it.block_length = 0;
15967}
15968
15969/* Update the mask of the current automatically-generated IT
15970 instruction. See comments in new_automatic_it_block (). */
15971
15972static void
15973now_it_add_mask (int cond)
15974{
15975#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15976#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15977 | ((bitvalue) << (nbit)))
e07e6e58 15978 const int resulting_bit = (cond & 1);
c921be7d 15979
e07e6e58
NC
15980 now_it.mask &= 0xf;
15981 now_it.mask = SET_BIT_VALUE (now_it.mask,
15982 resulting_bit,
15983 (5 - now_it.block_length));
15984 now_it.mask = SET_BIT_VALUE (now_it.mask,
15985 1,
15986 ((5 - now_it.block_length) - 1) );
15987 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15988
15989#undef CLEAR_BIT
15990#undef SET_BIT_VALUE
e07e6e58
NC
15991}
15992
15993/* The IT blocks handling machinery is accessed through the these functions:
15994 it_fsm_pre_encode () from md_assemble ()
15995 set_it_insn_type () optional, from the tencode functions
15996 set_it_insn_type_last () ditto
15997 in_it_block () ditto
15998 it_fsm_post_encode () from md_assemble ()
15999 force_automatic_it_block_close () from label habdling functions
16000
16001 Rationale:
16002 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
16003 initializing the IT insn type with a generic initial value depending
16004 on the inst.condition.
16005 2) During the tencode function, two things may happen:
16006 a) The tencode function overrides the IT insn type by
16007 calling either set_it_insn_type (type) or set_it_insn_type_last ().
16008 b) The tencode function queries the IT block state by
16009 calling in_it_block () (i.e. to determine narrow/not narrow mode).
16010
16011 Both set_it_insn_type and in_it_block run the internal FSM state
16012 handling function (handle_it_state), because: a) setting the IT insn
16013 type may incur in an invalid state (exiting the function),
16014 and b) querying the state requires the FSM to be updated.
16015 Specifically we want to avoid creating an IT block for conditional
16016 branches, so it_fsm_pre_encode is actually a guess and we can't
16017 determine whether an IT block is required until the tencode () routine
16018 has decided what type of instruction this actually it.
16019 Because of this, if set_it_insn_type and in_it_block have to be used,
16020 set_it_insn_type has to be called first.
16021
16022 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
16023 determines the insn IT type depending on the inst.cond code.
16024 When a tencode () routine encodes an instruction that can be
16025 either outside an IT block, or, in the case of being inside, has to be
16026 the last one, set_it_insn_type_last () will determine the proper
16027 IT instruction type based on the inst.cond code. Otherwise,
16028 set_it_insn_type can be called for overriding that logic or
16029 for covering other cases.
16030
16031 Calling handle_it_state () may not transition the IT block state to
16032 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
16033 still queried. Instead, if the FSM determines that the state should
16034 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
16035 after the tencode () function: that's what it_fsm_post_encode () does.
16036
16037 Since in_it_block () calls the state handling function to get an
16038 updated state, an error may occur (due to invalid insns combination).
16039 In that case, inst.error is set.
16040 Therefore, inst.error has to be checked after the execution of
16041 the tencode () routine.
16042
16043 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
16044 any pending state change (if any) that didn't take place in
16045 handle_it_state () as explained above. */
16046
16047static void
16048it_fsm_pre_encode (void)
16049{
16050 if (inst.cond != COND_ALWAYS)
16051 inst.it_insn_type = INSIDE_IT_INSN;
16052 else
16053 inst.it_insn_type = OUTSIDE_IT_INSN;
16054
16055 now_it.state_handled = 0;
16056}
16057
16058/* IT state FSM handling function. */
16059
16060static int
16061handle_it_state (void)
16062{
16063 now_it.state_handled = 1;
16064
16065 switch (now_it.state)
16066 {
16067 case OUTSIDE_IT_BLOCK:
16068 switch (inst.it_insn_type)
16069 {
16070 case OUTSIDE_IT_INSN:
16071 break;
16072
16073 case INSIDE_IT_INSN:
16074 case INSIDE_IT_LAST_INSN:
16075 if (thumb_mode == 0)
16076 {
c921be7d 16077 if (unified_syntax
e07e6e58
NC
16078 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
16079 as_tsktsk (_("Warning: conditional outside an IT block"\
16080 " for Thumb."));
16081 }
16082 else
16083 {
16084 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
16085 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
16086 {
16087 /* Automatically generate the IT instruction. */
16088 new_automatic_it_block (inst.cond);
16089 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
16090 close_automatic_it_block ();
16091 }
16092 else
16093 {
16094 inst.error = BAD_OUT_IT;
16095 return FAIL;
16096 }
16097 }
16098 break;
16099
16100 case IF_INSIDE_IT_LAST_INSN:
16101 case NEUTRAL_IT_INSN:
16102 break;
16103
16104 case IT_INSN:
16105 now_it.state = MANUAL_IT_BLOCK;
16106 now_it.block_length = 0;
16107 break;
16108 }
16109 break;
16110
16111 case AUTOMATIC_IT_BLOCK:
16112 /* Three things may happen now:
16113 a) We should increment current it block size;
16114 b) We should close current it block (closing insn or 4 insns);
16115 c) We should close current it block and start a new one (due
16116 to incompatible conditions or
16117 4 insns-length block reached). */
16118
16119 switch (inst.it_insn_type)
16120 {
16121 case OUTSIDE_IT_INSN:
16122 /* The closure of the block shall happen immediatelly,
16123 so any in_it_block () call reports the block as closed. */
16124 force_automatic_it_block_close ();
16125 break;
16126
16127 case INSIDE_IT_INSN:
16128 case INSIDE_IT_LAST_INSN:
16129 case IF_INSIDE_IT_LAST_INSN:
16130 now_it.block_length++;
16131
16132 if (now_it.block_length > 4
16133 || !now_it_compatible (inst.cond))
16134 {
16135 force_automatic_it_block_close ();
16136 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
16137 new_automatic_it_block (inst.cond);
16138 }
16139 else
16140 {
16141 now_it_add_mask (inst.cond);
16142 }
16143
16144 if (now_it.state == AUTOMATIC_IT_BLOCK
16145 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
16146 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
16147 close_automatic_it_block ();
16148 break;
16149
16150 case NEUTRAL_IT_INSN:
16151 now_it.block_length++;
16152
16153 if (now_it.block_length > 4)
16154 force_automatic_it_block_close ();
16155 else
16156 now_it_add_mask (now_it.cc & 1);
16157 break;
16158
16159 case IT_INSN:
16160 close_automatic_it_block ();
16161 now_it.state = MANUAL_IT_BLOCK;
16162 break;
16163 }
16164 break;
16165
16166 case MANUAL_IT_BLOCK:
16167 {
16168 /* Check conditional suffixes. */
16169 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
16170 int is_last;
16171 now_it.mask <<= 1;
16172 now_it.mask &= 0x1f;
16173 is_last = (now_it.mask == 0x10);
16174
16175 switch (inst.it_insn_type)
16176 {
16177 case OUTSIDE_IT_INSN:
16178 inst.error = BAD_NOT_IT;
16179 return FAIL;
16180
16181 case INSIDE_IT_INSN:
16182 if (cond != inst.cond)
16183 {
16184 inst.error = BAD_IT_COND;
16185 return FAIL;
16186 }
16187 break;
16188
16189 case INSIDE_IT_LAST_INSN:
16190 case IF_INSIDE_IT_LAST_INSN:
16191 if (cond != inst.cond)
16192 {
16193 inst.error = BAD_IT_COND;
16194 return FAIL;
16195 }
16196 if (!is_last)
16197 {
16198 inst.error = BAD_BRANCH;
16199 return FAIL;
16200 }
16201 break;
16202
16203 case NEUTRAL_IT_INSN:
16204 /* The BKPT instruction is unconditional even in an IT block. */
16205 break;
16206
16207 case IT_INSN:
16208 inst.error = BAD_IT_IT;
16209 return FAIL;
16210 }
16211 }
16212 break;
16213 }
16214
16215 return SUCCESS;
16216}
16217
16218static void
16219it_fsm_post_encode (void)
16220{
16221 int is_last;
16222
16223 if (!now_it.state_handled)
16224 handle_it_state ();
16225
16226 is_last = (now_it.mask == 0x10);
16227 if (is_last)
16228 {
16229 now_it.state = OUTSIDE_IT_BLOCK;
16230 now_it.mask = 0;
16231 }
16232}
16233
16234static void
16235force_automatic_it_block_close (void)
16236{
16237 if (now_it.state == AUTOMATIC_IT_BLOCK)
16238 {
16239 close_automatic_it_block ();
16240 now_it.state = OUTSIDE_IT_BLOCK;
16241 now_it.mask = 0;
16242 }
16243}
16244
16245static int
16246in_it_block (void)
16247{
16248 if (!now_it.state_handled)
16249 handle_it_state ();
16250
16251 return now_it.state != OUTSIDE_IT_BLOCK;
16252}
16253
c19d1205
ZW
16254void
16255md_assemble (char *str)
b99bd4ef 16256{
c19d1205
ZW
16257 char *p = str;
16258 const struct asm_opcode * opcode;
b99bd4ef 16259
c19d1205
ZW
16260 /* Align the previous label if needed. */
16261 if (last_label_seen != NULL)
b99bd4ef 16262 {
c19d1205
ZW
16263 symbol_set_frag (last_label_seen, frag_now);
16264 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
16265 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
16266 }
16267
c19d1205
ZW
16268 memset (&inst, '\0', sizeof (inst));
16269 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 16270
c19d1205
ZW
16271 opcode = opcode_lookup (&p);
16272 if (!opcode)
b99bd4ef 16273 {
c19d1205 16274 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 16275 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d
NC
16276 if (! create_register_alias (str, p)
16277 && ! create_neon_reg_alias (str, p))
c19d1205 16278 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 16279
b99bd4ef
NC
16280 return;
16281 }
16282
278df34e 16283 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
16284 as_warn (_("s suffix on comparison instruction is deprecated"));
16285
037e8744
JB
16286 /* The value which unconditional instructions should have in place of the
16287 condition field. */
16288 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
16289
c19d1205 16290 if (thumb_mode)
b99bd4ef 16291 {
e74cfd16 16292 arm_feature_set variant;
8f06b2d8
PB
16293
16294 variant = cpu_variant;
16295 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
16296 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
16297 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 16298 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
16299 if (!opcode->tvariant
16300 || (thumb_mode == 1
16301 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 16302 {
bf3eeda7 16303 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
b99bd4ef
NC
16304 return;
16305 }
c19d1205
ZW
16306 if (inst.cond != COND_ALWAYS && !unified_syntax
16307 && opcode->tencode != do_t_branch)
b99bd4ef 16308 {
c19d1205 16309 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
16310 return;
16311 }
16312
752d5da4 16313 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 16314 {
7e806470 16315 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
16316 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
16317 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
16318 {
16319 /* Two things are addressed here.
16320 1) Implicit require narrow instructions on Thumb-1.
16321 This avoids relaxation accidentally introducing Thumb-2
16322 instructions.
16323 2) Reject wide instructions in non Thumb-2 cores. */
16324 if (inst.size_req == 0)
16325 inst.size_req = 2;
16326 else if (inst.size_req == 4)
16327 {
bf3eeda7 16328 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
752d5da4
NC
16329 return;
16330 }
16331 }
076d447c
PB
16332 }
16333
c19d1205
ZW
16334 inst.instruction = opcode->tvalue;
16335
5be8be5d 16336 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
e07e6e58
NC
16337 {
16338 /* Prepare the it_insn_type for those encodings that don't set
16339 it. */
16340 it_fsm_pre_encode ();
c19d1205 16341
e07e6e58
NC
16342 opcode->tencode ();
16343
16344 it_fsm_post_encode ();
16345 }
e27ec89e 16346
0110f2b8 16347 if (!(inst.error || inst.relax))
b99bd4ef 16348 {
9c2799c2 16349 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
16350 inst.size = (inst.instruction > 0xffff ? 4 : 2);
16351 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 16352 {
c19d1205 16353 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
16354 return;
16355 }
16356 }
076d447c
PB
16357
16358 /* Something has gone badly wrong if we try to relax a fixed size
16359 instruction. */
9c2799c2 16360 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 16361
e74cfd16
PB
16362 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16363 *opcode->tvariant);
ee065d83 16364 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 16365 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 16366 anything other than bl/blx and v6-M instructions.
ee065d83 16367 This is overly pessimistic for relaxable instructions. */
7e806470
PB
16368 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
16369 || inst.relax)
e07e6e58
NC
16370 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
16371 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
16372 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16373 arm_ext_v6t2);
cd000bff 16374
88714cb8
DG
16375 check_neon_suffixes;
16376
cd000bff 16377 if (!inst.error)
c877a2f2
NC
16378 {
16379 mapping_state (MAP_THUMB);
16380 }
c19d1205 16381 }
3e9e4fcf 16382 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 16383 {
845b51d6
PB
16384 bfd_boolean is_bx;
16385
16386 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
16387 is_bx = (opcode->aencode == do_bx);
16388
c19d1205 16389 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
16390 if (!(is_bx && fix_v4bx)
16391 && !(opcode->avariant &&
16392 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 16393 {
bf3eeda7 16394 as_bad (_("selected processor does not support ARM mode `%s'"), str);
c19d1205 16395 return;
b99bd4ef 16396 }
c19d1205 16397 if (inst.size_req)
b99bd4ef 16398 {
c19d1205
ZW
16399 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
16400 return;
b99bd4ef
NC
16401 }
16402
c19d1205
ZW
16403 inst.instruction = opcode->avalue;
16404 if (opcode->tag == OT_unconditionalF)
16405 inst.instruction |= 0xF << 28;
16406 else
16407 inst.instruction |= inst.cond << 28;
16408 inst.size = INSN_SIZE;
5be8be5d 16409 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
e07e6e58
NC
16410 {
16411 it_fsm_pre_encode ();
16412 opcode->aencode ();
16413 it_fsm_post_encode ();
16414 }
ee065d83
PB
16415 /* Arm mode bx is marked as both v4T and v5 because it's still required
16416 on a hypothetical non-thumb v5 core. */
845b51d6 16417 if (is_bx)
e74cfd16 16418 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 16419 else
e74cfd16
PB
16420 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
16421 *opcode->avariant);
88714cb8
DG
16422
16423 check_neon_suffixes;
16424
cd000bff 16425 if (!inst.error)
c877a2f2
NC
16426 {
16427 mapping_state (MAP_ARM);
16428 }
b99bd4ef 16429 }
3e9e4fcf
JB
16430 else
16431 {
16432 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
16433 "-- `%s'"), str);
16434 return;
16435 }
c19d1205
ZW
16436 output_inst (str);
16437}
b99bd4ef 16438
e07e6e58
NC
16439static void
16440check_it_blocks_finished (void)
16441{
16442#ifdef OBJ_ELF
16443 asection *sect;
16444
16445 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
16446 if (seg_info (sect)->tc_segment_info_data.current_it.state
16447 == MANUAL_IT_BLOCK)
16448 {
16449 as_warn (_("section '%s' finished with an open IT block."),
16450 sect->name);
16451 }
16452#else
16453 if (now_it.state == MANUAL_IT_BLOCK)
16454 as_warn (_("file finished with an open IT block."));
16455#endif
16456}
16457
c19d1205
ZW
16458/* Various frobbings of labels and their addresses. */
16459
16460void
16461arm_start_line_hook (void)
16462{
16463 last_label_seen = NULL;
b99bd4ef
NC
16464}
16465
c19d1205
ZW
16466void
16467arm_frob_label (symbolS * sym)
b99bd4ef 16468{
c19d1205 16469 last_label_seen = sym;
b99bd4ef 16470
c19d1205 16471 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 16472
c19d1205
ZW
16473#if defined OBJ_COFF || defined OBJ_ELF
16474 ARM_SET_INTERWORK (sym, support_interwork);
16475#endif
b99bd4ef 16476
e07e6e58
NC
16477 force_automatic_it_block_close ();
16478
5f4273c7 16479 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
16480 as Thumb functions. This is because these labels, whilst
16481 they exist inside Thumb code, are not the entry points for
16482 possible ARM->Thumb calls. Also, these labels can be used
16483 as part of a computed goto or switch statement. eg gcc
16484 can generate code that looks like this:
b99bd4ef 16485
c19d1205
ZW
16486 ldr r2, [pc, .Laaa]
16487 lsl r3, r3, #2
16488 ldr r2, [r3, r2]
16489 mov pc, r2
b99bd4ef 16490
c19d1205
ZW
16491 .Lbbb: .word .Lxxx
16492 .Lccc: .word .Lyyy
16493 ..etc...
16494 .Laaa: .word Lbbb
b99bd4ef 16495
c19d1205
ZW
16496 The first instruction loads the address of the jump table.
16497 The second instruction converts a table index into a byte offset.
16498 The third instruction gets the jump address out of the table.
16499 The fourth instruction performs the jump.
b99bd4ef 16500
c19d1205
ZW
16501 If the address stored at .Laaa is that of a symbol which has the
16502 Thumb_Func bit set, then the linker will arrange for this address
16503 to have the bottom bit set, which in turn would mean that the
16504 address computation performed by the third instruction would end
16505 up with the bottom bit set. Since the ARM is capable of unaligned
16506 word loads, the instruction would then load the incorrect address
16507 out of the jump table, and chaos would ensue. */
16508 if (label_is_thumb_function_name
16509 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
16510 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 16511 {
c19d1205
ZW
16512 /* When the address of a Thumb function is taken the bottom
16513 bit of that address should be set. This will allow
16514 interworking between Arm and Thumb functions to work
16515 correctly. */
b99bd4ef 16516
c19d1205 16517 THUMB_SET_FUNC (sym, 1);
b99bd4ef 16518
c19d1205 16519 label_is_thumb_function_name = FALSE;
b99bd4ef 16520 }
07a53e5c 16521
07a53e5c 16522 dwarf2_emit_label (sym);
b99bd4ef
NC
16523}
16524
c921be7d 16525bfd_boolean
c19d1205 16526arm_data_in_code (void)
b99bd4ef 16527{
c19d1205 16528 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 16529 {
c19d1205
ZW
16530 *input_line_pointer = '/';
16531 input_line_pointer += 5;
16532 *input_line_pointer = 0;
c921be7d 16533 return TRUE;
b99bd4ef
NC
16534 }
16535
c921be7d 16536 return FALSE;
b99bd4ef
NC
16537}
16538
c19d1205
ZW
16539char *
16540arm_canonicalize_symbol_name (char * name)
b99bd4ef 16541{
c19d1205 16542 int len;
b99bd4ef 16543
c19d1205
ZW
16544 if (thumb_mode && (len = strlen (name)) > 5
16545 && streq (name + len - 5, "/data"))
16546 *(name + len - 5) = 0;
b99bd4ef 16547
c19d1205 16548 return name;
b99bd4ef 16549}
c19d1205
ZW
16550\f
16551/* Table of all register names defined by default. The user can
16552 define additional names with .req. Note that all register names
16553 should appear in both upper and lowercase variants. Some registers
16554 also have mixed-case names. */
b99bd4ef 16555
dcbf9037 16556#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 16557#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 16558#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
16559#define REGSET(p,t) \
16560 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
16561 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
16562 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
16563 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
16564#define REGSETH(p,t) \
16565 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
16566 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
16567 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
16568 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
16569#define REGSET2(p,t) \
16570 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
16571 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
16572 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
16573 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
16574#define SPLRBANK(base,bank,t) \
16575 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
16576 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
16577 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
16578 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
16579 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
16580 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 16581
c19d1205 16582static const struct reg_entry reg_names[] =
7ed4c4c5 16583{
c19d1205
ZW
16584 /* ARM integer registers. */
16585 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 16586
c19d1205
ZW
16587 /* ATPCS synonyms. */
16588 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
16589 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16590 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 16591
c19d1205
ZW
16592 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16593 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16594 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 16595
c19d1205
ZW
16596 /* Well-known aliases. */
16597 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16598 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16599
16600 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16601 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16602
16603 /* Coprocessor numbers. */
16604 REGSET(p, CP), REGSET(P, CP),
16605
16606 /* Coprocessor register numbers. The "cr" variants are for backward
16607 compatibility. */
16608 REGSET(c, CN), REGSET(C, CN),
16609 REGSET(cr, CN), REGSET(CR, CN),
16610
90ec0d68
MGD
16611 /* ARM banked registers. */
16612 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
16613 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
16614 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
16615 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
16616 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
16617 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
16618 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
16619
16620 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
16621 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
16622 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
16623 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
16624 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
16625 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB),
16626 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
16627 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
16628
16629 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
16630 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
16631 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
16632 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
16633 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
16634 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
16635 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
16636 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
16637 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
16638
c19d1205
ZW
16639 /* FPA registers. */
16640 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16641 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16642
16643 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16644 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16645
16646 /* VFP SP registers. */
5287ad62
JB
16647 REGSET(s,VFS), REGSET(S,VFS),
16648 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
16649
16650 /* VFP DP Registers. */
5287ad62
JB
16651 REGSET(d,VFD), REGSET(D,VFD),
16652 /* Extra Neon DP registers. */
16653 REGSETH(d,VFD), REGSETH(D,VFD),
16654
16655 /* Neon QP registers. */
16656 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
16657
16658 /* VFP control registers. */
16659 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16660 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
16661 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16662 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16663 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16664 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
16665
16666 /* Maverick DSP coprocessor registers. */
16667 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16668 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16669
16670 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16671 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16672 REGDEF(dspsc,0,DSPSC),
16673
16674 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16675 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16676 REGDEF(DSPSC,0,DSPSC),
16677
16678 /* iWMMXt data registers - p0, c0-15. */
16679 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16680
16681 /* iWMMXt control registers - p1, c0-3. */
16682 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16683 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16684 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16685 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16686
16687 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16688 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16689 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16690 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16691 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16692
16693 /* XScale accumulator registers. */
16694 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16695};
16696#undef REGDEF
16697#undef REGNUM
16698#undef REGSET
7ed4c4c5 16699
c19d1205
ZW
16700/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16701 within psr_required_here. */
16702static const struct asm_psr psrs[] =
16703{
16704 /* Backward compatibility notation. Note that "all" is no longer
16705 truly all possible PSR bits. */
16706 {"all", PSR_c | PSR_f},
16707 {"flg", PSR_f},
16708 {"ctl", PSR_c},
16709
16710 /* Individual flags. */
16711 {"f", PSR_f},
16712 {"c", PSR_c},
16713 {"x", PSR_x},
16714 {"s", PSR_s},
59b42a0d 16715
c19d1205
ZW
16716 /* Combinations of flags. */
16717 {"fs", PSR_f | PSR_s},
16718 {"fx", PSR_f | PSR_x},
16719 {"fc", PSR_f | PSR_c},
16720 {"sf", PSR_s | PSR_f},
16721 {"sx", PSR_s | PSR_x},
16722 {"sc", PSR_s | PSR_c},
16723 {"xf", PSR_x | PSR_f},
16724 {"xs", PSR_x | PSR_s},
16725 {"xc", PSR_x | PSR_c},
16726 {"cf", PSR_c | PSR_f},
16727 {"cs", PSR_c | PSR_s},
16728 {"cx", PSR_c | PSR_x},
16729 {"fsx", PSR_f | PSR_s | PSR_x},
16730 {"fsc", PSR_f | PSR_s | PSR_c},
16731 {"fxs", PSR_f | PSR_x | PSR_s},
16732 {"fxc", PSR_f | PSR_x | PSR_c},
16733 {"fcs", PSR_f | PSR_c | PSR_s},
16734 {"fcx", PSR_f | PSR_c | PSR_x},
16735 {"sfx", PSR_s | PSR_f | PSR_x},
16736 {"sfc", PSR_s | PSR_f | PSR_c},
16737 {"sxf", PSR_s | PSR_x | PSR_f},
16738 {"sxc", PSR_s | PSR_x | PSR_c},
16739 {"scf", PSR_s | PSR_c | PSR_f},
16740 {"scx", PSR_s | PSR_c | PSR_x},
16741 {"xfs", PSR_x | PSR_f | PSR_s},
16742 {"xfc", PSR_x | PSR_f | PSR_c},
16743 {"xsf", PSR_x | PSR_s | PSR_f},
16744 {"xsc", PSR_x | PSR_s | PSR_c},
16745 {"xcf", PSR_x | PSR_c | PSR_f},
16746 {"xcs", PSR_x | PSR_c | PSR_s},
16747 {"cfs", PSR_c | PSR_f | PSR_s},
16748 {"cfx", PSR_c | PSR_f | PSR_x},
16749 {"csf", PSR_c | PSR_s | PSR_f},
16750 {"csx", PSR_c | PSR_s | PSR_x},
16751 {"cxf", PSR_c | PSR_x | PSR_f},
16752 {"cxs", PSR_c | PSR_x | PSR_s},
16753 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16754 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16755 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16756 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16757 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16758 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16759 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16760 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16761 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16762 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16763 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16764 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16765 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16766 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16767 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16768 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16769 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16770 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16771 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16772 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16773 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16774 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16775 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16776 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16777};
16778
62b3e311
PB
16779/* Table of V7M psr names. */
16780static const struct asm_psr v7m_psrs[] =
16781{
2b744c99
PB
16782 {"apsr", 0 }, {"APSR", 0 },
16783 {"iapsr", 1 }, {"IAPSR", 1 },
16784 {"eapsr", 2 }, {"EAPSR", 2 },
16785 {"psr", 3 }, {"PSR", 3 },
16786 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16787 {"ipsr", 5 }, {"IPSR", 5 },
16788 {"epsr", 6 }, {"EPSR", 6 },
16789 {"iepsr", 7 }, {"IEPSR", 7 },
16790 {"msp", 8 }, {"MSP", 8 },
16791 {"psp", 9 }, {"PSP", 9 },
16792 {"primask", 16}, {"PRIMASK", 16},
16793 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
16794 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16795 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99
PB
16796 {"faultmask", 19}, {"FAULTMASK", 19},
16797 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
16798};
16799
c19d1205
ZW
16800/* Table of all shift-in-operand names. */
16801static const struct asm_shift_name shift_names [] =
b99bd4ef 16802{
c19d1205
ZW
16803 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16804 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16805 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16806 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16807 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16808 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16809};
b99bd4ef 16810
c19d1205
ZW
16811/* Table of all explicit relocation names. */
16812#ifdef OBJ_ELF
16813static struct reloc_entry reloc_names[] =
16814{
16815 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16816 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16817 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16818 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16819 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16820 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16821 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16822 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16823 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16824 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 16825 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
16826 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
16827 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
16828 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
16829 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
16830 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
16831 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
16832 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
16833};
16834#endif
b99bd4ef 16835
c19d1205
ZW
16836/* Table of all conditional affixes. 0xF is not defined as a condition code. */
16837static const struct asm_cond conds[] =
16838{
16839 {"eq", 0x0},
16840 {"ne", 0x1},
16841 {"cs", 0x2}, {"hs", 0x2},
16842 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16843 {"mi", 0x4},
16844 {"pl", 0x5},
16845 {"vs", 0x6},
16846 {"vc", 0x7},
16847 {"hi", 0x8},
16848 {"ls", 0x9},
16849 {"ge", 0xa},
16850 {"lt", 0xb},
16851 {"gt", 0xc},
16852 {"le", 0xd},
16853 {"al", 0xe}
16854};
bfae80f2 16855
62b3e311
PB
16856static struct asm_barrier_opt barrier_opt_names[] =
16857{
52e7f43d
RE
16858 { "sy", 0xf }, { "SY", 0xf },
16859 { "un", 0x7 }, { "UN", 0x7 },
16860 { "st", 0xe }, { "ST", 0xe },
16861 { "unst", 0x6 }, { "UNST", 0x6 },
16862 { "ish", 0xb }, { "ISH", 0xb },
16863 { "sh", 0xb }, { "SH", 0xb },
16864 { "ishst", 0xa }, { "ISHST", 0xa },
16865 { "shst", 0xa }, { "SHST", 0xa },
16866 { "nsh", 0x7 }, { "NSH", 0x7 },
16867 { "nshst", 0x6 }, { "NSHST", 0x6 },
16868 { "osh", 0x3 }, { "OSH", 0x3 },
16869 { "oshst", 0x2 }, { "OSHST", 0x2 }
62b3e311
PB
16870};
16871
c19d1205
ZW
16872/* Table of ARM-format instructions. */
16873
16874/* Macros for gluing together operand strings. N.B. In all cases
16875 other than OPS0, the trailing OP_stop comes from default
16876 zero-initialization of the unspecified elements of the array. */
16877#define OPS0() { OP_stop, }
16878#define OPS1(a) { OP_##a, }
16879#define OPS2(a,b) { OP_##a,OP_##b, }
16880#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16881#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16882#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16883#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16884
5be8be5d
DG
16885/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16886 This is useful when mixing operands for ARM and THUMB, i.e. using the
16887 MIX_ARM_THUMB_OPERANDS macro.
16888 In order to use these macros, prefix the number of operands with _
16889 e.g. _3. */
16890#define OPS_1(a) { a, }
16891#define OPS_2(a,b) { a,b, }
16892#define OPS_3(a,b,c) { a,b,c, }
16893#define OPS_4(a,b,c,d) { a,b,c,d, }
16894#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16895#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16896
c19d1205
ZW
16897/* These macros abstract out the exact format of the mnemonic table and
16898 save some repeated characters. */
16899
16900/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16901#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16902 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 16903 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16904
16905/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16906 a T_MNEM_xyz enumerator. */
16907#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16908 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16909#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16910 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16911
16912/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16913 infix after the third character. */
16914#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 16915 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 16916 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 16917#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 16918 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 16919 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 16920#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16921 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 16922#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16923 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16924#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16925 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 16926#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16927 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16928
16929/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16930 appear in the condition table. */
16931#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
21d799b5 16932 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
1887dd22 16933 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16934
16935#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
16936 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16937 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16938 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16939 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16940 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16941 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16942 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16943 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16944 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16945 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16946 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16947 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16948 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16949 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16950 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16951 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16952 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16953 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16954 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
16955
16956#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
16957 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16958#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
21d799b5 16959 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16960
16961/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
16962 field is still 0xE. Many of the Thumb variants can be executed
16963 conditionally, so this is checked separately. */
c19d1205 16964#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16965 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16966 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16967
16968/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16969 condition code field. */
16970#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 16971 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16972 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16973
16974/* ARM-only variants of all the above. */
6a86118a 16975#define CE(mnem, op, nops, ops, ae) \
21d799b5 16976 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
16977
16978#define C3(mnem, op, nops, ops, ae) \
16979 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16980
e3cb604e
PB
16981/* Legacy mnemonics that always have conditional infix after the third
16982 character. */
16983#define CL(mnem, op, nops, ops, ae) \
21d799b5 16984 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16985 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16986
8f06b2d8
PB
16987/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16988#define cCE(mnem, op, nops, ops, ae) \
21d799b5 16989 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16990
e3cb604e
PB
16991/* Legacy coprocessor instructions where conditional infix and conditional
16992 suffix are ambiguous. For consistency this includes all FPA instructions,
16993 not just the potentially ambiguous ones. */
16994#define cCL(mnem, op, nops, ops, ae) \
21d799b5 16995 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16996 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16997
16998/* Coprocessor, takes either a suffix or a position-3 infix
16999 (for an FPA corner case). */
17000#define C3E(mnem, op, nops, ops, ae) \
21d799b5 17001 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 17002 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 17003
6a86118a 17004#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
17005 { m1 #m2 m3, OPS##nops ops, \
17006 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
17007 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17008
17009#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
17010 xCM_ (m1, , m2, op, nops, ops, ae), \
17011 xCM_ (m1, eq, m2, op, nops, ops, ae), \
17012 xCM_ (m1, ne, m2, op, nops, ops, ae), \
17013 xCM_ (m1, cs, m2, op, nops, ops, ae), \
17014 xCM_ (m1, hs, m2, op, nops, ops, ae), \
17015 xCM_ (m1, cc, m2, op, nops, ops, ae), \
17016 xCM_ (m1, ul, m2, op, nops, ops, ae), \
17017 xCM_ (m1, lo, m2, op, nops, ops, ae), \
17018 xCM_ (m1, mi, m2, op, nops, ops, ae), \
17019 xCM_ (m1, pl, m2, op, nops, ops, ae), \
17020 xCM_ (m1, vs, m2, op, nops, ops, ae), \
17021 xCM_ (m1, vc, m2, op, nops, ops, ae), \
17022 xCM_ (m1, hi, m2, op, nops, ops, ae), \
17023 xCM_ (m1, ls, m2, op, nops, ops, ae), \
17024 xCM_ (m1, ge, m2, op, nops, ops, ae), \
17025 xCM_ (m1, lt, m2, op, nops, ops, ae), \
17026 xCM_ (m1, gt, m2, op, nops, ops, ae), \
17027 xCM_ (m1, le, m2, op, nops, ops, ae), \
17028 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
17029
17030#define UE(mnem, op, nops, ops, ae) \
17031 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17032
17033#define UF(mnem, op, nops, ops, ae) \
17034 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17035
5287ad62
JB
17036/* Neon data-processing. ARM versions are unconditional with cond=0xf.
17037 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
17038 use the same encoding function for each. */
17039#define NUF(mnem, op, nops, ops, enc) \
17040 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
17041 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17042
17043/* Neon data processing, version which indirects through neon_enc_tab for
17044 the various overloaded versions of opcodes. */
17045#define nUF(mnem, op, nops, ops, enc) \
21d799b5 17046 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
17047 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17048
17049/* Neon insn with conditional suffix for the ARM version, non-overloaded
17050 version. */
037e8744
JB
17051#define NCE_tag(mnem, op, nops, ops, enc, tag) \
17052 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
17053 THUMB_VARIANT, do_##enc, do_##enc }
17054
037e8744 17055#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 17056 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
17057
17058#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 17059 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 17060
5287ad62 17061/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 17062#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 17063 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
17064 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17065
037e8744 17066#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 17067 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
17068
17069#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 17070 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 17071
c19d1205
ZW
17072#define do_0 0
17073
c19d1205 17074static const struct asm_opcode insns[] =
bfae80f2 17075{
e74cfd16
PB
17076#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
17077#define THUMB_VARIANT &arm_ext_v4t
21d799b5
NC
17078 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
17079 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
17080 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
17081 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
17082 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
17083 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
17084 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
17085 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
17086 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
17087 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
17088 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
17089 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
17090 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
17091 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
17092 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
17093 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
17094
17095 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
17096 for setting PSR flag bits. They are obsolete in V6 and do not
17097 have Thumb equivalents. */
21d799b5
NC
17098 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17099 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17100 CL("tstp", 110f000, 2, (RR, SH), cmp),
17101 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17102 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17103 CL("cmpp", 150f000, 2, (RR, SH), cmp),
17104 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17105 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17106 CL("cmnp", 170f000, 2, (RR, SH), cmp),
17107
17108 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
17109 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
17110 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
17111 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
17112
17113 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
17114 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17115 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
17116 OP_RRnpc),
17117 OP_ADDRGLDR),ldst, t_ldst),
17118 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
17119
17120 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17121 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17122 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17123 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17124 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17125 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17126
17127 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
17128 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
17129 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
17130 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 17131
c19d1205 17132 /* Pseudo ops. */
21d799b5 17133 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 17134 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 17135 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
17136
17137 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
17138 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
17139 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
17140 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
17141 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
17142 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
17143 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
17144 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
17145 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
17146 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
17147 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
17148 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
17149 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 17150
16a4cf17 17151 /* These may simplify to neg. */
21d799b5
NC
17152 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
17153 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 17154
c921be7d
NC
17155#undef THUMB_VARIANT
17156#define THUMB_VARIANT & arm_ext_v6
17157
21d799b5 17158 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
17159
17160 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
17161#undef THUMB_VARIANT
17162#define THUMB_VARIANT & arm_ext_v6t2
17163
21d799b5
NC
17164 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17165 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17166 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 17167
5be8be5d
DG
17168 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17169 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17170 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
17171 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 17172
21d799b5
NC
17173 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17174 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 17175
21d799b5
NC
17176 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17177 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
17178
17179 /* V1 instructions with no Thumb analogue at all. */
21d799b5 17180 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
17181 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
17182
17183 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
17184 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
17185 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
17186 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
17187 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
17188 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
17189 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
17190 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
17191
c921be7d
NC
17192#undef ARM_VARIANT
17193#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
17194#undef THUMB_VARIANT
17195#define THUMB_VARIANT & arm_ext_v4t
17196
21d799b5
NC
17197 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
17198 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 17199
c921be7d
NC
17200#undef THUMB_VARIANT
17201#define THUMB_VARIANT & arm_ext_v6t2
17202
21d799b5 17203 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
17204 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
17205
17206 /* Generic coprocessor instructions. */
21d799b5
NC
17207 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17208 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17209 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17210 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17211 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17212 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 17213 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 17214
c921be7d
NC
17215#undef ARM_VARIANT
17216#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
17217
21d799b5 17218 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
17219 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
17220
c921be7d
NC
17221#undef ARM_VARIANT
17222#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
17223#undef THUMB_VARIANT
17224#define THUMB_VARIANT & arm_ext_msr
17225
d2cd1205
JB
17226 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
17227 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 17228
c921be7d
NC
17229#undef ARM_VARIANT
17230#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
17231#undef THUMB_VARIANT
17232#define THUMB_VARIANT & arm_ext_v6t2
17233
21d799b5
NC
17234 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17235 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17236 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17237 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17238 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17239 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17240 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17241 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 17242
c921be7d
NC
17243#undef ARM_VARIANT
17244#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
17245#undef THUMB_VARIANT
17246#define THUMB_VARIANT & arm_ext_v4t
17247
5be8be5d
DG
17248 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17249 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17250 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17251 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17252 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17253 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 17254
c921be7d
NC
17255#undef ARM_VARIANT
17256#define ARM_VARIANT & arm_ext_v4t_5
17257
c19d1205
ZW
17258 /* ARM Architecture 4T. */
17259 /* Note: bx (and blx) are required on V5, even if the processor does
17260 not support Thumb. */
21d799b5 17261 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 17262
c921be7d
NC
17263#undef ARM_VARIANT
17264#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
17265#undef THUMB_VARIANT
17266#define THUMB_VARIANT & arm_ext_v5t
17267
c19d1205
ZW
17268 /* Note: blx has 2 variants; the .value coded here is for
17269 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
17270 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
17271 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 17272
c921be7d
NC
17273#undef THUMB_VARIANT
17274#define THUMB_VARIANT & arm_ext_v6t2
17275
21d799b5
NC
17276 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
17277 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17278 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17279 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17280 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17281 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17282 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17283 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 17284
c921be7d
NC
17285#undef ARM_VARIANT
17286#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
9e3c6df6
PB
17287#undef THUMB_VARIANT
17288#define THUMB_VARIANT &arm_ext_v5exp
c921be7d 17289
21d799b5
NC
17290 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17291 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17292 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17293 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 17294
21d799b5
NC
17295 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17296 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 17297
21d799b5
NC
17298 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17299 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17300 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17301 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 17302
21d799b5
NC
17303 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17304 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17305 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17306 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 17307
21d799b5
NC
17308 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17309 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 17310
03ee1b7f
NC
17311 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17312 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17313 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17314 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 17315
c921be7d
NC
17316#undef ARM_VARIANT
17317#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
9e3c6df6
PB
17318#undef THUMB_VARIANT
17319#define THUMB_VARIANT &arm_ext_v6t2
c921be7d 17320
21d799b5 17321 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
17322 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
17323 ldrd, t_ldstd),
17324 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
17325 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 17326
21d799b5
NC
17327 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17328 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 17329
c921be7d
NC
17330#undef ARM_VARIANT
17331#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
17332
21d799b5 17333 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 17334
c921be7d
NC
17335#undef ARM_VARIANT
17336#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
17337#undef THUMB_VARIANT
17338#define THUMB_VARIANT & arm_ext_v6
17339
21d799b5
NC
17340 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
17341 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
17342 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17343 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17344 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17345 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17346 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17347 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17348 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17349 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 17350
c921be7d
NC
17351#undef THUMB_VARIANT
17352#define THUMB_VARIANT & arm_ext_v6t2
17353
5be8be5d
DG
17354 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
17355 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17356 strex, t_strex),
21d799b5
NC
17357 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17358 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 17359
21d799b5
NC
17360 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
17361 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 17362
9e3c6df6 17363/* ARM V6 not included in V7M. */
c921be7d
NC
17364#undef THUMB_VARIANT
17365#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6
PB
17366 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17367 UF(rfeib, 9900a00, 1, (RRw), rfe),
17368 UF(rfeda, 8100a00, 1, (RRw), rfe),
17369 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17370 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17371 UF(rfefa, 9900a00, 1, (RRw), rfe),
17372 UF(rfeea, 8100a00, 1, (RRw), rfe),
17373 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17374 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
17375 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
17376 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
17377 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 17378
9e3c6df6
PB
17379/* ARM V6 not included in V7M (eg. integer SIMD). */
17380#undef THUMB_VARIANT
17381#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
17382 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
17383 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
17384 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
17385 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17386 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17387 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17388 /* Old name for QASX. */
21d799b5
NC
17389 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17390 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17391 /* Old name for QSAX. */
21d799b5
NC
17392 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17393 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17394 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17395 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17396 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17397 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17398 /* Old name for SASX. */
21d799b5
NC
17399 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17400 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17401 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17402 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17403 /* Old name for SHASX. */
21d799b5
NC
17404 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17405 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17406 /* Old name for SHSAX. */
21d799b5
NC
17407 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17408 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17409 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17410 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17411 /* Old name for SSAX. */
21d799b5
NC
17412 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17413 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17414 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17415 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17416 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17417 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17418 /* Old name for UASX. */
21d799b5
NC
17419 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17420 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17421 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17422 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17423 /* Old name for UHASX. */
21d799b5
NC
17424 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17425 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17426 /* Old name for UHSAX. */
21d799b5
NC
17427 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17428 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17429 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17430 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17431 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17432 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17433 /* Old name for UQASX. */
21d799b5
NC
17434 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17435 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17436 /* Old name for UQSAX. */
21d799b5
NC
17437 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17438 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17439 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17440 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17441 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17442 /* Old name for USAX. */
21d799b5
NC
17443 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17444 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
17445 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17446 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17447 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17448 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17449 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17450 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17451 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17452 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17453 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17454 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17455 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17456 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17457 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17458 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17459 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17460 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17461 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17462 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17463 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17464 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17465 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17466 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17467 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17468 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17469 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17470 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17471 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
17472 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
17473 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
17474 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17475 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17476 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 17477
c921be7d
NC
17478#undef ARM_VARIANT
17479#define ARM_VARIANT & arm_ext_v6k
17480#undef THUMB_VARIANT
17481#define THUMB_VARIANT & arm_ext_v6k
17482
21d799b5
NC
17483 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
17484 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
17485 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
17486 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 17487
c921be7d
NC
17488#undef THUMB_VARIANT
17489#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
17490 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
17491 ldrexd, t_ldrexd),
17492 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
17493 RRnpcb), strexd, t_strexd),
ebdca51a 17494
c921be7d
NC
17495#undef THUMB_VARIANT
17496#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
17497 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
17498 rd_rn, rd_rn),
17499 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
17500 rd_rn, rd_rn),
17501 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17502 strex, rm_rd_rn),
17503 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17504 strex, rm_rd_rn),
21d799b5 17505 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 17506
c921be7d 17507#undef ARM_VARIANT
f4c65163
MGD
17508#define ARM_VARIANT & arm_ext_sec
17509#undef THUMB_VARIANT
17510#define THUMB_VARIANT & arm_ext_sec
c921be7d 17511
21d799b5 17512 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 17513
90ec0d68
MGD
17514#undef ARM_VARIANT
17515#define ARM_VARIANT & arm_ext_virt
17516#undef THUMB_VARIANT
17517#define THUMB_VARIANT & arm_ext_virt
17518
17519 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
17520 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
17521
c921be7d
NC
17522#undef ARM_VARIANT
17523#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
17524#undef THUMB_VARIANT
17525#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 17526
21d799b5
NC
17527 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
17528 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
17529 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17530 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 17531
21d799b5
NC
17532 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17533 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
17534 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
17535 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 17536
5be8be5d
DG
17537 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17538 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17539 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17540 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 17541
bf3eeda7
NS
17542 /* Thumb-only instructions. */
17543#undef ARM_VARIANT
17544#define ARM_VARIANT NULL
17545 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
17546 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
17547
17548 /* ARM does not really have an IT instruction, so always allow it.
17549 The opcode is copied from Thumb in order to allow warnings in
17550 -mimplicit-it=[never | arm] modes. */
17551#undef ARM_VARIANT
17552#define ARM_VARIANT & arm_ext_v1
17553
21d799b5
NC
17554 TUE("it", bf08, bf08, 1, (COND), it, t_it),
17555 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
17556 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
17557 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
17558 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
17559 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
17560 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
17561 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
17562 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
17563 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
17564 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
17565 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
17566 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
17567 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
17568 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 17569 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
17570 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
17571 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 17572
92e90b6e 17573 /* Thumb2 only instructions. */
c921be7d
NC
17574#undef ARM_VARIANT
17575#define ARM_VARIANT NULL
92e90b6e 17576
21d799b5
NC
17577 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17578 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17579 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
17580 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
17581 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
17582 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 17583
eea54501
MGD
17584 /* Hardware division instructions. */
17585#undef ARM_VARIANT
17586#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
17587#undef THUMB_VARIANT
17588#define THUMB_VARIANT & arm_ext_div
17589
eea54501
MGD
17590 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
17591 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 17592
7e806470 17593 /* ARM V6M/V7 instructions. */
c921be7d
NC
17594#undef ARM_VARIANT
17595#define ARM_VARIANT & arm_ext_barrier
17596#undef THUMB_VARIANT
17597#define THUMB_VARIANT & arm_ext_barrier
17598
52e7f43d
RE
17599 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
17600 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
17601 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
7e806470 17602
62b3e311 17603 /* ARM V7 instructions. */
c921be7d
NC
17604#undef ARM_VARIANT
17605#define ARM_VARIANT & arm_ext_v7
17606#undef THUMB_VARIANT
17607#define THUMB_VARIANT & arm_ext_v7
17608
21d799b5
NC
17609 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
17610 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 17611
60e5ef9f
MGD
17612#undef ARM_VARIANT
17613#define ARM_VARIANT & arm_ext_mp
17614#undef THUMB_VARIANT
17615#define THUMB_VARIANT & arm_ext_mp
17616
17617 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
17618
c921be7d
NC
17619#undef ARM_VARIANT
17620#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
17621
21d799b5
NC
17622 cCE("wfs", e200110, 1, (RR), rd),
17623 cCE("rfs", e300110, 1, (RR), rd),
17624 cCE("wfc", e400110, 1, (RR), rd),
17625 cCE("rfc", e500110, 1, (RR), rd),
17626
17627 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
17628 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
17629 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
17630 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
17631
17632 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
17633 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
17634 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
17635 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
17636
17637 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
17638 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
17639 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
17640 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
17641 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
17642 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
17643 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
17644 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
17645 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
17646 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
17647 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
17648 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
17649
17650 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
17651 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
17652 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
17653 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
17654 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17655 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17656 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17657 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17658 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17659 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17660 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17661 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17662
17663 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17664 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17665 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17666 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17667 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17668 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17669 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17670 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17671 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17672 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17673 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17674 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17675
17676 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17677 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17678 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17679 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17680 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17681 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17682 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17683 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17684 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17685 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17686 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17687 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17688
17689 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17690 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17691 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17692 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17693 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17694 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17695 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17696 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17697 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17698 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17699 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17700 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17701
17702 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17703 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17704 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17705 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17706 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17707 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17708 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17709 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17710 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17711 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17712 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17713 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17714
17715 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17716 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17717 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17718 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17719 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17720 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17721 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17722 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17723 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17724 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17725 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17726 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17727
17728 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17729 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17730 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17731 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17732 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17733 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17734 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17735 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17736 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17737 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17738 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17739 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17740
17741 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17742 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17743 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17744 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17745 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17746 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17747 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17748 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17749 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17750 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17751 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17752 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17753
17754 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17755 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17756 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17757 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17758 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17759 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17760 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17761 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17762 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17763 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17764 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17765 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17766
17767 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17768 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17769 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17770 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17771 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17772 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17773 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17774 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17775 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17776 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17777 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17778 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17779
17780 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17781 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17782 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17783 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17784 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17785 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17786 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17787 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17788 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17789 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17790 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17791 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17792
17793 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17794 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17795 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17796 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17797 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17798 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17799 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17800 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17801 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17802 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17803 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17804 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17805
17806 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17807 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17808 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17809 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17810 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17811 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17812 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17813 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17814 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17815 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17816 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17817 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17818
17819 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17820 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17821 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17822 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17823 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17824 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17825 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17826 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17827 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17828 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17829 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17830 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17831
17832 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17833 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17834 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17835 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17836 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17837 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17838 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17839 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17840 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17841 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17842 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17843 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17844
17845 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17846 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17847 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17848 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17849 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17850 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17851 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17852 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17853 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17854 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17855 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17856 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17857
17858 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17859 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17860 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17861 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17862 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17863 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17864 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17865 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17866 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17867 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17868 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17869 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17870
17871 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17872 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17873 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17874 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17875 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17876 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17877 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17878 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17879 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17880 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17881 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17882 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17883
17884 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17885 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17886 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17887 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17888 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17889 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17890 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17891 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17892 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17893 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17894 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17895 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17896
17897 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17898 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17899 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17900 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17901 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17902 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17903 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17904 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17905 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17906 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17907 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17908 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17909
17910 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17911 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17912 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17913 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17914 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17915 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17916 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17917 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17918 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17919 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17920 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17921 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17922
17923 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17924 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17925 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17926 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17927 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17928 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17929 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17930 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17931 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17932 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17933 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17934 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17935
17936 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17937 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17938 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17939 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17940 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17941 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17942 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17943 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17944 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17945 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17946 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17947 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17948
17949 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17950 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17951 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17952 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17953 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17954 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17955 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17956 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17957 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17958 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17959 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17960 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17961
17962 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17963 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17964 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17965 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17966 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17967 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17968 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17969 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17970 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17971 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17972 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17973 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17974
17975 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17976 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17977 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17978 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17979 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17980 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17981 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17982 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17983 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17984 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17985 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17986 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17987
17988 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17989 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17990 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17991 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17992 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17993 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17994 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17995 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17996 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17997 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17998 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17999 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18000
18001 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18002 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18003 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18004 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18005 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18006 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18007 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18008 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18009 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18010 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18011 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18012 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18013
18014 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
18015 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
18016 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
18017 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
18018
18019 cCL("flts", e000110, 2, (RF, RR), rn_rd),
18020 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
18021 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
18022 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
18023 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
18024 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
18025 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
18026 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
18027 cCL("flte", e080110, 2, (RF, RR), rn_rd),
18028 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
18029 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
18030 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 18031
c19d1205
ZW
18032 /* The implementation of the FIX instruction is broken on some
18033 assemblers, in that it accepts a precision specifier as well as a
18034 rounding specifier, despite the fact that this is meaningless.
18035 To be more compatible, we accept it as well, though of course it
18036 does not set any bits. */
21d799b5
NC
18037 cCE("fix", e100110, 2, (RR, RF), rd_rm),
18038 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
18039 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
18040 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
18041 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
18042 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
18043 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
18044 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
18045 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
18046 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
18047 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
18048 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
18049 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 18050
c19d1205 18051 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
18052#undef ARM_VARIANT
18053#define ARM_VARIANT & fpu_fpa_ext_v2
18054
21d799b5
NC
18055 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18056 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18057 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18058 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18059 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18060 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 18061
c921be7d
NC
18062#undef ARM_VARIANT
18063#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
18064
c19d1205 18065 /* Moves and type conversions. */
21d799b5
NC
18066 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
18067 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
18068 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
18069 cCE("fmstat", ef1fa10, 0, (), noargs),
f7c21dc7
NC
18070 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
18071 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
21d799b5
NC
18072 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
18073 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
18074 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
18075 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18076 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
18077 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18078 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
18079 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
18080
18081 /* Memory operations. */
21d799b5
NC
18082 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
18083 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
18084 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18085 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18086 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18087 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18088 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18089 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18090 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18091 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18092 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18093 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18094 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18095 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18096 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18097 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18098 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18099 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 18100
c19d1205 18101 /* Monadic operations. */
21d799b5
NC
18102 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
18103 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
18104 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
18105
18106 /* Dyadic operations. */
21d799b5
NC
18107 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18108 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18109 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18110 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18111 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18112 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18113 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18114 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18115 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 18116
c19d1205 18117 /* Comparisons. */
21d799b5
NC
18118 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
18119 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
18120 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
18121 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 18122
62f3b8c8
PB
18123 /* Double precision load/store are still present on single precision
18124 implementations. */
18125 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
18126 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
18127 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18128 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18129 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18130 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18131 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18132 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18133 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18134 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 18135
c921be7d
NC
18136#undef ARM_VARIANT
18137#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
18138
c19d1205 18139 /* Moves and type conversions. */
21d799b5
NC
18140 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18141 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18142 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18143 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
18144 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
18145 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
18146 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
18147 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18148 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
18149 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18150 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18151 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18152 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 18153
c19d1205 18154 /* Monadic operations. */
21d799b5
NC
18155 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18156 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18157 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
18158
18159 /* Dyadic operations. */
21d799b5
NC
18160 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18161 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18162 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18163 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18164 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18165 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18166 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18167 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18168 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 18169
c19d1205 18170 /* Comparisons. */
21d799b5
NC
18171 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18172 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
18173 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18174 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 18175
c921be7d
NC
18176#undef ARM_VARIANT
18177#define ARM_VARIANT & fpu_vfp_ext_v2
18178
21d799b5
NC
18179 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
18180 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
18181 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
18182 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 18183
037e8744
JB
18184/* Instructions which may belong to either the Neon or VFP instruction sets.
18185 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
18186#undef ARM_VARIANT
18187#define ARM_VARIANT & fpu_vfp_ext_v1xd
18188#undef THUMB_VARIANT
18189#define THUMB_VARIANT & fpu_vfp_ext_v1xd
18190
037e8744
JB
18191 /* These mnemonics are unique to VFP. */
18192 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
18193 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
18194 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18195 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18196 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18197 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
18198 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
18199 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
18200 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
18201 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
18202
18203 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
18204 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
18205 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
18206 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 18207
21d799b5
NC
18208 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
18209 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
18210
18211 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18212 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18213
55881a11
MGD
18214 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18215 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18216 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18217 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18218 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18219 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
18220 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
18221 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 18222
5f1af56b 18223 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 18224 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
21d799b5
NC
18225 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
18226 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 18227
037e8744
JB
18228
18229 /* NOTE: All VMOV encoding is special-cased! */
18230 NCE(vmov, 0, 1, (VMOV), neon_mov),
18231 NCE(vmovq, 0, 1, (VMOV), neon_mov),
18232
c921be7d
NC
18233#undef THUMB_VARIANT
18234#define THUMB_VARIANT & fpu_neon_ext_v1
18235#undef ARM_VARIANT
18236#define ARM_VARIANT & fpu_neon_ext_v1
18237
5287ad62
JB
18238 /* Data processing with three registers of the same length. */
18239 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
18240 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
18241 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
18242 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18243 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18244 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18245 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18246 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18247 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18248 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
18249 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18250 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
18251 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18252 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
18253 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18254 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
18255 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18256 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
18257 /* If not immediate, fall back to neon_dyadic_i64_su.
18258 shl_imm should accept I8 I16 I32 I64,
18259 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
18260 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
18261 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
18262 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
18263 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 18264 /* Logic ops, types optional & ignored. */
4316f0d2
DG
18265 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18266 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18267 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18268 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18269 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18270 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18271 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18272 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18273 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
18274 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
18275 /* Bitfield ops, untyped. */
18276 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18277 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18278 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18279 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18280 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18281 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18282 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
18283 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18284 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18285 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18286 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18287 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18288 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
18289 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
18290 back to neon_dyadic_if_su. */
21d799b5
NC
18291 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18292 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18293 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18294 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18295 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18296 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
18297 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18298 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 18299 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
18300 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
18301 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 18302 /* As above, D registers only. */
21d799b5
NC
18303 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
18304 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 18305 /* Int and float variants, signedness unimportant. */
21d799b5
NC
18306 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18307 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18308 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 18309 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
18310 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
18311 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
18312 /* vtst takes sizes 8, 16, 32. */
18313 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
18314 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
18315 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 18316 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 18317 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
18318 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18319 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
18320 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18321 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
18322 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18323 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
18324 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18325 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
18326 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18327 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
18328 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18329 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
18330 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18331 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18332 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18333 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18334
18335 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 18336 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
18337 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
18338
18339 /* Data processing with two registers and a shift amount. */
18340 /* Right shifts, and variants with rounding.
18341 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
18342 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18343 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18344 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18345 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18346 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18347 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18348 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18349 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18350 /* Shift and insert. Sizes accepted 8 16 32 64. */
18351 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
18352 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
18353 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
18354 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
18355 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
18356 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
18357 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
18358 /* Right shift immediate, saturating & narrowing, with rounding variants.
18359 Types accepted S16 S32 S64 U16 U32 U64. */
18360 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18361 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18362 /* As above, unsigned. Types accepted S16 S32 S64. */
18363 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18364 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18365 /* Right shift narrowing. Types accepted I16 I32 I64. */
18366 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18367 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18368 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 18369 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 18370 /* CVT with optional immediate for fixed-point variant. */
21d799b5 18371 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 18372
4316f0d2
DG
18373 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
18374 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
18375
18376 /* Data processing, three registers of different lengths. */
18377 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
18378 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
18379 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
18380 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
18381 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
18382 /* If not scalar, fall back to neon_dyadic_long.
18383 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
18384 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
18385 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
18386 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
18387 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18388 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18389 /* Dyadic, narrowing insns. Types I16 I32 I64. */
18390 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18391 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18392 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18393 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18394 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
18395 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18396 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18397 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
18398 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
18399 S16 S32 U16 U32. */
21d799b5 18400 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
18401
18402 /* Extract. Size 8. */
3b8d421e
PB
18403 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
18404 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
18405
18406 /* Two registers, miscellaneous. */
18407 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
18408 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
18409 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
18410 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
18411 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
18412 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
18413 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
18414 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
18415 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
18416 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
18417 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
18418 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
18419 /* VMOVN. Types I16 I32 I64. */
21d799b5 18420 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 18421 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 18422 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 18423 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 18424 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
18425 /* VZIP / VUZP. Sizes 8 16 32. */
18426 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
18427 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
18428 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
18429 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
18430 /* VQABS / VQNEG. Types S8 S16 S32. */
18431 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18432 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
18433 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18434 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
18435 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
18436 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
18437 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
18438 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
18439 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
18440 /* Reciprocal estimates. Types U32 F32. */
18441 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
18442 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
18443 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
18444 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
18445 /* VCLS. Types S8 S16 S32. */
18446 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
18447 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
18448 /* VCLZ. Types I8 I16 I32. */
18449 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
18450 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
18451 /* VCNT. Size 8. */
18452 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
18453 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
18454 /* Two address, untyped. */
18455 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
18456 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
18457 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
18458 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
18459 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
18460
18461 /* Table lookup. Size 8. */
18462 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18463 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18464
c921be7d
NC
18465#undef THUMB_VARIANT
18466#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
18467#undef ARM_VARIANT
18468#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
18469
5287ad62 18470 /* Neon element/structure load/store. */
21d799b5
NC
18471 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18472 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18473 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18474 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18475 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18476 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18477 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18478 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 18479
c921be7d 18480#undef THUMB_VARIANT
62f3b8c8
PB
18481#define THUMB_VARIANT &fpu_vfp_ext_v3xd
18482#undef ARM_VARIANT
18483#define ARM_VARIANT &fpu_vfp_ext_v3xd
18484 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
18485 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18486 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18487 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18488 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18489 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18490 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18491 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18492 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18493
18494#undef THUMB_VARIANT
c921be7d
NC
18495#define THUMB_VARIANT & fpu_vfp_ext_v3
18496#undef ARM_VARIANT
18497#define ARM_VARIANT & fpu_vfp_ext_v3
18498
21d799b5 18499 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 18500 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18501 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18502 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18503 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18504 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18505 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18506 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18507 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 18508
62f3b8c8
PB
18509#undef ARM_VARIANT
18510#define ARM_VARIANT &fpu_vfp_ext_fma
18511#undef THUMB_VARIANT
18512#define THUMB_VARIANT &fpu_vfp_ext_fma
18513 /* Mnemonics shared by Neon and VFP. These are included in the
18514 VFP FMA variant; NEON and VFP FMA always includes the NEON
18515 FMA instructions. */
18516 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18517 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18518 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
18519 the v form should always be used. */
18520 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18521 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18522 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18523 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18524 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18525 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18526
5287ad62 18527#undef THUMB_VARIANT
c921be7d
NC
18528#undef ARM_VARIANT
18529#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
18530
21d799b5
NC
18531 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18532 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18533 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18534 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18535 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18536 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18537 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
18538 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 18539
c921be7d
NC
18540#undef ARM_VARIANT
18541#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
18542
21d799b5
NC
18543 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
18544 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
18545 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
18546 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
18547 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
18548 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
18549 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
18550 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
18551 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
18552 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18553 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18554 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18555 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18556 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18557 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18558 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18559 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18560 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18561 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
18562 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
18563 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18564 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18565 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18566 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18567 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18568 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18569 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
18570 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
18571 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
18572 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
18573 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
18574 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
18575 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
18576 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
18577 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
18578 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
18579 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
18580 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18581 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18582 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18583 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18584 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18585 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18586 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18587 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18588 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18589 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
18590 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18591 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18592 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18593 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18594 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18595 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18596 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18597 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18598 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18599 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18600 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18601 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18602 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18603 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18604 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18605 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18606 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18607 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18608 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18609 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18610 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18611 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18612 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18613 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18614 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18615 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18616 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18617 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18618 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18619 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18620 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18621 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18622 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18623 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18624 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18625 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18626 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18627 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18628 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18629 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18630 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18631 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
18632 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18633 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18634 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18635 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18636 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18637 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18638 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18639 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18640 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18641 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18642 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18643 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18644 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18645 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18646 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18647 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18648 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18649 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18650 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18651 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18652 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18653 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
18654 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18655 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18656 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18657 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18658 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18659 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18660 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18661 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18662 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18663 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18664 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18665 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18666 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18667 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18668 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18669 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18670 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18671 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18672 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18673 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18674 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18675 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18676 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18677 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18678 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18679 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18680 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18681 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18682 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18683 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18684 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18685 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18686 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18687 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18688 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18689 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18690 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18691 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18692 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18693 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18694 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18695 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18696 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18697 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18698 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18699 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18700 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18701 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18702 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18703 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18704 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 18705
c921be7d
NC
18706#undef ARM_VARIANT
18707#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18708
21d799b5
NC
18709 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18710 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18711 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18712 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18713 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18714 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18715 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18716 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18717 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18718 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18719 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18720 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18721 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18722 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18723 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18724 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18725 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18726 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18727 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18728 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18729 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18730 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18731 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18732 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18733 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18734 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18735 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18736 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18737 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18738 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18739 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18740 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18741 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18742 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18743 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18744 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18745 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18746 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18747 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18748 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18749 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18750 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18751 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18752 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18753 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18754 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18755 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18756 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18757 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18758 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18759 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18760 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18761 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18762 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18763 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18764 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18765 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 18766
c921be7d
NC
18767#undef ARM_VARIANT
18768#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18769
21d799b5
NC
18770 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18771 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18772 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18773 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18774 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18775 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18776 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18777 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18778 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18779 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18780 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18781 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18782 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18783 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18784 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18785 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18786 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18787 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18788 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18789 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18790 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18791 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18792 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18793 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18794 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18795 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18796 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18797 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18798 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18799 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18800 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18801 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18802 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18803 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18804 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18805 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18806 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18807 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18808 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18809 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18810 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18811 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18812 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18813 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18814 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18815 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18816 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18817 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18818 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18819 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18820 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18821 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18822 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18823 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18824 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18825 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18826 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18827 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18828 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18829 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18830 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18831 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18832 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18833 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18834 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18835 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18836 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18837 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18838 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18839 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18840 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18841 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18842 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18843 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18844 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18845 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
18846};
18847#undef ARM_VARIANT
18848#undef THUMB_VARIANT
18849#undef TCE
18850#undef TCM
18851#undef TUE
18852#undef TUF
18853#undef TCC
8f06b2d8 18854#undef cCE
e3cb604e
PB
18855#undef cCL
18856#undef C3E
c19d1205
ZW
18857#undef CE
18858#undef CM
18859#undef UE
18860#undef UF
18861#undef UT
5287ad62
JB
18862#undef NUF
18863#undef nUF
18864#undef NCE
18865#undef nCE
c19d1205
ZW
18866#undef OPS0
18867#undef OPS1
18868#undef OPS2
18869#undef OPS3
18870#undef OPS4
18871#undef OPS5
18872#undef OPS6
18873#undef do_0
18874\f
18875/* MD interface: bits in the object file. */
bfae80f2 18876
c19d1205
ZW
18877/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18878 for use in the a.out file, and stores them in the array pointed to by buf.
18879 This knows about the endian-ness of the target machine and does
18880 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18881 2 (short) and 4 (long) Floating numbers are put out as a series of
18882 LITTLENUMS (shorts, here at least). */
b99bd4ef 18883
c19d1205
ZW
18884void
18885md_number_to_chars (char * buf, valueT val, int n)
18886{
18887 if (target_big_endian)
18888 number_to_chars_bigendian (buf, val, n);
18889 else
18890 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
18891}
18892
c19d1205
ZW
18893static valueT
18894md_chars_to_number (char * buf, int n)
bfae80f2 18895{
c19d1205
ZW
18896 valueT result = 0;
18897 unsigned char * where = (unsigned char *) buf;
bfae80f2 18898
c19d1205 18899 if (target_big_endian)
b99bd4ef 18900 {
c19d1205
ZW
18901 while (n--)
18902 {
18903 result <<= 8;
18904 result |= (*where++ & 255);
18905 }
b99bd4ef 18906 }
c19d1205 18907 else
b99bd4ef 18908 {
c19d1205
ZW
18909 while (n--)
18910 {
18911 result <<= 8;
18912 result |= (where[n] & 255);
18913 }
bfae80f2 18914 }
b99bd4ef 18915
c19d1205 18916 return result;
bfae80f2 18917}
b99bd4ef 18918
c19d1205 18919/* MD interface: Sections. */
b99bd4ef 18920
0110f2b8
PB
18921/* Estimate the size of a frag before relaxing. Assume everything fits in
18922 2 bytes. */
18923
c19d1205 18924int
0110f2b8 18925md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
18926 segT segtype ATTRIBUTE_UNUSED)
18927{
0110f2b8
PB
18928 fragp->fr_var = 2;
18929 return 2;
18930}
18931
18932/* Convert a machine dependent frag. */
18933
18934void
18935md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18936{
18937 unsigned long insn;
18938 unsigned long old_op;
18939 char *buf;
18940 expressionS exp;
18941 fixS *fixp;
18942 int reloc_type;
18943 int pc_rel;
18944 int opcode;
18945
18946 buf = fragp->fr_literal + fragp->fr_fix;
18947
18948 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
18949 if (fragp->fr_symbol)
18950 {
0110f2b8
PB
18951 exp.X_op = O_symbol;
18952 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
18953 }
18954 else
18955 {
0110f2b8 18956 exp.X_op = O_constant;
5f4273c7 18957 }
0110f2b8
PB
18958 exp.X_add_number = fragp->fr_offset;
18959 opcode = fragp->fr_subtype;
18960 switch (opcode)
18961 {
18962 case T_MNEM_ldr_pc:
18963 case T_MNEM_ldr_pc2:
18964 case T_MNEM_ldr_sp:
18965 case T_MNEM_str_sp:
18966 case T_MNEM_ldr:
18967 case T_MNEM_ldrb:
18968 case T_MNEM_ldrh:
18969 case T_MNEM_str:
18970 case T_MNEM_strb:
18971 case T_MNEM_strh:
18972 if (fragp->fr_var == 4)
18973 {
5f4273c7 18974 insn = THUMB_OP32 (opcode);
0110f2b8
PB
18975 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18976 {
18977 insn |= (old_op & 0x700) << 4;
18978 }
18979 else
18980 {
18981 insn |= (old_op & 7) << 12;
18982 insn |= (old_op & 0x38) << 13;
18983 }
18984 insn |= 0x00000c00;
18985 put_thumb32_insn (buf, insn);
18986 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18987 }
18988 else
18989 {
18990 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18991 }
18992 pc_rel = (opcode == T_MNEM_ldr_pc2);
18993 break;
18994 case T_MNEM_adr:
18995 if (fragp->fr_var == 4)
18996 {
18997 insn = THUMB_OP32 (opcode);
18998 insn |= (old_op & 0xf0) << 4;
18999 put_thumb32_insn (buf, insn);
19000 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
19001 }
19002 else
19003 {
19004 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19005 exp.X_add_number -= 4;
19006 }
19007 pc_rel = 1;
19008 break;
19009 case T_MNEM_mov:
19010 case T_MNEM_movs:
19011 case T_MNEM_cmp:
19012 case T_MNEM_cmn:
19013 if (fragp->fr_var == 4)
19014 {
19015 int r0off = (opcode == T_MNEM_mov
19016 || opcode == T_MNEM_movs) ? 0 : 8;
19017 insn = THUMB_OP32 (opcode);
19018 insn = (insn & 0xe1ffffff) | 0x10000000;
19019 insn |= (old_op & 0x700) << r0off;
19020 put_thumb32_insn (buf, insn);
19021 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
19022 }
19023 else
19024 {
19025 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
19026 }
19027 pc_rel = 0;
19028 break;
19029 case T_MNEM_b:
19030 if (fragp->fr_var == 4)
19031 {
19032 insn = THUMB_OP32(opcode);
19033 put_thumb32_insn (buf, insn);
19034 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
19035 }
19036 else
19037 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
19038 pc_rel = 1;
19039 break;
19040 case T_MNEM_bcond:
19041 if (fragp->fr_var == 4)
19042 {
19043 insn = THUMB_OP32(opcode);
19044 insn |= (old_op & 0xf00) << 14;
19045 put_thumb32_insn (buf, insn);
19046 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
19047 }
19048 else
19049 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
19050 pc_rel = 1;
19051 break;
19052 case T_MNEM_add_sp:
19053 case T_MNEM_add_pc:
19054 case T_MNEM_inc_sp:
19055 case T_MNEM_dec_sp:
19056 if (fragp->fr_var == 4)
19057 {
19058 /* ??? Choose between add and addw. */
19059 insn = THUMB_OP32 (opcode);
19060 insn |= (old_op & 0xf0) << 4;
19061 put_thumb32_insn (buf, insn);
16805f35
PB
19062 if (opcode == T_MNEM_add_pc)
19063 reloc_type = BFD_RELOC_ARM_T32_IMM12;
19064 else
19065 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
19066 }
19067 else
19068 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19069 pc_rel = 0;
19070 break;
19071
19072 case T_MNEM_addi:
19073 case T_MNEM_addis:
19074 case T_MNEM_subi:
19075 case T_MNEM_subis:
19076 if (fragp->fr_var == 4)
19077 {
19078 insn = THUMB_OP32 (opcode);
19079 insn |= (old_op & 0xf0) << 4;
19080 insn |= (old_op & 0xf) << 16;
19081 put_thumb32_insn (buf, insn);
16805f35
PB
19082 if (insn & (1 << 20))
19083 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
19084 else
19085 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
19086 }
19087 else
19088 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19089 pc_rel = 0;
19090 break;
19091 default:
5f4273c7 19092 abort ();
0110f2b8
PB
19093 }
19094 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 19095 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
19096 fixp->fx_file = fragp->fr_file;
19097 fixp->fx_line = fragp->fr_line;
19098 fragp->fr_fix += fragp->fr_var;
19099}
19100
19101/* Return the size of a relaxable immediate operand instruction.
19102 SHIFT and SIZE specify the form of the allowable immediate. */
19103static int
19104relax_immediate (fragS *fragp, int size, int shift)
19105{
19106 offsetT offset;
19107 offsetT mask;
19108 offsetT low;
19109
19110 /* ??? Should be able to do better than this. */
19111 if (fragp->fr_symbol)
19112 return 4;
19113
19114 low = (1 << shift) - 1;
19115 mask = (1 << (shift + size)) - (1 << shift);
19116 offset = fragp->fr_offset;
19117 /* Force misaligned offsets to 32-bit variant. */
19118 if (offset & low)
5e77afaa 19119 return 4;
0110f2b8
PB
19120 if (offset & ~mask)
19121 return 4;
19122 return 2;
19123}
19124
5e77afaa
PB
19125/* Get the address of a symbol during relaxation. */
19126static addressT
5f4273c7 19127relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
19128{
19129 fragS *sym_frag;
19130 addressT addr;
19131 symbolS *sym;
19132
19133 sym = fragp->fr_symbol;
19134 sym_frag = symbol_get_frag (sym);
19135 know (S_GET_SEGMENT (sym) != absolute_section
19136 || sym_frag == &zero_address_frag);
19137 addr = S_GET_VALUE (sym) + fragp->fr_offset;
19138
19139 /* If frag has yet to be reached on this pass, assume it will
19140 move by STRETCH just as we did. If this is not so, it will
19141 be because some frag between grows, and that will force
19142 another pass. */
19143
19144 if (stretch != 0
19145 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
19146 {
19147 fragS *f;
19148
19149 /* Adjust stretch for any alignment frag. Note that if have
19150 been expanding the earlier code, the symbol may be
19151 defined in what appears to be an earlier frag. FIXME:
19152 This doesn't handle the fr_subtype field, which specifies
19153 a maximum number of bytes to skip when doing an
19154 alignment. */
19155 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
19156 {
19157 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
19158 {
19159 if (stretch < 0)
19160 stretch = - ((- stretch)
19161 & ~ ((1 << (int) f->fr_offset) - 1));
19162 else
19163 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
19164 if (stretch == 0)
19165 break;
19166 }
19167 }
19168 if (f != NULL)
19169 addr += stretch;
19170 }
5e77afaa
PB
19171
19172 return addr;
19173}
19174
0110f2b8
PB
19175/* Return the size of a relaxable adr pseudo-instruction or PC-relative
19176 load. */
19177static int
5e77afaa 19178relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
19179{
19180 addressT addr;
19181 offsetT val;
19182
19183 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
19184 if (fragp->fr_symbol == NULL
19185 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
19186 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19187 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
19188 return 4;
19189
5f4273c7 19190 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
19191 addr = fragp->fr_address + fragp->fr_fix;
19192 addr = (addr + 4) & ~3;
5e77afaa 19193 /* Force misaligned targets to 32-bit variant. */
0110f2b8 19194 if (val & 3)
5e77afaa 19195 return 4;
0110f2b8
PB
19196 val -= addr;
19197 if (val < 0 || val > 1020)
19198 return 4;
19199 return 2;
19200}
19201
19202/* Return the size of a relaxable add/sub immediate instruction. */
19203static int
19204relax_addsub (fragS *fragp, asection *sec)
19205{
19206 char *buf;
19207 int op;
19208
19209 buf = fragp->fr_literal + fragp->fr_fix;
19210 op = bfd_get_16(sec->owner, buf);
19211 if ((op & 0xf) == ((op >> 4) & 0xf))
19212 return relax_immediate (fragp, 8, 0);
19213 else
19214 return relax_immediate (fragp, 3, 0);
19215}
19216
19217
19218/* Return the size of a relaxable branch instruction. BITS is the
19219 size of the offset field in the narrow instruction. */
19220
19221static int
5e77afaa 19222relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
19223{
19224 addressT addr;
19225 offsetT val;
19226 offsetT limit;
19227
19228 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 19229 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
19230 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19231 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
19232 return 4;
19233
267bf995
RR
19234#ifdef OBJ_ELF
19235 if (S_IS_DEFINED (fragp->fr_symbol)
19236 && ARM_IS_FUNC (fragp->fr_symbol))
19237 return 4;
0d9b4b55
NC
19238
19239 /* PR 12532. Global symbols with default visibility might
19240 be preempted, so do not relax relocations to them. */
19241 if ((ELF_ST_VISIBILITY (S_GET_OTHER (fragp->fr_symbol)) == STV_DEFAULT)
19242 && (! S_IS_LOCAL (fragp->fr_symbol)))
19243 return 4;
267bf995
RR
19244#endif
19245
5f4273c7 19246 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
19247 addr = fragp->fr_address + fragp->fr_fix + 4;
19248 val -= addr;
19249
19250 /* Offset is a signed value *2 */
19251 limit = 1 << bits;
19252 if (val >= limit || val < -limit)
19253 return 4;
19254 return 2;
19255}
19256
19257
19258/* Relax a machine dependent frag. This returns the amount by which
19259 the current size of the frag should change. */
19260
19261int
5e77afaa 19262arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
19263{
19264 int oldsize;
19265 int newsize;
19266
19267 oldsize = fragp->fr_var;
19268 switch (fragp->fr_subtype)
19269 {
19270 case T_MNEM_ldr_pc2:
5f4273c7 19271 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
19272 break;
19273 case T_MNEM_ldr_pc:
19274 case T_MNEM_ldr_sp:
19275 case T_MNEM_str_sp:
5f4273c7 19276 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
19277 break;
19278 case T_MNEM_ldr:
19279 case T_MNEM_str:
5f4273c7 19280 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
19281 break;
19282 case T_MNEM_ldrh:
19283 case T_MNEM_strh:
5f4273c7 19284 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
19285 break;
19286 case T_MNEM_ldrb:
19287 case T_MNEM_strb:
5f4273c7 19288 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
19289 break;
19290 case T_MNEM_adr:
5f4273c7 19291 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
19292 break;
19293 case T_MNEM_mov:
19294 case T_MNEM_movs:
19295 case T_MNEM_cmp:
19296 case T_MNEM_cmn:
5f4273c7 19297 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
19298 break;
19299 case T_MNEM_b:
5f4273c7 19300 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
19301 break;
19302 case T_MNEM_bcond:
5f4273c7 19303 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
19304 break;
19305 case T_MNEM_add_sp:
19306 case T_MNEM_add_pc:
19307 newsize = relax_immediate (fragp, 8, 2);
19308 break;
19309 case T_MNEM_inc_sp:
19310 case T_MNEM_dec_sp:
19311 newsize = relax_immediate (fragp, 7, 2);
19312 break;
19313 case T_MNEM_addi:
19314 case T_MNEM_addis:
19315 case T_MNEM_subi:
19316 case T_MNEM_subis:
19317 newsize = relax_addsub (fragp, sec);
19318 break;
19319 default:
5f4273c7 19320 abort ();
0110f2b8 19321 }
5e77afaa
PB
19322
19323 fragp->fr_var = newsize;
19324 /* Freeze wide instructions that are at or before the same location as
19325 in the previous pass. This avoids infinite loops.
5f4273c7
NC
19326 Don't freeze them unconditionally because targets may be artificially
19327 misaligned by the expansion of preceding frags. */
5e77afaa 19328 if (stretch <= 0 && newsize > 2)
0110f2b8 19329 {
0110f2b8 19330 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 19331 frag_wane (fragp);
0110f2b8 19332 }
5e77afaa 19333
0110f2b8 19334 return newsize - oldsize;
c19d1205 19335}
b99bd4ef 19336
c19d1205 19337/* Round up a section size to the appropriate boundary. */
b99bd4ef 19338
c19d1205
ZW
19339valueT
19340md_section_align (segT segment ATTRIBUTE_UNUSED,
19341 valueT size)
19342{
f0927246
NC
19343#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
19344 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
19345 {
19346 /* For a.out, force the section size to be aligned. If we don't do
19347 this, BFD will align it for us, but it will not write out the
19348 final bytes of the section. This may be a bug in BFD, but it is
19349 easier to fix it here since that is how the other a.out targets
19350 work. */
19351 int align;
19352
19353 align = bfd_get_section_alignment (stdoutput, segment);
19354 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
19355 }
c19d1205 19356#endif
f0927246
NC
19357
19358 return size;
bfae80f2 19359}
b99bd4ef 19360
c19d1205
ZW
19361/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
19362 of an rs_align_code fragment. */
19363
19364void
19365arm_handle_align (fragS * fragP)
bfae80f2 19366{
e7495e45
NS
19367 static char const arm_noop[2][2][4] =
19368 {
19369 { /* ARMv1 */
19370 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
19371 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
19372 },
19373 { /* ARMv6k */
19374 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
19375 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
19376 },
19377 };
19378 static char const thumb_noop[2][2][2] =
19379 {
19380 { /* Thumb-1 */
19381 {0xc0, 0x46}, /* LE */
19382 {0x46, 0xc0}, /* BE */
19383 },
19384 { /* Thumb-2 */
19385 {0x00, 0xbf}, /* LE */
19386 {0xbf, 0x00} /* BE */
19387 }
19388 };
19389 static char const wide_thumb_noop[2][4] =
19390 { /* Wide Thumb-2 */
19391 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
19392 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
19393 };
c921be7d 19394
e7495e45 19395 unsigned bytes, fix, noop_size;
c19d1205
ZW
19396 char * p;
19397 const char * noop;
e7495e45 19398 const char *narrow_noop = NULL;
cd000bff
DJ
19399#ifdef OBJ_ELF
19400 enum mstate state;
19401#endif
bfae80f2 19402
c19d1205 19403 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
19404 return;
19405
c19d1205
ZW
19406 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
19407 p = fragP->fr_literal + fragP->fr_fix;
19408 fix = 0;
bfae80f2 19409
c19d1205
ZW
19410 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
19411 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 19412
cd000bff 19413 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 19414
cd000bff 19415 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 19416 {
e7495e45
NS
19417 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
19418 {
19419 narrow_noop = thumb_noop[1][target_big_endian];
19420 noop = wide_thumb_noop[target_big_endian];
19421 }
c19d1205 19422 else
e7495e45
NS
19423 noop = thumb_noop[0][target_big_endian];
19424 noop_size = 2;
cd000bff
DJ
19425#ifdef OBJ_ELF
19426 state = MAP_THUMB;
19427#endif
7ed4c4c5
NC
19428 }
19429 else
19430 {
e7495e45
NS
19431 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
19432 [target_big_endian];
19433 noop_size = 4;
cd000bff
DJ
19434#ifdef OBJ_ELF
19435 state = MAP_ARM;
19436#endif
7ed4c4c5 19437 }
c921be7d 19438
e7495e45 19439 fragP->fr_var = noop_size;
c921be7d 19440
c19d1205 19441 if (bytes & (noop_size - 1))
7ed4c4c5 19442 {
c19d1205 19443 fix = bytes & (noop_size - 1);
cd000bff
DJ
19444#ifdef OBJ_ELF
19445 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
19446#endif
c19d1205
ZW
19447 memset (p, 0, fix);
19448 p += fix;
19449 bytes -= fix;
a737bd4d 19450 }
a737bd4d 19451
e7495e45
NS
19452 if (narrow_noop)
19453 {
19454 if (bytes & noop_size)
19455 {
19456 /* Insert a narrow noop. */
19457 memcpy (p, narrow_noop, noop_size);
19458 p += noop_size;
19459 bytes -= noop_size;
19460 fix += noop_size;
19461 }
19462
19463 /* Use wide noops for the remainder */
19464 noop_size = 4;
19465 }
19466
c19d1205 19467 while (bytes >= noop_size)
a737bd4d 19468 {
c19d1205
ZW
19469 memcpy (p, noop, noop_size);
19470 p += noop_size;
19471 bytes -= noop_size;
19472 fix += noop_size;
a737bd4d
NC
19473 }
19474
c19d1205 19475 fragP->fr_fix += fix;
a737bd4d
NC
19476}
19477
c19d1205
ZW
19478/* Called from md_do_align. Used to create an alignment
19479 frag in a code section. */
19480
19481void
19482arm_frag_align_code (int n, int max)
bfae80f2 19483{
c19d1205 19484 char * p;
7ed4c4c5 19485
c19d1205 19486 /* We assume that there will never be a requirement
6ec8e702 19487 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 19488 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
19489 {
19490 char err_msg[128];
19491
19492 sprintf (err_msg,
19493 _("alignments greater than %d bytes not supported in .text sections."),
19494 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 19495 as_fatal ("%s", err_msg);
6ec8e702 19496 }
bfae80f2 19497
c19d1205
ZW
19498 p = frag_var (rs_align_code,
19499 MAX_MEM_FOR_RS_ALIGN_CODE,
19500 1,
19501 (relax_substateT) max,
19502 (symbolS *) NULL,
19503 (offsetT) n,
19504 (char *) NULL);
19505 *p = 0;
19506}
bfae80f2 19507
8dc2430f
NC
19508/* Perform target specific initialisation of a frag.
19509 Note - despite the name this initialisation is not done when the frag
19510 is created, but only when its type is assigned. A frag can be created
19511 and used a long time before its type is set, so beware of assuming that
19512 this initialisationis performed first. */
bfae80f2 19513
cd000bff
DJ
19514#ifndef OBJ_ELF
19515void
19516arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
19517{
19518 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 19519 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
19520}
19521
19522#else /* OBJ_ELF is defined. */
c19d1205 19523void
cd000bff 19524arm_init_frag (fragS * fragP, int max_chars)
c19d1205 19525{
8dc2430f
NC
19526 /* If the current ARM vs THUMB mode has not already
19527 been recorded into this frag then do so now. */
cd000bff
DJ
19528 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
19529 {
19530 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19531
19532 /* Record a mapping symbol for alignment frags. We will delete this
19533 later if the alignment ends up empty. */
19534 switch (fragP->fr_type)
19535 {
19536 case rs_align:
19537 case rs_align_test:
19538 case rs_fill:
19539 mapping_state_2 (MAP_DATA, max_chars);
19540 break;
19541 case rs_align_code:
19542 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
19543 break;
19544 default:
19545 break;
19546 }
19547 }
bfae80f2
RE
19548}
19549
c19d1205
ZW
19550/* When we change sections we need to issue a new mapping symbol. */
19551
19552void
19553arm_elf_change_section (void)
bfae80f2 19554{
c19d1205
ZW
19555 /* Link an unlinked unwind index table section to the .text section. */
19556 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
19557 && elf_linked_to_section (now_seg) == NULL)
19558 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
19559}
19560
c19d1205
ZW
19561int
19562arm_elf_section_type (const char * str, size_t len)
e45d0630 19563{
c19d1205
ZW
19564 if (len == 5 && strncmp (str, "exidx", 5) == 0)
19565 return SHT_ARM_EXIDX;
e45d0630 19566
c19d1205
ZW
19567 return -1;
19568}
19569\f
19570/* Code to deal with unwinding tables. */
e45d0630 19571
c19d1205 19572static void add_unwind_adjustsp (offsetT);
e45d0630 19573
5f4273c7 19574/* Generate any deferred unwind frame offset. */
e45d0630 19575
bfae80f2 19576static void
c19d1205 19577flush_pending_unwind (void)
bfae80f2 19578{
c19d1205 19579 offsetT offset;
bfae80f2 19580
c19d1205
ZW
19581 offset = unwind.pending_offset;
19582 unwind.pending_offset = 0;
19583 if (offset != 0)
19584 add_unwind_adjustsp (offset);
bfae80f2
RE
19585}
19586
c19d1205
ZW
19587/* Add an opcode to this list for this function. Two-byte opcodes should
19588 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
19589 order. */
19590
bfae80f2 19591static void
c19d1205 19592add_unwind_opcode (valueT op, int length)
bfae80f2 19593{
c19d1205
ZW
19594 /* Add any deferred stack adjustment. */
19595 if (unwind.pending_offset)
19596 flush_pending_unwind ();
bfae80f2 19597
c19d1205 19598 unwind.sp_restored = 0;
bfae80f2 19599
c19d1205 19600 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 19601 {
c19d1205
ZW
19602 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
19603 if (unwind.opcodes)
21d799b5
NC
19604 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
19605 unwind.opcode_alloc);
c19d1205 19606 else
21d799b5 19607 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 19608 }
c19d1205 19609 while (length > 0)
bfae80f2 19610 {
c19d1205
ZW
19611 length--;
19612 unwind.opcodes[unwind.opcode_count] = op & 0xff;
19613 op >>= 8;
19614 unwind.opcode_count++;
bfae80f2 19615 }
bfae80f2
RE
19616}
19617
c19d1205
ZW
19618/* Add unwind opcodes to adjust the stack pointer. */
19619
bfae80f2 19620static void
c19d1205 19621add_unwind_adjustsp (offsetT offset)
bfae80f2 19622{
c19d1205 19623 valueT op;
bfae80f2 19624
c19d1205 19625 if (offset > 0x200)
bfae80f2 19626 {
c19d1205
ZW
19627 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
19628 char bytes[5];
19629 int n;
19630 valueT o;
bfae80f2 19631
c19d1205
ZW
19632 /* Long form: 0xb2, uleb128. */
19633 /* This might not fit in a word so add the individual bytes,
19634 remembering the list is built in reverse order. */
19635 o = (valueT) ((offset - 0x204) >> 2);
19636 if (o == 0)
19637 add_unwind_opcode (0, 1);
bfae80f2 19638
c19d1205
ZW
19639 /* Calculate the uleb128 encoding of the offset. */
19640 n = 0;
19641 while (o)
19642 {
19643 bytes[n] = o & 0x7f;
19644 o >>= 7;
19645 if (o)
19646 bytes[n] |= 0x80;
19647 n++;
19648 }
19649 /* Add the insn. */
19650 for (; n; n--)
19651 add_unwind_opcode (bytes[n - 1], 1);
19652 add_unwind_opcode (0xb2, 1);
19653 }
19654 else if (offset > 0x100)
bfae80f2 19655 {
c19d1205
ZW
19656 /* Two short opcodes. */
19657 add_unwind_opcode (0x3f, 1);
19658 op = (offset - 0x104) >> 2;
19659 add_unwind_opcode (op, 1);
bfae80f2 19660 }
c19d1205
ZW
19661 else if (offset > 0)
19662 {
19663 /* Short opcode. */
19664 op = (offset - 4) >> 2;
19665 add_unwind_opcode (op, 1);
19666 }
19667 else if (offset < 0)
bfae80f2 19668 {
c19d1205
ZW
19669 offset = -offset;
19670 while (offset > 0x100)
bfae80f2 19671 {
c19d1205
ZW
19672 add_unwind_opcode (0x7f, 1);
19673 offset -= 0x100;
bfae80f2 19674 }
c19d1205
ZW
19675 op = ((offset - 4) >> 2) | 0x40;
19676 add_unwind_opcode (op, 1);
bfae80f2 19677 }
bfae80f2
RE
19678}
19679
c19d1205
ZW
19680/* Finish the list of unwind opcodes for this function. */
19681static void
19682finish_unwind_opcodes (void)
bfae80f2 19683{
c19d1205 19684 valueT op;
bfae80f2 19685
c19d1205 19686 if (unwind.fp_used)
bfae80f2 19687 {
708587a4 19688 /* Adjust sp as necessary. */
c19d1205
ZW
19689 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19690 flush_pending_unwind ();
bfae80f2 19691
c19d1205
ZW
19692 /* After restoring sp from the frame pointer. */
19693 op = 0x90 | unwind.fp_reg;
19694 add_unwind_opcode (op, 1);
19695 }
19696 else
19697 flush_pending_unwind ();
bfae80f2
RE
19698}
19699
bfae80f2 19700
c19d1205
ZW
19701/* Start an exception table entry. If idx is nonzero this is an index table
19702 entry. */
bfae80f2
RE
19703
19704static void
c19d1205 19705start_unwind_section (const segT text_seg, int idx)
bfae80f2 19706{
c19d1205
ZW
19707 const char * text_name;
19708 const char * prefix;
19709 const char * prefix_once;
19710 const char * group_name;
19711 size_t prefix_len;
19712 size_t text_len;
19713 char * sec_name;
19714 size_t sec_name_len;
19715 int type;
19716 int flags;
19717 int linkonce;
bfae80f2 19718
c19d1205 19719 if (idx)
bfae80f2 19720 {
c19d1205
ZW
19721 prefix = ELF_STRING_ARM_unwind;
19722 prefix_once = ELF_STRING_ARM_unwind_once;
19723 type = SHT_ARM_EXIDX;
bfae80f2 19724 }
c19d1205 19725 else
bfae80f2 19726 {
c19d1205
ZW
19727 prefix = ELF_STRING_ARM_unwind_info;
19728 prefix_once = ELF_STRING_ARM_unwind_info_once;
19729 type = SHT_PROGBITS;
bfae80f2
RE
19730 }
19731
c19d1205
ZW
19732 text_name = segment_name (text_seg);
19733 if (streq (text_name, ".text"))
19734 text_name = "";
19735
19736 if (strncmp (text_name, ".gnu.linkonce.t.",
19737 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 19738 {
c19d1205
ZW
19739 prefix = prefix_once;
19740 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
19741 }
19742
c19d1205
ZW
19743 prefix_len = strlen (prefix);
19744 text_len = strlen (text_name);
19745 sec_name_len = prefix_len + text_len;
21d799b5 19746 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
19747 memcpy (sec_name, prefix, prefix_len);
19748 memcpy (sec_name + prefix_len, text_name, text_len);
19749 sec_name[prefix_len + text_len] = '\0';
bfae80f2 19750
c19d1205
ZW
19751 flags = SHF_ALLOC;
19752 linkonce = 0;
19753 group_name = 0;
bfae80f2 19754
c19d1205
ZW
19755 /* Handle COMDAT group. */
19756 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 19757 {
c19d1205
ZW
19758 group_name = elf_group_name (text_seg);
19759 if (group_name == NULL)
19760 {
bd3ba5d1 19761 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
19762 segment_name (text_seg));
19763 ignore_rest_of_line ();
19764 return;
19765 }
19766 flags |= SHF_GROUP;
19767 linkonce = 1;
bfae80f2
RE
19768 }
19769
c19d1205 19770 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 19771
5f4273c7 19772 /* Set the section link for index tables. */
c19d1205
ZW
19773 if (idx)
19774 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
19775}
19776
bfae80f2 19777
c19d1205
ZW
19778/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19779 personality routine data. Returns zero, or the index table value for
19780 and inline entry. */
19781
19782static valueT
19783create_unwind_entry (int have_data)
bfae80f2 19784{
c19d1205
ZW
19785 int size;
19786 addressT where;
19787 char *ptr;
19788 /* The current word of data. */
19789 valueT data;
19790 /* The number of bytes left in this word. */
19791 int n;
bfae80f2 19792
c19d1205 19793 finish_unwind_opcodes ();
bfae80f2 19794
c19d1205
ZW
19795 /* Remember the current text section. */
19796 unwind.saved_seg = now_seg;
19797 unwind.saved_subseg = now_subseg;
bfae80f2 19798
c19d1205 19799 start_unwind_section (now_seg, 0);
bfae80f2 19800
c19d1205 19801 if (unwind.personality_routine == NULL)
bfae80f2 19802 {
c19d1205
ZW
19803 if (unwind.personality_index == -2)
19804 {
19805 if (have_data)
5f4273c7 19806 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
19807 return 1; /* EXIDX_CANTUNWIND. */
19808 }
bfae80f2 19809
c19d1205
ZW
19810 /* Use a default personality routine if none is specified. */
19811 if (unwind.personality_index == -1)
19812 {
19813 if (unwind.opcode_count > 3)
19814 unwind.personality_index = 1;
19815 else
19816 unwind.personality_index = 0;
19817 }
bfae80f2 19818
c19d1205
ZW
19819 /* Space for the personality routine entry. */
19820 if (unwind.personality_index == 0)
19821 {
19822 if (unwind.opcode_count > 3)
19823 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 19824
c19d1205
ZW
19825 if (!have_data)
19826 {
19827 /* All the data is inline in the index table. */
19828 data = 0x80;
19829 n = 3;
19830 while (unwind.opcode_count > 0)
19831 {
19832 unwind.opcode_count--;
19833 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19834 n--;
19835 }
bfae80f2 19836
c19d1205
ZW
19837 /* Pad with "finish" opcodes. */
19838 while (n--)
19839 data = (data << 8) | 0xb0;
bfae80f2 19840
c19d1205
ZW
19841 return data;
19842 }
19843 size = 0;
19844 }
19845 else
19846 /* We get two opcodes "free" in the first word. */
19847 size = unwind.opcode_count - 2;
19848 }
19849 else
19850 /* An extra byte is required for the opcode count. */
19851 size = unwind.opcode_count + 1;
bfae80f2 19852
c19d1205
ZW
19853 size = (size + 3) >> 2;
19854 if (size > 0xff)
19855 as_bad (_("too many unwind opcodes"));
bfae80f2 19856
c19d1205
ZW
19857 frag_align (2, 0, 0);
19858 record_alignment (now_seg, 2);
19859 unwind.table_entry = expr_build_dot ();
19860
19861 /* Allocate the table entry. */
19862 ptr = frag_more ((size << 2) + 4);
19863 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 19864
c19d1205 19865 switch (unwind.personality_index)
bfae80f2 19866 {
c19d1205
ZW
19867 case -1:
19868 /* ??? Should this be a PLT generating relocation? */
19869 /* Custom personality routine. */
19870 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19871 BFD_RELOC_ARM_PREL31);
bfae80f2 19872
c19d1205
ZW
19873 where += 4;
19874 ptr += 4;
bfae80f2 19875
c19d1205
ZW
19876 /* Set the first byte to the number of additional words. */
19877 data = size - 1;
19878 n = 3;
19879 break;
bfae80f2 19880
c19d1205
ZW
19881 /* ABI defined personality routines. */
19882 case 0:
19883 /* Three opcodes bytes are packed into the first word. */
19884 data = 0x80;
19885 n = 3;
19886 break;
bfae80f2 19887
c19d1205
ZW
19888 case 1:
19889 case 2:
19890 /* The size and first two opcode bytes go in the first word. */
19891 data = ((0x80 + unwind.personality_index) << 8) | size;
19892 n = 2;
19893 break;
bfae80f2 19894
c19d1205
ZW
19895 default:
19896 /* Should never happen. */
19897 abort ();
19898 }
bfae80f2 19899
c19d1205
ZW
19900 /* Pack the opcodes into words (MSB first), reversing the list at the same
19901 time. */
19902 while (unwind.opcode_count > 0)
19903 {
19904 if (n == 0)
19905 {
19906 md_number_to_chars (ptr, data, 4);
19907 ptr += 4;
19908 n = 4;
19909 data = 0;
19910 }
19911 unwind.opcode_count--;
19912 n--;
19913 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19914 }
19915
19916 /* Finish off the last word. */
19917 if (n < 4)
19918 {
19919 /* Pad with "finish" opcodes. */
19920 while (n--)
19921 data = (data << 8) | 0xb0;
19922
19923 md_number_to_chars (ptr, data, 4);
19924 }
19925
19926 if (!have_data)
19927 {
19928 /* Add an empty descriptor if there is no user-specified data. */
19929 ptr = frag_more (4);
19930 md_number_to_chars (ptr, 0, 4);
19931 }
19932
19933 return 0;
bfae80f2
RE
19934}
19935
f0927246
NC
19936
19937/* Initialize the DWARF-2 unwind information for this procedure. */
19938
19939void
19940tc_arm_frame_initial_instructions (void)
19941{
19942 cfi_add_CFA_def_cfa (REG_SP, 0);
19943}
19944#endif /* OBJ_ELF */
19945
c19d1205
ZW
19946/* Convert REGNAME to a DWARF-2 register number. */
19947
19948int
1df69f4f 19949tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 19950{
1df69f4f 19951 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
19952
19953 if (reg == FAIL)
19954 return -1;
19955
19956 return reg;
bfae80f2
RE
19957}
19958
f0927246 19959#ifdef TE_PE
c19d1205 19960void
f0927246 19961tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 19962{
91d6fa6a 19963 expressionS exp;
bfae80f2 19964
91d6fa6a
NC
19965 exp.X_op = O_secrel;
19966 exp.X_add_symbol = symbol;
19967 exp.X_add_number = 0;
19968 emit_expr (&exp, size);
f0927246
NC
19969}
19970#endif
bfae80f2 19971
c19d1205 19972/* MD interface: Symbol and relocation handling. */
bfae80f2 19973
2fc8bdac
ZW
19974/* Return the address within the segment that a PC-relative fixup is
19975 relative to. For ARM, PC-relative fixups applied to instructions
19976 are generally relative to the location of the fixup plus 8 bytes.
19977 Thumb branches are offset by 4, and Thumb loads relative to PC
19978 require special handling. */
bfae80f2 19979
c19d1205 19980long
2fc8bdac 19981md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 19982{
2fc8bdac
ZW
19983 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19984
19985 /* If this is pc-relative and we are going to emit a relocation
19986 then we just want to put out any pipeline compensation that the linker
53baae48
NC
19987 will need. Otherwise we want to use the calculated base.
19988 For WinCE we skip the bias for externals as well, since this
19989 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 19990 if (fixP->fx_pcrel
2fc8bdac 19991 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
19992 || (arm_force_relocation (fixP)
19993#ifdef TE_WINCE
19994 && !S_IS_EXTERNAL (fixP->fx_addsy)
19995#endif
19996 )))
2fc8bdac 19997 base = 0;
bfae80f2 19998
267bf995 19999
c19d1205 20000 switch (fixP->fx_r_type)
bfae80f2 20001 {
2fc8bdac
ZW
20002 /* PC relative addressing on the Thumb is slightly odd as the
20003 bottom two bits of the PC are forced to zero for the
20004 calculation. This happens *after* application of the
20005 pipeline offset. However, Thumb adrl already adjusts for
20006 this, so we need not do it again. */
c19d1205 20007 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 20008 return base & ~3;
c19d1205
ZW
20009
20010 case BFD_RELOC_ARM_THUMB_OFFSET:
20011 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 20012 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 20013 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 20014 return (base + 4) & ~3;
c19d1205 20015
2fc8bdac
ZW
20016 /* Thumb branches are simply offset by +4. */
20017 case BFD_RELOC_THUMB_PCREL_BRANCH7:
20018 case BFD_RELOC_THUMB_PCREL_BRANCH9:
20019 case BFD_RELOC_THUMB_PCREL_BRANCH12:
20020 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 20021 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 20022 return base + 4;
bfae80f2 20023
267bf995 20024 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
20025 if (fixP->fx_addsy
20026 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20027 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20028 && ARM_IS_FUNC (fixP->fx_addsy)
20029 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20030 base = fixP->fx_where + fixP->fx_frag->fr_address;
20031 return base + 4;
20032
00adf2d4
JB
20033 /* BLX is like branches above, but forces the low two bits of PC to
20034 zero. */
486499d0
CL
20035 case BFD_RELOC_THUMB_PCREL_BLX:
20036 if (fixP->fx_addsy
20037 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20038 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20039 && THUMB_IS_FUNC (fixP->fx_addsy)
20040 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20041 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
20042 return (base + 4) & ~3;
20043
2fc8bdac
ZW
20044 /* ARM mode branches are offset by +8. However, the Windows CE
20045 loader expects the relocation not to take this into account. */
267bf995 20046 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
20047 if (fixP->fx_addsy
20048 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20049 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20050 && ARM_IS_FUNC (fixP->fx_addsy)
20051 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20052 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 20053 return base + 8;
267bf995 20054
486499d0
CL
20055 case BFD_RELOC_ARM_PCREL_CALL:
20056 if (fixP->fx_addsy
20057 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20058 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20059 && THUMB_IS_FUNC (fixP->fx_addsy)
20060 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20061 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 20062 return base + 8;
267bf995 20063
2fc8bdac 20064 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 20065 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 20066 case BFD_RELOC_ARM_PLT32:
c19d1205 20067#ifdef TE_WINCE
5f4273c7 20068 /* When handling fixups immediately, because we have already
53baae48
NC
20069 discovered the value of a symbol, or the address of the frag involved
20070 we must account for the offset by +8, as the OS loader will never see the reloc.
20071 see fixup_segment() in write.c
20072 The S_IS_EXTERNAL test handles the case of global symbols.
20073 Those need the calculated base, not just the pipe compensation the linker will need. */
20074 if (fixP->fx_pcrel
20075 && fixP->fx_addsy != NULL
20076 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20077 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
20078 return base + 8;
2fc8bdac 20079 return base;
c19d1205 20080#else
2fc8bdac 20081 return base + 8;
c19d1205 20082#endif
2fc8bdac 20083
267bf995 20084
2fc8bdac
ZW
20085 /* ARM mode loads relative to PC are also offset by +8. Unlike
20086 branches, the Windows CE loader *does* expect the relocation
20087 to take this into account. */
20088 case BFD_RELOC_ARM_OFFSET_IMM:
20089 case BFD_RELOC_ARM_OFFSET_IMM8:
20090 case BFD_RELOC_ARM_HWLITERAL:
20091 case BFD_RELOC_ARM_LITERAL:
20092 case BFD_RELOC_ARM_CP_OFF_IMM:
20093 return base + 8;
20094
20095
20096 /* Other PC-relative relocations are un-offset. */
20097 default:
20098 return base;
20099 }
bfae80f2
RE
20100}
20101
c19d1205
ZW
20102/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
20103 Otherwise we have no need to default values of symbols. */
20104
20105symbolS *
20106md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 20107{
c19d1205
ZW
20108#ifdef OBJ_ELF
20109 if (name[0] == '_' && name[1] == 'G'
20110 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
20111 {
20112 if (!GOT_symbol)
20113 {
20114 if (symbol_find (name))
bd3ba5d1 20115 as_bad (_("GOT already in the symbol table"));
bfae80f2 20116
c19d1205
ZW
20117 GOT_symbol = symbol_new (name, undefined_section,
20118 (valueT) 0, & zero_address_frag);
20119 }
bfae80f2 20120
c19d1205 20121 return GOT_symbol;
bfae80f2 20122 }
c19d1205 20123#endif
bfae80f2 20124
c921be7d 20125 return NULL;
bfae80f2
RE
20126}
20127
55cf6793 20128/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
20129 computed as two separate immediate values, added together. We
20130 already know that this value cannot be computed by just one ARM
20131 instruction. */
20132
20133static unsigned int
20134validate_immediate_twopart (unsigned int val,
20135 unsigned int * highpart)
bfae80f2 20136{
c19d1205
ZW
20137 unsigned int a;
20138 unsigned int i;
bfae80f2 20139
c19d1205
ZW
20140 for (i = 0; i < 32; i += 2)
20141 if (((a = rotate_left (val, i)) & 0xff) != 0)
20142 {
20143 if (a & 0xff00)
20144 {
20145 if (a & ~ 0xffff)
20146 continue;
20147 * highpart = (a >> 8) | ((i + 24) << 7);
20148 }
20149 else if (a & 0xff0000)
20150 {
20151 if (a & 0xff000000)
20152 continue;
20153 * highpart = (a >> 16) | ((i + 16) << 7);
20154 }
20155 else
20156 {
9c2799c2 20157 gas_assert (a & 0xff000000);
c19d1205
ZW
20158 * highpart = (a >> 24) | ((i + 8) << 7);
20159 }
bfae80f2 20160
c19d1205
ZW
20161 return (a & 0xff) | (i << 7);
20162 }
bfae80f2 20163
c19d1205 20164 return FAIL;
bfae80f2
RE
20165}
20166
c19d1205
ZW
20167static int
20168validate_offset_imm (unsigned int val, int hwse)
20169{
20170 if ((hwse && val > 255) || val > 4095)
20171 return FAIL;
20172 return val;
20173}
bfae80f2 20174
55cf6793 20175/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
20176 negative immediate constant by altering the instruction. A bit of
20177 a hack really.
20178 MOV <-> MVN
20179 AND <-> BIC
20180 ADC <-> SBC
20181 by inverting the second operand, and
20182 ADD <-> SUB
20183 CMP <-> CMN
20184 by negating the second operand. */
bfae80f2 20185
c19d1205
ZW
20186static int
20187negate_data_op (unsigned long * instruction,
20188 unsigned long value)
bfae80f2 20189{
c19d1205
ZW
20190 int op, new_inst;
20191 unsigned long negated, inverted;
bfae80f2 20192
c19d1205
ZW
20193 negated = encode_arm_immediate (-value);
20194 inverted = encode_arm_immediate (~value);
bfae80f2 20195
c19d1205
ZW
20196 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
20197 switch (op)
bfae80f2 20198 {
c19d1205
ZW
20199 /* First negates. */
20200 case OPCODE_SUB: /* ADD <-> SUB */
20201 new_inst = OPCODE_ADD;
20202 value = negated;
20203 break;
bfae80f2 20204
c19d1205
ZW
20205 case OPCODE_ADD:
20206 new_inst = OPCODE_SUB;
20207 value = negated;
20208 break;
bfae80f2 20209
c19d1205
ZW
20210 case OPCODE_CMP: /* CMP <-> CMN */
20211 new_inst = OPCODE_CMN;
20212 value = negated;
20213 break;
bfae80f2 20214
c19d1205
ZW
20215 case OPCODE_CMN:
20216 new_inst = OPCODE_CMP;
20217 value = negated;
20218 break;
bfae80f2 20219
c19d1205
ZW
20220 /* Now Inverted ops. */
20221 case OPCODE_MOV: /* MOV <-> MVN */
20222 new_inst = OPCODE_MVN;
20223 value = inverted;
20224 break;
bfae80f2 20225
c19d1205
ZW
20226 case OPCODE_MVN:
20227 new_inst = OPCODE_MOV;
20228 value = inverted;
20229 break;
bfae80f2 20230
c19d1205
ZW
20231 case OPCODE_AND: /* AND <-> BIC */
20232 new_inst = OPCODE_BIC;
20233 value = inverted;
20234 break;
bfae80f2 20235
c19d1205
ZW
20236 case OPCODE_BIC:
20237 new_inst = OPCODE_AND;
20238 value = inverted;
20239 break;
bfae80f2 20240
c19d1205
ZW
20241 case OPCODE_ADC: /* ADC <-> SBC */
20242 new_inst = OPCODE_SBC;
20243 value = inverted;
20244 break;
bfae80f2 20245
c19d1205
ZW
20246 case OPCODE_SBC:
20247 new_inst = OPCODE_ADC;
20248 value = inverted;
20249 break;
bfae80f2 20250
c19d1205
ZW
20251 /* We cannot do anything. */
20252 default:
20253 return FAIL;
b99bd4ef
NC
20254 }
20255
c19d1205
ZW
20256 if (value == (unsigned) FAIL)
20257 return FAIL;
20258
20259 *instruction &= OPCODE_MASK;
20260 *instruction |= new_inst << DATA_OP_SHIFT;
20261 return value;
b99bd4ef
NC
20262}
20263
ef8d22e6
PB
20264/* Like negate_data_op, but for Thumb-2. */
20265
20266static unsigned int
16dd5e42 20267thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
20268{
20269 int op, new_inst;
20270 int rd;
16dd5e42 20271 unsigned int negated, inverted;
ef8d22e6
PB
20272
20273 negated = encode_thumb32_immediate (-value);
20274 inverted = encode_thumb32_immediate (~value);
20275
20276 rd = (*instruction >> 8) & 0xf;
20277 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
20278 switch (op)
20279 {
20280 /* ADD <-> SUB. Includes CMP <-> CMN. */
20281 case T2_OPCODE_SUB:
20282 new_inst = T2_OPCODE_ADD;
20283 value = negated;
20284 break;
20285
20286 case T2_OPCODE_ADD:
20287 new_inst = T2_OPCODE_SUB;
20288 value = negated;
20289 break;
20290
20291 /* ORR <-> ORN. Includes MOV <-> MVN. */
20292 case T2_OPCODE_ORR:
20293 new_inst = T2_OPCODE_ORN;
20294 value = inverted;
20295 break;
20296
20297 case T2_OPCODE_ORN:
20298 new_inst = T2_OPCODE_ORR;
20299 value = inverted;
20300 break;
20301
20302 /* AND <-> BIC. TST has no inverted equivalent. */
20303 case T2_OPCODE_AND:
20304 new_inst = T2_OPCODE_BIC;
20305 if (rd == 15)
20306 value = FAIL;
20307 else
20308 value = inverted;
20309 break;
20310
20311 case T2_OPCODE_BIC:
20312 new_inst = T2_OPCODE_AND;
20313 value = inverted;
20314 break;
20315
20316 /* ADC <-> SBC */
20317 case T2_OPCODE_ADC:
20318 new_inst = T2_OPCODE_SBC;
20319 value = inverted;
20320 break;
20321
20322 case T2_OPCODE_SBC:
20323 new_inst = T2_OPCODE_ADC;
20324 value = inverted;
20325 break;
20326
20327 /* We cannot do anything. */
20328 default:
20329 return FAIL;
20330 }
20331
16dd5e42 20332 if (value == (unsigned int)FAIL)
ef8d22e6
PB
20333 return FAIL;
20334
20335 *instruction &= T2_OPCODE_MASK;
20336 *instruction |= new_inst << T2_DATA_OP_SHIFT;
20337 return value;
20338}
20339
8f06b2d8
PB
20340/* Read a 32-bit thumb instruction from buf. */
20341static unsigned long
20342get_thumb32_insn (char * buf)
20343{
20344 unsigned long insn;
20345 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
20346 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20347
20348 return insn;
20349}
20350
a8bc6c78
PB
20351
20352/* We usually want to set the low bit on the address of thumb function
20353 symbols. In particular .word foo - . should have the low bit set.
20354 Generic code tries to fold the difference of two symbols to
20355 a constant. Prevent this and force a relocation when the first symbols
20356 is a thumb function. */
c921be7d
NC
20357
20358bfd_boolean
a8bc6c78
PB
20359arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
20360{
20361 if (op == O_subtract
20362 && l->X_op == O_symbol
20363 && r->X_op == O_symbol
20364 && THUMB_IS_FUNC (l->X_add_symbol))
20365 {
20366 l->X_op = O_subtract;
20367 l->X_op_symbol = r->X_add_symbol;
20368 l->X_add_number -= r->X_add_number;
c921be7d 20369 return TRUE;
a8bc6c78 20370 }
c921be7d 20371
a8bc6c78 20372 /* Process as normal. */
c921be7d 20373 return FALSE;
a8bc6c78
PB
20374}
20375
4a42ebbc
RR
20376/* Encode Thumb2 unconditional branches and calls. The encoding
20377 for the 2 are identical for the immediate values. */
20378
20379static void
20380encode_thumb2_b_bl_offset (char * buf, offsetT value)
20381{
20382#define T2I1I2MASK ((1 << 13) | (1 << 11))
20383 offsetT newval;
20384 offsetT newval2;
20385 addressT S, I1, I2, lo, hi;
20386
20387 S = (value >> 24) & 0x01;
20388 I1 = (value >> 23) & 0x01;
20389 I2 = (value >> 22) & 0x01;
20390 hi = (value >> 12) & 0x3ff;
20391 lo = (value >> 1) & 0x7ff;
20392 newval = md_chars_to_number (buf, THUMB_SIZE);
20393 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20394 newval |= (S << 10) | hi;
20395 newval2 &= ~T2I1I2MASK;
20396 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
20397 md_number_to_chars (buf, newval, THUMB_SIZE);
20398 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20399}
20400
c19d1205 20401void
55cf6793 20402md_apply_fix (fixS * fixP,
c19d1205
ZW
20403 valueT * valP,
20404 segT seg)
20405{
20406 offsetT value = * valP;
20407 offsetT newval;
20408 unsigned int newimm;
20409 unsigned long temp;
20410 int sign;
20411 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 20412
9c2799c2 20413 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 20414
c19d1205 20415 /* Note whether this will delete the relocation. */
4962c51a 20416
c19d1205
ZW
20417 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
20418 fixP->fx_done = 1;
b99bd4ef 20419
adbaf948 20420 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 20421 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
20422 for emit_reloc. */
20423 value &= 0xffffffff;
20424 value ^= 0x80000000;
5f4273c7 20425 value -= 0x80000000;
adbaf948
ZW
20426
20427 *valP = value;
c19d1205 20428 fixP->fx_addnumber = value;
b99bd4ef 20429
adbaf948
ZW
20430 /* Same treatment for fixP->fx_offset. */
20431 fixP->fx_offset &= 0xffffffff;
20432 fixP->fx_offset ^= 0x80000000;
20433 fixP->fx_offset -= 0x80000000;
20434
c19d1205 20435 switch (fixP->fx_r_type)
b99bd4ef 20436 {
c19d1205
ZW
20437 case BFD_RELOC_NONE:
20438 /* This will need to go in the object file. */
20439 fixP->fx_done = 0;
20440 break;
b99bd4ef 20441
c19d1205
ZW
20442 case BFD_RELOC_ARM_IMMEDIATE:
20443 /* We claim that this fixup has been processed here,
20444 even if in fact we generate an error because we do
20445 not have a reloc for it, so tc_gen_reloc will reject it. */
20446 fixP->fx_done = 1;
b99bd4ef 20447
77db8e2e 20448 if (fixP->fx_addsy)
b99bd4ef 20449 {
77db8e2e 20450 const char *msg = 0;
b99bd4ef 20451
77db8e2e
NC
20452 if (! S_IS_DEFINED (fixP->fx_addsy))
20453 msg = _("undefined symbol %s used as an immediate value");
20454 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20455 msg = _("symbol %s is in a different section");
20456 else if (S_IS_WEAK (fixP->fx_addsy))
20457 msg = _("symbol %s is weak and may be overridden later");
20458
20459 if (msg)
20460 {
20461 as_bad_where (fixP->fx_file, fixP->fx_line,
20462 msg, S_GET_NAME (fixP->fx_addsy));
20463 break;
20464 }
42e5fcbf
AS
20465 }
20466
c19d1205
ZW
20467 newimm = encode_arm_immediate (value);
20468 temp = md_chars_to_number (buf, INSN_SIZE);
20469
20470 /* If the instruction will fail, see if we can fix things up by
20471 changing the opcode. */
20472 if (newimm == (unsigned int) FAIL
20473 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 20474 {
c19d1205
ZW
20475 as_bad_where (fixP->fx_file, fixP->fx_line,
20476 _("invalid constant (%lx) after fixup"),
20477 (unsigned long) value);
20478 break;
b99bd4ef 20479 }
b99bd4ef 20480
c19d1205
ZW
20481 newimm |= (temp & 0xfffff000);
20482 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20483 break;
b99bd4ef 20484
c19d1205
ZW
20485 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20486 {
20487 unsigned int highpart = 0;
20488 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 20489
77db8e2e 20490 if (fixP->fx_addsy)
42e5fcbf 20491 {
77db8e2e 20492 const char *msg = 0;
42e5fcbf 20493
77db8e2e
NC
20494 if (! S_IS_DEFINED (fixP->fx_addsy))
20495 msg = _("undefined symbol %s used as an immediate value");
20496 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20497 msg = _("symbol %s is in a different section");
20498 else if (S_IS_WEAK (fixP->fx_addsy))
20499 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 20500
77db8e2e
NC
20501 if (msg)
20502 {
20503 as_bad_where (fixP->fx_file, fixP->fx_line,
20504 msg, S_GET_NAME (fixP->fx_addsy));
20505 break;
20506 }
20507 }
20508
c19d1205
ZW
20509 newimm = encode_arm_immediate (value);
20510 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 20511
c19d1205
ZW
20512 /* If the instruction will fail, see if we can fix things up by
20513 changing the opcode. */
20514 if (newimm == (unsigned int) FAIL
20515 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
20516 {
20517 /* No ? OK - try using two ADD instructions to generate
20518 the value. */
20519 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 20520
c19d1205
ZW
20521 /* Yes - then make sure that the second instruction is
20522 also an add. */
20523 if (newimm != (unsigned int) FAIL)
20524 newinsn = temp;
20525 /* Still No ? Try using a negated value. */
20526 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
20527 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
20528 /* Otherwise - give up. */
20529 else
20530 {
20531 as_bad_where (fixP->fx_file, fixP->fx_line,
20532 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
20533 (long) value);
20534 break;
20535 }
b99bd4ef 20536
c19d1205
ZW
20537 /* Replace the first operand in the 2nd instruction (which
20538 is the PC) with the destination register. We have
20539 already added in the PC in the first instruction and we
20540 do not want to do it again. */
20541 newinsn &= ~ 0xf0000;
20542 newinsn |= ((newinsn & 0x0f000) << 4);
20543 }
b99bd4ef 20544
c19d1205
ZW
20545 newimm |= (temp & 0xfffff000);
20546 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 20547
c19d1205
ZW
20548 highpart |= (newinsn & 0xfffff000);
20549 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
20550 }
20551 break;
b99bd4ef 20552
c19d1205 20553 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
20554 if (!fixP->fx_done && seg->use_rela_p)
20555 value = 0;
20556
c19d1205 20557 case BFD_RELOC_ARM_LITERAL:
26d97720 20558 sign = value > 0;
b99bd4ef 20559
c19d1205
ZW
20560 if (value < 0)
20561 value = - value;
b99bd4ef 20562
c19d1205 20563 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 20564 {
c19d1205
ZW
20565 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
20566 as_bad_where (fixP->fx_file, fixP->fx_line,
20567 _("invalid literal constant: pool needs to be closer"));
20568 else
20569 as_bad_where (fixP->fx_file, fixP->fx_line,
20570 _("bad immediate value for offset (%ld)"),
20571 (long) value);
20572 break;
f03698e6
RE
20573 }
20574
c19d1205 20575 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
20576 if (value == 0)
20577 newval &= 0xfffff000;
20578 else
20579 {
20580 newval &= 0xff7ff000;
20581 newval |= value | (sign ? INDEX_UP : 0);
20582 }
c19d1205
ZW
20583 md_number_to_chars (buf, newval, INSN_SIZE);
20584 break;
b99bd4ef 20585
c19d1205
ZW
20586 case BFD_RELOC_ARM_OFFSET_IMM8:
20587 case BFD_RELOC_ARM_HWLITERAL:
26d97720 20588 sign = value > 0;
b99bd4ef 20589
c19d1205
ZW
20590 if (value < 0)
20591 value = - value;
b99bd4ef 20592
c19d1205 20593 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 20594 {
c19d1205
ZW
20595 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
20596 as_bad_where (fixP->fx_file, fixP->fx_line,
20597 _("invalid literal constant: pool needs to be closer"));
20598 else
f9d4405b 20599 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
20600 (long) value);
20601 break;
b99bd4ef
NC
20602 }
20603
c19d1205 20604 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
20605 if (value == 0)
20606 newval &= 0xfffff0f0;
20607 else
20608 {
20609 newval &= 0xff7ff0f0;
20610 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
20611 }
c19d1205
ZW
20612 md_number_to_chars (buf, newval, INSN_SIZE);
20613 break;
b99bd4ef 20614
c19d1205
ZW
20615 case BFD_RELOC_ARM_T32_OFFSET_U8:
20616 if (value < 0 || value > 1020 || value % 4 != 0)
20617 as_bad_where (fixP->fx_file, fixP->fx_line,
20618 _("bad immediate value for offset (%ld)"), (long) value);
20619 value /= 4;
b99bd4ef 20620
c19d1205 20621 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
20622 newval |= value;
20623 md_number_to_chars (buf+2, newval, THUMB_SIZE);
20624 break;
b99bd4ef 20625
c19d1205
ZW
20626 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20627 /* This is a complicated relocation used for all varieties of Thumb32
20628 load/store instruction with immediate offset:
20629
20630 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
20631 *4, optional writeback(W)
20632 (doubleword load/store)
20633
20634 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
20635 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
20636 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
20637 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
20638 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
20639
20640 Uppercase letters indicate bits that are already encoded at
20641 this point. Lowercase letters are our problem. For the
20642 second block of instructions, the secondary opcode nybble
20643 (bits 8..11) is present, and bit 23 is zero, even if this is
20644 a PC-relative operation. */
20645 newval = md_chars_to_number (buf, THUMB_SIZE);
20646 newval <<= 16;
20647 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 20648
c19d1205 20649 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 20650 {
c19d1205
ZW
20651 /* Doubleword load/store: 8-bit offset, scaled by 4. */
20652 if (value >= 0)
20653 newval |= (1 << 23);
20654 else
20655 value = -value;
20656 if (value % 4 != 0)
20657 {
20658 as_bad_where (fixP->fx_file, fixP->fx_line,
20659 _("offset not a multiple of 4"));
20660 break;
20661 }
20662 value /= 4;
216d22bc 20663 if (value > 0xff)
c19d1205
ZW
20664 {
20665 as_bad_where (fixP->fx_file, fixP->fx_line,
20666 _("offset out of range"));
20667 break;
20668 }
20669 newval &= ~0xff;
b99bd4ef 20670 }
c19d1205 20671 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 20672 {
c19d1205
ZW
20673 /* PC-relative, 12-bit offset. */
20674 if (value >= 0)
20675 newval |= (1 << 23);
20676 else
20677 value = -value;
216d22bc 20678 if (value > 0xfff)
c19d1205
ZW
20679 {
20680 as_bad_where (fixP->fx_file, fixP->fx_line,
20681 _("offset out of range"));
20682 break;
20683 }
20684 newval &= ~0xfff;
b99bd4ef 20685 }
c19d1205 20686 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 20687 {
c19d1205
ZW
20688 /* Writeback: 8-bit, +/- offset. */
20689 if (value >= 0)
20690 newval |= (1 << 9);
20691 else
20692 value = -value;
216d22bc 20693 if (value > 0xff)
c19d1205
ZW
20694 {
20695 as_bad_where (fixP->fx_file, fixP->fx_line,
20696 _("offset out of range"));
20697 break;
20698 }
20699 newval &= ~0xff;
b99bd4ef 20700 }
c19d1205 20701 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 20702 {
c19d1205 20703 /* T-instruction: positive 8-bit offset. */
216d22bc 20704 if (value < 0 || value > 0xff)
b99bd4ef 20705 {
c19d1205
ZW
20706 as_bad_where (fixP->fx_file, fixP->fx_line,
20707 _("offset out of range"));
20708 break;
b99bd4ef 20709 }
c19d1205
ZW
20710 newval &= ~0xff;
20711 newval |= value;
b99bd4ef
NC
20712 }
20713 else
b99bd4ef 20714 {
c19d1205
ZW
20715 /* Positive 12-bit or negative 8-bit offset. */
20716 int limit;
20717 if (value >= 0)
b99bd4ef 20718 {
c19d1205
ZW
20719 newval |= (1 << 23);
20720 limit = 0xfff;
20721 }
20722 else
20723 {
20724 value = -value;
20725 limit = 0xff;
20726 }
20727 if (value > limit)
20728 {
20729 as_bad_where (fixP->fx_file, fixP->fx_line,
20730 _("offset out of range"));
20731 break;
b99bd4ef 20732 }
c19d1205 20733 newval &= ~limit;
b99bd4ef 20734 }
b99bd4ef 20735
c19d1205
ZW
20736 newval |= value;
20737 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20738 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20739 break;
404ff6b5 20740
c19d1205
ZW
20741 case BFD_RELOC_ARM_SHIFT_IMM:
20742 newval = md_chars_to_number (buf, INSN_SIZE);
20743 if (((unsigned long) value) > 32
20744 || (value == 32
20745 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20746 {
20747 as_bad_where (fixP->fx_file, fixP->fx_line,
20748 _("shift expression is too large"));
20749 break;
20750 }
404ff6b5 20751
c19d1205
ZW
20752 if (value == 0)
20753 /* Shifts of zero must be done as lsl. */
20754 newval &= ~0x60;
20755 else if (value == 32)
20756 value = 0;
20757 newval &= 0xfffff07f;
20758 newval |= (value & 0x1f) << 7;
20759 md_number_to_chars (buf, newval, INSN_SIZE);
20760 break;
404ff6b5 20761
c19d1205 20762 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 20763 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 20764 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 20765 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
20766 /* We claim that this fixup has been processed here,
20767 even if in fact we generate an error because we do
20768 not have a reloc for it, so tc_gen_reloc will reject it. */
20769 fixP->fx_done = 1;
404ff6b5 20770
c19d1205
ZW
20771 if (fixP->fx_addsy
20772 && ! S_IS_DEFINED (fixP->fx_addsy))
20773 {
20774 as_bad_where (fixP->fx_file, fixP->fx_line,
20775 _("undefined symbol %s used as an immediate value"),
20776 S_GET_NAME (fixP->fx_addsy));
20777 break;
20778 }
404ff6b5 20779
c19d1205
ZW
20780 newval = md_chars_to_number (buf, THUMB_SIZE);
20781 newval <<= 16;
20782 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 20783
16805f35
PB
20784 newimm = FAIL;
20785 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20786 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
20787 {
20788 newimm = encode_thumb32_immediate (value);
20789 if (newimm == (unsigned int) FAIL)
20790 newimm = thumb32_negate_data_op (&newval, value);
20791 }
16805f35
PB
20792 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20793 && newimm == (unsigned int) FAIL)
92e90b6e 20794 {
16805f35
PB
20795 /* Turn add/sum into addw/subw. */
20796 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20797 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
20798 /* No flat 12-bit imm encoding for addsw/subsw. */
20799 if ((newval & 0x00100000) == 0)
e9f89963 20800 {
40f246e3
NC
20801 /* 12 bit immediate for addw/subw. */
20802 if (value < 0)
20803 {
20804 value = -value;
20805 newval ^= 0x00a00000;
20806 }
20807 if (value > 0xfff)
20808 newimm = (unsigned int) FAIL;
20809 else
20810 newimm = value;
e9f89963 20811 }
92e90b6e 20812 }
cc8a6dd0 20813
c19d1205 20814 if (newimm == (unsigned int)FAIL)
3631a3c8 20815 {
c19d1205
ZW
20816 as_bad_where (fixP->fx_file, fixP->fx_line,
20817 _("invalid constant (%lx) after fixup"),
20818 (unsigned long) value);
20819 break;
3631a3c8
NC
20820 }
20821
c19d1205
ZW
20822 newval |= (newimm & 0x800) << 15;
20823 newval |= (newimm & 0x700) << 4;
20824 newval |= (newimm & 0x0ff);
cc8a6dd0 20825
c19d1205
ZW
20826 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20827 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20828 break;
a737bd4d 20829
3eb17e6b 20830 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
20831 if (((unsigned long) value) > 0xffff)
20832 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 20833 _("invalid smc expression"));
2fc8bdac 20834 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20835 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20836 md_number_to_chars (buf, newval, INSN_SIZE);
20837 break;
a737bd4d 20838
90ec0d68
MGD
20839 case BFD_RELOC_ARM_HVC:
20840 if (((unsigned long) value) > 0xffff)
20841 as_bad_where (fixP->fx_file, fixP->fx_line,
20842 _("invalid hvc expression"));
20843 newval = md_chars_to_number (buf, INSN_SIZE);
20844 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20845 md_number_to_chars (buf, newval, INSN_SIZE);
20846 break;
20847
c19d1205 20848 case BFD_RELOC_ARM_SWI:
adbaf948 20849 if (fixP->tc_fix_data != 0)
c19d1205
ZW
20850 {
20851 if (((unsigned long) value) > 0xff)
20852 as_bad_where (fixP->fx_file, fixP->fx_line,
20853 _("invalid swi expression"));
2fc8bdac 20854 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
20855 newval |= value;
20856 md_number_to_chars (buf, newval, THUMB_SIZE);
20857 }
20858 else
20859 {
20860 if (((unsigned long) value) > 0x00ffffff)
20861 as_bad_where (fixP->fx_file, fixP->fx_line,
20862 _("invalid swi expression"));
2fc8bdac 20863 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20864 newval |= value;
20865 md_number_to_chars (buf, newval, INSN_SIZE);
20866 }
20867 break;
a737bd4d 20868
c19d1205
ZW
20869 case BFD_RELOC_ARM_MULTI:
20870 if (((unsigned long) value) > 0xffff)
20871 as_bad_where (fixP->fx_file, fixP->fx_line,
20872 _("invalid expression in load/store multiple"));
20873 newval = value | md_chars_to_number (buf, INSN_SIZE);
20874 md_number_to_chars (buf, newval, INSN_SIZE);
20875 break;
a737bd4d 20876
c19d1205 20877#ifdef OBJ_ELF
39b41c9c 20878 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
20879
20880 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20881 && fixP->fx_addsy
34e77a92 20882 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20883 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20884 && THUMB_IS_FUNC (fixP->fx_addsy))
20885 /* Flip the bl to blx. This is a simple flip
20886 bit here because we generate PCREL_CALL for
20887 unconditional bls. */
20888 {
20889 newval = md_chars_to_number (buf, INSN_SIZE);
20890 newval = newval | 0x10000000;
20891 md_number_to_chars (buf, newval, INSN_SIZE);
20892 temp = 1;
20893 fixP->fx_done = 1;
20894 }
39b41c9c
PB
20895 else
20896 temp = 3;
20897 goto arm_branch_common;
20898
20899 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
20900 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20901 && fixP->fx_addsy
34e77a92 20902 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20903 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20904 && THUMB_IS_FUNC (fixP->fx_addsy))
20905 {
20906 /* This would map to a bl<cond>, b<cond>,
20907 b<always> to a Thumb function. We
20908 need to force a relocation for this particular
20909 case. */
20910 newval = md_chars_to_number (buf, INSN_SIZE);
20911 fixP->fx_done = 0;
20912 }
20913
2fc8bdac 20914 case BFD_RELOC_ARM_PLT32:
c19d1205 20915#endif
39b41c9c
PB
20916 case BFD_RELOC_ARM_PCREL_BRANCH:
20917 temp = 3;
20918 goto arm_branch_common;
a737bd4d 20919
39b41c9c 20920 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 20921
39b41c9c 20922 temp = 1;
267bf995
RR
20923 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20924 && fixP->fx_addsy
34e77a92 20925 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20926 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20927 && ARM_IS_FUNC (fixP->fx_addsy))
20928 {
20929 /* Flip the blx to a bl and warn. */
20930 const char *name = S_GET_NAME (fixP->fx_addsy);
20931 newval = 0xeb000000;
20932 as_warn_where (fixP->fx_file, fixP->fx_line,
20933 _("blx to '%s' an ARM ISA state function changed to bl"),
20934 name);
20935 md_number_to_chars (buf, newval, INSN_SIZE);
20936 temp = 3;
20937 fixP->fx_done = 1;
20938 }
20939
20940#ifdef OBJ_ELF
20941 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20942 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20943#endif
20944
39b41c9c 20945 arm_branch_common:
c19d1205 20946 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
20947 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20948 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20949 also be be clear. */
20950 if (value & temp)
c19d1205 20951 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
20952 _("misaligned branch destination"));
20953 if ((value & (offsetT)0xfe000000) != (offsetT)0
20954 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 20955 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 20956
2fc8bdac 20957 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20958 {
2fc8bdac
ZW
20959 newval = md_chars_to_number (buf, INSN_SIZE);
20960 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
20961 /* Set the H bit on BLX instructions. */
20962 if (temp == 1)
20963 {
20964 if (value & 2)
20965 newval |= 0x01000000;
20966 else
20967 newval &= ~0x01000000;
20968 }
2fc8bdac 20969 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 20970 }
c19d1205 20971 break;
a737bd4d 20972
25fe350b
MS
20973 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20974 /* CBZ can only branch forward. */
a737bd4d 20975
738755b0
MS
20976 /* Attempts to use CBZ to branch to the next instruction
20977 (which, strictly speaking, are prohibited) will be turned into
20978 no-ops.
20979
20980 FIXME: It may be better to remove the instruction completely and
20981 perform relaxation. */
20982 if (value == -2)
2fc8bdac
ZW
20983 {
20984 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 20985 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
20986 md_number_to_chars (buf, newval, THUMB_SIZE);
20987 }
738755b0
MS
20988 else
20989 {
20990 if (value & ~0x7e)
08f10d51 20991 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0
MS
20992
20993 if (fixP->fx_done || !seg->use_rela_p)
20994 {
20995 newval = md_chars_to_number (buf, THUMB_SIZE);
20996 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20997 md_number_to_chars (buf, newval, THUMB_SIZE);
20998 }
20999 }
c19d1205 21000 break;
a737bd4d 21001
c19d1205 21002 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 21003 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 21004 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 21005
2fc8bdac
ZW
21006 if (fixP->fx_done || !seg->use_rela_p)
21007 {
21008 newval = md_chars_to_number (buf, THUMB_SIZE);
21009 newval |= (value & 0x1ff) >> 1;
21010 md_number_to_chars (buf, newval, THUMB_SIZE);
21011 }
c19d1205 21012 break;
a737bd4d 21013
c19d1205 21014 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 21015 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 21016 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 21017
2fc8bdac
ZW
21018 if (fixP->fx_done || !seg->use_rela_p)
21019 {
21020 newval = md_chars_to_number (buf, THUMB_SIZE);
21021 newval |= (value & 0xfff) >> 1;
21022 md_number_to_chars (buf, newval, THUMB_SIZE);
21023 }
c19d1205 21024 break;
a737bd4d 21025
c19d1205 21026 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
21027 if (fixP->fx_addsy
21028 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21029 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21030 && ARM_IS_FUNC (fixP->fx_addsy)
21031 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21032 {
21033 /* Force a relocation for a branch 20 bits wide. */
21034 fixP->fx_done = 0;
21035 }
08f10d51 21036 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
21037 as_bad_where (fixP->fx_file, fixP->fx_line,
21038 _("conditional branch out of range"));
404ff6b5 21039
2fc8bdac
ZW
21040 if (fixP->fx_done || !seg->use_rela_p)
21041 {
21042 offsetT newval2;
21043 addressT S, J1, J2, lo, hi;
404ff6b5 21044
2fc8bdac
ZW
21045 S = (value & 0x00100000) >> 20;
21046 J2 = (value & 0x00080000) >> 19;
21047 J1 = (value & 0x00040000) >> 18;
21048 hi = (value & 0x0003f000) >> 12;
21049 lo = (value & 0x00000ffe) >> 1;
6c43fab6 21050
2fc8bdac
ZW
21051 newval = md_chars_to_number (buf, THUMB_SIZE);
21052 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21053 newval |= (S << 10) | hi;
21054 newval2 |= (J1 << 13) | (J2 << 11) | lo;
21055 md_number_to_chars (buf, newval, THUMB_SIZE);
21056 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
21057 }
c19d1205 21058 break;
6c43fab6 21059
c19d1205 21060 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
21061 /* If there is a blx from a thumb state function to
21062 another thumb function flip this to a bl and warn
21063 about it. */
21064
21065 if (fixP->fx_addsy
34e77a92 21066 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21067 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21068 && THUMB_IS_FUNC (fixP->fx_addsy))
21069 {
21070 const char *name = S_GET_NAME (fixP->fx_addsy);
21071 as_warn_where (fixP->fx_file, fixP->fx_line,
21072 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
21073 name);
21074 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21075 newval = newval | 0x1000;
21076 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
21077 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
21078 fixP->fx_done = 1;
21079 }
21080
21081
21082 goto thumb_bl_common;
21083
c19d1205 21084 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
21085 /* A bl from Thumb state ISA to an internal ARM state function
21086 is converted to a blx. */
21087 if (fixP->fx_addsy
21088 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21089 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21090 && ARM_IS_FUNC (fixP->fx_addsy)
21091 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21092 {
21093 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21094 newval = newval & ~0x1000;
21095 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
21096 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
21097 fixP->fx_done = 1;
21098 }
21099
21100 thumb_bl_common:
21101
21102#ifdef OBJ_ELF
21103 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
21104 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
21105 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
21106#endif
21107
2fc8bdac
ZW
21108 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
21109 /* For a BLX instruction, make sure that the relocation is rounded up
21110 to a word boundary. This follows the semantics of the instruction
21111 which specifies that bit 1 of the target address will come from bit
21112 1 of the base address. */
21113 value = (value + 1) & ~ 1;
404ff6b5 21114
4a42ebbc 21115 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
08f10d51
NC
21116 {
21117 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
21118 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21119 else if ((value & ~0x1ffffff)
21120 && ((value & ~0x1ffffff) != ~0x1ffffff))
21121 as_bad_where (fixP->fx_file, fixP->fx_line,
21122 _("Thumb2 branch out of range"));
21123 }
4a42ebbc
RR
21124
21125 if (fixP->fx_done || !seg->use_rela_p)
21126 encode_thumb2_b_bl_offset (buf, value);
21127
c19d1205 21128 break;
404ff6b5 21129
c19d1205 21130 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
21131 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
21132 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 21133
2fc8bdac 21134 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 21135 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 21136
2fc8bdac 21137 break;
a737bd4d 21138
2fc8bdac
ZW
21139 case BFD_RELOC_8:
21140 if (fixP->fx_done || !seg->use_rela_p)
21141 md_number_to_chars (buf, value, 1);
c19d1205 21142 break;
a737bd4d 21143
c19d1205 21144 case BFD_RELOC_16:
2fc8bdac 21145 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 21146 md_number_to_chars (buf, value, 2);
c19d1205 21147 break;
a737bd4d 21148
c19d1205 21149#ifdef OBJ_ELF
0855e32b
NS
21150 case BFD_RELOC_ARM_TLS_CALL:
21151 case BFD_RELOC_ARM_THM_TLS_CALL:
21152 case BFD_RELOC_ARM_TLS_DESCSEQ:
21153 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
21154 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21155 break;
21156
21157 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
21158 case BFD_RELOC_ARM_TLS_GD32:
21159 case BFD_RELOC_ARM_TLS_LE32:
21160 case BFD_RELOC_ARM_TLS_IE32:
21161 case BFD_RELOC_ARM_TLS_LDM32:
21162 case BFD_RELOC_ARM_TLS_LDO32:
21163 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21164 /* fall through */
6c43fab6 21165
c19d1205
ZW
21166 case BFD_RELOC_ARM_GOT32:
21167 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
21168 if (fixP->fx_done || !seg->use_rela_p)
21169 md_number_to_chars (buf, 0, 4);
c19d1205 21170 break;
b43420e6
NC
21171
21172 case BFD_RELOC_ARM_GOT_PREL:
21173 if (fixP->fx_done || !seg->use_rela_p)
21174 md_number_to_chars (buf, value, 4);
21175 break;
21176
9a6f4e97
NS
21177 case BFD_RELOC_ARM_TARGET2:
21178 /* TARGET2 is not partial-inplace, so we need to write the
21179 addend here for REL targets, because it won't be written out
21180 during reloc processing later. */
21181 if (fixP->fx_done || !seg->use_rela_p)
21182 md_number_to_chars (buf, fixP->fx_offset, 4);
21183 break;
c19d1205 21184#endif
6c43fab6 21185
c19d1205
ZW
21186 case BFD_RELOC_RVA:
21187 case BFD_RELOC_32:
21188 case BFD_RELOC_ARM_TARGET1:
21189 case BFD_RELOC_ARM_ROSEGREL32:
21190 case BFD_RELOC_ARM_SBREL32:
21191 case BFD_RELOC_32_PCREL:
f0927246
NC
21192#ifdef TE_PE
21193 case BFD_RELOC_32_SECREL:
21194#endif
2fc8bdac 21195 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
21196#ifdef TE_WINCE
21197 /* For WinCE we only do this for pcrel fixups. */
21198 if (fixP->fx_done || fixP->fx_pcrel)
21199#endif
21200 md_number_to_chars (buf, value, 4);
c19d1205 21201 break;
6c43fab6 21202
c19d1205
ZW
21203#ifdef OBJ_ELF
21204 case BFD_RELOC_ARM_PREL31:
2fc8bdac 21205 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
21206 {
21207 newval = md_chars_to_number (buf, 4) & 0x80000000;
21208 if ((value ^ (value >> 1)) & 0x40000000)
21209 {
21210 as_bad_where (fixP->fx_file, fixP->fx_line,
21211 _("rel31 relocation overflow"));
21212 }
21213 newval |= value & 0x7fffffff;
21214 md_number_to_chars (buf, newval, 4);
21215 }
21216 break;
c19d1205 21217#endif
a737bd4d 21218
c19d1205 21219 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 21220 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
21221 if (value < -1023 || value > 1023 || (value & 3))
21222 as_bad_where (fixP->fx_file, fixP->fx_line,
21223 _("co-processor offset out of range"));
21224 cp_off_common:
26d97720 21225 sign = value > 0;
c19d1205
ZW
21226 if (value < 0)
21227 value = -value;
8f06b2d8
PB
21228 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21229 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21230 newval = md_chars_to_number (buf, INSN_SIZE);
21231 else
21232 newval = get_thumb32_insn (buf);
26d97720
NS
21233 if (value == 0)
21234 newval &= 0xffffff00;
21235 else
21236 {
21237 newval &= 0xff7fff00;
21238 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
21239 }
8f06b2d8
PB
21240 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21241 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21242 md_number_to_chars (buf, newval, INSN_SIZE);
21243 else
21244 put_thumb32_insn (buf, newval);
c19d1205 21245 break;
a737bd4d 21246
c19d1205 21247 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 21248 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
21249 if (value < -255 || value > 255)
21250 as_bad_where (fixP->fx_file, fixP->fx_line,
21251 _("co-processor offset out of range"));
df7849c5 21252 value *= 4;
c19d1205 21253 goto cp_off_common;
6c43fab6 21254
c19d1205
ZW
21255 case BFD_RELOC_ARM_THUMB_OFFSET:
21256 newval = md_chars_to_number (buf, THUMB_SIZE);
21257 /* Exactly what ranges, and where the offset is inserted depends
21258 on the type of instruction, we can establish this from the
21259 top 4 bits. */
21260 switch (newval >> 12)
21261 {
21262 case 4: /* PC load. */
21263 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
21264 forced to zero for these loads; md_pcrel_from has already
21265 compensated for this. */
21266 if (value & 3)
21267 as_bad_where (fixP->fx_file, fixP->fx_line,
21268 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
21269 (((unsigned long) fixP->fx_frag->fr_address
21270 + (unsigned long) fixP->fx_where) & ~3)
21271 + (unsigned long) value);
a737bd4d 21272
c19d1205
ZW
21273 if (value & ~0x3fc)
21274 as_bad_where (fixP->fx_file, fixP->fx_line,
21275 _("invalid offset, value too big (0x%08lX)"),
21276 (long) value);
a737bd4d 21277
c19d1205
ZW
21278 newval |= value >> 2;
21279 break;
a737bd4d 21280
c19d1205
ZW
21281 case 9: /* SP load/store. */
21282 if (value & ~0x3fc)
21283 as_bad_where (fixP->fx_file, fixP->fx_line,
21284 _("invalid offset, value too big (0x%08lX)"),
21285 (long) value);
21286 newval |= value >> 2;
21287 break;
6c43fab6 21288
c19d1205
ZW
21289 case 6: /* Word load/store. */
21290 if (value & ~0x7c)
21291 as_bad_where (fixP->fx_file, fixP->fx_line,
21292 _("invalid offset, value too big (0x%08lX)"),
21293 (long) value);
21294 newval |= value << 4; /* 6 - 2. */
21295 break;
a737bd4d 21296
c19d1205
ZW
21297 case 7: /* Byte load/store. */
21298 if (value & ~0x1f)
21299 as_bad_where (fixP->fx_file, fixP->fx_line,
21300 _("invalid offset, value too big (0x%08lX)"),
21301 (long) value);
21302 newval |= value << 6;
21303 break;
a737bd4d 21304
c19d1205
ZW
21305 case 8: /* Halfword load/store. */
21306 if (value & ~0x3e)
21307 as_bad_where (fixP->fx_file, fixP->fx_line,
21308 _("invalid offset, value too big (0x%08lX)"),
21309 (long) value);
21310 newval |= value << 5; /* 6 - 1. */
21311 break;
a737bd4d 21312
c19d1205
ZW
21313 default:
21314 as_bad_where (fixP->fx_file, fixP->fx_line,
21315 "Unable to process relocation for thumb opcode: %lx",
21316 (unsigned long) newval);
21317 break;
21318 }
21319 md_number_to_chars (buf, newval, THUMB_SIZE);
21320 break;
a737bd4d 21321
c19d1205
ZW
21322 case BFD_RELOC_ARM_THUMB_ADD:
21323 /* This is a complicated relocation, since we use it for all of
21324 the following immediate relocations:
a737bd4d 21325
c19d1205
ZW
21326 3bit ADD/SUB
21327 8bit ADD/SUB
21328 9bit ADD/SUB SP word-aligned
21329 10bit ADD PC/SP word-aligned
a737bd4d 21330
c19d1205
ZW
21331 The type of instruction being processed is encoded in the
21332 instruction field:
a737bd4d 21333
c19d1205
ZW
21334 0x8000 SUB
21335 0x00F0 Rd
21336 0x000F Rs
21337 */
21338 newval = md_chars_to_number (buf, THUMB_SIZE);
21339 {
21340 int rd = (newval >> 4) & 0xf;
21341 int rs = newval & 0xf;
21342 int subtract = !!(newval & 0x8000);
a737bd4d 21343
c19d1205
ZW
21344 /* Check for HI regs, only very restricted cases allowed:
21345 Adjusting SP, and using PC or SP to get an address. */
21346 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
21347 || (rs > 7 && rs != REG_SP && rs != REG_PC))
21348 as_bad_where (fixP->fx_file, fixP->fx_line,
21349 _("invalid Hi register with immediate"));
a737bd4d 21350
c19d1205
ZW
21351 /* If value is negative, choose the opposite instruction. */
21352 if (value < 0)
21353 {
21354 value = -value;
21355 subtract = !subtract;
21356 if (value < 0)
21357 as_bad_where (fixP->fx_file, fixP->fx_line,
21358 _("immediate value out of range"));
21359 }
a737bd4d 21360
c19d1205
ZW
21361 if (rd == REG_SP)
21362 {
21363 if (value & ~0x1fc)
21364 as_bad_where (fixP->fx_file, fixP->fx_line,
21365 _("invalid immediate for stack address calculation"));
21366 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
21367 newval |= value >> 2;
21368 }
21369 else if (rs == REG_PC || rs == REG_SP)
21370 {
21371 if (subtract || value & ~0x3fc)
21372 as_bad_where (fixP->fx_file, fixP->fx_line,
21373 _("invalid immediate for address calculation (value = 0x%08lX)"),
21374 (unsigned long) value);
21375 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
21376 newval |= rd << 8;
21377 newval |= value >> 2;
21378 }
21379 else if (rs == rd)
21380 {
21381 if (value & ~0xff)
21382 as_bad_where (fixP->fx_file, fixP->fx_line,
21383 _("immediate value out of range"));
21384 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
21385 newval |= (rd << 8) | value;
21386 }
21387 else
21388 {
21389 if (value & ~0x7)
21390 as_bad_where (fixP->fx_file, fixP->fx_line,
21391 _("immediate value out of range"));
21392 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
21393 newval |= rd | (rs << 3) | (value << 6);
21394 }
21395 }
21396 md_number_to_chars (buf, newval, THUMB_SIZE);
21397 break;
a737bd4d 21398
c19d1205
ZW
21399 case BFD_RELOC_ARM_THUMB_IMM:
21400 newval = md_chars_to_number (buf, THUMB_SIZE);
21401 if (value < 0 || value > 255)
21402 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 21403 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
21404 (long) value);
21405 newval |= value;
21406 md_number_to_chars (buf, newval, THUMB_SIZE);
21407 break;
a737bd4d 21408
c19d1205
ZW
21409 case BFD_RELOC_ARM_THUMB_SHIFT:
21410 /* 5bit shift value (0..32). LSL cannot take 32. */
21411 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
21412 temp = newval & 0xf800;
21413 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
21414 as_bad_where (fixP->fx_file, fixP->fx_line,
21415 _("invalid shift value: %ld"), (long) value);
21416 /* Shifts of zero must be encoded as LSL. */
21417 if (value == 0)
21418 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
21419 /* Shifts of 32 are encoded as zero. */
21420 else if (value == 32)
21421 value = 0;
21422 newval |= value << 6;
21423 md_number_to_chars (buf, newval, THUMB_SIZE);
21424 break;
a737bd4d 21425
c19d1205
ZW
21426 case BFD_RELOC_VTABLE_INHERIT:
21427 case BFD_RELOC_VTABLE_ENTRY:
21428 fixP->fx_done = 0;
21429 return;
6c43fab6 21430
b6895b4f
PB
21431 case BFD_RELOC_ARM_MOVW:
21432 case BFD_RELOC_ARM_MOVT:
21433 case BFD_RELOC_ARM_THUMB_MOVW:
21434 case BFD_RELOC_ARM_THUMB_MOVT:
21435 if (fixP->fx_done || !seg->use_rela_p)
21436 {
21437 /* REL format relocations are limited to a 16-bit addend. */
21438 if (!fixP->fx_done)
21439 {
39623e12 21440 if (value < -0x8000 || value > 0x7fff)
b6895b4f 21441 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 21442 _("offset out of range"));
b6895b4f
PB
21443 }
21444 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21445 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21446 {
21447 value >>= 16;
21448 }
21449
21450 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21451 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21452 {
21453 newval = get_thumb32_insn (buf);
21454 newval &= 0xfbf08f00;
21455 newval |= (value & 0xf000) << 4;
21456 newval |= (value & 0x0800) << 15;
21457 newval |= (value & 0x0700) << 4;
21458 newval |= (value & 0x00ff);
21459 put_thumb32_insn (buf, newval);
21460 }
21461 else
21462 {
21463 newval = md_chars_to_number (buf, 4);
21464 newval &= 0xfff0f000;
21465 newval |= value & 0x0fff;
21466 newval |= (value & 0xf000) << 4;
21467 md_number_to_chars (buf, newval, 4);
21468 }
21469 }
21470 return;
21471
4962c51a
MS
21472 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21473 case BFD_RELOC_ARM_ALU_PC_G0:
21474 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21475 case BFD_RELOC_ARM_ALU_PC_G1:
21476 case BFD_RELOC_ARM_ALU_PC_G2:
21477 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21478 case BFD_RELOC_ARM_ALU_SB_G0:
21479 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21480 case BFD_RELOC_ARM_ALU_SB_G1:
21481 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 21482 gas_assert (!fixP->fx_done);
4962c51a
MS
21483 if (!seg->use_rela_p)
21484 {
21485 bfd_vma insn;
21486 bfd_vma encoded_addend;
21487 bfd_vma addend_abs = abs (value);
21488
21489 /* Check that the absolute value of the addend can be
21490 expressed as an 8-bit constant plus a rotation. */
21491 encoded_addend = encode_arm_immediate (addend_abs);
21492 if (encoded_addend == (unsigned int) FAIL)
21493 as_bad_where (fixP->fx_file, fixP->fx_line,
21494 _("the offset 0x%08lX is not representable"),
495bde8e 21495 (unsigned long) addend_abs);
4962c51a
MS
21496
21497 /* Extract the instruction. */
21498 insn = md_chars_to_number (buf, INSN_SIZE);
21499
21500 /* If the addend is positive, use an ADD instruction.
21501 Otherwise use a SUB. Take care not to destroy the S bit. */
21502 insn &= 0xff1fffff;
21503 if (value < 0)
21504 insn |= 1 << 22;
21505 else
21506 insn |= 1 << 23;
21507
21508 /* Place the encoded addend into the first 12 bits of the
21509 instruction. */
21510 insn &= 0xfffff000;
21511 insn |= encoded_addend;
5f4273c7
NC
21512
21513 /* Update the instruction. */
4962c51a
MS
21514 md_number_to_chars (buf, insn, INSN_SIZE);
21515 }
21516 break;
21517
21518 case BFD_RELOC_ARM_LDR_PC_G0:
21519 case BFD_RELOC_ARM_LDR_PC_G1:
21520 case BFD_RELOC_ARM_LDR_PC_G2:
21521 case BFD_RELOC_ARM_LDR_SB_G0:
21522 case BFD_RELOC_ARM_LDR_SB_G1:
21523 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 21524 gas_assert (!fixP->fx_done);
4962c51a
MS
21525 if (!seg->use_rela_p)
21526 {
21527 bfd_vma insn;
21528 bfd_vma addend_abs = abs (value);
21529
21530 /* Check that the absolute value of the addend can be
21531 encoded in 12 bits. */
21532 if (addend_abs >= 0x1000)
21533 as_bad_where (fixP->fx_file, fixP->fx_line,
21534 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 21535 (unsigned long) addend_abs);
4962c51a
MS
21536
21537 /* Extract the instruction. */
21538 insn = md_chars_to_number (buf, INSN_SIZE);
21539
21540 /* If the addend is negative, clear bit 23 of the instruction.
21541 Otherwise set it. */
21542 if (value < 0)
21543 insn &= ~(1 << 23);
21544 else
21545 insn |= 1 << 23;
21546
21547 /* Place the absolute value of the addend into the first 12 bits
21548 of the instruction. */
21549 insn &= 0xfffff000;
21550 insn |= addend_abs;
5f4273c7
NC
21551
21552 /* Update the instruction. */
4962c51a
MS
21553 md_number_to_chars (buf, insn, INSN_SIZE);
21554 }
21555 break;
21556
21557 case BFD_RELOC_ARM_LDRS_PC_G0:
21558 case BFD_RELOC_ARM_LDRS_PC_G1:
21559 case BFD_RELOC_ARM_LDRS_PC_G2:
21560 case BFD_RELOC_ARM_LDRS_SB_G0:
21561 case BFD_RELOC_ARM_LDRS_SB_G1:
21562 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 21563 gas_assert (!fixP->fx_done);
4962c51a
MS
21564 if (!seg->use_rela_p)
21565 {
21566 bfd_vma insn;
21567 bfd_vma addend_abs = abs (value);
21568
21569 /* Check that the absolute value of the addend can be
21570 encoded in 8 bits. */
21571 if (addend_abs >= 0x100)
21572 as_bad_where (fixP->fx_file, fixP->fx_line,
21573 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 21574 (unsigned long) addend_abs);
4962c51a
MS
21575
21576 /* Extract the instruction. */
21577 insn = md_chars_to_number (buf, INSN_SIZE);
21578
21579 /* If the addend is negative, clear bit 23 of the instruction.
21580 Otherwise set it. */
21581 if (value < 0)
21582 insn &= ~(1 << 23);
21583 else
21584 insn |= 1 << 23;
21585
21586 /* Place the first four bits of the absolute value of the addend
21587 into the first 4 bits of the instruction, and the remaining
21588 four into bits 8 .. 11. */
21589 insn &= 0xfffff0f0;
21590 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
21591
21592 /* Update the instruction. */
4962c51a
MS
21593 md_number_to_chars (buf, insn, INSN_SIZE);
21594 }
21595 break;
21596
21597 case BFD_RELOC_ARM_LDC_PC_G0:
21598 case BFD_RELOC_ARM_LDC_PC_G1:
21599 case BFD_RELOC_ARM_LDC_PC_G2:
21600 case BFD_RELOC_ARM_LDC_SB_G0:
21601 case BFD_RELOC_ARM_LDC_SB_G1:
21602 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 21603 gas_assert (!fixP->fx_done);
4962c51a
MS
21604 if (!seg->use_rela_p)
21605 {
21606 bfd_vma insn;
21607 bfd_vma addend_abs = abs (value);
21608
21609 /* Check that the absolute value of the addend is a multiple of
21610 four and, when divided by four, fits in 8 bits. */
21611 if (addend_abs & 0x3)
21612 as_bad_where (fixP->fx_file, fixP->fx_line,
21613 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 21614 (unsigned long) addend_abs);
4962c51a
MS
21615
21616 if ((addend_abs >> 2) > 0xff)
21617 as_bad_where (fixP->fx_file, fixP->fx_line,
21618 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 21619 (unsigned long) addend_abs);
4962c51a
MS
21620
21621 /* Extract the instruction. */
21622 insn = md_chars_to_number (buf, INSN_SIZE);
21623
21624 /* If the addend is negative, clear bit 23 of the instruction.
21625 Otherwise set it. */
21626 if (value < 0)
21627 insn &= ~(1 << 23);
21628 else
21629 insn |= 1 << 23;
21630
21631 /* Place the addend (divided by four) into the first eight
21632 bits of the instruction. */
21633 insn &= 0xfffffff0;
21634 insn |= addend_abs >> 2;
5f4273c7
NC
21635
21636 /* Update the instruction. */
4962c51a
MS
21637 md_number_to_chars (buf, insn, INSN_SIZE);
21638 }
21639 break;
21640
845b51d6
PB
21641 case BFD_RELOC_ARM_V4BX:
21642 /* This will need to go in the object file. */
21643 fixP->fx_done = 0;
21644 break;
21645
c19d1205
ZW
21646 case BFD_RELOC_UNUSED:
21647 default:
21648 as_bad_where (fixP->fx_file, fixP->fx_line,
21649 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
21650 }
6c43fab6
RE
21651}
21652
c19d1205
ZW
21653/* Translate internal representation of relocation info to BFD target
21654 format. */
a737bd4d 21655
c19d1205 21656arelent *
00a97672 21657tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 21658{
c19d1205
ZW
21659 arelent * reloc;
21660 bfd_reloc_code_real_type code;
a737bd4d 21661
21d799b5 21662 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 21663
21d799b5 21664 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
21665 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
21666 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 21667
2fc8bdac 21668 if (fixp->fx_pcrel)
00a97672
RS
21669 {
21670 if (section->use_rela_p)
21671 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
21672 else
21673 fixp->fx_offset = reloc->address;
21674 }
c19d1205 21675 reloc->addend = fixp->fx_offset;
a737bd4d 21676
c19d1205 21677 switch (fixp->fx_r_type)
a737bd4d 21678 {
c19d1205
ZW
21679 case BFD_RELOC_8:
21680 if (fixp->fx_pcrel)
21681 {
21682 code = BFD_RELOC_8_PCREL;
21683 break;
21684 }
a737bd4d 21685
c19d1205
ZW
21686 case BFD_RELOC_16:
21687 if (fixp->fx_pcrel)
21688 {
21689 code = BFD_RELOC_16_PCREL;
21690 break;
21691 }
6c43fab6 21692
c19d1205
ZW
21693 case BFD_RELOC_32:
21694 if (fixp->fx_pcrel)
21695 {
21696 code = BFD_RELOC_32_PCREL;
21697 break;
21698 }
a737bd4d 21699
b6895b4f
PB
21700 case BFD_RELOC_ARM_MOVW:
21701 if (fixp->fx_pcrel)
21702 {
21703 code = BFD_RELOC_ARM_MOVW_PCREL;
21704 break;
21705 }
21706
21707 case BFD_RELOC_ARM_MOVT:
21708 if (fixp->fx_pcrel)
21709 {
21710 code = BFD_RELOC_ARM_MOVT_PCREL;
21711 break;
21712 }
21713
21714 case BFD_RELOC_ARM_THUMB_MOVW:
21715 if (fixp->fx_pcrel)
21716 {
21717 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21718 break;
21719 }
21720
21721 case BFD_RELOC_ARM_THUMB_MOVT:
21722 if (fixp->fx_pcrel)
21723 {
21724 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21725 break;
21726 }
21727
c19d1205
ZW
21728 case BFD_RELOC_NONE:
21729 case BFD_RELOC_ARM_PCREL_BRANCH:
21730 case BFD_RELOC_ARM_PCREL_BLX:
21731 case BFD_RELOC_RVA:
21732 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21733 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21734 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21735 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21736 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21737 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
21738 case BFD_RELOC_VTABLE_ENTRY:
21739 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
21740#ifdef TE_PE
21741 case BFD_RELOC_32_SECREL:
21742#endif
c19d1205
ZW
21743 code = fixp->fx_r_type;
21744 break;
a737bd4d 21745
00adf2d4
JB
21746 case BFD_RELOC_THUMB_PCREL_BLX:
21747#ifdef OBJ_ELF
21748 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21749 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21750 else
21751#endif
21752 code = BFD_RELOC_THUMB_PCREL_BLX;
21753 break;
21754
c19d1205
ZW
21755 case BFD_RELOC_ARM_LITERAL:
21756 case BFD_RELOC_ARM_HWLITERAL:
21757 /* If this is called then the a literal has
21758 been referenced across a section boundary. */
21759 as_bad_where (fixp->fx_file, fixp->fx_line,
21760 _("literal referenced across section boundary"));
21761 return NULL;
a737bd4d 21762
c19d1205 21763#ifdef OBJ_ELF
0855e32b
NS
21764 case BFD_RELOC_ARM_TLS_CALL:
21765 case BFD_RELOC_ARM_THM_TLS_CALL:
21766 case BFD_RELOC_ARM_TLS_DESCSEQ:
21767 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
21768 case BFD_RELOC_ARM_GOT32:
21769 case BFD_RELOC_ARM_GOTOFF:
b43420e6 21770 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
21771 case BFD_RELOC_ARM_PLT32:
21772 case BFD_RELOC_ARM_TARGET1:
21773 case BFD_RELOC_ARM_ROSEGREL32:
21774 case BFD_RELOC_ARM_SBREL32:
21775 case BFD_RELOC_ARM_PREL31:
21776 case BFD_RELOC_ARM_TARGET2:
21777 case BFD_RELOC_ARM_TLS_LE32:
21778 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
21779 case BFD_RELOC_ARM_PCREL_CALL:
21780 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
21781 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21782 case BFD_RELOC_ARM_ALU_PC_G0:
21783 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21784 case BFD_RELOC_ARM_ALU_PC_G1:
21785 case BFD_RELOC_ARM_ALU_PC_G2:
21786 case BFD_RELOC_ARM_LDR_PC_G0:
21787 case BFD_RELOC_ARM_LDR_PC_G1:
21788 case BFD_RELOC_ARM_LDR_PC_G2:
21789 case BFD_RELOC_ARM_LDRS_PC_G0:
21790 case BFD_RELOC_ARM_LDRS_PC_G1:
21791 case BFD_RELOC_ARM_LDRS_PC_G2:
21792 case BFD_RELOC_ARM_LDC_PC_G0:
21793 case BFD_RELOC_ARM_LDC_PC_G1:
21794 case BFD_RELOC_ARM_LDC_PC_G2:
21795 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21796 case BFD_RELOC_ARM_ALU_SB_G0:
21797 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21798 case BFD_RELOC_ARM_ALU_SB_G1:
21799 case BFD_RELOC_ARM_ALU_SB_G2:
21800 case BFD_RELOC_ARM_LDR_SB_G0:
21801 case BFD_RELOC_ARM_LDR_SB_G1:
21802 case BFD_RELOC_ARM_LDR_SB_G2:
21803 case BFD_RELOC_ARM_LDRS_SB_G0:
21804 case BFD_RELOC_ARM_LDRS_SB_G1:
21805 case BFD_RELOC_ARM_LDRS_SB_G2:
21806 case BFD_RELOC_ARM_LDC_SB_G0:
21807 case BFD_RELOC_ARM_LDC_SB_G1:
21808 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 21809 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
21810 code = fixp->fx_r_type;
21811 break;
a737bd4d 21812
0855e32b 21813 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
21814 case BFD_RELOC_ARM_TLS_GD32:
21815 case BFD_RELOC_ARM_TLS_IE32:
21816 case BFD_RELOC_ARM_TLS_LDM32:
21817 /* BFD will include the symbol's address in the addend.
21818 But we don't want that, so subtract it out again here. */
21819 if (!S_IS_COMMON (fixp->fx_addsy))
21820 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21821 code = fixp->fx_r_type;
21822 break;
21823#endif
a737bd4d 21824
c19d1205
ZW
21825 case BFD_RELOC_ARM_IMMEDIATE:
21826 as_bad_where (fixp->fx_file, fixp->fx_line,
21827 _("internal relocation (type: IMMEDIATE) not fixed up"));
21828 return NULL;
a737bd4d 21829
c19d1205
ZW
21830 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21831 as_bad_where (fixp->fx_file, fixp->fx_line,
21832 _("ADRL used for a symbol not defined in the same file"));
21833 return NULL;
a737bd4d 21834
c19d1205 21835 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
21836 if (section->use_rela_p)
21837 {
21838 code = fixp->fx_r_type;
21839 break;
21840 }
21841
c19d1205
ZW
21842 if (fixp->fx_addsy != NULL
21843 && !S_IS_DEFINED (fixp->fx_addsy)
21844 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 21845 {
c19d1205
ZW
21846 as_bad_where (fixp->fx_file, fixp->fx_line,
21847 _("undefined local label `%s'"),
21848 S_GET_NAME (fixp->fx_addsy));
21849 return NULL;
a737bd4d
NC
21850 }
21851
c19d1205
ZW
21852 as_bad_where (fixp->fx_file, fixp->fx_line,
21853 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21854 return NULL;
a737bd4d 21855
c19d1205
ZW
21856 default:
21857 {
21858 char * type;
6c43fab6 21859
c19d1205
ZW
21860 switch (fixp->fx_r_type)
21861 {
21862 case BFD_RELOC_NONE: type = "NONE"; break;
21863 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21864 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 21865 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
21866 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21867 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21868 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 21869 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 21870 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
21871 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21872 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21873 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21874 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21875 default: type = _("<unknown>"); break;
21876 }
21877 as_bad_where (fixp->fx_file, fixp->fx_line,
21878 _("cannot represent %s relocation in this object file format"),
21879 type);
21880 return NULL;
21881 }
a737bd4d 21882 }
6c43fab6 21883
c19d1205
ZW
21884#ifdef OBJ_ELF
21885 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21886 && GOT_symbol
21887 && fixp->fx_addsy == GOT_symbol)
21888 {
21889 code = BFD_RELOC_ARM_GOTPC;
21890 reloc->addend = fixp->fx_offset = reloc->address;
21891 }
21892#endif
6c43fab6 21893
c19d1205 21894 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 21895
c19d1205
ZW
21896 if (reloc->howto == NULL)
21897 {
21898 as_bad_where (fixp->fx_file, fixp->fx_line,
21899 _("cannot represent %s relocation in this object file format"),
21900 bfd_get_reloc_code_name (code));
21901 return NULL;
21902 }
6c43fab6 21903
c19d1205
ZW
21904 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21905 vtable entry to be used in the relocation's section offset. */
21906 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21907 reloc->address = fixp->fx_offset;
6c43fab6 21908
c19d1205 21909 return reloc;
6c43fab6
RE
21910}
21911
c19d1205 21912/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 21913
c19d1205
ZW
21914void
21915cons_fix_new_arm (fragS * frag,
21916 int where,
21917 int size,
21918 expressionS * exp)
6c43fab6 21919{
c19d1205
ZW
21920 bfd_reloc_code_real_type type;
21921 int pcrel = 0;
6c43fab6 21922
c19d1205
ZW
21923 /* Pick a reloc.
21924 FIXME: @@ Should look at CPU word size. */
21925 switch (size)
21926 {
21927 case 1:
21928 type = BFD_RELOC_8;
21929 break;
21930 case 2:
21931 type = BFD_RELOC_16;
21932 break;
21933 case 4:
21934 default:
21935 type = BFD_RELOC_32;
21936 break;
21937 case 8:
21938 type = BFD_RELOC_64;
21939 break;
21940 }
6c43fab6 21941
f0927246
NC
21942#ifdef TE_PE
21943 if (exp->X_op == O_secrel)
21944 {
21945 exp->X_op = O_symbol;
21946 type = BFD_RELOC_32_SECREL;
21947 }
21948#endif
21949
c19d1205
ZW
21950 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21951}
6c43fab6 21952
4343666d 21953#if defined (OBJ_COFF)
c19d1205
ZW
21954void
21955arm_validate_fix (fixS * fixP)
6c43fab6 21956{
c19d1205
ZW
21957 /* If the destination of the branch is a defined symbol which does not have
21958 the THUMB_FUNC attribute, then we must be calling a function which has
21959 the (interfacearm) attribute. We look for the Thumb entry point to that
21960 function and change the branch to refer to that function instead. */
21961 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21962 && fixP->fx_addsy != NULL
21963 && S_IS_DEFINED (fixP->fx_addsy)
21964 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 21965 {
c19d1205 21966 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 21967 }
c19d1205
ZW
21968}
21969#endif
6c43fab6 21970
267bf995 21971
c19d1205
ZW
21972int
21973arm_force_relocation (struct fix * fixp)
21974{
21975#if defined (OBJ_COFF) && defined (TE_PE)
21976 if (fixp->fx_r_type == BFD_RELOC_RVA)
21977 return 1;
21978#endif
6c43fab6 21979
267bf995
RR
21980 /* In case we have a call or a branch to a function in ARM ISA mode from
21981 a thumb function or vice-versa force the relocation. These relocations
21982 are cleared off for some cores that might have blx and simple transformations
21983 are possible. */
21984
21985#ifdef OBJ_ELF
21986 switch (fixp->fx_r_type)
21987 {
21988 case BFD_RELOC_ARM_PCREL_JUMP:
21989 case BFD_RELOC_ARM_PCREL_CALL:
21990 case BFD_RELOC_THUMB_PCREL_BLX:
21991 if (THUMB_IS_FUNC (fixp->fx_addsy))
21992 return 1;
21993 break;
21994
21995 case BFD_RELOC_ARM_PCREL_BLX:
21996 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21997 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21998 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21999 if (ARM_IS_FUNC (fixp->fx_addsy))
22000 return 1;
22001 break;
22002
22003 default:
22004 break;
22005 }
22006#endif
22007
b5884301
PB
22008 /* Resolve these relocations even if the symbol is extern or weak.
22009 Technically this is probably wrong due to symbol preemption.
22010 In practice these relocations do not have enough range to be useful
22011 at dynamic link time, and some code (e.g. in the Linux kernel)
22012 expects these references to be resolved. */
c19d1205
ZW
22013 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
22014 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 22015 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 22016 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
22017 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22018 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
22019 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 22020 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
22021 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22022 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
22023 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
22024 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
22025 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
22026 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 22027 return 0;
a737bd4d 22028
4962c51a
MS
22029 /* Always leave these relocations for the linker. */
22030 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22031 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22032 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
22033 return 1;
22034
f0291e4c
PB
22035 /* Always generate relocations against function symbols. */
22036 if (fixp->fx_r_type == BFD_RELOC_32
22037 && fixp->fx_addsy
22038 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
22039 return 1;
22040
c19d1205 22041 return generic_force_reloc (fixp);
404ff6b5
AH
22042}
22043
0ffdc86c 22044#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
22045/* Relocations against function names must be left unadjusted,
22046 so that the linker can use this information to generate interworking
22047 stubs. The MIPS version of this function
c19d1205
ZW
22048 also prevents relocations that are mips-16 specific, but I do not
22049 know why it does this.
404ff6b5 22050
c19d1205
ZW
22051 FIXME:
22052 There is one other problem that ought to be addressed here, but
22053 which currently is not: Taking the address of a label (rather
22054 than a function) and then later jumping to that address. Such
22055 addresses also ought to have their bottom bit set (assuming that
22056 they reside in Thumb code), but at the moment they will not. */
404ff6b5 22057
c19d1205
ZW
22058bfd_boolean
22059arm_fix_adjustable (fixS * fixP)
404ff6b5 22060{
c19d1205
ZW
22061 if (fixP->fx_addsy == NULL)
22062 return 1;
404ff6b5 22063
e28387c3
PB
22064 /* Preserve relocations against symbols with function type. */
22065 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 22066 return FALSE;
e28387c3 22067
c19d1205
ZW
22068 if (THUMB_IS_FUNC (fixP->fx_addsy)
22069 && fixP->fx_subsy == NULL)
c921be7d 22070 return FALSE;
a737bd4d 22071
c19d1205
ZW
22072 /* We need the symbol name for the VTABLE entries. */
22073 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
22074 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 22075 return FALSE;
404ff6b5 22076
c19d1205
ZW
22077 /* Don't allow symbols to be discarded on GOT related relocs. */
22078 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
22079 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
22080 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
22081 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
22082 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
22083 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
22084 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
22085 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
22086 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
22087 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
22088 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
22089 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
22090 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 22091 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 22092 return FALSE;
a737bd4d 22093
4962c51a
MS
22094 /* Similarly for group relocations. */
22095 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22096 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22097 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 22098 return FALSE;
4962c51a 22099
79947c54
CD
22100 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
22101 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
22102 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
22103 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
22104 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
22105 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
22106 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
22107 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
22108 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 22109 return FALSE;
79947c54 22110
c921be7d 22111 return TRUE;
a737bd4d 22112}
0ffdc86c
NC
22113#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
22114
22115#ifdef OBJ_ELF
404ff6b5 22116
c19d1205
ZW
22117const char *
22118elf32_arm_target_format (void)
404ff6b5 22119{
c19d1205
ZW
22120#ifdef TE_SYMBIAN
22121 return (target_big_endian
22122 ? "elf32-bigarm-symbian"
22123 : "elf32-littlearm-symbian");
22124#elif defined (TE_VXWORKS)
22125 return (target_big_endian
22126 ? "elf32-bigarm-vxworks"
22127 : "elf32-littlearm-vxworks");
22128#else
22129 if (target_big_endian)
22130 return "elf32-bigarm";
22131 else
22132 return "elf32-littlearm";
22133#endif
404ff6b5
AH
22134}
22135
c19d1205
ZW
22136void
22137armelf_frob_symbol (symbolS * symp,
22138 int * puntp)
404ff6b5 22139{
c19d1205
ZW
22140 elf_frob_symbol (symp, puntp);
22141}
22142#endif
404ff6b5 22143
c19d1205 22144/* MD interface: Finalization. */
a737bd4d 22145
c19d1205
ZW
22146void
22147arm_cleanup (void)
22148{
22149 literal_pool * pool;
a737bd4d 22150
e07e6e58
NC
22151 /* Ensure that all the IT blocks are properly closed. */
22152 check_it_blocks_finished ();
22153
c19d1205
ZW
22154 for (pool = list_of_pools; pool; pool = pool->next)
22155 {
5f4273c7 22156 /* Put it at the end of the relevant section. */
c19d1205
ZW
22157 subseg_set (pool->section, pool->sub_section);
22158#ifdef OBJ_ELF
22159 arm_elf_change_section ();
22160#endif
22161 s_ltorg (0);
22162 }
404ff6b5
AH
22163}
22164
cd000bff
DJ
22165#ifdef OBJ_ELF
22166/* Remove any excess mapping symbols generated for alignment frags in
22167 SEC. We may have created a mapping symbol before a zero byte
22168 alignment; remove it if there's a mapping symbol after the
22169 alignment. */
22170static void
22171check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
22172 void *dummy ATTRIBUTE_UNUSED)
22173{
22174 segment_info_type *seginfo = seg_info (sec);
22175 fragS *fragp;
22176
22177 if (seginfo == NULL || seginfo->frchainP == NULL)
22178 return;
22179
22180 for (fragp = seginfo->frchainP->frch_root;
22181 fragp != NULL;
22182 fragp = fragp->fr_next)
22183 {
22184 symbolS *sym = fragp->tc_frag_data.last_map;
22185 fragS *next = fragp->fr_next;
22186
22187 /* Variable-sized frags have been converted to fixed size by
22188 this point. But if this was variable-sized to start with,
22189 there will be a fixed-size frag after it. So don't handle
22190 next == NULL. */
22191 if (sym == NULL || next == NULL)
22192 continue;
22193
22194 if (S_GET_VALUE (sym) < next->fr_address)
22195 /* Not at the end of this frag. */
22196 continue;
22197 know (S_GET_VALUE (sym) == next->fr_address);
22198
22199 do
22200 {
22201 if (next->tc_frag_data.first_map != NULL)
22202 {
22203 /* Next frag starts with a mapping symbol. Discard this
22204 one. */
22205 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22206 break;
22207 }
22208
22209 if (next->fr_next == NULL)
22210 {
22211 /* This mapping symbol is at the end of the section. Discard
22212 it. */
22213 know (next->fr_fix == 0 && next->fr_var == 0);
22214 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22215 break;
22216 }
22217
22218 /* As long as we have empty frags without any mapping symbols,
22219 keep looking. */
22220 /* If the next frag is non-empty and does not start with a
22221 mapping symbol, then this mapping symbol is required. */
22222 if (next->fr_address != next->fr_next->fr_address)
22223 break;
22224
22225 next = next->fr_next;
22226 }
22227 while (next != NULL);
22228 }
22229}
22230#endif
22231
c19d1205
ZW
22232/* Adjust the symbol table. This marks Thumb symbols as distinct from
22233 ARM ones. */
404ff6b5 22234
c19d1205
ZW
22235void
22236arm_adjust_symtab (void)
404ff6b5 22237{
c19d1205
ZW
22238#ifdef OBJ_COFF
22239 symbolS * sym;
404ff6b5 22240
c19d1205
ZW
22241 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
22242 {
22243 if (ARM_IS_THUMB (sym))
22244 {
22245 if (THUMB_IS_FUNC (sym))
22246 {
22247 /* Mark the symbol as a Thumb function. */
22248 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
22249 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
22250 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 22251
c19d1205
ZW
22252 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
22253 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
22254 else
22255 as_bad (_("%s: unexpected function type: %d"),
22256 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
22257 }
22258 else switch (S_GET_STORAGE_CLASS (sym))
22259 {
22260 case C_EXT:
22261 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
22262 break;
22263 case C_STAT:
22264 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
22265 break;
22266 case C_LABEL:
22267 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
22268 break;
22269 default:
22270 /* Do nothing. */
22271 break;
22272 }
22273 }
a737bd4d 22274
c19d1205
ZW
22275 if (ARM_IS_INTERWORK (sym))
22276 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 22277 }
c19d1205
ZW
22278#endif
22279#ifdef OBJ_ELF
22280 symbolS * sym;
22281 char bind;
404ff6b5 22282
c19d1205 22283 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 22284 {
c19d1205
ZW
22285 if (ARM_IS_THUMB (sym))
22286 {
22287 elf_symbol_type * elf_sym;
404ff6b5 22288
c19d1205
ZW
22289 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
22290 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 22291
b0796911
PB
22292 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
22293 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
22294 {
22295 /* If it's a .thumb_func, declare it as so,
22296 otherwise tag label as .code 16. */
22297 if (THUMB_IS_FUNC (sym))
35fc36a8
RS
22298 elf_sym->internal_elf_sym.st_target_internal
22299 = ST_BRANCH_TO_THUMB;
3ba67470 22300 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
22301 elf_sym->internal_elf_sym.st_info =
22302 ELF_ST_INFO (bind, STT_ARM_16BIT);
22303 }
22304 }
22305 }
cd000bff
DJ
22306
22307 /* Remove any overlapping mapping symbols generated by alignment frags. */
22308 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
22309 /* Now do generic ELF adjustments. */
22310 elf_adjust_symtab ();
c19d1205 22311#endif
404ff6b5
AH
22312}
22313
c19d1205 22314/* MD interface: Initialization. */
404ff6b5 22315
a737bd4d 22316static void
c19d1205 22317set_constant_flonums (void)
a737bd4d 22318{
c19d1205 22319 int i;
404ff6b5 22320
c19d1205
ZW
22321 for (i = 0; i < NUM_FLOAT_VALS; i++)
22322 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
22323 abort ();
a737bd4d 22324}
404ff6b5 22325
3e9e4fcf
JB
22326/* Auto-select Thumb mode if it's the only available instruction set for the
22327 given architecture. */
22328
22329static void
22330autoselect_thumb_from_cpu_variant (void)
22331{
22332 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
22333 opcode_select (16);
22334}
22335
c19d1205
ZW
22336void
22337md_begin (void)
a737bd4d 22338{
c19d1205
ZW
22339 unsigned mach;
22340 unsigned int i;
404ff6b5 22341
c19d1205
ZW
22342 if ( (arm_ops_hsh = hash_new ()) == NULL
22343 || (arm_cond_hsh = hash_new ()) == NULL
22344 || (arm_shift_hsh = hash_new ()) == NULL
22345 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 22346 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 22347 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
22348 || (arm_reloc_hsh = hash_new ()) == NULL
22349 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
22350 as_fatal (_("virtual memory exhausted"));
22351
22352 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 22353 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 22354 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 22355 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 22356 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 22357 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 22358 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 22359 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 22360 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0
NC
22361 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
22362 (void *) (v7m_psrs + i));
c19d1205 22363 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 22364 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
22365 for (i = 0;
22366 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
22367 i++)
d3ce72d0 22368 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 22369 (void *) (barrier_opt_names + i));
c19d1205
ZW
22370#ifdef OBJ_ELF
22371 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 22372 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
22373#endif
22374
22375 set_constant_flonums ();
404ff6b5 22376
c19d1205
ZW
22377 /* Set the cpu variant based on the command-line options. We prefer
22378 -mcpu= over -march= if both are set (as for GCC); and we prefer
22379 -mfpu= over any other way of setting the floating point unit.
22380 Use of legacy options with new options are faulted. */
e74cfd16 22381 if (legacy_cpu)
404ff6b5 22382 {
e74cfd16 22383 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
22384 as_bad (_("use of old and new-style options to set CPU type"));
22385
22386 mcpu_cpu_opt = legacy_cpu;
404ff6b5 22387 }
e74cfd16 22388 else if (!mcpu_cpu_opt)
c19d1205 22389 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 22390
e74cfd16 22391 if (legacy_fpu)
c19d1205 22392 {
e74cfd16 22393 if (mfpu_opt)
c19d1205 22394 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
22395
22396 mfpu_opt = legacy_fpu;
22397 }
e74cfd16 22398 else if (!mfpu_opt)
03b1477f 22399 {
45eb4c1b
NS
22400#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
22401 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
22402 /* Some environments specify a default FPU. If they don't, infer it
22403 from the processor. */
e74cfd16 22404 if (mcpu_fpu_opt)
03b1477f
RE
22405 mfpu_opt = mcpu_fpu_opt;
22406 else
22407 mfpu_opt = march_fpu_opt;
39c2da32 22408#else
e74cfd16 22409 mfpu_opt = &fpu_default;
39c2da32 22410#endif
03b1477f
RE
22411 }
22412
e74cfd16 22413 if (!mfpu_opt)
03b1477f 22414 {
493cb6ef 22415 if (mcpu_cpu_opt != NULL)
e74cfd16 22416 mfpu_opt = &fpu_default;
493cb6ef 22417 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 22418 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 22419 else
e74cfd16 22420 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
22421 }
22422
ee065d83 22423#ifdef CPU_DEFAULT
e74cfd16 22424 if (!mcpu_cpu_opt)
ee065d83 22425 {
e74cfd16
PB
22426 mcpu_cpu_opt = &cpu_default;
22427 selected_cpu = cpu_default;
ee065d83 22428 }
e74cfd16
PB
22429#else
22430 if (mcpu_cpu_opt)
22431 selected_cpu = *mcpu_cpu_opt;
ee065d83 22432 else
e74cfd16 22433 mcpu_cpu_opt = &arm_arch_any;
ee065d83 22434#endif
03b1477f 22435
e74cfd16 22436 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 22437
3e9e4fcf
JB
22438 autoselect_thumb_from_cpu_variant ();
22439
e74cfd16 22440 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 22441
f17c130b 22442#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 22443 {
7cc69913
NC
22444 unsigned int flags = 0;
22445
22446#if defined OBJ_ELF
22447 flags = meabi_flags;
d507cf36
PB
22448
22449 switch (meabi_flags)
33a392fb 22450 {
d507cf36 22451 case EF_ARM_EABI_UNKNOWN:
7cc69913 22452#endif
d507cf36
PB
22453 /* Set the flags in the private structure. */
22454 if (uses_apcs_26) flags |= F_APCS26;
22455 if (support_interwork) flags |= F_INTERWORK;
22456 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 22457 if (pic_code) flags |= F_PIC;
e74cfd16 22458 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
22459 flags |= F_SOFT_FLOAT;
22460
d507cf36
PB
22461 switch (mfloat_abi_opt)
22462 {
22463 case ARM_FLOAT_ABI_SOFT:
22464 case ARM_FLOAT_ABI_SOFTFP:
22465 flags |= F_SOFT_FLOAT;
22466 break;
33a392fb 22467
d507cf36
PB
22468 case ARM_FLOAT_ABI_HARD:
22469 if (flags & F_SOFT_FLOAT)
22470 as_bad (_("hard-float conflicts with specified fpu"));
22471 break;
22472 }
03b1477f 22473
e74cfd16
PB
22474 /* Using pure-endian doubles (even if soft-float). */
22475 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 22476 flags |= F_VFP_FLOAT;
f17c130b 22477
fde78edd 22478#if defined OBJ_ELF
e74cfd16 22479 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 22480 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
22481 break;
22482
8cb51566 22483 case EF_ARM_EABI_VER4:
3a4a14e9 22484 case EF_ARM_EABI_VER5:
c19d1205 22485 /* No additional flags to set. */
d507cf36
PB
22486 break;
22487
22488 default:
22489 abort ();
22490 }
7cc69913 22491#endif
b99bd4ef
NC
22492 bfd_set_private_flags (stdoutput, flags);
22493
22494 /* We have run out flags in the COFF header to encode the
22495 status of ATPCS support, so instead we create a dummy,
c19d1205 22496 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
22497 if (atpcs)
22498 {
22499 asection * sec;
22500
22501 sec = bfd_make_section (stdoutput, ".arm.atpcs");
22502
22503 if (sec != NULL)
22504 {
22505 bfd_set_section_flags
22506 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
22507 bfd_set_section_size (stdoutput, sec, 0);
22508 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
22509 }
22510 }
7cc69913 22511 }
f17c130b 22512#endif
b99bd4ef
NC
22513
22514 /* Record the CPU type as well. */
2d447fca
JM
22515 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
22516 mach = bfd_mach_arm_iWMMXt2;
22517 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 22518 mach = bfd_mach_arm_iWMMXt;
e74cfd16 22519 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 22520 mach = bfd_mach_arm_XScale;
e74cfd16 22521 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 22522 mach = bfd_mach_arm_ep9312;
e74cfd16 22523 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 22524 mach = bfd_mach_arm_5TE;
e74cfd16 22525 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 22526 {
e74cfd16 22527 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22528 mach = bfd_mach_arm_5T;
22529 else
22530 mach = bfd_mach_arm_5;
22531 }
e74cfd16 22532 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 22533 {
e74cfd16 22534 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22535 mach = bfd_mach_arm_4T;
22536 else
22537 mach = bfd_mach_arm_4;
22538 }
e74cfd16 22539 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 22540 mach = bfd_mach_arm_3M;
e74cfd16
PB
22541 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
22542 mach = bfd_mach_arm_3;
22543 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
22544 mach = bfd_mach_arm_2a;
22545 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
22546 mach = bfd_mach_arm_2;
22547 else
22548 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
22549
22550 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
22551}
22552
c19d1205 22553/* Command line processing. */
b99bd4ef 22554
c19d1205
ZW
22555/* md_parse_option
22556 Invocation line includes a switch not recognized by the base assembler.
22557 See if it's a processor-specific option.
b99bd4ef 22558
c19d1205
ZW
22559 This routine is somewhat complicated by the need for backwards
22560 compatibility (since older releases of gcc can't be changed).
22561 The new options try to make the interface as compatible as
22562 possible with GCC.
b99bd4ef 22563
c19d1205 22564 New options (supported) are:
b99bd4ef 22565
c19d1205
ZW
22566 -mcpu=<cpu name> Assemble for selected processor
22567 -march=<architecture name> Assemble for selected architecture
22568 -mfpu=<fpu architecture> Assemble for selected FPU.
22569 -EB/-mbig-endian Big-endian
22570 -EL/-mlittle-endian Little-endian
22571 -k Generate PIC code
22572 -mthumb Start in Thumb mode
22573 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 22574
278df34e 22575 -m[no-]warn-deprecated Warn about deprecated features
267bf995 22576
c19d1205 22577 For now we will also provide support for:
b99bd4ef 22578
c19d1205
ZW
22579 -mapcs-32 32-bit Program counter
22580 -mapcs-26 26-bit Program counter
22581 -macps-float Floats passed in FP registers
22582 -mapcs-reentrant Reentrant code
22583 -matpcs
22584 (sometime these will probably be replaced with -mapcs=<list of options>
22585 and -matpcs=<list of options>)
b99bd4ef 22586
c19d1205
ZW
22587 The remaining options are only supported for back-wards compatibility.
22588 Cpu variants, the arm part is optional:
22589 -m[arm]1 Currently not supported.
22590 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
22591 -m[arm]3 Arm 3 processor
22592 -m[arm]6[xx], Arm 6 processors
22593 -m[arm]7[xx][t][[d]m] Arm 7 processors
22594 -m[arm]8[10] Arm 8 processors
22595 -m[arm]9[20][tdmi] Arm 9 processors
22596 -mstrongarm[110[0]] StrongARM processors
22597 -mxscale XScale processors
22598 -m[arm]v[2345[t[e]]] Arm architectures
22599 -mall All (except the ARM1)
22600 FP variants:
22601 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
22602 -mfpe-old (No float load/store multiples)
22603 -mvfpxd VFP Single precision
22604 -mvfp All VFP
22605 -mno-fpu Disable all floating point instructions
b99bd4ef 22606
c19d1205
ZW
22607 The following CPU names are recognized:
22608 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
22609 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
22610 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
22611 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
22612 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
22613 arm10t arm10e, arm1020t, arm1020e, arm10200e,
22614 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 22615
c19d1205 22616 */
b99bd4ef 22617
c19d1205 22618const char * md_shortopts = "m:k";
b99bd4ef 22619
c19d1205
ZW
22620#ifdef ARM_BI_ENDIAN
22621#define OPTION_EB (OPTION_MD_BASE + 0)
22622#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 22623#else
c19d1205
ZW
22624#if TARGET_BYTES_BIG_ENDIAN
22625#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 22626#else
c19d1205
ZW
22627#define OPTION_EL (OPTION_MD_BASE + 1)
22628#endif
b99bd4ef 22629#endif
845b51d6 22630#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 22631
c19d1205 22632struct option md_longopts[] =
b99bd4ef 22633{
c19d1205
ZW
22634#ifdef OPTION_EB
22635 {"EB", no_argument, NULL, OPTION_EB},
22636#endif
22637#ifdef OPTION_EL
22638 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 22639#endif
845b51d6 22640 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
22641 {NULL, no_argument, NULL, 0}
22642};
b99bd4ef 22643
c19d1205 22644size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 22645
c19d1205 22646struct arm_option_table
b99bd4ef 22647{
c19d1205
ZW
22648 char *option; /* Option name to match. */
22649 char *help; /* Help information. */
22650 int *var; /* Variable to change. */
22651 int value; /* What to change it to. */
22652 char *deprecated; /* If non-null, print this message. */
22653};
b99bd4ef 22654
c19d1205
ZW
22655struct arm_option_table arm_opts[] =
22656{
22657 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
22658 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
22659 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
22660 &support_interwork, 1, NULL},
22661 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
22662 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
22663 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
22664 1, NULL},
22665 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
22666 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
22667 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
22668 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
22669 NULL},
b99bd4ef 22670
c19d1205
ZW
22671 /* These are recognized by the assembler, but have no affect on code. */
22672 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
22673 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
22674
22675 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
22676 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
22677 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
22678 {NULL, NULL, NULL, 0, NULL}
22679};
22680
22681struct arm_legacy_option_table
22682{
22683 char *option; /* Option name to match. */
22684 const arm_feature_set **var; /* Variable to change. */
22685 const arm_feature_set value; /* What to change it to. */
22686 char *deprecated; /* If non-null, print this message. */
22687};
b99bd4ef 22688
e74cfd16
PB
22689const struct arm_legacy_option_table arm_legacy_opts[] =
22690{
c19d1205
ZW
22691 /* DON'T add any new processors to this list -- we want the whole list
22692 to go away... Add them to the processors table instead. */
e74cfd16
PB
22693 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22694 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22695 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22696 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22697 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22698 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22699 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22700 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22701 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22702 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22703 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22704 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22705 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22706 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22707 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22708 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22709 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22710 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22711 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22712 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22713 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22714 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22715 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22716 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22717 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22718 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22719 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22720 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22721 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22722 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22723 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22724 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22725 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22726 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22727 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22728 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22729 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22730 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22731 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22732 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22733 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22734 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22735 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22736 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22737 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22738 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22739 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22740 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22741 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22742 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22743 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22744 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22745 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22746 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22747 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22748 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22749 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22750 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22751 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22752 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22753 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22754 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22755 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22756 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22757 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22758 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22759 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22760 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22761 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22762 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22763 N_("use -mcpu=strongarm110")},
e74cfd16 22764 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22765 N_("use -mcpu=strongarm1100")},
e74cfd16 22766 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22767 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
22768 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22769 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22770 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 22771
c19d1205 22772 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
22773 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22774 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22775 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22776 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22777 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22778 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22779 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22780 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22781 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22782 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22783 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22784 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22785 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22786 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22787 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22788 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22789 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22790 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 22791
c19d1205 22792 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
22793 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22794 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22795 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22796 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 22797 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 22798
e74cfd16 22799 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 22800};
7ed4c4c5 22801
c19d1205 22802struct arm_cpu_option_table
7ed4c4c5 22803{
c19d1205 22804 char *name;
e74cfd16 22805 const arm_feature_set value;
c19d1205
ZW
22806 /* For some CPUs we assume an FPU unless the user explicitly sets
22807 -mfpu=... */
e74cfd16 22808 const arm_feature_set default_fpu;
ee065d83
PB
22809 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22810 case. */
22811 const char *canonical_name;
c19d1205 22812};
7ed4c4c5 22813
c19d1205
ZW
22814/* This list should, at a minimum, contain all the cpu names
22815 recognized by GCC. */
e74cfd16 22816static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 22817{
ee065d83
PB
22818 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
22819 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
22820 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
22821 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22822 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22823 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22824 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22825 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22826 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22827 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22828 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22829 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22830 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22831 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22832 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22833 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22834 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22835 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22836 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22837 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22838 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22839 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22840 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22841 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22842 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22843 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22844 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22845 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22846 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22847 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22848 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22849 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22850 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22851 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22852 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22853 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22854 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22855 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22856 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22857 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
22858 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22859 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22860 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22861 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
22862 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22863 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
22864 /* For V5 or later processors we default to using VFP; but the user
22865 should really set the FPU type explicitly. */
ee065d83
PB
22866 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22867 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22868 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22869 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22870 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22871 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22872 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22873 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22874 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22875 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22876 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22877 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22878 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22879 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22880 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22881 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22882 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22883 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22884 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22885 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22886 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
4a58c4bd
NC
22887 {"fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22888 {"fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22889 {"fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22890 {"fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
7fac0536 22891 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
22892 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22893 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22894 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22895 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
4ff9b924
MGD
22896 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"},
22897 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"},
ee065d83
PB
22898 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22899 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22900 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22901 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
f4c65163
MGD
22902 {"cortex-a5", ARM_ARCH_V7A_MP_SEC,
22903 FPU_NONE, "Cortex-A5"},
22904 {"cortex-a8", ARM_ARCH_V7A_SEC,
22905 ARM_FEATURE (0, FPU_VFP_V3
5287ad62 22906 | FPU_NEON_EXT_V1),
4ff9b924 22907 "Cortex-A8"},
f4c65163
MGD
22908 {"cortex-a9", ARM_ARCH_V7A_MP_SEC,
22909 ARM_FEATURE (0, FPU_VFP_V3
15290f0a 22910 | FPU_NEON_EXT_V1),
4ff9b924 22911 "Cortex-A9"},
90ec0d68 22912 {"cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
eea54501 22913 FPU_ARCH_NEON_VFP_V4,
dbb1f804 22914 "Cortex-A15"},
4ff9b924
MGD
22915 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"},
22916 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
22917 "Cortex-R4F"},
3b2f0793
PB
22918 {"cortex-r5", ARM_ARCH_V7R_IDIV,
22919 FPU_NONE, "Cortex-R5"},
4ff9b924
MGD
22920 {"cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"},
22921 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"},
b2a5fbdc
MGD
22922 {"cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"},
22923 {"cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"},
c19d1205 22924 /* ??? XSCALE is really an architecture. */
ee065d83 22925 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22926 /* ??? iwmmxt is not a processor. */
ee065d83 22927 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 22928 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 22929 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22930 /* Maverick */
e07e6e58 22931 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
e74cfd16 22932 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 22933};
7ed4c4c5 22934
c19d1205 22935struct arm_arch_option_table
7ed4c4c5 22936{
c19d1205 22937 char *name;
e74cfd16
PB
22938 const arm_feature_set value;
22939 const arm_feature_set default_fpu;
c19d1205 22940};
7ed4c4c5 22941
c19d1205
ZW
22942/* This list should, at a minimum, contain all the architecture names
22943 recognized by GCC. */
e74cfd16 22944static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
22945{
22946 {"all", ARM_ANY, FPU_ARCH_FPA},
22947 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22948 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22949 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22950 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22951 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22952 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22953 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22954 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22955 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22956 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22957 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22958 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22959 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22960 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22961 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22962 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22963 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22964 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22965 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22966 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22967 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22968 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22969 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22970 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22971 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 22972 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
b2a5fbdc 22973 {"armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP},
62b3e311 22974 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
22975 /* The official spelling of the ARMv7 profile variants is the dashed form.
22976 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
22977 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22978 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22979 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
22980 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22981 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22982 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
9e3c6df6 22983 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
c19d1205
ZW
22984 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22985 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 22986 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 22987 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 22988};
7ed4c4c5 22989
69133863
MGD
22990/* ISA extensions in the co-processor and main instruction set space. */
22991struct arm_option_extension_value_table
c19d1205
ZW
22992{
22993 char *name;
e74cfd16 22994 const arm_feature_set value;
69133863 22995 const arm_feature_set allowed_archs;
c19d1205 22996};
7ed4c4c5 22997
69133863
MGD
22998/* The following table must be in alphabetical order with a NULL last entry.
22999 */
23000static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 23001{
eea54501 23002 {"idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0),
3b2f0793 23003 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)},
69133863
MGD
23004 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY},
23005 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY},
23006 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY},
60e5ef9f
MGD
23007 {"mp", ARM_FEATURE (ARM_EXT_MP, 0),
23008 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)},
b2a5fbdc
MGD
23009 {"os", ARM_FEATURE (ARM_EXT_OS, 0),
23010 ARM_FEATURE (ARM_EXT_V6M, 0)},
f4c65163
MGD
23011 {"sec", ARM_FEATURE (ARM_EXT_SEC, 0),
23012 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)},
90ec0d68
MGD
23013 {"virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV | ARM_EXT_DIV, 0),
23014 ARM_FEATURE (ARM_EXT_V7A, 0)},
69133863 23015 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY},
60e5ef9f 23016 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
69133863
MGD
23017};
23018
23019/* ISA floating-point and Advanced SIMD extensions. */
23020struct arm_option_fpu_value_table
23021{
23022 char *name;
23023 const arm_feature_set value;
c19d1205 23024};
7ed4c4c5 23025
c19d1205
ZW
23026/* This list should, at a minimum, contain all the fpu names
23027 recognized by GCC. */
69133863 23028static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
23029{
23030 {"softfpa", FPU_NONE},
23031 {"fpe", FPU_ARCH_FPE},
23032 {"fpe2", FPU_ARCH_FPE},
23033 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
23034 {"fpa", FPU_ARCH_FPA},
23035 {"fpa10", FPU_ARCH_FPA},
23036 {"fpa11", FPU_ARCH_FPA},
23037 {"arm7500fe", FPU_ARCH_FPA},
23038 {"softvfp", FPU_ARCH_VFP},
23039 {"softvfp+vfp", FPU_ARCH_VFP_V2},
23040 {"vfp", FPU_ARCH_VFP_V2},
23041 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 23042 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
23043 {"vfp10", FPU_ARCH_VFP_V2},
23044 {"vfp10-r0", FPU_ARCH_VFP_V1},
23045 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
23046 {"vfpv2", FPU_ARCH_VFP_V2},
23047 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 23048 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 23049 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
23050 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
23051 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
23052 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
23053 {"arm1020t", FPU_ARCH_VFP_V1},
23054 {"arm1020e", FPU_ARCH_VFP_V2},
23055 {"arm1136jfs", FPU_ARCH_VFP_V2},
23056 {"arm1136jf-s", FPU_ARCH_VFP_V2},
23057 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 23058 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 23059 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
23060 {"vfpv4", FPU_ARCH_VFP_V4},
23061 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 23062 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 23063 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
e74cfd16
PB
23064 {NULL, ARM_ARCH_NONE}
23065};
23066
23067struct arm_option_value_table
23068{
23069 char *name;
23070 long value;
c19d1205 23071};
7ed4c4c5 23072
e74cfd16 23073static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
23074{
23075 {"hard", ARM_FLOAT_ABI_HARD},
23076 {"softfp", ARM_FLOAT_ABI_SOFTFP},
23077 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 23078 {NULL, 0}
c19d1205 23079};
7ed4c4c5 23080
c19d1205 23081#ifdef OBJ_ELF
3a4a14e9 23082/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 23083static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
23084{
23085 {"gnu", EF_ARM_EABI_UNKNOWN},
23086 {"4", EF_ARM_EABI_VER4},
3a4a14e9 23087 {"5", EF_ARM_EABI_VER5},
e74cfd16 23088 {NULL, 0}
c19d1205
ZW
23089};
23090#endif
7ed4c4c5 23091
c19d1205
ZW
23092struct arm_long_option_table
23093{
23094 char * option; /* Substring to match. */
23095 char * help; /* Help information. */
23096 int (* func) (char * subopt); /* Function to decode sub-option. */
23097 char * deprecated; /* If non-null, print this message. */
23098};
7ed4c4c5 23099
c921be7d 23100static bfd_boolean
e74cfd16 23101arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 23102{
21d799b5
NC
23103 arm_feature_set *ext_set = (arm_feature_set *)
23104 xmalloc (sizeof (arm_feature_set));
e74cfd16 23105
69133863
MGD
23106 /* We insist on extensions being specified in alphabetical order, and with
23107 extensions being added before being removed. We achieve this by having
23108 the global ARM_EXTENSIONS table in alphabetical order, and using the
23109 ADDING_VALUE variable to indicate whether we are adding an extension (1)
23110 or removing it (0) and only allowing it to change in the order
23111 -1 -> 1 -> 0. */
23112 const struct arm_option_extension_value_table * opt = NULL;
23113 int adding_value = -1;
23114
e74cfd16
PB
23115 /* Copy the feature set, so that we can modify it. */
23116 *ext_set = **opt_p;
23117 *opt_p = ext_set;
23118
c19d1205 23119 while (str != NULL && *str != 0)
7ed4c4c5 23120 {
c19d1205 23121 char * ext;
69133863 23122 size_t optlen;
7ed4c4c5 23123
c19d1205
ZW
23124 if (*str != '+')
23125 {
23126 as_bad (_("invalid architectural extension"));
c921be7d 23127 return FALSE;
c19d1205 23128 }
7ed4c4c5 23129
c19d1205
ZW
23130 str++;
23131 ext = strchr (str, '+');
7ed4c4c5 23132
c19d1205
ZW
23133 if (ext != NULL)
23134 optlen = ext - str;
23135 else
23136 optlen = strlen (str);
7ed4c4c5 23137
69133863
MGD
23138 if (optlen >= 2
23139 && strncmp (str, "no", 2) == 0)
23140 {
23141 if (adding_value != 0)
23142 {
23143 adding_value = 0;
23144 opt = arm_extensions;
23145 }
23146
23147 optlen -= 2;
23148 str += 2;
23149 }
23150 else if (optlen > 0)
23151 {
23152 if (adding_value == -1)
23153 {
23154 adding_value = 1;
23155 opt = arm_extensions;
23156 }
23157 else if (adding_value != 1)
23158 {
23159 as_bad (_("must specify extensions to add before specifying "
23160 "those to remove"));
23161 return FALSE;
23162 }
23163 }
23164
c19d1205
ZW
23165 if (optlen == 0)
23166 {
23167 as_bad (_("missing architectural extension"));
c921be7d 23168 return FALSE;
c19d1205 23169 }
7ed4c4c5 23170
69133863
MGD
23171 gas_assert (adding_value != -1);
23172 gas_assert (opt != NULL);
23173
23174 /* Scan over the options table trying to find an exact match. */
23175 for (; opt->name != NULL; opt++)
23176 if (strncmp (opt->name, str, optlen) == 0
23177 && strlen (opt->name) == optlen)
c19d1205 23178 {
69133863
MGD
23179 /* Check we can apply the extension to this architecture. */
23180 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
23181 {
23182 as_bad (_("extension does not apply to the base architecture"));
23183 return FALSE;
23184 }
23185
23186 /* Add or remove the extension. */
23187 if (adding_value)
23188 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
23189 else
23190 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
23191
c19d1205
ZW
23192 break;
23193 }
7ed4c4c5 23194
c19d1205
ZW
23195 if (opt->name == NULL)
23196 {
69133863
MGD
23197 /* Did we fail to find an extension because it wasn't specified in
23198 alphabetical order, or because it does not exist? */
23199
23200 for (opt = arm_extensions; opt->name != NULL; opt++)
23201 if (strncmp (opt->name, str, optlen) == 0)
23202 break;
23203
23204 if (opt->name == NULL)
23205 as_bad (_("unknown architectural extension `%s'"), str);
23206 else
23207 as_bad (_("architectural extensions must be specified in "
23208 "alphabetical order"));
23209
c921be7d 23210 return FALSE;
c19d1205 23211 }
69133863
MGD
23212 else
23213 {
23214 /* We should skip the extension we've just matched the next time
23215 round. */
23216 opt++;
23217 }
7ed4c4c5 23218
c19d1205
ZW
23219 str = ext;
23220 };
7ed4c4c5 23221
c921be7d 23222 return TRUE;
c19d1205 23223}
7ed4c4c5 23224
c921be7d 23225static bfd_boolean
c19d1205 23226arm_parse_cpu (char * str)
7ed4c4c5 23227{
e74cfd16 23228 const struct arm_cpu_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 cpu name `%s'"), str);
c921be7d 23240 return FALSE;
7ed4c4c5
NC
23241 }
23242
c19d1205
ZW
23243 for (opt = arm_cpus; opt->name != NULL; opt++)
23244 if (strncmp (opt->name, str, optlen) == 0)
23245 {
e74cfd16
PB
23246 mcpu_cpu_opt = &opt->value;
23247 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 23248 if (opt->canonical_name)
5f4273c7 23249 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
23250 else
23251 {
23252 int i;
c921be7d 23253
ee065d83
PB
23254 for (i = 0; i < optlen; i++)
23255 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23256 selected_cpu_name[i] = 0;
23257 }
7ed4c4c5 23258
c19d1205
ZW
23259 if (ext != NULL)
23260 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 23261
c921be7d 23262 return TRUE;
c19d1205 23263 }
7ed4c4c5 23264
c19d1205 23265 as_bad (_("unknown cpu `%s'"), str);
c921be7d 23266 return FALSE;
7ed4c4c5
NC
23267}
23268
c921be7d 23269static bfd_boolean
c19d1205 23270arm_parse_arch (char * str)
7ed4c4c5 23271{
e74cfd16 23272 const struct arm_arch_option_table *opt;
c19d1205
ZW
23273 char *ext = strchr (str, '+');
23274 int optlen;
7ed4c4c5 23275
c19d1205
ZW
23276 if (ext != NULL)
23277 optlen = ext - str;
7ed4c4c5 23278 else
c19d1205 23279 optlen = strlen (str);
7ed4c4c5 23280
c19d1205 23281 if (optlen == 0)
7ed4c4c5 23282 {
c19d1205 23283 as_bad (_("missing architecture name `%s'"), str);
c921be7d 23284 return FALSE;
7ed4c4c5
NC
23285 }
23286
c19d1205 23287 for (opt = arm_archs; opt->name != NULL; opt++)
69133863 23288 if (strncmp (opt->name, str, optlen) == 0)
c19d1205 23289 {
e74cfd16
PB
23290 march_cpu_opt = &opt->value;
23291 march_fpu_opt = &opt->default_fpu;
5f4273c7 23292 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 23293
c19d1205
ZW
23294 if (ext != NULL)
23295 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 23296
c921be7d 23297 return TRUE;
c19d1205
ZW
23298 }
23299
23300 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 23301 return FALSE;
7ed4c4c5 23302}
eb043451 23303
c921be7d 23304static bfd_boolean
c19d1205
ZW
23305arm_parse_fpu (char * str)
23306{
69133863 23307 const struct arm_option_fpu_value_table * opt;
b99bd4ef 23308
c19d1205
ZW
23309 for (opt = arm_fpus; opt->name != NULL; opt++)
23310 if (streq (opt->name, str))
23311 {
e74cfd16 23312 mfpu_opt = &opt->value;
c921be7d 23313 return TRUE;
c19d1205 23314 }
b99bd4ef 23315
c19d1205 23316 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 23317 return FALSE;
c19d1205
ZW
23318}
23319
c921be7d 23320static bfd_boolean
c19d1205 23321arm_parse_float_abi (char * str)
b99bd4ef 23322{
e74cfd16 23323 const struct arm_option_value_table * opt;
b99bd4ef 23324
c19d1205
ZW
23325 for (opt = arm_float_abis; opt->name != NULL; opt++)
23326 if (streq (opt->name, str))
23327 {
23328 mfloat_abi_opt = opt->value;
c921be7d 23329 return TRUE;
c19d1205 23330 }
cc8a6dd0 23331
c19d1205 23332 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 23333 return FALSE;
c19d1205 23334}
b99bd4ef 23335
c19d1205 23336#ifdef OBJ_ELF
c921be7d 23337static bfd_boolean
c19d1205
ZW
23338arm_parse_eabi (char * str)
23339{
e74cfd16 23340 const struct arm_option_value_table *opt;
cc8a6dd0 23341
c19d1205
ZW
23342 for (opt = arm_eabis; opt->name != NULL; opt++)
23343 if (streq (opt->name, str))
23344 {
23345 meabi_flags = opt->value;
c921be7d 23346 return TRUE;
c19d1205
ZW
23347 }
23348 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 23349 return FALSE;
c19d1205
ZW
23350}
23351#endif
cc8a6dd0 23352
c921be7d 23353static bfd_boolean
e07e6e58
NC
23354arm_parse_it_mode (char * str)
23355{
c921be7d 23356 bfd_boolean ret = TRUE;
e07e6e58
NC
23357
23358 if (streq ("arm", str))
23359 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
23360 else if (streq ("thumb", str))
23361 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
23362 else if (streq ("always", str))
23363 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
23364 else if (streq ("never", str))
23365 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
23366 else
23367 {
23368 as_bad (_("unknown implicit IT mode `%s', should be "\
23369 "arm, thumb, always, or never."), str);
c921be7d 23370 ret = FALSE;
e07e6e58
NC
23371 }
23372
23373 return ret;
23374}
23375
c19d1205
ZW
23376struct arm_long_option_table arm_long_opts[] =
23377{
23378 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
23379 arm_parse_cpu, NULL},
23380 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
23381 arm_parse_arch, NULL},
23382 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
23383 arm_parse_fpu, NULL},
23384 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
23385 arm_parse_float_abi, NULL},
23386#ifdef OBJ_ELF
7fac0536 23387 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
23388 arm_parse_eabi, NULL},
23389#endif
e07e6e58
NC
23390 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
23391 arm_parse_it_mode, NULL},
c19d1205
ZW
23392 {NULL, NULL, 0, NULL}
23393};
cc8a6dd0 23394
c19d1205
ZW
23395int
23396md_parse_option (int c, char * arg)
23397{
23398 struct arm_option_table *opt;
e74cfd16 23399 const struct arm_legacy_option_table *fopt;
c19d1205 23400 struct arm_long_option_table *lopt;
b99bd4ef 23401
c19d1205 23402 switch (c)
b99bd4ef 23403 {
c19d1205
ZW
23404#ifdef OPTION_EB
23405 case OPTION_EB:
23406 target_big_endian = 1;
23407 break;
23408#endif
cc8a6dd0 23409
c19d1205
ZW
23410#ifdef OPTION_EL
23411 case OPTION_EL:
23412 target_big_endian = 0;
23413 break;
23414#endif
b99bd4ef 23415
845b51d6
PB
23416 case OPTION_FIX_V4BX:
23417 fix_v4bx = TRUE;
23418 break;
23419
c19d1205
ZW
23420 case 'a':
23421 /* Listing option. Just ignore these, we don't support additional
23422 ones. */
23423 return 0;
b99bd4ef 23424
c19d1205
ZW
23425 default:
23426 for (opt = arm_opts; opt->option != NULL; opt++)
23427 {
23428 if (c == opt->option[0]
23429 && ((arg == NULL && opt->option[1] == 0)
23430 || streq (arg, opt->option + 1)))
23431 {
c19d1205 23432 /* If the option is deprecated, tell the user. */
278df34e 23433 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
23434 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23435 arg ? arg : "", _(opt->deprecated));
b99bd4ef 23436
c19d1205
ZW
23437 if (opt->var != NULL)
23438 *opt->var = opt->value;
cc8a6dd0 23439
c19d1205
ZW
23440 return 1;
23441 }
23442 }
b99bd4ef 23443
e74cfd16
PB
23444 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
23445 {
23446 if (c == fopt->option[0]
23447 && ((arg == NULL && fopt->option[1] == 0)
23448 || streq (arg, fopt->option + 1)))
23449 {
e74cfd16 23450 /* If the option is deprecated, tell the user. */
278df34e 23451 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
23452 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23453 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
23454
23455 if (fopt->var != NULL)
23456 *fopt->var = &fopt->value;
23457
23458 return 1;
23459 }
23460 }
23461
c19d1205
ZW
23462 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23463 {
23464 /* These options are expected to have an argument. */
23465 if (c == lopt->option[0]
23466 && arg != NULL
23467 && strncmp (arg, lopt->option + 1,
23468 strlen (lopt->option + 1)) == 0)
23469 {
c19d1205 23470 /* If the option is deprecated, tell the user. */
278df34e 23471 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
23472 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
23473 _(lopt->deprecated));
b99bd4ef 23474
c19d1205
ZW
23475 /* Call the sup-option parser. */
23476 return lopt->func (arg + strlen (lopt->option) - 1);
23477 }
23478 }
a737bd4d 23479
c19d1205
ZW
23480 return 0;
23481 }
a394c00f 23482
c19d1205
ZW
23483 return 1;
23484}
a394c00f 23485
c19d1205
ZW
23486void
23487md_show_usage (FILE * fp)
a394c00f 23488{
c19d1205
ZW
23489 struct arm_option_table *opt;
23490 struct arm_long_option_table *lopt;
a394c00f 23491
c19d1205 23492 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 23493
c19d1205
ZW
23494 for (opt = arm_opts; opt->option != NULL; opt++)
23495 if (opt->help != NULL)
23496 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 23497
c19d1205
ZW
23498 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23499 if (lopt->help != NULL)
23500 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 23501
c19d1205
ZW
23502#ifdef OPTION_EB
23503 fprintf (fp, _("\
23504 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
23505#endif
23506
c19d1205
ZW
23507#ifdef OPTION_EL
23508 fprintf (fp, _("\
23509 -EL assemble code for a little-endian cpu\n"));
a737bd4d 23510#endif
845b51d6
PB
23511
23512 fprintf (fp, _("\
23513 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 23514}
ee065d83
PB
23515
23516
23517#ifdef OBJ_ELF
62b3e311
PB
23518typedef struct
23519{
23520 int val;
23521 arm_feature_set flags;
23522} cpu_arch_ver_table;
23523
23524/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
23525 least features first. */
23526static const cpu_arch_ver_table cpu_arch_ver[] =
23527{
23528 {1, ARM_ARCH_V4},
23529 {2, ARM_ARCH_V4T},
23530 {3, ARM_ARCH_V5},
ee3c0378 23531 {3, ARM_ARCH_V5T},
62b3e311
PB
23532 {4, ARM_ARCH_V5TE},
23533 {5, ARM_ARCH_V5TEJ},
23534 {6, ARM_ARCH_V6},
7e806470 23535 {9, ARM_ARCH_V6K},
f4c65163 23536 {7, ARM_ARCH_V6Z},
91e22acd 23537 {11, ARM_ARCH_V6M},
b2a5fbdc 23538 {12, ARM_ARCH_V6SM},
7e806470 23539 {8, ARM_ARCH_V6T2},
62b3e311
PB
23540 {10, ARM_ARCH_V7A},
23541 {10, ARM_ARCH_V7R},
23542 {10, ARM_ARCH_V7M},
23543 {0, ARM_ARCH_NONE}
23544};
23545
ee3c0378
AS
23546/* Set an attribute if it has not already been set by the user. */
23547static void
23548aeabi_set_attribute_int (int tag, int value)
23549{
23550 if (tag < 1
23551 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23552 || !attributes_set_explicitly[tag])
23553 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
23554}
23555
23556static void
23557aeabi_set_attribute_string (int tag, const char *value)
23558{
23559 if (tag < 1
23560 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23561 || !attributes_set_explicitly[tag])
23562 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
23563}
23564
ee065d83
PB
23565/* Set the public EABI object attributes. */
23566static void
23567aeabi_set_public_attributes (void)
23568{
23569 int arch;
90ec0d68 23570 int virt_sec = 0;
e74cfd16 23571 arm_feature_set flags;
62b3e311
PB
23572 arm_feature_set tmp;
23573 const cpu_arch_ver_table *p;
ee065d83
PB
23574
23575 /* Choose the architecture based on the capabilities of the requested cpu
23576 (if any) and/or the instructions actually used. */
e74cfd16
PB
23577 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
23578 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
23579 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
23580 /*Allow the user to override the reported architecture. */
23581 if (object_arch)
23582 {
23583 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
23584 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
23585 }
23586
251665fc
MGD
23587 /* We need to make sure that the attributes do not identify us as v6S-M
23588 when the only v6S-M feature in use is the Operating System Extensions. */
23589 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
23590 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
23591 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
23592
62b3e311
PB
23593 tmp = flags;
23594 arch = 0;
23595 for (p = cpu_arch_ver; p->val; p++)
23596 {
23597 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
23598 {
23599 arch = p->val;
23600 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
23601 }
23602 }
ee065d83 23603
9e3c6df6
PB
23604 /* The table lookup above finds the last architecture to contribute
23605 a new feature. Unfortunately, Tag13 is a subset of the union of
23606 v6T2 and v7-M, so it is never seen as contributing a new feature.
23607 We can not search for the last entry which is entirely used,
23608 because if no CPU is specified we build up only those flags
23609 actually used. Perhaps we should separate out the specified
23610 and implicit cases. Avoid taking this path for -march=all by
23611 checking for contradictory v7-A / v7-M features. */
23612 if (arch == 10
23613 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
23614 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
23615 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
23616 arch = 13;
23617
ee065d83
PB
23618 /* Tag_CPU_name. */
23619 if (selected_cpu_name[0])
23620 {
91d6fa6a 23621 char *q;
ee065d83 23622
91d6fa6a
NC
23623 q = selected_cpu_name;
23624 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
23625 {
23626 int i;
5f4273c7 23627
91d6fa6a
NC
23628 q += 4;
23629 for (i = 0; q[i]; i++)
23630 q[i] = TOUPPER (q[i]);
ee065d83 23631 }
91d6fa6a 23632 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 23633 }
62f3b8c8 23634
ee065d83 23635 /* Tag_CPU_arch. */
ee3c0378 23636 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 23637
62b3e311
PB
23638 /* Tag_CPU_arch_profile. */
23639 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 23640 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 23641 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 23642 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 23643 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 23644 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
62f3b8c8 23645
ee065d83 23646 /* Tag_ARM_ISA_use. */
ee3c0378
AS
23647 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
23648 || arch == 0)
23649 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 23650
ee065d83 23651 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
23652 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
23653 || arch == 0)
23654 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
23655 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 23656
ee065d83 23657 /* Tag_VFP_arch. */
62f3b8c8
PB
23658 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
23659 aeabi_set_attribute_int (Tag_VFP_arch,
23660 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
23661 ? 5 : 6);
23662 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
ee3c0378 23663 aeabi_set_attribute_int (Tag_VFP_arch, 3);
ada65aa3 23664 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
ee3c0378
AS
23665 aeabi_set_attribute_int (Tag_VFP_arch, 4);
23666 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
23667 aeabi_set_attribute_int (Tag_VFP_arch, 2);
23668 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
23669 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
23670 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 23671
4547cb56
NC
23672 /* Tag_ABI_HardFP_use. */
23673 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
23674 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
23675 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
23676
ee065d83 23677 /* Tag_WMMX_arch. */
ee3c0378
AS
23678 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
23679 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
23680 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
23681 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 23682
ee3c0378 23683 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 23684 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
62f3b8c8
PB
23685 aeabi_set_attribute_int
23686 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
23687 ? 2 : 1));
23688
ee3c0378 23689 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
62f3b8c8 23690 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
ee3c0378 23691 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56
NC
23692
23693 /* Tag_DIV_use. */
eea54501
MGD
23694 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv))
23695 aeabi_set_attribute_int (Tag_DIV_use, 2);
23696 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_div))
4547cb56 23697 aeabi_set_attribute_int (Tag_DIV_use, 0);
4547cb56
NC
23698 else
23699 aeabi_set_attribute_int (Tag_DIV_use, 1);
60e5ef9f
MGD
23700
23701 /* Tag_MP_extension_use. */
23702 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
23703 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
23704
23705 /* Tag Virtualization_use. */
23706 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
23707 virt_sec |= 1;
23708 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
23709 virt_sec |= 2;
23710 if (virt_sec != 0)
23711 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
23712}
23713
104d59d1 23714/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
23715void
23716arm_md_end (void)
23717{
ee065d83
PB
23718 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
23719 return;
23720
23721 aeabi_set_public_attributes ();
ee065d83 23722}
8463be01 23723#endif /* OBJ_ELF */
ee065d83
PB
23724
23725
23726/* Parse a .cpu directive. */
23727
23728static void
23729s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
23730{
e74cfd16 23731 const struct arm_cpu_option_table *opt;
ee065d83
PB
23732 char *name;
23733 char saved_char;
23734
23735 name = input_line_pointer;
5f4273c7 23736 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23737 input_line_pointer++;
23738 saved_char = *input_line_pointer;
23739 *input_line_pointer = 0;
23740
23741 /* Skip the first "all" entry. */
23742 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
23743 if (streq (opt->name, name))
23744 {
e74cfd16
PB
23745 mcpu_cpu_opt = &opt->value;
23746 selected_cpu = opt->value;
ee065d83 23747 if (opt->canonical_name)
5f4273c7 23748 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
23749 else
23750 {
23751 int i;
23752 for (i = 0; opt->name[i]; i++)
23753 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23754 selected_cpu_name[i] = 0;
23755 }
e74cfd16 23756 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23757 *input_line_pointer = saved_char;
23758 demand_empty_rest_of_line ();
23759 return;
23760 }
23761 as_bad (_("unknown cpu `%s'"), name);
23762 *input_line_pointer = saved_char;
23763 ignore_rest_of_line ();
23764}
23765
23766
23767/* Parse a .arch directive. */
23768
23769static void
23770s_arm_arch (int ignored ATTRIBUTE_UNUSED)
23771{
e74cfd16 23772 const struct arm_arch_option_table *opt;
ee065d83
PB
23773 char saved_char;
23774 char *name;
23775
23776 name = input_line_pointer;
5f4273c7 23777 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23778 input_line_pointer++;
23779 saved_char = *input_line_pointer;
23780 *input_line_pointer = 0;
23781
23782 /* Skip the first "all" entry. */
23783 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23784 if (streq (opt->name, name))
23785 {
e74cfd16
PB
23786 mcpu_cpu_opt = &opt->value;
23787 selected_cpu = opt->value;
5f4273c7 23788 strcpy (selected_cpu_name, opt->name);
e74cfd16 23789 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23790 *input_line_pointer = saved_char;
23791 demand_empty_rest_of_line ();
23792 return;
23793 }
23794
23795 as_bad (_("unknown architecture `%s'\n"), name);
23796 *input_line_pointer = saved_char;
23797 ignore_rest_of_line ();
23798}
23799
23800
7a1d4c38
PB
23801/* Parse a .object_arch directive. */
23802
23803static void
23804s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
23805{
23806 const struct arm_arch_option_table *opt;
23807 char saved_char;
23808 char *name;
23809
23810 name = input_line_pointer;
5f4273c7 23811 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
23812 input_line_pointer++;
23813 saved_char = *input_line_pointer;
23814 *input_line_pointer = 0;
23815
23816 /* Skip the first "all" entry. */
23817 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23818 if (streq (opt->name, name))
23819 {
23820 object_arch = &opt->value;
23821 *input_line_pointer = saved_char;
23822 demand_empty_rest_of_line ();
23823 return;
23824 }
23825
23826 as_bad (_("unknown architecture `%s'\n"), name);
23827 *input_line_pointer = saved_char;
23828 ignore_rest_of_line ();
23829}
23830
69133863
MGD
23831/* Parse a .arch_extension directive. */
23832
23833static void
23834s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
23835{
23836 const struct arm_option_extension_value_table *opt;
23837 char saved_char;
23838 char *name;
23839 int adding_value = 1;
23840
23841 name = input_line_pointer;
23842 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23843 input_line_pointer++;
23844 saved_char = *input_line_pointer;
23845 *input_line_pointer = 0;
23846
23847 if (strlen (name) >= 2
23848 && strncmp (name, "no", 2) == 0)
23849 {
23850 adding_value = 0;
23851 name += 2;
23852 }
23853
23854 for (opt = arm_extensions; opt->name != NULL; opt++)
23855 if (streq (opt->name, name))
23856 {
23857 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
23858 {
23859 as_bad (_("architectural extension `%s' is not allowed for the "
23860 "current base architecture"), name);
23861 break;
23862 }
23863
23864 if (adding_value)
23865 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
23866 else
23867 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
23868
23869 mcpu_cpu_opt = &selected_cpu;
23870 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23871 *input_line_pointer = saved_char;
23872 demand_empty_rest_of_line ();
23873 return;
23874 }
23875
23876 if (opt->name == NULL)
23877 as_bad (_("unknown architecture `%s'\n"), name);
23878
23879 *input_line_pointer = saved_char;
23880 ignore_rest_of_line ();
23881}
23882
ee065d83
PB
23883/* Parse a .fpu directive. */
23884
23885static void
23886s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
23887{
69133863 23888 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
23889 char saved_char;
23890 char *name;
23891
23892 name = input_line_pointer;
5f4273c7 23893 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23894 input_line_pointer++;
23895 saved_char = *input_line_pointer;
23896 *input_line_pointer = 0;
5f4273c7 23897
ee065d83
PB
23898 for (opt = arm_fpus; opt->name != NULL; opt++)
23899 if (streq (opt->name, name))
23900 {
e74cfd16
PB
23901 mfpu_opt = &opt->value;
23902 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23903 *input_line_pointer = saved_char;
23904 demand_empty_rest_of_line ();
23905 return;
23906 }
23907
23908 as_bad (_("unknown floating point format `%s'\n"), name);
23909 *input_line_pointer = saved_char;
23910 ignore_rest_of_line ();
23911}
ee065d83 23912
794ba86a 23913/* Copy symbol information. */
f31fef98 23914
794ba86a
DJ
23915void
23916arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
23917{
23918 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
23919}
e04befd0 23920
f31fef98 23921#ifdef OBJ_ELF
e04befd0
AS
23922/* Given a symbolic attribute NAME, return the proper integer value.
23923 Returns -1 if the attribute is not known. */
f31fef98 23924
e04befd0
AS
23925int
23926arm_convert_symbolic_attribute (const char *name)
23927{
f31fef98
NC
23928 static const struct
23929 {
23930 const char * name;
23931 const int tag;
23932 }
23933 attribute_table[] =
23934 {
23935 /* When you modify this table you should
23936 also modify the list in doc/c-arm.texi. */
e04befd0 23937#define T(tag) {#tag, tag}
f31fef98
NC
23938 T (Tag_CPU_raw_name),
23939 T (Tag_CPU_name),
23940 T (Tag_CPU_arch),
23941 T (Tag_CPU_arch_profile),
23942 T (Tag_ARM_ISA_use),
23943 T (Tag_THUMB_ISA_use),
75375b3e 23944 T (Tag_FP_arch),
f31fef98
NC
23945 T (Tag_VFP_arch),
23946 T (Tag_WMMX_arch),
23947 T (Tag_Advanced_SIMD_arch),
23948 T (Tag_PCS_config),
23949 T (Tag_ABI_PCS_R9_use),
23950 T (Tag_ABI_PCS_RW_data),
23951 T (Tag_ABI_PCS_RO_data),
23952 T (Tag_ABI_PCS_GOT_use),
23953 T (Tag_ABI_PCS_wchar_t),
23954 T (Tag_ABI_FP_rounding),
23955 T (Tag_ABI_FP_denormal),
23956 T (Tag_ABI_FP_exceptions),
23957 T (Tag_ABI_FP_user_exceptions),
23958 T (Tag_ABI_FP_number_model),
75375b3e 23959 T (Tag_ABI_align_needed),
f31fef98 23960 T (Tag_ABI_align8_needed),
75375b3e 23961 T (Tag_ABI_align_preserved),
f31fef98
NC
23962 T (Tag_ABI_align8_preserved),
23963 T (Tag_ABI_enum_size),
23964 T (Tag_ABI_HardFP_use),
23965 T (Tag_ABI_VFP_args),
23966 T (Tag_ABI_WMMX_args),
23967 T (Tag_ABI_optimization_goals),
23968 T (Tag_ABI_FP_optimization_goals),
23969 T (Tag_compatibility),
23970 T (Tag_CPU_unaligned_access),
75375b3e 23971 T (Tag_FP_HP_extension),
f31fef98
NC
23972 T (Tag_VFP_HP_extension),
23973 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
23974 T (Tag_MPextension_use),
23975 T (Tag_DIV_use),
f31fef98
NC
23976 T (Tag_nodefaults),
23977 T (Tag_also_compatible_with),
23978 T (Tag_conformance),
23979 T (Tag_T2EE_use),
23980 T (Tag_Virtualization_use),
cd21e546 23981 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 23982#undef T
f31fef98 23983 };
e04befd0
AS
23984 unsigned int i;
23985
23986 if (name == NULL)
23987 return -1;
23988
f31fef98 23989 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 23990 if (streq (name, attribute_table[i].name))
e04befd0
AS
23991 return attribute_table[i].tag;
23992
23993 return -1;
23994}
267bf995
RR
23995
23996
23997/* Apply sym value for relocations only in the case that
23998 they are for local symbols and you have the respective
23999 architectural feature for blx and simple switches. */
24000int
24001arm_apply_sym_value (struct fix * fixP)
24002{
24003 if (fixP->fx_addsy
24004 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
34e77a92 24005 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
24006 {
24007 switch (fixP->fx_r_type)
24008 {
24009 case BFD_RELOC_ARM_PCREL_BLX:
24010 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24011 if (ARM_IS_FUNC (fixP->fx_addsy))
24012 return 1;
24013 break;
24014
24015 case BFD_RELOC_ARM_PCREL_CALL:
24016 case BFD_RELOC_THUMB_PCREL_BLX:
24017 if (THUMB_IS_FUNC (fixP->fx_addsy))
24018 return 1;
24019 break;
24020
24021 default:
24022 break;
24023 }
24024
24025 }
24026 return 0;
24027}
f31fef98 24028#endif /* OBJ_ELF */