Add assembler support for ARMv8-M Mainline
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
b90efa5b 2 Copyright (C) 1994-2015 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b
RE
34#include "opcode/arm.h"
35
b99bd4ef
NC
36#ifdef OBJ_ELF
37#include "elf/arm.h"
a394c00f 38#include "dw2gencfi.h"
b99bd4ef
NC
39#endif
40
f0927246
NC
41#include "dwarf2dbg.h"
42
7ed4c4c5
NC
43#ifdef OBJ_ELF
44/* Must be at least the size of the largest unwind opcode (currently two). */
45#define ARM_OPCODE_CHUNK_SIZE 8
46
47/* This structure holds the unwinding state. */
48
49static struct
50{
c19d1205
ZW
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
7ed4c4c5 55 /* The segment containing the function. */
c19d1205
ZW
56 segT saved_seg;
57 subsegT saved_subseg;
7ed4c4c5
NC
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
c19d1205
ZW
60 int opcode_count;
61 int opcode_alloc;
7ed4c4c5 62 /* The number of bytes pushed to the stack. */
c19d1205 63 offsetT frame_size;
7ed4c4c5
NC
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
c19d1205 67 offsetT pending_offset;
7ed4c4c5 68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
7ed4c4c5 72 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 73 unsigned fp_used:1;
7ed4c4c5 74 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 75 unsigned sp_restored:1;
7ed4c4c5
NC
76} unwind;
77
8b1ad454
NC
78#endif /* OBJ_ELF */
79
4962c51a
MS
80/* Results from operand parsing worker functions. */
81
82typedef enum
83{
84 PARSE_OPERAND_SUCCESS,
85 PARSE_OPERAND_FAIL,
86 PARSE_OPERAND_FAIL_NO_BACKTRACK
87} parse_operand_result;
88
33a392fb
PB
89enum arm_float_abi
90{
91 ARM_FLOAT_ABI_HARD,
92 ARM_FLOAT_ABI_SOFTFP,
93 ARM_FLOAT_ABI_SOFT
94};
95
c19d1205 96/* Types of processor to assemble for. */
b99bd4ef 97#ifndef CPU_DEFAULT
8a59fff3 98/* The code that was here used to select a default CPU depending on compiler
fa94de6b 99 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
100 changing gas' default behaviour depending upon the build host.
101
102 If you have a target that requires a default CPU option then the you
103 should define CPU_DEFAULT here. */
b99bd4ef
NC
104#endif
105
106#ifndef FPU_DEFAULT
c820d418
MM
107# ifdef TE_LINUX
108# define FPU_DEFAULT FPU_ARCH_FPA
109# elif defined (TE_NetBSD)
110# ifdef OBJ_ELF
111# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
112# else
113 /* Legacy a.out format. */
114# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
115# endif
4e7fd91e
PB
116# elif defined (TE_VXWORKS)
117# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
118# else
119 /* For backwards compatibility, default to FPA. */
120# define FPU_DEFAULT FPU_ARCH_FPA
121# endif
122#endif /* ifndef FPU_DEFAULT */
b99bd4ef 123
c19d1205 124#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 125
e74cfd16
PB
126static arm_feature_set cpu_variant;
127static arm_feature_set arm_arch_used;
128static arm_feature_set thumb_arch_used;
b99bd4ef 129
b99bd4ef 130/* Flags stored in private area of BFD structure. */
c19d1205
ZW
131static int uses_apcs_26 = FALSE;
132static int atpcs = FALSE;
b34976b6
AM
133static int support_interwork = FALSE;
134static int uses_apcs_float = FALSE;
c19d1205 135static int pic_code = FALSE;
845b51d6 136static int fix_v4bx = FALSE;
278df34e
NS
137/* Warn on using deprecated features. */
138static int warn_on_deprecated = TRUE;
139
2e6976a8
DG
140/* Understand CodeComposer Studio assembly syntax. */
141bfd_boolean codecomposer_syntax = FALSE;
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
823d2571
TG
171static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
172static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
173static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
174static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
175static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
176static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
177static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
178static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 179static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
180 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
181static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
182static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
183static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
184static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
185static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
186static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
187static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
188static const arm_feature_set arm_ext_v6m = ARM_FEATURE_CORE_LOW (ARM_EXT_V6M);
189static const arm_feature_set arm_ext_v6_notm =
190 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
191static const arm_feature_set arm_ext_v6_dsp =
192 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
193static const arm_feature_set arm_ext_barrier =
194 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
195static const arm_feature_set arm_ext_msr =
196 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
197static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
198static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
199static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
200static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
201static const arm_feature_set arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
202static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 203static const arm_feature_set arm_ext_m =
4ed7ed8d 204 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, ARM_EXT2_V8M);
823d2571
TG
205static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
206static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
207static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
208static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
209static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 210static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d
TP
211static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
212/* Instructions shared between ARMv8-A and ARMv8-M. */
213static const arm_feature_set arm_ext_atomics =
214 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
e74cfd16
PB
215
216static const arm_feature_set arm_arch_any = ARM_ANY;
823d2571 217static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
218static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
219static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
251665fc 220static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
e74cfd16 221
2d447fca 222static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 223 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 224static const arm_feature_set arm_cext_iwmmxt =
823d2571 225 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 226static const arm_feature_set arm_cext_xscale =
823d2571 227 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 228static const arm_feature_set arm_cext_maverick =
823d2571
TG
229 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
230static const arm_feature_set fpu_fpa_ext_v1 =
231 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
232static const arm_feature_set fpu_fpa_ext_v2 =
233 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 234static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
235 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
236static const arm_feature_set fpu_vfp_ext_v1 =
237 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
238static const arm_feature_set fpu_vfp_ext_v2 =
239 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
240static const arm_feature_set fpu_vfp_ext_v3xd =
241 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
242static const arm_feature_set fpu_vfp_ext_v3 =
243 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 244static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
245 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
246static const arm_feature_set fpu_neon_ext_v1 =
247 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 248static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571
TG
249 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
250static const arm_feature_set fpu_vfp_fp16 =
251 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
252static const arm_feature_set fpu_neon_ext_fma =
253 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
254static const arm_feature_set fpu_vfp_ext_fma =
255 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 256static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 257 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 258static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 259 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 260static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 261 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 262static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 263 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 264static const arm_feature_set crc_ext_armv8 =
823d2571 265 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e
MW
266static const arm_feature_set fpu_neon_ext_v8_1 =
267 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8 | FPU_NEON_EXT_RDMA);
e74cfd16 268
33a392fb 269static int mfloat_abi_opt = -1;
e74cfd16
PB
270/* Record user cpu selection for object attributes. */
271static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83 272/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 273static char selected_cpu_name[20];
8d67f500 274
aacf0b33
KT
275extern FLONUM_TYPE generic_floating_point_number;
276
8d67f500
NC
277/* Return if no cpu was selected on command-line. */
278static bfd_boolean
279no_cpu_selected (void)
280{
823d2571 281 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
282}
283
7cc69913 284#ifdef OBJ_ELF
deeaaff8
DJ
285# ifdef EABI_DEFAULT
286static int meabi_flags = EABI_DEFAULT;
287# else
d507cf36 288static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 289# endif
e1da3f5b 290
ee3c0378
AS
291static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
292
e1da3f5b 293bfd_boolean
5f4273c7 294arm_is_eabi (void)
e1da3f5b
PB
295{
296 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
297}
7cc69913 298#endif
b99bd4ef 299
b99bd4ef 300#ifdef OBJ_ELF
c19d1205 301/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
302symbolS * GOT_symbol;
303#endif
304
b99bd4ef
NC
305/* 0: assemble for ARM,
306 1: assemble for Thumb,
307 2: assemble for Thumb even though target CPU does not support thumb
308 instructions. */
309static int thumb_mode = 0;
8dc2430f
NC
310/* A value distinct from the possible values for thumb_mode that we
311 can use to record whether thumb_mode has been copied into the
312 tc_frag_data field of a frag. */
313#define MODE_RECORDED (1 << 4)
b99bd4ef 314
e07e6e58
NC
315/* Specifies the intrinsic IT insn behavior mode. */
316enum implicit_it_mode
317{
318 IMPLICIT_IT_MODE_NEVER = 0x00,
319 IMPLICIT_IT_MODE_ARM = 0x01,
320 IMPLICIT_IT_MODE_THUMB = 0x02,
321 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
322};
323static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
324
c19d1205
ZW
325/* If unified_syntax is true, we are processing the new unified
326 ARM/Thumb syntax. Important differences from the old ARM mode:
327
328 - Immediate operands do not require a # prefix.
329 - Conditional affixes always appear at the end of the
330 instruction. (For backward compatibility, those instructions
331 that formerly had them in the middle, continue to accept them
332 there.)
333 - The IT instruction may appear, and if it does is validated
334 against subsequent conditional affixes. It does not generate
335 machine code.
336
337 Important differences from the old Thumb mode:
338
339 - Immediate operands do not require a # prefix.
340 - Most of the V6T2 instructions are only available in unified mode.
341 - The .N and .W suffixes are recognized and honored (it is an error
342 if they cannot be honored).
343 - All instructions set the flags if and only if they have an 's' affix.
344 - Conditional affixes may be used. They are validated against
345 preceding IT instructions. Unlike ARM mode, you cannot use a
346 conditional affix except in the scope of an IT instruction. */
347
348static bfd_boolean unified_syntax = FALSE;
b99bd4ef 349
bacebabc
RM
350/* An immediate operand can start with #, and ld*, st*, pld operands
351 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
352 before a [, which can appear as the first operand for pld.
353 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
354const char arm_symbol_chars[] = "#[]{}";
bacebabc 355
5287ad62
JB
356enum neon_el_type
357{
dcbf9037 358 NT_invtype,
5287ad62
JB
359 NT_untyped,
360 NT_integer,
361 NT_float,
362 NT_poly,
363 NT_signed,
dcbf9037 364 NT_unsigned
5287ad62
JB
365};
366
367struct neon_type_el
368{
369 enum neon_el_type type;
370 unsigned size;
371};
372
373#define NEON_MAX_TYPE_ELS 4
374
375struct neon_type
376{
377 struct neon_type_el el[NEON_MAX_TYPE_ELS];
378 unsigned elems;
379};
380
e07e6e58
NC
381enum it_instruction_type
382{
383 OUTSIDE_IT_INSN,
384 INSIDE_IT_INSN,
385 INSIDE_IT_LAST_INSN,
386 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 387 if inside, should be the last one. */
e07e6e58 388 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 389 i.e. BKPT and NOP. */
e07e6e58
NC
390 IT_INSN /* The IT insn has been parsed. */
391};
392
ad6cec43
MGD
393/* The maximum number of operands we need. */
394#define ARM_IT_MAX_OPERANDS 6
395
b99bd4ef
NC
396struct arm_it
397{
c19d1205 398 const char * error;
b99bd4ef 399 unsigned long instruction;
c19d1205
ZW
400 int size;
401 int size_req;
402 int cond;
037e8744
JB
403 /* "uncond_value" is set to the value in place of the conditional field in
404 unconditional versions of the instruction, or -1 if nothing is
405 appropriate. */
406 int uncond_value;
5287ad62 407 struct neon_type vectype;
88714cb8
DG
408 /* This does not indicate an actual NEON instruction, only that
409 the mnemonic accepts neon-style type suffixes. */
410 int is_neon;
0110f2b8
PB
411 /* Set to the opcode if the instruction needs relaxation.
412 Zero if the instruction is not relaxed. */
413 unsigned long relax;
b99bd4ef
NC
414 struct
415 {
416 bfd_reloc_code_real_type type;
c19d1205
ZW
417 expressionS exp;
418 int pc_rel;
b99bd4ef 419 } reloc;
b99bd4ef 420
e07e6e58
NC
421 enum it_instruction_type it_insn_type;
422
c19d1205
ZW
423 struct
424 {
425 unsigned reg;
ca3f61f7 426 signed int imm;
dcbf9037 427 struct neon_type_el vectype;
ca3f61f7
NC
428 unsigned present : 1; /* Operand present. */
429 unsigned isreg : 1; /* Operand was a register. */
430 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
431 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
432 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 433 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
434 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
435 instructions. This allows us to disambiguate ARM <-> vector insns. */
436 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 437 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 438 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 439 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
440 unsigned hasreloc : 1; /* Operand has relocation suffix. */
441 unsigned writeback : 1; /* Operand has trailing ! */
442 unsigned preind : 1; /* Preindexed address. */
443 unsigned postind : 1; /* Postindexed address. */
444 unsigned negative : 1; /* Index register was negated. */
445 unsigned shifted : 1; /* Shift applied to operation. */
446 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 447 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
448};
449
c19d1205 450static struct arm_it inst;
b99bd4ef
NC
451
452#define NUM_FLOAT_VALS 8
453
05d2d07e 454const char * fp_const[] =
b99bd4ef
NC
455{
456 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
457};
458
c19d1205 459/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
460#define MAX_LITTLENUMS 6
461
462LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
463
464#define FAIL (-1)
465#define SUCCESS (0)
466
467#define SUFF_S 1
468#define SUFF_D 2
469#define SUFF_E 3
470#define SUFF_P 4
471
c19d1205
ZW
472#define CP_T_X 0x00008000
473#define CP_T_Y 0x00400000
b99bd4ef 474
c19d1205
ZW
475#define CONDS_BIT 0x00100000
476#define LOAD_BIT 0x00100000
b99bd4ef
NC
477
478#define DOUBLE_LOAD_FLAG 0x00000001
479
480struct asm_cond
481{
d3ce72d0 482 const char * template_name;
c921be7d 483 unsigned long value;
b99bd4ef
NC
484};
485
c19d1205 486#define COND_ALWAYS 0xE
b99bd4ef 487
b99bd4ef
NC
488struct asm_psr
489{
d3ce72d0 490 const char * template_name;
c921be7d 491 unsigned long field;
b99bd4ef
NC
492};
493
62b3e311
PB
494struct asm_barrier_opt
495{
e797f7e0
MGD
496 const char * template_name;
497 unsigned long value;
498 const arm_feature_set arch;
62b3e311
PB
499};
500
2d2255b5 501/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
502#define SPSR_BIT (1 << 22)
503
c19d1205
ZW
504/* The individual PSR flag bits. */
505#define PSR_c (1 << 16)
506#define PSR_x (1 << 17)
507#define PSR_s (1 << 18)
508#define PSR_f (1 << 19)
b99bd4ef 509
c19d1205 510struct reloc_entry
bfae80f2 511{
c921be7d
NC
512 char * name;
513 bfd_reloc_code_real_type reloc;
bfae80f2
RE
514};
515
5287ad62 516enum vfp_reg_pos
bfae80f2 517{
5287ad62
JB
518 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
519 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
520};
521
522enum vfp_ldstm_type
523{
524 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
525};
526
dcbf9037
JB
527/* Bits for DEFINED field in neon_typed_alias. */
528#define NTA_HASTYPE 1
529#define NTA_HASINDEX 2
530
531struct neon_typed_alias
532{
c921be7d
NC
533 unsigned char defined;
534 unsigned char index;
535 struct neon_type_el eltype;
dcbf9037
JB
536};
537
c19d1205
ZW
538/* ARM register categories. This includes coprocessor numbers and various
539 architecture extensions' registers. */
540enum arm_reg_type
bfae80f2 541{
c19d1205
ZW
542 REG_TYPE_RN,
543 REG_TYPE_CP,
544 REG_TYPE_CN,
545 REG_TYPE_FN,
546 REG_TYPE_VFS,
547 REG_TYPE_VFD,
5287ad62 548 REG_TYPE_NQ,
037e8744 549 REG_TYPE_VFSD,
5287ad62 550 REG_TYPE_NDQ,
037e8744 551 REG_TYPE_NSDQ,
c19d1205
ZW
552 REG_TYPE_VFC,
553 REG_TYPE_MVF,
554 REG_TYPE_MVD,
555 REG_TYPE_MVFX,
556 REG_TYPE_MVDX,
557 REG_TYPE_MVAX,
558 REG_TYPE_DSPSC,
559 REG_TYPE_MMXWR,
560 REG_TYPE_MMXWC,
561 REG_TYPE_MMXWCG,
562 REG_TYPE_XSCALE,
90ec0d68 563 REG_TYPE_RNB
bfae80f2
RE
564};
565
dcbf9037
JB
566/* Structure for a hash table entry for a register.
567 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
568 information which states whether a vector type or index is specified (for a
569 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
570struct reg_entry
571{
c921be7d 572 const char * name;
90ec0d68 573 unsigned int number;
c921be7d
NC
574 unsigned char type;
575 unsigned char builtin;
576 struct neon_typed_alias * neon;
6c43fab6
RE
577};
578
c19d1205 579/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 580const char * const reg_expected_msgs[] =
c19d1205
ZW
581{
582 N_("ARM register expected"),
583 N_("bad or missing co-processor number"),
584 N_("co-processor register expected"),
585 N_("FPA register expected"),
586 N_("VFP single precision register expected"),
5287ad62
JB
587 N_("VFP/Neon double precision register expected"),
588 N_("Neon quad precision register expected"),
037e8744 589 N_("VFP single or double precision register expected"),
5287ad62 590 N_("Neon double or quad precision register expected"),
037e8744 591 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
592 N_("VFP system register expected"),
593 N_("Maverick MVF register expected"),
594 N_("Maverick MVD register expected"),
595 N_("Maverick MVFX register expected"),
596 N_("Maverick MVDX register expected"),
597 N_("Maverick MVAX register expected"),
598 N_("Maverick DSPSC register expected"),
599 N_("iWMMXt data register expected"),
600 N_("iWMMXt control register expected"),
601 N_("iWMMXt scalar register expected"),
602 N_("XScale accumulator register expected"),
6c43fab6
RE
603};
604
c19d1205 605/* Some well known registers that we refer to directly elsewhere. */
bd340a04 606#define REG_R12 12
c19d1205
ZW
607#define REG_SP 13
608#define REG_LR 14
609#define REG_PC 15
404ff6b5 610
b99bd4ef
NC
611/* ARM instructions take 4bytes in the object file, Thumb instructions
612 take 2: */
c19d1205 613#define INSN_SIZE 4
b99bd4ef
NC
614
615struct asm_opcode
616{
617 /* Basic string to match. */
d3ce72d0 618 const char * template_name;
c19d1205
ZW
619
620 /* Parameters to instruction. */
5be8be5d 621 unsigned int operands[8];
c19d1205
ZW
622
623 /* Conditional tag - see opcode_lookup. */
624 unsigned int tag : 4;
b99bd4ef
NC
625
626 /* Basic instruction code. */
c19d1205 627 unsigned int avalue : 28;
b99bd4ef 628
c19d1205
ZW
629 /* Thumb-format instruction code. */
630 unsigned int tvalue;
b99bd4ef 631
90e4755a 632 /* Which architecture variant provides this instruction. */
c921be7d
NC
633 const arm_feature_set * avariant;
634 const arm_feature_set * tvariant;
c19d1205
ZW
635
636 /* Function to call to encode instruction in ARM format. */
637 void (* aencode) (void);
b99bd4ef 638
c19d1205
ZW
639 /* Function to call to encode instruction in Thumb format. */
640 void (* tencode) (void);
b99bd4ef
NC
641};
642
a737bd4d
NC
643/* Defines for various bits that we will want to toggle. */
644#define INST_IMMEDIATE 0x02000000
645#define OFFSET_REG 0x02000000
c19d1205 646#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
647#define SHIFT_BY_REG 0x00000010
648#define PRE_INDEX 0x01000000
649#define INDEX_UP 0x00800000
650#define WRITE_BACK 0x00200000
651#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 652#define CPSI_MMOD 0x00020000
90e4755a 653
a737bd4d
NC
654#define LITERAL_MASK 0xf000f000
655#define OPCODE_MASK 0xfe1fffff
656#define V4_STR_BIT 0x00000020
8335d6aa 657#define VLDR_VMOV_SAME 0x0040f000
90e4755a 658
efd81785
PB
659#define T2_SUBS_PC_LR 0xf3de8f00
660
a737bd4d 661#define DATA_OP_SHIFT 21
90e4755a 662
ef8d22e6
PB
663#define T2_OPCODE_MASK 0xfe1fffff
664#define T2_DATA_OP_SHIFT 21
665
6530b175
NC
666#define A_COND_MASK 0xf0000000
667#define A_PUSH_POP_OP_MASK 0x0fff0000
668
669/* Opcodes for pushing/poping registers to/from the stack. */
670#define A1_OPCODE_PUSH 0x092d0000
671#define A2_OPCODE_PUSH 0x052d0004
672#define A2_OPCODE_POP 0x049d0004
673
a737bd4d
NC
674/* Codes to distinguish the arithmetic instructions. */
675#define OPCODE_AND 0
676#define OPCODE_EOR 1
677#define OPCODE_SUB 2
678#define OPCODE_RSB 3
679#define OPCODE_ADD 4
680#define OPCODE_ADC 5
681#define OPCODE_SBC 6
682#define OPCODE_RSC 7
683#define OPCODE_TST 8
684#define OPCODE_TEQ 9
685#define OPCODE_CMP 10
686#define OPCODE_CMN 11
687#define OPCODE_ORR 12
688#define OPCODE_MOV 13
689#define OPCODE_BIC 14
690#define OPCODE_MVN 15
90e4755a 691
ef8d22e6
PB
692#define T2_OPCODE_AND 0
693#define T2_OPCODE_BIC 1
694#define T2_OPCODE_ORR 2
695#define T2_OPCODE_ORN 3
696#define T2_OPCODE_EOR 4
697#define T2_OPCODE_ADD 8
698#define T2_OPCODE_ADC 10
699#define T2_OPCODE_SBC 11
700#define T2_OPCODE_SUB 13
701#define T2_OPCODE_RSB 14
702
a737bd4d
NC
703#define T_OPCODE_MUL 0x4340
704#define T_OPCODE_TST 0x4200
705#define T_OPCODE_CMN 0x42c0
706#define T_OPCODE_NEG 0x4240
707#define T_OPCODE_MVN 0x43c0
90e4755a 708
a737bd4d
NC
709#define T_OPCODE_ADD_R3 0x1800
710#define T_OPCODE_SUB_R3 0x1a00
711#define T_OPCODE_ADD_HI 0x4400
712#define T_OPCODE_ADD_ST 0xb000
713#define T_OPCODE_SUB_ST 0xb080
714#define T_OPCODE_ADD_SP 0xa800
715#define T_OPCODE_ADD_PC 0xa000
716#define T_OPCODE_ADD_I8 0x3000
717#define T_OPCODE_SUB_I8 0x3800
718#define T_OPCODE_ADD_I3 0x1c00
719#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 720
a737bd4d
NC
721#define T_OPCODE_ASR_R 0x4100
722#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
723#define T_OPCODE_LSR_R 0x40c0
724#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
725#define T_OPCODE_ASR_I 0x1000
726#define T_OPCODE_LSL_I 0x0000
727#define T_OPCODE_LSR_I 0x0800
b99bd4ef 728
a737bd4d
NC
729#define T_OPCODE_MOV_I8 0x2000
730#define T_OPCODE_CMP_I8 0x2800
731#define T_OPCODE_CMP_LR 0x4280
732#define T_OPCODE_MOV_HR 0x4600
733#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 734
a737bd4d
NC
735#define T_OPCODE_LDR_PC 0x4800
736#define T_OPCODE_LDR_SP 0x9800
737#define T_OPCODE_STR_SP 0x9000
738#define T_OPCODE_LDR_IW 0x6800
739#define T_OPCODE_STR_IW 0x6000
740#define T_OPCODE_LDR_IH 0x8800
741#define T_OPCODE_STR_IH 0x8000
742#define T_OPCODE_LDR_IB 0x7800
743#define T_OPCODE_STR_IB 0x7000
744#define T_OPCODE_LDR_RW 0x5800
745#define T_OPCODE_STR_RW 0x5000
746#define T_OPCODE_LDR_RH 0x5a00
747#define T_OPCODE_STR_RH 0x5200
748#define T_OPCODE_LDR_RB 0x5c00
749#define T_OPCODE_STR_RB 0x5400
c9b604bd 750
a737bd4d
NC
751#define T_OPCODE_PUSH 0xb400
752#define T_OPCODE_POP 0xbc00
b99bd4ef 753
2fc8bdac 754#define T_OPCODE_BRANCH 0xe000
b99bd4ef 755
a737bd4d 756#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 757#define THUMB_PP_PC_LR 0x0100
c19d1205 758#define THUMB_LOAD_BIT 0x0800
53365c0d 759#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
760
761#define BAD_ARGS _("bad arguments to instruction")
fdfde340 762#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
763#define BAD_PC _("r15 not allowed here")
764#define BAD_COND _("instruction cannot be conditional")
765#define BAD_OVERLAP _("registers may not be the same")
766#define BAD_HIREG _("lo register required")
767#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 768#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
769#define BAD_BRANCH _("branch must be last instruction in IT block")
770#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 771#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
772#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
773#define BAD_IT_COND _("incorrect condition in IT block")
774#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 775#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
776#define BAD_PC_ADDRESSING \
777 _("cannot use register index with PC-relative addressing")
778#define BAD_PC_WRITEBACK \
779 _("cannot use writeback with PC-relative addressing")
08f10d51 780#define BAD_RANGE _("branch out of range")
dd5181d5 781#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
c19d1205 782
c921be7d
NC
783static struct hash_control * arm_ops_hsh;
784static struct hash_control * arm_cond_hsh;
785static struct hash_control * arm_shift_hsh;
786static struct hash_control * arm_psr_hsh;
787static struct hash_control * arm_v7m_psr_hsh;
788static struct hash_control * arm_reg_hsh;
789static struct hash_control * arm_reloc_hsh;
790static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 791
b99bd4ef
NC
792/* Stuff needed to resolve the label ambiguity
793 As:
794 ...
795 label: <insn>
796 may differ from:
797 ...
798 label:
5f4273c7 799 <insn> */
b99bd4ef
NC
800
801symbolS * last_label_seen;
b34976b6 802static int label_is_thumb_function_name = FALSE;
e07e6e58 803
3d0c9500
NC
804/* Literal pool structure. Held on a per-section
805 and per-sub-section basis. */
a737bd4d 806
c19d1205 807#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 808typedef struct literal_pool
b99bd4ef 809{
c921be7d
NC
810 expressionS literals [MAX_LITERAL_POOL_SIZE];
811 unsigned int next_free_entry;
812 unsigned int id;
813 symbolS * symbol;
814 segT section;
815 subsegT sub_section;
a8040cf2
NC
816#ifdef OBJ_ELF
817 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
818#endif
c921be7d 819 struct literal_pool * next;
8335d6aa 820 unsigned int alignment;
3d0c9500 821} literal_pool;
b99bd4ef 822
3d0c9500
NC
823/* Pointer to a linked list of literal pools. */
824literal_pool * list_of_pools = NULL;
e27ec89e 825
2e6976a8
DG
826typedef enum asmfunc_states
827{
828 OUTSIDE_ASMFUNC,
829 WAITING_ASMFUNC_NAME,
830 WAITING_ENDASMFUNC
831} asmfunc_states;
832
833static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
834
e07e6e58
NC
835#ifdef OBJ_ELF
836# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
837#else
838static struct current_it now_it;
839#endif
840
841static inline int
842now_it_compatible (int cond)
843{
844 return (cond & ~1) == (now_it.cc & ~1);
845}
846
847static inline int
848conditional_insn (void)
849{
850 return inst.cond != COND_ALWAYS;
851}
852
853static int in_it_block (void);
854
855static int handle_it_state (void);
856
857static void force_automatic_it_block_close (void);
858
c921be7d
NC
859static void it_fsm_post_encode (void);
860
e07e6e58
NC
861#define set_it_insn_type(type) \
862 do \
863 { \
864 inst.it_insn_type = type; \
865 if (handle_it_state () == FAIL) \
477330fc 866 return; \
e07e6e58
NC
867 } \
868 while (0)
869
c921be7d
NC
870#define set_it_insn_type_nonvoid(type, failret) \
871 do \
872 { \
873 inst.it_insn_type = type; \
874 if (handle_it_state () == FAIL) \
477330fc 875 return failret; \
c921be7d
NC
876 } \
877 while(0)
878
e07e6e58
NC
879#define set_it_insn_type_last() \
880 do \
881 { \
882 if (inst.cond == COND_ALWAYS) \
477330fc 883 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 884 else \
477330fc 885 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
886 } \
887 while (0)
888
c19d1205 889/* Pure syntax. */
b99bd4ef 890
c19d1205
ZW
891/* This array holds the chars that always start a comment. If the
892 pre-processor is disabled, these aren't very useful. */
2e6976a8 893char arm_comment_chars[] = "@";
3d0c9500 894
c19d1205
ZW
895/* This array holds the chars that only start a comment at the beginning of
896 a line. If the line seems to have the form '# 123 filename'
897 .line and .file directives will appear in the pre-processed output. */
898/* Note that input_file.c hand checks for '#' at the beginning of the
899 first line of the input file. This is because the compiler outputs
900 #NO_APP at the beginning of its output. */
901/* Also note that comments like this one will always work. */
902const char line_comment_chars[] = "#";
3d0c9500 903
2e6976a8 904char arm_line_separator_chars[] = ";";
b99bd4ef 905
c19d1205
ZW
906/* Chars that can be used to separate mant
907 from exp in floating point numbers. */
908const char EXP_CHARS[] = "eE";
3d0c9500 909
c19d1205
ZW
910/* Chars that mean this number is a floating point constant. */
911/* As in 0f12.456 */
912/* or 0d1.2345e12 */
b99bd4ef 913
c19d1205 914const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 915
c19d1205
ZW
916/* Prefix characters that indicate the start of an immediate
917 value. */
918#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 919
c19d1205
ZW
920/* Separator character handling. */
921
922#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
923
924static inline int
925skip_past_char (char ** str, char c)
926{
8ab8155f
NC
927 /* PR gas/14987: Allow for whitespace before the expected character. */
928 skip_whitespace (*str);
427d0db6 929
c19d1205
ZW
930 if (**str == c)
931 {
932 (*str)++;
933 return SUCCESS;
3d0c9500 934 }
c19d1205
ZW
935 else
936 return FAIL;
937}
c921be7d 938
c19d1205 939#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 940
c19d1205
ZW
941/* Arithmetic expressions (possibly involving symbols). */
942
943/* Return TRUE if anything in the expression is a bignum. */
944
945static int
946walk_no_bignums (symbolS * sp)
947{
948 if (symbol_get_value_expression (sp)->X_op == O_big)
949 return 1;
950
951 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 952 {
c19d1205
ZW
953 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
954 || (symbol_get_value_expression (sp)->X_op_symbol
955 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
956 }
957
c19d1205 958 return 0;
3d0c9500
NC
959}
960
c19d1205
ZW
961static int in_my_get_expression = 0;
962
963/* Third argument to my_get_expression. */
964#define GE_NO_PREFIX 0
965#define GE_IMM_PREFIX 1
966#define GE_OPT_PREFIX 2
5287ad62
JB
967/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
968 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
969#define GE_OPT_PREFIX_BIG 3
a737bd4d 970
b99bd4ef 971static int
c19d1205 972my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 973{
c19d1205
ZW
974 char * save_in;
975 segT seg;
b99bd4ef 976
c19d1205
ZW
977 /* In unified syntax, all prefixes are optional. */
978 if (unified_syntax)
5287ad62 979 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 980 : GE_OPT_PREFIX;
b99bd4ef 981
c19d1205 982 switch (prefix_mode)
b99bd4ef 983 {
c19d1205
ZW
984 case GE_NO_PREFIX: break;
985 case GE_IMM_PREFIX:
986 if (!is_immediate_prefix (**str))
987 {
988 inst.error = _("immediate expression requires a # prefix");
989 return FAIL;
990 }
991 (*str)++;
992 break;
993 case GE_OPT_PREFIX:
5287ad62 994 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
995 if (is_immediate_prefix (**str))
996 (*str)++;
997 break;
998 default: abort ();
999 }
b99bd4ef 1000
c19d1205 1001 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1002
c19d1205
ZW
1003 save_in = input_line_pointer;
1004 input_line_pointer = *str;
1005 in_my_get_expression = 1;
1006 seg = expression (ep);
1007 in_my_get_expression = 0;
1008
f86adc07 1009 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1010 {
f86adc07 1011 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1012 *str = input_line_pointer;
1013 input_line_pointer = save_in;
1014 if (inst.error == NULL)
f86adc07
NS
1015 inst.error = (ep->X_op == O_absent
1016 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1017 return 1;
1018 }
b99bd4ef 1019
c19d1205
ZW
1020#ifdef OBJ_AOUT
1021 if (seg != absolute_section
1022 && seg != text_section
1023 && seg != data_section
1024 && seg != bss_section
1025 && seg != undefined_section)
1026 {
1027 inst.error = _("bad segment");
1028 *str = input_line_pointer;
1029 input_line_pointer = save_in;
1030 return 1;
b99bd4ef 1031 }
87975d2a
AM
1032#else
1033 (void) seg;
c19d1205 1034#endif
b99bd4ef 1035
c19d1205
ZW
1036 /* Get rid of any bignums now, so that we don't generate an error for which
1037 we can't establish a line number later on. Big numbers are never valid
1038 in instructions, which is where this routine is always called. */
5287ad62
JB
1039 if (prefix_mode != GE_OPT_PREFIX_BIG
1040 && (ep->X_op == O_big
477330fc 1041 || (ep->X_add_symbol
5287ad62 1042 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1043 || (ep->X_op_symbol
5287ad62 1044 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1045 {
1046 inst.error = _("invalid constant");
1047 *str = input_line_pointer;
1048 input_line_pointer = save_in;
1049 return 1;
1050 }
b99bd4ef 1051
c19d1205
ZW
1052 *str = input_line_pointer;
1053 input_line_pointer = save_in;
1054 return 0;
b99bd4ef
NC
1055}
1056
c19d1205
ZW
1057/* Turn a string in input_line_pointer into a floating point constant
1058 of type TYPE, and store the appropriate bytes in *LITP. The number
1059 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1060 returned, or NULL on OK.
b99bd4ef 1061
c19d1205
ZW
1062 Note that fp constants aren't represent in the normal way on the ARM.
1063 In big endian mode, things are as expected. However, in little endian
1064 mode fp constants are big-endian word-wise, and little-endian byte-wise
1065 within the words. For example, (double) 1.1 in big endian mode is
1066 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1067 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1068
c19d1205 1069 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1070
c19d1205
ZW
1071char *
1072md_atof (int type, char * litP, int * sizeP)
1073{
1074 int prec;
1075 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1076 char *t;
1077 int i;
b99bd4ef 1078
c19d1205
ZW
1079 switch (type)
1080 {
1081 case 'f':
1082 case 'F':
1083 case 's':
1084 case 'S':
1085 prec = 2;
1086 break;
b99bd4ef 1087
c19d1205
ZW
1088 case 'd':
1089 case 'D':
1090 case 'r':
1091 case 'R':
1092 prec = 4;
1093 break;
b99bd4ef 1094
c19d1205
ZW
1095 case 'x':
1096 case 'X':
499ac353 1097 prec = 5;
c19d1205 1098 break;
b99bd4ef 1099
c19d1205
ZW
1100 case 'p':
1101 case 'P':
499ac353 1102 prec = 5;
c19d1205 1103 break;
a737bd4d 1104
c19d1205
ZW
1105 default:
1106 *sizeP = 0;
499ac353 1107 return _("Unrecognized or unsupported floating point constant");
c19d1205 1108 }
b99bd4ef 1109
c19d1205
ZW
1110 t = atof_ieee (input_line_pointer, type, words);
1111 if (t)
1112 input_line_pointer = t;
499ac353 1113 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1114
c19d1205
ZW
1115 if (target_big_endian)
1116 {
1117 for (i = 0; i < prec; i++)
1118 {
499ac353
NC
1119 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1120 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1121 }
1122 }
1123 else
1124 {
e74cfd16 1125 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1126 for (i = prec - 1; i >= 0; i--)
1127 {
499ac353
NC
1128 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1129 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1130 }
1131 else
1132 /* For a 4 byte float the order of elements in `words' is 1 0.
1133 For an 8 byte float the order is 1 0 3 2. */
1134 for (i = 0; i < prec; i += 2)
1135 {
499ac353
NC
1136 md_number_to_chars (litP, (valueT) words[i + 1],
1137 sizeof (LITTLENUM_TYPE));
1138 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1139 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1140 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1141 }
1142 }
b99bd4ef 1143
499ac353 1144 return NULL;
c19d1205 1145}
b99bd4ef 1146
c19d1205
ZW
1147/* We handle all bad expressions here, so that we can report the faulty
1148 instruction in the error message. */
1149void
91d6fa6a 1150md_operand (expressionS * exp)
c19d1205
ZW
1151{
1152 if (in_my_get_expression)
91d6fa6a 1153 exp->X_op = O_illegal;
b99bd4ef
NC
1154}
1155
c19d1205 1156/* Immediate values. */
b99bd4ef 1157
c19d1205
ZW
1158/* Generic immediate-value read function for use in directives.
1159 Accepts anything that 'expression' can fold to a constant.
1160 *val receives the number. */
1161#ifdef OBJ_ELF
1162static int
1163immediate_for_directive (int *val)
b99bd4ef 1164{
c19d1205
ZW
1165 expressionS exp;
1166 exp.X_op = O_illegal;
b99bd4ef 1167
c19d1205
ZW
1168 if (is_immediate_prefix (*input_line_pointer))
1169 {
1170 input_line_pointer++;
1171 expression (&exp);
1172 }
b99bd4ef 1173
c19d1205
ZW
1174 if (exp.X_op != O_constant)
1175 {
1176 as_bad (_("expected #constant"));
1177 ignore_rest_of_line ();
1178 return FAIL;
1179 }
1180 *val = exp.X_add_number;
1181 return SUCCESS;
b99bd4ef 1182}
c19d1205 1183#endif
b99bd4ef 1184
c19d1205 1185/* Register parsing. */
b99bd4ef 1186
c19d1205
ZW
1187/* Generic register parser. CCP points to what should be the
1188 beginning of a register name. If it is indeed a valid register
1189 name, advance CCP over it and return the reg_entry structure;
1190 otherwise return NULL. Does not issue diagnostics. */
1191
1192static struct reg_entry *
1193arm_reg_parse_multi (char **ccp)
b99bd4ef 1194{
c19d1205
ZW
1195 char *start = *ccp;
1196 char *p;
1197 struct reg_entry *reg;
b99bd4ef 1198
477330fc
RM
1199 skip_whitespace (start);
1200
c19d1205
ZW
1201#ifdef REGISTER_PREFIX
1202 if (*start != REGISTER_PREFIX)
01cfc07f 1203 return NULL;
c19d1205
ZW
1204 start++;
1205#endif
1206#ifdef OPTIONAL_REGISTER_PREFIX
1207 if (*start == OPTIONAL_REGISTER_PREFIX)
1208 start++;
1209#endif
b99bd4ef 1210
c19d1205
ZW
1211 p = start;
1212 if (!ISALPHA (*p) || !is_name_beginner (*p))
1213 return NULL;
b99bd4ef 1214
c19d1205
ZW
1215 do
1216 p++;
1217 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1218
1219 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1220
1221 if (!reg)
1222 return NULL;
1223
1224 *ccp = p;
1225 return reg;
b99bd4ef
NC
1226}
1227
1228static int
dcbf9037 1229arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1230 enum arm_reg_type type)
b99bd4ef 1231{
c19d1205
ZW
1232 /* Alternative syntaxes are accepted for a few register classes. */
1233 switch (type)
1234 {
1235 case REG_TYPE_MVF:
1236 case REG_TYPE_MVD:
1237 case REG_TYPE_MVFX:
1238 case REG_TYPE_MVDX:
1239 /* Generic coprocessor register names are allowed for these. */
79134647 1240 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1241 return reg->number;
1242 break;
69b97547 1243
c19d1205
ZW
1244 case REG_TYPE_CP:
1245 /* For backward compatibility, a bare number is valid here. */
1246 {
1247 unsigned long processor = strtoul (start, ccp, 10);
1248 if (*ccp != start && processor <= 15)
1249 return processor;
1250 }
6057a28f 1251
c19d1205
ZW
1252 case REG_TYPE_MMXWC:
1253 /* WC includes WCG. ??? I'm not sure this is true for all
1254 instructions that take WC registers. */
79134647 1255 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1256 return reg->number;
6057a28f 1257 break;
c19d1205 1258
6057a28f 1259 default:
c19d1205 1260 break;
6057a28f
NC
1261 }
1262
dcbf9037
JB
1263 return FAIL;
1264}
1265
1266/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1267 return value is the register number or FAIL. */
1268
1269static int
1270arm_reg_parse (char **ccp, enum arm_reg_type type)
1271{
1272 char *start = *ccp;
1273 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1274 int ret;
1275
1276 /* Do not allow a scalar (reg+index) to parse as a register. */
1277 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1278 return FAIL;
1279
1280 if (reg && reg->type == type)
1281 return reg->number;
1282
1283 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1284 return ret;
1285
c19d1205
ZW
1286 *ccp = start;
1287 return FAIL;
1288}
69b97547 1289
dcbf9037
JB
1290/* Parse a Neon type specifier. *STR should point at the leading '.'
1291 character. Does no verification at this stage that the type fits the opcode
1292 properly. E.g.,
1293
1294 .i32.i32.s16
1295 .s32.f32
1296 .u16
1297
1298 Can all be legally parsed by this function.
1299
1300 Fills in neon_type struct pointer with parsed information, and updates STR
1301 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1302 type, FAIL if not. */
1303
1304static int
1305parse_neon_type (struct neon_type *type, char **str)
1306{
1307 char *ptr = *str;
1308
1309 if (type)
1310 type->elems = 0;
1311
1312 while (type->elems < NEON_MAX_TYPE_ELS)
1313 {
1314 enum neon_el_type thistype = NT_untyped;
1315 unsigned thissize = -1u;
1316
1317 if (*ptr != '.')
1318 break;
1319
1320 ptr++;
1321
1322 /* Just a size without an explicit type. */
1323 if (ISDIGIT (*ptr))
1324 goto parsesize;
1325
1326 switch (TOLOWER (*ptr))
1327 {
1328 case 'i': thistype = NT_integer; break;
1329 case 'f': thistype = NT_float; break;
1330 case 'p': thistype = NT_poly; break;
1331 case 's': thistype = NT_signed; break;
1332 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1333 case 'd':
1334 thistype = NT_float;
1335 thissize = 64;
1336 ptr++;
1337 goto done;
dcbf9037
JB
1338 default:
1339 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1340 return FAIL;
1341 }
1342
1343 ptr++;
1344
1345 /* .f is an abbreviation for .f32. */
1346 if (thistype == NT_float && !ISDIGIT (*ptr))
1347 thissize = 32;
1348 else
1349 {
1350 parsesize:
1351 thissize = strtoul (ptr, &ptr, 10);
1352
1353 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1354 && thissize != 64)
1355 {
1356 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1357 return FAIL;
1358 }
1359 }
1360
037e8744 1361 done:
dcbf9037 1362 if (type)
477330fc
RM
1363 {
1364 type->el[type->elems].type = thistype;
dcbf9037
JB
1365 type->el[type->elems].size = thissize;
1366 type->elems++;
1367 }
1368 }
1369
1370 /* Empty/missing type is not a successful parse. */
1371 if (type->elems == 0)
1372 return FAIL;
1373
1374 *str = ptr;
1375
1376 return SUCCESS;
1377}
1378
1379/* Errors may be set multiple times during parsing or bit encoding
1380 (particularly in the Neon bits), but usually the earliest error which is set
1381 will be the most meaningful. Avoid overwriting it with later (cascading)
1382 errors by calling this function. */
1383
1384static void
1385first_error (const char *err)
1386{
1387 if (!inst.error)
1388 inst.error = err;
1389}
1390
1391/* Parse a single type, e.g. ".s32", leading period included. */
1392static int
1393parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1394{
1395 char *str = *ccp;
1396 struct neon_type optype;
1397
1398 if (*str == '.')
1399 {
1400 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1401 {
1402 if (optype.elems == 1)
1403 *vectype = optype.el[0];
1404 else
1405 {
1406 first_error (_("only one type should be specified for operand"));
1407 return FAIL;
1408 }
1409 }
dcbf9037 1410 else
477330fc
RM
1411 {
1412 first_error (_("vector type expected"));
1413 return FAIL;
1414 }
dcbf9037
JB
1415 }
1416 else
1417 return FAIL;
5f4273c7 1418
dcbf9037 1419 *ccp = str;
5f4273c7 1420
dcbf9037
JB
1421 return SUCCESS;
1422}
1423
1424/* Special meanings for indices (which have a range of 0-7), which will fit into
1425 a 4-bit integer. */
1426
1427#define NEON_ALL_LANES 15
1428#define NEON_INTERLEAVE_LANES 14
1429
1430/* Parse either a register or a scalar, with an optional type. Return the
1431 register number, and optionally fill in the actual type of the register
1432 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1433 type/index information in *TYPEINFO. */
1434
1435static int
1436parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1437 enum arm_reg_type *rtype,
1438 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1439{
1440 char *str = *ccp;
1441 struct reg_entry *reg = arm_reg_parse_multi (&str);
1442 struct neon_typed_alias atype;
1443 struct neon_type_el parsetype;
1444
1445 atype.defined = 0;
1446 atype.index = -1;
1447 atype.eltype.type = NT_invtype;
1448 atype.eltype.size = -1;
1449
1450 /* Try alternate syntax for some types of register. Note these are mutually
1451 exclusive with the Neon syntax extensions. */
1452 if (reg == NULL)
1453 {
1454 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1455 if (altreg != FAIL)
477330fc 1456 *ccp = str;
dcbf9037 1457 if (typeinfo)
477330fc 1458 *typeinfo = atype;
dcbf9037
JB
1459 return altreg;
1460 }
1461
037e8744
JB
1462 /* Undo polymorphism when a set of register types may be accepted. */
1463 if ((type == REG_TYPE_NDQ
1464 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1465 || (type == REG_TYPE_VFSD
477330fc 1466 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1467 || (type == REG_TYPE_NSDQ
477330fc
RM
1468 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1469 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1470 || (type == REG_TYPE_MMXWC
1471 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1472 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1473
1474 if (type != reg->type)
1475 return FAIL;
1476
1477 if (reg->neon)
1478 atype = *reg->neon;
5f4273c7 1479
dcbf9037
JB
1480 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1481 {
1482 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1483 {
1484 first_error (_("can't redefine type for operand"));
1485 return FAIL;
1486 }
dcbf9037
JB
1487 atype.defined |= NTA_HASTYPE;
1488 atype.eltype = parsetype;
1489 }
5f4273c7 1490
dcbf9037
JB
1491 if (skip_past_char (&str, '[') == SUCCESS)
1492 {
1493 if (type != REG_TYPE_VFD)
477330fc
RM
1494 {
1495 first_error (_("only D registers may be indexed"));
1496 return FAIL;
1497 }
5f4273c7 1498
dcbf9037 1499 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1500 {
1501 first_error (_("can't change index for operand"));
1502 return FAIL;
1503 }
dcbf9037
JB
1504
1505 atype.defined |= NTA_HASINDEX;
1506
1507 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1508 atype.index = NEON_ALL_LANES;
dcbf9037 1509 else
477330fc
RM
1510 {
1511 expressionS exp;
dcbf9037 1512
477330fc 1513 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1514
477330fc
RM
1515 if (exp.X_op != O_constant)
1516 {
1517 first_error (_("constant expression required"));
1518 return FAIL;
1519 }
dcbf9037 1520
477330fc
RM
1521 if (skip_past_char (&str, ']') == FAIL)
1522 return FAIL;
dcbf9037 1523
477330fc
RM
1524 atype.index = exp.X_add_number;
1525 }
dcbf9037 1526 }
5f4273c7 1527
dcbf9037
JB
1528 if (typeinfo)
1529 *typeinfo = atype;
5f4273c7 1530
dcbf9037
JB
1531 if (rtype)
1532 *rtype = type;
5f4273c7 1533
dcbf9037 1534 *ccp = str;
5f4273c7 1535
dcbf9037
JB
1536 return reg->number;
1537}
1538
1539/* Like arm_reg_parse, but allow allow the following extra features:
1540 - If RTYPE is non-zero, return the (possibly restricted) type of the
1541 register (e.g. Neon double or quad reg when either has been requested).
1542 - If this is a Neon vector type with additional type information, fill
1543 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1544 This function will fault on encountering a scalar. */
dcbf9037
JB
1545
1546static int
1547arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1548 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1549{
1550 struct neon_typed_alias atype;
1551 char *str = *ccp;
1552 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1553
1554 if (reg == FAIL)
1555 return FAIL;
1556
0855e32b
NS
1557 /* Do not allow regname(... to parse as a register. */
1558 if (*str == '(')
1559 return FAIL;
1560
dcbf9037
JB
1561 /* Do not allow a scalar (reg+index) to parse as a register. */
1562 if ((atype.defined & NTA_HASINDEX) != 0)
1563 {
1564 first_error (_("register operand expected, but got scalar"));
1565 return FAIL;
1566 }
1567
1568 if (vectype)
1569 *vectype = atype.eltype;
1570
1571 *ccp = str;
1572
1573 return reg;
1574}
1575
1576#define NEON_SCALAR_REG(X) ((X) >> 4)
1577#define NEON_SCALAR_INDEX(X) ((X) & 15)
1578
5287ad62
JB
1579/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1580 have enough information to be able to do a good job bounds-checking. So, we
1581 just do easy checks here, and do further checks later. */
1582
1583static int
dcbf9037 1584parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1585{
dcbf9037 1586 int reg;
5287ad62 1587 char *str = *ccp;
dcbf9037 1588 struct neon_typed_alias atype;
5f4273c7 1589
dcbf9037 1590 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1591
dcbf9037 1592 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1593 return FAIL;
5f4273c7 1594
dcbf9037 1595 if (atype.index == NEON_ALL_LANES)
5287ad62 1596 {
dcbf9037 1597 first_error (_("scalar must have an index"));
5287ad62
JB
1598 return FAIL;
1599 }
dcbf9037 1600 else if (atype.index >= 64 / elsize)
5287ad62 1601 {
dcbf9037 1602 first_error (_("scalar index out of range"));
5287ad62
JB
1603 return FAIL;
1604 }
5f4273c7 1605
dcbf9037
JB
1606 if (type)
1607 *type = atype.eltype;
5f4273c7 1608
5287ad62 1609 *ccp = str;
5f4273c7 1610
dcbf9037 1611 return reg * 16 + atype.index;
5287ad62
JB
1612}
1613
c19d1205 1614/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1615
c19d1205
ZW
1616static long
1617parse_reg_list (char ** strp)
1618{
1619 char * str = * strp;
1620 long range = 0;
1621 int another_range;
a737bd4d 1622
c19d1205
ZW
1623 /* We come back here if we get ranges concatenated by '+' or '|'. */
1624 do
6057a28f 1625 {
477330fc
RM
1626 skip_whitespace (str);
1627
c19d1205 1628 another_range = 0;
a737bd4d 1629
c19d1205
ZW
1630 if (*str == '{')
1631 {
1632 int in_range = 0;
1633 int cur_reg = -1;
a737bd4d 1634
c19d1205
ZW
1635 str++;
1636 do
1637 {
1638 int reg;
6057a28f 1639
dcbf9037 1640 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1641 {
dcbf9037 1642 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1643 return FAIL;
1644 }
a737bd4d 1645
c19d1205
ZW
1646 if (in_range)
1647 {
1648 int i;
a737bd4d 1649
c19d1205
ZW
1650 if (reg <= cur_reg)
1651 {
dcbf9037 1652 first_error (_("bad range in register list"));
c19d1205
ZW
1653 return FAIL;
1654 }
40a18ebd 1655
c19d1205
ZW
1656 for (i = cur_reg + 1; i < reg; i++)
1657 {
1658 if (range & (1 << i))
1659 as_tsktsk
1660 (_("Warning: duplicated register (r%d) in register list"),
1661 i);
1662 else
1663 range |= 1 << i;
1664 }
1665 in_range = 0;
1666 }
a737bd4d 1667
c19d1205
ZW
1668 if (range & (1 << reg))
1669 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1670 reg);
1671 else if (reg <= cur_reg)
1672 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1673
c19d1205
ZW
1674 range |= 1 << reg;
1675 cur_reg = reg;
1676 }
1677 while (skip_past_comma (&str) != FAIL
1678 || (in_range = 1, *str++ == '-'));
1679 str--;
a737bd4d 1680
d996d970 1681 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1682 {
dcbf9037 1683 first_error (_("missing `}'"));
c19d1205
ZW
1684 return FAIL;
1685 }
1686 }
1687 else
1688 {
91d6fa6a 1689 expressionS exp;
40a18ebd 1690
91d6fa6a 1691 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1692 return FAIL;
40a18ebd 1693
91d6fa6a 1694 if (exp.X_op == O_constant)
c19d1205 1695 {
91d6fa6a
NC
1696 if (exp.X_add_number
1697 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1698 {
1699 inst.error = _("invalid register mask");
1700 return FAIL;
1701 }
a737bd4d 1702
91d6fa6a 1703 if ((range & exp.X_add_number) != 0)
c19d1205 1704 {
91d6fa6a 1705 int regno = range & exp.X_add_number;
a737bd4d 1706
c19d1205
ZW
1707 regno &= -regno;
1708 regno = (1 << regno) - 1;
1709 as_tsktsk
1710 (_("Warning: duplicated register (r%d) in register list"),
1711 regno);
1712 }
a737bd4d 1713
91d6fa6a 1714 range |= exp.X_add_number;
c19d1205
ZW
1715 }
1716 else
1717 {
1718 if (inst.reloc.type != 0)
1719 {
1720 inst.error = _("expression too complex");
1721 return FAIL;
1722 }
a737bd4d 1723
91d6fa6a 1724 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1725 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1726 inst.reloc.pc_rel = 0;
1727 }
1728 }
a737bd4d 1729
c19d1205
ZW
1730 if (*str == '|' || *str == '+')
1731 {
1732 str++;
1733 another_range = 1;
1734 }
a737bd4d 1735 }
c19d1205 1736 while (another_range);
a737bd4d 1737
c19d1205
ZW
1738 *strp = str;
1739 return range;
a737bd4d
NC
1740}
1741
5287ad62
JB
1742/* Types of registers in a list. */
1743
1744enum reg_list_els
1745{
1746 REGLIST_VFP_S,
1747 REGLIST_VFP_D,
1748 REGLIST_NEON_D
1749};
1750
c19d1205
ZW
1751/* Parse a VFP register list. If the string is invalid return FAIL.
1752 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1753 register. Parses registers of type ETYPE.
1754 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1755 - Q registers can be used to specify pairs of D registers
1756 - { } can be omitted from around a singleton register list
477330fc
RM
1757 FIXME: This is not implemented, as it would require backtracking in
1758 some cases, e.g.:
1759 vtbl.8 d3,d4,d5
1760 This could be done (the meaning isn't really ambiguous), but doesn't
1761 fit in well with the current parsing framework.
dcbf9037
JB
1762 - 32 D registers may be used (also true for VFPv3).
1763 FIXME: Types are ignored in these register lists, which is probably a
1764 bug. */
6057a28f 1765
c19d1205 1766static int
037e8744 1767parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1768{
037e8744 1769 char *str = *ccp;
c19d1205
ZW
1770 int base_reg;
1771 int new_base;
21d799b5 1772 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1773 int max_regs = 0;
c19d1205
ZW
1774 int count = 0;
1775 int warned = 0;
1776 unsigned long mask = 0;
a737bd4d 1777 int i;
6057a28f 1778
477330fc 1779 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1780 {
1781 inst.error = _("expecting {");
1782 return FAIL;
1783 }
6057a28f 1784
5287ad62 1785 switch (etype)
c19d1205 1786 {
5287ad62 1787 case REGLIST_VFP_S:
c19d1205
ZW
1788 regtype = REG_TYPE_VFS;
1789 max_regs = 32;
5287ad62 1790 break;
5f4273c7 1791
5287ad62
JB
1792 case REGLIST_VFP_D:
1793 regtype = REG_TYPE_VFD;
b7fc2769 1794 break;
5f4273c7 1795
b7fc2769
JB
1796 case REGLIST_NEON_D:
1797 regtype = REG_TYPE_NDQ;
1798 break;
1799 }
1800
1801 if (etype != REGLIST_VFP_S)
1802 {
b1cc4aeb
PB
1803 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1804 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1805 {
1806 max_regs = 32;
1807 if (thumb_mode)
1808 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1809 fpu_vfp_ext_d32);
1810 else
1811 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1812 fpu_vfp_ext_d32);
1813 }
5287ad62 1814 else
477330fc 1815 max_regs = 16;
c19d1205 1816 }
6057a28f 1817
c19d1205 1818 base_reg = max_regs;
a737bd4d 1819
c19d1205
ZW
1820 do
1821 {
5287ad62 1822 int setmask = 1, addregs = 1;
dcbf9037 1823
037e8744 1824 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1825
c19d1205 1826 if (new_base == FAIL)
a737bd4d 1827 {
dcbf9037 1828 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1829 return FAIL;
1830 }
5f4273c7 1831
b7fc2769 1832 if (new_base >= max_regs)
477330fc
RM
1833 {
1834 first_error (_("register out of range in list"));
1835 return FAIL;
1836 }
5f4273c7 1837
5287ad62
JB
1838 /* Note: a value of 2 * n is returned for the register Q<n>. */
1839 if (regtype == REG_TYPE_NQ)
477330fc
RM
1840 {
1841 setmask = 3;
1842 addregs = 2;
1843 }
5287ad62 1844
c19d1205
ZW
1845 if (new_base < base_reg)
1846 base_reg = new_base;
a737bd4d 1847
5287ad62 1848 if (mask & (setmask << new_base))
c19d1205 1849 {
dcbf9037 1850 first_error (_("invalid register list"));
c19d1205 1851 return FAIL;
a737bd4d 1852 }
a737bd4d 1853
c19d1205
ZW
1854 if ((mask >> new_base) != 0 && ! warned)
1855 {
1856 as_tsktsk (_("register list not in ascending order"));
1857 warned = 1;
1858 }
0bbf2aa4 1859
5287ad62
JB
1860 mask |= setmask << new_base;
1861 count += addregs;
0bbf2aa4 1862
037e8744 1863 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1864 {
1865 int high_range;
0bbf2aa4 1866
037e8744 1867 str++;
0bbf2aa4 1868
037e8744 1869 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1870 == FAIL)
c19d1205
ZW
1871 {
1872 inst.error = gettext (reg_expected_msgs[regtype]);
1873 return FAIL;
1874 }
0bbf2aa4 1875
477330fc
RM
1876 if (high_range >= max_regs)
1877 {
1878 first_error (_("register out of range in list"));
1879 return FAIL;
1880 }
b7fc2769 1881
477330fc
RM
1882 if (regtype == REG_TYPE_NQ)
1883 high_range = high_range + 1;
5287ad62 1884
c19d1205
ZW
1885 if (high_range <= new_base)
1886 {
1887 inst.error = _("register range not in ascending order");
1888 return FAIL;
1889 }
0bbf2aa4 1890
5287ad62 1891 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1892 {
5287ad62 1893 if (mask & (setmask << new_base))
0bbf2aa4 1894 {
c19d1205
ZW
1895 inst.error = _("invalid register list");
1896 return FAIL;
0bbf2aa4 1897 }
c19d1205 1898
5287ad62
JB
1899 mask |= setmask << new_base;
1900 count += addregs;
0bbf2aa4 1901 }
0bbf2aa4 1902 }
0bbf2aa4 1903 }
037e8744 1904 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1905
037e8744 1906 str++;
0bbf2aa4 1907
c19d1205
ZW
1908 /* Sanity check -- should have raised a parse error above. */
1909 if (count == 0 || count > max_regs)
1910 abort ();
1911
1912 *pbase = base_reg;
1913
1914 /* Final test -- the registers must be consecutive. */
1915 mask >>= base_reg;
1916 for (i = 0; i < count; i++)
1917 {
1918 if ((mask & (1u << i)) == 0)
1919 {
1920 inst.error = _("non-contiguous register range");
1921 return FAIL;
1922 }
1923 }
1924
037e8744
JB
1925 *ccp = str;
1926
c19d1205 1927 return count;
b99bd4ef
NC
1928}
1929
dcbf9037
JB
1930/* True if two alias types are the same. */
1931
c921be7d 1932static bfd_boolean
dcbf9037
JB
1933neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1934{
1935 if (!a && !b)
c921be7d 1936 return TRUE;
5f4273c7 1937
dcbf9037 1938 if (!a || !b)
c921be7d 1939 return FALSE;
dcbf9037
JB
1940
1941 if (a->defined != b->defined)
c921be7d 1942 return FALSE;
5f4273c7 1943
dcbf9037
JB
1944 if ((a->defined & NTA_HASTYPE) != 0
1945 && (a->eltype.type != b->eltype.type
477330fc 1946 || a->eltype.size != b->eltype.size))
c921be7d 1947 return FALSE;
dcbf9037
JB
1948
1949 if ((a->defined & NTA_HASINDEX) != 0
1950 && (a->index != b->index))
c921be7d 1951 return FALSE;
5f4273c7 1952
c921be7d 1953 return TRUE;
dcbf9037
JB
1954}
1955
5287ad62
JB
1956/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1957 The base register is put in *PBASE.
dcbf9037 1958 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1959 the return value.
1960 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1961 Bits [6:5] encode the list length (minus one).
1962 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1963
5287ad62 1964#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1965#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1966#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1967
1968static int
dcbf9037 1969parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 1970 struct neon_type_el *eltype)
5287ad62
JB
1971{
1972 char *ptr = *str;
1973 int base_reg = -1;
1974 int reg_incr = -1;
1975 int count = 0;
1976 int lane = -1;
1977 int leading_brace = 0;
1978 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1979 const char *const incr_error = _("register stride must be 1 or 2");
1980 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1981 struct neon_typed_alias firsttype;
5f4273c7 1982
5287ad62
JB
1983 if (skip_past_char (&ptr, '{') == SUCCESS)
1984 leading_brace = 1;
5f4273c7 1985
5287ad62
JB
1986 do
1987 {
dcbf9037
JB
1988 struct neon_typed_alias atype;
1989 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1990
5287ad62 1991 if (getreg == FAIL)
477330fc
RM
1992 {
1993 first_error (_(reg_expected_msgs[rtype]));
1994 return FAIL;
1995 }
5f4273c7 1996
5287ad62 1997 if (base_reg == -1)
477330fc
RM
1998 {
1999 base_reg = getreg;
2000 if (rtype == REG_TYPE_NQ)
2001 {
2002 reg_incr = 1;
2003 }
2004 firsttype = atype;
2005 }
5287ad62 2006 else if (reg_incr == -1)
477330fc
RM
2007 {
2008 reg_incr = getreg - base_reg;
2009 if (reg_incr < 1 || reg_incr > 2)
2010 {
2011 first_error (_(incr_error));
2012 return FAIL;
2013 }
2014 }
5287ad62 2015 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2016 {
2017 first_error (_(incr_error));
2018 return FAIL;
2019 }
dcbf9037 2020
c921be7d 2021 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2022 {
2023 first_error (_(type_error));
2024 return FAIL;
2025 }
5f4273c7 2026
5287ad62 2027 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2028 modes. */
5287ad62 2029 if (ptr[0] == '-')
477330fc
RM
2030 {
2031 struct neon_typed_alias htype;
2032 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2033 if (lane == -1)
2034 lane = NEON_INTERLEAVE_LANES;
2035 else if (lane != NEON_INTERLEAVE_LANES)
2036 {
2037 first_error (_(type_error));
2038 return FAIL;
2039 }
2040 if (reg_incr == -1)
2041 reg_incr = 1;
2042 else if (reg_incr != 1)
2043 {
2044 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2045 return FAIL;
2046 }
2047 ptr++;
2048 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2049 if (hireg == FAIL)
2050 {
2051 first_error (_(reg_expected_msgs[rtype]));
2052 return FAIL;
2053 }
2054 if (! neon_alias_types_same (&htype, &firsttype))
2055 {
2056 first_error (_(type_error));
2057 return FAIL;
2058 }
2059 count += hireg + dregs - getreg;
2060 continue;
2061 }
5f4273c7 2062
5287ad62
JB
2063 /* If we're using Q registers, we can't use [] or [n] syntax. */
2064 if (rtype == REG_TYPE_NQ)
477330fc
RM
2065 {
2066 count += 2;
2067 continue;
2068 }
5f4273c7 2069
dcbf9037 2070 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2071 {
2072 if (lane == -1)
2073 lane = atype.index;
2074 else if (lane != atype.index)
2075 {
2076 first_error (_(type_error));
2077 return FAIL;
2078 }
2079 }
5287ad62 2080 else if (lane == -1)
477330fc 2081 lane = NEON_INTERLEAVE_LANES;
5287ad62 2082 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2083 {
2084 first_error (_(type_error));
2085 return FAIL;
2086 }
5287ad62
JB
2087 count++;
2088 }
2089 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2090
5287ad62
JB
2091 /* No lane set by [x]. We must be interleaving structures. */
2092 if (lane == -1)
2093 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2094
5287ad62
JB
2095 /* Sanity check. */
2096 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2097 || (count > 1 && reg_incr == -1))
2098 {
dcbf9037 2099 first_error (_("error parsing element/structure list"));
5287ad62
JB
2100 return FAIL;
2101 }
2102
2103 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2104 {
dcbf9037 2105 first_error (_("expected }"));
5287ad62
JB
2106 return FAIL;
2107 }
5f4273c7 2108
5287ad62
JB
2109 if (reg_incr == -1)
2110 reg_incr = 1;
2111
dcbf9037
JB
2112 if (eltype)
2113 *eltype = firsttype.eltype;
2114
5287ad62
JB
2115 *pbase = base_reg;
2116 *str = ptr;
5f4273c7 2117
5287ad62
JB
2118 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2119}
2120
c19d1205
ZW
2121/* Parse an explicit relocation suffix on an expression. This is
2122 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2123 arm_reloc_hsh contains no entries, so this function can only
2124 succeed if there is no () after the word. Returns -1 on error,
2125 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2126
c19d1205
ZW
2127static int
2128parse_reloc (char **str)
b99bd4ef 2129{
c19d1205
ZW
2130 struct reloc_entry *r;
2131 char *p, *q;
b99bd4ef 2132
c19d1205
ZW
2133 if (**str != '(')
2134 return BFD_RELOC_UNUSED;
b99bd4ef 2135
c19d1205
ZW
2136 p = *str + 1;
2137 q = p;
2138
2139 while (*q && *q != ')' && *q != ',')
2140 q++;
2141 if (*q != ')')
2142 return -1;
2143
21d799b5
NC
2144 if ((r = (struct reloc_entry *)
2145 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2146 return -1;
2147
2148 *str = q + 1;
2149 return r->reloc;
b99bd4ef
NC
2150}
2151
c19d1205
ZW
2152/* Directives: register aliases. */
2153
dcbf9037 2154static struct reg_entry *
90ec0d68 2155insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2156{
d3ce72d0 2157 struct reg_entry *new_reg;
c19d1205 2158 const char *name;
b99bd4ef 2159
d3ce72d0 2160 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2161 {
d3ce72d0 2162 if (new_reg->builtin)
c19d1205 2163 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2164
c19d1205
ZW
2165 /* Only warn about a redefinition if it's not defined as the
2166 same register. */
d3ce72d0 2167 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2168 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2169
d929913e 2170 return NULL;
c19d1205 2171 }
b99bd4ef 2172
c19d1205 2173 name = xstrdup (str);
d3ce72d0 2174 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2175
d3ce72d0
NC
2176 new_reg->name = name;
2177 new_reg->number = number;
2178 new_reg->type = type;
2179 new_reg->builtin = FALSE;
2180 new_reg->neon = NULL;
b99bd4ef 2181
d3ce72d0 2182 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2183 abort ();
5f4273c7 2184
d3ce72d0 2185 return new_reg;
dcbf9037
JB
2186}
2187
2188static void
2189insert_neon_reg_alias (char *str, int number, int type,
477330fc 2190 struct neon_typed_alias *atype)
dcbf9037
JB
2191{
2192 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2193
dcbf9037
JB
2194 if (!reg)
2195 {
2196 first_error (_("attempt to redefine typed alias"));
2197 return;
2198 }
5f4273c7 2199
dcbf9037
JB
2200 if (atype)
2201 {
21d799b5 2202 reg->neon = (struct neon_typed_alias *)
477330fc 2203 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2204 *reg->neon = *atype;
2205 }
c19d1205 2206}
b99bd4ef 2207
c19d1205 2208/* Look for the .req directive. This is of the form:
b99bd4ef 2209
c19d1205 2210 new_register_name .req existing_register_name
b99bd4ef 2211
c19d1205 2212 If we find one, or if it looks sufficiently like one that we want to
d929913e 2213 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2214
d929913e 2215static bfd_boolean
c19d1205
ZW
2216create_register_alias (char * newname, char *p)
2217{
2218 struct reg_entry *old;
2219 char *oldname, *nbuf;
2220 size_t nlen;
b99bd4ef 2221
c19d1205
ZW
2222 /* The input scrubber ensures that whitespace after the mnemonic is
2223 collapsed to single spaces. */
2224 oldname = p;
2225 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2226 return FALSE;
b99bd4ef 2227
c19d1205
ZW
2228 oldname += 6;
2229 if (*oldname == '\0')
d929913e 2230 return FALSE;
b99bd4ef 2231
21d799b5 2232 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2233 if (!old)
b99bd4ef 2234 {
c19d1205 2235 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2236 return TRUE;
b99bd4ef
NC
2237 }
2238
c19d1205
ZW
2239 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2240 the desired alias name, and p points to its end. If not, then
2241 the desired alias name is in the global original_case_string. */
2242#ifdef TC_CASE_SENSITIVE
2243 nlen = p - newname;
2244#else
2245 newname = original_case_string;
2246 nlen = strlen (newname);
2247#endif
b99bd4ef 2248
21d799b5 2249 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2250 memcpy (nbuf, newname, nlen);
2251 nbuf[nlen] = '\0';
b99bd4ef 2252
c19d1205
ZW
2253 /* Create aliases under the new name as stated; an all-lowercase
2254 version of the new name; and an all-uppercase version of the new
2255 name. */
d929913e
NC
2256 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2257 {
2258 for (p = nbuf; *p; p++)
2259 *p = TOUPPER (*p);
c19d1205 2260
d929913e
NC
2261 if (strncmp (nbuf, newname, nlen))
2262 {
2263 /* If this attempt to create an additional alias fails, do not bother
2264 trying to create the all-lower case alias. We will fail and issue
2265 a second, duplicate error message. This situation arises when the
2266 programmer does something like:
2267 foo .req r0
2268 Foo .req r1
2269 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2270 the artificial FOO alias because it has already been created by the
d929913e
NC
2271 first .req. */
2272 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2273 return TRUE;
2274 }
c19d1205 2275
d929913e
NC
2276 for (p = nbuf; *p; p++)
2277 *p = TOLOWER (*p);
c19d1205 2278
d929913e
NC
2279 if (strncmp (nbuf, newname, nlen))
2280 insert_reg_alias (nbuf, old->number, old->type);
2281 }
c19d1205 2282
d929913e 2283 return TRUE;
b99bd4ef
NC
2284}
2285
dcbf9037
JB
2286/* Create a Neon typed/indexed register alias using directives, e.g.:
2287 X .dn d5.s32[1]
2288 Y .qn 6.s16
2289 Z .dn d7
2290 T .dn Z[0]
2291 These typed registers can be used instead of the types specified after the
2292 Neon mnemonic, so long as all operands given have types. Types can also be
2293 specified directly, e.g.:
5f4273c7 2294 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2295
c921be7d 2296static bfd_boolean
dcbf9037
JB
2297create_neon_reg_alias (char *newname, char *p)
2298{
2299 enum arm_reg_type basetype;
2300 struct reg_entry *basereg;
2301 struct reg_entry mybasereg;
2302 struct neon_type ntype;
2303 struct neon_typed_alias typeinfo;
12d6b0b7 2304 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2305 int namelen;
5f4273c7 2306
dcbf9037
JB
2307 typeinfo.defined = 0;
2308 typeinfo.eltype.type = NT_invtype;
2309 typeinfo.eltype.size = -1;
2310 typeinfo.index = -1;
5f4273c7 2311
dcbf9037 2312 nameend = p;
5f4273c7 2313
dcbf9037
JB
2314 if (strncmp (p, " .dn ", 5) == 0)
2315 basetype = REG_TYPE_VFD;
2316 else if (strncmp (p, " .qn ", 5) == 0)
2317 basetype = REG_TYPE_NQ;
2318 else
c921be7d 2319 return FALSE;
5f4273c7 2320
dcbf9037 2321 p += 5;
5f4273c7 2322
dcbf9037 2323 if (*p == '\0')
c921be7d 2324 return FALSE;
5f4273c7 2325
dcbf9037
JB
2326 basereg = arm_reg_parse_multi (&p);
2327
2328 if (basereg && basereg->type != basetype)
2329 {
2330 as_bad (_("bad type for register"));
c921be7d 2331 return FALSE;
dcbf9037
JB
2332 }
2333
2334 if (basereg == NULL)
2335 {
2336 expressionS exp;
2337 /* Try parsing as an integer. */
2338 my_get_expression (&exp, &p, GE_NO_PREFIX);
2339 if (exp.X_op != O_constant)
477330fc
RM
2340 {
2341 as_bad (_("expression must be constant"));
2342 return FALSE;
2343 }
dcbf9037
JB
2344 basereg = &mybasereg;
2345 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2346 : exp.X_add_number;
dcbf9037
JB
2347 basereg->neon = 0;
2348 }
2349
2350 if (basereg->neon)
2351 typeinfo = *basereg->neon;
2352
2353 if (parse_neon_type (&ntype, &p) == SUCCESS)
2354 {
2355 /* We got a type. */
2356 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2357 {
2358 as_bad (_("can't redefine the type of a register alias"));
2359 return FALSE;
2360 }
5f4273c7 2361
dcbf9037
JB
2362 typeinfo.defined |= NTA_HASTYPE;
2363 if (ntype.elems != 1)
477330fc
RM
2364 {
2365 as_bad (_("you must specify a single type only"));
2366 return FALSE;
2367 }
dcbf9037
JB
2368 typeinfo.eltype = ntype.el[0];
2369 }
5f4273c7 2370
dcbf9037
JB
2371 if (skip_past_char (&p, '[') == SUCCESS)
2372 {
2373 expressionS exp;
2374 /* We got a scalar index. */
5f4273c7 2375
dcbf9037 2376 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2377 {
2378 as_bad (_("can't redefine the index of a scalar alias"));
2379 return FALSE;
2380 }
5f4273c7 2381
dcbf9037 2382 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2383
dcbf9037 2384 if (exp.X_op != O_constant)
477330fc
RM
2385 {
2386 as_bad (_("scalar index must be constant"));
2387 return FALSE;
2388 }
5f4273c7 2389
dcbf9037
JB
2390 typeinfo.defined |= NTA_HASINDEX;
2391 typeinfo.index = exp.X_add_number;
5f4273c7 2392
dcbf9037 2393 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2394 {
2395 as_bad (_("expecting ]"));
2396 return FALSE;
2397 }
dcbf9037
JB
2398 }
2399
15735687
NS
2400 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2401 the desired alias name, and p points to its end. If not, then
2402 the desired alias name is in the global original_case_string. */
2403#ifdef TC_CASE_SENSITIVE
dcbf9037 2404 namelen = nameend - newname;
15735687
NS
2405#else
2406 newname = original_case_string;
2407 namelen = strlen (newname);
2408#endif
2409
21d799b5 2410 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2411 strncpy (namebuf, newname, namelen);
2412 namebuf[namelen] = '\0';
5f4273c7 2413
dcbf9037 2414 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2415 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2416
dcbf9037
JB
2417 /* Insert name in all uppercase. */
2418 for (p = namebuf; *p; p++)
2419 *p = TOUPPER (*p);
5f4273c7 2420
dcbf9037
JB
2421 if (strncmp (namebuf, newname, namelen))
2422 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2423 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2424
dcbf9037
JB
2425 /* Insert name in all lowercase. */
2426 for (p = namebuf; *p; p++)
2427 *p = TOLOWER (*p);
5f4273c7 2428
dcbf9037
JB
2429 if (strncmp (namebuf, newname, namelen))
2430 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2431 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2432
c921be7d 2433 return TRUE;
dcbf9037
JB
2434}
2435
c19d1205
ZW
2436/* Should never be called, as .req goes between the alias and the
2437 register name, not at the beginning of the line. */
c921be7d 2438
b99bd4ef 2439static void
c19d1205 2440s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2441{
c19d1205
ZW
2442 as_bad (_("invalid syntax for .req directive"));
2443}
b99bd4ef 2444
dcbf9037
JB
2445static void
2446s_dn (int a ATTRIBUTE_UNUSED)
2447{
2448 as_bad (_("invalid syntax for .dn directive"));
2449}
2450
2451static void
2452s_qn (int a ATTRIBUTE_UNUSED)
2453{
2454 as_bad (_("invalid syntax for .qn directive"));
2455}
2456
c19d1205
ZW
2457/* The .unreq directive deletes an alias which was previously defined
2458 by .req. For example:
b99bd4ef 2459
c19d1205
ZW
2460 my_alias .req r11
2461 .unreq my_alias */
b99bd4ef
NC
2462
2463static void
c19d1205 2464s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2465{
c19d1205
ZW
2466 char * name;
2467 char saved_char;
b99bd4ef 2468
c19d1205
ZW
2469 name = input_line_pointer;
2470
2471 while (*input_line_pointer != 0
2472 && *input_line_pointer != ' '
2473 && *input_line_pointer != '\n')
2474 ++input_line_pointer;
2475
2476 saved_char = *input_line_pointer;
2477 *input_line_pointer = 0;
2478
2479 if (!*name)
2480 as_bad (_("invalid syntax for .unreq directive"));
2481 else
2482 {
21d799b5 2483 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2484 name);
c19d1205
ZW
2485
2486 if (!reg)
2487 as_bad (_("unknown register alias '%s'"), name);
2488 else if (reg->builtin)
a1727c1a 2489 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2490 name);
2491 else
2492 {
d929913e
NC
2493 char * p;
2494 char * nbuf;
2495
db0bc284 2496 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2497 free ((char *) reg->name);
477330fc
RM
2498 if (reg->neon)
2499 free (reg->neon);
c19d1205 2500 free (reg);
d929913e
NC
2501
2502 /* Also locate the all upper case and all lower case versions.
2503 Do not complain if we cannot find one or the other as it
2504 was probably deleted above. */
5f4273c7 2505
d929913e
NC
2506 nbuf = strdup (name);
2507 for (p = nbuf; *p; p++)
2508 *p = TOUPPER (*p);
21d799b5 2509 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2510 if (reg)
2511 {
db0bc284 2512 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2513 free ((char *) reg->name);
2514 if (reg->neon)
2515 free (reg->neon);
2516 free (reg);
2517 }
2518
2519 for (p = nbuf; *p; p++)
2520 *p = TOLOWER (*p);
21d799b5 2521 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2522 if (reg)
2523 {
db0bc284 2524 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2525 free ((char *) reg->name);
2526 if (reg->neon)
2527 free (reg->neon);
2528 free (reg);
2529 }
2530
2531 free (nbuf);
c19d1205
ZW
2532 }
2533 }
b99bd4ef 2534
c19d1205 2535 *input_line_pointer = saved_char;
b99bd4ef
NC
2536 demand_empty_rest_of_line ();
2537}
2538
c19d1205
ZW
2539/* Directives: Instruction set selection. */
2540
2541#ifdef OBJ_ELF
2542/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2543 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2544 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2545 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2546
cd000bff
DJ
2547/* Create a new mapping symbol for the transition to STATE. */
2548
2549static void
2550make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2551{
a737bd4d 2552 symbolS * symbolP;
c19d1205
ZW
2553 const char * symname;
2554 int type;
b99bd4ef 2555
c19d1205 2556 switch (state)
b99bd4ef 2557 {
c19d1205
ZW
2558 case MAP_DATA:
2559 symname = "$d";
2560 type = BSF_NO_FLAGS;
2561 break;
2562 case MAP_ARM:
2563 symname = "$a";
2564 type = BSF_NO_FLAGS;
2565 break;
2566 case MAP_THUMB:
2567 symname = "$t";
2568 type = BSF_NO_FLAGS;
2569 break;
c19d1205
ZW
2570 default:
2571 abort ();
2572 }
2573
cd000bff 2574 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2575 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2576
2577 switch (state)
2578 {
2579 case MAP_ARM:
2580 THUMB_SET_FUNC (symbolP, 0);
2581 ARM_SET_THUMB (symbolP, 0);
2582 ARM_SET_INTERWORK (symbolP, support_interwork);
2583 break;
2584
2585 case MAP_THUMB:
2586 THUMB_SET_FUNC (symbolP, 1);
2587 ARM_SET_THUMB (symbolP, 1);
2588 ARM_SET_INTERWORK (symbolP, support_interwork);
2589 break;
2590
2591 case MAP_DATA:
2592 default:
cd000bff
DJ
2593 break;
2594 }
2595
2596 /* Save the mapping symbols for future reference. Also check that
2597 we do not place two mapping symbols at the same offset within a
2598 frag. We'll handle overlap between frags in
2de7820f
JZ
2599 check_mapping_symbols.
2600
2601 If .fill or other data filling directive generates zero sized data,
2602 the mapping symbol for the following code will have the same value
2603 as the one generated for the data filling directive. In this case,
2604 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2605 if (value == 0)
2606 {
2de7820f
JZ
2607 if (frag->tc_frag_data.first_map != NULL)
2608 {
2609 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2610 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2611 }
cd000bff
DJ
2612 frag->tc_frag_data.first_map = symbolP;
2613 }
2614 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2615 {
2616 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2617 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2618 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2619 }
cd000bff
DJ
2620 frag->tc_frag_data.last_map = symbolP;
2621}
2622
2623/* We must sometimes convert a region marked as code to data during
2624 code alignment, if an odd number of bytes have to be padded. The
2625 code mapping symbol is pushed to an aligned address. */
2626
2627static void
2628insert_data_mapping_symbol (enum mstate state,
2629 valueT value, fragS *frag, offsetT bytes)
2630{
2631 /* If there was already a mapping symbol, remove it. */
2632 if (frag->tc_frag_data.last_map != NULL
2633 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2634 {
2635 symbolS *symp = frag->tc_frag_data.last_map;
2636
2637 if (value == 0)
2638 {
2639 know (frag->tc_frag_data.first_map == symp);
2640 frag->tc_frag_data.first_map = NULL;
2641 }
2642 frag->tc_frag_data.last_map = NULL;
2643 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2644 }
cd000bff
DJ
2645
2646 make_mapping_symbol (MAP_DATA, value, frag);
2647 make_mapping_symbol (state, value + bytes, frag);
2648}
2649
2650static void mapping_state_2 (enum mstate state, int max_chars);
2651
2652/* Set the mapping state to STATE. Only call this when about to
2653 emit some STATE bytes to the file. */
2654
4e9aaefb 2655#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2656void
2657mapping_state (enum mstate state)
2658{
940b5ce0
DJ
2659 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2660
cd000bff
DJ
2661 if (mapstate == state)
2662 /* The mapping symbol has already been emitted.
2663 There is nothing else to do. */
2664 return;
49c62a33
NC
2665
2666 if (state == MAP_ARM || state == MAP_THUMB)
2667 /* PR gas/12931
2668 All ARM instructions require 4-byte alignment.
2669 (Almost) all Thumb instructions require 2-byte alignment.
2670
2671 When emitting instructions into any section, mark the section
2672 appropriately.
2673
2674 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2675 but themselves require 2-byte alignment; this applies to some
2676 PC- relative forms. However, these cases will invovle implicit
2677 literal pool generation or an explicit .align >=2, both of
2678 which will cause the section to me marked with sufficient
2679 alignment. Thus, we don't handle those cases here. */
2680 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2681
2682 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2683 /* This case will be evaluated later. */
cd000bff 2684 return;
cd000bff
DJ
2685
2686 mapping_state_2 (state, 0);
cd000bff
DJ
2687}
2688
2689/* Same as mapping_state, but MAX_CHARS bytes have already been
2690 allocated. Put the mapping symbol that far back. */
2691
2692static void
2693mapping_state_2 (enum mstate state, int max_chars)
2694{
940b5ce0
DJ
2695 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2696
2697 if (!SEG_NORMAL (now_seg))
2698 return;
2699
cd000bff
DJ
2700 if (mapstate == state)
2701 /* The mapping symbol has already been emitted.
2702 There is nothing else to do. */
2703 return;
2704
4e9aaefb
SA
2705 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2706 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2707 {
2708 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2709 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2710
2711 if (add_symbol)
2712 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2713 }
2714
cd000bff
DJ
2715 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2716 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2717}
4e9aaefb 2718#undef TRANSITION
c19d1205 2719#else
d3106081
NS
2720#define mapping_state(x) ((void)0)
2721#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2722#endif
2723
2724/* Find the real, Thumb encoded start of a Thumb function. */
2725
4343666d 2726#ifdef OBJ_COFF
c19d1205
ZW
2727static symbolS *
2728find_real_start (symbolS * symbolP)
2729{
2730 char * real_start;
2731 const char * name = S_GET_NAME (symbolP);
2732 symbolS * new_target;
2733
2734 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2735#define STUB_NAME ".real_start_of"
2736
2737 if (name == NULL)
2738 abort ();
2739
37f6032b
ZW
2740 /* The compiler may generate BL instructions to local labels because
2741 it needs to perform a branch to a far away location. These labels
2742 do not have a corresponding ".real_start_of" label. We check
2743 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2744 the ".real_start_of" convention for nonlocal branches. */
2745 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2746 return symbolP;
2747
37f6032b 2748 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2749 new_target = symbol_find (real_start);
2750
2751 if (new_target == NULL)
2752 {
bd3ba5d1 2753 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2754 new_target = symbolP;
2755 }
2756
c19d1205
ZW
2757 return new_target;
2758}
4343666d 2759#endif
c19d1205
ZW
2760
2761static void
2762opcode_select (int width)
2763{
2764 switch (width)
2765 {
2766 case 16:
2767 if (! thumb_mode)
2768 {
e74cfd16 2769 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2770 as_bad (_("selected processor does not support THUMB opcodes"));
2771
2772 thumb_mode = 1;
2773 /* No need to force the alignment, since we will have been
2774 coming from ARM mode, which is word-aligned. */
2775 record_alignment (now_seg, 1);
2776 }
c19d1205
ZW
2777 break;
2778
2779 case 32:
2780 if (thumb_mode)
2781 {
e74cfd16 2782 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2783 as_bad (_("selected processor does not support ARM opcodes"));
2784
2785 thumb_mode = 0;
2786
2787 if (!need_pass_2)
2788 frag_align (2, 0, 0);
2789
2790 record_alignment (now_seg, 1);
2791 }
c19d1205
ZW
2792 break;
2793
2794 default:
2795 as_bad (_("invalid instruction size selected (%d)"), width);
2796 }
2797}
2798
2799static void
2800s_arm (int ignore ATTRIBUTE_UNUSED)
2801{
2802 opcode_select (32);
2803 demand_empty_rest_of_line ();
2804}
2805
2806static void
2807s_thumb (int ignore ATTRIBUTE_UNUSED)
2808{
2809 opcode_select (16);
2810 demand_empty_rest_of_line ();
2811}
2812
2813static void
2814s_code (int unused ATTRIBUTE_UNUSED)
2815{
2816 int temp;
2817
2818 temp = get_absolute_expression ();
2819 switch (temp)
2820 {
2821 case 16:
2822 case 32:
2823 opcode_select (temp);
2824 break;
2825
2826 default:
2827 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2828 }
2829}
2830
2831static void
2832s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2833{
2834 /* If we are not already in thumb mode go into it, EVEN if
2835 the target processor does not support thumb instructions.
2836 This is used by gcc/config/arm/lib1funcs.asm for example
2837 to compile interworking support functions even if the
2838 target processor should not support interworking. */
2839 if (! thumb_mode)
2840 {
2841 thumb_mode = 2;
2842 record_alignment (now_seg, 1);
2843 }
2844
2845 demand_empty_rest_of_line ();
2846}
2847
2848static void
2849s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2850{
2851 s_thumb (0);
2852
2853 /* The following label is the name/address of the start of a Thumb function.
2854 We need to know this for the interworking support. */
2855 label_is_thumb_function_name = TRUE;
2856}
2857
2858/* Perform a .set directive, but also mark the alias as
2859 being a thumb function. */
2860
2861static void
2862s_thumb_set (int equiv)
2863{
2864 /* XXX the following is a duplicate of the code for s_set() in read.c
2865 We cannot just call that code as we need to get at the symbol that
2866 is created. */
2867 char * name;
2868 char delim;
2869 char * end_name;
2870 symbolS * symbolP;
2871
2872 /* Especial apologies for the random logic:
2873 This just grew, and could be parsed much more simply!
2874 Dean - in haste. */
d02603dc 2875 delim = get_symbol_name (& name);
c19d1205 2876 end_name = input_line_pointer;
d02603dc 2877 (void) restore_line_pointer (delim);
c19d1205
ZW
2878
2879 if (*input_line_pointer != ',')
2880 {
2881 *end_name = 0;
2882 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2883 *end_name = delim;
2884 ignore_rest_of_line ();
2885 return;
2886 }
2887
2888 input_line_pointer++;
2889 *end_name = 0;
2890
2891 if (name[0] == '.' && name[1] == '\0')
2892 {
2893 /* XXX - this should not happen to .thumb_set. */
2894 abort ();
2895 }
2896
2897 if ((symbolP = symbol_find (name)) == NULL
2898 && (symbolP = md_undefined_symbol (name)) == NULL)
2899 {
2900#ifndef NO_LISTING
2901 /* When doing symbol listings, play games with dummy fragments living
2902 outside the normal fragment chain to record the file and line info
c19d1205 2903 for this symbol. */
b99bd4ef
NC
2904 if (listing & LISTING_SYMBOLS)
2905 {
2906 extern struct list_info_struct * listing_tail;
21d799b5 2907 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2908
2909 memset (dummy_frag, 0, sizeof (fragS));
2910 dummy_frag->fr_type = rs_fill;
2911 dummy_frag->line = listing_tail;
2912 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2913 dummy_frag->fr_symbol = symbolP;
2914 }
2915 else
2916#endif
2917 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2918
2919#ifdef OBJ_COFF
2920 /* "set" symbols are local unless otherwise specified. */
2921 SF_SET_LOCAL (symbolP);
2922#endif /* OBJ_COFF */
2923 } /* Make a new symbol. */
2924
2925 symbol_table_insert (symbolP);
2926
2927 * end_name = delim;
2928
2929 if (equiv
2930 && S_IS_DEFINED (symbolP)
2931 && S_GET_SEGMENT (symbolP) != reg_section)
2932 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2933
2934 pseudo_set (symbolP);
2935
2936 demand_empty_rest_of_line ();
2937
c19d1205 2938 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2939
2940 THUMB_SET_FUNC (symbolP, 1);
2941 ARM_SET_THUMB (symbolP, 1);
2942#if defined OBJ_ELF || defined OBJ_COFF
2943 ARM_SET_INTERWORK (symbolP, support_interwork);
2944#endif
2945}
2946
c19d1205 2947/* Directives: Mode selection. */
b99bd4ef 2948
c19d1205
ZW
2949/* .syntax [unified|divided] - choose the new unified syntax
2950 (same for Arm and Thumb encoding, modulo slight differences in what
2951 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2952static void
c19d1205 2953s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2954{
c19d1205
ZW
2955 char *name, delim;
2956
d02603dc 2957 delim = get_symbol_name (& name);
c19d1205
ZW
2958
2959 if (!strcasecmp (name, "unified"))
2960 unified_syntax = TRUE;
2961 else if (!strcasecmp (name, "divided"))
2962 unified_syntax = FALSE;
2963 else
2964 {
2965 as_bad (_("unrecognized syntax mode \"%s\""), name);
2966 return;
2967 }
d02603dc 2968 (void) restore_line_pointer (delim);
b99bd4ef
NC
2969 demand_empty_rest_of_line ();
2970}
2971
c19d1205
ZW
2972/* Directives: sectioning and alignment. */
2973
c19d1205
ZW
2974static void
2975s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2976{
c19d1205
ZW
2977 /* We don't support putting frags in the BSS segment, we fake it by
2978 marking in_bss, then looking at s_skip for clues. */
2979 subseg_set (bss_section, 0);
2980 demand_empty_rest_of_line ();
cd000bff
DJ
2981
2982#ifdef md_elf_section_change_hook
2983 md_elf_section_change_hook ();
2984#endif
c19d1205 2985}
b99bd4ef 2986
c19d1205
ZW
2987static void
2988s_even (int ignore ATTRIBUTE_UNUSED)
2989{
2990 /* Never make frag if expect extra pass. */
2991 if (!need_pass_2)
2992 frag_align (1, 0, 0);
b99bd4ef 2993
c19d1205 2994 record_alignment (now_seg, 1);
b99bd4ef 2995
c19d1205 2996 demand_empty_rest_of_line ();
b99bd4ef
NC
2997}
2998
2e6976a8
DG
2999/* Directives: CodeComposer Studio. */
3000
3001/* .ref (for CodeComposer Studio syntax only). */
3002static void
3003s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3004{
3005 if (codecomposer_syntax)
3006 ignore_rest_of_line ();
3007 else
3008 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3009}
3010
3011/* If name is not NULL, then it is used for marking the beginning of a
3012 function, wherease if it is NULL then it means the function end. */
3013static void
3014asmfunc_debug (const char * name)
3015{
3016 static const char * last_name = NULL;
3017
3018 if (name != NULL)
3019 {
3020 gas_assert (last_name == NULL);
3021 last_name = name;
3022
3023 if (debug_type == DEBUG_STABS)
3024 stabs_generate_asm_func (name, name);
3025 }
3026 else
3027 {
3028 gas_assert (last_name != NULL);
3029
3030 if (debug_type == DEBUG_STABS)
3031 stabs_generate_asm_endfunc (last_name, last_name);
3032
3033 last_name = NULL;
3034 }
3035}
3036
3037static void
3038s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3039{
3040 if (codecomposer_syntax)
3041 {
3042 switch (asmfunc_state)
3043 {
3044 case OUTSIDE_ASMFUNC:
3045 asmfunc_state = WAITING_ASMFUNC_NAME;
3046 break;
3047
3048 case WAITING_ASMFUNC_NAME:
3049 as_bad (_(".asmfunc repeated."));
3050 break;
3051
3052 case WAITING_ENDASMFUNC:
3053 as_bad (_(".asmfunc without function."));
3054 break;
3055 }
3056 demand_empty_rest_of_line ();
3057 }
3058 else
3059 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3060}
3061
3062static void
3063s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3064{
3065 if (codecomposer_syntax)
3066 {
3067 switch (asmfunc_state)
3068 {
3069 case OUTSIDE_ASMFUNC:
3070 as_bad (_(".endasmfunc without a .asmfunc."));
3071 break;
3072
3073 case WAITING_ASMFUNC_NAME:
3074 as_bad (_(".endasmfunc without function."));
3075 break;
3076
3077 case WAITING_ENDASMFUNC:
3078 asmfunc_state = OUTSIDE_ASMFUNC;
3079 asmfunc_debug (NULL);
3080 break;
3081 }
3082 demand_empty_rest_of_line ();
3083 }
3084 else
3085 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3086}
3087
3088static void
3089s_ccs_def (int name)
3090{
3091 if (codecomposer_syntax)
3092 s_globl (name);
3093 else
3094 as_bad (_(".def pseudo-op only available with -mccs flag."));
3095}
3096
c19d1205 3097/* Directives: Literal pools. */
a737bd4d 3098
c19d1205
ZW
3099static literal_pool *
3100find_literal_pool (void)
a737bd4d 3101{
c19d1205 3102 literal_pool * pool;
a737bd4d 3103
c19d1205 3104 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3105 {
c19d1205
ZW
3106 if (pool->section == now_seg
3107 && pool->sub_section == now_subseg)
3108 break;
a737bd4d
NC
3109 }
3110
c19d1205 3111 return pool;
a737bd4d
NC
3112}
3113
c19d1205
ZW
3114static literal_pool *
3115find_or_make_literal_pool (void)
a737bd4d 3116{
c19d1205
ZW
3117 /* Next literal pool ID number. */
3118 static unsigned int latest_pool_num = 1;
3119 literal_pool * pool;
a737bd4d 3120
c19d1205 3121 pool = find_literal_pool ();
a737bd4d 3122
c19d1205 3123 if (pool == NULL)
a737bd4d 3124 {
c19d1205 3125 /* Create a new pool. */
21d799b5 3126 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
3127 if (! pool)
3128 return NULL;
a737bd4d 3129
c19d1205
ZW
3130 pool->next_free_entry = 0;
3131 pool->section = now_seg;
3132 pool->sub_section = now_subseg;
3133 pool->next = list_of_pools;
3134 pool->symbol = NULL;
8335d6aa 3135 pool->alignment = 2;
c19d1205
ZW
3136
3137 /* Add it to the list. */
3138 list_of_pools = pool;
a737bd4d 3139 }
a737bd4d 3140
c19d1205
ZW
3141 /* New pools, and emptied pools, will have a NULL symbol. */
3142 if (pool->symbol == NULL)
a737bd4d 3143 {
c19d1205
ZW
3144 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3145 (valueT) 0, &zero_address_frag);
3146 pool->id = latest_pool_num ++;
a737bd4d
NC
3147 }
3148
c19d1205
ZW
3149 /* Done. */
3150 return pool;
a737bd4d
NC
3151}
3152
c19d1205 3153/* Add the literal in the global 'inst'
5f4273c7 3154 structure to the relevant literal pool. */
b99bd4ef
NC
3155
3156static int
8335d6aa 3157add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3158{
8335d6aa
JW
3159#define PADDING_SLOT 0x1
3160#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3161 literal_pool * pool;
8335d6aa
JW
3162 unsigned int entry, pool_size = 0;
3163 bfd_boolean padding_slot_p = FALSE;
e56c722b 3164 unsigned imm1 = 0;
8335d6aa
JW
3165 unsigned imm2 = 0;
3166
3167 if (nbytes == 8)
3168 {
3169 imm1 = inst.operands[1].imm;
3170 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3171 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3172 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3173 if (target_big_endian)
3174 {
3175 imm1 = imm2;
3176 imm2 = inst.operands[1].imm;
3177 }
3178 }
b99bd4ef 3179
c19d1205
ZW
3180 pool = find_or_make_literal_pool ();
3181
3182 /* Check if this literal value is already in the pool. */
3183 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3184 {
8335d6aa
JW
3185 if (nbytes == 4)
3186 {
3187 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3188 && (inst.reloc.exp.X_op == O_constant)
3189 && (pool->literals[entry].X_add_number
3190 == inst.reloc.exp.X_add_number)
3191 && (pool->literals[entry].X_md == nbytes)
3192 && (pool->literals[entry].X_unsigned
3193 == inst.reloc.exp.X_unsigned))
3194 break;
3195
3196 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3197 && (inst.reloc.exp.X_op == O_symbol)
3198 && (pool->literals[entry].X_add_number
3199 == inst.reloc.exp.X_add_number)
3200 && (pool->literals[entry].X_add_symbol
3201 == inst.reloc.exp.X_add_symbol)
3202 && (pool->literals[entry].X_op_symbol
3203 == inst.reloc.exp.X_op_symbol)
3204 && (pool->literals[entry].X_md == nbytes))
3205 break;
3206 }
3207 else if ((nbytes == 8)
3208 && !(pool_size & 0x7)
3209 && ((entry + 1) != pool->next_free_entry)
3210 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3211 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3212 && (pool->literals[entry].X_unsigned
3213 == inst.reloc.exp.X_unsigned)
3214 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3215 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3216 && (pool->literals[entry + 1].X_unsigned
3217 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3218 break;
3219
8335d6aa
JW
3220 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3221 if (padding_slot_p && (nbytes == 4))
c19d1205 3222 break;
8335d6aa
JW
3223
3224 pool_size += 4;
b99bd4ef
NC
3225 }
3226
c19d1205
ZW
3227 /* Do we need to create a new entry? */
3228 if (entry == pool->next_free_entry)
3229 {
3230 if (entry >= MAX_LITERAL_POOL_SIZE)
3231 {
3232 inst.error = _("literal pool overflow");
3233 return FAIL;
3234 }
3235
8335d6aa
JW
3236 if (nbytes == 8)
3237 {
3238 /* For 8-byte entries, we align to an 8-byte boundary,
3239 and split it into two 4-byte entries, because on 32-bit
3240 host, 8-byte constants are treated as big num, thus
3241 saved in "generic_bignum" which will be overwritten
3242 by later assignments.
3243
3244 We also need to make sure there is enough space for
3245 the split.
3246
3247 We also check to make sure the literal operand is a
3248 constant number. */
19f2f6a9
JW
3249 if (!(inst.reloc.exp.X_op == O_constant
3250 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3251 {
3252 inst.error = _("invalid type for literal pool");
3253 return FAIL;
3254 }
3255 else if (pool_size & 0x7)
3256 {
3257 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3258 {
3259 inst.error = _("literal pool overflow");
3260 return FAIL;
3261 }
3262
3263 pool->literals[entry] = inst.reloc.exp;
3264 pool->literals[entry].X_add_number = 0;
3265 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3266 pool->next_free_entry += 1;
3267 pool_size += 4;
3268 }
3269 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3270 {
3271 inst.error = _("literal pool overflow");
3272 return FAIL;
3273 }
3274
3275 pool->literals[entry] = inst.reloc.exp;
3276 pool->literals[entry].X_op = O_constant;
3277 pool->literals[entry].X_add_number = imm1;
3278 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3279 pool->literals[entry++].X_md = 4;
3280 pool->literals[entry] = inst.reloc.exp;
3281 pool->literals[entry].X_op = O_constant;
3282 pool->literals[entry].X_add_number = imm2;
3283 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3284 pool->literals[entry].X_md = 4;
3285 pool->alignment = 3;
3286 pool->next_free_entry += 1;
3287 }
3288 else
3289 {
3290 pool->literals[entry] = inst.reloc.exp;
3291 pool->literals[entry].X_md = 4;
3292 }
3293
a8040cf2
NC
3294#ifdef OBJ_ELF
3295 /* PR ld/12974: Record the location of the first source line to reference
3296 this entry in the literal pool. If it turns out during linking that the
3297 symbol does not exist we will be able to give an accurate line number for
3298 the (first use of the) missing reference. */
3299 if (debug_type == DEBUG_DWARF2)
3300 dwarf2_where (pool->locs + entry);
3301#endif
c19d1205
ZW
3302 pool->next_free_entry += 1;
3303 }
8335d6aa
JW
3304 else if (padding_slot_p)
3305 {
3306 pool->literals[entry] = inst.reloc.exp;
3307 pool->literals[entry].X_md = nbytes;
3308 }
b99bd4ef 3309
c19d1205 3310 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3311 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3312 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3313
c19d1205 3314 return SUCCESS;
b99bd4ef
NC
3315}
3316
2e6976a8 3317bfd_boolean
2e57ce7b 3318tc_start_label_without_colon (void)
2e6976a8
DG
3319{
3320 bfd_boolean ret = TRUE;
3321
3322 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3323 {
2e57ce7b 3324 const char *label = input_line_pointer;
2e6976a8
DG
3325
3326 while (!is_end_of_line[(int) label[-1]])
3327 --label;
3328
3329 if (*label == '.')
3330 {
3331 as_bad (_("Invalid label '%s'"), label);
3332 ret = FALSE;
3333 }
3334
3335 asmfunc_debug (label);
3336
3337 asmfunc_state = WAITING_ENDASMFUNC;
3338 }
3339
3340 return ret;
3341}
3342
c19d1205
ZW
3343/* Can't use symbol_new here, so have to create a symbol and then at
3344 a later date assign it a value. Thats what these functions do. */
e16bb312 3345
c19d1205
ZW
3346static void
3347symbol_locate (symbolS * symbolP,
3348 const char * name, /* It is copied, the caller can modify. */
3349 segT segment, /* Segment identifier (SEG_<something>). */
3350 valueT valu, /* Symbol value. */
3351 fragS * frag) /* Associated fragment. */
3352{
e57e6ddc 3353 size_t name_length;
c19d1205 3354 char * preserved_copy_of_name;
e16bb312 3355
c19d1205
ZW
3356 name_length = strlen (name) + 1; /* +1 for \0. */
3357 obstack_grow (&notes, name, name_length);
21d799b5 3358 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3359
c19d1205
ZW
3360#ifdef tc_canonicalize_symbol_name
3361 preserved_copy_of_name =
3362 tc_canonicalize_symbol_name (preserved_copy_of_name);
3363#endif
b99bd4ef 3364
c19d1205 3365 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3366
c19d1205
ZW
3367 S_SET_SEGMENT (symbolP, segment);
3368 S_SET_VALUE (symbolP, valu);
3369 symbol_clear_list_pointers (symbolP);
b99bd4ef 3370
c19d1205 3371 symbol_set_frag (symbolP, frag);
b99bd4ef 3372
c19d1205
ZW
3373 /* Link to end of symbol chain. */
3374 {
3375 extern int symbol_table_frozen;
b99bd4ef 3376
c19d1205
ZW
3377 if (symbol_table_frozen)
3378 abort ();
3379 }
b99bd4ef 3380
c19d1205 3381 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3382
c19d1205 3383 obj_symbol_new_hook (symbolP);
b99bd4ef 3384
c19d1205
ZW
3385#ifdef tc_symbol_new_hook
3386 tc_symbol_new_hook (symbolP);
3387#endif
3388
3389#ifdef DEBUG_SYMS
3390 verify_symbol_chain (symbol_rootP, symbol_lastP);
3391#endif /* DEBUG_SYMS */
b99bd4ef
NC
3392}
3393
c19d1205
ZW
3394static void
3395s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3396{
c19d1205
ZW
3397 unsigned int entry;
3398 literal_pool * pool;
3399 char sym_name[20];
b99bd4ef 3400
c19d1205
ZW
3401 pool = find_literal_pool ();
3402 if (pool == NULL
3403 || pool->symbol == NULL
3404 || pool->next_free_entry == 0)
3405 return;
b99bd4ef 3406
c19d1205
ZW
3407 /* Align pool as you have word accesses.
3408 Only make a frag if we have to. */
3409 if (!need_pass_2)
8335d6aa 3410 frag_align (pool->alignment, 0, 0);
b99bd4ef 3411
c19d1205 3412 record_alignment (now_seg, 2);
b99bd4ef 3413
aaca88ef 3414#ifdef OBJ_ELF
47fc6e36
WN
3415 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3416 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3417#endif
c19d1205 3418 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3419
c19d1205
ZW
3420 symbol_locate (pool->symbol, sym_name, now_seg,
3421 (valueT) frag_now_fix (), frag_now);
3422 symbol_table_insert (pool->symbol);
b99bd4ef 3423
c19d1205 3424 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3425
c19d1205
ZW
3426#if defined OBJ_COFF || defined OBJ_ELF
3427 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3428#endif
6c43fab6 3429
c19d1205 3430 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3431 {
3432#ifdef OBJ_ELF
3433 if (debug_type == DEBUG_DWARF2)
3434 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3435#endif
3436 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3437 emit_expr (&(pool->literals[entry]),
3438 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3439 }
b99bd4ef 3440
c19d1205
ZW
3441 /* Mark the pool as empty. */
3442 pool->next_free_entry = 0;
3443 pool->symbol = NULL;
b99bd4ef
NC
3444}
3445
c19d1205
ZW
3446#ifdef OBJ_ELF
3447/* Forward declarations for functions below, in the MD interface
3448 section. */
3449static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3450static valueT create_unwind_entry (int);
3451static void start_unwind_section (const segT, int);
3452static void add_unwind_opcode (valueT, int);
3453static void flush_pending_unwind (void);
b99bd4ef 3454
c19d1205 3455/* Directives: Data. */
b99bd4ef 3456
c19d1205
ZW
3457static void
3458s_arm_elf_cons (int nbytes)
3459{
3460 expressionS exp;
b99bd4ef 3461
c19d1205
ZW
3462#ifdef md_flush_pending_output
3463 md_flush_pending_output ();
3464#endif
b99bd4ef 3465
c19d1205 3466 if (is_it_end_of_statement ())
b99bd4ef 3467 {
c19d1205
ZW
3468 demand_empty_rest_of_line ();
3469 return;
b99bd4ef
NC
3470 }
3471
c19d1205
ZW
3472#ifdef md_cons_align
3473 md_cons_align (nbytes);
3474#endif
b99bd4ef 3475
c19d1205
ZW
3476 mapping_state (MAP_DATA);
3477 do
b99bd4ef 3478 {
c19d1205
ZW
3479 int reloc;
3480 char *base = input_line_pointer;
b99bd4ef 3481
c19d1205 3482 expression (& exp);
b99bd4ef 3483
c19d1205
ZW
3484 if (exp.X_op != O_symbol)
3485 emit_expr (&exp, (unsigned int) nbytes);
3486 else
3487 {
3488 char *before_reloc = input_line_pointer;
3489 reloc = parse_reloc (&input_line_pointer);
3490 if (reloc == -1)
3491 {
3492 as_bad (_("unrecognized relocation suffix"));
3493 ignore_rest_of_line ();
3494 return;
3495 }
3496 else if (reloc == BFD_RELOC_UNUSED)
3497 emit_expr (&exp, (unsigned int) nbytes);
3498 else
3499 {
21d799b5 3500 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3501 bfd_reloc_type_lookup (stdoutput,
3502 (bfd_reloc_code_real_type) reloc);
c19d1205 3503 int size = bfd_get_reloc_size (howto);
b99bd4ef 3504
2fc8bdac
ZW
3505 if (reloc == BFD_RELOC_ARM_PLT32)
3506 {
3507 as_bad (_("(plt) is only valid on branch targets"));
3508 reloc = BFD_RELOC_UNUSED;
3509 size = 0;
3510 }
3511
c19d1205 3512 if (size > nbytes)
2fc8bdac 3513 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3514 howto->name, nbytes);
3515 else
3516 {
3517 /* We've parsed an expression stopping at O_symbol.
3518 But there may be more expression left now that we
3519 have parsed the relocation marker. Parse it again.
3520 XXX Surely there is a cleaner way to do this. */
3521 char *p = input_line_pointer;
3522 int offset;
21d799b5 3523 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3524 memcpy (save_buf, base, input_line_pointer - base);
3525 memmove (base + (input_line_pointer - before_reloc),
3526 base, before_reloc - base);
3527
3528 input_line_pointer = base + (input_line_pointer-before_reloc);
3529 expression (&exp);
3530 memcpy (base, save_buf, p - base);
3531
3532 offset = nbytes - size;
4b1a927e
AM
3533 p = frag_more (nbytes);
3534 memset (p, 0, nbytes);
c19d1205 3535 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3536 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3537 }
3538 }
3539 }
b99bd4ef 3540 }
c19d1205 3541 while (*input_line_pointer++ == ',');
b99bd4ef 3542
c19d1205
ZW
3543 /* Put terminator back into stream. */
3544 input_line_pointer --;
3545 demand_empty_rest_of_line ();
b99bd4ef
NC
3546}
3547
c921be7d
NC
3548/* Emit an expression containing a 32-bit thumb instruction.
3549 Implementation based on put_thumb32_insn. */
3550
3551static void
3552emit_thumb32_expr (expressionS * exp)
3553{
3554 expressionS exp_high = *exp;
3555
3556 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3557 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3558 exp->X_add_number &= 0xffff;
3559 emit_expr (exp, (unsigned int) THUMB_SIZE);
3560}
3561
3562/* Guess the instruction size based on the opcode. */
3563
3564static int
3565thumb_insn_size (int opcode)
3566{
3567 if ((unsigned int) opcode < 0xe800u)
3568 return 2;
3569 else if ((unsigned int) opcode >= 0xe8000000u)
3570 return 4;
3571 else
3572 return 0;
3573}
3574
3575static bfd_boolean
3576emit_insn (expressionS *exp, int nbytes)
3577{
3578 int size = 0;
3579
3580 if (exp->X_op == O_constant)
3581 {
3582 size = nbytes;
3583
3584 if (size == 0)
3585 size = thumb_insn_size (exp->X_add_number);
3586
3587 if (size != 0)
3588 {
3589 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3590 {
3591 as_bad (_(".inst.n operand too big. "\
3592 "Use .inst.w instead"));
3593 size = 0;
3594 }
3595 else
3596 {
3597 if (now_it.state == AUTOMATIC_IT_BLOCK)
3598 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3599 else
3600 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3601
3602 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3603 emit_thumb32_expr (exp);
3604 else
3605 emit_expr (exp, (unsigned int) size);
3606
3607 it_fsm_post_encode ();
3608 }
3609 }
3610 else
3611 as_bad (_("cannot determine Thumb instruction size. " \
3612 "Use .inst.n/.inst.w instead"));
3613 }
3614 else
3615 as_bad (_("constant expression required"));
3616
3617 return (size != 0);
3618}
3619
3620/* Like s_arm_elf_cons but do not use md_cons_align and
3621 set the mapping state to MAP_ARM/MAP_THUMB. */
3622
3623static void
3624s_arm_elf_inst (int nbytes)
3625{
3626 if (is_it_end_of_statement ())
3627 {
3628 demand_empty_rest_of_line ();
3629 return;
3630 }
3631
3632 /* Calling mapping_state () here will not change ARM/THUMB,
3633 but will ensure not to be in DATA state. */
3634
3635 if (thumb_mode)
3636 mapping_state (MAP_THUMB);
3637 else
3638 {
3639 if (nbytes != 0)
3640 {
3641 as_bad (_("width suffixes are invalid in ARM mode"));
3642 ignore_rest_of_line ();
3643 return;
3644 }
3645
3646 nbytes = 4;
3647
3648 mapping_state (MAP_ARM);
3649 }
3650
3651 do
3652 {
3653 expressionS exp;
3654
3655 expression (& exp);
3656
3657 if (! emit_insn (& exp, nbytes))
3658 {
3659 ignore_rest_of_line ();
3660 return;
3661 }
3662 }
3663 while (*input_line_pointer++ == ',');
3664
3665 /* Put terminator back into stream. */
3666 input_line_pointer --;
3667 demand_empty_rest_of_line ();
3668}
b99bd4ef 3669
c19d1205 3670/* Parse a .rel31 directive. */
b99bd4ef 3671
c19d1205
ZW
3672static void
3673s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3674{
3675 expressionS exp;
3676 char *p;
3677 valueT highbit;
b99bd4ef 3678
c19d1205
ZW
3679 highbit = 0;
3680 if (*input_line_pointer == '1')
3681 highbit = 0x80000000;
3682 else if (*input_line_pointer != '0')
3683 as_bad (_("expected 0 or 1"));
b99bd4ef 3684
c19d1205
ZW
3685 input_line_pointer++;
3686 if (*input_line_pointer != ',')
3687 as_bad (_("missing comma"));
3688 input_line_pointer++;
b99bd4ef 3689
c19d1205
ZW
3690#ifdef md_flush_pending_output
3691 md_flush_pending_output ();
3692#endif
b99bd4ef 3693
c19d1205
ZW
3694#ifdef md_cons_align
3695 md_cons_align (4);
3696#endif
b99bd4ef 3697
c19d1205 3698 mapping_state (MAP_DATA);
b99bd4ef 3699
c19d1205 3700 expression (&exp);
b99bd4ef 3701
c19d1205
ZW
3702 p = frag_more (4);
3703 md_number_to_chars (p, highbit, 4);
3704 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3705 BFD_RELOC_ARM_PREL31);
b99bd4ef 3706
c19d1205 3707 demand_empty_rest_of_line ();
b99bd4ef
NC
3708}
3709
c19d1205 3710/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3711
c19d1205 3712/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3713
c19d1205
ZW
3714static void
3715s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3716{
3717 demand_empty_rest_of_line ();
921e5f0a
PB
3718 if (unwind.proc_start)
3719 {
c921be7d 3720 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3721 return;
3722 }
3723
c19d1205
ZW
3724 /* Mark the start of the function. */
3725 unwind.proc_start = expr_build_dot ();
b99bd4ef 3726
c19d1205
ZW
3727 /* Reset the rest of the unwind info. */
3728 unwind.opcode_count = 0;
3729 unwind.table_entry = NULL;
3730 unwind.personality_routine = NULL;
3731 unwind.personality_index = -1;
3732 unwind.frame_size = 0;
3733 unwind.fp_offset = 0;
fdfde340 3734 unwind.fp_reg = REG_SP;
c19d1205
ZW
3735 unwind.fp_used = 0;
3736 unwind.sp_restored = 0;
3737}
b99bd4ef 3738
b99bd4ef 3739
c19d1205
ZW
3740/* Parse a handlerdata directive. Creates the exception handling table entry
3741 for the function. */
b99bd4ef 3742
c19d1205
ZW
3743static void
3744s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3745{
3746 demand_empty_rest_of_line ();
921e5f0a 3747 if (!unwind.proc_start)
c921be7d 3748 as_bad (MISSING_FNSTART);
921e5f0a 3749
c19d1205 3750 if (unwind.table_entry)
6decc662 3751 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3752
c19d1205
ZW
3753 create_unwind_entry (1);
3754}
a737bd4d 3755
c19d1205 3756/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3757
c19d1205
ZW
3758static void
3759s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3760{
3761 long where;
3762 char *ptr;
3763 valueT val;
940b5ce0 3764 unsigned int marked_pr_dependency;
f02232aa 3765
c19d1205 3766 demand_empty_rest_of_line ();
f02232aa 3767
921e5f0a
PB
3768 if (!unwind.proc_start)
3769 {
c921be7d 3770 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3771 return;
3772 }
3773
c19d1205
ZW
3774 /* Add eh table entry. */
3775 if (unwind.table_entry == NULL)
3776 val = create_unwind_entry (0);
3777 else
3778 val = 0;
f02232aa 3779
c19d1205
ZW
3780 /* Add index table entry. This is two words. */
3781 start_unwind_section (unwind.saved_seg, 1);
3782 frag_align (2, 0, 0);
3783 record_alignment (now_seg, 2);
b99bd4ef 3784
c19d1205 3785 ptr = frag_more (8);
5011093d 3786 memset (ptr, 0, 8);
c19d1205 3787 where = frag_now_fix () - 8;
f02232aa 3788
c19d1205
ZW
3789 /* Self relative offset of the function start. */
3790 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3791 BFD_RELOC_ARM_PREL31);
f02232aa 3792
c19d1205
ZW
3793 /* Indicate dependency on EHABI-defined personality routines to the
3794 linker, if it hasn't been done already. */
940b5ce0
DJ
3795 marked_pr_dependency
3796 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3797 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3798 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3799 {
5f4273c7
NC
3800 static const char *const name[] =
3801 {
3802 "__aeabi_unwind_cpp_pr0",
3803 "__aeabi_unwind_cpp_pr1",
3804 "__aeabi_unwind_cpp_pr2"
3805 };
c19d1205
ZW
3806 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3807 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3808 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3809 |= 1 << unwind.personality_index;
c19d1205 3810 }
f02232aa 3811
c19d1205
ZW
3812 if (val)
3813 /* Inline exception table entry. */
3814 md_number_to_chars (ptr + 4, val, 4);
3815 else
3816 /* Self relative offset of the table entry. */
3817 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3818 BFD_RELOC_ARM_PREL31);
f02232aa 3819
c19d1205
ZW
3820 /* Restore the original section. */
3821 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3822
3823 unwind.proc_start = NULL;
c19d1205 3824}
f02232aa 3825
f02232aa 3826
c19d1205 3827/* Parse an unwind_cantunwind directive. */
b99bd4ef 3828
c19d1205
ZW
3829static void
3830s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3831{
3832 demand_empty_rest_of_line ();
921e5f0a 3833 if (!unwind.proc_start)
c921be7d 3834 as_bad (MISSING_FNSTART);
921e5f0a 3835
c19d1205
ZW
3836 if (unwind.personality_routine || unwind.personality_index != -1)
3837 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3838
c19d1205
ZW
3839 unwind.personality_index = -2;
3840}
b99bd4ef 3841
b99bd4ef 3842
c19d1205 3843/* Parse a personalityindex directive. */
b99bd4ef 3844
c19d1205
ZW
3845static void
3846s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3847{
3848 expressionS exp;
b99bd4ef 3849
921e5f0a 3850 if (!unwind.proc_start)
c921be7d 3851 as_bad (MISSING_FNSTART);
921e5f0a 3852
c19d1205
ZW
3853 if (unwind.personality_routine || unwind.personality_index != -1)
3854 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3855
c19d1205 3856 expression (&exp);
b99bd4ef 3857
c19d1205
ZW
3858 if (exp.X_op != O_constant
3859 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3860 {
c19d1205
ZW
3861 as_bad (_("bad personality routine number"));
3862 ignore_rest_of_line ();
3863 return;
b99bd4ef
NC
3864 }
3865
c19d1205 3866 unwind.personality_index = exp.X_add_number;
b99bd4ef 3867
c19d1205
ZW
3868 demand_empty_rest_of_line ();
3869}
e16bb312 3870
e16bb312 3871
c19d1205 3872/* Parse a personality directive. */
e16bb312 3873
c19d1205
ZW
3874static void
3875s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3876{
3877 char *name, *p, c;
a737bd4d 3878
921e5f0a 3879 if (!unwind.proc_start)
c921be7d 3880 as_bad (MISSING_FNSTART);
921e5f0a 3881
c19d1205
ZW
3882 if (unwind.personality_routine || unwind.personality_index != -1)
3883 as_bad (_("duplicate .personality directive"));
a737bd4d 3884
d02603dc 3885 c = get_symbol_name (& name);
c19d1205 3886 p = input_line_pointer;
d02603dc
NC
3887 if (c == '"')
3888 ++ input_line_pointer;
c19d1205
ZW
3889 unwind.personality_routine = symbol_find_or_make (name);
3890 *p = c;
3891 demand_empty_rest_of_line ();
3892}
e16bb312 3893
e16bb312 3894
c19d1205 3895/* Parse a directive saving core registers. */
e16bb312 3896
c19d1205
ZW
3897static void
3898s_arm_unwind_save_core (void)
e16bb312 3899{
c19d1205
ZW
3900 valueT op;
3901 long range;
3902 int n;
e16bb312 3903
c19d1205
ZW
3904 range = parse_reg_list (&input_line_pointer);
3905 if (range == FAIL)
e16bb312 3906 {
c19d1205
ZW
3907 as_bad (_("expected register list"));
3908 ignore_rest_of_line ();
3909 return;
3910 }
e16bb312 3911
c19d1205 3912 demand_empty_rest_of_line ();
e16bb312 3913
c19d1205
ZW
3914 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3915 into .unwind_save {..., sp...}. We aren't bothered about the value of
3916 ip because it is clobbered by calls. */
3917 if (unwind.sp_restored && unwind.fp_reg == 12
3918 && (range & 0x3000) == 0x1000)
3919 {
3920 unwind.opcode_count--;
3921 unwind.sp_restored = 0;
3922 range = (range | 0x2000) & ~0x1000;
3923 unwind.pending_offset = 0;
3924 }
e16bb312 3925
01ae4198
DJ
3926 /* Pop r4-r15. */
3927 if (range & 0xfff0)
c19d1205 3928 {
01ae4198
DJ
3929 /* See if we can use the short opcodes. These pop a block of up to 8
3930 registers starting with r4, plus maybe r14. */
3931 for (n = 0; n < 8; n++)
3932 {
3933 /* Break at the first non-saved register. */
3934 if ((range & (1 << (n + 4))) == 0)
3935 break;
3936 }
3937 /* See if there are any other bits set. */
3938 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3939 {
3940 /* Use the long form. */
3941 op = 0x8000 | ((range >> 4) & 0xfff);
3942 add_unwind_opcode (op, 2);
3943 }
0dd132b6 3944 else
01ae4198
DJ
3945 {
3946 /* Use the short form. */
3947 if (range & 0x4000)
3948 op = 0xa8; /* Pop r14. */
3949 else
3950 op = 0xa0; /* Do not pop r14. */
3951 op |= (n - 1);
3952 add_unwind_opcode (op, 1);
3953 }
c19d1205 3954 }
0dd132b6 3955
c19d1205
ZW
3956 /* Pop r0-r3. */
3957 if (range & 0xf)
3958 {
3959 op = 0xb100 | (range & 0xf);
3960 add_unwind_opcode (op, 2);
0dd132b6
NC
3961 }
3962
c19d1205
ZW
3963 /* Record the number of bytes pushed. */
3964 for (n = 0; n < 16; n++)
3965 {
3966 if (range & (1 << n))
3967 unwind.frame_size += 4;
3968 }
0dd132b6
NC
3969}
3970
c19d1205
ZW
3971
3972/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3973
3974static void
c19d1205 3975s_arm_unwind_save_fpa (int reg)
b99bd4ef 3976{
c19d1205
ZW
3977 expressionS exp;
3978 int num_regs;
3979 valueT op;
b99bd4ef 3980
c19d1205
ZW
3981 /* Get Number of registers to transfer. */
3982 if (skip_past_comma (&input_line_pointer) != FAIL)
3983 expression (&exp);
3984 else
3985 exp.X_op = O_illegal;
b99bd4ef 3986
c19d1205 3987 if (exp.X_op != O_constant)
b99bd4ef 3988 {
c19d1205
ZW
3989 as_bad (_("expected , <constant>"));
3990 ignore_rest_of_line ();
b99bd4ef
NC
3991 return;
3992 }
3993
c19d1205
ZW
3994 num_regs = exp.X_add_number;
3995
3996 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3997 {
c19d1205
ZW
3998 as_bad (_("number of registers must be in the range [1:4]"));
3999 ignore_rest_of_line ();
b99bd4ef
NC
4000 return;
4001 }
4002
c19d1205 4003 demand_empty_rest_of_line ();
b99bd4ef 4004
c19d1205
ZW
4005 if (reg == 4)
4006 {
4007 /* Short form. */
4008 op = 0xb4 | (num_regs - 1);
4009 add_unwind_opcode (op, 1);
4010 }
b99bd4ef
NC
4011 else
4012 {
c19d1205
ZW
4013 /* Long form. */
4014 op = 0xc800 | (reg << 4) | (num_regs - 1);
4015 add_unwind_opcode (op, 2);
b99bd4ef 4016 }
c19d1205 4017 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4018}
4019
c19d1205 4020
fa073d69
MS
4021/* Parse a directive saving VFP registers for ARMv6 and above. */
4022
4023static void
4024s_arm_unwind_save_vfp_armv6 (void)
4025{
4026 int count;
4027 unsigned int start;
4028 valueT op;
4029 int num_vfpv3_regs = 0;
4030 int num_regs_below_16;
4031
4032 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4033 if (count == FAIL)
4034 {
4035 as_bad (_("expected register list"));
4036 ignore_rest_of_line ();
4037 return;
4038 }
4039
4040 demand_empty_rest_of_line ();
4041
4042 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4043 than FSTMX/FLDMX-style ones). */
4044
4045 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4046 if (start >= 16)
4047 num_vfpv3_regs = count;
4048 else if (start + count > 16)
4049 num_vfpv3_regs = start + count - 16;
4050
4051 if (num_vfpv3_regs > 0)
4052 {
4053 int start_offset = start > 16 ? start - 16 : 0;
4054 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4055 add_unwind_opcode (op, 2);
4056 }
4057
4058 /* Generate opcode for registers numbered in the range 0 .. 15. */
4059 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4060 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4061 if (num_regs_below_16 > 0)
4062 {
4063 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4064 add_unwind_opcode (op, 2);
4065 }
4066
4067 unwind.frame_size += count * 8;
4068}
4069
4070
4071/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4072
4073static void
c19d1205 4074s_arm_unwind_save_vfp (void)
b99bd4ef 4075{
c19d1205 4076 int count;
ca3f61f7 4077 unsigned int reg;
c19d1205 4078 valueT op;
b99bd4ef 4079
5287ad62 4080 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4081 if (count == FAIL)
b99bd4ef 4082 {
c19d1205
ZW
4083 as_bad (_("expected register list"));
4084 ignore_rest_of_line ();
b99bd4ef
NC
4085 return;
4086 }
4087
c19d1205 4088 demand_empty_rest_of_line ();
b99bd4ef 4089
c19d1205 4090 if (reg == 8)
b99bd4ef 4091 {
c19d1205
ZW
4092 /* Short form. */
4093 op = 0xb8 | (count - 1);
4094 add_unwind_opcode (op, 1);
b99bd4ef 4095 }
c19d1205 4096 else
b99bd4ef 4097 {
c19d1205
ZW
4098 /* Long form. */
4099 op = 0xb300 | (reg << 4) | (count - 1);
4100 add_unwind_opcode (op, 2);
b99bd4ef 4101 }
c19d1205
ZW
4102 unwind.frame_size += count * 8 + 4;
4103}
b99bd4ef 4104
b99bd4ef 4105
c19d1205
ZW
4106/* Parse a directive saving iWMMXt data registers. */
4107
4108static void
4109s_arm_unwind_save_mmxwr (void)
4110{
4111 int reg;
4112 int hi_reg;
4113 int i;
4114 unsigned mask = 0;
4115 valueT op;
b99bd4ef 4116
c19d1205
ZW
4117 if (*input_line_pointer == '{')
4118 input_line_pointer++;
b99bd4ef 4119
c19d1205 4120 do
b99bd4ef 4121 {
dcbf9037 4122 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4123
c19d1205 4124 if (reg == FAIL)
b99bd4ef 4125 {
9b7132d3 4126 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4127 goto error;
b99bd4ef
NC
4128 }
4129
c19d1205
ZW
4130 if (mask >> reg)
4131 as_tsktsk (_("register list not in ascending order"));
4132 mask |= 1 << reg;
b99bd4ef 4133
c19d1205
ZW
4134 if (*input_line_pointer == '-')
4135 {
4136 input_line_pointer++;
dcbf9037 4137 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4138 if (hi_reg == FAIL)
4139 {
9b7132d3 4140 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4141 goto error;
4142 }
4143 else if (reg >= hi_reg)
4144 {
4145 as_bad (_("bad register range"));
4146 goto error;
4147 }
4148 for (; reg < hi_reg; reg++)
4149 mask |= 1 << reg;
4150 }
4151 }
4152 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4153
d996d970 4154 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4155
c19d1205 4156 demand_empty_rest_of_line ();
b99bd4ef 4157
708587a4 4158 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4159 the list. */
4160 flush_pending_unwind ();
b99bd4ef 4161
c19d1205 4162 for (i = 0; i < 16; i++)
b99bd4ef 4163 {
c19d1205
ZW
4164 if (mask & (1 << i))
4165 unwind.frame_size += 8;
b99bd4ef
NC
4166 }
4167
c19d1205
ZW
4168 /* Attempt to combine with a previous opcode. We do this because gcc
4169 likes to output separate unwind directives for a single block of
4170 registers. */
4171 if (unwind.opcode_count > 0)
b99bd4ef 4172 {
c19d1205
ZW
4173 i = unwind.opcodes[unwind.opcode_count - 1];
4174 if ((i & 0xf8) == 0xc0)
4175 {
4176 i &= 7;
4177 /* Only merge if the blocks are contiguous. */
4178 if (i < 6)
4179 {
4180 if ((mask & 0xfe00) == (1 << 9))
4181 {
4182 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4183 unwind.opcode_count--;
4184 }
4185 }
4186 else if (i == 6 && unwind.opcode_count >= 2)
4187 {
4188 i = unwind.opcodes[unwind.opcode_count - 2];
4189 reg = i >> 4;
4190 i &= 0xf;
b99bd4ef 4191
c19d1205
ZW
4192 op = 0xffff << (reg - 1);
4193 if (reg > 0
87a1fd79 4194 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4195 {
4196 op = (1 << (reg + i + 1)) - 1;
4197 op &= ~((1 << reg) - 1);
4198 mask |= op;
4199 unwind.opcode_count -= 2;
4200 }
4201 }
4202 }
b99bd4ef
NC
4203 }
4204
c19d1205
ZW
4205 hi_reg = 15;
4206 /* We want to generate opcodes in the order the registers have been
4207 saved, ie. descending order. */
4208 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4209 {
c19d1205
ZW
4210 /* Save registers in blocks. */
4211 if (reg < 0
4212 || !(mask & (1 << reg)))
4213 {
4214 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4215 preceding block. */
c19d1205
ZW
4216 if (reg != hi_reg)
4217 {
4218 if (reg == 9)
4219 {
4220 /* Short form. */
4221 op = 0xc0 | (hi_reg - 10);
4222 add_unwind_opcode (op, 1);
4223 }
4224 else
4225 {
4226 /* Long form. */
4227 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4228 add_unwind_opcode (op, 2);
4229 }
4230 }
4231 hi_reg = reg - 1;
4232 }
b99bd4ef
NC
4233 }
4234
c19d1205
ZW
4235 return;
4236error:
4237 ignore_rest_of_line ();
b99bd4ef
NC
4238}
4239
4240static void
c19d1205 4241s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4242{
c19d1205
ZW
4243 int reg;
4244 int hi_reg;
4245 unsigned mask = 0;
4246 valueT op;
b99bd4ef 4247
c19d1205
ZW
4248 if (*input_line_pointer == '{')
4249 input_line_pointer++;
b99bd4ef 4250
477330fc
RM
4251 skip_whitespace (input_line_pointer);
4252
c19d1205 4253 do
b99bd4ef 4254 {
dcbf9037 4255 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4256
c19d1205
ZW
4257 if (reg == FAIL)
4258 {
9b7132d3 4259 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4260 goto error;
4261 }
b99bd4ef 4262
c19d1205
ZW
4263 reg -= 8;
4264 if (mask >> reg)
4265 as_tsktsk (_("register list not in ascending order"));
4266 mask |= 1 << reg;
b99bd4ef 4267
c19d1205
ZW
4268 if (*input_line_pointer == '-')
4269 {
4270 input_line_pointer++;
dcbf9037 4271 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4272 if (hi_reg == FAIL)
4273 {
9b7132d3 4274 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4275 goto error;
4276 }
4277 else if (reg >= hi_reg)
4278 {
4279 as_bad (_("bad register range"));
4280 goto error;
4281 }
4282 for (; reg < hi_reg; reg++)
4283 mask |= 1 << reg;
4284 }
b99bd4ef 4285 }
c19d1205 4286 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4287
d996d970 4288 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4289
c19d1205
ZW
4290 demand_empty_rest_of_line ();
4291
708587a4 4292 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4293 the list. */
4294 flush_pending_unwind ();
b99bd4ef 4295
c19d1205 4296 for (reg = 0; reg < 16; reg++)
b99bd4ef 4297 {
c19d1205
ZW
4298 if (mask & (1 << reg))
4299 unwind.frame_size += 4;
b99bd4ef 4300 }
c19d1205
ZW
4301 op = 0xc700 | mask;
4302 add_unwind_opcode (op, 2);
4303 return;
4304error:
4305 ignore_rest_of_line ();
b99bd4ef
NC
4306}
4307
c19d1205 4308
fa073d69
MS
4309/* Parse an unwind_save directive.
4310 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4311
b99bd4ef 4312static void
fa073d69 4313s_arm_unwind_save (int arch_v6)
b99bd4ef 4314{
c19d1205
ZW
4315 char *peek;
4316 struct reg_entry *reg;
4317 bfd_boolean had_brace = FALSE;
b99bd4ef 4318
921e5f0a 4319 if (!unwind.proc_start)
c921be7d 4320 as_bad (MISSING_FNSTART);
921e5f0a 4321
c19d1205
ZW
4322 /* Figure out what sort of save we have. */
4323 peek = input_line_pointer;
b99bd4ef 4324
c19d1205 4325 if (*peek == '{')
b99bd4ef 4326 {
c19d1205
ZW
4327 had_brace = TRUE;
4328 peek++;
b99bd4ef
NC
4329 }
4330
c19d1205 4331 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4332
c19d1205 4333 if (!reg)
b99bd4ef 4334 {
c19d1205
ZW
4335 as_bad (_("register expected"));
4336 ignore_rest_of_line ();
b99bd4ef
NC
4337 return;
4338 }
4339
c19d1205 4340 switch (reg->type)
b99bd4ef 4341 {
c19d1205
ZW
4342 case REG_TYPE_FN:
4343 if (had_brace)
4344 {
4345 as_bad (_("FPA .unwind_save does not take a register list"));
4346 ignore_rest_of_line ();
4347 return;
4348 }
93ac2687 4349 input_line_pointer = peek;
c19d1205 4350 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4351 return;
c19d1205 4352
1f5afe1c
NC
4353 case REG_TYPE_RN:
4354 s_arm_unwind_save_core ();
4355 return;
4356
fa073d69
MS
4357 case REG_TYPE_VFD:
4358 if (arch_v6)
477330fc 4359 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4360 else
477330fc 4361 s_arm_unwind_save_vfp ();
fa073d69 4362 return;
1f5afe1c
NC
4363
4364 case REG_TYPE_MMXWR:
4365 s_arm_unwind_save_mmxwr ();
4366 return;
4367
4368 case REG_TYPE_MMXWCG:
4369 s_arm_unwind_save_mmxwcg ();
4370 return;
c19d1205
ZW
4371
4372 default:
4373 as_bad (_(".unwind_save does not support this kind of register"));
4374 ignore_rest_of_line ();
b99bd4ef 4375 }
c19d1205 4376}
b99bd4ef 4377
b99bd4ef 4378
c19d1205
ZW
4379/* Parse an unwind_movsp directive. */
4380
4381static void
4382s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4383{
4384 int reg;
4385 valueT op;
4fa3602b 4386 int offset;
c19d1205 4387
921e5f0a 4388 if (!unwind.proc_start)
c921be7d 4389 as_bad (MISSING_FNSTART);
921e5f0a 4390
dcbf9037 4391 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4392 if (reg == FAIL)
b99bd4ef 4393 {
9b7132d3 4394 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4395 ignore_rest_of_line ();
b99bd4ef
NC
4396 return;
4397 }
4fa3602b
PB
4398
4399 /* Optional constant. */
4400 if (skip_past_comma (&input_line_pointer) != FAIL)
4401 {
4402 if (immediate_for_directive (&offset) == FAIL)
4403 return;
4404 }
4405 else
4406 offset = 0;
4407
c19d1205 4408 demand_empty_rest_of_line ();
b99bd4ef 4409
c19d1205 4410 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4411 {
c19d1205 4412 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4413 return;
4414 }
4415
c19d1205
ZW
4416 if (unwind.fp_reg != REG_SP)
4417 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4418
c19d1205
ZW
4419 /* Generate opcode to restore the value. */
4420 op = 0x90 | reg;
4421 add_unwind_opcode (op, 1);
4422
4423 /* Record the information for later. */
4424 unwind.fp_reg = reg;
4fa3602b 4425 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4426 unwind.sp_restored = 1;
b05fe5cf
ZW
4427}
4428
c19d1205
ZW
4429/* Parse an unwind_pad directive. */
4430
b05fe5cf 4431static void
c19d1205 4432s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4433{
c19d1205 4434 int offset;
b05fe5cf 4435
921e5f0a 4436 if (!unwind.proc_start)
c921be7d 4437 as_bad (MISSING_FNSTART);
921e5f0a 4438
c19d1205
ZW
4439 if (immediate_for_directive (&offset) == FAIL)
4440 return;
b99bd4ef 4441
c19d1205
ZW
4442 if (offset & 3)
4443 {
4444 as_bad (_("stack increment must be multiple of 4"));
4445 ignore_rest_of_line ();
4446 return;
4447 }
b99bd4ef 4448
c19d1205
ZW
4449 /* Don't generate any opcodes, just record the details for later. */
4450 unwind.frame_size += offset;
4451 unwind.pending_offset += offset;
4452
4453 demand_empty_rest_of_line ();
4454}
4455
4456/* Parse an unwind_setfp directive. */
4457
4458static void
4459s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4460{
c19d1205
ZW
4461 int sp_reg;
4462 int fp_reg;
4463 int offset;
4464
921e5f0a 4465 if (!unwind.proc_start)
c921be7d 4466 as_bad (MISSING_FNSTART);
921e5f0a 4467
dcbf9037 4468 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4469 if (skip_past_comma (&input_line_pointer) == FAIL)
4470 sp_reg = FAIL;
4471 else
dcbf9037 4472 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4473
c19d1205
ZW
4474 if (fp_reg == FAIL || sp_reg == FAIL)
4475 {
4476 as_bad (_("expected <reg>, <reg>"));
4477 ignore_rest_of_line ();
4478 return;
4479 }
b99bd4ef 4480
c19d1205
ZW
4481 /* Optional constant. */
4482 if (skip_past_comma (&input_line_pointer) != FAIL)
4483 {
4484 if (immediate_for_directive (&offset) == FAIL)
4485 return;
4486 }
4487 else
4488 offset = 0;
a737bd4d 4489
c19d1205 4490 demand_empty_rest_of_line ();
a737bd4d 4491
fdfde340 4492 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4493 {
c19d1205
ZW
4494 as_bad (_("register must be either sp or set by a previous"
4495 "unwind_movsp directive"));
4496 return;
a737bd4d
NC
4497 }
4498
c19d1205
ZW
4499 /* Don't generate any opcodes, just record the information for later. */
4500 unwind.fp_reg = fp_reg;
4501 unwind.fp_used = 1;
fdfde340 4502 if (sp_reg == REG_SP)
c19d1205
ZW
4503 unwind.fp_offset = unwind.frame_size - offset;
4504 else
4505 unwind.fp_offset -= offset;
a737bd4d
NC
4506}
4507
c19d1205
ZW
4508/* Parse an unwind_raw directive. */
4509
4510static void
4511s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4512{
c19d1205 4513 expressionS exp;
708587a4 4514 /* This is an arbitrary limit. */
c19d1205
ZW
4515 unsigned char op[16];
4516 int count;
a737bd4d 4517
921e5f0a 4518 if (!unwind.proc_start)
c921be7d 4519 as_bad (MISSING_FNSTART);
921e5f0a 4520
c19d1205
ZW
4521 expression (&exp);
4522 if (exp.X_op == O_constant
4523 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4524 {
c19d1205
ZW
4525 unwind.frame_size += exp.X_add_number;
4526 expression (&exp);
4527 }
4528 else
4529 exp.X_op = O_illegal;
a737bd4d 4530
c19d1205
ZW
4531 if (exp.X_op != O_constant)
4532 {
4533 as_bad (_("expected <offset>, <opcode>"));
4534 ignore_rest_of_line ();
4535 return;
4536 }
a737bd4d 4537
c19d1205 4538 count = 0;
a737bd4d 4539
c19d1205
ZW
4540 /* Parse the opcode. */
4541 for (;;)
4542 {
4543 if (count >= 16)
4544 {
4545 as_bad (_("unwind opcode too long"));
4546 ignore_rest_of_line ();
a737bd4d 4547 }
c19d1205 4548 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4549 {
c19d1205
ZW
4550 as_bad (_("invalid unwind opcode"));
4551 ignore_rest_of_line ();
4552 return;
a737bd4d 4553 }
c19d1205 4554 op[count++] = exp.X_add_number;
a737bd4d 4555
c19d1205
ZW
4556 /* Parse the next byte. */
4557 if (skip_past_comma (&input_line_pointer) == FAIL)
4558 break;
a737bd4d 4559
c19d1205
ZW
4560 expression (&exp);
4561 }
b99bd4ef 4562
c19d1205
ZW
4563 /* Add the opcode bytes in reverse order. */
4564 while (count--)
4565 add_unwind_opcode (op[count], 1);
b99bd4ef 4566
c19d1205 4567 demand_empty_rest_of_line ();
b99bd4ef 4568}
ee065d83
PB
4569
4570
4571/* Parse a .eabi_attribute directive. */
4572
4573static void
4574s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4575{
0420f52b 4576 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4577
4578 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4579 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4580}
4581
0855e32b
NS
4582/* Emit a tls fix for the symbol. */
4583
4584static void
4585s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4586{
4587 char *p;
4588 expressionS exp;
4589#ifdef md_flush_pending_output
4590 md_flush_pending_output ();
4591#endif
4592
4593#ifdef md_cons_align
4594 md_cons_align (4);
4595#endif
4596
4597 /* Since we're just labelling the code, there's no need to define a
4598 mapping symbol. */
4599 expression (&exp);
4600 p = obstack_next_free (&frchain_now->frch_obstack);
4601 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4602 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4603 : BFD_RELOC_ARM_TLS_DESCSEQ);
4604}
cdf9ccec 4605#endif /* OBJ_ELF */
0855e32b 4606
ee065d83 4607static void s_arm_arch (int);
7a1d4c38 4608static void s_arm_object_arch (int);
ee065d83
PB
4609static void s_arm_cpu (int);
4610static void s_arm_fpu (int);
69133863 4611static void s_arm_arch_extension (int);
b99bd4ef 4612
f0927246
NC
4613#ifdef TE_PE
4614
4615static void
5f4273c7 4616pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4617{
4618 expressionS exp;
4619
4620 do
4621 {
4622 expression (&exp);
4623 if (exp.X_op == O_symbol)
4624 exp.X_op = O_secrel;
4625
4626 emit_expr (&exp, 4);
4627 }
4628 while (*input_line_pointer++ == ',');
4629
4630 input_line_pointer--;
4631 demand_empty_rest_of_line ();
4632}
4633#endif /* TE_PE */
4634
c19d1205
ZW
4635/* This table describes all the machine specific pseudo-ops the assembler
4636 has to support. The fields are:
4637 pseudo-op name without dot
4638 function to call to execute this pseudo-op
4639 Integer arg to pass to the function. */
b99bd4ef 4640
c19d1205 4641const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4642{
c19d1205
ZW
4643 /* Never called because '.req' does not start a line. */
4644 { "req", s_req, 0 },
dcbf9037
JB
4645 /* Following two are likewise never called. */
4646 { "dn", s_dn, 0 },
4647 { "qn", s_qn, 0 },
c19d1205
ZW
4648 { "unreq", s_unreq, 0 },
4649 { "bss", s_bss, 0 },
db2ed2e0 4650 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4651 { "arm", s_arm, 0 },
4652 { "thumb", s_thumb, 0 },
4653 { "code", s_code, 0 },
4654 { "force_thumb", s_force_thumb, 0 },
4655 { "thumb_func", s_thumb_func, 0 },
4656 { "thumb_set", s_thumb_set, 0 },
4657 { "even", s_even, 0 },
4658 { "ltorg", s_ltorg, 0 },
4659 { "pool", s_ltorg, 0 },
4660 { "syntax", s_syntax, 0 },
8463be01
PB
4661 { "cpu", s_arm_cpu, 0 },
4662 { "arch", s_arm_arch, 0 },
7a1d4c38 4663 { "object_arch", s_arm_object_arch, 0 },
8463be01 4664 { "fpu", s_arm_fpu, 0 },
69133863 4665 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4666#ifdef OBJ_ELF
c921be7d
NC
4667 { "word", s_arm_elf_cons, 4 },
4668 { "long", s_arm_elf_cons, 4 },
4669 { "inst.n", s_arm_elf_inst, 2 },
4670 { "inst.w", s_arm_elf_inst, 4 },
4671 { "inst", s_arm_elf_inst, 0 },
4672 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4673 { "fnstart", s_arm_unwind_fnstart, 0 },
4674 { "fnend", s_arm_unwind_fnend, 0 },
4675 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4676 { "personality", s_arm_unwind_personality, 0 },
4677 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4678 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4679 { "save", s_arm_unwind_save, 0 },
fa073d69 4680 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4681 { "movsp", s_arm_unwind_movsp, 0 },
4682 { "pad", s_arm_unwind_pad, 0 },
4683 { "setfp", s_arm_unwind_setfp, 0 },
4684 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4685 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4686 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4687#else
4688 { "word", cons, 4},
f0927246
NC
4689
4690 /* These are used for dwarf. */
4691 {"2byte", cons, 2},
4692 {"4byte", cons, 4},
4693 {"8byte", cons, 8},
4694 /* These are used for dwarf2. */
4695 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4696 { "loc", dwarf2_directive_loc, 0 },
4697 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4698#endif
4699 { "extend", float_cons, 'x' },
4700 { "ldouble", float_cons, 'x' },
4701 { "packed", float_cons, 'p' },
f0927246
NC
4702#ifdef TE_PE
4703 {"secrel32", pe_directive_secrel, 0},
4704#endif
2e6976a8
DG
4705
4706 /* These are for compatibility with CodeComposer Studio. */
4707 {"ref", s_ccs_ref, 0},
4708 {"def", s_ccs_def, 0},
4709 {"asmfunc", s_ccs_asmfunc, 0},
4710 {"endasmfunc", s_ccs_endasmfunc, 0},
4711
c19d1205
ZW
4712 { 0, 0, 0 }
4713};
4714\f
4715/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4716
c19d1205
ZW
4717/* Generic immediate-value read function for use in insn parsing.
4718 STR points to the beginning of the immediate (the leading #);
4719 VAL receives the value; if the value is outside [MIN, MAX]
4720 issue an error. PREFIX_OPT is true if the immediate prefix is
4721 optional. */
b99bd4ef 4722
c19d1205
ZW
4723static int
4724parse_immediate (char **str, int *val, int min, int max,
4725 bfd_boolean prefix_opt)
4726{
4727 expressionS exp;
4728 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4729 if (exp.X_op != O_constant)
b99bd4ef 4730 {
c19d1205
ZW
4731 inst.error = _("constant expression required");
4732 return FAIL;
4733 }
b99bd4ef 4734
c19d1205
ZW
4735 if (exp.X_add_number < min || exp.X_add_number > max)
4736 {
4737 inst.error = _("immediate value out of range");
4738 return FAIL;
4739 }
b99bd4ef 4740
c19d1205
ZW
4741 *val = exp.X_add_number;
4742 return SUCCESS;
4743}
b99bd4ef 4744
5287ad62 4745/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4746 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4747 instructions. Puts the result directly in inst.operands[i]. */
4748
4749static int
8335d6aa
JW
4750parse_big_immediate (char **str, int i, expressionS *in_exp,
4751 bfd_boolean allow_symbol_p)
5287ad62
JB
4752{
4753 expressionS exp;
8335d6aa 4754 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4755 char *ptr = *str;
4756
8335d6aa 4757 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4758
8335d6aa 4759 if (exp_p->X_op == O_constant)
036dc3f7 4760 {
8335d6aa 4761 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4762 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4763 O_constant. We have to be careful not to break compilation for
4764 32-bit X_add_number, though. */
8335d6aa 4765 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4766 {
8335d6aa
JW
4767 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4768 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4769 & 0xffffffff);
036dc3f7
PB
4770 inst.operands[i].regisimm = 1;
4771 }
4772 }
8335d6aa
JW
4773 else if (exp_p->X_op == O_big
4774 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4775 {
4776 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4777
5287ad62 4778 /* Bignums have their least significant bits in
477330fc
RM
4779 generic_bignum[0]. Make sure we put 32 bits in imm and
4780 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4781 gas_assert (parts != 0);
95b75c01
NC
4782
4783 /* Make sure that the number is not too big.
4784 PR 11972: Bignums can now be sign-extended to the
4785 size of a .octa so check that the out of range bits
4786 are all zero or all one. */
8335d6aa 4787 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4788 {
4789 LITTLENUM_TYPE m = -1;
4790
4791 if (generic_bignum[parts * 2] != 0
4792 && generic_bignum[parts * 2] != m)
4793 return FAIL;
4794
8335d6aa 4795 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4796 if (generic_bignum[j] != generic_bignum[j-1])
4797 return FAIL;
4798 }
4799
5287ad62
JB
4800 inst.operands[i].imm = 0;
4801 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4802 inst.operands[i].imm |= generic_bignum[idx]
4803 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4804 inst.operands[i].reg = 0;
4805 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4806 inst.operands[i].reg |= generic_bignum[idx]
4807 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4808 inst.operands[i].regisimm = 1;
4809 }
8335d6aa 4810 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4811 return FAIL;
5f4273c7 4812
5287ad62
JB
4813 *str = ptr;
4814
4815 return SUCCESS;
4816}
4817
c19d1205
ZW
4818/* Returns the pseudo-register number of an FPA immediate constant,
4819 or FAIL if there isn't a valid constant here. */
b99bd4ef 4820
c19d1205
ZW
4821static int
4822parse_fpa_immediate (char ** str)
4823{
4824 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4825 char * save_in;
4826 expressionS exp;
4827 int i;
4828 int j;
b99bd4ef 4829
c19d1205
ZW
4830 /* First try and match exact strings, this is to guarantee
4831 that some formats will work even for cross assembly. */
b99bd4ef 4832
c19d1205
ZW
4833 for (i = 0; fp_const[i]; i++)
4834 {
4835 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4836 {
c19d1205 4837 char *start = *str;
b99bd4ef 4838
c19d1205
ZW
4839 *str += strlen (fp_const[i]);
4840 if (is_end_of_line[(unsigned char) **str])
4841 return i + 8;
4842 *str = start;
4843 }
4844 }
b99bd4ef 4845
c19d1205
ZW
4846 /* Just because we didn't get a match doesn't mean that the constant
4847 isn't valid, just that it is in a format that we don't
4848 automatically recognize. Try parsing it with the standard
4849 expression routines. */
b99bd4ef 4850
c19d1205 4851 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4852
c19d1205
ZW
4853 /* Look for a raw floating point number. */
4854 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4855 && is_end_of_line[(unsigned char) *save_in])
4856 {
4857 for (i = 0; i < NUM_FLOAT_VALS; i++)
4858 {
4859 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4860 {
c19d1205
ZW
4861 if (words[j] != fp_values[i][j])
4862 break;
b99bd4ef
NC
4863 }
4864
c19d1205 4865 if (j == MAX_LITTLENUMS)
b99bd4ef 4866 {
c19d1205
ZW
4867 *str = save_in;
4868 return i + 8;
b99bd4ef
NC
4869 }
4870 }
4871 }
b99bd4ef 4872
c19d1205
ZW
4873 /* Try and parse a more complex expression, this will probably fail
4874 unless the code uses a floating point prefix (eg "0f"). */
4875 save_in = input_line_pointer;
4876 input_line_pointer = *str;
4877 if (expression (&exp) == absolute_section
4878 && exp.X_op == O_big
4879 && exp.X_add_number < 0)
4880 {
4881 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4882 Ditto for 15. */
ba592044
AM
4883#define X_PRECISION 5
4884#define E_PRECISION 15L
4885 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4886 {
4887 for (i = 0; i < NUM_FLOAT_VALS; i++)
4888 {
4889 for (j = 0; j < MAX_LITTLENUMS; j++)
4890 {
4891 if (words[j] != fp_values[i][j])
4892 break;
4893 }
b99bd4ef 4894
c19d1205
ZW
4895 if (j == MAX_LITTLENUMS)
4896 {
4897 *str = input_line_pointer;
4898 input_line_pointer = save_in;
4899 return i + 8;
4900 }
4901 }
4902 }
b99bd4ef
NC
4903 }
4904
c19d1205
ZW
4905 *str = input_line_pointer;
4906 input_line_pointer = save_in;
4907 inst.error = _("invalid FPA immediate expression");
4908 return FAIL;
b99bd4ef
NC
4909}
4910
136da414
JB
4911/* Returns 1 if a number has "quarter-precision" float format
4912 0baBbbbbbc defgh000 00000000 00000000. */
4913
4914static int
4915is_quarter_float (unsigned imm)
4916{
4917 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4918 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4919}
4920
aacf0b33
KT
4921
4922/* Detect the presence of a floating point or integer zero constant,
4923 i.e. #0.0 or #0. */
4924
4925static bfd_boolean
4926parse_ifimm_zero (char **in)
4927{
4928 int error_code;
4929
4930 if (!is_immediate_prefix (**in))
4931 return FALSE;
4932
4933 ++*in;
0900a05b
JW
4934
4935 /* Accept #0x0 as a synonym for #0. */
4936 if (strncmp (*in, "0x", 2) == 0)
4937 {
4938 int val;
4939 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4940 return FALSE;
4941 return TRUE;
4942 }
4943
aacf0b33
KT
4944 error_code = atof_generic (in, ".", EXP_CHARS,
4945 &generic_floating_point_number);
4946
4947 if (!error_code
4948 && generic_floating_point_number.sign == '+'
4949 && (generic_floating_point_number.low
4950 > generic_floating_point_number.leader))
4951 return TRUE;
4952
4953 return FALSE;
4954}
4955
136da414
JB
4956/* Parse an 8-bit "quarter-precision" floating point number of the form:
4957 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4958 The zero and minus-zero cases need special handling, since they can't be
4959 encoded in the "quarter-precision" float format, but can nonetheless be
4960 loaded as integer constants. */
136da414
JB
4961
4962static unsigned
4963parse_qfloat_immediate (char **ccp, int *immed)
4964{
4965 char *str = *ccp;
c96612cc 4966 char *fpnum;
136da414 4967 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4968 int found_fpchar = 0;
5f4273c7 4969
136da414 4970 skip_past_char (&str, '#');
5f4273c7 4971
c96612cc
JB
4972 /* We must not accidentally parse an integer as a floating-point number. Make
4973 sure that the value we parse is not an integer by checking for special
4974 characters '.' or 'e'.
4975 FIXME: This is a horrible hack, but doing better is tricky because type
4976 information isn't in a very usable state at parse time. */
4977 fpnum = str;
4978 skip_whitespace (fpnum);
4979
4980 if (strncmp (fpnum, "0x", 2) == 0)
4981 return FAIL;
4982 else
4983 {
4984 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
4985 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4986 {
4987 found_fpchar = 1;
4988 break;
4989 }
c96612cc
JB
4990
4991 if (!found_fpchar)
477330fc 4992 return FAIL;
c96612cc 4993 }
5f4273c7 4994
136da414
JB
4995 if ((str = atof_ieee (str, 's', words)) != NULL)
4996 {
4997 unsigned fpword = 0;
4998 int i;
5f4273c7 4999
136da414
JB
5000 /* Our FP word must be 32 bits (single-precision FP). */
5001 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5002 {
5003 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5004 fpword |= words[i];
5005 }
5f4273c7 5006
c96612cc 5007 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5008 *immed = fpword;
136da414 5009 else
477330fc 5010 return FAIL;
136da414
JB
5011
5012 *ccp = str;
5f4273c7 5013
136da414
JB
5014 return SUCCESS;
5015 }
5f4273c7 5016
136da414
JB
5017 return FAIL;
5018}
5019
c19d1205
ZW
5020/* Shift operands. */
5021enum shift_kind
b99bd4ef 5022{
c19d1205
ZW
5023 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5024};
b99bd4ef 5025
c19d1205
ZW
5026struct asm_shift_name
5027{
5028 const char *name;
5029 enum shift_kind kind;
5030};
b99bd4ef 5031
c19d1205
ZW
5032/* Third argument to parse_shift. */
5033enum parse_shift_mode
5034{
5035 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5036 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5037 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5038 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5039 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5040};
b99bd4ef 5041
c19d1205
ZW
5042/* Parse a <shift> specifier on an ARM data processing instruction.
5043 This has three forms:
b99bd4ef 5044
c19d1205
ZW
5045 (LSL|LSR|ASL|ASR|ROR) Rs
5046 (LSL|LSR|ASL|ASR|ROR) #imm
5047 RRX
b99bd4ef 5048
c19d1205
ZW
5049 Note that ASL is assimilated to LSL in the instruction encoding, and
5050 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5051
c19d1205
ZW
5052static int
5053parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5054{
c19d1205
ZW
5055 const struct asm_shift_name *shift_name;
5056 enum shift_kind shift;
5057 char *s = *str;
5058 char *p = s;
5059 int reg;
b99bd4ef 5060
c19d1205
ZW
5061 for (p = *str; ISALPHA (*p); p++)
5062 ;
b99bd4ef 5063
c19d1205 5064 if (p == *str)
b99bd4ef 5065 {
c19d1205
ZW
5066 inst.error = _("shift expression expected");
5067 return FAIL;
b99bd4ef
NC
5068 }
5069
21d799b5 5070 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5071 p - *str);
c19d1205
ZW
5072
5073 if (shift_name == NULL)
b99bd4ef 5074 {
c19d1205
ZW
5075 inst.error = _("shift expression expected");
5076 return FAIL;
b99bd4ef
NC
5077 }
5078
c19d1205 5079 shift = shift_name->kind;
b99bd4ef 5080
c19d1205
ZW
5081 switch (mode)
5082 {
5083 case NO_SHIFT_RESTRICT:
5084 case SHIFT_IMMEDIATE: break;
b99bd4ef 5085
c19d1205
ZW
5086 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5087 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5088 {
5089 inst.error = _("'LSL' or 'ASR' required");
5090 return FAIL;
5091 }
5092 break;
b99bd4ef 5093
c19d1205
ZW
5094 case SHIFT_LSL_IMMEDIATE:
5095 if (shift != SHIFT_LSL)
5096 {
5097 inst.error = _("'LSL' required");
5098 return FAIL;
5099 }
5100 break;
b99bd4ef 5101
c19d1205
ZW
5102 case SHIFT_ASR_IMMEDIATE:
5103 if (shift != SHIFT_ASR)
5104 {
5105 inst.error = _("'ASR' required");
5106 return FAIL;
5107 }
5108 break;
b99bd4ef 5109
c19d1205
ZW
5110 default: abort ();
5111 }
b99bd4ef 5112
c19d1205
ZW
5113 if (shift != SHIFT_RRX)
5114 {
5115 /* Whitespace can appear here if the next thing is a bare digit. */
5116 skip_whitespace (p);
b99bd4ef 5117
c19d1205 5118 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5119 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5120 {
5121 inst.operands[i].imm = reg;
5122 inst.operands[i].immisreg = 1;
5123 }
5124 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5125 return FAIL;
5126 }
5127 inst.operands[i].shift_kind = shift;
5128 inst.operands[i].shifted = 1;
5129 *str = p;
5130 return SUCCESS;
b99bd4ef
NC
5131}
5132
c19d1205 5133/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5134
c19d1205
ZW
5135 #<immediate>
5136 #<immediate>, <rotate>
5137 <Rm>
5138 <Rm>, <shift>
b99bd4ef 5139
c19d1205
ZW
5140 where <shift> is defined by parse_shift above, and <rotate> is a
5141 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5142 is deferred to md_apply_fix. */
b99bd4ef 5143
c19d1205
ZW
5144static int
5145parse_shifter_operand (char **str, int i)
5146{
5147 int value;
91d6fa6a 5148 expressionS exp;
b99bd4ef 5149
dcbf9037 5150 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5151 {
5152 inst.operands[i].reg = value;
5153 inst.operands[i].isreg = 1;
b99bd4ef 5154
c19d1205
ZW
5155 /* parse_shift will override this if appropriate */
5156 inst.reloc.exp.X_op = O_constant;
5157 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5158
c19d1205
ZW
5159 if (skip_past_comma (str) == FAIL)
5160 return SUCCESS;
b99bd4ef 5161
c19d1205
ZW
5162 /* Shift operation on register. */
5163 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5164 }
5165
c19d1205
ZW
5166 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5167 return FAIL;
b99bd4ef 5168
c19d1205 5169 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5170 {
c19d1205 5171 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5172 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5173 return FAIL;
b99bd4ef 5174
91d6fa6a 5175 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5176 {
5177 inst.error = _("constant expression expected");
5178 return FAIL;
5179 }
b99bd4ef 5180
91d6fa6a 5181 value = exp.X_add_number;
c19d1205
ZW
5182 if (value < 0 || value > 30 || value % 2 != 0)
5183 {
5184 inst.error = _("invalid rotation");
5185 return FAIL;
5186 }
5187 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5188 {
5189 inst.error = _("invalid constant");
5190 return FAIL;
5191 }
09d92015 5192
a415b1cd
JB
5193 /* Encode as specified. */
5194 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5195 return SUCCESS;
09d92015
MM
5196 }
5197
c19d1205
ZW
5198 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5199 inst.reloc.pc_rel = 0;
5200 return SUCCESS;
09d92015
MM
5201}
5202
4962c51a
MS
5203/* Group relocation information. Each entry in the table contains the
5204 textual name of the relocation as may appear in assembler source
5205 and must end with a colon.
5206 Along with this textual name are the relocation codes to be used if
5207 the corresponding instruction is an ALU instruction (ADD or SUB only),
5208 an LDR, an LDRS, or an LDC. */
5209
5210struct group_reloc_table_entry
5211{
5212 const char *name;
5213 int alu_code;
5214 int ldr_code;
5215 int ldrs_code;
5216 int ldc_code;
5217};
5218
5219typedef enum
5220{
5221 /* Varieties of non-ALU group relocation. */
5222
5223 GROUP_LDR,
5224 GROUP_LDRS,
5225 GROUP_LDC
5226} group_reloc_type;
5227
5228static struct group_reloc_table_entry group_reloc_table[] =
5229 { /* Program counter relative: */
5230 { "pc_g0_nc",
5231 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5232 0, /* LDR */
5233 0, /* LDRS */
5234 0 }, /* LDC */
5235 { "pc_g0",
5236 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5237 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5238 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5239 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5240 { "pc_g1_nc",
5241 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5242 0, /* LDR */
5243 0, /* LDRS */
5244 0 }, /* LDC */
5245 { "pc_g1",
5246 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5247 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5248 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5249 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5250 { "pc_g2",
5251 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5252 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5253 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5254 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5255 /* Section base relative */
5256 { "sb_g0_nc",
5257 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5258 0, /* LDR */
5259 0, /* LDRS */
5260 0 }, /* LDC */
5261 { "sb_g0",
5262 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5263 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5264 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5265 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5266 { "sb_g1_nc",
5267 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5268 0, /* LDR */
5269 0, /* LDRS */
5270 0 }, /* LDC */
5271 { "sb_g1",
5272 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5273 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5274 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5275 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5276 { "sb_g2",
5277 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5278 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5279 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5280 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5281 /* Absolute thumb alu relocations. */
5282 { "lower0_7",
5283 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5284 0, /* LDR. */
5285 0, /* LDRS. */
5286 0 }, /* LDC. */
5287 { "lower8_15",
5288 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5289 0, /* LDR. */
5290 0, /* LDRS. */
5291 0 }, /* LDC. */
5292 { "upper0_7",
5293 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5294 0, /* LDR. */
5295 0, /* LDRS. */
5296 0 }, /* LDC. */
5297 { "upper8_15",
5298 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5299 0, /* LDR. */
5300 0, /* LDRS. */
5301 0 } }; /* LDC. */
4962c51a
MS
5302
5303/* Given the address of a pointer pointing to the textual name of a group
5304 relocation as may appear in assembler source, attempt to find its details
5305 in group_reloc_table. The pointer will be updated to the character after
5306 the trailing colon. On failure, FAIL will be returned; SUCCESS
5307 otherwise. On success, *entry will be updated to point at the relevant
5308 group_reloc_table entry. */
5309
5310static int
5311find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5312{
5313 unsigned int i;
5314 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5315 {
5316 int length = strlen (group_reloc_table[i].name);
5317
5f4273c7
NC
5318 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5319 && (*str)[length] == ':')
477330fc
RM
5320 {
5321 *out = &group_reloc_table[i];
5322 *str += (length + 1);
5323 return SUCCESS;
5324 }
4962c51a
MS
5325 }
5326
5327 return FAIL;
5328}
5329
5330/* Parse a <shifter_operand> for an ARM data processing instruction
5331 (as for parse_shifter_operand) where group relocations are allowed:
5332
5333 #<immediate>
5334 #<immediate>, <rotate>
5335 #:<group_reloc>:<expression>
5336 <Rm>
5337 <Rm>, <shift>
5338
5339 where <group_reloc> is one of the strings defined in group_reloc_table.
5340 The hashes are optional.
5341
5342 Everything else is as for parse_shifter_operand. */
5343
5344static parse_operand_result
5345parse_shifter_operand_group_reloc (char **str, int i)
5346{
5347 /* Determine if we have the sequence of characters #: or just :
5348 coming next. If we do, then we check for a group relocation.
5349 If we don't, punt the whole lot to parse_shifter_operand. */
5350
5351 if (((*str)[0] == '#' && (*str)[1] == ':')
5352 || (*str)[0] == ':')
5353 {
5354 struct group_reloc_table_entry *entry;
5355
5356 if ((*str)[0] == '#')
477330fc 5357 (*str) += 2;
4962c51a 5358 else
477330fc 5359 (*str)++;
4962c51a
MS
5360
5361 /* Try to parse a group relocation. Anything else is an error. */
5362 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5363 {
5364 inst.error = _("unknown group relocation");
5365 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5366 }
4962c51a
MS
5367
5368 /* We now have the group relocation table entry corresponding to
477330fc 5369 the name in the assembler source. Next, we parse the expression. */
4962c51a 5370 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5371 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5372
5373 /* Record the relocation type (always the ALU variant here). */
21d799b5 5374 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5375 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5376
5377 return PARSE_OPERAND_SUCCESS;
5378 }
5379 else
5380 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5381 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5382
5383 /* Never reached. */
5384}
5385
8e560766
MGD
5386/* Parse a Neon alignment expression. Information is written to
5387 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5388
8e560766
MGD
5389 align .imm = align << 8, .immisalign=1, .preind=0 */
5390static parse_operand_result
5391parse_neon_alignment (char **str, int i)
5392{
5393 char *p = *str;
5394 expressionS exp;
5395
5396 my_get_expression (&exp, &p, GE_NO_PREFIX);
5397
5398 if (exp.X_op != O_constant)
5399 {
5400 inst.error = _("alignment must be constant");
5401 return PARSE_OPERAND_FAIL;
5402 }
5403
5404 inst.operands[i].imm = exp.X_add_number << 8;
5405 inst.operands[i].immisalign = 1;
5406 /* Alignments are not pre-indexes. */
5407 inst.operands[i].preind = 0;
5408
5409 *str = p;
5410 return PARSE_OPERAND_SUCCESS;
5411}
5412
c19d1205
ZW
5413/* Parse all forms of an ARM address expression. Information is written
5414 to inst.operands[i] and/or inst.reloc.
09d92015 5415
c19d1205 5416 Preindexed addressing (.preind=1):
09d92015 5417
c19d1205
ZW
5418 [Rn, #offset] .reg=Rn .reloc.exp=offset
5419 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5420 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5421 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5422
c19d1205 5423 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5424
c19d1205 5425 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5426
c19d1205
ZW
5427 [Rn], #offset .reg=Rn .reloc.exp=offset
5428 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5429 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5430 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5431
c19d1205 5432 Unindexed addressing (.preind=0, .postind=0):
09d92015 5433
c19d1205 5434 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5435
c19d1205 5436 Other:
09d92015 5437
c19d1205
ZW
5438 [Rn]{!} shorthand for [Rn,#0]{!}
5439 =immediate .isreg=0 .reloc.exp=immediate
5440 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5441
c19d1205
ZW
5442 It is the caller's responsibility to check for addressing modes not
5443 supported by the instruction, and to set inst.reloc.type. */
5444
4962c51a
MS
5445static parse_operand_result
5446parse_address_main (char **str, int i, int group_relocations,
477330fc 5447 group_reloc_type group_type)
09d92015 5448{
c19d1205
ZW
5449 char *p = *str;
5450 int reg;
09d92015 5451
c19d1205 5452 if (skip_past_char (&p, '[') == FAIL)
09d92015 5453 {
c19d1205
ZW
5454 if (skip_past_char (&p, '=') == FAIL)
5455 {
974da60d 5456 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5457 inst.reloc.pc_rel = 1;
5458 inst.operands[i].reg = REG_PC;
5459 inst.operands[i].isreg = 1;
5460 inst.operands[i].preind = 1;
09d92015 5461
8335d6aa
JW
5462 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5463 return PARSE_OPERAND_FAIL;
5464 }
5465 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5466 /*allow_symbol_p=*/TRUE))
4962c51a 5467 return PARSE_OPERAND_FAIL;
09d92015 5468
c19d1205 5469 *str = p;
4962c51a 5470 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5471 }
5472
8ab8155f
NC
5473 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5474 skip_whitespace (p);
5475
dcbf9037 5476 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5477 {
c19d1205 5478 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5479 return PARSE_OPERAND_FAIL;
09d92015 5480 }
c19d1205
ZW
5481 inst.operands[i].reg = reg;
5482 inst.operands[i].isreg = 1;
09d92015 5483
c19d1205 5484 if (skip_past_comma (&p) == SUCCESS)
09d92015 5485 {
c19d1205 5486 inst.operands[i].preind = 1;
09d92015 5487
c19d1205
ZW
5488 if (*p == '+') p++;
5489 else if (*p == '-') p++, inst.operands[i].negative = 1;
5490
dcbf9037 5491 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5492 {
c19d1205
ZW
5493 inst.operands[i].imm = reg;
5494 inst.operands[i].immisreg = 1;
5495
5496 if (skip_past_comma (&p) == SUCCESS)
5497 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5498 return PARSE_OPERAND_FAIL;
c19d1205 5499 }
5287ad62 5500 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5501 {
5502 /* FIXME: '@' should be used here, but it's filtered out by generic
5503 code before we get to see it here. This may be subject to
5504 change. */
5505 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5506
8e560766
MGD
5507 if (result != PARSE_OPERAND_SUCCESS)
5508 return result;
5509 }
c19d1205
ZW
5510 else
5511 {
5512 if (inst.operands[i].negative)
5513 {
5514 inst.operands[i].negative = 0;
5515 p--;
5516 }
4962c51a 5517
5f4273c7
NC
5518 if (group_relocations
5519 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5520 {
5521 struct group_reloc_table_entry *entry;
5522
477330fc
RM
5523 /* Skip over the #: or : sequence. */
5524 if (*p == '#')
5525 p += 2;
5526 else
5527 p++;
4962c51a
MS
5528
5529 /* Try to parse a group relocation. Anything else is an
477330fc 5530 error. */
4962c51a
MS
5531 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5532 {
5533 inst.error = _("unknown group relocation");
5534 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5535 }
5536
5537 /* We now have the group relocation table entry corresponding to
5538 the name in the assembler source. Next, we parse the
477330fc 5539 expression. */
4962c51a
MS
5540 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5541 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5542
5543 /* Record the relocation type. */
477330fc
RM
5544 switch (group_type)
5545 {
5546 case GROUP_LDR:
5547 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5548 break;
4962c51a 5549
477330fc
RM
5550 case GROUP_LDRS:
5551 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5552 break;
4962c51a 5553
477330fc
RM
5554 case GROUP_LDC:
5555 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5556 break;
4962c51a 5557
477330fc
RM
5558 default:
5559 gas_assert (0);
5560 }
4962c51a 5561
477330fc 5562 if (inst.reloc.type == 0)
4962c51a
MS
5563 {
5564 inst.error = _("this group relocation is not allowed on this instruction");
5565 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5566 }
477330fc
RM
5567 }
5568 else
26d97720
NS
5569 {
5570 char *q = p;
5571 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5572 return PARSE_OPERAND_FAIL;
5573 /* If the offset is 0, find out if it's a +0 or -0. */
5574 if (inst.reloc.exp.X_op == O_constant
5575 && inst.reloc.exp.X_add_number == 0)
5576 {
5577 skip_whitespace (q);
5578 if (*q == '#')
5579 {
5580 q++;
5581 skip_whitespace (q);
5582 }
5583 if (*q == '-')
5584 inst.operands[i].negative = 1;
5585 }
5586 }
09d92015
MM
5587 }
5588 }
8e560766
MGD
5589 else if (skip_past_char (&p, ':') == SUCCESS)
5590 {
5591 /* FIXME: '@' should be used here, but it's filtered out by generic code
5592 before we get to see it here. This may be subject to change. */
5593 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5594
8e560766
MGD
5595 if (result != PARSE_OPERAND_SUCCESS)
5596 return result;
5597 }
09d92015 5598
c19d1205 5599 if (skip_past_char (&p, ']') == FAIL)
09d92015 5600 {
c19d1205 5601 inst.error = _("']' expected");
4962c51a 5602 return PARSE_OPERAND_FAIL;
09d92015
MM
5603 }
5604
c19d1205
ZW
5605 if (skip_past_char (&p, '!') == SUCCESS)
5606 inst.operands[i].writeback = 1;
09d92015 5607
c19d1205 5608 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5609 {
c19d1205
ZW
5610 if (skip_past_char (&p, '{') == SUCCESS)
5611 {
5612 /* [Rn], {expr} - unindexed, with option */
5613 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5614 0, 255, TRUE) == FAIL)
4962c51a 5615 return PARSE_OPERAND_FAIL;
09d92015 5616
c19d1205
ZW
5617 if (skip_past_char (&p, '}') == FAIL)
5618 {
5619 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5620 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5621 }
5622 if (inst.operands[i].preind)
5623 {
5624 inst.error = _("cannot combine index with option");
4962c51a 5625 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5626 }
5627 *str = p;
4962c51a 5628 return PARSE_OPERAND_SUCCESS;
09d92015 5629 }
c19d1205
ZW
5630 else
5631 {
5632 inst.operands[i].postind = 1;
5633 inst.operands[i].writeback = 1;
09d92015 5634
c19d1205
ZW
5635 if (inst.operands[i].preind)
5636 {
5637 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5638 return PARSE_OPERAND_FAIL;
c19d1205 5639 }
09d92015 5640
c19d1205
ZW
5641 if (*p == '+') p++;
5642 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5643
dcbf9037 5644 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5645 {
477330fc
RM
5646 /* We might be using the immediate for alignment already. If we
5647 are, OR the register number into the low-order bits. */
5648 if (inst.operands[i].immisalign)
5649 inst.operands[i].imm |= reg;
5650 else
5651 inst.operands[i].imm = reg;
c19d1205 5652 inst.operands[i].immisreg = 1;
a737bd4d 5653
c19d1205
ZW
5654 if (skip_past_comma (&p) == SUCCESS)
5655 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5656 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5657 }
5658 else
5659 {
26d97720 5660 char *q = p;
c19d1205
ZW
5661 if (inst.operands[i].negative)
5662 {
5663 inst.operands[i].negative = 0;
5664 p--;
5665 }
5666 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5667 return PARSE_OPERAND_FAIL;
26d97720
NS
5668 /* If the offset is 0, find out if it's a +0 or -0. */
5669 if (inst.reloc.exp.X_op == O_constant
5670 && inst.reloc.exp.X_add_number == 0)
5671 {
5672 skip_whitespace (q);
5673 if (*q == '#')
5674 {
5675 q++;
5676 skip_whitespace (q);
5677 }
5678 if (*q == '-')
5679 inst.operands[i].negative = 1;
5680 }
c19d1205
ZW
5681 }
5682 }
a737bd4d
NC
5683 }
5684
c19d1205
ZW
5685 /* If at this point neither .preind nor .postind is set, we have a
5686 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5687 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5688 {
5689 inst.operands[i].preind = 1;
5690 inst.reloc.exp.X_op = O_constant;
5691 inst.reloc.exp.X_add_number = 0;
5692 }
5693 *str = p;
4962c51a
MS
5694 return PARSE_OPERAND_SUCCESS;
5695}
5696
5697static int
5698parse_address (char **str, int i)
5699{
21d799b5 5700 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5701 ? SUCCESS : FAIL;
4962c51a
MS
5702}
5703
5704static parse_operand_result
5705parse_address_group_reloc (char **str, int i, group_reloc_type type)
5706{
5707 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5708}
5709
b6895b4f
PB
5710/* Parse an operand for a MOVW or MOVT instruction. */
5711static int
5712parse_half (char **str)
5713{
5714 char * p;
5f4273c7 5715
b6895b4f
PB
5716 p = *str;
5717 skip_past_char (&p, '#');
5f4273c7 5718 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5719 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5720 else if (strncasecmp (p, ":upper16:", 9) == 0)
5721 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5722
5723 if (inst.reloc.type != BFD_RELOC_UNUSED)
5724 {
5725 p += 9;
5f4273c7 5726 skip_whitespace (p);
b6895b4f
PB
5727 }
5728
5729 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5730 return FAIL;
5731
5732 if (inst.reloc.type == BFD_RELOC_UNUSED)
5733 {
5734 if (inst.reloc.exp.X_op != O_constant)
5735 {
5736 inst.error = _("constant expression expected");
5737 return FAIL;
5738 }
5739 if (inst.reloc.exp.X_add_number < 0
5740 || inst.reloc.exp.X_add_number > 0xffff)
5741 {
5742 inst.error = _("immediate value out of range");
5743 return FAIL;
5744 }
5745 }
5746 *str = p;
5747 return SUCCESS;
5748}
5749
c19d1205 5750/* Miscellaneous. */
a737bd4d 5751
c19d1205
ZW
5752/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5753 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5754static int
d2cd1205 5755parse_psr (char **str, bfd_boolean lhs)
09d92015 5756{
c19d1205
ZW
5757 char *p;
5758 unsigned long psr_field;
62b3e311
PB
5759 const struct asm_psr *psr;
5760 char *start;
d2cd1205 5761 bfd_boolean is_apsr = FALSE;
ac7f631b 5762 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5763
a4482bb6
NC
5764 /* PR gas/12698: If the user has specified -march=all then m_profile will
5765 be TRUE, but we want to ignore it in this case as we are building for any
5766 CPU type, including non-m variants. */
823d2571 5767 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5768 m_profile = FALSE;
5769
c19d1205
ZW
5770 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5771 feature for ease of use and backwards compatibility. */
5772 p = *str;
62b3e311 5773 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5774 {
5775 if (m_profile)
5776 goto unsupported_psr;
fa94de6b 5777
d2cd1205
JB
5778 psr_field = SPSR_BIT;
5779 }
5780 else if (strncasecmp (p, "CPSR", 4) == 0)
5781 {
5782 if (m_profile)
5783 goto unsupported_psr;
5784
5785 psr_field = 0;
5786 }
5787 else if (strncasecmp (p, "APSR", 4) == 0)
5788 {
5789 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5790 and ARMv7-R architecture CPUs. */
5791 is_apsr = TRUE;
5792 psr_field = 0;
5793 }
5794 else if (m_profile)
62b3e311
PB
5795 {
5796 start = p;
5797 do
5798 p++;
5799 while (ISALNUM (*p) || *p == '_');
5800
d2cd1205
JB
5801 if (strncasecmp (start, "iapsr", 5) == 0
5802 || strncasecmp (start, "eapsr", 5) == 0
5803 || strncasecmp (start, "xpsr", 4) == 0
5804 || strncasecmp (start, "psr", 3) == 0)
5805 p = start + strcspn (start, "rR") + 1;
5806
21d799b5 5807 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5808 p - start);
d2cd1205 5809
62b3e311
PB
5810 if (!psr)
5811 return FAIL;
09d92015 5812
d2cd1205
JB
5813 /* If APSR is being written, a bitfield may be specified. Note that
5814 APSR itself is handled above. */
5815 if (psr->field <= 3)
5816 {
5817 psr_field = psr->field;
5818 is_apsr = TRUE;
5819 goto check_suffix;
5820 }
5821
62b3e311 5822 *str = p;
d2cd1205
JB
5823 /* M-profile MSR instructions have the mask field set to "10", except
5824 *PSR variants which modify APSR, which may use a different mask (and
5825 have been handled already). Do that by setting the PSR_f field
5826 here. */
5827 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5828 }
d2cd1205
JB
5829 else
5830 goto unsupported_psr;
09d92015 5831
62b3e311 5832 p += 4;
d2cd1205 5833check_suffix:
c19d1205
ZW
5834 if (*p == '_')
5835 {
5836 /* A suffix follows. */
c19d1205
ZW
5837 p++;
5838 start = p;
a737bd4d 5839
c19d1205
ZW
5840 do
5841 p++;
5842 while (ISALNUM (*p) || *p == '_');
a737bd4d 5843
d2cd1205
JB
5844 if (is_apsr)
5845 {
5846 /* APSR uses a notation for bits, rather than fields. */
5847 unsigned int nzcvq_bits = 0;
5848 unsigned int g_bit = 0;
5849 char *bit;
fa94de6b 5850
d2cd1205
JB
5851 for (bit = start; bit != p; bit++)
5852 {
5853 switch (TOLOWER (*bit))
477330fc 5854 {
d2cd1205
JB
5855 case 'n':
5856 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5857 break;
5858
5859 case 'z':
5860 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5861 break;
5862
5863 case 'c':
5864 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5865 break;
5866
5867 case 'v':
5868 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5869 break;
fa94de6b 5870
d2cd1205
JB
5871 case 'q':
5872 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5873 break;
fa94de6b 5874
d2cd1205
JB
5875 case 'g':
5876 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5877 break;
fa94de6b 5878
d2cd1205
JB
5879 default:
5880 inst.error = _("unexpected bit specified after APSR");
5881 return FAIL;
5882 }
5883 }
fa94de6b 5884
d2cd1205
JB
5885 if (nzcvq_bits == 0x1f)
5886 psr_field |= PSR_f;
fa94de6b 5887
d2cd1205
JB
5888 if (g_bit == 0x1)
5889 {
5890 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5891 {
d2cd1205
JB
5892 inst.error = _("selected processor does not "
5893 "support DSP extension");
5894 return FAIL;
5895 }
5896
5897 psr_field |= PSR_s;
5898 }
fa94de6b 5899
d2cd1205
JB
5900 if ((nzcvq_bits & 0x20) != 0
5901 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5902 || (g_bit & 0x2) != 0)
5903 {
5904 inst.error = _("bad bitmask specified after APSR");
5905 return FAIL;
5906 }
5907 }
5908 else
477330fc 5909 {
d2cd1205 5910 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5911 p - start);
d2cd1205 5912 if (!psr)
477330fc 5913 goto error;
a737bd4d 5914
d2cd1205
JB
5915 psr_field |= psr->field;
5916 }
a737bd4d 5917 }
c19d1205 5918 else
a737bd4d 5919 {
c19d1205
ZW
5920 if (ISALNUM (*p))
5921 goto error; /* Garbage after "[CS]PSR". */
5922
d2cd1205 5923 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5924 is deprecated, but allow it anyway. */
d2cd1205
JB
5925 if (is_apsr && lhs)
5926 {
5927 psr_field |= PSR_f;
5928 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5929 "deprecated"));
5930 }
5931 else if (!m_profile)
5932 /* These bits are never right for M-profile devices: don't set them
5933 (only code paths which read/write APSR reach here). */
5934 psr_field |= (PSR_c | PSR_f);
a737bd4d 5935 }
c19d1205
ZW
5936 *str = p;
5937 return psr_field;
a737bd4d 5938
d2cd1205
JB
5939 unsupported_psr:
5940 inst.error = _("selected processor does not support requested special "
5941 "purpose register");
5942 return FAIL;
5943
c19d1205
ZW
5944 error:
5945 inst.error = _("flag for {c}psr instruction expected");
5946 return FAIL;
a737bd4d
NC
5947}
5948
c19d1205
ZW
5949/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5950 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5951
c19d1205
ZW
5952static int
5953parse_cps_flags (char **str)
a737bd4d 5954{
c19d1205
ZW
5955 int val = 0;
5956 int saw_a_flag = 0;
5957 char *s = *str;
a737bd4d 5958
c19d1205
ZW
5959 for (;;)
5960 switch (*s++)
5961 {
5962 case '\0': case ',':
5963 goto done;
a737bd4d 5964
c19d1205
ZW
5965 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5966 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5967 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5968
c19d1205
ZW
5969 default:
5970 inst.error = _("unrecognized CPS flag");
5971 return FAIL;
5972 }
a737bd4d 5973
c19d1205
ZW
5974 done:
5975 if (saw_a_flag == 0)
a737bd4d 5976 {
c19d1205
ZW
5977 inst.error = _("missing CPS flags");
5978 return FAIL;
a737bd4d 5979 }
a737bd4d 5980
c19d1205
ZW
5981 *str = s - 1;
5982 return val;
a737bd4d
NC
5983}
5984
c19d1205
ZW
5985/* Parse an endian specifier ("BE" or "LE", case insensitive);
5986 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5987
5988static int
c19d1205 5989parse_endian_specifier (char **str)
a737bd4d 5990{
c19d1205
ZW
5991 int little_endian;
5992 char *s = *str;
a737bd4d 5993
c19d1205
ZW
5994 if (strncasecmp (s, "BE", 2))
5995 little_endian = 0;
5996 else if (strncasecmp (s, "LE", 2))
5997 little_endian = 1;
5998 else
a737bd4d 5999 {
c19d1205 6000 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6001 return FAIL;
6002 }
6003
c19d1205 6004 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6005 {
c19d1205 6006 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6007 return FAIL;
6008 }
6009
c19d1205
ZW
6010 *str = s + 2;
6011 return little_endian;
6012}
a737bd4d 6013
c19d1205
ZW
6014/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6015 value suitable for poking into the rotate field of an sxt or sxta
6016 instruction, or FAIL on error. */
6017
6018static int
6019parse_ror (char **str)
6020{
6021 int rot;
6022 char *s = *str;
6023
6024 if (strncasecmp (s, "ROR", 3) == 0)
6025 s += 3;
6026 else
a737bd4d 6027 {
c19d1205 6028 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6029 return FAIL;
6030 }
c19d1205
ZW
6031
6032 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6033 return FAIL;
6034
6035 switch (rot)
a737bd4d 6036 {
c19d1205
ZW
6037 case 0: *str = s; return 0x0;
6038 case 8: *str = s; return 0x1;
6039 case 16: *str = s; return 0x2;
6040 case 24: *str = s; return 0x3;
6041
6042 default:
6043 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6044 return FAIL;
6045 }
c19d1205 6046}
a737bd4d 6047
c19d1205
ZW
6048/* Parse a conditional code (from conds[] below). The value returned is in the
6049 range 0 .. 14, or FAIL. */
6050static int
6051parse_cond (char **str)
6052{
c462b453 6053 char *q;
c19d1205 6054 const struct asm_cond *c;
c462b453
PB
6055 int n;
6056 /* Condition codes are always 2 characters, so matching up to
6057 3 characters is sufficient. */
6058 char cond[3];
a737bd4d 6059
c462b453
PB
6060 q = *str;
6061 n = 0;
6062 while (ISALPHA (*q) && n < 3)
6063 {
e07e6e58 6064 cond[n] = TOLOWER (*q);
c462b453
PB
6065 q++;
6066 n++;
6067 }
a737bd4d 6068
21d799b5 6069 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6070 if (!c)
a737bd4d 6071 {
c19d1205 6072 inst.error = _("condition required");
a737bd4d
NC
6073 return FAIL;
6074 }
6075
c19d1205
ZW
6076 *str = q;
6077 return c->value;
6078}
6079
e797f7e0
MGD
6080/* If the given feature available in the selected CPU, mark it as used.
6081 Returns TRUE iff feature is available. */
6082static bfd_boolean
6083mark_feature_used (const arm_feature_set *feature)
6084{
6085 /* Ensure the option is valid on the current architecture. */
6086 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6087 return FALSE;
6088
6089 /* Add the appropriate architecture feature for the barrier option used.
6090 */
6091 if (thumb_mode)
6092 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6093 else
6094 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6095
6096 return TRUE;
6097}
6098
62b3e311
PB
6099/* Parse an option for a barrier instruction. Returns the encoding for the
6100 option, or FAIL. */
6101static int
6102parse_barrier (char **str)
6103{
6104 char *p, *q;
6105 const struct asm_barrier_opt *o;
6106
6107 p = q = *str;
6108 while (ISALPHA (*q))
6109 q++;
6110
21d799b5 6111 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6112 q - p);
62b3e311
PB
6113 if (!o)
6114 return FAIL;
6115
e797f7e0
MGD
6116 if (!mark_feature_used (&o->arch))
6117 return FAIL;
6118
62b3e311
PB
6119 *str = q;
6120 return o->value;
6121}
6122
92e90b6e
PB
6123/* Parse the operands of a table branch instruction. Similar to a memory
6124 operand. */
6125static int
6126parse_tb (char **str)
6127{
6128 char * p = *str;
6129 int reg;
6130
6131 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6132 {
6133 inst.error = _("'[' expected");
6134 return FAIL;
6135 }
92e90b6e 6136
dcbf9037 6137 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6138 {
6139 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6140 return FAIL;
6141 }
6142 inst.operands[0].reg = reg;
6143
6144 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6145 {
6146 inst.error = _("',' expected");
6147 return FAIL;
6148 }
5f4273c7 6149
dcbf9037 6150 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6151 {
6152 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6153 return FAIL;
6154 }
6155 inst.operands[0].imm = reg;
6156
6157 if (skip_past_comma (&p) == SUCCESS)
6158 {
6159 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6160 return FAIL;
6161 if (inst.reloc.exp.X_add_number != 1)
6162 {
6163 inst.error = _("invalid shift");
6164 return FAIL;
6165 }
6166 inst.operands[0].shifted = 1;
6167 }
6168
6169 if (skip_past_char (&p, ']') == FAIL)
6170 {
6171 inst.error = _("']' expected");
6172 return FAIL;
6173 }
6174 *str = p;
6175 return SUCCESS;
6176}
6177
5287ad62
JB
6178/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6179 information on the types the operands can take and how they are encoded.
037e8744
JB
6180 Up to four operands may be read; this function handles setting the
6181 ".present" field for each read operand itself.
5287ad62
JB
6182 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6183 else returns FAIL. */
6184
6185static int
6186parse_neon_mov (char **str, int *which_operand)
6187{
6188 int i = *which_operand, val;
6189 enum arm_reg_type rtype;
6190 char *ptr = *str;
dcbf9037 6191 struct neon_type_el optype;
5f4273c7 6192
dcbf9037 6193 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6194 {
6195 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6196 inst.operands[i].reg = val;
6197 inst.operands[i].isscalar = 1;
dcbf9037 6198 inst.operands[i].vectype = optype;
5287ad62
JB
6199 inst.operands[i++].present = 1;
6200
6201 if (skip_past_comma (&ptr) == FAIL)
477330fc 6202 goto wanted_comma;
5f4273c7 6203
dcbf9037 6204 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6205 goto wanted_arm;
5f4273c7 6206
5287ad62
JB
6207 inst.operands[i].reg = val;
6208 inst.operands[i].isreg = 1;
6209 inst.operands[i].present = 1;
6210 }
037e8744 6211 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6212 != FAIL)
5287ad62
JB
6213 {
6214 /* Cases 0, 1, 2, 3, 5 (D only). */
6215 if (skip_past_comma (&ptr) == FAIL)
477330fc 6216 goto wanted_comma;
5f4273c7 6217
5287ad62
JB
6218 inst.operands[i].reg = val;
6219 inst.operands[i].isreg = 1;
6220 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6221 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6222 inst.operands[i].isvec = 1;
dcbf9037 6223 inst.operands[i].vectype = optype;
5287ad62
JB
6224 inst.operands[i++].present = 1;
6225
dcbf9037 6226 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6227 {
6228 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6229 Case 13: VMOV <Sd>, <Rm> */
6230 inst.operands[i].reg = val;
6231 inst.operands[i].isreg = 1;
6232 inst.operands[i].present = 1;
6233
6234 if (rtype == REG_TYPE_NQ)
6235 {
6236 first_error (_("can't use Neon quad register here"));
6237 return FAIL;
6238 }
6239 else if (rtype != REG_TYPE_VFS)
6240 {
6241 i++;
6242 if (skip_past_comma (&ptr) == FAIL)
6243 goto wanted_comma;
6244 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6245 goto wanted_arm;
6246 inst.operands[i].reg = val;
6247 inst.operands[i].isreg = 1;
6248 inst.operands[i].present = 1;
6249 }
6250 }
037e8744 6251 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6252 &optype)) != FAIL)
6253 {
6254 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6255 Case 1: VMOV<c><q> <Dd>, <Dm>
6256 Case 8: VMOV.F32 <Sd>, <Sm>
6257 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6258
6259 inst.operands[i].reg = val;
6260 inst.operands[i].isreg = 1;
6261 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6262 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6263 inst.operands[i].isvec = 1;
6264 inst.operands[i].vectype = optype;
6265 inst.operands[i].present = 1;
6266
6267 if (skip_past_comma (&ptr) == SUCCESS)
6268 {
6269 /* Case 15. */
6270 i++;
6271
6272 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6273 goto wanted_arm;
6274
6275 inst.operands[i].reg = val;
6276 inst.operands[i].isreg = 1;
6277 inst.operands[i++].present = 1;
6278
6279 if (skip_past_comma (&ptr) == FAIL)
6280 goto wanted_comma;
6281
6282 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6283 goto wanted_arm;
6284
6285 inst.operands[i].reg = val;
6286 inst.operands[i].isreg = 1;
6287 inst.operands[i].present = 1;
6288 }
6289 }
4641781c 6290 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6291 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6292 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6293 Case 10: VMOV.F32 <Sd>, #<imm>
6294 Case 11: VMOV.F64 <Dd>, #<imm> */
6295 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6296 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6297 == SUCCESS)
477330fc
RM
6298 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6299 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6300 ;
5287ad62 6301 else
477330fc
RM
6302 {
6303 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6304 return FAIL;
6305 }
5287ad62 6306 }
dcbf9037 6307 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6308 {
6309 /* Cases 6, 7. */
6310 inst.operands[i].reg = val;
6311 inst.operands[i].isreg = 1;
6312 inst.operands[i++].present = 1;
5f4273c7 6313
5287ad62 6314 if (skip_past_comma (&ptr) == FAIL)
477330fc 6315 goto wanted_comma;
5f4273c7 6316
dcbf9037 6317 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6318 {
6319 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6320 inst.operands[i].reg = val;
6321 inst.operands[i].isscalar = 1;
6322 inst.operands[i].present = 1;
6323 inst.operands[i].vectype = optype;
6324 }
dcbf9037 6325 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6326 {
6327 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6328 inst.operands[i].reg = val;
6329 inst.operands[i].isreg = 1;
6330 inst.operands[i++].present = 1;
6331
6332 if (skip_past_comma (&ptr) == FAIL)
6333 goto wanted_comma;
6334
6335 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6336 == FAIL)
6337 {
6338 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6339 return FAIL;
6340 }
6341
6342 inst.operands[i].reg = val;
6343 inst.operands[i].isreg = 1;
6344 inst.operands[i].isvec = 1;
6345 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6346 inst.operands[i].vectype = optype;
6347 inst.operands[i].present = 1;
6348
6349 if (rtype == REG_TYPE_VFS)
6350 {
6351 /* Case 14. */
6352 i++;
6353 if (skip_past_comma (&ptr) == FAIL)
6354 goto wanted_comma;
6355 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6356 &optype)) == FAIL)
6357 {
6358 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6359 return FAIL;
6360 }
6361 inst.operands[i].reg = val;
6362 inst.operands[i].isreg = 1;
6363 inst.operands[i].isvec = 1;
6364 inst.operands[i].issingle = 1;
6365 inst.operands[i].vectype = optype;
6366 inst.operands[i].present = 1;
6367 }
6368 }
037e8744 6369 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6370 != FAIL)
6371 {
6372 /* Case 13. */
6373 inst.operands[i].reg = val;
6374 inst.operands[i].isreg = 1;
6375 inst.operands[i].isvec = 1;
6376 inst.operands[i].issingle = 1;
6377 inst.operands[i].vectype = optype;
6378 inst.operands[i].present = 1;
6379 }
5287ad62
JB
6380 }
6381 else
6382 {
dcbf9037 6383 first_error (_("parse error"));
5287ad62
JB
6384 return FAIL;
6385 }
6386
6387 /* Successfully parsed the operands. Update args. */
6388 *which_operand = i;
6389 *str = ptr;
6390 return SUCCESS;
6391
5f4273c7 6392 wanted_comma:
dcbf9037 6393 first_error (_("expected comma"));
5287ad62 6394 return FAIL;
5f4273c7
NC
6395
6396 wanted_arm:
dcbf9037 6397 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6398 return FAIL;
5287ad62
JB
6399}
6400
5be8be5d
DG
6401/* Use this macro when the operand constraints are different
6402 for ARM and THUMB (e.g. ldrd). */
6403#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6404 ((arm_operand) | ((thumb_operand) << 16))
6405
c19d1205
ZW
6406/* Matcher codes for parse_operands. */
6407enum operand_parse_code
6408{
6409 OP_stop, /* end of line */
6410
6411 OP_RR, /* ARM register */
6412 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6413 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6414 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6415 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6416 optional trailing ! */
c19d1205
ZW
6417 OP_RRw, /* ARM register, not r15, optional trailing ! */
6418 OP_RCP, /* Coprocessor number */
6419 OP_RCN, /* Coprocessor register */
6420 OP_RF, /* FPA register */
6421 OP_RVS, /* VFP single precision register */
5287ad62
JB
6422 OP_RVD, /* VFP double precision register (0..15) */
6423 OP_RND, /* Neon double precision register (0..31) */
6424 OP_RNQ, /* Neon quad precision register */
037e8744 6425 OP_RVSD, /* VFP single or double precision register */
5287ad62 6426 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6427 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6428 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6429 OP_RVC, /* VFP control register */
6430 OP_RMF, /* Maverick F register */
6431 OP_RMD, /* Maverick D register */
6432 OP_RMFX, /* Maverick FX register */
6433 OP_RMDX, /* Maverick DX register */
6434 OP_RMAX, /* Maverick AX register */
6435 OP_RMDS, /* Maverick DSPSC register */
6436 OP_RIWR, /* iWMMXt wR register */
6437 OP_RIWC, /* iWMMXt wC register */
6438 OP_RIWG, /* iWMMXt wCG register */
6439 OP_RXA, /* XScale accumulator register */
6440
6441 OP_REGLST, /* ARM register list */
6442 OP_VRSLST, /* VFP single-precision register list */
6443 OP_VRDLST, /* VFP double-precision register list */
037e8744 6444 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6445 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6446 OP_NSTRLST, /* Neon element/structure list */
6447
5287ad62 6448 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6449 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6450 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6451 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6452 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6453 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6454 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6455 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6456 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6457 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6458 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6459
6460 OP_I0, /* immediate zero */
c19d1205
ZW
6461 OP_I7, /* immediate value 0 .. 7 */
6462 OP_I15, /* 0 .. 15 */
6463 OP_I16, /* 1 .. 16 */
5287ad62 6464 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6465 OP_I31, /* 0 .. 31 */
6466 OP_I31w, /* 0 .. 31, optional trailing ! */
6467 OP_I32, /* 1 .. 32 */
5287ad62
JB
6468 OP_I32z, /* 0 .. 32 */
6469 OP_I63, /* 0 .. 63 */
c19d1205 6470 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6471 OP_I64, /* 1 .. 64 */
6472 OP_I64z, /* 0 .. 64 */
c19d1205 6473 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6474
6475 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6476 OP_I7b, /* 0 .. 7 */
6477 OP_I15b, /* 0 .. 15 */
6478 OP_I31b, /* 0 .. 31 */
6479
6480 OP_SH, /* shifter operand */
4962c51a 6481 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6482 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6483 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6484 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6485 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6486 OP_EXP, /* arbitrary expression */
6487 OP_EXPi, /* same, with optional immediate prefix */
6488 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6489 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6490
6491 OP_CPSF, /* CPS flags */
6492 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6493 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6494 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6495 OP_COND, /* conditional code */
92e90b6e 6496 OP_TB, /* Table branch. */
c19d1205 6497
037e8744
JB
6498 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6499
c19d1205
ZW
6500 OP_RRnpc_I0, /* ARM register or literal 0 */
6501 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6502 OP_RR_EXi, /* ARM register or expression with imm prefix */
6503 OP_RF_IF, /* FPA register or immediate */
6504 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6505 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6506
6507 /* Optional operands. */
6508 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6509 OP_oI31b, /* 0 .. 31 */
5287ad62 6510 OP_oI32b, /* 1 .. 32 */
5f1af56b 6511 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6512 OP_oIffffb, /* 0 .. 65535 */
6513 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6514
6515 OP_oRR, /* ARM register */
6516 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6517 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6518 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6519 OP_oRND, /* Optional Neon double precision register */
6520 OP_oRNQ, /* Optional Neon quad precision register */
6521 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6522 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6523 OP_oSHll, /* LSL immediate */
6524 OP_oSHar, /* ASR immediate */
6525 OP_oSHllar, /* LSL or ASR immediate */
6526 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6527 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6528
5be8be5d
DG
6529 /* Some pre-defined mixed (ARM/THUMB) operands. */
6530 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6531 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6532 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6533
c19d1205
ZW
6534 OP_FIRST_OPTIONAL = OP_oI7b
6535};
a737bd4d 6536
c19d1205
ZW
6537/* Generic instruction operand parser. This does no encoding and no
6538 semantic validation; it merely squirrels values away in the inst
6539 structure. Returns SUCCESS or FAIL depending on whether the
6540 specified grammar matched. */
6541static int
5be8be5d 6542parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6543{
5be8be5d 6544 unsigned const int *upat = pattern;
c19d1205
ZW
6545 char *backtrack_pos = 0;
6546 const char *backtrack_error = 0;
99aad254 6547 int i, val = 0, backtrack_index = 0;
5287ad62 6548 enum arm_reg_type rtype;
4962c51a 6549 parse_operand_result result;
5be8be5d 6550 unsigned int op_parse_code;
c19d1205 6551
e07e6e58
NC
6552#define po_char_or_fail(chr) \
6553 do \
6554 { \
6555 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6556 goto bad_args; \
e07e6e58
NC
6557 } \
6558 while (0)
c19d1205 6559
e07e6e58
NC
6560#define po_reg_or_fail(regtype) \
6561 do \
dcbf9037 6562 { \
e07e6e58 6563 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6564 & inst.operands[i].vectype); \
e07e6e58 6565 if (val == FAIL) \
477330fc
RM
6566 { \
6567 first_error (_(reg_expected_msgs[regtype])); \
6568 goto failure; \
6569 } \
e07e6e58
NC
6570 inst.operands[i].reg = val; \
6571 inst.operands[i].isreg = 1; \
6572 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6573 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6574 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6575 || rtype == REG_TYPE_VFD \
6576 || rtype == REG_TYPE_NQ); \
dcbf9037 6577 } \
e07e6e58
NC
6578 while (0)
6579
6580#define po_reg_or_goto(regtype, label) \
6581 do \
6582 { \
6583 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6584 & inst.operands[i].vectype); \
6585 if (val == FAIL) \
6586 goto label; \
dcbf9037 6587 \
e07e6e58
NC
6588 inst.operands[i].reg = val; \
6589 inst.operands[i].isreg = 1; \
6590 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6591 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6592 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6593 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6594 || rtype == REG_TYPE_NQ); \
6595 } \
6596 while (0)
6597
6598#define po_imm_or_fail(min, max, popt) \
6599 do \
6600 { \
6601 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6602 goto failure; \
6603 inst.operands[i].imm = val; \
6604 } \
6605 while (0)
6606
6607#define po_scalar_or_goto(elsz, label) \
6608 do \
6609 { \
6610 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6611 if (val == FAIL) \
6612 goto label; \
6613 inst.operands[i].reg = val; \
6614 inst.operands[i].isscalar = 1; \
6615 } \
6616 while (0)
6617
6618#define po_misc_or_fail(expr) \
6619 do \
6620 { \
6621 if (expr) \
6622 goto failure; \
6623 } \
6624 while (0)
6625
6626#define po_misc_or_fail_no_backtrack(expr) \
6627 do \
6628 { \
6629 result = expr; \
6630 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6631 backtrack_pos = 0; \
6632 if (result != PARSE_OPERAND_SUCCESS) \
6633 goto failure; \
6634 } \
6635 while (0)
4962c51a 6636
52e7f43d
RE
6637#define po_barrier_or_imm(str) \
6638 do \
6639 { \
6640 val = parse_barrier (&str); \
ccb84d65
JB
6641 if (val == FAIL && ! ISALPHA (*str)) \
6642 goto immediate; \
6643 if (val == FAIL \
6644 /* ISB can only take SY as an option. */ \
6645 || ((inst.instruction & 0xf0) == 0x60 \
6646 && val != 0xf)) \
52e7f43d 6647 { \
ccb84d65
JB
6648 inst.error = _("invalid barrier type"); \
6649 backtrack_pos = 0; \
6650 goto failure; \
52e7f43d
RE
6651 } \
6652 } \
6653 while (0)
6654
c19d1205
ZW
6655 skip_whitespace (str);
6656
6657 for (i = 0; upat[i] != OP_stop; i++)
6658 {
5be8be5d
DG
6659 op_parse_code = upat[i];
6660 if (op_parse_code >= 1<<16)
6661 op_parse_code = thumb ? (op_parse_code >> 16)
6662 : (op_parse_code & ((1<<16)-1));
6663
6664 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6665 {
6666 /* Remember where we are in case we need to backtrack. */
9c2799c2 6667 gas_assert (!backtrack_pos);
c19d1205
ZW
6668 backtrack_pos = str;
6669 backtrack_error = inst.error;
6670 backtrack_index = i;
6671 }
6672
b6702015 6673 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6674 po_char_or_fail (',');
6675
5be8be5d 6676 switch (op_parse_code)
c19d1205
ZW
6677 {
6678 /* Registers */
6679 case OP_oRRnpc:
5be8be5d 6680 case OP_oRRnpcsp:
c19d1205 6681 case OP_RRnpc:
5be8be5d 6682 case OP_RRnpcsp:
c19d1205
ZW
6683 case OP_oRR:
6684 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6685 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6686 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6687 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6688 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6689 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6690 case OP_oRND:
5287ad62 6691 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6692 case OP_RVC:
6693 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6694 break;
6695 /* Also accept generic coprocessor regs for unknown registers. */
6696 coproc_reg:
6697 po_reg_or_fail (REG_TYPE_CN);
6698 break;
c19d1205
ZW
6699 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6700 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6701 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6702 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6703 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6704 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6705 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6706 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6707 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6708 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6709 case OP_oRNQ:
5287ad62 6710 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6711 case OP_oRNDQ:
5287ad62 6712 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6713 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6714 case OP_oRNSDQ:
6715 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6716
6717 /* Neon scalar. Using an element size of 8 means that some invalid
6718 scalars are accepted here, so deal with those in later code. */
6719 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6720
6721 case OP_RNDQ_I0:
6722 {
6723 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6724 break;
6725 try_imm0:
6726 po_imm_or_fail (0, 0, TRUE);
6727 }
6728 break;
6729
6730 case OP_RVSD_I0:
6731 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6732 break;
6733
aacf0b33
KT
6734 case OP_RSVD_FI0:
6735 {
6736 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6737 break;
6738 try_ifimm0:
6739 if (parse_ifimm_zero (&str))
6740 inst.operands[i].imm = 0;
6741 else
6742 {
6743 inst.error
6744 = _("only floating point zero is allowed as immediate value");
6745 goto failure;
6746 }
6747 }
6748 break;
6749
477330fc
RM
6750 case OP_RR_RNSC:
6751 {
6752 po_scalar_or_goto (8, try_rr);
6753 break;
6754 try_rr:
6755 po_reg_or_fail (REG_TYPE_RN);
6756 }
6757 break;
6758
6759 case OP_RNSDQ_RNSC:
6760 {
6761 po_scalar_or_goto (8, try_nsdq);
6762 break;
6763 try_nsdq:
6764 po_reg_or_fail (REG_TYPE_NSDQ);
6765 }
6766 break;
6767
6768 case OP_RNDQ_RNSC:
6769 {
6770 po_scalar_or_goto (8, try_ndq);
6771 break;
6772 try_ndq:
6773 po_reg_or_fail (REG_TYPE_NDQ);
6774 }
6775 break;
6776
6777 case OP_RND_RNSC:
6778 {
6779 po_scalar_or_goto (8, try_vfd);
6780 break;
6781 try_vfd:
6782 po_reg_or_fail (REG_TYPE_VFD);
6783 }
6784 break;
6785
6786 case OP_VMOV:
6787 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6788 not careful then bad things might happen. */
6789 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6790 break;
6791
6792 case OP_RNDQ_Ibig:
6793 {
6794 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6795 break;
6796 try_immbig:
6797 /* There's a possibility of getting a 64-bit immediate here, so
6798 we need special handling. */
8335d6aa
JW
6799 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6800 == FAIL)
477330fc
RM
6801 {
6802 inst.error = _("immediate value is out of range");
6803 goto failure;
6804 }
6805 }
6806 break;
6807
6808 case OP_RNDQ_I63b:
6809 {
6810 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6811 break;
6812 try_shimm:
6813 po_imm_or_fail (0, 63, TRUE);
6814 }
6815 break;
c19d1205
ZW
6816
6817 case OP_RRnpcb:
6818 po_char_or_fail ('[');
6819 po_reg_or_fail (REG_TYPE_RN);
6820 po_char_or_fail (']');
6821 break;
a737bd4d 6822
55881a11 6823 case OP_RRnpctw:
c19d1205 6824 case OP_RRw:
b6702015 6825 case OP_oRRw:
c19d1205
ZW
6826 po_reg_or_fail (REG_TYPE_RN);
6827 if (skip_past_char (&str, '!') == SUCCESS)
6828 inst.operands[i].writeback = 1;
6829 break;
6830
6831 /* Immediates */
6832 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6833 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6834 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6835 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6836 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6837 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6838 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6839 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6840 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6841 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6842 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6843 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6844
6845 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6846 case OP_oI7b:
6847 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6848 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6849 case OP_oI31b:
6850 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6851 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6852 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6853 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6854
6855 /* Immediate variants */
6856 case OP_oI255c:
6857 po_char_or_fail ('{');
6858 po_imm_or_fail (0, 255, TRUE);
6859 po_char_or_fail ('}');
6860 break;
6861
6862 case OP_I31w:
6863 /* The expression parser chokes on a trailing !, so we have
6864 to find it first and zap it. */
6865 {
6866 char *s = str;
6867 while (*s && *s != ',')
6868 s++;
6869 if (s[-1] == '!')
6870 {
6871 s[-1] = '\0';
6872 inst.operands[i].writeback = 1;
6873 }
6874 po_imm_or_fail (0, 31, TRUE);
6875 if (str == s - 1)
6876 str = s;
6877 }
6878 break;
6879
6880 /* Expressions */
6881 case OP_EXPi: EXPi:
6882 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6883 GE_OPT_PREFIX));
6884 break;
6885
6886 case OP_EXP:
6887 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6888 GE_NO_PREFIX));
6889 break;
6890
6891 case OP_EXPr: EXPr:
6892 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6893 GE_NO_PREFIX));
6894 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6895 {
c19d1205
ZW
6896 val = parse_reloc (&str);
6897 if (val == -1)
6898 {
6899 inst.error = _("unrecognized relocation suffix");
6900 goto failure;
6901 }
6902 else if (val != BFD_RELOC_UNUSED)
6903 {
6904 inst.operands[i].imm = val;
6905 inst.operands[i].hasreloc = 1;
6906 }
a737bd4d 6907 }
c19d1205 6908 break;
a737bd4d 6909
b6895b4f
PB
6910 /* Operand for MOVW or MOVT. */
6911 case OP_HALF:
6912 po_misc_or_fail (parse_half (&str));
6913 break;
6914
e07e6e58 6915 /* Register or expression. */
c19d1205
ZW
6916 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6917 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6918
e07e6e58 6919 /* Register or immediate. */
c19d1205
ZW
6920 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6921 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6922
c19d1205
ZW
6923 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6924 IF:
6925 if (!is_immediate_prefix (*str))
6926 goto bad_args;
6927 str++;
6928 val = parse_fpa_immediate (&str);
6929 if (val == FAIL)
6930 goto failure;
6931 /* FPA immediates are encoded as registers 8-15.
6932 parse_fpa_immediate has already applied the offset. */
6933 inst.operands[i].reg = val;
6934 inst.operands[i].isreg = 1;
6935 break;
09d92015 6936
2d447fca
JM
6937 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6938 I32z: po_imm_or_fail (0, 32, FALSE); break;
6939
e07e6e58 6940 /* Two kinds of register. */
c19d1205
ZW
6941 case OP_RIWR_RIWC:
6942 {
6943 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6944 if (!rege
6945 || (rege->type != REG_TYPE_MMXWR
6946 && rege->type != REG_TYPE_MMXWC
6947 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6948 {
6949 inst.error = _("iWMMXt data or control register expected");
6950 goto failure;
6951 }
6952 inst.operands[i].reg = rege->number;
6953 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6954 }
6955 break;
09d92015 6956
41adaa5c
JM
6957 case OP_RIWC_RIWG:
6958 {
6959 struct reg_entry *rege = arm_reg_parse_multi (&str);
6960 if (!rege
6961 || (rege->type != REG_TYPE_MMXWC
6962 && rege->type != REG_TYPE_MMXWCG))
6963 {
6964 inst.error = _("iWMMXt control register expected");
6965 goto failure;
6966 }
6967 inst.operands[i].reg = rege->number;
6968 inst.operands[i].isreg = 1;
6969 }
6970 break;
6971
c19d1205
ZW
6972 /* Misc */
6973 case OP_CPSF: val = parse_cps_flags (&str); break;
6974 case OP_ENDI: val = parse_endian_specifier (&str); break;
6975 case OP_oROR: val = parse_ror (&str); break;
c19d1205 6976 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6977 case OP_oBARRIER_I15:
6978 po_barrier_or_imm (str); break;
6979 immediate:
6980 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 6981 goto failure;
52e7f43d 6982 break;
c19d1205 6983
fa94de6b 6984 case OP_wPSR:
d2cd1205 6985 case OP_rPSR:
90ec0d68
MGD
6986 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6987 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6988 {
6989 inst.error = _("Banked registers are not available with this "
6990 "architecture.");
6991 goto failure;
6992 }
6993 break;
d2cd1205
JB
6994 try_psr:
6995 val = parse_psr (&str, op_parse_code == OP_wPSR);
6996 break;
037e8744 6997
477330fc
RM
6998 case OP_APSR_RR:
6999 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7000 break;
7001 try_apsr:
7002 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7003 instruction). */
7004 if (strncasecmp (str, "APSR_", 5) == 0)
7005 {
7006 unsigned found = 0;
7007 str += 5;
7008 while (found < 15)
7009 switch (*str++)
7010 {
7011 case 'c': found = (found & 1) ? 16 : found | 1; break;
7012 case 'n': found = (found & 2) ? 16 : found | 2; break;
7013 case 'z': found = (found & 4) ? 16 : found | 4; break;
7014 case 'v': found = (found & 8) ? 16 : found | 8; break;
7015 default: found = 16;
7016 }
7017 if (found != 15)
7018 goto failure;
7019 inst.operands[i].isvec = 1;
f7c21dc7
NC
7020 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7021 inst.operands[i].reg = REG_PC;
477330fc
RM
7022 }
7023 else
7024 goto failure;
7025 break;
037e8744 7026
92e90b6e
PB
7027 case OP_TB:
7028 po_misc_or_fail (parse_tb (&str));
7029 break;
7030
e07e6e58 7031 /* Register lists. */
c19d1205
ZW
7032 case OP_REGLST:
7033 val = parse_reg_list (&str);
7034 if (*str == '^')
7035 {
5e0d7f77 7036 inst.operands[i].writeback = 1;
c19d1205
ZW
7037 str++;
7038 }
7039 break;
09d92015 7040
c19d1205 7041 case OP_VRSLST:
5287ad62 7042 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7043 break;
09d92015 7044
c19d1205 7045 case OP_VRDLST:
5287ad62 7046 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7047 break;
a737bd4d 7048
477330fc
RM
7049 case OP_VRSDLST:
7050 /* Allow Q registers too. */
7051 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7052 REGLIST_NEON_D);
7053 if (val == FAIL)
7054 {
7055 inst.error = NULL;
7056 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7057 REGLIST_VFP_S);
7058 inst.operands[i].issingle = 1;
7059 }
7060 break;
7061
7062 case OP_NRDLST:
7063 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7064 REGLIST_NEON_D);
7065 break;
5287ad62
JB
7066
7067 case OP_NSTRLST:
477330fc
RM
7068 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7069 &inst.operands[i].vectype);
7070 break;
5287ad62 7071
c19d1205
ZW
7072 /* Addressing modes */
7073 case OP_ADDR:
7074 po_misc_or_fail (parse_address (&str, i));
7075 break;
09d92015 7076
4962c51a
MS
7077 case OP_ADDRGLDR:
7078 po_misc_or_fail_no_backtrack (
477330fc 7079 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7080 break;
7081
7082 case OP_ADDRGLDRS:
7083 po_misc_or_fail_no_backtrack (
477330fc 7084 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7085 break;
7086
7087 case OP_ADDRGLDC:
7088 po_misc_or_fail_no_backtrack (
477330fc 7089 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7090 break;
7091
c19d1205
ZW
7092 case OP_SH:
7093 po_misc_or_fail (parse_shifter_operand (&str, i));
7094 break;
09d92015 7095
4962c51a
MS
7096 case OP_SHG:
7097 po_misc_or_fail_no_backtrack (
477330fc 7098 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7099 break;
7100
c19d1205
ZW
7101 case OP_oSHll:
7102 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7103 break;
09d92015 7104
c19d1205
ZW
7105 case OP_oSHar:
7106 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7107 break;
09d92015 7108
c19d1205
ZW
7109 case OP_oSHllar:
7110 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7111 break;
09d92015 7112
c19d1205 7113 default:
5be8be5d 7114 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7115 }
09d92015 7116
c19d1205
ZW
7117 /* Various value-based sanity checks and shared operations. We
7118 do not signal immediate failures for the register constraints;
7119 this allows a syntax error to take precedence. */
5be8be5d 7120 switch (op_parse_code)
c19d1205
ZW
7121 {
7122 case OP_oRRnpc:
7123 case OP_RRnpc:
7124 case OP_RRnpcb:
7125 case OP_RRw:
b6702015 7126 case OP_oRRw:
c19d1205
ZW
7127 case OP_RRnpc_I0:
7128 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7129 inst.error = BAD_PC;
7130 break;
09d92015 7131
5be8be5d
DG
7132 case OP_oRRnpcsp:
7133 case OP_RRnpcsp:
7134 if (inst.operands[i].isreg)
7135 {
7136 if (inst.operands[i].reg == REG_PC)
7137 inst.error = BAD_PC;
7138 else if (inst.operands[i].reg == REG_SP)
7139 inst.error = BAD_SP;
7140 }
7141 break;
7142
55881a11 7143 case OP_RRnpctw:
fa94de6b
RM
7144 if (inst.operands[i].isreg
7145 && inst.operands[i].reg == REG_PC
55881a11
MGD
7146 && (inst.operands[i].writeback || thumb))
7147 inst.error = BAD_PC;
7148 break;
7149
c19d1205
ZW
7150 case OP_CPSF:
7151 case OP_ENDI:
7152 case OP_oROR:
d2cd1205
JB
7153 case OP_wPSR:
7154 case OP_rPSR:
c19d1205 7155 case OP_COND:
52e7f43d 7156 case OP_oBARRIER_I15:
c19d1205
ZW
7157 case OP_REGLST:
7158 case OP_VRSLST:
7159 case OP_VRDLST:
477330fc
RM
7160 case OP_VRSDLST:
7161 case OP_NRDLST:
7162 case OP_NSTRLST:
c19d1205
ZW
7163 if (val == FAIL)
7164 goto failure;
7165 inst.operands[i].imm = val;
7166 break;
a737bd4d 7167
c19d1205
ZW
7168 default:
7169 break;
7170 }
09d92015 7171
c19d1205
ZW
7172 /* If we get here, this operand was successfully parsed. */
7173 inst.operands[i].present = 1;
7174 continue;
09d92015 7175
c19d1205 7176 bad_args:
09d92015 7177 inst.error = BAD_ARGS;
c19d1205
ZW
7178
7179 failure:
7180 if (!backtrack_pos)
d252fdde
PB
7181 {
7182 /* The parse routine should already have set inst.error, but set a
5f4273c7 7183 default here just in case. */
d252fdde
PB
7184 if (!inst.error)
7185 inst.error = _("syntax error");
7186 return FAIL;
7187 }
c19d1205
ZW
7188
7189 /* Do not backtrack over a trailing optional argument that
7190 absorbed some text. We will only fail again, with the
7191 'garbage following instruction' error message, which is
7192 probably less helpful than the current one. */
7193 if (backtrack_index == i && backtrack_pos != str
7194 && upat[i+1] == OP_stop)
d252fdde
PB
7195 {
7196 if (!inst.error)
7197 inst.error = _("syntax error");
7198 return FAIL;
7199 }
c19d1205
ZW
7200
7201 /* Try again, skipping the optional argument at backtrack_pos. */
7202 str = backtrack_pos;
7203 inst.error = backtrack_error;
7204 inst.operands[backtrack_index].present = 0;
7205 i = backtrack_index;
7206 backtrack_pos = 0;
09d92015 7207 }
09d92015 7208
c19d1205
ZW
7209 /* Check that we have parsed all the arguments. */
7210 if (*str != '\0' && !inst.error)
7211 inst.error = _("garbage following instruction");
09d92015 7212
c19d1205 7213 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7214}
7215
c19d1205
ZW
7216#undef po_char_or_fail
7217#undef po_reg_or_fail
7218#undef po_reg_or_goto
7219#undef po_imm_or_fail
5287ad62 7220#undef po_scalar_or_fail
52e7f43d 7221#undef po_barrier_or_imm
e07e6e58 7222
c19d1205 7223/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7224#define constraint(expr, err) \
7225 do \
c19d1205 7226 { \
e07e6e58
NC
7227 if (expr) \
7228 { \
7229 inst.error = err; \
7230 return; \
7231 } \
c19d1205 7232 } \
e07e6e58 7233 while (0)
c19d1205 7234
fdfde340
JM
7235/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7236 instructions are unpredictable if these registers are used. This
7237 is the BadReg predicate in ARM's Thumb-2 documentation. */
7238#define reject_bad_reg(reg) \
7239 do \
7240 if (reg == REG_SP || reg == REG_PC) \
7241 { \
7242 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
7243 return; \
7244 } \
7245 while (0)
7246
94206790
MM
7247/* If REG is R13 (the stack pointer), warn that its use is
7248 deprecated. */
7249#define warn_deprecated_sp(reg) \
7250 do \
7251 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7252 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7253 while (0)
7254
c19d1205
ZW
7255/* Functions for operand encoding. ARM, then Thumb. */
7256
d840c081 7257#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205
ZW
7258
7259/* If VAL can be encoded in the immediate field of an ARM instruction,
7260 return the encoded form. Otherwise, return FAIL. */
7261
7262static unsigned int
7263encode_arm_immediate (unsigned int val)
09d92015 7264{
c19d1205
ZW
7265 unsigned int a, i;
7266
7267 for (i = 0; i < 32; i += 2)
7268 if ((a = rotate_left (val, i)) <= 0xff)
7269 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7270
7271 return FAIL;
09d92015
MM
7272}
7273
c19d1205
ZW
7274/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7275 return the encoded form. Otherwise, return FAIL. */
7276static unsigned int
7277encode_thumb32_immediate (unsigned int val)
09d92015 7278{
c19d1205 7279 unsigned int a, i;
09d92015 7280
9c3c69f2 7281 if (val <= 0xff)
c19d1205 7282 return val;
a737bd4d 7283
9c3c69f2 7284 for (i = 1; i <= 24; i++)
09d92015 7285 {
9c3c69f2
PB
7286 a = val >> i;
7287 if ((val & ~(0xff << i)) == 0)
7288 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7289 }
a737bd4d 7290
c19d1205
ZW
7291 a = val & 0xff;
7292 if (val == ((a << 16) | a))
7293 return 0x100 | a;
7294 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7295 return 0x300 | a;
09d92015 7296
c19d1205
ZW
7297 a = val & 0xff00;
7298 if (val == ((a << 16) | a))
7299 return 0x200 | (a >> 8);
a737bd4d 7300
c19d1205 7301 return FAIL;
09d92015 7302}
5287ad62 7303/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7304
7305static void
5287ad62
JB
7306encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7307{
7308 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7309 && reg > 15)
7310 {
b1cc4aeb 7311 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7312 {
7313 if (thumb_mode)
7314 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7315 fpu_vfp_ext_d32);
7316 else
7317 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7318 fpu_vfp_ext_d32);
7319 }
5287ad62 7320 else
477330fc
RM
7321 {
7322 first_error (_("D register out of range for selected VFP version"));
7323 return;
7324 }
5287ad62
JB
7325 }
7326
c19d1205 7327 switch (pos)
09d92015 7328 {
c19d1205
ZW
7329 case VFP_REG_Sd:
7330 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7331 break;
7332
7333 case VFP_REG_Sn:
7334 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7335 break;
7336
7337 case VFP_REG_Sm:
7338 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7339 break;
7340
5287ad62
JB
7341 case VFP_REG_Dd:
7342 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7343 break;
5f4273c7 7344
5287ad62
JB
7345 case VFP_REG_Dn:
7346 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7347 break;
5f4273c7 7348
5287ad62
JB
7349 case VFP_REG_Dm:
7350 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7351 break;
7352
c19d1205
ZW
7353 default:
7354 abort ();
09d92015 7355 }
09d92015
MM
7356}
7357
c19d1205 7358/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7359 if any, is handled by md_apply_fix. */
09d92015 7360static void
c19d1205 7361encode_arm_shift (int i)
09d92015 7362{
c19d1205
ZW
7363 if (inst.operands[i].shift_kind == SHIFT_RRX)
7364 inst.instruction |= SHIFT_ROR << 5;
7365 else
09d92015 7366 {
c19d1205
ZW
7367 inst.instruction |= inst.operands[i].shift_kind << 5;
7368 if (inst.operands[i].immisreg)
7369 {
7370 inst.instruction |= SHIFT_BY_REG;
7371 inst.instruction |= inst.operands[i].imm << 8;
7372 }
7373 else
7374 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7375 }
c19d1205 7376}
09d92015 7377
c19d1205
ZW
7378static void
7379encode_arm_shifter_operand (int i)
7380{
7381 if (inst.operands[i].isreg)
09d92015 7382 {
c19d1205
ZW
7383 inst.instruction |= inst.operands[i].reg;
7384 encode_arm_shift (i);
09d92015 7385 }
c19d1205 7386 else
a415b1cd
JB
7387 {
7388 inst.instruction |= INST_IMMEDIATE;
7389 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7390 inst.instruction |= inst.operands[i].imm;
7391 }
09d92015
MM
7392}
7393
c19d1205 7394/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7395static void
c19d1205 7396encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7397{
2b2f5df9
NC
7398 /* PR 14260:
7399 Generate an error if the operand is not a register. */
7400 constraint (!inst.operands[i].isreg,
7401 _("Instruction does not support =N addresses"));
7402
c19d1205 7403 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7404
c19d1205 7405 if (inst.operands[i].preind)
09d92015 7406 {
c19d1205
ZW
7407 if (is_t)
7408 {
7409 inst.error = _("instruction does not accept preindexed addressing");
7410 return;
7411 }
7412 inst.instruction |= PRE_INDEX;
7413 if (inst.operands[i].writeback)
7414 inst.instruction |= WRITE_BACK;
09d92015 7415
c19d1205
ZW
7416 }
7417 else if (inst.operands[i].postind)
7418 {
9c2799c2 7419 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7420 if (is_t)
7421 inst.instruction |= WRITE_BACK;
7422 }
7423 else /* unindexed - only for coprocessor */
09d92015 7424 {
c19d1205 7425 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7426 return;
7427 }
7428
c19d1205
ZW
7429 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7430 && (((inst.instruction & 0x000f0000) >> 16)
7431 == ((inst.instruction & 0x0000f000) >> 12)))
7432 as_warn ((inst.instruction & LOAD_BIT)
7433 ? _("destination register same as write-back base")
7434 : _("source register same as write-back base"));
09d92015
MM
7435}
7436
c19d1205
ZW
7437/* inst.operands[i] was set up by parse_address. Encode it into an
7438 ARM-format mode 2 load or store instruction. If is_t is true,
7439 reject forms that cannot be used with a T instruction (i.e. not
7440 post-indexed). */
a737bd4d 7441static void
c19d1205 7442encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7443{
5be8be5d
DG
7444 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7445
c19d1205 7446 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7447
c19d1205 7448 if (inst.operands[i].immisreg)
09d92015 7449 {
5be8be5d
DG
7450 constraint ((inst.operands[i].imm == REG_PC
7451 || (is_pc && inst.operands[i].writeback)),
7452 BAD_PC_ADDRESSING);
c19d1205
ZW
7453 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7454 inst.instruction |= inst.operands[i].imm;
7455 if (!inst.operands[i].negative)
7456 inst.instruction |= INDEX_UP;
7457 if (inst.operands[i].shifted)
7458 {
7459 if (inst.operands[i].shift_kind == SHIFT_RRX)
7460 inst.instruction |= SHIFT_ROR << 5;
7461 else
7462 {
7463 inst.instruction |= inst.operands[i].shift_kind << 5;
7464 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7465 }
7466 }
09d92015 7467 }
c19d1205 7468 else /* immediate offset in inst.reloc */
09d92015 7469 {
5be8be5d
DG
7470 if (is_pc && !inst.reloc.pc_rel)
7471 {
7472 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7473
7474 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7475 cannot use PC in addressing.
7476 PC cannot be used in writeback addressing, either. */
7477 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7478 BAD_PC_ADDRESSING);
23a10334 7479
dc5ec521 7480 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7481 if (warn_on_deprecated
7482 && !is_load
7483 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7484 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7485 }
7486
c19d1205 7487 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7488 {
7489 /* Prefer + for zero encoded value. */
7490 if (!inst.operands[i].negative)
7491 inst.instruction |= INDEX_UP;
7492 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7493 }
09d92015 7494 }
09d92015
MM
7495}
7496
c19d1205
ZW
7497/* inst.operands[i] was set up by parse_address. Encode it into an
7498 ARM-format mode 3 load or store instruction. Reject forms that
7499 cannot be used with such instructions. If is_t is true, reject
7500 forms that cannot be used with a T instruction (i.e. not
7501 post-indexed). */
7502static void
7503encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7504{
c19d1205 7505 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7506 {
c19d1205
ZW
7507 inst.error = _("instruction does not accept scaled register index");
7508 return;
09d92015 7509 }
a737bd4d 7510
c19d1205 7511 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7512
c19d1205
ZW
7513 if (inst.operands[i].immisreg)
7514 {
5be8be5d 7515 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7516 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7517 BAD_PC_ADDRESSING);
eb9f3f00
JB
7518 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7519 BAD_PC_WRITEBACK);
c19d1205
ZW
7520 inst.instruction |= inst.operands[i].imm;
7521 if (!inst.operands[i].negative)
7522 inst.instruction |= INDEX_UP;
7523 }
7524 else /* immediate offset in inst.reloc */
7525 {
5be8be5d
DG
7526 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7527 && inst.operands[i].writeback),
7528 BAD_PC_WRITEBACK);
c19d1205
ZW
7529 inst.instruction |= HWOFFSET_IMM;
7530 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7531 {
7532 /* Prefer + for zero encoded value. */
7533 if (!inst.operands[i].negative)
7534 inst.instruction |= INDEX_UP;
7535
7536 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7537 }
c19d1205 7538 }
a737bd4d
NC
7539}
7540
8335d6aa
JW
7541/* Write immediate bits [7:0] to the following locations:
7542
7543 |28/24|23 19|18 16|15 4|3 0|
7544 | 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|
7545
7546 This function is used by VMOV/VMVN/VORR/VBIC. */
7547
7548static void
7549neon_write_immbits (unsigned immbits)
7550{
7551 inst.instruction |= immbits & 0xf;
7552 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7553 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7554}
7555
7556/* Invert low-order SIZE bits of XHI:XLO. */
7557
7558static void
7559neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7560{
7561 unsigned immlo = xlo ? *xlo : 0;
7562 unsigned immhi = xhi ? *xhi : 0;
7563
7564 switch (size)
7565 {
7566 case 8:
7567 immlo = (~immlo) & 0xff;
7568 break;
7569
7570 case 16:
7571 immlo = (~immlo) & 0xffff;
7572 break;
7573
7574 case 64:
7575 immhi = (~immhi) & 0xffffffff;
7576 /* fall through. */
7577
7578 case 32:
7579 immlo = (~immlo) & 0xffffffff;
7580 break;
7581
7582 default:
7583 abort ();
7584 }
7585
7586 if (xlo)
7587 *xlo = immlo;
7588
7589 if (xhi)
7590 *xhi = immhi;
7591}
7592
7593/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7594 A, B, C, D. */
09d92015 7595
c19d1205 7596static int
8335d6aa 7597neon_bits_same_in_bytes (unsigned imm)
09d92015 7598{
8335d6aa
JW
7599 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7600 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7601 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7602 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7603}
a737bd4d 7604
8335d6aa 7605/* For immediate of above form, return 0bABCD. */
09d92015 7606
8335d6aa
JW
7607static unsigned
7608neon_squash_bits (unsigned imm)
7609{
7610 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7611 | ((imm & 0x01000000) >> 21);
7612}
7613
7614/* Compress quarter-float representation to 0b...000 abcdefgh. */
7615
7616static unsigned
7617neon_qfloat_bits (unsigned imm)
7618{
7619 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7620}
7621
7622/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7623 the instruction. *OP is passed as the initial value of the op field, and
7624 may be set to a different value depending on the constant (i.e.
7625 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7626 MVN). If the immediate looks like a repeated pattern then also
7627 try smaller element sizes. */
7628
7629static int
7630neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7631 unsigned *immbits, int *op, int size,
7632 enum neon_el_type type)
7633{
7634 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7635 float. */
7636 if (type == NT_float && !float_p)
7637 return FAIL;
7638
7639 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7640 {
8335d6aa
JW
7641 if (size != 32 || *op == 1)
7642 return FAIL;
7643 *immbits = neon_qfloat_bits (immlo);
7644 return 0xf;
7645 }
7646
7647 if (size == 64)
7648 {
7649 if (neon_bits_same_in_bytes (immhi)
7650 && neon_bits_same_in_bytes (immlo))
c19d1205 7651 {
8335d6aa
JW
7652 if (*op == 1)
7653 return FAIL;
7654 *immbits = (neon_squash_bits (immhi) << 4)
7655 | neon_squash_bits (immlo);
7656 *op = 1;
7657 return 0xe;
c19d1205 7658 }
a737bd4d 7659
8335d6aa
JW
7660 if (immhi != immlo)
7661 return FAIL;
7662 }
a737bd4d 7663
8335d6aa 7664 if (size >= 32)
09d92015 7665 {
8335d6aa 7666 if (immlo == (immlo & 0x000000ff))
c19d1205 7667 {
8335d6aa
JW
7668 *immbits = immlo;
7669 return 0x0;
c19d1205 7670 }
8335d6aa 7671 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7672 {
8335d6aa
JW
7673 *immbits = immlo >> 8;
7674 return 0x2;
c19d1205 7675 }
8335d6aa
JW
7676 else if (immlo == (immlo & 0x00ff0000))
7677 {
7678 *immbits = immlo >> 16;
7679 return 0x4;
7680 }
7681 else if (immlo == (immlo & 0xff000000))
7682 {
7683 *immbits = immlo >> 24;
7684 return 0x6;
7685 }
7686 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7687 {
7688 *immbits = (immlo >> 8) & 0xff;
7689 return 0xc;
7690 }
7691 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7692 {
7693 *immbits = (immlo >> 16) & 0xff;
7694 return 0xd;
7695 }
7696
7697 if ((immlo & 0xffff) != (immlo >> 16))
7698 return FAIL;
7699 immlo &= 0xffff;
09d92015 7700 }
a737bd4d 7701
8335d6aa 7702 if (size >= 16)
4962c51a 7703 {
8335d6aa
JW
7704 if (immlo == (immlo & 0x000000ff))
7705 {
7706 *immbits = immlo;
7707 return 0x8;
7708 }
7709 else if (immlo == (immlo & 0x0000ff00))
7710 {
7711 *immbits = immlo >> 8;
7712 return 0xa;
7713 }
7714
7715 if ((immlo & 0xff) != (immlo >> 8))
7716 return FAIL;
7717 immlo &= 0xff;
4962c51a
MS
7718 }
7719
8335d6aa
JW
7720 if (immlo == (immlo & 0x000000ff))
7721 {
7722 /* Don't allow MVN with 8-bit immediate. */
7723 if (*op == 1)
7724 return FAIL;
7725 *immbits = immlo;
7726 return 0xe;
7727 }
26d97720 7728
8335d6aa 7729 return FAIL;
c19d1205 7730}
a737bd4d 7731
5fc177c8 7732#if defined BFD_HOST_64_BIT
ba592044
AM
7733/* Returns TRUE if double precision value V may be cast
7734 to single precision without loss of accuracy. */
7735
7736static bfd_boolean
5fc177c8 7737is_double_a_single (bfd_int64_t v)
ba592044 7738{
5fc177c8 7739 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7740 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7741
7742 return (exp == 0 || exp == 0x7FF
7743 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7744 && (mantissa & 0x1FFFFFFFl) == 0;
7745}
7746
3739860c 7747/* Returns a double precision value casted to single precision
ba592044
AM
7748 (ignoring the least significant bits in exponent and mantissa). */
7749
7750static int
5fc177c8 7751double_to_single (bfd_int64_t v)
ba592044
AM
7752{
7753 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7754 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7755 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7756
7757 if (exp == 0x7FF)
7758 exp = 0xFF;
7759 else
7760 {
7761 exp = exp - 1023 + 127;
7762 if (exp >= 0xFF)
7763 {
7764 /* Infinity. */
7765 exp = 0x7F;
7766 mantissa = 0;
7767 }
7768 else if (exp < 0)
7769 {
7770 /* No denormalized numbers. */
7771 exp = 0;
7772 mantissa = 0;
7773 }
7774 }
7775 mantissa >>= 29;
7776 return (sign << 31) | (exp << 23) | mantissa;
7777}
5fc177c8 7778#endif /* BFD_HOST_64_BIT */
ba592044 7779
8335d6aa
JW
7780enum lit_type
7781{
7782 CONST_THUMB,
7783 CONST_ARM,
7784 CONST_VEC
7785};
7786
ba592044
AM
7787static void do_vfp_nsyn_opcode (const char *);
7788
c19d1205
ZW
7789/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7790 Determine whether it can be performed with a move instruction; if
7791 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7792 return TRUE; if it can't, convert inst.instruction to a literal-pool
7793 load and return FALSE. If this is not a valid thing to do in the
7794 current context, set inst.error and return TRUE.
a737bd4d 7795
c19d1205
ZW
7796 inst.operands[i] describes the destination register. */
7797
c921be7d 7798static bfd_boolean
8335d6aa 7799move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7800{
53365c0d 7801 unsigned long tbit;
8335d6aa
JW
7802 bfd_boolean thumb_p = (t == CONST_THUMB);
7803 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7804
7805 if (thumb_p)
7806 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7807 else
7808 tbit = LOAD_BIT;
7809
7810 if ((inst.instruction & tbit) == 0)
09d92015 7811 {
c19d1205 7812 inst.error = _("invalid pseudo operation");
c921be7d 7813 return TRUE;
09d92015 7814 }
ba592044 7815
8335d6aa
JW
7816 if (inst.reloc.exp.X_op != O_constant
7817 && inst.reloc.exp.X_op != O_symbol
7818 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7819 {
7820 inst.error = _("constant expression expected");
c921be7d 7821 return TRUE;
09d92015 7822 }
ba592044
AM
7823
7824 if (inst.reloc.exp.X_op == O_constant
7825 || inst.reloc.exp.X_op == O_big)
8335d6aa 7826 {
5fc177c8
NC
7827#if defined BFD_HOST_64_BIT
7828 bfd_int64_t v;
7829#else
ba592044 7830 offsetT v;
5fc177c8 7831#endif
ba592044 7832 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7833 {
ba592044
AM
7834 LITTLENUM_TYPE w[X_PRECISION];
7835 LITTLENUM_TYPE * l;
7836
7837 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7838 {
ba592044
AM
7839 gen_to_words (w, X_PRECISION, E_PRECISION);
7840 l = w;
7841 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7842 }
ba592044
AM
7843 else
7844 l = generic_bignum;
3739860c 7845
5fc177c8
NC
7846#if defined BFD_HOST_64_BIT
7847 v =
7848 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7849 << LITTLENUM_NUMBER_OF_BITS)
7850 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7851 << LITTLENUM_NUMBER_OF_BITS)
7852 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7853 << LITTLENUM_NUMBER_OF_BITS)
7854 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7855#else
ba592044
AM
7856 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7857 | (l[0] & LITTLENUM_MASK);
5fc177c8 7858#endif
8335d6aa 7859 }
ba592044
AM
7860 else
7861 v = inst.reloc.exp.X_add_number;
7862
7863 if (!inst.operands[i].issingle)
8335d6aa 7864 {
12569877 7865 if (thumb_p)
8335d6aa 7866 {
2c32be70
CM
7867 /* This can be encoded only for a low register. */
7868 if ((v & ~0xFF) == 0 && (inst.operands[i].reg < 8))
ba592044
AM
7869 {
7870 /* This can be done with a mov(1) instruction. */
7871 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7872 inst.instruction |= v;
7873 return TRUE;
7874 }
12569877 7875
fc289b0a 7876 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 7877 {
fc289b0a
TP
7878 /* Check if on thumb2 it can be done with a mov.w, mvn or
7879 movw instruction. */
12569877
AM
7880 unsigned int newimm;
7881 bfd_boolean isNegated;
7882
7883 newimm = encode_thumb32_immediate (v);
7884 if (newimm != (unsigned int) FAIL)
7885 isNegated = FALSE;
7886 else
7887 {
582cfe03 7888 newimm = encode_thumb32_immediate (~v);
12569877
AM
7889 if (newimm != (unsigned int) FAIL)
7890 isNegated = TRUE;
7891 }
7892
fc289b0a
TP
7893 /* The number can be loaded with a mov.w or mvn
7894 instruction. */
12569877
AM
7895 if (newimm != (unsigned int) FAIL)
7896 {
fc289b0a 7897 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 7898 | (inst.operands[i].reg << 8));
fc289b0a 7899 /* Change to MOVN. */
582cfe03 7900 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
7901 inst.instruction |= (newimm & 0x800) << 15;
7902 inst.instruction |= (newimm & 0x700) << 4;
7903 inst.instruction |= (newimm & 0x0ff);
7904 return TRUE;
7905 }
fc289b0a 7906 /* The number can be loaded with a movw instruction. */
582cfe03 7907 else if ((v & ~0xFFFF) == 0)
3739860c 7908 {
582cfe03 7909 int imm = v & 0xFFFF;
12569877 7910
582cfe03 7911 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
7912 inst.instruction |= (inst.operands[i].reg << 8);
7913 inst.instruction |= (imm & 0xf000) << 4;
7914 inst.instruction |= (imm & 0x0800) << 15;
7915 inst.instruction |= (imm & 0x0700) << 4;
7916 inst.instruction |= (imm & 0x00ff);
7917 return TRUE;
7918 }
7919 }
8335d6aa 7920 }
12569877 7921 else if (arm_p)
ba592044
AM
7922 {
7923 int value = encode_arm_immediate (v);
12569877 7924
ba592044
AM
7925 if (value != FAIL)
7926 {
7927 /* This can be done with a mov instruction. */
7928 inst.instruction &= LITERAL_MASK;
7929 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7930 inst.instruction |= value & 0xfff;
7931 return TRUE;
7932 }
8335d6aa 7933
ba592044
AM
7934 value = encode_arm_immediate (~ v);
7935 if (value != FAIL)
7936 {
7937 /* This can be done with a mvn instruction. */
7938 inst.instruction &= LITERAL_MASK;
7939 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7940 inst.instruction |= value & 0xfff;
7941 return TRUE;
7942 }
7943 }
7944 else if (t == CONST_VEC)
8335d6aa 7945 {
ba592044
AM
7946 int op = 0;
7947 unsigned immbits = 0;
7948 unsigned immlo = inst.operands[1].imm;
7949 unsigned immhi = inst.operands[1].regisimm
7950 ? inst.operands[1].reg
7951 : inst.reloc.exp.X_unsigned
7952 ? 0
7953 : ((bfd_int64_t)((int) immlo)) >> 32;
7954 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
7955 &op, 64, NT_invtype);
7956
7957 if (cmode == FAIL)
7958 {
7959 neon_invert_size (&immlo, &immhi, 64);
7960 op = !op;
7961 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
7962 &op, 64, NT_invtype);
7963 }
7964
7965 if (cmode != FAIL)
7966 {
7967 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
7968 | (1 << 23)
7969 | (cmode << 8)
7970 | (op << 5)
7971 | (1 << 4);
7972
7973 /* Fill other bits in vmov encoding for both thumb and arm. */
7974 if (thumb_mode)
eff0bc54 7975 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 7976 else
eff0bc54 7977 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
7978 neon_write_immbits (immbits);
7979 return TRUE;
7980 }
8335d6aa
JW
7981 }
7982 }
8335d6aa 7983
ba592044
AM
7984 if (t == CONST_VEC)
7985 {
7986 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
7987 if (inst.operands[i].issingle
7988 && is_quarter_float (inst.operands[1].imm)
7989 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 7990 {
ba592044
AM
7991 inst.operands[1].imm =
7992 neon_qfloat_bits (v);
7993 do_vfp_nsyn_opcode ("fconsts");
7994 return TRUE;
8335d6aa 7995 }
5fc177c8
NC
7996
7997 /* If our host does not support a 64-bit type then we cannot perform
7998 the following optimization. This mean that there will be a
7999 discrepancy between the output produced by an assembler built for
8000 a 32-bit-only host and the output produced from a 64-bit host, but
8001 this cannot be helped. */
8002#if defined BFD_HOST_64_BIT
ba592044
AM
8003 else if (!inst.operands[1].issingle
8004 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8005 {
ba592044
AM
8006 if (is_double_a_single (v)
8007 && is_quarter_float (double_to_single (v)))
8008 {
8009 inst.operands[1].imm =
8010 neon_qfloat_bits (double_to_single (v));
8011 do_vfp_nsyn_opcode ("fconstd");
8012 return TRUE;
8013 }
8335d6aa 8014 }
5fc177c8 8015#endif
8335d6aa
JW
8016 }
8017 }
8018
8019 if (add_to_lit_pool ((!inst.operands[i].isvec
8020 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8021 return TRUE;
8022
8023 inst.operands[1].reg = REG_PC;
8024 inst.operands[1].isreg = 1;
8025 inst.operands[1].preind = 1;
8026 inst.reloc.pc_rel = 1;
8027 inst.reloc.type = (thumb_p
8028 ? BFD_RELOC_ARM_THUMB_OFFSET
8029 : (mode_3
8030 ? BFD_RELOC_ARM_HWLITERAL
8031 : BFD_RELOC_ARM_LITERAL));
8032 return FALSE;
8033}
8034
8035/* inst.operands[i] was set up by parse_address. Encode it into an
8036 ARM-format instruction. Reject all forms which cannot be encoded
8037 into a coprocessor load/store instruction. If wb_ok is false,
8038 reject use of writeback; if unind_ok is false, reject use of
8039 unindexed addressing. If reloc_override is not 0, use it instead
8040 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8041 (in which case it is preserved). */
8042
8043static int
8044encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8045{
8046 if (!inst.operands[i].isreg)
8047 {
99b2a2dd
NC
8048 /* PR 18256 */
8049 if (! inst.operands[0].isvec)
8050 {
8051 inst.error = _("invalid co-processor operand");
8052 return FAIL;
8053 }
8335d6aa
JW
8054 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8055 return SUCCESS;
8056 }
8057
8058 inst.instruction |= inst.operands[i].reg << 16;
8059
8060 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8061
8062 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8063 {
8064 gas_assert (!inst.operands[i].writeback);
8065 if (!unind_ok)
8066 {
8067 inst.error = _("instruction does not support unindexed addressing");
8068 return FAIL;
8069 }
8070 inst.instruction |= inst.operands[i].imm;
8071 inst.instruction |= INDEX_UP;
8072 return SUCCESS;
8073 }
8074
8075 if (inst.operands[i].preind)
8076 inst.instruction |= PRE_INDEX;
8077
8078 if (inst.operands[i].writeback)
09d92015 8079 {
8335d6aa 8080 if (inst.operands[i].reg == REG_PC)
c19d1205 8081 {
8335d6aa
JW
8082 inst.error = _("pc may not be used with write-back");
8083 return FAIL;
c19d1205 8084 }
8335d6aa 8085 if (!wb_ok)
c19d1205 8086 {
8335d6aa
JW
8087 inst.error = _("instruction does not support writeback");
8088 return FAIL;
c19d1205 8089 }
8335d6aa 8090 inst.instruction |= WRITE_BACK;
09d92015
MM
8091 }
8092
8335d6aa
JW
8093 if (reloc_override)
8094 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8095 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8096 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8097 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8098 {
8335d6aa
JW
8099 if (thumb_mode)
8100 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8101 else
8102 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8103 }
8335d6aa
JW
8104
8105 /* Prefer + for zero encoded value. */
8106 if (!inst.operands[i].negative)
8107 inst.instruction |= INDEX_UP;
8108
8109 return SUCCESS;
09d92015
MM
8110}
8111
5f4273c7 8112/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8113 First some generics; their names are taken from the conventional
8114 bit positions for register arguments in ARM format instructions. */
09d92015 8115
a737bd4d 8116static void
c19d1205 8117do_noargs (void)
09d92015 8118{
c19d1205 8119}
a737bd4d 8120
c19d1205
ZW
8121static void
8122do_rd (void)
8123{
8124 inst.instruction |= inst.operands[0].reg << 12;
8125}
a737bd4d 8126
c19d1205
ZW
8127static void
8128do_rd_rm (void)
8129{
8130 inst.instruction |= inst.operands[0].reg << 12;
8131 inst.instruction |= inst.operands[1].reg;
8132}
09d92015 8133
9eb6c0f1
MGD
8134static void
8135do_rm_rn (void)
8136{
8137 inst.instruction |= inst.operands[0].reg;
8138 inst.instruction |= inst.operands[1].reg << 16;
8139}
8140
c19d1205
ZW
8141static void
8142do_rd_rn (void)
8143{
8144 inst.instruction |= inst.operands[0].reg << 12;
8145 inst.instruction |= inst.operands[1].reg << 16;
8146}
a737bd4d 8147
c19d1205
ZW
8148static void
8149do_rn_rd (void)
8150{
8151 inst.instruction |= inst.operands[0].reg << 16;
8152 inst.instruction |= inst.operands[1].reg << 12;
8153}
09d92015 8154
4ed7ed8d
TP
8155static void
8156do_tt (void)
8157{
8158 inst.instruction |= inst.operands[0].reg << 8;
8159 inst.instruction |= inst.operands[1].reg << 16;
8160}
8161
59d09be6
MGD
8162static bfd_boolean
8163check_obsolete (const arm_feature_set *feature, const char *msg)
8164{
8165 if (ARM_CPU_IS_ANY (cpu_variant))
8166 {
5c3696f8 8167 as_tsktsk ("%s", msg);
59d09be6
MGD
8168 return TRUE;
8169 }
8170 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8171 {
8172 as_bad ("%s", msg);
8173 return TRUE;
8174 }
8175
8176 return FALSE;
8177}
8178
c19d1205
ZW
8179static void
8180do_rd_rm_rn (void)
8181{
9a64e435 8182 unsigned Rn = inst.operands[2].reg;
708587a4 8183 /* Enforce restrictions on SWP instruction. */
9a64e435 8184 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8185 {
8186 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8187 _("Rn must not overlap other operands"));
8188
59d09be6
MGD
8189 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8190 */
8191 if (!check_obsolete (&arm_ext_v8,
8192 _("swp{b} use is obsoleted for ARMv8 and later"))
8193 && warn_on_deprecated
8194 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8195 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8196 }
59d09be6 8197
c19d1205
ZW
8198 inst.instruction |= inst.operands[0].reg << 12;
8199 inst.instruction |= inst.operands[1].reg;
9a64e435 8200 inst.instruction |= Rn << 16;
c19d1205 8201}
09d92015 8202
c19d1205
ZW
8203static void
8204do_rd_rn_rm (void)
8205{
8206 inst.instruction |= inst.operands[0].reg << 12;
8207 inst.instruction |= inst.operands[1].reg << 16;
8208 inst.instruction |= inst.operands[2].reg;
8209}
a737bd4d 8210
c19d1205
ZW
8211static void
8212do_rm_rd_rn (void)
8213{
5be8be5d
DG
8214 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8215 constraint (((inst.reloc.exp.X_op != O_constant
8216 && inst.reloc.exp.X_op != O_illegal)
8217 || inst.reloc.exp.X_add_number != 0),
8218 BAD_ADDR_MODE);
c19d1205
ZW
8219 inst.instruction |= inst.operands[0].reg;
8220 inst.instruction |= inst.operands[1].reg << 12;
8221 inst.instruction |= inst.operands[2].reg << 16;
8222}
09d92015 8223
c19d1205
ZW
8224static void
8225do_imm0 (void)
8226{
8227 inst.instruction |= inst.operands[0].imm;
8228}
09d92015 8229
c19d1205
ZW
8230static void
8231do_rd_cpaddr (void)
8232{
8233 inst.instruction |= inst.operands[0].reg << 12;
8234 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8235}
a737bd4d 8236
c19d1205
ZW
8237/* ARM instructions, in alphabetical order by function name (except
8238 that wrapper functions appear immediately after the function they
8239 wrap). */
09d92015 8240
c19d1205
ZW
8241/* This is a pseudo-op of the form "adr rd, label" to be converted
8242 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8243
8244static void
c19d1205 8245do_adr (void)
09d92015 8246{
c19d1205 8247 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8248
c19d1205
ZW
8249 /* Frag hacking will turn this into a sub instruction if the offset turns
8250 out to be negative. */
8251 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8252 inst.reloc.pc_rel = 1;
2fc8bdac 8253 inst.reloc.exp.X_add_number -= 8;
c19d1205 8254}
b99bd4ef 8255
c19d1205
ZW
8256/* This is a pseudo-op of the form "adrl rd, label" to be converted
8257 into a relative address of the form:
8258 add rd, pc, #low(label-.-8)"
8259 add rd, rd, #high(label-.-8)" */
b99bd4ef 8260
c19d1205
ZW
8261static void
8262do_adrl (void)
8263{
8264 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8265
c19d1205
ZW
8266 /* Frag hacking will turn this into a sub instruction if the offset turns
8267 out to be negative. */
8268 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8269 inst.reloc.pc_rel = 1;
8270 inst.size = INSN_SIZE * 2;
2fc8bdac 8271 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
8272}
8273
b99bd4ef 8274static void
c19d1205 8275do_arit (void)
b99bd4ef 8276{
c19d1205
ZW
8277 if (!inst.operands[1].present)
8278 inst.operands[1].reg = inst.operands[0].reg;
8279 inst.instruction |= inst.operands[0].reg << 12;
8280 inst.instruction |= inst.operands[1].reg << 16;
8281 encode_arm_shifter_operand (2);
8282}
b99bd4ef 8283
62b3e311
PB
8284static void
8285do_barrier (void)
8286{
8287 if (inst.operands[0].present)
ccb84d65 8288 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8289 else
8290 inst.instruction |= 0xf;
8291}
8292
c19d1205
ZW
8293static void
8294do_bfc (void)
8295{
8296 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8297 constraint (msb > 32, _("bit-field extends past end of register"));
8298 /* The instruction encoding stores the LSB and MSB,
8299 not the LSB and width. */
8300 inst.instruction |= inst.operands[0].reg << 12;
8301 inst.instruction |= inst.operands[1].imm << 7;
8302 inst.instruction |= (msb - 1) << 16;
8303}
b99bd4ef 8304
c19d1205
ZW
8305static void
8306do_bfi (void)
8307{
8308 unsigned int msb;
b99bd4ef 8309
c19d1205
ZW
8310 /* #0 in second position is alternative syntax for bfc, which is
8311 the same instruction but with REG_PC in the Rm field. */
8312 if (!inst.operands[1].isreg)
8313 inst.operands[1].reg = REG_PC;
b99bd4ef 8314
c19d1205
ZW
8315 msb = inst.operands[2].imm + inst.operands[3].imm;
8316 constraint (msb > 32, _("bit-field extends past end of register"));
8317 /* The instruction encoding stores the LSB and MSB,
8318 not the LSB and width. */
8319 inst.instruction |= inst.operands[0].reg << 12;
8320 inst.instruction |= inst.operands[1].reg;
8321 inst.instruction |= inst.operands[2].imm << 7;
8322 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8323}
8324
b99bd4ef 8325static void
c19d1205 8326do_bfx (void)
b99bd4ef 8327{
c19d1205
ZW
8328 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8329 _("bit-field extends past end of register"));
8330 inst.instruction |= inst.operands[0].reg << 12;
8331 inst.instruction |= inst.operands[1].reg;
8332 inst.instruction |= inst.operands[2].imm << 7;
8333 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8334}
09d92015 8335
c19d1205
ZW
8336/* ARM V5 breakpoint instruction (argument parse)
8337 BKPT <16 bit unsigned immediate>
8338 Instruction is not conditional.
8339 The bit pattern given in insns[] has the COND_ALWAYS condition,
8340 and it is an error if the caller tried to override that. */
b99bd4ef 8341
c19d1205
ZW
8342static void
8343do_bkpt (void)
8344{
8345 /* Top 12 of 16 bits to bits 19:8. */
8346 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8347
c19d1205
ZW
8348 /* Bottom 4 of 16 bits to bits 3:0. */
8349 inst.instruction |= inst.operands[0].imm & 0xf;
8350}
09d92015 8351
c19d1205
ZW
8352static void
8353encode_branch (int default_reloc)
8354{
8355 if (inst.operands[0].hasreloc)
8356 {
0855e32b
NS
8357 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8358 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8359 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8360 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8361 ? BFD_RELOC_ARM_PLT32
8362 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8363 }
b99bd4ef 8364 else
9ae92b05 8365 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8366 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8367}
8368
b99bd4ef 8369static void
c19d1205 8370do_branch (void)
b99bd4ef 8371{
39b41c9c
PB
8372#ifdef OBJ_ELF
8373 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8374 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8375 else
8376#endif
8377 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8378}
8379
8380static void
8381do_bl (void)
8382{
8383#ifdef OBJ_ELF
8384 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8385 {
8386 if (inst.cond == COND_ALWAYS)
8387 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8388 else
8389 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8390 }
8391 else
8392#endif
8393 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8394}
b99bd4ef 8395
c19d1205
ZW
8396/* ARM V5 branch-link-exchange instruction (argument parse)
8397 BLX <target_addr> ie BLX(1)
8398 BLX{<condition>} <Rm> ie BLX(2)
8399 Unfortunately, there are two different opcodes for this mnemonic.
8400 So, the insns[].value is not used, and the code here zaps values
8401 into inst.instruction.
8402 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8403
c19d1205
ZW
8404static void
8405do_blx (void)
8406{
8407 if (inst.operands[0].isreg)
b99bd4ef 8408 {
c19d1205
ZW
8409 /* Arg is a register; the opcode provided by insns[] is correct.
8410 It is not illegal to do "blx pc", just useless. */
8411 if (inst.operands[0].reg == REG_PC)
8412 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8413
c19d1205
ZW
8414 inst.instruction |= inst.operands[0].reg;
8415 }
8416 else
b99bd4ef 8417 {
c19d1205 8418 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8419 conditionally, and the opcode must be adjusted.
8420 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8421 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8422 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8423 inst.instruction = 0xfa000000;
267bf995 8424 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8425 }
c19d1205
ZW
8426}
8427
8428static void
8429do_bx (void)
8430{
845b51d6
PB
8431 bfd_boolean want_reloc;
8432
c19d1205
ZW
8433 if (inst.operands[0].reg == REG_PC)
8434 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8435
c19d1205 8436 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8437 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8438 it is for ARMv4t or earlier. */
8439 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8440 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8441 want_reloc = TRUE;
8442
5ad34203 8443#ifdef OBJ_ELF
845b51d6 8444 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8445#endif
584206db 8446 want_reloc = FALSE;
845b51d6
PB
8447
8448 if (want_reloc)
8449 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8450}
8451
c19d1205
ZW
8452
8453/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8454
8455static void
c19d1205 8456do_bxj (void)
a737bd4d 8457{
c19d1205
ZW
8458 if (inst.operands[0].reg == REG_PC)
8459 as_tsktsk (_("use of r15 in bxj is not really useful"));
8460
8461 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8462}
8463
c19d1205
ZW
8464/* Co-processor data operation:
8465 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8466 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8467static void
8468do_cdp (void)
8469{
8470 inst.instruction |= inst.operands[0].reg << 8;
8471 inst.instruction |= inst.operands[1].imm << 20;
8472 inst.instruction |= inst.operands[2].reg << 12;
8473 inst.instruction |= inst.operands[3].reg << 16;
8474 inst.instruction |= inst.operands[4].reg;
8475 inst.instruction |= inst.operands[5].imm << 5;
8476}
a737bd4d
NC
8477
8478static void
c19d1205 8479do_cmp (void)
a737bd4d 8480{
c19d1205
ZW
8481 inst.instruction |= inst.operands[0].reg << 16;
8482 encode_arm_shifter_operand (1);
a737bd4d
NC
8483}
8484
c19d1205
ZW
8485/* Transfer between coprocessor and ARM registers.
8486 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8487 MRC2
8488 MCR{cond}
8489 MCR2
8490
8491 No special properties. */
09d92015 8492
dcbd0d71
MGD
8493struct deprecated_coproc_regs_s
8494{
8495 unsigned cp;
8496 int opc1;
8497 unsigned crn;
8498 unsigned crm;
8499 int opc2;
8500 arm_feature_set deprecated;
8501 arm_feature_set obsoleted;
8502 const char *dep_msg;
8503 const char *obs_msg;
8504};
8505
8506#define DEPR_ACCESS_V8 \
8507 N_("This coprocessor register access is deprecated in ARMv8")
8508
8509/* Table of all deprecated coprocessor registers. */
8510static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8511{
8512 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8513 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8514 DEPR_ACCESS_V8, NULL},
8515 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8516 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8517 DEPR_ACCESS_V8, NULL},
8518 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8519 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8520 DEPR_ACCESS_V8, NULL},
8521 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8522 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8523 DEPR_ACCESS_V8, NULL},
8524 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8525 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8526 DEPR_ACCESS_V8, NULL},
8527};
8528
8529#undef DEPR_ACCESS_V8
8530
8531static const size_t deprecated_coproc_reg_count =
8532 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8533
09d92015 8534static void
c19d1205 8535do_co_reg (void)
09d92015 8536{
fdfde340 8537 unsigned Rd;
dcbd0d71 8538 size_t i;
fdfde340
JM
8539
8540 Rd = inst.operands[2].reg;
8541 if (thumb_mode)
8542 {
8543 if (inst.instruction == 0xee000010
8544 || inst.instruction == 0xfe000010)
8545 /* MCR, MCR2 */
8546 reject_bad_reg (Rd);
8547 else
8548 /* MRC, MRC2 */
8549 constraint (Rd == REG_SP, BAD_SP);
8550 }
8551 else
8552 {
8553 /* MCR */
8554 if (inst.instruction == 0xe000010)
8555 constraint (Rd == REG_PC, BAD_PC);
8556 }
8557
dcbd0d71
MGD
8558 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8559 {
8560 const struct deprecated_coproc_regs_s *r =
8561 deprecated_coproc_regs + i;
8562
8563 if (inst.operands[0].reg == r->cp
8564 && inst.operands[1].imm == r->opc1
8565 && inst.operands[3].reg == r->crn
8566 && inst.operands[4].reg == r->crm
8567 && inst.operands[5].imm == r->opc2)
8568 {
b10bf8c5 8569 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8570 && warn_on_deprecated
dcbd0d71 8571 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8572 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8573 }
8574 }
fdfde340 8575
c19d1205
ZW
8576 inst.instruction |= inst.operands[0].reg << 8;
8577 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8578 inst.instruction |= Rd << 12;
c19d1205
ZW
8579 inst.instruction |= inst.operands[3].reg << 16;
8580 inst.instruction |= inst.operands[4].reg;
8581 inst.instruction |= inst.operands[5].imm << 5;
8582}
09d92015 8583
c19d1205
ZW
8584/* Transfer between coprocessor register and pair of ARM registers.
8585 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8586 MCRR2
8587 MRRC{cond}
8588 MRRC2
b99bd4ef 8589
c19d1205 8590 Two XScale instructions are special cases of these:
09d92015 8591
c19d1205
ZW
8592 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8593 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8594
5f4273c7 8595 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8596
c19d1205
ZW
8597static void
8598do_co_reg2c (void)
8599{
fdfde340
JM
8600 unsigned Rd, Rn;
8601
8602 Rd = inst.operands[2].reg;
8603 Rn = inst.operands[3].reg;
8604
8605 if (thumb_mode)
8606 {
8607 reject_bad_reg (Rd);
8608 reject_bad_reg (Rn);
8609 }
8610 else
8611 {
8612 constraint (Rd == REG_PC, BAD_PC);
8613 constraint (Rn == REG_PC, BAD_PC);
8614 }
8615
c19d1205
ZW
8616 inst.instruction |= inst.operands[0].reg << 8;
8617 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8618 inst.instruction |= Rd << 12;
8619 inst.instruction |= Rn << 16;
c19d1205 8620 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8621}
8622
c19d1205
ZW
8623static void
8624do_cpsi (void)
8625{
8626 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8627 if (inst.operands[1].present)
8628 {
8629 inst.instruction |= CPSI_MMOD;
8630 inst.instruction |= inst.operands[1].imm;
8631 }
c19d1205 8632}
b99bd4ef 8633
62b3e311
PB
8634static void
8635do_dbg (void)
8636{
8637 inst.instruction |= inst.operands[0].imm;
8638}
8639
eea54501
MGD
8640static void
8641do_div (void)
8642{
8643 unsigned Rd, Rn, Rm;
8644
8645 Rd = inst.operands[0].reg;
8646 Rn = (inst.operands[1].present
8647 ? inst.operands[1].reg : Rd);
8648 Rm = inst.operands[2].reg;
8649
8650 constraint ((Rd == REG_PC), BAD_PC);
8651 constraint ((Rn == REG_PC), BAD_PC);
8652 constraint ((Rm == REG_PC), BAD_PC);
8653
8654 inst.instruction |= Rd << 16;
8655 inst.instruction |= Rn << 0;
8656 inst.instruction |= Rm << 8;
8657}
8658
b99bd4ef 8659static void
c19d1205 8660do_it (void)
b99bd4ef 8661{
c19d1205 8662 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8663 process it to do the validation as if in
8664 thumb mode, just in case the code gets
8665 assembled for thumb using the unified syntax. */
8666
c19d1205 8667 inst.size = 0;
e07e6e58
NC
8668 if (unified_syntax)
8669 {
8670 set_it_insn_type (IT_INSN);
8671 now_it.mask = (inst.instruction & 0xf) | 0x10;
8672 now_it.cc = inst.operands[0].imm;
8673 }
09d92015 8674}
b99bd4ef 8675
6530b175
NC
8676/* If there is only one register in the register list,
8677 then return its register number. Otherwise return -1. */
8678static int
8679only_one_reg_in_list (int range)
8680{
8681 int i = ffs (range) - 1;
8682 return (i > 15 || range != (1 << i)) ? -1 : i;
8683}
8684
09d92015 8685static void
6530b175 8686encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8687{
c19d1205
ZW
8688 int base_reg = inst.operands[0].reg;
8689 int range = inst.operands[1].imm;
6530b175 8690 int one_reg;
ea6ef066 8691
c19d1205
ZW
8692 inst.instruction |= base_reg << 16;
8693 inst.instruction |= range;
ea6ef066 8694
c19d1205
ZW
8695 if (inst.operands[1].writeback)
8696 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8697
c19d1205 8698 if (inst.operands[0].writeback)
ea6ef066 8699 {
c19d1205
ZW
8700 inst.instruction |= WRITE_BACK;
8701 /* Check for unpredictable uses of writeback. */
8702 if (inst.instruction & LOAD_BIT)
09d92015 8703 {
c19d1205
ZW
8704 /* Not allowed in LDM type 2. */
8705 if ((inst.instruction & LDM_TYPE_2_OR_3)
8706 && ((range & (1 << REG_PC)) == 0))
8707 as_warn (_("writeback of base register is UNPREDICTABLE"));
8708 /* Only allowed if base reg not in list for other types. */
8709 else if (range & (1 << base_reg))
8710 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8711 }
8712 else /* STM. */
8713 {
8714 /* Not allowed for type 2. */
8715 if (inst.instruction & LDM_TYPE_2_OR_3)
8716 as_warn (_("writeback of base register is UNPREDICTABLE"));
8717 /* Only allowed if base reg not in list, or first in list. */
8718 else if ((range & (1 << base_reg))
8719 && (range & ((1 << base_reg) - 1)))
8720 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8721 }
ea6ef066 8722 }
6530b175
NC
8723
8724 /* If PUSH/POP has only one register, then use the A2 encoding. */
8725 one_reg = only_one_reg_in_list (range);
8726 if (from_push_pop_mnem && one_reg >= 0)
8727 {
8728 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8729
8730 inst.instruction &= A_COND_MASK;
8731 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8732 inst.instruction |= one_reg << 12;
8733 }
8734}
8735
8736static void
8737do_ldmstm (void)
8738{
8739 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8740}
8741
c19d1205
ZW
8742/* ARMv5TE load-consecutive (argument parse)
8743 Mode is like LDRH.
8744
8745 LDRccD R, mode
8746 STRccD R, mode. */
8747
a737bd4d 8748static void
c19d1205 8749do_ldrd (void)
a737bd4d 8750{
c19d1205 8751 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8752 _("first transfer register must be even"));
c19d1205
ZW
8753 constraint (inst.operands[1].present
8754 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8755 _("can only transfer two consecutive registers"));
c19d1205
ZW
8756 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8757 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8758
c19d1205
ZW
8759 if (!inst.operands[1].present)
8760 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8761
c56791bb
RE
8762 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8763 register and the first register written; we have to diagnose
8764 overlap between the base and the second register written here. */
ea6ef066 8765
c56791bb
RE
8766 if (inst.operands[2].reg == inst.operands[1].reg
8767 && (inst.operands[2].writeback || inst.operands[2].postind))
8768 as_warn (_("base register written back, and overlaps "
8769 "second transfer register"));
b05fe5cf 8770
c56791bb
RE
8771 if (!(inst.instruction & V4_STR_BIT))
8772 {
c19d1205 8773 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8774 destination (even if not write-back). */
8775 if (inst.operands[2].immisreg
8776 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8777 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8778 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8779 }
c19d1205
ZW
8780 inst.instruction |= inst.operands[0].reg << 12;
8781 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8782}
8783
8784static void
c19d1205 8785do_ldrex (void)
b05fe5cf 8786{
c19d1205
ZW
8787 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8788 || inst.operands[1].postind || inst.operands[1].writeback
8789 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8790 || inst.operands[1].negative
8791 /* This can arise if the programmer has written
8792 strex rN, rM, foo
8793 or if they have mistakenly used a register name as the last
8794 operand, eg:
8795 strex rN, rM, rX
8796 It is very difficult to distinguish between these two cases
8797 because "rX" might actually be a label. ie the register
8798 name has been occluded by a symbol of the same name. So we
8799 just generate a general 'bad addressing mode' type error
8800 message and leave it up to the programmer to discover the
8801 true cause and fix their mistake. */
8802 || (inst.operands[1].reg == REG_PC),
8803 BAD_ADDR_MODE);
b05fe5cf 8804
c19d1205
ZW
8805 constraint (inst.reloc.exp.X_op != O_constant
8806 || inst.reloc.exp.X_add_number != 0,
8807 _("offset must be zero in ARM encoding"));
b05fe5cf 8808
5be8be5d
DG
8809 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8810
c19d1205
ZW
8811 inst.instruction |= inst.operands[0].reg << 12;
8812 inst.instruction |= inst.operands[1].reg << 16;
8813 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8814}
8815
8816static void
c19d1205 8817do_ldrexd (void)
b05fe5cf 8818{
c19d1205
ZW
8819 constraint (inst.operands[0].reg % 2 != 0,
8820 _("even register required"));
8821 constraint (inst.operands[1].present
8822 && inst.operands[1].reg != inst.operands[0].reg + 1,
8823 _("can only load two consecutive registers"));
8824 /* If op 1 were present and equal to PC, this function wouldn't
8825 have been called in the first place. */
8826 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8827
c19d1205
ZW
8828 inst.instruction |= inst.operands[0].reg << 12;
8829 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8830}
8831
1be5fd2e
NC
8832/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8833 which is not a multiple of four is UNPREDICTABLE. */
8834static void
8835check_ldr_r15_aligned (void)
8836{
8837 constraint (!(inst.operands[1].immisreg)
8838 && (inst.operands[0].reg == REG_PC
8839 && inst.operands[1].reg == REG_PC
8840 && (inst.reloc.exp.X_add_number & 0x3)),
8841 _("ldr to register 15 must be 4-byte alligned"));
8842}
8843
b05fe5cf 8844static void
c19d1205 8845do_ldst (void)
b05fe5cf 8846{
c19d1205
ZW
8847 inst.instruction |= inst.operands[0].reg << 12;
8848 if (!inst.operands[1].isreg)
8335d6aa 8849 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8850 return;
c19d1205 8851 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8852 check_ldr_r15_aligned ();
b05fe5cf
ZW
8853}
8854
8855static void
c19d1205 8856do_ldstt (void)
b05fe5cf 8857{
c19d1205
ZW
8858 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8859 reject [Rn,...]. */
8860 if (inst.operands[1].preind)
b05fe5cf 8861 {
bd3ba5d1
NC
8862 constraint (inst.reloc.exp.X_op != O_constant
8863 || inst.reloc.exp.X_add_number != 0,
c19d1205 8864 _("this instruction requires a post-indexed address"));
b05fe5cf 8865
c19d1205
ZW
8866 inst.operands[1].preind = 0;
8867 inst.operands[1].postind = 1;
8868 inst.operands[1].writeback = 1;
b05fe5cf 8869 }
c19d1205
ZW
8870 inst.instruction |= inst.operands[0].reg << 12;
8871 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8872}
b05fe5cf 8873
c19d1205 8874/* Halfword and signed-byte load/store operations. */
b05fe5cf 8875
c19d1205
ZW
8876static void
8877do_ldstv4 (void)
8878{
ff4a8d2b 8879 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8880 inst.instruction |= inst.operands[0].reg << 12;
8881 if (!inst.operands[1].isreg)
8335d6aa 8882 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 8883 return;
c19d1205 8884 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
8885}
8886
8887static void
c19d1205 8888do_ldsttv4 (void)
b05fe5cf 8889{
c19d1205
ZW
8890 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8891 reject [Rn,...]. */
8892 if (inst.operands[1].preind)
b05fe5cf 8893 {
bd3ba5d1
NC
8894 constraint (inst.reloc.exp.X_op != O_constant
8895 || inst.reloc.exp.X_add_number != 0,
c19d1205 8896 _("this instruction requires a post-indexed address"));
b05fe5cf 8897
c19d1205
ZW
8898 inst.operands[1].preind = 0;
8899 inst.operands[1].postind = 1;
8900 inst.operands[1].writeback = 1;
b05fe5cf 8901 }
c19d1205
ZW
8902 inst.instruction |= inst.operands[0].reg << 12;
8903 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8904}
b05fe5cf 8905
c19d1205
ZW
8906/* Co-processor register load/store.
8907 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8908static void
8909do_lstc (void)
8910{
8911 inst.instruction |= inst.operands[0].reg << 8;
8912 inst.instruction |= inst.operands[1].reg << 12;
8913 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
8914}
8915
b05fe5cf 8916static void
c19d1205 8917do_mlas (void)
b05fe5cf 8918{
8fb9d7b9 8919 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 8920 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 8921 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 8922 && !(inst.instruction & 0x00400000))
8fb9d7b9 8923 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 8924
c19d1205
ZW
8925 inst.instruction |= inst.operands[0].reg << 16;
8926 inst.instruction |= inst.operands[1].reg;
8927 inst.instruction |= inst.operands[2].reg << 8;
8928 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 8929}
b05fe5cf 8930
c19d1205
ZW
8931static void
8932do_mov (void)
8933{
8934 inst.instruction |= inst.operands[0].reg << 12;
8935 encode_arm_shifter_operand (1);
8936}
b05fe5cf 8937
c19d1205
ZW
8938/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8939static void
8940do_mov16 (void)
8941{
b6895b4f
PB
8942 bfd_vma imm;
8943 bfd_boolean top;
8944
8945 top = (inst.instruction & 0x00400000) != 0;
8946 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8947 _(":lower16: not allowed this instruction"));
8948 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8949 _(":upper16: not allowed instruction"));
c19d1205 8950 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
8951 if (inst.reloc.type == BFD_RELOC_UNUSED)
8952 {
8953 imm = inst.reloc.exp.X_add_number;
8954 /* The value is in two pieces: 0:11, 16:19. */
8955 inst.instruction |= (imm & 0x00000fff);
8956 inst.instruction |= (imm & 0x0000f000) << 4;
8957 }
b05fe5cf 8958}
b99bd4ef 8959
037e8744
JB
8960static int
8961do_vfp_nsyn_mrs (void)
8962{
8963 if (inst.operands[0].isvec)
8964 {
8965 if (inst.operands[1].reg != 1)
477330fc 8966 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
8967 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8968 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8969 do_vfp_nsyn_opcode ("fmstat");
8970 }
8971 else if (inst.operands[1].isvec)
8972 do_vfp_nsyn_opcode ("fmrx");
8973 else
8974 return FAIL;
5f4273c7 8975
037e8744
JB
8976 return SUCCESS;
8977}
8978
8979static int
8980do_vfp_nsyn_msr (void)
8981{
8982 if (inst.operands[0].isvec)
8983 do_vfp_nsyn_opcode ("fmxr");
8984 else
8985 return FAIL;
8986
8987 return SUCCESS;
8988}
8989
f7c21dc7
NC
8990static void
8991do_vmrs (void)
8992{
8993 unsigned Rt = inst.operands[0].reg;
fa94de6b 8994
16d02dc9 8995 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
8996 {
8997 inst.error = BAD_SP;
8998 return;
8999 }
9000
9001 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9002 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9003 {
9004 inst.error = BAD_PC;
9005 return;
9006 }
9007
16d02dc9
JB
9008 /* If we get through parsing the register name, we just insert the number
9009 generated into the instruction without further validation. */
9010 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9011 inst.instruction |= (Rt << 12);
9012}
9013
9014static void
9015do_vmsr (void)
9016{
9017 unsigned Rt = inst.operands[1].reg;
fa94de6b 9018
f7c21dc7
NC
9019 if (thumb_mode)
9020 reject_bad_reg (Rt);
9021 else if (Rt == REG_PC)
9022 {
9023 inst.error = BAD_PC;
9024 return;
9025 }
9026
16d02dc9
JB
9027 /* If we get through parsing the register name, we just insert the number
9028 generated into the instruction without further validation. */
9029 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9030 inst.instruction |= (Rt << 12);
9031}
9032
b99bd4ef 9033static void
c19d1205 9034do_mrs (void)
b99bd4ef 9035{
90ec0d68
MGD
9036 unsigned br;
9037
037e8744
JB
9038 if (do_vfp_nsyn_mrs () == SUCCESS)
9039 return;
9040
ff4a8d2b 9041 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9042 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9043
9044 if (inst.operands[1].isreg)
9045 {
9046 br = inst.operands[1].reg;
9047 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9048 as_bad (_("bad register for mrs"));
9049 }
9050 else
9051 {
9052 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9053 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9054 != (PSR_c|PSR_f),
d2cd1205 9055 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9056 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9057 }
9058
9059 inst.instruction |= br;
c19d1205 9060}
b99bd4ef 9061
c19d1205
ZW
9062/* Two possible forms:
9063 "{C|S}PSR_<field>, Rm",
9064 "{C|S}PSR_f, #expression". */
b99bd4ef 9065
c19d1205
ZW
9066static void
9067do_msr (void)
9068{
037e8744
JB
9069 if (do_vfp_nsyn_msr () == SUCCESS)
9070 return;
9071
c19d1205
ZW
9072 inst.instruction |= inst.operands[0].imm;
9073 if (inst.operands[1].isreg)
9074 inst.instruction |= inst.operands[1].reg;
9075 else
b99bd4ef 9076 {
c19d1205
ZW
9077 inst.instruction |= INST_IMMEDIATE;
9078 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9079 inst.reloc.pc_rel = 0;
b99bd4ef 9080 }
b99bd4ef
NC
9081}
9082
c19d1205
ZW
9083static void
9084do_mul (void)
a737bd4d 9085{
ff4a8d2b
NC
9086 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9087
c19d1205
ZW
9088 if (!inst.operands[2].present)
9089 inst.operands[2].reg = inst.operands[0].reg;
9090 inst.instruction |= inst.operands[0].reg << 16;
9091 inst.instruction |= inst.operands[1].reg;
9092 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9093
8fb9d7b9
MS
9094 if (inst.operands[0].reg == inst.operands[1].reg
9095 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9096 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9097}
9098
c19d1205
ZW
9099/* Long Multiply Parser
9100 UMULL RdLo, RdHi, Rm, Rs
9101 SMULL RdLo, RdHi, Rm, Rs
9102 UMLAL RdLo, RdHi, Rm, Rs
9103 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9104
9105static void
c19d1205 9106do_mull (void)
b99bd4ef 9107{
c19d1205
ZW
9108 inst.instruction |= inst.operands[0].reg << 12;
9109 inst.instruction |= inst.operands[1].reg << 16;
9110 inst.instruction |= inst.operands[2].reg;
9111 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9112
682b27ad
PB
9113 /* rdhi and rdlo must be different. */
9114 if (inst.operands[0].reg == inst.operands[1].reg)
9115 as_tsktsk (_("rdhi and rdlo must be different"));
9116
9117 /* rdhi, rdlo and rm must all be different before armv6. */
9118 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9119 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9120 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9121 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9122}
b99bd4ef 9123
c19d1205
ZW
9124static void
9125do_nop (void)
9126{
e7495e45
NS
9127 if (inst.operands[0].present
9128 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9129 {
9130 /* Architectural NOP hints are CPSR sets with no bits selected. */
9131 inst.instruction &= 0xf0000000;
e7495e45
NS
9132 inst.instruction |= 0x0320f000;
9133 if (inst.operands[0].present)
9134 inst.instruction |= inst.operands[0].imm;
c19d1205 9135 }
b99bd4ef
NC
9136}
9137
c19d1205
ZW
9138/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9139 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9140 Condition defaults to COND_ALWAYS.
9141 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9142
9143static void
c19d1205 9144do_pkhbt (void)
b99bd4ef 9145{
c19d1205
ZW
9146 inst.instruction |= inst.operands[0].reg << 12;
9147 inst.instruction |= inst.operands[1].reg << 16;
9148 inst.instruction |= inst.operands[2].reg;
9149 if (inst.operands[3].present)
9150 encode_arm_shift (3);
9151}
b99bd4ef 9152
c19d1205 9153/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9154
c19d1205
ZW
9155static void
9156do_pkhtb (void)
9157{
9158 if (!inst.operands[3].present)
b99bd4ef 9159 {
c19d1205
ZW
9160 /* If the shift specifier is omitted, turn the instruction
9161 into pkhbt rd, rm, rn. */
9162 inst.instruction &= 0xfff00010;
9163 inst.instruction |= inst.operands[0].reg << 12;
9164 inst.instruction |= inst.operands[1].reg;
9165 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9166 }
9167 else
9168 {
c19d1205
ZW
9169 inst.instruction |= inst.operands[0].reg << 12;
9170 inst.instruction |= inst.operands[1].reg << 16;
9171 inst.instruction |= inst.operands[2].reg;
9172 encode_arm_shift (3);
b99bd4ef
NC
9173 }
9174}
9175
c19d1205 9176/* ARMv5TE: Preload-Cache
60e5ef9f 9177 MP Extensions: Preload for write
c19d1205 9178
60e5ef9f 9179 PLD(W) <addr_mode>
c19d1205
ZW
9180
9181 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9182
9183static void
c19d1205 9184do_pld (void)
b99bd4ef 9185{
c19d1205
ZW
9186 constraint (!inst.operands[0].isreg,
9187 _("'[' expected after PLD mnemonic"));
9188 constraint (inst.operands[0].postind,
9189 _("post-indexed expression used in preload instruction"));
9190 constraint (inst.operands[0].writeback,
9191 _("writeback used in preload instruction"));
9192 constraint (!inst.operands[0].preind,
9193 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9194 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9195}
b99bd4ef 9196
62b3e311
PB
9197/* ARMv7: PLI <addr_mode> */
9198static void
9199do_pli (void)
9200{
9201 constraint (!inst.operands[0].isreg,
9202 _("'[' expected after PLI mnemonic"));
9203 constraint (inst.operands[0].postind,
9204 _("post-indexed expression used in preload instruction"));
9205 constraint (inst.operands[0].writeback,
9206 _("writeback used in preload instruction"));
9207 constraint (!inst.operands[0].preind,
9208 _("unindexed addressing used in preload instruction"));
9209 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9210 inst.instruction &= ~PRE_INDEX;
9211}
9212
c19d1205
ZW
9213static void
9214do_push_pop (void)
9215{
5e0d7f77
MP
9216 constraint (inst.operands[0].writeback,
9217 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9218 inst.operands[1] = inst.operands[0];
9219 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9220 inst.operands[0].isreg = 1;
9221 inst.operands[0].writeback = 1;
9222 inst.operands[0].reg = REG_SP;
6530b175 9223 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9224}
b99bd4ef 9225
c19d1205
ZW
9226/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9227 word at the specified address and the following word
9228 respectively.
9229 Unconditionally executed.
9230 Error if Rn is R15. */
b99bd4ef 9231
c19d1205
ZW
9232static void
9233do_rfe (void)
9234{
9235 inst.instruction |= inst.operands[0].reg << 16;
9236 if (inst.operands[0].writeback)
9237 inst.instruction |= WRITE_BACK;
9238}
b99bd4ef 9239
c19d1205 9240/* ARM V6 ssat (argument parse). */
b99bd4ef 9241
c19d1205
ZW
9242static void
9243do_ssat (void)
9244{
9245 inst.instruction |= inst.operands[0].reg << 12;
9246 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9247 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9248
c19d1205
ZW
9249 if (inst.operands[3].present)
9250 encode_arm_shift (3);
b99bd4ef
NC
9251}
9252
c19d1205 9253/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9254
9255static void
c19d1205 9256do_usat (void)
b99bd4ef 9257{
c19d1205
ZW
9258 inst.instruction |= inst.operands[0].reg << 12;
9259 inst.instruction |= inst.operands[1].imm << 16;
9260 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9261
c19d1205
ZW
9262 if (inst.operands[3].present)
9263 encode_arm_shift (3);
b99bd4ef
NC
9264}
9265
c19d1205 9266/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9267
9268static void
c19d1205 9269do_ssat16 (void)
09d92015 9270{
c19d1205
ZW
9271 inst.instruction |= inst.operands[0].reg << 12;
9272 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9273 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9274}
9275
c19d1205
ZW
9276static void
9277do_usat16 (void)
a737bd4d 9278{
c19d1205
ZW
9279 inst.instruction |= inst.operands[0].reg << 12;
9280 inst.instruction |= inst.operands[1].imm << 16;
9281 inst.instruction |= inst.operands[2].reg;
9282}
a737bd4d 9283
c19d1205
ZW
9284/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9285 preserving the other bits.
a737bd4d 9286
c19d1205
ZW
9287 setend <endian_specifier>, where <endian_specifier> is either
9288 BE or LE. */
a737bd4d 9289
c19d1205
ZW
9290static void
9291do_setend (void)
9292{
12e37cbc
MGD
9293 if (warn_on_deprecated
9294 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9295 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9296
c19d1205
ZW
9297 if (inst.operands[0].imm)
9298 inst.instruction |= 0x200;
a737bd4d
NC
9299}
9300
9301static void
c19d1205 9302do_shift (void)
a737bd4d 9303{
c19d1205
ZW
9304 unsigned int Rm = (inst.operands[1].present
9305 ? inst.operands[1].reg
9306 : inst.operands[0].reg);
a737bd4d 9307
c19d1205
ZW
9308 inst.instruction |= inst.operands[0].reg << 12;
9309 inst.instruction |= Rm;
9310 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9311 {
c19d1205
ZW
9312 inst.instruction |= inst.operands[2].reg << 8;
9313 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9314 /* PR 12854: Error on extraneous shifts. */
9315 constraint (inst.operands[2].shifted,
9316 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9317 }
9318 else
c19d1205 9319 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9320}
9321
09d92015 9322static void
3eb17e6b 9323do_smc (void)
09d92015 9324{
3eb17e6b 9325 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9326 inst.reloc.pc_rel = 0;
09d92015
MM
9327}
9328
90ec0d68
MGD
9329static void
9330do_hvc (void)
9331{
9332 inst.reloc.type = BFD_RELOC_ARM_HVC;
9333 inst.reloc.pc_rel = 0;
9334}
9335
09d92015 9336static void
c19d1205 9337do_swi (void)
09d92015 9338{
c19d1205
ZW
9339 inst.reloc.type = BFD_RELOC_ARM_SWI;
9340 inst.reloc.pc_rel = 0;
09d92015
MM
9341}
9342
ddfded2f
MW
9343static void
9344do_setpan (void)
9345{
9346 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9347 _("selected processor does not support SETPAN instruction"));
9348
9349 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9350}
9351
9352static void
9353do_t_setpan (void)
9354{
9355 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9356 _("selected processor does not support SETPAN instruction"));
9357
9358 inst.instruction |= (inst.operands[0].imm << 3);
9359}
9360
c19d1205
ZW
9361/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9362 SMLAxy{cond} Rd,Rm,Rs,Rn
9363 SMLAWy{cond} Rd,Rm,Rs,Rn
9364 Error if any register is R15. */
e16bb312 9365
c19d1205
ZW
9366static void
9367do_smla (void)
e16bb312 9368{
c19d1205
ZW
9369 inst.instruction |= inst.operands[0].reg << 16;
9370 inst.instruction |= inst.operands[1].reg;
9371 inst.instruction |= inst.operands[2].reg << 8;
9372 inst.instruction |= inst.operands[3].reg << 12;
9373}
a737bd4d 9374
c19d1205
ZW
9375/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9376 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9377 Error if any register is R15.
9378 Warning if Rdlo == Rdhi. */
a737bd4d 9379
c19d1205
ZW
9380static void
9381do_smlal (void)
9382{
9383 inst.instruction |= inst.operands[0].reg << 12;
9384 inst.instruction |= inst.operands[1].reg << 16;
9385 inst.instruction |= inst.operands[2].reg;
9386 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9387
c19d1205
ZW
9388 if (inst.operands[0].reg == inst.operands[1].reg)
9389 as_tsktsk (_("rdhi and rdlo must be different"));
9390}
a737bd4d 9391
c19d1205
ZW
9392/* ARM V5E (El Segundo) signed-multiply (argument parse)
9393 SMULxy{cond} Rd,Rm,Rs
9394 Error if any register is R15. */
a737bd4d 9395
c19d1205
ZW
9396static void
9397do_smul (void)
9398{
9399 inst.instruction |= inst.operands[0].reg << 16;
9400 inst.instruction |= inst.operands[1].reg;
9401 inst.instruction |= inst.operands[2].reg << 8;
9402}
a737bd4d 9403
b6702015
PB
9404/* ARM V6 srs (argument parse). The variable fields in the encoding are
9405 the same for both ARM and Thumb-2. */
a737bd4d 9406
c19d1205
ZW
9407static void
9408do_srs (void)
9409{
b6702015
PB
9410 int reg;
9411
9412 if (inst.operands[0].present)
9413 {
9414 reg = inst.operands[0].reg;
fdfde340 9415 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9416 }
9417 else
fdfde340 9418 reg = REG_SP;
b6702015
PB
9419
9420 inst.instruction |= reg << 16;
9421 inst.instruction |= inst.operands[1].imm;
9422 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9423 inst.instruction |= WRITE_BACK;
9424}
a737bd4d 9425
c19d1205 9426/* ARM V6 strex (argument parse). */
a737bd4d 9427
c19d1205
ZW
9428static void
9429do_strex (void)
9430{
9431 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9432 || inst.operands[2].postind || inst.operands[2].writeback
9433 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9434 || inst.operands[2].negative
9435 /* See comment in do_ldrex(). */
9436 || (inst.operands[2].reg == REG_PC),
9437 BAD_ADDR_MODE);
a737bd4d 9438
c19d1205
ZW
9439 constraint (inst.operands[0].reg == inst.operands[1].reg
9440 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9441
c19d1205
ZW
9442 constraint (inst.reloc.exp.X_op != O_constant
9443 || inst.reloc.exp.X_add_number != 0,
9444 _("offset must be zero in ARM encoding"));
a737bd4d 9445
c19d1205
ZW
9446 inst.instruction |= inst.operands[0].reg << 12;
9447 inst.instruction |= inst.operands[1].reg;
9448 inst.instruction |= inst.operands[2].reg << 16;
9449 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9450}
9451
877807f8
NC
9452static void
9453do_t_strexbh (void)
9454{
9455 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9456 || inst.operands[2].postind || inst.operands[2].writeback
9457 || inst.operands[2].immisreg || inst.operands[2].shifted
9458 || inst.operands[2].negative,
9459 BAD_ADDR_MODE);
9460
9461 constraint (inst.operands[0].reg == inst.operands[1].reg
9462 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9463
9464 do_rm_rd_rn ();
9465}
9466
e16bb312 9467static void
c19d1205 9468do_strexd (void)
e16bb312 9469{
c19d1205
ZW
9470 constraint (inst.operands[1].reg % 2 != 0,
9471 _("even register required"));
9472 constraint (inst.operands[2].present
9473 && inst.operands[2].reg != inst.operands[1].reg + 1,
9474 _("can only store two consecutive registers"));
9475 /* If op 2 were present and equal to PC, this function wouldn't
9476 have been called in the first place. */
9477 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9478
c19d1205
ZW
9479 constraint (inst.operands[0].reg == inst.operands[1].reg
9480 || inst.operands[0].reg == inst.operands[1].reg + 1
9481 || inst.operands[0].reg == inst.operands[3].reg,
9482 BAD_OVERLAP);
e16bb312 9483
c19d1205
ZW
9484 inst.instruction |= inst.operands[0].reg << 12;
9485 inst.instruction |= inst.operands[1].reg;
9486 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9487}
9488
9eb6c0f1
MGD
9489/* ARM V8 STRL. */
9490static void
4b8c8c02 9491do_stlex (void)
9eb6c0f1
MGD
9492{
9493 constraint (inst.operands[0].reg == inst.operands[1].reg
9494 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9495
9496 do_rd_rm_rn ();
9497}
9498
9499static void
4b8c8c02 9500do_t_stlex (void)
9eb6c0f1
MGD
9501{
9502 constraint (inst.operands[0].reg == inst.operands[1].reg
9503 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9504
9505 do_rm_rd_rn ();
9506}
9507
c19d1205
ZW
9508/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9509 extends it to 32-bits, and adds the result to a value in another
9510 register. You can specify a rotation by 0, 8, 16, or 24 bits
9511 before extracting the 16-bit value.
9512 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9513 Condition defaults to COND_ALWAYS.
9514 Error if any register uses R15. */
9515
e16bb312 9516static void
c19d1205 9517do_sxtah (void)
e16bb312 9518{
c19d1205
ZW
9519 inst.instruction |= inst.operands[0].reg << 12;
9520 inst.instruction |= inst.operands[1].reg << 16;
9521 inst.instruction |= inst.operands[2].reg;
9522 inst.instruction |= inst.operands[3].imm << 10;
9523}
e16bb312 9524
c19d1205 9525/* ARM V6 SXTH.
e16bb312 9526
c19d1205
ZW
9527 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9528 Condition defaults to COND_ALWAYS.
9529 Error if any register uses R15. */
e16bb312
NC
9530
9531static void
c19d1205 9532do_sxth (void)
e16bb312 9533{
c19d1205
ZW
9534 inst.instruction |= inst.operands[0].reg << 12;
9535 inst.instruction |= inst.operands[1].reg;
9536 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9537}
c19d1205
ZW
9538\f
9539/* VFP instructions. In a logical order: SP variant first, monad
9540 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9541
9542static void
c19d1205 9543do_vfp_sp_monadic (void)
e16bb312 9544{
5287ad62
JB
9545 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9546 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9547}
9548
9549static void
c19d1205 9550do_vfp_sp_dyadic (void)
e16bb312 9551{
5287ad62
JB
9552 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9553 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9554 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9555}
9556
9557static void
c19d1205 9558do_vfp_sp_compare_z (void)
e16bb312 9559{
5287ad62 9560 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9561}
9562
9563static void
c19d1205 9564do_vfp_dp_sp_cvt (void)
e16bb312 9565{
5287ad62
JB
9566 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9567 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9568}
9569
9570static void
c19d1205 9571do_vfp_sp_dp_cvt (void)
e16bb312 9572{
5287ad62
JB
9573 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9574 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9575}
9576
9577static void
c19d1205 9578do_vfp_reg_from_sp (void)
e16bb312 9579{
c19d1205 9580 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9581 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9582}
9583
9584static void
c19d1205 9585do_vfp_reg2_from_sp2 (void)
e16bb312 9586{
c19d1205
ZW
9587 constraint (inst.operands[2].imm != 2,
9588 _("only two consecutive VFP SP registers allowed here"));
9589 inst.instruction |= inst.operands[0].reg << 12;
9590 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9591 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9592}
9593
9594static void
c19d1205 9595do_vfp_sp_from_reg (void)
e16bb312 9596{
5287ad62 9597 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9598 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9599}
9600
9601static void
c19d1205 9602do_vfp_sp2_from_reg2 (void)
e16bb312 9603{
c19d1205
ZW
9604 constraint (inst.operands[0].imm != 2,
9605 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9606 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9607 inst.instruction |= inst.operands[1].reg << 12;
9608 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9609}
9610
9611static void
c19d1205 9612do_vfp_sp_ldst (void)
e16bb312 9613{
5287ad62 9614 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9615 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9616}
9617
9618static void
c19d1205 9619do_vfp_dp_ldst (void)
e16bb312 9620{
5287ad62 9621 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9622 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9623}
9624
c19d1205 9625
e16bb312 9626static void
c19d1205 9627vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9628{
c19d1205
ZW
9629 if (inst.operands[0].writeback)
9630 inst.instruction |= WRITE_BACK;
9631 else
9632 constraint (ldstm_type != VFP_LDSTMIA,
9633 _("this addressing mode requires base-register writeback"));
9634 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9635 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9636 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9637}
9638
9639static void
c19d1205 9640vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9641{
c19d1205 9642 int count;
e16bb312 9643
c19d1205
ZW
9644 if (inst.operands[0].writeback)
9645 inst.instruction |= WRITE_BACK;
9646 else
9647 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9648 _("this addressing mode requires base-register writeback"));
e16bb312 9649
c19d1205 9650 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9651 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9652
c19d1205
ZW
9653 count = inst.operands[1].imm << 1;
9654 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9655 count += 1;
e16bb312 9656
c19d1205 9657 inst.instruction |= count;
e16bb312
NC
9658}
9659
9660static void
c19d1205 9661do_vfp_sp_ldstmia (void)
e16bb312 9662{
c19d1205 9663 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9664}
9665
9666static void
c19d1205 9667do_vfp_sp_ldstmdb (void)
e16bb312 9668{
c19d1205 9669 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9670}
9671
9672static void
c19d1205 9673do_vfp_dp_ldstmia (void)
e16bb312 9674{
c19d1205 9675 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9676}
9677
9678static void
c19d1205 9679do_vfp_dp_ldstmdb (void)
e16bb312 9680{
c19d1205 9681 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9682}
9683
9684static void
c19d1205 9685do_vfp_xp_ldstmia (void)
e16bb312 9686{
c19d1205
ZW
9687 vfp_dp_ldstm (VFP_LDSTMIAX);
9688}
e16bb312 9689
c19d1205
ZW
9690static void
9691do_vfp_xp_ldstmdb (void)
9692{
9693 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9694}
5287ad62
JB
9695
9696static void
9697do_vfp_dp_rd_rm (void)
9698{
9699 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9700 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9701}
9702
9703static void
9704do_vfp_dp_rn_rd (void)
9705{
9706 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9707 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9708}
9709
9710static void
9711do_vfp_dp_rd_rn (void)
9712{
9713 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9714 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9715}
9716
9717static void
9718do_vfp_dp_rd_rn_rm (void)
9719{
9720 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9721 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9722 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9723}
9724
9725static void
9726do_vfp_dp_rd (void)
9727{
9728 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9729}
9730
9731static void
9732do_vfp_dp_rm_rd_rn (void)
9733{
9734 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9735 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9736 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9737}
9738
9739/* VFPv3 instructions. */
9740static void
9741do_vfp_sp_const (void)
9742{
9743 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9744 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9745 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9746}
9747
9748static void
9749do_vfp_dp_const (void)
9750{
9751 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9752 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9753 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9754}
9755
9756static void
9757vfp_conv (int srcsize)
9758{
5f1af56b
MGD
9759 int immbits = srcsize - inst.operands[1].imm;
9760
fa94de6b
RM
9761 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9762 {
5f1af56b 9763 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9764 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9765 inst.error = _("immediate value out of range, expected range [0, 16]");
9766 return;
9767 }
fa94de6b 9768 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9769 {
9770 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9771 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9772 inst.error = _("immediate value out of range, expected range [1, 32]");
9773 return;
9774 }
9775
5287ad62
JB
9776 inst.instruction |= (immbits & 1) << 5;
9777 inst.instruction |= (immbits >> 1);
9778}
9779
9780static void
9781do_vfp_sp_conv_16 (void)
9782{
9783 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9784 vfp_conv (16);
9785}
9786
9787static void
9788do_vfp_dp_conv_16 (void)
9789{
9790 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9791 vfp_conv (16);
9792}
9793
9794static void
9795do_vfp_sp_conv_32 (void)
9796{
9797 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9798 vfp_conv (32);
9799}
9800
9801static void
9802do_vfp_dp_conv_32 (void)
9803{
9804 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9805 vfp_conv (32);
9806}
c19d1205
ZW
9807\f
9808/* FPA instructions. Also in a logical order. */
e16bb312 9809
c19d1205
ZW
9810static void
9811do_fpa_cmp (void)
9812{
9813 inst.instruction |= inst.operands[0].reg << 16;
9814 inst.instruction |= inst.operands[1].reg;
9815}
b99bd4ef
NC
9816
9817static void
c19d1205 9818do_fpa_ldmstm (void)
b99bd4ef 9819{
c19d1205
ZW
9820 inst.instruction |= inst.operands[0].reg << 12;
9821 switch (inst.operands[1].imm)
9822 {
9823 case 1: inst.instruction |= CP_T_X; break;
9824 case 2: inst.instruction |= CP_T_Y; break;
9825 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9826 case 4: break;
9827 default: abort ();
9828 }
b99bd4ef 9829
c19d1205
ZW
9830 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9831 {
9832 /* The instruction specified "ea" or "fd", so we can only accept
9833 [Rn]{!}. The instruction does not really support stacking or
9834 unstacking, so we have to emulate these by setting appropriate
9835 bits and offsets. */
9836 constraint (inst.reloc.exp.X_op != O_constant
9837 || inst.reloc.exp.X_add_number != 0,
9838 _("this instruction does not support indexing"));
b99bd4ef 9839
c19d1205
ZW
9840 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9841 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9842
c19d1205
ZW
9843 if (!(inst.instruction & INDEX_UP))
9844 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9845
c19d1205
ZW
9846 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9847 {
9848 inst.operands[2].preind = 0;
9849 inst.operands[2].postind = 1;
9850 }
9851 }
b99bd4ef 9852
c19d1205 9853 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9854}
c19d1205
ZW
9855\f
9856/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9857
c19d1205
ZW
9858static void
9859do_iwmmxt_tandorc (void)
9860{
9861 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9862}
b99bd4ef 9863
c19d1205
ZW
9864static void
9865do_iwmmxt_textrc (void)
9866{
9867 inst.instruction |= inst.operands[0].reg << 12;
9868 inst.instruction |= inst.operands[1].imm;
9869}
b99bd4ef
NC
9870
9871static void
c19d1205 9872do_iwmmxt_textrm (void)
b99bd4ef 9873{
c19d1205
ZW
9874 inst.instruction |= inst.operands[0].reg << 12;
9875 inst.instruction |= inst.operands[1].reg << 16;
9876 inst.instruction |= inst.operands[2].imm;
9877}
b99bd4ef 9878
c19d1205
ZW
9879static void
9880do_iwmmxt_tinsr (void)
9881{
9882 inst.instruction |= inst.operands[0].reg << 16;
9883 inst.instruction |= inst.operands[1].reg << 12;
9884 inst.instruction |= inst.operands[2].imm;
9885}
b99bd4ef 9886
c19d1205
ZW
9887static void
9888do_iwmmxt_tmia (void)
9889{
9890 inst.instruction |= inst.operands[0].reg << 5;
9891 inst.instruction |= inst.operands[1].reg;
9892 inst.instruction |= inst.operands[2].reg << 12;
9893}
b99bd4ef 9894
c19d1205
ZW
9895static void
9896do_iwmmxt_waligni (void)
9897{
9898 inst.instruction |= inst.operands[0].reg << 12;
9899 inst.instruction |= inst.operands[1].reg << 16;
9900 inst.instruction |= inst.operands[2].reg;
9901 inst.instruction |= inst.operands[3].imm << 20;
9902}
b99bd4ef 9903
2d447fca
JM
9904static void
9905do_iwmmxt_wmerge (void)
9906{
9907 inst.instruction |= inst.operands[0].reg << 12;
9908 inst.instruction |= inst.operands[1].reg << 16;
9909 inst.instruction |= inst.operands[2].reg;
9910 inst.instruction |= inst.operands[3].imm << 21;
9911}
9912
c19d1205
ZW
9913static void
9914do_iwmmxt_wmov (void)
9915{
9916 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9917 inst.instruction |= inst.operands[0].reg << 12;
9918 inst.instruction |= inst.operands[1].reg << 16;
9919 inst.instruction |= inst.operands[1].reg;
9920}
b99bd4ef 9921
c19d1205
ZW
9922static void
9923do_iwmmxt_wldstbh (void)
9924{
8f06b2d8 9925 int reloc;
c19d1205 9926 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
9927 if (thumb_mode)
9928 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9929 else
9930 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9931 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
9932}
9933
c19d1205
ZW
9934static void
9935do_iwmmxt_wldstw (void)
9936{
9937 /* RIWR_RIWC clears .isreg for a control register. */
9938 if (!inst.operands[0].isreg)
9939 {
9940 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9941 inst.instruction |= 0xf0000000;
9942 }
b99bd4ef 9943
c19d1205
ZW
9944 inst.instruction |= inst.operands[0].reg << 12;
9945 encode_arm_cp_address (1, TRUE, TRUE, 0);
9946}
b99bd4ef
NC
9947
9948static void
c19d1205 9949do_iwmmxt_wldstd (void)
b99bd4ef 9950{
c19d1205 9951 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
9952 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9953 && inst.operands[1].immisreg)
9954 {
9955 inst.instruction &= ~0x1a000ff;
eff0bc54 9956 inst.instruction |= (0xfU << 28);
2d447fca
JM
9957 if (inst.operands[1].preind)
9958 inst.instruction |= PRE_INDEX;
9959 if (!inst.operands[1].negative)
9960 inst.instruction |= INDEX_UP;
9961 if (inst.operands[1].writeback)
9962 inst.instruction |= WRITE_BACK;
9963 inst.instruction |= inst.operands[1].reg << 16;
9964 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9965 inst.instruction |= inst.operands[1].imm;
9966 }
9967 else
9968 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 9969}
b99bd4ef 9970
c19d1205
ZW
9971static void
9972do_iwmmxt_wshufh (void)
9973{
9974 inst.instruction |= inst.operands[0].reg << 12;
9975 inst.instruction |= inst.operands[1].reg << 16;
9976 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
9977 inst.instruction |= (inst.operands[2].imm & 0x0f);
9978}
b99bd4ef 9979
c19d1205
ZW
9980static void
9981do_iwmmxt_wzero (void)
9982{
9983 /* WZERO reg is an alias for WANDN reg, reg, reg. */
9984 inst.instruction |= inst.operands[0].reg;
9985 inst.instruction |= inst.operands[0].reg << 12;
9986 inst.instruction |= inst.operands[0].reg << 16;
9987}
2d447fca
JM
9988
9989static void
9990do_iwmmxt_wrwrwr_or_imm5 (void)
9991{
9992 if (inst.operands[2].isreg)
9993 do_rd_rn_rm ();
9994 else {
9995 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
9996 _("immediate operand requires iWMMXt2"));
9997 do_rd_rn ();
9998 if (inst.operands[2].imm == 0)
9999 {
10000 switch ((inst.instruction >> 20) & 0xf)
10001 {
10002 case 4:
10003 case 5:
10004 case 6:
5f4273c7 10005 case 7:
2d447fca
JM
10006 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10007 inst.operands[2].imm = 16;
10008 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10009 break;
10010 case 8:
10011 case 9:
10012 case 10:
10013 case 11:
10014 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10015 inst.operands[2].imm = 32;
10016 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10017 break;
10018 case 12:
10019 case 13:
10020 case 14:
10021 case 15:
10022 {
10023 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10024 unsigned long wrn;
10025 wrn = (inst.instruction >> 16) & 0xf;
10026 inst.instruction &= 0xff0fff0f;
10027 inst.instruction |= wrn;
10028 /* Bail out here; the instruction is now assembled. */
10029 return;
10030 }
10031 }
10032 }
10033 /* Map 32 -> 0, etc. */
10034 inst.operands[2].imm &= 0x1f;
eff0bc54 10035 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10036 }
10037}
c19d1205
ZW
10038\f
10039/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10040 operations first, then control, shift, and load/store. */
b99bd4ef 10041
c19d1205 10042/* Insns like "foo X,Y,Z". */
b99bd4ef 10043
c19d1205
ZW
10044static void
10045do_mav_triple (void)
10046{
10047 inst.instruction |= inst.operands[0].reg << 16;
10048 inst.instruction |= inst.operands[1].reg;
10049 inst.instruction |= inst.operands[2].reg << 12;
10050}
b99bd4ef 10051
c19d1205
ZW
10052/* Insns like "foo W,X,Y,Z".
10053 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10054
c19d1205
ZW
10055static void
10056do_mav_quad (void)
10057{
10058 inst.instruction |= inst.operands[0].reg << 5;
10059 inst.instruction |= inst.operands[1].reg << 12;
10060 inst.instruction |= inst.operands[2].reg << 16;
10061 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10062}
10063
c19d1205
ZW
10064/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10065static void
10066do_mav_dspsc (void)
a737bd4d 10067{
c19d1205
ZW
10068 inst.instruction |= inst.operands[1].reg << 12;
10069}
a737bd4d 10070
c19d1205
ZW
10071/* Maverick shift immediate instructions.
10072 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10073 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10074
c19d1205
ZW
10075static void
10076do_mav_shift (void)
10077{
10078 int imm = inst.operands[2].imm;
a737bd4d 10079
c19d1205
ZW
10080 inst.instruction |= inst.operands[0].reg << 12;
10081 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10082
c19d1205
ZW
10083 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10084 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10085 Bit 4 should be 0. */
10086 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10087
c19d1205
ZW
10088 inst.instruction |= imm;
10089}
10090\f
10091/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10092
c19d1205
ZW
10093/* Xscale multiply-accumulate (argument parse)
10094 MIAcc acc0,Rm,Rs
10095 MIAPHcc acc0,Rm,Rs
10096 MIAxycc acc0,Rm,Rs. */
a737bd4d 10097
c19d1205
ZW
10098static void
10099do_xsc_mia (void)
10100{
10101 inst.instruction |= inst.operands[1].reg;
10102 inst.instruction |= inst.operands[2].reg << 12;
10103}
a737bd4d 10104
c19d1205 10105/* Xscale move-accumulator-register (argument parse)
a737bd4d 10106
c19d1205 10107 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10108
c19d1205
ZW
10109static void
10110do_xsc_mar (void)
10111{
10112 inst.instruction |= inst.operands[1].reg << 12;
10113 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10114}
10115
c19d1205 10116/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10117
c19d1205 10118 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10119
10120static void
c19d1205 10121do_xsc_mra (void)
b99bd4ef 10122{
c19d1205
ZW
10123 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10124 inst.instruction |= inst.operands[0].reg << 12;
10125 inst.instruction |= inst.operands[1].reg << 16;
10126}
10127\f
10128/* Encoding functions relevant only to Thumb. */
b99bd4ef 10129
c19d1205
ZW
10130/* inst.operands[i] is a shifted-register operand; encode
10131 it into inst.instruction in the format used by Thumb32. */
10132
10133static void
10134encode_thumb32_shifted_operand (int i)
10135{
10136 unsigned int value = inst.reloc.exp.X_add_number;
10137 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10138
9c3c69f2
PB
10139 constraint (inst.operands[i].immisreg,
10140 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10141 inst.instruction |= inst.operands[i].reg;
10142 if (shift == SHIFT_RRX)
10143 inst.instruction |= SHIFT_ROR << 4;
10144 else
b99bd4ef 10145 {
c19d1205
ZW
10146 constraint (inst.reloc.exp.X_op != O_constant,
10147 _("expression too complex"));
10148
10149 constraint (value > 32
10150 || (value == 32 && (shift == SHIFT_LSL
10151 || shift == SHIFT_ROR)),
10152 _("shift expression is too large"));
10153
10154 if (value == 0)
10155 shift = SHIFT_LSL;
10156 else if (value == 32)
10157 value = 0;
10158
10159 inst.instruction |= shift << 4;
10160 inst.instruction |= (value & 0x1c) << 10;
10161 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10162 }
c19d1205 10163}
b99bd4ef 10164
b99bd4ef 10165
c19d1205
ZW
10166/* inst.operands[i] was set up by parse_address. Encode it into a
10167 Thumb32 format load or store instruction. Reject forms that cannot
10168 be used with such instructions. If is_t is true, reject forms that
10169 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10170 that cannot be used with a D instruction. If it is a store insn,
10171 reject PC in Rn. */
b99bd4ef 10172
c19d1205
ZW
10173static void
10174encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10175{
5be8be5d 10176 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10177
10178 constraint (!inst.operands[i].isreg,
53365c0d 10179 _("Instruction does not support =N addresses"));
b99bd4ef 10180
c19d1205
ZW
10181 inst.instruction |= inst.operands[i].reg << 16;
10182 if (inst.operands[i].immisreg)
b99bd4ef 10183 {
5be8be5d 10184 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10185 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10186 constraint (inst.operands[i].negative,
10187 _("Thumb does not support negative register indexing"));
10188 constraint (inst.operands[i].postind,
10189 _("Thumb does not support register post-indexing"));
10190 constraint (inst.operands[i].writeback,
10191 _("Thumb does not support register indexing with writeback"));
10192 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10193 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10194
f40d1643 10195 inst.instruction |= inst.operands[i].imm;
c19d1205 10196 if (inst.operands[i].shifted)
b99bd4ef 10197 {
c19d1205
ZW
10198 constraint (inst.reloc.exp.X_op != O_constant,
10199 _("expression too complex"));
9c3c69f2
PB
10200 constraint (inst.reloc.exp.X_add_number < 0
10201 || inst.reloc.exp.X_add_number > 3,
c19d1205 10202 _("shift out of range"));
9c3c69f2 10203 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10204 }
10205 inst.reloc.type = BFD_RELOC_UNUSED;
10206 }
10207 else if (inst.operands[i].preind)
10208 {
5be8be5d 10209 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10210 constraint (is_t && inst.operands[i].writeback,
c19d1205 10211 _("cannot use writeback with this instruction"));
4755303e
WN
10212 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10213 BAD_PC_ADDRESSING);
c19d1205
ZW
10214
10215 if (is_d)
10216 {
10217 inst.instruction |= 0x01000000;
10218 if (inst.operands[i].writeback)
10219 inst.instruction |= 0x00200000;
b99bd4ef 10220 }
c19d1205 10221 else
b99bd4ef 10222 {
c19d1205
ZW
10223 inst.instruction |= 0x00000c00;
10224 if (inst.operands[i].writeback)
10225 inst.instruction |= 0x00000100;
b99bd4ef 10226 }
c19d1205 10227 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10228 }
c19d1205 10229 else if (inst.operands[i].postind)
b99bd4ef 10230 {
9c2799c2 10231 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10232 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10233 constraint (is_t, _("cannot use post-indexing with this instruction"));
10234
10235 if (is_d)
10236 inst.instruction |= 0x00200000;
10237 else
10238 inst.instruction |= 0x00000900;
10239 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10240 }
10241 else /* unindexed - only for coprocessor */
10242 inst.error = _("instruction does not accept unindexed addressing");
10243}
10244
10245/* Table of Thumb instructions which exist in both 16- and 32-bit
10246 encodings (the latter only in post-V6T2 cores). The index is the
10247 value used in the insns table below. When there is more than one
10248 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10249 holds variant (1).
10250 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10251#define T16_32_TAB \
21d799b5
NC
10252 X(_adc, 4140, eb400000), \
10253 X(_adcs, 4140, eb500000), \
10254 X(_add, 1c00, eb000000), \
10255 X(_adds, 1c00, eb100000), \
10256 X(_addi, 0000, f1000000), \
10257 X(_addis, 0000, f1100000), \
10258 X(_add_pc,000f, f20f0000), \
10259 X(_add_sp,000d, f10d0000), \
10260 X(_adr, 000f, f20f0000), \
10261 X(_and, 4000, ea000000), \
10262 X(_ands, 4000, ea100000), \
10263 X(_asr, 1000, fa40f000), \
10264 X(_asrs, 1000, fa50f000), \
10265 X(_b, e000, f000b000), \
10266 X(_bcond, d000, f0008000), \
10267 X(_bic, 4380, ea200000), \
10268 X(_bics, 4380, ea300000), \
10269 X(_cmn, 42c0, eb100f00), \
10270 X(_cmp, 2800, ebb00f00), \
10271 X(_cpsie, b660, f3af8400), \
10272 X(_cpsid, b670, f3af8600), \
10273 X(_cpy, 4600, ea4f0000), \
10274 X(_dec_sp,80dd, f1ad0d00), \
10275 X(_eor, 4040, ea800000), \
10276 X(_eors, 4040, ea900000), \
10277 X(_inc_sp,00dd, f10d0d00), \
10278 X(_ldmia, c800, e8900000), \
10279 X(_ldr, 6800, f8500000), \
10280 X(_ldrb, 7800, f8100000), \
10281 X(_ldrh, 8800, f8300000), \
10282 X(_ldrsb, 5600, f9100000), \
10283 X(_ldrsh, 5e00, f9300000), \
10284 X(_ldr_pc,4800, f85f0000), \
10285 X(_ldr_pc2,4800, f85f0000), \
10286 X(_ldr_sp,9800, f85d0000), \
10287 X(_lsl, 0000, fa00f000), \
10288 X(_lsls, 0000, fa10f000), \
10289 X(_lsr, 0800, fa20f000), \
10290 X(_lsrs, 0800, fa30f000), \
10291 X(_mov, 2000, ea4f0000), \
10292 X(_movs, 2000, ea5f0000), \
10293 X(_mul, 4340, fb00f000), \
10294 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10295 X(_mvn, 43c0, ea6f0000), \
10296 X(_mvns, 43c0, ea7f0000), \
10297 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10298 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10299 X(_orr, 4300, ea400000), \
10300 X(_orrs, 4300, ea500000), \
10301 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10302 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10303 X(_rev, ba00, fa90f080), \
10304 X(_rev16, ba40, fa90f090), \
10305 X(_revsh, bac0, fa90f0b0), \
10306 X(_ror, 41c0, fa60f000), \
10307 X(_rors, 41c0, fa70f000), \
10308 X(_sbc, 4180, eb600000), \
10309 X(_sbcs, 4180, eb700000), \
10310 X(_stmia, c000, e8800000), \
10311 X(_str, 6000, f8400000), \
10312 X(_strb, 7000, f8000000), \
10313 X(_strh, 8000, f8200000), \
10314 X(_str_sp,9000, f84d0000), \
10315 X(_sub, 1e00, eba00000), \
10316 X(_subs, 1e00, ebb00000), \
10317 X(_subi, 8000, f1a00000), \
10318 X(_subis, 8000, f1b00000), \
10319 X(_sxtb, b240, fa4ff080), \
10320 X(_sxth, b200, fa0ff080), \
10321 X(_tst, 4200, ea100f00), \
10322 X(_uxtb, b2c0, fa5ff080), \
10323 X(_uxth, b280, fa1ff080), \
10324 X(_nop, bf00, f3af8000), \
10325 X(_yield, bf10, f3af8001), \
10326 X(_wfe, bf20, f3af8002), \
10327 X(_wfi, bf30, f3af8003), \
53c4b28b 10328 X(_sev, bf40, f3af8004), \
74db7efb
NC
10329 X(_sevl, bf50, f3af8005), \
10330 X(_udf, de00, f7f0a000)
c19d1205
ZW
10331
10332/* To catch errors in encoding functions, the codes are all offset by
10333 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10334 as 16-bit instructions. */
21d799b5 10335#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10336enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10337#undef X
10338
10339#define X(a,b,c) 0x##b
10340static const unsigned short thumb_op16[] = { T16_32_TAB };
10341#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10342#undef X
10343
10344#define X(a,b,c) 0x##c
10345static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10346#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10347#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10348#undef X
10349#undef T16_32_TAB
10350
10351/* Thumb instruction encoders, in alphabetical order. */
10352
92e90b6e 10353/* ADDW or SUBW. */
c921be7d 10354
92e90b6e
PB
10355static void
10356do_t_add_sub_w (void)
10357{
10358 int Rd, Rn;
10359
10360 Rd = inst.operands[0].reg;
10361 Rn = inst.operands[1].reg;
10362
539d4391
NC
10363 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10364 is the SP-{plus,minus}-immediate form of the instruction. */
10365 if (Rn == REG_SP)
10366 constraint (Rd == REG_PC, BAD_PC);
10367 else
10368 reject_bad_reg (Rd);
fdfde340 10369
92e90b6e
PB
10370 inst.instruction |= (Rn << 16) | (Rd << 8);
10371 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10372}
10373
c19d1205
ZW
10374/* Parse an add or subtract instruction. We get here with inst.instruction
10375 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
10376
10377static void
10378do_t_add_sub (void)
10379{
10380 int Rd, Rs, Rn;
10381
10382 Rd = inst.operands[0].reg;
10383 Rs = (inst.operands[1].present
10384 ? inst.operands[1].reg /* Rd, Rs, foo */
10385 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10386
e07e6e58
NC
10387 if (Rd == REG_PC)
10388 set_it_insn_type_last ();
10389
c19d1205
ZW
10390 if (unified_syntax)
10391 {
0110f2b8
PB
10392 bfd_boolean flags;
10393 bfd_boolean narrow;
10394 int opcode;
10395
10396 flags = (inst.instruction == T_MNEM_adds
10397 || inst.instruction == T_MNEM_subs);
10398 if (flags)
e07e6e58 10399 narrow = !in_it_block ();
0110f2b8 10400 else
e07e6e58 10401 narrow = in_it_block ();
c19d1205 10402 if (!inst.operands[2].isreg)
b99bd4ef 10403 {
16805f35
PB
10404 int add;
10405
fdfde340
JM
10406 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10407
16805f35
PB
10408 add = (inst.instruction == T_MNEM_add
10409 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10410 opcode = 0;
10411 if (inst.size_req != 4)
10412 {
0110f2b8 10413 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10414 appropriate. */
0110f2b8
PB
10415 if (Rd == REG_SP && Rs == REG_SP && !flags)
10416 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10417 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10418 opcode = T_MNEM_add_sp;
10419 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10420 opcode = T_MNEM_add_pc;
10421 else if (Rd <= 7 && Rs <= 7 && narrow)
10422 {
10423 if (flags)
10424 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10425 else
10426 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10427 }
10428 if (opcode)
10429 {
10430 inst.instruction = THUMB_OP16(opcode);
10431 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10432 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10433 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
10434 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
0110f2b8
PB
10435 if (inst.size_req != 2)
10436 inst.relax = opcode;
10437 }
10438 else
10439 constraint (inst.size_req == 2, BAD_HIREG);
10440 }
10441 if (inst.size_req == 4
10442 || (inst.size_req != 2 && !opcode))
10443 {
efd81785
PB
10444 if (Rd == REG_PC)
10445 {
fdfde340 10446 constraint (add, BAD_PC);
efd81785
PB
10447 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10448 _("only SUBS PC, LR, #const allowed"));
10449 constraint (inst.reloc.exp.X_op != O_constant,
10450 _("expression too complex"));
10451 constraint (inst.reloc.exp.X_add_number < 0
10452 || inst.reloc.exp.X_add_number > 0xff,
10453 _("immediate value out of range"));
10454 inst.instruction = T2_SUBS_PC_LR
10455 | inst.reloc.exp.X_add_number;
10456 inst.reloc.type = BFD_RELOC_UNUSED;
10457 return;
10458 }
10459 else if (Rs == REG_PC)
16805f35
PB
10460 {
10461 /* Always use addw/subw. */
10462 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10463 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10464 }
10465 else
10466 {
10467 inst.instruction = THUMB_OP32 (inst.instruction);
10468 inst.instruction = (inst.instruction & 0xe1ffffff)
10469 | 0x10000000;
10470 if (flags)
10471 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10472 else
10473 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10474 }
dc4503c6
PB
10475 inst.instruction |= Rd << 8;
10476 inst.instruction |= Rs << 16;
0110f2b8 10477 }
b99bd4ef 10478 }
c19d1205
ZW
10479 else
10480 {
5f4cb198
NC
10481 unsigned int value = inst.reloc.exp.X_add_number;
10482 unsigned int shift = inst.operands[2].shift_kind;
10483
c19d1205
ZW
10484 Rn = inst.operands[2].reg;
10485 /* See if we can do this with a 16-bit instruction. */
10486 if (!inst.operands[2].shifted && inst.size_req != 4)
10487 {
e27ec89e
PB
10488 if (Rd > 7 || Rs > 7 || Rn > 7)
10489 narrow = FALSE;
10490
10491 if (narrow)
c19d1205 10492 {
e27ec89e
PB
10493 inst.instruction = ((inst.instruction == T_MNEM_adds
10494 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10495 ? T_OPCODE_ADD_R3
10496 : T_OPCODE_SUB_R3);
10497 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10498 return;
10499 }
b99bd4ef 10500
7e806470 10501 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10502 {
7e806470
PB
10503 /* Thumb-1 cores (except v6-M) require at least one high
10504 register in a narrow non flag setting add. */
10505 if (Rd > 7 || Rn > 7
10506 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10507 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10508 {
7e806470
PB
10509 if (Rd == Rn)
10510 {
10511 Rn = Rs;
10512 Rs = Rd;
10513 }
c19d1205
ZW
10514 inst.instruction = T_OPCODE_ADD_HI;
10515 inst.instruction |= (Rd & 8) << 4;
10516 inst.instruction |= (Rd & 7);
10517 inst.instruction |= Rn << 3;
10518 return;
10519 }
c19d1205
ZW
10520 }
10521 }
c921be7d 10522
fdfde340
JM
10523 constraint (Rd == REG_PC, BAD_PC);
10524 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10525 constraint (Rs == REG_PC, BAD_PC);
10526 reject_bad_reg (Rn);
10527
c19d1205
ZW
10528 /* If we get here, it can't be done in 16 bits. */
10529 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10530 _("shift must be constant"));
10531 inst.instruction = THUMB_OP32 (inst.instruction);
10532 inst.instruction |= Rd << 8;
10533 inst.instruction |= Rs << 16;
5f4cb198
NC
10534 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10535 _("shift value over 3 not allowed in thumb mode"));
10536 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10537 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10538 encode_thumb32_shifted_operand (2);
10539 }
10540 }
10541 else
10542 {
10543 constraint (inst.instruction == T_MNEM_adds
10544 || inst.instruction == T_MNEM_subs,
10545 BAD_THUMB32);
b99bd4ef 10546
c19d1205 10547 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10548 {
c19d1205
ZW
10549 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10550 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10551 BAD_HIREG);
10552
10553 inst.instruction = (inst.instruction == T_MNEM_add
10554 ? 0x0000 : 0x8000);
10555 inst.instruction |= (Rd << 4) | Rs;
10556 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10557 return;
10558 }
10559
c19d1205
ZW
10560 Rn = inst.operands[2].reg;
10561 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10562
c19d1205
ZW
10563 /* We now have Rd, Rs, and Rn set to registers. */
10564 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10565 {
c19d1205
ZW
10566 /* Can't do this for SUB. */
10567 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10568 inst.instruction = T_OPCODE_ADD_HI;
10569 inst.instruction |= (Rd & 8) << 4;
10570 inst.instruction |= (Rd & 7);
10571 if (Rs == Rd)
10572 inst.instruction |= Rn << 3;
10573 else if (Rn == Rd)
10574 inst.instruction |= Rs << 3;
10575 else
10576 constraint (1, _("dest must overlap one source register"));
10577 }
10578 else
10579 {
10580 inst.instruction = (inst.instruction == T_MNEM_add
10581 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10582 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10583 }
b99bd4ef 10584 }
b99bd4ef
NC
10585}
10586
c19d1205
ZW
10587static void
10588do_t_adr (void)
10589{
fdfde340
JM
10590 unsigned Rd;
10591
10592 Rd = inst.operands[0].reg;
10593 reject_bad_reg (Rd);
10594
10595 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10596 {
10597 /* Defer to section relaxation. */
10598 inst.relax = inst.instruction;
10599 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10600 inst.instruction |= Rd << 4;
0110f2b8
PB
10601 }
10602 else if (unified_syntax && inst.size_req != 2)
e9f89963 10603 {
0110f2b8 10604 /* Generate a 32-bit opcode. */
e9f89963 10605 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10606 inst.instruction |= Rd << 8;
e9f89963
PB
10607 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10608 inst.reloc.pc_rel = 1;
10609 }
10610 else
10611 {
0110f2b8 10612 /* Generate a 16-bit opcode. */
e9f89963
PB
10613 inst.instruction = THUMB_OP16 (inst.instruction);
10614 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10615 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10616 inst.reloc.pc_rel = 1;
b99bd4ef 10617
fdfde340 10618 inst.instruction |= Rd << 4;
e9f89963 10619 }
c19d1205 10620}
b99bd4ef 10621
c19d1205
ZW
10622/* Arithmetic instructions for which there is just one 16-bit
10623 instruction encoding, and it allows only two low registers.
10624 For maximal compatibility with ARM syntax, we allow three register
10625 operands even when Thumb-32 instructions are not available, as long
10626 as the first two are identical. For instance, both "sbc r0,r1" and
10627 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10628static void
c19d1205 10629do_t_arit3 (void)
b99bd4ef 10630{
c19d1205 10631 int Rd, Rs, Rn;
b99bd4ef 10632
c19d1205
ZW
10633 Rd = inst.operands[0].reg;
10634 Rs = (inst.operands[1].present
10635 ? inst.operands[1].reg /* Rd, Rs, foo */
10636 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10637 Rn = inst.operands[2].reg;
b99bd4ef 10638
fdfde340
JM
10639 reject_bad_reg (Rd);
10640 reject_bad_reg (Rs);
10641 if (inst.operands[2].isreg)
10642 reject_bad_reg (Rn);
10643
c19d1205 10644 if (unified_syntax)
b99bd4ef 10645 {
c19d1205
ZW
10646 if (!inst.operands[2].isreg)
10647 {
10648 /* For an immediate, we always generate a 32-bit opcode;
10649 section relaxation will shrink it later if possible. */
10650 inst.instruction = THUMB_OP32 (inst.instruction);
10651 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10652 inst.instruction |= Rd << 8;
10653 inst.instruction |= Rs << 16;
10654 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10655 }
10656 else
10657 {
e27ec89e
PB
10658 bfd_boolean narrow;
10659
c19d1205 10660 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10661 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10662 narrow = !in_it_block ();
e27ec89e 10663 else
e07e6e58 10664 narrow = in_it_block ();
e27ec89e
PB
10665
10666 if (Rd > 7 || Rn > 7 || Rs > 7)
10667 narrow = FALSE;
10668 if (inst.operands[2].shifted)
10669 narrow = FALSE;
10670 if (inst.size_req == 4)
10671 narrow = FALSE;
10672
10673 if (narrow
c19d1205
ZW
10674 && Rd == Rs)
10675 {
10676 inst.instruction = THUMB_OP16 (inst.instruction);
10677 inst.instruction |= Rd;
10678 inst.instruction |= Rn << 3;
10679 return;
10680 }
b99bd4ef 10681
c19d1205
ZW
10682 /* If we get here, it can't be done in 16 bits. */
10683 constraint (inst.operands[2].shifted
10684 && inst.operands[2].immisreg,
10685 _("shift must be constant"));
10686 inst.instruction = THUMB_OP32 (inst.instruction);
10687 inst.instruction |= Rd << 8;
10688 inst.instruction |= Rs << 16;
10689 encode_thumb32_shifted_operand (2);
10690 }
a737bd4d 10691 }
c19d1205 10692 else
b99bd4ef 10693 {
c19d1205
ZW
10694 /* On its face this is a lie - the instruction does set the
10695 flags. However, the only supported mnemonic in this mode
10696 says it doesn't. */
10697 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10698
c19d1205
ZW
10699 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10700 _("unshifted register required"));
10701 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10702 constraint (Rd != Rs,
10703 _("dest and source1 must be the same register"));
a737bd4d 10704
c19d1205
ZW
10705 inst.instruction = THUMB_OP16 (inst.instruction);
10706 inst.instruction |= Rd;
10707 inst.instruction |= Rn << 3;
b99bd4ef 10708 }
a737bd4d 10709}
b99bd4ef 10710
c19d1205
ZW
10711/* Similarly, but for instructions where the arithmetic operation is
10712 commutative, so we can allow either of them to be different from
10713 the destination operand in a 16-bit instruction. For instance, all
10714 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10715 accepted. */
10716static void
10717do_t_arit3c (void)
a737bd4d 10718{
c19d1205 10719 int Rd, Rs, Rn;
b99bd4ef 10720
c19d1205
ZW
10721 Rd = inst.operands[0].reg;
10722 Rs = (inst.operands[1].present
10723 ? inst.operands[1].reg /* Rd, Rs, foo */
10724 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10725 Rn = inst.operands[2].reg;
c921be7d 10726
fdfde340
JM
10727 reject_bad_reg (Rd);
10728 reject_bad_reg (Rs);
10729 if (inst.operands[2].isreg)
10730 reject_bad_reg (Rn);
a737bd4d 10731
c19d1205 10732 if (unified_syntax)
a737bd4d 10733 {
c19d1205 10734 if (!inst.operands[2].isreg)
b99bd4ef 10735 {
c19d1205
ZW
10736 /* For an immediate, we always generate a 32-bit opcode;
10737 section relaxation will shrink it later if possible. */
10738 inst.instruction = THUMB_OP32 (inst.instruction);
10739 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10740 inst.instruction |= Rd << 8;
10741 inst.instruction |= Rs << 16;
10742 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10743 }
c19d1205 10744 else
a737bd4d 10745 {
e27ec89e
PB
10746 bfd_boolean narrow;
10747
c19d1205 10748 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10749 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10750 narrow = !in_it_block ();
e27ec89e 10751 else
e07e6e58 10752 narrow = in_it_block ();
e27ec89e
PB
10753
10754 if (Rd > 7 || Rn > 7 || Rs > 7)
10755 narrow = FALSE;
10756 if (inst.operands[2].shifted)
10757 narrow = FALSE;
10758 if (inst.size_req == 4)
10759 narrow = FALSE;
10760
10761 if (narrow)
a737bd4d 10762 {
c19d1205 10763 if (Rd == Rs)
a737bd4d 10764 {
c19d1205
ZW
10765 inst.instruction = THUMB_OP16 (inst.instruction);
10766 inst.instruction |= Rd;
10767 inst.instruction |= Rn << 3;
10768 return;
a737bd4d 10769 }
c19d1205 10770 if (Rd == Rn)
a737bd4d 10771 {
c19d1205
ZW
10772 inst.instruction = THUMB_OP16 (inst.instruction);
10773 inst.instruction |= Rd;
10774 inst.instruction |= Rs << 3;
10775 return;
a737bd4d
NC
10776 }
10777 }
c19d1205
ZW
10778
10779 /* If we get here, it can't be done in 16 bits. */
10780 constraint (inst.operands[2].shifted
10781 && inst.operands[2].immisreg,
10782 _("shift must be constant"));
10783 inst.instruction = THUMB_OP32 (inst.instruction);
10784 inst.instruction |= Rd << 8;
10785 inst.instruction |= Rs << 16;
10786 encode_thumb32_shifted_operand (2);
a737bd4d 10787 }
b99bd4ef 10788 }
c19d1205
ZW
10789 else
10790 {
10791 /* On its face this is a lie - the instruction does set the
10792 flags. However, the only supported mnemonic in this mode
10793 says it doesn't. */
10794 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10795
c19d1205
ZW
10796 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10797 _("unshifted register required"));
10798 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10799
10800 inst.instruction = THUMB_OP16 (inst.instruction);
10801 inst.instruction |= Rd;
10802
10803 if (Rd == Rs)
10804 inst.instruction |= Rn << 3;
10805 else if (Rd == Rn)
10806 inst.instruction |= Rs << 3;
10807 else
10808 constraint (1, _("dest must overlap one source register"));
10809 }
a737bd4d
NC
10810}
10811
c19d1205
ZW
10812static void
10813do_t_bfc (void)
a737bd4d 10814{
fdfde340 10815 unsigned Rd;
c19d1205
ZW
10816 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10817 constraint (msb > 32, _("bit-field extends past end of register"));
10818 /* The instruction encoding stores the LSB and MSB,
10819 not the LSB and width. */
fdfde340
JM
10820 Rd = inst.operands[0].reg;
10821 reject_bad_reg (Rd);
10822 inst.instruction |= Rd << 8;
c19d1205
ZW
10823 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10824 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10825 inst.instruction |= msb - 1;
b99bd4ef
NC
10826}
10827
c19d1205
ZW
10828static void
10829do_t_bfi (void)
b99bd4ef 10830{
fdfde340 10831 int Rd, Rn;
c19d1205 10832 unsigned int msb;
b99bd4ef 10833
fdfde340
JM
10834 Rd = inst.operands[0].reg;
10835 reject_bad_reg (Rd);
10836
c19d1205
ZW
10837 /* #0 in second position is alternative syntax for bfc, which is
10838 the same instruction but with REG_PC in the Rm field. */
10839 if (!inst.operands[1].isreg)
fdfde340
JM
10840 Rn = REG_PC;
10841 else
10842 {
10843 Rn = inst.operands[1].reg;
10844 reject_bad_reg (Rn);
10845 }
b99bd4ef 10846
c19d1205
ZW
10847 msb = inst.operands[2].imm + inst.operands[3].imm;
10848 constraint (msb > 32, _("bit-field extends past end of register"));
10849 /* The instruction encoding stores the LSB and MSB,
10850 not the LSB and width. */
fdfde340
JM
10851 inst.instruction |= Rd << 8;
10852 inst.instruction |= Rn << 16;
c19d1205
ZW
10853 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10854 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10855 inst.instruction |= msb - 1;
b99bd4ef
NC
10856}
10857
c19d1205
ZW
10858static void
10859do_t_bfx (void)
b99bd4ef 10860{
fdfde340
JM
10861 unsigned Rd, Rn;
10862
10863 Rd = inst.operands[0].reg;
10864 Rn = inst.operands[1].reg;
10865
10866 reject_bad_reg (Rd);
10867 reject_bad_reg (Rn);
10868
c19d1205
ZW
10869 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10870 _("bit-field extends past end of register"));
fdfde340
JM
10871 inst.instruction |= Rd << 8;
10872 inst.instruction |= Rn << 16;
c19d1205
ZW
10873 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10874 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10875 inst.instruction |= inst.operands[3].imm - 1;
10876}
b99bd4ef 10877
c19d1205
ZW
10878/* ARM V5 Thumb BLX (argument parse)
10879 BLX <target_addr> which is BLX(1)
10880 BLX <Rm> which is BLX(2)
10881 Unfortunately, there are two different opcodes for this mnemonic.
10882 So, the insns[].value is not used, and the code here zaps values
10883 into inst.instruction.
b99bd4ef 10884
c19d1205
ZW
10885 ??? How to take advantage of the additional two bits of displacement
10886 available in Thumb32 mode? Need new relocation? */
b99bd4ef 10887
c19d1205
ZW
10888static void
10889do_t_blx (void)
10890{
e07e6e58
NC
10891 set_it_insn_type_last ();
10892
c19d1205 10893 if (inst.operands[0].isreg)
fdfde340
JM
10894 {
10895 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10896 /* We have a register, so this is BLX(2). */
10897 inst.instruction |= inst.operands[0].reg << 3;
10898 }
b99bd4ef
NC
10899 else
10900 {
c19d1205 10901 /* No register. This must be BLX(1). */
2fc8bdac 10902 inst.instruction = 0xf000e800;
0855e32b 10903 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
10904 }
10905}
10906
c19d1205
ZW
10907static void
10908do_t_branch (void)
b99bd4ef 10909{
0110f2b8 10910 int opcode;
dfa9f0d5 10911 int cond;
9ae92b05 10912 int reloc;
dfa9f0d5 10913
e07e6e58
NC
10914 cond = inst.cond;
10915 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10916
10917 if (in_it_block ())
dfa9f0d5
PB
10918 {
10919 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 10920 branches. */
dfa9f0d5 10921 cond = COND_ALWAYS;
dfa9f0d5
PB
10922 }
10923 else
10924 cond = inst.cond;
10925
10926 if (cond != COND_ALWAYS)
0110f2b8
PB
10927 opcode = T_MNEM_bcond;
10928 else
10929 opcode = inst.instruction;
10930
12d6b0b7
RS
10931 if (unified_syntax
10932 && (inst.size_req == 4
10960bfb
PB
10933 || (inst.size_req != 2
10934 && (inst.operands[0].hasreloc
10935 || inst.reloc.exp.X_op == O_constant))))
c19d1205 10936 {
0110f2b8 10937 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 10938 if (cond == COND_ALWAYS)
9ae92b05 10939 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
10940 else
10941 {
9c2799c2 10942 gas_assert (cond != 0xF);
dfa9f0d5 10943 inst.instruction |= cond << 22;
9ae92b05 10944 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
10945 }
10946 }
b99bd4ef
NC
10947 else
10948 {
0110f2b8 10949 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 10950 if (cond == COND_ALWAYS)
9ae92b05 10951 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 10952 else
b99bd4ef 10953 {
dfa9f0d5 10954 inst.instruction |= cond << 8;
9ae92b05 10955 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 10956 }
0110f2b8
PB
10957 /* Allow section relaxation. */
10958 if (unified_syntax && inst.size_req != 2)
10959 inst.relax = opcode;
b99bd4ef 10960 }
9ae92b05 10961 inst.reloc.type = reloc;
c19d1205 10962 inst.reloc.pc_rel = 1;
b99bd4ef
NC
10963}
10964
8884b720 10965/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 10966 between the two is the maximum immediate allowed - which is passed in
8884b720 10967 RANGE. */
b99bd4ef 10968static void
8884b720 10969do_t_bkpt_hlt1 (int range)
b99bd4ef 10970{
dfa9f0d5
PB
10971 constraint (inst.cond != COND_ALWAYS,
10972 _("instruction is always unconditional"));
c19d1205 10973 if (inst.operands[0].present)
b99bd4ef 10974 {
8884b720 10975 constraint (inst.operands[0].imm > range,
c19d1205
ZW
10976 _("immediate value out of range"));
10977 inst.instruction |= inst.operands[0].imm;
b99bd4ef 10978 }
8884b720
MGD
10979
10980 set_it_insn_type (NEUTRAL_IT_INSN);
10981}
10982
10983static void
10984do_t_hlt (void)
10985{
10986 do_t_bkpt_hlt1 (63);
10987}
10988
10989static void
10990do_t_bkpt (void)
10991{
10992 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
10993}
10994
10995static void
c19d1205 10996do_t_branch23 (void)
b99bd4ef 10997{
e07e6e58 10998 set_it_insn_type_last ();
0855e32b 10999 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11000
0855e32b
NS
11001 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11002 this file. We used to simply ignore the PLT reloc type here --
11003 the branch encoding is now needed to deal with TLSCALL relocs.
11004 So if we see a PLT reloc now, put it back to how it used to be to
11005 keep the preexisting behaviour. */
11006 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11007 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11008
4343666d 11009#if defined(OBJ_COFF)
c19d1205
ZW
11010 /* If the destination of the branch is a defined symbol which does not have
11011 the THUMB_FUNC attribute, then we must be calling a function which has
11012 the (interfacearm) attribute. We look for the Thumb entry point to that
11013 function and change the branch to refer to that function instead. */
11014 if ( inst.reloc.exp.X_op == O_symbol
11015 && inst.reloc.exp.X_add_symbol != NULL
11016 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11017 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11018 inst.reloc.exp.X_add_symbol =
11019 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11020#endif
90e4755a
RE
11021}
11022
11023static void
c19d1205 11024do_t_bx (void)
90e4755a 11025{
e07e6e58 11026 set_it_insn_type_last ();
c19d1205
ZW
11027 inst.instruction |= inst.operands[0].reg << 3;
11028 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11029 should cause the alignment to be checked once it is known. This is
11030 because BX PC only works if the instruction is word aligned. */
11031}
90e4755a 11032
c19d1205
ZW
11033static void
11034do_t_bxj (void)
11035{
fdfde340 11036 int Rm;
90e4755a 11037
e07e6e58 11038 set_it_insn_type_last ();
fdfde340
JM
11039 Rm = inst.operands[0].reg;
11040 reject_bad_reg (Rm);
11041 inst.instruction |= Rm << 16;
90e4755a
RE
11042}
11043
11044static void
c19d1205 11045do_t_clz (void)
90e4755a 11046{
fdfde340
JM
11047 unsigned Rd;
11048 unsigned Rm;
11049
11050 Rd = inst.operands[0].reg;
11051 Rm = inst.operands[1].reg;
11052
11053 reject_bad_reg (Rd);
11054 reject_bad_reg (Rm);
11055
11056 inst.instruction |= Rd << 8;
11057 inst.instruction |= Rm << 16;
11058 inst.instruction |= Rm;
c19d1205 11059}
90e4755a 11060
dfa9f0d5
PB
11061static void
11062do_t_cps (void)
11063{
e07e6e58 11064 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11065 inst.instruction |= inst.operands[0].imm;
11066}
11067
c19d1205
ZW
11068static void
11069do_t_cpsi (void)
11070{
e07e6e58 11071 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11072 if (unified_syntax
62b3e311
PB
11073 && (inst.operands[1].present || inst.size_req == 4)
11074 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11075 {
c19d1205
ZW
11076 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11077 inst.instruction = 0xf3af8000;
11078 inst.instruction |= imod << 9;
11079 inst.instruction |= inst.operands[0].imm << 5;
11080 if (inst.operands[1].present)
11081 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11082 }
c19d1205 11083 else
90e4755a 11084 {
62b3e311
PB
11085 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11086 && (inst.operands[0].imm & 4),
11087 _("selected processor does not support 'A' form "
11088 "of this instruction"));
11089 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11090 _("Thumb does not support the 2-argument "
11091 "form of this instruction"));
11092 inst.instruction |= inst.operands[0].imm;
90e4755a 11093 }
90e4755a
RE
11094}
11095
c19d1205
ZW
11096/* THUMB CPY instruction (argument parse). */
11097
90e4755a 11098static void
c19d1205 11099do_t_cpy (void)
90e4755a 11100{
c19d1205 11101 if (inst.size_req == 4)
90e4755a 11102 {
c19d1205
ZW
11103 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11104 inst.instruction |= inst.operands[0].reg << 8;
11105 inst.instruction |= inst.operands[1].reg;
90e4755a 11106 }
c19d1205 11107 else
90e4755a 11108 {
c19d1205
ZW
11109 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11110 inst.instruction |= (inst.operands[0].reg & 0x7);
11111 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11112 }
90e4755a
RE
11113}
11114
90e4755a 11115static void
25fe350b 11116do_t_cbz (void)
90e4755a 11117{
e07e6e58 11118 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11119 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11120 inst.instruction |= inst.operands[0].reg;
11121 inst.reloc.pc_rel = 1;
11122 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11123}
90e4755a 11124
62b3e311
PB
11125static void
11126do_t_dbg (void)
11127{
11128 inst.instruction |= inst.operands[0].imm;
11129}
11130
11131static void
11132do_t_div (void)
11133{
fdfde340
JM
11134 unsigned Rd, Rn, Rm;
11135
11136 Rd = inst.operands[0].reg;
11137 Rn = (inst.operands[1].present
11138 ? inst.operands[1].reg : Rd);
11139 Rm = inst.operands[2].reg;
11140
11141 reject_bad_reg (Rd);
11142 reject_bad_reg (Rn);
11143 reject_bad_reg (Rm);
11144
11145 inst.instruction |= Rd << 8;
11146 inst.instruction |= Rn << 16;
11147 inst.instruction |= Rm;
62b3e311
PB
11148}
11149
c19d1205
ZW
11150static void
11151do_t_hint (void)
11152{
11153 if (unified_syntax && inst.size_req == 4)
11154 inst.instruction = THUMB_OP32 (inst.instruction);
11155 else
11156 inst.instruction = THUMB_OP16 (inst.instruction);
11157}
90e4755a 11158
c19d1205
ZW
11159static void
11160do_t_it (void)
11161{
11162 unsigned int cond = inst.operands[0].imm;
e27ec89e 11163
e07e6e58
NC
11164 set_it_insn_type (IT_INSN);
11165 now_it.mask = (inst.instruction & 0xf) | 0x10;
11166 now_it.cc = cond;
5a01bb1d 11167 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11168
11169 /* If the condition is a negative condition, invert the mask. */
c19d1205 11170 if ((cond & 0x1) == 0x0)
90e4755a 11171 {
c19d1205 11172 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11173
c19d1205 11174 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11175 {
11176 /* No conversion needed. */
11177 now_it.block_length = 1;
11178 }
c19d1205 11179 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11180 {
11181 mask ^= 0x8;
11182 now_it.block_length = 2;
11183 }
e27ec89e 11184 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11185 {
11186 mask ^= 0xC;
11187 now_it.block_length = 3;
11188 }
c19d1205 11189 else
5a01bb1d
MGD
11190 {
11191 mask ^= 0xE;
11192 now_it.block_length = 4;
11193 }
90e4755a 11194
e27ec89e
PB
11195 inst.instruction &= 0xfff0;
11196 inst.instruction |= mask;
c19d1205 11197 }
90e4755a 11198
c19d1205
ZW
11199 inst.instruction |= cond << 4;
11200}
90e4755a 11201
3c707909
PB
11202/* Helper function used for both push/pop and ldm/stm. */
11203static void
11204encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11205{
11206 bfd_boolean load;
11207
11208 load = (inst.instruction & (1 << 20)) != 0;
11209
11210 if (mask & (1 << 13))
11211 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11212
11213 if ((mask & (1 << base)) != 0
11214 && writeback)
11215 inst.error = _("having the base register in the register list when "
11216 "using write back is UNPREDICTABLE");
11217
3c707909
PB
11218 if (load)
11219 {
e07e6e58 11220 if (mask & (1 << 15))
477330fc
RM
11221 {
11222 if (mask & (1 << 14))
11223 inst.error = _("LR and PC should not both be in register list");
11224 else
11225 set_it_insn_type_last ();
11226 }
3c707909
PB
11227 }
11228 else
11229 {
11230 if (mask & (1 << 15))
11231 inst.error = _("PC not allowed in register list");
3c707909
PB
11232 }
11233
11234 if ((mask & (mask - 1)) == 0)
11235 {
11236 /* Single register transfers implemented as str/ldr. */
11237 if (writeback)
11238 {
11239 if (inst.instruction & (1 << 23))
11240 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11241 else
11242 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11243 }
11244 else
11245 {
11246 if (inst.instruction & (1 << 23))
11247 inst.instruction = 0x00800000; /* ia -> [base] */
11248 else
11249 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11250 }
11251
11252 inst.instruction |= 0xf8400000;
11253 if (load)
11254 inst.instruction |= 0x00100000;
11255
5f4273c7 11256 mask = ffs (mask) - 1;
3c707909
PB
11257 mask <<= 12;
11258 }
11259 else if (writeback)
11260 inst.instruction |= WRITE_BACK;
11261
11262 inst.instruction |= mask;
11263 inst.instruction |= base << 16;
11264}
11265
c19d1205
ZW
11266static void
11267do_t_ldmstm (void)
11268{
11269 /* This really doesn't seem worth it. */
11270 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11271 _("expression too complex"));
11272 constraint (inst.operands[1].writeback,
11273 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11274
c19d1205
ZW
11275 if (unified_syntax)
11276 {
3c707909
PB
11277 bfd_boolean narrow;
11278 unsigned mask;
11279
11280 narrow = FALSE;
c19d1205
ZW
11281 /* See if we can use a 16-bit instruction. */
11282 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11283 && inst.size_req != 4
3c707909 11284 && !(inst.operands[1].imm & ~0xff))
90e4755a 11285 {
3c707909 11286 mask = 1 << inst.operands[0].reg;
90e4755a 11287
eab4f823 11288 if (inst.operands[0].reg <= 7)
90e4755a 11289 {
3c707909 11290 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11291 ? inst.operands[0].writeback
11292 : (inst.operands[0].writeback
11293 == !(inst.operands[1].imm & mask)))
477330fc 11294 {
eab4f823
MGD
11295 if (inst.instruction == T_MNEM_stmia
11296 && (inst.operands[1].imm & mask)
11297 && (inst.operands[1].imm & (mask - 1)))
11298 as_warn (_("value stored for r%d is UNKNOWN"),
11299 inst.operands[0].reg);
3c707909 11300
eab4f823
MGD
11301 inst.instruction = THUMB_OP16 (inst.instruction);
11302 inst.instruction |= inst.operands[0].reg << 8;
11303 inst.instruction |= inst.operands[1].imm;
11304 narrow = TRUE;
11305 }
11306 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11307 {
11308 /* This means 1 register in reg list one of 3 situations:
11309 1. Instruction is stmia, but without writeback.
11310 2. lmdia without writeback, but with Rn not in
477330fc 11311 reglist.
eab4f823
MGD
11312 3. ldmia with writeback, but with Rn in reglist.
11313 Case 3 is UNPREDICTABLE behaviour, so we handle
11314 case 1 and 2 which can be converted into a 16-bit
11315 str or ldr. The SP cases are handled below. */
11316 unsigned long opcode;
11317 /* First, record an error for Case 3. */
11318 if (inst.operands[1].imm & mask
11319 && inst.operands[0].writeback)
fa94de6b 11320 inst.error =
eab4f823
MGD
11321 _("having the base register in the register list when "
11322 "using write back is UNPREDICTABLE");
fa94de6b
RM
11323
11324 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11325 : T_MNEM_ldr);
11326 inst.instruction = THUMB_OP16 (opcode);
11327 inst.instruction |= inst.operands[0].reg << 3;
11328 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11329 narrow = TRUE;
11330 }
90e4755a 11331 }
eab4f823 11332 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11333 {
eab4f823
MGD
11334 if (inst.operands[0].writeback)
11335 {
fa94de6b 11336 inst.instruction =
eab4f823 11337 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11338 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11339 inst.instruction |= inst.operands[1].imm;
477330fc 11340 narrow = TRUE;
eab4f823
MGD
11341 }
11342 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11343 {
fa94de6b 11344 inst.instruction =
eab4f823 11345 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11346 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11347 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11348 narrow = TRUE;
eab4f823 11349 }
90e4755a 11350 }
3c707909
PB
11351 }
11352
11353 if (!narrow)
11354 {
c19d1205
ZW
11355 if (inst.instruction < 0xffff)
11356 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11357
5f4273c7
NC
11358 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11359 inst.operands[0].writeback);
90e4755a
RE
11360 }
11361 }
c19d1205 11362 else
90e4755a 11363 {
c19d1205
ZW
11364 constraint (inst.operands[0].reg > 7
11365 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11366 constraint (inst.instruction != T_MNEM_ldmia
11367 && inst.instruction != T_MNEM_stmia,
11368 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11369 if (inst.instruction == T_MNEM_stmia)
f03698e6 11370 {
c19d1205
ZW
11371 if (!inst.operands[0].writeback)
11372 as_warn (_("this instruction will write back the base register"));
11373 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11374 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11375 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11376 inst.operands[0].reg);
f03698e6 11377 }
c19d1205 11378 else
90e4755a 11379 {
c19d1205
ZW
11380 if (!inst.operands[0].writeback
11381 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11382 as_warn (_("this instruction will write back the base register"));
11383 else if (inst.operands[0].writeback
11384 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11385 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11386 }
11387
c19d1205
ZW
11388 inst.instruction = THUMB_OP16 (inst.instruction);
11389 inst.instruction |= inst.operands[0].reg << 8;
11390 inst.instruction |= inst.operands[1].imm;
11391 }
11392}
e28cd48c 11393
c19d1205
ZW
11394static void
11395do_t_ldrex (void)
11396{
11397 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11398 || inst.operands[1].postind || inst.operands[1].writeback
11399 || inst.operands[1].immisreg || inst.operands[1].shifted
11400 || inst.operands[1].negative,
01cfc07f 11401 BAD_ADDR_MODE);
e28cd48c 11402
5be8be5d
DG
11403 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11404
c19d1205
ZW
11405 inst.instruction |= inst.operands[0].reg << 12;
11406 inst.instruction |= inst.operands[1].reg << 16;
11407 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11408}
e28cd48c 11409
c19d1205
ZW
11410static void
11411do_t_ldrexd (void)
11412{
11413 if (!inst.operands[1].present)
1cac9012 11414 {
c19d1205
ZW
11415 constraint (inst.operands[0].reg == REG_LR,
11416 _("r14 not allowed as first register "
11417 "when second register is omitted"));
11418 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11419 }
c19d1205
ZW
11420 constraint (inst.operands[0].reg == inst.operands[1].reg,
11421 BAD_OVERLAP);
b99bd4ef 11422
c19d1205
ZW
11423 inst.instruction |= inst.operands[0].reg << 12;
11424 inst.instruction |= inst.operands[1].reg << 8;
11425 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11426}
11427
11428static void
c19d1205 11429do_t_ldst (void)
b99bd4ef 11430{
0110f2b8
PB
11431 unsigned long opcode;
11432 int Rn;
11433
e07e6e58
NC
11434 if (inst.operands[0].isreg
11435 && !inst.operands[0].preind
11436 && inst.operands[0].reg == REG_PC)
11437 set_it_insn_type_last ();
11438
0110f2b8 11439 opcode = inst.instruction;
c19d1205 11440 if (unified_syntax)
b99bd4ef 11441 {
53365c0d
PB
11442 if (!inst.operands[1].isreg)
11443 {
11444 if (opcode <= 0xffff)
11445 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11446 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11447 return;
11448 }
0110f2b8
PB
11449 if (inst.operands[1].isreg
11450 && !inst.operands[1].writeback
c19d1205
ZW
11451 && !inst.operands[1].shifted && !inst.operands[1].postind
11452 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11453 && opcode <= 0xffff
11454 && inst.size_req != 4)
c19d1205 11455 {
0110f2b8
PB
11456 /* Insn may have a 16-bit form. */
11457 Rn = inst.operands[1].reg;
11458 if (inst.operands[1].immisreg)
11459 {
11460 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11461 /* [Rn, Rik] */
0110f2b8
PB
11462 if (Rn <= 7 && inst.operands[1].imm <= 7)
11463 goto op16;
5be8be5d
DG
11464 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11465 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11466 }
11467 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11468 && opcode != T_MNEM_ldrsb)
11469 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11470 || (Rn == REG_SP && opcode == T_MNEM_str))
11471 {
11472 /* [Rn, #const] */
11473 if (Rn > 7)
11474 {
11475 if (Rn == REG_PC)
11476 {
11477 if (inst.reloc.pc_rel)
11478 opcode = T_MNEM_ldr_pc2;
11479 else
11480 opcode = T_MNEM_ldr_pc;
11481 }
11482 else
11483 {
11484 if (opcode == T_MNEM_ldr)
11485 opcode = T_MNEM_ldr_sp;
11486 else
11487 opcode = T_MNEM_str_sp;
11488 }
11489 inst.instruction = inst.operands[0].reg << 8;
11490 }
11491 else
11492 {
11493 inst.instruction = inst.operands[0].reg;
11494 inst.instruction |= inst.operands[1].reg << 3;
11495 }
11496 inst.instruction |= THUMB_OP16 (opcode);
11497 if (inst.size_req == 2)
11498 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11499 else
11500 inst.relax = opcode;
11501 return;
11502 }
c19d1205 11503 }
0110f2b8 11504 /* Definitely a 32-bit variant. */
5be8be5d 11505
8d67f500
NC
11506 /* Warning for Erratum 752419. */
11507 if (opcode == T_MNEM_ldr
11508 && inst.operands[0].reg == REG_SP
11509 && inst.operands[1].writeback == 1
11510 && !inst.operands[1].immisreg)
11511 {
11512 if (no_cpu_selected ()
11513 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11514 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11515 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11516 as_warn (_("This instruction may be unpredictable "
11517 "if executed on M-profile cores "
11518 "with interrupts enabled."));
11519 }
11520
5be8be5d 11521 /* Do some validations regarding addressing modes. */
1be5fd2e 11522 if (inst.operands[1].immisreg)
5be8be5d
DG
11523 reject_bad_reg (inst.operands[1].imm);
11524
1be5fd2e
NC
11525 constraint (inst.operands[1].writeback == 1
11526 && inst.operands[0].reg == inst.operands[1].reg,
11527 BAD_OVERLAP);
11528
0110f2b8 11529 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11530 inst.instruction |= inst.operands[0].reg << 12;
11531 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11532 check_ldr_r15_aligned ();
b99bd4ef
NC
11533 return;
11534 }
11535
c19d1205
ZW
11536 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11537
11538 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11539 {
c19d1205
ZW
11540 /* Only [Rn,Rm] is acceptable. */
11541 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11542 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11543 || inst.operands[1].postind || inst.operands[1].shifted
11544 || inst.operands[1].negative,
11545 _("Thumb does not support this addressing mode"));
11546 inst.instruction = THUMB_OP16 (inst.instruction);
11547 goto op16;
b99bd4ef 11548 }
5f4273c7 11549
c19d1205
ZW
11550 inst.instruction = THUMB_OP16 (inst.instruction);
11551 if (!inst.operands[1].isreg)
8335d6aa 11552 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11553 return;
b99bd4ef 11554
c19d1205
ZW
11555 constraint (!inst.operands[1].preind
11556 || inst.operands[1].shifted
11557 || inst.operands[1].writeback,
11558 _("Thumb does not support this addressing mode"));
11559 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11560 {
c19d1205
ZW
11561 constraint (inst.instruction & 0x0600,
11562 _("byte or halfword not valid for base register"));
11563 constraint (inst.operands[1].reg == REG_PC
11564 && !(inst.instruction & THUMB_LOAD_BIT),
11565 _("r15 based store not allowed"));
11566 constraint (inst.operands[1].immisreg,
11567 _("invalid base register for register offset"));
b99bd4ef 11568
c19d1205
ZW
11569 if (inst.operands[1].reg == REG_PC)
11570 inst.instruction = T_OPCODE_LDR_PC;
11571 else if (inst.instruction & THUMB_LOAD_BIT)
11572 inst.instruction = T_OPCODE_LDR_SP;
11573 else
11574 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11575
c19d1205
ZW
11576 inst.instruction |= inst.operands[0].reg << 8;
11577 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11578 return;
11579 }
90e4755a 11580
c19d1205
ZW
11581 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11582 if (!inst.operands[1].immisreg)
11583 {
11584 /* Immediate offset. */
11585 inst.instruction |= inst.operands[0].reg;
11586 inst.instruction |= inst.operands[1].reg << 3;
11587 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11588 return;
11589 }
90e4755a 11590
c19d1205
ZW
11591 /* Register offset. */
11592 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11593 constraint (inst.operands[1].negative,
11594 _("Thumb does not support this addressing mode"));
90e4755a 11595
c19d1205
ZW
11596 op16:
11597 switch (inst.instruction)
11598 {
11599 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11600 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11601 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11602 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11603 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11604 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11605 case 0x5600 /* ldrsb */:
11606 case 0x5e00 /* ldrsh */: break;
11607 default: abort ();
11608 }
90e4755a 11609
c19d1205
ZW
11610 inst.instruction |= inst.operands[0].reg;
11611 inst.instruction |= inst.operands[1].reg << 3;
11612 inst.instruction |= inst.operands[1].imm << 6;
11613}
90e4755a 11614
c19d1205
ZW
11615static void
11616do_t_ldstd (void)
11617{
11618 if (!inst.operands[1].present)
b99bd4ef 11619 {
c19d1205
ZW
11620 inst.operands[1].reg = inst.operands[0].reg + 1;
11621 constraint (inst.operands[0].reg == REG_LR,
11622 _("r14 not allowed here"));
bd340a04 11623 constraint (inst.operands[0].reg == REG_R12,
477330fc 11624 _("r12 not allowed here"));
b99bd4ef 11625 }
bd340a04
MGD
11626
11627 if (inst.operands[2].writeback
11628 && (inst.operands[0].reg == inst.operands[2].reg
11629 || inst.operands[1].reg == inst.operands[2].reg))
11630 as_warn (_("base register written back, and overlaps "
477330fc 11631 "one of transfer registers"));
bd340a04 11632
c19d1205
ZW
11633 inst.instruction |= inst.operands[0].reg << 12;
11634 inst.instruction |= inst.operands[1].reg << 8;
11635 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11636}
11637
c19d1205
ZW
11638static void
11639do_t_ldstt (void)
11640{
11641 inst.instruction |= inst.operands[0].reg << 12;
11642 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11643}
a737bd4d 11644
b99bd4ef 11645static void
c19d1205 11646do_t_mla (void)
b99bd4ef 11647{
fdfde340 11648 unsigned Rd, Rn, Rm, Ra;
c921be7d 11649
fdfde340
JM
11650 Rd = inst.operands[0].reg;
11651 Rn = inst.operands[1].reg;
11652 Rm = inst.operands[2].reg;
11653 Ra = inst.operands[3].reg;
11654
11655 reject_bad_reg (Rd);
11656 reject_bad_reg (Rn);
11657 reject_bad_reg (Rm);
11658 reject_bad_reg (Ra);
11659
11660 inst.instruction |= Rd << 8;
11661 inst.instruction |= Rn << 16;
11662 inst.instruction |= Rm;
11663 inst.instruction |= Ra << 12;
c19d1205 11664}
b99bd4ef 11665
c19d1205
ZW
11666static void
11667do_t_mlal (void)
11668{
fdfde340
JM
11669 unsigned RdLo, RdHi, Rn, Rm;
11670
11671 RdLo = inst.operands[0].reg;
11672 RdHi = inst.operands[1].reg;
11673 Rn = inst.operands[2].reg;
11674 Rm = inst.operands[3].reg;
11675
11676 reject_bad_reg (RdLo);
11677 reject_bad_reg (RdHi);
11678 reject_bad_reg (Rn);
11679 reject_bad_reg (Rm);
11680
11681 inst.instruction |= RdLo << 12;
11682 inst.instruction |= RdHi << 8;
11683 inst.instruction |= Rn << 16;
11684 inst.instruction |= Rm;
c19d1205 11685}
b99bd4ef 11686
c19d1205
ZW
11687static void
11688do_t_mov_cmp (void)
11689{
fdfde340
JM
11690 unsigned Rn, Rm;
11691
11692 Rn = inst.operands[0].reg;
11693 Rm = inst.operands[1].reg;
11694
e07e6e58
NC
11695 if (Rn == REG_PC)
11696 set_it_insn_type_last ();
11697
c19d1205 11698 if (unified_syntax)
b99bd4ef 11699 {
c19d1205
ZW
11700 int r0off = (inst.instruction == T_MNEM_mov
11701 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11702 unsigned long opcode;
3d388997
PB
11703 bfd_boolean narrow;
11704 bfd_boolean low_regs;
11705
fdfde340 11706 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11707 opcode = inst.instruction;
e07e6e58 11708 if (in_it_block ())
0110f2b8 11709 narrow = opcode != T_MNEM_movs;
3d388997 11710 else
0110f2b8 11711 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11712 if (inst.size_req == 4
11713 || inst.operands[1].shifted)
11714 narrow = FALSE;
11715
efd81785
PB
11716 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11717 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11718 && !inst.operands[1].shifted
fdfde340
JM
11719 && Rn == REG_PC
11720 && Rm == REG_LR)
efd81785
PB
11721 {
11722 inst.instruction = T2_SUBS_PC_LR;
11723 return;
11724 }
11725
fdfde340
JM
11726 if (opcode == T_MNEM_cmp)
11727 {
11728 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11729 if (narrow)
11730 {
11731 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11732 but valid. */
11733 warn_deprecated_sp (Rm);
11734 /* R15 was documented as a valid choice for Rm in ARMv6,
11735 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11736 tools reject R15, so we do too. */
11737 constraint (Rm == REG_PC, BAD_PC);
11738 }
11739 else
11740 reject_bad_reg (Rm);
fdfde340
JM
11741 }
11742 else if (opcode == T_MNEM_mov
11743 || opcode == T_MNEM_movs)
11744 {
11745 if (inst.operands[1].isreg)
11746 {
11747 if (opcode == T_MNEM_movs)
11748 {
11749 reject_bad_reg (Rn);
11750 reject_bad_reg (Rm);
11751 }
76fa04a4
MGD
11752 else if (narrow)
11753 {
11754 /* This is mov.n. */
11755 if ((Rn == REG_SP || Rn == REG_PC)
11756 && (Rm == REG_SP || Rm == REG_PC))
11757 {
5c3696f8 11758 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11759 "deprecated when r%u is the destination "
11760 "register."), Rm, Rn);
11761 }
11762 }
11763 else
11764 {
11765 /* This is mov.w. */
11766 constraint (Rn == REG_PC, BAD_PC);
11767 constraint (Rm == REG_PC, BAD_PC);
11768 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11769 }
fdfde340
JM
11770 }
11771 else
11772 reject_bad_reg (Rn);
11773 }
11774
c19d1205
ZW
11775 if (!inst.operands[1].isreg)
11776 {
0110f2b8 11777 /* Immediate operand. */
e07e6e58 11778 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11779 narrow = 0;
11780 if (low_regs && narrow)
11781 {
11782 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11783 inst.instruction |= Rn << 8;
0110f2b8 11784 if (inst.size_req == 2)
72d98d16
MG
11785 {
11786 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11787 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
11788 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11789 }
0110f2b8 11790 else
72d98d16 11791 inst.relax = opcode;
0110f2b8
PB
11792 }
11793 else
11794 {
11795 inst.instruction = THUMB_OP32 (inst.instruction);
11796 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11797 inst.instruction |= Rn << r0off;
0110f2b8
PB
11798 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11799 }
c19d1205 11800 }
728ca7c9
PB
11801 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11802 && (inst.instruction == T_MNEM_mov
11803 || inst.instruction == T_MNEM_movs))
11804 {
11805 /* Register shifts are encoded as separate shift instructions. */
11806 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11807
e07e6e58 11808 if (in_it_block ())
728ca7c9
PB
11809 narrow = !flags;
11810 else
11811 narrow = flags;
11812
11813 if (inst.size_req == 4)
11814 narrow = FALSE;
11815
11816 if (!low_regs || inst.operands[1].imm > 7)
11817 narrow = FALSE;
11818
fdfde340 11819 if (Rn != Rm)
728ca7c9
PB
11820 narrow = FALSE;
11821
11822 switch (inst.operands[1].shift_kind)
11823 {
11824 case SHIFT_LSL:
11825 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11826 break;
11827 case SHIFT_ASR:
11828 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11829 break;
11830 case SHIFT_LSR:
11831 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11832 break;
11833 case SHIFT_ROR:
11834 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11835 break;
11836 default:
5f4273c7 11837 abort ();
728ca7c9
PB
11838 }
11839
11840 inst.instruction = opcode;
11841 if (narrow)
11842 {
fdfde340 11843 inst.instruction |= Rn;
728ca7c9
PB
11844 inst.instruction |= inst.operands[1].imm << 3;
11845 }
11846 else
11847 {
11848 if (flags)
11849 inst.instruction |= CONDS_BIT;
11850
fdfde340
JM
11851 inst.instruction |= Rn << 8;
11852 inst.instruction |= Rm << 16;
728ca7c9
PB
11853 inst.instruction |= inst.operands[1].imm;
11854 }
11855 }
3d388997 11856 else if (!narrow)
c19d1205 11857 {
728ca7c9
PB
11858 /* Some mov with immediate shift have narrow variants.
11859 Register shifts are handled above. */
11860 if (low_regs && inst.operands[1].shifted
11861 && (inst.instruction == T_MNEM_mov
11862 || inst.instruction == T_MNEM_movs))
11863 {
e07e6e58 11864 if (in_it_block ())
728ca7c9
PB
11865 narrow = (inst.instruction == T_MNEM_mov);
11866 else
11867 narrow = (inst.instruction == T_MNEM_movs);
11868 }
11869
11870 if (narrow)
11871 {
11872 switch (inst.operands[1].shift_kind)
11873 {
11874 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11875 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11876 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11877 default: narrow = FALSE; break;
11878 }
11879 }
11880
11881 if (narrow)
11882 {
fdfde340
JM
11883 inst.instruction |= Rn;
11884 inst.instruction |= Rm << 3;
728ca7c9
PB
11885 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11886 }
11887 else
11888 {
11889 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11890 inst.instruction |= Rn << r0off;
728ca7c9
PB
11891 encode_thumb32_shifted_operand (1);
11892 }
c19d1205
ZW
11893 }
11894 else
11895 switch (inst.instruction)
11896 {
11897 case T_MNEM_mov:
837b3435 11898 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
11899 results. Don't allow this. */
11900 if (low_regs)
11901 {
11902 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11903 "MOV Rd, Rs with two low registers is not "
11904 "permitted on this architecture");
fa94de6b 11905 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
11906 arm_ext_v6);
11907 }
11908
c19d1205 11909 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
11910 inst.instruction |= (Rn & 0x8) << 4;
11911 inst.instruction |= (Rn & 0x7);
11912 inst.instruction |= Rm << 3;
c19d1205 11913 break;
b99bd4ef 11914
c19d1205
ZW
11915 case T_MNEM_movs:
11916 /* We know we have low registers at this point.
941a8a52
MGD
11917 Generate LSLS Rd, Rs, #0. */
11918 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
11919 inst.instruction |= Rn;
11920 inst.instruction |= Rm << 3;
c19d1205
ZW
11921 break;
11922
11923 case T_MNEM_cmp:
3d388997 11924 if (low_regs)
c19d1205
ZW
11925 {
11926 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
11927 inst.instruction |= Rn;
11928 inst.instruction |= Rm << 3;
c19d1205
ZW
11929 }
11930 else
11931 {
11932 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
11933 inst.instruction |= (Rn & 0x8) << 4;
11934 inst.instruction |= (Rn & 0x7);
11935 inst.instruction |= Rm << 3;
c19d1205
ZW
11936 }
11937 break;
11938 }
b99bd4ef
NC
11939 return;
11940 }
11941
c19d1205 11942 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
11943
11944 /* PR 10443: Do not silently ignore shifted operands. */
11945 constraint (inst.operands[1].shifted,
11946 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
11947
c19d1205 11948 if (inst.operands[1].isreg)
b99bd4ef 11949 {
fdfde340 11950 if (Rn < 8 && Rm < 8)
b99bd4ef 11951 {
c19d1205
ZW
11952 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11953 since a MOV instruction produces unpredictable results. */
11954 if (inst.instruction == T_OPCODE_MOV_I8)
11955 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 11956 else
c19d1205 11957 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 11958
fdfde340
JM
11959 inst.instruction |= Rn;
11960 inst.instruction |= Rm << 3;
b99bd4ef
NC
11961 }
11962 else
11963 {
c19d1205
ZW
11964 if (inst.instruction == T_OPCODE_MOV_I8)
11965 inst.instruction = T_OPCODE_MOV_HR;
11966 else
11967 inst.instruction = T_OPCODE_CMP_HR;
11968 do_t_cpy ();
b99bd4ef
NC
11969 }
11970 }
c19d1205 11971 else
b99bd4ef 11972 {
fdfde340 11973 constraint (Rn > 7,
c19d1205 11974 _("only lo regs allowed with immediate"));
fdfde340 11975 inst.instruction |= Rn << 8;
c19d1205
ZW
11976 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11977 }
11978}
b99bd4ef 11979
c19d1205
ZW
11980static void
11981do_t_mov16 (void)
11982{
fdfde340 11983 unsigned Rd;
b6895b4f
PB
11984 bfd_vma imm;
11985 bfd_boolean top;
11986
11987 top = (inst.instruction & 0x00800000) != 0;
11988 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
11989 {
11990 constraint (top, _(":lower16: not allowed this instruction"));
11991 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
11992 }
11993 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
11994 {
11995 constraint (!top, _(":upper16: not allowed this instruction"));
11996 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
11997 }
11998
fdfde340
JM
11999 Rd = inst.operands[0].reg;
12000 reject_bad_reg (Rd);
12001
12002 inst.instruction |= Rd << 8;
b6895b4f
PB
12003 if (inst.reloc.type == BFD_RELOC_UNUSED)
12004 {
12005 imm = inst.reloc.exp.X_add_number;
12006 inst.instruction |= (imm & 0xf000) << 4;
12007 inst.instruction |= (imm & 0x0800) << 15;
12008 inst.instruction |= (imm & 0x0700) << 4;
12009 inst.instruction |= (imm & 0x00ff);
12010 }
c19d1205 12011}
b99bd4ef 12012
c19d1205
ZW
12013static void
12014do_t_mvn_tst (void)
12015{
fdfde340 12016 unsigned Rn, Rm;
c921be7d 12017
fdfde340
JM
12018 Rn = inst.operands[0].reg;
12019 Rm = inst.operands[1].reg;
12020
12021 if (inst.instruction == T_MNEM_cmp
12022 || inst.instruction == T_MNEM_cmn)
12023 constraint (Rn == REG_PC, BAD_PC);
12024 else
12025 reject_bad_reg (Rn);
12026 reject_bad_reg (Rm);
12027
c19d1205
ZW
12028 if (unified_syntax)
12029 {
12030 int r0off = (inst.instruction == T_MNEM_mvn
12031 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12032 bfd_boolean narrow;
12033
12034 if (inst.size_req == 4
12035 || inst.instruction > 0xffff
12036 || inst.operands[1].shifted
fdfde340 12037 || Rn > 7 || Rm > 7)
3d388997 12038 narrow = FALSE;
fe8b4cc3
KT
12039 else if (inst.instruction == T_MNEM_cmn
12040 || inst.instruction == T_MNEM_tst)
3d388997
PB
12041 narrow = TRUE;
12042 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12043 narrow = !in_it_block ();
3d388997 12044 else
e07e6e58 12045 narrow = in_it_block ();
3d388997 12046
c19d1205 12047 if (!inst.operands[1].isreg)
b99bd4ef 12048 {
c19d1205
ZW
12049 /* For an immediate, we always generate a 32-bit opcode;
12050 section relaxation will shrink it later if possible. */
12051 if (inst.instruction < 0xffff)
12052 inst.instruction = THUMB_OP32 (inst.instruction);
12053 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12054 inst.instruction |= Rn << r0off;
c19d1205 12055 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12056 }
c19d1205 12057 else
b99bd4ef 12058 {
c19d1205 12059 /* See if we can do this with a 16-bit instruction. */
3d388997 12060 if (narrow)
b99bd4ef 12061 {
c19d1205 12062 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12063 inst.instruction |= Rn;
12064 inst.instruction |= Rm << 3;
b99bd4ef 12065 }
c19d1205 12066 else
b99bd4ef 12067 {
c19d1205
ZW
12068 constraint (inst.operands[1].shifted
12069 && inst.operands[1].immisreg,
12070 _("shift must be constant"));
12071 if (inst.instruction < 0xffff)
12072 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12073 inst.instruction |= Rn << r0off;
c19d1205 12074 encode_thumb32_shifted_operand (1);
b99bd4ef 12075 }
b99bd4ef
NC
12076 }
12077 }
12078 else
12079 {
c19d1205
ZW
12080 constraint (inst.instruction > 0xffff
12081 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12082 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12083 _("unshifted register required"));
fdfde340 12084 constraint (Rn > 7 || Rm > 7,
c19d1205 12085 BAD_HIREG);
b99bd4ef 12086
c19d1205 12087 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12088 inst.instruction |= Rn;
12089 inst.instruction |= Rm << 3;
b99bd4ef 12090 }
b99bd4ef
NC
12091}
12092
b05fe5cf 12093static void
c19d1205 12094do_t_mrs (void)
b05fe5cf 12095{
fdfde340 12096 unsigned Rd;
037e8744
JB
12097
12098 if (do_vfp_nsyn_mrs () == SUCCESS)
12099 return;
12100
90ec0d68
MGD
12101 Rd = inst.operands[0].reg;
12102 reject_bad_reg (Rd);
12103 inst.instruction |= Rd << 8;
12104
12105 if (inst.operands[1].isreg)
62b3e311 12106 {
90ec0d68
MGD
12107 unsigned br = inst.operands[1].reg;
12108 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12109 as_bad (_("bad register for mrs"));
12110
12111 inst.instruction |= br & (0xf << 16);
12112 inst.instruction |= (br & 0x300) >> 4;
12113 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12114 }
12115 else
12116 {
90ec0d68 12117 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12118
d2cd1205 12119 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12120 {
12121 /* PR gas/12698: The constraint is only applied for m_profile.
12122 If the user has specified -march=all, we want to ignore it as
12123 we are building for any CPU type, including non-m variants. */
823d2571
TG
12124 bfd_boolean m_profile =
12125 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12126 constraint ((flags != 0) && m_profile, _("selected processor does "
12127 "not support requested special purpose register"));
12128 }
90ec0d68 12129 else
d2cd1205
JB
12130 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12131 devices). */
12132 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12133 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12134
90ec0d68
MGD
12135 inst.instruction |= (flags & SPSR_BIT) >> 2;
12136 inst.instruction |= inst.operands[1].imm & 0xff;
12137 inst.instruction |= 0xf0000;
12138 }
c19d1205 12139}
b05fe5cf 12140
c19d1205
ZW
12141static void
12142do_t_msr (void)
12143{
62b3e311 12144 int flags;
fdfde340 12145 unsigned Rn;
62b3e311 12146
037e8744
JB
12147 if (do_vfp_nsyn_msr () == SUCCESS)
12148 return;
12149
c19d1205
ZW
12150 constraint (!inst.operands[1].isreg,
12151 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12152
12153 if (inst.operands[0].isreg)
12154 flags = (int)(inst.operands[0].reg);
12155 else
12156 flags = inst.operands[0].imm;
12157
d2cd1205 12158 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12159 {
d2cd1205
JB
12160 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12161
1a43faaf 12162 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12163 If the user has specified -march=all, we want to ignore it as
12164 we are building for any CPU type, including non-m variants. */
823d2571
TG
12165 bfd_boolean m_profile =
12166 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12167 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12168 && (bits & ~(PSR_s | PSR_f)) != 0)
12169 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12170 && bits != PSR_f)) && m_profile,
12171 _("selected processor does not support requested special "
12172 "purpose register"));
62b3e311
PB
12173 }
12174 else
d2cd1205
JB
12175 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12176 "requested special purpose register"));
c921be7d 12177
fdfde340
JM
12178 Rn = inst.operands[1].reg;
12179 reject_bad_reg (Rn);
12180
62b3e311 12181 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12182 inst.instruction |= (flags & 0xf0000) >> 8;
12183 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12184 inst.instruction |= (flags & 0xff);
fdfde340 12185 inst.instruction |= Rn << 16;
c19d1205 12186}
b05fe5cf 12187
c19d1205
ZW
12188static void
12189do_t_mul (void)
12190{
17828f45 12191 bfd_boolean narrow;
fdfde340 12192 unsigned Rd, Rn, Rm;
17828f45 12193
c19d1205
ZW
12194 if (!inst.operands[2].present)
12195 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12196
fdfde340
JM
12197 Rd = inst.operands[0].reg;
12198 Rn = inst.operands[1].reg;
12199 Rm = inst.operands[2].reg;
12200
17828f45 12201 if (unified_syntax)
b05fe5cf 12202 {
17828f45 12203 if (inst.size_req == 4
fdfde340
JM
12204 || (Rd != Rn
12205 && Rd != Rm)
12206 || Rn > 7
12207 || Rm > 7)
17828f45
JM
12208 narrow = FALSE;
12209 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12210 narrow = !in_it_block ();
17828f45 12211 else
e07e6e58 12212 narrow = in_it_block ();
b05fe5cf 12213 }
c19d1205 12214 else
b05fe5cf 12215 {
17828f45 12216 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12217 constraint (Rn > 7 || Rm > 7,
c19d1205 12218 BAD_HIREG);
17828f45
JM
12219 narrow = TRUE;
12220 }
b05fe5cf 12221
17828f45
JM
12222 if (narrow)
12223 {
12224 /* 16-bit MULS/Conditional MUL. */
c19d1205 12225 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12226 inst.instruction |= Rd;
b05fe5cf 12227
fdfde340
JM
12228 if (Rd == Rn)
12229 inst.instruction |= Rm << 3;
12230 else if (Rd == Rm)
12231 inst.instruction |= Rn << 3;
c19d1205
ZW
12232 else
12233 constraint (1, _("dest must overlap one source register"));
12234 }
17828f45
JM
12235 else
12236 {
e07e6e58
NC
12237 constraint (inst.instruction != T_MNEM_mul,
12238 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12239 /* 32-bit MUL. */
12240 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12241 inst.instruction |= Rd << 8;
12242 inst.instruction |= Rn << 16;
12243 inst.instruction |= Rm << 0;
12244
12245 reject_bad_reg (Rd);
12246 reject_bad_reg (Rn);
12247 reject_bad_reg (Rm);
17828f45 12248 }
c19d1205 12249}
b05fe5cf 12250
c19d1205
ZW
12251static void
12252do_t_mull (void)
12253{
fdfde340 12254 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12255
fdfde340
JM
12256 RdLo = inst.operands[0].reg;
12257 RdHi = inst.operands[1].reg;
12258 Rn = inst.operands[2].reg;
12259 Rm = inst.operands[3].reg;
12260
12261 reject_bad_reg (RdLo);
12262 reject_bad_reg (RdHi);
12263 reject_bad_reg (Rn);
12264 reject_bad_reg (Rm);
12265
12266 inst.instruction |= RdLo << 12;
12267 inst.instruction |= RdHi << 8;
12268 inst.instruction |= Rn << 16;
12269 inst.instruction |= Rm;
12270
12271 if (RdLo == RdHi)
c19d1205
ZW
12272 as_tsktsk (_("rdhi and rdlo must be different"));
12273}
b05fe5cf 12274
c19d1205
ZW
12275static void
12276do_t_nop (void)
12277{
e07e6e58
NC
12278 set_it_insn_type (NEUTRAL_IT_INSN);
12279
c19d1205
ZW
12280 if (unified_syntax)
12281 {
12282 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12283 {
c19d1205
ZW
12284 inst.instruction = THUMB_OP32 (inst.instruction);
12285 inst.instruction |= inst.operands[0].imm;
12286 }
12287 else
12288 {
bc2d1808
NC
12289 /* PR9722: Check for Thumb2 availability before
12290 generating a thumb2 nop instruction. */
afa62d5e 12291 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12292 {
12293 inst.instruction = THUMB_OP16 (inst.instruction);
12294 inst.instruction |= inst.operands[0].imm << 4;
12295 }
12296 else
12297 inst.instruction = 0x46c0;
c19d1205
ZW
12298 }
12299 }
12300 else
12301 {
12302 constraint (inst.operands[0].present,
12303 _("Thumb does not support NOP with hints"));
12304 inst.instruction = 0x46c0;
12305 }
12306}
b05fe5cf 12307
c19d1205
ZW
12308static void
12309do_t_neg (void)
12310{
12311 if (unified_syntax)
12312 {
3d388997
PB
12313 bfd_boolean narrow;
12314
12315 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12316 narrow = !in_it_block ();
3d388997 12317 else
e07e6e58 12318 narrow = in_it_block ();
3d388997
PB
12319 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12320 narrow = FALSE;
12321 if (inst.size_req == 4)
12322 narrow = FALSE;
12323
12324 if (!narrow)
c19d1205
ZW
12325 {
12326 inst.instruction = THUMB_OP32 (inst.instruction);
12327 inst.instruction |= inst.operands[0].reg << 8;
12328 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12329 }
12330 else
12331 {
c19d1205
ZW
12332 inst.instruction = THUMB_OP16 (inst.instruction);
12333 inst.instruction |= inst.operands[0].reg;
12334 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12335 }
12336 }
12337 else
12338 {
c19d1205
ZW
12339 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12340 BAD_HIREG);
12341 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12342
12343 inst.instruction = THUMB_OP16 (inst.instruction);
12344 inst.instruction |= inst.operands[0].reg;
12345 inst.instruction |= inst.operands[1].reg << 3;
12346 }
12347}
12348
1c444d06
JM
12349static void
12350do_t_orn (void)
12351{
12352 unsigned Rd, Rn;
12353
12354 Rd = inst.operands[0].reg;
12355 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12356
fdfde340
JM
12357 reject_bad_reg (Rd);
12358 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12359 reject_bad_reg (Rn);
12360
1c444d06
JM
12361 inst.instruction |= Rd << 8;
12362 inst.instruction |= Rn << 16;
12363
12364 if (!inst.operands[2].isreg)
12365 {
12366 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12367 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12368 }
12369 else
12370 {
12371 unsigned Rm;
12372
12373 Rm = inst.operands[2].reg;
fdfde340 12374 reject_bad_reg (Rm);
1c444d06
JM
12375
12376 constraint (inst.operands[2].shifted
12377 && inst.operands[2].immisreg,
12378 _("shift must be constant"));
12379 encode_thumb32_shifted_operand (2);
12380 }
12381}
12382
c19d1205
ZW
12383static void
12384do_t_pkhbt (void)
12385{
fdfde340
JM
12386 unsigned Rd, Rn, Rm;
12387
12388 Rd = inst.operands[0].reg;
12389 Rn = inst.operands[1].reg;
12390 Rm = inst.operands[2].reg;
12391
12392 reject_bad_reg (Rd);
12393 reject_bad_reg (Rn);
12394 reject_bad_reg (Rm);
12395
12396 inst.instruction |= Rd << 8;
12397 inst.instruction |= Rn << 16;
12398 inst.instruction |= Rm;
c19d1205
ZW
12399 if (inst.operands[3].present)
12400 {
12401 unsigned int val = inst.reloc.exp.X_add_number;
12402 constraint (inst.reloc.exp.X_op != O_constant,
12403 _("expression too complex"));
12404 inst.instruction |= (val & 0x1c) << 10;
12405 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12406 }
c19d1205 12407}
b05fe5cf 12408
c19d1205
ZW
12409static void
12410do_t_pkhtb (void)
12411{
12412 if (!inst.operands[3].present)
1ef52f49
NC
12413 {
12414 unsigned Rtmp;
12415
12416 inst.instruction &= ~0x00000020;
12417
12418 /* PR 10168. Swap the Rm and Rn registers. */
12419 Rtmp = inst.operands[1].reg;
12420 inst.operands[1].reg = inst.operands[2].reg;
12421 inst.operands[2].reg = Rtmp;
12422 }
c19d1205 12423 do_t_pkhbt ();
b05fe5cf
ZW
12424}
12425
c19d1205
ZW
12426static void
12427do_t_pld (void)
12428{
fdfde340
JM
12429 if (inst.operands[0].immisreg)
12430 reject_bad_reg (inst.operands[0].imm);
12431
c19d1205
ZW
12432 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12433}
b05fe5cf 12434
c19d1205
ZW
12435static void
12436do_t_push_pop (void)
b99bd4ef 12437{
e9f89963 12438 unsigned mask;
5f4273c7 12439
c19d1205
ZW
12440 constraint (inst.operands[0].writeback,
12441 _("push/pop do not support {reglist}^"));
12442 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12443 _("expression too complex"));
b99bd4ef 12444
e9f89963 12445 mask = inst.operands[0].imm;
d3bfe16e 12446 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12447 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e
JB
12448 else if (inst.size_req != 4
12449 && (mask & ~0xff) == (1 << (inst.instruction == T_MNEM_push
12450 ? REG_LR : REG_PC)))
b99bd4ef 12451 {
c19d1205
ZW
12452 inst.instruction = THUMB_OP16 (inst.instruction);
12453 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12454 inst.instruction |= mask & 0xff;
c19d1205
ZW
12455 }
12456 else if (unified_syntax)
12457 {
3c707909 12458 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12459 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12460 }
12461 else
12462 {
12463 inst.error = _("invalid register list to push/pop instruction");
12464 return;
12465 }
c19d1205 12466}
b99bd4ef 12467
c19d1205
ZW
12468static void
12469do_t_rbit (void)
12470{
fdfde340
JM
12471 unsigned Rd, Rm;
12472
12473 Rd = inst.operands[0].reg;
12474 Rm = inst.operands[1].reg;
12475
12476 reject_bad_reg (Rd);
12477 reject_bad_reg (Rm);
12478
12479 inst.instruction |= Rd << 8;
12480 inst.instruction |= Rm << 16;
12481 inst.instruction |= Rm;
c19d1205 12482}
b99bd4ef 12483
c19d1205
ZW
12484static void
12485do_t_rev (void)
12486{
fdfde340
JM
12487 unsigned Rd, Rm;
12488
12489 Rd = inst.operands[0].reg;
12490 Rm = inst.operands[1].reg;
12491
12492 reject_bad_reg (Rd);
12493 reject_bad_reg (Rm);
12494
12495 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12496 && inst.size_req != 4)
12497 {
12498 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12499 inst.instruction |= Rd;
12500 inst.instruction |= Rm << 3;
c19d1205
ZW
12501 }
12502 else if (unified_syntax)
12503 {
12504 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12505 inst.instruction |= Rd << 8;
12506 inst.instruction |= Rm << 16;
12507 inst.instruction |= Rm;
c19d1205
ZW
12508 }
12509 else
12510 inst.error = BAD_HIREG;
12511}
b99bd4ef 12512
1c444d06
JM
12513static void
12514do_t_rrx (void)
12515{
12516 unsigned Rd, Rm;
12517
12518 Rd = inst.operands[0].reg;
12519 Rm = inst.operands[1].reg;
12520
fdfde340
JM
12521 reject_bad_reg (Rd);
12522 reject_bad_reg (Rm);
c921be7d 12523
1c444d06
JM
12524 inst.instruction |= Rd << 8;
12525 inst.instruction |= Rm;
12526}
12527
c19d1205
ZW
12528static void
12529do_t_rsb (void)
12530{
fdfde340 12531 unsigned Rd, Rs;
b99bd4ef 12532
c19d1205
ZW
12533 Rd = inst.operands[0].reg;
12534 Rs = (inst.operands[1].present
12535 ? inst.operands[1].reg /* Rd, Rs, foo */
12536 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12537
fdfde340
JM
12538 reject_bad_reg (Rd);
12539 reject_bad_reg (Rs);
12540 if (inst.operands[2].isreg)
12541 reject_bad_reg (inst.operands[2].reg);
12542
c19d1205
ZW
12543 inst.instruction |= Rd << 8;
12544 inst.instruction |= Rs << 16;
12545 if (!inst.operands[2].isreg)
12546 {
026d3abb
PB
12547 bfd_boolean narrow;
12548
12549 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12550 narrow = !in_it_block ();
026d3abb 12551 else
e07e6e58 12552 narrow = in_it_block ();
026d3abb
PB
12553
12554 if (Rd > 7 || Rs > 7)
12555 narrow = FALSE;
12556
12557 if (inst.size_req == 4 || !unified_syntax)
12558 narrow = FALSE;
12559
12560 if (inst.reloc.exp.X_op != O_constant
12561 || inst.reloc.exp.X_add_number != 0)
12562 narrow = FALSE;
12563
12564 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12565 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12566 if (narrow)
12567 {
12568 inst.reloc.type = BFD_RELOC_UNUSED;
12569 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12570 inst.instruction |= Rs << 3;
12571 inst.instruction |= Rd;
12572 }
12573 else
12574 {
12575 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12576 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12577 }
c19d1205
ZW
12578 }
12579 else
12580 encode_thumb32_shifted_operand (2);
12581}
b99bd4ef 12582
c19d1205
ZW
12583static void
12584do_t_setend (void)
12585{
12e37cbc
MGD
12586 if (warn_on_deprecated
12587 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12588 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12589
e07e6e58 12590 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12591 if (inst.operands[0].imm)
12592 inst.instruction |= 0x8;
12593}
b99bd4ef 12594
c19d1205
ZW
12595static void
12596do_t_shift (void)
12597{
12598 if (!inst.operands[1].present)
12599 inst.operands[1].reg = inst.operands[0].reg;
12600
12601 if (unified_syntax)
12602 {
3d388997
PB
12603 bfd_boolean narrow;
12604 int shift_kind;
12605
12606 switch (inst.instruction)
12607 {
12608 case T_MNEM_asr:
12609 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12610 case T_MNEM_lsl:
12611 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12612 case T_MNEM_lsr:
12613 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12614 case T_MNEM_ror:
12615 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12616 default: abort ();
12617 }
12618
12619 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12620 narrow = !in_it_block ();
3d388997 12621 else
e07e6e58 12622 narrow = in_it_block ();
3d388997
PB
12623 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12624 narrow = FALSE;
12625 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12626 narrow = FALSE;
12627 if (inst.operands[2].isreg
12628 && (inst.operands[1].reg != inst.operands[0].reg
12629 || inst.operands[2].reg > 7))
12630 narrow = FALSE;
12631 if (inst.size_req == 4)
12632 narrow = FALSE;
12633
fdfde340
JM
12634 reject_bad_reg (inst.operands[0].reg);
12635 reject_bad_reg (inst.operands[1].reg);
c921be7d 12636
3d388997 12637 if (!narrow)
c19d1205
ZW
12638 {
12639 if (inst.operands[2].isreg)
b99bd4ef 12640 {
fdfde340 12641 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12642 inst.instruction = THUMB_OP32 (inst.instruction);
12643 inst.instruction |= inst.operands[0].reg << 8;
12644 inst.instruction |= inst.operands[1].reg << 16;
12645 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12646
12647 /* PR 12854: Error on extraneous shifts. */
12648 constraint (inst.operands[2].shifted,
12649 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12650 }
12651 else
12652 {
12653 inst.operands[1].shifted = 1;
3d388997 12654 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12655 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12656 ? T_MNEM_movs : T_MNEM_mov);
12657 inst.instruction |= inst.operands[0].reg << 8;
12658 encode_thumb32_shifted_operand (1);
12659 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12660 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12661 }
12662 }
12663 else
12664 {
c19d1205 12665 if (inst.operands[2].isreg)
b99bd4ef 12666 {
3d388997 12667 switch (shift_kind)
b99bd4ef 12668 {
3d388997
PB
12669 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12670 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12671 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12672 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12673 default: abort ();
b99bd4ef 12674 }
5f4273c7 12675
c19d1205
ZW
12676 inst.instruction |= inst.operands[0].reg;
12677 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12678
12679 /* PR 12854: Error on extraneous shifts. */
12680 constraint (inst.operands[2].shifted,
12681 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12682 }
12683 else
12684 {
3d388997 12685 switch (shift_kind)
b99bd4ef 12686 {
3d388997
PB
12687 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12688 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12689 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12690 default: abort ();
b99bd4ef 12691 }
c19d1205
ZW
12692 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12693 inst.instruction |= inst.operands[0].reg;
12694 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12695 }
12696 }
c19d1205
ZW
12697 }
12698 else
12699 {
12700 constraint (inst.operands[0].reg > 7
12701 || inst.operands[1].reg > 7, BAD_HIREG);
12702 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12703
c19d1205
ZW
12704 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12705 {
12706 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12707 constraint (inst.operands[0].reg != inst.operands[1].reg,
12708 _("source1 and dest must be same register"));
b99bd4ef 12709
c19d1205
ZW
12710 switch (inst.instruction)
12711 {
12712 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12713 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12714 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12715 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12716 default: abort ();
12717 }
5f4273c7 12718
c19d1205
ZW
12719 inst.instruction |= inst.operands[0].reg;
12720 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12721
12722 /* PR 12854: Error on extraneous shifts. */
12723 constraint (inst.operands[2].shifted,
12724 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12725 }
12726 else
b99bd4ef 12727 {
c19d1205
ZW
12728 switch (inst.instruction)
12729 {
12730 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12731 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12732 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12733 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12734 default: abort ();
12735 }
12736 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12737 inst.instruction |= inst.operands[0].reg;
12738 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12739 }
12740 }
b99bd4ef
NC
12741}
12742
12743static void
c19d1205 12744do_t_simd (void)
b99bd4ef 12745{
fdfde340
JM
12746 unsigned Rd, Rn, Rm;
12747
12748 Rd = inst.operands[0].reg;
12749 Rn = inst.operands[1].reg;
12750 Rm = inst.operands[2].reg;
12751
12752 reject_bad_reg (Rd);
12753 reject_bad_reg (Rn);
12754 reject_bad_reg (Rm);
12755
12756 inst.instruction |= Rd << 8;
12757 inst.instruction |= Rn << 16;
12758 inst.instruction |= Rm;
c19d1205 12759}
b99bd4ef 12760
03ee1b7f
NC
12761static void
12762do_t_simd2 (void)
12763{
12764 unsigned Rd, Rn, Rm;
12765
12766 Rd = inst.operands[0].reg;
12767 Rm = inst.operands[1].reg;
12768 Rn = inst.operands[2].reg;
12769
12770 reject_bad_reg (Rd);
12771 reject_bad_reg (Rn);
12772 reject_bad_reg (Rm);
12773
12774 inst.instruction |= Rd << 8;
12775 inst.instruction |= Rn << 16;
12776 inst.instruction |= Rm;
12777}
12778
c19d1205 12779static void
3eb17e6b 12780do_t_smc (void)
c19d1205
ZW
12781{
12782 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12783 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12784 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12785 constraint (inst.reloc.exp.X_op != O_constant,
12786 _("expression too complex"));
12787 inst.reloc.type = BFD_RELOC_UNUSED;
12788 inst.instruction |= (value & 0xf000) >> 12;
12789 inst.instruction |= (value & 0x0ff0);
12790 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12791 /* PR gas/15623: SMC instructions must be last in an IT block. */
12792 set_it_insn_type_last ();
c19d1205 12793}
b99bd4ef 12794
90ec0d68
MGD
12795static void
12796do_t_hvc (void)
12797{
12798 unsigned int value = inst.reloc.exp.X_add_number;
12799
12800 inst.reloc.type = BFD_RELOC_UNUSED;
12801 inst.instruction |= (value & 0x0fff);
12802 inst.instruction |= (value & 0xf000) << 4;
12803}
12804
c19d1205 12805static void
3a21c15a 12806do_t_ssat_usat (int bias)
c19d1205 12807{
fdfde340
JM
12808 unsigned Rd, Rn;
12809
12810 Rd = inst.operands[0].reg;
12811 Rn = inst.operands[2].reg;
12812
12813 reject_bad_reg (Rd);
12814 reject_bad_reg (Rn);
12815
12816 inst.instruction |= Rd << 8;
3a21c15a 12817 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12818 inst.instruction |= Rn << 16;
b99bd4ef 12819
c19d1205 12820 if (inst.operands[3].present)
b99bd4ef 12821 {
3a21c15a
NC
12822 offsetT shift_amount = inst.reloc.exp.X_add_number;
12823
12824 inst.reloc.type = BFD_RELOC_UNUSED;
12825
c19d1205
ZW
12826 constraint (inst.reloc.exp.X_op != O_constant,
12827 _("expression too complex"));
b99bd4ef 12828
3a21c15a 12829 if (shift_amount != 0)
6189168b 12830 {
3a21c15a
NC
12831 constraint (shift_amount > 31,
12832 _("shift expression is too large"));
12833
c19d1205 12834 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12835 inst.instruction |= 0x00200000; /* sh bit. */
12836
12837 inst.instruction |= (shift_amount & 0x1c) << 10;
12838 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
12839 }
12840 }
b99bd4ef 12841}
c921be7d 12842
3a21c15a
NC
12843static void
12844do_t_ssat (void)
12845{
12846 do_t_ssat_usat (1);
12847}
b99bd4ef 12848
0dd132b6 12849static void
c19d1205 12850do_t_ssat16 (void)
0dd132b6 12851{
fdfde340
JM
12852 unsigned Rd, Rn;
12853
12854 Rd = inst.operands[0].reg;
12855 Rn = inst.operands[2].reg;
12856
12857 reject_bad_reg (Rd);
12858 reject_bad_reg (Rn);
12859
12860 inst.instruction |= Rd << 8;
c19d1205 12861 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 12862 inst.instruction |= Rn << 16;
c19d1205 12863}
0dd132b6 12864
c19d1205
ZW
12865static void
12866do_t_strex (void)
12867{
12868 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12869 || inst.operands[2].postind || inst.operands[2].writeback
12870 || inst.operands[2].immisreg || inst.operands[2].shifted
12871 || inst.operands[2].negative,
01cfc07f 12872 BAD_ADDR_MODE);
0dd132b6 12873
5be8be5d
DG
12874 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12875
c19d1205
ZW
12876 inst.instruction |= inst.operands[0].reg << 8;
12877 inst.instruction |= inst.operands[1].reg << 12;
12878 inst.instruction |= inst.operands[2].reg << 16;
12879 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
12880}
12881
b99bd4ef 12882static void
c19d1205 12883do_t_strexd (void)
b99bd4ef 12884{
c19d1205
ZW
12885 if (!inst.operands[2].present)
12886 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 12887
c19d1205
ZW
12888 constraint (inst.operands[0].reg == inst.operands[1].reg
12889 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 12890 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 12891 BAD_OVERLAP);
b99bd4ef 12892
c19d1205
ZW
12893 inst.instruction |= inst.operands[0].reg;
12894 inst.instruction |= inst.operands[1].reg << 12;
12895 inst.instruction |= inst.operands[2].reg << 8;
12896 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
12897}
12898
12899static void
c19d1205 12900do_t_sxtah (void)
b99bd4ef 12901{
fdfde340
JM
12902 unsigned Rd, Rn, Rm;
12903
12904 Rd = inst.operands[0].reg;
12905 Rn = inst.operands[1].reg;
12906 Rm = inst.operands[2].reg;
12907
12908 reject_bad_reg (Rd);
12909 reject_bad_reg (Rn);
12910 reject_bad_reg (Rm);
12911
12912 inst.instruction |= Rd << 8;
12913 inst.instruction |= Rn << 16;
12914 inst.instruction |= Rm;
c19d1205
ZW
12915 inst.instruction |= inst.operands[3].imm << 4;
12916}
b99bd4ef 12917
c19d1205
ZW
12918static void
12919do_t_sxth (void)
12920{
fdfde340
JM
12921 unsigned Rd, Rm;
12922
12923 Rd = inst.operands[0].reg;
12924 Rm = inst.operands[1].reg;
12925
12926 reject_bad_reg (Rd);
12927 reject_bad_reg (Rm);
c921be7d
NC
12928
12929 if (inst.instruction <= 0xffff
12930 && inst.size_req != 4
fdfde340 12931 && Rd <= 7 && Rm <= 7
c19d1205 12932 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 12933 {
c19d1205 12934 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12935 inst.instruction |= Rd;
12936 inst.instruction |= Rm << 3;
b99bd4ef 12937 }
c19d1205 12938 else if (unified_syntax)
b99bd4ef 12939 {
c19d1205
ZW
12940 if (inst.instruction <= 0xffff)
12941 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12942 inst.instruction |= Rd << 8;
12943 inst.instruction |= Rm;
c19d1205 12944 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 12945 }
c19d1205 12946 else
b99bd4ef 12947 {
c19d1205
ZW
12948 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
12949 _("Thumb encoding does not support rotation"));
12950 constraint (1, BAD_HIREG);
b99bd4ef 12951 }
c19d1205 12952}
b99bd4ef 12953
c19d1205
ZW
12954static void
12955do_t_swi (void)
12956{
b2a5fbdc
MGD
12957 /* We have to do the following check manually as ARM_EXT_OS only applies
12958 to ARM_EXT_V6M. */
12959 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
12960 {
ac7f631b
NC
12961 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
12962 /* This only applies to the v6m howver, not later architectures. */
12963 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
12964 as_bad (_("SVC is not permitted on this architecture"));
12965 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
12966 }
12967
c19d1205
ZW
12968 inst.reloc.type = BFD_RELOC_ARM_SWI;
12969}
b99bd4ef 12970
92e90b6e
PB
12971static void
12972do_t_tb (void)
12973{
fdfde340 12974 unsigned Rn, Rm;
92e90b6e
PB
12975 int half;
12976
12977 half = (inst.instruction & 0x10) != 0;
e07e6e58 12978 set_it_insn_type_last ();
dfa9f0d5
PB
12979 constraint (inst.operands[0].immisreg,
12980 _("instruction requires register index"));
fdfde340
JM
12981
12982 Rn = inst.operands[0].reg;
12983 Rm = inst.operands[0].imm;
c921be7d 12984
fdfde340
JM
12985 constraint (Rn == REG_SP, BAD_SP);
12986 reject_bad_reg (Rm);
12987
92e90b6e
PB
12988 constraint (!half && inst.operands[0].shifted,
12989 _("instruction does not allow shifted index"));
fdfde340 12990 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
12991}
12992
74db7efb
NC
12993static void
12994do_t_udf (void)
12995{
12996 if (!inst.operands[0].present)
12997 inst.operands[0].imm = 0;
12998
12999 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13000 {
13001 constraint (inst.size_req == 2,
13002 _("immediate value out of range"));
13003 inst.instruction = THUMB_OP32 (inst.instruction);
13004 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13005 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13006 }
13007 else
13008 {
13009 inst.instruction = THUMB_OP16 (inst.instruction);
13010 inst.instruction |= inst.operands[0].imm;
13011 }
13012
13013 set_it_insn_type (NEUTRAL_IT_INSN);
13014}
13015
13016
c19d1205
ZW
13017static void
13018do_t_usat (void)
13019{
3a21c15a 13020 do_t_ssat_usat (0);
b99bd4ef
NC
13021}
13022
13023static void
c19d1205 13024do_t_usat16 (void)
b99bd4ef 13025{
fdfde340
JM
13026 unsigned Rd, Rn;
13027
13028 Rd = inst.operands[0].reg;
13029 Rn = inst.operands[2].reg;
13030
13031 reject_bad_reg (Rd);
13032 reject_bad_reg (Rn);
13033
13034 inst.instruction |= Rd << 8;
c19d1205 13035 inst.instruction |= inst.operands[1].imm;
fdfde340 13036 inst.instruction |= Rn << 16;
b99bd4ef 13037}
c19d1205 13038
5287ad62 13039/* Neon instruction encoder helpers. */
5f4273c7 13040
5287ad62 13041/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13042
5287ad62
JB
13043/* An "invalid" code for the following tables. */
13044#define N_INV -1u
13045
13046struct neon_tab_entry
b99bd4ef 13047{
5287ad62
JB
13048 unsigned integer;
13049 unsigned float_or_poly;
13050 unsigned scalar_or_imm;
13051};
5f4273c7 13052
5287ad62
JB
13053/* Map overloaded Neon opcodes to their respective encodings. */
13054#define NEON_ENC_TAB \
13055 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13056 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13057 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13058 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13059 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13060 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13061 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13062 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13063 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13064 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13065 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13066 /* Register variants of the following two instructions are encoded as
e07e6e58 13067 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13068 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13069 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13070 X(vfma, N_INV, 0x0000c10, N_INV), \
13071 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13072 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13073 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13074 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13075 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13076 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13077 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13078 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13079 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13080 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13081 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13082 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13083 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13084 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13085 X(vshl, 0x0000400, N_INV, 0x0800510), \
13086 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13087 X(vand, 0x0000110, N_INV, 0x0800030), \
13088 X(vbic, 0x0100110, N_INV, 0x0800030), \
13089 X(veor, 0x1000110, N_INV, N_INV), \
13090 X(vorn, 0x0300110, N_INV, 0x0800010), \
13091 X(vorr, 0x0200110, N_INV, 0x0800010), \
13092 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13093 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13094 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13095 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13096 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13097 X(vst1, 0x0000000, 0x0800000, N_INV), \
13098 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13099 X(vst2, 0x0000100, 0x0800100, N_INV), \
13100 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13101 X(vst3, 0x0000200, 0x0800200, N_INV), \
13102 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13103 X(vst4, 0x0000300, 0x0800300, N_INV), \
13104 X(vmovn, 0x1b20200, N_INV, N_INV), \
13105 X(vtrn, 0x1b20080, N_INV, N_INV), \
13106 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13107 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13108 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13109 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13110 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13111 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13112 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13113 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13114 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13115 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13116 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13117 X(vseleq, 0xe000a00, N_INV, N_INV), \
13118 X(vselvs, 0xe100a00, N_INV, N_INV), \
13119 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13120 X(vselgt, 0xe300a00, N_INV, N_INV), \
13121 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13122 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13123 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13124 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13125 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13126 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13127 X(sha3op, 0x2000c00, N_INV, N_INV), \
13128 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13129 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13130
13131enum neon_opc
13132{
13133#define X(OPC,I,F,S) N_MNEM_##OPC
13134NEON_ENC_TAB
13135#undef X
13136};
b99bd4ef 13137
5287ad62
JB
13138static const struct neon_tab_entry neon_enc_tab[] =
13139{
13140#define X(OPC,I,F,S) { (I), (F), (S) }
13141NEON_ENC_TAB
13142#undef X
13143};
b99bd4ef 13144
88714cb8
DG
13145/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13146#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13147#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13148#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13149#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13150#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13151#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13152#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13153#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13154#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13155#define NEON_ENC_SINGLE_(X) \
037e8744 13156 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13157#define NEON_ENC_DOUBLE_(X) \
037e8744 13158 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13159#define NEON_ENC_FPV8_(X) \
13160 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13161
88714cb8
DG
13162#define NEON_ENCODE(type, inst) \
13163 do \
13164 { \
13165 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13166 inst.is_neon = 1; \
13167 } \
13168 while (0)
13169
13170#define check_neon_suffixes \
13171 do \
13172 { \
13173 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13174 { \
13175 as_bad (_("invalid neon suffix for non neon instruction")); \
13176 return; \
13177 } \
13178 } \
13179 while (0)
13180
037e8744
JB
13181/* Define shapes for instruction operands. The following mnemonic characters
13182 are used in this table:
5287ad62 13183
037e8744 13184 F - VFP S<n> register
5287ad62
JB
13185 D - Neon D<n> register
13186 Q - Neon Q<n> register
13187 I - Immediate
13188 S - Scalar
13189 R - ARM register
13190 L - D<n> register list
5f4273c7 13191
037e8744
JB
13192 This table is used to generate various data:
13193 - enumerations of the form NS_DDR to be used as arguments to
13194 neon_select_shape.
13195 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13196 - a table used to drive neon_select_shape. */
b99bd4ef 13197
037e8744
JB
13198#define NEON_SHAPE_DEF \
13199 X(3, (D, D, D), DOUBLE), \
13200 X(3, (Q, Q, Q), QUAD), \
13201 X(3, (D, D, I), DOUBLE), \
13202 X(3, (Q, Q, I), QUAD), \
13203 X(3, (D, D, S), DOUBLE), \
13204 X(3, (Q, Q, S), QUAD), \
13205 X(2, (D, D), DOUBLE), \
13206 X(2, (Q, Q), QUAD), \
13207 X(2, (D, S), DOUBLE), \
13208 X(2, (Q, S), QUAD), \
13209 X(2, (D, R), DOUBLE), \
13210 X(2, (Q, R), QUAD), \
13211 X(2, (D, I), DOUBLE), \
13212 X(2, (Q, I), QUAD), \
13213 X(3, (D, L, D), DOUBLE), \
13214 X(2, (D, Q), MIXED), \
13215 X(2, (Q, D), MIXED), \
13216 X(3, (D, Q, I), MIXED), \
13217 X(3, (Q, D, I), MIXED), \
13218 X(3, (Q, D, D), MIXED), \
13219 X(3, (D, Q, Q), MIXED), \
13220 X(3, (Q, Q, D), MIXED), \
13221 X(3, (Q, D, S), MIXED), \
13222 X(3, (D, Q, S), MIXED), \
13223 X(4, (D, D, D, I), DOUBLE), \
13224 X(4, (Q, Q, Q, I), QUAD), \
13225 X(2, (F, F), SINGLE), \
13226 X(3, (F, F, F), SINGLE), \
13227 X(2, (F, I), SINGLE), \
13228 X(2, (F, D), MIXED), \
13229 X(2, (D, F), MIXED), \
13230 X(3, (F, F, I), MIXED), \
13231 X(4, (R, R, F, F), SINGLE), \
13232 X(4, (F, F, R, R), SINGLE), \
13233 X(3, (D, R, R), DOUBLE), \
13234 X(3, (R, R, D), DOUBLE), \
13235 X(2, (S, R), SINGLE), \
13236 X(2, (R, S), SINGLE), \
13237 X(2, (F, R), SINGLE), \
13238 X(2, (R, F), SINGLE)
13239
13240#define S2(A,B) NS_##A##B
13241#define S3(A,B,C) NS_##A##B##C
13242#define S4(A,B,C,D) NS_##A##B##C##D
13243
13244#define X(N, L, C) S##N L
13245
5287ad62
JB
13246enum neon_shape
13247{
037e8744
JB
13248 NEON_SHAPE_DEF,
13249 NS_NULL
5287ad62 13250};
b99bd4ef 13251
037e8744
JB
13252#undef X
13253#undef S2
13254#undef S3
13255#undef S4
13256
13257enum neon_shape_class
13258{
13259 SC_SINGLE,
13260 SC_DOUBLE,
13261 SC_QUAD,
13262 SC_MIXED
13263};
13264
13265#define X(N, L, C) SC_##C
13266
13267static enum neon_shape_class neon_shape_class[] =
13268{
13269 NEON_SHAPE_DEF
13270};
13271
13272#undef X
13273
13274enum neon_shape_el
13275{
13276 SE_F,
13277 SE_D,
13278 SE_Q,
13279 SE_I,
13280 SE_S,
13281 SE_R,
13282 SE_L
13283};
13284
13285/* Register widths of above. */
13286static unsigned neon_shape_el_size[] =
13287{
13288 32,
13289 64,
13290 128,
13291 0,
13292 32,
13293 32,
13294 0
13295};
13296
13297struct neon_shape_info
13298{
13299 unsigned els;
13300 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13301};
13302
13303#define S2(A,B) { SE_##A, SE_##B }
13304#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13305#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13306
13307#define X(N, L, C) { N, S##N L }
13308
13309static struct neon_shape_info neon_shape_tab[] =
13310{
13311 NEON_SHAPE_DEF
13312};
13313
13314#undef X
13315#undef S2
13316#undef S3
13317#undef S4
13318
5287ad62
JB
13319/* Bit masks used in type checking given instructions.
13320 'N_EQK' means the type must be the same as (or based on in some way) the key
13321 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13322 set, various other bits can be set as well in order to modify the meaning of
13323 the type constraint. */
13324
13325enum neon_type_mask
13326{
8e79c3df
CM
13327 N_S8 = 0x0000001,
13328 N_S16 = 0x0000002,
13329 N_S32 = 0x0000004,
13330 N_S64 = 0x0000008,
13331 N_U8 = 0x0000010,
13332 N_U16 = 0x0000020,
13333 N_U32 = 0x0000040,
13334 N_U64 = 0x0000080,
13335 N_I8 = 0x0000100,
13336 N_I16 = 0x0000200,
13337 N_I32 = 0x0000400,
13338 N_I64 = 0x0000800,
13339 N_8 = 0x0001000,
13340 N_16 = 0x0002000,
13341 N_32 = 0x0004000,
13342 N_64 = 0x0008000,
13343 N_P8 = 0x0010000,
13344 N_P16 = 0x0020000,
13345 N_F16 = 0x0040000,
13346 N_F32 = 0x0080000,
13347 N_F64 = 0x0100000,
4f51b4bd 13348 N_P64 = 0x0200000,
c921be7d
NC
13349 N_KEY = 0x1000000, /* Key element (main type specifier). */
13350 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13351 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13352 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13353 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13354 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13355 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13356 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13357 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13358 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13359 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13360 N_UTYP = 0,
4f51b4bd 13361 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13362};
13363
dcbf9037
JB
13364#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13365
5287ad62
JB
13366#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13367#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13368#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
13369#define N_SUF_32 (N_SU_32 | N_F32)
13370#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
13371#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
13372
13373/* Pass this as the first type argument to neon_check_type to ignore types
13374 altogether. */
13375#define N_IGNORE_TYPE (N_KEY | N_EQK)
13376
037e8744
JB
13377/* Select a "shape" for the current instruction (describing register types or
13378 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13379 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13380 function of operand parsing, so this function doesn't need to be called.
13381 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13382
13383static enum neon_shape
037e8744 13384neon_select_shape (enum neon_shape shape, ...)
5287ad62 13385{
037e8744
JB
13386 va_list ap;
13387 enum neon_shape first_shape = shape;
5287ad62
JB
13388
13389 /* Fix missing optional operands. FIXME: we don't know at this point how
13390 many arguments we should have, so this makes the assumption that we have
13391 > 1. This is true of all current Neon opcodes, I think, but may not be
13392 true in the future. */
13393 if (!inst.operands[1].present)
13394 inst.operands[1] = inst.operands[0];
13395
037e8744 13396 va_start (ap, shape);
5f4273c7 13397
21d799b5 13398 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13399 {
13400 unsigned j;
13401 int matches = 1;
13402
13403 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13404 {
13405 if (!inst.operands[j].present)
13406 {
13407 matches = 0;
13408 break;
13409 }
13410
13411 switch (neon_shape_tab[shape].el[j])
13412 {
13413 case SE_F:
13414 if (!(inst.operands[j].isreg
13415 && inst.operands[j].isvec
13416 && inst.operands[j].issingle
13417 && !inst.operands[j].isquad))
13418 matches = 0;
13419 break;
13420
13421 case SE_D:
13422 if (!(inst.operands[j].isreg
13423 && inst.operands[j].isvec
13424 && !inst.operands[j].isquad
13425 && !inst.operands[j].issingle))
13426 matches = 0;
13427 break;
13428
13429 case SE_R:
13430 if (!(inst.operands[j].isreg
13431 && !inst.operands[j].isvec))
13432 matches = 0;
13433 break;
13434
13435 case SE_Q:
13436 if (!(inst.operands[j].isreg
13437 && inst.operands[j].isvec
13438 && inst.operands[j].isquad
13439 && !inst.operands[j].issingle))
13440 matches = 0;
13441 break;
13442
13443 case SE_I:
13444 if (!(!inst.operands[j].isreg
13445 && !inst.operands[j].isscalar))
13446 matches = 0;
13447 break;
13448
13449 case SE_S:
13450 if (!(!inst.operands[j].isreg
13451 && inst.operands[j].isscalar))
13452 matches = 0;
13453 break;
13454
13455 case SE_L:
13456 break;
13457 }
3fde54a2
JZ
13458 if (!matches)
13459 break;
477330fc 13460 }
ad6cec43
MGD
13461 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13462 /* We've matched all the entries in the shape table, and we don't
13463 have any left over operands which have not been matched. */
477330fc 13464 break;
037e8744 13465 }
5f4273c7 13466
037e8744 13467 va_end (ap);
5287ad62 13468
037e8744
JB
13469 if (shape == NS_NULL && first_shape != NS_NULL)
13470 first_error (_("invalid instruction shape"));
5287ad62 13471
037e8744
JB
13472 return shape;
13473}
5287ad62 13474
037e8744
JB
13475/* True if SHAPE is predominantly a quadword operation (most of the time, this
13476 means the Q bit should be set). */
13477
13478static int
13479neon_quad (enum neon_shape shape)
13480{
13481 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13482}
037e8744 13483
5287ad62
JB
13484static void
13485neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13486 unsigned *g_size)
5287ad62
JB
13487{
13488 /* Allow modification to be made to types which are constrained to be
13489 based on the key element, based on bits set alongside N_EQK. */
13490 if ((typebits & N_EQK) != 0)
13491 {
13492 if ((typebits & N_HLF) != 0)
13493 *g_size /= 2;
13494 else if ((typebits & N_DBL) != 0)
13495 *g_size *= 2;
13496 if ((typebits & N_SGN) != 0)
13497 *g_type = NT_signed;
13498 else if ((typebits & N_UNS) != 0)
477330fc 13499 *g_type = NT_unsigned;
5287ad62 13500 else if ((typebits & N_INT) != 0)
477330fc 13501 *g_type = NT_integer;
5287ad62 13502 else if ((typebits & N_FLT) != 0)
477330fc 13503 *g_type = NT_float;
dcbf9037 13504 else if ((typebits & N_SIZ) != 0)
477330fc 13505 *g_type = NT_untyped;
5287ad62
JB
13506 }
13507}
5f4273c7 13508
5287ad62
JB
13509/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13510 operand type, i.e. the single type specified in a Neon instruction when it
13511 is the only one given. */
13512
13513static struct neon_type_el
13514neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13515{
13516 struct neon_type_el dest = *key;
5f4273c7 13517
9c2799c2 13518 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13519
5287ad62
JB
13520 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13521
13522 return dest;
13523}
13524
13525/* Convert Neon type and size into compact bitmask representation. */
13526
13527static enum neon_type_mask
13528type_chk_of_el_type (enum neon_el_type type, unsigned size)
13529{
13530 switch (type)
13531 {
13532 case NT_untyped:
13533 switch (size)
477330fc
RM
13534 {
13535 case 8: return N_8;
13536 case 16: return N_16;
13537 case 32: return N_32;
13538 case 64: return N_64;
13539 default: ;
13540 }
5287ad62
JB
13541 break;
13542
13543 case NT_integer:
13544 switch (size)
477330fc
RM
13545 {
13546 case 8: return N_I8;
13547 case 16: return N_I16;
13548 case 32: return N_I32;
13549 case 64: return N_I64;
13550 default: ;
13551 }
5287ad62
JB
13552 break;
13553
13554 case NT_float:
037e8744 13555 switch (size)
477330fc 13556 {
8e79c3df 13557 case 16: return N_F16;
477330fc
RM
13558 case 32: return N_F32;
13559 case 64: return N_F64;
13560 default: ;
13561 }
5287ad62
JB
13562 break;
13563
13564 case NT_poly:
13565 switch (size)
477330fc
RM
13566 {
13567 case 8: return N_P8;
13568 case 16: return N_P16;
4f51b4bd 13569 case 64: return N_P64;
477330fc
RM
13570 default: ;
13571 }
5287ad62
JB
13572 break;
13573
13574 case NT_signed:
13575 switch (size)
477330fc
RM
13576 {
13577 case 8: return N_S8;
13578 case 16: return N_S16;
13579 case 32: return N_S32;
13580 case 64: return N_S64;
13581 default: ;
13582 }
5287ad62
JB
13583 break;
13584
13585 case NT_unsigned:
13586 switch (size)
477330fc
RM
13587 {
13588 case 8: return N_U8;
13589 case 16: return N_U16;
13590 case 32: return N_U32;
13591 case 64: return N_U64;
13592 default: ;
13593 }
5287ad62
JB
13594 break;
13595
13596 default: ;
13597 }
5f4273c7 13598
5287ad62
JB
13599 return N_UTYP;
13600}
13601
13602/* Convert compact Neon bitmask type representation to a type and size. Only
13603 handles the case where a single bit is set in the mask. */
13604
dcbf9037 13605static int
5287ad62 13606el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13607 enum neon_type_mask mask)
5287ad62 13608{
dcbf9037
JB
13609 if ((mask & N_EQK) != 0)
13610 return FAIL;
13611
5287ad62
JB
13612 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13613 *size = 8;
c70a8987 13614 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13615 *size = 16;
dcbf9037 13616 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13617 *size = 32;
4f51b4bd 13618 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13619 *size = 64;
dcbf9037
JB
13620 else
13621 return FAIL;
13622
5287ad62
JB
13623 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13624 *type = NT_signed;
dcbf9037 13625 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13626 *type = NT_unsigned;
dcbf9037 13627 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13628 *type = NT_integer;
dcbf9037 13629 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13630 *type = NT_untyped;
4f51b4bd 13631 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13632 *type = NT_poly;
c70a8987 13633 else if ((mask & (N_F16 | N_F32 | N_F64)) != 0)
5287ad62 13634 *type = NT_float;
dcbf9037
JB
13635 else
13636 return FAIL;
5f4273c7 13637
dcbf9037 13638 return SUCCESS;
5287ad62
JB
13639}
13640
13641/* Modify a bitmask of allowed types. This is only needed for type
13642 relaxation. */
13643
13644static unsigned
13645modify_types_allowed (unsigned allowed, unsigned mods)
13646{
13647 unsigned size;
13648 enum neon_el_type type;
13649 unsigned destmask;
13650 int i;
5f4273c7 13651
5287ad62 13652 destmask = 0;
5f4273c7 13653
5287ad62
JB
13654 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13655 {
21d799b5 13656 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13657 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13658 {
13659 neon_modify_type_size (mods, &type, &size);
13660 destmask |= type_chk_of_el_type (type, size);
13661 }
5287ad62 13662 }
5f4273c7 13663
5287ad62
JB
13664 return destmask;
13665}
13666
13667/* Check type and return type classification.
13668 The manual states (paraphrase): If one datatype is given, it indicates the
13669 type given in:
13670 - the second operand, if there is one
13671 - the operand, if there is no second operand
13672 - the result, if there are no operands.
13673 This isn't quite good enough though, so we use a concept of a "key" datatype
13674 which is set on a per-instruction basis, which is the one which matters when
13675 only one data type is written.
13676 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13677 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13678
13679static struct neon_type_el
13680neon_check_type (unsigned els, enum neon_shape ns, ...)
13681{
13682 va_list ap;
13683 unsigned i, pass, key_el = 0;
13684 unsigned types[NEON_MAX_TYPE_ELS];
13685 enum neon_el_type k_type = NT_invtype;
13686 unsigned k_size = -1u;
13687 struct neon_type_el badtype = {NT_invtype, -1};
13688 unsigned key_allowed = 0;
13689
13690 /* Optional registers in Neon instructions are always (not) in operand 1.
13691 Fill in the missing operand here, if it was omitted. */
13692 if (els > 1 && !inst.operands[1].present)
13693 inst.operands[1] = inst.operands[0];
13694
13695 /* Suck up all the varargs. */
13696 va_start (ap, ns);
13697 for (i = 0; i < els; i++)
13698 {
13699 unsigned thisarg = va_arg (ap, unsigned);
13700 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13701 {
13702 va_end (ap);
13703 return badtype;
13704 }
5287ad62
JB
13705 types[i] = thisarg;
13706 if ((thisarg & N_KEY) != 0)
477330fc 13707 key_el = i;
5287ad62
JB
13708 }
13709 va_end (ap);
13710
dcbf9037
JB
13711 if (inst.vectype.elems > 0)
13712 for (i = 0; i < els; i++)
13713 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13714 {
13715 first_error (_("types specified in both the mnemonic and operands"));
13716 return badtype;
13717 }
dcbf9037 13718
5287ad62
JB
13719 /* Duplicate inst.vectype elements here as necessary.
13720 FIXME: No idea if this is exactly the same as the ARM assembler,
13721 particularly when an insn takes one register and one non-register
13722 operand. */
13723 if (inst.vectype.elems == 1 && els > 1)
13724 {
13725 unsigned j;
13726 inst.vectype.elems = els;
13727 inst.vectype.el[key_el] = inst.vectype.el[0];
13728 for (j = 0; j < els; j++)
477330fc
RM
13729 if (j != key_el)
13730 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13731 types[j]);
dcbf9037
JB
13732 }
13733 else if (inst.vectype.elems == 0 && els > 0)
13734 {
13735 unsigned j;
13736 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13737 after each operand. We allow some flexibility here; as long as the
13738 "key" operand has a type, we can infer the others. */
dcbf9037 13739 for (j = 0; j < els; j++)
477330fc
RM
13740 if (inst.operands[j].vectype.type != NT_invtype)
13741 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13742
13743 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13744 {
13745 for (j = 0; j < els; j++)
13746 if (inst.operands[j].vectype.type == NT_invtype)
13747 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13748 types[j]);
13749 }
dcbf9037 13750 else
477330fc
RM
13751 {
13752 first_error (_("operand types can't be inferred"));
13753 return badtype;
13754 }
5287ad62
JB
13755 }
13756 else if (inst.vectype.elems != els)
13757 {
dcbf9037 13758 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13759 return badtype;
13760 }
13761
13762 for (pass = 0; pass < 2; pass++)
13763 {
13764 for (i = 0; i < els; i++)
477330fc
RM
13765 {
13766 unsigned thisarg = types[i];
13767 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13768 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13769 enum neon_el_type g_type = inst.vectype.el[i].type;
13770 unsigned g_size = inst.vectype.el[i].size;
13771
13772 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 13773 integer types if sign-specific variants are unavailable. */
477330fc 13774 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
13775 && (types_allowed & N_SU_ALL) == 0)
13776 g_type = NT_integer;
13777
477330fc 13778 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
13779 them. Some instructions only care about signs for some element
13780 sizes, so handle that properly. */
477330fc 13781 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
13782 && ((g_size == 8 && (types_allowed & N_8) != 0)
13783 || (g_size == 16 && (types_allowed & N_16) != 0)
13784 || (g_size == 32 && (types_allowed & N_32) != 0)
13785 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
13786 g_type = NT_untyped;
13787
477330fc
RM
13788 if (pass == 0)
13789 {
13790 if ((thisarg & N_KEY) != 0)
13791 {
13792 k_type = g_type;
13793 k_size = g_size;
13794 key_allowed = thisarg & ~N_KEY;
13795 }
13796 }
13797 else
13798 {
13799 if ((thisarg & N_VFP) != 0)
13800 {
13801 enum neon_shape_el regshape;
13802 unsigned regwidth, match;
99b253c5
NC
13803
13804 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13805 if (ns == NS_NULL)
13806 {
13807 first_error (_("invalid instruction shape"));
13808 return badtype;
13809 }
477330fc
RM
13810 regshape = neon_shape_tab[ns].el[i];
13811 regwidth = neon_shape_el_size[regshape];
13812
13813 /* In VFP mode, operands must match register widths. If we
13814 have a key operand, use its width, else use the width of
13815 the current operand. */
13816 if (k_size != -1u)
13817 match = k_size;
13818 else
13819 match = g_size;
13820
13821 if (regwidth != match)
13822 {
13823 first_error (_("operand size must match register width"));
13824 return badtype;
13825 }
13826 }
13827
13828 if ((thisarg & N_EQK) == 0)
13829 {
13830 unsigned given_type = type_chk_of_el_type (g_type, g_size);
13831
13832 if ((given_type & types_allowed) == 0)
13833 {
13834 first_error (_("bad type in Neon instruction"));
13835 return badtype;
13836 }
13837 }
13838 else
13839 {
13840 enum neon_el_type mod_k_type = k_type;
13841 unsigned mod_k_size = k_size;
13842 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
13843 if (g_type != mod_k_type || g_size != mod_k_size)
13844 {
13845 first_error (_("inconsistent types in Neon instruction"));
13846 return badtype;
13847 }
13848 }
13849 }
13850 }
5287ad62
JB
13851 }
13852
13853 return inst.vectype.el[key_el];
13854}
13855
037e8744 13856/* Neon-style VFP instruction forwarding. */
5287ad62 13857
037e8744
JB
13858/* Thumb VFP instructions have 0xE in the condition field. */
13859
13860static void
13861do_vfp_cond_or_thumb (void)
5287ad62 13862{
88714cb8
DG
13863 inst.is_neon = 1;
13864
5287ad62 13865 if (thumb_mode)
037e8744 13866 inst.instruction |= 0xe0000000;
5287ad62 13867 else
037e8744 13868 inst.instruction |= inst.cond << 28;
5287ad62
JB
13869}
13870
037e8744
JB
13871/* Look up and encode a simple mnemonic, for use as a helper function for the
13872 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
13873 etc. It is assumed that operand parsing has already been done, and that the
13874 operands are in the form expected by the given opcode (this isn't necessarily
13875 the same as the form in which they were parsed, hence some massaging must
13876 take place before this function is called).
13877 Checks current arch version against that in the looked-up opcode. */
5287ad62 13878
037e8744
JB
13879static void
13880do_vfp_nsyn_opcode (const char *opname)
5287ad62 13881{
037e8744 13882 const struct asm_opcode *opcode;
5f4273c7 13883
21d799b5 13884 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 13885
037e8744
JB
13886 if (!opcode)
13887 abort ();
5287ad62 13888
037e8744 13889 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
13890 thumb_mode ? *opcode->tvariant : *opcode->avariant),
13891 _(BAD_FPU));
5287ad62 13892
88714cb8
DG
13893 inst.is_neon = 1;
13894
037e8744
JB
13895 if (thumb_mode)
13896 {
13897 inst.instruction = opcode->tvalue;
13898 opcode->tencode ();
13899 }
13900 else
13901 {
13902 inst.instruction = (inst.cond << 28) | opcode->avalue;
13903 opcode->aencode ();
13904 }
13905}
5287ad62
JB
13906
13907static void
037e8744 13908do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 13909{
037e8744
JB
13910 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
13911
13912 if (rs == NS_FFF)
13913 {
13914 if (is_add)
477330fc 13915 do_vfp_nsyn_opcode ("fadds");
037e8744 13916 else
477330fc 13917 do_vfp_nsyn_opcode ("fsubs");
037e8744
JB
13918 }
13919 else
13920 {
13921 if (is_add)
477330fc 13922 do_vfp_nsyn_opcode ("faddd");
037e8744 13923 else
477330fc 13924 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
13925 }
13926}
13927
13928/* Check operand types to see if this is a VFP instruction, and if so call
13929 PFN (). */
13930
13931static int
13932try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
13933{
13934 enum neon_shape rs;
13935 struct neon_type_el et;
13936
13937 switch (args)
13938 {
13939 case 2:
13940 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13941 et = neon_check_type (2, rs,
477330fc 13942 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
037e8744 13943 break;
5f4273c7 13944
037e8744
JB
13945 case 3:
13946 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13947 et = neon_check_type (3, rs,
477330fc 13948 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
037e8744
JB
13949 break;
13950
13951 default:
13952 abort ();
13953 }
13954
13955 if (et.type != NT_invtype)
13956 {
13957 pfn (rs);
13958 return SUCCESS;
13959 }
037e8744 13960
99b253c5 13961 inst.error = NULL;
037e8744
JB
13962 return FAIL;
13963}
13964
13965static void
13966do_vfp_nsyn_mla_mls (enum neon_shape rs)
13967{
13968 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 13969
037e8744
JB
13970 if (rs == NS_FFF)
13971 {
13972 if (is_mla)
477330fc 13973 do_vfp_nsyn_opcode ("fmacs");
037e8744 13974 else
477330fc 13975 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
13976 }
13977 else
13978 {
13979 if (is_mla)
477330fc 13980 do_vfp_nsyn_opcode ("fmacd");
037e8744 13981 else
477330fc 13982 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
13983 }
13984}
13985
62f3b8c8
PB
13986static void
13987do_vfp_nsyn_fma_fms (enum neon_shape rs)
13988{
13989 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
13990
13991 if (rs == NS_FFF)
13992 {
13993 if (is_fma)
477330fc 13994 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 13995 else
477330fc 13996 do_vfp_nsyn_opcode ("ffnmas");
62f3b8c8
PB
13997 }
13998 else
13999 {
14000 if (is_fma)
477330fc 14001 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14002 else
477330fc 14003 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14004 }
14005}
14006
037e8744
JB
14007static void
14008do_vfp_nsyn_mul (enum neon_shape rs)
14009{
14010 if (rs == NS_FFF)
14011 do_vfp_nsyn_opcode ("fmuls");
14012 else
14013 do_vfp_nsyn_opcode ("fmuld");
14014}
14015
14016static void
14017do_vfp_nsyn_abs_neg (enum neon_shape rs)
14018{
14019 int is_neg = (inst.instruction & 0x80) != 0;
14020 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
14021
14022 if (rs == NS_FF)
14023 {
14024 if (is_neg)
477330fc 14025 do_vfp_nsyn_opcode ("fnegs");
037e8744 14026 else
477330fc 14027 do_vfp_nsyn_opcode ("fabss");
037e8744
JB
14028 }
14029 else
14030 {
14031 if (is_neg)
477330fc 14032 do_vfp_nsyn_opcode ("fnegd");
037e8744 14033 else
477330fc 14034 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14035 }
14036}
14037
14038/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14039 insns belong to Neon, and are handled elsewhere. */
14040
14041static void
14042do_vfp_nsyn_ldm_stm (int is_dbmode)
14043{
14044 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14045 if (is_ldm)
14046 {
14047 if (is_dbmode)
477330fc 14048 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14049 else
477330fc 14050 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14051 }
14052 else
14053 {
14054 if (is_dbmode)
477330fc 14055 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14056 else
477330fc 14057 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14058 }
14059}
14060
037e8744
JB
14061static void
14062do_vfp_nsyn_sqrt (void)
14063{
14064 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
14065 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 14066
037e8744
JB
14067 if (rs == NS_FF)
14068 do_vfp_nsyn_opcode ("fsqrts");
14069 else
14070 do_vfp_nsyn_opcode ("fsqrtd");
14071}
14072
14073static void
14074do_vfp_nsyn_div (void)
14075{
14076 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
14077 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14078 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 14079
037e8744
JB
14080 if (rs == NS_FFF)
14081 do_vfp_nsyn_opcode ("fdivs");
14082 else
14083 do_vfp_nsyn_opcode ("fdivd");
14084}
14085
14086static void
14087do_vfp_nsyn_nmul (void)
14088{
14089 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
14090 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14091 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 14092
037e8744
JB
14093 if (rs == NS_FFF)
14094 {
88714cb8 14095 NEON_ENCODE (SINGLE, inst);
037e8744
JB
14096 do_vfp_sp_dyadic ();
14097 }
14098 else
14099 {
88714cb8 14100 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14101 do_vfp_dp_rd_rn_rm ();
14102 }
14103 do_vfp_cond_or_thumb ();
14104}
14105
14106static void
14107do_vfp_nsyn_cmp (void)
14108{
14109 if (inst.operands[1].isreg)
14110 {
14111 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
14112 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 14113
037e8744 14114 if (rs == NS_FF)
477330fc
RM
14115 {
14116 NEON_ENCODE (SINGLE, inst);
14117 do_vfp_sp_monadic ();
14118 }
037e8744 14119 else
477330fc
RM
14120 {
14121 NEON_ENCODE (DOUBLE, inst);
14122 do_vfp_dp_rd_rm ();
14123 }
037e8744
JB
14124 }
14125 else
14126 {
14127 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
14128 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
14129
14130 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14131 {
14132 case N_MNEM_vcmp:
14133 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14134 break;
14135 case N_MNEM_vcmpe:
14136 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14137 break;
14138 default:
14139 abort ();
14140 }
5f4273c7 14141
037e8744 14142 if (rs == NS_FI)
477330fc
RM
14143 {
14144 NEON_ENCODE (SINGLE, inst);
14145 do_vfp_sp_compare_z ();
14146 }
037e8744 14147 else
477330fc
RM
14148 {
14149 NEON_ENCODE (DOUBLE, inst);
14150 do_vfp_dp_rd ();
14151 }
037e8744
JB
14152 }
14153 do_vfp_cond_or_thumb ();
14154}
14155
14156static void
14157nsyn_insert_sp (void)
14158{
14159 inst.operands[1] = inst.operands[0];
14160 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14161 inst.operands[0].reg = REG_SP;
037e8744
JB
14162 inst.operands[0].isreg = 1;
14163 inst.operands[0].writeback = 1;
14164 inst.operands[0].present = 1;
14165}
14166
14167static void
14168do_vfp_nsyn_push (void)
14169{
14170 nsyn_insert_sp ();
14171 if (inst.operands[1].issingle)
14172 do_vfp_nsyn_opcode ("fstmdbs");
14173 else
14174 do_vfp_nsyn_opcode ("fstmdbd");
14175}
14176
14177static void
14178do_vfp_nsyn_pop (void)
14179{
14180 nsyn_insert_sp ();
14181 if (inst.operands[1].issingle)
22b5b651 14182 do_vfp_nsyn_opcode ("fldmias");
037e8744 14183 else
22b5b651 14184 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14185}
14186
14187/* Fix up Neon data-processing instructions, ORing in the correct bits for
14188 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14189
88714cb8
DG
14190static void
14191neon_dp_fixup (struct arm_it* insn)
037e8744 14192{
88714cb8
DG
14193 unsigned int i = insn->instruction;
14194 insn->is_neon = 1;
14195
037e8744
JB
14196 if (thumb_mode)
14197 {
14198 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14199 if (i & (1 << 24))
477330fc 14200 i |= 1 << 28;
5f4273c7 14201
037e8744 14202 i &= ~(1 << 24);
5f4273c7 14203
037e8744
JB
14204 i |= 0xef000000;
14205 }
14206 else
14207 i |= 0xf2000000;
5f4273c7 14208
88714cb8 14209 insn->instruction = i;
037e8744
JB
14210}
14211
14212/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14213 (0, 1, 2, 3). */
14214
14215static unsigned
14216neon_logbits (unsigned x)
14217{
14218 return ffs (x) - 4;
14219}
14220
14221#define LOW4(R) ((R) & 0xf)
14222#define HI1(R) (((R) >> 4) & 1)
14223
14224/* Encode insns with bit pattern:
14225
14226 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14227 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14228
037e8744
JB
14229 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14230 different meaning for some instruction. */
14231
14232static void
14233neon_three_same (int isquad, int ubit, int size)
14234{
14235 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14236 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14237 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14238 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14239 inst.instruction |= LOW4 (inst.operands[2].reg);
14240 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14241 inst.instruction |= (isquad != 0) << 6;
14242 inst.instruction |= (ubit != 0) << 24;
14243 if (size != -1)
14244 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14245
88714cb8 14246 neon_dp_fixup (&inst);
037e8744
JB
14247}
14248
14249/* Encode instructions of the form:
14250
14251 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14252 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14253
14254 Don't write size if SIZE == -1. */
14255
14256static void
14257neon_two_same (int qbit, int ubit, int size)
14258{
14259 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14260 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14261 inst.instruction |= LOW4 (inst.operands[1].reg);
14262 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14263 inst.instruction |= (qbit != 0) << 6;
14264 inst.instruction |= (ubit != 0) << 24;
14265
14266 if (size != -1)
14267 inst.instruction |= neon_logbits (size) << 18;
14268
88714cb8 14269 neon_dp_fixup (&inst);
5287ad62
JB
14270}
14271
14272/* Neon instruction encoders, in approximate order of appearance. */
14273
14274static void
14275do_neon_dyadic_i_su (void)
14276{
037e8744 14277 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14278 struct neon_type_el et = neon_check_type (3, rs,
14279 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14280 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14281}
14282
14283static void
14284do_neon_dyadic_i64_su (void)
14285{
037e8744 14286 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14287 struct neon_type_el et = neon_check_type (3, rs,
14288 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14289 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14290}
14291
14292static void
14293neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14294 unsigned immbits)
5287ad62
JB
14295{
14296 unsigned size = et.size >> 3;
14297 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14298 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14299 inst.instruction |= LOW4 (inst.operands[1].reg);
14300 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14301 inst.instruction |= (isquad != 0) << 6;
14302 inst.instruction |= immbits << 16;
14303 inst.instruction |= (size >> 3) << 7;
14304 inst.instruction |= (size & 0x7) << 19;
14305 if (write_ubit)
14306 inst.instruction |= (uval != 0) << 24;
14307
88714cb8 14308 neon_dp_fixup (&inst);
5287ad62
JB
14309}
14310
14311static void
14312do_neon_shl_imm (void)
14313{
14314 if (!inst.operands[2].isreg)
14315 {
037e8744 14316 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14317 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14318 int imm = inst.operands[2].imm;
14319
14320 constraint (imm < 0 || (unsigned)imm >= et.size,
14321 _("immediate out of range for shift"));
88714cb8 14322 NEON_ENCODE (IMMED, inst);
cb3b1e65 14323 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14324 }
14325 else
14326 {
037e8744 14327 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14328 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14329 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14330 unsigned int tmp;
14331
14332 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14333 vshl.xx Dd, Dm, Dn
14334 whereas other 3-register operations encoded by neon_three_same have
14335 syntax like:
14336 vadd.xx Dd, Dn, Dm
14337 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14338 here. */
627907b7
JB
14339 tmp = inst.operands[2].reg;
14340 inst.operands[2].reg = inst.operands[1].reg;
14341 inst.operands[1].reg = tmp;
88714cb8 14342 NEON_ENCODE (INTEGER, inst);
037e8744 14343 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14344 }
14345}
14346
14347static void
14348do_neon_qshl_imm (void)
14349{
14350 if (!inst.operands[2].isreg)
14351 {
037e8744 14352 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14353 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14354 int imm = inst.operands[2].imm;
627907b7 14355
cb3b1e65
JB
14356 constraint (imm < 0 || (unsigned)imm >= et.size,
14357 _("immediate out of range for shift"));
88714cb8 14358 NEON_ENCODE (IMMED, inst);
cb3b1e65 14359 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14360 }
14361 else
14362 {
037e8744 14363 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14364 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14365 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14366 unsigned int tmp;
14367
14368 /* See note in do_neon_shl_imm. */
14369 tmp = inst.operands[2].reg;
14370 inst.operands[2].reg = inst.operands[1].reg;
14371 inst.operands[1].reg = tmp;
88714cb8 14372 NEON_ENCODE (INTEGER, inst);
037e8744 14373 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14374 }
14375}
14376
627907b7
JB
14377static void
14378do_neon_rshl (void)
14379{
14380 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14381 struct neon_type_el et = neon_check_type (3, rs,
14382 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14383 unsigned int tmp;
14384
14385 tmp = inst.operands[2].reg;
14386 inst.operands[2].reg = inst.operands[1].reg;
14387 inst.operands[1].reg = tmp;
14388 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14389}
14390
5287ad62
JB
14391static int
14392neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14393{
036dc3f7
PB
14394 /* Handle .I8 pseudo-instructions. */
14395 if (size == 8)
5287ad62 14396 {
5287ad62 14397 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14398 FIXME is this the intended semantics? There doesn't seem much point in
14399 accepting .I8 if so. */
5287ad62
JB
14400 immediate |= immediate << 8;
14401 size = 16;
036dc3f7
PB
14402 }
14403
14404 if (size >= 32)
14405 {
14406 if (immediate == (immediate & 0x000000ff))
14407 {
14408 *immbits = immediate;
14409 return 0x1;
14410 }
14411 else if (immediate == (immediate & 0x0000ff00))
14412 {
14413 *immbits = immediate >> 8;
14414 return 0x3;
14415 }
14416 else if (immediate == (immediate & 0x00ff0000))
14417 {
14418 *immbits = immediate >> 16;
14419 return 0x5;
14420 }
14421 else if (immediate == (immediate & 0xff000000))
14422 {
14423 *immbits = immediate >> 24;
14424 return 0x7;
14425 }
14426 if ((immediate & 0xffff) != (immediate >> 16))
14427 goto bad_immediate;
14428 immediate &= 0xffff;
5287ad62
JB
14429 }
14430
14431 if (immediate == (immediate & 0x000000ff))
14432 {
14433 *immbits = immediate;
036dc3f7 14434 return 0x9;
5287ad62
JB
14435 }
14436 else if (immediate == (immediate & 0x0000ff00))
14437 {
14438 *immbits = immediate >> 8;
036dc3f7 14439 return 0xb;
5287ad62
JB
14440 }
14441
14442 bad_immediate:
dcbf9037 14443 first_error (_("immediate value out of range"));
5287ad62
JB
14444 return FAIL;
14445}
14446
5287ad62
JB
14447static void
14448do_neon_logic (void)
14449{
14450 if (inst.operands[2].present && inst.operands[2].isreg)
14451 {
037e8744 14452 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14453 neon_check_type (3, rs, N_IGNORE_TYPE);
14454 /* U bit and size field were set as part of the bitmask. */
88714cb8 14455 NEON_ENCODE (INTEGER, inst);
037e8744 14456 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14457 }
14458 else
14459 {
4316f0d2
DG
14460 const int three_ops_form = (inst.operands[2].present
14461 && !inst.operands[2].isreg);
14462 const int immoperand = (three_ops_form ? 2 : 1);
14463 enum neon_shape rs = (three_ops_form
14464 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14465 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14466 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14467 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14468 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14469 unsigned immbits;
14470 int cmode;
5f4273c7 14471
5287ad62 14472 if (et.type == NT_invtype)
477330fc 14473 return;
5f4273c7 14474
4316f0d2
DG
14475 if (three_ops_form)
14476 constraint (inst.operands[0].reg != inst.operands[1].reg,
14477 _("first and second operands shall be the same register"));
14478
88714cb8 14479 NEON_ENCODE (IMMED, inst);
5287ad62 14480
4316f0d2 14481 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14482 if (et.size == 64)
14483 {
14484 /* .i64 is a pseudo-op, so the immediate must be a repeating
14485 pattern. */
4316f0d2
DG
14486 if (immbits != (inst.operands[immoperand].regisimm ?
14487 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14488 {
14489 /* Set immbits to an invalid constant. */
14490 immbits = 0xdeadbeef;
14491 }
14492 }
14493
5287ad62 14494 switch (opcode)
477330fc
RM
14495 {
14496 case N_MNEM_vbic:
14497 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14498 break;
14499
14500 case N_MNEM_vorr:
14501 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14502 break;
14503
14504 case N_MNEM_vand:
14505 /* Pseudo-instruction for VBIC. */
14506 neon_invert_size (&immbits, 0, et.size);
14507 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14508 break;
14509
14510 case N_MNEM_vorn:
14511 /* Pseudo-instruction for VORR. */
14512 neon_invert_size (&immbits, 0, et.size);
14513 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14514 break;
14515
14516 default:
14517 abort ();
14518 }
5287ad62
JB
14519
14520 if (cmode == FAIL)
477330fc 14521 return;
5287ad62 14522
037e8744 14523 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14524 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14525 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14526 inst.instruction |= cmode << 8;
14527 neon_write_immbits (immbits);
5f4273c7 14528
88714cb8 14529 neon_dp_fixup (&inst);
5287ad62
JB
14530 }
14531}
14532
14533static void
14534do_neon_bitfield (void)
14535{
037e8744 14536 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14537 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14538 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14539}
14540
14541static void
dcbf9037 14542neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14543 unsigned destbits)
5287ad62 14544{
037e8744 14545 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14546 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14547 types | N_KEY);
5287ad62
JB
14548 if (et.type == NT_float)
14549 {
88714cb8 14550 NEON_ENCODE (FLOAT, inst);
037e8744 14551 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14552 }
14553 else
14554 {
88714cb8 14555 NEON_ENCODE (INTEGER, inst);
037e8744 14556 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14557 }
14558}
14559
14560static void
14561do_neon_dyadic_if_su (void)
14562{
dcbf9037 14563 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14564}
14565
14566static void
14567do_neon_dyadic_if_su_d (void)
14568{
14569 /* This version only allow D registers, but that constraint is enforced during
14570 operand parsing so we don't need to do anything extra here. */
dcbf9037 14571 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14572}
14573
5287ad62
JB
14574static void
14575do_neon_dyadic_if_i_d (void)
14576{
428e3f1f
PB
14577 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14578 affected if we specify unsigned args. */
14579 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14580}
14581
037e8744
JB
14582enum vfp_or_neon_is_neon_bits
14583{
14584 NEON_CHECK_CC = 1,
73924fbc
MGD
14585 NEON_CHECK_ARCH = 2,
14586 NEON_CHECK_ARCH8 = 4
037e8744
JB
14587};
14588
14589/* Call this function if an instruction which may have belonged to the VFP or
14590 Neon instruction sets, but turned out to be a Neon instruction (due to the
14591 operand types involved, etc.). We have to check and/or fix-up a couple of
14592 things:
14593
14594 - Make sure the user hasn't attempted to make a Neon instruction
14595 conditional.
14596 - Alter the value in the condition code field if necessary.
14597 - Make sure that the arch supports Neon instructions.
14598
14599 Which of these operations take place depends on bits from enum
14600 vfp_or_neon_is_neon_bits.
14601
14602 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14603 current instruction's condition is COND_ALWAYS, the condition field is
14604 changed to inst.uncond_value. This is necessary because instructions shared
14605 between VFP and Neon may be conditional for the VFP variants only, and the
14606 unconditional Neon version must have, e.g., 0xF in the condition field. */
14607
14608static int
14609vfp_or_neon_is_neon (unsigned check)
14610{
14611 /* Conditions are always legal in Thumb mode (IT blocks). */
14612 if (!thumb_mode && (check & NEON_CHECK_CC))
14613 {
14614 if (inst.cond != COND_ALWAYS)
477330fc
RM
14615 {
14616 first_error (_(BAD_COND));
14617 return FAIL;
14618 }
037e8744 14619 if (inst.uncond_value != -1)
477330fc 14620 inst.instruction |= inst.uncond_value << 28;
037e8744 14621 }
5f4273c7 14622
037e8744 14623 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14624 && !mark_feature_used (&fpu_neon_ext_v1))
14625 {
14626 first_error (_(BAD_FPU));
14627 return FAIL;
14628 }
14629
14630 if ((check & NEON_CHECK_ARCH8)
14631 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14632 {
14633 first_error (_(BAD_FPU));
14634 return FAIL;
14635 }
5f4273c7 14636
037e8744
JB
14637 return SUCCESS;
14638}
14639
5287ad62
JB
14640static void
14641do_neon_addsub_if_i (void)
14642{
037e8744
JB
14643 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14644 return;
14645
14646 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14647 return;
14648
5287ad62
JB
14649 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14650 affected if we specify unsigned args. */
dcbf9037 14651 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14652}
14653
14654/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14655 result to be:
14656 V<op> A,B (A is operand 0, B is operand 2)
14657 to mean:
14658 V<op> A,B,A
14659 not:
14660 V<op> A,B,B
14661 so handle that case specially. */
14662
14663static void
14664neon_exchange_operands (void)
14665{
14666 void *scratch = alloca (sizeof (inst.operands[0]));
14667 if (inst.operands[1].present)
14668 {
14669 /* Swap operands[1] and operands[2]. */
14670 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14671 inst.operands[1] = inst.operands[2];
14672 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
14673 }
14674 else
14675 {
14676 inst.operands[1] = inst.operands[2];
14677 inst.operands[2] = inst.operands[0];
14678 }
14679}
14680
14681static void
14682neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14683{
14684 if (inst.operands[2].isreg)
14685 {
14686 if (invert)
477330fc 14687 neon_exchange_operands ();
dcbf9037 14688 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14689 }
14690 else
14691 {
037e8744 14692 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 14693 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14694 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 14695
88714cb8 14696 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14697 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14698 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14699 inst.instruction |= LOW4 (inst.operands[1].reg);
14700 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14701 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14702 inst.instruction |= (et.type == NT_float) << 10;
14703 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14704
88714cb8 14705 neon_dp_fixup (&inst);
5287ad62
JB
14706 }
14707}
14708
14709static void
14710do_neon_cmp (void)
14711{
14712 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
14713}
14714
14715static void
14716do_neon_cmp_inv (void)
14717{
14718 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
14719}
14720
14721static void
14722do_neon_ceq (void)
14723{
14724 neon_compare (N_IF_32, N_IF_32, FALSE);
14725}
14726
14727/* For multiply instructions, we have the possibility of 16-bit or 32-bit
14728 scalars, which are encoded in 5 bits, M : Rm.
14729 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14730 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14731 index in M. */
14732
14733static unsigned
14734neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14735{
dcbf9037
JB
14736 unsigned regno = NEON_SCALAR_REG (scalar);
14737 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
14738
14739 switch (elsize)
14740 {
14741 case 16:
14742 if (regno > 7 || elno > 3)
477330fc 14743 goto bad_scalar;
5287ad62 14744 return regno | (elno << 3);
5f4273c7 14745
5287ad62
JB
14746 case 32:
14747 if (regno > 15 || elno > 1)
477330fc 14748 goto bad_scalar;
5287ad62
JB
14749 return regno | (elno << 4);
14750
14751 default:
14752 bad_scalar:
dcbf9037 14753 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
14754 }
14755
14756 return 0;
14757}
14758
14759/* Encode multiply / multiply-accumulate scalar instructions. */
14760
14761static void
14762neon_mul_mac (struct neon_type_el et, int ubit)
14763{
dcbf9037
JB
14764 unsigned scalar;
14765
14766 /* Give a more helpful error message if we have an invalid type. */
14767 if (et.type == NT_invtype)
14768 return;
5f4273c7 14769
dcbf9037 14770 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
14771 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14772 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14773 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14774 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14775 inst.instruction |= LOW4 (scalar);
14776 inst.instruction |= HI1 (scalar) << 5;
14777 inst.instruction |= (et.type == NT_float) << 8;
14778 inst.instruction |= neon_logbits (et.size) << 20;
14779 inst.instruction |= (ubit != 0) << 24;
14780
88714cb8 14781 neon_dp_fixup (&inst);
5287ad62
JB
14782}
14783
14784static void
14785do_neon_mac_maybe_scalar (void)
14786{
037e8744
JB
14787 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14788 return;
14789
14790 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14791 return;
14792
5287ad62
JB
14793 if (inst.operands[2].isscalar)
14794 {
037e8744 14795 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 14796 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14797 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 14798 NEON_ENCODE (SCALAR, inst);
037e8744 14799 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14800 }
14801 else
428e3f1f
PB
14802 {
14803 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14804 affected if we specify unsigned args. */
14805 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14806 }
5287ad62
JB
14807}
14808
62f3b8c8
PB
14809static void
14810do_neon_fmac (void)
14811{
14812 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
14813 return;
14814
14815 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14816 return;
14817
14818 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14819}
14820
5287ad62
JB
14821static void
14822do_neon_tst (void)
14823{
037e8744 14824 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14825 struct neon_type_el et = neon_check_type (3, rs,
14826 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 14827 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14828}
14829
14830/* VMUL with 3 registers allows the P8 type. The scalar version supports the
14831 same types as the MAC equivalents. The polynomial type for this instruction
14832 is encoded the same as the integer type. */
14833
14834static void
14835do_neon_mul (void)
14836{
037e8744
JB
14837 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14838 return;
14839
14840 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14841 return;
14842
5287ad62
JB
14843 if (inst.operands[2].isscalar)
14844 do_neon_mac_maybe_scalar ();
14845 else
dcbf9037 14846 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
14847}
14848
14849static void
14850do_neon_qdmulh (void)
14851{
14852 if (inst.operands[2].isscalar)
14853 {
037e8744 14854 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 14855 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14856 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14857 NEON_ENCODE (SCALAR, inst);
037e8744 14858 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14859 }
14860 else
14861 {
037e8744 14862 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14863 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14864 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14865 NEON_ENCODE (INTEGER, inst);
5287ad62 14866 /* The U bit (rounding) comes from bit mask. */
037e8744 14867 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14868 }
14869}
14870
14871static void
14872do_neon_fcmp_absolute (void)
14873{
037e8744 14874 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14875 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14876 /* Size field comes from bit mask. */
037e8744 14877 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
14878}
14879
14880static void
14881do_neon_fcmp_absolute_inv (void)
14882{
14883 neon_exchange_operands ();
14884 do_neon_fcmp_absolute ();
14885}
14886
14887static void
14888do_neon_step (void)
14889{
037e8744 14890 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14891 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 14892 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14893}
14894
14895static void
14896do_neon_abs_neg (void)
14897{
037e8744
JB
14898 enum neon_shape rs;
14899 struct neon_type_el et;
5f4273c7 14900
037e8744
JB
14901 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
14902 return;
14903
14904 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14905 return;
14906
14907 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14908 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 14909
5287ad62
JB
14910 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14911 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14912 inst.instruction |= LOW4 (inst.operands[1].reg);
14913 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14914 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14915 inst.instruction |= (et.type == NT_float) << 10;
14916 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14917
88714cb8 14918 neon_dp_fixup (&inst);
5287ad62
JB
14919}
14920
14921static void
14922do_neon_sli (void)
14923{
037e8744 14924 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14925 struct neon_type_el et = neon_check_type (2, rs,
14926 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14927 int imm = inst.operands[2].imm;
14928 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 14929 _("immediate out of range for insert"));
037e8744 14930 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14931}
14932
14933static void
14934do_neon_sri (void)
14935{
037e8744 14936 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14937 struct neon_type_el et = neon_check_type (2, rs,
14938 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14939 int imm = inst.operands[2].imm;
14940 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14941 _("immediate out of range for insert"));
037e8744 14942 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
14943}
14944
14945static void
14946do_neon_qshlu_imm (void)
14947{
037e8744 14948 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14949 struct neon_type_el et = neon_check_type (2, rs,
14950 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14951 int imm = inst.operands[2].imm;
14952 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 14953 _("immediate out of range for shift"));
5287ad62
JB
14954 /* Only encodes the 'U present' variant of the instruction.
14955 In this case, signed types have OP (bit 8) set to 0.
14956 Unsigned types have OP set to 1. */
14957 inst.instruction |= (et.type == NT_unsigned) << 8;
14958 /* The rest of the bits are the same as other immediate shifts. */
037e8744 14959 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14960}
14961
14962static void
14963do_neon_qmovn (void)
14964{
14965 struct neon_type_el et = neon_check_type (2, NS_DQ,
14966 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14967 /* Saturating move where operands can be signed or unsigned, and the
14968 destination has the same signedness. */
88714cb8 14969 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14970 if (et.type == NT_unsigned)
14971 inst.instruction |= 0xc0;
14972 else
14973 inst.instruction |= 0x80;
14974 neon_two_same (0, 1, et.size / 2);
14975}
14976
14977static void
14978do_neon_qmovun (void)
14979{
14980 struct neon_type_el et = neon_check_type (2, NS_DQ,
14981 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14982 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 14983 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14984 neon_two_same (0, 1, et.size / 2);
14985}
14986
14987static void
14988do_neon_rshift_sat_narrow (void)
14989{
14990 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14991 or unsigned. If operands are unsigned, results must also be unsigned. */
14992 struct neon_type_el et = neon_check_type (2, NS_DQI,
14993 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14994 int imm = inst.operands[2].imm;
14995 /* This gets the bounds check, size encoding and immediate bits calculation
14996 right. */
14997 et.size /= 2;
5f4273c7 14998
5287ad62
JB
14999 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15000 VQMOVN.I<size> <Dd>, <Qm>. */
15001 if (imm == 0)
15002 {
15003 inst.operands[2].present = 0;
15004 inst.instruction = N_MNEM_vqmovn;
15005 do_neon_qmovn ();
15006 return;
15007 }
5f4273c7 15008
5287ad62 15009 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15010 _("immediate out of range"));
5287ad62
JB
15011 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15012}
15013
15014static void
15015do_neon_rshift_sat_narrow_u (void)
15016{
15017 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15018 or unsigned. If operands are unsigned, results must also be unsigned. */
15019 struct neon_type_el et = neon_check_type (2, NS_DQI,
15020 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15021 int imm = inst.operands[2].imm;
15022 /* This gets the bounds check, size encoding and immediate bits calculation
15023 right. */
15024 et.size /= 2;
15025
15026 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15027 VQMOVUN.I<size> <Dd>, <Qm>. */
15028 if (imm == 0)
15029 {
15030 inst.operands[2].present = 0;
15031 inst.instruction = N_MNEM_vqmovun;
15032 do_neon_qmovun ();
15033 return;
15034 }
15035
15036 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15037 _("immediate out of range"));
5287ad62
JB
15038 /* FIXME: The manual is kind of unclear about what value U should have in
15039 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15040 must be 1. */
15041 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15042}
15043
15044static void
15045do_neon_movn (void)
15046{
15047 struct neon_type_el et = neon_check_type (2, NS_DQ,
15048 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15049 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15050 neon_two_same (0, 1, et.size / 2);
15051}
15052
15053static void
15054do_neon_rshift_narrow (void)
15055{
15056 struct neon_type_el et = neon_check_type (2, NS_DQI,
15057 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15058 int imm = inst.operands[2].imm;
15059 /* This gets the bounds check, size encoding and immediate bits calculation
15060 right. */
15061 et.size /= 2;
5f4273c7 15062
5287ad62
JB
15063 /* If immediate is zero then we are a pseudo-instruction for
15064 VMOVN.I<size> <Dd>, <Qm> */
15065 if (imm == 0)
15066 {
15067 inst.operands[2].present = 0;
15068 inst.instruction = N_MNEM_vmovn;
15069 do_neon_movn ();
15070 return;
15071 }
5f4273c7 15072
5287ad62 15073 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15074 _("immediate out of range for narrowing operation"));
5287ad62
JB
15075 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15076}
15077
15078static void
15079do_neon_shll (void)
15080{
15081 /* FIXME: Type checking when lengthening. */
15082 struct neon_type_el et = neon_check_type (2, NS_QDI,
15083 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15084 unsigned imm = inst.operands[2].imm;
15085
15086 if (imm == et.size)
15087 {
15088 /* Maximum shift variant. */
88714cb8 15089 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15090 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15091 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15092 inst.instruction |= LOW4 (inst.operands[1].reg);
15093 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15094 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15095
88714cb8 15096 neon_dp_fixup (&inst);
5287ad62
JB
15097 }
15098 else
15099 {
15100 /* A more-specific type check for non-max versions. */
15101 et = neon_check_type (2, NS_QDI,
477330fc 15102 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15103 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15104 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15105 }
15106}
15107
037e8744 15108/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15109 the current instruction is. */
15110
6b9a8b67
MGD
15111#define CVT_FLAVOUR_VAR \
15112 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15113 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15114 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15115 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15116 /* Half-precision conversions. */ \
15117 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15118 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
15119 /* VFP instructions. */ \
15120 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15121 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15122 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15123 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15124 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15125 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15126 /* VFP instructions with bitshift. */ \
15127 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15128 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15129 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15130 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15131 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15132 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15133 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15134 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15135
15136#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15137 neon_cvt_flavour_##C,
15138
15139/* The different types of conversions we can do. */
15140enum neon_cvt_flavour
15141{
15142 CVT_FLAVOUR_VAR
15143 neon_cvt_flavour_invalid,
15144 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15145};
15146
15147#undef CVT_VAR
15148
15149static enum neon_cvt_flavour
15150get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15151{
6b9a8b67
MGD
15152#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15153 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15154 if (et.type != NT_invtype) \
15155 { \
15156 inst.error = NULL; \
15157 return (neon_cvt_flavour_##C); \
5287ad62 15158 }
6b9a8b67 15159
5287ad62 15160 struct neon_type_el et;
037e8744 15161 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15162 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15163 /* The instruction versions which take an immediate take one register
15164 argument, which is extended to the width of the full register. Thus the
15165 "source" and "destination" registers must have the same width. Hack that
15166 here by making the size equal to the key (wider, in this case) operand. */
15167 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15168
6b9a8b67
MGD
15169 CVT_FLAVOUR_VAR;
15170
15171 return neon_cvt_flavour_invalid;
5287ad62
JB
15172#undef CVT_VAR
15173}
15174
7e8e6784
MGD
15175enum neon_cvt_mode
15176{
15177 neon_cvt_mode_a,
15178 neon_cvt_mode_n,
15179 neon_cvt_mode_p,
15180 neon_cvt_mode_m,
15181 neon_cvt_mode_z,
30bdf752
MGD
15182 neon_cvt_mode_x,
15183 neon_cvt_mode_r
7e8e6784
MGD
15184};
15185
037e8744
JB
15186/* Neon-syntax VFP conversions. */
15187
5287ad62 15188static void
6b9a8b67 15189do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15190{
037e8744 15191 const char *opname = 0;
5f4273c7 15192
037e8744 15193 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 15194 {
037e8744
JB
15195 /* Conversions with immediate bitshift. */
15196 const char *enc[] =
477330fc 15197 {
6b9a8b67
MGD
15198#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15199 CVT_FLAVOUR_VAR
15200 NULL
15201#undef CVT_VAR
477330fc 15202 };
037e8744 15203
6b9a8b67 15204 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15205 {
15206 opname = enc[flavour];
15207 constraint (inst.operands[0].reg != inst.operands[1].reg,
15208 _("operands 0 and 1 must be the same register"));
15209 inst.operands[1] = inst.operands[2];
15210 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15211 }
5287ad62
JB
15212 }
15213 else
15214 {
037e8744
JB
15215 /* Conversions without bitshift. */
15216 const char *enc[] =
477330fc 15217 {
6b9a8b67
MGD
15218#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15219 CVT_FLAVOUR_VAR
15220 NULL
15221#undef CVT_VAR
477330fc 15222 };
037e8744 15223
6b9a8b67 15224 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15225 opname = enc[flavour];
037e8744
JB
15226 }
15227
15228 if (opname)
15229 do_vfp_nsyn_opcode (opname);
15230}
15231
15232static void
15233do_vfp_nsyn_cvtz (void)
15234{
15235 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
6b9a8b67 15236 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15237 const char *enc[] =
15238 {
6b9a8b67
MGD
15239#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15240 CVT_FLAVOUR_VAR
15241 NULL
15242#undef CVT_VAR
037e8744
JB
15243 };
15244
6b9a8b67 15245 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15246 do_vfp_nsyn_opcode (enc[flavour]);
15247}
f31fef98 15248
037e8744 15249static void
bacebabc 15250do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15251 enum neon_cvt_mode mode)
15252{
15253 int sz, op;
15254 int rm;
15255
a715796b
TG
15256 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15257 D register operands. */
15258 if (flavour == neon_cvt_flavour_s32_f64
15259 || flavour == neon_cvt_flavour_u32_f64)
15260 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15261 _(BAD_FPU));
15262
7e8e6784
MGD
15263 set_it_insn_type (OUTSIDE_IT_INSN);
15264
15265 switch (flavour)
15266 {
15267 case neon_cvt_flavour_s32_f64:
15268 sz = 1;
827f64ff 15269 op = 1;
7e8e6784
MGD
15270 break;
15271 case neon_cvt_flavour_s32_f32:
15272 sz = 0;
15273 op = 1;
15274 break;
15275 case neon_cvt_flavour_u32_f64:
15276 sz = 1;
15277 op = 0;
15278 break;
15279 case neon_cvt_flavour_u32_f32:
15280 sz = 0;
15281 op = 0;
15282 break;
15283 default:
15284 first_error (_("invalid instruction shape"));
15285 return;
15286 }
15287
15288 switch (mode)
15289 {
15290 case neon_cvt_mode_a: rm = 0; break;
15291 case neon_cvt_mode_n: rm = 1; break;
15292 case neon_cvt_mode_p: rm = 2; break;
15293 case neon_cvt_mode_m: rm = 3; break;
15294 default: first_error (_("invalid rounding mode")); return;
15295 }
15296
15297 NEON_ENCODE (FPV8, inst);
15298 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15299 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15300 inst.instruction |= sz << 8;
15301 inst.instruction |= op << 7;
15302 inst.instruction |= rm << 16;
15303 inst.instruction |= 0xf0000000;
15304 inst.is_neon = TRUE;
15305}
15306
15307static void
15308do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15309{
15310 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 15311 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
6b9a8b67 15312 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15313
e3e535bc 15314 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15315 if (mode == neon_cvt_mode_z
e3e535bc 15316 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
bacebabc
RM
15317 && (flavour == neon_cvt_flavour_s32_f32
15318 || flavour == neon_cvt_flavour_u32_f32
15319 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15320 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15321 && (rs == NS_FD || rs == NS_FF))
15322 {
15323 do_vfp_nsyn_cvtz ();
15324 return;
15325 }
15326
037e8744 15327 /* VFP rather than Neon conversions. */
6b9a8b67 15328 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15329 {
7e8e6784
MGD
15330 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15331 do_vfp_nsyn_cvt (rs, flavour);
15332 else
15333 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15334
037e8744
JB
15335 return;
15336 }
15337
15338 switch (rs)
15339 {
15340 case NS_DDI:
15341 case NS_QQI:
15342 {
477330fc
RM
15343 unsigned immbits;
15344 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
35997600 15345
477330fc
RM
15346 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15347 return;
037e8744 15348
477330fc
RM
15349 /* Fixed-point conversion with #0 immediate is encoded as an
15350 integer conversion. */
15351 if (inst.operands[2].present && inst.operands[2].imm == 0)
15352 goto int_encode;
35997600 15353 immbits = 32 - inst.operands[2].imm;
477330fc
RM
15354 NEON_ENCODE (IMMED, inst);
15355 if (flavour != neon_cvt_flavour_invalid)
15356 inst.instruction |= enctab[flavour];
15357 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15358 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15359 inst.instruction |= LOW4 (inst.operands[1].reg);
15360 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15361 inst.instruction |= neon_quad (rs) << 6;
15362 inst.instruction |= 1 << 21;
15363 inst.instruction |= immbits << 16;
15364
15365 neon_dp_fixup (&inst);
037e8744
JB
15366 }
15367 break;
15368
15369 case NS_DD:
15370 case NS_QQ:
7e8e6784
MGD
15371 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15372 {
15373 NEON_ENCODE (FLOAT, inst);
15374 set_it_insn_type (OUTSIDE_IT_INSN);
15375
15376 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15377 return;
15378
15379 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15380 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15381 inst.instruction |= LOW4 (inst.operands[1].reg);
15382 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15383 inst.instruction |= neon_quad (rs) << 6;
15384 inst.instruction |= (flavour == neon_cvt_flavour_u32_f32) << 7;
15385 inst.instruction |= mode << 8;
15386 if (thumb_mode)
15387 inst.instruction |= 0xfc000000;
15388 else
15389 inst.instruction |= 0xf0000000;
15390 }
15391 else
15392 {
037e8744 15393 int_encode:
7e8e6784
MGD
15394 {
15395 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
037e8744 15396
7e8e6784 15397 NEON_ENCODE (INTEGER, inst);
037e8744 15398
7e8e6784
MGD
15399 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15400 return;
037e8744 15401
7e8e6784
MGD
15402 if (flavour != neon_cvt_flavour_invalid)
15403 inst.instruction |= enctab[flavour];
037e8744 15404
7e8e6784
MGD
15405 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15406 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15407 inst.instruction |= LOW4 (inst.operands[1].reg);
15408 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15409 inst.instruction |= neon_quad (rs) << 6;
15410 inst.instruction |= 2 << 18;
037e8744 15411
7e8e6784
MGD
15412 neon_dp_fixup (&inst);
15413 }
15414 }
15415 break;
037e8744 15416
8e79c3df
CM
15417 /* Half-precision conversions for Advanced SIMD -- neon. */
15418 case NS_QD:
15419 case NS_DQ:
15420
15421 if ((rs == NS_DQ)
15422 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15423 {
15424 as_bad (_("operand size must match register width"));
15425 break;
15426 }
15427
15428 if ((rs == NS_QD)
15429 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15430 {
15431 as_bad (_("operand size must match register width"));
15432 break;
15433 }
15434
15435 if (rs == NS_DQ)
477330fc 15436 inst.instruction = 0x3b60600;
8e79c3df
CM
15437 else
15438 inst.instruction = 0x3b60700;
15439
15440 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15441 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15442 inst.instruction |= LOW4 (inst.operands[1].reg);
15443 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15444 neon_dp_fixup (&inst);
8e79c3df
CM
15445 break;
15446
037e8744
JB
15447 default:
15448 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15449 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15450 do_vfp_nsyn_cvt (rs, flavour);
15451 else
15452 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15453 }
5287ad62
JB
15454}
15455
e3e535bc
NC
15456static void
15457do_neon_cvtr (void)
15458{
7e8e6784 15459 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15460}
15461
15462static void
15463do_neon_cvt (void)
15464{
7e8e6784
MGD
15465 do_neon_cvt_1 (neon_cvt_mode_z);
15466}
15467
15468static void
15469do_neon_cvta (void)
15470{
15471 do_neon_cvt_1 (neon_cvt_mode_a);
15472}
15473
15474static void
15475do_neon_cvtn (void)
15476{
15477 do_neon_cvt_1 (neon_cvt_mode_n);
15478}
15479
15480static void
15481do_neon_cvtp (void)
15482{
15483 do_neon_cvt_1 (neon_cvt_mode_p);
15484}
15485
15486static void
15487do_neon_cvtm (void)
15488{
15489 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15490}
15491
8e79c3df 15492static void
c70a8987 15493do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15494{
c70a8987
MGD
15495 if (is_double)
15496 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15497
c70a8987
MGD
15498 encode_arm_vfp_reg (inst.operands[0].reg,
15499 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15500 encode_arm_vfp_reg (inst.operands[1].reg,
15501 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15502 inst.instruction |= to ? 0x10000 : 0;
15503 inst.instruction |= t ? 0x80 : 0;
15504 inst.instruction |= is_double ? 0x100 : 0;
15505 do_vfp_cond_or_thumb ();
15506}
8e79c3df 15507
c70a8987
MGD
15508static void
15509do_neon_cvttb_1 (bfd_boolean t)
15510{
15511 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_DF, NS_NULL);
8e79c3df 15512
c70a8987
MGD
15513 if (rs == NS_NULL)
15514 return;
15515 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15516 {
15517 inst.error = NULL;
15518 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15519 }
15520 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15521 {
15522 inst.error = NULL;
15523 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15524 }
15525 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15526 {
a715796b
TG
15527 /* The VCVTB and VCVTT instructions with D-register operands
15528 don't work for SP only targets. */
15529 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15530 _(BAD_FPU));
15531
c70a8987
MGD
15532 inst.error = NULL;
15533 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15534 }
15535 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15536 {
a715796b
TG
15537 /* The VCVTB and VCVTT instructions with D-register operands
15538 don't work for SP only targets. */
15539 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15540 _(BAD_FPU));
15541
c70a8987
MGD
15542 inst.error = NULL;
15543 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15544 }
15545 else
15546 return;
15547}
15548
15549static void
15550do_neon_cvtb (void)
15551{
15552 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15553}
15554
15555
15556static void
15557do_neon_cvtt (void)
15558{
c70a8987 15559 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15560}
15561
5287ad62
JB
15562static void
15563neon_move_immediate (void)
15564{
037e8744
JB
15565 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15566 struct neon_type_el et = neon_check_type (2, rs,
15567 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15568 unsigned immlo, immhi = 0, immbits;
c96612cc 15569 int op, cmode, float_p;
5287ad62 15570
037e8744 15571 constraint (et.type == NT_invtype,
477330fc 15572 _("operand size must be specified for immediate VMOV"));
037e8744 15573
5287ad62
JB
15574 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15575 op = (inst.instruction & (1 << 5)) != 0;
15576
15577 immlo = inst.operands[1].imm;
15578 if (inst.operands[1].regisimm)
15579 immhi = inst.operands[1].reg;
15580
15581 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 15582 _("immediate has bits set outside the operand size"));
5287ad62 15583
c96612cc
JB
15584 float_p = inst.operands[1].immisfloat;
15585
15586 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 15587 et.size, et.type)) == FAIL)
5287ad62
JB
15588 {
15589 /* Invert relevant bits only. */
15590 neon_invert_size (&immlo, &immhi, et.size);
15591 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
15592 with one or the other; those cases are caught by
15593 neon_cmode_for_move_imm. */
5287ad62 15594 op = !op;
c96612cc
JB
15595 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15596 &op, et.size, et.type)) == FAIL)
477330fc
RM
15597 {
15598 first_error (_("immediate out of range"));
15599 return;
15600 }
5287ad62
JB
15601 }
15602
15603 inst.instruction &= ~(1 << 5);
15604 inst.instruction |= op << 5;
15605
15606 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15607 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 15608 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15609 inst.instruction |= cmode << 8;
15610
15611 neon_write_immbits (immbits);
15612}
15613
15614static void
15615do_neon_mvn (void)
15616{
15617 if (inst.operands[1].isreg)
15618 {
037e8744 15619 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 15620
88714cb8 15621 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15622 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15623 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15624 inst.instruction |= LOW4 (inst.operands[1].reg);
15625 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15626 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15627 }
15628 else
15629 {
88714cb8 15630 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15631 neon_move_immediate ();
15632 }
15633
88714cb8 15634 neon_dp_fixup (&inst);
5287ad62
JB
15635}
15636
15637/* Encode instructions of form:
15638
15639 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 15640 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
15641
15642static void
15643neon_mixed_length (struct neon_type_el et, unsigned size)
15644{
15645 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15646 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15647 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15648 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15649 inst.instruction |= LOW4 (inst.operands[2].reg);
15650 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15651 inst.instruction |= (et.type == NT_unsigned) << 24;
15652 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 15653
88714cb8 15654 neon_dp_fixup (&inst);
5287ad62
JB
15655}
15656
15657static void
15658do_neon_dyadic_long (void)
15659{
15660 /* FIXME: Type checking for lengthening op. */
15661 struct neon_type_el et = neon_check_type (3, NS_QDD,
15662 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
15663 neon_mixed_length (et, et.size);
15664}
15665
15666static void
15667do_neon_abal (void)
15668{
15669 struct neon_type_el et = neon_check_type (3, NS_QDD,
15670 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
15671 neon_mixed_length (et, et.size);
15672}
15673
15674static void
15675neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
15676{
15677 if (inst.operands[2].isscalar)
15678 {
dcbf9037 15679 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 15680 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 15681 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15682 neon_mul_mac (et, et.type == NT_unsigned);
15683 }
15684 else
15685 {
15686 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 15687 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 15688 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15689 neon_mixed_length (et, et.size);
15690 }
15691}
15692
15693static void
15694do_neon_mac_maybe_scalar_long (void)
15695{
15696 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
15697}
15698
15699static void
15700do_neon_dyadic_wide (void)
15701{
15702 struct neon_type_el et = neon_check_type (3, NS_QQD,
15703 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
15704 neon_mixed_length (et, et.size);
15705}
15706
15707static void
15708do_neon_dyadic_narrow (void)
15709{
15710 struct neon_type_el et = neon_check_type (3, NS_QDD,
15711 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
15712 /* Operand sign is unimportant, and the U bit is part of the opcode,
15713 so force the operand type to integer. */
15714 et.type = NT_integer;
5287ad62
JB
15715 neon_mixed_length (et, et.size / 2);
15716}
15717
15718static void
15719do_neon_mul_sat_scalar_long (void)
15720{
15721 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
15722}
15723
15724static void
15725do_neon_vmull (void)
15726{
15727 if (inst.operands[2].isscalar)
15728 do_neon_mac_maybe_scalar_long ();
15729 else
15730 {
15731 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 15732 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 15733
5287ad62 15734 if (et.type == NT_poly)
477330fc 15735 NEON_ENCODE (POLY, inst);
5287ad62 15736 else
477330fc 15737 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
15738
15739 /* For polynomial encoding the U bit must be zero, and the size must
15740 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
15741 obviously, as 0b10). */
15742 if (et.size == 64)
15743 {
15744 /* Check we're on the correct architecture. */
15745 if (!mark_feature_used (&fpu_crypto_ext_armv8))
15746 inst.error =
15747 _("Instruction form not available on this architecture.");
15748
15749 et.size = 32;
15750 }
15751
5287ad62
JB
15752 neon_mixed_length (et, et.size);
15753 }
15754}
15755
15756static void
15757do_neon_ext (void)
15758{
037e8744 15759 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
15760 struct neon_type_el et = neon_check_type (3, rs,
15761 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15762 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
15763
15764 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
15765 _("shift out of range"));
5287ad62
JB
15766 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15767 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15768 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15769 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15770 inst.instruction |= LOW4 (inst.operands[2].reg);
15771 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 15772 inst.instruction |= neon_quad (rs) << 6;
5287ad62 15773 inst.instruction |= imm << 8;
5f4273c7 15774
88714cb8 15775 neon_dp_fixup (&inst);
5287ad62
JB
15776}
15777
15778static void
15779do_neon_rev (void)
15780{
037e8744 15781 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15782 struct neon_type_el et = neon_check_type (2, rs,
15783 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15784 unsigned op = (inst.instruction >> 7) & 3;
15785 /* N (width of reversed regions) is encoded as part of the bitmask. We
15786 extract it here to check the elements to be reversed are smaller.
15787 Otherwise we'd get a reserved instruction. */
15788 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 15789 gas_assert (elsize != 0);
5287ad62 15790 constraint (et.size >= elsize,
477330fc 15791 _("elements must be smaller than reversal region"));
037e8744 15792 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15793}
15794
15795static void
15796do_neon_dup (void)
15797{
15798 if (inst.operands[1].isscalar)
15799 {
037e8744 15800 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 15801 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15802 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 15803 unsigned sizebits = et.size >> 3;
dcbf9037 15804 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 15805 int logsize = neon_logbits (et.size);
dcbf9037 15806 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
15807
15808 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 15809 return;
037e8744 15810
88714cb8 15811 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15812 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15813 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15814 inst.instruction |= LOW4 (dm);
15815 inst.instruction |= HI1 (dm) << 5;
037e8744 15816 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15817 inst.instruction |= x << 17;
15818 inst.instruction |= sizebits << 16;
5f4273c7 15819
88714cb8 15820 neon_dp_fixup (&inst);
5287ad62
JB
15821 }
15822 else
15823 {
037e8744
JB
15824 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
15825 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15826 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 15827 /* Duplicate ARM register to lanes of vector. */
88714cb8 15828 NEON_ENCODE (ARMREG, inst);
5287ad62 15829 switch (et.size)
477330fc
RM
15830 {
15831 case 8: inst.instruction |= 0x400000; break;
15832 case 16: inst.instruction |= 0x000020; break;
15833 case 32: inst.instruction |= 0x000000; break;
15834 default: break;
15835 }
5287ad62
JB
15836 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15837 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
15838 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 15839 inst.instruction |= neon_quad (rs) << 21;
5287ad62 15840 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 15841 variants, except for the condition field. */
037e8744 15842 do_vfp_cond_or_thumb ();
5287ad62
JB
15843 }
15844}
15845
15846/* VMOV has particularly many variations. It can be one of:
15847 0. VMOV<c><q> <Qd>, <Qm>
15848 1. VMOV<c><q> <Dd>, <Dm>
15849 (Register operations, which are VORR with Rm = Rn.)
15850 2. VMOV<c><q>.<dt> <Qd>, #<imm>
15851 3. VMOV<c><q>.<dt> <Dd>, #<imm>
15852 (Immediate loads.)
15853 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
15854 (ARM register to scalar.)
15855 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
15856 (Two ARM registers to vector.)
15857 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
15858 (Scalar to ARM register.)
15859 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
15860 (Vector to two ARM registers.)
037e8744
JB
15861 8. VMOV.F32 <Sd>, <Sm>
15862 9. VMOV.F64 <Dd>, <Dm>
15863 (VFP register moves.)
15864 10. VMOV.F32 <Sd>, #imm
15865 11. VMOV.F64 <Dd>, #imm
15866 (VFP float immediate load.)
15867 12. VMOV <Rd>, <Sm>
15868 (VFP single to ARM reg.)
15869 13. VMOV <Sd>, <Rm>
15870 (ARM reg to VFP single.)
15871 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
15872 (Two ARM regs to two VFP singles.)
15873 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
15874 (Two VFP singles to two ARM regs.)
5f4273c7 15875
037e8744
JB
15876 These cases can be disambiguated using neon_select_shape, except cases 1/9
15877 and 3/11 which depend on the operand type too.
5f4273c7 15878
5287ad62 15879 All the encoded bits are hardcoded by this function.
5f4273c7 15880
b7fc2769
JB
15881 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
15882 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 15883
5287ad62 15884 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 15885 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
15886
15887static void
15888do_neon_mov (void)
15889{
037e8744
JB
15890 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
15891 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
15892 NS_NULL);
15893 struct neon_type_el et;
15894 const char *ldconst = 0;
5287ad62 15895
037e8744 15896 switch (rs)
5287ad62 15897 {
037e8744
JB
15898 case NS_DD: /* case 1/9. */
15899 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15900 /* It is not an error here if no type is given. */
15901 inst.error = NULL;
15902 if (et.type == NT_float && et.size == 64)
477330fc
RM
15903 {
15904 do_vfp_nsyn_opcode ("fcpyd");
15905 break;
15906 }
037e8744 15907 /* fall through. */
5287ad62 15908
037e8744
JB
15909 case NS_QQ: /* case 0/1. */
15910 {
477330fc
RM
15911 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15912 return;
15913 /* The architecture manual I have doesn't explicitly state which
15914 value the U bit should have for register->register moves, but
15915 the equivalent VORR instruction has U = 0, so do that. */
15916 inst.instruction = 0x0200110;
15917 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15918 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15919 inst.instruction |= LOW4 (inst.operands[1].reg);
15920 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15921 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15922 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15923 inst.instruction |= neon_quad (rs) << 6;
15924
15925 neon_dp_fixup (&inst);
037e8744
JB
15926 }
15927 break;
5f4273c7 15928
037e8744
JB
15929 case NS_DI: /* case 3/11. */
15930 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15931 inst.error = NULL;
15932 if (et.type == NT_float && et.size == 64)
477330fc
RM
15933 {
15934 /* case 11 (fconstd). */
15935 ldconst = "fconstd";
15936 goto encode_fconstd;
15937 }
037e8744
JB
15938 /* fall through. */
15939
15940 case NS_QI: /* case 2/3. */
15941 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 15942 return;
037e8744
JB
15943 inst.instruction = 0x0800010;
15944 neon_move_immediate ();
88714cb8 15945 neon_dp_fixup (&inst);
5287ad62 15946 break;
5f4273c7 15947
037e8744
JB
15948 case NS_SR: /* case 4. */
15949 {
477330fc
RM
15950 unsigned bcdebits = 0;
15951 int logsize;
15952 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
15953 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 15954
05ac0ffb
JB
15955 /* .<size> is optional here, defaulting to .32. */
15956 if (inst.vectype.elems == 0
15957 && inst.operands[0].vectype.type == NT_invtype
15958 && inst.operands[1].vectype.type == NT_invtype)
15959 {
15960 inst.vectype.el[0].type = NT_untyped;
15961 inst.vectype.el[0].size = 32;
15962 inst.vectype.elems = 1;
15963 }
15964
477330fc
RM
15965 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
15966 logsize = neon_logbits (et.size);
15967
15968 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15969 _(BAD_FPU));
15970 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15971 && et.size != 32, _(BAD_FPU));
15972 constraint (et.type == NT_invtype, _("bad type for scalar"));
15973 constraint (x >= 64 / et.size, _("scalar index out of range"));
15974
15975 switch (et.size)
15976 {
15977 case 8: bcdebits = 0x8; break;
15978 case 16: bcdebits = 0x1; break;
15979 case 32: bcdebits = 0x0; break;
15980 default: ;
15981 }
15982
15983 bcdebits |= x << logsize;
15984
15985 inst.instruction = 0xe000b10;
15986 do_vfp_cond_or_thumb ();
15987 inst.instruction |= LOW4 (dn) << 16;
15988 inst.instruction |= HI1 (dn) << 7;
15989 inst.instruction |= inst.operands[1].reg << 12;
15990 inst.instruction |= (bcdebits & 3) << 5;
15991 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
15992 }
15993 break;
5f4273c7 15994
037e8744 15995 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 15996 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 15997 _(BAD_FPU));
b7fc2769 15998
037e8744
JB
15999 inst.instruction = 0xc400b10;
16000 do_vfp_cond_or_thumb ();
16001 inst.instruction |= LOW4 (inst.operands[0].reg);
16002 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16003 inst.instruction |= inst.operands[1].reg << 12;
16004 inst.instruction |= inst.operands[2].reg << 16;
16005 break;
5f4273c7 16006
037e8744
JB
16007 case NS_RS: /* case 6. */
16008 {
477330fc
RM
16009 unsigned logsize;
16010 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16011 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16012 unsigned abcdebits = 0;
037e8744 16013
05ac0ffb
JB
16014 /* .<dt> is optional here, defaulting to .32. */
16015 if (inst.vectype.elems == 0
16016 && inst.operands[0].vectype.type == NT_invtype
16017 && inst.operands[1].vectype.type == NT_invtype)
16018 {
16019 inst.vectype.el[0].type = NT_untyped;
16020 inst.vectype.el[0].size = 32;
16021 inst.vectype.elems = 1;
16022 }
16023
91d6fa6a
NC
16024 et = neon_check_type (2, NS_NULL,
16025 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16026 logsize = neon_logbits (et.size);
16027
16028 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16029 _(BAD_FPU));
16030 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16031 && et.size != 32, _(BAD_FPU));
16032 constraint (et.type == NT_invtype, _("bad type for scalar"));
16033 constraint (x >= 64 / et.size, _("scalar index out of range"));
16034
16035 switch (et.size)
16036 {
16037 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16038 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16039 case 32: abcdebits = 0x00; break;
16040 default: ;
16041 }
16042
16043 abcdebits |= x << logsize;
16044 inst.instruction = 0xe100b10;
16045 do_vfp_cond_or_thumb ();
16046 inst.instruction |= LOW4 (dn) << 16;
16047 inst.instruction |= HI1 (dn) << 7;
16048 inst.instruction |= inst.operands[0].reg << 12;
16049 inst.instruction |= (abcdebits & 3) << 5;
16050 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16051 }
16052 break;
5f4273c7 16053
037e8744
JB
16054 case NS_RRD: /* case 7 (fmrrd). */
16055 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16056 _(BAD_FPU));
037e8744
JB
16057
16058 inst.instruction = 0xc500b10;
16059 do_vfp_cond_or_thumb ();
16060 inst.instruction |= inst.operands[0].reg << 12;
16061 inst.instruction |= inst.operands[1].reg << 16;
16062 inst.instruction |= LOW4 (inst.operands[2].reg);
16063 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16064 break;
5f4273c7 16065
037e8744
JB
16066 case NS_FF: /* case 8 (fcpys). */
16067 do_vfp_nsyn_opcode ("fcpys");
16068 break;
5f4273c7 16069
037e8744
JB
16070 case NS_FI: /* case 10 (fconsts). */
16071 ldconst = "fconsts";
16072 encode_fconstd:
16073 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16074 {
16075 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16076 do_vfp_nsyn_opcode (ldconst);
16077 }
5287ad62 16078 else
477330fc 16079 first_error (_("immediate out of range"));
037e8744 16080 break;
5f4273c7 16081
037e8744
JB
16082 case NS_RF: /* case 12 (fmrs). */
16083 do_vfp_nsyn_opcode ("fmrs");
16084 break;
5f4273c7 16085
037e8744
JB
16086 case NS_FR: /* case 13 (fmsr). */
16087 do_vfp_nsyn_opcode ("fmsr");
16088 break;
5f4273c7 16089
037e8744
JB
16090 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16091 (one of which is a list), but we have parsed four. Do some fiddling to
16092 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16093 expect. */
16094 case NS_RRFF: /* case 14 (fmrrs). */
16095 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16096 _("VFP registers must be adjacent"));
037e8744
JB
16097 inst.operands[2].imm = 2;
16098 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16099 do_vfp_nsyn_opcode ("fmrrs");
16100 break;
5f4273c7 16101
037e8744
JB
16102 case NS_FFRR: /* case 15 (fmsrr). */
16103 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16104 _("VFP registers must be adjacent"));
037e8744
JB
16105 inst.operands[1] = inst.operands[2];
16106 inst.operands[2] = inst.operands[3];
16107 inst.operands[0].imm = 2;
16108 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16109 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16110 break;
5f4273c7 16111
4c261dff
NC
16112 case NS_NULL:
16113 /* neon_select_shape has determined that the instruction
16114 shape is wrong and has already set the error message. */
16115 break;
16116
5287ad62
JB
16117 default:
16118 abort ();
16119 }
16120}
16121
16122static void
16123do_neon_rshift_round_imm (void)
16124{
037e8744 16125 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16126 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16127 int imm = inst.operands[2].imm;
16128
16129 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16130 if (imm == 0)
16131 {
16132 inst.operands[2].present = 0;
16133 do_neon_mov ();
16134 return;
16135 }
16136
16137 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16138 _("immediate out of range for shift"));
037e8744 16139 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16140 et.size - imm);
5287ad62
JB
16141}
16142
16143static void
16144do_neon_movl (void)
16145{
16146 struct neon_type_el et = neon_check_type (2, NS_QD,
16147 N_EQK | N_DBL, N_SU_32 | N_KEY);
16148 unsigned sizebits = et.size >> 3;
16149 inst.instruction |= sizebits << 19;
16150 neon_two_same (0, et.type == NT_unsigned, -1);
16151}
16152
16153static void
16154do_neon_trn (void)
16155{
037e8744 16156 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16157 struct neon_type_el et = neon_check_type (2, rs,
16158 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16159 NEON_ENCODE (INTEGER, inst);
037e8744 16160 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16161}
16162
16163static void
16164do_neon_zip_uzp (void)
16165{
037e8744 16166 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16167 struct neon_type_el et = neon_check_type (2, rs,
16168 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16169 if (rs == NS_DD && et.size == 32)
16170 {
16171 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16172 inst.instruction = N_MNEM_vtrn;
16173 do_neon_trn ();
16174 return;
16175 }
037e8744 16176 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16177}
16178
16179static void
16180do_neon_sat_abs_neg (void)
16181{
037e8744 16182 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16183 struct neon_type_el et = neon_check_type (2, rs,
16184 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16185 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16186}
16187
16188static void
16189do_neon_pair_long (void)
16190{
037e8744 16191 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16192 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16193 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16194 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16195 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16196}
16197
16198static void
16199do_neon_recip_est (void)
16200{
037e8744 16201 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16202 struct neon_type_el et = neon_check_type (2, rs,
16203 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
16204 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16205 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16206}
16207
16208static void
16209do_neon_cls (void)
16210{
037e8744 16211 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16212 struct neon_type_el et = neon_check_type (2, rs,
16213 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16214 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16215}
16216
16217static void
16218do_neon_clz (void)
16219{
037e8744 16220 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16221 struct neon_type_el et = neon_check_type (2, rs,
16222 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16223 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16224}
16225
16226static void
16227do_neon_cnt (void)
16228{
037e8744 16229 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16230 struct neon_type_el et = neon_check_type (2, rs,
16231 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16232 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16233}
16234
16235static void
16236do_neon_swp (void)
16237{
037e8744
JB
16238 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16239 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16240}
16241
16242static void
16243do_neon_tbl_tbx (void)
16244{
16245 unsigned listlenbits;
dcbf9037 16246 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16247
5287ad62
JB
16248 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16249 {
dcbf9037 16250 first_error (_("bad list length for table lookup"));
5287ad62
JB
16251 return;
16252 }
5f4273c7 16253
5287ad62
JB
16254 listlenbits = inst.operands[1].imm - 1;
16255 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16256 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16257 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16258 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16259 inst.instruction |= LOW4 (inst.operands[2].reg);
16260 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16261 inst.instruction |= listlenbits << 8;
5f4273c7 16262
88714cb8 16263 neon_dp_fixup (&inst);
5287ad62
JB
16264}
16265
16266static void
16267do_neon_ldm_stm (void)
16268{
16269 /* P, U and L bits are part of bitmask. */
16270 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16271 unsigned offsetbits = inst.operands[1].imm * 2;
16272
037e8744
JB
16273 if (inst.operands[1].issingle)
16274 {
16275 do_vfp_nsyn_ldm_stm (is_dbmode);
16276 return;
16277 }
16278
5287ad62 16279 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16280 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16281
16282 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16283 _("register list must contain at least 1 and at most 16 "
16284 "registers"));
5287ad62
JB
16285
16286 inst.instruction |= inst.operands[0].reg << 16;
16287 inst.instruction |= inst.operands[0].writeback << 21;
16288 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16289 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16290
16291 inst.instruction |= offsetbits;
5f4273c7 16292
037e8744 16293 do_vfp_cond_or_thumb ();
5287ad62
JB
16294}
16295
16296static void
16297do_neon_ldr_str (void)
16298{
5287ad62 16299 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16300
6844b2c2
MGD
16301 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16302 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16303 if (!is_ldr
6844b2c2 16304 && inst.operands[1].reg == REG_PC
ba86b375 16305 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16306 {
94dcf8bf 16307 if (thumb_mode)
6844b2c2 16308 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16309 else if (warn_on_deprecated)
5c3696f8 16310 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16311 }
16312
037e8744
JB
16313 if (inst.operands[0].issingle)
16314 {
cd2f129f 16315 if (is_ldr)
477330fc 16316 do_vfp_nsyn_opcode ("flds");
cd2f129f 16317 else
477330fc 16318 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
16319 }
16320 else
5287ad62 16321 {
cd2f129f 16322 if (is_ldr)
477330fc 16323 do_vfp_nsyn_opcode ("fldd");
5287ad62 16324 else
477330fc 16325 do_vfp_nsyn_opcode ("fstd");
5287ad62 16326 }
5287ad62
JB
16327}
16328
16329/* "interleave" version also handles non-interleaving register VLD1/VST1
16330 instructions. */
16331
16332static void
16333do_neon_ld_st_interleave (void)
16334{
037e8744 16335 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16336 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16337 unsigned alignbits = 0;
16338 unsigned idx;
16339 /* The bits in this table go:
16340 0: register stride of one (0) or two (1)
16341 1,2: register list length, minus one (1, 2, 3, 4).
16342 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16343 We use -1 for invalid entries. */
16344 const int typetable[] =
16345 {
16346 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16347 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16348 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16349 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16350 };
16351 int typebits;
16352
dcbf9037
JB
16353 if (et.type == NT_invtype)
16354 return;
16355
5287ad62
JB
16356 if (inst.operands[1].immisalign)
16357 switch (inst.operands[1].imm >> 8)
16358 {
16359 case 64: alignbits = 1; break;
16360 case 128:
477330fc 16361 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16362 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16363 goto bad_alignment;
16364 alignbits = 2;
16365 break;
5287ad62 16366 case 256:
477330fc
RM
16367 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16368 goto bad_alignment;
16369 alignbits = 3;
16370 break;
5287ad62
JB
16371 default:
16372 bad_alignment:
477330fc
RM
16373 first_error (_("bad alignment"));
16374 return;
5287ad62
JB
16375 }
16376
16377 inst.instruction |= alignbits << 4;
16378 inst.instruction |= neon_logbits (et.size) << 6;
16379
16380 /* Bits [4:6] of the immediate in a list specifier encode register stride
16381 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16382 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16383 up the right value for "type" in a table based on this value and the given
16384 list style, then stick it back. */
16385 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16386 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16387
16388 typebits = typetable[idx];
5f4273c7 16389
5287ad62 16390 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16391 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16392 _("bad element type for instruction"));
5287ad62
JB
16393
16394 inst.instruction &= ~0xf00;
16395 inst.instruction |= typebits << 8;
16396}
16397
16398/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16399 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16400 otherwise. The variable arguments are a list of pairs of legal (size, align)
16401 values, terminated with -1. */
16402
16403static int
16404neon_alignment_bit (int size, int align, int *do_align, ...)
16405{
16406 va_list ap;
16407 int result = FAIL, thissize, thisalign;
5f4273c7 16408
5287ad62
JB
16409 if (!inst.operands[1].immisalign)
16410 {
16411 *do_align = 0;
16412 return SUCCESS;
16413 }
5f4273c7 16414
5287ad62
JB
16415 va_start (ap, do_align);
16416
16417 do
16418 {
16419 thissize = va_arg (ap, int);
16420 if (thissize == -1)
477330fc 16421 break;
5287ad62
JB
16422 thisalign = va_arg (ap, int);
16423
16424 if (size == thissize && align == thisalign)
477330fc 16425 result = SUCCESS;
5287ad62
JB
16426 }
16427 while (result != SUCCESS);
16428
16429 va_end (ap);
16430
16431 if (result == SUCCESS)
16432 *do_align = 1;
16433 else
dcbf9037 16434 first_error (_("unsupported alignment for instruction"));
5f4273c7 16435
5287ad62
JB
16436 return result;
16437}
16438
16439static void
16440do_neon_ld_st_lane (void)
16441{
037e8744 16442 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
16443 int align_good, do_align = 0;
16444 int logsize = neon_logbits (et.size);
16445 int align = inst.operands[1].imm >> 8;
16446 int n = (inst.instruction >> 8) & 3;
16447 int max_el = 64 / et.size;
5f4273c7 16448
dcbf9037
JB
16449 if (et.type == NT_invtype)
16450 return;
5f4273c7 16451
5287ad62 16452 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16453 _("bad list length"));
5287ad62 16454 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16455 _("scalar index out of range"));
5287ad62 16456 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16457 && et.size == 8,
16458 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16459
5287ad62
JB
16460 switch (n)
16461 {
16462 case 0: /* VLD1 / VST1. */
16463 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
477330fc 16464 32, 32, -1);
5287ad62 16465 if (align_good == FAIL)
477330fc 16466 return;
5287ad62 16467 if (do_align)
477330fc
RM
16468 {
16469 unsigned alignbits = 0;
16470 switch (et.size)
16471 {
16472 case 16: alignbits = 0x1; break;
16473 case 32: alignbits = 0x3; break;
16474 default: ;
16475 }
16476 inst.instruction |= alignbits << 4;
16477 }
5287ad62
JB
16478 break;
16479
16480 case 1: /* VLD2 / VST2. */
16481 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
477330fc 16482 32, 64, -1);
5287ad62 16483 if (align_good == FAIL)
477330fc 16484 return;
5287ad62 16485 if (do_align)
477330fc 16486 inst.instruction |= 1 << 4;
5287ad62
JB
16487 break;
16488
16489 case 2: /* VLD3 / VST3. */
16490 constraint (inst.operands[1].immisalign,
477330fc 16491 _("can't use alignment with this instruction"));
5287ad62
JB
16492 break;
16493
16494 case 3: /* VLD4 / VST4. */
16495 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
477330fc 16496 16, 64, 32, 64, 32, 128, -1);
5287ad62 16497 if (align_good == FAIL)
477330fc 16498 return;
5287ad62 16499 if (do_align)
477330fc
RM
16500 {
16501 unsigned alignbits = 0;
16502 switch (et.size)
16503 {
16504 case 8: alignbits = 0x1; break;
16505 case 16: alignbits = 0x1; break;
16506 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16507 default: ;
16508 }
16509 inst.instruction |= alignbits << 4;
16510 }
5287ad62
JB
16511 break;
16512
16513 default: ;
16514 }
16515
16516 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16517 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16518 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16519
5287ad62
JB
16520 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16521 inst.instruction |= logsize << 10;
16522}
16523
16524/* Encode single n-element structure to all lanes VLD<n> instructions. */
16525
16526static void
16527do_neon_ld_dup (void)
16528{
037e8744 16529 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
16530 int align_good, do_align = 0;
16531
dcbf9037
JB
16532 if (et.type == NT_invtype)
16533 return;
16534
5287ad62
JB
16535 switch ((inst.instruction >> 8) & 3)
16536 {
16537 case 0: /* VLD1. */
9c2799c2 16538 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16539 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
477330fc 16540 &do_align, 16, 16, 32, 32, -1);
5287ad62 16541 if (align_good == FAIL)
477330fc 16542 return;
5287ad62 16543 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
16544 {
16545 case 1: break;
16546 case 2: inst.instruction |= 1 << 5; break;
16547 default: first_error (_("bad list length")); return;
16548 }
5287ad62
JB
16549 inst.instruction |= neon_logbits (et.size) << 6;
16550 break;
16551
16552 case 1: /* VLD2. */
16553 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
477330fc 16554 &do_align, 8, 16, 16, 32, 32, 64, -1);
5287ad62 16555 if (align_good == FAIL)
477330fc 16556 return;
5287ad62 16557 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 16558 _("bad list length"));
5287ad62 16559 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16560 inst.instruction |= 1 << 5;
5287ad62
JB
16561 inst.instruction |= neon_logbits (et.size) << 6;
16562 break;
16563
16564 case 2: /* VLD3. */
16565 constraint (inst.operands[1].immisalign,
477330fc 16566 _("can't use alignment with this instruction"));
5287ad62 16567 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 16568 _("bad list length"));
5287ad62 16569 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16570 inst.instruction |= 1 << 5;
5287ad62
JB
16571 inst.instruction |= neon_logbits (et.size) << 6;
16572 break;
16573
16574 case 3: /* VLD4. */
16575 {
477330fc
RM
16576 int align = inst.operands[1].imm >> 8;
16577 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
16578 16, 64, 32, 64, 32, 128, -1);
16579 if (align_good == FAIL)
16580 return;
16581 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
16582 _("bad list length"));
16583 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16584 inst.instruction |= 1 << 5;
16585 if (et.size == 32 && align == 128)
16586 inst.instruction |= 0x3 << 6;
16587 else
16588 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
16589 }
16590 break;
16591
16592 default: ;
16593 }
16594
16595 inst.instruction |= do_align << 4;
16596}
16597
16598/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
16599 apart from bits [11:4]. */
16600
16601static void
16602do_neon_ldx_stx (void)
16603{
b1a769ed
DG
16604 if (inst.operands[1].isreg)
16605 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16606
5287ad62
JB
16607 switch (NEON_LANE (inst.operands[0].imm))
16608 {
16609 case NEON_INTERLEAVE_LANES:
88714cb8 16610 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
16611 do_neon_ld_st_interleave ();
16612 break;
5f4273c7 16613
5287ad62 16614 case NEON_ALL_LANES:
88714cb8 16615 NEON_ENCODE (DUP, inst);
2d51fb74
JB
16616 if (inst.instruction == N_INV)
16617 {
16618 first_error ("only loads support such operands");
16619 break;
16620 }
5287ad62
JB
16621 do_neon_ld_dup ();
16622 break;
5f4273c7 16623
5287ad62 16624 default:
88714cb8 16625 NEON_ENCODE (LANE, inst);
5287ad62
JB
16626 do_neon_ld_st_lane ();
16627 }
16628
16629 /* L bit comes from bit mask. */
16630 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16631 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16632 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 16633
5287ad62
JB
16634 if (inst.operands[1].postind)
16635 {
16636 int postreg = inst.operands[1].imm & 0xf;
16637 constraint (!inst.operands[1].immisreg,
477330fc 16638 _("post-index must be a register"));
5287ad62 16639 constraint (postreg == 0xd || postreg == 0xf,
477330fc 16640 _("bad register for post-index"));
5287ad62
JB
16641 inst.instruction |= postreg;
16642 }
4f2374c7 16643 else
5287ad62 16644 {
4f2374c7
WN
16645 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
16646 constraint (inst.reloc.exp.X_op != O_constant
16647 || inst.reloc.exp.X_add_number != 0,
16648 BAD_ADDR_MODE);
16649
16650 if (inst.operands[1].writeback)
16651 {
16652 inst.instruction |= 0xd;
16653 }
16654 else
16655 inst.instruction |= 0xf;
5287ad62 16656 }
5f4273c7 16657
5287ad62
JB
16658 if (thumb_mode)
16659 inst.instruction |= 0xf9000000;
16660 else
16661 inst.instruction |= 0xf4000000;
16662}
33399f07
MGD
16663
16664/* FP v8. */
16665static void
16666do_vfp_nsyn_fpv8 (enum neon_shape rs)
16667{
a715796b
TG
16668 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16669 D register operands. */
16670 if (neon_shape_class[rs] == SC_DOUBLE)
16671 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16672 _(BAD_FPU));
16673
33399f07
MGD
16674 NEON_ENCODE (FPV8, inst);
16675
16676 if (rs == NS_FFF)
16677 do_vfp_sp_dyadic ();
16678 else
16679 do_vfp_dp_rd_rn_rm ();
16680
16681 if (rs == NS_DDD)
16682 inst.instruction |= 0x100;
16683
16684 inst.instruction |= 0xf0000000;
16685}
16686
16687static void
16688do_vsel (void)
16689{
16690 set_it_insn_type (OUTSIDE_IT_INSN);
16691
16692 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
16693 first_error (_("invalid instruction shape"));
16694}
16695
73924fbc
MGD
16696static void
16697do_vmaxnm (void)
16698{
16699 set_it_insn_type (OUTSIDE_IT_INSN);
16700
16701 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
16702 return;
16703
16704 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16705 return;
16706
16707 neon_dyadic_misc (NT_untyped, N_F32, 0);
16708}
16709
30bdf752
MGD
16710static void
16711do_vrint_1 (enum neon_cvt_mode mode)
16712{
16713 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_QQ, NS_NULL);
16714 struct neon_type_el et;
16715
16716 if (rs == NS_NULL)
16717 return;
16718
a715796b
TG
16719 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16720 D register operands. */
16721 if (neon_shape_class[rs] == SC_DOUBLE)
16722 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16723 _(BAD_FPU));
16724
30bdf752
MGD
16725 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
16726 if (et.type != NT_invtype)
16727 {
16728 /* VFP encodings. */
16729 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
16730 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
16731 set_it_insn_type (OUTSIDE_IT_INSN);
16732
16733 NEON_ENCODE (FPV8, inst);
16734 if (rs == NS_FF)
16735 do_vfp_sp_monadic ();
16736 else
16737 do_vfp_dp_rd_rm ();
16738
16739 switch (mode)
16740 {
16741 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
16742 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
16743 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
16744 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
16745 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
16746 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
16747 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
16748 default: abort ();
16749 }
16750
16751 inst.instruction |= (rs == NS_DD) << 8;
16752 do_vfp_cond_or_thumb ();
16753 }
16754 else
16755 {
16756 /* Neon encodings (or something broken...). */
16757 inst.error = NULL;
16758 et = neon_check_type (2, rs, N_EQK, N_F32 | N_KEY);
16759
16760 if (et.type == NT_invtype)
16761 return;
16762
16763 set_it_insn_type (OUTSIDE_IT_INSN);
16764 NEON_ENCODE (FLOAT, inst);
16765
16766 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16767 return;
16768
16769 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16770 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16771 inst.instruction |= LOW4 (inst.operands[1].reg);
16772 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16773 inst.instruction |= neon_quad (rs) << 6;
16774 switch (mode)
16775 {
16776 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
16777 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
16778 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
16779 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
16780 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
16781 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
16782 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
16783 default: abort ();
16784 }
16785
16786 if (thumb_mode)
16787 inst.instruction |= 0xfc000000;
16788 else
16789 inst.instruction |= 0xf0000000;
16790 }
16791}
16792
16793static void
16794do_vrintx (void)
16795{
16796 do_vrint_1 (neon_cvt_mode_x);
16797}
16798
16799static void
16800do_vrintz (void)
16801{
16802 do_vrint_1 (neon_cvt_mode_z);
16803}
16804
16805static void
16806do_vrintr (void)
16807{
16808 do_vrint_1 (neon_cvt_mode_r);
16809}
16810
16811static void
16812do_vrinta (void)
16813{
16814 do_vrint_1 (neon_cvt_mode_a);
16815}
16816
16817static void
16818do_vrintn (void)
16819{
16820 do_vrint_1 (neon_cvt_mode_n);
16821}
16822
16823static void
16824do_vrintp (void)
16825{
16826 do_vrint_1 (neon_cvt_mode_p);
16827}
16828
16829static void
16830do_vrintm (void)
16831{
16832 do_vrint_1 (neon_cvt_mode_m);
16833}
16834
91ff7894
MGD
16835/* Crypto v1 instructions. */
16836static void
16837do_crypto_2op_1 (unsigned elttype, int op)
16838{
16839 set_it_insn_type (OUTSIDE_IT_INSN);
16840
16841 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
16842 == NT_invtype)
16843 return;
16844
16845 inst.error = NULL;
16846
16847 NEON_ENCODE (INTEGER, inst);
16848 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16849 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16850 inst.instruction |= LOW4 (inst.operands[1].reg);
16851 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16852 if (op != -1)
16853 inst.instruction |= op << 6;
16854
16855 if (thumb_mode)
16856 inst.instruction |= 0xfc000000;
16857 else
16858 inst.instruction |= 0xf0000000;
16859}
16860
48adcd8e
MGD
16861static void
16862do_crypto_3op_1 (int u, int op)
16863{
16864 set_it_insn_type (OUTSIDE_IT_INSN);
16865
16866 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
16867 N_32 | N_UNT | N_KEY).type == NT_invtype)
16868 return;
16869
16870 inst.error = NULL;
16871
16872 NEON_ENCODE (INTEGER, inst);
16873 neon_three_same (1, u, 8 << op);
16874}
16875
91ff7894
MGD
16876static void
16877do_aese (void)
16878{
16879 do_crypto_2op_1 (N_8, 0);
16880}
16881
16882static void
16883do_aesd (void)
16884{
16885 do_crypto_2op_1 (N_8, 1);
16886}
16887
16888static void
16889do_aesmc (void)
16890{
16891 do_crypto_2op_1 (N_8, 2);
16892}
16893
16894static void
16895do_aesimc (void)
16896{
16897 do_crypto_2op_1 (N_8, 3);
16898}
16899
48adcd8e
MGD
16900static void
16901do_sha1c (void)
16902{
16903 do_crypto_3op_1 (0, 0);
16904}
16905
16906static void
16907do_sha1p (void)
16908{
16909 do_crypto_3op_1 (0, 1);
16910}
16911
16912static void
16913do_sha1m (void)
16914{
16915 do_crypto_3op_1 (0, 2);
16916}
16917
16918static void
16919do_sha1su0 (void)
16920{
16921 do_crypto_3op_1 (0, 3);
16922}
91ff7894 16923
48adcd8e
MGD
16924static void
16925do_sha256h (void)
16926{
16927 do_crypto_3op_1 (1, 0);
16928}
16929
16930static void
16931do_sha256h2 (void)
16932{
16933 do_crypto_3op_1 (1, 1);
16934}
16935
16936static void
16937do_sha256su1 (void)
16938{
16939 do_crypto_3op_1 (1, 2);
16940}
3c9017d2
MGD
16941
16942static void
16943do_sha1h (void)
16944{
16945 do_crypto_2op_1 (N_32, -1);
16946}
16947
16948static void
16949do_sha1su1 (void)
16950{
16951 do_crypto_2op_1 (N_32, 0);
16952}
16953
16954static void
16955do_sha256su0 (void)
16956{
16957 do_crypto_2op_1 (N_32, 1);
16958}
dd5181d5
KT
16959
16960static void
16961do_crc32_1 (unsigned int poly, unsigned int sz)
16962{
16963 unsigned int Rd = inst.operands[0].reg;
16964 unsigned int Rn = inst.operands[1].reg;
16965 unsigned int Rm = inst.operands[2].reg;
16966
16967 set_it_insn_type (OUTSIDE_IT_INSN);
16968 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
16969 inst.instruction |= LOW4 (Rn) << 16;
16970 inst.instruction |= LOW4 (Rm);
16971 inst.instruction |= sz << (thumb_mode ? 4 : 21);
16972 inst.instruction |= poly << (thumb_mode ? 20 : 9);
16973
16974 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
16975 as_warn (UNPRED_REG ("r15"));
16976 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
16977 as_warn (UNPRED_REG ("r13"));
16978}
16979
16980static void
16981do_crc32b (void)
16982{
16983 do_crc32_1 (0, 0);
16984}
16985
16986static void
16987do_crc32h (void)
16988{
16989 do_crc32_1 (0, 1);
16990}
16991
16992static void
16993do_crc32w (void)
16994{
16995 do_crc32_1 (0, 2);
16996}
16997
16998static void
16999do_crc32cb (void)
17000{
17001 do_crc32_1 (1, 0);
17002}
17003
17004static void
17005do_crc32ch (void)
17006{
17007 do_crc32_1 (1, 1);
17008}
17009
17010static void
17011do_crc32cw (void)
17012{
17013 do_crc32_1 (1, 2);
17014}
17015
5287ad62
JB
17016\f
17017/* Overall per-instruction processing. */
17018
17019/* We need to be able to fix up arbitrary expressions in some statements.
17020 This is so that we can handle symbols that are an arbitrary distance from
17021 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17022 which returns part of an address in a form which will be valid for
17023 a data instruction. We do this by pushing the expression into a symbol
17024 in the expr_section, and creating a fix for that. */
17025
17026static void
17027fix_new_arm (fragS * frag,
17028 int where,
17029 short int size,
17030 expressionS * exp,
17031 int pc_rel,
17032 int reloc)
17033{
17034 fixS * new_fix;
17035
17036 switch (exp->X_op)
17037 {
17038 case O_constant:
6e7ce2cd
PB
17039 if (pc_rel)
17040 {
17041 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17042 refer to in the object file. Unfortunately for us, gas's
17043 generic expression parsing will already have folded out
17044 any use of .set foo/.type foo %function that may have
17045 been used to set type information of the target location,
17046 that's being specified symbolically. We have to presume
17047 the user knows what they are doing. */
6e7ce2cd
PB
17048 char name[16 + 8];
17049 symbolS *symbol;
17050
17051 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17052
17053 symbol = symbol_find_or_make (name);
17054 S_SET_SEGMENT (symbol, absolute_section);
17055 symbol_set_frag (symbol, &zero_address_frag);
17056 S_SET_VALUE (symbol, exp->X_add_number);
17057 exp->X_op = O_symbol;
17058 exp->X_add_symbol = symbol;
17059 exp->X_add_number = 0;
17060 }
17061 /* FALLTHROUGH */
5287ad62
JB
17062 case O_symbol:
17063 case O_add:
17064 case O_subtract:
21d799b5 17065 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17066 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17067 break;
17068
17069 default:
21d799b5 17070 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17071 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17072 break;
17073 }
17074
17075 /* Mark whether the fix is to a THUMB instruction, or an ARM
17076 instruction. */
17077 new_fix->tc_fix_data = thumb_mode;
17078}
17079
17080/* Create a frg for an instruction requiring relaxation. */
17081static void
17082output_relax_insn (void)
17083{
17084 char * to;
17085 symbolS *sym;
0110f2b8
PB
17086 int offset;
17087
6e1cb1a6
PB
17088 /* The size of the instruction is unknown, so tie the debug info to the
17089 start of the instruction. */
17090 dwarf2_emit_insn (0);
6e1cb1a6 17091
0110f2b8
PB
17092 switch (inst.reloc.exp.X_op)
17093 {
17094 case O_symbol:
17095 sym = inst.reloc.exp.X_add_symbol;
17096 offset = inst.reloc.exp.X_add_number;
17097 break;
17098 case O_constant:
17099 sym = NULL;
17100 offset = inst.reloc.exp.X_add_number;
17101 break;
17102 default:
17103 sym = make_expr_symbol (&inst.reloc.exp);
17104 offset = 0;
17105 break;
17106 }
17107 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17108 inst.relax, sym, offset, NULL/*offset, opcode*/);
17109 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17110}
17111
17112/* Write a 32-bit thumb instruction to buf. */
17113static void
17114put_thumb32_insn (char * buf, unsigned long insn)
17115{
17116 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17117 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17118}
17119
b99bd4ef 17120static void
c19d1205 17121output_inst (const char * str)
b99bd4ef 17122{
c19d1205 17123 char * to = NULL;
b99bd4ef 17124
c19d1205 17125 if (inst.error)
b99bd4ef 17126 {
c19d1205 17127 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17128 return;
17129 }
5f4273c7
NC
17130 if (inst.relax)
17131 {
17132 output_relax_insn ();
0110f2b8 17133 return;
5f4273c7 17134 }
c19d1205
ZW
17135 if (inst.size == 0)
17136 return;
b99bd4ef 17137
c19d1205 17138 to = frag_more (inst.size);
8dc2430f
NC
17139 /* PR 9814: Record the thumb mode into the current frag so that we know
17140 what type of NOP padding to use, if necessary. We override any previous
17141 setting so that if the mode has changed then the NOPS that we use will
17142 match the encoding of the last instruction in the frag. */
cd000bff 17143 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17144
17145 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17146 {
9c2799c2 17147 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17148 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17149 }
c19d1205 17150 else if (inst.size > INSN_SIZE)
b99bd4ef 17151 {
9c2799c2 17152 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17153 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17154 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17155 }
c19d1205
ZW
17156 else
17157 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17158
c19d1205
ZW
17159 if (inst.reloc.type != BFD_RELOC_UNUSED)
17160 fix_new_arm (frag_now, to - frag_now->fr_literal,
17161 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17162 inst.reloc.type);
b99bd4ef 17163
c19d1205 17164 dwarf2_emit_insn (inst.size);
c19d1205 17165}
b99bd4ef 17166
e07e6e58
NC
17167static char *
17168output_it_inst (int cond, int mask, char * to)
17169{
17170 unsigned long instruction = 0xbf00;
17171
17172 mask &= 0xf;
17173 instruction |= mask;
17174 instruction |= cond << 4;
17175
17176 if (to == NULL)
17177 {
17178 to = frag_more (2);
17179#ifdef OBJ_ELF
17180 dwarf2_emit_insn (2);
17181#endif
17182 }
17183
17184 md_number_to_chars (to, instruction, 2);
17185
17186 return to;
17187}
17188
c19d1205
ZW
17189/* Tag values used in struct asm_opcode's tag field. */
17190enum opcode_tag
17191{
17192 OT_unconditional, /* Instruction cannot be conditionalized.
17193 The ARM condition field is still 0xE. */
17194 OT_unconditionalF, /* Instruction cannot be conditionalized
17195 and carries 0xF in its ARM condition field. */
17196 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17197 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17198 suffix, others place 0xF where the condition field
17199 would be. */
c19d1205
ZW
17200 OT_cinfix3, /* Instruction takes a conditional infix,
17201 beginning at character index 3. (In
17202 unified mode, it becomes a suffix.) */
088fa78e
KH
17203 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17204 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17205 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17206 character index 3, even in unified mode. Used for
17207 legacy instructions where suffix and infix forms
17208 may be ambiguous. */
c19d1205 17209 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17210 suffix or an infix at character index 3. */
c19d1205
ZW
17211 OT_odd_infix_unc, /* This is the unconditional variant of an
17212 instruction that takes a conditional infix
17213 at an unusual position. In unified mode,
17214 this variant will accept a suffix. */
17215 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17216 are the conditional variants of instructions that
17217 take conditional infixes in unusual positions.
17218 The infix appears at character index
17219 (tag - OT_odd_infix_0). These are not accepted
17220 in unified mode. */
17221};
b99bd4ef 17222
c19d1205
ZW
17223/* Subroutine of md_assemble, responsible for looking up the primary
17224 opcode from the mnemonic the user wrote. STR points to the
17225 beginning of the mnemonic.
17226
17227 This is not simply a hash table lookup, because of conditional
17228 variants. Most instructions have conditional variants, which are
17229 expressed with a _conditional affix_ to the mnemonic. If we were
17230 to encode each conditional variant as a literal string in the opcode
17231 table, it would have approximately 20,000 entries.
17232
17233 Most mnemonics take this affix as a suffix, and in unified syntax,
17234 'most' is upgraded to 'all'. However, in the divided syntax, some
17235 instructions take the affix as an infix, notably the s-variants of
17236 the arithmetic instructions. Of those instructions, all but six
17237 have the infix appear after the third character of the mnemonic.
17238
17239 Accordingly, the algorithm for looking up primary opcodes given
17240 an identifier is:
17241
17242 1. Look up the identifier in the opcode table.
17243 If we find a match, go to step U.
17244
17245 2. Look up the last two characters of the identifier in the
17246 conditions table. If we find a match, look up the first N-2
17247 characters of the identifier in the opcode table. If we
17248 find a match, go to step CE.
17249
17250 3. Look up the fourth and fifth characters of the identifier in
17251 the conditions table. If we find a match, extract those
17252 characters from the identifier, and look up the remaining
17253 characters in the opcode table. If we find a match, go
17254 to step CM.
17255
17256 4. Fail.
17257
17258 U. Examine the tag field of the opcode structure, in case this is
17259 one of the six instructions with its conditional infix in an
17260 unusual place. If it is, the tag tells us where to find the
17261 infix; look it up in the conditions table and set inst.cond
17262 accordingly. Otherwise, this is an unconditional instruction.
17263 Again set inst.cond accordingly. Return the opcode structure.
17264
17265 CE. Examine the tag field to make sure this is an instruction that
17266 should receive a conditional suffix. If it is not, fail.
17267 Otherwise, set inst.cond from the suffix we already looked up,
17268 and return the opcode structure.
17269
17270 CM. Examine the tag field to make sure this is an instruction that
17271 should receive a conditional infix after the third character.
17272 If it is not, fail. Otherwise, undo the edits to the current
17273 line of input and proceed as for case CE. */
17274
17275static const struct asm_opcode *
17276opcode_lookup (char **str)
17277{
17278 char *end, *base;
17279 char *affix;
17280 const struct asm_opcode *opcode;
17281 const struct asm_cond *cond;
e3cb604e 17282 char save[2];
c19d1205
ZW
17283
17284 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17285 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17286 for (base = end = *str; *end != '\0'; end++)
721a8186 17287 if (*end == ' ' || *end == '.')
c19d1205 17288 break;
b99bd4ef 17289
c19d1205 17290 if (end == base)
c921be7d 17291 return NULL;
b99bd4ef 17292
5287ad62 17293 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17294 if (end[0] == '.')
b99bd4ef 17295 {
5287ad62 17296 int offset = 2;
5f4273c7 17297
267d2029 17298 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17299 use. */
267d2029 17300 if (unified_syntax && end[1] == 'w')
c19d1205 17301 inst.size_req = 4;
267d2029 17302 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17303 inst.size_req = 2;
17304 else
477330fc 17305 offset = 0;
5287ad62
JB
17306
17307 inst.vectype.elems = 0;
17308
17309 *str = end + offset;
b99bd4ef 17310
5f4273c7 17311 if (end[offset] == '.')
5287ad62 17312 {
267d2029 17313 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17314 non-unified ARM syntax mode). */
17315 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17316 return NULL;
477330fc 17317 }
5287ad62 17318 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17319 return NULL;
b99bd4ef 17320 }
c19d1205
ZW
17321 else
17322 *str = end;
b99bd4ef 17323
c19d1205 17324 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17325 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17326 end - base);
c19d1205 17327 if (opcode)
b99bd4ef 17328 {
c19d1205
ZW
17329 /* step U */
17330 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17331 {
c19d1205
ZW
17332 inst.cond = COND_ALWAYS;
17333 return opcode;
b99bd4ef 17334 }
b99bd4ef 17335
278df34e 17336 if (warn_on_deprecated && unified_syntax)
5c3696f8 17337 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17338 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17339 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17340 gas_assert (cond);
b99bd4ef 17341
c19d1205
ZW
17342 inst.cond = cond->value;
17343 return opcode;
17344 }
b99bd4ef 17345
c19d1205
ZW
17346 /* Cannot have a conditional suffix on a mnemonic of less than two
17347 characters. */
17348 if (end - base < 3)
c921be7d 17349 return NULL;
b99bd4ef 17350
c19d1205
ZW
17351 /* Look for suffixed mnemonic. */
17352 affix = end - 2;
21d799b5
NC
17353 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17354 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17355 affix - base);
c19d1205
ZW
17356 if (opcode && cond)
17357 {
17358 /* step CE */
17359 switch (opcode->tag)
17360 {
e3cb604e
PB
17361 case OT_cinfix3_legacy:
17362 /* Ignore conditional suffixes matched on infix only mnemonics. */
17363 break;
17364
c19d1205 17365 case OT_cinfix3:
088fa78e 17366 case OT_cinfix3_deprecated:
c19d1205
ZW
17367 case OT_odd_infix_unc:
17368 if (!unified_syntax)
e3cb604e 17369 return 0;
c19d1205
ZW
17370 /* else fall through */
17371
17372 case OT_csuffix:
477330fc 17373 case OT_csuffixF:
c19d1205
ZW
17374 case OT_csuf_or_in3:
17375 inst.cond = cond->value;
17376 return opcode;
17377
17378 case OT_unconditional:
17379 case OT_unconditionalF:
dfa9f0d5 17380 if (thumb_mode)
c921be7d 17381 inst.cond = cond->value;
dfa9f0d5
PB
17382 else
17383 {
c921be7d 17384 /* Delayed diagnostic. */
dfa9f0d5
PB
17385 inst.error = BAD_COND;
17386 inst.cond = COND_ALWAYS;
17387 }
c19d1205 17388 return opcode;
b99bd4ef 17389
c19d1205 17390 default:
c921be7d 17391 return NULL;
c19d1205
ZW
17392 }
17393 }
b99bd4ef 17394
c19d1205
ZW
17395 /* Cannot have a usual-position infix on a mnemonic of less than
17396 six characters (five would be a suffix). */
17397 if (end - base < 6)
c921be7d 17398 return NULL;
b99bd4ef 17399
c19d1205
ZW
17400 /* Look for infixed mnemonic in the usual position. */
17401 affix = base + 3;
21d799b5 17402 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 17403 if (!cond)
c921be7d 17404 return NULL;
e3cb604e
PB
17405
17406 memcpy (save, affix, 2);
17407 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 17408 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17409 (end - base) - 2);
e3cb604e
PB
17410 memmove (affix + 2, affix, (end - affix) - 2);
17411 memcpy (affix, save, 2);
17412
088fa78e
KH
17413 if (opcode
17414 && (opcode->tag == OT_cinfix3
17415 || opcode->tag == OT_cinfix3_deprecated
17416 || opcode->tag == OT_csuf_or_in3
17417 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 17418 {
c921be7d 17419 /* Step CM. */
278df34e 17420 if (warn_on_deprecated && unified_syntax
088fa78e
KH
17421 && (opcode->tag == OT_cinfix3
17422 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 17423 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
17424
17425 inst.cond = cond->value;
17426 return opcode;
b99bd4ef
NC
17427 }
17428
c921be7d 17429 return NULL;
b99bd4ef
NC
17430}
17431
e07e6e58
NC
17432/* This function generates an initial IT instruction, leaving its block
17433 virtually open for the new instructions. Eventually,
17434 the mask will be updated by now_it_add_mask () each time
17435 a new instruction needs to be included in the IT block.
17436 Finally, the block is closed with close_automatic_it_block ().
17437 The block closure can be requested either from md_assemble (),
17438 a tencode (), or due to a label hook. */
17439
17440static void
17441new_automatic_it_block (int cond)
17442{
17443 now_it.state = AUTOMATIC_IT_BLOCK;
17444 now_it.mask = 0x18;
17445 now_it.cc = cond;
17446 now_it.block_length = 1;
cd000bff 17447 mapping_state (MAP_THUMB);
e07e6e58 17448 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
17449 now_it.warn_deprecated = FALSE;
17450 now_it.insn_cond = TRUE;
e07e6e58
NC
17451}
17452
17453/* Close an automatic IT block.
17454 See comments in new_automatic_it_block (). */
17455
17456static void
17457close_automatic_it_block (void)
17458{
17459 now_it.mask = 0x10;
17460 now_it.block_length = 0;
17461}
17462
17463/* Update the mask of the current automatically-generated IT
17464 instruction. See comments in new_automatic_it_block (). */
17465
17466static void
17467now_it_add_mask (int cond)
17468{
17469#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
17470#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 17471 | ((bitvalue) << (nbit)))
e07e6e58 17472 const int resulting_bit = (cond & 1);
c921be7d 17473
e07e6e58
NC
17474 now_it.mask &= 0xf;
17475 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17476 resulting_bit,
17477 (5 - now_it.block_length));
e07e6e58 17478 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17479 1,
17480 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
17481 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
17482
17483#undef CLEAR_BIT
17484#undef SET_BIT_VALUE
e07e6e58
NC
17485}
17486
17487/* The IT blocks handling machinery is accessed through the these functions:
17488 it_fsm_pre_encode () from md_assemble ()
17489 set_it_insn_type () optional, from the tencode functions
17490 set_it_insn_type_last () ditto
17491 in_it_block () ditto
17492 it_fsm_post_encode () from md_assemble ()
17493 force_automatic_it_block_close () from label habdling functions
17494
17495 Rationale:
17496 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
17497 initializing the IT insn type with a generic initial value depending
17498 on the inst.condition.
e07e6e58 17499 2) During the tencode function, two things may happen:
477330fc
RM
17500 a) The tencode function overrides the IT insn type by
17501 calling either set_it_insn_type (type) or set_it_insn_type_last ().
17502 b) The tencode function queries the IT block state by
17503 calling in_it_block () (i.e. to determine narrow/not narrow mode).
17504
17505 Both set_it_insn_type and in_it_block run the internal FSM state
17506 handling function (handle_it_state), because: a) setting the IT insn
17507 type may incur in an invalid state (exiting the function),
17508 and b) querying the state requires the FSM to be updated.
17509 Specifically we want to avoid creating an IT block for conditional
17510 branches, so it_fsm_pre_encode is actually a guess and we can't
17511 determine whether an IT block is required until the tencode () routine
17512 has decided what type of instruction this actually it.
17513 Because of this, if set_it_insn_type and in_it_block have to be used,
17514 set_it_insn_type has to be called first.
17515
17516 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
17517 determines the insn IT type depending on the inst.cond code.
17518 When a tencode () routine encodes an instruction that can be
17519 either outside an IT block, or, in the case of being inside, has to be
17520 the last one, set_it_insn_type_last () will determine the proper
17521 IT instruction type based on the inst.cond code. Otherwise,
17522 set_it_insn_type can be called for overriding that logic or
17523 for covering other cases.
17524
17525 Calling handle_it_state () may not transition the IT block state to
17526 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
17527 still queried. Instead, if the FSM determines that the state should
17528 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
17529 after the tencode () function: that's what it_fsm_post_encode () does.
17530
17531 Since in_it_block () calls the state handling function to get an
17532 updated state, an error may occur (due to invalid insns combination).
17533 In that case, inst.error is set.
17534 Therefore, inst.error has to be checked after the execution of
17535 the tencode () routine.
e07e6e58
NC
17536
17537 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
17538 any pending state change (if any) that didn't take place in
17539 handle_it_state () as explained above. */
e07e6e58
NC
17540
17541static void
17542it_fsm_pre_encode (void)
17543{
17544 if (inst.cond != COND_ALWAYS)
17545 inst.it_insn_type = INSIDE_IT_INSN;
17546 else
17547 inst.it_insn_type = OUTSIDE_IT_INSN;
17548
17549 now_it.state_handled = 0;
17550}
17551
17552/* IT state FSM handling function. */
17553
17554static int
17555handle_it_state (void)
17556{
17557 now_it.state_handled = 1;
5a01bb1d 17558 now_it.insn_cond = FALSE;
e07e6e58
NC
17559
17560 switch (now_it.state)
17561 {
17562 case OUTSIDE_IT_BLOCK:
17563 switch (inst.it_insn_type)
17564 {
17565 case OUTSIDE_IT_INSN:
17566 break;
17567
17568 case INSIDE_IT_INSN:
17569 case INSIDE_IT_LAST_INSN:
17570 if (thumb_mode == 0)
17571 {
c921be7d 17572 if (unified_syntax
e07e6e58
NC
17573 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
17574 as_tsktsk (_("Warning: conditional outside an IT block"\
17575 " for Thumb."));
17576 }
17577 else
17578 {
17579 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 17580 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
17581 {
17582 /* Automatically generate the IT instruction. */
17583 new_automatic_it_block (inst.cond);
17584 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
17585 close_automatic_it_block ();
17586 }
17587 else
17588 {
17589 inst.error = BAD_OUT_IT;
17590 return FAIL;
17591 }
17592 }
17593 break;
17594
17595 case IF_INSIDE_IT_LAST_INSN:
17596 case NEUTRAL_IT_INSN:
17597 break;
17598
17599 case IT_INSN:
17600 now_it.state = MANUAL_IT_BLOCK;
17601 now_it.block_length = 0;
17602 break;
17603 }
17604 break;
17605
17606 case AUTOMATIC_IT_BLOCK:
17607 /* Three things may happen now:
17608 a) We should increment current it block size;
17609 b) We should close current it block (closing insn or 4 insns);
17610 c) We should close current it block and start a new one (due
17611 to incompatible conditions or
17612 4 insns-length block reached). */
17613
17614 switch (inst.it_insn_type)
17615 {
17616 case OUTSIDE_IT_INSN:
17617 /* The closure of the block shall happen immediatelly,
17618 so any in_it_block () call reports the block as closed. */
17619 force_automatic_it_block_close ();
17620 break;
17621
17622 case INSIDE_IT_INSN:
17623 case INSIDE_IT_LAST_INSN:
17624 case IF_INSIDE_IT_LAST_INSN:
17625 now_it.block_length++;
17626
17627 if (now_it.block_length > 4
17628 || !now_it_compatible (inst.cond))
17629 {
17630 force_automatic_it_block_close ();
17631 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
17632 new_automatic_it_block (inst.cond);
17633 }
17634 else
17635 {
5a01bb1d 17636 now_it.insn_cond = TRUE;
e07e6e58
NC
17637 now_it_add_mask (inst.cond);
17638 }
17639
17640 if (now_it.state == AUTOMATIC_IT_BLOCK
17641 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
17642 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
17643 close_automatic_it_block ();
17644 break;
17645
17646 case NEUTRAL_IT_INSN:
17647 now_it.block_length++;
5a01bb1d 17648 now_it.insn_cond = TRUE;
e07e6e58
NC
17649
17650 if (now_it.block_length > 4)
17651 force_automatic_it_block_close ();
17652 else
17653 now_it_add_mask (now_it.cc & 1);
17654 break;
17655
17656 case IT_INSN:
17657 close_automatic_it_block ();
17658 now_it.state = MANUAL_IT_BLOCK;
17659 break;
17660 }
17661 break;
17662
17663 case MANUAL_IT_BLOCK:
17664 {
17665 /* Check conditional suffixes. */
17666 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
17667 int is_last;
17668 now_it.mask <<= 1;
17669 now_it.mask &= 0x1f;
17670 is_last = (now_it.mask == 0x10);
5a01bb1d 17671 now_it.insn_cond = TRUE;
e07e6e58
NC
17672
17673 switch (inst.it_insn_type)
17674 {
17675 case OUTSIDE_IT_INSN:
17676 inst.error = BAD_NOT_IT;
17677 return FAIL;
17678
17679 case INSIDE_IT_INSN:
17680 if (cond != inst.cond)
17681 {
17682 inst.error = BAD_IT_COND;
17683 return FAIL;
17684 }
17685 break;
17686
17687 case INSIDE_IT_LAST_INSN:
17688 case IF_INSIDE_IT_LAST_INSN:
17689 if (cond != inst.cond)
17690 {
17691 inst.error = BAD_IT_COND;
17692 return FAIL;
17693 }
17694 if (!is_last)
17695 {
17696 inst.error = BAD_BRANCH;
17697 return FAIL;
17698 }
17699 break;
17700
17701 case NEUTRAL_IT_INSN:
17702 /* The BKPT instruction is unconditional even in an IT block. */
17703 break;
17704
17705 case IT_INSN:
17706 inst.error = BAD_IT_IT;
17707 return FAIL;
17708 }
17709 }
17710 break;
17711 }
17712
17713 return SUCCESS;
17714}
17715
5a01bb1d
MGD
17716struct depr_insn_mask
17717{
17718 unsigned long pattern;
17719 unsigned long mask;
17720 const char* description;
17721};
17722
17723/* List of 16-bit instruction patterns deprecated in an IT block in
17724 ARMv8. */
17725static const struct depr_insn_mask depr_it_insns[] = {
17726 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
17727 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
17728 { 0xa000, 0xb800, N_("ADR") },
17729 { 0x4800, 0xf800, N_("Literal loads") },
17730 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
17731 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
17732 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
17733 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
17734 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
17735 { 0, 0, NULL }
17736};
17737
e07e6e58
NC
17738static void
17739it_fsm_post_encode (void)
17740{
17741 int is_last;
17742
17743 if (!now_it.state_handled)
17744 handle_it_state ();
17745
5a01bb1d
MGD
17746 if (now_it.insn_cond
17747 && !now_it.warn_deprecated
17748 && warn_on_deprecated
17749 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
17750 {
17751 if (inst.instruction >= 0x10000)
17752 {
5c3696f8 17753 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
17754 "deprecated in ARMv8"));
17755 now_it.warn_deprecated = TRUE;
17756 }
17757 else
17758 {
17759 const struct depr_insn_mask *p = depr_it_insns;
17760
17761 while (p->mask != 0)
17762 {
17763 if ((inst.instruction & p->mask) == p->pattern)
17764 {
5c3696f8 17765 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
17766 "of the following class are deprecated in ARMv8: "
17767 "%s"), p->description);
17768 now_it.warn_deprecated = TRUE;
17769 break;
17770 }
17771
17772 ++p;
17773 }
17774 }
17775
17776 if (now_it.block_length > 1)
17777 {
5c3696f8 17778 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 17779 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
17780 now_it.warn_deprecated = TRUE;
17781 }
17782 }
17783
e07e6e58
NC
17784 is_last = (now_it.mask == 0x10);
17785 if (is_last)
17786 {
17787 now_it.state = OUTSIDE_IT_BLOCK;
17788 now_it.mask = 0;
17789 }
17790}
17791
17792static void
17793force_automatic_it_block_close (void)
17794{
17795 if (now_it.state == AUTOMATIC_IT_BLOCK)
17796 {
17797 close_automatic_it_block ();
17798 now_it.state = OUTSIDE_IT_BLOCK;
17799 now_it.mask = 0;
17800 }
17801}
17802
17803static int
17804in_it_block (void)
17805{
17806 if (!now_it.state_handled)
17807 handle_it_state ();
17808
17809 return now_it.state != OUTSIDE_IT_BLOCK;
17810}
17811
fc289b0a
TP
17812/* Whether OPCODE only has T32 encoding and makes build attribute
17813 Tag_THUMB_ISA_use be set to 1 if assembled without any cpu or arch info. */
17814
17815static bfd_boolean
17816t1_isa_t32_only_insn (const struct asm_opcode *opcode)
17817{
17818 /* Original Thumb-1 wide instruction. */
17819 if (opcode->tencode == do_t_blx
17820 || opcode->tencode == do_t_branch23
17821 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
17822 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
17823 return TRUE;
17824
17825 return FALSE;
17826}
17827
c19d1205
ZW
17828void
17829md_assemble (char *str)
b99bd4ef 17830{
c19d1205
ZW
17831 char *p = str;
17832 const struct asm_opcode * opcode;
b99bd4ef 17833
c19d1205
ZW
17834 /* Align the previous label if needed. */
17835 if (last_label_seen != NULL)
b99bd4ef 17836 {
c19d1205
ZW
17837 symbol_set_frag (last_label_seen, frag_now);
17838 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
17839 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
17840 }
17841
c19d1205
ZW
17842 memset (&inst, '\0', sizeof (inst));
17843 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 17844
c19d1205
ZW
17845 opcode = opcode_lookup (&p);
17846 if (!opcode)
b99bd4ef 17847 {
c19d1205 17848 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 17849 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 17850 if (! create_register_alias (str, p)
477330fc 17851 && ! create_neon_reg_alias (str, p))
c19d1205 17852 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 17853
b99bd4ef
NC
17854 return;
17855 }
17856
278df34e 17857 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 17858 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 17859
037e8744
JB
17860 /* The value which unconditional instructions should have in place of the
17861 condition field. */
17862 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
17863
c19d1205 17864 if (thumb_mode)
b99bd4ef 17865 {
e74cfd16 17866 arm_feature_set variant;
8f06b2d8
PB
17867
17868 variant = cpu_variant;
17869 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
17870 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
17871 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 17872 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
17873 if (!opcode->tvariant
17874 || (thumb_mode == 1
17875 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 17876 {
84b52b66 17877 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
17878 return;
17879 }
c19d1205
ZW
17880 if (inst.cond != COND_ALWAYS && !unified_syntax
17881 && opcode->tencode != do_t_branch)
b99bd4ef 17882 {
c19d1205 17883 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
17884 return;
17885 }
17886
fc289b0a
TP
17887 /* Two things are addressed here:
17888 1) Implicit require narrow instructions on Thumb-1.
17889 This avoids relaxation accidentally introducing Thumb-2
17890 instructions.
17891 2) Reject wide instructions in non Thumb-2 cores.
17892
17893 Only instructions with narrow and wide variants need to be handled
17894 but selecting all non wide-only instructions is easier. */
17895 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
17896 && !t1_isa_t32_only_insn (opcode))
076d447c 17897 {
fc289b0a
TP
17898 if (inst.size_req == 0)
17899 inst.size_req = 2;
17900 else if (inst.size_req == 4)
752d5da4 17901 {
fc289b0a
TP
17902 as_bad (_("selected processor does not support `%s' in Thumb-2 "
17903 "mode"), str);
17904 return;
752d5da4 17905 }
076d447c
PB
17906 }
17907
c19d1205
ZW
17908 inst.instruction = opcode->tvalue;
17909
5be8be5d 17910 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
17911 {
17912 /* Prepare the it_insn_type for those encodings that don't set
17913 it. */
17914 it_fsm_pre_encode ();
c19d1205 17915
477330fc 17916 opcode->tencode ();
e07e6e58 17917
477330fc
RM
17918 it_fsm_post_encode ();
17919 }
e27ec89e 17920
0110f2b8 17921 if (!(inst.error || inst.relax))
b99bd4ef 17922 {
9c2799c2 17923 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
17924 inst.size = (inst.instruction > 0xffff ? 4 : 2);
17925 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 17926 {
c19d1205 17927 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
17928 return;
17929 }
17930 }
076d447c
PB
17931
17932 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 17933 instruction. */
9c2799c2 17934 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 17935
e74cfd16
PB
17936 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17937 *opcode->tvariant);
ee065d83 17938 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
17939 set those bits when Thumb-2 32-bit instructions are seen. The impact
17940 of relaxable instructions will be considered later after we finish all
17941 relaxation. */
17942 if (inst.size == 4 && !t1_isa_t32_only_insn (opcode))
e74cfd16
PB
17943 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17944 arm_ext_v6t2);
cd000bff 17945
88714cb8
DG
17946 check_neon_suffixes;
17947
cd000bff 17948 if (!inst.error)
c877a2f2
NC
17949 {
17950 mapping_state (MAP_THUMB);
17951 }
c19d1205 17952 }
3e9e4fcf 17953 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 17954 {
845b51d6
PB
17955 bfd_boolean is_bx;
17956
17957 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
17958 is_bx = (opcode->aencode == do_bx);
17959
c19d1205 17960 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
17961 if (!(is_bx && fix_v4bx)
17962 && !(opcode->avariant &&
17963 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 17964 {
84b52b66 17965 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 17966 return;
b99bd4ef 17967 }
c19d1205 17968 if (inst.size_req)
b99bd4ef 17969 {
c19d1205
ZW
17970 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
17971 return;
b99bd4ef
NC
17972 }
17973
c19d1205
ZW
17974 inst.instruction = opcode->avalue;
17975 if (opcode->tag == OT_unconditionalF)
eff0bc54 17976 inst.instruction |= 0xFU << 28;
c19d1205
ZW
17977 else
17978 inst.instruction |= inst.cond << 28;
17979 inst.size = INSN_SIZE;
5be8be5d 17980 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
17981 {
17982 it_fsm_pre_encode ();
17983 opcode->aencode ();
17984 it_fsm_post_encode ();
17985 }
ee065d83 17986 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 17987 on a hypothetical non-thumb v5 core. */
845b51d6 17988 if (is_bx)
e74cfd16 17989 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 17990 else
e74cfd16
PB
17991 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
17992 *opcode->avariant);
88714cb8
DG
17993
17994 check_neon_suffixes;
17995
cd000bff 17996 if (!inst.error)
c877a2f2
NC
17997 {
17998 mapping_state (MAP_ARM);
17999 }
b99bd4ef 18000 }
3e9e4fcf
JB
18001 else
18002 {
18003 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18004 "-- `%s'"), str);
18005 return;
18006 }
c19d1205
ZW
18007 output_inst (str);
18008}
b99bd4ef 18009
e07e6e58
NC
18010static void
18011check_it_blocks_finished (void)
18012{
18013#ifdef OBJ_ELF
18014 asection *sect;
18015
18016 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18017 if (seg_info (sect)->tc_segment_info_data.current_it.state
18018 == MANUAL_IT_BLOCK)
18019 {
18020 as_warn (_("section '%s' finished with an open IT block."),
18021 sect->name);
18022 }
18023#else
18024 if (now_it.state == MANUAL_IT_BLOCK)
18025 as_warn (_("file finished with an open IT block."));
18026#endif
18027}
18028
c19d1205
ZW
18029/* Various frobbings of labels and their addresses. */
18030
18031void
18032arm_start_line_hook (void)
18033{
18034 last_label_seen = NULL;
b99bd4ef
NC
18035}
18036
c19d1205
ZW
18037void
18038arm_frob_label (symbolS * sym)
b99bd4ef 18039{
c19d1205 18040 last_label_seen = sym;
b99bd4ef 18041
c19d1205 18042 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18043
c19d1205
ZW
18044#if defined OBJ_COFF || defined OBJ_ELF
18045 ARM_SET_INTERWORK (sym, support_interwork);
18046#endif
b99bd4ef 18047
e07e6e58
NC
18048 force_automatic_it_block_close ();
18049
5f4273c7 18050 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18051 as Thumb functions. This is because these labels, whilst
18052 they exist inside Thumb code, are not the entry points for
18053 possible ARM->Thumb calls. Also, these labels can be used
18054 as part of a computed goto or switch statement. eg gcc
18055 can generate code that looks like this:
b99bd4ef 18056
c19d1205
ZW
18057 ldr r2, [pc, .Laaa]
18058 lsl r3, r3, #2
18059 ldr r2, [r3, r2]
18060 mov pc, r2
b99bd4ef 18061
c19d1205
ZW
18062 .Lbbb: .word .Lxxx
18063 .Lccc: .word .Lyyy
18064 ..etc...
18065 .Laaa: .word Lbbb
b99bd4ef 18066
c19d1205
ZW
18067 The first instruction loads the address of the jump table.
18068 The second instruction converts a table index into a byte offset.
18069 The third instruction gets the jump address out of the table.
18070 The fourth instruction performs the jump.
b99bd4ef 18071
c19d1205
ZW
18072 If the address stored at .Laaa is that of a symbol which has the
18073 Thumb_Func bit set, then the linker will arrange for this address
18074 to have the bottom bit set, which in turn would mean that the
18075 address computation performed by the third instruction would end
18076 up with the bottom bit set. Since the ARM is capable of unaligned
18077 word loads, the instruction would then load the incorrect address
18078 out of the jump table, and chaos would ensue. */
18079 if (label_is_thumb_function_name
18080 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18081 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18082 {
c19d1205
ZW
18083 /* When the address of a Thumb function is taken the bottom
18084 bit of that address should be set. This will allow
18085 interworking between Arm and Thumb functions to work
18086 correctly. */
b99bd4ef 18087
c19d1205 18088 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18089
c19d1205 18090 label_is_thumb_function_name = FALSE;
b99bd4ef 18091 }
07a53e5c 18092
07a53e5c 18093 dwarf2_emit_label (sym);
b99bd4ef
NC
18094}
18095
c921be7d 18096bfd_boolean
c19d1205 18097arm_data_in_code (void)
b99bd4ef 18098{
c19d1205 18099 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18100 {
c19d1205
ZW
18101 *input_line_pointer = '/';
18102 input_line_pointer += 5;
18103 *input_line_pointer = 0;
c921be7d 18104 return TRUE;
b99bd4ef
NC
18105 }
18106
c921be7d 18107 return FALSE;
b99bd4ef
NC
18108}
18109
c19d1205
ZW
18110char *
18111arm_canonicalize_symbol_name (char * name)
b99bd4ef 18112{
c19d1205 18113 int len;
b99bd4ef 18114
c19d1205
ZW
18115 if (thumb_mode && (len = strlen (name)) > 5
18116 && streq (name + len - 5, "/data"))
18117 *(name + len - 5) = 0;
b99bd4ef 18118
c19d1205 18119 return name;
b99bd4ef 18120}
c19d1205
ZW
18121\f
18122/* Table of all register names defined by default. The user can
18123 define additional names with .req. Note that all register names
18124 should appear in both upper and lowercase variants. Some registers
18125 also have mixed-case names. */
b99bd4ef 18126
dcbf9037 18127#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18128#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18129#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18130#define REGSET(p,t) \
18131 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18132 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18133 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18134 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18135#define REGSETH(p,t) \
18136 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18137 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18138 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18139 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18140#define REGSET2(p,t) \
18141 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18142 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18143 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18144 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18145#define SPLRBANK(base,bank,t) \
18146 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18147 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18148 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18149 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18150 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18151 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18152
c19d1205 18153static const struct reg_entry reg_names[] =
7ed4c4c5 18154{
c19d1205
ZW
18155 /* ARM integer registers. */
18156 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18157
c19d1205
ZW
18158 /* ATPCS synonyms. */
18159 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18160 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18161 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18162
c19d1205
ZW
18163 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18164 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18165 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18166
c19d1205
ZW
18167 /* Well-known aliases. */
18168 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18169 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18170
18171 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18172 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18173
18174 /* Coprocessor numbers. */
18175 REGSET(p, CP), REGSET(P, CP),
18176
18177 /* Coprocessor register numbers. The "cr" variants are for backward
18178 compatibility. */
18179 REGSET(c, CN), REGSET(C, CN),
18180 REGSET(cr, CN), REGSET(CR, CN),
18181
90ec0d68
MGD
18182 /* ARM banked registers. */
18183 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18184 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18185 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18186 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18187 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18188 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18189 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18190
18191 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18192 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18193 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18194 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18195 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18196 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18197 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18198 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18199
18200 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18201 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18202 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18203 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18204 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18205 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18206 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18207 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18208 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18209
c19d1205
ZW
18210 /* FPA registers. */
18211 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18212 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18213
18214 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18215 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18216
18217 /* VFP SP registers. */
5287ad62
JB
18218 REGSET(s,VFS), REGSET(S,VFS),
18219 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18220
18221 /* VFP DP Registers. */
5287ad62
JB
18222 REGSET(d,VFD), REGSET(D,VFD),
18223 /* Extra Neon DP registers. */
18224 REGSETH(d,VFD), REGSETH(D,VFD),
18225
18226 /* Neon QP registers. */
18227 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18228
18229 /* VFP control registers. */
18230 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18231 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18232 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18233 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18234 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18235 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
18236
18237 /* Maverick DSP coprocessor registers. */
18238 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18239 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18240
18241 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18242 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18243 REGDEF(dspsc,0,DSPSC),
18244
18245 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18246 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18247 REGDEF(DSPSC,0,DSPSC),
18248
18249 /* iWMMXt data registers - p0, c0-15. */
18250 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18251
18252 /* iWMMXt control registers - p1, c0-3. */
18253 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18254 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18255 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18256 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18257
18258 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18259 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18260 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18261 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18262 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18263
18264 /* XScale accumulator registers. */
18265 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18266};
18267#undef REGDEF
18268#undef REGNUM
18269#undef REGSET
7ed4c4c5 18270
c19d1205
ZW
18271/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18272 within psr_required_here. */
18273static const struct asm_psr psrs[] =
18274{
18275 /* Backward compatibility notation. Note that "all" is no longer
18276 truly all possible PSR bits. */
18277 {"all", PSR_c | PSR_f},
18278 {"flg", PSR_f},
18279 {"ctl", PSR_c},
18280
18281 /* Individual flags. */
18282 {"f", PSR_f},
18283 {"c", PSR_c},
18284 {"x", PSR_x},
18285 {"s", PSR_s},
59b42a0d 18286
c19d1205
ZW
18287 /* Combinations of flags. */
18288 {"fs", PSR_f | PSR_s},
18289 {"fx", PSR_f | PSR_x},
18290 {"fc", PSR_f | PSR_c},
18291 {"sf", PSR_s | PSR_f},
18292 {"sx", PSR_s | PSR_x},
18293 {"sc", PSR_s | PSR_c},
18294 {"xf", PSR_x | PSR_f},
18295 {"xs", PSR_x | PSR_s},
18296 {"xc", PSR_x | PSR_c},
18297 {"cf", PSR_c | PSR_f},
18298 {"cs", PSR_c | PSR_s},
18299 {"cx", PSR_c | PSR_x},
18300 {"fsx", PSR_f | PSR_s | PSR_x},
18301 {"fsc", PSR_f | PSR_s | PSR_c},
18302 {"fxs", PSR_f | PSR_x | PSR_s},
18303 {"fxc", PSR_f | PSR_x | PSR_c},
18304 {"fcs", PSR_f | PSR_c | PSR_s},
18305 {"fcx", PSR_f | PSR_c | PSR_x},
18306 {"sfx", PSR_s | PSR_f | PSR_x},
18307 {"sfc", PSR_s | PSR_f | PSR_c},
18308 {"sxf", PSR_s | PSR_x | PSR_f},
18309 {"sxc", PSR_s | PSR_x | PSR_c},
18310 {"scf", PSR_s | PSR_c | PSR_f},
18311 {"scx", PSR_s | PSR_c | PSR_x},
18312 {"xfs", PSR_x | PSR_f | PSR_s},
18313 {"xfc", PSR_x | PSR_f | PSR_c},
18314 {"xsf", PSR_x | PSR_s | PSR_f},
18315 {"xsc", PSR_x | PSR_s | PSR_c},
18316 {"xcf", PSR_x | PSR_c | PSR_f},
18317 {"xcs", PSR_x | PSR_c | PSR_s},
18318 {"cfs", PSR_c | PSR_f | PSR_s},
18319 {"cfx", PSR_c | PSR_f | PSR_x},
18320 {"csf", PSR_c | PSR_s | PSR_f},
18321 {"csx", PSR_c | PSR_s | PSR_x},
18322 {"cxf", PSR_c | PSR_x | PSR_f},
18323 {"cxs", PSR_c | PSR_x | PSR_s},
18324 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18325 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18326 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18327 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18328 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18329 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18330 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18331 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18332 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18333 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18334 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18335 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18336 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18337 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18338 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18339 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18340 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18341 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18342 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18343 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18344 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18345 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18346 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18347 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18348};
18349
62b3e311
PB
18350/* Table of V7M psr names. */
18351static const struct asm_psr v7m_psrs[] =
18352{
2b744c99
PB
18353 {"apsr", 0 }, {"APSR", 0 },
18354 {"iapsr", 1 }, {"IAPSR", 1 },
18355 {"eapsr", 2 }, {"EAPSR", 2 },
18356 {"psr", 3 }, {"PSR", 3 },
18357 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
18358 {"ipsr", 5 }, {"IPSR", 5 },
18359 {"epsr", 6 }, {"EPSR", 6 },
18360 {"iepsr", 7 }, {"IEPSR", 7 },
18361 {"msp", 8 }, {"MSP", 8 },
18362 {"psp", 9 }, {"PSP", 9 },
18363 {"primask", 16}, {"PRIMASK", 16},
18364 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
18365 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
18366 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99
PB
18367 {"faultmask", 19}, {"FAULTMASK", 19},
18368 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
18369};
18370
c19d1205
ZW
18371/* Table of all shift-in-operand names. */
18372static const struct asm_shift_name shift_names [] =
b99bd4ef 18373{
c19d1205
ZW
18374 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18375 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18376 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18377 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18378 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18379 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18380};
b99bd4ef 18381
c19d1205
ZW
18382/* Table of all explicit relocation names. */
18383#ifdef OBJ_ELF
18384static struct reloc_entry reloc_names[] =
18385{
18386 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
18387 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
18388 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
18389 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
18390 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
18391 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
18392 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
18393 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
18394 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
18395 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 18396 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
18397 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
18398 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 18399 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 18400 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 18401 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 18402 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 18403 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
18404};
18405#endif
b99bd4ef 18406
c19d1205
ZW
18407/* Table of all conditional affixes. 0xF is not defined as a condition code. */
18408static const struct asm_cond conds[] =
18409{
18410 {"eq", 0x0},
18411 {"ne", 0x1},
18412 {"cs", 0x2}, {"hs", 0x2},
18413 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
18414 {"mi", 0x4},
18415 {"pl", 0x5},
18416 {"vs", 0x6},
18417 {"vc", 0x7},
18418 {"hi", 0x8},
18419 {"ls", 0x9},
18420 {"ge", 0xa},
18421 {"lt", 0xb},
18422 {"gt", 0xc},
18423 {"le", 0xd},
18424 {"al", 0xe}
18425};
bfae80f2 18426
e797f7e0 18427#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
18428 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
18429 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 18430
62b3e311
PB
18431static struct asm_barrier_opt barrier_opt_names[] =
18432{
e797f7e0
MGD
18433 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
18434 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
18435 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
18436 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
18437 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
18438 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
18439 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
18440 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
18441 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
18442 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
18443 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
18444 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
18445 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
18446 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
18447 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
18448 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
18449};
18450
e797f7e0
MGD
18451#undef UL_BARRIER
18452
c19d1205
ZW
18453/* Table of ARM-format instructions. */
18454
18455/* Macros for gluing together operand strings. N.B. In all cases
18456 other than OPS0, the trailing OP_stop comes from default
18457 zero-initialization of the unspecified elements of the array. */
18458#define OPS0() { OP_stop, }
18459#define OPS1(a) { OP_##a, }
18460#define OPS2(a,b) { OP_##a,OP_##b, }
18461#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
18462#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
18463#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
18464#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
18465
5be8be5d
DG
18466/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
18467 This is useful when mixing operands for ARM and THUMB, i.e. using the
18468 MIX_ARM_THUMB_OPERANDS macro.
18469 In order to use these macros, prefix the number of operands with _
18470 e.g. _3. */
18471#define OPS_1(a) { a, }
18472#define OPS_2(a,b) { a,b, }
18473#define OPS_3(a,b,c) { a,b,c, }
18474#define OPS_4(a,b,c,d) { a,b,c,d, }
18475#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
18476#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
18477
c19d1205
ZW
18478/* These macros abstract out the exact format of the mnemonic table and
18479 save some repeated characters. */
18480
18481/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
18482#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18483 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 18484 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18485
18486/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
18487 a T_MNEM_xyz enumerator. */
18488#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18489 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18490#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18491 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
18492
18493/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
18494 infix after the third character. */
18495#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 18496 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 18497 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 18498#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 18499 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 18500 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18501#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18502 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 18503#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18504 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18505#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18506 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 18507#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18508 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 18509
c19d1205 18510/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
18511 field is still 0xE. Many of the Thumb variants can be executed
18512 conditionally, so this is checked separately. */
c19d1205 18513#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18514 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18515 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18516
dd5181d5
KT
18517/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
18518 Used by mnemonics that have very minimal differences in the encoding for
18519 ARM and Thumb variants and can be handled in a common function. */
18520#define TUEc(mnem, op, top, nops, ops, en) \
18521 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
18522 THUMB_VARIANT, do_##en, do_##en }
18523
c19d1205
ZW
18524/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
18525 condition code field. */
18526#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 18527 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18528 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18529
18530/* ARM-only variants of all the above. */
6a86118a 18531#define CE(mnem, op, nops, ops, ae) \
21d799b5 18532 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
18533
18534#define C3(mnem, op, nops, ops, ae) \
18535 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18536
e3cb604e
PB
18537/* Legacy mnemonics that always have conditional infix after the third
18538 character. */
18539#define CL(mnem, op, nops, ops, ae) \
21d799b5 18540 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18541 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18542
8f06b2d8
PB
18543/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
18544#define cCE(mnem, op, nops, ops, ae) \
21d799b5 18545 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18546
e3cb604e
PB
18547/* Legacy coprocessor instructions where conditional infix and conditional
18548 suffix are ambiguous. For consistency this includes all FPA instructions,
18549 not just the potentially ambiguous ones. */
18550#define cCL(mnem, op, nops, ops, ae) \
21d799b5 18551 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18552 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
18553
18554/* Coprocessor, takes either a suffix or a position-3 infix
18555 (for an FPA corner case). */
18556#define C3E(mnem, op, nops, ops, ae) \
21d799b5 18557 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 18558 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18559
6a86118a 18560#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
18561 { m1 #m2 m3, OPS##nops ops, \
18562 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
18563 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18564
18565#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
18566 xCM_ (m1, , m2, op, nops, ops, ae), \
18567 xCM_ (m1, eq, m2, op, nops, ops, ae), \
18568 xCM_ (m1, ne, m2, op, nops, ops, ae), \
18569 xCM_ (m1, cs, m2, op, nops, ops, ae), \
18570 xCM_ (m1, hs, m2, op, nops, ops, ae), \
18571 xCM_ (m1, cc, m2, op, nops, ops, ae), \
18572 xCM_ (m1, ul, m2, op, nops, ops, ae), \
18573 xCM_ (m1, lo, m2, op, nops, ops, ae), \
18574 xCM_ (m1, mi, m2, op, nops, ops, ae), \
18575 xCM_ (m1, pl, m2, op, nops, ops, ae), \
18576 xCM_ (m1, vs, m2, op, nops, ops, ae), \
18577 xCM_ (m1, vc, m2, op, nops, ops, ae), \
18578 xCM_ (m1, hi, m2, op, nops, ops, ae), \
18579 xCM_ (m1, ls, m2, op, nops, ops, ae), \
18580 xCM_ (m1, ge, m2, op, nops, ops, ae), \
18581 xCM_ (m1, lt, m2, op, nops, ops, ae), \
18582 xCM_ (m1, gt, m2, op, nops, ops, ae), \
18583 xCM_ (m1, le, m2, op, nops, ops, ae), \
18584 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
18585
18586#define UE(mnem, op, nops, ops, ae) \
18587 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18588
18589#define UF(mnem, op, nops, ops, ae) \
18590 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18591
5287ad62
JB
18592/* Neon data-processing. ARM versions are unconditional with cond=0xf.
18593 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
18594 use the same encoding function for each. */
18595#define NUF(mnem, op, nops, ops, enc) \
18596 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
18597 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18598
18599/* Neon data processing, version which indirects through neon_enc_tab for
18600 the various overloaded versions of opcodes. */
18601#define nUF(mnem, op, nops, ops, enc) \
21d799b5 18602 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
18603 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18604
18605/* Neon insn with conditional suffix for the ARM version, non-overloaded
18606 version. */
037e8744
JB
18607#define NCE_tag(mnem, op, nops, ops, enc, tag) \
18608 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
18609 THUMB_VARIANT, do_##enc, do_##enc }
18610
037e8744 18611#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 18612 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
18613
18614#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 18615 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 18616
5287ad62 18617/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 18618#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 18619 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
18620 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18621
037e8744 18622#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 18623 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
18624
18625#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 18626 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 18627
c19d1205
ZW
18628#define do_0 0
18629
c19d1205 18630static const struct asm_opcode insns[] =
bfae80f2 18631{
74db7efb
NC
18632#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
18633#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
18634 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
18635 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
18636 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
18637 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
18638 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
18639 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
18640 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
18641 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
18642 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
18643 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
18644 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
18645 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
18646 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
18647 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
18648 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
18649 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
18650
18651 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
18652 for setting PSR flag bits. They are obsolete in V6 and do not
18653 have Thumb equivalents. */
21d799b5
NC
18654 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18655 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18656 CL("tstp", 110f000, 2, (RR, SH), cmp),
18657 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18658 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18659 CL("cmpp", 150f000, 2, (RR, SH), cmp),
18660 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18661 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18662 CL("cmnp", 170f000, 2, (RR, SH), cmp),
18663
18664 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 18665 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
18666 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
18667 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
18668
18669 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
18670 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
18671 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
18672 OP_RRnpc),
18673 OP_ADDRGLDR),ldst, t_ldst),
18674 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
18675
18676 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18677 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18678 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18679 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18680 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18681 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18682
18683 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
18684 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
18685 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
18686 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 18687
c19d1205 18688 /* Pseudo ops. */
21d799b5 18689 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 18690 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 18691 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 18692 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
18693
18694 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
18695 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
18696 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
18697 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
18698 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
18699 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
18700 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
18701 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
18702 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
18703 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
18704 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
18705 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
18706 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 18707
16a4cf17 18708 /* These may simplify to neg. */
21d799b5
NC
18709 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
18710 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 18711
c921be7d
NC
18712#undef THUMB_VARIANT
18713#define THUMB_VARIANT & arm_ext_v6
18714
21d799b5 18715 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
18716
18717 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
18718#undef THUMB_VARIANT
18719#define THUMB_VARIANT & arm_ext_v6t2
18720
21d799b5
NC
18721 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
18722 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
18723 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 18724
5be8be5d
DG
18725 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18726 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18727 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
18728 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 18729
21d799b5
NC
18730 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18731 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 18732
21d799b5
NC
18733 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18734 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
18735
18736 /* V1 instructions with no Thumb analogue at all. */
21d799b5 18737 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
18738 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
18739
18740 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
18741 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
18742 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
18743 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
18744 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
18745 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
18746 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
18747 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
18748
c921be7d
NC
18749#undef ARM_VARIANT
18750#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
18751#undef THUMB_VARIANT
18752#define THUMB_VARIANT & arm_ext_v4t
18753
21d799b5
NC
18754 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
18755 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 18756
c921be7d
NC
18757#undef THUMB_VARIANT
18758#define THUMB_VARIANT & arm_ext_v6t2
18759
21d799b5 18760 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
18761 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
18762
18763 /* Generic coprocessor instructions. */
21d799b5
NC
18764 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18765 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18766 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18767 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18768 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18769 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 18770 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 18771
c921be7d
NC
18772#undef ARM_VARIANT
18773#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
18774
21d799b5 18775 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
18776 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
18777
c921be7d
NC
18778#undef ARM_VARIANT
18779#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
18780#undef THUMB_VARIANT
18781#define THUMB_VARIANT & arm_ext_msr
18782
d2cd1205
JB
18783 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
18784 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 18785
c921be7d
NC
18786#undef ARM_VARIANT
18787#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
18788#undef THUMB_VARIANT
18789#define THUMB_VARIANT & arm_ext_v6t2
18790
21d799b5
NC
18791 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18792 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18793 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18794 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18795 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18796 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18797 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18798 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 18799
c921be7d
NC
18800#undef ARM_VARIANT
18801#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
18802#undef THUMB_VARIANT
18803#define THUMB_VARIANT & arm_ext_v4t
18804
5be8be5d
DG
18805 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18806 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18807 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18808 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
18809 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18810 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 18811
c921be7d
NC
18812#undef ARM_VARIANT
18813#define ARM_VARIANT & arm_ext_v4t_5
18814
c19d1205
ZW
18815 /* ARM Architecture 4T. */
18816 /* Note: bx (and blx) are required on V5, even if the processor does
18817 not support Thumb. */
21d799b5 18818 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 18819
c921be7d
NC
18820#undef ARM_VARIANT
18821#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
18822#undef THUMB_VARIANT
18823#define THUMB_VARIANT & arm_ext_v5t
18824
c19d1205
ZW
18825 /* Note: blx has 2 variants; the .value coded here is for
18826 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
18827 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
18828 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 18829
c921be7d
NC
18830#undef THUMB_VARIANT
18831#define THUMB_VARIANT & arm_ext_v6t2
18832
21d799b5
NC
18833 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
18834 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18835 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18836 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18837 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18838 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18839 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18840 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 18841
c921be7d 18842#undef ARM_VARIANT
74db7efb
NC
18843#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
18844#undef THUMB_VARIANT
18845#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 18846
21d799b5
NC
18847 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18848 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18849 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18850 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 18851
21d799b5
NC
18852 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18853 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 18854
21d799b5
NC
18855 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18856 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18857 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18858 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 18859
21d799b5
NC
18860 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18861 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18862 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18863 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 18864
21d799b5
NC
18865 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18866 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 18867
03ee1b7f
NC
18868 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18869 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18870 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18871 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 18872
c921be7d 18873#undef ARM_VARIANT
74db7efb
NC
18874#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
18875#undef THUMB_VARIANT
18876#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 18877
21d799b5 18878 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
18879 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
18880 ldrd, t_ldstd),
18881 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
18882 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 18883
21d799b5
NC
18884 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18885 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 18886
c921be7d
NC
18887#undef ARM_VARIANT
18888#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
18889
21d799b5 18890 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 18891
c921be7d
NC
18892#undef ARM_VARIANT
18893#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
18894#undef THUMB_VARIANT
18895#define THUMB_VARIANT & arm_ext_v6
18896
21d799b5
NC
18897 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
18898 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
18899 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18900 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18901 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18902 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18903 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18904 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18905 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18906 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 18907
c921be7d
NC
18908#undef THUMB_VARIANT
18909#define THUMB_VARIANT & arm_ext_v6t2
18910
5be8be5d
DG
18911 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
18912 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
18913 strex, t_strex),
21d799b5
NC
18914 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18915 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 18916
21d799b5
NC
18917 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
18918 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 18919
9e3c6df6 18920/* ARM V6 not included in V7M. */
c921be7d
NC
18921#undef THUMB_VARIANT
18922#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 18923 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 18924 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
18925 UF(rfeib, 9900a00, 1, (RRw), rfe),
18926 UF(rfeda, 8100a00, 1, (RRw), rfe),
18927 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18928 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
18929 UF(rfefa, 8100a00, 1, (RRw), rfe),
18930 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18931 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 18932 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
18933 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18934 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 18935 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 18936 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 18937 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 18938 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 18939 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 18940 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 18941 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 18942
9e3c6df6
PB
18943/* ARM V6 not included in V7M (eg. integer SIMD). */
18944#undef THUMB_VARIANT
18945#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
18946 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
18947 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
18948 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18949 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18950 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18951 /* Old name for QASX. */
74db7efb 18952 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 18953 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18954 /* Old name for QSAX. */
74db7efb 18955 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18956 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18957 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18958 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18959 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18960 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18961 /* Old name for SASX. */
74db7efb 18962 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18963 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18964 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18965 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18966 /* Old name for SHASX. */
21d799b5 18967 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18968 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18969 /* Old name for SHSAX. */
21d799b5
NC
18970 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18971 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18972 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18973 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18974 /* Old name for SSAX. */
74db7efb 18975 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18976 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18977 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18978 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18979 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18980 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18981 /* Old name for UASX. */
74db7efb 18982 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18983 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18984 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18985 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18986 /* Old name for UHASX. */
21d799b5
NC
18987 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18988 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18989 /* Old name for UHSAX. */
21d799b5
NC
18990 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18991 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18992 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18993 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18994 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18995 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18996 /* Old name for UQASX. */
21d799b5
NC
18997 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18998 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18999 /* Old name for UQSAX. */
21d799b5
NC
19000 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19001 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19002 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19003 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19004 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19005 /* Old name for USAX. */
74db7efb 19006 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19007 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19008 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19009 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19010 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19011 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19012 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19013 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19014 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19015 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19016 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19017 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19018 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19019 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19020 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19021 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19022 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19023 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19024 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19025 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19026 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19027 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19028 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19029 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19030 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19031 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19032 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19033 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19034 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19035 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19036 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19037 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19038 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19039 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19040
c921be7d
NC
19041#undef ARM_VARIANT
19042#define ARM_VARIANT & arm_ext_v6k
19043#undef THUMB_VARIANT
19044#define THUMB_VARIANT & arm_ext_v6k
19045
21d799b5
NC
19046 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19047 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19048 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19049 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19050
c921be7d
NC
19051#undef THUMB_VARIANT
19052#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19053 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19054 ldrexd, t_ldrexd),
19055 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19056 RRnpcb), strexd, t_strexd),
ebdca51a 19057
c921be7d
NC
19058#undef THUMB_VARIANT
19059#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
19060 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19061 rd_rn, rd_rn),
19062 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19063 rd_rn, rd_rn),
19064 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19065 strex, t_strexbh),
5be8be5d 19066 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19067 strex, t_strexbh),
21d799b5 19068 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19069
c921be7d 19070#undef ARM_VARIANT
f4c65163 19071#define ARM_VARIANT & arm_ext_sec
74db7efb 19072#undef THUMB_VARIANT
f4c65163 19073#define THUMB_VARIANT & arm_ext_sec
c921be7d 19074
21d799b5 19075 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19076
90ec0d68
MGD
19077#undef ARM_VARIANT
19078#define ARM_VARIANT & arm_ext_virt
19079#undef THUMB_VARIANT
19080#define THUMB_VARIANT & arm_ext_virt
19081
19082 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19083 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19084
ddfded2f
MW
19085#undef ARM_VARIANT
19086#define ARM_VARIANT & arm_ext_pan
19087#undef THUMB_VARIANT
19088#define THUMB_VARIANT & arm_ext_pan
19089
19090 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19091
c921be7d 19092#undef ARM_VARIANT
74db7efb 19093#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19094#undef THUMB_VARIANT
19095#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19096
21d799b5
NC
19097 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19098 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19099 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19100 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19101
21d799b5
NC
19102 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
19103 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19104 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19105 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19106
5be8be5d
DG
19107 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19108 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19109 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19110 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19111
bf3eeda7 19112 /* Thumb-only instructions. */
74db7efb 19113#undef ARM_VARIANT
bf3eeda7
NS
19114#define ARM_VARIANT NULL
19115 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19116 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19117
19118 /* ARM does not really have an IT instruction, so always allow it.
19119 The opcode is copied from Thumb in order to allow warnings in
19120 -mimplicit-it=[never | arm] modes. */
19121#undef ARM_VARIANT
19122#define ARM_VARIANT & arm_ext_v1
19123
21d799b5
NC
19124 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19125 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19126 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19127 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19128 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19129 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19130 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19131 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19132 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19133 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19134 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19135 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19136 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19137 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19138 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19139 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19140 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19141 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19142
92e90b6e 19143 /* Thumb2 only instructions. */
c921be7d
NC
19144#undef ARM_VARIANT
19145#define ARM_VARIANT NULL
92e90b6e 19146
21d799b5
NC
19147 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19148 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19149 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19150 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19151 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19152 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19153
eea54501
MGD
19154 /* Hardware division instructions. */
19155#undef ARM_VARIANT
19156#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19157#undef THUMB_VARIANT
19158#define THUMB_VARIANT & arm_ext_div
19159
eea54501
MGD
19160 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19161 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19162
7e806470 19163 /* ARM V6M/V7 instructions. */
c921be7d
NC
19164#undef ARM_VARIANT
19165#define ARM_VARIANT & arm_ext_barrier
19166#undef THUMB_VARIANT
19167#define THUMB_VARIANT & arm_ext_barrier
19168
ccb84d65
JB
19169 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19170 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19171 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19172
62b3e311 19173 /* ARM V7 instructions. */
c921be7d
NC
19174#undef ARM_VARIANT
19175#define ARM_VARIANT & arm_ext_v7
19176#undef THUMB_VARIANT
19177#define THUMB_VARIANT & arm_ext_v7
19178
21d799b5
NC
19179 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19180 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19181
74db7efb 19182#undef ARM_VARIANT
60e5ef9f 19183#define ARM_VARIANT & arm_ext_mp
74db7efb 19184#undef THUMB_VARIANT
60e5ef9f
MGD
19185#define THUMB_VARIANT & arm_ext_mp
19186
19187 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19188
53c4b28b
MGD
19189 /* AArchv8 instructions. */
19190#undef ARM_VARIANT
19191#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
19192
19193/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 19194#undef THUMB_VARIANT
4ed7ed8d 19195#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 19196
4ed7ed8d
TP
19197 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19198 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19199 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19200 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19201 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19202 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 19203 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
19204 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19205 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19206 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19207 stlex, t_stlex),
4b8c8c02
RE
19208 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19209 stlex, t_stlex),
19210 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19211 stlex, t_stlex),
4ed7ed8d
TP
19212#undef THUMB_VARIANT
19213#define THUMB_VARIANT & arm_ext_v8
53c4b28b 19214
4ed7ed8d
TP
19215 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
19216 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
19217 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
19218 ldrexd, t_ldrexd),
19219 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
19220 strexd, t_strexd),
8884b720 19221 /* ARMv8 T32 only. */
74db7efb 19222#undef ARM_VARIANT
b79f7053
MGD
19223#define ARM_VARIANT NULL
19224 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19225 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19226 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19227
33399f07
MGD
19228 /* FP for ARMv8. */
19229#undef ARM_VARIANT
a715796b 19230#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19231#undef THUMB_VARIANT
a715796b 19232#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19233
19234 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19235 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19236 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19237 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19238 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19239 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19240 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19241 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19242 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19243 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19244 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19245 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19246 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19247 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19248 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19249 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19250 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19251
91ff7894
MGD
19252 /* Crypto v1 extensions. */
19253#undef ARM_VARIANT
19254#define ARM_VARIANT & fpu_crypto_ext_armv8
19255#undef THUMB_VARIANT
19256#define THUMB_VARIANT & fpu_crypto_ext_armv8
19257
19258 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19259 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19260 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19261 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19262 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19263 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19264 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19265 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19266 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19267 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19268 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19269 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19270 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19271 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19272
dd5181d5 19273#undef ARM_VARIANT
74db7efb 19274#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19275#undef THUMB_VARIANT
19276#define THUMB_VARIANT & crc_ext_armv8
19277 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19278 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19279 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19280 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19281 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19282 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19283
c921be7d
NC
19284#undef ARM_VARIANT
19285#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
19286#undef THUMB_VARIANT
19287#define THUMB_VARIANT NULL
c921be7d 19288
21d799b5
NC
19289 cCE("wfs", e200110, 1, (RR), rd),
19290 cCE("rfs", e300110, 1, (RR), rd),
19291 cCE("wfc", e400110, 1, (RR), rd),
19292 cCE("rfc", e500110, 1, (RR), rd),
19293
19294 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19295 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19296 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19297 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19298
19299 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19300 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19301 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19302 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19303
19304 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19305 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19306 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19307 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19308 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19309 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19310 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19311 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19312 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19313 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19314 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19315 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19316
19317 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19318 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19319 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19320 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19321 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19322 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19323 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19324 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19325 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19326 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19327 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19328 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19329
19330 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19331 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19332 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19333 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19334 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19335 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19336 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19337 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19338 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19339 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19340 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19341 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19342
19343 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19344 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19345 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19346 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19347 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19348 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19349 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19350 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19351 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19352 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19353 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19354 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19355
19356 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19357 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19358 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19359 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19360 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19361 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
19362 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
19363 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
19364 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
19365 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
19366 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
19367 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
19368
19369 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
19370 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
19371 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
19372 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
19373 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
19374 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
19375 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
19376 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
19377 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
19378 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
19379 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
19380 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
19381
19382 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
19383 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
19384 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
19385 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
19386 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
19387 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
19388 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
19389 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
19390 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
19391 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
19392 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
19393 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
19394
19395 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
19396 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
19397 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
19398 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
19399 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
19400 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
19401 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
19402 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
19403 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
19404 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
19405 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
19406 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
19407
19408 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
19409 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
19410 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
19411 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
19412 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
19413 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
19414 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
19415 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
19416 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
19417 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
19418 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
19419 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
19420
19421 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
19422 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
19423 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
19424 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
19425 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
19426 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
19427 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
19428 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
19429 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
19430 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
19431 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
19432 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
19433
19434 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
19435 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
19436 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
19437 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
19438 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
19439 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
19440 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
19441 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
19442 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
19443 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
19444 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
19445 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
19446
19447 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
19448 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
19449 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
19450 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
19451 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
19452 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
19453 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
19454 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
19455 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
19456 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
19457 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
19458 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
19459
19460 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
19461 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
19462 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
19463 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
19464 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
19465 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
19466 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
19467 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
19468 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
19469 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
19470 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
19471 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
19472
19473 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
19474 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
19475 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
19476 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
19477 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
19478 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
19479 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
19480 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
19481 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
19482 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
19483 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
19484 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
19485
19486 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
19487 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
19488 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
19489 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
19490 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
19491 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
19492 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
19493 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
19494 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
19495 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
19496 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
19497 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
19498
19499 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
19500 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
19501 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
19502 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
19503 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
19504 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
19505 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
19506 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
19507 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
19508 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
19509 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
19510 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
19511
19512 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
19513 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
19514 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
19515 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
19516 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
19517 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19518 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19519 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19520 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
19521 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
19522 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
19523 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
19524
19525 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
19526 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
19527 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
19528 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
19529 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
19530 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19531 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19532 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19533 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
19534 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
19535 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
19536 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
19537
19538 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
19539 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
19540 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
19541 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
19542 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
19543 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19544 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19545 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19546 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
19547 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
19548 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
19549 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
19550
19551 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
19552 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
19553 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
19554 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
19555 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
19556 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19557 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19558 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19559 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
19560 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
19561 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
19562 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
19563
19564 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
19565 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
19566 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
19567 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
19568 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
19569 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19570 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19571 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19572 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
19573 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
19574 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
19575 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
19576
19577 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
19578 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
19579 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
19580 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
19581 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
19582 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19583 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19584 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19585 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
19586 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
19587 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
19588 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
19589
19590 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
19591 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
19592 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
19593 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
19594 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
19595 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19596 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19597 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19598 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
19599 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
19600 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
19601 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
19602
19603 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
19604 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
19605 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
19606 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
19607 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
19608 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19609 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19610 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19611 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
19612 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
19613 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
19614 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
19615
19616 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
19617 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
19618 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
19619 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
19620 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
19621 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19622 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19623 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19624 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
19625 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
19626 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
19627 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
19628
19629 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
19630 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
19631 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
19632 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
19633 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
19634 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19635 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19636 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19637 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
19638 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
19639 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
19640 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
19641
19642 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19643 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19644 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19645 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19646 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19647 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19648 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19649 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19650 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19651 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19652 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19653 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19654
19655 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19656 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19657 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19658 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19659 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19660 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19661 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19662 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19663 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19664 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19665 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19666 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19667
19668 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19669 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19670 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19671 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19672 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19673 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19674 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19675 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19676 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19677 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19678 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19679 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19680
19681 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
19682 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
19683 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
19684 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
19685
19686 cCL("flts", e000110, 2, (RF, RR), rn_rd),
19687 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
19688 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
19689 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
19690 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
19691 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
19692 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
19693 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
19694 cCL("flte", e080110, 2, (RF, RR), rn_rd),
19695 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
19696 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
19697 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 19698
c19d1205
ZW
19699 /* The implementation of the FIX instruction is broken on some
19700 assemblers, in that it accepts a precision specifier as well as a
19701 rounding specifier, despite the fact that this is meaningless.
19702 To be more compatible, we accept it as well, though of course it
19703 does not set any bits. */
21d799b5
NC
19704 cCE("fix", e100110, 2, (RR, RF), rd_rm),
19705 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
19706 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
19707 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
19708 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
19709 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
19710 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
19711 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
19712 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
19713 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
19714 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
19715 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
19716 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 19717
c19d1205 19718 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
19719#undef ARM_VARIANT
19720#define ARM_VARIANT & fpu_fpa_ext_v2
19721
21d799b5
NC
19722 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19723 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19724 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19725 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19726 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19727 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 19728
c921be7d
NC
19729#undef ARM_VARIANT
19730#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
19731
c19d1205 19732 /* Moves and type conversions. */
21d799b5
NC
19733 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
19734 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
19735 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
19736 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
19737 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
19738 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
19739 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
19740 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
19741 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
19742 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
19743 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
19744 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
19745 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
19746 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
19747
19748 /* Memory operations. */
21d799b5
NC
19749 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
19750 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
19751 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19752 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19753 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19754 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19755 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19756 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19757 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19758 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19759 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19760 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19761 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19762 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19763 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19764 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19765 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19766 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 19767
c19d1205 19768 /* Monadic operations. */
21d799b5
NC
19769 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
19770 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
19771 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
19772
19773 /* Dyadic operations. */
21d799b5
NC
19774 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19775 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19776 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19777 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19778 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19779 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19780 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19781 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19782 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 19783
c19d1205 19784 /* Comparisons. */
21d799b5
NC
19785 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
19786 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
19787 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
19788 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 19789
62f3b8c8
PB
19790 /* Double precision load/store are still present on single precision
19791 implementations. */
19792 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
19793 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
19794 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19795 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19796 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19797 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19798 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19799 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19800 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19801 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 19802
c921be7d
NC
19803#undef ARM_VARIANT
19804#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
19805
c19d1205 19806 /* Moves and type conversions. */
21d799b5
NC
19807 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19808 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19809 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19810 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
19811 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
19812 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
19813 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
19814 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19815 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
19816 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19817 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19818 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19819 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 19820
c19d1205 19821 /* Monadic operations. */
21d799b5
NC
19822 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19823 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19824 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
19825
19826 /* Dyadic operations. */
21d799b5
NC
19827 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19828 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19829 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19830 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19831 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19832 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19833 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19834 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19835 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 19836
c19d1205 19837 /* Comparisons. */
21d799b5
NC
19838 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19839 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
19840 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19841 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 19842
c921be7d
NC
19843#undef ARM_VARIANT
19844#define ARM_VARIANT & fpu_vfp_ext_v2
19845
21d799b5
NC
19846 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
19847 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
19848 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
19849 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 19850
037e8744
JB
19851/* Instructions which may belong to either the Neon or VFP instruction sets.
19852 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
19853#undef ARM_VARIANT
19854#define ARM_VARIANT & fpu_vfp_ext_v1xd
19855#undef THUMB_VARIANT
19856#define THUMB_VARIANT & fpu_vfp_ext_v1xd
19857
037e8744
JB
19858 /* These mnemonics are unique to VFP. */
19859 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
19860 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
19861 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19862 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19863 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
19864 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
19865 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
19866 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
19867 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
19868 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
19869
19870 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
19871 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
19872 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
19873 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 19874
21d799b5
NC
19875 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
19876 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
19877
19878 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19879 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19880
55881a11
MGD
19881 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19882 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19883 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19884 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19885 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19886 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
19887 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
19888 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 19889
5f1af56b 19890 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 19891 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
19892 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
19893 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 19894
037e8744
JB
19895
19896 /* NOTE: All VMOV encoding is special-cased! */
19897 NCE(vmov, 0, 1, (VMOV), neon_mov),
19898 NCE(vmovq, 0, 1, (VMOV), neon_mov),
19899
c921be7d
NC
19900#undef THUMB_VARIANT
19901#define THUMB_VARIANT & fpu_neon_ext_v1
19902#undef ARM_VARIANT
19903#define ARM_VARIANT & fpu_neon_ext_v1
19904
5287ad62
JB
19905 /* Data processing with three registers of the same length. */
19906 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
19907 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
19908 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
19909 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19910 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19911 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19912 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19913 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19914 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19915 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
19916 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19917 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
19918 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19919 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
19920 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19921 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
19922 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19923 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
19924 /* If not immediate, fall back to neon_dyadic_i64_su.
19925 shl_imm should accept I8 I16 I32 I64,
19926 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
19927 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
19928 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
19929 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
19930 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 19931 /* Logic ops, types optional & ignored. */
4316f0d2
DG
19932 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19933 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19934 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19935 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19936 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19937 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19938 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19939 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19940 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
19941 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
19942 /* Bitfield ops, untyped. */
19943 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19944 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19945 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19946 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19947 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19948 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19949 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
19950 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19951 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19952 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19953 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19954 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19955 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
19956 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
19957 back to neon_dyadic_if_su. */
21d799b5
NC
19958 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19959 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19960 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19961 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19962 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19963 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
19964 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19965 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 19966 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
19967 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
19968 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 19969 /* As above, D registers only. */
21d799b5
NC
19970 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
19971 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 19972 /* Int and float variants, signedness unimportant. */
21d799b5
NC
19973 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19974 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19975 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 19976 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
19977 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
19978 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
19979 /* vtst takes sizes 8, 16, 32. */
19980 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
19981 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
19982 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 19983 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 19984 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
19985 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19986 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19987 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19988 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
19989 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19990 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
19991 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19992 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
19993 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19994 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
19995 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19996 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
19997 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19998 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19999 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20000 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e
MW
20001 /* ARM v8.1 extension. */
20002 nUF(vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20003 nUF(vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20004 nUF(vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20005 nUF(vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20006
20007 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20008 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20009 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20010
20011 /* Data processing with two registers and a shift amount. */
20012 /* Right shifts, and variants with rounding.
20013 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20014 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20015 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20016 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20017 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20018 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20019 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20020 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20021 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20022 /* Shift and insert. Sizes accepted 8 16 32 64. */
20023 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20024 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20025 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20026 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20027 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20028 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20029 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20030 /* Right shift immediate, saturating & narrowing, with rounding variants.
20031 Types accepted S16 S32 S64 U16 U32 U64. */
20032 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20033 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20034 /* As above, unsigned. Types accepted S16 S32 S64. */
20035 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20036 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20037 /* Right shift narrowing. Types accepted I16 I32 I64. */
20038 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20039 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20040 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20041 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20042 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20043 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20044
4316f0d2
DG
20045 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20046 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20047
20048 /* Data processing, three registers of different lengths. */
20049 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20050 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20051 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20052 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20053 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20054 /* If not scalar, fall back to neon_dyadic_long.
20055 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20056 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20057 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20058 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20059 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20060 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20061 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20062 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20063 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20064 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20065 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20066 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20067 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20068 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20069 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20070 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20071 S16 S32 U16 U32. */
21d799b5 20072 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20073
20074 /* Extract. Size 8. */
3b8d421e
PB
20075 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20076 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20077
20078 /* Two registers, miscellaneous. */
20079 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20080 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20081 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20082 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20083 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20084 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20085 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20086 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20087 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20088 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20089 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20090 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20091 /* VMOVN. Types I16 I32 I64. */
21d799b5 20092 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20093 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20094 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20095 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20096 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20097 /* VZIP / VUZP. Sizes 8 16 32. */
20098 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20099 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20100 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20101 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20102 /* VQABS / VQNEG. Types S8 S16 S32. */
20103 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20104 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20105 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20106 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20107 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20108 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20109 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20110 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20111 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
20112 /* Reciprocal estimates. Types U32 F32. */
20113 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20114 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20115 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20116 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20117 /* VCLS. Types S8 S16 S32. */
20118 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20119 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20120 /* VCLZ. Types I8 I16 I32. */
20121 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20122 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20123 /* VCNT. Size 8. */
20124 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20125 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20126 /* Two address, untyped. */
20127 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20128 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20129 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20130 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20131 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20132
20133 /* Table lookup. Size 8. */
20134 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20135 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20136
c921be7d
NC
20137#undef THUMB_VARIANT
20138#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20139#undef ARM_VARIANT
20140#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20141
5287ad62 20142 /* Neon element/structure load/store. */
21d799b5
NC
20143 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20144 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20145 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20146 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20147 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20148 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20149 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20150 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20151
c921be7d 20152#undef THUMB_VARIANT
74db7efb
NC
20153#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20154#undef ARM_VARIANT
20155#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20156 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20157 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20158 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20159 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20160 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20161 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20162 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20163 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20164 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20165
74db7efb 20166#undef THUMB_VARIANT
c921be7d
NC
20167#define THUMB_VARIANT & fpu_vfp_ext_v3
20168#undef ARM_VARIANT
20169#define ARM_VARIANT & fpu_vfp_ext_v3
20170
21d799b5 20171 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20172 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20173 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20174 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20175 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20176 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20177 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20178 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20179 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20180
74db7efb
NC
20181#undef ARM_VARIANT
20182#define ARM_VARIANT & fpu_vfp_ext_fma
20183#undef THUMB_VARIANT
20184#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20185 /* Mnemonics shared by Neon and VFP. These are included in the
20186 VFP FMA variant; NEON and VFP FMA always includes the NEON
20187 FMA instructions. */
20188 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20189 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20190 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20191 the v form should always be used. */
20192 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20193 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20194 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20195 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20196 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20197 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20198
5287ad62 20199#undef THUMB_VARIANT
c921be7d
NC
20200#undef ARM_VARIANT
20201#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20202
21d799b5
NC
20203 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20204 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20205 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20206 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20207 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20208 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20209 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20210 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20211
c921be7d
NC
20212#undef ARM_VARIANT
20213#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20214
21d799b5
NC
20215 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20216 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20217 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20218 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20219 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20220 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20221 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20222 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20223 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20224 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20225 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20226 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20227 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20228 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20229 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20230 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20231 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20232 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20233 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20234 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20235 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20236 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20237 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20238 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20239 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20240 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20241 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20242 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20243 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20244 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20245 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20246 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20247 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20248 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20249 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20250 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20251 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20252 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20253 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20254 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20255 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20256 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20257 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20258 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20259 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20260 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20261 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
20262 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20263 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20264 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20265 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20266 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20267 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20268 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20269 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20270 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20271 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20272 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20273 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20274 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20275 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20276 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20277 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20278 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20279 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20280 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20281 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20282 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20283 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20284 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20285 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20286 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20287 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20288 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20289 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20290 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20291 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20292 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20293 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20294 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20295 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20296 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20297 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20298 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20299 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20300 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20301 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20302 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20303 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20304 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20305 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20306 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20307 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20308 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20309 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20310 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20311 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20312 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20313 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20314 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20315 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20316 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20317 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20318 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20319 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20320 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20321 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20322 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20323 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20324 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20325 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20326 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20327 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20328 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20329 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20330 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20331 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20332 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20333 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20334 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20335 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20336 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20337 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20338 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20339 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20340 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20341 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20342 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20343 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20344 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20345 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20346 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20347 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20348 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20349 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20350 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20351 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20352 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20353 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20354 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20355 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20356 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20357 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
20358 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
20359 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
20360 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
20361 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
20362 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
20363 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20364 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20365 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20366 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
20367 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
20368 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
20369 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
20370 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
20371 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
20372 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20373 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20374 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20375 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20376 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 20377
c921be7d
NC
20378#undef ARM_VARIANT
20379#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
20380
21d799b5
NC
20381 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
20382 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
20383 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
20384 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
20385 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
20386 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
20387 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20388 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20389 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20390 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20391 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20392 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20393 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20394 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20395 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20396 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20397 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20398 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20399 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20400 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20401 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
20402 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20403 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20404 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20405 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20406 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20407 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20408 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20409 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20410 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20411 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20412 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20413 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20414 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20415 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20416 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20417 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20418 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20419 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20420 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20421 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20422 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20423 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20424 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20425 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20426 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20427 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20428 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20429 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20430 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20431 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20432 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20433 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20434 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20435 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20436 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20437 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 20438
c921be7d
NC
20439#undef ARM_VARIANT
20440#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
20441
21d799b5
NC
20442 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20443 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20444 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20445 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20446 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20447 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20448 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20449 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20450 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
20451 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
20452 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
20453 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
20454 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
20455 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
20456 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
20457 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
20458 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
20459 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
20460 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
20461 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
20462 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
20463 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
20464 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
20465 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
20466 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
20467 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
20468 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
20469 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
20470 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
20471 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
20472 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
20473 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
20474 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
20475 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
20476 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
20477 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
20478 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
20479 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
20480 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
20481 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
20482 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
20483 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
20484 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
20485 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
20486 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
20487 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
20488 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
20489 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
20490 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
20491 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
20492 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
20493 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
20494 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
20495 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
20496 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
20497 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
20498 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
20499 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
20500 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
20501 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
20502 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
20503 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
20504 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
20505 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
20506 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20507 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20508 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20509 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20510 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20511 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20512 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20513 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
20514 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
20515 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
20516 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
20517 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d
TP
20518
20519#undef ARM_VARIANT
20520#define ARM_VARIANT NULL
20521#undef THUMB_VARIANT
20522#define THUMB_VARIANT & arm_ext_v8m
20523 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
20524 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
c19d1205
ZW
20525};
20526#undef ARM_VARIANT
20527#undef THUMB_VARIANT
20528#undef TCE
c19d1205
ZW
20529#undef TUE
20530#undef TUF
20531#undef TCC
8f06b2d8 20532#undef cCE
e3cb604e
PB
20533#undef cCL
20534#undef C3E
c19d1205
ZW
20535#undef CE
20536#undef CM
20537#undef UE
20538#undef UF
20539#undef UT
5287ad62
JB
20540#undef NUF
20541#undef nUF
20542#undef NCE
20543#undef nCE
c19d1205
ZW
20544#undef OPS0
20545#undef OPS1
20546#undef OPS2
20547#undef OPS3
20548#undef OPS4
20549#undef OPS5
20550#undef OPS6
20551#undef do_0
20552\f
20553/* MD interface: bits in the object file. */
bfae80f2 20554
c19d1205
ZW
20555/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
20556 for use in the a.out file, and stores them in the array pointed to by buf.
20557 This knows about the endian-ness of the target machine and does
20558 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
20559 2 (short) and 4 (long) Floating numbers are put out as a series of
20560 LITTLENUMS (shorts, here at least). */
b99bd4ef 20561
c19d1205
ZW
20562void
20563md_number_to_chars (char * buf, valueT val, int n)
20564{
20565 if (target_big_endian)
20566 number_to_chars_bigendian (buf, val, n);
20567 else
20568 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
20569}
20570
c19d1205
ZW
20571static valueT
20572md_chars_to_number (char * buf, int n)
bfae80f2 20573{
c19d1205
ZW
20574 valueT result = 0;
20575 unsigned char * where = (unsigned char *) buf;
bfae80f2 20576
c19d1205 20577 if (target_big_endian)
b99bd4ef 20578 {
c19d1205
ZW
20579 while (n--)
20580 {
20581 result <<= 8;
20582 result |= (*where++ & 255);
20583 }
b99bd4ef 20584 }
c19d1205 20585 else
b99bd4ef 20586 {
c19d1205
ZW
20587 while (n--)
20588 {
20589 result <<= 8;
20590 result |= (where[n] & 255);
20591 }
bfae80f2 20592 }
b99bd4ef 20593
c19d1205 20594 return result;
bfae80f2 20595}
b99bd4ef 20596
c19d1205 20597/* MD interface: Sections. */
b99bd4ef 20598
fa94de6b
RM
20599/* Calculate the maximum variable size (i.e., excluding fr_fix)
20600 that an rs_machine_dependent frag may reach. */
20601
20602unsigned int
20603arm_frag_max_var (fragS *fragp)
20604{
20605 /* We only use rs_machine_dependent for variable-size Thumb instructions,
20606 which are either THUMB_SIZE (2) or INSN_SIZE (4).
20607
20608 Note that we generate relaxable instructions even for cases that don't
20609 really need it, like an immediate that's a trivial constant. So we're
20610 overestimating the instruction size for some of those cases. Rather
20611 than putting more intelligence here, it would probably be better to
20612 avoid generating a relaxation frag in the first place when it can be
20613 determined up front that a short instruction will suffice. */
20614
20615 gas_assert (fragp->fr_type == rs_machine_dependent);
20616 return INSN_SIZE;
20617}
20618
0110f2b8
PB
20619/* Estimate the size of a frag before relaxing. Assume everything fits in
20620 2 bytes. */
20621
c19d1205 20622int
0110f2b8 20623md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
20624 segT segtype ATTRIBUTE_UNUSED)
20625{
0110f2b8
PB
20626 fragp->fr_var = 2;
20627 return 2;
20628}
20629
20630/* Convert a machine dependent frag. */
20631
20632void
20633md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
20634{
20635 unsigned long insn;
20636 unsigned long old_op;
20637 char *buf;
20638 expressionS exp;
20639 fixS *fixp;
20640 int reloc_type;
20641 int pc_rel;
20642 int opcode;
20643
20644 buf = fragp->fr_literal + fragp->fr_fix;
20645
20646 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
20647 if (fragp->fr_symbol)
20648 {
0110f2b8
PB
20649 exp.X_op = O_symbol;
20650 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
20651 }
20652 else
20653 {
0110f2b8 20654 exp.X_op = O_constant;
5f4273c7 20655 }
0110f2b8
PB
20656 exp.X_add_number = fragp->fr_offset;
20657 opcode = fragp->fr_subtype;
20658 switch (opcode)
20659 {
20660 case T_MNEM_ldr_pc:
20661 case T_MNEM_ldr_pc2:
20662 case T_MNEM_ldr_sp:
20663 case T_MNEM_str_sp:
20664 case T_MNEM_ldr:
20665 case T_MNEM_ldrb:
20666 case T_MNEM_ldrh:
20667 case T_MNEM_str:
20668 case T_MNEM_strb:
20669 case T_MNEM_strh:
20670 if (fragp->fr_var == 4)
20671 {
5f4273c7 20672 insn = THUMB_OP32 (opcode);
0110f2b8
PB
20673 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
20674 {
20675 insn |= (old_op & 0x700) << 4;
20676 }
20677 else
20678 {
20679 insn |= (old_op & 7) << 12;
20680 insn |= (old_op & 0x38) << 13;
20681 }
20682 insn |= 0x00000c00;
20683 put_thumb32_insn (buf, insn);
20684 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
20685 }
20686 else
20687 {
20688 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
20689 }
20690 pc_rel = (opcode == T_MNEM_ldr_pc2);
20691 break;
20692 case T_MNEM_adr:
20693 if (fragp->fr_var == 4)
20694 {
20695 insn = THUMB_OP32 (opcode);
20696 insn |= (old_op & 0xf0) << 4;
20697 put_thumb32_insn (buf, insn);
20698 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
20699 }
20700 else
20701 {
20702 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20703 exp.X_add_number -= 4;
20704 }
20705 pc_rel = 1;
20706 break;
20707 case T_MNEM_mov:
20708 case T_MNEM_movs:
20709 case T_MNEM_cmp:
20710 case T_MNEM_cmn:
20711 if (fragp->fr_var == 4)
20712 {
20713 int r0off = (opcode == T_MNEM_mov
20714 || opcode == T_MNEM_movs) ? 0 : 8;
20715 insn = THUMB_OP32 (opcode);
20716 insn = (insn & 0xe1ffffff) | 0x10000000;
20717 insn |= (old_op & 0x700) << r0off;
20718 put_thumb32_insn (buf, insn);
20719 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
20720 }
20721 else
20722 {
20723 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
20724 }
20725 pc_rel = 0;
20726 break;
20727 case T_MNEM_b:
20728 if (fragp->fr_var == 4)
20729 {
20730 insn = THUMB_OP32(opcode);
20731 put_thumb32_insn (buf, insn);
20732 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
20733 }
20734 else
20735 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
20736 pc_rel = 1;
20737 break;
20738 case T_MNEM_bcond:
20739 if (fragp->fr_var == 4)
20740 {
20741 insn = THUMB_OP32(opcode);
20742 insn |= (old_op & 0xf00) << 14;
20743 put_thumb32_insn (buf, insn);
20744 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
20745 }
20746 else
20747 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
20748 pc_rel = 1;
20749 break;
20750 case T_MNEM_add_sp:
20751 case T_MNEM_add_pc:
20752 case T_MNEM_inc_sp:
20753 case T_MNEM_dec_sp:
20754 if (fragp->fr_var == 4)
20755 {
20756 /* ??? Choose between add and addw. */
20757 insn = THUMB_OP32 (opcode);
20758 insn |= (old_op & 0xf0) << 4;
20759 put_thumb32_insn (buf, insn);
16805f35
PB
20760 if (opcode == T_MNEM_add_pc)
20761 reloc_type = BFD_RELOC_ARM_T32_IMM12;
20762 else
20763 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
20764 }
20765 else
20766 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20767 pc_rel = 0;
20768 break;
20769
20770 case T_MNEM_addi:
20771 case T_MNEM_addis:
20772 case T_MNEM_subi:
20773 case T_MNEM_subis:
20774 if (fragp->fr_var == 4)
20775 {
20776 insn = THUMB_OP32 (opcode);
20777 insn |= (old_op & 0xf0) << 4;
20778 insn |= (old_op & 0xf) << 16;
20779 put_thumb32_insn (buf, insn);
16805f35
PB
20780 if (insn & (1 << 20))
20781 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
20782 else
20783 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
20784 }
20785 else
20786 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20787 pc_rel = 0;
20788 break;
20789 default:
5f4273c7 20790 abort ();
0110f2b8
PB
20791 }
20792 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 20793 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
20794 fixp->fx_file = fragp->fr_file;
20795 fixp->fx_line = fragp->fr_line;
20796 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
20797
20798 /* Set whether we use thumb-2 ISA based on final relaxation results. */
20799 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
20800 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
20801 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
20802}
20803
20804/* Return the size of a relaxable immediate operand instruction.
20805 SHIFT and SIZE specify the form of the allowable immediate. */
20806static int
20807relax_immediate (fragS *fragp, int size, int shift)
20808{
20809 offsetT offset;
20810 offsetT mask;
20811 offsetT low;
20812
20813 /* ??? Should be able to do better than this. */
20814 if (fragp->fr_symbol)
20815 return 4;
20816
20817 low = (1 << shift) - 1;
20818 mask = (1 << (shift + size)) - (1 << shift);
20819 offset = fragp->fr_offset;
20820 /* Force misaligned offsets to 32-bit variant. */
20821 if (offset & low)
5e77afaa 20822 return 4;
0110f2b8
PB
20823 if (offset & ~mask)
20824 return 4;
20825 return 2;
20826}
20827
5e77afaa
PB
20828/* Get the address of a symbol during relaxation. */
20829static addressT
5f4273c7 20830relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
20831{
20832 fragS *sym_frag;
20833 addressT addr;
20834 symbolS *sym;
20835
20836 sym = fragp->fr_symbol;
20837 sym_frag = symbol_get_frag (sym);
20838 know (S_GET_SEGMENT (sym) != absolute_section
20839 || sym_frag == &zero_address_frag);
20840 addr = S_GET_VALUE (sym) + fragp->fr_offset;
20841
20842 /* If frag has yet to be reached on this pass, assume it will
20843 move by STRETCH just as we did. If this is not so, it will
20844 be because some frag between grows, and that will force
20845 another pass. */
20846
20847 if (stretch != 0
20848 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
20849 {
20850 fragS *f;
20851
20852 /* Adjust stretch for any alignment frag. Note that if have
20853 been expanding the earlier code, the symbol may be
20854 defined in what appears to be an earlier frag. FIXME:
20855 This doesn't handle the fr_subtype field, which specifies
20856 a maximum number of bytes to skip when doing an
20857 alignment. */
20858 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
20859 {
20860 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
20861 {
20862 if (stretch < 0)
20863 stretch = - ((- stretch)
20864 & ~ ((1 << (int) f->fr_offset) - 1));
20865 else
20866 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
20867 if (stretch == 0)
20868 break;
20869 }
20870 }
20871 if (f != NULL)
20872 addr += stretch;
20873 }
5e77afaa
PB
20874
20875 return addr;
20876}
20877
0110f2b8
PB
20878/* Return the size of a relaxable adr pseudo-instruction or PC-relative
20879 load. */
20880static int
5e77afaa 20881relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
20882{
20883 addressT addr;
20884 offsetT val;
20885
20886 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
20887 if (fragp->fr_symbol == NULL
20888 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
20889 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20890 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
20891 return 4;
20892
5f4273c7 20893 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
20894 addr = fragp->fr_address + fragp->fr_fix;
20895 addr = (addr + 4) & ~3;
5e77afaa 20896 /* Force misaligned targets to 32-bit variant. */
0110f2b8 20897 if (val & 3)
5e77afaa 20898 return 4;
0110f2b8
PB
20899 val -= addr;
20900 if (val < 0 || val > 1020)
20901 return 4;
20902 return 2;
20903}
20904
20905/* Return the size of a relaxable add/sub immediate instruction. */
20906static int
20907relax_addsub (fragS *fragp, asection *sec)
20908{
20909 char *buf;
20910 int op;
20911
20912 buf = fragp->fr_literal + fragp->fr_fix;
20913 op = bfd_get_16(sec->owner, buf);
20914 if ((op & 0xf) == ((op >> 4) & 0xf))
20915 return relax_immediate (fragp, 8, 0);
20916 else
20917 return relax_immediate (fragp, 3, 0);
20918}
20919
e83a675f
RE
20920/* Return TRUE iff the definition of symbol S could be pre-empted
20921 (overridden) at link or load time. */
20922static bfd_boolean
20923symbol_preemptible (symbolS *s)
20924{
20925 /* Weak symbols can always be pre-empted. */
20926 if (S_IS_WEAK (s))
20927 return TRUE;
20928
20929 /* Non-global symbols cannot be pre-empted. */
20930 if (! S_IS_EXTERNAL (s))
20931 return FALSE;
20932
20933#ifdef OBJ_ELF
20934 /* In ELF, a global symbol can be marked protected, or private. In that
20935 case it can't be pre-empted (other definitions in the same link unit
20936 would violate the ODR). */
20937 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
20938 return FALSE;
20939#endif
20940
20941 /* Other global symbols might be pre-empted. */
20942 return TRUE;
20943}
0110f2b8
PB
20944
20945/* Return the size of a relaxable branch instruction. BITS is the
20946 size of the offset field in the narrow instruction. */
20947
20948static int
5e77afaa 20949relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
20950{
20951 addressT addr;
20952 offsetT val;
20953 offsetT limit;
20954
20955 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 20956 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
20957 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20958 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
20959 return 4;
20960
267bf995 20961#ifdef OBJ_ELF
e83a675f 20962 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
20963 if (S_IS_DEFINED (fragp->fr_symbol)
20964 && ARM_IS_FUNC (fragp->fr_symbol))
20965 return 4;
e83a675f 20966#endif
0d9b4b55 20967
e83a675f 20968 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 20969 return 4;
267bf995 20970
5f4273c7 20971 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
20972 addr = fragp->fr_address + fragp->fr_fix + 4;
20973 val -= addr;
20974
20975 /* Offset is a signed value *2 */
20976 limit = 1 << bits;
20977 if (val >= limit || val < -limit)
20978 return 4;
20979 return 2;
20980}
20981
20982
20983/* Relax a machine dependent frag. This returns the amount by which
20984 the current size of the frag should change. */
20985
20986int
5e77afaa 20987arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
20988{
20989 int oldsize;
20990 int newsize;
20991
20992 oldsize = fragp->fr_var;
20993 switch (fragp->fr_subtype)
20994 {
20995 case T_MNEM_ldr_pc2:
5f4273c7 20996 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
20997 break;
20998 case T_MNEM_ldr_pc:
20999 case T_MNEM_ldr_sp:
21000 case T_MNEM_str_sp:
5f4273c7 21001 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21002 break;
21003 case T_MNEM_ldr:
21004 case T_MNEM_str:
5f4273c7 21005 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21006 break;
21007 case T_MNEM_ldrh:
21008 case T_MNEM_strh:
5f4273c7 21009 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21010 break;
21011 case T_MNEM_ldrb:
21012 case T_MNEM_strb:
5f4273c7 21013 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21014 break;
21015 case T_MNEM_adr:
5f4273c7 21016 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21017 break;
21018 case T_MNEM_mov:
21019 case T_MNEM_movs:
21020 case T_MNEM_cmp:
21021 case T_MNEM_cmn:
5f4273c7 21022 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21023 break;
21024 case T_MNEM_b:
5f4273c7 21025 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21026 break;
21027 case T_MNEM_bcond:
5f4273c7 21028 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21029 break;
21030 case T_MNEM_add_sp:
21031 case T_MNEM_add_pc:
21032 newsize = relax_immediate (fragp, 8, 2);
21033 break;
21034 case T_MNEM_inc_sp:
21035 case T_MNEM_dec_sp:
21036 newsize = relax_immediate (fragp, 7, 2);
21037 break;
21038 case T_MNEM_addi:
21039 case T_MNEM_addis:
21040 case T_MNEM_subi:
21041 case T_MNEM_subis:
21042 newsize = relax_addsub (fragp, sec);
21043 break;
21044 default:
5f4273c7 21045 abort ();
0110f2b8 21046 }
5e77afaa
PB
21047
21048 fragp->fr_var = newsize;
21049 /* Freeze wide instructions that are at or before the same location as
21050 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21051 Don't freeze them unconditionally because targets may be artificially
21052 misaligned by the expansion of preceding frags. */
5e77afaa 21053 if (stretch <= 0 && newsize > 2)
0110f2b8 21054 {
0110f2b8 21055 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21056 frag_wane (fragp);
0110f2b8 21057 }
5e77afaa 21058
0110f2b8 21059 return newsize - oldsize;
c19d1205 21060}
b99bd4ef 21061
c19d1205 21062/* Round up a section size to the appropriate boundary. */
b99bd4ef 21063
c19d1205
ZW
21064valueT
21065md_section_align (segT segment ATTRIBUTE_UNUSED,
21066 valueT size)
21067{
f0927246
NC
21068#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21069 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21070 {
21071 /* For a.out, force the section size to be aligned. If we don't do
21072 this, BFD will align it for us, but it will not write out the
21073 final bytes of the section. This may be a bug in BFD, but it is
21074 easier to fix it here since that is how the other a.out targets
21075 work. */
21076 int align;
21077
21078 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21079 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 21080 }
c19d1205 21081#endif
f0927246
NC
21082
21083 return size;
bfae80f2 21084}
b99bd4ef 21085
c19d1205
ZW
21086/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21087 of an rs_align_code fragment. */
21088
21089void
21090arm_handle_align (fragS * fragP)
bfae80f2 21091{
e7495e45
NS
21092 static char const arm_noop[2][2][4] =
21093 {
21094 { /* ARMv1 */
21095 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21096 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21097 },
21098 { /* ARMv6k */
21099 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21100 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21101 },
21102 };
21103 static char const thumb_noop[2][2][2] =
21104 {
21105 { /* Thumb-1 */
21106 {0xc0, 0x46}, /* LE */
21107 {0x46, 0xc0}, /* BE */
21108 },
21109 { /* Thumb-2 */
21110 {0x00, 0xbf}, /* LE */
21111 {0xbf, 0x00} /* BE */
21112 }
21113 };
21114 static char const wide_thumb_noop[2][4] =
21115 { /* Wide Thumb-2 */
21116 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21117 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21118 };
c921be7d 21119
e7495e45 21120 unsigned bytes, fix, noop_size;
c19d1205
ZW
21121 char * p;
21122 const char * noop;
e7495e45 21123 const char *narrow_noop = NULL;
cd000bff
DJ
21124#ifdef OBJ_ELF
21125 enum mstate state;
21126#endif
bfae80f2 21127
c19d1205 21128 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21129 return;
21130
c19d1205
ZW
21131 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21132 p = fragP->fr_literal + fragP->fr_fix;
21133 fix = 0;
bfae80f2 21134
c19d1205
ZW
21135 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21136 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21137
cd000bff 21138 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21139
cd000bff 21140 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21141 {
7f78eb34
JW
21142 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21143 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21144 {
21145 narrow_noop = thumb_noop[1][target_big_endian];
21146 noop = wide_thumb_noop[target_big_endian];
21147 }
c19d1205 21148 else
e7495e45
NS
21149 noop = thumb_noop[0][target_big_endian];
21150 noop_size = 2;
cd000bff
DJ
21151#ifdef OBJ_ELF
21152 state = MAP_THUMB;
21153#endif
7ed4c4c5
NC
21154 }
21155 else
21156 {
7f78eb34
JW
21157 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21158 ? selected_cpu : arm_arch_none,
21159 arm_ext_v6k) != 0]
e7495e45
NS
21160 [target_big_endian];
21161 noop_size = 4;
cd000bff
DJ
21162#ifdef OBJ_ELF
21163 state = MAP_ARM;
21164#endif
7ed4c4c5 21165 }
c921be7d 21166
e7495e45 21167 fragP->fr_var = noop_size;
c921be7d 21168
c19d1205 21169 if (bytes & (noop_size - 1))
7ed4c4c5 21170 {
c19d1205 21171 fix = bytes & (noop_size - 1);
cd000bff
DJ
21172#ifdef OBJ_ELF
21173 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21174#endif
c19d1205
ZW
21175 memset (p, 0, fix);
21176 p += fix;
21177 bytes -= fix;
a737bd4d 21178 }
a737bd4d 21179
e7495e45
NS
21180 if (narrow_noop)
21181 {
21182 if (bytes & noop_size)
21183 {
21184 /* Insert a narrow noop. */
21185 memcpy (p, narrow_noop, noop_size);
21186 p += noop_size;
21187 bytes -= noop_size;
21188 fix += noop_size;
21189 }
21190
21191 /* Use wide noops for the remainder */
21192 noop_size = 4;
21193 }
21194
c19d1205 21195 while (bytes >= noop_size)
a737bd4d 21196 {
c19d1205
ZW
21197 memcpy (p, noop, noop_size);
21198 p += noop_size;
21199 bytes -= noop_size;
21200 fix += noop_size;
a737bd4d
NC
21201 }
21202
c19d1205 21203 fragP->fr_fix += fix;
a737bd4d
NC
21204}
21205
c19d1205
ZW
21206/* Called from md_do_align. Used to create an alignment
21207 frag in a code section. */
21208
21209void
21210arm_frag_align_code (int n, int max)
bfae80f2 21211{
c19d1205 21212 char * p;
7ed4c4c5 21213
c19d1205 21214 /* We assume that there will never be a requirement
6ec8e702 21215 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21216 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21217 {
21218 char err_msg[128];
21219
fa94de6b 21220 sprintf (err_msg,
477330fc
RM
21221 _("alignments greater than %d bytes not supported in .text sections."),
21222 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21223 as_fatal ("%s", err_msg);
6ec8e702 21224 }
bfae80f2 21225
c19d1205
ZW
21226 p = frag_var (rs_align_code,
21227 MAX_MEM_FOR_RS_ALIGN_CODE,
21228 1,
21229 (relax_substateT) max,
21230 (symbolS *) NULL,
21231 (offsetT) n,
21232 (char *) NULL);
21233 *p = 0;
21234}
bfae80f2 21235
8dc2430f
NC
21236/* Perform target specific initialisation of a frag.
21237 Note - despite the name this initialisation is not done when the frag
21238 is created, but only when its type is assigned. A frag can be created
21239 and used a long time before its type is set, so beware of assuming that
21240 this initialisationis performed first. */
bfae80f2 21241
cd000bff
DJ
21242#ifndef OBJ_ELF
21243void
21244arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21245{
21246 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21247 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
21248}
21249
21250#else /* OBJ_ELF is defined. */
c19d1205 21251void
cd000bff 21252arm_init_frag (fragS * fragP, int max_chars)
c19d1205 21253{
b968d18a
JW
21254 int frag_thumb_mode;
21255
8dc2430f
NC
21256 /* If the current ARM vs THUMB mode has not already
21257 been recorded into this frag then do so now. */
cd000bff 21258 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
21259 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21260
21261 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 21262
f9c1b181
RL
21263 /* Record a mapping symbol for alignment frags. We will delete this
21264 later if the alignment ends up empty. */
21265 switch (fragP->fr_type)
21266 {
21267 case rs_align:
21268 case rs_align_test:
21269 case rs_fill:
21270 mapping_state_2 (MAP_DATA, max_chars);
21271 break;
21272 case rs_align_code:
b968d18a 21273 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
21274 break;
21275 default:
21276 break;
cd000bff 21277 }
bfae80f2
RE
21278}
21279
c19d1205
ZW
21280/* When we change sections we need to issue a new mapping symbol. */
21281
21282void
21283arm_elf_change_section (void)
bfae80f2 21284{
c19d1205
ZW
21285 /* Link an unlinked unwind index table section to the .text section. */
21286 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21287 && elf_linked_to_section (now_seg) == NULL)
21288 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
21289}
21290
c19d1205
ZW
21291int
21292arm_elf_section_type (const char * str, size_t len)
e45d0630 21293{
c19d1205
ZW
21294 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21295 return SHT_ARM_EXIDX;
e45d0630 21296
c19d1205
ZW
21297 return -1;
21298}
21299\f
21300/* Code to deal with unwinding tables. */
e45d0630 21301
c19d1205 21302static void add_unwind_adjustsp (offsetT);
e45d0630 21303
5f4273c7 21304/* Generate any deferred unwind frame offset. */
e45d0630 21305
bfae80f2 21306static void
c19d1205 21307flush_pending_unwind (void)
bfae80f2 21308{
c19d1205 21309 offsetT offset;
bfae80f2 21310
c19d1205
ZW
21311 offset = unwind.pending_offset;
21312 unwind.pending_offset = 0;
21313 if (offset != 0)
21314 add_unwind_adjustsp (offset);
bfae80f2
RE
21315}
21316
c19d1205
ZW
21317/* Add an opcode to this list for this function. Two-byte opcodes should
21318 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21319 order. */
21320
bfae80f2 21321static void
c19d1205 21322add_unwind_opcode (valueT op, int length)
bfae80f2 21323{
c19d1205
ZW
21324 /* Add any deferred stack adjustment. */
21325 if (unwind.pending_offset)
21326 flush_pending_unwind ();
bfae80f2 21327
c19d1205 21328 unwind.sp_restored = 0;
bfae80f2 21329
c19d1205 21330 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 21331 {
c19d1205
ZW
21332 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21333 if (unwind.opcodes)
21d799b5 21334 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
477330fc 21335 unwind.opcode_alloc);
c19d1205 21336 else
21d799b5 21337 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 21338 }
c19d1205 21339 while (length > 0)
bfae80f2 21340 {
c19d1205
ZW
21341 length--;
21342 unwind.opcodes[unwind.opcode_count] = op & 0xff;
21343 op >>= 8;
21344 unwind.opcode_count++;
bfae80f2 21345 }
bfae80f2
RE
21346}
21347
c19d1205
ZW
21348/* Add unwind opcodes to adjust the stack pointer. */
21349
bfae80f2 21350static void
c19d1205 21351add_unwind_adjustsp (offsetT offset)
bfae80f2 21352{
c19d1205 21353 valueT op;
bfae80f2 21354
c19d1205 21355 if (offset > 0x200)
bfae80f2 21356 {
c19d1205
ZW
21357 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
21358 char bytes[5];
21359 int n;
21360 valueT o;
bfae80f2 21361
c19d1205
ZW
21362 /* Long form: 0xb2, uleb128. */
21363 /* This might not fit in a word so add the individual bytes,
21364 remembering the list is built in reverse order. */
21365 o = (valueT) ((offset - 0x204) >> 2);
21366 if (o == 0)
21367 add_unwind_opcode (0, 1);
bfae80f2 21368
c19d1205
ZW
21369 /* Calculate the uleb128 encoding of the offset. */
21370 n = 0;
21371 while (o)
21372 {
21373 bytes[n] = o & 0x7f;
21374 o >>= 7;
21375 if (o)
21376 bytes[n] |= 0x80;
21377 n++;
21378 }
21379 /* Add the insn. */
21380 for (; n; n--)
21381 add_unwind_opcode (bytes[n - 1], 1);
21382 add_unwind_opcode (0xb2, 1);
21383 }
21384 else if (offset > 0x100)
bfae80f2 21385 {
c19d1205
ZW
21386 /* Two short opcodes. */
21387 add_unwind_opcode (0x3f, 1);
21388 op = (offset - 0x104) >> 2;
21389 add_unwind_opcode (op, 1);
bfae80f2 21390 }
c19d1205
ZW
21391 else if (offset > 0)
21392 {
21393 /* Short opcode. */
21394 op = (offset - 4) >> 2;
21395 add_unwind_opcode (op, 1);
21396 }
21397 else if (offset < 0)
bfae80f2 21398 {
c19d1205
ZW
21399 offset = -offset;
21400 while (offset > 0x100)
bfae80f2 21401 {
c19d1205
ZW
21402 add_unwind_opcode (0x7f, 1);
21403 offset -= 0x100;
bfae80f2 21404 }
c19d1205
ZW
21405 op = ((offset - 4) >> 2) | 0x40;
21406 add_unwind_opcode (op, 1);
bfae80f2 21407 }
bfae80f2
RE
21408}
21409
c19d1205
ZW
21410/* Finish the list of unwind opcodes for this function. */
21411static void
21412finish_unwind_opcodes (void)
bfae80f2 21413{
c19d1205 21414 valueT op;
bfae80f2 21415
c19d1205 21416 if (unwind.fp_used)
bfae80f2 21417 {
708587a4 21418 /* Adjust sp as necessary. */
c19d1205
ZW
21419 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
21420 flush_pending_unwind ();
bfae80f2 21421
c19d1205
ZW
21422 /* After restoring sp from the frame pointer. */
21423 op = 0x90 | unwind.fp_reg;
21424 add_unwind_opcode (op, 1);
21425 }
21426 else
21427 flush_pending_unwind ();
bfae80f2
RE
21428}
21429
bfae80f2 21430
c19d1205
ZW
21431/* Start an exception table entry. If idx is nonzero this is an index table
21432 entry. */
bfae80f2
RE
21433
21434static void
c19d1205 21435start_unwind_section (const segT text_seg, int idx)
bfae80f2 21436{
c19d1205
ZW
21437 const char * text_name;
21438 const char * prefix;
21439 const char * prefix_once;
21440 const char * group_name;
21441 size_t prefix_len;
21442 size_t text_len;
21443 char * sec_name;
21444 size_t sec_name_len;
21445 int type;
21446 int flags;
21447 int linkonce;
bfae80f2 21448
c19d1205 21449 if (idx)
bfae80f2 21450 {
c19d1205
ZW
21451 prefix = ELF_STRING_ARM_unwind;
21452 prefix_once = ELF_STRING_ARM_unwind_once;
21453 type = SHT_ARM_EXIDX;
bfae80f2 21454 }
c19d1205 21455 else
bfae80f2 21456 {
c19d1205
ZW
21457 prefix = ELF_STRING_ARM_unwind_info;
21458 prefix_once = ELF_STRING_ARM_unwind_info_once;
21459 type = SHT_PROGBITS;
bfae80f2
RE
21460 }
21461
c19d1205
ZW
21462 text_name = segment_name (text_seg);
21463 if (streq (text_name, ".text"))
21464 text_name = "";
21465
21466 if (strncmp (text_name, ".gnu.linkonce.t.",
21467 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 21468 {
c19d1205
ZW
21469 prefix = prefix_once;
21470 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
21471 }
21472
c19d1205
ZW
21473 prefix_len = strlen (prefix);
21474 text_len = strlen (text_name);
21475 sec_name_len = prefix_len + text_len;
21d799b5 21476 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
21477 memcpy (sec_name, prefix, prefix_len);
21478 memcpy (sec_name + prefix_len, text_name, text_len);
21479 sec_name[prefix_len + text_len] = '\0';
bfae80f2 21480
c19d1205
ZW
21481 flags = SHF_ALLOC;
21482 linkonce = 0;
21483 group_name = 0;
bfae80f2 21484
c19d1205
ZW
21485 /* Handle COMDAT group. */
21486 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 21487 {
c19d1205
ZW
21488 group_name = elf_group_name (text_seg);
21489 if (group_name == NULL)
21490 {
bd3ba5d1 21491 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
21492 segment_name (text_seg));
21493 ignore_rest_of_line ();
21494 return;
21495 }
21496 flags |= SHF_GROUP;
21497 linkonce = 1;
bfae80f2
RE
21498 }
21499
c19d1205 21500 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 21501
5f4273c7 21502 /* Set the section link for index tables. */
c19d1205
ZW
21503 if (idx)
21504 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
21505}
21506
bfae80f2 21507
c19d1205
ZW
21508/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
21509 personality routine data. Returns zero, or the index table value for
cad0da33 21510 an inline entry. */
c19d1205
ZW
21511
21512static valueT
21513create_unwind_entry (int have_data)
bfae80f2 21514{
c19d1205
ZW
21515 int size;
21516 addressT where;
21517 char *ptr;
21518 /* The current word of data. */
21519 valueT data;
21520 /* The number of bytes left in this word. */
21521 int n;
bfae80f2 21522
c19d1205 21523 finish_unwind_opcodes ();
bfae80f2 21524
c19d1205
ZW
21525 /* Remember the current text section. */
21526 unwind.saved_seg = now_seg;
21527 unwind.saved_subseg = now_subseg;
bfae80f2 21528
c19d1205 21529 start_unwind_section (now_seg, 0);
bfae80f2 21530
c19d1205 21531 if (unwind.personality_routine == NULL)
bfae80f2 21532 {
c19d1205
ZW
21533 if (unwind.personality_index == -2)
21534 {
21535 if (have_data)
5f4273c7 21536 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
21537 return 1; /* EXIDX_CANTUNWIND. */
21538 }
bfae80f2 21539
c19d1205
ZW
21540 /* Use a default personality routine if none is specified. */
21541 if (unwind.personality_index == -1)
21542 {
21543 if (unwind.opcode_count > 3)
21544 unwind.personality_index = 1;
21545 else
21546 unwind.personality_index = 0;
21547 }
bfae80f2 21548
c19d1205
ZW
21549 /* Space for the personality routine entry. */
21550 if (unwind.personality_index == 0)
21551 {
21552 if (unwind.opcode_count > 3)
21553 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 21554
c19d1205
ZW
21555 if (!have_data)
21556 {
21557 /* All the data is inline in the index table. */
21558 data = 0x80;
21559 n = 3;
21560 while (unwind.opcode_count > 0)
21561 {
21562 unwind.opcode_count--;
21563 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21564 n--;
21565 }
bfae80f2 21566
c19d1205
ZW
21567 /* Pad with "finish" opcodes. */
21568 while (n--)
21569 data = (data << 8) | 0xb0;
bfae80f2 21570
c19d1205
ZW
21571 return data;
21572 }
21573 size = 0;
21574 }
21575 else
21576 /* We get two opcodes "free" in the first word. */
21577 size = unwind.opcode_count - 2;
21578 }
21579 else
5011093d 21580 {
cad0da33
NC
21581 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
21582 if (unwind.personality_index != -1)
21583 {
21584 as_bad (_("attempt to recreate an unwind entry"));
21585 return 1;
21586 }
5011093d
NC
21587
21588 /* An extra byte is required for the opcode count. */
21589 size = unwind.opcode_count + 1;
21590 }
bfae80f2 21591
c19d1205
ZW
21592 size = (size + 3) >> 2;
21593 if (size > 0xff)
21594 as_bad (_("too many unwind opcodes"));
bfae80f2 21595
c19d1205
ZW
21596 frag_align (2, 0, 0);
21597 record_alignment (now_seg, 2);
21598 unwind.table_entry = expr_build_dot ();
21599
21600 /* Allocate the table entry. */
21601 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
21602 /* PR 13449: Zero the table entries in case some of them are not used. */
21603 memset (ptr, 0, (size << 2) + 4);
c19d1205 21604 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 21605
c19d1205 21606 switch (unwind.personality_index)
bfae80f2 21607 {
c19d1205
ZW
21608 case -1:
21609 /* ??? Should this be a PLT generating relocation? */
21610 /* Custom personality routine. */
21611 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
21612 BFD_RELOC_ARM_PREL31);
bfae80f2 21613
c19d1205
ZW
21614 where += 4;
21615 ptr += 4;
bfae80f2 21616
c19d1205 21617 /* Set the first byte to the number of additional words. */
5011093d 21618 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
21619 n = 3;
21620 break;
bfae80f2 21621
c19d1205
ZW
21622 /* ABI defined personality routines. */
21623 case 0:
21624 /* Three opcodes bytes are packed into the first word. */
21625 data = 0x80;
21626 n = 3;
21627 break;
bfae80f2 21628
c19d1205
ZW
21629 case 1:
21630 case 2:
21631 /* The size and first two opcode bytes go in the first word. */
21632 data = ((0x80 + unwind.personality_index) << 8) | size;
21633 n = 2;
21634 break;
bfae80f2 21635
c19d1205
ZW
21636 default:
21637 /* Should never happen. */
21638 abort ();
21639 }
bfae80f2 21640
c19d1205
ZW
21641 /* Pack the opcodes into words (MSB first), reversing the list at the same
21642 time. */
21643 while (unwind.opcode_count > 0)
21644 {
21645 if (n == 0)
21646 {
21647 md_number_to_chars (ptr, data, 4);
21648 ptr += 4;
21649 n = 4;
21650 data = 0;
21651 }
21652 unwind.opcode_count--;
21653 n--;
21654 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21655 }
21656
21657 /* Finish off the last word. */
21658 if (n < 4)
21659 {
21660 /* Pad with "finish" opcodes. */
21661 while (n--)
21662 data = (data << 8) | 0xb0;
21663
21664 md_number_to_chars (ptr, data, 4);
21665 }
21666
21667 if (!have_data)
21668 {
21669 /* Add an empty descriptor if there is no user-specified data. */
21670 ptr = frag_more (4);
21671 md_number_to_chars (ptr, 0, 4);
21672 }
21673
21674 return 0;
bfae80f2
RE
21675}
21676
f0927246
NC
21677
21678/* Initialize the DWARF-2 unwind information for this procedure. */
21679
21680void
21681tc_arm_frame_initial_instructions (void)
21682{
21683 cfi_add_CFA_def_cfa (REG_SP, 0);
21684}
21685#endif /* OBJ_ELF */
21686
c19d1205
ZW
21687/* Convert REGNAME to a DWARF-2 register number. */
21688
21689int
1df69f4f 21690tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 21691{
1df69f4f 21692 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
21693 if (reg != FAIL)
21694 return reg;
c19d1205 21695
1f5afe1c
NC
21696 /* PR 16694: Allow VFP registers as well. */
21697 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
21698 if (reg != FAIL)
21699 return 64 + reg;
c19d1205 21700
1f5afe1c
NC
21701 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
21702 if (reg != FAIL)
21703 return reg + 256;
21704
21705 return -1;
bfae80f2
RE
21706}
21707
f0927246 21708#ifdef TE_PE
c19d1205 21709void
f0927246 21710tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 21711{
91d6fa6a 21712 expressionS exp;
bfae80f2 21713
91d6fa6a
NC
21714 exp.X_op = O_secrel;
21715 exp.X_add_symbol = symbol;
21716 exp.X_add_number = 0;
21717 emit_expr (&exp, size);
f0927246
NC
21718}
21719#endif
bfae80f2 21720
c19d1205 21721/* MD interface: Symbol and relocation handling. */
bfae80f2 21722
2fc8bdac
ZW
21723/* Return the address within the segment that a PC-relative fixup is
21724 relative to. For ARM, PC-relative fixups applied to instructions
21725 are generally relative to the location of the fixup plus 8 bytes.
21726 Thumb branches are offset by 4, and Thumb loads relative to PC
21727 require special handling. */
bfae80f2 21728
c19d1205 21729long
2fc8bdac 21730md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 21731{
2fc8bdac
ZW
21732 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
21733
21734 /* If this is pc-relative and we are going to emit a relocation
21735 then we just want to put out any pipeline compensation that the linker
53baae48
NC
21736 will need. Otherwise we want to use the calculated base.
21737 For WinCE we skip the bias for externals as well, since this
21738 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 21739 if (fixP->fx_pcrel
2fc8bdac 21740 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
21741 || (arm_force_relocation (fixP)
21742#ifdef TE_WINCE
21743 && !S_IS_EXTERNAL (fixP->fx_addsy)
21744#endif
21745 )))
2fc8bdac 21746 base = 0;
bfae80f2 21747
267bf995 21748
c19d1205 21749 switch (fixP->fx_r_type)
bfae80f2 21750 {
2fc8bdac
ZW
21751 /* PC relative addressing on the Thumb is slightly odd as the
21752 bottom two bits of the PC are forced to zero for the
21753 calculation. This happens *after* application of the
21754 pipeline offset. However, Thumb adrl already adjusts for
21755 this, so we need not do it again. */
c19d1205 21756 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 21757 return base & ~3;
c19d1205
ZW
21758
21759 case BFD_RELOC_ARM_THUMB_OFFSET:
21760 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 21761 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 21762 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 21763 return (base + 4) & ~3;
c19d1205 21764
2fc8bdac
ZW
21765 /* Thumb branches are simply offset by +4. */
21766 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21767 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21768 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21769 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 21770 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 21771 return base + 4;
bfae80f2 21772
267bf995 21773 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
21774 if (fixP->fx_addsy
21775 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21776 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 21777 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
21778 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21779 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
21780 return base + 4;
21781
00adf2d4
JB
21782 /* BLX is like branches above, but forces the low two bits of PC to
21783 zero. */
486499d0
CL
21784 case BFD_RELOC_THUMB_PCREL_BLX:
21785 if (fixP->fx_addsy
21786 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21787 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21788 && THUMB_IS_FUNC (fixP->fx_addsy)
21789 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21790 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
21791 return (base + 4) & ~3;
21792
2fc8bdac
ZW
21793 /* ARM mode branches are offset by +8. However, the Windows CE
21794 loader expects the relocation not to take this into account. */
267bf995 21795 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
21796 if (fixP->fx_addsy
21797 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21798 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21799 && ARM_IS_FUNC (fixP->fx_addsy)
21800 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21801 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 21802 return base + 8;
267bf995 21803
486499d0
CL
21804 case BFD_RELOC_ARM_PCREL_CALL:
21805 if (fixP->fx_addsy
21806 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21807 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21808 && THUMB_IS_FUNC (fixP->fx_addsy)
21809 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21810 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 21811 return base + 8;
267bf995 21812
2fc8bdac 21813 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 21814 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 21815 case BFD_RELOC_ARM_PLT32:
c19d1205 21816#ifdef TE_WINCE
5f4273c7 21817 /* When handling fixups immediately, because we have already
477330fc 21818 discovered the value of a symbol, or the address of the frag involved
53baae48 21819 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
21820 see fixup_segment() in write.c
21821 The S_IS_EXTERNAL test handles the case of global symbols.
21822 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
21823 if (fixP->fx_pcrel
21824 && fixP->fx_addsy != NULL
21825 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21826 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
21827 return base + 8;
2fc8bdac 21828 return base;
c19d1205 21829#else
2fc8bdac 21830 return base + 8;
c19d1205 21831#endif
2fc8bdac 21832
267bf995 21833
2fc8bdac
ZW
21834 /* ARM mode loads relative to PC are also offset by +8. Unlike
21835 branches, the Windows CE loader *does* expect the relocation
21836 to take this into account. */
21837 case BFD_RELOC_ARM_OFFSET_IMM:
21838 case BFD_RELOC_ARM_OFFSET_IMM8:
21839 case BFD_RELOC_ARM_HWLITERAL:
21840 case BFD_RELOC_ARM_LITERAL:
21841 case BFD_RELOC_ARM_CP_OFF_IMM:
21842 return base + 8;
21843
21844
21845 /* Other PC-relative relocations are un-offset. */
21846 default:
21847 return base;
21848 }
bfae80f2
RE
21849}
21850
8b2d793c
NC
21851static bfd_boolean flag_warn_syms = TRUE;
21852
ae8714c2
NC
21853bfd_boolean
21854arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 21855{
8b2d793c
NC
21856 /* PR 18347 - Warn if the user attempts to create a symbol with the same
21857 name as an ARM instruction. Whilst strictly speaking it is allowed, it
21858 does mean that the resulting code might be very confusing to the reader.
21859 Also this warning can be triggered if the user omits an operand before
21860 an immediate address, eg:
21861
21862 LDR =foo
21863
21864 GAS treats this as an assignment of the value of the symbol foo to a
21865 symbol LDR, and so (without this code) it will not issue any kind of
21866 warning or error message.
21867
21868 Note - ARM instructions are case-insensitive but the strings in the hash
21869 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
21870 lower case too. */
21871 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
21872 {
21873 char * nbuf = strdup (name);
21874 char * p;
21875
21876 for (p = nbuf; *p; p++)
21877 *p = TOLOWER (*p);
21878 if (hash_find (arm_ops_hsh, nbuf) != NULL)
21879 {
21880 static struct hash_control * already_warned = NULL;
21881
21882 if (already_warned == NULL)
21883 already_warned = hash_new ();
21884 /* Only warn about the symbol once. To keep the code
21885 simple we let hash_insert do the lookup for us. */
21886 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 21887 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
21888 }
21889 else
21890 free (nbuf);
21891 }
3739860c 21892
ae8714c2
NC
21893 return FALSE;
21894}
21895
21896/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
21897 Otherwise we have no need to default values of symbols. */
21898
21899symbolS *
21900md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
21901{
21902#ifdef OBJ_ELF
21903 if (name[0] == '_' && name[1] == 'G'
21904 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
21905 {
21906 if (!GOT_symbol)
21907 {
21908 if (symbol_find (name))
21909 as_bad (_("GOT already in the symbol table"));
21910
21911 GOT_symbol = symbol_new (name, undefined_section,
21912 (valueT) 0, & zero_address_frag);
21913 }
21914
21915 return GOT_symbol;
21916 }
21917#endif
21918
c921be7d 21919 return NULL;
bfae80f2
RE
21920}
21921
55cf6793 21922/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
21923 computed as two separate immediate values, added together. We
21924 already know that this value cannot be computed by just one ARM
21925 instruction. */
21926
21927static unsigned int
21928validate_immediate_twopart (unsigned int val,
21929 unsigned int * highpart)
bfae80f2 21930{
c19d1205
ZW
21931 unsigned int a;
21932 unsigned int i;
bfae80f2 21933
c19d1205
ZW
21934 for (i = 0; i < 32; i += 2)
21935 if (((a = rotate_left (val, i)) & 0xff) != 0)
21936 {
21937 if (a & 0xff00)
21938 {
21939 if (a & ~ 0xffff)
21940 continue;
21941 * highpart = (a >> 8) | ((i + 24) << 7);
21942 }
21943 else if (a & 0xff0000)
21944 {
21945 if (a & 0xff000000)
21946 continue;
21947 * highpart = (a >> 16) | ((i + 16) << 7);
21948 }
21949 else
21950 {
9c2799c2 21951 gas_assert (a & 0xff000000);
c19d1205
ZW
21952 * highpart = (a >> 24) | ((i + 8) << 7);
21953 }
bfae80f2 21954
c19d1205
ZW
21955 return (a & 0xff) | (i << 7);
21956 }
bfae80f2 21957
c19d1205 21958 return FAIL;
bfae80f2
RE
21959}
21960
c19d1205
ZW
21961static int
21962validate_offset_imm (unsigned int val, int hwse)
21963{
21964 if ((hwse && val > 255) || val > 4095)
21965 return FAIL;
21966 return val;
21967}
bfae80f2 21968
55cf6793 21969/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
21970 negative immediate constant by altering the instruction. A bit of
21971 a hack really.
21972 MOV <-> MVN
21973 AND <-> BIC
21974 ADC <-> SBC
21975 by inverting the second operand, and
21976 ADD <-> SUB
21977 CMP <-> CMN
21978 by negating the second operand. */
bfae80f2 21979
c19d1205
ZW
21980static int
21981negate_data_op (unsigned long * instruction,
21982 unsigned long value)
bfae80f2 21983{
c19d1205
ZW
21984 int op, new_inst;
21985 unsigned long negated, inverted;
bfae80f2 21986
c19d1205
ZW
21987 negated = encode_arm_immediate (-value);
21988 inverted = encode_arm_immediate (~value);
bfae80f2 21989
c19d1205
ZW
21990 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
21991 switch (op)
bfae80f2 21992 {
c19d1205
ZW
21993 /* First negates. */
21994 case OPCODE_SUB: /* ADD <-> SUB */
21995 new_inst = OPCODE_ADD;
21996 value = negated;
21997 break;
bfae80f2 21998
c19d1205
ZW
21999 case OPCODE_ADD:
22000 new_inst = OPCODE_SUB;
22001 value = negated;
22002 break;
bfae80f2 22003
c19d1205
ZW
22004 case OPCODE_CMP: /* CMP <-> CMN */
22005 new_inst = OPCODE_CMN;
22006 value = negated;
22007 break;
bfae80f2 22008
c19d1205
ZW
22009 case OPCODE_CMN:
22010 new_inst = OPCODE_CMP;
22011 value = negated;
22012 break;
bfae80f2 22013
c19d1205
ZW
22014 /* Now Inverted ops. */
22015 case OPCODE_MOV: /* MOV <-> MVN */
22016 new_inst = OPCODE_MVN;
22017 value = inverted;
22018 break;
bfae80f2 22019
c19d1205
ZW
22020 case OPCODE_MVN:
22021 new_inst = OPCODE_MOV;
22022 value = inverted;
22023 break;
bfae80f2 22024
c19d1205
ZW
22025 case OPCODE_AND: /* AND <-> BIC */
22026 new_inst = OPCODE_BIC;
22027 value = inverted;
22028 break;
bfae80f2 22029
c19d1205
ZW
22030 case OPCODE_BIC:
22031 new_inst = OPCODE_AND;
22032 value = inverted;
22033 break;
bfae80f2 22034
c19d1205
ZW
22035 case OPCODE_ADC: /* ADC <-> SBC */
22036 new_inst = OPCODE_SBC;
22037 value = inverted;
22038 break;
bfae80f2 22039
c19d1205
ZW
22040 case OPCODE_SBC:
22041 new_inst = OPCODE_ADC;
22042 value = inverted;
22043 break;
bfae80f2 22044
c19d1205
ZW
22045 /* We cannot do anything. */
22046 default:
22047 return FAIL;
b99bd4ef
NC
22048 }
22049
c19d1205
ZW
22050 if (value == (unsigned) FAIL)
22051 return FAIL;
22052
22053 *instruction &= OPCODE_MASK;
22054 *instruction |= new_inst << DATA_OP_SHIFT;
22055 return value;
b99bd4ef
NC
22056}
22057
ef8d22e6
PB
22058/* Like negate_data_op, but for Thumb-2. */
22059
22060static unsigned int
16dd5e42 22061thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22062{
22063 int op, new_inst;
22064 int rd;
16dd5e42 22065 unsigned int negated, inverted;
ef8d22e6
PB
22066
22067 negated = encode_thumb32_immediate (-value);
22068 inverted = encode_thumb32_immediate (~value);
22069
22070 rd = (*instruction >> 8) & 0xf;
22071 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22072 switch (op)
22073 {
22074 /* ADD <-> SUB. Includes CMP <-> CMN. */
22075 case T2_OPCODE_SUB:
22076 new_inst = T2_OPCODE_ADD;
22077 value = negated;
22078 break;
22079
22080 case T2_OPCODE_ADD:
22081 new_inst = T2_OPCODE_SUB;
22082 value = negated;
22083 break;
22084
22085 /* ORR <-> ORN. Includes MOV <-> MVN. */
22086 case T2_OPCODE_ORR:
22087 new_inst = T2_OPCODE_ORN;
22088 value = inverted;
22089 break;
22090
22091 case T2_OPCODE_ORN:
22092 new_inst = T2_OPCODE_ORR;
22093 value = inverted;
22094 break;
22095
22096 /* AND <-> BIC. TST has no inverted equivalent. */
22097 case T2_OPCODE_AND:
22098 new_inst = T2_OPCODE_BIC;
22099 if (rd == 15)
22100 value = FAIL;
22101 else
22102 value = inverted;
22103 break;
22104
22105 case T2_OPCODE_BIC:
22106 new_inst = T2_OPCODE_AND;
22107 value = inverted;
22108 break;
22109
22110 /* ADC <-> SBC */
22111 case T2_OPCODE_ADC:
22112 new_inst = T2_OPCODE_SBC;
22113 value = inverted;
22114 break;
22115
22116 case T2_OPCODE_SBC:
22117 new_inst = T2_OPCODE_ADC;
22118 value = inverted;
22119 break;
22120
22121 /* We cannot do anything. */
22122 default:
22123 return FAIL;
22124 }
22125
16dd5e42 22126 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22127 return FAIL;
22128
22129 *instruction &= T2_OPCODE_MASK;
22130 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22131 return value;
22132}
22133
8f06b2d8
PB
22134/* Read a 32-bit thumb instruction from buf. */
22135static unsigned long
22136get_thumb32_insn (char * buf)
22137{
22138 unsigned long insn;
22139 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22140 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22141
22142 return insn;
22143}
22144
a8bc6c78
PB
22145
22146/* We usually want to set the low bit on the address of thumb function
22147 symbols. In particular .word foo - . should have the low bit set.
22148 Generic code tries to fold the difference of two symbols to
22149 a constant. Prevent this and force a relocation when the first symbols
22150 is a thumb function. */
c921be7d
NC
22151
22152bfd_boolean
a8bc6c78
PB
22153arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22154{
22155 if (op == O_subtract
22156 && l->X_op == O_symbol
22157 && r->X_op == O_symbol
22158 && THUMB_IS_FUNC (l->X_add_symbol))
22159 {
22160 l->X_op = O_subtract;
22161 l->X_op_symbol = r->X_add_symbol;
22162 l->X_add_number -= r->X_add_number;
c921be7d 22163 return TRUE;
a8bc6c78 22164 }
c921be7d 22165
a8bc6c78 22166 /* Process as normal. */
c921be7d 22167 return FALSE;
a8bc6c78
PB
22168}
22169
4a42ebbc
RR
22170/* Encode Thumb2 unconditional branches and calls. The encoding
22171 for the 2 are identical for the immediate values. */
22172
22173static void
22174encode_thumb2_b_bl_offset (char * buf, offsetT value)
22175{
22176#define T2I1I2MASK ((1 << 13) | (1 << 11))
22177 offsetT newval;
22178 offsetT newval2;
22179 addressT S, I1, I2, lo, hi;
22180
22181 S = (value >> 24) & 0x01;
22182 I1 = (value >> 23) & 0x01;
22183 I2 = (value >> 22) & 0x01;
22184 hi = (value >> 12) & 0x3ff;
fa94de6b 22185 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22186 newval = md_chars_to_number (buf, THUMB_SIZE);
22187 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22188 newval |= (S << 10) | hi;
22189 newval2 &= ~T2I1I2MASK;
22190 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22191 md_number_to_chars (buf, newval, THUMB_SIZE);
22192 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22193}
22194
c19d1205 22195void
55cf6793 22196md_apply_fix (fixS * fixP,
c19d1205
ZW
22197 valueT * valP,
22198 segT seg)
22199{
22200 offsetT value = * valP;
22201 offsetT newval;
22202 unsigned int newimm;
22203 unsigned long temp;
22204 int sign;
22205 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22206
9c2799c2 22207 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22208
c19d1205 22209 /* Note whether this will delete the relocation. */
4962c51a 22210
c19d1205
ZW
22211 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22212 fixP->fx_done = 1;
b99bd4ef 22213
adbaf948 22214 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22215 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22216 for emit_reloc. */
22217 value &= 0xffffffff;
22218 value ^= 0x80000000;
5f4273c7 22219 value -= 0x80000000;
adbaf948
ZW
22220
22221 *valP = value;
c19d1205 22222 fixP->fx_addnumber = value;
b99bd4ef 22223
adbaf948
ZW
22224 /* Same treatment for fixP->fx_offset. */
22225 fixP->fx_offset &= 0xffffffff;
22226 fixP->fx_offset ^= 0x80000000;
22227 fixP->fx_offset -= 0x80000000;
22228
c19d1205 22229 switch (fixP->fx_r_type)
b99bd4ef 22230 {
c19d1205
ZW
22231 case BFD_RELOC_NONE:
22232 /* This will need to go in the object file. */
22233 fixP->fx_done = 0;
22234 break;
b99bd4ef 22235
c19d1205
ZW
22236 case BFD_RELOC_ARM_IMMEDIATE:
22237 /* We claim that this fixup has been processed here,
22238 even if in fact we generate an error because we do
22239 not have a reloc for it, so tc_gen_reloc will reject it. */
22240 fixP->fx_done = 1;
b99bd4ef 22241
77db8e2e 22242 if (fixP->fx_addsy)
b99bd4ef 22243 {
77db8e2e 22244 const char *msg = 0;
b99bd4ef 22245
77db8e2e
NC
22246 if (! S_IS_DEFINED (fixP->fx_addsy))
22247 msg = _("undefined symbol %s used as an immediate value");
22248 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22249 msg = _("symbol %s is in a different section");
22250 else if (S_IS_WEAK (fixP->fx_addsy))
22251 msg = _("symbol %s is weak and may be overridden later");
22252
22253 if (msg)
22254 {
22255 as_bad_where (fixP->fx_file, fixP->fx_line,
22256 msg, S_GET_NAME (fixP->fx_addsy));
22257 break;
22258 }
42e5fcbf
AS
22259 }
22260
c19d1205
ZW
22261 temp = md_chars_to_number (buf, INSN_SIZE);
22262
5e73442d
SL
22263 /* If the offset is negative, we should use encoding A2 for ADR. */
22264 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22265 newimm = negate_data_op (&temp, value);
22266 else
22267 {
22268 newimm = encode_arm_immediate (value);
22269
22270 /* If the instruction will fail, see if we can fix things up by
22271 changing the opcode. */
22272 if (newimm == (unsigned int) FAIL)
22273 newimm = negate_data_op (&temp, value);
22274 }
22275
22276 if (newimm == (unsigned int) FAIL)
b99bd4ef 22277 {
c19d1205
ZW
22278 as_bad_where (fixP->fx_file, fixP->fx_line,
22279 _("invalid constant (%lx) after fixup"),
22280 (unsigned long) value);
22281 break;
b99bd4ef 22282 }
b99bd4ef 22283
c19d1205
ZW
22284 newimm |= (temp & 0xfffff000);
22285 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22286 break;
b99bd4ef 22287
c19d1205
ZW
22288 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22289 {
22290 unsigned int highpart = 0;
22291 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 22292
77db8e2e 22293 if (fixP->fx_addsy)
42e5fcbf 22294 {
77db8e2e 22295 const char *msg = 0;
42e5fcbf 22296
77db8e2e
NC
22297 if (! S_IS_DEFINED (fixP->fx_addsy))
22298 msg = _("undefined symbol %s used as an immediate value");
22299 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22300 msg = _("symbol %s is in a different section");
22301 else if (S_IS_WEAK (fixP->fx_addsy))
22302 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 22303
77db8e2e
NC
22304 if (msg)
22305 {
22306 as_bad_where (fixP->fx_file, fixP->fx_line,
22307 msg, S_GET_NAME (fixP->fx_addsy));
22308 break;
22309 }
22310 }
fa94de6b 22311
c19d1205
ZW
22312 newimm = encode_arm_immediate (value);
22313 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 22314
c19d1205
ZW
22315 /* If the instruction will fail, see if we can fix things up by
22316 changing the opcode. */
22317 if (newimm == (unsigned int) FAIL
22318 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22319 {
22320 /* No ? OK - try using two ADD instructions to generate
22321 the value. */
22322 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 22323
c19d1205
ZW
22324 /* Yes - then make sure that the second instruction is
22325 also an add. */
22326 if (newimm != (unsigned int) FAIL)
22327 newinsn = temp;
22328 /* Still No ? Try using a negated value. */
22329 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22330 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
22331 /* Otherwise - give up. */
22332 else
22333 {
22334 as_bad_where (fixP->fx_file, fixP->fx_line,
22335 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
22336 (long) value);
22337 break;
22338 }
b99bd4ef 22339
c19d1205
ZW
22340 /* Replace the first operand in the 2nd instruction (which
22341 is the PC) with the destination register. We have
22342 already added in the PC in the first instruction and we
22343 do not want to do it again. */
22344 newinsn &= ~ 0xf0000;
22345 newinsn |= ((newinsn & 0x0f000) << 4);
22346 }
b99bd4ef 22347
c19d1205
ZW
22348 newimm |= (temp & 0xfffff000);
22349 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 22350
c19d1205
ZW
22351 highpart |= (newinsn & 0xfffff000);
22352 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
22353 }
22354 break;
b99bd4ef 22355
c19d1205 22356 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
22357 if (!fixP->fx_done && seg->use_rela_p)
22358 value = 0;
22359
c19d1205 22360 case BFD_RELOC_ARM_LITERAL:
26d97720 22361 sign = value > 0;
b99bd4ef 22362
c19d1205
ZW
22363 if (value < 0)
22364 value = - value;
b99bd4ef 22365
c19d1205 22366 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 22367 {
c19d1205
ZW
22368 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
22369 as_bad_where (fixP->fx_file, fixP->fx_line,
22370 _("invalid literal constant: pool needs to be closer"));
22371 else
22372 as_bad_where (fixP->fx_file, fixP->fx_line,
22373 _("bad immediate value for offset (%ld)"),
22374 (long) value);
22375 break;
f03698e6
RE
22376 }
22377
c19d1205 22378 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22379 if (value == 0)
22380 newval &= 0xfffff000;
22381 else
22382 {
22383 newval &= 0xff7ff000;
22384 newval |= value | (sign ? INDEX_UP : 0);
22385 }
c19d1205
ZW
22386 md_number_to_chars (buf, newval, INSN_SIZE);
22387 break;
b99bd4ef 22388
c19d1205
ZW
22389 case BFD_RELOC_ARM_OFFSET_IMM8:
22390 case BFD_RELOC_ARM_HWLITERAL:
26d97720 22391 sign = value > 0;
b99bd4ef 22392
c19d1205
ZW
22393 if (value < 0)
22394 value = - value;
b99bd4ef 22395
c19d1205 22396 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 22397 {
c19d1205
ZW
22398 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
22399 as_bad_where (fixP->fx_file, fixP->fx_line,
22400 _("invalid literal constant: pool needs to be closer"));
22401 else
427d0db6
RM
22402 as_bad_where (fixP->fx_file, fixP->fx_line,
22403 _("bad immediate value for 8-bit offset (%ld)"),
22404 (long) value);
c19d1205 22405 break;
b99bd4ef
NC
22406 }
22407
c19d1205 22408 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22409 if (value == 0)
22410 newval &= 0xfffff0f0;
22411 else
22412 {
22413 newval &= 0xff7ff0f0;
22414 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
22415 }
c19d1205
ZW
22416 md_number_to_chars (buf, newval, INSN_SIZE);
22417 break;
b99bd4ef 22418
c19d1205
ZW
22419 case BFD_RELOC_ARM_T32_OFFSET_U8:
22420 if (value < 0 || value > 1020 || value % 4 != 0)
22421 as_bad_where (fixP->fx_file, fixP->fx_line,
22422 _("bad immediate value for offset (%ld)"), (long) value);
22423 value /= 4;
b99bd4ef 22424
c19d1205 22425 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
22426 newval |= value;
22427 md_number_to_chars (buf+2, newval, THUMB_SIZE);
22428 break;
b99bd4ef 22429
c19d1205
ZW
22430 case BFD_RELOC_ARM_T32_OFFSET_IMM:
22431 /* This is a complicated relocation used for all varieties of Thumb32
22432 load/store instruction with immediate offset:
22433
22434 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 22435 *4, optional writeback(W)
c19d1205
ZW
22436 (doubleword load/store)
22437
22438 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
22439 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
22440 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
22441 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
22442 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
22443
22444 Uppercase letters indicate bits that are already encoded at
22445 this point. Lowercase letters are our problem. For the
22446 second block of instructions, the secondary opcode nybble
22447 (bits 8..11) is present, and bit 23 is zero, even if this is
22448 a PC-relative operation. */
22449 newval = md_chars_to_number (buf, THUMB_SIZE);
22450 newval <<= 16;
22451 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 22452
c19d1205 22453 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 22454 {
c19d1205
ZW
22455 /* Doubleword load/store: 8-bit offset, scaled by 4. */
22456 if (value >= 0)
22457 newval |= (1 << 23);
22458 else
22459 value = -value;
22460 if (value % 4 != 0)
22461 {
22462 as_bad_where (fixP->fx_file, fixP->fx_line,
22463 _("offset not a multiple of 4"));
22464 break;
22465 }
22466 value /= 4;
216d22bc 22467 if (value > 0xff)
c19d1205
ZW
22468 {
22469 as_bad_where (fixP->fx_file, fixP->fx_line,
22470 _("offset out of range"));
22471 break;
22472 }
22473 newval &= ~0xff;
b99bd4ef 22474 }
c19d1205 22475 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 22476 {
c19d1205
ZW
22477 /* PC-relative, 12-bit offset. */
22478 if (value >= 0)
22479 newval |= (1 << 23);
22480 else
22481 value = -value;
216d22bc 22482 if (value > 0xfff)
c19d1205
ZW
22483 {
22484 as_bad_where (fixP->fx_file, fixP->fx_line,
22485 _("offset out of range"));
22486 break;
22487 }
22488 newval &= ~0xfff;
b99bd4ef 22489 }
c19d1205 22490 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 22491 {
c19d1205
ZW
22492 /* Writeback: 8-bit, +/- offset. */
22493 if (value >= 0)
22494 newval |= (1 << 9);
22495 else
22496 value = -value;
216d22bc 22497 if (value > 0xff)
c19d1205
ZW
22498 {
22499 as_bad_where (fixP->fx_file, fixP->fx_line,
22500 _("offset out of range"));
22501 break;
22502 }
22503 newval &= ~0xff;
b99bd4ef 22504 }
c19d1205 22505 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 22506 {
c19d1205 22507 /* T-instruction: positive 8-bit offset. */
216d22bc 22508 if (value < 0 || value > 0xff)
b99bd4ef 22509 {
c19d1205
ZW
22510 as_bad_where (fixP->fx_file, fixP->fx_line,
22511 _("offset out of range"));
22512 break;
b99bd4ef 22513 }
c19d1205
ZW
22514 newval &= ~0xff;
22515 newval |= value;
b99bd4ef
NC
22516 }
22517 else
b99bd4ef 22518 {
c19d1205
ZW
22519 /* Positive 12-bit or negative 8-bit offset. */
22520 int limit;
22521 if (value >= 0)
b99bd4ef 22522 {
c19d1205
ZW
22523 newval |= (1 << 23);
22524 limit = 0xfff;
22525 }
22526 else
22527 {
22528 value = -value;
22529 limit = 0xff;
22530 }
22531 if (value > limit)
22532 {
22533 as_bad_where (fixP->fx_file, fixP->fx_line,
22534 _("offset out of range"));
22535 break;
b99bd4ef 22536 }
c19d1205 22537 newval &= ~limit;
b99bd4ef 22538 }
b99bd4ef 22539
c19d1205
ZW
22540 newval |= value;
22541 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
22542 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
22543 break;
404ff6b5 22544
c19d1205
ZW
22545 case BFD_RELOC_ARM_SHIFT_IMM:
22546 newval = md_chars_to_number (buf, INSN_SIZE);
22547 if (((unsigned long) value) > 32
22548 || (value == 32
22549 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
22550 {
22551 as_bad_where (fixP->fx_file, fixP->fx_line,
22552 _("shift expression is too large"));
22553 break;
22554 }
404ff6b5 22555
c19d1205
ZW
22556 if (value == 0)
22557 /* Shifts of zero must be done as lsl. */
22558 newval &= ~0x60;
22559 else if (value == 32)
22560 value = 0;
22561 newval &= 0xfffff07f;
22562 newval |= (value & 0x1f) << 7;
22563 md_number_to_chars (buf, newval, INSN_SIZE);
22564 break;
404ff6b5 22565
c19d1205 22566 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 22567 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 22568 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 22569 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
22570 /* We claim that this fixup has been processed here,
22571 even if in fact we generate an error because we do
22572 not have a reloc for it, so tc_gen_reloc will reject it. */
22573 fixP->fx_done = 1;
404ff6b5 22574
c19d1205
ZW
22575 if (fixP->fx_addsy
22576 && ! S_IS_DEFINED (fixP->fx_addsy))
22577 {
22578 as_bad_where (fixP->fx_file, fixP->fx_line,
22579 _("undefined symbol %s used as an immediate value"),
22580 S_GET_NAME (fixP->fx_addsy));
22581 break;
22582 }
404ff6b5 22583
c19d1205
ZW
22584 newval = md_chars_to_number (buf, THUMB_SIZE);
22585 newval <<= 16;
22586 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 22587
16805f35
PB
22588 newimm = FAIL;
22589 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22590 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
22591 {
22592 newimm = encode_thumb32_immediate (value);
22593 if (newimm == (unsigned int) FAIL)
22594 newimm = thumb32_negate_data_op (&newval, value);
22595 }
16805f35
PB
22596 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
22597 && newimm == (unsigned int) FAIL)
92e90b6e 22598 {
16805f35
PB
22599 /* Turn add/sum into addw/subw. */
22600 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
22601 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
22602 /* No flat 12-bit imm encoding for addsw/subsw. */
22603 if ((newval & 0x00100000) == 0)
e9f89963 22604 {
40f246e3
NC
22605 /* 12 bit immediate for addw/subw. */
22606 if (value < 0)
22607 {
22608 value = -value;
22609 newval ^= 0x00a00000;
22610 }
22611 if (value > 0xfff)
22612 newimm = (unsigned int) FAIL;
22613 else
22614 newimm = value;
e9f89963 22615 }
92e90b6e 22616 }
cc8a6dd0 22617
c19d1205 22618 if (newimm == (unsigned int)FAIL)
3631a3c8 22619 {
c19d1205
ZW
22620 as_bad_where (fixP->fx_file, fixP->fx_line,
22621 _("invalid constant (%lx) after fixup"),
22622 (unsigned long) value);
22623 break;
3631a3c8
NC
22624 }
22625
c19d1205
ZW
22626 newval |= (newimm & 0x800) << 15;
22627 newval |= (newimm & 0x700) << 4;
22628 newval |= (newimm & 0x0ff);
cc8a6dd0 22629
c19d1205
ZW
22630 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
22631 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
22632 break;
a737bd4d 22633
3eb17e6b 22634 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
22635 if (((unsigned long) value) > 0xffff)
22636 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 22637 _("invalid smc expression"));
2fc8bdac 22638 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
22639 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22640 md_number_to_chars (buf, newval, INSN_SIZE);
22641 break;
a737bd4d 22642
90ec0d68
MGD
22643 case BFD_RELOC_ARM_HVC:
22644 if (((unsigned long) value) > 0xffff)
22645 as_bad_where (fixP->fx_file, fixP->fx_line,
22646 _("invalid hvc expression"));
22647 newval = md_chars_to_number (buf, INSN_SIZE);
22648 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22649 md_number_to_chars (buf, newval, INSN_SIZE);
22650 break;
22651
c19d1205 22652 case BFD_RELOC_ARM_SWI:
adbaf948 22653 if (fixP->tc_fix_data != 0)
c19d1205
ZW
22654 {
22655 if (((unsigned long) value) > 0xff)
22656 as_bad_where (fixP->fx_file, fixP->fx_line,
22657 _("invalid swi expression"));
2fc8bdac 22658 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
22659 newval |= value;
22660 md_number_to_chars (buf, newval, THUMB_SIZE);
22661 }
22662 else
22663 {
22664 if (((unsigned long) value) > 0x00ffffff)
22665 as_bad_where (fixP->fx_file, fixP->fx_line,
22666 _("invalid swi expression"));
2fc8bdac 22667 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
22668 newval |= value;
22669 md_number_to_chars (buf, newval, INSN_SIZE);
22670 }
22671 break;
a737bd4d 22672
c19d1205
ZW
22673 case BFD_RELOC_ARM_MULTI:
22674 if (((unsigned long) value) > 0xffff)
22675 as_bad_where (fixP->fx_file, fixP->fx_line,
22676 _("invalid expression in load/store multiple"));
22677 newval = value | md_chars_to_number (buf, INSN_SIZE);
22678 md_number_to_chars (buf, newval, INSN_SIZE);
22679 break;
a737bd4d 22680
c19d1205 22681#ifdef OBJ_ELF
39b41c9c 22682 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
22683
22684 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22685 && fixP->fx_addsy
34e77a92 22686 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22687 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22688 && THUMB_IS_FUNC (fixP->fx_addsy))
22689 /* Flip the bl to blx. This is a simple flip
22690 bit here because we generate PCREL_CALL for
22691 unconditional bls. */
22692 {
22693 newval = md_chars_to_number (buf, INSN_SIZE);
22694 newval = newval | 0x10000000;
22695 md_number_to_chars (buf, newval, INSN_SIZE);
22696 temp = 1;
22697 fixP->fx_done = 1;
22698 }
39b41c9c
PB
22699 else
22700 temp = 3;
22701 goto arm_branch_common;
22702
22703 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
22704 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22705 && fixP->fx_addsy
34e77a92 22706 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22707 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22708 && THUMB_IS_FUNC (fixP->fx_addsy))
22709 {
22710 /* This would map to a bl<cond>, b<cond>,
22711 b<always> to a Thumb function. We
22712 need to force a relocation for this particular
22713 case. */
22714 newval = md_chars_to_number (buf, INSN_SIZE);
22715 fixP->fx_done = 0;
22716 }
22717
2fc8bdac 22718 case BFD_RELOC_ARM_PLT32:
c19d1205 22719#endif
39b41c9c
PB
22720 case BFD_RELOC_ARM_PCREL_BRANCH:
22721 temp = 3;
22722 goto arm_branch_common;
a737bd4d 22723
39b41c9c 22724 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 22725
39b41c9c 22726 temp = 1;
267bf995
RR
22727 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22728 && fixP->fx_addsy
34e77a92 22729 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22730 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22731 && ARM_IS_FUNC (fixP->fx_addsy))
22732 {
22733 /* Flip the blx to a bl and warn. */
22734 const char *name = S_GET_NAME (fixP->fx_addsy);
22735 newval = 0xeb000000;
22736 as_warn_where (fixP->fx_file, fixP->fx_line,
22737 _("blx to '%s' an ARM ISA state function changed to bl"),
22738 name);
22739 md_number_to_chars (buf, newval, INSN_SIZE);
22740 temp = 3;
22741 fixP->fx_done = 1;
22742 }
22743
22744#ifdef OBJ_ELF
22745 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 22746 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
22747#endif
22748
39b41c9c 22749 arm_branch_common:
c19d1205 22750 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
22751 instruction, in a 24 bit, signed field. Bits 26 through 32 either
22752 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
22753 also be be clear. */
22754 if (value & temp)
c19d1205 22755 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
22756 _("misaligned branch destination"));
22757 if ((value & (offsetT)0xfe000000) != (offsetT)0
22758 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 22759 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22760
2fc8bdac 22761 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 22762 {
2fc8bdac
ZW
22763 newval = md_chars_to_number (buf, INSN_SIZE);
22764 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
22765 /* Set the H bit on BLX instructions. */
22766 if (temp == 1)
22767 {
22768 if (value & 2)
22769 newval |= 0x01000000;
22770 else
22771 newval &= ~0x01000000;
22772 }
2fc8bdac 22773 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 22774 }
c19d1205 22775 break;
a737bd4d 22776
25fe350b
MS
22777 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
22778 /* CBZ can only branch forward. */
a737bd4d 22779
738755b0 22780 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
22781 (which, strictly speaking, are prohibited) will be turned into
22782 no-ops.
738755b0
MS
22783
22784 FIXME: It may be better to remove the instruction completely and
22785 perform relaxation. */
22786 if (value == -2)
2fc8bdac
ZW
22787 {
22788 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 22789 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
22790 md_number_to_chars (buf, newval, THUMB_SIZE);
22791 }
738755b0
MS
22792 else
22793 {
22794 if (value & ~0x7e)
08f10d51 22795 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 22796
477330fc 22797 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
22798 {
22799 newval = md_chars_to_number (buf, THUMB_SIZE);
22800 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
22801 md_number_to_chars (buf, newval, THUMB_SIZE);
22802 }
22803 }
c19d1205 22804 break;
a737bd4d 22805
c19d1205 22806 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 22807 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 22808 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22809
2fc8bdac
ZW
22810 if (fixP->fx_done || !seg->use_rela_p)
22811 {
22812 newval = md_chars_to_number (buf, THUMB_SIZE);
22813 newval |= (value & 0x1ff) >> 1;
22814 md_number_to_chars (buf, newval, THUMB_SIZE);
22815 }
c19d1205 22816 break;
a737bd4d 22817
c19d1205 22818 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 22819 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 22820 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22821
2fc8bdac
ZW
22822 if (fixP->fx_done || !seg->use_rela_p)
22823 {
22824 newval = md_chars_to_number (buf, THUMB_SIZE);
22825 newval |= (value & 0xfff) >> 1;
22826 md_number_to_chars (buf, newval, THUMB_SIZE);
22827 }
c19d1205 22828 break;
a737bd4d 22829
c19d1205 22830 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
22831 if (fixP->fx_addsy
22832 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22833 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22834 && ARM_IS_FUNC (fixP->fx_addsy)
22835 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22836 {
22837 /* Force a relocation for a branch 20 bits wide. */
22838 fixP->fx_done = 0;
22839 }
08f10d51 22840 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
22841 as_bad_where (fixP->fx_file, fixP->fx_line,
22842 _("conditional branch out of range"));
404ff6b5 22843
2fc8bdac
ZW
22844 if (fixP->fx_done || !seg->use_rela_p)
22845 {
22846 offsetT newval2;
22847 addressT S, J1, J2, lo, hi;
404ff6b5 22848
2fc8bdac
ZW
22849 S = (value & 0x00100000) >> 20;
22850 J2 = (value & 0x00080000) >> 19;
22851 J1 = (value & 0x00040000) >> 18;
22852 hi = (value & 0x0003f000) >> 12;
22853 lo = (value & 0x00000ffe) >> 1;
6c43fab6 22854
2fc8bdac
ZW
22855 newval = md_chars_to_number (buf, THUMB_SIZE);
22856 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22857 newval |= (S << 10) | hi;
22858 newval2 |= (J1 << 13) | (J2 << 11) | lo;
22859 md_number_to_chars (buf, newval, THUMB_SIZE);
22860 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22861 }
c19d1205 22862 break;
6c43fab6 22863
c19d1205 22864 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
22865 /* If there is a blx from a thumb state function to
22866 another thumb function flip this to a bl and warn
22867 about it. */
22868
22869 if (fixP->fx_addsy
34e77a92 22870 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22871 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22872 && THUMB_IS_FUNC (fixP->fx_addsy))
22873 {
22874 const char *name = S_GET_NAME (fixP->fx_addsy);
22875 as_warn_where (fixP->fx_file, fixP->fx_line,
22876 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
22877 name);
22878 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22879 newval = newval | 0x1000;
22880 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22881 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22882 fixP->fx_done = 1;
22883 }
22884
22885
22886 goto thumb_bl_common;
22887
c19d1205 22888 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
22889 /* A bl from Thumb state ISA to an internal ARM state function
22890 is converted to a blx. */
22891 if (fixP->fx_addsy
22892 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22893 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22894 && ARM_IS_FUNC (fixP->fx_addsy)
22895 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22896 {
22897 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22898 newval = newval & ~0x1000;
22899 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22900 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
22901 fixP->fx_done = 1;
22902 }
22903
22904 thumb_bl_common:
22905
2fc8bdac
ZW
22906 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22907 /* For a BLX instruction, make sure that the relocation is rounded up
22908 to a word boundary. This follows the semantics of the instruction
22909 which specifies that bit 1 of the target address will come from bit
22910 1 of the base address. */
d406f3e4
JB
22911 value = (value + 3) & ~ 3;
22912
22913#ifdef OBJ_ELF
22914 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
22915 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22916 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22917#endif
404ff6b5 22918
2b2f5df9
NC
22919 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
22920 {
fc289b0a 22921 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
22922 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22923 else if ((value & ~0x1ffffff)
22924 && ((value & ~0x1ffffff) != ~0x1ffffff))
22925 as_bad_where (fixP->fx_file, fixP->fx_line,
22926 _("Thumb2 branch out of range"));
22927 }
4a42ebbc
RR
22928
22929 if (fixP->fx_done || !seg->use_rela_p)
22930 encode_thumb2_b_bl_offset (buf, value);
22931
c19d1205 22932 break;
404ff6b5 22933
c19d1205 22934 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
22935 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
22936 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 22937
2fc8bdac 22938 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 22939 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 22940
2fc8bdac 22941 break;
a737bd4d 22942
2fc8bdac
ZW
22943 case BFD_RELOC_8:
22944 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 22945 *buf = value;
c19d1205 22946 break;
a737bd4d 22947
c19d1205 22948 case BFD_RELOC_16:
2fc8bdac 22949 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 22950 md_number_to_chars (buf, value, 2);
c19d1205 22951 break;
a737bd4d 22952
c19d1205 22953#ifdef OBJ_ELF
0855e32b
NS
22954 case BFD_RELOC_ARM_TLS_CALL:
22955 case BFD_RELOC_ARM_THM_TLS_CALL:
22956 case BFD_RELOC_ARM_TLS_DESCSEQ:
22957 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 22958 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
22959 case BFD_RELOC_ARM_TLS_GD32:
22960 case BFD_RELOC_ARM_TLS_LE32:
22961 case BFD_RELOC_ARM_TLS_IE32:
22962 case BFD_RELOC_ARM_TLS_LDM32:
22963 case BFD_RELOC_ARM_TLS_LDO32:
22964 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 22965 break;
6c43fab6 22966
c19d1205
ZW
22967 case BFD_RELOC_ARM_GOT32:
22968 case BFD_RELOC_ARM_GOTOFF:
c19d1205 22969 break;
b43420e6
NC
22970
22971 case BFD_RELOC_ARM_GOT_PREL:
22972 if (fixP->fx_done || !seg->use_rela_p)
477330fc 22973 md_number_to_chars (buf, value, 4);
b43420e6
NC
22974 break;
22975
9a6f4e97
NS
22976 case BFD_RELOC_ARM_TARGET2:
22977 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
22978 addend here for REL targets, because it won't be written out
22979 during reloc processing later. */
9a6f4e97
NS
22980 if (fixP->fx_done || !seg->use_rela_p)
22981 md_number_to_chars (buf, fixP->fx_offset, 4);
22982 break;
c19d1205 22983#endif
6c43fab6 22984
c19d1205
ZW
22985 case BFD_RELOC_RVA:
22986 case BFD_RELOC_32:
22987 case BFD_RELOC_ARM_TARGET1:
22988 case BFD_RELOC_ARM_ROSEGREL32:
22989 case BFD_RELOC_ARM_SBREL32:
22990 case BFD_RELOC_32_PCREL:
f0927246
NC
22991#ifdef TE_PE
22992 case BFD_RELOC_32_SECREL:
22993#endif
2fc8bdac 22994 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
22995#ifdef TE_WINCE
22996 /* For WinCE we only do this for pcrel fixups. */
22997 if (fixP->fx_done || fixP->fx_pcrel)
22998#endif
22999 md_number_to_chars (buf, value, 4);
c19d1205 23000 break;
6c43fab6 23001
c19d1205
ZW
23002#ifdef OBJ_ELF
23003 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23004 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23005 {
23006 newval = md_chars_to_number (buf, 4) & 0x80000000;
23007 if ((value ^ (value >> 1)) & 0x40000000)
23008 {
23009 as_bad_where (fixP->fx_file, fixP->fx_line,
23010 _("rel31 relocation overflow"));
23011 }
23012 newval |= value & 0x7fffffff;
23013 md_number_to_chars (buf, newval, 4);
23014 }
23015 break;
c19d1205 23016#endif
a737bd4d 23017
c19d1205 23018 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23019 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
23020 if (value < -1023 || value > 1023 || (value & 3))
23021 as_bad_where (fixP->fx_file, fixP->fx_line,
23022 _("co-processor offset out of range"));
23023 cp_off_common:
26d97720 23024 sign = value > 0;
c19d1205
ZW
23025 if (value < 0)
23026 value = -value;
8f06b2d8
PB
23027 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23028 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23029 newval = md_chars_to_number (buf, INSN_SIZE);
23030 else
23031 newval = get_thumb32_insn (buf);
26d97720
NS
23032 if (value == 0)
23033 newval &= 0xffffff00;
23034 else
23035 {
23036 newval &= 0xff7fff00;
23037 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
23038 }
8f06b2d8
PB
23039 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23040 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23041 md_number_to_chars (buf, newval, INSN_SIZE);
23042 else
23043 put_thumb32_insn (buf, newval);
c19d1205 23044 break;
a737bd4d 23045
c19d1205 23046 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 23047 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
23048 if (value < -255 || value > 255)
23049 as_bad_where (fixP->fx_file, fixP->fx_line,
23050 _("co-processor offset out of range"));
df7849c5 23051 value *= 4;
c19d1205 23052 goto cp_off_common;
6c43fab6 23053
c19d1205
ZW
23054 case BFD_RELOC_ARM_THUMB_OFFSET:
23055 newval = md_chars_to_number (buf, THUMB_SIZE);
23056 /* Exactly what ranges, and where the offset is inserted depends
23057 on the type of instruction, we can establish this from the
23058 top 4 bits. */
23059 switch (newval >> 12)
23060 {
23061 case 4: /* PC load. */
23062 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
23063 forced to zero for these loads; md_pcrel_from has already
23064 compensated for this. */
23065 if (value & 3)
23066 as_bad_where (fixP->fx_file, fixP->fx_line,
23067 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
23068 (((unsigned long) fixP->fx_frag->fr_address
23069 + (unsigned long) fixP->fx_where) & ~3)
23070 + (unsigned long) value);
a737bd4d 23071
c19d1205
ZW
23072 if (value & ~0x3fc)
23073 as_bad_where (fixP->fx_file, fixP->fx_line,
23074 _("invalid offset, value too big (0x%08lX)"),
23075 (long) value);
a737bd4d 23076
c19d1205
ZW
23077 newval |= value >> 2;
23078 break;
a737bd4d 23079
c19d1205
ZW
23080 case 9: /* SP load/store. */
23081 if (value & ~0x3fc)
23082 as_bad_where (fixP->fx_file, fixP->fx_line,
23083 _("invalid offset, value too big (0x%08lX)"),
23084 (long) value);
23085 newval |= value >> 2;
23086 break;
6c43fab6 23087
c19d1205
ZW
23088 case 6: /* Word load/store. */
23089 if (value & ~0x7c)
23090 as_bad_where (fixP->fx_file, fixP->fx_line,
23091 _("invalid offset, value too big (0x%08lX)"),
23092 (long) value);
23093 newval |= value << 4; /* 6 - 2. */
23094 break;
a737bd4d 23095
c19d1205
ZW
23096 case 7: /* Byte load/store. */
23097 if (value & ~0x1f)
23098 as_bad_where (fixP->fx_file, fixP->fx_line,
23099 _("invalid offset, value too big (0x%08lX)"),
23100 (long) value);
23101 newval |= value << 6;
23102 break;
a737bd4d 23103
c19d1205
ZW
23104 case 8: /* Halfword load/store. */
23105 if (value & ~0x3e)
23106 as_bad_where (fixP->fx_file, fixP->fx_line,
23107 _("invalid offset, value too big (0x%08lX)"),
23108 (long) value);
23109 newval |= value << 5; /* 6 - 1. */
23110 break;
a737bd4d 23111
c19d1205
ZW
23112 default:
23113 as_bad_where (fixP->fx_file, fixP->fx_line,
23114 "Unable to process relocation for thumb opcode: %lx",
23115 (unsigned long) newval);
23116 break;
23117 }
23118 md_number_to_chars (buf, newval, THUMB_SIZE);
23119 break;
a737bd4d 23120
c19d1205
ZW
23121 case BFD_RELOC_ARM_THUMB_ADD:
23122 /* This is a complicated relocation, since we use it for all of
23123 the following immediate relocations:
a737bd4d 23124
c19d1205
ZW
23125 3bit ADD/SUB
23126 8bit ADD/SUB
23127 9bit ADD/SUB SP word-aligned
23128 10bit ADD PC/SP word-aligned
a737bd4d 23129
c19d1205
ZW
23130 The type of instruction being processed is encoded in the
23131 instruction field:
a737bd4d 23132
c19d1205
ZW
23133 0x8000 SUB
23134 0x00F0 Rd
23135 0x000F Rs
23136 */
23137 newval = md_chars_to_number (buf, THUMB_SIZE);
23138 {
23139 int rd = (newval >> 4) & 0xf;
23140 int rs = newval & 0xf;
23141 int subtract = !!(newval & 0x8000);
a737bd4d 23142
c19d1205
ZW
23143 /* Check for HI regs, only very restricted cases allowed:
23144 Adjusting SP, and using PC or SP to get an address. */
23145 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23146 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23147 as_bad_where (fixP->fx_file, fixP->fx_line,
23148 _("invalid Hi register with immediate"));
a737bd4d 23149
c19d1205
ZW
23150 /* If value is negative, choose the opposite instruction. */
23151 if (value < 0)
23152 {
23153 value = -value;
23154 subtract = !subtract;
23155 if (value < 0)
23156 as_bad_where (fixP->fx_file, fixP->fx_line,
23157 _("immediate value out of range"));
23158 }
a737bd4d 23159
c19d1205
ZW
23160 if (rd == REG_SP)
23161 {
75c11999 23162 if (value & ~0x1fc)
c19d1205
ZW
23163 as_bad_where (fixP->fx_file, fixP->fx_line,
23164 _("invalid immediate for stack address calculation"));
23165 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23166 newval |= value >> 2;
23167 }
23168 else if (rs == REG_PC || rs == REG_SP)
23169 {
c12d2c9d
NC
23170 /* PR gas/18541. If the addition is for a defined symbol
23171 within range of an ADR instruction then accept it. */
23172 if (subtract
23173 && value == 4
23174 && fixP->fx_addsy != NULL)
23175 {
23176 subtract = 0;
23177
23178 if (! S_IS_DEFINED (fixP->fx_addsy)
23179 || S_GET_SEGMENT (fixP->fx_addsy) != seg
23180 || S_IS_WEAK (fixP->fx_addsy))
23181 {
23182 as_bad_where (fixP->fx_file, fixP->fx_line,
23183 _("address calculation needs a strongly defined nearby symbol"));
23184 }
23185 else
23186 {
23187 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
23188
23189 /* Round up to the next 4-byte boundary. */
23190 if (v & 3)
23191 v = (v + 3) & ~ 3;
23192 else
23193 v += 4;
23194 v = S_GET_VALUE (fixP->fx_addsy) - v;
23195
23196 if (v & ~0x3fc)
23197 {
23198 as_bad_where (fixP->fx_file, fixP->fx_line,
23199 _("symbol too far away"));
23200 }
23201 else
23202 {
23203 fixP->fx_done = 1;
23204 value = v;
23205 }
23206 }
23207 }
23208
c19d1205
ZW
23209 if (subtract || value & ~0x3fc)
23210 as_bad_where (fixP->fx_file, fixP->fx_line,
23211 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 23212 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
23213 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
23214 newval |= rd << 8;
23215 newval |= value >> 2;
23216 }
23217 else if (rs == rd)
23218 {
23219 if (value & ~0xff)
23220 as_bad_where (fixP->fx_file, fixP->fx_line,
23221 _("immediate value out of range"));
23222 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
23223 newval |= (rd << 8) | value;
23224 }
23225 else
23226 {
23227 if (value & ~0x7)
23228 as_bad_where (fixP->fx_file, fixP->fx_line,
23229 _("immediate value out of range"));
23230 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
23231 newval |= rd | (rs << 3) | (value << 6);
23232 }
23233 }
23234 md_number_to_chars (buf, newval, THUMB_SIZE);
23235 break;
a737bd4d 23236
c19d1205
ZW
23237 case BFD_RELOC_ARM_THUMB_IMM:
23238 newval = md_chars_to_number (buf, THUMB_SIZE);
23239 if (value < 0 || value > 255)
23240 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 23241 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
23242 (long) value);
23243 newval |= value;
23244 md_number_to_chars (buf, newval, THUMB_SIZE);
23245 break;
a737bd4d 23246
c19d1205
ZW
23247 case BFD_RELOC_ARM_THUMB_SHIFT:
23248 /* 5bit shift value (0..32). LSL cannot take 32. */
23249 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23250 temp = newval & 0xf800;
23251 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23252 as_bad_where (fixP->fx_file, fixP->fx_line,
23253 _("invalid shift value: %ld"), (long) value);
23254 /* Shifts of zero must be encoded as LSL. */
23255 if (value == 0)
23256 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23257 /* Shifts of 32 are encoded as zero. */
23258 else if (value == 32)
23259 value = 0;
23260 newval |= value << 6;
23261 md_number_to_chars (buf, newval, THUMB_SIZE);
23262 break;
a737bd4d 23263
c19d1205
ZW
23264 case BFD_RELOC_VTABLE_INHERIT:
23265 case BFD_RELOC_VTABLE_ENTRY:
23266 fixP->fx_done = 0;
23267 return;
6c43fab6 23268
b6895b4f
PB
23269 case BFD_RELOC_ARM_MOVW:
23270 case BFD_RELOC_ARM_MOVT:
23271 case BFD_RELOC_ARM_THUMB_MOVW:
23272 case BFD_RELOC_ARM_THUMB_MOVT:
23273 if (fixP->fx_done || !seg->use_rela_p)
23274 {
23275 /* REL format relocations are limited to a 16-bit addend. */
23276 if (!fixP->fx_done)
23277 {
39623e12 23278 if (value < -0x8000 || value > 0x7fff)
b6895b4f 23279 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 23280 _("offset out of range"));
b6895b4f
PB
23281 }
23282 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23283 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23284 {
23285 value >>= 16;
23286 }
23287
23288 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23289 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23290 {
23291 newval = get_thumb32_insn (buf);
23292 newval &= 0xfbf08f00;
23293 newval |= (value & 0xf000) << 4;
23294 newval |= (value & 0x0800) << 15;
23295 newval |= (value & 0x0700) << 4;
23296 newval |= (value & 0x00ff);
23297 put_thumb32_insn (buf, newval);
23298 }
23299 else
23300 {
23301 newval = md_chars_to_number (buf, 4);
23302 newval &= 0xfff0f000;
23303 newval |= value & 0x0fff;
23304 newval |= (value & 0xf000) << 4;
23305 md_number_to_chars (buf, newval, 4);
23306 }
23307 }
23308 return;
23309
72d98d16
MG
23310 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
23311 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
23312 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
23313 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
23314 gas_assert (!fixP->fx_done);
23315 {
23316 bfd_vma insn;
23317 bfd_boolean is_mov;
23318 bfd_vma encoded_addend = value;
23319
23320 /* Check that addend can be encoded in instruction. */
23321 if (!seg->use_rela_p && (value < 0 || value > 255))
23322 as_bad_where (fixP->fx_file, fixP->fx_line,
23323 _("the offset 0x%08lX is not representable"),
23324 (unsigned long) encoded_addend);
23325
23326 /* Extract the instruction. */
23327 insn = md_chars_to_number (buf, THUMB_SIZE);
23328 is_mov = (insn & 0xf800) == 0x2000;
23329
23330 /* Encode insn. */
23331 if (is_mov)
23332 {
23333 if (!seg->use_rela_p)
23334 insn |= encoded_addend;
23335 }
23336 else
23337 {
23338 int rd, rs;
23339
23340 /* Extract the instruction. */
23341 /* Encoding is the following
23342 0x8000 SUB
23343 0x00F0 Rd
23344 0x000F Rs
23345 */
23346 /* The following conditions must be true :
23347 - ADD
23348 - Rd == Rs
23349 - Rd <= 7
23350 */
23351 rd = (insn >> 4) & 0xf;
23352 rs = insn & 0xf;
23353 if ((insn & 0x8000) || (rd != rs) || rd > 7)
23354 as_bad_where (fixP->fx_file, fixP->fx_line,
23355 _("Unable to process relocation for thumb opcode: %lx"),
23356 (unsigned long) insn);
23357
23358 /* Encode as ADD immediate8 thumb 1 code. */
23359 insn = 0x3000 | (rd << 8);
23360
23361 /* Place the encoded addend into the first 8 bits of the
23362 instruction. */
23363 if (!seg->use_rela_p)
23364 insn |= encoded_addend;
23365 }
23366
23367 /* Update the instruction. */
23368 md_number_to_chars (buf, insn, THUMB_SIZE);
23369 }
23370 break;
23371
4962c51a
MS
23372 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23373 case BFD_RELOC_ARM_ALU_PC_G0:
23374 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23375 case BFD_RELOC_ARM_ALU_PC_G1:
23376 case BFD_RELOC_ARM_ALU_PC_G2:
23377 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23378 case BFD_RELOC_ARM_ALU_SB_G0:
23379 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23380 case BFD_RELOC_ARM_ALU_SB_G1:
23381 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 23382 gas_assert (!fixP->fx_done);
4962c51a
MS
23383 if (!seg->use_rela_p)
23384 {
477330fc
RM
23385 bfd_vma insn;
23386 bfd_vma encoded_addend;
23387 bfd_vma addend_abs = abs (value);
23388
23389 /* Check that the absolute value of the addend can be
23390 expressed as an 8-bit constant plus a rotation. */
23391 encoded_addend = encode_arm_immediate (addend_abs);
23392 if (encoded_addend == (unsigned int) FAIL)
4962c51a 23393 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23394 _("the offset 0x%08lX is not representable"),
23395 (unsigned long) addend_abs);
23396
23397 /* Extract the instruction. */
23398 insn = md_chars_to_number (buf, INSN_SIZE);
23399
23400 /* If the addend is positive, use an ADD instruction.
23401 Otherwise use a SUB. Take care not to destroy the S bit. */
23402 insn &= 0xff1fffff;
23403 if (value < 0)
23404 insn |= 1 << 22;
23405 else
23406 insn |= 1 << 23;
23407
23408 /* Place the encoded addend into the first 12 bits of the
23409 instruction. */
23410 insn &= 0xfffff000;
23411 insn |= encoded_addend;
23412
23413 /* Update the instruction. */
23414 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
23415 }
23416 break;
23417
23418 case BFD_RELOC_ARM_LDR_PC_G0:
23419 case BFD_RELOC_ARM_LDR_PC_G1:
23420 case BFD_RELOC_ARM_LDR_PC_G2:
23421 case BFD_RELOC_ARM_LDR_SB_G0:
23422 case BFD_RELOC_ARM_LDR_SB_G1:
23423 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 23424 gas_assert (!fixP->fx_done);
4962c51a 23425 if (!seg->use_rela_p)
477330fc
RM
23426 {
23427 bfd_vma insn;
23428 bfd_vma addend_abs = abs (value);
4962c51a 23429
477330fc
RM
23430 /* Check that the absolute value of the addend can be
23431 encoded in 12 bits. */
23432 if (addend_abs >= 0x1000)
4962c51a 23433 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23434 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
23435 (unsigned long) addend_abs);
23436
23437 /* Extract the instruction. */
23438 insn = md_chars_to_number (buf, INSN_SIZE);
23439
23440 /* If the addend is negative, clear bit 23 of the instruction.
23441 Otherwise set it. */
23442 if (value < 0)
23443 insn &= ~(1 << 23);
23444 else
23445 insn |= 1 << 23;
23446
23447 /* Place the absolute value of the addend into the first 12 bits
23448 of the instruction. */
23449 insn &= 0xfffff000;
23450 insn |= addend_abs;
23451
23452 /* Update the instruction. */
23453 md_number_to_chars (buf, insn, INSN_SIZE);
23454 }
4962c51a
MS
23455 break;
23456
23457 case BFD_RELOC_ARM_LDRS_PC_G0:
23458 case BFD_RELOC_ARM_LDRS_PC_G1:
23459 case BFD_RELOC_ARM_LDRS_PC_G2:
23460 case BFD_RELOC_ARM_LDRS_SB_G0:
23461 case BFD_RELOC_ARM_LDRS_SB_G1:
23462 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 23463 gas_assert (!fixP->fx_done);
4962c51a 23464 if (!seg->use_rela_p)
477330fc
RM
23465 {
23466 bfd_vma insn;
23467 bfd_vma addend_abs = abs (value);
4962c51a 23468
477330fc
RM
23469 /* Check that the absolute value of the addend can be
23470 encoded in 8 bits. */
23471 if (addend_abs >= 0x100)
4962c51a 23472 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23473 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
23474 (unsigned long) addend_abs);
23475
23476 /* Extract the instruction. */
23477 insn = md_chars_to_number (buf, INSN_SIZE);
23478
23479 /* If the addend is negative, clear bit 23 of the instruction.
23480 Otherwise set it. */
23481 if (value < 0)
23482 insn &= ~(1 << 23);
23483 else
23484 insn |= 1 << 23;
23485
23486 /* Place the first four bits of the absolute value of the addend
23487 into the first 4 bits of the instruction, and the remaining
23488 four into bits 8 .. 11. */
23489 insn &= 0xfffff0f0;
23490 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
23491
23492 /* Update the instruction. */
23493 md_number_to_chars (buf, insn, INSN_SIZE);
23494 }
4962c51a
MS
23495 break;
23496
23497 case BFD_RELOC_ARM_LDC_PC_G0:
23498 case BFD_RELOC_ARM_LDC_PC_G1:
23499 case BFD_RELOC_ARM_LDC_PC_G2:
23500 case BFD_RELOC_ARM_LDC_SB_G0:
23501 case BFD_RELOC_ARM_LDC_SB_G1:
23502 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 23503 gas_assert (!fixP->fx_done);
4962c51a 23504 if (!seg->use_rela_p)
477330fc
RM
23505 {
23506 bfd_vma insn;
23507 bfd_vma addend_abs = abs (value);
4962c51a 23508
477330fc
RM
23509 /* Check that the absolute value of the addend is a multiple of
23510 four and, when divided by four, fits in 8 bits. */
23511 if (addend_abs & 0x3)
4962c51a 23512 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23513 _("bad offset 0x%08lX (must be word-aligned)"),
23514 (unsigned long) addend_abs);
4962c51a 23515
477330fc 23516 if ((addend_abs >> 2) > 0xff)
4962c51a 23517 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23518 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
23519 (unsigned long) addend_abs);
23520
23521 /* Extract the instruction. */
23522 insn = md_chars_to_number (buf, INSN_SIZE);
23523
23524 /* If the addend is negative, clear bit 23 of the instruction.
23525 Otherwise set it. */
23526 if (value < 0)
23527 insn &= ~(1 << 23);
23528 else
23529 insn |= 1 << 23;
23530
23531 /* Place the addend (divided by four) into the first eight
23532 bits of the instruction. */
23533 insn &= 0xfffffff0;
23534 insn |= addend_abs >> 2;
23535
23536 /* Update the instruction. */
23537 md_number_to_chars (buf, insn, INSN_SIZE);
23538 }
4962c51a
MS
23539 break;
23540
845b51d6
PB
23541 case BFD_RELOC_ARM_V4BX:
23542 /* This will need to go in the object file. */
23543 fixP->fx_done = 0;
23544 break;
23545
c19d1205
ZW
23546 case BFD_RELOC_UNUSED:
23547 default:
23548 as_bad_where (fixP->fx_file, fixP->fx_line,
23549 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
23550 }
6c43fab6
RE
23551}
23552
c19d1205
ZW
23553/* Translate internal representation of relocation info to BFD target
23554 format. */
a737bd4d 23555
c19d1205 23556arelent *
00a97672 23557tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 23558{
c19d1205
ZW
23559 arelent * reloc;
23560 bfd_reloc_code_real_type code;
a737bd4d 23561
21d799b5 23562 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 23563
21d799b5 23564 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
23565 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
23566 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 23567
2fc8bdac 23568 if (fixp->fx_pcrel)
00a97672
RS
23569 {
23570 if (section->use_rela_p)
23571 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
23572 else
23573 fixp->fx_offset = reloc->address;
23574 }
c19d1205 23575 reloc->addend = fixp->fx_offset;
a737bd4d 23576
c19d1205 23577 switch (fixp->fx_r_type)
a737bd4d 23578 {
c19d1205
ZW
23579 case BFD_RELOC_8:
23580 if (fixp->fx_pcrel)
23581 {
23582 code = BFD_RELOC_8_PCREL;
23583 break;
23584 }
a737bd4d 23585
c19d1205
ZW
23586 case BFD_RELOC_16:
23587 if (fixp->fx_pcrel)
23588 {
23589 code = BFD_RELOC_16_PCREL;
23590 break;
23591 }
6c43fab6 23592
c19d1205
ZW
23593 case BFD_RELOC_32:
23594 if (fixp->fx_pcrel)
23595 {
23596 code = BFD_RELOC_32_PCREL;
23597 break;
23598 }
a737bd4d 23599
b6895b4f
PB
23600 case BFD_RELOC_ARM_MOVW:
23601 if (fixp->fx_pcrel)
23602 {
23603 code = BFD_RELOC_ARM_MOVW_PCREL;
23604 break;
23605 }
23606
23607 case BFD_RELOC_ARM_MOVT:
23608 if (fixp->fx_pcrel)
23609 {
23610 code = BFD_RELOC_ARM_MOVT_PCREL;
23611 break;
23612 }
23613
23614 case BFD_RELOC_ARM_THUMB_MOVW:
23615 if (fixp->fx_pcrel)
23616 {
23617 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
23618 break;
23619 }
23620
23621 case BFD_RELOC_ARM_THUMB_MOVT:
23622 if (fixp->fx_pcrel)
23623 {
23624 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
23625 break;
23626 }
23627
c19d1205
ZW
23628 case BFD_RELOC_NONE:
23629 case BFD_RELOC_ARM_PCREL_BRANCH:
23630 case BFD_RELOC_ARM_PCREL_BLX:
23631 case BFD_RELOC_RVA:
23632 case BFD_RELOC_THUMB_PCREL_BRANCH7:
23633 case BFD_RELOC_THUMB_PCREL_BRANCH9:
23634 case BFD_RELOC_THUMB_PCREL_BRANCH12:
23635 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23636 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23637 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
23638 case BFD_RELOC_VTABLE_ENTRY:
23639 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
23640#ifdef TE_PE
23641 case BFD_RELOC_32_SECREL:
23642#endif
c19d1205
ZW
23643 code = fixp->fx_r_type;
23644 break;
a737bd4d 23645
00adf2d4
JB
23646 case BFD_RELOC_THUMB_PCREL_BLX:
23647#ifdef OBJ_ELF
23648 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
23649 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
23650 else
23651#endif
23652 code = BFD_RELOC_THUMB_PCREL_BLX;
23653 break;
23654
c19d1205
ZW
23655 case BFD_RELOC_ARM_LITERAL:
23656 case BFD_RELOC_ARM_HWLITERAL:
23657 /* If this is called then the a literal has
23658 been referenced across a section boundary. */
23659 as_bad_where (fixp->fx_file, fixp->fx_line,
23660 _("literal referenced across section boundary"));
23661 return NULL;
a737bd4d 23662
c19d1205 23663#ifdef OBJ_ELF
0855e32b
NS
23664 case BFD_RELOC_ARM_TLS_CALL:
23665 case BFD_RELOC_ARM_THM_TLS_CALL:
23666 case BFD_RELOC_ARM_TLS_DESCSEQ:
23667 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
23668 case BFD_RELOC_ARM_GOT32:
23669 case BFD_RELOC_ARM_GOTOFF:
b43420e6 23670 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
23671 case BFD_RELOC_ARM_PLT32:
23672 case BFD_RELOC_ARM_TARGET1:
23673 case BFD_RELOC_ARM_ROSEGREL32:
23674 case BFD_RELOC_ARM_SBREL32:
23675 case BFD_RELOC_ARM_PREL31:
23676 case BFD_RELOC_ARM_TARGET2:
c19d1205 23677 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
23678 case BFD_RELOC_ARM_PCREL_CALL:
23679 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
23680 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23681 case BFD_RELOC_ARM_ALU_PC_G0:
23682 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23683 case BFD_RELOC_ARM_ALU_PC_G1:
23684 case BFD_RELOC_ARM_ALU_PC_G2:
23685 case BFD_RELOC_ARM_LDR_PC_G0:
23686 case BFD_RELOC_ARM_LDR_PC_G1:
23687 case BFD_RELOC_ARM_LDR_PC_G2:
23688 case BFD_RELOC_ARM_LDRS_PC_G0:
23689 case BFD_RELOC_ARM_LDRS_PC_G1:
23690 case BFD_RELOC_ARM_LDRS_PC_G2:
23691 case BFD_RELOC_ARM_LDC_PC_G0:
23692 case BFD_RELOC_ARM_LDC_PC_G1:
23693 case BFD_RELOC_ARM_LDC_PC_G2:
23694 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23695 case BFD_RELOC_ARM_ALU_SB_G0:
23696 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23697 case BFD_RELOC_ARM_ALU_SB_G1:
23698 case BFD_RELOC_ARM_ALU_SB_G2:
23699 case BFD_RELOC_ARM_LDR_SB_G0:
23700 case BFD_RELOC_ARM_LDR_SB_G1:
23701 case BFD_RELOC_ARM_LDR_SB_G2:
23702 case BFD_RELOC_ARM_LDRS_SB_G0:
23703 case BFD_RELOC_ARM_LDRS_SB_G1:
23704 case BFD_RELOC_ARM_LDRS_SB_G2:
23705 case BFD_RELOC_ARM_LDC_SB_G0:
23706 case BFD_RELOC_ARM_LDC_SB_G1:
23707 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 23708 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
23709 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
23710 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
23711 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
23712 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
23713 code = fixp->fx_r_type;
23714 break;
a737bd4d 23715
0855e32b 23716 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 23717 case BFD_RELOC_ARM_TLS_GD32:
75c11999 23718 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
23719 case BFD_RELOC_ARM_TLS_IE32:
23720 case BFD_RELOC_ARM_TLS_LDM32:
23721 /* BFD will include the symbol's address in the addend.
23722 But we don't want that, so subtract it out again here. */
23723 if (!S_IS_COMMON (fixp->fx_addsy))
23724 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
23725 code = fixp->fx_r_type;
23726 break;
23727#endif
a737bd4d 23728
c19d1205
ZW
23729 case BFD_RELOC_ARM_IMMEDIATE:
23730 as_bad_where (fixp->fx_file, fixp->fx_line,
23731 _("internal relocation (type: IMMEDIATE) not fixed up"));
23732 return NULL;
a737bd4d 23733
c19d1205
ZW
23734 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23735 as_bad_where (fixp->fx_file, fixp->fx_line,
23736 _("ADRL used for a symbol not defined in the same file"));
23737 return NULL;
a737bd4d 23738
c19d1205 23739 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23740 if (section->use_rela_p)
23741 {
23742 code = fixp->fx_r_type;
23743 break;
23744 }
23745
c19d1205
ZW
23746 if (fixp->fx_addsy != NULL
23747 && !S_IS_DEFINED (fixp->fx_addsy)
23748 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 23749 {
c19d1205
ZW
23750 as_bad_where (fixp->fx_file, fixp->fx_line,
23751 _("undefined local label `%s'"),
23752 S_GET_NAME (fixp->fx_addsy));
23753 return NULL;
a737bd4d
NC
23754 }
23755
c19d1205
ZW
23756 as_bad_where (fixp->fx_file, fixp->fx_line,
23757 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
23758 return NULL;
a737bd4d 23759
c19d1205
ZW
23760 default:
23761 {
23762 char * type;
6c43fab6 23763
c19d1205
ZW
23764 switch (fixp->fx_r_type)
23765 {
23766 case BFD_RELOC_NONE: type = "NONE"; break;
23767 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
23768 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 23769 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
23770 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
23771 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
23772 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 23773 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 23774 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
23775 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
23776 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
23777 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
23778 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
23779 default: type = _("<unknown>"); break;
23780 }
23781 as_bad_where (fixp->fx_file, fixp->fx_line,
23782 _("cannot represent %s relocation in this object file format"),
23783 type);
23784 return NULL;
23785 }
a737bd4d 23786 }
6c43fab6 23787
c19d1205
ZW
23788#ifdef OBJ_ELF
23789 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
23790 && GOT_symbol
23791 && fixp->fx_addsy == GOT_symbol)
23792 {
23793 code = BFD_RELOC_ARM_GOTPC;
23794 reloc->addend = fixp->fx_offset = reloc->address;
23795 }
23796#endif
6c43fab6 23797
c19d1205 23798 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 23799
c19d1205
ZW
23800 if (reloc->howto == NULL)
23801 {
23802 as_bad_where (fixp->fx_file, fixp->fx_line,
23803 _("cannot represent %s relocation in this object file format"),
23804 bfd_get_reloc_code_name (code));
23805 return NULL;
23806 }
6c43fab6 23807
c19d1205
ZW
23808 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
23809 vtable entry to be used in the relocation's section offset. */
23810 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
23811 reloc->address = fixp->fx_offset;
6c43fab6 23812
c19d1205 23813 return reloc;
6c43fab6
RE
23814}
23815
c19d1205 23816/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 23817
c19d1205
ZW
23818void
23819cons_fix_new_arm (fragS * frag,
23820 int where,
23821 int size,
62ebcb5c
AM
23822 expressionS * exp,
23823 bfd_reloc_code_real_type reloc)
6c43fab6 23824{
c19d1205 23825 int pcrel = 0;
6c43fab6 23826
c19d1205
ZW
23827 /* Pick a reloc.
23828 FIXME: @@ Should look at CPU word size. */
23829 switch (size)
23830 {
23831 case 1:
62ebcb5c 23832 reloc = BFD_RELOC_8;
c19d1205
ZW
23833 break;
23834 case 2:
62ebcb5c 23835 reloc = BFD_RELOC_16;
c19d1205
ZW
23836 break;
23837 case 4:
23838 default:
62ebcb5c 23839 reloc = BFD_RELOC_32;
c19d1205
ZW
23840 break;
23841 case 8:
62ebcb5c 23842 reloc = BFD_RELOC_64;
c19d1205
ZW
23843 break;
23844 }
6c43fab6 23845
f0927246
NC
23846#ifdef TE_PE
23847 if (exp->X_op == O_secrel)
23848 {
23849 exp->X_op = O_symbol;
62ebcb5c 23850 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
23851 }
23852#endif
23853
62ebcb5c 23854 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 23855}
6c43fab6 23856
4343666d 23857#if defined (OBJ_COFF)
c19d1205
ZW
23858void
23859arm_validate_fix (fixS * fixP)
6c43fab6 23860{
c19d1205
ZW
23861 /* If the destination of the branch is a defined symbol which does not have
23862 the THUMB_FUNC attribute, then we must be calling a function which has
23863 the (interfacearm) attribute. We look for the Thumb entry point to that
23864 function and change the branch to refer to that function instead. */
23865 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
23866 && fixP->fx_addsy != NULL
23867 && S_IS_DEFINED (fixP->fx_addsy)
23868 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 23869 {
c19d1205 23870 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 23871 }
c19d1205
ZW
23872}
23873#endif
6c43fab6 23874
267bf995 23875
c19d1205
ZW
23876int
23877arm_force_relocation (struct fix * fixp)
23878{
23879#if defined (OBJ_COFF) && defined (TE_PE)
23880 if (fixp->fx_r_type == BFD_RELOC_RVA)
23881 return 1;
23882#endif
6c43fab6 23883
267bf995
RR
23884 /* In case we have a call or a branch to a function in ARM ISA mode from
23885 a thumb function or vice-versa force the relocation. These relocations
23886 are cleared off for some cores that might have blx and simple transformations
23887 are possible. */
23888
23889#ifdef OBJ_ELF
23890 switch (fixp->fx_r_type)
23891 {
23892 case BFD_RELOC_ARM_PCREL_JUMP:
23893 case BFD_RELOC_ARM_PCREL_CALL:
23894 case BFD_RELOC_THUMB_PCREL_BLX:
23895 if (THUMB_IS_FUNC (fixp->fx_addsy))
23896 return 1;
23897 break;
23898
23899 case BFD_RELOC_ARM_PCREL_BLX:
23900 case BFD_RELOC_THUMB_PCREL_BRANCH25:
23901 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23902 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23903 if (ARM_IS_FUNC (fixp->fx_addsy))
23904 return 1;
23905 break;
23906
23907 default:
23908 break;
23909 }
23910#endif
23911
b5884301
PB
23912 /* Resolve these relocations even if the symbol is extern or weak.
23913 Technically this is probably wrong due to symbol preemption.
23914 In practice these relocations do not have enough range to be useful
23915 at dynamic link time, and some code (e.g. in the Linux kernel)
23916 expects these references to be resolved. */
c19d1205
ZW
23917 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
23918 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 23919 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 23920 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
23921 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23922 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
23923 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 23924 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
23925 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23926 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
23927 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
23928 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
23929 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
23930 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 23931 return 0;
a737bd4d 23932
4962c51a
MS
23933 /* Always leave these relocations for the linker. */
23934 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
23935 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
23936 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
23937 return 1;
23938
f0291e4c
PB
23939 /* Always generate relocations against function symbols. */
23940 if (fixp->fx_r_type == BFD_RELOC_32
23941 && fixp->fx_addsy
23942 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
23943 return 1;
23944
c19d1205 23945 return generic_force_reloc (fixp);
404ff6b5
AH
23946}
23947
0ffdc86c 23948#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
23949/* Relocations against function names must be left unadjusted,
23950 so that the linker can use this information to generate interworking
23951 stubs. The MIPS version of this function
c19d1205
ZW
23952 also prevents relocations that are mips-16 specific, but I do not
23953 know why it does this.
404ff6b5 23954
c19d1205
ZW
23955 FIXME:
23956 There is one other problem that ought to be addressed here, but
23957 which currently is not: Taking the address of a label (rather
23958 than a function) and then later jumping to that address. Such
23959 addresses also ought to have their bottom bit set (assuming that
23960 they reside in Thumb code), but at the moment they will not. */
404ff6b5 23961
c19d1205
ZW
23962bfd_boolean
23963arm_fix_adjustable (fixS * fixP)
404ff6b5 23964{
c19d1205
ZW
23965 if (fixP->fx_addsy == NULL)
23966 return 1;
404ff6b5 23967
e28387c3
PB
23968 /* Preserve relocations against symbols with function type. */
23969 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 23970 return FALSE;
e28387c3 23971
c19d1205
ZW
23972 if (THUMB_IS_FUNC (fixP->fx_addsy)
23973 && fixP->fx_subsy == NULL)
c921be7d 23974 return FALSE;
a737bd4d 23975
c19d1205
ZW
23976 /* We need the symbol name for the VTABLE entries. */
23977 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
23978 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 23979 return FALSE;
404ff6b5 23980
c19d1205
ZW
23981 /* Don't allow symbols to be discarded on GOT related relocs. */
23982 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
23983 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
23984 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
23985 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
23986 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
23987 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
23988 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
23989 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
23990 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
23991 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
23992 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
23993 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
23994 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 23995 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 23996 return FALSE;
a737bd4d 23997
4962c51a
MS
23998 /* Similarly for group relocations. */
23999 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24000 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24001 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 24002 return FALSE;
4962c51a 24003
79947c54
CD
24004 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
24005 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
24006 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24007 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
24008 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
24009 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24010 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
24011 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
24012 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 24013 return FALSE;
79947c54 24014
72d98d16
MG
24015 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
24016 offsets, so keep these symbols. */
24017 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
24018 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
24019 return FALSE;
24020
c921be7d 24021 return TRUE;
a737bd4d 24022}
0ffdc86c
NC
24023#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
24024
24025#ifdef OBJ_ELF
404ff6b5 24026
c19d1205
ZW
24027const char *
24028elf32_arm_target_format (void)
404ff6b5 24029{
c19d1205
ZW
24030#ifdef TE_SYMBIAN
24031 return (target_big_endian
24032 ? "elf32-bigarm-symbian"
24033 : "elf32-littlearm-symbian");
24034#elif defined (TE_VXWORKS)
24035 return (target_big_endian
24036 ? "elf32-bigarm-vxworks"
24037 : "elf32-littlearm-vxworks");
b38cadfb
NC
24038#elif defined (TE_NACL)
24039 return (target_big_endian
24040 ? "elf32-bigarm-nacl"
24041 : "elf32-littlearm-nacl");
c19d1205
ZW
24042#else
24043 if (target_big_endian)
24044 return "elf32-bigarm";
24045 else
24046 return "elf32-littlearm";
24047#endif
404ff6b5
AH
24048}
24049
c19d1205
ZW
24050void
24051armelf_frob_symbol (symbolS * symp,
24052 int * puntp)
404ff6b5 24053{
c19d1205
ZW
24054 elf_frob_symbol (symp, puntp);
24055}
24056#endif
404ff6b5 24057
c19d1205 24058/* MD interface: Finalization. */
a737bd4d 24059
c19d1205
ZW
24060void
24061arm_cleanup (void)
24062{
24063 literal_pool * pool;
a737bd4d 24064
e07e6e58
NC
24065 /* Ensure that all the IT blocks are properly closed. */
24066 check_it_blocks_finished ();
24067
c19d1205
ZW
24068 for (pool = list_of_pools; pool; pool = pool->next)
24069 {
5f4273c7 24070 /* Put it at the end of the relevant section. */
c19d1205
ZW
24071 subseg_set (pool->section, pool->sub_section);
24072#ifdef OBJ_ELF
24073 arm_elf_change_section ();
24074#endif
24075 s_ltorg (0);
24076 }
404ff6b5
AH
24077}
24078
cd000bff
DJ
24079#ifdef OBJ_ELF
24080/* Remove any excess mapping symbols generated for alignment frags in
24081 SEC. We may have created a mapping symbol before a zero byte
24082 alignment; remove it if there's a mapping symbol after the
24083 alignment. */
24084static void
24085check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
24086 void *dummy ATTRIBUTE_UNUSED)
24087{
24088 segment_info_type *seginfo = seg_info (sec);
24089 fragS *fragp;
24090
24091 if (seginfo == NULL || seginfo->frchainP == NULL)
24092 return;
24093
24094 for (fragp = seginfo->frchainP->frch_root;
24095 fragp != NULL;
24096 fragp = fragp->fr_next)
24097 {
24098 symbolS *sym = fragp->tc_frag_data.last_map;
24099 fragS *next = fragp->fr_next;
24100
24101 /* Variable-sized frags have been converted to fixed size by
24102 this point. But if this was variable-sized to start with,
24103 there will be a fixed-size frag after it. So don't handle
24104 next == NULL. */
24105 if (sym == NULL || next == NULL)
24106 continue;
24107
24108 if (S_GET_VALUE (sym) < next->fr_address)
24109 /* Not at the end of this frag. */
24110 continue;
24111 know (S_GET_VALUE (sym) == next->fr_address);
24112
24113 do
24114 {
24115 if (next->tc_frag_data.first_map != NULL)
24116 {
24117 /* Next frag starts with a mapping symbol. Discard this
24118 one. */
24119 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24120 break;
24121 }
24122
24123 if (next->fr_next == NULL)
24124 {
24125 /* This mapping symbol is at the end of the section. Discard
24126 it. */
24127 know (next->fr_fix == 0 && next->fr_var == 0);
24128 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24129 break;
24130 }
24131
24132 /* As long as we have empty frags without any mapping symbols,
24133 keep looking. */
24134 /* If the next frag is non-empty and does not start with a
24135 mapping symbol, then this mapping symbol is required. */
24136 if (next->fr_address != next->fr_next->fr_address)
24137 break;
24138
24139 next = next->fr_next;
24140 }
24141 while (next != NULL);
24142 }
24143}
24144#endif
24145
c19d1205
ZW
24146/* Adjust the symbol table. This marks Thumb symbols as distinct from
24147 ARM ones. */
404ff6b5 24148
c19d1205
ZW
24149void
24150arm_adjust_symtab (void)
404ff6b5 24151{
c19d1205
ZW
24152#ifdef OBJ_COFF
24153 symbolS * sym;
404ff6b5 24154
c19d1205
ZW
24155 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24156 {
24157 if (ARM_IS_THUMB (sym))
24158 {
24159 if (THUMB_IS_FUNC (sym))
24160 {
24161 /* Mark the symbol as a Thumb function. */
24162 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24163 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24164 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 24165
c19d1205
ZW
24166 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
24167 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
24168 else
24169 as_bad (_("%s: unexpected function type: %d"),
24170 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
24171 }
24172 else switch (S_GET_STORAGE_CLASS (sym))
24173 {
24174 case C_EXT:
24175 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
24176 break;
24177 case C_STAT:
24178 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
24179 break;
24180 case C_LABEL:
24181 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
24182 break;
24183 default:
24184 /* Do nothing. */
24185 break;
24186 }
24187 }
a737bd4d 24188
c19d1205
ZW
24189 if (ARM_IS_INTERWORK (sym))
24190 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 24191 }
c19d1205
ZW
24192#endif
24193#ifdef OBJ_ELF
24194 symbolS * sym;
24195 char bind;
404ff6b5 24196
c19d1205 24197 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 24198 {
c19d1205
ZW
24199 if (ARM_IS_THUMB (sym))
24200 {
24201 elf_symbol_type * elf_sym;
404ff6b5 24202
c19d1205
ZW
24203 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
24204 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 24205
b0796911
PB
24206 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
24207 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
24208 {
24209 /* If it's a .thumb_func, declare it as so,
24210 otherwise tag label as .code 16. */
24211 if (THUMB_IS_FUNC (sym))
35fc36a8
RS
24212 elf_sym->internal_elf_sym.st_target_internal
24213 = ST_BRANCH_TO_THUMB;
3ba67470 24214 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
24215 elf_sym->internal_elf_sym.st_info =
24216 ELF_ST_INFO (bind, STT_ARM_16BIT);
24217 }
24218 }
24219 }
cd000bff
DJ
24220
24221 /* Remove any overlapping mapping symbols generated by alignment frags. */
24222 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
24223 /* Now do generic ELF adjustments. */
24224 elf_adjust_symtab ();
c19d1205 24225#endif
404ff6b5
AH
24226}
24227
c19d1205 24228/* MD interface: Initialization. */
404ff6b5 24229
a737bd4d 24230static void
c19d1205 24231set_constant_flonums (void)
a737bd4d 24232{
c19d1205 24233 int i;
404ff6b5 24234
c19d1205
ZW
24235 for (i = 0; i < NUM_FLOAT_VALS; i++)
24236 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
24237 abort ();
a737bd4d 24238}
404ff6b5 24239
3e9e4fcf
JB
24240/* Auto-select Thumb mode if it's the only available instruction set for the
24241 given architecture. */
24242
24243static void
24244autoselect_thumb_from_cpu_variant (void)
24245{
24246 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
24247 opcode_select (16);
24248}
24249
c19d1205
ZW
24250void
24251md_begin (void)
a737bd4d 24252{
c19d1205
ZW
24253 unsigned mach;
24254 unsigned int i;
404ff6b5 24255
c19d1205
ZW
24256 if ( (arm_ops_hsh = hash_new ()) == NULL
24257 || (arm_cond_hsh = hash_new ()) == NULL
24258 || (arm_shift_hsh = hash_new ()) == NULL
24259 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 24260 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 24261 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
24262 || (arm_reloc_hsh = hash_new ()) == NULL
24263 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
24264 as_fatal (_("virtual memory exhausted"));
24265
24266 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 24267 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 24268 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 24269 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 24270 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 24271 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 24272 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24273 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 24274 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24275 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 24276 (void *) (v7m_psrs + i));
c19d1205 24277 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 24278 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
24279 for (i = 0;
24280 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
24281 i++)
d3ce72d0 24282 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 24283 (void *) (barrier_opt_names + i));
c19d1205 24284#ifdef OBJ_ELF
3da1d841
NC
24285 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
24286 {
24287 struct reloc_entry * entry = reloc_names + i;
24288
24289 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
24290 /* This makes encode_branch() use the EABI versions of this relocation. */
24291 entry->reloc = BFD_RELOC_UNUSED;
24292
24293 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
24294 }
c19d1205
ZW
24295#endif
24296
24297 set_constant_flonums ();
404ff6b5 24298
c19d1205
ZW
24299 /* Set the cpu variant based on the command-line options. We prefer
24300 -mcpu= over -march= if both are set (as for GCC); and we prefer
24301 -mfpu= over any other way of setting the floating point unit.
24302 Use of legacy options with new options are faulted. */
e74cfd16 24303 if (legacy_cpu)
404ff6b5 24304 {
e74cfd16 24305 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
24306 as_bad (_("use of old and new-style options to set CPU type"));
24307
24308 mcpu_cpu_opt = legacy_cpu;
404ff6b5 24309 }
e74cfd16 24310 else if (!mcpu_cpu_opt)
c19d1205 24311 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 24312
e74cfd16 24313 if (legacy_fpu)
c19d1205 24314 {
e74cfd16 24315 if (mfpu_opt)
c19d1205 24316 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
24317
24318 mfpu_opt = legacy_fpu;
24319 }
e74cfd16 24320 else if (!mfpu_opt)
03b1477f 24321 {
45eb4c1b
NS
24322#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
24323 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
24324 /* Some environments specify a default FPU. If they don't, infer it
24325 from the processor. */
e74cfd16 24326 if (mcpu_fpu_opt)
03b1477f
RE
24327 mfpu_opt = mcpu_fpu_opt;
24328 else
24329 mfpu_opt = march_fpu_opt;
39c2da32 24330#else
e74cfd16 24331 mfpu_opt = &fpu_default;
39c2da32 24332#endif
03b1477f
RE
24333 }
24334
e74cfd16 24335 if (!mfpu_opt)
03b1477f 24336 {
493cb6ef 24337 if (mcpu_cpu_opt != NULL)
e74cfd16 24338 mfpu_opt = &fpu_default;
493cb6ef 24339 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 24340 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 24341 else
e74cfd16 24342 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
24343 }
24344
ee065d83 24345#ifdef CPU_DEFAULT
e74cfd16 24346 if (!mcpu_cpu_opt)
ee065d83 24347 {
e74cfd16
PB
24348 mcpu_cpu_opt = &cpu_default;
24349 selected_cpu = cpu_default;
ee065d83 24350 }
73f43896
NC
24351 else if (no_cpu_selected ())
24352 selected_cpu = cpu_default;
e74cfd16
PB
24353#else
24354 if (mcpu_cpu_opt)
24355 selected_cpu = *mcpu_cpu_opt;
ee065d83 24356 else
e74cfd16 24357 mcpu_cpu_opt = &arm_arch_any;
ee065d83 24358#endif
03b1477f 24359
e74cfd16 24360 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 24361
3e9e4fcf
JB
24362 autoselect_thumb_from_cpu_variant ();
24363
e74cfd16 24364 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 24365
f17c130b 24366#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 24367 {
7cc69913
NC
24368 unsigned int flags = 0;
24369
24370#if defined OBJ_ELF
24371 flags = meabi_flags;
d507cf36
PB
24372
24373 switch (meabi_flags)
33a392fb 24374 {
d507cf36 24375 case EF_ARM_EABI_UNKNOWN:
7cc69913 24376#endif
d507cf36
PB
24377 /* Set the flags in the private structure. */
24378 if (uses_apcs_26) flags |= F_APCS26;
24379 if (support_interwork) flags |= F_INTERWORK;
24380 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 24381 if (pic_code) flags |= F_PIC;
e74cfd16 24382 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
24383 flags |= F_SOFT_FLOAT;
24384
d507cf36
PB
24385 switch (mfloat_abi_opt)
24386 {
24387 case ARM_FLOAT_ABI_SOFT:
24388 case ARM_FLOAT_ABI_SOFTFP:
24389 flags |= F_SOFT_FLOAT;
24390 break;
33a392fb 24391
d507cf36
PB
24392 case ARM_FLOAT_ABI_HARD:
24393 if (flags & F_SOFT_FLOAT)
24394 as_bad (_("hard-float conflicts with specified fpu"));
24395 break;
24396 }
03b1477f 24397
e74cfd16
PB
24398 /* Using pure-endian doubles (even if soft-float). */
24399 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 24400 flags |= F_VFP_FLOAT;
f17c130b 24401
fde78edd 24402#if defined OBJ_ELF
e74cfd16 24403 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 24404 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
24405 break;
24406
8cb51566 24407 case EF_ARM_EABI_VER4:
3a4a14e9 24408 case EF_ARM_EABI_VER5:
c19d1205 24409 /* No additional flags to set. */
d507cf36
PB
24410 break;
24411
24412 default:
24413 abort ();
24414 }
7cc69913 24415#endif
b99bd4ef
NC
24416 bfd_set_private_flags (stdoutput, flags);
24417
24418 /* We have run out flags in the COFF header to encode the
24419 status of ATPCS support, so instead we create a dummy,
c19d1205 24420 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
24421 if (atpcs)
24422 {
24423 asection * sec;
24424
24425 sec = bfd_make_section (stdoutput, ".arm.atpcs");
24426
24427 if (sec != NULL)
24428 {
24429 bfd_set_section_flags
24430 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
24431 bfd_set_section_size (stdoutput, sec, 0);
24432 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
24433 }
24434 }
7cc69913 24435 }
f17c130b 24436#endif
b99bd4ef
NC
24437
24438 /* Record the CPU type as well. */
2d447fca
JM
24439 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
24440 mach = bfd_mach_arm_iWMMXt2;
24441 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 24442 mach = bfd_mach_arm_iWMMXt;
e74cfd16 24443 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 24444 mach = bfd_mach_arm_XScale;
e74cfd16 24445 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 24446 mach = bfd_mach_arm_ep9312;
e74cfd16 24447 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 24448 mach = bfd_mach_arm_5TE;
e74cfd16 24449 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 24450 {
e74cfd16 24451 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24452 mach = bfd_mach_arm_5T;
24453 else
24454 mach = bfd_mach_arm_5;
24455 }
e74cfd16 24456 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 24457 {
e74cfd16 24458 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24459 mach = bfd_mach_arm_4T;
24460 else
24461 mach = bfd_mach_arm_4;
24462 }
e74cfd16 24463 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 24464 mach = bfd_mach_arm_3M;
e74cfd16
PB
24465 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
24466 mach = bfd_mach_arm_3;
24467 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
24468 mach = bfd_mach_arm_2a;
24469 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
24470 mach = bfd_mach_arm_2;
24471 else
24472 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
24473
24474 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
24475}
24476
c19d1205 24477/* Command line processing. */
b99bd4ef 24478
c19d1205
ZW
24479/* md_parse_option
24480 Invocation line includes a switch not recognized by the base assembler.
24481 See if it's a processor-specific option.
b99bd4ef 24482
c19d1205
ZW
24483 This routine is somewhat complicated by the need for backwards
24484 compatibility (since older releases of gcc can't be changed).
24485 The new options try to make the interface as compatible as
24486 possible with GCC.
b99bd4ef 24487
c19d1205 24488 New options (supported) are:
b99bd4ef 24489
c19d1205
ZW
24490 -mcpu=<cpu name> Assemble for selected processor
24491 -march=<architecture name> Assemble for selected architecture
24492 -mfpu=<fpu architecture> Assemble for selected FPU.
24493 -EB/-mbig-endian Big-endian
24494 -EL/-mlittle-endian Little-endian
24495 -k Generate PIC code
24496 -mthumb Start in Thumb mode
24497 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 24498
278df34e 24499 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 24500 -m[no-]warn-syms Warn when symbols match instructions
267bf995 24501
c19d1205 24502 For now we will also provide support for:
b99bd4ef 24503
c19d1205
ZW
24504 -mapcs-32 32-bit Program counter
24505 -mapcs-26 26-bit Program counter
24506 -macps-float Floats passed in FP registers
24507 -mapcs-reentrant Reentrant code
24508 -matpcs
24509 (sometime these will probably be replaced with -mapcs=<list of options>
24510 and -matpcs=<list of options>)
b99bd4ef 24511
c19d1205
ZW
24512 The remaining options are only supported for back-wards compatibility.
24513 Cpu variants, the arm part is optional:
24514 -m[arm]1 Currently not supported.
24515 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
24516 -m[arm]3 Arm 3 processor
24517 -m[arm]6[xx], Arm 6 processors
24518 -m[arm]7[xx][t][[d]m] Arm 7 processors
24519 -m[arm]8[10] Arm 8 processors
24520 -m[arm]9[20][tdmi] Arm 9 processors
24521 -mstrongarm[110[0]] StrongARM processors
24522 -mxscale XScale processors
24523 -m[arm]v[2345[t[e]]] Arm architectures
24524 -mall All (except the ARM1)
24525 FP variants:
24526 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
24527 -mfpe-old (No float load/store multiples)
24528 -mvfpxd VFP Single precision
24529 -mvfp All VFP
24530 -mno-fpu Disable all floating point instructions
b99bd4ef 24531
c19d1205
ZW
24532 The following CPU names are recognized:
24533 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
24534 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
24535 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
24536 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
24537 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
24538 arm10t arm10e, arm1020t, arm1020e, arm10200e,
24539 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 24540
c19d1205 24541 */
b99bd4ef 24542
c19d1205 24543const char * md_shortopts = "m:k";
b99bd4ef 24544
c19d1205
ZW
24545#ifdef ARM_BI_ENDIAN
24546#define OPTION_EB (OPTION_MD_BASE + 0)
24547#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 24548#else
c19d1205
ZW
24549#if TARGET_BYTES_BIG_ENDIAN
24550#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 24551#else
c19d1205
ZW
24552#define OPTION_EL (OPTION_MD_BASE + 1)
24553#endif
b99bd4ef 24554#endif
845b51d6 24555#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 24556
c19d1205 24557struct option md_longopts[] =
b99bd4ef 24558{
c19d1205
ZW
24559#ifdef OPTION_EB
24560 {"EB", no_argument, NULL, OPTION_EB},
24561#endif
24562#ifdef OPTION_EL
24563 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 24564#endif
845b51d6 24565 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
24566 {NULL, no_argument, NULL, 0}
24567};
b99bd4ef 24568
8b2d793c 24569
c19d1205 24570size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 24571
c19d1205 24572struct arm_option_table
b99bd4ef 24573{
c19d1205
ZW
24574 char *option; /* Option name to match. */
24575 char *help; /* Help information. */
24576 int *var; /* Variable to change. */
24577 int value; /* What to change it to. */
24578 char *deprecated; /* If non-null, print this message. */
24579};
b99bd4ef 24580
c19d1205
ZW
24581struct arm_option_table arm_opts[] =
24582{
24583 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
24584 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
24585 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
24586 &support_interwork, 1, NULL},
24587 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
24588 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
24589 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
24590 1, NULL},
24591 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
24592 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
24593 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
24594 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
24595 NULL},
b99bd4ef 24596
c19d1205
ZW
24597 /* These are recognized by the assembler, but have no affect on code. */
24598 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
24599 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
24600
24601 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
24602 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
24603 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
24604 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
24605 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
24606 {NULL, NULL, NULL, 0, NULL}
24607};
24608
24609struct arm_legacy_option_table
24610{
24611 char *option; /* Option name to match. */
24612 const arm_feature_set **var; /* Variable to change. */
24613 const arm_feature_set value; /* What to change it to. */
24614 char *deprecated; /* If non-null, print this message. */
24615};
b99bd4ef 24616
e74cfd16
PB
24617const struct arm_legacy_option_table arm_legacy_opts[] =
24618{
c19d1205
ZW
24619 /* DON'T add any new processors to this list -- we want the whole list
24620 to go away... Add them to the processors table instead. */
e74cfd16
PB
24621 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
24622 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
24623 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
24624 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
24625 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
24626 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
24627 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
24628 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
24629 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
24630 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
24631 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
24632 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
24633 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
24634 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
24635 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
24636 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
24637 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
24638 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
24639 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
24640 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
24641 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
24642 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
24643 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
24644 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
24645 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
24646 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
24647 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
24648 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
24649 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
24650 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
24651 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
24652 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
24653 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
24654 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
24655 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
24656 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
24657 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
24658 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
24659 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
24660 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
24661 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
24662 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
24663 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
24664 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
24665 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
24666 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
24667 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24668 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24669 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24670 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24671 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
24672 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
24673 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
24674 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
24675 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
24676 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
24677 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
24678 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
24679 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
24680 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
24681 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
24682 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
24683 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
24684 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
24685 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
24686 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
24687 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
24688 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
24689 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
24690 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24691 N_("use -mcpu=strongarm110")},
e74cfd16 24692 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24693 N_("use -mcpu=strongarm1100")},
e74cfd16 24694 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24695 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
24696 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
24697 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
24698 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 24699
c19d1205 24700 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
24701 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
24702 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
24703 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
24704 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
24705 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
24706 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
24707 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
24708 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
24709 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
24710 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
24711 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
24712 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
24713 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
24714 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
24715 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
24716 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
24717 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
24718 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 24719
c19d1205 24720 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
24721 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
24722 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
24723 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
24724 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 24725 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 24726
e74cfd16 24727 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 24728};
7ed4c4c5 24729
c19d1205 24730struct arm_cpu_option_table
7ed4c4c5 24731{
c19d1205 24732 char *name;
f3bad469 24733 size_t name_len;
e74cfd16 24734 const arm_feature_set value;
c19d1205
ZW
24735 /* For some CPUs we assume an FPU unless the user explicitly sets
24736 -mfpu=... */
e74cfd16 24737 const arm_feature_set default_fpu;
ee065d83
PB
24738 /* The canonical name of the CPU, or NULL to use NAME converted to upper
24739 case. */
24740 const char *canonical_name;
c19d1205 24741};
7ed4c4c5 24742
c19d1205
ZW
24743/* This list should, at a minimum, contain all the cpu names
24744 recognized by GCC. */
f3bad469 24745#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 24746static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 24747{
f3bad469
MGD
24748 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
24749 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
24750 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
24751 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
24752 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
24753 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24754 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24755 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24756 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24757 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24758 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24759 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24760 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24761 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24762 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24763 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24764 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24765 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24766 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24767 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24768 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24769 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24770 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24771 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24772 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24773 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24774 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24775 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24776 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24777 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24778 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24779 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24780 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24781 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24782 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24783 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24784 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24785 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24786 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24787 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
24788 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24789 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24790 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24791 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24792 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24793 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
24794 /* For V5 or later processors we default to using VFP; but the user
24795 should really set the FPU type explicitly. */
f3bad469
MGD
24796 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24797 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24798 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
24799 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
24800 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
24801 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24802 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
24803 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24804 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24805 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
24806 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24807 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24808 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24809 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24810 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24811 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
24812 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24813 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24814 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24815 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
24816 "ARM1026EJ-S"),
24817 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
24818 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24819 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24820 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24821 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24822 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24823 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
24824 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
24825 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
24826 "ARM1136JF-S"),
24827 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
24828 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
24829 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
24830 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
24831 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
f33026a9
MW
24832 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6KZ, FPU_NONE, NULL),
24833 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6KZ, FPU_ARCH_VFP_V2, NULL),
f3bad469
MGD
24834 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
24835 FPU_NONE, "Cortex-A5"),
c9fb6e58 24836 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469
MGD
24837 "Cortex-A7"),
24838 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
823d2571 24839 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 24840 | FPU_NEON_EXT_V1),
f3bad469
MGD
24841 "Cortex-A8"),
24842 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
823d2571 24843 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 24844 | FPU_NEON_EXT_V1),
f3bad469 24845 "Cortex-A9"),
c9fb6e58 24846 ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
63a4bc21 24847 "Cortex-A12"),
c9fb6e58 24848 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469 24849 "Cortex-A15"),
d7adf960
KT
24850 ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
24851 "Cortex-A17"),
43cdc0a8
RR
24852 ARM_CPU_OPT ("cortex-a35", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24853 "Cortex-A35"),
92eb40d9 24854 ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 24855 "Cortex-A53"),
92eb40d9 24856 ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 24857 "Cortex-A57"),
b19f47ad
JW
24858 ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24859 "Cortex-A72"),
f3bad469
MGD
24860 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
24861 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
24862 "Cortex-R4F"),
24863 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
24864 FPU_NONE, "Cortex-R5"),
70a8bc5b 24865 ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV,
24866 FPU_ARCH_VFP_V3D16,
24867 "Cortex-R7"),
a715796b 24868 ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"),
f3bad469
MGD
24869 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
24870 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
24871 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
24872 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 24873 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
246496bb
EM
24874 ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24875 "Samsung " \
24876 "Exynos M1"),
6b21c2bf
JW
24877 ARM_CPU_OPT ("qdf24xx", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24878 "Qualcomm "
24879 "QDF24XX"),
24880
c19d1205 24881 /* ??? XSCALE is really an architecture. */
f3bad469 24882 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 24883 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
24884 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
24885 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
24886 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 24887 /* Maverick */
823d2571 24888 ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
da4339ed
NC
24889 FPU_ARCH_MAVERICK, "ARM920T"),
24890 /* Marvell processors. */
823d2571
TG
24891 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE_LOW (ARM_AEXT_V7A | ARM_EXT_MP
24892 | ARM_EXT_SEC),
477330fc 24893 FPU_ARCH_VFP_V3D16, NULL),
823d2571
TG
24894 ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE_LOW (ARM_AEXT_V7A | ARM_EXT_MP
24895 | ARM_EXT_SEC),
4347085a 24896 FPU_ARCH_NEON_VFP_V4, NULL),
ea0d6bb9
PT
24897 /* APM X-Gene family. */
24898 ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24899 "APM X-Gene 1"),
24900 ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24901 "APM X-Gene 2"),
da4339ed 24902
f3bad469 24903 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 24904};
f3bad469 24905#undef ARM_CPU_OPT
7ed4c4c5 24906
c19d1205 24907struct arm_arch_option_table
7ed4c4c5 24908{
c19d1205 24909 char *name;
f3bad469 24910 size_t name_len;
e74cfd16
PB
24911 const arm_feature_set value;
24912 const arm_feature_set default_fpu;
c19d1205 24913};
7ed4c4c5 24914
c19d1205
ZW
24915/* This list should, at a minimum, contain all the architecture names
24916 recognized by GCC. */
f3bad469 24917#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 24918static const struct arm_arch_option_table arm_archs[] =
c19d1205 24919{
f3bad469
MGD
24920 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
24921 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
24922 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
24923 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
24924 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
24925 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
24926 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
24927 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
24928 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
24929 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
24930 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
24931 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
24932 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
24933 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
24934 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
24935 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
24936 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
24937 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
24938 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
24939 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
24940 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
24941 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
24942 kept to preserve existing behaviour. */
24943 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
24944 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
24945 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
24946 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
24947 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
24948 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
24949 kept to preserve existing behaviour. */
24950 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
24951 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
24952 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
24953 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
24954 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
24955 /* The official spelling of the ARMv7 profile variants is the dashed form.
24956 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 24957 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 24958 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
24959 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
24960 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
24961 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
24962 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
24963 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
24964 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
4ed7ed8d 24965 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 24966 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 24967 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 24968 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
f3bad469
MGD
24969 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
24970 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
24971 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
24972 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 24973};
f3bad469 24974#undef ARM_ARCH_OPT
7ed4c4c5 24975
69133863
MGD
24976/* ISA extensions in the co-processor and main instruction set space. */
24977struct arm_option_extension_value_table
c19d1205
ZW
24978{
24979 char *name;
f3bad469 24980 size_t name_len;
5a70a223
JB
24981 const arm_feature_set merge_value;
24982 const arm_feature_set clear_value;
69133863 24983 const arm_feature_set allowed_archs;
c19d1205 24984};
7ed4c4c5 24985
69133863
MGD
24986/* The following table must be in alphabetical order with a NULL last entry.
24987 */
5a70a223 24988#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, AA }
69133863 24989static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 24990{
823d2571
TG
24991 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
24992 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 24993 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
24994 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
24995 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24996 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
24997 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24998 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
24999 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
25000 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
25001 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
25002 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ANY),
25003 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
25004 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ANY),
25005 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
25006 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ANY),
25007 ARM_EXT_OPT ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
25008 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
25009 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
bca38921 25010 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
823d2571
TG
25011 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
25012 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
25013 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25014 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25015 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
25016 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
25017 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
25018 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
25019 ARM_EXT_OPT ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
25020 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
25021 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V7A)),
25022 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
25023 | ARM_EXT_DIV),
25024 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
25025 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
d6b4b13e
MW
25026 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8,
25027 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
25028 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
25029 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
25030 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ANY),
5a70a223 25031 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE }
69133863 25032};
f3bad469 25033#undef ARM_EXT_OPT
69133863
MGD
25034
25035/* ISA floating-point and Advanced SIMD extensions. */
25036struct arm_option_fpu_value_table
25037{
25038 char *name;
25039 const arm_feature_set value;
c19d1205 25040};
7ed4c4c5 25041
c19d1205
ZW
25042/* This list should, at a minimum, contain all the fpu names
25043 recognized by GCC. */
69133863 25044static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
25045{
25046 {"softfpa", FPU_NONE},
25047 {"fpe", FPU_ARCH_FPE},
25048 {"fpe2", FPU_ARCH_FPE},
25049 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
25050 {"fpa", FPU_ARCH_FPA},
25051 {"fpa10", FPU_ARCH_FPA},
25052 {"fpa11", FPU_ARCH_FPA},
25053 {"arm7500fe", FPU_ARCH_FPA},
25054 {"softvfp", FPU_ARCH_VFP},
25055 {"softvfp+vfp", FPU_ARCH_VFP_V2},
25056 {"vfp", FPU_ARCH_VFP_V2},
25057 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 25058 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
25059 {"vfp10", FPU_ARCH_VFP_V2},
25060 {"vfp10-r0", FPU_ARCH_VFP_V1},
25061 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
25062 {"vfpv2", FPU_ARCH_VFP_V2},
25063 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 25064 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 25065 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
25066 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
25067 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
25068 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
25069 {"arm1020t", FPU_ARCH_VFP_V1},
25070 {"arm1020e", FPU_ARCH_VFP_V2},
25071 {"arm1136jfs", FPU_ARCH_VFP_V2},
25072 {"arm1136jf-s", FPU_ARCH_VFP_V2},
25073 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 25074 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 25075 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
25076 {"vfpv4", FPU_ARCH_VFP_V4},
25077 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 25078 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
25079 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
25080 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 25081 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
25082 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
25083 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
25084 {"crypto-neon-fp-armv8",
25085 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 25086 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
25087 {"crypto-neon-fp-armv8.1",
25088 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
25089 {NULL, ARM_ARCH_NONE}
25090};
25091
25092struct arm_option_value_table
25093{
25094 char *name;
25095 long value;
c19d1205 25096};
7ed4c4c5 25097
e74cfd16 25098static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
25099{
25100 {"hard", ARM_FLOAT_ABI_HARD},
25101 {"softfp", ARM_FLOAT_ABI_SOFTFP},
25102 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 25103 {NULL, 0}
c19d1205 25104};
7ed4c4c5 25105
c19d1205 25106#ifdef OBJ_ELF
3a4a14e9 25107/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 25108static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
25109{
25110 {"gnu", EF_ARM_EABI_UNKNOWN},
25111 {"4", EF_ARM_EABI_VER4},
3a4a14e9 25112 {"5", EF_ARM_EABI_VER5},
e74cfd16 25113 {NULL, 0}
c19d1205
ZW
25114};
25115#endif
7ed4c4c5 25116
c19d1205
ZW
25117struct arm_long_option_table
25118{
25119 char * option; /* Substring to match. */
25120 char * help; /* Help information. */
25121 int (* func) (char * subopt); /* Function to decode sub-option. */
25122 char * deprecated; /* If non-null, print this message. */
25123};
7ed4c4c5 25124
c921be7d 25125static bfd_boolean
f3bad469 25126arm_parse_extension (char *str, const arm_feature_set **opt_p)
7ed4c4c5 25127{
21d799b5
NC
25128 arm_feature_set *ext_set = (arm_feature_set *)
25129 xmalloc (sizeof (arm_feature_set));
e74cfd16 25130
69133863 25131 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
25132 extensions being added before being removed. We achieve this by having
25133 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 25134 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 25135 or removing it (0) and only allowing it to change in the order
69133863
MGD
25136 -1 -> 1 -> 0. */
25137 const struct arm_option_extension_value_table * opt = NULL;
25138 int adding_value = -1;
25139
e74cfd16
PB
25140 /* Copy the feature set, so that we can modify it. */
25141 *ext_set = **opt_p;
25142 *opt_p = ext_set;
25143
c19d1205 25144 while (str != NULL && *str != 0)
7ed4c4c5 25145 {
f3bad469
MGD
25146 char *ext;
25147 size_t len;
7ed4c4c5 25148
c19d1205
ZW
25149 if (*str != '+')
25150 {
25151 as_bad (_("invalid architectural extension"));
c921be7d 25152 return FALSE;
c19d1205 25153 }
7ed4c4c5 25154
c19d1205
ZW
25155 str++;
25156 ext = strchr (str, '+');
7ed4c4c5 25157
c19d1205 25158 if (ext != NULL)
f3bad469 25159 len = ext - str;
c19d1205 25160 else
f3bad469 25161 len = strlen (str);
7ed4c4c5 25162
f3bad469 25163 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
25164 {
25165 if (adding_value != 0)
25166 {
25167 adding_value = 0;
25168 opt = arm_extensions;
25169 }
25170
f3bad469 25171 len -= 2;
69133863
MGD
25172 str += 2;
25173 }
f3bad469 25174 else if (len > 0)
69133863
MGD
25175 {
25176 if (adding_value == -1)
25177 {
25178 adding_value = 1;
25179 opt = arm_extensions;
25180 }
25181 else if (adding_value != 1)
25182 {
25183 as_bad (_("must specify extensions to add before specifying "
25184 "those to remove"));
25185 return FALSE;
25186 }
25187 }
25188
f3bad469 25189 if (len == 0)
c19d1205
ZW
25190 {
25191 as_bad (_("missing architectural extension"));
c921be7d 25192 return FALSE;
c19d1205 25193 }
7ed4c4c5 25194
69133863
MGD
25195 gas_assert (adding_value != -1);
25196 gas_assert (opt != NULL);
25197
25198 /* Scan over the options table trying to find an exact match. */
25199 for (; opt->name != NULL; opt++)
f3bad469 25200 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25201 {
69133863
MGD
25202 /* Check we can apply the extension to this architecture. */
25203 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
25204 {
25205 as_bad (_("extension does not apply to the base architecture"));
25206 return FALSE;
25207 }
25208
25209 /* Add or remove the extension. */
25210 if (adding_value)
5a70a223 25211 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 25212 else
5a70a223 25213 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 25214
c19d1205
ZW
25215 break;
25216 }
7ed4c4c5 25217
c19d1205
ZW
25218 if (opt->name == NULL)
25219 {
69133863
MGD
25220 /* Did we fail to find an extension because it wasn't specified in
25221 alphabetical order, or because it does not exist? */
25222
25223 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 25224 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
25225 break;
25226
25227 if (opt->name == NULL)
25228 as_bad (_("unknown architectural extension `%s'"), str);
25229 else
25230 as_bad (_("architectural extensions must be specified in "
25231 "alphabetical order"));
25232
c921be7d 25233 return FALSE;
c19d1205 25234 }
69133863
MGD
25235 else
25236 {
25237 /* We should skip the extension we've just matched the next time
25238 round. */
25239 opt++;
25240 }
7ed4c4c5 25241
c19d1205
ZW
25242 str = ext;
25243 };
7ed4c4c5 25244
c921be7d 25245 return TRUE;
c19d1205 25246}
7ed4c4c5 25247
c921be7d 25248static bfd_boolean
f3bad469 25249arm_parse_cpu (char *str)
7ed4c4c5 25250{
f3bad469
MGD
25251 const struct arm_cpu_option_table *opt;
25252 char *ext = strchr (str, '+');
25253 size_t len;
7ed4c4c5 25254
c19d1205 25255 if (ext != NULL)
f3bad469 25256 len = ext - str;
7ed4c4c5 25257 else
f3bad469 25258 len = strlen (str);
7ed4c4c5 25259
f3bad469 25260 if (len == 0)
7ed4c4c5 25261 {
c19d1205 25262 as_bad (_("missing cpu name `%s'"), str);
c921be7d 25263 return FALSE;
7ed4c4c5
NC
25264 }
25265
c19d1205 25266 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 25267 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25268 {
e74cfd16
PB
25269 mcpu_cpu_opt = &opt->value;
25270 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 25271 if (opt->canonical_name)
ef8e6722
JW
25272 {
25273 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
25274 strcpy (selected_cpu_name, opt->canonical_name);
25275 }
ee065d83
PB
25276 else
25277 {
f3bad469 25278 size_t i;
c921be7d 25279
ef8e6722
JW
25280 if (len >= sizeof selected_cpu_name)
25281 len = (sizeof selected_cpu_name) - 1;
25282
f3bad469 25283 for (i = 0; i < len; i++)
ee065d83
PB
25284 selected_cpu_name[i] = TOUPPER (opt->name[i]);
25285 selected_cpu_name[i] = 0;
25286 }
7ed4c4c5 25287
c19d1205
ZW
25288 if (ext != NULL)
25289 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 25290
c921be7d 25291 return TRUE;
c19d1205 25292 }
7ed4c4c5 25293
c19d1205 25294 as_bad (_("unknown cpu `%s'"), str);
c921be7d 25295 return FALSE;
7ed4c4c5
NC
25296}
25297
c921be7d 25298static bfd_boolean
f3bad469 25299arm_parse_arch (char *str)
7ed4c4c5 25300{
e74cfd16 25301 const struct arm_arch_option_table *opt;
c19d1205 25302 char *ext = strchr (str, '+');
f3bad469 25303 size_t len;
7ed4c4c5 25304
c19d1205 25305 if (ext != NULL)
f3bad469 25306 len = ext - str;
7ed4c4c5 25307 else
f3bad469 25308 len = strlen (str);
7ed4c4c5 25309
f3bad469 25310 if (len == 0)
7ed4c4c5 25311 {
c19d1205 25312 as_bad (_("missing architecture name `%s'"), str);
c921be7d 25313 return FALSE;
7ed4c4c5
NC
25314 }
25315
c19d1205 25316 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 25317 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25318 {
e74cfd16
PB
25319 march_cpu_opt = &opt->value;
25320 march_fpu_opt = &opt->default_fpu;
5f4273c7 25321 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 25322
c19d1205
ZW
25323 if (ext != NULL)
25324 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 25325
c921be7d 25326 return TRUE;
c19d1205
ZW
25327 }
25328
25329 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 25330 return FALSE;
7ed4c4c5 25331}
eb043451 25332
c921be7d 25333static bfd_boolean
c19d1205
ZW
25334arm_parse_fpu (char * str)
25335{
69133863 25336 const struct arm_option_fpu_value_table * opt;
b99bd4ef 25337
c19d1205
ZW
25338 for (opt = arm_fpus; opt->name != NULL; opt++)
25339 if (streq (opt->name, str))
25340 {
e74cfd16 25341 mfpu_opt = &opt->value;
c921be7d 25342 return TRUE;
c19d1205 25343 }
b99bd4ef 25344
c19d1205 25345 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 25346 return FALSE;
c19d1205
ZW
25347}
25348
c921be7d 25349static bfd_boolean
c19d1205 25350arm_parse_float_abi (char * str)
b99bd4ef 25351{
e74cfd16 25352 const struct arm_option_value_table * opt;
b99bd4ef 25353
c19d1205
ZW
25354 for (opt = arm_float_abis; opt->name != NULL; opt++)
25355 if (streq (opt->name, str))
25356 {
25357 mfloat_abi_opt = opt->value;
c921be7d 25358 return TRUE;
c19d1205 25359 }
cc8a6dd0 25360
c19d1205 25361 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 25362 return FALSE;
c19d1205 25363}
b99bd4ef 25364
c19d1205 25365#ifdef OBJ_ELF
c921be7d 25366static bfd_boolean
c19d1205
ZW
25367arm_parse_eabi (char * str)
25368{
e74cfd16 25369 const struct arm_option_value_table *opt;
cc8a6dd0 25370
c19d1205
ZW
25371 for (opt = arm_eabis; opt->name != NULL; opt++)
25372 if (streq (opt->name, str))
25373 {
25374 meabi_flags = opt->value;
c921be7d 25375 return TRUE;
c19d1205
ZW
25376 }
25377 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 25378 return FALSE;
c19d1205
ZW
25379}
25380#endif
cc8a6dd0 25381
c921be7d 25382static bfd_boolean
e07e6e58
NC
25383arm_parse_it_mode (char * str)
25384{
c921be7d 25385 bfd_boolean ret = TRUE;
e07e6e58
NC
25386
25387 if (streq ("arm", str))
25388 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
25389 else if (streq ("thumb", str))
25390 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
25391 else if (streq ("always", str))
25392 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
25393 else if (streq ("never", str))
25394 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
25395 else
25396 {
25397 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 25398 "arm, thumb, always, or never."), str);
c921be7d 25399 ret = FALSE;
e07e6e58
NC
25400 }
25401
25402 return ret;
25403}
25404
2e6976a8
DG
25405static bfd_boolean
25406arm_ccs_mode (char * unused ATTRIBUTE_UNUSED)
25407{
25408 codecomposer_syntax = TRUE;
25409 arm_comment_chars[0] = ';';
25410 arm_line_separator_chars[0] = 0;
25411 return TRUE;
25412}
25413
c19d1205
ZW
25414struct arm_long_option_table arm_long_opts[] =
25415{
25416 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
25417 arm_parse_cpu, NULL},
25418 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
25419 arm_parse_arch, NULL},
25420 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
25421 arm_parse_fpu, NULL},
25422 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
25423 arm_parse_float_abi, NULL},
25424#ifdef OBJ_ELF
7fac0536 25425 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
25426 arm_parse_eabi, NULL},
25427#endif
e07e6e58
NC
25428 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
25429 arm_parse_it_mode, NULL},
2e6976a8
DG
25430 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
25431 arm_ccs_mode, NULL},
c19d1205
ZW
25432 {NULL, NULL, 0, NULL}
25433};
cc8a6dd0 25434
c19d1205
ZW
25435int
25436md_parse_option (int c, char * arg)
25437{
25438 struct arm_option_table *opt;
e74cfd16 25439 const struct arm_legacy_option_table *fopt;
c19d1205 25440 struct arm_long_option_table *lopt;
b99bd4ef 25441
c19d1205 25442 switch (c)
b99bd4ef 25443 {
c19d1205
ZW
25444#ifdef OPTION_EB
25445 case OPTION_EB:
25446 target_big_endian = 1;
25447 break;
25448#endif
cc8a6dd0 25449
c19d1205
ZW
25450#ifdef OPTION_EL
25451 case OPTION_EL:
25452 target_big_endian = 0;
25453 break;
25454#endif
b99bd4ef 25455
845b51d6
PB
25456 case OPTION_FIX_V4BX:
25457 fix_v4bx = TRUE;
25458 break;
25459
c19d1205
ZW
25460 case 'a':
25461 /* Listing option. Just ignore these, we don't support additional
25462 ones. */
25463 return 0;
b99bd4ef 25464
c19d1205
ZW
25465 default:
25466 for (opt = arm_opts; opt->option != NULL; opt++)
25467 {
25468 if (c == opt->option[0]
25469 && ((arg == NULL && opt->option[1] == 0)
25470 || streq (arg, opt->option + 1)))
25471 {
c19d1205 25472 /* If the option is deprecated, tell the user. */
278df34e 25473 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
25474 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25475 arg ? arg : "", _(opt->deprecated));
b99bd4ef 25476
c19d1205
ZW
25477 if (opt->var != NULL)
25478 *opt->var = opt->value;
cc8a6dd0 25479
c19d1205
ZW
25480 return 1;
25481 }
25482 }
b99bd4ef 25483
e74cfd16
PB
25484 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
25485 {
25486 if (c == fopt->option[0]
25487 && ((arg == NULL && fopt->option[1] == 0)
25488 || streq (arg, fopt->option + 1)))
25489 {
e74cfd16 25490 /* If the option is deprecated, tell the user. */
278df34e 25491 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
25492 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25493 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
25494
25495 if (fopt->var != NULL)
25496 *fopt->var = &fopt->value;
25497
25498 return 1;
25499 }
25500 }
25501
c19d1205
ZW
25502 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25503 {
25504 /* These options are expected to have an argument. */
25505 if (c == lopt->option[0]
25506 && arg != NULL
25507 && strncmp (arg, lopt->option + 1,
25508 strlen (lopt->option + 1)) == 0)
25509 {
c19d1205 25510 /* If the option is deprecated, tell the user. */
278df34e 25511 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
25512 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
25513 _(lopt->deprecated));
b99bd4ef 25514
c19d1205
ZW
25515 /* Call the sup-option parser. */
25516 return lopt->func (arg + strlen (lopt->option) - 1);
25517 }
25518 }
a737bd4d 25519
c19d1205
ZW
25520 return 0;
25521 }
a394c00f 25522
c19d1205
ZW
25523 return 1;
25524}
a394c00f 25525
c19d1205
ZW
25526void
25527md_show_usage (FILE * fp)
a394c00f 25528{
c19d1205
ZW
25529 struct arm_option_table *opt;
25530 struct arm_long_option_table *lopt;
a394c00f 25531
c19d1205 25532 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 25533
c19d1205
ZW
25534 for (opt = arm_opts; opt->option != NULL; opt++)
25535 if (opt->help != NULL)
25536 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 25537
c19d1205
ZW
25538 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25539 if (lopt->help != NULL)
25540 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 25541
c19d1205
ZW
25542#ifdef OPTION_EB
25543 fprintf (fp, _("\
25544 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
25545#endif
25546
c19d1205
ZW
25547#ifdef OPTION_EL
25548 fprintf (fp, _("\
25549 -EL assemble code for a little-endian cpu\n"));
a737bd4d 25550#endif
845b51d6
PB
25551
25552 fprintf (fp, _("\
25553 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 25554}
ee065d83
PB
25555
25556
25557#ifdef OBJ_ELF
62b3e311
PB
25558typedef struct
25559{
25560 int val;
25561 arm_feature_set flags;
25562} cpu_arch_ver_table;
25563
4ed7ed8d
TP
25564/* Mapping from CPU features to EABI CPU arch values. As a general rule, table
25565 must be sorted least features first but some reordering is needed, eg. for
25566 Thumb-2 instructions to be detected as coming from ARMv6T2. */
62b3e311
PB
25567static const cpu_arch_ver_table cpu_arch_ver[] =
25568{
25569 {1, ARM_ARCH_V4},
25570 {2, ARM_ARCH_V4T},
25571 {3, ARM_ARCH_V5},
ee3c0378 25572 {3, ARM_ARCH_V5T},
62b3e311
PB
25573 {4, ARM_ARCH_V5TE},
25574 {5, ARM_ARCH_V5TEJ},
25575 {6, ARM_ARCH_V6},
7e806470 25576 {9, ARM_ARCH_V6K},
f4c65163 25577 {7, ARM_ARCH_V6Z},
91e22acd 25578 {11, ARM_ARCH_V6M},
b2a5fbdc 25579 {12, ARM_ARCH_V6SM},
7e806470 25580 {8, ARM_ARCH_V6T2},
c9fb6e58 25581 {10, ARM_ARCH_V7VE},
62b3e311
PB
25582 {10, ARM_ARCH_V7R},
25583 {10, ARM_ARCH_V7M},
bca38921 25584 {14, ARM_ARCH_V8A},
4ed7ed8d 25585 {17, ARM_ARCH_V8M_MAIN},
62b3e311
PB
25586 {0, ARM_ARCH_NONE}
25587};
25588
ee3c0378
AS
25589/* Set an attribute if it has not already been set by the user. */
25590static void
25591aeabi_set_attribute_int (int tag, int value)
25592{
25593 if (tag < 1
25594 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
25595 || !attributes_set_explicitly[tag])
25596 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
25597}
25598
25599static void
25600aeabi_set_attribute_string (int tag, const char *value)
25601{
25602 if (tag < 1
25603 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
25604 || !attributes_set_explicitly[tag])
25605 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
25606}
25607
ee065d83 25608/* Set the public EABI object attributes. */
3cfdb781 25609void
ee065d83
PB
25610aeabi_set_public_attributes (void)
25611{
25612 int arch;
69239280 25613 char profile;
90ec0d68 25614 int virt_sec = 0;
bca38921 25615 int fp16_optional = 0;
e74cfd16 25616 arm_feature_set flags;
62b3e311
PB
25617 arm_feature_set tmp;
25618 const cpu_arch_ver_table *p;
ee065d83
PB
25619
25620 /* Choose the architecture based on the capabilities of the requested cpu
25621 (if any) and/or the instructions actually used. */
e74cfd16
PB
25622 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
25623 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
25624 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
25625
25626 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
25627 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
25628
25629 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
25630 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
25631
7f78eb34
JW
25632 selected_cpu = flags;
25633
ddd7f988 25634 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
25635 if (object_arch)
25636 {
25637 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
25638 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
25639 }
25640
251665fc
MGD
25641 /* We need to make sure that the attributes do not identify us as v6S-M
25642 when the only v6S-M feature in use is the Operating System Extensions. */
25643 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
25644 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
477330fc 25645 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
251665fc 25646
62b3e311
PB
25647 tmp = flags;
25648 arch = 0;
25649 for (p = cpu_arch_ver; p->val; p++)
25650 {
25651 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
25652 {
25653 arch = p->val;
25654 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
25655 }
25656 }
ee065d83 25657
9e3c6df6
PB
25658 /* The table lookup above finds the last architecture to contribute
25659 a new feature. Unfortunately, Tag13 is a subset of the union of
25660 v6T2 and v7-M, so it is never seen as contributing a new feature.
25661 We can not search for the last entry which is entirely used,
25662 because if no CPU is specified we build up only those flags
25663 actually used. Perhaps we should separate out the specified
25664 and implicit cases. Avoid taking this path for -march=all by
25665 checking for contradictory v7-A / v7-M features. */
4ed7ed8d 25666 if (arch == TAG_CPU_ARCH_V7
9e3c6df6
PB
25667 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
25668 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
25669 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
4ed7ed8d
TP
25670 arch = TAG_CPU_ARCH_V7E_M;
25671
25672 /* In cpu_arch_ver ARMv8-A is before ARMv8-M for atomics to be detected as
25673 coming from ARMv8-A. However, since ARMv8-A has more instructions than
25674 ARMv8-M, -march=all must be detected as ARMv8-A. */
25675 if (arch == TAG_CPU_ARCH_V8M_MAIN
25676 && ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
25677 arch = TAG_CPU_ARCH_V8;
9e3c6df6 25678
ee065d83
PB
25679 /* Tag_CPU_name. */
25680 if (selected_cpu_name[0])
25681 {
91d6fa6a 25682 char *q;
ee065d83 25683
91d6fa6a
NC
25684 q = selected_cpu_name;
25685 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
25686 {
25687 int i;
5f4273c7 25688
91d6fa6a
NC
25689 q += 4;
25690 for (i = 0; q[i]; i++)
25691 q[i] = TOUPPER (q[i]);
ee065d83 25692 }
91d6fa6a 25693 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 25694 }
62f3b8c8 25695
ee065d83 25696 /* Tag_CPU_arch. */
ee3c0378 25697 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 25698
62b3e311 25699 /* Tag_CPU_arch_profile. */
10c9892b 25700 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
4ed7ed8d
TP
25701 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
25702 || (ARM_CPU_HAS_FEATURE (flags, arm_ext_atomics)
25703 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m)))
69239280 25704 profile = 'A';
62b3e311 25705 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 25706 profile = 'R';
7e806470 25707 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
25708 profile = 'M';
25709 else
25710 profile = '\0';
25711
25712 if (profile != '\0')
25713 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 25714
ee065d83 25715 /* Tag_ARM_ISA_use. */
ee3c0378
AS
25716 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
25717 || arch == 0)
25718 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 25719
ee065d83 25720 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
25721 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
25722 || arch == 0)
4ed7ed8d
TP
25723 {
25724 int thumb_isa_use;
25725
25726 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
25727 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
25728 thumb_isa_use = 3;
25729 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
25730 thumb_isa_use = 2;
25731 else
25732 thumb_isa_use = 1;
25733 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
25734 }
62f3b8c8 25735
ee065d83 25736 /* Tag_VFP_arch. */
a715796b
TG
25737 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
25738 aeabi_set_attribute_int (Tag_VFP_arch,
25739 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
25740 ? 7 : 8);
bca38921 25741 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
25742 aeabi_set_attribute_int (Tag_VFP_arch,
25743 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
25744 ? 5 : 6);
25745 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
25746 {
25747 fp16_optional = 1;
25748 aeabi_set_attribute_int (Tag_VFP_arch, 3);
25749 }
ada65aa3 25750 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
25751 {
25752 aeabi_set_attribute_int (Tag_VFP_arch, 4);
25753 fp16_optional = 1;
25754 }
ee3c0378
AS
25755 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
25756 aeabi_set_attribute_int (Tag_VFP_arch, 2);
25757 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 25758 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 25759 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 25760
4547cb56
NC
25761 /* Tag_ABI_HardFP_use. */
25762 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
25763 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
25764 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
25765
ee065d83 25766 /* Tag_WMMX_arch. */
ee3c0378
AS
25767 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
25768 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
25769 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
25770 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 25771
ee3c0378 25772 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
bca38921
MGD
25773 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
25774 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
25775 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
25776 {
25777 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
25778 {
25779 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
25780 }
25781 else
25782 {
25783 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
25784 fp16_optional = 1;
25785 }
25786 }
fa94de6b 25787
ee3c0378 25788 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 25789 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 25790 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 25791
69239280
MGD
25792 /* Tag_DIV_use.
25793
25794 We set Tag_DIV_use to two when integer divide instructions have been used
25795 in ARM state, or when Thumb integer divide instructions have been used,
25796 but we have no architecture profile set, nor have we any ARM instructions.
25797
4ed7ed8d
TP
25798 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
25799 by the base architecture.
bca38921 25800
69239280 25801 For new architectures we will have to check these tests. */
4ed7ed8d
TP
25802 gas_assert (arch <= TAG_CPU_ARCH_V8 || arch == TAG_CPU_ARCH_V8M_MAIN);
25803 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
25804 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
25805 aeabi_set_attribute_int (Tag_DIV_use, 0);
25806 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
25807 || (profile == '\0'
25808 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
25809 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 25810 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
25811
25812 /* Tag_MP_extension_use. */
25813 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
25814 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
25815
25816 /* Tag Virtualization_use. */
25817 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
25818 virt_sec |= 1;
25819 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
25820 virt_sec |= 2;
25821 if (virt_sec != 0)
25822 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
25823}
25824
104d59d1 25825/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
25826void
25827arm_md_end (void)
25828{
ee065d83
PB
25829 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
25830 return;
25831
25832 aeabi_set_public_attributes ();
ee065d83 25833}
8463be01 25834#endif /* OBJ_ELF */
ee065d83
PB
25835
25836
25837/* Parse a .cpu directive. */
25838
25839static void
25840s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
25841{
e74cfd16 25842 const struct arm_cpu_option_table *opt;
ee065d83
PB
25843 char *name;
25844 char saved_char;
25845
25846 name = input_line_pointer;
5f4273c7 25847 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
25848 input_line_pointer++;
25849 saved_char = *input_line_pointer;
25850 *input_line_pointer = 0;
25851
25852 /* Skip the first "all" entry. */
25853 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
25854 if (streq (opt->name, name))
25855 {
e74cfd16
PB
25856 mcpu_cpu_opt = &opt->value;
25857 selected_cpu = opt->value;
ee065d83 25858 if (opt->canonical_name)
5f4273c7 25859 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
25860 else
25861 {
25862 int i;
25863 for (i = 0; opt->name[i]; i++)
25864 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 25865
ee065d83
PB
25866 selected_cpu_name[i] = 0;
25867 }
e74cfd16 25868 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
25869 *input_line_pointer = saved_char;
25870 demand_empty_rest_of_line ();
25871 return;
25872 }
25873 as_bad (_("unknown cpu `%s'"), name);
25874 *input_line_pointer = saved_char;
25875 ignore_rest_of_line ();
25876}
25877
25878
25879/* Parse a .arch directive. */
25880
25881static void
25882s_arm_arch (int ignored ATTRIBUTE_UNUSED)
25883{
e74cfd16 25884 const struct arm_arch_option_table *opt;
ee065d83
PB
25885 char saved_char;
25886 char *name;
25887
25888 name = input_line_pointer;
5f4273c7 25889 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
25890 input_line_pointer++;
25891 saved_char = *input_line_pointer;
25892 *input_line_pointer = 0;
25893
25894 /* Skip the first "all" entry. */
25895 for (opt = arm_archs + 1; opt->name != NULL; opt++)
25896 if (streq (opt->name, name))
25897 {
e74cfd16
PB
25898 mcpu_cpu_opt = &opt->value;
25899 selected_cpu = opt->value;
5f4273c7 25900 strcpy (selected_cpu_name, opt->name);
e74cfd16 25901 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
25902 *input_line_pointer = saved_char;
25903 demand_empty_rest_of_line ();
25904 return;
25905 }
25906
25907 as_bad (_("unknown architecture `%s'\n"), name);
25908 *input_line_pointer = saved_char;
25909 ignore_rest_of_line ();
25910}
25911
25912
7a1d4c38
PB
25913/* Parse a .object_arch directive. */
25914
25915static void
25916s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
25917{
25918 const struct arm_arch_option_table *opt;
25919 char saved_char;
25920 char *name;
25921
25922 name = input_line_pointer;
5f4273c7 25923 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
25924 input_line_pointer++;
25925 saved_char = *input_line_pointer;
25926 *input_line_pointer = 0;
25927
25928 /* Skip the first "all" entry. */
25929 for (opt = arm_archs + 1; opt->name != NULL; opt++)
25930 if (streq (opt->name, name))
25931 {
25932 object_arch = &opt->value;
25933 *input_line_pointer = saved_char;
25934 demand_empty_rest_of_line ();
25935 return;
25936 }
25937
25938 as_bad (_("unknown architecture `%s'\n"), name);
25939 *input_line_pointer = saved_char;
25940 ignore_rest_of_line ();
25941}
25942
69133863
MGD
25943/* Parse a .arch_extension directive. */
25944
25945static void
25946s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
25947{
25948 const struct arm_option_extension_value_table *opt;
25949 char saved_char;
25950 char *name;
25951 int adding_value = 1;
25952
25953 name = input_line_pointer;
25954 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
25955 input_line_pointer++;
25956 saved_char = *input_line_pointer;
25957 *input_line_pointer = 0;
25958
25959 if (strlen (name) >= 2
25960 && strncmp (name, "no", 2) == 0)
25961 {
25962 adding_value = 0;
25963 name += 2;
25964 }
25965
25966 for (opt = arm_extensions; opt->name != NULL; opt++)
25967 if (streq (opt->name, name))
25968 {
25969 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
25970 {
25971 as_bad (_("architectural extension `%s' is not allowed for the "
25972 "current base architecture"), name);
25973 break;
25974 }
25975
25976 if (adding_value)
5a70a223
JB
25977 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu,
25978 opt->merge_value);
69133863 25979 else
5a70a223 25980 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value);
69133863
MGD
25981
25982 mcpu_cpu_opt = &selected_cpu;
25983 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
25984 *input_line_pointer = saved_char;
25985 demand_empty_rest_of_line ();
25986 return;
25987 }
25988
25989 if (opt->name == NULL)
e673710a 25990 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
25991
25992 *input_line_pointer = saved_char;
25993 ignore_rest_of_line ();
25994}
25995
ee065d83
PB
25996/* Parse a .fpu directive. */
25997
25998static void
25999s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
26000{
69133863 26001 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
26002 char saved_char;
26003 char *name;
26004
26005 name = input_line_pointer;
5f4273c7 26006 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26007 input_line_pointer++;
26008 saved_char = *input_line_pointer;
26009 *input_line_pointer = 0;
5f4273c7 26010
ee065d83
PB
26011 for (opt = arm_fpus; opt->name != NULL; opt++)
26012 if (streq (opt->name, name))
26013 {
e74cfd16
PB
26014 mfpu_opt = &opt->value;
26015 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26016 *input_line_pointer = saved_char;
26017 demand_empty_rest_of_line ();
26018 return;
26019 }
26020
26021 as_bad (_("unknown floating point format `%s'\n"), name);
26022 *input_line_pointer = saved_char;
26023 ignore_rest_of_line ();
26024}
ee065d83 26025
794ba86a 26026/* Copy symbol information. */
f31fef98 26027
794ba86a
DJ
26028void
26029arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
26030{
26031 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
26032}
e04befd0 26033
f31fef98 26034#ifdef OBJ_ELF
e04befd0
AS
26035/* Given a symbolic attribute NAME, return the proper integer value.
26036 Returns -1 if the attribute is not known. */
f31fef98 26037
e04befd0
AS
26038int
26039arm_convert_symbolic_attribute (const char *name)
26040{
f31fef98
NC
26041 static const struct
26042 {
26043 const char * name;
26044 const int tag;
26045 }
26046 attribute_table[] =
26047 {
26048 /* When you modify this table you should
26049 also modify the list in doc/c-arm.texi. */
e04befd0 26050#define T(tag) {#tag, tag}
f31fef98
NC
26051 T (Tag_CPU_raw_name),
26052 T (Tag_CPU_name),
26053 T (Tag_CPU_arch),
26054 T (Tag_CPU_arch_profile),
26055 T (Tag_ARM_ISA_use),
26056 T (Tag_THUMB_ISA_use),
75375b3e 26057 T (Tag_FP_arch),
f31fef98
NC
26058 T (Tag_VFP_arch),
26059 T (Tag_WMMX_arch),
26060 T (Tag_Advanced_SIMD_arch),
26061 T (Tag_PCS_config),
26062 T (Tag_ABI_PCS_R9_use),
26063 T (Tag_ABI_PCS_RW_data),
26064 T (Tag_ABI_PCS_RO_data),
26065 T (Tag_ABI_PCS_GOT_use),
26066 T (Tag_ABI_PCS_wchar_t),
26067 T (Tag_ABI_FP_rounding),
26068 T (Tag_ABI_FP_denormal),
26069 T (Tag_ABI_FP_exceptions),
26070 T (Tag_ABI_FP_user_exceptions),
26071 T (Tag_ABI_FP_number_model),
75375b3e 26072 T (Tag_ABI_align_needed),
f31fef98 26073 T (Tag_ABI_align8_needed),
75375b3e 26074 T (Tag_ABI_align_preserved),
f31fef98
NC
26075 T (Tag_ABI_align8_preserved),
26076 T (Tag_ABI_enum_size),
26077 T (Tag_ABI_HardFP_use),
26078 T (Tag_ABI_VFP_args),
26079 T (Tag_ABI_WMMX_args),
26080 T (Tag_ABI_optimization_goals),
26081 T (Tag_ABI_FP_optimization_goals),
26082 T (Tag_compatibility),
26083 T (Tag_CPU_unaligned_access),
75375b3e 26084 T (Tag_FP_HP_extension),
f31fef98
NC
26085 T (Tag_VFP_HP_extension),
26086 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
26087 T (Tag_MPextension_use),
26088 T (Tag_DIV_use),
f31fef98
NC
26089 T (Tag_nodefaults),
26090 T (Tag_also_compatible_with),
26091 T (Tag_conformance),
26092 T (Tag_T2EE_use),
26093 T (Tag_Virtualization_use),
cd21e546 26094 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 26095#undef T
f31fef98 26096 };
e04befd0
AS
26097 unsigned int i;
26098
26099 if (name == NULL)
26100 return -1;
26101
f31fef98 26102 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 26103 if (streq (name, attribute_table[i].name))
e04befd0
AS
26104 return attribute_table[i].tag;
26105
26106 return -1;
26107}
267bf995
RR
26108
26109
93ef582d
NC
26110/* Apply sym value for relocations only in the case that they are for
26111 local symbols in the same segment as the fixup and you have the
26112 respective architectural feature for blx and simple switches. */
267bf995 26113int
93ef582d 26114arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
26115{
26116 if (fixP->fx_addsy
26117 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
26118 /* PR 17444: If the local symbol is in a different section then a reloc
26119 will always be generated for it, so applying the symbol value now
26120 will result in a double offset being stored in the relocation. */
26121 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 26122 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
26123 {
26124 switch (fixP->fx_r_type)
26125 {
26126 case BFD_RELOC_ARM_PCREL_BLX:
26127 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26128 if (ARM_IS_FUNC (fixP->fx_addsy))
26129 return 1;
26130 break;
26131
26132 case BFD_RELOC_ARM_PCREL_CALL:
26133 case BFD_RELOC_THUMB_PCREL_BLX:
26134 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 26135 return 1;
267bf995
RR
26136 break;
26137
26138 default:
26139 break;
26140 }
26141
26142 }
26143 return 0;
26144}
f31fef98 26145#endif /* OBJ_ELF */
This page took 3.680513 seconds and 4 git commands to generate.