2011-05-31 Paul Brook <paul@codesourcery.com>
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4a58c4bd 3 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
b99bd4ef
NC
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
ec2655a6 15 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
b99bd4ef 27
42a68e18 28#include "as.h"
5287ad62 29#include <limits.h>
037e8744 30#include <stdarg.h>
c19d1205 31#define NO_RELOC 0
3882b010 32#include "safe-ctype.h"
b99bd4ef
NC
33#include "subsegs.h"
34#include "obstack.h"
b99bd4ef 35
f263249b
RE
36#include "opcode/arm.h"
37
b99bd4ef
NC
38#ifdef OBJ_ELF
39#include "elf/arm.h"
a394c00f 40#include "dw2gencfi.h"
b99bd4ef
NC
41#endif
42
f0927246
NC
43#include "dwarf2dbg.h"
44
7ed4c4c5
NC
45#ifdef OBJ_ELF
46/* Must be at least the size of the largest unwind opcode (currently two). */
47#define ARM_OPCODE_CHUNK_SIZE 8
48
49/* This structure holds the unwinding state. */
50
51static struct
52{
c19d1205
ZW
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
7ed4c4c5 57 /* The segment containing the function. */
c19d1205
ZW
58 segT saved_seg;
59 subsegT saved_subseg;
7ed4c4c5
NC
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
c19d1205
ZW
62 int opcode_count;
63 int opcode_alloc;
7ed4c4c5 64 /* The number of bytes pushed to the stack. */
c19d1205 65 offsetT frame_size;
7ed4c4c5
NC
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
c19d1205 69 offsetT pending_offset;
7ed4c4c5 70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
7ed4c4c5 74 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 75 unsigned fp_used:1;
7ed4c4c5 76 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 77 unsigned sp_restored:1;
7ed4c4c5
NC
78} unwind;
79
8b1ad454
NC
80#endif /* OBJ_ELF */
81
4962c51a
MS
82/* Results from operand parsing worker functions. */
83
84typedef enum
85{
86 PARSE_OPERAND_SUCCESS,
87 PARSE_OPERAND_FAIL,
88 PARSE_OPERAND_FAIL_NO_BACKTRACK
89} parse_operand_result;
90
33a392fb
PB
91enum arm_float_abi
92{
93 ARM_FLOAT_ABI_HARD,
94 ARM_FLOAT_ABI_SOFTFP,
95 ARM_FLOAT_ABI_SOFT
96};
97
c19d1205 98/* Types of processor to assemble for. */
b99bd4ef 99#ifndef CPU_DEFAULT
8a59fff3
MGD
100/* The code that was here used to select a default CPU depending on compiler
101 pre-defines which were only present when doing native builds, thus
102 changing gas' default behaviour depending upon the build host.
103
104 If you have a target that requires a default CPU option then the you
105 should define CPU_DEFAULT here. */
b99bd4ef
NC
106#endif
107
108#ifndef FPU_DEFAULT
c820d418
MM
109# ifdef TE_LINUX
110# define FPU_DEFAULT FPU_ARCH_FPA
111# elif defined (TE_NetBSD)
112# ifdef OBJ_ELF
113# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
114# else
115 /* Legacy a.out format. */
116# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
117# endif
4e7fd91e
PB
118# elif defined (TE_VXWORKS)
119# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
120# else
121 /* For backwards compatibility, default to FPA. */
122# define FPU_DEFAULT FPU_ARCH_FPA
123# endif
124#endif /* ifndef FPU_DEFAULT */
b99bd4ef 125
c19d1205 126#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 127
e74cfd16
PB
128static arm_feature_set cpu_variant;
129static arm_feature_set arm_arch_used;
130static arm_feature_set thumb_arch_used;
b99bd4ef 131
b99bd4ef 132/* Flags stored in private area of BFD structure. */
c19d1205
ZW
133static int uses_apcs_26 = FALSE;
134static int atpcs = FALSE;
b34976b6
AM
135static int support_interwork = FALSE;
136static int uses_apcs_float = FALSE;
c19d1205 137static int pic_code = FALSE;
845b51d6 138static int fix_v4bx = FALSE;
278df34e
NS
139/* Warn on using deprecated features. */
140static int warn_on_deprecated = TRUE;
141
03b1477f
RE
142
143/* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
e74cfd16
PB
146static const arm_feature_set *legacy_cpu = NULL;
147static const arm_feature_set *legacy_fpu = NULL;
148
149static const arm_feature_set *mcpu_cpu_opt = NULL;
150static const arm_feature_set *mcpu_fpu_opt = NULL;
151static const arm_feature_set *march_cpu_opt = NULL;
152static const arm_feature_set *march_fpu_opt = NULL;
153static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 154static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
155
156/* Constants for known architecture features. */
157static const arm_feature_set fpu_default = FPU_DEFAULT;
158static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
159static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
160static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
161static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
162static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
164static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
165static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
166
167#ifdef CPU_DEFAULT
168static const arm_feature_set cpu_default = CPU_DEFAULT;
169#endif
170
171static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
172static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
173static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
174static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
175static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
176static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
177static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
178static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
179static const arm_feature_set arm_ext_v4t_5 =
180 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
181static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
182static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
183static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
184static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
185static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
186static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
e74cfd16 187static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
b2a5fbdc 188static const arm_feature_set arm_ext_v6m = ARM_FEATURE (ARM_EXT_V6M, 0);
62b3e311 189static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
9e3c6df6 190static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
7e806470
PB
191static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
192static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
193static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
194static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
195static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
196static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
9e3c6df6 197static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
7e806470 198static const arm_feature_set arm_ext_m =
b2a5fbdc 199 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, 0);
60e5ef9f 200static const arm_feature_set arm_ext_mp = ARM_FEATURE (ARM_EXT_MP, 0);
f4c65163 201static const arm_feature_set arm_ext_sec = ARM_FEATURE (ARM_EXT_SEC, 0);
b2a5fbdc 202static const arm_feature_set arm_ext_os = ARM_FEATURE (ARM_EXT_OS, 0);
eea54501 203static const arm_feature_set arm_ext_adiv = ARM_FEATURE (ARM_EXT_ADIV, 0);
90ec0d68 204static const arm_feature_set arm_ext_virt = ARM_FEATURE (ARM_EXT_VIRT, 0);
e74cfd16
PB
205
206static const arm_feature_set arm_arch_any = ARM_ANY;
207static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
208static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
209static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
251665fc 210static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
e74cfd16 211
2d447fca
JM
212static const arm_feature_set arm_cext_iwmmxt2 =
213 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
214static const arm_feature_set arm_cext_iwmmxt =
215 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
216static const arm_feature_set arm_cext_xscale =
217 ARM_FEATURE (0, ARM_CEXT_XSCALE);
218static const arm_feature_set arm_cext_maverick =
219 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
220static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
221static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
222static const arm_feature_set fpu_vfp_ext_v1xd =
223 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
224static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
225static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
62f3b8c8 226static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
5287ad62 227static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
228static const arm_feature_set fpu_vfp_ext_d32 =
229 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
230static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
231static const arm_feature_set fpu_vfp_v3_or_neon_ext =
232 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
62f3b8c8
PB
233static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
234static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
235static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
e74cfd16 236
33a392fb 237static int mfloat_abi_opt = -1;
e74cfd16
PB
238/* Record user cpu selection for object attributes. */
239static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
240/* Must be long enough to hold any of the names in arm_cpus. */
241static char selected_cpu_name[16];
8d67f500
NC
242
243/* Return if no cpu was selected on command-line. */
244static bfd_boolean
245no_cpu_selected (void)
246{
247 return selected_cpu.core == arm_arch_none.core
248 && selected_cpu.coproc == arm_arch_none.coproc;
249}
250
7cc69913 251#ifdef OBJ_ELF
deeaaff8
DJ
252# ifdef EABI_DEFAULT
253static int meabi_flags = EABI_DEFAULT;
254# else
d507cf36 255static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 256# endif
e1da3f5b 257
ee3c0378
AS
258static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
259
e1da3f5b 260bfd_boolean
5f4273c7 261arm_is_eabi (void)
e1da3f5b
PB
262{
263 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
264}
7cc69913 265#endif
b99bd4ef 266
b99bd4ef 267#ifdef OBJ_ELF
c19d1205 268/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
269symbolS * GOT_symbol;
270#endif
271
b99bd4ef
NC
272/* 0: assemble for ARM,
273 1: assemble for Thumb,
274 2: assemble for Thumb even though target CPU does not support thumb
275 instructions. */
276static int thumb_mode = 0;
8dc2430f
NC
277/* A value distinct from the possible values for thumb_mode that we
278 can use to record whether thumb_mode has been copied into the
279 tc_frag_data field of a frag. */
280#define MODE_RECORDED (1 << 4)
b99bd4ef 281
e07e6e58
NC
282/* Specifies the intrinsic IT insn behavior mode. */
283enum implicit_it_mode
284{
285 IMPLICIT_IT_MODE_NEVER = 0x00,
286 IMPLICIT_IT_MODE_ARM = 0x01,
287 IMPLICIT_IT_MODE_THUMB = 0x02,
288 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
289};
290static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
291
c19d1205
ZW
292/* If unified_syntax is true, we are processing the new unified
293 ARM/Thumb syntax. Important differences from the old ARM mode:
294
295 - Immediate operands do not require a # prefix.
296 - Conditional affixes always appear at the end of the
297 instruction. (For backward compatibility, those instructions
298 that formerly had them in the middle, continue to accept them
299 there.)
300 - The IT instruction may appear, and if it does is validated
301 against subsequent conditional affixes. It does not generate
302 machine code.
303
304 Important differences from the old Thumb mode:
305
306 - Immediate operands do not require a # prefix.
307 - Most of the V6T2 instructions are only available in unified mode.
308 - The .N and .W suffixes are recognized and honored (it is an error
309 if they cannot be honored).
310 - All instructions set the flags if and only if they have an 's' affix.
311 - Conditional affixes may be used. They are validated against
312 preceding IT instructions. Unlike ARM mode, you cannot use a
313 conditional affix except in the scope of an IT instruction. */
314
315static bfd_boolean unified_syntax = FALSE;
b99bd4ef 316
5287ad62
JB
317enum neon_el_type
318{
dcbf9037 319 NT_invtype,
5287ad62
JB
320 NT_untyped,
321 NT_integer,
322 NT_float,
323 NT_poly,
324 NT_signed,
dcbf9037 325 NT_unsigned
5287ad62
JB
326};
327
328struct neon_type_el
329{
330 enum neon_el_type type;
331 unsigned size;
332};
333
334#define NEON_MAX_TYPE_ELS 4
335
336struct neon_type
337{
338 struct neon_type_el el[NEON_MAX_TYPE_ELS];
339 unsigned elems;
340};
341
e07e6e58
NC
342enum it_instruction_type
343{
344 OUTSIDE_IT_INSN,
345 INSIDE_IT_INSN,
346 INSIDE_IT_LAST_INSN,
347 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
348 if inside, should be the last one. */
349 NEUTRAL_IT_INSN, /* This could be either inside or outside,
350 i.e. BKPT and NOP. */
351 IT_INSN /* The IT insn has been parsed. */
352};
353
b99bd4ef
NC
354struct arm_it
355{
c19d1205 356 const char * error;
b99bd4ef 357 unsigned long instruction;
c19d1205
ZW
358 int size;
359 int size_req;
360 int cond;
037e8744
JB
361 /* "uncond_value" is set to the value in place of the conditional field in
362 unconditional versions of the instruction, or -1 if nothing is
363 appropriate. */
364 int uncond_value;
5287ad62 365 struct neon_type vectype;
88714cb8
DG
366 /* This does not indicate an actual NEON instruction, only that
367 the mnemonic accepts neon-style type suffixes. */
368 int is_neon;
0110f2b8
PB
369 /* Set to the opcode if the instruction needs relaxation.
370 Zero if the instruction is not relaxed. */
371 unsigned long relax;
b99bd4ef
NC
372 struct
373 {
374 bfd_reloc_code_real_type type;
c19d1205
ZW
375 expressionS exp;
376 int pc_rel;
b99bd4ef 377 } reloc;
b99bd4ef 378
e07e6e58
NC
379 enum it_instruction_type it_insn_type;
380
c19d1205
ZW
381 struct
382 {
383 unsigned reg;
ca3f61f7 384 signed int imm;
dcbf9037 385 struct neon_type_el vectype;
ca3f61f7
NC
386 unsigned present : 1; /* Operand present. */
387 unsigned isreg : 1; /* Operand was a register. */
388 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
389 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
390 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 391 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
392 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
393 instructions. This allows us to disambiguate ARM <-> vector insns. */
394 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 395 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 396 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 397 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
398 unsigned hasreloc : 1; /* Operand has relocation suffix. */
399 unsigned writeback : 1; /* Operand has trailing ! */
400 unsigned preind : 1; /* Preindexed address. */
401 unsigned postind : 1; /* Postindexed address. */
402 unsigned negative : 1; /* Index register was negated. */
403 unsigned shifted : 1; /* Shift applied to operation. */
404 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 405 } operands[6];
b99bd4ef
NC
406};
407
c19d1205 408static struct arm_it inst;
b99bd4ef
NC
409
410#define NUM_FLOAT_VALS 8
411
05d2d07e 412const char * fp_const[] =
b99bd4ef
NC
413{
414 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
415};
416
c19d1205 417/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
418#define MAX_LITTLENUMS 6
419
420LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
421
422#define FAIL (-1)
423#define SUCCESS (0)
424
425#define SUFF_S 1
426#define SUFF_D 2
427#define SUFF_E 3
428#define SUFF_P 4
429
c19d1205
ZW
430#define CP_T_X 0x00008000
431#define CP_T_Y 0x00400000
b99bd4ef 432
c19d1205
ZW
433#define CONDS_BIT 0x00100000
434#define LOAD_BIT 0x00100000
b99bd4ef
NC
435
436#define DOUBLE_LOAD_FLAG 0x00000001
437
438struct asm_cond
439{
d3ce72d0 440 const char * template_name;
c921be7d 441 unsigned long value;
b99bd4ef
NC
442};
443
c19d1205 444#define COND_ALWAYS 0xE
b99bd4ef 445
b99bd4ef
NC
446struct asm_psr
447{
d3ce72d0 448 const char * template_name;
c921be7d 449 unsigned long field;
b99bd4ef
NC
450};
451
62b3e311
PB
452struct asm_barrier_opt
453{
d3ce72d0 454 const char * template_name;
c921be7d 455 unsigned long value;
62b3e311
PB
456};
457
2d2255b5 458/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
459#define SPSR_BIT (1 << 22)
460
c19d1205
ZW
461/* The individual PSR flag bits. */
462#define PSR_c (1 << 16)
463#define PSR_x (1 << 17)
464#define PSR_s (1 << 18)
465#define PSR_f (1 << 19)
b99bd4ef 466
c19d1205 467struct reloc_entry
bfae80f2 468{
c921be7d
NC
469 char * name;
470 bfd_reloc_code_real_type reloc;
bfae80f2
RE
471};
472
5287ad62 473enum vfp_reg_pos
bfae80f2 474{
5287ad62
JB
475 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
476 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
477};
478
479enum vfp_ldstm_type
480{
481 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
482};
483
dcbf9037
JB
484/* Bits for DEFINED field in neon_typed_alias. */
485#define NTA_HASTYPE 1
486#define NTA_HASINDEX 2
487
488struct neon_typed_alias
489{
c921be7d
NC
490 unsigned char defined;
491 unsigned char index;
492 struct neon_type_el eltype;
dcbf9037
JB
493};
494
c19d1205
ZW
495/* ARM register categories. This includes coprocessor numbers and various
496 architecture extensions' registers. */
497enum arm_reg_type
bfae80f2 498{
c19d1205
ZW
499 REG_TYPE_RN,
500 REG_TYPE_CP,
501 REG_TYPE_CN,
502 REG_TYPE_FN,
503 REG_TYPE_VFS,
504 REG_TYPE_VFD,
5287ad62 505 REG_TYPE_NQ,
037e8744 506 REG_TYPE_VFSD,
5287ad62 507 REG_TYPE_NDQ,
037e8744 508 REG_TYPE_NSDQ,
c19d1205
ZW
509 REG_TYPE_VFC,
510 REG_TYPE_MVF,
511 REG_TYPE_MVD,
512 REG_TYPE_MVFX,
513 REG_TYPE_MVDX,
514 REG_TYPE_MVAX,
515 REG_TYPE_DSPSC,
516 REG_TYPE_MMXWR,
517 REG_TYPE_MMXWC,
518 REG_TYPE_MMXWCG,
519 REG_TYPE_XSCALE,
90ec0d68 520 REG_TYPE_RNB
bfae80f2
RE
521};
522
dcbf9037
JB
523/* Structure for a hash table entry for a register.
524 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
525 information which states whether a vector type or index is specified (for a
526 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
527struct reg_entry
528{
c921be7d 529 const char * name;
90ec0d68 530 unsigned int number;
c921be7d
NC
531 unsigned char type;
532 unsigned char builtin;
533 struct neon_typed_alias * neon;
6c43fab6
RE
534};
535
c19d1205 536/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 537const char * const reg_expected_msgs[] =
c19d1205
ZW
538{
539 N_("ARM register expected"),
540 N_("bad or missing co-processor number"),
541 N_("co-processor register expected"),
542 N_("FPA register expected"),
543 N_("VFP single precision register expected"),
5287ad62
JB
544 N_("VFP/Neon double precision register expected"),
545 N_("Neon quad precision register expected"),
037e8744 546 N_("VFP single or double precision register expected"),
5287ad62 547 N_("Neon double or quad precision register expected"),
037e8744 548 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
549 N_("VFP system register expected"),
550 N_("Maverick MVF register expected"),
551 N_("Maverick MVD register expected"),
552 N_("Maverick MVFX register expected"),
553 N_("Maverick MVDX register expected"),
554 N_("Maverick MVAX register expected"),
555 N_("Maverick DSPSC register expected"),
556 N_("iWMMXt data register expected"),
557 N_("iWMMXt control register expected"),
558 N_("iWMMXt scalar register expected"),
559 N_("XScale accumulator register expected"),
6c43fab6
RE
560};
561
c19d1205
ZW
562/* Some well known registers that we refer to directly elsewhere. */
563#define REG_SP 13
564#define REG_LR 14
565#define REG_PC 15
404ff6b5 566
b99bd4ef
NC
567/* ARM instructions take 4bytes in the object file, Thumb instructions
568 take 2: */
c19d1205 569#define INSN_SIZE 4
b99bd4ef
NC
570
571struct asm_opcode
572{
573 /* Basic string to match. */
d3ce72d0 574 const char * template_name;
c19d1205
ZW
575
576 /* Parameters to instruction. */
5be8be5d 577 unsigned int operands[8];
c19d1205
ZW
578
579 /* Conditional tag - see opcode_lookup. */
580 unsigned int tag : 4;
b99bd4ef
NC
581
582 /* Basic instruction code. */
c19d1205 583 unsigned int avalue : 28;
b99bd4ef 584
c19d1205
ZW
585 /* Thumb-format instruction code. */
586 unsigned int tvalue;
b99bd4ef 587
90e4755a 588 /* Which architecture variant provides this instruction. */
c921be7d
NC
589 const arm_feature_set * avariant;
590 const arm_feature_set * tvariant;
c19d1205
ZW
591
592 /* Function to call to encode instruction in ARM format. */
593 void (* aencode) (void);
b99bd4ef 594
c19d1205
ZW
595 /* Function to call to encode instruction in Thumb format. */
596 void (* tencode) (void);
b99bd4ef
NC
597};
598
a737bd4d
NC
599/* Defines for various bits that we will want to toggle. */
600#define INST_IMMEDIATE 0x02000000
601#define OFFSET_REG 0x02000000
c19d1205 602#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
603#define SHIFT_BY_REG 0x00000010
604#define PRE_INDEX 0x01000000
605#define INDEX_UP 0x00800000
606#define WRITE_BACK 0x00200000
607#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 608#define CPSI_MMOD 0x00020000
90e4755a 609
a737bd4d
NC
610#define LITERAL_MASK 0xf000f000
611#define OPCODE_MASK 0xfe1fffff
612#define V4_STR_BIT 0x00000020
90e4755a 613
efd81785
PB
614#define T2_SUBS_PC_LR 0xf3de8f00
615
a737bd4d 616#define DATA_OP_SHIFT 21
90e4755a 617
ef8d22e6
PB
618#define T2_OPCODE_MASK 0xfe1fffff
619#define T2_DATA_OP_SHIFT 21
620
a737bd4d
NC
621/* Codes to distinguish the arithmetic instructions. */
622#define OPCODE_AND 0
623#define OPCODE_EOR 1
624#define OPCODE_SUB 2
625#define OPCODE_RSB 3
626#define OPCODE_ADD 4
627#define OPCODE_ADC 5
628#define OPCODE_SBC 6
629#define OPCODE_RSC 7
630#define OPCODE_TST 8
631#define OPCODE_TEQ 9
632#define OPCODE_CMP 10
633#define OPCODE_CMN 11
634#define OPCODE_ORR 12
635#define OPCODE_MOV 13
636#define OPCODE_BIC 14
637#define OPCODE_MVN 15
90e4755a 638
ef8d22e6
PB
639#define T2_OPCODE_AND 0
640#define T2_OPCODE_BIC 1
641#define T2_OPCODE_ORR 2
642#define T2_OPCODE_ORN 3
643#define T2_OPCODE_EOR 4
644#define T2_OPCODE_ADD 8
645#define T2_OPCODE_ADC 10
646#define T2_OPCODE_SBC 11
647#define T2_OPCODE_SUB 13
648#define T2_OPCODE_RSB 14
649
a737bd4d
NC
650#define T_OPCODE_MUL 0x4340
651#define T_OPCODE_TST 0x4200
652#define T_OPCODE_CMN 0x42c0
653#define T_OPCODE_NEG 0x4240
654#define T_OPCODE_MVN 0x43c0
90e4755a 655
a737bd4d
NC
656#define T_OPCODE_ADD_R3 0x1800
657#define T_OPCODE_SUB_R3 0x1a00
658#define T_OPCODE_ADD_HI 0x4400
659#define T_OPCODE_ADD_ST 0xb000
660#define T_OPCODE_SUB_ST 0xb080
661#define T_OPCODE_ADD_SP 0xa800
662#define T_OPCODE_ADD_PC 0xa000
663#define T_OPCODE_ADD_I8 0x3000
664#define T_OPCODE_SUB_I8 0x3800
665#define T_OPCODE_ADD_I3 0x1c00
666#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 667
a737bd4d
NC
668#define T_OPCODE_ASR_R 0x4100
669#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
670#define T_OPCODE_LSR_R 0x40c0
671#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
672#define T_OPCODE_ASR_I 0x1000
673#define T_OPCODE_LSL_I 0x0000
674#define T_OPCODE_LSR_I 0x0800
b99bd4ef 675
a737bd4d
NC
676#define T_OPCODE_MOV_I8 0x2000
677#define T_OPCODE_CMP_I8 0x2800
678#define T_OPCODE_CMP_LR 0x4280
679#define T_OPCODE_MOV_HR 0x4600
680#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 681
a737bd4d
NC
682#define T_OPCODE_LDR_PC 0x4800
683#define T_OPCODE_LDR_SP 0x9800
684#define T_OPCODE_STR_SP 0x9000
685#define T_OPCODE_LDR_IW 0x6800
686#define T_OPCODE_STR_IW 0x6000
687#define T_OPCODE_LDR_IH 0x8800
688#define T_OPCODE_STR_IH 0x8000
689#define T_OPCODE_LDR_IB 0x7800
690#define T_OPCODE_STR_IB 0x7000
691#define T_OPCODE_LDR_RW 0x5800
692#define T_OPCODE_STR_RW 0x5000
693#define T_OPCODE_LDR_RH 0x5a00
694#define T_OPCODE_STR_RH 0x5200
695#define T_OPCODE_LDR_RB 0x5c00
696#define T_OPCODE_STR_RB 0x5400
c9b604bd 697
a737bd4d
NC
698#define T_OPCODE_PUSH 0xb400
699#define T_OPCODE_POP 0xbc00
b99bd4ef 700
2fc8bdac 701#define T_OPCODE_BRANCH 0xe000
b99bd4ef 702
a737bd4d 703#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 704#define THUMB_PP_PC_LR 0x0100
c19d1205 705#define THUMB_LOAD_BIT 0x0800
53365c0d 706#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
707
708#define BAD_ARGS _("bad arguments to instruction")
fdfde340 709#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
710#define BAD_PC _("r15 not allowed here")
711#define BAD_COND _("instruction cannot be conditional")
712#define BAD_OVERLAP _("registers may not be the same")
713#define BAD_HIREG _("lo register required")
714#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 715#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
716#define BAD_BRANCH _("branch must be last instruction in IT block")
717#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 718#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
719#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
720#define BAD_IT_COND _("incorrect condition in IT block")
721#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 722#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
723#define BAD_PC_ADDRESSING \
724 _("cannot use register index with PC-relative addressing")
725#define BAD_PC_WRITEBACK \
726 _("cannot use writeback with PC-relative addressing")
c19d1205 727
c921be7d
NC
728static struct hash_control * arm_ops_hsh;
729static struct hash_control * arm_cond_hsh;
730static struct hash_control * arm_shift_hsh;
731static struct hash_control * arm_psr_hsh;
732static struct hash_control * arm_v7m_psr_hsh;
733static struct hash_control * arm_reg_hsh;
734static struct hash_control * arm_reloc_hsh;
735static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 736
b99bd4ef
NC
737/* Stuff needed to resolve the label ambiguity
738 As:
739 ...
740 label: <insn>
741 may differ from:
742 ...
743 label:
5f4273c7 744 <insn> */
b99bd4ef
NC
745
746symbolS * last_label_seen;
b34976b6 747static int label_is_thumb_function_name = FALSE;
e07e6e58 748
3d0c9500
NC
749/* Literal pool structure. Held on a per-section
750 and per-sub-section basis. */
a737bd4d 751
c19d1205 752#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 753typedef struct literal_pool
b99bd4ef 754{
c921be7d
NC
755 expressionS literals [MAX_LITERAL_POOL_SIZE];
756 unsigned int next_free_entry;
757 unsigned int id;
758 symbolS * symbol;
759 segT section;
760 subsegT sub_section;
761 struct literal_pool * next;
3d0c9500 762} literal_pool;
b99bd4ef 763
3d0c9500
NC
764/* Pointer to a linked list of literal pools. */
765literal_pool * list_of_pools = NULL;
e27ec89e 766
e07e6e58
NC
767#ifdef OBJ_ELF
768# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
769#else
770static struct current_it now_it;
771#endif
772
773static inline int
774now_it_compatible (int cond)
775{
776 return (cond & ~1) == (now_it.cc & ~1);
777}
778
779static inline int
780conditional_insn (void)
781{
782 return inst.cond != COND_ALWAYS;
783}
784
785static int in_it_block (void);
786
787static int handle_it_state (void);
788
789static void force_automatic_it_block_close (void);
790
c921be7d
NC
791static void it_fsm_post_encode (void);
792
e07e6e58
NC
793#define set_it_insn_type(type) \
794 do \
795 { \
796 inst.it_insn_type = type; \
797 if (handle_it_state () == FAIL) \
798 return; \
799 } \
800 while (0)
801
c921be7d
NC
802#define set_it_insn_type_nonvoid(type, failret) \
803 do \
804 { \
805 inst.it_insn_type = type; \
806 if (handle_it_state () == FAIL) \
807 return failret; \
808 } \
809 while(0)
810
e07e6e58
NC
811#define set_it_insn_type_last() \
812 do \
813 { \
814 if (inst.cond == COND_ALWAYS) \
815 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
816 else \
817 set_it_insn_type (INSIDE_IT_LAST_INSN); \
818 } \
819 while (0)
820
c19d1205 821/* Pure syntax. */
b99bd4ef 822
c19d1205
ZW
823/* This array holds the chars that always start a comment. If the
824 pre-processor is disabled, these aren't very useful. */
825const char comment_chars[] = "@";
3d0c9500 826
c19d1205
ZW
827/* This array holds the chars that only start a comment at the beginning of
828 a line. If the line seems to have the form '# 123 filename'
829 .line and .file directives will appear in the pre-processed output. */
830/* Note that input_file.c hand checks for '#' at the beginning of the
831 first line of the input file. This is because the compiler outputs
832 #NO_APP at the beginning of its output. */
833/* Also note that comments like this one will always work. */
834const char line_comment_chars[] = "#";
3d0c9500 835
c19d1205 836const char line_separator_chars[] = ";";
b99bd4ef 837
c19d1205
ZW
838/* Chars that can be used to separate mant
839 from exp in floating point numbers. */
840const char EXP_CHARS[] = "eE";
3d0c9500 841
c19d1205
ZW
842/* Chars that mean this number is a floating point constant. */
843/* As in 0f12.456 */
844/* or 0d1.2345e12 */
b99bd4ef 845
c19d1205 846const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 847
c19d1205
ZW
848/* Prefix characters that indicate the start of an immediate
849 value. */
850#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 851
c19d1205
ZW
852/* Separator character handling. */
853
854#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
855
856static inline int
857skip_past_char (char ** str, char c)
858{
859 if (**str == c)
860 {
861 (*str)++;
862 return SUCCESS;
3d0c9500 863 }
c19d1205
ZW
864 else
865 return FAIL;
866}
c921be7d 867
c19d1205 868#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 869
c19d1205
ZW
870/* Arithmetic expressions (possibly involving symbols). */
871
872/* Return TRUE if anything in the expression is a bignum. */
873
874static int
875walk_no_bignums (symbolS * sp)
876{
877 if (symbol_get_value_expression (sp)->X_op == O_big)
878 return 1;
879
880 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 881 {
c19d1205
ZW
882 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
883 || (symbol_get_value_expression (sp)->X_op_symbol
884 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
885 }
886
c19d1205 887 return 0;
3d0c9500
NC
888}
889
c19d1205
ZW
890static int in_my_get_expression = 0;
891
892/* Third argument to my_get_expression. */
893#define GE_NO_PREFIX 0
894#define GE_IMM_PREFIX 1
895#define GE_OPT_PREFIX 2
5287ad62
JB
896/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
897 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
898#define GE_OPT_PREFIX_BIG 3
a737bd4d 899
b99bd4ef 900static int
c19d1205 901my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 902{
c19d1205
ZW
903 char * save_in;
904 segT seg;
b99bd4ef 905
c19d1205
ZW
906 /* In unified syntax, all prefixes are optional. */
907 if (unified_syntax)
5287ad62
JB
908 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
909 : GE_OPT_PREFIX;
b99bd4ef 910
c19d1205 911 switch (prefix_mode)
b99bd4ef 912 {
c19d1205
ZW
913 case GE_NO_PREFIX: break;
914 case GE_IMM_PREFIX:
915 if (!is_immediate_prefix (**str))
916 {
917 inst.error = _("immediate expression requires a # prefix");
918 return FAIL;
919 }
920 (*str)++;
921 break;
922 case GE_OPT_PREFIX:
5287ad62 923 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
924 if (is_immediate_prefix (**str))
925 (*str)++;
926 break;
927 default: abort ();
928 }
b99bd4ef 929
c19d1205 930 memset (ep, 0, sizeof (expressionS));
b99bd4ef 931
c19d1205
ZW
932 save_in = input_line_pointer;
933 input_line_pointer = *str;
934 in_my_get_expression = 1;
935 seg = expression (ep);
936 in_my_get_expression = 0;
937
f86adc07 938 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 939 {
f86adc07 940 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
941 *str = input_line_pointer;
942 input_line_pointer = save_in;
943 if (inst.error == NULL)
f86adc07
NS
944 inst.error = (ep->X_op == O_absent
945 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
946 return 1;
947 }
b99bd4ef 948
c19d1205
ZW
949#ifdef OBJ_AOUT
950 if (seg != absolute_section
951 && seg != text_section
952 && seg != data_section
953 && seg != bss_section
954 && seg != undefined_section)
955 {
956 inst.error = _("bad segment");
957 *str = input_line_pointer;
958 input_line_pointer = save_in;
959 return 1;
b99bd4ef 960 }
87975d2a
AM
961#else
962 (void) seg;
c19d1205 963#endif
b99bd4ef 964
c19d1205
ZW
965 /* Get rid of any bignums now, so that we don't generate an error for which
966 we can't establish a line number later on. Big numbers are never valid
967 in instructions, which is where this routine is always called. */
5287ad62
JB
968 if (prefix_mode != GE_OPT_PREFIX_BIG
969 && (ep->X_op == O_big
970 || (ep->X_add_symbol
971 && (walk_no_bignums (ep->X_add_symbol)
972 || (ep->X_op_symbol
973 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
974 {
975 inst.error = _("invalid constant");
976 *str = input_line_pointer;
977 input_line_pointer = save_in;
978 return 1;
979 }
b99bd4ef 980
c19d1205
ZW
981 *str = input_line_pointer;
982 input_line_pointer = save_in;
983 return 0;
b99bd4ef
NC
984}
985
c19d1205
ZW
986/* Turn a string in input_line_pointer into a floating point constant
987 of type TYPE, and store the appropriate bytes in *LITP. The number
988 of LITTLENUMS emitted is stored in *SIZEP. An error message is
989 returned, or NULL on OK.
b99bd4ef 990
c19d1205
ZW
991 Note that fp constants aren't represent in the normal way on the ARM.
992 In big endian mode, things are as expected. However, in little endian
993 mode fp constants are big-endian word-wise, and little-endian byte-wise
994 within the words. For example, (double) 1.1 in big endian mode is
995 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
996 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 997
c19d1205 998 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 999
c19d1205
ZW
1000char *
1001md_atof (int type, char * litP, int * sizeP)
1002{
1003 int prec;
1004 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1005 char *t;
1006 int i;
b99bd4ef 1007
c19d1205
ZW
1008 switch (type)
1009 {
1010 case 'f':
1011 case 'F':
1012 case 's':
1013 case 'S':
1014 prec = 2;
1015 break;
b99bd4ef 1016
c19d1205
ZW
1017 case 'd':
1018 case 'D':
1019 case 'r':
1020 case 'R':
1021 prec = 4;
1022 break;
b99bd4ef 1023
c19d1205
ZW
1024 case 'x':
1025 case 'X':
499ac353 1026 prec = 5;
c19d1205 1027 break;
b99bd4ef 1028
c19d1205
ZW
1029 case 'p':
1030 case 'P':
499ac353 1031 prec = 5;
c19d1205 1032 break;
a737bd4d 1033
c19d1205
ZW
1034 default:
1035 *sizeP = 0;
499ac353 1036 return _("Unrecognized or unsupported floating point constant");
c19d1205 1037 }
b99bd4ef 1038
c19d1205
ZW
1039 t = atof_ieee (input_line_pointer, type, words);
1040 if (t)
1041 input_line_pointer = t;
499ac353 1042 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1043
c19d1205
ZW
1044 if (target_big_endian)
1045 {
1046 for (i = 0; i < prec; i++)
1047 {
499ac353
NC
1048 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1049 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1050 }
1051 }
1052 else
1053 {
e74cfd16 1054 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1055 for (i = prec - 1; i >= 0; i--)
1056 {
499ac353
NC
1057 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1058 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1059 }
1060 else
1061 /* For a 4 byte float the order of elements in `words' is 1 0.
1062 For an 8 byte float the order is 1 0 3 2. */
1063 for (i = 0; i < prec; i += 2)
1064 {
499ac353
NC
1065 md_number_to_chars (litP, (valueT) words[i + 1],
1066 sizeof (LITTLENUM_TYPE));
1067 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1068 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1069 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1070 }
1071 }
b99bd4ef 1072
499ac353 1073 return NULL;
c19d1205 1074}
b99bd4ef 1075
c19d1205
ZW
1076/* We handle all bad expressions here, so that we can report the faulty
1077 instruction in the error message. */
1078void
91d6fa6a 1079md_operand (expressionS * exp)
c19d1205
ZW
1080{
1081 if (in_my_get_expression)
91d6fa6a 1082 exp->X_op = O_illegal;
b99bd4ef
NC
1083}
1084
c19d1205 1085/* Immediate values. */
b99bd4ef 1086
c19d1205
ZW
1087/* Generic immediate-value read function for use in directives.
1088 Accepts anything that 'expression' can fold to a constant.
1089 *val receives the number. */
1090#ifdef OBJ_ELF
1091static int
1092immediate_for_directive (int *val)
b99bd4ef 1093{
c19d1205
ZW
1094 expressionS exp;
1095 exp.X_op = O_illegal;
b99bd4ef 1096
c19d1205
ZW
1097 if (is_immediate_prefix (*input_line_pointer))
1098 {
1099 input_line_pointer++;
1100 expression (&exp);
1101 }
b99bd4ef 1102
c19d1205
ZW
1103 if (exp.X_op != O_constant)
1104 {
1105 as_bad (_("expected #constant"));
1106 ignore_rest_of_line ();
1107 return FAIL;
1108 }
1109 *val = exp.X_add_number;
1110 return SUCCESS;
b99bd4ef 1111}
c19d1205 1112#endif
b99bd4ef 1113
c19d1205 1114/* Register parsing. */
b99bd4ef 1115
c19d1205
ZW
1116/* Generic register parser. CCP points to what should be the
1117 beginning of a register name. If it is indeed a valid register
1118 name, advance CCP over it and return the reg_entry structure;
1119 otherwise return NULL. Does not issue diagnostics. */
1120
1121static struct reg_entry *
1122arm_reg_parse_multi (char **ccp)
b99bd4ef 1123{
c19d1205
ZW
1124 char *start = *ccp;
1125 char *p;
1126 struct reg_entry *reg;
b99bd4ef 1127
c19d1205
ZW
1128#ifdef REGISTER_PREFIX
1129 if (*start != REGISTER_PREFIX)
01cfc07f 1130 return NULL;
c19d1205
ZW
1131 start++;
1132#endif
1133#ifdef OPTIONAL_REGISTER_PREFIX
1134 if (*start == OPTIONAL_REGISTER_PREFIX)
1135 start++;
1136#endif
b99bd4ef 1137
c19d1205
ZW
1138 p = start;
1139 if (!ISALPHA (*p) || !is_name_beginner (*p))
1140 return NULL;
b99bd4ef 1141
c19d1205
ZW
1142 do
1143 p++;
1144 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1145
1146 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1147
1148 if (!reg)
1149 return NULL;
1150
1151 *ccp = p;
1152 return reg;
b99bd4ef
NC
1153}
1154
1155static int
dcbf9037
JB
1156arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1157 enum arm_reg_type type)
b99bd4ef 1158{
c19d1205
ZW
1159 /* Alternative syntaxes are accepted for a few register classes. */
1160 switch (type)
1161 {
1162 case REG_TYPE_MVF:
1163 case REG_TYPE_MVD:
1164 case REG_TYPE_MVFX:
1165 case REG_TYPE_MVDX:
1166 /* Generic coprocessor register names are allowed for these. */
79134647 1167 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1168 return reg->number;
1169 break;
69b97547 1170
c19d1205
ZW
1171 case REG_TYPE_CP:
1172 /* For backward compatibility, a bare number is valid here. */
1173 {
1174 unsigned long processor = strtoul (start, ccp, 10);
1175 if (*ccp != start && processor <= 15)
1176 return processor;
1177 }
6057a28f 1178
c19d1205
ZW
1179 case REG_TYPE_MMXWC:
1180 /* WC includes WCG. ??? I'm not sure this is true for all
1181 instructions that take WC registers. */
79134647 1182 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1183 return reg->number;
6057a28f 1184 break;
c19d1205 1185
6057a28f 1186 default:
c19d1205 1187 break;
6057a28f
NC
1188 }
1189
dcbf9037
JB
1190 return FAIL;
1191}
1192
1193/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1194 return value is the register number or FAIL. */
1195
1196static int
1197arm_reg_parse (char **ccp, enum arm_reg_type type)
1198{
1199 char *start = *ccp;
1200 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1201 int ret;
1202
1203 /* Do not allow a scalar (reg+index) to parse as a register. */
1204 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1205 return FAIL;
1206
1207 if (reg && reg->type == type)
1208 return reg->number;
1209
1210 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1211 return ret;
1212
c19d1205
ZW
1213 *ccp = start;
1214 return FAIL;
1215}
69b97547 1216
dcbf9037
JB
1217/* Parse a Neon type specifier. *STR should point at the leading '.'
1218 character. Does no verification at this stage that the type fits the opcode
1219 properly. E.g.,
1220
1221 .i32.i32.s16
1222 .s32.f32
1223 .u16
1224
1225 Can all be legally parsed by this function.
1226
1227 Fills in neon_type struct pointer with parsed information, and updates STR
1228 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1229 type, FAIL if not. */
1230
1231static int
1232parse_neon_type (struct neon_type *type, char **str)
1233{
1234 char *ptr = *str;
1235
1236 if (type)
1237 type->elems = 0;
1238
1239 while (type->elems < NEON_MAX_TYPE_ELS)
1240 {
1241 enum neon_el_type thistype = NT_untyped;
1242 unsigned thissize = -1u;
1243
1244 if (*ptr != '.')
1245 break;
1246
1247 ptr++;
1248
1249 /* Just a size without an explicit type. */
1250 if (ISDIGIT (*ptr))
1251 goto parsesize;
1252
1253 switch (TOLOWER (*ptr))
1254 {
1255 case 'i': thistype = NT_integer; break;
1256 case 'f': thistype = NT_float; break;
1257 case 'p': thistype = NT_poly; break;
1258 case 's': thistype = NT_signed; break;
1259 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1260 case 'd':
1261 thistype = NT_float;
1262 thissize = 64;
1263 ptr++;
1264 goto done;
dcbf9037
JB
1265 default:
1266 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1267 return FAIL;
1268 }
1269
1270 ptr++;
1271
1272 /* .f is an abbreviation for .f32. */
1273 if (thistype == NT_float && !ISDIGIT (*ptr))
1274 thissize = 32;
1275 else
1276 {
1277 parsesize:
1278 thissize = strtoul (ptr, &ptr, 10);
1279
1280 if (thissize != 8 && thissize != 16 && thissize != 32
1281 && thissize != 64)
1282 {
1283 as_bad (_("bad size %d in type specifier"), thissize);
1284 return FAIL;
1285 }
1286 }
1287
037e8744 1288 done:
dcbf9037
JB
1289 if (type)
1290 {
1291 type->el[type->elems].type = thistype;
1292 type->el[type->elems].size = thissize;
1293 type->elems++;
1294 }
1295 }
1296
1297 /* Empty/missing type is not a successful parse. */
1298 if (type->elems == 0)
1299 return FAIL;
1300
1301 *str = ptr;
1302
1303 return SUCCESS;
1304}
1305
1306/* Errors may be set multiple times during parsing or bit encoding
1307 (particularly in the Neon bits), but usually the earliest error which is set
1308 will be the most meaningful. Avoid overwriting it with later (cascading)
1309 errors by calling this function. */
1310
1311static void
1312first_error (const char *err)
1313{
1314 if (!inst.error)
1315 inst.error = err;
1316}
1317
1318/* Parse a single type, e.g. ".s32", leading period included. */
1319static int
1320parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1321{
1322 char *str = *ccp;
1323 struct neon_type optype;
1324
1325 if (*str == '.')
1326 {
1327 if (parse_neon_type (&optype, &str) == SUCCESS)
1328 {
1329 if (optype.elems == 1)
1330 *vectype = optype.el[0];
1331 else
1332 {
1333 first_error (_("only one type should be specified for operand"));
1334 return FAIL;
1335 }
1336 }
1337 else
1338 {
1339 first_error (_("vector type expected"));
1340 return FAIL;
1341 }
1342 }
1343 else
1344 return FAIL;
5f4273c7 1345
dcbf9037 1346 *ccp = str;
5f4273c7 1347
dcbf9037
JB
1348 return SUCCESS;
1349}
1350
1351/* Special meanings for indices (which have a range of 0-7), which will fit into
1352 a 4-bit integer. */
1353
1354#define NEON_ALL_LANES 15
1355#define NEON_INTERLEAVE_LANES 14
1356
1357/* Parse either a register or a scalar, with an optional type. Return the
1358 register number, and optionally fill in the actual type of the register
1359 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1360 type/index information in *TYPEINFO. */
1361
1362static int
1363parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1364 enum arm_reg_type *rtype,
1365 struct neon_typed_alias *typeinfo)
1366{
1367 char *str = *ccp;
1368 struct reg_entry *reg = arm_reg_parse_multi (&str);
1369 struct neon_typed_alias atype;
1370 struct neon_type_el parsetype;
1371
1372 atype.defined = 0;
1373 atype.index = -1;
1374 atype.eltype.type = NT_invtype;
1375 atype.eltype.size = -1;
1376
1377 /* Try alternate syntax for some types of register. Note these are mutually
1378 exclusive with the Neon syntax extensions. */
1379 if (reg == NULL)
1380 {
1381 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1382 if (altreg != FAIL)
1383 *ccp = str;
1384 if (typeinfo)
1385 *typeinfo = atype;
1386 return altreg;
1387 }
1388
037e8744
JB
1389 /* Undo polymorphism when a set of register types may be accepted. */
1390 if ((type == REG_TYPE_NDQ
1391 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1392 || (type == REG_TYPE_VFSD
1393 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1394 || (type == REG_TYPE_NSDQ
1395 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1396 || reg->type == REG_TYPE_NQ))
1397 || (type == REG_TYPE_MMXWC
1398 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1399 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1400
1401 if (type != reg->type)
1402 return FAIL;
1403
1404 if (reg->neon)
1405 atype = *reg->neon;
5f4273c7 1406
dcbf9037
JB
1407 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1408 {
1409 if ((atype.defined & NTA_HASTYPE) != 0)
1410 {
1411 first_error (_("can't redefine type for operand"));
1412 return FAIL;
1413 }
1414 atype.defined |= NTA_HASTYPE;
1415 atype.eltype = parsetype;
1416 }
5f4273c7 1417
dcbf9037
JB
1418 if (skip_past_char (&str, '[') == SUCCESS)
1419 {
1420 if (type != REG_TYPE_VFD)
1421 {
1422 first_error (_("only D registers may be indexed"));
1423 return FAIL;
1424 }
5f4273c7 1425
dcbf9037
JB
1426 if ((atype.defined & NTA_HASINDEX) != 0)
1427 {
1428 first_error (_("can't change index for operand"));
1429 return FAIL;
1430 }
1431
1432 atype.defined |= NTA_HASINDEX;
1433
1434 if (skip_past_char (&str, ']') == SUCCESS)
1435 atype.index = NEON_ALL_LANES;
1436 else
1437 {
1438 expressionS exp;
1439
1440 my_get_expression (&exp, &str, GE_NO_PREFIX);
1441
1442 if (exp.X_op != O_constant)
1443 {
1444 first_error (_("constant expression required"));
1445 return FAIL;
1446 }
1447
1448 if (skip_past_char (&str, ']') == FAIL)
1449 return FAIL;
1450
1451 atype.index = exp.X_add_number;
1452 }
1453 }
5f4273c7 1454
dcbf9037
JB
1455 if (typeinfo)
1456 *typeinfo = atype;
5f4273c7 1457
dcbf9037
JB
1458 if (rtype)
1459 *rtype = type;
5f4273c7 1460
dcbf9037 1461 *ccp = str;
5f4273c7 1462
dcbf9037
JB
1463 return reg->number;
1464}
1465
1466/* Like arm_reg_parse, but allow allow the following extra features:
1467 - If RTYPE is non-zero, return the (possibly restricted) type of the
1468 register (e.g. Neon double or quad reg when either has been requested).
1469 - If this is a Neon vector type with additional type information, fill
1470 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1471 This function will fault on encountering a scalar. */
dcbf9037
JB
1472
1473static int
1474arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1475 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1476{
1477 struct neon_typed_alias atype;
1478 char *str = *ccp;
1479 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1480
1481 if (reg == FAIL)
1482 return FAIL;
1483
0855e32b
NS
1484 /* Do not allow regname(... to parse as a register. */
1485 if (*str == '(')
1486 return FAIL;
1487
dcbf9037
JB
1488 /* Do not allow a scalar (reg+index) to parse as a register. */
1489 if ((atype.defined & NTA_HASINDEX) != 0)
1490 {
1491 first_error (_("register operand expected, but got scalar"));
1492 return FAIL;
1493 }
1494
1495 if (vectype)
1496 *vectype = atype.eltype;
1497
1498 *ccp = str;
1499
1500 return reg;
1501}
1502
1503#define NEON_SCALAR_REG(X) ((X) >> 4)
1504#define NEON_SCALAR_INDEX(X) ((X) & 15)
1505
5287ad62
JB
1506/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1507 have enough information to be able to do a good job bounds-checking. So, we
1508 just do easy checks here, and do further checks later. */
1509
1510static int
dcbf9037 1511parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1512{
dcbf9037 1513 int reg;
5287ad62 1514 char *str = *ccp;
dcbf9037 1515 struct neon_typed_alias atype;
5f4273c7 1516
dcbf9037 1517 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1518
dcbf9037 1519 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1520 return FAIL;
5f4273c7 1521
dcbf9037 1522 if (atype.index == NEON_ALL_LANES)
5287ad62 1523 {
dcbf9037 1524 first_error (_("scalar must have an index"));
5287ad62
JB
1525 return FAIL;
1526 }
dcbf9037 1527 else if (atype.index >= 64 / elsize)
5287ad62 1528 {
dcbf9037 1529 first_error (_("scalar index out of range"));
5287ad62
JB
1530 return FAIL;
1531 }
5f4273c7 1532
dcbf9037
JB
1533 if (type)
1534 *type = atype.eltype;
5f4273c7 1535
5287ad62 1536 *ccp = str;
5f4273c7 1537
dcbf9037 1538 return reg * 16 + atype.index;
5287ad62
JB
1539}
1540
c19d1205 1541/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1542
c19d1205
ZW
1543static long
1544parse_reg_list (char ** strp)
1545{
1546 char * str = * strp;
1547 long range = 0;
1548 int another_range;
a737bd4d 1549
c19d1205
ZW
1550 /* We come back here if we get ranges concatenated by '+' or '|'. */
1551 do
6057a28f 1552 {
c19d1205 1553 another_range = 0;
a737bd4d 1554
c19d1205
ZW
1555 if (*str == '{')
1556 {
1557 int in_range = 0;
1558 int cur_reg = -1;
a737bd4d 1559
c19d1205
ZW
1560 str++;
1561 do
1562 {
1563 int reg;
6057a28f 1564
dcbf9037 1565 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1566 {
dcbf9037 1567 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1568 return FAIL;
1569 }
a737bd4d 1570
c19d1205
ZW
1571 if (in_range)
1572 {
1573 int i;
a737bd4d 1574
c19d1205
ZW
1575 if (reg <= cur_reg)
1576 {
dcbf9037 1577 first_error (_("bad range in register list"));
c19d1205
ZW
1578 return FAIL;
1579 }
40a18ebd 1580
c19d1205
ZW
1581 for (i = cur_reg + 1; i < reg; i++)
1582 {
1583 if (range & (1 << i))
1584 as_tsktsk
1585 (_("Warning: duplicated register (r%d) in register list"),
1586 i);
1587 else
1588 range |= 1 << i;
1589 }
1590 in_range = 0;
1591 }
a737bd4d 1592
c19d1205
ZW
1593 if (range & (1 << reg))
1594 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1595 reg);
1596 else if (reg <= cur_reg)
1597 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1598
c19d1205
ZW
1599 range |= 1 << reg;
1600 cur_reg = reg;
1601 }
1602 while (skip_past_comma (&str) != FAIL
1603 || (in_range = 1, *str++ == '-'));
1604 str--;
a737bd4d 1605
c19d1205
ZW
1606 if (*str++ != '}')
1607 {
dcbf9037 1608 first_error (_("missing `}'"));
c19d1205
ZW
1609 return FAIL;
1610 }
1611 }
1612 else
1613 {
91d6fa6a 1614 expressionS exp;
40a18ebd 1615
91d6fa6a 1616 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1617 return FAIL;
40a18ebd 1618
91d6fa6a 1619 if (exp.X_op == O_constant)
c19d1205 1620 {
91d6fa6a
NC
1621 if (exp.X_add_number
1622 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1623 {
1624 inst.error = _("invalid register mask");
1625 return FAIL;
1626 }
a737bd4d 1627
91d6fa6a 1628 if ((range & exp.X_add_number) != 0)
c19d1205 1629 {
91d6fa6a 1630 int regno = range & exp.X_add_number;
a737bd4d 1631
c19d1205
ZW
1632 regno &= -regno;
1633 regno = (1 << regno) - 1;
1634 as_tsktsk
1635 (_("Warning: duplicated register (r%d) in register list"),
1636 regno);
1637 }
a737bd4d 1638
91d6fa6a 1639 range |= exp.X_add_number;
c19d1205
ZW
1640 }
1641 else
1642 {
1643 if (inst.reloc.type != 0)
1644 {
1645 inst.error = _("expression too complex");
1646 return FAIL;
1647 }
a737bd4d 1648
91d6fa6a 1649 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1650 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1651 inst.reloc.pc_rel = 0;
1652 }
1653 }
a737bd4d 1654
c19d1205
ZW
1655 if (*str == '|' || *str == '+')
1656 {
1657 str++;
1658 another_range = 1;
1659 }
a737bd4d 1660 }
c19d1205 1661 while (another_range);
a737bd4d 1662
c19d1205
ZW
1663 *strp = str;
1664 return range;
a737bd4d
NC
1665}
1666
5287ad62
JB
1667/* Types of registers in a list. */
1668
1669enum reg_list_els
1670{
1671 REGLIST_VFP_S,
1672 REGLIST_VFP_D,
1673 REGLIST_NEON_D
1674};
1675
c19d1205
ZW
1676/* Parse a VFP register list. If the string is invalid return FAIL.
1677 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1678 register. Parses registers of type ETYPE.
1679 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1680 - Q registers can be used to specify pairs of D registers
1681 - { } can be omitted from around a singleton register list
1682 FIXME: This is not implemented, as it would require backtracking in
1683 some cases, e.g.:
1684 vtbl.8 d3,d4,d5
1685 This could be done (the meaning isn't really ambiguous), but doesn't
1686 fit in well with the current parsing framework.
dcbf9037
JB
1687 - 32 D registers may be used (also true for VFPv3).
1688 FIXME: Types are ignored in these register lists, which is probably a
1689 bug. */
6057a28f 1690
c19d1205 1691static int
037e8744 1692parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1693{
037e8744 1694 char *str = *ccp;
c19d1205
ZW
1695 int base_reg;
1696 int new_base;
21d799b5 1697 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1698 int max_regs = 0;
c19d1205
ZW
1699 int count = 0;
1700 int warned = 0;
1701 unsigned long mask = 0;
a737bd4d 1702 int i;
6057a28f 1703
037e8744 1704 if (*str != '{')
5287ad62
JB
1705 {
1706 inst.error = _("expecting {");
1707 return FAIL;
1708 }
6057a28f 1709
037e8744 1710 str++;
6057a28f 1711
5287ad62 1712 switch (etype)
c19d1205 1713 {
5287ad62 1714 case REGLIST_VFP_S:
c19d1205
ZW
1715 regtype = REG_TYPE_VFS;
1716 max_regs = 32;
5287ad62 1717 break;
5f4273c7 1718
5287ad62
JB
1719 case REGLIST_VFP_D:
1720 regtype = REG_TYPE_VFD;
b7fc2769 1721 break;
5f4273c7 1722
b7fc2769
JB
1723 case REGLIST_NEON_D:
1724 regtype = REG_TYPE_NDQ;
1725 break;
1726 }
1727
1728 if (etype != REGLIST_VFP_S)
1729 {
b1cc4aeb
PB
1730 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1731 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1732 {
1733 max_regs = 32;
1734 if (thumb_mode)
1735 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1736 fpu_vfp_ext_d32);
5287ad62
JB
1737 else
1738 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1739 fpu_vfp_ext_d32);
5287ad62
JB
1740 }
1741 else
1742 max_regs = 16;
c19d1205 1743 }
6057a28f 1744
c19d1205 1745 base_reg = max_regs;
a737bd4d 1746
c19d1205
ZW
1747 do
1748 {
5287ad62 1749 int setmask = 1, addregs = 1;
dcbf9037 1750
037e8744 1751 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1752
c19d1205 1753 if (new_base == FAIL)
a737bd4d 1754 {
dcbf9037 1755 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1756 return FAIL;
1757 }
5f4273c7 1758
b7fc2769
JB
1759 if (new_base >= max_regs)
1760 {
1761 first_error (_("register out of range in list"));
1762 return FAIL;
1763 }
5f4273c7 1764
5287ad62
JB
1765 /* Note: a value of 2 * n is returned for the register Q<n>. */
1766 if (regtype == REG_TYPE_NQ)
1767 {
1768 setmask = 3;
1769 addregs = 2;
1770 }
1771
c19d1205
ZW
1772 if (new_base < base_reg)
1773 base_reg = new_base;
a737bd4d 1774
5287ad62 1775 if (mask & (setmask << new_base))
c19d1205 1776 {
dcbf9037 1777 first_error (_("invalid register list"));
c19d1205 1778 return FAIL;
a737bd4d 1779 }
a737bd4d 1780
c19d1205
ZW
1781 if ((mask >> new_base) != 0 && ! warned)
1782 {
1783 as_tsktsk (_("register list not in ascending order"));
1784 warned = 1;
1785 }
0bbf2aa4 1786
5287ad62
JB
1787 mask |= setmask << new_base;
1788 count += addregs;
0bbf2aa4 1789
037e8744 1790 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1791 {
1792 int high_range;
0bbf2aa4 1793
037e8744 1794 str++;
0bbf2aa4 1795
037e8744 1796 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1797 == FAIL)
c19d1205
ZW
1798 {
1799 inst.error = gettext (reg_expected_msgs[regtype]);
1800 return FAIL;
1801 }
0bbf2aa4 1802
b7fc2769
JB
1803 if (high_range >= max_regs)
1804 {
1805 first_error (_("register out of range in list"));
1806 return FAIL;
1807 }
1808
5287ad62
JB
1809 if (regtype == REG_TYPE_NQ)
1810 high_range = high_range + 1;
1811
c19d1205
ZW
1812 if (high_range <= new_base)
1813 {
1814 inst.error = _("register range not in ascending order");
1815 return FAIL;
1816 }
0bbf2aa4 1817
5287ad62 1818 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1819 {
5287ad62 1820 if (mask & (setmask << new_base))
0bbf2aa4 1821 {
c19d1205
ZW
1822 inst.error = _("invalid register list");
1823 return FAIL;
0bbf2aa4 1824 }
c19d1205 1825
5287ad62
JB
1826 mask |= setmask << new_base;
1827 count += addregs;
0bbf2aa4 1828 }
0bbf2aa4 1829 }
0bbf2aa4 1830 }
037e8744 1831 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1832
037e8744 1833 str++;
0bbf2aa4 1834
c19d1205
ZW
1835 /* Sanity check -- should have raised a parse error above. */
1836 if (count == 0 || count > max_regs)
1837 abort ();
1838
1839 *pbase = base_reg;
1840
1841 /* Final test -- the registers must be consecutive. */
1842 mask >>= base_reg;
1843 for (i = 0; i < count; i++)
1844 {
1845 if ((mask & (1u << i)) == 0)
1846 {
1847 inst.error = _("non-contiguous register range");
1848 return FAIL;
1849 }
1850 }
1851
037e8744
JB
1852 *ccp = str;
1853
c19d1205 1854 return count;
b99bd4ef
NC
1855}
1856
dcbf9037
JB
1857/* True if two alias types are the same. */
1858
c921be7d 1859static bfd_boolean
dcbf9037
JB
1860neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1861{
1862 if (!a && !b)
c921be7d 1863 return TRUE;
5f4273c7 1864
dcbf9037 1865 if (!a || !b)
c921be7d 1866 return FALSE;
dcbf9037
JB
1867
1868 if (a->defined != b->defined)
c921be7d 1869 return FALSE;
5f4273c7 1870
dcbf9037
JB
1871 if ((a->defined & NTA_HASTYPE) != 0
1872 && (a->eltype.type != b->eltype.type
1873 || a->eltype.size != b->eltype.size))
c921be7d 1874 return FALSE;
dcbf9037
JB
1875
1876 if ((a->defined & NTA_HASINDEX) != 0
1877 && (a->index != b->index))
c921be7d 1878 return FALSE;
5f4273c7 1879
c921be7d 1880 return TRUE;
dcbf9037
JB
1881}
1882
5287ad62
JB
1883/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1884 The base register is put in *PBASE.
dcbf9037 1885 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1886 the return value.
1887 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1888 Bits [6:5] encode the list length (minus one).
1889 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1890
5287ad62 1891#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1892#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1893#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1894
1895static int
dcbf9037
JB
1896parse_neon_el_struct_list (char **str, unsigned *pbase,
1897 struct neon_type_el *eltype)
5287ad62
JB
1898{
1899 char *ptr = *str;
1900 int base_reg = -1;
1901 int reg_incr = -1;
1902 int count = 0;
1903 int lane = -1;
1904 int leading_brace = 0;
1905 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1906 const char *const incr_error = _("register stride must be 1 or 2");
1907 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1908 struct neon_typed_alias firsttype;
5f4273c7 1909
5287ad62
JB
1910 if (skip_past_char (&ptr, '{') == SUCCESS)
1911 leading_brace = 1;
5f4273c7 1912
5287ad62
JB
1913 do
1914 {
dcbf9037
JB
1915 struct neon_typed_alias atype;
1916 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1917
5287ad62
JB
1918 if (getreg == FAIL)
1919 {
dcbf9037 1920 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1921 return FAIL;
1922 }
5f4273c7 1923
5287ad62
JB
1924 if (base_reg == -1)
1925 {
1926 base_reg = getreg;
1927 if (rtype == REG_TYPE_NQ)
1928 {
1929 reg_incr = 1;
5287ad62 1930 }
dcbf9037 1931 firsttype = atype;
5287ad62
JB
1932 }
1933 else if (reg_incr == -1)
1934 {
1935 reg_incr = getreg - base_reg;
1936 if (reg_incr < 1 || reg_incr > 2)
1937 {
dcbf9037 1938 first_error (_(incr_error));
5287ad62
JB
1939 return FAIL;
1940 }
1941 }
1942 else if (getreg != base_reg + reg_incr * count)
1943 {
dcbf9037
JB
1944 first_error (_(incr_error));
1945 return FAIL;
1946 }
1947
c921be7d 1948 if (! neon_alias_types_same (&atype, &firsttype))
dcbf9037
JB
1949 {
1950 first_error (_(type_error));
5287ad62
JB
1951 return FAIL;
1952 }
5f4273c7 1953
5287ad62
JB
1954 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1955 modes. */
1956 if (ptr[0] == '-')
1957 {
dcbf9037 1958 struct neon_typed_alias htype;
5287ad62
JB
1959 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1960 if (lane == -1)
1961 lane = NEON_INTERLEAVE_LANES;
1962 else if (lane != NEON_INTERLEAVE_LANES)
1963 {
dcbf9037 1964 first_error (_(type_error));
5287ad62
JB
1965 return FAIL;
1966 }
1967 if (reg_incr == -1)
1968 reg_incr = 1;
1969 else if (reg_incr != 1)
1970 {
dcbf9037 1971 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1972 return FAIL;
1973 }
1974 ptr++;
dcbf9037 1975 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1976 if (hireg == FAIL)
1977 {
dcbf9037
JB
1978 first_error (_(reg_expected_msgs[rtype]));
1979 return FAIL;
1980 }
c921be7d 1981 if (! neon_alias_types_same (&htype, &firsttype))
dcbf9037
JB
1982 {
1983 first_error (_(type_error));
5287ad62
JB
1984 return FAIL;
1985 }
1986 count += hireg + dregs - getreg;
1987 continue;
1988 }
5f4273c7 1989
5287ad62
JB
1990 /* If we're using Q registers, we can't use [] or [n] syntax. */
1991 if (rtype == REG_TYPE_NQ)
1992 {
1993 count += 2;
1994 continue;
1995 }
5f4273c7 1996
dcbf9037 1997 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1998 {
dcbf9037
JB
1999 if (lane == -1)
2000 lane = atype.index;
2001 else if (lane != atype.index)
5287ad62 2002 {
dcbf9037
JB
2003 first_error (_(type_error));
2004 return FAIL;
5287ad62
JB
2005 }
2006 }
2007 else if (lane == -1)
2008 lane = NEON_INTERLEAVE_LANES;
2009 else if (lane != NEON_INTERLEAVE_LANES)
2010 {
dcbf9037 2011 first_error (_(type_error));
5287ad62
JB
2012 return FAIL;
2013 }
2014 count++;
2015 }
2016 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2017
5287ad62
JB
2018 /* No lane set by [x]. We must be interleaving structures. */
2019 if (lane == -1)
2020 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2021
5287ad62
JB
2022 /* Sanity check. */
2023 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2024 || (count > 1 && reg_incr == -1))
2025 {
dcbf9037 2026 first_error (_("error parsing element/structure list"));
5287ad62
JB
2027 return FAIL;
2028 }
2029
2030 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2031 {
dcbf9037 2032 first_error (_("expected }"));
5287ad62
JB
2033 return FAIL;
2034 }
5f4273c7 2035
5287ad62
JB
2036 if (reg_incr == -1)
2037 reg_incr = 1;
2038
dcbf9037
JB
2039 if (eltype)
2040 *eltype = firsttype.eltype;
2041
5287ad62
JB
2042 *pbase = base_reg;
2043 *str = ptr;
5f4273c7 2044
5287ad62
JB
2045 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2046}
2047
c19d1205
ZW
2048/* Parse an explicit relocation suffix on an expression. This is
2049 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2050 arm_reloc_hsh contains no entries, so this function can only
2051 succeed if there is no () after the word. Returns -1 on error,
2052 BFD_RELOC_UNUSED if there wasn't any suffix. */
2053static int
2054parse_reloc (char **str)
b99bd4ef 2055{
c19d1205
ZW
2056 struct reloc_entry *r;
2057 char *p, *q;
b99bd4ef 2058
c19d1205
ZW
2059 if (**str != '(')
2060 return BFD_RELOC_UNUSED;
b99bd4ef 2061
c19d1205
ZW
2062 p = *str + 1;
2063 q = p;
2064
2065 while (*q && *q != ')' && *q != ',')
2066 q++;
2067 if (*q != ')')
2068 return -1;
2069
21d799b5
NC
2070 if ((r = (struct reloc_entry *)
2071 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2072 return -1;
2073
2074 *str = q + 1;
2075 return r->reloc;
b99bd4ef
NC
2076}
2077
c19d1205
ZW
2078/* Directives: register aliases. */
2079
dcbf9037 2080static struct reg_entry *
90ec0d68 2081insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2082{
d3ce72d0 2083 struct reg_entry *new_reg;
c19d1205 2084 const char *name;
b99bd4ef 2085
d3ce72d0 2086 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2087 {
d3ce72d0 2088 if (new_reg->builtin)
c19d1205 2089 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2090
c19d1205
ZW
2091 /* Only warn about a redefinition if it's not defined as the
2092 same register. */
d3ce72d0 2093 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2094 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2095
d929913e 2096 return NULL;
c19d1205 2097 }
b99bd4ef 2098
c19d1205 2099 name = xstrdup (str);
d3ce72d0 2100 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2101
d3ce72d0
NC
2102 new_reg->name = name;
2103 new_reg->number = number;
2104 new_reg->type = type;
2105 new_reg->builtin = FALSE;
2106 new_reg->neon = NULL;
b99bd4ef 2107
d3ce72d0 2108 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2109 abort ();
5f4273c7 2110
d3ce72d0 2111 return new_reg;
dcbf9037
JB
2112}
2113
2114static void
2115insert_neon_reg_alias (char *str, int number, int type,
2116 struct neon_typed_alias *atype)
2117{
2118 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2119
dcbf9037
JB
2120 if (!reg)
2121 {
2122 first_error (_("attempt to redefine typed alias"));
2123 return;
2124 }
5f4273c7 2125
dcbf9037
JB
2126 if (atype)
2127 {
21d799b5
NC
2128 reg->neon = (struct neon_typed_alias *)
2129 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2130 *reg->neon = *atype;
2131 }
c19d1205 2132}
b99bd4ef 2133
c19d1205 2134/* Look for the .req directive. This is of the form:
b99bd4ef 2135
c19d1205 2136 new_register_name .req existing_register_name
b99bd4ef 2137
c19d1205 2138 If we find one, or if it looks sufficiently like one that we want to
d929913e 2139 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2140
d929913e 2141static bfd_boolean
c19d1205
ZW
2142create_register_alias (char * newname, char *p)
2143{
2144 struct reg_entry *old;
2145 char *oldname, *nbuf;
2146 size_t nlen;
b99bd4ef 2147
c19d1205
ZW
2148 /* The input scrubber ensures that whitespace after the mnemonic is
2149 collapsed to single spaces. */
2150 oldname = p;
2151 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2152 return FALSE;
b99bd4ef 2153
c19d1205
ZW
2154 oldname += 6;
2155 if (*oldname == '\0')
d929913e 2156 return FALSE;
b99bd4ef 2157
21d799b5 2158 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2159 if (!old)
b99bd4ef 2160 {
c19d1205 2161 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2162 return TRUE;
b99bd4ef
NC
2163 }
2164
c19d1205
ZW
2165 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2166 the desired alias name, and p points to its end. If not, then
2167 the desired alias name is in the global original_case_string. */
2168#ifdef TC_CASE_SENSITIVE
2169 nlen = p - newname;
2170#else
2171 newname = original_case_string;
2172 nlen = strlen (newname);
2173#endif
b99bd4ef 2174
21d799b5 2175 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2176 memcpy (nbuf, newname, nlen);
2177 nbuf[nlen] = '\0';
b99bd4ef 2178
c19d1205
ZW
2179 /* Create aliases under the new name as stated; an all-lowercase
2180 version of the new name; and an all-uppercase version of the new
2181 name. */
d929913e
NC
2182 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2183 {
2184 for (p = nbuf; *p; p++)
2185 *p = TOUPPER (*p);
c19d1205 2186
d929913e
NC
2187 if (strncmp (nbuf, newname, nlen))
2188 {
2189 /* If this attempt to create an additional alias fails, do not bother
2190 trying to create the all-lower case alias. We will fail and issue
2191 a second, duplicate error message. This situation arises when the
2192 programmer does something like:
2193 foo .req r0
2194 Foo .req r1
2195 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2196 the artificial FOO alias because it has already been created by the
d929913e
NC
2197 first .req. */
2198 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2199 return TRUE;
2200 }
c19d1205 2201
d929913e
NC
2202 for (p = nbuf; *p; p++)
2203 *p = TOLOWER (*p);
c19d1205 2204
d929913e
NC
2205 if (strncmp (nbuf, newname, nlen))
2206 insert_reg_alias (nbuf, old->number, old->type);
2207 }
c19d1205 2208
d929913e 2209 return TRUE;
b99bd4ef
NC
2210}
2211
dcbf9037
JB
2212/* Create a Neon typed/indexed register alias using directives, e.g.:
2213 X .dn d5.s32[1]
2214 Y .qn 6.s16
2215 Z .dn d7
2216 T .dn Z[0]
2217 These typed registers can be used instead of the types specified after the
2218 Neon mnemonic, so long as all operands given have types. Types can also be
2219 specified directly, e.g.:
5f4273c7 2220 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2221
c921be7d 2222static bfd_boolean
dcbf9037
JB
2223create_neon_reg_alias (char *newname, char *p)
2224{
2225 enum arm_reg_type basetype;
2226 struct reg_entry *basereg;
2227 struct reg_entry mybasereg;
2228 struct neon_type ntype;
2229 struct neon_typed_alias typeinfo;
12d6b0b7 2230 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2231 int namelen;
5f4273c7 2232
dcbf9037
JB
2233 typeinfo.defined = 0;
2234 typeinfo.eltype.type = NT_invtype;
2235 typeinfo.eltype.size = -1;
2236 typeinfo.index = -1;
5f4273c7 2237
dcbf9037 2238 nameend = p;
5f4273c7 2239
dcbf9037
JB
2240 if (strncmp (p, " .dn ", 5) == 0)
2241 basetype = REG_TYPE_VFD;
2242 else if (strncmp (p, " .qn ", 5) == 0)
2243 basetype = REG_TYPE_NQ;
2244 else
c921be7d 2245 return FALSE;
5f4273c7 2246
dcbf9037 2247 p += 5;
5f4273c7 2248
dcbf9037 2249 if (*p == '\0')
c921be7d 2250 return FALSE;
5f4273c7 2251
dcbf9037
JB
2252 basereg = arm_reg_parse_multi (&p);
2253
2254 if (basereg && basereg->type != basetype)
2255 {
2256 as_bad (_("bad type for register"));
c921be7d 2257 return FALSE;
dcbf9037
JB
2258 }
2259
2260 if (basereg == NULL)
2261 {
2262 expressionS exp;
2263 /* Try parsing as an integer. */
2264 my_get_expression (&exp, &p, GE_NO_PREFIX);
2265 if (exp.X_op != O_constant)
2266 {
2267 as_bad (_("expression must be constant"));
c921be7d 2268 return FALSE;
dcbf9037
JB
2269 }
2270 basereg = &mybasereg;
2271 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2272 : exp.X_add_number;
2273 basereg->neon = 0;
2274 }
2275
2276 if (basereg->neon)
2277 typeinfo = *basereg->neon;
2278
2279 if (parse_neon_type (&ntype, &p) == SUCCESS)
2280 {
2281 /* We got a type. */
2282 if (typeinfo.defined & NTA_HASTYPE)
2283 {
2284 as_bad (_("can't redefine the type of a register alias"));
c921be7d 2285 return FALSE;
dcbf9037 2286 }
5f4273c7 2287
dcbf9037
JB
2288 typeinfo.defined |= NTA_HASTYPE;
2289 if (ntype.elems != 1)
2290 {
2291 as_bad (_("you must specify a single type only"));
c921be7d 2292 return FALSE;
dcbf9037
JB
2293 }
2294 typeinfo.eltype = ntype.el[0];
2295 }
5f4273c7 2296
dcbf9037
JB
2297 if (skip_past_char (&p, '[') == SUCCESS)
2298 {
2299 expressionS exp;
2300 /* We got a scalar index. */
5f4273c7 2301
dcbf9037
JB
2302 if (typeinfo.defined & NTA_HASINDEX)
2303 {
2304 as_bad (_("can't redefine the index of a scalar alias"));
c921be7d 2305 return FALSE;
dcbf9037 2306 }
5f4273c7 2307
dcbf9037 2308 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2309
dcbf9037
JB
2310 if (exp.X_op != O_constant)
2311 {
2312 as_bad (_("scalar index must be constant"));
c921be7d 2313 return FALSE;
dcbf9037 2314 }
5f4273c7 2315
dcbf9037
JB
2316 typeinfo.defined |= NTA_HASINDEX;
2317 typeinfo.index = exp.X_add_number;
5f4273c7 2318
dcbf9037
JB
2319 if (skip_past_char (&p, ']') == FAIL)
2320 {
2321 as_bad (_("expecting ]"));
c921be7d 2322 return FALSE;
dcbf9037
JB
2323 }
2324 }
2325
15735687
NS
2326 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2327 the desired alias name, and p points to its end. If not, then
2328 the desired alias name is in the global original_case_string. */
2329#ifdef TC_CASE_SENSITIVE
dcbf9037 2330 namelen = nameend - newname;
15735687
NS
2331#else
2332 newname = original_case_string;
2333 namelen = strlen (newname);
2334#endif
2335
21d799b5 2336 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2337 strncpy (namebuf, newname, namelen);
2338 namebuf[namelen] = '\0';
5f4273c7 2339
dcbf9037
JB
2340 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2341 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2342
dcbf9037
JB
2343 /* Insert name in all uppercase. */
2344 for (p = namebuf; *p; p++)
2345 *p = TOUPPER (*p);
5f4273c7 2346
dcbf9037
JB
2347 if (strncmp (namebuf, newname, namelen))
2348 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2349 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2350
dcbf9037
JB
2351 /* Insert name in all lowercase. */
2352 for (p = namebuf; *p; p++)
2353 *p = TOLOWER (*p);
5f4273c7 2354
dcbf9037
JB
2355 if (strncmp (namebuf, newname, namelen))
2356 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2357 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2358
c921be7d 2359 return TRUE;
dcbf9037
JB
2360}
2361
c19d1205
ZW
2362/* Should never be called, as .req goes between the alias and the
2363 register name, not at the beginning of the line. */
c921be7d 2364
b99bd4ef 2365static void
c19d1205 2366s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2367{
c19d1205
ZW
2368 as_bad (_("invalid syntax for .req directive"));
2369}
b99bd4ef 2370
dcbf9037
JB
2371static void
2372s_dn (int a ATTRIBUTE_UNUSED)
2373{
2374 as_bad (_("invalid syntax for .dn directive"));
2375}
2376
2377static void
2378s_qn (int a ATTRIBUTE_UNUSED)
2379{
2380 as_bad (_("invalid syntax for .qn directive"));
2381}
2382
c19d1205
ZW
2383/* The .unreq directive deletes an alias which was previously defined
2384 by .req. For example:
b99bd4ef 2385
c19d1205
ZW
2386 my_alias .req r11
2387 .unreq my_alias */
b99bd4ef
NC
2388
2389static void
c19d1205 2390s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2391{
c19d1205
ZW
2392 char * name;
2393 char saved_char;
b99bd4ef 2394
c19d1205
ZW
2395 name = input_line_pointer;
2396
2397 while (*input_line_pointer != 0
2398 && *input_line_pointer != ' '
2399 && *input_line_pointer != '\n')
2400 ++input_line_pointer;
2401
2402 saved_char = *input_line_pointer;
2403 *input_line_pointer = 0;
2404
2405 if (!*name)
2406 as_bad (_("invalid syntax for .unreq directive"));
2407 else
2408 {
21d799b5
NC
2409 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2410 name);
c19d1205
ZW
2411
2412 if (!reg)
2413 as_bad (_("unknown register alias '%s'"), name);
2414 else if (reg->builtin)
a1727c1a 2415 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2416 name);
2417 else
2418 {
d929913e
NC
2419 char * p;
2420 char * nbuf;
2421
db0bc284 2422 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2423 free ((char *) reg->name);
dcbf9037
JB
2424 if (reg->neon)
2425 free (reg->neon);
c19d1205 2426 free (reg);
d929913e
NC
2427
2428 /* Also locate the all upper case and all lower case versions.
2429 Do not complain if we cannot find one or the other as it
2430 was probably deleted above. */
5f4273c7 2431
d929913e
NC
2432 nbuf = strdup (name);
2433 for (p = nbuf; *p; p++)
2434 *p = TOUPPER (*p);
21d799b5 2435 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2436 if (reg)
2437 {
db0bc284 2438 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2439 free ((char *) reg->name);
2440 if (reg->neon)
2441 free (reg->neon);
2442 free (reg);
2443 }
2444
2445 for (p = nbuf; *p; p++)
2446 *p = TOLOWER (*p);
21d799b5 2447 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2448 if (reg)
2449 {
db0bc284 2450 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2451 free ((char *) reg->name);
2452 if (reg->neon)
2453 free (reg->neon);
2454 free (reg);
2455 }
2456
2457 free (nbuf);
c19d1205
ZW
2458 }
2459 }
b99bd4ef 2460
c19d1205 2461 *input_line_pointer = saved_char;
b99bd4ef
NC
2462 demand_empty_rest_of_line ();
2463}
2464
c19d1205
ZW
2465/* Directives: Instruction set selection. */
2466
2467#ifdef OBJ_ELF
2468/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2469 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2470 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2471 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2472
cd000bff
DJ
2473/* Create a new mapping symbol for the transition to STATE. */
2474
2475static void
2476make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2477{
a737bd4d 2478 symbolS * symbolP;
c19d1205
ZW
2479 const char * symname;
2480 int type;
b99bd4ef 2481
c19d1205 2482 switch (state)
b99bd4ef 2483 {
c19d1205
ZW
2484 case MAP_DATA:
2485 symname = "$d";
2486 type = BSF_NO_FLAGS;
2487 break;
2488 case MAP_ARM:
2489 symname = "$a";
2490 type = BSF_NO_FLAGS;
2491 break;
2492 case MAP_THUMB:
2493 symname = "$t";
2494 type = BSF_NO_FLAGS;
2495 break;
c19d1205
ZW
2496 default:
2497 abort ();
2498 }
2499
cd000bff 2500 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2501 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2502
2503 switch (state)
2504 {
2505 case MAP_ARM:
2506 THUMB_SET_FUNC (symbolP, 0);
2507 ARM_SET_THUMB (symbolP, 0);
2508 ARM_SET_INTERWORK (symbolP, support_interwork);
2509 break;
2510
2511 case MAP_THUMB:
2512 THUMB_SET_FUNC (symbolP, 1);
2513 ARM_SET_THUMB (symbolP, 1);
2514 ARM_SET_INTERWORK (symbolP, support_interwork);
2515 break;
2516
2517 case MAP_DATA:
2518 default:
cd000bff
DJ
2519 break;
2520 }
2521
2522 /* Save the mapping symbols for future reference. Also check that
2523 we do not place two mapping symbols at the same offset within a
2524 frag. We'll handle overlap between frags in
2de7820f
JZ
2525 check_mapping_symbols.
2526
2527 If .fill or other data filling directive generates zero sized data,
2528 the mapping symbol for the following code will have the same value
2529 as the one generated for the data filling directive. In this case,
2530 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2531 if (value == 0)
2532 {
2de7820f
JZ
2533 if (frag->tc_frag_data.first_map != NULL)
2534 {
2535 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2536 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2537 }
cd000bff
DJ
2538 frag->tc_frag_data.first_map = symbolP;
2539 }
2540 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2541 {
2542 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2543 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2544 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2545 }
cd000bff
DJ
2546 frag->tc_frag_data.last_map = symbolP;
2547}
2548
2549/* We must sometimes convert a region marked as code to data during
2550 code alignment, if an odd number of bytes have to be padded. The
2551 code mapping symbol is pushed to an aligned address. */
2552
2553static void
2554insert_data_mapping_symbol (enum mstate state,
2555 valueT value, fragS *frag, offsetT bytes)
2556{
2557 /* If there was already a mapping symbol, remove it. */
2558 if (frag->tc_frag_data.last_map != NULL
2559 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2560 {
2561 symbolS *symp = frag->tc_frag_data.last_map;
2562
2563 if (value == 0)
2564 {
2565 know (frag->tc_frag_data.first_map == symp);
2566 frag->tc_frag_data.first_map = NULL;
2567 }
2568 frag->tc_frag_data.last_map = NULL;
2569 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2570 }
cd000bff
DJ
2571
2572 make_mapping_symbol (MAP_DATA, value, frag);
2573 make_mapping_symbol (state, value + bytes, frag);
2574}
2575
2576static void mapping_state_2 (enum mstate state, int max_chars);
2577
2578/* Set the mapping state to STATE. Only call this when about to
2579 emit some STATE bytes to the file. */
2580
2581void
2582mapping_state (enum mstate state)
2583{
940b5ce0
DJ
2584 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2585
cd000bff
DJ
2586#define TRANSITION(from, to) (mapstate == (from) && state == (to))
2587
2588 if (mapstate == state)
2589 /* The mapping symbol has already been emitted.
2590 There is nothing else to do. */
2591 return;
2592 else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2593 /* This case will be evaluated later in the next else. */
2594 return;
2595 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2596 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2597 {
2598 /* Only add the symbol if the offset is > 0:
2599 if we're at the first frag, check it's size > 0;
2600 if we're not at the first frag, then for sure
2601 the offset is > 0. */
2602 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2603 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2604
2605 if (add_symbol)
2606 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2607 }
2608
2609 mapping_state_2 (state, 0);
2610#undef TRANSITION
2611}
2612
2613/* Same as mapping_state, but MAX_CHARS bytes have already been
2614 allocated. Put the mapping symbol that far back. */
2615
2616static void
2617mapping_state_2 (enum mstate state, int max_chars)
2618{
940b5ce0
DJ
2619 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2620
2621 if (!SEG_NORMAL (now_seg))
2622 return;
2623
cd000bff
DJ
2624 if (mapstate == state)
2625 /* The mapping symbol has already been emitted.
2626 There is nothing else to do. */
2627 return;
2628
cd000bff
DJ
2629 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2630 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205
ZW
2631}
2632#else
d3106081
NS
2633#define mapping_state(x) ((void)0)
2634#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2635#endif
2636
2637/* Find the real, Thumb encoded start of a Thumb function. */
2638
4343666d 2639#ifdef OBJ_COFF
c19d1205
ZW
2640static symbolS *
2641find_real_start (symbolS * symbolP)
2642{
2643 char * real_start;
2644 const char * name = S_GET_NAME (symbolP);
2645 symbolS * new_target;
2646
2647 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2648#define STUB_NAME ".real_start_of"
2649
2650 if (name == NULL)
2651 abort ();
2652
37f6032b
ZW
2653 /* The compiler may generate BL instructions to local labels because
2654 it needs to perform a branch to a far away location. These labels
2655 do not have a corresponding ".real_start_of" label. We check
2656 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2657 the ".real_start_of" convention for nonlocal branches. */
2658 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2659 return symbolP;
2660
37f6032b 2661 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2662 new_target = symbol_find (real_start);
2663
2664 if (new_target == NULL)
2665 {
bd3ba5d1 2666 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2667 new_target = symbolP;
2668 }
2669
c19d1205
ZW
2670 return new_target;
2671}
4343666d 2672#endif
c19d1205
ZW
2673
2674static void
2675opcode_select (int width)
2676{
2677 switch (width)
2678 {
2679 case 16:
2680 if (! thumb_mode)
2681 {
e74cfd16 2682 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2683 as_bad (_("selected processor does not support THUMB opcodes"));
2684
2685 thumb_mode = 1;
2686 /* No need to force the alignment, since we will have been
2687 coming from ARM mode, which is word-aligned. */
2688 record_alignment (now_seg, 1);
2689 }
c19d1205
ZW
2690 break;
2691
2692 case 32:
2693 if (thumb_mode)
2694 {
e74cfd16 2695 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2696 as_bad (_("selected processor does not support ARM opcodes"));
2697
2698 thumb_mode = 0;
2699
2700 if (!need_pass_2)
2701 frag_align (2, 0, 0);
2702
2703 record_alignment (now_seg, 1);
2704 }
c19d1205
ZW
2705 break;
2706
2707 default:
2708 as_bad (_("invalid instruction size selected (%d)"), width);
2709 }
2710}
2711
2712static void
2713s_arm (int ignore ATTRIBUTE_UNUSED)
2714{
2715 opcode_select (32);
2716 demand_empty_rest_of_line ();
2717}
2718
2719static void
2720s_thumb (int ignore ATTRIBUTE_UNUSED)
2721{
2722 opcode_select (16);
2723 demand_empty_rest_of_line ();
2724}
2725
2726static void
2727s_code (int unused ATTRIBUTE_UNUSED)
2728{
2729 int temp;
2730
2731 temp = get_absolute_expression ();
2732 switch (temp)
2733 {
2734 case 16:
2735 case 32:
2736 opcode_select (temp);
2737 break;
2738
2739 default:
2740 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2741 }
2742}
2743
2744static void
2745s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2746{
2747 /* If we are not already in thumb mode go into it, EVEN if
2748 the target processor does not support thumb instructions.
2749 This is used by gcc/config/arm/lib1funcs.asm for example
2750 to compile interworking support functions even if the
2751 target processor should not support interworking. */
2752 if (! thumb_mode)
2753 {
2754 thumb_mode = 2;
2755 record_alignment (now_seg, 1);
2756 }
2757
2758 demand_empty_rest_of_line ();
2759}
2760
2761static void
2762s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2763{
2764 s_thumb (0);
2765
2766 /* The following label is the name/address of the start of a Thumb function.
2767 We need to know this for the interworking support. */
2768 label_is_thumb_function_name = TRUE;
2769}
2770
2771/* Perform a .set directive, but also mark the alias as
2772 being a thumb function. */
2773
2774static void
2775s_thumb_set (int equiv)
2776{
2777 /* XXX the following is a duplicate of the code for s_set() in read.c
2778 We cannot just call that code as we need to get at the symbol that
2779 is created. */
2780 char * name;
2781 char delim;
2782 char * end_name;
2783 symbolS * symbolP;
2784
2785 /* Especial apologies for the random logic:
2786 This just grew, and could be parsed much more simply!
2787 Dean - in haste. */
2788 name = input_line_pointer;
2789 delim = get_symbol_end ();
2790 end_name = input_line_pointer;
2791 *end_name = delim;
2792
2793 if (*input_line_pointer != ',')
2794 {
2795 *end_name = 0;
2796 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2797 *end_name = delim;
2798 ignore_rest_of_line ();
2799 return;
2800 }
2801
2802 input_line_pointer++;
2803 *end_name = 0;
2804
2805 if (name[0] == '.' && name[1] == '\0')
2806 {
2807 /* XXX - this should not happen to .thumb_set. */
2808 abort ();
2809 }
2810
2811 if ((symbolP = symbol_find (name)) == NULL
2812 && (symbolP = md_undefined_symbol (name)) == NULL)
2813 {
2814#ifndef NO_LISTING
2815 /* When doing symbol listings, play games with dummy fragments living
2816 outside the normal fragment chain to record the file and line info
c19d1205 2817 for this symbol. */
b99bd4ef
NC
2818 if (listing & LISTING_SYMBOLS)
2819 {
2820 extern struct list_info_struct * listing_tail;
21d799b5 2821 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2822
2823 memset (dummy_frag, 0, sizeof (fragS));
2824 dummy_frag->fr_type = rs_fill;
2825 dummy_frag->line = listing_tail;
2826 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2827 dummy_frag->fr_symbol = symbolP;
2828 }
2829 else
2830#endif
2831 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2832
2833#ifdef OBJ_COFF
2834 /* "set" symbols are local unless otherwise specified. */
2835 SF_SET_LOCAL (symbolP);
2836#endif /* OBJ_COFF */
2837 } /* Make a new symbol. */
2838
2839 symbol_table_insert (symbolP);
2840
2841 * end_name = delim;
2842
2843 if (equiv
2844 && S_IS_DEFINED (symbolP)
2845 && S_GET_SEGMENT (symbolP) != reg_section)
2846 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2847
2848 pseudo_set (symbolP);
2849
2850 demand_empty_rest_of_line ();
2851
c19d1205 2852 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2853
2854 THUMB_SET_FUNC (symbolP, 1);
2855 ARM_SET_THUMB (symbolP, 1);
2856#if defined OBJ_ELF || defined OBJ_COFF
2857 ARM_SET_INTERWORK (symbolP, support_interwork);
2858#endif
2859}
2860
c19d1205 2861/* Directives: Mode selection. */
b99bd4ef 2862
c19d1205
ZW
2863/* .syntax [unified|divided] - choose the new unified syntax
2864 (same for Arm and Thumb encoding, modulo slight differences in what
2865 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2866static void
c19d1205 2867s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2868{
c19d1205
ZW
2869 char *name, delim;
2870
2871 name = input_line_pointer;
2872 delim = get_symbol_end ();
2873
2874 if (!strcasecmp (name, "unified"))
2875 unified_syntax = TRUE;
2876 else if (!strcasecmp (name, "divided"))
2877 unified_syntax = FALSE;
2878 else
2879 {
2880 as_bad (_("unrecognized syntax mode \"%s\""), name);
2881 return;
2882 }
2883 *input_line_pointer = delim;
b99bd4ef
NC
2884 demand_empty_rest_of_line ();
2885}
2886
c19d1205
ZW
2887/* Directives: sectioning and alignment. */
2888
2889/* Same as s_align_ptwo but align 0 => align 2. */
2890
b99bd4ef 2891static void
c19d1205 2892s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2893{
a737bd4d 2894 int temp;
dce323d1 2895 bfd_boolean fill_p;
c19d1205
ZW
2896 long temp_fill;
2897 long max_alignment = 15;
b99bd4ef
NC
2898
2899 temp = get_absolute_expression ();
c19d1205
ZW
2900 if (temp > max_alignment)
2901 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2902 else if (temp < 0)
b99bd4ef 2903 {
c19d1205
ZW
2904 as_bad (_("alignment negative. 0 assumed."));
2905 temp = 0;
2906 }
b99bd4ef 2907
c19d1205
ZW
2908 if (*input_line_pointer == ',')
2909 {
2910 input_line_pointer++;
2911 temp_fill = get_absolute_expression ();
dce323d1 2912 fill_p = TRUE;
b99bd4ef 2913 }
c19d1205 2914 else
dce323d1
PB
2915 {
2916 fill_p = FALSE;
2917 temp_fill = 0;
2918 }
b99bd4ef 2919
c19d1205
ZW
2920 if (!temp)
2921 temp = 2;
b99bd4ef 2922
c19d1205
ZW
2923 /* Only make a frag if we HAVE to. */
2924 if (temp && !need_pass_2)
dce323d1
PB
2925 {
2926 if (!fill_p && subseg_text_p (now_seg))
2927 frag_align_code (temp, 0);
2928 else
2929 frag_align (temp, (int) temp_fill, 0);
2930 }
c19d1205
ZW
2931 demand_empty_rest_of_line ();
2932
2933 record_alignment (now_seg, temp);
b99bd4ef
NC
2934}
2935
c19d1205
ZW
2936static void
2937s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2938{
c19d1205
ZW
2939 /* We don't support putting frags in the BSS segment, we fake it by
2940 marking in_bss, then looking at s_skip for clues. */
2941 subseg_set (bss_section, 0);
2942 demand_empty_rest_of_line ();
cd000bff
DJ
2943
2944#ifdef md_elf_section_change_hook
2945 md_elf_section_change_hook ();
2946#endif
c19d1205 2947}
b99bd4ef 2948
c19d1205
ZW
2949static void
2950s_even (int ignore ATTRIBUTE_UNUSED)
2951{
2952 /* Never make frag if expect extra pass. */
2953 if (!need_pass_2)
2954 frag_align (1, 0, 0);
b99bd4ef 2955
c19d1205 2956 record_alignment (now_seg, 1);
b99bd4ef 2957
c19d1205 2958 demand_empty_rest_of_line ();
b99bd4ef
NC
2959}
2960
c19d1205 2961/* Directives: Literal pools. */
a737bd4d 2962
c19d1205
ZW
2963static literal_pool *
2964find_literal_pool (void)
a737bd4d 2965{
c19d1205 2966 literal_pool * pool;
a737bd4d 2967
c19d1205 2968 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2969 {
c19d1205
ZW
2970 if (pool->section == now_seg
2971 && pool->sub_section == now_subseg)
2972 break;
a737bd4d
NC
2973 }
2974
c19d1205 2975 return pool;
a737bd4d
NC
2976}
2977
c19d1205
ZW
2978static literal_pool *
2979find_or_make_literal_pool (void)
a737bd4d 2980{
c19d1205
ZW
2981 /* Next literal pool ID number. */
2982 static unsigned int latest_pool_num = 1;
2983 literal_pool * pool;
a737bd4d 2984
c19d1205 2985 pool = find_literal_pool ();
a737bd4d 2986
c19d1205 2987 if (pool == NULL)
a737bd4d 2988 {
c19d1205 2989 /* Create a new pool. */
21d799b5 2990 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
2991 if (! pool)
2992 return NULL;
a737bd4d 2993
c19d1205
ZW
2994 pool->next_free_entry = 0;
2995 pool->section = now_seg;
2996 pool->sub_section = now_subseg;
2997 pool->next = list_of_pools;
2998 pool->symbol = NULL;
2999
3000 /* Add it to the list. */
3001 list_of_pools = pool;
a737bd4d 3002 }
a737bd4d 3003
c19d1205
ZW
3004 /* New pools, and emptied pools, will have a NULL symbol. */
3005 if (pool->symbol == NULL)
a737bd4d 3006 {
c19d1205
ZW
3007 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3008 (valueT) 0, &zero_address_frag);
3009 pool->id = latest_pool_num ++;
a737bd4d
NC
3010 }
3011
c19d1205
ZW
3012 /* Done. */
3013 return pool;
a737bd4d
NC
3014}
3015
c19d1205 3016/* Add the literal in the global 'inst'
5f4273c7 3017 structure to the relevant literal pool. */
b99bd4ef
NC
3018
3019static int
c19d1205 3020add_to_lit_pool (void)
b99bd4ef 3021{
c19d1205
ZW
3022 literal_pool * pool;
3023 unsigned int entry;
b99bd4ef 3024
c19d1205
ZW
3025 pool = find_or_make_literal_pool ();
3026
3027 /* Check if this literal value is already in the pool. */
3028 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3029 {
c19d1205
ZW
3030 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3031 && (inst.reloc.exp.X_op == O_constant)
3032 && (pool->literals[entry].X_add_number
3033 == inst.reloc.exp.X_add_number)
3034 && (pool->literals[entry].X_unsigned
3035 == inst.reloc.exp.X_unsigned))
3036 break;
3037
3038 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3039 && (inst.reloc.exp.X_op == O_symbol)
3040 && (pool->literals[entry].X_add_number
3041 == inst.reloc.exp.X_add_number)
3042 && (pool->literals[entry].X_add_symbol
3043 == inst.reloc.exp.X_add_symbol)
3044 && (pool->literals[entry].X_op_symbol
3045 == inst.reloc.exp.X_op_symbol))
3046 break;
b99bd4ef
NC
3047 }
3048
c19d1205
ZW
3049 /* Do we need to create a new entry? */
3050 if (entry == pool->next_free_entry)
3051 {
3052 if (entry >= MAX_LITERAL_POOL_SIZE)
3053 {
3054 inst.error = _("literal pool overflow");
3055 return FAIL;
3056 }
3057
3058 pool->literals[entry] = inst.reloc.exp;
3059 pool->next_free_entry += 1;
3060 }
b99bd4ef 3061
c19d1205
ZW
3062 inst.reloc.exp.X_op = O_symbol;
3063 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3064 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3065
c19d1205 3066 return SUCCESS;
b99bd4ef
NC
3067}
3068
c19d1205
ZW
3069/* Can't use symbol_new here, so have to create a symbol and then at
3070 a later date assign it a value. Thats what these functions do. */
e16bb312 3071
c19d1205
ZW
3072static void
3073symbol_locate (symbolS * symbolP,
3074 const char * name, /* It is copied, the caller can modify. */
3075 segT segment, /* Segment identifier (SEG_<something>). */
3076 valueT valu, /* Symbol value. */
3077 fragS * frag) /* Associated fragment. */
3078{
3079 unsigned int name_length;
3080 char * preserved_copy_of_name;
e16bb312 3081
c19d1205
ZW
3082 name_length = strlen (name) + 1; /* +1 for \0. */
3083 obstack_grow (&notes, name, name_length);
21d799b5 3084 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3085
c19d1205
ZW
3086#ifdef tc_canonicalize_symbol_name
3087 preserved_copy_of_name =
3088 tc_canonicalize_symbol_name (preserved_copy_of_name);
3089#endif
b99bd4ef 3090
c19d1205 3091 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3092
c19d1205
ZW
3093 S_SET_SEGMENT (symbolP, segment);
3094 S_SET_VALUE (symbolP, valu);
3095 symbol_clear_list_pointers (symbolP);
b99bd4ef 3096
c19d1205 3097 symbol_set_frag (symbolP, frag);
b99bd4ef 3098
c19d1205
ZW
3099 /* Link to end of symbol chain. */
3100 {
3101 extern int symbol_table_frozen;
b99bd4ef 3102
c19d1205
ZW
3103 if (symbol_table_frozen)
3104 abort ();
3105 }
b99bd4ef 3106
c19d1205 3107 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3108
c19d1205 3109 obj_symbol_new_hook (symbolP);
b99bd4ef 3110
c19d1205
ZW
3111#ifdef tc_symbol_new_hook
3112 tc_symbol_new_hook (symbolP);
3113#endif
3114
3115#ifdef DEBUG_SYMS
3116 verify_symbol_chain (symbol_rootP, symbol_lastP);
3117#endif /* DEBUG_SYMS */
b99bd4ef
NC
3118}
3119
b99bd4ef 3120
c19d1205
ZW
3121static void
3122s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3123{
c19d1205
ZW
3124 unsigned int entry;
3125 literal_pool * pool;
3126 char sym_name[20];
b99bd4ef 3127
c19d1205
ZW
3128 pool = find_literal_pool ();
3129 if (pool == NULL
3130 || pool->symbol == NULL
3131 || pool->next_free_entry == 0)
3132 return;
b99bd4ef 3133
c19d1205 3134 mapping_state (MAP_DATA);
b99bd4ef 3135
c19d1205
ZW
3136 /* Align pool as you have word accesses.
3137 Only make a frag if we have to. */
3138 if (!need_pass_2)
3139 frag_align (2, 0, 0);
b99bd4ef 3140
c19d1205 3141 record_alignment (now_seg, 2);
b99bd4ef 3142
c19d1205 3143 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3144
c19d1205
ZW
3145 symbol_locate (pool->symbol, sym_name, now_seg,
3146 (valueT) frag_now_fix (), frag_now);
3147 symbol_table_insert (pool->symbol);
b99bd4ef 3148
c19d1205 3149 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3150
c19d1205
ZW
3151#if defined OBJ_COFF || defined OBJ_ELF
3152 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3153#endif
6c43fab6 3154
c19d1205
ZW
3155 for (entry = 0; entry < pool->next_free_entry; entry ++)
3156 /* First output the expression in the instruction to the pool. */
3157 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 3158
c19d1205
ZW
3159 /* Mark the pool as empty. */
3160 pool->next_free_entry = 0;
3161 pool->symbol = NULL;
b99bd4ef
NC
3162}
3163
c19d1205
ZW
3164#ifdef OBJ_ELF
3165/* Forward declarations for functions below, in the MD interface
3166 section. */
3167static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3168static valueT create_unwind_entry (int);
3169static void start_unwind_section (const segT, int);
3170static void add_unwind_opcode (valueT, int);
3171static void flush_pending_unwind (void);
b99bd4ef 3172
c19d1205 3173/* Directives: Data. */
b99bd4ef 3174
c19d1205
ZW
3175static void
3176s_arm_elf_cons (int nbytes)
3177{
3178 expressionS exp;
b99bd4ef 3179
c19d1205
ZW
3180#ifdef md_flush_pending_output
3181 md_flush_pending_output ();
3182#endif
b99bd4ef 3183
c19d1205 3184 if (is_it_end_of_statement ())
b99bd4ef 3185 {
c19d1205
ZW
3186 demand_empty_rest_of_line ();
3187 return;
b99bd4ef
NC
3188 }
3189
c19d1205
ZW
3190#ifdef md_cons_align
3191 md_cons_align (nbytes);
3192#endif
b99bd4ef 3193
c19d1205
ZW
3194 mapping_state (MAP_DATA);
3195 do
b99bd4ef 3196 {
c19d1205
ZW
3197 int reloc;
3198 char *base = input_line_pointer;
b99bd4ef 3199
c19d1205 3200 expression (& exp);
b99bd4ef 3201
c19d1205
ZW
3202 if (exp.X_op != O_symbol)
3203 emit_expr (&exp, (unsigned int) nbytes);
3204 else
3205 {
3206 char *before_reloc = input_line_pointer;
3207 reloc = parse_reloc (&input_line_pointer);
3208 if (reloc == -1)
3209 {
3210 as_bad (_("unrecognized relocation suffix"));
3211 ignore_rest_of_line ();
3212 return;
3213 }
3214 else if (reloc == BFD_RELOC_UNUSED)
3215 emit_expr (&exp, (unsigned int) nbytes);
3216 else
3217 {
21d799b5
NC
3218 reloc_howto_type *howto = (reloc_howto_type *)
3219 bfd_reloc_type_lookup (stdoutput,
3220 (bfd_reloc_code_real_type) reloc);
c19d1205 3221 int size = bfd_get_reloc_size (howto);
b99bd4ef 3222
2fc8bdac
ZW
3223 if (reloc == BFD_RELOC_ARM_PLT32)
3224 {
3225 as_bad (_("(plt) is only valid on branch targets"));
3226 reloc = BFD_RELOC_UNUSED;
3227 size = 0;
3228 }
3229
c19d1205 3230 if (size > nbytes)
2fc8bdac 3231 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3232 howto->name, nbytes);
3233 else
3234 {
3235 /* We've parsed an expression stopping at O_symbol.
3236 But there may be more expression left now that we
3237 have parsed the relocation marker. Parse it again.
3238 XXX Surely there is a cleaner way to do this. */
3239 char *p = input_line_pointer;
3240 int offset;
21d799b5 3241 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3242 memcpy (save_buf, base, input_line_pointer - base);
3243 memmove (base + (input_line_pointer - before_reloc),
3244 base, before_reloc - base);
3245
3246 input_line_pointer = base + (input_line_pointer-before_reloc);
3247 expression (&exp);
3248 memcpy (base, save_buf, p - base);
3249
3250 offset = nbytes - size;
3251 p = frag_more ((int) nbytes);
3252 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3253 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3254 }
3255 }
3256 }
b99bd4ef 3257 }
c19d1205 3258 while (*input_line_pointer++ == ',');
b99bd4ef 3259
c19d1205
ZW
3260 /* Put terminator back into stream. */
3261 input_line_pointer --;
3262 demand_empty_rest_of_line ();
b99bd4ef
NC
3263}
3264
c921be7d
NC
3265/* Emit an expression containing a 32-bit thumb instruction.
3266 Implementation based on put_thumb32_insn. */
3267
3268static void
3269emit_thumb32_expr (expressionS * exp)
3270{
3271 expressionS exp_high = *exp;
3272
3273 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3274 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3275 exp->X_add_number &= 0xffff;
3276 emit_expr (exp, (unsigned int) THUMB_SIZE);
3277}
3278
3279/* Guess the instruction size based on the opcode. */
3280
3281static int
3282thumb_insn_size (int opcode)
3283{
3284 if ((unsigned int) opcode < 0xe800u)
3285 return 2;
3286 else if ((unsigned int) opcode >= 0xe8000000u)
3287 return 4;
3288 else
3289 return 0;
3290}
3291
3292static bfd_boolean
3293emit_insn (expressionS *exp, int nbytes)
3294{
3295 int size = 0;
3296
3297 if (exp->X_op == O_constant)
3298 {
3299 size = nbytes;
3300
3301 if (size == 0)
3302 size = thumb_insn_size (exp->X_add_number);
3303
3304 if (size != 0)
3305 {
3306 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3307 {
3308 as_bad (_(".inst.n operand too big. "\
3309 "Use .inst.w instead"));
3310 size = 0;
3311 }
3312 else
3313 {
3314 if (now_it.state == AUTOMATIC_IT_BLOCK)
3315 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3316 else
3317 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3318
3319 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3320 emit_thumb32_expr (exp);
3321 else
3322 emit_expr (exp, (unsigned int) size);
3323
3324 it_fsm_post_encode ();
3325 }
3326 }
3327 else
3328 as_bad (_("cannot determine Thumb instruction size. " \
3329 "Use .inst.n/.inst.w instead"));
3330 }
3331 else
3332 as_bad (_("constant expression required"));
3333
3334 return (size != 0);
3335}
3336
3337/* Like s_arm_elf_cons but do not use md_cons_align and
3338 set the mapping state to MAP_ARM/MAP_THUMB. */
3339
3340static void
3341s_arm_elf_inst (int nbytes)
3342{
3343 if (is_it_end_of_statement ())
3344 {
3345 demand_empty_rest_of_line ();
3346 return;
3347 }
3348
3349 /* Calling mapping_state () here will not change ARM/THUMB,
3350 but will ensure not to be in DATA state. */
3351
3352 if (thumb_mode)
3353 mapping_state (MAP_THUMB);
3354 else
3355 {
3356 if (nbytes != 0)
3357 {
3358 as_bad (_("width suffixes are invalid in ARM mode"));
3359 ignore_rest_of_line ();
3360 return;
3361 }
3362
3363 nbytes = 4;
3364
3365 mapping_state (MAP_ARM);
3366 }
3367
3368 do
3369 {
3370 expressionS exp;
3371
3372 expression (& exp);
3373
3374 if (! emit_insn (& exp, nbytes))
3375 {
3376 ignore_rest_of_line ();
3377 return;
3378 }
3379 }
3380 while (*input_line_pointer++ == ',');
3381
3382 /* Put terminator back into stream. */
3383 input_line_pointer --;
3384 demand_empty_rest_of_line ();
3385}
b99bd4ef 3386
c19d1205 3387/* Parse a .rel31 directive. */
b99bd4ef 3388
c19d1205
ZW
3389static void
3390s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3391{
3392 expressionS exp;
3393 char *p;
3394 valueT highbit;
b99bd4ef 3395
c19d1205
ZW
3396 highbit = 0;
3397 if (*input_line_pointer == '1')
3398 highbit = 0x80000000;
3399 else if (*input_line_pointer != '0')
3400 as_bad (_("expected 0 or 1"));
b99bd4ef 3401
c19d1205
ZW
3402 input_line_pointer++;
3403 if (*input_line_pointer != ',')
3404 as_bad (_("missing comma"));
3405 input_line_pointer++;
b99bd4ef 3406
c19d1205
ZW
3407#ifdef md_flush_pending_output
3408 md_flush_pending_output ();
3409#endif
b99bd4ef 3410
c19d1205
ZW
3411#ifdef md_cons_align
3412 md_cons_align (4);
3413#endif
b99bd4ef 3414
c19d1205 3415 mapping_state (MAP_DATA);
b99bd4ef 3416
c19d1205 3417 expression (&exp);
b99bd4ef 3418
c19d1205
ZW
3419 p = frag_more (4);
3420 md_number_to_chars (p, highbit, 4);
3421 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3422 BFD_RELOC_ARM_PREL31);
b99bd4ef 3423
c19d1205 3424 demand_empty_rest_of_line ();
b99bd4ef
NC
3425}
3426
c19d1205 3427/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3428
c19d1205 3429/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3430
c19d1205
ZW
3431static void
3432s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3433{
3434 demand_empty_rest_of_line ();
921e5f0a
PB
3435 if (unwind.proc_start)
3436 {
c921be7d 3437 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3438 return;
3439 }
3440
c19d1205
ZW
3441 /* Mark the start of the function. */
3442 unwind.proc_start = expr_build_dot ();
b99bd4ef 3443
c19d1205
ZW
3444 /* Reset the rest of the unwind info. */
3445 unwind.opcode_count = 0;
3446 unwind.table_entry = NULL;
3447 unwind.personality_routine = NULL;
3448 unwind.personality_index = -1;
3449 unwind.frame_size = 0;
3450 unwind.fp_offset = 0;
fdfde340 3451 unwind.fp_reg = REG_SP;
c19d1205
ZW
3452 unwind.fp_used = 0;
3453 unwind.sp_restored = 0;
3454}
b99bd4ef 3455
b99bd4ef 3456
c19d1205
ZW
3457/* Parse a handlerdata directive. Creates the exception handling table entry
3458 for the function. */
b99bd4ef 3459
c19d1205
ZW
3460static void
3461s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3462{
3463 demand_empty_rest_of_line ();
921e5f0a 3464 if (!unwind.proc_start)
c921be7d 3465 as_bad (MISSING_FNSTART);
921e5f0a 3466
c19d1205 3467 if (unwind.table_entry)
6decc662 3468 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3469
c19d1205
ZW
3470 create_unwind_entry (1);
3471}
a737bd4d 3472
c19d1205 3473/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3474
c19d1205
ZW
3475static void
3476s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3477{
3478 long where;
3479 char *ptr;
3480 valueT val;
940b5ce0 3481 unsigned int marked_pr_dependency;
f02232aa 3482
c19d1205 3483 demand_empty_rest_of_line ();
f02232aa 3484
921e5f0a
PB
3485 if (!unwind.proc_start)
3486 {
c921be7d 3487 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3488 return;
3489 }
3490
c19d1205
ZW
3491 /* Add eh table entry. */
3492 if (unwind.table_entry == NULL)
3493 val = create_unwind_entry (0);
3494 else
3495 val = 0;
f02232aa 3496
c19d1205
ZW
3497 /* Add index table entry. This is two words. */
3498 start_unwind_section (unwind.saved_seg, 1);
3499 frag_align (2, 0, 0);
3500 record_alignment (now_seg, 2);
b99bd4ef 3501
c19d1205
ZW
3502 ptr = frag_more (8);
3503 where = frag_now_fix () - 8;
f02232aa 3504
c19d1205
ZW
3505 /* Self relative offset of the function start. */
3506 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3507 BFD_RELOC_ARM_PREL31);
f02232aa 3508
c19d1205
ZW
3509 /* Indicate dependency on EHABI-defined personality routines to the
3510 linker, if it hasn't been done already. */
940b5ce0
DJ
3511 marked_pr_dependency
3512 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3513 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3514 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3515 {
5f4273c7
NC
3516 static const char *const name[] =
3517 {
3518 "__aeabi_unwind_cpp_pr0",
3519 "__aeabi_unwind_cpp_pr1",
3520 "__aeabi_unwind_cpp_pr2"
3521 };
c19d1205
ZW
3522 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3523 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3524 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3525 |= 1 << unwind.personality_index;
c19d1205 3526 }
f02232aa 3527
c19d1205
ZW
3528 if (val)
3529 /* Inline exception table entry. */
3530 md_number_to_chars (ptr + 4, val, 4);
3531 else
3532 /* Self relative offset of the table entry. */
3533 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3534 BFD_RELOC_ARM_PREL31);
f02232aa 3535
c19d1205
ZW
3536 /* Restore the original section. */
3537 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3538
3539 unwind.proc_start = NULL;
c19d1205 3540}
f02232aa 3541
f02232aa 3542
c19d1205 3543/* Parse an unwind_cantunwind directive. */
b99bd4ef 3544
c19d1205
ZW
3545static void
3546s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3547{
3548 demand_empty_rest_of_line ();
921e5f0a 3549 if (!unwind.proc_start)
c921be7d 3550 as_bad (MISSING_FNSTART);
921e5f0a 3551
c19d1205
ZW
3552 if (unwind.personality_routine || unwind.personality_index != -1)
3553 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3554
c19d1205
ZW
3555 unwind.personality_index = -2;
3556}
b99bd4ef 3557
b99bd4ef 3558
c19d1205 3559/* Parse a personalityindex directive. */
b99bd4ef 3560
c19d1205
ZW
3561static void
3562s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3563{
3564 expressionS exp;
b99bd4ef 3565
921e5f0a 3566 if (!unwind.proc_start)
c921be7d 3567 as_bad (MISSING_FNSTART);
921e5f0a 3568
c19d1205
ZW
3569 if (unwind.personality_routine || unwind.personality_index != -1)
3570 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3571
c19d1205 3572 expression (&exp);
b99bd4ef 3573
c19d1205
ZW
3574 if (exp.X_op != O_constant
3575 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3576 {
c19d1205
ZW
3577 as_bad (_("bad personality routine number"));
3578 ignore_rest_of_line ();
3579 return;
b99bd4ef
NC
3580 }
3581
c19d1205 3582 unwind.personality_index = exp.X_add_number;
b99bd4ef 3583
c19d1205
ZW
3584 demand_empty_rest_of_line ();
3585}
e16bb312 3586
e16bb312 3587
c19d1205 3588/* Parse a personality directive. */
e16bb312 3589
c19d1205
ZW
3590static void
3591s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3592{
3593 char *name, *p, c;
a737bd4d 3594
921e5f0a 3595 if (!unwind.proc_start)
c921be7d 3596 as_bad (MISSING_FNSTART);
921e5f0a 3597
c19d1205
ZW
3598 if (unwind.personality_routine || unwind.personality_index != -1)
3599 as_bad (_("duplicate .personality directive"));
a737bd4d 3600
c19d1205
ZW
3601 name = input_line_pointer;
3602 c = get_symbol_end ();
3603 p = input_line_pointer;
3604 unwind.personality_routine = symbol_find_or_make (name);
3605 *p = c;
3606 demand_empty_rest_of_line ();
3607}
e16bb312 3608
e16bb312 3609
c19d1205 3610/* Parse a directive saving core registers. */
e16bb312 3611
c19d1205
ZW
3612static void
3613s_arm_unwind_save_core (void)
e16bb312 3614{
c19d1205
ZW
3615 valueT op;
3616 long range;
3617 int n;
e16bb312 3618
c19d1205
ZW
3619 range = parse_reg_list (&input_line_pointer);
3620 if (range == FAIL)
e16bb312 3621 {
c19d1205
ZW
3622 as_bad (_("expected register list"));
3623 ignore_rest_of_line ();
3624 return;
3625 }
e16bb312 3626
c19d1205 3627 demand_empty_rest_of_line ();
e16bb312 3628
c19d1205
ZW
3629 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3630 into .unwind_save {..., sp...}. We aren't bothered about the value of
3631 ip because it is clobbered by calls. */
3632 if (unwind.sp_restored && unwind.fp_reg == 12
3633 && (range & 0x3000) == 0x1000)
3634 {
3635 unwind.opcode_count--;
3636 unwind.sp_restored = 0;
3637 range = (range | 0x2000) & ~0x1000;
3638 unwind.pending_offset = 0;
3639 }
e16bb312 3640
01ae4198
DJ
3641 /* Pop r4-r15. */
3642 if (range & 0xfff0)
c19d1205 3643 {
01ae4198
DJ
3644 /* See if we can use the short opcodes. These pop a block of up to 8
3645 registers starting with r4, plus maybe r14. */
3646 for (n = 0; n < 8; n++)
3647 {
3648 /* Break at the first non-saved register. */
3649 if ((range & (1 << (n + 4))) == 0)
3650 break;
3651 }
3652 /* See if there are any other bits set. */
3653 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3654 {
3655 /* Use the long form. */
3656 op = 0x8000 | ((range >> 4) & 0xfff);
3657 add_unwind_opcode (op, 2);
3658 }
0dd132b6 3659 else
01ae4198
DJ
3660 {
3661 /* Use the short form. */
3662 if (range & 0x4000)
3663 op = 0xa8; /* Pop r14. */
3664 else
3665 op = 0xa0; /* Do not pop r14. */
3666 op |= (n - 1);
3667 add_unwind_opcode (op, 1);
3668 }
c19d1205 3669 }
0dd132b6 3670
c19d1205
ZW
3671 /* Pop r0-r3. */
3672 if (range & 0xf)
3673 {
3674 op = 0xb100 | (range & 0xf);
3675 add_unwind_opcode (op, 2);
0dd132b6
NC
3676 }
3677
c19d1205
ZW
3678 /* Record the number of bytes pushed. */
3679 for (n = 0; n < 16; n++)
3680 {
3681 if (range & (1 << n))
3682 unwind.frame_size += 4;
3683 }
0dd132b6
NC
3684}
3685
c19d1205
ZW
3686
3687/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3688
3689static void
c19d1205 3690s_arm_unwind_save_fpa (int reg)
b99bd4ef 3691{
c19d1205
ZW
3692 expressionS exp;
3693 int num_regs;
3694 valueT op;
b99bd4ef 3695
c19d1205
ZW
3696 /* Get Number of registers to transfer. */
3697 if (skip_past_comma (&input_line_pointer) != FAIL)
3698 expression (&exp);
3699 else
3700 exp.X_op = O_illegal;
b99bd4ef 3701
c19d1205 3702 if (exp.X_op != O_constant)
b99bd4ef 3703 {
c19d1205
ZW
3704 as_bad (_("expected , <constant>"));
3705 ignore_rest_of_line ();
b99bd4ef
NC
3706 return;
3707 }
3708
c19d1205
ZW
3709 num_regs = exp.X_add_number;
3710
3711 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3712 {
c19d1205
ZW
3713 as_bad (_("number of registers must be in the range [1:4]"));
3714 ignore_rest_of_line ();
b99bd4ef
NC
3715 return;
3716 }
3717
c19d1205 3718 demand_empty_rest_of_line ();
b99bd4ef 3719
c19d1205
ZW
3720 if (reg == 4)
3721 {
3722 /* Short form. */
3723 op = 0xb4 | (num_regs - 1);
3724 add_unwind_opcode (op, 1);
3725 }
b99bd4ef
NC
3726 else
3727 {
c19d1205
ZW
3728 /* Long form. */
3729 op = 0xc800 | (reg << 4) | (num_regs - 1);
3730 add_unwind_opcode (op, 2);
b99bd4ef 3731 }
c19d1205 3732 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3733}
3734
c19d1205 3735
fa073d69
MS
3736/* Parse a directive saving VFP registers for ARMv6 and above. */
3737
3738static void
3739s_arm_unwind_save_vfp_armv6 (void)
3740{
3741 int count;
3742 unsigned int start;
3743 valueT op;
3744 int num_vfpv3_regs = 0;
3745 int num_regs_below_16;
3746
3747 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3748 if (count == FAIL)
3749 {
3750 as_bad (_("expected register list"));
3751 ignore_rest_of_line ();
3752 return;
3753 }
3754
3755 demand_empty_rest_of_line ();
3756
3757 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3758 than FSTMX/FLDMX-style ones). */
3759
3760 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3761 if (start >= 16)
3762 num_vfpv3_regs = count;
3763 else if (start + count > 16)
3764 num_vfpv3_regs = start + count - 16;
3765
3766 if (num_vfpv3_regs > 0)
3767 {
3768 int start_offset = start > 16 ? start - 16 : 0;
3769 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3770 add_unwind_opcode (op, 2);
3771 }
3772
3773 /* Generate opcode for registers numbered in the range 0 .. 15. */
3774 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3775 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3776 if (num_regs_below_16 > 0)
3777 {
3778 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3779 add_unwind_opcode (op, 2);
3780 }
3781
3782 unwind.frame_size += count * 8;
3783}
3784
3785
3786/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3787
3788static void
c19d1205 3789s_arm_unwind_save_vfp (void)
b99bd4ef 3790{
c19d1205 3791 int count;
ca3f61f7 3792 unsigned int reg;
c19d1205 3793 valueT op;
b99bd4ef 3794
5287ad62 3795 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3796 if (count == FAIL)
b99bd4ef 3797 {
c19d1205
ZW
3798 as_bad (_("expected register list"));
3799 ignore_rest_of_line ();
b99bd4ef
NC
3800 return;
3801 }
3802
c19d1205 3803 demand_empty_rest_of_line ();
b99bd4ef 3804
c19d1205 3805 if (reg == 8)
b99bd4ef 3806 {
c19d1205
ZW
3807 /* Short form. */
3808 op = 0xb8 | (count - 1);
3809 add_unwind_opcode (op, 1);
b99bd4ef 3810 }
c19d1205 3811 else
b99bd4ef 3812 {
c19d1205
ZW
3813 /* Long form. */
3814 op = 0xb300 | (reg << 4) | (count - 1);
3815 add_unwind_opcode (op, 2);
b99bd4ef 3816 }
c19d1205
ZW
3817 unwind.frame_size += count * 8 + 4;
3818}
b99bd4ef 3819
b99bd4ef 3820
c19d1205
ZW
3821/* Parse a directive saving iWMMXt data registers. */
3822
3823static void
3824s_arm_unwind_save_mmxwr (void)
3825{
3826 int reg;
3827 int hi_reg;
3828 int i;
3829 unsigned mask = 0;
3830 valueT op;
b99bd4ef 3831
c19d1205
ZW
3832 if (*input_line_pointer == '{')
3833 input_line_pointer++;
b99bd4ef 3834
c19d1205 3835 do
b99bd4ef 3836 {
dcbf9037 3837 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3838
c19d1205 3839 if (reg == FAIL)
b99bd4ef 3840 {
9b7132d3 3841 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3842 goto error;
b99bd4ef
NC
3843 }
3844
c19d1205
ZW
3845 if (mask >> reg)
3846 as_tsktsk (_("register list not in ascending order"));
3847 mask |= 1 << reg;
b99bd4ef 3848
c19d1205
ZW
3849 if (*input_line_pointer == '-')
3850 {
3851 input_line_pointer++;
dcbf9037 3852 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3853 if (hi_reg == FAIL)
3854 {
9b7132d3 3855 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3856 goto error;
3857 }
3858 else if (reg >= hi_reg)
3859 {
3860 as_bad (_("bad register range"));
3861 goto error;
3862 }
3863 for (; reg < hi_reg; reg++)
3864 mask |= 1 << reg;
3865 }
3866 }
3867 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3868
c19d1205
ZW
3869 if (*input_line_pointer == '}')
3870 input_line_pointer++;
b99bd4ef 3871
c19d1205 3872 demand_empty_rest_of_line ();
b99bd4ef 3873
708587a4 3874 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3875 the list. */
3876 flush_pending_unwind ();
b99bd4ef 3877
c19d1205 3878 for (i = 0; i < 16; i++)
b99bd4ef 3879 {
c19d1205
ZW
3880 if (mask & (1 << i))
3881 unwind.frame_size += 8;
b99bd4ef
NC
3882 }
3883
c19d1205
ZW
3884 /* Attempt to combine with a previous opcode. We do this because gcc
3885 likes to output separate unwind directives for a single block of
3886 registers. */
3887 if (unwind.opcode_count > 0)
b99bd4ef 3888 {
c19d1205
ZW
3889 i = unwind.opcodes[unwind.opcode_count - 1];
3890 if ((i & 0xf8) == 0xc0)
3891 {
3892 i &= 7;
3893 /* Only merge if the blocks are contiguous. */
3894 if (i < 6)
3895 {
3896 if ((mask & 0xfe00) == (1 << 9))
3897 {
3898 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3899 unwind.opcode_count--;
3900 }
3901 }
3902 else if (i == 6 && unwind.opcode_count >= 2)
3903 {
3904 i = unwind.opcodes[unwind.opcode_count - 2];
3905 reg = i >> 4;
3906 i &= 0xf;
b99bd4ef 3907
c19d1205
ZW
3908 op = 0xffff << (reg - 1);
3909 if (reg > 0
87a1fd79 3910 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3911 {
3912 op = (1 << (reg + i + 1)) - 1;
3913 op &= ~((1 << reg) - 1);
3914 mask |= op;
3915 unwind.opcode_count -= 2;
3916 }
3917 }
3918 }
b99bd4ef
NC
3919 }
3920
c19d1205
ZW
3921 hi_reg = 15;
3922 /* We want to generate opcodes in the order the registers have been
3923 saved, ie. descending order. */
3924 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3925 {
c19d1205
ZW
3926 /* Save registers in blocks. */
3927 if (reg < 0
3928 || !(mask & (1 << reg)))
3929 {
3930 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3931 preceding block. */
c19d1205
ZW
3932 if (reg != hi_reg)
3933 {
3934 if (reg == 9)
3935 {
3936 /* Short form. */
3937 op = 0xc0 | (hi_reg - 10);
3938 add_unwind_opcode (op, 1);
3939 }
3940 else
3941 {
3942 /* Long form. */
3943 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3944 add_unwind_opcode (op, 2);
3945 }
3946 }
3947 hi_reg = reg - 1;
3948 }
b99bd4ef
NC
3949 }
3950
c19d1205
ZW
3951 return;
3952error:
3953 ignore_rest_of_line ();
b99bd4ef
NC
3954}
3955
3956static void
c19d1205 3957s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3958{
c19d1205
ZW
3959 int reg;
3960 int hi_reg;
3961 unsigned mask = 0;
3962 valueT op;
b99bd4ef 3963
c19d1205
ZW
3964 if (*input_line_pointer == '{')
3965 input_line_pointer++;
b99bd4ef 3966
c19d1205 3967 do
b99bd4ef 3968 {
dcbf9037 3969 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3970
c19d1205
ZW
3971 if (reg == FAIL)
3972 {
9b7132d3 3973 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3974 goto error;
3975 }
b99bd4ef 3976
c19d1205
ZW
3977 reg -= 8;
3978 if (mask >> reg)
3979 as_tsktsk (_("register list not in ascending order"));
3980 mask |= 1 << reg;
b99bd4ef 3981
c19d1205
ZW
3982 if (*input_line_pointer == '-')
3983 {
3984 input_line_pointer++;
dcbf9037 3985 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3986 if (hi_reg == FAIL)
3987 {
9b7132d3 3988 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3989 goto error;
3990 }
3991 else if (reg >= hi_reg)
3992 {
3993 as_bad (_("bad register range"));
3994 goto error;
3995 }
3996 for (; reg < hi_reg; reg++)
3997 mask |= 1 << reg;
3998 }
b99bd4ef 3999 }
c19d1205 4000 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4001
c19d1205
ZW
4002 if (*input_line_pointer == '}')
4003 input_line_pointer++;
b99bd4ef 4004
c19d1205
ZW
4005 demand_empty_rest_of_line ();
4006
708587a4 4007 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4008 the list. */
4009 flush_pending_unwind ();
b99bd4ef 4010
c19d1205 4011 for (reg = 0; reg < 16; reg++)
b99bd4ef 4012 {
c19d1205
ZW
4013 if (mask & (1 << reg))
4014 unwind.frame_size += 4;
b99bd4ef 4015 }
c19d1205
ZW
4016 op = 0xc700 | mask;
4017 add_unwind_opcode (op, 2);
4018 return;
4019error:
4020 ignore_rest_of_line ();
b99bd4ef
NC
4021}
4022
c19d1205 4023
fa073d69
MS
4024/* Parse an unwind_save directive.
4025 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4026
b99bd4ef 4027static void
fa073d69 4028s_arm_unwind_save (int arch_v6)
b99bd4ef 4029{
c19d1205
ZW
4030 char *peek;
4031 struct reg_entry *reg;
4032 bfd_boolean had_brace = FALSE;
b99bd4ef 4033
921e5f0a 4034 if (!unwind.proc_start)
c921be7d 4035 as_bad (MISSING_FNSTART);
921e5f0a 4036
c19d1205
ZW
4037 /* Figure out what sort of save we have. */
4038 peek = input_line_pointer;
b99bd4ef 4039
c19d1205 4040 if (*peek == '{')
b99bd4ef 4041 {
c19d1205
ZW
4042 had_brace = TRUE;
4043 peek++;
b99bd4ef
NC
4044 }
4045
c19d1205 4046 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4047
c19d1205 4048 if (!reg)
b99bd4ef 4049 {
c19d1205
ZW
4050 as_bad (_("register expected"));
4051 ignore_rest_of_line ();
b99bd4ef
NC
4052 return;
4053 }
4054
c19d1205 4055 switch (reg->type)
b99bd4ef 4056 {
c19d1205
ZW
4057 case REG_TYPE_FN:
4058 if (had_brace)
4059 {
4060 as_bad (_("FPA .unwind_save does not take a register list"));
4061 ignore_rest_of_line ();
4062 return;
4063 }
93ac2687 4064 input_line_pointer = peek;
c19d1205 4065 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4066 return;
c19d1205
ZW
4067
4068 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
4069 case REG_TYPE_VFD:
4070 if (arch_v6)
4071 s_arm_unwind_save_vfp_armv6 ();
4072 else
4073 s_arm_unwind_save_vfp ();
4074 return;
c19d1205
ZW
4075 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4076 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4077
4078 default:
4079 as_bad (_(".unwind_save does not support this kind of register"));
4080 ignore_rest_of_line ();
b99bd4ef 4081 }
c19d1205 4082}
b99bd4ef 4083
b99bd4ef 4084
c19d1205
ZW
4085/* Parse an unwind_movsp directive. */
4086
4087static void
4088s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4089{
4090 int reg;
4091 valueT op;
4fa3602b 4092 int offset;
c19d1205 4093
921e5f0a 4094 if (!unwind.proc_start)
c921be7d 4095 as_bad (MISSING_FNSTART);
921e5f0a 4096
dcbf9037 4097 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4098 if (reg == FAIL)
b99bd4ef 4099 {
9b7132d3 4100 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4101 ignore_rest_of_line ();
b99bd4ef
NC
4102 return;
4103 }
4fa3602b
PB
4104
4105 /* Optional constant. */
4106 if (skip_past_comma (&input_line_pointer) != FAIL)
4107 {
4108 if (immediate_for_directive (&offset) == FAIL)
4109 return;
4110 }
4111 else
4112 offset = 0;
4113
c19d1205 4114 demand_empty_rest_of_line ();
b99bd4ef 4115
c19d1205 4116 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4117 {
c19d1205 4118 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4119 return;
4120 }
4121
c19d1205
ZW
4122 if (unwind.fp_reg != REG_SP)
4123 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4124
c19d1205
ZW
4125 /* Generate opcode to restore the value. */
4126 op = 0x90 | reg;
4127 add_unwind_opcode (op, 1);
4128
4129 /* Record the information for later. */
4130 unwind.fp_reg = reg;
4fa3602b 4131 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4132 unwind.sp_restored = 1;
b05fe5cf
ZW
4133}
4134
c19d1205
ZW
4135/* Parse an unwind_pad directive. */
4136
b05fe5cf 4137static void
c19d1205 4138s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4139{
c19d1205 4140 int offset;
b05fe5cf 4141
921e5f0a 4142 if (!unwind.proc_start)
c921be7d 4143 as_bad (MISSING_FNSTART);
921e5f0a 4144
c19d1205
ZW
4145 if (immediate_for_directive (&offset) == FAIL)
4146 return;
b99bd4ef 4147
c19d1205
ZW
4148 if (offset & 3)
4149 {
4150 as_bad (_("stack increment must be multiple of 4"));
4151 ignore_rest_of_line ();
4152 return;
4153 }
b99bd4ef 4154
c19d1205
ZW
4155 /* Don't generate any opcodes, just record the details for later. */
4156 unwind.frame_size += offset;
4157 unwind.pending_offset += offset;
4158
4159 demand_empty_rest_of_line ();
4160}
4161
4162/* Parse an unwind_setfp directive. */
4163
4164static void
4165s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4166{
c19d1205
ZW
4167 int sp_reg;
4168 int fp_reg;
4169 int offset;
4170
921e5f0a 4171 if (!unwind.proc_start)
c921be7d 4172 as_bad (MISSING_FNSTART);
921e5f0a 4173
dcbf9037 4174 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4175 if (skip_past_comma (&input_line_pointer) == FAIL)
4176 sp_reg = FAIL;
4177 else
dcbf9037 4178 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4179
c19d1205
ZW
4180 if (fp_reg == FAIL || sp_reg == FAIL)
4181 {
4182 as_bad (_("expected <reg>, <reg>"));
4183 ignore_rest_of_line ();
4184 return;
4185 }
b99bd4ef 4186
c19d1205
ZW
4187 /* Optional constant. */
4188 if (skip_past_comma (&input_line_pointer) != FAIL)
4189 {
4190 if (immediate_for_directive (&offset) == FAIL)
4191 return;
4192 }
4193 else
4194 offset = 0;
a737bd4d 4195
c19d1205 4196 demand_empty_rest_of_line ();
a737bd4d 4197
fdfde340 4198 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4199 {
c19d1205
ZW
4200 as_bad (_("register must be either sp or set by a previous"
4201 "unwind_movsp directive"));
4202 return;
a737bd4d
NC
4203 }
4204
c19d1205
ZW
4205 /* Don't generate any opcodes, just record the information for later. */
4206 unwind.fp_reg = fp_reg;
4207 unwind.fp_used = 1;
fdfde340 4208 if (sp_reg == REG_SP)
c19d1205
ZW
4209 unwind.fp_offset = unwind.frame_size - offset;
4210 else
4211 unwind.fp_offset -= offset;
a737bd4d
NC
4212}
4213
c19d1205
ZW
4214/* Parse an unwind_raw directive. */
4215
4216static void
4217s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4218{
c19d1205 4219 expressionS exp;
708587a4 4220 /* This is an arbitrary limit. */
c19d1205
ZW
4221 unsigned char op[16];
4222 int count;
a737bd4d 4223
921e5f0a 4224 if (!unwind.proc_start)
c921be7d 4225 as_bad (MISSING_FNSTART);
921e5f0a 4226
c19d1205
ZW
4227 expression (&exp);
4228 if (exp.X_op == O_constant
4229 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4230 {
c19d1205
ZW
4231 unwind.frame_size += exp.X_add_number;
4232 expression (&exp);
4233 }
4234 else
4235 exp.X_op = O_illegal;
a737bd4d 4236
c19d1205
ZW
4237 if (exp.X_op != O_constant)
4238 {
4239 as_bad (_("expected <offset>, <opcode>"));
4240 ignore_rest_of_line ();
4241 return;
4242 }
a737bd4d 4243
c19d1205 4244 count = 0;
a737bd4d 4245
c19d1205
ZW
4246 /* Parse the opcode. */
4247 for (;;)
4248 {
4249 if (count >= 16)
4250 {
4251 as_bad (_("unwind opcode too long"));
4252 ignore_rest_of_line ();
a737bd4d 4253 }
c19d1205 4254 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4255 {
c19d1205
ZW
4256 as_bad (_("invalid unwind opcode"));
4257 ignore_rest_of_line ();
4258 return;
a737bd4d 4259 }
c19d1205 4260 op[count++] = exp.X_add_number;
a737bd4d 4261
c19d1205
ZW
4262 /* Parse the next byte. */
4263 if (skip_past_comma (&input_line_pointer) == FAIL)
4264 break;
a737bd4d 4265
c19d1205
ZW
4266 expression (&exp);
4267 }
b99bd4ef 4268
c19d1205
ZW
4269 /* Add the opcode bytes in reverse order. */
4270 while (count--)
4271 add_unwind_opcode (op[count], 1);
b99bd4ef 4272
c19d1205 4273 demand_empty_rest_of_line ();
b99bd4ef 4274}
ee065d83
PB
4275
4276
4277/* Parse a .eabi_attribute directive. */
4278
4279static void
4280s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4281{
ee3c0378
AS
4282 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4283
4284 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4285 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4286}
4287
0855e32b
NS
4288/* Emit a tls fix for the symbol. */
4289
4290static void
4291s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4292{
4293 char *p;
4294 expressionS exp;
4295#ifdef md_flush_pending_output
4296 md_flush_pending_output ();
4297#endif
4298
4299#ifdef md_cons_align
4300 md_cons_align (4);
4301#endif
4302
4303 /* Since we're just labelling the code, there's no need to define a
4304 mapping symbol. */
4305 expression (&exp);
4306 p = obstack_next_free (&frchain_now->frch_obstack);
4307 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4308 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4309 : BFD_RELOC_ARM_TLS_DESCSEQ);
4310}
cdf9ccec 4311#endif /* OBJ_ELF */
0855e32b 4312
ee065d83 4313static void s_arm_arch (int);
7a1d4c38 4314static void s_arm_object_arch (int);
ee065d83
PB
4315static void s_arm_cpu (int);
4316static void s_arm_fpu (int);
69133863 4317static void s_arm_arch_extension (int);
b99bd4ef 4318
f0927246
NC
4319#ifdef TE_PE
4320
4321static void
5f4273c7 4322pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4323{
4324 expressionS exp;
4325
4326 do
4327 {
4328 expression (&exp);
4329 if (exp.X_op == O_symbol)
4330 exp.X_op = O_secrel;
4331
4332 emit_expr (&exp, 4);
4333 }
4334 while (*input_line_pointer++ == ',');
4335
4336 input_line_pointer--;
4337 demand_empty_rest_of_line ();
4338}
4339#endif /* TE_PE */
4340
c19d1205
ZW
4341/* This table describes all the machine specific pseudo-ops the assembler
4342 has to support. The fields are:
4343 pseudo-op name without dot
4344 function to call to execute this pseudo-op
4345 Integer arg to pass to the function. */
b99bd4ef 4346
c19d1205 4347const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4348{
c19d1205
ZW
4349 /* Never called because '.req' does not start a line. */
4350 { "req", s_req, 0 },
dcbf9037
JB
4351 /* Following two are likewise never called. */
4352 { "dn", s_dn, 0 },
4353 { "qn", s_qn, 0 },
c19d1205
ZW
4354 { "unreq", s_unreq, 0 },
4355 { "bss", s_bss, 0 },
4356 { "align", s_align, 0 },
4357 { "arm", s_arm, 0 },
4358 { "thumb", s_thumb, 0 },
4359 { "code", s_code, 0 },
4360 { "force_thumb", s_force_thumb, 0 },
4361 { "thumb_func", s_thumb_func, 0 },
4362 { "thumb_set", s_thumb_set, 0 },
4363 { "even", s_even, 0 },
4364 { "ltorg", s_ltorg, 0 },
4365 { "pool", s_ltorg, 0 },
4366 { "syntax", s_syntax, 0 },
8463be01
PB
4367 { "cpu", s_arm_cpu, 0 },
4368 { "arch", s_arm_arch, 0 },
7a1d4c38 4369 { "object_arch", s_arm_object_arch, 0 },
8463be01 4370 { "fpu", s_arm_fpu, 0 },
69133863 4371 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4372#ifdef OBJ_ELF
c921be7d
NC
4373 { "word", s_arm_elf_cons, 4 },
4374 { "long", s_arm_elf_cons, 4 },
4375 { "inst.n", s_arm_elf_inst, 2 },
4376 { "inst.w", s_arm_elf_inst, 4 },
4377 { "inst", s_arm_elf_inst, 0 },
4378 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4379 { "fnstart", s_arm_unwind_fnstart, 0 },
4380 { "fnend", s_arm_unwind_fnend, 0 },
4381 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4382 { "personality", s_arm_unwind_personality, 0 },
4383 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4384 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4385 { "save", s_arm_unwind_save, 0 },
fa073d69 4386 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4387 { "movsp", s_arm_unwind_movsp, 0 },
4388 { "pad", s_arm_unwind_pad, 0 },
4389 { "setfp", s_arm_unwind_setfp, 0 },
4390 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4391 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4392 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4393#else
4394 { "word", cons, 4},
f0927246
NC
4395
4396 /* These are used for dwarf. */
4397 {"2byte", cons, 2},
4398 {"4byte", cons, 4},
4399 {"8byte", cons, 8},
4400 /* These are used for dwarf2. */
4401 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4402 { "loc", dwarf2_directive_loc, 0 },
4403 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4404#endif
4405 { "extend", float_cons, 'x' },
4406 { "ldouble", float_cons, 'x' },
4407 { "packed", float_cons, 'p' },
f0927246
NC
4408#ifdef TE_PE
4409 {"secrel32", pe_directive_secrel, 0},
4410#endif
c19d1205
ZW
4411 { 0, 0, 0 }
4412};
4413\f
4414/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4415
c19d1205
ZW
4416/* Generic immediate-value read function for use in insn parsing.
4417 STR points to the beginning of the immediate (the leading #);
4418 VAL receives the value; if the value is outside [MIN, MAX]
4419 issue an error. PREFIX_OPT is true if the immediate prefix is
4420 optional. */
b99bd4ef 4421
c19d1205
ZW
4422static int
4423parse_immediate (char **str, int *val, int min, int max,
4424 bfd_boolean prefix_opt)
4425{
4426 expressionS exp;
4427 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4428 if (exp.X_op != O_constant)
b99bd4ef 4429 {
c19d1205
ZW
4430 inst.error = _("constant expression required");
4431 return FAIL;
4432 }
b99bd4ef 4433
c19d1205
ZW
4434 if (exp.X_add_number < min || exp.X_add_number > max)
4435 {
4436 inst.error = _("immediate value out of range");
4437 return FAIL;
4438 }
b99bd4ef 4439
c19d1205
ZW
4440 *val = exp.X_add_number;
4441 return SUCCESS;
4442}
b99bd4ef 4443
5287ad62 4444/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4445 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4446 instructions. Puts the result directly in inst.operands[i]. */
4447
4448static int
4449parse_big_immediate (char **str, int i)
4450{
4451 expressionS exp;
4452 char *ptr = *str;
4453
4454 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4455
4456 if (exp.X_op == O_constant)
036dc3f7
PB
4457 {
4458 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4459 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4460 O_constant. We have to be careful not to break compilation for
4461 32-bit X_add_number, though. */
58ad575f 4462 if ((exp.X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7
PB
4463 {
4464 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4465 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4466 inst.operands[i].regisimm = 1;
4467 }
4468 }
5287ad62 4469 else if (exp.X_op == O_big
95b75c01 4470 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
5287ad62
JB
4471 {
4472 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4473
5287ad62
JB
4474 /* Bignums have their least significant bits in
4475 generic_bignum[0]. Make sure we put 32 bits in imm and
4476 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4477 gas_assert (parts != 0);
95b75c01
NC
4478
4479 /* Make sure that the number is not too big.
4480 PR 11972: Bignums can now be sign-extended to the
4481 size of a .octa so check that the out of range bits
4482 are all zero or all one. */
4483 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4484 {
4485 LITTLENUM_TYPE m = -1;
4486
4487 if (generic_bignum[parts * 2] != 0
4488 && generic_bignum[parts * 2] != m)
4489 return FAIL;
4490
4491 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4492 if (generic_bignum[j] != generic_bignum[j-1])
4493 return FAIL;
4494 }
4495
5287ad62
JB
4496 inst.operands[i].imm = 0;
4497 for (j = 0; j < parts; j++, idx++)
4498 inst.operands[i].imm |= generic_bignum[idx]
4499 << (LITTLENUM_NUMBER_OF_BITS * j);
4500 inst.operands[i].reg = 0;
4501 for (j = 0; j < parts; j++, idx++)
4502 inst.operands[i].reg |= generic_bignum[idx]
4503 << (LITTLENUM_NUMBER_OF_BITS * j);
4504 inst.operands[i].regisimm = 1;
4505 }
4506 else
4507 return FAIL;
5f4273c7 4508
5287ad62
JB
4509 *str = ptr;
4510
4511 return SUCCESS;
4512}
4513
c19d1205
ZW
4514/* Returns the pseudo-register number of an FPA immediate constant,
4515 or FAIL if there isn't a valid constant here. */
b99bd4ef 4516
c19d1205
ZW
4517static int
4518parse_fpa_immediate (char ** str)
4519{
4520 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4521 char * save_in;
4522 expressionS exp;
4523 int i;
4524 int j;
b99bd4ef 4525
c19d1205
ZW
4526 /* First try and match exact strings, this is to guarantee
4527 that some formats will work even for cross assembly. */
b99bd4ef 4528
c19d1205
ZW
4529 for (i = 0; fp_const[i]; i++)
4530 {
4531 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4532 {
c19d1205 4533 char *start = *str;
b99bd4ef 4534
c19d1205
ZW
4535 *str += strlen (fp_const[i]);
4536 if (is_end_of_line[(unsigned char) **str])
4537 return i + 8;
4538 *str = start;
4539 }
4540 }
b99bd4ef 4541
c19d1205
ZW
4542 /* Just because we didn't get a match doesn't mean that the constant
4543 isn't valid, just that it is in a format that we don't
4544 automatically recognize. Try parsing it with the standard
4545 expression routines. */
b99bd4ef 4546
c19d1205 4547 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4548
c19d1205
ZW
4549 /* Look for a raw floating point number. */
4550 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4551 && is_end_of_line[(unsigned char) *save_in])
4552 {
4553 for (i = 0; i < NUM_FLOAT_VALS; i++)
4554 {
4555 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4556 {
c19d1205
ZW
4557 if (words[j] != fp_values[i][j])
4558 break;
b99bd4ef
NC
4559 }
4560
c19d1205 4561 if (j == MAX_LITTLENUMS)
b99bd4ef 4562 {
c19d1205
ZW
4563 *str = save_in;
4564 return i + 8;
b99bd4ef
NC
4565 }
4566 }
4567 }
b99bd4ef 4568
c19d1205
ZW
4569 /* Try and parse a more complex expression, this will probably fail
4570 unless the code uses a floating point prefix (eg "0f"). */
4571 save_in = input_line_pointer;
4572 input_line_pointer = *str;
4573 if (expression (&exp) == absolute_section
4574 && exp.X_op == O_big
4575 && exp.X_add_number < 0)
4576 {
4577 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4578 Ditto for 15. */
4579 if (gen_to_words (words, 5, (long) 15) == 0)
4580 {
4581 for (i = 0; i < NUM_FLOAT_VALS; i++)
4582 {
4583 for (j = 0; j < MAX_LITTLENUMS; j++)
4584 {
4585 if (words[j] != fp_values[i][j])
4586 break;
4587 }
b99bd4ef 4588
c19d1205
ZW
4589 if (j == MAX_LITTLENUMS)
4590 {
4591 *str = input_line_pointer;
4592 input_line_pointer = save_in;
4593 return i + 8;
4594 }
4595 }
4596 }
b99bd4ef
NC
4597 }
4598
c19d1205
ZW
4599 *str = input_line_pointer;
4600 input_line_pointer = save_in;
4601 inst.error = _("invalid FPA immediate expression");
4602 return FAIL;
b99bd4ef
NC
4603}
4604
136da414
JB
4605/* Returns 1 if a number has "quarter-precision" float format
4606 0baBbbbbbc defgh000 00000000 00000000. */
4607
4608static int
4609is_quarter_float (unsigned imm)
4610{
4611 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4612 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4613}
4614
4615/* Parse an 8-bit "quarter-precision" floating point number of the form:
4616 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4617 The zero and minus-zero cases need special handling, since they can't be
4618 encoded in the "quarter-precision" float format, but can nonetheless be
4619 loaded as integer constants. */
136da414
JB
4620
4621static unsigned
4622parse_qfloat_immediate (char **ccp, int *immed)
4623{
4624 char *str = *ccp;
c96612cc 4625 char *fpnum;
136da414 4626 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4627 int found_fpchar = 0;
5f4273c7 4628
136da414 4629 skip_past_char (&str, '#');
5f4273c7 4630
c96612cc
JB
4631 /* We must not accidentally parse an integer as a floating-point number. Make
4632 sure that the value we parse is not an integer by checking for special
4633 characters '.' or 'e'.
4634 FIXME: This is a horrible hack, but doing better is tricky because type
4635 information isn't in a very usable state at parse time. */
4636 fpnum = str;
4637 skip_whitespace (fpnum);
4638
4639 if (strncmp (fpnum, "0x", 2) == 0)
4640 return FAIL;
4641 else
4642 {
4643 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4644 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4645 {
4646 found_fpchar = 1;
4647 break;
4648 }
4649
4650 if (!found_fpchar)
4651 return FAIL;
4652 }
5f4273c7 4653
136da414
JB
4654 if ((str = atof_ieee (str, 's', words)) != NULL)
4655 {
4656 unsigned fpword = 0;
4657 int i;
5f4273c7 4658
136da414
JB
4659 /* Our FP word must be 32 bits (single-precision FP). */
4660 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4661 {
4662 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4663 fpword |= words[i];
4664 }
5f4273c7 4665
c96612cc 4666 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4667 *immed = fpword;
4668 else
4669 return FAIL;
4670
4671 *ccp = str;
5f4273c7 4672
136da414
JB
4673 return SUCCESS;
4674 }
5f4273c7 4675
136da414
JB
4676 return FAIL;
4677}
4678
c19d1205
ZW
4679/* Shift operands. */
4680enum shift_kind
b99bd4ef 4681{
c19d1205
ZW
4682 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4683};
b99bd4ef 4684
c19d1205
ZW
4685struct asm_shift_name
4686{
4687 const char *name;
4688 enum shift_kind kind;
4689};
b99bd4ef 4690
c19d1205
ZW
4691/* Third argument to parse_shift. */
4692enum parse_shift_mode
4693{
4694 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4695 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4696 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4697 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4698 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4699};
b99bd4ef 4700
c19d1205
ZW
4701/* Parse a <shift> specifier on an ARM data processing instruction.
4702 This has three forms:
b99bd4ef 4703
c19d1205
ZW
4704 (LSL|LSR|ASL|ASR|ROR) Rs
4705 (LSL|LSR|ASL|ASR|ROR) #imm
4706 RRX
b99bd4ef 4707
c19d1205
ZW
4708 Note that ASL is assimilated to LSL in the instruction encoding, and
4709 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4710
c19d1205
ZW
4711static int
4712parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4713{
c19d1205
ZW
4714 const struct asm_shift_name *shift_name;
4715 enum shift_kind shift;
4716 char *s = *str;
4717 char *p = s;
4718 int reg;
b99bd4ef 4719
c19d1205
ZW
4720 for (p = *str; ISALPHA (*p); p++)
4721 ;
b99bd4ef 4722
c19d1205 4723 if (p == *str)
b99bd4ef 4724 {
c19d1205
ZW
4725 inst.error = _("shift expression expected");
4726 return FAIL;
b99bd4ef
NC
4727 }
4728
21d799b5
NC
4729 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4730 p - *str);
c19d1205
ZW
4731
4732 if (shift_name == NULL)
b99bd4ef 4733 {
c19d1205
ZW
4734 inst.error = _("shift expression expected");
4735 return FAIL;
b99bd4ef
NC
4736 }
4737
c19d1205 4738 shift = shift_name->kind;
b99bd4ef 4739
c19d1205
ZW
4740 switch (mode)
4741 {
4742 case NO_SHIFT_RESTRICT:
4743 case SHIFT_IMMEDIATE: break;
b99bd4ef 4744
c19d1205
ZW
4745 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4746 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4747 {
4748 inst.error = _("'LSL' or 'ASR' required");
4749 return FAIL;
4750 }
4751 break;
b99bd4ef 4752
c19d1205
ZW
4753 case SHIFT_LSL_IMMEDIATE:
4754 if (shift != SHIFT_LSL)
4755 {
4756 inst.error = _("'LSL' required");
4757 return FAIL;
4758 }
4759 break;
b99bd4ef 4760
c19d1205
ZW
4761 case SHIFT_ASR_IMMEDIATE:
4762 if (shift != SHIFT_ASR)
4763 {
4764 inst.error = _("'ASR' required");
4765 return FAIL;
4766 }
4767 break;
b99bd4ef 4768
c19d1205
ZW
4769 default: abort ();
4770 }
b99bd4ef 4771
c19d1205
ZW
4772 if (shift != SHIFT_RRX)
4773 {
4774 /* Whitespace can appear here if the next thing is a bare digit. */
4775 skip_whitespace (p);
b99bd4ef 4776
c19d1205 4777 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4778 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4779 {
4780 inst.operands[i].imm = reg;
4781 inst.operands[i].immisreg = 1;
4782 }
4783 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4784 return FAIL;
4785 }
4786 inst.operands[i].shift_kind = shift;
4787 inst.operands[i].shifted = 1;
4788 *str = p;
4789 return SUCCESS;
b99bd4ef
NC
4790}
4791
c19d1205 4792/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4793
c19d1205
ZW
4794 #<immediate>
4795 #<immediate>, <rotate>
4796 <Rm>
4797 <Rm>, <shift>
b99bd4ef 4798
c19d1205
ZW
4799 where <shift> is defined by parse_shift above, and <rotate> is a
4800 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4801 is deferred to md_apply_fix. */
b99bd4ef 4802
c19d1205
ZW
4803static int
4804parse_shifter_operand (char **str, int i)
4805{
4806 int value;
91d6fa6a 4807 expressionS exp;
b99bd4ef 4808
dcbf9037 4809 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4810 {
4811 inst.operands[i].reg = value;
4812 inst.operands[i].isreg = 1;
b99bd4ef 4813
c19d1205
ZW
4814 /* parse_shift will override this if appropriate */
4815 inst.reloc.exp.X_op = O_constant;
4816 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4817
c19d1205
ZW
4818 if (skip_past_comma (str) == FAIL)
4819 return SUCCESS;
b99bd4ef 4820
c19d1205
ZW
4821 /* Shift operation on register. */
4822 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4823 }
4824
c19d1205
ZW
4825 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4826 return FAIL;
b99bd4ef 4827
c19d1205 4828 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4829 {
c19d1205 4830 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 4831 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 4832 return FAIL;
b99bd4ef 4833
91d6fa6a 4834 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
4835 {
4836 inst.error = _("constant expression expected");
4837 return FAIL;
4838 }
b99bd4ef 4839
91d6fa6a 4840 value = exp.X_add_number;
c19d1205
ZW
4841 if (value < 0 || value > 30 || value % 2 != 0)
4842 {
4843 inst.error = _("invalid rotation");
4844 return FAIL;
4845 }
4846 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4847 {
4848 inst.error = _("invalid constant");
4849 return FAIL;
4850 }
09d92015 4851
55cf6793 4852 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4853 inst.reloc.exp.X_add_number
4854 = (((inst.reloc.exp.X_add_number << (32 - value))
4855 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4856 }
4857
c19d1205
ZW
4858 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4859 inst.reloc.pc_rel = 0;
4860 return SUCCESS;
09d92015
MM
4861}
4862
4962c51a
MS
4863/* Group relocation information. Each entry in the table contains the
4864 textual name of the relocation as may appear in assembler source
4865 and must end with a colon.
4866 Along with this textual name are the relocation codes to be used if
4867 the corresponding instruction is an ALU instruction (ADD or SUB only),
4868 an LDR, an LDRS, or an LDC. */
4869
4870struct group_reloc_table_entry
4871{
4872 const char *name;
4873 int alu_code;
4874 int ldr_code;
4875 int ldrs_code;
4876 int ldc_code;
4877};
4878
4879typedef enum
4880{
4881 /* Varieties of non-ALU group relocation. */
4882
4883 GROUP_LDR,
4884 GROUP_LDRS,
4885 GROUP_LDC
4886} group_reloc_type;
4887
4888static struct group_reloc_table_entry group_reloc_table[] =
4889 { /* Program counter relative: */
4890 { "pc_g0_nc",
4891 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4892 0, /* LDR */
4893 0, /* LDRS */
4894 0 }, /* LDC */
4895 { "pc_g0",
4896 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4897 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4898 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4899 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4900 { "pc_g1_nc",
4901 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4902 0, /* LDR */
4903 0, /* LDRS */
4904 0 }, /* LDC */
4905 { "pc_g1",
4906 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4907 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4908 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4909 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4910 { "pc_g2",
4911 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4912 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4913 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4914 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4915 /* Section base relative */
4916 { "sb_g0_nc",
4917 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4918 0, /* LDR */
4919 0, /* LDRS */
4920 0 }, /* LDC */
4921 { "sb_g0",
4922 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4923 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4924 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4925 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4926 { "sb_g1_nc",
4927 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4928 0, /* LDR */
4929 0, /* LDRS */
4930 0 }, /* LDC */
4931 { "sb_g1",
4932 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4933 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4934 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4935 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4936 { "sb_g2",
4937 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4938 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4939 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4940 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4941
4942/* Given the address of a pointer pointing to the textual name of a group
4943 relocation as may appear in assembler source, attempt to find its details
4944 in group_reloc_table. The pointer will be updated to the character after
4945 the trailing colon. On failure, FAIL will be returned; SUCCESS
4946 otherwise. On success, *entry will be updated to point at the relevant
4947 group_reloc_table entry. */
4948
4949static int
4950find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4951{
4952 unsigned int i;
4953 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4954 {
4955 int length = strlen (group_reloc_table[i].name);
4956
5f4273c7
NC
4957 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4958 && (*str)[length] == ':')
4962c51a
MS
4959 {
4960 *out = &group_reloc_table[i];
4961 *str += (length + 1);
4962 return SUCCESS;
4963 }
4964 }
4965
4966 return FAIL;
4967}
4968
4969/* Parse a <shifter_operand> for an ARM data processing instruction
4970 (as for parse_shifter_operand) where group relocations are allowed:
4971
4972 #<immediate>
4973 #<immediate>, <rotate>
4974 #:<group_reloc>:<expression>
4975 <Rm>
4976 <Rm>, <shift>
4977
4978 where <group_reloc> is one of the strings defined in group_reloc_table.
4979 The hashes are optional.
4980
4981 Everything else is as for parse_shifter_operand. */
4982
4983static parse_operand_result
4984parse_shifter_operand_group_reloc (char **str, int i)
4985{
4986 /* Determine if we have the sequence of characters #: or just :
4987 coming next. If we do, then we check for a group relocation.
4988 If we don't, punt the whole lot to parse_shifter_operand. */
4989
4990 if (((*str)[0] == '#' && (*str)[1] == ':')
4991 || (*str)[0] == ':')
4992 {
4993 struct group_reloc_table_entry *entry;
4994
4995 if ((*str)[0] == '#')
4996 (*str) += 2;
4997 else
4998 (*str)++;
4999
5000 /* Try to parse a group relocation. Anything else is an error. */
5001 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5002 {
5003 inst.error = _("unknown group relocation");
5004 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5005 }
5006
5007 /* We now have the group relocation table entry corresponding to
5008 the name in the assembler source. Next, we parse the expression. */
5009 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
5010 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5011
5012 /* Record the relocation type (always the ALU variant here). */
21d799b5 5013 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5014 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5015
5016 return PARSE_OPERAND_SUCCESS;
5017 }
5018 else
5019 return parse_shifter_operand (str, i) == SUCCESS
5020 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5021
5022 /* Never reached. */
5023}
5024
8e560766
MGD
5025/* Parse a Neon alignment expression. Information is written to
5026 inst.operands[i]. We assume the initial ':' has been skipped.
5027
5028 align .imm = align << 8, .immisalign=1, .preind=0 */
5029static parse_operand_result
5030parse_neon_alignment (char **str, int i)
5031{
5032 char *p = *str;
5033 expressionS exp;
5034
5035 my_get_expression (&exp, &p, GE_NO_PREFIX);
5036
5037 if (exp.X_op != O_constant)
5038 {
5039 inst.error = _("alignment must be constant");
5040 return PARSE_OPERAND_FAIL;
5041 }
5042
5043 inst.operands[i].imm = exp.X_add_number << 8;
5044 inst.operands[i].immisalign = 1;
5045 /* Alignments are not pre-indexes. */
5046 inst.operands[i].preind = 0;
5047
5048 *str = p;
5049 return PARSE_OPERAND_SUCCESS;
5050}
5051
c19d1205
ZW
5052/* Parse all forms of an ARM address expression. Information is written
5053 to inst.operands[i] and/or inst.reloc.
09d92015 5054
c19d1205 5055 Preindexed addressing (.preind=1):
09d92015 5056
c19d1205
ZW
5057 [Rn, #offset] .reg=Rn .reloc.exp=offset
5058 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5059 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5060 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5061
c19d1205 5062 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5063
c19d1205 5064 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5065
c19d1205
ZW
5066 [Rn], #offset .reg=Rn .reloc.exp=offset
5067 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5068 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5069 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5070
c19d1205 5071 Unindexed addressing (.preind=0, .postind=0):
09d92015 5072
c19d1205 5073 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5074
c19d1205 5075 Other:
09d92015 5076
c19d1205
ZW
5077 [Rn]{!} shorthand for [Rn,#0]{!}
5078 =immediate .isreg=0 .reloc.exp=immediate
5079 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5080
c19d1205
ZW
5081 It is the caller's responsibility to check for addressing modes not
5082 supported by the instruction, and to set inst.reloc.type. */
5083
4962c51a
MS
5084static parse_operand_result
5085parse_address_main (char **str, int i, int group_relocations,
5086 group_reloc_type group_type)
09d92015 5087{
c19d1205
ZW
5088 char *p = *str;
5089 int reg;
09d92015 5090
c19d1205 5091 if (skip_past_char (&p, '[') == FAIL)
09d92015 5092 {
c19d1205
ZW
5093 if (skip_past_char (&p, '=') == FAIL)
5094 {
974da60d 5095 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5096 inst.reloc.pc_rel = 1;
5097 inst.operands[i].reg = REG_PC;
5098 inst.operands[i].isreg = 1;
5099 inst.operands[i].preind = 1;
5100 }
974da60d 5101 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
09d92015 5102
c19d1205 5103 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 5104 return PARSE_OPERAND_FAIL;
09d92015 5105
c19d1205 5106 *str = p;
4962c51a 5107 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5108 }
5109
dcbf9037 5110 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5111 {
c19d1205 5112 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5113 return PARSE_OPERAND_FAIL;
09d92015 5114 }
c19d1205
ZW
5115 inst.operands[i].reg = reg;
5116 inst.operands[i].isreg = 1;
09d92015 5117
c19d1205 5118 if (skip_past_comma (&p) == SUCCESS)
09d92015 5119 {
c19d1205 5120 inst.operands[i].preind = 1;
09d92015 5121
c19d1205
ZW
5122 if (*p == '+') p++;
5123 else if (*p == '-') p++, inst.operands[i].negative = 1;
5124
dcbf9037 5125 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5126 {
c19d1205
ZW
5127 inst.operands[i].imm = reg;
5128 inst.operands[i].immisreg = 1;
5129
5130 if (skip_past_comma (&p) == SUCCESS)
5131 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5132 return PARSE_OPERAND_FAIL;
c19d1205 5133 }
5287ad62 5134 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5135 {
5136 /* FIXME: '@' should be used here, but it's filtered out by generic
5137 code before we get to see it here. This may be subject to
5138 change. */
5139 parse_operand_result result = parse_neon_alignment (&p, i);
5140
5141 if (result != PARSE_OPERAND_SUCCESS)
5142 return result;
5143 }
c19d1205
ZW
5144 else
5145 {
5146 if (inst.operands[i].negative)
5147 {
5148 inst.operands[i].negative = 0;
5149 p--;
5150 }
4962c51a 5151
5f4273c7
NC
5152 if (group_relocations
5153 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5154 {
5155 struct group_reloc_table_entry *entry;
5156
5157 /* Skip over the #: or : sequence. */
5158 if (*p == '#')
5159 p += 2;
5160 else
5161 p++;
5162
5163 /* Try to parse a group relocation. Anything else is an
5164 error. */
5165 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5166 {
5167 inst.error = _("unknown group relocation");
5168 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5169 }
5170
5171 /* We now have the group relocation table entry corresponding to
5172 the name in the assembler source. Next, we parse the
5173 expression. */
5174 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5175 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5176
5177 /* Record the relocation type. */
5178 switch (group_type)
5179 {
5180 case GROUP_LDR:
21d799b5 5181 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
4962c51a
MS
5182 break;
5183
5184 case GROUP_LDRS:
21d799b5 5185 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
4962c51a
MS
5186 break;
5187
5188 case GROUP_LDC:
21d799b5 5189 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
4962c51a
MS
5190 break;
5191
5192 default:
9c2799c2 5193 gas_assert (0);
4962c51a
MS
5194 }
5195
5196 if (inst.reloc.type == 0)
5197 {
5198 inst.error = _("this group relocation is not allowed on this instruction");
5199 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5200 }
5201 }
5202 else
5203 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5204 return PARSE_OPERAND_FAIL;
09d92015
MM
5205 }
5206 }
8e560766
MGD
5207 else if (skip_past_char (&p, ':') == SUCCESS)
5208 {
5209 /* FIXME: '@' should be used here, but it's filtered out by generic code
5210 before we get to see it here. This may be subject to change. */
5211 parse_operand_result result = parse_neon_alignment (&p, i);
5212
5213 if (result != PARSE_OPERAND_SUCCESS)
5214 return result;
5215 }
09d92015 5216
c19d1205 5217 if (skip_past_char (&p, ']') == FAIL)
09d92015 5218 {
c19d1205 5219 inst.error = _("']' expected");
4962c51a 5220 return PARSE_OPERAND_FAIL;
09d92015
MM
5221 }
5222
c19d1205
ZW
5223 if (skip_past_char (&p, '!') == SUCCESS)
5224 inst.operands[i].writeback = 1;
09d92015 5225
c19d1205 5226 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5227 {
c19d1205
ZW
5228 if (skip_past_char (&p, '{') == SUCCESS)
5229 {
5230 /* [Rn], {expr} - unindexed, with option */
5231 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5232 0, 255, TRUE) == FAIL)
4962c51a 5233 return PARSE_OPERAND_FAIL;
09d92015 5234
c19d1205
ZW
5235 if (skip_past_char (&p, '}') == FAIL)
5236 {
5237 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5238 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5239 }
5240 if (inst.operands[i].preind)
5241 {
5242 inst.error = _("cannot combine index with option");
4962c51a 5243 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5244 }
5245 *str = p;
4962c51a 5246 return PARSE_OPERAND_SUCCESS;
09d92015 5247 }
c19d1205
ZW
5248 else
5249 {
5250 inst.operands[i].postind = 1;
5251 inst.operands[i].writeback = 1;
09d92015 5252
c19d1205
ZW
5253 if (inst.operands[i].preind)
5254 {
5255 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5256 return PARSE_OPERAND_FAIL;
c19d1205 5257 }
09d92015 5258
c19d1205
ZW
5259 if (*p == '+') p++;
5260 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5261
dcbf9037 5262 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5263 {
5287ad62
JB
5264 /* We might be using the immediate for alignment already. If we
5265 are, OR the register number into the low-order bits. */
5266 if (inst.operands[i].immisalign)
5267 inst.operands[i].imm |= reg;
5268 else
5269 inst.operands[i].imm = reg;
c19d1205 5270 inst.operands[i].immisreg = 1;
a737bd4d 5271
c19d1205
ZW
5272 if (skip_past_comma (&p) == SUCCESS)
5273 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5274 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5275 }
5276 else
5277 {
5278 if (inst.operands[i].negative)
5279 {
5280 inst.operands[i].negative = 0;
5281 p--;
5282 }
5283 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5284 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5285 }
5286 }
a737bd4d
NC
5287 }
5288
c19d1205
ZW
5289 /* If at this point neither .preind nor .postind is set, we have a
5290 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5291 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5292 {
5293 inst.operands[i].preind = 1;
5294 inst.reloc.exp.X_op = O_constant;
5295 inst.reloc.exp.X_add_number = 0;
5296 }
5297 *str = p;
4962c51a
MS
5298 return PARSE_OPERAND_SUCCESS;
5299}
5300
5301static int
5302parse_address (char **str, int i)
5303{
21d799b5 5304 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
4962c51a
MS
5305 ? SUCCESS : FAIL;
5306}
5307
5308static parse_operand_result
5309parse_address_group_reloc (char **str, int i, group_reloc_type type)
5310{
5311 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5312}
5313
b6895b4f
PB
5314/* Parse an operand for a MOVW or MOVT instruction. */
5315static int
5316parse_half (char **str)
5317{
5318 char * p;
5f4273c7 5319
b6895b4f
PB
5320 p = *str;
5321 skip_past_char (&p, '#');
5f4273c7 5322 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5323 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5324 else if (strncasecmp (p, ":upper16:", 9) == 0)
5325 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5326
5327 if (inst.reloc.type != BFD_RELOC_UNUSED)
5328 {
5329 p += 9;
5f4273c7 5330 skip_whitespace (p);
b6895b4f
PB
5331 }
5332
5333 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5334 return FAIL;
5335
5336 if (inst.reloc.type == BFD_RELOC_UNUSED)
5337 {
5338 if (inst.reloc.exp.X_op != O_constant)
5339 {
5340 inst.error = _("constant expression expected");
5341 return FAIL;
5342 }
5343 if (inst.reloc.exp.X_add_number < 0
5344 || inst.reloc.exp.X_add_number > 0xffff)
5345 {
5346 inst.error = _("immediate value out of range");
5347 return FAIL;
5348 }
5349 }
5350 *str = p;
5351 return SUCCESS;
5352}
5353
c19d1205 5354/* Miscellaneous. */
a737bd4d 5355
c19d1205
ZW
5356/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5357 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5358static int
d2cd1205 5359parse_psr (char **str, bfd_boolean lhs)
09d92015 5360{
c19d1205
ZW
5361 char *p;
5362 unsigned long psr_field;
62b3e311
PB
5363 const struct asm_psr *psr;
5364 char *start;
d2cd1205 5365 bfd_boolean is_apsr = FALSE;
ac7f631b 5366 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5367
c19d1205
ZW
5368 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5369 feature for ease of use and backwards compatibility. */
5370 p = *str;
62b3e311 5371 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5372 {
5373 if (m_profile)
5374 goto unsupported_psr;
5375
5376 psr_field = SPSR_BIT;
5377 }
5378 else if (strncasecmp (p, "CPSR", 4) == 0)
5379 {
5380 if (m_profile)
5381 goto unsupported_psr;
5382
5383 psr_field = 0;
5384 }
5385 else if (strncasecmp (p, "APSR", 4) == 0)
5386 {
5387 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5388 and ARMv7-R architecture CPUs. */
5389 is_apsr = TRUE;
5390 psr_field = 0;
5391 }
5392 else if (m_profile)
62b3e311
PB
5393 {
5394 start = p;
5395 do
5396 p++;
5397 while (ISALNUM (*p) || *p == '_');
5398
d2cd1205
JB
5399 if (strncasecmp (start, "iapsr", 5) == 0
5400 || strncasecmp (start, "eapsr", 5) == 0
5401 || strncasecmp (start, "xpsr", 4) == 0
5402 || strncasecmp (start, "psr", 3) == 0)
5403 p = start + strcspn (start, "rR") + 1;
5404
21d799b5
NC
5405 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5406 p - start);
d2cd1205 5407
62b3e311
PB
5408 if (!psr)
5409 return FAIL;
09d92015 5410
d2cd1205
JB
5411 /* If APSR is being written, a bitfield may be specified. Note that
5412 APSR itself is handled above. */
5413 if (psr->field <= 3)
5414 {
5415 psr_field = psr->field;
5416 is_apsr = TRUE;
5417 goto check_suffix;
5418 }
5419
62b3e311 5420 *str = p;
d2cd1205
JB
5421 /* M-profile MSR instructions have the mask field set to "10", except
5422 *PSR variants which modify APSR, which may use a different mask (and
5423 have been handled already). Do that by setting the PSR_f field
5424 here. */
5425 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5426 }
d2cd1205
JB
5427 else
5428 goto unsupported_psr;
09d92015 5429
62b3e311 5430 p += 4;
d2cd1205 5431check_suffix:
c19d1205
ZW
5432 if (*p == '_')
5433 {
5434 /* A suffix follows. */
c19d1205
ZW
5435 p++;
5436 start = p;
a737bd4d 5437
c19d1205
ZW
5438 do
5439 p++;
5440 while (ISALNUM (*p) || *p == '_');
a737bd4d 5441
d2cd1205
JB
5442 if (is_apsr)
5443 {
5444 /* APSR uses a notation for bits, rather than fields. */
5445 unsigned int nzcvq_bits = 0;
5446 unsigned int g_bit = 0;
5447 char *bit;
5448
5449 for (bit = start; bit != p; bit++)
5450 {
5451 switch (TOLOWER (*bit))
5452 {
5453 case 'n':
5454 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5455 break;
5456
5457 case 'z':
5458 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5459 break;
5460
5461 case 'c':
5462 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5463 break;
5464
5465 case 'v':
5466 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5467 break;
5468
5469 case 'q':
5470 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5471 break;
5472
5473 case 'g':
5474 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5475 break;
5476
5477 default:
5478 inst.error = _("unexpected bit specified after APSR");
5479 return FAIL;
5480 }
5481 }
5482
5483 if (nzcvq_bits == 0x1f)
5484 psr_field |= PSR_f;
5485
5486 if (g_bit == 0x1)
5487 {
5488 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
5489 {
5490 inst.error = _("selected processor does not "
5491 "support DSP extension");
5492 return FAIL;
5493 }
5494
5495 psr_field |= PSR_s;
5496 }
5497
5498 if ((nzcvq_bits & 0x20) != 0
5499 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5500 || (g_bit & 0x2) != 0)
5501 {
5502 inst.error = _("bad bitmask specified after APSR");
5503 return FAIL;
5504 }
5505 }
5506 else
5507 {
5508 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5509 p - start);
5510 if (!psr)
5511 goto error;
a737bd4d 5512
d2cd1205
JB
5513 psr_field |= psr->field;
5514 }
a737bd4d 5515 }
c19d1205 5516 else
a737bd4d 5517 {
c19d1205
ZW
5518 if (ISALNUM (*p))
5519 goto error; /* Garbage after "[CS]PSR". */
5520
d2cd1205
JB
5521 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
5522 is deprecated, but allow it anyway. */
5523 if (is_apsr && lhs)
5524 {
5525 psr_field |= PSR_f;
5526 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5527 "deprecated"));
5528 }
5529 else if (!m_profile)
5530 /* These bits are never right for M-profile devices: don't set them
5531 (only code paths which read/write APSR reach here). */
5532 psr_field |= (PSR_c | PSR_f);
a737bd4d 5533 }
c19d1205
ZW
5534 *str = p;
5535 return psr_field;
a737bd4d 5536
d2cd1205
JB
5537 unsupported_psr:
5538 inst.error = _("selected processor does not support requested special "
5539 "purpose register");
5540 return FAIL;
5541
c19d1205
ZW
5542 error:
5543 inst.error = _("flag for {c}psr instruction expected");
5544 return FAIL;
a737bd4d
NC
5545}
5546
c19d1205
ZW
5547/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5548 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5549
c19d1205
ZW
5550static int
5551parse_cps_flags (char **str)
a737bd4d 5552{
c19d1205
ZW
5553 int val = 0;
5554 int saw_a_flag = 0;
5555 char *s = *str;
a737bd4d 5556
c19d1205
ZW
5557 for (;;)
5558 switch (*s++)
5559 {
5560 case '\0': case ',':
5561 goto done;
a737bd4d 5562
c19d1205
ZW
5563 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5564 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5565 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5566
c19d1205
ZW
5567 default:
5568 inst.error = _("unrecognized CPS flag");
5569 return FAIL;
5570 }
a737bd4d 5571
c19d1205
ZW
5572 done:
5573 if (saw_a_flag == 0)
a737bd4d 5574 {
c19d1205
ZW
5575 inst.error = _("missing CPS flags");
5576 return FAIL;
a737bd4d 5577 }
a737bd4d 5578
c19d1205
ZW
5579 *str = s - 1;
5580 return val;
a737bd4d
NC
5581}
5582
c19d1205
ZW
5583/* Parse an endian specifier ("BE" or "LE", case insensitive);
5584 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5585
5586static int
c19d1205 5587parse_endian_specifier (char **str)
a737bd4d 5588{
c19d1205
ZW
5589 int little_endian;
5590 char *s = *str;
a737bd4d 5591
c19d1205
ZW
5592 if (strncasecmp (s, "BE", 2))
5593 little_endian = 0;
5594 else if (strncasecmp (s, "LE", 2))
5595 little_endian = 1;
5596 else
a737bd4d 5597 {
c19d1205 5598 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5599 return FAIL;
5600 }
5601
c19d1205 5602 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5603 {
c19d1205 5604 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5605 return FAIL;
5606 }
5607
c19d1205
ZW
5608 *str = s + 2;
5609 return little_endian;
5610}
a737bd4d 5611
c19d1205
ZW
5612/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5613 value suitable for poking into the rotate field of an sxt or sxta
5614 instruction, or FAIL on error. */
5615
5616static int
5617parse_ror (char **str)
5618{
5619 int rot;
5620 char *s = *str;
5621
5622 if (strncasecmp (s, "ROR", 3) == 0)
5623 s += 3;
5624 else
a737bd4d 5625 {
c19d1205 5626 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5627 return FAIL;
5628 }
c19d1205
ZW
5629
5630 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5631 return FAIL;
5632
5633 switch (rot)
a737bd4d 5634 {
c19d1205
ZW
5635 case 0: *str = s; return 0x0;
5636 case 8: *str = s; return 0x1;
5637 case 16: *str = s; return 0x2;
5638 case 24: *str = s; return 0x3;
5639
5640 default:
5641 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5642 return FAIL;
5643 }
c19d1205 5644}
a737bd4d 5645
c19d1205
ZW
5646/* Parse a conditional code (from conds[] below). The value returned is in the
5647 range 0 .. 14, or FAIL. */
5648static int
5649parse_cond (char **str)
5650{
c462b453 5651 char *q;
c19d1205 5652 const struct asm_cond *c;
c462b453
PB
5653 int n;
5654 /* Condition codes are always 2 characters, so matching up to
5655 3 characters is sufficient. */
5656 char cond[3];
a737bd4d 5657
c462b453
PB
5658 q = *str;
5659 n = 0;
5660 while (ISALPHA (*q) && n < 3)
5661 {
e07e6e58 5662 cond[n] = TOLOWER (*q);
c462b453
PB
5663 q++;
5664 n++;
5665 }
a737bd4d 5666
21d799b5 5667 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5668 if (!c)
a737bd4d 5669 {
c19d1205 5670 inst.error = _("condition required");
a737bd4d
NC
5671 return FAIL;
5672 }
5673
c19d1205
ZW
5674 *str = q;
5675 return c->value;
5676}
5677
62b3e311
PB
5678/* Parse an option for a barrier instruction. Returns the encoding for the
5679 option, or FAIL. */
5680static int
5681parse_barrier (char **str)
5682{
5683 char *p, *q;
5684 const struct asm_barrier_opt *o;
5685
5686 p = q = *str;
5687 while (ISALPHA (*q))
5688 q++;
5689
21d799b5
NC
5690 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5691 q - p);
62b3e311
PB
5692 if (!o)
5693 return FAIL;
5694
5695 *str = q;
5696 return o->value;
5697}
5698
92e90b6e
PB
5699/* Parse the operands of a table branch instruction. Similar to a memory
5700 operand. */
5701static int
5702parse_tb (char **str)
5703{
5704 char * p = *str;
5705 int reg;
5706
5707 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5708 {
5709 inst.error = _("'[' expected");
5710 return FAIL;
5711 }
92e90b6e 5712
dcbf9037 5713 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5714 {
5715 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5716 return FAIL;
5717 }
5718 inst.operands[0].reg = reg;
5719
5720 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5721 {
5722 inst.error = _("',' expected");
5723 return FAIL;
5724 }
5f4273c7 5725
dcbf9037 5726 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5727 {
5728 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5729 return FAIL;
5730 }
5731 inst.operands[0].imm = reg;
5732
5733 if (skip_past_comma (&p) == SUCCESS)
5734 {
5735 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5736 return FAIL;
5737 if (inst.reloc.exp.X_add_number != 1)
5738 {
5739 inst.error = _("invalid shift");
5740 return FAIL;
5741 }
5742 inst.operands[0].shifted = 1;
5743 }
5744
5745 if (skip_past_char (&p, ']') == FAIL)
5746 {
5747 inst.error = _("']' expected");
5748 return FAIL;
5749 }
5750 *str = p;
5751 return SUCCESS;
5752}
5753
5287ad62
JB
5754/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5755 information on the types the operands can take and how they are encoded.
037e8744
JB
5756 Up to four operands may be read; this function handles setting the
5757 ".present" field for each read operand itself.
5287ad62
JB
5758 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5759 else returns FAIL. */
5760
5761static int
5762parse_neon_mov (char **str, int *which_operand)
5763{
5764 int i = *which_operand, val;
5765 enum arm_reg_type rtype;
5766 char *ptr = *str;
dcbf9037 5767 struct neon_type_el optype;
5f4273c7 5768
dcbf9037 5769 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5770 {
5771 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5772 inst.operands[i].reg = val;
5773 inst.operands[i].isscalar = 1;
dcbf9037 5774 inst.operands[i].vectype = optype;
5287ad62
JB
5775 inst.operands[i++].present = 1;
5776
5777 if (skip_past_comma (&ptr) == FAIL)
5778 goto wanted_comma;
5f4273c7 5779
dcbf9037 5780 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5781 goto wanted_arm;
5f4273c7 5782
5287ad62
JB
5783 inst.operands[i].reg = val;
5784 inst.operands[i].isreg = 1;
5785 inst.operands[i].present = 1;
5786 }
037e8744 5787 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5788 != FAIL)
5287ad62
JB
5789 {
5790 /* Cases 0, 1, 2, 3, 5 (D only). */
5791 if (skip_past_comma (&ptr) == FAIL)
5792 goto wanted_comma;
5f4273c7 5793
5287ad62
JB
5794 inst.operands[i].reg = val;
5795 inst.operands[i].isreg = 1;
5796 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5797 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5798 inst.operands[i].isvec = 1;
dcbf9037 5799 inst.operands[i].vectype = optype;
5287ad62
JB
5800 inst.operands[i++].present = 1;
5801
dcbf9037 5802 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5803 {
037e8744
JB
5804 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5805 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5806 inst.operands[i].reg = val;
5807 inst.operands[i].isreg = 1;
037e8744 5808 inst.operands[i].present = 1;
5287ad62
JB
5809
5810 if (rtype == REG_TYPE_NQ)
5811 {
dcbf9037 5812 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5813 return FAIL;
5814 }
037e8744
JB
5815 else if (rtype != REG_TYPE_VFS)
5816 {
5817 i++;
5818 if (skip_past_comma (&ptr) == FAIL)
5819 goto wanted_comma;
5820 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5821 goto wanted_arm;
5822 inst.operands[i].reg = val;
5823 inst.operands[i].isreg = 1;
5824 inst.operands[i].present = 1;
5825 }
5287ad62 5826 }
037e8744
JB
5827 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5828 &optype)) != FAIL)
5287ad62
JB
5829 {
5830 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5831 Case 1: VMOV<c><q> <Dd>, <Dm>
5832 Case 8: VMOV.F32 <Sd>, <Sm>
5833 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5834
5835 inst.operands[i].reg = val;
5836 inst.operands[i].isreg = 1;
5837 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5838 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5839 inst.operands[i].isvec = 1;
dcbf9037 5840 inst.operands[i].vectype = optype;
5287ad62 5841 inst.operands[i].present = 1;
5f4273c7 5842
037e8744
JB
5843 if (skip_past_comma (&ptr) == SUCCESS)
5844 {
5845 /* Case 15. */
5846 i++;
5847
5848 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5849 goto wanted_arm;
5850
5851 inst.operands[i].reg = val;
5852 inst.operands[i].isreg = 1;
5853 inst.operands[i++].present = 1;
5f4273c7 5854
037e8744
JB
5855 if (skip_past_comma (&ptr) == FAIL)
5856 goto wanted_comma;
5f4273c7 5857
037e8744
JB
5858 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5859 goto wanted_arm;
5f4273c7 5860
037e8744
JB
5861 inst.operands[i].reg = val;
5862 inst.operands[i].isreg = 1;
5863 inst.operands[i++].present = 1;
5864 }
5287ad62 5865 }
4641781c
PB
5866 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5867 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5868 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5869 Case 10: VMOV.F32 <Sd>, #<imm>
5870 Case 11: VMOV.F64 <Dd>, #<imm> */
5871 inst.operands[i].immisfloat = 1;
5872 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5873 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5874 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5875 ;
5287ad62
JB
5876 else
5877 {
dcbf9037 5878 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5879 return FAIL;
5880 }
5881 }
dcbf9037 5882 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5883 {
5884 /* Cases 6, 7. */
5885 inst.operands[i].reg = val;
5886 inst.operands[i].isreg = 1;
5887 inst.operands[i++].present = 1;
5f4273c7 5888
5287ad62
JB
5889 if (skip_past_comma (&ptr) == FAIL)
5890 goto wanted_comma;
5f4273c7 5891
dcbf9037 5892 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5893 {
5894 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5895 inst.operands[i].reg = val;
5896 inst.operands[i].isscalar = 1;
5897 inst.operands[i].present = 1;
dcbf9037 5898 inst.operands[i].vectype = optype;
5287ad62 5899 }
dcbf9037 5900 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5901 {
5902 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5903 inst.operands[i].reg = val;
5904 inst.operands[i].isreg = 1;
5905 inst.operands[i++].present = 1;
5f4273c7 5906
5287ad62
JB
5907 if (skip_past_comma (&ptr) == FAIL)
5908 goto wanted_comma;
5f4273c7 5909
037e8744 5910 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5911 == FAIL)
5287ad62 5912 {
037e8744 5913 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5914 return FAIL;
5915 }
5916
5917 inst.operands[i].reg = val;
5918 inst.operands[i].isreg = 1;
037e8744
JB
5919 inst.operands[i].isvec = 1;
5920 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5921 inst.operands[i].vectype = optype;
5287ad62 5922 inst.operands[i].present = 1;
5f4273c7 5923
037e8744
JB
5924 if (rtype == REG_TYPE_VFS)
5925 {
5926 /* Case 14. */
5927 i++;
5928 if (skip_past_comma (&ptr) == FAIL)
5929 goto wanted_comma;
5930 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5931 &optype)) == FAIL)
5932 {
5933 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5934 return FAIL;
5935 }
5936 inst.operands[i].reg = val;
5937 inst.operands[i].isreg = 1;
5938 inst.operands[i].isvec = 1;
5939 inst.operands[i].issingle = 1;
5940 inst.operands[i].vectype = optype;
5941 inst.operands[i].present = 1;
5942 }
5943 }
5944 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5945 != FAIL)
5946 {
5947 /* Case 13. */
5948 inst.operands[i].reg = val;
5949 inst.operands[i].isreg = 1;
5950 inst.operands[i].isvec = 1;
5951 inst.operands[i].issingle = 1;
5952 inst.operands[i].vectype = optype;
5953 inst.operands[i++].present = 1;
5287ad62
JB
5954 }
5955 }
5956 else
5957 {
dcbf9037 5958 first_error (_("parse error"));
5287ad62
JB
5959 return FAIL;
5960 }
5961
5962 /* Successfully parsed the operands. Update args. */
5963 *which_operand = i;
5964 *str = ptr;
5965 return SUCCESS;
5966
5f4273c7 5967 wanted_comma:
dcbf9037 5968 first_error (_("expected comma"));
5287ad62 5969 return FAIL;
5f4273c7
NC
5970
5971 wanted_arm:
dcbf9037 5972 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5973 return FAIL;
5287ad62
JB
5974}
5975
5be8be5d
DG
5976/* Use this macro when the operand constraints are different
5977 for ARM and THUMB (e.g. ldrd). */
5978#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
5979 ((arm_operand) | ((thumb_operand) << 16))
5980
c19d1205
ZW
5981/* Matcher codes for parse_operands. */
5982enum operand_parse_code
5983{
5984 OP_stop, /* end of line */
5985
5986 OP_RR, /* ARM register */
5987 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 5988 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 5989 OP_RRnpcb, /* ARM register, not r15, in square brackets */
55881a11
MGD
5990 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
5991 optional trailing ! */
c19d1205
ZW
5992 OP_RRw, /* ARM register, not r15, optional trailing ! */
5993 OP_RCP, /* Coprocessor number */
5994 OP_RCN, /* Coprocessor register */
5995 OP_RF, /* FPA register */
5996 OP_RVS, /* VFP single precision register */
5287ad62
JB
5997 OP_RVD, /* VFP double precision register (0..15) */
5998 OP_RND, /* Neon double precision register (0..31) */
5999 OP_RNQ, /* Neon quad precision register */
037e8744 6000 OP_RVSD, /* VFP single or double precision register */
5287ad62 6001 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6002 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6003 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6004 OP_RVC, /* VFP control register */
6005 OP_RMF, /* Maverick F register */
6006 OP_RMD, /* Maverick D register */
6007 OP_RMFX, /* Maverick FX register */
6008 OP_RMDX, /* Maverick DX register */
6009 OP_RMAX, /* Maverick AX register */
6010 OP_RMDS, /* Maverick DSPSC register */
6011 OP_RIWR, /* iWMMXt wR register */
6012 OP_RIWC, /* iWMMXt wC register */
6013 OP_RIWG, /* iWMMXt wCG register */
6014 OP_RXA, /* XScale accumulator register */
6015
6016 OP_REGLST, /* ARM register list */
6017 OP_VRSLST, /* VFP single-precision register list */
6018 OP_VRDLST, /* VFP double-precision register list */
037e8744 6019 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6020 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6021 OP_NSTRLST, /* Neon element/structure list */
6022
5287ad62 6023 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6024 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 6025 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6026 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6027 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6028 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6029 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6030 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6031 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6032 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6033
6034 OP_I0, /* immediate zero */
c19d1205
ZW
6035 OP_I7, /* immediate value 0 .. 7 */
6036 OP_I15, /* 0 .. 15 */
6037 OP_I16, /* 1 .. 16 */
5287ad62 6038 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6039 OP_I31, /* 0 .. 31 */
6040 OP_I31w, /* 0 .. 31, optional trailing ! */
6041 OP_I32, /* 1 .. 32 */
5287ad62
JB
6042 OP_I32z, /* 0 .. 32 */
6043 OP_I63, /* 0 .. 63 */
c19d1205 6044 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6045 OP_I64, /* 1 .. 64 */
6046 OP_I64z, /* 0 .. 64 */
c19d1205 6047 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6048
6049 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6050 OP_I7b, /* 0 .. 7 */
6051 OP_I15b, /* 0 .. 15 */
6052 OP_I31b, /* 0 .. 31 */
6053
6054 OP_SH, /* shifter operand */
4962c51a 6055 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6056 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6057 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6058 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6059 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6060 OP_EXP, /* arbitrary expression */
6061 OP_EXPi, /* same, with optional immediate prefix */
6062 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6063 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6064
6065 OP_CPSF, /* CPS flags */
6066 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6067 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6068 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6069 OP_COND, /* conditional code */
92e90b6e 6070 OP_TB, /* Table branch. */
c19d1205 6071
037e8744
JB
6072 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6073
c19d1205
ZW
6074 OP_RRnpc_I0, /* ARM register or literal 0 */
6075 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6076 OP_RR_EXi, /* ARM register or expression with imm prefix */
6077 OP_RF_IF, /* FPA register or immediate */
6078 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6079 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6080
6081 /* Optional operands. */
6082 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6083 OP_oI31b, /* 0 .. 31 */
5287ad62 6084 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
6085 OP_oIffffb, /* 0 .. 65535 */
6086 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6087
6088 OP_oRR, /* ARM register */
6089 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6090 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6091 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6092 OP_oRND, /* Optional Neon double precision register */
6093 OP_oRNQ, /* Optional Neon quad precision register */
6094 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6095 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6096 OP_oSHll, /* LSL immediate */
6097 OP_oSHar, /* ASR immediate */
6098 OP_oSHllar, /* LSL or ASR immediate */
6099 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6100 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6101
5be8be5d
DG
6102 /* Some pre-defined mixed (ARM/THUMB) operands. */
6103 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6104 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6105 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6106
c19d1205
ZW
6107 OP_FIRST_OPTIONAL = OP_oI7b
6108};
a737bd4d 6109
c19d1205
ZW
6110/* Generic instruction operand parser. This does no encoding and no
6111 semantic validation; it merely squirrels values away in the inst
6112 structure. Returns SUCCESS or FAIL depending on whether the
6113 specified grammar matched. */
6114static int
5be8be5d 6115parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6116{
5be8be5d 6117 unsigned const int *upat = pattern;
c19d1205
ZW
6118 char *backtrack_pos = 0;
6119 const char *backtrack_error = 0;
6120 int i, val, backtrack_index = 0;
5287ad62 6121 enum arm_reg_type rtype;
4962c51a 6122 parse_operand_result result;
5be8be5d 6123 unsigned int op_parse_code;
c19d1205 6124
e07e6e58
NC
6125#define po_char_or_fail(chr) \
6126 do \
6127 { \
6128 if (skip_past_char (&str, chr) == FAIL) \
6129 goto bad_args; \
6130 } \
6131 while (0)
c19d1205 6132
e07e6e58
NC
6133#define po_reg_or_fail(regtype) \
6134 do \
dcbf9037 6135 { \
e07e6e58
NC
6136 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6137 & inst.operands[i].vectype); \
6138 if (val == FAIL) \
6139 { \
6140 first_error (_(reg_expected_msgs[regtype])); \
6141 goto failure; \
6142 } \
6143 inst.operands[i].reg = val; \
6144 inst.operands[i].isreg = 1; \
6145 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6146 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6147 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6148 || rtype == REG_TYPE_VFD \
6149 || rtype == REG_TYPE_NQ); \
dcbf9037 6150 } \
e07e6e58
NC
6151 while (0)
6152
6153#define po_reg_or_goto(regtype, label) \
6154 do \
6155 { \
6156 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6157 & inst.operands[i].vectype); \
6158 if (val == FAIL) \
6159 goto label; \
dcbf9037 6160 \
e07e6e58
NC
6161 inst.operands[i].reg = val; \
6162 inst.operands[i].isreg = 1; \
6163 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6164 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6165 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6166 || rtype == REG_TYPE_VFD \
6167 || rtype == REG_TYPE_NQ); \
6168 } \
6169 while (0)
6170
6171#define po_imm_or_fail(min, max, popt) \
6172 do \
6173 { \
6174 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6175 goto failure; \
6176 inst.operands[i].imm = val; \
6177 } \
6178 while (0)
6179
6180#define po_scalar_or_goto(elsz, label) \
6181 do \
6182 { \
6183 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6184 if (val == FAIL) \
6185 goto label; \
6186 inst.operands[i].reg = val; \
6187 inst.operands[i].isscalar = 1; \
6188 } \
6189 while (0)
6190
6191#define po_misc_or_fail(expr) \
6192 do \
6193 { \
6194 if (expr) \
6195 goto failure; \
6196 } \
6197 while (0)
6198
6199#define po_misc_or_fail_no_backtrack(expr) \
6200 do \
6201 { \
6202 result = expr; \
6203 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6204 backtrack_pos = 0; \
6205 if (result != PARSE_OPERAND_SUCCESS) \
6206 goto failure; \
6207 } \
6208 while (0)
4962c51a 6209
52e7f43d
RE
6210#define po_barrier_or_imm(str) \
6211 do \
6212 { \
6213 val = parse_barrier (&str); \
6214 if (val == FAIL) \
6215 { \
6216 if (ISALPHA (*str)) \
6217 goto failure; \
6218 else \
6219 goto immediate; \
6220 } \
6221 else \
6222 { \
6223 if ((inst.instruction & 0xf0) == 0x60 \
6224 && val != 0xf) \
6225 { \
6226 /* ISB can only take SY as an option. */ \
6227 inst.error = _("invalid barrier type"); \
6228 goto failure; \
6229 } \
6230 } \
6231 } \
6232 while (0)
6233
c19d1205
ZW
6234 skip_whitespace (str);
6235
6236 for (i = 0; upat[i] != OP_stop; i++)
6237 {
5be8be5d
DG
6238 op_parse_code = upat[i];
6239 if (op_parse_code >= 1<<16)
6240 op_parse_code = thumb ? (op_parse_code >> 16)
6241 : (op_parse_code & ((1<<16)-1));
6242
6243 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6244 {
6245 /* Remember where we are in case we need to backtrack. */
9c2799c2 6246 gas_assert (!backtrack_pos);
c19d1205
ZW
6247 backtrack_pos = str;
6248 backtrack_error = inst.error;
6249 backtrack_index = i;
6250 }
6251
b6702015 6252 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6253 po_char_or_fail (',');
6254
5be8be5d 6255 switch (op_parse_code)
c19d1205
ZW
6256 {
6257 /* Registers */
6258 case OP_oRRnpc:
5be8be5d 6259 case OP_oRRnpcsp:
c19d1205 6260 case OP_RRnpc:
5be8be5d 6261 case OP_RRnpcsp:
c19d1205
ZW
6262 case OP_oRR:
6263 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6264 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6265 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6266 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6267 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6268 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
6269 case OP_oRND:
6270 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6271 case OP_RVC:
6272 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6273 break;
6274 /* Also accept generic coprocessor regs for unknown registers. */
6275 coproc_reg:
6276 po_reg_or_fail (REG_TYPE_CN);
6277 break;
c19d1205
ZW
6278 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6279 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6280 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6281 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6282 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6283 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6284 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6285 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6286 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6287 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
6288 case OP_oRNQ:
6289 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6290 case OP_oRNDQ:
6291 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
6292 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6293 case OP_oRNSDQ:
6294 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
6295
6296 /* Neon scalar. Using an element size of 8 means that some invalid
6297 scalars are accepted here, so deal with those in later code. */
6298 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6299
5287ad62
JB
6300 case OP_RNDQ_I0:
6301 {
6302 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6303 break;
6304 try_imm0:
6305 po_imm_or_fail (0, 0, TRUE);
6306 }
6307 break;
6308
037e8744
JB
6309 case OP_RVSD_I0:
6310 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6311 break;
6312
5287ad62
JB
6313 case OP_RR_RNSC:
6314 {
6315 po_scalar_or_goto (8, try_rr);
6316 break;
6317 try_rr:
6318 po_reg_or_fail (REG_TYPE_RN);
6319 }
6320 break;
6321
037e8744
JB
6322 case OP_RNSDQ_RNSC:
6323 {
6324 po_scalar_or_goto (8, try_nsdq);
6325 break;
6326 try_nsdq:
6327 po_reg_or_fail (REG_TYPE_NSDQ);
6328 }
6329 break;
6330
5287ad62
JB
6331 case OP_RNDQ_RNSC:
6332 {
6333 po_scalar_or_goto (8, try_ndq);
6334 break;
6335 try_ndq:
6336 po_reg_or_fail (REG_TYPE_NDQ);
6337 }
6338 break;
6339
6340 case OP_RND_RNSC:
6341 {
6342 po_scalar_or_goto (8, try_vfd);
6343 break;
6344 try_vfd:
6345 po_reg_or_fail (REG_TYPE_VFD);
6346 }
6347 break;
6348
6349 case OP_VMOV:
6350 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6351 not careful then bad things might happen. */
6352 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6353 break;
6354
4316f0d2 6355 case OP_RNDQ_Ibig:
5287ad62 6356 {
4316f0d2 6357 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
5287ad62 6358 break;
4316f0d2 6359 try_immbig:
5287ad62
JB
6360 /* There's a possibility of getting a 64-bit immediate here, so
6361 we need special handling. */
6362 if (parse_big_immediate (&str, i) == FAIL)
6363 {
6364 inst.error = _("immediate value is out of range");
6365 goto failure;
6366 }
6367 }
6368 break;
6369
6370 case OP_RNDQ_I63b:
6371 {
6372 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6373 break;
6374 try_shimm:
6375 po_imm_or_fail (0, 63, TRUE);
6376 }
6377 break;
c19d1205
ZW
6378
6379 case OP_RRnpcb:
6380 po_char_or_fail ('[');
6381 po_reg_or_fail (REG_TYPE_RN);
6382 po_char_or_fail (']');
6383 break;
a737bd4d 6384
55881a11 6385 case OP_RRnpctw:
c19d1205 6386 case OP_RRw:
b6702015 6387 case OP_oRRw:
c19d1205
ZW
6388 po_reg_or_fail (REG_TYPE_RN);
6389 if (skip_past_char (&str, '!') == SUCCESS)
6390 inst.operands[i].writeback = 1;
6391 break;
6392
6393 /* Immediates */
6394 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6395 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6396 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 6397 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6398 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6399 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 6400 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6401 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
6402 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6403 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6404 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6405 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6406
6407 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6408 case OP_oI7b:
6409 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6410 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6411 case OP_oI31b:
6412 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 6413 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
6414 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6415
6416 /* Immediate variants */
6417 case OP_oI255c:
6418 po_char_or_fail ('{');
6419 po_imm_or_fail (0, 255, TRUE);
6420 po_char_or_fail ('}');
6421 break;
6422
6423 case OP_I31w:
6424 /* The expression parser chokes on a trailing !, so we have
6425 to find it first and zap it. */
6426 {
6427 char *s = str;
6428 while (*s && *s != ',')
6429 s++;
6430 if (s[-1] == '!')
6431 {
6432 s[-1] = '\0';
6433 inst.operands[i].writeback = 1;
6434 }
6435 po_imm_or_fail (0, 31, TRUE);
6436 if (str == s - 1)
6437 str = s;
6438 }
6439 break;
6440
6441 /* Expressions */
6442 case OP_EXPi: EXPi:
6443 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6444 GE_OPT_PREFIX));
6445 break;
6446
6447 case OP_EXP:
6448 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6449 GE_NO_PREFIX));
6450 break;
6451
6452 case OP_EXPr: EXPr:
6453 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6454 GE_NO_PREFIX));
6455 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6456 {
c19d1205
ZW
6457 val = parse_reloc (&str);
6458 if (val == -1)
6459 {
6460 inst.error = _("unrecognized relocation suffix");
6461 goto failure;
6462 }
6463 else if (val != BFD_RELOC_UNUSED)
6464 {
6465 inst.operands[i].imm = val;
6466 inst.operands[i].hasreloc = 1;
6467 }
a737bd4d 6468 }
c19d1205 6469 break;
a737bd4d 6470
b6895b4f
PB
6471 /* Operand for MOVW or MOVT. */
6472 case OP_HALF:
6473 po_misc_or_fail (parse_half (&str));
6474 break;
6475
e07e6e58 6476 /* Register or expression. */
c19d1205
ZW
6477 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6478 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6479
e07e6e58 6480 /* Register or immediate. */
c19d1205
ZW
6481 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6482 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6483
c19d1205
ZW
6484 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6485 IF:
6486 if (!is_immediate_prefix (*str))
6487 goto bad_args;
6488 str++;
6489 val = parse_fpa_immediate (&str);
6490 if (val == FAIL)
6491 goto failure;
6492 /* FPA immediates are encoded as registers 8-15.
6493 parse_fpa_immediate has already applied the offset. */
6494 inst.operands[i].reg = val;
6495 inst.operands[i].isreg = 1;
6496 break;
09d92015 6497
2d447fca
JM
6498 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6499 I32z: po_imm_or_fail (0, 32, FALSE); break;
6500
e07e6e58 6501 /* Two kinds of register. */
c19d1205
ZW
6502 case OP_RIWR_RIWC:
6503 {
6504 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6505 if (!rege
6506 || (rege->type != REG_TYPE_MMXWR
6507 && rege->type != REG_TYPE_MMXWC
6508 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6509 {
6510 inst.error = _("iWMMXt data or control register expected");
6511 goto failure;
6512 }
6513 inst.operands[i].reg = rege->number;
6514 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6515 }
6516 break;
09d92015 6517
41adaa5c
JM
6518 case OP_RIWC_RIWG:
6519 {
6520 struct reg_entry *rege = arm_reg_parse_multi (&str);
6521 if (!rege
6522 || (rege->type != REG_TYPE_MMXWC
6523 && rege->type != REG_TYPE_MMXWCG))
6524 {
6525 inst.error = _("iWMMXt control register expected");
6526 goto failure;
6527 }
6528 inst.operands[i].reg = rege->number;
6529 inst.operands[i].isreg = 1;
6530 }
6531 break;
6532
c19d1205
ZW
6533 /* Misc */
6534 case OP_CPSF: val = parse_cps_flags (&str); break;
6535 case OP_ENDI: val = parse_endian_specifier (&str); break;
6536 case OP_oROR: val = parse_ror (&str); break;
c19d1205 6537 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6538 case OP_oBARRIER_I15:
6539 po_barrier_or_imm (str); break;
6540 immediate:
6541 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6542 goto failure;
6543 break;
c19d1205 6544
d2cd1205
JB
6545 case OP_wPSR:
6546 case OP_rPSR:
90ec0d68
MGD
6547 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6548 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6549 {
6550 inst.error = _("Banked registers are not available with this "
6551 "architecture.");
6552 goto failure;
6553 }
6554 break;
d2cd1205
JB
6555 try_psr:
6556 val = parse_psr (&str, op_parse_code == OP_wPSR);
6557 break;
037e8744
JB
6558
6559 case OP_APSR_RR:
6560 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6561 break;
6562 try_apsr:
6563 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6564 instruction). */
6565 if (strncasecmp (str, "APSR_", 5) == 0)
6566 {
6567 unsigned found = 0;
6568 str += 5;
6569 while (found < 15)
6570 switch (*str++)
6571 {
6572 case 'c': found = (found & 1) ? 16 : found | 1; break;
6573 case 'n': found = (found & 2) ? 16 : found | 2; break;
6574 case 'z': found = (found & 4) ? 16 : found | 4; break;
6575 case 'v': found = (found & 8) ? 16 : found | 8; break;
6576 default: found = 16;
6577 }
6578 if (found != 15)
6579 goto failure;
6580 inst.operands[i].isvec = 1;
f7c21dc7
NC
6581 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6582 inst.operands[i].reg = REG_PC;
037e8744
JB
6583 }
6584 else
6585 goto failure;
6586 break;
6587
92e90b6e
PB
6588 case OP_TB:
6589 po_misc_or_fail (parse_tb (&str));
6590 break;
6591
e07e6e58 6592 /* Register lists. */
c19d1205
ZW
6593 case OP_REGLST:
6594 val = parse_reg_list (&str);
6595 if (*str == '^')
6596 {
6597 inst.operands[1].writeback = 1;
6598 str++;
6599 }
6600 break;
09d92015 6601
c19d1205 6602 case OP_VRSLST:
5287ad62 6603 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6604 break;
09d92015 6605
c19d1205 6606 case OP_VRDLST:
5287ad62 6607 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6608 break;
a737bd4d 6609
037e8744
JB
6610 case OP_VRSDLST:
6611 /* Allow Q registers too. */
6612 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6613 REGLIST_NEON_D);
6614 if (val == FAIL)
6615 {
6616 inst.error = NULL;
6617 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6618 REGLIST_VFP_S);
6619 inst.operands[i].issingle = 1;
6620 }
6621 break;
6622
5287ad62
JB
6623 case OP_NRDLST:
6624 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6625 REGLIST_NEON_D);
6626 break;
6627
6628 case OP_NSTRLST:
dcbf9037
JB
6629 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6630 &inst.operands[i].vectype);
5287ad62
JB
6631 break;
6632
c19d1205
ZW
6633 /* Addressing modes */
6634 case OP_ADDR:
6635 po_misc_or_fail (parse_address (&str, i));
6636 break;
09d92015 6637
4962c51a
MS
6638 case OP_ADDRGLDR:
6639 po_misc_or_fail_no_backtrack (
6640 parse_address_group_reloc (&str, i, GROUP_LDR));
6641 break;
6642
6643 case OP_ADDRGLDRS:
6644 po_misc_or_fail_no_backtrack (
6645 parse_address_group_reloc (&str, i, GROUP_LDRS));
6646 break;
6647
6648 case OP_ADDRGLDC:
6649 po_misc_or_fail_no_backtrack (
6650 parse_address_group_reloc (&str, i, GROUP_LDC));
6651 break;
6652
c19d1205
ZW
6653 case OP_SH:
6654 po_misc_or_fail (parse_shifter_operand (&str, i));
6655 break;
09d92015 6656
4962c51a
MS
6657 case OP_SHG:
6658 po_misc_or_fail_no_backtrack (
6659 parse_shifter_operand_group_reloc (&str, i));
6660 break;
6661
c19d1205
ZW
6662 case OP_oSHll:
6663 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6664 break;
09d92015 6665
c19d1205
ZW
6666 case OP_oSHar:
6667 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6668 break;
09d92015 6669
c19d1205
ZW
6670 case OP_oSHllar:
6671 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6672 break;
09d92015 6673
c19d1205 6674 default:
5be8be5d 6675 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 6676 }
09d92015 6677
c19d1205
ZW
6678 /* Various value-based sanity checks and shared operations. We
6679 do not signal immediate failures for the register constraints;
6680 this allows a syntax error to take precedence. */
5be8be5d 6681 switch (op_parse_code)
c19d1205
ZW
6682 {
6683 case OP_oRRnpc:
6684 case OP_RRnpc:
6685 case OP_RRnpcb:
6686 case OP_RRw:
b6702015 6687 case OP_oRRw:
c19d1205
ZW
6688 case OP_RRnpc_I0:
6689 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6690 inst.error = BAD_PC;
6691 break;
09d92015 6692
5be8be5d
DG
6693 case OP_oRRnpcsp:
6694 case OP_RRnpcsp:
6695 if (inst.operands[i].isreg)
6696 {
6697 if (inst.operands[i].reg == REG_PC)
6698 inst.error = BAD_PC;
6699 else if (inst.operands[i].reg == REG_SP)
6700 inst.error = BAD_SP;
6701 }
6702 break;
6703
55881a11
MGD
6704 case OP_RRnpctw:
6705 if (inst.operands[i].isreg
6706 && inst.operands[i].reg == REG_PC
6707 && (inst.operands[i].writeback || thumb))
6708 inst.error = BAD_PC;
6709 break;
6710
c19d1205
ZW
6711 case OP_CPSF:
6712 case OP_ENDI:
6713 case OP_oROR:
d2cd1205
JB
6714 case OP_wPSR:
6715 case OP_rPSR:
c19d1205 6716 case OP_COND:
52e7f43d 6717 case OP_oBARRIER_I15:
c19d1205
ZW
6718 case OP_REGLST:
6719 case OP_VRSLST:
6720 case OP_VRDLST:
037e8744 6721 case OP_VRSDLST:
5287ad62
JB
6722 case OP_NRDLST:
6723 case OP_NSTRLST:
c19d1205
ZW
6724 if (val == FAIL)
6725 goto failure;
6726 inst.operands[i].imm = val;
6727 break;
a737bd4d 6728
c19d1205
ZW
6729 default:
6730 break;
6731 }
09d92015 6732
c19d1205
ZW
6733 /* If we get here, this operand was successfully parsed. */
6734 inst.operands[i].present = 1;
6735 continue;
09d92015 6736
c19d1205 6737 bad_args:
09d92015 6738 inst.error = BAD_ARGS;
c19d1205
ZW
6739
6740 failure:
6741 if (!backtrack_pos)
d252fdde
PB
6742 {
6743 /* The parse routine should already have set inst.error, but set a
5f4273c7 6744 default here just in case. */
d252fdde
PB
6745 if (!inst.error)
6746 inst.error = _("syntax error");
6747 return FAIL;
6748 }
c19d1205
ZW
6749
6750 /* Do not backtrack over a trailing optional argument that
6751 absorbed some text. We will only fail again, with the
6752 'garbage following instruction' error message, which is
6753 probably less helpful than the current one. */
6754 if (backtrack_index == i && backtrack_pos != str
6755 && upat[i+1] == OP_stop)
d252fdde
PB
6756 {
6757 if (!inst.error)
6758 inst.error = _("syntax error");
6759 return FAIL;
6760 }
c19d1205
ZW
6761
6762 /* Try again, skipping the optional argument at backtrack_pos. */
6763 str = backtrack_pos;
6764 inst.error = backtrack_error;
6765 inst.operands[backtrack_index].present = 0;
6766 i = backtrack_index;
6767 backtrack_pos = 0;
09d92015 6768 }
09d92015 6769
c19d1205
ZW
6770 /* Check that we have parsed all the arguments. */
6771 if (*str != '\0' && !inst.error)
6772 inst.error = _("garbage following instruction");
09d92015 6773
c19d1205 6774 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6775}
6776
c19d1205
ZW
6777#undef po_char_or_fail
6778#undef po_reg_or_fail
6779#undef po_reg_or_goto
6780#undef po_imm_or_fail
5287ad62 6781#undef po_scalar_or_fail
52e7f43d 6782#undef po_barrier_or_imm
e07e6e58 6783
c19d1205 6784/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6785#define constraint(expr, err) \
6786 do \
c19d1205 6787 { \
e07e6e58
NC
6788 if (expr) \
6789 { \
6790 inst.error = err; \
6791 return; \
6792 } \
c19d1205 6793 } \
e07e6e58 6794 while (0)
c19d1205 6795
fdfde340
JM
6796/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6797 instructions are unpredictable if these registers are used. This
6798 is the BadReg predicate in ARM's Thumb-2 documentation. */
6799#define reject_bad_reg(reg) \
6800 do \
6801 if (reg == REG_SP || reg == REG_PC) \
6802 { \
6803 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6804 return; \
6805 } \
6806 while (0)
6807
94206790
MM
6808/* If REG is R13 (the stack pointer), warn that its use is
6809 deprecated. */
6810#define warn_deprecated_sp(reg) \
6811 do \
6812 if (warn_on_deprecated && reg == REG_SP) \
6813 as_warn (_("use of r13 is deprecated")); \
6814 while (0)
6815
c19d1205
ZW
6816/* Functions for operand encoding. ARM, then Thumb. */
6817
6818#define rotate_left(v, n) (v << n | v >> (32 - n))
6819
6820/* If VAL can be encoded in the immediate field of an ARM instruction,
6821 return the encoded form. Otherwise, return FAIL. */
6822
6823static unsigned int
6824encode_arm_immediate (unsigned int val)
09d92015 6825{
c19d1205
ZW
6826 unsigned int a, i;
6827
6828 for (i = 0; i < 32; i += 2)
6829 if ((a = rotate_left (val, i)) <= 0xff)
6830 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6831
6832 return FAIL;
09d92015
MM
6833}
6834
c19d1205
ZW
6835/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6836 return the encoded form. Otherwise, return FAIL. */
6837static unsigned int
6838encode_thumb32_immediate (unsigned int val)
09d92015 6839{
c19d1205 6840 unsigned int a, i;
09d92015 6841
9c3c69f2 6842 if (val <= 0xff)
c19d1205 6843 return val;
a737bd4d 6844
9c3c69f2 6845 for (i = 1; i <= 24; i++)
09d92015 6846 {
9c3c69f2
PB
6847 a = val >> i;
6848 if ((val & ~(0xff << i)) == 0)
6849 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6850 }
a737bd4d 6851
c19d1205
ZW
6852 a = val & 0xff;
6853 if (val == ((a << 16) | a))
6854 return 0x100 | a;
6855 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6856 return 0x300 | a;
09d92015 6857
c19d1205
ZW
6858 a = val & 0xff00;
6859 if (val == ((a << 16) | a))
6860 return 0x200 | (a >> 8);
a737bd4d 6861
c19d1205 6862 return FAIL;
09d92015 6863}
5287ad62 6864/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6865
6866static void
5287ad62
JB
6867encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6868{
6869 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6870 && reg > 15)
6871 {
b1cc4aeb 6872 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6873 {
6874 if (thumb_mode)
6875 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6876 fpu_vfp_ext_d32);
5287ad62
JB
6877 else
6878 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6879 fpu_vfp_ext_d32);
5287ad62
JB
6880 }
6881 else
6882 {
dcbf9037 6883 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6884 return;
6885 }
6886 }
6887
c19d1205 6888 switch (pos)
09d92015 6889 {
c19d1205
ZW
6890 case VFP_REG_Sd:
6891 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6892 break;
6893
6894 case VFP_REG_Sn:
6895 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6896 break;
6897
6898 case VFP_REG_Sm:
6899 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6900 break;
6901
5287ad62
JB
6902 case VFP_REG_Dd:
6903 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6904 break;
5f4273c7 6905
5287ad62
JB
6906 case VFP_REG_Dn:
6907 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6908 break;
5f4273c7 6909
5287ad62
JB
6910 case VFP_REG_Dm:
6911 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6912 break;
6913
c19d1205
ZW
6914 default:
6915 abort ();
09d92015 6916 }
09d92015
MM
6917}
6918
c19d1205 6919/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6920 if any, is handled by md_apply_fix. */
09d92015 6921static void
c19d1205 6922encode_arm_shift (int i)
09d92015 6923{
c19d1205
ZW
6924 if (inst.operands[i].shift_kind == SHIFT_RRX)
6925 inst.instruction |= SHIFT_ROR << 5;
6926 else
09d92015 6927 {
c19d1205
ZW
6928 inst.instruction |= inst.operands[i].shift_kind << 5;
6929 if (inst.operands[i].immisreg)
6930 {
6931 inst.instruction |= SHIFT_BY_REG;
6932 inst.instruction |= inst.operands[i].imm << 8;
6933 }
6934 else
6935 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6936 }
c19d1205 6937}
09d92015 6938
c19d1205
ZW
6939static void
6940encode_arm_shifter_operand (int i)
6941{
6942 if (inst.operands[i].isreg)
09d92015 6943 {
c19d1205
ZW
6944 inst.instruction |= inst.operands[i].reg;
6945 encode_arm_shift (i);
09d92015 6946 }
c19d1205
ZW
6947 else
6948 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6949}
6950
c19d1205 6951/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6952static void
c19d1205 6953encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6954{
9c2799c2 6955 gas_assert (inst.operands[i].isreg);
c19d1205 6956 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6957
c19d1205 6958 if (inst.operands[i].preind)
09d92015 6959 {
c19d1205
ZW
6960 if (is_t)
6961 {
6962 inst.error = _("instruction does not accept preindexed addressing");
6963 return;
6964 }
6965 inst.instruction |= PRE_INDEX;
6966 if (inst.operands[i].writeback)
6967 inst.instruction |= WRITE_BACK;
09d92015 6968
c19d1205
ZW
6969 }
6970 else if (inst.operands[i].postind)
6971 {
9c2799c2 6972 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
6973 if (is_t)
6974 inst.instruction |= WRITE_BACK;
6975 }
6976 else /* unindexed - only for coprocessor */
09d92015 6977 {
c19d1205 6978 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6979 return;
6980 }
6981
c19d1205
ZW
6982 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6983 && (((inst.instruction & 0x000f0000) >> 16)
6984 == ((inst.instruction & 0x0000f000) >> 12)))
6985 as_warn ((inst.instruction & LOAD_BIT)
6986 ? _("destination register same as write-back base")
6987 : _("source register same as write-back base"));
09d92015
MM
6988}
6989
c19d1205
ZW
6990/* inst.operands[i] was set up by parse_address. Encode it into an
6991 ARM-format mode 2 load or store instruction. If is_t is true,
6992 reject forms that cannot be used with a T instruction (i.e. not
6993 post-indexed). */
a737bd4d 6994static void
c19d1205 6995encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6996{
5be8be5d
DG
6997 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
6998
c19d1205 6999 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7000
c19d1205 7001 if (inst.operands[i].immisreg)
09d92015 7002 {
5be8be5d
DG
7003 constraint ((inst.operands[i].imm == REG_PC
7004 || (is_pc && inst.operands[i].writeback)),
7005 BAD_PC_ADDRESSING);
c19d1205
ZW
7006 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7007 inst.instruction |= inst.operands[i].imm;
7008 if (!inst.operands[i].negative)
7009 inst.instruction |= INDEX_UP;
7010 if (inst.operands[i].shifted)
7011 {
7012 if (inst.operands[i].shift_kind == SHIFT_RRX)
7013 inst.instruction |= SHIFT_ROR << 5;
7014 else
7015 {
7016 inst.instruction |= inst.operands[i].shift_kind << 5;
7017 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7018 }
7019 }
09d92015 7020 }
c19d1205 7021 else /* immediate offset in inst.reloc */
09d92015 7022 {
5be8be5d
DG
7023 if (is_pc && !inst.reloc.pc_rel)
7024 {
7025 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7026
7027 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7028 cannot use PC in addressing.
7029 PC cannot be used in writeback addressing, either. */
7030 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7031 BAD_PC_ADDRESSING);
23a10334 7032
dc5ec521 7033 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7034 if (warn_on_deprecated
7035 && !is_load
7036 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7037 as_warn (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7038 }
7039
c19d1205
ZW
7040 if (inst.reloc.type == BFD_RELOC_UNUSED)
7041 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 7042 }
09d92015
MM
7043}
7044
c19d1205
ZW
7045/* inst.operands[i] was set up by parse_address. Encode it into an
7046 ARM-format mode 3 load or store instruction. Reject forms that
7047 cannot be used with such instructions. If is_t is true, reject
7048 forms that cannot be used with a T instruction (i.e. not
7049 post-indexed). */
7050static void
7051encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7052{
c19d1205 7053 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7054 {
c19d1205
ZW
7055 inst.error = _("instruction does not accept scaled register index");
7056 return;
09d92015 7057 }
a737bd4d 7058
c19d1205 7059 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7060
c19d1205
ZW
7061 if (inst.operands[i].immisreg)
7062 {
5be8be5d
DG
7063 constraint ((inst.operands[i].imm == REG_PC
7064 || inst.operands[i].reg == REG_PC),
7065 BAD_PC_ADDRESSING);
c19d1205
ZW
7066 inst.instruction |= inst.operands[i].imm;
7067 if (!inst.operands[i].negative)
7068 inst.instruction |= INDEX_UP;
7069 }
7070 else /* immediate offset in inst.reloc */
7071 {
5be8be5d
DG
7072 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7073 && inst.operands[i].writeback),
7074 BAD_PC_WRITEBACK);
c19d1205
ZW
7075 inst.instruction |= HWOFFSET_IMM;
7076 if (inst.reloc.type == BFD_RELOC_UNUSED)
7077 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 7078 }
a737bd4d
NC
7079}
7080
c19d1205
ZW
7081/* inst.operands[i] was set up by parse_address. Encode it into an
7082 ARM-format instruction. Reject all forms which cannot be encoded
7083 into a coprocessor load/store instruction. If wb_ok is false,
7084 reject use of writeback; if unind_ok is false, reject use of
7085 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
7086 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
7087 (in which case it is preserved). */
09d92015 7088
c19d1205
ZW
7089static int
7090encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 7091{
c19d1205 7092 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7093
9c2799c2 7094 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 7095
c19d1205 7096 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 7097 {
9c2799c2 7098 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
7099 if (!unind_ok)
7100 {
7101 inst.error = _("instruction does not support unindexed addressing");
7102 return FAIL;
7103 }
7104 inst.instruction |= inst.operands[i].imm;
7105 inst.instruction |= INDEX_UP;
7106 return SUCCESS;
09d92015 7107 }
a737bd4d 7108
c19d1205
ZW
7109 if (inst.operands[i].preind)
7110 inst.instruction |= PRE_INDEX;
a737bd4d 7111
c19d1205 7112 if (inst.operands[i].writeback)
09d92015 7113 {
c19d1205
ZW
7114 if (inst.operands[i].reg == REG_PC)
7115 {
7116 inst.error = _("pc may not be used with write-back");
7117 return FAIL;
7118 }
7119 if (!wb_ok)
7120 {
7121 inst.error = _("instruction does not support writeback");
7122 return FAIL;
7123 }
7124 inst.instruction |= WRITE_BACK;
09d92015 7125 }
a737bd4d 7126
c19d1205 7127 if (reloc_override)
21d799b5 7128 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a
MS
7129 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
7130 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
7131 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
7132 {
7133 if (thumb_mode)
7134 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
7135 else
7136 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
7137 }
7138
c19d1205
ZW
7139 return SUCCESS;
7140}
a737bd4d 7141
c19d1205
ZW
7142/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7143 Determine whether it can be performed with a move instruction; if
7144 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7145 return TRUE; if it can't, convert inst.instruction to a literal-pool
7146 load and return FALSE. If this is not a valid thing to do in the
7147 current context, set inst.error and return TRUE.
a737bd4d 7148
c19d1205
ZW
7149 inst.operands[i] describes the destination register. */
7150
c921be7d 7151static bfd_boolean
c19d1205
ZW
7152move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
7153{
53365c0d
PB
7154 unsigned long tbit;
7155
7156 if (thumb_p)
7157 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7158 else
7159 tbit = LOAD_BIT;
7160
7161 if ((inst.instruction & tbit) == 0)
09d92015 7162 {
c19d1205 7163 inst.error = _("invalid pseudo operation");
c921be7d 7164 return TRUE;
09d92015 7165 }
c19d1205 7166 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
7167 {
7168 inst.error = _("constant expression expected");
c921be7d 7169 return TRUE;
09d92015 7170 }
c19d1205 7171 if (inst.reloc.exp.X_op == O_constant)
09d92015 7172 {
c19d1205
ZW
7173 if (thumb_p)
7174 {
53365c0d 7175 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
7176 {
7177 /* This can be done with a mov(1) instruction. */
7178 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7179 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 7180 return TRUE;
c19d1205
ZW
7181 }
7182 }
7183 else
7184 {
7185 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7186 if (value != FAIL)
7187 {
7188 /* This can be done with a mov instruction. */
7189 inst.instruction &= LITERAL_MASK;
7190 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7191 inst.instruction |= value & 0xfff;
c921be7d 7192 return TRUE;
c19d1205 7193 }
09d92015 7194
c19d1205
ZW
7195 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7196 if (value != FAIL)
7197 {
7198 /* This can be done with a mvn instruction. */
7199 inst.instruction &= LITERAL_MASK;
7200 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7201 inst.instruction |= value & 0xfff;
c921be7d 7202 return TRUE;
c19d1205
ZW
7203 }
7204 }
09d92015
MM
7205 }
7206
c19d1205
ZW
7207 if (add_to_lit_pool () == FAIL)
7208 {
7209 inst.error = _("literal pool insertion failed");
c921be7d 7210 return TRUE;
c19d1205
ZW
7211 }
7212 inst.operands[1].reg = REG_PC;
7213 inst.operands[1].isreg = 1;
7214 inst.operands[1].preind = 1;
7215 inst.reloc.pc_rel = 1;
7216 inst.reloc.type = (thumb_p
7217 ? BFD_RELOC_ARM_THUMB_OFFSET
7218 : (mode_3
7219 ? BFD_RELOC_ARM_HWLITERAL
7220 : BFD_RELOC_ARM_LITERAL));
c921be7d 7221 return FALSE;
09d92015
MM
7222}
7223
5f4273c7 7224/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
7225 First some generics; their names are taken from the conventional
7226 bit positions for register arguments in ARM format instructions. */
09d92015 7227
a737bd4d 7228static void
c19d1205 7229do_noargs (void)
09d92015 7230{
c19d1205 7231}
a737bd4d 7232
c19d1205
ZW
7233static void
7234do_rd (void)
7235{
7236 inst.instruction |= inst.operands[0].reg << 12;
7237}
a737bd4d 7238
c19d1205
ZW
7239static void
7240do_rd_rm (void)
7241{
7242 inst.instruction |= inst.operands[0].reg << 12;
7243 inst.instruction |= inst.operands[1].reg;
7244}
09d92015 7245
c19d1205
ZW
7246static void
7247do_rd_rn (void)
7248{
7249 inst.instruction |= inst.operands[0].reg << 12;
7250 inst.instruction |= inst.operands[1].reg << 16;
7251}
a737bd4d 7252
c19d1205
ZW
7253static void
7254do_rn_rd (void)
7255{
7256 inst.instruction |= inst.operands[0].reg << 16;
7257 inst.instruction |= inst.operands[1].reg << 12;
7258}
09d92015 7259
c19d1205
ZW
7260static void
7261do_rd_rm_rn (void)
7262{
9a64e435 7263 unsigned Rn = inst.operands[2].reg;
708587a4 7264 /* Enforce restrictions on SWP instruction. */
9a64e435 7265 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
7266 {
7267 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7268 _("Rn must not overlap other operands"));
7269
7270 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
7271 if (warn_on_deprecated
7272 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7273 as_warn (_("swp{b} use is deprecated for this architecture"));
7274
7275 }
c19d1205
ZW
7276 inst.instruction |= inst.operands[0].reg << 12;
7277 inst.instruction |= inst.operands[1].reg;
9a64e435 7278 inst.instruction |= Rn << 16;
c19d1205 7279}
09d92015 7280
c19d1205
ZW
7281static void
7282do_rd_rn_rm (void)
7283{
7284 inst.instruction |= inst.operands[0].reg << 12;
7285 inst.instruction |= inst.operands[1].reg << 16;
7286 inst.instruction |= inst.operands[2].reg;
7287}
a737bd4d 7288
c19d1205
ZW
7289static void
7290do_rm_rd_rn (void)
7291{
5be8be5d
DG
7292 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7293 constraint (((inst.reloc.exp.X_op != O_constant
7294 && inst.reloc.exp.X_op != O_illegal)
7295 || inst.reloc.exp.X_add_number != 0),
7296 BAD_ADDR_MODE);
c19d1205
ZW
7297 inst.instruction |= inst.operands[0].reg;
7298 inst.instruction |= inst.operands[1].reg << 12;
7299 inst.instruction |= inst.operands[2].reg << 16;
7300}
09d92015 7301
c19d1205
ZW
7302static void
7303do_imm0 (void)
7304{
7305 inst.instruction |= inst.operands[0].imm;
7306}
09d92015 7307
c19d1205
ZW
7308static void
7309do_rd_cpaddr (void)
7310{
7311 inst.instruction |= inst.operands[0].reg << 12;
7312 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 7313}
a737bd4d 7314
c19d1205
ZW
7315/* ARM instructions, in alphabetical order by function name (except
7316 that wrapper functions appear immediately after the function they
7317 wrap). */
09d92015 7318
c19d1205
ZW
7319/* This is a pseudo-op of the form "adr rd, label" to be converted
7320 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
7321
7322static void
c19d1205 7323do_adr (void)
09d92015 7324{
c19d1205 7325 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7326
c19d1205
ZW
7327 /* Frag hacking will turn this into a sub instruction if the offset turns
7328 out to be negative. */
7329 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 7330 inst.reloc.pc_rel = 1;
2fc8bdac 7331 inst.reloc.exp.X_add_number -= 8;
c19d1205 7332}
b99bd4ef 7333
c19d1205
ZW
7334/* This is a pseudo-op of the form "adrl rd, label" to be converted
7335 into a relative address of the form:
7336 add rd, pc, #low(label-.-8)"
7337 add rd, rd, #high(label-.-8)" */
b99bd4ef 7338
c19d1205
ZW
7339static void
7340do_adrl (void)
7341{
7342 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7343
c19d1205
ZW
7344 /* Frag hacking will turn this into a sub instruction if the offset turns
7345 out to be negative. */
7346 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
7347 inst.reloc.pc_rel = 1;
7348 inst.size = INSN_SIZE * 2;
2fc8bdac 7349 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
7350}
7351
b99bd4ef 7352static void
c19d1205 7353do_arit (void)
b99bd4ef 7354{
c19d1205
ZW
7355 if (!inst.operands[1].present)
7356 inst.operands[1].reg = inst.operands[0].reg;
7357 inst.instruction |= inst.operands[0].reg << 12;
7358 inst.instruction |= inst.operands[1].reg << 16;
7359 encode_arm_shifter_operand (2);
7360}
b99bd4ef 7361
62b3e311
PB
7362static void
7363do_barrier (void)
7364{
7365 if (inst.operands[0].present)
7366 {
7367 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
7368 && inst.operands[0].imm > 0xf
7369 && inst.operands[0].imm < 0x0,
bd3ba5d1 7370 _("bad barrier type"));
62b3e311
PB
7371 inst.instruction |= inst.operands[0].imm;
7372 }
7373 else
7374 inst.instruction |= 0xf;
7375}
7376
c19d1205
ZW
7377static void
7378do_bfc (void)
7379{
7380 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7381 constraint (msb > 32, _("bit-field extends past end of register"));
7382 /* The instruction encoding stores the LSB and MSB,
7383 not the LSB and width. */
7384 inst.instruction |= inst.operands[0].reg << 12;
7385 inst.instruction |= inst.operands[1].imm << 7;
7386 inst.instruction |= (msb - 1) << 16;
7387}
b99bd4ef 7388
c19d1205
ZW
7389static void
7390do_bfi (void)
7391{
7392 unsigned int msb;
b99bd4ef 7393
c19d1205
ZW
7394 /* #0 in second position is alternative syntax for bfc, which is
7395 the same instruction but with REG_PC in the Rm field. */
7396 if (!inst.operands[1].isreg)
7397 inst.operands[1].reg = REG_PC;
b99bd4ef 7398
c19d1205
ZW
7399 msb = inst.operands[2].imm + inst.operands[3].imm;
7400 constraint (msb > 32, _("bit-field extends past end of register"));
7401 /* The instruction encoding stores the LSB and MSB,
7402 not the LSB and width. */
7403 inst.instruction |= inst.operands[0].reg << 12;
7404 inst.instruction |= inst.operands[1].reg;
7405 inst.instruction |= inst.operands[2].imm << 7;
7406 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7407}
7408
b99bd4ef 7409static void
c19d1205 7410do_bfx (void)
b99bd4ef 7411{
c19d1205
ZW
7412 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7413 _("bit-field extends past end of register"));
7414 inst.instruction |= inst.operands[0].reg << 12;
7415 inst.instruction |= inst.operands[1].reg;
7416 inst.instruction |= inst.operands[2].imm << 7;
7417 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7418}
09d92015 7419
c19d1205
ZW
7420/* ARM V5 breakpoint instruction (argument parse)
7421 BKPT <16 bit unsigned immediate>
7422 Instruction is not conditional.
7423 The bit pattern given in insns[] has the COND_ALWAYS condition,
7424 and it is an error if the caller tried to override that. */
b99bd4ef 7425
c19d1205
ZW
7426static void
7427do_bkpt (void)
7428{
7429 /* Top 12 of 16 bits to bits 19:8. */
7430 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7431
c19d1205
ZW
7432 /* Bottom 4 of 16 bits to bits 3:0. */
7433 inst.instruction |= inst.operands[0].imm & 0xf;
7434}
09d92015 7435
c19d1205
ZW
7436static void
7437encode_branch (int default_reloc)
7438{
7439 if (inst.operands[0].hasreloc)
7440 {
0855e32b
NS
7441 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
7442 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
7443 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
7444 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
7445 ? BFD_RELOC_ARM_PLT32
7446 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 7447 }
b99bd4ef 7448 else
9ae92b05 7449 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 7450 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7451}
7452
b99bd4ef 7453static void
c19d1205 7454do_branch (void)
b99bd4ef 7455{
39b41c9c
PB
7456#ifdef OBJ_ELF
7457 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7458 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7459 else
7460#endif
7461 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7462}
7463
7464static void
7465do_bl (void)
7466{
7467#ifdef OBJ_ELF
7468 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7469 {
7470 if (inst.cond == COND_ALWAYS)
7471 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7472 else
7473 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7474 }
7475 else
7476#endif
7477 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7478}
b99bd4ef 7479
c19d1205
ZW
7480/* ARM V5 branch-link-exchange instruction (argument parse)
7481 BLX <target_addr> ie BLX(1)
7482 BLX{<condition>} <Rm> ie BLX(2)
7483 Unfortunately, there are two different opcodes for this mnemonic.
7484 So, the insns[].value is not used, and the code here zaps values
7485 into inst.instruction.
7486 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7487
c19d1205
ZW
7488static void
7489do_blx (void)
7490{
7491 if (inst.operands[0].isreg)
b99bd4ef 7492 {
c19d1205
ZW
7493 /* Arg is a register; the opcode provided by insns[] is correct.
7494 It is not illegal to do "blx pc", just useless. */
7495 if (inst.operands[0].reg == REG_PC)
7496 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7497
c19d1205
ZW
7498 inst.instruction |= inst.operands[0].reg;
7499 }
7500 else
b99bd4ef 7501 {
c19d1205 7502 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7503 conditionally, and the opcode must be adjusted.
7504 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7505 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7506 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7507 inst.instruction = 0xfa000000;
267bf995 7508 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7509 }
c19d1205
ZW
7510}
7511
7512static void
7513do_bx (void)
7514{
845b51d6
PB
7515 bfd_boolean want_reloc;
7516
c19d1205
ZW
7517 if (inst.operands[0].reg == REG_PC)
7518 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7519
c19d1205 7520 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7521 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7522 it is for ARMv4t or earlier. */
7523 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7524 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7525 want_reloc = TRUE;
7526
5ad34203 7527#ifdef OBJ_ELF
845b51d6 7528 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7529#endif
584206db 7530 want_reloc = FALSE;
845b51d6
PB
7531
7532 if (want_reloc)
7533 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7534}
7535
c19d1205
ZW
7536
7537/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7538
7539static void
c19d1205 7540do_bxj (void)
a737bd4d 7541{
c19d1205
ZW
7542 if (inst.operands[0].reg == REG_PC)
7543 as_tsktsk (_("use of r15 in bxj is not really useful"));
7544
7545 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7546}
7547
c19d1205
ZW
7548/* Co-processor data operation:
7549 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7550 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7551static void
7552do_cdp (void)
7553{
7554 inst.instruction |= inst.operands[0].reg << 8;
7555 inst.instruction |= inst.operands[1].imm << 20;
7556 inst.instruction |= inst.operands[2].reg << 12;
7557 inst.instruction |= inst.operands[3].reg << 16;
7558 inst.instruction |= inst.operands[4].reg;
7559 inst.instruction |= inst.operands[5].imm << 5;
7560}
a737bd4d
NC
7561
7562static void
c19d1205 7563do_cmp (void)
a737bd4d 7564{
c19d1205
ZW
7565 inst.instruction |= inst.operands[0].reg << 16;
7566 encode_arm_shifter_operand (1);
a737bd4d
NC
7567}
7568
c19d1205
ZW
7569/* Transfer between coprocessor and ARM registers.
7570 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7571 MRC2
7572 MCR{cond}
7573 MCR2
7574
7575 No special properties. */
09d92015
MM
7576
7577static void
c19d1205 7578do_co_reg (void)
09d92015 7579{
fdfde340
JM
7580 unsigned Rd;
7581
7582 Rd = inst.operands[2].reg;
7583 if (thumb_mode)
7584 {
7585 if (inst.instruction == 0xee000010
7586 || inst.instruction == 0xfe000010)
7587 /* MCR, MCR2 */
7588 reject_bad_reg (Rd);
7589 else
7590 /* MRC, MRC2 */
7591 constraint (Rd == REG_SP, BAD_SP);
7592 }
7593 else
7594 {
7595 /* MCR */
7596 if (inst.instruction == 0xe000010)
7597 constraint (Rd == REG_PC, BAD_PC);
7598 }
7599
7600
c19d1205
ZW
7601 inst.instruction |= inst.operands[0].reg << 8;
7602 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7603 inst.instruction |= Rd << 12;
c19d1205
ZW
7604 inst.instruction |= inst.operands[3].reg << 16;
7605 inst.instruction |= inst.operands[4].reg;
7606 inst.instruction |= inst.operands[5].imm << 5;
7607}
09d92015 7608
c19d1205
ZW
7609/* Transfer between coprocessor register and pair of ARM registers.
7610 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7611 MCRR2
7612 MRRC{cond}
7613 MRRC2
b99bd4ef 7614
c19d1205 7615 Two XScale instructions are special cases of these:
09d92015 7616
c19d1205
ZW
7617 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7618 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7619
5f4273c7 7620 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7621
c19d1205
ZW
7622static void
7623do_co_reg2c (void)
7624{
fdfde340
JM
7625 unsigned Rd, Rn;
7626
7627 Rd = inst.operands[2].reg;
7628 Rn = inst.operands[3].reg;
7629
7630 if (thumb_mode)
7631 {
7632 reject_bad_reg (Rd);
7633 reject_bad_reg (Rn);
7634 }
7635 else
7636 {
7637 constraint (Rd == REG_PC, BAD_PC);
7638 constraint (Rn == REG_PC, BAD_PC);
7639 }
7640
c19d1205
ZW
7641 inst.instruction |= inst.operands[0].reg << 8;
7642 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7643 inst.instruction |= Rd << 12;
7644 inst.instruction |= Rn << 16;
c19d1205 7645 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7646}
7647
c19d1205
ZW
7648static void
7649do_cpsi (void)
7650{
7651 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7652 if (inst.operands[1].present)
7653 {
7654 inst.instruction |= CPSI_MMOD;
7655 inst.instruction |= inst.operands[1].imm;
7656 }
c19d1205 7657}
b99bd4ef 7658
62b3e311
PB
7659static void
7660do_dbg (void)
7661{
7662 inst.instruction |= inst.operands[0].imm;
7663}
7664
eea54501
MGD
7665static void
7666do_div (void)
7667{
7668 unsigned Rd, Rn, Rm;
7669
7670 Rd = inst.operands[0].reg;
7671 Rn = (inst.operands[1].present
7672 ? inst.operands[1].reg : Rd);
7673 Rm = inst.operands[2].reg;
7674
7675 constraint ((Rd == REG_PC), BAD_PC);
7676 constraint ((Rn == REG_PC), BAD_PC);
7677 constraint ((Rm == REG_PC), BAD_PC);
7678
7679 inst.instruction |= Rd << 16;
7680 inst.instruction |= Rn << 0;
7681 inst.instruction |= Rm << 8;
7682}
7683
b99bd4ef 7684static void
c19d1205 7685do_it (void)
b99bd4ef 7686{
c19d1205 7687 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7688 process it to do the validation as if in
7689 thumb mode, just in case the code gets
7690 assembled for thumb using the unified syntax. */
7691
c19d1205 7692 inst.size = 0;
e07e6e58
NC
7693 if (unified_syntax)
7694 {
7695 set_it_insn_type (IT_INSN);
7696 now_it.mask = (inst.instruction & 0xf) | 0x10;
7697 now_it.cc = inst.operands[0].imm;
7698 }
09d92015 7699}
b99bd4ef 7700
09d92015 7701static void
c19d1205 7702do_ldmstm (void)
ea6ef066 7703{
c19d1205
ZW
7704 int base_reg = inst.operands[0].reg;
7705 int range = inst.operands[1].imm;
ea6ef066 7706
c19d1205
ZW
7707 inst.instruction |= base_reg << 16;
7708 inst.instruction |= range;
ea6ef066 7709
c19d1205
ZW
7710 if (inst.operands[1].writeback)
7711 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7712
c19d1205 7713 if (inst.operands[0].writeback)
ea6ef066 7714 {
c19d1205
ZW
7715 inst.instruction |= WRITE_BACK;
7716 /* Check for unpredictable uses of writeback. */
7717 if (inst.instruction & LOAD_BIT)
09d92015 7718 {
c19d1205
ZW
7719 /* Not allowed in LDM type 2. */
7720 if ((inst.instruction & LDM_TYPE_2_OR_3)
7721 && ((range & (1 << REG_PC)) == 0))
7722 as_warn (_("writeback of base register is UNPREDICTABLE"));
7723 /* Only allowed if base reg not in list for other types. */
7724 else if (range & (1 << base_reg))
7725 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7726 }
7727 else /* STM. */
7728 {
7729 /* Not allowed for type 2. */
7730 if (inst.instruction & LDM_TYPE_2_OR_3)
7731 as_warn (_("writeback of base register is UNPREDICTABLE"));
7732 /* Only allowed if base reg not in list, or first in list. */
7733 else if ((range & (1 << base_reg))
7734 && (range & ((1 << base_reg) - 1)))
7735 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7736 }
ea6ef066 7737 }
a737bd4d
NC
7738}
7739
c19d1205
ZW
7740/* ARMv5TE load-consecutive (argument parse)
7741 Mode is like LDRH.
7742
7743 LDRccD R, mode
7744 STRccD R, mode. */
7745
a737bd4d 7746static void
c19d1205 7747do_ldrd (void)
a737bd4d 7748{
c19d1205
ZW
7749 constraint (inst.operands[0].reg % 2 != 0,
7750 _("first destination register must be even"));
7751 constraint (inst.operands[1].present
7752 && inst.operands[1].reg != inst.operands[0].reg + 1,
7753 _("can only load two consecutive registers"));
7754 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7755 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7756
c19d1205
ZW
7757 if (!inst.operands[1].present)
7758 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7759
c19d1205 7760 if (inst.instruction & LOAD_BIT)
a737bd4d 7761 {
c19d1205
ZW
7762 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7763 register and the first register written; we have to diagnose
7764 overlap between the base and the second register written here. */
ea6ef066 7765
c19d1205
ZW
7766 if (inst.operands[2].reg == inst.operands[1].reg
7767 && (inst.operands[2].writeback || inst.operands[2].postind))
7768 as_warn (_("base register written back, and overlaps "
7769 "second destination register"));
b05fe5cf 7770
c19d1205
ZW
7771 /* For an index-register load, the index register must not overlap the
7772 destination (even if not write-back). */
7773 else if (inst.operands[2].immisreg
ca3f61f7
NC
7774 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7775 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 7776 as_warn (_("index register overlaps destination register"));
b05fe5cf 7777 }
c19d1205
ZW
7778
7779 inst.instruction |= inst.operands[0].reg << 12;
7780 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7781}
7782
7783static void
c19d1205 7784do_ldrex (void)
b05fe5cf 7785{
c19d1205
ZW
7786 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7787 || inst.operands[1].postind || inst.operands[1].writeback
7788 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7789 || inst.operands[1].negative
7790 /* This can arise if the programmer has written
7791 strex rN, rM, foo
7792 or if they have mistakenly used a register name as the last
7793 operand, eg:
7794 strex rN, rM, rX
7795 It is very difficult to distinguish between these two cases
7796 because "rX" might actually be a label. ie the register
7797 name has been occluded by a symbol of the same name. So we
7798 just generate a general 'bad addressing mode' type error
7799 message and leave it up to the programmer to discover the
7800 true cause and fix their mistake. */
7801 || (inst.operands[1].reg == REG_PC),
7802 BAD_ADDR_MODE);
b05fe5cf 7803
c19d1205
ZW
7804 constraint (inst.reloc.exp.X_op != O_constant
7805 || inst.reloc.exp.X_add_number != 0,
7806 _("offset must be zero in ARM encoding"));
b05fe5cf 7807
5be8be5d
DG
7808 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7809
c19d1205
ZW
7810 inst.instruction |= inst.operands[0].reg << 12;
7811 inst.instruction |= inst.operands[1].reg << 16;
7812 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7813}
7814
7815static void
c19d1205 7816do_ldrexd (void)
b05fe5cf 7817{
c19d1205
ZW
7818 constraint (inst.operands[0].reg % 2 != 0,
7819 _("even register required"));
7820 constraint (inst.operands[1].present
7821 && inst.operands[1].reg != inst.operands[0].reg + 1,
7822 _("can only load two consecutive registers"));
7823 /* If op 1 were present and equal to PC, this function wouldn't
7824 have been called in the first place. */
7825 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7826
c19d1205
ZW
7827 inst.instruction |= inst.operands[0].reg << 12;
7828 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7829}
7830
7831static void
c19d1205 7832do_ldst (void)
b05fe5cf 7833{
c19d1205
ZW
7834 inst.instruction |= inst.operands[0].reg << 12;
7835 if (!inst.operands[1].isreg)
7836 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7837 return;
c19d1205 7838 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7839}
7840
7841static void
c19d1205 7842do_ldstt (void)
b05fe5cf 7843{
c19d1205
ZW
7844 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7845 reject [Rn,...]. */
7846 if (inst.operands[1].preind)
b05fe5cf 7847 {
bd3ba5d1
NC
7848 constraint (inst.reloc.exp.X_op != O_constant
7849 || inst.reloc.exp.X_add_number != 0,
c19d1205 7850 _("this instruction requires a post-indexed address"));
b05fe5cf 7851
c19d1205
ZW
7852 inst.operands[1].preind = 0;
7853 inst.operands[1].postind = 1;
7854 inst.operands[1].writeback = 1;
b05fe5cf 7855 }
c19d1205
ZW
7856 inst.instruction |= inst.operands[0].reg << 12;
7857 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7858}
b05fe5cf 7859
c19d1205 7860/* Halfword and signed-byte load/store operations. */
b05fe5cf 7861
c19d1205
ZW
7862static void
7863do_ldstv4 (void)
7864{
ff4a8d2b 7865 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7866 inst.instruction |= inst.operands[0].reg << 12;
7867 if (!inst.operands[1].isreg)
7868 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7869 return;
c19d1205 7870 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7871}
7872
7873static void
c19d1205 7874do_ldsttv4 (void)
b05fe5cf 7875{
c19d1205
ZW
7876 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7877 reject [Rn,...]. */
7878 if (inst.operands[1].preind)
b05fe5cf 7879 {
bd3ba5d1
NC
7880 constraint (inst.reloc.exp.X_op != O_constant
7881 || inst.reloc.exp.X_add_number != 0,
c19d1205 7882 _("this instruction requires a post-indexed address"));
b05fe5cf 7883
c19d1205
ZW
7884 inst.operands[1].preind = 0;
7885 inst.operands[1].postind = 1;
7886 inst.operands[1].writeback = 1;
b05fe5cf 7887 }
c19d1205
ZW
7888 inst.instruction |= inst.operands[0].reg << 12;
7889 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7890}
b05fe5cf 7891
c19d1205
ZW
7892/* Co-processor register load/store.
7893 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7894static void
7895do_lstc (void)
7896{
7897 inst.instruction |= inst.operands[0].reg << 8;
7898 inst.instruction |= inst.operands[1].reg << 12;
7899 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7900}
7901
b05fe5cf 7902static void
c19d1205 7903do_mlas (void)
b05fe5cf 7904{
8fb9d7b9 7905 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7906 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7907 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7908 && !(inst.instruction & 0x00400000))
8fb9d7b9 7909 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7910
c19d1205
ZW
7911 inst.instruction |= inst.operands[0].reg << 16;
7912 inst.instruction |= inst.operands[1].reg;
7913 inst.instruction |= inst.operands[2].reg << 8;
7914 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7915}
b05fe5cf 7916
c19d1205
ZW
7917static void
7918do_mov (void)
7919{
7920 inst.instruction |= inst.operands[0].reg << 12;
7921 encode_arm_shifter_operand (1);
7922}
b05fe5cf 7923
c19d1205
ZW
7924/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7925static void
7926do_mov16 (void)
7927{
b6895b4f
PB
7928 bfd_vma imm;
7929 bfd_boolean top;
7930
7931 top = (inst.instruction & 0x00400000) != 0;
7932 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7933 _(":lower16: not allowed this instruction"));
7934 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7935 _(":upper16: not allowed instruction"));
c19d1205 7936 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7937 if (inst.reloc.type == BFD_RELOC_UNUSED)
7938 {
7939 imm = inst.reloc.exp.X_add_number;
7940 /* The value is in two pieces: 0:11, 16:19. */
7941 inst.instruction |= (imm & 0x00000fff);
7942 inst.instruction |= (imm & 0x0000f000) << 4;
7943 }
b05fe5cf 7944}
b99bd4ef 7945
037e8744
JB
7946static void do_vfp_nsyn_opcode (const char *);
7947
7948static int
7949do_vfp_nsyn_mrs (void)
7950{
7951 if (inst.operands[0].isvec)
7952 {
7953 if (inst.operands[1].reg != 1)
7954 first_error (_("operand 1 must be FPSCR"));
7955 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7956 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7957 do_vfp_nsyn_opcode ("fmstat");
7958 }
7959 else if (inst.operands[1].isvec)
7960 do_vfp_nsyn_opcode ("fmrx");
7961 else
7962 return FAIL;
5f4273c7 7963
037e8744
JB
7964 return SUCCESS;
7965}
7966
7967static int
7968do_vfp_nsyn_msr (void)
7969{
7970 if (inst.operands[0].isvec)
7971 do_vfp_nsyn_opcode ("fmxr");
7972 else
7973 return FAIL;
7974
7975 return SUCCESS;
7976}
7977
f7c21dc7
NC
7978static void
7979do_vmrs (void)
7980{
7981 unsigned Rt = inst.operands[0].reg;
7982
7983 if (thumb_mode && inst.operands[0].reg == REG_SP)
7984 {
7985 inst.error = BAD_SP;
7986 return;
7987 }
7988
7989 /* APSR_ sets isvec. All other refs to PC are illegal. */
7990 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
7991 {
7992 inst.error = BAD_PC;
7993 return;
7994 }
7995
7996 if (inst.operands[1].reg != 1)
7997 first_error (_("operand 1 must be FPSCR"));
7998
7999 inst.instruction |= (Rt << 12);
8000}
8001
8002static void
8003do_vmsr (void)
8004{
8005 unsigned Rt = inst.operands[1].reg;
8006
8007 if (thumb_mode)
8008 reject_bad_reg (Rt);
8009 else if (Rt == REG_PC)
8010 {
8011 inst.error = BAD_PC;
8012 return;
8013 }
8014
8015 if (inst.operands[0].reg != 1)
8016 first_error (_("operand 0 must be FPSCR"));
8017
8018 inst.instruction |= (Rt << 12);
8019}
8020
b99bd4ef 8021static void
c19d1205 8022do_mrs (void)
b99bd4ef 8023{
90ec0d68
MGD
8024 unsigned br;
8025
037e8744
JB
8026 if (do_vfp_nsyn_mrs () == SUCCESS)
8027 return;
8028
ff4a8d2b 8029 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 8030 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
8031
8032 if (inst.operands[1].isreg)
8033 {
8034 br = inst.operands[1].reg;
8035 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
8036 as_bad (_("bad register for mrs"));
8037 }
8038 else
8039 {
8040 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
8041 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
8042 != (PSR_c|PSR_f),
d2cd1205 8043 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
8044 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
8045 }
8046
8047 inst.instruction |= br;
c19d1205 8048}
b99bd4ef 8049
c19d1205
ZW
8050/* Two possible forms:
8051 "{C|S}PSR_<field>, Rm",
8052 "{C|S}PSR_f, #expression". */
b99bd4ef 8053
c19d1205
ZW
8054static void
8055do_msr (void)
8056{
037e8744
JB
8057 if (do_vfp_nsyn_msr () == SUCCESS)
8058 return;
8059
c19d1205
ZW
8060 inst.instruction |= inst.operands[0].imm;
8061 if (inst.operands[1].isreg)
8062 inst.instruction |= inst.operands[1].reg;
8063 else
b99bd4ef 8064 {
c19d1205
ZW
8065 inst.instruction |= INST_IMMEDIATE;
8066 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8067 inst.reloc.pc_rel = 0;
b99bd4ef 8068 }
b99bd4ef
NC
8069}
8070
c19d1205
ZW
8071static void
8072do_mul (void)
a737bd4d 8073{
ff4a8d2b
NC
8074 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
8075
c19d1205
ZW
8076 if (!inst.operands[2].present)
8077 inst.operands[2].reg = inst.operands[0].reg;
8078 inst.instruction |= inst.operands[0].reg << 16;
8079 inst.instruction |= inst.operands[1].reg;
8080 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 8081
8fb9d7b9
MS
8082 if (inst.operands[0].reg == inst.operands[1].reg
8083 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8084 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
8085}
8086
c19d1205
ZW
8087/* Long Multiply Parser
8088 UMULL RdLo, RdHi, Rm, Rs
8089 SMULL RdLo, RdHi, Rm, Rs
8090 UMLAL RdLo, RdHi, Rm, Rs
8091 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
8092
8093static void
c19d1205 8094do_mull (void)
b99bd4ef 8095{
c19d1205
ZW
8096 inst.instruction |= inst.operands[0].reg << 12;
8097 inst.instruction |= inst.operands[1].reg << 16;
8098 inst.instruction |= inst.operands[2].reg;
8099 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 8100
682b27ad
PB
8101 /* rdhi and rdlo must be different. */
8102 if (inst.operands[0].reg == inst.operands[1].reg)
8103 as_tsktsk (_("rdhi and rdlo must be different"));
8104
8105 /* rdhi, rdlo and rm must all be different before armv6. */
8106 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 8107 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 8108 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
8109 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
8110}
b99bd4ef 8111
c19d1205
ZW
8112static void
8113do_nop (void)
8114{
e7495e45
NS
8115 if (inst.operands[0].present
8116 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
8117 {
8118 /* Architectural NOP hints are CPSR sets with no bits selected. */
8119 inst.instruction &= 0xf0000000;
e7495e45
NS
8120 inst.instruction |= 0x0320f000;
8121 if (inst.operands[0].present)
8122 inst.instruction |= inst.operands[0].imm;
c19d1205 8123 }
b99bd4ef
NC
8124}
8125
c19d1205
ZW
8126/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
8127 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
8128 Condition defaults to COND_ALWAYS.
8129 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
8130
8131static void
c19d1205 8132do_pkhbt (void)
b99bd4ef 8133{
c19d1205
ZW
8134 inst.instruction |= inst.operands[0].reg << 12;
8135 inst.instruction |= inst.operands[1].reg << 16;
8136 inst.instruction |= inst.operands[2].reg;
8137 if (inst.operands[3].present)
8138 encode_arm_shift (3);
8139}
b99bd4ef 8140
c19d1205 8141/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 8142
c19d1205
ZW
8143static void
8144do_pkhtb (void)
8145{
8146 if (!inst.operands[3].present)
b99bd4ef 8147 {
c19d1205
ZW
8148 /* If the shift specifier is omitted, turn the instruction
8149 into pkhbt rd, rm, rn. */
8150 inst.instruction &= 0xfff00010;
8151 inst.instruction |= inst.operands[0].reg << 12;
8152 inst.instruction |= inst.operands[1].reg;
8153 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8154 }
8155 else
8156 {
c19d1205
ZW
8157 inst.instruction |= inst.operands[0].reg << 12;
8158 inst.instruction |= inst.operands[1].reg << 16;
8159 inst.instruction |= inst.operands[2].reg;
8160 encode_arm_shift (3);
b99bd4ef
NC
8161 }
8162}
8163
c19d1205 8164/* ARMv5TE: Preload-Cache
60e5ef9f 8165 MP Extensions: Preload for write
c19d1205 8166
60e5ef9f 8167 PLD(W) <addr_mode>
c19d1205
ZW
8168
8169 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
8170
8171static void
c19d1205 8172do_pld (void)
b99bd4ef 8173{
c19d1205
ZW
8174 constraint (!inst.operands[0].isreg,
8175 _("'[' expected after PLD mnemonic"));
8176 constraint (inst.operands[0].postind,
8177 _("post-indexed expression used in preload instruction"));
8178 constraint (inst.operands[0].writeback,
8179 _("writeback used in preload instruction"));
8180 constraint (!inst.operands[0].preind,
8181 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
8182 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8183}
b99bd4ef 8184
62b3e311
PB
8185/* ARMv7: PLI <addr_mode> */
8186static void
8187do_pli (void)
8188{
8189 constraint (!inst.operands[0].isreg,
8190 _("'[' expected after PLI mnemonic"));
8191 constraint (inst.operands[0].postind,
8192 _("post-indexed expression used in preload instruction"));
8193 constraint (inst.operands[0].writeback,
8194 _("writeback used in preload instruction"));
8195 constraint (!inst.operands[0].preind,
8196 _("unindexed addressing used in preload instruction"));
8197 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8198 inst.instruction &= ~PRE_INDEX;
8199}
8200
c19d1205
ZW
8201static void
8202do_push_pop (void)
8203{
8204 inst.operands[1] = inst.operands[0];
8205 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8206 inst.operands[0].isreg = 1;
8207 inst.operands[0].writeback = 1;
8208 inst.operands[0].reg = REG_SP;
8209 do_ldmstm ();
8210}
b99bd4ef 8211
c19d1205
ZW
8212/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8213 word at the specified address and the following word
8214 respectively.
8215 Unconditionally executed.
8216 Error if Rn is R15. */
b99bd4ef 8217
c19d1205
ZW
8218static void
8219do_rfe (void)
8220{
8221 inst.instruction |= inst.operands[0].reg << 16;
8222 if (inst.operands[0].writeback)
8223 inst.instruction |= WRITE_BACK;
8224}
b99bd4ef 8225
c19d1205 8226/* ARM V6 ssat (argument parse). */
b99bd4ef 8227
c19d1205
ZW
8228static void
8229do_ssat (void)
8230{
8231 inst.instruction |= inst.operands[0].reg << 12;
8232 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8233 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8234
c19d1205
ZW
8235 if (inst.operands[3].present)
8236 encode_arm_shift (3);
b99bd4ef
NC
8237}
8238
c19d1205 8239/* ARM V6 usat (argument parse). */
b99bd4ef
NC
8240
8241static void
c19d1205 8242do_usat (void)
b99bd4ef 8243{
c19d1205
ZW
8244 inst.instruction |= inst.operands[0].reg << 12;
8245 inst.instruction |= inst.operands[1].imm << 16;
8246 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8247
c19d1205
ZW
8248 if (inst.operands[3].present)
8249 encode_arm_shift (3);
b99bd4ef
NC
8250}
8251
c19d1205 8252/* ARM V6 ssat16 (argument parse). */
09d92015
MM
8253
8254static void
c19d1205 8255do_ssat16 (void)
09d92015 8256{
c19d1205
ZW
8257 inst.instruction |= inst.operands[0].reg << 12;
8258 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8259 inst.instruction |= inst.operands[2].reg;
09d92015
MM
8260}
8261
c19d1205
ZW
8262static void
8263do_usat16 (void)
a737bd4d 8264{
c19d1205
ZW
8265 inst.instruction |= inst.operands[0].reg << 12;
8266 inst.instruction |= inst.operands[1].imm << 16;
8267 inst.instruction |= inst.operands[2].reg;
8268}
a737bd4d 8269
c19d1205
ZW
8270/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8271 preserving the other bits.
a737bd4d 8272
c19d1205
ZW
8273 setend <endian_specifier>, where <endian_specifier> is either
8274 BE or LE. */
a737bd4d 8275
c19d1205
ZW
8276static void
8277do_setend (void)
8278{
8279 if (inst.operands[0].imm)
8280 inst.instruction |= 0x200;
a737bd4d
NC
8281}
8282
8283static void
c19d1205 8284do_shift (void)
a737bd4d 8285{
c19d1205
ZW
8286 unsigned int Rm = (inst.operands[1].present
8287 ? inst.operands[1].reg
8288 : inst.operands[0].reg);
a737bd4d 8289
c19d1205
ZW
8290 inst.instruction |= inst.operands[0].reg << 12;
8291 inst.instruction |= Rm;
8292 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 8293 {
c19d1205
ZW
8294 inst.instruction |= inst.operands[2].reg << 8;
8295 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
8296 }
8297 else
c19d1205 8298 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
8299}
8300
09d92015 8301static void
3eb17e6b 8302do_smc (void)
09d92015 8303{
3eb17e6b 8304 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 8305 inst.reloc.pc_rel = 0;
09d92015
MM
8306}
8307
90ec0d68
MGD
8308static void
8309do_hvc (void)
8310{
8311 inst.reloc.type = BFD_RELOC_ARM_HVC;
8312 inst.reloc.pc_rel = 0;
8313}
8314
09d92015 8315static void
c19d1205 8316do_swi (void)
09d92015 8317{
c19d1205
ZW
8318 inst.reloc.type = BFD_RELOC_ARM_SWI;
8319 inst.reloc.pc_rel = 0;
09d92015
MM
8320}
8321
c19d1205
ZW
8322/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8323 SMLAxy{cond} Rd,Rm,Rs,Rn
8324 SMLAWy{cond} Rd,Rm,Rs,Rn
8325 Error if any register is R15. */
e16bb312 8326
c19d1205
ZW
8327static void
8328do_smla (void)
e16bb312 8329{
c19d1205
ZW
8330 inst.instruction |= inst.operands[0].reg << 16;
8331 inst.instruction |= inst.operands[1].reg;
8332 inst.instruction |= inst.operands[2].reg << 8;
8333 inst.instruction |= inst.operands[3].reg << 12;
8334}
a737bd4d 8335
c19d1205
ZW
8336/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8337 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8338 Error if any register is R15.
8339 Warning if Rdlo == Rdhi. */
a737bd4d 8340
c19d1205
ZW
8341static void
8342do_smlal (void)
8343{
8344 inst.instruction |= inst.operands[0].reg << 12;
8345 inst.instruction |= inst.operands[1].reg << 16;
8346 inst.instruction |= inst.operands[2].reg;
8347 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 8348
c19d1205
ZW
8349 if (inst.operands[0].reg == inst.operands[1].reg)
8350 as_tsktsk (_("rdhi and rdlo must be different"));
8351}
a737bd4d 8352
c19d1205
ZW
8353/* ARM V5E (El Segundo) signed-multiply (argument parse)
8354 SMULxy{cond} Rd,Rm,Rs
8355 Error if any register is R15. */
a737bd4d 8356
c19d1205
ZW
8357static void
8358do_smul (void)
8359{
8360 inst.instruction |= inst.operands[0].reg << 16;
8361 inst.instruction |= inst.operands[1].reg;
8362 inst.instruction |= inst.operands[2].reg << 8;
8363}
a737bd4d 8364
b6702015
PB
8365/* ARM V6 srs (argument parse). The variable fields in the encoding are
8366 the same for both ARM and Thumb-2. */
a737bd4d 8367
c19d1205
ZW
8368static void
8369do_srs (void)
8370{
b6702015
PB
8371 int reg;
8372
8373 if (inst.operands[0].present)
8374 {
8375 reg = inst.operands[0].reg;
fdfde340 8376 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
8377 }
8378 else
fdfde340 8379 reg = REG_SP;
b6702015
PB
8380
8381 inst.instruction |= reg << 16;
8382 inst.instruction |= inst.operands[1].imm;
8383 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
8384 inst.instruction |= WRITE_BACK;
8385}
a737bd4d 8386
c19d1205 8387/* ARM V6 strex (argument parse). */
a737bd4d 8388
c19d1205
ZW
8389static void
8390do_strex (void)
8391{
8392 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8393 || inst.operands[2].postind || inst.operands[2].writeback
8394 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
8395 || inst.operands[2].negative
8396 /* See comment in do_ldrex(). */
8397 || (inst.operands[2].reg == REG_PC),
8398 BAD_ADDR_MODE);
a737bd4d 8399
c19d1205
ZW
8400 constraint (inst.operands[0].reg == inst.operands[1].reg
8401 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 8402
c19d1205
ZW
8403 constraint (inst.reloc.exp.X_op != O_constant
8404 || inst.reloc.exp.X_add_number != 0,
8405 _("offset must be zero in ARM encoding"));
a737bd4d 8406
c19d1205
ZW
8407 inst.instruction |= inst.operands[0].reg << 12;
8408 inst.instruction |= inst.operands[1].reg;
8409 inst.instruction |= inst.operands[2].reg << 16;
8410 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8411}
8412
8413static void
c19d1205 8414do_strexd (void)
e16bb312 8415{
c19d1205
ZW
8416 constraint (inst.operands[1].reg % 2 != 0,
8417 _("even register required"));
8418 constraint (inst.operands[2].present
8419 && inst.operands[2].reg != inst.operands[1].reg + 1,
8420 _("can only store two consecutive registers"));
8421 /* If op 2 were present and equal to PC, this function wouldn't
8422 have been called in the first place. */
8423 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8424
c19d1205
ZW
8425 constraint (inst.operands[0].reg == inst.operands[1].reg
8426 || inst.operands[0].reg == inst.operands[1].reg + 1
8427 || inst.operands[0].reg == inst.operands[3].reg,
8428 BAD_OVERLAP);
e16bb312 8429
c19d1205
ZW
8430 inst.instruction |= inst.operands[0].reg << 12;
8431 inst.instruction |= inst.operands[1].reg;
8432 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8433}
8434
c19d1205
ZW
8435/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8436 extends it to 32-bits, and adds the result to a value in another
8437 register. You can specify a rotation by 0, 8, 16, or 24 bits
8438 before extracting the 16-bit value.
8439 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8440 Condition defaults to COND_ALWAYS.
8441 Error if any register uses R15. */
8442
e16bb312 8443static void
c19d1205 8444do_sxtah (void)
e16bb312 8445{
c19d1205
ZW
8446 inst.instruction |= inst.operands[0].reg << 12;
8447 inst.instruction |= inst.operands[1].reg << 16;
8448 inst.instruction |= inst.operands[2].reg;
8449 inst.instruction |= inst.operands[3].imm << 10;
8450}
e16bb312 8451
c19d1205 8452/* ARM V6 SXTH.
e16bb312 8453
c19d1205
ZW
8454 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8455 Condition defaults to COND_ALWAYS.
8456 Error if any register uses R15. */
e16bb312
NC
8457
8458static void
c19d1205 8459do_sxth (void)
e16bb312 8460{
c19d1205
ZW
8461 inst.instruction |= inst.operands[0].reg << 12;
8462 inst.instruction |= inst.operands[1].reg;
8463 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8464}
c19d1205
ZW
8465\f
8466/* VFP instructions. In a logical order: SP variant first, monad
8467 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8468
8469static void
c19d1205 8470do_vfp_sp_monadic (void)
e16bb312 8471{
5287ad62
JB
8472 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8473 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8474}
8475
8476static void
c19d1205 8477do_vfp_sp_dyadic (void)
e16bb312 8478{
5287ad62
JB
8479 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8480 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8481 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8482}
8483
8484static void
c19d1205 8485do_vfp_sp_compare_z (void)
e16bb312 8486{
5287ad62 8487 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8488}
8489
8490static void
c19d1205 8491do_vfp_dp_sp_cvt (void)
e16bb312 8492{
5287ad62
JB
8493 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8494 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8495}
8496
8497static void
c19d1205 8498do_vfp_sp_dp_cvt (void)
e16bb312 8499{
5287ad62
JB
8500 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8501 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8502}
8503
8504static void
c19d1205 8505do_vfp_reg_from_sp (void)
e16bb312 8506{
c19d1205 8507 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8508 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8509}
8510
8511static void
c19d1205 8512do_vfp_reg2_from_sp2 (void)
e16bb312 8513{
c19d1205
ZW
8514 constraint (inst.operands[2].imm != 2,
8515 _("only two consecutive VFP SP registers allowed here"));
8516 inst.instruction |= inst.operands[0].reg << 12;
8517 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8518 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8519}
8520
8521static void
c19d1205 8522do_vfp_sp_from_reg (void)
e16bb312 8523{
5287ad62 8524 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8525 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8526}
8527
8528static void
c19d1205 8529do_vfp_sp2_from_reg2 (void)
e16bb312 8530{
c19d1205
ZW
8531 constraint (inst.operands[0].imm != 2,
8532 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8533 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8534 inst.instruction |= inst.operands[1].reg << 12;
8535 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8536}
8537
8538static void
c19d1205 8539do_vfp_sp_ldst (void)
e16bb312 8540{
5287ad62 8541 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 8542 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8543}
8544
8545static void
c19d1205 8546do_vfp_dp_ldst (void)
e16bb312 8547{
5287ad62 8548 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 8549 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8550}
8551
c19d1205 8552
e16bb312 8553static void
c19d1205 8554vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8555{
c19d1205
ZW
8556 if (inst.operands[0].writeback)
8557 inst.instruction |= WRITE_BACK;
8558 else
8559 constraint (ldstm_type != VFP_LDSTMIA,
8560 _("this addressing mode requires base-register writeback"));
8561 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8562 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 8563 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
8564}
8565
8566static void
c19d1205 8567vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8568{
c19d1205 8569 int count;
e16bb312 8570
c19d1205
ZW
8571 if (inst.operands[0].writeback)
8572 inst.instruction |= WRITE_BACK;
8573 else
8574 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8575 _("this addressing mode requires base-register writeback"));
e16bb312 8576
c19d1205 8577 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8578 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 8579
c19d1205
ZW
8580 count = inst.operands[1].imm << 1;
8581 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8582 count += 1;
e16bb312 8583
c19d1205 8584 inst.instruction |= count;
e16bb312
NC
8585}
8586
8587static void
c19d1205 8588do_vfp_sp_ldstmia (void)
e16bb312 8589{
c19d1205 8590 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8591}
8592
8593static void
c19d1205 8594do_vfp_sp_ldstmdb (void)
e16bb312 8595{
c19d1205 8596 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8597}
8598
8599static void
c19d1205 8600do_vfp_dp_ldstmia (void)
e16bb312 8601{
c19d1205 8602 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8603}
8604
8605static void
c19d1205 8606do_vfp_dp_ldstmdb (void)
e16bb312 8607{
c19d1205 8608 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8609}
8610
8611static void
c19d1205 8612do_vfp_xp_ldstmia (void)
e16bb312 8613{
c19d1205
ZW
8614 vfp_dp_ldstm (VFP_LDSTMIAX);
8615}
e16bb312 8616
c19d1205
ZW
8617static void
8618do_vfp_xp_ldstmdb (void)
8619{
8620 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 8621}
5287ad62
JB
8622
8623static void
8624do_vfp_dp_rd_rm (void)
8625{
8626 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8627 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8628}
8629
8630static void
8631do_vfp_dp_rn_rd (void)
8632{
8633 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8634 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8635}
8636
8637static void
8638do_vfp_dp_rd_rn (void)
8639{
8640 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8641 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8642}
8643
8644static void
8645do_vfp_dp_rd_rn_rm (void)
8646{
8647 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8648 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8649 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8650}
8651
8652static void
8653do_vfp_dp_rd (void)
8654{
8655 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8656}
8657
8658static void
8659do_vfp_dp_rm_rd_rn (void)
8660{
8661 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8662 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8663 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8664}
8665
8666/* VFPv3 instructions. */
8667static void
8668do_vfp_sp_const (void)
8669{
8670 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8671 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8672 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8673}
8674
8675static void
8676do_vfp_dp_const (void)
8677{
8678 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8679 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8680 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8681}
8682
8683static void
8684vfp_conv (int srcsize)
8685{
8686 unsigned immbits = srcsize - inst.operands[1].imm;
8687 inst.instruction |= (immbits & 1) << 5;
8688 inst.instruction |= (immbits >> 1);
8689}
8690
8691static void
8692do_vfp_sp_conv_16 (void)
8693{
8694 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8695 vfp_conv (16);
8696}
8697
8698static void
8699do_vfp_dp_conv_16 (void)
8700{
8701 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8702 vfp_conv (16);
8703}
8704
8705static void
8706do_vfp_sp_conv_32 (void)
8707{
8708 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8709 vfp_conv (32);
8710}
8711
8712static void
8713do_vfp_dp_conv_32 (void)
8714{
8715 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8716 vfp_conv (32);
8717}
c19d1205
ZW
8718\f
8719/* FPA instructions. Also in a logical order. */
e16bb312 8720
c19d1205
ZW
8721static void
8722do_fpa_cmp (void)
8723{
8724 inst.instruction |= inst.operands[0].reg << 16;
8725 inst.instruction |= inst.operands[1].reg;
8726}
b99bd4ef
NC
8727
8728static void
c19d1205 8729do_fpa_ldmstm (void)
b99bd4ef 8730{
c19d1205
ZW
8731 inst.instruction |= inst.operands[0].reg << 12;
8732 switch (inst.operands[1].imm)
8733 {
8734 case 1: inst.instruction |= CP_T_X; break;
8735 case 2: inst.instruction |= CP_T_Y; break;
8736 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8737 case 4: break;
8738 default: abort ();
8739 }
b99bd4ef 8740
c19d1205
ZW
8741 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8742 {
8743 /* The instruction specified "ea" or "fd", so we can only accept
8744 [Rn]{!}. The instruction does not really support stacking or
8745 unstacking, so we have to emulate these by setting appropriate
8746 bits and offsets. */
8747 constraint (inst.reloc.exp.X_op != O_constant
8748 || inst.reloc.exp.X_add_number != 0,
8749 _("this instruction does not support indexing"));
b99bd4ef 8750
c19d1205
ZW
8751 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8752 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8753
c19d1205
ZW
8754 if (!(inst.instruction & INDEX_UP))
8755 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8756
c19d1205
ZW
8757 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8758 {
8759 inst.operands[2].preind = 0;
8760 inst.operands[2].postind = 1;
8761 }
8762 }
b99bd4ef 8763
c19d1205 8764 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8765}
c19d1205
ZW
8766\f
8767/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8768
c19d1205
ZW
8769static void
8770do_iwmmxt_tandorc (void)
8771{
8772 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8773}
b99bd4ef 8774
c19d1205
ZW
8775static void
8776do_iwmmxt_textrc (void)
8777{
8778 inst.instruction |= inst.operands[0].reg << 12;
8779 inst.instruction |= inst.operands[1].imm;
8780}
b99bd4ef
NC
8781
8782static void
c19d1205 8783do_iwmmxt_textrm (void)
b99bd4ef 8784{
c19d1205
ZW
8785 inst.instruction |= inst.operands[0].reg << 12;
8786 inst.instruction |= inst.operands[1].reg << 16;
8787 inst.instruction |= inst.operands[2].imm;
8788}
b99bd4ef 8789
c19d1205
ZW
8790static void
8791do_iwmmxt_tinsr (void)
8792{
8793 inst.instruction |= inst.operands[0].reg << 16;
8794 inst.instruction |= inst.operands[1].reg << 12;
8795 inst.instruction |= inst.operands[2].imm;
8796}
b99bd4ef 8797
c19d1205
ZW
8798static void
8799do_iwmmxt_tmia (void)
8800{
8801 inst.instruction |= inst.operands[0].reg << 5;
8802 inst.instruction |= inst.operands[1].reg;
8803 inst.instruction |= inst.operands[2].reg << 12;
8804}
b99bd4ef 8805
c19d1205
ZW
8806static void
8807do_iwmmxt_waligni (void)
8808{
8809 inst.instruction |= inst.operands[0].reg << 12;
8810 inst.instruction |= inst.operands[1].reg << 16;
8811 inst.instruction |= inst.operands[2].reg;
8812 inst.instruction |= inst.operands[3].imm << 20;
8813}
b99bd4ef 8814
2d447fca
JM
8815static void
8816do_iwmmxt_wmerge (void)
8817{
8818 inst.instruction |= inst.operands[0].reg << 12;
8819 inst.instruction |= inst.operands[1].reg << 16;
8820 inst.instruction |= inst.operands[2].reg;
8821 inst.instruction |= inst.operands[3].imm << 21;
8822}
8823
c19d1205
ZW
8824static void
8825do_iwmmxt_wmov (void)
8826{
8827 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8828 inst.instruction |= inst.operands[0].reg << 12;
8829 inst.instruction |= inst.operands[1].reg << 16;
8830 inst.instruction |= inst.operands[1].reg;
8831}
b99bd4ef 8832
c19d1205
ZW
8833static void
8834do_iwmmxt_wldstbh (void)
8835{
8f06b2d8 8836 int reloc;
c19d1205 8837 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8838 if (thumb_mode)
8839 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8840 else
8841 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8842 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8843}
8844
c19d1205
ZW
8845static void
8846do_iwmmxt_wldstw (void)
8847{
8848 /* RIWR_RIWC clears .isreg for a control register. */
8849 if (!inst.operands[0].isreg)
8850 {
8851 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8852 inst.instruction |= 0xf0000000;
8853 }
b99bd4ef 8854
c19d1205
ZW
8855 inst.instruction |= inst.operands[0].reg << 12;
8856 encode_arm_cp_address (1, TRUE, TRUE, 0);
8857}
b99bd4ef
NC
8858
8859static void
c19d1205 8860do_iwmmxt_wldstd (void)
b99bd4ef 8861{
c19d1205 8862 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8863 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8864 && inst.operands[1].immisreg)
8865 {
8866 inst.instruction &= ~0x1a000ff;
8867 inst.instruction |= (0xf << 28);
8868 if (inst.operands[1].preind)
8869 inst.instruction |= PRE_INDEX;
8870 if (!inst.operands[1].negative)
8871 inst.instruction |= INDEX_UP;
8872 if (inst.operands[1].writeback)
8873 inst.instruction |= WRITE_BACK;
8874 inst.instruction |= inst.operands[1].reg << 16;
8875 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8876 inst.instruction |= inst.operands[1].imm;
8877 }
8878 else
8879 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8880}
b99bd4ef 8881
c19d1205
ZW
8882static void
8883do_iwmmxt_wshufh (void)
8884{
8885 inst.instruction |= inst.operands[0].reg << 12;
8886 inst.instruction |= inst.operands[1].reg << 16;
8887 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8888 inst.instruction |= (inst.operands[2].imm & 0x0f);
8889}
b99bd4ef 8890
c19d1205
ZW
8891static void
8892do_iwmmxt_wzero (void)
8893{
8894 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8895 inst.instruction |= inst.operands[0].reg;
8896 inst.instruction |= inst.operands[0].reg << 12;
8897 inst.instruction |= inst.operands[0].reg << 16;
8898}
2d447fca
JM
8899
8900static void
8901do_iwmmxt_wrwrwr_or_imm5 (void)
8902{
8903 if (inst.operands[2].isreg)
8904 do_rd_rn_rm ();
8905 else {
8906 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8907 _("immediate operand requires iWMMXt2"));
8908 do_rd_rn ();
8909 if (inst.operands[2].imm == 0)
8910 {
8911 switch ((inst.instruction >> 20) & 0xf)
8912 {
8913 case 4:
8914 case 5:
8915 case 6:
5f4273c7 8916 case 7:
2d447fca
JM
8917 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8918 inst.operands[2].imm = 16;
8919 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8920 break;
8921 case 8:
8922 case 9:
8923 case 10:
8924 case 11:
8925 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8926 inst.operands[2].imm = 32;
8927 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8928 break;
8929 case 12:
8930 case 13:
8931 case 14:
8932 case 15:
8933 {
8934 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8935 unsigned long wrn;
8936 wrn = (inst.instruction >> 16) & 0xf;
8937 inst.instruction &= 0xff0fff0f;
8938 inst.instruction |= wrn;
8939 /* Bail out here; the instruction is now assembled. */
8940 return;
8941 }
8942 }
8943 }
8944 /* Map 32 -> 0, etc. */
8945 inst.operands[2].imm &= 0x1f;
8946 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8947 }
8948}
c19d1205
ZW
8949\f
8950/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8951 operations first, then control, shift, and load/store. */
b99bd4ef 8952
c19d1205 8953/* Insns like "foo X,Y,Z". */
b99bd4ef 8954
c19d1205
ZW
8955static void
8956do_mav_triple (void)
8957{
8958 inst.instruction |= inst.operands[0].reg << 16;
8959 inst.instruction |= inst.operands[1].reg;
8960 inst.instruction |= inst.operands[2].reg << 12;
8961}
b99bd4ef 8962
c19d1205
ZW
8963/* Insns like "foo W,X,Y,Z".
8964 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8965
c19d1205
ZW
8966static void
8967do_mav_quad (void)
8968{
8969 inst.instruction |= inst.operands[0].reg << 5;
8970 inst.instruction |= inst.operands[1].reg << 12;
8971 inst.instruction |= inst.operands[2].reg << 16;
8972 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8973}
8974
c19d1205
ZW
8975/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8976static void
8977do_mav_dspsc (void)
a737bd4d 8978{
c19d1205
ZW
8979 inst.instruction |= inst.operands[1].reg << 12;
8980}
a737bd4d 8981
c19d1205
ZW
8982/* Maverick shift immediate instructions.
8983 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8984 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8985
c19d1205
ZW
8986static void
8987do_mav_shift (void)
8988{
8989 int imm = inst.operands[2].imm;
a737bd4d 8990
c19d1205
ZW
8991 inst.instruction |= inst.operands[0].reg << 12;
8992 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8993
c19d1205
ZW
8994 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8995 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8996 Bit 4 should be 0. */
8997 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8998
c19d1205
ZW
8999 inst.instruction |= imm;
9000}
9001\f
9002/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 9003
c19d1205
ZW
9004/* Xscale multiply-accumulate (argument parse)
9005 MIAcc acc0,Rm,Rs
9006 MIAPHcc acc0,Rm,Rs
9007 MIAxycc acc0,Rm,Rs. */
a737bd4d 9008
c19d1205
ZW
9009static void
9010do_xsc_mia (void)
9011{
9012 inst.instruction |= inst.operands[1].reg;
9013 inst.instruction |= inst.operands[2].reg << 12;
9014}
a737bd4d 9015
c19d1205 9016/* Xscale move-accumulator-register (argument parse)
a737bd4d 9017
c19d1205 9018 MARcc acc0,RdLo,RdHi. */
b99bd4ef 9019
c19d1205
ZW
9020static void
9021do_xsc_mar (void)
9022{
9023 inst.instruction |= inst.operands[1].reg << 12;
9024 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9025}
9026
c19d1205 9027/* Xscale move-register-accumulator (argument parse)
b99bd4ef 9028
c19d1205 9029 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
9030
9031static void
c19d1205 9032do_xsc_mra (void)
b99bd4ef 9033{
c19d1205
ZW
9034 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
9035 inst.instruction |= inst.operands[0].reg << 12;
9036 inst.instruction |= inst.operands[1].reg << 16;
9037}
9038\f
9039/* Encoding functions relevant only to Thumb. */
b99bd4ef 9040
c19d1205
ZW
9041/* inst.operands[i] is a shifted-register operand; encode
9042 it into inst.instruction in the format used by Thumb32. */
9043
9044static void
9045encode_thumb32_shifted_operand (int i)
9046{
9047 unsigned int value = inst.reloc.exp.X_add_number;
9048 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 9049
9c3c69f2
PB
9050 constraint (inst.operands[i].immisreg,
9051 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
9052 inst.instruction |= inst.operands[i].reg;
9053 if (shift == SHIFT_RRX)
9054 inst.instruction |= SHIFT_ROR << 4;
9055 else
b99bd4ef 9056 {
c19d1205
ZW
9057 constraint (inst.reloc.exp.X_op != O_constant,
9058 _("expression too complex"));
9059
9060 constraint (value > 32
9061 || (value == 32 && (shift == SHIFT_LSL
9062 || shift == SHIFT_ROR)),
9063 _("shift expression is too large"));
9064
9065 if (value == 0)
9066 shift = SHIFT_LSL;
9067 else if (value == 32)
9068 value = 0;
9069
9070 inst.instruction |= shift << 4;
9071 inst.instruction |= (value & 0x1c) << 10;
9072 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 9073 }
c19d1205 9074}
b99bd4ef 9075
b99bd4ef 9076
c19d1205
ZW
9077/* inst.operands[i] was set up by parse_address. Encode it into a
9078 Thumb32 format load or store instruction. Reject forms that cannot
9079 be used with such instructions. If is_t is true, reject forms that
9080 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
9081 that cannot be used with a D instruction. If it is a store insn,
9082 reject PC in Rn. */
b99bd4ef 9083
c19d1205
ZW
9084static void
9085encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
9086{
5be8be5d 9087 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
9088
9089 constraint (!inst.operands[i].isreg,
53365c0d 9090 _("Instruction does not support =N addresses"));
b99bd4ef 9091
c19d1205
ZW
9092 inst.instruction |= inst.operands[i].reg << 16;
9093 if (inst.operands[i].immisreg)
b99bd4ef 9094 {
5be8be5d 9095 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
9096 constraint (is_t || is_d, _("cannot use register index with this instruction"));
9097 constraint (inst.operands[i].negative,
9098 _("Thumb does not support negative register indexing"));
9099 constraint (inst.operands[i].postind,
9100 _("Thumb does not support register post-indexing"));
9101 constraint (inst.operands[i].writeback,
9102 _("Thumb does not support register indexing with writeback"));
9103 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
9104 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 9105
f40d1643 9106 inst.instruction |= inst.operands[i].imm;
c19d1205 9107 if (inst.operands[i].shifted)
b99bd4ef 9108 {
c19d1205
ZW
9109 constraint (inst.reloc.exp.X_op != O_constant,
9110 _("expression too complex"));
9c3c69f2
PB
9111 constraint (inst.reloc.exp.X_add_number < 0
9112 || inst.reloc.exp.X_add_number > 3,
c19d1205 9113 _("shift out of range"));
9c3c69f2 9114 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
9115 }
9116 inst.reloc.type = BFD_RELOC_UNUSED;
9117 }
9118 else if (inst.operands[i].preind)
9119 {
5be8be5d 9120 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 9121 constraint (is_t && inst.operands[i].writeback,
c19d1205 9122 _("cannot use writeback with this instruction"));
5be8be5d
DG
9123 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
9124 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
c19d1205
ZW
9125
9126 if (is_d)
9127 {
9128 inst.instruction |= 0x01000000;
9129 if (inst.operands[i].writeback)
9130 inst.instruction |= 0x00200000;
b99bd4ef 9131 }
c19d1205 9132 else
b99bd4ef 9133 {
c19d1205
ZW
9134 inst.instruction |= 0x00000c00;
9135 if (inst.operands[i].writeback)
9136 inst.instruction |= 0x00000100;
b99bd4ef 9137 }
c19d1205 9138 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 9139 }
c19d1205 9140 else if (inst.operands[i].postind)
b99bd4ef 9141 {
9c2799c2 9142 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
9143 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
9144 constraint (is_t, _("cannot use post-indexing with this instruction"));
9145
9146 if (is_d)
9147 inst.instruction |= 0x00200000;
9148 else
9149 inst.instruction |= 0x00000900;
9150 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9151 }
9152 else /* unindexed - only for coprocessor */
9153 inst.error = _("instruction does not accept unindexed addressing");
9154}
9155
9156/* Table of Thumb instructions which exist in both 16- and 32-bit
9157 encodings (the latter only in post-V6T2 cores). The index is the
9158 value used in the insns table below. When there is more than one
9159 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
9160 holds variant (1).
9161 Also contains several pseudo-instructions used during relaxation. */
c19d1205 9162#define T16_32_TAB \
21d799b5
NC
9163 X(_adc, 4140, eb400000), \
9164 X(_adcs, 4140, eb500000), \
9165 X(_add, 1c00, eb000000), \
9166 X(_adds, 1c00, eb100000), \
9167 X(_addi, 0000, f1000000), \
9168 X(_addis, 0000, f1100000), \
9169 X(_add_pc,000f, f20f0000), \
9170 X(_add_sp,000d, f10d0000), \
9171 X(_adr, 000f, f20f0000), \
9172 X(_and, 4000, ea000000), \
9173 X(_ands, 4000, ea100000), \
9174 X(_asr, 1000, fa40f000), \
9175 X(_asrs, 1000, fa50f000), \
9176 X(_b, e000, f000b000), \
9177 X(_bcond, d000, f0008000), \
9178 X(_bic, 4380, ea200000), \
9179 X(_bics, 4380, ea300000), \
9180 X(_cmn, 42c0, eb100f00), \
9181 X(_cmp, 2800, ebb00f00), \
9182 X(_cpsie, b660, f3af8400), \
9183 X(_cpsid, b670, f3af8600), \
9184 X(_cpy, 4600, ea4f0000), \
9185 X(_dec_sp,80dd, f1ad0d00), \
9186 X(_eor, 4040, ea800000), \
9187 X(_eors, 4040, ea900000), \
9188 X(_inc_sp,00dd, f10d0d00), \
9189 X(_ldmia, c800, e8900000), \
9190 X(_ldr, 6800, f8500000), \
9191 X(_ldrb, 7800, f8100000), \
9192 X(_ldrh, 8800, f8300000), \
9193 X(_ldrsb, 5600, f9100000), \
9194 X(_ldrsh, 5e00, f9300000), \
9195 X(_ldr_pc,4800, f85f0000), \
9196 X(_ldr_pc2,4800, f85f0000), \
9197 X(_ldr_sp,9800, f85d0000), \
9198 X(_lsl, 0000, fa00f000), \
9199 X(_lsls, 0000, fa10f000), \
9200 X(_lsr, 0800, fa20f000), \
9201 X(_lsrs, 0800, fa30f000), \
9202 X(_mov, 2000, ea4f0000), \
9203 X(_movs, 2000, ea5f0000), \
9204 X(_mul, 4340, fb00f000), \
9205 X(_muls, 4340, ffffffff), /* no 32b muls */ \
9206 X(_mvn, 43c0, ea6f0000), \
9207 X(_mvns, 43c0, ea7f0000), \
9208 X(_neg, 4240, f1c00000), /* rsb #0 */ \
9209 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
9210 X(_orr, 4300, ea400000), \
9211 X(_orrs, 4300, ea500000), \
9212 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9213 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9214 X(_rev, ba00, fa90f080), \
9215 X(_rev16, ba40, fa90f090), \
9216 X(_revsh, bac0, fa90f0b0), \
9217 X(_ror, 41c0, fa60f000), \
9218 X(_rors, 41c0, fa70f000), \
9219 X(_sbc, 4180, eb600000), \
9220 X(_sbcs, 4180, eb700000), \
9221 X(_stmia, c000, e8800000), \
9222 X(_str, 6000, f8400000), \
9223 X(_strb, 7000, f8000000), \
9224 X(_strh, 8000, f8200000), \
9225 X(_str_sp,9000, f84d0000), \
9226 X(_sub, 1e00, eba00000), \
9227 X(_subs, 1e00, ebb00000), \
9228 X(_subi, 8000, f1a00000), \
9229 X(_subis, 8000, f1b00000), \
9230 X(_sxtb, b240, fa4ff080), \
9231 X(_sxth, b200, fa0ff080), \
9232 X(_tst, 4200, ea100f00), \
9233 X(_uxtb, b2c0, fa5ff080), \
9234 X(_uxth, b280, fa1ff080), \
9235 X(_nop, bf00, f3af8000), \
9236 X(_yield, bf10, f3af8001), \
9237 X(_wfe, bf20, f3af8002), \
9238 X(_wfi, bf30, f3af8003), \
9239 X(_sev, bf40, f3af8004),
c19d1205
ZW
9240
9241/* To catch errors in encoding functions, the codes are all offset by
9242 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9243 as 16-bit instructions. */
21d799b5 9244#define X(a,b,c) T_MNEM##a
c19d1205
ZW
9245enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9246#undef X
9247
9248#define X(a,b,c) 0x##b
9249static const unsigned short thumb_op16[] = { T16_32_TAB };
9250#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9251#undef X
9252
9253#define X(a,b,c) 0x##c
9254static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
9255#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9256#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
9257#undef X
9258#undef T16_32_TAB
9259
9260/* Thumb instruction encoders, in alphabetical order. */
9261
92e90b6e 9262/* ADDW or SUBW. */
c921be7d 9263
92e90b6e
PB
9264static void
9265do_t_add_sub_w (void)
9266{
9267 int Rd, Rn;
9268
9269 Rd = inst.operands[0].reg;
9270 Rn = inst.operands[1].reg;
9271
539d4391
NC
9272 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9273 is the SP-{plus,minus}-immediate form of the instruction. */
9274 if (Rn == REG_SP)
9275 constraint (Rd == REG_PC, BAD_PC);
9276 else
9277 reject_bad_reg (Rd);
fdfde340 9278
92e90b6e
PB
9279 inst.instruction |= (Rn << 16) | (Rd << 8);
9280 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9281}
9282
c19d1205
ZW
9283/* Parse an add or subtract instruction. We get here with inst.instruction
9284 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9285
9286static void
9287do_t_add_sub (void)
9288{
9289 int Rd, Rs, Rn;
9290
9291 Rd = inst.operands[0].reg;
9292 Rs = (inst.operands[1].present
9293 ? inst.operands[1].reg /* Rd, Rs, foo */
9294 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9295
e07e6e58
NC
9296 if (Rd == REG_PC)
9297 set_it_insn_type_last ();
9298
c19d1205
ZW
9299 if (unified_syntax)
9300 {
0110f2b8
PB
9301 bfd_boolean flags;
9302 bfd_boolean narrow;
9303 int opcode;
9304
9305 flags = (inst.instruction == T_MNEM_adds
9306 || inst.instruction == T_MNEM_subs);
9307 if (flags)
e07e6e58 9308 narrow = !in_it_block ();
0110f2b8 9309 else
e07e6e58 9310 narrow = in_it_block ();
c19d1205 9311 if (!inst.operands[2].isreg)
b99bd4ef 9312 {
16805f35
PB
9313 int add;
9314
fdfde340
JM
9315 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9316
16805f35
PB
9317 add = (inst.instruction == T_MNEM_add
9318 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
9319 opcode = 0;
9320 if (inst.size_req != 4)
9321 {
0110f2b8
PB
9322 /* Attempt to use a narrow opcode, with relaxation if
9323 appropriate. */
9324 if (Rd == REG_SP && Rs == REG_SP && !flags)
9325 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9326 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9327 opcode = T_MNEM_add_sp;
9328 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9329 opcode = T_MNEM_add_pc;
9330 else if (Rd <= 7 && Rs <= 7 && narrow)
9331 {
9332 if (flags)
9333 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9334 else
9335 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9336 }
9337 if (opcode)
9338 {
9339 inst.instruction = THUMB_OP16(opcode);
9340 inst.instruction |= (Rd << 4) | Rs;
9341 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9342 if (inst.size_req != 2)
9343 inst.relax = opcode;
9344 }
9345 else
9346 constraint (inst.size_req == 2, BAD_HIREG);
9347 }
9348 if (inst.size_req == 4
9349 || (inst.size_req != 2 && !opcode))
9350 {
efd81785
PB
9351 if (Rd == REG_PC)
9352 {
fdfde340 9353 constraint (add, BAD_PC);
efd81785
PB
9354 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9355 _("only SUBS PC, LR, #const allowed"));
9356 constraint (inst.reloc.exp.X_op != O_constant,
9357 _("expression too complex"));
9358 constraint (inst.reloc.exp.X_add_number < 0
9359 || inst.reloc.exp.X_add_number > 0xff,
9360 _("immediate value out of range"));
9361 inst.instruction = T2_SUBS_PC_LR
9362 | inst.reloc.exp.X_add_number;
9363 inst.reloc.type = BFD_RELOC_UNUSED;
9364 return;
9365 }
9366 else if (Rs == REG_PC)
16805f35
PB
9367 {
9368 /* Always use addw/subw. */
9369 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9370 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9371 }
9372 else
9373 {
9374 inst.instruction = THUMB_OP32 (inst.instruction);
9375 inst.instruction = (inst.instruction & 0xe1ffffff)
9376 | 0x10000000;
9377 if (flags)
9378 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9379 else
9380 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9381 }
dc4503c6
PB
9382 inst.instruction |= Rd << 8;
9383 inst.instruction |= Rs << 16;
0110f2b8 9384 }
b99bd4ef 9385 }
c19d1205
ZW
9386 else
9387 {
9388 Rn = inst.operands[2].reg;
9389 /* See if we can do this with a 16-bit instruction. */
9390 if (!inst.operands[2].shifted && inst.size_req != 4)
9391 {
e27ec89e
PB
9392 if (Rd > 7 || Rs > 7 || Rn > 7)
9393 narrow = FALSE;
9394
9395 if (narrow)
c19d1205 9396 {
e27ec89e
PB
9397 inst.instruction = ((inst.instruction == T_MNEM_adds
9398 || inst.instruction == T_MNEM_add)
c19d1205
ZW
9399 ? T_OPCODE_ADD_R3
9400 : T_OPCODE_SUB_R3);
9401 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9402 return;
9403 }
b99bd4ef 9404
7e806470 9405 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 9406 {
7e806470
PB
9407 /* Thumb-1 cores (except v6-M) require at least one high
9408 register in a narrow non flag setting add. */
9409 if (Rd > 7 || Rn > 7
9410 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9411 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9412 {
7e806470
PB
9413 if (Rd == Rn)
9414 {
9415 Rn = Rs;
9416 Rs = Rd;
9417 }
c19d1205
ZW
9418 inst.instruction = T_OPCODE_ADD_HI;
9419 inst.instruction |= (Rd & 8) << 4;
9420 inst.instruction |= (Rd & 7);
9421 inst.instruction |= Rn << 3;
9422 return;
9423 }
c19d1205
ZW
9424 }
9425 }
c921be7d 9426
fdfde340
JM
9427 constraint (Rd == REG_PC, BAD_PC);
9428 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9429 constraint (Rs == REG_PC, BAD_PC);
9430 reject_bad_reg (Rn);
9431
c19d1205
ZW
9432 /* If we get here, it can't be done in 16 bits. */
9433 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9434 _("shift must be constant"));
9435 inst.instruction = THUMB_OP32 (inst.instruction);
9436 inst.instruction |= Rd << 8;
9437 inst.instruction |= Rs << 16;
9438 encode_thumb32_shifted_operand (2);
9439 }
9440 }
9441 else
9442 {
9443 constraint (inst.instruction == T_MNEM_adds
9444 || inst.instruction == T_MNEM_subs,
9445 BAD_THUMB32);
b99bd4ef 9446
c19d1205 9447 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9448 {
c19d1205
ZW
9449 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9450 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9451 BAD_HIREG);
9452
9453 inst.instruction = (inst.instruction == T_MNEM_add
9454 ? 0x0000 : 0x8000);
9455 inst.instruction |= (Rd << 4) | Rs;
9456 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9457 return;
9458 }
9459
c19d1205
ZW
9460 Rn = inst.operands[2].reg;
9461 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9462
c19d1205
ZW
9463 /* We now have Rd, Rs, and Rn set to registers. */
9464 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9465 {
c19d1205
ZW
9466 /* Can't do this for SUB. */
9467 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9468 inst.instruction = T_OPCODE_ADD_HI;
9469 inst.instruction |= (Rd & 8) << 4;
9470 inst.instruction |= (Rd & 7);
9471 if (Rs == Rd)
9472 inst.instruction |= Rn << 3;
9473 else if (Rn == Rd)
9474 inst.instruction |= Rs << 3;
9475 else
9476 constraint (1, _("dest must overlap one source register"));
9477 }
9478 else
9479 {
9480 inst.instruction = (inst.instruction == T_MNEM_add
9481 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9482 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9483 }
b99bd4ef 9484 }
b99bd4ef
NC
9485}
9486
c19d1205
ZW
9487static void
9488do_t_adr (void)
9489{
fdfde340
JM
9490 unsigned Rd;
9491
9492 Rd = inst.operands[0].reg;
9493 reject_bad_reg (Rd);
9494
9495 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9496 {
9497 /* Defer to section relaxation. */
9498 inst.relax = inst.instruction;
9499 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9500 inst.instruction |= Rd << 4;
0110f2b8
PB
9501 }
9502 else if (unified_syntax && inst.size_req != 2)
e9f89963 9503 {
0110f2b8 9504 /* Generate a 32-bit opcode. */
e9f89963 9505 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9506 inst.instruction |= Rd << 8;
e9f89963
PB
9507 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9508 inst.reloc.pc_rel = 1;
9509 }
9510 else
9511 {
0110f2b8 9512 /* Generate a 16-bit opcode. */
e9f89963
PB
9513 inst.instruction = THUMB_OP16 (inst.instruction);
9514 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9515 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9516 inst.reloc.pc_rel = 1;
b99bd4ef 9517
fdfde340 9518 inst.instruction |= Rd << 4;
e9f89963 9519 }
c19d1205 9520}
b99bd4ef 9521
c19d1205
ZW
9522/* Arithmetic instructions for which there is just one 16-bit
9523 instruction encoding, and it allows only two low registers.
9524 For maximal compatibility with ARM syntax, we allow three register
9525 operands even when Thumb-32 instructions are not available, as long
9526 as the first two are identical. For instance, both "sbc r0,r1" and
9527 "sbc r0,r0,r1" are allowed. */
b99bd4ef 9528static void
c19d1205 9529do_t_arit3 (void)
b99bd4ef 9530{
c19d1205 9531 int Rd, Rs, Rn;
b99bd4ef 9532
c19d1205
ZW
9533 Rd = inst.operands[0].reg;
9534 Rs = (inst.operands[1].present
9535 ? inst.operands[1].reg /* Rd, Rs, foo */
9536 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9537 Rn = inst.operands[2].reg;
b99bd4ef 9538
fdfde340
JM
9539 reject_bad_reg (Rd);
9540 reject_bad_reg (Rs);
9541 if (inst.operands[2].isreg)
9542 reject_bad_reg (Rn);
9543
c19d1205 9544 if (unified_syntax)
b99bd4ef 9545 {
c19d1205
ZW
9546 if (!inst.operands[2].isreg)
9547 {
9548 /* For an immediate, we always generate a 32-bit opcode;
9549 section relaxation will shrink it later if possible. */
9550 inst.instruction = THUMB_OP32 (inst.instruction);
9551 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9552 inst.instruction |= Rd << 8;
9553 inst.instruction |= Rs << 16;
9554 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9555 }
9556 else
9557 {
e27ec89e
PB
9558 bfd_boolean narrow;
9559
c19d1205 9560 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9561 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9562 narrow = !in_it_block ();
e27ec89e 9563 else
e07e6e58 9564 narrow = in_it_block ();
e27ec89e
PB
9565
9566 if (Rd > 7 || Rn > 7 || Rs > 7)
9567 narrow = FALSE;
9568 if (inst.operands[2].shifted)
9569 narrow = FALSE;
9570 if (inst.size_req == 4)
9571 narrow = FALSE;
9572
9573 if (narrow
c19d1205
ZW
9574 && Rd == Rs)
9575 {
9576 inst.instruction = THUMB_OP16 (inst.instruction);
9577 inst.instruction |= Rd;
9578 inst.instruction |= Rn << 3;
9579 return;
9580 }
b99bd4ef 9581
c19d1205
ZW
9582 /* If we get here, it can't be done in 16 bits. */
9583 constraint (inst.operands[2].shifted
9584 && inst.operands[2].immisreg,
9585 _("shift must be constant"));
9586 inst.instruction = THUMB_OP32 (inst.instruction);
9587 inst.instruction |= Rd << 8;
9588 inst.instruction |= Rs << 16;
9589 encode_thumb32_shifted_operand (2);
9590 }
a737bd4d 9591 }
c19d1205 9592 else
b99bd4ef 9593 {
c19d1205
ZW
9594 /* On its face this is a lie - the instruction does set the
9595 flags. However, the only supported mnemonic in this mode
9596 says it doesn't. */
9597 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9598
c19d1205
ZW
9599 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9600 _("unshifted register required"));
9601 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9602 constraint (Rd != Rs,
9603 _("dest and source1 must be the same register"));
a737bd4d 9604
c19d1205
ZW
9605 inst.instruction = THUMB_OP16 (inst.instruction);
9606 inst.instruction |= Rd;
9607 inst.instruction |= Rn << 3;
b99bd4ef 9608 }
a737bd4d 9609}
b99bd4ef 9610
c19d1205
ZW
9611/* Similarly, but for instructions where the arithmetic operation is
9612 commutative, so we can allow either of them to be different from
9613 the destination operand in a 16-bit instruction. For instance, all
9614 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9615 accepted. */
9616static void
9617do_t_arit3c (void)
a737bd4d 9618{
c19d1205 9619 int Rd, Rs, Rn;
b99bd4ef 9620
c19d1205
ZW
9621 Rd = inst.operands[0].reg;
9622 Rs = (inst.operands[1].present
9623 ? inst.operands[1].reg /* Rd, Rs, foo */
9624 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9625 Rn = inst.operands[2].reg;
c921be7d 9626
fdfde340
JM
9627 reject_bad_reg (Rd);
9628 reject_bad_reg (Rs);
9629 if (inst.operands[2].isreg)
9630 reject_bad_reg (Rn);
a737bd4d 9631
c19d1205 9632 if (unified_syntax)
a737bd4d 9633 {
c19d1205 9634 if (!inst.operands[2].isreg)
b99bd4ef 9635 {
c19d1205
ZW
9636 /* For an immediate, we always generate a 32-bit opcode;
9637 section relaxation will shrink it later if possible. */
9638 inst.instruction = THUMB_OP32 (inst.instruction);
9639 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9640 inst.instruction |= Rd << 8;
9641 inst.instruction |= Rs << 16;
9642 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9643 }
c19d1205 9644 else
a737bd4d 9645 {
e27ec89e
PB
9646 bfd_boolean narrow;
9647
c19d1205 9648 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9649 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9650 narrow = !in_it_block ();
e27ec89e 9651 else
e07e6e58 9652 narrow = in_it_block ();
e27ec89e
PB
9653
9654 if (Rd > 7 || Rn > 7 || Rs > 7)
9655 narrow = FALSE;
9656 if (inst.operands[2].shifted)
9657 narrow = FALSE;
9658 if (inst.size_req == 4)
9659 narrow = FALSE;
9660
9661 if (narrow)
a737bd4d 9662 {
c19d1205 9663 if (Rd == Rs)
a737bd4d 9664 {
c19d1205
ZW
9665 inst.instruction = THUMB_OP16 (inst.instruction);
9666 inst.instruction |= Rd;
9667 inst.instruction |= Rn << 3;
9668 return;
a737bd4d 9669 }
c19d1205 9670 if (Rd == Rn)
a737bd4d 9671 {
c19d1205
ZW
9672 inst.instruction = THUMB_OP16 (inst.instruction);
9673 inst.instruction |= Rd;
9674 inst.instruction |= Rs << 3;
9675 return;
a737bd4d
NC
9676 }
9677 }
c19d1205
ZW
9678
9679 /* If we get here, it can't be done in 16 bits. */
9680 constraint (inst.operands[2].shifted
9681 && inst.operands[2].immisreg,
9682 _("shift must be constant"));
9683 inst.instruction = THUMB_OP32 (inst.instruction);
9684 inst.instruction |= Rd << 8;
9685 inst.instruction |= Rs << 16;
9686 encode_thumb32_shifted_operand (2);
a737bd4d 9687 }
b99bd4ef 9688 }
c19d1205
ZW
9689 else
9690 {
9691 /* On its face this is a lie - the instruction does set the
9692 flags. However, the only supported mnemonic in this mode
9693 says it doesn't. */
9694 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9695
c19d1205
ZW
9696 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9697 _("unshifted register required"));
9698 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9699
9700 inst.instruction = THUMB_OP16 (inst.instruction);
9701 inst.instruction |= Rd;
9702
9703 if (Rd == Rs)
9704 inst.instruction |= Rn << 3;
9705 else if (Rd == Rn)
9706 inst.instruction |= Rs << 3;
9707 else
9708 constraint (1, _("dest must overlap one source register"));
9709 }
a737bd4d
NC
9710}
9711
62b3e311
PB
9712static void
9713do_t_barrier (void)
9714{
9715 if (inst.operands[0].present)
9716 {
9717 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
9718 && inst.operands[0].imm > 0xf
9719 && inst.operands[0].imm < 0x0,
bd3ba5d1 9720 _("bad barrier type"));
62b3e311
PB
9721 inst.instruction |= inst.operands[0].imm;
9722 }
9723 else
9724 inst.instruction |= 0xf;
9725}
9726
c19d1205
ZW
9727static void
9728do_t_bfc (void)
a737bd4d 9729{
fdfde340 9730 unsigned Rd;
c19d1205
ZW
9731 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9732 constraint (msb > 32, _("bit-field extends past end of register"));
9733 /* The instruction encoding stores the LSB and MSB,
9734 not the LSB and width. */
fdfde340
JM
9735 Rd = inst.operands[0].reg;
9736 reject_bad_reg (Rd);
9737 inst.instruction |= Rd << 8;
c19d1205
ZW
9738 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9739 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9740 inst.instruction |= msb - 1;
b99bd4ef
NC
9741}
9742
c19d1205
ZW
9743static void
9744do_t_bfi (void)
b99bd4ef 9745{
fdfde340 9746 int Rd, Rn;
c19d1205 9747 unsigned int msb;
b99bd4ef 9748
fdfde340
JM
9749 Rd = inst.operands[0].reg;
9750 reject_bad_reg (Rd);
9751
c19d1205
ZW
9752 /* #0 in second position is alternative syntax for bfc, which is
9753 the same instruction but with REG_PC in the Rm field. */
9754 if (!inst.operands[1].isreg)
fdfde340
JM
9755 Rn = REG_PC;
9756 else
9757 {
9758 Rn = inst.operands[1].reg;
9759 reject_bad_reg (Rn);
9760 }
b99bd4ef 9761
c19d1205
ZW
9762 msb = inst.operands[2].imm + inst.operands[3].imm;
9763 constraint (msb > 32, _("bit-field extends past end of register"));
9764 /* The instruction encoding stores the LSB and MSB,
9765 not the LSB and width. */
fdfde340
JM
9766 inst.instruction |= Rd << 8;
9767 inst.instruction |= Rn << 16;
c19d1205
ZW
9768 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9769 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9770 inst.instruction |= msb - 1;
b99bd4ef
NC
9771}
9772
c19d1205
ZW
9773static void
9774do_t_bfx (void)
b99bd4ef 9775{
fdfde340
JM
9776 unsigned Rd, Rn;
9777
9778 Rd = inst.operands[0].reg;
9779 Rn = inst.operands[1].reg;
9780
9781 reject_bad_reg (Rd);
9782 reject_bad_reg (Rn);
9783
c19d1205
ZW
9784 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9785 _("bit-field extends past end of register"));
fdfde340
JM
9786 inst.instruction |= Rd << 8;
9787 inst.instruction |= Rn << 16;
c19d1205
ZW
9788 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9789 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9790 inst.instruction |= inst.operands[3].imm - 1;
9791}
b99bd4ef 9792
c19d1205
ZW
9793/* ARM V5 Thumb BLX (argument parse)
9794 BLX <target_addr> which is BLX(1)
9795 BLX <Rm> which is BLX(2)
9796 Unfortunately, there are two different opcodes for this mnemonic.
9797 So, the insns[].value is not used, and the code here zaps values
9798 into inst.instruction.
b99bd4ef 9799
c19d1205
ZW
9800 ??? How to take advantage of the additional two bits of displacement
9801 available in Thumb32 mode? Need new relocation? */
b99bd4ef 9802
c19d1205
ZW
9803static void
9804do_t_blx (void)
9805{
e07e6e58
NC
9806 set_it_insn_type_last ();
9807
c19d1205 9808 if (inst.operands[0].isreg)
fdfde340
JM
9809 {
9810 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9811 /* We have a register, so this is BLX(2). */
9812 inst.instruction |= inst.operands[0].reg << 3;
9813 }
b99bd4ef
NC
9814 else
9815 {
c19d1205 9816 /* No register. This must be BLX(1). */
2fc8bdac 9817 inst.instruction = 0xf000e800;
0855e32b 9818 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
9819 }
9820}
9821
c19d1205
ZW
9822static void
9823do_t_branch (void)
b99bd4ef 9824{
0110f2b8 9825 int opcode;
dfa9f0d5 9826 int cond;
9ae92b05 9827 int reloc;
dfa9f0d5 9828
e07e6e58
NC
9829 cond = inst.cond;
9830 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9831
9832 if (in_it_block ())
dfa9f0d5
PB
9833 {
9834 /* Conditional branches inside IT blocks are encoded as unconditional
9835 branches. */
9836 cond = COND_ALWAYS;
dfa9f0d5
PB
9837 }
9838 else
9839 cond = inst.cond;
9840
9841 if (cond != COND_ALWAYS)
0110f2b8
PB
9842 opcode = T_MNEM_bcond;
9843 else
9844 opcode = inst.instruction;
9845
12d6b0b7
RS
9846 if (unified_syntax
9847 && (inst.size_req == 4
9848 || (inst.size_req != 2 && inst.operands[0].hasreloc)))
c19d1205 9849 {
0110f2b8 9850 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9851 if (cond == COND_ALWAYS)
9ae92b05 9852 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9853 else
9854 {
9c2799c2 9855 gas_assert (cond != 0xF);
dfa9f0d5 9856 inst.instruction |= cond << 22;
9ae92b05 9857 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
9858 }
9859 }
b99bd4ef
NC
9860 else
9861 {
0110f2b8 9862 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9863 if (cond == COND_ALWAYS)
9ae92b05 9864 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 9865 else
b99bd4ef 9866 {
dfa9f0d5 9867 inst.instruction |= cond << 8;
9ae92b05 9868 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9869 }
0110f2b8
PB
9870 /* Allow section relaxation. */
9871 if (unified_syntax && inst.size_req != 2)
9872 inst.relax = opcode;
b99bd4ef 9873 }
9ae92b05 9874 inst.reloc.type = reloc;
c19d1205 9875 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9876}
9877
9878static void
c19d1205 9879do_t_bkpt (void)
b99bd4ef 9880{
dfa9f0d5
PB
9881 constraint (inst.cond != COND_ALWAYS,
9882 _("instruction is always unconditional"));
c19d1205 9883 if (inst.operands[0].present)
b99bd4ef 9884 {
c19d1205
ZW
9885 constraint (inst.operands[0].imm > 255,
9886 _("immediate value out of range"));
9887 inst.instruction |= inst.operands[0].imm;
e07e6e58 9888 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 9889 }
b99bd4ef
NC
9890}
9891
9892static void
c19d1205 9893do_t_branch23 (void)
b99bd4ef 9894{
e07e6e58 9895 set_it_insn_type_last ();
0855e32b
NS
9896 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
9897
9898 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
9899 this file. We used to simply ignore the PLT reloc type here --
9900 the branch encoding is now needed to deal with TLSCALL relocs.
9901 So if we see a PLT reloc now, put it back to how it used to be to
9902 keep the preexisting behaviour. */
9903 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
9904 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 9905
4343666d 9906#if defined(OBJ_COFF)
c19d1205
ZW
9907 /* If the destination of the branch is a defined symbol which does not have
9908 the THUMB_FUNC attribute, then we must be calling a function which has
9909 the (interfacearm) attribute. We look for the Thumb entry point to that
9910 function and change the branch to refer to that function instead. */
9911 if ( inst.reloc.exp.X_op == O_symbol
9912 && inst.reloc.exp.X_add_symbol != NULL
9913 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9914 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9915 inst.reloc.exp.X_add_symbol =
9916 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 9917#endif
90e4755a
RE
9918}
9919
9920static void
c19d1205 9921do_t_bx (void)
90e4755a 9922{
e07e6e58 9923 set_it_insn_type_last ();
c19d1205
ZW
9924 inst.instruction |= inst.operands[0].reg << 3;
9925 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9926 should cause the alignment to be checked once it is known. This is
9927 because BX PC only works if the instruction is word aligned. */
9928}
90e4755a 9929
c19d1205
ZW
9930static void
9931do_t_bxj (void)
9932{
fdfde340 9933 int Rm;
90e4755a 9934
e07e6e58 9935 set_it_insn_type_last ();
fdfde340
JM
9936 Rm = inst.operands[0].reg;
9937 reject_bad_reg (Rm);
9938 inst.instruction |= Rm << 16;
90e4755a
RE
9939}
9940
9941static void
c19d1205 9942do_t_clz (void)
90e4755a 9943{
fdfde340
JM
9944 unsigned Rd;
9945 unsigned Rm;
9946
9947 Rd = inst.operands[0].reg;
9948 Rm = inst.operands[1].reg;
9949
9950 reject_bad_reg (Rd);
9951 reject_bad_reg (Rm);
9952
9953 inst.instruction |= Rd << 8;
9954 inst.instruction |= Rm << 16;
9955 inst.instruction |= Rm;
c19d1205 9956}
90e4755a 9957
dfa9f0d5
PB
9958static void
9959do_t_cps (void)
9960{
e07e6e58 9961 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
9962 inst.instruction |= inst.operands[0].imm;
9963}
9964
c19d1205
ZW
9965static void
9966do_t_cpsi (void)
9967{
e07e6e58 9968 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 9969 if (unified_syntax
62b3e311
PB
9970 && (inst.operands[1].present || inst.size_req == 4)
9971 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9972 {
c19d1205
ZW
9973 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9974 inst.instruction = 0xf3af8000;
9975 inst.instruction |= imod << 9;
9976 inst.instruction |= inst.operands[0].imm << 5;
9977 if (inst.operands[1].present)
9978 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9979 }
c19d1205 9980 else
90e4755a 9981 {
62b3e311
PB
9982 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9983 && (inst.operands[0].imm & 4),
9984 _("selected processor does not support 'A' form "
9985 "of this instruction"));
9986 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9987 _("Thumb does not support the 2-argument "
9988 "form of this instruction"));
9989 inst.instruction |= inst.operands[0].imm;
90e4755a 9990 }
90e4755a
RE
9991}
9992
c19d1205
ZW
9993/* THUMB CPY instruction (argument parse). */
9994
90e4755a 9995static void
c19d1205 9996do_t_cpy (void)
90e4755a 9997{
c19d1205 9998 if (inst.size_req == 4)
90e4755a 9999 {
c19d1205
ZW
10000 inst.instruction = THUMB_OP32 (T_MNEM_mov);
10001 inst.instruction |= inst.operands[0].reg << 8;
10002 inst.instruction |= inst.operands[1].reg;
90e4755a 10003 }
c19d1205 10004 else
90e4755a 10005 {
c19d1205
ZW
10006 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
10007 inst.instruction |= (inst.operands[0].reg & 0x7);
10008 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 10009 }
90e4755a
RE
10010}
10011
90e4755a 10012static void
25fe350b 10013do_t_cbz (void)
90e4755a 10014{
e07e6e58 10015 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
10016 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10017 inst.instruction |= inst.operands[0].reg;
10018 inst.reloc.pc_rel = 1;
10019 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
10020}
90e4755a 10021
62b3e311
PB
10022static void
10023do_t_dbg (void)
10024{
10025 inst.instruction |= inst.operands[0].imm;
10026}
10027
10028static void
10029do_t_div (void)
10030{
fdfde340
JM
10031 unsigned Rd, Rn, Rm;
10032
10033 Rd = inst.operands[0].reg;
10034 Rn = (inst.operands[1].present
10035 ? inst.operands[1].reg : Rd);
10036 Rm = inst.operands[2].reg;
10037
10038 reject_bad_reg (Rd);
10039 reject_bad_reg (Rn);
10040 reject_bad_reg (Rm);
10041
10042 inst.instruction |= Rd << 8;
10043 inst.instruction |= Rn << 16;
10044 inst.instruction |= Rm;
62b3e311
PB
10045}
10046
c19d1205
ZW
10047static void
10048do_t_hint (void)
10049{
10050 if (unified_syntax && inst.size_req == 4)
10051 inst.instruction = THUMB_OP32 (inst.instruction);
10052 else
10053 inst.instruction = THUMB_OP16 (inst.instruction);
10054}
90e4755a 10055
c19d1205
ZW
10056static void
10057do_t_it (void)
10058{
10059 unsigned int cond = inst.operands[0].imm;
e27ec89e 10060
e07e6e58
NC
10061 set_it_insn_type (IT_INSN);
10062 now_it.mask = (inst.instruction & 0xf) | 0x10;
10063 now_it.cc = cond;
e27ec89e
PB
10064
10065 /* If the condition is a negative condition, invert the mask. */
c19d1205 10066 if ((cond & 0x1) == 0x0)
90e4755a 10067 {
c19d1205 10068 unsigned int mask = inst.instruction & 0x000f;
90e4755a 10069
c19d1205
ZW
10070 if ((mask & 0x7) == 0)
10071 /* no conversion needed */;
10072 else if ((mask & 0x3) == 0)
e27ec89e
PB
10073 mask ^= 0x8;
10074 else if ((mask & 0x1) == 0)
10075 mask ^= 0xC;
c19d1205 10076 else
e27ec89e 10077 mask ^= 0xE;
90e4755a 10078
e27ec89e
PB
10079 inst.instruction &= 0xfff0;
10080 inst.instruction |= mask;
c19d1205 10081 }
90e4755a 10082
c19d1205
ZW
10083 inst.instruction |= cond << 4;
10084}
90e4755a 10085
3c707909
PB
10086/* Helper function used for both push/pop and ldm/stm. */
10087static void
10088encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
10089{
10090 bfd_boolean load;
10091
10092 load = (inst.instruction & (1 << 20)) != 0;
10093
10094 if (mask & (1 << 13))
10095 inst.error = _("SP not allowed in register list");
1e5b0379
NC
10096
10097 if ((mask & (1 << base)) != 0
10098 && writeback)
10099 inst.error = _("having the base register in the register list when "
10100 "using write back is UNPREDICTABLE");
10101
3c707909
PB
10102 if (load)
10103 {
e07e6e58
NC
10104 if (mask & (1 << 15))
10105 {
10106 if (mask & (1 << 14))
10107 inst.error = _("LR and PC should not both be in register list");
10108 else
10109 set_it_insn_type_last ();
10110 }
3c707909
PB
10111 }
10112 else
10113 {
10114 if (mask & (1 << 15))
10115 inst.error = _("PC not allowed in register list");
3c707909
PB
10116 }
10117
10118 if ((mask & (mask - 1)) == 0)
10119 {
10120 /* Single register transfers implemented as str/ldr. */
10121 if (writeback)
10122 {
10123 if (inst.instruction & (1 << 23))
10124 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
10125 else
10126 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
10127 }
10128 else
10129 {
10130 if (inst.instruction & (1 << 23))
10131 inst.instruction = 0x00800000; /* ia -> [base] */
10132 else
10133 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
10134 }
10135
10136 inst.instruction |= 0xf8400000;
10137 if (load)
10138 inst.instruction |= 0x00100000;
10139
5f4273c7 10140 mask = ffs (mask) - 1;
3c707909
PB
10141 mask <<= 12;
10142 }
10143 else if (writeback)
10144 inst.instruction |= WRITE_BACK;
10145
10146 inst.instruction |= mask;
10147 inst.instruction |= base << 16;
10148}
10149
c19d1205
ZW
10150static void
10151do_t_ldmstm (void)
10152{
10153 /* This really doesn't seem worth it. */
10154 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10155 _("expression too complex"));
10156 constraint (inst.operands[1].writeback,
10157 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 10158
c19d1205
ZW
10159 if (unified_syntax)
10160 {
3c707909
PB
10161 bfd_boolean narrow;
10162 unsigned mask;
10163
10164 narrow = FALSE;
c19d1205
ZW
10165 /* See if we can use a 16-bit instruction. */
10166 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
10167 && inst.size_req != 4
3c707909 10168 && !(inst.operands[1].imm & ~0xff))
90e4755a 10169 {
3c707909 10170 mask = 1 << inst.operands[0].reg;
90e4755a 10171
eab4f823 10172 if (inst.operands[0].reg <= 7)
90e4755a 10173 {
3c707909 10174 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
10175 ? inst.operands[0].writeback
10176 : (inst.operands[0].writeback
10177 == !(inst.operands[1].imm & mask)))
10178 {
10179 if (inst.instruction == T_MNEM_stmia
10180 && (inst.operands[1].imm & mask)
10181 && (inst.operands[1].imm & (mask - 1)))
10182 as_warn (_("value stored for r%d is UNKNOWN"),
10183 inst.operands[0].reg);
3c707909 10184
eab4f823
MGD
10185 inst.instruction = THUMB_OP16 (inst.instruction);
10186 inst.instruction |= inst.operands[0].reg << 8;
10187 inst.instruction |= inst.operands[1].imm;
10188 narrow = TRUE;
10189 }
10190 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10191 {
10192 /* This means 1 register in reg list one of 3 situations:
10193 1. Instruction is stmia, but without writeback.
10194 2. lmdia without writeback, but with Rn not in
10195 reglist.
10196 3. ldmia with writeback, but with Rn in reglist.
10197 Case 3 is UNPREDICTABLE behaviour, so we handle
10198 case 1 and 2 which can be converted into a 16-bit
10199 str or ldr. The SP cases are handled below. */
10200 unsigned long opcode;
10201 /* First, record an error for Case 3. */
10202 if (inst.operands[1].imm & mask
10203 && inst.operands[0].writeback)
10204 inst.error =
10205 _("having the base register in the register list when "
10206 "using write back is UNPREDICTABLE");
10207
10208 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
10209 : T_MNEM_ldr);
10210 inst.instruction = THUMB_OP16 (opcode);
10211 inst.instruction |= inst.operands[0].reg << 3;
10212 inst.instruction |= (ffs (inst.operands[1].imm)-1);
10213 narrow = TRUE;
10214 }
90e4755a 10215 }
eab4f823 10216 else if (inst.operands[0] .reg == REG_SP)
90e4755a 10217 {
eab4f823
MGD
10218 if (inst.operands[0].writeback)
10219 {
10220 inst.instruction =
10221 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10222 ? T_MNEM_push : T_MNEM_pop);
10223 inst.instruction |= inst.operands[1].imm;
10224 narrow = TRUE;
10225 }
10226 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10227 {
10228 inst.instruction =
10229 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10230 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10231 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10232 narrow = TRUE;
10233 }
90e4755a 10234 }
3c707909
PB
10235 }
10236
10237 if (!narrow)
10238 {
c19d1205
ZW
10239 if (inst.instruction < 0xffff)
10240 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 10241
5f4273c7
NC
10242 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10243 inst.operands[0].writeback);
90e4755a
RE
10244 }
10245 }
c19d1205 10246 else
90e4755a 10247 {
c19d1205
ZW
10248 constraint (inst.operands[0].reg > 7
10249 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
10250 constraint (inst.instruction != T_MNEM_ldmia
10251 && inst.instruction != T_MNEM_stmia,
10252 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 10253 if (inst.instruction == T_MNEM_stmia)
f03698e6 10254 {
c19d1205
ZW
10255 if (!inst.operands[0].writeback)
10256 as_warn (_("this instruction will write back the base register"));
10257 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10258 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 10259 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 10260 inst.operands[0].reg);
f03698e6 10261 }
c19d1205 10262 else
90e4755a 10263 {
c19d1205
ZW
10264 if (!inst.operands[0].writeback
10265 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10266 as_warn (_("this instruction will write back the base register"));
10267 else if (inst.operands[0].writeback
10268 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10269 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
10270 }
10271
c19d1205
ZW
10272 inst.instruction = THUMB_OP16 (inst.instruction);
10273 inst.instruction |= inst.operands[0].reg << 8;
10274 inst.instruction |= inst.operands[1].imm;
10275 }
10276}
e28cd48c 10277
c19d1205
ZW
10278static void
10279do_t_ldrex (void)
10280{
10281 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10282 || inst.operands[1].postind || inst.operands[1].writeback
10283 || inst.operands[1].immisreg || inst.operands[1].shifted
10284 || inst.operands[1].negative,
01cfc07f 10285 BAD_ADDR_MODE);
e28cd48c 10286
5be8be5d
DG
10287 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10288
c19d1205
ZW
10289 inst.instruction |= inst.operands[0].reg << 12;
10290 inst.instruction |= inst.operands[1].reg << 16;
10291 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10292}
e28cd48c 10293
c19d1205
ZW
10294static void
10295do_t_ldrexd (void)
10296{
10297 if (!inst.operands[1].present)
1cac9012 10298 {
c19d1205
ZW
10299 constraint (inst.operands[0].reg == REG_LR,
10300 _("r14 not allowed as first register "
10301 "when second register is omitted"));
10302 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 10303 }
c19d1205
ZW
10304 constraint (inst.operands[0].reg == inst.operands[1].reg,
10305 BAD_OVERLAP);
b99bd4ef 10306
c19d1205
ZW
10307 inst.instruction |= inst.operands[0].reg << 12;
10308 inst.instruction |= inst.operands[1].reg << 8;
10309 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10310}
10311
10312static void
c19d1205 10313do_t_ldst (void)
b99bd4ef 10314{
0110f2b8
PB
10315 unsigned long opcode;
10316 int Rn;
10317
e07e6e58
NC
10318 if (inst.operands[0].isreg
10319 && !inst.operands[0].preind
10320 && inst.operands[0].reg == REG_PC)
10321 set_it_insn_type_last ();
10322
0110f2b8 10323 opcode = inst.instruction;
c19d1205 10324 if (unified_syntax)
b99bd4ef 10325 {
53365c0d
PB
10326 if (!inst.operands[1].isreg)
10327 {
10328 if (opcode <= 0xffff)
10329 inst.instruction = THUMB_OP32 (opcode);
10330 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10331 return;
10332 }
0110f2b8
PB
10333 if (inst.operands[1].isreg
10334 && !inst.operands[1].writeback
c19d1205
ZW
10335 && !inst.operands[1].shifted && !inst.operands[1].postind
10336 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
10337 && opcode <= 0xffff
10338 && inst.size_req != 4)
c19d1205 10339 {
0110f2b8
PB
10340 /* Insn may have a 16-bit form. */
10341 Rn = inst.operands[1].reg;
10342 if (inst.operands[1].immisreg)
10343 {
10344 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 10345 /* [Rn, Rik] */
0110f2b8
PB
10346 if (Rn <= 7 && inst.operands[1].imm <= 7)
10347 goto op16;
5be8be5d
DG
10348 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10349 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
10350 }
10351 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10352 && opcode != T_MNEM_ldrsb)
10353 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10354 || (Rn == REG_SP && opcode == T_MNEM_str))
10355 {
10356 /* [Rn, #const] */
10357 if (Rn > 7)
10358 {
10359 if (Rn == REG_PC)
10360 {
10361 if (inst.reloc.pc_rel)
10362 opcode = T_MNEM_ldr_pc2;
10363 else
10364 opcode = T_MNEM_ldr_pc;
10365 }
10366 else
10367 {
10368 if (opcode == T_MNEM_ldr)
10369 opcode = T_MNEM_ldr_sp;
10370 else
10371 opcode = T_MNEM_str_sp;
10372 }
10373 inst.instruction = inst.operands[0].reg << 8;
10374 }
10375 else
10376 {
10377 inst.instruction = inst.operands[0].reg;
10378 inst.instruction |= inst.operands[1].reg << 3;
10379 }
10380 inst.instruction |= THUMB_OP16 (opcode);
10381 if (inst.size_req == 2)
10382 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10383 else
10384 inst.relax = opcode;
10385 return;
10386 }
c19d1205 10387 }
0110f2b8 10388 /* Definitely a 32-bit variant. */
5be8be5d 10389
8d67f500
NC
10390 /* Warning for Erratum 752419. */
10391 if (opcode == T_MNEM_ldr
10392 && inst.operands[0].reg == REG_SP
10393 && inst.operands[1].writeback == 1
10394 && !inst.operands[1].immisreg)
10395 {
10396 if (no_cpu_selected ()
10397 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
10398 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
10399 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
10400 as_warn (_("This instruction may be unpredictable "
10401 "if executed on M-profile cores "
10402 "with interrupts enabled."));
10403 }
10404
5be8be5d
DG
10405 /* Do some validations regarding addressing modes. */
10406 if (inst.operands[1].immisreg && opcode != T_MNEM_ldr
10407 && opcode != T_MNEM_str)
10408 reject_bad_reg (inst.operands[1].imm);
10409
0110f2b8 10410 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
10411 inst.instruction |= inst.operands[0].reg << 12;
10412 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
10413 return;
10414 }
10415
c19d1205
ZW
10416 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10417
10418 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 10419 {
c19d1205
ZW
10420 /* Only [Rn,Rm] is acceptable. */
10421 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10422 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10423 || inst.operands[1].postind || inst.operands[1].shifted
10424 || inst.operands[1].negative,
10425 _("Thumb does not support this addressing mode"));
10426 inst.instruction = THUMB_OP16 (inst.instruction);
10427 goto op16;
b99bd4ef 10428 }
5f4273c7 10429
c19d1205
ZW
10430 inst.instruction = THUMB_OP16 (inst.instruction);
10431 if (!inst.operands[1].isreg)
10432 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10433 return;
b99bd4ef 10434
c19d1205
ZW
10435 constraint (!inst.operands[1].preind
10436 || inst.operands[1].shifted
10437 || inst.operands[1].writeback,
10438 _("Thumb does not support this addressing mode"));
10439 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 10440 {
c19d1205
ZW
10441 constraint (inst.instruction & 0x0600,
10442 _("byte or halfword not valid for base register"));
10443 constraint (inst.operands[1].reg == REG_PC
10444 && !(inst.instruction & THUMB_LOAD_BIT),
10445 _("r15 based store not allowed"));
10446 constraint (inst.operands[1].immisreg,
10447 _("invalid base register for register offset"));
b99bd4ef 10448
c19d1205
ZW
10449 if (inst.operands[1].reg == REG_PC)
10450 inst.instruction = T_OPCODE_LDR_PC;
10451 else if (inst.instruction & THUMB_LOAD_BIT)
10452 inst.instruction = T_OPCODE_LDR_SP;
10453 else
10454 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 10455
c19d1205
ZW
10456 inst.instruction |= inst.operands[0].reg << 8;
10457 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10458 return;
10459 }
90e4755a 10460
c19d1205
ZW
10461 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10462 if (!inst.operands[1].immisreg)
10463 {
10464 /* Immediate offset. */
10465 inst.instruction |= inst.operands[0].reg;
10466 inst.instruction |= inst.operands[1].reg << 3;
10467 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10468 return;
10469 }
90e4755a 10470
c19d1205
ZW
10471 /* Register offset. */
10472 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10473 constraint (inst.operands[1].negative,
10474 _("Thumb does not support this addressing mode"));
90e4755a 10475
c19d1205
ZW
10476 op16:
10477 switch (inst.instruction)
10478 {
10479 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10480 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10481 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10482 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10483 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10484 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10485 case 0x5600 /* ldrsb */:
10486 case 0x5e00 /* ldrsh */: break;
10487 default: abort ();
10488 }
90e4755a 10489
c19d1205
ZW
10490 inst.instruction |= inst.operands[0].reg;
10491 inst.instruction |= inst.operands[1].reg << 3;
10492 inst.instruction |= inst.operands[1].imm << 6;
10493}
90e4755a 10494
c19d1205
ZW
10495static void
10496do_t_ldstd (void)
10497{
10498 if (!inst.operands[1].present)
b99bd4ef 10499 {
c19d1205
ZW
10500 inst.operands[1].reg = inst.operands[0].reg + 1;
10501 constraint (inst.operands[0].reg == REG_LR,
10502 _("r14 not allowed here"));
b99bd4ef 10503 }
c19d1205
ZW
10504 inst.instruction |= inst.operands[0].reg << 12;
10505 inst.instruction |= inst.operands[1].reg << 8;
10506 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
10507}
10508
c19d1205
ZW
10509static void
10510do_t_ldstt (void)
10511{
10512 inst.instruction |= inst.operands[0].reg << 12;
10513 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10514}
a737bd4d 10515
b99bd4ef 10516static void
c19d1205 10517do_t_mla (void)
b99bd4ef 10518{
fdfde340 10519 unsigned Rd, Rn, Rm, Ra;
c921be7d 10520
fdfde340
JM
10521 Rd = inst.operands[0].reg;
10522 Rn = inst.operands[1].reg;
10523 Rm = inst.operands[2].reg;
10524 Ra = inst.operands[3].reg;
10525
10526 reject_bad_reg (Rd);
10527 reject_bad_reg (Rn);
10528 reject_bad_reg (Rm);
10529 reject_bad_reg (Ra);
10530
10531 inst.instruction |= Rd << 8;
10532 inst.instruction |= Rn << 16;
10533 inst.instruction |= Rm;
10534 inst.instruction |= Ra << 12;
c19d1205 10535}
b99bd4ef 10536
c19d1205
ZW
10537static void
10538do_t_mlal (void)
10539{
fdfde340
JM
10540 unsigned RdLo, RdHi, Rn, Rm;
10541
10542 RdLo = inst.operands[0].reg;
10543 RdHi = inst.operands[1].reg;
10544 Rn = inst.operands[2].reg;
10545 Rm = inst.operands[3].reg;
10546
10547 reject_bad_reg (RdLo);
10548 reject_bad_reg (RdHi);
10549 reject_bad_reg (Rn);
10550 reject_bad_reg (Rm);
10551
10552 inst.instruction |= RdLo << 12;
10553 inst.instruction |= RdHi << 8;
10554 inst.instruction |= Rn << 16;
10555 inst.instruction |= Rm;
c19d1205 10556}
b99bd4ef 10557
c19d1205
ZW
10558static void
10559do_t_mov_cmp (void)
10560{
fdfde340
JM
10561 unsigned Rn, Rm;
10562
10563 Rn = inst.operands[0].reg;
10564 Rm = inst.operands[1].reg;
10565
e07e6e58
NC
10566 if (Rn == REG_PC)
10567 set_it_insn_type_last ();
10568
c19d1205 10569 if (unified_syntax)
b99bd4ef 10570 {
c19d1205
ZW
10571 int r0off = (inst.instruction == T_MNEM_mov
10572 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 10573 unsigned long opcode;
3d388997
PB
10574 bfd_boolean narrow;
10575 bfd_boolean low_regs;
10576
fdfde340 10577 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 10578 opcode = inst.instruction;
e07e6e58 10579 if (in_it_block ())
0110f2b8 10580 narrow = opcode != T_MNEM_movs;
3d388997 10581 else
0110f2b8 10582 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
10583 if (inst.size_req == 4
10584 || inst.operands[1].shifted)
10585 narrow = FALSE;
10586
efd81785
PB
10587 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10588 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10589 && !inst.operands[1].shifted
fdfde340
JM
10590 && Rn == REG_PC
10591 && Rm == REG_LR)
efd81785
PB
10592 {
10593 inst.instruction = T2_SUBS_PC_LR;
10594 return;
10595 }
10596
fdfde340
JM
10597 if (opcode == T_MNEM_cmp)
10598 {
10599 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
10600 if (narrow)
10601 {
10602 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10603 but valid. */
10604 warn_deprecated_sp (Rm);
10605 /* R15 was documented as a valid choice for Rm in ARMv6,
10606 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10607 tools reject R15, so we do too. */
10608 constraint (Rm == REG_PC, BAD_PC);
10609 }
10610 else
10611 reject_bad_reg (Rm);
fdfde340
JM
10612 }
10613 else if (opcode == T_MNEM_mov
10614 || opcode == T_MNEM_movs)
10615 {
10616 if (inst.operands[1].isreg)
10617 {
10618 if (opcode == T_MNEM_movs)
10619 {
10620 reject_bad_reg (Rn);
10621 reject_bad_reg (Rm);
10622 }
76fa04a4
MGD
10623 else if (narrow)
10624 {
10625 /* This is mov.n. */
10626 if ((Rn == REG_SP || Rn == REG_PC)
10627 && (Rm == REG_SP || Rm == REG_PC))
10628 {
10629 as_warn (_("Use of r%u as a source register is "
10630 "deprecated when r%u is the destination "
10631 "register."), Rm, Rn);
10632 }
10633 }
10634 else
10635 {
10636 /* This is mov.w. */
10637 constraint (Rn == REG_PC, BAD_PC);
10638 constraint (Rm == REG_PC, BAD_PC);
10639 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
10640 }
fdfde340
JM
10641 }
10642 else
10643 reject_bad_reg (Rn);
10644 }
10645
c19d1205
ZW
10646 if (!inst.operands[1].isreg)
10647 {
0110f2b8 10648 /* Immediate operand. */
e07e6e58 10649 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
10650 narrow = 0;
10651 if (low_regs && narrow)
10652 {
10653 inst.instruction = THUMB_OP16 (opcode);
fdfde340 10654 inst.instruction |= Rn << 8;
0110f2b8
PB
10655 if (inst.size_req == 2)
10656 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10657 else
10658 inst.relax = opcode;
10659 }
10660 else
10661 {
10662 inst.instruction = THUMB_OP32 (inst.instruction);
10663 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10664 inst.instruction |= Rn << r0off;
0110f2b8
PB
10665 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10666 }
c19d1205 10667 }
728ca7c9
PB
10668 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10669 && (inst.instruction == T_MNEM_mov
10670 || inst.instruction == T_MNEM_movs))
10671 {
10672 /* Register shifts are encoded as separate shift instructions. */
10673 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10674
e07e6e58 10675 if (in_it_block ())
728ca7c9
PB
10676 narrow = !flags;
10677 else
10678 narrow = flags;
10679
10680 if (inst.size_req == 4)
10681 narrow = FALSE;
10682
10683 if (!low_regs || inst.operands[1].imm > 7)
10684 narrow = FALSE;
10685
fdfde340 10686 if (Rn != Rm)
728ca7c9
PB
10687 narrow = FALSE;
10688
10689 switch (inst.operands[1].shift_kind)
10690 {
10691 case SHIFT_LSL:
10692 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10693 break;
10694 case SHIFT_ASR:
10695 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10696 break;
10697 case SHIFT_LSR:
10698 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10699 break;
10700 case SHIFT_ROR:
10701 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10702 break;
10703 default:
5f4273c7 10704 abort ();
728ca7c9
PB
10705 }
10706
10707 inst.instruction = opcode;
10708 if (narrow)
10709 {
fdfde340 10710 inst.instruction |= Rn;
728ca7c9
PB
10711 inst.instruction |= inst.operands[1].imm << 3;
10712 }
10713 else
10714 {
10715 if (flags)
10716 inst.instruction |= CONDS_BIT;
10717
fdfde340
JM
10718 inst.instruction |= Rn << 8;
10719 inst.instruction |= Rm << 16;
728ca7c9
PB
10720 inst.instruction |= inst.operands[1].imm;
10721 }
10722 }
3d388997 10723 else if (!narrow)
c19d1205 10724 {
728ca7c9
PB
10725 /* Some mov with immediate shift have narrow variants.
10726 Register shifts are handled above. */
10727 if (low_regs && inst.operands[1].shifted
10728 && (inst.instruction == T_MNEM_mov
10729 || inst.instruction == T_MNEM_movs))
10730 {
e07e6e58 10731 if (in_it_block ())
728ca7c9
PB
10732 narrow = (inst.instruction == T_MNEM_mov);
10733 else
10734 narrow = (inst.instruction == T_MNEM_movs);
10735 }
10736
10737 if (narrow)
10738 {
10739 switch (inst.operands[1].shift_kind)
10740 {
10741 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10742 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10743 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10744 default: narrow = FALSE; break;
10745 }
10746 }
10747
10748 if (narrow)
10749 {
fdfde340
JM
10750 inst.instruction |= Rn;
10751 inst.instruction |= Rm << 3;
728ca7c9
PB
10752 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10753 }
10754 else
10755 {
10756 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10757 inst.instruction |= Rn << r0off;
728ca7c9
PB
10758 encode_thumb32_shifted_operand (1);
10759 }
c19d1205
ZW
10760 }
10761 else
10762 switch (inst.instruction)
10763 {
10764 case T_MNEM_mov:
10765 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
10766 inst.instruction |= (Rn & 0x8) << 4;
10767 inst.instruction |= (Rn & 0x7);
10768 inst.instruction |= Rm << 3;
c19d1205 10769 break;
b99bd4ef 10770
c19d1205
ZW
10771 case T_MNEM_movs:
10772 /* We know we have low registers at this point.
941a8a52
MGD
10773 Generate LSLS Rd, Rs, #0. */
10774 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
10775 inst.instruction |= Rn;
10776 inst.instruction |= Rm << 3;
c19d1205
ZW
10777 break;
10778
10779 case T_MNEM_cmp:
3d388997 10780 if (low_regs)
c19d1205
ZW
10781 {
10782 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
10783 inst.instruction |= Rn;
10784 inst.instruction |= Rm << 3;
c19d1205
ZW
10785 }
10786 else
10787 {
10788 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
10789 inst.instruction |= (Rn & 0x8) << 4;
10790 inst.instruction |= (Rn & 0x7);
10791 inst.instruction |= Rm << 3;
c19d1205
ZW
10792 }
10793 break;
10794 }
b99bd4ef
NC
10795 return;
10796 }
10797
c19d1205 10798 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
10799
10800 /* PR 10443: Do not silently ignore shifted operands. */
10801 constraint (inst.operands[1].shifted,
10802 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10803
c19d1205 10804 if (inst.operands[1].isreg)
b99bd4ef 10805 {
fdfde340 10806 if (Rn < 8 && Rm < 8)
b99bd4ef 10807 {
c19d1205
ZW
10808 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10809 since a MOV instruction produces unpredictable results. */
10810 if (inst.instruction == T_OPCODE_MOV_I8)
10811 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 10812 else
c19d1205 10813 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 10814
fdfde340
JM
10815 inst.instruction |= Rn;
10816 inst.instruction |= Rm << 3;
b99bd4ef
NC
10817 }
10818 else
10819 {
c19d1205
ZW
10820 if (inst.instruction == T_OPCODE_MOV_I8)
10821 inst.instruction = T_OPCODE_MOV_HR;
10822 else
10823 inst.instruction = T_OPCODE_CMP_HR;
10824 do_t_cpy ();
b99bd4ef
NC
10825 }
10826 }
c19d1205 10827 else
b99bd4ef 10828 {
fdfde340 10829 constraint (Rn > 7,
c19d1205 10830 _("only lo regs allowed with immediate"));
fdfde340 10831 inst.instruction |= Rn << 8;
c19d1205
ZW
10832 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10833 }
10834}
b99bd4ef 10835
c19d1205
ZW
10836static void
10837do_t_mov16 (void)
10838{
fdfde340 10839 unsigned Rd;
b6895b4f
PB
10840 bfd_vma imm;
10841 bfd_boolean top;
10842
10843 top = (inst.instruction & 0x00800000) != 0;
10844 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10845 {
10846 constraint (top, _(":lower16: not allowed this instruction"));
10847 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10848 }
10849 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10850 {
10851 constraint (!top, _(":upper16: not allowed this instruction"));
10852 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10853 }
10854
fdfde340
JM
10855 Rd = inst.operands[0].reg;
10856 reject_bad_reg (Rd);
10857
10858 inst.instruction |= Rd << 8;
b6895b4f
PB
10859 if (inst.reloc.type == BFD_RELOC_UNUSED)
10860 {
10861 imm = inst.reloc.exp.X_add_number;
10862 inst.instruction |= (imm & 0xf000) << 4;
10863 inst.instruction |= (imm & 0x0800) << 15;
10864 inst.instruction |= (imm & 0x0700) << 4;
10865 inst.instruction |= (imm & 0x00ff);
10866 }
c19d1205 10867}
b99bd4ef 10868
c19d1205
ZW
10869static void
10870do_t_mvn_tst (void)
10871{
fdfde340 10872 unsigned Rn, Rm;
c921be7d 10873
fdfde340
JM
10874 Rn = inst.operands[0].reg;
10875 Rm = inst.operands[1].reg;
10876
10877 if (inst.instruction == T_MNEM_cmp
10878 || inst.instruction == T_MNEM_cmn)
10879 constraint (Rn == REG_PC, BAD_PC);
10880 else
10881 reject_bad_reg (Rn);
10882 reject_bad_reg (Rm);
10883
c19d1205
ZW
10884 if (unified_syntax)
10885 {
10886 int r0off = (inst.instruction == T_MNEM_mvn
10887 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
10888 bfd_boolean narrow;
10889
10890 if (inst.size_req == 4
10891 || inst.instruction > 0xffff
10892 || inst.operands[1].shifted
fdfde340 10893 || Rn > 7 || Rm > 7)
3d388997
PB
10894 narrow = FALSE;
10895 else if (inst.instruction == T_MNEM_cmn)
10896 narrow = TRUE;
10897 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10898 narrow = !in_it_block ();
3d388997 10899 else
e07e6e58 10900 narrow = in_it_block ();
3d388997 10901
c19d1205 10902 if (!inst.operands[1].isreg)
b99bd4ef 10903 {
c19d1205
ZW
10904 /* For an immediate, we always generate a 32-bit opcode;
10905 section relaxation will shrink it later if possible. */
10906 if (inst.instruction < 0xffff)
10907 inst.instruction = THUMB_OP32 (inst.instruction);
10908 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10909 inst.instruction |= Rn << r0off;
c19d1205 10910 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10911 }
c19d1205 10912 else
b99bd4ef 10913 {
c19d1205 10914 /* See if we can do this with a 16-bit instruction. */
3d388997 10915 if (narrow)
b99bd4ef 10916 {
c19d1205 10917 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10918 inst.instruction |= Rn;
10919 inst.instruction |= Rm << 3;
b99bd4ef 10920 }
c19d1205 10921 else
b99bd4ef 10922 {
c19d1205
ZW
10923 constraint (inst.operands[1].shifted
10924 && inst.operands[1].immisreg,
10925 _("shift must be constant"));
10926 if (inst.instruction < 0xffff)
10927 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10928 inst.instruction |= Rn << r0off;
c19d1205 10929 encode_thumb32_shifted_operand (1);
b99bd4ef 10930 }
b99bd4ef
NC
10931 }
10932 }
10933 else
10934 {
c19d1205
ZW
10935 constraint (inst.instruction > 0xffff
10936 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10937 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10938 _("unshifted register required"));
fdfde340 10939 constraint (Rn > 7 || Rm > 7,
c19d1205 10940 BAD_HIREG);
b99bd4ef 10941
c19d1205 10942 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10943 inst.instruction |= Rn;
10944 inst.instruction |= Rm << 3;
b99bd4ef 10945 }
b99bd4ef
NC
10946}
10947
b05fe5cf 10948static void
c19d1205 10949do_t_mrs (void)
b05fe5cf 10950{
fdfde340 10951 unsigned Rd;
037e8744
JB
10952
10953 if (do_vfp_nsyn_mrs () == SUCCESS)
10954 return;
10955
90ec0d68
MGD
10956 Rd = inst.operands[0].reg;
10957 reject_bad_reg (Rd);
10958 inst.instruction |= Rd << 8;
10959
10960 if (inst.operands[1].isreg)
62b3e311 10961 {
90ec0d68
MGD
10962 unsigned br = inst.operands[1].reg;
10963 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
10964 as_bad (_("bad register for mrs"));
10965
10966 inst.instruction |= br & (0xf << 16);
10967 inst.instruction |= (br & 0x300) >> 4;
10968 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
10969 }
10970 else
10971 {
90ec0d68 10972 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 10973
d2cd1205
JB
10974 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
10975 constraint (flags != 0, _("selected processor does not support "
10976 "requested special purpose register"));
90ec0d68 10977 else
d2cd1205
JB
10978 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
10979 devices). */
10980 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10981 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 10982
90ec0d68
MGD
10983 inst.instruction |= (flags & SPSR_BIT) >> 2;
10984 inst.instruction |= inst.operands[1].imm & 0xff;
10985 inst.instruction |= 0xf0000;
10986 }
c19d1205 10987}
b05fe5cf 10988
c19d1205
ZW
10989static void
10990do_t_msr (void)
10991{
62b3e311 10992 int flags;
fdfde340 10993 unsigned Rn;
62b3e311 10994
037e8744
JB
10995 if (do_vfp_nsyn_msr () == SUCCESS)
10996 return;
10997
c19d1205
ZW
10998 constraint (!inst.operands[1].isreg,
10999 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
11000
11001 if (inst.operands[0].isreg)
11002 flags = (int)(inst.operands[0].reg);
11003 else
11004 flags = inst.operands[0].imm;
11005
d2cd1205 11006 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 11007 {
d2cd1205
JB
11008 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11009
11010 constraint ((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11011 && (bits & ~(PSR_s | PSR_f)) != 0)
11012 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11013 && bits != PSR_f),
11014 _("selected processor does not support requested special "
11015 "purpose register"));
62b3e311
PB
11016 }
11017 else
d2cd1205
JB
11018 constraint ((flags & 0xff) != 0, _("selected processor does not support "
11019 "requested special purpose register"));
c921be7d 11020
fdfde340
JM
11021 Rn = inst.operands[1].reg;
11022 reject_bad_reg (Rn);
11023
62b3e311 11024 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
11025 inst.instruction |= (flags & 0xf0000) >> 8;
11026 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 11027 inst.instruction |= (flags & 0xff);
fdfde340 11028 inst.instruction |= Rn << 16;
c19d1205 11029}
b05fe5cf 11030
c19d1205
ZW
11031static void
11032do_t_mul (void)
11033{
17828f45 11034 bfd_boolean narrow;
fdfde340 11035 unsigned Rd, Rn, Rm;
17828f45 11036
c19d1205
ZW
11037 if (!inst.operands[2].present)
11038 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 11039
fdfde340
JM
11040 Rd = inst.operands[0].reg;
11041 Rn = inst.operands[1].reg;
11042 Rm = inst.operands[2].reg;
11043
17828f45 11044 if (unified_syntax)
b05fe5cf 11045 {
17828f45 11046 if (inst.size_req == 4
fdfde340
JM
11047 || (Rd != Rn
11048 && Rd != Rm)
11049 || Rn > 7
11050 || Rm > 7)
17828f45
JM
11051 narrow = FALSE;
11052 else if (inst.instruction == T_MNEM_muls)
e07e6e58 11053 narrow = !in_it_block ();
17828f45 11054 else
e07e6e58 11055 narrow = in_it_block ();
b05fe5cf 11056 }
c19d1205 11057 else
b05fe5cf 11058 {
17828f45 11059 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 11060 constraint (Rn > 7 || Rm > 7,
c19d1205 11061 BAD_HIREG);
17828f45
JM
11062 narrow = TRUE;
11063 }
b05fe5cf 11064
17828f45
JM
11065 if (narrow)
11066 {
11067 /* 16-bit MULS/Conditional MUL. */
c19d1205 11068 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11069 inst.instruction |= Rd;
b05fe5cf 11070
fdfde340
JM
11071 if (Rd == Rn)
11072 inst.instruction |= Rm << 3;
11073 else if (Rd == Rm)
11074 inst.instruction |= Rn << 3;
c19d1205
ZW
11075 else
11076 constraint (1, _("dest must overlap one source register"));
11077 }
17828f45
JM
11078 else
11079 {
e07e6e58
NC
11080 constraint (inst.instruction != T_MNEM_mul,
11081 _("Thumb-2 MUL must not set flags"));
17828f45
JM
11082 /* 32-bit MUL. */
11083 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11084 inst.instruction |= Rd << 8;
11085 inst.instruction |= Rn << 16;
11086 inst.instruction |= Rm << 0;
11087
11088 reject_bad_reg (Rd);
11089 reject_bad_reg (Rn);
11090 reject_bad_reg (Rm);
17828f45 11091 }
c19d1205 11092}
b05fe5cf 11093
c19d1205
ZW
11094static void
11095do_t_mull (void)
11096{
fdfde340 11097 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 11098
fdfde340
JM
11099 RdLo = inst.operands[0].reg;
11100 RdHi = inst.operands[1].reg;
11101 Rn = inst.operands[2].reg;
11102 Rm = inst.operands[3].reg;
11103
11104 reject_bad_reg (RdLo);
11105 reject_bad_reg (RdHi);
11106 reject_bad_reg (Rn);
11107 reject_bad_reg (Rm);
11108
11109 inst.instruction |= RdLo << 12;
11110 inst.instruction |= RdHi << 8;
11111 inst.instruction |= Rn << 16;
11112 inst.instruction |= Rm;
11113
11114 if (RdLo == RdHi)
c19d1205
ZW
11115 as_tsktsk (_("rdhi and rdlo must be different"));
11116}
b05fe5cf 11117
c19d1205
ZW
11118static void
11119do_t_nop (void)
11120{
e07e6e58
NC
11121 set_it_insn_type (NEUTRAL_IT_INSN);
11122
c19d1205
ZW
11123 if (unified_syntax)
11124 {
11125 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 11126 {
c19d1205
ZW
11127 inst.instruction = THUMB_OP32 (inst.instruction);
11128 inst.instruction |= inst.operands[0].imm;
11129 }
11130 else
11131 {
bc2d1808
NC
11132 /* PR9722: Check for Thumb2 availability before
11133 generating a thumb2 nop instruction. */
afa62d5e 11134 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
11135 {
11136 inst.instruction = THUMB_OP16 (inst.instruction);
11137 inst.instruction |= inst.operands[0].imm << 4;
11138 }
11139 else
11140 inst.instruction = 0x46c0;
c19d1205
ZW
11141 }
11142 }
11143 else
11144 {
11145 constraint (inst.operands[0].present,
11146 _("Thumb does not support NOP with hints"));
11147 inst.instruction = 0x46c0;
11148 }
11149}
b05fe5cf 11150
c19d1205
ZW
11151static void
11152do_t_neg (void)
11153{
11154 if (unified_syntax)
11155 {
3d388997
PB
11156 bfd_boolean narrow;
11157
11158 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11159 narrow = !in_it_block ();
3d388997 11160 else
e07e6e58 11161 narrow = in_it_block ();
3d388997
PB
11162 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11163 narrow = FALSE;
11164 if (inst.size_req == 4)
11165 narrow = FALSE;
11166
11167 if (!narrow)
c19d1205
ZW
11168 {
11169 inst.instruction = THUMB_OP32 (inst.instruction);
11170 inst.instruction |= inst.operands[0].reg << 8;
11171 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
11172 }
11173 else
11174 {
c19d1205
ZW
11175 inst.instruction = THUMB_OP16 (inst.instruction);
11176 inst.instruction |= inst.operands[0].reg;
11177 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
11178 }
11179 }
11180 else
11181 {
c19d1205
ZW
11182 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
11183 BAD_HIREG);
11184 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11185
11186 inst.instruction = THUMB_OP16 (inst.instruction);
11187 inst.instruction |= inst.operands[0].reg;
11188 inst.instruction |= inst.operands[1].reg << 3;
11189 }
11190}
11191
1c444d06
JM
11192static void
11193do_t_orn (void)
11194{
11195 unsigned Rd, Rn;
11196
11197 Rd = inst.operands[0].reg;
11198 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
11199
fdfde340
JM
11200 reject_bad_reg (Rd);
11201 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
11202 reject_bad_reg (Rn);
11203
1c444d06
JM
11204 inst.instruction |= Rd << 8;
11205 inst.instruction |= Rn << 16;
11206
11207 if (!inst.operands[2].isreg)
11208 {
11209 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11210 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11211 }
11212 else
11213 {
11214 unsigned Rm;
11215
11216 Rm = inst.operands[2].reg;
fdfde340 11217 reject_bad_reg (Rm);
1c444d06
JM
11218
11219 constraint (inst.operands[2].shifted
11220 && inst.operands[2].immisreg,
11221 _("shift must be constant"));
11222 encode_thumb32_shifted_operand (2);
11223 }
11224}
11225
c19d1205
ZW
11226static void
11227do_t_pkhbt (void)
11228{
fdfde340
JM
11229 unsigned Rd, Rn, Rm;
11230
11231 Rd = inst.operands[0].reg;
11232 Rn = inst.operands[1].reg;
11233 Rm = inst.operands[2].reg;
11234
11235 reject_bad_reg (Rd);
11236 reject_bad_reg (Rn);
11237 reject_bad_reg (Rm);
11238
11239 inst.instruction |= Rd << 8;
11240 inst.instruction |= Rn << 16;
11241 inst.instruction |= Rm;
c19d1205
ZW
11242 if (inst.operands[3].present)
11243 {
11244 unsigned int val = inst.reloc.exp.X_add_number;
11245 constraint (inst.reloc.exp.X_op != O_constant,
11246 _("expression too complex"));
11247 inst.instruction |= (val & 0x1c) << 10;
11248 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 11249 }
c19d1205 11250}
b05fe5cf 11251
c19d1205
ZW
11252static void
11253do_t_pkhtb (void)
11254{
11255 if (!inst.operands[3].present)
1ef52f49
NC
11256 {
11257 unsigned Rtmp;
11258
11259 inst.instruction &= ~0x00000020;
11260
11261 /* PR 10168. Swap the Rm and Rn registers. */
11262 Rtmp = inst.operands[1].reg;
11263 inst.operands[1].reg = inst.operands[2].reg;
11264 inst.operands[2].reg = Rtmp;
11265 }
c19d1205 11266 do_t_pkhbt ();
b05fe5cf
ZW
11267}
11268
c19d1205
ZW
11269static void
11270do_t_pld (void)
11271{
fdfde340
JM
11272 if (inst.operands[0].immisreg)
11273 reject_bad_reg (inst.operands[0].imm);
11274
c19d1205
ZW
11275 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11276}
b05fe5cf 11277
c19d1205
ZW
11278static void
11279do_t_push_pop (void)
b99bd4ef 11280{
e9f89963 11281 unsigned mask;
5f4273c7 11282
c19d1205
ZW
11283 constraint (inst.operands[0].writeback,
11284 _("push/pop do not support {reglist}^"));
11285 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11286 _("expression too complex"));
b99bd4ef 11287
e9f89963
PB
11288 mask = inst.operands[0].imm;
11289 if ((mask & ~0xff) == 0)
3c707909 11290 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 11291 else if ((inst.instruction == T_MNEM_push
e9f89963 11292 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 11293 || (inst.instruction == T_MNEM_pop
e9f89963 11294 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 11295 {
c19d1205
ZW
11296 inst.instruction = THUMB_OP16 (inst.instruction);
11297 inst.instruction |= THUMB_PP_PC_LR;
3c707909 11298 inst.instruction |= mask & 0xff;
c19d1205
ZW
11299 }
11300 else if (unified_syntax)
11301 {
3c707909 11302 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 11303 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
11304 }
11305 else
11306 {
11307 inst.error = _("invalid register list to push/pop instruction");
11308 return;
11309 }
c19d1205 11310}
b99bd4ef 11311
c19d1205
ZW
11312static void
11313do_t_rbit (void)
11314{
fdfde340
JM
11315 unsigned Rd, Rm;
11316
11317 Rd = inst.operands[0].reg;
11318 Rm = inst.operands[1].reg;
11319
11320 reject_bad_reg (Rd);
11321 reject_bad_reg (Rm);
11322
11323 inst.instruction |= Rd << 8;
11324 inst.instruction |= Rm << 16;
11325 inst.instruction |= Rm;
c19d1205 11326}
b99bd4ef 11327
c19d1205
ZW
11328static void
11329do_t_rev (void)
11330{
fdfde340
JM
11331 unsigned Rd, Rm;
11332
11333 Rd = inst.operands[0].reg;
11334 Rm = inst.operands[1].reg;
11335
11336 reject_bad_reg (Rd);
11337 reject_bad_reg (Rm);
11338
11339 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
11340 && inst.size_req != 4)
11341 {
11342 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11343 inst.instruction |= Rd;
11344 inst.instruction |= Rm << 3;
c19d1205
ZW
11345 }
11346 else if (unified_syntax)
11347 {
11348 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11349 inst.instruction |= Rd << 8;
11350 inst.instruction |= Rm << 16;
11351 inst.instruction |= Rm;
c19d1205
ZW
11352 }
11353 else
11354 inst.error = BAD_HIREG;
11355}
b99bd4ef 11356
1c444d06
JM
11357static void
11358do_t_rrx (void)
11359{
11360 unsigned Rd, Rm;
11361
11362 Rd = inst.operands[0].reg;
11363 Rm = inst.operands[1].reg;
11364
fdfde340
JM
11365 reject_bad_reg (Rd);
11366 reject_bad_reg (Rm);
c921be7d 11367
1c444d06
JM
11368 inst.instruction |= Rd << 8;
11369 inst.instruction |= Rm;
11370}
11371
c19d1205
ZW
11372static void
11373do_t_rsb (void)
11374{
fdfde340 11375 unsigned Rd, Rs;
b99bd4ef 11376
c19d1205
ZW
11377 Rd = inst.operands[0].reg;
11378 Rs = (inst.operands[1].present
11379 ? inst.operands[1].reg /* Rd, Rs, foo */
11380 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 11381
fdfde340
JM
11382 reject_bad_reg (Rd);
11383 reject_bad_reg (Rs);
11384 if (inst.operands[2].isreg)
11385 reject_bad_reg (inst.operands[2].reg);
11386
c19d1205
ZW
11387 inst.instruction |= Rd << 8;
11388 inst.instruction |= Rs << 16;
11389 if (!inst.operands[2].isreg)
11390 {
026d3abb
PB
11391 bfd_boolean narrow;
11392
11393 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 11394 narrow = !in_it_block ();
026d3abb 11395 else
e07e6e58 11396 narrow = in_it_block ();
026d3abb
PB
11397
11398 if (Rd > 7 || Rs > 7)
11399 narrow = FALSE;
11400
11401 if (inst.size_req == 4 || !unified_syntax)
11402 narrow = FALSE;
11403
11404 if (inst.reloc.exp.X_op != O_constant
11405 || inst.reloc.exp.X_add_number != 0)
11406 narrow = FALSE;
11407
11408 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11409 relaxation, but it doesn't seem worth the hassle. */
11410 if (narrow)
11411 {
11412 inst.reloc.type = BFD_RELOC_UNUSED;
11413 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11414 inst.instruction |= Rs << 3;
11415 inst.instruction |= Rd;
11416 }
11417 else
11418 {
11419 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11420 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11421 }
c19d1205
ZW
11422 }
11423 else
11424 encode_thumb32_shifted_operand (2);
11425}
b99bd4ef 11426
c19d1205
ZW
11427static void
11428do_t_setend (void)
11429{
e07e6e58 11430 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11431 if (inst.operands[0].imm)
11432 inst.instruction |= 0x8;
11433}
b99bd4ef 11434
c19d1205
ZW
11435static void
11436do_t_shift (void)
11437{
11438 if (!inst.operands[1].present)
11439 inst.operands[1].reg = inst.operands[0].reg;
11440
11441 if (unified_syntax)
11442 {
3d388997
PB
11443 bfd_boolean narrow;
11444 int shift_kind;
11445
11446 switch (inst.instruction)
11447 {
11448 case T_MNEM_asr:
11449 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11450 case T_MNEM_lsl:
11451 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11452 case T_MNEM_lsr:
11453 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11454 case T_MNEM_ror:
11455 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11456 default: abort ();
11457 }
11458
11459 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11460 narrow = !in_it_block ();
3d388997 11461 else
e07e6e58 11462 narrow = in_it_block ();
3d388997
PB
11463 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11464 narrow = FALSE;
11465 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11466 narrow = FALSE;
11467 if (inst.operands[2].isreg
11468 && (inst.operands[1].reg != inst.operands[0].reg
11469 || inst.operands[2].reg > 7))
11470 narrow = FALSE;
11471 if (inst.size_req == 4)
11472 narrow = FALSE;
11473
fdfde340
JM
11474 reject_bad_reg (inst.operands[0].reg);
11475 reject_bad_reg (inst.operands[1].reg);
c921be7d 11476
3d388997 11477 if (!narrow)
c19d1205
ZW
11478 {
11479 if (inst.operands[2].isreg)
b99bd4ef 11480 {
fdfde340 11481 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
11482 inst.instruction = THUMB_OP32 (inst.instruction);
11483 inst.instruction |= inst.operands[0].reg << 8;
11484 inst.instruction |= inst.operands[1].reg << 16;
11485 inst.instruction |= inst.operands[2].reg;
11486 }
11487 else
11488 {
11489 inst.operands[1].shifted = 1;
3d388997 11490 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
11491 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11492 ? T_MNEM_movs : T_MNEM_mov);
11493 inst.instruction |= inst.operands[0].reg << 8;
11494 encode_thumb32_shifted_operand (1);
11495 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11496 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
11497 }
11498 }
11499 else
11500 {
c19d1205 11501 if (inst.operands[2].isreg)
b99bd4ef 11502 {
3d388997 11503 switch (shift_kind)
b99bd4ef 11504 {
3d388997
PB
11505 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11506 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11507 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11508 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 11509 default: abort ();
b99bd4ef 11510 }
5f4273c7 11511
c19d1205
ZW
11512 inst.instruction |= inst.operands[0].reg;
11513 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
11514 }
11515 else
11516 {
3d388997 11517 switch (shift_kind)
b99bd4ef 11518 {
3d388997
PB
11519 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11520 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11521 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 11522 default: abort ();
b99bd4ef 11523 }
c19d1205
ZW
11524 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11525 inst.instruction |= inst.operands[0].reg;
11526 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11527 }
11528 }
c19d1205
ZW
11529 }
11530 else
11531 {
11532 constraint (inst.operands[0].reg > 7
11533 || inst.operands[1].reg > 7, BAD_HIREG);
11534 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 11535
c19d1205
ZW
11536 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11537 {
11538 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11539 constraint (inst.operands[0].reg != inst.operands[1].reg,
11540 _("source1 and dest must be same register"));
b99bd4ef 11541
c19d1205
ZW
11542 switch (inst.instruction)
11543 {
11544 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11545 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11546 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11547 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11548 default: abort ();
11549 }
5f4273c7 11550
c19d1205
ZW
11551 inst.instruction |= inst.operands[0].reg;
11552 inst.instruction |= inst.operands[2].reg << 3;
11553 }
11554 else
b99bd4ef 11555 {
c19d1205
ZW
11556 switch (inst.instruction)
11557 {
11558 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11559 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11560 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11561 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11562 default: abort ();
11563 }
11564 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11565 inst.instruction |= inst.operands[0].reg;
11566 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11567 }
11568 }
b99bd4ef
NC
11569}
11570
11571static void
c19d1205 11572do_t_simd (void)
b99bd4ef 11573{
fdfde340
JM
11574 unsigned Rd, Rn, Rm;
11575
11576 Rd = inst.operands[0].reg;
11577 Rn = inst.operands[1].reg;
11578 Rm = inst.operands[2].reg;
11579
11580 reject_bad_reg (Rd);
11581 reject_bad_reg (Rn);
11582 reject_bad_reg (Rm);
11583
11584 inst.instruction |= Rd << 8;
11585 inst.instruction |= Rn << 16;
11586 inst.instruction |= Rm;
c19d1205 11587}
b99bd4ef 11588
03ee1b7f
NC
11589static void
11590do_t_simd2 (void)
11591{
11592 unsigned Rd, Rn, Rm;
11593
11594 Rd = inst.operands[0].reg;
11595 Rm = inst.operands[1].reg;
11596 Rn = inst.operands[2].reg;
11597
11598 reject_bad_reg (Rd);
11599 reject_bad_reg (Rn);
11600 reject_bad_reg (Rm);
11601
11602 inst.instruction |= Rd << 8;
11603 inst.instruction |= Rn << 16;
11604 inst.instruction |= Rm;
11605}
11606
c19d1205 11607static void
3eb17e6b 11608do_t_smc (void)
c19d1205
ZW
11609{
11610 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
11611 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
11612 _("SMC is not permitted on this architecture"));
c19d1205
ZW
11613 constraint (inst.reloc.exp.X_op != O_constant,
11614 _("expression too complex"));
11615 inst.reloc.type = BFD_RELOC_UNUSED;
11616 inst.instruction |= (value & 0xf000) >> 12;
11617 inst.instruction |= (value & 0x0ff0);
11618 inst.instruction |= (value & 0x000f) << 16;
11619}
b99bd4ef 11620
90ec0d68
MGD
11621static void
11622do_t_hvc (void)
11623{
11624 unsigned int value = inst.reloc.exp.X_add_number;
11625
11626 inst.reloc.type = BFD_RELOC_UNUSED;
11627 inst.instruction |= (value & 0x0fff);
11628 inst.instruction |= (value & 0xf000) << 4;
11629}
11630
c19d1205 11631static void
3a21c15a 11632do_t_ssat_usat (int bias)
c19d1205 11633{
fdfde340
JM
11634 unsigned Rd, Rn;
11635
11636 Rd = inst.operands[0].reg;
11637 Rn = inst.operands[2].reg;
11638
11639 reject_bad_reg (Rd);
11640 reject_bad_reg (Rn);
11641
11642 inst.instruction |= Rd << 8;
3a21c15a 11643 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 11644 inst.instruction |= Rn << 16;
b99bd4ef 11645
c19d1205 11646 if (inst.operands[3].present)
b99bd4ef 11647 {
3a21c15a
NC
11648 offsetT shift_amount = inst.reloc.exp.X_add_number;
11649
11650 inst.reloc.type = BFD_RELOC_UNUSED;
11651
c19d1205
ZW
11652 constraint (inst.reloc.exp.X_op != O_constant,
11653 _("expression too complex"));
b99bd4ef 11654
3a21c15a 11655 if (shift_amount != 0)
6189168b 11656 {
3a21c15a
NC
11657 constraint (shift_amount > 31,
11658 _("shift expression is too large"));
11659
c19d1205 11660 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
11661 inst.instruction |= 0x00200000; /* sh bit. */
11662
11663 inst.instruction |= (shift_amount & 0x1c) << 10;
11664 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
11665 }
11666 }
b99bd4ef 11667}
c921be7d 11668
3a21c15a
NC
11669static void
11670do_t_ssat (void)
11671{
11672 do_t_ssat_usat (1);
11673}
b99bd4ef 11674
0dd132b6 11675static void
c19d1205 11676do_t_ssat16 (void)
0dd132b6 11677{
fdfde340
JM
11678 unsigned Rd, Rn;
11679
11680 Rd = inst.operands[0].reg;
11681 Rn = inst.operands[2].reg;
11682
11683 reject_bad_reg (Rd);
11684 reject_bad_reg (Rn);
11685
11686 inst.instruction |= Rd << 8;
c19d1205 11687 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 11688 inst.instruction |= Rn << 16;
c19d1205 11689}
0dd132b6 11690
c19d1205
ZW
11691static void
11692do_t_strex (void)
11693{
11694 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11695 || inst.operands[2].postind || inst.operands[2].writeback
11696 || inst.operands[2].immisreg || inst.operands[2].shifted
11697 || inst.operands[2].negative,
01cfc07f 11698 BAD_ADDR_MODE);
0dd132b6 11699
5be8be5d
DG
11700 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11701
c19d1205
ZW
11702 inst.instruction |= inst.operands[0].reg << 8;
11703 inst.instruction |= inst.operands[1].reg << 12;
11704 inst.instruction |= inst.operands[2].reg << 16;
11705 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
11706}
11707
b99bd4ef 11708static void
c19d1205 11709do_t_strexd (void)
b99bd4ef 11710{
c19d1205
ZW
11711 if (!inst.operands[2].present)
11712 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 11713
c19d1205
ZW
11714 constraint (inst.operands[0].reg == inst.operands[1].reg
11715 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 11716 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 11717 BAD_OVERLAP);
b99bd4ef 11718
c19d1205
ZW
11719 inst.instruction |= inst.operands[0].reg;
11720 inst.instruction |= inst.operands[1].reg << 12;
11721 inst.instruction |= inst.operands[2].reg << 8;
11722 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
11723}
11724
11725static void
c19d1205 11726do_t_sxtah (void)
b99bd4ef 11727{
fdfde340
JM
11728 unsigned Rd, Rn, Rm;
11729
11730 Rd = inst.operands[0].reg;
11731 Rn = inst.operands[1].reg;
11732 Rm = inst.operands[2].reg;
11733
11734 reject_bad_reg (Rd);
11735 reject_bad_reg (Rn);
11736 reject_bad_reg (Rm);
11737
11738 inst.instruction |= Rd << 8;
11739 inst.instruction |= Rn << 16;
11740 inst.instruction |= Rm;
c19d1205
ZW
11741 inst.instruction |= inst.operands[3].imm << 4;
11742}
b99bd4ef 11743
c19d1205
ZW
11744static void
11745do_t_sxth (void)
11746{
fdfde340
JM
11747 unsigned Rd, Rm;
11748
11749 Rd = inst.operands[0].reg;
11750 Rm = inst.operands[1].reg;
11751
11752 reject_bad_reg (Rd);
11753 reject_bad_reg (Rm);
c921be7d
NC
11754
11755 if (inst.instruction <= 0xffff
11756 && inst.size_req != 4
fdfde340 11757 && Rd <= 7 && Rm <= 7
c19d1205 11758 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 11759 {
c19d1205 11760 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11761 inst.instruction |= Rd;
11762 inst.instruction |= Rm << 3;
b99bd4ef 11763 }
c19d1205 11764 else if (unified_syntax)
b99bd4ef 11765 {
c19d1205
ZW
11766 if (inst.instruction <= 0xffff)
11767 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11768 inst.instruction |= Rd << 8;
11769 inst.instruction |= Rm;
c19d1205 11770 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 11771 }
c19d1205 11772 else
b99bd4ef 11773 {
c19d1205
ZW
11774 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11775 _("Thumb encoding does not support rotation"));
11776 constraint (1, BAD_HIREG);
b99bd4ef 11777 }
c19d1205 11778}
b99bd4ef 11779
c19d1205
ZW
11780static void
11781do_t_swi (void)
11782{
b2a5fbdc
MGD
11783 /* We have to do the following check manually as ARM_EXT_OS only applies
11784 to ARM_EXT_V6M. */
11785 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
11786 {
ac7f631b
NC
11787 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
11788 /* This only applies to the v6m howver, not later architectures. */
11789 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
11790 as_bad (_("SVC is not permitted on this architecture"));
11791 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
11792 }
11793
c19d1205
ZW
11794 inst.reloc.type = BFD_RELOC_ARM_SWI;
11795}
b99bd4ef 11796
92e90b6e
PB
11797static void
11798do_t_tb (void)
11799{
fdfde340 11800 unsigned Rn, Rm;
92e90b6e
PB
11801 int half;
11802
11803 half = (inst.instruction & 0x10) != 0;
e07e6e58 11804 set_it_insn_type_last ();
dfa9f0d5
PB
11805 constraint (inst.operands[0].immisreg,
11806 _("instruction requires register index"));
fdfde340
JM
11807
11808 Rn = inst.operands[0].reg;
11809 Rm = inst.operands[0].imm;
c921be7d 11810
fdfde340
JM
11811 constraint (Rn == REG_SP, BAD_SP);
11812 reject_bad_reg (Rm);
11813
92e90b6e
PB
11814 constraint (!half && inst.operands[0].shifted,
11815 _("instruction does not allow shifted index"));
fdfde340 11816 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
11817}
11818
c19d1205
ZW
11819static void
11820do_t_usat (void)
11821{
3a21c15a 11822 do_t_ssat_usat (0);
b99bd4ef
NC
11823}
11824
11825static void
c19d1205 11826do_t_usat16 (void)
b99bd4ef 11827{
fdfde340
JM
11828 unsigned Rd, Rn;
11829
11830 Rd = inst.operands[0].reg;
11831 Rn = inst.operands[2].reg;
11832
11833 reject_bad_reg (Rd);
11834 reject_bad_reg (Rn);
11835
11836 inst.instruction |= Rd << 8;
c19d1205 11837 inst.instruction |= inst.operands[1].imm;
fdfde340 11838 inst.instruction |= Rn << 16;
b99bd4ef 11839}
c19d1205 11840
5287ad62 11841/* Neon instruction encoder helpers. */
5f4273c7 11842
5287ad62 11843/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 11844
5287ad62
JB
11845/* An "invalid" code for the following tables. */
11846#define N_INV -1u
11847
11848struct neon_tab_entry
b99bd4ef 11849{
5287ad62
JB
11850 unsigned integer;
11851 unsigned float_or_poly;
11852 unsigned scalar_or_imm;
11853};
5f4273c7 11854
5287ad62
JB
11855/* Map overloaded Neon opcodes to their respective encodings. */
11856#define NEON_ENC_TAB \
11857 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11858 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11859 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11860 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11861 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11862 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11863 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11864 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11865 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11866 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11867 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11868 /* Register variants of the following two instructions are encoded as
e07e6e58 11869 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
11870 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11871 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
11872 X(vfma, N_INV, 0x0000c10, N_INV), \
11873 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
11874 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11875 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11876 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11877 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11878 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11879 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11880 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11881 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11882 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11883 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11884 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11885 X(vshl, 0x0000400, N_INV, 0x0800510), \
11886 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11887 X(vand, 0x0000110, N_INV, 0x0800030), \
11888 X(vbic, 0x0100110, N_INV, 0x0800030), \
11889 X(veor, 0x1000110, N_INV, N_INV), \
11890 X(vorn, 0x0300110, N_INV, 0x0800010), \
11891 X(vorr, 0x0200110, N_INV, 0x0800010), \
11892 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11893 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11894 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11895 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11896 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11897 X(vst1, 0x0000000, 0x0800000, N_INV), \
11898 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11899 X(vst2, 0x0000100, 0x0800100, N_INV), \
11900 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11901 X(vst3, 0x0000200, 0x0800200, N_INV), \
11902 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11903 X(vst4, 0x0000300, 0x0800300, N_INV), \
11904 X(vmovn, 0x1b20200, N_INV, N_INV), \
11905 X(vtrn, 0x1b20080, N_INV, N_INV), \
11906 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
11907 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11908 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
11909 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11910 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
11911 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11912 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
11913 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11914 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11915 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11916 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
11917
11918enum neon_opc
11919{
11920#define X(OPC,I,F,S) N_MNEM_##OPC
11921NEON_ENC_TAB
11922#undef X
11923};
b99bd4ef 11924
5287ad62
JB
11925static const struct neon_tab_entry neon_enc_tab[] =
11926{
11927#define X(OPC,I,F,S) { (I), (F), (S) }
11928NEON_ENC_TAB
11929#undef X
11930};
b99bd4ef 11931
88714cb8
DG
11932/* Do not use these macros; instead, use NEON_ENCODE defined below. */
11933#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11934#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11935#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11936#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11937#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11938#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11939#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11940#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11941#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11942#define NEON_ENC_SINGLE_(X) \
037e8744 11943 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 11944#define NEON_ENC_DOUBLE_(X) \
037e8744 11945 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 11946
88714cb8
DG
11947#define NEON_ENCODE(type, inst) \
11948 do \
11949 { \
11950 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
11951 inst.is_neon = 1; \
11952 } \
11953 while (0)
11954
11955#define check_neon_suffixes \
11956 do \
11957 { \
11958 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
11959 { \
11960 as_bad (_("invalid neon suffix for non neon instruction")); \
11961 return; \
11962 } \
11963 } \
11964 while (0)
11965
037e8744
JB
11966/* Define shapes for instruction operands. The following mnemonic characters
11967 are used in this table:
5287ad62 11968
037e8744 11969 F - VFP S<n> register
5287ad62
JB
11970 D - Neon D<n> register
11971 Q - Neon Q<n> register
11972 I - Immediate
11973 S - Scalar
11974 R - ARM register
11975 L - D<n> register list
5f4273c7 11976
037e8744
JB
11977 This table is used to generate various data:
11978 - enumerations of the form NS_DDR to be used as arguments to
11979 neon_select_shape.
11980 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 11981 - a table used to drive neon_select_shape. */
b99bd4ef 11982
037e8744
JB
11983#define NEON_SHAPE_DEF \
11984 X(3, (D, D, D), DOUBLE), \
11985 X(3, (Q, Q, Q), QUAD), \
11986 X(3, (D, D, I), DOUBLE), \
11987 X(3, (Q, Q, I), QUAD), \
11988 X(3, (D, D, S), DOUBLE), \
11989 X(3, (Q, Q, S), QUAD), \
11990 X(2, (D, D), DOUBLE), \
11991 X(2, (Q, Q), QUAD), \
11992 X(2, (D, S), DOUBLE), \
11993 X(2, (Q, S), QUAD), \
11994 X(2, (D, R), DOUBLE), \
11995 X(2, (Q, R), QUAD), \
11996 X(2, (D, I), DOUBLE), \
11997 X(2, (Q, I), QUAD), \
11998 X(3, (D, L, D), DOUBLE), \
11999 X(2, (D, Q), MIXED), \
12000 X(2, (Q, D), MIXED), \
12001 X(3, (D, Q, I), MIXED), \
12002 X(3, (Q, D, I), MIXED), \
12003 X(3, (Q, D, D), MIXED), \
12004 X(3, (D, Q, Q), MIXED), \
12005 X(3, (Q, Q, D), MIXED), \
12006 X(3, (Q, D, S), MIXED), \
12007 X(3, (D, Q, S), MIXED), \
12008 X(4, (D, D, D, I), DOUBLE), \
12009 X(4, (Q, Q, Q, I), QUAD), \
12010 X(2, (F, F), SINGLE), \
12011 X(3, (F, F, F), SINGLE), \
12012 X(2, (F, I), SINGLE), \
12013 X(2, (F, D), MIXED), \
12014 X(2, (D, F), MIXED), \
12015 X(3, (F, F, I), MIXED), \
12016 X(4, (R, R, F, F), SINGLE), \
12017 X(4, (F, F, R, R), SINGLE), \
12018 X(3, (D, R, R), DOUBLE), \
12019 X(3, (R, R, D), DOUBLE), \
12020 X(2, (S, R), SINGLE), \
12021 X(2, (R, S), SINGLE), \
12022 X(2, (F, R), SINGLE), \
12023 X(2, (R, F), SINGLE)
12024
12025#define S2(A,B) NS_##A##B
12026#define S3(A,B,C) NS_##A##B##C
12027#define S4(A,B,C,D) NS_##A##B##C##D
12028
12029#define X(N, L, C) S##N L
12030
5287ad62
JB
12031enum neon_shape
12032{
037e8744
JB
12033 NEON_SHAPE_DEF,
12034 NS_NULL
5287ad62 12035};
b99bd4ef 12036
037e8744
JB
12037#undef X
12038#undef S2
12039#undef S3
12040#undef S4
12041
12042enum neon_shape_class
12043{
12044 SC_SINGLE,
12045 SC_DOUBLE,
12046 SC_QUAD,
12047 SC_MIXED
12048};
12049
12050#define X(N, L, C) SC_##C
12051
12052static enum neon_shape_class neon_shape_class[] =
12053{
12054 NEON_SHAPE_DEF
12055};
12056
12057#undef X
12058
12059enum neon_shape_el
12060{
12061 SE_F,
12062 SE_D,
12063 SE_Q,
12064 SE_I,
12065 SE_S,
12066 SE_R,
12067 SE_L
12068};
12069
12070/* Register widths of above. */
12071static unsigned neon_shape_el_size[] =
12072{
12073 32,
12074 64,
12075 128,
12076 0,
12077 32,
12078 32,
12079 0
12080};
12081
12082struct neon_shape_info
12083{
12084 unsigned els;
12085 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
12086};
12087
12088#define S2(A,B) { SE_##A, SE_##B }
12089#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
12090#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
12091
12092#define X(N, L, C) { N, S##N L }
12093
12094static struct neon_shape_info neon_shape_tab[] =
12095{
12096 NEON_SHAPE_DEF
12097};
12098
12099#undef X
12100#undef S2
12101#undef S3
12102#undef S4
12103
5287ad62
JB
12104/* Bit masks used in type checking given instructions.
12105 'N_EQK' means the type must be the same as (or based on in some way) the key
12106 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
12107 set, various other bits can be set as well in order to modify the meaning of
12108 the type constraint. */
12109
12110enum neon_type_mask
12111{
8e79c3df
CM
12112 N_S8 = 0x0000001,
12113 N_S16 = 0x0000002,
12114 N_S32 = 0x0000004,
12115 N_S64 = 0x0000008,
12116 N_U8 = 0x0000010,
12117 N_U16 = 0x0000020,
12118 N_U32 = 0x0000040,
12119 N_U64 = 0x0000080,
12120 N_I8 = 0x0000100,
12121 N_I16 = 0x0000200,
12122 N_I32 = 0x0000400,
12123 N_I64 = 0x0000800,
12124 N_8 = 0x0001000,
12125 N_16 = 0x0002000,
12126 N_32 = 0x0004000,
12127 N_64 = 0x0008000,
12128 N_P8 = 0x0010000,
12129 N_P16 = 0x0020000,
12130 N_F16 = 0x0040000,
12131 N_F32 = 0x0080000,
12132 N_F64 = 0x0100000,
c921be7d
NC
12133 N_KEY = 0x1000000, /* Key element (main type specifier). */
12134 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 12135 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
c921be7d
NC
12136 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
12137 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
12138 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
12139 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
12140 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
12141 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
12142 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 12143 N_UTYP = 0,
037e8744 12144 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
12145};
12146
dcbf9037
JB
12147#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
12148
5287ad62
JB
12149#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
12150#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
12151#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
12152#define N_SUF_32 (N_SU_32 | N_F32)
12153#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
12154#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
12155
12156/* Pass this as the first type argument to neon_check_type to ignore types
12157 altogether. */
12158#define N_IGNORE_TYPE (N_KEY | N_EQK)
12159
037e8744
JB
12160/* Select a "shape" for the current instruction (describing register types or
12161 sizes) from a list of alternatives. Return NS_NULL if the current instruction
12162 doesn't fit. For non-polymorphic shapes, checking is usually done as a
12163 function of operand parsing, so this function doesn't need to be called.
12164 Shapes should be listed in order of decreasing length. */
5287ad62
JB
12165
12166static enum neon_shape
037e8744 12167neon_select_shape (enum neon_shape shape, ...)
5287ad62 12168{
037e8744
JB
12169 va_list ap;
12170 enum neon_shape first_shape = shape;
5287ad62
JB
12171
12172 /* Fix missing optional operands. FIXME: we don't know at this point how
12173 many arguments we should have, so this makes the assumption that we have
12174 > 1. This is true of all current Neon opcodes, I think, but may not be
12175 true in the future. */
12176 if (!inst.operands[1].present)
12177 inst.operands[1] = inst.operands[0];
12178
037e8744 12179 va_start (ap, shape);
5f4273c7 12180
21d799b5 12181 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
12182 {
12183 unsigned j;
12184 int matches = 1;
12185
12186 for (j = 0; j < neon_shape_tab[shape].els; j++)
12187 {
12188 if (!inst.operands[j].present)
12189 {
12190 matches = 0;
12191 break;
12192 }
12193
12194 switch (neon_shape_tab[shape].el[j])
12195 {
12196 case SE_F:
12197 if (!(inst.operands[j].isreg
12198 && inst.operands[j].isvec
12199 && inst.operands[j].issingle
12200 && !inst.operands[j].isquad))
12201 matches = 0;
12202 break;
12203
12204 case SE_D:
12205 if (!(inst.operands[j].isreg
12206 && inst.operands[j].isvec
12207 && !inst.operands[j].isquad
12208 && !inst.operands[j].issingle))
12209 matches = 0;
12210 break;
12211
12212 case SE_R:
12213 if (!(inst.operands[j].isreg
12214 && !inst.operands[j].isvec))
12215 matches = 0;
12216 break;
12217
12218 case SE_Q:
12219 if (!(inst.operands[j].isreg
12220 && inst.operands[j].isvec
12221 && inst.operands[j].isquad
12222 && !inst.operands[j].issingle))
12223 matches = 0;
12224 break;
12225
12226 case SE_I:
12227 if (!(!inst.operands[j].isreg
12228 && !inst.operands[j].isscalar))
12229 matches = 0;
12230 break;
12231
12232 case SE_S:
12233 if (!(!inst.operands[j].isreg
12234 && inst.operands[j].isscalar))
12235 matches = 0;
12236 break;
12237
12238 case SE_L:
12239 break;
12240 }
3fde54a2
JZ
12241 if (!matches)
12242 break;
037e8744
JB
12243 }
12244 if (matches)
5287ad62 12245 break;
037e8744 12246 }
5f4273c7 12247
037e8744 12248 va_end (ap);
5287ad62 12249
037e8744
JB
12250 if (shape == NS_NULL && first_shape != NS_NULL)
12251 first_error (_("invalid instruction shape"));
5287ad62 12252
037e8744
JB
12253 return shape;
12254}
5287ad62 12255
037e8744
JB
12256/* True if SHAPE is predominantly a quadword operation (most of the time, this
12257 means the Q bit should be set). */
12258
12259static int
12260neon_quad (enum neon_shape shape)
12261{
12262 return neon_shape_class[shape] == SC_QUAD;
5287ad62 12263}
037e8744 12264
5287ad62
JB
12265static void
12266neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
12267 unsigned *g_size)
12268{
12269 /* Allow modification to be made to types which are constrained to be
12270 based on the key element, based on bits set alongside N_EQK. */
12271 if ((typebits & N_EQK) != 0)
12272 {
12273 if ((typebits & N_HLF) != 0)
12274 *g_size /= 2;
12275 else if ((typebits & N_DBL) != 0)
12276 *g_size *= 2;
12277 if ((typebits & N_SGN) != 0)
12278 *g_type = NT_signed;
12279 else if ((typebits & N_UNS) != 0)
12280 *g_type = NT_unsigned;
12281 else if ((typebits & N_INT) != 0)
12282 *g_type = NT_integer;
12283 else if ((typebits & N_FLT) != 0)
12284 *g_type = NT_float;
dcbf9037
JB
12285 else if ((typebits & N_SIZ) != 0)
12286 *g_type = NT_untyped;
5287ad62
JB
12287 }
12288}
5f4273c7 12289
5287ad62
JB
12290/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12291 operand type, i.e. the single type specified in a Neon instruction when it
12292 is the only one given. */
12293
12294static struct neon_type_el
12295neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12296{
12297 struct neon_type_el dest = *key;
5f4273c7 12298
9c2799c2 12299 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 12300
5287ad62
JB
12301 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12302
12303 return dest;
12304}
12305
12306/* Convert Neon type and size into compact bitmask representation. */
12307
12308static enum neon_type_mask
12309type_chk_of_el_type (enum neon_el_type type, unsigned size)
12310{
12311 switch (type)
12312 {
12313 case NT_untyped:
12314 switch (size)
12315 {
12316 case 8: return N_8;
12317 case 16: return N_16;
12318 case 32: return N_32;
12319 case 64: return N_64;
12320 default: ;
12321 }
12322 break;
12323
12324 case NT_integer:
12325 switch (size)
12326 {
12327 case 8: return N_I8;
12328 case 16: return N_I16;
12329 case 32: return N_I32;
12330 case 64: return N_I64;
12331 default: ;
12332 }
12333 break;
12334
12335 case NT_float:
037e8744
JB
12336 switch (size)
12337 {
8e79c3df 12338 case 16: return N_F16;
037e8744
JB
12339 case 32: return N_F32;
12340 case 64: return N_F64;
12341 default: ;
12342 }
5287ad62
JB
12343 break;
12344
12345 case NT_poly:
12346 switch (size)
12347 {
12348 case 8: return N_P8;
12349 case 16: return N_P16;
12350 default: ;
12351 }
12352 break;
12353
12354 case NT_signed:
12355 switch (size)
12356 {
12357 case 8: return N_S8;
12358 case 16: return N_S16;
12359 case 32: return N_S32;
12360 case 64: return N_S64;
12361 default: ;
12362 }
12363 break;
12364
12365 case NT_unsigned:
12366 switch (size)
12367 {
12368 case 8: return N_U8;
12369 case 16: return N_U16;
12370 case 32: return N_U32;
12371 case 64: return N_U64;
12372 default: ;
12373 }
12374 break;
12375
12376 default: ;
12377 }
5f4273c7 12378
5287ad62
JB
12379 return N_UTYP;
12380}
12381
12382/* Convert compact Neon bitmask type representation to a type and size. Only
12383 handles the case where a single bit is set in the mask. */
12384
dcbf9037 12385static int
5287ad62
JB
12386el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12387 enum neon_type_mask mask)
12388{
dcbf9037
JB
12389 if ((mask & N_EQK) != 0)
12390 return FAIL;
12391
5287ad62
JB
12392 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12393 *size = 8;
dcbf9037 12394 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 12395 *size = 16;
dcbf9037 12396 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 12397 *size = 32;
037e8744 12398 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 12399 *size = 64;
dcbf9037
JB
12400 else
12401 return FAIL;
12402
5287ad62
JB
12403 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12404 *type = NT_signed;
dcbf9037 12405 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 12406 *type = NT_unsigned;
dcbf9037 12407 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 12408 *type = NT_integer;
dcbf9037 12409 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 12410 *type = NT_untyped;
dcbf9037 12411 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 12412 *type = NT_poly;
037e8744 12413 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 12414 *type = NT_float;
dcbf9037
JB
12415 else
12416 return FAIL;
5f4273c7 12417
dcbf9037 12418 return SUCCESS;
5287ad62
JB
12419}
12420
12421/* Modify a bitmask of allowed types. This is only needed for type
12422 relaxation. */
12423
12424static unsigned
12425modify_types_allowed (unsigned allowed, unsigned mods)
12426{
12427 unsigned size;
12428 enum neon_el_type type;
12429 unsigned destmask;
12430 int i;
5f4273c7 12431
5287ad62 12432 destmask = 0;
5f4273c7 12433
5287ad62
JB
12434 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12435 {
21d799b5
NC
12436 if (el_type_of_type_chk (&type, &size,
12437 (enum neon_type_mask) (allowed & i)) == SUCCESS)
dcbf9037
JB
12438 {
12439 neon_modify_type_size (mods, &type, &size);
12440 destmask |= type_chk_of_el_type (type, size);
12441 }
5287ad62 12442 }
5f4273c7 12443
5287ad62
JB
12444 return destmask;
12445}
12446
12447/* Check type and return type classification.
12448 The manual states (paraphrase): If one datatype is given, it indicates the
12449 type given in:
12450 - the second operand, if there is one
12451 - the operand, if there is no second operand
12452 - the result, if there are no operands.
12453 This isn't quite good enough though, so we use a concept of a "key" datatype
12454 which is set on a per-instruction basis, which is the one which matters when
12455 only one data type is written.
12456 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 12457 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
12458
12459static struct neon_type_el
12460neon_check_type (unsigned els, enum neon_shape ns, ...)
12461{
12462 va_list ap;
12463 unsigned i, pass, key_el = 0;
12464 unsigned types[NEON_MAX_TYPE_ELS];
12465 enum neon_el_type k_type = NT_invtype;
12466 unsigned k_size = -1u;
12467 struct neon_type_el badtype = {NT_invtype, -1};
12468 unsigned key_allowed = 0;
12469
12470 /* Optional registers in Neon instructions are always (not) in operand 1.
12471 Fill in the missing operand here, if it was omitted. */
12472 if (els > 1 && !inst.operands[1].present)
12473 inst.operands[1] = inst.operands[0];
12474
12475 /* Suck up all the varargs. */
12476 va_start (ap, ns);
12477 for (i = 0; i < els; i++)
12478 {
12479 unsigned thisarg = va_arg (ap, unsigned);
12480 if (thisarg == N_IGNORE_TYPE)
12481 {
12482 va_end (ap);
12483 return badtype;
12484 }
12485 types[i] = thisarg;
12486 if ((thisarg & N_KEY) != 0)
12487 key_el = i;
12488 }
12489 va_end (ap);
12490
dcbf9037
JB
12491 if (inst.vectype.elems > 0)
12492 for (i = 0; i < els; i++)
12493 if (inst.operands[i].vectype.type != NT_invtype)
12494 {
12495 first_error (_("types specified in both the mnemonic and operands"));
12496 return badtype;
12497 }
12498
5287ad62
JB
12499 /* Duplicate inst.vectype elements here as necessary.
12500 FIXME: No idea if this is exactly the same as the ARM assembler,
12501 particularly when an insn takes one register and one non-register
12502 operand. */
12503 if (inst.vectype.elems == 1 && els > 1)
12504 {
12505 unsigned j;
12506 inst.vectype.elems = els;
12507 inst.vectype.el[key_el] = inst.vectype.el[0];
12508 for (j = 0; j < els; j++)
dcbf9037
JB
12509 if (j != key_el)
12510 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12511 types[j]);
12512 }
12513 else if (inst.vectype.elems == 0 && els > 0)
12514 {
12515 unsigned j;
12516 /* No types were given after the mnemonic, so look for types specified
12517 after each operand. We allow some flexibility here; as long as the
12518 "key" operand has a type, we can infer the others. */
12519 for (j = 0; j < els; j++)
12520 if (inst.operands[j].vectype.type != NT_invtype)
12521 inst.vectype.el[j] = inst.operands[j].vectype;
12522
12523 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 12524 {
dcbf9037
JB
12525 for (j = 0; j < els; j++)
12526 if (inst.operands[j].vectype.type == NT_invtype)
12527 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12528 types[j]);
12529 }
12530 else
12531 {
12532 first_error (_("operand types can't be inferred"));
12533 return badtype;
5287ad62
JB
12534 }
12535 }
12536 else if (inst.vectype.elems != els)
12537 {
dcbf9037 12538 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
12539 return badtype;
12540 }
12541
12542 for (pass = 0; pass < 2; pass++)
12543 {
12544 for (i = 0; i < els; i++)
12545 {
12546 unsigned thisarg = types[i];
12547 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12548 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12549 enum neon_el_type g_type = inst.vectype.el[i].type;
12550 unsigned g_size = inst.vectype.el[i].size;
12551
12552 /* Decay more-specific signed & unsigned types to sign-insensitive
12553 integer types if sign-specific variants are unavailable. */
12554 if ((g_type == NT_signed || g_type == NT_unsigned)
12555 && (types_allowed & N_SU_ALL) == 0)
12556 g_type = NT_integer;
12557
12558 /* If only untyped args are allowed, decay any more specific types to
12559 them. Some instructions only care about signs for some element
12560 sizes, so handle that properly. */
12561 if ((g_size == 8 && (types_allowed & N_8) != 0)
12562 || (g_size == 16 && (types_allowed & N_16) != 0)
12563 || (g_size == 32 && (types_allowed & N_32) != 0)
12564 || (g_size == 64 && (types_allowed & N_64) != 0))
12565 g_type = NT_untyped;
12566
12567 if (pass == 0)
12568 {
12569 if ((thisarg & N_KEY) != 0)
12570 {
12571 k_type = g_type;
12572 k_size = g_size;
12573 key_allowed = thisarg & ~N_KEY;
12574 }
12575 }
12576 else
12577 {
037e8744
JB
12578 if ((thisarg & N_VFP) != 0)
12579 {
99b253c5
NC
12580 enum neon_shape_el regshape;
12581 unsigned regwidth, match;
12582
12583 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12584 if (ns == NS_NULL)
12585 {
12586 first_error (_("invalid instruction shape"));
12587 return badtype;
12588 }
12589 regshape = neon_shape_tab[ns].el[i];
12590 regwidth = neon_shape_el_size[regshape];
037e8744
JB
12591
12592 /* In VFP mode, operands must match register widths. If we
12593 have a key operand, use its width, else use the width of
12594 the current operand. */
12595 if (k_size != -1u)
12596 match = k_size;
12597 else
12598 match = g_size;
12599
12600 if (regwidth != match)
12601 {
12602 first_error (_("operand size must match register width"));
12603 return badtype;
12604 }
12605 }
5f4273c7 12606
5287ad62
JB
12607 if ((thisarg & N_EQK) == 0)
12608 {
12609 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12610
12611 if ((given_type & types_allowed) == 0)
12612 {
dcbf9037 12613 first_error (_("bad type in Neon instruction"));
5287ad62
JB
12614 return badtype;
12615 }
12616 }
12617 else
12618 {
12619 enum neon_el_type mod_k_type = k_type;
12620 unsigned mod_k_size = k_size;
12621 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12622 if (g_type != mod_k_type || g_size != mod_k_size)
12623 {
dcbf9037 12624 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
12625 return badtype;
12626 }
12627 }
12628 }
12629 }
12630 }
12631
12632 return inst.vectype.el[key_el];
12633}
12634
037e8744 12635/* Neon-style VFP instruction forwarding. */
5287ad62 12636
037e8744
JB
12637/* Thumb VFP instructions have 0xE in the condition field. */
12638
12639static void
12640do_vfp_cond_or_thumb (void)
5287ad62 12641{
88714cb8
DG
12642 inst.is_neon = 1;
12643
5287ad62 12644 if (thumb_mode)
037e8744 12645 inst.instruction |= 0xe0000000;
5287ad62 12646 else
037e8744 12647 inst.instruction |= inst.cond << 28;
5287ad62
JB
12648}
12649
037e8744
JB
12650/* Look up and encode a simple mnemonic, for use as a helper function for the
12651 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12652 etc. It is assumed that operand parsing has already been done, and that the
12653 operands are in the form expected by the given opcode (this isn't necessarily
12654 the same as the form in which they were parsed, hence some massaging must
12655 take place before this function is called).
12656 Checks current arch version against that in the looked-up opcode. */
5287ad62 12657
037e8744
JB
12658static void
12659do_vfp_nsyn_opcode (const char *opname)
5287ad62 12660{
037e8744 12661 const struct asm_opcode *opcode;
5f4273c7 12662
21d799b5 12663 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 12664
037e8744
JB
12665 if (!opcode)
12666 abort ();
5287ad62 12667
037e8744
JB
12668 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12669 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12670 _(BAD_FPU));
5287ad62 12671
88714cb8
DG
12672 inst.is_neon = 1;
12673
037e8744
JB
12674 if (thumb_mode)
12675 {
12676 inst.instruction = opcode->tvalue;
12677 opcode->tencode ();
12678 }
12679 else
12680 {
12681 inst.instruction = (inst.cond << 28) | opcode->avalue;
12682 opcode->aencode ();
12683 }
12684}
5287ad62
JB
12685
12686static void
037e8744 12687do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 12688{
037e8744
JB
12689 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12690
12691 if (rs == NS_FFF)
12692 {
12693 if (is_add)
12694 do_vfp_nsyn_opcode ("fadds");
12695 else
12696 do_vfp_nsyn_opcode ("fsubs");
12697 }
12698 else
12699 {
12700 if (is_add)
12701 do_vfp_nsyn_opcode ("faddd");
12702 else
12703 do_vfp_nsyn_opcode ("fsubd");
12704 }
12705}
12706
12707/* Check operand types to see if this is a VFP instruction, and if so call
12708 PFN (). */
12709
12710static int
12711try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12712{
12713 enum neon_shape rs;
12714 struct neon_type_el et;
12715
12716 switch (args)
12717 {
12718 case 2:
12719 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12720 et = neon_check_type (2, rs,
12721 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12722 break;
5f4273c7 12723
037e8744
JB
12724 case 3:
12725 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12726 et = neon_check_type (3, rs,
12727 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12728 break;
12729
12730 default:
12731 abort ();
12732 }
12733
12734 if (et.type != NT_invtype)
12735 {
12736 pfn (rs);
12737 return SUCCESS;
12738 }
037e8744 12739
99b253c5 12740 inst.error = NULL;
037e8744
JB
12741 return FAIL;
12742}
12743
12744static void
12745do_vfp_nsyn_mla_mls (enum neon_shape rs)
12746{
12747 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 12748
037e8744
JB
12749 if (rs == NS_FFF)
12750 {
12751 if (is_mla)
12752 do_vfp_nsyn_opcode ("fmacs");
12753 else
1ee69515 12754 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
12755 }
12756 else
12757 {
12758 if (is_mla)
12759 do_vfp_nsyn_opcode ("fmacd");
12760 else
1ee69515 12761 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
12762 }
12763}
12764
62f3b8c8
PB
12765static void
12766do_vfp_nsyn_fma_fms (enum neon_shape rs)
12767{
12768 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12769
12770 if (rs == NS_FFF)
12771 {
12772 if (is_fma)
12773 do_vfp_nsyn_opcode ("ffmas");
12774 else
12775 do_vfp_nsyn_opcode ("ffnmas");
12776 }
12777 else
12778 {
12779 if (is_fma)
12780 do_vfp_nsyn_opcode ("ffmad");
12781 else
12782 do_vfp_nsyn_opcode ("ffnmad");
12783 }
12784}
12785
037e8744
JB
12786static void
12787do_vfp_nsyn_mul (enum neon_shape rs)
12788{
12789 if (rs == NS_FFF)
12790 do_vfp_nsyn_opcode ("fmuls");
12791 else
12792 do_vfp_nsyn_opcode ("fmuld");
12793}
12794
12795static void
12796do_vfp_nsyn_abs_neg (enum neon_shape rs)
12797{
12798 int is_neg = (inst.instruction & 0x80) != 0;
12799 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12800
12801 if (rs == NS_FF)
12802 {
12803 if (is_neg)
12804 do_vfp_nsyn_opcode ("fnegs");
12805 else
12806 do_vfp_nsyn_opcode ("fabss");
12807 }
12808 else
12809 {
12810 if (is_neg)
12811 do_vfp_nsyn_opcode ("fnegd");
12812 else
12813 do_vfp_nsyn_opcode ("fabsd");
12814 }
12815}
12816
12817/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12818 insns belong to Neon, and are handled elsewhere. */
12819
12820static void
12821do_vfp_nsyn_ldm_stm (int is_dbmode)
12822{
12823 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12824 if (is_ldm)
12825 {
12826 if (is_dbmode)
12827 do_vfp_nsyn_opcode ("fldmdbs");
12828 else
12829 do_vfp_nsyn_opcode ("fldmias");
12830 }
12831 else
12832 {
12833 if (is_dbmode)
12834 do_vfp_nsyn_opcode ("fstmdbs");
12835 else
12836 do_vfp_nsyn_opcode ("fstmias");
12837 }
12838}
12839
037e8744
JB
12840static void
12841do_vfp_nsyn_sqrt (void)
12842{
12843 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12844 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12845
037e8744
JB
12846 if (rs == NS_FF)
12847 do_vfp_nsyn_opcode ("fsqrts");
12848 else
12849 do_vfp_nsyn_opcode ("fsqrtd");
12850}
12851
12852static void
12853do_vfp_nsyn_div (void)
12854{
12855 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12856 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12857 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12858
037e8744
JB
12859 if (rs == NS_FFF)
12860 do_vfp_nsyn_opcode ("fdivs");
12861 else
12862 do_vfp_nsyn_opcode ("fdivd");
12863}
12864
12865static void
12866do_vfp_nsyn_nmul (void)
12867{
12868 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12869 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12870 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12871
037e8744
JB
12872 if (rs == NS_FFF)
12873 {
88714cb8 12874 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12875 do_vfp_sp_dyadic ();
12876 }
12877 else
12878 {
88714cb8 12879 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12880 do_vfp_dp_rd_rn_rm ();
12881 }
12882 do_vfp_cond_or_thumb ();
12883}
12884
12885static void
12886do_vfp_nsyn_cmp (void)
12887{
12888 if (inst.operands[1].isreg)
12889 {
12890 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12891 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12892
037e8744
JB
12893 if (rs == NS_FF)
12894 {
88714cb8 12895 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12896 do_vfp_sp_monadic ();
12897 }
12898 else
12899 {
88714cb8 12900 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12901 do_vfp_dp_rd_rm ();
12902 }
12903 }
12904 else
12905 {
12906 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12907 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12908
12909 switch (inst.instruction & 0x0fffffff)
12910 {
12911 case N_MNEM_vcmp:
12912 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12913 break;
12914 case N_MNEM_vcmpe:
12915 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12916 break;
12917 default:
12918 abort ();
12919 }
5f4273c7 12920
037e8744
JB
12921 if (rs == NS_FI)
12922 {
88714cb8 12923 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12924 do_vfp_sp_compare_z ();
12925 }
12926 else
12927 {
88714cb8 12928 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12929 do_vfp_dp_rd ();
12930 }
12931 }
12932 do_vfp_cond_or_thumb ();
12933}
12934
12935static void
12936nsyn_insert_sp (void)
12937{
12938 inst.operands[1] = inst.operands[0];
12939 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 12940 inst.operands[0].reg = REG_SP;
037e8744
JB
12941 inst.operands[0].isreg = 1;
12942 inst.operands[0].writeback = 1;
12943 inst.operands[0].present = 1;
12944}
12945
12946static void
12947do_vfp_nsyn_push (void)
12948{
12949 nsyn_insert_sp ();
12950 if (inst.operands[1].issingle)
12951 do_vfp_nsyn_opcode ("fstmdbs");
12952 else
12953 do_vfp_nsyn_opcode ("fstmdbd");
12954}
12955
12956static void
12957do_vfp_nsyn_pop (void)
12958{
12959 nsyn_insert_sp ();
12960 if (inst.operands[1].issingle)
22b5b651 12961 do_vfp_nsyn_opcode ("fldmias");
037e8744 12962 else
22b5b651 12963 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
12964}
12965
12966/* Fix up Neon data-processing instructions, ORing in the correct bits for
12967 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12968
88714cb8
DG
12969static void
12970neon_dp_fixup (struct arm_it* insn)
037e8744 12971{
88714cb8
DG
12972 unsigned int i = insn->instruction;
12973 insn->is_neon = 1;
12974
037e8744
JB
12975 if (thumb_mode)
12976 {
12977 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12978 if (i & (1 << 24))
12979 i |= 1 << 28;
5f4273c7 12980
037e8744 12981 i &= ~(1 << 24);
5f4273c7 12982
037e8744
JB
12983 i |= 0xef000000;
12984 }
12985 else
12986 i |= 0xf2000000;
5f4273c7 12987
88714cb8 12988 insn->instruction = i;
037e8744
JB
12989}
12990
12991/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12992 (0, 1, 2, 3). */
12993
12994static unsigned
12995neon_logbits (unsigned x)
12996{
12997 return ffs (x) - 4;
12998}
12999
13000#define LOW4(R) ((R) & 0xf)
13001#define HI1(R) (((R) >> 4) & 1)
13002
13003/* Encode insns with bit pattern:
13004
13005 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13006 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 13007
037e8744
JB
13008 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
13009 different meaning for some instruction. */
13010
13011static void
13012neon_three_same (int isquad, int ubit, int size)
13013{
13014 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13015 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13016 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13017 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13018 inst.instruction |= LOW4 (inst.operands[2].reg);
13019 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13020 inst.instruction |= (isquad != 0) << 6;
13021 inst.instruction |= (ubit != 0) << 24;
13022 if (size != -1)
13023 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 13024
88714cb8 13025 neon_dp_fixup (&inst);
037e8744
JB
13026}
13027
13028/* Encode instructions of the form:
13029
13030 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
13031 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
13032
13033 Don't write size if SIZE == -1. */
13034
13035static void
13036neon_two_same (int qbit, int ubit, int size)
13037{
13038 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13039 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13040 inst.instruction |= LOW4 (inst.operands[1].reg);
13041 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13042 inst.instruction |= (qbit != 0) << 6;
13043 inst.instruction |= (ubit != 0) << 24;
13044
13045 if (size != -1)
13046 inst.instruction |= neon_logbits (size) << 18;
13047
88714cb8 13048 neon_dp_fixup (&inst);
5287ad62
JB
13049}
13050
13051/* Neon instruction encoders, in approximate order of appearance. */
13052
13053static void
13054do_neon_dyadic_i_su (void)
13055{
037e8744 13056 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13057 struct neon_type_el et = neon_check_type (3, rs,
13058 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 13059 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13060}
13061
13062static void
13063do_neon_dyadic_i64_su (void)
13064{
037e8744 13065 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13066 struct neon_type_el et = neon_check_type (3, rs,
13067 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 13068 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13069}
13070
13071static void
13072neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
13073 unsigned immbits)
13074{
13075 unsigned size = et.size >> 3;
13076 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13077 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13078 inst.instruction |= LOW4 (inst.operands[1].reg);
13079 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13080 inst.instruction |= (isquad != 0) << 6;
13081 inst.instruction |= immbits << 16;
13082 inst.instruction |= (size >> 3) << 7;
13083 inst.instruction |= (size & 0x7) << 19;
13084 if (write_ubit)
13085 inst.instruction |= (uval != 0) << 24;
13086
88714cb8 13087 neon_dp_fixup (&inst);
5287ad62
JB
13088}
13089
13090static void
13091do_neon_shl_imm (void)
13092{
13093 if (!inst.operands[2].isreg)
13094 {
037e8744 13095 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 13096 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
88714cb8 13097 NEON_ENCODE (IMMED, inst);
037e8744 13098 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
13099 }
13100 else
13101 {
037e8744 13102 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13103 struct neon_type_el et = neon_check_type (3, rs,
13104 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13105 unsigned int tmp;
13106
13107 /* VSHL/VQSHL 3-register variants have syntax such as:
13108 vshl.xx Dd, Dm, Dn
13109 whereas other 3-register operations encoded by neon_three_same have
13110 syntax like:
13111 vadd.xx Dd, Dn, Dm
13112 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
13113 here. */
13114 tmp = inst.operands[2].reg;
13115 inst.operands[2].reg = inst.operands[1].reg;
13116 inst.operands[1].reg = tmp;
88714cb8 13117 NEON_ENCODE (INTEGER, inst);
037e8744 13118 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13119 }
13120}
13121
13122static void
13123do_neon_qshl_imm (void)
13124{
13125 if (!inst.operands[2].isreg)
13126 {
037e8744 13127 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 13128 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 13129
88714cb8 13130 NEON_ENCODE (IMMED, inst);
037e8744 13131 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13132 inst.operands[2].imm);
13133 }
13134 else
13135 {
037e8744 13136 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13137 struct neon_type_el et = neon_check_type (3, rs,
13138 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13139 unsigned int tmp;
13140
13141 /* See note in do_neon_shl_imm. */
13142 tmp = inst.operands[2].reg;
13143 inst.operands[2].reg = inst.operands[1].reg;
13144 inst.operands[1].reg = tmp;
88714cb8 13145 NEON_ENCODE (INTEGER, inst);
037e8744 13146 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13147 }
13148}
13149
627907b7
JB
13150static void
13151do_neon_rshl (void)
13152{
13153 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13154 struct neon_type_el et = neon_check_type (3, rs,
13155 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13156 unsigned int tmp;
13157
13158 tmp = inst.operands[2].reg;
13159 inst.operands[2].reg = inst.operands[1].reg;
13160 inst.operands[1].reg = tmp;
13161 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13162}
13163
5287ad62
JB
13164static int
13165neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
13166{
036dc3f7
PB
13167 /* Handle .I8 pseudo-instructions. */
13168 if (size == 8)
5287ad62 13169 {
5287ad62
JB
13170 /* Unfortunately, this will make everything apart from zero out-of-range.
13171 FIXME is this the intended semantics? There doesn't seem much point in
13172 accepting .I8 if so. */
13173 immediate |= immediate << 8;
13174 size = 16;
036dc3f7
PB
13175 }
13176
13177 if (size >= 32)
13178 {
13179 if (immediate == (immediate & 0x000000ff))
13180 {
13181 *immbits = immediate;
13182 return 0x1;
13183 }
13184 else if (immediate == (immediate & 0x0000ff00))
13185 {
13186 *immbits = immediate >> 8;
13187 return 0x3;
13188 }
13189 else if (immediate == (immediate & 0x00ff0000))
13190 {
13191 *immbits = immediate >> 16;
13192 return 0x5;
13193 }
13194 else if (immediate == (immediate & 0xff000000))
13195 {
13196 *immbits = immediate >> 24;
13197 return 0x7;
13198 }
13199 if ((immediate & 0xffff) != (immediate >> 16))
13200 goto bad_immediate;
13201 immediate &= 0xffff;
5287ad62
JB
13202 }
13203
13204 if (immediate == (immediate & 0x000000ff))
13205 {
13206 *immbits = immediate;
036dc3f7 13207 return 0x9;
5287ad62
JB
13208 }
13209 else if (immediate == (immediate & 0x0000ff00))
13210 {
13211 *immbits = immediate >> 8;
036dc3f7 13212 return 0xb;
5287ad62
JB
13213 }
13214
13215 bad_immediate:
dcbf9037 13216 first_error (_("immediate value out of range"));
5287ad62
JB
13217 return FAIL;
13218}
13219
13220/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
13221 A, B, C, D. */
13222
13223static int
13224neon_bits_same_in_bytes (unsigned imm)
13225{
13226 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
13227 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
13228 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
13229 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
13230}
13231
13232/* For immediate of above form, return 0bABCD. */
13233
13234static unsigned
13235neon_squash_bits (unsigned imm)
13236{
13237 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
13238 | ((imm & 0x01000000) >> 21);
13239}
13240
136da414 13241/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
13242
13243static unsigned
13244neon_qfloat_bits (unsigned imm)
13245{
136da414 13246 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
13247}
13248
13249/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
13250 the instruction. *OP is passed as the initial value of the op field, and
13251 may be set to a different value depending on the constant (i.e.
13252 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 13253 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 13254 try smaller element sizes. */
5287ad62
JB
13255
13256static int
c96612cc
JB
13257neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
13258 unsigned *immbits, int *op, int size,
13259 enum neon_el_type type)
5287ad62 13260{
c96612cc
JB
13261 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13262 float. */
13263 if (type == NT_float && !float_p)
13264 return FAIL;
13265
136da414
JB
13266 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13267 {
13268 if (size != 32 || *op == 1)
13269 return FAIL;
13270 *immbits = neon_qfloat_bits (immlo);
13271 return 0xf;
13272 }
036dc3f7
PB
13273
13274 if (size == 64)
5287ad62 13275 {
036dc3f7
PB
13276 if (neon_bits_same_in_bytes (immhi)
13277 && neon_bits_same_in_bytes (immlo))
13278 {
13279 if (*op == 1)
13280 return FAIL;
13281 *immbits = (neon_squash_bits (immhi) << 4)
13282 | neon_squash_bits (immlo);
13283 *op = 1;
13284 return 0xe;
13285 }
13286
13287 if (immhi != immlo)
13288 return FAIL;
5287ad62 13289 }
036dc3f7
PB
13290
13291 if (size >= 32)
5287ad62 13292 {
036dc3f7
PB
13293 if (immlo == (immlo & 0x000000ff))
13294 {
13295 *immbits = immlo;
13296 return 0x0;
13297 }
13298 else if (immlo == (immlo & 0x0000ff00))
13299 {
13300 *immbits = immlo >> 8;
13301 return 0x2;
13302 }
13303 else if (immlo == (immlo & 0x00ff0000))
13304 {
13305 *immbits = immlo >> 16;
13306 return 0x4;
13307 }
13308 else if (immlo == (immlo & 0xff000000))
13309 {
13310 *immbits = immlo >> 24;
13311 return 0x6;
13312 }
13313 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13314 {
13315 *immbits = (immlo >> 8) & 0xff;
13316 return 0xc;
13317 }
13318 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13319 {
13320 *immbits = (immlo >> 16) & 0xff;
13321 return 0xd;
13322 }
13323
13324 if ((immlo & 0xffff) != (immlo >> 16))
13325 return FAIL;
13326 immlo &= 0xffff;
5287ad62 13327 }
036dc3f7
PB
13328
13329 if (size >= 16)
5287ad62 13330 {
036dc3f7
PB
13331 if (immlo == (immlo & 0x000000ff))
13332 {
13333 *immbits = immlo;
13334 return 0x8;
13335 }
13336 else if (immlo == (immlo & 0x0000ff00))
13337 {
13338 *immbits = immlo >> 8;
13339 return 0xa;
13340 }
13341
13342 if ((immlo & 0xff) != (immlo >> 8))
13343 return FAIL;
13344 immlo &= 0xff;
5287ad62 13345 }
036dc3f7
PB
13346
13347 if (immlo == (immlo & 0x000000ff))
5287ad62 13348 {
036dc3f7
PB
13349 /* Don't allow MVN with 8-bit immediate. */
13350 if (*op == 1)
13351 return FAIL;
13352 *immbits = immlo;
13353 return 0xe;
5287ad62 13354 }
5287ad62
JB
13355
13356 return FAIL;
13357}
13358
13359/* Write immediate bits [7:0] to the following locations:
13360
13361 |28/24|23 19|18 16|15 4|3 0|
13362 | 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|
13363
13364 This function is used by VMOV/VMVN/VORR/VBIC. */
13365
13366static void
13367neon_write_immbits (unsigned immbits)
13368{
13369 inst.instruction |= immbits & 0xf;
13370 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13371 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13372}
13373
13374/* Invert low-order SIZE bits of XHI:XLO. */
13375
13376static void
13377neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13378{
13379 unsigned immlo = xlo ? *xlo : 0;
13380 unsigned immhi = xhi ? *xhi : 0;
13381
13382 switch (size)
13383 {
13384 case 8:
13385 immlo = (~immlo) & 0xff;
13386 break;
13387
13388 case 16:
13389 immlo = (~immlo) & 0xffff;
13390 break;
13391
13392 case 64:
13393 immhi = (~immhi) & 0xffffffff;
13394 /* fall through. */
13395
13396 case 32:
13397 immlo = (~immlo) & 0xffffffff;
13398 break;
13399
13400 default:
13401 abort ();
13402 }
13403
13404 if (xlo)
13405 *xlo = immlo;
13406
13407 if (xhi)
13408 *xhi = immhi;
13409}
13410
13411static void
13412do_neon_logic (void)
13413{
13414 if (inst.operands[2].present && inst.operands[2].isreg)
13415 {
037e8744 13416 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13417 neon_check_type (3, rs, N_IGNORE_TYPE);
13418 /* U bit and size field were set as part of the bitmask. */
88714cb8 13419 NEON_ENCODE (INTEGER, inst);
037e8744 13420 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13421 }
13422 else
13423 {
4316f0d2
DG
13424 const int three_ops_form = (inst.operands[2].present
13425 && !inst.operands[2].isreg);
13426 const int immoperand = (three_ops_form ? 2 : 1);
13427 enum neon_shape rs = (three_ops_form
13428 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13429 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744
JB
13430 struct neon_type_el et = neon_check_type (2, rs,
13431 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 13432 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
13433 unsigned immbits;
13434 int cmode;
5f4273c7 13435
5287ad62
JB
13436 if (et.type == NT_invtype)
13437 return;
5f4273c7 13438
4316f0d2
DG
13439 if (three_ops_form)
13440 constraint (inst.operands[0].reg != inst.operands[1].reg,
13441 _("first and second operands shall be the same register"));
13442
88714cb8 13443 NEON_ENCODE (IMMED, inst);
5287ad62 13444
4316f0d2 13445 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
13446 if (et.size == 64)
13447 {
13448 /* .i64 is a pseudo-op, so the immediate must be a repeating
13449 pattern. */
4316f0d2
DG
13450 if (immbits != (inst.operands[immoperand].regisimm ?
13451 inst.operands[immoperand].reg : 0))
036dc3f7
PB
13452 {
13453 /* Set immbits to an invalid constant. */
13454 immbits = 0xdeadbeef;
13455 }
13456 }
13457
5287ad62
JB
13458 switch (opcode)
13459 {
13460 case N_MNEM_vbic:
036dc3f7 13461 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13462 break;
5f4273c7 13463
5287ad62 13464 case N_MNEM_vorr:
036dc3f7 13465 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13466 break;
5f4273c7 13467
5287ad62
JB
13468 case N_MNEM_vand:
13469 /* Pseudo-instruction for VBIC. */
5287ad62
JB
13470 neon_invert_size (&immbits, 0, et.size);
13471 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13472 break;
5f4273c7 13473
5287ad62
JB
13474 case N_MNEM_vorn:
13475 /* Pseudo-instruction for VORR. */
5287ad62
JB
13476 neon_invert_size (&immbits, 0, et.size);
13477 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13478 break;
5f4273c7 13479
5287ad62
JB
13480 default:
13481 abort ();
13482 }
13483
13484 if (cmode == FAIL)
13485 return;
13486
037e8744 13487 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13488 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13489 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13490 inst.instruction |= cmode << 8;
13491 neon_write_immbits (immbits);
5f4273c7 13492
88714cb8 13493 neon_dp_fixup (&inst);
5287ad62
JB
13494 }
13495}
13496
13497static void
13498do_neon_bitfield (void)
13499{
037e8744 13500 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 13501 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 13502 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13503}
13504
13505static void
dcbf9037
JB
13506neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13507 unsigned destbits)
5287ad62 13508{
037e8744 13509 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
13510 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13511 types | N_KEY);
5287ad62
JB
13512 if (et.type == NT_float)
13513 {
88714cb8 13514 NEON_ENCODE (FLOAT, inst);
037e8744 13515 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13516 }
13517 else
13518 {
88714cb8 13519 NEON_ENCODE (INTEGER, inst);
037e8744 13520 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
13521 }
13522}
13523
13524static void
13525do_neon_dyadic_if_su (void)
13526{
dcbf9037 13527 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13528}
13529
13530static void
13531do_neon_dyadic_if_su_d (void)
13532{
13533 /* This version only allow D registers, but that constraint is enforced during
13534 operand parsing so we don't need to do anything extra here. */
dcbf9037 13535 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13536}
13537
5287ad62
JB
13538static void
13539do_neon_dyadic_if_i_d (void)
13540{
428e3f1f
PB
13541 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13542 affected if we specify unsigned args. */
13543 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
13544}
13545
037e8744
JB
13546enum vfp_or_neon_is_neon_bits
13547{
13548 NEON_CHECK_CC = 1,
13549 NEON_CHECK_ARCH = 2
13550};
13551
13552/* Call this function if an instruction which may have belonged to the VFP or
13553 Neon instruction sets, but turned out to be a Neon instruction (due to the
13554 operand types involved, etc.). We have to check and/or fix-up a couple of
13555 things:
13556
13557 - Make sure the user hasn't attempted to make a Neon instruction
13558 conditional.
13559 - Alter the value in the condition code field if necessary.
13560 - Make sure that the arch supports Neon instructions.
13561
13562 Which of these operations take place depends on bits from enum
13563 vfp_or_neon_is_neon_bits.
13564
13565 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13566 current instruction's condition is COND_ALWAYS, the condition field is
13567 changed to inst.uncond_value. This is necessary because instructions shared
13568 between VFP and Neon may be conditional for the VFP variants only, and the
13569 unconditional Neon version must have, e.g., 0xF in the condition field. */
13570
13571static int
13572vfp_or_neon_is_neon (unsigned check)
13573{
13574 /* Conditions are always legal in Thumb mode (IT blocks). */
13575 if (!thumb_mode && (check & NEON_CHECK_CC))
13576 {
13577 if (inst.cond != COND_ALWAYS)
13578 {
13579 first_error (_(BAD_COND));
13580 return FAIL;
13581 }
13582 if (inst.uncond_value != -1)
13583 inst.instruction |= inst.uncond_value << 28;
13584 }
5f4273c7 13585
037e8744
JB
13586 if ((check & NEON_CHECK_ARCH)
13587 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13588 {
13589 first_error (_(BAD_FPU));
13590 return FAIL;
13591 }
5f4273c7 13592
037e8744
JB
13593 return SUCCESS;
13594}
13595
5287ad62
JB
13596static void
13597do_neon_addsub_if_i (void)
13598{
037e8744
JB
13599 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13600 return;
13601
13602 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13603 return;
13604
5287ad62
JB
13605 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13606 affected if we specify unsigned args. */
dcbf9037 13607 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
13608}
13609
13610/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13611 result to be:
13612 V<op> A,B (A is operand 0, B is operand 2)
13613 to mean:
13614 V<op> A,B,A
13615 not:
13616 V<op> A,B,B
13617 so handle that case specially. */
13618
13619static void
13620neon_exchange_operands (void)
13621{
13622 void *scratch = alloca (sizeof (inst.operands[0]));
13623 if (inst.operands[1].present)
13624 {
13625 /* Swap operands[1] and operands[2]. */
13626 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13627 inst.operands[1] = inst.operands[2];
13628 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13629 }
13630 else
13631 {
13632 inst.operands[1] = inst.operands[2];
13633 inst.operands[2] = inst.operands[0];
13634 }
13635}
13636
13637static void
13638neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13639{
13640 if (inst.operands[2].isreg)
13641 {
13642 if (invert)
13643 neon_exchange_operands ();
dcbf9037 13644 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
13645 }
13646 else
13647 {
037e8744 13648 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
13649 struct neon_type_el et = neon_check_type (2, rs,
13650 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 13651
88714cb8 13652 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13653 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13654 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13655 inst.instruction |= LOW4 (inst.operands[1].reg);
13656 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13657 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13658 inst.instruction |= (et.type == NT_float) << 10;
13659 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13660
88714cb8 13661 neon_dp_fixup (&inst);
5287ad62
JB
13662 }
13663}
13664
13665static void
13666do_neon_cmp (void)
13667{
13668 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13669}
13670
13671static void
13672do_neon_cmp_inv (void)
13673{
13674 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13675}
13676
13677static void
13678do_neon_ceq (void)
13679{
13680 neon_compare (N_IF_32, N_IF_32, FALSE);
13681}
13682
13683/* For multiply instructions, we have the possibility of 16-bit or 32-bit
13684 scalars, which are encoded in 5 bits, M : Rm.
13685 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13686 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13687 index in M. */
13688
13689static unsigned
13690neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13691{
dcbf9037
JB
13692 unsigned regno = NEON_SCALAR_REG (scalar);
13693 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
13694
13695 switch (elsize)
13696 {
13697 case 16:
13698 if (regno > 7 || elno > 3)
13699 goto bad_scalar;
13700 return regno | (elno << 3);
5f4273c7 13701
5287ad62
JB
13702 case 32:
13703 if (regno > 15 || elno > 1)
13704 goto bad_scalar;
13705 return regno | (elno << 4);
13706
13707 default:
13708 bad_scalar:
dcbf9037 13709 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
13710 }
13711
13712 return 0;
13713}
13714
13715/* Encode multiply / multiply-accumulate scalar instructions. */
13716
13717static void
13718neon_mul_mac (struct neon_type_el et, int ubit)
13719{
dcbf9037
JB
13720 unsigned scalar;
13721
13722 /* Give a more helpful error message if we have an invalid type. */
13723 if (et.type == NT_invtype)
13724 return;
5f4273c7 13725
dcbf9037 13726 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
13727 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13728 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13729 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13730 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13731 inst.instruction |= LOW4 (scalar);
13732 inst.instruction |= HI1 (scalar) << 5;
13733 inst.instruction |= (et.type == NT_float) << 8;
13734 inst.instruction |= neon_logbits (et.size) << 20;
13735 inst.instruction |= (ubit != 0) << 24;
13736
88714cb8 13737 neon_dp_fixup (&inst);
5287ad62
JB
13738}
13739
13740static void
13741do_neon_mac_maybe_scalar (void)
13742{
037e8744
JB
13743 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13744 return;
13745
13746 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13747 return;
13748
5287ad62
JB
13749 if (inst.operands[2].isscalar)
13750 {
037e8744 13751 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13752 struct neon_type_el et = neon_check_type (3, rs,
13753 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 13754 NEON_ENCODE (SCALAR, inst);
037e8744 13755 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13756 }
13757 else
428e3f1f
PB
13758 {
13759 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13760 affected if we specify unsigned args. */
13761 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13762 }
5287ad62
JB
13763}
13764
62f3b8c8
PB
13765static void
13766do_neon_fmac (void)
13767{
13768 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13769 return;
13770
13771 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13772 return;
13773
13774 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13775}
13776
5287ad62
JB
13777static void
13778do_neon_tst (void)
13779{
037e8744 13780 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13781 struct neon_type_el et = neon_check_type (3, rs,
13782 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 13783 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13784}
13785
13786/* VMUL with 3 registers allows the P8 type. The scalar version supports the
13787 same types as the MAC equivalents. The polynomial type for this instruction
13788 is encoded the same as the integer type. */
13789
13790static void
13791do_neon_mul (void)
13792{
037e8744
JB
13793 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13794 return;
13795
13796 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13797 return;
13798
5287ad62
JB
13799 if (inst.operands[2].isscalar)
13800 do_neon_mac_maybe_scalar ();
13801 else
dcbf9037 13802 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
13803}
13804
13805static void
13806do_neon_qdmulh (void)
13807{
13808 if (inst.operands[2].isscalar)
13809 {
037e8744 13810 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13811 struct neon_type_el et = neon_check_type (3, rs,
13812 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13813 NEON_ENCODE (SCALAR, inst);
037e8744 13814 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13815 }
13816 else
13817 {
037e8744 13818 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13819 struct neon_type_el et = neon_check_type (3, rs,
13820 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13821 NEON_ENCODE (INTEGER, inst);
5287ad62 13822 /* The U bit (rounding) comes from bit mask. */
037e8744 13823 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13824 }
13825}
13826
13827static void
13828do_neon_fcmp_absolute (void)
13829{
037e8744 13830 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13831 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13832 /* Size field comes from bit mask. */
037e8744 13833 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
13834}
13835
13836static void
13837do_neon_fcmp_absolute_inv (void)
13838{
13839 neon_exchange_operands ();
13840 do_neon_fcmp_absolute ();
13841}
13842
13843static void
13844do_neon_step (void)
13845{
037e8744 13846 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 13847 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 13848 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13849}
13850
13851static void
13852do_neon_abs_neg (void)
13853{
037e8744
JB
13854 enum neon_shape rs;
13855 struct neon_type_el et;
5f4273c7 13856
037e8744
JB
13857 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13858 return;
13859
13860 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13861 return;
13862
13863 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13864 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 13865
5287ad62
JB
13866 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13867 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13868 inst.instruction |= LOW4 (inst.operands[1].reg);
13869 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13870 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13871 inst.instruction |= (et.type == NT_float) << 10;
13872 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13873
88714cb8 13874 neon_dp_fixup (&inst);
5287ad62
JB
13875}
13876
13877static void
13878do_neon_sli (void)
13879{
037e8744 13880 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13881 struct neon_type_el et = neon_check_type (2, rs,
13882 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13883 int imm = inst.operands[2].imm;
13884 constraint (imm < 0 || (unsigned)imm >= et.size,
13885 _("immediate out of range for insert"));
037e8744 13886 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13887}
13888
13889static void
13890do_neon_sri (void)
13891{
037e8744 13892 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13893 struct neon_type_el et = neon_check_type (2, rs,
13894 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13895 int imm = inst.operands[2].imm;
13896 constraint (imm < 1 || (unsigned)imm > et.size,
13897 _("immediate out of range for insert"));
037e8744 13898 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
13899}
13900
13901static void
13902do_neon_qshlu_imm (void)
13903{
037e8744 13904 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13905 struct neon_type_el et = neon_check_type (2, rs,
13906 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13907 int imm = inst.operands[2].imm;
13908 constraint (imm < 0 || (unsigned)imm >= et.size,
13909 _("immediate out of range for shift"));
13910 /* Only encodes the 'U present' variant of the instruction.
13911 In this case, signed types have OP (bit 8) set to 0.
13912 Unsigned types have OP set to 1. */
13913 inst.instruction |= (et.type == NT_unsigned) << 8;
13914 /* The rest of the bits are the same as other immediate shifts. */
037e8744 13915 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13916}
13917
13918static void
13919do_neon_qmovn (void)
13920{
13921 struct neon_type_el et = neon_check_type (2, NS_DQ,
13922 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13923 /* Saturating move where operands can be signed or unsigned, and the
13924 destination has the same signedness. */
88714cb8 13925 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13926 if (et.type == NT_unsigned)
13927 inst.instruction |= 0xc0;
13928 else
13929 inst.instruction |= 0x80;
13930 neon_two_same (0, 1, et.size / 2);
13931}
13932
13933static void
13934do_neon_qmovun (void)
13935{
13936 struct neon_type_el et = neon_check_type (2, NS_DQ,
13937 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13938 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 13939 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13940 neon_two_same (0, 1, et.size / 2);
13941}
13942
13943static void
13944do_neon_rshift_sat_narrow (void)
13945{
13946 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13947 or unsigned. If operands are unsigned, results must also be unsigned. */
13948 struct neon_type_el et = neon_check_type (2, NS_DQI,
13949 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13950 int imm = inst.operands[2].imm;
13951 /* This gets the bounds check, size encoding and immediate bits calculation
13952 right. */
13953 et.size /= 2;
5f4273c7 13954
5287ad62
JB
13955 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13956 VQMOVN.I<size> <Dd>, <Qm>. */
13957 if (imm == 0)
13958 {
13959 inst.operands[2].present = 0;
13960 inst.instruction = N_MNEM_vqmovn;
13961 do_neon_qmovn ();
13962 return;
13963 }
5f4273c7 13964
5287ad62
JB
13965 constraint (imm < 1 || (unsigned)imm > et.size,
13966 _("immediate out of range"));
13967 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13968}
13969
13970static void
13971do_neon_rshift_sat_narrow_u (void)
13972{
13973 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13974 or unsigned. If operands are unsigned, results must also be unsigned. */
13975 struct neon_type_el et = neon_check_type (2, NS_DQI,
13976 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13977 int imm = inst.operands[2].imm;
13978 /* This gets the bounds check, size encoding and immediate bits calculation
13979 right. */
13980 et.size /= 2;
13981
13982 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13983 VQMOVUN.I<size> <Dd>, <Qm>. */
13984 if (imm == 0)
13985 {
13986 inst.operands[2].present = 0;
13987 inst.instruction = N_MNEM_vqmovun;
13988 do_neon_qmovun ();
13989 return;
13990 }
13991
13992 constraint (imm < 1 || (unsigned)imm > et.size,
13993 _("immediate out of range"));
13994 /* FIXME: The manual is kind of unclear about what value U should have in
13995 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13996 must be 1. */
13997 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13998}
13999
14000static void
14001do_neon_movn (void)
14002{
14003 struct neon_type_el et = neon_check_type (2, NS_DQ,
14004 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 14005 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14006 neon_two_same (0, 1, et.size / 2);
14007}
14008
14009static void
14010do_neon_rshift_narrow (void)
14011{
14012 struct neon_type_el et = neon_check_type (2, NS_DQI,
14013 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14014 int imm = inst.operands[2].imm;
14015 /* This gets the bounds check, size encoding and immediate bits calculation
14016 right. */
14017 et.size /= 2;
5f4273c7 14018
5287ad62
JB
14019 /* If immediate is zero then we are a pseudo-instruction for
14020 VMOVN.I<size> <Dd>, <Qm> */
14021 if (imm == 0)
14022 {
14023 inst.operands[2].present = 0;
14024 inst.instruction = N_MNEM_vmovn;
14025 do_neon_movn ();
14026 return;
14027 }
5f4273c7 14028
5287ad62
JB
14029 constraint (imm < 1 || (unsigned)imm > et.size,
14030 _("immediate out of range for narrowing operation"));
14031 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
14032}
14033
14034static void
14035do_neon_shll (void)
14036{
14037 /* FIXME: Type checking when lengthening. */
14038 struct neon_type_el et = neon_check_type (2, NS_QDI,
14039 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
14040 unsigned imm = inst.operands[2].imm;
14041
14042 if (imm == et.size)
14043 {
14044 /* Maximum shift variant. */
88714cb8 14045 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14046 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14047 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14048 inst.instruction |= LOW4 (inst.operands[1].reg);
14049 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14050 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14051
88714cb8 14052 neon_dp_fixup (&inst);
5287ad62
JB
14053 }
14054 else
14055 {
14056 /* A more-specific type check for non-max versions. */
14057 et = neon_check_type (2, NS_QDI,
14058 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 14059 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14060 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
14061 }
14062}
14063
037e8744 14064/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
14065 the current instruction is. */
14066
14067static int
14068neon_cvt_flavour (enum neon_shape rs)
14069{
037e8744
JB
14070#define CVT_VAR(C,X,Y) \
14071 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
14072 if (et.type != NT_invtype) \
14073 { \
14074 inst.error = NULL; \
14075 return (C); \
5287ad62
JB
14076 }
14077 struct neon_type_el et;
037e8744
JB
14078 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
14079 || rs == NS_FF) ? N_VFP : 0;
14080 /* The instruction versions which take an immediate take one register
14081 argument, which is extended to the width of the full register. Thus the
14082 "source" and "destination" registers must have the same width. Hack that
14083 here by making the size equal to the key (wider, in this case) operand. */
14084 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 14085
5287ad62
JB
14086 CVT_VAR (0, N_S32, N_F32);
14087 CVT_VAR (1, N_U32, N_F32);
14088 CVT_VAR (2, N_F32, N_S32);
14089 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
14090 /* Half-precision conversions. */
14091 CVT_VAR (4, N_F32, N_F16);
14092 CVT_VAR (5, N_F16, N_F32);
5f4273c7 14093
037e8744 14094 whole_reg = N_VFP;
5f4273c7 14095
037e8744 14096 /* VFP instructions. */
8e79c3df
CM
14097 CVT_VAR (6, N_F32, N_F64);
14098 CVT_VAR (7, N_F64, N_F32);
14099 CVT_VAR (8, N_S32, N_F64 | key);
14100 CVT_VAR (9, N_U32, N_F64 | key);
14101 CVT_VAR (10, N_F64 | key, N_S32);
14102 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 14103 /* VFP instructions with bitshift. */
8e79c3df
CM
14104 CVT_VAR (12, N_F32 | key, N_S16);
14105 CVT_VAR (13, N_F32 | key, N_U16);
14106 CVT_VAR (14, N_F64 | key, N_S16);
14107 CVT_VAR (15, N_F64 | key, N_U16);
14108 CVT_VAR (16, N_S16, N_F32 | key);
14109 CVT_VAR (17, N_U16, N_F32 | key);
14110 CVT_VAR (18, N_S16, N_F64 | key);
14111 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 14112
5287ad62
JB
14113 return -1;
14114#undef CVT_VAR
14115}
14116
037e8744
JB
14117/* Neon-syntax VFP conversions. */
14118
5287ad62 14119static void
037e8744 14120do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 14121{
037e8744 14122 const char *opname = 0;
5f4273c7 14123
037e8744 14124 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 14125 {
037e8744
JB
14126 /* Conversions with immediate bitshift. */
14127 const char *enc[] =
14128 {
14129 "ftosls",
14130 "ftouls",
14131 "fsltos",
14132 "fultos",
14133 NULL,
14134 NULL,
8e79c3df
CM
14135 NULL,
14136 NULL,
037e8744
JB
14137 "ftosld",
14138 "ftould",
14139 "fsltod",
14140 "fultod",
14141 "fshtos",
14142 "fuhtos",
14143 "fshtod",
14144 "fuhtod",
14145 "ftoshs",
14146 "ftouhs",
14147 "ftoshd",
14148 "ftouhd"
14149 };
14150
14151 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14152 {
14153 opname = enc[flavour];
14154 constraint (inst.operands[0].reg != inst.operands[1].reg,
14155 _("operands 0 and 1 must be the same register"));
14156 inst.operands[1] = inst.operands[2];
14157 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
14158 }
5287ad62
JB
14159 }
14160 else
14161 {
037e8744
JB
14162 /* Conversions without bitshift. */
14163 const char *enc[] =
14164 {
14165 "ftosis",
14166 "ftouis",
14167 "fsitos",
14168 "fuitos",
8e79c3df
CM
14169 "NULL",
14170 "NULL",
037e8744
JB
14171 "fcvtsd",
14172 "fcvtds",
14173 "ftosid",
14174 "ftouid",
14175 "fsitod",
14176 "fuitod"
14177 };
14178
14179 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14180 opname = enc[flavour];
14181 }
14182
14183 if (opname)
14184 do_vfp_nsyn_opcode (opname);
14185}
14186
14187static void
14188do_vfp_nsyn_cvtz (void)
14189{
14190 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
14191 int flavour = neon_cvt_flavour (rs);
14192 const char *enc[] =
14193 {
14194 "ftosizs",
14195 "ftouizs",
14196 NULL,
14197 NULL,
14198 NULL,
14199 NULL,
8e79c3df
CM
14200 NULL,
14201 NULL,
037e8744
JB
14202 "ftosizd",
14203 "ftouizd"
14204 };
14205
14206 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
14207 do_vfp_nsyn_opcode (enc[flavour]);
14208}
f31fef98 14209
037e8744 14210static void
e3e535bc 14211do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
037e8744
JB
14212{
14213 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 14214 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
14215 int flavour = neon_cvt_flavour (rs);
14216
e3e535bc
NC
14217 /* PR11109: Handle round-to-zero for VCVT conversions. */
14218 if (round_to_zero
14219 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
14220 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
14221 && (rs == NS_FD || rs == NS_FF))
14222 {
14223 do_vfp_nsyn_cvtz ();
14224 return;
14225 }
14226
037e8744 14227 /* VFP rather than Neon conversions. */
8e79c3df 14228 if (flavour >= 6)
037e8744
JB
14229 {
14230 do_vfp_nsyn_cvt (rs, flavour);
14231 return;
14232 }
14233
14234 switch (rs)
14235 {
14236 case NS_DDI:
14237 case NS_QQI:
14238 {
35997600
NC
14239 unsigned immbits;
14240 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
14241
037e8744
JB
14242 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14243 return;
14244
14245 /* Fixed-point conversion with #0 immediate is encoded as an
14246 integer conversion. */
14247 if (inst.operands[2].present && inst.operands[2].imm == 0)
14248 goto int_encode;
35997600 14249 immbits = 32 - inst.operands[2].imm;
88714cb8 14250 NEON_ENCODE (IMMED, inst);
037e8744
JB
14251 if (flavour != -1)
14252 inst.instruction |= enctab[flavour];
14253 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14254 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14255 inst.instruction |= LOW4 (inst.operands[1].reg);
14256 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14257 inst.instruction |= neon_quad (rs) << 6;
14258 inst.instruction |= 1 << 21;
14259 inst.instruction |= immbits << 16;
14260
88714cb8 14261 neon_dp_fixup (&inst);
037e8744
JB
14262 }
14263 break;
14264
14265 case NS_DD:
14266 case NS_QQ:
14267 int_encode:
14268 {
14269 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
14270
88714cb8 14271 NEON_ENCODE (INTEGER, inst);
037e8744
JB
14272
14273 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14274 return;
14275
14276 if (flavour != -1)
14277 inst.instruction |= enctab[flavour];
14278
14279 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14280 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14281 inst.instruction |= LOW4 (inst.operands[1].reg);
14282 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14283 inst.instruction |= neon_quad (rs) << 6;
14284 inst.instruction |= 2 << 18;
14285
88714cb8 14286 neon_dp_fixup (&inst);
037e8744
JB
14287 }
14288 break;
14289
8e79c3df
CM
14290 /* Half-precision conversions for Advanced SIMD -- neon. */
14291 case NS_QD:
14292 case NS_DQ:
14293
14294 if ((rs == NS_DQ)
14295 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14296 {
14297 as_bad (_("operand size must match register width"));
14298 break;
14299 }
14300
14301 if ((rs == NS_QD)
14302 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14303 {
14304 as_bad (_("operand size must match register width"));
14305 break;
14306 }
14307
14308 if (rs == NS_DQ)
14309 inst.instruction = 0x3b60600;
14310 else
14311 inst.instruction = 0x3b60700;
14312
14313 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14314 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14315 inst.instruction |= LOW4 (inst.operands[1].reg);
14316 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 14317 neon_dp_fixup (&inst);
8e79c3df
CM
14318 break;
14319
037e8744
JB
14320 default:
14321 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
14322 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 14323 }
5287ad62
JB
14324}
14325
e3e535bc
NC
14326static void
14327do_neon_cvtr (void)
14328{
14329 do_neon_cvt_1 (FALSE);
14330}
14331
14332static void
14333do_neon_cvt (void)
14334{
14335 do_neon_cvt_1 (TRUE);
14336}
14337
8e79c3df
CM
14338static void
14339do_neon_cvtb (void)
14340{
14341 inst.instruction = 0xeb20a40;
14342
14343 /* The sizes are attached to the mnemonic. */
14344 if (inst.vectype.el[0].type != NT_invtype
14345 && inst.vectype.el[0].size == 16)
14346 inst.instruction |= 0x00010000;
14347
14348 /* Programmer's syntax: the sizes are attached to the operands. */
14349 else if (inst.operands[0].vectype.type != NT_invtype
14350 && inst.operands[0].vectype.size == 16)
14351 inst.instruction |= 0x00010000;
14352
14353 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14354 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
14355 do_vfp_cond_or_thumb ();
14356}
14357
14358
14359static void
14360do_neon_cvtt (void)
14361{
14362 do_neon_cvtb ();
14363 inst.instruction |= 0x80;
14364}
14365
5287ad62
JB
14366static void
14367neon_move_immediate (void)
14368{
037e8744
JB
14369 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14370 struct neon_type_el et = neon_check_type (2, rs,
14371 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 14372 unsigned immlo, immhi = 0, immbits;
c96612cc 14373 int op, cmode, float_p;
5287ad62 14374
037e8744
JB
14375 constraint (et.type == NT_invtype,
14376 _("operand size must be specified for immediate VMOV"));
14377
5287ad62
JB
14378 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14379 op = (inst.instruction & (1 << 5)) != 0;
14380
14381 immlo = inst.operands[1].imm;
14382 if (inst.operands[1].regisimm)
14383 immhi = inst.operands[1].reg;
14384
14385 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14386 _("immediate has bits set outside the operand size"));
14387
c96612cc
JB
14388 float_p = inst.operands[1].immisfloat;
14389
14390 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 14391 et.size, et.type)) == FAIL)
5287ad62
JB
14392 {
14393 /* Invert relevant bits only. */
14394 neon_invert_size (&immlo, &immhi, et.size);
14395 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14396 with one or the other; those cases are caught by
14397 neon_cmode_for_move_imm. */
14398 op = !op;
c96612cc
JB
14399 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
14400 &op, et.size, et.type)) == FAIL)
5287ad62 14401 {
dcbf9037 14402 first_error (_("immediate out of range"));
5287ad62
JB
14403 return;
14404 }
14405 }
14406
14407 inst.instruction &= ~(1 << 5);
14408 inst.instruction |= op << 5;
14409
14410 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14411 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 14412 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14413 inst.instruction |= cmode << 8;
14414
14415 neon_write_immbits (immbits);
14416}
14417
14418static void
14419do_neon_mvn (void)
14420{
14421 if (inst.operands[1].isreg)
14422 {
037e8744 14423 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 14424
88714cb8 14425 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14426 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14427 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14428 inst.instruction |= LOW4 (inst.operands[1].reg);
14429 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14430 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14431 }
14432 else
14433 {
88714cb8 14434 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14435 neon_move_immediate ();
14436 }
14437
88714cb8 14438 neon_dp_fixup (&inst);
5287ad62
JB
14439}
14440
14441/* Encode instructions of form:
14442
14443 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 14444 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
14445
14446static void
14447neon_mixed_length (struct neon_type_el et, unsigned size)
14448{
14449 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14450 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14451 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14452 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14453 inst.instruction |= LOW4 (inst.operands[2].reg);
14454 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14455 inst.instruction |= (et.type == NT_unsigned) << 24;
14456 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14457
88714cb8 14458 neon_dp_fixup (&inst);
5287ad62
JB
14459}
14460
14461static void
14462do_neon_dyadic_long (void)
14463{
14464 /* FIXME: Type checking for lengthening op. */
14465 struct neon_type_el et = neon_check_type (3, NS_QDD,
14466 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14467 neon_mixed_length (et, et.size);
14468}
14469
14470static void
14471do_neon_abal (void)
14472{
14473 struct neon_type_el et = neon_check_type (3, NS_QDD,
14474 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14475 neon_mixed_length (et, et.size);
14476}
14477
14478static void
14479neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14480{
14481 if (inst.operands[2].isscalar)
14482 {
dcbf9037
JB
14483 struct neon_type_el et = neon_check_type (3, NS_QDS,
14484 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 14485 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14486 neon_mul_mac (et, et.type == NT_unsigned);
14487 }
14488 else
14489 {
14490 struct neon_type_el et = neon_check_type (3, NS_QDD,
14491 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 14492 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14493 neon_mixed_length (et, et.size);
14494 }
14495}
14496
14497static void
14498do_neon_mac_maybe_scalar_long (void)
14499{
14500 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14501}
14502
14503static void
14504do_neon_dyadic_wide (void)
14505{
14506 struct neon_type_el et = neon_check_type (3, NS_QQD,
14507 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14508 neon_mixed_length (et, et.size);
14509}
14510
14511static void
14512do_neon_dyadic_narrow (void)
14513{
14514 struct neon_type_el et = neon_check_type (3, NS_QDD,
14515 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
14516 /* Operand sign is unimportant, and the U bit is part of the opcode,
14517 so force the operand type to integer. */
14518 et.type = NT_integer;
5287ad62
JB
14519 neon_mixed_length (et, et.size / 2);
14520}
14521
14522static void
14523do_neon_mul_sat_scalar_long (void)
14524{
14525 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14526}
14527
14528static void
14529do_neon_vmull (void)
14530{
14531 if (inst.operands[2].isscalar)
14532 do_neon_mac_maybe_scalar_long ();
14533 else
14534 {
14535 struct neon_type_el et = neon_check_type (3, NS_QDD,
14536 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14537 if (et.type == NT_poly)
88714cb8 14538 NEON_ENCODE (POLY, inst);
5287ad62 14539 else
88714cb8 14540 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14541 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14542 zero. Should be OK as-is. */
14543 neon_mixed_length (et, et.size);
14544 }
14545}
14546
14547static void
14548do_neon_ext (void)
14549{
037e8744 14550 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
14551 struct neon_type_el et = neon_check_type (3, rs,
14552 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14553 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
14554
14555 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14556 _("shift out of range"));
5287ad62
JB
14557 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14558 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14559 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14560 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14561 inst.instruction |= LOW4 (inst.operands[2].reg);
14562 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 14563 inst.instruction |= neon_quad (rs) << 6;
5287ad62 14564 inst.instruction |= imm << 8;
5f4273c7 14565
88714cb8 14566 neon_dp_fixup (&inst);
5287ad62
JB
14567}
14568
14569static void
14570do_neon_rev (void)
14571{
037e8744 14572 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14573 struct neon_type_el et = neon_check_type (2, rs,
14574 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14575 unsigned op = (inst.instruction >> 7) & 3;
14576 /* N (width of reversed regions) is encoded as part of the bitmask. We
14577 extract it here to check the elements to be reversed are smaller.
14578 Otherwise we'd get a reserved instruction. */
14579 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 14580 gas_assert (elsize != 0);
5287ad62
JB
14581 constraint (et.size >= elsize,
14582 _("elements must be smaller than reversal region"));
037e8744 14583 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14584}
14585
14586static void
14587do_neon_dup (void)
14588{
14589 if (inst.operands[1].isscalar)
14590 {
037e8744 14591 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
14592 struct neon_type_el et = neon_check_type (2, rs,
14593 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 14594 unsigned sizebits = et.size >> 3;
dcbf9037 14595 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 14596 int logsize = neon_logbits (et.size);
dcbf9037 14597 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
14598
14599 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14600 return;
14601
88714cb8 14602 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14603 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14604 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14605 inst.instruction |= LOW4 (dm);
14606 inst.instruction |= HI1 (dm) << 5;
037e8744 14607 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14608 inst.instruction |= x << 17;
14609 inst.instruction |= sizebits << 16;
5f4273c7 14610
88714cb8 14611 neon_dp_fixup (&inst);
5287ad62
JB
14612 }
14613 else
14614 {
037e8744
JB
14615 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14616 struct neon_type_el et = neon_check_type (2, rs,
14617 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 14618 /* Duplicate ARM register to lanes of vector. */
88714cb8 14619 NEON_ENCODE (ARMREG, inst);
5287ad62
JB
14620 switch (et.size)
14621 {
14622 case 8: inst.instruction |= 0x400000; break;
14623 case 16: inst.instruction |= 0x000020; break;
14624 case 32: inst.instruction |= 0x000000; break;
14625 default: break;
14626 }
14627 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14628 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14629 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 14630 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
14631 /* The encoding for this instruction is identical for the ARM and Thumb
14632 variants, except for the condition field. */
037e8744 14633 do_vfp_cond_or_thumb ();
5287ad62
JB
14634 }
14635}
14636
14637/* VMOV has particularly many variations. It can be one of:
14638 0. VMOV<c><q> <Qd>, <Qm>
14639 1. VMOV<c><q> <Dd>, <Dm>
14640 (Register operations, which are VORR with Rm = Rn.)
14641 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14642 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14643 (Immediate loads.)
14644 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14645 (ARM register to scalar.)
14646 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14647 (Two ARM registers to vector.)
14648 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14649 (Scalar to ARM register.)
14650 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14651 (Vector to two ARM registers.)
037e8744
JB
14652 8. VMOV.F32 <Sd>, <Sm>
14653 9. VMOV.F64 <Dd>, <Dm>
14654 (VFP register moves.)
14655 10. VMOV.F32 <Sd>, #imm
14656 11. VMOV.F64 <Dd>, #imm
14657 (VFP float immediate load.)
14658 12. VMOV <Rd>, <Sm>
14659 (VFP single to ARM reg.)
14660 13. VMOV <Sd>, <Rm>
14661 (ARM reg to VFP single.)
14662 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14663 (Two ARM regs to two VFP singles.)
14664 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14665 (Two VFP singles to two ARM regs.)
5f4273c7 14666
037e8744
JB
14667 These cases can be disambiguated using neon_select_shape, except cases 1/9
14668 and 3/11 which depend on the operand type too.
5f4273c7 14669
5287ad62 14670 All the encoded bits are hardcoded by this function.
5f4273c7 14671
b7fc2769
JB
14672 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14673 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 14674
5287ad62 14675 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 14676 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
14677
14678static void
14679do_neon_mov (void)
14680{
037e8744
JB
14681 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14682 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14683 NS_NULL);
14684 struct neon_type_el et;
14685 const char *ldconst = 0;
5287ad62 14686
037e8744 14687 switch (rs)
5287ad62 14688 {
037e8744
JB
14689 case NS_DD: /* case 1/9. */
14690 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14691 /* It is not an error here if no type is given. */
14692 inst.error = NULL;
14693 if (et.type == NT_float && et.size == 64)
5287ad62 14694 {
037e8744
JB
14695 do_vfp_nsyn_opcode ("fcpyd");
14696 break;
5287ad62 14697 }
037e8744 14698 /* fall through. */
5287ad62 14699
037e8744
JB
14700 case NS_QQ: /* case 0/1. */
14701 {
14702 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14703 return;
14704 /* The architecture manual I have doesn't explicitly state which
14705 value the U bit should have for register->register moves, but
14706 the equivalent VORR instruction has U = 0, so do that. */
14707 inst.instruction = 0x0200110;
14708 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14709 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14710 inst.instruction |= LOW4 (inst.operands[1].reg);
14711 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14712 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14713 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14714 inst.instruction |= neon_quad (rs) << 6;
14715
88714cb8 14716 neon_dp_fixup (&inst);
037e8744
JB
14717 }
14718 break;
5f4273c7 14719
037e8744
JB
14720 case NS_DI: /* case 3/11. */
14721 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14722 inst.error = NULL;
14723 if (et.type == NT_float && et.size == 64)
5287ad62 14724 {
037e8744
JB
14725 /* case 11 (fconstd). */
14726 ldconst = "fconstd";
14727 goto encode_fconstd;
5287ad62 14728 }
037e8744
JB
14729 /* fall through. */
14730
14731 case NS_QI: /* case 2/3. */
14732 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14733 return;
14734 inst.instruction = 0x0800010;
14735 neon_move_immediate ();
88714cb8 14736 neon_dp_fixup (&inst);
5287ad62 14737 break;
5f4273c7 14738
037e8744
JB
14739 case NS_SR: /* case 4. */
14740 {
14741 unsigned bcdebits = 0;
91d6fa6a 14742 int logsize;
037e8744
JB
14743 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14744 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14745
91d6fa6a
NC
14746 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14747 logsize = neon_logbits (et.size);
14748
037e8744
JB
14749 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14750 _(BAD_FPU));
14751 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14752 && et.size != 32, _(BAD_FPU));
14753 constraint (et.type == NT_invtype, _("bad type for scalar"));
14754 constraint (x >= 64 / et.size, _("scalar index out of range"));
14755
14756 switch (et.size)
14757 {
14758 case 8: bcdebits = 0x8; break;
14759 case 16: bcdebits = 0x1; break;
14760 case 32: bcdebits = 0x0; break;
14761 default: ;
14762 }
14763
14764 bcdebits |= x << logsize;
14765
14766 inst.instruction = 0xe000b10;
14767 do_vfp_cond_or_thumb ();
14768 inst.instruction |= LOW4 (dn) << 16;
14769 inst.instruction |= HI1 (dn) << 7;
14770 inst.instruction |= inst.operands[1].reg << 12;
14771 inst.instruction |= (bcdebits & 3) << 5;
14772 inst.instruction |= (bcdebits >> 2) << 21;
14773 }
14774 break;
5f4273c7 14775
037e8744 14776 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 14777 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 14778 _(BAD_FPU));
b7fc2769 14779
037e8744
JB
14780 inst.instruction = 0xc400b10;
14781 do_vfp_cond_or_thumb ();
14782 inst.instruction |= LOW4 (inst.operands[0].reg);
14783 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14784 inst.instruction |= inst.operands[1].reg << 12;
14785 inst.instruction |= inst.operands[2].reg << 16;
14786 break;
5f4273c7 14787
037e8744
JB
14788 case NS_RS: /* case 6. */
14789 {
91d6fa6a 14790 unsigned logsize;
037e8744
JB
14791 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14792 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14793 unsigned abcdebits = 0;
14794
91d6fa6a
NC
14795 et = neon_check_type (2, NS_NULL,
14796 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14797 logsize = neon_logbits (et.size);
14798
037e8744
JB
14799 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14800 _(BAD_FPU));
14801 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14802 && et.size != 32, _(BAD_FPU));
14803 constraint (et.type == NT_invtype, _("bad type for scalar"));
14804 constraint (x >= 64 / et.size, _("scalar index out of range"));
14805
14806 switch (et.size)
14807 {
14808 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14809 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14810 case 32: abcdebits = 0x00; break;
14811 default: ;
14812 }
14813
14814 abcdebits |= x << logsize;
14815 inst.instruction = 0xe100b10;
14816 do_vfp_cond_or_thumb ();
14817 inst.instruction |= LOW4 (dn) << 16;
14818 inst.instruction |= HI1 (dn) << 7;
14819 inst.instruction |= inst.operands[0].reg << 12;
14820 inst.instruction |= (abcdebits & 3) << 5;
14821 inst.instruction |= (abcdebits >> 2) << 21;
14822 }
14823 break;
5f4273c7 14824
037e8744
JB
14825 case NS_RRD: /* case 7 (fmrrd). */
14826 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14827 _(BAD_FPU));
14828
14829 inst.instruction = 0xc500b10;
14830 do_vfp_cond_or_thumb ();
14831 inst.instruction |= inst.operands[0].reg << 12;
14832 inst.instruction |= inst.operands[1].reg << 16;
14833 inst.instruction |= LOW4 (inst.operands[2].reg);
14834 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14835 break;
5f4273c7 14836
037e8744
JB
14837 case NS_FF: /* case 8 (fcpys). */
14838 do_vfp_nsyn_opcode ("fcpys");
14839 break;
5f4273c7 14840
037e8744
JB
14841 case NS_FI: /* case 10 (fconsts). */
14842 ldconst = "fconsts";
14843 encode_fconstd:
14844 if (is_quarter_float (inst.operands[1].imm))
5287ad62 14845 {
037e8744
JB
14846 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14847 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
14848 }
14849 else
037e8744
JB
14850 first_error (_("immediate out of range"));
14851 break;
5f4273c7 14852
037e8744
JB
14853 case NS_RF: /* case 12 (fmrs). */
14854 do_vfp_nsyn_opcode ("fmrs");
14855 break;
5f4273c7 14856
037e8744
JB
14857 case NS_FR: /* case 13 (fmsr). */
14858 do_vfp_nsyn_opcode ("fmsr");
14859 break;
5f4273c7 14860
037e8744
JB
14861 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14862 (one of which is a list), but we have parsed four. Do some fiddling to
14863 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14864 expect. */
14865 case NS_RRFF: /* case 14 (fmrrs). */
14866 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14867 _("VFP registers must be adjacent"));
14868 inst.operands[2].imm = 2;
14869 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14870 do_vfp_nsyn_opcode ("fmrrs");
14871 break;
5f4273c7 14872
037e8744
JB
14873 case NS_FFRR: /* case 15 (fmsrr). */
14874 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14875 _("VFP registers must be adjacent"));
14876 inst.operands[1] = inst.operands[2];
14877 inst.operands[2] = inst.operands[3];
14878 inst.operands[0].imm = 2;
14879 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14880 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 14881 break;
5f4273c7 14882
5287ad62
JB
14883 default:
14884 abort ();
14885 }
14886}
14887
14888static void
14889do_neon_rshift_round_imm (void)
14890{
037e8744 14891 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14892 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14893 int imm = inst.operands[2].imm;
14894
14895 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14896 if (imm == 0)
14897 {
14898 inst.operands[2].present = 0;
14899 do_neon_mov ();
14900 return;
14901 }
14902
14903 constraint (imm < 1 || (unsigned)imm > et.size,
14904 _("immediate out of range for shift"));
037e8744 14905 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
14906 et.size - imm);
14907}
14908
14909static void
14910do_neon_movl (void)
14911{
14912 struct neon_type_el et = neon_check_type (2, NS_QD,
14913 N_EQK | N_DBL, N_SU_32 | N_KEY);
14914 unsigned sizebits = et.size >> 3;
14915 inst.instruction |= sizebits << 19;
14916 neon_two_same (0, et.type == NT_unsigned, -1);
14917}
14918
14919static void
14920do_neon_trn (void)
14921{
037e8744 14922 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14923 struct neon_type_el et = neon_check_type (2, rs,
14924 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 14925 NEON_ENCODE (INTEGER, inst);
037e8744 14926 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14927}
14928
14929static void
14930do_neon_zip_uzp (void)
14931{
037e8744 14932 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14933 struct neon_type_el et = neon_check_type (2, rs,
14934 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14935 if (rs == NS_DD && et.size == 32)
14936 {
14937 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14938 inst.instruction = N_MNEM_vtrn;
14939 do_neon_trn ();
14940 return;
14941 }
037e8744 14942 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14943}
14944
14945static void
14946do_neon_sat_abs_neg (void)
14947{
037e8744 14948 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14949 struct neon_type_el et = neon_check_type (2, rs,
14950 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14951 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14952}
14953
14954static void
14955do_neon_pair_long (void)
14956{
037e8744 14957 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14958 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14959 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14960 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 14961 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14962}
14963
14964static void
14965do_neon_recip_est (void)
14966{
037e8744 14967 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14968 struct neon_type_el et = neon_check_type (2, rs,
14969 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
14970 inst.instruction |= (et.type == NT_float) << 8;
037e8744 14971 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14972}
14973
14974static void
14975do_neon_cls (void)
14976{
037e8744 14977 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14978 struct neon_type_el et = neon_check_type (2, rs,
14979 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14980 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14981}
14982
14983static void
14984do_neon_clz (void)
14985{
037e8744 14986 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14987 struct neon_type_el et = neon_check_type (2, rs,
14988 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 14989 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14990}
14991
14992static void
14993do_neon_cnt (void)
14994{
037e8744 14995 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14996 struct neon_type_el et = neon_check_type (2, rs,
14997 N_EQK | N_INT, N_8 | N_KEY);
037e8744 14998 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14999}
15000
15001static void
15002do_neon_swp (void)
15003{
037e8744
JB
15004 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15005 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
15006}
15007
15008static void
15009do_neon_tbl_tbx (void)
15010{
15011 unsigned listlenbits;
dcbf9037 15012 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 15013
5287ad62
JB
15014 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
15015 {
dcbf9037 15016 first_error (_("bad list length for table lookup"));
5287ad62
JB
15017 return;
15018 }
5f4273c7 15019
5287ad62
JB
15020 listlenbits = inst.operands[1].imm - 1;
15021 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15022 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15023 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15024 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15025 inst.instruction |= LOW4 (inst.operands[2].reg);
15026 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15027 inst.instruction |= listlenbits << 8;
5f4273c7 15028
88714cb8 15029 neon_dp_fixup (&inst);
5287ad62
JB
15030}
15031
15032static void
15033do_neon_ldm_stm (void)
15034{
15035 /* P, U and L bits are part of bitmask. */
15036 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
15037 unsigned offsetbits = inst.operands[1].imm * 2;
15038
037e8744
JB
15039 if (inst.operands[1].issingle)
15040 {
15041 do_vfp_nsyn_ldm_stm (is_dbmode);
15042 return;
15043 }
15044
5287ad62
JB
15045 constraint (is_dbmode && !inst.operands[0].writeback,
15046 _("writeback (!) must be used for VLDMDB and VSTMDB"));
15047
15048 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15049 _("register list must contain at least 1 and at most 16 "
15050 "registers"));
15051
15052 inst.instruction |= inst.operands[0].reg << 16;
15053 inst.instruction |= inst.operands[0].writeback << 21;
15054 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15055 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
15056
15057 inst.instruction |= offsetbits;
5f4273c7 15058
037e8744 15059 do_vfp_cond_or_thumb ();
5287ad62
JB
15060}
15061
15062static void
15063do_neon_ldr_str (void)
15064{
5287ad62 15065 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 15066
6844b2c2
MGD
15067 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
15068 And is UNPREDICTABLE in thumb mode. */
15069 if (!is_ldr
15070 && inst.operands[1].reg == REG_PC
15071 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
15072 {
15073 if (!thumb_mode && warn_on_deprecated)
15074 as_warn (_("Use of PC here is deprecated"));
15075 else
15076 inst.error = _("Use of PC here is UNPREDICTABLE");
15077 }
15078
037e8744
JB
15079 if (inst.operands[0].issingle)
15080 {
cd2f129f
JB
15081 if (is_ldr)
15082 do_vfp_nsyn_opcode ("flds");
15083 else
15084 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
15085 }
15086 else
5287ad62 15087 {
cd2f129f
JB
15088 if (is_ldr)
15089 do_vfp_nsyn_opcode ("fldd");
5287ad62 15090 else
cd2f129f 15091 do_vfp_nsyn_opcode ("fstd");
5287ad62 15092 }
5287ad62
JB
15093}
15094
15095/* "interleave" version also handles non-interleaving register VLD1/VST1
15096 instructions. */
15097
15098static void
15099do_neon_ld_st_interleave (void)
15100{
037e8744 15101 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
15102 N_8 | N_16 | N_32 | N_64);
15103 unsigned alignbits = 0;
15104 unsigned idx;
15105 /* The bits in this table go:
15106 0: register stride of one (0) or two (1)
15107 1,2: register list length, minus one (1, 2, 3, 4).
15108 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
15109 We use -1 for invalid entries. */
15110 const int typetable[] =
15111 {
15112 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
15113 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
15114 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
15115 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
15116 };
15117 int typebits;
15118
dcbf9037
JB
15119 if (et.type == NT_invtype)
15120 return;
15121
5287ad62
JB
15122 if (inst.operands[1].immisalign)
15123 switch (inst.operands[1].imm >> 8)
15124 {
15125 case 64: alignbits = 1; break;
15126 case 128:
e23c0ad8
JZ
15127 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
15128 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
15129 goto bad_alignment;
15130 alignbits = 2;
15131 break;
15132 case 256:
e23c0ad8 15133 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
15134 goto bad_alignment;
15135 alignbits = 3;
15136 break;
15137 default:
15138 bad_alignment:
dcbf9037 15139 first_error (_("bad alignment"));
5287ad62
JB
15140 return;
15141 }
15142
15143 inst.instruction |= alignbits << 4;
15144 inst.instruction |= neon_logbits (et.size) << 6;
15145
15146 /* Bits [4:6] of the immediate in a list specifier encode register stride
15147 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
15148 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
15149 up the right value for "type" in a table based on this value and the given
15150 list style, then stick it back. */
15151 idx = ((inst.operands[0].imm >> 4) & 7)
15152 | (((inst.instruction >> 8) & 3) << 3);
15153
15154 typebits = typetable[idx];
5f4273c7 15155
5287ad62
JB
15156 constraint (typebits == -1, _("bad list type for instruction"));
15157
15158 inst.instruction &= ~0xf00;
15159 inst.instruction |= typebits << 8;
15160}
15161
15162/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
15163 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
15164 otherwise. The variable arguments are a list of pairs of legal (size, align)
15165 values, terminated with -1. */
15166
15167static int
15168neon_alignment_bit (int size, int align, int *do_align, ...)
15169{
15170 va_list ap;
15171 int result = FAIL, thissize, thisalign;
5f4273c7 15172
5287ad62
JB
15173 if (!inst.operands[1].immisalign)
15174 {
15175 *do_align = 0;
15176 return SUCCESS;
15177 }
5f4273c7 15178
5287ad62
JB
15179 va_start (ap, do_align);
15180
15181 do
15182 {
15183 thissize = va_arg (ap, int);
15184 if (thissize == -1)
15185 break;
15186 thisalign = va_arg (ap, int);
15187
15188 if (size == thissize && align == thisalign)
15189 result = SUCCESS;
15190 }
15191 while (result != SUCCESS);
15192
15193 va_end (ap);
15194
15195 if (result == SUCCESS)
15196 *do_align = 1;
15197 else
dcbf9037 15198 first_error (_("unsupported alignment for instruction"));
5f4273c7 15199
5287ad62
JB
15200 return result;
15201}
15202
15203static void
15204do_neon_ld_st_lane (void)
15205{
037e8744 15206 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15207 int align_good, do_align = 0;
15208 int logsize = neon_logbits (et.size);
15209 int align = inst.operands[1].imm >> 8;
15210 int n = (inst.instruction >> 8) & 3;
15211 int max_el = 64 / et.size;
5f4273c7 15212
dcbf9037
JB
15213 if (et.type == NT_invtype)
15214 return;
5f4273c7 15215
5287ad62
JB
15216 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
15217 _("bad list length"));
15218 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
15219 _("scalar index out of range"));
15220 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
15221 && et.size == 8,
15222 _("stride of 2 unavailable when element size is 8"));
5f4273c7 15223
5287ad62
JB
15224 switch (n)
15225 {
15226 case 0: /* VLD1 / VST1. */
15227 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
15228 32, 32, -1);
15229 if (align_good == FAIL)
15230 return;
15231 if (do_align)
15232 {
15233 unsigned alignbits = 0;
15234 switch (et.size)
15235 {
15236 case 16: alignbits = 0x1; break;
15237 case 32: alignbits = 0x3; break;
15238 default: ;
15239 }
15240 inst.instruction |= alignbits << 4;
15241 }
15242 break;
15243
15244 case 1: /* VLD2 / VST2. */
15245 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
15246 32, 64, -1);
15247 if (align_good == FAIL)
15248 return;
15249 if (do_align)
15250 inst.instruction |= 1 << 4;
15251 break;
15252
15253 case 2: /* VLD3 / VST3. */
15254 constraint (inst.operands[1].immisalign,
15255 _("can't use alignment with this instruction"));
15256 break;
15257
15258 case 3: /* VLD4 / VST4. */
15259 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15260 16, 64, 32, 64, 32, 128, -1);
15261 if (align_good == FAIL)
15262 return;
15263 if (do_align)
15264 {
15265 unsigned alignbits = 0;
15266 switch (et.size)
15267 {
15268 case 8: alignbits = 0x1; break;
15269 case 16: alignbits = 0x1; break;
15270 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
15271 default: ;
15272 }
15273 inst.instruction |= alignbits << 4;
15274 }
15275 break;
15276
15277 default: ;
15278 }
15279
15280 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
15281 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15282 inst.instruction |= 1 << (4 + logsize);
5f4273c7 15283
5287ad62
JB
15284 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
15285 inst.instruction |= logsize << 10;
15286}
15287
15288/* Encode single n-element structure to all lanes VLD<n> instructions. */
15289
15290static void
15291do_neon_ld_dup (void)
15292{
037e8744 15293 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15294 int align_good, do_align = 0;
15295
dcbf9037
JB
15296 if (et.type == NT_invtype)
15297 return;
15298
5287ad62
JB
15299 switch ((inst.instruction >> 8) & 3)
15300 {
15301 case 0: /* VLD1. */
9c2799c2 15302 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
15303 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15304 &do_align, 16, 16, 32, 32, -1);
15305 if (align_good == FAIL)
15306 return;
15307 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15308 {
15309 case 1: break;
15310 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 15311 default: first_error (_("bad list length")); return;
5287ad62
JB
15312 }
15313 inst.instruction |= neon_logbits (et.size) << 6;
15314 break;
15315
15316 case 1: /* VLD2. */
15317 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15318 &do_align, 8, 16, 16, 32, 32, 64, -1);
15319 if (align_good == FAIL)
15320 return;
15321 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15322 _("bad list length"));
15323 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15324 inst.instruction |= 1 << 5;
15325 inst.instruction |= neon_logbits (et.size) << 6;
15326 break;
15327
15328 case 2: /* VLD3. */
15329 constraint (inst.operands[1].immisalign,
15330 _("can't use alignment with this instruction"));
15331 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15332 _("bad list length"));
15333 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15334 inst.instruction |= 1 << 5;
15335 inst.instruction |= neon_logbits (et.size) << 6;
15336 break;
15337
15338 case 3: /* VLD4. */
15339 {
15340 int align = inst.operands[1].imm >> 8;
15341 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15342 16, 64, 32, 64, 32, 128, -1);
15343 if (align_good == FAIL)
15344 return;
15345 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15346 _("bad list length"));
15347 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15348 inst.instruction |= 1 << 5;
15349 if (et.size == 32 && align == 128)
15350 inst.instruction |= 0x3 << 6;
15351 else
15352 inst.instruction |= neon_logbits (et.size) << 6;
15353 }
15354 break;
15355
15356 default: ;
15357 }
15358
15359 inst.instruction |= do_align << 4;
15360}
15361
15362/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15363 apart from bits [11:4]. */
15364
15365static void
15366do_neon_ldx_stx (void)
15367{
b1a769ed
DG
15368 if (inst.operands[1].isreg)
15369 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15370
5287ad62
JB
15371 switch (NEON_LANE (inst.operands[0].imm))
15372 {
15373 case NEON_INTERLEAVE_LANES:
88714cb8 15374 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
15375 do_neon_ld_st_interleave ();
15376 break;
5f4273c7 15377
5287ad62 15378 case NEON_ALL_LANES:
88714cb8 15379 NEON_ENCODE (DUP, inst);
5287ad62
JB
15380 do_neon_ld_dup ();
15381 break;
5f4273c7 15382
5287ad62 15383 default:
88714cb8 15384 NEON_ENCODE (LANE, inst);
5287ad62
JB
15385 do_neon_ld_st_lane ();
15386 }
15387
15388 /* L bit comes from bit mask. */
15389 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15390 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15391 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 15392
5287ad62
JB
15393 if (inst.operands[1].postind)
15394 {
15395 int postreg = inst.operands[1].imm & 0xf;
15396 constraint (!inst.operands[1].immisreg,
15397 _("post-index must be a register"));
15398 constraint (postreg == 0xd || postreg == 0xf,
15399 _("bad register for post-index"));
15400 inst.instruction |= postreg;
15401 }
15402 else if (inst.operands[1].writeback)
15403 {
15404 inst.instruction |= 0xd;
15405 }
15406 else
5f4273c7
NC
15407 inst.instruction |= 0xf;
15408
5287ad62
JB
15409 if (thumb_mode)
15410 inst.instruction |= 0xf9000000;
15411 else
15412 inst.instruction |= 0xf4000000;
15413}
5287ad62
JB
15414\f
15415/* Overall per-instruction processing. */
15416
15417/* We need to be able to fix up arbitrary expressions in some statements.
15418 This is so that we can handle symbols that are an arbitrary distance from
15419 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
15420 which returns part of an address in a form which will be valid for
15421 a data instruction. We do this by pushing the expression into a symbol
15422 in the expr_section, and creating a fix for that. */
15423
15424static void
15425fix_new_arm (fragS * frag,
15426 int where,
15427 short int size,
15428 expressionS * exp,
15429 int pc_rel,
15430 int reloc)
15431{
15432 fixS * new_fix;
15433
15434 switch (exp->X_op)
15435 {
15436 case O_constant:
15437 case O_symbol:
15438 case O_add:
15439 case O_subtract:
21d799b5
NC
15440 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
15441 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15442 break;
15443
15444 default:
21d799b5
NC
15445 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
15446 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15447 break;
15448 }
15449
15450 /* Mark whether the fix is to a THUMB instruction, or an ARM
15451 instruction. */
15452 new_fix->tc_fix_data = thumb_mode;
15453}
15454
15455/* Create a frg for an instruction requiring relaxation. */
15456static void
15457output_relax_insn (void)
15458{
15459 char * to;
15460 symbolS *sym;
0110f2b8
PB
15461 int offset;
15462
6e1cb1a6
PB
15463 /* The size of the instruction is unknown, so tie the debug info to the
15464 start of the instruction. */
15465 dwarf2_emit_insn (0);
6e1cb1a6 15466
0110f2b8
PB
15467 switch (inst.reloc.exp.X_op)
15468 {
15469 case O_symbol:
15470 sym = inst.reloc.exp.X_add_symbol;
15471 offset = inst.reloc.exp.X_add_number;
15472 break;
15473 case O_constant:
15474 sym = NULL;
15475 offset = inst.reloc.exp.X_add_number;
15476 break;
15477 default:
15478 sym = make_expr_symbol (&inst.reloc.exp);
15479 offset = 0;
15480 break;
15481 }
15482 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15483 inst.relax, sym, offset, NULL/*offset, opcode*/);
15484 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
15485}
15486
15487/* Write a 32-bit thumb instruction to buf. */
15488static void
15489put_thumb32_insn (char * buf, unsigned long insn)
15490{
15491 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15492 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15493}
15494
b99bd4ef 15495static void
c19d1205 15496output_inst (const char * str)
b99bd4ef 15497{
c19d1205 15498 char * to = NULL;
b99bd4ef 15499
c19d1205 15500 if (inst.error)
b99bd4ef 15501 {
c19d1205 15502 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
15503 return;
15504 }
5f4273c7
NC
15505 if (inst.relax)
15506 {
15507 output_relax_insn ();
0110f2b8 15508 return;
5f4273c7 15509 }
c19d1205
ZW
15510 if (inst.size == 0)
15511 return;
b99bd4ef 15512
c19d1205 15513 to = frag_more (inst.size);
8dc2430f
NC
15514 /* PR 9814: Record the thumb mode into the current frag so that we know
15515 what type of NOP padding to use, if necessary. We override any previous
15516 setting so that if the mode has changed then the NOPS that we use will
15517 match the encoding of the last instruction in the frag. */
cd000bff 15518 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
15519
15520 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 15521 {
9c2799c2 15522 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 15523 put_thumb32_insn (to, inst.instruction);
b99bd4ef 15524 }
c19d1205 15525 else if (inst.size > INSN_SIZE)
b99bd4ef 15526 {
9c2799c2 15527 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
15528 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15529 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 15530 }
c19d1205
ZW
15531 else
15532 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 15533
c19d1205
ZW
15534 if (inst.reloc.type != BFD_RELOC_UNUSED)
15535 fix_new_arm (frag_now, to - frag_now->fr_literal,
15536 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15537 inst.reloc.type);
b99bd4ef 15538
c19d1205 15539 dwarf2_emit_insn (inst.size);
c19d1205 15540}
b99bd4ef 15541
e07e6e58
NC
15542static char *
15543output_it_inst (int cond, int mask, char * to)
15544{
15545 unsigned long instruction = 0xbf00;
15546
15547 mask &= 0xf;
15548 instruction |= mask;
15549 instruction |= cond << 4;
15550
15551 if (to == NULL)
15552 {
15553 to = frag_more (2);
15554#ifdef OBJ_ELF
15555 dwarf2_emit_insn (2);
15556#endif
15557 }
15558
15559 md_number_to_chars (to, instruction, 2);
15560
15561 return to;
15562}
15563
c19d1205
ZW
15564/* Tag values used in struct asm_opcode's tag field. */
15565enum opcode_tag
15566{
15567 OT_unconditional, /* Instruction cannot be conditionalized.
15568 The ARM condition field is still 0xE. */
15569 OT_unconditionalF, /* Instruction cannot be conditionalized
15570 and carries 0xF in its ARM condition field. */
15571 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
15572 OT_csuffixF, /* Some forms of the instruction take a conditional
15573 suffix, others place 0xF where the condition field
15574 would be. */
c19d1205
ZW
15575 OT_cinfix3, /* Instruction takes a conditional infix,
15576 beginning at character index 3. (In
15577 unified mode, it becomes a suffix.) */
088fa78e
KH
15578 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15579 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
15580 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15581 character index 3, even in unified mode. Used for
15582 legacy instructions where suffix and infix forms
15583 may be ambiguous. */
c19d1205 15584 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 15585 suffix or an infix at character index 3. */
c19d1205
ZW
15586 OT_odd_infix_unc, /* This is the unconditional variant of an
15587 instruction that takes a conditional infix
15588 at an unusual position. In unified mode,
15589 this variant will accept a suffix. */
15590 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15591 are the conditional variants of instructions that
15592 take conditional infixes in unusual positions.
15593 The infix appears at character index
15594 (tag - OT_odd_infix_0). These are not accepted
15595 in unified mode. */
15596};
b99bd4ef 15597
c19d1205
ZW
15598/* Subroutine of md_assemble, responsible for looking up the primary
15599 opcode from the mnemonic the user wrote. STR points to the
15600 beginning of the mnemonic.
15601
15602 This is not simply a hash table lookup, because of conditional
15603 variants. Most instructions have conditional variants, which are
15604 expressed with a _conditional affix_ to the mnemonic. If we were
15605 to encode each conditional variant as a literal string in the opcode
15606 table, it would have approximately 20,000 entries.
15607
15608 Most mnemonics take this affix as a suffix, and in unified syntax,
15609 'most' is upgraded to 'all'. However, in the divided syntax, some
15610 instructions take the affix as an infix, notably the s-variants of
15611 the arithmetic instructions. Of those instructions, all but six
15612 have the infix appear after the third character of the mnemonic.
15613
15614 Accordingly, the algorithm for looking up primary opcodes given
15615 an identifier is:
15616
15617 1. Look up the identifier in the opcode table.
15618 If we find a match, go to step U.
15619
15620 2. Look up the last two characters of the identifier in the
15621 conditions table. If we find a match, look up the first N-2
15622 characters of the identifier in the opcode table. If we
15623 find a match, go to step CE.
15624
15625 3. Look up the fourth and fifth characters of the identifier in
15626 the conditions table. If we find a match, extract those
15627 characters from the identifier, and look up the remaining
15628 characters in the opcode table. If we find a match, go
15629 to step CM.
15630
15631 4. Fail.
15632
15633 U. Examine the tag field of the opcode structure, in case this is
15634 one of the six instructions with its conditional infix in an
15635 unusual place. If it is, the tag tells us where to find the
15636 infix; look it up in the conditions table and set inst.cond
15637 accordingly. Otherwise, this is an unconditional instruction.
15638 Again set inst.cond accordingly. Return the opcode structure.
15639
15640 CE. Examine the tag field to make sure this is an instruction that
15641 should receive a conditional suffix. If it is not, fail.
15642 Otherwise, set inst.cond from the suffix we already looked up,
15643 and return the opcode structure.
15644
15645 CM. Examine the tag field to make sure this is an instruction that
15646 should receive a conditional infix after the third character.
15647 If it is not, fail. Otherwise, undo the edits to the current
15648 line of input and proceed as for case CE. */
15649
15650static const struct asm_opcode *
15651opcode_lookup (char **str)
15652{
15653 char *end, *base;
15654 char *affix;
15655 const struct asm_opcode *opcode;
15656 const struct asm_cond *cond;
e3cb604e 15657 char save[2];
c19d1205
ZW
15658
15659 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 15660 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 15661 for (base = end = *str; *end != '\0'; end++)
721a8186 15662 if (*end == ' ' || *end == '.')
c19d1205 15663 break;
b99bd4ef 15664
c19d1205 15665 if (end == base)
c921be7d 15666 return NULL;
b99bd4ef 15667
5287ad62 15668 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 15669 if (end[0] == '.')
b99bd4ef 15670 {
5287ad62 15671 int offset = 2;
5f4273c7 15672
267d2029
JB
15673 /* The .w and .n suffixes are only valid if the unified syntax is in
15674 use. */
15675 if (unified_syntax && end[1] == 'w')
c19d1205 15676 inst.size_req = 4;
267d2029 15677 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
15678 inst.size_req = 2;
15679 else
5287ad62
JB
15680 offset = 0;
15681
15682 inst.vectype.elems = 0;
15683
15684 *str = end + offset;
b99bd4ef 15685
5f4273c7 15686 if (end[offset] == '.')
5287ad62 15687 {
267d2029
JB
15688 /* See if we have a Neon type suffix (possible in either unified or
15689 non-unified ARM syntax mode). */
dcbf9037 15690 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 15691 return NULL;
5287ad62
JB
15692 }
15693 else if (end[offset] != '\0' && end[offset] != ' ')
c921be7d 15694 return NULL;
b99bd4ef 15695 }
c19d1205
ZW
15696 else
15697 *str = end;
b99bd4ef 15698
c19d1205 15699 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5
NC
15700 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15701 end - base);
c19d1205 15702 if (opcode)
b99bd4ef 15703 {
c19d1205
ZW
15704 /* step U */
15705 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 15706 {
c19d1205
ZW
15707 inst.cond = COND_ALWAYS;
15708 return opcode;
b99bd4ef 15709 }
b99bd4ef 15710
278df34e 15711 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
15712 as_warn (_("conditional infixes are deprecated in unified syntax"));
15713 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 15714 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 15715 gas_assert (cond);
b99bd4ef 15716
c19d1205
ZW
15717 inst.cond = cond->value;
15718 return opcode;
15719 }
b99bd4ef 15720
c19d1205
ZW
15721 /* Cannot have a conditional suffix on a mnemonic of less than two
15722 characters. */
15723 if (end - base < 3)
c921be7d 15724 return NULL;
b99bd4ef 15725
c19d1205
ZW
15726 /* Look for suffixed mnemonic. */
15727 affix = end - 2;
21d799b5
NC
15728 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15729 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15730 affix - base);
c19d1205
ZW
15731 if (opcode && cond)
15732 {
15733 /* step CE */
15734 switch (opcode->tag)
15735 {
e3cb604e
PB
15736 case OT_cinfix3_legacy:
15737 /* Ignore conditional suffixes matched on infix only mnemonics. */
15738 break;
15739
c19d1205 15740 case OT_cinfix3:
088fa78e 15741 case OT_cinfix3_deprecated:
c19d1205
ZW
15742 case OT_odd_infix_unc:
15743 if (!unified_syntax)
e3cb604e 15744 return 0;
c19d1205
ZW
15745 /* else fall through */
15746
15747 case OT_csuffix:
037e8744 15748 case OT_csuffixF:
c19d1205
ZW
15749 case OT_csuf_or_in3:
15750 inst.cond = cond->value;
15751 return opcode;
15752
15753 case OT_unconditional:
15754 case OT_unconditionalF:
dfa9f0d5 15755 if (thumb_mode)
c921be7d 15756 inst.cond = cond->value;
dfa9f0d5
PB
15757 else
15758 {
c921be7d 15759 /* Delayed diagnostic. */
dfa9f0d5
PB
15760 inst.error = BAD_COND;
15761 inst.cond = COND_ALWAYS;
15762 }
c19d1205 15763 return opcode;
b99bd4ef 15764
c19d1205 15765 default:
c921be7d 15766 return NULL;
c19d1205
ZW
15767 }
15768 }
b99bd4ef 15769
c19d1205
ZW
15770 /* Cannot have a usual-position infix on a mnemonic of less than
15771 six characters (five would be a suffix). */
15772 if (end - base < 6)
c921be7d 15773 return NULL;
b99bd4ef 15774
c19d1205
ZW
15775 /* Look for infixed mnemonic in the usual position. */
15776 affix = base + 3;
21d799b5 15777 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 15778 if (!cond)
c921be7d 15779 return NULL;
e3cb604e
PB
15780
15781 memcpy (save, affix, 2);
15782 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5
NC
15783 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15784 (end - base) - 2);
e3cb604e
PB
15785 memmove (affix + 2, affix, (end - affix) - 2);
15786 memcpy (affix, save, 2);
15787
088fa78e
KH
15788 if (opcode
15789 && (opcode->tag == OT_cinfix3
15790 || opcode->tag == OT_cinfix3_deprecated
15791 || opcode->tag == OT_csuf_or_in3
15792 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 15793 {
c921be7d 15794 /* Step CM. */
278df34e 15795 if (warn_on_deprecated && unified_syntax
088fa78e
KH
15796 && (opcode->tag == OT_cinfix3
15797 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
15798 as_warn (_("conditional infixes are deprecated in unified syntax"));
15799
15800 inst.cond = cond->value;
15801 return opcode;
b99bd4ef
NC
15802 }
15803
c921be7d 15804 return NULL;
b99bd4ef
NC
15805}
15806
e07e6e58
NC
15807/* This function generates an initial IT instruction, leaving its block
15808 virtually open for the new instructions. Eventually,
15809 the mask will be updated by now_it_add_mask () each time
15810 a new instruction needs to be included in the IT block.
15811 Finally, the block is closed with close_automatic_it_block ().
15812 The block closure can be requested either from md_assemble (),
15813 a tencode (), or due to a label hook. */
15814
15815static void
15816new_automatic_it_block (int cond)
15817{
15818 now_it.state = AUTOMATIC_IT_BLOCK;
15819 now_it.mask = 0x18;
15820 now_it.cc = cond;
15821 now_it.block_length = 1;
cd000bff 15822 mapping_state (MAP_THUMB);
e07e6e58
NC
15823 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15824}
15825
15826/* Close an automatic IT block.
15827 See comments in new_automatic_it_block (). */
15828
15829static void
15830close_automatic_it_block (void)
15831{
15832 now_it.mask = 0x10;
15833 now_it.block_length = 0;
15834}
15835
15836/* Update the mask of the current automatically-generated IT
15837 instruction. See comments in new_automatic_it_block (). */
15838
15839static void
15840now_it_add_mask (int cond)
15841{
15842#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15843#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15844 | ((bitvalue) << (nbit)))
e07e6e58 15845 const int resulting_bit = (cond & 1);
c921be7d 15846
e07e6e58
NC
15847 now_it.mask &= 0xf;
15848 now_it.mask = SET_BIT_VALUE (now_it.mask,
15849 resulting_bit,
15850 (5 - now_it.block_length));
15851 now_it.mask = SET_BIT_VALUE (now_it.mask,
15852 1,
15853 ((5 - now_it.block_length) - 1) );
15854 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15855
15856#undef CLEAR_BIT
15857#undef SET_BIT_VALUE
e07e6e58
NC
15858}
15859
15860/* The IT blocks handling machinery is accessed through the these functions:
15861 it_fsm_pre_encode () from md_assemble ()
15862 set_it_insn_type () optional, from the tencode functions
15863 set_it_insn_type_last () ditto
15864 in_it_block () ditto
15865 it_fsm_post_encode () from md_assemble ()
15866 force_automatic_it_block_close () from label habdling functions
15867
15868 Rationale:
15869 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15870 initializing the IT insn type with a generic initial value depending
15871 on the inst.condition.
15872 2) During the tencode function, two things may happen:
15873 a) The tencode function overrides the IT insn type by
15874 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15875 b) The tencode function queries the IT block state by
15876 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15877
15878 Both set_it_insn_type and in_it_block run the internal FSM state
15879 handling function (handle_it_state), because: a) setting the IT insn
15880 type may incur in an invalid state (exiting the function),
15881 and b) querying the state requires the FSM to be updated.
15882 Specifically we want to avoid creating an IT block for conditional
15883 branches, so it_fsm_pre_encode is actually a guess and we can't
15884 determine whether an IT block is required until the tencode () routine
15885 has decided what type of instruction this actually it.
15886 Because of this, if set_it_insn_type and in_it_block have to be used,
15887 set_it_insn_type has to be called first.
15888
15889 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15890 determines the insn IT type depending on the inst.cond code.
15891 When a tencode () routine encodes an instruction that can be
15892 either outside an IT block, or, in the case of being inside, has to be
15893 the last one, set_it_insn_type_last () will determine the proper
15894 IT instruction type based on the inst.cond code. Otherwise,
15895 set_it_insn_type can be called for overriding that logic or
15896 for covering other cases.
15897
15898 Calling handle_it_state () may not transition the IT block state to
15899 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15900 still queried. Instead, if the FSM determines that the state should
15901 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15902 after the tencode () function: that's what it_fsm_post_encode () does.
15903
15904 Since in_it_block () calls the state handling function to get an
15905 updated state, an error may occur (due to invalid insns combination).
15906 In that case, inst.error is set.
15907 Therefore, inst.error has to be checked after the execution of
15908 the tencode () routine.
15909
15910 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15911 any pending state change (if any) that didn't take place in
15912 handle_it_state () as explained above. */
15913
15914static void
15915it_fsm_pre_encode (void)
15916{
15917 if (inst.cond != COND_ALWAYS)
15918 inst.it_insn_type = INSIDE_IT_INSN;
15919 else
15920 inst.it_insn_type = OUTSIDE_IT_INSN;
15921
15922 now_it.state_handled = 0;
15923}
15924
15925/* IT state FSM handling function. */
15926
15927static int
15928handle_it_state (void)
15929{
15930 now_it.state_handled = 1;
15931
15932 switch (now_it.state)
15933 {
15934 case OUTSIDE_IT_BLOCK:
15935 switch (inst.it_insn_type)
15936 {
15937 case OUTSIDE_IT_INSN:
15938 break;
15939
15940 case INSIDE_IT_INSN:
15941 case INSIDE_IT_LAST_INSN:
15942 if (thumb_mode == 0)
15943 {
c921be7d 15944 if (unified_syntax
e07e6e58
NC
15945 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15946 as_tsktsk (_("Warning: conditional outside an IT block"\
15947 " for Thumb."));
15948 }
15949 else
15950 {
15951 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15952 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15953 {
15954 /* Automatically generate the IT instruction. */
15955 new_automatic_it_block (inst.cond);
15956 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15957 close_automatic_it_block ();
15958 }
15959 else
15960 {
15961 inst.error = BAD_OUT_IT;
15962 return FAIL;
15963 }
15964 }
15965 break;
15966
15967 case IF_INSIDE_IT_LAST_INSN:
15968 case NEUTRAL_IT_INSN:
15969 break;
15970
15971 case IT_INSN:
15972 now_it.state = MANUAL_IT_BLOCK;
15973 now_it.block_length = 0;
15974 break;
15975 }
15976 break;
15977
15978 case AUTOMATIC_IT_BLOCK:
15979 /* Three things may happen now:
15980 a) We should increment current it block size;
15981 b) We should close current it block (closing insn or 4 insns);
15982 c) We should close current it block and start a new one (due
15983 to incompatible conditions or
15984 4 insns-length block reached). */
15985
15986 switch (inst.it_insn_type)
15987 {
15988 case OUTSIDE_IT_INSN:
15989 /* The closure of the block shall happen immediatelly,
15990 so any in_it_block () call reports the block as closed. */
15991 force_automatic_it_block_close ();
15992 break;
15993
15994 case INSIDE_IT_INSN:
15995 case INSIDE_IT_LAST_INSN:
15996 case IF_INSIDE_IT_LAST_INSN:
15997 now_it.block_length++;
15998
15999 if (now_it.block_length > 4
16000 || !now_it_compatible (inst.cond))
16001 {
16002 force_automatic_it_block_close ();
16003 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
16004 new_automatic_it_block (inst.cond);
16005 }
16006 else
16007 {
16008 now_it_add_mask (inst.cond);
16009 }
16010
16011 if (now_it.state == AUTOMATIC_IT_BLOCK
16012 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
16013 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
16014 close_automatic_it_block ();
16015 break;
16016
16017 case NEUTRAL_IT_INSN:
16018 now_it.block_length++;
16019
16020 if (now_it.block_length > 4)
16021 force_automatic_it_block_close ();
16022 else
16023 now_it_add_mask (now_it.cc & 1);
16024 break;
16025
16026 case IT_INSN:
16027 close_automatic_it_block ();
16028 now_it.state = MANUAL_IT_BLOCK;
16029 break;
16030 }
16031 break;
16032
16033 case MANUAL_IT_BLOCK:
16034 {
16035 /* Check conditional suffixes. */
16036 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
16037 int is_last;
16038 now_it.mask <<= 1;
16039 now_it.mask &= 0x1f;
16040 is_last = (now_it.mask == 0x10);
16041
16042 switch (inst.it_insn_type)
16043 {
16044 case OUTSIDE_IT_INSN:
16045 inst.error = BAD_NOT_IT;
16046 return FAIL;
16047
16048 case INSIDE_IT_INSN:
16049 if (cond != inst.cond)
16050 {
16051 inst.error = BAD_IT_COND;
16052 return FAIL;
16053 }
16054 break;
16055
16056 case INSIDE_IT_LAST_INSN:
16057 case IF_INSIDE_IT_LAST_INSN:
16058 if (cond != inst.cond)
16059 {
16060 inst.error = BAD_IT_COND;
16061 return FAIL;
16062 }
16063 if (!is_last)
16064 {
16065 inst.error = BAD_BRANCH;
16066 return FAIL;
16067 }
16068 break;
16069
16070 case NEUTRAL_IT_INSN:
16071 /* The BKPT instruction is unconditional even in an IT block. */
16072 break;
16073
16074 case IT_INSN:
16075 inst.error = BAD_IT_IT;
16076 return FAIL;
16077 }
16078 }
16079 break;
16080 }
16081
16082 return SUCCESS;
16083}
16084
16085static void
16086it_fsm_post_encode (void)
16087{
16088 int is_last;
16089
16090 if (!now_it.state_handled)
16091 handle_it_state ();
16092
16093 is_last = (now_it.mask == 0x10);
16094 if (is_last)
16095 {
16096 now_it.state = OUTSIDE_IT_BLOCK;
16097 now_it.mask = 0;
16098 }
16099}
16100
16101static void
16102force_automatic_it_block_close (void)
16103{
16104 if (now_it.state == AUTOMATIC_IT_BLOCK)
16105 {
16106 close_automatic_it_block ();
16107 now_it.state = OUTSIDE_IT_BLOCK;
16108 now_it.mask = 0;
16109 }
16110}
16111
16112static int
16113in_it_block (void)
16114{
16115 if (!now_it.state_handled)
16116 handle_it_state ();
16117
16118 return now_it.state != OUTSIDE_IT_BLOCK;
16119}
16120
c19d1205
ZW
16121void
16122md_assemble (char *str)
b99bd4ef 16123{
c19d1205
ZW
16124 char *p = str;
16125 const struct asm_opcode * opcode;
b99bd4ef 16126
c19d1205
ZW
16127 /* Align the previous label if needed. */
16128 if (last_label_seen != NULL)
b99bd4ef 16129 {
c19d1205
ZW
16130 symbol_set_frag (last_label_seen, frag_now);
16131 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
16132 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
16133 }
16134
c19d1205
ZW
16135 memset (&inst, '\0', sizeof (inst));
16136 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 16137
c19d1205
ZW
16138 opcode = opcode_lookup (&p);
16139 if (!opcode)
b99bd4ef 16140 {
c19d1205 16141 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 16142 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d
NC
16143 if (! create_register_alias (str, p)
16144 && ! create_neon_reg_alias (str, p))
c19d1205 16145 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 16146
b99bd4ef
NC
16147 return;
16148 }
16149
278df34e 16150 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
16151 as_warn (_("s suffix on comparison instruction is deprecated"));
16152
037e8744
JB
16153 /* The value which unconditional instructions should have in place of the
16154 condition field. */
16155 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
16156
c19d1205 16157 if (thumb_mode)
b99bd4ef 16158 {
e74cfd16 16159 arm_feature_set variant;
8f06b2d8
PB
16160
16161 variant = cpu_variant;
16162 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
16163 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
16164 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 16165 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
16166 if (!opcode->tvariant
16167 || (thumb_mode == 1
16168 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 16169 {
bf3eeda7 16170 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
b99bd4ef
NC
16171 return;
16172 }
c19d1205
ZW
16173 if (inst.cond != COND_ALWAYS && !unified_syntax
16174 && opcode->tencode != do_t_branch)
b99bd4ef 16175 {
c19d1205 16176 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
16177 return;
16178 }
16179
752d5da4 16180 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 16181 {
7e806470 16182 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
16183 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
16184 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
16185 {
16186 /* Two things are addressed here.
16187 1) Implicit require narrow instructions on Thumb-1.
16188 This avoids relaxation accidentally introducing Thumb-2
16189 instructions.
16190 2) Reject wide instructions in non Thumb-2 cores. */
16191 if (inst.size_req == 0)
16192 inst.size_req = 2;
16193 else if (inst.size_req == 4)
16194 {
bf3eeda7 16195 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
752d5da4
NC
16196 return;
16197 }
16198 }
076d447c
PB
16199 }
16200
c19d1205
ZW
16201 inst.instruction = opcode->tvalue;
16202
5be8be5d 16203 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
e07e6e58
NC
16204 {
16205 /* Prepare the it_insn_type for those encodings that don't set
16206 it. */
16207 it_fsm_pre_encode ();
c19d1205 16208
e07e6e58
NC
16209 opcode->tencode ();
16210
16211 it_fsm_post_encode ();
16212 }
e27ec89e 16213
0110f2b8 16214 if (!(inst.error || inst.relax))
b99bd4ef 16215 {
9c2799c2 16216 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
16217 inst.size = (inst.instruction > 0xffff ? 4 : 2);
16218 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 16219 {
c19d1205 16220 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
16221 return;
16222 }
16223 }
076d447c
PB
16224
16225 /* Something has gone badly wrong if we try to relax a fixed size
16226 instruction. */
9c2799c2 16227 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 16228
e74cfd16
PB
16229 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16230 *opcode->tvariant);
ee065d83 16231 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 16232 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 16233 anything other than bl/blx and v6-M instructions.
ee065d83 16234 This is overly pessimistic for relaxable instructions. */
7e806470
PB
16235 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
16236 || inst.relax)
e07e6e58
NC
16237 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
16238 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
16239 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16240 arm_ext_v6t2);
cd000bff 16241
88714cb8
DG
16242 check_neon_suffixes;
16243
cd000bff 16244 if (!inst.error)
c877a2f2
NC
16245 {
16246 mapping_state (MAP_THUMB);
16247 }
c19d1205 16248 }
3e9e4fcf 16249 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 16250 {
845b51d6
PB
16251 bfd_boolean is_bx;
16252
16253 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
16254 is_bx = (opcode->aencode == do_bx);
16255
c19d1205 16256 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
16257 if (!(is_bx && fix_v4bx)
16258 && !(opcode->avariant &&
16259 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 16260 {
bf3eeda7 16261 as_bad (_("selected processor does not support ARM mode `%s'"), str);
c19d1205 16262 return;
b99bd4ef 16263 }
c19d1205 16264 if (inst.size_req)
b99bd4ef 16265 {
c19d1205
ZW
16266 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
16267 return;
b99bd4ef
NC
16268 }
16269
c19d1205
ZW
16270 inst.instruction = opcode->avalue;
16271 if (opcode->tag == OT_unconditionalF)
16272 inst.instruction |= 0xF << 28;
16273 else
16274 inst.instruction |= inst.cond << 28;
16275 inst.size = INSN_SIZE;
5be8be5d 16276 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
e07e6e58
NC
16277 {
16278 it_fsm_pre_encode ();
16279 opcode->aencode ();
16280 it_fsm_post_encode ();
16281 }
ee065d83
PB
16282 /* Arm mode bx is marked as both v4T and v5 because it's still required
16283 on a hypothetical non-thumb v5 core. */
845b51d6 16284 if (is_bx)
e74cfd16 16285 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 16286 else
e74cfd16
PB
16287 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
16288 *opcode->avariant);
88714cb8
DG
16289
16290 check_neon_suffixes;
16291
cd000bff 16292 if (!inst.error)
c877a2f2
NC
16293 {
16294 mapping_state (MAP_ARM);
16295 }
b99bd4ef 16296 }
3e9e4fcf
JB
16297 else
16298 {
16299 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
16300 "-- `%s'"), str);
16301 return;
16302 }
c19d1205
ZW
16303 output_inst (str);
16304}
b99bd4ef 16305
e07e6e58
NC
16306static void
16307check_it_blocks_finished (void)
16308{
16309#ifdef OBJ_ELF
16310 asection *sect;
16311
16312 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
16313 if (seg_info (sect)->tc_segment_info_data.current_it.state
16314 == MANUAL_IT_BLOCK)
16315 {
16316 as_warn (_("section '%s' finished with an open IT block."),
16317 sect->name);
16318 }
16319#else
16320 if (now_it.state == MANUAL_IT_BLOCK)
16321 as_warn (_("file finished with an open IT block."));
16322#endif
16323}
16324
c19d1205
ZW
16325/* Various frobbings of labels and their addresses. */
16326
16327void
16328arm_start_line_hook (void)
16329{
16330 last_label_seen = NULL;
b99bd4ef
NC
16331}
16332
c19d1205
ZW
16333void
16334arm_frob_label (symbolS * sym)
b99bd4ef 16335{
c19d1205 16336 last_label_seen = sym;
b99bd4ef 16337
c19d1205 16338 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 16339
c19d1205
ZW
16340#if defined OBJ_COFF || defined OBJ_ELF
16341 ARM_SET_INTERWORK (sym, support_interwork);
16342#endif
b99bd4ef 16343
e07e6e58
NC
16344 force_automatic_it_block_close ();
16345
5f4273c7 16346 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
16347 as Thumb functions. This is because these labels, whilst
16348 they exist inside Thumb code, are not the entry points for
16349 possible ARM->Thumb calls. Also, these labels can be used
16350 as part of a computed goto or switch statement. eg gcc
16351 can generate code that looks like this:
b99bd4ef 16352
c19d1205
ZW
16353 ldr r2, [pc, .Laaa]
16354 lsl r3, r3, #2
16355 ldr r2, [r3, r2]
16356 mov pc, r2
b99bd4ef 16357
c19d1205
ZW
16358 .Lbbb: .word .Lxxx
16359 .Lccc: .word .Lyyy
16360 ..etc...
16361 .Laaa: .word Lbbb
b99bd4ef 16362
c19d1205
ZW
16363 The first instruction loads the address of the jump table.
16364 The second instruction converts a table index into a byte offset.
16365 The third instruction gets the jump address out of the table.
16366 The fourth instruction performs the jump.
b99bd4ef 16367
c19d1205
ZW
16368 If the address stored at .Laaa is that of a symbol which has the
16369 Thumb_Func bit set, then the linker will arrange for this address
16370 to have the bottom bit set, which in turn would mean that the
16371 address computation performed by the third instruction would end
16372 up with the bottom bit set. Since the ARM is capable of unaligned
16373 word loads, the instruction would then load the incorrect address
16374 out of the jump table, and chaos would ensue. */
16375 if (label_is_thumb_function_name
16376 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
16377 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 16378 {
c19d1205
ZW
16379 /* When the address of a Thumb function is taken the bottom
16380 bit of that address should be set. This will allow
16381 interworking between Arm and Thumb functions to work
16382 correctly. */
b99bd4ef 16383
c19d1205 16384 THUMB_SET_FUNC (sym, 1);
b99bd4ef 16385
c19d1205 16386 label_is_thumb_function_name = FALSE;
b99bd4ef 16387 }
07a53e5c 16388
07a53e5c 16389 dwarf2_emit_label (sym);
b99bd4ef
NC
16390}
16391
c921be7d 16392bfd_boolean
c19d1205 16393arm_data_in_code (void)
b99bd4ef 16394{
c19d1205 16395 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 16396 {
c19d1205
ZW
16397 *input_line_pointer = '/';
16398 input_line_pointer += 5;
16399 *input_line_pointer = 0;
c921be7d 16400 return TRUE;
b99bd4ef
NC
16401 }
16402
c921be7d 16403 return FALSE;
b99bd4ef
NC
16404}
16405
c19d1205
ZW
16406char *
16407arm_canonicalize_symbol_name (char * name)
b99bd4ef 16408{
c19d1205 16409 int len;
b99bd4ef 16410
c19d1205
ZW
16411 if (thumb_mode && (len = strlen (name)) > 5
16412 && streq (name + len - 5, "/data"))
16413 *(name + len - 5) = 0;
b99bd4ef 16414
c19d1205 16415 return name;
b99bd4ef 16416}
c19d1205
ZW
16417\f
16418/* Table of all register names defined by default. The user can
16419 define additional names with .req. Note that all register names
16420 should appear in both upper and lowercase variants. Some registers
16421 also have mixed-case names. */
b99bd4ef 16422
dcbf9037 16423#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 16424#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 16425#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
16426#define REGSET(p,t) \
16427 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
16428 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
16429 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
16430 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
16431#define REGSETH(p,t) \
16432 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
16433 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
16434 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
16435 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
16436#define REGSET2(p,t) \
16437 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
16438 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
16439 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
16440 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
16441#define SPLRBANK(base,bank,t) \
16442 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
16443 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
16444 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
16445 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
16446 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
16447 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 16448
c19d1205 16449static const struct reg_entry reg_names[] =
7ed4c4c5 16450{
c19d1205
ZW
16451 /* ARM integer registers. */
16452 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 16453
c19d1205
ZW
16454 /* ATPCS synonyms. */
16455 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
16456 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16457 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 16458
c19d1205
ZW
16459 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16460 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16461 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 16462
c19d1205
ZW
16463 /* Well-known aliases. */
16464 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16465 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16466
16467 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16468 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16469
16470 /* Coprocessor numbers. */
16471 REGSET(p, CP), REGSET(P, CP),
16472
16473 /* Coprocessor register numbers. The "cr" variants are for backward
16474 compatibility. */
16475 REGSET(c, CN), REGSET(C, CN),
16476 REGSET(cr, CN), REGSET(CR, CN),
16477
90ec0d68
MGD
16478 /* ARM banked registers. */
16479 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
16480 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
16481 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
16482 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
16483 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
16484 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
16485 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
16486
16487 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
16488 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
16489 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
16490 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
16491 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
16492 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB),
16493 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
16494 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
16495
16496 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
16497 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
16498 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
16499 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
16500 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
16501 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
16502 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
16503 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
16504 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
16505
c19d1205
ZW
16506 /* FPA registers. */
16507 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16508 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16509
16510 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16511 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16512
16513 /* VFP SP registers. */
5287ad62
JB
16514 REGSET(s,VFS), REGSET(S,VFS),
16515 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
16516
16517 /* VFP DP Registers. */
5287ad62
JB
16518 REGSET(d,VFD), REGSET(D,VFD),
16519 /* Extra Neon DP registers. */
16520 REGSETH(d,VFD), REGSETH(D,VFD),
16521
16522 /* Neon QP registers. */
16523 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
16524
16525 /* VFP control registers. */
16526 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16527 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
16528 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16529 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16530 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16531 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
16532
16533 /* Maverick DSP coprocessor registers. */
16534 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16535 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16536
16537 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16538 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16539 REGDEF(dspsc,0,DSPSC),
16540
16541 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16542 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16543 REGDEF(DSPSC,0,DSPSC),
16544
16545 /* iWMMXt data registers - p0, c0-15. */
16546 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16547
16548 /* iWMMXt control registers - p1, c0-3. */
16549 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16550 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16551 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16552 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16553
16554 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16555 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16556 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16557 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16558 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16559
16560 /* XScale accumulator registers. */
16561 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16562};
16563#undef REGDEF
16564#undef REGNUM
16565#undef REGSET
7ed4c4c5 16566
c19d1205
ZW
16567/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16568 within psr_required_here. */
16569static const struct asm_psr psrs[] =
16570{
16571 /* Backward compatibility notation. Note that "all" is no longer
16572 truly all possible PSR bits. */
16573 {"all", PSR_c | PSR_f},
16574 {"flg", PSR_f},
16575 {"ctl", PSR_c},
16576
16577 /* Individual flags. */
16578 {"f", PSR_f},
16579 {"c", PSR_c},
16580 {"x", PSR_x},
16581 {"s", PSR_s},
59b42a0d 16582
c19d1205
ZW
16583 /* Combinations of flags. */
16584 {"fs", PSR_f | PSR_s},
16585 {"fx", PSR_f | PSR_x},
16586 {"fc", PSR_f | PSR_c},
16587 {"sf", PSR_s | PSR_f},
16588 {"sx", PSR_s | PSR_x},
16589 {"sc", PSR_s | PSR_c},
16590 {"xf", PSR_x | PSR_f},
16591 {"xs", PSR_x | PSR_s},
16592 {"xc", PSR_x | PSR_c},
16593 {"cf", PSR_c | PSR_f},
16594 {"cs", PSR_c | PSR_s},
16595 {"cx", PSR_c | PSR_x},
16596 {"fsx", PSR_f | PSR_s | PSR_x},
16597 {"fsc", PSR_f | PSR_s | PSR_c},
16598 {"fxs", PSR_f | PSR_x | PSR_s},
16599 {"fxc", PSR_f | PSR_x | PSR_c},
16600 {"fcs", PSR_f | PSR_c | PSR_s},
16601 {"fcx", PSR_f | PSR_c | PSR_x},
16602 {"sfx", PSR_s | PSR_f | PSR_x},
16603 {"sfc", PSR_s | PSR_f | PSR_c},
16604 {"sxf", PSR_s | PSR_x | PSR_f},
16605 {"sxc", PSR_s | PSR_x | PSR_c},
16606 {"scf", PSR_s | PSR_c | PSR_f},
16607 {"scx", PSR_s | PSR_c | PSR_x},
16608 {"xfs", PSR_x | PSR_f | PSR_s},
16609 {"xfc", PSR_x | PSR_f | PSR_c},
16610 {"xsf", PSR_x | PSR_s | PSR_f},
16611 {"xsc", PSR_x | PSR_s | PSR_c},
16612 {"xcf", PSR_x | PSR_c | PSR_f},
16613 {"xcs", PSR_x | PSR_c | PSR_s},
16614 {"cfs", PSR_c | PSR_f | PSR_s},
16615 {"cfx", PSR_c | PSR_f | PSR_x},
16616 {"csf", PSR_c | PSR_s | PSR_f},
16617 {"csx", PSR_c | PSR_s | PSR_x},
16618 {"cxf", PSR_c | PSR_x | PSR_f},
16619 {"cxs", PSR_c | PSR_x | PSR_s},
16620 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16621 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16622 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16623 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16624 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16625 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16626 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16627 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16628 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16629 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16630 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16631 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16632 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16633 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16634 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16635 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16636 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16637 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16638 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16639 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16640 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16641 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16642 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16643 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16644};
16645
62b3e311
PB
16646/* Table of V7M psr names. */
16647static const struct asm_psr v7m_psrs[] =
16648{
2b744c99
PB
16649 {"apsr", 0 }, {"APSR", 0 },
16650 {"iapsr", 1 }, {"IAPSR", 1 },
16651 {"eapsr", 2 }, {"EAPSR", 2 },
16652 {"psr", 3 }, {"PSR", 3 },
16653 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16654 {"ipsr", 5 }, {"IPSR", 5 },
16655 {"epsr", 6 }, {"EPSR", 6 },
16656 {"iepsr", 7 }, {"IEPSR", 7 },
16657 {"msp", 8 }, {"MSP", 8 },
16658 {"psp", 9 }, {"PSP", 9 },
16659 {"primask", 16}, {"PRIMASK", 16},
16660 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
16661 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16662 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99
PB
16663 {"faultmask", 19}, {"FAULTMASK", 19},
16664 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
16665};
16666
c19d1205
ZW
16667/* Table of all shift-in-operand names. */
16668static const struct asm_shift_name shift_names [] =
b99bd4ef 16669{
c19d1205
ZW
16670 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16671 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16672 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16673 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16674 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16675 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16676};
b99bd4ef 16677
c19d1205
ZW
16678/* Table of all explicit relocation names. */
16679#ifdef OBJ_ELF
16680static struct reloc_entry reloc_names[] =
16681{
16682 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16683 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16684 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16685 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16686 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16687 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16688 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16689 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16690 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16691 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 16692 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
16693 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
16694 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
16695 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
16696 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
16697 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
16698 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
16699 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
16700};
16701#endif
b99bd4ef 16702
c19d1205
ZW
16703/* Table of all conditional affixes. 0xF is not defined as a condition code. */
16704static const struct asm_cond conds[] =
16705{
16706 {"eq", 0x0},
16707 {"ne", 0x1},
16708 {"cs", 0x2}, {"hs", 0x2},
16709 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16710 {"mi", 0x4},
16711 {"pl", 0x5},
16712 {"vs", 0x6},
16713 {"vc", 0x7},
16714 {"hi", 0x8},
16715 {"ls", 0x9},
16716 {"ge", 0xa},
16717 {"lt", 0xb},
16718 {"gt", 0xc},
16719 {"le", 0xd},
16720 {"al", 0xe}
16721};
bfae80f2 16722
62b3e311
PB
16723static struct asm_barrier_opt barrier_opt_names[] =
16724{
52e7f43d
RE
16725 { "sy", 0xf }, { "SY", 0xf },
16726 { "un", 0x7 }, { "UN", 0x7 },
16727 { "st", 0xe }, { "ST", 0xe },
16728 { "unst", 0x6 }, { "UNST", 0x6 },
16729 { "ish", 0xb }, { "ISH", 0xb },
16730 { "sh", 0xb }, { "SH", 0xb },
16731 { "ishst", 0xa }, { "ISHST", 0xa },
16732 { "shst", 0xa }, { "SHST", 0xa },
16733 { "nsh", 0x7 }, { "NSH", 0x7 },
16734 { "nshst", 0x6 }, { "NSHST", 0x6 },
16735 { "osh", 0x3 }, { "OSH", 0x3 },
16736 { "oshst", 0x2 }, { "OSHST", 0x2 }
62b3e311
PB
16737};
16738
c19d1205
ZW
16739/* Table of ARM-format instructions. */
16740
16741/* Macros for gluing together operand strings. N.B. In all cases
16742 other than OPS0, the trailing OP_stop comes from default
16743 zero-initialization of the unspecified elements of the array. */
16744#define OPS0() { OP_stop, }
16745#define OPS1(a) { OP_##a, }
16746#define OPS2(a,b) { OP_##a,OP_##b, }
16747#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16748#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16749#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16750#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16751
5be8be5d
DG
16752/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16753 This is useful when mixing operands for ARM and THUMB, i.e. using the
16754 MIX_ARM_THUMB_OPERANDS macro.
16755 In order to use these macros, prefix the number of operands with _
16756 e.g. _3. */
16757#define OPS_1(a) { a, }
16758#define OPS_2(a,b) { a,b, }
16759#define OPS_3(a,b,c) { a,b,c, }
16760#define OPS_4(a,b,c,d) { a,b,c,d, }
16761#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16762#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16763
c19d1205
ZW
16764/* These macros abstract out the exact format of the mnemonic table and
16765 save some repeated characters. */
16766
16767/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16768#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16769 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 16770 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16771
16772/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16773 a T_MNEM_xyz enumerator. */
16774#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16775 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16776#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16777 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16778
16779/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16780 infix after the third character. */
16781#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 16782 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 16783 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 16784#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 16785 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 16786 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 16787#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16788 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 16789#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16790 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16791#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16792 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 16793#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16794 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16795
16796/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16797 appear in the condition table. */
16798#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
21d799b5 16799 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
1887dd22 16800 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16801
16802#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
16803 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16804 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16805 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16806 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16807 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16808 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16809 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16810 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16811 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16812 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16813 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16814 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16815 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16816 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16817 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16818 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16819 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16820 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16821 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
16822
16823#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
16824 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16825#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
21d799b5 16826 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16827
16828/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
16829 field is still 0xE. Many of the Thumb variants can be executed
16830 conditionally, so this is checked separately. */
c19d1205 16831#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16832 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16833 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16834
16835/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16836 condition code field. */
16837#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 16838 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16839 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16840
16841/* ARM-only variants of all the above. */
6a86118a 16842#define CE(mnem, op, nops, ops, ae) \
21d799b5 16843 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
16844
16845#define C3(mnem, op, nops, ops, ae) \
16846 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16847
e3cb604e
PB
16848/* Legacy mnemonics that always have conditional infix after the third
16849 character. */
16850#define CL(mnem, op, nops, ops, ae) \
21d799b5 16851 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16852 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16853
8f06b2d8
PB
16854/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16855#define cCE(mnem, op, nops, ops, ae) \
21d799b5 16856 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16857
e3cb604e
PB
16858/* Legacy coprocessor instructions where conditional infix and conditional
16859 suffix are ambiguous. For consistency this includes all FPA instructions,
16860 not just the potentially ambiguous ones. */
16861#define cCL(mnem, op, nops, ops, ae) \
21d799b5 16862 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16863 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16864
16865/* Coprocessor, takes either a suffix or a position-3 infix
16866 (for an FPA corner case). */
16867#define C3E(mnem, op, nops, ops, ae) \
21d799b5 16868 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 16869 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16870
6a86118a 16871#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
16872 { m1 #m2 m3, OPS##nops ops, \
16873 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
16874 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16875
16876#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
16877 xCM_ (m1, , m2, op, nops, ops, ae), \
16878 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16879 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16880 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16881 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16882 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16883 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16884 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16885 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16886 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16887 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16888 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16889 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16890 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16891 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16892 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16893 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16894 xCM_ (m1, le, m2, op, nops, ops, ae), \
16895 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
16896
16897#define UE(mnem, op, nops, ops, ae) \
16898 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16899
16900#define UF(mnem, op, nops, ops, ae) \
16901 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16902
5287ad62
JB
16903/* Neon data-processing. ARM versions are unconditional with cond=0xf.
16904 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16905 use the same encoding function for each. */
16906#define NUF(mnem, op, nops, ops, enc) \
16907 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16908 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16909
16910/* Neon data processing, version which indirects through neon_enc_tab for
16911 the various overloaded versions of opcodes. */
16912#define nUF(mnem, op, nops, ops, enc) \
21d799b5 16913 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16914 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16915
16916/* Neon insn with conditional suffix for the ARM version, non-overloaded
16917 version. */
037e8744
JB
16918#define NCE_tag(mnem, op, nops, ops, enc, tag) \
16919 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
16920 THUMB_VARIANT, do_##enc, do_##enc }
16921
037e8744 16922#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 16923 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16924
16925#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 16926 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16927
5287ad62 16928/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 16929#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 16930 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16931 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16932
037e8744 16933#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 16934 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16935
16936#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 16937 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16938
c19d1205
ZW
16939#define do_0 0
16940
c19d1205 16941static const struct asm_opcode insns[] =
bfae80f2 16942{
e74cfd16
PB
16943#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
16944#define THUMB_VARIANT &arm_ext_v4t
21d799b5
NC
16945 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
16946 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
16947 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
16948 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
16949 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
16950 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
16951 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
16952 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
16953 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
16954 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
16955 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
16956 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
16957 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
16958 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
16959 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
16960 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
16961
16962 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
16963 for setting PSR flag bits. They are obsolete in V6 and do not
16964 have Thumb equivalents. */
21d799b5
NC
16965 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16966 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16967 CL("tstp", 110f000, 2, (RR, SH), cmp),
16968 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16969 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16970 CL("cmpp", 150f000, 2, (RR, SH), cmp),
16971 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16972 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16973 CL("cmnp", 170f000, 2, (RR, SH), cmp),
16974
16975 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
16976 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
16977 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
16978 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
16979
16980 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
16981 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16982 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
16983 OP_RRnpc),
16984 OP_ADDRGLDR),ldst, t_ldst),
16985 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
16986
16987 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16988 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16989 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16990 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16991 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16992 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16993
16994 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
16995 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
16996 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
16997 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 16998
c19d1205 16999 /* Pseudo ops. */
21d799b5 17000 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 17001 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 17002 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
17003
17004 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
17005 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
17006 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
17007 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
17008 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
17009 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
17010 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
17011 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
17012 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
17013 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
17014 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
17015 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
17016 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 17017
16a4cf17 17018 /* These may simplify to neg. */
21d799b5
NC
17019 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
17020 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 17021
c921be7d
NC
17022#undef THUMB_VARIANT
17023#define THUMB_VARIANT & arm_ext_v6
17024
21d799b5 17025 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
17026
17027 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
17028#undef THUMB_VARIANT
17029#define THUMB_VARIANT & arm_ext_v6t2
17030
21d799b5
NC
17031 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17032 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17033 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 17034
5be8be5d
DG
17035 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17036 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17037 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
17038 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 17039
21d799b5
NC
17040 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17041 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 17042
21d799b5
NC
17043 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17044 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
17045
17046 /* V1 instructions with no Thumb analogue at all. */
21d799b5 17047 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
17048 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
17049
17050 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
17051 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
17052 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
17053 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
17054 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
17055 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
17056 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
17057 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
17058
c921be7d
NC
17059#undef ARM_VARIANT
17060#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
17061#undef THUMB_VARIANT
17062#define THUMB_VARIANT & arm_ext_v4t
17063
21d799b5
NC
17064 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
17065 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 17066
c921be7d
NC
17067#undef THUMB_VARIANT
17068#define THUMB_VARIANT & arm_ext_v6t2
17069
21d799b5 17070 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
17071 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
17072
17073 /* Generic coprocessor instructions. */
21d799b5
NC
17074 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17075 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17076 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17077 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17078 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17079 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 17080 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 17081
c921be7d
NC
17082#undef ARM_VARIANT
17083#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
17084
21d799b5 17085 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
17086 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
17087
c921be7d
NC
17088#undef ARM_VARIANT
17089#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
17090#undef THUMB_VARIANT
17091#define THUMB_VARIANT & arm_ext_msr
17092
d2cd1205
JB
17093 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
17094 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 17095
c921be7d
NC
17096#undef ARM_VARIANT
17097#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
17098#undef THUMB_VARIANT
17099#define THUMB_VARIANT & arm_ext_v6t2
17100
21d799b5
NC
17101 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17102 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17103 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17104 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17105 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17106 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17107 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17108 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 17109
c921be7d
NC
17110#undef ARM_VARIANT
17111#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
17112#undef THUMB_VARIANT
17113#define THUMB_VARIANT & arm_ext_v4t
17114
5be8be5d
DG
17115 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17116 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17117 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17118 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17119 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17120 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 17121
c921be7d
NC
17122#undef ARM_VARIANT
17123#define ARM_VARIANT & arm_ext_v4t_5
17124
c19d1205
ZW
17125 /* ARM Architecture 4T. */
17126 /* Note: bx (and blx) are required on V5, even if the processor does
17127 not support Thumb. */
21d799b5 17128 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 17129
c921be7d
NC
17130#undef ARM_VARIANT
17131#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
17132#undef THUMB_VARIANT
17133#define THUMB_VARIANT & arm_ext_v5t
17134
c19d1205
ZW
17135 /* Note: blx has 2 variants; the .value coded here is for
17136 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
17137 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
17138 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 17139
c921be7d
NC
17140#undef THUMB_VARIANT
17141#define THUMB_VARIANT & arm_ext_v6t2
17142
21d799b5
NC
17143 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
17144 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17145 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17146 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17147 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17148 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17149 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17150 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 17151
c921be7d
NC
17152#undef ARM_VARIANT
17153#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
9e3c6df6
PB
17154#undef THUMB_VARIANT
17155#define THUMB_VARIANT &arm_ext_v5exp
c921be7d 17156
21d799b5
NC
17157 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17158 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17159 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17160 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 17161
21d799b5
NC
17162 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17163 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 17164
21d799b5
NC
17165 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17166 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17167 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17168 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 17169
21d799b5
NC
17170 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17171 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17172 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17173 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 17174
21d799b5
NC
17175 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17176 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 17177
03ee1b7f
NC
17178 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17179 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17180 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17181 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 17182
c921be7d
NC
17183#undef ARM_VARIANT
17184#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
9e3c6df6
PB
17185#undef THUMB_VARIANT
17186#define THUMB_VARIANT &arm_ext_v6t2
c921be7d 17187
21d799b5 17188 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
17189 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
17190 ldrd, t_ldstd),
17191 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
17192 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 17193
21d799b5
NC
17194 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17195 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 17196
c921be7d
NC
17197#undef ARM_VARIANT
17198#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
17199
21d799b5 17200 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 17201
c921be7d
NC
17202#undef ARM_VARIANT
17203#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
17204#undef THUMB_VARIANT
17205#define THUMB_VARIANT & arm_ext_v6
17206
21d799b5
NC
17207 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
17208 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
17209 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17210 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17211 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17212 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17213 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17214 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17215 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17216 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 17217
c921be7d
NC
17218#undef THUMB_VARIANT
17219#define THUMB_VARIANT & arm_ext_v6t2
17220
5be8be5d
DG
17221 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
17222 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17223 strex, t_strex),
21d799b5
NC
17224 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17225 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 17226
21d799b5
NC
17227 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
17228 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 17229
9e3c6df6 17230/* ARM V6 not included in V7M. */
c921be7d
NC
17231#undef THUMB_VARIANT
17232#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6
PB
17233 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17234 UF(rfeib, 9900a00, 1, (RRw), rfe),
17235 UF(rfeda, 8100a00, 1, (RRw), rfe),
17236 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17237 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17238 UF(rfefa, 9900a00, 1, (RRw), rfe),
17239 UF(rfeea, 8100a00, 1, (RRw), rfe),
17240 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17241 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
17242 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
17243 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
17244 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 17245
9e3c6df6
PB
17246/* ARM V6 not included in V7M (eg. integer SIMD). */
17247#undef THUMB_VARIANT
17248#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
17249 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
17250 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
17251 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
17252 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17253 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17254 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17255 /* Old name for QASX. */
21d799b5
NC
17256 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17257 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17258 /* Old name for QSAX. */
21d799b5
NC
17259 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17260 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17261 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17262 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17263 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17264 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17265 /* Old name for SASX. */
21d799b5
NC
17266 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17267 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17268 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17269 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17270 /* Old name for SHASX. */
21d799b5
NC
17271 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17272 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17273 /* Old name for SHSAX. */
21d799b5
NC
17274 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17275 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17276 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17277 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17278 /* Old name for SSAX. */
21d799b5
NC
17279 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17280 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17281 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17282 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17283 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17284 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17285 /* Old name for UASX. */
21d799b5
NC
17286 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17287 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17288 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17289 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17290 /* Old name for UHASX. */
21d799b5
NC
17291 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17292 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17293 /* Old name for UHSAX. */
21d799b5
NC
17294 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17295 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17296 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17297 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17298 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17299 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17300 /* Old name for UQASX. */
21d799b5
NC
17301 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17302 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17303 /* Old name for UQSAX. */
21d799b5
NC
17304 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17305 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17306 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17307 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17308 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17309 /* Old name for USAX. */
21d799b5
NC
17310 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17311 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
17312 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17313 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17314 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17315 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17316 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17317 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17318 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17319 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17320 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17321 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17322 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17323 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17324 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17325 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17326 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17327 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17328 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17329 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17330 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17331 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17332 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17333 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17334 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17335 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17336 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17337 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17338 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
17339 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
17340 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
17341 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17342 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17343 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 17344
c921be7d
NC
17345#undef ARM_VARIANT
17346#define ARM_VARIANT & arm_ext_v6k
17347#undef THUMB_VARIANT
17348#define THUMB_VARIANT & arm_ext_v6k
17349
21d799b5
NC
17350 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
17351 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
17352 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
17353 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 17354
c921be7d
NC
17355#undef THUMB_VARIANT
17356#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
17357 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
17358 ldrexd, t_ldrexd),
17359 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
17360 RRnpcb), strexd, t_strexd),
ebdca51a 17361
c921be7d
NC
17362#undef THUMB_VARIANT
17363#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
17364 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
17365 rd_rn, rd_rn),
17366 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
17367 rd_rn, rd_rn),
17368 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17369 strex, rm_rd_rn),
17370 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17371 strex, rm_rd_rn),
21d799b5 17372 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 17373
c921be7d 17374#undef ARM_VARIANT
f4c65163
MGD
17375#define ARM_VARIANT & arm_ext_sec
17376#undef THUMB_VARIANT
17377#define THUMB_VARIANT & arm_ext_sec
c921be7d 17378
21d799b5 17379 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 17380
90ec0d68
MGD
17381#undef ARM_VARIANT
17382#define ARM_VARIANT & arm_ext_virt
17383#undef THUMB_VARIANT
17384#define THUMB_VARIANT & arm_ext_virt
17385
17386 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
17387 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
17388
c921be7d
NC
17389#undef ARM_VARIANT
17390#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
17391#undef THUMB_VARIANT
17392#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 17393
21d799b5
NC
17394 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
17395 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
17396 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17397 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 17398
21d799b5
NC
17399 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17400 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
17401 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
17402 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 17403
5be8be5d
DG
17404 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17405 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17406 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17407 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 17408
bf3eeda7
NS
17409 /* Thumb-only instructions. */
17410#undef ARM_VARIANT
17411#define ARM_VARIANT NULL
17412 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
17413 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
17414
17415 /* ARM does not really have an IT instruction, so always allow it.
17416 The opcode is copied from Thumb in order to allow warnings in
17417 -mimplicit-it=[never | arm] modes. */
17418#undef ARM_VARIANT
17419#define ARM_VARIANT & arm_ext_v1
17420
21d799b5
NC
17421 TUE("it", bf08, bf08, 1, (COND), it, t_it),
17422 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
17423 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
17424 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
17425 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
17426 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
17427 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
17428 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
17429 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
17430 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
17431 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
17432 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
17433 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
17434 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
17435 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 17436 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
17437 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
17438 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 17439
92e90b6e 17440 /* Thumb2 only instructions. */
c921be7d
NC
17441#undef ARM_VARIANT
17442#define ARM_VARIANT NULL
92e90b6e 17443
21d799b5
NC
17444 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17445 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17446 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
17447 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
17448 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
17449 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 17450
eea54501
MGD
17451 /* Hardware division instructions. */
17452#undef ARM_VARIANT
17453#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
17454#undef THUMB_VARIANT
17455#define THUMB_VARIANT & arm_ext_div
17456
eea54501
MGD
17457 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
17458 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 17459
7e806470 17460 /* ARM V6M/V7 instructions. */
c921be7d
NC
17461#undef ARM_VARIANT
17462#define ARM_VARIANT & arm_ext_barrier
17463#undef THUMB_VARIANT
17464#define THUMB_VARIANT & arm_ext_barrier
17465
52e7f43d
RE
17466 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
17467 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
17468 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
7e806470 17469
62b3e311 17470 /* ARM V7 instructions. */
c921be7d
NC
17471#undef ARM_VARIANT
17472#define ARM_VARIANT & arm_ext_v7
17473#undef THUMB_VARIANT
17474#define THUMB_VARIANT & arm_ext_v7
17475
21d799b5
NC
17476 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
17477 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 17478
60e5ef9f
MGD
17479#undef ARM_VARIANT
17480#define ARM_VARIANT & arm_ext_mp
17481#undef THUMB_VARIANT
17482#define THUMB_VARIANT & arm_ext_mp
17483
17484 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
17485
c921be7d
NC
17486#undef ARM_VARIANT
17487#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
17488
21d799b5
NC
17489 cCE("wfs", e200110, 1, (RR), rd),
17490 cCE("rfs", e300110, 1, (RR), rd),
17491 cCE("wfc", e400110, 1, (RR), rd),
17492 cCE("rfc", e500110, 1, (RR), rd),
17493
17494 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
17495 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
17496 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
17497 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
17498
17499 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
17500 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
17501 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
17502 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
17503
17504 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
17505 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
17506 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
17507 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
17508 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
17509 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
17510 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
17511 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
17512 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
17513 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
17514 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
17515 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
17516
17517 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
17518 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
17519 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
17520 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
17521 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17522 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17523 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17524 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17525 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17526 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17527 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17528 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17529
17530 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17531 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17532 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17533 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17534 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17535 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17536 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17537 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17538 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17539 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17540 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17541 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17542
17543 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17544 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17545 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17546 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17547 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17548 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17549 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17550 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17551 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17552 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17553 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17554 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17555
17556 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17557 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17558 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17559 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17560 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17561 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17562 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17563 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17564 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17565 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17566 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17567 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17568
17569 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17570 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17571 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17572 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17573 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17574 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17575 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17576 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17577 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17578 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17579 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17580 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17581
17582 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17583 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17584 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17585 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17586 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17587 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17588 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17589 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17590 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17591 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17592 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17593 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17594
17595 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17596 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17597 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17598 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17599 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17600 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17601 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17602 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17603 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17604 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17605 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17606 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17607
17608 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17609 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17610 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17611 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17612 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17613 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17614 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17615 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17616 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17617 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17618 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17619 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17620
17621 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17622 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17623 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17624 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17625 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17626 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17627 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17628 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17629 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17630 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17631 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17632 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17633
17634 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17635 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17636 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17637 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17638 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17639 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17640 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17641 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17642 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17643 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17644 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17645 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17646
17647 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17648 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17649 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17650 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17651 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17652 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17653 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17654 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17655 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17656 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17657 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17658 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17659
17660 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17661 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17662 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17663 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17664 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17665 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17666 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17667 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17668 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17669 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17670 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17671 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17672
17673 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17674 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17675 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17676 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17677 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17678 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17679 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17680 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17681 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17682 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17683 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17684 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17685
17686 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17687 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17688 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17689 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17690 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17691 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17692 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17693 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17694 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17695 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17696 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17697 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17698
17699 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17700 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17701 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17702 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17703 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17704 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17705 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17706 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17707 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17708 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17709 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17710 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17711
17712 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17713 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17714 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17715 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17716 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17717 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17718 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17719 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17720 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17721 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17722 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17723 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17724
17725 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17726 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17727 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17728 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17729 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17730 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17731 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17732 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17733 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17734 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17735 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17736 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17737
17738 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17739 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17740 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17741 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17742 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17743 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17744 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17745 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17746 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17747 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17748 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17749 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17750
17751 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17752 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17753 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17754 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17755 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17756 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17757 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17758 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17759 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17760 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17761 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17762 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17763
17764 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17765 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17766 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17767 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17768 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17769 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17770 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17771 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17772 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17773 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17774 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17775 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17776
17777 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17778 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17779 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17780 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17781 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17782 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17783 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17784 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17785 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17786 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17787 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17788 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17789
17790 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17791 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17792 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17793 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17794 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17795 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17796 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17797 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17798 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17799 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17800 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17801 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17802
17803 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17804 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17805 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17806 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17807 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17808 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17809 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17810 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17811 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17812 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17813 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17814 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17815
17816 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17817 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17818 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17819 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17820 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17821 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17822 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17823 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17824 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17825 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17826 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17827 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17828
17829 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17830 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17831 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17832 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17833 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17834 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17835 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17836 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17837 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17838 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17839 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17840 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17841
17842 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17843 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17844 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17845 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17846 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17847 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17848 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17849 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17850 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17851 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17852 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17853 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17854
17855 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17856 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17857 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17858 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17859 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17860 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17861 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17862 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17863 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17864 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17865 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17866 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17867
17868 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17869 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17870 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17871 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17872 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17873 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17874 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17875 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17876 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17877 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17878 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17879 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17880
17881 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17882 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17883 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17884 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17885
17886 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17887 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17888 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17889 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17890 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17891 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17892 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17893 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17894 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17895 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17896 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17897 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 17898
c19d1205
ZW
17899 /* The implementation of the FIX instruction is broken on some
17900 assemblers, in that it accepts a precision specifier as well as a
17901 rounding specifier, despite the fact that this is meaningless.
17902 To be more compatible, we accept it as well, though of course it
17903 does not set any bits. */
21d799b5
NC
17904 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17905 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17906 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17907 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17908 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17909 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17910 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17911 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17912 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17913 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17914 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17915 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17916 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 17917
c19d1205 17918 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
17919#undef ARM_VARIANT
17920#define ARM_VARIANT & fpu_fpa_ext_v2
17921
21d799b5
NC
17922 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17923 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17924 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17925 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17926 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17927 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 17928
c921be7d
NC
17929#undef ARM_VARIANT
17930#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
17931
c19d1205 17932 /* Moves and type conversions. */
21d799b5
NC
17933 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
17934 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
17935 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
17936 cCE("fmstat", ef1fa10, 0, (), noargs),
f7c21dc7
NC
17937 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
17938 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
21d799b5
NC
17939 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
17940 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
17941 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
17942 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17943 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
17944 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17945 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
17946 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
17947
17948 /* Memory operations. */
21d799b5
NC
17949 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17950 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
17951 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17952 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17953 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17954 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17955 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17956 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17957 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17958 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17959 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17960 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17961 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17962 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17963 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17964 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17965 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17966 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 17967
c19d1205 17968 /* Monadic operations. */
21d799b5
NC
17969 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
17970 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
17971 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
17972
17973 /* Dyadic operations. */
21d799b5
NC
17974 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17975 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17976 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17977 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17978 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17979 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17980 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17981 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17982 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 17983
c19d1205 17984 /* Comparisons. */
21d799b5
NC
17985 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
17986 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
17987 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
17988 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 17989
62f3b8c8
PB
17990 /* Double precision load/store are still present on single precision
17991 implementations. */
17992 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17993 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
17994 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17995 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17996 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17997 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17998 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17999 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18000 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18001 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 18002
c921be7d
NC
18003#undef ARM_VARIANT
18004#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
18005
c19d1205 18006 /* Moves and type conversions. */
21d799b5
NC
18007 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18008 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18009 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18010 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
18011 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
18012 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
18013 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
18014 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18015 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
18016 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18017 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18018 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18019 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 18020
c19d1205 18021 /* Monadic operations. */
21d799b5
NC
18022 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18023 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18024 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
18025
18026 /* Dyadic operations. */
21d799b5
NC
18027 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18028 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18029 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18030 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18031 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18032 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18033 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18034 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18035 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 18036
c19d1205 18037 /* Comparisons. */
21d799b5
NC
18038 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18039 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
18040 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18041 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 18042
c921be7d
NC
18043#undef ARM_VARIANT
18044#define ARM_VARIANT & fpu_vfp_ext_v2
18045
21d799b5
NC
18046 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
18047 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
18048 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
18049 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 18050
037e8744
JB
18051/* Instructions which may belong to either the Neon or VFP instruction sets.
18052 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
18053#undef ARM_VARIANT
18054#define ARM_VARIANT & fpu_vfp_ext_v1xd
18055#undef THUMB_VARIANT
18056#define THUMB_VARIANT & fpu_vfp_ext_v1xd
18057
037e8744
JB
18058 /* These mnemonics are unique to VFP. */
18059 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
18060 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
18061 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18062 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18063 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18064 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
18065 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
18066 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
18067 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
18068 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
18069
18070 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
18071 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
18072 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
18073 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 18074
21d799b5
NC
18075 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
18076 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
18077
18078 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18079 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18080
55881a11
MGD
18081 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18082 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18083 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18084 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18085 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18086 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
18087 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
18088 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 18089
e3e535bc
NC
18090 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
18091 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
21d799b5
NC
18092 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
18093 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 18094
037e8744
JB
18095
18096 /* NOTE: All VMOV encoding is special-cased! */
18097 NCE(vmov, 0, 1, (VMOV), neon_mov),
18098 NCE(vmovq, 0, 1, (VMOV), neon_mov),
18099
c921be7d
NC
18100#undef THUMB_VARIANT
18101#define THUMB_VARIANT & fpu_neon_ext_v1
18102#undef ARM_VARIANT
18103#define ARM_VARIANT & fpu_neon_ext_v1
18104
5287ad62
JB
18105 /* Data processing with three registers of the same length. */
18106 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
18107 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
18108 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
18109 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18110 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18111 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18112 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18113 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18114 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18115 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
18116 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18117 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
18118 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18119 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
18120 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18121 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
18122 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18123 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
18124 /* If not immediate, fall back to neon_dyadic_i64_su.
18125 shl_imm should accept I8 I16 I32 I64,
18126 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
18127 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
18128 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
18129 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
18130 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 18131 /* Logic ops, types optional & ignored. */
4316f0d2
DG
18132 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18133 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18134 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18135 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18136 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18137 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18138 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18139 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18140 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
18141 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
18142 /* Bitfield ops, untyped. */
18143 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18144 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18145 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18146 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18147 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18148 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18149 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
18150 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18151 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18152 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18153 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18154 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18155 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
18156 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
18157 back to neon_dyadic_if_su. */
21d799b5
NC
18158 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18159 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18160 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18161 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18162 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18163 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
18164 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18165 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 18166 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
18167 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
18168 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 18169 /* As above, D registers only. */
21d799b5
NC
18170 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
18171 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 18172 /* Int and float variants, signedness unimportant. */
21d799b5
NC
18173 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18174 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18175 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 18176 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
18177 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
18178 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
18179 /* vtst takes sizes 8, 16, 32. */
18180 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
18181 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
18182 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 18183 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 18184 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
18185 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18186 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
18187 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18188 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
18189 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18190 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
18191 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18192 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
18193 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18194 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
18195 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18196 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
18197 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18198 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18199 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18200 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18201
18202 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 18203 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
18204 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
18205
18206 /* Data processing with two registers and a shift amount. */
18207 /* Right shifts, and variants with rounding.
18208 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
18209 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18210 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18211 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18212 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18213 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18214 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18215 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18216 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18217 /* Shift and insert. Sizes accepted 8 16 32 64. */
18218 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
18219 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
18220 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
18221 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
18222 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
18223 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
18224 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
18225 /* Right shift immediate, saturating & narrowing, with rounding variants.
18226 Types accepted S16 S32 S64 U16 U32 U64. */
18227 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18228 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18229 /* As above, unsigned. Types accepted S16 S32 S64. */
18230 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18231 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18232 /* Right shift narrowing. Types accepted I16 I32 I64. */
18233 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18234 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18235 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 18236 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 18237 /* CVT with optional immediate for fixed-point variant. */
21d799b5 18238 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 18239
4316f0d2
DG
18240 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
18241 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
18242
18243 /* Data processing, three registers of different lengths. */
18244 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
18245 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
18246 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
18247 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
18248 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
18249 /* If not scalar, fall back to neon_dyadic_long.
18250 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
18251 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
18252 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
18253 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
18254 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18255 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18256 /* Dyadic, narrowing insns. Types I16 I32 I64. */
18257 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18258 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18259 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18260 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18261 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
18262 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18263 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18264 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
18265 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
18266 S16 S32 U16 U32. */
21d799b5 18267 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
18268
18269 /* Extract. Size 8. */
3b8d421e
PB
18270 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
18271 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
18272
18273 /* Two registers, miscellaneous. */
18274 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
18275 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
18276 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
18277 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
18278 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
18279 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
18280 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
18281 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
18282 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
18283 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
18284 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
18285 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
18286 /* VMOVN. Types I16 I32 I64. */
21d799b5 18287 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 18288 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 18289 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 18290 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 18291 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
18292 /* VZIP / VUZP. Sizes 8 16 32. */
18293 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
18294 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
18295 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
18296 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
18297 /* VQABS / VQNEG. Types S8 S16 S32. */
18298 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18299 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
18300 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18301 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
18302 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
18303 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
18304 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
18305 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
18306 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
18307 /* Reciprocal estimates. Types U32 F32. */
18308 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
18309 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
18310 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
18311 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
18312 /* VCLS. Types S8 S16 S32. */
18313 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
18314 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
18315 /* VCLZ. Types I8 I16 I32. */
18316 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
18317 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
18318 /* VCNT. Size 8. */
18319 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
18320 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
18321 /* Two address, untyped. */
18322 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
18323 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
18324 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
18325 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
18326 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
18327
18328 /* Table lookup. Size 8. */
18329 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18330 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18331
c921be7d
NC
18332#undef THUMB_VARIANT
18333#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
18334#undef ARM_VARIANT
18335#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
18336
5287ad62 18337 /* Neon element/structure load/store. */
21d799b5
NC
18338 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18339 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18340 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18341 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18342 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18343 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18344 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18345 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 18346
c921be7d 18347#undef THUMB_VARIANT
62f3b8c8
PB
18348#define THUMB_VARIANT &fpu_vfp_ext_v3xd
18349#undef ARM_VARIANT
18350#define ARM_VARIANT &fpu_vfp_ext_v3xd
18351 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
18352 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18353 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18354 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18355 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18356 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18357 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18358 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18359 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18360
18361#undef THUMB_VARIANT
c921be7d
NC
18362#define THUMB_VARIANT & fpu_vfp_ext_v3
18363#undef ARM_VARIANT
18364#define ARM_VARIANT & fpu_vfp_ext_v3
18365
21d799b5 18366 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 18367 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18368 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18369 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18370 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18371 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18372 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18373 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18374 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 18375
62f3b8c8
PB
18376#undef ARM_VARIANT
18377#define ARM_VARIANT &fpu_vfp_ext_fma
18378#undef THUMB_VARIANT
18379#define THUMB_VARIANT &fpu_vfp_ext_fma
18380 /* Mnemonics shared by Neon and VFP. These are included in the
18381 VFP FMA variant; NEON and VFP FMA always includes the NEON
18382 FMA instructions. */
18383 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18384 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18385 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
18386 the v form should always be used. */
18387 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18388 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18389 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18390 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18391 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18392 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18393
5287ad62 18394#undef THUMB_VARIANT
c921be7d
NC
18395#undef ARM_VARIANT
18396#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
18397
21d799b5
NC
18398 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18399 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18400 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18401 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18402 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18403 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18404 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
18405 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 18406
c921be7d
NC
18407#undef ARM_VARIANT
18408#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
18409
21d799b5
NC
18410 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
18411 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
18412 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
18413 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
18414 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
18415 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
18416 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
18417 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
18418 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
18419 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18420 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18421 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18422 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18423 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18424 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18425 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18426 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18427 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18428 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
18429 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
18430 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18431 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18432 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18433 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18434 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18435 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18436 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
18437 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
18438 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
18439 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
18440 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
18441 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
18442 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
18443 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
18444 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
18445 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
18446 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
18447 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18448 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18449 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18450 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18451 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18452 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18453 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18454 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18455 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18456 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
18457 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18458 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18459 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18460 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18461 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18462 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18463 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18464 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18465 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18466 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18467 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18468 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18469 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18470 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18471 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18472 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18473 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18474 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18475 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18476 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18477 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18478 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18479 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18480 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18481 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18482 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18483 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18484 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18485 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18486 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18487 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18488 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18489 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18490 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18491 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18492 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18493 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18494 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18495 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18496 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18497 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18498 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
18499 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18500 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18501 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18502 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18503 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18504 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18505 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18506 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18507 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18508 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18509 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18510 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18511 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18512 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18513 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18514 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18515 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18516 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18517 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18518 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18519 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18520 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
18521 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18522 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18523 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18524 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18525 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18526 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18527 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18528 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18529 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18530 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18531 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18532 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18533 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18534 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18535 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18536 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18537 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18538 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18539 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18540 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18541 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18542 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18543 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18544 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18545 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18546 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18547 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18548 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18549 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18550 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18551 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18552 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18553 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18554 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18555 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18556 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18557 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18558 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18559 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18560 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18561 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18562 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18563 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18564 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18565 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18566 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18567 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18568 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18569 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18570 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18571 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 18572
c921be7d
NC
18573#undef ARM_VARIANT
18574#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18575
21d799b5
NC
18576 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18577 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18578 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18579 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18580 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18581 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18582 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18583 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18584 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18585 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18586 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18587 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18588 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18589 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18590 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18591 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18592 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18593 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18594 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18595 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18596 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18597 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18598 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18599 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18600 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18601 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18602 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18603 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18604 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18605 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18606 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18607 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18608 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18609 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18610 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18611 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18612 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18613 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18614 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18615 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18616 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18617 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18618 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18619 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18620 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18621 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18622 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18623 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18624 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18625 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18626 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18627 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18628 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18629 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18630 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18631 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18632 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 18633
c921be7d
NC
18634#undef ARM_VARIANT
18635#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18636
21d799b5
NC
18637 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18638 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18639 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18640 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18641 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18642 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18643 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18644 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18645 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18646 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18647 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18648 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18649 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18650 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18651 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18652 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18653 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18654 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18655 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18656 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18657 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18658 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18659 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18660 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18661 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18662 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18663 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18664 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18665 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18666 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18667 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18668 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18669 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18670 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18671 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18672 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18673 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18674 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18675 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18676 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18677 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18678 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18679 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18680 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18681 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18682 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18683 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18684 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18685 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18686 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18687 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18688 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18689 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18690 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18691 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18692 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18693 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18694 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18695 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18696 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18697 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18698 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18699 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18700 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18701 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18702 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18703 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18704 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18705 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18706 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18707 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18708 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18709 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18710 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18711 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18712 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
18713};
18714#undef ARM_VARIANT
18715#undef THUMB_VARIANT
18716#undef TCE
18717#undef TCM
18718#undef TUE
18719#undef TUF
18720#undef TCC
8f06b2d8 18721#undef cCE
e3cb604e
PB
18722#undef cCL
18723#undef C3E
c19d1205
ZW
18724#undef CE
18725#undef CM
18726#undef UE
18727#undef UF
18728#undef UT
5287ad62
JB
18729#undef NUF
18730#undef nUF
18731#undef NCE
18732#undef nCE
c19d1205
ZW
18733#undef OPS0
18734#undef OPS1
18735#undef OPS2
18736#undef OPS3
18737#undef OPS4
18738#undef OPS5
18739#undef OPS6
18740#undef do_0
18741\f
18742/* MD interface: bits in the object file. */
bfae80f2 18743
c19d1205
ZW
18744/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18745 for use in the a.out file, and stores them in the array pointed to by buf.
18746 This knows about the endian-ness of the target machine and does
18747 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18748 2 (short) and 4 (long) Floating numbers are put out as a series of
18749 LITTLENUMS (shorts, here at least). */
b99bd4ef 18750
c19d1205
ZW
18751void
18752md_number_to_chars (char * buf, valueT val, int n)
18753{
18754 if (target_big_endian)
18755 number_to_chars_bigendian (buf, val, n);
18756 else
18757 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
18758}
18759
c19d1205
ZW
18760static valueT
18761md_chars_to_number (char * buf, int n)
bfae80f2 18762{
c19d1205
ZW
18763 valueT result = 0;
18764 unsigned char * where = (unsigned char *) buf;
bfae80f2 18765
c19d1205 18766 if (target_big_endian)
b99bd4ef 18767 {
c19d1205
ZW
18768 while (n--)
18769 {
18770 result <<= 8;
18771 result |= (*where++ & 255);
18772 }
b99bd4ef 18773 }
c19d1205 18774 else
b99bd4ef 18775 {
c19d1205
ZW
18776 while (n--)
18777 {
18778 result <<= 8;
18779 result |= (where[n] & 255);
18780 }
bfae80f2 18781 }
b99bd4ef 18782
c19d1205 18783 return result;
bfae80f2 18784}
b99bd4ef 18785
c19d1205 18786/* MD interface: Sections. */
b99bd4ef 18787
0110f2b8
PB
18788/* Estimate the size of a frag before relaxing. Assume everything fits in
18789 2 bytes. */
18790
c19d1205 18791int
0110f2b8 18792md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
18793 segT segtype ATTRIBUTE_UNUSED)
18794{
0110f2b8
PB
18795 fragp->fr_var = 2;
18796 return 2;
18797}
18798
18799/* Convert a machine dependent frag. */
18800
18801void
18802md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18803{
18804 unsigned long insn;
18805 unsigned long old_op;
18806 char *buf;
18807 expressionS exp;
18808 fixS *fixp;
18809 int reloc_type;
18810 int pc_rel;
18811 int opcode;
18812
18813 buf = fragp->fr_literal + fragp->fr_fix;
18814
18815 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
18816 if (fragp->fr_symbol)
18817 {
0110f2b8
PB
18818 exp.X_op = O_symbol;
18819 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
18820 }
18821 else
18822 {
0110f2b8 18823 exp.X_op = O_constant;
5f4273c7 18824 }
0110f2b8
PB
18825 exp.X_add_number = fragp->fr_offset;
18826 opcode = fragp->fr_subtype;
18827 switch (opcode)
18828 {
18829 case T_MNEM_ldr_pc:
18830 case T_MNEM_ldr_pc2:
18831 case T_MNEM_ldr_sp:
18832 case T_MNEM_str_sp:
18833 case T_MNEM_ldr:
18834 case T_MNEM_ldrb:
18835 case T_MNEM_ldrh:
18836 case T_MNEM_str:
18837 case T_MNEM_strb:
18838 case T_MNEM_strh:
18839 if (fragp->fr_var == 4)
18840 {
5f4273c7 18841 insn = THUMB_OP32 (opcode);
0110f2b8
PB
18842 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18843 {
18844 insn |= (old_op & 0x700) << 4;
18845 }
18846 else
18847 {
18848 insn |= (old_op & 7) << 12;
18849 insn |= (old_op & 0x38) << 13;
18850 }
18851 insn |= 0x00000c00;
18852 put_thumb32_insn (buf, insn);
18853 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18854 }
18855 else
18856 {
18857 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18858 }
18859 pc_rel = (opcode == T_MNEM_ldr_pc2);
18860 break;
18861 case T_MNEM_adr:
18862 if (fragp->fr_var == 4)
18863 {
18864 insn = THUMB_OP32 (opcode);
18865 insn |= (old_op & 0xf0) << 4;
18866 put_thumb32_insn (buf, insn);
18867 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18868 }
18869 else
18870 {
18871 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18872 exp.X_add_number -= 4;
18873 }
18874 pc_rel = 1;
18875 break;
18876 case T_MNEM_mov:
18877 case T_MNEM_movs:
18878 case T_MNEM_cmp:
18879 case T_MNEM_cmn:
18880 if (fragp->fr_var == 4)
18881 {
18882 int r0off = (opcode == T_MNEM_mov
18883 || opcode == T_MNEM_movs) ? 0 : 8;
18884 insn = THUMB_OP32 (opcode);
18885 insn = (insn & 0xe1ffffff) | 0x10000000;
18886 insn |= (old_op & 0x700) << r0off;
18887 put_thumb32_insn (buf, insn);
18888 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18889 }
18890 else
18891 {
18892 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18893 }
18894 pc_rel = 0;
18895 break;
18896 case T_MNEM_b:
18897 if (fragp->fr_var == 4)
18898 {
18899 insn = THUMB_OP32(opcode);
18900 put_thumb32_insn (buf, insn);
18901 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18902 }
18903 else
18904 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18905 pc_rel = 1;
18906 break;
18907 case T_MNEM_bcond:
18908 if (fragp->fr_var == 4)
18909 {
18910 insn = THUMB_OP32(opcode);
18911 insn |= (old_op & 0xf00) << 14;
18912 put_thumb32_insn (buf, insn);
18913 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18914 }
18915 else
18916 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18917 pc_rel = 1;
18918 break;
18919 case T_MNEM_add_sp:
18920 case T_MNEM_add_pc:
18921 case T_MNEM_inc_sp:
18922 case T_MNEM_dec_sp:
18923 if (fragp->fr_var == 4)
18924 {
18925 /* ??? Choose between add and addw. */
18926 insn = THUMB_OP32 (opcode);
18927 insn |= (old_op & 0xf0) << 4;
18928 put_thumb32_insn (buf, insn);
16805f35
PB
18929 if (opcode == T_MNEM_add_pc)
18930 reloc_type = BFD_RELOC_ARM_T32_IMM12;
18931 else
18932 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
18933 }
18934 else
18935 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18936 pc_rel = 0;
18937 break;
18938
18939 case T_MNEM_addi:
18940 case T_MNEM_addis:
18941 case T_MNEM_subi:
18942 case T_MNEM_subis:
18943 if (fragp->fr_var == 4)
18944 {
18945 insn = THUMB_OP32 (opcode);
18946 insn |= (old_op & 0xf0) << 4;
18947 insn |= (old_op & 0xf) << 16;
18948 put_thumb32_insn (buf, insn);
16805f35
PB
18949 if (insn & (1 << 20))
18950 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18951 else
18952 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
18953 }
18954 else
18955 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18956 pc_rel = 0;
18957 break;
18958 default:
5f4273c7 18959 abort ();
0110f2b8
PB
18960 }
18961 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 18962 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
18963 fixp->fx_file = fragp->fr_file;
18964 fixp->fx_line = fragp->fr_line;
18965 fragp->fr_fix += fragp->fr_var;
18966}
18967
18968/* Return the size of a relaxable immediate operand instruction.
18969 SHIFT and SIZE specify the form of the allowable immediate. */
18970static int
18971relax_immediate (fragS *fragp, int size, int shift)
18972{
18973 offsetT offset;
18974 offsetT mask;
18975 offsetT low;
18976
18977 /* ??? Should be able to do better than this. */
18978 if (fragp->fr_symbol)
18979 return 4;
18980
18981 low = (1 << shift) - 1;
18982 mask = (1 << (shift + size)) - (1 << shift);
18983 offset = fragp->fr_offset;
18984 /* Force misaligned offsets to 32-bit variant. */
18985 if (offset & low)
5e77afaa 18986 return 4;
0110f2b8
PB
18987 if (offset & ~mask)
18988 return 4;
18989 return 2;
18990}
18991
5e77afaa
PB
18992/* Get the address of a symbol during relaxation. */
18993static addressT
5f4273c7 18994relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
18995{
18996 fragS *sym_frag;
18997 addressT addr;
18998 symbolS *sym;
18999
19000 sym = fragp->fr_symbol;
19001 sym_frag = symbol_get_frag (sym);
19002 know (S_GET_SEGMENT (sym) != absolute_section
19003 || sym_frag == &zero_address_frag);
19004 addr = S_GET_VALUE (sym) + fragp->fr_offset;
19005
19006 /* If frag has yet to be reached on this pass, assume it will
19007 move by STRETCH just as we did. If this is not so, it will
19008 be because some frag between grows, and that will force
19009 another pass. */
19010
19011 if (stretch != 0
19012 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
19013 {
19014 fragS *f;
19015
19016 /* Adjust stretch for any alignment frag. Note that if have
19017 been expanding the earlier code, the symbol may be
19018 defined in what appears to be an earlier frag. FIXME:
19019 This doesn't handle the fr_subtype field, which specifies
19020 a maximum number of bytes to skip when doing an
19021 alignment. */
19022 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
19023 {
19024 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
19025 {
19026 if (stretch < 0)
19027 stretch = - ((- stretch)
19028 & ~ ((1 << (int) f->fr_offset) - 1));
19029 else
19030 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
19031 if (stretch == 0)
19032 break;
19033 }
19034 }
19035 if (f != NULL)
19036 addr += stretch;
19037 }
5e77afaa
PB
19038
19039 return addr;
19040}
19041
0110f2b8
PB
19042/* Return the size of a relaxable adr pseudo-instruction or PC-relative
19043 load. */
19044static int
5e77afaa 19045relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
19046{
19047 addressT addr;
19048 offsetT val;
19049
19050 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
19051 if (fragp->fr_symbol == NULL
19052 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
19053 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19054 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
19055 return 4;
19056
5f4273c7 19057 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
19058 addr = fragp->fr_address + fragp->fr_fix;
19059 addr = (addr + 4) & ~3;
5e77afaa 19060 /* Force misaligned targets to 32-bit variant. */
0110f2b8 19061 if (val & 3)
5e77afaa 19062 return 4;
0110f2b8
PB
19063 val -= addr;
19064 if (val < 0 || val > 1020)
19065 return 4;
19066 return 2;
19067}
19068
19069/* Return the size of a relaxable add/sub immediate instruction. */
19070static int
19071relax_addsub (fragS *fragp, asection *sec)
19072{
19073 char *buf;
19074 int op;
19075
19076 buf = fragp->fr_literal + fragp->fr_fix;
19077 op = bfd_get_16(sec->owner, buf);
19078 if ((op & 0xf) == ((op >> 4) & 0xf))
19079 return relax_immediate (fragp, 8, 0);
19080 else
19081 return relax_immediate (fragp, 3, 0);
19082}
19083
19084
19085/* Return the size of a relaxable branch instruction. BITS is the
19086 size of the offset field in the narrow instruction. */
19087
19088static int
5e77afaa 19089relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
19090{
19091 addressT addr;
19092 offsetT val;
19093 offsetT limit;
19094
19095 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 19096 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
19097 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19098 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
19099 return 4;
19100
267bf995
RR
19101#ifdef OBJ_ELF
19102 if (S_IS_DEFINED (fragp->fr_symbol)
19103 && ARM_IS_FUNC (fragp->fr_symbol))
19104 return 4;
0d9b4b55
NC
19105
19106 /* PR 12532. Global symbols with default visibility might
19107 be preempted, so do not relax relocations to them. */
19108 if ((ELF_ST_VISIBILITY (S_GET_OTHER (fragp->fr_symbol)) == STV_DEFAULT)
19109 && (! S_IS_LOCAL (fragp->fr_symbol)))
19110 return 4;
267bf995
RR
19111#endif
19112
5f4273c7 19113 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
19114 addr = fragp->fr_address + fragp->fr_fix + 4;
19115 val -= addr;
19116
19117 /* Offset is a signed value *2 */
19118 limit = 1 << bits;
19119 if (val >= limit || val < -limit)
19120 return 4;
19121 return 2;
19122}
19123
19124
19125/* Relax a machine dependent frag. This returns the amount by which
19126 the current size of the frag should change. */
19127
19128int
5e77afaa 19129arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
19130{
19131 int oldsize;
19132 int newsize;
19133
19134 oldsize = fragp->fr_var;
19135 switch (fragp->fr_subtype)
19136 {
19137 case T_MNEM_ldr_pc2:
5f4273c7 19138 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
19139 break;
19140 case T_MNEM_ldr_pc:
19141 case T_MNEM_ldr_sp:
19142 case T_MNEM_str_sp:
5f4273c7 19143 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
19144 break;
19145 case T_MNEM_ldr:
19146 case T_MNEM_str:
5f4273c7 19147 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
19148 break;
19149 case T_MNEM_ldrh:
19150 case T_MNEM_strh:
5f4273c7 19151 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
19152 break;
19153 case T_MNEM_ldrb:
19154 case T_MNEM_strb:
5f4273c7 19155 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
19156 break;
19157 case T_MNEM_adr:
5f4273c7 19158 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
19159 break;
19160 case T_MNEM_mov:
19161 case T_MNEM_movs:
19162 case T_MNEM_cmp:
19163 case T_MNEM_cmn:
5f4273c7 19164 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
19165 break;
19166 case T_MNEM_b:
5f4273c7 19167 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
19168 break;
19169 case T_MNEM_bcond:
5f4273c7 19170 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
19171 break;
19172 case T_MNEM_add_sp:
19173 case T_MNEM_add_pc:
19174 newsize = relax_immediate (fragp, 8, 2);
19175 break;
19176 case T_MNEM_inc_sp:
19177 case T_MNEM_dec_sp:
19178 newsize = relax_immediate (fragp, 7, 2);
19179 break;
19180 case T_MNEM_addi:
19181 case T_MNEM_addis:
19182 case T_MNEM_subi:
19183 case T_MNEM_subis:
19184 newsize = relax_addsub (fragp, sec);
19185 break;
19186 default:
5f4273c7 19187 abort ();
0110f2b8 19188 }
5e77afaa
PB
19189
19190 fragp->fr_var = newsize;
19191 /* Freeze wide instructions that are at or before the same location as
19192 in the previous pass. This avoids infinite loops.
5f4273c7
NC
19193 Don't freeze them unconditionally because targets may be artificially
19194 misaligned by the expansion of preceding frags. */
5e77afaa 19195 if (stretch <= 0 && newsize > 2)
0110f2b8 19196 {
0110f2b8 19197 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 19198 frag_wane (fragp);
0110f2b8 19199 }
5e77afaa 19200
0110f2b8 19201 return newsize - oldsize;
c19d1205 19202}
b99bd4ef 19203
c19d1205 19204/* Round up a section size to the appropriate boundary. */
b99bd4ef 19205
c19d1205
ZW
19206valueT
19207md_section_align (segT segment ATTRIBUTE_UNUSED,
19208 valueT size)
19209{
f0927246
NC
19210#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
19211 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
19212 {
19213 /* For a.out, force the section size to be aligned. If we don't do
19214 this, BFD will align it for us, but it will not write out the
19215 final bytes of the section. This may be a bug in BFD, but it is
19216 easier to fix it here since that is how the other a.out targets
19217 work. */
19218 int align;
19219
19220 align = bfd_get_section_alignment (stdoutput, segment);
19221 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
19222 }
c19d1205 19223#endif
f0927246
NC
19224
19225 return size;
bfae80f2 19226}
b99bd4ef 19227
c19d1205
ZW
19228/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
19229 of an rs_align_code fragment. */
19230
19231void
19232arm_handle_align (fragS * fragP)
bfae80f2 19233{
e7495e45
NS
19234 static char const arm_noop[2][2][4] =
19235 {
19236 { /* ARMv1 */
19237 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
19238 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
19239 },
19240 { /* ARMv6k */
19241 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
19242 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
19243 },
19244 };
19245 static char const thumb_noop[2][2][2] =
19246 {
19247 { /* Thumb-1 */
19248 {0xc0, 0x46}, /* LE */
19249 {0x46, 0xc0}, /* BE */
19250 },
19251 { /* Thumb-2 */
19252 {0x00, 0xbf}, /* LE */
19253 {0xbf, 0x00} /* BE */
19254 }
19255 };
19256 static char const wide_thumb_noop[2][4] =
19257 { /* Wide Thumb-2 */
19258 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
19259 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
19260 };
c921be7d 19261
e7495e45 19262 unsigned bytes, fix, noop_size;
c19d1205
ZW
19263 char * p;
19264 const char * noop;
e7495e45 19265 const char *narrow_noop = NULL;
cd000bff
DJ
19266#ifdef OBJ_ELF
19267 enum mstate state;
19268#endif
bfae80f2 19269
c19d1205 19270 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
19271 return;
19272
c19d1205
ZW
19273 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
19274 p = fragP->fr_literal + fragP->fr_fix;
19275 fix = 0;
bfae80f2 19276
c19d1205
ZW
19277 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
19278 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 19279
cd000bff 19280 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 19281
cd000bff 19282 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 19283 {
e7495e45
NS
19284 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
19285 {
19286 narrow_noop = thumb_noop[1][target_big_endian];
19287 noop = wide_thumb_noop[target_big_endian];
19288 }
c19d1205 19289 else
e7495e45
NS
19290 noop = thumb_noop[0][target_big_endian];
19291 noop_size = 2;
cd000bff
DJ
19292#ifdef OBJ_ELF
19293 state = MAP_THUMB;
19294#endif
7ed4c4c5
NC
19295 }
19296 else
19297 {
e7495e45
NS
19298 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
19299 [target_big_endian];
19300 noop_size = 4;
cd000bff
DJ
19301#ifdef OBJ_ELF
19302 state = MAP_ARM;
19303#endif
7ed4c4c5 19304 }
c921be7d 19305
e7495e45 19306 fragP->fr_var = noop_size;
c921be7d 19307
c19d1205 19308 if (bytes & (noop_size - 1))
7ed4c4c5 19309 {
c19d1205 19310 fix = bytes & (noop_size - 1);
cd000bff
DJ
19311#ifdef OBJ_ELF
19312 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
19313#endif
c19d1205
ZW
19314 memset (p, 0, fix);
19315 p += fix;
19316 bytes -= fix;
a737bd4d 19317 }
a737bd4d 19318
e7495e45
NS
19319 if (narrow_noop)
19320 {
19321 if (bytes & noop_size)
19322 {
19323 /* Insert a narrow noop. */
19324 memcpy (p, narrow_noop, noop_size);
19325 p += noop_size;
19326 bytes -= noop_size;
19327 fix += noop_size;
19328 }
19329
19330 /* Use wide noops for the remainder */
19331 noop_size = 4;
19332 }
19333
c19d1205 19334 while (bytes >= noop_size)
a737bd4d 19335 {
c19d1205
ZW
19336 memcpy (p, noop, noop_size);
19337 p += noop_size;
19338 bytes -= noop_size;
19339 fix += noop_size;
a737bd4d
NC
19340 }
19341
c19d1205 19342 fragP->fr_fix += fix;
a737bd4d
NC
19343}
19344
c19d1205
ZW
19345/* Called from md_do_align. Used to create an alignment
19346 frag in a code section. */
19347
19348void
19349arm_frag_align_code (int n, int max)
bfae80f2 19350{
c19d1205 19351 char * p;
7ed4c4c5 19352
c19d1205 19353 /* We assume that there will never be a requirement
6ec8e702 19354 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 19355 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
19356 {
19357 char err_msg[128];
19358
19359 sprintf (err_msg,
19360 _("alignments greater than %d bytes not supported in .text sections."),
19361 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 19362 as_fatal ("%s", err_msg);
6ec8e702 19363 }
bfae80f2 19364
c19d1205
ZW
19365 p = frag_var (rs_align_code,
19366 MAX_MEM_FOR_RS_ALIGN_CODE,
19367 1,
19368 (relax_substateT) max,
19369 (symbolS *) NULL,
19370 (offsetT) n,
19371 (char *) NULL);
19372 *p = 0;
19373}
bfae80f2 19374
8dc2430f
NC
19375/* Perform target specific initialisation of a frag.
19376 Note - despite the name this initialisation is not done when the frag
19377 is created, but only when its type is assigned. A frag can be created
19378 and used a long time before its type is set, so beware of assuming that
19379 this initialisationis performed first. */
bfae80f2 19380
cd000bff
DJ
19381#ifndef OBJ_ELF
19382void
19383arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
19384{
19385 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 19386 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
19387}
19388
19389#else /* OBJ_ELF is defined. */
c19d1205 19390void
cd000bff 19391arm_init_frag (fragS * fragP, int max_chars)
c19d1205 19392{
8dc2430f
NC
19393 /* If the current ARM vs THUMB mode has not already
19394 been recorded into this frag then do so now. */
cd000bff
DJ
19395 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
19396 {
19397 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19398
19399 /* Record a mapping symbol for alignment frags. We will delete this
19400 later if the alignment ends up empty. */
19401 switch (fragP->fr_type)
19402 {
19403 case rs_align:
19404 case rs_align_test:
19405 case rs_fill:
19406 mapping_state_2 (MAP_DATA, max_chars);
19407 break;
19408 case rs_align_code:
19409 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
19410 break;
19411 default:
19412 break;
19413 }
19414 }
bfae80f2
RE
19415}
19416
c19d1205
ZW
19417/* When we change sections we need to issue a new mapping symbol. */
19418
19419void
19420arm_elf_change_section (void)
bfae80f2 19421{
c19d1205
ZW
19422 /* Link an unlinked unwind index table section to the .text section. */
19423 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
19424 && elf_linked_to_section (now_seg) == NULL)
19425 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
19426}
19427
c19d1205
ZW
19428int
19429arm_elf_section_type (const char * str, size_t len)
e45d0630 19430{
c19d1205
ZW
19431 if (len == 5 && strncmp (str, "exidx", 5) == 0)
19432 return SHT_ARM_EXIDX;
e45d0630 19433
c19d1205
ZW
19434 return -1;
19435}
19436\f
19437/* Code to deal with unwinding tables. */
e45d0630 19438
c19d1205 19439static void add_unwind_adjustsp (offsetT);
e45d0630 19440
5f4273c7 19441/* Generate any deferred unwind frame offset. */
e45d0630 19442
bfae80f2 19443static void
c19d1205 19444flush_pending_unwind (void)
bfae80f2 19445{
c19d1205 19446 offsetT offset;
bfae80f2 19447
c19d1205
ZW
19448 offset = unwind.pending_offset;
19449 unwind.pending_offset = 0;
19450 if (offset != 0)
19451 add_unwind_adjustsp (offset);
bfae80f2
RE
19452}
19453
c19d1205
ZW
19454/* Add an opcode to this list for this function. Two-byte opcodes should
19455 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
19456 order. */
19457
bfae80f2 19458static void
c19d1205 19459add_unwind_opcode (valueT op, int length)
bfae80f2 19460{
c19d1205
ZW
19461 /* Add any deferred stack adjustment. */
19462 if (unwind.pending_offset)
19463 flush_pending_unwind ();
bfae80f2 19464
c19d1205 19465 unwind.sp_restored = 0;
bfae80f2 19466
c19d1205 19467 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 19468 {
c19d1205
ZW
19469 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
19470 if (unwind.opcodes)
21d799b5
NC
19471 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
19472 unwind.opcode_alloc);
c19d1205 19473 else
21d799b5 19474 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 19475 }
c19d1205 19476 while (length > 0)
bfae80f2 19477 {
c19d1205
ZW
19478 length--;
19479 unwind.opcodes[unwind.opcode_count] = op & 0xff;
19480 op >>= 8;
19481 unwind.opcode_count++;
bfae80f2 19482 }
bfae80f2
RE
19483}
19484
c19d1205
ZW
19485/* Add unwind opcodes to adjust the stack pointer. */
19486
bfae80f2 19487static void
c19d1205 19488add_unwind_adjustsp (offsetT offset)
bfae80f2 19489{
c19d1205 19490 valueT op;
bfae80f2 19491
c19d1205 19492 if (offset > 0x200)
bfae80f2 19493 {
c19d1205
ZW
19494 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
19495 char bytes[5];
19496 int n;
19497 valueT o;
bfae80f2 19498
c19d1205
ZW
19499 /* Long form: 0xb2, uleb128. */
19500 /* This might not fit in a word so add the individual bytes,
19501 remembering the list is built in reverse order. */
19502 o = (valueT) ((offset - 0x204) >> 2);
19503 if (o == 0)
19504 add_unwind_opcode (0, 1);
bfae80f2 19505
c19d1205
ZW
19506 /* Calculate the uleb128 encoding of the offset. */
19507 n = 0;
19508 while (o)
19509 {
19510 bytes[n] = o & 0x7f;
19511 o >>= 7;
19512 if (o)
19513 bytes[n] |= 0x80;
19514 n++;
19515 }
19516 /* Add the insn. */
19517 for (; n; n--)
19518 add_unwind_opcode (bytes[n - 1], 1);
19519 add_unwind_opcode (0xb2, 1);
19520 }
19521 else if (offset > 0x100)
bfae80f2 19522 {
c19d1205
ZW
19523 /* Two short opcodes. */
19524 add_unwind_opcode (0x3f, 1);
19525 op = (offset - 0x104) >> 2;
19526 add_unwind_opcode (op, 1);
bfae80f2 19527 }
c19d1205
ZW
19528 else if (offset > 0)
19529 {
19530 /* Short opcode. */
19531 op = (offset - 4) >> 2;
19532 add_unwind_opcode (op, 1);
19533 }
19534 else if (offset < 0)
bfae80f2 19535 {
c19d1205
ZW
19536 offset = -offset;
19537 while (offset > 0x100)
bfae80f2 19538 {
c19d1205
ZW
19539 add_unwind_opcode (0x7f, 1);
19540 offset -= 0x100;
bfae80f2 19541 }
c19d1205
ZW
19542 op = ((offset - 4) >> 2) | 0x40;
19543 add_unwind_opcode (op, 1);
bfae80f2 19544 }
bfae80f2
RE
19545}
19546
c19d1205
ZW
19547/* Finish the list of unwind opcodes for this function. */
19548static void
19549finish_unwind_opcodes (void)
bfae80f2 19550{
c19d1205 19551 valueT op;
bfae80f2 19552
c19d1205 19553 if (unwind.fp_used)
bfae80f2 19554 {
708587a4 19555 /* Adjust sp as necessary. */
c19d1205
ZW
19556 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19557 flush_pending_unwind ();
bfae80f2 19558
c19d1205
ZW
19559 /* After restoring sp from the frame pointer. */
19560 op = 0x90 | unwind.fp_reg;
19561 add_unwind_opcode (op, 1);
19562 }
19563 else
19564 flush_pending_unwind ();
bfae80f2
RE
19565}
19566
bfae80f2 19567
c19d1205
ZW
19568/* Start an exception table entry. If idx is nonzero this is an index table
19569 entry. */
bfae80f2
RE
19570
19571static void
c19d1205 19572start_unwind_section (const segT text_seg, int idx)
bfae80f2 19573{
c19d1205
ZW
19574 const char * text_name;
19575 const char * prefix;
19576 const char * prefix_once;
19577 const char * group_name;
19578 size_t prefix_len;
19579 size_t text_len;
19580 char * sec_name;
19581 size_t sec_name_len;
19582 int type;
19583 int flags;
19584 int linkonce;
bfae80f2 19585
c19d1205 19586 if (idx)
bfae80f2 19587 {
c19d1205
ZW
19588 prefix = ELF_STRING_ARM_unwind;
19589 prefix_once = ELF_STRING_ARM_unwind_once;
19590 type = SHT_ARM_EXIDX;
bfae80f2 19591 }
c19d1205 19592 else
bfae80f2 19593 {
c19d1205
ZW
19594 prefix = ELF_STRING_ARM_unwind_info;
19595 prefix_once = ELF_STRING_ARM_unwind_info_once;
19596 type = SHT_PROGBITS;
bfae80f2
RE
19597 }
19598
c19d1205
ZW
19599 text_name = segment_name (text_seg);
19600 if (streq (text_name, ".text"))
19601 text_name = "";
19602
19603 if (strncmp (text_name, ".gnu.linkonce.t.",
19604 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 19605 {
c19d1205
ZW
19606 prefix = prefix_once;
19607 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
19608 }
19609
c19d1205
ZW
19610 prefix_len = strlen (prefix);
19611 text_len = strlen (text_name);
19612 sec_name_len = prefix_len + text_len;
21d799b5 19613 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
19614 memcpy (sec_name, prefix, prefix_len);
19615 memcpy (sec_name + prefix_len, text_name, text_len);
19616 sec_name[prefix_len + text_len] = '\0';
bfae80f2 19617
c19d1205
ZW
19618 flags = SHF_ALLOC;
19619 linkonce = 0;
19620 group_name = 0;
bfae80f2 19621
c19d1205
ZW
19622 /* Handle COMDAT group. */
19623 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 19624 {
c19d1205
ZW
19625 group_name = elf_group_name (text_seg);
19626 if (group_name == NULL)
19627 {
bd3ba5d1 19628 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
19629 segment_name (text_seg));
19630 ignore_rest_of_line ();
19631 return;
19632 }
19633 flags |= SHF_GROUP;
19634 linkonce = 1;
bfae80f2
RE
19635 }
19636
c19d1205 19637 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 19638
5f4273c7 19639 /* Set the section link for index tables. */
c19d1205
ZW
19640 if (idx)
19641 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
19642}
19643
bfae80f2 19644
c19d1205
ZW
19645/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19646 personality routine data. Returns zero, or the index table value for
19647 and inline entry. */
19648
19649static valueT
19650create_unwind_entry (int have_data)
bfae80f2 19651{
c19d1205
ZW
19652 int size;
19653 addressT where;
19654 char *ptr;
19655 /* The current word of data. */
19656 valueT data;
19657 /* The number of bytes left in this word. */
19658 int n;
bfae80f2 19659
c19d1205 19660 finish_unwind_opcodes ();
bfae80f2 19661
c19d1205
ZW
19662 /* Remember the current text section. */
19663 unwind.saved_seg = now_seg;
19664 unwind.saved_subseg = now_subseg;
bfae80f2 19665
c19d1205 19666 start_unwind_section (now_seg, 0);
bfae80f2 19667
c19d1205 19668 if (unwind.personality_routine == NULL)
bfae80f2 19669 {
c19d1205
ZW
19670 if (unwind.personality_index == -2)
19671 {
19672 if (have_data)
5f4273c7 19673 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
19674 return 1; /* EXIDX_CANTUNWIND. */
19675 }
bfae80f2 19676
c19d1205
ZW
19677 /* Use a default personality routine if none is specified. */
19678 if (unwind.personality_index == -1)
19679 {
19680 if (unwind.opcode_count > 3)
19681 unwind.personality_index = 1;
19682 else
19683 unwind.personality_index = 0;
19684 }
bfae80f2 19685
c19d1205
ZW
19686 /* Space for the personality routine entry. */
19687 if (unwind.personality_index == 0)
19688 {
19689 if (unwind.opcode_count > 3)
19690 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 19691
c19d1205
ZW
19692 if (!have_data)
19693 {
19694 /* All the data is inline in the index table. */
19695 data = 0x80;
19696 n = 3;
19697 while (unwind.opcode_count > 0)
19698 {
19699 unwind.opcode_count--;
19700 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19701 n--;
19702 }
bfae80f2 19703
c19d1205
ZW
19704 /* Pad with "finish" opcodes. */
19705 while (n--)
19706 data = (data << 8) | 0xb0;
bfae80f2 19707
c19d1205
ZW
19708 return data;
19709 }
19710 size = 0;
19711 }
19712 else
19713 /* We get two opcodes "free" in the first word. */
19714 size = unwind.opcode_count - 2;
19715 }
19716 else
19717 /* An extra byte is required for the opcode count. */
19718 size = unwind.opcode_count + 1;
bfae80f2 19719
c19d1205
ZW
19720 size = (size + 3) >> 2;
19721 if (size > 0xff)
19722 as_bad (_("too many unwind opcodes"));
bfae80f2 19723
c19d1205
ZW
19724 frag_align (2, 0, 0);
19725 record_alignment (now_seg, 2);
19726 unwind.table_entry = expr_build_dot ();
19727
19728 /* Allocate the table entry. */
19729 ptr = frag_more ((size << 2) + 4);
19730 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 19731
c19d1205 19732 switch (unwind.personality_index)
bfae80f2 19733 {
c19d1205
ZW
19734 case -1:
19735 /* ??? Should this be a PLT generating relocation? */
19736 /* Custom personality routine. */
19737 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19738 BFD_RELOC_ARM_PREL31);
bfae80f2 19739
c19d1205
ZW
19740 where += 4;
19741 ptr += 4;
bfae80f2 19742
c19d1205
ZW
19743 /* Set the first byte to the number of additional words. */
19744 data = size - 1;
19745 n = 3;
19746 break;
bfae80f2 19747
c19d1205
ZW
19748 /* ABI defined personality routines. */
19749 case 0:
19750 /* Three opcodes bytes are packed into the first word. */
19751 data = 0x80;
19752 n = 3;
19753 break;
bfae80f2 19754
c19d1205
ZW
19755 case 1:
19756 case 2:
19757 /* The size and first two opcode bytes go in the first word. */
19758 data = ((0x80 + unwind.personality_index) << 8) | size;
19759 n = 2;
19760 break;
bfae80f2 19761
c19d1205
ZW
19762 default:
19763 /* Should never happen. */
19764 abort ();
19765 }
bfae80f2 19766
c19d1205
ZW
19767 /* Pack the opcodes into words (MSB first), reversing the list at the same
19768 time. */
19769 while (unwind.opcode_count > 0)
19770 {
19771 if (n == 0)
19772 {
19773 md_number_to_chars (ptr, data, 4);
19774 ptr += 4;
19775 n = 4;
19776 data = 0;
19777 }
19778 unwind.opcode_count--;
19779 n--;
19780 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19781 }
19782
19783 /* Finish off the last word. */
19784 if (n < 4)
19785 {
19786 /* Pad with "finish" opcodes. */
19787 while (n--)
19788 data = (data << 8) | 0xb0;
19789
19790 md_number_to_chars (ptr, data, 4);
19791 }
19792
19793 if (!have_data)
19794 {
19795 /* Add an empty descriptor if there is no user-specified data. */
19796 ptr = frag_more (4);
19797 md_number_to_chars (ptr, 0, 4);
19798 }
19799
19800 return 0;
bfae80f2
RE
19801}
19802
f0927246
NC
19803
19804/* Initialize the DWARF-2 unwind information for this procedure. */
19805
19806void
19807tc_arm_frame_initial_instructions (void)
19808{
19809 cfi_add_CFA_def_cfa (REG_SP, 0);
19810}
19811#endif /* OBJ_ELF */
19812
c19d1205
ZW
19813/* Convert REGNAME to a DWARF-2 register number. */
19814
19815int
1df69f4f 19816tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 19817{
1df69f4f 19818 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
19819
19820 if (reg == FAIL)
19821 return -1;
19822
19823 return reg;
bfae80f2
RE
19824}
19825
f0927246 19826#ifdef TE_PE
c19d1205 19827void
f0927246 19828tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 19829{
91d6fa6a 19830 expressionS exp;
bfae80f2 19831
91d6fa6a
NC
19832 exp.X_op = O_secrel;
19833 exp.X_add_symbol = symbol;
19834 exp.X_add_number = 0;
19835 emit_expr (&exp, size);
f0927246
NC
19836}
19837#endif
bfae80f2 19838
c19d1205 19839/* MD interface: Symbol and relocation handling. */
bfae80f2 19840
2fc8bdac
ZW
19841/* Return the address within the segment that a PC-relative fixup is
19842 relative to. For ARM, PC-relative fixups applied to instructions
19843 are generally relative to the location of the fixup plus 8 bytes.
19844 Thumb branches are offset by 4, and Thumb loads relative to PC
19845 require special handling. */
bfae80f2 19846
c19d1205 19847long
2fc8bdac 19848md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 19849{
2fc8bdac
ZW
19850 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19851
19852 /* If this is pc-relative and we are going to emit a relocation
19853 then we just want to put out any pipeline compensation that the linker
53baae48
NC
19854 will need. Otherwise we want to use the calculated base.
19855 For WinCE we skip the bias for externals as well, since this
19856 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 19857 if (fixP->fx_pcrel
2fc8bdac 19858 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
19859 || (arm_force_relocation (fixP)
19860#ifdef TE_WINCE
19861 && !S_IS_EXTERNAL (fixP->fx_addsy)
19862#endif
19863 )))
2fc8bdac 19864 base = 0;
bfae80f2 19865
267bf995 19866
c19d1205 19867 switch (fixP->fx_r_type)
bfae80f2 19868 {
2fc8bdac
ZW
19869 /* PC relative addressing on the Thumb is slightly odd as the
19870 bottom two bits of the PC are forced to zero for the
19871 calculation. This happens *after* application of the
19872 pipeline offset. However, Thumb adrl already adjusts for
19873 this, so we need not do it again. */
c19d1205 19874 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 19875 return base & ~3;
c19d1205
ZW
19876
19877 case BFD_RELOC_ARM_THUMB_OFFSET:
19878 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 19879 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 19880 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 19881 return (base + 4) & ~3;
c19d1205 19882
2fc8bdac
ZW
19883 /* Thumb branches are simply offset by +4. */
19884 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19885 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19886 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19887 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 19888 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 19889 return base + 4;
bfae80f2 19890
267bf995 19891 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
19892 if (fixP->fx_addsy
19893 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 19894 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
19895 && ARM_IS_FUNC (fixP->fx_addsy)
19896 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19897 base = fixP->fx_where + fixP->fx_frag->fr_address;
19898 return base + 4;
19899
00adf2d4
JB
19900 /* BLX is like branches above, but forces the low two bits of PC to
19901 zero. */
486499d0
CL
19902 case BFD_RELOC_THUMB_PCREL_BLX:
19903 if (fixP->fx_addsy
19904 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 19905 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
19906 && THUMB_IS_FUNC (fixP->fx_addsy)
19907 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19908 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
19909 return (base + 4) & ~3;
19910
2fc8bdac
ZW
19911 /* ARM mode branches are offset by +8. However, the Windows CE
19912 loader expects the relocation not to take this into account. */
267bf995 19913 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
19914 if (fixP->fx_addsy
19915 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 19916 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
19917 && ARM_IS_FUNC (fixP->fx_addsy)
19918 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19919 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19920 return base + 8;
267bf995 19921
486499d0
CL
19922 case BFD_RELOC_ARM_PCREL_CALL:
19923 if (fixP->fx_addsy
19924 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 19925 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
19926 && THUMB_IS_FUNC (fixP->fx_addsy)
19927 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19928 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19929 return base + 8;
267bf995 19930
2fc8bdac 19931 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 19932 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 19933 case BFD_RELOC_ARM_PLT32:
c19d1205 19934#ifdef TE_WINCE
5f4273c7 19935 /* When handling fixups immediately, because we have already
53baae48
NC
19936 discovered the value of a symbol, or the address of the frag involved
19937 we must account for the offset by +8, as the OS loader will never see the reloc.
19938 see fixup_segment() in write.c
19939 The S_IS_EXTERNAL test handles the case of global symbols.
19940 Those need the calculated base, not just the pipe compensation the linker will need. */
19941 if (fixP->fx_pcrel
19942 && fixP->fx_addsy != NULL
19943 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19944 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
19945 return base + 8;
2fc8bdac 19946 return base;
c19d1205 19947#else
2fc8bdac 19948 return base + 8;
c19d1205 19949#endif
2fc8bdac 19950
267bf995 19951
2fc8bdac
ZW
19952 /* ARM mode loads relative to PC are also offset by +8. Unlike
19953 branches, the Windows CE loader *does* expect the relocation
19954 to take this into account. */
19955 case BFD_RELOC_ARM_OFFSET_IMM:
19956 case BFD_RELOC_ARM_OFFSET_IMM8:
19957 case BFD_RELOC_ARM_HWLITERAL:
19958 case BFD_RELOC_ARM_LITERAL:
19959 case BFD_RELOC_ARM_CP_OFF_IMM:
19960 return base + 8;
19961
19962
19963 /* Other PC-relative relocations are un-offset. */
19964 default:
19965 return base;
19966 }
bfae80f2
RE
19967}
19968
c19d1205
ZW
19969/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
19970 Otherwise we have no need to default values of symbols. */
19971
19972symbolS *
19973md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 19974{
c19d1205
ZW
19975#ifdef OBJ_ELF
19976 if (name[0] == '_' && name[1] == 'G'
19977 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
19978 {
19979 if (!GOT_symbol)
19980 {
19981 if (symbol_find (name))
bd3ba5d1 19982 as_bad (_("GOT already in the symbol table"));
bfae80f2 19983
c19d1205
ZW
19984 GOT_symbol = symbol_new (name, undefined_section,
19985 (valueT) 0, & zero_address_frag);
19986 }
bfae80f2 19987
c19d1205 19988 return GOT_symbol;
bfae80f2 19989 }
c19d1205 19990#endif
bfae80f2 19991
c921be7d 19992 return NULL;
bfae80f2
RE
19993}
19994
55cf6793 19995/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
19996 computed as two separate immediate values, added together. We
19997 already know that this value cannot be computed by just one ARM
19998 instruction. */
19999
20000static unsigned int
20001validate_immediate_twopart (unsigned int val,
20002 unsigned int * highpart)
bfae80f2 20003{
c19d1205
ZW
20004 unsigned int a;
20005 unsigned int i;
bfae80f2 20006
c19d1205
ZW
20007 for (i = 0; i < 32; i += 2)
20008 if (((a = rotate_left (val, i)) & 0xff) != 0)
20009 {
20010 if (a & 0xff00)
20011 {
20012 if (a & ~ 0xffff)
20013 continue;
20014 * highpart = (a >> 8) | ((i + 24) << 7);
20015 }
20016 else if (a & 0xff0000)
20017 {
20018 if (a & 0xff000000)
20019 continue;
20020 * highpart = (a >> 16) | ((i + 16) << 7);
20021 }
20022 else
20023 {
9c2799c2 20024 gas_assert (a & 0xff000000);
c19d1205
ZW
20025 * highpart = (a >> 24) | ((i + 8) << 7);
20026 }
bfae80f2 20027
c19d1205
ZW
20028 return (a & 0xff) | (i << 7);
20029 }
bfae80f2 20030
c19d1205 20031 return FAIL;
bfae80f2
RE
20032}
20033
c19d1205
ZW
20034static int
20035validate_offset_imm (unsigned int val, int hwse)
20036{
20037 if ((hwse && val > 255) || val > 4095)
20038 return FAIL;
20039 return val;
20040}
bfae80f2 20041
55cf6793 20042/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
20043 negative immediate constant by altering the instruction. A bit of
20044 a hack really.
20045 MOV <-> MVN
20046 AND <-> BIC
20047 ADC <-> SBC
20048 by inverting the second operand, and
20049 ADD <-> SUB
20050 CMP <-> CMN
20051 by negating the second operand. */
bfae80f2 20052
c19d1205
ZW
20053static int
20054negate_data_op (unsigned long * instruction,
20055 unsigned long value)
bfae80f2 20056{
c19d1205
ZW
20057 int op, new_inst;
20058 unsigned long negated, inverted;
bfae80f2 20059
c19d1205
ZW
20060 negated = encode_arm_immediate (-value);
20061 inverted = encode_arm_immediate (~value);
bfae80f2 20062
c19d1205
ZW
20063 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
20064 switch (op)
bfae80f2 20065 {
c19d1205
ZW
20066 /* First negates. */
20067 case OPCODE_SUB: /* ADD <-> SUB */
20068 new_inst = OPCODE_ADD;
20069 value = negated;
20070 break;
bfae80f2 20071
c19d1205
ZW
20072 case OPCODE_ADD:
20073 new_inst = OPCODE_SUB;
20074 value = negated;
20075 break;
bfae80f2 20076
c19d1205
ZW
20077 case OPCODE_CMP: /* CMP <-> CMN */
20078 new_inst = OPCODE_CMN;
20079 value = negated;
20080 break;
bfae80f2 20081
c19d1205
ZW
20082 case OPCODE_CMN:
20083 new_inst = OPCODE_CMP;
20084 value = negated;
20085 break;
bfae80f2 20086
c19d1205
ZW
20087 /* Now Inverted ops. */
20088 case OPCODE_MOV: /* MOV <-> MVN */
20089 new_inst = OPCODE_MVN;
20090 value = inverted;
20091 break;
bfae80f2 20092
c19d1205
ZW
20093 case OPCODE_MVN:
20094 new_inst = OPCODE_MOV;
20095 value = inverted;
20096 break;
bfae80f2 20097
c19d1205
ZW
20098 case OPCODE_AND: /* AND <-> BIC */
20099 new_inst = OPCODE_BIC;
20100 value = inverted;
20101 break;
bfae80f2 20102
c19d1205
ZW
20103 case OPCODE_BIC:
20104 new_inst = OPCODE_AND;
20105 value = inverted;
20106 break;
bfae80f2 20107
c19d1205
ZW
20108 case OPCODE_ADC: /* ADC <-> SBC */
20109 new_inst = OPCODE_SBC;
20110 value = inverted;
20111 break;
bfae80f2 20112
c19d1205
ZW
20113 case OPCODE_SBC:
20114 new_inst = OPCODE_ADC;
20115 value = inverted;
20116 break;
bfae80f2 20117
c19d1205
ZW
20118 /* We cannot do anything. */
20119 default:
20120 return FAIL;
b99bd4ef
NC
20121 }
20122
c19d1205
ZW
20123 if (value == (unsigned) FAIL)
20124 return FAIL;
20125
20126 *instruction &= OPCODE_MASK;
20127 *instruction |= new_inst << DATA_OP_SHIFT;
20128 return value;
b99bd4ef
NC
20129}
20130
ef8d22e6
PB
20131/* Like negate_data_op, but for Thumb-2. */
20132
20133static unsigned int
16dd5e42 20134thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
20135{
20136 int op, new_inst;
20137 int rd;
16dd5e42 20138 unsigned int negated, inverted;
ef8d22e6
PB
20139
20140 negated = encode_thumb32_immediate (-value);
20141 inverted = encode_thumb32_immediate (~value);
20142
20143 rd = (*instruction >> 8) & 0xf;
20144 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
20145 switch (op)
20146 {
20147 /* ADD <-> SUB. Includes CMP <-> CMN. */
20148 case T2_OPCODE_SUB:
20149 new_inst = T2_OPCODE_ADD;
20150 value = negated;
20151 break;
20152
20153 case T2_OPCODE_ADD:
20154 new_inst = T2_OPCODE_SUB;
20155 value = negated;
20156 break;
20157
20158 /* ORR <-> ORN. Includes MOV <-> MVN. */
20159 case T2_OPCODE_ORR:
20160 new_inst = T2_OPCODE_ORN;
20161 value = inverted;
20162 break;
20163
20164 case T2_OPCODE_ORN:
20165 new_inst = T2_OPCODE_ORR;
20166 value = inverted;
20167 break;
20168
20169 /* AND <-> BIC. TST has no inverted equivalent. */
20170 case T2_OPCODE_AND:
20171 new_inst = T2_OPCODE_BIC;
20172 if (rd == 15)
20173 value = FAIL;
20174 else
20175 value = inverted;
20176 break;
20177
20178 case T2_OPCODE_BIC:
20179 new_inst = T2_OPCODE_AND;
20180 value = inverted;
20181 break;
20182
20183 /* ADC <-> SBC */
20184 case T2_OPCODE_ADC:
20185 new_inst = T2_OPCODE_SBC;
20186 value = inverted;
20187 break;
20188
20189 case T2_OPCODE_SBC:
20190 new_inst = T2_OPCODE_ADC;
20191 value = inverted;
20192 break;
20193
20194 /* We cannot do anything. */
20195 default:
20196 return FAIL;
20197 }
20198
16dd5e42 20199 if (value == (unsigned int)FAIL)
ef8d22e6
PB
20200 return FAIL;
20201
20202 *instruction &= T2_OPCODE_MASK;
20203 *instruction |= new_inst << T2_DATA_OP_SHIFT;
20204 return value;
20205}
20206
8f06b2d8
PB
20207/* Read a 32-bit thumb instruction from buf. */
20208static unsigned long
20209get_thumb32_insn (char * buf)
20210{
20211 unsigned long insn;
20212 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
20213 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20214
20215 return insn;
20216}
20217
a8bc6c78
PB
20218
20219/* We usually want to set the low bit on the address of thumb function
20220 symbols. In particular .word foo - . should have the low bit set.
20221 Generic code tries to fold the difference of two symbols to
20222 a constant. Prevent this and force a relocation when the first symbols
20223 is a thumb function. */
c921be7d
NC
20224
20225bfd_boolean
a8bc6c78
PB
20226arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
20227{
20228 if (op == O_subtract
20229 && l->X_op == O_symbol
20230 && r->X_op == O_symbol
20231 && THUMB_IS_FUNC (l->X_add_symbol))
20232 {
20233 l->X_op = O_subtract;
20234 l->X_op_symbol = r->X_add_symbol;
20235 l->X_add_number -= r->X_add_number;
c921be7d 20236 return TRUE;
a8bc6c78 20237 }
c921be7d 20238
a8bc6c78 20239 /* Process as normal. */
c921be7d 20240 return FALSE;
a8bc6c78
PB
20241}
20242
4a42ebbc
RR
20243/* Encode Thumb2 unconditional branches and calls. The encoding
20244 for the 2 are identical for the immediate values. */
20245
20246static void
20247encode_thumb2_b_bl_offset (char * buf, offsetT value)
20248{
20249#define T2I1I2MASK ((1 << 13) | (1 << 11))
20250 offsetT newval;
20251 offsetT newval2;
20252 addressT S, I1, I2, lo, hi;
20253
20254 S = (value >> 24) & 0x01;
20255 I1 = (value >> 23) & 0x01;
20256 I2 = (value >> 22) & 0x01;
20257 hi = (value >> 12) & 0x3ff;
20258 lo = (value >> 1) & 0x7ff;
20259 newval = md_chars_to_number (buf, THUMB_SIZE);
20260 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20261 newval |= (S << 10) | hi;
20262 newval2 &= ~T2I1I2MASK;
20263 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
20264 md_number_to_chars (buf, newval, THUMB_SIZE);
20265 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20266}
20267
c19d1205 20268void
55cf6793 20269md_apply_fix (fixS * fixP,
c19d1205
ZW
20270 valueT * valP,
20271 segT seg)
20272{
20273 offsetT value = * valP;
20274 offsetT newval;
20275 unsigned int newimm;
20276 unsigned long temp;
20277 int sign;
20278 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 20279
9c2799c2 20280 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 20281
c19d1205 20282 /* Note whether this will delete the relocation. */
4962c51a 20283
c19d1205
ZW
20284 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
20285 fixP->fx_done = 1;
b99bd4ef 20286
adbaf948 20287 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 20288 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
20289 for emit_reloc. */
20290 value &= 0xffffffff;
20291 value ^= 0x80000000;
5f4273c7 20292 value -= 0x80000000;
adbaf948
ZW
20293
20294 *valP = value;
c19d1205 20295 fixP->fx_addnumber = value;
b99bd4ef 20296
adbaf948
ZW
20297 /* Same treatment for fixP->fx_offset. */
20298 fixP->fx_offset &= 0xffffffff;
20299 fixP->fx_offset ^= 0x80000000;
20300 fixP->fx_offset -= 0x80000000;
20301
c19d1205 20302 switch (fixP->fx_r_type)
b99bd4ef 20303 {
c19d1205
ZW
20304 case BFD_RELOC_NONE:
20305 /* This will need to go in the object file. */
20306 fixP->fx_done = 0;
20307 break;
b99bd4ef 20308
c19d1205
ZW
20309 case BFD_RELOC_ARM_IMMEDIATE:
20310 /* We claim that this fixup has been processed here,
20311 even if in fact we generate an error because we do
20312 not have a reloc for it, so tc_gen_reloc will reject it. */
20313 fixP->fx_done = 1;
b99bd4ef 20314
77db8e2e 20315 if (fixP->fx_addsy)
b99bd4ef 20316 {
77db8e2e 20317 const char *msg = 0;
b99bd4ef 20318
77db8e2e
NC
20319 if (! S_IS_DEFINED (fixP->fx_addsy))
20320 msg = _("undefined symbol %s used as an immediate value");
20321 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20322 msg = _("symbol %s is in a different section");
20323 else if (S_IS_WEAK (fixP->fx_addsy))
20324 msg = _("symbol %s is weak and may be overridden later");
20325
20326 if (msg)
20327 {
20328 as_bad_where (fixP->fx_file, fixP->fx_line,
20329 msg, S_GET_NAME (fixP->fx_addsy));
20330 break;
20331 }
42e5fcbf
AS
20332 }
20333
c19d1205
ZW
20334 newimm = encode_arm_immediate (value);
20335 temp = md_chars_to_number (buf, INSN_SIZE);
20336
20337 /* If the instruction will fail, see if we can fix things up by
20338 changing the opcode. */
20339 if (newimm == (unsigned int) FAIL
20340 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 20341 {
c19d1205
ZW
20342 as_bad_where (fixP->fx_file, fixP->fx_line,
20343 _("invalid constant (%lx) after fixup"),
20344 (unsigned long) value);
20345 break;
b99bd4ef 20346 }
b99bd4ef 20347
c19d1205
ZW
20348 newimm |= (temp & 0xfffff000);
20349 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20350 break;
b99bd4ef 20351
c19d1205
ZW
20352 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20353 {
20354 unsigned int highpart = 0;
20355 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 20356
77db8e2e 20357 if (fixP->fx_addsy)
42e5fcbf 20358 {
77db8e2e 20359 const char *msg = 0;
42e5fcbf 20360
77db8e2e
NC
20361 if (! S_IS_DEFINED (fixP->fx_addsy))
20362 msg = _("undefined symbol %s used as an immediate value");
20363 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20364 msg = _("symbol %s is in a different section");
20365 else if (S_IS_WEAK (fixP->fx_addsy))
20366 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 20367
77db8e2e
NC
20368 if (msg)
20369 {
20370 as_bad_where (fixP->fx_file, fixP->fx_line,
20371 msg, S_GET_NAME (fixP->fx_addsy));
20372 break;
20373 }
20374 }
20375
c19d1205
ZW
20376 newimm = encode_arm_immediate (value);
20377 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 20378
c19d1205
ZW
20379 /* If the instruction will fail, see if we can fix things up by
20380 changing the opcode. */
20381 if (newimm == (unsigned int) FAIL
20382 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
20383 {
20384 /* No ? OK - try using two ADD instructions to generate
20385 the value. */
20386 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 20387
c19d1205
ZW
20388 /* Yes - then make sure that the second instruction is
20389 also an add. */
20390 if (newimm != (unsigned int) FAIL)
20391 newinsn = temp;
20392 /* Still No ? Try using a negated value. */
20393 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
20394 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
20395 /* Otherwise - give up. */
20396 else
20397 {
20398 as_bad_where (fixP->fx_file, fixP->fx_line,
20399 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
20400 (long) value);
20401 break;
20402 }
b99bd4ef 20403
c19d1205
ZW
20404 /* Replace the first operand in the 2nd instruction (which
20405 is the PC) with the destination register. We have
20406 already added in the PC in the first instruction and we
20407 do not want to do it again. */
20408 newinsn &= ~ 0xf0000;
20409 newinsn |= ((newinsn & 0x0f000) << 4);
20410 }
b99bd4ef 20411
c19d1205
ZW
20412 newimm |= (temp & 0xfffff000);
20413 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 20414
c19d1205
ZW
20415 highpart |= (newinsn & 0xfffff000);
20416 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
20417 }
20418 break;
b99bd4ef 20419
c19d1205 20420 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
20421 if (!fixP->fx_done && seg->use_rela_p)
20422 value = 0;
20423
c19d1205
ZW
20424 case BFD_RELOC_ARM_LITERAL:
20425 sign = value >= 0;
b99bd4ef 20426
c19d1205
ZW
20427 if (value < 0)
20428 value = - value;
b99bd4ef 20429
c19d1205 20430 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 20431 {
c19d1205
ZW
20432 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
20433 as_bad_where (fixP->fx_file, fixP->fx_line,
20434 _("invalid literal constant: pool needs to be closer"));
20435 else
20436 as_bad_where (fixP->fx_file, fixP->fx_line,
20437 _("bad immediate value for offset (%ld)"),
20438 (long) value);
20439 break;
f03698e6
RE
20440 }
20441
c19d1205
ZW
20442 newval = md_chars_to_number (buf, INSN_SIZE);
20443 newval &= 0xff7ff000;
20444 newval |= value | (sign ? INDEX_UP : 0);
20445 md_number_to_chars (buf, newval, INSN_SIZE);
20446 break;
b99bd4ef 20447
c19d1205
ZW
20448 case BFD_RELOC_ARM_OFFSET_IMM8:
20449 case BFD_RELOC_ARM_HWLITERAL:
20450 sign = value >= 0;
b99bd4ef 20451
c19d1205
ZW
20452 if (value < 0)
20453 value = - value;
b99bd4ef 20454
c19d1205 20455 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 20456 {
c19d1205
ZW
20457 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
20458 as_bad_where (fixP->fx_file, fixP->fx_line,
20459 _("invalid literal constant: pool needs to be closer"));
20460 else
f9d4405b 20461 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
20462 (long) value);
20463 break;
b99bd4ef
NC
20464 }
20465
c19d1205
ZW
20466 newval = md_chars_to_number (buf, INSN_SIZE);
20467 newval &= 0xff7ff0f0;
20468 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
20469 md_number_to_chars (buf, newval, INSN_SIZE);
20470 break;
b99bd4ef 20471
c19d1205
ZW
20472 case BFD_RELOC_ARM_T32_OFFSET_U8:
20473 if (value < 0 || value > 1020 || value % 4 != 0)
20474 as_bad_where (fixP->fx_file, fixP->fx_line,
20475 _("bad immediate value for offset (%ld)"), (long) value);
20476 value /= 4;
b99bd4ef 20477
c19d1205 20478 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
20479 newval |= value;
20480 md_number_to_chars (buf+2, newval, THUMB_SIZE);
20481 break;
b99bd4ef 20482
c19d1205
ZW
20483 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20484 /* This is a complicated relocation used for all varieties of Thumb32
20485 load/store instruction with immediate offset:
20486
20487 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
20488 *4, optional writeback(W)
20489 (doubleword load/store)
20490
20491 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
20492 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
20493 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
20494 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
20495 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
20496
20497 Uppercase letters indicate bits that are already encoded at
20498 this point. Lowercase letters are our problem. For the
20499 second block of instructions, the secondary opcode nybble
20500 (bits 8..11) is present, and bit 23 is zero, even if this is
20501 a PC-relative operation. */
20502 newval = md_chars_to_number (buf, THUMB_SIZE);
20503 newval <<= 16;
20504 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 20505
c19d1205 20506 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 20507 {
c19d1205
ZW
20508 /* Doubleword load/store: 8-bit offset, scaled by 4. */
20509 if (value >= 0)
20510 newval |= (1 << 23);
20511 else
20512 value = -value;
20513 if (value % 4 != 0)
20514 {
20515 as_bad_where (fixP->fx_file, fixP->fx_line,
20516 _("offset not a multiple of 4"));
20517 break;
20518 }
20519 value /= 4;
216d22bc 20520 if (value > 0xff)
c19d1205
ZW
20521 {
20522 as_bad_where (fixP->fx_file, fixP->fx_line,
20523 _("offset out of range"));
20524 break;
20525 }
20526 newval &= ~0xff;
b99bd4ef 20527 }
c19d1205 20528 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 20529 {
c19d1205
ZW
20530 /* PC-relative, 12-bit offset. */
20531 if (value >= 0)
20532 newval |= (1 << 23);
20533 else
20534 value = -value;
216d22bc 20535 if (value > 0xfff)
c19d1205
ZW
20536 {
20537 as_bad_where (fixP->fx_file, fixP->fx_line,
20538 _("offset out of range"));
20539 break;
20540 }
20541 newval &= ~0xfff;
b99bd4ef 20542 }
c19d1205 20543 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 20544 {
c19d1205
ZW
20545 /* Writeback: 8-bit, +/- offset. */
20546 if (value >= 0)
20547 newval |= (1 << 9);
20548 else
20549 value = -value;
216d22bc 20550 if (value > 0xff)
c19d1205
ZW
20551 {
20552 as_bad_where (fixP->fx_file, fixP->fx_line,
20553 _("offset out of range"));
20554 break;
20555 }
20556 newval &= ~0xff;
b99bd4ef 20557 }
c19d1205 20558 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 20559 {
c19d1205 20560 /* T-instruction: positive 8-bit offset. */
216d22bc 20561 if (value < 0 || value > 0xff)
b99bd4ef 20562 {
c19d1205
ZW
20563 as_bad_where (fixP->fx_file, fixP->fx_line,
20564 _("offset out of range"));
20565 break;
b99bd4ef 20566 }
c19d1205
ZW
20567 newval &= ~0xff;
20568 newval |= value;
b99bd4ef
NC
20569 }
20570 else
b99bd4ef 20571 {
c19d1205
ZW
20572 /* Positive 12-bit or negative 8-bit offset. */
20573 int limit;
20574 if (value >= 0)
b99bd4ef 20575 {
c19d1205
ZW
20576 newval |= (1 << 23);
20577 limit = 0xfff;
20578 }
20579 else
20580 {
20581 value = -value;
20582 limit = 0xff;
20583 }
20584 if (value > limit)
20585 {
20586 as_bad_where (fixP->fx_file, fixP->fx_line,
20587 _("offset out of range"));
20588 break;
b99bd4ef 20589 }
c19d1205 20590 newval &= ~limit;
b99bd4ef 20591 }
b99bd4ef 20592
c19d1205
ZW
20593 newval |= value;
20594 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20595 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20596 break;
404ff6b5 20597
c19d1205
ZW
20598 case BFD_RELOC_ARM_SHIFT_IMM:
20599 newval = md_chars_to_number (buf, INSN_SIZE);
20600 if (((unsigned long) value) > 32
20601 || (value == 32
20602 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20603 {
20604 as_bad_where (fixP->fx_file, fixP->fx_line,
20605 _("shift expression is too large"));
20606 break;
20607 }
404ff6b5 20608
c19d1205
ZW
20609 if (value == 0)
20610 /* Shifts of zero must be done as lsl. */
20611 newval &= ~0x60;
20612 else if (value == 32)
20613 value = 0;
20614 newval &= 0xfffff07f;
20615 newval |= (value & 0x1f) << 7;
20616 md_number_to_chars (buf, newval, INSN_SIZE);
20617 break;
404ff6b5 20618
c19d1205 20619 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 20620 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 20621 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 20622 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
20623 /* We claim that this fixup has been processed here,
20624 even if in fact we generate an error because we do
20625 not have a reloc for it, so tc_gen_reloc will reject it. */
20626 fixP->fx_done = 1;
404ff6b5 20627
c19d1205
ZW
20628 if (fixP->fx_addsy
20629 && ! S_IS_DEFINED (fixP->fx_addsy))
20630 {
20631 as_bad_where (fixP->fx_file, fixP->fx_line,
20632 _("undefined symbol %s used as an immediate value"),
20633 S_GET_NAME (fixP->fx_addsy));
20634 break;
20635 }
404ff6b5 20636
c19d1205
ZW
20637 newval = md_chars_to_number (buf, THUMB_SIZE);
20638 newval <<= 16;
20639 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 20640
16805f35
PB
20641 newimm = FAIL;
20642 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20643 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
20644 {
20645 newimm = encode_thumb32_immediate (value);
20646 if (newimm == (unsigned int) FAIL)
20647 newimm = thumb32_negate_data_op (&newval, value);
20648 }
16805f35
PB
20649 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20650 && newimm == (unsigned int) FAIL)
92e90b6e 20651 {
16805f35
PB
20652 /* Turn add/sum into addw/subw. */
20653 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20654 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
20655 /* No flat 12-bit imm encoding for addsw/subsw. */
20656 if ((newval & 0x00100000) == 0)
e9f89963 20657 {
40f246e3
NC
20658 /* 12 bit immediate for addw/subw. */
20659 if (value < 0)
20660 {
20661 value = -value;
20662 newval ^= 0x00a00000;
20663 }
20664 if (value > 0xfff)
20665 newimm = (unsigned int) FAIL;
20666 else
20667 newimm = value;
e9f89963 20668 }
92e90b6e 20669 }
cc8a6dd0 20670
c19d1205 20671 if (newimm == (unsigned int)FAIL)
3631a3c8 20672 {
c19d1205
ZW
20673 as_bad_where (fixP->fx_file, fixP->fx_line,
20674 _("invalid constant (%lx) after fixup"),
20675 (unsigned long) value);
20676 break;
3631a3c8
NC
20677 }
20678
c19d1205
ZW
20679 newval |= (newimm & 0x800) << 15;
20680 newval |= (newimm & 0x700) << 4;
20681 newval |= (newimm & 0x0ff);
cc8a6dd0 20682
c19d1205
ZW
20683 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20684 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20685 break;
a737bd4d 20686
3eb17e6b 20687 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
20688 if (((unsigned long) value) > 0xffff)
20689 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 20690 _("invalid smc expression"));
2fc8bdac 20691 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20692 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20693 md_number_to_chars (buf, newval, INSN_SIZE);
20694 break;
a737bd4d 20695
90ec0d68
MGD
20696 case BFD_RELOC_ARM_HVC:
20697 if (((unsigned long) value) > 0xffff)
20698 as_bad_where (fixP->fx_file, fixP->fx_line,
20699 _("invalid hvc expression"));
20700 newval = md_chars_to_number (buf, INSN_SIZE);
20701 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20702 md_number_to_chars (buf, newval, INSN_SIZE);
20703 break;
20704
c19d1205 20705 case BFD_RELOC_ARM_SWI:
adbaf948 20706 if (fixP->tc_fix_data != 0)
c19d1205
ZW
20707 {
20708 if (((unsigned long) value) > 0xff)
20709 as_bad_where (fixP->fx_file, fixP->fx_line,
20710 _("invalid swi expression"));
2fc8bdac 20711 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
20712 newval |= value;
20713 md_number_to_chars (buf, newval, THUMB_SIZE);
20714 }
20715 else
20716 {
20717 if (((unsigned long) value) > 0x00ffffff)
20718 as_bad_where (fixP->fx_file, fixP->fx_line,
20719 _("invalid swi expression"));
2fc8bdac 20720 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20721 newval |= value;
20722 md_number_to_chars (buf, newval, INSN_SIZE);
20723 }
20724 break;
a737bd4d 20725
c19d1205
ZW
20726 case BFD_RELOC_ARM_MULTI:
20727 if (((unsigned long) value) > 0xffff)
20728 as_bad_where (fixP->fx_file, fixP->fx_line,
20729 _("invalid expression in load/store multiple"));
20730 newval = value | md_chars_to_number (buf, INSN_SIZE);
20731 md_number_to_chars (buf, newval, INSN_SIZE);
20732 break;
a737bd4d 20733
c19d1205 20734#ifdef OBJ_ELF
39b41c9c 20735 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
20736
20737 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20738 && fixP->fx_addsy
34e77a92 20739 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20740 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20741 && THUMB_IS_FUNC (fixP->fx_addsy))
20742 /* Flip the bl to blx. This is a simple flip
20743 bit here because we generate PCREL_CALL for
20744 unconditional bls. */
20745 {
20746 newval = md_chars_to_number (buf, INSN_SIZE);
20747 newval = newval | 0x10000000;
20748 md_number_to_chars (buf, newval, INSN_SIZE);
20749 temp = 1;
20750 fixP->fx_done = 1;
20751 }
39b41c9c
PB
20752 else
20753 temp = 3;
20754 goto arm_branch_common;
20755
20756 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
20757 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20758 && fixP->fx_addsy
34e77a92 20759 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20760 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20761 && THUMB_IS_FUNC (fixP->fx_addsy))
20762 {
20763 /* This would map to a bl<cond>, b<cond>,
20764 b<always> to a Thumb function. We
20765 need to force a relocation for this particular
20766 case. */
20767 newval = md_chars_to_number (buf, INSN_SIZE);
20768 fixP->fx_done = 0;
20769 }
20770
2fc8bdac 20771 case BFD_RELOC_ARM_PLT32:
c19d1205 20772#endif
39b41c9c
PB
20773 case BFD_RELOC_ARM_PCREL_BRANCH:
20774 temp = 3;
20775 goto arm_branch_common;
a737bd4d 20776
39b41c9c 20777 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 20778
39b41c9c 20779 temp = 1;
267bf995
RR
20780 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20781 && fixP->fx_addsy
34e77a92 20782 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20783 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20784 && ARM_IS_FUNC (fixP->fx_addsy))
20785 {
20786 /* Flip the blx to a bl and warn. */
20787 const char *name = S_GET_NAME (fixP->fx_addsy);
20788 newval = 0xeb000000;
20789 as_warn_where (fixP->fx_file, fixP->fx_line,
20790 _("blx to '%s' an ARM ISA state function changed to bl"),
20791 name);
20792 md_number_to_chars (buf, newval, INSN_SIZE);
20793 temp = 3;
20794 fixP->fx_done = 1;
20795 }
20796
20797#ifdef OBJ_ELF
20798 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20799 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20800#endif
20801
39b41c9c 20802 arm_branch_common:
c19d1205 20803 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
20804 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20805 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20806 also be be clear. */
20807 if (value & temp)
c19d1205 20808 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
20809 _("misaligned branch destination"));
20810 if ((value & (offsetT)0xfe000000) != (offsetT)0
20811 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20812 as_bad_where (fixP->fx_file, fixP->fx_line,
20813 _("branch out of range"));
a737bd4d 20814
2fc8bdac 20815 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20816 {
2fc8bdac
ZW
20817 newval = md_chars_to_number (buf, INSN_SIZE);
20818 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
20819 /* Set the H bit on BLX instructions. */
20820 if (temp == 1)
20821 {
20822 if (value & 2)
20823 newval |= 0x01000000;
20824 else
20825 newval &= ~0x01000000;
20826 }
2fc8bdac 20827 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 20828 }
c19d1205 20829 break;
a737bd4d 20830
25fe350b
MS
20831 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20832 /* CBZ can only branch forward. */
a737bd4d 20833
738755b0
MS
20834 /* Attempts to use CBZ to branch to the next instruction
20835 (which, strictly speaking, are prohibited) will be turned into
20836 no-ops.
20837
20838 FIXME: It may be better to remove the instruction completely and
20839 perform relaxation. */
20840 if (value == -2)
2fc8bdac
ZW
20841 {
20842 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 20843 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
20844 md_number_to_chars (buf, newval, THUMB_SIZE);
20845 }
738755b0
MS
20846 else
20847 {
20848 if (value & ~0x7e)
20849 as_bad_where (fixP->fx_file, fixP->fx_line,
20850 _("branch out of range"));
20851
20852 if (fixP->fx_done || !seg->use_rela_p)
20853 {
20854 newval = md_chars_to_number (buf, THUMB_SIZE);
20855 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20856 md_number_to_chars (buf, newval, THUMB_SIZE);
20857 }
20858 }
c19d1205 20859 break;
a737bd4d 20860
c19d1205 20861 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
20862 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20863 as_bad_where (fixP->fx_file, fixP->fx_line,
20864 _("branch out of range"));
a737bd4d 20865
2fc8bdac
ZW
20866 if (fixP->fx_done || !seg->use_rela_p)
20867 {
20868 newval = md_chars_to_number (buf, THUMB_SIZE);
20869 newval |= (value & 0x1ff) >> 1;
20870 md_number_to_chars (buf, newval, THUMB_SIZE);
20871 }
c19d1205 20872 break;
a737bd4d 20873
c19d1205 20874 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
20875 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20876 as_bad_where (fixP->fx_file, fixP->fx_line,
20877 _("branch out of range"));
a737bd4d 20878
2fc8bdac
ZW
20879 if (fixP->fx_done || !seg->use_rela_p)
20880 {
20881 newval = md_chars_to_number (buf, THUMB_SIZE);
20882 newval |= (value & 0xfff) >> 1;
20883 md_number_to_chars (buf, newval, THUMB_SIZE);
20884 }
c19d1205 20885 break;
a737bd4d 20886
c19d1205 20887 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
20888 if (fixP->fx_addsy
20889 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20890 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20891 && ARM_IS_FUNC (fixP->fx_addsy)
20892 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20893 {
20894 /* Force a relocation for a branch 20 bits wide. */
20895 fixP->fx_done = 0;
20896 }
2fc8bdac
ZW
20897 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20898 as_bad_where (fixP->fx_file, fixP->fx_line,
20899 _("conditional branch out of range"));
404ff6b5 20900
2fc8bdac
ZW
20901 if (fixP->fx_done || !seg->use_rela_p)
20902 {
20903 offsetT newval2;
20904 addressT S, J1, J2, lo, hi;
404ff6b5 20905
2fc8bdac
ZW
20906 S = (value & 0x00100000) >> 20;
20907 J2 = (value & 0x00080000) >> 19;
20908 J1 = (value & 0x00040000) >> 18;
20909 hi = (value & 0x0003f000) >> 12;
20910 lo = (value & 0x00000ffe) >> 1;
6c43fab6 20911
2fc8bdac
ZW
20912 newval = md_chars_to_number (buf, THUMB_SIZE);
20913 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20914 newval |= (S << 10) | hi;
20915 newval2 |= (J1 << 13) | (J2 << 11) | lo;
20916 md_number_to_chars (buf, newval, THUMB_SIZE);
20917 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20918 }
c19d1205 20919 break;
6c43fab6 20920
c19d1205 20921 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
20922
20923 /* If there is a blx from a thumb state function to
20924 another thumb function flip this to a bl and warn
20925 about it. */
20926
20927 if (fixP->fx_addsy
34e77a92 20928 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20929 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20930 && THUMB_IS_FUNC (fixP->fx_addsy))
20931 {
20932 const char *name = S_GET_NAME (fixP->fx_addsy);
20933 as_warn_where (fixP->fx_file, fixP->fx_line,
20934 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
20935 name);
20936 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20937 newval = newval | 0x1000;
20938 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20939 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20940 fixP->fx_done = 1;
20941 }
20942
20943
20944 goto thumb_bl_common;
20945
c19d1205 20946 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
20947
20948 /* A bl from Thumb state ISA to an internal ARM state function
20949 is converted to a blx. */
20950 if (fixP->fx_addsy
20951 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20952 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20953 && ARM_IS_FUNC (fixP->fx_addsy)
20954 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20955 {
20956 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20957 newval = newval & ~0x1000;
20958 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20959 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
20960 fixP->fx_done = 1;
20961 }
20962
20963 thumb_bl_common:
20964
20965#ifdef OBJ_ELF
20966 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
20967 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20968 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20969#endif
20970
2fc8bdac
ZW
20971 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20972 /* For a BLX instruction, make sure that the relocation is rounded up
20973 to a word boundary. This follows the semantics of the instruction
20974 which specifies that bit 1 of the target address will come from bit
20975 1 of the base address. */
20976 value = (value + 1) & ~ 1;
404ff6b5 20977
2fc8bdac 20978
4a42ebbc
RR
20979 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
20980 {
20981 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
20982 {
20983 as_bad_where (fixP->fx_file, fixP->fx_line,
20984 _("branch out of range"));
20985 }
20986 else if ((value & ~0x1ffffff)
20987 && ((value & ~0x1ffffff) != ~0x1ffffff))
20988 {
20989 as_bad_where (fixP->fx_file, fixP->fx_line,
20990 _("Thumb2 branch out of range"));
20991 }
c19d1205 20992 }
4a42ebbc
RR
20993
20994 if (fixP->fx_done || !seg->use_rela_p)
20995 encode_thumb2_b_bl_offset (buf, value);
20996
c19d1205 20997 break;
404ff6b5 20998
c19d1205 20999 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
21000 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
21001 as_bad_where (fixP->fx_file, fixP->fx_line,
21002 _("branch out of range"));
6c43fab6 21003
2fc8bdac 21004 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 21005 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 21006
2fc8bdac 21007 break;
a737bd4d 21008
2fc8bdac
ZW
21009 case BFD_RELOC_8:
21010 if (fixP->fx_done || !seg->use_rela_p)
21011 md_number_to_chars (buf, value, 1);
c19d1205 21012 break;
a737bd4d 21013
c19d1205 21014 case BFD_RELOC_16:
2fc8bdac 21015 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 21016 md_number_to_chars (buf, value, 2);
c19d1205 21017 break;
a737bd4d 21018
c19d1205 21019#ifdef OBJ_ELF
0855e32b
NS
21020 case BFD_RELOC_ARM_TLS_CALL:
21021 case BFD_RELOC_ARM_THM_TLS_CALL:
21022 case BFD_RELOC_ARM_TLS_DESCSEQ:
21023 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
21024 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21025 break;
21026
21027 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
21028 case BFD_RELOC_ARM_TLS_GD32:
21029 case BFD_RELOC_ARM_TLS_LE32:
21030 case BFD_RELOC_ARM_TLS_IE32:
21031 case BFD_RELOC_ARM_TLS_LDM32:
21032 case BFD_RELOC_ARM_TLS_LDO32:
21033 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21034 /* fall through */
6c43fab6 21035
c19d1205
ZW
21036 case BFD_RELOC_ARM_GOT32:
21037 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
21038 if (fixP->fx_done || !seg->use_rela_p)
21039 md_number_to_chars (buf, 0, 4);
c19d1205 21040 break;
b43420e6
NC
21041
21042 case BFD_RELOC_ARM_GOT_PREL:
21043 if (fixP->fx_done || !seg->use_rela_p)
21044 md_number_to_chars (buf, value, 4);
21045 break;
21046
9a6f4e97
NS
21047 case BFD_RELOC_ARM_TARGET2:
21048 /* TARGET2 is not partial-inplace, so we need to write the
21049 addend here for REL targets, because it won't be written out
21050 during reloc processing later. */
21051 if (fixP->fx_done || !seg->use_rela_p)
21052 md_number_to_chars (buf, fixP->fx_offset, 4);
21053 break;
c19d1205 21054#endif
6c43fab6 21055
c19d1205
ZW
21056 case BFD_RELOC_RVA:
21057 case BFD_RELOC_32:
21058 case BFD_RELOC_ARM_TARGET1:
21059 case BFD_RELOC_ARM_ROSEGREL32:
21060 case BFD_RELOC_ARM_SBREL32:
21061 case BFD_RELOC_32_PCREL:
f0927246
NC
21062#ifdef TE_PE
21063 case BFD_RELOC_32_SECREL:
21064#endif
2fc8bdac 21065 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
21066#ifdef TE_WINCE
21067 /* For WinCE we only do this for pcrel fixups. */
21068 if (fixP->fx_done || fixP->fx_pcrel)
21069#endif
21070 md_number_to_chars (buf, value, 4);
c19d1205 21071 break;
6c43fab6 21072
c19d1205
ZW
21073#ifdef OBJ_ELF
21074 case BFD_RELOC_ARM_PREL31:
2fc8bdac 21075 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
21076 {
21077 newval = md_chars_to_number (buf, 4) & 0x80000000;
21078 if ((value ^ (value >> 1)) & 0x40000000)
21079 {
21080 as_bad_where (fixP->fx_file, fixP->fx_line,
21081 _("rel31 relocation overflow"));
21082 }
21083 newval |= value & 0x7fffffff;
21084 md_number_to_chars (buf, newval, 4);
21085 }
21086 break;
c19d1205 21087#endif
a737bd4d 21088
c19d1205 21089 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 21090 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
21091 if (value < -1023 || value > 1023 || (value & 3))
21092 as_bad_where (fixP->fx_file, fixP->fx_line,
21093 _("co-processor offset out of range"));
21094 cp_off_common:
21095 sign = value >= 0;
21096 if (value < 0)
21097 value = -value;
8f06b2d8
PB
21098 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21099 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21100 newval = md_chars_to_number (buf, INSN_SIZE);
21101 else
21102 newval = get_thumb32_insn (buf);
21103 newval &= 0xff7fff00;
c19d1205 21104 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
21105 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21106 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21107 md_number_to_chars (buf, newval, INSN_SIZE);
21108 else
21109 put_thumb32_insn (buf, newval);
c19d1205 21110 break;
a737bd4d 21111
c19d1205 21112 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 21113 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
21114 if (value < -255 || value > 255)
21115 as_bad_where (fixP->fx_file, fixP->fx_line,
21116 _("co-processor offset out of range"));
df7849c5 21117 value *= 4;
c19d1205 21118 goto cp_off_common;
6c43fab6 21119
c19d1205
ZW
21120 case BFD_RELOC_ARM_THUMB_OFFSET:
21121 newval = md_chars_to_number (buf, THUMB_SIZE);
21122 /* Exactly what ranges, and where the offset is inserted depends
21123 on the type of instruction, we can establish this from the
21124 top 4 bits. */
21125 switch (newval >> 12)
21126 {
21127 case 4: /* PC load. */
21128 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
21129 forced to zero for these loads; md_pcrel_from has already
21130 compensated for this. */
21131 if (value & 3)
21132 as_bad_where (fixP->fx_file, fixP->fx_line,
21133 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
21134 (((unsigned long) fixP->fx_frag->fr_address
21135 + (unsigned long) fixP->fx_where) & ~3)
21136 + (unsigned long) value);
a737bd4d 21137
c19d1205
ZW
21138 if (value & ~0x3fc)
21139 as_bad_where (fixP->fx_file, fixP->fx_line,
21140 _("invalid offset, value too big (0x%08lX)"),
21141 (long) value);
a737bd4d 21142
c19d1205
ZW
21143 newval |= value >> 2;
21144 break;
a737bd4d 21145
c19d1205
ZW
21146 case 9: /* SP load/store. */
21147 if (value & ~0x3fc)
21148 as_bad_where (fixP->fx_file, fixP->fx_line,
21149 _("invalid offset, value too big (0x%08lX)"),
21150 (long) value);
21151 newval |= value >> 2;
21152 break;
6c43fab6 21153
c19d1205
ZW
21154 case 6: /* Word load/store. */
21155 if (value & ~0x7c)
21156 as_bad_where (fixP->fx_file, fixP->fx_line,
21157 _("invalid offset, value too big (0x%08lX)"),
21158 (long) value);
21159 newval |= value << 4; /* 6 - 2. */
21160 break;
a737bd4d 21161
c19d1205
ZW
21162 case 7: /* Byte load/store. */
21163 if (value & ~0x1f)
21164 as_bad_where (fixP->fx_file, fixP->fx_line,
21165 _("invalid offset, value too big (0x%08lX)"),
21166 (long) value);
21167 newval |= value << 6;
21168 break;
a737bd4d 21169
c19d1205
ZW
21170 case 8: /* Halfword load/store. */
21171 if (value & ~0x3e)
21172 as_bad_where (fixP->fx_file, fixP->fx_line,
21173 _("invalid offset, value too big (0x%08lX)"),
21174 (long) value);
21175 newval |= value << 5; /* 6 - 1. */
21176 break;
a737bd4d 21177
c19d1205
ZW
21178 default:
21179 as_bad_where (fixP->fx_file, fixP->fx_line,
21180 "Unable to process relocation for thumb opcode: %lx",
21181 (unsigned long) newval);
21182 break;
21183 }
21184 md_number_to_chars (buf, newval, THUMB_SIZE);
21185 break;
a737bd4d 21186
c19d1205
ZW
21187 case BFD_RELOC_ARM_THUMB_ADD:
21188 /* This is a complicated relocation, since we use it for all of
21189 the following immediate relocations:
a737bd4d 21190
c19d1205
ZW
21191 3bit ADD/SUB
21192 8bit ADD/SUB
21193 9bit ADD/SUB SP word-aligned
21194 10bit ADD PC/SP word-aligned
a737bd4d 21195
c19d1205
ZW
21196 The type of instruction being processed is encoded in the
21197 instruction field:
a737bd4d 21198
c19d1205
ZW
21199 0x8000 SUB
21200 0x00F0 Rd
21201 0x000F Rs
21202 */
21203 newval = md_chars_to_number (buf, THUMB_SIZE);
21204 {
21205 int rd = (newval >> 4) & 0xf;
21206 int rs = newval & 0xf;
21207 int subtract = !!(newval & 0x8000);
a737bd4d 21208
c19d1205
ZW
21209 /* Check for HI regs, only very restricted cases allowed:
21210 Adjusting SP, and using PC or SP to get an address. */
21211 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
21212 || (rs > 7 && rs != REG_SP && rs != REG_PC))
21213 as_bad_where (fixP->fx_file, fixP->fx_line,
21214 _("invalid Hi register with immediate"));
a737bd4d 21215
c19d1205
ZW
21216 /* If value is negative, choose the opposite instruction. */
21217 if (value < 0)
21218 {
21219 value = -value;
21220 subtract = !subtract;
21221 if (value < 0)
21222 as_bad_where (fixP->fx_file, fixP->fx_line,
21223 _("immediate value out of range"));
21224 }
a737bd4d 21225
c19d1205
ZW
21226 if (rd == REG_SP)
21227 {
21228 if (value & ~0x1fc)
21229 as_bad_where (fixP->fx_file, fixP->fx_line,
21230 _("invalid immediate for stack address calculation"));
21231 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
21232 newval |= value >> 2;
21233 }
21234 else if (rs == REG_PC || rs == REG_SP)
21235 {
21236 if (subtract || value & ~0x3fc)
21237 as_bad_where (fixP->fx_file, fixP->fx_line,
21238 _("invalid immediate for address calculation (value = 0x%08lX)"),
21239 (unsigned long) value);
21240 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
21241 newval |= rd << 8;
21242 newval |= value >> 2;
21243 }
21244 else if (rs == rd)
21245 {
21246 if (value & ~0xff)
21247 as_bad_where (fixP->fx_file, fixP->fx_line,
21248 _("immediate value out of range"));
21249 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
21250 newval |= (rd << 8) | value;
21251 }
21252 else
21253 {
21254 if (value & ~0x7)
21255 as_bad_where (fixP->fx_file, fixP->fx_line,
21256 _("immediate value out of range"));
21257 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
21258 newval |= rd | (rs << 3) | (value << 6);
21259 }
21260 }
21261 md_number_to_chars (buf, newval, THUMB_SIZE);
21262 break;
a737bd4d 21263
c19d1205
ZW
21264 case BFD_RELOC_ARM_THUMB_IMM:
21265 newval = md_chars_to_number (buf, THUMB_SIZE);
21266 if (value < 0 || value > 255)
21267 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 21268 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
21269 (long) value);
21270 newval |= value;
21271 md_number_to_chars (buf, newval, THUMB_SIZE);
21272 break;
a737bd4d 21273
c19d1205
ZW
21274 case BFD_RELOC_ARM_THUMB_SHIFT:
21275 /* 5bit shift value (0..32). LSL cannot take 32. */
21276 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
21277 temp = newval & 0xf800;
21278 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
21279 as_bad_where (fixP->fx_file, fixP->fx_line,
21280 _("invalid shift value: %ld"), (long) value);
21281 /* Shifts of zero must be encoded as LSL. */
21282 if (value == 0)
21283 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
21284 /* Shifts of 32 are encoded as zero. */
21285 else if (value == 32)
21286 value = 0;
21287 newval |= value << 6;
21288 md_number_to_chars (buf, newval, THUMB_SIZE);
21289 break;
a737bd4d 21290
c19d1205
ZW
21291 case BFD_RELOC_VTABLE_INHERIT:
21292 case BFD_RELOC_VTABLE_ENTRY:
21293 fixP->fx_done = 0;
21294 return;
6c43fab6 21295
b6895b4f
PB
21296 case BFD_RELOC_ARM_MOVW:
21297 case BFD_RELOC_ARM_MOVT:
21298 case BFD_RELOC_ARM_THUMB_MOVW:
21299 case BFD_RELOC_ARM_THUMB_MOVT:
21300 if (fixP->fx_done || !seg->use_rela_p)
21301 {
21302 /* REL format relocations are limited to a 16-bit addend. */
21303 if (!fixP->fx_done)
21304 {
39623e12 21305 if (value < -0x8000 || value > 0x7fff)
b6895b4f 21306 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 21307 _("offset out of range"));
b6895b4f
PB
21308 }
21309 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21310 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21311 {
21312 value >>= 16;
21313 }
21314
21315 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21316 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21317 {
21318 newval = get_thumb32_insn (buf);
21319 newval &= 0xfbf08f00;
21320 newval |= (value & 0xf000) << 4;
21321 newval |= (value & 0x0800) << 15;
21322 newval |= (value & 0x0700) << 4;
21323 newval |= (value & 0x00ff);
21324 put_thumb32_insn (buf, newval);
21325 }
21326 else
21327 {
21328 newval = md_chars_to_number (buf, 4);
21329 newval &= 0xfff0f000;
21330 newval |= value & 0x0fff;
21331 newval |= (value & 0xf000) << 4;
21332 md_number_to_chars (buf, newval, 4);
21333 }
21334 }
21335 return;
21336
4962c51a
MS
21337 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21338 case BFD_RELOC_ARM_ALU_PC_G0:
21339 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21340 case BFD_RELOC_ARM_ALU_PC_G1:
21341 case BFD_RELOC_ARM_ALU_PC_G2:
21342 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21343 case BFD_RELOC_ARM_ALU_SB_G0:
21344 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21345 case BFD_RELOC_ARM_ALU_SB_G1:
21346 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 21347 gas_assert (!fixP->fx_done);
4962c51a
MS
21348 if (!seg->use_rela_p)
21349 {
21350 bfd_vma insn;
21351 bfd_vma encoded_addend;
21352 bfd_vma addend_abs = abs (value);
21353
21354 /* Check that the absolute value of the addend can be
21355 expressed as an 8-bit constant plus a rotation. */
21356 encoded_addend = encode_arm_immediate (addend_abs);
21357 if (encoded_addend == (unsigned int) FAIL)
21358 as_bad_where (fixP->fx_file, fixP->fx_line,
21359 _("the offset 0x%08lX is not representable"),
495bde8e 21360 (unsigned long) addend_abs);
4962c51a
MS
21361
21362 /* Extract the instruction. */
21363 insn = md_chars_to_number (buf, INSN_SIZE);
21364
21365 /* If the addend is positive, use an ADD instruction.
21366 Otherwise use a SUB. Take care not to destroy the S bit. */
21367 insn &= 0xff1fffff;
21368 if (value < 0)
21369 insn |= 1 << 22;
21370 else
21371 insn |= 1 << 23;
21372
21373 /* Place the encoded addend into the first 12 bits of the
21374 instruction. */
21375 insn &= 0xfffff000;
21376 insn |= encoded_addend;
5f4273c7
NC
21377
21378 /* Update the instruction. */
4962c51a
MS
21379 md_number_to_chars (buf, insn, INSN_SIZE);
21380 }
21381 break;
21382
21383 case BFD_RELOC_ARM_LDR_PC_G0:
21384 case BFD_RELOC_ARM_LDR_PC_G1:
21385 case BFD_RELOC_ARM_LDR_PC_G2:
21386 case BFD_RELOC_ARM_LDR_SB_G0:
21387 case BFD_RELOC_ARM_LDR_SB_G1:
21388 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 21389 gas_assert (!fixP->fx_done);
4962c51a
MS
21390 if (!seg->use_rela_p)
21391 {
21392 bfd_vma insn;
21393 bfd_vma addend_abs = abs (value);
21394
21395 /* Check that the absolute value of the addend can be
21396 encoded in 12 bits. */
21397 if (addend_abs >= 0x1000)
21398 as_bad_where (fixP->fx_file, fixP->fx_line,
21399 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 21400 (unsigned long) addend_abs);
4962c51a
MS
21401
21402 /* Extract the instruction. */
21403 insn = md_chars_to_number (buf, INSN_SIZE);
21404
21405 /* If the addend is negative, clear bit 23 of the instruction.
21406 Otherwise set it. */
21407 if (value < 0)
21408 insn &= ~(1 << 23);
21409 else
21410 insn |= 1 << 23;
21411
21412 /* Place the absolute value of the addend into the first 12 bits
21413 of the instruction. */
21414 insn &= 0xfffff000;
21415 insn |= addend_abs;
5f4273c7
NC
21416
21417 /* Update the instruction. */
4962c51a
MS
21418 md_number_to_chars (buf, insn, INSN_SIZE);
21419 }
21420 break;
21421
21422 case BFD_RELOC_ARM_LDRS_PC_G0:
21423 case BFD_RELOC_ARM_LDRS_PC_G1:
21424 case BFD_RELOC_ARM_LDRS_PC_G2:
21425 case BFD_RELOC_ARM_LDRS_SB_G0:
21426 case BFD_RELOC_ARM_LDRS_SB_G1:
21427 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 21428 gas_assert (!fixP->fx_done);
4962c51a
MS
21429 if (!seg->use_rela_p)
21430 {
21431 bfd_vma insn;
21432 bfd_vma addend_abs = abs (value);
21433
21434 /* Check that the absolute value of the addend can be
21435 encoded in 8 bits. */
21436 if (addend_abs >= 0x100)
21437 as_bad_where (fixP->fx_file, fixP->fx_line,
21438 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 21439 (unsigned long) addend_abs);
4962c51a
MS
21440
21441 /* Extract the instruction. */
21442 insn = md_chars_to_number (buf, INSN_SIZE);
21443
21444 /* If the addend is negative, clear bit 23 of the instruction.
21445 Otherwise set it. */
21446 if (value < 0)
21447 insn &= ~(1 << 23);
21448 else
21449 insn |= 1 << 23;
21450
21451 /* Place the first four bits of the absolute value of the addend
21452 into the first 4 bits of the instruction, and the remaining
21453 four into bits 8 .. 11. */
21454 insn &= 0xfffff0f0;
21455 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
21456
21457 /* Update the instruction. */
4962c51a
MS
21458 md_number_to_chars (buf, insn, INSN_SIZE);
21459 }
21460 break;
21461
21462 case BFD_RELOC_ARM_LDC_PC_G0:
21463 case BFD_RELOC_ARM_LDC_PC_G1:
21464 case BFD_RELOC_ARM_LDC_PC_G2:
21465 case BFD_RELOC_ARM_LDC_SB_G0:
21466 case BFD_RELOC_ARM_LDC_SB_G1:
21467 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 21468 gas_assert (!fixP->fx_done);
4962c51a
MS
21469 if (!seg->use_rela_p)
21470 {
21471 bfd_vma insn;
21472 bfd_vma addend_abs = abs (value);
21473
21474 /* Check that the absolute value of the addend is a multiple of
21475 four and, when divided by four, fits in 8 bits. */
21476 if (addend_abs & 0x3)
21477 as_bad_where (fixP->fx_file, fixP->fx_line,
21478 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 21479 (unsigned long) addend_abs);
4962c51a
MS
21480
21481 if ((addend_abs >> 2) > 0xff)
21482 as_bad_where (fixP->fx_file, fixP->fx_line,
21483 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 21484 (unsigned long) addend_abs);
4962c51a
MS
21485
21486 /* Extract the instruction. */
21487 insn = md_chars_to_number (buf, INSN_SIZE);
21488
21489 /* If the addend is negative, clear bit 23 of the instruction.
21490 Otherwise set it. */
21491 if (value < 0)
21492 insn &= ~(1 << 23);
21493 else
21494 insn |= 1 << 23;
21495
21496 /* Place the addend (divided by four) into the first eight
21497 bits of the instruction. */
21498 insn &= 0xfffffff0;
21499 insn |= addend_abs >> 2;
5f4273c7
NC
21500
21501 /* Update the instruction. */
4962c51a
MS
21502 md_number_to_chars (buf, insn, INSN_SIZE);
21503 }
21504 break;
21505
845b51d6
PB
21506 case BFD_RELOC_ARM_V4BX:
21507 /* This will need to go in the object file. */
21508 fixP->fx_done = 0;
21509 break;
21510
c19d1205
ZW
21511 case BFD_RELOC_UNUSED:
21512 default:
21513 as_bad_where (fixP->fx_file, fixP->fx_line,
21514 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
21515 }
6c43fab6
RE
21516}
21517
c19d1205
ZW
21518/* Translate internal representation of relocation info to BFD target
21519 format. */
a737bd4d 21520
c19d1205 21521arelent *
00a97672 21522tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 21523{
c19d1205
ZW
21524 arelent * reloc;
21525 bfd_reloc_code_real_type code;
a737bd4d 21526
21d799b5 21527 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 21528
21d799b5 21529 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
21530 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
21531 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 21532
2fc8bdac 21533 if (fixp->fx_pcrel)
00a97672
RS
21534 {
21535 if (section->use_rela_p)
21536 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
21537 else
21538 fixp->fx_offset = reloc->address;
21539 }
c19d1205 21540 reloc->addend = fixp->fx_offset;
a737bd4d 21541
c19d1205 21542 switch (fixp->fx_r_type)
a737bd4d 21543 {
c19d1205
ZW
21544 case BFD_RELOC_8:
21545 if (fixp->fx_pcrel)
21546 {
21547 code = BFD_RELOC_8_PCREL;
21548 break;
21549 }
a737bd4d 21550
c19d1205
ZW
21551 case BFD_RELOC_16:
21552 if (fixp->fx_pcrel)
21553 {
21554 code = BFD_RELOC_16_PCREL;
21555 break;
21556 }
6c43fab6 21557
c19d1205
ZW
21558 case BFD_RELOC_32:
21559 if (fixp->fx_pcrel)
21560 {
21561 code = BFD_RELOC_32_PCREL;
21562 break;
21563 }
a737bd4d 21564
b6895b4f
PB
21565 case BFD_RELOC_ARM_MOVW:
21566 if (fixp->fx_pcrel)
21567 {
21568 code = BFD_RELOC_ARM_MOVW_PCREL;
21569 break;
21570 }
21571
21572 case BFD_RELOC_ARM_MOVT:
21573 if (fixp->fx_pcrel)
21574 {
21575 code = BFD_RELOC_ARM_MOVT_PCREL;
21576 break;
21577 }
21578
21579 case BFD_RELOC_ARM_THUMB_MOVW:
21580 if (fixp->fx_pcrel)
21581 {
21582 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21583 break;
21584 }
21585
21586 case BFD_RELOC_ARM_THUMB_MOVT:
21587 if (fixp->fx_pcrel)
21588 {
21589 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21590 break;
21591 }
21592
c19d1205
ZW
21593 case BFD_RELOC_NONE:
21594 case BFD_RELOC_ARM_PCREL_BRANCH:
21595 case BFD_RELOC_ARM_PCREL_BLX:
21596 case BFD_RELOC_RVA:
21597 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21598 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21599 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21600 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21601 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21602 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
21603 case BFD_RELOC_VTABLE_ENTRY:
21604 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
21605#ifdef TE_PE
21606 case BFD_RELOC_32_SECREL:
21607#endif
c19d1205
ZW
21608 code = fixp->fx_r_type;
21609 break;
a737bd4d 21610
00adf2d4
JB
21611 case BFD_RELOC_THUMB_PCREL_BLX:
21612#ifdef OBJ_ELF
21613 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21614 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21615 else
21616#endif
21617 code = BFD_RELOC_THUMB_PCREL_BLX;
21618 break;
21619
c19d1205
ZW
21620 case BFD_RELOC_ARM_LITERAL:
21621 case BFD_RELOC_ARM_HWLITERAL:
21622 /* If this is called then the a literal has
21623 been referenced across a section boundary. */
21624 as_bad_where (fixp->fx_file, fixp->fx_line,
21625 _("literal referenced across section boundary"));
21626 return NULL;
a737bd4d 21627
c19d1205 21628#ifdef OBJ_ELF
0855e32b
NS
21629 case BFD_RELOC_ARM_TLS_CALL:
21630 case BFD_RELOC_ARM_THM_TLS_CALL:
21631 case BFD_RELOC_ARM_TLS_DESCSEQ:
21632 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
21633 case BFD_RELOC_ARM_GOT32:
21634 case BFD_RELOC_ARM_GOTOFF:
b43420e6 21635 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
21636 case BFD_RELOC_ARM_PLT32:
21637 case BFD_RELOC_ARM_TARGET1:
21638 case BFD_RELOC_ARM_ROSEGREL32:
21639 case BFD_RELOC_ARM_SBREL32:
21640 case BFD_RELOC_ARM_PREL31:
21641 case BFD_RELOC_ARM_TARGET2:
21642 case BFD_RELOC_ARM_TLS_LE32:
21643 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
21644 case BFD_RELOC_ARM_PCREL_CALL:
21645 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
21646 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21647 case BFD_RELOC_ARM_ALU_PC_G0:
21648 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21649 case BFD_RELOC_ARM_ALU_PC_G1:
21650 case BFD_RELOC_ARM_ALU_PC_G2:
21651 case BFD_RELOC_ARM_LDR_PC_G0:
21652 case BFD_RELOC_ARM_LDR_PC_G1:
21653 case BFD_RELOC_ARM_LDR_PC_G2:
21654 case BFD_RELOC_ARM_LDRS_PC_G0:
21655 case BFD_RELOC_ARM_LDRS_PC_G1:
21656 case BFD_RELOC_ARM_LDRS_PC_G2:
21657 case BFD_RELOC_ARM_LDC_PC_G0:
21658 case BFD_RELOC_ARM_LDC_PC_G1:
21659 case BFD_RELOC_ARM_LDC_PC_G2:
21660 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21661 case BFD_RELOC_ARM_ALU_SB_G0:
21662 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21663 case BFD_RELOC_ARM_ALU_SB_G1:
21664 case BFD_RELOC_ARM_ALU_SB_G2:
21665 case BFD_RELOC_ARM_LDR_SB_G0:
21666 case BFD_RELOC_ARM_LDR_SB_G1:
21667 case BFD_RELOC_ARM_LDR_SB_G2:
21668 case BFD_RELOC_ARM_LDRS_SB_G0:
21669 case BFD_RELOC_ARM_LDRS_SB_G1:
21670 case BFD_RELOC_ARM_LDRS_SB_G2:
21671 case BFD_RELOC_ARM_LDC_SB_G0:
21672 case BFD_RELOC_ARM_LDC_SB_G1:
21673 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 21674 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
21675 code = fixp->fx_r_type;
21676 break;
a737bd4d 21677
0855e32b 21678 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
21679 case BFD_RELOC_ARM_TLS_GD32:
21680 case BFD_RELOC_ARM_TLS_IE32:
21681 case BFD_RELOC_ARM_TLS_LDM32:
21682 /* BFD will include the symbol's address in the addend.
21683 But we don't want that, so subtract it out again here. */
21684 if (!S_IS_COMMON (fixp->fx_addsy))
21685 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21686 code = fixp->fx_r_type;
21687 break;
21688#endif
a737bd4d 21689
c19d1205
ZW
21690 case BFD_RELOC_ARM_IMMEDIATE:
21691 as_bad_where (fixp->fx_file, fixp->fx_line,
21692 _("internal relocation (type: IMMEDIATE) not fixed up"));
21693 return NULL;
a737bd4d 21694
c19d1205
ZW
21695 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21696 as_bad_where (fixp->fx_file, fixp->fx_line,
21697 _("ADRL used for a symbol not defined in the same file"));
21698 return NULL;
a737bd4d 21699
c19d1205 21700 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
21701 if (section->use_rela_p)
21702 {
21703 code = fixp->fx_r_type;
21704 break;
21705 }
21706
c19d1205
ZW
21707 if (fixp->fx_addsy != NULL
21708 && !S_IS_DEFINED (fixp->fx_addsy)
21709 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 21710 {
c19d1205
ZW
21711 as_bad_where (fixp->fx_file, fixp->fx_line,
21712 _("undefined local label `%s'"),
21713 S_GET_NAME (fixp->fx_addsy));
21714 return NULL;
a737bd4d
NC
21715 }
21716
c19d1205
ZW
21717 as_bad_where (fixp->fx_file, fixp->fx_line,
21718 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21719 return NULL;
a737bd4d 21720
c19d1205
ZW
21721 default:
21722 {
21723 char * type;
6c43fab6 21724
c19d1205
ZW
21725 switch (fixp->fx_r_type)
21726 {
21727 case BFD_RELOC_NONE: type = "NONE"; break;
21728 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21729 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 21730 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
21731 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21732 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21733 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 21734 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 21735 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
21736 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21737 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21738 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21739 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21740 default: type = _("<unknown>"); break;
21741 }
21742 as_bad_where (fixp->fx_file, fixp->fx_line,
21743 _("cannot represent %s relocation in this object file format"),
21744 type);
21745 return NULL;
21746 }
a737bd4d 21747 }
6c43fab6 21748
c19d1205
ZW
21749#ifdef OBJ_ELF
21750 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21751 && GOT_symbol
21752 && fixp->fx_addsy == GOT_symbol)
21753 {
21754 code = BFD_RELOC_ARM_GOTPC;
21755 reloc->addend = fixp->fx_offset = reloc->address;
21756 }
21757#endif
6c43fab6 21758
c19d1205 21759 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 21760
c19d1205
ZW
21761 if (reloc->howto == NULL)
21762 {
21763 as_bad_where (fixp->fx_file, fixp->fx_line,
21764 _("cannot represent %s relocation in this object file format"),
21765 bfd_get_reloc_code_name (code));
21766 return NULL;
21767 }
6c43fab6 21768
c19d1205
ZW
21769 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21770 vtable entry to be used in the relocation's section offset. */
21771 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21772 reloc->address = fixp->fx_offset;
6c43fab6 21773
c19d1205 21774 return reloc;
6c43fab6
RE
21775}
21776
c19d1205 21777/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 21778
c19d1205
ZW
21779void
21780cons_fix_new_arm (fragS * frag,
21781 int where,
21782 int size,
21783 expressionS * exp)
6c43fab6 21784{
c19d1205
ZW
21785 bfd_reloc_code_real_type type;
21786 int pcrel = 0;
6c43fab6 21787
c19d1205
ZW
21788 /* Pick a reloc.
21789 FIXME: @@ Should look at CPU word size. */
21790 switch (size)
21791 {
21792 case 1:
21793 type = BFD_RELOC_8;
21794 break;
21795 case 2:
21796 type = BFD_RELOC_16;
21797 break;
21798 case 4:
21799 default:
21800 type = BFD_RELOC_32;
21801 break;
21802 case 8:
21803 type = BFD_RELOC_64;
21804 break;
21805 }
6c43fab6 21806
f0927246
NC
21807#ifdef TE_PE
21808 if (exp->X_op == O_secrel)
21809 {
21810 exp->X_op = O_symbol;
21811 type = BFD_RELOC_32_SECREL;
21812 }
21813#endif
21814
c19d1205
ZW
21815 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21816}
6c43fab6 21817
4343666d 21818#if defined (OBJ_COFF)
c19d1205
ZW
21819void
21820arm_validate_fix (fixS * fixP)
6c43fab6 21821{
c19d1205
ZW
21822 /* If the destination of the branch is a defined symbol which does not have
21823 the THUMB_FUNC attribute, then we must be calling a function which has
21824 the (interfacearm) attribute. We look for the Thumb entry point to that
21825 function and change the branch to refer to that function instead. */
21826 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21827 && fixP->fx_addsy != NULL
21828 && S_IS_DEFINED (fixP->fx_addsy)
21829 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 21830 {
c19d1205 21831 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 21832 }
c19d1205
ZW
21833}
21834#endif
6c43fab6 21835
267bf995 21836
c19d1205
ZW
21837int
21838arm_force_relocation (struct fix * fixp)
21839{
21840#if defined (OBJ_COFF) && defined (TE_PE)
21841 if (fixp->fx_r_type == BFD_RELOC_RVA)
21842 return 1;
21843#endif
6c43fab6 21844
267bf995
RR
21845 /* In case we have a call or a branch to a function in ARM ISA mode from
21846 a thumb function or vice-versa force the relocation. These relocations
21847 are cleared off for some cores that might have blx and simple transformations
21848 are possible. */
21849
21850#ifdef OBJ_ELF
21851 switch (fixp->fx_r_type)
21852 {
21853 case BFD_RELOC_ARM_PCREL_JUMP:
21854 case BFD_RELOC_ARM_PCREL_CALL:
21855 case BFD_RELOC_THUMB_PCREL_BLX:
21856 if (THUMB_IS_FUNC (fixp->fx_addsy))
21857 return 1;
21858 break;
21859
21860 case BFD_RELOC_ARM_PCREL_BLX:
21861 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21862 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21863 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21864 if (ARM_IS_FUNC (fixp->fx_addsy))
21865 return 1;
21866 break;
21867
21868 default:
21869 break;
21870 }
21871#endif
21872
c19d1205
ZW
21873 /* Resolve these relocations even if the symbol is extern or weak. */
21874 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21875 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 21876 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 21877 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
21878 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21879 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
21880 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 21881 return 0;
a737bd4d 21882
4962c51a
MS
21883 /* Always leave these relocations for the linker. */
21884 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21885 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21886 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21887 return 1;
21888
f0291e4c
PB
21889 /* Always generate relocations against function symbols. */
21890 if (fixp->fx_r_type == BFD_RELOC_32
21891 && fixp->fx_addsy
21892 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21893 return 1;
21894
c19d1205 21895 return generic_force_reloc (fixp);
404ff6b5
AH
21896}
21897
0ffdc86c 21898#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
21899/* Relocations against function names must be left unadjusted,
21900 so that the linker can use this information to generate interworking
21901 stubs. The MIPS version of this function
c19d1205
ZW
21902 also prevents relocations that are mips-16 specific, but I do not
21903 know why it does this.
404ff6b5 21904
c19d1205
ZW
21905 FIXME:
21906 There is one other problem that ought to be addressed here, but
21907 which currently is not: Taking the address of a label (rather
21908 than a function) and then later jumping to that address. Such
21909 addresses also ought to have their bottom bit set (assuming that
21910 they reside in Thumb code), but at the moment they will not. */
404ff6b5 21911
c19d1205
ZW
21912bfd_boolean
21913arm_fix_adjustable (fixS * fixP)
404ff6b5 21914{
c19d1205
ZW
21915 if (fixP->fx_addsy == NULL)
21916 return 1;
404ff6b5 21917
e28387c3
PB
21918 /* Preserve relocations against symbols with function type. */
21919 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 21920 return FALSE;
e28387c3 21921
c19d1205
ZW
21922 if (THUMB_IS_FUNC (fixP->fx_addsy)
21923 && fixP->fx_subsy == NULL)
c921be7d 21924 return FALSE;
a737bd4d 21925
c19d1205
ZW
21926 /* We need the symbol name for the VTABLE entries. */
21927 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
21928 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 21929 return FALSE;
404ff6b5 21930
c19d1205
ZW
21931 /* Don't allow symbols to be discarded on GOT related relocs. */
21932 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
21933 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
21934 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
21935 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
21936 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
21937 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
21938 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
21939 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
21940 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
21941 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
21942 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
21943 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
21944 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 21945 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 21946 return FALSE;
a737bd4d 21947
4962c51a
MS
21948 /* Similarly for group relocations. */
21949 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21950 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21951 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 21952 return FALSE;
4962c51a 21953
79947c54
CD
21954 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
21955 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
21956 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21957 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
21958 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
21959 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21960 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
21961 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
21962 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 21963 return FALSE;
79947c54 21964
c921be7d 21965 return TRUE;
a737bd4d 21966}
0ffdc86c
NC
21967#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
21968
21969#ifdef OBJ_ELF
404ff6b5 21970
c19d1205
ZW
21971const char *
21972elf32_arm_target_format (void)
404ff6b5 21973{
c19d1205
ZW
21974#ifdef TE_SYMBIAN
21975 return (target_big_endian
21976 ? "elf32-bigarm-symbian"
21977 : "elf32-littlearm-symbian");
21978#elif defined (TE_VXWORKS)
21979 return (target_big_endian
21980 ? "elf32-bigarm-vxworks"
21981 : "elf32-littlearm-vxworks");
21982#else
21983 if (target_big_endian)
21984 return "elf32-bigarm";
21985 else
21986 return "elf32-littlearm";
21987#endif
404ff6b5
AH
21988}
21989
c19d1205
ZW
21990void
21991armelf_frob_symbol (symbolS * symp,
21992 int * puntp)
404ff6b5 21993{
c19d1205
ZW
21994 elf_frob_symbol (symp, puntp);
21995}
21996#endif
404ff6b5 21997
c19d1205 21998/* MD interface: Finalization. */
a737bd4d 21999
c19d1205
ZW
22000void
22001arm_cleanup (void)
22002{
22003 literal_pool * pool;
a737bd4d 22004
e07e6e58
NC
22005 /* Ensure that all the IT blocks are properly closed. */
22006 check_it_blocks_finished ();
22007
c19d1205
ZW
22008 for (pool = list_of_pools; pool; pool = pool->next)
22009 {
5f4273c7 22010 /* Put it at the end of the relevant section. */
c19d1205
ZW
22011 subseg_set (pool->section, pool->sub_section);
22012#ifdef OBJ_ELF
22013 arm_elf_change_section ();
22014#endif
22015 s_ltorg (0);
22016 }
404ff6b5
AH
22017}
22018
cd000bff
DJ
22019#ifdef OBJ_ELF
22020/* Remove any excess mapping symbols generated for alignment frags in
22021 SEC. We may have created a mapping symbol before a zero byte
22022 alignment; remove it if there's a mapping symbol after the
22023 alignment. */
22024static void
22025check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
22026 void *dummy ATTRIBUTE_UNUSED)
22027{
22028 segment_info_type *seginfo = seg_info (sec);
22029 fragS *fragp;
22030
22031 if (seginfo == NULL || seginfo->frchainP == NULL)
22032 return;
22033
22034 for (fragp = seginfo->frchainP->frch_root;
22035 fragp != NULL;
22036 fragp = fragp->fr_next)
22037 {
22038 symbolS *sym = fragp->tc_frag_data.last_map;
22039 fragS *next = fragp->fr_next;
22040
22041 /* Variable-sized frags have been converted to fixed size by
22042 this point. But if this was variable-sized to start with,
22043 there will be a fixed-size frag after it. So don't handle
22044 next == NULL. */
22045 if (sym == NULL || next == NULL)
22046 continue;
22047
22048 if (S_GET_VALUE (sym) < next->fr_address)
22049 /* Not at the end of this frag. */
22050 continue;
22051 know (S_GET_VALUE (sym) == next->fr_address);
22052
22053 do
22054 {
22055 if (next->tc_frag_data.first_map != NULL)
22056 {
22057 /* Next frag starts with a mapping symbol. Discard this
22058 one. */
22059 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22060 break;
22061 }
22062
22063 if (next->fr_next == NULL)
22064 {
22065 /* This mapping symbol is at the end of the section. Discard
22066 it. */
22067 know (next->fr_fix == 0 && next->fr_var == 0);
22068 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22069 break;
22070 }
22071
22072 /* As long as we have empty frags without any mapping symbols,
22073 keep looking. */
22074 /* If the next frag is non-empty and does not start with a
22075 mapping symbol, then this mapping symbol is required. */
22076 if (next->fr_address != next->fr_next->fr_address)
22077 break;
22078
22079 next = next->fr_next;
22080 }
22081 while (next != NULL);
22082 }
22083}
22084#endif
22085
c19d1205
ZW
22086/* Adjust the symbol table. This marks Thumb symbols as distinct from
22087 ARM ones. */
404ff6b5 22088
c19d1205
ZW
22089void
22090arm_adjust_symtab (void)
404ff6b5 22091{
c19d1205
ZW
22092#ifdef OBJ_COFF
22093 symbolS * sym;
404ff6b5 22094
c19d1205
ZW
22095 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
22096 {
22097 if (ARM_IS_THUMB (sym))
22098 {
22099 if (THUMB_IS_FUNC (sym))
22100 {
22101 /* Mark the symbol as a Thumb function. */
22102 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
22103 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
22104 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 22105
c19d1205
ZW
22106 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
22107 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
22108 else
22109 as_bad (_("%s: unexpected function type: %d"),
22110 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
22111 }
22112 else switch (S_GET_STORAGE_CLASS (sym))
22113 {
22114 case C_EXT:
22115 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
22116 break;
22117 case C_STAT:
22118 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
22119 break;
22120 case C_LABEL:
22121 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
22122 break;
22123 default:
22124 /* Do nothing. */
22125 break;
22126 }
22127 }
a737bd4d 22128
c19d1205
ZW
22129 if (ARM_IS_INTERWORK (sym))
22130 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 22131 }
c19d1205
ZW
22132#endif
22133#ifdef OBJ_ELF
22134 symbolS * sym;
22135 char bind;
404ff6b5 22136
c19d1205 22137 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 22138 {
c19d1205
ZW
22139 if (ARM_IS_THUMB (sym))
22140 {
22141 elf_symbol_type * elf_sym;
404ff6b5 22142
c19d1205
ZW
22143 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
22144 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 22145
b0796911
PB
22146 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
22147 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
22148 {
22149 /* If it's a .thumb_func, declare it as so,
22150 otherwise tag label as .code 16. */
22151 if (THUMB_IS_FUNC (sym))
35fc36a8
RS
22152 elf_sym->internal_elf_sym.st_target_internal
22153 = ST_BRANCH_TO_THUMB;
3ba67470 22154 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
22155 elf_sym->internal_elf_sym.st_info =
22156 ELF_ST_INFO (bind, STT_ARM_16BIT);
22157 }
22158 }
22159 }
cd000bff
DJ
22160
22161 /* Remove any overlapping mapping symbols generated by alignment frags. */
22162 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
22163 /* Now do generic ELF adjustments. */
22164 elf_adjust_symtab ();
c19d1205 22165#endif
404ff6b5
AH
22166}
22167
c19d1205 22168/* MD interface: Initialization. */
404ff6b5 22169
a737bd4d 22170static void
c19d1205 22171set_constant_flonums (void)
a737bd4d 22172{
c19d1205 22173 int i;
404ff6b5 22174
c19d1205
ZW
22175 for (i = 0; i < NUM_FLOAT_VALS; i++)
22176 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
22177 abort ();
a737bd4d 22178}
404ff6b5 22179
3e9e4fcf
JB
22180/* Auto-select Thumb mode if it's the only available instruction set for the
22181 given architecture. */
22182
22183static void
22184autoselect_thumb_from_cpu_variant (void)
22185{
22186 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
22187 opcode_select (16);
22188}
22189
c19d1205
ZW
22190void
22191md_begin (void)
a737bd4d 22192{
c19d1205
ZW
22193 unsigned mach;
22194 unsigned int i;
404ff6b5 22195
c19d1205
ZW
22196 if ( (arm_ops_hsh = hash_new ()) == NULL
22197 || (arm_cond_hsh = hash_new ()) == NULL
22198 || (arm_shift_hsh = hash_new ()) == NULL
22199 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 22200 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 22201 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
22202 || (arm_reloc_hsh = hash_new ()) == NULL
22203 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
22204 as_fatal (_("virtual memory exhausted"));
22205
22206 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 22207 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 22208 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 22209 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 22210 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 22211 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 22212 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 22213 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 22214 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0
NC
22215 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
22216 (void *) (v7m_psrs + i));
c19d1205 22217 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 22218 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
22219 for (i = 0;
22220 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
22221 i++)
d3ce72d0 22222 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 22223 (void *) (barrier_opt_names + i));
c19d1205
ZW
22224#ifdef OBJ_ELF
22225 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 22226 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
22227#endif
22228
22229 set_constant_flonums ();
404ff6b5 22230
c19d1205
ZW
22231 /* Set the cpu variant based on the command-line options. We prefer
22232 -mcpu= over -march= if both are set (as for GCC); and we prefer
22233 -mfpu= over any other way of setting the floating point unit.
22234 Use of legacy options with new options are faulted. */
e74cfd16 22235 if (legacy_cpu)
404ff6b5 22236 {
e74cfd16 22237 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
22238 as_bad (_("use of old and new-style options to set CPU type"));
22239
22240 mcpu_cpu_opt = legacy_cpu;
404ff6b5 22241 }
e74cfd16 22242 else if (!mcpu_cpu_opt)
c19d1205 22243 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 22244
e74cfd16 22245 if (legacy_fpu)
c19d1205 22246 {
e74cfd16 22247 if (mfpu_opt)
c19d1205 22248 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
22249
22250 mfpu_opt = legacy_fpu;
22251 }
e74cfd16 22252 else if (!mfpu_opt)
03b1477f 22253 {
45eb4c1b
NS
22254#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
22255 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
22256 /* Some environments specify a default FPU. If they don't, infer it
22257 from the processor. */
e74cfd16 22258 if (mcpu_fpu_opt)
03b1477f
RE
22259 mfpu_opt = mcpu_fpu_opt;
22260 else
22261 mfpu_opt = march_fpu_opt;
39c2da32 22262#else
e74cfd16 22263 mfpu_opt = &fpu_default;
39c2da32 22264#endif
03b1477f
RE
22265 }
22266
e74cfd16 22267 if (!mfpu_opt)
03b1477f 22268 {
493cb6ef 22269 if (mcpu_cpu_opt != NULL)
e74cfd16 22270 mfpu_opt = &fpu_default;
493cb6ef 22271 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 22272 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 22273 else
e74cfd16 22274 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
22275 }
22276
ee065d83 22277#ifdef CPU_DEFAULT
e74cfd16 22278 if (!mcpu_cpu_opt)
ee065d83 22279 {
e74cfd16
PB
22280 mcpu_cpu_opt = &cpu_default;
22281 selected_cpu = cpu_default;
ee065d83 22282 }
e74cfd16
PB
22283#else
22284 if (mcpu_cpu_opt)
22285 selected_cpu = *mcpu_cpu_opt;
ee065d83 22286 else
e74cfd16 22287 mcpu_cpu_opt = &arm_arch_any;
ee065d83 22288#endif
03b1477f 22289
e74cfd16 22290 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 22291
3e9e4fcf
JB
22292 autoselect_thumb_from_cpu_variant ();
22293
e74cfd16 22294 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 22295
f17c130b 22296#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 22297 {
7cc69913
NC
22298 unsigned int flags = 0;
22299
22300#if defined OBJ_ELF
22301 flags = meabi_flags;
d507cf36
PB
22302
22303 switch (meabi_flags)
33a392fb 22304 {
d507cf36 22305 case EF_ARM_EABI_UNKNOWN:
7cc69913 22306#endif
d507cf36
PB
22307 /* Set the flags in the private structure. */
22308 if (uses_apcs_26) flags |= F_APCS26;
22309 if (support_interwork) flags |= F_INTERWORK;
22310 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 22311 if (pic_code) flags |= F_PIC;
e74cfd16 22312 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
22313 flags |= F_SOFT_FLOAT;
22314
d507cf36
PB
22315 switch (mfloat_abi_opt)
22316 {
22317 case ARM_FLOAT_ABI_SOFT:
22318 case ARM_FLOAT_ABI_SOFTFP:
22319 flags |= F_SOFT_FLOAT;
22320 break;
33a392fb 22321
d507cf36
PB
22322 case ARM_FLOAT_ABI_HARD:
22323 if (flags & F_SOFT_FLOAT)
22324 as_bad (_("hard-float conflicts with specified fpu"));
22325 break;
22326 }
03b1477f 22327
e74cfd16
PB
22328 /* Using pure-endian doubles (even if soft-float). */
22329 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 22330 flags |= F_VFP_FLOAT;
f17c130b 22331
fde78edd 22332#if defined OBJ_ELF
e74cfd16 22333 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 22334 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
22335 break;
22336
8cb51566 22337 case EF_ARM_EABI_VER4:
3a4a14e9 22338 case EF_ARM_EABI_VER5:
c19d1205 22339 /* No additional flags to set. */
d507cf36
PB
22340 break;
22341
22342 default:
22343 abort ();
22344 }
7cc69913 22345#endif
b99bd4ef
NC
22346 bfd_set_private_flags (stdoutput, flags);
22347
22348 /* We have run out flags in the COFF header to encode the
22349 status of ATPCS support, so instead we create a dummy,
c19d1205 22350 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
22351 if (atpcs)
22352 {
22353 asection * sec;
22354
22355 sec = bfd_make_section (stdoutput, ".arm.atpcs");
22356
22357 if (sec != NULL)
22358 {
22359 bfd_set_section_flags
22360 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
22361 bfd_set_section_size (stdoutput, sec, 0);
22362 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
22363 }
22364 }
7cc69913 22365 }
f17c130b 22366#endif
b99bd4ef
NC
22367
22368 /* Record the CPU type as well. */
2d447fca
JM
22369 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
22370 mach = bfd_mach_arm_iWMMXt2;
22371 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 22372 mach = bfd_mach_arm_iWMMXt;
e74cfd16 22373 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 22374 mach = bfd_mach_arm_XScale;
e74cfd16 22375 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 22376 mach = bfd_mach_arm_ep9312;
e74cfd16 22377 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 22378 mach = bfd_mach_arm_5TE;
e74cfd16 22379 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 22380 {
e74cfd16 22381 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22382 mach = bfd_mach_arm_5T;
22383 else
22384 mach = bfd_mach_arm_5;
22385 }
e74cfd16 22386 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 22387 {
e74cfd16 22388 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22389 mach = bfd_mach_arm_4T;
22390 else
22391 mach = bfd_mach_arm_4;
22392 }
e74cfd16 22393 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 22394 mach = bfd_mach_arm_3M;
e74cfd16
PB
22395 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
22396 mach = bfd_mach_arm_3;
22397 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
22398 mach = bfd_mach_arm_2a;
22399 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
22400 mach = bfd_mach_arm_2;
22401 else
22402 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
22403
22404 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
22405}
22406
c19d1205 22407/* Command line processing. */
b99bd4ef 22408
c19d1205
ZW
22409/* md_parse_option
22410 Invocation line includes a switch not recognized by the base assembler.
22411 See if it's a processor-specific option.
b99bd4ef 22412
c19d1205
ZW
22413 This routine is somewhat complicated by the need for backwards
22414 compatibility (since older releases of gcc can't be changed).
22415 The new options try to make the interface as compatible as
22416 possible with GCC.
b99bd4ef 22417
c19d1205 22418 New options (supported) are:
b99bd4ef 22419
c19d1205
ZW
22420 -mcpu=<cpu name> Assemble for selected processor
22421 -march=<architecture name> Assemble for selected architecture
22422 -mfpu=<fpu architecture> Assemble for selected FPU.
22423 -EB/-mbig-endian Big-endian
22424 -EL/-mlittle-endian Little-endian
22425 -k Generate PIC code
22426 -mthumb Start in Thumb mode
22427 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 22428
278df34e 22429 -m[no-]warn-deprecated Warn about deprecated features
267bf995 22430
c19d1205 22431 For now we will also provide support for:
b99bd4ef 22432
c19d1205
ZW
22433 -mapcs-32 32-bit Program counter
22434 -mapcs-26 26-bit Program counter
22435 -macps-float Floats passed in FP registers
22436 -mapcs-reentrant Reentrant code
22437 -matpcs
22438 (sometime these will probably be replaced with -mapcs=<list of options>
22439 and -matpcs=<list of options>)
b99bd4ef 22440
c19d1205
ZW
22441 The remaining options are only supported for back-wards compatibility.
22442 Cpu variants, the arm part is optional:
22443 -m[arm]1 Currently not supported.
22444 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
22445 -m[arm]3 Arm 3 processor
22446 -m[arm]6[xx], Arm 6 processors
22447 -m[arm]7[xx][t][[d]m] Arm 7 processors
22448 -m[arm]8[10] Arm 8 processors
22449 -m[arm]9[20][tdmi] Arm 9 processors
22450 -mstrongarm[110[0]] StrongARM processors
22451 -mxscale XScale processors
22452 -m[arm]v[2345[t[e]]] Arm architectures
22453 -mall All (except the ARM1)
22454 FP variants:
22455 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
22456 -mfpe-old (No float load/store multiples)
22457 -mvfpxd VFP Single precision
22458 -mvfp All VFP
22459 -mno-fpu Disable all floating point instructions
b99bd4ef 22460
c19d1205
ZW
22461 The following CPU names are recognized:
22462 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
22463 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
22464 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
22465 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
22466 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
22467 arm10t arm10e, arm1020t, arm1020e, arm10200e,
22468 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 22469
c19d1205 22470 */
b99bd4ef 22471
c19d1205 22472const char * md_shortopts = "m:k";
b99bd4ef 22473
c19d1205
ZW
22474#ifdef ARM_BI_ENDIAN
22475#define OPTION_EB (OPTION_MD_BASE + 0)
22476#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 22477#else
c19d1205
ZW
22478#if TARGET_BYTES_BIG_ENDIAN
22479#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 22480#else
c19d1205
ZW
22481#define OPTION_EL (OPTION_MD_BASE + 1)
22482#endif
b99bd4ef 22483#endif
845b51d6 22484#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 22485
c19d1205 22486struct option md_longopts[] =
b99bd4ef 22487{
c19d1205
ZW
22488#ifdef OPTION_EB
22489 {"EB", no_argument, NULL, OPTION_EB},
22490#endif
22491#ifdef OPTION_EL
22492 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 22493#endif
845b51d6 22494 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
22495 {NULL, no_argument, NULL, 0}
22496};
b99bd4ef 22497
c19d1205 22498size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 22499
c19d1205 22500struct arm_option_table
b99bd4ef 22501{
c19d1205
ZW
22502 char *option; /* Option name to match. */
22503 char *help; /* Help information. */
22504 int *var; /* Variable to change. */
22505 int value; /* What to change it to. */
22506 char *deprecated; /* If non-null, print this message. */
22507};
b99bd4ef 22508
c19d1205
ZW
22509struct arm_option_table arm_opts[] =
22510{
22511 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
22512 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
22513 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
22514 &support_interwork, 1, NULL},
22515 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
22516 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
22517 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
22518 1, NULL},
22519 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
22520 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
22521 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
22522 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
22523 NULL},
b99bd4ef 22524
c19d1205
ZW
22525 /* These are recognized by the assembler, but have no affect on code. */
22526 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
22527 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
22528
22529 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
22530 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
22531 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
22532 {NULL, NULL, NULL, 0, NULL}
22533};
22534
22535struct arm_legacy_option_table
22536{
22537 char *option; /* Option name to match. */
22538 const arm_feature_set **var; /* Variable to change. */
22539 const arm_feature_set value; /* What to change it to. */
22540 char *deprecated; /* If non-null, print this message. */
22541};
b99bd4ef 22542
e74cfd16
PB
22543const struct arm_legacy_option_table arm_legacy_opts[] =
22544{
c19d1205
ZW
22545 /* DON'T add any new processors to this list -- we want the whole list
22546 to go away... Add them to the processors table instead. */
e74cfd16
PB
22547 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22548 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22549 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22550 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22551 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22552 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22553 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22554 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22555 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22556 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22557 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22558 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22559 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22560 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22561 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22562 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22563 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22564 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22565 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22566 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22567 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22568 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22569 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22570 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22571 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22572 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22573 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22574 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22575 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22576 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22577 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22578 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22579 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22580 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22581 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22582 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22583 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22584 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22585 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22586 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22587 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22588 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22589 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22590 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22591 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22592 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22593 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22594 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22595 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22596 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22597 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22598 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22599 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22600 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22601 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22602 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22603 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22604 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22605 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22606 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22607 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22608 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22609 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22610 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22611 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22612 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22613 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22614 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22615 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22616 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22617 N_("use -mcpu=strongarm110")},
e74cfd16 22618 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22619 N_("use -mcpu=strongarm1100")},
e74cfd16 22620 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22621 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
22622 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22623 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22624 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 22625
c19d1205 22626 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
22627 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22628 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22629 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22630 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22631 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22632 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22633 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22634 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22635 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22636 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22637 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22638 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22639 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22640 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22641 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22642 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22643 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22644 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 22645
c19d1205 22646 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
22647 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22648 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22649 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22650 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 22651 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 22652
e74cfd16 22653 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 22654};
7ed4c4c5 22655
c19d1205 22656struct arm_cpu_option_table
7ed4c4c5 22657{
c19d1205 22658 char *name;
e74cfd16 22659 const arm_feature_set value;
c19d1205
ZW
22660 /* For some CPUs we assume an FPU unless the user explicitly sets
22661 -mfpu=... */
e74cfd16 22662 const arm_feature_set default_fpu;
ee065d83
PB
22663 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22664 case. */
22665 const char *canonical_name;
c19d1205 22666};
7ed4c4c5 22667
c19d1205
ZW
22668/* This list should, at a minimum, contain all the cpu names
22669 recognized by GCC. */
e74cfd16 22670static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 22671{
ee065d83
PB
22672 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
22673 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
22674 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
22675 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22676 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22677 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22678 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22679 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22680 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22681 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22682 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22683 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22684 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22685 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22686 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22687 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22688 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22689 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22690 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22691 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22692 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22693 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22694 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22695 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22696 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22697 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22698 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22699 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22700 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22701 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22702 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22703 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22704 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22705 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22706 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22707 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22708 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22709 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22710 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22711 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
22712 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22713 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22714 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22715 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
22716 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22717 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
22718 /* For V5 or later processors we default to using VFP; but the user
22719 should really set the FPU type explicitly. */
ee065d83
PB
22720 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22721 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22722 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22723 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22724 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22725 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22726 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22727 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22728 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22729 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22730 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22731 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22732 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22733 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22734 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22735 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22736 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22737 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22738 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22739 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22740 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
4a58c4bd
NC
22741 {"fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22742 {"fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22743 {"fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22744 {"fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
7fac0536 22745 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
22746 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22747 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22748 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22749 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
4ff9b924
MGD
22750 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"},
22751 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"},
ee065d83
PB
22752 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22753 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22754 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22755 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
f4c65163
MGD
22756 {"cortex-a5", ARM_ARCH_V7A_MP_SEC,
22757 FPU_NONE, "Cortex-A5"},
22758 {"cortex-a8", ARM_ARCH_V7A_SEC,
22759 ARM_FEATURE (0, FPU_VFP_V3
5287ad62 22760 | FPU_NEON_EXT_V1),
4ff9b924 22761 "Cortex-A8"},
f4c65163
MGD
22762 {"cortex-a9", ARM_ARCH_V7A_MP_SEC,
22763 ARM_FEATURE (0, FPU_VFP_V3
15290f0a 22764 | FPU_NEON_EXT_V1),
4ff9b924 22765 "Cortex-A9"},
90ec0d68 22766 {"cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
eea54501 22767 FPU_ARCH_NEON_VFP_V4,
dbb1f804 22768 "Cortex-A15"},
4ff9b924
MGD
22769 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"},
22770 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
22771 "Cortex-R4F"},
22772 {"cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"},
22773 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"},
b2a5fbdc
MGD
22774 {"cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"},
22775 {"cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"},
c19d1205 22776 /* ??? XSCALE is really an architecture. */
ee065d83 22777 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22778 /* ??? iwmmxt is not a processor. */
ee065d83 22779 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 22780 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 22781 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22782 /* Maverick */
e07e6e58 22783 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
e74cfd16 22784 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 22785};
7ed4c4c5 22786
c19d1205 22787struct arm_arch_option_table
7ed4c4c5 22788{
c19d1205 22789 char *name;
e74cfd16
PB
22790 const arm_feature_set value;
22791 const arm_feature_set default_fpu;
c19d1205 22792};
7ed4c4c5 22793
c19d1205
ZW
22794/* This list should, at a minimum, contain all the architecture names
22795 recognized by GCC. */
e74cfd16 22796static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
22797{
22798 {"all", ARM_ANY, FPU_ARCH_FPA},
22799 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22800 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22801 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22802 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22803 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22804 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22805 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22806 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22807 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22808 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22809 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22810 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22811 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22812 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22813 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22814 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22815 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22816 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22817 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22818 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22819 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22820 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22821 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22822 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22823 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 22824 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
b2a5fbdc 22825 {"armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP},
62b3e311 22826 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
22827 /* The official spelling of the ARMv7 profile variants is the dashed form.
22828 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
22829 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22830 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22831 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
22832 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22833 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22834 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
9e3c6df6 22835 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
c19d1205
ZW
22836 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22837 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 22838 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 22839 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 22840};
7ed4c4c5 22841
69133863
MGD
22842/* ISA extensions in the co-processor and main instruction set space. */
22843struct arm_option_extension_value_table
c19d1205
ZW
22844{
22845 char *name;
e74cfd16 22846 const arm_feature_set value;
69133863 22847 const arm_feature_set allowed_archs;
c19d1205 22848};
7ed4c4c5 22849
69133863
MGD
22850/* The following table must be in alphabetical order with a NULL last entry.
22851 */
22852static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 22853{
eea54501
MGD
22854 {"idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0),
22855 ARM_FEATURE (ARM_EXT_V7A, 0)},
69133863
MGD
22856 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY},
22857 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY},
22858 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY},
60e5ef9f
MGD
22859 {"mp", ARM_FEATURE (ARM_EXT_MP, 0),
22860 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)},
b2a5fbdc
MGD
22861 {"os", ARM_FEATURE (ARM_EXT_OS, 0),
22862 ARM_FEATURE (ARM_EXT_V6M, 0)},
f4c65163
MGD
22863 {"sec", ARM_FEATURE (ARM_EXT_SEC, 0),
22864 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)},
90ec0d68
MGD
22865 {"virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV | ARM_EXT_DIV, 0),
22866 ARM_FEATURE (ARM_EXT_V7A, 0)},
69133863 22867 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY},
60e5ef9f 22868 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
69133863
MGD
22869};
22870
22871/* ISA floating-point and Advanced SIMD extensions. */
22872struct arm_option_fpu_value_table
22873{
22874 char *name;
22875 const arm_feature_set value;
c19d1205 22876};
7ed4c4c5 22877
c19d1205
ZW
22878/* This list should, at a minimum, contain all the fpu names
22879 recognized by GCC. */
69133863 22880static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
22881{
22882 {"softfpa", FPU_NONE},
22883 {"fpe", FPU_ARCH_FPE},
22884 {"fpe2", FPU_ARCH_FPE},
22885 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22886 {"fpa", FPU_ARCH_FPA},
22887 {"fpa10", FPU_ARCH_FPA},
22888 {"fpa11", FPU_ARCH_FPA},
22889 {"arm7500fe", FPU_ARCH_FPA},
22890 {"softvfp", FPU_ARCH_VFP},
22891 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22892 {"vfp", FPU_ARCH_VFP_V2},
22893 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 22894 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
22895 {"vfp10", FPU_ARCH_VFP_V2},
22896 {"vfp10-r0", FPU_ARCH_VFP_V1},
22897 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
22898 {"vfpv2", FPU_ARCH_VFP_V2},
22899 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 22900 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 22901 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
22902 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
22903 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
22904 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
22905 {"arm1020t", FPU_ARCH_VFP_V1},
22906 {"arm1020e", FPU_ARCH_VFP_V2},
22907 {"arm1136jfs", FPU_ARCH_VFP_V2},
22908 {"arm1136jf-s", FPU_ARCH_VFP_V2},
22909 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 22910 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 22911 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
22912 {"vfpv4", FPU_ARCH_VFP_V4},
22913 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 22914 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 22915 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
e74cfd16
PB
22916 {NULL, ARM_ARCH_NONE}
22917};
22918
22919struct arm_option_value_table
22920{
22921 char *name;
22922 long value;
c19d1205 22923};
7ed4c4c5 22924
e74cfd16 22925static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
22926{
22927 {"hard", ARM_FLOAT_ABI_HARD},
22928 {"softfp", ARM_FLOAT_ABI_SOFTFP},
22929 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 22930 {NULL, 0}
c19d1205 22931};
7ed4c4c5 22932
c19d1205 22933#ifdef OBJ_ELF
3a4a14e9 22934/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 22935static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
22936{
22937 {"gnu", EF_ARM_EABI_UNKNOWN},
22938 {"4", EF_ARM_EABI_VER4},
3a4a14e9 22939 {"5", EF_ARM_EABI_VER5},
e74cfd16 22940 {NULL, 0}
c19d1205
ZW
22941};
22942#endif
7ed4c4c5 22943
c19d1205
ZW
22944struct arm_long_option_table
22945{
22946 char * option; /* Substring to match. */
22947 char * help; /* Help information. */
22948 int (* func) (char * subopt); /* Function to decode sub-option. */
22949 char * deprecated; /* If non-null, print this message. */
22950};
7ed4c4c5 22951
c921be7d 22952static bfd_boolean
e74cfd16 22953arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 22954{
21d799b5
NC
22955 arm_feature_set *ext_set = (arm_feature_set *)
22956 xmalloc (sizeof (arm_feature_set));
e74cfd16 22957
69133863
MGD
22958 /* We insist on extensions being specified in alphabetical order, and with
22959 extensions being added before being removed. We achieve this by having
22960 the global ARM_EXTENSIONS table in alphabetical order, and using the
22961 ADDING_VALUE variable to indicate whether we are adding an extension (1)
22962 or removing it (0) and only allowing it to change in the order
22963 -1 -> 1 -> 0. */
22964 const struct arm_option_extension_value_table * opt = NULL;
22965 int adding_value = -1;
22966
e74cfd16
PB
22967 /* Copy the feature set, so that we can modify it. */
22968 *ext_set = **opt_p;
22969 *opt_p = ext_set;
22970
c19d1205 22971 while (str != NULL && *str != 0)
7ed4c4c5 22972 {
c19d1205 22973 char * ext;
69133863 22974 size_t optlen;
7ed4c4c5 22975
c19d1205
ZW
22976 if (*str != '+')
22977 {
22978 as_bad (_("invalid architectural extension"));
c921be7d 22979 return FALSE;
c19d1205 22980 }
7ed4c4c5 22981
c19d1205
ZW
22982 str++;
22983 ext = strchr (str, '+');
7ed4c4c5 22984
c19d1205
ZW
22985 if (ext != NULL)
22986 optlen = ext - str;
22987 else
22988 optlen = strlen (str);
7ed4c4c5 22989
69133863
MGD
22990 if (optlen >= 2
22991 && strncmp (str, "no", 2) == 0)
22992 {
22993 if (adding_value != 0)
22994 {
22995 adding_value = 0;
22996 opt = arm_extensions;
22997 }
22998
22999 optlen -= 2;
23000 str += 2;
23001 }
23002 else if (optlen > 0)
23003 {
23004 if (adding_value == -1)
23005 {
23006 adding_value = 1;
23007 opt = arm_extensions;
23008 }
23009 else if (adding_value != 1)
23010 {
23011 as_bad (_("must specify extensions to add before specifying "
23012 "those to remove"));
23013 return FALSE;
23014 }
23015 }
23016
c19d1205
ZW
23017 if (optlen == 0)
23018 {
23019 as_bad (_("missing architectural extension"));
c921be7d 23020 return FALSE;
c19d1205 23021 }
7ed4c4c5 23022
69133863
MGD
23023 gas_assert (adding_value != -1);
23024 gas_assert (opt != NULL);
23025
23026 /* Scan over the options table trying to find an exact match. */
23027 for (; opt->name != NULL; opt++)
23028 if (strncmp (opt->name, str, optlen) == 0
23029 && strlen (opt->name) == optlen)
c19d1205 23030 {
69133863
MGD
23031 /* Check we can apply the extension to this architecture. */
23032 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
23033 {
23034 as_bad (_("extension does not apply to the base architecture"));
23035 return FALSE;
23036 }
23037
23038 /* Add or remove the extension. */
23039 if (adding_value)
23040 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
23041 else
23042 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
23043
c19d1205
ZW
23044 break;
23045 }
7ed4c4c5 23046
c19d1205
ZW
23047 if (opt->name == NULL)
23048 {
69133863
MGD
23049 /* Did we fail to find an extension because it wasn't specified in
23050 alphabetical order, or because it does not exist? */
23051
23052 for (opt = arm_extensions; opt->name != NULL; opt++)
23053 if (strncmp (opt->name, str, optlen) == 0)
23054 break;
23055
23056 if (opt->name == NULL)
23057 as_bad (_("unknown architectural extension `%s'"), str);
23058 else
23059 as_bad (_("architectural extensions must be specified in "
23060 "alphabetical order"));
23061
c921be7d 23062 return FALSE;
c19d1205 23063 }
69133863
MGD
23064 else
23065 {
23066 /* We should skip the extension we've just matched the next time
23067 round. */
23068 opt++;
23069 }
7ed4c4c5 23070
c19d1205
ZW
23071 str = ext;
23072 };
7ed4c4c5 23073
c921be7d 23074 return TRUE;
c19d1205 23075}
7ed4c4c5 23076
c921be7d 23077static bfd_boolean
c19d1205 23078arm_parse_cpu (char * str)
7ed4c4c5 23079{
e74cfd16 23080 const struct arm_cpu_option_table * opt;
c19d1205
ZW
23081 char * ext = strchr (str, '+');
23082 int optlen;
7ed4c4c5 23083
c19d1205
ZW
23084 if (ext != NULL)
23085 optlen = ext - str;
7ed4c4c5 23086 else
c19d1205 23087 optlen = strlen (str);
7ed4c4c5 23088
c19d1205 23089 if (optlen == 0)
7ed4c4c5 23090 {
c19d1205 23091 as_bad (_("missing cpu name `%s'"), str);
c921be7d 23092 return FALSE;
7ed4c4c5
NC
23093 }
23094
c19d1205
ZW
23095 for (opt = arm_cpus; opt->name != NULL; opt++)
23096 if (strncmp (opt->name, str, optlen) == 0)
23097 {
e74cfd16
PB
23098 mcpu_cpu_opt = &opt->value;
23099 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 23100 if (opt->canonical_name)
5f4273c7 23101 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
23102 else
23103 {
23104 int i;
c921be7d 23105
ee065d83
PB
23106 for (i = 0; i < optlen; i++)
23107 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23108 selected_cpu_name[i] = 0;
23109 }
7ed4c4c5 23110
c19d1205
ZW
23111 if (ext != NULL)
23112 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 23113
c921be7d 23114 return TRUE;
c19d1205 23115 }
7ed4c4c5 23116
c19d1205 23117 as_bad (_("unknown cpu `%s'"), str);
c921be7d 23118 return FALSE;
7ed4c4c5
NC
23119}
23120
c921be7d 23121static bfd_boolean
c19d1205 23122arm_parse_arch (char * str)
7ed4c4c5 23123{
e74cfd16 23124 const struct arm_arch_option_table *opt;
c19d1205
ZW
23125 char *ext = strchr (str, '+');
23126 int optlen;
7ed4c4c5 23127
c19d1205
ZW
23128 if (ext != NULL)
23129 optlen = ext - str;
7ed4c4c5 23130 else
c19d1205 23131 optlen = strlen (str);
7ed4c4c5 23132
c19d1205 23133 if (optlen == 0)
7ed4c4c5 23134 {
c19d1205 23135 as_bad (_("missing architecture name `%s'"), str);
c921be7d 23136 return FALSE;
7ed4c4c5
NC
23137 }
23138
c19d1205 23139 for (opt = arm_archs; opt->name != NULL; opt++)
69133863 23140 if (strncmp (opt->name, str, optlen) == 0)
c19d1205 23141 {
e74cfd16
PB
23142 march_cpu_opt = &opt->value;
23143 march_fpu_opt = &opt->default_fpu;
5f4273c7 23144 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 23145
c19d1205
ZW
23146 if (ext != NULL)
23147 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 23148
c921be7d 23149 return TRUE;
c19d1205
ZW
23150 }
23151
23152 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 23153 return FALSE;
7ed4c4c5 23154}
eb043451 23155
c921be7d 23156static bfd_boolean
c19d1205
ZW
23157arm_parse_fpu (char * str)
23158{
69133863 23159 const struct arm_option_fpu_value_table * opt;
b99bd4ef 23160
c19d1205
ZW
23161 for (opt = arm_fpus; opt->name != NULL; opt++)
23162 if (streq (opt->name, str))
23163 {
e74cfd16 23164 mfpu_opt = &opt->value;
c921be7d 23165 return TRUE;
c19d1205 23166 }
b99bd4ef 23167
c19d1205 23168 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 23169 return FALSE;
c19d1205
ZW
23170}
23171
c921be7d 23172static bfd_boolean
c19d1205 23173arm_parse_float_abi (char * str)
b99bd4ef 23174{
e74cfd16 23175 const struct arm_option_value_table * opt;
b99bd4ef 23176
c19d1205
ZW
23177 for (opt = arm_float_abis; opt->name != NULL; opt++)
23178 if (streq (opt->name, str))
23179 {
23180 mfloat_abi_opt = opt->value;
c921be7d 23181 return TRUE;
c19d1205 23182 }
cc8a6dd0 23183
c19d1205 23184 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 23185 return FALSE;
c19d1205 23186}
b99bd4ef 23187
c19d1205 23188#ifdef OBJ_ELF
c921be7d 23189static bfd_boolean
c19d1205
ZW
23190arm_parse_eabi (char * str)
23191{
e74cfd16 23192 const struct arm_option_value_table *opt;
cc8a6dd0 23193
c19d1205
ZW
23194 for (opt = arm_eabis; opt->name != NULL; opt++)
23195 if (streq (opt->name, str))
23196 {
23197 meabi_flags = opt->value;
c921be7d 23198 return TRUE;
c19d1205
ZW
23199 }
23200 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 23201 return FALSE;
c19d1205
ZW
23202}
23203#endif
cc8a6dd0 23204
c921be7d 23205static bfd_boolean
e07e6e58
NC
23206arm_parse_it_mode (char * str)
23207{
c921be7d 23208 bfd_boolean ret = TRUE;
e07e6e58
NC
23209
23210 if (streq ("arm", str))
23211 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
23212 else if (streq ("thumb", str))
23213 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
23214 else if (streq ("always", str))
23215 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
23216 else if (streq ("never", str))
23217 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
23218 else
23219 {
23220 as_bad (_("unknown implicit IT mode `%s', should be "\
23221 "arm, thumb, always, or never."), str);
c921be7d 23222 ret = FALSE;
e07e6e58
NC
23223 }
23224
23225 return ret;
23226}
23227
c19d1205
ZW
23228struct arm_long_option_table arm_long_opts[] =
23229{
23230 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
23231 arm_parse_cpu, NULL},
23232 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
23233 arm_parse_arch, NULL},
23234 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
23235 arm_parse_fpu, NULL},
23236 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
23237 arm_parse_float_abi, NULL},
23238#ifdef OBJ_ELF
7fac0536 23239 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
23240 arm_parse_eabi, NULL},
23241#endif
e07e6e58
NC
23242 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
23243 arm_parse_it_mode, NULL},
c19d1205
ZW
23244 {NULL, NULL, 0, NULL}
23245};
cc8a6dd0 23246
c19d1205
ZW
23247int
23248md_parse_option (int c, char * arg)
23249{
23250 struct arm_option_table *opt;
e74cfd16 23251 const struct arm_legacy_option_table *fopt;
c19d1205 23252 struct arm_long_option_table *lopt;
b99bd4ef 23253
c19d1205 23254 switch (c)
b99bd4ef 23255 {
c19d1205
ZW
23256#ifdef OPTION_EB
23257 case OPTION_EB:
23258 target_big_endian = 1;
23259 break;
23260#endif
cc8a6dd0 23261
c19d1205
ZW
23262#ifdef OPTION_EL
23263 case OPTION_EL:
23264 target_big_endian = 0;
23265 break;
23266#endif
b99bd4ef 23267
845b51d6
PB
23268 case OPTION_FIX_V4BX:
23269 fix_v4bx = TRUE;
23270 break;
23271
c19d1205
ZW
23272 case 'a':
23273 /* Listing option. Just ignore these, we don't support additional
23274 ones. */
23275 return 0;
b99bd4ef 23276
c19d1205
ZW
23277 default:
23278 for (opt = arm_opts; opt->option != NULL; opt++)
23279 {
23280 if (c == opt->option[0]
23281 && ((arg == NULL && opt->option[1] == 0)
23282 || streq (arg, opt->option + 1)))
23283 {
c19d1205 23284 /* If the option is deprecated, tell the user. */
278df34e 23285 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
23286 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23287 arg ? arg : "", _(opt->deprecated));
b99bd4ef 23288
c19d1205
ZW
23289 if (opt->var != NULL)
23290 *opt->var = opt->value;
cc8a6dd0 23291
c19d1205
ZW
23292 return 1;
23293 }
23294 }
b99bd4ef 23295
e74cfd16
PB
23296 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
23297 {
23298 if (c == fopt->option[0]
23299 && ((arg == NULL && fopt->option[1] == 0)
23300 || streq (arg, fopt->option + 1)))
23301 {
e74cfd16 23302 /* If the option is deprecated, tell the user. */
278df34e 23303 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
23304 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23305 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
23306
23307 if (fopt->var != NULL)
23308 *fopt->var = &fopt->value;
23309
23310 return 1;
23311 }
23312 }
23313
c19d1205
ZW
23314 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23315 {
23316 /* These options are expected to have an argument. */
23317 if (c == lopt->option[0]
23318 && arg != NULL
23319 && strncmp (arg, lopt->option + 1,
23320 strlen (lopt->option + 1)) == 0)
23321 {
c19d1205 23322 /* If the option is deprecated, tell the user. */
278df34e 23323 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
23324 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
23325 _(lopt->deprecated));
b99bd4ef 23326
c19d1205
ZW
23327 /* Call the sup-option parser. */
23328 return lopt->func (arg + strlen (lopt->option) - 1);
23329 }
23330 }
a737bd4d 23331
c19d1205
ZW
23332 return 0;
23333 }
a394c00f 23334
c19d1205
ZW
23335 return 1;
23336}
a394c00f 23337
c19d1205
ZW
23338void
23339md_show_usage (FILE * fp)
a394c00f 23340{
c19d1205
ZW
23341 struct arm_option_table *opt;
23342 struct arm_long_option_table *lopt;
a394c00f 23343
c19d1205 23344 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 23345
c19d1205
ZW
23346 for (opt = arm_opts; opt->option != NULL; opt++)
23347 if (opt->help != NULL)
23348 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 23349
c19d1205
ZW
23350 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23351 if (lopt->help != NULL)
23352 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 23353
c19d1205
ZW
23354#ifdef OPTION_EB
23355 fprintf (fp, _("\
23356 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
23357#endif
23358
c19d1205
ZW
23359#ifdef OPTION_EL
23360 fprintf (fp, _("\
23361 -EL assemble code for a little-endian cpu\n"));
a737bd4d 23362#endif
845b51d6
PB
23363
23364 fprintf (fp, _("\
23365 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 23366}
ee065d83
PB
23367
23368
23369#ifdef OBJ_ELF
62b3e311
PB
23370typedef struct
23371{
23372 int val;
23373 arm_feature_set flags;
23374} cpu_arch_ver_table;
23375
23376/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
23377 least features first. */
23378static const cpu_arch_ver_table cpu_arch_ver[] =
23379{
23380 {1, ARM_ARCH_V4},
23381 {2, ARM_ARCH_V4T},
23382 {3, ARM_ARCH_V5},
ee3c0378 23383 {3, ARM_ARCH_V5T},
62b3e311
PB
23384 {4, ARM_ARCH_V5TE},
23385 {5, ARM_ARCH_V5TEJ},
23386 {6, ARM_ARCH_V6},
7e806470 23387 {9, ARM_ARCH_V6K},
f4c65163 23388 {7, ARM_ARCH_V6Z},
91e22acd 23389 {11, ARM_ARCH_V6M},
b2a5fbdc 23390 {12, ARM_ARCH_V6SM},
7e806470 23391 {8, ARM_ARCH_V6T2},
62b3e311
PB
23392 {10, ARM_ARCH_V7A},
23393 {10, ARM_ARCH_V7R},
23394 {10, ARM_ARCH_V7M},
23395 {0, ARM_ARCH_NONE}
23396};
23397
ee3c0378
AS
23398/* Set an attribute if it has not already been set by the user. */
23399static void
23400aeabi_set_attribute_int (int tag, int value)
23401{
23402 if (tag < 1
23403 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23404 || !attributes_set_explicitly[tag])
23405 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
23406}
23407
23408static void
23409aeabi_set_attribute_string (int tag, const char *value)
23410{
23411 if (tag < 1
23412 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23413 || !attributes_set_explicitly[tag])
23414 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
23415}
23416
ee065d83
PB
23417/* Set the public EABI object attributes. */
23418static void
23419aeabi_set_public_attributes (void)
23420{
23421 int arch;
90ec0d68 23422 int virt_sec = 0;
e74cfd16 23423 arm_feature_set flags;
62b3e311
PB
23424 arm_feature_set tmp;
23425 const cpu_arch_ver_table *p;
ee065d83
PB
23426
23427 /* Choose the architecture based on the capabilities of the requested cpu
23428 (if any) and/or the instructions actually used. */
e74cfd16
PB
23429 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
23430 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
23431 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
23432 /*Allow the user to override the reported architecture. */
23433 if (object_arch)
23434 {
23435 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
23436 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
23437 }
23438
251665fc
MGD
23439 /* We need to make sure that the attributes do not identify us as v6S-M
23440 when the only v6S-M feature in use is the Operating System Extensions. */
23441 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
23442 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
23443 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
23444
62b3e311
PB
23445 tmp = flags;
23446 arch = 0;
23447 for (p = cpu_arch_ver; p->val; p++)
23448 {
23449 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
23450 {
23451 arch = p->val;
23452 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
23453 }
23454 }
ee065d83 23455
9e3c6df6
PB
23456 /* The table lookup above finds the last architecture to contribute
23457 a new feature. Unfortunately, Tag13 is a subset of the union of
23458 v6T2 and v7-M, so it is never seen as contributing a new feature.
23459 We can not search for the last entry which is entirely used,
23460 because if no CPU is specified we build up only those flags
23461 actually used. Perhaps we should separate out the specified
23462 and implicit cases. Avoid taking this path for -march=all by
23463 checking for contradictory v7-A / v7-M features. */
23464 if (arch == 10
23465 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
23466 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
23467 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
23468 arch = 13;
23469
ee065d83
PB
23470 /* Tag_CPU_name. */
23471 if (selected_cpu_name[0])
23472 {
91d6fa6a 23473 char *q;
ee065d83 23474
91d6fa6a
NC
23475 q = selected_cpu_name;
23476 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
23477 {
23478 int i;
5f4273c7 23479
91d6fa6a
NC
23480 q += 4;
23481 for (i = 0; q[i]; i++)
23482 q[i] = TOUPPER (q[i]);
ee065d83 23483 }
91d6fa6a 23484 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 23485 }
62f3b8c8 23486
ee065d83 23487 /* Tag_CPU_arch. */
ee3c0378 23488 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 23489
62b3e311
PB
23490 /* Tag_CPU_arch_profile. */
23491 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 23492 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 23493 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 23494 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 23495 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 23496 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
62f3b8c8 23497
ee065d83 23498 /* Tag_ARM_ISA_use. */
ee3c0378
AS
23499 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
23500 || arch == 0)
23501 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 23502
ee065d83 23503 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
23504 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
23505 || arch == 0)
23506 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
23507 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 23508
ee065d83 23509 /* Tag_VFP_arch. */
62f3b8c8
PB
23510 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
23511 aeabi_set_attribute_int (Tag_VFP_arch,
23512 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
23513 ? 5 : 6);
23514 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
ee3c0378 23515 aeabi_set_attribute_int (Tag_VFP_arch, 3);
ada65aa3 23516 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
ee3c0378
AS
23517 aeabi_set_attribute_int (Tag_VFP_arch, 4);
23518 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
23519 aeabi_set_attribute_int (Tag_VFP_arch, 2);
23520 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
23521 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
23522 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 23523
4547cb56
NC
23524 /* Tag_ABI_HardFP_use. */
23525 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
23526 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
23527 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
23528
ee065d83 23529 /* Tag_WMMX_arch. */
ee3c0378
AS
23530 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
23531 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
23532 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
23533 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 23534
ee3c0378 23535 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 23536 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
62f3b8c8
PB
23537 aeabi_set_attribute_int
23538 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
23539 ? 2 : 1));
23540
ee3c0378 23541 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
62f3b8c8 23542 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
ee3c0378 23543 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56
NC
23544
23545 /* Tag_DIV_use. */
eea54501
MGD
23546 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv))
23547 aeabi_set_attribute_int (Tag_DIV_use, 2);
23548 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_div))
4547cb56 23549 aeabi_set_attribute_int (Tag_DIV_use, 0);
4547cb56
NC
23550 else
23551 aeabi_set_attribute_int (Tag_DIV_use, 1);
60e5ef9f
MGD
23552
23553 /* Tag_MP_extension_use. */
23554 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
23555 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
23556
23557 /* Tag Virtualization_use. */
23558 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
23559 virt_sec |= 1;
23560 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
23561 virt_sec |= 2;
23562 if (virt_sec != 0)
23563 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
23564}
23565
104d59d1 23566/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
23567void
23568arm_md_end (void)
23569{
ee065d83
PB
23570 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
23571 return;
23572
23573 aeabi_set_public_attributes ();
ee065d83 23574}
8463be01 23575#endif /* OBJ_ELF */
ee065d83
PB
23576
23577
23578/* Parse a .cpu directive. */
23579
23580static void
23581s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
23582{
e74cfd16 23583 const struct arm_cpu_option_table *opt;
ee065d83
PB
23584 char *name;
23585 char saved_char;
23586
23587 name = input_line_pointer;
5f4273c7 23588 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23589 input_line_pointer++;
23590 saved_char = *input_line_pointer;
23591 *input_line_pointer = 0;
23592
23593 /* Skip the first "all" entry. */
23594 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
23595 if (streq (opt->name, name))
23596 {
e74cfd16
PB
23597 mcpu_cpu_opt = &opt->value;
23598 selected_cpu = opt->value;
ee065d83 23599 if (opt->canonical_name)
5f4273c7 23600 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
23601 else
23602 {
23603 int i;
23604 for (i = 0; opt->name[i]; i++)
23605 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23606 selected_cpu_name[i] = 0;
23607 }
e74cfd16 23608 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23609 *input_line_pointer = saved_char;
23610 demand_empty_rest_of_line ();
23611 return;
23612 }
23613 as_bad (_("unknown cpu `%s'"), name);
23614 *input_line_pointer = saved_char;
23615 ignore_rest_of_line ();
23616}
23617
23618
23619/* Parse a .arch directive. */
23620
23621static void
23622s_arm_arch (int ignored ATTRIBUTE_UNUSED)
23623{
e74cfd16 23624 const struct arm_arch_option_table *opt;
ee065d83
PB
23625 char saved_char;
23626 char *name;
23627
23628 name = input_line_pointer;
5f4273c7 23629 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23630 input_line_pointer++;
23631 saved_char = *input_line_pointer;
23632 *input_line_pointer = 0;
23633
23634 /* Skip the first "all" entry. */
23635 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23636 if (streq (opt->name, name))
23637 {
e74cfd16
PB
23638 mcpu_cpu_opt = &opt->value;
23639 selected_cpu = opt->value;
5f4273c7 23640 strcpy (selected_cpu_name, opt->name);
e74cfd16 23641 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23642 *input_line_pointer = saved_char;
23643 demand_empty_rest_of_line ();
23644 return;
23645 }
23646
23647 as_bad (_("unknown architecture `%s'\n"), name);
23648 *input_line_pointer = saved_char;
23649 ignore_rest_of_line ();
23650}
23651
23652
7a1d4c38
PB
23653/* Parse a .object_arch directive. */
23654
23655static void
23656s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
23657{
23658 const struct arm_arch_option_table *opt;
23659 char saved_char;
23660 char *name;
23661
23662 name = input_line_pointer;
5f4273c7 23663 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
23664 input_line_pointer++;
23665 saved_char = *input_line_pointer;
23666 *input_line_pointer = 0;
23667
23668 /* Skip the first "all" entry. */
23669 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23670 if (streq (opt->name, name))
23671 {
23672 object_arch = &opt->value;
23673 *input_line_pointer = saved_char;
23674 demand_empty_rest_of_line ();
23675 return;
23676 }
23677
23678 as_bad (_("unknown architecture `%s'\n"), name);
23679 *input_line_pointer = saved_char;
23680 ignore_rest_of_line ();
23681}
23682
69133863
MGD
23683/* Parse a .arch_extension directive. */
23684
23685static void
23686s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
23687{
23688 const struct arm_option_extension_value_table *opt;
23689 char saved_char;
23690 char *name;
23691 int adding_value = 1;
23692
23693 name = input_line_pointer;
23694 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23695 input_line_pointer++;
23696 saved_char = *input_line_pointer;
23697 *input_line_pointer = 0;
23698
23699 if (strlen (name) >= 2
23700 && strncmp (name, "no", 2) == 0)
23701 {
23702 adding_value = 0;
23703 name += 2;
23704 }
23705
23706 for (opt = arm_extensions; opt->name != NULL; opt++)
23707 if (streq (opt->name, name))
23708 {
23709 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
23710 {
23711 as_bad (_("architectural extension `%s' is not allowed for the "
23712 "current base architecture"), name);
23713 break;
23714 }
23715
23716 if (adding_value)
23717 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
23718 else
23719 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
23720
23721 mcpu_cpu_opt = &selected_cpu;
23722 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23723 *input_line_pointer = saved_char;
23724 demand_empty_rest_of_line ();
23725 return;
23726 }
23727
23728 if (opt->name == NULL)
23729 as_bad (_("unknown architecture `%s'\n"), name);
23730
23731 *input_line_pointer = saved_char;
23732 ignore_rest_of_line ();
23733}
23734
ee065d83
PB
23735/* Parse a .fpu directive. */
23736
23737static void
23738s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
23739{
69133863 23740 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
23741 char saved_char;
23742 char *name;
23743
23744 name = input_line_pointer;
5f4273c7 23745 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23746 input_line_pointer++;
23747 saved_char = *input_line_pointer;
23748 *input_line_pointer = 0;
5f4273c7 23749
ee065d83
PB
23750 for (opt = arm_fpus; opt->name != NULL; opt++)
23751 if (streq (opt->name, name))
23752 {
e74cfd16
PB
23753 mfpu_opt = &opt->value;
23754 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23755 *input_line_pointer = saved_char;
23756 demand_empty_rest_of_line ();
23757 return;
23758 }
23759
23760 as_bad (_("unknown floating point format `%s'\n"), name);
23761 *input_line_pointer = saved_char;
23762 ignore_rest_of_line ();
23763}
ee065d83 23764
794ba86a 23765/* Copy symbol information. */
f31fef98 23766
794ba86a
DJ
23767void
23768arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
23769{
23770 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
23771}
e04befd0 23772
f31fef98 23773#ifdef OBJ_ELF
e04befd0
AS
23774/* Given a symbolic attribute NAME, return the proper integer value.
23775 Returns -1 if the attribute is not known. */
f31fef98 23776
e04befd0
AS
23777int
23778arm_convert_symbolic_attribute (const char *name)
23779{
f31fef98
NC
23780 static const struct
23781 {
23782 const char * name;
23783 const int tag;
23784 }
23785 attribute_table[] =
23786 {
23787 /* When you modify this table you should
23788 also modify the list in doc/c-arm.texi. */
e04befd0 23789#define T(tag) {#tag, tag}
f31fef98
NC
23790 T (Tag_CPU_raw_name),
23791 T (Tag_CPU_name),
23792 T (Tag_CPU_arch),
23793 T (Tag_CPU_arch_profile),
23794 T (Tag_ARM_ISA_use),
23795 T (Tag_THUMB_ISA_use),
75375b3e 23796 T (Tag_FP_arch),
f31fef98
NC
23797 T (Tag_VFP_arch),
23798 T (Tag_WMMX_arch),
23799 T (Tag_Advanced_SIMD_arch),
23800 T (Tag_PCS_config),
23801 T (Tag_ABI_PCS_R9_use),
23802 T (Tag_ABI_PCS_RW_data),
23803 T (Tag_ABI_PCS_RO_data),
23804 T (Tag_ABI_PCS_GOT_use),
23805 T (Tag_ABI_PCS_wchar_t),
23806 T (Tag_ABI_FP_rounding),
23807 T (Tag_ABI_FP_denormal),
23808 T (Tag_ABI_FP_exceptions),
23809 T (Tag_ABI_FP_user_exceptions),
23810 T (Tag_ABI_FP_number_model),
75375b3e 23811 T (Tag_ABI_align_needed),
f31fef98 23812 T (Tag_ABI_align8_needed),
75375b3e 23813 T (Tag_ABI_align_preserved),
f31fef98
NC
23814 T (Tag_ABI_align8_preserved),
23815 T (Tag_ABI_enum_size),
23816 T (Tag_ABI_HardFP_use),
23817 T (Tag_ABI_VFP_args),
23818 T (Tag_ABI_WMMX_args),
23819 T (Tag_ABI_optimization_goals),
23820 T (Tag_ABI_FP_optimization_goals),
23821 T (Tag_compatibility),
23822 T (Tag_CPU_unaligned_access),
75375b3e 23823 T (Tag_FP_HP_extension),
f31fef98
NC
23824 T (Tag_VFP_HP_extension),
23825 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
23826 T (Tag_MPextension_use),
23827 T (Tag_DIV_use),
f31fef98
NC
23828 T (Tag_nodefaults),
23829 T (Tag_also_compatible_with),
23830 T (Tag_conformance),
23831 T (Tag_T2EE_use),
23832 T (Tag_Virtualization_use),
cd21e546 23833 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 23834#undef T
f31fef98 23835 };
e04befd0
AS
23836 unsigned int i;
23837
23838 if (name == NULL)
23839 return -1;
23840
f31fef98 23841 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 23842 if (streq (name, attribute_table[i].name))
e04befd0
AS
23843 return attribute_table[i].tag;
23844
23845 return -1;
23846}
267bf995
RR
23847
23848
23849/* Apply sym value for relocations only in the case that
23850 they are for local symbols and you have the respective
23851 architectural feature for blx and simple switches. */
23852int
23853arm_apply_sym_value (struct fix * fixP)
23854{
23855 if (fixP->fx_addsy
23856 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
34e77a92 23857 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
23858 {
23859 switch (fixP->fx_r_type)
23860 {
23861 case BFD_RELOC_ARM_PCREL_BLX:
23862 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23863 if (ARM_IS_FUNC (fixP->fx_addsy))
23864 return 1;
23865 break;
23866
23867 case BFD_RELOC_ARM_PCREL_CALL:
23868 case BFD_RELOC_THUMB_PCREL_BLX:
23869 if (THUMB_IS_FUNC (fixP->fx_addsy))
23870 return 1;
23871 break;
23872
23873 default:
23874 break;
23875 }
23876
23877 }
23878 return 0;
23879}
f31fef98 23880#endif /* OBJ_ELF */
This page took 3.112723 seconds and 4 git commands to generate.